dvander@347: /* ======== SourceHook ======== dvander@347: * Copyright (C) 2004-2007 Metamod:Source Development Team dvander@347: * No warranties of any kind dvander@347: * dvander@347: * License: zlib/libpng dvander@347: * dvander@347: * Author(s): Pavol "PM OnoTo" Marko dvander@347: * ============================ dvander@347: */ dvander@347: dvander@347: #ifndef __SOURCEHOOK_IMPL_H__ dvander@347: #define __SOURCEHOOK_IMPL_H__ dvander@347: dvander@347: #include "sourcehook.h" dvander@347: #include "sh_list.h" dvander@347: #include "sh_vector.h" dvander@347: #include "sh_tinyhash.h" dvander@347: #include "sh_stack.h" dvander@347: dvander@347: /* dvander@347: dvander@347: IMPLEMENTATION INFO dvander@347: dvander@347: --------------------------------------- dvander@347: Protos ("Prototypes") dvander@347: The purpose of protos is to provide the amount of type information about a function dvander@347: which is required to be able to execute a function call without corrupting the stack. dvander@347: Our protos do not fully do this, but they provide the size of the return value, the number of dvander@347: parameters, and the size of each parameter, which is enough for most situations. dvander@347: dvander@347: There are two version of protos: dvander@347: OLD: dvander@347: C-Style strings. dvander@347: dvander@347: 0_void: dvander@347: "attrib" dvander@347: 1_void: dvander@347: "attrib|param1_type" dvander@347: 2_void: dvander@347: "attrib|param1_type|param2_type dvander@347: 0: dvander@347: "attrib|ret_type" dvander@347: 1: dvander@347: "attrib|ret_type|param1_type" dvander@347: 2: dvander@347: "attrib|ret_type|param2_type" dvander@347: dvander@347: Old protos are deprecated. dvander@347: dvander@347: NEW: dvander@347: New protos are in fact pointers to the ProtoInfo structure (see sourcehook.h) dvander@347: dvander@347: Old protos begin with a non-zero byte, new protos begin with a zero byte. dvander@347: dvander@347: Protos are usually stored in a CProto instance. dvander@347: dvander@347: --------------------------------------- dvander@347: Hook managers and hook manager containers dvander@347: Each hookman container is tied to _one_ proto/vtable index/vtable offset info. dvander@347: Hookman containers then contain a list of hook managers provided by plugins, sorted by version. dvander@347: (higher versions come first) dvander@347: dvander@347: Duplicate hook managers are ignored (ie. hook managers where proto, vtable index, vtable offset, dvander@347: plugin, version are the same as in an already exisiting hook manager) dvander@347: dvander@347: A new hook manager is always added to the end of the version group in the corresponding dvander@347: hook container. dvander@347: dvander@347: If the new hook manager was added to the beginning of the container (which only happens if dvander@347: it is the first one or if it has a higher version than the previously first hook manager), dvander@347: the now second hook manager is shut down and the new hook manager takes its job. dvander@347: dvander@347: A "hook manager container id" (HMCI) consits of three values: proto, vtbl index, vtbl offset. dvander@347: --------------------------------------- dvander@347: Hooks dvander@347: When adding a hook, first the proposed hook manager is added to the corresponding dvander@347: hook manager container as described above. dvander@347: dvander@347: Then the first hook manager in the the manhook container is chosen to handle the function. dvander@347: dvander@347: Removing a hook does not neccessarily unreigster the plugin's hook manager. In order to do this, dvander@347: use RemoveHookManager or UnloadPlugin/ dvander@347: dvander@347: Hooks can be paused - they remain in memory but they are not called. In SH, the hook iterator dvander@347: classes handle pausing transparently. dvander@347: dvander@347: The hook loop is supposed to call ShouldContinue before each iteration. This makes hook handlers dvander@347: able to remove themselves. dvander@347: dvander@347: --------------------------------------- dvander@347: Call classes dvander@347: Call classes are identified by a this pointer and an instance size dvander@347: dvander@347: We use the instance size because a derived class instance and a base class instance could dvander@347: have the same this pointers, and we want to avoid that the derived class dvander@347: (which could be bigger) gets the same callclass as the base class (mainly if the dvander@347: base class' callclass was requested first). dvander@347: dvander@347: Call classes are reference counted. dvander@347: dvander@347: The original function pointers are stored in a vector (in order to allow fast random access). dvander@347: These vectors are stored as the value type of a hash. The key type is int and represents the dvander@347: vtable offset. dvander@347: dvander@347: If the hash key doesn't exist or the vtblidx is out of range or the corresponding element in the dvander@347: vector is NULL, there is no hook on that function. dvander@347: dvander@347: --------------------------------------- dvander@347: Recalls dvander@347: Recalls are used for the META_RETURN_(VALUE_)NEWPARAMS macros, ie. to change the parameters dvander@347: in the hook loop on the fly. dvander@347: dvander@347: First, the macro calls DoRecall(), then it calls the function the hook is attached to -> it dvander@347: calls the hookfunc. SourceHook makes sure that the newly invoked hook loop starts where the last dvander@347: one left off and that status variables like status, previous result, override return are kept. dvander@347: When this recurisvely called hookfunc returns, the macro returns what it returned dvander@347: (using MRES_SUPERCEDE). CSourceHookImpl returns false from ShouldContinue so the original hook loop dvander@347: is abandonned. dvander@347: dvander@347: Post Recalls dvander@347: People wanted to be able to use META_RETURN_(VALUE_)NEWPARAMS from post hooks as well. Crazy people! dvander@347: Anyway, for this, we have to know where a hook handler is. Is it executing pre or post hooks at the moment? dvander@347: The only way we can know this is watching when it calls CHookList::GetIter(). So CHookList gets a new variable: dvander@347: m_RequestedFlag. It also gets two new functions: RQFlagReset() and RQFlagGet(). dvander@347: HookLoopBegin() calls RQFlagReset on both hooklists of the iface; then DoRecall() checks whether the postlist's dvander@347: RQ flag is set. if yes, the hook loop is in post mode. dvander@347: dvander@347: So, what a about a recall in post mode? The first ShouldContinue returns false and sets Status to supercede. dvander@347: This way the pre hooks and the function call will be skipped. Then, then next ShouldContinue returns true, so we get dvander@347: into the post hooks. HA! dvander@347: dvander@347: Return Values in Post Recalls dvander@347: The easy case is when we already have an override return value. In this case, the status register gets transferred, dvander@347: and so does the override return pointer. So, basically, everything is ok. dvander@347: dvander@347: However, what happens if we don't? ie. the status register is on MRES_IGNORED? In this case we'd have to transfer the dvander@347: orig ret value. But we can't: There's no way to tell the hookfunc: "Use this as orig ret pointer". It uses its own. dvander@347: So, we emulate it. GetOrigRet will return the orig ret pointer from the old hook loop. If still no one overrides it, dvander@347: we'd have to return it. BUT! HOW TO DO THIS? Check out SH_RETURN(). First calls HookLoopEnd(), then decides whether dvander@347: to return the override retval or the orig retval. But it doesn't ask for a new override return. So we give the function dvander@347: the last orig return value as its new override return value; but leave status where it is so everything works, and in dvander@347: HookLoopEnd we make sure that status is high enough so that the override return will be returned. crazy. dvander@347: dvander@347: All this stuff could be much less complicated if I didn't try to preserve binary compatibility :) dvander@347: */ dvander@347: dvander@347: namespace SourceHook dvander@347: { dvander@347: /** dvander@347: * @brief The SourceHook implementation class dvander@347: */ dvander@347: class CSourceHookImpl : public ISourceHook dvander@347: { dvander@347: private: dvander@347: class CProto dvander@347: { dvander@347: char *m_Proto; dvander@347: dvander@347: static bool Equal(const char *p1, const char *p2); dvander@347: char *DupProto(const char *src); dvander@347: void FreeProto(char *prot); dvander@347: public: dvander@347: CProto(const char *szProto) : m_Proto(DupProto(szProto)) dvander@347: { dvander@347: } dvander@347: dvander@347: CProto(const CProto &other) : m_Proto(DupProto(other.m_Proto)) dvander@347: { dvander@347: } dvander@347: dvander@347: ~CProto() dvander@347: { dvander@347: FreeProto(m_Proto); dvander@347: m_Proto = NULL; dvander@347: } dvander@347: dvander@347: void operator = (const char *szProto) dvander@347: { dvander@347: m_Proto = DupProto(szProto); dvander@347: } dvander@347: dvander@347: void operator = (const CProto &other) dvander@347: { dvander@347: m_Proto = DupProto(other.m_Proto); dvander@347: } dvander@347: dvander@347: bool operator == (const char *szProto) const dvander@347: { dvander@347: return Equal(szProto, m_Proto); dvander@347: } dvander@347: bool operator == (const CProto &other) const dvander@347: { dvander@347: return Equal(other.m_Proto, m_Proto); dvander@347: } dvander@347: }; dvander@347: dvander@347: dvander@347: /** dvander@347: * @brief A hook can be removed if you have this information dvander@347: */ dvander@347: struct RemoveHookInfo dvander@347: { dvander@347: RemoveHookInfo(Plugin pplug, void *piface, int tpo, HookManagerPubFunc phookman, dvander@347: ISHDelegate *phandler, bool ppost) dvander@347: : plug(pplug), iface(piface), thisptr_offs(tpo), dvander@347: hookman(phookman), handler(phandler), post(ppost) dvander@347: { dvander@347: } dvander@347: dvander@347: Plugin plug; dvander@347: void *iface; dvander@347: int thisptr_offs; dvander@347: HookManagerPubFunc hookman; dvander@347: ISHDelegate *handler; dvander@347: bool post; dvander@347: }; dvander@347: dvander@347: struct RemoveHookManInfo dvander@347: { dvander@347: RemoveHookManInfo(Plugin pplug, HookManagerPubFunc phookman) dvander@347: : plug(pplug), hookman(phookman) dvander@347: { dvander@347: } dvander@347: dvander@347: Plugin plug; dvander@347: HookManagerPubFunc hookman; dvander@347: }; dvander@347: dvander@347: struct HookInfo dvander@347: { dvander@347: ISHDelegate *handler; //!< Pointer to the handler dvander@347: bool paused; //!< If true, the hook should not be executed dvander@347: Plugin plug; //!< The owner plugin dvander@347: int thisptr_offs; //!< This pointer offset dvander@347: }; dvander@347: dvander@347: class CHookList : public IHookList dvander@347: { dvander@347: public: dvander@347: List m_List; dvander@347: dvander@347: friend class CIter; dvander@347: dvander@347: class CIter : public IHookList::IIter dvander@347: { dvander@347: friend class CHookList; dvander@347: dvander@347: CHookList *m_pList; dvander@347: dvander@347: void SkipPaused(); dvander@347: public: dvander@347: dvander@347: List::iterator m_Iter; dvander@347: dvander@347: CIter(CHookList *pList); dvander@347: dvander@347: virtual ~CIter(); dvander@347: dvander@347: void GoToBegin(); dvander@347: void Set(CIter *pOther); dvander@347: dvander@347: bool End(); dvander@347: void Next(); dvander@347: ISHDelegate *Handler(); dvander@347: int ThisPtrOffs(); dvander@347: dvander@347: void Clear(); dvander@347: dvander@347: CIter *m_pNext; // When stored in m_FreeIters and m_UsedIters dvander@347: CIter *m_pPrev; // Only used when stored in m_UsedIters dvander@347: }; dvander@347: dvander@347: CIter *m_FreeIters; dvander@347: CIter *m_UsedIters; // The last returned and not-yet-released iter is always m_UsedIters dvander@347: dvander@347: // For recalls dvander@347: bool m_Recall; dvander@347: bool m_RQFlag; dvander@347: dvander@347: void SetRecallState(); // Sets the list into a state where the next returned dvander@347: // iterator (from GetIter) will be a copy of the last dvander@347: // returned iterator, incremented by one. This is used in Recalls. dvander@347: // The hook resets this state automatically on: dvander@347: // GetIter, ReleaseIter dvander@347: dvander@347: void RQFlagReset() { m_RQFlag = false; } dvander@347: bool RQFlagGet() { return m_RQFlag; } dvander@347: CHookList(); dvander@347: CHookList(const CHookList &other); dvander@347: virtual ~CHookList(); dvander@347: dvander@347: void operator=(const CHookList &other); dvander@347: dvander@347: IIter *GetIter(); dvander@347: void ReleaseIter(IIter *pIter); dvander@347: }; dvander@347: dvander@347: // I know, data hiding... But I'm a lazy bastard! dvander@347: dvander@347: class CIface : public IIface dvander@347: { dvander@347: public: dvander@347: void *m_Ptr; dvander@347: CHookList m_PreHooks; dvander@347: CHookList m_PostHooks; dvander@347: public: dvander@347: CIface(void *ptr); dvander@347: virtual ~CIface(); dvander@347: dvander@347: void *GetPtr(); dvander@347: IHookList *GetPreHooks(); dvander@347: IHookList *GetPostHooks(); dvander@347: dvander@347: bool operator==(void *ptr) dvander@347: { dvander@347: return m_Ptr == ptr; dvander@347: } dvander@347: }; dvander@347: dvander@347: class CVfnPtr : public IVfnPtr dvander@347: { dvander@347: public: dvander@347: typedef List IfaceList; dvander@347: typedef IfaceList::iterator IfaceListIter; dvander@347: dvander@347: void *m_Ptr; dvander@347: void *m_OrigEntry; dvander@347: dvander@347: IfaceList m_Ifaces; dvander@347: dvander@347: public: dvander@347: CVfnPtr(void *ptr); dvander@347: virtual ~CVfnPtr(); dvander@347: dvander@347: void *GetVfnPtr(); dvander@347: void *GetOrigEntry(); dvander@347: dvander@347: virtual IIface *FindIface(void *ptr); dvander@347: dvander@347: bool operator==(void *ptr) dvander@347: { dvander@347: return m_Ptr == ptr; dvander@347: } dvander@347: }; dvander@347: dvander@347: class CHookManagerInfo : public IHookManagerInfo dvander@347: { dvander@347: public: dvander@347: typedef List VfnPtrList; dvander@347: typedef VfnPtrList::iterator VfnPtrListIter; dvander@347: dvander@347: Plugin m_Plug; dvander@347: HookManagerPubFunc m_Func; dvander@347: dvander@347: int m_VtblOffs; dvander@347: int m_VtblIdx; dvander@347: const char *m_Proto; dvander@347: void *m_HookfuncVfnptr; dvander@347: dvander@347: VfnPtrList m_VfnPtrs; dvander@347: dvander@347: int m_HookManVersion; dvander@347: public: dvander@347: CHookManagerInfo(); dvander@347: virtual ~CHookManagerInfo(); dvander@347: dvander@347: IVfnPtr *FindVfnPtr(void *vfnptr); dvander@347: dvander@347: void SetInfo(int vtbl_offs, int vtbl_idx, const char *proto); dvander@347: void SetHookfuncVfnptr(void *hookfunc_vfnptr); dvander@347: dvander@347: void SetVersion(int version); dvander@347: dvander@347: bool operator < (const CHookManagerInfo &other) dvander@347: { dvander@347: return m_HookManVersion < other.m_HookManVersion; dvander@347: } dvander@347: dvander@347: struct Descriptor dvander@347: { dvander@347: Descriptor(Plugin pplug, HookManagerPubFunc ppubFunc) : plug(pplug), pubFunc(ppubFunc) dvander@347: { dvander@347: } dvander@347: dvander@347: Plugin plug; dvander@347: HookManagerPubFunc pubFunc; dvander@347: }; dvander@347: dvander@347: bool operator == (const Descriptor desc) dvander@347: { dvander@347: return m_Func == desc.pubFunc && m_Plug == desc.plug; dvander@347: } dvander@347: }; dvander@347: dvander@347: typedef List HookManInfoList; dvander@347: dvander@347: class CHookManagerContainer : public HookManInfoList dvander@347: { dvander@347: public: dvander@347: // HMCI (Hook Manager Container Identification) dvander@347: class HMCI dvander@347: { dvander@347: CProto m_Proto; dvander@347: int m_VtableOffset; dvander@347: int m_VtableIndex; dvander@347: public: dvander@347: HMCI(const char *proto, int vtbloffs, int vtblidx) : dvander@347: m_Proto(proto), m_VtableOffset(vtbloffs), m_VtableIndex(vtblidx) dvander@347: { dvander@347: } dvander@347: ~HMCI() dvander@347: { dvander@347: } dvander@347: dvander@347: bool operator==(const HMCI &other) const dvander@347: { dvander@347: return dvander@347: other.m_VtableIndex == m_VtableIndex && dvander@347: other.m_Proto == m_Proto && dvander@347: other.m_VtableOffset == m_VtableOffset; dvander@347: } dvander@347: dvander@347: const CProto &GetProto() const dvander@347: { dvander@347: return m_Proto; dvander@347: } dvander@347: int GetVtableOffset() const dvander@347: { dvander@347: return m_VtableOffset; dvander@347: } dvander@347: int GetVtableIndex() const dvander@347: { dvander@347: return m_VtableIndex; dvander@347: } dvander@347: }; dvander@347: HMCI m_HCMI; dvander@347: dvander@347: public: dvander@347: CHookManagerContainer(const HMCI &hmci) : m_HCMI(hmci) dvander@347: { dvander@347: } dvander@347: bool operator == (const HMCI &other) const dvander@347: { dvander@347: return m_HCMI == other; dvander@347: } dvander@347: void AddHookManager(Plugin plug, const CHookManagerInfo &hookman); dvander@347: }; dvander@347: dvander@347: class CCallClassImpl : public GenericCallClass dvander@347: { dvander@347: public: dvander@347: dvander@347: typedef SourceHook::CVector OrigFuncs; dvander@347: typedef SourceHook::THash OrigVTables; dvander@347: dvander@347: void *m_Ptr; //!< Pointer to the actual object dvander@347: size_t m_ObjSize; //!< Size of the instance dvander@347: OrigVTables m_VT; //!< Info about vtables & functions dvander@347: dvander@347: int m_RefCounter; dvander@347: dvander@347: CCallClassImpl(void *ptr, size_t size); dvander@347: virtual ~CCallClassImpl(); dvander@347: dvander@347: bool operator==(void *other) dvander@347: { dvander@347: return m_Ptr == other; dvander@347: } dvander@347: dvander@347: void *GetThisPtr(); dvander@347: void *GetOrigFunc(int vtbloffs, int vtblidx); dvander@347: dvander@347: void ApplyCallClassPatch(int vtbl_offs, int vtbl_idx, void *orig_entry); dvander@347: void RemoveCallClassPatch(int vtbl_offs, int vtbl_idx); dvander@347: }; dvander@347: dvander@347: /** dvander@347: * @brief A list of CallClass structures dvander@347: */ dvander@347: typedef List Impl_CallClassList; dvander@347: dvander@347: Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses dvander@347: dvander@347: /** dvander@347: * @brief A list of CHookManagerContainers dvander@347: */ dvander@347: typedef List HookManContList; dvander@347: dvander@347: HookManContList m_HookMans; //!< A list of hook managers dvander@347: dvander@347: struct HookLoopInfo dvander@347: { dvander@347: enum RecallType dvander@347: { dvander@347: Recall_No=0, dvander@347: Recall_Pre, dvander@347: Recall_Post1, dvander@347: Recall_Post2 dvander@347: }; dvander@347: dvander@347: META_RES *pStatus; dvander@347: META_RES *pPrevRes; dvander@347: META_RES *pCurRes; dvander@347: dvander@347: META_RES temporaryStatus; //!< Stored during Post1 recall phase dvander@347: bool shouldContinue; dvander@347: RecallType recall; //!< Specifies which kind of recall we're in. dvander@347: dvander@347: IIface *pCurIface; dvander@347: const void *pOrigRet; dvander@347: void *pOverrideRet; dvander@347: void **pIfacePtrPtr; dvander@347: }; dvander@347: typedef CStack HookLoopInfoStack; dvander@347: dvander@347: void ApplyCallClassPatches(CCallClassImpl &cc); dvander@347: void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry); dvander@347: void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx); dvander@347: dvander@347: void SetPluginPaused(Plugin plug, bool paused); dvander@347: dvander@347: HookLoopInfoStack m_HLIStack; dvander@347: public: dvander@347: CSourceHookImpl(); dvander@347: virtual ~CSourceHookImpl(); dvander@347: dvander@347: /** dvander@347: * @brief Returns the interface version dvander@347: */ dvander@347: int GetIfaceVersion(); dvander@347: dvander@347: /** dvander@347: * @brief Returns the implemnetation version dvander@347: */ dvander@347: int GetImplVersion(); dvander@347: dvander@347: /** dvander@347: * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers dvander@347: */ dvander@347: void UnloadPlugin(Plugin plug); dvander@347: dvander@347: /** dvander@347: * @brief Shut down the whole system, unregister all hook managers dvander@347: */ dvander@347: void CompleteShutdown(); dvander@347: dvander@347: /** dvander@347: * @brief Add a hook. dvander@347: * dvander@347: * @return True if the function succeeded, false otherwise dvander@347: * dvander@347: * @param plug The unique identifier of the plugin that calls this function dvander@347: * @param iface The interface pointer dvander@347: * @param ifacesize The size of the class iface points to dvander@347: * @param myHookMan A hook manager function that should be capable of handling the function dvander@347: * @param handler A pointer to a FastDelegate containing the hook handler dvander@347: * @param post Set to true if you want a post handler dvander@347: */ dvander@347: bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post); dvander@347: dvander@347: /** dvander@347: * @brief Removes a hook. dvander@347: * dvander@347: * @return True if the function succeeded, false otherwise dvander@347: * dvander@347: * @param plug The unique identifier of the plugin that calls this function dvander@347: * @param iface The interface pointer dvander@347: * @param thisptr_offs This pointer adjuster dvander@347: * @param myHookMan A hook manager function that should be capable of handling the function dvander@347: * @param handler A pointer to a FastDelegate containing the hook handler dvander@347: * @param post Set to true if you want a post handler dvander@347: */ dvander@347: bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post); dvander@347: dvander@347: /** dvander@347: * @brief Removes a hook. dvander@347: * dvander@347: * @ return True if the function succeeded, false otherwise dvander@347: * dvander@347: * @param info A RemoveHookInfo structure, describing the hook dvander@347: */ dvander@347: bool RemoveHook(RemoveHookInfo info); dvander@347: dvander@347: /** dvander@347: * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins dvander@347: * dvander@347: * @param plug The unique identifier of the plugin in question dvander@347: */ dvander@347: bool IsPluginInUse(Plugin plug); dvander@347: dvander@347: /** dvander@347: * @brief Pauses all hooks of a plugin dvander@347: * dvander@347: * @param plug The unique identifier of the plugin dvander@347: */ dvander@347: void PausePlugin(Plugin plug); dvander@347: dvander@347: /** dvander@347: * @brief Unpauses all hooks of a plugin dvander@347: * dvander@347: * @param plug The unique identifier of the plugin dvander@347: */ dvander@347: void UnpausePlugin(Plugin plug); dvander@347: dvander@347: /** dvander@347: * @brief Return a pointer to a callclass. Generate a new one if required. dvander@347: * dvander@347: * @param iface The interface pointer dvander@347: * @param size Size of the class instance dvander@347: */ dvander@347: GenericCallClass *GetCallClass(void *iface, size_t size); dvander@347: dvander@347: /** dvander@347: * @brief Release a callclass dvander@347: * dvander@347: * @param ptr Pointer to the callclass dvander@347: */ dvander@347: virtual void ReleaseCallClass(GenericCallClass *ptr); dvander@347: dvander@347: virtual void SetRes(META_RES res); //!< Sets the meta result dvander@347: virtual META_RES GetPrevRes(); //!< Gets the meta result of the previously called handler dvander@347: virtual META_RES GetStatus(); //!< Gets the highest meta result dvander@347: virtual const void *GetOrigRet(); //!< Gets the original result. If not in post function, undefined dvander@347: virtual const void *GetOverrideRet(); //!< Gets the override result. If none is specified, NULL dvander@347: virtual void *GetIfacePtr(); //!< Gets the interface pointer dvander@347: dvander@347: ////////////////////////////////////////////////////////////////////////// dvander@347: // For hook managers dvander@347: void HookLoopBegin(IIface *pIface); //!< Should be called when a hook loop begins dvander@347: void HookLoopEnd(); //!< Should be called when a hook loop exits dvander@347: void SetCurResPtr(META_RES *mres); //!< Sets pointer to the current meta result dvander@347: void SetPrevResPtr(META_RES *mres); //!< Sets pointer to previous meta result dvander@347: void SetStatusPtr(META_RES *mres); //!< Sets pointer to the status variable dvander@347: void SetIfacePtrPtr(void **pp); //!< Sets pointer to the interface this pointer dvander@347: void SetOrigRetPtr(const void *ptr); //!< Sets the original return pointer dvander@347: void SetOverrideRetPtr(void *ptr); //!< Sets the override result pointer dvander@347: bool ShouldContinue(); //!< Returns false if the hook loop should exit dvander@347: dvander@347: /** dvander@347: * @brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug. dvander@347: * dvander@347: * @param plug The owner of the hook manager dvander@347: * @param pubFunc The hook manager's info function dvander@347: */ dvander@347: virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc); dvander@347: virtual void RemoveHookManager(RemoveHookManInfo info); dvander@347: dvander@347: virtual void DoRecall(); //!< Initiates a recall sequence dvander@347: virtual void *GetOverrideRetPtr(); //!< Returns the pointer set by SetOverrideRetPtr dvander@347: dvander@347: virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr, dvander@347: void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr); dvander@347: }; dvander@347: } dvander@347: dvander@347: #endif