From 42feff734dbaeb56f522b52679df65529ab9e3fc Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 12 Sep 2023 17:03:06 +0800 Subject: [PATCH] finish CKTexture reading --- LibCmo/CK2/CKBitmapData.cpp | 24 ++- LibCmo/CK2/CKBitmapData.hpp | 22 ++- LibCmo/CK2/CKGlobals.cpp | 2 + LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp | 2 +- LibCmo/CK2/ObjImpls/CKTexture.cpp | 170 +++++++++++++++++++- LibCmo/CK2/ObjImpls/CKTexture.hpp | 1 + LibCmo/VxMath/VxMemoryMappedFile.hpp | 5 + Unvirt/AccessibleValue.cpp | 91 +---------- Unvirt/AccessibleValue.hpp | 7 - Unvirt/StructFormatter.cpp | 2 +- Unvirt/UnvirtContext.cpp | 36 ++++- Unvirt/UnvirtContext.hpp | 1 + 12 files changed, 257 insertions(+), 106 deletions(-) diff --git a/LibCmo/CK2/CKBitmapData.cpp b/LibCmo/CK2/CKBitmapData.cpp index fb6a1d3..d85b31e 100644 --- a/LibCmo/CK2/CKBitmapData.cpp +++ b/LibCmo/CK2/CKBitmapData.cpp @@ -137,7 +137,7 @@ namespace LibCmo::CK2 { #pragma region Core Read / Write bool CKBitmapData::ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers) { - XContainer::XBitArray notReadSlot; + XContainer::XBitArray hasReadSlot; // check 3 types enbedded image // MARK: i think there is a potential vulnerable issue. @@ -152,7 +152,7 @@ namespace LibCmo::CK2 { chunk->ReadStruct(bpp); SetSlotCount(slotcount); - notReadSlot.resize(slotcount, false); + hasReadSlot.resize(slotcount, false); // the height and width is written outside of specific format // so we create image first for it. @@ -162,7 +162,7 @@ namespace LibCmo::CK2 { for (CKDWORD i = 0; i < slotcount; ++i) { CreateImage(width, height, i); if (ReadSpecificFormatBitmap(chunk, GetImageDesc(i))) { - notReadSlot[i] = true; + hasReadSlot[i] = true; } else { ReleaseImage(i); } @@ -175,7 +175,7 @@ namespace LibCmo::CK2 { chunk->ReadStruct(slotcount); SetSlotCount(slotcount); - notReadSlot.resize(slotcount, false); + hasReadSlot.resize(slotcount, false); // the height and width is read by raw data function self. // so we pass a cache variable to reader and do some modification @@ -183,7 +183,7 @@ namespace LibCmo::CK2 { for (CKDWORD i = 0; i < slotcount; ++i) { VxMath::VxImageDescEx rawcache; if (ReadRawBitmap(chunk, &rawcache)) { - notReadSlot[i] = true; + hasReadSlot[i] = true; // do upside down blit CreateImage(rawcache.GetWidth(), rawcache.GetHeight(), i); @@ -197,12 +197,12 @@ namespace LibCmo::CK2 { chunk->ReadStruct(slotcount); SetSlotCount(slotcount); - notReadSlot.resize(slotcount, false); + hasReadSlot.resize(slotcount, false); // MARK: a rough implement because we do not support this identifier for (CKDWORD i = 0; i < slotcount; ++i) { if (ReadOldRawBitmap(chunk, GetImageDesc(i))) { - notReadSlot[i] = true; + hasReadSlot[i] = true; } else { ReleaseImage(i); } @@ -224,7 +224,7 @@ namespace LibCmo::CK2 { chunk->ReadString(filename); if (filename.empty()) continue; - bool isNotLoaded = i >= notReadSlot.size() || notReadSlot[i]; + bool isNotLoaded = i >= hasReadSlot.size() || (!hasReadSlot[i]); if (isNotLoaded) { // if this image is not loaded. // try resolve its file name and load it. @@ -399,6 +399,14 @@ namespace LibCmo::CK2 { CKDWORD CKBitmapData::GetTransparentColor() { return m_TransColor; } + + void CKBitmapData::SetPickThreshold(CKDWORD threshold) { + m_PickThreshold = threshold; + } + + CKDWORD CKBitmapData::GetPickThreshold() { + return m_PickThreshold; + } #pragma endregion diff --git a/LibCmo/CK2/CKBitmapData.hpp b/LibCmo/CK2/CKBitmapData.hpp index 1d2c461..16a019e 100644 --- a/LibCmo/CK2/CKBitmapData.hpp +++ b/LibCmo/CK2/CKBitmapData.hpp @@ -114,12 +114,32 @@ namespace LibCmo::CK2 { See also: SetTranparentColor,SetTransparent */ CKDWORD GetTransparentColor(); + /** + Summary: Sets pick threshold value. + Arguments: + pt: Pick threshold value to be set. + Remarks: + + The pick threshold is used when picking object with + transparent textures. + + It is the minimum value for alpha component + below which picking is not valid.So this value is supposed to be in the range 0..255 + and the default value 0 means the picking is always valid. + + But if a value >0 is used and the texture use transparency (some pixels of the bitmap will have + alpha component of 0) an object will not be picked on its transparent part. + + See Also: CKRenderContext::Pick + */ + void SetPickThreshold(CKDWORD threshold); + /** + Summary: Gets pick threshold value. + */ + CKDWORD GetPickThreshold(); protected: CKContext* m_Context; XContainer::XArray m_Slots; CKDWORD m_CurrentSlot; - CKINT m_PickThreshold; + CKDWORD m_PickThreshold; CK_BITMAPDATA_FLAGS m_BitmapFlags; CKDWORD m_TransColor; diff --git a/LibCmo/CK2/CKGlobals.cpp b/LibCmo/CK2/CKGlobals.cpp index e3326a4..2d5c65f 100644 --- a/LibCmo/CK2/CKGlobals.cpp +++ b/LibCmo/CK2/CKGlobals.cpp @@ -17,6 +17,7 @@ #include "ObjImpls/CKRenderObject.hpp" #include "ObjImpls/CK3dEntity.hpp" #include "ObjImpls/CK3dObject.hpp" +#include "ObjImpls/CKTexture.hpp" namespace LibCmo::CK2 { @@ -270,6 +271,7 @@ CKClassRegister(cid, parentCid, \ EasyClassReg(ObjImpls::CKRenderObject, CK_CLASSID::CKCID_RENDEROBJECT, CK_CLASSID::CKCID_BEOBJECT, "Render Object"); EasyClassReg(ObjImpls::CK3dEntity, CK_CLASSID::CKCID_3DENTITY, CK_CLASSID::CKCID_RENDEROBJECT, "3D Entity"); EasyClassReg(ObjImpls::CK3dObject, CK_CLASSID::CKCID_3DOBJECT, CK_CLASSID::CKCID_3DENTITY, "3D Object"); + EasyClassReg(ObjImpls::CKTexture, CK_CLASSID::CKCID_TEXTURE, CK_CLASSID::CKCID_BEOBJECT, "Texture"); #undef EasyClassReg diff --git a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp index 5b3766c..c83d8c3 100644 --- a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp +++ b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp @@ -282,7 +282,7 @@ namespace LibCmo::CK2::DataHandlers { } std::unique_ptr CKBitmapHandler::GetBitmapHandlerWrapper(const CKFileExtension& ext, const CKGUID& guid) { - return std::unique_ptr>(GetBitmapHandler(ext, guid)); + return std::unique_ptr(GetBitmapHandler(ext, guid)); } void CKBitmapHandlerDeleter::operator()(CKBitmapHandler* handler) { diff --git a/LibCmo/CK2/ObjImpls/CKTexture.cpp b/LibCmo/CK2/ObjImpls/CKTexture.cpp index 6f7aecd..efdc791 100644 --- a/LibCmo/CK2/ObjImpls/CKTexture.cpp +++ b/LibCmo/CK2/ObjImpls/CKTexture.cpp @@ -3,7 +3,63 @@ namespace LibCmo::CK2::ObjImpls { - CKTexture::CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name) {} + /** + * @brief A fake struct define. + * This define is served for a buffer read / write in CKTexture. + * Because Virtools directly write a raw struct into file, + * and our defines are different with Virtools. + * So we need create a fake struct. + */ + struct FakeBitmapProperties { + CKINT m_Size; + struct { + // fake CKGUID + CKDWORD d1, d2; + }m_ReaderGuid; + struct { + // fake CKFileExtension + CKCHAR m_Data[4]; + }m_Ext; + struct { + // fake VxImageDescEx + CK2::CKINT Size; ///< Size of the structure + CK2::CKDWORD Flags; ///< Reserved for special formats (such as compressed ) 0 otherwise + + CK2::CKINT Width; ///< Width in pixel of the image + CK2::CKINT Height; ///< Height in pixel of the image + union { + CK2::CKINT BytesPerLine; ///< Pitch (width in bytes) of the image + CK2::CKINT TotalImageSize; ///< For compressed image (DXT1...) the total size of the image + }; + CK2::CKINT BitsPerPixel; ///< Number of bits per pixel + union { + CK2::CKDWORD RedMask; ///< Mask for Red component + CK2::CKDWORD BumpDuMask; ///< Mask for Bump Du component + }; + union { + CK2::CKDWORD GreenMask; ///< Mask for Green component + CK2::CKDWORD BumpDvMask; ///< Mask for Bump Dv component + }; + union { + CK2::CKDWORD BlueMask; ///< Mask for Blue component + CK2::CKDWORD BumpLumMask; ///< Mask for Luminance component + + }; + CK2::CKDWORD AlphaMask; ///< Mask for Alpha component + + CK2::CKWORD BytesPerColorEntry; ///< ColorMap Stride + CK2::CKWORD ColorMapEntries; ///< If other than 0 image is palletized + + CK2::CKBYTE* ColorMap; ///< Palette colors + CK2::CKBYTE* Image; ///< Image + }m_Format; + void* m_Data; + }; + + CKTexture::CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name) : + CKBeObject(ctx, ckid, name), + m_ImageHost(ctx), + m_VideoFormat(VxMath::VX_PIXELFORMAT::_16_ARGB1555), m_UseMipMap(false), m_MipmapImages() {} CKTexture::~CKTexture() {} @@ -18,6 +74,118 @@ namespace LibCmo::CK2::ObjImpls { bool suc = CKBeObject::Load(chunk, file); if (!suc) return false; + // read base image + suc = m_ImageHost.ReadFromChunk(chunk, file, CKBitmapDataReadIdentifiers { + .m_SpecificFormat = static_cast(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXREADER), + .m_RawData = static_cast(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXCOMPRESSED), + .m_OldRawData = static_cast(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXBITMAPS), + .m_FileNames = static_cast(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXFILENAMES), + .m_MovieFileName = static_cast(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXAVIFILENAME) + }); + if (!suc) return false; + + if (chunk->GetDataVersion() < CK_STATECHUNK_DATAVERSION::CHUNK_MAJORCHANGE_VERSION) { + // MARK: old data process. i don't want to process it anymore. + // thus return false directly. + return false; + } else { + CKDWORD fmtbytesize; + if (chunk->SeekIdentifierAndReturnSize(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_OLDTEXONLY, &fmtbytesize)) { + // 0xFF (blank) 0xFF (save options) 0xFF (transparent + movie info + video fmt) 0xFF (mip map) + CKDWORD mixdata; + chunk->ReadStruct(mixdata); + m_UseMipMap = (mixdata & 0xFF); + m_ImageHost.SetSaveOptions(static_cast((mixdata & 0xFF0000) >> 16)); + + mixdata = mixdata & 0xFF00 >> 8; + m_ImageHost.SetTransparent(mixdata & 0x1); + bool hasVideoFmt = mixdata & 0x2; + // MARK: I ignore 0x4 in there because it involve video. + + // set current slot, transparent color, and video format. + CKDWORD currentSlot, transColor, videoFmt; + fmtbytesize -= CKSizeof(CKDWORD); + switch (fmtbytesize) { + case (3 * sizeof(CKDWORD)): + chunk->ReadStruct(transColor); + m_ImageHost.SetTransparentColor(transColor); + chunk->ReadStruct(currentSlot); + m_ImageHost.SetCurrentSlot(currentSlot); + chunk->ReadStruct(m_VideoFormat); + break; + case (2 * sizeof(CKDWORD)): + if (m_ImageHost.GetSlotCount() <= 1 || !hasVideoFmt) { + chunk->ReadStruct(transColor); + m_ImageHost.SetTransparentColor(transColor); + } + if (m_ImageHost.GetSlotCount() > 1) { + chunk->ReadStruct(currentSlot); + m_ImageHost.SetCurrentSlot(currentSlot); + } + if (hasVideoFmt) { + chunk->ReadStruct(m_VideoFormat); + } + break; + case (sizeof(CKDWORD)): + if (hasVideoFmt) { + chunk->ReadStruct(m_VideoFormat); + } else if (m_ImageHost.GetSlotCount() <= 1) { + chunk->ReadStruct(transColor); + m_ImageHost.SetTransparentColor(transColor); + } else { + chunk->ReadStruct(currentSlot); + m_ImageHost.SetCurrentSlot(currentSlot); + } + break; + } + + } + + // read mipmap + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_USERMIPMAP)) { + CKDWORD mipmapCount; + chunk->ReadStruct(mipmapCount); + m_MipmapImages.resize(mipmapCount); + + for (CKDWORD i = 0; i < mipmapCount; ++i) { + VxMath::VxImageDescEx cache; + if (CKBitmapData::ReadRawBitmap(chunk, &cache)) { + VxMath::VxDoBlitUpsideDown(&cache, &m_MipmapImages[i]); + } + } + + } + + // pick threshold + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_PICKTHRESHOLD)) { + CKDWORD threshold; + chunk->ReadStruct(threshold); + m_ImageHost.SetPickThreshold(threshold); + } + + // save properties + if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXSAVEFORMAT)) { + CKDWORD bufsize; + CKStateChunk::TBuffer buf; + chunk->ReadBufferWrapper(&buf, &bufsize); + if (buf != nullptr) { + FakeBitmapProperties* props = reinterpret_cast(buf.get()); + + CKBitmapProperties myprops( + CKGUID(props->m_ReaderGuid.d1, props->m_ReaderGuid.d2), + props->m_Ext.m_Data + ); + m_ImageHost.SetSaveFormat(myprops); + } + } + + } + + // correct video format + if (m_VideoFormat > VxMath::VX_PIXELFORMAT::_32_X8L8V8U8) { + m_VideoFormat = VxMath::VX_PIXELFORMAT::_16_ARGB1555; + } + return true; } diff --git a/LibCmo/CK2/ObjImpls/CKTexture.hpp b/LibCmo/CK2/ObjImpls/CKTexture.hpp index e793762..b2266e9 100644 --- a/LibCmo/CK2/ObjImpls/CKTexture.hpp +++ b/LibCmo/CK2/ObjImpls/CKTexture.hpp @@ -25,6 +25,7 @@ namespace LibCmo::CK2::ObjImpls { CKBitmapData m_ImageHost; VxMath::VX_PIXELFORMAT m_VideoFormat; bool m_UseMipMap; + XContainer::XArray m_MipmapImages; }; //class CKRenderObject : public CKBeObject { diff --git a/LibCmo/VxMath/VxMemoryMappedFile.hpp b/LibCmo/VxMath/VxMemoryMappedFile.hpp index d9fbaaf..a055956 100644 --- a/LibCmo/VxMath/VxMemoryMappedFile.hpp +++ b/LibCmo/VxMath/VxMemoryMappedFile.hpp @@ -3,6 +3,11 @@ #include "../VTAll.hpp" #if defined(LIBCMO_OS_WIN32) #include +// disable annoy macro at the same time +#undef GetObject +#undef GetClassName +#undef LoadImage +#undef GetTempPath #else #include #include diff --git a/Unvirt/AccessibleValue.cpp b/Unvirt/AccessibleValue.cpp index 77f6edb..9461376 100644 --- a/Unvirt/AccessibleValue.cpp +++ b/Unvirt/AccessibleValue.cpp @@ -51,6 +51,13 @@ namespace Unvirt::AccessibleValue { namespace EnumDesc { + const GeneralReflectionArray CK_FILE_WRITEMODE { + { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_UNCOMPRESSED, {"CKFILE_UNCOMPRESSED"} }, + { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD, {"CKFILE_CHUNKCOMPRESSED_OLD"} }, + { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_EXTERNALTEXTURES_OLD, {"CKFILE_EXTERNALTEXTURES_OLD"} }, + { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_FORVIEWER, {"CKFILE_FORVIEWER"} }, + { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_WHOLECOMPRESSED, {"CKFILE_WHOLECOMPRESSED"} }, + }; const CkClassidReflectionArray CK_CLASSID { { LibCmo::CK2::CK_CLASSID::CKCID_OBJECT, { { "CKCID_OBJECT" } } }, { LibCmo::CK2::CK_CLASSID::CKCID_PARAMETERIN, { { "CKCID_OBJECT", "CKCID_PARAMETERIN" } } }, @@ -235,59 +242,12 @@ namespace Unvirt::AccessibleValue { namespace EnumDesc { - const GeneralReflectionArray CK_FILE_WRITEMODE { - { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_UNCOMPRESSED, {"CKFILE_UNCOMPRESSED"} }, - { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_CHUNKCOMPRESSED_OLD, {"CKFILE_CHUNKCOMPRESSED_OLD"} }, - { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_EXTERNALTEXTURES_OLD, {"CKFILE_EXTERNALTEXTURES_OLD"} }, - { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_FORVIEWER, {"CKFILE_FORVIEWER"} }, - { LibCmo::CK2::CK_FILE_WRITEMODE::CKFILE_WHOLECOMPRESSED, {"CKFILE_WHOLECOMPRESSED"} }, - }; - const GeneralReflectionArray CK_LOAD_FLAGS { - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_ANIMATION, {"CK_LOAD_ANIMATION"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_GEOMETRY, {"CK_LOAD_GEOMETRY"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_DEFAULT, {"CK_LOAD_DEFAULT"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_ASCHARACTER, {"CK_LOAD_ASCHARACTER"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_DODIALOG, {"CK_LOAD_DODIALOG"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_AS_DYNAMIC_OBJECT, {"CK_LOAD_AS_DYNAMIC_OBJECT"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_AUTOMATICMODE, {"CK_LOAD_AUTOMATICMODE"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_CHECKDUPLICATES, {"CK_LOAD_CHECKDUPLICATES"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_CHECKDEPENDENCIES, {"CK_LOAD_CHECKDEPENDENCIES"} }, - { LibCmo::CK2::CK_LOAD_FLAGS::CK_LOAD_ONLYBEHAVIORS, {"CK_LOAD_ONLYBEHAVIORS"} }, - }; const GeneralReflectionArray CK_FO_OPTIONS { { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_DEFAULT, {"CK_FO_DEFAULT"} }, { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_RENAMEOBJECT, {"CK_FO_RENAMEOBJECT"} }, { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_REPLACEOBJECT, {"CK_FO_REPLACEOBJECT"} }, { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_DONTLOADOBJECT, {"CK_FO_DONTLOADOBJECT"} }, }; - const GeneralReflectionArray CK_LOADMODE { - { LibCmo::CK2::CK_LOADMODE::CKLOAD_INVALID, {"CKLOAD_INVALID"} }, - { LibCmo::CK2::CK_LOADMODE::CKLOAD_OK, {"CKLOAD_OK"} }, - { LibCmo::CK2::CK_LOADMODE::CKLOAD_REPLACE, {"CKLOAD_REPLACE"} }, - { LibCmo::CK2::CK_LOADMODE::CKLOAD_RENAME, {"CKLOAD_RENAME"} }, - { LibCmo::CK2::CK_LOADMODE::CKLOAD_USECURRENT, {"CKLOAD_USECURRENT"} }, - }; - const GeneralReflectionArray CK_OBJECTCREATION_OPTIONS { - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECHECK, {"CK_OBJECTCREATION_NONAMECHECK"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_REPLACE, {"CK_OBJECTCREATION_REPLACE"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_RENAME, {"CK_OBJECTCREATION_RENAME"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_USECURRENT, {"CK_OBJECTCREATION_USECURRENT"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_ASK, {"CK_OBJECTCREATION_ASK"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_FLAGSMASK, {"CK_OBJECTCREATION_FLAGSMASK"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_DYNAMIC, {"CK_OBJECTCREATION_DYNAMIC"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_ACTIVATE, {"CK_OBJECTCREATION_ACTIVATE"} }, - { LibCmo::CK2::CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECOPY, {"CK_OBJECTCREATION_NONAMECOPY"} }, - }; - const GeneralReflectionArray CK_PLUGIN_TYPE { - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_BITMAP_READER, {"CKPLUGIN_BITMAP_READER"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_SOUND_READER, {"CKPLUGIN_SOUND_READER"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_MODEL_READER, {"CKPLUGIN_MODEL_READER"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL, {"CKPLUGIN_MANAGER_DLL"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_BEHAVIOR_DLL, {"CKPLUGIN_BEHAVIOR_DLL"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_RENDERENGINE_DLL, {"CKPLUGIN_RENDERENGINE_DLL"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_MOVIE_READER, {"CKPLUGIN_MOVIE_READER"} }, - { LibCmo::CK2::CK_PLUGIN_TYPE::CKPLUGIN_EXTENSION_DLL, {"CKPLUGIN_EXTENSION_DLL"} }, - }; const GeneralReflectionArray CK_STATECHUNK_CHUNKOPTIONS { { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_OPTION_IDS, {"CHNK_OPTION_IDS"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_OPTION_MAN, {"CHNK_OPTION_MAN"} }, @@ -298,42 +258,6 @@ namespace Unvirt::AccessibleValue { { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_DONTDELETE_PTR, {"CHNK_DONTDELETE_PTR"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_DONTDELETE_PARSER, {"CHNK_DONTDELETE_PARSER"} }, }; - const GeneralReflectionArray CK_OBJECT_FLAGS { - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_INTERFACEOBJ, {"CK_OBJECT_INTERFACEOBJ"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_PRIVATE, {"CK_OBJECT_PRIVATE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_INTERFACEMARK, {"CK_OBJECT_INTERFACEMARK"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_FREEID, {"CK_OBJECT_FREEID"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_TOBEDELETED, {"CK_OBJECT_TOBEDELETED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_NOTTOBESAVED, {"CK_OBJECT_NOTTOBESAVED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE, {"CK_OBJECT_VISIBLE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_NAMESHARED, {"CK_OBJECT_NAMESHARED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_DYNAMIC, {"CK_OBJECT_DYNAMIC"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE, {"CK_OBJECT_HIERACHICALHIDE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_UPTODATE, {"CK_OBJECT_UPTODATE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_TEMPMARKER, {"CK_OBJECT_TEMPMARKER"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_ONLYFORFILEREFERENCE, {"CK_OBJECT_ONLYFORFILEREFERENCE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_NOTTOBEDELETED, {"CK_OBJECT_NOTTOBEDELETED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_APPDATA, {"CK_OBJECT_APPDATA"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_SINGLEACTIVITY, {"CK_OBJECT_SINGLEACTIVITY"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_LOADSKIPBEOBJECT, {"CK_OBJECT_LOADSKIPBEOBJECT"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_NOTTOBELISTEDANDSAVED, {"CK_OBJECT_NOTTOBELISTEDANDSAVED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETEROUT_SETTINGS, {"CK_PARAMETEROUT_SETTINGS"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETEROUT_PARAMOP, {"CK_PARAMETEROUT_PARAMOP"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETERIN_DISABLED, {"CK_PARAMETERIN_DISABLED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETERIN_THIS, {"CK_PARAMETERIN_THIS"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETERIN_SHARED, {"CK_PARAMETERIN_SHARED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_PARAMETEROUT_DELETEAFTERUSE, {"CK_PARAMETEROUT_DELETEAFTERUSE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_PARAMMASK, {"CK_OBJECT_PARAMMASK"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_BEHAVIORIO_IN, {"CK_BEHAVIORIO_IN"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_BEHAVIORIO_OUT, {"CK_BEHAVIORIO_OUT"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_BEHAVIORIO_ACTIVE, {"CK_BEHAVIORIO_ACTIVE"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_IOTYPEMASK, {"CK_OBJECT_IOTYPEMASK"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_IOMASK, {"CK_OBJECT_IOMASK"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CKBEHAVIORLINK_RESERVED, {"CKBEHAVIORLINK_RESERVED"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CKBEHAVIORLINK_ACTIVATEDLASTFRAME, {"CKBEHAVIORLINK_ACTIVATEDLASTFRAME"} }, - { LibCmo::CK2::CK_OBJECT_FLAGS::CK_OBJECT_BEHAVIORLINKMASK, {"CK_OBJECT_BEHAVIORLINKMASK"} }, - }; - const GeneralReflectionArray CK_STATECHUNK_DATAVERSION { { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_OLDVERSION, {"CHUNKDATA_OLDVERSION"} }, { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_BASEVERSION, {"CHUNKDATA_BASEVERSION"} }, @@ -348,7 +272,6 @@ namespace Unvirt::AccessibleValue { { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNK_DEV_2_1, {"CHUNK_DEV_2_1"} }, { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_CURRENTVERSION, {"CHUNKDATA_CURRENTVERSION"} }, }; - const GeneralReflectionArray CK_STATECHUNK_CHUNKVERSION { { LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSIONBASE, {"CHUNK_VERSIONBASE"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSION1, {"CHUNK_VERSION1"} }, diff --git a/Unvirt/AccessibleValue.hpp b/Unvirt/AccessibleValue.hpp index a60a2ff..f5f2359 100644 --- a/Unvirt/AccessibleValue.hpp +++ b/Unvirt/AccessibleValue.hpp @@ -59,16 +59,9 @@ namespace Unvirt { namespace EnumDesc { extern const GeneralReflectionArray CK_FILE_WRITEMODE; - extern const GeneralReflectionArray CK_LOAD_FLAGS; extern const GeneralReflectionArray CK_FO_OPTIONS; - extern const GeneralReflectionArray CK_LOADMODE; - extern const GeneralReflectionArray CK_OBJECTCREATION_OPTIONS; - extern const GeneralReflectionArray CK_PLUGIN_TYPE; extern const GeneralReflectionArray CK_STATECHUNK_CHUNKOPTIONS; - extern const GeneralReflectionArray CK_OBJECT_FLAGS; - extern const GeneralReflectionArray CK_STATECHUNK_DATAVERSION; - extern const GeneralReflectionArray CK_STATECHUNK_CHUNKVERSION; } diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index 9a6d7df..8324fd5 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -136,7 +136,7 @@ namespace Unvirt::StructFormatter { fputc('\t', stdout); PrintPointer(obj.Data); fputc('\t', stdout); - PrintCKSTRING(obj.Name.c_str()); + PrintCKSTRING(obj.Name.toCKSTRING()); fputc('\n', stdout); } ); diff --git a/Unvirt/UnvirtContext.cpp b/Unvirt/UnvirtContext.cpp index cbc7d50..e1c64ad 100644 --- a/Unvirt/UnvirtContext.cpp +++ b/Unvirt/UnvirtContext.cpp @@ -1,4 +1,5 @@ #include "UnvirtContext.hpp" +#include #include namespace Unvirt::Context { @@ -21,7 +22,7 @@ namespace Unvirt::Context { ->Comment("The path to loading file.") ->Executes( std::bind(&UnvirtContext::ProcLoad, this, std::placeholders::_1), - "Load a Virtools composition deeply." + "Load a Virtools composition." ) ) ) @@ -110,6 +111,23 @@ namespace Unvirt::Context { ) ) ) + ->Then((new CmdHelper::Literal("rsc")) + ->Then((new CmdHelper::Literal("clear")) + ->Executes( + std::bind(&UnvirtContext::ProcRsc, this, std::placeholders::_1, true), + "Clear all data resources paths." + ) + ) + ->Then((new CmdHelper::Literal("add")) + ->Then((new CmdHelper::StringArgument("datares")) + ->Comment("The data resources path .") + ->Executes( + std::bind(&UnvirtContext::ProcRsc, this, std::placeholders::_1, false), + "Add a path to let Virtools find resources." + ) + ) + ) + ) ->Then((new CmdHelper::Literal("help")) ->Executes( std::bind(&UnvirtContext::ProcHelp, this, std::placeholders::_1), @@ -152,7 +170,7 @@ namespace Unvirt::Context { delete m_FileReader; m_FileReader = nullptr; // clear context - m_Ctx->DestroyAllCKObjects(); + m_Ctx->ClearAll(); } void UnvirtContext::PrintContextMsg(LibCmo::CK2::CKSTRING msg) { @@ -399,7 +417,19 @@ namespace Unvirt::Context { void UnvirtContext::ProcTemp(const CmdHelper::ArgumentsMap* amap) { // assign - m_Ctx->SetTempPath(amap->Get("temppath")->c_str()); + if (!m_Ctx->GetPathManager()->SetTempFolder(amap->Get("temppath")->c_str())) { + PrintCommonError("Set temp folder failed. Check your path first."); + } + } + + void Unvirt::Context::UnvirtContext::ProcRsc(const CmdHelper::ArgumentsMap* amap, bool isClear) { + if (isClear) { + m_Ctx->GetPathManager()->ClearPath(); + } else { + if (!m_Ctx->GetPathManager()->AddPath(amap->Get("datares")->c_str())) { + PrintCommonError("Set data resource folder failed. Check your path first."); + } + } } void Unvirt::Context::UnvirtContext::ProcHelp(const CmdHelper::ArgumentsMap*) { diff --git a/Unvirt/UnvirtContext.hpp b/Unvirt/UnvirtContext.hpp index 254fb99..6f3da8d 100644 --- a/Unvirt/UnvirtContext.hpp +++ b/Unvirt/UnvirtContext.hpp @@ -37,6 +37,7 @@ namespace Unvirt::Context { void ProcItems(const CmdHelper::ArgumentsMap* amap); void ProcEncoding(const CmdHelper::ArgumentsMap* amap); void ProcTemp(const CmdHelper::ArgumentsMap* amap); + void ProcRsc(const CmdHelper::ArgumentsMap* amap, bool isClear); void ProcHelp(const CmdHelper::ArgumentsMap* amap); void ProcExit(const CmdHelper::ArgumentsMap* amap);