One bugfix, addition of META_RETURN_(VALUE_)NEWPARAMS (implemented using recalls), tests now support compiling against an older version of sourcehook.h (through the sourcehook_test.h file) while main.cpp which now also acts as a CSourceHookImpl factory compiles against the new version.
authorPavol Marko <pavolmarko@gmail.com>
Fri Dec 23 11:58:11 2005 +0000 (2005-12-23)
changeset 162a95db73792e5
parent 161 264cecd7a0a8
child 163 377bdd31c28d
One bugfix, addition of META_RETURN_(VALUE_)NEWPARAMS (implemented using recalls), tests now support compiling against an older version of sourcehook.h (through the sourcehook_test.h file) while main.cpp which now also acts as a CSourceHookImpl factory compiles against the new version.
sourcehook/generate/sourcehook.h
sourcehook/generate/sourcehook.hxx
sourcehook/sh_stack.h
sourcehook/sourcehook.cpp
sourcehook/sourcehook.h
sourcehook/sourcehook_impl.h
sourcehook/test/main.cpp
sourcehook/test/sourcehook_test.h
sourcehook/test/test.vcproj
sourcehook/test/test1.cpp
sourcehook/test/test2.cpp
sourcehook/test/test3.cpp
sourcehook/test/test4.cpp
sourcehook/test/testbail.cpp
sourcehook/test/testbail.h
sourcehook/test/testbail2.cpp
sourcehook/test/testevents.h
sourcehook/test/testmanual.cpp
sourcehook/test/testrecall.cpp
sourcehook/test/testreentr.cpp
     1.1 --- a/sourcehook/generate/sourcehook.h	Thu Dec 22 21:00:54 2005 +0000
     1.2 +++ b/sourcehook/generate/sourcehook.h	Fri Dec 23 11:58:11 2005 +0000
     1.3 @@ -372,7 +372,7 @@
     1.4  		virtual void SetStatusPtr(META_RES *mres) = 0;			//!< Sets pointer to the status variable
     1.5  		virtual void SetIfacePtrPtr(void **pp) = 0;				//!< Sets pointer to the interface this pointer
     1.6  		virtual void SetOrigRetPtr(const void *ptr) = 0;		//!< Sets the original return pointer
     1.7 -		virtual void SetOverrideRetPtr(const void *ptr) = 0;	//!< Sets the override result pointer
     1.8 +		virtual void SetOverrideRetPtr(void *ptr) = 0;			//!< Sets the override result pointer
     1.9  		virtual bool ShouldContinue() = 0;						//!< Returns false if the hook loop should exit
    1.10  
    1.11  		/**
    1.12 @@ -382,22 +382,89 @@
    1.13  		*   @param pubFunc The hook manager's info function
    1.14  		*/
    1.15  		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
    1.16 +
    1.17 +		virtual void DoRecall() = 0;							//!< Initiates a recall sequence
    1.18 +		/*
    1.19 +			HOW RECALLS WORK:
    1.20 +			
    1.21 +			The problem:
    1.22 +				Users want the ability to change parameters of the called function
    1.23 +				from inside their handler.
    1.24 +			The solution:
    1.25 +				1) Mark as "recall"
    1.26 +				2) Recall the function
    1.27 +				3) => SH's hook func gets called:
    1.28 +				  4) The first iterator points at the first hook the last hookfunc didn't execute yet
    1.29 +				  5) does all iteration and returns normally
    1.30 +		        6) The user's handler returns immediately
    1.31 +				7) The hook func returns immediately as well
    1.32 +
    1.33 +				Also note that the recalled hookfunc starts with the status the recalling hookfunc
    1.34 +				ended with. The last handler (doing the recall) is also able to specify its own
    1.35 +				META_RES.
    1.36 +		*/
    1.37 +
    1.38 +		virtual void *GetOverrideRetPtr() = 0;		//!< Returns the pointer set by SetOverrideRetPtr
    1.39 +
    1.40 +		/**
    1.41 +		*	@brief Set up the hook loop. Equivalent to calling:
    1.42 +		*	SetStatusPtr, SetPrevResPtr, SetCurResPtr, SetIfacePtrPtr, SetOrigRetPtr, Get/SetOverrideRetPtr
    1.43 +		*
    1.44 +		*	@param statusPtr		pointer to status variable
    1.45 +		*	@param prevResPtr		pointer to previous result variable
    1.46 +		*	@param curResPtr		pointer to current result variable
    1.47 +		*	@param ifacePtrPtr		pointer to interface this pointer variable
    1.48 +		*	@param origRetPr		pointer to original return value variable. NULL for void funcs
    1.49 +		*	@param overrideRetPtr	pointer to override return value variable. NULL for void funcs
    1.50 +		*	
    1.51 +		*	@return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
    1.52 +		*		when the hook func is being called as part of a recall
    1.53 +		*/
    1.54 +		virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
    1.55 +			void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr) = 0;
    1.56  	};
    1.57  }
    1.58  
    1.59  /************************************************************************/
    1.60  /* High level interface                                                 */
    1.61  /************************************************************************/
    1.62 -#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    1.63 -#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    1.64 -#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    1.65 -
    1.66  #define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
    1.67  #define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
    1.68  #define META_RESULT_ORIG_RET(type)			*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOrigRet())
    1.69  #define META_RESULT_OVERRIDE_RET(type)		*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOverrideRet())
    1.70  #define META_IFACEPTR(type)					reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
    1.71  
    1.72 +#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    1.73 +#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    1.74 +#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    1.75 +
    1.76 +
    1.77 +// NEVER-EVER call these from post hooks!
    1.78 +// also, only call it from the hook handlers directly!
    1.79 +// :TODO: enforce it
    1.80 +// :TODO: problems with SetOverrideResult and overloaded iface::func ?
    1.81 +
    1.82 +// SourceHook::SetOverrideRet is defined later.
    1.83 +#define RETURN_META_NEWPARAMS(result, iface, func, newparams) \
    1.84 +	do { \
    1.85 +		SET_META_RESULT(result); \
    1.86 +		SH_GLOB_SHPTR->DoRecall(); \
    1.87 +		META_IFACEPTR(iface)->func newparams; \
    1.88 +		RETURN_META(MRES_SUPERCEDE); \
    1.89 +	} while (0)
    1.90 +
    1.91 +#define RETURN_META_VALUE_NEWPARAMS(result, value, iface, func, newparams) \
    1.92 +	do { \
    1.93 +		SET_META_RESULT(result); \
    1.94 +		SH_GLOB_SHPTR->DoRecall(); \
    1.95 +		if ((result) >= MRES_OVERRIDE) \
    1.96 +		{ \
    1.97 +			/* meh, set the override result here because we don't get a chance to return */ \
    1.98 +			/* before continuing the hook loop through the recall */ \
    1.99 +			SourceHook::SetOverrideResult(SH_GLOB_SHPTR, &iface::func, value); \
   1.100 +		} \
   1.101 +		RETURN_META_VALUE(MRES_SUPERCEDE, META_IFACEPTR(iface)->func newparams); \
   1.102 +	} while (0)
   1.103  
   1.104  /**
   1.105  *	@brief Get/generate callclass for an interface pointer
   1.106 @@ -542,8 +609,8 @@
   1.107  		using namespace ::SourceHook; \
   1.108  		MemFuncInfo mfi; \
   1.109  		GetFuncInfo(funcptr, mfi); \
   1.110 -		if (mfi.thisptroffs < 0) \
   1.111 -			return false; /* No virtual inheritance supported */ \
   1.112 +		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   1.113 +			return false; /* No non-virtual functions / virtual inheritance supported */ \
   1.114  		\
   1.115  		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
   1.116  			SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   1.117 @@ -659,16 +726,12 @@
   1.118  	META_RES status = MRES_IGNORED; \
   1.119  	META_RES prev_res; \
   1.120  	META_RES cur_res; \
   1.121 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   1.122 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   1.123 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   1.124  	rettype orig_ret; \
   1.125  	rettype override_ret; \
   1.126  	rettype plugin_ret; \
   1.127  	void* ifptr; \
   1.128 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   1.129 -	SH_GLOB_SHPTR->SetOrigRetPtr(reinterpret_cast<void*>(&orig_ret)); \
   1.130 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL);
   1.131 +	rettype *pOverrideRet = reinterpret_cast<rettype*>(SH_GLOB_SHPTR->SetupHookLoop( \
   1.132 +		&status, &prev_res, &cur_res, &ifptr, &orig_ret, &override_ret));
   1.133  
   1.134  #define SH_CALL_HOOKS(post, params) \
   1.135  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   1.136 @@ -683,10 +746,7 @@
   1.137  			if (cur_res > status) \
   1.138  				status = cur_res; \
   1.139  			if (cur_res >= MRES_OVERRIDE) \
   1.140 -			{ \
   1.141 -				override_ret = plugin_ret; \
   1.142 -				SH_GLOB_SHPTR->SetOverrideRetPtr(&override_ret); \
   1.143 -			} \
   1.144 +				*pOverrideRet = plugin_ret; \
   1.145  			if (!SH_GLOB_SHPTR->ShouldContinue()) \
   1.146  			{ \
   1.147  				iter.SetToZero(); \
   1.148 @@ -703,11 +763,11 @@
   1.149  		orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
   1.150  	} \
   1.151  	else \
   1.152 -		orig_ret = override_ret;
   1.153 +		orig_ret = override_ret; \
   1.154  
   1.155  #define SH_RETURN() \
   1.156  	SH_GLOB_SHPTR->HookLoopEnd(); \
   1.157 -	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   1.158 +	return status >= MRES_OVERRIDE ? *pOverrideRet : orig_ret;
   1.159  
   1.160  #define SH_HANDLEFUNC(paramtypes, params, rettype) \
   1.161  	SH_SETUPCALLS(rettype, paramtypes, params) \
   1.162 @@ -743,13 +803,8 @@
   1.163  	META_RES status = MRES_IGNORED; \
   1.164  	META_RES prev_res; \
   1.165  	META_RES cur_res; \
   1.166 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   1.167 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   1.168 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   1.169  	void* ifptr; \
   1.170 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   1.171 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL); \
   1.172 -	SH_GLOB_SHPTR->SetOrigRetPtr(NULL);
   1.173 +	SH_GLOB_SHPTR->SetupHookLoop(&status, &prev_res, &cur_res, &ifptr, NULL, NULL); \
   1.174  
   1.175  #define SH_CALL_HOOKS_void(post, params) \
   1.176  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   1.177 @@ -791,6 +846,7 @@
   1.178  
   1.179  
   1.180  // Special vafmt handlers
   1.181 +// :TODO: what
   1.182  #define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
   1.183  	SH_SETUPCALLS(rettype, paramtypes, params_orig) \
   1.184  	SH_CALL_HOOKS(pre, params_plug) \
   1.185 @@ -3497,6 +3553,121 @@
   1.186  
   1.187  #undef SH_MAKE_EXECUTABLECLASS_OB
   1.188  
   1.189 +//////////////////////////////////////////////////////////////////////////
   1.190 +// SetOverrideRet for recalls
   1.191 +// These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
   1.192 +// The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
   1.193 +// (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
   1.194 +
   1.195 +namespace SourceHook
   1.196 +{
   1.197 +	template <class Iface, class RetType>
   1.198 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(), const RetType res)
   1.199 +	{
   1.200 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.201 +	}
   1.202 +	template <class Iface, class RetType, class Param1>
   1.203 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1), const RetType res)
   1.204 +	{
   1.205 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.206 +	}
   1.207 +	template <class Iface, class RetType, class Param1, class Param2>
   1.208 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2), const RetType res)
   1.209 +	{
   1.210 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.211 +	}
   1.212 +	template <class Iface, class RetType, class Param1, class Param2, class Param3>
   1.213 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3), const RetType res)
   1.214 +	{
   1.215 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.216 +	}
   1.217 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
   1.218 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4), const RetType res)
   1.219 +	{
   1.220 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.221 +	}
   1.222 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
   1.223 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5), const RetType res)
   1.224 +	{
   1.225 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.226 +	}
   1.227 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
   1.228 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6), const RetType res)
   1.229 +	{
   1.230 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.231 +	}
   1.232 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
   1.233 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7), const RetType res)
   1.234 +	{
   1.235 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.236 +	}
   1.237 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
   1.238 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8), const RetType res)
   1.239 +	{
   1.240 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.241 +	}
   1.242 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
   1.243 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9), const RetType res)
   1.244 +	{
   1.245 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.246 +	}
   1.247 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
   1.248 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10), const RetType res)
   1.249 +	{
   1.250 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.251 +	}
   1.252 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
   1.253 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11), const RetType res)
   1.254 +	{
   1.255 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.256 +	}
   1.257 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
   1.258 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12), const RetType res)
   1.259 +	{
   1.260 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.261 +	}
   1.262 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
   1.263 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13), const RetType res)
   1.264 +	{
   1.265 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.266 +	}
   1.267 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
   1.268 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14), const RetType res)
   1.269 +	{
   1.270 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.271 +	}
   1.272 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
   1.273 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15), const RetType res)
   1.274 +	{
   1.275 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.276 +	}
   1.277 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
   1.278 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16), const RetType res)
   1.279 +	{
   1.280 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.281 +	}
   1.282 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17>
   1.283 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17), const RetType res)
   1.284 +	{
   1.285 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.286 +	}
   1.287 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18>
   1.288 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18), const RetType res)
   1.289 +	{
   1.290 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.291 +	}
   1.292 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18, class Param19>
   1.293 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18, Param19), const RetType res)
   1.294 +	{
   1.295 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.296 +	}
   1.297 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18, class Param19, class Param20>
   1.298 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18, Param19, Param20), const RetType res)
   1.299 +	{
   1.300 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   1.301 +	}
   1.302 +}
   1.303 +
   1.304  #endif
   1.305  	// The pope is dead. -> :(
   1.306  
     2.1 --- a/sourcehook/generate/sourcehook.hxx	Thu Dec 22 21:00:54 2005 +0000
     2.2 +++ b/sourcehook/generate/sourcehook.hxx	Fri Dec 23 11:58:11 2005 +0000
     2.3 @@ -372,7 +372,7 @@
     2.4  		virtual void SetStatusPtr(META_RES *mres) = 0;			//!< Sets pointer to the status variable
     2.5  		virtual void SetIfacePtrPtr(void **pp) = 0;				//!< Sets pointer to the interface this pointer
     2.6  		virtual void SetOrigRetPtr(const void *ptr) = 0;		//!< Sets the original return pointer
     2.7 -		virtual void SetOverrideRetPtr(const void *ptr) = 0;	//!< Sets the override result pointer
     2.8 +		virtual void SetOverrideRetPtr(void *ptr) = 0;			//!< Sets the override result pointer
     2.9  		virtual bool ShouldContinue() = 0;						//!< Returns false if the hook loop should exit
    2.10  
    2.11  		/**
    2.12 @@ -382,22 +382,89 @@
    2.13  		*   @param pubFunc The hook manager's info function
    2.14  		*/
    2.15  		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
    2.16 +
    2.17 +		virtual void DoRecall() = 0;							//!< Initiates a recall sequence
    2.18 +		/*
    2.19 +			HOW RECALLS WORK:
    2.20 +			
    2.21 +			The problem:
    2.22 +				Users want the ability to change parameters of the called function
    2.23 +				from inside their handler.
    2.24 +			The solution:
    2.25 +				1) Mark as "recall"
    2.26 +				2) Recall the function
    2.27 +				3) => SH's hook func gets called:
    2.28 +				  4) The first iterator points at the first hook the last hookfunc didn't execute yet
    2.29 +				  5) does all iteration and returns normally
    2.30 +		        6) The user's handler returns immediately
    2.31 +				7) The hook func returns immediately as well
    2.32 +
    2.33 +				Also note that the recalled hookfunc starts with the status the recalling hookfunc
    2.34 +				ended with. The last handler (doing the recall) is also able to specify its own
    2.35 +				META_RES.
    2.36 +		*/
    2.37 +
    2.38 +		virtual void *GetOverrideRetPtr() = 0;		//!< Returns the pointer set by SetOverrideRetPtr
    2.39 +
    2.40 +		/**
    2.41 +		*	@brief Set up the hook loop. Equivalent to calling:
    2.42 +		*	SetStatusPtr, SetPrevResPtr, SetCurResPtr, SetIfacePtrPtr, SetOrigRetPtr, Get/SetOverrideRetPtr
    2.43 +		*
    2.44 +		*	@param statusPtr		pointer to status variable
    2.45 +		*	@param prevResPtr		pointer to previous result variable
    2.46 +		*	@param curResPtr		pointer to current result variable
    2.47 +		*	@param ifacePtrPtr		pointer to interface this pointer variable
    2.48 +		*	@param origRetPr		pointer to original return value variable. NULL for void funcs
    2.49 +		*	@param overrideRetPtr	pointer to override return value variable. NULL for void funcs
    2.50 +		*	
    2.51 +		*	@return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
    2.52 +		*		when the hook func is being called as part of a recall
    2.53 +		*/
    2.54 +		virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
    2.55 +			void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr) = 0;
    2.56  	};
    2.57  }
    2.58  
    2.59  /************************************************************************/
    2.60  /* High level interface                                                 */
    2.61  /************************************************************************/
    2.62 -#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    2.63 -#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    2.64 -#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    2.65 -
    2.66  #define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
    2.67  #define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
    2.68  #define META_RESULT_ORIG_RET(type)			*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOrigRet())
    2.69  #define META_RESULT_OVERRIDE_RET(type)		*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOverrideRet())
    2.70  #define META_IFACEPTR(type)					reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
    2.71  
    2.72 +#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    2.73 +#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    2.74 +#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    2.75 +
    2.76 +
    2.77 +// NEVER-EVER call these from post hooks!
    2.78 +// also, only call it from the hook handlers directly!
    2.79 +// :TODO: enforce it
    2.80 +// :TODO: problems with SetOverrideResult and overloaded iface::func ?
    2.81 +
    2.82 +// SourceHook::SetOverrideRet is defined later.
    2.83 +#define RETURN_META_NEWPARAMS(result, iface, func, newparams) \
    2.84 +	do { \
    2.85 +		SET_META_RESULT(result); \
    2.86 +		SH_GLOB_SHPTR->DoRecall(); \
    2.87 +		META_IFACEPTR(iface)->func newparams; \
    2.88 +		RETURN_META(MRES_SUPERCEDE); \
    2.89 +	} while (0)
    2.90 +
    2.91 +#define RETURN_META_VALUE_NEWPARAMS(result, value, iface, func, newparams) \
    2.92 +	do { \
    2.93 +		SET_META_RESULT(result); \
    2.94 +		SH_GLOB_SHPTR->DoRecall(); \
    2.95 +		if ((result) >= MRES_OVERRIDE) \
    2.96 +		{ \
    2.97 +			/* meh, set the override result here because we don't get a chance to return */ \
    2.98 +			/* before continuing the hook loop through the recall */ \
    2.99 +			SourceHook::SetOverrideResult(SH_GLOB_SHPTR, &iface::func, value); \
   2.100 +		} \
   2.101 +		RETURN_META_VALUE(MRES_SUPERCEDE, META_IFACEPTR(iface)->func newparams); \
   2.102 +	} while (0)
   2.103  
   2.104  /**
   2.105  *	@brief Get/generate callclass for an interface pointer
   2.106 @@ -542,8 +609,8 @@
   2.107  		using namespace ::SourceHook; \
   2.108  		MemFuncInfo mfi; \
   2.109  		GetFuncInfo(funcptr, mfi); \
   2.110 -		if (mfi.thisptroffs < 0) \
   2.111 -			return false; /* No virtual inheritance supported */ \
   2.112 +		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   2.113 +			return false; /* No non-virtual functions / virtual inheritance supported */ \
   2.114  		\
   2.115  		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
   2.116  			SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   2.117 @@ -659,16 +726,12 @@
   2.118  	META_RES status = MRES_IGNORED; \
   2.119  	META_RES prev_res; \
   2.120  	META_RES cur_res; \
   2.121 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   2.122 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   2.123 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   2.124  	rettype orig_ret; \
   2.125  	rettype override_ret; \
   2.126  	rettype plugin_ret; \
   2.127  	void* ifptr; \
   2.128 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   2.129 -	SH_GLOB_SHPTR->SetOrigRetPtr(reinterpret_cast<void*>(&orig_ret)); \
   2.130 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL);
   2.131 +	rettype *pOverrideRet = reinterpret_cast<rettype*>(SH_GLOB_SHPTR->SetupHookLoop( \
   2.132 +		&status, &prev_res, &cur_res, &ifptr, &orig_ret, &override_ret));
   2.133  
   2.134  #define SH_CALL_HOOKS(post, params) \
   2.135  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   2.136 @@ -683,10 +746,7 @@
   2.137  			if (cur_res > status) \
   2.138  				status = cur_res; \
   2.139  			if (cur_res >= MRES_OVERRIDE) \
   2.140 -			{ \
   2.141 -				override_ret = plugin_ret; \
   2.142 -				SH_GLOB_SHPTR->SetOverrideRetPtr(&override_ret); \
   2.143 -			} \
   2.144 +				*pOverrideRet = plugin_ret; \
   2.145  			if (!SH_GLOB_SHPTR->ShouldContinue()) \
   2.146  			{ \
   2.147  				iter.SetToZero(); \
   2.148 @@ -703,11 +763,11 @@
   2.149  		orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
   2.150  	} \
   2.151  	else \
   2.152 -		orig_ret = override_ret;
   2.153 +		orig_ret = override_ret; \
   2.154  
   2.155  #define SH_RETURN() \
   2.156  	SH_GLOB_SHPTR->HookLoopEnd(); \
   2.157 -	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   2.158 +	return status >= MRES_OVERRIDE ? *pOverrideRet : orig_ret;
   2.159  
   2.160  #define SH_HANDLEFUNC(paramtypes, params, rettype) \
   2.161  	SH_SETUPCALLS(rettype, paramtypes, params) \
   2.162 @@ -743,13 +803,8 @@
   2.163  	META_RES status = MRES_IGNORED; \
   2.164  	META_RES prev_res; \
   2.165  	META_RES cur_res; \
   2.166 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   2.167 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   2.168 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   2.169  	void* ifptr; \
   2.170 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   2.171 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL); \
   2.172 -	SH_GLOB_SHPTR->SetOrigRetPtr(NULL);
   2.173 +	SH_GLOB_SHPTR->SetupHookLoop(&status, &prev_res, &cur_res, &ifptr, NULL, NULL); \
   2.174  
   2.175  #define SH_CALL_HOOKS_void(post, params) \
   2.176  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   2.177 @@ -791,6 +846,7 @@
   2.178  
   2.179  
   2.180  // Special vafmt handlers
   2.181 +// :TODO: what
   2.182  #define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
   2.183  	SH_SETUPCALLS(rettype, paramtypes, params_orig) \
   2.184  	SH_CALL_HOOKS(pre, params_plug) \
   2.185 @@ -1025,5 +1081,22 @@
   2.186  
   2.187  #undef SH_MAKE_EXECUTABLECLASS_OB
   2.188  
   2.189 +//////////////////////////////////////////////////////////////////////////
   2.190 +// SetOverrideRet for recalls
   2.191 +// These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
   2.192 +// The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
   2.193 +// (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
   2.194 +
   2.195 +namespace SourceHook
   2.196 +{
   2.197 +@VARARGS@
   2.198 +	template <class Iface, class RetType@, class Param%%@>
   2.199 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(@Param%%|, @), const RetType res)
   2.200 +	{
   2.201 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   2.202 +	}
   2.203 +@ENDARGS@
   2.204 +}
   2.205 +
   2.206  #endif
   2.207  	// The pope is dead. -> :(
     3.1 --- a/sourcehook/sh_stack.h	Thu Dec 22 21:00:54 2005 +0000
     3.2 +++ b/sourcehook/sh_stack.h	Fri Dec 23 11:58:11 2005 +0000
     3.3 @@ -174,6 +174,16 @@
     3.4  			return m_Elements[m_UsedSize - 1];
     3.5  		}
     3.6  
     3.7 +		T &second()
     3.8 +		{
     3.9 +			return m_Elements[m_UsedSize - 2];
    3.10 +		}
    3.11 +
    3.12 +		const T &second() const
    3.13 +		{
    3.14 +			return m_Elements[m_UsedSize - 2];
    3.15 +		}
    3.16 +
    3.17  		iterator begin()
    3.18  		{
    3.19  			return iterator(this, 0);
     4.1 --- a/sourcehook/sourcehook.cpp	Thu Dec 22 21:00:54 2005 +0000
     4.2 +++ b/sourcehook/sourcehook.cpp	Fri Dec 23 11:58:11 2005 +0000
     4.3 @@ -627,6 +627,7 @@
     4.4  		HookLoopInfo hli;
     4.5  		hli.pCurIface = pIface;
     4.6  		hli.shouldContinue = true;
     4.7 +		hli.recall = false;
     4.8  		m_HLIStack.push(hli);
     4.9  	}
    4.10  
    4.11 @@ -657,6 +658,20 @@
    4.12  
    4.13  	const void *CSourceHookImpl::GetOverrideRet()
    4.14  	{
    4.15 +		// pOverrideRet is always set since recalls were introduced
    4.16 +		// GetOverrideRetPtr was added; a function which always returns pOverrideRet
    4.17 +		// so that RETURN_META_VALUE_NEWPARAMS can provide an override result
    4.18 +
    4.19 +		// This means that we have to filter GetOverrideRet:
    4.20 +		//  If the status variable is < MRES_OVERRIDE, return NULL.
    4.21 +
    4.22 +		return (*m_HLIStack.front().pStatus < MRES_OVERRIDE) ?
    4.23 +			NULL : m_HLIStack.front().pOverrideRet;
    4.24 +	}
    4.25 +
    4.26 +	void *CSourceHookImpl::GetOverrideRetPtr()
    4.27 +	{
    4.28 +		// As described in the comment above: always return pOverrideRet
    4.29  		return m_HLIStack.front().pOverrideRet;
    4.30  	}
    4.31  
    4.32 @@ -673,11 +688,19 @@
    4.33  	void CSourceHookImpl::SetPrevResPtr(META_RES *mres)
    4.34  	{
    4.35  		m_HLIStack.front().pPrevRes = mres;
    4.36 +
    4.37 +		// If we're recalling, drag the previous mres value to the new hookfunc
    4.38 +		if (m_HLIStack.size() > 1 && m_HLIStack.second().recall)
    4.39 +			*mres = *m_HLIStack.second().pPrevRes;
    4.40  	}
    4.41  
    4.42  	void CSourceHookImpl::SetStatusPtr(META_RES *mres)
    4.43  	{
    4.44  		m_HLIStack.front().pStatus = mres;
    4.45 +
    4.46 +		// If we're recalling, drag the previous mres value to the new hookfunc
    4.47 +		if (m_HLIStack.size() > 1 && m_HLIStack.second().recall)
    4.48 +			*mres = *m_HLIStack.second().pStatus;
    4.49  	}
    4.50  
    4.51  	void CSourceHookImpl::SetIfacePtrPtr(void **pp)
    4.52 @@ -689,13 +712,61 @@
    4.53  	{
    4.54  		m_HLIStack.front().pOrigRet = ptr;
    4.55  	}
    4.56 -	void CSourceHookImpl::SetOverrideRetPtr(const void *ptr)
    4.57 +	void CSourceHookImpl::SetOverrideRetPtr(void *ptr)
    4.58  	{
    4.59  		m_HLIStack.front().pOverrideRet = ptr;
    4.60  	}
    4.61 +
    4.62 +	// New function which does all of the above + more :)
    4.63 +	void *CSourceHookImpl::SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
    4.64 +		void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr)
    4.65 +	{
    4.66 +		HookLoopInfo &hli = m_HLIStack.front();
    4.67 +		hli.pStatus = statusPtr;
    4.68 +		hli.pPrevRes = prevResPtr;
    4.69 +		hli.pCurRes = curResPtr;
    4.70 +		hli.pIfacePtrPtr = ifacePtrPtr;
    4.71 +		hli.pOrigRet = origRetPtr;
    4.72 +
    4.73 +		// Handle some recall stuff
    4.74 +		if (m_HLIStack.size() > 1 && m_HLIStack.second().recall)
    4.75 +		{
    4.76 +			HookLoopInfo &other = m_HLIStack.second();
    4.77 +			*statusPtr = *other.pStatus;
    4.78 +			*prevResPtr = *other.pStatus;
    4.79 +			hli.pOverrideRet = other.pOverrideRet;
    4.80 +		}
    4.81 +		else
    4.82 +			hli.pOverrideRet = overrideRetPtr;
    4.83 +
    4.84 +		// Tell the hook func which override ret ptr to use
    4.85 +		return hli.pOverrideRet;
    4.86 +	}
    4.87 +
    4.88  	bool CSourceHookImpl::ShouldContinue()
    4.89  	{
    4.90 -		return m_HLIStack.front().shouldContinue;
    4.91 +		// If recall is true, we shall not continue either.
    4.92 +		// This is because, if it's true and ShouldContinue is called, it suggests that the
    4.93 +		// actual recall is done and that we are back in the original handler which shall return
    4.94 +		// immediately.
    4.95 +
    4.96 +		return m_HLIStack.front().shouldContinue && !m_HLIStack.front().recall;
    4.97 +	}
    4.98 +
    4.99 +	void CSourceHookImpl::DoRecall()
   4.100 +	{
   4.101 +		if (!m_HLIStack.empty())
   4.102 +		{
   4.103 +			m_HLIStack.front().recall = true;
   4.104 +			CHookList *mlist = static_cast<CHookList*>(m_HLIStack.front().pCurIface->GetPreHooks());
   4.105 +			mlist->m_Recall = true;
   4.106 +
   4.107 +			// The hookfunc usually do this, but it won't have a chance to see it, 
   4.108 +			// so for recalls, we update status here if it's required
   4.109 +			if (*m_HLIStack.front().pCurRes > *m_HLIStack.front().pStatus) 
   4.110 +				*m_HLIStack.front().pStatus = *m_HLIStack.front().pCurRes;
   4.111 +
   4.112 +		}
   4.113  	}
   4.114  
   4.115  	////////////////////////////
   4.116 @@ -897,12 +968,15 @@
   4.117  	// CHookList
   4.118  	////////////////////////////
   4.119  
   4.120 -	CSourceHookImpl::CHookList::CHookList() : m_FreeIters(NULL), m_UsedIters(NULL)
   4.121 +	CSourceHookImpl::CHookList::CHookList() : m_FreeIters(NULL), m_UsedIters(NULL),
   4.122 +		m_Recall(false)
   4.123  	{
   4.124  	}
   4.125 -	CSourceHookImpl::CHookList::CHookList(const CHookList &other) : m_List(other.m_List), m_FreeIters(NULL), m_UsedIters(NULL)
   4.126 +	CSourceHookImpl::CHookList::CHookList(const CHookList &other) : m_List(other.m_List),
   4.127 +		m_FreeIters(NULL), m_UsedIters(NULL), m_Recall(false)
   4.128  	{
   4.129  	}
   4.130 +
   4.131  	CSourceHookImpl::CHookList::~CHookList()
   4.132  	{
   4.133  		while (m_FreeIters)
   4.134 @@ -932,12 +1006,22 @@
   4.135  			ret = new CIter(this);
   4.136  		}
   4.137  		
   4.138 +		// Muuuh, if we're recalling, it shall be a copy of the last iterator, incremented by one
   4.139 +		if (m_Recall && m_UsedIters)
   4.140 +		{
   4.141 +			ret->Set(m_UsedIters);		// m_UsedIters is the last returned and not released iterator
   4.142 +			ret->Next();				// Use next instead of directly incrementing its m_Iter:
   4.143 +										// skips paused plugins
   4.144 +		}
   4.145 +
   4.146  		ret->m_pNext = m_UsedIters;
   4.147  		ret->m_pPrev = NULL;
   4.148  		if (m_UsedIters)
   4.149  			m_UsedIters->m_pPrev = ret;
   4.150  		m_UsedIters = ret;
   4.151  
   4.152 +		m_Recall = false;
   4.153 +
   4.154  		return ret;
   4.155  	}
   4.156  	void CSourceHookImpl::CHookList::ReleaseIter(IIter *pIter)
   4.157 @@ -958,6 +1042,9 @@
   4.158  		pIter2->m_pNext = m_FreeIters;
   4.159  
   4.160  		m_FreeIters = pIter2;
   4.161 +
   4.162 +		// Reset recall state.
   4.163 +		m_Recall = false;
   4.164  	}
   4.165  
   4.166  	CSourceHookImpl::CHookList::CIter::CIter(CHookList *pList) : m_pList(pList), m_pNext(NULL)
   4.167 @@ -968,6 +1055,11 @@
   4.168  	{
   4.169  	}
   4.170  
   4.171 +	void CSourceHookImpl::CHookList::CIter::Set(CIter *pOther)
   4.172 +	{
   4.173 +		m_Iter = pOther->m_Iter;
   4.174 +	}
   4.175 +
   4.176  	void CSourceHookImpl::CHookList::CIter::GoToBegin()
   4.177  	{
   4.178  		m_Iter = m_pList->m_List.begin();
     5.1 --- a/sourcehook/sourcehook.h	Thu Dec 22 21:00:54 2005 +0000
     5.2 +++ b/sourcehook/sourcehook.h	Fri Dec 23 11:58:11 2005 +0000
     5.3 @@ -372,7 +372,7 @@
     5.4  		virtual void SetStatusPtr(META_RES *mres) = 0;			//!< Sets pointer to the status variable
     5.5  		virtual void SetIfacePtrPtr(void **pp) = 0;				//!< Sets pointer to the interface this pointer
     5.6  		virtual void SetOrigRetPtr(const void *ptr) = 0;		//!< Sets the original return pointer
     5.7 -		virtual void SetOverrideRetPtr(const void *ptr) = 0;	//!< Sets the override result pointer
     5.8 +		virtual void SetOverrideRetPtr(void *ptr) = 0;			//!< Sets the override result pointer
     5.9  		virtual bool ShouldContinue() = 0;						//!< Returns false if the hook loop should exit
    5.10  
    5.11  		/**
    5.12 @@ -382,22 +382,89 @@
    5.13  		*   @param pubFunc The hook manager's info function
    5.14  		*/
    5.15  		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
    5.16 +
    5.17 +		virtual void DoRecall() = 0;							//!< Initiates a recall sequence
    5.18 +		/*
    5.19 +			HOW RECALLS WORK:
    5.20 +			
    5.21 +			The problem:
    5.22 +				Users want the ability to change parameters of the called function
    5.23 +				from inside their handler.
    5.24 +			The solution:
    5.25 +				1) Mark as "recall"
    5.26 +				2) Recall the function
    5.27 +				3) => SH's hook func gets called:
    5.28 +				  4) The first iterator points at the first hook the last hookfunc didn't execute yet
    5.29 +				  5) does all iteration and returns normally
    5.30 +		        6) The user's handler returns immediately
    5.31 +				7) The hook func returns immediately as well
    5.32 +
    5.33 +				Also note that the recalled hookfunc starts with the status the recalling hookfunc
    5.34 +				ended with. The last handler (doing the recall) is also able to specify its own
    5.35 +				META_RES.
    5.36 +		*/
    5.37 +
    5.38 +		virtual void *GetOverrideRetPtr() = 0;		//!< Returns the pointer set by SetOverrideRetPtr
    5.39 +
    5.40 +		/**
    5.41 +		*	@brief Set up the hook loop. Equivalent to calling:
    5.42 +		*	SetStatusPtr, SetPrevResPtr, SetCurResPtr, SetIfacePtrPtr, SetOrigRetPtr, Get/SetOverrideRetPtr
    5.43 +		*
    5.44 +		*	@param statusPtr		pointer to status variable
    5.45 +		*	@param prevResPtr		pointer to previous result variable
    5.46 +		*	@param curResPtr		pointer to current result variable
    5.47 +		*	@param ifacePtrPtr		pointer to interface this pointer variable
    5.48 +		*	@param origRetPr		pointer to original return value variable. NULL for void funcs
    5.49 +		*	@param overrideRetPtr	pointer to override return value variable. NULL for void funcs
    5.50 +		*	
    5.51 +		*	@return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
    5.52 +		*		when the hook func is being called as part of a recall
    5.53 +		*/
    5.54 +		virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
    5.55 +			void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr) = 0;
    5.56  	};
    5.57  }
    5.58  
    5.59  /************************************************************************/
    5.60  /* High level interface                                                 */
    5.61  /************************************************************************/
    5.62 -#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    5.63 -#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    5.64 -#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    5.65 -
    5.66  #define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
    5.67  #define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
    5.68  #define META_RESULT_ORIG_RET(type)			*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOrigRet())
    5.69  #define META_RESULT_OVERRIDE_RET(type)		*reinterpret_cast<const type*>(SH_GLOB_SHPTR->GetOverrideRet())
    5.70  #define META_IFACEPTR(type)					reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
    5.71  
    5.72 +#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
    5.73 +#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
    5.74 +#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
    5.75 +
    5.76 +
    5.77 +// NEVER-EVER call these from post hooks!
    5.78 +// also, only call it from the hook handlers directly!
    5.79 +// :TODO: enforce it
    5.80 +// :TODO: problems with SetOverrideResult and overloaded iface::func ?
    5.81 +
    5.82 +// SourceHook::SetOverrideRet is defined later.
    5.83 +#define RETURN_META_NEWPARAMS(result, iface, func, newparams) \
    5.84 +	do { \
    5.85 +		SET_META_RESULT(result); \
    5.86 +		SH_GLOB_SHPTR->DoRecall(); \
    5.87 +		META_IFACEPTR(iface)->func newparams; \
    5.88 +		RETURN_META(MRES_SUPERCEDE); \
    5.89 +	} while (0)
    5.90 +
    5.91 +#define RETURN_META_VALUE_NEWPARAMS(result, value, iface, func, newparams) \
    5.92 +	do { \
    5.93 +		SET_META_RESULT(result); \
    5.94 +		SH_GLOB_SHPTR->DoRecall(); \
    5.95 +		if ((result) >= MRES_OVERRIDE) \
    5.96 +		{ \
    5.97 +			/* meh, set the override result here because we don't get a chance to return */ \
    5.98 +			/* before continuing the hook loop through the recall */ \
    5.99 +			SourceHook::SetOverrideResult(SH_GLOB_SHPTR, &iface::func, value); \
   5.100 +		} \
   5.101 +		RETURN_META_VALUE(MRES_SUPERCEDE, META_IFACEPTR(iface)->func newparams); \
   5.102 +	} while (0)
   5.103  
   5.104  /**
   5.105  *	@brief Get/generate callclass for an interface pointer
   5.106 @@ -542,8 +609,8 @@
   5.107  		using namespace ::SourceHook; \
   5.108  		MemFuncInfo mfi; \
   5.109  		GetFuncInfo(funcptr, mfi); \
   5.110 -		if (mfi.thisptroffs < 0) \
   5.111 -			return false; /* No virtual inheritance supported */ \
   5.112 +		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   5.113 +			return false; /* No non-virtual functions / virtual inheritance supported */ \
   5.114  		\
   5.115  		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
   5.116  			SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   5.117 @@ -659,16 +726,12 @@
   5.118  	META_RES status = MRES_IGNORED; \
   5.119  	META_RES prev_res; \
   5.120  	META_RES cur_res; \
   5.121 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   5.122 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   5.123 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   5.124  	rettype orig_ret; \
   5.125  	rettype override_ret; \
   5.126  	rettype plugin_ret; \
   5.127  	void* ifptr; \
   5.128 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   5.129 -	SH_GLOB_SHPTR->SetOrigRetPtr(reinterpret_cast<void*>(&orig_ret)); \
   5.130 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL);
   5.131 +	rettype *pOverrideRet = reinterpret_cast<rettype*>(SH_GLOB_SHPTR->SetupHookLoop( \
   5.132 +		&status, &prev_res, &cur_res, &ifptr, &orig_ret, &override_ret));
   5.133  
   5.134  #define SH_CALL_HOOKS(post, params) \
   5.135  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   5.136 @@ -683,10 +746,7 @@
   5.137  			if (cur_res > status) \
   5.138  				status = cur_res; \
   5.139  			if (cur_res >= MRES_OVERRIDE) \
   5.140 -			{ \
   5.141 -				override_ret = plugin_ret; \
   5.142 -				SH_GLOB_SHPTR->SetOverrideRetPtr(&override_ret); \
   5.143 -			} \
   5.144 +				*pOverrideRet = plugin_ret; \
   5.145  			if (!SH_GLOB_SHPTR->ShouldContinue()) \
   5.146  			{ \
   5.147  				iter.SetToZero(); \
   5.148 @@ -703,11 +763,11 @@
   5.149  		orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
   5.150  	} \
   5.151  	else \
   5.152 -		orig_ret = override_ret;
   5.153 +		orig_ret = override_ret; \
   5.154  
   5.155  #define SH_RETURN() \
   5.156  	SH_GLOB_SHPTR->HookLoopEnd(); \
   5.157 -	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   5.158 +	return status >= MRES_OVERRIDE ? *pOverrideRet : orig_ret;
   5.159  
   5.160  #define SH_HANDLEFUNC(paramtypes, params, rettype) \
   5.161  	SH_SETUPCALLS(rettype, paramtypes, params) \
   5.162 @@ -743,13 +803,8 @@
   5.163  	META_RES status = MRES_IGNORED; \
   5.164  	META_RES prev_res; \
   5.165  	META_RES cur_res; \
   5.166 -	SH_GLOB_SHPTR->SetStatusPtr(&status); \
   5.167 -	SH_GLOB_SHPTR->SetPrevResPtr(&prev_res); \
   5.168 -	SH_GLOB_SHPTR->SetCurResPtr(&cur_res); \
   5.169  	void* ifptr; \
   5.170 -	SH_GLOB_SHPTR->SetIfacePtrPtr(&ifptr); \
   5.171 -	SH_GLOB_SHPTR->SetOverrideRetPtr(NULL); \
   5.172 -	SH_GLOB_SHPTR->SetOrigRetPtr(NULL);
   5.173 +	SH_GLOB_SHPTR->SetupHookLoop(&status, &prev_res, &cur_res, &ifptr, NULL, NULL); \
   5.174  
   5.175  #define SH_CALL_HOOKS_void(post, params) \
   5.176  	if (SH_GLOB_SHPTR->ShouldContinue()) \
   5.177 @@ -791,6 +846,7 @@
   5.178  
   5.179  
   5.180  // Special vafmt handlers
   5.181 +// :TODO: what
   5.182  #define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
   5.183  	SH_SETUPCALLS(rettype, paramtypes, params_orig) \
   5.184  	SH_CALL_HOOKS(pre, params_plug) \
   5.185 @@ -3497,6 +3553,121 @@
   5.186  
   5.187  #undef SH_MAKE_EXECUTABLECLASS_OB
   5.188  
   5.189 +//////////////////////////////////////////////////////////////////////////
   5.190 +// SetOverrideRet for recalls
   5.191 +// These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
   5.192 +// The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
   5.193 +// (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
   5.194 +
   5.195 +namespace SourceHook
   5.196 +{
   5.197 +	template <class Iface, class RetType>
   5.198 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(), const RetType res)
   5.199 +	{
   5.200 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.201 +	}
   5.202 +	template <class Iface, class RetType, class Param1>
   5.203 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1), const RetType res)
   5.204 +	{
   5.205 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.206 +	}
   5.207 +	template <class Iface, class RetType, class Param1, class Param2>
   5.208 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2), const RetType res)
   5.209 +	{
   5.210 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.211 +	}
   5.212 +	template <class Iface, class RetType, class Param1, class Param2, class Param3>
   5.213 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3), const RetType res)
   5.214 +	{
   5.215 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.216 +	}
   5.217 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
   5.218 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4), const RetType res)
   5.219 +	{
   5.220 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.221 +	}
   5.222 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
   5.223 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5), const RetType res)
   5.224 +	{
   5.225 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.226 +	}
   5.227 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
   5.228 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6), const RetType res)
   5.229 +	{
   5.230 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.231 +	}
   5.232 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
   5.233 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7), const RetType res)
   5.234 +	{
   5.235 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.236 +	}
   5.237 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
   5.238 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8), const RetType res)
   5.239 +	{
   5.240 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.241 +	}
   5.242 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
   5.243 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9), const RetType res)
   5.244 +	{
   5.245 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.246 +	}
   5.247 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
   5.248 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10), const RetType res)
   5.249 +	{
   5.250 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.251 +	}
   5.252 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
   5.253 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11), const RetType res)
   5.254 +	{
   5.255 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.256 +	}
   5.257 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
   5.258 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12), const RetType res)
   5.259 +	{
   5.260 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.261 +	}
   5.262 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
   5.263 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13), const RetType res)
   5.264 +	{
   5.265 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.266 +	}
   5.267 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
   5.268 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14), const RetType res)
   5.269 +	{
   5.270 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.271 +	}
   5.272 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
   5.273 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15), const RetType res)
   5.274 +	{
   5.275 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.276 +	}
   5.277 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
   5.278 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16), const RetType res)
   5.279 +	{
   5.280 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.281 +	}
   5.282 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17>
   5.283 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17), const RetType res)
   5.284 +	{
   5.285 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.286 +	}
   5.287 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18>
   5.288 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18), const RetType res)
   5.289 +	{
   5.290 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.291 +	}
   5.292 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18, class Param19>
   5.293 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18, Param19), const RetType res)
   5.294 +	{
   5.295 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.296 +	}
   5.297 +	template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16, class Param17, class Param18, class Param19, class Param20>
   5.298 +	void SetOverrideResult(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, Param17, Param18, Param19, Param20), const RetType res)
   5.299 +	{
   5.300 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
   5.301 +	}
   5.302 +}
   5.303 +
   5.304  #endif
   5.305  	// The pope is dead. -> :(
   5.306  
     6.1 --- a/sourcehook/sourcehook_impl.h	Thu Dec 22 21:00:54 2005 +0000
     6.2 +++ b/sourcehook/sourcehook_impl.h	Fri Dec 23 11:58:11 2005 +0000
     6.3 @@ -76,6 +76,7 @@
     6.4  				virtual ~CIter();
     6.5  
     6.6  				void GoToBegin();
     6.7 +				void Set(CIter *pOther);
     6.8  
     6.9  				bool End();
    6.10  				void Next();
    6.11 @@ -89,7 +90,16 @@
    6.12  			};
    6.13  
    6.14  			CIter *m_FreeIters;
    6.15 -			CIter *m_UsedIters;
    6.16 +			CIter *m_UsedIters;		// The last returned and not-yet-released iter is always m_UsedIters
    6.17 +
    6.18 +			// For recalls
    6.19 +			bool m_Recall;
    6.20 +
    6.21 +			void SetRecallState();	// Sets the list into a state where the next returned
    6.22 +									// iterator (from GetIter) will be a copy of the last
    6.23 +									// returned iterator, incremented by one. This is used in Recalls.
    6.24 +									// The hook resets this state automatically on:
    6.25 +									// GetIter, ReleaseIter
    6.26  
    6.27  			CHookList();
    6.28  			CHookList(const CHookList &other);
    6.29 @@ -165,6 +175,8 @@
    6.30  
    6.31  			VfnPtrList m_VfnPtrs;
    6.32  
    6.33 +			int m_HookFuncVersion;
    6.34 +
    6.35  		public:
    6.36  			virtual ~CHookManagerInfo();
    6.37  
    6.38 @@ -221,10 +233,11 @@
    6.39  			META_RES *pCurRes;
    6.40  
    6.41  			bool shouldContinue;
    6.42 +			bool recall;							//!< True if we're in a recall, eh.
    6.43  
    6.44  			IIface *pCurIface;
    6.45  			const void *pOrigRet;
    6.46 -			const void *pOverrideRet;
    6.47 +			void *pOverrideRet;
    6.48  			void **pIfacePtrPtr;
    6.49  		};
    6.50  		typedef CStack<HookLoopInfo> HookLoopInfoStack;
    6.51 @@ -357,7 +370,7 @@
    6.52  		void SetStatusPtr(META_RES *mres);			//!< Sets pointer to the status variable
    6.53  		void SetIfacePtrPtr(void **pp);				//!< Sets pointer to the interface this pointer
    6.54  		void SetOrigRetPtr(const void *ptr);		//!< Sets the original return pointer
    6.55 -		void SetOverrideRetPtr(const void *ptr);	//!< Sets the override result pointer
    6.56 +		void SetOverrideRetPtr(void *ptr);			//!< Sets the override result pointer
    6.57  		bool ShouldContinue();						//!< Returns false if the hook loop should exit
    6.58  
    6.59  		/**
    6.60 @@ -367,6 +380,11 @@
    6.61  		*   @param pubFunc The hook manager's info function
    6.62  		*/
    6.63  		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
    6.64 +		virtual void DoRecall();					//!< Initiates a recall sequence
    6.65 +		virtual void *GetOverrideRetPtr();			//!< Returns the pointer set by SetOverrideRetPtr
    6.66 +
    6.67 +		virtual void *SetupHookLoop(META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
    6.68 +			void **ifacePtrPtr, const void *origRetPtr, void *overrideRetPtr);
    6.69  	};
    6.70  }
    6.71  
     7.1 --- a/sourcehook/test/main.cpp	Thu Dec 22 21:00:54 2005 +0000
     7.2 +++ b/sourcehook/test/main.cpp	Fri Dec 23 11:58:11 2005 +0000
     7.3 @@ -2,6 +2,7 @@
     7.4  //   hello pm how are you
     7.5  //    I'm fine, what about you?
     7.6  //     not bad, just looking for mem leaks
     7.7 +//      mem leaks in my code!? never! I have to preserve binary compatibility :(
     7.8  // This is a test file
     7.9  
    7.10  #include <stdio.h>
    7.11 @@ -75,6 +76,7 @@
    7.12  DO_TEST(Bail);
    7.13  DO_TEST(Reentr);
    7.14  DO_TEST(Manual);
    7.15 +DO_TEST(Recall);
    7.16  
    7.17  int main(int argc, char *argv[])
    7.18  {
    7.19 @@ -90,3 +92,37 @@
    7.20  	cin.read(&x, 1);
    7.21  }
    7.22  
    7.23 +SourceHook::ISourceHook *Test_Factory()
    7.24 +{
    7.25 +	return new SourceHook::CSourceHookImpl();
    7.26 +}
    7.27 +
    7.28 +void Test_Delete(SourceHook::ISourceHook *shptr)
    7.29 +{
    7.30 +	delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
    7.31 +}
    7.32 +
    7.33 +void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
    7.34 +{
    7.35 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
    7.36 +}
    7.37 +
    7.38 +bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
    7.39 +{
    7.40 +	return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
    7.41 +}
    7.42 +
    7.43 +void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
    7.44 +{
    7.45 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
    7.46 +}
    7.47 +
    7.48 +void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
    7.49 +{
    7.50 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
    7.51 +}
    7.52 +
    7.53 +void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
    7.54 +{
    7.55 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
    7.56 +}
    7.57 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/sourcehook/test/sourcehook_test.h	Fri Dec 23 11:58:11 2005 +0000
     8.3 @@ -0,0 +1,27 @@
     8.4 +// This file is used for backwards compatibility testing
     8.5 +// It allows us to test binary backwards compatibility by using an older include file HERE:
     8.6 +#include "sourcehook.h"			// <-- here
     8.7 +// There. main.cpp which implements all of the following function is always usign sourcehook.h
     8.8 +// and the up-to-date sourcehook_impl.h/sourcehook.cpp. The tests use this file however.
     8.9 +// If the test needs an up-to-date version (like the recall test), it can simply
    8.10 +// #include "sourcehook.h" before including this, thus overriding our decision.
    8.11 +
    8.12 +
    8.13 +SourceHook::ISourceHook *Test_Factory();
    8.14 +void Test_Delete(SourceHook::ISourceHook *shptr);
    8.15 +
    8.16 +struct CSHPtrAutoDestruction
    8.17 +{
    8.18 +	SourceHook::ISourceHook *m_SHPtr;
    8.19 +	CSHPtrAutoDestruction(SourceHook::ISourceHook *shptr) : m_SHPtr(shptr) {}
    8.20 +	~CSHPtrAutoDestruction() { Test_Delete(m_SHPtr); }
    8.21 +};
    8.22 +
    8.23 +#define GET_SHPTR(var) var = Test_Factory(); CSHPtrAutoDestruction ___autodestruction(var);
    8.24 +
    8.25 +// Access to CSourceHookImpl functions
    8.26 +void Test_CompleteShutdown(SourceHook::ISourceHook *shptr);
    8.27 +bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
    8.28 +void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
    8.29 +void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
    8.30 +void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
     9.1 --- a/sourcehook/test/test.vcproj	Thu Dec 22 21:00:54 2005 +0000
     9.2 +++ b/sourcehook/test/test.vcproj	Fri Dec 23 11:58:11 2005 +0000
     9.3 @@ -263,6 +263,9 @@
     9.4  				RelativePath=".\testbail.cpp">
     9.5  			</File>
     9.6  			<File
     9.7 +				RelativePath=".\testbail.h">
     9.8 +			</File>
     9.9 +			<File
    9.10  				RelativePath=".\testbail2.cpp">
    9.11  			</File>
    9.12  			<File
    9.13 @@ -278,6 +281,9 @@
    9.14  				</FileConfiguration>
    9.15  			</File>
    9.16  			<File
    9.17 +				RelativePath=".\testrecall.cpp">
    9.18 +			</File>
    9.19 +			<File
    9.20  				RelativePath=".\testreentr.cpp">
    9.21  			</File>
    9.22  		</Filter>
    9.23 @@ -306,6 +312,9 @@
    9.24  				RelativePath="..\sourcehook_impl.h">
    9.25  			</File>
    9.26  			<File
    9.27 +				RelativePath=".\sourcehook_test.h">
    9.28 +			</File>
    9.29 +			<File
    9.30  				RelativePath="testevents.h">
    9.31  			</File>
    9.32  			<Filter
    10.1 --- a/sourcehook/test/test1.cpp	Thu Dec 22 21:00:54 2005 +0000
    10.2 +++ b/sourcehook/test/test1.cpp	Fri Dec 23 11:58:11 2005 +0000
    10.3 @@ -1,5 +1,5 @@
    10.4  #include <string>
    10.5 -#include "sourcehook_impl.h"
    10.6 +#include "sourcehook_test.h"
    10.7  #include "testevents.h"
    10.8  
    10.9  #include "sh_memory.h"
   10.10 @@ -92,7 +92,7 @@
   10.11  		virtual void F57(){}
   10.12  		virtual void F58(){}
   10.13  		virtual void F59(){}
   10.14 -		virtual void F60(){}
   10.15 +		virtual void F60(int &hello){}
   10.16  		virtual void F61(){}
   10.17  		virtual void F62(){}
   10.18  		virtual void F63(){}
   10.19 @@ -350,6 +350,8 @@
   10.20  	SH_DECL_HOOK0_void(Test, F9, SH_NOATTRIB, 0);
   10.21  	SH_DECL_HOOK0_void(Test, F10, SH_NOATTRIB, 0);
   10.22  
   10.23 +	SH_DECL_HOOK1_void(Test, F60, SH_NOATTRIB, 0, int&);
   10.24 +
   10.25  	META_RES g_F1Pre_WhatToDo;
   10.26  	META_RES g_F1Post_WhatToDo;
   10.27  
   10.28 @@ -384,8 +386,18 @@
   10.29  			!META_RESULT_ORIG_RET(bool));
   10.30  	}
   10.31  
   10.32 +	void F60_Pre(int &hello)
   10.33 +	{
   10.34 +		hello = 10;
   10.35 +	}
   10.36  }
   10.37  
   10.38 +template <class T> T func(T a)
   10.39 +{
   10.40 +	return a;
   10.41 +}
   10.42 +
   10.43 +
   10.44  bool TestBasic(std::string &error)
   10.45  {
   10.46  	// Simple test for ModuleInMemory
   10.47 @@ -399,8 +411,7 @@
   10.48  		new State_ModuleInMemory(false),
   10.49  		NULL), "ModuleInMemory");
   10.50  
   10.51 -	SourceHook::CSourceHookImpl g_SHImpl;
   10.52 -	g_SHPtr = &g_SHImpl;
   10.53 +	GET_SHPTR(g_SHPtr);
   10.54  	g_PLID = 1337;
   10.55  
   10.56  	HandlersF1 f1_handlers;
   10.57 @@ -676,7 +687,13 @@
   10.58  	SH_REMOVE_HOOK_MEMFUNC(Test, F9, pTest, &f1_handlers, &HandlersF1::Pre, false);
   10.59  	SH_REMOVE_HOOK_MEMFUNC(Test, F10, pTest, &f1_handlers, &HandlersF1::Pre, false);
   10.60  
   10.61 -	g_SHImpl.CompleteShutdown();
   10.62 +	SH_ADD_HOOK_STATICFUNC(Test, F60, pTest, F60_Pre, false);
   10.63 +
   10.64 +	int a = 0;
   10.65 +	pTest->F60(a);
   10.66 +	Test_CompleteShutdown(g_SHPtr);
   10.67 +
   10.68 +	CHECK_COND(a == 10, "Part12.a");
   10.69  
   10.70  	return true;
   10.71  }
    11.1 --- a/sourcehook/test/test2.cpp	Thu Dec 22 21:00:54 2005 +0000
    11.2 +++ b/sourcehook/test/test2.cpp	Fri Dec 23 11:58:11 2005 +0000
    11.3 @@ -1,5 +1,5 @@
    11.4  #include <string>
    11.5 -#include "sourcehook_impl.h"
    11.6 +#include "sourcehook_test.h"
    11.7  #include "testevents.h"
    11.8  #include <stdarg.h>
    11.9  
   11.10 @@ -89,8 +89,7 @@
   11.11  
   11.12  bool TestVafmtAndOverload(std::string &error)
   11.13  {
   11.14 -	SourceHook::CSourceHookImpl g_SHImpl;
   11.15 -	g_SHPtr = &g_SHImpl;
   11.16 +	GET_SHPTR(g_SHPtr);
   11.17  	g_PLID = 1337;	
   11.18  
   11.19  	IGaben gabgab;
    12.1 --- a/sourcehook/test/test3.cpp	Thu Dec 22 21:00:54 2005 +0000
    12.2 +++ b/sourcehook/test/test3.cpp	Fri Dec 23 11:58:11 2005 +0000
    12.3 @@ -1,5 +1,5 @@
    12.4  #include <string>
    12.5 -#include "sourcehook_impl.h"
    12.6 +#include "sourcehook_test.h"
    12.7  #include "testevents.h"
    12.8  
    12.9  // TEST3
   12.10 @@ -69,8 +69,7 @@
   12.11  
   12.12  bool TestThisPtrOffs(std::string &error)
   12.13  {
   12.14 -	SourceHook::CSourceHookImpl g_SHImpl;
   12.15 -	g_SHPtr = &g_SHImpl;
   12.16 +	GET_SHPTR(g_SHPtr);
   12.17  	g_PLID = 1337;
   12.18  
   12.19  	Derived inst;
    13.1 --- a/sourcehook/test/test4.cpp	Thu Dec 22 21:00:54 2005 +0000
    13.2 +++ b/sourcehook/test/test4.cpp	Fri Dec 23 11:58:11 2005 +0000
    13.3 @@ -1,5 +1,5 @@
    13.4  #include <string>
    13.5 -#include "sourcehook_impl.h"
    13.6 +#include "sourcehook_test.h"
    13.7  #include "testevents.h"
    13.8  
    13.9  // TEST4
   13.10 @@ -60,8 +60,7 @@
   13.11  
   13.12  bool TestPlugSys(std::string &error)
   13.13  {
   13.14 -	SourceHook::CSourceHookImpl g_SHImpl;
   13.15 -	g_SHPtr = &g_SHImpl;
   13.16 +	GET_SHPTR(g_SHPtr);
   13.17  	g_PLID = 1;
   13.18  
   13.19  	Test inst;
   13.20 @@ -86,7 +85,7 @@
   13.21  		new State_Func3_Called,
   13.22  		NULL), "Part 1.1");
   13.23  
   13.24 -	g_SHImpl.CompleteShutdown();
   13.25 +	Test_CompleteShutdown(g_SHPtr);
   13.26  
   13.27  	pInst->Func1();
   13.28  	pInst->Func2();
   13.29 @@ -139,10 +138,10 @@
   13.30  		new State_Func3_Called,
   13.31  		NULL), "Part 2.1");
   13.32  
   13.33 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
   13.34 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
   13.35 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
   13.36 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
   13.37 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   13.38 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   13.39 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   13.40 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   13.41  
   13.42  	CHECK_STATES((&g_States,
   13.43  		new State_PluginInUse(1, true),
   13.44 @@ -152,7 +151,7 @@
   13.45  		NULL), "Part 2.2");
   13.46  
   13.47  	// Unload plugins one by one
   13.48 -	g_SHImpl.UnloadPlugin(3);
   13.49 +	Test_UnloadPlugin(g_SHPtr, 3);
   13.50  
   13.51  	pInst->Func1();
   13.52  	pInst->Func2();
   13.53 @@ -170,10 +169,10 @@
   13.54  		new State_Func3_Called,
   13.55  		NULL), "Part 2.3.1");
   13.56  
   13.57 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
   13.58 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
   13.59 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
   13.60 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
   13.61 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   13.62 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   13.63 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   13.64 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   13.65  
   13.66  	CHECK_STATES((&g_States,
   13.67  		new State_PluginInUse(1, true),
   13.68 @@ -182,7 +181,7 @@
   13.69  		new State_PluginInUse(4, false),
   13.70  		NULL), "Part 2.3.2");
   13.71  
   13.72 -	g_SHImpl.UnloadPlugin(2);
   13.73 +	Test_UnloadPlugin(g_SHPtr, 2);
   13.74  
   13.75  	pInst->Func1();
   13.76  	pInst->Func2();
   13.77 @@ -197,10 +196,10 @@
   13.78  		new State_Func3_Called,
   13.79  		NULL), "Part 2.4.1");
   13.80  
   13.81 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
   13.82 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
   13.83 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
   13.84 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
   13.85 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   13.86 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   13.87 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   13.88 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   13.89  
   13.90  	CHECK_STATES((&g_States,
   13.91  		new State_PluginInUse(1, true),
   13.92 @@ -209,7 +208,7 @@
   13.93  		new State_PluginInUse(4, false),
   13.94  		NULL), "Part 2.4.2");
   13.95  
   13.96 -	g_SHImpl.UnloadPlugin(1);
   13.97 +	Test_UnloadPlugin(g_SHPtr, 1);
   13.98  
   13.99  	pInst->Func1();
  13.100  	pInst->Func2();
  13.101 @@ -221,10 +220,10 @@
  13.102  		new State_Func3_Called,
  13.103  		NULL), "Part 2.5.1");
  13.104  
  13.105 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.106 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.107 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.108 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.109 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.110 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.111 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.112 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.113  
  13.114  	CHECK_STATES((&g_States,
  13.115  		new State_PluginInUse(1, false),
  13.116 @@ -275,10 +274,10 @@
  13.117  		new State_Func3_Called,
  13.118  		NULL), "Part 3.1");
  13.119  
  13.120 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.121 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.122 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.123 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.124 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.125 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.126 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.127 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.128  
  13.129  	CHECK_STATES((&g_States,
  13.130  		new State_PluginInUse(1, true),
  13.131 @@ -288,7 +287,7 @@
  13.132  		NULL), "Part 3.2");
  13.133  
  13.134  	// Unload plugins one by one
  13.135 -	g_SHImpl.PausePlugin(3);
  13.136 +	Test_PausePlugin(g_SHPtr, 3);
  13.137  
  13.138  	pInst->Func1();
  13.139  	pInst->Func2();
  13.140 @@ -306,10 +305,10 @@
  13.141  		new State_Func3_Called,
  13.142  		NULL), "Part 3.3.1");
  13.143  
  13.144 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.145 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.146 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.147 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.148 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.149 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.150 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.151 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.152  
  13.153  	CHECK_STATES((&g_States,
  13.154  		new State_PluginInUse(1, true),
  13.155 @@ -318,7 +317,7 @@
  13.156  		new State_PluginInUse(4, false),
  13.157  		NULL), "Part 3.3.2");
  13.158  
  13.159 -	g_SHImpl.PausePlugin(2);
  13.160 +	Test_PausePlugin(g_SHPtr, 2);
  13.161  
  13.162  	pInst->Func1();
  13.163  	pInst->Func2();
  13.164 @@ -333,10 +332,10 @@
  13.165  		new State_Func3_Called,
  13.166  		NULL), "Part 3.4.1");
  13.167  
  13.168 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.169 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.170 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.171 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.172 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.173 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.174 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.175 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.176  
  13.177  	CHECK_STATES((&g_States,
  13.178  		new State_PluginInUse(1, true),
  13.179 @@ -345,7 +344,7 @@
  13.180  		new State_PluginInUse(4, false),
  13.181  		NULL), "Part 3.4.2");
  13.182  
  13.183 -	g_SHImpl.PausePlugin(1);
  13.184 +	Test_PausePlugin(g_SHPtr, 1);
  13.185  
  13.186  	pInst->Func1();
  13.187  	pInst->Func2();
  13.188 @@ -357,10 +356,10 @@
  13.189  		new State_Func3_Called,
  13.190  		NULL), "Part 3.5.1");
  13.191  
  13.192 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.193 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.194 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.195 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.196 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.197 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.198 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.199 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.200  
  13.201  	CHECK_STATES((&g_States,
  13.202  		new State_PluginInUse(1, true),
  13.203 @@ -369,14 +368,14 @@
  13.204  		new State_PluginInUse(4, false),
  13.205  		NULL), "Part 3.5.2");
  13.206  
  13.207 -	g_SHImpl.UnpausePlugin(1);
  13.208 -	g_SHImpl.UnpausePlugin(2);
  13.209 -	g_SHImpl.UnpausePlugin(3);
  13.210 +	Test_UnpausePlugin(g_SHPtr, 1);
  13.211 +	Test_UnpausePlugin(g_SHPtr, 2);
  13.212 +	Test_UnpausePlugin(g_SHPtr, 3);
  13.213  
  13.214 -	ADD_STATE(State_PluginInUse(1, g_SHImpl.IsPluginInUse(1)));
  13.215 -	ADD_STATE(State_PluginInUse(2, g_SHImpl.IsPluginInUse(2)));
  13.216 -	ADD_STATE(State_PluginInUse(3, g_SHImpl.IsPluginInUse(3)));
  13.217 -	ADD_STATE(State_PluginInUse(4, g_SHImpl.IsPluginInUse(4)));
  13.218 +	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
  13.219 +	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
  13.220 +	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
  13.221 +	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
  13.222  
  13.223  	CHECK_STATES((&g_States,
  13.224  		new State_PluginInUse(1, true),
  13.225 @@ -405,7 +404,7 @@
  13.226  		NULL), "Part 3.7");
  13.227  
  13.228  	// 4) Shutdown :)
  13.229 -	g_SHImpl.CompleteShutdown();
  13.230 +	Test_CompleteShutdown(g_SHPtr);
  13.231  
  13.232  	pInst->Func1();
  13.233  	pInst->Func2();
    14.1 --- a/sourcehook/test/testbail.cpp	Thu Dec 22 21:00:54 2005 +0000
    14.2 +++ b/sourcehook/test/testbail.cpp	Fri Dec 23 11:58:11 2005 +0000
    14.3 @@ -1,74 +1,103 @@
    14.4  // TESTBAIL
    14.5 -// Test for a bug Bail has found
    14.6 +// This test used to be a test for a bug BAIL found.
    14.7 +// That bug is now fixed so I've granted BAIL the pleasure of being a test for
    14.8 +// the correct priority ordering of hook managers based on their version.
    14.9 +
   14.10 +/*
   14.11 +	THE PROBLEM:
   14.12 +		Old hook funcs don't work right when you combine override returns and recalls.
   14.13 +	THE SOLUTION:
   14.14 +		Always use a new hook func when possible. For this, hook funcs have to be able to say
   14.15 +			" HELLO I'M NEW! "
   14.16  
   14.17 +	This file tests that functionality.
   14.18 +
   14.19 +	How it works:
   14.20 +		testbail.cpp compiles with old version of sourcehook.h.
   14.21 +		It sets everything up, adds a hook on a function
   14.22 +		Then testbail2.cpp which has the new version adds a hook on the same function and 
   14.23 +		does a recall and overrides the value in it.
   14.24 +*/
   14.25 +
   14.26 +#include "sourcehook_test.h"
   14.27  #include "testbail.h"
   14.28  
   14.29  void *___testbail_gabgab;
   14.30 +SourceHook::ISourceHook *___testbail_shptr;
   14.31  
   14.32  namespace
   14.33  {
   14.34 -	class zomg_lolz
   14.35 +	int EatYams_Handler1(int a)
   14.36  	{
   14.37 -	public:
   14.38 -		virtual void zomg()
   14.39 -		{
   14.40 -		}
   14.41 -	};
   14.42 -	SH_DECL_HOOK0_void(zomg_lolz, zomg, SH_NOATTRIB, 0);
   14.43 -	void Handler()
   14.44 -	{
   14.45 -		SH_REMOVE_HOOK_STATICFUNC(zomg_lolz, zomg, META_IFACEPTR(zomg_lolz),
   14.46 -			Handler, false);
   14.47 +		ADD_STATE(State_EatYams_Handler1_Called(a));
   14.48 +		RETURN_META_VALUE(MRES_IGNORED, 0);
   14.49  	}
   14.50 -	void Handler2()
   14.51 -	{
   14.52 -	}
   14.53 +}
   14.54 +
   14.55 +// These are here so they can access this CU's g_States
   14.56 +int ___testbail_EatYams_Handler2(int a)
   14.57 +{
   14.58 +	ADD_STATE(State_EatYams_Handler2_Called(a));
   14.59 +	RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 6, IGaben, EatYams, (0xBEEF));
   14.60 +}
   14.61 +
   14.62 +int ___testbail_EatYams_Handler3(int a)
   14.63 +{
   14.64 +	ADD_STATE(State_EatYams_Handler3_Called(a));
   14.65 +	RETURN_META_VALUE(MRES_IGNORED, 0);
   14.66  }
   14.67  
   14.68  bool TestBail(std::string &error)
   14.69  {
   14.70 -	SourceHook::CSourceHookImpl g_SHImpl;
   14.71 -	g_SHPtr = &g_SHImpl;
   14.72 +	GET_SHPTR(g_SHPtr);
   14.73  	g_PLID = 1;
   14.74  
   14.75  	g_Gabgab = new IGaben;
   14.76  	___testbail_gabgab = (void*)g_Gabgab;
   14.77 +	___testbail_shptr = g_SHPtr;
   14.78  
   14.79 -	g_Gabgab->EatYams();
   14.80 +	SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler1, false);
   14.81 +
   14.82 +	ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
   14.83  
   14.84 -	SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false);
   14.85 +	CHECK_STATES((&g_States,
   14.86 +		new State_EatYams_Handler1_Called(0xDEAD),
   14.87 +		new State_EatYams_Called(0xDEAD),
   14.88 +		new State_EatYams_Return(5),
   14.89 +		NULL), "Part 1");
   14.90  
   14.91 -	g_Gabgab->EatYams();
   14.92 +	if (!___TestBail2(error))
   14.93 +		return false;
   14.94  
   14.95 -	___TestBail2();
   14.96 -	
   14.97 -	g_Gabgab->EatYams();
   14.98 +	CHECK_STATES((&g_States,
   14.99 +		new State_EatYams_Handler1_Called(0xDEAD),
  14.100 +		new State_EatYams_Handler2_Called(0xDEAD),
  14.101 +		new State_EatYams_Handler3_Called(0xBEEF),
  14.102 +		new State_EatYams_Called(0xBEEF),
  14.103 +		NULL), "Part 2.1");
  14.104 +
  14.105 +	// WHAT IF NOW SOMEONE UNLOADS PLUGIN 2 !?!?!?!?
  14.106 +	Test_UnloadPlugin(g_SHPtr, 2);
  14.107 +
  14.108 +	ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
  14.109  
  14.110 -	SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false);
  14.111 +	CHECK_STATES((&g_States,
  14.112 +		new State_EatYams_Handler1_Called(0xDEAD),
  14.113 +		new State_EatYams_Called(0xDEAD),
  14.114 +		new State_EatYams_Return(5),
  14.115 +		NULL), "Part 3");
  14.116  
  14.117 -	g_Gabgab->EatYams();
  14.118 +	SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler1, false);
  14.119 +
  14.120 +	ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
  14.121 +
  14.122 +	CHECK_STATES((&g_States,
  14.123 +		new State_EatYams_Called(0xDEAD),
  14.124 +		new State_EatYams_Return(5),
  14.125 +		NULL), "Part 4");
  14.126  
  14.127  	delete g_Gabgab;
  14.128  
  14.129 -	// If it didn't crash, it's ok
  14.130 -
  14.131 -	// NEW TEST: Remove hook from handler
  14.132 -	zomg_lolz inst;
  14.133 -	SH_ADD_HOOK_STATICFUNC(zomg_lolz, zomg, &inst, Handler, false);
  14.134 -	SH_ADD_HOOK_STATICFUNC(zomg_lolz, zomg, &inst, Handler2, false);
  14.135 -
  14.136 -	zomg_lolz *mwah = &inst;
  14.137 -	mwah->zomg();
  14.138 -	mwah->zomg();
  14.139 -
  14.140 -	SH_ADD_HOOK_STATICFUNC(zomg_lolz, zomg, &inst, Handler, false);
  14.141 -	SH_REMOVE_HOOK_STATICFUNC(zomg_lolz, zomg, &inst, Handler2, false);
  14.142 -
  14.143 -	mwah->zomg();
  14.144 -	mwah->zomg();
  14.145 -
  14.146 -	// Shouldn't crash again...
  14.147 -
  14.148  	return true;
  14.149  }
  14.150  
    15.1 --- a/sourcehook/test/testbail.h	Thu Dec 22 21:00:54 2005 +0000
    15.2 +++ b/sourcehook/test/testbail.h	Fri Dec 23 11:58:11 2005 +0000
    15.3 @@ -2,13 +2,9 @@
    15.4  // Shared data for testbail
    15.5  
    15.6  #include <string>
    15.7 -#include "sourcehook_impl.h"
    15.8  #include "testevents.h"
    15.9 -#include <stdarg.h>
   15.10 -#include <list>
   15.11 -#include <algorithm>
   15.12  
   15.13 -void ___TestBail2();
   15.14 +bool ___TestBail2(std::string &error);
   15.15  
   15.16  namespace
   15.17  {
   15.18 @@ -16,79 +12,28 @@
   15.19  	SourceHook::ISourceHook *g_SHPtr;
   15.20  	SourceHook::Plugin g_PLID;
   15.21  
   15.22 -	MAKE_STATE(State_EatYams_Called);
   15.23 -	MAKE_STATE(State_EatYams_Handler_Called);
   15.24 -
   15.25 +	MAKE_STATE_1(State_EatYams_Called, int);
   15.26 +	MAKE_STATE_1(State_EatYams_Handler1_Called, int);
   15.27 +	MAKE_STATE_1(State_EatYams_Handler2_Called, int);
   15.28 +	MAKE_STATE_1(State_EatYams_Handler3_Called, int);
   15.29 +	MAKE_STATE_1(State_EatYams_Return, int);
   15.30  
   15.31  	class IGaben
   15.32  	{
   15.33  	public:
   15.34 -		virtual void EatYams()
   15.35 +		virtual int EatYams(int a)
   15.36  		{
   15.37 -			ADD_STATE(State_EatYams_Called);
   15.38 +			ADD_STATE(State_EatYams_Called(a));
   15.39 +			return 5;
   15.40  		}
   15.41  	};
   15.42  
   15.43 -	SH_DECL_HOOK0_void(IGaben, EatYams, SH_NOATTRIB, 0);
   15.44 -
   15.45 -	/*
   15.46 -	SHINT_MAKE_GENERICSTUFF_BEGIN(IGaben, EatYams, 0, (static_cast<void (IGaben::*)() SH_NOATTRIB>
   15.47 -		(&IGaben::EatYams)))
   15.48 -		typedef fastdelegate::FastDelegate0<> FD;
   15.49 -		virtual void Func()
   15.50 -		{
   15.51 -			// SH_HANDLEFUNC_void(IGaben, EatYams, (), ());
   15.52 -
   15.53 -			SH_SETUPCALLS_void((), ())
   15.54 -			SH_CALL_HOOKS_void(pre, ())
   15.55 -			if (status != MRES_SUPERCEDE)
   15.56 -			{
   15.57 -				void (EmptyClass::*mfp)();
   15.58 -				SH_SETUP_MFP(mfp);
   15.59 -				(reinterpret_cast<EmptyClass*>(ifinfo->GetPtr())->*mfp)();
   15.60 -			}
   15.61 -			SH_CALL_HOOKS_void(post, ())
   15.62 -			SH_RETURN_void()
   15.63 -		}
   15.64 -	};
   15.65 -	SH_FHCls(IGaben,EatYams,0) SH_FHCls(IGaben,EatYams,0)::ms_Inst;
   15.66 -	::SourceHook::MemFuncInfo SH_FHCls(IGaben,EatYams,0)::ms_MFI;
   15.67 -	::SourceHook::IHookManagerInfo *SH_FHCls(IGaben,EatYams,0)::ms_HI;
   15.68 -	const char *SH_FHCls(IGaben,EatYams,0)::ms_Proto = "SH_NOATTRIB";
   15.69 -	bool __SourceHook_FHAddIGabenEatYams(void *iface, bool post,
   15.70 -		SH_FHCls(IGaben,EatYams,0)::FD handler)
   15.71 -	{
   15.72 -		using namespace ::SourceHook;
   15.73 -		MemFuncInfo mfi;
   15.74 -		GetFuncInfo((static_cast<void (IGaben::*)() SH_NOATTRIB>(&IGaben::EatYams)), mfi);
   15.75 -		if (mfi.thisptroffs < 0)
   15.76 -			return false;
   15.77 -
   15.78 -		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs,
   15.79 -			SH_FHCls(IGaben,EatYams,0)::HookManPubFunc,
   15.80 -			new CSHDelegate<SH_FHCls(IGaben,EatYams,0)::FD>(handler), post);
   15.81 -	}
   15.82 -	bool __SourceHook_FHRemoveIGabenEatYams(void *iface, bool post,
   15.83 -		SH_FHCls(IGaben,EatYams,0)::FD handler)
   15.84 -	{
   15.85 -		using namespace ::SourceHook;
   15.86 -		MemFuncInfo mfi;
   15.87 -		GetFuncInfo((static_cast<void (IGaben::*)() SH_NOATTRIB>(&IGaben::EatYams)), mfi);
   15.88 -		if (mfi.thisptroffs < 0)
   15.89 -			return false;
   15.90 -
   15.91 -		CSHDelegate<SH_FHCls(IGaben,EatYams,0)::FD> tmp(handler);
   15.92 -		return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs,
   15.93 -			SH_FHCls(IGaben,EatYams,0)::HookManPubFunc, &tmp, post);
   15.94 -	}
   15.95 -	*/
   15.96 -
   15.97 -	void EatYams0_Handler()
   15.98 -	{
   15.99 -		ADD_STATE(State_EatYams_Handler_Called);
  15.100 -	}
  15.101 +	SH_DECL_HOOK1(IGaben, EatYams, SH_NOATTRIB, 0, int, int);
  15.102  
  15.103  	IGaben *g_Gabgab;
  15.104  }
  15.105  
  15.106  extern void *___testbail_gabgab;
  15.107 +extern SourceHook::ISourceHook *___testbail_shptr;
  15.108 +extern int ___testbail_EatYams_Handler2(int a);
  15.109 +extern int ___testbail_EatYams_Handler3(int a);
  15.110 \ No newline at end of file
    16.1 --- a/sourcehook/test/testbail2.cpp	Thu Dec 22 21:00:54 2005 +0000
    16.2 +++ b/sourcehook/test/testbail2.cpp	Fri Dec 23 11:58:11 2005 +0000
    16.3 @@ -1,23 +1,25 @@
    16.4  // TESTBAIL
    16.5  //  Different compilation unit
    16.6  
    16.7 +#include "sourcehook.h"
    16.8 +#include "sourcehook_test.h"
    16.9  #include "testbail.h"
   16.10  
   16.11 -void ___TestBail2()
   16.12 +// :TODO: Test new-old proto system compa
   16.13 +
   16.14 +bool ___TestBail2(std::string &error)
   16.15  {
   16.16 -	SourceHook::CSourceHookImpl g_SHImpl;
   16.17 -	g_SHPtr = &g_SHImpl;
   16.18 +	g_SHPtr = ___testbail_shptr;
   16.19  	g_PLID = 2;
   16.20  
   16.21  	g_Gabgab = (IGaben*)___testbail_gabgab;
   16.22  
   16.23 -	g_Gabgab->EatYams();
   16.24 -
   16.25 -	SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false);
   16.26 +	SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, ___testbail_EatYams_Handler2, false);
   16.27 +	SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, ___testbail_EatYams_Handler3, false);
   16.28  
   16.29 -	g_Gabgab->EatYams();
   16.30 +	int ret = g_Gabgab->EatYams(0xDEAD);
   16.31  	
   16.32 -	SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false);
   16.33 -
   16.34 -	g_Gabgab->EatYams();
   16.35 +	CHECK_COND(ret == 6, "Part 2.1");
   16.36 +	
   16.37 +	return true;
   16.38  }
    17.1 --- a/sourcehook/test/testevents.h	Thu Dec 22 21:00:54 2005 +0000
    17.2 +++ b/sourcehook/test/testevents.h	Fri Dec 23 11:58:11 2005 +0000
    17.3 @@ -39,9 +39,6 @@
    17.4  
    17.5  	typedef std::list<State*> StateList;
    17.6  
    17.7 -	#define ADD_STATE(name) g_States.push_back(new name)
    17.8 -
    17.9 -
   17.10  	void DumpStates(StateList *sl)
   17.11  	{
   17.12  		for (StateList::iterator iter = sl->begin(); iter != sl->end(); ++iter)
   17.13 @@ -101,6 +98,9 @@
   17.14  	}
   17.15  }
   17.16  
   17.17 +#define ADD_STATE(name) g_States.push_back(new name)
   17.18 +#define ADD_STATE_PTR(statesptr, name) statesptr->push_back(new name)
   17.19 +
   17.20  #define CHECK_STATES(mwah, myerr) if (!StatesOk mwah) { error=myerr; return false; } else if (g_Verbose) { std::cout << "No error: " << myerr << std::endl; }
   17.21  
   17.22  #define MAKE_STATE(name) struct name : State { \
    18.1 --- a/sourcehook/test/testmanual.cpp	Thu Dec 22 21:00:54 2005 +0000
    18.2 +++ b/sourcehook/test/testmanual.cpp	Fri Dec 23 11:58:11 2005 +0000
    18.3 @@ -1,5 +1,6 @@
    18.4  #include <string>
    18.5 -#include "sourcehook_impl.h"
    18.6 +#include "sourcehook.h"
    18.7 +#include "sourcehook_test.h"
    18.8  #include "testevents.h"
    18.9  
   18.10  // TESTMANUAL
   18.11 @@ -94,8 +95,7 @@
   18.12  
   18.13  bool TestManual(std::string &error)
   18.14  {
   18.15 -	SourceHook::CSourceHookImpl g_SHImpl;
   18.16 -	g_SHPtr = &g_SHImpl;
   18.17 +	GET_SHPTR(g_SHPtr);
   18.18  	g_PLID = 1337;
   18.19  
   18.20  	TheWall inst;
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/sourcehook/test/testrecall.cpp	Fri Dec 23 11:58:11 2005 +0000
    19.3 @@ -0,0 +1,131 @@
    19.4 +#include <string>
    19.5 +#include "sourcehook.h"
    19.6 +#include "sourcehook_test.h"
    19.7 +#include "testevents.h"
    19.8 +
    19.9 +// TESTRECALL
   19.10 +// Test modifying parameters from hook handlers
   19.11 +
   19.12 +namespace
   19.13 +{
   19.14 +	StateList g_States;
   19.15 +	SourceHook::ISourceHook *g_SHPtr;
   19.16 +	SourceHook::Plugin g_PLID;
   19.17 +
   19.18 +	MAKE_STATE_1(State_Func1, int);
   19.19 +	MAKE_STATE_1(State_H1_Func1, int);
   19.20 +	MAKE_STATE_1(State_H2_Func1, int);
   19.21 +	MAKE_STATE_2(State_HP_Func1, int, void*);
   19.22 +
   19.23 +	MAKE_STATE_1(State_Func2, int);
   19.24 +	MAKE_STATE_1(State_H1_Func2, int);
   19.25 +	MAKE_STATE_2(State_HP_Func2, int, int);
   19.26 +
   19.27 +	struct Test
   19.28 +	{
   19.29 +		virtual void Func1(int a)
   19.30 +		{
   19.31 +			ADD_STATE(State_Func1(a));
   19.32 +		}
   19.33 +
   19.34 +		virtual int Func2(int a)
   19.35 +		{
   19.36 +			ADD_STATE(State_Func2(a));
   19.37 +			return 1000;
   19.38 +		}
   19.39 +	};
   19.40 +
   19.41 +	void Handler1_Func1(int a)
   19.42 +	{
   19.43 +		ADD_STATE(State_H1_Func1(a));
   19.44 +		RETURN_META_NEWPARAMS(MRES_IGNORED, Test, Func1, (5));
   19.45 +	}
   19.46 +	void Handler2_Func1(int a)
   19.47 +	{
   19.48 +		ADD_STATE(State_H2_Func1(a));
   19.49 +		RETURN_META_NEWPARAMS(MRES_IGNORED, Test, Func1, (a - 5));
   19.50 +	}
   19.51 +	void HandlerPost_Func1(int a)
   19.52 +	{
   19.53 +		ADD_STATE(State_HP_Func1(a, META_IFACEPTR(void)));
   19.54 +	}
   19.55 +
   19.56 +
   19.57 +	int Handler1_Func2(int a)
   19.58 +	{
   19.59 +		ADD_STATE(State_H1_Func2(a));
   19.60 +		RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 500, Test, Func2, (a - 10));
   19.61 +	}
   19.62 +
   19.63 +	int HandlerPost_Func2(int a)
   19.64 +	{
   19.65 +		ADD_STATE(State_HP_Func2(a, META_RESULT_ORIG_RET(int)));
   19.66 +		RETURN_META_VALUE(MRES_IGNORED, 0);
   19.67 +	}
   19.68 +
   19.69 +	SH_DECL_HOOK1_void(Test, Func1, SH_NOATTRIB, 0, int);
   19.70 +	SH_DECL_HOOK1(Test, Func2, SH_NOATTRIB, 0, int, int);
   19.71 +}
   19.72 +
   19.73 +bool TestRecall(std::string &error)
   19.74 +{
   19.75 +	GET_SHPTR(g_SHPtr);
   19.76 +	g_PLID = 1337;
   19.77 +
   19.78 +	Test inst;
   19.79 +	Test *ptr = &inst;
   19.80 +
   19.81 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler1_Func1, false);
   19.82 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
   19.83 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, HandlerPost_Func1, true);
   19.84 +
   19.85 +	ptr->Func1(77);
   19.86 +
   19.87 +	CHECK_STATES((&g_States,
   19.88 +		new State_H1_Func1(77),
   19.89 +		new State_H2_Func1(5),
   19.90 +		new State_Func1(0),
   19.91 +		new State_HP_Func1(0, ptr),
   19.92 +		NULL), "Part 1");
   19.93 +
   19.94 +	SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, Handler1_Func1, false);
   19.95 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
   19.96 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
   19.97 +	SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
   19.98 +
   19.99 +	ptr->Func1(77);
  19.100 +
  19.101 +	CHECK_STATES((&g_States,
  19.102 +		new State_H2_Func1(77),
  19.103 +		new State_H2_Func1(72),
  19.104 +		new State_H2_Func1(67),
  19.105 +		new State_H2_Func1(62),
  19.106 +		new State_Func1(57),
  19.107 +		new State_HP_Func1(57, ptr),
  19.108 +		NULL), "Part 2");
  19.109 +
  19.110 +	SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
  19.111 +	SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, HandlerPost_Func1, true);
  19.112 +
  19.113 +	ptr->Func1(77);
  19.114 +
  19.115 +	CHECK_STATES((&g_States,
  19.116 +		new State_Func1(77),
  19.117 +		NULL), "Part 3");
  19.118 +
  19.119 +	// Func2
  19.120 +
  19.121 +	SH_ADD_HOOK_STATICFUNC(Test, Func2, ptr, Handler1_Func2, false);
  19.122 +	SH_ADD_HOOK_STATICFUNC(Test, Func2, ptr, HandlerPost_Func2, true);
  19.123 +
  19.124 +	int a = ptr->Func2(77);
  19.125 +	CHECK_STATES((&g_States,
  19.126 +		new State_H1_Func2(77),
  19.127 +		new State_Func2(67),
  19.128 +		new State_HP_Func2(67, 1000),			// 1000 because it's the ORIG_RET
  19.129 +		NULL), "Part 4");
  19.130 +
  19.131 +	CHECK_COND(a == 500, "Part 4.1");
  19.132 +
  19.133 +	return true;
  19.134 +}
    20.1 --- a/sourcehook/test/testreentr.cpp	Thu Dec 22 21:00:54 2005 +0000
    20.2 +++ b/sourcehook/test/testreentr.cpp	Fri Dec 23 11:58:11 2005 +0000
    20.3 @@ -2,7 +2,7 @@
    20.4  // = calling hooks from hook handlers, etc
    20.5  
    20.6  #include <string>
    20.7 -#include "sourcehook_impl.h"
    20.8 +#include "sourcehook_test.h"
    20.9  #include "testevents.h"
   20.10  
   20.11  namespace
   20.12 @@ -294,8 +294,7 @@
   20.13  
   20.14  bool TestReentr(std::string &error)
   20.15  {
   20.16 -	SourceHook::CSourceHookImpl g_SHImpl;
   20.17 -	g_SHPtr = &g_SHImpl;
   20.18 +	GET_SHPTR(g_SHPtr);
   20.19  	g_PLID = 1337;
   20.20  
   20.21  	g_pC1 = &g_C1;