Cube 2: Sauerbraten: Difference between revisions

From LANCommander
(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...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
{{Game.InfoBox
{{Game.InfoBox
|Cover = cover.jpg
|Cover = cover.jpg
|Developers =
|Publishers =
|Release Date =
|Release Date =
{{Game.InfoBox.ReleaseDate|Windows|December 31, 2004}}
{{Game.InfoBox.ReleaseDate|Windows|December 31, 2004}}
| PCGamingWiki = Cube_2:_Sauerbraten
|Genres =
}}
{{Game.InfoBox.Genre|Shooter}}
|PCGamingWiki = Cube_2:_Sauerbraten}}


{{Game.ActionBox
{{Game.ActionBox
|Actions =  
|Actions =  
{{Game.ActionBox.Row|Name = Play|Path = sauerbraten.bat|Arguments = |WorkingDirectory = |Primary = True}}
{{Game.ActionBox.Row|Name = Play|Path = {InstallDir}\sauerbraten.bat|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 =
$InstallDir = $PSScriptRoot
<syntaxhighlight lang="powershell" line>
$NewName = $args[0]
$Display = Get-PrimaryDisplay
$Documents = [Environment]::GetFolderPath('MyDocuments')


function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
Write-ReplaceContentInFile -Pattern '^scr_w (.+)' -Substitution "scr_w $($Display.Bounds.Width)" -FilePath "$InstallDirectory\config\init.cfg"
{
Write-ReplaceContentInFile -Pattern '^scr_h (.+)' -Substitution "scr_h $($Display.Bounds.Height)" -FilePath "$InstallDirectory\config\init.cfg"
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
Write-ReplaceContentInFile -Pattern '^scr_w (.+)' -Substitution "scr_w $($Display.Bounds.Width)" -FilePath "$Documents\My Games\Sauerbraten\init.cfg"
    [IO.File]::WriteAllLines($FilePath, $content)
Write-ReplaceContentInFile -Pattern '^scr_h (.+)' -Substitution "scr_h $($Display.Bounds.Height)" -FilePath "$Documents\My Games\Sauerbraten\init.cfg"
}
 
# 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"
</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 15) {
$Display = ([System.Windows.Forms.Screen]::AllScreens | Where-Object Primary).Bounds
     $NewPlayerAlias = $NewPlayerAlias.Substring(0, 15);
 
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 ("")
# 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 -Pattern '^name "(.+)"' -Substitution "name ""$NewPlayerAlias""" -FilePath "$InstallDirectory\config\config.cfg"
Write-ReplaceContentInFile -Regex '^scr_h (.+)' -Replacement "scr_h $($Display.Height)" -FilePath "$InstallDir\config\init.cfg"
Write-ReplaceContentInFile -Pattern '^newname \[.+\]' -Substitution "name ""$NewPlayerAlias""" -FilePath "$InstallDirectory\config\config.cfg"
</syntaxhighlight>
</syntaxhighlight>
}}
}}

Latest revision as of 00:40, 22 February 2024

Release Date
Windows: December 31, 2004
Genres
Shooter
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play {InstallDir}\sauerbraten.bat True

Install Script

$Display = Get-PrimaryDisplay
$Documents = [Environment]::GetFolderPath('MyDocuments')

Write-ReplaceContentInFile -Pattern '^scr_w (.+)' -Substitution "scr_w $($Display.Bounds.Width)" -FilePath "$InstallDirectory\config\init.cfg"
Write-ReplaceContentInFile -Pattern '^scr_h (.+)' -Substitution "scr_h $($Display.Bounds.Height)" -FilePath "$InstallDirectory\config\init.cfg"
Write-ReplaceContentInFile -Pattern '^scr_w (.+)' -Substitution "scr_w $($Display.Bounds.Width)" -FilePath "$Documents\My Games\Sauerbraten\init.cfg"
Write-ReplaceContentInFile -Pattern '^scr_h (.+)' -Substitution "scr_h $($Display.Bounds.Height)" -FilePath "$Documents\My Games\Sauerbraten\init.cfg"

Name Change Script

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

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