Puppeteer
Emperor
I just successfully loaded a save game file that was decompressed using my code.
I ran into a couple of snags:
- I had to negate the offset for the seek call
- I had to subtract one from the negated seek, because .Seek(0,2) puts the read pointer after the last byte, but for coded offset 0 I want to read the last byte, so the pointer needs to back up one extra byte first, so .Seek(-1-offset,2).
After that it looked like it might be working and indeed worked on a small test case spelled out in the specification. But from experience I could see the hex dump looked a little suspicious, and sure enough Civ3 crashed when trying to load it.
I was worried it was going to be hard to figure, then I recalled a special case I hadn't coded in: "There is one exception to this: if the copy length is equal to 2, then only two low-order offset bits are encoded instead of 4, 5, or 6." Once I coded that exception in, things looked more normal and Civ3 loaded the resulting decompressed save file.
The hard-to-figure part is done, but now I need to refactor the decompression logic into a package which might take a little time.
Sample output:
Spoiler :
Code:
000df310 52 50 4c 45 0a 00 00 00 06 01 14 00 08 00 03 ff |RPLE............|
000df320 00 00 00 52 50 4c 45 0a 00 00 00 06 01 16 00 08 |...RPLE.........|
000df330 00 03 ff 00 00 00 52 50 4c 45 0a 00 00 00 06 01 |......RPLE......|
000df340 13 00 09 00 03 ff 00 00 00 52 50 4c 45 0a 00 00 |.........RPLE...|
000df350 00 06 01 15 00 09 00 03 ff 00 00 00 52 50 4c 45 |............RPLE|
000df360 0a 00 00 00 06 01 17 00 09 00 03 ff 00 00 00 52 |...............R|
000df370 50 4c 45 0a 00 00 00 06 01 14 00 0a 00 03 ff 00 |PLE.............|
000df380 00 00 52 50 4c 45 0a 00 00 00 06 01 16 00 0a 00 |..RPLE..........|
000df390 03 ff 00 00 00 52 50 4c 45 0a 00 00 00 06 01 15 |.....RPLE.......|
000df3a0 00 0b 00 03 57 00 00 00 52 50 4c 45 0a 00 00 00 |....W...RPLE....|
000df3b0 04 01 15 00 09 00 00 ff d0 d0 44 61 72 68 61 6e |..........Darhan|
000df3c0 00 52 50 4c 54 05 00 00 00 02 01 00 00 00 0b 00 |.RPLT...........|
000df3d0 00 00 52 50 4c 45 0a 00 00 00 06 01 0f 00 07 00 |..RPLE..........|
000df3e0 03 2e 00 00 00 52 50 4c 45 0a 00 00 00 06 01 0e |.....RPLE.......|
000df3f0 00 08 00 03 65 00 00 00 52 50 4c 45 0a 00 00 00 |....e...RPLE....|
000df400 06 01 10 00 08 00 03 2f 00 00 00 52 50 4c 45 0a |......./...RPLE.|
000df410 00 00 00 06 01 0d 00 09 00 03 2f 00 00 00 52 50 |........../...RP|
000df420 4c 45 0a 00 00 00 06 01 0f 00 09 00 03 2e 00 00 |LE..............|
000df430 00 52 50 4c 45 0a 00 00 00 06 01 11 00 09 00 03 |.RPLE...........|
000df440 2f 00 00 00 52 50 4c 45 0a 00 00 00 06 01 0e 00 |/...RPLE........|
000df450 0a 00 03 2e 00 00 00 52 50 4c 45 0a 00 00 00 06 |.......RPLE.....|
000df460 01 10 00 0a 00 03 6e 00 00 00 52 50 4c 45 0a 00 |......n...RPLE..|
000df470 00 00 06 01 0f 00 0b 00 03 ff 00 00 00 52 50 4c |.............RPL|
000df480 45 0a 00 00 00 06 01 10 00 0c 00 00 ff 00 00 00 |E...............|
000df490 52 50 4c 45 0a 00 00 00 04 01 0f 00 09 00 00 6b |RPLE...........k|
000df4a0 50 fc 4d 61 6e 64 61 6c 67 6f 76 69 00 00 00 00 |P.Mandalgovi....|
000df4b0 00 50 45 45 52 18 00 00 00 00 00 00 00 00 00 00 |.PEER...........|
000df4c0 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 |................|
000df4d0 00 |.|