Battlefield 1942

From LANCommander
Revision as of 06:54, 31 July 2023 by DoctorDalek (talk | contribs)
Release Date
Windows: September 10, 2002
View at PCGamingWiki

Actions

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

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.

$NewName = $args[0]
$InstallDir = $PSScriptRoot
$OldName = ""
if ($args[1]) {
	$OldName = $args[1]
}

function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [IO.File]::WriteAllLines($FilePath, $content)
}

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

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

Write-ReplaceContentInFile -Regex 'rem \*\* (.+) \*\*' -Replacement "rem ** $NewName **" -FilePath "$InstallDir\Mods\bf1942\Settings\Profile.con"
Write-ReplaceContentInFile -Regex 'game.setProfile "(.+)"' -Replacement "game.setProfile ""$NewName""" -FilePath "$InstallDir\Mods\bf1942\Settings\Profile.con"

Write-ReplaceContentInFile -Regex 'game.setPlayerName "(.+)"' -Replacement "game.setPlayerName ""$NewName""" -FilePath "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName\GeneralOptions.con"