remove all raw char type ref in code

This commit is contained in:
yyc12345 2023-09-17 10:38:46 +08:00
parent 23da6c9e3e
commit 230b18c0ba
17 changed files with 105 additions and 95 deletions

View File

@ -50,7 +50,7 @@ namespace LibCmo::CK2 {
/** /**
* @brief The identifier of Virtools file. * @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) * @brief Current Version of CK Engine (Day/Month/Year)
*/ */

View File

@ -11,10 +11,10 @@ namespace LibCmo::CK2 {
class CKBufferParser { class CKBufferParser {
private: private:
char* m_MemBegin; CKBYTE* m_MemBegin;
size_t m_MemPos; CKDWORD m_MemPos;
bool m_NeedManualFree; bool m_NeedManualFree;
size_t m_MemSize; CKDWORD m_MemSize;
public: public:
/** /**
@ -23,8 +23,8 @@ namespace LibCmo::CK2 {
* @param rsize The size of buffer. * @param rsize The size of buffer.
* @param need_manual_free True if provided buffer need freed by CKBufferParser automatically. * @param need_manual_free True if provided buffer need freed by CKBufferParser automatically.
*/ */
CKBufferParser(const void* ptr, size_t rsize, bool need_manual_free) : CKBufferParser(const void* ptr, CKDWORD rsize, bool need_manual_free) :
m_MemBegin(const_cast<char*>(static_cast<const char*>(ptr))), m_MemBegin(const_cast<CKBYTE*>(static_cast<const CKBYTE*>(ptr))),
m_MemPos(0u), m_MemSize(rsize), m_MemPos(0u), m_MemSize(rsize),
m_NeedManualFree(need_manual_free) m_NeedManualFree(need_manual_free)
{} {}
@ -32,8 +32,8 @@ namespace LibCmo::CK2 {
* @brief Create CKBufferParser from a new created buffer. * @brief Create CKBufferParser from a new created buffer.
* @param newsize The size of new buffer. * @param newsize The size of new buffer.
*/ */
CKBufferParser(size_t newsize) : CKBufferParser(CKDWORD newsize) :
m_MemBegin(new char[newsize]), m_MemBegin(new CKBYTE[newsize]),
m_MemPos(0u), m_MemSize(newsize), m_MemPos(0u), m_MemSize(newsize),
m_NeedManualFree(true) m_NeedManualFree(true)
{} {}
@ -42,21 +42,29 @@ namespace LibCmo::CK2 {
} }
LIBCMO_DISABLE_COPY_MOVE(CKBufferParser); LIBCMO_DISABLE_COPY_MOVE(CKBufferParser);
const void* GetPtr(ptrdiff_t extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } const void* GetPtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); }
void* GetMutablePtr(ptrdiff_t extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } void* GetMutablePtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); }
void Read(void* data, size_t data_size) { 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); std::memcpy(data, (this->m_MemBegin + m_MemPos), data_size);
this->m_MemPos += data_size; this->m_MemPos += data_size;
} }
void Write(const void* data, size_t data_size) { template<class _Ty>
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); std::memcpy((this->m_MemBegin + m_MemPos), data, data_size);
this->m_MemPos += data_size; this->m_MemPos += data_size;
} }
void* GetBase(void) { return this->m_MemBegin; } template<class _Ty>
CKDWORD GetSize(void) { return static_cast<CKDWORD>(this->m_MemSize); } void Write(const _Ty* data) {
CKDWORD GetCursor(void) { return static_cast<CKDWORD>(this->m_MemPos); } Write(data, CKSizeof(_Ty));
void MoveCursor(ptrdiff_t off) { this->m_MemPos += off; } }
void SetCursor(size_t off) { this->m_MemPos = off; }
}; };
#pragma pack(push) #pragma pack(push)

View File

