finish hdr1 dep read
This commit is contained in:
parent
2a6cd48ac9
commit
01bc6074f4
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
|||
*.nms
|
||||
*.vmo
|
||||
CodeGen/dest/*.txt
|
||||
PyCmoOld/
|
||||
|
||||
.vscode/
|
||||
|
||||
|
|
|
@ -25,3 +25,14 @@ enum CK_FO_OPTIONS
|
|||
CK_FO_DONTLOADOBJECT, // Object chunk will not be read either because it is a reference
|
||||
// or because the loaded object already exist in the current level
|
||||
// and the user choose to keep the existing one.
|
||||
|
||||
enum CK_PLUGIN_TYPE
|
||||
CKPLUGIN_BITMAP_READER = 0, // The plugin is bitmap (textures,sprites) loader
|
||||
CKPLUGIN_SOUND_READER = 1, // Sound Reader Plugin
|
||||
CKPLUGIN_MODEL_READER = 2, // 3D Model Reader
|
||||
CKPLUGIN_MANAGER_DLL = 3, // The plugin implements a Manager
|
||||
CKPLUGIN_BEHAVIOR_DLL = 4, // The plugin implements one or more behaviors
|
||||
CKPLUGIN_RENDERENGINE_DLL = 5, // Render Engine plugin
|
||||
CKPLUGIN_MOVIE_READER = 6, // Movie (AVI,Mpeg) reader
|
||||
CKPLUGIN_EXTENSION_DLL = 7, // Generic extension (definition of new parameter types or operations for ex.)
|
||||
|
||||
|
|
|
@ -193,6 +193,16 @@ namespace LibCmo {
|
|||
CK_FO_REPLACEOBJECT,
|
||||
CK_FO_DONTLOADOBJECT
|
||||
};
|
||||
enum class CK_PLUGIN_TYPE : int32_t {
|
||||
CKPLUGIN_BITMAP_READER = 0,
|
||||
CKPLUGIN_SOUND_READER = 1,
|
||||
CKPLUGIN_MODEL_READER = 2,
|
||||
CKPLUGIN_MANAGER_DLL = 3,
|
||||
CKPLUGIN_BEHAVIOR_DLL = 4,
|
||||
CKPLUGIN_RENDERENGINE_DLL = 5,
|
||||
CKPLUGIN_MOVIE_READER = 6,
|
||||
CKPLUGIN_EXTENSION_DLL = 7
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@ namespace LibCmo {
|
|||
if (u8_filename == nullptr) return CKERROR::CKERR_INVALIDPARAMETER;
|
||||
|
||||
this->m_FileName = u8_filename;
|
||||
this->m_MappedFile = new VxMemoryMappedFile(this->m_FileName.c_str());
|
||||
this->m_MappedFile = new(std::nothrow) VxMemoryMappedFile(this->m_FileName.c_str());
|
||||
if (this->m_MappedFile == nullptr) return CKERROR::CKERR_OUTOFMEMORY;
|
||||
if (!this->m_MappedFile->IsValid()) return CKERROR::CKERR_INVALIDFILE;
|
||||
|
||||
// MARK: CKContext::SetLastCmoLoaded
|
||||
return this->OpenMemory(this->m_MappedFile->GetBase(), this->m_MappedFile->GetFileSize(), flags);
|
||||
}
|
||||
|
||||
|
@ -34,8 +36,11 @@ namespace LibCmo {
|
|||
// compare magic words
|
||||
if (BufferSize < 0x20 || memcmp(MemoryBuffer, "Nemo", 4u)) return CKERROR::CKERR_INVALIDFILE;
|
||||
|
||||
this->m_Parser = new CKBufferParser(MemoryBuffer, BufferSize, false);
|
||||
this->m_Parser = new(std::nothrow) CKBufferParser(MemoryBuffer, BufferSize, false);
|
||||
if (this->m_Parser == nullptr) return CKERROR::CKERR_OUTOFMEMORY;
|
||||
// MARK: eliminate check of m_Parser->m_ReaderBegin
|
||||
|
||||
// MARK: dword_2405F6C0 = 0;
|
||||
this->m_Flags = Flags;
|
||||
this->m_IndexByClassId.resize(static_cast<size_t>(CK_CLASSID::CKCID_MAXCLASSID));
|
||||
return this->ReadFileHeaders(&(this->m_Parser));
|
||||
|
@ -49,8 +54,7 @@ namespace LibCmo {
|
|||
CKDWORD fhdr1[8];
|
||||
CKDWORD fhdr2[8];
|
||||
if (parser->GetSize() < sizeof(fhdr1)) return CKERROR::CKERR_INVALIDFILE;
|
||||
memcpy(fhdr1, parser->GetPtr(), sizeof(fhdr1));
|
||||
parser->MoveCursor(sizeof(fhdr1));
|
||||
parser->ReadAndMove(fhdr1, sizeof(fhdr1));
|
||||
|
||||
if (fhdr1[5]) { // it seems that there is a ZERO checker?
|
||||
memset(fhdr1, 0, sizeof(fhdr1));
|
||||
|
@ -64,8 +68,7 @@ namespace LibCmo {
|
|||
memset(fhdr2, 0, sizeof(fhdr2));
|
||||
} else {
|
||||
if (parser->GetSize() < sizeof(fhdr1) + sizeof(fhdr2)) return CKERROR::CKERR_INVALIDFILE;
|
||||
memcpy(fhdr2, parser->GetPtr(), sizeof(fhdr2));
|
||||
parser->MoveCursor(sizeof(fhdr2));
|
||||
parser->ReadAndMove(fhdr2, sizeof(fhdr2));
|
||||
}
|
||||
|
||||
// forcely reset too big product ver
|
||||
|
@ -111,7 +114,11 @@ namespace LibCmo {
|
|||
// compare size to decide wheher use compress feature
|
||||
void* decomp_buffer = CKUnPackData(this->m_FileInfo.Hdr1UnPackSize, parser->GetPtr(), this->m_FileInfo.Hdr1PackSize);
|
||||
if (decomp_buffer != nullptr) {
|
||||
parser = new CKBufferParser(decomp_buffer, this->m_FileInfo.Hdr1UnPackSize, true);
|
||||
parser = new(std::nothrow) CKBufferParser(decomp_buffer, this->m_FileInfo.Hdr1UnPackSize, true);
|
||||
if (parser == nullptr) {
|
||||
free(decomp_buffer);
|
||||
return CKERROR::CKERR_OUTOFMEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,31 +131,100 @@ namespace LibCmo {
|
|||
this->m_FileObject.resize(this->m_FileInfo.ObjectCount);
|
||||
|
||||
// read data
|
||||
for (auto it = this->m_FileObject.begin(); it != this->m_FileObject.end(); ++it) {
|
||||
CKFileObject* fileobj = &(*it);
|
||||
for (auto& fileobj : this->m_FileObject) {
|
||||
// setup useless fields
|
||||
fileobj->ObjPtr = nullptr;
|
||||
fileobj->Data = nullptr;
|
||||
fileobj.ObjPtr = nullptr;
|
||||
fileobj.Data = nullptr;
|
||||
|
||||
// read basic fields
|
||||
memcpy(&(fileobj->Object), parser->GetPtr(), sizeof(CK_ID));
|
||||
parser->MoveCursor(sizeof(CK_ID));
|
||||
memcpy(&(fileobj->ObjectCid), parser->GetPtr(), sizeof(CK_CLASSID));
|
||||
parser->MoveCursor(sizeof(CK_CLASSID));
|
||||
memcpy(&(fileobj->FileIndex), parser->GetPtr(), sizeof(CKDWORD));
|
||||
parser->MoveCursor(sizeof(CKDWORD));
|
||||
parser->ReadAndMove(&(fileobj.Object), sizeof(CK_ID));
|
||||
parser->ReadAndMove(&(fileobj.ObjectCid), sizeof(CK_CLASSID));
|
||||
parser->ReadAndMove(&(fileobj.FileIndex), sizeof(CKDWORD));
|
||||
|
||||
CKDWORD namelen;
|
||||
memcpy(&namelen, parser->GetPtr(), sizeof(CKDWORD));
|
||||
parser->MoveCursor(sizeof(CKDWORD));
|
||||
parser->ReadAndMove(&namelen, sizeof(CKDWORD));
|
||||
if (namelen != 0) {
|
||||
fileobj->Name.resize(namelen);
|
||||
memcpy(fileobj->Name.data(), parser->GetPtr(), namelen);
|
||||
parser->MoveCursor(namelen);
|
||||
fileobj.Name.resize(namelen);
|
||||
parser->ReadAndMove(fileobj.Name.data(), namelen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== dep list read ==========
|
||||
// file ver >= 8 have this feature
|
||||
bool noDepLost = true;
|
||||
if (this->m_FileInfo.FileVersion >= 8) {
|
||||
// get size and resize
|
||||
CKDWORD depSize;
|
||||
parser->ReadAndMove(&depSize, sizeof(CKDWORD));
|
||||
this->m_PluginDep.resize(depSize);
|
||||
|
||||
CKDWORD guid_size;
|
||||
for (auto& dep : this->m_PluginDep) {
|
||||
// read category
|
||||
parser->ReadAndMove(&(dep.m_PluginCategory), sizeof(CK_PLUGIN_TYPE));
|
||||
// get size and resize
|
||||
parser->ReadAndMove(&guid_size, sizeof(CKDWORD));
|
||||
dep.m_Guids.resize(guid_size);
|
||||
dep.ValidGuids.resize(guid_size);
|
||||
// read data
|
||||
if (guid_size != 0) {
|
||||
parser->ReadAndMove(dep.m_Guids.data(), sizeof(CKGUID)* guid_size);
|
||||
}
|
||||
|
||||
// extra load flag
|
||||
if (EnumHelper::FlagEnumHas(this->m_Flags, CK_LOAD_FLAGS::CK_LOAD_CHECKDEPENDENCIES)) {
|
||||
for (size_t i = 0u; i < dep.m_Guids.size(); ++i) {
|
||||
// MARK: CKPluginManager::FindComponent
|
||||
bool plgEntryIsNull = true;
|
||||
if (plgEntryIsNull) {
|
||||
noDepLost = false;
|
||||
dep.ValidGuids[i] = false;
|
||||
} else {
|
||||
dep.ValidGuids[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ========== included file list read ==========
|
||||
// file ver >= 8 have this feature
|
||||
if (this->m_FileInfo.FileVersion >= 8) {
|
||||
// MARK: i don't knwo what is this!
|
||||
int32_t unknowIncludedFileFlag;
|
||||
parser->ReadAndMove(&unknowIncludedFileFlag, sizeof(int32_t));
|
||||
|
||||
if (unknowIncludedFileFlag > 0) {
|
||||
// read included file size and resize
|
||||
CKDWORD includedFileCount;
|
||||
parser->ReadAndMove(&includedFileCount, sizeof(CKDWORD));
|
||||
this->m_IncludedFiles.resize(includedFileCount);
|
||||
|
||||
unknowIncludedFileFlag -= 4;
|
||||
}
|
||||
|
||||
// backward pos
|
||||
parser->SetCursor(unknowIncludedFileFlag);
|
||||
}
|
||||
|
||||
// ========== read data ==========
|
||||
// restore old parser if needed
|
||||
if (parser != *ParserPtr) {
|
||||
delete parser;
|
||||
parser = *ParserPtr;
|
||||
parser->MoveCursor(this->m_FileInfo.Hdr1PackSize);
|
||||
}
|
||||
|
||||
// MARK: dword_2405F6BC, dword_2405F6B8 set
|
||||
|
||||
if (!(EnumHelper::FlagEnumHas(this->m_Flags, CK_LOAD_FLAGS::CK_LOAD_CHECKDEPENDENCIES) &&
|
||||
this->m_FileInfo.FileVersion < 8)) {
|
||||
// we have read all header. return result
|
||||
return noDepLost ? CKERROR::CKERR_OK : CKERROR::CKERR_PLUGINSMISSING;
|
||||
} // however, if we need check dep, and, we have not read dep list. continue read them.
|
||||
|
||||
return CKERROR::CKERR_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace LibCmo {
|
|||
|
||||
// write member data
|
||||
m_pMemoryMappedFileBase = m_hFileMapView;
|
||||
m_cbFile = static_cast<size_t>(m_dwFileSizeLow) | (static_cast<size_t>(m_dwFileSizeHigh) << 32);
|
||||
m_cbFile = static_cast<size_t>(static_cast<uint64_t>(m_dwFileSizeLow) | (static_cast<uint64_t>(m_dwFileSizeHigh) << 32));
|
||||
|
||||
#else
|
||||
#error NO IMPLEMENTATION FOR LINUX MMAP!
|
||||
|
@ -142,7 +142,7 @@ namespace LibCmo {
|
|||
|
||||
#pragma region CKFile Misc
|
||||
|
||||
CKFile::CKFile(const Utils::VirtoolsContext& cfg) :
|
||||
CKFile::CKFile(const Utils::VirtoolsEnvironment& cfg) :
|
||||
m_Parser(nullptr), m_MappedFile(nullptr),
|
||||
m_UserCfg(cfg) {
|
||||
;
|
||||
|
|
|
@ -67,6 +67,10 @@ namespace LibCmo {
|
|||
~CKBufferParser();
|
||||
|
||||
inline const void* GetPtr(void) { return (this->m_ReaderBegin + m_ReaderPos); }
|
||||
inline void ReadAndMove(void* data, size_t data_size) {
|
||||
memcpy(data, (this->m_ReaderBegin + m_ReaderPos), data_size);
|
||||
this->m_ReaderPos += data_size;
|
||||
}
|
||||
inline size_t GetSize(void) { return this->m_ReaderSize; }
|
||||
inline void MoveCursor(size_t off) { this->m_ReaderPos += off; }
|
||||
inline void SetCursor(size_t off) { this->m_ReaderPos = off; }
|
||||
|
@ -104,14 +108,14 @@ namespace LibCmo {
|
|||
};
|
||||
|
||||
struct CKFilePluginDependencies {
|
||||
CKDWORD m_PluginCategory;
|
||||
CK_PLUGIN_TYPE m_PluginCategory;
|
||||
XArray<CKGUID> m_Guids;
|
||||
XBitArray ValidGuids;
|
||||
};
|
||||
|
||||
class CKFile {
|
||||
public:
|
||||
CKFile(const Utils::VirtoolsContext& cfg);
|
||||
CKFile(const Utils::VirtoolsEnvironment& cfg);
|
||||
CKFile(const CKFile&) = delete;
|
||||
CKFile& operator=(const CKFile&) = delete;
|
||||
~CKFile();
|
||||
|
@ -141,7 +145,7 @@ namespace LibCmo {
|
|||
bool m_ReadFileDataDone;
|
||||
|
||||
private:
|
||||
Utils::VirtoolsContext m_UserCfg;
|
||||
Utils::VirtoolsEnvironment m_UserCfg;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@
|
|||
namespace LibCmo {
|
||||
namespace Utils {
|
||||
|
||||
struct VirtoolsContext {
|
||||
struct VirtoolsEnvironment {
|
||||
std::string NameEncoding;
|
||||
|
||||
std::string TempFolder;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
import VTReader, VTStruct, VTConstants
|
||||
|
||||
ckFile = VTStruct.CKFile()
|
||||
VTReader.CKFileReader.Load(ckFile, "D:\\libcmo21\\PyCmo\\Language.old.nmo", VTConstants.CK_LOAD_FLAGS(VTConstants.CK_LOAD_FLAGS.CK_LOAD_DEFAULT))
|
||||
print(ckFile)
|
||||
print(str(ckFile.m_FileObjects))
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>adc519e8-5f1b-427d-8e5c-1fabcb6147fb</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>PyCmo.py</StartupFile>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<Name>PyCmo</Name>
|
||||
<RootNamespace>PyCmo</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PyCmo.py" />
|
||||
<Compile Include="PyCmoMisc.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="VTConstants.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="VTReader.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="VTStruct.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="VTUtils.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
|
||||
<!-- Uncomment the CoreCompile target to enable the Build command in
|
||||
Visual Studio and specify your pre- and post-build commands in
|
||||
the BeforeBuild and AfterBuild targets below. -->
|
||||
<!--<Target Name="CoreCompile" />-->
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
</Project>
|
|
@ -1,46 +0,0 @@
|
|||
import functools, inspect
|
||||
|
||||
def OutputSizeHumanReadable(storage_size: int):
|
||||
probe = storage_size
|
||||
|
||||
# check Bytes
|
||||
if (probe >> 10) == 0:
|
||||
return f"{storage_size:d}Bytes"
|
||||
probe >>= 10
|
||||
|
||||
# check KiB
|
||||
if (probe >> 10) == 0:
|
||||
return f"{(storage_size / (1 << 10)):.2f}KiB"
|
||||
probe >>= 10
|
||||
|
||||
# check MiB
|
||||
if (probe >> 10) == 0:
|
||||
return f"{(storage_size / (1 << 20)):.2f}MiB"
|
||||
probe >>= 10
|
||||
|
||||
# otherwise GiB
|
||||
return f"{(storage_size / (1 << 30)):.2f}GiB"
|
||||
|
||||
def BcdCodeToDecCode(bcd_num: int):
|
||||
result = 0
|
||||
pow = 1
|
||||
|
||||
while bcd_num != 0:
|
||||
result += (bcd_num & 0xf) * pow
|
||||
bcd_num >>= 4
|
||||
pow *= 10
|
||||
|
||||
return result
|
||||
|
||||
def ClsMethodRegister(cls):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
return func(self, *args, **kwargs)
|
||||
if inspect.getattr_static(cls, func.__name__, None):
|
||||
msg = 'Error. method name REPEAT, {} has exist'.format(func.__name__)
|
||||
raise NameError(msg)
|
||||
else:
|
||||
setattr(cls, func.__name__, wrapper)
|
||||
return func
|
||||
return decorator
|
|
@ -1,350 +0,0 @@
|
|||
import enum
|
||||
|
||||
class CKEnumItem(object):
|
||||
def __init__(self, name: str, value: int):
|
||||
self.name: str = name
|
||||
self.value: int = value
|
||||
|
||||
class CKEnum(object):
|
||||
def __init__(self, val: int):
|
||||
self.m_Value: int = val
|
||||
|
||||
self.__ItemsList = (
|
||||
CKEnumItem(attr, getattr(self, attr))
|
||||
for attr in dir(self) if not attr.startswith("__") and not callable(getattr(self, attr))
|
||||
)
|
||||
|
||||
def Set(self, data: int):
|
||||
self.m_Value = data
|
||||
|
||||
def __iter__(self):
|
||||
return self.__ItemsList
|
||||
|
||||
def __repr__(self):
|
||||
for i in self:
|
||||
if i.value == self.m_Value:
|
||||
return '<' + i.name + '>'
|
||||
|
||||
return "<[None]: {:d}>".format(self.m_Value)
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
class CKFlagEnum(CKEnum):
|
||||
def Add(self, data: int):
|
||||
self.m_Value = self.m_Value | data
|
||||
|
||||
def __contains__(self, probe):
|
||||
if isinstance(probe, int):
|
||||
return bool(self.m_Value & probe)
|
||||
if isinstance(probe, CKFlagEnum):
|
||||
return bool(self.m_Value & probe.m_Value)
|
||||
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
pending = []
|
||||
|
||||
for i in self:
|
||||
# if it have exactly same entry, return directly
|
||||
if i.value == self.m_Value:
|
||||
return '<' + i.name + '>'
|
||||
|
||||
# check exist
|
||||
if bool(self.m_Value & i.value):
|
||||
pending.append(i.name)
|
||||
|
||||
result = ', '.join(pending)
|
||||
return ('<' + result + '>') if len(result) != 0 else "<[None]: {:d}>".format(self.m_Value)
|
||||
|
||||
class CK_FILE_WRITEMODE(CKFlagEnum):
|
||||
CKFILE_UNCOMPRESSED =0 # Save data uncompressed
|
||||
CKFILE_CHUNKCOMPRESSED_OLD =1 # Obsolete
|
||||
CKFILE_EXTERNALTEXTURES_OLD=2 # Obsolete : use CKContext::SetGlobalImagesSaveOptions instead.
|
||||
CKFILE_FORVIEWER =4 # Don't save Interface Data within the file, the level won't be editable anymore in the interface
|
||||
CKFILE_WHOLECOMPRESSED =8 # Compress the whole file
|
||||
|
||||
class CK_LOAD_FLAGS(CKFlagEnum):
|
||||
CK_LOAD_ANIMATION =1<<0 # Load animations
|
||||
CK_LOAD_GEOMETRY =1<<1 # Load geometry.
|
||||
CK_LOAD_DEFAULT =CK_LOAD_GEOMETRY|CK_LOAD_ANIMATION # Load animations & geometry
|
||||
CK_LOAD_ASCHARACTER =1<<2 # Load all the objects and create a character that contains them all .
|
||||
CK_LOAD_DODIALOG =1<<3 # Check object name unicity and warns the user with a dialog box when duplicate names are found.
|
||||
CK_LOAD_AS_DYNAMIC_OBJECT =1<<4 # Objects loaded from this file may be deleted at run-time or are temporary
|
||||
CK_LOAD_AUTOMATICMODE =1<<5 # Check object name unicity and automatically rename or replace according to the options specified in CKContext::SetAutomaticLoadMode
|
||||
CK_LOAD_CHECKDUPLICATES =1<<6 # Check object name unicity (The list of duplicates is stored in the CKFile class after a OpenFile call
|
||||
CK_LOAD_CHECKDEPENDENCIES =1<<7 # Check if every plugins needed are availables
|
||||
CK_LOAD_ONLYBEHAVIORS =1<<8 #
|
||||
|
||||
class CK_FO_OPTIONS(CKEnum):
|
||||
CK_FO_DEFAULT = 0
|
||||
CK_FO_RENAMEOBJECT = 1
|
||||
CK_FO_REPLACEOBJECT = 2
|
||||
CK_FO_DONTLOADOBJECT = 3
|
||||
|
||||
CK_ID = int
|
||||
|
||||
ClassHierarchy = {
|
||||
1: ("CKCID_OBJECT", ),
|
||||
2: ("CKCID_OBJECT", "CKCID_PARAMETERIN", ),
|
||||
4: ("CKCID_OBJECT", "CKCID_PARAMETEROPERATION", ),
|
||||
5: ("CKCID_OBJECT", "CKCID_STATE", ),
|
||||
6: ("CKCID_OBJECT", "CKCID_BEHAVIORLINK", ),
|
||||
8: ("CKCID_OBJECT", "CKCID_BEHAVIOR", ),
|
||||
9: ("CKCID_OBJECT", "CKCID_BEHAVIORIO", ),
|
||||
12: ("CKCID_OBJECT", "CKCID_RENDERCONTEXT", ),
|
||||
13: ("CKCID_OBJECT", "CKCID_KINEMATICCHAIN", ),
|
||||
11: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", ),
|
||||
15: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_OBJECTANIMATION", ),
|
||||
16: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_ANIMATION", ),
|
||||
18: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_ANIMATION", "CKCID_KEYEDANIMATION", ),
|
||||
19: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", ),
|
||||
52: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_DATAARRAY", ),
|
||||
10: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_SCENE", ),
|
||||
21: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_LEVEL", ),
|
||||
22: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_PLACE", ),
|
||||
23: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_GROUP", ),
|
||||
24: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_SOUND", ),
|
||||
25: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_SOUND", "CKCID_WAVESOUND", ),
|
||||
26: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_SOUND", "CKCID_MIDISOUND", ),
|
||||
30: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_MATERIAL", ),
|
||||
31: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_TEXTURE", ),
|
||||
32: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_MESH", ),
|
||||
53: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_MESH", "CKCID_PATCHMESH", ),
|
||||
47: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_RENDEROBJECT", ),
|
||||
27: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_RENDEROBJECT", "CKCID_2DENTITY", ),
|
||||
28: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_RENDEROBJECT", "CKCID_2DENTITY", "CKCID_SPRITE", ),
|
||||
29: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_RENDEROBJECT", "CKCID_2DENTITY", "CKCID_SPRITETEXT", ),
|
||||
33: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", ),
|
||||
50: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_GRID", ),
|
||||
36: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_CURVEPOINT", ),
|
||||
37: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_SPRITE3D", ),
|
||||
43: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_CURVE", ),
|
||||
34: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_CAMERA", ),
|
||||
35: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_CAMERA", "CKCID_TARGETCAMERA", ),
|
||||
38: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_LIGHT", ),
|
||||
39: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_LIGHT", "CKCID_TARGETLIGHT", ),
|
||||
40: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_CHARACTER", ),
|
||||
41: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_3DOBJECT", ),
|
||||
42: ("CKCID_OBJECT", "CKCID_SCENEOBJECT", "CKCID_BEOBJECT", "CKCID_3DENTITY", "CKCID_3DOBJECT", "CKCID_BODYPART", ),
|
||||
46: ("CKCID_OBJECT", "CKCID_PARAMETER", ),
|
||||
45: ("CKCID_OBJECT", "CKCID_PARAMETER", "CKCID_PARAMETERLOCAL", ),
|
||||
55: ("CKCID_OBJECT", "CKCID_PARAMETER", "CKCID_PARAMETERLOCAL", "CKCID_PARAMETERVARIABLE", ),
|
||||
3: ("CKCID_OBJECT", "CKCID_PARAMETER", "CKCID_PARAMETEROUT", ),
|
||||
48: ("CKCID_OBJECT", "CKCID_INTERFACEOBJECTMANAGER", ),
|
||||
49: ("CKCID_OBJECT", "CKCID_CRITICALSECTION", ),
|
||||
51: ("CKCID_OBJECT", "CKCID_LAYER", ),
|
||||
54: ("CKCID_OBJECT", "CKCID_PROGRESSIVEMESH", ),
|
||||
20: ("CKCID_OBJECT", "CKCID_SYNCHRO", ),
|
||||
80: ("CKCID_OBJECTARRAY", ),
|
||||
81: ("CKCID_SCENEOBJECTDESC", ),
|
||||
82: ("CKCID_ATTRIBUTEMANAGER", ),
|
||||
83: ("CKCID_MESSAGEMANAGER", ),
|
||||
84: ("CKCID_COLLISIONMANAGER", ),
|
||||
85: ("CKCID_OBJECTMANAGER", ),
|
||||
86: ("CKCID_FLOORMANAGER", ),
|
||||
87: ("CKCID_RENDERMANAGER", ),
|
||||
88: ("CKCID_BEHAVIORMANAGER", ),
|
||||
89: ("CKCID_INPUTMANAGER", ),
|
||||
90: ("CKCID_PARAMETERMANAGER", ),
|
||||
91: ("CKCID_GRIDMANAGER", ),
|
||||
92: ("CKCID_SOUNDMANAGER", ),
|
||||
93: ("CKCID_TIMEMANAGER", ),
|
||||
-1: ("CKCID_CUIKBEHDATA", ),
|
||||
56: ("CKCID_MAXCLASSID", ),
|
||||
128: ("CKCID_MAXMAXCLASSID", ),
|
||||
}
|
||||
class CK_CLASSID(CKEnum):
|
||||
CKCID_OBJECT = 1
|
||||
CKCID_PARAMETERIN = 2
|
||||
CKCID_PARAMETEROPERATION = 4
|
||||
CKCID_STATE = 5
|
||||
CKCID_BEHAVIORLINK = 6
|
||||
CKCID_BEHAVIOR = 8
|
||||
CKCID_BEHAVIORIO = 9
|
||||
CKCID_RENDERCONTEXT = 12
|
||||
CKCID_KINEMATICCHAIN = 13
|
||||
CKCID_SCENEOBJECT = 11
|
||||
CKCID_OBJECTANIMATION = 15
|
||||
CKCID_ANIMATION = 16
|
||||
CKCID_KEYEDANIMATION = 18
|
||||
CKCID_BEOBJECT = 19
|
||||
CKCID_DATAARRAY = 52
|
||||
CKCID_SCENE = 10
|
||||
CKCID_LEVEL = 21
|
||||
CKCID_PLACE = 22
|
||||
CKCID_GROUP = 23
|
||||
CKCID_SOUND = 24
|
||||
CKCID_WAVESOUND = 25
|
||||
CKCID_MIDISOUND = 26
|
||||
CKCID_MATERIAL = 30
|
||||
CKCID_TEXTURE = 31
|
||||
CKCID_MESH = 32
|
||||
CKCID_PATCHMESH = 53
|
||||
CKCID_RENDEROBJECT = 47
|
||||
CKCID_2DENTITY = 27
|
||||
CKCID_SPRITE = 28
|
||||
CKCID_SPRITETEXT = 29
|
||||
CKCID_3DENTITY = 33
|
||||
CKCID_GRID = 50
|
||||
CKCID_CURVEPOINT = 36
|
||||
CKCID_SPRITE3D = 37
|
||||
CKCID_CURVE = 43
|
||||
CKCID_CAMERA = 34
|
||||
CKCID_TARGETCAMERA = 35
|
||||
CKCID_LIGHT = 38
|
||||
CKCID_TARGETLIGHT = 39
|
||||
CKCID_CHARACTER = 40
|
||||
CKCID_3DOBJECT = 41
|
||||
CKCID_BODYPART = 42
|
||||
CKCID_PARAMETER = 46
|
||||
CKCID_PARAMETERLOCAL = 45
|
||||
CKCID_PARAMETERVARIABLE = 55
|
||||
CKCID_PARAMETEROUT = 3
|
||||
CKCID_INTERFACEOBJECTMANAGER = 48
|
||||
CKCID_CRITICALSECTION = 49
|
||||
CKCID_LAYER = 51
|
||||
CKCID_PROGRESSIVEMESH = 54
|
||||
CKCID_SYNCHRO = 20
|
||||
|
||||
CKCID_OBJECTARRAY = 80
|
||||
CKCID_SCENEOBJECTDESC = 81
|
||||
CKCID_ATTRIBUTEMANAGER = 82
|
||||
CKCID_MESSAGEMANAGER = 83
|
||||
CKCID_COLLISIONMANAGER = 84
|
||||
CKCID_OBJECTMANAGER = 85
|
||||
CKCID_FLOORMANAGER = 86
|
||||
CKCID_RENDERMANAGER = 87
|
||||
CKCID_BEHAVIORMANAGER = 88
|
||||
CKCID_INPUTMANAGER = 89
|
||||
CKCID_PARAMETERMANAGER = 90
|
||||
CKCID_GRIDMANAGER = 91
|
||||
CKCID_SOUNDMANAGER = 92
|
||||
CKCID_TIMEMANAGER = 93
|
||||
CKCID_CUIKBEHDATA = -1
|
||||
|
||||
CKCID_MAXCLASSID = 56
|
||||
CKCID_MAXMAXCLASSID = 128
|
||||
|
||||
def __repr__(self):
|
||||
hierarchy = ClassHierarchy.get(self.m_Value, None)
|
||||
if hierarchy is None:
|
||||
return "[Undefined] {:d}".format(self.m_Value)
|
||||
return "{} ({})".format(
|
||||
hierarchy[-1],
|
||||
' -> '.join(hierarchy)
|
||||
)
|
||||
def __str__(self):
|
||||
hierarchy = ClassHierarchy.get(self.m_Value, None)
|
||||
if hierarchy is None:
|
||||
return "[Undefined] {:d}".format(self.m_Value)
|
||||
return hierarchy[-1]
|
||||
|
||||
|
||||
ErrorDescription = {
|
||||
0: "Operation successful",
|
||||
-1: "One of the parameter passed to the function was invalid",
|
||||
-2: "One of the parameter passed to the function was invalid",
|
||||
-3: "The parameter size was invalid",
|
||||
-4: "The operation type didn't exist",
|
||||
-5: "The function used to execute the operation is not yet implemented",
|
||||
-6: "There was not enough memory to perform the action",
|
||||
-7: "The function is not yet implemented",
|
||||
-11: "There was an attempt to remove something not present",
|
||||
-13: "There is no level currently created",
|
||||
-14: "There is no level currently created",
|
||||
-16: "The notification message was not used",
|
||||
-17: "Attempt to add an item that was already present",
|
||||
-18: "the render context is not valid",
|
||||
-19: "the render context is not activated for rendering",
|
||||
-20: "there was no plugins to load this kind of file",
|
||||
-21: "there was no plugins to save this kind of file",
|
||||
-22: "attempt to load an invalid file",
|
||||
-23: "attempt to load with an invalid plugin",
|
||||
-24: "attempt use an object that wasnt initialized",
|
||||
-25: "attempt use a message type that wasn't registred",
|
||||
-29: "No dll file found in the parse directory",
|
||||
-30: "this dll has already been registred",
|
||||
-31: "this dll does not contain information to create the prototype",
|
||||
-34: "Invalid Object (attempt to Get an object from an invalid ID)",
|
||||
-35: "Invalid window was provided as console window",
|
||||
-36: "Invalid kinematic chain ( end and start effector may not be part of the same hierarchy )",
|
||||
-37: "Keyboard not attached or not working properly",
|
||||
-38: "Mouse not attached or not working properly",
|
||||
-39: "Joystick not attached or not working properly",
|
||||
-40: "Try to link imcompatible Parameters",
|
||||
-44: "There is no render engine dll",
|
||||
-45: "There is no current level (use CKSetCurrentLevel )",
|
||||
-46: "Sound Management has been disabled",
|
||||
-47: "DirectInput Management has been disabled",
|
||||
-48: "Guid is already in use or invalid",
|
||||
-49: "There was no more free space on disk when trying to save a file",
|
||||
-50: "Impossible to write to file (write-protection ?)",
|
||||
-51: "The behavior cannnot be added to this entity",
|
||||
-52: "The behavior cannnot be added to this entity",
|
||||
-53: "A manager was registered more than once",
|
||||
-54: "CKprocess or TimeManager process while CK is paused will fail",
|
||||
-55: "Some plugins were missing whileloading a file",
|
||||
-56: "Virtools version too old to load this file",
|
||||
-57: "CRC Error while loading file",
|
||||
-58: "A Render context is already in Fullscreen Mode",
|
||||
-59: "Operation was cancelled by user",
|
||||
-121: "there were no animation key at the given index",
|
||||
-122: "attemp to acces an animation key with an invalid index",
|
||||
-123: "the animation is invalid (no entity associated or zero length)",
|
||||
}
|
||||
class CKERROR(CKEnum):
|
||||
CKERR_OK = 0
|
||||
CKERR_INVALIDPARAMETER = -1
|
||||
CKERR_INVALIDPARAMETERTYPE = -2
|
||||
CKERR_INVALIDSIZE = -3
|
||||
CKERR_INVALIDOPERATION = -4
|
||||
CKERR_OPERATIONNOTIMPLEMENTED = -5
|
||||
CKERR_OUTOFMEMORY = -6
|
||||
CKERR_NOTIMPLEMENTED = -7
|
||||
CKERR_NOTFOUND = -11
|
||||
CKERR_NOLEVEL = -13
|
||||
CKERR_CANCREATERENDERCONTEXT = -14
|
||||
CKERR_NOTIFICATIONNOTHANDLED = -16
|
||||
CKERR_ALREADYPRESENT = -17
|
||||
CKERR_INVALIDRENDERCONTEXT = -18
|
||||
CKERR_RENDERCONTEXTINACTIVE = -19
|
||||
CKERR_NOLOADPLUGINS = -20
|
||||
CKERR_NOSAVEPLUGINS = -21
|
||||
CKERR_INVALIDFILE = -22
|
||||
CKERR_INVALIDPLUGIN = -23
|
||||
CKERR_NOTINITIALIZED = -24
|
||||
CKERR_INVALIDMESSAGE = -25
|
||||
CKERR_NODLLFOUND = -29
|
||||
CKERR_ALREADYREGISTREDDLL = -30
|
||||
CKERR_INVALIDDLL = -31
|
||||
CKERR_INVALIDOBJECT = -34
|
||||
CKERR_INVALIDCONDSOLEWINDOW = -35
|
||||
CKERR_INVALIDKINEMATICCHAIN = -36
|
||||
CKERR_NOKEYBOARD = -37
|
||||
CKERR_NOMOUSE = -38
|
||||
CKERR_NOJOYSTICK = -39
|
||||
CKERR_INCOMPATIBLEPARAMETERS = -40
|
||||
CKERR_NORENDERENGINE = -44
|
||||
CKERR_NOCURRENTLEVEL = -45
|
||||
CKERR_SOUNDDISABLED = -46
|
||||
CKERR_DINPUTDISABLED = -47
|
||||
CKERR_INVALIDGUID = -48
|
||||
CKERR_NOTENOUGHDISKPLACE = -49
|
||||
CKERR_CANTWRITETOFILE = -50
|
||||
CKERR_BEHAVIORADDDENIEDBYCB = -51
|
||||
CKERR_INCOMPATIBLECLASSID = -52
|
||||
CKERR_MANAGERALREADYEXISTS = -53
|
||||
CKERR_PAUSED = -54
|
||||
CKERR_PLUGINSMISSING = -55
|
||||
CKERR_OBSOLETEVIRTOOLS = -56
|
||||
CKERR_FILECRCERROR = -57
|
||||
CKERR_ALREADYFULLSCREEN = -58
|
||||
CKERR_CANCELLED = -59
|
||||
CKERR_NOANIMATIONKEY = -121
|
||||
CKERR_INVALIDINDEX = -122
|
||||
CKERR_INVALIDANIMATION = -123
|
||||
|
||||
def __repr__(self):
|
||||
return ErrorDescription.get(self.m_Value, "[Undefined] {:d}".format(self.m_Value))
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
import VTStruct, VTUtils, VTConstants
|
||||
import PyCmoMisc
|
||||
import struct, io, datetime, zlib
|
||||
import typing
|
||||
|
||||
g_Header1Packer = struct.Struct('<iiIiiiii')
|
||||
g_Header2Packer = struct.Struct('<iiiiiiii')
|
||||
g_FileObjectPacker = struct.Struct('<iiii')
|
||||
|
||||
class CKFileReader():
|
||||
|
||||
@staticmethod
|
||||
def ReadFileHeaders(self: VTStruct.CKFile) -> VTConstants.CKERROR:
|
||||
if self.m_Parser is None:
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_INVALIDPARAMETER)
|
||||
parser = self.m_Parser
|
||||
|
||||
# ========== magic words ==========
|
||||
magic_words = parser.GetReader()[0:4]
|
||||
if magic_words != b'Nemo':
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_INVALIDFILE)
|
||||
|
||||
# ========== read header1 ==========
|
||||
if parser.GetSize() < 0x20:
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_INVALIDFILE)
|
||||
header1 = list(g_Header1Packer.unpack(parser.GetReader().read(8 * 4)))
|
||||
|
||||
# check header1
|
||||
if header1[5]: # i don't know what is this fields stands for
|
||||
header1 = list(0 for _ in range(8))
|
||||
|
||||
# virtools is too old to open this file. file is too new.
|
||||
if header1[4] > 9: # file version
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_OBSOLETEVIRTOOLS)
|
||||
|
||||
# ========== read header2 ==========
|
||||
# file ver < 5 do not have second header
|
||||
if header1[4] < 5:
|
||||
header2 = list(0 for _ in range(8))
|
||||
else:
|
||||
if parser.GetSize() < 0x40:
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_INVALIDFILE)
|
||||
|
||||
header2 = g_Header2Packer.unpack(parser.GetReader().read(8 * 4))
|
||||
|
||||
# forcely reset too big product ver
|
||||
if header2[5] >= 12: # product version
|
||||
header2[5] = 0
|
||||
header2[6] = 0x1010000 # product build
|
||||
|
||||
# ========== assign value ==========
|
||||
self.m_FileInfo.ProductVersion = header2[5]
|
||||
self.m_FileInfo.ProductBuild = header2[6]
|
||||
self.m_FileInfo.FileWriteMode.m_Value = header1[6]
|
||||
self.m_FileInfo.CKVersion = header1[3]
|
||||
self.m_FileInfo.FileVersion = header1[4]
|
||||
self.m_FileInfo.FileSize = self.m_Parser.GetSize()
|
||||
self.m_FileInfo.ManagerCount = header2[2]
|
||||
self.m_FileInfo.ObjectCount = header2[3]
|
||||
self.m_FileInfo.MaxIDSaved = header2[4]
|
||||
self.m_FileInfo.Hdr1PackSize = header1[7]
|
||||
self.m_FileInfo.Hdr1UnPackSize = header2[7]
|
||||
self.m_FileInfo.DataPackSize = header2[0]
|
||||
self.m_FileInfo.DataUnPackSize = header2[1]
|
||||
self.m_FileInfo.Crc = header1[2]
|
||||
|
||||
# ========== crc and body unpacker ==========
|
||||
# file version greater than 8 have crc feature and compression feature
|
||||
if self.m_FileInfo.FileVersion >= 8:
|
||||
# reset crc field of header
|
||||
header1[2] = 0
|
||||
|
||||
# compute crc
|
||||
gotten_crc = zlib.adler32(g_Header1Packer.pack(*header1), 0)
|
||||
|
||||
reader = parser.GetReader()
|
||||
pos_cache = reader.tell()
|
||||
reader.seek(8 * 4, io.SEEK_SET)
|
||||
gotten_crc = zlib.adler32(reader.read(
|
||||
8 * 4 + self.m_FileInfo.Hdr1PackSize + self.m_FileInfo.DataPackSize
|
||||
), gotten_crc)
|
||||
reader.seek(pos_cache, io.SEEK_SET)
|
||||
|
||||
# compare crc
|
||||
if gotten_crc != self.m_FileInfo.Crc:
|
||||
return VTConstants.CKERROR(VTConstants.CKERROR.CKERR_FILECRCERROR)
|
||||
|
||||
|
||||
# compare size to decide wheher use compress feature
|
||||
if self.m_FileInfo.Hdr1UnPackSize != self.m_FileInfo.Hdr1PackSize:
|
||||
# create a new parser for following analyze
|
||||
parser = VTUtils.SmallZlibFileReader(parser, self.m_FileInfo.Hdr1PackSize, self.m_FileInfo.Hdr1UnPackSize)
|
||||
|
||||
# ========== object list read ==========
|
||||
# file ver >= 7 have this features
|
||||
if self.m_FileInfo.FileVersion >= 7:
|
||||
self.m_SaveIDMax = self.m_FileInfo.MaxIDSaved
|
||||
# resize
|
||||
self.m_FileObjects = list(VTStruct.CKFileObject() for _ in range(self.m_FileInfo.ObjectCount))
|
||||
|
||||
# read data
|
||||
reader = parser.GetReader()
|
||||
for fileobj in self.m_FileObjects:
|
||||
# set useless fields
|
||||
fileobj.ObjPtr = None
|
||||
fileobj.Name = None
|
||||
fileobj.Data = None
|
||||
|
||||
# read basic fields
|
||||
(fileobj.Object, cid, fileobj.FileIndex, namelen) = g_FileObjectPacker.unpack(
|
||||
reader.read(g_FileObjectPacker.size)
|
||||
)
|
||||
fileobj.ObjectCid.Set(cid)
|
||||
|
||||
# read name
|
||||
if namelen > 0:
|
||||
fileobj.Name = reader.read(namelen).decode('utf-8', errors = 'ignore')
|
||||
|
||||
# ========== dep list read ==========
|
||||
# only file ver >= 8, this sector is existed
|
||||
if self.m_FileInfo.FileVersion >= 8:
|
||||
pass
|
||||
|
||||
|
||||
@staticmethod
|
||||
def Load(self: VTStruct.CKFile, filename: str, load_flags: VTConstants.CK_LOAD_FLAGS) -> VTConstants.CKERROR:
|
||||
# todo: clear first
|
||||
|
||||
# setup basic fields
|
||||
self.m_FileName = filename
|
||||
self.m_Flags = load_flags
|
||||
|
||||
# setup parser
|
||||
self.m_Parser = VTUtils.RawFileReader(filename)
|
||||
|
||||
# read header first
|
||||
err = CKFileReader.ReadFileHeaders(self)
|
||||
|
||||
# todo: finish other read
|
||||
|
||||
return err
|
|
@ -1,116 +0,0 @@
|
|||
import VTConstants, VTUtils
|
||||
import PyCmoMisc
|
||||
import datetime
|
||||
|
||||
class CKGUID():
|
||||
def __init__(self):
|
||||
self.D1: int = 0
|
||||
self.D2: int = 0
|
||||
def __init__(self, d1: int, d2: int):
|
||||
self.D1: int = d1
|
||||
self.D2: int = d2
|
||||
def __repr__(self):
|
||||
return f"<CKGUID: 0x{self.D1:08X}, 0x{self.D2:08X}"
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
class CKFileInfo:
|
||||
def __init__(self):
|
||||
self.ProductVersion: int = 0
|
||||
self.ProductBuild: int = 0
|
||||
|
||||
self.FileWriteMode: VTConstants.CK_FILE_WRITEMODE = VTConstants.CK_FILE_WRITEMODE(VTConstants.CK_FILE_WRITEMODE.CKFILE_WHOLECOMPRESSED)
|
||||
|
||||
self.FileVersion: int = 0
|
||||
self.CKVersion: int = 0
|
||||
|
||||
self.FileSize: int = 0
|
||||
self.ObjectCount: int = 0
|
||||
self.ManagerCount: int = 0
|
||||
self.MaxIDSaved: int = 0
|
||||
|
||||
self.Crc: int = 0
|
||||
|
||||
self.Hdr1PackSize: int = 0
|
||||
self.Hdr1UnPackSize: int = 0
|
||||
self.DataPackSize: int = 0
|
||||
self.DataUnPackSize: int = 0
|
||||
|
||||
def GetProductBuildTuple(self) -> tuple[int]:
|
||||
return (
|
||||
(self.ProductBuild >> 24) & 0xff,
|
||||
(self.ProductBuild >> 16) & 0xff,
|
||||
(self.ProductBuild >> 8) & 0xff,
|
||||
self.ProductBuild & 0xff
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"""<CKFile:
|
||||
Version (File / CK): {self.FileVersion:d} / 0x{self.CKVersion:08X}
|
||||
Product (Version / Build): {self.ProductVersion:d} / {'.0'.join(map(lambda x: str(x), self.GetProductBuildTuple()))}
|
||||
Save Flags: {self.FileWriteMode}
|
||||
File Size: {PyCmoMisc.OutputSizeHumanReadable(self.FileSize)}
|
||||
Crc: 0x{self.Crc:08X}
|
||||
|
||||
Hdr1 (Pack / Unpack): {PyCmoMisc.OutputSizeHumanReadable(self.Hdr1PackSize)} / {PyCmoMisc.OutputSizeHumanReadable(self.Hdr1UnPackSize)}
|
||||
Data (Pack / Unpack): {PyCmoMisc.OutputSizeHumanReadable(self.DataPackSize)} / {PyCmoMisc.OutputSizeHumanReadable(self.DataUnPackSize)}
|
||||
|
||||
Manager Count: {self.ManagerCount:d}
|
||||
Object Count: {self.ObjectCount:d}
|
||||
Max ID Saved: {self.MaxIDSaved:d}
|
||||
>"""
|
||||
def __str__(self) -> str:
|
||||
return self.__repr__()
|
||||
|
||||
class CKFileObject():
|
||||
def __init__(self):
|
||||
self.Object: VTConstants.CK_ID = 0
|
||||
self.CreatedObject: VTConstants.CK_ID = 0
|
||||
self.ObjectCid: VTConstants.CK_CLASSID = VTConstants.CK_CLASSID(VTConstants.CK_CLASSID.CKCID_OBJECT)
|
||||
self.ObjPtr = None
|
||||
self.Name: str = None
|
||||
self.Data = None
|
||||
self.PostPackSize: int = 0
|
||||
self.PrePackSize: int = 0
|
||||
self.Options: VTConstants.CK_FO_OPTIONS = VTConstants.CK_FO_OPTIONS(VTConstants.CK_FO_OPTIONS.CK_FO_DEFAULT)
|
||||
self.FileIndex: int = 0
|
||||
self.SaveFlags: VTConstants.CK_FILE_WRITEMODE = VTConstants.CK_FILE_WRITEMODE(0)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<{self.Name if self.Name else "[Anonymous]"}: {self.ObjectCid}>'
|
||||
def __str__(self) -> str:
|
||||
return self.__repr__()
|
||||
|
||||
class CKFilePluginDependencies():
|
||||
def __init__(self):
|
||||
self.m_PluginCategory: int = 0
|
||||
self.m_Guids: list[CKGUID] = []
|
||||
self.ValidGuids: list[bool] = []
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return repr(self.m_Guids)
|
||||
def __str__(self) -> str:
|
||||
return self.__repr__()
|
||||
|
||||
class CKFile(object):
|
||||
def __init__(self):
|
||||
self.m_SaveIDMax: int = 0
|
||||
self.m_FileObjects: list[CKFileObject] = []
|
||||
self.m_ManagersData = []
|
||||
self.m_PluginDep: list[CKFilePluginDependencies] = []
|
||||
self.m_IndexByClassId: list[list[int]] = []
|
||||
self.m_IncludedFiles: list[str] = []
|
||||
|
||||
self.m_FileInfo: CKFileInfo = CKFileInfo()
|
||||
|
||||
self.m_Flags: VTConstants.CK_LOAD_FLAGS = VTConstants.CK_LOAD_FLAGS(VTConstants.CK_LOAD_FLAGS.CK_LOAD_DEFAULT)
|
||||
self.m_FileName: str = ''
|
||||
self.m_Parser: VTUtils.UniversalFileReader = None
|
||||
|
||||
self.m_ReadFileDataDone: bool = False
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return repr(self.m_FileInfo)
|
||||
def __str__(self) -> str:
|
||||
return self.__repr__()
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
import PyCmoMisc
|
||||
import zlib, io, mmap, os
|
||||
import typing
|
||||
|
||||
class RawFileReader():
|
||||
def __init__(self, filename: str):
|
||||
self.__size: int = os.path.getsize(filename)
|
||||
self.__fs = open(filename, 'rb')
|
||||
self.__mm: mmap.mmap = mmap.mmap(self.__fs.fileno(), 0, access = mmap.ACCESS_READ)
|
||||
|
||||
def __del__(self):
|
||||
self.__mm.close()
|
||||
del self.__mm
|
||||
self.__fs.close()
|
||||
del self.__fs
|
||||
|
||||
def GetSize(self) -> int:
|
||||
return self.__size
|
||||
|
||||
def GetReader(self) -> mmap.mmap:
|
||||
return self.__mm
|
||||
|
||||
class LargeZlibFileReader():
|
||||
def __init__(self, raw_reader: RawFileReader, comp_size: int, uncomp_size: int):
|
||||
# set size
|
||||
self.__size: int = uncomp_size
|
||||
|
||||
# create mmap
|
||||
self.__mm: mmap.mmap = mmap.mmap(-1, -1, access = mmap.ACCESS_WRITE)
|
||||
|
||||
# decompress data
|
||||
reader = raw_reader.GetReader()
|
||||
parser: zlib._Decompress = zlib.decompressobj()
|
||||
|
||||
buf = reader.read(io.DEFAULT_BUFFER_SIZE)
|
||||
while buf:
|
||||
self.__mm.write(parser.decompress(buf))
|
||||
buf = reader.read(io.DEFAULT_BUFFER_SIZE)
|
||||
self._mm.write(parser.flush())
|
||||
|
||||
def __del__(self):
|
||||
self.__mm.close()
|
||||
del self.__mm
|
||||
|
||||
def GetSize(self) -> int:
|
||||
return self.__size
|
||||
|
||||
def GetReader(self) -> mmap.mmap:
|
||||
return self.__mm
|
||||
|
||||
class SmallZlibFileReader():
|
||||
def __init__(self, raw_reader: RawFileReader, comp_size: int, uncomp_size: int):
|
||||
# set size
|
||||
self.__size: int = uncomp_size
|
||||
|
||||
# create io
|
||||
self.__ss: io.BytesIO = io.BytesIO()
|
||||
|
||||
# decompress data
|
||||
reader = raw_reader.GetReader()
|
||||
parser: zlib._Decompress = zlib.decompressobj()
|
||||
|
||||
buf = reader.read(io.DEFAULT_BUFFER_SIZE)
|
||||
while buf:
|
||||
self.__ss.write(parser.decompress(buf))
|
||||
buf = reader.read(io.DEFAULT_BUFFER_SIZE)
|
||||
self.__ss.write(parser.flush())
|
||||
|
||||
# reset cursor
|
||||
self.__ss.seek(0, io.SEEK_SET)
|
||||
|
||||
def __del__(self):
|
||||
del self.__ss
|
||||
|
||||
def GetSize(self) -> int:
|
||||
return self.__size
|
||||
|
||||
def GetReader(self) -> io.BytesIO:
|
||||
return self.__ss
|
||||
|
||||
UniversalFileReader = typing.Union[RawFileReader, LargeZlibFileReader, SmallZlibFileReader]
|
|
@ -36,6 +36,16 @@ namespace Unvirt {
|
|||
{ LibCmo::CK_FO_OPTIONS::CK_FO_REPLACEOBJECT, "CK_FO_REPLACEOBJECT" },
|
||||
{ LibCmo::CK_FO_OPTIONS::CK_FO_DONTLOADOBJECT, "CK_FO_DONTLOADOBJECT" }
|
||||
};
|
||||
const EnumDescPairArray<LibCmo::CK_PLUGIN_TYPE> CK_PLUGIN_TYPE{
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_BITMAP_READER, "CKPLUGIN_BITMAP_READER" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_SOUND_READER, "CKPLUGIN_SOUND_READER" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_MODEL_READER, "CKPLUGIN_MODEL_READER" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL, "CKPLUGIN_MANAGER_DLL" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_BEHAVIOR_DLL, "CKPLUGIN_BEHAVIOR_DLL" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_RENDERENGINE_DLL, "CKPLUGIN_RENDERENGINE_DLL" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_MOVIE_READER, "CKPLUGIN_MOVIE_READER" },
|
||||
{ LibCmo::CK_PLUGIN_TYPE::CKPLUGIN_EXTENSION_DLL, "CKPLUGIN_EXTENSION_DLL" }
|
||||
};
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace Unvirt {
|
|||
extern const EnumDescPairArray<LibCmo::CK_FILE_WRITEMODE> CK_FILE_WRITEMODE;
|
||||
extern const EnumDescPairArray<LibCmo::CK_LOAD_FLAGS> CK_LOAD_FLAGS;
|
||||
extern const EnumDescPairArray<LibCmo::CK_FO_OPTIONS> CK_FO_OPTIONS;
|
||||
extern const EnumDescPairArray<LibCmo::CK_PLUGIN_TYPE> CK_PLUGIN_TYPE;
|
||||
}
|
||||
|
||||
template<typename TEnum>
|
||||
|
|
|
@ -9,9 +9,9 @@ int main(int argc, char* argv[]) {
|
|||
Unvirt::TerminalHelper::EnsureTerminalColor();
|
||||
Unvirt::TerminalHelper::EnsureTerminalEncoding();
|
||||
|
||||
LibCmo::Utils::VirtoolsContext vtctx;
|
||||
LibCmo::Utils::VirtoolsEnvironment vtctx;
|
||||
LibCmo::CKFile vtfile(vtctx);
|
||||
vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
||||
LibCmo::CKERROR err = vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
||||
|
||||
Unvirt::StructFormatter::PrintCKFileInfo(vtfile.m_FileInfo);
|
||||
|
||||
|
|
14
libcmo21.sln
14
libcmo21.sln
|
@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31702.278
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PyCmo", "PyCmo\PyCmo.pyproj", "{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibCmo", "LibCmo\LibCmo.vcxproj", "{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Unvirt", "Unvirt\Unvirt.vcxproj", "{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}"
|
||||
|
@ -14,36 +12,24 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Unvirt", "Unvirt\Unvirt.vcx
|
|||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{ADC519E8-5F1B-427D-8E5C-1FABCB6147FB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Debug|x64.Build.0 = Debug|x64
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Debug|x86.Build.0 = Debug|Win32
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Release|x64.ActiveCfg = Release|x64
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Release|x64.Build.0 = Release|x64
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Release|x86.ActiveCfg = Release|Win32
|
||||
{70F64F8D-099C-4C21-B29C-0A8F1E22FB2E}.Release|x86.Build.0 = Release|Win32
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Debug|x64.Build.0 = Debug|x64
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Debug|x86.Build.0 = Debug|Win32
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Release|x64.ActiveCfg = Release|x64
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Release|x64.Build.0 = Release|x64
|
||||
{77E7ADB6-0D0C-4BA4-8DE7-A284C7F83941}.Release|x86.ActiveCfg = Release|Win32
|
||||
|
|
Loading…
Reference in New Issue
Block a user