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