1.1 --- a/sourcehook/sourcehook.h Thu Apr 14 16:19:07 2005 +0000
1.2 +++ b/sourcehook/sourcehook.h Sat Apr 16 16:55:53 2005 +0000
1.3 @@ -12,6 +12,14 @@
1.4 #ifndef __SOURCEHOOK_H__
1.5 #define __SOURCEHOOK_H__
1.6
1.7 +#ifndef SH_GLOB_SHPTR
1.8 +#define SH_GLOB_SHPTR g_SHPtr
1.9 +#endif
1.10 +
1.11 +#ifndef SH_GLOB_PLUGPTR
1.12 +#define SH_GLOB_PLUGPTR g_Plug
1.13 +#endif
1.14 +
1.15 #define SH_ASSERT(x) if (!(x)) __asm { int 3 }
1.16
1.17 // System
1.18 @@ -73,26 +81,24 @@
1.19 */
1.20 typedef void* Plugin;
1.21
1.22 - enum HookerAction
1.23 + enum HookManagerAction
1.24 {
1.25 HA_GetInfo = 0, // -> Only store info
1.26 HA_Register, // -> Save the pointer for future reference
1.27 - HA_Unregister, // -> Clear the saved pointer
1.28 - HA_IfaceAdded, // -> Request call class
1.29 - HA_IfaceRemoved // -> Release call class
1.30 + HA_Unregister // -> Clear the saved pointer
1.31 };
1.32
1.33 - struct HookerInfo;
1.34 + struct HookManagerInfo;
1.35
1.36 /**
1.37 - * @brief Pointer to hooker type
1.38 + * @brief Pointer to hook manager type
1.39 *
1.40 - * A "hooker" is a the only thing that knows the actual protoype of the function at compile time.
1.41 + * A "hook manager" is a the only thing that knows the actual protoype of the function at compile time.
1.42 *
1.43 - * @param hi A pointer to a HookerInfo structure. The hooker should fill it and store it for
1.44 + * @param hi A pointer to a HookManagerInfo structure. The hook manager should fill it and store it for
1.45 * future reference (mainly if something should get hooked to its hookfunc)
1.46 */
1.47 - typedef int (*Hooker)(HookerAction ha, HookerInfo *hi);
1.48 + typedef int (*HookManagerPubFunc)(HookManagerAction ha, HookManagerInfo *hi);
1.49
1.50 class ISHDelegate
1.51 {
1.52 @@ -126,9 +132,9 @@
1.53 };
1.54
1.55 /**
1.56 - * @brief This structure contains information about a hooker (hook manager)
1.57 + * @brief This structure contains information about a hook manager (hook manager)
1.58 */
1.59 - struct HookerInfo
1.60 + struct HookManagerInfo
1.61 {
1.62 struct Iface
1.63 {
1.64 @@ -148,11 +154,11 @@
1.65 }
1.66 };
1.67 Plugin plug; //!< The owner plugin
1.68 - const char *proto; //!< The prototype of the function the hooker is responsible for
1.69 + const char *proto; //!< The prototype of the function the hook manager is responsible for
1.70 int vtbl_idx; //!< The vtable index
1.71 int vtbl_offs; //!< The vtable offset
1.72 int thisptr_offs; //!< The this-pointer-adjuster
1.73 - Hooker func; //!< The interface to the hooker
1.74 + HookManagerPubFunc func; //!< The interface to the hook manager
1.75
1.76 int hookfunc_vtbl_idx; //!< the vtable index of the hookfunc
1.77 int hookfunc_vtbl_offs; //!< the vtable offset of the hookfunc
1.78 @@ -203,11 +209,11 @@
1.79 * @param plug The unique identifier of the plugin that calls this function
1.80 * @param iface The interface pointer
1.81 * @param ifacesize The size of the class iface points to
1.82 - * @param myHooker A hooker function that should be capable of handling the function
1.83 + * @param myHookMan A hook manager function that should be capable of handling the function
1.84 * @param handler A pointer to a FastDelegate containing the hook handler
1.85 * @param post Set to true if you want a post handler
1.86 */
1.87 - virtual bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
1.88 + virtual bool AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
1.89
1.90 /**
1.91 * @brief Removes a hook.
1.92 @@ -216,14 +222,14 @@
1.93 *
1.94 * @param plug The unique identifier of the plugin that calls this function
1.95 * @param iface The interface pointer
1.96 - * @param myHooker A hooker function that should be capable of handling the function
1.97 + * @param myHookMan A hook manager function that should be capable of handling the function
1.98 * @param handler A pointer to a FastDelegate containing the hook handler
1.99 * @param post Set to true if you want a post handler
1.100 */
1.101 - virtual bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
1.102 + virtual bool RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
1.103
1.104 /**
1.105 - * @brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
1.106 + * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
1.107 *
1.108 * @param plug The unique identifier of the plugin in question
1.109 */
1.110 @@ -251,7 +257,7 @@
1.111 virtual const void *GetOverrideRet() = 0; //!< Gets the override result. If none is specified, NULL
1.112 virtual void *GetIfacePtr() = 0; //!< Gets the interface pointer
1.113 //////////////////////////////////////////////////////////////////////////
1.114 - // For hookers
1.115 + // For hook managers
1.116 virtual META_RES &GetCurResRef() = 0; //!< Gets the pointer to the current meta result
1.117 virtual META_RES &GetPrevResRef() = 0; //!< Gets the pointer to the previous meta result
1.118 virtual META_RES &GetStatusRef() = 0; //!< Gets the pointer to the status variable
1.119 @@ -263,15 +269,15 @@
1.120
1.121 //////////////////////////////////////////////////////////////////////////
1.122 // Macro interface
1.123 -#define SET_META_RESULT(result) g_SHPtr->SetRes(result)
1.124 -#define RETURN_META(result) do { g_SHPtr->SetRes(result); return; } while(0)
1.125 -#define RETURN_META_VALUE(result, value) do { g_SHPtr->SetRes(result); return (value); } while(0)
1.126 +#define SET_META_RESULT(result) SH_GLOB_SHPTR->SetRes(result)
1.127 +#define RETURN_META(result) do { SH_GLOB_SHPTR->SetRes(result); return; } while(0)
1.128 +#define RETURN_META_VALUE(result, value) do { SH_GLOB_SHPTR->SetRes(result); return (value); } while(0)
1.129
1.130 -#define META_RESULT_STATUS g_SHPtr->GetStatus()
1.131 -#define META_RESULT_PREVIOUS g_SHPtr->GetPrevRes()
1.132 -#define META_RESULT_ORIG_RET(type) *(const type *)g_SHPtr->GetOrigRet()
1.133 -#define META_RESULT_OVERRIDE_RET(type) *(const type *)g_SHPtr->GetOverrideRet()
1.134 -#define META_IFACEPTR g_SHPtr->GetIfacePtr()
1.135 +#define META_RESULT_STATUS SH_GLOB_SHPTR->GetStatus()
1.136 +#define META_RESULT_PREVIOUS SH_GLOB_SHPTR->GetPrevRes()
1.137 +#define META_RESULT_ORIG_RET(type) *(const type *)SH_GLOB_SHPTR->GetOrigRet()
1.138 +#define META_RESULT_OVERRIDE_RET(type) *(const type *)SH_GLOB_SHPTR->GetOverrideRet()
1.139 +#define META_IFACEPTR SH_GLOB_SHPTR->GetIfacePtr()
1.140
1.141
1.142 /**
1.143 @@ -280,8 +286,8 @@
1.144 * @param ifacetype The type of the interface
1.145 * @param ifaceptr The interface pointer
1.146 */
1.147 -#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(g_SHPtr->GetCallClass(ifaceptr, sizeof(ifacetype)))
1.148 -#define SH_RELEASE_CALLCLASS(ptr) g_SHPtr->ReleaseCallClass(reinterpret_cast<void*>(ptr))
1.149 +#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(SH_GLOB_SHPTR->GetCallClass(ifaceptr, sizeof(ifacetype)))
1.150 +#define SH_RELEASE_CALLCLASS(ptr) SH_GLOB_SHPTR->ReleaseCallClass(reinterpret_cast<void*>(ptr))
1.151
1.152 #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.153 SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
1.154 @@ -303,8 +309,8 @@
1.155 //////////////////////////////////////////////////////////////////////////
1.156 #define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
1.157
1.158 -#define SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
1.159 - static int Hooker(HookerAction action, HookerInfo *param) \
1.160 +#define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
1.161 + static int HookManPubFunc(HookManagerAction action, HookManagerInfo *param) \
1.162 { \
1.163 if (action == HA_GetInfo) \
1.164 { \
1.165 @@ -342,28 +348,28 @@
1.166 struct SH_FHCls(ifacetype,ifacefunc,overload) \
1.167 { \
1.168 static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
1.169 - static HookerInfo *ms_HI; \
1.170 + static HookManagerInfo *ms_HI; \
1.171 static const char *ms_Proto; \
1.172 - SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
1.173 + SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
1.174
1.175 #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
1.176 }; \
1.177 const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
1.178 SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
1.179 - HookerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
1.180 + HookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
1.181 bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
1.182 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
1.183 { \
1.184 - return g_SHPtr->AddHook(g_Plug, iface, sizeof(ifacetype), \
1.185 - SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, \
1.186 + return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, sizeof(ifacetype), \
1.187 + SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
1.188 new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
1.189 } \
1.190 bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
1.191 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
1.192 { \
1.193 CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
1.194 - return g_SHPtr->RemoveHook(g_Plug, iface, \
1.195 - SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, &tmp, post); \
1.196 + return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, \
1.197 + SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
1.198 } \
1.199 }
1.200
1.201 @@ -371,25 +377,25 @@
1.202 /* 1) Find the iface ptr */ \
1.203 /* 1.1) Adjust to original this pointer */ \
1.204 void *origthis = this - ms_HI->thisptr_offs; \
1.205 - std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
1.206 + std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
1.207 ms_HI->ifaces.end(), origthis); \
1.208 SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
1.209 - HookerInfo::Iface &ci = *ifaceiter; \
1.210 + HookManagerInfo::Iface &ci = *ifaceiter; \
1.211 /* 2) Declare some vars and set it up */ \
1.212 - std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
1.213 - std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
1.214 + std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
1.215 + std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
1.216 rettype orig_ret, override_ret, plugin_ret; \
1.217 - META_RES &cur_res = g_SHPtr->GetCurResRef(); \
1.218 - META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
1.219 - META_RES &status = g_SHPtr->GetStatusRef(); \
1.220 + META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
1.221 + META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
1.222 + META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
1.223 status = MRES_IGNORED; \
1.224 - g_SHPtr->SetIfacePtr(ci.ptr); \
1.225 - g_SHPtr->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
1.226 - g_SHPtr->SetOverrideRet(NULL);
1.227 + SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
1.228 + SH_GLOB_SHPTR->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
1.229 + SH_GLOB_SHPTR->SetOverrideRet(NULL);
1.230
1.231 #define SH_CALL_HOOKS(post, params) \
1.232 prev_res = MRES_IGNORED; \
1.233 - for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
1.234 + for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
1.235 { \
1.236 cur_res = MRES_IGNORED; \
1.237 plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
1.238 @@ -399,7 +405,7 @@
1.239 if (cur_res >= MRES_OVERRIDE) \
1.240 { \
1.241 override_ret = plugin_ret; \
1.242 - g_SHPtr->SetOverrideRet(&override_ret); \
1.243 + SH_GLOB_SHPTR->SetOverrideRet(&override_ret); \
1.244 } \
1.245 }
1.246
1.247 @@ -424,23 +430,23 @@
1.248 /* 1) Find the iface ptr */ \
1.249 /* 1.1) Adjust to original this pointer */ \
1.250 void *origthis = this - ms_HI->thisptr_offs; \
1.251 - std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
1.252 + std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
1.253 ms_HI->ifaces.end(), origthis); \
1.254 SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
1.255 - HookerInfo::Iface &ci = *ifaceiter; \
1.256 + HookManagerInfo::Iface &ci = *ifaceiter; \
1.257 /* 2) Declare some vars and set it up */ \
1.258 - std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
1.259 - std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
1.260 - META_RES &cur_res = g_SHPtr->GetCurResRef(); \
1.261 - META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
1.262 - META_RES &status = g_SHPtr->GetStatusRef(); \
1.263 + std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
1.264 + std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
1.265 + META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
1.266 + META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
1.267 + META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
1.268 status = MRES_IGNORED; \
1.269 - g_SHPtr->SetIfacePtr(ci.ptr); \
1.270 - g_SHPtr->SetOverrideRet(NULL);
1.271 + SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
1.272 + SH_GLOB_SHPTR->SetOverrideRet(NULL);
1.273
1.274 #define SH_CALL_HOOKS_void(post, params) \
1.275 prev_res = MRES_IGNORED; \
1.276 - for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
1.277 + for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
1.278 { \
1.279 cur_res = MRES_IGNORED; \
1.280 reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \