sourcehook/generate/sourcehook.hxx
author Pavol Marko <pavolmarko@gmail.com>
Thu Apr 14 13:15:33 2005 +0000 (2005-04-14)
changeset 2 dfa5ea299c33
parent 1 586787053c73
child 6 4803fd7d28bb
permissions -rwxr-xr-x
Added callclass macros
     1 /* ======== SourceHook ========
     2 * By PM
     3 * No warranties of any kind
     4 * ============================
     5 */
     6 
     7 /**
     8 *	@file sourcehook.h
     9 *	@brief Contains the public SourceHook API
    10 */
    11 
    12 #ifndef __SOURCEHOOK_H__
    13 #define __SOURCEHOOK_H__
    14 
    15 #define SH_ASSERT(x) if (!(x)) __asm { int 3 }
    16 
    17 // System
    18 #define SH_SYS_WIN32 1
    19 #define SH_SYS_LINUX 2
    20 
    21 #ifdef _WIN32
    22 # define SH_SYS SH_SYS_WIN32
    23 #elif defined __linux__
    24 # define SH_SYS SH_SYS_LINUX
    25 #else
    26 # error Unsupported system
    27 #endif
    28 
    29 // Compiler
    30 #define SH_COMP_GCC 1
    31 #define SH_COMP_MSVC 2
    32 
    33 #ifdef _MSC_VER
    34 # define SH_COMP SH_COMP_MSVC
    35 #elif defined __GNUC__
    36 # define SH_COMP SH_COMP_GCC
    37 #else
    38 # error Unsupported compiler
    39 #endif
    40 
    41 #if SH_COMP==SH_COMP_MSVC
    42 # define vsnprintf _vsnprintf
    43 #endif
    44 
    45 #include "FastDelegate.h"
    46 #include "sh_memfuncinfo.h"
    47 #include "sh_memory.h"
    48 #include <list>
    49 #include <algorithm>
    50 
    51 // Good old metamod!
    52 
    53 // Flags returned by a plugin's api function.
    54 // NOTE: order is crucial, as greater/less comparisons are made.
    55 enum META_RES
    56 {
    57 	MRES_IGNORED=0,		// plugin didn't take any action
    58 	MRES_HANDLED,		// plugin did something, but real function should still be called
    59 	MRES_OVERRIDE,		// call real function, but use my return value
    60 	MRES_SUPERCEDE,		// skip real function; use my return value
    61 };
    62 
    63 
    64 namespace SourceHook
    65 {
    66 	const int STRBUF_LEN=8192;		// In bytes, for "vafmt" functions
    67 
    68 	/**
    69 	*	@brief A plugin typedef
    70 	*
    71 	*	SourceHook doesn't really care what this is. As long as the ==, != and = operators work on it
    72 	*	and every plugin has a unique identifier, everything is ok.
    73 	*/
    74 	typedef void* Plugin;
    75 
    76 	enum HookerAction
    77 	{
    78 		HA_GetInfo = 0,			// -> Only store info
    79 		HA_Register,			// -> Save the pointer for future reference
    80 		HA_Unregister,			// -> Clear the saved pointer
    81 		HA_IfaceAdded,			// -> Request call class
    82 		HA_IfaceRemoved			// -> Release call class
    83 	};
    84 
    85 	struct HookerInfo;
    86 
    87 	/**
    88 	*	@brief Pointer to hooker type
    89 	*
    90 	*	A "hooker" is a the only thing that knows the actual protoype of the function at compile time.
    91 	*	
    92 	*	@param hi A pointer to a HookerInfo structure. The hooker should fill it and store it for
    93 	*				future reference (mainly if something should get hooked to its hookfunc)
    94 	*/
    95 	typedef int (*Hooker)(HookerAction ha, HookerInfo *hi);
    96 
    97 	class ISHDelegate
    98 	{
    99 	public:
   100 		virtual void DeleteThis() = 0;				// Ugly, I know
   101 		virtual bool IsEqual(ISHDelegate *other) = 0;
   102 	};
   103 
   104 	template <class T> class CSHDelegate : public ISHDelegate
   105 	{
   106 		T m_Deleg;
   107 	public:
   108 		CSHDelegate(T deleg) : m_Deleg(deleg)
   109 		{
   110 		}
   111 
   112 		void DeleteThis()
   113 		{
   114 			delete this;
   115 		}
   116 
   117 		bool IsEqual(ISHDelegate *other)
   118 		{
   119 			return static_cast<CSHDelegate<T>* >(other)->GetDeleg() == GetDeleg();				
   120 		}
   121 
   122 		T &GetDeleg()
   123 		{
   124 			return m_Deleg;
   125 		}
   126 	};
   127 
   128 	/**
   129 	*	@brief This structure contains information about a hooker (hook manager)
   130 	*/
   131 	struct HookerInfo
   132 	{
   133 		struct Iface
   134 		{
   135 			struct Hook
   136 			{
   137 				ISHDelegate *handler;			//!< Pointer to the handler
   138 				Plugin plug;					//!< The owner plugin
   139 			};
   140 			void *callclass;					//!< Stores a call class for this interface
   141 			void *ptr;							//!< Pointer to the interface instance
   142 			void *orig_entry;					//!< The original vtable entry
   143 			std::list<Hook> hooks_pre;			//!< A list of pre-hooks
   144 			std::list<Hook> hooks_post;			//!< A list of post-hooks
   145 			bool operator ==(void *other) const
   146 			{
   147 				return ptr == other;
   148 			}
   149 		};
   150 		Plugin plug;							//!< The owner plugin
   151 		const char *proto;						//!< The prototype of the function the hooker is responsible for
   152 		int vtbl_idx;							//!< The vtable index
   153 		int vtbl_offs;							//!< The vtable offset
   154 		int thisptr_offs;						//!< The this-pointer-adjuster
   155 		Hooker func;							//!< The interface to the hooker
   156 
   157 		int hookfunc_vtbl_idx;					//!< the vtable index of the hookfunc
   158 		int hookfunc_vtbl_offs;					//!< the vtable offset of the hookfunc
   159 		void *hookfunc_inst;					//!< Instance of the class the hookfunc is in
   160 		
   161 		std::list<Iface> ifaces;				//!< List of hooked interfaces
   162 	};
   163 
   164 	/**
   165 	*	@brief Structure describing a callclass
   166 	*/
   167 	struct CallClass
   168 	{
   169 		struct VTable
   170 		{
   171 			void *ptr;
   172 			int actsize;
   173 			std::list<int> patches;	//!< Already patched entries
   174 			bool operator ==(void *other) const
   175 			{
   176 				return ptr == other;
   177 			}
   178 		};
   179 		void *iface;				//!< The iface pointer this callclass belongs to
   180 		size_t size;				//!< The size of the callclass
   181 		void *ptr;					//!< The actual "object"
   182 		typedef std::list<VTable> VTableList;
   183 		VTableList vtables;			//!< Already known vtables
   184 		int refcounter;				//!< How many times it was requested
   185 
   186 		bool operator ==(void *other) const
   187 		{
   188 			return ptr == other;
   189 		}
   190 	};
   191 
   192 	/**
   193 	*	@brief The main SourceHook interface
   194 	*/
   195 	class ISourceHook
   196 	{
   197 	public:
   198 		/**
   199 		*	@brief Add a hook.
   200 		*
   201 		*	@return True if the function succeeded, false otherwise
   202 		*
   203 		*	@param plug The unique identifier of the plugin that calls this function
   204 		*	@param iface The interface pointer
   205 		*	@param ifacesize The size of the class iface points to
   206 		*	@param myHooker A hooker function that should be capable of handling the function
   207 		*	@param handler A pointer to a FastDelegate containing the hook handler
   208 		*	@param post Set to true if you want a post handler
   209 		*/
   210 		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   211 
   212 		/**
   213 		*	@brief Removes a hook.
   214 		*
   215 		*	@return True if the function succeeded, false otherwise
   216 		*
   217 		*	@param plug The unique identifier of the plugin that calls this function
   218 		*	@param iface The interface pointer
   219 		*	@param myHooker A hooker function that should be capable of handling the function
   220 		*	@param handler A pointer to a FastDelegate containing the hook handler
   221 		*	@param post Set to true if you want a post handler
   222 		*/
   223 		virtual bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post) = 0;
   224 
   225 		/**
   226 		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
   227 		*
   228 		*	@param plug The unique identifier of the plugin in question
   229 		*/
   230 		virtual bool IsPluginInUse(Plugin plug) = 0;
   231 
   232 		/**
   233 		*	@brief Return a pointer to a callclass. Generate a new one if required.
   234 		*
   235 		*	@param iface The interface pointer
   236 		*	@param size Size of the class
   237 		*/
   238 		virtual void *GetCallClass(void *iface, size_t size) = 0;
   239 
   240 		/**
   241 		*	@brief Release a callclass
   242 		*
   243 		*	@param ptr Pointer to the callclass
   244 		*/
   245 		virtual void ReleaseCallClass(void *ptr) = 0;
   246 
   247 		virtual void SetRes(META_RES res) = 0;				//!< Sets the meta result
   248 		virtual META_RES GetPrevRes() = 0;					//!< Gets the meta result of the previously called handler
   249 		virtual META_RES GetStatus() = 0;					//!< Gets the highest meta result
   250 		virtual const void *GetOrigRet() = 0;				//!< Gets the original result. If not in post function, undefined
   251 		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result. If none is specified, NULL
   252 		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   253 		//////////////////////////////////////////////////////////////////////////
   254 		// For hookers
   255 		virtual META_RES &GetCurResRef() = 0;				//!< Gets the pointer to the current meta result
   256 		virtual META_RES &GetPrevResRef() = 0;				//!< Gets the pointer to the previous meta result
   257 		virtual META_RES &GetStatusRef() = 0;				//!< Gets the pointer to the status variable
   258 		virtual void SetOrigRet(const void *ptr) = 0;		//!< Sets the original return pointer
   259 		virtual void SetOverrideRet(const void *ptr) = 0;	//!< Sets the override result pointer
   260 		virtual void SetIfacePtr(void *ptr) = 0;			//!< Sets the interface this pointer
   261 	};
   262 }
   263 
   264 //////////////////////////////////////////////////////////////////////////
   265 // Macro interface
   266 #define SET_META_RESULT(result)		g_SHPtr->SetRes(result)
   267 #define RETURN_META(result)			do { g_SHPtr->SetRes(result); return; } while(0)
   268 #define RETURN_META_VALUE(result, value)	do { g_SHPtr->SetRes(result); return (value); } while(0)
   269 
   270 #define META_RESULT_STATUS					g_SHPtr->GetStatus()
   271 #define META_RESULT_PREVIOUS				g_SHPtr->GetPrevRes()
   272 #define META_RESULT_ORIG_RET(type)			*(const type *)g_SHPtr->GetOrigRet()
   273 #define META_RESULT_OVERRIDE_RET(type)		*(const type *)g_SHPtr->GetOverrideRet()
   274 #define META_IFACEPTR						g_SHPtr->GetIfacePtr()
   275 
   276 
   277 /**
   278 *	@brief Get/generate callclass for an interface pointer
   279 *
   280 *	@param ifacetype The type of the interface
   281 *	@param ifaceptr The interface pointer
   282 */
   283 #define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(g_SHPtr->GetCallClass(ifaceptr, sizeof(ifacetype)))
   284 #define SH_RELEASE_CALLCLASS(ptr) g_SHPtr->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   285 
   286 #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   287 	SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   288 #define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   289 	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   290 #define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   291 	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   292 
   293 #define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   294 	SourceHook::SH_FHRemove##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   295 #define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   296 	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   297 #define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   298 	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   299 
   300 #define SH_NOATTRIB
   301 
   302 
   303 //////////////////////////////////////////////////////////////////////////
   304 #define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
   305 
   306 #define SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   307 	static int Hooker(HookerAction action, HookerInfo *param) \
   308 	{ \
   309 		if (action == HA_GetInfo) \
   310 		{ \
   311 			param->proto = ms_Proto; \
   312 			MemFuncInfo mfi; \
   313 			GetFuncInfo(funcptr, mfi); \
   314 			param->vtbl_idx = mfi.vtblindex; \
   315 			param->vtbl_offs = mfi.vtbloffs; \
   316 			param->thisptr_offs = mfi.thisptroffs; \
   317 			if (param->thisptr_offs) \
   318 				return 2; /*No virtual inheritance supported*/ \
   319 			GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
   320 			param->hookfunc_vtbl_idx = mfi.vtblindex; \
   321 			param->hookfunc_vtbl_offs = mfi.vtbloffs; \
   322 			param->hookfunc_inst = (void*)&ms_Inst; \
   323 			return 0; \
   324 		} \
   325 		else if (action == HA_Register) \
   326 		{ \
   327 			ms_HI = param; \
   328 			return 0; \
   329 		} \
   330 		else if (action == HA_Unregister) \
   331 		{ \
   332 			ms_HI = NULL; \
   333 			return 0; \
   334 		} \
   335 		else \
   336 			return 1; \
   337 	}
   338 
   339 #define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
   340 	namespace SourceHook \
   341 	{ \
   342 		struct SH_FHCls(ifacetype,ifacefunc,overload) \
   343 		{ \
   344 			static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   345 			static HookerInfo *ms_HI; \
   346 			static const char *ms_Proto; \
   347 			SHINT_MAKE_HOOKERPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   348 
   349 #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
   350 		}; \
   351 		const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
   352 		SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   353 		HookerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   354 		bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   355 			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   356 		{ \
   357 			return g_SHPtr->AddHook(g_Plug, iface, sizeof(ifacetype), \
   358 				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, \
   359 				new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   360 		} \
   361 		bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   362 			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   363 		{ \
   364 			CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
   365 			return g_SHPtr->RemoveHook(g_Plug, iface, \
   366 				SH_FHCls(ifacetype,ifacefunc,overload)::Hooker, &tmp, post); \
   367 		} \
   368 	}
   369 
   370 #define SH_SETUPCALLS(rettype) \
   371 	/* 1) Find the iface ptr */ \
   372 	/* 1.1) Adjust to original this pointer */ \
   373 	void *origthis = this - ms_HI->thisptr_offs; \
   374 	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   375 		ms_HI->ifaces.end(), origthis); \
   376 	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   377 	HookerInfo::Iface &ci = *ifaceiter; \
   378 	/* 2) Declare some vars and set it up */ \
   379 	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   380 	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   381 	rettype orig_ret, override_ret, plugin_ret; \
   382 	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   383 	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   384 	META_RES &status = g_SHPtr->GetStatusRef(); \
   385 	status = MRES_IGNORED; \
   386 	g_SHPtr->SetIfacePtr(ci.ptr); \
   387 	g_SHPtr->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   388 	g_SHPtr->SetOverrideRet(NULL);
   389 
   390 #define SH_CALL_HOOKS(post, params) \
   391 	prev_res = MRES_IGNORED; \
   392 	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   393 	{ \
   394 		cur_res = MRES_IGNORED; \
   395 		plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   396 		prev_res = cur_res; \
   397 		if (cur_res > status) \
   398 			status = cur_res; \
   399 		if (cur_res >= MRES_OVERRIDE) \
   400 		{ \
   401 			override_ret = plugin_ret; \
   402 			g_SHPtr->SetOverrideRet(&override_ret); \
   403 		} \
   404 	}
   405 
   406 #define SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   407 	if (status != MRES_SUPERCEDE) \
   408 		orig_ret = reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params; \
   409 	else \
   410 		orig_ret = override_ret;
   411 
   412 #define SH_RETURN() \
   413 	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   414 
   415 #define SH_HANDLEFUNC(ifacetype, ifacefunc, params, rettype) \
   416 	SH_SETUPCALLS(rettype) \
   417 	SH_CALL_HOOKS(pre, params) \
   418 	SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   419 	SH_CALL_HOOKS(post, params) \
   420 	SH_RETURN()
   421 
   422 //////////////////////////////////////////////////////////////////////////
   423 #define SH_SETUPCALLS_void() \
   424 	/* 1) Find the iface ptr */ \
   425 	/* 1.1) Adjust to original this pointer */ \
   426 	void *origthis = this - ms_HI->thisptr_offs; \
   427 	std::list<HookerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   428 		ms_HI->ifaces.end(), origthis); \
   429 	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   430 	HookerInfo::Iface &ci = *ifaceiter; \
   431 	/* 2) Declare some vars and set it up */ \
   432 	std::list<HookerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   433 	std::list<HookerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   434 	META_RES &cur_res = g_SHPtr->GetCurResRef(); \
   435 	META_RES &prev_res = g_SHPtr->GetPrevResRef(); \
   436 	META_RES &status = g_SHPtr->GetStatusRef(); \
   437 	status = MRES_IGNORED; \
   438 	g_SHPtr->SetIfacePtr(ci.ptr); \
   439 	g_SHPtr->SetOverrideRet(NULL);
   440 
   441 #define SH_CALL_HOOKS_void(post, params) \
   442 	prev_res = MRES_IGNORED; \
   443 	for (std::list<HookerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   444 	{ \
   445 		cur_res = MRES_IGNORED; \
   446 		reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   447 		prev_res = cur_res; \
   448 		if (cur_res > status) \
   449 			status = cur_res; \
   450 	}
   451 
   452 #define SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   453 	if (status != MRES_SUPERCEDE) \
   454 		reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params;
   455 
   456 #define SH_RETURN_void()
   457 
   458 #define SH_HANDLEFUNC_void(ifacetype, ifacefunc, params) \
   459 	SH_SETUPCALLS_void() \
   460 	SH_CALL_HOOKS_void(pre, params) \
   461 	SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   462 	SH_CALL_HOOKS_void(post, params) \
   463 	SH_RETURN_void()
   464 
   465 
   466 // Special vafmt handlers
   467 #define SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, params_orig, params_plug, rettype) \
   468 	SH_SETUPCALLS(rettype) \
   469 	SH_CALL_HOOKS(pre, params_plug) \
   470 	SH_CALL_ORIG(ifacetype, ifacefunc, params_orig) \
   471 	SH_CALL_HOOKS(post, params_plug) \
   472 	SH_RETURN()
   473 
   474 #define SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, params_orig, params_plug) \
   475 	SH_SETUPCALLS_void() \
   476 	SH_CALL_HOOKS_void(pre, params_plug) \
   477 	SH_CALL_ORIG_void(ifacetype, ifacefunc, params_orig) \
   478 	SH_CALL_HOOKS_void(post, params_plug) \
   479 	SH_RETURN_void()
   480 
   481 //////////////////////////////////////////////////////////////////////////
   482 
   483 @VARARGS@
   484 // *********
   485 #define SH_DECL_HOOK@$@(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   486 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @)> \
   487 		(&ifacetype::ifacefunc))) \
   488 		typedef fastdelegate::FastDelegate@$@<@param%%|, @@, @rettype> FD; \
   489 		virtual rettype Func(@param%% p%%|, @) attr \
   490 		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (@p%%|, @), rettype); } \
   491 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @)
   492 
   493 #define SH_DECL_HOOK@$@_void(ifacetype, ifacefunc, attr, overload@, param%%@) \
   494 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @)> \
   495 		(&ifacetype::ifacefunc))) \
   496 		typedef fastdelegate::FastDelegate@$@<@param%%|, @> FD; \
   497 		virtual void Func(@param%% p%%|, @) attr \
   498 		{ SH_HANDLEFUNC_void(ifacetype, ifacefunc, (@p%%|, @)); } \
   499 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @)
   500 
   501 #define SH_DECL_HOOK@$@_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   502 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   503 		(&ifacetype::ifacefunc))) \
   504 		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *, rettype> FD; \
   505 		virtual rettype Func(@param%% p%%|, @@, @const char *fmt, ...) attr \
   506 		{ \
   507 			char buf[STRBUF_LEN]; \
   508 			va_list ap; \
   509 			va_start(ap, fmt); \
   510 			vsnprintf(buf, sizeof(buf), fmt, ap); \
   511 			va_end(ap); \
   512 			SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf), rettype); \
   513 		} \
   514 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @ "|const char*|...")
   515 
   516 #define SH_DECL_HOOK@$@_void_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   517 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   518 		(&ifacetype::ifacefunc))) \
   519 		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *> FD; \
   520 		virtual void Func(@param%% p%%|, @@, @const char *, ...) attr \
   521 		{ \
   522 			char buf[STRBUF_LEN]; \
   523 			va_list ap; \
   524 			va_start(ap, fmt); \
   525 			vsnprintf(buf, sizeof(buf), fmt, ap); \
   526 			va_end(ap); \
   527 			SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf)); \
   528 		} \
   529 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @ "|const char*|...")
   530 
   531 @ENDARGS@
   532 
   533 /*
   534 #define SH_DECL_HOOK1(ifacetype, ifacefunc, attr, overload, rettype, param1) \
   535 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload) \
   536 		typedef fastdelegate::FastDelegate1<param1, rettype> FD; \
   537 		virtual rettype Func(param1 p1) \
   538 		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (p1), rettype); } \
   539 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype "|" #param1)
   540 		
   541 
   542 */
   543 
   544 #endif
   545 	// The pope is dead. -> :(