-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathshavit-misc.sp
2737 lines (2255 loc) · 68.3 KB
/
shavit-misc.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
/*
* shavit's Timer - Miscellaneous
* by: shavit, Technoblazed, strafe, EvanIMK, Nickelony, rtldg, ofirgall
*
* This file is part of shavit's Timer (https://github.com/shavitush/bhoptimer)
*
*
* 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 <sdkhooks>
#include <clientprefs>
#include <convar_class>
#include <dhooks>
#undef REQUIRE_EXTENSIONS
#include <SteamWorks>
#include <cstrike>
#include <tf2>
#include <tf2_stocks>
#include <shavit/core>
#include <shavit/misc>
#undef REQUIRE_PLUGIN
#include <shavit/chat>
#include <shavit/checkpoints>
#include <shavit/rankings>
#include <shavit/replay-playback>
#include <shavit/wr>
#include <shavit/zones>
#include <eventqueuefix>
#include <shavit/weapon-stocks>
#pragma newdecls required
#pragma semicolon 1
#define DEBUG 0
typedef StopTimerCallback = function void (int data);
// game specific
EngineVersion gEV_Type = Engine_Unknown;
char gS_RadioCommands[][] = { "coverme", "takepoint", "holdpos", "regroup", "followme", "takingfire", "go", "fallback", "sticktog",
"getinpos", "stormfront", "report", "roger", "enemyspot", "needbackup", "sectorclear", "inposition", "reportingin",
"getout", "negative", "enemydown", "compliment", "thanks", "cheer", "go_a", "go_b", "sorry", "needrop", "playerradio", "playerchatwheel", "player_ping", "chatwheel_ping" };
bool gB_Hide[MAXPLAYERS+1];
bool gB_AutoRestart[MAXPLAYERS+1];
bool gB_Late = false;
int gI_GroundEntity[MAXPLAYERS+1];
int gI_LastShot[MAXPLAYERS+1];
ArrayList gA_Advertisements = null;
int gI_AdvertisementsCycle = 0;
char gS_Map[PLATFORM_MAX_PATH];
int gI_Style[MAXPLAYERS+1];
Function gH_AfterWarningMenu[MAXPLAYERS+1];
int gI_LastWeaponTick[MAXPLAYERS+1];
int gI_LastNoclipTick[MAXPLAYERS+1];
int gI_LastStopInfo[MAXPLAYERS+1];
// cookies
Handle gH_HideCookie = null;
Handle gH_AutoRestartCookie = null;
Cookie gH_BlockAdvertsCookie = null;
// cvars
Convar gCV_GodMode = null;
Convar gCV_PreSpeed = null;
Convar gCV_HideTeamChanges = null;
Convar gCV_RespawnOnTeam = null;
Convar gCV_RespawnOnRestart = null;
Convar gCV_StartOnSpawn = null;
Convar gCV_PrestrafeLimit = null;
Convar gCV_HideRadar = null;
Convar gCV_TeleportCommands = null;
Convar gCV_NoWeaponDrops = null;
Convar gCV_NoBlock = null;
Convar gCV_NoBlood = null;
Convar gCV_AutoRespawn = null;
Convar gCV_CreateSpawnPoints = null;
Convar gCV_DisableRadio = null;
Convar gCV_Scoreboard = null;
Convar gCV_WeaponCommands = null;
Convar gCV_PlayerOpacity = null;
Convar gCV_StaticPrestrafe = null;
Convar gCV_NoclipMe = null;
Convar gCV_AdvertisementInterval = null;
Convar gCV_RemoveRagdolls = null;
Convar gCV_ClanTag = null;
Convar gCV_DropAll = null;
Convar gCV_JointeamHook = null;
Convar gCV_SpectatorList = null;
Convar gCV_HideChatCommands = null;
Convar gCV_StopTimerWarning = null;
Convar gCV_WRMessages = null;
Convar gCV_BhopSounds = null;
Convar gCV_RestrictNoclip = null;
Convar gCV_SpecScoreboardOrder = null;
Convar gCV_BadSetLocalAnglesFix = null;
ConVar gCV_PauseMovement = null;
// external cvars
ConVar sv_cheats = null;
ConVar sv_disable_immunity_alpha = null;
ConVar mp_humanteam = null;
ConVar hostname = null;
ConVar hostport = null;
ConVar sv_disable_radar = null;
ConVar tf_dropped_weapon_lifetime = null;
// forwards
Handle gH_Forwards_OnClanTagChangePre = null;
Handle gH_Forwards_OnClanTagChangePost = null;
// dhooks
DynamicHook gH_GetPlayerMaxSpeed = null;
DynamicHook gH_IsSpawnPointValid = null;
DynamicDetour gH_CalcPlayerScore = null;
// modules
bool gB_Checkpoints = false;
bool gB_Eventqueuefix = false;
bool gB_Rankings = false;
bool gB_ReplayPlayback = false;
bool gB_Chat = false;
bool gB_Zones = false;
// timer settings
stylestrings_t gS_StyleStrings[STYLE_LIMIT];
// chat settings
chatstrings_t gS_ChatStrings;
public Plugin myinfo =
{
name = "[shavit] Miscellaneous",
author = "shavit, Technoblazed, strafe, EvanIMK, Nickelony, rtldg, ofirgall",
description = "Miscellaneous features for shavit's bhop timer.",
version = SHAVIT_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("Shavit_IsClientUsingHide", Native_IsClientUsingHide);
gB_Late = late;
return APLRes_Success;
}
public void OnPluginStart()
{
// forwards
gH_Forwards_OnClanTagChangePre = CreateGlobalForward("Shavit_OnClanTagChangePre", ET_Event, Param_Cell, Param_String, Param_Cell);
gH_Forwards_OnClanTagChangePost = CreateGlobalForward("Shavit_OnClanTagChangePost", ET_Event, Param_Cell, Param_String, Param_Cell);
// cache
gEV_Type = GetEngineVersion();
sv_cheats = FindConVar("sv_cheats");
sv_disable_immunity_alpha = FindConVar("sv_disable_immunity_alpha");
RegAdminCmd("sm_maptimer_checkpoints", Command_MaptimerCheckpoints, ADMFLAG_RCON, "kz_bhop_yonkoma");
// spectator list
RegConsoleCmd("sm_specs", Command_Specs, "Show a list of spectators.");
RegConsoleCmd("sm_spectators", Command_Specs, "Show a list of spectators.");
// spec
RegConsoleCmd("sm_spec", Command_Spec, "Moves you to the spectators' team. Usage: sm_spec [target]");
RegConsoleCmd("sm_spectate", Command_Spec, "Moves you to the spectators' team. Usage: sm_spectate [target]");
// hide
RegConsoleCmd("sm_hide", Command_Hide, "Toggle players' hiding.");
RegConsoleCmd("sm_unhide", Command_Hide, "Toggle players' hiding.");
gH_HideCookie = RegClientCookie("shavit_hide", "Hide settings", CookieAccess_Protected);
// tpto
RegConsoleCmd("sm_tpto", Command_Teleport, "Teleport to another player. Usage: sm_tpto [target]");
RegConsoleCmd("sm_goto", Command_Teleport, "Teleport to another player. Usage: sm_goto [target]");
// weapons
RegConsoleCmd("sm_usp", Command_Weapon, "Spawn a USP.");
RegConsoleCmd("sm_glock", Command_Weapon, "Spawn a Glock.");
RegConsoleCmd("sm_knife", Command_Weapon, "Spawn a knife.");
// noclip
RegConsoleCmd("sm_prac", Command_Noclip, "Toggles noclip. (sm_nc alias)");
RegConsoleCmd("sm_practice", Command_Noclip, "Toggles noclip. (sm_nc alias)");
RegConsoleCmd("sm_nc", Command_Noclip, "Toggles noclip.");
RegConsoleCmd("sm_noclipme", Command_Noclip, "Toggles noclip. (sm_nc alias)");
// qol
RegConsoleCmd("sm_autorestart", Command_AutoRestart, "Toggles auto-restart.");
RegConsoleCmd("sm_autoreset", Command_AutoRestart, "Toggles auto-restart.");
gH_AutoRestartCookie = RegClientCookie("shavit_autorestart", "Auto-restart settings", CookieAccess_Protected);
AddCommandListener(CommandListener_Noclip, "+noclip");
AddCommandListener(CommandListener_Noclip, "-noclip");
// Hijack sourcemod's sm_noclip from funcommands to work when no args are specified.
AddCommandListener(CommandListener_funcommands_Noclip, "sm_noclip");
AddCommandListener(CommandListener_Real_Noclip, "noclip");
// hook teamjoins
AddCommandListener(Command_Jointeam, "jointeam");
AddCommandListener(Command_Spectate, "spectate");
// gCV_SpecScoreboardOrder stuff
AddCommandListener(Command_SpecNextPrev, "spec_next");
AddCommandListener(Command_SpecNextPrev, "spec_prev");
// hook radio commands instead of a global listener
for(int i = 0; i < sizeof(gS_RadioCommands); i++)
{
AddCommandListener(Command_Radio, gS_RadioCommands[i]);
}
// hooks
HookEvent("player_spawn", Player_Spawn);
HookEvent("player_team", Player_Notifications, EventHookMode_Pre);
HookEvent("player_death", Player_Notifications, EventHookMode_Pre);
HookEventEx("weapon_fire", Weapon_Fire);
HookEventEx("weapon_fire_on_empty", Weapon_Fire);
HookEventEx("weapon_reload", Weapon_Fire);
AddCommandListener(Command_Drop, "drop");
AddTempEntHook("EffectDispatch", EffectDispatch);
AddTempEntHook("World Decal", WorldDecal);
AddTempEntHook((gEV_Type != Engine_TF2)? "Shotgun Shot":"Fire Bullets", Shotgun_Shot);
AddNormalSoundHook(NormalSound);
// phrases
LoadTranslations("common.phrases");
LoadTranslations("shavit-common.phrases");
LoadTranslations("shavit-misc.phrases");
// advertisements
gA_Advertisements = new ArrayList(ByteCountToCells(300));
hostname = FindConVar("hostname");
hostport = FindConVar("hostport");
RegConsoleCmd("sm_toggleadverts", Command_ToggleAdverts, "Toggles visibility of advertisements");
gH_BlockAdvertsCookie = new Cookie("shavit-blockadverts", "whether to block shavit-misc advertisements", CookieAccess_Private);
RegConsoleCmd("sm_adverts", Command_PrintAdverts, "Prints all the adverts to your chat");
// cvars and stuff
gCV_GodMode = new Convar("shavit_misc_godmode", "3", "Enable godmode for players?\n0 - Disabled\n1 - Only prevent fall/world damage.\n2 - Only prevent damage from other players.\n3 - Full godmode.", 0, true, 0.0, true, 3.0);
gCV_PreSpeed = new Convar("shavit_misc_prespeed", "2", "Stop prespeeding in the start zone?\n0 - Disabled, fully allow prespeeding.\n1 - Limit relatively to prestrafelimit.\n2 - Block bunnyhopping in startzone.\n3 - Limit to prestrafelimit and block bunnyhopping.\n4 - Limit to prestrafelimit but allow prespeeding. Combine with shavit_core_nozaxisspeed 1 for SourceCode timer's behavior.\n5 - Limit horizontal speed to prestrafe but allow prespeeding.", 0, true, 0.0, true, 5.0);
gCV_HideTeamChanges = new Convar("shavit_misc_hideteamchanges", "1", "Hide team changes in chat?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_RespawnOnTeam = new Convar("shavit_misc_respawnonteam", "1", "Respawn whenever a player joins a team?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_RespawnOnRestart = new Convar("shavit_misc_respawnonrestart", "1", "Respawn a dead player if they use the timer restart command?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_StartOnSpawn = new Convar("shavit_misc_startonspawn", "1", "Restart the timer for a player after they spawn?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_PrestrafeLimit = new Convar("shavit_misc_prestrafelimit", "30", "Prestrafe limitation in startzone.\nThe value used internally is style run speed + this.\ni.e. run speed of 250 can prestrafe up to 278 (+28) with regular settings.", 0, true, 0.0, false);
gCV_HideRadar = new Convar("shavit_misc_hideradar", "1", "Should the plugin hide the in-game radar?", 0, true, 0.0, true, 1.0);
gCV_TeleportCommands = new Convar("shavit_misc_tpcmds", "1", "Enable teleport-related commands? (sm_goto/sm_tpto)\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_NoWeaponDrops = new Convar("shavit_misc_noweapondrops", "1", "Remove every dropped weapon.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_NoBlock = new Convar("shavit_misc_noblock", "1", "Disable player collision?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_NoBlood = new Convar("shavit_misc_noblood", "1", "Hide blood decals and particles?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_AutoRespawn = new Convar("shavit_misc_autorespawn", "1.5", "Seconds to wait before respawning player?\n0 - Disabled", 0, true, 0.0, true, 10.0);
gCV_CreateSpawnPoints = new Convar("shavit_misc_createspawnpoints", "6", "Amount of spawn points to add for each team.\n0 - Disabled", 0, true, 0.0, true, 32.0);
gCV_DisableRadio = new Convar("shavit_misc_disableradio", "1", "Block radio commands.\n0 - Disabled (radio commands work)\n1 - Enabled (radio commands are blocked)", 0, true, 0.0, true, 1.0);
gCV_Scoreboard = new Convar("shavit_misc_scoreboard", "1", "Manipulate scoreboard so score is -{time} and deaths are {rank})?\nDeaths part requires shavit-rankings.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_WeaponCommands = new Convar("shavit_misc_weaponcommands", "2", "Enable sm_usp, sm_glock, sm_knife, and infinite ammo?\n0 - Disabled\n1 - Enabled\n2 - Also give infinite reserve ammo for USP & Glocks.\n3 - Also give infinite clip ammo for USP & Glocks.\n4 - Also give infinite reserve for all weapons (and grenades).\n5 - Also give infinite clip ammo for all weapons (and grenades).", 0, true, 0.0, true, 5.0);
gCV_PlayerOpacity = new Convar("shavit_misc_playeropacity", "69", "Player opacity (alpha) to set on spawn.\n-1 - Disabled\nValue can go up to 255. 0 for invisibility.", 0, true, -1.0, true, 255.0);
gCV_StaticPrestrafe = new Convar("shavit_misc_staticprestrafe", "1", "Force prestrafe for every pistol.\n250 is the default value and some styles will have 260.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_NoclipMe = new Convar("shavit_misc_noclipme", "1", "Allow +noclip, sm_p and all the noclip commands?\n0 - Disabled\n1 - Enabled\n2 - requires 'admin_noclipme' override or ADMFLAG_CHEATS flag.", 0, true, 0.0, true, 2.0);
gCV_AdvertisementInterval = new Convar("shavit_misc_advertisementinterval", "600.0", "Interval between each chat advertisement.\nConfiguration file for those is configs/shavit-advertisements.cfg.\nSet to 0.0 to disable.\nRequires server restart for changes to take effect.", 0, true, 0.0);
gCV_RemoveRagdolls = new Convar("shavit_misc_removeragdolls", "1", "Remove ragdolls after death?\n0 - Disabled\n1 - Only remove replay bot ragdolls.\n2 - Remove all ragdolls.", 0, true, 0.0, true, 2.0);
gCV_ClanTag = new Convar("shavit_misc_clantag", "{tr}{styletag} :: {time}", "Custom clantag for players.\n0 - Disabled\n{styletag} - style tag.\n{style} - style name.\n{time} - formatted time.\n{tr} - first letter of track.\n{rank} - player rank.\n{cr} - player's chatrank from shavit-chat, trimmed, with no colors", 0);
gCV_DropAll = new Convar("shavit_misc_dropall", "1", "Allow all weapons to be dropped?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_JointeamHook = new Convar("shavit_misc_jointeamhook", "1", "Hook `jointeam`?\n0 - Disabled\n1 - Enabled, players can instantly change teams.", 0, true, 0.0, true, 1.0);
gCV_SpectatorList = new Convar("shavit_misc_speclist", "1", "Who to show in !specs?\n0 - everyone\n1 - all admins (admin_speclisthide override to bypass)\n2 - players you can target", 0, true, 0.0, true, 2.0);
gCV_HideChatCommands = new Convar("shavit_misc_hidechatcmds", "1", "Hide commands from chat?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_StopTimerWarning = new Convar("shavit_misc_stoptimerwarning", "180", "Time in seconds to display a warning before stopping the timer with noclip or !stop.\n0 - Disabled");
gCV_WRMessages = new Convar("shavit_misc_wrmessages", "3", "How many \"NEW <style> WR!!!\" messages to print?\n0 - Disabled", 0, true, 0.0, true, 100.0);
gCV_BhopSounds = new Convar("shavit_misc_bhopsounds", "1", "Should bhop (landing and jumping) sounds be muted?\n1 - Blocked while !hide is enabled\n2 - Always blocked", 0, true, 1.0, true, 2.0);
gCV_RestrictNoclip = new Convar("shavit_misc_restrictnoclip", "0", "Should noclip be be restricted\n0 - Disabled\n1 - No vertical velocity while in noclip in start zone\n2 - No noclip in start zone", 0, true, 0.0, true, 2.0);
gCV_SpecScoreboardOrder = new Convar("shavit_misc_spec_scoreboard_order", "1", "Use scoreboard ordering for players when changing target when spectating.", 0, true, 0.0, true, 1.0);
if (gEV_Type != Engine_CSGO)
{
gCV_BadSetLocalAnglesFix = new Convar("shavit_misc_bad_setlocalangles_fix", "1", "Fix 'Bad SetLocalAngles' on func_rotating entities.", 0, true, 0.0, true, 1.0);
}
gCV_HideRadar.AddChangeHook(OnConVarChanged);
gCV_NoWeaponDrops.AddChangeHook(OnConVarChanged);
Convar.AutoExecConfig();
mp_humanteam = FindConVar((gEV_Type == Engine_TF2) ? "mp_humans_must_join_team" : "mp_humanteam");
sv_disable_radar = FindConVar("sv_disable_radar");
tf_dropped_weapon_lifetime = FindConVar("tf_dropped_weapon_lifetime");
// crons
CreateTimer(10.0, Timer_Cron, 0, TIMER_REPEAT);
LoadDHooks();
if(gEV_Type != Engine_TF2)
{
CreateTimer(1.0, Timer_Scoreboard, 0, TIMER_REPEAT);
}
// modules
gB_Checkpoints = LibraryExists("shavit-checkpoints");
gB_Eventqueuefix = LibraryExists("eventqueuefix");
gB_Rankings = LibraryExists("shavit-rankings");
gB_ReplayPlayback = LibraryExists("shavit-replay-playback");
gB_Chat = LibraryExists("shavit-chat");
gB_Zones = LibraryExists("shavit-zones");
}
public void OnAllPluginsLoaded()
{
gCV_PauseMovement = FindConVar("shavit_core_pause_movement");
}
void LoadDHooks()
{
Handle hGameData = LoadGameConfigFile("shavit.games");
if (hGameData == null)
{
SetFailState("Failed to load shavit gamedata");
}
int iOffset;
if (gEV_Type == Engine_TF2)
{
if (!(gH_CalcPlayerScore = DHookCreateDetour(Address_Null, CallConv_CDECL, ReturnType_Int, ThisPointer_Ignore)))
{
SetFailState("Failed to create detour for CTFGameRules::CalcPlayerScore");
}
if (DHookSetFromConf(gH_CalcPlayerScore, hGameData, SDKConf_Signature, "CTFGameRules::CalcPlayerScore"))
{
gH_CalcPlayerScore.AddParam(HookParamType_Int);
gH_CalcPlayerScore.AddParam(HookParamType_CBaseEntity);
gH_CalcPlayerScore.Enable(Hook_Pre, Detour_CalcPlayerScore);
}
else
{
LogError("Couldn't get the address for \"CTFGameRules::CalcPlayerScore\" - make sure your gamedata is updated!");
}
}
else
{
if ((iOffset = GameConfGetOffset(hGameData, "CCSPlayer::GetPlayerMaxSpeed")) == -1)
{
SetFailState("Couldn't get the offset for \"CCSPlayer::GetPlayerMaxSpeed\" - make sure your gamedata is updated!");
}
gH_GetPlayerMaxSpeed = DHookCreate(iOffset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, CCSPlayer__GetPlayerMaxSpeed);
}
if ((iOffset = GameConfGetOffset(hGameData, "CGameRules::IsSpawnPointValid")) != -1)
{
gH_IsSpawnPointValid = new DynamicHook(iOffset, HookType_GameRules, ReturnType_Bool, ThisPointer_Ignore);
gH_IsSpawnPointValid.AddParam(HookParamType_CBaseEntity);
gH_IsSpawnPointValid.AddParam(HookParamType_CBaseEntity);
}
else
{
SetFailState("Couldn't get the offset for \"CGameRules::IsSpawnPointValid\" - make sure your gamedata is updated!");
}
delete hGameData;
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (convar == gCV_HideRadar && sv_disable_radar != null)
{
sv_disable_radar.BoolValue = gCV_HideRadar.BoolValue;
}
else if (gEV_Type == Engine_TF2 && convar == gCV_NoWeaponDrops)
{
if (convar.BoolValue)
{
tf_dropped_weapon_lifetime.IntValue = 0;
TF2_KillDroppedWeapons();
} else
{
tf_dropped_weapon_lifetime.IntValue = 30; // default value
}
}
}
public MRESReturn Hook_IsSpawnPointValid(Handle hReturn, Handle hParams)
{
if (gCV_NoBlock.BoolValue)
{
DHookSetReturn(hReturn, true);
return MRES_Supercede;
}
return MRES_Ignored;
}
MRESReturn Detour_CalcPlayerScore(DHookReturn hReturn, DHookParam hParams)
{
if (!gCV_Scoreboard.BoolValue)
{
return MRES_Ignored;
}
int client = hParams.Get(2);
float fPB = Shavit_GetClientPB(client, 0, Track_Main);
int iScore = (fPB != 0.0 && fPB < 2000)? -RoundToFloor(fPB):-2000;
hReturn.Value = iScore;
return MRES_Supercede;
}
public void OnClientCookiesCached(int client)
{
if(IsFakeClient(client))
{
return;
}
char sSetting[8];
GetClientCookie(client, gH_HideCookie, sSetting, sizeof(sSetting));
gB_Hide[client] = StringToInt(sSetting) != 0;
GetClientCookie(client, gH_AutoRestartCookie, sSetting, sizeof(sSetting));
gB_AutoRestart[client] = StringToInt(sSetting) != 0;
gI_Style[client] = Shavit_GetBhopStyle(client);
}
public void Shavit_OnStyleConfigLoaded(int styles)
{
for(int i = 0; i < styles; i++)
{
Shavit_GetStyleStringsStruct(i, gS_StyleStrings[i]);
}
}
public void Shavit_OnChatConfigLoaded()
{
Shavit_GetChatStringsStruct(gS_ChatStrings);
if(!LoadAdvertisementsConfig())
{
SetFailState("Cannot open \"configs/shavit-advertisements.cfg\". Make sure this file exists and that the server has read permissions to it.");
}
}
public void Shavit_OnStyleChanged(int client, int oldstyle, int newstyle, int track, bool manual)
{
gI_Style[client] = newstyle;
}
void LoadMapFixes()
{
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-mapfixes.cfg");
KeyValues kv = new KeyValues("shavit-mapfixes");
if (kv.ImportFromFile(sPath) && kv.JumpToKey(gS_Map) && kv.GotoFirstSubKey(false))
{
do {
char key[128];
char value[128];
kv.GetSectionName(key, sizeof(key));
kv.GetString(NULL_STRING, value, sizeof(value));
PrintToServer(">>>> shavit-misc/mapfixes: %s \"%s\"", key, value);
ConVar cvar = FindConVar(key);
if (cvar)
{
cvar.SetString(value, true, true);
}
} while (kv.GotoNextKey(false));
}
delete kv;
}
void CreateSpawnPoint(int iTeam, float fOrigin[3], float fAngles[3])
{
int iSpawnPoint = CreateEntityByName((gEV_Type == Engine_TF2)? "info_player_teamspawn":((iTeam == 2)? "info_player_terrorist":"info_player_counterterrorist"));
if (DispatchSpawn(iSpawnPoint))
{
if (gEV_Type == Engine_TF2)
{
SetEntProp(iSpawnPoint, Prop_Send, "m_iTeamNum", iTeam);
}
TeleportEntity(iSpawnPoint, fOrigin, fAngles, NULL_VECTOR);
}
}
public void OnMapStart()
{
gH_IsSpawnPointValid.HookGamerules(Hook_Post, Hook_IsSpawnPointValid);
GetLowercaseMapName(gS_Map);
if (gB_Late)
{
gB_Late = false;
Shavit_OnStyleConfigLoaded(Shavit_GetStyleCount());
Shavit_OnChatConfigLoaded();
OnAutoConfigsBuffered();
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
OnClientPutInServer(i);
if(AreClientCookiesCached(i))
{
OnClientCookiesCached(i);
Shavit_OnStyleChanged(i, 0, Shavit_GetBhopStyle(i), Shavit_GetClientTrack(i), false);
}
}
}
}
}
public void OnAutoConfigsBuffered()
{
LoadMapFixes();
}
public void OnConfigsExecuted()
{
if(sv_disable_immunity_alpha != null)
{
sv_disable_immunity_alpha.BoolValue = true;
}
if (sv_disable_radar != null && gCV_HideRadar.BoolValue)
{
sv_disable_radar.BoolValue = true;
}
if (tf_dropped_weapon_lifetime != null && gCV_NoWeaponDrops.BoolValue)
{
tf_dropped_weapon_lifetime.IntValue = 0;
}
if(gCV_CreateSpawnPoints.IntValue > 0)
{
int info_player_terrorist = FindEntityByClassname(-1, "info_player_terrorist");
int info_player_counterterrorist = FindEntityByClassname(-1, "info_player_counterterrorist");
int info_player_teamspawn = FindEntityByClassname(-1, "info_player_teamspawn");
int info_player_start = FindEntityByClassname(-1, "info_player_start");
int iEntity =
((info_player_terrorist != -1) ? info_player_terrorist :
((info_player_counterterrorist != -1) ? info_player_counterterrorist :
((info_player_teamspawn != -1) ? info_player_teamspawn :
((info_player_start != -1) ? info_player_start : -1))));
if (iEntity != -1)
{
float fOrigin[3], fAngles[3];
GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", fOrigin);
GetEntPropVector(iEntity, Prop_Data, "m_angAbsRotation", fAngles);
if (gEV_Type == Engine_TF2)
{
int iSearch = -1;
bool haveRed = false;
bool haveBlu = false;
while ((iSearch = FindEntityByClassname(iSearch, "info_player_teamspawn")) != -1)
{
int team = GetEntProp(iSearch, Prop_Send, "m_iTeamNum");
haveRed = haveRed || team == 2;
haveBlu = haveBlu || team == 3;
}
if (!haveRed)
{
CreateSpawnPoint(2, fOrigin, fAngles);
}
if (!haveBlu)
{
CreateSpawnPoint(3, fOrigin, fAngles);
}
}
else
{
if (info_player_terrorist == -1)
{
CreateSpawnPoint(2, fOrigin, fAngles);
}
if (info_player_counterterrorist == -1)
{
CreateSpawnPoint(3, fOrigin, fAngles);
}
}
}
}
if(gCV_AdvertisementInterval.FloatValue > 0.0)
{
CreateTimer(gCV_AdvertisementInterval.FloatValue, Timer_Advertisement, 0, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
}
bool LoadAdvertisementsConfig()
{
gA_Advertisements.Clear();
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-advertisements.cfg");
KeyValues kv = new KeyValues("shavit-advertisements");
if(!kv.ImportFromFile(sPath) || !kv.GotoFirstSubKey(false))
{
delete kv;
return false;
}
do
{
char sTempMessage[300];
kv.GetString(NULL_STRING, sTempMessage, 300, "<EMPTY ADVERTISEMENT>");
ReplaceString(sTempMessage, 300, "{text}", gS_ChatStrings.sText);
ReplaceString(sTempMessage, 300, "{warning}", gS_ChatStrings.sWarning);
ReplaceString(sTempMessage, 300, "{variable}", gS_ChatStrings.sVariable);
ReplaceString(sTempMessage, 300, "{variable2}", gS_ChatStrings.sVariable2);
ReplaceString(sTempMessage, 300, "{style}", gS_ChatStrings.sStyle);
gA_Advertisements.PushString(sTempMessage);
}
while(kv.GotoNextKey(false));
delete kv;
gI_AdvertisementsCycle = gA_Advertisements.Length ? (gI_AdvertisementsCycle % gA_Advertisements.Length) : 0;
return true;
}
public void OnLibraryAdded(const char[] name)
{
if(StrEqual(name, "shavit-rankings"))
{
gB_Rankings = true;
}
else if(StrEqual(name, "shavit-replay-playback"))
{
gB_ReplayPlayback = true;
}
else if(StrEqual(name, "shavit-chat"))
{
gB_Chat = true;
}
else if (StrEqual(name, "shavit-zones"))
{
gB_Zones = true;
}
else if (StrEqual(name, "shavit-checkpoints"))
{
gB_Checkpoints = true;
}
else if(StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = true;
}
}
public void OnLibraryRemoved(const char[] name)
{
if(StrEqual(name, "shavit-rankings"))
{
gB_Rankings = false;
}
else if(StrEqual(name, "shavit-replay-playback"))
{
gB_ReplayPlayback = false;
}
else if(StrEqual(name, "shavit-chat"))
{
gB_Chat = false;
}
else if (StrEqual(name, "shavit-zones"))
{
gB_Zones = false;
}
else if (StrEqual(name, "shavit-checkpoints"))
{
gB_Checkpoints = false;
}
else if(StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = false;
}
}
int GetHumanTeam()
{
char sTeam[8];
mp_humanteam.GetString(sTeam, 8);
if(StrEqual(sTeam, "t", false) || StrEqual(sTeam, "red", false))
{
return 2;
}
else if(StrEqual(sTeam, "ct", false) || StrContains(sTeam, "blu", false) != -1)
{
return 3;
}
return 0;
}
public Action Command_Spectate(int client, const char[] command, int args)
{
if(!IsValidClient(client) || !gCV_JointeamHook.BoolValue)
{
return Plugin_Continue;
}
Command_Spec(client, 0);
return Plugin_Stop;
}
public int ScoreboardSort(int index1, int index2, Handle array, Handle hndl)
{
int a = GetArrayCell(array, index1);
int b = GetArrayCell(array, index2);
int a_team = GetClientTeam(a);
int b_team = GetClientTeam(b);
if (a_team != b_team)
{
return a_team > b_team ? -1 : 1;
}
int a_score;
int b_score;
if (gEV_Type == Engine_CSGO)
{
a_score = CS_GetClientContributionScore(a);
b_score = CS_GetClientContributionScore(b);
}
else
{
a_score = GetEntProp(a, Prop_Data, "m_iFrags");
b_score = GetEntProp(b, Prop_Data, "m_iFrags");
}
if (a_score != b_score)
{
return a_score > b_score ? -1 : 1;
}
int a_deaths = GetEntProp(a, Prop_Data, "m_iDeaths");
int b_deaths = GetEntProp(b, Prop_Data, "m_iDeaths");
if (a_deaths != b_deaths)
{
return a_deaths < b_deaths ? -1 : 1;
}
return a < b ? -1 : 1;
}
public Action Command_SpecNextPrev(int client, const char[] command, int args)
{
if (!IsValidClient(client) || !gCV_SpecScoreboardOrder.BoolValue)
{
return Plugin_Continue;
}
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if (iObserverMode <= 3 /* OBS_MODE_FIXED */)
{
return Plugin_Continue;
}
ArrayList players = new ArrayList(1);
// add valid alive players
for (int i = 1; i <= MaxClients; i++)
{
if (i != client && IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1)
{
players.Push(i);
}
}
if (players.Length < 2)
{
delete players;
return Plugin_Continue;
}
players.SortCustom(ScoreboardSort);
int current_target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if (!IsValidClient(current_target))
{
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", players.Get(0));
delete players;
return Plugin_Stop;
}
int pos = players.FindValue(current_target);
if (pos == -1)
{
pos = 0;
}
pos += (StrEqual(command, "spec_next", true)) ? 1 : -1;
if (pos < 0)
{
pos = players.Length - 1;
}
if (pos >= players.Length)
{
pos = 0;
}
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", players.Get(pos));
delete players;
return Plugin_Stop;
}
public Action Command_Jointeam(int client, const char[] command, int args)
{
if(!IsValidClient(client) || !gCV_JointeamHook.BoolValue)
{
return Plugin_Continue;
}
char arg1[8];
GetCmdArg(1, arg1, 8);
int iTeam = StringToInt(arg1);
int iHumanTeam = GetHumanTeam();
if (iHumanTeam != 0 && iTeam != 1)
{
iTeam = iHumanTeam;
}
if (iTeam < 1 || iTeam > 3)
{
iTeam = GetRandomInt(2, 3);
}
CleanSwitchTeam(client, iTeam);
if(gCV_RespawnOnTeam.BoolValue && iTeam != 1)
{
if(gEV_Type == Engine_TF2)
{
TF2_RespawnPlayer(client);
}
else
{
RemoveAllWeapons(client); // so weapons are removed and we don't hit the edict limit
CS_RespawnPlayer(client);
}
return Plugin_Stop;
}
return Plugin_Continue;
}
void CleanSwitchTeam(int client, int team)
{
if (gEV_Type == Engine_CSGO && GetClientTeam(client) == team)
{
// Close the team menu when selecting your own team...
Event event = CreateEvent("player_team");
event.SetInt("userid", GetClientUserId(client));
event.SetInt("team", team);
event.SetBool("silent", true);
event.FireToClient(client);
event.Cancel();
}
if(gEV_Type == Engine_TF2)
{
TF2_ChangeClientTeam(client, view_as<TFTeam>(team));
}
else if(team != 1)
{
CS_SwitchTeam(client, team);
}
else
{
// Remove flashlight :)
if (gEV_Type == Engine_CSS)
{
int EF_DIMLIGHT = 4;
SetEntProp(client, Prop_Send, "m_fEffects", ~EF_DIMLIGHT & GetEntProp(client, Prop_Send, "m_fEffects"));
}
ChangeClientTeam(client, team);
}
}
public Action Command_Radio(int client, const char[] command, int args)
{
if(gCV_DisableRadio.BoolValue)
{
return Plugin_Stop;
}
return Plugin_Continue;
}
public MRESReturn CCSPlayer__GetPlayerMaxSpeed(int pThis, DHookReturn hReturn)
{
if(!gCV_StaticPrestrafe.BoolValue || !IsValidClient(pThis, true))
{
return MRES_Ignored;
}
hReturn.Value = Shavit_GetStyleSettingFloat(gI_Style[pThis], "runspeed");
return MRES_Override;
}
float normalize_ang(float ang)
{
while (ang > 180.0) ang -= 360.0;
while (ang < -180.0) ang += 360.0; return ang;
}
public Action Timer_Cron(Handle timer)
{
if(gCV_HideRadar.BoolValue && gEV_Type == Engine_CSS)
{
float salt = GetURandomFloat();
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
RemoveRadar(i, salt);
}
}
}
if (gCV_NoWeaponDrops.BoolValue)
{
int ent = -1;
while ((ent = FindEntityByClassname(ent, "weapon_*")) != -1)
{
if (GetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity") == -1)
{
AcceptEntityInput(ent, "Kill");
}
}
}
if (gEV_Type != Engine_CSGO && gCV_BadSetLocalAnglesFix.BoolValue)
{
int ent = -1;
while ((ent = FindEntityByClassname(ent, "func_rotating")) != -1)
{
float ang[3], newang[3];
GetEntPropVector(ent, Prop_Send, "m_angRotation", ang);
newang[0] = normalize_ang(ang[0]);