-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsghook.cpp
293 lines (267 loc) · 8.16 KB
/
msghook.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include <windows.h>
#include <mmsystem.h>
#include <memory.h>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#define _CRT_SECURE_NO_WARNINGS
#include "gateways.h"
#include "parsemsg.h"
#include "client.h"
#include "weapon.h"
#include "players.h"
#include "xorstr.h"
#include "cvar.h"
#include "apihook.h"
#include "Engine.h"
#include "stdafx.h"
#define IS_DEAD (1<<0)
#define HAS_BOMB (1<<1)
#define IS_VIP (1<<2)
void AtRoundStart(void);
int modId;
int RoundsPlayed = 0;
bool bMsgHook = false;
#pragma warning(disable:4786)
#pragma warning(disable:4800)
#pragma warning(disable:4244)
#pragma warning(disable:4101)
#pragma warning(disable:4715)
#pragma warning(disable:4305)
void ConPrint(LPSTR form, ...)
{
static char tmp[2048];
va_list p;
va_start(p, form);
vsprintf(tmp, form, p);
OutputDebugStringA(tmp);
va_end(p);
}
pfnUserMsgHook TeamInfoOrg = NULL;
pfnUserMsgHook SetFOVOrg = NULL;
pfnUserMsgHook CurWeaponOrg = NULL;
pfnUserMsgHook ScoreAttribOrg = NULL;
pfnUserMsgHook HealthOrg = NULL;
pfnUserMsgHook BatteryOrg = NULL;
pfnUserMsgHook ScoreInfoOrg = NULL;
pfnUserMsgHook DeathMsgOrg = NULL;
pfnUserMsgHook SayTextOrg = NULL;
pfnUserMsgHook ResetHUDOrg = NULL;
pfnUserMsgHook TextMsgOrg = NULL;
pfnUserMsgHook DamageOrg = NULL;
pfnUserMsgHook AmmoXOrg = NULL;
pfnUserMsgHook WeaponListOrg = NULL;
pfnUserMsgHook MoneyOrg = NULL;
pfnUserMsgHook ServerNameOrg = NULL;
pfnUserMsgHook IAC_QueryOrg = NULL;
pfnUserMsgHook IAC_HIQueryOrg = NULL;
pfnUserMsgHook RadarOrg = NULL;
pfnUserMsgHook StatusValueOrg = NULL;
pfnUserMsgHook BrassOrg = NULL;
pfnUserMsgHook PTeamOrg = NULL;
float fCurrentFOV;
//==================================================================================
static int TeamInfo(const char *pszName, int iSize, void *pbuf)
{
ConPrint("TeamInfo=%s", pbuf);
BEGIN_READ(pbuf, iSize);
int px = READ_BYTE();
char * teamtext = READ_STRING();
char STR_TERROR[9];
char STR_CT[2];
char STR_UNASSIGNED[10];
char STR_SPECTATOR[9];
strcpy(STR_TERROR,/*TERRORIST*/XorStr<0xC4, 10, 0x38B5214A>("\x90\x80\x94\x95\x87\x9B\x83\x98\x98" + 0x38B5214A).s);
strcpy(STR_CT,/*CT*/XorStr<0xA9, 3, 0xF0057E58>("\xEA\xFE" + 0xF0057E58).s);
strcpy(STR_UNASSIGNED,/*UNASSIGNED*/XorStr<0x96, 11, 0xEAA6E22A>("\xC3\xD9\xD9\xCA\xC9\xD2\xDB\xD3\xDB\xDB" + 0xEAA6E22A).s);
strcpy(STR_SPECTATOR,/*SPECTATOR*/XorStr<0x8E, 10, 0x924A9907>("\xDD\xDF\xD5\xD2\xC6\xD2\xC0\xDA\xC4" + 0x924A9907).s);
if (!strcmp(teamtext, STR_TERROR)) g_Player[px].team = 1;
else if (!strcmp(teamtext, STR_CT)) g_Player[px].team = 2;
else if (!strcmp(teamtext, STR_UNASSIGNED)) g_Player[px].team = 0;
else if (!strcmp(teamtext, STR_SPECTATOR)) g_Player[px].team = 0;
else {
g_Player[px].team = -1;
}
if (px == GetLocalPlayer()->index)
{
if (!strcmp(teamtext, STR_TERROR)) g_Local.team = 1;
else if (!strcmp(teamtext, STR_CT)) g_Local.team = 2;
else if (!strcmp(teamtext, STR_UNASSIGNED)) g_Local.team = 0;
else if (!strcmp(teamtext, STR_SPECTATOR)) g_Local.team = 0;
else {
g_Local.team = -1;
}
}
return (*TeamInfoOrg)(pszName, iSize, pbuf);
}
int CurWeapon(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
int iState = READ_BYTE();
int iID = READ_CHAR();
int iClip = READ_CHAR();
if (iState) g_Local.iClip = iClip;
WeaponListCurWeapon(iState, iID, iClip);
return (*CurWeaponOrg)(pszName, iSize, pbuf);
}
int ScoreAttrib(const char *pszName, int iSize, void *pbuf)
{
UpdateMe();
BEGIN_READ(pbuf, iSize);
int idx = READ_BYTE();
int info = READ_BYTE();
if (idx == g_Local.ent->index)
g_Local.alive = info != IS_DEAD;
g_Player[idx].hasbomb = info == HAS_BOMB;
g_Player[idx].vip = info == IS_VIP;
return (*ScoreAttribOrg)(pszName, iSize, pbuf);
}
int SetFOV(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
g_Local.iFOV = READ_BYTE();
if (!g_Local.iFOV) { g_Local.iFOV = 90; }
if (g_Local.iFOV == 90) { g_Local.inZoomMode = false; }
else { g_Local.inZoomMode = true; }
fCurrentFOV = g_Local.iFOV;
return (*SetFOVOrg)(pszName, iSize, pbuf);
}
int Health(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
g_Local.iHealth = READ_BYTE();
return (*HealthOrg)(pszName, iSize, pbuf);
}
int Battery(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
g_Local.iArmor = READ_BYTE();
return (*BatteryOrg)(pszName, iSize, pbuf);
}
int ScoreInfo(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
int id = READ_BYTE();
int frags = READ_SHORT();
int deaths = READ_SHORT();
int classid = READ_SHORT();
int teamid = READ_SHORT();
if (id == g_Local.ent->index)
{
if (g_Local.iKills > frags)
{
g_Local.iKills = 0;
g_Local.iHs = 0;
}
g_Local.iDeaths = deaths;
}
return (*ScoreInfoOrg)(pszName, iSize, pbuf);
}
int DeathMsg(const char *pszName, int iSize, void *pbuf)
{
UpdateMe();
BEGIN_READ(pbuf, iSize);
int killer = READ_BYTE();
int victim = READ_BYTE();
int headshot = READ_BYTE();
char* weaponName = READ_STRING();
if (killer == g_Local.ent->index && headshot)
g_Local.iHs++;
if (killer == g_Local.ent->index && victim != g_Local.ent->index)
g_Local.iKills++;
g_Player[victim].setDead();
g_Player[victim].updateClear();
return (*DeathMsgOrg)(pszName, iSize, pbuf);
}
int SayText(const char *pszName, int iSize, void *pbuf)
{
return (*SayTextOrg)(pszName, iSize, pbuf);
}
int TextMsg(const char *pszName, int iSize, void *pbuf)
{
return (*TextMsgOrg)(pszName, iSize, pbuf);
}
int ResetHUD(const char *pszName, int iSize, void *pbuf)
{
AtRoundStart();
RoundsPlayed++;
return (*ResetHUDOrg)(pszName, iSize, pbuf);
}
int Damage(const char *pszName, int iSize, void *pbuf)
{
return (*DamageOrg)(pszName, iSize, pbuf);
}
int AmmoX(const char *pszName, int iSize, void *pbuf)
{
return 0;
}
int WeaponListMsg(const char *pszName, int iSize, void *pbuf)
{
return (*WeaponListOrg)(pszName, iSize, pbuf);
}
int Money(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
g_Local.iMoney = READ_SHORT();
return (*MoneyOrg)(pszName, iSize, pbuf);
}
int ServerName(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);
return (*ServerNameOrg)(pszName, iSize, pbuf);
}
int Radar(const char *pszName, int iSize, void *pbuf)
{
return (*RadarOrg)(pszName, iSize, pbuf);
}
int HookUserMsg(char *szMsgName, pfnUserMsgHook pfn)
{
int retval;
if (!modId)
{
OutputDebugString(szMsgName);
#define REDIRECT_MESSAGE(name)\
else if (!strcmp(szMsgName,#name))\
{\
name##Org = pfn;\
retval = g_Engine.pfnHookUserMsg(szMsgName,##name);\
}
if (0) {}
else if (!strcmp(szMsgName,/*TeamInfo*/XorStr<0xA7, 9, 0x93B42356>("\xF3\xCD\xC8\xC7\xE2\xC2\xCB\xC1" + 0x93B42356).s))
{
TeamInfoOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, TeamInfo);
}
else if (!strcmp(szMsgName,/*CurWeapon*/XorStr<0xF7, 10, 0x4D94E1F3>("\xB4\x8D\x8B\xAD\x9E\x9D\x8D\x91\x91" + 0x4D94E1F3).s))
{
CurWeaponOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, CurWeapon);
}
else if (!strcmp(szMsgName,/*SetFOV*/XorStr<0xDD, 7, 0xFAC49F20>("\x8E\xBB\xAB\xA6\xAE\xB4" + 0xFAC49F20).s))
{
SetFOVOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, SetFOV);
}
else if (!strcmp(szMsgName,/*Health*/XorStr<0x32, 7, 0xF4BA79A2>("\x7A\x56\x55\x59\x42\x5F" + 0xF4BA79A2).s))
{
HealthOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, Health);
}
else if (!strcmp(szMsgName,/*ScoreInfo*/XorStr<0xE4, 10, 0xDC8EC937>("\xB7\x86\x89\x95\x8D\xA0\x84\x8D\x83" + 0xDC8EC937).s))
{
ScoreInfoOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, ScoreInfo);
}
else if (!strcmp(szMsgName,/*WeaponList*/XorStr<0xA4, 11, 0xD15F2FC8>("\xF3\xC0\xC7\xD7\xC7\xC7\xE6\xC2\xDF\xD9" + 0xD15F2FC8).s)) // Because the Class is called like the Msg
{
WeaponListOrg = pfn;
retval = g_Engine.pfnHookUserMsg(szMsgName, WeaponListMsg);
}
else
retval = g_Engine.pfnHookUserMsg(szMsgName, pfn);
}
else
retval = g_Engine.pfnHookUserMsg(szMsgName, pfn);
return retval;
}