Actions
Name |
Path |
Arguments |
Working Directory |
Primary |
Play |
halo2.exe |
|
|
True |
Name Change Script
Names are stored in a `profile` and `savemeta.bin` file as an ASCII encoded string with 0x00 separating characters. Names can be a maximum of 16 characters. We force that to avoid any overflows / profile corruption.
$NewName = $args[0]
$InstallDir = $PSScriptRoot
function Get-AsciiBytes([string]$InputString, [int]$MaxLength)
{
if ($InputString.Length -gt $MaxLength)
{
$InputString = $InputString.Substring(0, $MaxLength)
}
$bytes = [System.Text.Encoding]::ASCII.GetBytes($InputString)
$array = @()
$count = 0
$extraPadding = $MaxLength - $bytes.Length
foreach ($byte in $bytes)
{
if ($count -lt $MaxLength)
{
$array += $byte
$count++
}
}
for ($i = $count; $i -lt $MaxLength; $i++)
{
$array += 0x00
}
return $array
}
function Separate-AsciiBytes([byte[]]$Data)
{
$array = @()
foreach ($byte in $Data)
{
$array += $byte
$array += 0x00
}
return $array
}
function Patch-Binary([byte[]]$Data, [int]$Offset, [string]$FilePath)
{
$bytes = [System.IO.File]::ReadAllBytes($FilePath)
for ($i = 0; $i -lt $Data.Length; $i++)
{
$bytes[$Offset + $i] = $Data[$i]
}
[System.IO.File]::WriteAllBytes($FilePath, $bytes)
}
$rawBytes = Get-AsciiBytes -InputString $NewName -MaxLength 16
$profileNameBytes = Separate-AsciiBytes -Data $rawBytes
Remove-Item "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000" -Recurse -ErrorAction Ignore
Copy-Item -Path "$InstallDir\ProfileTemplate\S0000000" -Destination "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000" -Recurse
Patch-Binary -FilePath "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000\profile" -Offset 8 -Data $profileNameBytes
Patch-Binary -FilePath "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000\savemeta.bin" -Offset 18 -Data $profileNameBytes
Install Script
$InstallDir = $PSScriptRoot
New-Item -ItemType Directory -Force -Path "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games"
Remove-Item "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000" -Recurse -ErrorAction Ignore
Copy-Item -Path "$InstallDir\ProfileTemplate\S0000000" -Destination "$($env:LOCALAPPDATA)\Microsoft\Halo 2\Saved Games\S0000000" -Recurse