Restunts

From Stunts Wiki

Restunts is the name given to a project originally started in the community with the purpose of disassembling Stunts and then translating it to C and thus obtain a source code we can handle and modify. This was desired because attempts to get to the original source code failed and it appears to not exist anymore. Nowadays, the term sometimes extends to other related efforts, which include modification and recompilation of the assembly source code as well as recreation of parts of the code.

Many extensive forum threads make up vital parts of the history and progress of the project. At its current stage, the dissassembly was completed and recompilation was achieved successfully. Some mods have been created based on this source code and a huge amount of information was learned from reading and analysing it. The knowledge of the Stunts internals has increased significantly thanks to this project and variables and structures have been named and tagged, while the source is already very well commented in many sections. On the other hand, translation into C is minimal as of November 2023.

The source code in its current status has been mirrored and can be found at https://bitbucket.org/dreadnaut/restunts/

History

During the decade of 2000, there had been several moments when wishes of getting the original game source code were expressed. At some point, the community managed to get in touch the Stunts' main programmer Kevin Pickell, who said he didn't have the source and that it was almost certainly lost. With time, there were fewer talks about finding that source code and more about reverse engineering the game one day.

In July 2004, a forum thread was started by user Cyberman in which he tells about his observations on file compression in Stunts. He noticed that the "P" in file extensions stands for "packed". He later continues to notice that the main executable appears to be combined with DIF files for the different graphics cards. While this thread does not progress much at that point, it would later become a spark that starts a fire.

In May 2006, an anonymous user started this one asking about obtaining the source code. Bonzai Joe answers that Kevin Pickell has already said the source code does not exist any more. Cas says later that he has begun disassembling LOAD.EXE, but it's very large and would be better to split it and work in a team. He managed to decompress the binary, but he didn't combine it with the DIF files at that point. This was later abandoned when Cas entered hiatus. Yet, he does talk about what the different car files contain, showing that this was already well known back then. He says he has disassembled STUNTS.COM and that it's nothing but a loader for LOAD.EXE that passes parameters based on the configuration.

In March 2008, dstien posts his analysis on RES files in the first thread and later, he mentions that he has reversed the first decompession pass. Soon, many community members become interested in start participating. This marks the beginning of the complete understanding of Stunts data files and opens the door to car making, among many other things. Another great contributor throughout this thread is Duplode. This investigation apparently led to the development of wiki articles such as: Resource file format.

In January 2009 another forum thread was started by llm, which might be the first thread in the reverse-engineering section of the forum, in which he described his first efforts in decompressing LOAD.EXE. dstien says in his thread that he has been working on this too and that he intends to find the way to combine LOAD.EXE with the DIF files to produce a static binary and make it easier to reverse-engineer the code. In 22 January, Cas posts a Zip file in this thread with what he's been doing. This includes the assembly source for STUNTS.COM as well as the beginning of LOAD.EXE after being unpacked, but not combined. The amount of code is significant considering it's been done manually. At this point, the Reverse Engineering subforum was created.

In October 2009, clvn started this thread about bypassing LOAD.EXE, in which he describes the procedure to combine the binary with the HDR/CMN/COD/DIF files for the different graphics cards. It's at this point that in becomes a lot more straightforward to decompile Stunts. Soon after, the whole code was extracted and it became possible to recompile it to the same GAME.EXE binary. A lot of effort was put in using debugging symbol names and quite some human analysis to comment much of the code and assign function, variable and label names. Still, some large parts of the code remain quite obscure.

Some small parts, especially the loading sections of the code, have already been ported to C.

Program Structure

Stunts main executable is called LOAD.EXE. In the form it's originally distributed, it has a compression layer based on EXEPACK. When run, it quickly proceeds to decompress in memory and run from there. LOAD.EXE accepts command line parameters to specify graphics card and sound driver. Depending on the graphics card, it reads HDR/COD/CMN/DIF files which are then decompressed in memory as well and combined with the code. From that point onwards, the actual game code begins executing.

Most distributions of Stunts (if not all) include a loader called STUNTS.COM, a tiny assembly-language program that reads the configuration from SETUP.CFG and passes parameters to LOAD.EXE based on the contents. This way, SETUP.EXE will be able to make it more comfortable for the user to configure and run the game.

Many distributions also have a crack like STUNT.COM or STUNTS_K.EXE that disable the copy protection system by acting on the game binary code while load in memory.

Restunts main executable (usually called GAME.EXE) is produced by eliminating the EXEPACK layer from LOAD.EXE and combining it with the video files on disk so that it no longer needs to combine in memory. This results in a much larger executable file, but one that's much simpler to analyse, decompile and mod. One byte is usually changed in the file: the flag that marks whether the copy protection system has already been disabled by the user. This means a crack is no longer necessary either.

Mods

A number of mods have been made by making changes to the Restunts code and recompiling it, plus, in some cases, creating graphics and other data. Some notable ones are: