Halo 2

From LANCommander
Revision as of 00:35, 1 August 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Developers = {{Game.InfoBox.Developer|Bungie}} |Publishers = {{Game.InfoBox.Publisher|Microsoft Game Studios}} |Release Date = {{Game.InfoBox.ReleaseDate|Windows|November 9, 2004}} |Genres = {{Game.InfoBox.Genre|Shooter}} | PCGamingWiki = Halo_2 }} {{Game.ActionBox |Actions = {{Game.ActionBox.Row|Name = Play|Path = halo2.exe|Arguments = |WorkingDirectory = |Primary = True}} }} {{Game.Scripts.NameChange |Name = Name...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Developers
Bungie
Publishers
Microsoft Game Studios
Release Date
Windows: November 9, 2004
Genres
Shooter
View at PCGamingWiki

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