#######################################################################
#Updates Screen Resolution to match desktop resolution
#######################################################################
# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay
Set-Content -Path "$InstallDirectory\bf2.bat" -Value "bf2.exe +szx $($Display.Bounds.Width) +szy $($Display.Bounds.Height) +widescreen 1 +restart" -force
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$env:userprofile\Documents\Battlefield 2" -force -Recurse
#######################################################################
Remove-item -path "$env:userprofile\Documents\Battlefield 2" -recurse -force
Remove-Item -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Electronic Arts\EA Games\Battlefield 2" -force -recurse
Remove-Item -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Electronic Arts\EA Games\Battlefield 2 Special Forces" -force -recurse
Write-ReplaceContentInFile -Pattern 'LocalProfile.setName "(.+)"' -Substitution "LocalProfile.setName ""$NewPlayerAlias""" -FilePath "$env:userprofile\Documents\Battlefield 2\Profiles\0001\Profile.con"
Write-ReplaceContentInFile -Pattern 'LocalProfile.setNick "(.+)"' -Substitution "LocalProfile.setNick ""$NewPlayerAlias""" -FilePath "$env:userprofile\Documents\Battlefield 2\Profiles\0001\Profile.con"
Write-ReplaceContentInFile -Pattern 'LocalProfile.setName "(.+)"' -Substitution "LocalProfile.setName ""$NewPlayerAlias""" -FilePath "$env:userprofile\Documents\Battlefield 2\Profiles\Default\Profile.con"
Write-ReplaceContentInFile -Pattern 'LocalProfile.setNick "(.+)"' -Substitution "LocalProfile.setNick ""$NewPlayerAlias""" -FilePath "$env:userprofile\Documents\Battlefield 2\Profiles\Default\Profile.con"
New-Item -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Electronic Arts\EA Games\Battlefield 2\ergc"
New-ItemProperty -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Electronic Arts\EA GAMES\Battlefield 2\ergc" -Name "@" -Value "x9392$AllocatedKey" -Force
New-Item -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Electronic Arts\EA Games\Battlefield 2 Special Forces\ergc"
New-ItemProperty -Path "registry::\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Electronic Arts\EA GAMES\Battlefield 2 Special Forcers\ergc" -Name "@" -Value "x9392$AllocatedKey" -Force