From 8adda5ee1ec41db243486e3e5b21eefff31b6470 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Tue, 11 Mar 2014 15:57:17 +0100 Subject: [PATCH] - better PluginInformation structure (normal callback definitions) --- TitanEngine/Global.Engine.Extension.cpp | 37 +++++-------------------- TitanEngine/Global.Engine.Extension.h | 25 +++++++++++++++++ TitanEngine/stdafx.h | 13 --------- 3 files changed, 32 insertions(+), 43 deletions(-) diff --git a/TitanEngine/Global.Engine.Extension.cpp b/TitanEngine/Global.Engine.Extension.cpp index fefb214..4f2a0ae 100644 --- a/TitanEngine/Global.Engine.Extension.cpp +++ b/TitanEngine/Global.Engine.Extension.cpp @@ -8,17 +8,13 @@ static std::vector Plugin; // Global.Engine.Extension.Functions: void ExtensionManagerPluginReleaseCallBack() { - typedef void(TITCALL *fPluginReleaseExec)(); - fPluginReleaseExec myPluginReleaseExec; - for(unsigned int i = 0; i < Plugin.size(); i++) { __try { if(Plugin.at(i).TitanReleasePlugin != NULL) { - myPluginReleaseExec = (fPluginReleaseExec)Plugin.at(i).TitanReleasePlugin; - myPluginReleaseExec(); + Plugin.at(i).TitanReleasePlugin(); } } __except(EXCEPTION_EXECUTE_HANDLER) @@ -30,18 +26,13 @@ void ExtensionManagerPluginReleaseCallBack() void ExtensionManagerPluginResetCallBack() { - - typedef void(TITCALL *fPluginResetExec)(); - fPluginResetExec myPluginResetExec; - for(unsigned int i = 0; i < Plugin.size(); i++) { __try { if(Plugin.at(i).TitanResetPlugin != NULL) { - myPluginResetExec = (fPluginResetExec)Plugin.at(i).TitanResetPlugin; - myPluginResetExec(); + Plugin.at(i).TitanResetPlugin(); } } __except(EXCEPTION_EXECUTE_HANDLER) @@ -53,9 +44,6 @@ void ExtensionManagerPluginResetCallBack() void ExtensionManagerPluginDebugCallBack(LPDEBUG_EVENT debugEvent, int CallReason) { - typedef void(TITCALL *fPluginDebugExec)(LPDEBUG_EVENT debugEvent, int CallReason); - fPluginDebugExec myPluginDebugExec; - for(unsigned int i = 0; i < Plugin.size(); i++) { __try @@ -64,8 +52,7 @@ void ExtensionManagerPluginDebugCallBack(LPDEBUG_EVENT debugEvent, int CallReaso { if(Plugin.at(i).TitanDebuggingCallBack != NULL) { - myPluginDebugExec = (fPluginDebugExec)Plugin.at(i).TitanDebuggingCallBack; - myPluginDebugExec(debugEvent, CallReason); + Plugin.at(i).TitanDebuggingCallBack(debugEvent, CallReason); } } } @@ -78,7 +65,6 @@ void ExtensionManagerPluginDebugCallBack(LPDEBUG_EVENT debugEvent, int CallReaso void EngineInitPlugins(wchar_t* szEngineFolder) { - bool MoreFiles = true; bool NameHasBeenRegistered = false; PluginInformation myPluginInfo = {}; @@ -87,7 +73,6 @@ void EngineInitPlugins(wchar_t* szEngineFolder) #else wchar_t* szPluginFolder = L"\\plugins\\x86\\"; #endif - typedef bool(TITCALL *fPluginRegister)(char* szPluginName, LPDWORD titanPluginMajorVersion, LPDWORD titanPluginMinorVersion); wchar_t szPluginSearchString[MAX_PATH] = {}; wchar_t szPluginFullPath[MAX_PATH] = {}; fPluginRegister myPluginRegister; @@ -107,10 +92,10 @@ void EngineInitPlugins(wchar_t* szEngineFolder) myPluginInfo.PluginBaseAddress = LoadLibraryW(szPluginFullPath); if(myPluginInfo.PluginBaseAddress != NULL) { - myPluginInfo.TitanResetPlugin = (void*)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanResetPlugin"); - myPluginInfo.TitanReleasePlugin = (void*)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanReleasePlugin"); - myPluginInfo.TitanRegisterPlugin = (void*)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanRegisterPlugin"); - myPluginInfo.TitanDebuggingCallBack = (void*)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanDebuggingCallBack"); + myPluginInfo.TitanResetPlugin = (fPluginResetExec)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanResetPlugin"); + myPluginInfo.TitanReleasePlugin = (fPluginReleaseExec)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanReleasePlugin"); + myPluginInfo.TitanRegisterPlugin = (fPluginRegister)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanRegisterPlugin"); + myPluginInfo.TitanDebuggingCallBack = (fPluginDebugExec)GetProcAddress(myPluginInfo.PluginBaseAddress, "TitanDebuggingCallBack"); myPluginRegister = (fPluginRegister)myPluginInfo.TitanRegisterPlugin; if(myPluginRegister != NULL) { @@ -176,7 +161,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerIsPluginLoaded(char* szPlugin __declspec(dllexport) bool TITCALL ExtensionManagerIsPluginEnabled(char* szPluginName) { - for(unsigned int i = 0; i < Plugin.size(); i++) { if(lstrcmpiA(Plugin.at(i).PluginName, szPluginName) == NULL) @@ -196,7 +180,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerIsPluginEnabled(char* szPlugi __declspec(dllexport) bool TITCALL ExtensionManagerDisableAllPlugins() { - for(unsigned int i = 0; i < Plugin.size(); i++) { Plugin.at(i).PluginDisabled = true; @@ -206,7 +189,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerDisableAllPlugins() __declspec(dllexport) bool TITCALL ExtensionManagerDisablePlugin(char* szPluginName) { - for(unsigned int i = 0; i < Plugin.size(); i++) { if(lstrcmpiA(Plugin.at(i).PluginName, szPluginName) == NULL) @@ -220,7 +202,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerDisablePlugin(char* szPluginN __declspec(dllexport) bool TITCALL ExtensionManagerEnableAllPlugins() { - for(unsigned int i = 0; i < Plugin.size(); i++) { Plugin.at(i).PluginDisabled = false; @@ -230,7 +211,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerEnableAllPlugins() __declspec(dllexport) bool TITCALL ExtensionManagerEnablePlugin(char* szPluginName) { - for(unsigned int i = 0; i < Plugin.size(); i++) { if(lstrcmpiA(Plugin.at(i).PluginName, szPluginName) == NULL) @@ -244,7 +224,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerEnablePlugin(char* szPluginNa __declspec(dllexport) bool TITCALL ExtensionManagerUnloadAllPlugins() { - for(unsigned int i = 0; i < Plugin.size(); i++) { if(FreeLibrary(Plugin.at(i).PluginBaseAddress)) @@ -257,8 +236,6 @@ __declspec(dllexport) bool TITCALL ExtensionManagerUnloadAllPlugins() __declspec(dllexport) bool TITCALL ExtensionManagerUnloadPlugin(char* szPluginName) { - - typedef void(TITCALL *fPluginReleaseExec)(); fPluginReleaseExec myPluginReleaseExec; for(unsigned int i = 0; i < Plugin.size(); i++) diff --git a/TitanEngine/Global.Engine.Extension.h b/TitanEngine/Global.Engine.Extension.h index ae44353..7ec832e 100644 --- a/TitanEngine/Global.Engine.Extension.h +++ b/TitanEngine/Global.Engine.Extension.h @@ -1,6 +1,31 @@ #ifndef _GLOBAL_ENGINE_EXTENSION_H #define _GLOBAL_ENGINE_EXTENSION_H +#include "definitions.h" + +#define PLUGCALL TITCALL + +//typedefs +typedef void(PLUGCALL *fPluginDebugExec)(LPDEBUG_EVENT debugEvent, int CallReason); +typedef bool(PLUGCALL *fPluginRegister)(char* szPluginName, LPDWORD titanPluginMajorVersion, LPDWORD titanPluginMinorVersion); +typedef void(PLUGCALL *fPluginReleaseExec)(); +typedef void(PLUGCALL *fPluginResetExec)(); + +//structs +typedef struct +{ + char PluginName[64]; + DWORD PluginMajorVersion; + DWORD PluginMinorVersion; + HMODULE PluginBaseAddress; + fPluginDebugExec TitanDebuggingCallBack; + fPluginRegister TitanRegisterPlugin; + fPluginReleaseExec TitanReleasePlugin; + fPluginResetExec TitanResetPlugin; + bool PluginDisabled; +} PluginInformation, *PPluginInformation; + +//functions void ExtensionManagerPluginReleaseCallBack(); void ExtensionManagerPluginResetCallBack(); void ExtensionManagerPluginDebugCallBack(LPDEBUG_EVENT debugEvent, int CallReason); diff --git a/TitanEngine/stdafx.h b/TitanEngine/stdafx.h index dac11be..1360b62 100644 --- a/TitanEngine/stdafx.h +++ b/TitanEngine/stdafx.h @@ -49,19 +49,6 @@ #define UE_OPTION_IMPORTER_RETURN_NEAREST_APINAME 12 #define UE_OPTION_IMPORTER_RETURN_API_ORDINAL_NUMBER 13 -typedef struct -{ - char PluginName[64]; - DWORD PluginMajorVersion; - DWORD PluginMinorVersion; - HMODULE PluginBaseAddress; - void* TitanDebuggingCallBack; - void* TitanRegisterPlugin; - void* TitanReleasePlugin; - void* TitanResetPlugin; - bool PluginDisabled; -} PluginInformation, *PPluginInformation; - typedef struct { ULONG_PTR BreakPointAddress;