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:
1 parent
aefd3e2098
commit
7d407d5c19
17 files changed
+140
-86
No files matched your search
+13
-9
@@ -3,20 +3,24 @@
|
||||
/ghidra_12.2_PUBLIC/
|
||||
/bin/
|
||||
/repentogon/
|
||||
/resources/
|
||||
# Ghidra per-user state, locks and backups (the program itself is project/isaac.rep/idata/00/~00000000.db)
|
||||
/project/**/*.lock*
|
||||
/project/isaac.rep/user/
|
||||
/project/**/*.bak
|
||||
# build by-products
|
||||
/build.log
|
||||
/build_fields.tsv
|
||||
/retry*.c
|
||||
__pycache__/
|
||||
/.tmp/
|
||||
# scripts/build.sh by-products: its log, retries and intermediate tables (the kept ones are tracked in analysis/)
|
||||
/analysis/build.log
|
||||
/analysis/retry*.c
|
||||
/analysis/build_fields.tsv
|
||||
/analysis/build_this.tsv
|
||||
/analysis/lua_bindings.tsv
|
||||
/dump.new/
|
||||
/dump.old/
|
||||
/build_this.tsv
|
||||
/.tmp/
|
||||
/CLAUDE.md
|
||||
__pycache__/
|
||||
# builds, editor index, local tools and test runs
|
||||
/build*/
|
||||
/.cache/
|
||||
/tools/
|
||||
/resources/
|
||||
/runs/
|
||||
/CLAUDE.md
|
||||
@@ -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.
|
||||
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+26
-26
@@ -6,10 +6,10 @@
|
||||
# Steps: import+auto-analysis -> ZHL sig/vtable names -> Lua-registration names -> NPC AI table
|
||||
# -> REPENTOGON struct fields this exe confirms (getters, Lua field table) -> struct/this types -> final dump.
|
||||
set -e
|
||||
D="$(cd "$(dirname "$0")" && pwd)"
|
||||
D="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
export JAVA_HOME="$D/jdk" GHIDRA_MAXMEM=24G JAVA_TOOL_OPTIONS="-Djava.io.tmpdir=$D/.tmp" # not /tmp: its user quota is shared
|
||||
mkdir -p "$D/.tmp"
|
||||
G() { "$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$D/project" isaac "$@" -scriptPath "$D/scripts" >> "$D/build.log" 2>&1; }
|
||||
G() { "$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$D/project" isaac "$@" -scriptPath "$D/scripts" >> "$D/analysis/build.log" 2>&1; }
|
||||
P() { python3 -I "$D/scripts/$@"; }
|
||||
LUA_REG=00866960 # function that registers the Lua API (references "UseActiveItem" etc.; find.sh str '^UseActiveItem$')
|
||||
NPC_DISPATCH=006c2990 # Entity_NPC_UpdateAI_dispatch (callee of Entity_NPC::Update with a jump table on type-10)
|
||||
@@ -17,11 +17,11 @@ NPC_DISPATCH=006c2990 # Entity_NPC_UpdateAI_dispatch (callee of Entity_NPC::Up
|
||||
GAME="${GAME:-$HOME/.steam/steam/steamapps/common/The Binding of Isaac Rebirth}"
|
||||
apply_db() { # db names -> struct types (zhl + db fields)
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyDb.java "$D/db/names.tsv"
|
||||
P vtable.py "$D/bin/isaac-ng.exe" "$D/dump/functions.tsv" "$D/zhl_vtables.tsv" --classes "$D/dump/all.c" > "$D/classes.tsv" # RTTI: size, bases, slots
|
||||
P merge_fields.py "$D/build_fields.tsv" "$D/zhl_fields.tsv" "$D/lua_fields.tsv" "$D/db/fields.tsv" \
|
||||
<(awk -F'\t' '!/^#/ && $4 != "-" {print $1 "\tsize\t" $4}' "$D/classes.tsv") # later rows win, "-" deletes
|
||||
P this_types.py "$D/dump/all.c" "$D/build_fields.tsv" "$D/build_this.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyTypes.java "$D/build_fields.tsv" "$D/build_this.tsv"
|
||||
P vtable.py "$D/bin/isaac-ng.exe" "$D/dump/functions.tsv" "$D/analysis/zhl_vtables.tsv" --classes "$D/dump/all.c" > "$D/analysis/classes.tsv" # RTTI: size, bases, slots
|
||||
P merge_fields.py "$D/analysis/build_fields.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_fields.tsv" "$D/db/fields.tsv" \
|
||||
<(awk -F'\t' '!/^#/ && $4 != "-" {print $1 "\tsize\t" $4}' "$D/analysis/classes.tsv") # later rows win, "-" deletes
|
||||
P this_types.py "$D/dump/all.c" "$D/analysis/build_fields.tsv" "$D/analysis/build_this.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyTypes.java "$D/analysis/build_fields.tsv" "$D/analysis/build_this.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyGlobals.java "$D/db/globals.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyProtos.java "$D/db" "$D/repentogon/libzhl/functions" # only where RET n agrees
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyLocals.java "$D/db/locals.tsv" # after types: names refer to that decompile
|
||||
@@ -30,16 +30,16 @@ types_dump() { # final dump, built in dump.new and swapped in at the end so re
|
||||
O="$D/dump.new"; command rm -rf "$O"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript DumpAll.java "$O"
|
||||
P lua_bindings.py "$D/bin/isaac-ng.exe" "$O/all.c" "$O"
|
||||
command cp -f "$D/npc_ai.tsv" "$O/"; command mv -f "$D/build_fields.tsv" "$O/zhl_fields.tsv"
|
||||
command cp -f "$D/analysis/npc_ai.tsv" "$O/"; command mv -f "$D/analysis/build_fields.tsv" "$O/zhl_fields.tsv"
|
||||
command rm -f "$O/lua_names.tsv"
|
||||
# the dump gives up after 900 s; retry the big named ones live (UseActiveItem takes ~30-60 min) and splice them in.
|
||||
# With --db --full the exe is unchanged, so the previous dump's copy is reused instead (only newer types missing).
|
||||
for A in $(grep -B1 'decompile failed' "$O/all.c" | awk '/^\/\/@@ / && $3 !~ /^FUN_/ {print $2}'); do
|
||||
if [ -n "$REUSE" ]; then "$D/decompile.sh" "$A" 1 > "$D/retry.c" # an old failure stays a failure, no 2 h retry
|
||||
else DECOMP_TIMEOUT=7200 "$D/decompile.sh" --live "$A" > "$D/retry.c"; fi
|
||||
P splice.py "$O/all.c" "$D/retry.c" || true
|
||||
if [ -n "$REUSE" ]; then "$D/scripts/decompile.sh" "$A" 1 > "$D/analysis/retry.c" # an old failure stays a failure, no 2 h retry
|
||||
else DECOMP_TIMEOUT=7200 "$D/scripts/decompile.sh" --live "$A" > "$D/analysis/retry.c"; fi
|
||||
P splice.py "$O/all.c" "$D/analysis/retry.c" || true
|
||||
done
|
||||
command rm -f "$D/retry.c"
|
||||
command rm -f "$D/analysis/retry.c"
|
||||
P apply_db.py "$D/db/names.tsv" "$O" # npc_ai.tsv was written before ApplyDb
|
||||
n() { grep -c '^//@@ ' "$1/all.c" || true; } # a dump cut short (disk full, crash) must not replace a good one
|
||||
[ ! -f "$D/dump/all.c" ] || [ "$(n "$O")" -ge "$(( $(n "$D/dump") * 99 / 100 ))" ] || { echo "dump.new has $(n "$O") functions, dump/ $(n "$D/dump"): kept dump/" >&2; exit 1; }
|
||||
@@ -48,31 +48,31 @@ types_dump() { # final dump, built in dump.new and swapped in at the end so re
|
||||
}
|
||||
source_tree() { # generated-src/: the decompiled C++ tree (classes.h + one .cpp per class) for 64-bit Linux, minus what src/ took over
|
||||
command rm -rf "$D/generated-src" && mkdir -p "$D/generated-src"
|
||||
P source_tree.py "$D/generated-src" "$D/classes.tsv" "$D/dump" "$D/zhl_vtables.tsv" --check
|
||||
P source_tree.py "$D/generated-src" "$D/analysis/classes.tsv" "$D/dump" "$D/analysis/zhl_vtables.tsv" --check
|
||||
}
|
||||
if [ "$1" = --db ]; then
|
||||
apply_db
|
||||
[ "$2" = --full ] && { REUSE=1 types_dump; exit; }
|
||||
RX="^($( (grep -v '^#' "$D/db/names.tsv" | cut -f2; grep -v '^#' "$D/db/locals.tsv" | grep . | cut -f1 | while read A; do
|
||||
awk -F'\t' -v a="$(printf '%08x' $((16#${A#0x})))" '$1 == a "" {print $2}' "$D/dump/functions.tsv"; done) | sort -u | sed 's/[][().*+?^$|]/\\&/g' | paste -sd'|'))\$"
|
||||
DECOMP_TIMEOUT=900 "$D/decompile.sh" --live "$RX" 100000 | awk -v d="$D" '/^\/\/@@ /{f=d "/retry_" $2 ".c"} {print > f}'
|
||||
for F in "$D"/retry_*.c; do P splice.py "$D/dump/all.c" "$F" || true; done
|
||||
command rm -f "$D"/retry_*.c "$D/build_fields.tsv" "$D/build_this.tsv"
|
||||
DECOMP_TIMEOUT=900 "$D/scripts/decompile.sh" --live "$RX" 100000 | awk -v d="$D" '/^\/\/@@ /{f=d "/analysis/retry_" $2 ".c"} {print > f}'
|
||||
for F in "$D/analysis"/retry_*.c; do P splice.py "$D/dump/all.c" "$F" || true; done
|
||||
command rm -f "$D/analysis"/retry_*.c "$D/analysis/build_fields.tsv" "$D/analysis/build_this.tsv"
|
||||
P apply_db.py "$D/db/names.tsv" "$D/dump"; exit
|
||||
fi
|
||||
|
||||
command cp -f "$GAME/isaac-ng.exe" "$D/bin/"
|
||||
[ "$1" = --keep-analysis ] || G -import "$D/bin/isaac-ng.exe" -overwrite
|
||||
P zhl_match.py "$D/bin/isaac-ng.exe" "$D/repentogon/libzhl/functions" "$D/zhl_matches.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/zhl_matches.tsv" "$D/zhl_vtables.tsv"
|
||||
P zhl_match.py "$D/bin/isaac-ng.exe" "$D/repentogon/libzhl/functions" "$D/analysis/zhl_matches.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/analysis/zhl_matches.tsv" "$D/analysis/zhl_vtables.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript DumpAll.java "$D/dump"
|
||||
P lua_bindings.py "$D/bin/isaac-ng.exe" "$D/dump/all.c" "$D"
|
||||
cut -f1 "$D/lua_bindings.tsv" | sort -u > "$D/lua_classes.txt"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript LuaAsm.java $LUA_REG "$D/lua_classes.txt" "$D/lua_asm.tsv"
|
||||
cat "$D/lua_names.tsv" "$D/lua_asm.tsv" | awk -F'\t' '!seen[$1]++' > "$D/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/zhl_matches.tsv" "$D/zhl_vtables.tsv" "$D/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript NpcTable.java $NPC_DISPATCH "$D/repentogon/libzhl/functions/Global.zhl" "$D/npc_ai.tsv"
|
||||
P zhl_fields.py "$D/dump/all.c" "$D/repentogon/libzhl/functions" "$D/lua_bindings.tsv" "$D/zhl_fields.tsv" "$D/lua_all.tsv"
|
||||
P lua_fields.py "$D/dump/all.c" "$D/lua_names.tsv" "$D/lua_asm.tsv" "$D/zhl_fields.tsv" "$D/lua_fields.tsv"
|
||||
P lua_bindings.py "$D/bin/isaac-ng.exe" "$D/dump/all.c" "$D/analysis"
|
||||
cut -f1 "$D/analysis/lua_bindings.tsv" | sort -u > "$D/analysis/lua_classes.txt"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript LuaAsm.java $LUA_REG "$D/analysis/lua_classes.txt" "$D/analysis/lua_asm.tsv"
|
||||
cat "$D/analysis/lua_names.tsv" "$D/analysis/lua_asm.tsv" | awk -F'\t' '!seen[$1]++' > "$D/analysis/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/analysis/zhl_matches.tsv" "$D/analysis/zhl_vtables.tsv" "$D/analysis/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript NpcTable.java $NPC_DISPATCH "$D/repentogon/libzhl/functions/Global.zhl" "$D/analysis/npc_ai.tsv"
|
||||
P zhl_fields.py "$D/dump/all.c" "$D/repentogon/libzhl/functions" "$D/analysis/lua_bindings.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_all.tsv"
|
||||
P lua_fields.py "$D/dump/all.c" "$D/analysis/lua_names.tsv" "$D/analysis/lua_asm.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_fields.tsv"
|
||||
apply_db
|
||||
types_dump
|
||||
@@ -45,13 +45,13 @@ How to take over a class:
|
||||
- Names: keep Rebirth's names for the class and for methods the game has (ANM2::Play, StringTable::GetString, ItemConfig::Load ...). Name fields in camelCase without a leading underscore (_spriteSheetPath becomes spriteSheetPath). Use REPENTOGON's names (repentogon/libzhl/functions/*.zhl) where they exist. Everything else follows CLAUDE.md: noun_verb snake_case free functions, camelCase locals, "is" booleans.
|
||||
- Method signatures may become idiomatic (std::string_view instead of std_string*, references instead of pointers, enums instead of ints) when that is clearer. Keep the meaning.
|
||||
- Each method the original has gets a comment directly above it that starts with its address (or addresses, if you merged several), then one short sentence: "// 0040bd50 Loads the .anm2 at path, sharing parsed files through the cache." The generator stops emitting a function once src/ carries its address.
|
||||
- Take over the WHOLE class you are assigned: every method the class has in the original that the game needs (see generated-src/classes.h for the list and generated-src/<class>.cpp, ./decompile.sh <address>, ./decompile.sh --asm <address> N for bodies).
|
||||
- Take over the WHOLE class you are assigned: every method the class has in the original that the game needs (see generated-src/classes.h for the list and generated-src/<class>.cpp, scripts/decompile.sh <address>, scripts/decompile.sh --asm <address> N for bodies).
|
||||
- Collapse compiler-generated ones (copy constructors, operator_assign, destructors that only free members) into the language defaults where std members make them unnecessary, and still list their addresses in a comment above the class so the generator drops them: "// Copies, assignment and destruction (0040b000, 0040b1d0, 0040ae70) are the defaults."
|
||||
- Behaviour must match the original exactly: same results, same order of effects, same edge cases. Where the original crashes or has undefined behaviour, pick a safe behaviour and say so in one comment line.
|
||||
- Data: XML is converted by the import tool into JSON under resources/ (lowercase paths, ".json" appended). Read it through src/engine/data.h: data_load, node_children, node_tag, node_attr, node_text. Element order is preserved and attribute values are the original strings. A file with several roots becomes {"tag":"#document","children":[...]}. Convert values exactly as the original did. resources/ holds the real converted game files: look at them.
|
||||
- Other classes: call whatever classes.h declares for classes nobody has taken over (they are stubs for now). Do NOT edit src/ files other than your own: other agents are rewriting other classes at the same time. If a round 1 file outside your assignment calls something you changed, list the needed call-site change in your report.
|
||||
- Every file you write must compile with no warnings: clang++ -std=c++20 -fsyntax-only -Wall -Wextra -I src -isystem ${R}/gen_\${i} -isystem external/simdjson/singleheader -isystem external/sdl/include -isystem external/lua -isystem external/stb src/<file>.cpp
|
||||
- First regenerate your private header with python3 -I scripts/source_tree.py ${R}/gen_\${i} classes.tsv dump zhl_vtables.tsv. Rerun it after creating your .h, because the generator drops the classes your header defines.
|
||||
- First regenerate your private header with python3 -I scripts/source_tree.py ${R}/gen_\${i} analysis/classes.tsv dump analysis/zhl_vtables.tsv. Rerun it after creating your .h, because the generator drops the classes your header defines.
|
||||
- Round 1 files that depend on your old API may stop compiling. That is expected, so only check your own files.
|
||||
- Style details from CLAUDE.md:
|
||||
- Allman braces; a one-line body stays on one line without braces.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# --case decompiles single switch cases of a function the decompiler times out on (Entity_Effect::Update): each
|
||||
# CASEADDR is a jump-table target; the switch is patched to jump straight there in a throwaway copy (DecompileCase.java).
|
||||
# --live runs the Ghidra decompiler on a copy of the saved project (~25s; env DECOMP_TIMEOUT=secs, default 180).
|
||||
D="$(cd "$(dirname "$0")" && pwd)"
|
||||
D="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
LIVE=0; SCRIPT=Decompile.java
|
||||
[ "$1" = --live ] && { LIVE=1; shift; }
|
||||
[ "$1" = --asm ] && { LIVE=1; SCRIPT=Disasm.java; shift; }
|
||||
@@ -17,7 +17,7 @@
|
||||
# val ADDR constant at DAT_ADDR as int/float/double/string (decompiler leaves floats as DAT_)
|
||||
# field REGEX known struct field offsets (REPENTOGON zhl struct defs)
|
||||
# vtable CLASS vtable slots of an RTTI class, read from the exe (e.g. Weapon_Knife, Entity_Player)
|
||||
D="$(cd "$(dirname "$0")" && pwd)"; T="$D/dump"
|
||||
D="$(cd "$(dirname "$0")/.." && pwd)"; T="$D/dump"
|
||||
MODE="$1"; ARG="$2"
|
||||
[ -z "$ARG" ] && { sed -n '2,19p' "$0"; exit 1; }
|
||||
addr_of() { # address or name -> 8-digit address
|
||||
@@ -29,7 +29,7 @@ case "$MODE" in
|
||||
name) grep -E -- "$ARG" <(cut -f1-3 "$T/functions.tsv") ;;
|
||||
str) awk -F'\t' -v r="$ARG" '$2 ~ r' "$T/strings.tsv" ;;
|
||||
code) awk -v r="$ARG" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {c[h]++} END {for (k in c) print k, c[k]}' "$T/all.c" | sort ;;
|
||||
strs) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a:" 'index($3, a) {print $2}' "$T/strings.tsv"; "$D/decompile.sh" "$a" | grep -o '"[^"]*"' | tr -d '"'; done | sort -u ;;
|
||||
strs) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a:" 'index($3, a) {print $2}' "$T/strings.tsv"; "$D/scripts/decompile.sh" "$a" | grep -o '"[^"]*"' | tr -d '"'; done | sort -u ;;
|
||||
callers) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$2 == a "" {print $1}' "$T/calls.tsv"; done | sort -u | name_of ;;
|
||||
callees) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$1 == a "" {print $2}' "$T/calls.tsv"; done | sort -u | name_of ;;
|
||||
npc) grep -P "^$ARG\t" "$T/npc_ai.tsv" ;;
|
||||
@@ -37,11 +37,11 @@ case "$MODE" in
|
||||
awk -v r="(Collectible|Trinket)[A-Za-z]*[(]([^,()]*,)?($H|$ARG)[,)]" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;;
|
||||
active|card|pill) # id -> case address and label from the exe's jump tables (scripts/use_dispatch.py)
|
||||
F=UseActiveItem; [ "$MODE" = card ] && F=UseCard; [ "$MODE" = pill ] && F=UsePill
|
||||
ROW=$(awk -F'\t' -v k="$MODE" -v i="$ARG" '$1 == k && $2 == i' "$D/use_dispatch.tsv")
|
||||
ROW=$(awk -F'\t' -v k="$MODE" -v i="$ARG" '$1 == k && $2 == i' "$D/analysis/use_dispatch.tsv")
|
||||
[ -z "$ROW" ] && { echo "$MODE $ARG has no case in $F (an active then only adds its TemporaryEffect: try find.sh item $ARG)"; exit; }
|
||||
IFS=$'\t' read -r _ _ ENUM TARGET LABEL ANCHOR SHARES <<< "$ROW"
|
||||
echo "---- $ENUM: case at 0x$TARGET, shared with: $SHARES"
|
||||
"$D/decompile.sh" "^Entity_Player::$F\$" | awk -v r="$LABEL" -v a="$ANCHOR" -v n="${3:-60}" \
|
||||
"$D/scripts/decompile.sh" "^Entity_Player::$F\$" | awk -v r="$LABEL" -v a="$ANCHOR" -v n="${3:-60}" \
|
||||
-v t="LAB_$TARGET:" 'a == "-" || index($0, a) {on = 1} (on && !c && $0 ~ r && ++c) || index($0, t) == 1 {w = n; print "---- line " NR} w > 0 {print; w--}' ;; # also the case code under its LAB_ label (a case that is only a goto)
|
||||
player) H=$(printf '0x%x' "$ARG") # player-type read, then a compare/case with ID within 4 lines
|
||||
awk -v r="([!=]= |case )($H|$ARG)([^0-9a-fx]|$)" '/^\/\/@@ / {h=$2" "$3; next} /_playerType|0x13c0|GetPlayerType/ {w=5} w-- > 0 && $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;;
|
||||
@@ -49,6 +49,6 @@ case "$MODE" in
|
||||
lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;;
|
||||
val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;;
|
||||
field) grep -P -- "$ARG" "$T/zhl_fields.tsv" ;;
|
||||
vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$D/zhl_vtables.tsv" "$ARG" "${3:-60}" ;;
|
||||
vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$D/analysis/zhl_vtables.tsv" "$ARG" "${3:-60}" ;;
|
||||
*) sed -n '2,19p' "$0"; exit 1 ;;
|
||||
esac
|
||||
Reference in new issue
Block a user