Red Faction

From LANCommander
Revision as of 01:25, 1 August 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{Game.InfoBox |Cover = cover.jpg |Developers = {{Game.InfoBox.Developer|Volition}} |Publishers = {{Game.InfoBox.Publisher|THQ}} {{Game.InfoBox.Publisher|THQ Nordic}} {{Game.InfoBox.Publisher|Graphsim Entertainment}} {{Game.InfoBox.Publisher|Deep Silver}} |Release Date = {{Game.InfoBox.ReleaseDate|Windows|May 21, 2001}} |Genres = {{Game.InfoBox.Genre|Adventure}} {{Game.InfoBox.Genre|Shooter}} | PCGamingWiki = Red_Faction }} {{Game.ActionBox |Actions =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Developers
Volition
Publishers
THQ

THQ Nordic Graphsim Entertainment

Deep Silver
Release Date
Windows: May 21, 2001
Genres
Adventure

Shooter

View at PCGamingWiki

Actions

Name Path Arguments Working Directory Primary
Play RF.exe True
Run Setup RedFaction.exe False

Name Change Script

Red Faction stores the player name in the file players.cfg. This file stores the multiplayer name for the player in three locations in the first 263 bytes of the file. There is no visible checksum to this section of the file and can be modified freely. There is some extra data after the player name that cannot be modified and will mess up the config. However, we can make a default name that is 20 characters long and replace them as needed. If our name is shorter than 20 bytes, 0x00 is written to make up to 20 bytes. The game will trim these values for us and reconstruct the cfg file.

$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++)
    {
        $bytes += 0x00
    }

    return $bytes
}

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

$Default = ([byte[]](0x1B, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x00, 0xF2, 0x1F, 0x77, 0xB4, 0xF3, 0x00, 0x00, 0xB3, 0xF1, 0x00, 0x42, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x01, 0x29, 0x01, 0x02, 0x00, 0x00, 0x00, 0x40, 0xA2, 0xFF, 0x10, 0x40, 0xA2, 0xFF, 0x10, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x97, 0x03, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x26, 0x02, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x1E, 0x04, 0xA0, 0x3A, 0x1E, 0x04, 0x01, 0x00, 0x00, 0x00, 0xB3, 0xF1, 0x00, 0x00, 0x88, 0x33, 0x01, 0x01, 0x04, 0x00, 0x00, 0x00, 0x34, 0x68, 0xA8, 0x76, 0x00, 0x00, 0x00, 0x00, 0x88, 0x48, 0xCD, 0x0F, 0x70, 0xF7, 0x19, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x07, 0x00, 0x0F, 0x00, 0x0E, 0x00, 0x10, 0x00, 0x05, 0x00, 0x06, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x09, 0x00, 0x0B, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0D, 0x00))
$NewNameHex = Get-AsciiBytes -InputString $NewName -MaxLength 20

Patch-Binary -FilePath "$InstallDir\players.cfg" -Offset 0x00 -Data $Default
Patch-Binary -FilePath "$InstallDir\players.cfg" -Offset 0x01 -Data $NewNameHex
Patch-Binary -FilePath "$InstallDir\players.cfg" -Offset 0x21 -Data $NewNameHex
Patch-Binary -FilePath "$InstallDir\players.cfg" -Offset 0x55 -Data $NewNameHex