sourcehook/generate/sourcehook.hxx
changeset 1 586787053c73
child 2 dfa5ea299c33
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/generate/sourcehook.hxx	Thu Apr 14 12:54:13 2005 +0000
     1.3 @@ -0,0 +1,544 @@
     1.4 +/* ======== SourceHook ========
     1.5 +* By PM
     1.6 +* No warranties of any kind
     1.7 +* ============================
     1.8 +*/
     1.9 +
    1.10 +/**
    1.11 +*	@file sourcehook.h
    1.12 +*	@brief Contains the public SourceHook API
    1.13 +*/
    1.14 +
    1.15 +#ifndef __SOURCEHOOK_H__
    1.16 +#define __SOURCEHOOK_H__
    1.17 +
    1.18 +#define SH_ASSERT(x) if (!(x)) __asm { int 3 }
    1.19 +
    1.20 +// System
    1.21 +#define SH_SYS_WIN32 1
    1.22 +#define SH_SYS_LINUX 2
    1.23 +
    1.24 +#ifdef _WIN32
    1.25 +# define SH_SYS SH_SYS_WIN32
    1.26 +#elif defined __linux__
    1.27 +# define SH_SYS SH_SYS_LINUX
    1.28 +#else
    1.29 +# error Unsupported system
    1.30 +#endif
    1.31 +
    1.32 +// Compiler
    1.33 +#define SH_COMP_GCC 1
    1.34 +#define SH_COMP_MSVC 2
    1.35 +
    1.36 +#ifdef _MSC_VER
    1.37 +# define SH_COMP SH_COMP_MSVC
    1.38 +#elif defined __GNUC__
    1.39 +# define SH_COMP SH_COMP_GCC
    1.40 +#else
    1.41 +# error Unsupported compiler
    1.42 +#endif
    1.43 +
    1.44 +#if SH_COMP==SH_COMP_MSVC
    1.45 +# define vsnprintf _vsnprintf
    1.46 +#endif
    1.47 +
    1.48 +#include "FastDelegate.h"
    1.49 +#include "sh_memfuncinfo.h"
    1.50 +#include "sh_memory.h"
    1.51 +#include <list>
    1.52 +#include <algorithm>
    1.53 +
    1.54 +// Good old metamod!
    1.55 +
    1.56 +// Flags returned by a plugin's api function.
    1.57 +// NOTE: order is crucial, as greater/less comparisons are made.
    1.58 +enum META_RES
    1.59 +{
    1.60 +	MRES_IGNORED=0,		// plugin didn't take any action
    1.61 +	MRES_HANDLED,		// plugin did something, but real function should still be called
    1.62 +	MRES_OVERRIDE,		// call real function, but use my return value
    1.63 +	MRES_SUPERCEDE,		// skip real function; use my return value
    1.64 +};
    1.65 +
    1.66 +
    1.67 +namespace SourceHook
    1.68 +{
    1.69 +	const int STRBUF_LEN=8192;		// In bytes, for "vafmt" functions
    1.70 +
    1.71 +	/**
    1.72 +	*	@brief A plugin typedef
    1.73 +	*
    1.74 +	*	SourceHook doesn't really care what this is. As long as the ==, != and = operators work on it
    1.75 +	*	and every plugin has a unique identifier, everything is ok.
    1.76 +	*/
    1.77 +	typedef void* Plugin;
    1.78 +
    1.79 +	enum HookerAction
    1.80 +	{
    1.81 +		HA_GetInfo = 0,			// -> Only store info
    1.82 +		HA_Register,			// -> Save the pointer for future reference
    1.83 +		HA_Unregister,			// -> Clear the saved pointer
    1.84 +		HA_IfaceAdded,			// -> Request call class
    1.85 +		HA_IfaceRemoved			// -> Release call class
    1.86 +	};
    1.87 +
    1.88 +	struct HookerInfo;
    1.89 +
    1.90 +	/**
    1.91 +	*	@brief Pointer to hooker type
    1.92 +	*
    1.93 +	*	A "hooker" is a the only thing that knows the actual protoype of the function at compile time.
    1.94 +	*	
    1.95 +	*	@param hi A pointer to a HookerInfo structure. The hooker should fill it and store it for
    1.96 +	*				future reference (mainly if something should get hooked to its hookfunc)
    1.97 +	*/
    1.98 +	typedef int (*Hooker)(HookerAction ha, HookerInfo *hi);
    1.99 +
   1.100 +	class ISHDelegate
   1.101 +	{
   1.102 +	public:
   1.103 +		virtual void DeleteThis() = 0;				// Ugly, I know
   1.104 +		virtual bool IsEqual(ISHDelegate *other) = 0;
   1.105 +	};
   1.106 +
   1.107 +	template <class T> class CSHDelegate : public ISHDelegate
   1.108 +	{
   1.109 +		T m_Deleg;
   1.110 +	public:
   1.111 +		CSHDelegate(T deleg) : m_Deleg(deleg)
   1.112 +		{
   1.113 +		}
   1.114 +
   1.115 +		void DeleteThis()
   1.116 +		{
   1.117 +			delete this;
   1.118 +		}
   1.119 +
   1.120 +		bool IsEqual(ISHDelegate *other)
   1.121 +		{
   1.122 +			return static_cast<CSHDelegate<T>* >(other)->GetDeleg() == GetDeleg();				
   1.123 +		}
   1.124 +
   1.125 +		T &GetDeleg()
   1.126 +		{
   1.127 +			return m_Deleg;
   1.128 +		}
   1.129 +	};
   1.130 +
   1.131 +	/**
   1.132 +	*	@brief This structure contains information about a hooker (hook manager)
   1.133 +	*/
   1.134 +	struct HookerInfo
   1.135 +	{
   1.136 +		struct Iface
   1.137 +		{
   1.138 +			struct Hook
   1.139 +			{
   1.140 +				ISHDelegate *handler;			//!< Pointer to the handler
   1.141 +				Plugin plug;					//!< The owner plugin
   1.142 +			};
   1.143 +			void *callclass;					//!< Stores a call class for this interface
   1.144 +			void *ptr;							//!< Pointer to the interface instance
   1.145 +			void *orig_entry;					//!< The original vtable entry
   1.146 +			std::list<Hook> hooks_pre;			//!< A list of pre-hooks
   1.147 +			std::list<Hook> hooks_post;			//!< A list of post-hooks
   1.148 +			bool operator ==(void *other) const
   1.149 +			{
   1.150 +				return ptr == other;
   1.151 +			}
   1.152 +		};
   1.153 +		Plugin plug;							//!< The owner plugin
   1.154 +		const char *proto;						//!< The prototype of the function the hooker is responsible for
   1.155 +		int vtbl_idx;							//!< The vtable index
   1.156 +		int vtbl_offs;							//!< The vtable offset
   1.157 +		int thisptr_offs;						//!< The this-pointer-adjuster
   1.158 +		Hooker func;							//!< The interface to the hooker
   1.159 +
   1.160 +		int hookfunc_vtbl_idx;					//!< the vtable index of the hookfunc
   1.161 +		int hookfunc_vtbl_offs;					//!< the vtable offset of the hookfunc
   1.162 +		void *hookfunc_inst;					//!< Instance of the class the hookfunc is in
   1.163 +		
   1.164 +		std::list<Iface> ifaces;				//!< List of hooked interfaces
   1.165 +	};
   1.166 +
   1.167 +	/**
   1.168 +	*	@brief Structure describing a callclass
   1.169 +	*/
   1.170 +	struct CallClass
   1.171 +	{
   1.172 +		struct VTable
   1.173 +		{
   1.174 +			void *ptr;
   1.175 +			int actsize;
   1.176 +			std::list<int> patches;	//!< Already patched entries
   1.177 +			bool operator ==(void *other) const
   1.178 +			{
   1.179 +				return ptr == other;
   1.180 +			}
   1.181 +		};
   1.182 +		void *iface;				//!< The iface pointer this callclass belongs to
   1.183 +		size_t size;				//!< The size of the callclass
   1.184 +		void *ptr;					//!< The actual "object"
   1.185 +		typedef std::list<VTable> VTableList;
   1.186 +		VTableList vtables;			//!< Already known vtables
   1.187 +		int refcounter;				//!< How many times it was requested
   1.188 +
   1.189 +		bool operator ==(void *other) const
   1.190 +		{
   1.191 +			return ptr == other;
   1.192 +		}
   1.193 +	};
   1.194 +
   1.195 +	/**
   1.196 +	*	@brief The main SourceHook interface
   1.197 +	*/
   1.198 +	class ISourceHook
   1.199 +	{
   1.200 +	public:
   1.201 +		/**
   1.202 +		*	@brief Add a hook.
   1.203 +		*
   1.204 +		*	@return True if the function succeeded, false otherwise
   1.205 +		*
   1.206 +		*	@param plug The unique identifier of the plugin that calls this function
   1.207 +		*	@param iface The interface pointer
   1.208 +		*	@param ifacesize The size of the class iface points to
   1.209 +		*	@param myHooker A hooker function that should be capable of handling the function
   1.210 +		*	@param handler A pointer to a FastDelegate containing the hook handler
   1.211 +		*	@param post Set to true if you want a post handler
   1.212 +		*/
   1.213 +		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   1.214 +
   1.215 +		/**
   1.216 +		*	@brief Removes a hook.
   1.217 +		*
   1.218 +		*	@return True if the function succeeded, false otherwise
   1.219 +		*
   1.220 +		*	@param plug The unique identifier of the plugin that calls this function
   1.221 +		*	@param iface The interface pointer
   1.222 +		*	@param myHooker A hooker function that should be capable of handling the function
   1.223 +		*	@param handler A pointer to a FastDelegate containing the hook handler
   1.224 +		*	@param post Set to true if you want a post handler
   1.225 +		*/
   1.226 +		virtual bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   1.227 +
   1.228 +		/**
   1.229 +		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
   1.230 +		*
   1.231 +		*	@param plug The unique identifier of the plugin in question
   1.232 +		*/
   1.233 +		virtual bool IsPluginInUse(Plugin plug) = 0;
   1.234 +
   1.235 +		/**
   1.236 +		*	@brief Return a pointer to a callclass. Generate a new one if required.
   1.237 +		*
   1.238 +		*	@param iface The interface pointer
   1.239 +		*	@param size Size of the class
   1.240 +		*/
   1.241 +		virtual void *GetCallClass(void *iface, size_t size) = 0;
   1.242 +
   1.243 +		/**
   1.244 +		*	@brief Release a callclass
   1.245 +		*
   1.246 +		*	@param ptr Pointer to the callclass
   1.247 +		*/
   1.248 +		virtual void ReleaseCallClass(void *ptr) = 0;
   1.249 +
   1.250 +		virtual void SetRes(META_RES res) = 0;				//!< Sets the meta result
   1.251 +		virtual META_RES GetPrevRes() = 0;					//!< Gets the meta result of the previously called handler
   1.252 +		virtual META_RES GetStatus() = 0;					//!< Gets the highest meta result
   1.253 +		virtual const void *GetOrigRet() = 0;				//!< Gets the original result. If not in post function, undefined
   1.254 +		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result. If none is specified, NULL
   1.255 +		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   1.256 +		//////////////////////////////////////////////////////////////////////////
   1.257 +		// For hookers
   1.258 +		virtual META_RES &GetCurResRef() = 0;				//!< Gets the pointer to the current meta result
   1.259 +		virtual META_RES &GetPrevResRef() = 0;				//!< Gets the pointer to the previous meta result
   1.260 +		virtual META_RES &GetStatusRef() = 0;				//!< Gets the pointer to the status variable
   1.261 +		virtual void SetOrigRet(const void *ptr) = 0;		//!< Sets the original return pointer
   1.262 +		virtual void SetOverrideRet(const void *ptr) = 0;	//!< Sets the override result pointer
   1.263 +		virtual void SetIfacePtr(void *ptr) = 0;			//!< Sets the interface this pointer
   1.264 +	};
   1.265 +}
   1.266 +
   1.267 +//////////////////////////////////////////////////////////////////////////
   1.268 +// Macro interface
   1.269 +#define SET_META_RESULT(result)		g_SHPtr->SetRes(result)
   1.270 +#define RETURN_META(result)			do { g_SHPtr->SetRes(result); return; } while(0)
   1.271 +#define RETURN_META_VALUE(result, value)	do { g_SHPtr->SetRes(result); return (value); } while(0)
   1.272 +
   1.273 +#define META_RESULT_STATUS					g_SHPtr->GetStatus()
   1.274 +#define META_RESULT_PREVIOUS				g_SHPtr->GetPrevRes()
   1.275 +#define META_RESULT_ORIG_RET(type)			*(const type *)g_SHPtr->GetOrigRet()
   1.276 +#define META_RESULT_OVERRIDE_RET(type)		*(const type *)g_SHPtr->GetOverrideRet()
   1.277 +#define META_IFACEPTR						g_SHPtr->GetIfacePtr()
   1.278 +
   1.279 +
   1.280 +/**
   1.281 +*	@brief Get/generate callclass for an interface pointer
   1.282 +*
   1.283 +*	@param ifacetype The type of the interface
   1.284 +*	@param ifaceptr The interface pointer
   1.285 +*/
   1.286 +#define SH_GET_CALLCLASS(ifacetype, ifaceptr) g_SHPtr->GetCallClass(iface, sizeof(ifacetype))
   1.287 +
   1.288 +#define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.289 +	SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   1.290 +#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.291 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   1.292 +#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.293 +	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.294 +
   1.295 +#define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.296 +	SourceHook::SH_FHRemove##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   1.297 +#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   1.298 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   1.299 +#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   1.300 +	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   1.301 +
   1.302 +#define SH_NOATTRIB
   1.303 +
   1.304 +
   1.305 +//////////////////////////////////////////////////////////////////////////
   1.306 +#define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
   1.307 +
   1.308 +#define SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   1.309 +	static int Hooker(HookerAction action, HookerInfo *param) \
   1.310 +	{ \
   1.311 +		if (action == HA_GetInfo) \
   1.312 +		{ \
   1.313 +			param->proto = ms_Proto; \
   1.314 +			MemFuncInfo mfi; \
   1.315 +			GetFuncInfo(funcptr, mfi); \
   1.316 +			param->vtbl_idx = mfi.vtblindex; \
   1.317 +			param->vtbl_offs = mfi.vtbloffs; \
   1.318 +			param->thisptr_offs = mfi.thisptroffs; \
   1.319 +			if (param->thisptr_offs) \
   1.320 +				return 2; /*No virtual inheritance supported*/ \
   1.321 +			GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
   1.322 +			param->hookfunc_vtbl_idx = mfi.vtblindex; \
   1.323 +			param->hookfunc_vtbl_offs = mfi.vtbloffs; \
   1.324 +			param->hookfunc_inst = (void*)&ms_Inst; \
   1.325 +			return 0; \
   1.326 +		} \
   1.327 +		else if (action == HA_Register) \
   1.328 +		{ \
   1.329 +			ms_HI = param; \
   1.330 +			return 0; \
   1.331 +		} \
   1.332 +		else if (action == HA_Unregister) \
   1.333 +		{ \
   1.334 +			ms_HI = NULL; \
   1.335 +			return 0; \
   1.336 +		} \
   1.337 +		else \
   1.338 +			return 1; \
   1.339 +	}
   1.340 +
   1.341 +#define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
   1.342 +	namespace SourceHook \
   1.343 +	{ \
   1.344 +		struct SH_FHCls(ifacetype,ifacefunc,overload) \
   1.345 +		{ \
   1.346 +			static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   1.347 +			static HookerInfo *ms_HI; \
   1.348 +			static const char *ms_Proto; \
   1.349 +			SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   1.350 +
   1.351 +#define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
   1.352 +		}; \
   1.353 +		const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
   1.354 +		SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   1.355 +		HookerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   1.356 +		bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   1.357 +			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.358 +		{ \
   1.359 +			return g_SHPtr->AddHook(g_Plug, iface, sizeof(ifacetype), \
   1.360 +				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, \
   1.361 +				new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   1.362 +		} \
   1.363 +		bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   1.364 +			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   1.365 +		{ \
   1.366 +			CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
   1.367 +			return g_SHPtr->RemoveHook(g_Plug, iface, \
   1.368 +				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, &tmp, post); \
   1.369 +		} \
   1.370 +	}
   1.371 +
   1.372 +#define SH_SETUPCALLS(rettype) \
   1.373 +	/* 1) Find the iface ptr */ \
   1.374 +	/* 1.1) Adjust to original this pointer */ \
   1.375 +	void *origthis = this - ms_HI->thisptr_offs; \
   1.376 +	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.377 +		ms_HI->ifaces.end(), origthis); \
   1.378 +	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   1.379 +	HookerInfo::Iface &ci = *ifaceiter; \
   1.380 +	/* 2) Declare some vars and set it up */ \
   1.381 +	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.382 +	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.383 +	rettype orig_ret, override_ret, plugin_ret; \
   1.384 +	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   1.385 +	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   1.386 +	META_RES &status = g_SHPtr->GetStatusRef(); \
   1.387 +	status = MRES_IGNORED; \
   1.388 +	g_SHPtr->SetIfacePtr(ci.ptr); \
   1.389 +	g_SHPtr->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   1.390 +	g_SHPtr->SetOverrideRet(NULL);
   1.391 +
   1.392 +#define SH_CALL_HOOKS(post, params) \
   1.393 +	prev_res = MRES_IGNORED; \
   1.394 +	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.395 +	{ \
   1.396 +		cur_res = MRES_IGNORED; \
   1.397 +		plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   1.398 +		prev_res = cur_res; \
   1.399 +		if (cur_res > status) \
   1.400 +			status = cur_res; \
   1.401 +		if (cur_res >= MRES_OVERRIDE) \
   1.402 +		{ \
   1.403 +			override_ret = plugin_ret; \
   1.404 +			g_SHPtr->SetOverrideRet(&override_ret); \
   1.405 +		} \
   1.406 +	}
   1.407 +
   1.408 +#define SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   1.409 +	if (status != MRES_SUPERCEDE) \
   1.410 +		orig_ret = reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params; \
   1.411 +	else \
   1.412 +		orig_ret = override_ret;
   1.413 +
   1.414 +#define SH_RETURN() \
   1.415 +	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   1.416 +
   1.417 +#define SH_HANDLEFUNC(ifacetype, ifacefunc, params, rettype) \
   1.418 +	SH_SETUPCALLS(rettype) \
   1.419 +	SH_CALL_HOOKS(pre, params) \
   1.420 +	SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   1.421 +	SH_CALL_HOOKS(post, params) \
   1.422 +	SH_RETURN()
   1.423 +
   1.424 +//////////////////////////////////////////////////////////////////////////
   1.425 +#define SH_SETUPCALLS_void() \
   1.426 +	/* 1) Find the iface ptr */ \
   1.427 +	/* 1.1) Adjust to original this pointer */ \
   1.428 +	void *origthis = this - ms_HI->thisptr_offs; \
   1.429 +	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   1.430 +		ms_HI->ifaces.end(), origthis); \
   1.431 +	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   1.432 +	HookerInfo::Iface &ci = *ifaceiter; \
   1.433 +	/* 2) Declare some vars and set it up */ \
   1.434 +	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   1.435 +	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   1.436 +	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   1.437 +	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   1.438 +	META_RES &status = g_SHPtr->GetStatusRef(); \
   1.439 +	status = MRES_IGNORED; \
   1.440 +	g_SHPtr->SetIfacePtr(ci.ptr); \
   1.441 +	g_SHPtr->SetOverrideRet(NULL);
   1.442 +
   1.443 +#define SH_CALL_HOOKS_void(post, params) \
   1.444 +	prev_res = MRES_IGNORED; \
   1.445 +	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.446 +	{ \
   1.447 +		cur_res = MRES_IGNORED; \
   1.448 +		reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   1.449 +		prev_res = cur_res; \
   1.450 +		if (cur_res > status) \
   1.451 +			status = cur_res; \
   1.452 +	}
   1.453 +
   1.454 +#define SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   1.455 +	if (status != MRES_SUPERCEDE) \
   1.456 +		reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params;
   1.457 +
   1.458 +#define SH_RETURN_void()
   1.459 +
   1.460 +#define SH_HANDLEFUNC_void(ifacetype, ifacefunc, params) \
   1.461 +	SH_SETUPCALLS_void() \
   1.462 +	SH_CALL_HOOKS_void(pre, params) \
   1.463 +	SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   1.464 +	SH_CALL_HOOKS_void(post, params) \
   1.465 +	SH_RETURN_void()
   1.466 +
   1.467 +
   1.468 +// Special vafmt handlers
   1.469 +#define SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, params_orig, params_plug, rettype) \
   1.470 +	SH_SETUPCALLS(rettype) \
   1.471 +	SH_CALL_HOOKS(pre, params_plug) \
   1.472 +	SH_CALL_ORIG(ifacetype, ifacefunc, params_orig) \
   1.473 +	SH_CALL_HOOKS(post, params_plug) \
   1.474 +	SH_RETURN()
   1.475 +
   1.476 +#define SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, params_orig, params_plug) \
   1.477 +	SH_SETUPCALLS_void() \
   1.478 +	SH_CALL_HOOKS_void(pre, params_plug) \
   1.479 +	SH_CALL_ORIG_void(ifacetype, ifacefunc, params_orig) \
   1.480 +	SH_CALL_HOOKS_void(post, params_plug) \
   1.481 +	SH_RETURN_void()
   1.482 +
   1.483 +//////////////////////////////////////////////////////////////////////////
   1.484 +
   1.485 +@VARARGS@
   1.486 +// *********
   1.487 +#define SH_DECL_HOOK@$@(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   1.488 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @)> \
   1.489 +		(&ifacetype::ifacefunc))) \
   1.490 +		typedef fastdelegate::FastDelegate@$@<@param%%|, @@, @rettype> FD; \
   1.491 +		virtual rettype Func(@param%% p%%|, @) attr \
   1.492 +		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (@p%%|, @), rettype); } \
   1.493 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @)
   1.494 +
   1.495 +#define SH_DECL_HOOK@$@_void(ifacetype, ifacefunc, attr, overload@, param%%@) \
   1.496 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @)> \
   1.497 +		(&ifacetype::ifacefunc))) \
   1.498 +		typedef fastdelegate::FastDelegate@$@<@param%%|, @> FD; \
   1.499 +		virtual void Func(@param%% p%%|, @) attr \
   1.500 +		{ SH_HANDLEFUNC_void(ifacetype, ifacefunc, (@p%%|, @)); } \
   1.501 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @)
   1.502 +
   1.503 +#define SH_DECL_HOOK@$@_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   1.504 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   1.505 +		(&ifacetype::ifacefunc))) \
   1.506 +		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *, rettype> FD; \
   1.507 +		virtual rettype Func(@param%% p%%|, @@, @const char *fmt, ...) attr \
   1.508 +		{ \
   1.509 +			char buf[STRBUF_LEN]; \
   1.510 +			va_list ap; \
   1.511 +			va_start(ap, fmt); \
   1.512 +			vsnprintf(buf, sizeof(buf), fmt, ap); \
   1.513 +			va_end(ap); \
   1.514 +			SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf), rettype); \
   1.515 +		} \
   1.516 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @ "|const char*|...")
   1.517 +
   1.518 +#define SH_DECL_HOOK@$@_void_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   1.519 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   1.520 +		(&ifacetype::ifacefunc))) \
   1.521 +		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *> FD; \
   1.522 +		virtual void Func(@param%% p%%|, @@, @const char *, ...) attr \
   1.523 +		{ \
   1.524 +			char buf[STRBUF_LEN]; \
   1.525 +			va_list ap; \
   1.526 +			va_start(ap, fmt); \
   1.527 +			vsnprintf(buf, sizeof(buf), fmt, ap); \
   1.528 +			va_end(ap); \
   1.529 +			SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf)); \
   1.530 +		} \
   1.531 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @ "|const char*|...")
   1.532 +
   1.533 +@ENDARGS@
   1.534 +
   1.535 +/*
   1.536 +#define SH_DECL_HOOK1(ifacetype, ifacefunc, attr, overload, rettype, param1) \
   1.537 +	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload) \
   1.538 +		typedef fastdelegate::FastDelegate1<param1, rettype> FD; \
   1.539 +		virtual rettype Func(param1 p1) \
   1.540 +		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (p1), rettype); } \
   1.541 +	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype "|" #param1)
   1.542 +		
   1.543 +
   1.544 +*/
   1.545 +
   1.546 +#endif
   1.547 +	// The pope is dead. -> :(
   1.548 \ No newline at end of file