core/sourcehook/generate/sourcehook.hxx
changeset 539 db914129ae01
parent 523 6f1630519b81
child 680 39d0803bdb6e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/sourcehook/generate/sourcehook.hxx	Fri Nov 14 04:04:02 2008 -0600
     1.3 @@ -0,0 +1,1465 @@
     1.4 +/* ======== SourceHook ========
     1.5 +* Copyright (C) 2004-2008 Metamod:Source Development Team
     1.6 +* No warranties of any kind
     1.7 +*
     1.8 +* License: zlib/libpng
     1.9 +*
    1.10 +* Author(s): Pavol "PM OnoTo" Marko
    1.11 +* ============================
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +*	@file sourcehook.h
    1.16 +*	@brief Contains the public SourceHook API
    1.17 +*/
    1.18 +
    1.19 +#ifndef __SOURCEHOOK_H__
    1.20 +#define __SOURCEHOOK_H__
    1.21 +
    1.22 +// Interface revisions:
    1.23 +//  1 - Initial revision
    1.24 +//  2 - Changed to virtual functions for iterators and all queries
    1.25 +//  3 - Added "hook loop status variable"
    1.26 +//  4 - Reentrant
    1.27 +//  5 - New "V2" interface
    1.28 +#define SH_IFACE_VERSION 5
    1.29 +
    1.30 +// Impl versions:
    1.31 +// ???
    1.32 +// 4 - addition of hook ids and vp hooks (with them, AddHookNew and RemoveHookNew)
    1.33 +//     This is not a SH_IFACE_VERSION change so that old plugins continue working!
    1.34 +// 5 - implementation of the new "V2" interface
    1.35 +#define SH_IMPL_VERSION 5
    1.36 +
    1.37 +// Hookman version:
    1.38 +// 1 - standard
    1.39 +#define SH_HOOKMAN_VERSION 1
    1.40 +
    1.41 +// Hookmanautogen versions
    1.42 +//  1 - initial
    1.43 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
    1.44 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
    1.45 +
    1.46 +// The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
    1.47 +// It's used in various macros
    1.48 +#ifndef SH_GLOB_SHPTR
    1.49 +#define SH_GLOB_SHPTR g_SHPtr
    1.50 +#endif
    1.51 +
    1.52 +// Used to identify the current plugin
    1.53 +#ifndef SH_GLOB_PLUGPTR
    1.54 +#define SH_GLOB_PLUGPTR g_PLID
    1.55 +#endif
    1.56 +
    1.57 +#ifdef SH_DEBUG
    1.58 +# include <stdio.h>
    1.59 +# include <stdlib.h>
    1.60 +
    1.61 +# define SH_ASSERT(x, info) \
    1.62 +	do { \
    1.63 +		if (!(x)) \
    1.64 +		{ \
    1.65 +			printf("SOURCEHOOK DEBUG ASSERTION FAILED: %s:%u(%s): %s: ", __FILE__, __LINE__, __FUNCTION__, #x); \
    1.66 +			printf info; \
    1.67 +			putchar('\n'); \
    1.68 +			abort(); \
    1.69 +		} \
    1.70 +	} while(0)
    1.71 +
    1.72 +#else
    1.73 +# define SH_ASSERT(x, info)
    1.74 +#endif
    1.75 +
    1.76 +// System
    1.77 +#define SH_SYS_WIN32 1
    1.78 +#define SH_SYS_LINUX 2
    1.79 +
    1.80 +#ifdef _WIN32
    1.81 +# define SH_SYS SH_SYS_WIN32
    1.82 +#elif defined __linux__
    1.83 +# define SH_SYS SH_SYS_LINUX
    1.84 +#else
    1.85 +# error Unsupported system
    1.86 +#endif
    1.87 +
    1.88 +// Compiler
    1.89 +#define SH_COMP_GCC 1
    1.90 +#define SH_COMP_MSVC 2
    1.91 +
    1.92 +#ifdef _MSC_VER
    1.93 +# define SH_COMP SH_COMP_MSVC
    1.94 +#elif defined __GNUC__
    1.95 +# define SH_COMP SH_COMP_GCC
    1.96 +#else
    1.97 +# error Unsupported compiler
    1.98 +#endif
    1.99 +
   1.100 +#if SH_COMP==SH_COMP_MSVC
   1.101 +# define vsnprintf _vsnprintf
   1.102 +#endif
   1.103 +
   1.104 +#if SH_SYS != SH_SYS_WIN32
   1.105 +# include <unistd.h>
   1.106 +#endif
   1.107 +
   1.108 +#define SH_PTRSIZE sizeof(void*)
   1.109 +
   1.110 +#include "sh_memfuncinfo.h"
   1.111 +#include "FastDelegate.h"
   1.112 +
   1.113 +// Good old metamod!
   1.114 +
   1.115 +// Flags returned by a plugin's api function.
   1.116 +// NOTE: order is crucial, as greater/less comparisons are made.
   1.117 +enum META_RES
   1.118 +{
   1.119 +	MRES_IGNORED=0,		// plugin didn't take any action
   1.120 +	MRES_HANDLED,		// plugin did something, but real function should still be called
   1.121 +	MRES_OVERRIDE,		// call real function, but use my return value
   1.122 +	MRES_SUPERCEDE		// skip real function; use my return value
   1.123 +};
   1.124 +
   1.125 +
   1.126 +namespace SourceHook
   1.127 +{
   1.128 +	/**
   1.129 +	*	@brief	Specifies the size (in bytes) for the internal buffer of vafmt(printf-like) function handlers
   1.130 +	*/
   1.131 +	const int STRBUF_LEN=4096;
   1.132 +
   1.133 +	/**
   1.134 +	*	@brief	An empty class. No inheritance used. Used for original-function-call hacks
   1.135 +	*/
   1.136 +	class EmptyClass
   1.137 +	{
   1.138 +	};
   1.139 +
   1.140 +	/**
   1.141 +	*	@brief Implicit cast.
   1.142 +	*/
   1.143 +	template <class In, class Out>
   1.144 +		inline Out implicit_cast(In input)
   1.145 +		{
   1.146 +			return input;
   1.147 +		}
   1.148 +
   1.149 +	/**
   1.150 +	*	@brief A plugin typedef
   1.151 +	*
   1.152 +	*	SourceHook doesn't really care what this is. As long as the ==, != and = operators work on it and every
   1.153 +	*	plugin has a unique identifier, everything is ok.
   1.154 +	*	It should also be possible to set it to 0.
   1.155 +	*/
   1.156 +	typedef int Plugin;
   1.157 +
   1.158 +
   1.159 +	template <class T> class CallClass : public T
   1.160 +	{
   1.161 +	};
   1.162 +	typedef void ManualCallClass;
   1.163 +
   1.164 +	/**
   1.165 +	*	@brief Describes the way a parameter/retval is passed.
   1.166 +	*/
   1.167 +	struct PassInfo
   1.168 +	{
   1.169 +		enum PassType
   1.170 +		{
   1.171 +			PassType_Unknown=0,		/**< Unknown -- no extra info available */
   1.172 +			PassType_Basic,			/**< Plain old register data (pointers, integers) */
   1.173 +			PassType_Float,			/**< Floating point data */
   1.174 +			PassType_Object,		/**< Object or structure */
   1.175 +		};
   1.176 +
   1.177 +		enum PassFlags
   1.178 +		{
   1.179 +			PassFlag_ByVal		= (1<<0),		/**< Passing by value */
   1.180 +			PassFlag_ByRef		= (1<<1),		/**< Passing by reference */
   1.181 +			PassFlag_ODtor		= (1<<2),		/**< Object has a destructor */
   1.182 +			PassFlag_OCtor		= (1<<3),		/**< Object has a normal non-trivial constructor */
   1.183 +			PassFlag_AssignOp	= (1<<4),		/**< Object has a non-trivial assignment operator */
   1.184 +			PassFlag_CCtor		= (1<<5),		/**< Object has a copy constructor (which takes const Object& as only parameter) */
   1.185 +
   1.186 +			// The following two flags are only relevant for byval return types.
   1.187 +			// SH tries to auto-detect these
   1.188 +			// If you want to override SH's auto-detection, pass them in yourself
   1.189 +			PassFlag_RetMem		= (1<<6),		/**< Object is returned in memory (through hidden first param */
   1.190 +			PassFlag_RetReg		= (1<<7)		/**< Object is returned in EAX(:EDX) */
   1.191 +		};
   1.192 +
   1.193 +		size_t size;			//!< Size of the data being passed
   1.194 +
   1.195 +		// Extra info:
   1.196 +		//  (might be used in future versions for automatic hookfunc generation)
   1.197 +		int type;				//!< PassType value
   1.198 +		unsigned int flags;		//!< Pass/return flags
   1.199 +
   1.200 +		struct V2Info
   1.201 +		{
   1.202 +			void *pNormalCtor;
   1.203 +			void *pCopyCtor;
   1.204 +			void *pDtor;
   1.205 +			void *pAssignOperator;
   1.206 +		};
   1.207 +	};
   1.208 +
   1.209 +	struct ProtoInfo
   1.210 +	{
   1.211 +		enum CallConvention
   1.212 +		{
   1.213 +			CallConv_Unknown,		/**< Unknown  -- no extra info available (0)*/
   1.214 +			CallConv_ThisCall,		/**< This call (object pointer required) (1)*/
   1.215 +			CallConv_Cdecl,			/**< C call								 (2)*/
   1.216 +			CallConv_StdCall,		/**< Windows "stdcall"					 (3)*/
   1.217 +
   1.218 +			CallConv_HasVarArgs = (1<<16),	/**< Has variable arguments */
   1.219 +			CallConv_HasVafmt = CallConv_HasVarArgs | (1<<17)	/**< last params: const char*, ... */
   1.220 +		};
   1.221 +
   1.222 +		int numOfParams;			//!< number of parameters
   1.223 +		PassInfo retPassInfo;		//!< PassInfo for the return value. size=0 -> no retval
   1.224 +		const PassInfo *paramsPassInfo;	//!< PassInfos for the parameters
   1.225 +
   1.226 +		// paramsPassInfo[0] is basically a dummy parameter.
   1.227 +		// However, paramsPassInfo[0].size stores the version of the ProtoInfo structure.
   1.228 +
   1.229 +		// Extra info:
   1.230 +		int convention;
   1.231 +
   1.232 +		// Version2:
   1.233 +		PassInfo::V2Info retPassInfo2;
   1.234 +		const PassInfo::V2Info *paramsPassInfo2;
   1.235 +	};
   1.236 +
   1.237 +	struct IHookManagerInfo;
   1.238 +
   1.239 +	/**
   1.240 +	*	@brief Pointer to hook manager interface function
   1.241 +	*
   1.242 +	*	The hook manager should store hi for later use if store==true. It should then call hi->SetInfo(...) if hi
   1.243 +	*   is non-null. The hook manager can return 0 for success or a non-zero value if it doesn't want to be used.
   1.244 +	*
   1.245 +	*	@param hi A pointer to IHookManagerInfo
   1.246 +	*/
   1.247 +	typedef int (*HookManagerPubFunc)(bool store, IHookManagerInfo *hi);
   1.248 +
   1.249 +	class ISHDelegate
   1.250 +	{
   1.251 +	public:
   1.252 +		virtual bool IsEqual(ISHDelegate *pOtherDeleg) = 0;		// pOtherDeleg is from the same plugin and hookman
   1.253 +		virtual void DeleteThis() = 0;
   1.254 +	};
   1.255 +
   1.256 +	struct IHookManagerInfo
   1.257 +	{
   1.258 +		virtual void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
   1.259 +			ProtoInfo *proto, void *hookfunc_vfnptr) = 0;
   1.260 +	};
   1.261 +
   1.262 +	// I'm adding support for functions which return references.
   1.263 +
   1.264 +	// How it works:
   1.265 +	//  SH_SETUPCALLS doesn't use plain rettype to store the temporary return values (plugin ret, orig ret,
   1.266 +	//  override ret) anymore; instead, it uses SourceHook::ReferenceCarrier<rettype>::type
   1.267 +	//  this is typedefed to the original rettype normally, but if the rettype is a reference, it's a special class
   1.268 +	//  which stores the reference as a pointer, and implements constructors, operator= and a conversion operator.
   1.269 +	//  special cases were needed for getoverrideret / getorigret; these are implemented through the
   1.270 +	//  SourceHook::MacroRefHelpers structs.
   1.271 +	//  Furthermore, SetOverrideRet had to be changed a bit; see SourceHook::OverrideFunctor somewhere down in this file.
   1.272 +	template <class T> struct ReferenceCarrier
   1.273 +	{
   1.274 +		typedef T type;
   1.275 +	};
   1.276 +
   1.277 +	template <class T> struct ReferenceCarrier<T&>
   1.278 +	{
   1.279 +		class type
   1.280 +		{
   1.281 +			T *m_StoredRef;
   1.282 +		public:
   1.283 +			type() : m_StoredRef(NULL)
   1.284 +			{
   1.285 +			}
   1.286 +			type(T& ref) : m_StoredRef(&ref)
   1.287 +			{
   1.288 +			}
   1.289 +
   1.290 +			T& operator= (T& ref)
   1.291 +			{
   1.292 +				m_StoredRef = &ref;
   1.293 +				return ref;
   1.294 +			}
   1.295 +
   1.296 +			operator T& () const
   1.297 +			{
   1.298 +				return *m_StoredRef;
   1.299 +			}
   1.300 +		};
   1.301 +	};
   1.302 +
   1.303 +	struct IHookContext
   1.304 +	{
   1.305 +		virtual ISHDelegate *GetNext() = 0;
   1.306 +		virtual void *GetOverrideRetPtr() = 0;
   1.307 +		virtual const void *GetOrigRetPtr() = 0;
   1.308 +		virtual bool ShouldCallOrig() = 0;
   1.309 +	};
   1.310 +
   1.311 +	/**
   1.312 +	*	@brief The main SourceHook interface
   1.313 +	*/
   1.314 +	class ISourceHook
   1.315 +	{
   1.316 +	public:
   1.317 +		/**
   1.318 +		*	@brief Return interface version
   1.319 +		*/
   1.320 +		virtual int GetIfaceVersion() = 0;
   1.321 +
   1.322 +		/**
   1.323 +		*	@brief Return implementation version
   1.324 +		*/
   1.325 +		virtual int GetImplVersion() = 0;
   1.326 +
   1.327 +		/**
   1.328 +		*	@brief Modes for the new AddHook
   1.329 +		*/
   1.330 +		enum AddHookMode
   1.331 +		{
   1.332 +			Hook_Normal,
   1.333 +			Hook_VP,
   1.334 +			Hook_DVP
   1.335 +		}; 
   1.336 +
   1.337 +		/**
   1.338 +		*	@brief Add a (VP) hook.
   1.339 +		*
   1.340 +		*	@return non-zero hook id on success, 0 otherwise
   1.341 +		*
   1.342 +		*	@param plug The unique identifier of the plugin that calls this function
   1.343 +		*	@param mode	Can be either Hook_Normal or Hook_VP (vtable-wide hook)
   1.344 +		*	@param iface The interface pointer
   1.345 +		*	@param ifacesize The size of the class iface points to
   1.346 +		*	@param myHookMan A hook manager function that should be capable of handling the function
   1.347 +		*	@param handler A pointer to the hook handler something
   1.348 +		*	@param post Set to true if you want a post handler
   1.349 +		*/
   1.350 +		virtual int AddHook(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
   1.351 +			ISHDelegate *handler, bool post) = 0;
   1.352 +
   1.353 +		// Source backwarts compat (only for normal hooks)
   1.354 +		virtual bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
   1.355 +			ISHDelegate *handler, bool post) = 0;
   1.356 +
   1.357 +		/**
   1.358 +		*	@brief Remove a hook by ID.
   1.359 +		*
   1.360 +		*	@return true on success, false otherwise
   1.361 +		*
   1.362 +		*	@param hookid The hook id (returned by AddHook)
   1.363 +		*/
   1.364 +		virtual bool RemoveHookByID(int hookid) = 0;
   1.365 +
   1.366 +		/**
   1.367 +		*	@brief Pause a hook by ID.
   1.368 +		*
   1.369 +		*	@return true on success, false otherwise
   1.370 +		*
   1.371 +		*	@param hookid The hook id (returned by AddHook)
   1.372 +		*/
   1.373 +		virtual bool PauseHookByID(int hookid) = 0;
   1.374 +
   1.375 +		/**
   1.376 +		*	@brief Unpause a hook by ID.
   1.377 +		*
   1.378 +		*	@return true on success, false otherwise
   1.379 +		*
   1.380 +		*	@param hookid The hook id (returned by AddHook)
   1.381 +		*/
   1.382 +		virtual bool UnpauseHookByID(int hookid) = 0;
   1.383 +
   1.384 +		/**
   1.385 +		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
   1.386 +		*
   1.387 +		*	@param plug The unique identifier of the plugin in question
   1.388 +		*/
   1.389 +
   1.390 +		virtual void SetRes(META_RES res) = 0;				//!< Sets the meta result
   1.391 +		virtual META_RES GetPrevRes() = 0;					//!< Gets the meta result of the
   1.392 +															//!<  previously calledhandler
   1.393 +		virtual META_RES GetStatus() = 0;					//!< Gets the highest meta result
   1.394 +		virtual const void *GetOrigRet() = 0;				//!< Gets the original result.
   1.395 +															//!<  If not in post function, undefined
   1.396 +		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result.
   1.397 +															//!<  If none is specified, NULL
   1.398 +		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   1.399 +
   1.400 +		virtual void *GetOverrideRetPtr() = 0;				//!< Used for setting the override return value
   1.401 +
   1.402 +		/**
   1.403 +		*	@brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
   1.404 +		*
   1.405 +		*	@param plug The owner of the hook manager
   1.406 +		*   @param pubFunc The hook manager's info function
   1.407 +		*/
   1.408 +		virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
   1.409 +
   1.410 +		// For SH_CALL:
   1.411 +
   1.412 +		/**
   1.413 +		*	@brief Makes sure that hooks are going to be ignored on the next call of vfnptr
   1.414 +		*
   1.415 +		*	@param plug The unique identifier of the plugin that calls this function
   1.416 +		*	@param vfnptr The virtual function pointer of the function in question
   1.417 +		*/
   1.418 +		virtual void SetIgnoreHooks(void *vfnptr) = 0;
   1.419 +
   1.420 +		/**
   1.421 +		*	@brief Reverses SetIgnoreHooks' effect
   1.422 +		*
   1.423 +		*	@param plug The unique identifier of the plugin that calls this function
   1.424 +		*	@param vfnptr The virtual function pointer of the function in question
   1.425 +		*/
   1.426 +		virtual void ResetIgnoreHooks(void *vfnptr) = 0;
   1.427 +
   1.428 +		/**
   1.429 +		*	@brief Finds the original entry of a virtual function pointer
   1.430 +		*
   1.431 +		*	@param vfnptr The virtual function pointer
   1.432 +		*	@return The original entry if the virtual function pointer has been patched; NULL otherwise.
   1.433 +		*/
   1.434 +		virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
   1.435 +
   1.436 +		//////////////////////////////////////////////////////////////////////////
   1.437 +
   1.438 +		// For hook managers	
   1.439 +
   1.440 +		// Returns the current iface ptr
   1.441 +		virtual void DoRecall() = 0;							//!< Initiates a recall sequence
   1.442 +
   1.443 +		/*
   1.444 +			HOW RECALLS WORK:
   1.445 +			
   1.446 +			The problem:
   1.447 +				Users want the ability to change parameters of the called function
   1.448 +				from inside their handler.
   1.449 +			The solution:
   1.450 +				1) Mark as "recall"
   1.451 +				2) Recall the function
   1.452 +				3) => SH's hook func gets called:
   1.453 +				  4) The first iterator points at the first hook the last hookfunc didn't execute yet
   1.454 +				  5) does all iteration and returns normally
   1.455 +		        6) The user's handler returns immediately
   1.456 +				7) The hook func returns immediately as well
   1.457 +
   1.458 +				Also note that the recalled hookfunc starts with the status the recalling hookfunc
   1.459 +				ended with. The last handler (doing the recall) is also able to specify its own
   1.460 +				META_RES.
   1.461 +		*/
   1.462 +
   1.463 +		/**
   1.464 +		*	@brief Set up the hook loop.
   1.465 +		*
   1.466 +		*	@param statusPtr		pointer to status variable
   1.467 +		*	@param prevResPtr		pointer to previous result variable
   1.468 +		*	@param curResPtr		pointer to current result variable
   1.469 +		*	@param ifacePtrPtr		pointer to interface this pointer variable
   1.470 +		*	@param origRetPr		pointer to original return value variable. NULL for void funcs
   1.471 +		*	@param overrideRetPtr	pointer to override return value variable. NULL for void funcs
   1.472 +		*	
   1.473 +		*	@return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
   1.474 +		*		when the hook func is being called as part of a recall
   1.475 +		*/
   1.476 +		virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
   1.477 +			META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
   1.478 +			const void *origRetPtr, void *overrideRetPtr) = 0;
   1.479 +
   1.480 +		virtual void EndContext(IHookContext *pCtx) = 0;
   1.481 +	};
   1.482 +
   1.483 +
   1.484 +	class IHookManagerAutoGen
   1.485 +	{
   1.486 +	public:
   1.487 +		virtual int GetIfaceVersion() = 0;
   1.488 +		virtual int GetImplVersion() = 0;
   1.489 +		
   1.490 +		virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
   1.491 +		virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
   1.492 +	};
   1.493 +	
   1.494 +	// For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
   1.495 +	//  These have to be able to return references. If T is a reference, the pointers returned
   1.496 +	//  from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
   1.497 +	template <class T> struct MacroRefHelpers
   1.498 +	{
   1.499 +		inline static const T* GetOrigRet(ISourceHook *shptr)
   1.500 +		{
   1.501 +			return reinterpret_cast<const T*>(shptr->GetOrigRet());
   1.502 +		}
   1.503 +		inline static const T* GetOverrideRet(ISourceHook *shptr)
   1.504 +		{
   1.505 +			return reinterpret_cast<const T*>(shptr->GetOverrideRet());
   1.506 +		}
   1.507 +	};
   1.508 +
   1.509 +	template <class T> struct MacroRefHelpers<T&>
   1.510 +	{
   1.511 +		inline static T* GetOrigRet(ISourceHook *shptr)
   1.512 +		{
   1.513 +			T &ref = *reinterpret_cast<const typename ReferenceCarrier<T&>::type *>(shptr->GetOrigRet());
   1.514 +			return &ref;
   1.515 +		}
   1.516 +		inline static T* GetOverrideRet(ISourceHook *shptr)
   1.517 +		{
   1.518 +			T &ref = *reinterpret_cast<const typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRet());
   1.519 +			return &ref;
   1.520 +		}
   1.521 +	};
   1.522 +
   1.523 +	template <class X, class MFP>
   1.524 +		void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
   1.525 +	{
   1.526 +		SourceHook::MemFuncInfo info = {true, -1, 0, 0};
   1.527 +		SourceHook::GetFuncInfo(pInstance, mfp, info);
   1.528 +
   1.529 +		void *vfnptr = reinterpret_cast<void*>(
   1.530 +			*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
   1.531 +
   1.532 +		void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
   1.533 +
   1.534 +		return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
   1.535 +	}
   1.536 +
   1.537 +	template <class T> struct GetPassInfo
   1.538 +	{
   1.539 +		static const int type = 0;
   1.540 +		static const unsigned int flags = PassInfo::PassFlag_ByVal;
   1.541 +	};
   1.542 +
   1.543 +	template <class T> struct GetPassInfo<T&>
   1.544 +	{
   1.545 +		static const int type = 0;
   1.546 +		static const unsigned int flags = PassInfo::PassFlag_ByRef;
   1.547 +	};
   1.548 +}
   1.549 +
   1.550 +/************************************************************************/
   1.551 +/* High level interface                                                 */
   1.552 +/************************************************************************/
   1.553 +#define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
   1.554 +#define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
   1.555 +#define META_RESULT_ORIG_RET(type)			*SourceHook::MacroRefHelpers<type>::GetOrigRet(SH_GLOB_SHPTR)
   1.556 +#define META_RESULT_OVERRIDE_RET(type)		*SourceHook::MacroRefHelpers<type>::GetOverrideRet(SH_GLOB_SHPTR)
   1.557 +#define META_IFACEPTR(type)					reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
   1.558 +
   1.559 +#define SET_META_RESULT(result)				SH_GLOB_SHPTR->SetRes(result)
   1.560 +#define RETURN_META(result)					do { SET_META_RESULT(result); return; } while(0)
   1.561 +#define RETURN_META_VALUE(result, value)	do { SET_META_RESULT(result); return (value); } while(0)
   1.562 +
   1.563 +
   1.564 +template<class T>
   1.565 +SourceHook::CallClass<T> *SH_GET_CALLCLASS(T *p)
   1.566 +{
   1.567 +	return static_cast< SourceHook::CallClass<T> *>(p);
   1.568 +}
   1.569 +#define SH_RELEASE_CALLCLASS(p)
   1.570 +
   1.571 +#define SH_GET_MCALLCLASS(p, size) reinterpret_cast<void*>(p)
   1.572 +
   1.573 +// only call these from the hook handlers directly!
   1.574 +
   1.575 +// If a hook on a function which returns a reference does not want to specify a return value,
   1.576 +// it can use this macro.
   1.577 +//   ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
   1.578 +#define RETURN_META_NOREF(result, rettype)	do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
   1.579 +
   1.580 +// Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
   1.581 +// Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
   1.582 +
   1.583 +// SourceHook::SetOverrideRet is defined later.
   1.584 +#define RETURN_META_NEWPARAMS(result, memfuncptr, newparams) \
   1.585 +	do { \
   1.586 +		SET_META_RESULT(result); \
   1.587 +		SH_GLOB_SHPTR->DoRecall(); \
   1.588 +		(SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams; \
   1.589 +		RETURN_META(MRES_SUPERCEDE); \
   1.590 +	} while (0)
   1.591 +
   1.592 +#define RETURN_META_VALUE_NEWPARAMS(result, value, memfuncptr, newparams) \
   1.593 +	do { \
   1.594 +		SET_META_RESULT(result); \
   1.595 +		SH_GLOB_SHPTR->DoRecall(); \
   1.596 +		if ((result) >= MRES_OVERRIDE) \
   1.597 +		{ \
   1.598 +			/* meh, set the override result here because we don't get a chance to return */ \
   1.599 +			/* before continuing the hook loop through the recall */ \
   1.600 +			SourceHook::SetOverrideResult(memfuncptr)(SH_GLOB_SHPTR, value); \
   1.601 +		} \
   1.602 +		RETURN_META_VALUE(MRES_SUPERCEDE, \
   1.603 +			(SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams); \
   1.604 +	} while (0)
   1.605 +
   1.606 +// :TODO: thisptroffs in MNEWPARAMS ??
   1.607 +
   1.608 +#if SH_COMP == SH_COMP_MSVC
   1.609 +
   1.610 +#define SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname) \
   1.611 +	union \
   1.612 +	{ \
   1.613 +		SH_MFHCls(hookname)::ECMFP mfp; \
   1.614 +		void *addr; \
   1.615 +	} u; \
   1.616 +	u.addr = (*reinterpret_cast<void***>(reinterpret_cast<char*>(thisptr) + SH_MFHCls(hookname)::ms_MFI.vtbloffs))[ \
   1.617 +		SH_MFHCls(hookname)::ms_MFI.vtblindex];
   1.618 +
   1.619 +#elif SH_COMP == SH_COMP_GCC
   1.620 +
   1.621 +#define SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname) \
   1.622 +	union \
   1.623 +	{ \
   1.624 +		SH_MFHCls(hookname)::ECMFP mfp; \
   1.625 +		struct \
   1.626 +		{ \
   1.627 +			void *addr; \
   1.628 +			intptr_t adjustor; \
   1.629 +		} s; \
   1.630 +	} u; \
   1.631 +	u.s.addr = (*reinterpret_cast<void***>(reinterpret_cast<char*>(thisptr) + SH_MFHCls(hookname)::ms_MFI.vtbloffs))[ \
   1.632 +		SH_MFHCls(hookname)::ms_MFI.vtblindex]; \
   1.633 +	u.s.adjustor = 0;
   1.634 +
   1.635 +#endif
   1.636 +
   1.637 +#define RETURN_META_MNEWPARAMS(result, hookname, newparams) \
   1.638 +	do { \
   1.639 +		SET_META_RESULT(result); \
   1.640 +		SH_GLOB_SHPTR->DoRecall(); \
   1.641 +		SourceHook::EmptyClass *thisptr = reinterpret_cast<SourceHook::EmptyClass*>(SH_GLOB_SHPTR->GetIfacePtr()); \
   1.642 +		(thisptr->*(__SoureceHook_FHM_GetRecallMFP##hookname(thisptr))) newparams; \
   1.643 +		RETURN_META(MRES_SUPERCEDE); \
   1.644 +	} while (0)
   1.645 +
   1.646 +#define RETURN_META_VALUE_MNEWPARAMS(result, value, hookname, newparams) \
   1.647 +	do { \
   1.648 +		SET_META_RESULT(result); \
   1.649 +		SH_GLOB_SHPTR->DoRecall(); \
   1.650 +		if ((result) >= MRES_OVERRIDE) \
   1.651 +		{ \
   1.652 +			/* see RETURN_META_VALUE_NEWPARAMS */ \
   1.653 +			__SoureceHook_FHM_SetOverrideResult##hookname(SH_GLOB_SHPTR, value); \
   1.654 +		} \
   1.655 +		SourceHook::EmptyClass *thisptr = reinterpret_cast<SourceHook::EmptyClass*>(SH_GLOB_SHPTR->GetIfacePtr()); \
   1.656 +		RETURN_META_VALUE(MRES_SUPERCEDE, (thisptr->*(__SoureceHook_FHM_GetRecallMFP##hookname(thisptr))) newparams); \
   1.657 +	} while (0)
   1.658 +
   1.659 +
   1.660 +#define SH_MANUALHOOK_RECONFIGURE(hookname, pvtblindex, pvtbloffs, pthisptroffs) \
   1.661 +	__SourceHook_FHM_Reconfigure##hookname(pvtblindex, pvtbloffs, pthisptroffs)
   1.662 +
   1.663 +#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
   1.664 +
   1.665 +// New ADD / REMOVE macros.
   1.666 +#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
   1.667 +#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
   1.668 +
   1.669 +#define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.670 +	__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.671 +	SourceHook::ISourceHook::Hook_Normal, post, handler)
   1.672 +
   1.673 +#define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.674 +	__SourceHook_FHRemove##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.675 +	post, handler) 
   1.676 +
   1.677 +#define SH_ADD_MANUALHOOK(hookname, ifaceptr, handler, post) \
   1.678 +	__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), \
   1.679 +	SourceHook::ISourceHook::Hook_Normal, post, handler)
   1.680 +
   1.681 +#define SH_REMOVE_MANUALHOOK(hookname, ifaceptr, handler, post) \
   1.682 +	__SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler) 
   1.683 +
   1.684 +#define SH_ADD_VPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.685 +	__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.686 +	SourceHook::ISourceHook::Hook_VP, post, handler)
   1.687 +
   1.688 +#define SH_ADD_DVPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.689 +	__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
   1.690 +	SourceHook::ISourceHook::Hook_DVP, post, handler)
   1.691 +
   1.692 +#define SH_ADD_MANUALVPHOOK(hookname, ifaceptr, handler, post) \
   1.693 +	__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), SourceHook::ISourceHook::Hook_VP, post, handler) 
   1.694 +
   1.695 +#define SH_ADD_MANUALDVPHOOK(hookname, ifaceptr, handler, post) \
   1.696 +	__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), SourceHook::ISourceHook::Hook_DVP, post, handler) 
   1.697 +
   1.698 +#define SH_REMOVE_HOOK_ID(hookid) \
   1.699 +	(SH_GLOB_SHPTR->RemoveHookByID(hookid))
   1.700 +
   1.701 +// Old macros
   1.702 +// !! These are now deprecated. Instead, use one of these:
   1.703 +//  SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.704 +//  SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
   1.705 +
   1.706 +#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.707 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.708 +#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.709 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.710 +
   1.711 +//  SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.712 +//  SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
   1.713 +
   1.714 +#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.715 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
   1.716 +#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.717 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.718 +
   1.719 +//  SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.720 +//  SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
   1.721 +
   1.722 +#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
   1.723 +	SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.724 +#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
   1.725 +	SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
   1.726 +
   1.727 +//  SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.728 +//  SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
   1.729 +
   1.730 +#define SH_REMOVE_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
   1.731 +	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
   1.732 +#define SH_REMOVE_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
   1.733 +	SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)  
   1.734 +
   1.735 +#define SH_NOATTRIB
   1.736 +
   1.737 +
   1.738 +
   1.739 +
   1.740 +#if SH_COMP == SH_COMP_MSVC
   1.741 +# define SH_SETUP_MFP(mfp) \
   1.742 +	reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry;
   1.743 +#elif SH_COMP == SH_COMP_GCC
   1.744 +# define SH_SETUP_MFP(mfp) \
   1.745 +	reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry; \
   1.746 +	reinterpret_cast<void**>(&mfp)[1] = 0;
   1.747 +#else
   1.748 +# error Not supported yet.
   1.749 +#endif
   1.750 +
   1.751 +//////////////////////////////////////////////////////////////////////////
   1.752 +#define SH_FHCls(ift, iff, ov) __SourceHook_FHCls_##ift##iff##ov
   1.753 +#define SH_MFHCls(hookname) __SourceHook_MFHCls_##hookname
   1.754 +
   1.755 +#define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   1.756 +	static int HookManPubFunc(bool store, ::SourceHook::IHookManagerInfo *hi) \
   1.757 +	{ \
   1.758 +		using namespace ::SourceHook; \
   1.759 +		GetFuncInfo(funcptr, ms_MFI); \
   1.760 +		/* Verify interface version */ \
   1.761 +		if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
   1.762 +			return 1; \
   1.763 +		if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
   1.764 +			return 1; \
   1.765 +		if (store) \
   1.766 +			ms_HI = hi; \
   1.767 +		if (hi) \
   1.768 +		{ \
   1.769 +			MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.770 +			GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
   1.771 +			hi->SetInfo(SH_HOOKMAN_VERSION, ms_MFI.vtbloffs, ms_MFI.vtblindex, &ms_Proto, \
   1.772 +				reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex] ); \
   1.773 +		} \
   1.774 +		return 0; \
   1.775 +	}
   1.776 +
   1.777 +// It has to be possible to use the macros in namespaces
   1.778 +// -> So we need to access and extend the global SourceHook namespace
   1.779 +// We use a namespace alias for this
   1.780 +#define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
   1.781 +	struct SH_FHCls(ifacetype,ifacefunc,overload) \
   1.782 +	{ \
   1.783 +		static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   1.784 +		static ::SourceHook::MemFuncInfo ms_MFI; \
   1.785 +		static ::SourceHook::IHookManagerInfo *ms_HI; \
   1.786 +		static ::SourceHook::ProtoInfo ms_Proto; \
   1.787 +		SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   1.788 +
   1.789 +#define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, funcptr) \
   1.790 +	}; \
   1.791 +	SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   1.792 +	::SourceHook::MemFuncInfo SH_FHCls(ifacetype,ifacefunc,overload)::ms_MFI; \
   1.793 +	::SourceHook::IHookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   1.794 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
   1.795 +		SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.796 +	{ \
   1.797 +		using namespace ::SourceHook; \
   1.798 +		MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.799 +		GetFuncInfo(funcptr, mfi); \
   1.800 +		if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
   1.801 +			return false; /* No non-virtual functions / virtual inheritance supported */ \
   1.802 +		\
   1.803 +		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, mode, \
   1.804 +			iface, mfi.thisptroffs, SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   1.805 +			new SH_FHCls(ifacetype,ifacefunc,overload)::CMyDelegateImpl(handler), post); \
   1.806 +	} \
   1.807 +	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   1.808 +		SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.809 +	{ \
   1.810 +		using namespace ::SourceHook; \
   1.811 +		MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.812 +		GetFuncInfo(funcptr, mfi); \
   1.813 +		SH_FHCls(ifacetype,ifacefunc,overload)::CMyDelegateImpl tmp(handler); \
   1.814 +		return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
   1.815 +			SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
   1.816 +	} \
   1.817 +
   1.818 +#define SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
   1.819 +	struct SH_MFHCls(hookname) \
   1.820 +	{ \
   1.821 +		static SH_MFHCls(hookname) ms_Inst; \
   1.822 +		static ::SourceHook::MemFuncInfo ms_MFI; \
   1.823 +		static ::SourceHook::IHookManagerInfo *ms_HI; \
   1.824 +		static ::SourceHook::ProtoInfo ms_Proto; \
   1.825 +		\
   1.826 +		SH_MFHCls(hookname)() \
   1.827 +		{ \
   1.828 +			ms_MFI.isVirtual = true; \
   1.829 +			ms_MFI.thisptroffs = pthisptroffs; \
   1.830 +			ms_MFI.vtblindex = pvtblidx; \
   1.831 +			ms_MFI.vtbloffs = pvtbloffs; \
   1.832 +		} \
   1.833 +		static int HookManPubFunc(bool store, ::SourceHook::IHookManagerInfo *hi) \
   1.834 +		{ \
   1.835 +			using namespace ::SourceHook; \
   1.836 +			/* Verify interface version */ \
   1.837 +			if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
   1.838 +				return 1; \
   1.839 +			if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
   1.840 +				return 1; \
   1.841 +			if (store) \
   1.842 +				ms_HI = hi; \
   1.843 +			if (hi) \
   1.844 +			{ \
   1.845 +				MemFuncInfo mfi = {true, -1, 0, 0}; \
   1.846 +				GetFuncInfo(&SH_MFHCls(hookname)::Func, mfi); \
   1.847 +				hi->SetInfo(SH_HOOKMAN_VERSION, ms_MFI.vtbloffs, ms_MFI.vtblindex, &ms_Proto, \
   1.848 +					reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex] ); \
   1.849 +			} \
   1.850 +			return 0; \
   1.851 +		}
   1.852 +
   1.853 +#define SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
   1.854 +	}; \
   1.855 +	SH_MFHCls(hookname) SH_MFHCls(hookname)::ms_Inst; \
   1.856 +	::SourceHook::MemFuncInfo SH_MFHCls(hookname)::ms_MFI; \
   1.857 +	::SourceHook::IHookManagerInfo *SH_MFHCls(hookname)::ms_HI; \
   1.858 +	int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
   1.859 +		SH_MFHCls(hookname)::FD handler) \
   1.860 +	{ \
   1.861 +		return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, mode, \
   1.862 +			iface, pthisptroffs, SH_MFHCls(hookname)::HookManPubFunc, \
   1.863 +			new SH_MFHCls(hookname)::CMyDelegateImpl(handler), post); \
   1.864 +	} \
   1.865 +	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
   1.866 +		SH_MFHCls(hookname)::FD handler) \
   1.867 +	{ \
   1.868 +		SH_MFHCls(hookname)::CMyDelegateImpl tmp(handler); \
   1.869 +		return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
   1.870 +			SH_MFHCls(hookname)::HookManPubFunc, &tmp, post); \
   1.871 +	} \
   1.872 +	SH_MFHCls(hookname)::ECMFP __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) \
   1.873 +	{ \
   1.874 +		SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname); \
   1.875 +		return u.mfp; \
   1.876 +	} \
   1.877 +	SH_MFHCls(hookname)::CallEC __SoureceHook_FHM_SHCall##hookname(void *ptr) \
   1.878 +	{ \
   1.879 +		SH_MFHCls(hookname)::ECMFP mfp; \
   1.880 +		void *vfnptr = reinterpret_cast<void*>( \
   1.881 +			*reinterpret_cast<void***>( (reinterpret_cast<char*>(ptr) + SH_MFHCls(hookname)::ms_MFI.thisptroffs + SH_MFHCls(hookname)::ms_MFI.vtbloffs) ) + SH_MFHCls(hookname)::ms_MFI.vtblindex); \
   1.882 +		/* patch mfp */ \
   1.883 +		*reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr); \
   1.884 +		if (sizeof(mfp) == 2*sizeof(void*)) /* gcc */ \
   1.885 +			*(reinterpret_cast<void**>(&mfp) + 1) = 0; \
   1.886 +		return SH_MFHCls(hookname)::CallEC(reinterpret_cast< ::SourceHook::EmptyClass* >(ptr), mfp, vfnptr, SH_GLOB_SHPTR); \
   1.887 +	} \
   1.888 +	void __SourceHook_FHM_Reconfigure##hookname(int p_vtblindex, int p_vtbloffs, int p_thisptroffs) \
   1.889 +	{ \
   1.890 +		SH_GLOB_SHPTR->RemoveHookManager(SH_GLOB_PLUGPTR, SH_MFHCls(hookname)::HookManPubFunc); \
   1.891 +		SH_MFHCls(hookname)::ms_MFI.thisptroffs = p_thisptroffs; \
   1.892 +		SH_MFHCls(hookname)::ms_MFI.vtblindex = p_vtblindex; \
   1.893 +		SH_MFHCls(hookname)::ms_MFI.vtbloffs = p_vtbloffs; \
   1.894 +	}
   1.895 +
   1.896 +#define SH_SETUPCALLS(rettype, paramtypes, params) \
   1.897 +	/* 1) Set up */ \
   1.898 +	using namespace ::SourceHook; \
   1.899 +	void *ourvfnptr = reinterpret_cast<void*>( \
   1.900 +		*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
   1.901 +	void *vfnptr_origentry; \
   1.902 +	\
   1.903 +	META_RES status = MRES_IGNORED; \
   1.904 +	META_RES prev_res; \
   1.905 +	META_RES cur_res; \
   1.906 +	\
   1.907 +	typedef ReferenceCarrier< rettype >::type my_rettype; \
   1.908 +	my_rettype orig_ret; \
   1.909 +	my_rettype override_ret; \
   1.910 +	my_rettype plugin_ret; \
   1.911 +	IMyDelegate *iter; \
   1.912 +	IHookContext *pContext = SH_GLOB_SHPTR->SetupHookLoop(ms_HI, ourvfnptr, reinterpret_cast<void*>(this), \
   1.913 +		&vfnptr_origentry, &status, &prev_res, &cur_res, &orig_ret, &override_ret);
   1.914 +
   1.915 +#define SH_CALL_HOOKS(post, params) \
   1.916 +	prev_res = MRES_IGNORED; \
   1.917 +	while ( (iter = static_cast<IMyDelegate*>(pContext->GetNext())) ) \
   1.918 +	{ \
   1.919 +		cur_res = MRES_IGNORED; \
   1.920 +		plugin_ret = iter->Call params; \
   1.921 +		prev_res = cur_res; \
   1.922 +		if (cur_res > status) \
   1.923 +			status = cur_res; \
   1.924 +		if (cur_res >= MRES_OVERRIDE) \
   1.925 +			*reinterpret_cast<my_rettype*>(pContext->GetOverrideRetPtr()) = plugin_ret; \
   1.926 +	}
   1.927 +
   1.928 +#define SH_CALL_ORIG(rettype, paramtypes, params) \
   1.929 +	if (status != MRES_SUPERCEDE && pContext->ShouldCallOrig()) \
   1.930 +	{ \
   1.931 +		rettype (EmptyClass::*mfp)paramtypes; \
   1.932 +		SH_SETUP_MFP(mfp); \
   1.933 +		orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
   1.934 +	} \
   1.935 +	else \
   1.936 +		orig_ret = override_ret; /* :TODO: ??? : use pContext->GetOverrideRetPtr() or not? */
   1.937 +
   1.938 +#define SH_RETURN() \
   1.939 +	const my_rettype *retptr = reinterpret_cast<const my_rettype*>( \
   1.940 +		(status >= MRES_OVERRIDE) ? pContext->GetOverrideRetPtr() : pContext->GetOrigRetPtr()); \
   1.941 +	SH_GLOB_SHPTR->EndContext(pContext); \
   1.942 +	return *retptr;
   1.943 +
   1.944 +#define SH_HANDLEFUNC(paramtypes, params, rettype) \
   1.945 +	SH_SETUPCALLS(rettype, paramtypes, params) \
   1.946 +	SH_CALL_HOOKS(pre, params) \
   1.947 +	SH_CALL_ORIG(rettype, paramtypes, params) \
   1.948 +	SH_CALL_HOOKS(post, params) \
   1.949 +	SH_RETURN()
   1.950 +
   1.951 +//////////////////////////////////////////////////////////////////////////
   1.952 +#define SH_SETUPCALLS_void(paramtypes, params) \
   1.953 +	/* 1) Set up */ \
   1.954 +	using namespace ::SourceHook; \
   1.955 +	void *ourvfnptr = reinterpret_cast<void*>( \
   1.956 +		*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
   1.957 +	void *vfnptr_origentry; \
   1.958 +	\
   1.959 +	META_RES status = MRES_IGNORED; \
   1.960 +	META_RES prev_res; \
   1.961 +	META_RES cur_res; \
   1.962 +	\
   1.963 +	IMyDelegate *iter; \
   1.964 +	IHookContext *pContext = SH_GLOB_SHPTR->SetupHookLoop(ms_HI, ourvfnptr, reinterpret_cast<void*>(this), \
   1.965 +		&vfnptr_origentry, &status, &prev_res, &cur_res, NULL, NULL);
   1.966 +
   1.967 +#define SH_CALL_HOOKS_void(post, params) \
   1.968 +	prev_res = MRES_IGNORED; \
   1.969 +	while ( (iter = static_cast<IMyDelegate*>(pContext->GetNext())) ) \
   1.970 +	{ \
   1.971 +		cur_res = MRES_IGNORED; \
   1.972 +		iter->Call params; \
   1.973 +		prev_res = cur_res; \
   1.974 +		if (cur_res > status) \
   1.975 +			status = cur_res; \
   1.976 +	}
   1.977 +
   1.978 +#define SH_CALL_ORIG_void(paramtypes, params) \
   1.979 +	if (status != MRES_SUPERCEDE && pContext->ShouldCallOrig()) \
   1.980 +	{ \
   1.981 +		void (EmptyClass::*mfp)paramtypes; \
   1.982 +		SH_SETUP_MFP(mfp); \
   1.983 +		(reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
   1.984 +	}
   1.985 +
   1.986 +#define SH_RETURN_void() \
   1.987 +	SH_GLOB_SHPTR->EndContext(pContext);
   1.988 +
   1.989 +#define SH_HANDLEFUNC_void(paramtypes, params) \
   1.990 +	SH_SETUPCALLS_void(paramtypes, params) \
   1.991 +	SH_CALL_HOOKS_void(pre, params) \
   1.992 +	SH_CALL_ORIG_void(paramtypes, params) \
   1.993 +	SH_CALL_HOOKS_void(post, params) \
   1.994 +	SH_RETURN_void()
   1.995 +
   1.996 +
   1.997 +// Special vafmt handlers
   1.998 +// :TODO: what
   1.999 +#define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
  1.1000 +	SH_SETUPCALLS(rettype, paramtypes, params_orig) \
  1.1001 +	SH_CALL_HOOKS(pre, params_plug) \
  1.1002 +	SH_CALL_ORIG(rettype, paramtypes, params_orig) \
  1.1003 +	SH_CALL_HOOKS(post, params_plug) \
  1.1004 +	SH_RETURN()
  1.1005 +
  1.1006 +#define SH_HANDLEFUNC_void_vafmt(paramtypes, params_orig, params_plug) \
  1.1007 +	SH_SETUPCALLS_void(paramtypes, params_orig) \
  1.1008 +	SH_CALL_HOOKS_void(pre, params_plug) \
  1.1009 +	SH_CALL_ORIG_void(paramtypes, params_orig) \
  1.1010 +	SH_CALL_HOOKS_void(post, params_plug) \
  1.1011 +	SH_RETURN_void()
  1.1012 +
  1.1013 +//////////////////////////////////////////////////////////////////////////
  1.1014 +
  1.1015 +#define MAKE_DELEG(ret_type, params_decl, params_pass) \
  1.1016 +	struct IMyDelegate : ::SourceHook::ISHDelegate { virtual ret_type Call params_decl = 0; }; \
  1.1017 +	struct CMyDelegateImpl : IMyDelegate \
  1.1018 +	{ \
  1.1019 +		FD m_Deleg; \
  1.1020 +		CMyDelegateImpl(FD deleg) : m_Deleg(deleg) {} \
  1.1021 +		ret_type Call params_decl { return m_Deleg params_pass; } \
  1.1022 +		void DeleteThis() { delete this; } \
  1.1023 +		bool IsEqual(ISHDelegate *pOtherDeleg) { return m_Deleg == static_cast<CMyDelegateImpl*>(pOtherDeleg)->m_Deleg; } \
  1.1024 +	};
  1.1025 +
  1.1026 +#define MAKE_DELEG_void(params_decl, params_pass) \
  1.1027 +	struct IMyDelegate : ::SourceHook::ISHDelegate { virtual void  Call params_decl = 0; }; \
  1.1028 +	struct CMyDelegateImpl : IMyDelegate \
  1.1029 +	{ \
  1.1030 +		FD m_Deleg; \
  1.1031 +		CMyDelegateImpl(FD deleg) : m_Deleg(deleg) {} \
  1.1032 +		void Call params_decl { m_Deleg params_pass; } \
  1.1033 +		void DeleteThis() { delete this; } \
  1.1034 +		bool IsEqual(ISHDelegate *pOtherDeleg) { return m_Deleg == static_cast<CMyDelegateImpl*>(pOtherDeleg)->m_Deleg; } \
  1.1035 +	};
  1.1036 +
  1.1037 +// GetPassInfo -> easier access. __SH_GPI generates a SourceHook::PassInfo instance.
  1.1038 +#define __SH_GPI(tt) { sizeof(tt), ::SourceHook::GetPassInfo< tt >::type, ::SourceHook::GetPassInfo< tt >::flags }
  1.1039 +// Extra pass info V2
  1.1040 +#define __SH_EPI { 0, 0, 0, 0 }
  1.1041 +
  1.1042 +#define __SH_VAFMT_SEQ(fmt, buf) \
  1.1043 +	char buf[::SourceHook::STRBUF_LEN]; \
  1.1044 +	va_list ap; \
  1.1045 +	va_start(ap, fmt); \
  1.1046 +	vsnprintf(buf, sizeof(buf), fmt, ap); \
  1.1047 +	buf[sizeof(buf) - 1] = 0; \
  1.1048 +	va_end(ap);
  1.1049 +
  1.1050 +@[$1,0,$a:
  1.1051 +// ********* Support for $1 arguments *********
  1.1052 +#define SH_DECL_HOOK$1(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
  1.1053 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
  1.1054 +		(&ifacetype::ifacefunc))) \
  1.1055 +		typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
  1.1056 +		MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
  1.1057 +		virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
  1.1058 +		{ SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
  1.1059 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
  1.1060 +		(static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
  1.1061 +	\
  1.1062 +	const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1063 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1064 +	::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, __SH_GPI(rettype), \
  1.1065 +		__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
  1.1066 +
  1.1067 +#define SH_DECL_EXTERN$1(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
  1.1068 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1069 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
  1.1070 +	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
  1.1071 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler);
  1.1072 +
  1.1073 +#define SH_DECL_HOOK$1_void(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
  1.1074 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
  1.1075 +		(&ifacetype::ifacefunc))) \
  1.1076 +		typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
  1.1077 +		MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
  1.1078 +		virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
  1.1079 +		{ SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
  1.1080 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
  1.1081 +		(static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
  1.1082 +	\
  1.1083 +	const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:,__SH_GPI(param$2)@] }; \
  1.1084 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1085 +	::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, { 0, 0, 0 }, \
  1.1086 +		__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
  1.1087 +
  1.1088 +#define SH_DECL_EXTERN$1_void(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
  1.1089 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1090 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
  1.1091 +	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
  1.1092 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler);
  1.1093 +
  1.1094 +#define SH_DECL_HOOK$1_vafmt(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
  1.1095 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
  1.1096 +		(&ifacetype::ifacefunc))) \
  1.1097 +		typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> FD; \
  1.1098 +		MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *px), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]px)); \
  1.1099 +		virtual rettype Func(@[$2,1,$1|, :param$2 p$2@] @[$1!=0:, @]const char *fmt, ...) \
  1.1100 +		{ \
  1.1101 +			__SH_VAFMT_SEQ(fmt, buf); \
  1.1102 +			SH_HANDLEFUNC_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf), rettype); \
  1.1103 +		} \
  1.1104 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
  1.1105 +		(static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
  1.1106 +	\
  1.1107 +	const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1108 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1109 +	::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, __SH_GPI(rettype), \
  1.1110 +		__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
  1.1111 +
  1.1112 +#define SH_DECL_EXTERN$1_vafmt(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
  1.1113 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1114 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> handler); \
  1.1115 +	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
  1.1116 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> handler);
  1.1117 +
  1.1118 +#define SH_DECL_HOOK$1_void_vafmt(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
  1.1119 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
  1.1120 +		(&ifacetype::ifacefunc))) \
  1.1121 +		typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> FD; \
  1.1122 +		MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *px), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]px)); \
  1.1123 +		virtual void Func(@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *fmt, ...) \
  1.1124 +		{ \
  1.1125 +			__SH_VAFMT_SEQ(fmt, buf); \
  1.1126 +			SH_HANDLEFUNC_void_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf)); \
  1.1127 +		} \
  1.1128 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
  1.1129 +		(static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
  1.1130 +	\
  1.1131 +	const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1132 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1133 +	::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, { 0, 0, 0 }, \
  1.1134 +		__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
  1.1135 +
  1.1136 +#define SH_DECL_EXTERN$1_void_vafmt(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
  1.1137 +	int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1138 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> handler); \
  1.1139 +	bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
  1.1140 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> handler);
  1.1141 +
  1.1142 +#define SH_DECL_MANUALHOOK$1(hookname, vtblidx, vtbloffs, thisptroffs, rettype@[$2,1,$1:, param$2@]) \
  1.1143 +	SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1144 +		typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
  1.1145 +		MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
  1.1146 +		virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
  1.1147 +		{ SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
  1.1148 +		typedef rettype(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
  1.1149 +		typedef SourceHook::ExecutableClass$1< ::SourceHook::EmptyClass, ECMFP, rettype@[$2,1,$1:, param$2@] > CallEC; \
  1.1150 +		typedef rettype RetType; \
  1.1151 +	SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1152 +	\
  1.1153 +	const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1154 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1155 +	::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, __SH_GPI(rettype), \
  1.1156 +		__SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
  1.1157 +	void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
  1.1158 +	{ \
  1.1159 +		::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
  1.1160 +	}
  1.1161 +
  1.1162 +#define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \
  1.1163 +	int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1164 +		fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \
  1.1165 +	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
  1.1166 +		fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \
  1.1167 +	rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \
  1.1168 +	SourceHook::ExecutableClass$1<SourceHook::EmptyClass, rettype(::SourceHook::EmptyClass::*)(@[$2,1,$1|, :param$2@]), rettype@[$2,1,$1:, param$2@]> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
  1.1169 +	void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \
  1.1170 +	void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
  1.1171 +
  1.1172 +#define SH_DECL_MANUALHOOK$1_vafmt(hookname, vtblidx, vtbloffs, thisptroffs, rettype@[$2,1,$1:, param$2@]) \
  1.1173 +	SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1174 +		typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> FD; \
  1.1175 +		MAKE_DELEG(rettype, (@[$2,1,$1:param$2 p$2, @]const char *px), (@[$2,1,$1:p$2, @]px)); \
  1.1176 +		virtual rettype Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
  1.1177 +		{ \
  1.1178 +			__SH_VAFMT_SEQ(fmt, buf); \
  1.1179 +			SH_HANDLEFUNC_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf), rettype); \
  1.1180 +		} \
  1.1181 +		typedef rettype(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1:param$2, @]const char *, ...); \
  1.1182 +		typedef SourceHook::ExecutableClass@($1+1)< ::SourceHook::EmptyClass, ECMFP, rettype@[$2,1,$1:, param$2@], const char * > CallEC; \
  1.1183 +		typedef rettype RetType; \
  1.1184 +	SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1185 +	\
  1.1186 +	const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1187 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1188 +	::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, __SH_GPI(rettype), \
  1.1189 +		__SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
  1.1190 +	void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
  1.1191 +	{ \
  1.1192 +		::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
  1.1193 +	}
  1.1194 +
  1.1195 +#define SH_DECL_MANUALEXTERN$1_vafmt(hookname, rettype@[$2,1,$1:, param$2@]) \
  1.1196 +	int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1197 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> handler); \
  1.1198 +	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
  1.1199 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> handler); \
  1.1200 +	rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1:param$2, @]const char *, ...); \
  1.1201 +	SourceHook::ExecutableClass@($1+1)<SourceHook::EmptyClass, rettype(::SourceHook::EmptyClass::*)(@[$2,1,$1:param$2, @]const char *, ...), rettype@[$2,1,$1:, param$2@], const char*> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
  1.1202 +	void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \
  1.1203 +	void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
  1.1204 +
  1.1205 +#define SH_DECL_MANUALHOOK$1_void(hookname, vtblidx, vtbloffs, thisptroffs@[$2,1,$1:, param$2@]) \
  1.1206 +	SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1207 +		typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
  1.1208 +		MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
  1.1209 +		virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
  1.1210 +		{ SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
  1.1211 +		typedef void(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
  1.1212 +		typedef SourceHook::ExecutableClass$1<SourceHook::EmptyClass, ECMFP, void@[$2,1,$1:, param$2@]> CallEC; \
  1.1213 +	SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1214 +	\
  1.1215 +	const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1216 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1217 +	::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, { 0, 0, 0 }, \
  1.1218 +		__SourceHook_ParamInfosM_##hookname	, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname };
  1.1219 +
  1.1220 +#define SH_DECL_MANUALEXTERN$1_void(hookname@[$2,1,$1:, param$2@]) \
  1.1221 +	int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1222 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
  1.1223 +	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
  1.1224 +		fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
  1.1225 +	void(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \
  1.1226 +	SourceHook::ExecutableClass$1<SourceHook::EmptyClass, void(::SourceHook::EmptyClass::*)(@[$2,1,$1|, :param$2@]), void@[$2,1,$1:, param$2@]> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
  1.1227 +	void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
  1.1228 +
  1.1229 +#define SH_DECL_MANUALHOOK$1_void_vafmt(hookname, vtblidx, vtbloffs, thisptroffs@[$2,1,$1:, param$2@]) \
  1.1230 +	SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1231 +		typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> FD; \
  1.1232 +		MAKE_DELEG_void((@[$2,1,$1:param$2 p$2, @]const char *px), (@[$2,1,$1:p$2, @]px)); \
  1.1233 +		virtual void Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
  1.1234 +		{ \
  1.1235 +			__SH_VAFMT_SEQ(fmt, buf); \
  1.1236 +			SH_HANDLEFUNC_void_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf)); \
  1.1237 +		} \
  1.1238 +		typedef void(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1:param$2, @]const char *, ...); \
  1.1239 +		typedef SourceHook::ExecutableClass@($1+1)< ::SourceHook::EmptyClass, ECMFP, void@[$2,1,$1:, param$2@], const char * > CallEC; \
  1.1240 +	SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
  1.1241 +	\
  1.1242 +	const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
  1.1243 +	const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
  1.1244 +	::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, { 0, 0, 0 }, \
  1.1245 +		__SourceHook_ParamInfosM_##hookname	, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname };
  1.1246 +
  1.1247 +#define SH_DECL_MANUALEXTERN$1_void_vafmt(hookname@[$2,1,$1:, param$2@]) \
  1.1248 +	int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
  1.1249 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> handler); \
  1.1250 +	bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
  1.1251 +		fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> handler); \
  1.1252 +	void(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1:param$2, @]const char *, ...); \
  1.1253 +	SourceHook::ExecutableClass@($1+1)<SourceHook::EmptyClass, void(::SourceHook::EmptyClass::*)(@[$2,1,$1:param$2, @]const char *, ...), void@[$2,1,$1:, param$2@], const char*> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
  1.1254 +	void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
  1.1255 +@]
  1.1256 +
  1.1257 +
  1.1258 +//////////////////////////////////////////////////////////////////////////
  1.1259 +// SH_CALL
  1.1260 +
  1.1261 +#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
  1.1262 +{ \
  1.1263 +	using namespace ::SourceHook; \
  1.1264 +	\
  1.1265 +	m_pSH->SetIgnoreHooks(m_VfnPtr); \
  1.1266 +	RetType tmpret = (m_ThisPtr->*m_MFP)call; \
  1.1267 +	m_pSH->ResetIgnoreHooks(m_VfnPtr); \
  1.1268 +	return tmpret; \
  1.1269 +}
  1.1270 +
  1.1271 +#define SH_MAKE_EXECUTABLECLASS_OB_void(call, prms) \
  1.1272 +{ \
  1.1273 +	using namespace ::SourceHook; \
  1.1274 +	\
  1.1275 +	m_pSH->SetIgnoreHooks(m_VfnPtr); \
  1.1276 +	(m_ThisPtr->*m_MFP)call; \
  1.1277 +	m_pSH->ResetIgnoreHooks(m_VfnPtr); \
  1.1278 +}
  1.1279 +
  1.1280 +namespace SourceHook
  1.1281 +{
  1.1282 +@[$1,0,$a:
  1.1283 +	// Support for $1 arguments
  1.1284 +	template<class ObjType, class MFPType, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
  1.1285 +	{
  1.1286 +		ObjType *m_ThisPtr;
  1.1287 +		void *m_VfnPtr;
  1.1288 +		MFPType m_MFP;
  1.1289 +		ISourceHook *m_pSH;
  1.1290 +	public:
  1.1291 +		ExecutableClass$1(ObjType *tp, MFPType mfp, void *vp, ISourceHook *pSH) : m_ThisPtr(tp),
  1.1292 +			m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH) { }
  1.1293 +	
  1.1294 +		RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
  1.1295 +			SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
  1.1296 +	         
  1.1297 +		@[$2,$1+1,$a:
  1.1298 +		template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
  1.1299 +			SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
  1.1300 +		@]
  1.1301 +	};
  1.1302 +
  1.1303 +	template<class ObjType, class MFPType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1<ObjType, MFPType, void@[$2,1,$1:, Param$2@]>
  1.1304 +	{
  1.1305 +		ObjType *m_ThisPtr;
  1.1306 +		void *m_VfnPtr;
  1.1307 +		MFPType m_MFP;
  1.1308 +		ISourceHook *m_pSH;
  1.1309 +	public:
  1.1310 +		ExecutableClass$1(ObjType *tp, MFPType mfp, void *vp, ISourceHook *pSH) : m_ThisPtr(tp),
  1.1311 +			m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH) { }
  1.1312 +	
  1.1313 +	   void operator()(@[$2,1,$1|, :Param$2 p$2@]) const
  1.1314 +	      SH_MAKE_EXECUTABLECLASS_OB_void((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
  1.1315 +	         
  1.1316 +	   @[$2,$1+1,$a:
  1.1317 +	   template <@[$3,$1+1,$2|, :class Param$3@]> void operator()(@[$3,1,$2|, :Param$3 p$3@]) const
  1.1318 +	      SH_MAKE_EXECUTABLECLASS_OB_void((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
  1.1319 +	   @]
  1.1320 +	};
  1.1321 +@]
  1.1322 +
  1.1323 +}
  1.1324 +
  1.1325 +#define SH__CALL_GET_VFNPTR_NORMAL \
  1.1326 +	using namespace ::SourceHook; \
  1.1327 +	MemFuncInfo mfi = {true, -1, 0, 0}; \
  1.1328 +	GetFuncInfo(ptr, mfp, mfi); \
  1.1329 +	void *vfnptr = reinterpret_cast<void*>( \
  1.1330 +		*reinterpret_cast<void***>(reinterpret_cast<char*>(ptr) + mfi.thisptroffs + mfi.vtbloffs) + mfi.vtblindex);
  1.1331 +
  1.1332 +#define SH__CALL_GET_VFNPTR_MANUAL \
  1.1333 +	using namespace ::SourceHook; \
  1.1334 +	void *vfnptr = reinterpret_cast<void*>( \
  1.1335 +		*reinterpret_cast<void***>( (reinterpret_cast<char*>(ptr) + thisptroffs + vtbloffs) ) + vtblidx); \
  1.1336 +	/* patch mfp */ \
  1.1337 +	*reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr);
  1.1338 +
  1.1339 +// SH_CALL needs to deduce the return type -> it uses templates and function overloading
  1.1340 +// That's why SH_CALL takes two parameters: "mfp2" of type RetType(X::*mfp)(params), and "mfp" of type MFP
  1.1341 +// The only purpose of the mfp2 parameter is to extract the return type
  1.1342 +
  1.1343 +@[$1,0,$a:
  1.1344 +// Support for $1 arguments
  1.1345 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
  1.1346 +SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
  1.1347 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), SourceHook::ISourceHook *shptr)
  1.1348 +{
  1.1349 +	SH__CALL_GET_VFNPTR_NORMAL
  1.1350 +	return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
  1.1351 +}
  1.1352 +
  1.1353 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
  1.1354 +SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
  1.1355 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const, SourceHook::ISourceHook *shptr)
  1.1356 +{
  1.1357 +	SH__CALL_GET_VFNPTR_NORMAL
  1.1358 +	return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
  1.1359 +}
  1.1360 +
  1.1361 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
  1.1362 +SourceHook::ExecutableClass$1<SourceHook::EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>
  1.1363 +SH_MCALL3(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs, SourceHook::ISourceHook *shptr)
  1.1364 +{
  1.1365 +	SH__CALL_GET_VFNPTR_MANUAL
  1.1366 +	return SourceHook::ExecutableClass$1<EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>(
  1.1367 +		reinterpret_cast<SourceHook::EmptyClass*>(ptr), mfp, vfnptr, shptr);
  1.1368 +}
  1.1369 +@]
  1.1370 +
  1.1371 +#if SH_COMP != SH_COMP_MSVC || _MSC_VER > 1300
  1.1372 +// GCC & MSVC 7.1 need this, MSVC 7.0 doesn't like it
  1.1373 +
  1.1374 +@[$1,0,$a:
  1.1375 +// Support for $1 arguments
  1.1376 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
  1.1377 +SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
  1.1378 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...), SourceHook::ISourceHook *shptr)
  1.1379 +{
  1.1380 +	SH__CALL_GET_VFNPTR_NORMAL
  1.1381 +	return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
  1.1382 +}
  1.1383 +
  1.1384 +template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
  1.1385 +SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
  1.1386 +SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const, SourceHook::ISourceHook *shptr)
  1.1387 +{
  1.1388 +	SH__CALL_GET_VFNPTR_NORMAL
  1.1389 +	return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
  1.1390 +}
  1.1391 +
  1.1392 +@]
  1.1393 +
  1.1394 +#endif
  1.1395 +
  1.1396 +#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp), SH_GLOB_SHPTR)
  1.1397 +#define SH_MCALL2(ptr, mfp, vtblidx, vtbloffs, thisptroffs) SH_MCALL3((ptr), (mfp), (mfp), (vtblidx), (vtbloffs), (thisptroffs), SH_GLOB_SHPTR)
  1.1398 +#define SH_MCALL(ptr, mhookname) __SoureceHook_FHM_SHCall##mhookname(ptr)
  1.1399 +
  1.1400 +#undef SH_MAKE_EXECUTABLECLASS_OB
  1.1401 +#undef SH_MAKE_EXECUTABLECLASS_OB_void
  1.1402 +
  1.1403 +//////////////////////////////////////////////////////////////////////////
  1.1404 +// SetOverrideRet and RecallGetIface for recalls
  1.1405 +// These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
  1.1406 +// The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
  1.1407 +// (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
  1.1408 +
  1.1409 +namespace SourceHook
  1.1410 +{
  1.1411 +	template <class RetType>
  1.1412 +	void SetOverrideResult(ISourceHook *shptr, const RetType res)
  1.1413 +	{
  1.1414 +		*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
  1.1415 +	}
  1.1416 +
  1.1417 +	// SetOverrideResult used to be implemented like this:
  1.1418 +	//  SetOverrideResult(shptr, memfuncptr, return);
  1.1419 +	//  normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
  1.1420 +	//  (it thought it was ambigous - the ref and non-ref type)
  1.1421 +	//  so now SetOverrideResult(memfuncptr) deduces the ret type, and returns a functor which does the work
  1.1422 +	//  new syntax: SetOverrideResult(memfuncptr)(shptr, return)
  1.1423 +	// This also allows us to create a special version for references which respects ReferenceCarrier.
  1.1424 +
  1.1425 +	template <class T> struct OverrideFunctor
  1.1426 +	{
  1.1427 +		void operator()(ISourceHook *shptr, T res)
  1.1428 +		{
  1.1429 +			*reinterpret_cast<T*>(shptr->GetOverrideRetPtr()) = res;
  1.1430 +		}
  1.1431 +	};
  1.1432 +	template <class T> struct OverrideFunctor<T&>
  1.1433 +	{
  1.1434 +		void operator()(ISourceHook *shptr, T &res)
  1.1435 +		{
  1.1436 +			// overrideretptr points to ReferenceCarrier<T&>
  1.1437 +			*reinterpret_cast<typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRetPtr()) = res;
  1.1438 +		}
  1.1439 +	};
  1.1440 +@[$1,0,$a:
  1.1441 +	template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
  1.1442 +	OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
  1.1443 +	{
  1.1444 +		return OverrideFunctor<RetType>();
  1.1445 +	}
  1.1446 +
  1.1447 +	template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
  1.1448 +	OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1:Param$2, @]...))
  1.1449 +	{
  1.1450 +		return OverrideFunctor<RetType>();
  1.1451 +	}
  1.1452 +
  1.1453 +	template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
  1.1454 +	Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
  1.1455 +	{
  1.1456 +		return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
  1.1457 +	}
  1.1458 +
  1.1459 +	template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
  1.1460 +	Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1:Param$2, @]...))
  1.1461 +	{
  1.1462 +		return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
  1.1463 +	}
  1.1464 +@]
  1.1465 +}
  1.1466 +
  1.1467 +#endif
  1.1468 +	// The pope is dead. -> :(