$Display = Get-PrimaryDisplay
Write-ReplaceContentInFile -Pattern '^ResX=(.+)' -Substitution "ResX=$($Display.Bounds.Width)" -FilePath "$InstallDirectory\scripts\NFSUnderground2.WidescreenFix.ini"
Write-ReplaceContentInFile -Pattern '^ResY=(.+)' -Substitution "ResY=$($Display.Bounds.Height)" -FilePath "$InstallDirectory\scripts\NFSUnderground2.WidescreenFix.ini"
$NewPlayerAlias = $NewPlayerAlias.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'
$OldPlayerAlias = $OldPlayerAlias.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'
if ($NewPlayerAlias.Length -gt 7) {
$NewPlayerAlias = $NewPlayerAlias.Substring(0, 7);
}
if ($OldPlayerAlias.Length -gt 7) {
$OldPlayerAlias = $OldPlayerAlias.Substring(0, 7);
}
if ((![string]::IsNullOrWhitespace($OldPlayerAlias)) -and (Test-Path "$InstallDirectory\Profiles\NFS Underground 2\$OldPlayerAlias")) {
Rename-Item -Path "$InstallDirectory\Profiles\NFS Underground 2\$OldPlayerAlias\$OldPlayerAlias" -NewName "$NewPlayerAlias"
Rename-Item -Path "$InstallDirectory\Profiles\NFS Underground 2\$OldPlayerAlias" -NewName "$NewPlayerAlias"
} else {
Write-Host "Creating profile directory"
New-Item -ItemType Directory -Force -Path "$InstallDirectory\Profiles\NFS Underground 2"
Write-Host "Copying template profile"
Copy-Item -Path "$InstallDirectory\Profiles\Template" -Destination "$InstallDirectory\Profiles\NFS Underground 2\$NewPlayerAlias" -Recurse
Write-Host "Renaming template profile folder"
Rename-Item -Path "$InstallDirectory\Profiles\NFS Underground 2\$NewPlayerAlias\Template" -NewName "$NewPlayerAlias"
}
Write-Host "Patching save file"
$bytes = ConvertTo-StringBytes -Input $NewPlayerAlias -MaxLength 7 -MinLength 7
Edit-PatchBinary -FilePath "$InstallDirectory\Profiles\NFS Underground 2\$NewPlayerAlias\$NewPlayerAlias" -Offset 0xD225 -Data $bytes
Read-Host