Added hitdump. It's not yet complete in the sense that it can tolerate any input file you give it, but it can correctly disassemble every HIT file in both games now.

This commit is contained in:
Fatbag 2012-07-26 13:35:45 -05:00
parent 90c703188b
commit 6b0b0c1d9c
9 changed files with 1121 additions and 88 deletions

View file

@ -62,11 +62,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
endif()
# Size
set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -mstringop-strategy=rep_byte")
set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fsched-pressure -mstringop-strategy=rep_byte")
set(LDFLAGS_SIZE "${LDFLAGS} -s -fwhole-program")
# Speed
set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -flto")
set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -flto")
set(LDFLAGS_SPEED "${LDFLAGS} -s -fwhole-program -flto")
else()
# Debug

View file

@ -150,7 +150,7 @@ int main(int argc, char *argv[]){
printf("File \"%s\" exists.\nContinue anyway? (y/n) ", OutFile);
c = getchar();
if(c != 'y' && c != 'Y'){
printf("\nAborted.");
printf("\nAborted.\n");
return -1;
}
}

View file

@ -146,7 +146,7 @@ int main(int argc, char *argv[]){
printf("File \"%s\" exists.\nContinue anyway? (y/n) ", OutFile);
c = getchar();
if(c != 'y' && c != 'Y'){
printf("\nAborted.");
printf("\nAborted.\n");
return -1;
}
}

View file

@ -2,15 +2,15 @@ cmake_minimum_required(VERSION 2.6)
project(hitutils)
set(HITDUMP_SOURCES
hitdump.cpp
hitdump.c
)
set(HITASM_SOURCES
hitasm.cpp
hitasm.c
)
set(HITLD_SOURCES
hitld.cpp
hitld.c
)
add_executable(hitdump ${HITDUMP_SOURCES})

59
Tools/hitutils/Design.txt Normal file
View file

@ -0,0 +1,59 @@
1. Dumping
A HIT file is dumped by running this command:
$ hitdump -o example.txt example.hit
This will disassemble example.hit into example.txt using MakeTrax syntax.
* Instructions, arguments, registers, and globals are rewritten using the mnemonics in
example.hsm.
* The disassembly is split into BINARY[] sections and logical addresses are defined names
using the data provided by example.hsm, example.hot, example.evt, and the HIT symbol table.
All user-created constants in example.hsm that begin with "tkd_" are interpreted by
hitutils as track data.
2. Reassembling
A source file is assembled into an intermediate object by running this command:
$ hitasm -o example.o example.txt
This will assemble example.txt into example.o according to MakeTrax syntax.
* Instructions, arguments, and registers are interpreted using the mnemonics in example.hsm.
* The logical addresses defined in example.hsm are ignored.
3. Relinking into the game
Object files are relinked into the game by running this command:
$ hitld -o example.hit example1.o example2.o ...
This will link example1.o, example2.o, and so on into example.hit and reconstruct the
relocation tables in example.hot and example.hsm.
To clarify, the user cannot change the events signaled by objects without changing the
SimAntics of each of those objects. The HIT subroutines invoked by those events, however, can
be changed or swapped out quite easily.
Appendix A. Address labeling strategies
In TSO, the HIT symbol table lists the logical address of each exported function, along with
the Track File ID associated with it.
In TSO, the EVT file lists the name of each exported function, along with the Track File ID
associated with it.
* The HIT file can be used to locate each exported function for placement in BINARY[] sections.
* In the case of tsov2.hit, the HIT and EVT files can be used together to name these exported
functions, seeing that the HSM file is not provided.
The HOT file lists all addresses that were labelled, along with the Track File ID associated
with it, in the TrackData section. Because the HIT symbol table is not included in The Sims 1,
the TrackData section can be used instead.
The HSM file lists the name of each labelled address, along with its logical address in the
HIT file. (This is done with a Ctrl+F for "tkd_").

View file

@ -1,6 +1,6 @@
/*
hitutils - The Sims HIT (dis)assembler and linker
hitasm.cpp - Copyright (c) 2012 Niotso Project <http://niotso.org/>
hitasm.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any

1049
Tools/hitutils/hitdump.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
hitutils - The Sims HIT (dis)assembler and linker
hitdump.cpp - Copyright (c) 2012 Niotso Project <http://niotso.org/>
hitld.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
@ -19,12 +19,10 @@
#include <stdio.h>
int main(){
printf("Usage: hitdump [-f] [-o outfile.txt] [-hsm outfile.hsm]\n"
" [-hot outfile.hot] infile.hit\n"
"Disassemble a HIT binary.\n"
"\n"
"The HSM and HOT files contain necessary information and are\n"
"required as inputs.\n"
printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n"
" outfile.hit INFILES\n"
"Link object files produced by hitasm into a HIT binary, and\n"
"relink the game's HSM and HOT files.\n"
"Use -f to force overwriting without confirmation.\n"
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"

View file

@ -1,73 +0,0 @@
/*
hitutils - The Sims HIT (dis)assembler and linker
hitld.cpp - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[]){
unsigned objectcount;
int arg;
/****
** Parameter extraction
*/
if(argc < 3 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n"
" outfile.hit INFILES\n"
"Link object files produced by hitasm into a HIT binary, and\n"
"relink the game's HSM and HOT files.\n"
"Use -f to force overwriting without confirmation.\n"
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"
"hitutils is maintained by the Niotso project.\n"
"Home page: <http://www.niotso.org/>\n");
return 0;
}
const char * hitfile;
char * hsmfile = NULL, * hotfile = NULL;
bool force = false;
for(arg=1; arg<argc-2; arg++){
if(!strcmp(argv[arg], "-f")) force = true;
else if(arg<argc-3 && !strcmp(argv[arg], "-hsm")) hsmfile = argv[++arg];
else if(arg<argc-3 && !strcmp(argv[arg], "-hot")) hotfile = argv[++arg];
else break;
}
hitfile = argv[arg++];
objectcount = argc-arg; //Guaranteed to be >=1
for(int i=0, length = strlen(hitfile); i<2; i++){
char *& string = (i==0) ? hsmfile : hotfile;
if(!string){
string = (char*) malloc(length+1);
strcpy(string, hitfile);
for(int j=1; j<=3 && j<=length; j++){
const char * ext = "hsmhot";
string[length-j] = ext[3*i + 3-j];
}
}
}
printf("Force: %s\nHSM file: %s\nHOT file: %s\nHIT file: %s\nObject count: %u",
force ? "yes" : "no", hsmfile, hotfile, hitfile, objectcount);
return 0;
}