-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathcs2fixes.cpp
More file actions
1375 lines (1094 loc) · 47.8 KB
/
cs2fixes.cpp
File metadata and controls
1375 lines (1094 loc) · 47.8 KB
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
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023-2025 Source2ZE
* =============================================================================
*
* 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 "cs2fixes.h"
#include "iserver.h"
#include "adminsystem.h"
#include "appframework/IAppSystem.h"
#include "commands.h"
#include "common.h"
#include "cs_gameevents.pb.h"
#include "ctimer.h"
#include "detours.h"
#include "discord.h"
#include "entities.h"
#include "entity/ccsplayercontroller.h"
#include "entity/services.h"
#include "entitylistener.h"
#include "entitysystem.h"
#include "entwatch.h"
#include "eventlistener.h"
#include "gameconfig.h"
#include "gameevents.pb.h"
#include "gamesystem.h"
#include "httpmanager.h"
#include "hud_manager.h"
#include "icvar.h"
#include "idlemanager.h"
#include "interface.h"
#include "leader.h"
#include "map_votes.h"
#include "networkstringtabledefs.h"
#include "panoramavote.h"
#include "patches.h"
#include "plat.h"
#include "playermanager.h"
#include "schemasystem/schemasystem.h"
#include "serversideclient.h"
#include "te.pb.h"
#include "tier0/dbg.h"
#include "tier0/vprof.h"
#include "user_preferences.h"
#include "usermessages.pb.h"
#include "votemanager.h"
#include "zombiereborn.h"
#include <entity.h>
#include "tier0/memdbgon.h"
void Message(const char* msg, ...)
{
va_list args;
va_start(args, msg);
char buf[1024] = {};
V_vsnprintf(buf, sizeof(buf) - 1, msg, args);
ConColorMsg(Color(255, 0, 255, 255), "[CS2Fixes] %s", buf);
va_end(args);
}
void Panic(const char* msg, ...)
{
va_list args;
va_start(args, msg);
char buf[1024] = {};
V_vsnprintf(buf, sizeof(buf) - 1, msg, args);
Warning("[CS2Fixes] %s", buf);
va_end(args);
}
class GameSessionConfiguration_t
{};
SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, GameServerSteamAPIActivated, SH_NOATTRIB, 0);
SH_DECL_HOOK0_void(IServerGameDLL, GameServerSteamAPIDeactivated, SH_NOATTRIB, 0);
SH_DECL_HOOK1_void(IServerGameDLL, ApplyGameSettings, SH_NOATTRIB, 0, KeyValues*);
SH_DECL_HOOK4_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, CPlayerSlot, bool, const char*, uint64);
SH_DECL_HOOK5_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, CPlayerSlot, ENetworkDisconnectionReason, const char*, uint64, const char*);
SH_DECL_HOOK4_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, CPlayerSlot, char const*, int, uint64);
SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, CPlayerSlot);
SH_DECL_HOOK6_void(IServerGameClients, OnClientConnected, SH_NOATTRIB, 0, CPlayerSlot, const char*, uint64, const char*, const char*, bool);
SH_DECL_HOOK6(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, CPlayerSlot, const char*, uint64, const char*, bool, CBufferString*);
SH_DECL_HOOK8_void(IGameEventSystem, PostEventAbstract, SH_NOATTRIB, 0, CSplitScreenSlot, bool, int, const uint64*,
INetworkMessageInternal*, const CNetMessage*, unsigned long, NetChannelBufType_t)
SH_DECL_HOOK3_void(INetworkServerService, StartupServer, SH_NOATTRIB, 0, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);
SH_DECL_HOOK7_void(ISource2GameEntities, CheckTransmit, SH_NOATTRIB, 0, CCheckTransmitInfo**, int, CBitVec<16384>&, CBitVec<16384>&, const Entity2Networkable_t**, const uint16*, int);
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlot, const CCommand&);
SH_DECL_HOOK3_void(ICvar, DispatchConCommand, SH_NOATTRIB, 0, ConCommandRef, const CCommandContext&, const CCommand&);
SH_DECL_MANUALHOOK1_void(CGamePlayerEquipUse, 0, 0, 0, InputData_t*);
SH_DECL_MANUALHOOK1_void(CGamePlayerEquipPrecache, 0, 0, 0, CEntityPrecacheContext*);
SH_DECL_MANUALHOOK1_void(CTriggerGravityPrecache, 0, 0, 0, CEntityPrecacheContext*);
SH_DECL_MANUALHOOK1_void(CTriggerGravityEndTouch, 0, 0, 0, CBaseEntity*);
SH_DECL_MANUALHOOK2_void(CreateWorkshopMapGroup, 0, 0, 0, const char*, const CUtlStringList&);
SH_DECL_MANUALHOOK1(OnTakeDamage_Alive, 0, 0, 0, bool, CTakeDamageResult*);
SH_DECL_MANUALHOOK1_void(CheckMovingGround, 0, 0, 0, double);
SH_DECL_HOOK2(IGameEventManager2, LoadEventsFromFile, SH_NOATTRIB, 0, int, const char*, bool);
SH_DECL_MANUALHOOK1_void(GoToIntermission, 0, 0, 0, bool);
SH_DECL_MANUALHOOK2_void(PhysicsTouchShuffle, 0, 0, 0, CUtlVector<TouchLinked_t>*, bool);
SH_DECL_MANUALHOOK3_void(DropWeapon, 0, 0, 0, CBasePlayerWeapon*, Vector*, Vector*);
SH_DECL_HOOK1_void(IServer, SetGameSpawnGroupMgr, SH_NOATTRIB, 0, IGameSpawnGroupMgr*);
CS2Fixes g_CS2Fixes;
IGameEventSystem* g_gameEventSystem = nullptr;
IGameEventManager2* g_gameEventManager = nullptr;
CGameEntitySystem* g_pEntitySystem = nullptr;
IVEngineServer2* g_pEngineServer2 = nullptr;
ISteamHTTP* g_http = nullptr;
CSteamGameServerAPIContext g_steamAPI;
CCSGameRules* g_pGameRules = nullptr; // Will be null between map end & new map startup, null check if necessary!
CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr = nullptr; // Will be null between map end & new map startup, null check if necessary!
int g_iCGamePlayerEquipUseId = -1;
int g_iCGamePlayerEquipPrecacheId = -1;
int g_iCTriggerGravityPrecacheId = -1;
int g_iCTriggerGravityEndTouchId = -1;
int g_iCreateWorkshopMapGroupId = -1;
int g_iOnTakeDamageAliveId = -1;
int g_iCheckMovingGroundId = -1;
int g_iLoadEventsFromFileId = -1;
int g_iGoToIntermissionId = -1;
int g_iPhysicsTouchShuffle = -1;
int g_iWeaponServiceDropWeaponId = -1;
int g_iSetGameSpawnGroupMgrId = -1;
double g_flUniversalTime = 0.0;
float g_flLastTickedTime = 0.0f;
bool g_bHasTicked = false;
CGameEntitySystem* GameEntitySystem()
{
static int offset = g_GameConfig->GetOffset("GameEntitySystem");
return *reinterpret_cast<CGameEntitySystem**>((uintptr_t)(g_pGameResourceServiceServer) + offset);
}
// Will return null between map end & new map startup, null check if necessary!
INetworkGameServer* GetNetworkGameServer()
{
return g_pNetworkServerService->GetIGameServer();
}
// Will return null between map end & new map startup, null check if necessary!
CGlobalVars* GetGlobals()
{
return g_pEngineServer2->GetServerGlobals();
}
PLUGIN_EXPOSE(CS2Fixes, g_CS2Fixes);
bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
GET_V_IFACE_CURRENT(GetEngineFactory, g_pEngineServer2, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameResourceServiceServer, IGameResourceService, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pSchemaSystem, ISchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2ServerConfig, ISource2ServerConfig, SOURCE2SERVERCONFIG_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameEntities, ISource2GameEntities, SOURCE2GAMEENTITIES_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameClients, IServerGameClients, SOURCE2GAMECLIENTS_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_gameEventSystem, IGameEventSystem, GAMEEVENTSYSTEM_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkMessages, INetworkMessages, NETWORKMESSAGES_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pGameTypes, IGameTypes, GAMETYPES_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetFileSystemFactory, g_pFullFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkStringTableServer, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
// Required to get the IMetamodListener events
g_SMAPI->AddListener(this, this);
Message("Starting plugin.\n");
CBufferStringGrowable<256> gamedirpath;
g_pEngineServer2->GetGameDir(gamedirpath);
std::string gamedirname = CGameConfig::GetDirectoryName(gamedirpath.Get());
const char* gamedataPath = "addons/cs2fixes/gamedata/cs2fixes.games.txt";
Message("Loading %s for game: %s\n", gamedataPath, gamedirname.c_str());
g_GameConfig = new CGameConfig(gamedirname, gamedataPath);
char conf_error[255] = "";
if (!g_GameConfig->Init(g_pFullFileSystem, conf_error, sizeof(conf_error)))
{
snprintf(error, maxlen, "Could not read %s: %s", g_GameConfig->GetPath().c_str(), conf_error);
Panic("%s\n", error);
return false;
}
int offset = g_GameConfig->GetOffset("IGameTypes_CreateWorkshopMapGroup");
SH_MANUALHOOK_RECONFIGURE(CreateWorkshopMapGroup, offset, 0, 0);
SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameFramePost), true);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIActivated), false);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIDeactivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIDeactivated), false);
SH_ADD_HOOK(IServerGameDLL, ApplyGameSettings, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_ApplyGameSettings), false);
SH_ADD_HOOK(IServerGameClients, ClientActive, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientActive), true);
SH_ADD_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientDisconnect), true);
SH_ADD_HOOK(IServerGameClients, ClientPutInServer, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientPutInServer), true);
SH_ADD_HOOK(IServerGameClients, ClientSettingsChanged, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientSettingsChanged), false);
SH_ADD_HOOK(IServerGameClients, OnClientConnected, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_OnClientConnected), false);
SH_ADD_HOOK(IServerGameClients, ClientConnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientConnect), false);
SH_ADD_HOOK(IServerGameClients, ClientCommand, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientCommand), false);
SH_ADD_HOOK(IGameEventSystem, PostEventAbstract, g_gameEventSystem, SH_MEMBER(this, &CS2Fixes::Hook_PostEvent), false);
SH_ADD_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &CS2Fixes::Hook_StartupServer), true);
SH_ADD_HOOK(ISource2GameEntities, CheckTransmit, g_pSource2GameEntities, SH_MEMBER(this, &CS2Fixes::Hook_CheckTransmit), true);
SH_ADD_HOOK(ICvar, DispatchConCommand, g_pCVar, SH_MEMBER(this, &CS2Fixes::Hook_DispatchConCommand), false);
g_iCreateWorkshopMapGroupId = SH_ADD_MANUALVPHOOK(CreateWorkshopMapGroup, g_pGameTypes, SH_MEMBER(this, &CS2Fixes::Hook_CreateWorkshopMapGroup), false);
META_CONPRINTF("All hooks started!\n");
bool bRequiredInitLoaded = true;
if (!addresses::Initialize(g_GameConfig))
bRequiredInitLoaded = false;
if (!InitPatches(g_GameConfig))
bRequiredInitLoaded = false;
if (!InitDetours(g_GameConfig))
bRequiredInitLoaded = false;
if (!InitGameSystems())
bRequiredInitLoaded = false;
const auto pCGamePlayerEquipVTable = modules::server->FindVirtualTable("CGamePlayerEquip");
if (!pCGamePlayerEquipVTable)
{
snprintf(error, maxlen, "Failed to find CGamePlayerEquip vtable\n");
bRequiredInitLoaded = false;
}
offset = g_GameConfig->GetOffset("CBaseEntity::Use");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CBaseEntity::Use\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(CGamePlayerEquipUse, offset, 0, 0);
g_iCGamePlayerEquipUseId = SH_ADD_MANUALDVPHOOK(CGamePlayerEquipUse, pCGamePlayerEquipVTable, SH_MEMBER(this, &CS2Fixes::Hook_CGamePlayerEquipUse), false);
offset = g_GameConfig->GetOffset("CBaseEntity::Precache");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CBaseEntity::Precache\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(CGamePlayerEquipPrecache, offset, 0, 0);
g_iCGamePlayerEquipPrecacheId = SH_ADD_MANUALDVPHOOK(CGamePlayerEquipPrecache, pCGamePlayerEquipVTable, SH_MEMBER(this, &CS2Fixes::Hook_CGamePlayerEquipPrecache), true);
const auto pTriggerGravityVTable = modules::server->FindVirtualTable("CTriggerGravity");
if (!pTriggerGravityVTable)
{
snprintf(error, maxlen, "Failed to find TriggerGravity vtable\n");
bRequiredInitLoaded = false;
}
offset = g_GameConfig->GetOffset("CBaseEntity::Precache");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CBaseEntity::Precache\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(CTriggerGravityPrecache, offset, 0, 0);
g_iCTriggerGravityPrecacheId = SH_ADD_MANUALDVPHOOK(CTriggerGravityPrecache, pTriggerGravityVTable, SH_MEMBER(this, &CS2Fixes::Hook_CTriggerGravityPrecache), true);
offset = g_GameConfig->GetOffset("CBaseEntity::EndTouch");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CBaseEntity::EndTouch\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(CTriggerGravityEndTouch, offset, 0, 0);
g_iCTriggerGravityEndTouchId = SH_ADD_MANUALDVPHOOK(CTriggerGravityEndTouch, pTriggerGravityVTable, SH_MEMBER(this, &CS2Fixes::Hook_CTriggerGravityEndTouch), true);
const auto pCCSPlayerPawnVTable = modules::server->FindVirtualTable("CCSPlayerPawn");
if (!pCCSPlayerPawnVTable)
{
snprintf(error, maxlen, "Failed to find CCSPlayerPawn vtable\n");
bRequiredInitLoaded = false;
}
offset = g_GameConfig->GetOffset("CCSPlayerPawn::OnTakeDamage_Alive");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CCSPlayerPawn::OnTakeDamage_Alive\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(OnTakeDamage_Alive, offset, 0, 0);
g_iOnTakeDamageAliveId = SH_ADD_MANUALDVPHOOK(OnTakeDamage_Alive, pCCSPlayerPawnVTable, SH_MEMBER(this, &CS2Fixes::Hook_OnTakeDamage_Alive), false);
const auto pCCSPlayer_MovementServicesVTable = modules::server->FindVirtualTable("CCSPlayer_MovementServices");
offset = g_GameConfig->GetOffset("CCSPlayer_MovementServices::CheckMovingGround");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CCSPlayer_MovementServices::CheckMovingGround\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(CheckMovingGround, offset, 0, 0);
g_iCheckMovingGroundId = SH_ADD_MANUALDVPHOOK(CheckMovingGround, pCCSPlayer_MovementServicesVTable, SH_MEMBER(this, &CS2Fixes::Hook_CheckMovingGround), false);
auto pCVPhys2WorldVTable = modules::vphysics2->FindVirtualTable("CVPhys2World");
offset = g_GameConfig->GetOffset("CVPhys2World::GetTouchingList");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CVPhys2World::GetTouchingList\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(PhysicsTouchShuffle, offset, 0, 0);
g_iPhysicsTouchShuffle = SH_ADD_MANUALDVPHOOK(PhysicsTouchShuffle, pCVPhys2WorldVTable, SH_MEMBER(this, &CS2Fixes::Hook_PhysicsTouchShuffle), true);
const auto pCCSPlayer_WeaponServicesVTable = modules::server->FindVirtualTable("CCSPlayer_WeaponServices");
offset = g_GameConfig->GetOffset("CCSPlayer_WeaponServices::DropWeapon");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CCSPlayer_WeaponServices::DropWeapon\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(DropWeapon, offset, 0, 0);
g_iWeaponServiceDropWeaponId = SH_ADD_MANUALDVPHOOK(DropWeapon, pCCSPlayer_WeaponServicesVTable, SH_MEMBER(this, &CS2Fixes::Hook_DropWeaponPost), true);
auto pCGameEventManagerVTable = (IGameEventManager2*)modules::server->FindVirtualTable("CGameEventManager");
g_iLoadEventsFromFileId = SH_ADD_DVPHOOK(IGameEventManager2, LoadEventsFromFile, pCGameEventManagerVTable, SH_MEMBER(this, &CS2Fixes::Hook_LoadEventsFromFile), false);
if (!bRequiredInitLoaded)
{
snprintf(error, maxlen, "One or more address lookups, patches or detours failed, please refer to startup logs for more information");
return false;
}
auto pCCSGameRulesVTable = modules::server->FindVirtualTable("CCSGameRules");
offset = g_GameConfig->GetOffset("CCSGameRules_GoToIntermission");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CCSGameRules::GoToIntermission\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(GoToIntermission, offset, 0, 0);
g_iGoToIntermissionId = SH_ADD_MANUALDVPHOOK(GoToIntermission, pCCSGameRulesVTable, SH_MEMBER(this, &CS2Fixes::Hook_GoToIntermission), false);
Message("All hooks started!\n");
UnlockConVars();
UnlockConCommands();
META_CONVAR_REGISTER(FCVAR_RELEASE | FCVAR_GAMEDLL);
g_pAdminSystem = new CAdminSystem();
g_playerManager = new CPlayerManager();
g_pDiscordBotManager = new CDiscordBotManager();
g_pMapVoteSystem = new CMapVoteSystem();
g_pVoteManager = new CVoteManager();
g_pUserPreferencesSystem = new CUserPreferencesSystem();
g_pUserPreferencesStorage = new CUserPreferencesREST();
g_pZRPlayerClassManager = new CZRPlayerClassManager();
g_pZRWeaponConfig = new ZRWeaponConfig();
g_pZRHitgroupConfig = new ZRHitgroupConfig();
g_pEntityListener = new CEntityListener();
g_pIdleSystem = new CIdleSystem();
g_pPanoramaVoteHandler = new CPanoramaVoteHandler();
g_pEWHandler = new CEWHandler();
RegisterWeaponCommands();
// Check hide distance
CTimer::Create(0.5f, TIMERFLAG_NONE, []() {
g_playerManager->CheckHideDistances();
return 0.5f;
});
// Check for the expiration of infractions like mutes or gags
CTimer::Create(30.0f, TIMERFLAG_NONE, []() {
g_playerManager->CheckInfractions();
return 30.0f;
});
// Check for idle players and kick them if permitted by cs2f_idle_kick_* 'convars'
CTimer::Create(5.0f, TIMERFLAG_NONE, []() {
g_pIdleSystem->CheckForIdleClients();
return 5.0f;
});
// run our cfg
g_pEngineServer2->ServerCommand("exec cs2fixes/cs2fixes");
srand(time(0));
if (late)
{
RegisterEventListeners();
g_pEntitySystem = GameEntitySystem();
g_pEntitySystem->AddListenerEntity(g_pEntityListener);
g_playerManager->OnLateLoad();
g_pPanoramaVoteHandler->Reset();
g_pVoteManager->VoteManager_Init();
g_pIdleSystem->Reset();
g_steamAPI.Init();
g_http = g_steamAPI.SteamHTTP();
g_playerManager->OnSteamAPIActivated();
if (g_cvarVoteManagerEnable.Get() && !g_pMapVoteSystem->IsMapListLoaded())
g_pMapVoteSystem->LoadMapList();
Message("Plugin late load finished\n");
}
Message("Plugin successfully started!\n");
return true;
}
bool CS2Fixes::Unload(char* error, size_t maxlen)
{
SH_REMOVE_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameFramePost), true);
SH_REMOVE_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIActivated), false);
SH_REMOVE_HOOK(IServerGameDLL, GameServerSteamAPIDeactivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIDeactivated), false);
SH_REMOVE_HOOK(IServerGameDLL, ApplyGameSettings, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_ApplyGameSettings), false);
SH_REMOVE_HOOK(IServerGameClients, ClientActive, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientActive), true);
SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientDisconnect), true);
SH_REMOVE_HOOK(IServerGameClients, ClientPutInServer, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientPutInServer), true);
SH_REMOVE_HOOK(IServerGameClients, ClientSettingsChanged, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientSettingsChanged), false);
SH_REMOVE_HOOK(IServerGameClients, OnClientConnected, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_OnClientConnected), false);
SH_REMOVE_HOOK(IServerGameClients, ClientConnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientConnect), false);
SH_REMOVE_HOOK(IServerGameClients, ClientCommand, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientCommand), false);
SH_REMOVE_HOOK(IGameEventSystem, PostEventAbstract, g_gameEventSystem, SH_MEMBER(this, &CS2Fixes::Hook_PostEvent), false);
SH_REMOVE_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &CS2Fixes::Hook_StartupServer), true);
SH_REMOVE_HOOK(ISource2GameEntities, CheckTransmit, g_pSource2GameEntities, SH_MEMBER(this, &CS2Fixes::Hook_CheckTransmit), true);
SH_REMOVE_HOOK(ICvar, DispatchConCommand, g_pCVar, SH_MEMBER(this, &CS2Fixes::Hook_DispatchConCommand), false);
SH_REMOVE_HOOK_ID(g_iLoadEventsFromFileId);
SH_REMOVE_HOOK_ID(g_iCreateWorkshopMapGroupId);
SH_REMOVE_HOOK_ID(g_iOnTakeDamageAliveId);
SH_REMOVE_HOOK_ID(g_iCheckMovingGroundId);
SH_REMOVE_HOOK_ID(g_iPhysicsTouchShuffle);
SH_REMOVE_HOOK_ID(g_iWeaponServiceDropWeaponId);
SH_REMOVE_HOOK_ID(g_iGoToIntermissionId);
SH_REMOVE_HOOK_ID(g_iCGamePlayerEquipUseId);
SH_REMOVE_HOOK_ID(g_iCGamePlayerEquipPrecacheId);
SH_REMOVE_HOOK_ID(g_iCTriggerGravityPrecacheId);
SH_REMOVE_HOOK_ID(g_iCTriggerGravityEndTouchId);
if (g_iSetGameSpawnGroupMgrId != -1)
SH_REMOVE_HOOK_ID(g_iSetGameSpawnGroupMgrId);
ConVar_Unregister();
UnregisterGameSystem();
CommandList().clear();
FlushAllDetours();
UndoPatches();
RemoveAllTimers();
UnregisterEventListeners();
if (g_GameConfig)
delete g_GameConfig;
if (g_pAdminSystem)
delete g_pAdminSystem;
if (g_playerManager)
delete g_playerManager;
if (g_pDiscordBotManager)
delete g_pDiscordBotManager;
if (g_pMapVoteSystem)
delete g_pMapVoteSystem;
if (g_pVoteManager)
delete g_pVoteManager;
if (g_pUserPreferencesSystem)
delete g_pUserPreferencesSystem;
if (g_pUserPreferencesStorage)
delete g_pUserPreferencesStorage;
if (g_pZRPlayerClassManager)
delete g_pZRPlayerClassManager;
if (g_pZRWeaponConfig)
delete g_pZRWeaponConfig;
if (g_pZRHitgroupConfig)
delete g_pZRHitgroupConfig;
if (g_pEntitySystem && g_pEntityListener)
{
g_pEntitySystem->RemoveListenerEntity(g_pEntityListener);
delete g_pEntityListener;
}
if (g_pIdleSystem)
delete g_pIdleSystem;
if (g_pPanoramaVoteHandler)
delete g_pPanoramaVoteHandler;
if (g_pEWHandler)
{
g_pEWHandler->RemoveAllUseHooks();
g_pEWHandler->RemoveAllTriggers();
delete g_pEWHandler;
}
return true;
}
void CS2Fixes::Hook_DispatchConCommand(ConCommandRef cmdHandle, const CCommandContext& ctx, const CCommand& args)
{
VPROF_BUDGET("CS2Fixes::Hook_DispatchConCommand", "ConCommands");
if (!g_pEntitySystem)
RETURN_META(MRES_IGNORED);
auto iCommandPlayerSlot = ctx.GetPlayerSlot();
if (!g_cvarEnableCommands.Get())
RETURN_META(MRES_IGNORED);
bool bSay = !V_strcmp(args.Arg(0), "say");
bool bTeamSay = !V_strcmp(args.Arg(0), "say_team");
if (iCommandPlayerSlot != -1 && (bSay || bTeamSay))
{
auto pController = CCSPlayerController::FromSlot(iCommandPlayerSlot);
bool bGagged = pController && pController->GetZEPlayer()->IsGagged();
bool bFlooding = pController && pController->GetZEPlayer()->IsFlooding();
bool bIsAdmin = pController && pController->GetZEPlayer()->IsAdminFlagSet(ADMFLAG_GENERIC);
bool bAdminChat = bTeamSay && *args[1] == '@';
bool bSilent = *args[1] == '/' || bAdminChat;
bool bCommand = *args[1] == '!' || *args[1] == '/';
// Chat messages should generate events regardless
if (pController)
{
IGameEvent* pEvent = g_gameEventManager->CreateEvent("player_chat");
if (pEvent)
{
pEvent->SetBool("teamonly", bTeamSay);
pEvent->SetInt("userid", pController->GetPlayerSlot());
pEvent->SetString("text", args[1]);
g_gameEventManager->FireEvent(pEvent, true);
}
}
if (!bGagged && !bSilent && !bFlooding)
{
SH_CALL(g_pCVar, &ICvar::DispatchConCommand)
(cmdHandle, ctx, args);
}
else if (bFlooding)
{
if (pController)
ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "You are flooding the server!");
}
else if (bAdminChat && GetGlobals()) // Admin chat can be sent by anyone but only seen by admins, use flood protection here too
{
// HACK: At this point, we can safely modify the arg buffer as it won't be passed anywhere else
// The string here is originally ("@foo bar"), trim it to be (foo bar)
char* pszMessage = (char*)(args.ArgS() + 2);
pszMessage[V_strlen(pszMessage) - 1] = 0;
for (int i = 0; i < GetGlobals()->maxClients; i++)
{
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);
if (!pPlayer)
continue;
if (i == iCommandPlayerSlot.Get() || pPlayer->IsAdminFlagSet(ADMFLAG_GENERIC))
ClientPrint(CCSPlayerController::FromSlot(i), HUD_PRINTTALK, " \4(%sADMINS) %s:\6 %s", bIsAdmin ? "" : "TO ", pController->GetPlayerName(), pszMessage);
}
}
// Finally, run the chat command if it is one, so anything will print after the player's message
if (bCommand)
{
char* pszMessage = (char*)(args.ArgS() + 1);
if (pszMessage[0] == '"' || pszMessage[0] == '!' || pszMessage[0] == '/')
pszMessage += 1;
// Host_Say at some point removes the trailing " for whatever reason, so we only remove if it was never called
if ((bGagged || bSilent || bFlooding) && pszMessage[V_strlen(pszMessage) - 1] == '"')
pszMessage[V_strlen(pszMessage) - 1] = '\0';
ParseChatCommand(pszMessage, pController);
}
RETURN_META(MRES_SUPERCEDE);
}
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession* pSession, const char* pszMapName)
{
g_pEntitySystem = GameEntitySystem();
g_pEntitySystem->AddListenerEntity(g_pEntityListener);
if (g_pNetworkServerService->GetIGameServer())
g_iSetGameSpawnGroupMgrId = SH_ADD_HOOK(IServer, SetGameSpawnGroupMgr, g_pNetworkServerService->GetIGameServer(), SH_MEMBER(this, &CS2Fixes::Hook_SetGameSpawnGroupMgr), false);
Message("Hook_StartupServer: %s\n", pszMapName);
RegisterEventListeners();
if (g_bHasTicked)
RemoveTimers(TIMERFLAG_MAP);
g_bHasTicked = false;
g_pPanoramaVoteHandler->Reset();
g_pVoteManager->VoteManager_Init();
g_pIdleSystem->Reset();
}
class CGamePlayerEquip;
void CS2Fixes::Hook_CGamePlayerEquipUse(InputData_t* pInput)
{
CGamePlayerEquipHandler::Use(META_IFACEPTR(CGamePlayerEquip), pInput);
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_CGamePlayerEquipPrecache(CEntityPrecacheContext* param)
{
const auto kv = param->m_pKeyValues;
CGamePlayerEquipHandler::OnPrecache(META_IFACEPTR(CGamePlayerEquip), kv);
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_CTriggerGravityPrecache(CEntityPrecacheContext* param)
{
const auto kv = param->m_pKeyValues;
CTriggerGravityHandler::OnPrecache(META_IFACEPTR(CBaseEntity), kv);
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_CTriggerGravityEndTouch(CBaseEntity* pOther)
{
CTriggerGravityHandler::OnEndTouch(META_IFACEPTR(CBaseEntity), pOther);
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_GameServerSteamAPIActivated()
{
g_steamAPI.Init();
g_http = g_steamAPI.SteamHTTP();
g_playerManager->OnSteamAPIActivated();
if (g_cvarVoteManagerEnable.Get() && !g_pMapVoteSystem->IsMapListLoaded())
g_pMapVoteSystem->LoadMapList();
RETURN_META(MRES_IGNORED);
}
void CS2Fixes::Hook_GameServerSteamAPIDeactivated()
{
g_http = nullptr;
RETURN_META(MRES_IGNORED);
}
uint32 GetSoundEventHash(const char* pszSoundEventName)
{
return MurmurHash2LowerCase(pszSoundEventName, 0x53524332);
}
void CS2Fixes::Hook_PostEvent(CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients,
INetworkMessageInternal* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType)
{
// Message( "Hook_PostEvent(%d, %d, %d, %lli)\n", nSlot, bLocalOnly, nClientCount, clients );
// Need to explicitly get a pointer to the right function as it's overloaded and SH_CALL can't resolve that
static void (IGameEventSystem::*PostEventAbstract)(CSplitScreenSlot, bool, int, const uint64*,
INetworkMessageInternal*, const CNetMessage*, unsigned long, NetChannelBufType_t) = &IGameEventSystem::PostEventAbstract;
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (g_cvarEnableStopSound.Get() && info->m_MessageId == GE_FireBulletsId)
{
if (g_playerManager->GetSilenceSoundMask())
{
// Post the silenced sound to those who use silencesound
// Creating a new event object requires us to include the protobuf c files which I didn't feel like doing yet
// So instead just edit the event in place and reset later
auto msg = const_cast<CNetMessage*>(pData)->ToPB<CMsgTEFireBullets>();
int32_t weapon_id = msg->weapon_id();
int32_t sound_type = msg->sound_type();
int32_t item_def_index = msg->item_def_index();
// original weapon_id will override new settings if not removed
msg->set_weapon_id(0);
msg->set_sound_type(9);
msg->set_item_def_index(61); // weapon_usp_silencer
uint64 clientMask = *(uint64*)clients & g_playerManager->GetSilenceSoundMask();
SH_CALL(g_gameEventSystem, PostEventAbstract)
(nSlot, bLocalOnly, nClientCount, &clientMask, pEvent, msg, nSize, bufType);
msg->set_weapon_id(weapon_id);
msg->set_sound_type(sound_type);
msg->set_item_def_index(item_def_index);
}
// Filter out people using stop/silence sound from the original event
*(uint64*)clients &= ~g_playerManager->GetStopSoundMask();
*(uint64*)clients &= ~g_playerManager->GetSilenceSoundMask();
}
else if (info->m_MessageId == TE_WorldDecalId)
{
*(uint64*)clients &= ~g_playerManager->GetStopDecalsMask();
}
else if (info->m_MessageId == GE_Source1LegacyGameEvent)
{
if (g_cvarEnableLeader.Get())
Leader_PostEventAbstract_Source1LegacyGameEvent(clients, pData);
}
else if (info->m_MessageId == UM_Shake)
{
auto pPBData = const_cast<CNetMessage*>(pData)->ToPB<CUserMessageShake>();
if (g_cvarMaxShakeAmp.Get() >= 0 && pPBData->amplitude() > g_cvarMaxShakeAmp.Get())
pPBData->set_amplitude(g_cvarMaxShakeAmp.Get());
// remove client with noshake from the event
if (g_cvarEnableNoShake.Get())
*(uint64*)clients &= ~g_playerManager->GetNoShakeMask();
}
else if (g_cvarEnableStopSound.Get() && info->m_MessageId == GE_SosStartSoundEvent)
{
static std::set<uint32> soundEventHashes;
auto msg = const_cast<CNetMessage*>(pData)->ToPB<CMsgSosStartSoundEvent>();
ExecuteOnce(
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.HitWall"));
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Slash"));
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Hit"));
soundEventHashes.insert(GetSoundEventHash("Weapon_Knife.Stab"));
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomIn"));
soundEventHashes.insert(GetSoundEventHash("Weapon_sg556.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomIn"));
soundEventHashes.insert(GetSoundEventHash("Weapon_AUG.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.Zoom"));
soundEventHashes.insert(GetSoundEventHash("Weapon_SSG08.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.Zoom"));
soundEventHashes.insert(GetSoundEventHash("Weapon_SCAR20.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.Zoom"));
soundEventHashes.insert(GetSoundEventHash("Weapon_G3SG1.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.Zoom"));
soundEventHashes.insert(GetSoundEventHash("Weapon_AWP.ZoomOut"));
soundEventHashes.insert(GetSoundEventHash("Weapon_Revolver.Prepare"));
soundEventHashes.insert(GetSoundEventHash("Weapon.AutoSemiAutoSwitch")););
if (!soundEventHashes.contains(msg->soundevent_hash()))
return;
uint64 stopSoundMask = g_playerManager->GetStopSoundMask();
uint64 silenceSoundMask = g_playerManager->GetSilenceSoundMask();
if (!msg->has_source_entity_index())
return;
CBaseEntity* pSourceEntity = (CBaseEntity*)g_pEntitySystem->GetEntityInstance(CEntityIndex(msg->source_entity_index()));
int playerSlot = -1;
if (!pSourceEntity)
return;
if (!V_strcasecmp(pSourceEntity->GetClassname(), "player"))
{
playerSlot = ((CCSPlayerPawn*)pSourceEntity)->GetController()->GetPlayerSlot();
}
else if (!V_strncasecmp(pSourceEntity->GetClassname(), "weapon_", 7))
{
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)pSourceEntity->m_hOwnerEntity().Get();
if (pPawn && pPawn->IsPawn())
playerSlot = pPawn->GetController()->GetPlayerSlot();
}
// Remove player who triggered this sound from masks
// Because some of these sounds never get played locally (Zoom's, Knife Hit/Stab)
if (playerSlot != -1 && g_playerManager->IsPlayerUsingStopSound(playerSlot))
stopSoundMask &= ~((uint64)1 << playerSlot);
if (playerSlot != -1 && g_playerManager->IsPlayerUsingSilenceSound(playerSlot))
silenceSoundMask &= ~((uint64)1 << playerSlot);
// Filter out people using stop/silence sound from hearing this sound from other players
*(uint64*)clients &= ~stopSoundMask;
*(uint64*)clients &= ~silenceSoundMask;
}
}
void CS2Fixes::AllPluginsLoaded()
{
/* This is where we'd do stuff that relies on the mod or other plugins
* being initialized (for example, cvars added and events registered).
*/
Message("AllPluginsLoaded\n");
}
CUtlVector<CServerSideClient*>* GetClientList()
{
if (!GetNetworkGameServer())
return nullptr;
static int offset = g_GameConfig->GetOffset("CNetworkGameServer_ClientList");
return (CUtlVector<CServerSideClient*>*)(&GetNetworkGameServer()[offset]);
}
CServerSideClient* GetClientBySlot(CPlayerSlot slot)
{
CUtlVector<CServerSideClient*>* pClients = GetClientList();
if (!pClients)
return nullptr;
return pClients->Element(slot.Get());
}
void FullUpdateAllClients()
{
auto pClients = GetClientList();
if (!pClients)
return;
FOR_EACH_VEC(*pClients, i)
(*pClients)[i]->ForceFullUpdate();
}
// Because sv_fullupdate doesn't work
CON_COMMAND_F(cs2f_fullupdate, "- Force a full update for all clients.", FCVAR_LINKED_CONCOMMAND | FCVAR_SPONLY)
{
FullUpdateAllClients();
}
void CS2Fixes::Hook_ClientActive(CPlayerSlot slot, bool bLoadGame, const char* pszName, uint64 xuid)
{
Message("Hook_ClientActive(%d, %d, \"%s\", %lli)\n", slot, bLoadGame, pszName, xuid);
}
void CS2Fixes::Hook_ClientCommand(CPlayerSlot slot, const CCommand& args)
{
#ifdef _DEBUG
Message("Hook_ClientCommand(%d, \"%s\")\n", slot, args.GetCommandString());
#endif
if (g_cvarIdleKickTime.Get() > 0.0f)
{
ZEPlayer* pPlayer = g_playerManager->GetPlayer(slot);
if (pPlayer)
pPlayer->UpdateLastInputTime();
}
if (g_cvarVoteManagerEnable.Get() && V_stricmp(args[0], "endmatch_votenextmap") == 0 && args.ArgC() == 2)
{
if (g_pMapVoteSystem->RegisterPlayerVote(slot, atoi(args[1])))
RETURN_META(MRES_HANDLED);
else
RETURN_META(MRES_SUPERCEDE);
}
if (g_cvarEnableZR.Get() && slot != -1 && !V_strncmp(args.Arg(0), "jointeam", 8))
{
ZR_Hook_ClientCommand_JoinTeam(slot, args);
RETURN_META(MRES_SUPERCEDE);
}
}
void CS2Fixes::Hook_ClientSettingsChanged(CPlayerSlot slot)
{
#ifdef _DEBUG
Message("Hook_ClientSettingsChanged(%d)\n", slot);
#endif
}
void CS2Fixes::Hook_OnClientConnected(CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer)
{
Message("Hook_OnClientConnected(%d, \"%s\", %lli, \"%s\", \"%s\", %d)\n", slot, pszName, xuid, pszNetworkID, pszAddress, bFakePlayer);
static ConVarRefAbstract tv_name("tv_name");
const char* pszTvName = tv_name.GetString().Get();
// Ideally we would use CServerSideClient::IsHLTV().. but it doesn't work :(
if (bFakePlayer && V_strcmp(pszName, pszTvName))
g_playerManager->OnBotConnected(slot);
}
bool CS2Fixes::Hook_ClientConnect(CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason)
{
Message("Hook_ClientConnect(%d, \"%s\", %lli, \"%s\", %d, \"%s\")\n", slot, pszName, xuid, pszNetworkID, unk1, pRejectReason->Get());
// Player is banned
if (!g_playerManager->OnClientConnected(slot, xuid, pszNetworkID))
RETURN_META_VALUE(MRES_SUPERCEDE, false);
RETURN_META_VALUE(MRES_IGNORED, true);
}
void CS2Fixes::Hook_ClientPutInServer(CPlayerSlot slot, char const* pszName, int type, uint64 xuid)
{
Message("Hook_ClientPutInServer(%d, \"%s\", %d, %d, %lli)\n", slot, pszName, type, xuid);
if (!g_playerManager->GetPlayer(slot))
return;
g_playerManager->OnClientPutInServer(slot);
if (g_cvarEnableZR.Get())
ZR_Hook_ClientPutInServer(slot, pszName, type, xuid);
}
void CS2Fixes::Hook_ClientDisconnect(CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID)
{
Message("Hook_ClientDisconnect(%d, %d, \"%s\", %lli)\n", slot, reason, pszName, xuid);
CCSPlayerController* player = CCSPlayerController::FromSlot(slot);
if (g_cvarEnableZR.Get())
{
if (player)
ZR_CheckTeamWinConditions(player->m_iTeamNum == CS_TEAM_T ? CS_TEAM_CT : CS_TEAM_T);
else if (!ZR_CheckTeamWinConditions(CS_TEAM_T)) // If we cant get team num, just check both
ZR_CheckTeamWinConditions(CS_TEAM_CT);
}
ZEPlayer* pPlayer = g_playerManager->GetPlayer(slot);
if (!pPlayer)
return;
// Dont add to c_listdc clients that are downloading MultiAddonManager stuff or were present during a map change
if (reason != NETWORK_DISCONNECT_LOOPSHUTDOWN && reason != NETWORK_DISCONNECT_SHUTDOWN)
g_pAdminSystem->AddDisconnectedPlayer(pszName, xuid, pPlayer ? pPlayer->GetIpAddress() : "");
g_playerManager->OnClientDisconnect(slot);
}
void CS2Fixes::Hook_GameFramePost(bool simulating, bool bFirstTick, bool bLastTick)
{
/**
* simulating:
* ***********
* true | game is ticking
* false | game is not ticking
*/
VPROF_BUDGET("CS2Fixes::Hook_GameFramePost", "CS2FixesPerFrame");
if (!GetGlobals())
return;
if (simulating && g_bHasTicked)
g_flUniversalTime += GetGlobals()->curtime - g_flLastTickedTime;
g_flLastTickedTime = GetGlobals()->curtime;
g_bHasTicked = true;
RunTimers();
EntityHandler_OnGameFramePost(simulating, GetGlobals()->tickcount);
if (g_playerManager)
g_playerManager->CheckForLadderExits();
}