sourcehook/generate/sourcehook.hxx
branchsourcemm-1.6.0
changeset 361 f34718303c8f
parent 347 e82968c21606
     1.1 --- a/sourcehook/generate/sourcehook.hxx	Fri Sep 28 21:32:02 2007 +0000
     1.2 +++ b/sourcehook/generate/sourcehook.hxx	Fri Sep 28 21:40:58 2007 +0000
     1.3 @@ -22,7 +22,14 @@
     1.4  //  3 - Added "hook loop status variable"
     1.5  //  4 - Reentrant
     1.6  #define SH_IFACE_VERSION 4
     1.7 -#define SH_IMPL_VERSION 3
     1.8 +
     1.9 +// Impl versions:
    1.10 +// ???
    1.11 +// 4 - addition of hook ids and vp hooks (with them, AddHookNew and RemoveHookNew)
    1.12 +//     This is not a SH_IFACE_VERSION change so that old plugins continue working!
    1.13 +// 5 - addition of direct vp hooks (new hook mode; from now on AddHookNew checks for
    1.14 +//	   invalid hookmode -> impl version won't have to change because of things like this)
    1.15 +#define SH_IMPL_VERSION 5
    1.16  
    1.17  // Hookman version:
    1.18  //  1 - Support for recalls, performance optimisations
    1.19 @@ -291,15 +298,12 @@
    1.20  		}
    1.21  	};
    1.22  
    1.23 -	template<class B> struct CallClass
    1.24 +	template<class B> struct DeprecatedCallClass
    1.25  	{
    1.26  		virtual B *GetThisPtr() = 0;
    1.27  		virtual void *GetOrigFunc(int vtbloffs, int vtblidx) = 0;
    1.28  	};
    1.29  
    1.30 -	typedef CallClass<void> GenericCallClass;
    1.31 -	typedef CallClass<EmptyClass> ManualCallClass;
    1.32 -
    1.33  	// 09.08.2008 (6 AM, I just woke up, the others are still sleeping so i finally can use this notebook !!)
    1.34  	// - Today is an important day.
    1.35  	// I'm adding support for functions which return references.
    1.36 @@ -401,14 +405,14 @@
    1.37  		*	@param iface The interface pointer
    1.38  		*	@param size Size of the class instance
    1.39  		*/
    1.40 -		virtual GenericCallClass *GetCallClass(void *iface, size_t size) = 0;
    1.41 +		virtual DeprecatedCallClass<void> *GetCallClass(void *iface, size_t size) = 0;
    1.42  
    1.43  		/**
    1.44  		*	@brief Release a callclass
    1.45  		*
    1.46  		*	@param ptr Pointer to the callclass
    1.47  		*/
    1.48 -		virtual void ReleaseCallClass(GenericCallClass *ptr) = 0;
    1.49 +		virtual void ReleaseCallClass(DeprecatedCallClass<void> *ptr) = 0;
    1.50  
    1.51  		virtual void SetRes(META_RES res) = 0;				//!< Sets the meta result
    1.52  		virtual META_RES GetPrevRes() = 0;					//!< Gets the meta result of the
    1.53 @@ -479,7 +483,65 @@
    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 +		*	@brief Modes for the new AddHook
    1.60 +		*/
    1.61 +		enum AddHookMode
    1.62 +		{
    1.63 +			Hook_Normal,
    1.64 +			Hook_VP,
    1.65 +			Hook_DVP
    1.66 +		}; 
    1.67 +
    1.68 +		/**
    1.69 +		*	@brief Add a (VP) hook.
    1.70 +		*
    1.71 +		*	@return non-zero hook id on success, 0 otherwise
    1.72 +		*
    1.73 +		*	@param plug The unique identifier of the plugin that calls this function
    1.74 +		*	@param mode	Can be either Hook_Normal or Hook_VP (vtable-wide hook)
    1.75 +		*	@param iface The interface pointer
    1.76 +		*	@param ifacesize The size of the class iface points to
    1.77 +		*	@param myHookMan A hook manager function that should be capable of handling the function
    1.78 +		*	@param handler A pointer to a FastDelegate containing the hook handler
    1.79 +		*	@param post Set to true if you want a post handler
    1.80 +		*/
    1.81 +		virtual int AddHookNew(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
    1.82 +			ISHDelegate *handler, bool post) = 0;
    1.83 +
    1.84 +		/**
    1.85 +		*	@brief Remove a VP hook by ID.
    1.86 +		*
    1.87 +		*	@return true on success, false otherwise
    1.88 +		*
    1.89 +		*	@param plug The unique identifier of the plugin that calls this function
    1.90 +		*	@param hookid The hook id (returned by AddHookNew)
    1.91 +		*/
    1.92 +		virtual bool RemoveHookByID(Plugin plug, int hookid) = 0;
    1.93 +
    1.94 +		/**
    1.95 +		*	@brief Makes sure that hooks are going to be ignored on the next call of vfnptr
    1.96 +		*
    1.97 +		*	@param plug The unique identifier of the plugin that calls this function
    1.98 +		*	@param vfnptr The virtual function pointer of the function in question
    1.99 +		*/
   1.100 +		virtual void SetIgnoreHooks(Plugin plug, void *vfnptr) = 0;
   1.101 +
   1.102 +		/**
   1.103 +		*	@brief Reverses SetIgnoreHooks' effect
   1.104 +		*
   1.105 +		*	@param plug The unique identifier of the plugin that calls this function
   1.106 +		*	@param vfnptr The virtual function pointer of the function in question
   1.107 +		*/
   1.108 +		virtual void ResetIgnoreHooks(Plugin plug, void *vfnptr) = 0;
   1.109 +
   1.110 +		/**
   1.111 +		*	@brief Finds the original entry of a virtual function pointer
   1.112 +		*
   1.113 +		*	@param vfnptr The virtual function pointer
   1.114 +		*	@return The original entry if the virtual function pointer has been patched; NULL otherwise.
   1.115 +		*/
   1.116 +		virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
   1.117  	};
   1.118  
   1.119  	// For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
   1.120 @@ -510,6 +572,50 @@
   1.121  			return &ref;
   1.122  		}
   1.123  	};
   1.124 +
   1.125 +	// For source-level compatibility
   1.126 +	template <class T> struct CallClass
   1.127 +	{
   1.128 +		T *ptr;
   1.129 +
   1.130 +		CallClass(T *p) : ptr(p)
   1.131 +		{
   1.132 +		}
   1.133 +
   1.134 +		operator T*()
   1.135 +		{
   1.136 +			return ptr;
   1.137 +		}
   1.138 +	};
   1.139 +
   1.140 +	typedef CallClass<void> GenericCallClass;
   1.141 +	typedef CallClass<EmptyClass> ManualCallClass;
   1.142 +
   1.143 +	template <class T>
   1.144 +	CallClass<T> *GetCallClass(T *p)
   1.145 +	{
   1.146 +		return new CallClass<T>(p);
   1.147 +	}
   1.148 +
   1.149 +	template <class T>
   1.150 +	void ReleaseCallClass(CallClass<T> *p)
   1.151 +	{
   1.152 +		delete p;
   1.153 +	}
   1.154 +
   1.155 +	template <class X, class MFP>
   1.156 +	void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
   1.157 +	{
   1.158 +		SourceHook::MemFuncInfo info = {true, -1, 0, 0};
   1.159 +		SourceHook::GetFuncInfo(pInstance, mfp, info);
   1.160 +
   1.161 +		void *vfnptr = reinterpret_cast<void*>(
   1.162 +			*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
   1.163 +
   1.164 +		void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
   1.165 +		
   1.166 +		return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
   1.167 +	}
   1.168  }
   1.169  
   1.170  /************************************************************************/
   1.171 @@ -614,31 +720,6 @@
   1.172  		RETURN_META_VALUE(MRES_SUPERCEDE, (thisptr->*(u.mfp)) newparams); \
   1.173  	} while (0)
   1.174  
   1.175 -/**
   1.176 -*	@brief Get/generate callclass for an interface pointer
   1.177 -*
   1.178 -*	@param ifaceptr The interface pointer
   1.179 -*/
   1.180 -template<class ifacetype>
   1.181 -inline SourceHook::CallClass<ifacetype> *SH_GET_CALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr)
   1.182 -{
   1.183 -	return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
   1.184 -		shptr->GetCallClass(reinterpret_cast<void*>(ptr), sizeof(ifacetype)));
   1.185 -}
   1.186 -
   1.187 -template<class ifacetype>
   1.188 -inline SourceHook::CallClass<ifacetype> *SH_GET_MCALLCLASS_R(SourceHook::ISourceHook *shptr, ifacetype *ptr, int ifacesize)
   1.189 -{
   1.190 -	return reinterpret_cast<SourceHook::CallClass<ifacetype>*>(
   1.191 -		shptr->GetCallClass(reinterpret_cast<void*>(ptr), ifacesize));
   1.192 -}
   1.193 -
   1.194 -template<class ifacetype>
   1.195 -inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::CallClass<ifacetype> *ptr)
   1.196 -{
   1.197 -	shptr->ReleaseCallClass(reinterpret_cast<SourceHook::GenericCallClass*>(ptr));
   1.198 -}
   1.199 -
   1.200  #define SH_MANUALHOOK_RECONFIGURE(hookname, pvtblindex, pvtbloffs, pthisptroffs) \
   1.201  	do { \
   1.202  		SH_GLOB_SHPTR->RemoveHookManager(SH_GLOB_PLUGPTR, SH_MFHCls(hookname)::HookManPubFunc); \
   1.203 @@ -647,41 +728,83 @@
   1.204  		SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
   1.205  	} while (0)
   1.206  
   1.207 -#define SH_GET_CALLCLASS(ptr) SH_GET_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
   1.208 -#define SH_GET_MCALLCLASS(ptr, size) SH_GET_MCALLCLASS_R(SH_GLOB_SHPTR, reinterpret_cast<SourceHook::EmptyClass*>(ptr), size)
   1.209 -#define SH_RELEASE_CALLCLASS(ptr) SH_RELEASE_CALLCLASS_R(SH_GLOB_SHPTR, ptr)
   1.210 +
   1.211 +#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
   1.212 +
   1.213 +// For source-level compatibility
   1.214 +
   1.215 +#define SH_GET_CALLCLASS(ptr) SourceHook::GetCallClass(ptr)
   1.216 +#define SH_GET_MCALLCLASS(ptr, size) SourceHook::GetCallClass(reinterpret_cast<SourceHook::EmptyClass*>(ptr))
   1.217 +#define SH_RELEASE_CALLCLASS(ptr) SourceHook::ReleaseCallClass(ptr)
   1.218 +
   1.219 +// New ADD / REMOVE macros.
   1.220 +#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
   1.221 +#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
   1.222  
   1.223  #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.224  	__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.225  	post, handler)
   1.226 -#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.227 -	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
   1.228 -#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.229 -	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.230  
   1.231  #define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.232  	__SourceHook_FHRemove##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.233 -	post, handler)
   1.234 -#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.235 -	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler), post)
   1.236 -#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.237 -	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.238 -
   1.239 +	post, handler) 
   1.240  
   1.241  #define SH_ADD_MANUALHOOK(hookname, ifaceptr, handler, post) \
   1.242  	__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
   1.243 -#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
   1.244 -	SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
   1.245 -#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
   1.246 -	SH_ADD_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.247  
   1.248  #define SH_REMOVE_MANUALHOOK(hookname, ifaceptr, handler, post) \
   1.249 -	__SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
   1.250 +	__SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler) 
   1.251 +
   1.252 +#define SH_ADD_VPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.253 +	__SourceHook_FHVPAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.254 +	post, handler, false)
   1.255 +
   1.256 +#define SH_ADD_DVPHOOK(ifacetype, ifacefunc, vtableptr, handler, post) \
   1.257 +	__SourceHook_FHVPAdd##ifacetype##ifacefunc(reinterpret_cast<void*>(vtableptr), \
   1.258 +	post, handler, true)
   1.259 +
   1.260 +#define SH_ADD_MANUALVPHOOK(hookname, ifaceptr, handler, post) \
   1.261 +	__SourceHook_FHMVPAdd##hookname(reinterpret_cast<void*>(ifaceptr), post, handler, false)
   1.262 +
   1.263 +#define SH_ADD_MANUALDVPHOOK(hookname, vtableptr, handler, post) \
   1.264 +	__SourceHook_FHMVPAdd##hookname(reinterpret_cast<void*>(vtableptr), post, handler, true)
   1.265 +
   1.266 +#define SH_REMOVE_HOOK_ID(hookid) \
   1.267 +	(SH_GLOB_SHPTR->RemoveHookByID(SH_GLOB_PLUGPTR, hookid))
   1.268 +
   1.269 +// Old macros
   1.270 +// !! These are now deprecated. Instead, use one of these:
   1.271 +//  SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.272 +//  SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
   1.273 +
   1.274 +#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.275 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.276 +#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.277 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.278 +
   1.279 +//  SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.280 +//  SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
   1.281 +
   1.282 +#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.283 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.284 +#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.285 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.286 +
   1.287 +//  SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.288 +//  SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
   1.289 +
   1.290 +#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
   1.291 +	SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.292 +#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
   1.293 +	SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.294 +
   1.295 +//  SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.296 +//  SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
   1.297 +
   1.298  #define SH_REMOVE_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
   1.299 -	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler), post)
   1.300 +	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.301  #define SH_REMOVE_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
   1.302 -	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.303 -
   1.304 +	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)  
   1.305  
   1.306  #define SH_NOATTRIB
   1.307  
   1.308 @@ -716,6 +839,8 @@
   1.309  		/* Verify interface version */ \
   1.310  		if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
   1.311  			return 1; \
   1.312 +		if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
   1.313 +			return 1; \
   1.314  		\
   1.315  		if (action == HA_GetInfo) \
   1.316  		{ \
   1.317 @@ -760,7 +885,7 @@
   1.318  	SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   1.319  	::SourceHook::MemFuncInfo SH_FHCls(ifacetype,ifacefunc,overload)::ms_MFI; \
   1.320  	::SourceHook::IHookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   1.321 -	bool __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   1.322 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   1.323  		SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.324  	{ \
   1.325  		using namespace ::SourceHook; \
   1.326 @@ -769,10 +894,24 @@
   1.327  		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   1.328  			return false; /* No non-virtual functions / virtual inheritance supported */ \
   1.329  		\
   1.330 -		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
   1.331 +		return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, ::SourceHook::ISourceHook::Hook_Normal, iface, mfi.thisptroffs, \
   1.332  			SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   1.333  			new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   1.334  	} \
   1.335 +	int __SourceHook_FHVPAdd##ifacetype##ifacefunc(void *iface, bool post, \
   1.336 +		SH_FHCls(ifacetype,ifacefunc,overload)::FD handler, bool direct) \
   1.337 +	{ \
   1.338 +		using namespace ::SourceHook; \
   1.339 +		MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.340 +		GetFuncInfo(funcptr, mfi); \
   1.341 +		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   1.342 +			return false; /* No non-virtual functions / virtual inheritance supported */ \
   1.343 +		\
   1.344 +		return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, \
   1.345 +			direct ? ::SourceHook::ISourceHook::Hook_DVP : ::SourceHook::ISourceHook::Hook_VP, \
   1.346 +			iface, mfi.thisptroffs, SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   1.347 +			new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   1.348 +	} \
   1.349  	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   1.350  		SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.351  	{ \
   1.352 @@ -811,6 +950,8 @@
   1.353  			/* Verify interface version */ \
   1.354  			if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
   1.355  				return 1; \
   1.356 +			if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
   1.357 +				return 1; \
   1.358  			\
   1.359  			if (action == HA_GetInfo) \
   1.360  			{ \
   1.361 @@ -843,13 +984,21 @@
   1.362  	SH_MFHCls(hookname) SH_MFHCls(hookname)::ms_Inst; \
   1.363  	::SourceHook::MemFuncInfo SH_MFHCls(hookname)::ms_MFI; \
   1.364  	::SourceHook::IHookManagerInfo *SH_MFHCls(hookname)::ms_HI; \
   1.365 -	bool __SourceHook_FHMAdd##hookname(void *iface, bool post, \
   1.366 +	int __SourceHook_FHMAdd##hookname(void *iface, bool post, \
   1.367  		SH_MFHCls(hookname)::FD handler) \
   1.368  	{ \
   1.369 -		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
   1.370 +		return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, ::SourceHook::ISourceHook::Hook_Normal, iface, pthisptroffs, \
   1.371  			SH_MFHCls(hookname)::HookManPubFunc, \
   1.372  			new ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD>(handler), post); \
   1.373  	} \
   1.374 +	int __SourceHook_FHMVPAdd##hookname(void *iface, bool post, \
   1.375 +		SH_MFHCls(hookname)::FD handler, bool direct) \
   1.376 +	{ \
   1.377 +		return SH_GLOB_SHPTR->AddHookNew(SH_GLOB_PLUGPTR, \
   1.378 +			direct ? ::SourceHook::ISourceHook::Hook_DVP : ::SourceHook::ISourceHook::Hook_VP, \
   1.379 +			iface, pthisptroffs, SH_MFHCls(hookname)::HookManPubFunc, \
   1.380 +			new ::SourceHook::CSHDelegate<SH_MFHCls(hookname)::FD>(handler), post); \
   1.381 +	} \
   1.382  	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
   1.383  		SH_MFHCls(hookname)::FD handler) \
   1.384  	{ \
   1.385 @@ -1127,136 +1276,109 @@
   1.386  //////////////////////////////////////////////////////////////////////////
   1.387  // SH_CALL
   1.388  
   1.389 -#if SH_COMP == SH_COMP_MSVC
   1.390 -
   1.391 -# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
   1.392 -{ \
   1.393 -	using namespace ::SourceHook; \
   1.394 -	MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.395 -	GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
   1.396 -	void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
   1.397 -	if (!origfunc) \
   1.398 -		return (m_CC->GetThisPtr()->*m_MFP)call; \
   1.399 -	\
   1.400 -	/* It's hooked. Call the original function. */ \
   1.401 -	union \
   1.402 -	{ \
   1.403 -		RetType(EmptyClass::*mfpnew)prms; \
   1.404 -		void *addr; \
   1.405 -	} u; \
   1.406 -	u.addr = origfunc; \
   1.407 -	\
   1.408 -	void *adjustedthisptr = reinterpret_cast<void*>(reinterpret_cast<char*>(m_CC->GetThisPtr()) + mfi.thisptroffs); \
   1.409 -	return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
   1.410 -}
   1.411 -
   1.412 -# define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
   1.413 -{ \
   1.414 -	using namespace ::SourceHook; \
   1.415 -	char *adjustedthisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()) + m_ThisPtrOffs; \
   1.416 -	union \
   1.417 -	{ \
   1.418 -		RetType(EmptyClass::*mfpnew)prms; \
   1.419 -		void *addr; \
   1.420 -	} u; \
   1.421 -	u.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
   1.422 -	if (!u.addr) \
   1.423 -		u.addr = (*reinterpret_cast<void***>(adjustedthisptr + m_VtblOffs))[m_VtblIdx]; \
   1.424 -	\
   1.425 -	return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
   1.426 -}
   1.427 -
   1.428 -#elif SH_COMP == SH_COMP_GCC
   1.429 -
   1.430 -# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
   1.431 +#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
   1.432  { \
   1.433  	using namespace ::SourceHook; \
   1.434 -	MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.435 -	GetFuncInfo(m_CC->GetThisPtr(), m_MFP, mfi); \
   1.436 -	void *origfunc = m_CC->GetOrigFunc(mfi.thisptroffs + mfi.vtbloffs, mfi.vtblindex); \
   1.437 -	if (!origfunc) \
   1.438 -		return (m_CC->GetThisPtr()->*m_MFP)call; \
   1.439  	\
   1.440 -	/* It's hooked. Call the original function. */ \
   1.441 -	union \
   1.442 -	{ \
   1.443 -		RetType(EmptyClass::*mfpnew)prms; \
   1.444 -		struct \
   1.445 -		{ \
   1.446 -			void *addr; \
   1.447 -			intptr_t adjustor; \
   1.448 -		} s; \
   1.449 -	} u; \
   1.450 -	u.s.addr = origfunc; \
   1.451 -	u.s.adjustor = mfi.thisptroffs; \
   1.452 -	\
   1.453 -	return (reinterpret_cast<EmptyClass*>(m_CC->GetThisPtr())->*u.mfpnew)call; \
   1.454 +	m_pSH->SetIgnoreHooks(m_Plug, m_VfnPtr); \
   1.455 +	RetType tmpret = (m_ThisPtr->*m_MFP)call; \
   1.456 +	m_pSH->ResetIgnoreHooks(m_Plug, m_VfnPtr); \
   1.457 +	return tmpret; \
   1.458  }
   1.459  
   1.460 -# define SH_MAKE_MEXECUTABLECLASS_OB(call, prms) \
   1.461 +#define SH_MAKE_EXECUTABLECLASS_OB_void(call, prms) \
   1.462  { \
   1.463  	using namespace ::SourceHook; \
   1.464 -	char *thisptr = reinterpret_cast<char*>(m_CC->GetThisPtr()); \
   1.465 -	union \
   1.466 -	{ \
   1.467 -		RetType(EmptyClass::*mfpnew)prms; \
   1.468 -		struct { \
   1.469 -			void *addr; \
   1.470 -			intptr_t adjustor; \
   1.471 -		} s; \
   1.472 -	} u; \
   1.473 -	u.s.addr = m_CC->GetOrigFunc(m_ThisPtrOffs + m_VtblOffs, m_VtblIdx); \
   1.474 -	if (!u.s.addr) \
   1.475 -		u.s.addr = (*reinterpret_cast<void***>(thisptr + m_ThisPtrOffs + m_VtblOffs))[m_VtblIdx]; \
   1.476  	\
   1.477 -	u.s.adjustor = m_ThisPtrOffs; \
   1.478 -	return (reinterpret_cast<EmptyClass*>(thisptr)->*u.mfpnew)call; \
   1.479 +	m_pSH->SetIgnoreHooks(m_Plug, m_VfnPtr); \
   1.480 +	(m_ThisPtr->*m_MFP)call; \
   1.481 +	m_pSH->ResetIgnoreHooks(m_Plug, m_VfnPtr); \
   1.482  }
   1.483  
   1.484 -#endif
   1.485 -
   1.486  namespace SourceHook
   1.487  {
   1.488 -@[$1,0,$a:
   1.489 -	// Support for $1 arguments
   1.490 -	template<class CCType, class MFPType, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
   1.491 +	// Call Class Wrapper!
   1.492 +	template <class T> struct CCW
   1.493  	{
   1.494 -	   CCType *m_CC;
   1.495 -	   MFPType m_MFP;
   1.496 -	public:
   1.497 -	   ExecutableClass$1(CCType *cc, MFPType mfp) : m_CC(cc), m_MFP(mfp) { }
   1.498 -	
   1.499 -	   RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
   1.500 -	      SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
   1.501 -	         
   1.502 -	   @[$2,$1+1,$a:
   1.503 -	   template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
   1.504 -	      SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
   1.505 -	   @]
   1.506 +		typedef T type;
   1.507 +
   1.508 +		// Get Real Pointer!
   1.509 +		static inline T *GRP(T *p)
   1.510 +		{
   1.511 +			return p;
   1.512 +		}
   1.513 +	};
   1.514 +
   1.515 +	template <class T> struct CCW< CallClass<T> >
   1.516 +	{
   1.517 +		typedef T type;
   1.518 +
   1.519 +		// Get Real Pointer!
   1.520 +		static inline T *GRP(CallClass<T> *p)
   1.521 +		{
   1.522 +			return p->ptr;
   1.523 +		}
   1.524  	};
   1.525  
   1.526 -	template <class RetType@[$2,1,$1:, class Param$2@]> class MExecutableClass$1
   1.527 +@[$1,0,$a:
   1.528 +	// Support for $1 arguments
   1.529 +	template<class ObjType, class MFP, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
   1.530  	{
   1.531 -		ManualCallClass *m_CC;
   1.532 -		int m_ThisPtrOffs;
   1.533 -		int m_VtblIdx;
   1.534 -		int m_VtblOffs;
   1.535 +		ObjType *m_ThisPtr;
   1.536 +		void *m_VfnPtr;
   1.537 +		MFP m_MFP;
   1.538 +		ISourceHook *m_pSH;
   1.539 +		Plugin m_Plug;
   1.540  	public:
   1.541 -		MExecutableClass$1(ManualCallClass *cc, int vtbloffs, int vtblidx, int thisptroffs) : m_CC(cc),
   1.542 -			m_ThisPtrOffs(thisptroffs), m_VtblIdx(vtblidx), m_VtblOffs(vtbloffs) { }
   1.543 -
   1.544 +		ExecutableClass$1(ObjType *tp, MFP mfp, void *vp, ISourceHook *pSH, Plugin plug) : m_ThisPtr(tp),
   1.545 +			m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH), m_Plug(plug) { }
   1.546 +	
   1.547  		RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
   1.548 -			SH_MAKE_MEXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
   1.549 -
   1.550 +			SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
   1.551 +	         
   1.552  		@[$2,$1+1,$a:
   1.553  		template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
   1.554 -			SH_MAKE_MEXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
   1.555 +			SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
   1.556  		@]
   1.557  	};
   1.558 +
   1.559 +	template<class ObjType, class MFP@[$2,1,$1:, class Param$2@]> class ExecutableClass$1<ObjType, MFP, void@[$2,1,$1:, Param$2@]>
   1.560 +	{
   1.561 +	   ObjType *m_ThisPtr;
   1.562 +	   void *m_VfnPtr;
   1.563 +	   MFP m_MFP;
   1.564 +	   ISourceHook *m_pSH;
   1.565 +	   Plugin m_Plug;
   1.566 +	public:
   1.567 +	   ExecutableClass$1(ObjType *tp, MFP mfp, void *vp, ISourceHook *pSH, Plugin plug) : m_ThisPtr(tp),
   1.568 +		   m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH), m_Plug(plug) { }
   1.569 +	
   1.570 +	   void operator()(@[$2,1,$1|, :Param$2 p$2@]) const
   1.571 +	      SH_MAKE_EXECUTABLECLASS_OB_void((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
   1.572 +	         
   1.573 +	   @[$2,$1+1,$a:
   1.574 +	   template <@[$3,$1+1,$2|, :class Param$3@]> void operator()(@[$3,1,$2|, :Param$3 p$3@]) const
   1.575 +	      SH_MAKE_EXECUTABLECLASS_OB_void((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
   1.576 +	   @]
   1.577 +	};
   1.578  @]
   1.579  
   1.580  }
   1.581  
   1.582 +#define SH__CALL_GET_VFNPTR_NORMAL \
   1.583 +	using namespace ::SourceHook; \
   1.584 +	MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.585 +	GetFuncInfo(CCW<Y>::GRP(ptr), mfp, mfi); \
   1.586 +	void *vfnptr = reinterpret_cast<void*>( \
   1.587 +		*reinterpret_cast<void***>(reinterpret_cast<char*>(ptr) + mfi.thisptroffs + mfi.vtbloffs) + mfi.vtblindex);
   1.588 +
   1.589 +#define SH__CALL_GET_VFNPTR_MANUAL \
   1.590 +	using namespace ::SourceHook; \
   1.591 +	void *vfnptr = reinterpret_cast<void*>( \
   1.592 +		*reinterpret_cast<void***>( (reinterpret_cast<char*>(CCW<Y>::GRP(ptr)) + thisptroffs + vtbloffs) ) + vtblidx); \
   1.593 +	/* patch mfp */ \
   1.594 +	*reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr);
   1.595 +
   1.596  // SH_CALL needs to deduce the return type -> it uses templates and function overloading
   1.597  // That's why SH_CALL takes two parameters: "mfp2" of type RetType(X::*mfp)(params), and "mfp" of type MFP
   1.598  // The only purpose of the mfp2 parameter is to extract the return type
   1.599 @@ -1264,24 +1386,30 @@
   1.600  @[$1,0,$a:
   1.601  // Support for $1 arguments
   1.602  template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
   1.603 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.604 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]))
   1.605 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.606 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.607  {
   1.608 -	return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
   1.609 +	SH__CALL_GET_VFNPTR_NORMAL
   1.610 +	return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
   1.611 +		mfp, vfnptr, shptr, plug);
   1.612  }
   1.613  
   1.614  template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
   1.615 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.616 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const)
   1.617 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.618 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.619  {
   1.620 -	return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
   1.621 +	SH__CALL_GET_VFNPTR_NORMAL
   1.622 +	return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
   1.623 +		mfp, vfnptr, shptr, plug);
   1.624  }
   1.625  
   1.626 -template <class X, class RetType@[$2,1,$1:, class Param$2@]>
   1.627 -SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>
   1.628 -SH_MCALL2(SourceHook::ManualCallClass *ptr, RetType(X::*mfp)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs)
   1.629 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
   1.630 +SourceHook::ExecutableClass$1<SourceHook::EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.631 +SH_MCALL3(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.632  {
   1.633 -	return SourceHook::MExecutableClass$1<RetType@[$2,1,$1:, Param$2@]>(ptr, vtbloffs, vtblidx, thisptroffs);
   1.634 +	SH__CALL_GET_VFNPTR_MANUAL
   1.635 +	return SourceHook::ExecutableClass$1<EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>(
   1.636 +		reinterpret_cast<SourceHook::EmptyClass*>(CCW<Y>::GRP(ptr)), mfp, vfnptr, shptr, plug);
   1.637  }
   1.638  @]
   1.639  
   1.640 @@ -1291,24 +1419,29 @@
   1.641  @[$1,0,$a:
   1.642  // Support for $1 arguments
   1.643  template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
   1.644 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.645 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...))
   1.646 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.647 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...), SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.648  {
   1.649 -	return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
   1.650 +	SH__CALL_GET_VFNPTR_NORMAL
   1.651 +	return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
   1.652 +		mfp, vfnptr, shptr, plug);
   1.653  }
   1.654  
   1.655  template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
   1.656 -SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.657 -SH_CALL2(SourceHook::CallClass<Y> *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const)
   1.658 +SourceHook::ExecutableClass$1<typename SourceHook::CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>
   1.659 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const, SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.660  {
   1.661 -	return SourceHook::ExecutableClass$1<SourceHook::CallClass<Y>, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp);
   1.662 +	SH__CALL_GET_VFNPTR_NORMAL
   1.663 +	return SourceHook::ExecutableClass$1<typename CCW<Y>::type, MFP, RetType@[$2,1,$1:, Param$2@]>(CCW<Y>::GRP(ptr),
   1.664 +		mfp, vfnptr, shptr, plug);
   1.665  }
   1.666  
   1.667  @]
   1.668  
   1.669  #endif
   1.670  
   1.671 -#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp))
   1.672 +#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp), SH_GLOB_SHPTR, SH_GLOB_PLUGPTR)
   1.673 +#define SH_MCALL2(ptr, mfp, vtblidx, vtbloffs, thisptroffs) SH_MCALL3((ptr), (mfp), (mfp), (vtblidx), (vtbloffs), (thisptroffs), SH_GLOB_SHPTR, SH_GLOB_PLUGPTR)
   1.674  #define SH_MCALL(ptr, mhookname) SH_MCALL2((ptr), SH_MFHCls(mhookname)::ECMFP(), SH_MFHCls(mhookname)::ms_MFI.vtblindex, \
   1.675  	SH_MFHCls(mhookname)::ms_MFI.vtbloffs, SH_MFHCls(mhookname)::ms_MFI.thisptroffs)
   1.676