-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistenevents_tracker.sp
235 lines (177 loc) · 6.63 KB
/
listenevents_tracker.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <dhooks>
#pragma newdecls required
Handle g_detourCLCMsg_ListenEvents;
Handle g_callGetEventDescriptor;
Address g_gameEventManager;
public void OnPluginStart()
{
GameData conf = new GameData("listenevents_tracker.games");
if (conf == null)
SetFailState("Failed to load listenevents_tracker gamedata");
StartPrepSDKCall(SDKCall_Static);
if (!PrepSDKCall_SetFromConf(conf, SDKConf_Signature, "CreateInterface"))
SetFailState("Failed to get CreateInterface");
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
char iface[64];
if (!conf.GetKeyValue("GameEventManagerInterface", iface, sizeof(iface)))
SetFailState("Failed to get gameeventmanager interface name");
Handle call = EndPrepSDKCall();
g_gameEventManager = SDKCall(call, iface, 0);
delete call;
if (!g_gameEventManager)
SetFailState("Failed to get gameeventmanager ptr");
StartPrepSDKCall(SDKCall_Raw);
if (!PrepSDKCall_SetFromConf(conf, SDKConf_Signature, "CGameEventManager::GetEventDescriptor"))
SetFailState("Failed to load CGameEventManager::GetEventDescriptor signature from gamedata");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
g_callGetEventDescriptor = EndPrepSDKCall();
if (!(g_detourCLCMsg_ListenEvents = DHookCreateFromConf(conf, "CBaseClient::CLCMsg_ListenEvents")))
SetFailState("Failed to setup detour for CBaseClient::CLCMsg_ListenEvents");
delete conf;
if (!DHookEnableDetour(g_detourCLCMsg_ListenEvents, false, Detour_CLCMsg_ListenEvents))
SetFailState("Failed to detour CBaseClient::CLCMsg_ListenEvents");
}
public MRESReturn Detour_CLCMsg_ListenEvents(Address thisPtr, Handle retn, Handle params)
{
int client = LoadFromAddress(thisPtr + view_as<Address>(0x70), NumberType_Int32) + 1;
if (!IsClientConnected(client))
return MRES_Ignored;
char name[MAX_NAME_LENGTH];
char steamid[64];
GetClientName(client, name, sizeof(name));
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
LogMessage("========== CLCMsg_ListenEvents arrived from client %s (%s) ==========", name, steamid);
int event_mask_size = DHookGetParamObjectPtrVar(params, 1, 0x0C, ObjectValueType_Int);
Address event_mask_ptr = DHookGetParamObjectPtrVar(params, 1, 0x08, ObjectValueType_Int);
int event_mask[16];
for (int i = 0; i < event_mask_size && i < 16; i++)
event_mask[i] = LoadFromAddress(event_mask_ptr + view_as<Address>(i * 0x04), NumberType_Int32);
int index = BitVec512_FindNextSetBit(event_mask, 0);
while (index >= 0)
{
Address descriptor = SDKCall(g_callGetEventDescriptor, g_gameEventManager, index);
if (descriptor)
{
char eventName[64];
GetEventDescName(descriptor, eventName, sizeof(eventName));
LogMessage("%i: %s", index, eventName);
}
else
{
LogMessage("%i: unknown", index);
}
index = BitVec512_FindNextSetBit(event_mask, index + 1);
}
return MRES_Ignored;
}
void GetEventDescName(Address descriptor, char[] dest, int len)
{
if (len > 0)
{
Address eventMap = LoadFromAddress(g_gameEventManager + view_as<Address>(0x78), NumberType_Int32);
int elemIdx = LoadFromAddress(descriptor + view_as<Address>(0x04), NumberType_Int32);
Address eventName = LoadFromAddress(eventMap + view_as<Address>(0x18 * elemIdx + 0x10), NumberType_Int32);
int i;
for (i = 0; i < len - 1; i++)
{
char chr = LoadFromAddress(eventName + view_as<Address>(i), NumberType_Int8);
if (chr == '\0')
break;
dest[i] = chr;
}
dest[i] = '\0';
}
}
int BitVec_FirstBitInWord(int elem, int offset)
{
static const int firstBitLUT[256] =
{
0,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,
3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,
3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,
3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0
};
int elem_byte = (elem & 0xFF);
if (elem_byte)
return offset + firstBitLUT[elem_byte];
elem >>>= 8;
offset += 8;
elem_byte = (elem & 0xFF);
if (elem_byte)
return offset + firstBitLUT[elem_byte];
elem >>>= 8;
offset += 8;
elem_byte = (elem & 0xFF);
if (elem_byte)
return offset + firstBitLUT[elem_byte];
elem >>>= 8;
offset += 8;
elem_byte = (elem & 0xFF);
if (elem_byte)
return offset + firstBitLUT[elem_byte];
return -1;
}
int BitVec512_FindNextSetBit(int bit_vec[16], int start_bit)
{
static const int start_mask[32] =
{
0xffffffff,
0xfffffffe,
0xfffffffc,
0xfffffff8,
0xfffffff0,
0xffffffe0,
0xffffffc0,
0xffffff80,
0xffffff00,
0xfffffe00,
0xfffffc00,
0xfffff800,
0xfffff000,
0xffffe000,
0xffffc000,
0xffff8000,
0xffff0000,
0xfffe0000,
0xfffc0000,
0xfff80000,
0xfff00000,
0xffe00000,
0xffc00000,
0xff800000,
0xff000000,
0xfe000000,
0xfc000000,
0xf8000000,
0xf0000000,
0xe0000000,
0xc0000000,
0x80000000,
};
if (start_bit < 512)
{
int word_index = start_bit >> 5;
int elem = bit_vec[word_index];
elem &= start_mask[start_bit & 31];
if (elem)
return BitVec_FirstBitInWord(elem, word_index << 5);
word_index++;
while (word_index < 16)
{
elem = bit_vec[word_index];
if (elem)
return BitVec_FirstBitInWord(elem, word_index << 5);
word_index++;
}
}
return -1;
}