DEFCON: Difference between revisions

From LANCommander
(Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Developers = {{Game.InfoBox.Developer|Introversion Software}} |Publishers = {{Game.InfoBox.Publisher|Introversion Software}} |Release Date = {{Game.InfoBox.ReleaseDate|Windows|September 29, 2006}} |Genres = {{Game.InfoBox.Genre|Real Time Strategy (RTS)}} {{Game.InfoBox.Genre|Strategy}} {{Game.InfoBox.Genre|Indie}} | PCGamingWiki = DEFCON }} {{Game.ActionBox |Actions = {{Game.ActionBox.Row|Name = Play|Path = defcon_o...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
{{Game.InfoBox.ReleaseDate|Windows|September 29, 2006}}
{{Game.InfoBox.ReleaseDate|Windows|September 29, 2006}}
|Genres =
|Genres =
{{Game.InfoBox.Genre|Real Time Strategy (RTS)}}
{{Game.InfoBox.Genre|Indie}}{{Game.InfoBox.Genre|Real Time Strategy (RTS)}}{{Game.InfoBox.Genre|Strategy}}
{{Game.InfoBox.Genre|Strategy}}
|PCGamingWiki = DEFCON}}
{{Game.InfoBox.Genre|Indie}}
| PCGamingWiki = DEFCON
}}


{{Game.ActionBox
{{Game.ActionBox
|Actions =  
|Actions =  
{{Game.ActionBox.Row|Name = Play|Path = defcon_offline.exe|Arguments = |WorkingDirectory = |Primary = True}}
{{Game.ActionBox.Row|Name = Play|Path = {InstallDir}\defcon_offline.exe|Arguments = |WorkingDirectory = |Primary = True}}
}}
}}


{{Game.Scripts.NameChange
 
|Name = Name Change Script
{{Game.Scripts.Install
|Name = Install Script
|Description =  
|Description =  
|RequiresAdmin = False
|RequiresAdmin = False
|Contents = <syntaxhighlight lang="powershell" line>
|Contents =
$NewName = $args[0]
<syntaxhighlight lang="powershell" line>
$InstallDir = $PSScriptRoot
# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay


function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
{
Write-ReplaceContentInFile -Pattern '^ScreenWidth = "(.+)"' -Substitution "ScreenWidth $($Display.Bounds.Width)" -FilePath "$InstallDirectory\preferences.txt"
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
Write-ReplaceContentInFile -Pattern '^ScreenHeight = "(.+)"' -Substitution "ScreenHeight $($Display.Bounds.Height)" -FilePath "$InstallDirectory\preferences.txt"
    [IO.File]::WriteAllLines($FilePath, $content)
}
 
# Trim a string down to a specified amount of characters
if ($NewName.Length -gt 16) {
    $NewName = $NewName.Substring(0, 16);
}
 
Write-ReplaceContentInFile -Regex '^PlayerName = (.+)' -Replacement "PlayerName = $NewName" -FilePath "$InstallDir\preferences.txt"
</syntaxhighlight>
</syntaxhighlight>
}}
}}
 
           
{{Game.Scripts.Install
{{Game.Scripts.NameChange
|Name = Install Script
|Name = Name Change Script
|Description =  
|Description =  
|RequiresAdmin = False
|RequiresAdmin = False
|Contents = <syntaxhighlight lang="powershell" line>
|Contents =
$InstallDir = $PSScriptRoot
<syntaxhighlight lang="powershell" line>
# Accessible via $Display.Width and $Display.Height
# Trim a string down to a specified amount of characters
Add-Type -AssemblyName System.Windows.Forms
if ($NewPlayerAlias.Length -gt 16) {
$Display = ([System.Windows.Forms.Screen]::AllScreens | Where-Object Primary).Bounds
     $NewPlayerAlias = $NewPlayerAlias.Substring(0, 16);
 
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
     $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [IO.File]::WriteAllLines($FilePath, $content)
}
}


# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Pattern '^PlayerName = (.+)' -Substitution "PlayerName = $NewPlayerAlias" -FilePath "$InstallDirectory\preferences.txt"
Write-ReplaceContentInFile -Regex '^ScreenWidth = "(.+)"' -Replacement "ScreenWidth $($Display.Width)" -FilePath "$InstallDir\preferences.txt"
Write-ReplaceContentInFile -Regex '^ScreenHeight = "(.+)"' -Replacement "ScreenHeight $($Display.Height)" -FilePath "$InstallDir\preferences.txt"
</syntaxhighlight>
</syntaxhighlight>
}}
}}

Latest revision as of 00:40, 22 February 2024

Developers
Introversion Software
Publishers
Introversion Software
Release Date
Windows: September 29, 2006
Genres
IndieReal Time Strategy (RTS)Strategy
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play {InstallDir}\defcon_offline.exe True

Install Script

# 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 '^ScreenWidth = "(.+)"' -Substitution "ScreenWidth $($Display.Bounds.Width)" -FilePath "$InstallDirectory\preferences.txt"
Write-ReplaceContentInFile -Pattern '^ScreenHeight = "(.+)"' -Substitution "ScreenHeight $($Display.Bounds.Height)" -FilePath "$InstallDirectory\preferences.txt"

Name Change Script

# Trim a string down to a specified amount of characters
if ($NewPlayerAlias.Length -gt 16) {
    $NewPlayerAlias = $NewPlayerAlias.Substring(0, 16);
}

Write-ReplaceContentInFile -Pattern '^PlayerName = (.+)' -Substitution "PlayerName = $NewPlayerAlias" -FilePath "$InstallDirectory\preferences.txt"