Battlefield 1942

From LANCommander
Revision as of 02:02, 6 January 2024 by DoctorDalek (talk | contribs) (Fixes to deprecated PowerShell scripts)
Developers
Digital Illusions CE
Publishers
Electronic ArtsAspyr Media
Release Date
Windows: September 10, 2002
Genres
Shooter
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play Battlefield 1942: Secret Weapons of WWII {InstallDir}\BF1942.exe +game XPack2 True
Play Battlefield 1942 {InstallDir}\BF1942.exe True
Play Battlefield 1942: The Road to Rome {InstallDir}\BF1942.exe +game XPack1 True

Install Script

#######################################################################
#Updates Screen Resolution to match desktop resolution
#######################################################################

$Config1 = "$InstallDirectory\ProfileTemplate\Video.con"
$Config2 = "$InstallDirectory\ProfileTemplate\VideoCustom.con"
$Config3 = "$InstallDirectory\Mods\bf1942\Settings\Profiles\Custom\Video.con"
$Config4 = "$InstallDirectory\Mods\bf1942\Settings\Profiles\Custom\VideoCustom.con"

# 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 '^game.setGameDisplayMode (.+)' -Substitution "game.setGameDisplayMode $($Display.Bounds.Width) $($Display.Bounds.Height) 32 60" -FilePath "$Config1"
Write-ReplaceContentInFile -Pattern '^game.setGameDisplayMode (.+)' -Substitution "game.setGameDisplayMode $($Display.Bounds.Width) $($Display.Bounds.Height) 32 60" -FilePath "$Config2"
Write-ReplaceContentInFile -Pattern '^game.setGameDisplayMode (.+)' -Substitution "game.setGameDisplayMode $($Display.Bounds.Width) $($Display.Bounds.Height) 32 0" -FilePath "$Config3"
Write-ReplaceContentInFile -Pattern '^game.setGameDisplayMode (.+)' -Substitution "game.setGameDisplayMode $($Display.Bounds.Width) $($Display.Bounds.Height) 32 0" -FilePath "$Config4"

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

Name Change Script

A template profile is copied from the base game directory and some files have to be modified to set the primary selected profile.

# Clear out any existing profile with the same name
Remove-Item "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Recurse -ErrorAction Ignore

if ($OldPlayerAlias -ne "") {
    if (Test-Path -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$OldPlayerAlias") {
        # Profile exists with old name
        Move-Item -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$OldPlayerAlias" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Force
    } else {
        # Old profile doesn't exist, scaffold a new one
        Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Recurse
    }
} else {
    # New install, scaffold new profile
    Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Recurse
}

Write-ReplaceContentInFile -Pattern 'rem \*\* (.+) \*\*' -Substitution "rem ** $NewPlayerAlias **" -FilePath "$InstallDirectory\Mods\bf1942\Settings\Profile.con"
Write-ReplaceContentInFile -Pattern 'game.setProfile "(.+)"' -Substitution "game.setProfile ""$NewPlayerAlias""" -FilePath "$InstallDirectory\Mods\bf1942\Settings\Profile.con"

Write-ReplaceContentInFile -Pattern 'game.setPlayerName "(.+)"' -Substitution "game.setPlayerName ""$NewPlayerAlias""" -FilePath "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias\GeneralOptions.con"