# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Pattern '^FullscreenViewportX=(.+)' -Substitution "FullscreenViewportX=$($Display.Bounds.Width)" -FilePath "$InstallDirectory\System\UT2004.ini"
Write-ReplaceContentInFile -Pattern '^FullscreenViewportY=(.+)' -Substitution "FullscreenViewportY=$($Display.Bounds.Height)" -FilePath "$InstallDirectory\System\UT2004.ini"
# Might need to set FOV
$FOV = 90
if (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 9)) {
$FOV = 106
} elseif (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 10)) {
$FOV = 100
}
Write-ReplaceContentInFile -Pattern '^DesiredFOV=(.+)' -Substitution "DesiredFOV=$FOV" -FilePath "$InstallDirectory\System\UT2004.ini"
Write-ReplaceContentInFile -Pattern '^DefaultFOV=(.+)' -Substitution "DefaultFOV=$FOV" -FilePath "$InstallDirectory\System\UT2004.ini"
Write-ReplaceContentInFile -Pattern '^FOVAngle=(.+)' -Substitution "DefaultFOV=$FOV.0" -FilePath "$InstallDirectory\System\UT2004.ini"
# Turns off Gamespy Stats & Replaces utmaster servers
Write-ReplaceContentInFile -Pattern '^UplinkToGamespy=(.+)' -Substitution "UplinkToGamespy=False" -FilePath "$InstallDirectory\System\UT2004.ini"
Write-ReplaceContentInFile -Pattern '^MasterServerList=(Address="ut2004master1.epicgames.com",Port=28902' -Substitution 'MasterServerList=(Address="utmaster.openspy.net",Port=28902' -FilePath "$InstallDirectory\System\UT2004.ini"
Write-ReplaceContentInFile -Pattern '^MasterServerList=(Address="ut2004master2.epicgames.com",Port=28902' -Substitution 'MasterServerList=(Address="ut2004master.333networks.com",Port=28902' -FilePath "$InstallDirectory\System\UT2004.ini"
$VirtualStore = "registry::\HKEY_LOCAL_MACHINE\SOFTWARE"
# Creates or updates a key in the registry
# Non-destructively creates path in registry
New-Item -Path "$VirtualStore\WOW6432Node\Unreal Technology"
New-Item -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps"
New-Item -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004"
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "Version" -Value "1" -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "CDKey" -Value "3QHVC-DHA9K-A84RE-KYRT4" -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "ADMIN_RIGHTS" -Value "You need to run this program as an administrator, not as a guest or limited user account." -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "NO_DISC" -Value "No disc in drive. Please insert the disc labeled 'Unreal Tournament 2004 Play Disc' to continue." -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "NO_DRIVE" -Value "No CD-ROM or DVD-ROM drive detected." -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "TITLEBAR" -Value "Unreal Tournament 2004" -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "WRONG_DISC" -Value "Wrong disc in drive. Please insert the disc labeled 'Unreal Tournament 2004 Play Disc' to continue." -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "YEAR" -Value "2004" -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Name "Folder" -Value "$InstallDirectory" -Force
Start-Sleep 10
$VirtualStore = "Registry::\HKEY_LOCAL_MACHINE\SOFTWARE"
Remove-Item -Path "$VirtualStore\WOW6432Node\Unreal Technology\Installed Apps\UT2004" -Force -Recurse
$VirtualStore = "Registry::\HKEY_LOCAL_MACHINE\SOFTWARE"
New-ItemProperty -Path "$VirtualStore\Wow6432Node\Unreal Technology\Installed Apps\UT2004" -Name "CDKey" -Value "$AllocatedKey" -Force
Write-ReplaceContentInFile -Pattern 'Name=(.+)' -Substitution "Name=$NewPlayerAlias" -FilePath "$InstallDirectory\System\User.ini"