-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.cpp
More file actions
2375 lines (2113 loc) · 79.2 KB
/
utils.cpp
File metadata and controls
2375 lines (2113 loc) · 79.2 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
#include <stdio.h>
#include "utils.h"
#include "metamod_oslink.h"
#include "schemasystem/schemasystem.h"
#include <iostream>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <chrono>
#include <fstream>
Menus g_Menus;
PLUGIN_EXPOSE(Menus, g_Menus);
CGlobalVars* gpGlobals = nullptr;
IVEngineServer2* engine = nullptr;
CCSGameRules* g_pGameRules = nullptr;
CEntitySystem* g_pEntitySystem = nullptr;
CPhysicsQuery* g_pGameTraceManager = nullptr;
IGameEventSystem* g_gameEventSystem = nullptr;
IGameEventManager2* gameeventmanager = nullptr;
CGameEntitySystem* g_pGameEntitySystem = nullptr;
INetworkGameServer* g_pNetworkGameServer = nullptr;
float g_flUniversalTime;
float g_flLastTickedTime;
bool g_bHasTicked;
int g_iCommitSuicide = 0;
int g_iRemoveWeapons = 0;
int g_iChangeTeam = 0;
int g_iCollisionRulesChanged = 0;
int g_iTeleport = 0;
int g_iRespawn = 0;
int g_iDropWeapon = 0;
CGameEntitySystem* GameEntitySystem()
{
g_pGameEntitySystem = *reinterpret_cast<CGameEntitySystem**>(reinterpret_cast<uintptr_t>(g_pGameResourceServiceServer) + WIN_LINUX(0x58, 0x50));
return g_pGameEntitySystem;
}
KeyValues* g_hKVData;
int g_iMenuType[64];
int g_iMenuItem[64];
std::chrono::milliseconds g_iMenuLastButtonInput[64];
MenuPlayer g_MenuPlayer[64];
std::string g_TextMenuPlayer[64];
std::map<std::string, std::string> g_vecPhrases;
std::map<std::string, std::map<std::string, int>> g_Offsets;
std::map<std::string, std::map<std::string, int>> g_ChainOffsets;
MenusApi* g_pMenusApi = nullptr;
IMenusApi* g_pMenusCore = nullptr;
UtilsApi* g_pUtilsApi = nullptr;
IUtilsApi* g_pUtilsCore = nullptr;
PlayersApi* g_pPlayersApi = nullptr;
IPlayersApi* g_pPlayersCore = nullptr;
ICookiesApi* g_pCookies = nullptr;
char szLanguage[16];
int g_iMenuTypeDefault;
int g_iMenuTime;
int g_iDelayAuthFailKick;
bool g_bMenuAddon;
const char* g_szMenuURL;
bool g_bMenuFlashFix;
bool g_bAccessUserChangeType;
bool g_bStopingUser;
int g_iTimeoutMenu;
int g_iSoundType;
std::string g_szServerID;
std::map<std::string, std::string> g_mapSounds;
std::vector<std::string> g_vCommandEater;
int g_iOnTakeDamageAliveId = -1;
SH_DECL_HOOK0_void(IServerGameDLL, GameServerSteamAPIActivated, SH_NOATTRIB, 0);
SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool);
SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent*, bool);
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_HOOK3_void(INetworkServerService, StartupServer, SH_NOATTRIB, 0, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);
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_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_MANUALHOOK1(OnTakeDamage_Alive, 0, 0, 0, bool, CTakeDamageInfoContainer *);
struct SndOpEventGuid_t;
void (*UTIL_Remove)(CEntityInstance*) = nullptr;
int (*UTIL_TakeDamage)(CCSPlayer_DamageReactServices*, CTakeDamageInfo*) = nullptr;
bool (*UTIL_IsHearingClient)(void* serverClient, int index) = nullptr;
void (*UTIL_Say)(const CCommandContext& ctx, CCommand& args) = nullptr;
void (*UTIL_SetModel)(CBaseModelEntity*, const char* szModel) = nullptr;
void (*UTIL_DispatchSpawn)(CEntityInstance*, CEntityKeyValues*) = nullptr;
void (*UTIL_SayTeam)(const CCommandContext& ctx, CCommand& args) = nullptr;
void (*UTIL_SwitchTeam)(CCSPlayerController* pPlayer, int iTeam) = nullptr;
void (*UTIL_StopSoundEvent)(CBaseEntity *pEntity, const char *pszSound) = nullptr;
void (*UTIL_RespawnPlayer)(CBasePlayerController* pController, CCSPlayerPawn* pPawn, bool a3, bool a4, bool a5, bool a6) = nullptr;
IGameEventListener2* (*UTIL_GetLegacyGameEventListener)(CPlayerSlot slot) = nullptr;
CBaseEntity* (*UTIL_CreateEntity)(const char *pClassName, CEntityIndex iForceEdictIndex) = nullptr;
void (*UTIL_SetMoveType)(CBaseEntity *pThis, MoveType_t nMoveType, MoveCollide_t nMoveCollide) = nullptr;
SndOpEventGuid_t (*UTIL_EmitSoundFilter)(uint8_t unk1[32], IRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params);
void (*UTIL_AcceptInput)(CEntityInstance* pThis, const char* pInputName, CEntityInstance* pActivator, CEntityInstance* pCaller, const variant_t& pValue, int nOutputID, void* pUnk1) = nullptr;
bool (*UTIL_TraceShape)(CPhysicsQuery*, const Ray_t* ray, const Vector* start, const Vector* end, CTraceFilter* filter, trace_t* trace) = nullptr;
// void (*UTIL_ClientPrint)(CBasePlayerController*, int, const char *, const char *, const char *, const char *, const char *) = nullptr;
// void (*UTIL_ClientPrintAll)(int, const char *, const char *, const char *, const char *, const char *) = nullptr;
using namespace DynLibUtils;
funchook_t* m_SayHook;
funchook_t* m_SayTeamHook;
funchook_t* m_TakeDamageHook;
funchook_t* m_IsHearingClientHook;
bool containsOnlyDigits(const std::string& str) {
return str.find_first_not_of("0123456789") == std::string::npos;
}
void SayTeamHook(const CCommandContext& ctx, CCommand& args)
{
bool bCallback = true;
bCallback = g_pUtilsApi->SendChatListenerPreCallback(ctx.GetPlayerSlot().Get(), args.ArgS(), true);
if(args[1][0])
{
if(g_pEntitySystem)
{
auto pController = CCSPlayerController::FromSlot(ctx.GetPlayerSlot().Get());
if(bCallback && pController && pController->GetPawn() && pController->m_steamID() != 0 && g_MenuPlayer[ctx.GetPlayerSlot().Get()].bEnabled && containsOnlyDigits(std::string(args[1] + 1)))
bCallback = false;
}
}
bCallback = g_pUtilsApi->SendChatListenerPostCallback(ctx.GetPlayerSlot().Get(), args.ArgS(), bCallback, true);
if(bCallback)
{
UTIL_SayTeam(ctx, args);
}
}
void SayHook(const CCommandContext& ctx, CCommand& args)
{
bool bCallback = true;
bCallback = g_pUtilsApi->SendChatListenerPreCallback(ctx.GetPlayerSlot().Get(), args.ArgS(), false);
if(args[1][0])
{
if(g_pEntitySystem)
{
auto pController = CCSPlayerController::FromSlot(ctx.GetPlayerSlot().Get());
if(bCallback && pController && pController->GetPawn() && pController->m_steamID() != 0 && g_MenuPlayer[ctx.GetPlayerSlot().Get()].bEnabled && containsOnlyDigits(std::string(args[1] + 1)))
bCallback = false;
}
}
bCallback = g_pUtilsApi->SendChatListenerPostCallback(ctx.GetPlayerSlot().Get(), args.ArgS(), bCallback, false);
if(bCallback)
{
UTIL_Say(ctx, args);
}
}
int Hook_TakeDamage(CCSPlayer_DamageReactServices* pService, CTakeDamageInfo* info)
{
if (!pService || !info) return UTIL_TakeDamage(pService, info);
CCSPlayerPawn* pPawn = pService->GetPawn();
if (!pPawn) return UTIL_TakeDamage(pService, info);
auto pController = pPawn->m_hController();
if (!pController) return UTIL_TakeDamage(pService, info);
int iPlayerSlot = pController->GetEntityIndex().Get() - 1;
if (iPlayerSlot < 0 || iPlayerSlot >= 64) return UTIL_TakeDamage(pService, info);
if (!g_pUtilsApi->SendHookOnTakeDamagePre(iPlayerSlot, info)) return 1;
return UTIL_TakeDamage(pService, info);
}
std::string Colorizer(std::string str)
{
for (size_t i = 0; i < std::size(colors_hex); i++)
{
size_t pos = 0;
while ((pos = str.find(colors_text[i], pos)) != std::string::npos)
{
str.replace(pos, colors_text[i].length(), colors_hex[i]);
pos += colors_hex[i].length();
}
}
return str;
}
void* Menus::OnMetamodQuery(const char* iface, int* ret)
{
if (!strcmp(iface, Menus_INTERFACE))
{
*ret = META_IFACE_OK;
return g_pMenusCore;
}
if (!strcmp(iface, Utils_INTERFACE))
{
*ret = META_IFACE_OK;
return g_pUtilsCore;
}
if (!strcmp(iface, PLAYERS_INTERFACE))
{
*ret = META_IFACE_OK;
return g_pPlayersCore;
}
*ret = META_IFACE_FAILED;
return nullptr;
}
int CheckActionMenu(int iSlot, CCSPlayerController* pController, int iButton)
{
if(!pController) return 0;
if(iSlot < 0 || iSlot >= 64) return 0;
auto& hMenuPlayer = g_MenuPlayer[iSlot];
auto& hMenu = hMenuPlayer.hMenu;
if(hMenuPlayer.bEnabled)
{
hMenuPlayer.iEnd = std::time(0) + g_iMenuTime;
if(iButton == 9 && hMenu.bExit)
{
hMenuPlayer.iList = 0;
hMenuPlayer.bEnabled = false;
if(g_iMenuType[iSlot] == 0)
{
for (size_t i = 0; i < 8; i++)
{
g_pUtilsCore->PrintToChat(iSlot, " \x08-\x01");
}
}
if(hMenu.hFunc) hMenu.hFunc("exit", "exit", 9, iSlot);
hMenuPlayer.hMenu.clear();
}
else if(iButton == 8)
{
int iItems = size(hMenu.hItems) / 5;
if (size(hMenu.hItems) % 5 > 0) iItems++;
if(iItems > hMenuPlayer.iList+1)
{
hMenuPlayer.iList++;
g_pMenusCore->DisplayPlayerMenu(hMenu, iSlot, false, true);
if(hMenu.hFunc) hMenu.hFunc("next", "next", 8, iSlot);
}
}
else if(iButton == 7)
{
if(hMenuPlayer.iList != 0 || hMenuPlayer.hMenu.bBack)
{
if(hMenuPlayer.iList != 0)
{
hMenuPlayer.iList--;
g_pMenusCore->DisplayPlayerMenu(hMenu, iSlot, false, true);
}
else if(hMenu.hFunc) hMenu.hFunc("back", "back", 7, iSlot);
}
}
else
{
int iItems = size(hMenu.hItems);
int iItem = hMenuPlayer.iList*5+iButton-1;
if(iItems <= iItem) return 1;
if(hMenu.hItems.size() <= iItem) return 1;
if(hMenu.hItems[iItem].iType != 1) return 1;
if(hMenu.hFunc) hMenu.hFunc(hMenu.hItems[iItem].sBack.c_str(), hMenu.hItems[iItem].sText.c_str(), iButton, iSlot);
}
return 1;
}
return 0;
}
bool FASTCALL IsHearingClient(void* serverClient, int index)
{
return g_pUtilsApi->SendHookOnHearingClient(index)?UTIL_IsHearingClient(serverClient, index):false;
}
void Menus::AllPluginsLoaded() {
char error[64];
int ret;
g_pCookies = (ICookiesApi *)g_SMAPI->MetaFactory(COOKIES_INTERFACE, &ret, NULL);
if (ret == META_IFACE_FAILED)
{
g_pCookies = nullptr;
g_hKVData = new KeyValues("Data");
const char *pszPath = "addons/data/menus_data.ini";
if (!g_hKVData->LoadFromFile(g_pFullFileSystem, pszPath)) {
char szPath2[256];
g_SMAPI->Format(szPath2, sizeof(szPath2), "%s/%s", g_SMAPI->GetBaseDir(), pszPath);
std::fstream file;
file.open(szPath2, std::fstream::out | std::fstream::trunc);
file << "\"Data\"\n{\n\n}\n";
file.close();
}
return;
}
g_pCookies->HookClientCookieLoaded(g_PLID, [](int iSlot) {
const char* szMenuType = g_pCookies->GetCookie(iSlot, "Utils.MenuType");
if (szMenuType && szMenuType[0]) g_iMenuType[iSlot] = atoi(szMenuType);
else g_iMenuType[iSlot] = g_iMenuTypeDefault;
});
}
int GetClientCookieMenuType(int iSlot)
{
if(g_pPlayersApi->IsFakeClient(iSlot)) return g_iMenuTypeDefault;
uint64 m_steamID = g_pPlayersApi->GetSteamID64(iSlot);
if(m_steamID == 0) return g_iMenuTypeDefault;
char szSteamID[64];
g_SMAPI->Format(szSteamID, sizeof(szSteamID), "%llu", m_steamID);
KeyValues *hData = g_hKVData->FindKey(szSteamID, false);
if(!hData) return g_iMenuTypeDefault;
return hData->GetInt("Utils.MenuType", g_iMenuTypeDefault);
}
bool SetClientCookie(int iSlot, const char* sCookieName, const char* sData)
{
if(g_pPlayersApi->IsFakeClient(iSlot)) return false;
uint64 m_steamID = g_pPlayersApi->GetSteamID64(iSlot);
if(m_steamID == 0) return false;
char szSteamID[64];
g_SMAPI->Format(szSteamID, sizeof(szSteamID), "%llu", m_steamID);
KeyValues *hData = g_hKVData->FindKey(szSteamID, true);
hData->SetString(sCookieName, sData);
g_hKVData->SaveToFile(g_pFullFileSystem, "addons/data/menus_data.ini");
return true;
}
void SettingMenu(int iSlot)
{
Menu hMenu;
hMenu.szTitle = g_vecPhrases["MenuMenusTitle"];
g_pMenusCore->AddItemMenu(hMenu, "0", g_vecPhrases["MenuMenusItem0"].c_str(), g_iMenuType[iSlot] == 0 ? ITEM_DISABLED : ITEM_DEFAULT);
g_pMenusCore->AddItemMenu(hMenu, "1", g_vecPhrases["MenuMenusItem1"].c_str(), g_iMenuType[iSlot] == 1 ? ITEM_DISABLED : ITEM_DEFAULT);
g_pMenusCore->AddItemMenu(hMenu, "2", g_vecPhrases["MenuMenusItem2"].c_str(), g_iMenuType[iSlot] == 2 ? ITEM_DISABLED : ITEM_DEFAULT);
g_pMenusCore->SetExitMenu(hMenu, true);
g_pMenusCore->SetCallback(hMenu, [](const char* szBack, const char* szFront, int iItem, int iSlot){
if(iItem < 7) {
int iType = std::atoi(szBack);
g_iMenuType[iSlot] = iType;
if(g_pCookies) g_pCookies->SetCookie(iSlot, "Utils.MenuType", std::to_string(iType).c_str());
else SetClientCookie(iSlot, "Utils.MenuType", std::to_string(iType).c_str());
SettingMenu(iSlot);
}
});
g_pMenusCore->DisplayPlayerMenu(hMenu, iSlot, true, true);
}
bool Menus::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
g_SMAPI->AddListener( this, this );
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pSchemaSystem, ISchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, g_pFullFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_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(GetServerFactory, g_pSource2GameClients, IServerGameClients, SOURCE2GAMECLIENTS_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameResourceServiceServer, IGameResourceService, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
SH_ADD_HOOK_MEMFUNC(ICvar, DispatchConCommand, g_pCVar, this, &Menus::OnDispatchConCommand, false);
SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &Menus::GameFrame), true);
SH_ADD_HOOK(IServerGameClients, ClientCommand, g_pSource2GameClients, SH_MEMBER(this, &Menus::ClientCommand), false);
SH_ADD_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &Menus::StartupServer), true);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &Menus::OnGameServerSteamAPIActivated), false);
SH_ADD_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &Menus::OnClientDisconnect), true);
SH_ADD_HOOK(IServerGameClients, ClientPutInServer, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_ClientPutInServer), true);
SH_ADD_HOOK(IServerGameClients, OnClientConnected, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_OnClientConnected), false);
SH_ADD_HOOK(IServerGameClients, ClientConnect, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_ClientConnect), false );
ConVar_Register(FCVAR_RELEASE | FCVAR_CLIENT_CAN_EXECUTE | FCVAR_GAMEDLL);
if (late)
{
g_pEntitySystem = GameEntitySystem();
gpGlobals = engine->GetServerGlobals();
}
//0 - в чат
//1 - также как в чат но в центр
//2 - выбор через WASD
g_pMenusApi = new MenusApi();
g_pMenusCore = g_pMenusApi;
g_pUtilsApi = new UtilsApi();
g_pUtilsCore = g_pUtilsApi;
g_pPlayersApi = new PlayersApi();
g_pPlayersCore = g_pPlayersApi;
{
KeyValues* g_kvCore = new KeyValues("Core");
const char *pszPath = "addons/configs/core.cfg";
if (!g_kvCore->LoadFromFile(g_pFullFileSystem, pszPath))
{
g_pUtilsApi->ErrorLog("[%s] Failed to load %s\n", g_PLAPI->GetLogTag(), pszPath);
return false;
}
g_SMAPI->Format(szLanguage, sizeof(szLanguage), "%s", g_kvCore->GetString("ServerLang", "en"));
g_iMenuTypeDefault = g_kvCore->GetInt("MenuType", 0);
g_iMenuTime = g_kvCore->GetInt("MenuTime", 60);
g_bMenuAddon = g_kvCore->GetBool("MenuAddon", false);
g_szMenuURL = g_kvCore->GetString("MenuURL");
g_bMenuFlashFix = g_kvCore->GetBool("MenuFlashFix", false);
g_iDelayAuthFailKick = g_kvCore->GetInt("delay_auth_fail_kick", 30);
g_bAccessUserChangeType = g_kvCore->GetBool("AccessUserChangeType", true);
g_bStopingUser = g_kvCore->GetBool("StopingUser", false);
g_iTimeoutMenu = g_kvCore->GetInt("TimeoutInputMenu", 160);
g_iSoundType = g_kvCore->GetInt("sound_type", 0);
g_szServerID = g_kvCore->GetString("server_id", "0");
g_mapSounds.clear();
const char* szBackSound = g_kvCore->GetString("sound_back", "");
if(szBackSound && szBackSound[0]) g_mapSounds["back"] = szBackSound;
const char* szNextSound = g_kvCore->GetString("sound_next", "");
if(szNextSound && szNextSound[0]) g_mapSounds["next"] = szNextSound;
const char* szSelectSound = g_kvCore->GetString("sound_select", "");
if(szSelectSound && szSelectSound[0]) g_mapSounds["select"] = szSelectSound;
const char* szExitSound = g_kvCore->GetString("sound_exit", "");
if(szExitSound && szExitSound[0]) g_mapSounds["exit"] = szExitSound;
const char* szMoveSound = g_kvCore->GetString("sound_move", "");
if(szMoveSound && szMoveSound[0]) g_mapSounds["move"] = szMoveSound;
const char* szCommandEater = g_kvCore->GetString("commands_eater");
if(szCommandEater && szCommandEater[0])
{
std::string sCommandEater(szCommandEater);
std::istringstream ss(sCommandEater);
std::string token;
while(std::getline(ss, token, ','))
{
g_vCommandEater.push_back(token);
}
}
if(g_bAccessUserChangeType)
{
const char* g_szMenuChangeCommand = g_kvCore->GetString("MenuChangeCommand");
g_pUtilsApi->RegCommand(g_PLID, {}, {g_szMenuChangeCommand}, [](int iSlot, const char* szContent){
if(g_pPlayersApi->IsFakeClient(iSlot)) return false;
SettingMenu(iSlot);
return false;
});
}
}
g_pUtilsApi->LoadTranslations("menus.phrases");
KeyValues::AutoDelete g_kvSigs("Gamedata");
const char *pszPath = "addons/configs/signatures.ini";
if (!g_kvSigs->LoadFromFile(g_pFullFileSystem, pszPath))
{
g_pUtilsApi->ErrorLog("[%s] Failed to load %s\n", g_PLAPI->GetLogTag(), pszPath);
return false;
}
CModule libserver(g_pSource2Server);
const char* pszSay = g_kvSigs->GetString("UTIL_Say");
if(pszSay && pszSay[0]) {
UTIL_SayTeam = libserver.FindPattern(pszSay).RCast< decltype(UTIL_SayTeam) >();
if (!UTIL_SayTeam)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_Say", g_PLAPI->GetLogTag());
}
else
{
m_SayTeamHook = funchook_create();
funchook_prepare(m_SayTeamHook, (void**)&UTIL_SayTeam, (void*)SayTeamHook);
funchook_install(m_SayTeamHook, 0);
}
UTIL_Say = libserver.FindPattern(pszSay).RCast< decltype(UTIL_Say) >();
if (!UTIL_Say)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_Say", g_PLAPI->GetLogTag());
}
else
{
m_SayHook = funchook_create();
funchook_prepare(m_SayHook, (void**)&UTIL_Say, (void*)SayHook);
funchook_install(m_SayHook, 0);
}
}
// UTIL_ClientPrint = libserver.FindPattern("55 48 89 E5 41 57 41 56 41 55 41 54 53 48 83 EC 38 4C 89 45 A0").RCast< decltype(UTIL_ClientPrint) >();
// if(!UTIL_ClientPrint) g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_ClientPrint", g_PLAPI->GetLogTag());
// UTIL_ClientPrintAll = libserver.FindPattern("55 48 89 E5 41 57 4D 89 CF 41 56 4D 89 C6 41 55 49 89 CD 41 54 49 89 D4 53 48 8D 5D B0").RCast< decltype(UTIL_ClientPrintAll) >();
// if(!UTIL_ClientPrintAll) g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_ClientPrintAll", g_PLAPI->GetLogTag());
const char* pszTakeDamage = g_kvSigs->GetString("OnTakeDamagePre");
if(pszTakeDamage && pszTakeDamage[0]) {
UTIL_TakeDamage = libserver.FindPattern(pszTakeDamage).RCast< decltype(UTIL_TakeDamage) >();
if (!UTIL_TakeDamage)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_TakeDamage", g_PLAPI->GetLogTag());
}
else
{
m_TakeDamageHook = funchook_create();
funchook_prepare(m_TakeDamageHook, (void**)&UTIL_TakeDamage, (void*)Hook_TakeDamage);
funchook_install(m_TakeDamageHook, 0);
}
}
CModule libengine(engine);
const char* pszIsHearingClient = g_kvSigs->GetString("IsHearingClient");
if(pszIsHearingClient && pszIsHearingClient[0]) {
UTIL_IsHearingClient = libengine.FindPattern(g_kvSigs->GetString("IsHearingClient")).RCast< decltype(UTIL_IsHearingClient) >();
if (!UTIL_IsHearingClient)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get IsHearingClient", g_PLAPI->GetLogTag());
}
else
{
m_IsHearingClientHook = funchook_create();
funchook_prepare(m_IsHearingClientHook, (void**)&UTIL_IsHearingClient, (void*)IsHearingClient);
funchook_install(m_IsHearingClientHook, 0);
}
}
const char* pszSetModel = g_kvSigs->GetString("CBaseModelEntity_SetModel");
if(pszSetModel && pszSetModel[0]) {
UTIL_SetModel = libserver.FindPattern(pszSetModel).RCast< decltype(UTIL_SetModel) >();
if (!UTIL_SetModel)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get CBaseModelEntity_SetModel", g_PLAPI->GetLogTag());
}
}
const char* pszRespawnPlayer = g_kvSigs->GetString("UTIL_RespawnPlayer");
if(pszRespawnPlayer && pszRespawnPlayer[0]) {
UTIL_RespawnPlayer = libserver.FindPattern(pszRespawnPlayer).RCast< decltype(UTIL_RespawnPlayer) >();
if (!UTIL_RespawnPlayer)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_RespawnPlayer", g_PLAPI->GetLogTag());
}
}
const char* pszAcceptInput = g_kvSigs->GetString("UTIL_AcceptInput");
if(pszAcceptInput && pszAcceptInput[0]) {
UTIL_AcceptInput = libserver.FindPattern(pszAcceptInput).RCast< decltype(UTIL_AcceptInput) >();
if (!UTIL_AcceptInput)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_AcceptInput", g_PLAPI->GetLogTag());
}
}
const char* pszRemove = g_kvSigs->GetString("UTIL_Remove");
if(pszRemove && pszRemove[0]) {
UTIL_Remove = libserver.FindPattern(pszRemove).RCast< decltype(UTIL_Remove) >();
if (!UTIL_Remove)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_Remove", g_PLAPI->GetLogTag());
}
}
const char* pszDispatchSpawn = g_kvSigs->GetString("UTIL_DispatchSpawn");
if(pszDispatchSpawn && pszDispatchSpawn[0]) {
UTIL_DispatchSpawn = libserver.FindPattern(pszDispatchSpawn).RCast< decltype(UTIL_DispatchSpawn) >();
if (!UTIL_DispatchSpawn)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_DispatchSpawn", g_PLAPI->GetLogTag());
}
}
const char* pszCreateEntity = g_kvSigs->GetString("UTIL_CreateEntity");
if(pszCreateEntity && pszCreateEntity[0]) {
UTIL_CreateEntity = libserver.FindPattern(pszCreateEntity).RCast< decltype(UTIL_CreateEntity) >();
if (!UTIL_CreateEntity)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_CreateEntity", g_PLAPI->GetLogTag());
}
}
const char* pszGetLegacyGameEventListener = g_kvSigs->GetString("GetLegacyGameEventListener");
if(pszGetLegacyGameEventListener && pszGetLegacyGameEventListener[0]) {
UTIL_GetLegacyGameEventListener = libserver.FindPattern(pszGetLegacyGameEventListener).RCast< decltype(UTIL_GetLegacyGameEventListener) >();
if (!UTIL_GetLegacyGameEventListener)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get GetLegacyGameEventListener", g_PLAPI->GetLogTag());
}
}
const char* pszSwitchTeam = g_kvSigs->GetString("SwitchTeam");
if(pszSwitchTeam && pszSwitchTeam[0]) {
UTIL_SwitchTeam = libserver.FindPattern(pszSwitchTeam).RCast< decltype(UTIL_SwitchTeam) >();
if (!UTIL_SwitchTeam)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get SwitchTeam", g_PLAPI->GetLogTag());
}
}
const char* pszSetMoveType = g_kvSigs->GetString("SetMoveType");
if(pszSetMoveType && pszSetMoveType[0]) {
UTIL_SetMoveType = libserver.FindPattern(pszSetMoveType).RCast< decltype(UTIL_SetMoveType) >();
if (!UTIL_SetMoveType)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get SetMoveType", g_PLAPI->GetLogTag());
}
}
const char* pszEmitSoundFilter = g_kvSigs->GetString("EmitSoundFilter");
if(pszEmitSoundFilter && pszEmitSoundFilter[0]) {
UTIL_EmitSoundFilter = libserver.FindPattern(pszEmitSoundFilter).RCast< decltype(UTIL_EmitSoundFilter) >();
if (!UTIL_EmitSoundFilter)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_EmitSoundFilter", g_PLAPI->GetLogTag());
}
}
const char* pszStopSoundEvent = g_kvSigs->GetString("StopSoundEvent");
if(pszStopSoundEvent && pszStopSoundEvent[0]) {
UTIL_StopSoundEvent = libserver.FindPattern(pszStopSoundEvent).RCast< decltype(UTIL_StopSoundEvent) >();
if (!UTIL_StopSoundEvent)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get StopSoundEvent", g_PLAPI->GetLogTag());
}
}
g_iCommitSuicide = g_kvSigs->GetInt("CommitSuicide", 0);
g_iChangeTeam = g_kvSigs->GetInt("ChangeTeam", 0);
g_iCollisionRulesChanged = g_kvSigs->GetInt("CollisionRulesChanged", 0);
g_iTeleport = g_kvSigs->GetInt("Teleport", 0);
g_iRespawn = g_kvSigs->GetInt("Respawn", 0);
g_iDropWeapon = g_kvSigs->GetInt("DropWeapon", 0);
g_iRemoveWeapons = g_kvSigs->GetInt("RemoveWeapons", 0);
void* pCCSPlayerPawnVTable = libserver.GetVirtualTableByName("CCSPlayerPawn");
if (!pCCSPlayerPawnVTable)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find CCSPlayerPawn vtable", g_PLAPI->GetLogTag());
}
else
{
SH_MANUALHOOK_RECONFIGURE(OnTakeDamage_Alive, g_kvSigs->GetInt("OnTakeDamage_Alive"), 0, 0);
g_iOnTakeDamageAliveId = SH_ADD_MANUALDVPHOOK(OnTakeDamage_Alive, pCCSPlayerPawnVTable, SH_MEMBER(this, &Menus::Hook_OnTakeDamage_Alive), false);
}
const char* pszGameEventManager = g_kvSigs->GetString("GetGameEventManager");
if(pszGameEventManager && pszGameEventManager[0]) {
auto gameEventManagerFn = libserver.FindPattern(pszGameEventManager);
if( !gameEventManagerFn ) {
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get GetGameEventManager", g_PLAPI->GetLogTag());
}
else
{
gameeventmanager = gameEventManagerFn.ResolveRelativeAddress(0x3, 0x7).GetValue<IGameEventManager2*>();
SH_ADD_HOOK(IGameEventManager2, FireEvent, gameeventmanager, SH_MEMBER(this, &Menus::FireEvent), false);
}
}
const char* pszTraceShape = g_kvSigs->GetString("UTIL_TraceShape");
if(pszTraceShape && pszTraceShape[0]) {
UTIL_TraceShape = libserver.FindPattern(pszTraceShape).RCast< decltype(UTIL_TraceShape) >();
if (!UTIL_TraceShape)
{
g_pUtilsApi->ErrorLog("[%s] Failed to find function to get UTIL_TraceShape", g_PLAPI->GetLogTag());
}
}
const char* pszGameTraceManager = g_kvSigs->GetString("GetGameTraceManager");
if(pszGameTraceManager && pszGameTraceManager[0]) {
auto gameTraceManagerFn = libserver.FindPattern(pszGameTraceManager);
if( !gameTraceManagerFn ) g_pUtilsApi->ErrorLog("[%s] Failed to find function to get GetGameTraceManager", g_PLAPI->GetLogTag());
else g_pGameTraceManager = *gameTraceManagerFn.ResolveRelativeAddress(3, 7).RCast<CPhysicsQuery**>();
}
new CTimer(1.0f, []()
{
for(int i = 0; i < 64; i++)
{
if (!m_Players[i] || m_Players[i]->IsFakeClient() || m_Players[i]->IsAuthenticated())
continue;
if(engine->IsClientFullyAuthenticated(CPlayerSlot(i)))
{
m_Players[i]->SetAuthenticated(true);
m_Players[i]->SetSteamId(m_Players[i]->GetUnauthenticatedSteamId());
g_pPlayersApi->SendClientAuthCallback(i, m_Players[i]->GetUnauthenticatedSteamId64());
}
}
return 1.0f;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_1"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 1)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_2"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 2)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_3"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 3)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_4"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 4)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_5"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 5)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_6"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 6)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_7"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 7)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_8"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 8)) return true;
return false;
});
g_pUtilsApi->RegCommand(g_PLID, {"mm_9"}, {}, [](int iSlot, const char* szContent){
if(g_iMenuType[iSlot] != 2) if(CheckActionMenu(iSlot, CCSPlayerController::FromSlot(iSlot), 9)) return true;
return false;
});
return true;
}
void Menus::OnPluginUnload(PluginId id) {
g_pUtilsApi->ClearAllHooks(id);
}
bool Menus::Hook_OnTakeDamage_Alive(CTakeDamageInfoContainer *pInfoContainer)
{
CCSPlayerPawn *pPawn = META_IFACEPTR(CCSPlayerPawn);
if(!pPawn) RETURN_META_VALUE(MRES_IGNORED, true);
CBasePlayerController* pPlayerController = pPawn->m_hController();
if (pPlayerController)
{
int iPlayerSlot = pPlayerController->GetEntityIndex().Get() - 1;
g_pUtilsApi->SendHookOnTakeDamage(iPlayerSlot, pInfoContainer);
}
RETURN_META_VALUE(MRES_IGNORED, true);
}
bool Menus::Unload(char *error, size_t maxlen)
{
SH_REMOVE_HOOK_MEMFUNC(ICvar, DispatchConCommand, g_pCVar, this, &Menus::OnDispatchConCommand, false);
SH_REMOVE_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &Menus::GameFrame), true);
SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameeventmanager, SH_MEMBER(this, &Menus::FireEvent), false);
SH_REMOVE_HOOK(IServerGameClients, ClientCommand, g_pSource2GameClients, SH_MEMBER(this, &Menus::ClientCommand), false);
SH_REMOVE_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &Menus::StartupServer), true);
SH_REMOVE_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &Menus::OnGameServerSteamAPIActivated), false);
SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &Menus::OnClientDisconnect), true);
SH_REMOVE_HOOK(IServerGameClients, ClientPutInServer, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_ClientPutInServer), true);
SH_REMOVE_HOOK(IServerGameClients, OnClientConnected, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_OnClientConnected), false);
SH_REMOVE_HOOK(IServerGameClients, ClientConnect, g_pSource2GameClients, SH_MEMBER(this, &Menus::Hook_ClientConnect), false );
if(g_iOnTakeDamageAliveId) SH_REMOVE_HOOK_ID(g_iOnTakeDamageAliveId);
if(m_SayHook) funchook_destroy(m_SayHook);
if(m_SayTeamHook) funchook_destroy(m_SayTeamHook);
if(m_TakeDamageHook) funchook_destroy(m_TakeDamageHook);
ConVar_Unregister();
return true;
}
void Menus::OnGameServerSteamAPIActivated()
{
m_CallbackValidateAuthTicketResponse.Register(this, &Menus::OnValidateAuthTicketHook);
}
void Menus::Hook_OnClientConnected(CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer)
{
if(bFakePlayer)
m_Players[slot.Get()] = new Player(slot.Get(), true);
}
bool Menus::Hook_ClientConnect( CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, bool unk1, CBufferString *pRejectReason )
{
Player *pPlayer = new Player(slot.Get());
pPlayer->SetUnauthenticatedSteamId(new CSteamID(xuid));
std::string ip(pszNetworkID);
for (size_t i = 0; i < ip.length(); i++)
{
if (ip[i] == ':')
{
ip = ip.substr(0, i);
break;
}
}
pPlayer->SetIpAddress(ip);
pPlayer->SetConnected();
m_Players[slot.Get()] = pPlayer;
RETURN_META_VALUE(MRES_IGNORED, true);
}
void Menus::Hook_ClientPutInServer( CPlayerSlot slot, char const *pszName, int type, uint64 xuid )
{
m_Players[slot.Get()]->SetInGame(true);
}
void Menus::OnValidateAuthTicketHook(ValidateAuthTicketResponse_t *pResponse)
{
uint64 iSteamId = pResponse->m_SteamID.ConvertToUint64();
for (int i = 0; i < 64; i++)
{
if (!m_Players[i] || m_Players[i]->IsFakeClient() || !(m_Players[i]->GetUnauthenticatedSteamId64() == iSteamId))
continue;
switch (pResponse->m_eAuthSessionResponse)
{
case k_EAuthSessionResponseOK:
{
if(m_Players[i]->IsAuthenticated())
return;
m_Players[i]->SetAuthenticated(true);
m_Players[i]->SetSteamId(m_Players[i]->GetUnauthenticatedSteamId());
g_pPlayersApi->SendClientAuthCallback(i, iSteamId);
if(!g_pCookies) {
g_iMenuType[i] = GetClientCookieMenuType(i);
}
return;
}
case k_EAuthSessionResponseAuthTicketInvalid:
case k_EAuthSessionResponseAuthTicketInvalidAlreadyUsed:
{
if (!g_iDelayAuthFailKick)
return;
g_pUtilsApi->PrintToChat(i, g_vecPhrases["AuthTicketInvalid"].c_str());
[[fallthrough]];
}
default:
{
if (!g_iDelayAuthFailKick)
return;
g_pUtilsApi->PrintToChat(i, g_vecPhrases["AuthFailed"].c_str(), g_iDelayAuthFailKick);
new CTimer(g_iDelayAuthFailKick, [i]()
{
if(!m_Players[i] || m_Players[i]->IsFakeClient() || m_Players[i]->IsAuthenticated()) return -1.f;
engine->DisconnectClient(i, NETWORK_DISCONNECT_KICKED_NOSTEAMLOGIN);
return -1.f;
});
}
}
}
}
void UtilsApi::LoadTranslations(const char* FileName)
{
KeyValues::AutoDelete g_kvPhrases("Phrases");
char pszPath[256];
g_SMAPI->Format(pszPath, sizeof(pszPath), "addons/translations/%s.txt", FileName);
if (!g_kvPhrases->LoadFromFile(g_pFullFileSystem, pszPath))
{
Warning("Failed to load %s\n", pszPath);
return;
}
for (KeyValues *pKey = g_kvPhrases->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey())
g_vecPhrases[std::string(pKey->GetName())] = std::string(pKey->GetString(szLanguage));
}
bool Menus::FireEvent(IGameEvent* pEvent, bool bDontBroadcast)
{
if (!pEvent) {
RETURN_META_VALUE(MRES_IGNORED, false);
}
const char* szName = pEvent->GetName();
g_pUtilsApi->SendHookEventCallback(szName, pEvent, bDontBroadcast);
RETURN_META_VALUE(MRES_IGNORED, true);
}
void Menus::GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
{
if(!g_pGameRules)
{
CCSGameRulesProxy* pGameRulesProxy = static_cast<CCSGameRulesProxy*>(UTIL_FindEntityByClassname("cs_gamerules"));
if (pGameRulesProxy)
{
g_pGameRules = pGameRulesProxy->m_pGameRules();
if(g_pGameRules) g_pUtilsApi->SendHookGameRules();
}
} else if(g_bMenuFlashFix) {
if(!g_pGameRules->m_bWarmupPeriod() && !g_pGameRules->m_bGameRestart()) g_pGameRules->m_bGameRestart() = g_pGameRules->m_flRestartRoundTime().GetTime() < gpGlobals->curtime;
else g_pGameRules->m_bGameRestart() = false;
}
g_pUtilsApi->NextFrame();
if (simulating && g_bHasTicked)
{
g_flUniversalTime += gpGlobals->curtime - g_flLastTickedTime;
}
g_flLastTickedTime = gpGlobals->curtime;
g_bHasTicked = true;
for (int i = g_timers.Count() - 1; i >= 0; i--)
{
auto timer = g_timers[i];
if (timer->m_flLastExecute == -1)
timer->m_flLastExecute = g_flUniversalTime;
// Timer execute
if (timer->m_flLastExecute + timer->m_flInterval <= g_flUniversalTime)
{
if (!timer->Execute())
{
delete timer;
g_timers.Remove(i);
}
else
{
timer->m_flLastExecute = g_flUniversalTime;
}
}
}
}
void Menus::ClientCommand(CPlayerSlot slot, const CCommand &args)
{
bool bFound = g_pUtilsApi->FindAndSendCommandCallback(args.Arg(0), slot.Get(), args.ArgS(), true);
if(bFound) RETURN_META(MRES_SUPERCEDE);
}
std::string StripQuotes(const std::string& str) {
if (str.size() >= 2 && str.front() == '"' && str.back() == '"')
return str.substr(1, str.size() - 2);
return str;
}
std::string TrimTrailingQuote(const std::string& str) {
if (!str.empty() && str.back() == '"')
return str.substr(0, str.size() - 1);
return str;
}
std::vector<std::string> SplitStringBySpace(const std::string& input) {
std::istringstream iss(input);
std::vector<std::string> tokens;
std::string token;
while (iss >> token) {
token = TrimTrailingQuote(token);
tokens.push_back(token);
}
return tokens;
}
void Menus::OnDispatchConCommand(ConCommandRef cmdHandle, const CCommandContext& ctx, const CCommand& args)
{
if (!g_pEntitySystem)
return;
auto iCommandPlayerSlot = ctx.GetPlayerSlot();
bool bSay = !V_strcmp(args.Arg(0), "say");
bool bTeamSay = !V_strcmp(args.Arg(0), "say_team");
int iSlot = iCommandPlayerSlot.Get();
if (iSlot != -1 && (bSay || bTeamSay))
{
auto pController = CCSPlayerController::FromSlot(iSlot);
bool bCommand = *args[1] == '!' || *args[1] == '/';
if (pController && bCommand)
{
std::string message = args.ArgS() + 2;
auto tokens = SplitStringBySpace(message);
if (!tokens.empty())
{
if (containsOnlyDigits(tokens[0]))
{
if (g_iMenuType[iSlot] != 2)
{
int iButton = atoi(tokens[0].c_str());