re4 README

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

Resident Evil 4 (GameCube) — decompilation

A complete, byte-identical decompilation of Resident Evil 4 for the Nintendo GameCube: the G4BE08 debug build (the "Nov 25 2004" prototype, both discs), whose Bio4.sym files name every function. Building the repository reproduces main.dol and all 114 REL overlays exactly (config/G4BE08/build.sha1, checked on every build).

Objects 1083 (675 in the DOL, 408 across the 114 RELs), all byte-identical; 23289 function symbols (14587 distinct names; template and inline copies repeat per module)
Source ~571k lines of C/C++ (src/: 635 .cpp, 380 .c), ~43k lines in 417 headers (include/); no assembly files
Game code SN Systems ProDG 3.9.3 — GCC 2.95.3 "SN BUILD v1.79", built natively from SN's GPL source drop
CRI middleware (src/lib/adx_*, sfd_*, mpv_*, …) Metrowerks CodeWarrior 2.4.7 (GC/2.7), the compiler CRI shipped the libraries with
Nintendo SDK (src/lib/OS*, GX*, …) Metrowerks CodeWarrior GC/1.2.5n, sources from dolsdk2004

The repository contains no game assets and no code or data copied from the discs. You need your own images of the debug discs to build (disc 1 for main.dol and most RELs, disc 2 for the four island-stage RELs); the original files are read from them at configure time.

Building

Linux, Python 3, ninja. Compilers and tools (decomp-toolkit, objdiff, wibo, the CodeWarrior builds) are downloaded by the first configure run, except the native SN GCC:

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

# 2. your disc images (disc 1: main.dol + 110 RELs; disc 2: the four island-stage RELs st3_0..st3_3)
cp re4_debug_disc1.iso re4_debug_disc2.gcm orig/G4BE08/

# 3. build and verify
python3 configure.py && ninja

ninja ends with the progress report (100% matched and linked for the DOL and the REL modules); build/tools/dtk shasum -c config/G4BE08/build.sha1 prints 115 OK lines. To work on a unit, python3 tools/bytecmp.py game/foo compares its object with the original word by word and python3 tools/fdiff.py game/foo <symbol> shows one function.

Layout

What "matching" means here

Every unit compiles to the original bytes with the original compilers. Where the compiler needed a particular source shape to reproduce a register choice or a schedule and no natural spelling was found, the construct is marked with a // COMPILER-DIFF: comment (578 of them: dead tests, empty asm("") launders and anchors, register T x asm("rN") pins, padding statements). None of them emits an instruction: python3 tools/asmcheck.py --all compiles every GCC unit with its asm templates marked and lists the instructions that came from a template — the only hits are the hardware kernels below (TOTAL 231; the eight asm-bodied units are reported on their own line and kept out of that number). An earlier state of this tree had ~100 hand-placed instructions (asm("li %0,0"), asm("lis/addi"), asm("mr")) in the game code and ~100 register-pinning asm { } blocks in the CRI libraries; they were replaced by C on 2026-09-17 (docs/research/compiler.md, section "Asm-removal pass", records the recipe and the compiler mechanism per site). Each tag's mechanism is documented in docs/matching.md and docs/research/.

Assembly that remains, all of it code the original authors also wrote in assembly because their compilers had no other way to express it:

Naming

Function names are Capcom's, from the debug build's Bio4.sym files; they are C++-mangled, which is why the game code is C++ and the SDK, CRI and newlib units are C. File names and unit boundaries come from the D:/Bio4/Prog/<file>.cpp strings the asserts left in the binaries. Struct and field names are of three kinds: the vendor's, from the PS2 debug build's type information (matched to the GameCube layouts by tools/ps2sym.py); ours, named from usage and marked as such; and placeholders xNN (offset in hex, meaning unknown). Vendor names keep the vendor's spelling, so the tree mixes conventions on purpose. Constants are the PS2 build's enums, imported as declared, and the pG flag bits are read through the XxxFlagChk/On/Off macros of include/global.h with the PS2 bit names. #line directives reproduce the vendor's line numbers in the assert strings. docs/naming.md has the full account and the counts.

Contributing

CONTRIBUTING.md: build, the three verification checks, the rules (bytes never change, no instruction-emitting asm, naming), and how to propose a rename with evidence.

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

re4 (adonis-singh/re4)

Searching Database…

349 ·GitHub
这是什么?对 GameCube 版《生化危机 4》的完整逐字节还原的反编译——即 G4BE08 调试版,包含两张光盘——以可读的 C/C++ 代码重建,并能在编译后得到和原版完全一致的程序文件。
那我能拿到游戏真正的源代码吗?可以——大约 57.1 万行 C/C++ 代码(635 个 .cpp 文件和 380 个 .c 文件,外加 417 个头文件),覆盖整个游戏:主 DOL 可执行文件以及全部 114 个 REL 覆盖模块。
怎么编译它?在装有 Python 3 和 ninja 的 Linux 上:第一次运行配置时会自动下载编译器和工具,每次编译结束时还会自动做 sha1 校验,检查结果是否正确。
编译这个项目需要我自己有游戏吗?需要——你得有那两张调试光盘自己的镜像:光盘 1 用于 main.dol 和大部分 REL,光盘 2 用于四个岛屿关卡的 REL。仓库里不含任何游戏资源;配置时会从你自己的镜像中读取原始文件。
这个项目能让我玩到这个游戏吗?不能——编译只是为了复现出原版的 main.dol 和 REL 文件,用来对照你自己的光盘验证源代码是否准确;它没有把游戏移植到 PC,也没有添加任何新功能。
这些代码归谁所有——我能在自己的项目里复用吗?重建出来的游戏和 SDK 源代码归 Capcom、Nintendo 和 CRI Middleware 所有,仅出于研究和保存的目的发布。项目自带的构建脚本、工具和文档则采用 CC0 许可。
为什么选调试版而不是市售版游戏?G4BE08 原型带有 Bio4.sym 符号文件,标注了每个函数的名字,所以反编译得到的不是猜测,而是 Capcom 真实的 C++ 修饰名;断言字符串甚至保留了原始的文件名。
原版游戏是用哪些编译器编译的?游戏代码用的是 SN Systems ProDG 3.9.3(GCC 2.95.3 的 'SN BUILD' 版本),CRI 中间件和 Nintendo SDK 库用的是 Metrowerks CodeWarrior——要做到结果一致就必须用完全相同的版本编译,所以配置时会自动下载它们。
除了 C/C++ 源代码,这个项目还提供别的东西吗?有——motionexport.py 可以利用游戏自身的代码把游戏动画导出为 glTF/BVH 格式,并对照 Dolphin 模拟器中运行的游戏做了验证;docs/ 目录里还涵盖了引擎架构、配平技巧和完整的研究日志。
Size
30.5 MB
Stars
349
Updated
CommitOct 02
Age
1mo
Commits · 90 Days