diff --git a/Extension/CDetour/detours.cpp b/Extension/CDetour/detours.cpp index b4f6cc6..3c9514d 100644 --- a/Extension/CDetour/detours.cpp +++ b/Extension/CDetour/detours.cpp @@ -58,6 +58,23 @@ CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline, return NULL; } +CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline, void *address) +{ + CDetour *detour = new CDetour(callbackfunction, trampoline, address); + if (detour) + { + if (!detour->Init(spengine, gameconf)) + { + delete detour; + return NULL; + } + + return detour; + } + + return NULL; +} + CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame) { enabled = false; @@ -65,6 +82,21 @@ CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame) detour_address = NULL; detour_trampoline = NULL; this->signame = signame; + this->address = address; + this->detour_callback = callbackfunction; + spengine = NULL; + gameconf = NULL; + this->trampoline = trampoline; +} + +CDetour::CDetour(void *callbackfunction, void **trampoline, void *address) +{ + enabled = false; + detoured = false; + detour_address = NULL; + detour_trampoline = NULL; + this->signame = NULL; + this->address = address; this->detour_callback = callbackfunction; spengine = NULL; gameconf = NULL; @@ -100,11 +132,15 @@ bool CDetour::IsEnabled() bool CDetour::CreateDetour() { - if (!gameconf->GetMemSig(signame, &detour_address)) + if (signame != NULL && !gameconf->GetMemSig(signame, &detour_address)) { g_pSM->LogError(myself, "Could not locate %s - Disabling detour", signame); return false; } + else if (address != NULL) + { + detour_address = address; + } if (!detour_address) { diff --git a/Extension/CDetour/detours.h b/Extension/CDetour/detours.h index cc0d8f9..42c55a5 100644 --- a/Extension/CDetour/detours.h +++ b/Extension/CDetour/detours.h @@ -32,7 +32,7 @@ #ifndef _INCLUDE_SOURCEMOD_DETOURS_H_ #define _INCLUDE_SOURCEMOD_DETOURS_H_ -#include "extension.h" +#include "smsdk_ext.h" #include #include #include "detourhelpers.h" @@ -119,6 +119,7 @@ ret name##Class::name(p1type p1name, p2type p2name, p3type p3name, p4type p4name #define DETOUR_CREATE_MEMBER(name, gamedata) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), gamedata); #define DETOUR_CREATE_STATIC(name, gamedata) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), gamedata); +#define DETOUR_CREATE_STATIC_FIXED(name, address) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), address); class GenericClass {}; @@ -157,6 +158,7 @@ public: protected: CDetour(void *callbackfunction, void **trampoline, const char *signame); + CDetour(void *callbackfunction, void **trampoline, void *address); bool Init(ISourcePawnEngine *spengine, IGameConfig *gameconf); private: @@ -179,6 +181,7 @@ private: void **trampoline; const char *signame; + void *address; ISourcePawnEngine *spengine; IGameConfig *gameconf; }; @@ -229,6 +232,7 @@ public: * Note we changed the netadr_s reference into a void* to avoid needing to define the type */ static CDetour *CreateDetour(void *callbackfunction, void **trampoline, const char *signame); + static CDetour *CreateDetour(void *callbackfunction, void **trampoline, void *address); friend class CBlocker; friend class CDetour;