Tidy the repo root: build.sh's derived tables into analysis/, build.sh, decompile.sh and find.sh into scripts/, stale by-products removed, .gitignore regrouped, README describes the src/ layout and the test harness

This commit is contained in:
shweet committed 2026-11-23 20:24:03 -05:00
1 parent aefd3e2098
commit 7d407d5c19
17 files changed
+140 -86

No files matched your search

+93 -43
View File
@@ -17,16 +17,20 @@ generated-src/ GENERATED, do not edit: the decompiled game as C++ for 64-bit Lin
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
build.sh rebuild everything from the exe (after a game update)
address in a comment (// 0040ed50) and the generator stops emitting it (see Source layout below)
dump/ the corpus the scripts read: all.c (every function, ~21k), functions.tsv, calls.tsv,
strings.tsv (string -> functions using it), npc_ai.tsv, lua_bindings.tsv, zhl_fields.tsv
analysis/ tables scripts/build.sh derives on the way to the dump: classes.tsv (every RTTI class: vftable, size
from its deleting destructor, direct bases, vtable slots), zhl_vtables.tsv, zhl_matches.tsv,
zhl_fields.tsv, the lua_*.tsv tables, the raw npc_ai.tsv and use_dispatch.tsv (active, card and pill
ids -> UseActiveItem/UseCard/UsePill cases)
project/ saved Ghidra project (auto-analysed + names + types)
scripts/ Ghidra Java scripts and Python helpers used by the above
scripts/ decompile.sh (print decompiled C for a function, by name regex or address, from the dump or live),
find.sh (search names, strings, string users, code, callers/callees, NPC type -> AI, item ids, enums,
fields), build.sh (rebuild everything from the exe after a game update), and the Ghidra Java scripts
and Python helpers they use
tools/ gitignored local tools: the resource importer and the test harness (tools/harness/)
external/ static submodules: SDL3, Lua 5.3, simdjson, Ogg, Vorbis, Theora, stb
repentogon/ shallow clone of TeamREPENTOGON/REPENTOGON (libzhl/functions/*.zhl = sigs, structs, enums)
bin/ private copy of the exe (analysis input; also used to read constants)
jdk/ ghidra_12.2_PUBLIC/ Temurin 21 (system java is 8, too old) and Ghidra
@@ -51,20 +55,66 @@ game, written by hand on top of it one function at a time:
`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.
Regenerate `generated-src/` after adding or moving a function in `src/`:
`python3 -I scripts/source_tree.py generated-src analysis/classes.tsv dump analysis/zhl_vtables.tsv --check`.
### Source layout
`src/` is sorted by subsystem. A file drops its folder's prefix and includes others by path from `src/`
(`#include "entity/boss/mom.h"`); CMake builds every `.cpp` under it.
```
engine/ platform (SDL3 window, frame pacing, clock), gl, kage_* (graphics, input, sound), anm2, textures,
fonts, video, renderers, data loading, log, seeds and RNG, the test harness
game/ main, Manager, game_* (game/state, game/save, game/update ...), options, strings, save data, mods,
sound and music managers, dailies, local versus
level/ level_* (level/generator, level/stage ...), room*, backdrop, minimap, path finder, rails,
stage transition, Greed
grid/ grid entities (level/grid/rock, level/grid/door ...)
entity/ Entity and its list, factory, config, collision, combat
player/ Entity_Player split by concern (player/actives, player/cards, player/update ...), PlayerManager
npc/ Entity_NPC and every enemy AI (npc/gaper, npc/hopper ...)
boss/ every boss (boss/mom, boss/delirium ...)
familiar/ Entity_Familiar and familiar behaviour
effect/ Entity_Effect variants
pickup/ pickups, slots, item config, item pools, procedural items
weapon/ weapons, tears, lasers, knives, bombs, projectiles
ui/ HUDs, popups, pause screen, cutscenes, console
menu/ every menu screen (ui/menu/character, ui/menu/mods ...)
lua/ the Lua engine, API bindings and callbacks
online/ online-only code, kept as offline stubs
```
### Test harness
Flags on the game binary (`src/engine/harness.cpp`), deterministic: the same input file always gives the same run.
```
--headless no window, GL context or audio, no frame pacing (about 7,900 frames per second)
--record F / --replay F per-frame input from boot, so menu navigation is included
--frames N quit after N frames
--trace F [--trace-every N] [--trace-detail] hashes (or the fields) of the RNGs, players and entities
--mods DIR a private mods folder
```
`tools/harness/run.sh SAVE WORK [flags]` runs on a fresh copy of a save folder with a private `XDG_DATA_HOME`;
`tools/harness/menu.py` writes the boot-to-run menu input; `tools/harness/compare.py A B` prints the first frame
and field where two traces differ; `tools/harness/bot/` is a Lua mod that plays through `MC_INPUT_ACTION`.
## Quick use
```sh
cd <this folder>
./find.sh npc 29 # entity type 29 (Hopper) -> its AI routine
./decompile.sh '^NpcAI::ENTITY_HOPPER$' # decompiled C (instant, from dump/all.c)
./find.sh strs NpcAI::ENTITY_HOPPER # anm2 animation/event names, sounds, paths it uses
./find.sh item 4 # every line testing collectible/trinket 4
./find.sh active 33 # The Bible's case in Entity_Player::UseActiveItem
./find.sh enum 'COLLECTIBLE_.*HEAD' # id lookup (entity types, items, trinkets, cards, pills, players...)
./find.sh val DAT_00baa2d0 # float/int constant the decompiler left as DAT_
./decompile.sh 0x526470 # by address (any address inside the function works)
./decompile.sh --live 'Entity_NPC::Morph$' # live Ghidra decompile (~30s), for anything not in the dump
./decompile.sh --asm 0x6c29f0 30 # disassembly, for the few functions that will not decompile
scripts/find.sh npc 29 # entity type 29 (Hopper) -> its AI routine
scripts/decompile.sh '^NpcAI::ENTITY_HOPPER$' # decompiled C (instant, from dump/all.c)
scripts/find.sh strs NpcAI::ENTITY_HOPPER # anm2 animation/event names, sounds, paths it uses
scripts/find.sh item 4 # every line testing collectible/trinket 4
scripts/find.sh active 33 # The Bible's case in Entity_Player::UseActiveItem
scripts/find.sh enum 'COLLECTIBLE_.*HEAD' # id lookup (entity types, items, trinkets, cards, pills, players...)
scripts/find.sh val DAT_00baa2d0 # float/int constant the decompiler left as DAT_
scripts/decompile.sh 0x526470 # by address (any address inside the function works)
scripts/decompile.sh --live 'Entity_NPC::Morph$' # live Ghidra decompile (~30s), for anything not in the dump
scripts/decompile.sh --asm 0x6c29f0 30 # disassembly, for the few functions that will not decompile
```
`decompile.sh QUERY [MAX]`: QUERY is a hex address or an awk/ERE regex matched against the full name
@@ -108,7 +158,7 @@ is consistent. STL members (`std_vector_*`/`vector_*`, `std_string`, `std_deque_
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.
Types: structs built from the confirmed REPENTOGON fields, plus `lua_fields.tsv` (about 100 fields REPENTOGON lacks,
Types: structs built from the confirmed REPENTOGON fields, plus `analysis/lua_fields.tsv` (about 100 fields REPENTOGON lacks,
read from the game's own trivial Lua getters, e.g. Entity 0x334 `_targetPosition`) and `db/fields.tsv`. Embedded structs
are typed too (`npc->_sprite._animState._isPlaying`).
**Prototypes** come from REPENTOGON's declarations only where this exe confirms them: a `__thiscall`/`__stdcall` callee
@@ -133,7 +183,7 @@ V1 0xbb0, V2 0xbb8, I1 0xbc0, I2 0xbc4. Entity_Player PlayerType 0x13c0.
(006c2990). That function checks `type - 10 < 0x3be`, then reads a byte index table at 0x6c45a4 and a jump table
at 0x6c41dc. Each case calls one AI routine with ECX = the NPC. `scripts/NpcTable.java` resolved all of these into
`dump/npc_ai.tsv` (`type, ENTITY_ENUM, case block, calls in the block`). So:
1. `./find.sh npc <type>` gives the routine, for example `29 ENTITY_HOPPER ... 00526470:NpcAI::ENTITY_HOPPER`.
1. `scripts/find.sh npc <type>` gives the routine, for example `29 ENTITY_HOPPER ... 00526470:NpcAI::ENTITY_HOPPER`.
2. A routine is often shared, and **variants are handled inside it** (`if (npc->_type == 0x56)`,
`npc->_variant == 2`, `switch(npc->_variant)`). Search the body for the variant or subtype you care about.
Several types share a routine. Fly 13 and Pooter 14 both run `NpcAI::ENTITY_FLY`, and Hopper's routine serves
@@ -153,36 +203,36 @@ at 0x6c41dc. Each case calls one AI routine with ECX = the NPC. `scripts/NpcTabl
offsets are in `find.sh lua ProjectileParams`.
**Item / trinket id.** There is no table, because effects are scattered `HasCollectible(id)` checks:
1. `./find.sh enum 'COLLECTIBLE_SAD_ONION'` gives the id.
2. `./find.sh item <id>` lists every call like `HasCollectible(0x34,..)`, `GetCollectibleNum(4,..)`,
1. `scripts/find.sh enum 'COLLECTIBLE_SAD_ONION'` gives the id.
2. `scripts/find.sh item <id>` lists every call like `HasCollectible(0x34,..)`, `GetCollectibleNum(4,..)`,
`HasTrinket(..)`, `GetTrinketMultiplier(..)` with that first argument, along with its function. This is a
heuristic: it also shows `ItemPool::GetCollectible(4,..)`, where 4 is a pool, and trinket/collectible ids
overlap, so read the callee name. The `this` (player) argument is implicit (ECX) and not printed.
3. Stat items live in `Entity_Player::EvaluateItems` (00763570, about 53 KB). Tear and fire behaviour is in
`Entity_Player::GetMultiShotParams`, `Entity_Tear::*` and `Entity_Player::Update`.
4. **Actives, cards, pills:** `./find.sh active <id>` (also `card <id>`, `pill <effect>`) prints the case of
4. **Actives, cards, pills:** `scripts/find.sh active <id>` (also `card <id>`, `pill <effect>`) prints the case of
`Entity_Player::UseActiveItem` (005b39d0, about 10.7k lines; it took about 45 min to decompile and was spliced into
the dump), `UseCard` or `UsePill`. The id -> case table `use_dispatch.tsv` is read from the exe's jump tables
the dump), `UseCard` or `UsePill`. The id -> case table `analysis/use_dispatch.tsv` is read from the exe's jump tables
(`scripts/use_dispatch.py`); UseActiveItem's second table (ids 283+) is labelled by table slot in the C, not by id,
see `notes/systems/use_dispatch.md`. An active with no case only adds its TemporaryEffect: use `find.sh item`.
**Character.** `./find.sh enum PLAYER_` gives the id. `./find.sh player <id>` lists compares against the player
**Character.** `scripts/find.sh enum PLAYER_` gives the id. `scripts/find.sh player <id>` lists compares against the player
type that sit within 4 lines of a `GetPlayerType()` or `_playerType` (0x13c0) read. For gimmicks, also grep
code: `./find.sh code 'GetPlayerType'`, and look in `Entity_Player::Init`, `Update`, `EvaluateItems`,
code: `scripts/find.sh code 'GetPlayerType'`, and look in `Entity_Player::Init`, `Update`, `EvaluateItems`,
`TakeDamage`.
**Animation, event or sound name to code.** `./find.sh str '^Hop$'` lists the functions using that string, and
`./find.sh strs <func>` goes the other way. Ghidra leaves strings of 4 characters or fewer as `&DAT_...`. The
**Animation, event or sound name to code.** `scripts/find.sh str '^Hop$'` lists the functions using that string, and
`scripts/find.sh strs <func>` goes the other way. Ghidra leaves strings of 4 characters or fewer as `&DAT_...`. The
dump turns most into literals, and `find.sh val DAT_x` reads any of them.
## Worked example 1: Hopper (type 29)
```
$ ./find.sh npc 29
$ scripts/find.sh npc 29
29 ENTITY_HOPPER 006c3b4d 00526470:NpcAI::ENTITY_HOPPER
$ ./find.sh strs NpcAI::ENTITY_HOPPER
$ scripts/find.sh strs NpcAI::ENTITY_HOPPER
Appear Attack BigJumpDown BigJumpUp Hop Hop2 HopLong HopShort JumpDown Regen Shoot ShootDown
$ ./decompile.sh '^NpcAI::ENTITY_HOPPER$' | less
$ scripts/decompile.sh '^NpcAI::ENTITY_HOPPER$' | less
if (npc->_state == 0) { npc->_state = 3; ... /* init -> idle */
local_278 = "Hop";
if (iVar13 == 0x56) { /* 86 = ENTITY_KEEPER (find.sh enum 'ENTITY_\w+ = 86,') */
@@ -197,7 +247,7 @@ decompiler did not inline show as `DAT_00xxxxxx`. Read those with `find.sh val`.
## Worked example 2: Gaper (type 10)
`./find.sh npc 10` gives `NpcAI::ENTITY_GAPER` (00508f40, about 790 lines). It handles every type-10 variant
`scripts/find.sh npc 10` gives `NpcAI::ENTITY_GAPER` (00508f40, about 790 lines). It handles every type-10 variant
(`npc->_variant == 1/2/3/10`) plus a few other types (`_type == 0xd0`, `0x101`, `0x11c`, `0x12e`). State 0
is init and sets `_state = 4`. Movement chases `Entity_NPC::GetPlayerTarget(npc)`, and the anims are
`WalkVert`/`WalkHori` with the head layer on `HeadIdle`.
@@ -205,16 +255,16 @@ is init and sets `_state = 4`. Movement chases `Entity_NPC::GetPlayerTarget(npc)
## Worked example 3: item effect, Cricket's Head (collectible 4)
```
$ ./find.sh enum CRICKETS_HEAD -> COLLECTIBLE_CRICKETS_HEAD = 4,
$ ./find.sh item 4
$ scripts/find.sh enum CRICKETS_HEAD -> COLLECTIBLE_CRICKETS_HEAD = 4,
$ scripts/find.sh item 4
00763570 Entity_Player::EvaluateItems iVar12 = GetCollectibleNum(local_45c,4,0);
00763570 Entity_Player::EvaluateItems cVar2 = HasCollectible(4,0);
00782af0 FUN_00782af0 iVar11 = Entity_Player::GetTrinketMultiplier(4); <- trinket 4, unrelated
$ ./decompile.sh Entity_Player::EvaluateItems | grep -n -A4 'GetCollectibleNum(local_45c,4,0)'
$ scripts/decompile.sh Entity_Player::EvaluateItems | grep -n -A4 'GetCollectibleNum(local_45c,4,0)'
iVar12 = GetCollectibleNum(local_45c,4,0);
iVar17 = TemporaryEffects::GetCollectibleEffectNum(0x2b4);
local_460 = (float)(iVar17 + ... + iVar11 + iVar12) * 0.5 + local_460;
$ ./decompile.sh Entity_Player::EvaluateItems | grep -n -A8 'HasCollectible(4,0)'
$ scripts/decompile.sh Entity_Player::EvaluateItems | grep -n -A8 'HasCollectible(4,0)'
cVar2 = HasCollectible(4,0);
if (cVar2 || (HasCollectibleEffect(0x22) && HasCollectible(7,0)) || HasCollectible(0xc,0)
|| TemporaryEffects::HasCollectibleEffect(0xc)) {
@@ -227,7 +277,7 @@ together with the Book of Belial (34) effect. The multiplier applies once, not p
## Worked example 4: active item, The Bible (33)
```
$ ./find.sh active 33 25
$ scripts/find.sh active 33 25
---- line 628
case 0x21:
FUN_009568e0(); ... (sound/effect calls)
@@ -261,7 +311,7 @@ finding only in your scratch files or your final message.
routines that take only the npc (they get typed `Entity_NPC *npc`), `NpcHelper::snake_name` for NPC helpers with
other arguments, `Class::snake_name` otherwise. Then run `python3 -I scripts/apply_db.py db/names.tsv dump`
(instant: renames it in the dump everywhere, including call sites and `npc_ai.tsv`).
For a virtual method, `./find.sh vtable CLASS` shows which slot it is; slot names are the most reliable evidence
For a virtual method, `scripts/find.sh vtable CLASS` shows which slot it is; slot names are the most reliable evidence
there is (a short ZHL sig or ICF can put a name on the wrong function, a vtable slot cannot).
2. **A struct field** you have confirmed in this exe: add `Class<TAB>0xOFF<TAB>type _name<TAB>evidence` to `db/fields.tsv`
(arrays as `int _slots[4]`). Evidence is a function that reads/writes it with a known meaning, never REPENTOGON's offset.
@@ -272,25 +322,25 @@ finding only in your scratch files or your final message.
in `db/globals.tsv`. Pointer types (`Game*`) type every access; `apply_db.py` renames it in the dump at once.
**A function signature**: one REPENTOGON-style line in `db/protos.zhl`, e.g.
`__thiscall int Entity_NPC::FooBar(int count, Vector* pos);`. It is applied only if the callee's `RET n` agrees.
3. **Re-apply to Ghidra** after any of them: `./build.sh --db` (about 10 min: updates the project and re-decompiles every
db function into the dump, typed). Field changes reach every function only with `./build.sh --db --full` (about 50 min).
3. **Re-apply to Ghidra** after any of them: `scripts/build.sh --db` (about 10 min: updates the project and re-decompiles every
db function into the dump, typed). Field changes reach every function only with `scripts/build.sh --db --full` (about 50 min).
4. **Behaviour** (states, timings, speeds, odds, bugs): write it in `notes/<entities|items|characters|systems>/<name>.md`
with a `## name (NpcAI::ENTITY_X 0xADDR, type.variant)` heading, so `python3 -I scripts/notes_index.py notes`
puts it in the index. Quote addresses, not copies of decompiled C: `./decompile.sh 0xADDR` reprints it with the
puts it in the index. Quote addresses, not copies of decompiled C: `scripts/decompile.sh 0xADDR` reprints it with the
newest names.
5. Commit: `git add -A && git commit -m "names/notes: <what>"`. Several agents may work at once; commit only your own
files, and if two of you touch `db/names.tsv`, keep both lines.
## After a game update
1. `./build.sh` (about 75 min) copies the new `isaac-ng.exe` into `bin/`, re-imports, re-applies every name source
1. `scripts/build.sh` (about 75 min) copies the new `isaac-ng.exe` into `bin/`, re-imports, re-applies every name source
and `db/`, and redumps. Set `GAME=/path/to/game` if the install is elsewhere.
2. If the NPC dispatcher or Lua-registration address moved, update `NPC_DISPATCH` and `LUA_REG` at the top of
`build.sh` first. Find them with `find.sh callees Entity_NPC::Update` (the callee with a 264-case switch) and
`find.sh str '^UseActiveItem$'`.
3. **`db/names.tsv` and `notes/` are keyed by address, and addresses move.** Before rebuilding, record each db
function's strings (`./find.sh strs ADDR`) so you can find it again in the new build (`./find.sh str`, then
`find.sh callers`). Rewrite the addresses, then `./build.sh --db`. Pull a newer REPENTOGON first
function's strings (`scripts/find.sh strs ADDR`) so you can find it again in the new build (`scripts/find.sh str`, then
`find.sh callers`). Rewrite the addresses, then `scripts/build.sh --db`. Pull a newer REPENTOGON first
(`git -C repentogon pull`) if it supports the new version.
4. Commit the result as one commit naming the game version.