Battlefield 2

From LANCommander
Developers
Digital Illusions CE
Publishers
Electronic Arts
Release Date
Windows: June 21, 2005
Genres
Shooter
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play Battlefield 2 {InstallDir}\bf2.exe +szx {DisplayWidth} +szy {DisplayHeight} +menu 1 +widescreen 1 +restart 1 True

Install Script

#######################################################################
#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

#######################################################################

Uninstall Script

$VirtualStore = "registry::\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE"
$Documents = [Environment]::GetFolderPath('MyDocuments')

Remove-Item -Path "$Documents\Battlefield 2" -Recurse -Force
Remove-Item -Path "$VirtualStore\Wow6432Node\Electronic Arts\EA Games\Battlefield 2" -Force -Recurse
Remove-Item -Path "$VirtualStore\Wow6432Node\Electronic Arts\EA Games\Battlefield 2 Special Forces" -Force -Recurse

Name Change Script

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"

Key Change Script

$VirtualStore = "registry::\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE"

New-Item -Path "$VirtualStore\Wow6432Node\Electronic Arts\EA Games\Battlefield 2\ergc"
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\EA GAMES\Battlefield 2\ergc" -Name "@" -Value "x9392$AllocatedKey" -Force
New-Item -Path "$VirtualStore\Wow6432Node\Electronic Arts\EA Games\Battlefield 2 Special Forces\ergc"
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\EA GAMES\Battlefield 2 Special Forcers\ergc" -Name "@" -Value "x9392$AllocatedKey" -Force