1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core-legacy/sourcehook/sourcehook_impl.h Fri Nov 14 05:02:00 2008 -0600
1.3 @@ -0,0 +1,659 @@
1.4 +/* ======== SourceHook ========
1.5 +* Copyright (C) 2004-2008 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 GoToEnd();
1.264 + void Set(CIter *pOther);
1.265 +
1.266 + bool End();
1.267 + void Next();
1.268 + ISHDelegate *Handler();
1.269 + int ThisPtrOffs();
1.270 +
1.271 + void Clear();
1.272 +
1.273 + CIter *m_pNext; // When stored in m_FreeIters and m_UsedIters
1.274 + CIter *m_pPrev; // Only used when stored in m_UsedIters
1.275 + };
1.276 +
1.277 + CIter *m_FreeIters;
1.278 + CIter *m_UsedIters; // The last returned and not-yet-released iter is always m_UsedIters
1.279 +
1.280 + // For recalls
1.281 + bool m_Recall;
1.282 + bool m_RQFlag;
1.283 + bool m_RelFlag;
1.284 +
1.285 + void SetRecallState(); // Sets the list into a state where the next returned
1.286 + // iterator (from GetIter) will be a copy of the last
1.287 + // returned iterator, incremented by one. This is used in Recalls.
1.288 + // The hook resets this state automatically on:
1.289 + // GetIter, ReleaseIter
1.290 +
1.291 + void RQFlagReset() { m_RQFlag = false; m_RelFlag = false; }
1.292 + bool RQFlagGet() { return m_RQFlag; }
1.293 + bool RelFlagGet() { return m_RelFlag; }
1.294 + CHookList();
1.295 + CHookList(const CHookList &other);
1.296 + virtual ~CHookList();
1.297 +
1.298 + void operator=(const CHookList &other);
1.299 +
1.300 + IIter *GetIter();
1.301 + void ReleaseIter(IIter *pIter);
1.302 + };
1.303 +
1.304 + // I know, data hiding... But I'm a lazy bastard!
1.305 +
1.306 + class CIface : public IIface
1.307 + {
1.308 + public:
1.309 + void *m_Ptr;
1.310 + CHookList m_PreHooks;
1.311 + CHookList m_PostHooks;
1.312 + public:
1.313 + CIface(void *ptr);
1.314 + virtual ~CIface();
1.315 +
1.316 + void *GetPtr();
1.317 + IHookList *GetPreHooks();
1.318 + IHookList *GetPostHooks();
1.319 +
1.320 + bool operator==(void *ptr)
1.321 + {
1.322 + return m_Ptr == ptr;
1.323 + }
1.324 + };
1.325 +
1.326 + class CVfnPtr : public IVfnPtr
1.327 + {
1.328 + public:
1.329 + typedef List<CIface> IfaceList;
1.330 + typedef IfaceList::iterator IfaceListIter;
1.331 +
1.332 + void *m_Ptr;
1.333 + void *m_OrigEntry;
1.334 +
1.335 + IfaceList m_Ifaces;
1.336 +
1.337 + public:
1.338 + CVfnPtr(void *ptr);
1.339 + virtual ~CVfnPtr();
1.340 +
1.341 + void *GetVfnPtr();
1.342 + void *GetOrigEntry();
1.343 +
1.344 + virtual IIface *FindIface(void *ptr);
1.345 +
1.346 + bool operator==(void *ptr)
1.347 + {
1.348 + return m_Ptr == ptr;
1.349 + }
1.350 + };
1.351 +
1.352 + class CHookManagerInfo : public IHookManagerInfo
1.353 + {
1.354 + public:
1.355 + typedef List<CVfnPtr> VfnPtrList;
1.356 + typedef VfnPtrList::iterator VfnPtrListIter;
1.357 +
1.358 + Plugin m_Plug;
1.359 + HookManagerPubFunc m_Func;
1.360 +
1.361 + int m_VtblOffs;
1.362 + int m_VtblIdx;
1.363 + const char *m_Proto;
1.364 + void *m_HookfuncVfnptr;
1.365 +
1.366 + VfnPtrList m_VfnPtrs;
1.367 +
1.368 + int m_HookManVersion;
1.369 + public:
1.370 + CHookManagerInfo();
1.371 + virtual ~CHookManagerInfo();
1.372 +
1.373 + IVfnPtr *FindVfnPtr(void *vfnptr);
1.374 +
1.375 + void SetInfo(int vtbl_offs, int vtbl_idx, const char *proto);
1.376 + void SetHookfuncVfnptr(void *hookfunc_vfnptr);
1.377 +
1.378 + void SetVersion(int version);
1.379 +
1.380 + bool operator < (const CHookManagerInfo &other)
1.381 + {
1.382 + return m_HookManVersion < other.m_HookManVersion;
1.383 + }
1.384 +
1.385 + struct Descriptor
1.386 + {
1.387 + Descriptor(Plugin pplug, HookManagerPubFunc ppubFunc) : plug(pplug), pubFunc(ppubFunc)
1.388 + {
1.389 + }
1.390 +
1.391 + Plugin plug;
1.392 + HookManagerPubFunc pubFunc;
1.393 + };
1.394 +
1.395 + bool operator == (const Descriptor desc)
1.396 + {
1.397 + return m_Func == desc.pubFunc && m_Plug == desc.plug;
1.398 + }
1.399 + };
1.400 +
1.401 + typedef List<CHookManagerInfo> HookManInfoList;
1.402 +
1.403 + class CHookManagerContainer : public HookManInfoList
1.404 + {
1.405 + public:
1.406 + // HMCI (Hook Manager Container Identification)
1.407 + class HMCI
1.408 + {
1.409 + CProto m_Proto;
1.410 + int m_VtableOffset;
1.411 + int m_VtableIndex;
1.412 + public:
1.413 + HMCI(const char *proto, int vtbloffs, int vtblidx) :
1.414 + m_Proto(proto), m_VtableOffset(vtbloffs), m_VtableIndex(vtblidx)
1.415 + {
1.416 + }
1.417 + ~HMCI()
1.418 + {
1.419 + }
1.420 +
1.421 + bool operator==(const HMCI &other) const
1.422 + {
1.423 + return
1.424 + other.m_VtableIndex == m_VtableIndex &&
1.425 + other.m_Proto == m_Proto &&
1.426 + other.m_VtableOffset == m_VtableOffset;
1.427 + }
1.428 +
1.429 + const CProto &GetProto() const
1.430 + {
1.431 + return m_Proto;
1.432 + }
1.433 + int GetVtableOffset() const
1.434 + {
1.435 + return m_VtableOffset;
1.436 + }
1.437 + int GetVtableIndex() const
1.438 + {
1.439 + return m_VtableIndex;
1.440 + }
1.441 + };
1.442 + HMCI m_HCMI;
1.443 +
1.444 + public:
1.445 + CHookManagerContainer(const HMCI &hmci) : m_HCMI(hmci)
1.446 + {
1.447 + }
1.448 + bool operator == (const HMCI &other) const
1.449 + {
1.450 + return m_HCMI == other;
1.451 + }
1.452 + void AddHookManager(Plugin plug, const CHookManagerInfo &hookman);
1.453 + };
1.454 +
1.455 + class CCallClassImpl : public GenericCallClass
1.456 + {
1.457 + public:
1.458 +
1.459 + typedef SourceHook::CVector<void*> OrigFuncs;
1.460 + typedef SourceHook::THash<int, OrigFuncs> OrigVTables;
1.461 +
1.462 + void *m_Ptr; //!< Pointer to the actual object
1.463 + size_t m_ObjSize; //!< Size of the instance
1.464 + OrigVTables m_VT; //!< Info about vtables & functions
1.465 +
1.466 + int m_RefCounter;
1.467 +
1.468 + CCallClassImpl(void *ptr, size_t size);
1.469 + virtual ~CCallClassImpl();
1.470 +
1.471 + bool operator==(void *other)
1.472 + {
1.473 + return m_Ptr == other;
1.474 + }
1.475 +
1.476 + void *GetThisPtr();
1.477 + void *GetOrigFunc(int vtbloffs, int vtblidx);
1.478 +
1.479 + void ApplyCallClassPatch(int vtbl_offs, int vtbl_idx, void *orig_entry);
1.480 + void RemoveCallClassPatch(int vtbl_offs, int vtbl_idx);
1.481 + };
1.482 +
1.483 + /**
1.484 + * @brief A list of CallClass structures
1.485 + */
1.486 + typedef List<CCallClassImpl> Impl_CallClassList;
1.487 +
1.488 + Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses
1.489 +
1.490 + /**
1.491 + * @brief A list of CHookManagerContainers
1.492 + */
1.493 + typedef List<CHookManagerContainer> HookManContList;
1.494 +
1.495 + HookManContList m_HookMans; //!< A list of hook managers
1.496 +
1.497 + struct HookLoopInfo
1.498 + {
1.499 + enum RecallType
1.500 + {
1.501 + Recall_No=0,
1.502 + Recall_Pre,
1.503 + Recall_Post1,
1.504 + Recall_Post2
1.505 + };
1.506 +
1.507 + META_RES *pStatus;
1.508 + META_RES *pPrevRes;
1.509 + META_RES *pCurRes;
1.510 +
1.511 + META_RES temporaryStatus; //!< Stored during Post1 recall phase
1.512 + bool shouldContinue;
1.513 + RecallType recall; //!< Specifies which kind of recall we're in.
1.514 +
1.515 + IIface *pCurIface;
1.516 + const void *pOrigRet;
1.517 + void *pOverrideRet;
1.518 + void **pIfacePtrPtr;
1.519 + };
1.520 + typedef CStack<HookLoopInfo> HookLoopInfoStack;
1.521 +
1.522 + void ApplyCallClassPatches(CCallClassImpl &cc);
1.523 + void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry);
1.524 + void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
1.525 +
1.526 + void SetPluginPaused(Plugin plug, bool paused);
1.527 +
1.528 + HookLoopInfoStack m_HLIStack;
1.529 + public:
1.530 + CSourceHookImpl();
1.531 + virtual ~CSourceHookImpl();
1.532 +
1.533 + /**
1.534 + * @brief Returns the interface version
1.535 + */
1.536 + int GetIfaceVersion();
1.537 +
1.538 + /**
1.539 + * @brief Returns the implemnetation version
1.540 + */
1.541 + int GetImplVersion();
1.542 +
1.543 + /**
1.544 + * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
1.545 + */
1.546 + void UnloadPlugin(Plugin plug);
1.547 +
1.548 + /**
1.549 + * @brief Shut down the whole system, unregister all hook managers
1.550 + */
1.551 + void CompleteShutdown();
1.552 +
1.553 + /**
1.554 + * @brief Add a hook.
1.555 + *
1.556 + * @return True if the function succeeded, false otherwise
1.557 + *
1.558 + * @param plug The unique identifier of the plugin that calls this function
1.559 + * @param iface The interface pointer
1.560 + * @param ifacesize The size of the class iface points to
1.561 + * @param myHookMan A hook manager function that should be capable of handling the function
1.562 + * @param handler A pointer to a FastDelegate containing the hook handler
1.563 + * @param post Set to true if you want a post handler
1.564 + */
1.565 + bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
1.566 +
1.567 + /**
1.568 + * @brief Removes a hook.
1.569 + *
1.570 + * @return True if the function succeeded, false otherwise
1.571 + *
1.572 + * @param plug The unique identifier of the plugin that calls this function
1.573 + * @param iface The interface pointer
1.574 + * @param thisptr_offs This pointer adjuster
1.575 + * @param myHookMan A hook manager function that should be capable of handling the function
1.576 + * @param handler A pointer to a FastDelegate containing the hook handler
1.577 + * @param post Set to true if you want a post handler
1.578 + */
1.579 + bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
1.580 +
1.581 + /**
1.582 + * @brief Removes a hook.
1.583 + *
1.584 + * @ return True if the function succeeded, false otherwise
1.585 + *
1.586 + * @param info A RemoveHookInfo structure, describing the hook
1.587 + */
1.588 + bool RemoveHook(RemoveHookInfo info);
1.589 +
1.590 + /**
1.591 + * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
1.592 + *
1.593 + * @param plug The unique identifier of the plugin in question
1.594 + */
1.595 + bool IsPluginInUse(Plugin plug);
1.596 +
1.597 + /**
1.598 + * @brief Pauses all hooks of a plugin
1.599 + *
1.600 + * @param plug The unique identifier of the plugin
1.601 + */
1.602 + void PausePlugin(Plugin plug);
1.603 +
1.604 + /**
1.605 + * @brief Unpauses all hooks of a plugin
1.606 + *
1.607 + * @param plug The unique identifier of the plugin
1.608 + */
1.609 + void UnpausePlugin(Plugin plug);
1.610 +
1.611 + /**
1.612 + * @brief Return a pointer to a callclass. Generate a new one if required.
1.613 + *
1.614 + * @param iface The interface pointer
1.615 + * @param size Size of the class instance
1.616 + */
1.617 + GenericCallClass *GetCallClass(void *iface, size_t size);
1.618 +
1.619 + /**
1.620 + * @brief Release a callclass
1.621 + *
1.622 + * @param ptr Pointer to the callclass
1.623 + */
1.624 + virtual void ReleaseCallClass(GenericCallClass *ptr);
1.625 +
1.626 + virtual void SetRes(META_RES res); //!< Sets the meta result
1.627 + virtual META_RES GetPrevRes(); //!< Gets the meta result of the previously called handler
1.628 + virtual META_RES GetStatus(); //!< Gets the highest meta result
1.629 + virtual const void *GetOrigRet(); //!< Gets the original result. If not in post function, undefined
1.630 + virtual const void *GetOverrideRet(); //!< Gets the override result. If none is specified, NULL
1.631 + virtual void *GetIfacePtr(); //!< Gets the interface pointer
1.632 +
1.633 + //////////////////////////////////////////////////////////////////////////
1.634 + // For hook managers
1.635 + void HookLoopBegin(IIface *pIface); //!< Should be called when a hook loop begins
1.636 + void HookLoopEnd(); //!< Should be called when a hook loop exits
1.637 + void SetCurResPtr(META_RES *mres); //!< Sets pointer to the current meta result
1.638 + void SetPrevResPtr(META_RES *mres); //!< Sets pointer to previous meta result
1.639 + void SetStatusPtr(META_RES *mres); //!< Sets pointer to the status variable
1.640 + void SetIfacePtrPtr(void **pp); //!< Sets pointer to the interface this pointer
1.641 + void SetOrigRetPtr(const void *ptr); //!< Sets the original return pointer
1.642 + void SetOverrideRetPtr(void *ptr); //!< Sets the override result pointer
1.643 + bool ShouldContinue(); //!< Returns false if the hook loop should exit
1.644 +
1.645 + /**
1.646 + * @brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
1.647 + *
1.648 + * @param plug The owner of the hook manager
1.649 + * @param pubFunc The hook manager's info function
1.650 + */
1.651 + virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
1.652 + virtual void RemoveHookManager(RemoveHookManInfo info);
1.653 +
1.654 + virtual void DoRecall(); //!< Initiates a recall sequence
1.655 + virtual void *GetOverrideRetPtr(); //!< Returns the pointer set by SetOverrideRetPtr
1.656 +
1.657 + virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
1.658 + void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr);
1.659 + };
1.660 +}
1.661 +
1.662 +#endif