Serious Sam: The First Encounter: Difference between revisions

From LANCommander
(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...")
 
No edit summary
 
Line 9: Line 9:
{{Game.InfoBox.ReleaseDate|Windows|March 1, 2001}}
{{Game.InfoBox.ReleaseDate|Windows|March 1, 2001}}
|Genres =
|Genres =
{{Game.InfoBox.Genre|Indie}}
{{Game.InfoBox.Genre|Indie}}{{Game.InfoBox.Genre|Shooter}}
{{Game.InfoBox.Genre|Shooter}}
|PCGamingWiki = Serious_Sam:_The_First_Encounter}}
| PCGamingWiki = Serious_Sam:_The_First_Encounter
}}


{{Game.ActionBox
{{Game.ActionBox
|Actions =  
|Actions =  
{{Game.ActionBox.Row|Name = Play|Path = Bin/SeriousSam.exe|Arguments = |WorkingDirectory = |Primary = True}}
{{Game.ActionBox.Row|Name = Play|Path = {InstallDir}\Bin/SeriousSam.exe|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 =
$NewName = $args[0]
<syntaxhighlight lang="powershell" line>
$InstallDir = $PSScriptRoot
# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay


function Get-AsciiBytes([string]$InputString, [int]$MaxLength)
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
{
Write-ReplaceContentInFile -Pattern '^persistent extern INDEX sam_iScreenSizeI=\(INDEX\)(\d+);' -Substitution "persistent extern INDEX sam_iScreenSizeI=(INDEX)$($Display.Bounds.Width);" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"
    if ($InputString.Length -gt $MaxLength)
Write-ReplaceContentInFile -Pattern '^persistent extern INDEX sam_iScreenSizeJ=\(INDEX\)(\d+);' -Substitution "persistent extern INDEX sam_iScreenSizeJ=(INDEX)$($Display.Bounds.Height);" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"
    {
        $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++)
# Might need to set FOV
    {
$FOV = 90
        $bytes[$Offset + $i] = $Data[$i]
    }


    [System.IO.File]::WriteAllBytes($FilePath, $bytes)
if (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 9)) {
    $FOV = 105
} elseif (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 10)) {
    $FOV = 100
}
}


$nameBytes = Get-AsciiBytes -InputString $NewName -MaxLength 11
Write-ReplaceContentInFile -Pattern '^persistent extern user FLOAT plr_fFOV=\(FLOAT\)(\d+);' -Substitution "persistent extern FLOAT plr_fFOV=\(FLOAT\)$FOV;" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"
$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
</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>
Add-Type -AssemblyName System.Windows.Forms
# Converts a string to a UTF16-encoded byte array. This looks like ASCII characters separated by 0x00 in most cases.
$Display = [System.Windows.Forms.Screen]::AllScreens | Where-Object Primary | Select Bounds
$nameBytes = ConvertTo-StringBytes -Input $NewPlayerAlias -MaxLength 11 -MinLength 11
 
$teamBytes = ConvertTo-StringBytes -Input "Vintage" -MaxLength 7 -MinLength 7
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) {
Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$InstallDirectory\Players\Player0.plr"
        return @{ Width = $Width; Height = [math]::Round($Width / $ratio) }
    }
}


function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
Edit-PatchBinary -FilePath "$InstallDirectory\Players\Player0.plr" -Offset 0x8 -Data $nameBytes
{
Edit-PatchBinary -FilePath "$InstallDirectory\Players\Player0.plr" -Offset 0x17 -Data $teamBytes
    $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"
</syntaxhighlight>
</syntaxhighlight>
}}
}}

Latest revision as of 21:54, 8 January 2024

Developers
Croteam
Publishers
Gathering of Developers
Release Date
Windows: March 1, 2001
Genres
IndieShooter
View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play {InstallDir}\Bin/SeriousSam.exe True

Install Script

# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay

# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Pattern '^persistent extern INDEX sam_iScreenSizeI=\(INDEX\)(\d+);' -Substitution "persistent extern INDEX sam_iScreenSizeI=(INDEX)$($Display.Bounds.Width);" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"
Write-ReplaceContentInFile -Pattern '^persistent extern INDEX sam_iScreenSizeJ=\(INDEX\)(\d+);' -Substitution "persistent extern INDEX sam_iScreenSizeJ=(INDEX)$($Display.Bounds.Height);" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"

# Might need to set FOV
$FOV = 90

if (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 9)) {
    $FOV = 105
} elseif (($Display.Bounds.Width / $Display.Bounds.Height) -eq (16 / 10)) {
    $FOV = 100
}

Write-ReplaceContentInFile -Pattern '^persistent extern user FLOAT plr_fFOV=\(FLOAT\)(\d+);' -Substitution "persistent extern FLOAT plr_fFOV=\(FLOAT\)$FOV;" -FilePath "$InstallDirectory\Scripts\PersistentSymbols.ini"

Name Change Script

# Converts a string to a UTF16-encoded byte array. This looks like ASCII characters separated by 0x00 in most cases.
$nameBytes = ConvertTo-StringBytes -Input $NewPlayerAlias -MaxLength 11 -MinLength 11
$teamBytes = ConvertTo-StringBytes -Input "Vintage" -MaxLength 7 -MinLength 7

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

Edit-PatchBinary -FilePath "$InstallDirectory\Players\Player0.plr" -Offset 0x8 -Data $nameBytes
Edit-PatchBinary -FilePath "$InstallDirectory\Players\Player0.plr" -Offset 0x17 -Data $teamBytes