dm2-saves: timer-count decode — Mac BE handling missing in GameplaySections::decode; LE path truncates the 9-bit field to 8 bits #170
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The SGB timer-count field (
w_14, mask0xFF 0x01, 9 bits) is read differently in the two decode paths, and both have defects:GameplaySections::decodehas no Mac branch (gameplay.rs:112:timer_count_raw & 0xFF).SaveFile::decode_full(sksave.rs:860-866) documents and fixes exactly this — "Reading it LE on Mac yields a wrong count" — with the 9-bit BE formula(b20 << 1) | (b21 & 1), but the fix never reached the non-full path. Measured on Mac fixtures:early_gamedecodes 0 timers instead of 1 (raw0x0100),endgame11 instead of 22,skullkeep_void_gate12 instead of 24. Every CLI path built ondecode_gameplay_sections(dm2 save show/party/champion/global,dm2 info's section decode) sees a truncated wrong timer list on Mac. Scalar edits still splice byte-safely (the error is symmetric between decode and re-encode), but all timer reads are wrong.& 0xFF) while the engine reads the full i16 (sksvgame.cpp:1517passestimdat.num_timerswhole) and the mask field is 9 bits. Irrelevant for retail DOS (timer cap 50), but SKWINSPX'sDM2_EXTENDED_MODEraises the cap to 500 — an extended-mode save with >255 timers mis-decodes. Should be& 0x1FF.Additionally
info.rs:167printssgb.timer_count_raw & 0xffdirectly, which is wrong on Mac independent of the section decode.Fix direction
One byte-order-aware helper (9-bit, Mac BE formula) used by
decode_full,GameplaySections::decode, and the CLI display — the logic currently exists only inline indecode_full.Reproduction
SaveFile::parse(fixtures/mac-us/saves/early_game, ByteOrder::Big).decode_gameplay_sections()returns 0 timers;decode_fullwith the Mac dungeon decodes 1.Fixed by #209 (merged into
main).