Serious Sam: The First Encounter

From LANCommander
Revision as of 01:26, 1 August 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Developers = {{Game.InfoBox.Developer|Croteam}} |Publishers = {{Game.InfoBox.Publisher|Gathering of Developers}} |Release Date = {{Game.InfoBox.ReleaseDate|Windows|March 1, 2001}} |Genres = {{Game.InfoBox.Genre|Indie}} {{Game.InfoBox.Genre|Shooter}} | PCGamingWiki = Serious_Sam:_The_First_Encounter }} {{Game.ActionBox |Actions = {{Game.ActionBox.Row|Name = Play|Path = Bin/SeriousSam.exe|Arguments = |WorkingDirectory...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Developers
Croteam
Publishers
Gathering of Developers
Release Date
Windows: March 1, 2001
Genres
Indie

Shooter

View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play Bin/SeriousSam.exe True

Name Change Script

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

function Get-AsciiBytes([string]$InputString, [int]$MaxLength)
{
    if ($InputString.Length -gt $MaxLength)
    {
        $InputString = $InputString.Substring(0, $MaxLength)
    }

    $bytes = [System.Text.Encoding]::ASCII.GetBytes($InputString)
    $array = @()
    $count = 0

    $extraPadding = $MaxLength - $bytes.Length

    foreach ($byte in $bytes)
    {
        if ($count -lt $MaxLength)
        {
            $array += $byte
            $count++
        }
    }

    for ($i = $count; $i -lt $MaxLength; $i++)
    {
        $array += 0x00
    }

    return $array
}

function Patch-Binary([byte[]]$Data, [int]$Offset, [string]$FilePath)
{
    $bytes = [System.IO.File]::ReadAllBytes($FilePath)

    for ($i = 0; $i -lt $Data.Length; $i++)
    {
        $bytes[$Offset + $i] = $Data[$i]
    }

    [System.IO.File]::WriteAllBytes($FilePath, $bytes)
}

$nameBytes = Get-AsciiBytes -InputString $NewName -MaxLength 11
$teamBytes = Get-AsciiBytes -InputString "Vintage" -MaxLength 7

Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$InstallDir\Players\Player0.plr"

Patch-Binary -FilePath "$InstallDir\Players\Player0.plr" -Offset 0x8 -Data $nameBytes
Patch-Binary -FilePath "$InstallDir\Players\Player0.plr" -Offset 0x17 -Data $teamBytes

Install Script

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

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

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

# 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 '^persistent extern INDEX sam_iScreenSizeI=\(INDEX\)(\d+);' -Replacement "persistent extern INDEX sam_iScreenSizeI=(INDEX)$($Resolution.Width);" -FilePath "$InstallDir\Scripts\PersistentSymbols.ini"
Write-ReplaceContentInFile -Regex '^persistent extern INDEX sam_iScreenSizeJ=\(INDEX\)(\d+);' -Replacement "persistent extern INDEX sam_iScreenSizeJ=(INDEX)$($Resolution.Height);" -FilePath "$InstallDir\Scripts\PersistentSymbols.ini"