mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-12-06 18:08:31 +00:00
expose khook to plugins
This commit is contained in:
parent
52eb132099
commit
eee0ae787d
@ -31,6 +31,8 @@ class MMSConfig(object):
|
||||
self.versionlib = None
|
||||
self.all_targets = []
|
||||
self.target_archs = set()
|
||||
self.libsafetyhook = {}
|
||||
self.libkhook = {}
|
||||
|
||||
if builder.options.targets:
|
||||
target_archs = builder.options.targets.split(',')
|
||||
@ -378,6 +380,8 @@ if builder.backend == 'amb2':
|
||||
'support/buildbot/PackageScript',
|
||||
]
|
||||
|
||||
builder.Build('core/khook/AMBuilder', { 'KHook': MMS })
|
||||
builder.Build('core/khook/third_party/safetyhook/AMBuilder', { 'SafetyHook': MMS })
|
||||
builder.Build(BuildScripts, { 'MMS': MMS })
|
||||
|
||||
if builder.options.breakpad_dump:
|
||||
|
||||
@ -9,6 +9,14 @@ for sdk_target in MMS.sdk_targets:
|
||||
binary = MMS.HL2Library(builder, cxx, name, sdk)
|
||||
binary.compiler.cxxincludes += [os.path.join(builder.sourcePath, 'core', 'khook', 'include')]
|
||||
|
||||
binary.compiler.defines += ['KHOOK_STANDALONE']
|
||||
for task in MMS.libkhook:
|
||||
if task.target.arch == binary.compiler.target.arch:
|
||||
binary.compiler.linkflags += [task.binary]
|
||||
for task in MMS.libsafetyhook:
|
||||
if task.target.arch == binary.compiler.target.arch:
|
||||
binary.compiler.linkflags += [task.binary]
|
||||
|
||||
binary.sources += [
|
||||
'metamod.cpp',
|
||||
'metamod_console.cpp',
|
||||
|
||||
@ -56,6 +56,7 @@ typedef ConCommandBase ProviderConCommand;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MMIFACE_KHOOK "IKHook" /**< IKHook Pointer */
|
||||
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
||||
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
||||
#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
|
||||
|
||||
@ -486,11 +486,15 @@ using namespace SourceMM;
|
||||
#define PL_EXPOSURE_FUNC(name, var) EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ISmmPlugin, ISmmPlugin, METAMOD_PLAPI_NAME, var);
|
||||
#endif
|
||||
|
||||
namespace KHook {
|
||||
class IKHook;
|
||||
}
|
||||
|
||||
#define PLUGIN_EXPOSE(name, var) \
|
||||
ISmmAPI *g_SMAPI = NULL; \
|
||||
ISmmPlugin *g_PLAPI = NULL; \
|
||||
PluginId g_PLID = (PluginId)0; \
|
||||
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
||||
KHook::IKHook* __exported__khook = nullptr; \
|
||||
PL_EXPOSURE_FUNC(name, var)
|
||||
|
||||
|
||||
@ -502,7 +506,7 @@ using namespace SourceMM;
|
||||
* to use values like g_SHPtr in other files.
|
||||
*/
|
||||
#define PLUGIN_GLOBALVARS() \
|
||||
extern SourceHook::ISourceHook *g_SHPtr; \
|
||||
extern KHook::IKHook* __exported__khook; \
|
||||
extern ISmmAPI *g_SMAPI; \
|
||||
extern ISmmPlugin *g_PLAPI; \
|
||||
extern PluginId g_PLID;
|
||||
@ -512,7 +516,7 @@ using namespace SourceMM;
|
||||
*/
|
||||
#define PLUGIN_SAVEVARS() \
|
||||
g_SMAPI = ismm; \
|
||||
g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
|
||||
__exported__khook = static_cast<KHook::IKHook*>(ismm->MetaFactory(MMIFACE_KHOOK, nullptr, nullptr)); \
|
||||
g_PLAPI = static_cast<ISmmPlugin *>(this); \
|
||||
g_PLID = id;
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include "metamod_util.h"
|
||||
#include "metamod_console.h"
|
||||
#include "provider/provider_base.h"
|
||||
#include "khook.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
@ -93,6 +94,31 @@ MetamodSource g_Metamod;
|
||||
PluginId g_PLID = Pl_Console;
|
||||
SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
|
||||
|
||||
#ifndef KHOOK_STANDALONE
|
||||
static_assert(false, "KHOOK_STANDALONE wasn't defined!");
|
||||
#endif
|
||||
class KHookImpl : public KHook::IKHook {
|
||||
public:
|
||||
virtual KHook::HookID_t SetupHook(void* function, void* hookPtr, void* removedFunctionMFP, KHook::Action* hookAction, void* overrideReturnPtr, void* originalReturnPtr, void* preMFP, void* postMFP, void* returnOverrideMFP, void* returnOriginalMFP, void* callOriginalMFP, bool async = false) override {
|
||||
return KHook::SetupHook(function, hookPtr, removedFunctionMFP, hookAction, overrideReturnPtr, originalReturnPtr, preMFP, postMFP, returnOverrideMFP, returnOriginalMFP, callOriginalMFP, async);
|
||||
}
|
||||
virtual void RemoveHook(KHook::HookID_t id, bool async = false) override {
|
||||
return KHook::RemoveHook(id, async);
|
||||
}
|
||||
virtual void* GetCurrent() override {
|
||||
return KHook::GetCurrent();
|
||||
}
|
||||
virtual void* GetOriginalFunction() override {
|
||||
return KHook::GetOriginalFunction();
|
||||
}
|
||||
virtual void* GetOriginalValuePtr(bool pop = false) override {
|
||||
return KHook::GetOriginalValuePtr(pop);
|
||||
}
|
||||
virtual void* GetOverrideValuePtr(bool pop = false) override {
|
||||
return KHook::GetOverrideValuePtr(pop);
|
||||
}
|
||||
} g_KHook;
|
||||
|
||||
/* Helper Macro */
|
||||
#define IFACE_MACRO(orig,nam) \
|
||||
CPluginManager::CPlugin *pl; \
|
||||
@ -806,7 +832,11 @@ void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
|
||||
}
|
||||
|
||||
/* First check ours... we get first chance! */
|
||||
if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
|
||||
if (strcmp(iface, MMIFACE_KHOOK) == 0)
|
||||
{
|
||||
return static_cast<void*>(static_cast<KHook::IKHook*>(&g_KHook));
|
||||
}
|
||||
else if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user