Uh.
2 #include "sourcehook.h"
3 #include "sourcehook_test.h"
4 #include "testevents.h"
7 // Test modifying parameters from hook handlers
12 SourceHook::ISourceHook *g_SHPtr;
13 SourceHook::Plugin g_PLID;
15 MAKE_STATE_1(State_Func1, int);
16 MAKE_STATE_1(State_H1_Func1, int);
17 MAKE_STATE_1(State_H2_Func1, int);
18 MAKE_STATE_2(State_HP_Func1, int, void*);
20 MAKE_STATE_1(State_Func2, int);
21 MAKE_STATE_1(State_H1_Func2, int);
22 MAKE_STATE_2(State_HP_Func2, int, int);
26 virtual void Func1(int a)
28 ADD_STATE(State_Func1(a));
31 virtual int Func2(int a)
33 ADD_STATE(State_Func2(a));
38 virtual int Func2(int a, int b)
44 void Handler1_Func1(int a)
46 ADD_STATE(State_H1_Func1(a));
47 RETURN_META_NEWPARAMS(MRES_IGNORED, &Test::Func1, (5));
49 void Handler2_Func1(int a)
51 ADD_STATE(State_H2_Func1(a));
52 RETURN_META_NEWPARAMS(MRES_IGNORED, &Test::Func1, (a - 5));
54 void HandlerPost_Func1(int a)
56 ADD_STATE(State_HP_Func1(a, META_IFACEPTR(void)));
60 int Handler1_Func2(int a)
62 ADD_STATE(State_H1_Func2(a));
63 // Pfeeehhh, ugly, I know, but I had to test it :)
64 RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 500,
65 static_cast<int (Test::*)(int)>(&Test::Func2), (a - 10));
68 int HandlerPost_Func2(int a)
70 ADD_STATE(State_HP_Func2(a, META_RESULT_ORIG_RET(int)));
71 RETURN_META_VALUE(MRES_IGNORED, 0);
74 SH_DECL_HOOK1_void(Test, Func1, SH_NOATTRIB, 0, int);
75 SH_DECL_HOOK1(Test, Func2, SH_NOATTRIB, 0, int, int);
78 bool TestRecall(std::string &error)
86 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler1_Func1, false);
87 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
88 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, HandlerPost_Func1, true);
92 CHECK_STATES((&g_States,
93 new State_H1_Func1(77),
94 new State_H2_Func1(5),
96 new State_HP_Func1(0, ptr),
99 SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, Handler1_Func1, false);
100 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
101 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
102 SH_ADD_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
106 CHECK_STATES((&g_States,
107 new State_H2_Func1(77),
108 new State_H2_Func1(72),
109 new State_H2_Func1(67),
110 new State_H2_Func1(62),
112 new State_HP_Func1(57, ptr),
115 SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, Handler2_Func1, false);
116 SH_REMOVE_HOOK_STATICFUNC(Test, Func1, ptr, HandlerPost_Func1, true);
120 CHECK_STATES((&g_States,
126 SH_ADD_HOOK_STATICFUNC(Test, Func2, ptr, Handler1_Func2, false);
127 SH_ADD_HOOK_STATICFUNC(Test, Func2, ptr, HandlerPost_Func2, true);
129 int a = ptr->Func2(77);
130 CHECK_STATES((&g_States,
131 new State_H1_Func2(77),
133 new State_HP_Func2(67, 1000), // 1000 because it's the ORIG_RET
136 CHECK_COND(a == 500, "Part 4.1");