$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 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 15
Patch-Binary -FilePath "$InstallDir\Data\Settings\OptionsAndPros.opt" -Offset 0xed -Data $rawBytes