sourcehook/sourcehook_impl.h
changeset 380 f9e21a2ac558
parent 333 3813f1ac0cfe
child 386 08583103ba6f
     1.1 --- a/sourcehook/sourcehook_impl.h	Sun Oct 07 03:12:19 2007 +0000
     1.2 +++ b/sourcehook/sourcehook_impl.h	Sun Oct 07 22:10:07 2007 +0000
     1.3 @@ -23,6 +23,8 @@
     1.4  IMPLEMENTATION INFO
     1.5  
     1.6  ---------------------------------------
     1.7 + :TODO: update ???
     1.8 +
     1.9  Protos ("Prototypes")
    1.10  	The purpose of protos is to provide the amount of type information about a function
    1.11  	which is required to be able to execute a function call without corrupting the stack.
    1.12 @@ -170,648 +172,168 @@
    1.13  	the original function. Everything works fine. This works even for VP hooks.
    1.14  */
    1.15  
    1.16 +#include "sourcehook_impl_cproto.h"
    1.17 +#include "sourcehook_impl_chook.h"
    1.18 +#include "sourcehook_impl_ciface.h"
    1.19 +#include "sourcehook_impl_cvfnptr.h"
    1.20 +#include "sourcehook_impl_chookmaninfo.h"
    1.21 +#include "sourcehook_impl_chookmancont.h"
    1.22 +#include "sourcehook_impl_chookidman.h"
    1.23 +
    1.24  namespace SourceHook
    1.25  {
    1.26  	/**
    1.27 -	*	@brief The SourceHook implementation class
    1.28 +	*	@brief The SourceHook implementation
    1.29  	*/
    1.30 -	class CSourceHookImpl : public ISourceHook
    1.31 -	{
    1.32 -	private:
    1.33 -		class CProto
    1.34 -		{
    1.35 -			char *m_Proto;
    1.36 -
    1.37 -			static bool Equal(const char *p1, const char *p2);
    1.38 -			char *DupProto(const char *src);
    1.39 -			void FreeProto(char *prot);
    1.40 -		public:
    1.41 -			CProto() : m_Proto(NULL)
    1.42 -			{
    1.43 -			}
    1.44 -
    1.45 -			CProto(const char *szProto) : m_Proto(DupProto(szProto))
    1.46 -			{
    1.47 -			}
    1.48 -
    1.49 -			CProto(const CProto &other) : m_Proto(DupProto(other.m_Proto))
    1.50 -			{
    1.51 -			}
    1.52 -
    1.53 -			~CProto()
    1.54 -			{
    1.55 -				FreeProto(m_Proto);
    1.56 -				m_Proto = NULL;
    1.57 -			}
    1.58 -
    1.59 -			void operator = (const char *szProto)
    1.60 -			{
    1.61 -				m_Proto = DupProto(szProto);
    1.62 -			}
    1.63 -
    1.64 -			void operator = (const CProto &other)
    1.65 -			{
    1.66 -				m_Proto = DupProto(other.m_Proto);
    1.67 -			}
    1.68  
    1.69 -			bool operator == (const char *szProto) const
    1.70 -			{
    1.71 -				return Equal(szProto, m_Proto);
    1.72 -			}
    1.73 -			bool operator == (const CProto &other) const
    1.74 -			{
    1.75 -				return Equal(other.m_Proto, m_Proto);
    1.76 -			}
    1.77 -
    1.78 -			const char *GetProto() const
    1.79 -			{
    1.80 -				return m_Proto;
    1.81 -			}
    1.82 -		};
    1.83 -
    1.84 +	namespace Impl
    1.85 +	{
    1.86  
    1.87 -		/**
    1.88 -		*	@brief A hook can be removed if you have this information
    1.89 -		*/
    1.90 -		struct RemoveHookInfo
    1.91 -		{
    1.92 -			RemoveHookInfo(Plugin pplug, void *piface, int tpo, HookManagerPubFunc phookman,
    1.93 -				ISHDelegate *phandler, bool ppost)
    1.94 -				: plug(pplug), iface(piface), thisptr_offs(tpo),
    1.95 -				hookman(phookman), handler(phandler), post(ppost)
    1.96 -			{
    1.97 -			}
    1.98 -
    1.99 -			Plugin plug;
   1.100 -			void *iface;
   1.101 -			int thisptr_offs;
   1.102 -			HookManagerPubFunc hookman;
   1.103 -			ISHDelegate *handler;
   1.104 -			bool post;
   1.105 -		};
   1.106 -
   1.107 -		struct RemoveHookManInfo
   1.108 -		{
   1.109 -			RemoveHookManInfo(Plugin pplug, HookManagerPubFunc phookman)
   1.110 -				: plug(pplug), hookman(phookman)
   1.111 -			{
   1.112 -			}
   1.113 -
   1.114 -			Plugin plug;
   1.115 -			HookManagerPubFunc hookman;
   1.116 -		};
   1.117 -
   1.118 -		// Associates hook ids with info about the hooks
   1.119 -		// Also used to keep track of used hook ids
   1.120 -		class CHookIDManager
   1.121 +		class CHookManContainerList : public List<CHookManagerContainer>
   1.122  		{
   1.123  		public:
   1.124 -			struct Entry
   1.125 -			{
   1.126 -				bool isfree;
   1.127 -
   1.128 -				// hookman info
   1.129 -				CProto proto;
   1.130 -				int vtbl_offs;
   1.131 -				int vtbl_idx;
   1.132 -
   1.133 -				// vfnptr
   1.134 -				void *vfnptr;
   1.135 -
   1.136 -				// iface
   1.137 -				void* adjustediface;
   1.138 -
   1.139 -				// hook
   1.140 -				Plugin plug;
   1.141 -				int thisptr_offs;
   1.142 -				ISHDelegate *handler;
   1.143 -				bool post;
   1.144 -
   1.145 -				Entry(const CProto &pprt, int pvo, int pvi, void *pvp, void *pai, Plugin pplug, int pto,
   1.146 -					ISHDelegate *ph, bool ppost)
   1.147 -					: isfree(false), proto(pprt), vtbl_offs(pvo), vtbl_idx(pvi), vfnptr(pvp), 
   1.148 -					adjustediface(pai), plug(pplug), thisptr_offs(pto), handler(ph), post(ppost)
   1.149 -				{
   1.150 -				}
   1.151 -				Entry()
   1.152 -				{
   1.153 -				}
   1.154 -			};
   1.155 -		private:
   1.156 -			// Internally, hookid 1 is stored as m_Entries[0]
   1.157 -
   1.158 -			CVector<Entry> m_Entries;
   1.159 -		public:
   1.160 -			CHookIDManager();
   1.161 -			int New(const CProto &proto, int vtbl_offs, int vtbl_idx, void *vfnptr, void *adjustediface,
   1.162 -				Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post);
   1.163 -			bool Remove(int hookid);
   1.164 -			const Entry * QueryHook(int hookid);
   1.165 -
   1.166 -			// Finds all hooks with the given info, and fills the hookids into output.
   1.167 -			void FindAllHooks(CVector<int> &output, const CProto &proto, int vtbl_offs, int vtbl_idx,
   1.168 -				void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post);
   1.169 -
   1.170 -			// Removes all hooks with a specified vfnptr
   1.171 -			bool RemoveAll(void *vfnptr);
   1.172 +			CHookManagerContainer &GetContainer(int vtbloffs, int vtblidx, const CProto &proto);
   1.173 +			void RemoveHookMans(Plugin plug);
   1.174 +			void RemoveHookMans(Plugin plug, HookManagerPubFunc pubFunc);
   1.175  		};
   1.176  
   1.177 -		struct HookInfo
   1.178 +		struct CHookContext : IHookContext
   1.179  		{
   1.180 -			ISHDelegate *handler;			//!< Pointer to the handler
   1.181 -			bool paused;					//!< If true, the hook should not be executed
   1.182 -			Plugin plug;					//!< The owner plugin
   1.183 -			int thisptr_offs;				//!< This pointer offset
   1.184 -			int hookid;						//!< Unique ID given by CHookIDManager
   1.185 -
   1.186 -			bool operator==(int otherid)
   1.187 -			{
   1.188 -				return hookid == otherid;
   1.189 -			}
   1.190 -		};
   1.191 -
   1.192 -		class CHookList : public IHookList
   1.193 -		{
   1.194 -		public:
   1.195 -			List<HookInfo> *m_VPList;			// left-hand list for ListCatIterator -> for VP hooks
   1.196 -			List<HookInfo> m_List;
   1.197 -
   1.198 -			friend class CIter;
   1.199 -
   1.200 -			class CIter : public IHookList::IIter
   1.201 +			enum State
   1.202  			{
   1.203 -				friend class CHookList;
   1.204 -
   1.205 -				CHookList *m_pList;
   1.206 -
   1.207 -				void SkipPaused();
   1.208 -			public:
   1.209 -
   1.210 -				ListCatIterator<HookInfo> m_Iter;
   1.211 -
   1.212 -				CIter(CHookList *pList);
   1.213 -
   1.214 -				virtual ~CIter();
   1.215 +				State_Born,
   1.216 +				State_Pre,
   1.217 +				State_PreVP,
   1.218 +				State_Post,
   1.219 +				State_PostVP,
   1.220 +				State_OrigCall,
   1.221 +				State_Dead,
   1.222  
   1.223 -				void GoToBegin();
   1.224 -				void Set(CIter *pOther);
   1.225 -
   1.226 -				bool End();
   1.227 -				void Next();
   1.228 -				ISHDelegate *Handler();
   1.229 -				int ThisPtrOffs();
   1.230 -
   1.231 -				void Clear();
   1.232 -
   1.233 -				CIter *m_pNext;		// When stored in m_FreeIters and m_UsedIters
   1.234 -				CIter *m_pPrev;		// Only used when stored in m_UsedIters
   1.235 +				// Special
   1.236 +				State_Ignore,
   1.237 +				State_Recall_Pre,
   1.238 +				State_Recall_PreVP,
   1.239 +				State_Recall_Post,
   1.240 +				State_Recall_PostVP
   1.241  			};
   1.242  
   1.243 -			CIter *m_FreeIters;
   1.244 -			CIter *m_UsedIters;		// The last returned and not-yet-released iter is always m_UsedIters
   1.245 -
   1.246 -			// For recalls
   1.247 -			bool m_Recall;
   1.248 -			bool m_RQFlag;
   1.249 -
   1.250 -			void SetRecallState();	// Sets the list into a state where the next returned
   1.251 -									// iterator (from GetIter) will be a copy of the last
   1.252 -									// returned iterator, incremented by one. This is used in Recalls.
   1.253 -									// The hook resets this state automatically on:
   1.254 -									// GetIter, ReleaseIter
   1.255 -
   1.256 -			void RQFlagReset() { m_RQFlag = false; }
   1.257 -			bool RQFlagGet() { return m_RQFlag; }
   1.258 -			CHookList();
   1.259 -			CHookList(const CHookList &other);
   1.260 -			virtual ~CHookList();
   1.261 -
   1.262 -			void operator=(const CHookList &other);
   1.263 -
   1.264 -			IIter *GetIter();
   1.265 -			void ReleaseIter(IIter *pIter);
   1.266 -
   1.267 -			void SetVPList(List<HookInfo> *newList);
   1.268 -			void ClearVPList();
   1.269 -		};
   1.270 -
   1.271 -		// I know, data hiding... But I'm a lazy bastard!
   1.272 -
   1.273 -		class CIface : public IIface
   1.274 -		{
   1.275 -		public:
   1.276 -			void *m_Ptr;
   1.277 -			CHookList m_PreHooks;
   1.278 -			CHookList m_PostHooks;
   1.279 -		public:
   1.280 -			CIface(void *ptr);
   1.281 -			virtual ~CIface();
   1.282 -
   1.283 -			void *GetPtr();
   1.284 -			IHookList *GetPreHooks();
   1.285 -			IHookList *GetPostHooks();
   1.286 -
   1.287 -			bool operator==(void *ptr)
   1.288 -			{
   1.289 -				return m_Ptr == ptr;
   1.290 -			}
   1.291 -			bool operator!=(void *ptr)
   1.292 -			{
   1.293 -				return m_Ptr != ptr;
   1.294 -			}
   1.295 -		};
   1.296 -
   1.297 -		class CVfnPtr : public IVfnPtr
   1.298 -		{
   1.299 -		public:
   1.300 -			typedef List<CIface> IfaceList;
   1.301 -			typedef IfaceList::iterator IfaceListIter;
   1.302 -
   1.303 -			void *m_Ptr;
   1.304 -			void *m_OrigEntry;
   1.305 -
   1.306 -			IfaceList m_Ifaces;
   1.307 -
   1.308 -			void **m_pOneIgnore;
   1.309 -		public:
   1.310 -			CVfnPtr(void *ptr, void **pOneIgnore);
   1.311 -			virtual ~CVfnPtr();
   1.312 -
   1.313 -			void *GetVfnPtr();
   1.314 -			void *GetOrigEntry();
   1.315 -
   1.316 -			virtual IIface *FindIface(void *ptr);
   1.317 -
   1.318 -			bool operator==(void *ptr)
   1.319 -			{
   1.320 -				return m_Ptr == ptr;
   1.321 -			}
   1.322 -		};
   1.323 -
   1.324 -		class CHookManagerInfo : public IHookManagerInfo
   1.325 -		{
   1.326 -		public:
   1.327 -			typedef List<CVfnPtr> VfnPtrList;
   1.328 -			typedef VfnPtrList::iterator VfnPtrListIter;
   1.329 -
   1.330 -			Plugin m_Plug;
   1.331 -			HookManagerPubFunc m_Func;
   1.332 -
   1.333 -			int m_VtblOffs;
   1.334 -			int m_VtblIdx;
   1.335 -			const char *m_Proto;
   1.336 -			void *m_HookfuncVfnptr;
   1.337 -
   1.338 -			VfnPtrList m_VfnPtrs;
   1.339 -
   1.340 -			int m_HookManVersion;
   1.341 -		public:
   1.342 -			CHookManagerInfo();
   1.343 -			virtual ~CHookManagerInfo();
   1.344 -
   1.345 -			IVfnPtr *FindVfnPtr(void *vfnptr);
   1.346 -
   1.347 -			void SetInfo(int vtbl_offs, int vtbl_idx, const char *proto);
   1.348 -			void SetHookfuncVfnptr(void *hookfunc_vfnptr);
   1.349 -
   1.350 -			void SetVersion(int version);
   1.351 -
   1.352 -			bool operator < (const CHookManagerInfo &other)
   1.353 -			{
   1.354 -				return m_HookManVersion < other.m_HookManVersion;
   1.355 -			}
   1.356 +			int m_State;
   1.357 +			List<CHook>::iterator m_Iter;
   1.358  
   1.359 -			struct Descriptor
   1.360 -			{
   1.361 -				Descriptor(Plugin pplug, HookManagerPubFunc ppubFunc) : plug(pplug), pubFunc(ppubFunc)
   1.362 -				{
   1.363 -				}
   1.364 -
   1.365 -				Plugin plug;
   1.366 -				HookManagerPubFunc pubFunc;
   1.367 -			};
   1.368 -
   1.369 -			bool operator == (const Descriptor desc)
   1.370 -			{
   1.371 -				return m_Func == desc.pubFunc && m_Plug == desc.plug;
   1.372 -			}
   1.373 -		};
   1.374 -
   1.375 -		typedef List<CHookManagerInfo> HookManInfoList;
   1.376 -
   1.377 -		class CHookManagerContainer : public HookManInfoList
   1.378 -		{
   1.379 -		public:
   1.380 -			// HMCI (Hook Manager Container Identification)
   1.381 -			class HMCI
   1.382 -			{
   1.383 -				CProto m_Proto;
   1.384 -				int m_VtableOffset;
   1.385 -				int m_VtableIndex;
   1.386 -			public:
   1.387 -				HMCI(const char *proto, int vtbloffs, int vtblidx) :
   1.388 -				  m_Proto(proto), m_VtableOffset(vtbloffs), m_VtableIndex(vtblidx)
   1.389 -				  {
   1.390 -				  }
   1.391 -				  ~HMCI()
   1.392 -				  {
   1.393 -				  }
   1.394 -
   1.395 -				  bool operator==(const HMCI &other) const
   1.396 -				  {
   1.397 -					  return
   1.398 -						  other.m_VtableIndex == m_VtableIndex &&
   1.399 -						  other.m_Proto == m_Proto &&
   1.400 -						  other.m_VtableOffset == m_VtableOffset;
   1.401 -				  }
   1.402 -
   1.403 -				  const CProto &GetProto() const
   1.404 -				  {
   1.405 -					  return m_Proto;
   1.406 -				  }
   1.407 -				  int GetVtableOffset() const
   1.408 -				  {
   1.409 -					  return m_VtableOffset;
   1.410 -				  }
   1.411 -				  int GetVtableIndex() const
   1.412 -				  {
   1.413 -					  return m_VtableIndex;
   1.414 -				  }
   1.415 -			};
   1.416 -			HMCI m_HCMI;
   1.417 -
   1.418 -		public:
   1.419 -			CHookManagerContainer(const HMCI &hmci) : m_HCMI(hmci)
   1.420 -			{
   1.421 -			}
   1.422 -			bool operator == (const HMCI &other) const
   1.423 -			{
   1.424 -				return m_HCMI == other;
   1.425 -			}
   1.426 -			void AddHookManager(Plugin plug, const CHookManagerInfo &hookman);
   1.427 -		};
   1.428 -
   1.429 -		class CCallClassImpl : public DeprecatedCallClass<void>
   1.430 -		{
   1.431 -		public:
   1.432 -
   1.433 -			typedef SourceHook::CVector<void*> OrigFuncs;
   1.434 -			typedef SourceHook::THash<int, OrigFuncs> OrigVTables;
   1.435 -
   1.436 -			void *m_Ptr;			//!< Pointer to the actual object
   1.437 -			size_t m_ObjSize;		//!< Size of the instance
   1.438 -			OrigVTables m_VT;		//!< Info about vtables & functions
   1.439 -
   1.440 -			int m_RefCounter;
   1.441 -
   1.442 -			CCallClassImpl(void *ptr, size_t size);
   1.443 -			virtual ~CCallClassImpl();
   1.444 -
   1.445 -			bool operator==(void *other)
   1.446 -			{
   1.447 -				return m_Ptr == other;
   1.448 -			}
   1.449 -
   1.450 -			void *GetThisPtr();
   1.451 -			void *GetOrigFunc(int vtbloffs, int vtblidx);
   1.452 -
   1.453 -			void ApplyCallClassPatch(int vtbl_offs, int vtbl_idx, void *orig_entry);
   1.454 -			void RemoveCallClassPatch(int vtbl_offs, int vtbl_idx);
   1.455 -		};
   1.456 -
   1.457 -		/**
   1.458 -		*	@brief A list of CallClass structures
   1.459 -		*/
   1.460 -		typedef List<CCallClassImpl> Impl_CallClassList;
   1.461 -
   1.462 -		Impl_CallClassList m_CallClasses;			//!< A list of already generated callclasses
   1.463 -
   1.464 -		/**
   1.465 -		*	@brief A list of CHookManagerContainers
   1.466 -		*/
   1.467 -		typedef List<CHookManagerContainer> HookManContList;
   1.468 -
   1.469 -		HookManContList m_HookMans;					//!< A list of hook managers
   1.470 -
   1.471 -		struct HookLoopInfo
   1.472 -		{
   1.473 -			enum RecallType
   1.474 -			{
   1.475 -				Recall_No=0,
   1.476 -				Recall_Pre,
   1.477 -				Recall_Post1,
   1.478 -				Recall_Post2
   1.479 -			};
   1.480 -
   1.481 +			CVfnPtr *pVfnPtr;
   1.482 +			CIface *pIface;
   1.483 +			
   1.484  			META_RES *pStatus;
   1.485  			META_RES *pPrevRes;
   1.486  			META_RES *pCurRes;
   1.487  
   1.488 -			META_RES temporaryStatus;				//!< Stored during Post1 recall phase
   1.489 -			bool shouldContinue;
   1.490 -			RecallType recall;						//!< Specifies which kind of recall we're in.
   1.491 -
   1.492 -			IIface *pCurIface;
   1.493 +			void *pThisPtr;
   1.494  			const void *pOrigRet;
   1.495  			void *pOverrideRet;
   1.496 -			void **pIfacePtrPtr;
   1.497 -		};
   1.498 -		typedef CStack<HookLoopInfo> HookLoopInfoStack;
   1.499 -
   1.500 -		void ApplyCallClassPatches(CCallClassImpl &cc);
   1.501 -		void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry);
   1.502 -		void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
   1.503 +			void *pIfacePtr;
   1.504  
   1.505 -		void SetPluginPaused(Plugin plug, bool paused);
   1.506 -
   1.507 -		HookLoopInfoStack m_HLIStack;
   1.508 -		CHookIDManager m_HookIDMan;
   1.509 -
   1.510 -		void *m_OneIgnore; //:TODO:
   1.511 -		bool m_IgnoreActive;
   1.512 -	public:
   1.513 -		CSourceHookImpl();
   1.514 -		virtual ~CSourceHookImpl();
   1.515 +			bool m_CallOrig;
   1.516  
   1.517 -		/**
   1.518 -		*	@brief Returns the interface version
   1.519 -		*/
   1.520 -		int GetIfaceVersion();
   1.521 -
   1.522 -		/**
   1.523 -		*	@brief Returns the implemnetation version
   1.524 -		*/
   1.525 -		int GetImplVersion();
   1.526 +			void SkipPaused(List<CHook>::iterator &iter, List<CHook> &list)
   1.527 +			{
   1.528 +				while (iter != list.end() && iter->IsPaused())
   1.529 +					++iter;
   1.530 +			}
   1.531 +		public:
   1.532 +			void HookRemoved(List<CHook>::iterator oldhookiter, List<CHook>::iterator nexthookiter);
   1.533 +			void IfaceRemoved(CIface *iface);
   1.534 +			void VfnPtrRemoved(CVfnPtr *vfnptr);
   1.535  
   1.536 -		/**
   1.537 -		*	@brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
   1.538 -		*/
   1.539 -		void UnloadPlugin(Plugin plug);
   1.540 +			ISHDelegate *GetNext();
   1.541 +			void *GetOverrideRetPtr();
   1.542 +			const void *GetOrigRetPtr();
   1.543 +			bool ShouldCallOrig();
   1.544 +		};
   1.545  
   1.546 -		/**
   1.547 -		*	@brief Shut down the whole system, unregister all hook managers
   1.548 -		*/
   1.549 -		void CompleteShutdown();
   1.550 +		typedef CStack<CHookContext> HookContextStack;
   1.551  
   1.552 -		/**
   1.553 -		*	@brief Add a hook.
   1.554 -		*
   1.555 -		*	@return True if the function succeeded, false otherwise
   1.556 -		*
   1.557 -		*	@param plug The unique identifier of the plugin that calls this function
   1.558 -		*	@param iface The interface pointer
   1.559 -		*	@param ifacesize The size of the class iface points to
   1.560 -		*	@param myHookMan A hook manager function that should be capable of handling the function
   1.561 -		*	@param handler A pointer to a FastDelegate containing the hook handler
   1.562 -		*	@param post Set to true if you want a post handler
   1.563 -		*/
   1.564 -		bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
   1.565 +		class CSourceHookImpl : public ISourceHook
   1.566 +		{
   1.567 +		private:
   1.568 +			CHookManContainerList m_HookManContainers;
   1.569 +			CHookIDManager m_HookIDMan;
   1.570 +			HookContextStack m_ContextStack;
   1.571  
   1.572 -		/**
   1.573 -		*	@brief Removes a hook.
   1.574 -		*
   1.575 -		*	@return True if the function succeeded, false otherwise
   1.576 -		*
   1.577 -		*	@param plug The unique identifier of the plugin that calls this function
   1.578 -		*	@param iface The interface pointer
   1.579 -		*	@param thisptr_offs This pointer adjuster
   1.580 -		*	@param myHookMan A hook manager function that should be capable of handling the function
   1.581 -		*	@param handler A pointer to a FastDelegate containing the hook handler
   1.582 -		*	@param post Set to true if you want a post handler
   1.583 -		*/
   1.584 -		bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
   1.585 +			bool SetHookPaused(int hookid, bool paused);
   1.586 +		public:
   1.587 +			CSourceHookImpl();
   1.588 +			virtual ~CSourceHookImpl();
   1.589  
   1.590 -		/**
   1.591 -		*	@brief Removes a hook.
   1.592 -		*
   1.593 -		*	@ return True if the function succeeded, false otherwise
   1.594 -		*
   1.595 -		*	@param info A RemoveHookInfo structure, describing the hook
   1.596 -		*/
   1.597 -		bool RemoveHook(RemoveHookInfo info);
   1.598 +			/**
   1.599 +			*	@brief Returns the interface version
   1.600 +			*/
   1.601 +			int GetIfaceVersion();
   1.602  
   1.603 -		/**
   1.604 -		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
   1.605 -		*
   1.606 -		*	@param plug The unique identifier of the plugin in question
   1.607 -		*/
   1.608 -		bool IsPluginInUse(Plugin plug);
   1.609 +			/**
   1.610 +			*	@brief Returns the implemnetation version
   1.611 +			*/
   1.612 +			int GetImplVersion();
   1.613  
   1.614 -		/**
   1.615 -		*	@brief Pauses all hooks of a plugin
   1.616 -		*
   1.617 -		*	@param plug The unique identifier of the plugin
   1.618 -		*/
   1.619 -		void PausePlugin(Plugin plug);
   1.620 +			int AddHook(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
   1.621 +				ISHDelegate *handler, bool post);
   1.622  
   1.623 -		/**
   1.624 -		*	@brief Unpauses all hooks of a plugin
   1.625 -		*
   1.626 -		*	@param plug The unique identifier of the plugin
   1.627 -		*/
   1.628 -		void UnpausePlugin(Plugin plug);
   1.629 +			bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
   1.630 +				ISHDelegate *handler, bool post);
   1.631 +
   1.632 +			bool RemoveHookByID(int hookid);
   1.633  
   1.634 -		/**
   1.635 -		*	@brief Return a pointer to a callclass. Generate a new one if required.
   1.636 -		*
   1.637 -		*	@param iface The interface pointer
   1.638 -		*	@param size Size of the class instance
   1.639 -		*/
   1.640 -		DeprecatedCallClass<void> *GetCallClass(void *iface, size_t size);
   1.641 -
   1.642 -		/**
   1.643 -		*	@brief Release a callclass
   1.644 -		*
   1.645 -		*	@param ptr Pointer to the callclass
   1.646 -		*/
   1.647 -		virtual void ReleaseCallClass(DeprecatedCallClass<void> *ptr);
   1.648 -
   1.649 -		virtual void SetRes(META_RES res);				//!< Sets the meta result
   1.650 -		virtual META_RES GetPrevRes();					//!< Gets the meta result of the previously called handler
   1.651 -		virtual META_RES GetStatus();					//!< Gets the highest meta result
   1.652 -		virtual const void *GetOrigRet();				//!< Gets the original result. If not in post function, undefined
   1.653 -		virtual const void *GetOverrideRet();			//!< Gets the override result. If none is specified, NULL
   1.654 -		virtual void *GetIfacePtr();					//!< Gets the interface pointer
   1.655 +			bool PauseHookByID(int hookid);
   1.656 +			bool UnpauseHookByID(int hookid);
   1.657  
   1.658 -		//////////////////////////////////////////////////////////////////////////
   1.659 -		// For hook managers
   1.660 -		void HookLoopBegin(IIface *pIface);			//!< Should be called when a hook loop begins
   1.661 -		void HookLoopEnd();							//!< Should be called when a hook loop exits
   1.662 -		void SetCurResPtr(META_RES *mres);			//!< Sets pointer to the current meta result
   1.663 -		void SetPrevResPtr(META_RES *mres);			//!< Sets pointer to previous meta result
   1.664 -		void SetStatusPtr(META_RES *mres);			//!< Sets pointer to the status variable
   1.665 -		void SetIfacePtrPtr(void **pp);				//!< Sets pointer to the interface this pointer
   1.666 -		void SetOrigRetPtr(const void *ptr);		//!< Sets the original return pointer
   1.667 -		void SetOverrideRetPtr(void *ptr);			//!< Sets the override result pointer
   1.668 -		bool ShouldContinue();						//!< Returns false if the hook loop should exit
   1.669 +			void SetRes(META_RES res);				//!< Sets the meta result
   1.670 +			META_RES GetPrevRes();					//!< Gets the meta result of the
   1.671 +													//!<  previously calledhandler
   1.672 +			META_RES GetStatus();					//!< Gets the highest meta result
   1.673 +			const void *GetOrigRet();				//!< Gets the original result.
   1.674 +													//!<  If not in post function, undefined
   1.675 +			const void *GetOverrideRet();			//!< Gets the override result.
   1.676 +													//!<  If none is specified, NULL
   1.677 +			void *GetIfacePtr();					//!< Gets the interface pointer
   1.678  
   1.679 -		/**
   1.680 -		*	@brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
   1.681 -		*
   1.682 -		*	@param plug The owner of the hook manager
   1.683 -		*   @param pubFunc The hook manager's info function
   1.684 -		*/
   1.685 -		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
   1.686 -		virtual void RemoveHookManager(RemoveHookManInfo info);
   1.687 +			void *GetOverrideRetPtr();				//!< Used for setting the override return value
   1.688  
   1.689 -		virtual void DoRecall();					//!< Initiates a recall sequence
   1.690 -		virtual void *GetOverrideRetPtr();			//!< Returns the pointer set by SetOverrideRetPtr
   1.691 +			/**
   1.692 +			*	@brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
   1.693 +			*/
   1.694 +			void UnloadPlugin(Plugin plug);
   1.695  
   1.696 -		virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
   1.697 -			void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr);
   1.698 +			void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
   1.699 +
   1.700 +			void SetIgnoreHooks(void *vfnptr);
   1.701 +			void ResetIgnoreHooks(void *vfnptr);
   1.702  
   1.703 -		/**
   1.704 -		*	@brief Add a (VP) hook.
   1.705 -		*
   1.706 -		*	@return non-zero hook id on success, 0 otherwise
   1.707 -		*
   1.708 -		*	@param plug The unique identifier of the plugin that calls this function
   1.709 -		*	@param mode	Can be either Hook_Normal or Hook_VP (vtable-wide hook)
   1.710 -		*	@param iface The interface pointer
   1.711 -		*				 The representative interface pointer for VP hooks
   1.712 -		*				 The vtable pointer for direct VP hooks !!!
   1.713 -		*	@param ifacesize The size of the class iface points to
   1.714 -		*	@param myHookMan A hook manager function that should be capable of handling the function
   1.715 -		*	@param handler A pointer to a FastDelegate containing the hook handler
   1.716 -		*	@param post Set to true if you want a post handler
   1.717 -		*/
   1.718 -		virtual int AddHookNew(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
   1.719 -			ISHDelegate *handler, bool post);
   1.720 +			void DoRecall();
   1.721 +
   1.722 +			IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry, META_RES *statusPtr,
   1.723 +				META_RES *prevResPtr, META_RES *curResPtr, const void *origRetPtr, void *overrideRetPtr);
   1.724 +
   1.725 +			void EndContext(IHookContext *pCtx);
   1.726 +
   1.727 +			/**
   1.728 +			*	@brief Shut down the whole system, unregister all hook managers
   1.729 +			*/
   1.730 +			void CompleteShutdown();
   1.731  
   1.732 -		/**
   1.733 -		*	@brief Remove a VP hook by ID.
   1.734 -		*
   1.735 -		*	@return true on success, false otherwise
   1.736 -		*
   1.737 -		*	@param plug The unique identifier of the plugin that calls this function
   1.738 -		*	@param hookid The hook id (returned by AddHookNew)
   1.739 -		*/
   1.740 -		virtual bool RemoveHookByID(Plugin plug, int hookid);
   1.741 +			/**
   1.742 +			*	@brief Pauses all hooks of a plugin
   1.743 +			*
   1.744 +			*	@param plug The unique identifier of the plugin
   1.745 +			*/
   1.746 +			void PausePlugin(Plugin plug);
   1.747  
   1.748 -		/**
   1.749 -		*	@brief Makes sure that hooks are going to be ignored on the next call of vfnptr
   1.750 -		*
   1.751 -		*	@param plug The unique identifier of the plugin that calls this function
   1.752 -		*	@param vfnptr The virtual function pointer of the function in question
   1.753 -		*/
   1.754 -		virtual void SetIgnoreHooks(Plugin plug, void *vfnptr);
   1.755 -
   1.756 -		/**
   1.757 -		*	@brief Reverses SetIgnoreHooks' effect
   1.758 -		*
   1.759 -		*	@param plug The unique identifier of the plugin that calls this function
   1.760 -		*	@param vfnptr The virtual function pointer of the function in question
   1.761 -		*/
   1.762 -		virtual void ResetIgnoreHooks(Plugin plug, void *vfnptr);
   1.763 -
   1.764 -		/**
   1.765 -		*	@brief Finds the original entry of a virtual function pointer
   1.766 -		*
   1.767 -		*	@param vfnptr The virtual function pointer
   1.768 -		*	@return The original entry if the virtual function pointer has been patched; NULL otherwise.
   1.769 -		*/
   1.770 -		virtual void *GetOrigVfnPtrEntry(void *vfnptr);
   1.771 -	};
   1.772 +			/**
   1.773 +			*	@brief Unpauses all hooks of a plugin
   1.774 +			*
   1.775 +			*	@param plug The unique identifier of the plugin
   1.776 +			*/
   1.777 +			void UnpausePlugin(Plugin plug);
   1.778 +		};
   1.779 +	}
   1.780  }
   1.781  
   1.782  #endif