Skip to content

Keep shuffled object descriptions across save and restore - #62

Merged
Critlist merged 2 commits into
masterfrom
fix/restore-object-descriptions
Nov 11, 2026
Merged

Critlist merged 2 commits into
masterfrom
fix/restore-object-descriptions

Conversation

@Critlist

Copy link
Copy Markdown
Owner

After a restore, every unidentified potion, scroll, ring, wand and gem showed its fixed default appearance instead of the game's shuffled one: a "ruby potion" came back as a "sky blue potion", items changed names mid-game, and every restored game shared the same mapping. Found by play-testing; present since a868d96 (v1.1.4).

Cause: the original code saved objects[] with raw oc_descr pointers, which only worked with fixed load addresses. a868d96 fixed the resulting crash by keeping the running binary's pointers, but the restore path never calls init_objects(), so those are the unshuffled defaults.

Fix: save the shuffle, not pointers. dosave0() appends a tagged block after the last level (tag RHDS, version, count, and per object the index of the default description it shows). dorecover()'s level loop recognises the tag (level numbers are 1..40, so it can't collide), validates the block and rebuilds oc_descr from this binary's default strings.

  • Saves from earlier versions have no block and load exactly as before (default appearances).
  • A damaged or truncated block falls back to the defaults with a warning.
  • No original code removed; uptodate() untouched.

Verified:

  • GCC Debug and Clang Release build with zero warnings; smoke/map/qwertz pass.
  • Unfixed master, 3 runs: pink/swirly/yellow → sky blue after restore.
  • Fixed, 6 runs: appearance kept through restore and a second save/restore cycle.
  • Multi-level save (DL3, levels 1–2 stored before the block) restores correctly.
  • Old master saves load cleanly; corrupted/truncated blocks fall back to the defaults.
  • ASan/UBSan clean across all of the above.

Known, not in scope: restoring a save written by a different binary can still crash in restmonchn() (pointer relocation into globals outside mons[]); pre-existing, and currently masked by uptodate().

🤖 Generated with Claude Code

restnames() keeps the running binary's oc_descr pointers, but on the
restore path init_objects() is never called, so those pointers are the
unshuffled defaults: every restored game showed the default appearances
(e.g. "sky blue potion") and items changed names after a restore.

Save the shuffle itself instead of pointers: dosave0() now appends a
tagged block after the last level (tag, version, count, and for each
object the index of the default description it shows). dorecover()'s
level loop recognises the tag, validates the block and rebuilds oc_descr
from this binary's default strings. Saves without the block (earlier
versions) load as before with default descriptions; a damaged or
truncated block falls back to the defaults with a warning.
Critlist added a commit that referenced this pull request Nov 11, 2026
@Critlist
Critlist merged commit 8607bad into master Nov 11, 2026
7 checks passed
neuhaus pushed a commit to neuhaus/restoHack that referenced this pull request Nov 15, 2026
…iptions

Keep shuffled object descriptions across save and restore
Critlist added a commit that referenced this pull request Nov 18, 2026
docs: CHANGELOG entries for unreleased changes (#31, #42, #43, #45-#62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant