CKStateChunk Data Structure

NOTE:
"Fill Zero" mean that this field still is existed but you should fill zero for it.
"Skip" mean that this field is entirely not existed. You should not consider it anymore.

Buffer Format

This section will introduce the buffer format of CKStateChunk.
Buffer format is the real format of CKStateChunk stored in file.
CKStateChunk::ConvertFromBuffer and CKStateChunk::ConvertToBuffer can convert between CKStateChunk and its buffer format.

According to the value of CK_STATECHUNK_CHUNKVERSION, we split it into 3 different format.

The unit of m_DataDwSize is CKDWORD(uint32), not char(uint8).
The core data of CKStateChunk is aligned with 4 byte boundary. so this is the reason why the unit of m_DataDwSize is CKDWORD.
Every reading and writing of m_pData should notice this unit issue.

Very Old Format

uint16 m_DataVersion

The type of m_DataVersion is CK_STATECHUNK_DATAVERSION.

uint16 m_ChunkVersion

The type of m_ChunkVersion is CK_STATECHUNK_CHUNKVERSION.

uint32 m_ClassId

The type of m_ClassId is CK_CLASSID.

uint32 m_DataDwSize

The size of CKStateChunk core data.

uint32 m_ObjectListSize

The size of object list.

uint32 m_ChunkListSize

The size of chunk list

uint32[] m_pData

The core data. Its length is indicated by m_DataDwSize.

uint32[] m_ObjectList

The object list. Its length is indicated by m_ObjectListSize.

uint32[] m_ChunkList

The chunk list. Its length is indicated by m_ChunkListSize.

Old Format

uint32 m_ManagerListSize

The size of manager list

uint32[] m_ManagerList

The manager list. Its length is indicated by m_ManagerListSize.

New Format

uint8 m_DataVersion

The type of m_DataVersion is CK_STATECHUNK_DATAVERSION.

uint8 m_ClassId

The type of m_ClassId is CK_CLASSID.

uint8 m_ChunkVersion

The type of m_ChunkVersion is CK_STATECHUNK_CHUNKVERSION.

uint8 m_Options

The type of m_Options is CK_STATECHUNK_CHUNKOPTIONS.

uint32 m_DataDwSize

The size of CKStateChunk core data.

uint32[] m_pData

The core data. Its length is indicated by m_DataDwSize.

uint32 m_ObjectListSize uint32[] m_ObjectList

Enabled when m_Options has CHNK_OPTION_IDS. Skip if not have.

uint32 m_ChunkListSize uint32[] m_ChunkList

Enabled when m_Options has CHNK_OPTION_CHN. Skip if not have.

uint32 m_ManagerListSize uint32[] m_ManagerList

Enabled when m_Options has CHNK_OPTION_MAN. Skip if not have.

Core Data Format

This section introduce the format of CKStateChunk core data, the format of m_pData.
The core data is filled by various Identifiers following various data.
It is related to the function of CKStateChunk.

uint32 m_Identifier uint32 m_NextIdentifier uint32[] m_Payload

A single identifier area.
m_Identifier is the unique magic word of this identifier area for CKStateChunk locating this area.
m_NextIdentifier is a relative pointer. It point to the m_Identifier in next identifier area and is relative to the start of core data.
Thus, the size of each identifier area can be simply computed by the absolute diff to adjacent m_NextIdentifier (*m_pData[pos] - pos)
m_Payload is the data of this identifier area and can be read or written by various CKStateChunk read write functions.
The minimum block size of m_Payload is uint32. It mean that all data must be aligned to uint32 boundary when saving.

...

More identifier area as much as you like.

The last m_NextIdentifier should set to zero to indicate the end of the series of identifier area.

SubChunk Format

According to the value of CK_STATECHUNK_CHUNKVERSION, we split it into 3 different format.

Very Old Format

uint32 m_SubChunkSize

The sum of all following variables' size.

uint32 m_ClassId

The CK_CLASSID of sub chunk.

uint32 m_DataDwSize

The size of core data in sub chunk.

uint32 Blank

A blank. I don't know why

uint32[] m_pData

The core data. Its length is indicated by m_DataDwSize.

Old Format

uint16 m_DataVersion

The CK_STATECHUNK_DATAVERSION of sub chunk.

uint16 m_ChunkVersion

The CK_STATECHUNK_CHUNKVERSION of sub chunk.

uint32 m_ObjectListSize

The size of sub chunk object list.

uint32 m_ChunkListSize

The size of sub chunk chunk list

uint32[] m_ObjectList

The object list. Its length is indicated by m_ObjectListSize.

uint32[] m_ChunkList

The chunk list. Its length is indicated by m_ChunkListSize.

New Format

uint32 m_ManagerListSize

The size of sub chunk manager list

uint32[] m_ManagerList

The manager list. Its length is indicated by m_ManagerListSize.