From 0c125bbdd1743012e68286c77455445831f84881 Mon Sep 17 00:00:00 2001 From: KliPPy Date: Fri, 24 Feb 2017 01:07:43 +0100 Subject: [PATCH] Fix SetString, hook FreeEntPrivateData instead of ED_Free --- source/amxxsdk/moduleconfig.h | 2 +- source/module.cpp | 30 +++++++++--------------------- source/natives.cpp | 2 +- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/source/amxxsdk/moduleconfig.h b/source/amxxsdk/moduleconfig.h index 393b0d6..34c8d90 100644 --- a/source/amxxsdk/moduleconfig.h +++ b/source/amxxsdk/moduleconfig.h @@ -15,7 +15,7 @@ * to add multiple entries. */ #define MODULE_NAME "Custom Entity Data" -#define MODULE_VERSION "1.0.0" +#define MODULE_VERSION "1.0.1" #define MODULE_AUTHOR "KliPPy" #define MODULE_URL "http://" #define MODULE_LOGTAG "CED" diff --git a/source/module.cpp b/source/module.cpp index 079fd5f..395954a 100644 --- a/source/module.cpp +++ b/source/module.cpp @@ -5,14 +5,9 @@ static CHooker Hooker; -using FN_ED_Free = void (*)(edict_t *); -//typedef void (*FN_ED_Free)(edict_t *); +static CFunc* funcFreeEntPrivateData = nullptr; -static FN_ED_Free pfnED_Free = nullptr; -static CFunc* funcED_Free = nullptr; - - -void ED_Free_Hook(edict_t *ed) +void FreeEntPrivateData_Hook(edict_t *ed) { GET_ORIG_FUNC(func); @@ -20,33 +15,26 @@ void ED_Free_Hook(edict_t *ed) { g_entityData[g_engfuncs.pfnIndexOfEdict(ed)].clear(); - pfnED_Free(ed); + g_engfuncs.pfnFreeEntPrivateData(ed); - funcED_Free->Patch(); + funcFreeEntPrivateData->Patch(); } } bool CreateHooks() { -#ifdef KE_WINDOWS - pfnED_Free = Hooker.MemorySearch("0x55,0x8B,0xEC,0x56,0x8B,0x75,*,0x57,0x33,0xFF,0x39,0x3E", (void *)gpGlobals, FALSE); -#else - pfnED_Free = Hooker.MemorySearch("ED_Free", (void *)gpGlobals, TRUE); -#endif - - funcED_Free = Hooker.CreateHook((void *)pfnED_Free, (void *)ED_Free_Hook, TRUE); - if(funcED_Free == nullptr) + funcFreeEntPrivateData = Hooker.CreateHook((void *)g_engfuncs.pfnFreeEntPrivateData, (void *)FreeEntPrivateData_Hook, TRUE); + if(funcFreeEntPrivateData == nullptr) { - g_engfuncs.pfnServerPrint("Failed to create ED_Free() hook...\n"); + g_engfuncs.pfnServerPrint("[CED] Failed to create FreeEntPrivateData() hook...\n"); return false; } - g_engfuncs.pfnServerPrint("Successfully hooked ED_Free()\n"); - return true; } void RestoreHooks() { - funcED_Free->Restore(); + if(funcFreeEntPrivateData != nullptr) + funcFreeEntPrivateData->Restore(); } \ No newline at end of file diff --git a/source/natives.cpp b/source/natives.cpp index fd1cc7b..f7d0626 100644 --- a/source/natives.cpp +++ b/source/natives.cpp @@ -40,7 +40,7 @@ static cell Native_SetString(AMX *amx, cell *params) { NATIVE_SETUP(); - g_entityData[index].replace(key, ke::AutoPtr(new EntDataString(MF_GetAmxString(amx, params[3], 1, &dummyLen)))); + g_entityData[index].replace(key, ke::AutoPtr(new EntDataString(MF_GetAmxString(amx, params[3], 2, &dummyLen)))); return 0; }