From ef1261e34977f09eef67ddd67001c06f7f34e88d Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 1 Aug 2024 17:12:31 +0800 Subject: [PATCH] fix: fix various compile error. - fix various compile error to let plugin now can be compiled. --- cmake/init_materializer_env.cmake | 10 ++- decorator/CMakeLists.txt | 4 +- materializer/CMakeLists.txt | 27 +++++-- materializer/PluginMain.cpp | 114 ++++++++++++++++++++++++++++++ materializer/PluginMain.hpp | 12 ++++ materializer/StandaloneMain.cpp | 89 +++++++++++++++++++++++ materializer/StandaloneMain.hpp | 10 +++ materializer/main.cpp | 52 ++++++++++++++ materializer/stdafx.hpp | 76 ++++++++++++++++++++ 9 files changed, 385 insertions(+), 9 deletions(-) create mode 100644 materializer/PluginMain.cpp create mode 100644 materializer/PluginMain.hpp create mode 100644 materializer/StandaloneMain.cpp create mode 100644 materializer/StandaloneMain.hpp diff --git a/cmake/init_materializer_env.cmake b/cmake/init_materializer_env.cmake index de4b685..ab3c3f1 100644 --- a/cmake/init_materializer_env.cmake +++ b/cmake/init_materializer_env.cmake @@ -95,8 +95,7 @@ INTERFACE_INCLUDE_DIRECTORIES "${VIRTOOLS_HEADER_PATH}" ) # Setup lib files -set_target_properties(VirtoolsSDK PROPERTIES -INTERFACE_LINK_LIBRARIES +set(VirtoolsSDK_LIBS_LIST # Both standalone and plugin build type needed "${VIRTOOLS_LIB_PATH}/CK2.lib" "${VIRTOOLS_LIB_PATH}/VxMath.lib" @@ -104,6 +103,11 @@ INTERFACE_LINK_LIBRARIES "$<$:${VIRTOOLS_LIB_PATH}/DllEditor.lib>" "$<$:${VIRTOOLS_LIB_PATH}/InterfaceControls.lib>" "$<$:${VIRTOOLS_LIB_PATH}/CKControls.lib>" + # Virtools 5.0 special + "$<$:${VIRTOOLS_LIB_PATH}/CKKernelInit.lib>" +) +set_target_properties(VirtoolsSDK PROPERTIES +INTERFACE_LINK_LIBRARIES "${VirtoolsSDK_LIBS_LIST}" ) # Setup compile macros target_compile_definitions(VirtoolsSDK @@ -111,7 +115,7 @@ INTERFACE # Virtools version macro "VIRTOOLS_${VIRTOOLS_VERSION}" # Virtools 5.0 standalone mode need an extra macro - "$<$,$>:VIRTOOLS_USER_SDK>" + "$<$,$>:VIRTOOLS_USER_SDK>" ) # Setup compiler options target_compile_options(VirtoolsSDK diff --git a/decorator/CMakeLists.txt b/decorator/CMakeLists.txt index f901200..58da4d5 100644 --- a/decorator/CMakeLists.txt +++ b/decorator/CMakeLists.txt @@ -17,14 +17,14 @@ FILES target_include_directories(VSWDecorator PUBLIC ${CMAKE_CURRENT_LIST_DIR} - YYCCommonplace + YYCC::YYCCommonplace SQLite3::SQLite3 VSWShared ) # Setup linked library target_link_libraries(VSWDecorator PRIVATE - YYCCommonplace + YYCC::YYCCommonplace SQLite3::SQLite3 VSWShared ) diff --git a/materializer/CMakeLists.txt b/materializer/CMakeLists.txt index b341a4f..9148e5a 100644 --- a/materializer/CMakeLists.txt +++ b/materializer/CMakeLists.txt @@ -2,8 +2,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cmake/init_materializer_env.cmake) # Create library or executable according to build type -if (VSW_MATERIALIZER_BUILD_TYPE STREQUAL "plugin") - add_library(VSWMaterializer STATIC "") +if (MATERIALIZER_BUILD_TYPE STREQUAL "plugin") + add_library(VSWMaterializer SHARED "") else () add_executable(VSWMaterializer "") endif () @@ -12,6 +12,10 @@ target_sources(VSWMaterializer PRIVATE # Sources main.cpp + PluginMain.cpp + StandaloneMain.cpp + # Defination file + "$<$:Materializer.def>" ) # Setup header files target_sources(VSWMaterializer @@ -21,12 +25,14 @@ FILES # Headers stdafx.hpp resource.h + PluginMain.hpp + StandaloneMain.hpp ) # Setup header infomations target_include_directories(VSWMaterializer PRIVATE ${CMAKE_CURRENT_LIST_DIR} - YYCCommonplace + YYCC::YYCCommonplace SQLite3::SQLite3 VirtoolsSDK VSWShared @@ -34,7 +40,7 @@ PRIVATE # Setup linked library target_link_libraries(VSWMaterializer PRIVATE - YYCCommonplace + YYCC::YYCCommonplace SQLite3::SQLite3 VirtoolsSDK VSWShared @@ -46,9 +52,22 @@ PROPERTIES CXX_STANDARD_REQUIRED 17 CXX_EXTENSION OFF ) +# Setup MFC use +set_target_properties(VSWMaterializer +PROPERTIES + CMAKE_MFC_FLAG 2 +) # MSVC specific correction target_compile_definitions(VSWMaterializer PRIVATE + # MFC macro + _AFXDLL + # Materializer build type + "MATERIALIZER_$" + # Materializer debug or release + "$<$:MATERIALIZER_DEBUG>" + "$<$:MATERIALIZER_DEBUG>" + # Multibyte encoding $<$:MBCS> $<$:_MBCS> ) diff --git a/materializer/PluginMain.cpp b/materializer/PluginMain.cpp new file mode 100644 index 0000000..3bce3be --- /dev/null +++ b/materializer/PluginMain.cpp @@ -0,0 +1,114 @@ +#include "PluginMain.hpp" + +namespace VSW::Materializer::PluginMain { + +#ifdef MATERIALIZER_PLUGIN + + PluginInterface* g_Plugininterface = nullptr; + PluginInfo g_PluginInfo; + CMenu* g_MainMenu = nullptr; + + static void PluginMenuCallback(int command_id) { + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + switch (command_id) { + case 0: + { + MessageBoxW(nullptr, L"Work in Progress", L"WIP", MB_ICONINFORMATION + MB_OK); + break; + } + case 1: + { + MessageBoxW(nullptr, L"Work in Progress", L"WIP", MB_ICONINFORMATION + MB_OK); + break; + } + case 2: + { + MessageBoxW(nullptr, L"Work in Progress", L"WIP", MB_ICONINFORMATION + MB_OK); + break; + } + case 3: + { + ShellExecuteW(NULL, L"open", L"https://github.com/yyc12345/SuperScriptMaterializer/issues", NULL, NULL, SW_SHOWNORMAL); + break; + } + case 4: + { + const wchar_t* body = + L"VSW Materializer v2.0.0 - Virtools Schematic Weaver Materializer.\n" + L"The exporter of universal Virtools scripts analyser.\n" + L"Under GPL v3 License.\n" + L"Project Home Page: https://github.com/yyc12345/SuperScriptMaterializer"; + MessageBoxW(nullptr, body, L"About VSW Materializer", MB_ICONINFORMATION + MB_OK); + break; + } + } + + } + + static void InitMenu() { + if (!g_Plugininterface) + return; + + g_MainMenu = g_Plugininterface->AddPluginMenu("VSW Materializer", 20, NULL, (VoidFunc1Param)PluginMenuCallback); + } + + static void RemoveMenu() { + if (!g_Plugininterface || !g_MainMenu) + return; + g_Plugininterface->RemovePluginMenu(g_MainMenu); + } + + static void UpdateMenu() { + g_Plugininterface->ClearPluginMenu(g_MainMenu); + + g_Plugininterface->AddPluginMenuItem(g_MainMenu, 0, "Export Scripts"); + g_Plugininterface->AddPluginMenuItem(g_MainMenu, 1, "Export Context"); + g_Plugininterface->AddPluginMenuItem(g_MainMenu, 2, "Export Environment"); + g_Plugininterface->AddPluginMenuItem(g_MainMenu, -1, NULL, TRUE); + g_Plugininterface->AddPluginMenuItem(g_MainMenu, 3, "Report Bug"); + g_Plugininterface->AddPluginMenuItem(g_MainMenu, 4, "About VSW Materializer"); + + + g_Plugininterface->UpdatePluginMenu(g_MainMenu); + } + + static void PluginCallback(PluginInfo::CALLBACK_REASON reason, PluginInterface* plugininterface) { + switch (reason) { + case PluginInfo::CR_LOAD: + { + g_Plugininterface = plugininterface; + InitMenu(); + UpdateMenu(); + break; + } + case PluginInfo::CR_UNLOAD: + { + RemoveMenu(); + g_Plugininterface = nullptr; + break; + } + case PluginInfo::CR_NEWCOMPOSITIONNAME: + break; + case PluginInfo::CR_NOTIFICATION: + break; + } + } + + void InitializePluginInfo() { + strcpy(g_PluginInfo.m_Name, "VSW Materializer"); + g_PluginInfo.m_PluginType = PluginInfo::PT_EDITOR; + g_PluginInfo.m_PluginType = (PluginInfo::PLUGIN_TYPE)(g_PluginInfo.m_PluginType | PluginInfo::PTF_RECEIVENOTIFICATION); + g_PluginInfo.m_PluginCallback = PluginCallback; + } + + PluginInfo* GetPluginInfo() { + return &g_PluginInfo; + } + PluginInterface* GetPluginInterface() { + return g_Plugininterface; + } + +#endif + +} diff --git a/materializer/PluginMain.hpp b/materializer/PluginMain.hpp new file mode 100644 index 0000000..cf5b7fa --- /dev/null +++ b/materializer/PluginMain.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "stdafx.hpp" + +namespace VSW::Materializer::PluginMain { + +#ifdef MATERIALIZER_PLUGIN + void InitializePluginInfo(); + PluginInfo* GetPluginInfo(); + PluginInterface* GetPluginInterface(); +#endif + +} diff --git a/materializer/StandaloneMain.cpp b/materializer/StandaloneMain.cpp new file mode 100644 index 0000000..ab60f57 --- /dev/null +++ b/materializer/StandaloneMain.cpp @@ -0,0 +1,89 @@ +#include "StandaloneMain.hpp" + +namespace VSW::Materializer::StandaloneMain { + +#ifdef MATERIALIZER_STANDALONE + + void PlayerMain(int argc, char* argv[]) { + printf("Super Script Materializer\n"); + printf("Homepage: https://github.com/yyc12345/SuperScriptMaterializer\n"); + printf("Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues\n"); + + // ====================== Init ck2 engine +#if defined(VIRTOOLS_21) + CommonAssert(LoadLibrary("CK2.dll") != NULL, "Error loading CK2.dll"); +#endif + + CommonAssert(!CKStartUp(), "CKStartUp Error"); + CKPluginManager* pluginManager = CKGetPluginManager(); + CommonAssert(pluginManager != NULL, "PluginManager = null"); + CommonAssert(pluginManager->ParsePlugins("RenderEngines") > 0, "Error loading RenderEngines"); + CommonAssert(pluginManager->ParsePlugins("Managers") > 0, "Error loading Managers"); + CommonAssert(pluginManager->ParsePlugins("BuildingBlocks") > 0, "Error loading BuildingBlocks"); + CommonAssert(pluginManager->ParsePlugins("Plugins") > 0, "Error loading Plugins"); + + // ====================== create context and load file + CKContext* context = NULL; + CommonAssert(!CKCreateContext(&context, NULL), "CKCreateContext Error"); + + CKObjectArray* array = CreateCKObjectArray(); + CommonAssert(!context->Load((char*)virtools_composition, array), "CKContext->Load() Error"); + + printf("Parsing %s...\n", virtools_composition); + + // ====================== do SSMaterializerDatabase export + // define and Init + scriptDatabase* _script_db = new scriptDatabase(); + dbScriptDataStructHelper* _script_helper = new dbScriptDataStructHelper(); + envDatabase* _env_db = new envDatabase(); + dbEnvDataStructHelper* _env_helper = new dbEnvDataStructHelper(); + + DeleteFile(script_db_path); + DeleteFile(env_db_path); + _script_db->open(script_db_path); + _script_helper->init(context->GetParameterManager()); + _env_db->open(env_db_path); + _env_helper->init(); + + // export + IterateScript(context, _script_db, _script_helper); + + IterateParameterOperation(context->GetParameterManager(), _env_db, _env_helper); + IterateParameter(context->GetParameterManager(), _env_db, _env_helper); + IterateMessage(context->GetMessageManager(), _env_db, _env_helper); + IterateAttribute(context->GetAttributeManager(), _env_db, _env_helper); + IteratePlugin(CKGetPluginManager(), _env_db, _env_helper); +#if !defined(VIRTOOLS_21) + IterateVariable(context->GetVariableManager(), _env_db, _env_helper); +#endif + + // free + _script_helper->dispose(); + _script_db->close(); + _env_helper->dispose(); + _env_db->close(); + delete _script_helper; + delete _script_db; + delete _env_helper; + delete _env_db; + + printf("Done!"); + + // ====================== free resources and shutdown engine + DeleteCKObjectArray(array); + context->Reset(); + context->ClearAll(); + + // todo: Virtools 4.0 standalone version throw exception in there, but i don't knwo why + // but it doesn't affect SSMaterializerDatabase export, perhaps + CKCloseContext(context); + + CKShutdown(); + + // todo: Virtools 2.5 standalone version throw exception in there, but i don't knwo why + // but it doesn't affect SSMaterializerDatabase export, perhaps + } + +#endif + +} diff --git a/materializer/StandaloneMain.hpp b/materializer/StandaloneMain.hpp new file mode 100644 index 0000000..e1b8836 --- /dev/null +++ b/materializer/StandaloneMain.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "stdafx.hpp" + +namespace VSW::Materializer::StandaloneMain { + +#ifdef MATERIALIZER_STANDALONE + void PlayerMain(int argc, char* argv[]); +#endif + +} diff --git a/materializer/main.cpp b/materializer/main.cpp index e69de29..433b0c3 100644 --- a/materializer/main.cpp +++ b/materializer/main.cpp @@ -0,0 +1,52 @@ +#include "stdafx.hpp" +#include "PluginMain.hpp" +#include "StandaloneMain.hpp" + +#if defined(MATERIALIZER_PLUGIN) + +int GetVirtoolsPluginInfoCount() { + return 1; +} + +PluginInfo* GetVirtoolsPluginInfo(int index) { + switch (index) { + case 0: + return VSW::Materializer::PluginMain::GetPluginInfo(); + default: + return nullptr; + } +} + +class CMaterializer : CWinApp { +public: + virtual BOOL InitInstance() override { + // register unhandler exception handler +#ifdef MATERIALIZER_RELEASE + YYCC::ExceptionHelper::Register(vtobjplugin::VirtoolsMenu::UnhandledExceptionCallback); +#endif + + // init plugin info + VSW::Materializer::PluginMain::InitializePluginInfo(); + + return CWinApp::InitInstance(); + } + virtual int ExitInstance() override { + + // unregister unhandler exception handler +#ifdef MATERIALIZER_RELEASE + YYCC::ExceptionHelper::Unregister(); +#endif + + return CWinApp::ExitInstance(); + } +}; +CMaterializer theApp; + +#else + +int main(int argc, char* argv[]) { + VSW::Materializer::StandaloneMain::PlayerMain(argc, argv); + return 0; +} + +#endif diff --git a/materializer/stdafx.hpp b/materializer/stdafx.hpp index e69de29..6f951bf 100644 --- a/materializer/stdafx.hpp +++ b/materializer/stdafx.hpp @@ -0,0 +1,76 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// +#pragma once + +// Check build macros +#if !defined(MATERIALIZER_PLUGIN) && !defined(MATERIALIZER_STANDALONE) +#error "You must define one of MATERIALIZER_PLUGIN or MATERIALIZER_STANDALONE to represent the build type of materializer!" +#endif +#if !defined(MATERIALIZER_DEBUG) && !defined(MATERIALIZER_RELEASE) +#error "You must define one of MATERIALIZER_DEBUG or MATERIALIZER_RELEASE!" +#endif +#if !defined(VIRTOOLS_50) && !defined(VIRTOOLS_40) && !defined(VIRTOOLS_35) && !defined(VIRTOOLS_30) && !defined(VIRTOOLS_25) && !defined(VIRTOOLS_21) +#error "Lost essential Virtools version macro!" +#endif + +#pragma region Windows and Virtools +#include + +#pragma region Windows Headers + +#include + +// Only plugin mode involve MFC headers +#if defined(MATERIALIZER_PLUGIN) +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers + +#include // MFC core and standard components +#include // MFC extensions + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC OLE classes +#include // MFC OLE dialog classes +#include // MFC Automation classes +#endif // _AFX_NO_OLE_SUPPORT + + +#ifndef _AFX_NO_DB_SUPPORT +#include // MFC ODBC database classes +#endif // _AFX_NO_DB_SUPPORT + +#ifndef _AFX_NO_DAO_SUPPORT +#include // MFC DAO database classes +#endif // _AFX_NO_DAO_SUPPORT + +#include // MFC support for Internet Explorer 4 Common Controls +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT +#endif + +#pragma endregion + +#pragma region Virtools Headers + +#include "CKAll.h" + +// Only plugi mode need include extra headers +#if defined(MATERIALIZER_PLUGIN) +#include "VIControls.h" +#include "CKControlsAll.h" +#include "VEP_ScriptActionMenu.h" +#include "VEP_KeyboardShortcutManager.h" +#include "VEP_All.h" +#endif + +#pragma endregion + +#include +#pragma endregion + +#pragma region YYCC Headers +#include +#pragma endregion +