diff --git a/.gitignore b/.gitignore index 06aa286..06d3c21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,18 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +# ============== My Options ============== # ignore generated Virtools.props SuperScriptMaterializer/Virtools.props +GPVirtoolsStatic/Virtools.props # ignore generated database *.db *.db-journal +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + # User-specific files *.rsuser *.suo @@ -362,4 +365,8 @@ healthchecksdb MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder -.ionide/ \ No newline at end of file +.ionide/ + +# ============== My Options ============== +# force adding debug profile for SuperScriptMaterializer +!SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.user diff --git a/GPVirtoolsStatic/Virtools.props b/GPVirtoolsStatic/Virtools.props deleted file mode 100644 index 79800c3..0000000 --- a/GPVirtoolsStatic/Virtools.props +++ /dev/null @@ -1,14 +0,0 @@ - - - - - D:\BallanceModLoader - - - - - - $(BML_REPOSITORY) - - - diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj index 2812a24..e3a0ec3 100644 --- a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj @@ -20,14 +20,14 @@ v142 Dynamic MultiByte - Application + DynamicLibrary false v142 true MultiByte Dynamic - Application + DynamicLibrary diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.user b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.user new file mode 100644 index 0000000..5d5a58c --- /dev/null +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.user @@ -0,0 +1,15 @@ + + + + $(VIRTOOLS_DEBUG_TARGET) + $(VIRTOOLS_DEBUG_COMMANDLINE) + $(VIRTOOLS_DEBUG_ROOT) + WindowsLocalDebugger + + + $(VIRTOOLS_DEBUG_TARGET) + $(VIRTOOLS_DEBUG_COMMANDLINE) + $(VIRTOOLS_DEBUG_ROOT) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index dabe66b..e264932 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -10,8 +10,7 @@ namespace SSMaterializer { script_bIn(), script_bOut(), script_bLink(), script_pIn(), script_pOut(), script_pLink(), script_eLink(), script_pLocal(), script_pTarget(), script_pAttr(), - msg(), - _array(), array_header(), array_cell(), + msg(), obj(), data() { param_manager = paramManager; } @@ -118,7 +117,7 @@ namespace SSMaterializer { #pragma region sub-database constructor, deconstructor and help functions DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* paramManager) : - SSMaterializerDatabase(), mUniqueAttr(), mUniqueObj(), mDbHelper(paramManager) { + SSMaterializerDatabase(), mUniqueAttr(), /*mUniqueObj(), */mDbHelper(paramManager) { FakeConstructor(file); } @@ -147,17 +146,17 @@ namespace SSMaterializer { } } - BOOL DocumentDatabase::is_obj_duplicated(DataStruct::EXPAND_CK_ID parents) { - // check duplication - if (mUniqueObj.find(parents) != mUniqueObj.end()) { - //existing item. skip it to make sure unique - return TRUE; - } else { - //add this item - mUniqueObj.insert(parents); - return FALSE; - } - } + //BOOL DocumentDatabase::is_obj_duplicated(DataStruct::EXPAND_CK_ID parents) { + // // check duplication + // if (mUniqueObj.find(parents) != mUniqueObj.end()) { + // //existing item. skip it to make sure unique + // return TRUE; + // } else { + // //add this item + // mUniqueObj.insert(parents); + // return FALSE; + // } + //} #pragma endregion @@ -190,10 +189,7 @@ if (result != SQLITE_OK) { return FALSE; } SafeSqlExec("CREATE TABLE [script_pAttr] ([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT);"); SafeSqlExec("CREATE TABLE [msg] ([index] INTEGER, [name] TEXT);"); - - SafeSqlExec("CREATE TABLE [array] ([thisobj] INTEGER, [name] TEXT, [rows] INTEGER, [columns] INTEGER);"); - SafeSqlExec("CREATE TABLE [array_header] ([index] INTEGER, [name] TEXT, [type] INTEGER, [param_type] TEXT, [param_type_guid] TEXT, [parent] INTEGER);"); - SafeSqlExec("CREATE TABLE [array_cell] ([row] INTEGER, [column] INTEGER, [showcase] TEXT, [inner_param] INTEGER, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [obj] ([id] INTEGER, [name] TEXT, [classid] INTEGER, [classtype] TEXT);"); SafeSqlExec("CREATE TABLE [data] ([field] TEXT, [data] TEXT, [parent] INTEGER);"); @@ -482,45 +478,16 @@ if (stmt == NULL) { \ sqlite3_step(stmt); } - void DocumentDatabase::write_array(DataStruct::dbdoc_array& data) { + void DocumentDatabase::write_obj(DataStruct::dbdoc_obj& data) { if (mDb == NULL) return; - TryGetStmtCache("INSERT INTO [array] VALUES (?, ?, ?, ?)"); + TryGetStmtCache("INSERT INTO [obj] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_int(stmt, 1, data.id); sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data.rows); - sqlite3_bind_int(stmt, 4, data.columns); - sqlite3_step(stmt); - } - - void DocumentDatabase::write_array_header(DataStruct::dbdoc_array_header& data) { - if (mDb == NULL) return; - - TryGetStmtCache("INSERT INTO [array_header] VALUES (?, ?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data.index); - sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data.type); - sqlite3_bind_text(stmt, 4, data.param_type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data.param_type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data.parent); - sqlite3_step(stmt); - } - - void DocumentDatabase::write_array_cell(DataStruct::dbdoc_array_cell& data) { - if (mDb == NULL) return; - - TryGetStmtCache("INSERT INTO [array_cell] VALUES (?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data.row); - sqlite3_bind_int(stmt, 2, data.column); - sqlite3_bind_text(stmt, 3, data.showcase.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, data.inner_param); - sqlite3_bind_int(stmt, 5, data.parent); + sqlite3_bind_int(stmt, 3, data.classid); + sqlite3_bind_text(stmt, 4, data.classtype.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); } diff --git a/SuperScriptMaterializer/database.hpp b/SuperScriptMaterializer/database.hpp index d8755cb..90aee18 100644 --- a/SuperScriptMaterializer/database.hpp +++ b/SuperScriptMaterializer/database.hpp @@ -154,28 +154,11 @@ namespace SSMaterializer { std::string name; }; - struct dbdoc_array { - EXPAND_CK_ID thisobj; + struct dbdoc_obj { + EXPAND_CK_ID id; std::string name; - int rows; - int columns; - }; - - struct dbdoc_array_header { - int index; - std::string name; - CK_ARRAYTYPE type; - std::string param_type; - std::string param_type_guid; - EXPAND_CK_ID parent; - }; - - struct dbdoc_array_cell { - int row; - int column; - std::string showcase; - EXPAND_CK_ID inner_param; - EXPAND_CK_ID parent; + CK_CLASSID classid; + std::string classtype; }; struct dbdoc_data { @@ -278,10 +261,7 @@ namespace SSMaterializer { dbdoc_script_pTarget script_pTarget; dbdoc_msg msg; - - dbdoc_array _array; - dbdoc_array_header array_header; - dbdoc_array_cell array_cell; + dbdoc_obj obj; dbdoc_data data; }; @@ -341,22 +321,19 @@ namespace SSMaterializer { void write_script_pAttr(DataStruct::dbdoc_script_pAttr& data); void write_msg(DataStruct::dbdoc_msg& data); - - void write_array(DataStruct::dbdoc_array& data); - void write_array_header(DataStruct::dbdoc_array_header& data); - void write_array_cell(DataStruct::dbdoc_array_cell& data); + void write_obj(DataStruct::dbdoc_obj& data); void write_data(DataStruct::dbdoc_data& data); BOOL is_attr_duplicated(DataStruct::EXPAND_CK_ID parents); - BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents); + //BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents); protected: virtual BOOL Init() override; virtual BOOL Finalize() override; std::set mUniqueAttr; - std::set mUniqueObj; + //std::set mUniqueObj; }; class EnvironmentDatabase : public SSMaterializerDatabase { diff --git a/SuperScriptMaterializer/doc_export.cpp b/SuperScriptMaterializer/doc_export.cpp index e6a2373..972d11c 100644 --- a/SuperScriptMaterializer/doc_export.cpp +++ b/SuperScriptMaterializer/doc_export.cpp @@ -219,9 +219,9 @@ namespace SSMaterializer { void Proc_pTarget(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents) { mDb->mDbHelper.script_pTarget.thisobj = cache->GetID(); - CopyCKString(mDb->mDbHelper.script_pTarget.name, cache->GetName()); - CopyCKParamTypeStr(mDb->mDbHelper.script_pTarget.type, cache->GetType(), mDb->mDbHelper.param_manager); - CopyGuid(mDb->mDbHelper.script_pTarget.type_guid, cache->GetGUID()); + Utils::CopyCKString(mDb->mDbHelper.script_pTarget.name, cache->GetName()); + Utils::CopyCKParamTypeStr(mDb->mDbHelper.script_pTarget.type, cache->GetType(), mDb->mDbHelper.param_manager); + Utils::CopyGuid(mDb->mDbHelper.script_pTarget.type_guid, cache->GetGUID()); mDb->mDbHelper.script_pTarget.parent = parents; mDb->mDbHelper.script_pTarget.direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1; mDb->mDbHelper.script_pTarget.shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1; @@ -235,9 +235,9 @@ namespace SSMaterializer { void Proc_pIn(CKContext* ctx, CKParameterIn* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { mDb->mDbHelper.script_pIn.thisobj = cache->GetID(); mDb->mDbHelper.script_pIn.index = index; - CopyCKString(mDb->mDbHelper.script_pIn.name, cache->GetName()); - CopyCKParamTypeStr(mDb->mDbHelper.script_pIn.type, cache->GetType(), mDb->mDbHelper.param_manager); - CopyGuid(mDb->mDbHelper.script_pIn.type_guid, cache->GetGUID()); + Utils::CopyCKString(mDb->mDbHelper.script_pIn.name, cache->GetName()); + Utils::CopyCKParamTypeStr(mDb->mDbHelper.script_pIn.type, cache->GetType(), mDb->mDbHelper.param_manager); + Utils::CopyGuid(mDb->mDbHelper.script_pIn.type_guid, cache->GetGUID()); mDb->mDbHelper.script_pIn.parent = parents; mDb->mDbHelper.script_pIn.direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1; mDb->mDbHelper.script_pIn.shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1; @@ -252,9 +252,9 @@ namespace SSMaterializer { void Proc_pOut(CKContext* ctx, CKParameterOut* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, DataStruct::EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { mDb->mDbHelper.script_pOut.thisobj = cache->GetID(); mDb->mDbHelper.script_pOut.index = index; - CopyCKString(mDb->mDbHelper.script_pOut.name, cache->GetName()); - CopyCKParamTypeStr(mDb->mDbHelper.script_pOut.type, cache->GetType(), mDb->mDbHelper.param_manager); - CopyGuid(mDb->mDbHelper.script_pOut.type_guid, cache->GetGUID()); + Utils::CopyCKString(mDb->mDbHelper.script_pOut.name, cache->GetName()); + Utils::CopyCKParamTypeStr(mDb->mDbHelper.script_pOut.type, cache->GetType(), mDb->mDbHelper.param_manager); + Utils::CopyGuid(mDb->mDbHelper.script_pOut.type_guid, cache->GetGUID()); mDb->mDbHelper.script_pOut.parent = parents; mDb->write_script_pOut(mDb->mDbHelper.script_pOut); @@ -266,7 +266,7 @@ namespace SSMaterializer { void Proc_bIn(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index) { mDb->mDbHelper.script_bIn.thisobj = cache->GetID(); mDb->mDbHelper.script_bIn.index = index; - CopyCKString(mDb->mDbHelper.script_bIn.name, cache->GetName()); + Utils::CopyCKString(mDb->mDbHelper.script_bIn.name, cache->GetName()); mDb->mDbHelper.script_bIn.parent = parents; mDb->write_script_bIn(mDb->mDbHelper.script_bIn); @@ -275,7 +275,7 @@ namespace SSMaterializer { void Proc_bOut(CKBehaviorIO* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, int index) { mDb->mDbHelper.script_bOut.thisobj = cache->GetID(); mDb->mDbHelper.script_bOut.index = index; - CopyCKString(mDb->mDbHelper.script_bOut.name, cache->GetName()); + Utils::CopyCKString(mDb->mDbHelper.script_bOut.name, cache->GetName()); mDb->mDbHelper.script_bOut.parent = parents; mDb->write_script_bOut(mDb->mDbHelper.script_bOut); @@ -303,9 +303,9 @@ namespace SSMaterializer { void Proc_pLocal(CKParameterLocal* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents, BOOL is_setting) { mDb->mDbHelper.script_pLocal.thisobj = cache->GetID(); - CopyCKString(mDb->mDbHelper.script_pLocal.name, cache->GetName()); - CopyCKParamTypeStr(mDb->mDbHelper.script_pLocal.type, cache->GetType(), mDb->mDbHelper.param_manager); - CopyGuid(mDb->mDbHelper.script_pLocal.type_guid, cache->GetGUID()); + Utils::CopyCKString(mDb->mDbHelper.script_pLocal.name, cache->GetName()); + Utils::CopyCKParamTypeStr(mDb->mDbHelper.script_pLocal.type, cache->GetType(), mDb->mDbHelper.param_manager); + Utils::CopyGuid(mDb->mDbHelper.script_pLocal.type_guid, cache->GetGUID()); mDb->mDbHelper.script_pLocal.is_setting = is_setting; mDb->mDbHelper.script_pLocal.parent = parents; @@ -318,7 +318,7 @@ namespace SSMaterializer { void Proc_pOper(CKContext* ctx, CKParameterOperation* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { mDb->mDbHelper.script_pOper.thisobj = cache->GetID(); mDb->mDbHelper.script_pOper.op = mDb->mDbHelper.param_manager->OperationGuidToName(cache->GetOperationGuid()); - CopyGuid(mDb->mDbHelper.script_pOper.op_guid, cache->GetOperationGuid()); + Utils::CopyGuid(mDb->mDbHelper.script_pOper.op_guid, cache->GetOperationGuid()); mDb->mDbHelper.script_pOper.parent = parents; mDb->write_script_pOper(mDb->mDbHelper.script_pOper); @@ -342,9 +342,9 @@ namespace SSMaterializer { // write self first to detect conflict mDb->mDbHelper.script_pAttr.thisobj = cache->GetID(); - CopyCKString(mDb->mDbHelper.script_pAttr.name, cache->GetName()); - CopyCKParamTypeStr(mDb->mDbHelper.script_pAttr.type, cache->GetType(), mDb->mDbHelper.param_manager); - CopyGuid(mDb->mDbHelper.script_pAttr.type_guid, cache->GetGUID()); + Utils::CopyCKString(mDb->mDbHelper.script_pAttr.name, cache->GetName()); + Utils::CopyCKParamTypeStr(mDb->mDbHelper.script_pAttr.type, cache->GetType(), mDb->mDbHelper.param_manager); + Utils::CopyGuid(mDb->mDbHelper.script_pAttr.type_guid, cache->GetGUID()); mDb->write_script_pAttr(mDb->mDbHelper.script_pAttr); @@ -352,17 +352,15 @@ namespace SSMaterializer { CKObject* host = cache->GetOwner(); // write owner id DataDictWritter("attr.owner", (long)host->GetID(), mDb, cache->GetID()); - // write data for owner - DigObjectData(host, mDb, host->GetID()); } void Proc_Behavior(CKContext* ctx, CKBehavior* bhv, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { //write self data mDb->mDbHelper.script_behavior.thisobj = bhv->GetID(); - CopyCKString(mDb->mDbHelper.script_behavior.name, bhv->GetName()); + Utils::CopyCKString(mDb->mDbHelper.script_behavior.name, bhv->GetName()); mDb->mDbHelper.script_behavior.type = bhv->GetType(); - CopyCKString(mDb->mDbHelper.script_behavior.proto_name, bhv->GetPrototypeName()); - CopyGuid(mDb->mDbHelper.script_behavior.proto_guid, bhv->GetPrototypeGuid()); + Utils::CopyCKString(mDb->mDbHelper.script_behavior.proto_name, bhv->GetPrototypeName()); + Utils::CopyGuid(mDb->mDbHelper.script_behavior.proto_guid, bhv->GetPrototypeGuid()); mDb->mDbHelper.script_behavior.flags = bhv->GetFlags(); mDb->mDbHelper.script_behavior.priority = bhv->GetPriority(); mDb->mDbHelper.script_behavior.version = bhv->GetVersion(); @@ -437,197 +435,49 @@ namespace SSMaterializer { #pragma endregion -#pragma region message +#pragma region message & obj void IterateMessage(CKContext* ctx, Database::DocumentDatabase* mDb) { CKMessageManager* msgManager = ctx->GetMessageManager(); int count = msgManager->GetMessageTypeCount(); for (int i = 0; i < count; i++) { mDb->mDbHelper.msg.index = i; - CopyCKString(mDb->mDbHelper.msg.name, msgManager->GetMessageTypeName(i)); + Utils::CopyCKString(mDb->mDbHelper.msg.name, msgManager->GetMessageTypeName(i)); mDb->write_msg(mDb->mDbHelper.msg); } } -#pragma endregion + static std::vector g_CommonClassId{ +#if defined(VIRTOOLS_50) || defined(VIRTOOLS_40) || defined(VIRTOOLS_35) + // export video for non-21/25 virtools ver + CKCID_VIDEO, +#endif + // export beobj object will export almost objects + CKCID_OBJECTANIMATION, CKCID_ANIMATION, CKCID_BEOBJECT + }; + void IterateObj(CKContext* ctx, Database::DocumentDatabase* mDb) { + for (auto it = g_CommonClassId.begin(); it != g_CommonClassId.end(); ++it) { + XObjectPointerArray objArray = ctx->GetObjectListByType(*it, TRUE); + int len = objArray.Size(); + int scriptLen = 0; + for (int i = 0; i < len; i++) { + CKSceneObject* scene_obj = (CKSceneObject*)objArray.GetObjectA(i); -#pragma region array - - void IterateArray(CKContext* ctx, Database::DocumentDatabase* mDb) { - // get all array - XObjectPointerArray objArray = ctx->GetObjectListByType(CKCID_DATAARRAY, TRUE); - CKDataArray* darray = NULL; - int len = objArray.Size(); - for (int i = 0; i < len; i++) { - darray = (CKDataArray*)objArray.GetObjectA(i); - - // dump self data first - mDb->mDbHelper._array.thisobj = darray->GetID(); - CopyCKString(mDb->mDbHelper._array.name, darray->GetName()); - mDb->mDbHelper._array.columns = darray->GetColumnCount(); - mDb->mDbHelper._array.rows = darray->GetRowCount(); - - mDb->write_array(mDb->mDbHelper._array); - - // dump column and row data - Proc_ArrayColumnRow(darray, mDb, darray->GetID()); - } - } - - void Proc_ArrayColumnRow(CKDataArray* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { - int columns = cache->GetColumnCount(), rows = cache->GetRowCount(); - - // we iterate columns to get data - // because the value type of one column is not changed, - // it is benefit to our export. - for (int col = 0; col < columns; ++col) { - // dump column self first - mDb->mDbHelper.array_header.index = col; - CopyCKString(mDb->mDbHelper.array_header.name, cache->GetColumnName(col)); - - CK_ARRAYTYPE coltype = cache->GetColumnType(col); - mDb->mDbHelper.array_header.type = coltype; - if (coltype == CKARRAYTYPE_PARAMETER) { - CKGUID guid = cache->GetColumnParameterGuid(col); - CopyGuid(mDb->mDbHelper.array_header.param_type_guid, guid); - CKSTRING pname = mDb->mDbHelper.param_manager->ParameterGuidToName(guid); - CopyCKString(mDb->mDbHelper.array_header.param_type, pname); - } else { - mDb->mDbHelper.array_header.param_type = ""; - mDb->mDbHelper.array_header.param_type_guid = ""; + mDb->mDbHelper.obj.id = scene_obj->GetID(); + Utils::CopyCKString(mDb->mDbHelper.obj.name, scene_obj->GetName()); + mDb->mDbHelper.obj.classid = scene_obj->GetClassID(); + Utils::CopyCKClassId(mDb->mDbHelper.obj.classtype, scene_obj->GetClassID(), mDb->mDbHelper.param_manager); + mDb->write_obj(mDb->mDbHelper.obj); } - - mDb->mDbHelper.array_header.parent = parents; - mDb->write_array_header(mDb->mDbHelper.array_header); - - // write row data - switch (coltype) { - case CKARRAYTYPE_INT: - { - for (int row = 0; row < rows; ++row) { - mDb->mDbHelper.array_cell.column = col; - mDb->mDbHelper.array_cell.row = row; - mDb->mDbHelper.array_cell.parent = parents; - - Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%d", *((int*)cache->GetElement(row, col))); - mDb->mDbHelper.array_cell.inner_param = -1; - - mDb->write_array_cell(mDb->mDbHelper.array_cell); - } - } - break; - case CKARRAYTYPE_FLOAT: - { - for (int row = 0; row < rows; ++row) { - mDb->mDbHelper.array_cell.column = col; - mDb->mDbHelper.array_cell.row = row; - mDb->mDbHelper.array_cell.parent = parents; - - Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%f", *((float*)cache->GetElement(row, col))); - mDb->mDbHelper.array_cell.inner_param = -1; - - mDb->write_array_cell(mDb->mDbHelper.array_cell); - } - } - break; - case CKARRAYTYPE_STRING: - { - for (int row = 0; row < rows; ++row) { - mDb->mDbHelper.array_cell.column = col; - mDb->mDbHelper.array_cell.row = row; - mDb->mDbHelper.array_cell.parent = parents; - - int count = cache->GetElementStringValue(row, col, NULL); - mDb->mDbHelper.array_cell.showcase.resize(count); - cache->GetElementStringValue(row, col, (char*)mDb->mDbHelper.array_cell.showcase.data()); - mDb->mDbHelper.array_cell.inner_param = -1; - - mDb->write_array_cell(mDb->mDbHelper.array_cell); - } - } - break; - case CKARRAYTYPE_OBJECT: - case CKARRAYTYPE_PARAMETER: - { - // due to Virtools shit document. - // although column has indicate current column is object or parameter. - // but it can not ensure value is CKParameter when column type is parameter. - // for example, Parameter - Array will return a CKDataArray, not CKParameter. - // so we put these 2 type together and check it in runtime to - // use different output. - - CKObject* obj = NULL; - CKParameter* p = NULL; - CK_CLASSID objcls; - int param_size = 0; - BOOL need_evaluate = FALSE; - - for (int row = 0; row < rows; ++row) { - mDb->mDbHelper.array_cell.column = col; - mDb->mDbHelper.array_cell.row = row; - mDb->mDbHelper.array_cell.parent = parents; - - // check get status - obj = cache->GetElementObject(row, col); - if (obj == NULL) { - // fail to get obj - mDb->mDbHelper.array_cell.showcase = "(null)"; - mDb->mDbHelper.array_cell.inner_param = -1; - } else { - // split normal obj and param obj - // use class id - objcls = obj->GetClassID(); - if (objcls == CKCID_PARAMETER || objcls == CKCID_PARAMETERLOCAL || objcls == CKCID_PARAMETEROUT) { - need_evaluate = objcls == CKCID_PARAMETEROUT; - - // CKParameter - p = (CKParameter*)obj; - param_size = p->GetStringValue(NULL, need_evaluate); - mDb->mDbHelper.array_cell.showcase.resize(param_size); - p->GetStringValue((char*)mDb->mDbHelper.array_cell.showcase.data(), need_evaluate); - - mDb->mDbHelper.array_cell.inner_param = p->GetID(); - - // dig more data for it. - DigParameterData(p, mDb, p->GetID()); - } else { - // normal CKObject - Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%s(%s)", - obj->GetName() ? obj->GetName() : "!!UNKNOW!!", - obj->GetClassNameA() ? obj->GetClassNameA() : "!!UNKNOW!!"); - - mDb->mDbHelper.array_cell.inner_param = obj->GetID(); - - // dig more data for it - DigObjectData(obj, mDb, obj->GetID()); - } - } - - mDb->write_array_cell(mDb->mDbHelper.array_cell); - } - } - break; - } - } + } #pragma endregion #pragma region data process - void DigObjectData(CKObject* o, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { - // check duplication - // we use `parents` not o->GetID() because in some call they are not equal. - if (mDb->is_obj_duplicated(parents)) return; - - DataDictWritter("obj.id", (long)o->GetID(), mDb, parents); - DataDictWritter("obj.name", o->GetName() ? o->GetName() : "!!UNKNOW!!", mDb, parents); - DataDictWritter("obj.classid", (long)o->GetClassID(), mDb, parents); - DataDictWritter("obj.type", o->GetClassNameA() ? o->GetClassNameA() : "!!UNKNOW!!", mDb, parents); - } - void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { // due to our algorithm, parameter can not be duplicated // so we don't need to check its duplication. @@ -637,9 +487,9 @@ namespace SSMaterializer { // export guid and type name corresponding with guid static std::string str_guid; static std::string str_typename; - CopyGuid(str_guid, t); + Utils::CopyGuid(str_guid, t); DataDictWritter("guid", str_guid.c_str(), mDb, parents); - CopyCKParamTypeStr(str_typename, pt, mDb->mDbHelper.param_manager); + Utils::CopyCKParamTypeStr(str_typename, pt, mDb->mDbHelper.param_manager); DataDictWritter("typename", str_typename.c_str(), mDb, parents); // value object @@ -647,8 +497,6 @@ namespace SSMaterializer { CKObject* vobj = p->GetValueObject(false); // write its id DataDictWritter("vobj", (long)vobj->GetID(), mDb, parents); - // write more data for its id - DigObjectData(vobj, mDb, vobj->GetID()); return; } diff --git a/SuperScriptMaterializer/doc_export.hpp b/SuperScriptMaterializer/doc_export.hpp index 8964570..0e8587b 100644 --- a/SuperScriptMaterializer/doc_export.hpp +++ b/SuperScriptMaterializer/doc_export.hpp @@ -18,16 +18,12 @@ namespace SSMaterializer { void Proc_pOper(CKContext* ctx, CKParameterOperation* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void Proc_pAttr(CKContext* ctx, Database::DocumentDatabase* mDb, CKParameter* cache); - void Proc_Behavior(CKContext* ctx, CKBehavior* bhv, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void IterateScript(CKContext* ctx, Database::DocumentDatabase* mDb); void IterateMessage(CKContext* ctx, Database::DocumentDatabase* mDb); + void IterateObj(CKContext* ctx, Database::DocumentDatabase* mDb); - void IterateArray(CKContext* ctx, Database::DocumentDatabase* mDb); - void Proc_ArrayColumnRow(CKDataArray* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); - - void DigObjectData(CKObject* o, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DataDictWritter(const char* field, long data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DataDictWritter(const char* field, float data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); diff --git a/SuperScriptMaterializer/env_export.cpp b/SuperScriptMaterializer/env_export.cpp index af32a06..e91aab6 100644 --- a/SuperScriptMaterializer/env_export.cpp +++ b/SuperScriptMaterializer/env_export.cpp @@ -16,7 +16,7 @@ namespace SSMaterializer { //fill basic data mDb->mDbHelper.op.op_code = i; _guid = parameterManager->OperationCodeToGuid(i); - CopyGuid(mDb->mDbHelper.op.op_guid, _guid); + Utils::CopyGuid(mDb->mDbHelper.op.op_guid, _guid); mDb->mDbHelper.op.op_name = parameterManager->OperationCodeToName(i); //allocate mem @@ -29,9 +29,9 @@ namespace SSMaterializer { parameterManager->GetAvailableOperationsDesc(_guid, NULL, NULL, NULL, opList); for (int j = 0; j < cacheListCount; j++) { - CopyGuid(mDb->mDbHelper.op.in1_guid, opList[j].P1Guid); - CopyGuid(mDb->mDbHelper.op.in2_guid, opList[j].P2Guid); - CopyGuid(mDb->mDbHelper.op.out_guid, opList[j].ResGuid); + Utils::CopyGuid(mDb->mDbHelper.op.in1_guid, opList[j].P1Guid); + Utils::CopyGuid(mDb->mDbHelper.op.in2_guid, opList[j].P2Guid); + Utils::CopyGuid(mDb->mDbHelper.op.out_guid, opList[j].ResGuid); mDb->mDbHelper.op.funcPtr = opList[j].Fct; mDb->write_op(mDb->mDbHelper.op); @@ -48,8 +48,8 @@ namespace SSMaterializer { desc = parameterManager->GetParameterTypeDescription(i); mDb->mDbHelper.param.index = desc->Index; - CopyGuid(mDb->mDbHelper.param.guid, desc->Guid); - CopyGuid(mDb->mDbHelper.param.derived_from, desc->DerivedFrom); + Utils::CopyGuid(mDb->mDbHelper.param.guid, desc->Guid); + Utils::CopyGuid(mDb->mDbHelper.param.derived_from, desc->DerivedFrom); mDb->mDbHelper.param.type_name = desc->TypeName.CStr(); mDb->mDbHelper.param.default_size = desc->DefaultSize; mDb->mDbHelper.param.func_CreateDefault = desc->CreateDefaultFunction; @@ -70,7 +70,7 @@ namespace SSMaterializer { mDb->mDbHelper.param.dw_param = desc->dwParam; mDb->mDbHelper.param.dw_flags = desc->dwFlags; mDb->mDbHelper.param.cid = desc->Cid; - CopyGuid(mDb->mDbHelper.param.saver_manager, desc->Saver_Manager); + Utils::CopyGuid(mDb->mDbHelper.param.saver_manager, desc->Saver_Manager); mDb->write_param(mDb->mDbHelper.param); } @@ -82,11 +82,11 @@ namespace SSMaterializer { mDb->mDbHelper.attr.index = i; mDb->mDbHelper.attr.name = attrManager->GetAttributeNameByType(i); mDb->mDbHelper.attr.category_index = attrManager->GetAttributeCategoryIndex(i); - CopyCKString(mDb->mDbHelper.attr.category_name, attrManager->GetAttributeCategory(i)); + Utils::CopyCKString(mDb->mDbHelper.attr.category_name, attrManager->GetAttributeCategory(i)); mDb->mDbHelper.attr.flags = attrManager->GetAttributeFlags(i); mDb->mDbHelper.attr.param_index = attrManager->GetAttributeParameterType(i); mDb->mDbHelper.attr.compatible_classid = attrManager->GetAttributeCompatibleClassId(i); - CopyCKString(mDb->mDbHelper.attr.default_value, attrManager->GetAttributeDefaultValue(i)); + Utils::CopyCKString(mDb->mDbHelper.attr.default_value, attrManager->GetAttributeDefaultValue(i)); mDb->write_attr(mDb->mDbHelper.attr); } @@ -108,7 +108,7 @@ namespace SSMaterializer { mDb->mDbHelper.plugin.plugin_index = plgEntry->m_PositionInDll; mDb->mDbHelper.plugin.active = plgEntry->m_Active; - CopyGuid(mDb->mDbHelper.plugin.guid, plgInfo->m_GUID); + Utils::CopyGuid(mDb->mDbHelper.plugin.guid, plgInfo->m_GUID); mDb->mDbHelper.plugin.desc = plgInfo->m_Description.CStr(); mDb->mDbHelper.plugin.author = plgInfo->m_Author.CStr(); mDb->mDbHelper.plugin.summary = plgInfo->m_Summary.CStr(); @@ -129,10 +129,10 @@ namespace SSMaterializer { for (; !it.End(); it++) { varobj = it.GetVariable(); mDb->mDbHelper.variable.name = it.GetName(); - CopyCKString(mDb->mDbHelper.variable.desciption, varobj->GetDescription()); + Utils::CopyCKString(mDb->mDbHelper.variable.desciption, varobj->GetDescription()); mDb->mDbHelper.variable.flags = varobj->GetFlags(); mDb->mDbHelper.variable.type = varobj->GetType(); - CopyCKString(mDb->mDbHelper.variable.representation, varobj->GetRepresentation()); + Utils::CopyCKString(mDb->mDbHelper.variable.representation, varobj->GetRepresentation()); varobj->GetStringValue(dataCopyCache); mDb->mDbHelper.variable.data = dataCopyCache.CStr(); diff --git a/SuperScriptMaterializer/string_helper.hpp b/SuperScriptMaterializer/string_helper.hpp index 2de0ccc..10e8c33 100644 --- a/SuperScriptMaterializer/string_helper.hpp +++ b/SuperScriptMaterializer/string_helper.hpp @@ -3,17 +3,29 @@ #include "stdafx.h" #include -#define CopyGuid(str, guid) SSMaterializer::Utils::StdstringPrintf((str), "0x%08X, 0x%08X", (guid).d1, (guid).d2); -#define CopyCKString(storage, str) storage = (str) ? (str) : "!!UNKNOW!!"; -#define CopyCKParamTypeStr(strl, ckpt, pm) if ((ckpt) != -1) (strl) = (pm)->ParameterTypeToName(ckpt);\ -else (strl) = "!!UNKNOW!!"; - namespace SSMaterializer { namespace Utils { + constexpr const char g_Unknow[] = "!!UNKNOW!!"; + void StdstringPrintf(std::string& strl, const char* format, ...); void StdstringVPrintf(std::string& strl, const char* format, va_list argptr); void StdstringGetBase64(std::string& strl, const char* data, size_t datalen); + inline void CopyGuid(std::string& str, CKGUID& guid) { + StdstringPrintf(str, "0x%08X, 0x%08X", guid.d1, guid.d2); + } + inline void CopyCKString(std::string& storage, const char* str) { + storage = str == NULL ? g_Unknow : str; + } + inline void CopyCKParamTypeStr(std::string& strl, CKParameterType ckpt, CKParameterManager* pm) { + if (ckpt != -1) strl = pm->ParameterTypeToName(ckpt); + else strl = g_Unknow; + } + inline void CopyCKClassId(std::string& strl, CK_CLASSID clsid, CKParameterManager* pm) { + CKSTRING ckstr = pm->ParameterGuidToName(pm->ClassIDToGuid(clsid)); + strl = ckstr == NULL ? g_Unknow : ckstr; + } + } } diff --git a/SuperScriptMaterializer/vt_menu.cpp b/SuperScriptMaterializer/vt_menu.cpp index a80433c..afed22b 100644 --- a/SuperScriptMaterializer/vt_menu.cpp +++ b/SuperScriptMaterializer/vt_menu.cpp @@ -47,12 +47,12 @@ void RemoveMenu() { void UpdateMenu() { s_Plugininterface->ClearPluginMenu(s_MainMenu); //clear menu - s_Plugininterface->AddPluginMenuItem(s_MainMenu, 0, "Export document"); - s_Plugininterface->AddPluginMenuItem(s_MainMenu, 1, "Export environment"); + s_Plugininterface->AddPluginMenuItem(s_MainMenu, 0, "Export Document"); + s_Plugininterface->AddPluginMenuItem(s_MainMenu, 1, "Export Environment"); s_Plugininterface->AddPluginMenuItem(s_MainMenu, -1, NULL, TRUE); - s_Plugininterface->AddPluginMenuItem(s_MainMenu, 2, "Report bug"); - s_Plugininterface->AddPluginMenuItem(s_MainMenu, 3, "Plugin homepage"); + s_Plugininterface->AddPluginMenuItem(s_MainMenu, 2, "Report Bug"); + s_Plugininterface->AddPluginMenuItem(s_MainMenu, 3, "Plugin Homepage"); s_Plugininterface->UpdatePluginMenu(s_MainMenu); //update menu,always needed when you finished to update the menu //unless you want the menu not to have Virtools Dev main menu color scheme. @@ -83,7 +83,7 @@ void PluginMenuCallback(int commandID) { //iterate item SSMaterializer::DocumentExporter::IterateScript(ctx, db); SSMaterializer::DocumentExporter::IterateMessage(ctx, db); - SSMaterializer::DocumentExporter::IterateArray(ctx, db); + SSMaterializer::DocumentExporter::IterateObj(ctx, db); //Close all resources delete db;