re4 README

The project's README from github.com/adonis-singh/re4. As one markdown file: README.md.

Resident Evil 4 (GameCube) decompilation

This is a complete decompilation of the GameCube debug build of Resident Evil 4, G4BE08, the "Nov 25 2004" prototype on two discs. The debug build shipped with Bio4.sym symbol files that name every function, and that is what made a full decompilation possible.

Building the repository gives back the exact original files: main.dol and all 114 REL overlays, checked against config/G4BE08/build.sha1 on every build. The source is about 570,000 lines of C and C++ in src/ and 44,000 lines of headers in include/, with no assembly files.

The code is built with the compilers the original was built with:

Code Compiler
The game SN Systems ProDG 3.9.3, GCC 2.95.3 "SN BUILD v1.79", built from SN's GPL source release
CRI middleware (adx_*, sfd_*, mpv_* and the rest in src/lib/) Metrowerks CodeWarrior 2.4.7, which CRI shipped the libraries with
Nintendo SDK (OS*, GX* and the rest in src/lib/) Metrowerks CodeWarrior GC/1.2.5n, sources from dolsdk2004

There are no game assets in this repository. To build it you need your own images of the debug discs. Disc 1 has main.dol and most of the RELs, disc 2 has the four RELs for the island stages.

Building

You need Linux, Python 3 and ninja. The first configure run downloads decomp-toolkit, objdiff, wibo and the CodeWarrior compilers. The SN GCC is built once from SN's source:

# 1. build the SN compiler once (needs SN's GPL source release, see tools/sn-gcc/build.sh)
SN_GCC_SRC=/path/to/NGC_GNU_SRC/NGC tools/sn-gcc/build.sh

# 2. copy in your disc images
cp re4_debug_disc1.iso re4_debug_disc2.gcm orig/G4BE08/

# 3. build
python3 configure.py && ninja

ninja finishes with a progress report that should say 100% matched and linked. To check the result, build/tools/dtk shasum -c config/G4BE08/build.sha1 should print one OK per file, 115 in all.

When working on one unit, python3 tools/bytecmp.py game/foo compares its object file with the original, and python3 tools/fdiff.py game/foo <symbol> shows one function side by side.

What's where

How close is the match

Every unit compiles to the original bytes with the original compilers. In some places the compiler only picks the same registers or instruction order as the original if the code is written in a particular way, and no natural way of writing it was found. Those spots are marked with a // COMPILER-DIFF: comment, 526 of them at the moment. Most are a dead test, an empty asm("") or a register T x asm("rN") declaration. None of them puts an instruction into the output, and python3 tools/asmcheck.py --all checks that. docs/matching.md explains the reason behind each kind. Getting this number down is ongoing work.

Almost all the assembly left is code the original developers also wrote in assembly, because their compilers couldn't express it in C. That's the paired-single math and matrix routines, the GQR setup, an exception handler, the cache and SPR code in the CRI video decoder, and eight startup, debugger and decompression units that were assembly to begin with. In the game code asmcheck.py counts 231 instructions of it, with the eight assembly units counted separately. The exceptions are in the CRI libraries: one small block in dct_ac that works around a difference between our build of CodeWarrior and Capcom's, and 28 register pins that emit nothing. docs/naming.md lists all of it.

Names

Function names are Capcom's own, from Bio4.sym. They are C++ mangled names, which is why the game code is C++ and the SDK, CRI and C library code is C. File names and the split into units come from the D:/Bio4/Prog/<file>.cpp paths the asserts left in the binaries.

Struct and field names come from three places. Most are Capcom's, taken from the debug information in the PS2 debug build and matched to the GameCube layouts with tools/ps2sym.py. Some are ours, named from how the code uses them. The rest are placeholders like x1C, named after their offset because their meaning isn't known yet. Capcom's names keep Capcom's spelling, so the naming style is mixed on purpose. Constants use the PS2 build's enums. docs/naming.md has the details.

Contributing

See CONTRIBUTING.md for the build, the three checks a change has to pass and the rules. The main rule is that the output bytes never change.

The reconstructed game and SDK source is the property of Capcom, Nintendo and CRI Middleware and is published for research and preservation only. The build scripts, tools, configuration and documentation written for this project are released under CC0, see LICENSE.

re4 (adonis-singh/re4)

Searching Database…

399 ·GitHub
What is this?A complete, byte-identical decompilation of Resident Evil 4 for GameCube — the G4BE08 debug build, both discs — reconstructed as readable C/C++ that rebuilds the exact original binaries.
So do I get the actual source code of the game?Yes — about 571k lines of C/C++ (635 .cpp and 380 .c files, plus 417 headers) covering the whole game: the main DOL executable and all 114 REL overlays.
How do I build it?On Linux with Python 3 and ninja: the first configure run downloads the compilers and tools, and each build ends with an automatic sha1 verification of the result.
Do I need my own copy of the game to build this?Yes — your own images of the two debug discs: disc 1 for main.dol and most RELs, disc 2 for the four island-stage RELs. The repo contains no assets; originals are read from your images at configure time.
Does this give me a way to play the game?Not on its own — building only reproduces the original main.dol and REL files to verify the source against your own discs; nothing here ports the game to PC or adds features.
Who owns the code — can I reuse it in my own project?The reconstructed game and SDK source belongs to Capcom, Nintendo and CRI Middleware and is published for research and preservation only. The project's own build scripts, tools and docs are CC0.
Why target the debug build instead of the retail game?The G4BE08 prototype ships Bio4.sym symbol files that name every function, so the decompilation gets Capcom's real C++-mangled names instead of guesses; assert strings even preserve the original file names.
Which compilers built the original game?SN Systems ProDG 3.9.3 (GCC 2.95.3 'SN BUILD') for the game code, and Metrowerks CodeWarrior for the CRI middleware and Nintendo SDK libraries — matching requires compiling with these exact builds, so configure downloads them.
Does the project offer anything beyond the C/C++ source?Yes — motionexport.py exports the game's animations to glTF/BVH using the game's own code, verified against the game running in Dolphin, and docs/ covers the engine architecture, matching techniques and the full research log.
Size
30.5 MB
Stars
399
Updated
CommitOct 02
Age
2mo
Commits · 90 Days