mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-12-07 02:18:30 +00:00
Initial detour code.
This commit is contained in:
parent
a112f84e1f
commit
9437b653fa
@ -250,6 +250,7 @@ class MMSConfig(object):
|
|||||||
compiler.cxxincludes += [
|
compiler.cxxincludes += [
|
||||||
os.path.join(context.currentSourcePath),
|
os.path.join(context.currentSourcePath),
|
||||||
os.path.join(context.currentSourcePath, 'sourcehook'),
|
os.path.join(context.currentSourcePath, 'sourcehook'),
|
||||||
|
os.path.join(context.currentSourcePath, 'detourhook'),
|
||||||
os.path.join(context.sourcePath, 'loader'),
|
os.path.join(context.sourcePath, 'loader'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,9 @@ for sdk_name in MMS.sdks:
|
|||||||
'sourcehook/sourcehook_impl_cproto.cpp',
|
'sourcehook/sourcehook_impl_cproto.cpp',
|
||||||
'sourcehook/sourcehook_impl_cvfnptr.cpp',
|
'sourcehook/sourcehook_impl_cvfnptr.cpp',
|
||||||
'gamedll_bridge.cpp',
|
'gamedll_bridge.cpp',
|
||||||
'vsp_bridge.cpp'
|
'vsp_bridge.cpp',
|
||||||
|
'detourhook/detourhook.cpp',
|
||||||
|
'detourhook/asm/asm.c'
|
||||||
]
|
]
|
||||||
nodes = builder.Add(binary)
|
nodes = builder.Add(binary)
|
||||||
MMS.binaries += [nodes]
|
MMS.binaries += [nodes]
|
||||||
|
|||||||
@ -58,6 +58,7 @@ class ConCommandBase;
|
|||||||
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
||||||
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
||||||
#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
|
#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
|
||||||
|
#define MMIFACE_DETOURHOOK "IDetourHook"
|
||||||
#define IFACE_MAXNUM 999 /**< Maximum interface version */
|
#define IFACE_MAXNUM 999 /**< Maximum interface version */
|
||||||
|
|
||||||
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sourcehook.h>
|
#include <sourcehook.h>
|
||||||
|
#include <detourhook.h>
|
||||||
#include <IPluginManager.h>
|
#include <IPluginManager.h>
|
||||||
#include <ISmmAPI.h>
|
#include <ISmmAPI.h>
|
||||||
#include <ISmmPluginExt.h>
|
#include <ISmmPluginExt.h>
|
||||||
@ -433,8 +434,8 @@ using namespace SourceMM;
|
|||||||
*
|
*
|
||||||
* @param name Deprecated - should be a variable name (like name).
|
* @param name Deprecated - should be a variable name (like name).
|
||||||
* @param var Name of the variable that contains the singleton.
|
* @param var Name of the variable that contains the singleton.
|
||||||
* This macro automatically takes the address of it, so
|
* This macro automatically takes the address of it, so
|
||||||
* you should not pass a pointer to your plugin's
|
* you should not pass a pointer to your plugin's
|
||||||
* singleton.
|
* singleton.
|
||||||
*/
|
*/
|
||||||
#define PLUGIN_EXPOSE(name, var) \
|
#define PLUGIN_EXPOSE(name, var) \
|
||||||
@ -442,6 +443,7 @@ using namespace SourceMM;
|
|||||||
ISmmPlugin *g_PLAPI = NULL; \
|
ISmmPlugin *g_PLAPI = NULL; \
|
||||||
PluginId g_PLID = (PluginId)0; \
|
PluginId g_PLID = (PluginId)0; \
|
||||||
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
||||||
|
DetourHook::IDetourHook *g_DHPtr = NULL; \
|
||||||
SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
|
SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
|
||||||
if (name && !strcmp(name, METAMOD_PLAPI_NAME)) { \
|
if (name && !strcmp(name, METAMOD_PLAPI_NAME)) { \
|
||||||
return static_cast<void *>(&var); \
|
return static_cast<void *>(&var); \
|
||||||
@ -450,12 +452,13 @@ using namespace SourceMM;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This should be in one of your header files, if you wish
|
* @brief This should be in one of your header files, if you wish
|
||||||
* to use values like g_SHPtr in other files.
|
* to use values like g_SHPtr in other files.
|
||||||
*/
|
*/
|
||||||
#define PLUGIN_GLOBALVARS() \
|
#define PLUGIN_GLOBALVARS() \
|
||||||
extern SourceHook::ISourceHook *g_SHPtr; \
|
extern SourceHook::ISourceHook *g_SHPtr; \
|
||||||
|
extern DetourHook::IDetourHook *g_DHPtr; \
|
||||||
extern ISmmAPI *g_SMAPI; \
|
extern ISmmAPI *g_SMAPI; \
|
||||||
extern ISmmPlugin *g_PLAPI; \
|
extern ISmmPlugin *g_PLAPI; \
|
||||||
extern PluginId g_PLID;
|
extern PluginId g_PLID;
|
||||||
@ -466,6 +469,7 @@ using namespace SourceMM;
|
|||||||
#define PLUGIN_SAVEVARS() \
|
#define PLUGIN_SAVEVARS() \
|
||||||
g_SMAPI = ismm; \
|
g_SMAPI = ismm; \
|
||||||
g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
|
g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
|
||||||
|
g_DHPtr = static_cast<DetourHook::IDetourHook *>(ismm->MetaFactory(MMIFACE_DETOURHOOK, NULL, NULL)); \
|
||||||
g_PLAPI = static_cast<ISmmPlugin *>(this); \
|
g_PLAPI = static_cast<ISmmPlugin *>(this); \
|
||||||
g_PLID = id;
|
g_PLID = id;
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
#if defined __linux__
|
#if defined __linux__
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "detourhook\detourhook_impl.h"
|
||||||
|
|
||||||
using namespace SourceMM;
|
using namespace SourceMM;
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
@ -109,6 +110,8 @@ MetamodSource g_Metamod;
|
|||||||
PluginId g_PLID = Pl_Console;
|
PluginId g_PLID = Pl_Console;
|
||||||
CSourceHookImpl g_SourceHook;
|
CSourceHookImpl g_SourceHook;
|
||||||
ISourceHook *g_SHPtr = &g_SourceHook;
|
ISourceHook *g_SHPtr = &g_SourceHook;
|
||||||
|
DetourHook::CDetourHookImpl g_DetourHook;
|
||||||
|
DetourHook::IDetourHook *g_DHPtr = &g_DetourHook;
|
||||||
SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
|
SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
|
||||||
|
|
||||||
/* Helper Macro */
|
/* Helper Macro */
|
||||||
@ -845,6 +848,14 @@ void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
|
|||||||
}
|
}
|
||||||
return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
|
return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
|
||||||
}
|
}
|
||||||
|
else if (strcmp(iface, MMIFACE_DETOURHOOK) == 0)
|
||||||
|
{
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
*ret = META_IFACE_OK;
|
||||||
|
}
|
||||||
|
return static_cast<void *>(static_cast<DetourHook::IDetourHook *>(&g_DetourHook));
|
||||||
|
}
|
||||||
else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
|
else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
|
||||||
{
|
{
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user