Added possibility to specify your own g_SHPtr / g_Plug, removed all occurencies of The Word, fixed UnloadPlugin and CompleteShutdown
authorPavol Marko <pavolmarko@gmail.com>
Sat Apr 16 16:55:53 2005 +0000 (2005-04-16)
changeset 64803fd7d28bb
parent 5 bb01f2691cd1
child 7 8ef11f6189e4
Added possibility to specify your own g_SHPtr / g_Plug, removed all occurencies of The Word, fixed UnloadPlugin and CompleteShutdown
sourcehook/generate/sourcehook.hxx
sourcehook/sourcehook.cpp
sourcehook/sourcehook.h
sourcehook/sourcehook_impl.h
     1.1 --- a/sourcehook/generate/sourcehook.hxx	Thu Apr 14 16:19:07 2005 +0000
     1.2 +++ b/sourcehook/generate/sourcehook.hxx	Sat Apr 16 16:55:53 2005 +0000
     1.3 @@ -12,6 +12,14 @@
     1.4  #ifndef __SOURCEHOOK_H__
     1.5  #define __SOURCEHOOK_H__
     1.6  
     1.7 +#ifndef SH_GLOB_SHPTR
     1.8 +#define SH_GLOB_SHPTR g_SHPtr
     1.9 +#endif
    1.10 +
    1.11 +#ifndef SH_GLOB_PLUGPTR
    1.12 +#define SH_GLOB_PLUGPTR g_Plug
    1.13 +#endif
    1.14 +
    1.15  #define SH_ASSERT(x) if (!(x)) __asm { int 3 }
    1.16  
    1.17  // System
    1.18 @@ -73,26 +81,24 @@
    1.19  	*/
    1.20  	typedef void* Plugin;
    1.21  
    1.22 -	enum HookerAction
    1.23 +	enum HookManagerAction
    1.24  	{
    1.25  		HA_GetInfo = 0,			// -> Only store info
    1.26  		HA_Register,			// -> Save the pointer for future reference
    1.27 -		HA_Unregister,			// -> Clear the saved pointer
    1.28 -		HA_IfaceAdded,			// -> Request call class
    1.29 -		HA_IfaceRemoved			// -> Release call class
    1.30 +		HA_Unregister			// -> Clear the saved pointer
    1.31  	};
    1.32  
    1.33 -	struct HookerInfo;
    1.34 +	struct HookManagerInfo;
    1.35  
    1.36  	/**
    1.37 -	*	@brief Pointer to hooker type
    1.38 +	*	@brief Pointer to hook manager type
    1.39  	*
    1.40 -	*	A "hooker" is a the only thing that knows the actual protoype of the function at compile time.
    1.41 +	*	A "hook manager" is a the only thing that knows the actual protoype of the function at compile time.
    1.42  	*	
    1.43 -	*	@param hi A pointer to a HookerInfo structure. The hooker should fill it and store it for
    1.44 +	*	@param hi A pointer to a HookManagerInfo structure. The hook manager should fill it and store it for
    1.45  	*				future reference (mainly if something should get hooked to its hookfunc)
    1.46  	*/
    1.47 -	typedef int (*Hooker)(HookerAction ha, HookerInfo *hi);
    1.48 +	typedef int (*HookManagerPubFunc)(HookManagerAction ha, HookManagerInfo *hi);
    1.49  
    1.50  	class ISHDelegate
    1.51  	{
    1.52 @@ -126,9 +132,9 @@
    1.53  	};
    1.54  
    1.55  	/**
    1.56 -	*	@brief This structure contains information about a hooker (hook manager)
    1.57 +	*	@brief This structure contains information about a hook manager (hook manager)
    1.58  	*/
    1.59 -	struct HookerInfo
    1.60 +	struct HookManagerInfo
    1.61  	{
    1.62  		struct Iface
    1.63  		{
    1.64 @@ -148,11 +154,11 @@
    1.65  			}
    1.66  		};
    1.67  		Plugin plug;							//!< The owner plugin
    1.68 -		const char *proto;						//!< The prototype of the function the hooker is responsible for
    1.69 +		const char *proto;						//!< The prototype of the function the hook manager is responsible for
    1.70  		int vtbl_idx;							//!< The vtable index
    1.71  		int vtbl_offs;							//!< The vtable offset
    1.72  		int thisptr_offs;						//!< The this-pointer-adjuster
    1.73 -		Hooker func;							//!< The interface to the hooker
    1.74 +		HookManagerPubFunc func;				//!< The interface to the hook manager
    1.75  
    1.76  		int hookfunc_vtbl_idx;					//!< the vtable index of the hookfunc
    1.77  		int hookfunc_vtbl_offs;					//!< the vtable offset of the hookfunc
    1.78 @@ -203,11 +209,11 @@
    1.79  		*	@param plug The unique identifier of the plugin that calls this function
    1.80  		*	@param iface The interface pointer
    1.81  		*	@param ifacesize The size of the class iface points to
    1.82 -		*	@param myHooker A hooker function that should be capable of handling the function
    1.83 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    1.84  		*	@param handler A pointer to a FastDelegate containing the hook handler
    1.85  		*	@param post Set to true if you want a post handler
    1.86  		*/
    1.87 -		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
    1.88 +		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
    1.89  
    1.90  		/**
    1.91  		*	@brief Removes a hook.
    1.92 @@ -216,14 +222,14 @@
    1.93  		*
    1.94  		*	@param plug The unique identifier of the plugin that calls this function
    1.95  		*	@param iface The interface pointer
    1.96 -		*	@param myHooker A hooker function that should be capable of handling the function
    1.97 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    1.98  		*	@param handler A pointer to a FastDelegate containing the hook handler
    1.99  		*	@param post Set to true if you want a post handler
   1.100  		*/
   1.101 -		virtual bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   1.102 +		virtual bool RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
   1.103  
   1.104  		/**
   1.105 -		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
   1.106 +		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
   1.107  		*
   1.108  		*	@param plug The unique identifier of the plugin in question
   1.109  		*/
   1.110 @@ -251,7 +257,7 @@
   1.111  		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result. If none is specified, NULL
   1.112  		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   1.113  		//////////////////////////////////////////////////////////////////////////
   1.114 -		// For hookers
   1.115 +		// For hook managers
   1.116  		virtual META_RES &GetCurResRef() = 0;				//!< Gets the pointer to the current meta result
   1.117  		virtual META_RES &GetPrevResRef() = 0;				//!< Gets the pointer to the previous meta result
   1.118  		virtual META_RES &GetStatusRef() = 0;				//!< Gets the pointer to the status variable
   1.119 @@ -263,15 +269,15 @@
   1.120  
   1.121  //////////////////////////////////////////////////////////////////////////
   1.122  // Macro interface
   1.123 -#define SET_META_RESULT(result)		g_SHPtr->SetRes(result)
   1.124 -#define RETURN_META(result)			do { g_SHPtr->SetRes(result); return; } while(0)
   1.125 -#define RETURN_META_VALUE(result, value)	do { g_SHPtr->SetRes(result); return (value); } while(0)
   1.126 +#define SET_META_RESULT(result)		SH_GLOB_SHPTR->SetRes(result)
   1.127 +#define RETURN_META(result)			do { SH_GLOB_SHPTR->SetRes(result); return; } while(0)
   1.128 +#define RETURN_META_VALUE(result, value)	do { SH_GLOB_SHPTR->SetRes(result); return (value); } while(0)
   1.129  
   1.130 -#define META_RESULT_STATUS					g_SHPtr->GetStatus()
   1.131 -#define META_RESULT_PREVIOUS				g_SHPtr->GetPrevRes()
   1.132 -#define META_RESULT_ORIG_RET(type)			*(const type *)g_SHPtr->GetOrigRet()
   1.133 -#define META_RESULT_OVERRIDE_RET(type)		*(const type *)g_SHPtr->GetOverrideRet()
   1.134 -#define META_IFACEPTR						g_SHPtr->GetIfacePtr()
   1.135 +#define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
   1.136 +#define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
   1.137 +#define META_RESULT_ORIG_RET(type)			*(const type *)SH_GLOB_SHPTR->GetOrigRet()
   1.138 +#define META_RESULT_OVERRIDE_RET(type)		*(const type *)SH_GLOB_SHPTR->GetOverrideRet()
   1.139 +#define META_IFACEPTR						SH_GLOB_SHPTR->GetIfacePtr()
   1.140  
   1.141  
   1.142  /**
   1.143 @@ -280,8 +286,8 @@
   1.144  *	@param ifacetype The type of the interface
   1.145  *	@param ifaceptr The interface pointer
   1.146  */
   1.147 -#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(g_SHPtr->GetCallClass(ifaceptr, sizeof(ifacetype)))
   1.148 -#define SH_RELEASE_CALLCLASS(ptr) g_SHPtr->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   1.149 +#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(SH_GLOB_SHPTR->GetCallClass(ifaceptr, sizeof(ifacetype)))
   1.150 +#define SH_RELEASE_CALLCLASS(ptr) SH_GLOB_SHPTR->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   1.151  
   1.152  #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.153  	SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   1.154 @@ -303,8 +309,8 @@
   1.155  //////////////////////////////////////////////////////////////////////////
   1.156  #define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
   1.157  
   1.158 -#define SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   1.159 -	static int Hooker(HookerAction action, HookerInfo *param) \
   1.160 +#define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   1.161 +	static int HookManPubFunc(HookManagerAction action, HookManagerInfo *param) \
   1.162  	{ \
   1.163  		if (action == HA_GetInfo) \
   1.164  		{ \
   1.165 @@ -314,7 +320,7 @@
   1.166  			param->vtbl_idx = mfi.vtblindex; \
   1.167  			param->vtbl_offs = mfi.vtbloffs; \
   1.168  			param->thisptr_offs = mfi.thisptroffs; \
   1.169 -			if (param->thisptr_offs) \
   1.170 +			if (param->thisptr_offs < 0) \
   1.171  				return 2; /*No virtual inheritance supported*/ \
   1.172  			GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
   1.173  			param->hookfunc_vtbl_idx = mfi.vtblindex; \
   1.174 @@ -342,28 +348,28 @@
   1.175  		struct SH_FHCls(ifacetype,ifacefunc,overload) \
   1.176  		{ \
   1.177  			static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   1.178 -			static HookerInfo *ms_HI; \
   1.179 +			static HookManagerInfo *ms_HI; \
   1.180  			static const char *ms_Proto; \
   1.181 -			SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   1.182 +			SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   1.183  
   1.184  #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
   1.185  		}; \
   1.186  		const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
   1.187  		SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   1.188 -		HookerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   1.189 +		HookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   1.190  		bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   1.191  			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.192  		{ \
   1.193 -			return g_SHPtr->AddHook(g_Plug, iface, sizeof(ifacetype), \
   1.194 -				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, \
   1.195 +			return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, sizeof(ifacetype), \
   1.196 +				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   1.197  				new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   1.198  		} \
   1.199  		bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   1.200  			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.201  		{ \
   1.202  			CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
   1.203 -			return g_SHPtr->RemoveHook(g_Plug, iface, \
   1.204 -				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, &tmp, post); \
   1.205 +			return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, \
   1.206 +				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
   1.207  		} \
   1.208  	}
   1.209  
   1.210 @@ -371,25 +377,25 @@
   1.211  	/* 1) Find the iface ptr */ \
   1.212  	/* 1.1) Adjust to original this pointer */ \
   1.213  	void *origthis = this - ms_HI->thisptr_offs; \
   1.214 -	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.215 +	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.216  		ms_HI->ifaces.end(), origthis); \
   1.217  	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   1.218 -	HookerInfo::Iface &ci = *ifaceiter; \
   1.219 +	HookManagerInfo::Iface &ci = *ifaceiter; \
   1.220  	/* 2) Declare some vars and set it up */ \
   1.221 -	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.222 -	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.223 +	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.224 +	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.225  	rettype orig_ret, override_ret, plugin_ret; \
   1.226 -	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   1.227 -	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   1.228 -	META_RES &status = g_SHPtr->GetStatusRef(); \
   1.229 +	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   1.230 +	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   1.231 +	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   1.232  	status = MRES_IGNORED; \
   1.233 -	g_SHPtr->SetIfacePtr(ci.ptr); \
   1.234 -	g_SHPtr->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   1.235 -	g_SHPtr->SetOverrideRet(NULL);
   1.236 +	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   1.237 +	SH_GLOB_SHPTR->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   1.238 +	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   1.239  
   1.240  #define SH_CALL_HOOKS(post, params) \
   1.241  	prev_res = MRES_IGNORED; \
   1.242 -	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.243 +	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.244  	{ \
   1.245  		cur_res = MRES_IGNORED; \
   1.246  		plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   1.247 @@ -399,7 +405,7 @@
   1.248  		if (cur_res >= MRES_OVERRIDE) \
   1.249  		{ \
   1.250  			override_ret = plugin_ret; \
   1.251 -			g_SHPtr->SetOverrideRet(&override_ret); \
   1.252 +			SH_GLOB_SHPTR->SetOverrideRet(&override_ret); \
   1.253  		} \
   1.254  	}
   1.255  
   1.256 @@ -424,23 +430,23 @@
   1.257  	/* 1) Find the iface ptr */ \
   1.258  	/* 1.1) Adjust to original this pointer */ \
   1.259  	void *origthis = this - ms_HI->thisptr_offs; \
   1.260 -	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.261 +	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.262  		ms_HI->ifaces.end(), origthis); \
   1.263  	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   1.264 -	HookerInfo::Iface &ci = *ifaceiter; \
   1.265 +	HookManagerInfo::Iface &ci = *ifaceiter; \
   1.266  	/* 2) Declare some vars and set it up */ \
   1.267 -	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.268 -	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.269 -	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   1.270 -	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   1.271 -	META_RES &status = g_SHPtr->GetStatusRef(); \
   1.272 +	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.273 +	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.274 +	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   1.275 +	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   1.276 +	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   1.277  	status = MRES_IGNORED; \
   1.278 -	g_SHPtr->SetIfacePtr(ci.ptr); \
   1.279 -	g_SHPtr->SetOverrideRet(NULL);
   1.280 +	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   1.281 +	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   1.282  
   1.283  #define SH_CALL_HOOKS_void(post, params) \
   1.284  	prev_res = MRES_IGNORED; \
   1.285 -	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.286 +	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.287  	{ \
   1.288  		cur_res = MRES_IGNORED; \
   1.289  		reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
     2.1 --- a/sourcehook/sourcehook.cpp	Thu Apr 14 16:19:07 2005 +0000
     2.2 +++ b/sourcehook/sourcehook.cpp	Sat Apr 16 16:55:53 2005 +0000
     2.3 @@ -83,18 +83,18 @@
     2.4  
     2.5  	bool CSourceHookImpl::IsPluginInUse(Plugin plug)
     2.6  	{
     2.7 -		// Iterate through all hookers which are in this plugin
     2.8 +		// Iterate through all hook managers which are in this plugin
     2.9  		// Iterate through their hooks
    2.10  		// If a hook from an other plugin is found, return true
    2.11  		// Return false otherwise
    2.12  
    2.13 -		for (HookerInfoList::iterator iter = m_Hookers.begin(); iter != m_Hookers.end(); ++iter)
    2.14 +		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
    2.15  		{
    2.16  			if (iter->plug == plug && !iter->ifaces.empty())
    2.17  			{
    2.18 -				for (std::list<HookerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end(); ++iter2)
    2.19 +				for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end(); ++iter2)
    2.20  				{
    2.21 -					std::list<HookerInfo::Iface::Hook>::iterator iter3;
    2.22 +					std::list<HookManagerInfo::Iface::Hook>::iterator iter3;
    2.23  					for (iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
    2.24  						if (iter3->plug == plug)
    2.25  							return true;
    2.26 @@ -109,41 +109,43 @@
    2.27  
    2.28  	void CSourceHookImpl::UnloadPlugin(Plugin plug)
    2.29  	{
    2.30 -		// Get a list of hookers that are in this plugin and are used by other plugins
    2.31 +		// 1) Manually remove all hooks by this plugin
    2.32 +		std::list<RemoveHookInfo> hookstoremove;
    2.33 +
    2.34 +		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
    2.35 +		{
    2.36 +			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
    2.37 +				++iter2)
    2.38 +			{
    2.39 +				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
    2.40 +					if (iter3->plug == plug)
    2.41 +						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
    2.42  
    2.43 -		HookerInfoList tmphookers;
    2.44 +				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
    2.45 +					if (iter3->plug == plug)
    2.46 +						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
    2.47 +			}
    2.48 +		}
    2.49 +
    2.50 +		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
    2.51 +			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
    2.52 +
    2.53 +		// 2) Other plugins may use hook managers in this plugin.
    2.54 +		// Get a list of hook managers that are in this plugin and are used by other plugins
    2.55 +		// Delete all hook managers that are in this plugin
    2.56 +
    2.57 +		HookManInfoList tmphookmans;
    2.58  		bool erase = false;
    2.59 -		for (HookerInfoList::iterator iter = m_Hookers.begin(); iter != m_Hookers.end();
    2.60 -			erase ? iter=m_Hookers.erase(iter) : ++iter)
    2.61 +		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end();
    2.62 +			erase ? iter=m_HookMans.erase(iter) : ++iter)
    2.63  		{
    2.64 -			if (iter->plug == plug && !iter->ifaces.empty())
    2.65 +			if (iter->plug == plug)
    2.66  			{
    2.67 -				bool found = false;
    2.68 -				for (std::list<HookerInfo::Iface>::iterator iter2 = iter->ifaces.begin();
    2.69 -					iter2 != iter->ifaces.end(); ++iter2)
    2.70 +				if (!iter->ifaces.empty())
    2.71  				{
    2.72 -					for (std::list<HookerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin();
    2.73 -						iter3 != iter2->hooks_pre.end(); ++iter3)
    2.74 -					{
    2.75 -						if (iter3->plug != plug)
    2.76 -						{
    2.77 -							found = true;
    2.78 -							break;
    2.79 -						}
    2.80 -					}
    2.81 -					for (iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
    2.82 -					{
    2.83 -						if (iter3->plug != plug)
    2.84 -						{
    2.85 -							found = true;
    2.86 -							break;
    2.87 -						}
    2.88 -					}
    2.89 -					if (found)
    2.90 -					{
    2.91 -						tmphookers.push_back(*iter);
    2.92 -						break;
    2.93 -					}
    2.94 +					// All hooks by this plugin are already removed
    2.95 +					// So if there is an iface, it has to be used by an other plugin
    2.96 +					tmphookmans.push_back(*iter);
    2.97  				}
    2.98  				erase = true;
    2.99  			}
   2.100 @@ -151,120 +153,106 @@
   2.101  				erase = false;
   2.102  		}
   2.103  		
   2.104 -		// For each hooker:
   2.105 -		for (HookerInfoList::iterator iter = tmphookers.begin(); iter != tmphookers.end(); ++iter)
   2.106 +		// For each hook manager:
   2.107 +		for (HookManInfoList::iterator iter = tmphookmans.begin(); iter != tmphookmans.end(); ++iter)
   2.108  		{
   2.109 -			// Shutdown all ifaces and remove the hooks from this plugin from their lists
   2.110 -			for (std::list<HookerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   2.111 -				erase ? iter2 = iter->ifaces.erase(iter2) : ++iter2)
   2.112 -			{
   2.113 -				*(reinterpret_cast<void**>(reinterpret_cast<char*>(iter2->ptr) + iter->vtbl_offs) 
   2.114 -					+ iter->vtbl_idx) = iter2->orig_entry;
   2.115 -
   2.116 -				for (std::list<HookerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end();
   2.117 -					iter3->plug == plug ? iter3=iter2->hooks_pre.erase(iter3) : ++iter3) {}
   2.118 -				for (std::list<HookerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end();
   2.119 -					iter3->plug == plug ? iter3=iter2->hooks_post.erase(iter3) : ++iter3) {}
   2.120 -				
   2.121 -				erase = iter2->hooks_pre.empty() && iter2->hooks_post.empty();
   2.122 -			}
   2.123 -			
   2.124 -			if (iter->ifaces.empty())
   2.125 -			{
   2.126 -				// Nothing more to do; no more ifaces to re-register
   2.127 -				continue;
   2.128 -			}
   2.129 -
   2.130 -			// 2) Find a suitable hooker in an other plugin
   2.131 -			HookerInfoList::iterator newHooker = FindHooker(m_Hookers.begin(), m_Hookers.end(),
   2.132 +			// Find a suitable hook manager in an other plugin
   2.133 +			HookManInfoList::iterator newHookMan = FindHookMan(m_HookMans.begin(), m_HookMans.end(),
   2.134  				iter->proto, iter->vtbl_offs, iter->vtbl_idx, iter->thisptr_offs);
   2.135 -			if (newHooker == m_Hookers.end())
   2.136 +			if (newHookMan == m_HookMans.end())
   2.137  			{
   2.138  				// This should _never_ happen.
   2.139 -				// If there is a hook from an other plugin, the plugin must have provided a hooker as well.
   2.140 +				// If there is a hook from an other plugin, the plugin must have provided a hook manager as well.
   2.141  				SH_ASSERT(0);
   2.142  			}
   2.143  
   2.144 -			// AddHook should make sure that every plugin only has _one_ hooker for _one_ proto/vi/vo
   2.145 -			SH_ASSERT(newHooker->plug != plug);
   2.146 +			// AddHook should make sure that every plugin only has _one_ hook manager for _one_ proto/vi/vo/thisptroffs
   2.147 +			SH_ASSERT(newHookMan->plug != plug);
   2.148 +
   2.149 +			// The first hooker should be always used - so the new hook manager has to be empty
   2.150 +			SH_ASSERT(newHookMan->ifaces.empty());
   2.151  
   2.152 -			// 3) Register it!
   2.153 -			newHooker->func(HA_Register, &(*iter));
   2.154 -			for (std::list<HookerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   2.155 -				++iter2)
   2.156 -			{
   2.157 -				reinterpret_cast<void**>(reinterpret_cast<char*>(iter2->ptr) + iter->vtbl_offs)[iter->vtbl_idx] =
   2.158 -					reinterpret_cast<void**>(reinterpret_cast<char*>(iter->hookfunc_inst) + iter->hookfunc_vtbl_offs)[iter->hookfunc_vtbl_idx];
   2.159 -			}
   2.160 +			// Move the ifaces from the old hook manager to the new one
   2.161 +			newHookMan->ifaces = iter->ifaces;
   2.162 +
   2.163 +			// Unregister the old one, register the new one
   2.164 +			iter->func(HA_Unregister, NULL);
   2.165 +			newHookMan->func(HA_Register, &(*newHookMan));
   2.166  		}
   2.167  	}
   2.168  
   2.169  	void CSourceHookImpl::CompleteShutdown()
   2.170  	{
   2.171 -		// Go through all hookers and shut down all interfaces
   2.172 -		for (HookerInfoList::iterator iter = m_Hookers.begin(); iter != m_Hookers.end(); ++iter)
   2.173 +		std::list<RemoveHookInfo> hookstoremove;
   2.174 +
   2.175 +		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   2.176  		{
   2.177 -			for (std::list<HookerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end(); ++iter2)
   2.178 +			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   2.179 +				++iter2)
   2.180  			{
   2.181 -				// Note that we can pass iter->func as "myHooker" because it is only used
   2.182 -				// to retreive data
   2.183 -				for (std::list<HookerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   2.184 -					RemoveHook(iter3->plug, iter2->ptr, iter->func, iter3->handler, false);
   2.185 -				for (std::list<HookerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   2.186 -					RemoveHook(iter3->plug, iter2->ptr, iter->func, iter3->handler, true);
   2.187 +				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   2.188 +					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
   2.189 +				
   2.190 +				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   2.191 +					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
   2.192  			}
   2.193  		}
   2.194 +
   2.195 +		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
   2.196 +			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
   2.197 +
   2.198 +		m_HookMans.clear();
   2.199  	}
   2.200  
   2.201 -	bool CSourceHookImpl::AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post)
   2.202 +	bool CSourceHookImpl::AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   2.203  	{
   2.204 -		// 1) Get info about the hooker
   2.205 -		HookerInfo tmp;
   2.206 -		if (myHooker(HA_GetInfo, &tmp) != 0)
   2.207 +		// 1) Get info about the hook manager
   2.208 +		HookManagerInfo tmp;
   2.209 +		if (myHookMan(HA_GetInfo, &tmp) != 0)
   2.210  			return false;
   2.211  
   2.212 -		// Add the proposed hooker to the _end_ of the list if the plugin doesn't have a hooker with this proto/vo/vi registered
   2.213 -		HookerInfoList::iterator hookeriter;
   2.214 -		for (hookeriter = m_Hookers.begin(); hookeriter != m_Hookers.end(); ++hookeriter)
   2.215 +		// Add the proposed hook manager to the _end_ of the list if the plugin doesn't have a hook manager with this proto/vo/vi registered
   2.216 +		HookManInfoList::iterator hookmaniter;
   2.217 +		for (hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   2.218  		{
   2.219 -			if (hookeriter->plug == plug && strcmp(hookeriter->proto, tmp.proto) == 0 &&
   2.220 -				hookeriter->vtbl_offs == tmp.vtbl_offs && hookeriter->vtbl_idx == tmp.vtbl_idx &&
   2.221 -				hookeriter->thisptr_offs == tmp.thisptr_offs)
   2.222 +			if (hookmaniter->plug == plug && strcmp(hookmaniter->proto, tmp.proto) == 0 &&
   2.223 +				hookmaniter->vtbl_offs == tmp.vtbl_offs && hookmaniter->vtbl_idx == tmp.vtbl_idx &&
   2.224 +				hookmaniter->thisptr_offs == tmp.thisptr_offs)
   2.225  				break;
   2.226  		}
   2.227 -		if (hookeriter == m_Hookers.end())
   2.228 +		if (hookmaniter == m_HookMans.end())
   2.229  		{
   2.230 -			// No such hooker from this plugin yet, add it!
   2.231 -			tmp.func = myHooker;
   2.232 +			// No such hook manager from this plugin yet, add it!
   2.233 +			tmp.func = myHookMan;
   2.234  			tmp.plug = plug;
   2.235 -			m_Hookers.push_back(tmp);
   2.236 +			m_HookMans.push_back(tmp);
   2.237  		}
   2.238  
   2.239 -		// Then, search for a suitable hooker (from the beginning)
   2.240 -		HookerInfoList::iterator hooker = FindHooker(m_Hookers.begin(), m_Hookers.end(), tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   2.241 -		SH_ASSERT(hooker != m_Hookers.end());
   2.242 +		// Then, search for a suitable hook manager (from the beginning)
   2.243 +		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   2.244 +		SH_ASSERT(hookman != m_HookMans.end());
   2.245  
   2.246  		// Tell it to store the pointer if it's not already active
   2.247 -		if (hooker->ifaces.empty())
   2.248 -			hooker->func(HA_Register, &(*hooker));
   2.249 +		if (hookman->ifaces.empty())
   2.250 +			hookman->func(HA_Register, &(*hookman));
   2.251  
   2.252 -		std::list<HookerInfo::Iface>::iterator ifsiter = std::find(hooker->ifaces.begin(), hooker->ifaces.end(), iface);
   2.253 +		std::list<HookManagerInfo::Iface>::iterator ifsiter = std::find(hookman->ifaces.begin(), hookman->ifaces.end(), iface);
   2.254  
   2.255 -		if (ifsiter == hooker->ifaces.end())
   2.256 +		if (ifsiter == hookman->ifaces.end())
   2.257  		{
   2.258 -			HookerInfo::Iface ifs;
   2.259 +			HookManagerInfo::Iface ifs;
   2.260  			ifs.ptr = iface;
   2.261  			ifs.callclass = GetCallClass(iface, ifacesize);
   2.262 -			void *vtableptr = *reinterpret_cast<void**>(reinterpret_cast<char*>(iface) + hooker->vtbl_offs);
   2.263 -			SetMemAccess(vtableptr, sizeof(void*) * hooker->vtbl_idx, SH_MEM_READ | SH_MEM_WRITE);
   2.264 -			ifs.orig_entry = (*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hooker->vtbl_offs))[hooker->vtbl_idx];
   2.265 -			(*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hooker->vtbl_offs))[hooker->vtbl_idx] =
   2.266 -				(*reinterpret_cast<void***>(reinterpret_cast<char*>(hooker->hookfunc_inst) + hooker->hookfunc_vtbl_offs))[hooker->hookfunc_vtbl_idx];
   2.267 -			hooker->ifaces.push_back(ifs);
   2.268 -			ifsiter = hooker->ifaces.end();
   2.269 +			void *vtableptr = *reinterpret_cast<void**>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs);
   2.270 +			SetMemAccess(vtableptr, sizeof(void*) * hookman->vtbl_idx, SH_MEM_READ | SH_MEM_WRITE);
   2.271 +			ifs.orig_entry = (*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx];
   2.272 +			(*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx] =
   2.273 +				(*reinterpret_cast<void***>(reinterpret_cast<char*>(hookman->hookfunc_inst) + hookman->hookfunc_vtbl_offs))[hookman->hookfunc_vtbl_idx];
   2.274 +			hookman->ifaces.push_back(ifs);
   2.275 +			ifsiter = hookman->ifaces.end();
   2.276  			--ifsiter;
   2.277  		}
   2.278 -		HookerInfo::Iface::Hook hookinfo;
   2.279 +		HookManagerInfo::Iface::Hook hookinfo;
   2.280  		hookinfo.handler = handler;
   2.281  		hookinfo.plug = plug;
   2.282  		if (post)
   2.283 @@ -288,25 +276,25 @@
   2.284  		return true;
   2.285  	}
   2.286  
   2.287 -	bool CSourceHookImpl::RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post)
   2.288 +	bool CSourceHookImpl::RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   2.289  	{
   2.290 -		HookerInfo tmp;
   2.291 -		if (myHooker(HA_GetInfo, &tmp) != 0)
   2.292 +		HookManagerInfo tmp;
   2.293 +		if (myHookMan(HA_GetInfo, &tmp) != 0)
   2.294  			return false;
   2.295  
   2.296 -		// Find the hooker and the hook
   2.297 -		HookerInfoList::iterator hooker = FindHooker(m_Hookers.begin(), m_Hookers.end(), 
   2.298 +		// Find the hook manager and the hook
   2.299 +		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), 
   2.300  			tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   2.301 -		if (hooker == m_Hookers.end())
   2.302 +		if (hookman == m_HookMans.end())
   2.303  			return false;
   2.304  
   2.305 -		for (std::list<HookerInfo::Iface>::iterator ifaceiter = hooker->ifaces.begin(); ifaceiter != hooker->ifaces.end(); ++ifaceiter)
   2.306 +		for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   2.307  		{
   2.308  			if (ifaceiter->ptr == iface)
   2.309  			{
   2.310 -				std::list<HookerInfo::Iface::Hook> &hooks = post ? ifaceiter->hooks_post : ifaceiter->hooks_pre;
   2.311 +				std::list<HookManagerInfo::Iface::Hook> &hooks = post ? ifaceiter->hooks_post : ifaceiter->hooks_pre;
   2.312  				bool erase;
   2.313 -				for (std::list<HookerInfo::Iface::Hook>::iterator hookiter = hooks.begin();
   2.314 +				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = hooks.begin();
   2.315  					hookiter != hooks.end(); erase ? hookiter = hooks.erase(hookiter) : ++hookiter)
   2.316  				{
   2.317  					erase = hookiter->plug == plug && hookiter->handler->IsEqual(handler);
   2.318 @@ -317,16 +305,16 @@
   2.319  				{
   2.320  					// Deactivate the hook
   2.321  					(*reinterpret_cast<void***>(reinterpret_cast<char*>(ifaceiter->ptr) +
   2.322 -						hooker->vtbl_offs))[hooker->vtbl_idx]= ifaceiter->orig_entry;
   2.323 +						hookman->vtbl_offs))[hookman->vtbl_idx]= ifaceiter->orig_entry;
   2.324  
   2.325  					// Release the callclass
   2.326  					ReleaseCallClass(ifaceiter->callclass);
   2.327  
   2.328  					// Remove the iface info
   2.329 -					hooker->ifaces.erase(ifaceiter);
   2.330 +					hookman->ifaces.erase(ifaceiter);
   2.331  
   2.332 -					if (hooker->ifaces.empty())
   2.333 -						hooker->func(HA_Unregister, NULL);
   2.334 +					if (hookman->ifaces.empty())
   2.335 +						hookman->func(HA_Unregister, NULL);
   2.336  				}
   2.337  				// :TODO: Better return value? Or none?
   2.338  				return true;
   2.339 @@ -361,13 +349,13 @@
   2.340  		tmp.refcounter = 1;
   2.341  
   2.342  		// Go through _all_ hooks and apply any needed patches
   2.343 -		for (HookerInfoList::iterator hooker = m_Hookers.begin(); hooker != m_Hookers.end(); ++hooker)
   2.344 +		for (HookManInfoList::iterator hookman = m_HookMans.begin(); hookman != m_HookMans.end(); ++hookman)
   2.345  		{
   2.346 -			for (std::list<HookerInfo::Iface>::iterator ifaceiter = hooker->ifaces.begin(); ifaceiter != hooker->ifaces.end(); ++ifaceiter)
   2.347 +			for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   2.348  			{
   2.349  				if (ifaceiter->ptr == iface)
   2.350  				{
   2.351 -					if (!ApplyCallClassPatch(tmp, hooker->vtbl_offs, hooker->vtbl_idx, ifaceiter->orig_entry))
   2.352 +					if (!ApplyCallClassPatch(tmp, hookman->vtbl_offs, hookman->vtbl_idx, ifaceiter->orig_entry))
   2.353  					{
   2.354  						FreeCallClass(tmp);
   2.355  						return NULL;
   2.356 @@ -479,16 +467,16 @@
   2.357  	}
   2.358  
   2.359  
   2.360 -	CSourceHookImpl::HookerInfoList::iterator CSourceHookImpl::FindHooker(HookerInfoList::iterator begin,
   2.361 -		HookerInfoList::iterator end, const char *proto, int vtblofs, int vtblidx, int thisptrofs)
   2.362 +	CSourceHookImpl::HookManInfoList::iterator CSourceHookImpl::FindHookMan(HookManInfoList::iterator begin,
   2.363 +		HookManInfoList::iterator end, const char *proto, int vtblofs, int vtblidx, int thisptrofs)
   2.364  	{
   2.365 -		for (HookerInfoList::iterator hookeriter = m_Hookers.begin(); hookeriter != m_Hookers.end(); ++hookeriter)
   2.366 +		for (HookManInfoList::iterator hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   2.367  		{
   2.368 -			if (strcmp(hookeriter->proto, proto) == 0 && hookeriter->vtbl_offs == vtblofs && hookeriter->vtbl_idx == vtblidx &&
   2.369 -				hookeriter->thisptr_offs == thisptrofs)
   2.370 +			if (strcmp(hookmaniter->proto, proto) == 0 && hookmaniter->vtbl_offs == vtblofs && hookmaniter->vtbl_idx == vtblidx &&
   2.371 +				hookmaniter->thisptr_offs == thisptrofs)
   2.372  				break;
   2.373  		}
   2.374 -		return hookeriter;
   2.375 +		return hookmaniter;
   2.376  	}
   2.377  
   2.378  
     3.1 --- a/sourcehook/sourcehook.h	Thu Apr 14 16:19:07 2005 +0000
     3.2 +++ b/sourcehook/sourcehook.h	Sat Apr 16 16:55:53 2005 +0000
     3.3 @@ -12,6 +12,14 @@
     3.4  #ifndef __SOURCEHOOK_H__
     3.5  #define __SOURCEHOOK_H__
     3.6  
     3.7 +#ifndef SH_GLOB_SHPTR
     3.8 +#define SH_GLOB_SHPTR g_SHPtr
     3.9 +#endif
    3.10 +
    3.11 +#ifndef SH_GLOB_PLUGPTR
    3.12 +#define SH_GLOB_PLUGPTR g_Plug
    3.13 +#endif
    3.14 +
    3.15  #define SH_ASSERT(x) if (!(x)) __asm { int 3 }
    3.16  
    3.17  // System
    3.18 @@ -73,26 +81,24 @@
    3.19  	*/
    3.20  	typedef void* Plugin;
    3.21  
    3.22 -	enum HookerAction
    3.23 +	enum HookManagerAction
    3.24  	{
    3.25  		HA_GetInfo = 0,			// -> Only store info
    3.26  		HA_Register,			// -> Save the pointer for future reference
    3.27 -		HA_Unregister,			// -> Clear the saved pointer
    3.28 -		HA_IfaceAdded,			// -> Request call class
    3.29 -		HA_IfaceRemoved			// -> Release call class
    3.30 +		HA_Unregister			// -> Clear the saved pointer
    3.31  	};
    3.32  
    3.33 -	struct HookerInfo;
    3.34 +	struct HookManagerInfo;
    3.35  
    3.36  	/**
    3.37 -	*	@brief Pointer to hooker type
    3.38 +	*	@brief Pointer to hook manager type
    3.39  	*
    3.40 -	*	A "hooker" is a the only thing that knows the actual protoype of the function at compile time.
    3.41 +	*	A "hook manager" is a the only thing that knows the actual protoype of the function at compile time.
    3.42  	*	
    3.43 -	*	@param hi A pointer to a HookerInfo structure. The hooker should fill it and store it for
    3.44 +	*	@param hi A pointer to a HookManagerInfo structure. The hook manager should fill it and store it for
    3.45  	*				future reference (mainly if something should get hooked to its hookfunc)
    3.46  	*/
    3.47 -	typedef int (*Hooker)(HookerAction ha, HookerInfo *hi);
    3.48 +	typedef int (*HookManagerPubFunc)(HookManagerAction ha, HookManagerInfo *hi);
    3.49  
    3.50  	class ISHDelegate
    3.51  	{
    3.52 @@ -126,9 +132,9 @@
    3.53  	};
    3.54  
    3.55  	/**
    3.56 -	*	@brief This structure contains information about a hooker (hook manager)
    3.57 +	*	@brief This structure contains information about a hook manager (hook manager)
    3.58  	*/
    3.59 -	struct HookerInfo
    3.60 +	struct HookManagerInfo
    3.61  	{
    3.62  		struct Iface
    3.63  		{
    3.64 @@ -148,11 +154,11 @@
    3.65  			}
    3.66  		};
    3.67  		Plugin plug;							//!< The owner plugin
    3.68 -		const char *proto;						//!< The prototype of the function the hooker is responsible for
    3.69 +		const char *proto;						//!< The prototype of the function the hook manager is responsible for
    3.70  		int vtbl_idx;							//!< The vtable index
    3.71  		int vtbl_offs;							//!< The vtable offset
    3.72  		int thisptr_offs;						//!< The this-pointer-adjuster
    3.73 -		Hooker func;							//!< The interface to the hooker
    3.74 +		HookManagerPubFunc func;				//!< The interface to the hook manager
    3.75  
    3.76  		int hookfunc_vtbl_idx;					//!< the vtable index of the hookfunc
    3.77  		int hookfunc_vtbl_offs;					//!< the vtable offset of the hookfunc
    3.78 @@ -203,11 +209,11 @@
    3.79  		*	@param plug The unique identifier of the plugin that calls this function
    3.80  		*	@param iface The interface pointer
    3.81  		*	@param ifacesize The size of the class iface points to
    3.82 -		*	@param myHooker A hooker function that should be capable of handling the function
    3.83 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    3.84  		*	@param handler A pointer to a FastDelegate containing the hook handler
    3.85  		*	@param post Set to true if you want a post handler
    3.86  		*/
    3.87 -		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
    3.88 +		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
    3.89  
    3.90  		/**
    3.91  		*	@brief Removes a hook.
    3.92 @@ -216,14 +222,14 @@
    3.93  		*
    3.94  		*	@param plug The unique identifier of the plugin that calls this function
    3.95  		*	@param iface The interface pointer
    3.96 -		*	@param myHooker A hooker function that should be capable of handling the function
    3.97 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    3.98  		*	@param handler A pointer to a FastDelegate containing the hook handler
    3.99  		*	@param post Set to true if you want a post handler
   3.100  		*/
   3.101 -		virtual bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   3.102 +		virtual bool RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
   3.103  
   3.104  		/**
   3.105 -		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
   3.106 +		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
   3.107  		*
   3.108  		*	@param plug The unique identifier of the plugin in question
   3.109  		*/
   3.110 @@ -251,7 +257,7 @@
   3.111  		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result. If none is specified, NULL
   3.112  		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   3.113  		//////////////////////////////////////////////////////////////////////////
   3.114 -		// For hookers
   3.115 +		// For hook managers
   3.116  		virtual META_RES &GetCurResRef() = 0;				//!< Gets the pointer to the current meta result
   3.117  		virtual META_RES &GetPrevResRef() = 0;				//!< Gets the pointer to the previous meta result
   3.118  		virtual META_RES &GetStatusRef() = 0;				//!< Gets the pointer to the status variable
   3.119 @@ -263,15 +269,15 @@
   3.120  
   3.121  //////////////////////////////////////////////////////////////////////////
   3.122  // Macro interface
   3.123 -#define SET_META_RESULT(result)		g_SHPtr->SetRes(result)
   3.124 -#define RETURN_META(result)			do { g_SHPtr->SetRes(result); return; } while(0)
   3.125 -#define RETURN_META_VALUE(result, value)	do { g_SHPtr->SetRes(result); return (value); } while(0)
   3.126 +#define SET_META_RESULT(result)		SH_GLOB_SHPTR->SetRes(result)
   3.127 +#define RETURN_META(result)			do { SH_GLOB_SHPTR->SetRes(result); return; } while(0)
   3.128 +#define RETURN_META_VALUE(result, value)	do { SH_GLOB_SHPTR->SetRes(result); return (value); } while(0)
   3.129  
   3.130 -#define META_RESULT_STATUS					g_SHPtr->GetStatus()
   3.131 -#define META_RESULT_PREVIOUS				g_SHPtr->GetPrevRes()
   3.132 -#define META_RESULT_ORIG_RET(type)			*(const type *)g_SHPtr->GetOrigRet()
   3.133 -#define META_RESULT_OVERRIDE_RET(type)		*(const type *)g_SHPtr->GetOverrideRet()
   3.134 -#define META_IFACEPTR						g_SHPtr->GetIfacePtr()
   3.135 +#define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
   3.136 +#define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
   3.137 +#define META_RESULT_ORIG_RET(type)			*(const type *)SH_GLOB_SHPTR->GetOrigRet()
   3.138 +#define META_RESULT_OVERRIDE_RET(type)		*(const type *)SH_GLOB_SHPTR->GetOverrideRet()
   3.139 +#define META_IFACEPTR						SH_GLOB_SHPTR->GetIfacePtr()
   3.140  
   3.141  
   3.142  /**
   3.143 @@ -280,8 +286,8 @@
   3.144  *	@param ifacetype The type of the interface
   3.145  *	@param ifaceptr The interface pointer
   3.146  */
   3.147 -#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(g_SHPtr->GetCallClass(ifaceptr, sizeof(ifacetype)))
   3.148 -#define SH_RELEASE_CALLCLASS(ptr) g_SHPtr->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   3.149 +#define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(SH_GLOB_SHPTR->GetCallClass(ifaceptr, sizeof(ifacetype)))
   3.150 +#define SH_RELEASE_CALLCLASS(ptr) SH_GLOB_SHPTR->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   3.151  
   3.152  #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   3.153  	SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   3.154 @@ -303,8 +309,8 @@
   3.155  //////////////////////////////////////////////////////////////////////////
   3.156  #define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
   3.157  
   3.158 -#define SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   3.159 -	static int Hooker(HookerAction action, HookerInfo *param) \
   3.160 +#define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   3.161 +	static int HookManPubFunc(HookManagerAction action, HookManagerInfo *param) \
   3.162  	{ \
   3.163  		if (action == HA_GetInfo) \
   3.164  		{ \
   3.165 @@ -342,28 +348,28 @@
   3.166  		struct SH_FHCls(ifacetype,ifacefunc,overload) \
   3.167  		{ \
   3.168  			static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   3.169 -			static HookerInfo *ms_HI; \
   3.170 +			static HookManagerInfo *ms_HI; \
   3.171  			static const char *ms_Proto; \
   3.172 -			SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   3.173 +			SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   3.174  
   3.175  #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
   3.176  		}; \
   3.177  		const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
   3.178  		SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   3.179 -		HookerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   3.180 +		HookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   3.181  		bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   3.182  			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   3.183  		{ \
   3.184 -			return g_SHPtr->AddHook(g_Plug, iface, sizeof(ifacetype), \
   3.185 -				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, \
   3.186 +			return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, sizeof(ifacetype), \
   3.187 +				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   3.188  				new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   3.189  		} \
   3.190  		bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   3.191  			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   3.192  		{ \
   3.193  			CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
   3.194 -			return g_SHPtr->RemoveHook(g_Plug, iface, \
   3.195 -				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, &tmp, post); \
   3.196 +			return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, \
   3.197 +				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
   3.198  		} \
   3.199  	}
   3.200  
   3.201 @@ -371,25 +377,25 @@
   3.202  	/* 1) Find the iface ptr */ \
   3.203  	/* 1.1) Adjust to original this pointer */ \
   3.204  	void *origthis = this - ms_HI->thisptr_offs; \
   3.205 -	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   3.206 +	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   3.207  		ms_HI->ifaces.end(), origthis); \
   3.208  	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   3.209 -	HookerInfo::Iface &ci = *ifaceiter; \
   3.210 +	HookManagerInfo::Iface &ci = *ifaceiter; \
   3.211  	/* 2) Declare some vars and set it up */ \
   3.212 -	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   3.213 -	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   3.214 +	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   3.215 +	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   3.216  	rettype orig_ret, override_ret, plugin_ret; \
   3.217 -	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   3.218 -	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   3.219 -	META_RES &status = g_SHPtr->GetStatusRef(); \
   3.220 +	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   3.221 +	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   3.222 +	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   3.223  	status = MRES_IGNORED; \
   3.224 -	g_SHPtr->SetIfacePtr(ci.ptr); \
   3.225 -	g_SHPtr->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   3.226 -	g_SHPtr->SetOverrideRet(NULL);
   3.227 +	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   3.228 +	SH_GLOB_SHPTR->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   3.229 +	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   3.230  
   3.231  #define SH_CALL_HOOKS(post, params) \
   3.232  	prev_res = MRES_IGNORED; \
   3.233 -	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   3.234 +	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   3.235  	{ \
   3.236  		cur_res = MRES_IGNORED; \
   3.237  		plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   3.238 @@ -399,7 +405,7 @@
   3.239  		if (cur_res >= MRES_OVERRIDE) \
   3.240  		{ \
   3.241  			override_ret = plugin_ret; \
   3.242 -			g_SHPtr->SetOverrideRet(&override_ret); \
   3.243 +			SH_GLOB_SHPTR->SetOverrideRet(&override_ret); \
   3.244  		} \
   3.245  	}
   3.246  
   3.247 @@ -424,23 +430,23 @@
   3.248  	/* 1) Find the iface ptr */ \
   3.249  	/* 1.1) Adjust to original this pointer */ \
   3.250  	void *origthis = this - ms_HI->thisptr_offs; \
   3.251 -	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   3.252 +	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   3.253  		ms_HI->ifaces.end(), origthis); \
   3.254  	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   3.255 -	HookerInfo::Iface &ci = *ifaceiter; \
   3.256 +	HookManagerInfo::Iface &ci = *ifaceiter; \
   3.257  	/* 2) Declare some vars and set it up */ \
   3.258 -	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   3.259 -	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   3.260 -	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   3.261 -	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   3.262 -	META_RES &status = g_SHPtr->GetStatusRef(); \
   3.263 +	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   3.264 +	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   3.265 +	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   3.266 +	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   3.267 +	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   3.268  	status = MRES_IGNORED; \
   3.269 -	g_SHPtr->SetIfacePtr(ci.ptr); \
   3.270 -	g_SHPtr->SetOverrideRet(NULL);
   3.271 +	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   3.272 +	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   3.273  
   3.274  #define SH_CALL_HOOKS_void(post, params) \
   3.275  	prev_res = MRES_IGNORED; \
   3.276 -	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   3.277 +	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   3.278  	{ \
   3.279  		cur_res = MRES_IGNORED; \
   3.280  		reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
     4.1 --- a/sourcehook/sourcehook_impl.h	Thu Apr 14 16:19:07 2005 +0000
     4.2 +++ b/sourcehook/sourcehook_impl.h	Sat Apr 16 16:55:53 2005 +0000
     4.3 @@ -22,9 +22,26 @@
     4.4  	class CSourceHookImpl : public ISourceHook
     4.5  	{
     4.6  		/**
     4.7 -		*	@brief A list of HookerInfo structures
     4.8 +		*	@brief A hook can be removed if you have this information
     4.9  		*/
    4.10 -		typedef std::list<HookerInfo> HookerInfoList;
    4.11 +		struct RemoveHookInfo
    4.12 +		{
    4.13 +			RemoveHookInfo(Plugin p, void *i, HookManagerPubFunc h, ISHDelegate *hd, bool ps)
    4.14 +				: plug(p), iface(i), hpf(h), handler(hd), post(ps)
    4.15 +			{
    4.16 +			}
    4.17 +
    4.18 +			Plugin plug;
    4.19 +			void *iface;
    4.20 +			HookManagerPubFunc hpf;
    4.21 +			ISHDelegate *handler;
    4.22 +			bool post;
    4.23 +		};
    4.24 +
    4.25 +		/**
    4.26 +		*	@brief A list of HookManagerInfo structures
    4.27 +		*/
    4.28 +		typedef std::list<HookManagerInfo> HookManInfoList;
    4.29  
    4.30  
    4.31  		/**
    4.32 @@ -33,14 +50,14 @@
    4.33  		typedef std::list<CallClass> Impl_CallClassList;
    4.34  
    4.35  		Impl_CallClassList m_CallClasses;			//!< A list of already generated callclasses
    4.36 -		HookerInfoList m_Hookers;					//!< A list of hookers
    4.37 +		HookManInfoList m_HookMans;					//!< A list of hook managers
    4.38  
    4.39  		int m_PageSize;								//!< Stores the system's page size
    4.40  
    4.41  		/**
    4.42 -		*	@brief Finds a hooker for a function based on a text-prototype, a vtable offset and a vtable index
    4.43 +		*	@brief Finds a hook manager for a function based on a text-prototype, a vtable offset and a vtable index
    4.44  		*/
    4.45 -		HookerInfoList::iterator FindHooker(HookerInfoList::iterator begin, HookerInfoList::iterator end, 
    4.46 +		HookManInfoList::iterator FindHookMan(HookManInfoList::iterator begin, HookManInfoList::iterator end, 
    4.47  			const char *proto, int vtblofs, int vtblidx, int thisptrofs);
    4.48  
    4.49  		void FreeCallClass(CallClass &cc);
    4.50 @@ -57,12 +74,12 @@
    4.51  		~CSourceHookImpl();
    4.52  
    4.53  		/**
    4.54 -		*	@brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hookers
    4.55 +		*	@brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
    4.56  		*/
    4.57  		void UnloadPlugin(Plugin plug);
    4.58  
    4.59  		/**
    4.60 -		*	@brief Shut down the whole system, unregister all hookers
    4.61 +		*	@brief Shut down the whole system, unregister all hook managers
    4.62  		*/
    4.63  		void CompleteShutdown();
    4.64  
    4.65 @@ -73,11 +90,12 @@
    4.66  		*
    4.67  		*	@param plug The unique identifier of the plugin that calls this function
    4.68  		*	@param iface The interface pointer
    4.69 -		*	@param myHooker A hooker (hook manager) function that should be capable of handling the corresponding function
    4.70 +		*	@param ifacesize The size of the class iface points to
    4.71 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    4.72  		*	@param handler A pointer to a FastDelegate containing the hook handler
    4.73  		*	@param post Set to true if you want a post handler
    4.74  		*/
    4.75 -		bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post);
    4.76 +		bool AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
    4.77  
    4.78  		/**
    4.79  		*	@brief Removes a hook.
    4.80 @@ -86,16 +104,14 @@
    4.81  		*
    4.82  		*	@param plug The unique identifier of the plugin that calls this function
    4.83  		*	@param iface The interface pointer
    4.84 -		*	@param vtableoffset Offset to the vtable, in bytes
    4.85 -		*	@param vtableidx Pointer to the vtable index of the function
    4.86 -		*	@param proto A text version of the function prototype; generated by the macros
    4.87 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    4.88  		*	@param handler A pointer to a FastDelegate containing the hook handler
    4.89  		*	@param post Set to true if you want a post handler
    4.90  		*/
    4.91 -		bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post);
    4.92 +		bool RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
    4.93  
    4.94  		/**
    4.95 -		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
    4.96 +		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
    4.97  		*
    4.98  		*	@param plug The unique identifier of the plugin in question
    4.99  		*/
   4.100 @@ -123,7 +139,7 @@
   4.101  		virtual void *GetIfacePtr();					//!< Gets the interface pointer
   4.102  
   4.103  		//////////////////////////////////////////////////////////////////////////
   4.104 -		// For hookers
   4.105 +		// For hook managers
   4.106  		virtual META_RES &GetCurResRef();				//!< Gets the pointer to the current meta result
   4.107  		virtual META_RES &GetPrevResRef();				//!< Gets the pointer to the previous meta result
   4.108  		virtual META_RES &GetStatusRef();				//!< Gets the pointer to the status variable