DEFCON

From LANCommander
Revision as of 00:25, 1 August 2023 by DoctorDalek (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Developers
Introversion Software
Publishers
Introversion Software
Release Date
Windows: September 29, 2006
Genres
Real Time Strategy (RTS)

Strategy Indie

View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play defcon_offline.exe True

Name Change Script

$NewName = $args[0]
$InstallDir = $PSScriptRoot

function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [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"

Install Script

$InstallDir = $PSScriptRoot
# Accessible via $Display.Width and $Display.Height
Add-Type -AssemblyName System.Windows.Forms
$Display = ([System.Windows.Forms.Screen]::AllScreens | Where-Object Primary).Bounds

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 -Regex '^ScreenWidth = "(.+)"' -Replacement "ScreenWidth $($Display.Width)" -FilePath "$InstallDir\preferences.txt"
Write-ReplaceContentInFile -Regex '^ScreenHeight = "(.+)"' -Replacement "ScreenHeight $($Display.Height)" -FilePath "$InstallDir\preferences.txt"