Skip to content

Instantly share code, notes, and snippets.

@jbarrett
Last active July 16, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarrett/e5fefc9b45c6fde7d1eec909094694c2 to your computer and use it in GitHub Desktop.
Save jbarrett/e5fefc9b45c6fde7d1eec909094694c2 to your computer and use it in GitHub Desktop.
SimCity 3000 Widescreen hack - run from same dir as SC3.EXE / SC3U.EXE
#!/usr/bin/env perl
use strict;
use warnings;
use bytes;
use Carp;
use File::Copy qw/ cp /;
# See: http://www.wsgf.org/dr/simcity-3000/en
my $exe = ( -f 'SC3.EXE' ) ? 'SC3.EXE' : 'SC3U.EXE';
my $backup = 0;
open my $fh, '+<:raw', $exe
or die("Unable to open Simcity 3000 EXE, please run from SC3000 install dir");
# Sliding window search or just use all the RAMs?
my $binary;
{
local $/;
$binary = <$fh>;
};
my $find = {
'8b 4c 24 04 8b 44 24 08 53' => 'c2 08 00 90',
'8b 4c 24 04 8b 54 24 08 81 f9' => 'c2 08 00 90',
};
for ( keys %{$find} ) {
my $string = join '', map chr hex, split ' ', $_;
my $replace = join '', map chr hex, split ' ', $find->{$_};
my $offset = index( $binary, $string );
croak "Cannot find string - $exe already patched?" if $offset < 0;
if ( !$backup ) {
printf "Creating backup...\n";
cp $exe, "$exe.bak-" . time;
$backup = 1;
}
sysseek $fh, $offset, 0;
syswrite $fh, pack( 'a4', $replace ), 4;
}
printf "$exe patched!\n";
@jbarrett
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment