1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2005 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko
8 * ============================
13 * @brief Contains the public SourceHook API
16 #ifndef __SOURCEHOOK_H__
17 #define __SOURCEHOOK_H__
19 // Interface revisions:
20 // 1 - Initial revision
21 // 2 - Changed to virtual functions for iterators and all queries
22 // 3 - Added "hook loop status variable"
24 #define SH_IFACE_VERSION 4
25 #define SH_IMPL_VERSION 3
28 // 1 - Support for recalls, performance optimisations
29 #define SH_HOOKMAN_VERSION 1
31 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
32 // It's used in various macros
34 #define SH_GLOB_SHPTR g_SHPtr
37 // Used to identify the current plugin
38 #ifndef SH_GLOB_PLUGPTR
39 #define SH_GLOB_PLUGPTR g_PLID
46 # define SH_ASSERT(x, info) \
50 printf("SOURCEHOOK DEBUG ASSERTION FAILED: %s:%u(%s): %s: ", __FILE__, __LINE__, __FUNCTION__, #x); \
58 # define SH_ASSERT(x, info)
62 #define SH_SYS_WIN32 1
63 #define SH_SYS_LINUX 2
66 # define SH_SYS SH_SYS_WIN32
67 #elif defined __linux__
68 # define SH_SYS SH_SYS_LINUX
70 # error Unsupported system
75 #define SH_COMP_MSVC 2
78 # define SH_COMP SH_COMP_MSVC
79 #elif defined __GNUC__
80 # define SH_COMP SH_COMP_GCC
82 # error Unsupported compiler
85 #if SH_COMP==SH_COMP_MSVC
86 # define vsnprintf _vsnprintf
89 #if SH_SYS != SH_SYS_WIN32
93 #define SH_PTRSIZE sizeof(void*)
95 #include "FastDelegate.h"
96 #include "sh_memfuncinfo.h"
100 // Flags returned by a plugin's api function.
101 // NOTE: order is crucial, as greater/less comparisons are made.
104 MRES_IGNORED=0, // plugin didn't take any action
105 MRES_HANDLED, // plugin did something, but real function should still be called
106 MRES_OVERRIDE, // call real function, but use my return value
107 MRES_SUPERCEDE // skip real function; use my return value
114 * @brief Specifies the size (in bytes) for the internal buffer of vafmt(printf-like) function handlers
116 const int STRBUF_LEN=4096;
119 * @brief An empty class. No inheritance used. Used for original-function-call hacks
126 * @brief Implicit cast.
128 template <class In, class Out>
129 inline Out implicit_cast(In input)
135 * @brief A plugin typedef
137 * SourceHook doesn't really care what this is. As long as the ==, != and = operators work on it and every
138 * plugin has a unique identifier, everything is ok.
139 * It should also be possible to set it to 0.
145 ProtoInfo(int rtsz, int nop, const int *p) : beginningNull(0), retTypeSize(rtsz), numOfParams(nop), params(p)
148 int beginningNull; //!< To distinguish from old protos (which never begin with 0)
149 int retTypeSize; //!< 0 if void
150 int numOfParams; //!< number of parameters
151 const int *params; //!< params[0]=0 (or -1 for vararg), params[1]=size of first param, ...
155 * @brief Specifies the actions for hook managers
157 enum HookManagerAction
159 HA_GetInfo = 0, //!< Store info about the hook manager
160 HA_Register, //!< Save the IHookManagerInfo pointer for future reference
161 HA_Unregister //!< Clear the saved pointer
164 struct IHookManagerInfo;
167 * @brief Pointer to hook manager interface function
169 * A "hook manager" is a the only thing that knows the actual protoype of the function at compile time.
171 * @param ha What the hook manager should do
172 * @param hi A pointer to IHookManagerInfo
174 typedef int (*HookManagerPubFunc)(HookManagerAction ha, IHookManagerInfo *hi);
179 virtual void DeleteThis() = 0; // Ugly, I know
180 virtual bool IsEqual(ISHDelegate *other) = 0;
183 template <class T> class CSHDelegate : public ISHDelegate
187 CSHDelegate(T deleg) : m_Deleg(deleg)
191 CSHDelegate(const CSHDelegate &other) : m_Deleg(other.m_Deleg)
200 bool IsEqual(ISHDelegate *other)
202 return static_cast<CSHDelegate<T>* >(other)->GetDeleg() == GetDeleg();
215 virtual bool End() = 0;
216 virtual void Next() = 0;
217 virtual ISHDelegate *Handler() = 0;
218 virtual int ThisPtrOffs() = 0;
220 virtual IIter *GetIter() = 0;
221 virtual void ReleaseIter(IIter *pIter) = 0;
226 virtual void *GetPtr() = 0;
227 virtual IHookList *GetPreHooks() = 0;
228 virtual IHookList *GetPostHooks() = 0;
233 virtual void *GetVfnPtr() = 0;
234 virtual void *GetOrigEntry() = 0;
236 virtual IIface *FindIface(void *ptr) = 0;
239 struct IHookManagerInfo
241 virtual IVfnPtr *FindVfnPtr(void *vfnptr) = 0;
243 virtual void SetInfo(int vtbloffs, int vtblidx, const char *proto) = 0;
244 virtual void SetHookfuncVfnptr(void *hookfunc_vfnptr) = 0;
246 // Added 23.12.2005 (yup! I'm coding RIGHT BEFORE CHRISTMAS!)
247 // If the hookman doesn't set this, it defaults 0
248 // SourceHook prefers hookmans with higher version numbers
249 virtual void SetVersion(int version) = 0;
255 IHookList::IIter *m_pIter;
257 AutoHookIter(IHookList *pList)
258 : m_pList(pList), m_pIter(pList->GetIter())
265 m_pList->ReleaseIter(m_pIter);
270 return m_pIter->End();
278 ISHDelegate *Handler()
280 return m_pIter->Handler();
285 return m_pIter->ThisPtrOffs();
294 template<class B> struct CallClass
296 virtual B *GetThisPtr() = 0;
297 virtual void *GetOrigFunc(int vtbloffs, int vtblidx) = 0;
300 typedef CallClass<void> GenericCallClass;
301 typedef CallClass<EmptyClass> ManualCallClass;
304 * @brief The main SourceHook interface
310 * @brief Return interface version
312 virtual int GetIfaceVersion() = 0;
315 * @brief Return implementation version
317 virtual int GetImplVersion() = 0;
322 * @return True if the function succeeded, false otherwise
324 * @param plug The unique identifier of the plugin that calls this function
325 * @param iface The interface pointer
326 * @param ifacesize The size of the class iface points to
327 * @param myHookMan A hook manager function that should be capable of handling the function
328 * @param handler A pointer to a FastDelegate containing the hook handler
329 * @param post Set to true if you want a post handler
331 virtual bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
332 ISHDelegate *handler, bool post) = 0;
335 * @brief Removes a hook.
337 * @return True if the function succeeded, false otherwise
339 * @param plug The unique identifier of the plugin that calls this function
340 * @param iface The interface pointer
341 * @param myHookMan A hook manager function that should be capable of handling the function
342 * @param handler A pointer to a FastDelegate containing the hook handler
343 * @param post Set to true if you want a post handler
345 virtual bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
346 ISHDelegate *handler, bool post) = 0;
349 * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
351 * @param plug The unique identifier of the plugin in question
353 virtual bool IsPluginInUse(Plugin plug) = 0;
356 * @brief Return a pointer to a callclass. Generate a new one if required.
358 * @param iface The interface pointer
359 * @param size Size of the class instance
361 virtual GenericCallClass *GetCallClass(void *iface, size_t size) = 0;
364 * @brief Release a callclass
366 * @param ptr Pointer to the callclass
368 virtual void ReleaseCallClass(GenericCallClass *ptr) = 0;
370 virtual void SetRes(META_RES res) = 0; //!< Sets the meta result
371 virtual META_RES GetPrevRes() = 0; //!< Gets the meta result of the
372 //!< previously calledhandler
373 virtual META_RES GetStatus() = 0; //!< Gets the highest meta result
374 virtual const void *GetOrigRet() = 0; //!< Gets the original result.
375 //!< If not in post function, undefined
376 virtual const void *GetOverrideRet() = 0; //!< Gets the override result.
377 //!< If none is specified, NULL
378 virtual void *GetIfacePtr() = 0; //!< Gets the interface pointer
379 //////////////////////////////////////////////////////////////////////////
381 virtual void HookLoopBegin(IIface *pIface) = 0; //!< Should be called when a hook loop begins
382 virtual void HookLoopEnd() = 0; //!< Should be called when a hook loop exits
383 virtual void SetCurResPtr(META_RES *mres) = 0; //!< Sets pointer to the current meta result
384 virtual void SetPrevResPtr(META_RES *mres) = 0; //!< Sets pointer to previous meta result
385 virtual void SetStatusPtr(META_RES *mres) = 0; //!< Sets pointer to the status variable
386 virtual void SetIfacePtrPtr(void **pp) = 0; //!< Sets pointer to the interface this pointer
387 virtual void SetOrigRetPtr(const void *ptr) = 0; //!< Sets the original return pointer
388 virtual void SetOverrideRetPtr(void *ptr) = 0; //!< Sets the override result pointer
389 virtual bool ShouldContinue() = 0; //!< Returns false if the hook loop should exit
392 * @brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
394 * @param plug The owner of the hook manager
395 * @param pubFunc The hook manager's info function
397 virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
399 virtual void DoRecall() = 0; //!< Initiates a recall sequence
404 Users want the ability to change parameters of the called function
405 from inside their handler.
408 2) Recall the function
409 3) => SH's hook func gets called:
410 4) The first iterator points at the first hook the last hookfunc didn't execute yet
411 5) does all iteration and returns normally
412 6) The user's handler returns immediately
413 7) The hook func returns immediately as well
415 Also note that the recalled hookfunc starts with the status the recalling hookfunc
416 ended with. The last handler (doing the recall) is also able to specify its own
420 virtual void *GetOverrideRetPtr() = 0; //!< Returns the pointer set by SetOverrideRetPtr
423 * @brief Set up the hook loop. Equivalent to calling:
424 * SetStatusPtr, SetPrevResPtr, SetCurResPtr, SetIfacePtrPtr, SetOrigRetPtr, Get/SetOverrideRetPtr
426 * @param statusPtr pointer to status variable
427 * @param prevResPtr pointer to previous result variable
428 * @param curResPtr pointer to current result variable
429 * @param ifacePtrPtr pointer to interface this pointer variable
430 * @param origRetPr pointer to original return value variable. NULL for void funcs
431 * @param overrideRetPtr pointer to override return value variable. NULL for void funcs
433 * @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
434 * when the hook func is being called as part of a recall
436 virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
437 void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr) = 0;
443 /************************************************************************/
444 /* High level interface */
445 /************************************************************************/
446 #define META_RESULT_STATUS SH_GLOB_SHPTR->GetStatus()
447 #define META_RESULT_PREVIOUS SH_GLOB_SHPTR->GetPrevRes()
448 #define META_RESULT_ORIG_RET(type) *reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOrigRet())
449 #define META_RESULT_OVERRIDE_RET(type) *reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOverrideRet())
450 #define META_IFACEPTR(type) reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
452 #define SET_META_RESULT(result) SH_GLOB_SHPTR->SetRes(result)
453 #define RETURN_META(result) do { SET_META_RESULT(result); return; } while(0)
454 #define RETURN_META_VALUE(result, value) do { SET_META_RESULT(result); return (value); } while(0)
457 // NEVER-EVER call these from post hooks!
458 // also, only call it from the hook handlers directly!
461 // Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
462 // Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
464 // SourceHook::SetOverrideRet is defined later.
465 #define RETURN_META_NEWPARAMS(result, memfuncptr, newparams) \
467 SET_META_RESULT(result); \
468 SH_GLOB_SHPTR->DoRecall(); \
469 (SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams; \
470 RETURN_META(MRES_SUPERCEDE); \
473 #define RETURN_META_VALUE_NEWPARAMS(result, value, memfuncptr, newparams) \
475 SET_META_RESULT(result); \
476 SH_GLOB_SHPTR->DoRecall(); \
477 if ((result) >= MRES_OVERRIDE) \
479 /* meh, set the override result here because we don't get a chance to return */ \
480 /* before continuing the hook loop through the recall */ \
481 SourceHook::SetOverrideResult(SH_GLOB_SHPTR, memfuncptr, value); \
483 RETURN_META_VALUE(MRES_SUPERCEDE, \
484 (SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams); \
488 * @brief Get/generate callclass for an interface pointer
490 * @param ifaceptr The interface pointer
492 template<class ifacetype>
493 inline SourceHook::CallClass<ifacetype> *SH_GET_CALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr)
495 return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
496 shptr->GetCallClass(reinterpret_cast<void*>(ptr), sizeof(ifacetype)));
499 template<class ifacetype>
500 inline SourceHook::CallClass<ifacetype> *SH_GET_MCALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr, int ifacesize)
502 return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
503 shptr->GetCallClass(reinterpret_cast<void*>(ptr), ifacesize));
506 template<class ifacetype>
507 inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::CallClass<ifacetype> *ptr)
509 shptr->ReleaseCallClass(reinterpret_cast<SourceHook::GenericCallClass*>(ptr));
512 #define SH_MANUALHOOK_RECONFIGURE(hookname, pvtblindex, pvtbloffs, pthisptroffs) \
514 SH_GLOB_SHPTR->RemoveHookManager(SH_GLOB_PLUGPTR, SH_MFHCls(hookname)::HookManPubFunc); \
515 SH_MFHCls(hookname)::ms_MFI.thisptroffs = pthisptroffs; \
516 SH_MFHCls(hookname)::ms_MFI.vtblindex = pvtblindex; \
517 SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
520 #define SH_GET_CALLCLASS(ptr) SH_GET_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
521 #define SH_GET_MCALLCLASS(ptr, size) SH_GET_MCALLCLASS_R(SH_GLOB_SHPTR, reinterpret_cast<SourceHook::EmptyClass*>(ptr), size)
522 #define SH_RELEASE_CALLCLASS(ptr) SH_RELEASE_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
524 #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
525 __SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
527 #define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
528 SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
529 #define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
530 SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
532 #define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
533 __SourceHook_FHRemove##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
535 #define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
536 SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
537 #define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
538 SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
541 #define SH_ADD_MANUALHOOK(hookname, ifaceptr, handler, post) \
542 __SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
543 #define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
544 SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
545 #define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
546 SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
548 #define SH_REMOVE_MANUALHOOK(hookname, ifaceptr, handler, post) \
549 __SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
550 #define SH_REMOVE_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
551 SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
552 #define SH_REMOVE_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
553 SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
561 #if SH_COMP == SH_COMP_MSVC
562 # define SH_SETUP_MFP(mfp) \
563 reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry;
564 #elif SH_COMP == SH_COMP_GCC
565 # define SH_SETUP_MFP(mfp) \
566 reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry; \
567 reinterpret_cast<void**>(&mfp)[1] = 0;
569 # error Not supported yet.
572 //////////////////////////////////////////////////////////////////////////
573 #define SH_FHCls(ift, iff, ov) __SourceHook_FHCls_##ift##iff##ov
574 #define SH_MFHCls(hookname) __SourceHook_MFHCls_##hookname
576 #define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
577 SH_FHCls(ifacetype,ifacefunc,overload)() \
579 GetFuncInfo(funcptr, ms_MFI); \
582 static int HookManPubFunc(::SourceHook::HookManagerAction action, ::SourceHook::IHookManagerInfo *param) \
584 using namespace ::SourceHook; \
585 GetFuncInfo(funcptr, ms_MFI); \
586 /* Verify interface version */ \
587 if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
590 if (action == HA_GetInfo) \
592 param->SetVersion(SH_HOOKMAN_VERSION); \
593 param->SetInfo(ms_MFI.vtbloffs, ms_MFI.vtblindex, \
594 reinterpret_cast<const char*>(&ms_Proto)); \
597 GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
598 param->SetHookfuncVfnptr( \
599 reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex]); \
602 else if (action == HA_Register) \
607 else if (action == HA_Unregister) \
616 // It has to be possible to use the macros in namespaces
617 // -> So we need to access and extend the global SourceHook namespace
618 // We use a namespace alias for this
619 #define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
620 struct SH_FHCls(ifacetype,ifacefunc,overload) \
622 static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
623 static ::SourceHook::MemFuncInfo ms_MFI; \
624 static ::SourceHook::IHookManagerInfo *ms_HI; \
625 static ::SourceHook::ProtoInfo ms_Proto; \
626 SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
628 #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, funcptr) \
630 SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
631 ::SourceHook::MemFuncInfo SH_FHCls(ifacetype,ifacefunc,overload)::ms_MFI; \
632 ::SourceHook::IHookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
633 bool __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
634 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
636 using namespace ::SourceHook; \
638 GetFuncInfo(funcptr, mfi); \
639 if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
640 return false; /* No non-virtual functions / virtual inheritance supported */ \
642 return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
643 SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
644 new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
646 bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
647 SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
649 using namespace ::SourceHook; \
651 GetFuncInfo(funcptr, mfi); \
652 if (mfi.thisptroffs < 0) \
653 return false; /* No virtual inheritance supported */ \
655 CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
656 return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
657 SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
660 #define SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
661 struct SH_MFHCls(hookname) \
663 static SH_MFHCls(hookname) ms_Inst; \
664 static ::SourceHook::MemFuncInfo ms_MFI; \
665 static ::SourceHook::IHookManagerInfo *ms_HI; \
666 static ::SourceHook::ProtoInfo ms_Proto; \
668 SH_MFHCls(hookname)() \
670 ms_MFI.isVirtual = true; \
671 ms_MFI.thisptroffs = pthisptroffs; \
672 ms_MFI.vtblindex = pvtblidx; \
673 ms_MFI.vtbloffs = pvtbloffs; \
675 static int HookManPubFunc(::SourceHook::HookManagerAction action, ::SourceHook::IHookManagerInfo *param) \
677 using namespace ::SourceHook; \
678 /* we don't set ms_MFI here because manual hookmans can be reconfigured */ \
679 /* :FIXME: possible problem: someone adding a hook from a constructor of a global entity */ \
680 /* which is construced before SH_MFHCls(hookname)() gets called? */ \
681 /* Verify interface version */ \
682 if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
685 if (action == HA_GetInfo) \
687 param->SetVersion(SH_HOOKMAN_VERSION); \
688 param->SetInfo(ms_MFI.vtbloffs, ms_MFI.vtblindex, \
689 reinterpret_cast<const char*>(&ms_Proto)); \
692 GetFuncInfo(&SH_MFHCls(hookname)::Func, mfi); \
693 param->SetHookfuncVfnptr( \
694 reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex]); \
697 else if (action == HA_Register) \
702 else if (action == HA_Unregister) \
711 #define SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
713 SH_MFHCls(hookname) SH_MFHCls(hookname)::ms_Inst; \
714 ::SourceHook::MemFuncInfo SH_MFHCls(hookname)::ms_MFI; \
715 ::SourceHook::IHookManagerInfo *SH_MFHCls(hookname)::ms_HI; \
716 bool __SourceHook_FHMAdd##hookname(void *iface, bool post, \
717 SH_MFHCls(hookname)::FD handler) \
719 return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
720 SH_MFHCls(hookname)::HookManPubFunc, \
721 new ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD>(handler), post); \
723 bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
724 SH_MFHCls(hookname)::FD handler) \
726 ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD> tmp(handler); \
727 return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
728 SH_MFHCls(hookname)::HookManPubFunc, &tmp, post); \
732 #define SH_SETUPCALLS(rettype, paramtypes, params) \
733 /* 1) Find the vfnptr */ \
734 using namespace ::SourceHook; \
735 void *ourvfnptr = reinterpret_cast<void*>( \
736 *reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
737 IVfnPtr *vfnptr = ms_HI->FindVfnPtr(ourvfnptr); \
738 SH_ASSERT(vfnptr, ("Called with vfnptr 0x%p which couldn't be found in the list", ourvfnptr)); \
740 void *vfnptr_origentry = vfnptr->GetOrigEntry(); \
741 /* ... and the iface */ \
742 IIface *ifinfo = vfnptr->FindIface(reinterpret_cast<void*>(this)); \
745 /* The iface info was not found. Redirect the call to the original function. */ \
746 rettype (EmptyClass::*mfp)paramtypes; \
748 return (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
750 /* 2) Declare some vars and set it up */ \
751 SH_GLOB_SHPTR->HookLoopBegin(ifinfo); \
752 IHookList *prelist = ifinfo->GetPreHooks(); \
753 IHookList *postlist = ifinfo->GetPostHooks(); \
754 META_RES status = MRES_IGNORED; \
758 rettype override_ret; \
759 rettype plugin_ret; \
761 rettype *pOverrideRet = reinterpret_cast<rettype*>(SH_GLOB_SHPTR->SetupHookLoop( \
762 &status, &prev_res, &cur_res, &ifptr, &orig_ret, &override_ret));
764 #define SH_CALL_HOOKS(post, params) \
765 if (SH_GLOB_SHPTR->ShouldContinue()) \
767 prev_res = MRES_IGNORED; \
768 for (AutoHookIter iter(post##list); !iter.End(); iter.Next()) \
770 cur_res = MRES_IGNORED; \
771 ifptr = reinterpret_cast<void*>(reinterpret_cast<char*>(this) - iter.ThisPtrOffs()); \
772 plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(iter.Handler())->GetDeleg() params; \
773 prev_res = cur_res; \
774 if (cur_res > status) \
776 if (cur_res >= MRES_OVERRIDE) \
777 *pOverrideRet = plugin_ret; \
778 if (!SH_GLOB_SHPTR->ShouldContinue()) \
786 #define SH_CALL_ORIG(rettype, paramtypes, params) \
787 if (status != MRES_SUPERCEDE) \
789 rettype (EmptyClass::*mfp)paramtypes; \
791 orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
794 orig_ret = override_ret; \
796 #define SH_RETURN() \
797 SH_GLOB_SHPTR->HookLoopEnd(); \
798 return status >= MRES_OVERRIDE ? *pOverrideRet : orig_ret;
800 #define SH_HANDLEFUNC(paramtypes, params, rettype) \
801 SH_SETUPCALLS(rettype, paramtypes, params) \
802 SH_CALL_HOOKS(pre, params) \
803 SH_CALL_ORIG(rettype, paramtypes, params) \
804 SH_CALL_HOOKS(post, params) \
807 //////////////////////////////////////////////////////////////////////////
808 #define SH_SETUPCALLS_void(paramtypes, params) \
809 /* 1) Find the vfnptr */ \
810 using namespace ::SourceHook; \
811 void *ourvfnptr = reinterpret_cast<void*>( \
812 *reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
813 IVfnPtr *vfnptr = ms_HI->FindVfnPtr(ourvfnptr); \
814 SH_ASSERT(vfnptr, ("Called with vfnptr 0x%p which couldn't be found in the list", ourvfnptr)); \
816 void *vfnptr_origentry = vfnptr->GetOrigEntry(); \
817 /* ... and the iface */ \
818 IIface *ifinfo = vfnptr->FindIface(reinterpret_cast<void*>(this)); \
821 /* The iface info was not found. Redirect the call to the original function. */ \
822 void (EmptyClass::*mfp)paramtypes; \
824 (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
827 /* 2) Declare some vars and set it up */ \
828 SH_GLOB_SHPTR->HookLoopBegin(ifinfo); \
829 IHookList *prelist = ifinfo->GetPreHooks(); \
830 IHookList *postlist = ifinfo->GetPostHooks(); \
831 META_RES status = MRES_IGNORED; \
835 SH_GLOB_SHPTR->SetupHookLoop(&status, &prev_res, &cur_res, &ifptr, NULL, NULL); \
837 #define SH_CALL_HOOKS_void(post, params) \
838 if (SH_GLOB_SHPTR->ShouldContinue()) \
840 prev_res = MRES_IGNORED; \
841 for (AutoHookIter iter(post##list); !iter.End(); iter.Next()) \
843 cur_res = MRES_IGNORED; \
844 ifptr = reinterpret_cast<void*>(reinterpret_cast<char*>(this) - iter.ThisPtrOffs()); \
845 reinterpret_cast<CSHDelegate<FD>*>(iter.Handler())->GetDeleg() params; \
846 prev_res = cur_res; \
847 if (cur_res > status) \
849 if (!SH_GLOB_SHPTR->ShouldContinue()) \
857 #define SH_CALL_ORIG_void(paramtypes, params) \
858 if (status != MRES_SUPERCEDE) \
860 void (EmptyClass::*mfp)paramtypes; \
862 (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
865 #define SH_RETURN_void() \
866 SH_GLOB_SHPTR->HookLoopEnd();
868 #define SH_HANDLEFUNC_void(paramtypes, params) \
869 SH_SETUPCALLS_void(paramtypes, params) \
870 SH_CALL_HOOKS_void(pre, params) \
871 SH_CALL_ORIG_void(paramtypes, params) \
872 SH_CALL_HOOKS_void(post, params) \
876 // Special vafmt handlers
878 #define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
879 SH_SETUPCALLS(rettype, paramtypes, params_orig) \
880 SH_CALL_HOOKS(pre, params_plug) \
881 SH_CALL_ORIG(rettype, paramtypes, params_orig) \
882 SH_CALL_HOOKS(post, params_plug) \
885 #define SH_HANDLEFUNC_void_vafmt(paramtypes, params_orig, params_plug) \
886 SH_SETUPCALLS_void(paramtypes, params_orig) \
887 SH_CALL_HOOKS_void(pre, params_plug) \
888 SH_CALL_ORIG_void(paramtypes, params_orig) \
889 SH_CALL_HOOKS_void(post, params_plug) \
892 //////////////////////////////////////////////////////////////////////////
895 // ********* Support for $1 arguments *********
896 #define SH_DECL_HOOK$1(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
897 SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
898 (&ifacetype::ifacefunc))) \
899 typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
900 virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
901 { SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
902 SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
903 (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
905 const int __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload[] = { 0@[$2,1,$1:, sizeof(param$2)@] }; \
906 ::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto(sizeof(rettype), \
907 $1, __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload);
909 #define SH_DECL_HOOK$1_void(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
910 SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
911 (&ifacetype::ifacefunc))) \
912 typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
913 virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
914 { SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
915 SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
916 (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
919 const int __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload[] = { 0@[$2,1,$1:, sizeof(param$2)@] }; \
920 ::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto(0, \
921 $1, __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload);
923 #define SH_DECL_HOOK$1_vafmt(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
924 SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
925 (&ifacetype::ifacefunc))) \
926 typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> FD; \
927 virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *fmt, ...) \
929 char buf[::SourceHook::STRBUF_LEN]; \
932 vsnprintf(buf, sizeof(buf), fmt, ap); \
934 SH_HANDLEFUNC_vafmt((@[$2,1,$1|, :param$2@]@[$1!=0:, @]...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf), rettype); \
936 SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
937 (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
939 const int __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload[] = { -1@[$2,1,$1:, sizeof(param$2)@] }; \
940 ::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto(sizeof(rettype), \
941 $1, __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload);
943 #define SH_DECL_HOOK$1_void_vafmt(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
944 SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
945 (&ifacetype::ifacefunc))) \
946 typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> FD; \
947 virtual void Func(@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *fmt, ...) \
949 char buf[::SourceHook::STRBUF_LEN]; \
952 vsnprintf(buf, sizeof(buf), fmt, ap); \
954 SH_HANDLEFUNC_void_vafmt((@[$2,1,$1|, :param$2@]@[$1!=0:, @]...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf)); \
956 SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
957 (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
959 const int __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload[] = { -1@[$2,1,$1:, sizeof(param$2)@] }; \
960 ::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto(0, \
961 $1, __SourceHook_ParamSizes_##ifacetype##ifacefunc##overload);
963 #define SH_DECL_MANUALHOOK$1(hookname, vtblidx, vtbloffs, thisptroffs, rettype@[$2,1,$1:, param$2@]) \
964 SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
965 typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
966 virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
967 { SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
968 typedef rettype(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
969 SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
971 const int __SourceHook_ParamSizesM_##hookname[] = { 0@[$2,1,$1:, sizeof(param$2)@] }; \
972 ::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto(sizeof(rettype), \
973 $1, __SourceHook_ParamSizesM_##hookname); \
975 #define SH_DECL_MANUALHOOK$1_void(hookname, vtblidx, vtbloffs, thisptroffs@[$2,1,$1:, param$2@]) \
976 SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
977 typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
978 virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
979 { SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
980 typedef void(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
981 SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
983 const int __SourceHook_ParamSizesM_##hookname[] = { 0@[$2,1,$1:, sizeof(param$2)@] }; \
984 ::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto(0, \
985 $1, __SourceHook_ParamSizesM_##hookname); \
990 //////////////////////////////////////////////////////////////////////////
993 #if SH_COMP == SH_COMP_MSVC
995 # define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
997 using namespace ::SourceHook; \
999 GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
1000 void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
1002 return (m_CC->GetThisPtr()->*m_MFP)call; \
1004 /* It's hooked. Call the original function. */ \
1007 RetType(EmptyClass::*mfpnew)prms; \
1010 u.addr = origfunc; \
1012 void *adjustedthisptr = reinterpret_cast<void*>(reinterpret_cast<char*>(m_CC->GetThisPtr()) + mfi.thisptroffs); \
1013 return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
1016 # define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
1018 using namespace ::SourceHook; \
1019 char *adjustedthisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()) + m_ThisPtrOffs; \
1022 RetType(EmptyClass::*mfpnew)prms; \
1025 u.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
1027 u.addr = (*reinterpret_cast<void***>(adjustedthisptr + m_VtblOffs))[m_VtblIdx]; \
1029 return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
1032 #elif SH_COMP == SH_COMP_GCC
1034 # define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
1036 using namespace ::SourceHook; \
1038 GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
1039 void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
1041 return (m_CC->GetThisPtr()->*m_MFP)call; \
1043 /* It's hooked. Call the original function. */ \
1046 RetType(EmptyClass::*mfpnew)prms; \
1050 intptr_t adjustor; \
1053 u.s.addr = origfunc; \
1054 u.s.adjustor = mfi.thisptroffs; \
1056 return (reinterpret_cast<EmptyClass*>(m_CC->GetThisPtr())->*u.mfpnew)call; \
1059 # define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
1061 using namespace ::SourceHook; \
1062 char *thisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()); \
1065 RetType(EmptyClass::*mfpnew)prms; \
1068 intptr_t adjustor; \
1071 u.s.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
1073 u.s.addr = (*reinterpret_cast<void***>(thisptr + m_ThisPtrOffs + m_VtblOffs))[m_VtblIdx]; \
1075 u.s.adjustor = m_ThisPtrOffs; \
1076 return (reinterpret_cast<EmptyClass*>(thisptr)->*u.mfpnew)call; \
1081 namespace SourceHook
1084 // Support for $1 arguments
1085 template<class CCType, class MFPType, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
1090 ExecutableClass$1(CCType *cc, MFPType mfp) : m_CC(cc), m_MFP(mfp) { }
1092 RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
1093 SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1096 template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
1097 SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1101 template <class RetType@[$2,1,$1:, class Param$2@]> class MExecutableClass$1
1103 ManualCallClass *m_CC;
1108 MExecutableClass$1(ManualCallClass *cc, int vtbloffs, int vtblidx, int thisptroffs) : m_CC(cc),
1109 m_ThisPtrOffs(thisptroffs), m_VtblIdx(vtblidx), m_VtblOffs(vtbloffs) { }
1111 RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
1112 SH_MAKE_MEXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
1115 template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
1116 SH_MAKE_MEXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
1123 // SH_CALL needs to deduce the return type -> it uses templates and function overloading
1124 // That's why SH_CALL takes two parameters: "mfp2" of type RetType(X::*mfp)(params), and "mfp" of type MFP
1125 // The only purpose of the mfp2 parameter is to extract the return type
1128 // Support for $1 arguments
1129 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1130 SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1131 SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]))
1133 return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1136 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1137 SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1138 SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const)
1140 return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1143 template <class X, class RetType@[$2,1,$1:, class Param$2@]>
1144 SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>
1145 SH_MCALL2(SourceHook::ManualCallClass *ptr, RetType(X::*mfp)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs)
1147 return SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>(ptr, vtbloffs, vtblidx, thisptroffs);
1151 #if SH_COMP != SH_COMP_MSVC || _MSC_VER > 1300
1152 // GCC & MSVC 7.1 need this, MSVC 7.0 doesn't like it
1155 // Support for $1 arguments
1156 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1157 SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1158 SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...))
1160 return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1163 template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
1164 SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
1165 SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const)
1167 return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
1174 #define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp))
1175 #define SH_MCALL(ptr, mhookname) SH_MCALL2((ptr), SH_MFHCls(mhookname)::ECMFP(), SH_MFHCls(mhookname)::ms_MFI.vtblindex, \
1176 SH_MFHCls(mhookname)::ms_MFI.vtbloffs, SH_MFHCls(mhookname)::ms_MFI.thisptroffs)
1178 #undef SH_MAKE_EXECUTABLECLASS_OB
1180 //////////////////////////////////////////////////////////////////////////
1181 // SetOverrideRet and RecallGetIface for recalls
1182 // These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
1183 // The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
1184 // (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
1186 namespace SourceHook
1189 template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
1190 void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]), const RetType res)
1192 *reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
1195 template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
1196 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
1198 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1204 // The pope is dead. -> :(