@ -50,7 +50,7 @@ namespace LibCmo::CK2 {
if (std::memcmp(parser->GetPtr(), CKNEMOFI, sizeof(CKRawFileInfo::NeMo))) return CKERROR::CKERR_INVALIDFILE; if (std::memcmp(parser->GetPtr(), CKNEMOFI, sizeof(CKRawFileInfo::NeMo))) return CKERROR::CKERR_INVALIDFILE;
// read header // read header
CKRawFileInfo rawHeader; CKRawFileInfo rawHeader;
parser->Read(&rawHeader, sizeof(CKRawFileInfo)); parser->Read(&rawHeader);
// ========== header checker ========== // ========== header checker ==========
// check zero flag? // check zero flag?
@ -120,12 +120,12 @@ namespace LibCmo::CK2 {
// read data // read data
for (auto& fileobj : this->m_FileObjects) { for (auto& fileobj : this->m_FileObjects) {
// read basic fields // read basic fields
parser->Read(&(fileobj.ObjectId), sizeof(CK_ID)); parser->Read(&fileobj.ObjectId);
parser->Read(&(fileobj.ObjectCid), sizeof(CK_CLASSID)); parser->Read(&fileobj.ObjectCid);
parser->Read(&(fileobj.FileIndex), sizeof(CKDWORD)); parser->Read(&fileobj.FileIndex);
CKDWORD namelen; CKDWORD namelen;
parser->Read(&namelen, sizeof(CKDWORD)); parser->Read(&namelen);
if (namelen != 0) { if (namelen != 0) {
name_conv.resize(namelen); name_conv.resize(namelen);
parser->Read(name_conv.data(), namelen); parser->Read(name_conv.data(), namelen);
@ -141,15 +141,15 @@ namespace LibCmo::CK2 {
if (this->m_FileInfo.FileVersion >= 8) { if (this->m_FileInfo.FileVersion >= 8) {
// get size and resize // get size and resize
CKDWORD depSize; CKDWORD depSize;
parser->Read(&depSize, sizeof(CKDWORD)); parser->Read(&depSize);
this->m_PluginsDep.resize(depSize); this->m_PluginsDep.resize(depSize);
CKDWORD guid_size; CKDWORD guid_size;
for (auto& dep : this->m_PluginsDep) { for (auto& dep : this->m_PluginsDep) {
// read category // read category
parser->Read(&(dep.m_PluginCategory), sizeof(CK_PLUGIN_TYPE)); parser->Read(&dep.m_PluginCategory);
// get size and resize // get size and resize
parser->Read(&guid_size, sizeof(CKDWORD)); parser->Read(&guid_size);
dep.m_Guids.resize(guid_size); dep.m_Guids.resize(guid_size);
// read data // read data
if (guid_size != 0) { if (guid_size != 0) {
@ -163,16 +163,16 @@ namespace LibCmo::CK2 {
// file ver >= 8 have this feature // file ver >= 8 have this feature
if (this->m_FileInfo.FileVersion >= 8) { if (this->m_FileInfo.FileVersion >= 8) {
// MARK: i don't knwo what is this! // MARK: i don't knwo what is this!
int32_t hasIncludedFile; CKINT hasIncludedFile;
parser->Read(&hasIncludedFile, sizeof(int32_t)); parser->Read(&hasIncludedFile);
if (hasIncludedFile > 0) { if (hasIncludedFile > 0) {
// read included file size and resize // read included file size and resize
CKDWORD includedFileCount; CKDWORD includedFileCount;
parser->Read(&includedFileCount, sizeof(CKDWORD)); parser->Read(&includedFileCount);
this->m_IncludedFiles.resize(includedFileCount); this->m_IncludedFiles.resize(includedFileCount);
hasIncludedFile -= static_cast<int32_t>(sizeof(CKDWORD)); hasIncludedFile -= static_cast<CKINT>(sizeof(CKDWORD));
} }
// MARK: backward pos // MARK: backward pos
@ -225,9 +225,9 @@ namespace LibCmo::CK2 {
// MARK: why read again? especially for file ver == 7. // MARK: why read again? especially for file ver == 7.
// get save id max // get save id max
parser->Read(&this->m_SaveIDMax, sizeof(int32_t)); parser->Read(&this->m_SaveIDMax);
// get object count and resize // get object count and resize
parser->Read(&this->m_FileInfo.ObjectCount, sizeof(CKDWORD)); parser->Read(&this->m_FileInfo.ObjectCount);
if (this->m_FileObjects.empty()) { if (this->m_FileObjects.empty()) {
this->m_FileObjects.resize(this->m_FileInfo.ObjectCount); this->m_FileObjects.resize(this->m_FileInfo.ObjectCount);
} }
@ -242,10 +242,10 @@ namespace LibCmo::CK2 {
for (auto& mgr : this->m_ManagersData) { for (auto& mgr : this->m_ManagersData) {
// read guid // read guid
parser->Read(&(mgr.Manager), sizeof(CKGUID)); parser->Read(&mgr.Manager);
// read statechunk len // read statechunk len
parser->Read(&stateChunkLen, sizeof(CKDWORD)); parser->Read(&stateChunkLen);
// check len // check len
if (stateChunkLen == 0) { if (stateChunkLen == 0) {
mgr.Data = nullptr; mgr.Data = nullptr;
@ -270,7 +270,7 @@ namespace LibCmo::CK2 {
bool stateChkParseSuccess = false; bool stateChkParseSuccess = false;
for (auto& obj : this->m_FileObjects) { for (auto& obj : this->m_FileObjects) {
// get statechunk len // get statechunk len
parser->Read(&obj.PackSize, sizeof(CKDWORD)); parser->Read(&obj.PackSize);
// check state chunk len // check state chunk len
if (obj.PackSize == 0) { if (obj.PackSize == 0) {
obj.Data = nullptr; obj.Data = nullptr;
@ -301,7 +301,7 @@ namespace LibCmo::CK2 {
for (auto& file : this->m_IncludedFiles) { for (auto& file : this->m_IncludedFiles) {
// get file name length and resize it // get file name length and resize it
CKDWORD filenamelen = 0u; CKDWORD filenamelen = 0u;
parser->Read(&filenamelen, sizeof(CKDWORD)); parser->Read(&filenamelen);
name_conv.resize(filenamelen); name_conv.resize(filenamelen);
// read filename // read filename
@ -312,13 +312,13 @@ namespace LibCmo::CK2 {
// read file body length // read file body length
CKDWORD filebodylen = 0u; CKDWORD filebodylen = 0u;
parser->Read(&filebodylen, sizeof(CKDWORD)); parser->Read(&filebodylen);
// read file body // read file body
XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(file.c_str()); XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(file.c_str());
FILE* fp = EncodingHelper::U8FOpen(tempfilename.c_str(), "wb"); FILE* fp = EncodingHelper::U8FOpen(tempfilename.c_str(), "wb");
if (fp != nullptr) { if (fp != nullptr) {
std::fwrite(parser->GetPtr(), sizeof(char), filebodylen, fp); std::fwrite(parser->GetPtr(), sizeof(CKBYTE), filebodylen, fp);
std::fclose(fp); std::fclose(fp);
} else { } else {
m_Ctx->OutputToConsoleEx("Fail to open temp file: %s", tempfilename.c_str()); m_Ctx->OutputToConsoleEx("Fail to open temp file: %s", tempfilename.c_str());

View File

@ -126,7 +126,7 @@ namespace LibCmo::CK2 {
+ 2 * CKSizeof(CKDWORD); + 2 * CKSizeof(CKDWORD);
} }
CKDWORD sumHdrIncludedFiles = CKSizeof(int32_t) + CKSizeof(CKDWORD); CKDWORD sumHdrIncludedFiles = CKSizeof(CKINT) + CKSizeof(CKDWORD);
// calc the whole size // calc the whole size
CKDWORD sumHdrSize = sumHdrObjSize + sumHdrPlgSize + sumHdrIncludedFiles; CKDWORD sumHdrSize = sumHdrObjSize + sumHdrPlgSize + sumHdrIncludedFiles;
@ -173,14 +173,14 @@ namespace LibCmo::CK2 {
// todo: remove TOBEDELETED for referenced objects' m_ObjectFlags // todo: remove TOBEDELETED for referenced objects' m_ObjectFlags
hdrparser->Write(&obj.ObjectId, sizeof(CK_ID)); hdrparser->Write(&obj.ObjectId);
hdrparser->Write(&obj.ObjectCid, sizeof(CK_CLASSID)); hdrparser->Write(&obj.ObjectCid);
hdrparser->Write(&obj.FileIndex, sizeof(CKDWORD)); hdrparser->Write(&obj.FileIndex);
if (XContainer::NSXString::ToCKSTRING(obj.Name) != nullptr) { if (XContainer::NSXString::ToCKSTRING(obj.Name) != nullptr) {
m_Ctx->GetNativeString(obj.Name, name_conv); m_Ctx->GetNativeString(obj.Name, name_conv);
CKDWORD namelen = static_cast<CKDWORD>(name_conv.size()); CKDWORD namelen = static_cast<CKDWORD>(name_conv.size());
hdrparser->Write(&namelen, sizeof(CKDWORD)); hdrparser->Write(&namelen);
hdrparser->Write(name_conv.data(), namelen); hdrparser->Write(name_conv.data(), namelen);
} }
} }
@ -188,13 +188,13 @@ namespace LibCmo::CK2 {
// write plugin dep // write plugin dep
{ {
CKDWORD depsize = static_cast<CKDWORD>(m_PluginsDep.size()); CKDWORD depsize = static_cast<CKDWORD>(m_PluginsDep.size());
hdrparser->Write(&depsize, sizeof(CKDWORD)); hdrparser->Write(&depsize);
for (auto& dep : m_PluginsDep) { for (auto& dep : m_PluginsDep) {
hdrparser->Write(&dep.m_PluginCategory, sizeof(CK_PLUGIN_TYPE)); hdrparser->Write(&dep.m_PluginCategory, sizeof(CK_PLUGIN_TYPE));
CKDWORD guidsize = static_cast<CKDWORD>(dep.m_Guids.size()); CKDWORD guidsize = static_cast<CKDWORD>(dep.m_Guids.size());
hdrparser->Write(&guidsize, sizeof(CKDWORD)); hdrparser->Write(&guidsize);
hdrparser->Write(dep.m_Guids.data(), sizeof(CKGUID) * guidsize); hdrparser->Write(dep.m_Guids.data(), sizeof(CKGUID) * guidsize);
} }
@ -203,10 +203,10 @@ namespace LibCmo::CK2 {
// write included file // write included file
{ {
CKDWORD cache = CKSizeof(CKDWORD); CKDWORD cache = CKSizeof(CKDWORD);
hdrparser->Write(&cache, sizeof(CKDWORD)); hdrparser->Write(&cache);
cache = static_cast<CKDWORD>(m_IncludedFiles.size()); cache = static_cast<CKDWORD>(m_IncludedFiles.size());
hdrparser->Write(&cache, sizeof(CKDWORD)); hdrparser->Write(&cache);
} }
// compress header if needed // compress header if needed
@ -230,22 +230,22 @@ namespace LibCmo::CK2 {
// write manager // write manager
for (auto& mgr : m_ManagersData) { for (auto& mgr : m_ManagersData) {
datparser->Write(&mgr.Manager, sizeof(CKGUID)); datparser->Write(&mgr.Manager);
CKDWORD writtenSize = 0; CKDWORD writtenSize = 0;
if (mgr.Data != nullptr) { if (mgr.Data != nullptr) {
writtenSize = mgr.Data->ConvertToBuffer(datparser->GetMutablePtr(sizeof(CKDWORD))); writtenSize = mgr.Data->ConvertToBuffer(datparser->GetMutablePtr(CKSizeof(CKDWORD)));
delete mgr.Data; delete mgr.Data;
mgr.Data = nullptr; mgr.Data = nullptr;
} }
datparser->Write(&writtenSize, sizeof(CKDWORD)); datparser->Write(&writtenSize);
datparser->MoveCursor(writtenSize); datparser->MoveCursor(writtenSize);
} }
// write object // write object
for (auto& obj : m_FileObjects) { for (auto& obj : m_FileObjects) {
datparser->Write(&obj.PackSize, sizeof(CKDWORD)); datparser->Write(&obj.PackSize);
if (obj.Data != nullptr) { if (obj.Data != nullptr) {
obj.Data->ConvertToBuffer(datparser->GetMutablePtr()); obj.Data->ConvertToBuffer(datparser->GetMutablePtr());
@ -301,8 +301,8 @@ namespace LibCmo::CK2 {
if (fs == nullptr) return CKERROR::CKERR_CANTWRITETOFILE; if (fs == nullptr) return CKERROR::CKERR_CANTWRITETOFILE;
// write small header + header + data // write small header + header + data
std::fwrite(&rawHeader, sizeof(CKRawFileInfo), 1, fs); std::fwrite(&rawHeader, sizeof(CKRawFileInfo), 1, fs);
std::fwrite(hdrparser->GetBase(), sizeof(char), hdrparser->GetSize(), fs); std::fwrite(hdrparser->GetBase(), sizeof(CKBYTE), hdrparser->GetSize(), fs);
std::fwrite(datparser->GetBase(), sizeof(char), datparser->GetSize(), fs); std::fwrite(datparser->GetBase(), sizeof(CKBYTE), datparser->GetSize(), fs);
// free buffer // free buffer
hdrparser.reset(); hdrparser.reset();
datparser.reset(); datparser.reset();
@ -313,7 +313,7 @@ namespace LibCmo::CK2 {
m_Ctx->GetNativeString(fentry, name_conv); m_Ctx->GetNativeString(fentry, name_conv);
CKDWORD filenamelen = static_cast<CKDWORD>(name_conv.size()); CKDWORD filenamelen = static_cast<CKDWORD>(name_conv.size());
std::fwrite(&filenamelen, sizeof(CKDWORD), 1, fs); 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. // try mapping file.
XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(fentry.c_str()); XContainer::XString tempfilename = m_Ctx->GetPathManager()->GetTempFilePath(fentry.c_str());
@ -324,7 +324,7 @@ namespace LibCmo::CK2 {
std::fwrite(&filebodylen, sizeof(CKDWORD), 1, fs); std::fwrite(&filebodylen, sizeof(CKDWORD), 1, fs);
// write file body // write file body
std::fwrite(mappedFile->GetBase(), sizeof(char), filebodylen, fs); std::fwrite(mappedFile->GetBase(), sizeof(CKBYTE), filebodylen, fs);
} else { } else {
// write zero file length // write zero file length
CKDWORD filebodylen = 0; CKDWORD filebodylen = 0;

View File

@ -25,7 +25,7 @@ namespace LibCmo::CK2 {
void* CKPackData(const void* Data, CKDWORD size, CKDWORD& NewSize, CKINT compressionlevel) { void* CKPackData(const void* Data, CKDWORD size, CKDWORD& NewSize, CKINT compressionlevel) {
uLong boundary = compressBound(static_cast<uLong>(size)); uLong boundary = compressBound(static_cast<uLong>(size));
char* DestBuffer = new char[boundary]; CKBYTE* DestBuffer = new CKBYTE[boundary];
uLongf _destLen = static_cast<uLongf>(boundary); uLongf _destLen = static_cast<uLongf>(boundary);
if (compress2( if (compress2(
@ -42,7 +42,7 @@ namespace LibCmo::CK2 {
} }
void* CKUnPackData(CKDWORD DestSize, const void* SrcBuffer, CKDWORD SrcSize) { void* CKUnPackData(CKDWORD DestSize, const void* SrcBuffer, CKDWORD SrcSize) {
char* DestBuffer = new char[DestSize]; CKBYTE* DestBuffer = new CKBYTE[DestSize];
uLongf cache = DestSize; uLongf cache = DestSize;
if (uncompress( if (uncompress(

View File

@ -261,11 +261,11 @@ namespace LibCmo::CK2 {
// read chunk ver and data ver first // read chunk ver and data ver first
// chunk ver always set in the 3rd BYTE in every format // chunk ver always set in the 3rd BYTE in every format
this->m_ChunkVersion = static_cast<CK_STATECHUNK_CHUNKVERSION>( this->m_ChunkVersion = static_cast<CK_STATECHUNK_CHUNKVERSION>(
reinterpret_cast<const char*>(buf)[2] reinterpret_cast<const CKBYTE*>(buf)[2]
); );
// data ver always set in the 1st BYTE in every format // data ver always set in the 1st BYTE in every format
this->m_DataVersion = static_cast<CK_STATECHUNK_DATAVERSION>( this->m_DataVersion = static_cast<CK_STATECHUNK_DATAVERSION>(
reinterpret_cast<const char*>(buf)[0] reinterpret_cast<const CKBYTE*>(buf)[0]
); );
// switch according to chunk ver // switch according to chunk ver
@ -336,11 +336,11 @@ namespace LibCmo::CK2 {
// re-read some extra data // re-read some extra data
// class id located the 2nd BYTE // class id located the 2nd BYTE
this->m_ClassId = static_cast<CK_CLASSID>( this->m_ClassId = static_cast<CK_CLASSID>(
reinterpret_cast<const char*>(buf)[1] reinterpret_cast<const CKBYTE*>(buf)[1]
); );
// options located the 4th BYTE // options located the 4th BYTE
CK_STATECHUNK_CHUNKOPTIONS options = static_cast<CK_STATECHUNK_CHUNKOPTIONS>( CK_STATECHUNK_CHUNKOPTIONS options = static_cast<CK_STATECHUNK_CHUNKOPTIONS>(
reinterpret_cast<const char*>(buf)[3] reinterpret_cast<const CKBYTE*>(buf)[3]
); );
// read normal data // read normal data
@ -410,10 +410,10 @@ namespace LibCmo::CK2 {
// if buffer provided, write it // if buffer provided, write it
if (buf != nullptr) { if (buf != nullptr) {
// write header // write header
reinterpret_cast<char*>(buf)[0] = static_cast<char>(this->m_DataVersion); reinterpret_cast<CKBYTE*>(buf)[0] = static_cast<CKBYTE>(this->m_DataVersion);
reinterpret_cast<char*>(buf)[1] = static_cast<char>(this->m_ClassId); reinterpret_cast<CKBYTE*>(buf)[1] = static_cast<CKBYTE>(this->m_ClassId);
reinterpret_cast<char*>(buf)[2] = static_cast<char>(this->m_ChunkVersion); reinterpret_cast<CKBYTE*>(buf)[2] = static_cast<CKBYTE>(this->m_ChunkVersion);
reinterpret_cast<char*>(buf)[3] = static_cast<char>(options); reinterpret_cast<CKBYTE*>(buf)[3] = static_cast<CKBYTE>(options);
CKDWORD* dwbuf = reinterpret_cast<CKDWORD*>(buf); CKDWORD* dwbuf = reinterpret_cast<CKDWORD*>(buf);
// write buffer length // write buffer length
@ -454,7 +454,7 @@ namespace LibCmo::CK2 {
// // dwSize store the length of compressed buffer as CHAR size, not DWORD size! // // dwSize store the length of compressed buffer as CHAR size, not DWORD size!
// // create a enough buffer // // create a enough buffer
// char* buffer = new char[DestSize]; // CKBYTE* buffer = new CKBYTE[DestSize];
// uLongf destSize = DestSize; // uLongf destSize = DestSize;
// // uncompress it // // uncompress it
// auto err = uncompress( // auto err = uncompress(
@ -776,7 +776,7 @@ namespace LibCmo::CK2 {
} }
// create buffer // create buffer
*buf = new char[bufByteSize]; *buf = new CKBYTE[bufByteSize];
// read data // read data
if (!this->ReadByteData(*buf, bufByteSize)) { if (!this->ReadByteData(*buf, bufByteSize)) {
@ -813,12 +813,12 @@ namespace LibCmo::CK2 {
void CKStateChunk::BufferDeleter::operator()(void* buf) { void CKStateChunk::BufferDeleter::operator()(void* buf) {
if (buf == nullptr) return; if (buf == nullptr) return;
delete[] reinterpret_cast<const char*>(buf); delete[] reinterpret_cast<const CKBYTE*>(buf);
} }
void CKStateChunk::DeleteBuffer(const void* buf) { void CKStateChunk::DeleteBuffer(const void* buf) {
if (buf == nullptr) return; if (buf == nullptr) return;
delete[] reinterpret_cast<const char*>(buf); delete[] reinterpret_cast<const CKBYTE*>(buf);
} }
/* ========== Sequence Functions ==========*/ /* ========== Sequence Functions ==========*/

View File

@ -36,7 +36,7 @@ namespace LibCmo::CK2 {
~CKStateChunk(); ~CKStateChunk();
private: private:
enum class CKStateChunkStatus : int32_t { enum class CKStateChunkStatus : CKDWORD {
IDLE, IDLE,
READ, READ,
WRITE WRITE

View File

@ -12,8 +12,8 @@ namespace LibCmo::CK2::DataHandlers {
*/ */
static void ABGRToARGB(CKDWORD count, const void* _abgr, void* _argb) { static void ABGRToARGB(CKDWORD count, const void* _abgr, void* _argb) {
const char* abgr = reinterpret_cast<const char*>(_abgr); const CKBYTE* abgr = static_cast<const CKBYTE*>(_abgr);
char* argb = reinterpret_cast<char*>(_argb); CKBYTE* argb = static_cast<CKBYTE*>(_argb);
// copy R // copy R
VxMath::VxCopyStructure( VxMath::VxCopyStructure(
count, count,
@ -53,8 +53,8 @@ namespace LibCmo::CK2::DataHandlers {
} }
static void ARGBToABGR(CKDWORD count, const void* _argb, void* _abgr) { static void ARGBToABGR(CKDWORD count, const void* _argb, void* _abgr) {
const char* argb = reinterpret_cast<const char*>(_argb); const CKBYTE* argb = static_cast<const CKBYTE*>(_argb);
char* abgr = reinterpret_cast<char*>(_abgr); CKBYTE* abgr = static_cast<CKBYTE*>(_abgr);
// copy R // copy R
VxMath::VxCopyStructure( VxMath::VxCopyStructure(
count, count,
@ -147,7 +147,7 @@ namespace LibCmo::CK2::DataHandlers {
static void FileWriteFunction(void* context, void* data, int size) { static void FileWriteFunction(void* context, void* data, int size) {
FileSaveContext* ctx = reinterpret_cast<FileSaveContext*>(context); FileSaveContext* ctx = reinterpret_cast<FileSaveContext*>(context);
if (ctx->m_Fs != nullptr) { 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; ctx->m_Counter += size;
} }
@ -161,7 +161,7 @@ namespace LibCmo::CK2::DataHandlers {
MemorySaveContext* ctx = reinterpret_cast<MemorySaveContext*>(context); MemorySaveContext* ctx = reinterpret_cast<MemorySaveContext*>(context);
if (ctx->m_Mem != nullptr) { if (ctx->m_Mem != nullptr) {
std::memcpy(ctx->m_Mem, data, size); std::memcpy(ctx->m_Mem, data, size);
ctx->m_Mem = reinterpret_cast<char*>(ctx->m_Mem) + size; ctx->m_Mem = static_cast<CKBYTE*>(ctx->m_Mem) + size;
} }
ctx->m_Counter += size; ctx->m_Counter += size;
} }

View File

@ -90,7 +90,7 @@ namespace LibCmo::CK2::MgrImpls {
data for your manager. data for your manager.
@see CKStateChunk, LoadData @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. 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. + During a load operation, each manager is automatically called if there was a chunk saved in the file with SaveData.
@see CKStateChunk, 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; return CKERROR::CKERR_OK;
} }
@ -138,7 +138,7 @@ namespace LibCmo::CK2::MgrImpls {
CKMANAGER_FUNC_OnSequenceToBeDeleted for this function to get called. CKMANAGER_FUNC_OnSequenceToBeDeleted for this function to get called.
@see Main Virtools Events, CKContext::DestroyObjects, SequenceDeleted @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. @brief Called after objects have been deleted.
@return CK_OK if successful or an error code otherwise. @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. CKMANAGER_FUNC_OnSequenceDeleted for this function to get called.
@see Main Virtools Events, CKContext::DestroyObjects, SequenceToBeDeleted @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: protected:

View File

@ -106,7 +106,7 @@ namespace LibCmo::CK2::ObjImpls {
// MARK: I ignore 0x4 in there because it involve video. // MARK: I ignore 0x4 in there because it involve video.
// set current slot, transparent color, and video format. // set current slot, transparent color, and video format.
CKDWORD currentSlot, transColor, videoFmt; CKDWORD currentSlot, transColor;
fmtbytesize -= CKSizeof(CKDWORD); fmtbytesize -= CKSizeof(CKDWORD);
switch (fmtbytesize) { switch (fmtbytesize) {
case (3 * sizeof(CKDWORD)): case (3 * sizeof(CKDWORD)):

View File

@ -67,6 +67,8 @@
#pragma endregion #pragma endregion
#define LIBCMO_UNUSED [[maybe_unused]]
namespace LibCmo { namespace LibCmo {
[[noreturn]] void LibPanic(int line, const char* file, const char* errmsg); [[noreturn]] void LibPanic(int line, const char* file, const char* errmsg);

View File

@ -12,8 +12,8 @@ namespace LibCmo::VxMath {
void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride) { void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride) {
if (Dst == nullptr || Src == nullptr) return; if (Dst == nullptr || Src == nullptr) return;
char* cdst = reinterpret_cast<char*>(Dst); CKBYTE* cdst = static_cast<CKBYTE*>(Dst);
const char* csrc = reinterpret_cast<const char*>(Src); const CKBYTE* csrc = static_cast<const CKBYTE*>(Src);
for (CKDWORD i = 0; i < Count; ++i) { for (CKDWORD i = 0; i < Count; ++i) {
std::memcpy(cdst, csrc, SizeSrc); std::memcpy(cdst, csrc, SizeSrc);
cdst += OutStride; cdst += OutStride;

View File

@ -3,7 +3,7 @@
namespace LibCmo::VxMath { namespace LibCmo::VxMath {
VxMemoryMappedFile::VxMemoryMappedFile(const char* u8_filepath) : VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) :
// init members // init members
#if defined(LIBCMO_OS_WIN32) #if defined(LIBCMO_OS_WIN32)
m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL), m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL),

View File

@ -40,7 +40,7 @@ namespace LibCmo::VxMath {
size_t m_cbFile; size_t m_cbFile;
bool m_bIsValid; bool m_bIsValid;
public: public:
VxMemoryMappedFile(const char* u8_filepath); VxMemoryMappedFile(CKSTRING u8_filepath);
VxMemoryMappedFile(const VxMemoryMappedFile&) = delete; VxMemoryMappedFile(const VxMemoryMappedFile&) = delete;
VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete; VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete;
~VxMemoryMappedFile(void); ~VxMemoryMappedFile(void);

View File

@ -10,7 +10,7 @@ namespace Unvirt::StructFormatter {
#define PRIuSIZET "zu" #define PRIuSIZET "zu"
static void PrintCKSTRING(LibCmo::CK2::CKSTRING name) { static void PrintCKSTRING(LibCmo::CKSTRING name) {
if (name == nullptr) { if (name == nullptr) {
fputs(UNVIRT_TERMCOL_LIGHT_MAGENTA(("<anonymous>")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_MAGENTA(("<anonymous>")), stdout);
} else { } else {
@ -70,7 +70,7 @@ namespace Unvirt::StructFormatter {
(fileinfo.CKVersion >> 0) & 0xFFFF (fileinfo.CKVersion >> 0) & 0xFFFF
); );
LibCmo::CK2::CKDWORD product_series[4] { LibCmo::CKDWORD product_series[4] {
(fileinfo.ProductBuild >> 24) & 0xFF, (fileinfo.ProductBuild >> 24) & 0xFF,
(fileinfo.ProductBuild >> 16) & 0xFF, (fileinfo.ProductBuild >> 16) & 0xFF,
(fileinfo.ProductBuild >> 8) & 0xFF, (fileinfo.ProductBuild >> 8) & 0xFF,
@ -136,7 +136,7 @@ namespace Unvirt::StructFormatter {
fputc('\t', stdout); fputc('\t', stdout);
PrintPointer(obj.Data); PrintPointer(obj.Data);
fputc('\t', stdout); fputc('\t', stdout);
PrintCKSTRING(obj.Name.toCKSTRING()); PrintCKSTRING(LibCmo::XContainer::NSXString::ToCKSTRING(obj.Name));
fputc('\n', stdout); fputc('\n', stdout);
} }
); );
@ -201,12 +201,12 @@ namespace Unvirt::StructFormatter {
fputc('\n', stdout); fputc('\n', stdout);
fprintf(stdout, "Version (Data / Chunk): %" PRIuCKDWORD " (%s) / %" PRIuCKDWORD " (%s)\n", fprintf(stdout, "Version (Data / Chunk): %" PRIuCKDWORD " (%s) / %" PRIuCKDWORD " (%s)\n",
static_cast<LibCmo::CK2::CKDWORD>(profile.m_DataVersion), AccessibleValue::GetEnumName(profile.m_DataVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_DATAVERSION).c_str(), static_cast<LibCmo::CKDWORD>(profile.m_DataVersion), AccessibleValue::GetEnumName(profile.m_DataVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_DATAVERSION).c_str(),
static_cast<LibCmo::CK2::CKDWORD>(profile.m_ChunkVersion), AccessibleValue::GetEnumName(profile.m_ChunkVersion, AccessibleValue::EnumDesc::CK_STATECHUNK_CHUNKVERSION).c_str()); static_cast<LibCmo::CKDWORD>(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", fprintf(stdout, "List (Object / Chunk / Manager): %" PRIuCKDWORD " / %" PRIuCKDWORD " / %" PRIuCKDWORD "\n",
static_cast<LibCmo::CK2::CKDWORD>(profile.m_ObjectListSize), static_cast<LibCmo::CKDWORD>(profile.m_ObjectListSize),
static_cast<LibCmo::CK2::CKDWORD>(profile.m_ChunkListSize), static_cast<LibCmo::CKDWORD>(profile.m_ChunkListSize),
static_cast<LibCmo::CK2::CKDWORD>(profile.m_ManagerListSize)); static_cast<LibCmo::CKDWORD>(profile.m_ManagerListSize));
fputs("Data: ", stdout); fputs("Data: ", stdout);
PrintPointer(profile.m_pData); PrintPointer(profile.m_pData);
@ -231,7 +231,7 @@ namespace Unvirt::StructFormatter {
PrintPointer(ident.m_DataPtr); PrintPointer(ident.m_DataPtr);
fputc('\t', stdout); fputc('\t', stdout);
fprintf(stdout, "%" PRIuCKDWORD " (%" PRIuCKDWORD " DWORD + %" PRIuCKDWORD ")\n", 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));
} }
} }

View File

@ -173,7 +173,7 @@ namespace Unvirt::Context {
m_Ctx->ClearAll(); m_Ctx->ClearAll();
} }
void UnvirtContext::PrintContextMsg(LibCmo::CK2::CKSTRING msg) { void UnvirtContext::PrintContextMsg(LibCmo::CKSTRING msg) {
if (msg != nullptr) { if (msg != nullptr) {
fprintf(stdout, UNVIRT_TERMCOL_LIGHT_YELLOW(("[CKContext] ")) "%s\n", msg); fprintf(stdout, UNVIRT_TERMCOL_LIGHT_YELLOW(("[CKContext] ")) "%s\n", msg);
} }

View File

@ -44,7 +44,7 @@ namespace Unvirt::Context {
protected: protected:
bool HasOpenedFile(); bool HasOpenedFile();
void ClearDocument(); void ClearDocument();
void PrintContextMsg(LibCmo::CK2::CKSTRING msg); void PrintContextMsg(LibCmo::CKSTRING msg);
CmdHelper::CommandRoot m_Root; CmdHelper::CommandRoot m_Root;
CmdHelper::HelpDocument* m_Help; CmdHelper::HelpDocument* m_Help;