Hi Mark,
The savegame data is stored in multiple blocks, some compressed and some not.
This comment from my source code explains it quite well, I think:
Code:
/* This is the SPWaW/winSPWW2 savegame file format:
*
* A savegame is a contiguous set of several data blocks.
*
* The first data block is the game info section.
* This is a fixed-size data block containing the savegame marker.
* (which is currently "SPWAW_SAVE_V101"/"SPCTS_SAVE_V100" for SPWaW/winSPWW2)
*
* The other data blocks contain the savegame section data.
*
* Each data block consists of:
* a data block header
* the section data.
*
* The fixed-size data block header describes the section data that follows:
* the identification number of the section
* the size of the section data
* a flag indicating if the section data is compressed or not
*
* Uncompressed section data can be loaded as-is.
*
* Compressed section data must be decompressed after loading.
* The actual size of the section data will be larger than the size of the section data in the file.
*/
/* This is the SPWaW/winSPWW2 section data compression format:
*
* Compressed section data is a contiguous set of run-length coded data blocks.
*
* There are two types of run-length coded data blocks:
* uncompressed run-length coded data (URLC)
* compressed run-length coded data (CRLC)
*
* Each run-length coded data block consists of:
* a run-length coding byte (RLB)
* one or more data bytes
*
* A compressed run-length coded data block is used to for sequences of identical data bytes:
* the RLB indicates the number of identical data bytes (N)
* the RLB is followed by a single data byte (B)
* the decompressed data is the sequence of N times the data byte B
*
* An uncompressed run-length coded data block is used for sequences of data bytes with mixed values:
* the RLB indicates the number of data bytes that follow (N)
* there is at least 1 and maximum 127 data bytes
* the N data bytes can be copied as-is
*/
The concrete block header layout for winSPWW2 is this:
Code:
#pragma pack(push, r1, 1)
typedef struct s_BLOCKHEAD_WINSPWW2 {
unsigned int section;
unsigned int size;
unsigned char flag;
} BLOCKHEAD_WINSPWW2;
#pragma pack(pop, r1)
If the 'flag' value is 0, the section data is NOT compressed.
If the 'flag' value is 1, the section data IS compressed.
Note: the two #pragma's you see are not part of the actual data layout, they are just hints to the compiler that it should respect the data layout as is and not insert additional padding between fields.
Hope this helps,
Erik