A small idiotproof library for working with and hooking source engine interfaces. Uses my custom vtable hook class.
Here's an example of how to use it that's correct:
CPP Code:
//used for CreateInterfaceFn Definition
#include "InterfaceFactory.h"
//contains the interface generation macros
#include "macros.h"
V_INTERFACE(IVClient17, 0)
METHOD(0, int, Init, ARGS_SIGNATURE(CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, void *pGlobals), ARGS_INSTANCE_SIGNATURE(CreateInterfaceFn, CreateInterfaceFn, void*), ARGS_INSTANCE(appSystemFactory, physicsFactory, pGlobals))
METHOD(1, void, PostInit, ARGS_SIGNATURE(void), ARGS_INSTANCE_SIGNATURE(), ARGS_INSTANCE())
METHOD(2, void, Shutdown, ARGS_SIGNATURE(void), ARGS_INSTANCE_SIGNATURE(), ARGS_INSTANCE())
END_V_INTERFACE
void hookShutdown(IVClient17 * client, void * shutdownhookfunc){
client->hookMethodByIndex(shutdownhookfunc, 2);
}
void callShutdown(IVClient17* client){
client->Shutdown();
}
Here's the resulting code generated by the macros:
CPP Code:
class IVClient17 : public Interface{
private:
RawInterface instance;
public:
IVClient17(RawInterface rawInter) :Interface(rawInter, 0 * 4) {
instance = rawInter;
}
int Init(CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, void *pGlobals){
return (((int(__thiscall*)(void*, CreateInterfaceFn, CreateInter
faceFn, void*))this->getMethodByIndex(0))((void*)instance, appSystemFactory, physicsFactory, pGlobals));
}
void PostInit(void){ return (((void(__thiscall*)(void*))this->getMethodByIndex(1))((void*)instance)); }
void Shutdown(void){ return (((void(__thiscall*)(void*))this->getMethodByIndex(2))((void*)instance)); }
};
Edit:
Here's how you add a static virtual method:
CPP Code:
METHOD(12, void, ExampleStaticVirtualMethod, ARGS_SIGNATURE(int a, int b, int c,), ARGS_STATIC_SIGNATURE(int,int,int), ARGS_STATIC(a,b,c))
you basically just swap all INSTANCE for STATIC in the macro names