One last oops. I really need to install Linux again SOON :(
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 * ============================
11 #ifndef __SOURCEHOOK_IMPL_H__
12 #define __SOURCEHOOK_IMPL_H__
14 #include "sourcehook.h"
21 // Set this to 1 to enable runtime code generation (faster)
22 #define SH_RUNTIME_CODEGEN 1
27 * @brief The SourceHook implementation class
29 class CSourceHookImpl : public ISourceHook
32 * @brief A hook can be removed if you have this information
36 RemoveHookInfo(Plugin pplug, void *piface, int tpo, HookManagerPubFunc phookman,
37 ISHDelegate *phandler, bool ppost)
38 : plug(pplug), iface(piface), thisptr_offs(tpo),
39 hookman(phookman), handler(phandler), post(ppost)
46 HookManagerPubFunc hookman;
52 * @brief A list of HookManagerInfo structures
54 typedef std::list<HookManagerInfo> HookManInfoList;
60 bool operator==(void *other)
62 return cc.ptr == other;
66 * @brief A list of CallClass structures
68 typedef std::list<CallClassInfo> Impl_CallClassList;
70 Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses
71 HookManInfoList m_HookMans; //!< A list of hook managers
74 * @brief Finds a hook manager for a function based on a text-prototype, a vtable offset and a vtable index
76 HookManInfoList::iterator FindHookMan(HookManInfoList::iterator begin, HookManInfoList::iterator end,
77 const char *proto, int vtblofs, int vtblidx);
79 void ApplyCallClassPatch(CallClassInfo &cc, int vtbl_offs, int vtbl_idx, void *orig_entry);
80 void ApplyCallClassPatches(CallClassInfo &cc);
81 void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry);
82 void RemoveCallClassPatch(CallClassInfo &cc, int vtbl_offs, int vtbl_idx);
83 void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
87 * @brief Checks to see if a memory value can be read from a given pointer.
89 * @return True if the value can be read and false if it cannot.
91 * @param ptr The pointer to the memory value.
92 * @param len The length of the memory value to be read from the pointer.
94 static bool IsBadReadPtr(const void *ptr, size_t len);
95 static void BadReadHandler(int sig);
98 jmp_buf m_BadReadJmpBuf;
101 META_RES m_Status, m_PrevRes, m_CurRes;
102 const void *m_OrigRet;
103 const void *m_OverrideRet;
110 * @brief Returns the interface version
112 int GetIfaceVersion();
115 * @brief Returns the implemnetation version
117 int GetImplVersion();
120 * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
122 void UnloadPlugin(Plugin plug);
125 * @brief Shut down the whole system, unregister all hook managers
127 void CompleteShutdown();
132 * @return True if the function succeeded, false otherwise
134 * @param plug The unique identifier of the plugin that calls this function
135 * @param iface The interface pointer
136 * @param ifacesize The size of the class iface points to
137 * @param myHookMan A hook manager function that should be capable of handling the function
138 * @param handler A pointer to a FastDelegate containing the hook handler
139 * @param post Set to true if you want a post handler
141 bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
144 * @brief Removes a hook.
146 * @return True if the function succeeded, false otherwise
148 * @param plug The unique identifier of the plugin that calls this function
149 * @param iface The interface pointer
150 * @param thisptr_offs This pointer adjuster
151 * @param myHookMan A hook manager function that should be capable of handling the function
152 * @param handler A pointer to a FastDelegate containing the hook handler
153 * @param post Set to true if you want a post handler
155 bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
158 * @brief Removes a hook.
160 * @ return True if the function succeeded, false otherwise
162 * @param info A RemoveHookInfo structure, describing the hook
164 bool RemoveHook(RemoveHookInfo info);
167 * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
169 * @param plug The unique identifier of the plugin in question
171 bool IsPluginInUse(Plugin plug);
174 * @brief Pauses all hooks of a plugin
176 * @param plug The unique identifier of the plugin
178 void PausePlugin(Plugin plug);
181 * @brief Unpauses all hooks of a plugin
183 * @param plug The unique identifier of the plugin
185 void UnpausePlugin(Plugin plug);
188 * @brief Return a pointer to a callclass. Generate a new one if required.
190 * @param iface The interface pointer
191 * @param size Size of the class instance
193 GenericCallClass *GetCallClass(void *iface, size_t size);
196 * @brief Release a callclass
198 * @param ptr Pointer to the callclass
200 virtual void ReleaseCallClass(GenericCallClass *ptr);
202 virtual void SetRes(META_RES res); //!< Sets the meta result
203 virtual META_RES GetPrevRes(); //!< Gets the meta result of the previously called handler
204 virtual META_RES GetStatus(); //!< Gets the highest meta result
205 virtual const void *GetOrigRet(); //!< Gets the original result. If not in post function, undefined
206 virtual const void *GetOverrideRet(); //!< Gets the override result. If none is specified, NULL
207 virtual void *GetIfacePtr(); //!< Gets the interface pointer
209 //////////////////////////////////////////////////////////////////////////
211 virtual META_RES &GetCurResRef(); //!< Gets the reference to the current meta result
212 virtual META_RES &GetPrevResRef(); //!< Gets the reference to the previous meta result
213 virtual META_RES &GetStatusRef(); //!< Gets the reference to the status variable
214 virtual void* &GetIfacePtrRef(); //!< Gets the reference to the iface ptr
215 virtual void SetOrigRet(const void *ptr); //!< Sets the original return pointer
216 virtual void SetOverrideRet(const void *ptr); //!< Sets the override result pointer