-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmousetester.sp
275 lines (218 loc) · 6.18 KB
/
mousetester.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
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
/*
* Mouse Tester
* by: shavit
*
* This file is part of Mouse Tester.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <sourcemod>
#include <sdktools>
#include <emitsoundany>
#undef REQUIRE_PLUGIN
#include <shavit>
#include <sourcebans>
#pragma newdecls required
#pragma semicolon 1
#define MOUSETESTER_VERSION "1.0"
// commented - no bans, pure logging/notifications
#define DEBUG
char gS_BeepSound[PLATFORM_MAX_PATH];
bool gB_SourceBans = false;
bool gB_Shavit = false;
float gF_LastDetection[MAXPLAYERS+1];
int gI_DetectedTicks[MAXPLAYERS+1];
float gF_Angles[MAXPLAYERS+1][2];
char gS_LogBans[PLATFORM_MAX_PATH];
public Plugin myinfo =
{
name = "Mouse Tester Anti-Cheat",
author = "shavit",
description = "Detects an invulnerability in most injected cheats, and proceeds to ban.",
version = MOUSETESTER_VERSION,
url = "https://github.com/shavitush"
}
public void OnPluginStart()
{
char[] sPath = new char[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "logs/shmt");
if(!DirExists(sPath))
{
CreateDirectory(sPath, 511);
}
BuildPath(Path_SM, gS_LogBans, PLATFORM_MAX_PATH, "logs/shmt_bans.log");
CreateConVar("mouestester_version", MOUSETESTER_VERSION, "Plugin version.", (FCVAR_NOTIFY | FCVAR_DONTRECORD));
gB_SourceBans = (LibraryExists("sourcebans") || LibraryExists("sourcebans++"));
gB_Shavit = LibraryExists("shavit");
}
public void OnMapStart()
{
// Beep sounds.
Handle hConfig = LoadGameConfigFile("funcommands.games");
if(hConfig == null)
{
SetFailState("Unable to load game config funcommands.games");
return;
}
if(GameConfGetKeyValue(hConfig, "SoundBeep", gS_BeepSound, PLATFORM_MAX_PATH) && gS_BeepSound[0])
{
PrecacheSoundAny(gS_BeepSound, true);
}
}
public void OnLibraryAdded(const char[] name)
{
if(StrEqual(name, "sourcebans") || StrEqual(name, "sourcebans++"))
{
gB_SourceBans = true;
}
else if(StrEqual(name, "shavit"))
{
gB_Shavit = true;
}
}
public void OnLibraryRemoved(const char[] name)
{
if(StrEqual(name, "sourcebans") || StrEqual(name, "sourcebans++"))
{
gB_SourceBans = false;
}
else if(StrEqual(name, "shavit"))
{
gB_Shavit = false;
}
}
public void OnClientPutInServer(int client)
{
gF_LastDetection[client] = -1.0;
gI_DetectedTicks[client] = 0;
gF_Angles[client][0] = -1.0;
gF_Angles[client][1] = -1.0;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if(!IsPlayerAlive(client) || IsFakeClient(client))
{
return Plugin_Continue;
}
int ticks = GetGameTickCount();
if(angles[1] > 180.0 || angles[1] < -180.0 || angles[0] > 90.0 || angles[0] < -90.0)
{
gI_DetectedTicks[client]++;
if(gI_DetectedTicks[client] >= 75)
{
TriggerDetection(client, true, false, "Invalid angle (%d | %f | %f)", ticks, angles[0], angles[1]);
gI_DetectedTicks[client] = 0;
}
return Plugin_Handled;
}
float delta1 = GetDelta(gF_Angles[client][1], angles[1]);
float delta2 = GetDelta(gF_Angles[client][0], angles[0]);
// there's data
if(delta1 != 0.0 || delta2 != 0.0)
{
int dticks = 0;
if(mouse[0] == 0 && (delta1 > 0.10 || delta1 < -0.10) && (buttons & IN_LEFT) == 0 && (buttons & IN_RIGHT) == 0 && (buttons & IN_ATTACK) > 0)
{
dticks++;
}
if(mouse[1] == 0 && (delta2 > 0.10 || delta2 < -0.10) && (buttons & IN_ATTACK) > 0)
{
dticks++;
}
if(dticks > 0)
{
gI_DetectedTicks[client]++;
}
if(gI_DetectedTicks[client] >= 60)
{
TriggerDetection(client, true, false, "Mouse discrepancy (ticks: %d | %d | {%d, %d} | {%f | %f})", gI_DetectedTicks[client], ticks, mouse[0], mouse[1], delta1, delta2);
gI_DetectedTicks[client] = 0;
return Plugin_Handled;
}
}
if(ticks % 100 == 0)
{
gI_DetectedTicks[client] = 0;
}
gF_Angles[client][0] = angles[0];
gF_Angles[client][1] = angles[1];
return Plugin_Continue;
}
float GetDelta(float cur, float old)
{
float delta = cur - old;
if(delta < -180.0)
{
delta += 360.0;
}
else if(delta > 180.0)
{
delta -= 360.0;
}
return delta;
}
void NotifyAdmins(int client, const char[] reason)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsClientInGame(i) && CheckCommandAccess(i, "sm_ban", ADMFLAG_BAN))
{
#if defined DEBUG
PrintToClient(i, "(DEBUG) \x04Cheat detection! \x03%N (uid %d) - \"%s\"", client, client, reason);
#else
PrintToClient(i, "\x04Cheat detection! \x03%N (uid %d) - \"%s\"", client, client, reason);
#endif
EmitSoundToClientAny(i, gS_BeepSound, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_NORMAL);
}
}
}
void PrintToClient(int client, const char[] text, any ...)
{
char[] buffer = new char[300];
VFormat(buffer, 300, text, 3);
if(gB_Shavit)
{
Shavit_PrintToChat(client, "%s", buffer);
}
else
{
PrintToChat(client, "[SHMT]: %s", buffer);
}
}
void TriggerDetection(int client, bool ban, bool notify, const char[] reason, any ...)
{
char[] buffer = new char[300];
VFormat(buffer, 300, reason, 5);
if(notify)
{
NotifyAdmins(client, buffer);
}
if(ban)
{
#if !defined DEBUG
LogToFile(gS_LogBans, "%L | Banned for - %s", client, buffer);
Format(buffer, 300, "[SHMT auto-ban]: %s", buffer);
if(gB_SourceBans)
{
SBBanPlayer(0, client, 129600, buffer);
}
else
{
BanClient(client, 0, BANFLAG_AUTO, buffer, buffer);
}
#else
LogToFile(gS_LogBans, "%L | (DEBUG) Detected for - %s", client, buffer);
#endif
}
}