Trigger build for hl2sdk-l4d changes.
1 struct CAutoReleaseHookMan
3 SourceHook::HookManagerPubFunc m_Ptr;
4 CAutoReleaseHookMan(SourceHook::HookManagerPubFunc ptr) : m_Ptr(ptr)
9 g_HMAGPtr->ReleaseHookMan(m_Ptr);
14 template <class T> struct StripRef
19 template <class T> struct StripRef<T&>
24 // Address of constructor/destructor
30 void NormalConstructor()
35 void CopyConstructor(const T &other)
42 reinterpret_cast<T*>(this)->~T();
45 const T& AssignOp(const T &other)
47 return (*reinterpret_cast<T*>(this) = other);
53 void *FindFuncAddr(T mfp)
65 template <class T> struct MyRefCarrier
70 template <class T> struct MyRefCarrier<T&>
76 type() : m_StoredRef(NULL)
79 type(T& ref) : m_StoredRef(&ref)
94 bool operator== (const typename MyRefCarrier<T&>::type &other)
96 return m_StoredRef == other.m_StoredRef;
99 friend std::ostream& operator <<(std::ostream &os,const typename MyRefCarrier<T&>::type &obj)
101 os << *obj.m_StoredRef;
107 #if SH_COMP==SH_COMP_GCC
108 #define NO_OPTIMIZE __attribute__((noinline))
113 // Return value maker
124 struct MakeRet< POD<SIZE> >
126 static POD<SIZE> Do(int a)
129 memset(reinterpret_cast<void*>(x.x), a, SIZE);
134 // Stores parameter status
136 bool EqualToMyFmtString(T sth)
141 bool EqualToMyFmtString(std::string &sth)
143 if (sth == "Hello %s%d%s")
151 template<int dummy@[$2,1,$1:, class p$2@]>
154 @[$2,1,$1:typename MyRefCarrier<p$2>::type m_$2; @]
156 bool operator==(const ParamState$1<dummy@[$2,1,$1:, p$2@]> &other)
159 @[$2,1,$1: && m_$1 == other.m_$1@]
162 ParamState$1(@[$2,1,$1:p$2 a$2, @]...) @[$1!=0::@] @[$2,1,$1|, :m_$2(a$2)@]
165 EqualToMyFmtString(m_$2);
169 ParamState$1<dummy@[$2,1,$1:, p$2@]> & operator() (int incrsteps)
173 for (i = 0; i < incrsteps; ++i)
174 Increment<typename StripRef< p$2 >::type >::Incr(m_$2);
181 @[$1!=0:template<@[$2,1,$1|, :class p$2@]>@]
182 std::ostream& operator <<(std::ostream &os,const ParamState$1<0@[$2,1,$1:, p$2@]> &obj)
184 @[$1!=0:os@] @[$2,1,$1:<< obj.m_$2@];
190 #define CAT2(a, b) a##b
191 #define CAT3(a, b, c) a##b##c
192 #define CAT4(a, b, c, d) a##b##c##d
195 // hook2: pre supercede
196 // hook3: post ignore
197 // hook4: post supercede
202 #define THGM_MAKE_TEST$1_void(id@[$2,1,$1:, param$2@]) \
203 struct TestClass##id; \
204 typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
205 MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
206 MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
208 struct TestClass##id \
210 static bool ms_DoRecall; \
212 virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
214 g_Inside_LeafFunc = true; \
215 ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
216 g_Inside_LeafFunc = false; \
219 struct Delegate : public MyDelegate \
222 Delegate(int num) : m_DelegNumber(num) { } \
224 virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
226 g_Inside_LeafFunc = true; \
227 ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
228 g_Inside_LeafFunc = false; \
231 @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
232 RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
235 RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
240 bool TestClass##id::ms_DoRecall = false; \
241 SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
244 #define THGM_MAKE_TEST$1(id, ret_type@[$2,1,$1:, param$2@]) \
245 struct TestClass##id; \
246 typedef ret_type RetType##id; \
247 typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
248 MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
249 MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
251 struct TestClass##id \
253 static bool ms_DoRecall; \
255 virtual ret_type Func(@[$2,1,$1|, :param$2 p$2@]) \
257 g_Inside_LeafFunc = true; \
258 ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
259 g_Inside_LeafFunc = false; \
261 return MakeRet< ret_type >::Do(0); \
264 struct Delegate : public MyDelegate \
267 Delegate(int num) : m_DelegNumber(num) { } \
269 virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
271 g_Inside_LeafFunc = true; \
272 ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
273 g_Inside_LeafFunc = false; \
276 @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
277 RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
280 RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
285 bool TestClass##id::ms_DoRecall = false; \
286 SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
288 #define THGM_MAKE_TEST$1_vafmt_void(id@[$2,1,$1:, param$2@]) \
289 struct TestClass##id; \
290 typedef ParamState@($1+1)<0@[$2,1,$1:, param$2@], std::string > ParamState_m##id; \
291 MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
292 MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
294 struct TestClass##id \
296 static bool ms_DoRecall; \
298 virtual void Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
300 g_Inside_LeafFunc = true; \
305 vsnprintf(buf, 9998, fmt, ap); \
309 ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1:p$2, @]std::string(buf)))); \
310 g_Inside_LeafFunc = false; \
313 struct Delegate : public MyDelegate \
316 Delegate(int num) : m_DelegNumber(num) { } \
318 virtual void Call(@[$2,1,$1:param$2 p$2, @]const char *buf) \
320 g_Inside_LeafFunc = true; \
321 ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1:p$2, @]buf))); \
322 g_Inside_LeafFunc = false; \
325 @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
326 RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1:p$2, @]"%s!", buf)); \
329 RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
334 bool TestClass##id::ms_DoRecall = false; \
335 SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
337 #define THGM_MAKE_TEST$1_vafmt(id, ret_type@[$2,1,$1:, param$2@]) \
338 struct TestClass##id; \
339 typedef ret_type RetType##id; \
340 typedef ParamState@($1+1)<0@[$2,1,$1:, param$2@], std::string > ParamState_m##id; \
341 MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
342 MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
344 struct TestClass##id \
346 static bool ms_DoRecall; \
348 virtual ret_type Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
350 g_Inside_LeafFunc = true; \
355 vsnprintf(buf, 9998, fmt, ap); \
359 ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1:p$2, @]std::string(buf)))); \
361 return MakeRet< ret_type >::Do(0); \
364 struct Delegate : public MyDelegate \
367 Delegate(int num) : m_DelegNumber(num) { } \
369 virtual ret_type Call(@[$2,1,$1:param$2 p$2, @]const char *buf) \
371 g_Inside_LeafFunc = true; \
372 ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1:p$2, @]buf))); \
373 g_Inside_LeafFunc = false; \
376 @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
377 RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (@[$2,1,$1:p$2, @]"%s!", buf)); \
380 RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
385 bool TestClass##id::ms_DoRecall = false; \
386 SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
388 #define THGM_SETUP_PI$1(id@[$2,1,$1:, p$2_type, p$2_passtype, p$2_flags@]) \
389 void setuppi_##id() \
392 protoinfo_##id.AddParam(sizeof(p$2_type), p$2_passtype, p$2_flags, \
393 (p$2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::NormalConstructor) : NULL, \
394 (p$2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::CopyConstructor) : NULL, \
395 (p$2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::Destructor) : NULL, \
396 (p$2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::AssignOp) : NULL \
403 #define THGM_SETUP_RI(id, ret_type, ret_passtype, ret_flags) \
404 void setupri_##id() \
406 protoinfo_##id.SetReturnType(sizeof(ret_type), ret_passtype, ret_flags, \
407 (ret_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::NormalConstructor) : NULL, \
408 (ret_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::CopyConstructor) : NULL, \
409 (ret_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::Destructor) : NULL, \
410 (ret_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::AssignOp) : NULL \
414 #define THGM_ADD_HOOK(id, num) \
415 CAT4(hook, num, _, id) = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pTest##id), \
416 0, myhookman##id, PtrBufPtr(new TestClass##id::Delegate(num)), num >= 3);
418 #define THGM_REMOVE_HOOK(id, num) \
419 g_SHPtr->RemoveHookByID(CAT4(hook, num, _, id));
421 #define THGM_CALLS_void(id, call_params) \
422 pTest##id->Func call_params; \
423 SH_CALL(pTest##id, &TestClass##id::Func) call_params;
425 #define THGM_DO_TEST_void(id, call_params) \
427 SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
428 CAutoReleaseHookMan arhm_##id(myhookman##id); \
429 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
431 TestClass##id::ms_DoRecall = false; \
432 TestClass##id *pTest##id = new TestClass##id; \
433 CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
435 /* no hooks - no hooks */ \
437 THGM_CALLS_void(id, call_params); \
438 CHECK_STATES((&g_States, \
439 new State_Func##id(pTest##id, ParamState_m##id call_params), \
440 new State_Func##id(pTest##id, ParamState_m##id call_params), \
441 NULL), "Test" #id " Part1"); \
443 /* hook1 - hook3 */ \
445 THGM_ADD_HOOK(id, 1); \
446 THGM_ADD_HOOK(id, 3); \
447 THGM_CALLS_void(id, call_params); \
448 CHECK_STATES((&g_States, \
449 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
450 new State_Func##id(pTest##id, ParamState_m##id call_params), \
451 new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
452 new State_Func##id(pTest##id, ParamState_m##id call_params), \
453 NULL), "Test" #id " Part4"); \
454 THGM_REMOVE_HOOK(id, 1); \
455 THGM_REMOVE_HOOK(id, 3); \
457 /* hook1, hook2 - hook3 */ \
459 THGM_ADD_HOOK(id, 1); \
460 THGM_ADD_HOOK(id, 2); \
461 THGM_ADD_HOOK(id, 3); \
462 THGM_CALLS_void(id, call_params); \
463 CHECK_STATES((&g_States, \
464 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
465 new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
466 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
467 new State_Func##id(pTest##id, ParamState_m##id call_params), \
468 NULL), "Test" #id " Part5"); \
469 /* hook1, hook2 - hook3, hook4 */ \
470 THGM_ADD_HOOK(id, 4); \
471 THGM_CALLS_void(id, call_params); \
472 CHECK_STATES((&g_States, \
473 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
474 new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
475 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
476 new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
477 new State_Func##id(pTest##id, ParamState_m##id call_params), \
478 NULL), "Test" #id " Part6"); \
480 /* hook1 - hook3, hook4, with recalls! */ \
482 TestClass##id::ms_DoRecall = true; \
483 THGM_REMOVE_HOOK(id, 2); \
484 THGM_CALLS_void(id, call_params); \
485 CHECK_STATES((&g_States, \
486 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
487 new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
488 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
489 new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
491 new State_Func##id(pTest##id, ParamState_m##id call_params), \
492 NULL), "Test" #id " Part7"); \
493 THGM_REMOVE_HOOK(id, 1); \
494 THGM_REMOVE_HOOK(id, 3); \
495 THGM_REMOVE_HOOK(id, 4);
504 T* ComparableRef(T& x)
509 #define THGM_CALLS(id, call_params, exp_ret_norm, exp_ret_shcall, err) \
510 CHECK_COND(ComparableRef<RetType##id>(pTest##id->Func call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_norm)), err " /retcallnorm"); \
511 CHECK_COND(ComparableRef<RetType##id>(SH_CALL(pTest##id, &TestClass##id::Func) call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_shcall)), err " /retcallshcall");
513 #define THGM_DO_TEST(id, call_params) \
516 SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
517 CAutoReleaseHookMan arhm_##id(myhookman##id); \
518 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
520 TestClass##id::ms_DoRecall = false; \
521 TestClass##id *pTest##id = new TestClass##id; \
522 CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
524 /* no hooks - no hooks */ \
526 THGM_CALLS(id, call_params, 0, 0, "Part1"); \
527 CHECK_STATES((&g_States, \
528 new State_Func##id(pTest##id, ParamState_m##id call_params), \
529 new State_Func##id(pTest##id, ParamState_m##id call_params), \
530 NULL), "Test" #id " Part1"); \
532 /* hook1 - hook3 */ \
534 THGM_ADD_HOOK(id, 1); \
535 THGM_ADD_HOOK(id, 3); \
536 THGM_CALLS(id, call_params, 0, 0, "Part4"); \
537 CHECK_STATES((&g_States, \
538 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
539 new State_Func##id(pTest##id, ParamState_m##id call_params), \
540 new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
541 new State_Func##id(pTest##id, ParamState_m##id call_params), \
542 NULL), "Test" #id " Part4"); \
543 THGM_REMOVE_HOOK(id, 1); \
544 THGM_REMOVE_HOOK(id, 3); \
546 /* hook1, hook2 - hook3 */ \
548 THGM_ADD_HOOK(id, 1); \
549 THGM_ADD_HOOK(id, 2); \
550 THGM_ADD_HOOK(id, 3); \
551 THGM_CALLS(id, call_params, 2, 0, "Part5"); \
552 CHECK_STATES((&g_States, \
553 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
554 new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
555 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
556 new State_Func##id(pTest##id, ParamState_m##id call_params), \
557 NULL), "Test" #id " Part5"); \
558 /* hook1, hook2 - hook3, hook4 */ \
559 THGM_ADD_HOOK(id, 4); \
560 THGM_CALLS(id, call_params, 4, 0, "Part6"); \
561 CHECK_STATES((&g_States, \
562 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
563 new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
564 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
565 new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
566 new State_Func##id(pTest##id, ParamState_m##id call_params), \
567 NULL), "Test" #id " Part6"); \
569 /* hook1 - hook3, hook4, with recalls! */ \
571 TestClass##id::ms_DoRecall = true; \
572 THGM_REMOVE_HOOK(id, 2); \
573 THGM_CALLS(id, call_params, 4, 0, "Part7"); \
574 CHECK_STATES((&g_States, \
575 new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
576 new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
577 new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
578 new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
580 new State_Func##id(pTest##id, ParamState_m##id call_params), \
581 NULL), "Test" #id " Part7"); \
582 THGM_REMOVE_HOOK(id, 1); \
583 THGM_REMOVE_HOOK(id, 3); \
584 THGM_REMOVE_HOOK(id, 4);