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