Realm Wars

From LANCommander
Revision as of 01:24, 1 August 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Release Date = {{Game.InfoBox.ReleaseDate|Windows|March 1, 2003}} }} {{Game.ActionBox |Actions = {{Game.ActionBox.Row|Name = Play|Path = RealmWars.exe|Arguments = |WorkingDirectory = |Primary = True}} }} {{Game.Scripts.Install |Name = Install Script |Description = |RequiresAdmin = False |Contents = <syntaxhighlight lang="powershell" line> $InstallDir = $PSScriptRoot Add-Type -AssemblyName System.Windows.Forms $Dis...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Release Date
Windows: March 1, 2003
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play RealmWars.exe True

Install Script

$InstallDir = $PSScriptRoot
Add-Type -AssemblyName System.Windows.Forms
$Display = [System.Windows.Forms.Screen]::AllScreens | Where-Object Primary | Select Bounds

function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [IO.File]::WriteAllLines($FilePath, $content)
}

function Get-43Resolution([int]$Width, [int]$Height) {
    $ratio = 4 / 3

    if (($Width -gt $Height) -or ($Width -eq $Height)) {
        return @{ Width = [math]::Round($ratio * $Height); Height = $Height }
    }

    if ($Width -lt $Height) {
        return @{ Width = $Width; Height = [math]::Round($Width / $ratio) }
    }
}

# Accessible via $Resolution.Height, $Resolution.Width
$Resolution = Get-43Resolution -Width $Display.Width -Height $Display.Height

# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^\$pref::Server::Info = "(.+)";' -Replacement "`$pref::Server::Info = ""Older than your mother!"";" -FilePath "$InstallDir\common\client\prefs.cs"
Write-ReplaceContentInFile -Regex '^\$pref::Server::Name = "(.+)";' -Replacement "`$pref::Server::Name = ""Vintage"";" -FilePath "$InstallDir\common\client\prefs.cs"
Write-ReplaceContentInFile -Regex '^\$pref::Server::MaxPlayers = "(.+)";' -Replacement "`$pref::Server::MaxPlayers = ""16"";" -FilePath "$InstallDir\common\client\prefs.cs"
Write-ReplaceContentInFile -Regex '^\$pref::Video::displayDevice = "(.+)";' -Replacement "`$pref::Video::displayDevice = ""OpenGL"";" -FilePath "$InstallDir\common\client\prefs.cs"
Write-ReplaceContentInFile -Regex '^\$pref::Video::fullScreen = "(.+)";' -Replacement "`$pref::Video::fullScreen = ""1"";" -FilePath "$InstallDir\common\client\prefs.cs"
Write-ReplaceContentInFile -Regex '^\$pref::Video::resolution = "(.+)";' -Replacement "`$pref::Video::resolution = ""$($Resolution.Width) $($Resolution.Height) 32"";" -FilePath "$InstallDir\common\client\prefs.cs"

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)
}

# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^\$pref::Player::Name = "(.+)";' -Replacement "`$pref::Player::Name = ""$NewName"";" -FilePath "$InstallDir\common\client\prefs.cs"