1.1 --- a/core-legacy/sourcehook/generate/sourcehook.hxx Fri Feb 27 00:19:50 2009 -0600
1.2 +++ b/core-legacy/sourcehook/generate/sourcehook.hxx Wed Oct 28 23:14:32 2009 -0700
1.3 @@ -1,5 +1,5 @@
1.4 /* ======== SourceHook ========
1.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 +* Copyright (C) 2004-2007 Metamod:Source Development Team
1.7 * No warranties of any kind
1.8 *
1.9 * License: zlib/libpng
1.10 @@ -22,7 +22,14 @@
1.11 // 3 - Added "hook loop status variable"
1.12 // 4 - Reentrant
1.13 #define SH_IFACE_VERSION 4
1.14 -#define SH_IMPL_VERSION 3
1.15 +
1.16 +// Impl versions:
1.17 +// ???
1.18 +// 4 - addition of hook ids and vp hooks (with them, AddHookNew and RemoveHookNew)
1.19 +// This is not a SH_IFACE_VERSION change so that old plugins continue working!
1.20 +// 5 - addition of direct vp hooks (new hook mode; from now on AddHookNew checks for
1.21 +// invalid hookmode -> impl version won't have to change because of things like this)
1.22 +#define SH_IMPL_VERSION 5
1.23
1.24 // Hookman version:
1.25 // 1 - Support for recalls, performance optimisations
1.26 @@ -291,15 +298,12 @@
1.27 }
1.28 };
1.29
1.30 - template<class B> struct CallClass
1.31 + template<class B> struct DeprecatedCallClass
1.32 {
1.33 virtual B *GetThisPtr() = 0;
1.34 virtual void *GetOrigFunc(int vtbloffs, int vtblidx) = 0;
1.35 };
1.36
1.37 - typedef CallClass<void> GenericCallClass;
1.38 - typedef CallClass<EmptyClass> ManualCallClass;
1.39 -
1.40 // 09.08.2008 (6 AM, I just woke up, the others are still sleeping so i finally can use this notebook !!)
1.41 // - Today is an important day.
1.42 // I'm adding support for functions which return references.
1.43 @@ -401,14 +405,14 @@
1.44 * @param iface The interface pointer
1.45 * @param size Size of the class instance
1.46 */
1.47 - virtual GenericCallClass *GetCallClass(void *iface, size_t size) = 0;
1.48 + virtual DeprecatedCallClass<void> *GetCallClass(void *iface, size_t size) = 0;
1.49
1.50 /**
1.51 * @brief Release a callclass
1.52 *
1.53 * @param ptr Pointer to the callclass
1.54 */
1.55 - virtual void ReleaseCallClass(GenericCallClass *ptr) = 0;
1.56 + virtual void ReleaseCallClass(DeprecatedCallClass<void> *ptr) = 0;
1.57
1.58 virtual void SetRes(META_RES res) = 0; //!< Sets the meta result
1.59 virtual META_RES GetPrevRes() = 0; //!< Gets the meta result of the
1.60 @@ -479,7 +483,65 @@
1.61 virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
1.62 void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr) = 0;
1.63
1.64 - //!<
1.65 + /**
1.66 + * @brief Modes for the new AddHook
1.67 + */
1.68 + enum AddHookMode
1.69 + {
1.70 + Hook_Normal,
1.71 + Hook_VP,
1.72 + Hook_DVP
1.73 + };
1.74 +
1.75 + /**
1.76 + * @brief Add a (VP) hook.
1.77 + *
1.78 + * @return non-zero hook id on success, 0 otherwise
1.79 + *
1.80 + * @param plug The unique identifier of the plugin that calls this function
1.81 + * @param mode Can be either Hook_Normal or Hook_VP (vtable-wide hook)
1.82 + * @param iface The interface pointer
1.83 + * @param ifacesize The size of the class iface points to
1.84 + * @param myHookMan A hook manager function that should be capable of handling the function
1.85 + * @param handler A pointer to a FastDelegate containing the hook handler
1.86 + * @param post Set to true if you want a post handler
1.87 + */
1.88 + virtual int AddHookNew(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
1.89 + ISHDelegate *handler, bool post) = 0;
1.90 +
1.91 + /**
1.92 + * @brief Remove a VP hook by ID.
1.93 + *
1.94 + * @return true on success, false otherwise
1.95 + *
1.96 + * @param plug The unique identifier of the plugin that calls this function
1.97 + * @param hookid The hook id (returned by AddHookNew)
1.98 + */
1.99 + virtual bool RemoveHookByID(Plugin plug, int hookid) = 0;
1.100 +
1.101 + /**
1.102 + * @brief Makes sure that hooks are going to be ignored on the next call of vfnptr
1.103 + *
1.104 + * @param plug The unique identifier of the plugin that calls this function
1.105 + * @param vfnptr The virtual function pointer of the function in question
1.106 + */
1.107 + virtual void SetIgnoreHooks(Plugin plug, void *vfnptr) = 0;
1.108 +
1.109 + /**
1.110 + * @brief Reverses SetIgnoreHooks' effect
1.111 + *
1.112 + * @param plug The unique identifier of the plugin that calls this function
1.113 + * @param vfnptr The virtual function pointer of the function in question
1.114 + */
1.115 + virtual void ResetIgnoreHooks(Plugin plug, void *vfnptr) = 0;
1.116 +
1.117 + /**
1.118 + * @brief Finds the original entry of a virtual function pointer
1.119 + *
1.120 + * @param vfnptr The virtual function pointer
1.121 + * @return The original entry if the virtual function pointer has been patched; NULL otherwise.
1.122 + */
1.123 + virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
1.124 };
1.125
1.126 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
1.127 @@ -510,6 +572,50 @@
1.128 return &ref;
1.129 }
1.130 };
1.131 +
1.132 + // For source-level compatibility
1.133 + template <class T> struct CallClass
1.134 + {
1.135 + T *ptr;
1.136 +
1.137 + CallClass(T *p) : ptr(p)
1.138 + {
1.139 + }
1.140 +
1.141 + operator T*()
1.142 + {
1.143 + return ptr;
1.144 + }
1.145 + };
1.146 +
1.147 + typedef CallClass<void> GenericCallClass;
1.148 + typedef CallClass<EmptyClass> ManualCallClass;
1.149 +
1.150 + template <class T>
1.151 + CallClass<T> *GetCallClass(T *p)
1.152 + {
1.153 + return new CallClass<T>(p);
1.154 + }
1.155 +
1.156 + template <class T>
1.157 + void ReleaseCallClass(CallClass<T> *p)
1.158 + {
1.159 + delete p;
1.160 + }
1.161 +
1.162 + template <class X, class MFP>
1.163 + void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
1.164 + {
1.165 + SourceHook::MemFuncInfo info = {true, -1, 0, 0};
1.166 + SourceHook::GetFuncInfo(pInstance, mfp, info);
1.167 +
1.168 + void *vfnptr = reinterpret_cast<void*>(
1.169 + *reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
1.170 +
1.171 + void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
1.172 +
1.173 + return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
1.174 + }
1.175 }
1.176
1.177 /************************************************************************/
1.178 @@ -614,31 +720,6 @@
1.179 RETURN_META_VALUE(MRES_SUPERCEDE, (thisptr->*(u.mfp)) newparams); \
1.180 } while (0)
1.181
1.182 -/**
1.183 -* @brief Get/generate callclass for an interface pointer
1.184 -*
1.185 -* @param ifaceptr The interface pointer
1.186 -*/
1.187 -template<class ifacetype>
1.188 -inline SourceHook::CallClass<ifacetype> *SH_GET_CALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr)
1.189 -{
1.190 - return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
1.191 - shptr->GetCallClass(reinterpret_cast<void*>(ptr), sizeof(ifacetype)));
1.192 -}
1.193 -
1.194 -template<class ifacetype>
1.195 -inline SourceHook::CallClass<ifacetype> *SH_GET_MCALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr, int ifacesize)
1.196 -{
1.197 - return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
1.198 - shptr->GetCallClass(reinterpret_cast<void*>(ptr), ifacesize));
1.199 -}
1.200 -
1.201 -template<class ifacetype>
1.202 -inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::CallClass<ifacetype> *ptr)
1.203 -{
1.204 - shptr->ReleaseCallClass(reinterpret_cast<SourceHook::GenericCallClass*>(ptr));
1.205 -}
1.206 -
1.207 #define SH_MANUALHOOK_RECONFIGURE(hookname, pvtblindex, pvtbloffs, pthisptroffs) \
1.208 do { \
1.209 SH_GLOB_SHPTR->RemoveHookManager(SH_GLOB_PLUGPTR, SH_MFHCls(hookname)::HookManPubFunc); \
1.210 @@ -647,41 +728,83 @@
1.211 SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
1.212 } while (0)
1.213
1.214 -#define SH_GET_CALLCLASS(ptr) SH_GET_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
1.215 -#define SH_GET_MCALLCLASS(ptr, size) SH_GET_MCALLCLASS_R(SH_GLOB_SHPTR, reinterpret_cast<SourceHook::EmptyClass*>(ptr), size)
1.216 -#define SH_RELEASE_CALLCLASS(ptr) SH_RELEASE_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
1.217 +
1.218 +#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
1.219 +
1.220 +// For source-level compatibility
1.221 +
1.222 +#define SH_GET_CALLCLASS(ptr) SourceHook::GetCallClass(ptr)
1.223 +#define SH_GET_MCALLCLASS(ptr, size) SourceHook::GetCallClass(reinterpret_cast<SourceHook::EmptyClass*>(ptr))
1.224 +#define SH_RELEASE_CALLCLASS(ptr) SourceHook::ReleaseCallClass(ptr)
1.225 +
1.226 +// New ADD / REMOVE macros.
1.227 +#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
1.228 +#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
1.229
1.230 #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.231 __SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
1.232 post, handler)
1.233 -#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.234 - SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
1.235 -#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
1.236 - SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
1.237
1.238 #define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.239 __SourceHook_FHRemove##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
1.240 - post, handler)
1.241 -#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.242 - SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
1.243 -#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
1.244 - SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
1.245 -
1.246 + post, handler)
1.247
1.248 #define SH_ADD_MANUALHOOK(hookname, ifaceptr, handler, post) \
1.249 __SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
1.250 -#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
1.251 - SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
1.252 -#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
1.253 - SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
1.254
1.255 #define SH_REMOVE_MANUALHOOK(hookname, ifaceptr, handler, post) \
1.256 - __SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
1.257 + __SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
1.258 +
1.259 +#define SH_ADD_VPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.260 + __SourceHook_FHVPAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
1.261 + post, handler, false)
1.262 +
1.263 +#define SH_ADD_DVPHOOK(ifacetype, ifacefunc, vtableptr, handler, post) \
1.264 + __SourceHook_FHVPAdd##ifacetype##ifacefunc(reinterpret_cast<void*>(vtableptr), \
1.265 + post, handler, true)
1.266 +
1.267 +#define SH_ADD_MANUALVPHOOK(hookname, ifaceptr, handler, post) \
1.268 + __SourceHook_FHMVPAdd##hookname(reinterpret_cast<void*>(ifaceptr), post, handler, false)
1.269 +
1.270 +#define SH_ADD_MANUALDVPHOOK(hookname, vtableptr, handler, post) \
1.271 + __SourceHook_FHMVPAdd##hookname(reinterpret_cast<void*>(vtableptr), post, handler, true)
1.272 +
1.273 +#define SH_REMOVE_HOOK_ID(hookid) \
1.274 + (SH_GLOB_SHPTR->RemoveHookByID(SH_GLOB_PLUGPTR, hookid))
1.275 +
1.276 +// Old macros
1.277 +// !! These are now deprecated. Instead, use one of these:
1.278 +// SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
1.279 +// SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
1.280 +
1.281 +#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.282 + SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
1.283 +#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
1.284 + SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
1.285 +
1.286 +// SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
1.287 +// SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
1.288 +
1.289 +#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
1.290 + SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
1.291 +#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
1.292 + SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
1.293 +
1.294 +// SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
1.295 +// SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
1.296 +
1.297 +#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
1.298 + SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
1.299 +#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
1.300 + SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
1.301 +
1.302 +// SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
1.303 +// SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
1.304 +
1.305 #define SH_REMOVE_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
1.306 - SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
1.307 + SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
1.308 #define SH_REMOVE_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
1.309 - SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
1.310 -
1.311 + SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
1.312
1.313 #define SH_NOATTRIB
1.314
1.315 @@ -716,6 +839,8 @@
1.316 /* Verify interface version */ \
1.317 if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
1.318 return 1; \
1.319 + if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
1.320 + return 1; \
1.321 \
1.322 if (action == HA_GetInfo) \
1.323 { \
1.324 @@ -760,7 +885,7 @@
1.325 SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
1.326 ::SourceHook::MemFuncInfo SH_FHCls(ifacetype,ifacefunc,overload)::ms_MFI; \
1.327 ::SourceHook::IHookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
1.328 - bool __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
1.329 + int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
1.330 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
1.331 { \
1.332 using namespace ::SourceHook; \
1.333 @@ -769,10 +894,24 @@
1.334 if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
1.335 return false; /* No non-virtual functions / virtual inheritance supported */ \
1.336 \
1.337 - return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
1.338 + return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, ::SourceHook::ISourceHook::Hook_Normal, iface, mfi.thisptroffs, \
1.339 SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
1.340 new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
1.341 } \
1.342 + int __SourceHook_FHVPAdd##ifacetype##ifacefunc(void *iface, bool post, \
1.343 + SH_FHCls(ifacetype,ifacefunc,overload)::FD handler, bool direct) \
1.344 + { \
1.345 + using namespace ::SourceHook; \
1.346 + MemFuncInfo mfi = {true, -1, 0, 0}; \
1.347 + GetFuncInfo(funcptr, mfi); \
1.348 + if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
1.349 + return false; /* No non-virtual functions / virtual inheritance supported */ \
1.350 + \
1.351 + return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, \
1.352 + direct ? ::SourceHook::ISourceHook::Hook_DVP : ::SourceHook::ISourceHook::Hook_VP, \
1.353 + iface, mfi.thisptroffs, SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
1.354 + new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
1.355 + } \
1.356 bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
1.357 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
1.358 { \
1.359 @@ -811,6 +950,8 @@
1.360 /* Verify interface version */ \
1.361 if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
1.362 return 1; \
1.363 + if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
1.364 + return 1; \
1.365 \
1.366 if (action == HA_GetInfo) \
1.367 { \
1.368 @@ -843,13 +984,21 @@
1.369 SH_MFHCls(hookname) SH_MFHCls(hookname)::ms_Inst; \
1.370 ::SourceHook::MemFuncInfo SH_MFHCls(hookname)::ms_MFI; \
1.371 ::SourceHook::IHookManagerInfo *SH_MFHCls(hookname)::ms_HI; \
1.372 - bool __SourceHook_FHMAdd##hookname(void *iface, bool post, \
1.373 + int __SourceHook_FHMAdd##hookname(void *iface, bool post, \
1.374 SH_MFHCls(hookname)::FD handler) \
1.375 { \
1.376 - return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
1.377 + return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, ::SourceHook::ISourceHook::Hook_Normal, iface, pthisptroffs, \
1.378 SH_MFHCls(hookname)::HookManPubFunc, \
1.379 new ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD>(handler), post); \
1.380 } \
1.381 + int __SourceHook_FHMVPAdd##hookname(void *iface, bool post, \
1.382 + SH_MFHCls(hookname)::FD handler, bool direct) \
1.383 + { \
1.384 + return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, \
1.385 + direct ? ::SourceHook::ISourceHook::Hook_DVP : ::SourceHook::ISourceHook::Hook_VP, \
1.386 + iface, pthisptroffs, SH_MFHCls(hookname)::HookManPubFunc, \
1.387 + new ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD>(handler), post); \
1.388 + } \
1.389 bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
1.390 SH_MFHCls(hookname)::FD handler) \
1.391 { \
1.392 @@ -1127,136 +1276,109 @@
1.393 //////////////////////////////////////////////////////////////////////////
1.394 // SH_CALL
1.395
1.396 -#if SH_COMP == SH_COMP_MSVC
1.397 -
1.398 -# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
1.399 -{ \
1.400 - using namespace ::SourceHook; \
1.401 - MemFuncInfo mfi = {true, -1, 0, 0}; \
1.402 - GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
1.403 - void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
1.404 - if (!origfunc) \
1.405 - return (m_CC->GetThisPtr()->*m_MFP)call; \
1.406 - \
1.407 - /* It's hooked. Call the original function. */ \
1.408 - union \
1.409 - { \
1.410 - RetType(EmptyClass::*mfpnew)prms; \
1.411 - void *addr; \
1.412 - } u; \
1.413 - u.addr = origfunc; \
1.414 - \
1.415 - void *adjustedthisptr = reinterpret_cast<void*>(reinterpret_cast<char*>(m_CC->GetThisPtr()) + mfi.thisptroffs); \
1.416 - return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
1.417 -}
1.418 -
1.419 -# define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
1.420 -{ \
1.421 - using namespace ::SourceHook; \
1.422 - char *adjustedthisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()) + m_ThisPtrOffs; \
1.423 - union \
1.424 - { \
1.425 - RetType(EmptyClass::*mfpnew)prms; \
1.426 - void *addr; \
1.427 - } u; \
1.428 - u.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
1.429 - if (!u.addr) \
1.430 - u.addr = (*reinterpret_cast<void***>(adjustedthisptr + m_VtblOffs))[m_VtblIdx]; \
1.431 - \
1.432 - return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
1.433 -}
1.434 -
1.435 -#elif SH_COMP == SH_COMP_GCC
1.436 -
1.437 -# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
1.438 +#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
1.439 { \
1.440 using namespace ::SourceHook; \
1.441 - MemFuncInfo mfi = {true, -1, 0, 0}; \
1.442 - GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
1.443 - void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
1.444 - if (!origfunc) \
1.445 - return (m_CC->GetThisPtr()->*m_MFP)call; \
1.446 \
1.447 - /* It's hooked. Call the original function. */ \
1.448 - union \
1.449 - { \
1.450 - RetType(EmptyClass::*mfpnew)prms; \
1.451 - struct \
1.452 - { \
1.453 - void *addr; \
1.454 - intptr_t adjustor; \
1.455 - } s; \
1.456 - } u; \
1.457 - u.s.addr = origfunc; \
1.458 - u.s.adjustor = mfi.thisptroffs; \
1.459 - \
1.460 - return (reinterpret_cast<EmptyClass*>(m_CC->GetThisPtr())->*u.mfpnew)call; \
1.461 + m_pSH->SetIgnoreHooks(m_Plug, m_VfnPtr); \
1.462 + RetType tmpret = (m_ThisPtr->*m_MFP)call; \
1.463 + m_pSH->ResetIgnoreHooks(m_Plug, m_VfnPtr); \
1.464 + return tmpret; \
1.465 }
1.466
1.467 -# define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
1.468 +#define SH_MAKE_EXECUTABLECLASS_OB_void(call, prms) \
1.469 { \
1.470 using namespace ::SourceHook; \
1.471 - char *thisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()); \
1.472 - union \
1.473 - { \
1.474 - RetType(EmptyClass::*mfpnew)prms; \
1.475 - struct { \
1.476 - void *addr; \
1.477 - intptr_t adjustor; \
1.478 - } s; \
1.479 - } u; \
1.480 - u.s.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
1.481 - if (!u.s.addr) \
1.482 - u.s.addr = (*reinterpret_cast<void***>(thisptr + m_ThisPtrOffs + m_VtblOffs))[m_VtblIdx]; \
1.483 \
1.484 - u.s.adjustor = m_ThisPtrOffs; \
1.485 - return (reinterpret_cast<EmptyClass*>(thisptr)->*u.mfpnew)call; \
1.486 + m_pSH->SetIgnoreHooks(m_Plug, m_VfnPtr); \
1.487 + (m_ThisPtr->*m_MFP)call; \
1.488 + m_pSH->ResetIgnoreHooks(m_Plug, m_VfnPtr); \
1.489 }
1.490
1.491 -#endif
1.492 -
1.493 namespace SourceHook
1.494 {
1.495 -@[$1,0,$a:
1.496 - // Support for $1 arguments
1.497 - template<class CCType, class MFPType, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
1.498 + // Call Class Wrapper!
1.499 + template <class T> struct CCW
1.500 {
1.501 - CCType *m_CC;
1.502 - MFPType m_MFP;
1.503 - public:
1.504 - ExecutableClass$1(CCType *cc, MFPType mfp) : m_CC(cc), m_MFP(mfp) { }
1.505 -
1.506 - RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
1.507 - SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1.508 -
1.509 - @[$2,$1+1,$a:
1.510 - template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
1.511 - SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1.512 - @]
1.513 + typedef T type;
1.514 +
1.515 + // Get Real Pointer!
1.516 + static inline T *GRP(T *p)
1.517 + {
1.518 + return p;
1.519 + }
1.520 + };
1.521 +
1.522 + template <class T> struct CCW< CallClass<T> >
1.523 + {
1.524 + typedef T type;
1.525 +
1.526 + // Get Real Pointer!
1.527 + static inline T *GRP(CallClass<T> *p)
1.528 + {
1.529 + return p->ptr;
1.530 + }
1.531 };
1.532
1.533 - template <class RetType@[$2,1,$1:, class Param$2@]> class MExecutableClass$1
1.534 +@[$1,0,$a:
1.535 + // Support for $1 arguments
1.536 + template<class ObjType, class MFP, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
1.537 {
1.538 - ManualCallClass *m_CC;
1.539 - int m_ThisPtrOffs;
1.540 - int m_VtblIdx;
1.541 - int m_VtblOffs;
1.542 + ObjType *m_ThisPtr;
1.543 + void *m_VfnPtr;
1.544 + MFP m_MFP;
1.545 + ISourceHook *m_pSH;
1.546 + Plugin m_Plug;
1.547 public:
1.548 - MExecutableClass$1(ManualCallClass *cc, int vtbloffs, int vtblidx, int thisptroffs) : m_CC(cc),
1.549 - m_ThisPtrOffs(thisptroffs), m_VtblIdx(vtblidx), m_VtblOffs(vtbloffs) { }
1.550 -
1.551 + ExecutableClass$1(ObjType *tp, MFP mfp, void *vp, ISourceHook *pSH, Plugin plug) : m_ThisPtr(tp),
1.552 + m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH), m_Plug(plug) { }
1.553 +
1.554 RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
1.555 - SH_MAKE_MEXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1.556 -
1.557 + SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1.558 +
1.559 @[$2,$1+1,$a:
1.560 template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
1.561 - SH_MAKE_MEXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1.562 + SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1.563 @]
1.564 };
1.565 +
1.566 + template<class ObjType, class MFP@[$2,1,$1:, class Param$2@]> class ExecutableClass$1<ObjType, MFP, void@[$2,1,$1:, Param$2@]>
1.567 + {
1.568 + ObjType *m_ThisPtr;
1.569 + void *m_VfnPtr;
1.570 + MFP m_MFP;
1.571 + ISourceHook *m_pSH;
1.572 + Plugin m_Plug;
1.573 + public:
1.574 + ExecutableClass$1(ObjType *tp, MFP mfp, void *vp, ISourceHook *pSH, Plugin plug) : m_ThisPtr(tp),
1.575 + m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH), m_Plug(plug) { }
1.576 +
1.577 + void operator()(@[$2,1,$1|, :Param$2 p$2@]) const
1.578 + SH_MAKE_EXECUTABLECLASS_OB_void((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1.579 +
1.580 + @[$2,$1+1,$a:
1.581 + template <@[$3,$1+1,$2|, :class Param$3@]> void operator()(@[$3,1,$2|, :Param$3 p$3@]) const
1.582 + SH_MAKE_EXECUTABLECLASS_OB_void((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1.583 + @]
1.584 + };
1.585 @]
1.586
1.587 }
1.588
1.589 +#define SH__CALL_GET_VFNPTR_NORMAL \
1.590 + using namespace ::SourceHook; \
1.591 + MemFuncInfo mfi = {true, -1, 0, 0}; \
1.592 + GetFuncInfo(CCW<Y>::GRP(ptr), mfp, mfi); \
1.593 + void *vfnptr = reinterpret_cast<void*>( \
1.594 + *reinterpret_cast<void***>(reinterpret_cast<char*>(ptr) + mfi.thisptroffs + mfi.vtbloffs) + mfi.vtblindex);
1.595 +
1.596 +#define SH__CALL_GET_VFNPTR_MANUAL \
1.597 + using namespace ::SourceHook; \
1.598 + void *vfnptr = reinterpret_cast<void*>( \
1.599 + *reinterpret_cast<void***>( (reinterpret_cast<char*>(CCW<Y>::GRP(ptr)) + thisptroffs + vtbloffs) ) + vtblidx); \
1.600 + /* patch mfp */ \
1.601 + *reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr);
1.602 +
1.603 // SH_CALL needs to deduce the return type -> it uses templates and function overloading
1.604 // That's why SH_CALL takes two parameters: "mfp2" of type RetType(X::*mfp)(params), and "mfp" of type MFP
1.605 // The only purpose of the mfp2 parameter is to extract the return type
1.606 @@ -1264,24 +1386,30 @@
1.607 @[$1,0,$a:
1.608 // Support for $1 arguments
1.609 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1.610 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1.611 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]))
1.612 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
1.613 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
1.614 {
1.615 - return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1.616 + SH__CALL_GET_VFNPTR_NORMAL
1.617 + return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
1.618 + mfp, vfnptr, shptr, plug);
1.619 }
1.620
1.621 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1.622 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1.623 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const)
1.624 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
1.625 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
1.626 {
1.627 - return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1.628 + SH__CALL_GET_VFNPTR_NORMAL
1.629 + return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
1.630 + mfp, vfnptr, shptr, plug);
1.631 }
1.632
1.633 -template <class X, class RetType@[$2,1,$1:, class Param$2@]>
1.634 -SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>
1.635 -SH_MCALL2(SourceHook::ManualCallClass *ptr, RetType(X::*mfp)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs)
1.636 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1.637 +SourceHook::ExecutableClass$1<SourceHook::EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>
1.638 +SH_MCALL3(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
1.639 {
1.640 - return SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>(ptr, vtbloffs, vtblidx, thisptroffs);
1.641 + SH__CALL_GET_VFNPTR_MANUAL
1.642 + return SourceHook::ExecutableClass$1<EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>(
1.643 + reinterpret_cast<SourceHook::EmptyClass*>(CCW<Y>::GRP(ptr)), mfp, vfnptr, shptr, plug);
1.644 }
1.645 @]
1.646
1.647 @@ -1291,24 +1419,29 @@
1.648 @[$1,0,$a:
1.649 // Support for $1 arguments
1.650 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1.651 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1.652 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...))
1.653 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
1.654 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...), SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
1.655 {
1.656 - return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1.657 + SH__CALL_GET_VFNPTR_NORMAL
1.658 + return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
1.659 + mfp, vfnptr, shptr, plug);
1.660 }
1.661
1.662 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1.663 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1.664 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const)
1.665 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
1.666 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
1.667 {
1.668 - return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1.669 + SH__CALL_GET_VFNPTR_NORMAL
1.670 + return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
1.671 + mfp, vfnptr, shptr, plug);
1.672 }
1.673
1.674 @]
1.675
1.676 #endif
1.677
1.678 -#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp))
1.679 +#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp), SH_GLOB_SHPTR, SH_GLOB_PLUGPTR)
1.680 +#define SH_MCALL2(ptr, mfp, vtblidx, vtbloffs, thisptroffs) SH_MCALL3((ptr), (mfp), (mfp), (vtblidx), (vtbloffs), (thisptroffs), SH_GLOB_SHPTR, SH_GLOB_PLUGPTR)
1.681 #define SH_MCALL(ptr, mhookname) SH_MCALL2((ptr), SH_MFHCls(mhookname)::ECMFP(), SH_MFHCls(mhookname)::ms_MFI.vtblindex, \
1.682 SH_MFHCls(mhookname)::ms_MFI.vtbloffs, SH_MFHCls(mhookname)::ms_MFI.thisptroffs)
1.683