1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcehook/sourcehook_impl.h Tue Sep 18 20:03:47 2007 +0000
1.3 @@ -0,0 +1,656 @@
1.4 +/* ======== SourceHook ========
1.5 +* Copyright (C) 2004-2007 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): Pavol "PM OnoTo" Marko
1.11 +* ============================
1.12 +*/
1.13 +
1.14 +#ifndef __SOURCEHOOK_IMPL_H__
1.15 +#define __SOURCEHOOK_IMPL_H__
1.16 +
1.17 +#include "sourcehook.h"
1.18 +#include "sh_list.h"
1.19 +#include "sh_vector.h"
1.20 +#include "sh_tinyhash.h"
1.21 +#include "sh_stack.h"
1.22 +
1.23 +/*
1.24 +
1.25 +IMPLEMENTATION INFO
1.26 +
1.27 +---------------------------------------
1.28 +Protos ("Prototypes")
1.29 + The purpose of protos is to provide the amount of type information about a function
1.30 + which is required to be able to execute a function call without corrupting the stack.
1.31 + Our protos do not fully do this, but they provide the size of the return value, the number of
1.32 + parameters, and the size of each parameter, which is enough for most situations.
1.33 +
1.34 + There are two version of protos:
1.35 + OLD:
1.36 + C-Style strings.
1.37 +
1.38 + 0_void:
1.39 + "attrib"
1.40 + 1_void:
1.41 + "attrib|param1_type"
1.42 + 2_void:
1.43 + "attrib|param1_type|param2_type
1.44 + 0:
1.45 + "attrib|ret_type"
1.46 + 1:
1.47 + "attrib|ret_type|param1_type"
1.48 + 2:
1.49 + "attrib|ret_type|param2_type"
1.50 +
1.51 + Old protos are deprecated.
1.52 +
1.53 + NEW:
1.54 + New protos are in fact pointers to the ProtoInfo structure (see sourcehook.h)
1.55 +
1.56 + Old protos begin with a non-zero byte, new protos begin with a zero byte.
1.57 +
1.58 + Protos are usually stored in a CProto instance.
1.59 +
1.60 +---------------------------------------
1.61 +Hook managers and hook manager containers
1.62 + Each hookman container is tied to _one_ proto/vtable index/vtable offset info.
1.63 + Hookman containers then contain a list of hook managers provided by plugins, sorted by version.
1.64 + (higher versions come first)
1.65 +
1.66 + Duplicate hook managers are ignored (ie. hook managers where proto, vtable index, vtable offset,
1.67 + plugin, version are the same as in an already exisiting hook manager)
1.68 +
1.69 + A new hook manager is always added to the end of the version group in the corresponding
1.70 + hook container.
1.71 +
1.72 + If the new hook manager was added to the beginning of the container (which only happens if
1.73 + it is the first one or if it has a higher version than the previously first hook manager),
1.74 + the now second hook manager is shut down and the new hook manager takes its job.
1.75 +
1.76 + A "hook manager container id" (HMCI) consits of three values: proto, vtbl index, vtbl offset.
1.77 +---------------------------------------
1.78 +Hooks
1.79 + When adding a hook, first the proposed hook manager is added to the corresponding
1.80 + hook manager container as described above.
1.81 +
1.82 + Then the first hook manager in the the manhook container is chosen to handle the function.
1.83 +
1.84 + Removing a hook does not neccessarily unreigster the plugin's hook manager. In order to do this,
1.85 + use RemoveHookManager or UnloadPlugin/
1.86 +
1.87 + Hooks can be paused - they remain in memory but they are not called. In SH, the hook iterator
1.88 + classes handle pausing transparently.
1.89 +
1.90 + The hook loop is supposed to call ShouldContinue before each iteration. This makes hook handlers
1.91 + able to remove themselves.
1.92 +
1.93 +---------------------------------------
1.94 +Call classes
1.95 + Call classes are identified by a this pointer and an instance size
1.96 +
1.97 + We use the instance size because a derived class instance and a base class instance could
1.98 + have the same this pointers, and we want to avoid that the derived class
1.99 + (which could be bigger) gets the same callclass as the base class (mainly if the
1.100 + base class' callclass was requested first).
1.101 +
1.102 + Call classes are reference counted.
1.103 +
1.104 + The original function pointers are stored in a vector (in order to allow fast random access).
1.105 + These vectors are stored as the value type of a hash. The key type is int and represents the
1.106 + vtable offset.
1.107 +
1.108 + If the hash key doesn't exist or the vtblidx is out of range or the corresponding element in the
1.109 + vector is NULL, there is no hook on that function.
1.110 +
1.111 +---------------------------------------
1.112 +Recalls
1.113 + Recalls are used for the META_RETURN_(VALUE_)NEWPARAMS macros, ie. to change the parameters
1.114 + in the hook loop on the fly.
1.115 +
1.116 + First, the macro calls DoRecall(), then it calls the function the hook is attached to -> it
1.117 + calls the hookfunc. SourceHook makes sure that the newly invoked hook loop starts where the last
1.118 + one left off and that status variables like status, previous result, override return are kept.
1.119 + When this recurisvely called hookfunc returns, the macro returns what it returned
1.120 + (using MRES_SUPERCEDE). CSourceHookImpl returns false from ShouldContinue so the original hook loop
1.121 + is abandonned.
1.122 +
1.123 +Post Recalls
1.124 + People wanted to be able to use META_RETURN_(VALUE_)NEWPARAMS from post hooks as well. Crazy people!
1.125 + Anyway, for this, we have to know where a hook handler is. Is it executing pre or post hooks at the moment?
1.126 + The only way we can know this is watching when it calls CHookList::GetIter(). So CHookList gets a new variable:
1.127 + m_RequestedFlag. It also gets two new functions: RQFlagReset() and RQFlagGet().
1.128 + HookLoopBegin() calls RQFlagReset on both hooklists of the iface; then DoRecall() checks whether the postlist's
1.129 + RQ flag is set. if yes, the hook loop is in post mode.
1.130 +
1.131 + So, what a about a recall in post mode? The first ShouldContinue returns false and sets Status to supercede.
1.132 + This way the pre hooks and the function call will be skipped. Then, then next ShouldContinue returns true, so we get
1.133 + into the post hooks. HA!
1.134 +
1.135 +Return Values in Post Recalls
1.136 + The easy case is when we already have an override return value. In this case, the status register gets transferred,
1.137 + and so does the override return pointer. So, basically, everything is ok.
1.138 +
1.139 + However, what happens if we don't? ie. the status register is on MRES_IGNORED? In this case we'd have to transfer the
1.140 + 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.
1.141 + So, we emulate it. GetOrigRet will return the orig ret pointer from the old hook loop. If still no one overrides it,
1.142 + we'd have to return it. BUT! HOW TO DO THIS? Check out SH_RETURN(). First calls HookLoopEnd(), then decides whether
1.143 + to return the override retval or the orig retval. But it doesn't ask for a new override return. So we give the function
1.144 + the last orig return value as its new override return value; but leave status where it is so everything works, and in
1.145 + HookLoopEnd we make sure that status is high enough so that the override return will be returned. crazy.
1.146 +
1.147 + All this stuff could be much less complicated if I didn't try to preserve binary compatibility :)
1.148 +*/
1.149 +
1.150 +namespace SourceHook
1.151 +{
1.152 + /**
1.153 + * @brief The SourceHook implementation class
1.154 + */
1.155 + class CSourceHookImpl : public ISourceHook
1.156 + {
1.157 + private:
1.158 + class CProto
1.159 + {
1.160 + char *m_Proto;
1.161 +
1.162 + static bool Equal(const char *p1, const char *p2);
1.163 + char *DupProto(const char *src);
1.164 + void FreeProto(char *prot);
1.165 + public:
1.166 + CProto(const char *szProto) : m_Proto(DupProto(szProto))
1.167 + {
1.168 + }
1.169 +
1.170 + CProto(const CProto &other) : m_Proto(DupProto(other.m_Proto))
1.171 + {
1.172 + }
1.173 +
1.174 + ~CProto()
1.175 + {
1.176 + FreeProto(m_Proto);
1.177 + m_Proto = NULL;
1.178 + }
1.179 +
1.180 + void operator = (const char *szProto)
1.181 + {
1.182 + m_Proto = DupProto(szProto);
1.183 + }
1.184 +
1.185 + void operator = (const CProto &other)
1.186 + {
1.187 + m_Proto = DupProto(other.m_Proto);
1.188 + }
1.189 +
1.190 + bool operator == (const char *szProto) const
1.191 + {
1.192 + return Equal(szProto, m_Proto);
1.193 + }
1.194 + bool operator == (const CProto &other) const
1.195 + {
1.196 + return Equal(other.m_Proto, m_Proto);
1.197 + }
1.198 + };
1.199 +
1.200 +
1.201 + /**
1.202 + * @brief A hook can be removed if you have this information
1.203 + */
1.204 + struct RemoveHookInfo
1.205 + {
1.206 + RemoveHookInfo(Plugin pplug, void *piface, int tpo, HookManagerPubFunc phookman,
1.207 + ISHDelegate *phandler, bool ppost)
1.208 + : plug(pplug), iface(piface), thisptr_offs(tpo),
1.209 + hookman(phookman), handler(phandler), post(ppost)
1.210 + {
1.211 + }
1.212 +
1.213 + Plugin plug;
1.214 + void *iface;
1.215 + int thisptr_offs;
1.216 + HookManagerPubFunc hookman;
1.217 + ISHDelegate *handler;
1.218 + bool post;
1.219 + };
1.220 +
1.221 + struct RemoveHookManInfo
1.222 + {
1.223 + RemoveHookManInfo(Plugin pplug, HookManagerPubFunc phookman)
1.224 + : plug(pplug), hookman(phookman)
1.225 + {
1.226 + }
1.227 +
1.228 + Plugin plug;
1.229 + HookManagerPubFunc hookman;
1.230 + };
1.231 +
1.232 + struct HookInfo
1.233 + {
1.234 + ISHDelegate *handler; //!< Pointer to the handler
1.235 + bool paused; //!< If true, the hook should not be executed
1.236 + Plugin plug; //!< The owner plugin
1.237 + int thisptr_offs; //!< This pointer offset
1.238 + };
1.239 +
1.240 + class CHookList : public IHookList
1.241 + {
1.242 + public:
1.243 + List<HookInfo> m_List;
1.244 +
1.245 + friend class CIter;
1.246 +
1.247 + class CIter : public IHookList::IIter
1.248 + {
1.249 + friend class CHookList;
1.250 +
1.251 + CHookList *m_pList;
1.252 +
1.253 + void SkipPaused();
1.254 + public:
1.255 +
1.256 + List<HookInfo>::iterator m_Iter;
1.257 +
1.258 + CIter(CHookList *pList);
1.259 +
1.260 + virtual ~CIter();
1.261 +
1.262 + void GoToBegin();
1.263 + void Set(CIter *pOther);
1.264 +
1.265 + bool End();
1.266 + void Next();
1.267 + ISHDelegate *Handler();
1.268 + int ThisPtrOffs();
1.269 +
1.270 + void Clear();
1.271 +
1.272 + CIter *m_pNext; // When stored in m_FreeIters and m_UsedIters
1.273 + CIter *m_pPrev; // Only used when stored in m_UsedIters
1.274 + };
1.275 +
1.276 + CIter *m_FreeIters;
1.277 + CIter *m_UsedIters; // The last returned and not-yet-released iter is always m_UsedIters
1.278 +
1.279 + // For recalls
1.280 + bool m_Recall;
1.281 + bool m_RQFlag;
1.282 +
1.283 + void SetRecallState(); // Sets the list into a state where the next returned
1.284 + // iterator (from GetIter) will be a copy of the last
1.285 + // returned iterator, incremented by one. This is used in Recalls.
1.286 + // The hook resets this state automatically on:
1.287 + // GetIter, ReleaseIter
1.288 +
1.289 + void RQFlagReset() { m_RQFlag = false; }
1.290 + bool RQFlagGet() { return m_RQFlag; }
1.291 + CHookList();
1.292 + CHookList(const CHookList &other);
1.293 + virtual ~CHookList();
1.294 +
1.295 + void operator=(const CHookList &other);
1.296 +
1.297 + IIter *GetIter();
1.298 + void ReleaseIter(IIter *pIter);
1.299 + };
1.300 +
1.301 + // I know, data hiding... But I'm a lazy bastard!
1.302 +
1.303 + class CIface : public IIface
1.304 + {
1.305 + public:
1.306 + void *m_Ptr;
1.307 + CHookList m_PreHooks;
1.308 + CHookList m_PostHooks;
1.309 + public:
1.310 + CIface(void *ptr);
1.311 + virtual ~CIface();
1.312 +
1.313 + void *GetPtr();
1.314 + IHookList *GetPreHooks();
1.315 + IHookList *GetPostHooks();
1.316 +
1.317 + bool operator==(void *ptr)
1.318 + {
1.319 + return m_Ptr == ptr;
1.320 + }
1.321 + };
1.322 +
1.323 + class CVfnPtr : public IVfnPtr
1.324 + {
1.325 + public:
1.326 + typedef List<CIface> IfaceList;
1.327 + typedef IfaceList::iterator IfaceListIter;
1.328 +
1.329 + void *m_Ptr;
1.330 + void *m_OrigEntry;
1.331 +
1.332 + IfaceList m_Ifaces;
1.333 +
1.334 + public:
1.335 + CVfnPtr(void *ptr);
1.336 + virtual ~CVfnPtr();
1.337 +
1.338 + void *GetVfnPtr();
1.339 + void *GetOrigEntry();
1.340 +
1.341 + virtual IIface *FindIface(void *ptr);
1.342 +
1.343 + bool operator==(void *ptr)
1.344 + {
1.345 + return m_Ptr == ptr;
1.346 + }
1.347 + };
1.348 +
1.349 + class CHookManagerInfo : public IHookManagerInfo
1.350 + {
1.351 + public:
1.352 + typedef List<CVfnPtr> VfnPtrList;
1.353 + typedef VfnPtrList::iterator VfnPtrListIter;
1.354 +
1.355 + Plugin m_Plug;
1.356 + HookManagerPubFunc m_Func;
1.357 +
1.358 + int m_VtblOffs;
1.359 + int m_VtblIdx;
1.360 + const char *m_Proto;
1.361 + void *m_HookfuncVfnptr;
1.362 +
1.363 + VfnPtrList m_VfnPtrs;
1.364 +
1.365 + int m_HookManVersion;
1.366 + public:
1.367 + CHookManagerInfo();
1.368 + virtual ~CHookManagerInfo();
1.369 +
1.370 + IVfnPtr *FindVfnPtr(void *vfnptr);
1.371 +
1.372 + void SetInfo(int vtbl_offs, int vtbl_idx, const char *proto);
1.373 + void SetHookfuncVfnptr(void *hookfunc_vfnptr);
1.374 +
1.375 + void SetVersion(int version);
1.376 +
1.377 + bool operator < (const CHookManagerInfo &other)
1.378 + {
1.379 + return m_HookManVersion < other.m_HookManVersion;
1.380 + }
1.381 +
1.382 + struct Descriptor
1.383 + {
1.384 + Descriptor(Plugin pplug, HookManagerPubFunc ppubFunc) : plug(pplug), pubFunc(ppubFunc)
1.385 + {
1.386 + }
1.387 +
1.388 + Plugin plug;
1.389 + HookManagerPubFunc pubFunc;
1.390 + };
1.391 +
1.392 + bool operator == (const Descriptor desc)
1.393 + {
1.394 + return m_Func == desc.pubFunc && m_Plug == desc.plug;
1.395 + }
1.396 + };
1.397 +
1.398 + typedef List<CHookManagerInfo> HookManInfoList;
1.399 +
1.400 + class CHookManagerContainer : public HookManInfoList
1.401 + {
1.402 + public:
1.403 + // HMCI (Hook Manager Container Identification)
1.404 + class HMCI
1.405 + {
1.406 + CProto m_Proto;
1.407 + int m_VtableOffset;
1.408 + int m_VtableIndex;
1.409 + public:
1.410 + HMCI(const char *proto, int vtbloffs, int vtblidx) :
1.411 + m_Proto(proto), m_VtableOffset(vtbloffs), m_VtableIndex(vtblidx)
1.412 + {
1.413 + }
1.414 + ~HMCI()
1.415 + {
1.416 + }
1.417 +
1.418 + bool operator==(const HMCI &other) const
1.419 + {
1.420 + return
1.421 + other.m_VtableIndex == m_VtableIndex &&
1.422 + other.m_Proto == m_Proto &&
1.423 + other.m_VtableOffset == m_VtableOffset;
1.424 + }
1.425 +
1.426 + const CProto &GetProto() const
1.427 + {
1.428 + return m_Proto;
1.429 + }
1.430 + int GetVtableOffset() const
1.431 + {
1.432 + return m_VtableOffset;
1.433 + }
1.434 + int GetVtableIndex() const
1.435 + {
1.436 + return m_VtableIndex;
1.437 + }
1.438 + };
1.439 + HMCI m_HCMI;
1.440 +
1.441 + public:
1.442 + CHookManagerContainer(const HMCI &hmci) : m_HCMI(hmci)
1.443 + {
1.444 + }
1.445 + bool operator == (const HMCI &other) const
1.446 + {
1.447 + return m_HCMI == other;
1.448 + }
1.449 + void AddHookManager(Plugin plug, const CHookManagerInfo &hookman);
1.450 + };
1.451 +
1.452 + class CCallClassImpl : public GenericCallClass
1.453 + {
1.454 + public:
1.455 +
1.456 + typedef SourceHook::CVector<void*> OrigFuncs;
1.457 + typedef SourceHook::THash<int, OrigFuncs> OrigVTables;
1.458 +
1.459 + void *m_Ptr; //!< Pointer to the actual object
1.460 + size_t m_ObjSize; //!< Size of the instance
1.461 + OrigVTables m_VT; //!< Info about vtables & functions
1.462 +
1.463 + int m_RefCounter;
1.464 +
1.465 + CCallClassImpl(void *ptr, size_t size);
1.466 + virtual ~CCallClassImpl();
1.467 +
1.468 + bool operator==(void *other)
1.469 + {
1.470 + return m_Ptr == other;
1.471 + }
1.472 +
1.473 + void *GetThisPtr();
1.474 + void *GetOrigFunc(int vtbloffs, int vtblidx);
1.475 +
1.476 + void ApplyCallClassPatch(int vtbl_offs, int vtbl_idx, void *orig_entry);
1.477 + void RemoveCallClassPatch(int vtbl_offs, int vtbl_idx);
1.478 + };
1.479 +
1.480 + /**
1.481 + * @brief A list of CallClass structures
1.482 + */
1.483 + typedef List<CCallClassImpl> Impl_CallClassList;
1.484 +
1.485 + Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses
1.486 +
1.487 + /**
1.488 + * @brief A list of CHookManagerContainers
1.489 + */
1.490 + typedef List<CHookManagerContainer> HookManContList;
1.491 +
1.492 + HookManContList m_HookMans; //!< A list of hook managers
1.493 +
1.494 + struct HookLoopInfo
1.495 + {
1.496 + enum RecallType
1.497 + {
1.498 + Recall_No=0,
1.499 + Recall_Pre,
1.500 + Recall_Post1,
1.501 + Recall_Post2
1.502 + };
1.503 +
1.504 + META_RES *pStatus;
1.505 + META_RES *pPrevRes;
1.506 + META_RES *pCurRes;
1.507 +
1.508 + META_RES temporaryStatus; //!< Stored during Post1 recall phase
1.509 + bool shouldContinue;
1.510 + RecallType recall; //!< Specifies which kind of recall we're in.
1.511 +
1.512 + IIface *pCurIface;
1.513 + const void *pOrigRet;
1.514 + void *pOverrideRet;
1.515 + void **pIfacePtrPtr;
1.516 + };
1.517 + typedef CStack<HookLoopInfo> HookLoopInfoStack;
1.518 +
1.519 + void ApplyCallClassPatches(CCallClassImpl &cc);
1.520 + void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry);
1.521 + void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
1.522 +
1.523 + void SetPluginPaused(Plugin plug, bool paused);
1.524 +
1.525 + HookLoopInfoStack m_HLIStack;
1.526 + public:
1.527 + CSourceHookImpl();
1.528 + virtual ~CSourceHookImpl();
1.529 +
1.530 + /**
1.531 + * @brief Returns the interface version
1.532 + */
1.533 + int GetIfaceVersion();
1.534 +
1.535 + /**
1.536 + * @brief Returns the implemnetation version
1.537 + */
1.538 + int GetImplVersion();
1.539 +
1.540 + /**
1.541 + * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
1.542 + */
1.543 + void UnloadPlugin(Plugin plug);
1.544 +
1.545 + /**
1.546 + * @brief Shut down the whole system, unregister all hook managers
1.547 + */
1.548 + void CompleteShutdown();
1.549 +
1.550 + /**
1.551 + * @brief Add a hook.
1.552 + *
1.553 + * @return True if the function succeeded, false otherwise
1.554 + *
1.555 + * @param plug The unique identifier of the plugin that calls this function
1.556 + * @param iface The interface pointer
1.557 + * @param ifacesize The size of the class iface points to
1.558 + * @param myHookMan A hook manager function that should be capable of handling the function
1.559 + * @param handler A pointer to a FastDelegate containing the hook handler
1.560 + * @param post Set to true if you want a post handler
1.561 + */
1.562 + bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
1.563 +
1.564 + /**
1.565 + * @brief Removes a hook.
1.566 + *
1.567 + * @return True if the function succeeded, false otherwise
1.568 + *
1.569 + * @param plug The unique identifier of the plugin that calls this function
1.570 + * @param iface The interface pointer
1.571 + * @param thisptr_offs This pointer adjuster
1.572 + * @param myHookMan A hook manager function that should be capable of handling the function
1.573 + * @param handler A pointer to a FastDelegate containing the hook handler
1.574 + * @param post Set to true if you want a post handler
1.575 + */
1.576 + bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
1.577 +
1.578 + /**
1.579 + * @brief Removes a hook.
1.580 + *
1.581 + * @ return True if the function succeeded, false otherwise
1.582 + *
1.583 + * @param info A RemoveHookInfo structure, describing the hook
1.584 + */
1.585 + bool RemoveHook(RemoveHookInfo info);
1.586 +
1.587 + /**
1.588 + * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
1.589 + *
1.590 + * @param plug The unique identifier of the plugin in question
1.591 + */
1.592 + bool IsPluginInUse(Plugin plug);
1.593 +
1.594 + /**
1.595 + * @brief Pauses all hooks of a plugin
1.596 + *
1.597 + * @param plug The unique identifier of the plugin
1.598 + */
1.599 + void PausePlugin(Plugin plug);
1.600 +
1.601 + /**
1.602 + * @brief Unpauses all hooks of a plugin
1.603 + *
1.604 + * @param plug The unique identifier of the plugin
1.605 + */
1.606 + void UnpausePlugin(Plugin plug);
1.607 +
1.608 + /**
1.609 + * @brief Return a pointer to a callclass. Generate a new one if required.
1.610 + *
1.611 + * @param iface The interface pointer
1.612 + * @param size Size of the class instance
1.613 + */
1.614 + GenericCallClass *GetCallClass(void *iface, size_t size);
1.615 +
1.616 + /**
1.617 + * @brief Release a callclass
1.618 + *
1.619 + * @param ptr Pointer to the callclass
1.620 + */
1.621 + virtual void ReleaseCallClass(GenericCallClass *ptr);
1.622 +
1.623 + virtual void SetRes(META_RES res); //!< Sets the meta result
1.624 + virtual META_RES GetPrevRes(); //!< Gets the meta result of the previously called handler
1.625 + virtual META_RES GetStatus(); //!< Gets the highest meta result
1.626 + virtual const void *GetOrigRet(); //!< Gets the original result. If not in post function, undefined
1.627 + virtual const void *GetOverrideRet(); //!< Gets the override result. If none is specified, NULL
1.628 + virtual void *GetIfacePtr(); //!< Gets the interface pointer
1.629 +
1.630 + //////////////////////////////////////////////////////////////////////////
1.631 + // For hook managers
1.632 + void HookLoopBegin(IIface *pIface); //!< Should be called when a hook loop begins
1.633 + void HookLoopEnd(); //!< Should be called when a hook loop exits
1.634 + void SetCurResPtr(META_RES *mres); //!< Sets pointer to the current meta result
1.635 + void SetPrevResPtr(META_RES *mres); //!< Sets pointer to previous meta result
1.636 + void SetStatusPtr(META_RES *mres); //!< Sets pointer to the status variable
1.637 + void SetIfacePtrPtr(void **pp); //!< Sets pointer to the interface this pointer
1.638 + void SetOrigRetPtr(const void *ptr); //!< Sets the original return pointer
1.639 + void SetOverrideRetPtr(void *ptr); //!< Sets the override result pointer
1.640 + bool ShouldContinue(); //!< Returns false if the hook loop should exit
1.641 +
1.642 + /**
1.643 + * @brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
1.644 + *
1.645 + * @param plug The owner of the hook manager
1.646 + * @param pubFunc The hook manager's info function
1.647 + */
1.648 + virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
1.649 + virtual void RemoveHookManager(RemoveHookManInfo info);
1.650 +
1.651 + virtual void DoRecall(); //!< Initiates a recall sequence
1.652 + virtual void *GetOverrideRetPtr(); //!< Returns the pointer set by SetOverrideRetPtr
1.653 +
1.654 + virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
1.655 + void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr);
1.656 + };
1.657 +}
1.658 +
1.659 +#endif