$Display = Get-PrimaryDisplay
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" -Name "$InstallDirectory\amrts.exe" -Value "~ DWM8And16BitMitigation HIGHDPIAWARE WIN98" -Force
Write-ReplaceContentInFile -Pattern '^Resolution.+' -Substitution "Resolution = h:$($Display.Bounds.Width), v:$($Display.Bounds.Height)" -FilePath "$InstallDirectory\dgVoodoo.conf"
Write-ReplaceContentInFile -Pattern '^dgVoodooWatermark.+' -Substitution "dgVoodooWatermark = false" -FilePath "$InstallDirectory\dgVoodoo.conf"
# Skip intro video on startup
Edit-PatchBinary -FilePath "$InstallDirectory\base.x-e" -Offset 0x38D65E8 -Data 0x61
if ($NewPlayerAlias.Length -gt 15) {
$NewPlayerAlias = $NewPlayerAlias.Substring(0, 15);
}
$configFilePath = "$InstallDirectory\user\data.cfg"
Function Find-Bytes([byte[]]$Bytes, [byte[]]$Search, [int]$Start, [Switch]$All) {
For ($Index = $Start; $Index -le $Bytes.Length - $Search.Length ; $Index++) {
For ($i = 0; $i -lt $Search.Length -and $Bytes[$Index + $i] -eq $Search[$i]; $i++) {}
If ($i -ge $Search.Length) {
$Index
If (!$All) { Return }
}
}
}
$headerBytes = [byte[]](
0x44, 0x4F, 0x43, 0x42, 0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x28, 0xFE, 0x79, 0x13,
0x0A, 0x00, 0x00, 0x00, 0x08, 0x81, 0xCB, 0x14,
0x00, 0x00, 0x00, 0x00, 0xB7, 0xDB, 0x11, 0xDB,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x42, 0x71, 0xC4, 0xB0, 0x23, 0x1C, 0x00, 0x00
)
$nameKeyBytes = [byte[]]("displayname".ToCharArray())
$nameValueBytes = [byte[]]($NewPlayerAlias.ToCharArray())
$originalConfigBytes = [System.IO.File]::ReadAllBytes($configFilePath)
$keyIndex = Find-Bytes -all $originalConfigBytes $nameKeyBytes
$seekIndex = 0
Write-Host "The key 'displayname' was found at position $keyIndex"
if ($keyIndex -ne -1) {
Write-Host "New name length is $($nameValueBytes.Length)"
Write-Host "Name key length is $($nameKeyBytes.Length)"
$seekIndex = $keyIndex + $nameKeyBytes.Length
$newConfig = $headerBytes
$newConfig += $originalConfigBytes[64..$seekIndex]
Write-Host "Seeking to $seekIndex"
Write-Host "New config length is currently $($newConfig.Length)"
$currentNameLength = [BitConverter]::ToInt16($originalConfigBytes[($seekIndex + 1)..($seekIndex + 2)], 0)
Write-Host "Current name length is $currentNameLength"
Write-Host "Current name is $([System.Text.Encoding]::UTF8.GetString($originalConfigBytes[($seekIndex + 2)..($seekIndex + $currentNameLength + 2)]))"
$lengthBytes = [BitConverter]::GetBytes([UInt16]$nameValueBytes.Length)
$newConfig += $lengthBytes
$newConfig += $nameValueBytes
$seekIndex += 3
$seekIndex += $currentNameLength
Write-Host "Current seek is $seekIndex"
Write-Host "New name length is $($nameValueBytes.Length)"
$newConfig += $originalConfigBytes[$seekIndex..($originalConfigBytes.Length - 1)]
[System.IO.File]::WriteAllBytes("$configFilePath", $newConfig)
}