$InstallDir = $PSScriptRoot
$InstallDrive = Split-Path -Path $InstallDir -Qualifier
$User = New-Object System.Security.Principal.NTAccount($env:UserName)
$SID = $User.Translate([System.Security.Principal.SecurityIdentifier]).value
$BasePath = "registry::\HKEY_USERS\$SID\Software\Classes\VirtualStore\MACHINE\SOFTWARE\WOW6432Node\Inner Workings"
# Non-destructively creates path in registry
New-Item -Path "HKLM:\SOFTWARE\WOW6432Node\<Path>"
# The OS might force your game to read/write to the user's virtual store. This will write a key to the correct SID's virtual store.
New-Item -Path $BasePath
New-Item -Path "$BasePath\Plane Crazy"
New-Item -Path "$BasePath\Plane Crazy\1.0"
New-ItemProperty -Path "$BasePath\Plane Crazy\1.0" -Name "bRetail" -Value 1 -Force
New-ItemProperty -Path "$BasePath\Plane Crazy\1.0" -Name "Installed" -Value 1 -Force
# The following lines are required for the CD check. sNotBovine will default to the drive letter, e.g. "C:"
New-ItemProperty -Path "$BasePath\Plane Crazy\1.0" -Name "sNotBovine" -Value $InstallDrive -Force
New-ItemProperty -Path "$BasePath\Plane Crazy\1.0" -Name "sPathDataMax" -Value "$InstallDir\data\datamax" -Force
New-ItemProperty -Path "$BasePath\Plane Crazy\1.0" -Name "sPathDataMin" -Value "$InstallDir\data\datamin" -Force
$NewName = $args[0]
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)
}
# Plane Crazy stores player/plane strings in a binary .pln file in the data\DataMin\Planes directory
# The following script should change the player name in plane1.pln. THe length of the name seems to
# be arbitrary, so make sure MaxLength matches the length of the template plane1.pln file you will
# have to place at the root of the game's directory before packaging.
$bytes = Get-AsciiBytes -InputString $NewName -MaxLength 32
Copy-Item -Path "$InstallDir\Template.pln" -Destination "$InstallDir\data\DataMin\Planes\plane1.pln" -Force
# Writes byte[] to a file at an offset
Patch-Binary -FilePath "$InstallDir\data\DataMin\Planes\plane1.pln" -Offset 0x00 -Data $bytes