From 230b18c0ba8e1c2acc33cdac2328bb20d8d3cd34 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 17 Sep 2023 10:38:46 +0800 Subject: [PATCH] remove all raw char type ref in code --- LibCmo/CK2/CKDefines.hpp | 2 +- LibCmo/CK2/CKFile.hpp | 40 ++++++++++++--------- LibCmo/CK2/CKFileReader.cpp | 40 ++++++++++----------- LibCmo/CK2/CKFileWriter.cpp | 34 +++++++++--------- LibCmo/CK2/CKGlobals.cpp | 4 +-- LibCmo/CK2/CKStateChunk.cpp | 24 ++++++------- LibCmo/CK2/CKStateChunk.hpp | 2 +- LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp | 12 +++---- LibCmo/CK2/MgrImpls/CKBaseManager.hpp | 8 ++--- LibCmo/CK2/ObjImpls/CKTexture.cpp | 2 +- LibCmo/VTUtils.hpp | 2 ++ LibCmo/VxMath/VxMath.cpp | 4 +-- LibCmo/VxMath/VxMemoryMappedFile.cpp | 2 +- LibCmo/VxMath/VxMemoryMappedFile.hpp | 2 +- Unvirt/StructFormatter.cpp | 18 +++++----- Unvirt/UnvirtContext.cpp | 2 +- Unvirt/UnvirtContext.hpp | 2 +- 17 files changed, 105 insertions(+), 95 deletions(-) diff --git a/LibCmo/CK2/CKDefines.hpp b/LibCmo/CK2/CKDefines.hpp index 7a1349e..5892e45 100644 --- a/LibCmo/CK2/CKDefines.hpp +++ b/LibCmo/CK2/CKDefines.hpp @@ -50,7 +50,7 @@ namespace LibCmo::CK2 { /** * @brief The identifier of Virtools file. */ - constexpr const char CKNEMOFI[] = "Nemo Fi"; + constexpr const CKCHAR CKNEMOFI[] = "Nemo Fi"; /** * @brief Current Version of CK Engine (Day/Month/Year) */ diff --git a/LibCmo/CK2/CKFile.hpp b/LibCmo/CK2/CKFile.hpp index 674c3ac..4e35d33 100644 --- a/LibCmo/CK2/CKFile.hpp +++ b/LibCmo/CK2/CKFile.hpp @@ -11,10 +11,10 @@ namespace LibCmo::CK2 { class CKBufferParser { private: - char* m_MemBegin; - size_t m_MemPos; + CKBYTE* m_MemBegin; + CKDWORD m_MemPos; bool m_NeedManualFree; - size_t m_MemSize; + CKDWORD m_MemSize; public: /** @@ -23,8 +23,8 @@ namespace LibCmo::CK2 { * @param rsize The size of buffer. * @param need_manual_free True if provided buffer need freed by CKBufferParser automatically. */ - CKBufferParser(const void* ptr, size_t rsize, bool need_manual_free) : - m_MemBegin(const_cast(static_cast(ptr))), + CKBufferParser(const void* ptr, CKDWORD rsize, bool need_manual_free) : + m_MemBegin(const_cast(static_cast(ptr))), m_MemPos(0u), m_MemSize(rsize), m_NeedManualFree(need_manual_free) {} @@ -32,8 +32,8 @@ namespace LibCmo::CK2 { * @brief Create CKBufferParser from a new created buffer. * @param newsize The size of new buffer. */ - CKBufferParser(size_t newsize) : - m_MemBegin(new char[newsize]), + CKBufferParser(CKDWORD newsize) : + m_MemBegin(new CKBYTE[newsize]), m_MemPos(0u), m_MemSize(newsize), m_NeedManualFree(true) {} @@ -42,21 +42,29 @@ namespace LibCmo::CK2 { } LIBCMO_DISABLE_COPY_MOVE(CKBufferParser); - const void* GetPtr(ptrdiff_t extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } - void* GetMutablePtr(ptrdiff_t extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } - void Read(void* data, size_t data_size) { + const void* GetPtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } + void* GetMutablePtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } + void* GetBase(void) { return this->m_MemBegin; } + CKDWORD GetSize(void) { return this->m_MemSize; } + CKDWORD GetCursor(void) { return this->m_MemPos; } + void MoveCursor(CKINT off) { this->m_MemPos += off; } + void SetCursor(CKDWORD off) { this->m_MemPos = off; } + void Read(void* data, CKDWORD data_size) { std::memcpy(data, (this->m_MemBegin + m_MemPos), data_size); this->m_MemPos += data_size; } - void Write(const void* data, size_t data_size) { + template + void Read(_Ty* data) { + Read(data, CKSizeof(_Ty)); + } + void Write(const void* data, CKDWORD data_size) { std::memcpy((this->m_MemBegin + m_MemPos), data, data_size); this->m_MemPos += data_size; } - void* GetBase(void) { return this->m_MemBegin; } - CKDWORD GetSize(void) { return static_cast(this->m_MemSize); } - CKDWORD GetCursor(void) { return static_cast(this->m_MemPos); } - void MoveCursor(ptrdiff_t off) { this->m_MemPos += off; } - void SetCursor(size_t off) { this->m_MemPos = off; } + template + void Write(const _Ty* data) { + Write(data, CKSizeof(_Ty)); + } }; #pragma pack(push) diff --git a/LibCmo/CK2/CKFileReader.cpp b/LibCmo/CK2/CKFileReader.cpp index cdc6b23..adc822e 100644 --- a/LibCmo/CK2/CKFileReader.cpp +++ b/LibCmo/CK2/CKFileReader.cpp @@ -50,7 +50,7 @@ namespace LibCmo::CK2 { if (std::memcmp(parser->GetPtr(), CKNEMOFI, sizeof(CKRawFileInfo::NeMo))) return CKERROR::CKERR_INVALIDFILE; // read header CKRawFileInfo rawHeader; - parser->Read(&rawHeader, sizeof(CKRawFileInfo)); + parser->Read(&rawHeader); // ========== header checker ========== // check zero flag? @@ -120,12 +120,12 @@ namespace LibCmo::CK2 { // read data for (auto& fileobj : this->m_FileObjects) { // read basic fields - parser->Read(&(fileobj.ObjectId), sizeof(CK_ID)); - parser->Read(&(fileobj.ObjectCid), sizeof(CK_CLASSID)); - parser->Read(&(fileobj.FileIndex), sizeof(CKDWORD)); + parser->Read(&fileobj.ObjectId); + parser->Read(&fileobj.ObjectCid); + parser->Read(&fileobj.FileIndex); CKDWORD namelen; - parser->Read(&namelen, sizeof(CKDWORD)); + parser->Read(&namelen); if (namelen != 0) { name_conv.resize(namelen); parser->Read(name_conv.data(), namelen); @@ -141,15 +141,15 @@ namespace LibCmo::CK2 { if (this->m_FileInfo.FileVersion >= 8) { // get size and resize CKDWORD depSize; - parser->Read(&depSize, sizeof(CKDWORD)); + parser->Read(&depSize); this->m_PluginsDep.resize(depSize); CKDWORD guid_size; for (auto& dep : this->m_PluginsDep) { // read category - parser->Read(&(dep.m_PluginCategory), sizeof(CK_PLUGIN_TYPE)); + parser->Read(&dep.m_PluginCategory); // get size and resize - parser->Read(&guid_size, sizeof(CKDWORD)); + parser->Read(&guid_size); dep.m_Guids.resize(guid_size); // read data if (guid_size != 0) { @@ -163,16 +163,16 @@ namespace LibCmo::CK2 { // file ver >= 8 have this feature if (this->m_FileInfo.FileVersion >= 8) { // MARK: i don't knwo what is this! - int32_t hasIncludedFile; - parser->Read(&hasIncludedFile, sizeof(int32_t)); + CKINT hasIncludedFile; + parser->Read(&hasIncludedFile); if (hasIncludedFile > 0) { // read included file size and resize CKDWORD includedFileCount; - parser->Read(&includedFileCount, sizeof(CKDWORD)); + parser->Read(&includedFileCount); this->m_IncludedFiles.resize(includedFileCount); - hasIncludedFile -= static_cast(sizeof(CKDWORD)); + hasIncludedFile -= static_cast(sizeof(CKDWORD)); } // MARK: backward pos @@ -225,9 +225,9 @@ namespace LibCmo::CK2 { // MARK: why read again? especially for file ver == 7. // get save id max - parser->Read(&this->m_SaveIDMax, sizeof(int32_t)); + parser->Read(&this->m_SaveIDMax); // get object count and resize - parser->Read(&this->m_FileInfo.ObjectCount, sizeof(CKDWORD)); + parser->Read(&this->m_FileInfo.ObjectCount); if (this->m_FileObjects.empty()) { this->m_FileObjects.resize(this->m_FileInfo.ObjectCount); } @@ -242,10 +242,10 @@ namespace LibCmo::CK2 { for (auto& mgr : this->m_ManagersData) { // read guid - parser->Read(&(mgr.Manager), sizeof(CKGUID)); + parser->Read(&mgr.Manager); // read statechunk len - parser->Read(&stateChunkLen, sizeof(CKDWORD)); + parser->Read(&stateChunkLen); // check len if (stateChunkLen == 0) { mgr.Data = nullptr; @@ -270,7 +270,7 @@ namespace LibCmo::CK2 { bool stateChkParseSuccess = false; for (auto& obj : this->m_FileObjects) { // get statechunk len - parser->Read(&obj.PackSize, sizeof(CKDWORD)); + parser->Read(&obj.PackSize); // check state chunk len if (obj.PackSize == 0) { obj.Data = nullptr; @@ -301,7 +301,7 @@ namespace LibCmo::CK2 { for (auto& file : this->m_IncludedFiles) { // get file name length and resize it CKDWORD filenamelen = 0u; - parser->Read(&filenamelen, sizeof(CKDWORD)); + parser->Read(&filenamelen); name_conv.resize(filenamelen); // read filename @@ -312,13 +312,13 @@ namespace LibCmo::CK2 { // read file body length CKDWORD filebodylen = 0u; - parser->Read(&filebodylen, sizeof(CKDWORD)); + parser->Read(&filebodylen); // read file body XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(file.c_str()); FILE* fp = EncodingHelper::U8FOpen(tempfilename.c_str(), "wb"); if (fp != nullptr) { - std::fwrite(parser->GetPtr(), sizeof(char), filebodylen, fp); + std::fwrite(parser->GetPtr(), sizeof(CKBYTE), filebodylen, fp); std::fclose(fp); } else { m_Ctx->OutputToConsoleEx("Fail to open temp file: %s", tempfilename.c_str()); diff --git a/LibCmo/CK2/CKFileWriter.cpp b/LibCmo/CK2/CKFileWriter.cpp index 98f2dce..3045a9b 100644 --- a/LibCmo/CK2/CKFileWriter.cpp +++ b/LibCmo/CK2/CKFileWriter.cpp @@ -126,7 +126,7 @@ namespace LibCmo::CK2 { + 2 * CKSizeof(CKDWORD); } - CKDWORD sumHdrIncludedFiles = CKSizeof(int32_t) + CKSizeof(CKDWORD); + CKDWORD sumHdrIncludedFiles = CKSizeof(CKINT) + CKSizeof(CKDWORD); // calc the whole size CKDWORD sumHdrSize = sumHdrObjSize + sumHdrPlgSize + sumHdrIncludedFiles; @@ -173,14 +173,14 @@ namespace LibCmo::CK2 { // todo: remove TOBEDELETED for referenced objects' m_ObjectFlags - hdrparser->Write(&obj.ObjectId, sizeof(CK_ID)); - hdrparser->Write(&obj.ObjectCid, sizeof(CK_CLASSID)); - hdrparser->Write(&obj.FileIndex, sizeof(CKDWORD)); + hdrparser->Write(&obj.ObjectId); + hdrparser->Write(&obj.ObjectCid); + hdrparser->Write(&obj.FileIndex); if (XContainer::NSXString::ToCKSTRING(obj.Name) != nullptr) { m_Ctx->GetNativeString(obj.Name, name_conv); CKDWORD namelen = static_cast(name_conv.size()); - hdrparser->Write(&namelen, sizeof(CKDWORD)); + hdrparser->Write(&namelen); hdrparser->Write(name_conv.data(), namelen); } } @@ -188,13 +188,13 @@ namespace LibCmo::CK2 { // write plugin dep { CKDWORD depsize = static_cast(m_PluginsDep.size()); - hdrparser->Write(&depsize, sizeof(CKDWORD)); + hdrparser->Write(&depsize); for (auto& dep : m_PluginsDep) { hdrparser->Write(&dep.m_PluginCategory, sizeof(CK_PLUGIN_TYPE)); CKDWORD guidsize = static_cast(dep.m_Guids.size()); - hdrparser->Write(&guidsize, sizeof(CKDWORD)); + hdrparser->Write(&guidsize); hdrparser->Write(dep.m_Guids.data(), sizeof(CKGUID) * guidsize); } @@ -203,10 +203,10 @@ namespace LibCmo::CK2 { // write included file { CKDWORD cache = CKSizeof(CKDWORD); - hdrparser->Write(&cache, sizeof(CKDWORD)); + hdrparser->Write(&cache); cache = static_cast(m_IncludedFiles.size()); - hdrparser->Write(&cache, sizeof(CKDWORD)); + hdrparser->Write(&cache); } // compress header if needed @@ -230,22 +230,22 @@ namespace LibCmo::CK2 { // write manager for (auto& mgr : m_ManagersData) { - datparser->Write(&mgr.Manager, sizeof(CKGUID)); + datparser->Write(&mgr.Manager); CKDWORD writtenSize = 0; if (mgr.Data != nullptr) { - writtenSize = mgr.Data->ConvertToBuffer(datparser->GetMutablePtr(sizeof(CKDWORD))); + writtenSize = mgr.Data->ConvertToBuffer(datparser->GetMutablePtr(CKSizeof(CKDWORD))); delete mgr.Data; mgr.Data = nullptr; } - datparser->Write(&writtenSize, sizeof(CKDWORD)); + datparser->Write(&writtenSize); datparser->MoveCursor(writtenSize); } // write object for (auto& obj : m_FileObjects) { - datparser->Write(&obj.PackSize, sizeof(CKDWORD)); + datparser->Write(&obj.PackSize); if (obj.Data != nullptr) { obj.Data->ConvertToBuffer(datparser->GetMutablePtr()); @@ -301,8 +301,8 @@ namespace LibCmo::CK2 { if (fs == nullptr) return CKERROR::CKERR_CANTWRITETOFILE; // write small header + header + data std::fwrite(&rawHeader, sizeof(CKRawFileInfo), 1, fs); - std::fwrite(hdrparser->GetBase(), sizeof(char), hdrparser->GetSize(), fs); - std::fwrite(datparser->GetBase(), sizeof(char), datparser->GetSize(), fs); + std::fwrite(hdrparser->GetBase(), sizeof(CKBYTE), hdrparser->GetSize(), fs); + std::fwrite(datparser->GetBase(), sizeof(CKBYTE), datparser->GetSize(), fs); // free buffer hdrparser.reset(); datparser.reset(); @@ -313,7 +313,7 @@ namespace LibCmo::CK2 { m_Ctx->GetNativeString(fentry, name_conv); CKDWORD filenamelen = static_cast(name_conv.size()); std::fwrite(&filenamelen, sizeof(CKDWORD), 1, fs); - std::fwrite(name_conv.data(), sizeof(char), filenamelen, fs); + std::fwrite(name_conv.data(), sizeof(CKBYTE), filenamelen, fs); // try mapping file. XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(fentry.c_str()); @@ -324,7 +324,7 @@ namespace LibCmo::CK2 { std::fwrite(&filebodylen, sizeof(CKDWORD), 1, fs); // write file body - std::fwrite(mappedFile->GetBase(), sizeof(char), filebodylen, fs); + std::fwrite(mappedFile->GetBase(), sizeof(CKBYTE), filebodylen, fs); } else { // write zero file length CKDWORD filebodylen = 0; diff --git a/LibCmo/CK2/CKGlobals.cpp b/LibCmo/CK2/CKGlobals.cpp index f13f015..5a34381 100644 --- a/LibCmo/CK2/CKGlobals.cpp +++ b/LibCmo/CK2/CKGlobals.cpp @@ -25,7 +25,7 @@ namespace LibCmo::CK2 { void* CKPackData(const void* Data, CKDWORD size, CKDWORD& NewSize, CKINT compressionlevel) { uLong boundary = compressBound(static_cast(size)); - char* DestBuffer = new char[boundary]; + CKBYTE* DestBuffer = new CKBYTE[boundary]; uLongf _destLen = static_cast(boundary); if (compress2( @@ -42,7 +42,7 @@ namespace LibCmo::CK2 { } void* CKUnPackData(CKDWORD DestSize, const void* SrcBuffer, CKDWORD SrcSize) { - char* DestBuffer = new char[DestSize]; + CKBYTE* DestBuffer = new CKBYTE[DestSize]; uLongf cache = DestSize; if (uncompress( diff --git a/LibCmo/CK2/CKStateChunk.cpp b/LibCmo/CK2/CKStateChunk.cpp index da5d490..d159185 100644 --- a/LibCmo/CK2/CKStateChunk.cpp +++ b/LibCmo/CK2/CKStateChunk.cpp @@ -261,11 +261,11 @@ namespace LibCmo::CK2 { // read chunk ver and data ver first // chunk ver always set in the 3rd BYTE in every format this->m_ChunkVersion = static_cast( - reinterpret_cast(buf)[2] + reinterpret_cast(buf)[2] ); // data ver always set in the 1st BYTE in every format this->m_DataVersion = static_cast( - reinterpret_cast(buf)[0] + reinterpret_cast(buf)[0] ); // switch according to chunk ver @@ -336,11 +336,11 @@ namespace LibCmo::CK2 { // re-read some extra data // class id located the 2nd BYTE this->m_ClassId = static_cast( - reinterpret_cast(buf)[1] + reinterpret_cast(buf)[1] ); // options located the 4th BYTE CK_STATECHUNK_CHUNKOPTIONS options = static_cast( - reinterpret_cast(buf)[3] + reinterpret_cast(buf)[3] ); // read normal data @@ -410,10 +410,10 @@ namespace LibCmo::CK2 { // if buffer provided, write it if (buf != nullptr) { // write header - reinterpret_cast(buf)[0] = static_cast(this->m_DataVersion); - reinterpret_cast(buf)[1] = static_cast(this->m_ClassId); - reinterpret_cast(buf)[2] = static_cast(this->m_ChunkVersion); - reinterpret_cast(buf)[3] = static_cast(options); + reinterpret_cast(buf)[0] = static_cast(this->m_DataVersion); + reinterpret_cast(buf)[1] = static_cast(this->m_ClassId); + reinterpret_cast(buf)[2] = static_cast(this->m_ChunkVersion); + reinterpret_cast(buf)[3] = static_cast(options); CKDWORD* dwbuf = reinterpret_cast(buf); // write buffer length @@ -454,7 +454,7 @@ namespace LibCmo::CK2 { // // dwSize store the length of compressed buffer as CHAR size, not DWORD size! // // create a enough buffer - // char* buffer = new char[DestSize]; + // CKBYTE* buffer = new CKBYTE[DestSize]; // uLongf destSize = DestSize; // // uncompress it // auto err = uncompress( @@ -776,7 +776,7 @@ namespace LibCmo::CK2 { } // create buffer - *buf = new char[bufByteSize]; + *buf = new CKBYTE[bufByteSize]; // read data if (!this->ReadByteData(*buf, bufByteSize)) { @@ -813,12 +813,12 @@ namespace LibCmo::CK2 { void CKStateChunk::BufferDeleter::operator()(void* buf) { if (buf == nullptr) return; - delete[] reinterpret_cast(buf); + delete[] reinterpret_cast(buf); } void CKStateChunk::DeleteBuffer(const void* buf) { if (buf == nullptr) return; - delete[] reinterpret_cast(buf); + delete[] reinterpret_cast(buf); } /* ========== Sequence Functions ==========*/ diff --git a/LibCmo/CK2/CKStateChunk.hpp b/LibCmo/CK2/CKStateChunk.hpp index fd809e3..d6bfe78 100644 --- a/LibCmo/CK2/CKStateChunk.hpp +++ b/LibCmo/CK2/CKStateChunk.hpp @@ -36,7 +36,7 @@ namespace LibCmo::CK2 { ~CKStateChunk(); private: - enum class CKStateChunkStatus : int32_t { + enum class CKStateChunkStatus : CKDWORD { IDLE, READ, WRITE diff --git a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp index ed99922..09d1b82 100644 --- a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp +++ b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp @@ -12,8 +12,8 @@ namespace LibCmo::CK2::DataHandlers { */ static void ABGRToARGB(CKDWORD count, const void* _abgr, void* _argb) { - const char* abgr = reinterpret_cast(_abgr); - char* argb = reinterpret_cast(_argb); + const CKBYTE* abgr = static_cast(_abgr); + CKBYTE* argb = static_cast(_argb); // copy R VxMath::VxCopyStructure( count, @@ -53,8 +53,8 @@ namespace LibCmo::CK2::DataHandlers { } static void ARGBToABGR(CKDWORD count, const void* _argb, void* _abgr) { - const char* argb = reinterpret_cast(_argb); - char* abgr = reinterpret_cast(_abgr); + const CKBYTE* argb = static_cast(_argb); + CKBYTE* abgr = static_cast(_abgr); // copy R VxMath::VxCopyStructure( count, @@ -147,7 +147,7 @@ namespace LibCmo::CK2::DataHandlers { static void FileWriteFunction(void* context, void* data, int size) { FileSaveContext* ctx = reinterpret_cast(context); if (ctx->m_Fs != nullptr) { - std::fwrite(data, sizeof(char), size, ctx->m_Fs); + std::fwrite(data, sizeof(CKBYTE), size, ctx->m_Fs); } ctx->m_Counter += size; } @@ -161,7 +161,7 @@ namespace LibCmo::CK2::DataHandlers { MemorySaveContext* ctx = reinterpret_cast(context); if (ctx->m_Mem != nullptr) { std::memcpy(ctx->m_Mem, data, size); - ctx->m_Mem = reinterpret_cast(ctx->m_Mem) + size; + ctx->m_Mem = static_cast(ctx->m_Mem) + size; } ctx->m_Counter += size; } diff --git a/LibCmo/CK2/MgrImpls/CKBaseManager.hpp b/LibCmo/CK2/MgrImpls/CKBaseManager.hpp index 686a334..1073d87 100644 --- a/LibCmo/CK2/MgrImpls/CKBaseManager.hpp +++ b/LibCmo/CK2/MgrImpls/CKBaseManager.hpp @@ -90,7 +90,7 @@ namespace LibCmo::CK2::MgrImpls { data for your manager. @see CKStateChunk, LoadData */ - virtual bool SaveData(CKStateChunk* chunk, CKFileVisitor* SavedFile) { + virtual bool SaveData(LIBCMO_UNUSED CKStateChunk* chunk, LIBCMO_UNUSED CKFileVisitor* SavedFile) { return false; // default value is false to indicate this manager do not need save any data. } /** @@ -102,7 +102,7 @@ namespace LibCmo::CK2::MgrImpls { + During a load operation, each manager is automatically called if there was a chunk saved in the file with SaveData. @see CKStateChunk, SaveData */ - virtual CKERROR LoadData(CKStateChunk* chunk, CKFileVisitor* LoadedFile) { + virtual CKERROR LoadData(LIBCMO_UNUSED CKStateChunk* chunk, LIBCMO_UNUSED CKFileVisitor* LoadedFile) { return CKERROR::CKERR_OK; } @@ -138,7 +138,7 @@ namespace LibCmo::CK2::MgrImpls { CKMANAGER_FUNC_OnSequenceToBeDeleted for this function to get called. @see Main Virtools Events, CKContext::DestroyObjects, SequenceDeleted */ - virtual CKERROR SequenceToBeDeleted(const CK_ID* objids, CKDWORD count) { return CKERROR::CKERR_OK; } + virtual CKERROR SequenceToBeDeleted(LIBCMO_UNUSED const CK_ID* objids, LIBCMO_UNUSED CKDWORD count) { return CKERROR::CKERR_OK; } /** @brief Called after objects have been deleted. @return CK_OK if successful or an error code otherwise. @@ -150,7 +150,7 @@ namespace LibCmo::CK2::MgrImpls { CKMANAGER_FUNC_OnSequenceDeleted for this function to get called. @see Main Virtools Events, CKContext::DestroyObjects, SequenceToBeDeleted */ - virtual CKERROR SequenceDeleted(const CK_ID* objids, CKDWORD count) { return CKERROR::CKERR_OK; } + virtual CKERROR SequenceDeleted(LIBCMO_UNUSED const CK_ID* objids, LIBCMO_UNUSED CKDWORD count) { return CKERROR::CKERR_OK; } protected: diff --git a/LibCmo/CK2/ObjImpls/CKTexture.cpp b/LibCmo/CK2/ObjImpls/CKTexture.cpp index c2b89bd..eee2acb 100644 --- a/LibCmo/CK2/ObjImpls/CKTexture.cpp +++ b/LibCmo/CK2/ObjImpls/CKTexture.cpp @@ -106,7 +106,7 @@ namespace LibCmo::CK2::ObjImpls { // MARK: I ignore 0x4 in there because it involve video. // set current slot, transparent color, and video format. - CKDWORD currentSlot, transColor, videoFmt; + CKDWORD currentSlot, transColor; fmtbytesize -= CKSizeof(CKDWORD); switch (fmtbytesize) { case (3 * sizeof(CKDWORD)): diff --git a/LibCmo/VTUtils.hpp b/LibCmo/VTUtils.hpp index 68c1bd9..41663ce 100644 --- a/LibCmo/VTUtils.hpp +++ b/LibCmo/VTUtils.hpp @@ -67,6 +67,8 @@ #pragma endregion +#define LIBCMO_UNUSED [[maybe_unused]] + namespace LibCmo { [[noreturn]] void LibPanic(int line, const char* file, const char* errmsg); diff --git a/LibCmo/VxMath/VxMath.cpp b/LibCmo/VxMath/VxMath.cpp index a22e9b9..07e99aa 100644 --- a/LibCmo/VxMath/VxMath.cpp +++ b/LibCmo/VxMath/VxMath.cpp @@ -12,8 +12,8 @@ namespace LibCmo::VxMath { void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride) { if (Dst == nullptr || Src == nullptr) return; - char* cdst = reinterpret_cast(Dst); - const char* csrc = reinterpret_cast(Src); + CKBYTE* cdst = static_cast(Dst); + const CKBYTE* csrc = static_cast(Src); for (CKDWORD i = 0; i < Count; ++i) { std::memcpy(cdst, csrc, SizeSrc); cdst += OutStride; diff --git a/LibCmo/VxMath/VxMemoryMappedFile.cpp b/LibCmo/VxMath/VxMemoryMappedFile.cpp index 50259db..361b1ce 100644 --- a/LibCmo/VxMath/VxMemoryMappedFile.cpp +++ b/LibCmo/VxMath/VxMemoryMappedFile.cpp @@ -3,7 +3,7 @@ namespace LibCmo::VxMath { - VxMemoryMappedFile::VxMemoryMappedFile(const char* u8_filepath) : + VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) : // init members #if defined(LIBCMO_OS_WIN32) m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL), diff --git a/LibCmo/VxMath/VxMemoryMappedFile.hpp b/LibCmo/VxMath/VxMemoryMappedFile.hpp index d02baeb..4d42ac5 100644 --- a/LibCmo/VxMath/VxMemoryMappedFile.hpp +++ b/LibCmo/VxMath/VxMemoryMappedFile.hpp @@ -40,7 +40,7 @@ namespace LibCmo::VxMath { size_t m_cbFile; bool m_bIsValid; public: - VxMemoryMappedFile(const char* u8_filepath); + VxMemoryMappedFile(CKSTRING u8_filepath); VxMemoryMappedFile(const VxMemoryMappedFile&) = delete; VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete; ~VxMemoryMappedFile(void); diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index 8324fd5..0a2bc9f 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -10,7 +10,7 @@ namespace Unvirt::StructFormatter { #define PRIuSIZET "zu" - static void PrintCKSTRING(LibCmo::CK2::CKSTRING name) { + static void PrintCKSTRING(LibCmo::CKSTRING name) { if (name == nullptr) { fputs(UNVIRT_TERMCOL_LIGHT_MAGENTA(("")), stdout); } else { @@ -70,7 +70,7 @@ namespace Unvirt::StructFormatter { (fileinfo.CKVersion >> 0) & 0xFFFF ); - LibCmo::CK2::CKDWORD product_series[4] { + LibCmo::CKDWORD product_series[4] { (fileinfo.ProductBuild >> 24) & 0xFF, (fileinfo.ProductBuild >> 16) & 0xFF, (fileinfo.ProductBuild >> 8) & 0xFF, @@ -136,7 +136,7 @@ namespace Unvirt::StructFormatter { fputc('\t', stdout); PrintPointer(obj.Data); fputc('\t', stdout); - PrintCKSTRING(obj.Name.toCKSTRING()); + PrintCKSTRING(LibCmo::XContainer::NSXString::ToCKSTRING(obj.Name)); fputc('\n', stdout); } ); @@ -201,12 +201,12 @@ namespace Unvirt::StructFormatter { fputc('\n', stdout); fprintf(stdout, "Version (Data / Chunk): %" PRIuCKDWORD " (%s) / %" PRIuCKDWORD " (%s)\n", - static_cast(profile.m_DataVersion), AccessibleValue::GetEnumName(profile.m_DataVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_DATAVERSION).c_str(), - static_cast(profile.m_ChunkVersion), AccessibleValue::GetEnumName(profile.m_ChunkVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_CHUNKVERSION).c_str()); + static_cast(profile.m_DataVersion), AccessibleValue::GetEnumName(profile.m_DataVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_DATAVERSION).c_str(), + static_cast(profile.m_ChunkVersion), AccessibleValue::GetEnumName(profile.m_ChunkVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_CHUNKVERSION).c_str()); fprintf(stdout, "List (Object / Chunk / Manager): %" PRIuCKDWORD " / %" PRIuCKDWORD " / %" PRIuCKDWORD "\n", - static_cast(profile.m_ObjectListSize), - static_cast(profile.m_ChunkListSize), - static_cast(profile.m_ManagerListSize)); + static_cast(profile.m_ObjectListSize), + static_cast(profile.m_ChunkListSize), + static_cast(profile.m_ManagerListSize)); fputs("Data: ", stdout); PrintPointer(profile.m_pData); @@ -231,7 +231,7 @@ namespace Unvirt::StructFormatter { PrintPointer(ident.m_DataPtr); fputc('\t', stdout); fprintf(stdout, "%" PRIuCKDWORD " (%" PRIuCKDWORD " DWORD + %" PRIuCKDWORD ")\n", - ident.m_AreaSize, ident.m_AreaSize / CKSizeof(LibCmo::CK2::CKDWORD), ident.m_AreaSize % CKSizeof(LibCmo::CK2::CKDWORD)); + ident.m_AreaSize, ident.m_AreaSize / CKSizeof(LibCmo::CKDWORD), ident.m_AreaSize % CKSizeof(LibCmo::CKDWORD)); } } diff --git a/Unvirt/UnvirtContext.cpp b/Unvirt/UnvirtContext.cpp index e1c64ad..00e18e1 100644 --- a/Unvirt/UnvirtContext.cpp +++ b/Unvirt/UnvirtContext.cpp @@ -173,7 +173,7 @@ namespace Unvirt::Context { m_Ctx->ClearAll(); } - void UnvirtContext::PrintContextMsg(LibCmo::CK2::CKSTRING msg) { + void UnvirtContext::PrintContextMsg(LibCmo::CKSTRING msg) { if (msg != nullptr) { fprintf(stdout, UNVIRT_TERMCOL_LIGHT_YELLOW(("[CKContext] ")) "%s\n", msg); } diff --git a/Unvirt/UnvirtContext.hpp b/Unvirt/UnvirtContext.hpp index 6f3da8d..e9f578b 100644 --- a/Unvirt/UnvirtContext.hpp +++ b/Unvirt/UnvirtContext.hpp @@ -44,7 +44,7 @@ namespace Unvirt::Context { protected: bool HasOpenedFile(); void ClearDocument(); - void PrintContextMsg(LibCmo::CK2::CKSTRING msg); + void PrintContextMsg(LibCmo::CKSTRING msg); CmdHelper::CommandRoot m_Root; CmdHelper::HelpDocument* m_Help;