-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathl4d2_lilac.sp
2140 lines (1690 loc) · 58 KB
/
l4d2_lilac.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Little Anti-Cheat
Copyright (C) 2018-2020 J_Tanzanite
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 <https://www.gnu.org/licenses/>.
*/
#include <sourcemod>
#include <sdktools_engine>
#undef REQUIRE_PLUGIN
#undef REQUIRE_EXTENSIONS
#tryinclude <materialadmin>
#tryinclude <sourcebanspp>
#include <tf2>
#include <tf2_stocks>
#define VERSION "1.5.0"
#define CMD_LENGTH 330
#define GAME_UNKNOWN 0
#define GAME_TF2 1
#define GAME_CSGO 2
#define GAME_DODS 3
#define GAME_L4D2 4
#define GAME_L4D 5
#define CHEAT_ANGLES 0
#define CHEAT_CHATCLEAR 1
#define CHEAT_CONVAR 2
#define CHEAT_NOLERP 3
#define CHEAT_BHOP 4
#define CHEAT_AIMBOT 5
#define CHEAT_AIMLOCK 6
#define CHEAT_MAX 7
#define CVAR_ENABLE 0
#define CVAR_WELCOME 1
#define CVAR_SB 2
#define CVAR_MA 3
#define CVAR_LOG 4
#define CVAR_LOG_EXTRA 5
#define CVAR_LOG_MISC 6
#define CVAR_LOG_DATE 7
#define CVAR_BAN 8
#define CVAR_BAN_LENGTH 9
#define CVAR_ANGLES 10
#define CVAR_PATCH_ANGLES 11
#define CVAR_CHAT 12
#define CVAR_CONVAR 13
#define CVAR_NOLERP 14
#define CVAR_BHOP 15
#define CVAR_AIMBOT 16
#define CVAR_AIMBOT_AUTOSHOOT 17
#define CVAR_AIMLOCK 18
#define CVAR_AIMLOCK_LIGHT 19
#define CVAR_BACKTRACK_PATCH 20
#define CVAR_MAX_PING 21
#define CVAR_MAX_LERP 22
#define CVAR_LOSS_FIX 23
#define CVAR_MAX 24
#define ACTION_SHOT 1
#define QUERY_MAX_FAILURES 24
#define QUERY_TIMEOUT 30
#define QUERY_TIMER 5.0
#define AIMLOCK_BAN_MIN 5
#define AIMBOT_BAN_MIN 5
#define AIMBOT_MAX_TOTAL_DELTA (180.0 * 2.5)
#define AIMBOT_FLAG_REPEAT (1 << 0)
#define AIMBOT_FLAG_AUTOSHOOT (1 << 1)
#define AIMBOT_FLAG_SNAP (1 << 2)
#define AIMBOT_FLAG_SNAP2 (1 << 3)
// Convars.
Handle cvar_bhop = null;
Handle cvar[CVAR_MAX];
int icvar[CVAR_MAX];
int sv_cheats = 0;
int time_sv_cheats = 0;
int cvar_bhop_value = 0;
int sv_maxupdaterate = 0;
// Banlength overwrite.
int ban_length_overwrite[CHEAT_MAX];
// Misc.
int ggame;
char line[2048];
char dateformat[512] = "%Y/%m/%d %H:%M:%S";
float max_angles[3] = {89.01, 0.0, 50.01};
Handle forwardhandle = INVALID_HANDLE;
Handle forwardhandleban = INVALID_HANDLE;
Handle forwardhandleallow = INVALID_HANDLE;
bool sourcebans_exist = false;
bool materialadmin_exist = false;
// Logging.
int playerinfo_index[MAXPLAYERS + 1];
int playerinfo_tickcount[MAXPLAYERS + 1];
int playerinfo_buttons[MAXPLAYERS + 1][CMD_LENGTH];
int playerinfo_actions[MAXPLAYERS + 1][CMD_LENGTH];
int playerinfo_autoshoot[MAXPLAYERS + 1];
int playerinfo_jumps[MAXPLAYERS + 1];
int playerinfo_high_ping[MAXPLAYERS + 1];
int playerinfo_query_index[MAXPLAYERS + 1];
int playerinfo_query_failed[MAXPLAYERS + 1];
int playerinfo_aimlock_sus[MAXPLAYERS + 1];
int playerinfo_aimlock[MAXPLAYERS + 1];
int playerinfo_aimbot[MAXPLAYERS + 1];
int playerinfo_bhop[MAXPLAYERS + 1];
float playerinfo_time_teleported[MAXPLAYERS + 1];
float playerinfo_time_aimlock[MAXPLAYERS + 1];
float playerinfo_time_backtrack[MAXPLAYERS + 1];
float playerinfo_time_process_aimlock[MAXPLAYERS + 1];
float playerinfo_angles[MAXPLAYERS + 1][CMD_LENGTH][3];
float playerinfo_time_usercmd[MAXPLAYERS + 1][CMD_LENGTH];
bool playerinfo_banned_flags[MAXPLAYERS + 1][CHEAT_MAX];
bool playerinfo_ignore_lerp[MAXPLAYERS + 1];
// Basic query list.
char query_list[][] = {
"sv_cheats",
"r_drawothermodels",
"mat_wireframe",
"snd_show",
"snd_visualize",
"mat_proxy",
"r_drawmodelstatsoverlay",
"r_shadowwireframe",
"r_showenvcubemap",
"r_drawrenderboxes",
"r_modelwireframedecal"
};
public Plugin:myinfo = {
name = "小反作弊",
author = "J_Tanzanite",
description = "An opensource Anti-Cheat.",
version = VERSION,
url = ""
};
public void OnPluginStart()
{
Handle tcvar;
char gamefolder[32];
LoadTranslations("lilac.phrases.txt");
GetGameFolderName(gamefolder, sizeof(gamefolder));
if (StrEqual(gamefolder, "tf", false)) {
ggame = GAME_TF2;
HookEvent("player_teleported",
event_teleported, EventHookMode_Post);
}
else if (StrEqual(gamefolder, "csgo", false)) {
ggame = GAME_CSGO;
// Pitch Anti-Aim doesn't work for CSGO anymore,
// but horrible cheats may still attempt it.
// max_angles = Float:{0.0, 0.0, 50.01};
if ((cvar_bhop = FindConVar("sv_autobunnyhopping")) != null) {
cvar_bhop_value = GetConVarInt(cvar_bhop);
HookConVarChange(cvar_bhop, cvar_change);
}
else {
// We weren't able to get the cvar,
// disable bhop checks just in case.
cvar_bhop_value = 1;
PrintToServer("[Lilac] Unable to to find convar \"sv_autobunnyhopping\", bhop checks have been forcefully disabled.");
}
}
else if (StrEqual(gamefolder, "left4dead2", false)) {
ggame = GAME_L4D2;
// Pitch AA isn't really used much in L4D2 afaik, plus,
// like larrybrains reported, causes false positives for
// the infected team memeber smoker.
// Thanks to Larrybrains for reporting this!
max_angles = Float:{0.0, 0.0, 50.01};
}
else if (StrEqual(gamefolder, "left4dead", false)) {
ggame = GAME_L4D;
// Same as L4D2, the smoker handles pitch differently it seems.
// Thanks to finishlast for reporting this!
max_angles = Float:{0.0, 0.0, 50.01};
}
else if (StrEqual(gamefolder, "dod", false)) {
ggame = GAME_DODS;
}
else {
ggame = GAME_UNKNOWN;
PrintToServer("[Lilac] This game currently isn't supported, Little Anti-Cheat will still run, but expect some bugs and false positives/bans!");
}
if (ggame == GAME_TF2)
HookEvent("player_death",
event_player_death_tf2, EventHookMode_Pre);
else
HookEvent("player_death",
event_player_death, EventHookMode_Pre);
HookEvent("player_spawn", event_teleported, EventHookMode_Post);
cvar[CVAR_ENABLE] = CreateConVar("lilac_enable", "1",
"是否开启插件",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_WELCOME] = CreateConVar("lilac_welcome", "0",
"是否显示欢迎信息",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_SB] = CreateConVar("lilac_sourcebans", "1",
"是否使用 Sourcebans 代替默认的 ban,如果未安装则视为0",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_MA] = CreateConVar("lilac_materialadmin", "1",
"是否使用 Material-Admin 代替默认的 ban,如果未安装则视为0",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_LOG] = CreateConVar("lilac_log", "1",
"是否开启日志记录",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_LOG_EXTRA] = CreateConVar("lilac_log_extra", "1",
"是否记录额外的信息.0=关闭.1=只有ban时.2=全部信息",
FCVAR_PROTECTED, true, 0.0, true, 2.0);
cvar[CVAR_LOG_MISC] = CreateConVar("lilac_log_misc", "0",
"是否记录因其他原因导致的kick",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_LOG_DATE] = CreateConVar("lilac_log_date", "{year}/{month}/{day} {hour}:{minute}:{second}",
"日志的时间格式. 输入: \"lilac_date_list\" 查看更多信息.",
FCVAR_PROTECTED, false, 0.0, false, 0.0);
cvar[CVAR_BAN] = CreateConVar("lilac_ban", "1",
"是否开启 ban 功能。除非在测试效果,否则不要设置为 0",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_BAN_LENGTH] = CreateConVar("lilac_ban_length", "0",
"ban 持续时间.0=无限",
FCVAR_PROTECTED, true, 0.0, false, 0.0);
cvar[CVAR_ANGLES] = CreateConVar("lilac_angles", "1",
"检测角度",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_PATCH_ANGLES] = CreateConVar("lilac_angles_patch", "1",
"检测 patch 角度",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_CHAT] = CreateConVar("lilac_chatclear", "1",
"检测聊天清理",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_CONVAR] = CreateConVar("lilac_convar", "0",
"检测错误 ConVars.",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_NOLERP] = CreateConVar("lilac_nolerp", "1",
"检测 NoLerp.",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_BHOP] = CreateConVar("lilac_bhop", "2",
"检测 BHop.0=禁用.1=检测10次.2=检测5次",
FCVAR_PROTECTED, true, 0.0, true, 2.0);
cvar[CVAR_AIMBOT] = CreateConVar("lilac_aimbot", "5",
"检测 Aimbot.0=禁用.1=仅记录.5>=检测指定次数",
FCVAR_PROTECTED, true, 0.0, false, 0.0);
cvar[CVAR_AIMBOT_AUTOSHOOT] = CreateConVar("lilac_aimbot_autoshoot", "1",
"检测 TriggerBot.",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_AIMLOCK] = CreateConVar("lilac_aimlock", "10",
"检测 Aimlock.0=禁用.1=仅记录.5>=检测指定次数",
FCVAR_PROTECTED, true, 0.0, false, 0.0);
cvar[CVAR_AIMLOCK_LIGHT] = CreateConVar("lilac_aimlock_light", "1",
"最多只能处理 5 个 Aimlock.除非出现意外,否则不要禁用它",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_BACKTRACK_PATCH] = CreateConVar("lilac_backtrack_patch", "0",
"修补 Backtrack.0=禁用.1=启用",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
cvar[CVAR_MAX_PING] = CreateConVar("lilac_max_ping", "0",
"禁止延迟超过该值的玩家3分钟.0=关闭",
FCVAR_PROTECTED, true, 0.0, true, 1000.0);
cvar[CVAR_MAX_LERP] = CreateConVar("lilac_max_lerp", "105",
"Kick players with an interp higher than this in ms (minimum possible is 105ms, default value in Source games is 100ms).\nThis is done to patch an exploit in the game that makes facestabbing players in TF2 easier (aka cl_interp 0.5).\n0 = Disabled.\n105+ = Kick larger than this.",
FCVAR_PROTECTED, true, 0.0, true, 510.0); // 500 is max possible.
cvar[CVAR_LOSS_FIX] = CreateConVar("lilac_loss_fix", "1",
"对于 loss 过高的玩家放宽检测",
FCVAR_PROTECTED, true, 0.0, true, 1.0);
for (int i = 0; i < CVAR_MAX; i++) {
if (i != CVAR_LOG_DATE)
icvar[i] = GetConVarInt(cvar[i]);
HookConVarChange(cvar[i], cvar_change);
}
if ((tcvar = FindConVar("sv_maxupdaterate")) != null) {
HookConVarChange(tcvar, cvar_change);
sv_maxupdaterate = GetConVarInt(tcvar);
}
if ((tcvar = FindConVar("sv_cheats")) != null) {
HookConVarChange(tcvar, cvar_change);
sv_cheats = GetConVarInt(tcvar);
}
else {
sv_cheats = 1;
}
for (int i = 0; i < CHEAT_MAX; i++)
ban_length_overwrite[i] = -1;
// If sv_maxupdaterate is changed mid-game and then this plugin
// is loaded, then it could lead to false positives.
// Reset all stats on all players already in-game, but ignore lerp.
for (int i = 1; i <= MaxClients; i++) {
lilac_reset_client(i);
playerinfo_ignore_lerp[i] = true;
}
RegServerCmd("lilac_date_list", lilac_date_list,
"Lists date formatting options", 0);
RegServerCmd("lilac_set_ban_length", lilac_set_ban_length,
"Sets custom ban lengths for specific cheats.", 0);
// Server is using the old config location, execute it.
if (FileExists("cfg/lilac_config.cfg", false, NULL_STRING)) {
AutoExecConfig(true, "lilac_config", "");
}
else {
// Server either just installed Lilac, or wants to use
// the more traditional config folder.
AutoExecConfig(true, "lilac_config", "sourcemod");
}
forwardhandle = CreateGlobalForward("lilac_cheater_detected",
ET_Ignore, Param_Cell, Param_Cell);
forwardhandleban = CreateGlobalForward("lilac_cheater_banned",
ET_Ignore, Param_Cell, Param_Cell);
forwardhandleallow = CreateGlobalForward("lilac_allow_cheat_detection",
ET_Event, Param_Cell, Param_Cell);
CreateTimer(QUERY_TIMER, timer_query, _, TIMER_REPEAT);
CreateTimer(5.0, timer_check_ping, _, TIMER_REPEAT);
CreateTimer(5.0, timer_check_lerp, _, TIMER_REPEAT);
CreateTimer(0.5, timer_check_aimlock, _, TIMER_REPEAT);
if (icvar[CVAR_LOG])
lilac_log_first_time_setup();
}
public void OnAllPluginsLoaded()
{
// Sourcebans compat...
sourcebans_exist = LibraryExists("sourcebans++");
materialadmin_exist = LibraryExists("materialadmin");
// Startup message.
PrintToServer("[Little Anti-Cheat %s] Successfully loaded!", VERSION);
}
public Action lilac_set_ban_length(int args)
{
char feature[32], length[32];
int index = -1;
int time;
if (args < 2) {
PrintToServer("Error: Too few arguments.\n\nUsage:\t\tlilac_set_ban_length <cheat> <minutes>");
PrintToServer("Example:\tlilac_set_ban_length bhop 15\n\nSets bhop ban to 15 minutes.");
PrintToServer("If ban length is -1, then the length will be ConVar lilac_ban_length\n");
PrintToServer("Possible cheat arguments:");
PrintToServer("\tlilac_set_ban_length angles <minutes>");
PrintToServer("\tlilac_set_ban_length chatclear <minutes>");
PrintToServer("\tlilac_set_ban_length convar <minutes>");
PrintToServer("\tlilac_set_ban_length nolerp <minutes>");
PrintToServer("\tlilac_set_ban_length bhop <minutes>");
PrintToServer("\tlilac_set_ban_length aimbot <minutes>");
PrintToServer("\tlilac_set_ban_length aimlock <minutes>\n");
return Plugin_Handled;
}
GetCmdArg(1, feature, sizeof(feature));
if (StrEqual(feature, "angles", false) || StrEqual(feature, "angle", false)) {
index = CHEAT_ANGLES;
}
else if (StrEqual(feature, "chat", false) || StrEqual(feature, "chatclear", false)) {
index = CHEAT_CHATCLEAR;
}
else if (StrEqual(feature, "convar", false) || StrEqual(feature, "cvar", false)) {
index = CHEAT_CONVAR;
}
else if (StrEqual(feature, "nolerp", false)) {
index = CHEAT_NOLERP;
}
else if (StrEqual(feature, "bhop", false) || StrEqual(feature, "bunnyhop", false)) {
index = CHEAT_BHOP;
}
else if (StrEqual(feature, "aimbot", false) || StrEqual(feature, "aim", false)) {
index = CHEAT_AIMBOT;
}
else if (StrEqual(feature, "aimlock", false)) {
index = CHEAT_AIMLOCK;
}
else {
PrintToServer("Error: Unknown cheat feature \"%s\"", feature);
return Plugin_Handled;
}
GetCmdArg(2, length, sizeof(length));
time = StringToInt(length, 10);
if (time < -1)
time = -1;
ban_length_overwrite[index] = time;
return Plugin_Handled;
}
public Action lilac_date_list(int args)
{
PrintToServer("=======[Lilac Date Formatting]=======");
PrintToServer("Manual formatting:");
PrintToServer("\t{raw} = Skips the special formatting listed here");
PrintToServer("\t and lets you insert your own formatting");
PrintToServer("\t (see: http://www.cplusplus.com/reference/ctime/strftime/).");
PrintToServer("Example:\n\t{raw}%%Y/%%m/%%d %%H:%%M:%%S");
PrintToServer("Dates:");
PrintToServer("\t{year} = Numerical year (2020).");
PrintToServer("\t{month} = Numerical month (12).");
PrintToServer("\t{day} = Numerical day (28).");
PrintToServer("Time:");
PrintToServer("\t{hour} = 24 hour format.");
PrintToServer("\t{hours} = 24 hour format.");
PrintToServer("\t{24hour} = 24 hour format.");
PrintToServer("\t{24hours} = 24 hour format.");
PrintToServer("\t{12hour} = 12 hour format.");
PrintToServer("\t{12hours} = 12 hour format.");
PrintToServer("\t{pm} = Insert AM/PM.");
PrintToServer("\t{am} = Insert AM/PM.");
PrintToServer("\t{minute} = Minute.");
PrintToServer("\t{minutes} = Minute.");
PrintToServer("\t{second} = Second.");
PrintToServer("\t{seconds} = Second.");
PrintToServer("Using flags example: {year}/{month}/{day} {hour}:{minute}:{second}");
}
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int err_max)
{
// Been told this isn't needed, but just in case.
MarkNativeAsOptional("SBPP_BanPlayer");
MarkNativeAsOptional("MABanPlayer");
return APLRes_Success;
}
public void OnLibraryAdded(const char []name)
{
if (StrEqual(name, "sourcebans++"))
sourcebans_exist = true;
else if (StrEqual(name, "materialadmin"))
materialadmin_exist = true;
}
public void OnLibraryRemoved(const char []name)
{
if (StrEqual(name, "sourcebans++"))
sourcebans_exist = false;
else if (StrEqual(name, "materialadmin"))
materialadmin_exist = false;
}
public void cvar_change(ConVar convar, const char[] oldValue,
const char[] newValue)
{
char cvarname[64];
char testdate[512];
// Thanks to MAGNAT2645 for informing me I could do this!
if (view_as<Handle>(convar) == cvar[CVAR_ENABLE]) {
icvar[CVAR_ENABLE] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_WELCOME]) {
icvar[CVAR_WELCOME] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_SB]) {
icvar[CVAR_SB] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_MA]) {
icvar[CVAR_MA] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_LOG]) {
icvar[CVAR_LOG] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_LOG_EXTRA]) {
icvar[CVAR_LOG_EXTRA] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_LOG_MISC]) {
icvar[CVAR_LOG_MISC] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_LOG_DATE]) {
lilac_setup_date_format(newValue);
FormatTime(testdate, sizeof(testdate), dateformat, GetTime());
PrintToServer("Date Format Preview: %s", testdate);
}
else if (view_as<Handle>(convar) == cvar[CVAR_BAN]) {
icvar[CVAR_BAN] = StringToInt(newValue, 10);
if (!icvar[CVAR_BAN])
PrintToServer("[Little Anti-Cheat %s] WARNING: 'lilac_ban' has been set to 0, banning of cheaters has been disabled.", VERSION);
}
else if (view_as<Handle>(convar) == cvar[CVAR_BAN_LENGTH]) {
icvar[CVAR_BAN_LENGTH] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_ANGLES]) {
icvar[CVAR_ANGLES] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_PATCH_ANGLES]) {
icvar[CVAR_PATCH_ANGLES] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_CHAT]) {
icvar[CVAR_CHAT] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_CONVAR]) {
icvar[CVAR_CONVAR] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_NOLERP]) {
icvar[CVAR_NOLERP] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_BHOP]) {
icvar[CVAR_BHOP] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_AIMBOT]) {
icvar[CVAR_AIMBOT] = StringToInt(newValue, 10);
if (icvar[CVAR_AIMBOT] > 1 &&
icvar[CVAR_AIMBOT] < AIMBOT_BAN_MIN)
icvar[CVAR_AIMBOT] = 5;
}
else if (view_as<Handle>(convar) == cvar[CVAR_AIMBOT_AUTOSHOOT]) {
icvar[CVAR_AIMBOT_AUTOSHOOT] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_AIMLOCK]) {
icvar[CVAR_AIMLOCK] = StringToInt(newValue, 10);
if (icvar[CVAR_AIMLOCK] > 1
&& icvar[CVAR_AIMLOCK] < AIMLOCK_BAN_MIN)
icvar[CVAR_AIMLOCK] = 5;
}
else if (view_as<Handle>(convar) == cvar[CVAR_AIMLOCK_LIGHT]) {
icvar[CVAR_AIMLOCK_LIGHT] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_BACKTRACK_PATCH]) {
icvar[CVAR_BACKTRACK_PATCH] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_MAX_PING]) {
icvar[CVAR_MAX_PING] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_MAX_LERP]) {
icvar[CVAR_MAX_LERP] = StringToInt(newValue, 10);
}
else if (view_as<Handle>(convar) == cvar[CVAR_LOSS_FIX]) {
icvar[CVAR_LOSS_FIX] = StringToInt(newValue, 10);
}
else {
GetConVarName(convar, cvarname, sizeof(cvarname));
if (StrEqual(cvarname, "sv_autobunnyhopping", false)) {
cvar_bhop_value = StringToInt(newValue, 10);
}
else if (StrEqual(cvarname, "sv_maxupdaterate", false)) {
sv_maxupdaterate = StringToInt(newValue);
// Changing this convar mid-game can cause false positives.
// Ignore players already in-game.
for (int i = 1; i <= MaxClients; i++)
playerinfo_ignore_lerp[i] = true;
}
else if (StrEqual(cvarname, "sv_cheats", false)) {
sv_cheats = StringToInt(newValue);
// Delay convar checks for 30 seconds.
time_sv_cheats = GetTime() + QUERY_TIMEOUT;
}
}
}
public void OnClientPutInServer(int client)
{
lilac_reset_client(client);
// CreateTimer(20.0, timer_welcome, GetClientUserId(client));
}
void lilac_reset_client(int client)
{
playerinfo_ignore_lerp[client] = false;
playerinfo_index[client] = 0;
playerinfo_tickcount[client] = 0;
playerinfo_autoshoot[client] = 0;
playerinfo_jumps[client] = 0;
playerinfo_high_ping[client] = 0;
playerinfo_query_index[client] = 0;
playerinfo_query_failed[client] = 0;
playerinfo_aimlock_sus[client] = 0;
playerinfo_aimlock[client] = 0;
playerinfo_aimbot[client] = 0;
playerinfo_bhop[client] = 0;
playerinfo_time_teleported[client] = 0.0;
playerinfo_time_aimlock[client] = 0.0;
playerinfo_time_backtrack[client] = 0.0;
playerinfo_time_process_aimlock[client] = 0.0;
for (int i = 0; i < CHEAT_MAX; i++)
playerinfo_banned_flags[client][i] = false;
for (int i = 0; i < CMD_LENGTH; i++) {
playerinfo_buttons[client][i] = 0;
playerinfo_actions[client][i] = 0;
playerinfo_time_usercmd[client][i] = 0.0;
set_player_log_angles(client, Float:{0.0, 0.0, 0.0}, i);
}
}
public void TF2_OnConditionRemoved(int client, TFCond condition)
{
if (condition == TFCond_Taunting)
playerinfo_time_teleported[client] = GetGameTime();
}
public Action event_teleported(Event event, const char[] name,
bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid", -1));
if (is_player_valid(client))
playerinfo_time_teleported[client] = GetGameTime();
}
public Action event_player_death(Event event, const char[] name,
bool dontBroadcast)
{
if (!icvar[CVAR_ENABLE])
return Plugin_Continue;
int userid = GetEventInt(event, "attacker", -1);
int client = GetClientOfUserId(userid);
int victim = GetClientOfUserId(GetEventInt(event, "userid", -1));
event_death_shared(userid, client, victim, false);
return Plugin_Continue;
}
// Todo: Ehh, needs some work, not pretty.
public Action event_player_death_tf2(Event event, const char[] name,
bool dontBroadcast)
{
if (!icvar[CVAR_ENABLE])
return Plugin_Continue;
char wep[64];
int userid = GetEventInt(event, "attacker", -1);
int client = GetClientOfUserId(userid);
int victim = GetClientOfUserId(GetEventInt(event, "userid", -1));
int killtype = GetEventInt(event, "customkill", 0);
GetEventString(event, "weapon_logclassname", wep, sizeof(wep), "");
// Ignore sentries in TF2.
if (!strncmp(wep, "obj_", 4, false))
return Plugin_Continue;
// Killtype 3 = flamethrower.
event_death_shared(userid, client, victim,
((killtype == 3) ? true : false));
return Plugin_Continue;
}
void event_death_shared(int userid, int client, int victim, bool skip_delta)
{
DataPack pack;
float killpos[3], deathpos[3];
int skip_snap = 0;
if (client == victim)
return;
if (!is_player_valid(client)
|| !is_player_valid(victim)
|| IsFakeClient(client)
|| playerinfo_banned_flags[client][CHEAT_AIMBOT]
|| GetClientTime(client) < 10.1)
return;
if (icvar[CVAR_AIMLOCK_LIGHT])
lilac_aimlock_light_test(client);
if (!icvar[CVAR_AIMBOT])
return;
GetClientEyePosition(client, killpos);
GetClientEyePosition(victim, deathpos);
// Killer and victim are too close to each other,
// Skip some detections.
if (GetVectorDistance(killpos, deathpos) < 350.0 || skip_delta)
skip_snap = 1;
CreateDataTimer(0.5, timer_check_aimbot, pack);
pack.WriteCell(userid);
pack.WriteCell(skip_snap);
// Fallback to this tick if the shot isn't found.
pack.WriteCell(playerinfo_index[client]);
pack.WriteFloat(killpos[0]);
pack.WriteFloat(killpos[1]);
pack.WriteFloat(killpos[2]);
pack.WriteFloat(deathpos[0]);
pack.WriteFloat(deathpos[1]);
pack.WriteFloat(deathpos[2]);
}
public Action timer_welcome(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (is_player_valid(client) && icvar[CVAR_WELCOME] && icvar[CVAR_ENABLE] && icvar[CVAR_BAN])
PrintToChat(client, "[Lilac] %T", "welcome_msg", client, VERSION);
}
public Action timer_query(Handle timer)
{
if (!icvar[CVAR_ENABLE] || !icvar[CVAR_CONVAR])
return Plugin_Continue;
// sv_cheats recently changed or is set to 1, abort.
if (GetTime() < time_sv_cheats || sv_cheats)
return Plugin_Continue;
for (int i = 1; i <= MaxClients; i++) {
if (!is_player_valid(i) || IsFakeClient(i))
continue;
// Player recently joined, wait before querying.
if (GetClientTime(i) < 60.0)
continue;
// Don't query already banned players.
if (playerinfo_banned_flags[i][CHEAT_CONVAR])
continue;
// Only increments query index if the player
// has responded to the last one.
if (!playerinfo_query_failed[i]) {
if (++playerinfo_query_index[i] >= 11)
playerinfo_query_index[i] = 0;
}
QueryClientConVar(i, query_list[playerinfo_query_index[i]], query_reply, 0);
if (++playerinfo_query_failed[i] > QUERY_MAX_FAILURES) {
if (icvar[CVAR_LOG_MISC]) {
lilac_log_setup_client(i);
Format(line, sizeof(line),
"%s was kicked for failing to respond to %d queries in %.0f seconds.",
line, QUERY_MAX_FAILURES, QUERY_TIMER * QUERY_MAX_FAILURES);
lilac_log(true);
if (icvar[CVAR_LOG_EXTRA] == 2)
lilac_log_extra(i);
}
KickClient(i, "[Lilac] %T", "kick_query_failure", i);
}
}
return Plugin_Continue;
}
public void query_reply(QueryCookie cookie, int client,
ConVarQueryResult result, const char[] cvarName,
const char[] cvarValue, any value)
{
// Player NEEDS to answer the query.
if (result != ConVarQuery_Okay)
return;
// Client did respond to the query request, move on to the next convar.
playerinfo_query_failed[client] = 0;
// Any response the server may recieve may also be faulty, ignore.
if (GetTime() < time_sv_cheats || sv_cheats)
return;
// Already banned.
if (playerinfo_banned_flags[client][CHEAT_CONVAR])
return;
int val = StringToInt(cvarValue);
// Check for invalid convar responses.
// This is pretty ugly, but does the job for
// a simple & basic query system.
if ((StrEqual("sv_cheats", cvarName, false) && val)
|| (StrEqual("r_drawothermodels", cvarName, false) && val != 1)
|| (StrEqual("mat_wireframe", cvarName, false) && val)
|| (StrEqual("snd_show", cvarName, false) && val)
|| (StrEqual("snd_visualize", cvarName, false) && val)
|| (StrEqual("mat_proxy", cvarName, false) && val)
|| (StrEqual("r_drawmodelstatsoverlay", cvarName, false) && val)
|| (StrEqual("r_shadowwireframe", cvarName, false) && val)
|| (StrEqual("r_showenvcubemap", cvarName, false) && val)
|| (StrEqual("r_drawrenderboxes", cvarName, false) && val)
|| (StrEqual("mat_fullbright", cvarName, false) && val)
|| (StrEqual("r_modelwireframedecal", cvarName, false) && val)) {
if (lilac_forward_allow_cheat_detection(client, CHEAT_CONVAR) == false)
return;
lilac_forward_client_cheat(client, CHEAT_CONVAR);
if (icvar[CVAR_LOG]) {
lilac_log_setup_client(client);
Format(line, sizeof(line),
"%s was detected and banned for an invalid ConVar (%s %s).",
line, cvarName, cvarValue);
lilac_log(true);
if (icvar[CVAR_LOG_EXTRA])
lilac_log_extra(client);
}
playerinfo_banned_flags[client][CHEAT_CONVAR] = true;
lilac_ban_client(client, CHEAT_CONVAR);
}
}
public Action timer_check_lerp(Handle timer)
{
float min;
if (!icvar[CVAR_ENABLE])
return Plugin_Continue;
if (sv_maxupdaterate > 0)
min = 1.0 / float(sv_maxupdaterate);
else
min = 0.0;
for (int i = 1; i <= MaxClients; i++) {
if (!is_player_valid(i) || IsFakeClient(i))
continue;
float lerp = GetEntPropFloat(i, Prop_Data, "m_fLerpTime");
if (lerp * 1000.0 > float(icvar[CVAR_MAX_LERP]) && icvar[CVAR_MAX_LERP] >= 105) {
if (icvar[CVAR_LOG_MISC]) {
lilac_log_setup_client(i);
Format(line, sizeof(line),
"%s was kicked for exploiting interpolation (%.3fms / %dms max).",
line, lerp * 1000.0, icvar[CVAR_MAX_LERP]);
lilac_log(true);
if (icvar[CVAR_LOG_EXTRA] == 2)
lilac_log_extra(i);
}
KickClient(i, "[Lilac] %T", "kick_interp_exploit", i,
lerp * 1000.0, icvar[CVAR_MAX_LERP], float(icvar[CVAR_MAX_LERP]) / 999.9);
continue;
}
if (!icvar[CVAR_NOLERP]
|| playerinfo_ignore_lerp[i]
|| playerinfo_banned_flags[i][CHEAT_NOLERP]
|| min < 0.005) // Minvalue invalid or too low.
continue;
if (lerp > min * 0.95 /* buffer */)
continue;
if (lilac_forward_allow_cheat_detection(i, CHEAT_NOLERP) == false)
continue;
playerinfo_banned_flags[i][CHEAT_NOLERP] = true;
lilac_forward_client_cheat(i, CHEAT_NOLERP);
if (icvar[CVAR_LOG]) {
lilac_log_setup_client(i);
Format(line, sizeof(line),
"%s was detected and banned for NoLerp (%fms).",
line, lerp * 1000.0);
lilac_log(true);
if (icvar[CVAR_LOG_EXTRA])
lilac_log_extra(i);
}
lilac_ban_client(i, CHEAT_NOLERP);
}
return Plugin_Continue;
}
public Action timer_check_ping(Handle timer)
{
static bool toggle = true;
char reason[128];
float ping;
if (!icvar[CVAR_ENABLE] || icvar[CVAR_MAX_PING] < 100)
return Plugin_Continue;
for (int i = 1; i <= MaxClients; i++) {
if (!is_player_valid(i) || IsFakeClient(i))
continue;
// Player recently joined, don't check ping yet.
if (GetClientTime(i) < 100.0)
continue;
ping = GetClientAvgLatency(i, NetFlow_Outgoing) * 1000.0;
if (ping < float(icvar[CVAR_MAX_PING])) {
if (toggle && playerinfo_high_ping[i] > 0)
playerinfo_high_ping[i]--;
continue;
}
// Player has a higher ping than maximum for 45 seconds.
if (++playerinfo_high_ping[i] < 9)
continue;
if (icvar[CVAR_LOG_MISC]) {
lilac_log_setup_client(i);
Format(line, sizeof(line),
"%s was kicked for having too high ping (%.3fms / %dms max).",
line, ping, icvar[CVAR_MAX_PING]);
lilac_log(true);
if (icvar[CVAR_LOG_EXTRA] == 2)
lilac_log_extra(i);
}
Format(reason, sizeof(reason),
"[Lilac] %T", "tban_ping_high", i,
ping, icvar[CVAR_MAX_PING]);
// Ban the client for three minutes to avoid instant reconnects.
BanClient(i, 3, BANFLAG_AUTHID, reason, reason, "lilac", 0);
}
toggle = !toggle;
return Plugin_Continue;
}
public Action timer_check_aimlock(Handle timer)
{
float ang[3], lang[3], ideal[3], pos[3], pos2[3];
float aimdist, laimdist;
int lock;
bool skip_report[MAXPLAYERS + 1]; // Skip reporting this player.
bool report[MAXPLAYERS + 1]; // report this player.
bool process; // Keep processing the player.
int players_processed = 0;
if (!icvar[CVAR_ENABLE] || !icvar[CVAR_AIMLOCK])
return Plugin_Continue;
for (int i = 1; i <= MaxClients; i++) {
skip_report[i] = true;
report[i] = false;
// Don't process more than 5 players!
if (players_processed >= 5 && icvar[CVAR_AIMLOCK_LIGHT] == 1)
return Plugin_Continue;