diff --git a/LibCmo/CKStateChunk.cpp b/LibCmo/CKStateChunk.cpp index 422ecd9..cf118b7 100644 --- a/LibCmo/CKStateChunk.cpp +++ b/LibCmo/CKStateChunk.cpp @@ -121,7 +121,7 @@ namespace LibCmo::CK2 { size_t CKStateChunk::GetCeilDwordSize(size_t char_size) { - return (char_size + 3) >> 3; + return (char_size + 3) >> 2; } bool CKStateChunk::ResizeBuffer(CKDWORD new_dwsize) { @@ -430,6 +430,22 @@ namespace LibCmo::CK2 { return true; } + /* ========== Complex Data Read Functions ==========*/ + + bool CKStateChunk::ReadObjectID(CK_ID* id) { + return false; + } + + bool CKStateChunk::ReadManagerInt(CKGUID* guid, CKINT* intval) { + return false; + } + + CKStateChunk* CKStateChunk::ReadSubChunk(void) { + return nullptr; + } + + /* ========== Buffer Functions ==========*/ + bool CKStateChunk::ReadNoSizeBuffer(CKDWORD size_in_byte, void* allocatedBuf) { if (allocatedBuf == nullptr) return false; return this->ReadByteData(allocatedBuf, size_in_byte); @@ -465,6 +481,23 @@ namespace LibCmo::CK2 { return true; } + /* ========== Sequence Functions ==========*/ + + bool CKStateChunk::ReadObjectIDSequence(std::vector* ls) { + return false; + } + + bool CKStateChunk::ReadManagerIntSequence(CKGUID* guid, std::vector* ls) { + return false; + } + + bool CKStateChunk::ReadSubChunkSequence(std::vector* ls) { + return false; + } + + bool CKStateChunk::ReadObjectArray(std::vector* ls) { + return false; + } #pragma endregion diff --git a/LibCmo/CKStateChunk.hpp b/LibCmo/CKStateChunk.hpp index 310adfe..a416ecb 100644 --- a/LibCmo/CKStateChunk.hpp +++ b/LibCmo/CKStateChunk.hpp @@ -135,18 +135,39 @@ namespace LibCmo::CK2 { return ReadString(&strl); } + /* ========== Complex Data Read Functions ==========*/ + + bool ReadObjectID(CK_ID* id); + inline bool ReadObjectID(CK_ID& id) { + return ReadObjectID(&id); + } + + bool ReadManagerInt(CKGUID* guid, CKINT* intval); + inline bool ReadManagerInt(CKGUID& guid, CKINT& intval) { + return ReadManagerInt(&guid, &intval); + } + + /// + /// Read sub chunk + /// Return nullptr if failed. + /// Returned CKStateChunk should be manually released! + /// + /// + /// + CKStateChunk* ReadSubChunk(void); + /* ========== Buffer Functions ==========*/ /* Buffer related function implements: - ReadBuffer(void**) Read Byte based size. - ReadAndFillBuffer(int, void*) User give Byte based size. - ReadAndFillBuffer(void*) Read Byte based size. - ReadAndFillBuffer_LEndian(int, void*) User give Byte based size. - ReadAndFillBuffer_LEndian(void*) Read Byte based size. - ReadAndFillBuffer_LEndian16(int, void*) User give Byte based size. - ReadAndFillBuffer_LEndian16(void*) Read Byte based size. + ReadBuffer(void**) Read Byte based size. -> ReadBuffer + ReadAndFillBuffer(int, void*) User give Byte based size. -> ReadNoSizeBuffer + ReadAndFillBuffer(void*) Read Byte based size. -> ReadBuffer + ReadAndFillBuffer_LEndian(int, void*) User give Byte based size. -> ReadNoSizeBuffer + ReadAndFillBuffer_LEndian(void*) Read Byte based size. -> ReadBuffer + ReadAndFillBuffer_LEndian16(int, void*) User give Byte based size. -> ReadNoSizeBuffer + ReadAndFillBuffer_LEndian16(void*) Read Byte based size. -> ReadBuffer */ /// @@ -171,6 +192,52 @@ namespace LibCmo::CK2 { /* ========== Sequence Functions ==========*/ + /// + /// Read Object ID Sequence + /// The combination using of StartReadSequence(), ReadObjectID(), and ReadObject() redirect to this. + /// + /// + /// + bool ReadObjectIDSequence(std::vector* ls); + inline bool ReadObjectIDSequence(std::vector& ls) { + return ReadObjectIDSequence(&ls); + } + + /// + /// Read Manager Sequence + /// The combination using of StartManagerReadSequence() and ReadManagerIntSequence() redirect to this. + /// + /// + /// + /// + bool ReadManagerIntSequence(CKGUID* guid, std::vector* ls); + inline bool ReadManagerIntSequence(CKGUID& guid, std::vector& ls) { + return ReadManagerIntSequence(&guid, &ls); + } + + /// + /// Read Sub Chunk Sequence + /// The combination using of StartReadSequence() and ReadSubChunk() redirect to this. + /// The item of returned CKStateChunk* list should be manually released! + /// + /// + /// + bool ReadSubChunkSequence(std::vector* ls); + inline bool ReadSubChunkSequence(std::vector& ls) { + return ReadSubChunkSequence(&ls); + } + + /// + /// Read Object Array (actually still is CK_ID) + /// ReadXObjectArray() and ReadObjectArray() redirect to this. + /// + /// + /// + bool ReadObjectArray(std::vector* ls); + inline bool ReadObjectArray(std::vector& ls) { + return ReadObjectArray(&ls); + } + //int ReadInt(); //int StartReadSequence(); //CK_ID ReadObjectID();