Skip to content
LostArtefactsPublic

About

Matching decompilation of Tomb Raider IV: The Last Revelation (1999), built on Linux via Wine

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1,856 Commits

Folders and files

Repository files navigation

tr04

A matching decompilation of Tomb Raider IV: The Last Revelation, the Steam Windows release, built and verified on Linux through Wine.

The goal is C and C++ source that compiles into the original machine code. During development, a DLL replaces recovered functions in a copy of the original executable, so they can be exercised in the game.

Progress

Sources

This is not a clean-room project. The references are:

  • TRX: the target's function and global names, addresses and types in docs/symbols/tr4.txt.
  • refs/tomb4-legacy: the hand decompilation, for structures and logic.
  • refs/tr02 and refs/tr03: reusable code and module layout.

IDA and Ghidra provide disassembly and pseudocode for the original binary.

Target

tomb4.exe, linked 1999-12-17, 32-bit PE with image base 0x400000. SHA-256:

1ae1e16a111598f087c661323b5e920ef8e23d922b6abf5168682e9a6ad986d1

Game files are not distributed. Supply a copy at orig/tomb4; see orig/README.md.

Toolchain

Visual C++ 6.0 SP3, run under Wine. Component versions matter:

Component Version
Compiler driver (cl.exe) 12.00.8168
C frontend (c1.dll) 12.00.8472
C++ frontend (c1xx.dll) 12.00.8472
Optimizer (c2.dll) 12.00.8447
Resource converter (cvtres.exe) 5.00.1736.1
Original assembly (Rich record) MASM 6.13.7299
Linker (link.exe) 6.00.8447

The original has linker version 6.00. Its Rich header contains compiler build 8447 (93 C and 26 C++ objects), plus build 8168 (VC6 RTM: 117 C and 2 C++ objects, the size of the runtime library's share).

The optimizer writes an object's compiler record from its own build, so the game's modules came from a c2.dll of build 8447. The Microsoft SP3 disc updates the frontends and linker but ships no optimizer; the 8447 c2.dll (SHA-256 a0cc45f8…, in config/toolchain.sha256) replaces the RTM one in the SP3 installation. For this code it generates the same instructions as RTM's 12.00.8168 in all but a few functions.

The header evidence does not establish an exact original linker build. The versions above identify the selected build tools; their file hashes are recorded in config/toolchain.sha256. The Rich IDs are decoded using richprint's compiler table.

The build uses the DirectX 6.1 SDK at C:\dx6, ahead of VC6's own DirectX 5 headers. The exact SDK revision used for the original executable is not established: the DirectX 6.0 SDK's headers differ from 6.1's only by a forward declaration and a define, neither of which changes a structure.

The compiler installation comes from Microsoft Visual C++ 6.0 Professional (X04-58170) with the English updates from the Visual Studio 6.0 SP3 disc (X04-73545).

The release flags in project.toml use /G5 /Zp1 /W3 /O2: Pentium scheduling, byte-packed structures and speed optimizations. Matching additional functions may require adjustments to these flags.

Setup

Clone with submodules, or run git submodule update --init. Requirements: Python 3.11+, just, Wine, Ghidra and Java 21. Running the game headlessly also needs Xvfb, xdotool and ImageMagick.

Place the reference checkouts at the refs/ paths above. Directories or local symlinks work; game files, references, .wine/ and build/ are ignored by Git. Initialize the prefix with WINEPREFIX="$PWD/.wine" wineboot -i, and supply the compiler's bin, include and lib directories under .wine/drive_c/msvc6sp3, with the 12.00.8447 c2.dll in bin. Install the DirectX 6.1 SDK (dx61sdkimage.exe) with just dxsdk dx61sdkimage.exe 'C:\dx6'. Supply MASM 6.13 under .wine/drive_c/masm613/bin: MASM 6.11's ML.EXE and ML.ERR updated with Microsoft's ML613 patch, a DOS program that runs in DOSBox. ml /? then reports 6.13.7299, the build the original's Rich header records. Set GHIDRA if the installation is outside the search paths in project.toml.

Workflow

Command Purpose
just analyze Analyze the original and record function sizes
just manifest Apply names and types from TRX's symbol manifest
just decompile ADDRESS Export Ghidra pseudocode
just fn NAME Look up a function in the reference source
just compare [NAME] Build and check byte parity; optionally show a function diff
just progress Rebuild the progress chart
just game Prepare the game with the replacement DLL
just run wait:10 shot:title Launch under Wine and capture a screenshot

Write recovered functions in src/, following the original module layout. Record function and global addresses in config/symbols.csv. The DLL's hook table is generated from the functions defined in the build; other symbols resolve to the original executable's addresses.

Some functions in the Steam executable are binary patches no compiler produced, such as the no-CD change in FileOpen. Their C source is the code before the patch, built for the DLL and listed in hooks.allow_diff, and src/exe/ holds the patched bytes as MASM from tools/asmgen.py for the standalone executable.

The injected polling helpers retain their original x86 register contracts in naked assembly. SW_GetSleepProc receives its module in EAX and is called only from assembly; its ordinary C prototype is enabled only for FEAT_C_ASM. The shared sleep and flag helpers retain C alternatives for FEAT=c_asm. The standalone register-saving wrappers remain in their existing MASM files.

Use one newly recovered function per commit, with a subject such as Decompile NAME (0xADDRESS). The hooks keep byte parity and the progress chart current on every commit; intentional differences are listed in hooks.allow_diff in project.toml.

The build tools are a submodule of decomp-tools, shared with other Tomb Raider decompilations. just lists all available commands.

About

Matching decompilation of Tomb Raider IV: The Last Revelation (1999), built on Linux via Wine

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages