sourcehook/generate/sourcehook.hxx
author David Anderson <dvander@alliedmods.net>
Tue Apr 19 22:05:41 2005 +0000 (2005-04-19)
changeset 31 543ffb5f4908
parent 8 07e339563a28
child 41 534eac4c53ef
permissions -rwxr-xr-x
Initial import of stub plugin
     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_PLID
    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 int 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 				bool paused;					//!< If true, the hook should not be executed
   145 				Plugin plug;					//!< The owner plugin
   146 			};
   147 			void *callclass;					//!< Stores a call class for this interface
   148 			void *ptr;							//!< Pointer to the interface instance
   149 			void *orig_entry;					//!< The original vtable entry
   150 			std::list<Hook> hooks_pre;			//!< A list of pre-hooks
   151 			std::list<Hook> hooks_post;			//!< A list of post-hooks
   152 			bool operator ==(void *other) const
   153 			{
   154 				return ptr == other;
   155 			}
   156 		};
   157 		Plugin plug;							//!< The owner plugin
   158 		const char *proto;						//!< The prototype of the function the hook manager is responsible for
   159 		int vtbl_idx;							//!< The vtable index
   160 		int vtbl_offs;							//!< The vtable offset
   161 		int thisptr_offs;						//!< The this-pointer-adjuster
   162 		HookManagerPubFunc func;				//!< The interface to the hook manager
   163 
   164 		int hookfunc_vtbl_idx;					//!< the vtable index of the hookfunc
   165 		int hookfunc_vtbl_offs;					//!< the vtable offset of the hookfunc
   166 		void *hookfunc_inst;					//!< Instance of the class the hookfunc is in
   167 		
   168 		std::list<Iface> ifaces;				//!< List of hooked interfaces
   169 	};
   170 
   171 	/**
   172 	*	@brief Structure describing a callclass
   173 	*/
   174 	struct CallClass
   175 	{
   176 		struct VTable
   177 		{
   178 			void *ptr;
   179 			int actsize;
   180 			std::list<int> patches;	//!< Already patched entries
   181 			bool operator ==(void *other) const
   182 			{
   183 				return ptr == other;
   184 			}
   185 		};
   186 		void *iface;				//!< The iface pointer this callclass belongs to
   187 		size_t size;				//!< The size of the callclass
   188 		void *ptr;					//!< The actual "object"
   189 		typedef std::list<VTable> VTableList;
   190 		VTableList vtables;			//!< Already known vtables
   191 		int refcounter;				//!< How many times it was requested
   192 
   193 		bool operator ==(void *other) const
   194 		{
   195 			return ptr == other;
   196 		}
   197 	};
   198 
   199 	/**
   200 	*	@brief The main SourceHook interface
   201 	*/
   202 	class ISourceHook
   203 	{
   204 	public:
   205 		/**
   206 		*	@brief Add a hook.
   207 		*
   208 		*	@return True if the function succeeded, false otherwise
   209 		*
   210 		*	@param plug The unique identifier of the plugin that calls this function
   211 		*	@param iface The interface pointer
   212 		*	@param ifacesize The size of the class iface points to
   213 		*	@param myHookMan A hook manager function that should be capable of handling the function
   214 		*	@param handler A pointer to a FastDelegate containing the hook handler
   215 		*	@param post Set to true if you want a post handler
   216 		*/
   217 		virtual bool AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
   218 
   219 		/**
   220 		*	@brief Removes a hook.
   221 		*
   222 		*	@return True if the function succeeded, false otherwise
   223 		*
   224 		*	@param plug The unique identifier of the plugin that calls this function
   225 		*	@param iface The interface pointer
   226 		*	@param myHookMan A hook manager function that should be capable of handling the function
   227 		*	@param handler A pointer to a FastDelegate containing the hook handler
   228 		*	@param post Set to true if you want a post handler
   229 		*/
   230 		virtual bool RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post) = 0;
   231 
   232 		/**
   233 		*	@brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
   234 		*
   235 		*	@param plug The unique identifier of the plugin in question
   236 		*/
   237 		virtual bool IsPluginInUse(Plugin plug) = 0;
   238 
   239 		/**
   240 		*	@brief Return a pointer to a callclass. Generate a new one if required.
   241 		*
   242 		*	@param iface The interface pointer
   243 		*	@param size Size of the class
   244 		*/
   245 		virtual void *GetCallClass(void *iface, size_t size) = 0;
   246 
   247 		/**
   248 		*	@brief Release a callclass
   249 		*
   250 		*	@param ptr Pointer to the callclass
   251 		*/
   252 		virtual void ReleaseCallClass(void *ptr) = 0;
   253 
   254 		virtual void SetRes(META_RES res) = 0;				//!< Sets the meta result
   255 		virtual META_RES GetPrevRes() = 0;					//!< Gets the meta result of the previously called handler
   256 		virtual META_RES GetStatus() = 0;					//!< Gets the highest meta result
   257 		virtual const void *GetOrigRet() = 0;				//!< Gets the original result. If not in post function, undefined
   258 		virtual const void *GetOverrideRet() = 0;			//!< Gets the override result. If none is specified, NULL
   259 		virtual void *GetIfacePtr() = 0;					//!< Gets the interface pointer
   260 		//////////////////////////////////////////////////////////////////////////
   261 		// For hook managers
   262 		virtual META_RES &GetCurResRef() = 0;				//!< Gets the pointer to the current meta result
   263 		virtual META_RES &GetPrevResRef() = 0;				//!< Gets the pointer to the previous meta result
   264 		virtual META_RES &GetStatusRef() = 0;				//!< Gets the pointer to the status variable
   265 		virtual void SetOrigRet(const void *ptr) = 0;		//!< Sets the original return pointer
   266 		virtual void SetOverrideRet(const void *ptr) = 0;	//!< Sets the override result pointer
   267 		virtual void SetIfacePtr(void *ptr) = 0;			//!< Sets the interface this pointer
   268 	};
   269 }
   270 
   271 //////////////////////////////////////////////////////////////////////////
   272 // Macro interface
   273 #define SET_META_RESULT(result)		SH_GLOB_SHPTR->SetRes(result)
   274 #define RETURN_META(result)			do { SH_GLOB_SHPTR->SetRes(result); return; } while(0)
   275 #define RETURN_META_VALUE(result, value)	do { SH_GLOB_SHPTR->SetRes(result); return (value); } while(0)
   276 
   277 #define META_RESULT_STATUS					SH_GLOB_SHPTR->GetStatus()
   278 #define META_RESULT_PREVIOUS				SH_GLOB_SHPTR->GetPrevRes()
   279 #define META_RESULT_ORIG_RET(type)			*(const type *)SH_GLOB_SHPTR->GetOrigRet()
   280 #define META_RESULT_OVERRIDE_RET(type)		*(const type *)SH_GLOB_SHPTR->GetOverrideRet()
   281 #define META_IFACEPTR						SH_GLOB_SHPTR->GetIfacePtr()
   282 
   283 
   284 /**
   285 *	@brief Get/generate callclass for an interface pointer
   286 *
   287 *	@param ifacetype The type of the interface
   288 *	@param ifaceptr The interface pointer
   289 */
   290 #define SH_GET_CALLCLASS(ifacetype, ifaceptr) reinterpret_cast<ifacetype*>(SH_GLOB_SHPTR->GetCallClass(ifaceptr, sizeof(ifacetype)))
   291 #define SH_RELEASE_CALLCLASS(ptr) SH_GLOB_SHPTR->ReleaseCallClass(reinterpret_cast<void*>(ptr))
   292 
   293 #define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   294 	SourceHook::SH_FHAdd##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   295 #define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   296 	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   297 #define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   298 	SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   299 
   300 #define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
   301 	SourceHook::SH_FHRemove##ifacetype##ifacefunc((void*)ifaceptr, post, handler)
   302 #define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
   303 	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post)
   304 #define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
   305 	SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, fastdelegate::MakeDelegate(handler_inst, handler_func), post)
   306 
   307 #define SH_NOATTRIB
   308 
   309 
   310 //////////////////////////////////////////////////////////////////////////
   311 #define SH_FHCls(ift, iff, ov) FHCls_##ift##iff##ov
   312 
   313 #define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
   314 	static int HookManPubFunc(HookManagerAction action, HookManagerInfo *param) \
   315 	{ \
   316 		if (action == HA_GetInfo) \
   317 		{ \
   318 			param->proto = ms_Proto; \
   319 			MemFuncInfo mfi; \
   320 			GetFuncInfo(funcptr, mfi); \
   321 			param->vtbl_idx = mfi.vtblindex; \
   322 			param->vtbl_offs = mfi.vtbloffs; \
   323 			param->thisptr_offs = mfi.thisptroffs; \
   324 			if (param->thisptr_offs < 0) \
   325 				return 2; /*No virtual inheritance supported*/ \
   326 			GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
   327 			param->hookfunc_vtbl_idx = mfi.vtblindex; \
   328 			param->hookfunc_vtbl_offs = mfi.vtbloffs; \
   329 			param->hookfunc_inst = (void*)&ms_Inst; \
   330 			return 0; \
   331 		} \
   332 		else if (action == HA_Register) \
   333 		{ \
   334 			ms_HI = param; \
   335 			return 0; \
   336 		} \
   337 		else if (action == HA_Unregister) \
   338 		{ \
   339 			ms_HI = NULL; \
   340 			return 0; \
   341 		} \
   342 		else \
   343 			return 1; \
   344 	}
   345 
   346 #define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
   347 	namespace SourceHook \
   348 	{ \
   349 		struct SH_FHCls(ifacetype,ifacefunc,overload) \
   350 		{ \
   351 			static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
   352 			static HookManagerInfo *ms_HI; \
   353 			static const char *ms_Proto; \
   354 			SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
   355 
   356 #define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, proto) \
   357 		}; \
   358 		const char *SH_FHCls(ifacetype,ifacefunc,overload)::ms_Proto = proto; \
   359 		SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
   360 		HookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
   361 		bool SH_FHAdd##ifacetype##ifacefunc(void *iface, bool post, \
   362 			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   363 		{ \
   364 			return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, iface, sizeof(ifacetype), \
   365 				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
   366 				new CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD>(handler), post); \
   367 		} \
   368 		bool SH_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
   369 			SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
   370 		{ \
   371 			CSHDelegate<SH_FHCls(ifacetype,ifacefunc,overload)::FD> tmp(handler); \
   372 			return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, \
   373 				SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
   374 		} \
   375 	}
   376 
   377 #define SH_SETUPCALLS(rettype) \
   378 	/* 1) Find the iface ptr */ \
   379 	/* 1.1) Adjust to original this pointer */ \
   380 	void *origthis = this - ms_HI->thisptr_offs; \
   381 	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   382 		ms_HI->ifaces.end(), origthis); \
   383 	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   384 	HookManagerInfo::Iface &ci = *ifaceiter; \
   385 	/* 2) Declare some vars and set it up */ \
   386 	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   387 	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   388 	rettype orig_ret, override_ret, plugin_ret; \
   389 	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   390 	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   391 	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   392 	status = MRES_IGNORED; \
   393 	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   394 	SH_GLOB_SHPTR->SetOrigRet(reinterpret_cast<void*>(&orig_ret)); \
   395 	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   396 
   397 #define SH_CALL_HOOKS(post, params) \
   398 	prev_res = MRES_IGNORED; \
   399 	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   400 	{ \
   401 		if (hiter->paused) continue; \
   402 		cur_res = MRES_IGNORED; \
   403 		plugin_ret = reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   404 		prev_res = cur_res; \
   405 		if (cur_res > status) \
   406 			status = cur_res; \
   407 		if (cur_res >= MRES_OVERRIDE) \
   408 		{ \
   409 			override_ret = plugin_ret; \
   410 			SH_GLOB_SHPTR->SetOverrideRet(&override_ret); \
   411 		} \
   412 	}
   413 
   414 #define SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   415 	if (status != MRES_SUPERCEDE) \
   416 		orig_ret = reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params; \
   417 	else \
   418 		orig_ret = override_ret;
   419 
   420 #define SH_RETURN() \
   421 	return status >= MRES_OVERRIDE ? override_ret : orig_ret;
   422 
   423 #define SH_HANDLEFUNC(ifacetype, ifacefunc, params, rettype) \
   424 	SH_SETUPCALLS(rettype) \
   425 	SH_CALL_HOOKS(pre, params) \
   426 	SH_CALL_ORIG(ifacetype, ifacefunc, params) \
   427 	SH_CALL_HOOKS(post, params) \
   428 	SH_RETURN()
   429 
   430 //////////////////////////////////////////////////////////////////////////
   431 #define SH_SETUPCALLS_void() \
   432 	/* 1) Find the iface ptr */ \
   433 	/* 1.1) Adjust to original this pointer */ \
   434 	void *origthis = this - ms_HI->thisptr_offs; \
   435 	std::list<HookManagerInfo::Iface>::iterator ifaceiter = std::find(ms_HI->ifaces.begin(), \
   436 		ms_HI->ifaces.end(), origthis); \
   437 	SH_ASSERT(ifaceiter != ms_HI->ifaces.end()); \
   438 	HookManagerInfo::Iface &ci = *ifaceiter; \
   439 	/* 2) Declare some vars and set it up */ \
   440 	std::list<HookManagerInfo::Iface::Hook> &prelist = ci.hooks_pre; \
   441 	std::list<HookManagerInfo::Iface::Hook> &postlist = ci.hooks_post; \
   442 	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   443 	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   444 	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   445 	status = MRES_IGNORED; \
   446 	SH_GLOB_SHPTR->SetIfacePtr(ci.ptr); \
   447 	SH_GLOB_SHPTR->SetOverrideRet(NULL);
   448 
   449 #define SH_CALL_HOOKS_void(post, params) \
   450 	prev_res = MRES_IGNORED; \
   451 	for (std::list<HookManagerInfo::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   452 	{ \
   453 		if (hiter->paused) continue; \
   454 		cur_res = MRES_IGNORED; \
   455 		reinterpret_cast<CSHDelegate<FD>*>(hiter->handler)->GetDeleg() params; \
   456 		prev_res = cur_res; \
   457 		if (cur_res > status) \
   458 			status = cur_res; \
   459 	}
   460 
   461 #define SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   462 	if (status != MRES_SUPERCEDE) \
   463 		reinterpret_cast<ifacetype*>(ci.callclass)->ifacefunc params;
   464 
   465 #define SH_RETURN_void()
   466 
   467 #define SH_HANDLEFUNC_void(ifacetype, ifacefunc, params) \
   468 	SH_SETUPCALLS_void() \
   469 	SH_CALL_HOOKS_void(pre, params) \
   470 	SH_CALL_ORIG_void(ifacetype, ifacefunc, params) \
   471 	SH_CALL_HOOKS_void(post, params) \
   472 	SH_RETURN_void()
   473 
   474 
   475 // Special vafmt handlers
   476 #define SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, params_orig, params_plug, rettype) \
   477 	SH_SETUPCALLS(rettype) \
   478 	SH_CALL_HOOKS(pre, params_plug) \
   479 	SH_CALL_ORIG(ifacetype, ifacefunc, params_orig) \
   480 	SH_CALL_HOOKS(post, params_plug) \
   481 	SH_RETURN()
   482 
   483 #define SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, params_orig, params_plug) \
   484 	SH_SETUPCALLS_void() \
   485 	SH_CALL_HOOKS_void(pre, params_plug) \
   486 	SH_CALL_ORIG_void(ifacetype, ifacefunc, params_orig) \
   487 	SH_CALL_HOOKS_void(post, params_plug) \
   488 	SH_RETURN_void()
   489 
   490 //////////////////////////////////////////////////////////////////////////
   491 
   492 @VARARGS@
   493 // *********
   494 #define SH_DECL_HOOK@$@(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   495 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @)> \
   496 		(&ifacetype::ifacefunc))) \
   497 		typedef fastdelegate::FastDelegate@$@<@param%%|, @@, @rettype> FD; \
   498 		virtual rettype Func(@param%% p%%|, @) attr \
   499 		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (@p%%|, @), rettype); } \
   500 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @)
   501 
   502 #define SH_DECL_HOOK@$@_void(ifacetype, ifacefunc, attr, overload@, param%%@) \
   503 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @)> \
   504 		(&ifacetype::ifacefunc))) \
   505 		typedef fastdelegate::FastDelegate@$@<@param%%|, @> FD; \
   506 		virtual void Func(@param%% p%%|, @) attr \
   507 		{ SH_HANDLEFUNC_void(ifacetype, ifacefunc, (@p%%|, @)); } \
   508 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @)
   509 
   510 #define SH_DECL_HOOK@$@_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   511 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   512 		(&ifacetype::ifacefunc))) \
   513 		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *, rettype> FD; \
   514 		virtual rettype Func(@param%% p%%|, @@, @const char *fmt, ...) attr \
   515 		{ \
   516 			char buf[STRBUF_LEN]; \
   517 			va_list ap; \
   518 			va_start(ap, fmt); \
   519 			vsnprintf(buf, sizeof(buf), fmt, ap); \
   520 			va_end(ap); \
   521 			SH_HANDLEFUNC_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf), rettype); \
   522 		} \
   523 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype @"|" #param%%| @ "|const char*|...")
   524 
   525 #define SH_DECL_HOOK@$@_void_vafmt(ifacetype, ifacefunc, attr, overload, rettype@, param%%@) \
   526 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@param%%|, @@, @const char *, ...)> \
   527 		(&ifacetype::ifacefunc))) \
   528 		typedef fastdelegate::FastDelegate@$+1@<@param%%|, @@, @const char *> FD; \
   529 		virtual void Func(@param%% p%%|, @@, @const char *, ...) attr \
   530 		{ \
   531 			char buf[STRBUF_LEN]; \
   532 			va_list ap; \
   533 			va_start(ap, fmt); \
   534 			vsnprintf(buf, sizeof(buf), fmt, ap); \
   535 			va_end(ap); \
   536 			SH_HANDLEFUNC_void_vafmt(ifacetype, ifacefunc, (@p%%|, @@, @"%s", buf), (@p%%|, @@, @buf)); \
   537 		} \
   538 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr @"|" #param%%| @ "|const char*|...")
   539 
   540 @ENDARGS@
   541 
   542 /*
   543 #define SH_DECL_HOOK1(ifacetype, ifacefunc, attr, overload, rettype, param1) \
   544 	SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload) \
   545 		typedef fastdelegate::FastDelegate1<param1, rettype> FD; \
   546 		virtual rettype Func(param1 p1) \
   547 		{ SH_HANDLEFUNC(ifacetype, ifacefunc, (p1), rettype); } \
   548 	SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, #attr "|" #rettype "|" #param1)
   549 		
   550 
   551 */
   552 
   553 #endif
   554 	// The pope is dead. -> :(