Reconstruction layout: generated-src/ (generated) and src/ (curated), CMake, the first takeover: RNG

The decompiled C++ tree moves to generated-src/ (classes.h, C++20); src/ is for code written by hand. A curated function
defines the generated declaration and starts its comment with its address, and source_tree.py stops emitting that body.
src/rng.cpp takes over RNG (SetSeed, the constructor, Next, RandomInt, RandomFloat, Shuffle) with the shift table read
from the exe as a constexpr array; src/log.h names KAGE_LogMessage's levels (1 INFO, 2 NET, 4 WARN, 8 ERROR, 16 ASSERT,
from its prefix jump table). CMakeLists.txt builds src/*.cpp against generated-src/classes.h (clean with -Wall -Wextra).
structs.hpp and headers.py are retired: scripts/merge_fields.py writes the merged field list, classes.h checks the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-19 21:10:23 -05:00
1 parent 2ff2d5d87f
commit 3ce74c6e2d
331 files changed
+485 -7835

No files matched your search

+22 -4
View File
@@ -13,9 +13,12 @@ it, or paste large parts of it anywhere public. The game install is only read, n
db/ YOUR names and types: names.tsv (address -> name, beats every other source), fields.tsv (struct fields),
locals.tsv (local variables inside one function), globals.tsv (global data), protos.zhl (signatures)
notes/ what is known per entity/item/character/system, with addresses; notes/README.md is the index
src/ C++ checked against the decompile: structs.hpp (generated: every confirmed struct, offsets static_asserted),
game/classes.hpp (generated: the reconstructed classes, bases, vtables, sizes, for the i686 MSVC ABI),
anm2/ (sprite player), rooms/ (.stb + RoomConfig)
generated-src/ GENERATED, do not edit: the decompiled game as C++ for 64-bit Linux (scripts/source_tree.py, each build):
classes.h (every class, Ghidra type, global and function declared; the original 32-bit layout as
LAYOUT32 asserts) and one .cpp per class with its method bodies
src/ human-written C++, replacing generated-src/ one function at a time: a function defined here carries its
address in a comment (// 0040ed50) and the generator stops emitting it. anm2/ and rooms/ are older
standalone reimplementations, to be ported onto the generated class declarations
classes.tsv every RTTI class: vftable, size (from its deleting destructor), direct bases, vtable slots
decompile.sh print decompiled C for a function (name regex or address), from the dump or live
find.sh search: names, strings, string users, code, callers/callees, NPC type -> AI, item id, enums, fields
@@ -29,6 +32,21 @@ bin/ private copy of the exe (analysis input; also used to read consta
jdk/ ghidra_12.2_PUBLIC/ Temurin 21 (system java is 8, too old) and Ghidra
```
## Reconstruction
The goal is a C++ source tree that builds a native 64-bit Linux game: `cmake -B build && cmake --build build`.
`generated-src/` is the whole decompiled game as C++, regenerated every build and never edited. `src/` is the readable
game, written by hand on top of it one function at a time:
- a function in `src/` defines the method `generated-src/classes.h` declares (Rebirth's names stay, as in
`RNG::RandomInt`), with its address first in the comment above it (`// 007e9020 A number below max ...`). The next
build stops emitting the generated body. `src/rng.cpp` is the first.
- no raw offsets: a field the code needs gets a name in `db/fields.tsv`, and with it a member in `classes.h`.
- constants are `constexpr` with names, read from the exe where they live there (`RNG`'s shift table).
`scripts/source_tree.py --check` (each build) reports how many generated bodies compile and how many raw offset
accesses are left: each is a 64-bit hazard, since pointer members are wider than in the original.
## Quick use
```sh
@@ -81,7 +99,7 @@ REPENTOGON offset is never evidence by itself, not even between two confirmed ne
Entity `_mass` at 0x2d4; the Lua getter reads 0x37c). `scripts/zhl_fields.py` keeps a REPENTOGON field only when a trivial
getter or the game's Lua field table confirms it; `db/fields.tsv` holds the rest, each with the function that proves it
(about 1,300 so far), and a row with type `-` deletes a wrong one. Anything else is
`field_0xNNN`: unknown, not guessed. `src/structs.hpp` is generated from the same data and only compiles if every offset
`field_0xNNN`: unknown, not guessed. `generated-src/classes.h` is generated from the same data and its LAYOUT32 asserts only hold if every offset
is consistent. STL members (`std_vector_*`/`vector_*`, `std_string`, `std_deque_*`, `std_map_*`/`std_set_*`/`std_list_*`)
get MSVC's layout, so the dump reads `(g_manager->_itemConfig)._pillEffects._end - ..._begin`; a field of any other unknown
type names only its first dword. Structs are padded to a multiple of 4, as MSVC does, so arrays of them get the right stride.