From 91a37b5b7ee170bd2e6fa518a2ce3c86944f26bb Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 26 Aug 2023 14:23:33 +0800 Subject: [PATCH] add document as a memorandum --- Documents/CKStateChunk.css | 16 +++ Documents/CKStateChunk.html | 278 ++++++++++++++++++++++++++++++++++++ Documents/CKStateChunk.js | 39 +++++ LibCmo/CK2/CKStateChunk.cpp | 4 +- 4 files changed, 335 insertions(+), 2 deletions(-) create mode 100644 Documents/CKStateChunk.css create mode 100644 Documents/CKStateChunk.html create mode 100644 Documents/CKStateChunk.js diff --git a/Documents/CKStateChunk.css b/Documents/CKStateChunk.css new file mode 100644 index 0000000..a35cdf6 --- /dev/null +++ b/Documents/CKStateChunk.css @@ -0,0 +1,16 @@ +body { + font-family: 'Times New Roman', Times, serif; +} + +td { + min-width: 15em; + text-align: left; + vertical-align: top; +} + +code { + font-family: 'Courier New', Courier, monospace; +} +pre { + font-family: 'Courier New', Courier, monospace; +} diff --git a/Documents/CKStateChunk.html b/Documents/CKStateChunk.html new file mode 100644 index 0000000..e5b0476 --- /dev/null +++ b/Documents/CKStateChunk.html @@ -0,0 +1,278 @@ + + + + + +

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_ObjectListSizeuint32[] m_ObjectList
+

Enabled when m_Options has CHNK_OPTION_IDS. Skip if not have.

+
+ + + + + +
uint32 m_ChunkListSizeuint32[] m_ChunkList
+

Enabled when m_Options has CHNK_OPTION_CHN. Skip if not have.

+
+ + + + + +
uint32 m_ManagerListSizeuint32[] 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_Identifieruint32 m_NextIdentifiervariable[] m_Payload
+

+ A single identifier area.
+ m_Identifier is the unique magic word of this identifier area for CKStateChunk locating this area.
+ m_NextIdentifier point to the m_Identifier in next identifier area.
+ m_Payload is the data of this identifier area and can be read or written by various CKStateChunk read write functions.
+ The size of each identifier area can be simply computed by the diff of m_NextIdentifier (*m_pData[pos] - pos) +

+
+
+
+ ... +

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.

+
+ + \ No newline at end of file diff --git a/Documents/CKStateChunk.js b/Documents/CKStateChunk.js new file mode 100644 index 0000000..59e96ea --- /dev/null +++ b/Documents/CKStateChunk.js @@ -0,0 +1,39 @@ + +function FixTableStyle() { + let tables = document.querySelectorAll("table"); + for (let index = 0; index < tables.length; index++) { + let singletable = tables[index]; + singletable.setAttribute("border", "1"); + singletable.setAttribute("cellspacing", "1"); + singletable.setAttribute("cellpadding", "10"); + } +} + +function TableCopyer() { + let phs = document.querySelectorAll(".ph"); + for (let index = 0; index < phs.length; index++) { + let ph = phs[index]; + let phparent = ph.parentNode; + + let phtarget = ph.getAttribute("target"); + if (phtarget === null) { + phparent.removeChild(ph); + continue; + } + + let target = document.querySelector("#" + phtarget); + if (target === null) { + phparent.removeChild(ph); + continue; + } + + let clonetarget = target.cloneNode(true); + clonetarget.removeAttribute("id"); + phparent.replaceChild(clonetarget, ph); + } +} + +window.onload=function() { + FixTableStyle(); + TableCopyer(); +}; \ No newline at end of file diff --git a/LibCmo/CK2/CKStateChunk.cpp b/LibCmo/CK2/CKStateChunk.cpp index 5771a44..040e14e 100644 --- a/LibCmo/CK2/CKStateChunk.cpp +++ b/LibCmo/CK2/CKStateChunk.cpp @@ -390,7 +390,7 @@ namespace LibCmo::CK2 { if (this->m_Parser.m_Status != CKStateChunkStatus::READ) return false; CKDWORD pos = 0u; - if (this->m_DataDwSize < 2) return false; // impossible to have a identifier + if (this->m_DataDwSize < 2u) return false; // impossible to have a identifier // search identifier while (this->m_pData[pos] != identifier) { @@ -409,7 +409,7 @@ namespace LibCmo::CK2 { // the last identifier, use chunk size instead nextptr = this->m_DataDwSize; } - *out_size = sizeof(CKDWORD) * (nextptr - pos); + *out_size = sizeof(CKDWORD) * (nextptr - pos - 2u); return true; }