365 lines
28 KiB
Markdown
365 lines
28 KiB
Markdown
# Repentance+ decompilation toolkit
|
||
|
||
Ghidra 12.2 headless setup for `isaac-ng.exe` (**v1.9.7.17**, PE32 i386, MSVC, RTTI present), with names from
|
||
REPENTOGON's signatures, the game's own Lua-API registration table and an NPC AI dispatch table. Use it to read
|
||
real game behaviour instead of wiki text, and to grow it into readable source: every name, type and note you
|
||
add is kept and re-applied (see **Adding findings back**). Everything is in this folder. Nothing outside it is touched
|
||
(Ghidra writes its user settings to `~/.config/ghidra` and `~/.cache/ghidra`), and the game install is only read.
|
||
|
||
**Private.** This repo holds decompiled game code. It is a local git repo with no remote: never push it, publish
|
||
it, or paste large parts of it anywhere public. The game install is only read, never modified.
|
||
|
||
```
|
||
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
|
||
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 (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/ 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, Dear ImGui (docking)
|
||
assets/ files the repository ships itself (git-lfs): the overlay's fonts, with their licences
|
||
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
|
||
```
|
||
|
||
## Reconstruction
|
||
|
||
The goal is a C++ source tree that builds a native 64-bit Linux game: `git submodule update --init --recursive`, then
|
||
`cmake -B build && cmake --build build`. SDL3 (window, OpenGL context, input, audio) and Lua 5.3 (mods) are submodules
|
||
in `external/`, built statically, with simdjson for data and Xiph's Ogg, Vorbis and Theora (decoders only) for the cutscene videos. Online features (Steam, EOS, curl) are offline stubs. The game
|
||
reads JSON, not XML: an import tool in `tools/` converts the player's own install (XML, packed archives) and mods into
|
||
`resources/` (both gitignored). Nothing from the game ships here.
|
||
`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/engine/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.
|
||
|
||
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 ...)
|
||
overlay/ the developer overlay (CMake option ISAAC_OVERLAY, on by default): ` shows it in place of the console,
|
||
with the Console, Game Options, Mods and Debug windows on Dear ImGui
|
||
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.
|
||
The first three leave the developer overlay out, so the console behaves as the original's.
|
||
|
||
```
|
||
--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
|
||
--screenshot-every N a windowed run saves every Nth frame (as Isaac.GetFrameCount() counts) to screenshots/
|
||
```
|
||
|
||
`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`.
|
||
`tools/harness/goldens/check.sh` replays about 70 recorded runs (every character, the main and alternate floors,
|
||
every final boss, Greed and Greedier, challenges, typed seeds, saving and continuing) on three saves (nothing unlocked
|
||
in Hard, everything unlocked in Normal and in Hard) and names each trace that changed; `--record` re-records them.
|
||
Traces follow the compiler's float code, so check with a clang build, as the goldens were recorded.
|
||
|
||
## Quick use
|
||
|
||
```sh
|
||
cd <this folder>
|
||
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
|
||
(`Class::Method`). It prints up to MAX (default 20) functions. Reading the dump is instant and safe for many
|
||
agents at once. `--live` copies the project to a temp dir first, because Ghidra locks a project even read-only,
|
||
so parallel live calls work too. Set `DECOMP_TIMEOUT=secs` for big functions (default 180).
|
||
|
||
`find.sh` modes (run it without args to list them): `name REGEX`, `str REGEX` (strings and their users),
|
||
`strs FUNC` (strings a function uses), `code REGEX` (functions whose C matches, with hit counts),
|
||
`callers X`, `callees X`, `npc TYPE`, `item ID`, `active ID [N]`, `card ID [N]`, `pill ID [N]`, `player ID`, `enum REGEX`, `lua REGEX`, `field REGEX`, `val ADDR`,
|
||
`vtable CLASS` (slots read from the exe's RTTI: the authoritative way to name Update/Render/Fire... of an Entity_* or Weapon_* class).
|
||
|
||
## Naming you will see
|
||
|
||
| prefix | source | trust |
|
||
|---|---|---|
|
||
| `NpcAI::ENTITY_<NAME>` | NPC AI dispatch table, named by the first entity type that uses it | high, but it is the first call in the case block: if one has many callers it is a shared helper (that is how ProjectileParams::ProjectileParams got called ENTITY_GEMINI). Types 79 Gemini and 93 Mask have no AI function at all: their case is inline in the dispatcher |
|
||
| `Entity_Player::UseActiveItem`, `Sprite::Play`, `Game::GetRoom` ... with comment `ZHL [lua]` | the game's own Lua API registration (method name -> C++ function) | high, but see the ICF note |
|
||
| comment `ZHL [exact]` | REPENTOGON byte signature, exact unique match | high for long sigs, but not proof (0099b520 matched Entity_Player::InitPreLevelInitStats exactly and is GridEntity_Gravity::PostInit); short sigs can hit the wrong function; where the Lua table disagrees, db/names.tsv records the Lua name (e.g. 007ab380 is `Entity_Player::AnimateCollectible`, not HasCollectible) |
|
||
| comment `ZHL [prefixN/M]` | the sig failed (version drift); the longest unique prefix of N of M bytes matched | medium |
|
||
| comment `ZHL [vtable slot N]` | REPENTOGON vtable layout applied to the RTTI `Class::vftable` | high |
|
||
| comment `DB: ...` | `db/names.tsv`, a person or agent checked it (the note says how) | highest; overrides all of the above |
|
||
| `NpcHelper::...` | `db/names.tsv`: a helper of one NPC AI that takes more than the npc (so not typed `npc`) | as its note says |
|
||
| `FUN_xxxxxxxx` | unnamed | |
|
||
|
||
About 730 functions are named from signatures (679 exact plus 75 prefix; 224 sigs missed and 196 matched in more
|
||
than one place, because REPENTOGON targets 1.9.7.12), about 160 from vtables, about 1100 from Lua registrations,
|
||
and 230 `NpcAI::` routines.
|
||
**ICF caveat:** MSVC folds identical tiny functions, so a 1–3 instruction getter can carry an unrelated name
|
||
(`EntityPtr::Ref` is also `RNG::GetSeed`, `Level::GetCurrentRoom` is `Game::GetRoom`, and so on). Judge tiny
|
||
functions by their body, not their name.
|
||
|
||
**Struct fields are only shown where this exe confirms the offset.** REPENTOGON's definitions target 1.9.7.12 and members
|
||
drift (Game +0x58 .. +0xd98 in steps, Entity_Player +4 .. +0x2c, Entity_Familiar +0x14, GridEntity_Door +0x114), so a
|
||
REPENTOGON offset is never evidence by itself, not even between two confirmed neighbours with the same shift (that put
|
||
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. `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.
|
||
|
||
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
|
||
pops its own stack arguments (`RET n`), so the declared parameters must add up to `n` (`scripts/ApplyProtos.java`, about
|
||
1,150 functions with `db/protos.zhl`; the comment says `prototype: REPENTOGON, confirmed by RET n` or names the db file).
|
||
Whole-program optimisation gives some functions other registers; REPENTOGON's notation covers them: `float r<xmm3>`,
|
||
`int x<edx>`, a `float<xmm0>` return, and `static cleanup` for a caller that pops the stack (RET n cannot check those).
|
||
Methods with a REPENTOGON `__thiscall` declaration get a typed `this`; so does any other `Class::method` whose reads
|
||
from ECX land at least 60% inside Class's confirmed fields (`scripts/this_types.py`, ~800 methods; the Lua `Sprite` and
|
||
`Color` classes are ANM2 and ColorMod). Every `NpcAI::` routine is
|
||
`__fastcall (Entity_NPC *npc)`, so you read `npc->_state`, `npc->_variant`, `npc->_i1` rather than
|
||
`param_1[0x2d9]`. Unknown offsets still show as `field_0xNNN` or `*(int *)(p + 0xNNN)`. Look them up with
|
||
`find.sh field` or `find.sh lua` (the Lua table has authoritative offsets such as `EntityNPC State field+0xb64`).
|
||
|
||
Useful offsets (Entity / Entity_NPC; check with `find.sh field`): Type 0x28, Variant 0x2c, SubType 0x30,
|
||
Position 0x33c... (`_pos`), NPC StateFrame 0x410, Pathfinder 0x414, State 0xb64, ProjectileCooldown 0xba0,
|
||
V1 0xbb0, V2 0xbb8, I1 0xbc0, I2 0xbc4. Entity_Player PlayerType 0x13c0.
|
||
|
||
## From an id to its code
|
||
|
||
**Entity (entities2.xml `id` = type).** `Entity_NPC::Update` (006c4b30) calls `Entity_NPC_UpdateAI_dispatch`
|
||
(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. `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
|
||
7 types. The routine is named after the lowest type.
|
||
3. Types whose case is the default block (`006c41af`, about 630 ids) have no AI in this dispatcher. They are
|
||
effects, pickups and so on, or are handled elsewhere: in `Entity_NPC::Update` itself (look for
|
||
`this->_type == N` there), in Entity_Effect/Entity_Familiar `Update` (big switches on variant), or in Lua.
|
||
Two types (98 Heart of Infamy, 922 Cadavra) run inline code with no call. Read that with
|
||
`decompile.sh --asm <case block>`.
|
||
4. Entity states are `npc->_state` (Lua `npc.State`). REPENTOGON has no NpcState enum, so use the modding docs' NpcState
|
||
values: 0 init, 3 idle, 4 move, 8 attack, ... Animations come from the string args:
|
||
`Sprite::Play` / `Sprite::SetAnimation` / `Sprite::IsEventTriggered("Shoot")` / `Sprite::IsFinished("Attack")`.
|
||
The decompiler often prints only the string (`FUN_0040a5d0("WalkVert",1)`), because the sprite is passed
|
||
in ECX.
|
||
5. Bosses work the same way (`find.sh npc 20` -> `NpcAI::ENTITY_MONSTRO`). Projectile patterns go through
|
||
`Entity_NPC::FireProjectiles(pos, vel, mode, params)` and `FireBossProjectiles`. `ProjectileParams` field
|
||
offsets are in `find.sh lua ProjectileParams`.
|
||
|
||
**Item / trinket id.** There is no table, because effects are scattered `HasCollectible(id)` checks:
|
||
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:** `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 `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.** `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: `scripts/find.sh code 'GetPlayerType'`, and look in `Entity_Player::Init`, `Update`, `EvaluateItems`,
|
||
`TakeDamage`.
|
||
|
||
**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)
|
||
|
||
```
|
||
$ scripts/find.sh npc 29
|
||
29 ENTITY_HOPPER 006c3b4d 00526470:NpcAI::ENTITY_HOPPER
|
||
$ scripts/find.sh strs NpcAI::ENTITY_HOPPER
|
||
Appear Attack BigJumpDown BigJumpUp Hop Hop2 HopLong HopShort JumpDown Regen Shoot ShootDown
|
||
$ 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,') */
|
||
local_278 = "JumpDown"; pcVar18 = "ShootDown"; }
|
||
else if (iVar13 == 0x131) { ... /* 305 = ENTITY_MINISTRO */
|
||
uVar15 = npc->_i1 & 1; ... "Hop2" : "Hop" /* alternates hop anim on I1 */
|
||
... npc->_state = 8 / 7 / 4 ... switch(npc->_i1) { ... }
|
||
```
|
||
One routine serves 7 types (Hopper, Keeper, Ministro, ...), and they branch on `npc->_type`. From here, follow
|
||
the `npc->_state` transitions, the `"Hop"` animation/event checks and the velocity math. Constants the
|
||
decompiler did not inline show as `DAT_00xxxxxx`. Read those with `find.sh val`.
|
||
|
||
## Worked example 2: Gaper (type 10)
|
||
|
||
`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`.
|
||
|
||
## Worked example 3: item effect, Cricket's Head (collectible 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
|
||
$ 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;
|
||
$ 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)) {
|
||
pEVar51->_damage = pEVar51->_damage * 1.5;
|
||
```
|
||
So each Cricket's Head copy adds +0.5 to the flat damage-up sum it shares with several other items. It also
|
||
grants the ×1.5 damage multiplier, the same one given by Magic Mushroom (12) and by Blood of the Martyr (7)
|
||
together with the Book of Belial (34) effect. The multiplier applies once, not per copy.
|
||
|
||
## Worked example 4: active item, The Bible (33)
|
||
|
||
```
|
||
$ scripts/find.sh active 33 25
|
||
---- line 628
|
||
case 0x21:
|
||
FUN_009568e0(); ... (sound/effect calls)
|
||
Room::GetEntities(); ... loop:
|
||
if ((Entity::Type() == 0x2d) || (Entity::Type() == 0x4e)) { /* Mom (45) / Mom's Heart (78) */
|
||
(*(code **)(*piVar21 + 0x24))(); /* vtable slot 9 = Kill */
|
||
```
|
||
`active` prints the one case the jump table sends id 33 to (`use_dispatch.tsv`), with the other ids sharing it.
|
||
|
||
## What works / what doesn't
|
||
|
||
- Works: the full dump of 21k functions (all but about 20 decompile), name and address lookup, strings with
|
||
users, call graph, NPC type to AI for 324 types, Lua API names (Sprite, Entity, Player, Room, Game ...),
|
||
typed NPC AI, constants, live decompile and disassembly, and running agents in parallel.
|
||
- Doesn't: 22 functions are not in the dump because they timed out at 900 s (`grep -B1 'decompile failed'
|
||
dump/all.c`). Most are unnamed CRT/GL code; `Entity_Effect::Update` (times out even at 7200 s) and
|
||
`Entity_NPC::HandleCollision` (decompiler error "PTRSUB off of non structured pointer type") do not
|
||
decompile at all; read them with `--asm`. `build.sh` retries named failures
|
||
automatically and splices them in (`scripts/splice.py`). For anything else use `--asm`.
|
||
- Item, trinket and player lookups are grep heuristics. Struct fields not confirmed in this exe are `field_0x...`.
|
||
A function with no confirmed prototype can still show `in_ECX + 0x13c0` or odd parameter types guessed by the
|
||
decompiler; if you work out its signature, add it to `db/protos.zhl`.
|
||
|
||
## Adding findings back
|
||
|
||
Whatever you learn reading the code goes back into the repo, so the next reader gets it for free. Never leave a
|
||
finding only in your scratch files or your final message.
|
||
|
||
1. **A function's real name** (a `FUN_`, or a wrong ZHL/ICF name such as `MinimapConfig::Render` being the Gate AI):
|
||
add a line to `db/names.tsv` (address in any hex form): `address<TAB>Qualified::Name<TAB>evidence`. Use `NpcAI::ENTITY_<ENUM>[_part]` for
|
||
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, `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.
|
||
**A local variable** in a function you have read closely: `function<TAB>local_2c0<TAB>newName[<TAB>C type]` in
|
||
`db/locals.tsv`. Only when every use has the same role: MSVC reuses registers and stack slots (see the file header).
|
||
Name-only rows reach the dump with `apply_db.py`; rows with a type (e.g. `Vector` for an x/y pair) need `--db`.
|
||
**A global** (a `DAT_<address>` you identified, e.g. the Game singleton): `address<TAB>g_name<TAB>C type<TAB>evidence`
|
||
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: `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: `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. `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 (`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.
|
||
|
||
## Setting up from scratch
|
||
|
||
Git keeps everything except the large tools and inputs (see `.gitignore`). On a fresh checkout:
|
||
|
||
- `jdk/`: a Temurin 21 JDK (portable tarball, unpacked as `jdk/`). System Java 8 is too old.
|
||
- `ghidra_12.2_PUBLIC/`: Ghidra 12.2 release zip, unpacked here.
|
||
- `repentogon/`: `git clone --depth 1 https://github.com/TeamREPENTOGON/REPENTOGON.git repentogon` (the dump was
|
||
built from commit e2c5aecacbbb83bb5938cfa89c0a58b78e616a36). `find.sh enum` and `build.sh` read it.
|
||
- `bin/isaac-ng.exe`: `build.sh` copies it from the game install.
|