fix something

This commit is contained in:
2023-08-27 22:14:02 +08:00
parent 6837253a01
commit 8fce45b0b4
9 changed files with 211 additions and 118 deletions

View File

@ -78,6 +78,19 @@ namespace LibCmo::CK2 {
}
void CKContext::DestroyAllCKObjects() {
// free all created objects
for (auto& ptr : m_ObjectsList) {
if (ptr != nullptr) {
InternalDestroy(this, ptr);
}
}
// restore returned object list
m_ReturnedObjectIds.clear();
// empty object list
m_ObjectsList.clear();
}
#pragma endregion
#pragma region Ctor Dtor
@ -96,13 +109,7 @@ namespace LibCmo::CK2 {
}
CKContext::~CKContext() {
// free all created objects
for (auto& ptr : m_ObjectsList) {
if (ptr != nullptr) {
InternalDestroy(this, ptr);
}
}
DestroyAllCKObjects();
}
#pragma endregion

View File

@ -42,6 +42,7 @@ namespace LibCmo::CK2 {
CK_CREATIONMODE* res = nullptr);
ObjImpls::CKObject* GetCKObject(CK_ID id);
void DestroyCKObject(CK_ID id);
void DestroyAllCKObjects();
// ========== Object Access ==========

View File

@ -440,6 +440,39 @@ namespace LibCmo::CK2 {
return true;
}
XContainer::XArray<IdentifierProfile> CKStateChunk::GetIdentifierProfile() {
XContainer::XArray<IdentifierProfile> collection;
if (this->m_Parser.m_Status != CKStateChunkStatus::READ) return collection;
CKDWORD pos = 0u;
if (this->m_DataDwSize < 2u) return collection; // impossible to have a identifier
// iterate identifier
while (true) {
// add current identifier
CKDWORD nextptr = this->m_pData[pos + 1];
if (nextptr == 0u) {
nextptr = this->m_DataDwSize; // got tail. no more identifier
}
collection.emplace_back(IdentifierProfile{
this->m_pData[pos],
this->m_pData + pos + 2,
sizeof(CKDWORD) * (nextptr - pos - 2u)
});
// move to next identifier or exit
// got tail. no more identifier
if (this->m_pData[pos + 1] == 0u) break;
pos = this->m_pData[pos + 1];
// out of buffer
if (pos + 1 >= this->m_DataDwSize) break;
};
return collection;
}
/* ========== Basic Data Read Functions ==========*/
bool CKStateChunk::ReadByteData(void* data_ptr, CKDWORD size_in_byte) {

View File

@ -4,6 +4,12 @@
namespace LibCmo::CK2 {
struct IdentifierProfile {
CKDWORD m_Identifier;
void* m_DataPtr;
CKDWORD m_AreaSize;
};
class CKStateChunk {
public:
//CKStateChunk();
@ -89,6 +95,7 @@ namespace LibCmo::CK2 {
inline bool SeekIdentifierAndReturnSize(TEnum enum_v, CKDWORD* out_size) {
return SeekIdentifierDwordAndReturnSize(static_cast<CKDWORD>(enum_v), out_size);
}
XContainer::XArray<IdentifierProfile> GetIdentifierProfile();
/* ========== Basic Data Read Functions ==========*/