Repository navigation
Load the original's saves that have signs or a Great Wall - #154
Open
MortenLyhr wants to merge 4 commits into
Open
MortenLyhr wants to merge 4 commits into
MortenLyhr wants to merge 4 commits into
Conversation
Owner
|
The comment at |
The original stores signs and engine-made lines (the Great Wall) after the
pickled Python data; reading a fixed 33 bytes there failed on such saves
("save file truncated"). Keep the section's bytes so they can be written back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A save may carry more data after the MD5 string (OpenCiv4's own Great Wall block), so taking the last 36 bytes as the MD5 broke loading of such saves with "save file truncated". The reader now looks for the first int 32 followed by 32 hex digits after the Python data; the engine's section before it holds only ints, floats and UTF-16 text. Adds save_file_test, which round-trips an empty engine section, one laid out like the original's, and both with a block after the MD5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
saveGame built a fresh SaveFile, so re-saving an original save wrote the empty section (33 zeros) and dropped its signs and Great Wall lines. GameSession now keeps the section from loadGame and writes it back as it was; a new game or scenario clears it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r it Drop the comment and the test cases about blocks after the MD5 string: nothing writes one. New cases cut the file 1 to 50 bytes short of its end (inside the MD5 string, just before it, inside the engine section) and expect read to throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MortenLyhr
force-pushed
the
fix/save-compat
branch
from
November 23, 2026 09:03
6c4223d to
1777dc7
Compare
Contributor
Author
|
Thanks, all three are done:
ctest passes (16/16). The sync checksum at turn 100 ( 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original engine keeps its own data after a save's pickled Python data: the map's signs and the lines it laid
(the Great Wall), then the MD5 string.
SaveFile::readskipped a fixed 33 bytes there (the size of the section when itis empty), so any original save with a sign or a wall failed to load with "save file truncated". One example is a
scenario with landmarks.
The reader now takes the whole section, up to the MD5 string, and keeps it in
SaveFile::engineData. The section's sizeisn't stored, so the MD5 string (int 32, then 32 hex digits) is found by its form: the first one after the Python data.
The section before it holds only ints, floats and UTF-16 text.
GameSessionkeeps a loaded save's section, andsaveGamewrites it back unchanged, so re-saving an original save keeps its signs and wall. New games and scenarioswrite the empty section, as before. OpenCiv4 doesn't read the section's contents: signs placed in OpenCiv4 aren't saved
yet, and a re-saved wall is the one from the turn the save was made. The layout was found by comparing the original's
saves (a 140-save Wine game and the saves in
testgames) with OpenCiv4's.Not in this PR: the original still rejects OpenCiv4's saves. That comes from the salted MD5 at the end, not from this
section, and its algorithm is known only from the exe, so the clean-room rule rules it out.
New ctest
save_file_test: round-trips an empty engine section and one laid out like the original's (a sign, a wallline, the tail that holds a 32), and checks that a file cut short anywhere from inside the engine section to the last
byte of the MD5 throws.
Tested:
W-antium,AutoSave_Initial, and empty-section ones) load, save, load again and save again. Both re-saves keep the enginesection byte for byte.
--turns 100 --map Fractal --size STANDARD --seed 7are unchanged (D7D43800at turn 100).🤖 Generated with Claude Code