Rewind the run record when Continue replays a room #335

Merged
nelsong6 merged 1 commit from codex/rewind-record-on-continue into main 2026-09-18 09:37:22 -07:00
nelsong6 commented 2026-09-18 09:37:17 -07:00 (Migrated from github.com)

Problem

A Save and Quit mid-shop/event followed by main-menu Continue replays the room from current_run.save, but OnRunStarted only adopted the existing record. Gold spent, cards bought and relics taken during the abandoned visit stayed committed and were banked again on the replay. The replayed AfterRoomEntered then overwrote RoomResetter's snapshot with the inflated record.

Fix

  • Take the rewind snapshot at the game's own write: RunSaveSnapshotPatch prefixes RunSaveManager.SaveRun(AbstractRoom) (same synchronous segment as RunManager.ToSave, same write condition). Nothing the game replays after the save — room creation, entry hooks, the visit — is in the snapshot. Replaces the AfterRoomEntered capture and subsumes AncientEventRewindSnapshotPatch.
  • A combat-victory save still defers to after CombatEnded's promotion, with no snapshot in the gap.
  • Each snapshot is tagged with its save point (act, map coord, total floor). Both Continue adoption paths rewind to it when the save being loaded is that one; a mismatch leaves the record alone and logs why. Core hot-reload resume never rewinds.
  • Snapshot file moves to user://SpireLens/run-save-snapshot/ with the tag; untagged room-entry/ files are ignored.
  • Primer's rewind section updated.

The suspected double-count of an Ancient's arrival heal doesn't happen: out of combat CreatureCmd.Heal never raises AfterCurrentHpChanged, so the heal isn't recorded at all.

Validation

Core and test projects build; deployed and hot-reloaded (HOT RELOAD DONE, Core.Initialize complete, 437 patch classes, 0 failed; RunSaveManager.SaveRun listed as patched). Tests and live behavioral verification not run.

## Problem A Save and Quit mid-shop/event followed by main-menu Continue replays the room from `current_run.save`, but `OnRunStarted` only adopted the existing record. Gold spent, cards bought and relics taken during the abandoned visit stayed committed and were banked again on the replay. The replayed `AfterRoomEntered` then overwrote RoomResetter's snapshot with the inflated record. ## Fix - Take the rewind snapshot at the game's own write: `RunSaveSnapshotPatch` prefixes `RunSaveManager.SaveRun(AbstractRoom)` (same synchronous segment as `RunManager.ToSave`, same write condition). Nothing the game replays after the save — room creation, entry hooks, the visit — is in the snapshot. Replaces the `AfterRoomEntered` capture and subsumes `AncientEventRewindSnapshotPatch`. - A combat-victory save still defers to after `CombatEnded`'s promotion, with no snapshot in the gap. - Each snapshot is tagged with its save point (act, map coord, total floor). Both Continue adoption paths rewind to it when the save being loaded is that one; a mismatch leaves the record alone and logs why. Core hot-reload resume never rewinds. - Snapshot file moves to `user://SpireLens/run-save-snapshot/` with the tag; untagged `room-entry/` files are ignored. - Primer's rewind section updated. The suspected double-count of an Ancient's arrival heal doesn't happen: out of combat `CreatureCmd.Heal` never raises `AfterCurrentHpChanged`, so the heal isn't recorded at all. ## Validation Core and test projects build; deployed and hot-reloaded (`HOT RELOAD DONE`, `Core.Initialize complete`, 437 patch classes, 0 failed; `RunSaveManager.SaveRun` listed as patched). Tests and live behavioral verification not run.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens!335
No description provided.