$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"
$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"