Add Raw Address support to CDetour.

This commit is contained in:
KyleSanderson
2014-01-14 17:49:09 -07:00
parent 420f85ff72
commit 54b9500974
2 changed files with 42 additions and 2 deletions
+37 -1
View File
@@ -58,6 +58,23 @@ CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline,
return NULL; 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) CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame)
{ {
enabled = false; enabled = false;
@@ -65,6 +82,21 @@ CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame)
detour_address = NULL; detour_address = NULL;
detour_trampoline = NULL; detour_trampoline = NULL;
this->signame = signame; 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; this->detour_callback = callbackfunction;
spengine = NULL; spengine = NULL;
gameconf = NULL; gameconf = NULL;
@@ -100,11 +132,15 @@ bool CDetour::IsEnabled()
bool CDetour::CreateDetour() 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); g_pSM->LogError(myself, "Could not locate %s - Disabling detour", signame);
return false; return false;
} }
else if (address != NULL)
{
detour_address = address;
}
if (!detour_address) if (!detour_address)
{ {
+5 -1
View File
@@ -32,7 +32,7 @@
#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_ #ifndef _INCLUDE_SOURCEMOD_DETOURS_H_
#define _INCLUDE_SOURCEMOD_DETOURS_H_ #define _INCLUDE_SOURCEMOD_DETOURS_H_
#include "extension.h" #include "smsdk_ext.h"
#include <jit/jit_helpers.h> #include <jit/jit_helpers.h>
#include <jit/x86/x86_macros.h> #include <jit/x86/x86_macros.h>
#include "detourhelpers.h" #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_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(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 {}; class GenericClass {};
@@ -157,6 +158,7 @@ public:
protected: protected:
CDetour(void *callbackfunction, void **trampoline, const char *signame); CDetour(void *callbackfunction, void **trampoline, const char *signame);
CDetour(void *callbackfunction, void **trampoline, void *address);
bool Init(ISourcePawnEngine *spengine, IGameConfig *gameconf); bool Init(ISourcePawnEngine *spengine, IGameConfig *gameconf);
private: private:
@@ -179,6 +181,7 @@ private:
void **trampoline; void **trampoline;
const char *signame; const char *signame;
void *address;
ISourcePawnEngine *spengine; ISourcePawnEngine *spengine;
IGameConfig *gameconf; IGameConfig *gameconf;
}; };
@@ -229,6 +232,7 @@ public:
* Note we changed the netadr_s reference into a void* to avoid needing to define the type * 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, const char *signame);
static CDetour *CreateDetour(void *callbackfunction, void **trampoline, void *address);
friend class CBlocker; friend class CBlocker;
friend class CDetour; friend class CDetour;