Cube 2: Sauerbraten

From LANCommander
Revision as of 07:03, 31 July 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Release Date = {{Game.InfoBox.ReleaseDate|Windows|December 31, 2004}} | PCGamingWiki = Cube_2:_Sauerbraten }} {{Game.ActionBox |Actions = {{Game.ActionBox.Row|Name = Play|Path = sauerbraten.bat|Arguments = |WorkingDirectory = |Primary = True}} }} {{Game.Scripts.NameChange |Name = Name Change Script |Description = |RequiresAdmin = False |Contents = <syntaxhighlight lang="powershell" line> $InstallDir = $PSScriptRoo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Release Date
Windows: December 31, 2004
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play sauerbraten.bat True

Name Change Script

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

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 15) {
    $NewName = $NewName.Substring(0, 15);
}

# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^name "(.+)"' -Replacement "name ""$NewName""" -FilePath "$InstallDir\config\config.cfg"
Write-ReplaceContentInFile -Regex '^newname \[.+\]' -Replacement "name ""$NewName""" -FilePath "$InstallDir\config\config.cfg"

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 '^scr_w (.+)' -Replacement "scr_w $($Display.Width)" -FilePath "$InstallDir\config\init.cfg"
Write-ReplaceContentInFile -Regex '^scr_h (.+)' -Replacement "scr_h $($Display.Height)" -FilePath "$InstallDir\config\init.cfg"