Ghidra 12.2 project and full dump of isaac-ng.exe v1.9.7.17, query scripts, notes indexed by entity, anm2/rooms reimplementations, and db/ (names + fields) that build.sh re-applies. Fixes awk numeric address comparison in find.sh/decompile.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Room config (.stb) handling in isaac-ng.exe (Repentance+ v1.9.7.17)
| File | Contents |
|---|---|
stb.hpp / stb.cpp |
Binary format, room reader, door-slot mapping, variant ranges, mod merge |
rooms.hpp / rooms.cpp |
RNG, stages.xml, lazy stage loading, room selection, spawn picking, GetStageID |
test.cpp |
Checks; pass a resources dir to load real data |
docs/rooms_load_decomp.md |
Stage table, stages.xml, load timing, mod merge (with addresses) |
docs/rooms_use_decomp.md |
RNG, GetRandomRoom, PickEntry, weights, Room::Init spawning (with addresses) |
docs/stbdump.py |
Standalone Python .stb parser |
docs/rex.py, docs/labels_*.json |
The disassembly helper and function names used for this work |
g++ -std=c++17 -O2 -ffp-contract=off stb.cpp rooms.cpp test.cpp -o rooms_test
./rooms_test ".../dump/rep+full/resources"
File format
Little-endian and packed, with no padding:
"STB1" u32 roomCount
room: u32 type u32 variant u32 subtype u8 difficulty u16 nameLen char name[nameLen]
f32 weight u8 width u8 height u8 shape u8 doorCount u16 spawnCount
door[doorCount]: i16 x i16 y u8 exists
spawn[spawnCount]: i16 x i16 y u8 entryCount
entry[entryCount]: u16 type u16 variant u16 subtype f32 weight
- Magic: only
STB1is accepted. - Error handling: read results are never checked.
- Coordinates: they are relative to the interior, so the left wall is x=-1 and a 1x1 room's right wall is x=13.
- Doors: each door becomes a bit (DoorSlot 0–7) through a fixed position table, 0x829a10. That table also covers the inner walls of L-shaped rooms (x=12, y=6, and so on).
- A door with
exists=0is dropped. - All 30,845 vanilla rooms parse with no leftover bytes, and every door maps to a valid slot.
- A door with
- Entry types: type is u16 on disk.
- Types below 1000 are entities.
- 1000 and up are grid entities: 1000 = rock, 4500 = pressure plate, 9000 = trapdoor, and so on.
- 970 is a metadata marker that spawns nothing.
- Flags computed at load:
- A room containing a 4500.0 entry gets flag 0x80.
- An entry 970.2 standing on a door tile sets that door's bit in a second mask (+0x3c).
- Two hard-coded vanilla fixups:
- stages 1–3, variants 603 and 716 get flag 4;
- stages 29–30, type 1 with subtype 31 get flag 2.
Where files come from
stages.xml(parsed at 0x82b2f0) defines 37 stage slots.- Each
pathsets bothrooms/<path>(normal) androoms/greed/<path>(greed). .xmlis replaced by.stbat load time. No.xmlroom file is read for stages; only the--load-room=debug option reads one.
- Each
- Loading is lazy. It happens per (stage, mode) the first time a stage is needed. Level::Init resets weights for the stages it uses: the current stage, stage 0 (special rooms), Mines in some cases, and 1–17 except 13 on The Void.
- Vanilla files can be replaced through
<mod>/resources[-dlc3]/rooms/X.stb. - Mod content files are appended:
<mod>/content[-dlc3]/rooms/X.stbis appended after the vanilla rooms, in mod order.- A (type, variant) that is already taken is remapped by extending the lowest variant interval for that type. A bug makes this hand out variants that already exist once the first gap is used up, and lookups then return the vanilla room.
- A bad header in one mod's file stops the merge for every mod after it.
Picking a room (GetRandomRoom 0x82c7d0)
-
Filter:
- type must match;
- shape must match, or the query shape is 13 (any);
- variant must be in range (unsigned compare);
- difficulty must be in range (signed compare);
- the room must have all the required doors;
- subtype must match, or the query subtype is -1 (any);
- with seed effect 79, rooms with flag 0x80 are dropped.
On The Void, candidates come from stages 1–17 except 13, with max difficulty forced to 20.
-
Sum weights: add up
Weightover all candidates. Separately, sum over the "exact" candidates whose door mask equals the requested doors exactly. -
Draw: use
RNG(seed, shift 7). When there are exact candidates, a second drawf2decides the list: if9.99 * exactSum/total > f2, the room comes from the exact list. In practice, rooms whose doors match exactly almost always win. -
Pick: return the first room whose cumulative weight is strictly greater than
f1 * sum. -
Reduce: with
reduceWeight, the picked room's weight becomesmax(1e-7, w*0.1). The weight is reset from InitialWeight on the next Level::Init for that stage. -
No match: log a warning and return NULL. Wrapper 0x82cdd0 then retries with a fallback stage.
Not reimplemented: the Curse of the Giant path. 50% of type-1 picks split a big shape into two smaller rooms (0x82d880) and merge them into a generated room (0x82d4a0); the merge wasn't decoded.
Spawning (Room::Init 0x7f2800)
- Pick:
RNG(desc.spawnSeed, shift 11)advances once per spawn, even when the spawn has no entries.PickEntryreturns the first entry whose cumulative weight is greater thanf * sumWeights, and falls back to entry 0. - Placement:
gridIdx = (x+1) + (y+1)*gridWidth, with world position(col*40+40, row*40+120). - Spawn: type < 1000 goes to
Game::Spawn; type ≥ 1000 becomes a grid entity, mapped through jump tables listed in the docs. - Two passes: an earlier pass with the same seed handles meta types 825–970 (room and descriptor flags). Its details are in the docs.
Not covered:
- the entry transform at 0x7ec100, which handles stage replacements and probably the Lua spawn callback;
- the full grid-type jump tables;
- the RoomDescriptor+0x80 skip set;
- Room +0x50/+0x54;
- the name of seed effect 79.