sourcehook/test/testhookmangen.h
author Pavol Marko <pavolmarko@gmail.com>
Thu Nov 01 17:29:39 2007 +0000 (2007-11-01)
branchhookman_autogen
changeset 436 41f21d77c3c1
parent 432 f26dd3e3030b
child 437 89cf494f6088
permissions -rw-r--r--
Implemented memory returns on MSVC for POD types.
     1 // Strip &
     2 template <class T> struct StripRef
     3 {
     4 	typedef T type;
     5 };
     6 
     7 template <class T> struct StripRef<T&>
     8 {
     9 	typedef T type;
    10 };
    11 
    12 // Address of constructor/destructor
    13 // (using wrappers)
    14 template <class T>
    15 class Ctor_Thunk
    16 {
    17 public:
    18 	void NormalConstructor()
    19 	{
    20 		new(this) T;
    21 	}
    22 
    23 	void CopyConstructor(const T &other)
    24 	{
    25 		new(this) T(other);
    26 	}
    27 
    28 	void Destructor()
    29 	{
    30 		reinterpret_cast<T*>(this)->~T();
    31 	}
    32 };
    33 
    34 
    35 template <class T>
    36 void *FindFuncAddr(T mfp)
    37 {
    38 	if (sizeof(mfp) != sizeof(void*))
    39 		return NULL;
    40 	else
    41 		return fastdelegate::detail::horrible_cast<void*>(mfp);
    42 }
    43 
    44 // Reference carrier
    45 template <class T> struct MyRefCarrier
    46 {
    47 	typedef T type;
    48 };
    49 
    50 template <class T> struct MyRefCarrier<T&>
    51 {
    52 	class type
    53 	{
    54 		T *m_StoredRef;
    55 	public:
    56 		type() : m_StoredRef(NULL)
    57 		{
    58 		}
    59 		type(T& ref) : m_StoredRef(&ref)
    60 		{
    61 		}
    62 
    63 		T& operator= (T& ref)
    64 		{
    65 			m_StoredRef = &ref;
    66 			return ref;
    67 		}
    68 
    69 		operator T& () const
    70 		{
    71 			return *m_StoredRef;
    72 		}
    73 		
    74 		bool operator== (const typename MyRefCarrier<T&>::type &other)
    75 		{
    76 			return m_StoredRef == other.m_StoredRef;
    77 		}
    78 		
    79 		friend std::ostream& operator <<(std::ostream &os,const typename MyRefCarrier<T&>::type &obj)
    80 		{
    81 			os << *obj.m_StoredRef;
    82 			return os;
    83 		}
    84 	};
    85 };
    86 
    87 // Return value maker
    88 template <class T>
    89 struct MakeRet
    90 {
    91 	static T Do(int a)
    92 	{
    93 		return static_cast<T>(a);
    94 	}
    95 };
    96 
    97 template <int SIZE>
    98 struct MakeRet< POD<SIZE> >
    99 {
   100 	static POD<SIZE> Do(int a)
   101 	{
   102 		POD<SIZE> x;
   103 		memset(reinterpret_cast<void*>(x.x), a, SIZE);
   104 		return x;
   105 	}
   106 };
   107 
   108 // Stores parameter status
   109 
   110 
   111 template<int dummy>
   112 struct ParamState0
   113 {
   114 	
   115 	
   116 	bool operator==(const ParamState0<dummy> &other)
   117 	{
   118 		return true
   119 			
   120 			;
   121 	}
   122 	ParamState0()  
   123 	{
   124 	}
   125 	
   126 	ParamState0<dummy> & operator() (int incrsteps)
   127 	{
   128 		
   129 		
   130 		
   131 		return *this;
   132 	}
   133 };
   134 
   135 
   136 std::ostream& operator <<(std::ostream &os,const ParamState0<0> &obj)
   137 {
   138 	 ;
   139 	return os;
   140 }
   141 	
   142 
   143 
   144 template<int dummy, class p1>
   145 struct ParamState1
   146 {
   147 	typename MyRefCarrier<p1>::type m_1; 
   148 	
   149 	bool operator==(const ParamState1<dummy, p1> &other)
   150 	{
   151 		return true
   152 			 && m_1 == other.m_1
   153 			;
   154 	}
   155 	ParamState1(p1 a1) : m_1(a1)
   156 	{
   157 	}
   158 	
   159 	ParamState1<dummy, p1> & operator() (int incrsteps)
   160 	{
   161 		int i;
   162 		
   163 		for (i = 0; i < incrsteps; ++i)
   164 			Increment<StripRef< p1 >::type>::Incr(m_1);
   165 		
   166 		
   167 		return *this;
   168 	}
   169 };
   170 
   171 template<class p1>
   172 std::ostream& operator <<(std::ostream &os,const ParamState1<0, p1> &obj)
   173 {
   174 	os << obj.m_1;
   175 	return os;
   176 }
   177 	
   178 
   179 
   180 template<int dummy, class p1, class p2>
   181 struct ParamState2
   182 {
   183 	typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; 
   184 	
   185 	bool operator==(const ParamState2<dummy, p1, p2> &other)
   186 	{
   187 		return true
   188 			 && m_2 == other.m_2 && m_2 == other.m_2
   189 			;
   190 	}
   191 	ParamState2(p1 a1, p2 a2) : m_1(a1), m_2(a2)
   192 	{
   193 	}
   194 	
   195 	ParamState2<dummy, p1, p2> & operator() (int incrsteps)
   196 	{
   197 		int i;
   198 		
   199 		for (i = 0; i < incrsteps; ++i)
   200 			Increment<StripRef< p1 >::type>::Incr(m_1);
   201 		
   202 		for (i = 0; i < incrsteps; ++i)
   203 			Increment<StripRef< p2 >::type>::Incr(m_2);
   204 		
   205 		
   206 		return *this;
   207 	}
   208 };
   209 
   210 template<class p1, class p2>
   211 std::ostream& operator <<(std::ostream &os,const ParamState2<0, p1, p2> &obj)
   212 {
   213 	os << obj.m_1<< obj.m_2;
   214 	return os;
   215 }
   216 	
   217 
   218 
   219 template<int dummy, class p1, class p2, class p3>
   220 struct ParamState3
   221 {
   222 	typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; 
   223 	
   224 	bool operator==(const ParamState3<dummy, p1, p2, p3> &other)
   225 	{
   226 		return true
   227 			 && m_3 == other.m_3 && m_3 == other.m_3 && m_3 == other.m_3
   228 			;
   229 	}
   230 	ParamState3(p1 a1, p2 a2, p3 a3) : m_1(a1), m_2(a2), m_3(a3)
   231 	{
   232 	}
   233 	
   234 	ParamState3<dummy, p1, p2, p3> & operator() (int incrsteps)
   235 	{
   236 		int i;
   237 		
   238 		for (i = 0; i < incrsteps; ++i)
   239 			Increment<StripRef< p1 >::type>::Incr(m_1);
   240 		
   241 		for (i = 0; i < incrsteps; ++i)
   242 			Increment<StripRef< p2 >::type>::Incr(m_2);
   243 		
   244 		for (i = 0; i < incrsteps; ++i)
   245 			Increment<StripRef< p3 >::type>::Incr(m_3);
   246 		
   247 		
   248 		return *this;
   249 	}
   250 };
   251 
   252 template<class p1, class p2, class p3>
   253 std::ostream& operator <<(std::ostream &os,const ParamState3<0, p1, p2, p3> &obj)
   254 {
   255 	os << obj.m_1<< obj.m_2<< obj.m_3;
   256 	return os;
   257 }
   258 	
   259 
   260 
   261 template<int dummy, class p1, class p2, class p3, class p4>
   262 struct ParamState4
   263 {
   264 	typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4; 
   265 	
   266 	bool operator==(const ParamState4<dummy, p1, p2, p3, p4> &other)
   267 	{
   268 		return true
   269 			 && m_4 == other.m_4 && m_4 == other.m_4 && m_4 == other.m_4 && m_4 == other.m_4
   270 			;
   271 	}
   272 	ParamState4(p1 a1, p2 a2, p3 a3, p4 a4) : m_1(a1), m_2(a2), m_3(a3), m_4(a4)
   273 	{
   274 	}
   275 	
   276 	ParamState4<dummy, p1, p2, p3, p4> & operator() (int incrsteps)
   277 	{
   278 		int i;
   279 		
   280 		for (i = 0; i < incrsteps; ++i)
   281 			Increment<StripRef< p1 >::type>::Incr(m_1);
   282 		
   283 		for (i = 0; i < incrsteps; ++i)
   284 			Increment<StripRef< p2 >::type>::Incr(m_2);
   285 		
   286 		for (i = 0; i < incrsteps; ++i)
   287 			Increment<StripRef< p3 >::type>::Incr(m_3);
   288 		
   289 		for (i = 0; i < incrsteps; ++i)
   290 			Increment<StripRef< p4 >::type>::Incr(m_4);
   291 		
   292 		
   293 		return *this;
   294 	}
   295 };
   296 
   297 template<class p1, class p2, class p3, class p4>
   298 std::ostream& operator <<(std::ostream &os,const ParamState4<0, p1, p2, p3, p4> &obj)
   299 {
   300 	os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4;
   301 	return os;
   302 }
   303 	
   304 
   305 
   306 template<int dummy, class p1, class p2, class p3, class p4, class p5>
   307 struct ParamState5
   308 {
   309 	typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4; typename MyRefCarrier<p5>::type m_5; 
   310 	
   311 	bool operator==(const ParamState5<dummy, p1, p2, p3, p4, p5> &other)
   312 	{
   313 		return true
   314 			 && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5
   315 			;
   316 	}
   317 	ParamState5(p1 a1, p2 a2, p3 a3, p4 a4, p5 a5) : m_1(a1), m_2(a2), m_3(a3), m_4(a4), m_5(a5)
   318 	{
   319 	}
   320 	
   321 	ParamState5<dummy, p1, p2, p3, p4, p5> & operator() (int incrsteps)
   322 	{
   323 		int i;
   324 		
   325 		for (i = 0; i < incrsteps; ++i)
   326 			Increment<StripRef< p1 >::type>::Incr(m_1);
   327 		
   328 		for (i = 0; i < incrsteps; ++i)
   329 			Increment<StripRef< p2 >::type>::Incr(m_2);
   330 		
   331 		for (i = 0; i < incrsteps; ++i)
   332 			Increment<StripRef< p3 >::type>::Incr(m_3);
   333 		
   334 		for (i = 0; i < incrsteps; ++i)
   335 			Increment<StripRef< p4 >::type>::Incr(m_4);
   336 		
   337 		for (i = 0; i < incrsteps; ++i)
   338 			Increment<StripRef< p5 >::type>::Incr(m_5);
   339 		
   340 		
   341 		return *this;
   342 	}
   343 };
   344 
   345 template<class p1, class p2, class p3, class p4, class p5>
   346 std::ostream& operator <<(std::ostream &os,const ParamState5<0, p1, p2, p3, p4, p5> &obj)
   347 {
   348 	os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4<< obj.m_5;
   349 	return os;
   350 }
   351 	
   352 
   353 
   354 template<int dummy, class p1, class p2, class p3, class p4, class p5, class p6>
   355 struct ParamState6
   356 {
   357 	typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4; typename MyRefCarrier<p5>::type m_5; typename MyRefCarrier<p6>::type m_6; 
   358 	
   359 	bool operator==(const ParamState6<dummy, p1, p2, p3, p4, p5, p6> &other)
   360 	{
   361 		return true
   362 			 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6
   363 			;
   364 	}
   365 	ParamState6(p1 a1, p2 a2, p3 a3, p4 a4, p5 a5, p6 a6) : m_1(a1), m_2(a2), m_3(a3), m_4(a4), m_5(a5), m_6(a6)
   366 	{
   367 	}
   368 	
   369 	ParamState6<dummy, p1, p2, p3, p4, p5, p6> & operator() (int incrsteps)
   370 	{
   371 		int i;
   372 		
   373 		for (i = 0; i < incrsteps; ++i)
   374 			Increment<StripRef< p1 >::type>::Incr(m_1);
   375 		
   376 		for (i = 0; i < incrsteps; ++i)
   377 			Increment<StripRef< p2 >::type>::Incr(m_2);
   378 		
   379 		for (i = 0; i < incrsteps; ++i)
   380 			Increment<StripRef< p3 >::type>::Incr(m_3);
   381 		
   382 		for (i = 0; i < incrsteps; ++i)
   383 			Increment<StripRef< p4 >::type>::Incr(m_4);
   384 		
   385 		for (i = 0; i < incrsteps; ++i)
   386 			Increment<StripRef< p5 >::type>::Incr(m_5);
   387 		
   388 		for (i = 0; i < incrsteps; ++i)
   389 			Increment<StripRef< p6 >::type>::Incr(m_6);
   390 		
   391 		
   392 		return *this;
   393 	}
   394 };
   395 
   396 template<class p1, class p2, class p3, class p4, class p5, class p6>
   397 std::ostream& operator <<(std::ostream &os,const ParamState6<0, p1, p2, p3, p4, p5, p6> &obj)
   398 {
   399 	os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4<< obj.m_5<< obj.m_6;
   400 	return os;
   401 }
   402 	
   403 
   404 
   405 #define CAT2(a, b) a##b
   406 #define CAT3(a, b, c) a##b##c
   407 #define CAT4(a, b, c, d) a##b##c##d
   408 
   409 // hook1: pre ignore
   410 // hook2: pre supercede
   411 // hook3: post ignore
   412 // hook4: post supercede
   413 
   414 
   415 
   416 
   417 #define THGM_MAKE_TEST0_void(id) \
   418 	struct TestClass##id; \
   419 	typedef ParamState0<0 > ParamState_m##id; \
   420 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   421 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   422 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   423 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   424 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   425 	\
   426 	struct TestClass##id \
   427 	{ \
   428 		static bool ms_DoRecall; \
   429 		\
   430 		virtual void Func() \
   431 		{ \
   432 			g_Inside_LeafFunc = true; \
   433 			ADD_STATE(State_Func##id(this, ParamState_m##id())); \
   434 			g_Inside_LeafFunc = false; \
   435 		} \
   436 		\
   437 		struct Delegate1 : public MyDelegate \
   438 		{ \
   439 			virtual void Call() \
   440 			{ \
   441 				g_Inside_LeafFunc = true; \
   442 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   443 				g_Inside_LeafFunc = false; \
   444 				if (ms_DoRecall) \
   445 				{ \
   446 					 \
   447 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, ()); \
   448 				} \
   449 				else \
   450 					RETURN_META(MRES_IGNORED); \
   451 			} \
   452 		}; \
   453 		struct Delegate2 : public MyDelegate \
   454 		{ \
   455 			virtual void Call() \
   456 			{ \
   457 				g_Inside_LeafFunc = true; \
   458 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   459 				g_Inside_LeafFunc = false; \
   460 				if (ms_DoRecall) \
   461 				{ \
   462 					 \
   463 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, ()); \
   464 				} \
   465 				else \
   466 					RETURN_META(MRES_SUPERCEDE); \
   467 			} \
   468 		}; \
   469 		struct Delegate3 : public MyDelegate \
   470 		{ \
   471 			virtual void Call() \
   472 			{ \
   473 				g_Inside_LeafFunc = true; \
   474 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   475 				g_Inside_LeafFunc = false; \
   476 				if (ms_DoRecall) \
   477 				{ \
   478 					 \
   479 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, ()); \
   480 				} \
   481 				else \
   482 					RETURN_META(MRES_IGNORED); \
   483 			} \
   484 		}; \
   485 		struct Delegate4 : public MyDelegate \
   486 		{ \
   487 			virtual void Call() \
   488 			{ \
   489 				g_Inside_LeafFunc = true; \
   490 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   491 				g_Inside_LeafFunc = false; \
   492 				if (ms_DoRecall) \
   493 				{ \
   494 					 \
   495 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, ()); \
   496 				} \
   497 				else \
   498 					RETURN_META(MRES_SUPERCEDE); \
   499 			}; \
   500 		}; \
   501 	}; \
   502 	\
   503 	bool TestClass##id::ms_DoRecall = false; \
   504 	\
   505 	SourceHook::PassInfo paraminfos_##id[0+1]; \
   506 	SourceHook::PassInfo::V2Info paraminfos2_##id[0+1]; \
   507 	SourceHook::ProtoInfo protoinfo_##id = { 0, {0, 0, 0}, paraminfos_##id, \
   508 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   509 	\
   510 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   511 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   512 
   513 
   514 #define THGM_MAKE_TEST0(id, ret_type) \
   515 	struct TestClass##id; \
   516 	typedef ParamState0<0 > ParamState_m##id; \
   517 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   518 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   519 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   520 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   521 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   522 	\
   523 	struct TestClass##id \
   524 	{ \
   525 		static bool ms_DoRecall; \
   526 		\
   527 		virtual ret_type Func() \
   528 		{ \
   529 			g_Inside_LeafFunc = true; \
   530 			ADD_STATE(State_Func##id(this, ParamState_m##id())); \
   531 			g_Inside_LeafFunc = false; \
   532 			\
   533 			return MakeRet<ret_type>::Do(0); \
   534 		} \
   535 		\
   536 		struct Delegate1 : public MyDelegate \
   537 		{ \
   538 			virtual ret_type Call() \
   539 			{ \
   540 				g_Inside_LeafFunc = true; \
   541 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   542 				g_Inside_LeafFunc = false; \
   543 				if (ms_DoRecall) \
   544 				{ \
   545 					 \
   546 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, ()); \
   547 				} \
   548 				else \
   549 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
   550 			} \
   551 		}; \
   552 		struct Delegate2 : public MyDelegate \
   553 		{ \
   554 			virtual ret_type Call() \
   555 			{ \
   556 				g_Inside_LeafFunc = true; \
   557 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   558 				g_Inside_LeafFunc = false; \
   559 				if (ms_DoRecall) \
   560 				{ \
   561 					 \
   562 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, ()); \
   563 				} \
   564 				else \
   565 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
   566 			} \
   567 		}; \
   568 		struct Delegate3 : public MyDelegate \
   569 		{ \
   570 			virtual ret_type Call() \
   571 			{ \
   572 				g_Inside_LeafFunc = true; \
   573 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   574 				g_Inside_LeafFunc = false; \
   575 				if (ms_DoRecall) \
   576 				{ \
   577 					 \
   578 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, ()); \
   579 				} \
   580 				else \
   581 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
   582 			} \
   583 		}; \
   584 		struct Delegate4 : public MyDelegate \
   585 		{ \
   586 			virtual ret_type Call() \
   587 			{ \
   588 				g_Inside_LeafFunc = true; \
   589 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
   590 				g_Inside_LeafFunc = false; \
   591 				if (ms_DoRecall) \
   592 				{ \
   593 					 \
   594 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, ()); \
   595 				} \
   596 				else \
   597 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
   598 			}; \
   599 		}; \
   600 	}; \
   601 	\
   602 	bool TestClass##id::ms_DoRecall = false; \
   603 	\
   604 	SourceHook::PassInfo paraminfos_##id[0+1]; \
   605 	SourceHook::PassInfo::V2Info paraminfos2_##id[0+1]; \
   606 	SourceHook::ProtoInfo protoinfo_##id = { 0, {0, 0, 0}, paraminfos_##id, \
   607 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   608 	\
   609 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   610 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   611 	
   612 #define THGM_SETUP_PI0(id) \
   613 	void setuppi_##id() \
   614 	{ \
   615 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
   616 		\
   617 		 \
   618 		\
   619 		 \
   620 		 \
   621 		 \
   622 	}
   623 	
   624 
   625 
   626 #define THGM_MAKE_TEST1_void(id, param1) \
   627 	struct TestClass##id; \
   628 	typedef ParamState1<0, param1 > ParamState_m##id; \
   629 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   630 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   631 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   632 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   633 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   634 	\
   635 	struct TestClass##id \
   636 	{ \
   637 		static bool ms_DoRecall; \
   638 		\
   639 		virtual void Func(param1 p1) \
   640 		{ \
   641 			g_Inside_LeafFunc = true; \
   642 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1))); \
   643 			g_Inside_LeafFunc = false; \
   644 		} \
   645 		\
   646 		struct Delegate1 : public MyDelegate \
   647 		{ \
   648 			virtual void Call(param1 p1) \
   649 			{ \
   650 				g_Inside_LeafFunc = true; \
   651 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   652 				g_Inside_LeafFunc = false; \
   653 				if (ms_DoRecall) \
   654 				{ \
   655 					Increment<StripRef< param1 >::type>::Incr(p1); \
   656 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1)); \
   657 				} \
   658 				else \
   659 					RETURN_META(MRES_IGNORED); \
   660 			} \
   661 		}; \
   662 		struct Delegate2 : public MyDelegate \
   663 		{ \
   664 			virtual void Call(param1 p1) \
   665 			{ \
   666 				g_Inside_LeafFunc = true; \
   667 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   668 				g_Inside_LeafFunc = false; \
   669 				if (ms_DoRecall) \
   670 				{ \
   671 					Increment<StripRef< param1 >::type>::Incr(p1); \
   672 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1)); \
   673 				} \
   674 				else \
   675 					RETURN_META(MRES_SUPERCEDE); \
   676 			} \
   677 		}; \
   678 		struct Delegate3 : public MyDelegate \
   679 		{ \
   680 			virtual void Call(param1 p1) \
   681 			{ \
   682 				g_Inside_LeafFunc = true; \
   683 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   684 				g_Inside_LeafFunc = false; \
   685 				if (ms_DoRecall) \
   686 				{ \
   687 					Increment<StripRef< param1 >::type>::Incr(p1); \
   688 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1)); \
   689 				} \
   690 				else \
   691 					RETURN_META(MRES_IGNORED); \
   692 			} \
   693 		}; \
   694 		struct Delegate4 : public MyDelegate \
   695 		{ \
   696 			virtual void Call(param1 p1) \
   697 			{ \
   698 				g_Inside_LeafFunc = true; \
   699 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   700 				g_Inside_LeafFunc = false; \
   701 				if (ms_DoRecall) \
   702 				{ \
   703 					Increment<StripRef< param1 >::type>::Incr(p1); \
   704 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1)); \
   705 				} \
   706 				else \
   707 					RETURN_META(MRES_SUPERCEDE); \
   708 			}; \
   709 		}; \
   710 	}; \
   711 	\
   712 	bool TestClass##id::ms_DoRecall = false; \
   713 	\
   714 	SourceHook::PassInfo paraminfos_##id[1+1]; \
   715 	SourceHook::PassInfo::V2Info paraminfos2_##id[1+1]; \
   716 	SourceHook::ProtoInfo protoinfo_##id = { 1, {0, 0, 0}, paraminfos_##id, \
   717 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   718 	\
   719 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   720 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   721 
   722 
   723 #define THGM_MAKE_TEST1(id, ret_type, param1) \
   724 	struct TestClass##id; \
   725 	typedef ParamState1<0, param1 > ParamState_m##id; \
   726 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   727 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   728 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   729 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   730 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   731 	\
   732 	struct TestClass##id \
   733 	{ \
   734 		static bool ms_DoRecall; \
   735 		\
   736 		virtual ret_type Func(param1 p1) \
   737 		{ \
   738 			g_Inside_LeafFunc = true; \
   739 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1))); \
   740 			g_Inside_LeafFunc = false; \
   741 			\
   742 			return MakeRet<ret_type>::Do(0); \
   743 		} \
   744 		\
   745 		struct Delegate1 : public MyDelegate \
   746 		{ \
   747 			virtual ret_type Call(param1 p1) \
   748 			{ \
   749 				g_Inside_LeafFunc = true; \
   750 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   751 				g_Inside_LeafFunc = false; \
   752 				if (ms_DoRecall) \
   753 				{ \
   754 					Increment<StripRef< param1 >::type>::Incr(p1); \
   755 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1)); \
   756 				} \
   757 				else \
   758 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
   759 			} \
   760 		}; \
   761 		struct Delegate2 : public MyDelegate \
   762 		{ \
   763 			virtual ret_type Call(param1 p1) \
   764 			{ \
   765 				g_Inside_LeafFunc = true; \
   766 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   767 				g_Inside_LeafFunc = false; \
   768 				if (ms_DoRecall) \
   769 				{ \
   770 					Increment<StripRef< param1 >::type>::Incr(p1); \
   771 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1)); \
   772 				} \
   773 				else \
   774 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
   775 			} \
   776 		}; \
   777 		struct Delegate3 : public MyDelegate \
   778 		{ \
   779 			virtual ret_type Call(param1 p1) \
   780 			{ \
   781 				g_Inside_LeafFunc = true; \
   782 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   783 				g_Inside_LeafFunc = false; \
   784 				if (ms_DoRecall) \
   785 				{ \
   786 					Increment<StripRef< param1 >::type>::Incr(p1); \
   787 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1)); \
   788 				} \
   789 				else \
   790 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
   791 			} \
   792 		}; \
   793 		struct Delegate4 : public MyDelegate \
   794 		{ \
   795 			virtual ret_type Call(param1 p1) \
   796 			{ \
   797 				g_Inside_LeafFunc = true; \
   798 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
   799 				g_Inside_LeafFunc = false; \
   800 				if (ms_DoRecall) \
   801 				{ \
   802 					Increment<StripRef< param1 >::type>::Incr(p1); \
   803 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1)); \
   804 				} \
   805 				else \
   806 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
   807 			}; \
   808 		}; \
   809 	}; \
   810 	\
   811 	bool TestClass##id::ms_DoRecall = false; \
   812 	\
   813 	SourceHook::PassInfo paraminfos_##id[1+1]; \
   814 	SourceHook::PassInfo::V2Info paraminfos2_##id[1+1]; \
   815 	SourceHook::ProtoInfo protoinfo_##id = { 1, {0, 0, 0}, paraminfos_##id, \
   816 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   817 	\
   818 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   819 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   820 	
   821 #define THGM_SETUP_PI1(id, p1_type, p1_passtype, p1_flags) \
   822 	void setuppi_##id() \
   823 	{ \
   824 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
   825 		\
   826 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  \
   827 		\
   828 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  \
   829 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  \
   830 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  \
   831 	}
   832 	
   833 
   834 
   835 #define THGM_MAKE_TEST2_void(id, param1, param2) \
   836 	struct TestClass##id; \
   837 	typedef ParamState2<0, param1, param2 > ParamState_m##id; \
   838 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   839 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   840 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   841 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   842 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   843 	\
   844 	struct TestClass##id \
   845 	{ \
   846 		static bool ms_DoRecall; \
   847 		\
   848 		virtual void Func(param1 p1, param2 p2) \
   849 		{ \
   850 			g_Inside_LeafFunc = true; \
   851 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2))); \
   852 			g_Inside_LeafFunc = false; \
   853 		} \
   854 		\
   855 		struct Delegate1 : public MyDelegate \
   856 		{ \
   857 			virtual void Call(param1 p1, param2 p2) \
   858 			{ \
   859 				g_Inside_LeafFunc = true; \
   860 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   861 				g_Inside_LeafFunc = false; \
   862 				if (ms_DoRecall) \
   863 				{ \
   864 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   865 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2)); \
   866 				} \
   867 				else \
   868 					RETURN_META(MRES_IGNORED); \
   869 			} \
   870 		}; \
   871 		struct Delegate2 : public MyDelegate \
   872 		{ \
   873 			virtual void Call(param1 p1, param2 p2) \
   874 			{ \
   875 				g_Inside_LeafFunc = true; \
   876 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   877 				g_Inside_LeafFunc = false; \
   878 				if (ms_DoRecall) \
   879 				{ \
   880 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   881 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2)); \
   882 				} \
   883 				else \
   884 					RETURN_META(MRES_SUPERCEDE); \
   885 			} \
   886 		}; \
   887 		struct Delegate3 : public MyDelegate \
   888 		{ \
   889 			virtual void Call(param1 p1, param2 p2) \
   890 			{ \
   891 				g_Inside_LeafFunc = true; \
   892 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   893 				g_Inside_LeafFunc = false; \
   894 				if (ms_DoRecall) \
   895 				{ \
   896 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   897 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2)); \
   898 				} \
   899 				else \
   900 					RETURN_META(MRES_IGNORED); \
   901 			} \
   902 		}; \
   903 		struct Delegate4 : public MyDelegate \
   904 		{ \
   905 			virtual void Call(param1 p1, param2 p2) \
   906 			{ \
   907 				g_Inside_LeafFunc = true; \
   908 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   909 				g_Inside_LeafFunc = false; \
   910 				if (ms_DoRecall) \
   911 				{ \
   912 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   913 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2)); \
   914 				} \
   915 				else \
   916 					RETURN_META(MRES_SUPERCEDE); \
   917 			}; \
   918 		}; \
   919 	}; \
   920 	\
   921 	bool TestClass##id::ms_DoRecall = false; \
   922 	\
   923 	SourceHook::PassInfo paraminfos_##id[2+1]; \
   924 	SourceHook::PassInfo::V2Info paraminfos2_##id[2+1]; \
   925 	SourceHook::ProtoInfo protoinfo_##id = { 2, {0, 0, 0}, paraminfos_##id, \
   926 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   927 	\
   928 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   929 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   930 
   931 
   932 #define THGM_MAKE_TEST2(id, ret_type, param1, param2) \
   933 	struct TestClass##id; \
   934 	typedef ParamState2<0, param1, param2 > ParamState_m##id; \
   935 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   936 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   937 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   938 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   939 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   940 	\
   941 	struct TestClass##id \
   942 	{ \
   943 		static bool ms_DoRecall; \
   944 		\
   945 		virtual ret_type Func(param1 p1, param2 p2) \
   946 		{ \
   947 			g_Inside_LeafFunc = true; \
   948 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2))); \
   949 			g_Inside_LeafFunc = false; \
   950 			\
   951 			return MakeRet<ret_type>::Do(0); \
   952 		} \
   953 		\
   954 		struct Delegate1 : public MyDelegate \
   955 		{ \
   956 			virtual ret_type Call(param1 p1, param2 p2) \
   957 			{ \
   958 				g_Inside_LeafFunc = true; \
   959 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   960 				g_Inside_LeafFunc = false; \
   961 				if (ms_DoRecall) \
   962 				{ \
   963 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   964 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1, p2)); \
   965 				} \
   966 				else \
   967 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
   968 			} \
   969 		}; \
   970 		struct Delegate2 : public MyDelegate \
   971 		{ \
   972 			virtual ret_type Call(param1 p1, param2 p2) \
   973 			{ \
   974 				g_Inside_LeafFunc = true; \
   975 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   976 				g_Inside_LeafFunc = false; \
   977 				if (ms_DoRecall) \
   978 				{ \
   979 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   980 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1, p2)); \
   981 				} \
   982 				else \
   983 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
   984 			} \
   985 		}; \
   986 		struct Delegate3 : public MyDelegate \
   987 		{ \
   988 			virtual ret_type Call(param1 p1, param2 p2) \
   989 			{ \
   990 				g_Inside_LeafFunc = true; \
   991 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
   992 				g_Inside_LeafFunc = false; \
   993 				if (ms_DoRecall) \
   994 				{ \
   995 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
   996 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1, p2)); \
   997 				} \
   998 				else \
   999 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
  1000 			} \
  1001 		}; \
  1002 		struct Delegate4 : public MyDelegate \
  1003 		{ \
  1004 			virtual ret_type Call(param1 p1, param2 p2) \
  1005 			{ \
  1006 				g_Inside_LeafFunc = true; \
  1007 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
  1008 				g_Inside_LeafFunc = false; \
  1009 				if (ms_DoRecall) \
  1010 				{ \
  1011 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
  1012 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1, p2)); \
  1013 				} \
  1014 				else \
  1015 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
  1016 			}; \
  1017 		}; \
  1018 	}; \
  1019 	\
  1020 	bool TestClass##id::ms_DoRecall = false; \
  1021 	\
  1022 	SourceHook::PassInfo paraminfos_##id[2+1]; \
  1023 	SourceHook::PassInfo::V2Info paraminfos2_##id[2+1]; \
  1024 	SourceHook::ProtoInfo protoinfo_##id = { 2, {0, 0, 0}, paraminfos_##id, \
  1025 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1026 	\
  1027 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1028 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1029 	
  1030 #define THGM_SETUP_PI2(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags) \
  1031 	void setuppi_##id() \
  1032 	{ \
  1033 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
  1034 		\
  1035 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  paraminfos_##id[2].size = sizeof(p2_type); paraminfos_##id[2].type = p2_passtype; paraminfos_##id[2].flags = p2_flags;  \
  1036 		\
  1037 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[2].pNormalCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL;  \
  1038 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[2].pCopyCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL;  \
  1039 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  paraminfos2_##id[2].pDtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL;  \
  1040 	}
  1041 	
  1042 
  1043 
  1044 #define THGM_MAKE_TEST3_void(id, param1, param2, param3) \
  1045 	struct TestClass##id; \
  1046 	typedef ParamState3<0, param1, param2, param3 > ParamState_m##id; \
  1047 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1048 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1049 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1050 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1051 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1052 	\
  1053 	struct TestClass##id \
  1054 	{ \
  1055 		static bool ms_DoRecall; \
  1056 		\
  1057 		virtual void Func(param1 p1, param2 p2, param3 p3) \
  1058 		{ \
  1059 			g_Inside_LeafFunc = true; \
  1060 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3))); \
  1061 			g_Inside_LeafFunc = false; \
  1062 		} \
  1063 		\
  1064 		struct Delegate1 : public MyDelegate \
  1065 		{ \
  1066 			virtual void Call(param1 p1, param2 p2, param3 p3) \
  1067 			{ \
  1068 				g_Inside_LeafFunc = true; \
  1069 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1070 				g_Inside_LeafFunc = false; \
  1071 				if (ms_DoRecall) \
  1072 				{ \
  1073 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1074 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3)); \
  1075 				} \
  1076 				else \
  1077 					RETURN_META(MRES_IGNORED); \
  1078 			} \
  1079 		}; \
  1080 		struct Delegate2 : public MyDelegate \
  1081 		{ \
  1082 			virtual void Call(param1 p1, param2 p2, param3 p3) \
  1083 			{ \
  1084 				g_Inside_LeafFunc = true; \
  1085 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1086 				g_Inside_LeafFunc = false; \
  1087 				if (ms_DoRecall) \
  1088 				{ \
  1089 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1090 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3)); \
  1091 				} \
  1092 				else \
  1093 					RETURN_META(MRES_SUPERCEDE); \
  1094 			} \
  1095 		}; \
  1096 		struct Delegate3 : public MyDelegate \
  1097 		{ \
  1098 			virtual void Call(param1 p1, param2 p2, param3 p3) \
  1099 			{ \
  1100 				g_Inside_LeafFunc = true; \
  1101 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1102 				g_Inside_LeafFunc = false; \
  1103 				if (ms_DoRecall) \
  1104 				{ \
  1105 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1106 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3)); \
  1107 				} \
  1108 				else \
  1109 					RETURN_META(MRES_IGNORED); \
  1110 			} \
  1111 		}; \
  1112 		struct Delegate4 : public MyDelegate \
  1113 		{ \
  1114 			virtual void Call(param1 p1, param2 p2, param3 p3) \
  1115 			{ \
  1116 				g_Inside_LeafFunc = true; \
  1117 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1118 				g_Inside_LeafFunc = false; \
  1119 				if (ms_DoRecall) \
  1120 				{ \
  1121 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1122 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3)); \
  1123 				} \
  1124 				else \
  1125 					RETURN_META(MRES_SUPERCEDE); \
  1126 			}; \
  1127 		}; \
  1128 	}; \
  1129 	\
  1130 	bool TestClass##id::ms_DoRecall = false; \
  1131 	\
  1132 	SourceHook::PassInfo paraminfos_##id[3+1]; \
  1133 	SourceHook::PassInfo::V2Info paraminfos2_##id[3+1]; \
  1134 	SourceHook::ProtoInfo protoinfo_##id = { 3, {0, 0, 0}, paraminfos_##id, \
  1135 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1136 	\
  1137 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1138 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1139 
  1140 
  1141 #define THGM_MAKE_TEST3(id, ret_type, param1, param2, param3) \
  1142 	struct TestClass##id; \
  1143 	typedef ParamState3<0, param1, param2, param3 > ParamState_m##id; \
  1144 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1145 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1146 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1147 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1148 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1149 	\
  1150 	struct TestClass##id \
  1151 	{ \
  1152 		static bool ms_DoRecall; \
  1153 		\
  1154 		virtual ret_type Func(param1 p1, param2 p2, param3 p3) \
  1155 		{ \
  1156 			g_Inside_LeafFunc = true; \
  1157 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3))); \
  1158 			g_Inside_LeafFunc = false; \
  1159 			\
  1160 			return MakeRet<ret_type>::Do(0); \
  1161 		} \
  1162 		\
  1163 		struct Delegate1 : public MyDelegate \
  1164 		{ \
  1165 			virtual ret_type Call(param1 p1, param2 p2, param3 p3) \
  1166 			{ \
  1167 				g_Inside_LeafFunc = true; \
  1168 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1169 				g_Inside_LeafFunc = false; \
  1170 				if (ms_DoRecall) \
  1171 				{ \
  1172 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1173 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1, p2, p3)); \
  1174 				} \
  1175 				else \
  1176 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
  1177 			} \
  1178 		}; \
  1179 		struct Delegate2 : public MyDelegate \
  1180 		{ \
  1181 			virtual ret_type Call(param1 p1, param2 p2, param3 p3) \
  1182 			{ \
  1183 				g_Inside_LeafFunc = true; \
  1184 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1185 				g_Inside_LeafFunc = false; \
  1186 				if (ms_DoRecall) \
  1187 				{ \
  1188 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1189 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1, p2, p3)); \
  1190 				} \
  1191 				else \
  1192 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
  1193 			} \
  1194 		}; \
  1195 		struct Delegate3 : public MyDelegate \
  1196 		{ \
  1197 			virtual ret_type Call(param1 p1, param2 p2, param3 p3) \
  1198 			{ \
  1199 				g_Inside_LeafFunc = true; \
  1200 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1201 				g_Inside_LeafFunc = false; \
  1202 				if (ms_DoRecall) \
  1203 				{ \
  1204 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1205 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1, p2, p3)); \
  1206 				} \
  1207 				else \
  1208 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
  1209 			} \
  1210 		}; \
  1211 		struct Delegate4 : public MyDelegate \
  1212 		{ \
  1213 			virtual ret_type Call(param1 p1, param2 p2, param3 p3) \
  1214 			{ \
  1215 				g_Inside_LeafFunc = true; \
  1216 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
  1217 				g_Inside_LeafFunc = false; \
  1218 				if (ms_DoRecall) \
  1219 				{ \
  1220 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
  1221 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1, p2, p3)); \
  1222 				} \
  1223 				else \
  1224 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
  1225 			}; \
  1226 		}; \
  1227 	}; \
  1228 	\
  1229 	bool TestClass##id::ms_DoRecall = false; \
  1230 	\
  1231 	SourceHook::PassInfo paraminfos_##id[3+1]; \
  1232 	SourceHook::PassInfo::V2Info paraminfos2_##id[3+1]; \
  1233 	SourceHook::ProtoInfo protoinfo_##id = { 3, {0, 0, 0}, paraminfos_##id, \
  1234 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1235 	\
  1236 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1237 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1238 	
  1239 #define THGM_SETUP_PI3(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags) \
  1240 	void setuppi_##id() \
  1241 	{ \
  1242 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
  1243 		\
  1244 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  paraminfos_##id[2].size = sizeof(p2_type); paraminfos_##id[2].type = p2_passtype; paraminfos_##id[2].flags = p2_flags;  paraminfos_##id[3].size = sizeof(p3_type); paraminfos_##id[3].type = p3_passtype; paraminfos_##id[3].flags = p3_flags;  \
  1245 		\
  1246 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[2].pNormalCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[3].pNormalCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL;  \
  1247 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[2].pCopyCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[3].pCopyCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL;  \
  1248 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  paraminfos2_##id[2].pDtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL;  paraminfos2_##id[3].pDtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL;  \
  1249 	}
  1250 	
  1251 
  1252 
  1253 #define THGM_MAKE_TEST4_void(id, param1, param2, param3, param4) \
  1254 	struct TestClass##id; \
  1255 	typedef ParamState4<0, param1, param2, param3, param4 > ParamState_m##id; \
  1256 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1257 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1258 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1259 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1260 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1261 	\
  1262 	struct TestClass##id \
  1263 	{ \
  1264 		static bool ms_DoRecall; \
  1265 		\
  1266 		virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4) \
  1267 		{ \
  1268 			g_Inside_LeafFunc = true; \
  1269 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4))); \
  1270 			g_Inside_LeafFunc = false; \
  1271 		} \
  1272 		\
  1273 		struct Delegate1 : public MyDelegate \
  1274 		{ \
  1275 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1276 			{ \
  1277 				g_Inside_LeafFunc = true; \
  1278 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1279 				g_Inside_LeafFunc = false; \
  1280 				if (ms_DoRecall) \
  1281 				{ \
  1282 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1283 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4)); \
  1284 				} \
  1285 				else \
  1286 					RETURN_META(MRES_IGNORED); \
  1287 			} \
  1288 		}; \
  1289 		struct Delegate2 : public MyDelegate \
  1290 		{ \
  1291 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1292 			{ \
  1293 				g_Inside_LeafFunc = true; \
  1294 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1295 				g_Inside_LeafFunc = false; \
  1296 				if (ms_DoRecall) \
  1297 				{ \
  1298 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1299 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4)); \
  1300 				} \
  1301 				else \
  1302 					RETURN_META(MRES_SUPERCEDE); \
  1303 			} \
  1304 		}; \
  1305 		struct Delegate3 : public MyDelegate \
  1306 		{ \
  1307 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1308 			{ \
  1309 				g_Inside_LeafFunc = true; \
  1310 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1311 				g_Inside_LeafFunc = false; \
  1312 				if (ms_DoRecall) \
  1313 				{ \
  1314 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1315 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4)); \
  1316 				} \
  1317 				else \
  1318 					RETURN_META(MRES_IGNORED); \
  1319 			} \
  1320 		}; \
  1321 		struct Delegate4 : public MyDelegate \
  1322 		{ \
  1323 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1324 			{ \
  1325 				g_Inside_LeafFunc = true; \
  1326 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1327 				g_Inside_LeafFunc = false; \
  1328 				if (ms_DoRecall) \
  1329 				{ \
  1330 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1331 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4)); \
  1332 				} \
  1333 				else \
  1334 					RETURN_META(MRES_SUPERCEDE); \
  1335 			}; \
  1336 		}; \
  1337 	}; \
  1338 	\
  1339 	bool TestClass##id::ms_DoRecall = false; \
  1340 	\
  1341 	SourceHook::PassInfo paraminfos_##id[4+1]; \
  1342 	SourceHook::PassInfo::V2Info paraminfos2_##id[4+1]; \
  1343 	SourceHook::ProtoInfo protoinfo_##id = { 4, {0, 0, 0}, paraminfos_##id, \
  1344 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1345 	\
  1346 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1347 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1348 
  1349 
  1350 #define THGM_MAKE_TEST4(id, ret_type, param1, param2, param3, param4) \
  1351 	struct TestClass##id; \
  1352 	typedef ParamState4<0, param1, param2, param3, param4 > ParamState_m##id; \
  1353 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1354 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1355 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1356 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1357 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1358 	\
  1359 	struct TestClass##id \
  1360 	{ \
  1361 		static bool ms_DoRecall; \
  1362 		\
  1363 		virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4) \
  1364 		{ \
  1365 			g_Inside_LeafFunc = true; \
  1366 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4))); \
  1367 			g_Inside_LeafFunc = false; \
  1368 			\
  1369 			return MakeRet<ret_type>::Do(0); \
  1370 		} \
  1371 		\
  1372 		struct Delegate1 : public MyDelegate \
  1373 		{ \
  1374 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1375 			{ \
  1376 				g_Inside_LeafFunc = true; \
  1377 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1378 				g_Inside_LeafFunc = false; \
  1379 				if (ms_DoRecall) \
  1380 				{ \
  1381 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1382 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1, p2, p3, p4)); \
  1383 				} \
  1384 				else \
  1385 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
  1386 			} \
  1387 		}; \
  1388 		struct Delegate2 : public MyDelegate \
  1389 		{ \
  1390 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1391 			{ \
  1392 				g_Inside_LeafFunc = true; \
  1393 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1394 				g_Inside_LeafFunc = false; \
  1395 				if (ms_DoRecall) \
  1396 				{ \
  1397 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1398 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1, p2, p3, p4)); \
  1399 				} \
  1400 				else \
  1401 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
  1402 			} \
  1403 		}; \
  1404 		struct Delegate3 : public MyDelegate \
  1405 		{ \
  1406 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1407 			{ \
  1408 				g_Inside_LeafFunc = true; \
  1409 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1410 				g_Inside_LeafFunc = false; \
  1411 				if (ms_DoRecall) \
  1412 				{ \
  1413 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1414 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1, p2, p3, p4)); \
  1415 				} \
  1416 				else \
  1417 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
  1418 			} \
  1419 		}; \
  1420 		struct Delegate4 : public MyDelegate \
  1421 		{ \
  1422 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4) \
  1423 			{ \
  1424 				g_Inside_LeafFunc = true; \
  1425 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
  1426 				g_Inside_LeafFunc = false; \
  1427 				if (ms_DoRecall) \
  1428 				{ \
  1429 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
  1430 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1, p2, p3, p4)); \
  1431 				} \
  1432 				else \
  1433 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
  1434 			}; \
  1435 		}; \
  1436 	}; \
  1437 	\
  1438 	bool TestClass##id::ms_DoRecall = false; \
  1439 	\
  1440 	SourceHook::PassInfo paraminfos_##id[4+1]; \
  1441 	SourceHook::PassInfo::V2Info paraminfos2_##id[4+1]; \
  1442 	SourceHook::ProtoInfo protoinfo_##id = { 4, {0, 0, 0}, paraminfos_##id, \
  1443 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1444 	\
  1445 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1446 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1447 	
  1448 #define THGM_SETUP_PI4(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags) \
  1449 	void setuppi_##id() \
  1450 	{ \
  1451 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
  1452 		\
  1453 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  paraminfos_##id[2].size = sizeof(p2_type); paraminfos_##id[2].type = p2_passtype; paraminfos_##id[2].flags = p2_flags;  paraminfos_##id[3].size = sizeof(p3_type); paraminfos_##id[3].type = p3_passtype; paraminfos_##id[3].flags = p3_flags;  paraminfos_##id[4].size = sizeof(p4_type); paraminfos_##id[4].type = p4_passtype; paraminfos_##id[4].flags = p4_flags;  \
  1454 		\
  1455 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[2].pNormalCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[3].pNormalCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[4].pNormalCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL;  \
  1456 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[2].pCopyCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[3].pCopyCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[4].pCopyCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL;  \
  1457 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  paraminfos2_##id[2].pDtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL;  paraminfos2_##id[3].pDtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL;  paraminfos2_##id[4].pDtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL;  \
  1458 	}
  1459 	
  1460 
  1461 
  1462 #define THGM_MAKE_TEST5_void(id, param1, param2, param3, param4, param5) \
  1463 	struct TestClass##id; \
  1464 	typedef ParamState5<0, param1, param2, param3, param4, param5 > ParamState_m##id; \
  1465 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1466 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1467 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1468 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1469 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1470 	\
  1471 	struct TestClass##id \
  1472 	{ \
  1473 		static bool ms_DoRecall; \
  1474 		\
  1475 		virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1476 		{ \
  1477 			g_Inside_LeafFunc = true; \
  1478 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5))); \
  1479 			g_Inside_LeafFunc = false; \
  1480 		} \
  1481 		\
  1482 		struct Delegate1 : public MyDelegate \
  1483 		{ \
  1484 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1485 			{ \
  1486 				g_Inside_LeafFunc = true; \
  1487 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1488 				g_Inside_LeafFunc = false; \
  1489 				if (ms_DoRecall) \
  1490 				{ \
  1491 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1492 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1493 				} \
  1494 				else \
  1495 					RETURN_META(MRES_IGNORED); \
  1496 			} \
  1497 		}; \
  1498 		struct Delegate2 : public MyDelegate \
  1499 		{ \
  1500 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1501 			{ \
  1502 				g_Inside_LeafFunc = true; \
  1503 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1504 				g_Inside_LeafFunc = false; \
  1505 				if (ms_DoRecall) \
  1506 				{ \
  1507 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1508 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1509 				} \
  1510 				else \
  1511 					RETURN_META(MRES_SUPERCEDE); \
  1512 			} \
  1513 		}; \
  1514 		struct Delegate3 : public MyDelegate \
  1515 		{ \
  1516 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1517 			{ \
  1518 				g_Inside_LeafFunc = true; \
  1519 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1520 				g_Inside_LeafFunc = false; \
  1521 				if (ms_DoRecall) \
  1522 				{ \
  1523 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1524 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1525 				} \
  1526 				else \
  1527 					RETURN_META(MRES_IGNORED); \
  1528 			} \
  1529 		}; \
  1530 		struct Delegate4 : public MyDelegate \
  1531 		{ \
  1532 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1533 			{ \
  1534 				g_Inside_LeafFunc = true; \
  1535 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1536 				g_Inside_LeafFunc = false; \
  1537 				if (ms_DoRecall) \
  1538 				{ \
  1539 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1540 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1541 				} \
  1542 				else \
  1543 					RETURN_META(MRES_SUPERCEDE); \
  1544 			}; \
  1545 		}; \
  1546 	}; \
  1547 	\
  1548 	bool TestClass##id::ms_DoRecall = false; \
  1549 	\
  1550 	SourceHook::PassInfo paraminfos_##id[5+1]; \
  1551 	SourceHook::PassInfo::V2Info paraminfos2_##id[5+1]; \
  1552 	SourceHook::ProtoInfo protoinfo_##id = { 5, {0, 0, 0}, paraminfos_##id, \
  1553 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1554 	\
  1555 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1556 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1557 
  1558 
  1559 #define THGM_MAKE_TEST5(id, ret_type, param1, param2, param3, param4, param5) \
  1560 	struct TestClass##id; \
  1561 	typedef ParamState5<0, param1, param2, param3, param4, param5 > ParamState_m##id; \
  1562 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1563 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1564 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1565 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1566 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1567 	\
  1568 	struct TestClass##id \
  1569 	{ \
  1570 		static bool ms_DoRecall; \
  1571 		\
  1572 		virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1573 		{ \
  1574 			g_Inside_LeafFunc = true; \
  1575 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5))); \
  1576 			g_Inside_LeafFunc = false; \
  1577 			\
  1578 			return MakeRet<ret_type>::Do(0); \
  1579 		} \
  1580 		\
  1581 		struct Delegate1 : public MyDelegate \
  1582 		{ \
  1583 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1584 			{ \
  1585 				g_Inside_LeafFunc = true; \
  1586 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1587 				g_Inside_LeafFunc = false; \
  1588 				if (ms_DoRecall) \
  1589 				{ \
  1590 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1591 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1592 				} \
  1593 				else \
  1594 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
  1595 			} \
  1596 		}; \
  1597 		struct Delegate2 : public MyDelegate \
  1598 		{ \
  1599 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1600 			{ \
  1601 				g_Inside_LeafFunc = true; \
  1602 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1603 				g_Inside_LeafFunc = false; \
  1604 				if (ms_DoRecall) \
  1605 				{ \
  1606 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1607 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1608 				} \
  1609 				else \
  1610 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
  1611 			} \
  1612 		}; \
  1613 		struct Delegate3 : public MyDelegate \
  1614 		{ \
  1615 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1616 			{ \
  1617 				g_Inside_LeafFunc = true; \
  1618 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1619 				g_Inside_LeafFunc = false; \
  1620 				if (ms_DoRecall) \
  1621 				{ \
  1622 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1623 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1624 				} \
  1625 				else \
  1626 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
  1627 			} \
  1628 		}; \
  1629 		struct Delegate4 : public MyDelegate \
  1630 		{ \
  1631 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
  1632 			{ \
  1633 				g_Inside_LeafFunc = true; \
  1634 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
  1635 				g_Inside_LeafFunc = false; \
  1636 				if (ms_DoRecall) \
  1637 				{ \
  1638 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
  1639 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
  1640 				} \
  1641 				else \
  1642 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
  1643 			}; \
  1644 		}; \
  1645 	}; \
  1646 	\
  1647 	bool TestClass##id::ms_DoRecall = false; \
  1648 	\
  1649 	SourceHook::PassInfo paraminfos_##id[5+1]; \
  1650 	SourceHook::PassInfo::V2Info paraminfos2_##id[5+1]; \
  1651 	SourceHook::ProtoInfo protoinfo_##id = { 5, {0, 0, 0}, paraminfos_##id, \
  1652 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1653 	\
  1654 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1655 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1656 	
  1657 #define THGM_SETUP_PI5(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags) \
  1658 	void setuppi_##id() \
  1659 	{ \
  1660 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
  1661 		\
  1662 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  paraminfos_##id[2].size = sizeof(p2_type); paraminfos_##id[2].type = p2_passtype; paraminfos_##id[2].flags = p2_flags;  paraminfos_##id[3].size = sizeof(p3_type); paraminfos_##id[3].type = p3_passtype; paraminfos_##id[3].flags = p3_flags;  paraminfos_##id[4].size = sizeof(p4_type); paraminfos_##id[4].type = p4_passtype; paraminfos_##id[4].flags = p4_flags;  paraminfos_##id[5].size = sizeof(p5_type); paraminfos_##id[5].type = p5_passtype; paraminfos_##id[5].flags = p5_flags;  \
  1663 		\
  1664 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[2].pNormalCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[3].pNormalCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[4].pNormalCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[5].pNormalCtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::NormalConstructor) : NULL;  \
  1665 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[2].pCopyCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[3].pCopyCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[4].pCopyCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[5].pCopyCtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::CopyConstructor) : NULL;  \
  1666 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  paraminfos2_##id[2].pDtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL;  paraminfos2_##id[3].pDtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL;  paraminfos2_##id[4].pDtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL;  paraminfos2_##id[5].pDtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::Destructor) : NULL;  \
  1667 	}
  1668 	
  1669 
  1670 
  1671 #define THGM_MAKE_TEST6_void(id, param1, param2, param3, param4, param5, param6) \
  1672 	struct TestClass##id; \
  1673 	typedef ParamState6<0, param1, param2, param3, param4, param5, param6 > ParamState_m##id; \
  1674 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1675 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1676 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1677 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1678 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1679 	\
  1680 	struct TestClass##id \
  1681 	{ \
  1682 		static bool ms_DoRecall; \
  1683 		\
  1684 		virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1685 		{ \
  1686 			g_Inside_LeafFunc = true; \
  1687 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1688 			g_Inside_LeafFunc = false; \
  1689 		} \
  1690 		\
  1691 		struct Delegate1 : public MyDelegate \
  1692 		{ \
  1693 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1694 			{ \
  1695 				g_Inside_LeafFunc = true; \
  1696 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1697 				g_Inside_LeafFunc = false; \
  1698 				if (ms_DoRecall) \
  1699 				{ \
  1700 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1701 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1702 				} \
  1703 				else \
  1704 					RETURN_META(MRES_IGNORED); \
  1705 			} \
  1706 		}; \
  1707 		struct Delegate2 : public MyDelegate \
  1708 		{ \
  1709 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1710 			{ \
  1711 				g_Inside_LeafFunc = true; \
  1712 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1713 				g_Inside_LeafFunc = false; \
  1714 				if (ms_DoRecall) \
  1715 				{ \
  1716 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1717 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1718 				} \
  1719 				else \
  1720 					RETURN_META(MRES_SUPERCEDE); \
  1721 			} \
  1722 		}; \
  1723 		struct Delegate3 : public MyDelegate \
  1724 		{ \
  1725 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1726 			{ \
  1727 				g_Inside_LeafFunc = true; \
  1728 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1729 				g_Inside_LeafFunc = false; \
  1730 				if (ms_DoRecall) \
  1731 				{ \
  1732 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1733 					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1734 				} \
  1735 				else \
  1736 					RETURN_META(MRES_IGNORED); \
  1737 			} \
  1738 		}; \
  1739 		struct Delegate4 : public MyDelegate \
  1740 		{ \
  1741 			virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1742 			{ \
  1743 				g_Inside_LeafFunc = true; \
  1744 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1745 				g_Inside_LeafFunc = false; \
  1746 				if (ms_DoRecall) \
  1747 				{ \
  1748 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1749 					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1750 				} \
  1751 				else \
  1752 					RETURN_META(MRES_SUPERCEDE); \
  1753 			}; \
  1754 		}; \
  1755 	}; \
  1756 	\
  1757 	bool TestClass##id::ms_DoRecall = false; \
  1758 	\
  1759 	SourceHook::PassInfo paraminfos_##id[6+1]; \
  1760 	SourceHook::PassInfo::V2Info paraminfos2_##id[6+1]; \
  1761 	SourceHook::ProtoInfo protoinfo_##id = { 6, {0, 0, 0}, paraminfos_##id, \
  1762 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1763 	\
  1764 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1765 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1766 
  1767 
  1768 #define THGM_MAKE_TEST6(id, ret_type, param1, param2, param3, param4, param5, param6) \
  1769 	struct TestClass##id; \
  1770 	typedef ParamState6<0, param1, param2, param3, param4, param5, param6 > ParamState_m##id; \
  1771 	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
  1772 	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1773 	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1774 	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1775 	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
  1776 	\
  1777 	struct TestClass##id \
  1778 	{ \
  1779 		static bool ms_DoRecall; \
  1780 		\
  1781 		virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1782 		{ \
  1783 			g_Inside_LeafFunc = true; \
  1784 			ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1785 			g_Inside_LeafFunc = false; \
  1786 			\
  1787 			return MakeRet<ret_type>::Do(0); \
  1788 		} \
  1789 		\
  1790 		struct Delegate1 : public MyDelegate \
  1791 		{ \
  1792 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1793 			{ \
  1794 				g_Inside_LeafFunc = true; \
  1795 				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1796 				g_Inside_LeafFunc = false; \
  1797 				if (ms_DoRecall) \
  1798 				{ \
  1799 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1800 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(1), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1801 				} \
  1802 				else \
  1803 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(1)); \
  1804 			} \
  1805 		}; \
  1806 		struct Delegate2 : public MyDelegate \
  1807 		{ \
  1808 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1809 			{ \
  1810 				g_Inside_LeafFunc = true; \
  1811 				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1812 				g_Inside_LeafFunc = false; \
  1813 				if (ms_DoRecall) \
  1814 				{ \
  1815 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1816 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1817 				} \
  1818 				else \
  1819 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(2)); \
  1820 			} \
  1821 		}; \
  1822 		struct Delegate3 : public MyDelegate \
  1823 		{ \
  1824 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1825 			{ \
  1826 				g_Inside_LeafFunc = true; \
  1827 				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1828 				g_Inside_LeafFunc = false; \
  1829 				if (ms_DoRecall) \
  1830 				{ \
  1831 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1832 					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, MakeRet<ret_type>::Do(3), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1833 				} \
  1834 				else \
  1835 					RETURN_META_VALUE(MRES_IGNORED, MakeRet<ret_type>::Do(3)); \
  1836 			} \
  1837 		}; \
  1838 		struct Delegate4 : public MyDelegate \
  1839 		{ \
  1840 			virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
  1841 			{ \
  1842 				g_Inside_LeafFunc = true; \
  1843 				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
  1844 				g_Inside_LeafFunc = false; \
  1845 				if (ms_DoRecall) \
  1846 				{ \
  1847 					Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
  1848 					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
  1849 				} \
  1850 				else \
  1851 					RETURN_META_VALUE(MRES_SUPERCEDE, MakeRet<ret_type>::Do(4)); \
  1852 			}; \
  1853 		}; \
  1854 	}; \
  1855 	\
  1856 	bool TestClass##id::ms_DoRecall = false; \
  1857 	\
  1858 	SourceHook::PassInfo paraminfos_##id[6+1]; \
  1859 	SourceHook::PassInfo::V2Info paraminfos2_##id[6+1]; \
  1860 	SourceHook::ProtoInfo protoinfo_##id = { 6, {0, 0, 0}, paraminfos_##id, \
  1861 		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
  1862 	\
  1863 	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
  1864 	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
  1865 	
  1866 #define THGM_SETUP_PI6(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags, p6_type, p6_passtype, p6_flags) \
  1867 	void setuppi_##id() \
  1868 	{ \
  1869 		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
  1870 		\
  1871 		 paraminfos_##id[1].size = sizeof(p1_type); paraminfos_##id[1].type = p1_passtype; paraminfos_##id[1].flags = p1_flags;  paraminfos_##id[2].size = sizeof(p2_type); paraminfos_##id[2].type = p2_passtype; paraminfos_##id[2].flags = p2_flags;  paraminfos_##id[3].size = sizeof(p3_type); paraminfos_##id[3].type = p3_passtype; paraminfos_##id[3].flags = p3_flags;  paraminfos_##id[4].size = sizeof(p4_type); paraminfos_##id[4].type = p4_passtype; paraminfos_##id[4].flags = p4_flags;  paraminfos_##id[5].size = sizeof(p5_type); paraminfos_##id[5].type = p5_passtype; paraminfos_##id[5].flags = p5_flags;  paraminfos_##id[6].size = sizeof(p6_type); paraminfos_##id[6].type = p6_passtype; paraminfos_##id[6].flags = p6_flags;  \
  1872 		\
  1873 		 paraminfos2_##id[1].pNormalCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[2].pNormalCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[3].pNormalCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[4].pNormalCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[5].pNormalCtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::NormalConstructor) : NULL;  paraminfos2_##id[6].pNormalCtor = (paraminfos_##id[6].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::NormalConstructor) : NULL;  \
  1874 		 paraminfos2_##id[1].pCopyCtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[2].pCopyCtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[3].pCopyCtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[4].pCopyCtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[5].pCopyCtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::CopyConstructor) : NULL;  paraminfos2_##id[6].pCopyCtor = (paraminfos_##id[6].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::CopyConstructor) : NULL;  \
  1875 		 paraminfos2_##id[1].pDtor = (paraminfos_##id[1].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL;  paraminfos2_##id[2].pDtor = (paraminfos_##id[2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL;  paraminfos2_##id[3].pDtor = (paraminfos_##id[3].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL;  paraminfos2_##id[4].pDtor = (paraminfos_##id[4].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL;  paraminfos2_##id[5].pDtor = (paraminfos_##id[5].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::Destructor) : NULL;  paraminfos2_##id[6].pDtor = (paraminfos_##id[6].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::Destructor) : NULL;  \
  1876 	}
  1877 	
  1878 
  1879 
  1880 #define THGM_SETUP_RI(id, ret_type, ret_passtype, ret_flags) \
  1881 	void setupri_##id() \
  1882 	{ \
  1883 		protoinfo_##id.retPassInfo.size = sizeof(ret_type); \
  1884 		protoinfo_##id.retPassInfo.type = ret_passtype; \
  1885 		protoinfo_##id.retPassInfo.flags = ret_flags; \
  1886 		\
  1887 		protoinfo_##id.retPassInfo2.pNormalCtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::NormalConstructor) : NULL; \
  1888 		protoinfo_##id.retPassInfo2.pCopyCtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::CopyConstructor) : NULL; \
  1889 		protoinfo_##id.retPassInfo2.pDtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::Destructor) : NULL; \
  1890 	}
  1891 	
  1892 #define THGM_ADD_HOOK(id, num) \
  1893 	CAT4(hook, num, _, id) = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pTest##id), \
  1894 		0, myhookman##id, PtrBufPtr(new TestClass##id::Delegate##num), num >= 3);
  1895 
  1896 #define THGM_REMOVE_HOOK(id, num) \
  1897 	g_SHPtr->RemoveHookByID(CAT4(hook, num, _, id));
  1898 
  1899 #define THGM_CALLS_void(id, call_params) \
  1900 	pTest##id->Func call_params; \
  1901 	SH_CALL(pTest##id, &TestClass##id::Func) call_params;
  1902 
  1903 #define THGM_DO_TEST_void(id, call_params) \
  1904 	setuppi_##id(); \
  1905 	g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
  1906 	g_Genc_ad##id.set(g_Genc##id); \
  1907 	SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
  1908 	int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
  1909 	\
  1910 	TestClass##id::ms_DoRecall = false; \
  1911 	TestClass##id *pTest##id = new TestClass##id; \
  1912 	CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
  1913 	\
  1914 			/* no hooks - no hooks */ \
  1915 	PtrBuf_Clear(); \
  1916 	THGM_CALLS_void(id, call_params); \
  1917 	CHECK_STATES((&g_States, \
  1918 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1919 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1920 		NULL), "Test" #id " Part1"); \
  1921 	\
  1922 			/* hook1 - no hooks */ \
  1923 	PtrBuf_Clear(); \
  1924 	THGM_ADD_HOOK(id, 1); \
  1925 	THGM_CALLS_void(id, call_params); \
  1926 	CHECK_STATES((&g_States, \
  1927 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  1928 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1929 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1930 		NULL), "Test" #id " Part2"); \
  1931 	THGM_REMOVE_HOOK(id, 1); \
  1932 	\
  1933 			/* no hooks - hook3 */ \
  1934 	PtrBuf_Clear(); \
  1935 	THGM_ADD_HOOK(id, 3); \
  1936 	THGM_CALLS_void(id, call_params); \
  1937 	CHECK_STATES((&g_States, \
  1938 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1939 		new State_Deleg3_##id(pTest##id, 0, ParamState_m##id call_params), \
  1940 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1941 		NULL), "Test" #id " Part3"); \
  1942 	THGM_REMOVE_HOOK(id, 3); \
  1943 	\
  1944 			/* hook1 - hook3 */ \
  1945 	PtrBuf_Clear(); \
  1946 	THGM_ADD_HOOK(id, 1); \
  1947 	THGM_ADD_HOOK(id, 3); \
  1948 	THGM_CALLS_void(id, call_params); \
  1949 	CHECK_STATES((&g_States, \
  1950 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  1951 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1952 		new State_Deleg3_##id(pTest##id, 1, ParamState_m##id call_params), \
  1953 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1954 		NULL), "Test" #id " Part4"); \
  1955 	THGM_REMOVE_HOOK(id, 1); \
  1956 	THGM_REMOVE_HOOK(id, 3); \
  1957 	\
  1958 			/* hook1, hook2 - hook3 */ \
  1959 	PtrBuf_Clear(); \
  1960 	THGM_ADD_HOOK(id, 1); \
  1961 	THGM_ADD_HOOK(id, 2); \
  1962 	THGM_ADD_HOOK(id, 3); \
  1963 	THGM_CALLS_void(id, call_params); \
  1964 	CHECK_STATES((&g_States, \
  1965 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  1966 		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
  1967 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
  1968 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1969 		NULL), "Test" #id " Part5"); \
  1970 	THGM_REMOVE_HOOK(id, 1); \
  1971 	THGM_REMOVE_HOOK(id, 2); \
  1972 	THGM_REMOVE_HOOK(id, 3); \
  1973 			/* hook1, hook2 - hook3, hook4 */ \
  1974 	PtrBuf_Clear(); \
  1975 	THGM_ADD_HOOK(id, 1); \
  1976 	THGM_ADD_HOOK(id, 2); \
  1977 	THGM_ADD_HOOK(id, 3); \
  1978 	THGM_ADD_HOOK(id, 4); \
  1979 	THGM_CALLS_void(id, call_params); \
  1980 	CHECK_STATES((&g_States, \
  1981 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  1982 		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
  1983 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
  1984 		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params), \
  1985 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  1986 		NULL), "Test" #id " Part6"); \
  1987 		\
  1988 			/* hook1 - hook3, hook4, with recalls! */ \
  1989 		\
  1990 	TestClass##id::ms_DoRecall = true; \
  1991 	THGM_REMOVE_HOOK(id, 2); \
  1992 	THGM_CALLS_void(id, call_params); \
  1993 	CHECK_STATES((&g_States, \
  1994 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params(0)), \
  1995 		new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
  1996 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params(1)), \
  1997 		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params(2)), \
  1998 		/* sh_call one */ \
  1999 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2000 		NULL), "Test" #id " Part7"); \
  2001 	THGM_REMOVE_HOOK(id, 1); \
  2002 	THGM_REMOVE_HOOK(id, 3); \
  2003 	THGM_REMOVE_HOOK(id, 4);
  2004 
  2005 
  2006 #define THGM_CALLS(id, call_params, exp_ret_norm, exp_ret_shcall, err) \
  2007 	CHECK_COND(pTest##id->Func call_params == exp_ret_norm, err " /retcallnorm"); \
  2008 	CHECK_COND(SH_CALL(pTest##id, &TestClass##id::Func) call_params == exp_ret_shcall, err " /retcallshcall");
  2009 
  2010 #define THGM_DO_TEST(id, call_params) \
  2011 	setuppi_##id(); \
  2012 	setupri_##id(); \
  2013 	g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
  2014 	g_Genc_ad##id.set(g_Genc##id); \
  2015 	SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
  2016 	int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
  2017 	\
  2018 	TestClass##id::ms_DoRecall = false; \
  2019 	TestClass##id *pTest##id = new TestClass##id; \
  2020 	CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
  2021 	\
  2022 			/* no hooks - no hooks */ \
  2023 	PtrBuf_Clear(); \
  2024 	THGM_CALLS(id, call_params, 0, 0, "Part1"); \
  2025 	CHECK_STATES((&g_States, \
  2026 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2027 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2028 		NULL), "Test" #id " Part1"); \
  2029 	\
  2030 			/* hook1 - no hooks */ \
  2031 	PtrBuf_Clear(); \
  2032 	THGM_ADD_HOOK(id, 1); \
  2033 	THGM_CALLS(id, call_params, 0, 0, "Part2"); \
  2034 	CHECK_STATES((&g_States, \
  2035 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  2036 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2037 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2038 		NULL), "Test" #id " Part2"); \
  2039 	THGM_REMOVE_HOOK(id, 1); \
  2040 	\
  2041 			/* no hooks - hook3 */ \
  2042 	PtrBuf_Clear(); \
  2043 	THGM_ADD_HOOK(id, 3); \
  2044 	THGM_CALLS(id, call_params, 0, 0, "Part3"); \
  2045 	CHECK_STATES((&g_States, \
  2046 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2047 		new State_Deleg3_##id(pTest##id, 0, ParamState_m##id call_params), \
  2048 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2049 		NULL), "Test" #id " Part3"); \
  2050 	THGM_REMOVE_HOOK(id, 3); \
  2051 	\
  2052 			/* hook1 - hook3 */ \
  2053 	PtrBuf_Clear(); \
  2054 	THGM_ADD_HOOK(id, 1); \
  2055 	THGM_ADD_HOOK(id, 3); \
  2056 	THGM_CALLS(id, call_params, 0, 0, "Part4"); \
  2057 	CHECK_STATES((&g_States, \
  2058 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  2059 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2060 		new State_Deleg3_##id(pTest##id, 1, ParamState_m##id call_params), \
  2061 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2062 		NULL), "Test" #id " Part4"); \
  2063 	THGM_REMOVE_HOOK(id, 1); \
  2064 	THGM_REMOVE_HOOK(id, 3); \
  2065 	\
  2066 			/* hook1, hook2 - hook3 */ \
  2067 	PtrBuf_Clear(); \
  2068 	THGM_ADD_HOOK(id, 1); \
  2069 	THGM_ADD_HOOK(id, 2); \
  2070 	THGM_ADD_HOOK(id, 3); \
  2071 	THGM_CALLS(id, call_params, 2, 0, "Part5"); \
  2072 	CHECK_STATES((&g_States, \
  2073 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  2074 		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
  2075 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
  2076 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2077 		NULL), "Test" #id " Part5"); \
  2078 	THGM_REMOVE_HOOK(id, 1); \
  2079 	THGM_REMOVE_HOOK(id, 2); \
  2080 	THGM_REMOVE_HOOK(id, 3); \
  2081 			/* hook1, hook2 - hook3, hook4 */ \
  2082 	PtrBuf_Clear(); \
  2083 	THGM_ADD_HOOK(id, 1); \
  2084 	THGM_ADD_HOOK(id, 2); \
  2085 	THGM_ADD_HOOK(id, 3); \
  2086 	THGM_ADD_HOOK(id, 4); \
  2087 	THGM_CALLS(id, call_params, 4, 0, "Part6"); \
  2088 	CHECK_STATES((&g_States, \
  2089 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
  2090 		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
  2091 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
  2092 		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params), \
  2093 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2094 		NULL), "Test" #id " Part6"); \
  2095 		\
  2096 			/* hook1 - hook3, hook4, with recalls! */ \
  2097 		\
  2098 	TestClass##id::ms_DoRecall = true; \
  2099 	THGM_REMOVE_HOOK(id, 2); \
  2100 	THGM_CALLS(id, call_params, 4, 0, "Part7"); \
  2101 	CHECK_STATES((&g_States, \
  2102 		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params(0)), \
  2103 		new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
  2104 		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params(1)), \
  2105 		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params(2)), \
  2106 		/* sh_call one */ \
  2107 		new State_Func##id(pTest##id, ParamState_m##id call_params), \
  2108 		NULL), "Test" #id " Part7"); \
  2109 	THGM_REMOVE_HOOK(id, 1); \
  2110 	THGM_REMOVE_HOOK(id, 3); \
  2111 	THGM_REMOVE_HOOK(id, 4);