re4 README

项目的 README,来自 github.com/adonis-singh/re4。合并为一个 markdown 文件: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)

正在搜索数据库…

399 ·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/ 目录里还涵盖了引擎架构、配平技巧和完整的研究日志。
大小
30.5 MB
星标
399
更新
提交Oct 02
时长
2个月
提交 · 90 天