Battlefield 1942: Difference between revisions

From LANCommander
(Created page with "Category:Games {{InfoBox.Game |Cover = cover.jpg |Developers = {{InfoBox.Game.Developer|Digital Illusions CE}} |Publishers = {{InfoBox.Game.Publisher|Electronic Arts}} {{InfoBox.Game.Publisher|Aspyr Media}} |Release Date = {{InfoBox.Game.ReleaseDate|Windows|September 10, 2002}} |Genres = {{InfoBox.Game.Genre|Shooter}} | PCGamingWiki = Battlefield_1942 }} == Name Change Script == A template profile is copied from the base game directory and some files have to be modi...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Games]]
[[Category:Games]]
{{InfoBox.Game
{{Game.InfoBox
|Cover = cover.jpg
|Cover = cover.jpg
|Developers =
|Developers =
{{InfoBox.Game.Developer|Digital Illusions CE}}
{{Game.InfoBox.Developer|Digital Illusions CE}}
|Publishers =
|Publishers =
{{InfoBox.Game.Publisher|Electronic Arts}}
{{Game.InfoBox.Publisher|Electronic Arts}}{{Game.InfoBox.Publisher|Aspyr Media}}
{{InfoBox.Game.Publisher|Aspyr Media}}
|Release Date =
|Release Date =
{{InfoBox.Game.ReleaseDate|Windows|September 10, 2002}}
{{Game.InfoBox.ReleaseDate|Windows|September 10, 2002}}
|Genres =
|Genres =
{{InfoBox.Game.Genre|Shooter}}
{{Game.InfoBox.Genre|Shooter}}
| PCGamingWiki = Battlefield_1942
|PCGamingWiki = Battlefield_1942}}
 
{{Game.ActionBox
|Actions =
{{Game.ActionBox.Row|Name = Play Battlefield 1942: Secret Weapons of WWII|Path = {InstallDir}\BF1942.exe|Arguments = +game XPack2|WorkingDirectory = |Primary = True}}
{{Game.ActionBox.Row|Name = Play Battlefield 1942|Path = {InstallDir}\BF1942.exe|Arguments = |WorkingDirectory = |Primary = True}}
{{Game.ActionBox.Row|Name = Play Battlefield 1942: The Road to Rome|Path = {InstallDir}\BF1942.exe|Arguments = +game XPack1|WorkingDirectory = |Primary = 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.
{{Game.Scripts.Install
|Name = Install Script
|Description =  
|RequiresAdmin = False
|Contents =
<syntaxhighlight lang="powershell" line>
<syntaxhighlight lang="powershell" line>
$NewName = $args[0]
#######################################################################
$InstallDir = $PSScriptRoot
#Updates Screen Resolution to match desktop resolution
$OldName = ""
#######################################################################
if ($args[1]) {
 
$OldName = $args[1]
$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"


function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
{
$Display = Get-PrimaryDisplay
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [IO.File]::WriteAllLines($FilePath, $content)
}


# Clear out any existing profile with the same name
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Remove-Item "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse -ErrorAction Ignore
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"


if ($OldName -ne "") {
#######################################################################
     if (Test-Path -Path "$InstallDir\Mods\bf1942\Settings\Profiles\$OldName") {
</syntaxhighlight>
}}
           
{{Game.Scripts.NameChange
|Name = Name Change Script
|Description = A template profile is copied from the base game directory and some files have to be modified to set the primary selected profile.
|RequiresAdmin = False
|Contents =
<syntaxhighlight lang="powershell" line>
if ($OldPlayerAlias -ne "") {
     if (Test-Path -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$OldPlayerAlias") {
         # Profile exists with old name
         # Profile exists with old name
         Move-Item -Path "$InstallDir\Mods\bf1942\Settings\Profiles\$OldName" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Force
         Move-Item -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$OldPlayerAlias" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Force
     } else {
     } else {
         # Old profile doesn't exist, scaffold a new one
         # Old profile doesn't exist, scaffold a new one
         Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse
         Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Recurse
     }
     }
} elseif (Test-Path -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias") {
    # Profile already exists, probably from a save, do nothing
} else {
} else {
     # New install, scaffold new profile
     # New install, scaffold new profile
     Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse
     Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias" -Recurse
}
}


Write-ReplaceContentInFile -Regex 'rem \*\* (.+) \*\*' -Replacement "rem ** $NewName **" -FilePath "$InstallDir\Mods\bf1942\Settings\Profile.con"
Write-ReplaceContentInFile -Pattern 'rem \*\* (.+) \*\*' -Substitution "rem ** $NewPlayerAlias **" -FilePath "$InstallDirectory\Mods\bf1942\Settings\Profile.con"
Write-ReplaceContentInFile -Regex 'game.setProfile "(.+)"' -Replacement "game.setProfile ""$NewName""" -FilePath "$InstallDir\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"
Write-ReplaceContentInFile -Regex 'game.setPlayerName "(.+)"' -Replacement "game.setPlayerName ""$NewName""" -FilePath "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName\GeneralOptions.con"
</syntaxhighlight>
</syntaxhighlight>
}}

Latest revision as of 00:38, 22 February 2024

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.

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
    }
} elseif (Test-Path -Path "$InstallDirectory\Mods\bf1942\Settings\Profiles\$NewPlayerAlias") {
    # Profile already exists, probably from a save, do nothing
} 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"