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>
ANM2 handling in isaac-ng.exe (Repentance+ v1.9.7.17)
These notes reconstruct how the game parses .anm2 files and how sprites play them, from the 32-bit isaac-ng.exe in the game root.
Addresses assume ImageBase 0x400000. The zhl.log addresses on disk come from an older build and don't match this one.
| File | Contents |
|---|---|
anm2.hpp / anm2.cpp |
Reimplementation: parser, load-time frame baking, AnimationState, Sprite API |
test.cpp |
Behaviour checks, plus an optional run against a real file |
docs/parser_decomp.md |
Field-by-field parser decompilation, with an address for every claim |
docs/cache_load_decomp.md |
AnmCache, the ANM2 object layout (0x114), and ctor/copy/Load/Reload |
docs/labels_*.json |
Function names for this build, for a disassembler |
Build and test:
g++ -std=c++17 -O2 -msse2 -mfpmath=sse -ffp-contract=off anm2.cpp test.cpp -o anm2_test
./anm2_test path/to/file.anm2 AnimName EventName
-ffp-contract=off matters: the game never fuses multiply-adds, and the interpolated values must match bit for bit.
Pipeline
- Load.
ANM2::Load(0x40bd50) callsAnmCache::Load(0x40db90).- The cache key is djb2 of
mountPrefix + path, lowercased with\turned into/. - On a cache miss,
AnmCache::LoadFile(0x40ed50) parses the file with rapidxml. - The sprite borrows pointers into the cache entry, and entries are refcounted.
- The cache key is djb2 of
- Bake. Everything is precomputed at load time:
- Interpolated keyframes become one-tick frames (0x415170 for layers, 0x414e00 for nulls and root).
- The RootAnimation is multiplied into every layer and null track, splitting frames at root-frame boundaries.
- Nothing is interpolated at runtime, and root frames are not kept.
- Play. Each sprite holds two
AnimationStates: main at +0x30 and overlay at +0x50.- Each one keeps a float
frameand a current keyframe index per track. - It also keeps two event bitmasks:
eventsThisUpdate(+0x18) answersIsEventTriggered.eventsSinceStart(+0x1c) answersWasEventTriggered.
- Each one keeps a float
Events and triggers
- Event table:
<Events>holds at most 16 names, and each id must equal its position. The sprite looks an event name up linearly and tests bitiof the mask. - Triggers:
<Trigger EventId AtFrame>holds raw ints, at most 128 per animation, with no validation. - Firing (0x408c90): for each trigger, if
(float)AtFrame == frameexactly, the game sets bitEventId & 31in both masks. Update(0x409030): this is the only place frames are stepped.- It computes
nf = floor(frame + PlaybackSpeed). - If
nf < FrameNum, it callsAdvancePosition(nf)and then storesframe + speed, so fractional frames are kept. AdvancePositionfirst clearseventsThisUpdate, then runsframe = floor(frame)+1and fires triggers on every whole frame up tonf. So with speed > 1, no event is skipped mid-animation.- If
nf >= FrameNumand the animation loops, it callsRewind()instead.- Rewind sets the frame to 0, clears both masks and fires the frame-0 triggers.
- The frames between the old position and the end are not stepped, so with speed > 1 an event near the end of a loop can be skipped.
- If
nf >= FrameNumand the animation doesn't loop, it callsAdvancePosition(FrameNum-1), but only when that isn't behind the current frame, and then setsplaying = false.
- It computes
- Masks while stopped:
Updatereturns immediately when stopped, so the masks are left as they were.- If the update that finished the animation crossed an event frame,
IsEventTriggeredstays true from then on. - The same happens after
Stop(). - In the normal speed-1 case the final update clears the mask, because it re-advances to the frame it is already on.
- If the update that finished the animation crossed an event frame,
Play(name)(0x40a380): it doesSetAnimationData(frame=-1, masks cleared, indices -1), thenRewind, thenplaying = true.- Frame-0 events are already set when
Playreturns. - With the same name and no
force:- a non-looping animation is never restarted, even after it has finished;
- a looping animation restarts only if it was stopped.
- Frame-0 events are already set when
SetFrame(f)(0x408e00): clamps tonextafterf(FrameNum, 0)and clears onlyeventsThisUpdate.- Triggers fire only when the clamped frame exactly equals AtFrame.
- Track indices are reset to 0 and moved forward to the unclamped f.
Sprite:SetFrame(name, f)also stops playback;SetOverlayFrame(name, f)does not.
NextEventTrigger(0x40af10): returns the nearest AtFrame strictly greater than(int)frame(truncated, not floored), or -1.- Lua
Sprite:IsEventTriggered/WasEventTriggered: these only look at the main state. - Playback speed:
PlaybackSpeed(+0x104) is shared by both states. A negative speed logs "cannot go backward" and fires nothing.
Bugs in the original
These are not reproduced; each one is marked ORIGINAL: in the code.
AnimationState::ChangeAnimationKeepFrame(0x408970) is reached throughSetAnimation(name, false). It has two bugs:- When the new animation has a different, non-zero null-animation count, the new null index array is stored into the layer slot (
mov [esi+8], ebxat 0x408b6a). The null slot is left NULL, so the nextUpdatedereferences NULL. - It also copies the old layer count into the new array, which overflows the heap when the new animation has fewer layers.
- When the new animation has a different, non-zero null-animation count, the new null index array is stored into the layer slot (
- Parser:
- Every limit (16/64/128/5000/256) only logs and keeps writing.
- A missing required element (
Content,RootAnimation,Triggers, …) is a NULL dereference. LayerId="-1"overwrites the animation'sLoopflag.- Frame attributes that are missing keep stale values from a reused scratch buffer, so a missing XScale can mean scale 0.
- An animation with no root frames applies an uninitialised root transform.
GetLayerFrame(0x40a220) has an off-by-one bounds check (jg).ANM2::Loadsetsloadedeven when loading failed.Sprite:Reloadleaks one cache reference per call.
Not covered
- Rendering:
AnimationLayer::RenderFrame(0x409120) only reads the current baked frame, throughlayerFrameIdx. - Texture loading.
- The spritesheet path resolver (0x67f670): it was only skimmed, and
ResolveRelativePathhere approximates it.