finish CKTexture reading

This commit is contained in:
yyc12345 2023-09-12 17:03:06 +08:00
parent 9c1fcd172d
commit 42feff734d
12 changed files with 257 additions and 106 deletions

View File

@ -137,7 +137,7 @@ namespace LibCmo::CK2 {
#pragma region Core Read / Write #pragma region Core Read / Write
bool CKBitmapData::ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers) { bool CKBitmapData::ReadFromChunk(CKStateChunk* chunk, CKFileVisitor* file, const CKBitmapDataReadIdentifiers& identifiers) {
XContainer::XBitArray notReadSlot; XContainer::XBitArray hasReadSlot;
// check 3 types enbedded image // check 3 types enbedded image
// MARK: i think there is a potential vulnerable issue. // MARK: i think there is a potential vulnerable issue.
@ -152,7 +152,7 @@ namespace LibCmo::CK2 {
chunk->ReadStruct(bpp); chunk->ReadStruct(bpp);
SetSlotCount(slotcount); SetSlotCount(slotcount);
notReadSlot.resize(slotcount, false); hasReadSlot.resize(slotcount, false);
// the height and width is written outside of specific format // the height and width is written outside of specific format
// so we create image first for it. // so we create image first for it.
@ -162,7 +162,7 @@ namespace LibCmo::CK2 {
for (CKDWORD i = 0; i < slotcount; ++i) { for (CKDWORD i = 0; i < slotcount; ++i) {
CreateImage(width, height, i); CreateImage(width, height, i);
if (ReadSpecificFormatBitmap(chunk, GetImageDesc(i))) { if (ReadSpecificFormatBitmap(chunk, GetImageDesc(i))) {
notReadSlot[i] = true; hasReadSlot[i] = true;
} else { } else {
ReleaseImage(i); ReleaseImage(i);
} }
@ -175,7 +175,7 @@ namespace LibCmo::CK2 {
chunk->ReadStruct(slotcount); chunk->ReadStruct(slotcount);
SetSlotCount(slotcount); SetSlotCount(slotcount);
notReadSlot.resize(slotcount, false); hasReadSlot.resize(slotcount, false);
// the height and width is read by raw data function self. // the height and width is read by raw data function self.
// so we pass a cache variable to reader and do some modification // 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) { for (CKDWORD i = 0; i < slotcount; ++i) {
VxMath::VxImageDescEx rawcache; VxMath::VxImageDescEx rawcache;
if (ReadRawBitmap(chunk, &rawcache)) { if (ReadRawBitmap(chunk, &rawcache)) {
notReadSlot[i] = true; hasReadSlot[i] = true;
// do upside down blit // do upside down blit
CreateImage(rawcache.GetWidth(), rawcache.GetHeight(), i); CreateImage(rawcache.GetWidth(), rawcache.GetHeight(), i);
@ -197,12 +197,12 @@ namespace LibCmo::CK2 {
chunk->ReadStruct(slotcount); chunk->ReadStruct(slotcount);
SetSlotCount(slotcount); SetSlotCount(slotcount);
notReadSlot.resize(slotcount, false); hasReadSlot.resize(slotcount, false);
// MARK: a rough implement because we do not support this identifier // MARK: a rough implement because we do not support this identifier
for (CKDWORD i = 0; i < slotcount; ++i) { for (CKDWORD i = 0; i < slotcount; ++i) {
if (ReadOldRawBitmap(chunk, GetImageDesc(i))) { if (ReadOldRawBitmap(chunk, GetImageDesc(i))) {
notReadSlot[i] = true; hasReadSlot[i] = true;
} else { } else {
ReleaseImage(i); ReleaseImage(i);
} }
@ -224,7 +224,7 @@ namespace LibCmo::CK2 {
chunk->ReadString(filename); chunk->ReadString(filename);
if (filename.empty()) continue; if (filename.empty()) continue;
bool isNotLoaded = i >= notReadSlot.size() || notReadSlot[i]; bool isNotLoaded = i >= hasReadSlot.size() || (!hasReadSlot[i]);
if (isNotLoaded) { if (isNotLoaded) {
// if this image is not loaded. // if this image is not loaded.
// try resolve its file name and load it. // try resolve its file name and load it.
@ -399,6 +399,14 @@ namespace LibCmo::CK2 {
CKDWORD CKBitmapData::GetTransparentColor() { CKDWORD CKBitmapData::GetTransparentColor() {
return m_TransColor; return m_TransColor;
} }
void CKBitmapData::SetPickThreshold(CKDWORD threshold) {
m_PickThreshold = threshold;
}
CKDWORD CKBitmapData::GetPickThreshold() {
return m_PickThreshold;
}
#pragma endregion #pragma endregion

View File

@ -114,12 +114,32 @@ namespace LibCmo::CK2 {
See also: SetTranparentColor,SetTransparent See also: SetTranparentColor,SetTransparent
*/ */
CKDWORD GetTransparentColor(); 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: protected:
CKContext* m_Context; CKContext* m_Context;
XContainer::XArray<CKBitmapSlot> m_Slots; XContainer::XArray<CKBitmapSlot> m_Slots;
CKDWORD m_CurrentSlot; CKDWORD m_CurrentSlot;
CKINT m_PickThreshold; CKDWORD m_PickThreshold;
CK_BITMAPDATA_FLAGS m_BitmapFlags; CK_BITMAPDATA_FLAGS m_BitmapFlags;
CKDWORD m_TransColor; CKDWORD m_TransColor;

View File

@ -17,6 +17,7 @@
#include "ObjImpls/CKRenderObject.hpp" #include "ObjImpls/CKRenderObject.hpp"
#include "ObjImpls/CK3dEntity.hpp" #include "ObjImpls/CK3dEntity.hpp"
#include "ObjImpls/CK3dObject.hpp" #include "ObjImpls/CK3dObject.hpp"
#include "ObjImpls/CKTexture.hpp"
namespace LibCmo::CK2 { 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::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::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::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 #undef EasyClassReg

View File

@ -282,7 +282,7 @@ namespace LibCmo::CK2::DataHandlers {
} }
std::unique_ptr<CKBitmapHandler, CKBitmapHandlerDeleter> CKBitmapHandler::GetBitmapHandlerWrapper(const CKFileExtension& ext, const CKGUID& guid) { std::unique_ptr<CKBitmapHandler, CKBitmapHandlerDeleter> CKBitmapHandler::GetBitmapHandlerWrapper(const CKFileExtension& ext, const CKGUID& guid) {
return std::unique_ptr<CKBitmapHandler, std::function<void(CKBitmapHandler*)>>(GetBitmapHandler(ext, guid)); return std::unique_ptr<CKBitmapHandler, CKBitmapHandlerDeleter>(GetBitmapHandler(ext, guid));
} }
void CKBitmapHandlerDeleter::operator()(CKBitmapHandler* handler) { void CKBitmapHandlerDeleter::operator()(CKBitmapHandler* handler) {

View File

@ -3,7 +3,63 @@
namespace LibCmo::CK2::ObjImpls { 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() {} CKTexture::~CKTexture() {}
@ -18,6 +74,118 @@ namespace LibCmo::CK2::ObjImpls {
bool suc = CKBeObject::Load(chunk, file); bool suc = CKBeObject::Load(chunk, file);
if (!suc) return false; if (!suc) return false;
// read base image
suc = m_ImageHost.ReadFromChunk(chunk, file, CKBitmapDataReadIdentifiers {
.m_SpecificFormat = static_cast<CKDWORD>(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXREADER),
.m_RawData = static_cast<CKDWORD>(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXCOMPRESSED),
.m_OldRawData = static_cast<CKDWORD>(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXBITMAPS),
.m_FileNames = static_cast<CKDWORD>(CK_STATESAVEFLAGS_TEXTURE::CK_STATESAVE_TEXFILENAMES),
.m_MovieFileName = static_cast<CKDWORD>(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<CK_TEXTURE_SAVEOPTIONS>((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<FakeBitmapProperties*>(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; return true;
} }

View File

@ -25,6 +25,7 @@ namespace LibCmo::CK2::ObjImpls {
CKBitmapData m_ImageHost; CKBitmapData m_ImageHost;
VxMath::VX_PIXELFORMAT m_VideoFormat; VxMath::VX_PIXELFORMAT m_VideoFormat;
bool m_UseMipMap; bool m_UseMipMap;
XContainer::XArray<VxMath::VxImageDescEx> m_MipmapImages;
}; };
//class CKRenderObject : public CKBeObject { //class CKRenderObject : public CKBeObject {

View File

@ -3,6 +3,11 @@
#include "../VTAll.hpp" #include "../VTAll.hpp"
#if defined(LIBCMO_OS_WIN32) #if defined(LIBCMO_OS_WIN32)
#include <Windows.h> #include <Windows.h>
// disable annoy macro at the same time
#undef GetObject
#undef GetClassName
#undef LoadImage
#undef GetTempPath
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>

View File

@ -51,6 +51,13 @@ namespace Unvirt::AccessibleValue {
namespace EnumDesc { namespace EnumDesc {
const GeneralReflectionArray<LibCmo::CK2::CK_FILE_WRITEMODE> 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 { const CkClassidReflectionArray CK_CLASSID {
{ LibCmo::CK2::CK_CLASSID::CKCID_OBJECT, { { "CKCID_OBJECT" } } }, { LibCmo::CK2::CK_CLASSID::CKCID_OBJECT, { { "CKCID_OBJECT" } } },
{ LibCmo::CK2::CK_CLASSID::CKCID_PARAMETERIN, { { "CKCID_OBJECT", "CKCID_PARAMETERIN" } } }, { LibCmo::CK2::CK_CLASSID::CKCID_PARAMETERIN, { { "CKCID_OBJECT", "CKCID_PARAMETERIN" } } },
@ -235,59 +242,12 @@ namespace Unvirt::AccessibleValue {
namespace EnumDesc { namespace EnumDesc {
const GeneralReflectionArray<LibCmo::CK2::CK_FILE_WRITEMODE> 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<LibCmo::CK2::CK_LOAD_FLAGS> 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<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS { const GeneralReflectionArray<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS {
{ LibCmo::CK2::CK_FO_OPTIONS::CK_FO_DEFAULT, {"CK_FO_DEFAULT"} }, { 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_RENAMEOBJECT, {"CK_FO_RENAMEOBJECT"} },
{ LibCmo::CK2::CK_FO_OPTIONS::CK_FO_REPLACEOBJECT, {"CK_FO_REPLACEOBJECT"} }, { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_REPLACEOBJECT, {"CK_FO_REPLACEOBJECT"} },
{ LibCmo::CK2::CK_FO_OPTIONS::CK_FO_DONTLOADOBJECT, {"CK_FO_DONTLOADOBJECT"} }, { LibCmo::CK2::CK_FO_OPTIONS::CK_FO_DONTLOADOBJECT, {"CK_FO_DONTLOADOBJECT"} },
}; };
const GeneralReflectionArray<LibCmo::CK2::CK_LOADMODE> 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<LibCmo::CK2::CK_OBJECTCREATION_OPTIONS> 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<LibCmo::CK2::CK_PLUGIN_TYPE> 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<LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS> CK_STATECHUNK_CHUNKOPTIONS { const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS> CK_STATECHUNK_CHUNKOPTIONS {
{ LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_OPTION_IDS, {"CHNK_OPTION_IDS"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_OPTION_IDS, {"CHNK_OPTION_IDS"} },
{ LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_OPTION_MAN, {"CHNK_OPTION_MAN"} }, { 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_PTR, {"CHNK_DONTDELETE_PTR"} },
{ LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_DONTDELETE_PARSER, {"CHNK_DONTDELETE_PARSER"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS::CHNK_DONTDELETE_PARSER, {"CHNK_DONTDELETE_PARSER"} },
}; };
const GeneralReflectionArray<LibCmo::CK2::CK_OBJECT_FLAGS> 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<LibCmo::CK2::CK_STATECHUNK_DATAVERSION> CK_STATECHUNK_DATAVERSION { const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_DATAVERSION> CK_STATECHUNK_DATAVERSION {
{ LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_OLDVERSION, {"CHUNKDATA_OLDVERSION"} }, { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_OLDVERSION, {"CHUNKDATA_OLDVERSION"} },
{ LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_BASEVERSION, {"CHUNKDATA_BASEVERSION"} }, { 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::CHUNK_DEV_2_1, {"CHUNK_DEV_2_1"} },
{ LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_CURRENTVERSION, {"CHUNKDATA_CURRENTVERSION"} }, { LibCmo::CK2::CK_STATECHUNK_DATAVERSION::CHUNKDATA_CURRENTVERSION, {"CHUNKDATA_CURRENTVERSION"} },
}; };
const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION> CK_STATECHUNK_CHUNKVERSION { const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION> CK_STATECHUNK_CHUNKVERSION {
{ LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSIONBASE, {"CHUNK_VERSIONBASE"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSIONBASE, {"CHUNK_VERSIONBASE"} },
{ LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSION1, {"CHUNK_VERSION1"} }, { LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION::CHUNK_VERSION1, {"CHUNK_VERSION1"} },

View File

@ -59,16 +59,9 @@ namespace Unvirt {
namespace EnumDesc { namespace EnumDesc {
extern const GeneralReflectionArray<LibCmo::CK2::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE; extern const GeneralReflectionArray<LibCmo::CK2::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE;
extern const GeneralReflectionArray<LibCmo::CK2::CK_LOAD_FLAGS> CK_LOAD_FLAGS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS; extern const GeneralReflectionArray<LibCmo::CK2::CK_FO_OPTIONS> CK_FO_OPTIONS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_LOADMODE> CK_LOADMODE;
extern const GeneralReflectionArray<LibCmo::CK2::CK_OBJECTCREATION_OPTIONS> CK_OBJECTCREATION_OPTIONS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_PLUGIN_TYPE> CK_PLUGIN_TYPE;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS> CK_STATECHUNK_CHUNKOPTIONS; extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKOPTIONS> CK_STATECHUNK_CHUNKOPTIONS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_OBJECT_FLAGS> CK_OBJECT_FLAGS;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_DATAVERSION> CK_STATECHUNK_DATAVERSION; extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_DATAVERSION> CK_STATECHUNK_DATAVERSION;
extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION> CK_STATECHUNK_CHUNKVERSION; extern const GeneralReflectionArray<LibCmo::CK2::CK_STATECHUNK_CHUNKVERSION> CK_STATECHUNK_CHUNKVERSION;
} }

View File

@ -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.c_str()); PrintCKSTRING(obj.Name.toCKSTRING());
fputc('\n', stdout); fputc('\n', stdout);
} }
); );

View File

@ -1,4 +1,5 @@
#include "UnvirtContext.hpp" #include "UnvirtContext.hpp"
#include <CK2/MgrImpls/CKPathManager.hpp>
#include <cstdarg> #include <cstdarg>
namespace Unvirt::Context { namespace Unvirt::Context {
@ -21,7 +22,7 @@ namespace Unvirt::Context {
->Comment("The path to loading file.") ->Comment("The path to loading file.")
->Executes( ->Executes(
std::bind(&UnvirtContext::ProcLoad, this, std::placeholders::_1), 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")) ->Then((new CmdHelper::Literal("help"))
->Executes( ->Executes(
std::bind(&UnvirtContext::ProcHelp, this, std::placeholders::_1), std::bind(&UnvirtContext::ProcHelp, this, std::placeholders::_1),
@ -152,7 +170,7 @@ namespace Unvirt::Context {
delete m_FileReader; delete m_FileReader;
m_FileReader = nullptr; m_FileReader = nullptr;
// clear context // clear context
m_Ctx->DestroyAllCKObjects(); m_Ctx->ClearAll();
} }
void UnvirtContext::PrintContextMsg(LibCmo::CK2::CKSTRING msg) { void UnvirtContext::PrintContextMsg(LibCmo::CK2::CKSTRING msg) {
@ -399,7 +417,19 @@ namespace Unvirt::Context {
void UnvirtContext::ProcTemp(const CmdHelper::ArgumentsMap* amap) { void UnvirtContext::ProcTemp(const CmdHelper::ArgumentsMap* amap) {
// assign // assign
m_Ctx->SetTempPath(amap->Get<CmdHelper::StringArgument::vType>("temppath")->c_str()); if (!m_Ctx->GetPathManager()->SetTempFolder(amap->Get<CmdHelper::StringArgument::vType>("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<CmdHelper::StringArgument::vType>("datares")->c_str())) {
PrintCommonError("Set data resource folder failed. Check your path first.");
}
}
} }
void Unvirt::Context::UnvirtContext::ProcHelp(const CmdHelper::ArgumentsMap*) { void Unvirt::Context::UnvirtContext::ProcHelp(const CmdHelper::ArgumentsMap*) {

View File

@ -37,6 +37,7 @@ namespace Unvirt::Context {
void ProcItems(const CmdHelper::ArgumentsMap* amap); void ProcItems(const CmdHelper::ArgumentsMap* amap);
void ProcEncoding(const CmdHelper::ArgumentsMap* amap); void ProcEncoding(const CmdHelper::ArgumentsMap* amap);
void ProcTemp(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 ProcHelp(const CmdHelper::ArgumentsMap* amap);
void ProcExit(const CmdHelper::ArgumentsMap* amap); void ProcExit(const CmdHelper::ArgumentsMap* amap);