diff --git a/LibCmo/VTReader.cpp b/LibCmo/VTReader.cpp index f131558..6436a8a 100644 --- a/LibCmo/VTReader.cpp +++ b/LibCmo/VTReader.cpp @@ -230,6 +230,7 @@ namespace LibCmo { CKERROR CKFile::ReadFileData(CKBufferParser** ParserPtr) { CKBufferParser* parser = *ParserPtr; + CKBufferParser* parserSrc = *ParserPtr; // ========== compress feature process ========== if (EnumHelper::FlagEnumHas(this->m_FileInfo.FileWriteMode, CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD) || @@ -243,6 +244,9 @@ namespace LibCmo { delete[] decomp_buffer; return CKERROR::CKERR_OUTOFMEMORY; } + + // sync to args + *ParserPtr = parser; } } @@ -396,6 +400,8 @@ namespace LibCmo { // move to next parser->MoveCursor(oldBufLen); } + + // MARK: remove a weird assign: parserSrc = v46; it seems useless. } } @@ -412,6 +418,39 @@ namespace LibCmo { } } + // ========== included file get ========== + // WARN: we use "parserSrc" to read, not "parser"!!! + for (size_t i = 0; i < this->m_IncludedFiles.size(); ++i) { + // get file name length and resize it + CKDWORD filenamelen = 0u; + parserSrc->Read(&filenamelen, sizeof(CKDWORD)); + std::string filename; + filename.resize(filenamelen); + + // read filename + if (filenamelen != 0) { + parserSrc->Read(filename.data(), filenamelen); + } + + // todo: construct temp folder path + // and regulate file name + + // read file body length + CKDWORD filebodylen = 0u; + parserSrc->Read(&filebodylen, sizeof(CKDWORD)); + + // todo: read file body + parserSrc->MoveCursor(filebodylen); + } + + // ========== free parser ========== + if (parserSrc != parser && parserSrc != nullptr) { + // WARN: we should free parserSrc! not free parser + // because "parser" has synced with ParserPtr and will be freed from outside. + delete parserSrc; + + } + return CKERROR::CKERR_OK; } @@ -431,9 +470,9 @@ namespace LibCmo { // MARK: i assume FinishLoading do not calling mapped file anymore // free file data - if (this->m_Parser != nullptr) { - delete this->m_Parser; - this->m_Parser = nullptr; + if (*ParserPtr != nullptr) { + delete *ParserPtr; + *ParserPtr = nullptr; } if (this->m_MappedFile != nullptr) { delete this->m_MappedFile; diff --git a/LibCmo/VTStateChunk.cpp b/LibCmo/VTStateChunk.cpp index ac5b094..a76c886 100644 --- a/LibCmo/VTStateChunk.cpp +++ b/LibCmo/VTStateChunk.cpp @@ -4,7 +4,7 @@ #include #endif -#include ; +#include #include "VTStruct.hpp" namespace LibCmo { @@ -190,10 +190,6 @@ namespace LibCmo { return 0u; } - bool CKStateChunk::SeekIdentifier(CKDWORD identifier) { - return false; - } - bool CKStateChunk::UnPack(CKDWORD DestSize) { // NOTE: in UnPack. pData store the compressed buffer, and // dwSize store the length of compressed buffer as CHAR size, not DWORD size! @@ -223,6 +219,18 @@ namespace LibCmo { return true; } + CKDWORD CKStateChunk::GetDataSize(void) { + return sizeof(CKDWORD) * this->m_DataDwSize; + } + + bool CKStateChunk::SeekIdentifier(CKDWORD identifier) { + return false; + } + + void CKStateChunk::ReadString(std::string& strl) { + ; + } + void LibCmo::CKStateChunk::_EnsureEnoughSpace(CKDWORD size) { ; } diff --git a/VirtoolsProbe/main.cpp b/VirtoolsProbe/main.cpp index afb609a..d56d4a3 100644 --- a/VirtoolsProbe/main.cpp +++ b/VirtoolsProbe/main.cpp @@ -41,14 +41,18 @@ int main() { CKContext* ctx = NULL; Assert(!CKCreateContext(&ctx, NULL, 0), "Fail to execute CKCreateContext()"); - // call saver + // call reader CKObjectArray* array = CreateCKObjectArray(); - CKObject* objs = ctx->CreateObject(CKCID_OBJECT, "fuck dassault", CK_OBJECTCREATION_NONAMECHECK, NULL); - array->AddIfNotHere(objs); + Assert(!ctx->Load("Language.old.nmo", array, CK_LOAD_DEFAULT, NULL), "Fail to load CMO file"); - CKDependencies* dep = CKGetDefaultClassDependencies(CK_DEPENDENCIES_SAVE); - dep->m_Flags = CK_DEPENDENCIES_FULL; - Assert(!ctx->Save("result.cmo", array, 0xFFFFFFFF, dep, NULL), "Fail to save CMO file"); + // call saver + //CKObjectArray* array = CreateCKObjectArray(); + //CKObject* objs = ctx->CreateObject(CKCID_OBJECT, "fuck dassault", CK_OBJECTCREATION_NONAMECHECK, NULL); + //array->AddIfNotHere(objs); + + //CKDependencies* dep = CKGetDefaultClassDependencies(CK_DEPENDENCIES_SAVE); + //dep->m_Flags = CK_DEPENDENCIES_FULL; + //Assert(!ctx->Save("result.cmo", array, 0xFFFFFFFF, dep, NULL), "Fail to save CMO file"); DeleteCKObjectArray(array); CKCloseContext(ctx);