From c303af4d9dfe6b4db8f0e04e8658cad92df74f3d Mon Sep 17 00:00:00 2001 From: BotoX Date: Thu, 4 Aug 2016 16:08:20 +0200 Subject: [PATCH] added windows support --- extension.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- smsdk_config.h | 4 ++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/extension.cpp b/extension.cpp index 25b8522..b399622 100644 --- a/extension.cpp +++ b/extension.cpp @@ -64,14 +64,36 @@ public: CEventAction *m_pNext; DECLARE_SIMPLE_DATADESC(); +#ifdef PLATFORM_WINDOWS + static int *s_pBlocksAllocated; + static void **s_ppHeadOfFreeList; +#else static void (*s_pOperatorDeleteFunc)(void *pMem); +#endif + static void operator delete(void *pMem); }; -void (*CEventAction::s_pOperatorDeleteFunc)(void *pMem); + +#ifdef PLATFORM_WINDOWS + int *CEventAction::s_pBlocksAllocated; + void **CEventAction::s_ppHeadOfFreeList; +#else + void (*CEventAction::s_pOperatorDeleteFunc)(void *pMem); +#endif void CEventAction::operator delete(void *pMem) { +#ifdef PLATFORM_WINDOWS + (*s_pBlocksAllocated)--; + + // make the block point to the first item in the list + *((void **)pMem) = *s_ppHeadOfFreeList; + + // the list head is now the new block + *s_ppHeadOfFreeList = pMem; +#else s_pOperatorDeleteFunc(pMem); +#endif } class CBaseEntityOutput @@ -418,11 +440,34 @@ bool Outputinfo::SDK_OnLoad(char *error, size_t maxlen, bool late) return false; } +#ifdef PLATFORM_WINDOWS + char path[PLATFORM_MAX_PATH]; + g_pSM->BuildPath(Path_Game, path, sizeof(path), "bin/server.dll"); + + HMODULE hModule = GetModuleHandle(path); + + uintptr_t pCode = (uintptr_t)memutils->FindPattern(hModule, + "\x8B\x4C\x24\x28\x89\x41\x14\x8B\x4F\x18\xA1****\xFF\x0D****\x89\x07\x89\x3D****\x8B\xF9\xEB\x07", + 33); + + if(!pCode) + { + snprintf(error, maxlen, "Failed to find windows signature.\n"); + return false; + } + + uintptr_t ppHeadOfFreeList = *(uintptr_t *)(pCode + 11); + uintptr_t pBlocksAllocated = *(uintptr_t *)(pCode + 17); + + CEventAction::s_pBlocksAllocated = (int *)pBlocksAllocated; + CEventAction::s_ppHeadOfFreeList = (void **)ppHeadOfFreeList; +#else if(!g_pGameConf->GetMemSig("CEventAction__operator_delete", (void **)(&CEventAction::s_pOperatorDeleteFunc)) || !CEventAction::s_pOperatorDeleteFunc) { snprintf(error, maxlen, "Failed to find CEventAction__operator_delete function.\n"); return false; } +#endif return true; } diff --git a/smsdk_config.h b/smsdk_config.h index 9006c1e..7898419 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -40,7 +40,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "OutputInfo" #define SMEXT_CONF_DESCRIPTION "Read entity outputs" -#define SMEXT_CONF_VERSION "1.0" +#define SMEXT_CONF_VERSION "1.1" #define SMEXT_CONF_AUTHOR "BotoX" #define SMEXT_CONF_URL "" #define SMEXT_CONF_LOGTAG "OUTPUTINFO" @@ -64,7 +64,7 @@ //#define SMEXT_ENABLE_PLAYERHELPERS //#define SMEXT_ENABLE_DBMANAGER #define SMEXT_ENABLE_GAMECONF -//#define SMEXT_ENABLE_MEMUTILS +#define SMEXT_ENABLE_MEMUTILS #define SMEXT_ENABLE_GAMEHELPERS //#define SMEXT_ENABLE_TIMERSYS //#define SMEXT_ENABLE_THREADER