-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathcommands.cpp
More file actions
1141 lines (912 loc) · 35.5 KB
/
commands.cpp
File metadata and controls
1141 lines (912 loc) · 35.5 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-2026 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 "commands.h"
#include "adminsystem.h"
#include "common.h"
#include "ctimer.h"
#include "detours.h"
#include "discord.h"
#include "engine/igameeventsystem.h"
#include "entity/cbaseentity.h"
#include "entity/cbasemodelentity.h"
#include "entity/ccsplayercontroller.h"
#include "entity/ccsplayerpawn.h"
#include "entity/ccsweaponbase.h"
#include "entity/cparticlesystem.h"
#include "entity/lights.h"
#include "httpmanager.h"
#include "leader.h"
#include "networksystem/inetworkmessages.h"
#include "playermanager.h"
#include "recipientfilters.h"
#include "tier0/vprof.h"
#include "usermessages.pb.h"
#include "utils/entity.h"
#include "utlstring.h"
#include "zombiereborn.h"
#undef snprintf
#include "vendor/nlohmann/json.hpp"
#include "tier0/memdbgon.h"
using json = nlohmann::json;
CConVar<bool> g_cvarEnableCommands("cs2f_commands_enable", FCVAR_NONE, "Whether to enable chat commands", false);
CConVar<bool> g_cvarEnableAdminCommands("cs2f_admin_commands_enable", FCVAR_NONE, "Whether to enable admin chat commands", false);
CConVar<bool> g_cvarEnableWeapons("cs2f_weapons_enable", FCVAR_NONE, "Whether to enable weapon commands", false);
// We need to use a helper function to avoid command macros accessing command list before its initialized
std::map<uint32, std::shared_ptr<CChatCommand>>& CommandList()
{
static std::map<uint32, std::shared_ptr<CChatCommand>> commandList;
return commandList;
}
int GetGrenadeAmmo(CCSPlayer_WeaponServices* pWeaponServices, const WeaponInfo_t* pWeaponInfo)
{
if (!pWeaponServices || pWeaponInfo->m_eSlot != GEAR_SLOT_GRENADES)
return -1;
// TODO: look into molotov vs inc interaction
if (strcmp(pWeaponInfo->m_pClass, "weapon_hegrenade") == 0)
return pWeaponServices->m_iAmmo[AMMO_OFFSET_HEGRENADE];
if (strcmp(pWeaponInfo->m_pClass, "weapon_molotov") == 0 || strcmp(pWeaponInfo->m_pClass, "weapon_incgrenade") == 0)
return pWeaponServices->m_iAmmo[AMMO_OFFSET_MOLOTOV];
if (strcmp(pWeaponInfo->m_pClass, "weapon_decoy") == 0)
return pWeaponServices->m_iAmmo[AMMO_OFFSET_DECOY];
if (strcmp(pWeaponInfo->m_pClass, "weapon_flashbang") == 0)
return pWeaponServices->m_iAmmo[AMMO_OFFSET_FLASHBANG];
if (strcmp(pWeaponInfo->m_pClass, "weapon_smokegrenade") == 0)
return pWeaponServices->m_iAmmo[AMMO_OFFSET_SMOKEGRENADE];
return -1;
}
int GetGrenadeAmmoTotal(CCSPlayer_WeaponServices* pWeaponServices)
{
if (!pWeaponServices)
return -1;
int grenadeAmmoOffsets[] = {
AMMO_OFFSET_HEGRENADE,
AMMO_OFFSET_FLASHBANG,
AMMO_OFFSET_SMOKEGRENADE,
AMMO_OFFSET_DECOY,
AMMO_OFFSET_MOLOTOV,
};
int totalGrenades = 0;
for (int i = 0; i < (sizeof(grenadeAmmoOffsets) / sizeof(int)); i++)
totalGrenades += pWeaponServices->m_iAmmo[grenadeAmmoOffsets[i]];
return totalGrenades;
}
void ParseWeaponCommand(const CCommand& args, CCSPlayerController* player)
{
if (!g_cvarEnableWeapons.Get() || !player || !player->m_hPawn())
return;
VPROF("ParseWeaponCommand");
const auto pPawn = reinterpret_cast<CCSPlayerPawn*>(player->GetPawn());
const char* command = args[0];
if (!V_strncmp("c_", command, 2))
command = command + 2;
const auto pWeaponInfo = FindWeaponInfoByAlias(command);
if (!pWeaponInfo || pWeaponInfo->m_nPrice == 0)
return;
if (pPawn->m_iHealth() <= 0 || pPawn->m_iTeamNum != CS_TEAM_CT)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You can only buy weapons when human.");
return;
}
CCSPlayer_ItemServices* pItemServices = pPawn->m_pItemServices;
CCSPlayer_WeaponServices* pWeaponServices = pPawn->m_pWeaponServices;
// it can sometimes be null when player joined on the very first round?
if (!pItemServices || !pWeaponServices)
return;
int money = player->m_pInGameMoneyServices->m_iAccount;
if (money < pWeaponInfo->m_nPrice)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You can't afford %s! It costs $%i, you only have $%i", pWeaponInfo->m_pName, pWeaponInfo->m_nPrice, money);
return;
}
static ConVarRefAbstract ammo_grenade_limit_default("ammo_grenade_limit_default"), ammo_grenade_limit_total("ammo_grenade_limit_total"), mp_weapons_allow_typecount("mp_weapons_allow_typecount");
int iGrenadeLimitDefault = ammo_grenade_limit_default.GetInt();
int iGrenadeLimitTotal = ammo_grenade_limit_total.GetInt();
int iWeaponLimit = mp_weapons_allow_typecount.GetInt();
if (pWeaponInfo->m_eSlot == GEAR_SLOT_GRENADES)
{
int iMatchingGrenades = GetGrenadeAmmo(pWeaponServices, pWeaponInfo);
int iTotalGrenades = GetGrenadeAmmoTotal(pWeaponServices);
if (iMatchingGrenades >= iGrenadeLimitDefault)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot carry any more %ss (Max %i)", pWeaponInfo->m_pName, iGrenadeLimitDefault);
return;
}
if (iTotalGrenades >= iGrenadeLimitTotal)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot carry any more grenades (Max %i)", iGrenadeLimitTotal);
return;
}
}
int maxAmount;
if (pWeaponInfo->m_nMaxAmount)
maxAmount = pWeaponInfo->m_nMaxAmount;
else if (pWeaponInfo->m_eSlot == GEAR_SLOT_GRENADES)
maxAmount = iGrenadeLimitDefault;
else
maxAmount = iWeaponLimit == -1 ? 9999 : iWeaponLimit;
CUtlVector<WeaponPurchaseCount_t>* weaponPurchases = pPawn->m_pActionTrackingServices->m_weaponPurchasesThisRound().m_weaponPurchases;
bool found = false;
FOR_EACH_VEC(*weaponPurchases, i)
{
WeaponPurchaseCount_t& purchase = (*weaponPurchases)[i];
if (purchase.m_nItemDefIndex == pWeaponInfo->m_iItemDefinitionIndex)
{
// Note ammo_grenade_limit_total is not followed here, only for checking inventory space
if (purchase.m_nCount >= maxAmount)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot buy any more %s (Max %i)", pWeaponInfo->m_pName, maxAmount);
return;
}
purchase.m_nCount += 1;
found = true;
break;
}
}
if (!found)
{
WeaponPurchaseCount_t purchase(pPawn, pWeaponInfo->m_iItemDefinitionIndex, 1);
weaponPurchases->AddToTail(purchase);
}
if (pWeaponInfo->m_eSlot == GEAR_SLOT_RIFLE || pWeaponInfo->m_eSlot == GEAR_SLOT_PISTOL)
{
CUtlVector<CHandle<CBasePlayerWeapon>>* weapons = pWeaponServices->m_hMyWeapons();
FOR_EACH_VEC(*weapons, i)
{
CBasePlayerWeapon* weapon = (*weapons)[i].Get();
if (!weapon)
continue;
if (weapon->GetWeaponVData()->m_GearSlot() == pWeaponInfo->m_eSlot)
{
pWeaponServices->DropWeapon(weapon);
break;
}
}
}
CBasePlayerWeapon* pWeapon = pItemServices->GiveNamedItemAws(pWeaponInfo->m_pClass);
// Normally shouldn't be possible, but avoid issues in some edge cases
if (!pWeapon)
return;
player->m_pInGameMoneyServices->m_iAccount = money - pWeaponInfo->m_nPrice;
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have purchased %s for $%i", pWeaponInfo->m_pName, pWeaponInfo->m_nPrice);
}
void WeaponCommandCallback(const CCommandContext& context, const CCommand& args)
{
CCSPlayerController* pController = nullptr;
if (context.GetPlayerSlot().Get() != -1)
pController = (CCSPlayerController*)g_pEntitySystem->GetEntityInstance((CEntityIndex)(context.GetPlayerSlot().Get() + 1));
// Only allow connected players to run chat commands
if (pController && !pController->IsConnected())
return;
ParseWeaponCommand(args, pController);
}
void RegisterWeaponCommands()
{
const auto& weapons = GenerateWeaponCommands();
for (const auto& aliases : weapons | std::views::values)
{
for (const auto& alias : aliases)
{
CChatCommand::Create(alias.c_str(), ParseWeaponCommand, "- Buys this weapon", ADMFLAG_NONE, CMDFLAG_NOHELP);
char cmdName[64];
V_snprintf(cmdName, sizeof(cmdName), "%s%s", COMMAND_PREFIX, alias.c_str());
new ConCommand(cmdName, WeaponCommandCallback, "Buys this weapon", FCVAR_RELEASE | FCVAR_CLIENT_CAN_EXECUTE | FCVAR_LINKED_CONCOMMAND);
}
}
}
void ParseChatCommand(const char* pMessage, CCSPlayerController* pController)
{
if (!pController || !pController->IsConnected())
return;
VPROF("ParseChatCommand");
CCommand args;
args.Tokenize(pMessage);
std::string name = args[0];
for (int i = 0; name[i]; i++)
name[i] = tolower(name[i]);
uint32 nameHash = hash_32_fnv1a_const(name.c_str());
if (CommandList().contains(nameHash))
(*CommandList()[nameHash])(args, pController);
}
bool CChatCommand::CheckCommandAccess(CCSPlayerController* pPlayer, uint64 flags)
{
if (!pPlayer)
return false;
int slot = pPlayer->GetPlayerSlot();
ZEPlayer* pZEPlayer = g_playerManager->GetPlayer(slot);
if (!pZEPlayer)
return false;
if ((flags & FLAG_LEADER) == FLAG_LEADER)
{
if (!g_cvarEnableLeader.Get())
return false;
if (!pZEPlayer->IsAdminFlagSet(FLAG_LEADER))
{
if (!pZEPlayer->IsLeader())
{
ClientPrint(pPlayer, HUD_PRINTTALK, CHAT_PREFIX "You must be a leader to use this command.");
return false;
}
else if (g_cvarLeaderActionsHumanOnly.Get() && pPlayer->m_iTeamNum != CS_TEAM_CT)
{
ClientPrint(pPlayer, HUD_PRINTTALK, CHAT_PREFIX "You must be a human to use this command.");
return false;
}
}
}
else if (!pZEPlayer->IsAdminFlagSet(flags))
{
ClientPrint(pPlayer, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command.");
return false;
}
return true;
}
void ClientPrintAll(int hud_dest, const char* msg, ...)
{
va_list args;
va_start(args, msg);
char buf[256];
V_vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg");
auto data = pNetMsg->AllocateMessage()->ToPB<CUserMessageTextMsg>();
data->set_dest(hud_dest);
data->add_param(buf);
CRecipientFilter filter;
filter.AddAllPlayers();
g_gameEventSystem->PostEventAbstract(-1, false, &filter, pNetMsg, data, 0);
delete data;
ConMsg("%s\n", buf);
}
void ClientPrint(CCSPlayerController* player, int hud_dest, const char* msg, ...)
{
va_list args;
va_start(args, msg);
char buf[256];
V_vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
if (!player || !player->IsConnected() || player->IsBot())
{
ConMsg("%s\n", buf);
return;
}
INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg");
auto data = pNetMsg->AllocateMessage()->ToPB<CUserMessageTextMsg>();
data->set_dest(hud_dest);
data->add_param(buf);
CSingleRecipientFilter filter(player->GetPlayerSlot());
g_gameEventSystem->PostEventAbstract(-1, false, &filter, pNetMsg, data, 0);
delete data;
}
CConVar<bool> g_cvarEnableStopSound("cs2f_stopsound_enable", FCVAR_NONE, "Whether to enable stopsound", false);
CON_COMMAND_CHAT(stopsound, "- Toggle weapon sounds")
{
if (!g_cvarEnableStopSound.Get())
return;
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
int iPlayer = player->GetPlayerSlot();
bool bStopSet = g_playerManager->IsPlayerUsingStopSound(iPlayer);
bool bSilencedSet = g_playerManager->IsPlayerUsingSilenceSound(iPlayer);
g_playerManager->SetPlayerStopSound(iPlayer, bSilencedSet);
g_playerManager->SetPlayerSilenceSound(iPlayer, !bSilencedSet && !bStopSet);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have %s weapon sounds.", bSilencedSet ? "disabled" : !bSilencedSet && !bStopSet ? "silenced" :
"enabled");
}
CON_COMMAND_CHAT(toggledecals, "- Toggle world decals, if you're into having 10 fps in ZE")
{
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
int iPlayer = player->GetPlayerSlot();
bool bSet = !g_playerManager->IsPlayerUsingStopDecals(iPlayer);
g_playerManager->SetPlayerStopDecals(iPlayer, bSet);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have %s world decals.", bSet ? "disabled" : "enabled");
}
CConVar<bool> g_cvarEnableNoShake("cs2f_noshake_enable", FCVAR_NONE, "Whether to enable noshake command", false);
CConVar<float> g_cvarMaxShakeAmp("cs2f_maximum_shake_amplitude", FCVAR_NONE, "Shaking Amplitude bigger than this will be clamped", -1.0f, true, -1.0f, true, 16.0f);
CON_COMMAND_CHAT(noshake, "- toggle noshake")
{
if (!g_cvarEnableNoShake.Get())
return;
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
int iPlayer = player->GetPlayerSlot();
bool bSet = !g_playerManager->IsPlayerUsingNoShake(iPlayer);
g_playerManager->SetPlayerNoShake(iPlayer, bSet);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have %s noshake.", bSet ? "enabled" : "disabled");
}
CConVar<bool> g_cvarEnableHide("cs2f_hide_enable", FCVAR_NONE, "Whether to enable hide (WARNING: randomly crashes clients since 2023-12-13 CS2 update)", false);
CConVar<bool> g_cvarHideWeapons("cs2f_hide_weapons", FCVAR_NONE, "Whether to hide weapons along with their holders", false);
CConVar<int> g_cvarDefaultHideDistance("cs2f_hide_distance_default", FCVAR_NONE, "The default distance for hide", 250, true, 0, false, 0);
CConVar<int> g_cvarMaxHideDistance("cs2f_hide_distance_max", FCVAR_NONE, "The max distance for hide", 2000, true, 0, false, 0);
CConVar<bool> g_cvarEnableHideMode("cs2f_hide_mode_enable", FCVAR_NONE, "Whether to enable hide mode command", false);
CON_COMMAND_CHAT(hide, "<distance> - Hide nearby players")
{
// Silently return so the command is completely hidden
if (!g_cvarEnableHide.Get())
return;
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
ZEPlayer* pZEPlayer = player->GetZEPlayer();
// Something has to really go wrong for this to happen
if (!pZEPlayer)
{
Warning("%s Tried to access a null ZEPlayer!!\n", player->GetPlayerName());
return;
}
int distance;
if (args.ArgC() < 2)
distance = pZEPlayer->GetHideDistance() > 0 ? pZEPlayer->GetHideDistance() : g_cvarDefaultHideDistance.Get();
else
distance = V_StringToInt32(args[1], -1);
if (distance > g_cvarMaxHideDistance.Get() || distance < 0)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You can only hide players between\x06 0\x01 and \x06%i units\x01 away.", g_cvarMaxHideDistance.Get());
return;
}
// allows for toggling hide by turning off when hide distance matches.
if (pZEPlayer->GetHideDistance() == distance)
distance = 0;
pZEPlayer->SetHideDistance(distance);
if (distance == 0)
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Hiding players is now disabled.");
else
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Now hiding players within \x06%i units\x01.", distance);
}
CON_COMMAND_CHAT(hidemode, "[mode] - Cycle or set hide mode: 0 (Normal), 1 (Include Items), 2 (Hide Everyone)")
{
// Silently return so the command is completely hidden
if (!g_cvarEnableHide.Get() || !g_cvarEnableHideMode.Get())
return;
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
ZEPlayer* pZEPlayer = player->GetZEPlayer();
// Something has to really go wrong for this to happen
if (!pZEPlayer)
{
Warning("%s Tried to access a null ZEPlayer!!\n", player->GetPlayerName());
return;
}
int iMode;
if(args.ArgC() < 2)
{
pZEPlayer->CycleHideMode();
iMode = pZEPlayer->GetHideMode();
}
else
{
iMode = V_StringToInt32(args[1], -1);
if (iMode != HIDE_MODE_NORMAL && iMode != HIDE_MODE_ITEMS && iMode != HIDE_MODE_ALL)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Invalid hide mode. Valid modes are: %i (Normal), %i (Include Items), %i (Hide Everyone)", HIDE_MODE_NORMAL, HIDE_MODE_ITEMS, HIDE_MODE_ALL);
return;
}
if (iMode == pZEPlayer->GetHideMode()) {
iMode = HIDE_MODE_NORMAL;
}
pZEPlayer->SetHideMode(iMode);
}
const char* desc;
switch (iMode)
{
case HIDE_MODE_NORMAL:
desc = "Normal";
break;
case HIDE_MODE_ITEMS:
desc = "Include Items";
break;
case HIDE_MODE_ALL:
desc = "Hide Everyone";
break;
}
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Hide mode is: %s.", desc);
}
void PrintHelp(const CCommand& args, CCSPlayerController* player)
{
std::vector<std::string> rgstrCommands;
if (args.ArgC() < 2)
{
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, "The list of all commands is:");
for (const auto& cmdPair : CommandList())
{
auto cmd = cmdPair.second;
if (!cmd->IsCommandFlagSet(CMDFLAG_NOHELP))
rgstrCommands.push_back(std::string("c_") + cmd->GetName() + " " + cmd->GetDescription());
}
}
else
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "The list of all available commands will be shown in console.");
ClientPrint(player, HUD_PRINTCONSOLE, "The list of all commands you can use is:");
ZEPlayer* pZEPlayer = player->GetZEPlayer();
for (const auto& cmdPair : CommandList())
{
auto cmd = cmdPair.second;
uint64 flags = cmd->GetAdminFlags();
if ((pZEPlayer->IsAdminFlagSet(flags) || ((flags & FLAG_LEADER) == FLAG_LEADER && pZEPlayer->IsLeader()))
&& !cmd->IsCommandFlagSet(CMDFLAG_NOHELP))
rgstrCommands.push_back(std::string("!") + cmd->GetName() + " " + cmd->GetDescription());
}
}
}
else
{
const char* pszSearchTerm = args[1];
bool bOnlyCheckStart = false;
// If a user's search starts with a prefix needed to actually use a command,
// assume that they only want to see commands starting with that substring
if (V_strnicmp(args[1], "c_", 2) == 0)
{
bOnlyCheckStart = true;
pszSearchTerm++;
pszSearchTerm++;
}
else if (V_strnicmp(args[1], "!", 1) == 0 || V_strnicmp(args[1], "/", 1) == 0)
{
bOnlyCheckStart = true;
pszSearchTerm++;
}
if (!player)
{
for (const auto& cmdPair : CommandList())
{
auto cmd = cmdPair.second;
if (!cmd->IsCommandFlagSet(CMDFLAG_NOHELP)
&& ((!bOnlyCheckStart && V_stristr(cmd->GetName(), pszSearchTerm))
|| (bOnlyCheckStart && V_strnicmp(cmd->GetName(), pszSearchTerm, strlen(pszSearchTerm)) == 0)))
rgstrCommands.push_back(std::string("c_") + cmd->GetName() + " " + cmd->GetDescription());
}
}
else
{
ZEPlayer* pZEPlayer = player->GetZEPlayer();
for (const auto& cmdPair : CommandList())
{
auto cmd = cmdPair.second;
uint64 flags = cmd->GetAdminFlags();
if ((pZEPlayer->IsAdminFlagSet(flags) || ((flags & FLAG_LEADER) == FLAG_LEADER && pZEPlayer->IsLeader()))
&& !cmd->IsCommandFlagSet(CMDFLAG_NOHELP)
&& ((!bOnlyCheckStart && V_stristr(cmd->GetName(), pszSearchTerm))
|| (bOnlyCheckStart && V_strnicmp(cmd->GetName(), pszSearchTerm, strlen(pszSearchTerm)) == 0)))
rgstrCommands.push_back(std::string("!") + cmd->GetName() + " " + cmd->GetDescription());
}
}
if (rgstrCommands.size() == 0)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "No commands matched \"%s\".", args[1]);
if (player)
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No commands matched \"%s\".", args[1]);
return;
}
ClientPrint(player, HUD_PRINTCONSOLE, "The list of all commands matching \"%s\" is:", args[1]);
if (player)
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "The list of all commands matching \"%s\" will be shown in console.", args[1]);
}
std::sort(rgstrCommands.begin(), rgstrCommands.end());
for (const auto& strCommand : rgstrCommands)
ClientPrint(player, HUD_PRINTCONSOLE, strCommand.c_str());
if (player)
ClientPrint(player, HUD_PRINTCONSOLE, "! can be replaced with / for a silent chat command, or c_ for console usage");
}
CON_COMMAND_CHAT(help, "- Display list of commands in console")
{
PrintHelp(args, player);
}
CON_COMMAND_CHAT(find, "<text> - Search for specific commands and list them in console")
{
PrintHelp(args, player);
}
CON_COMMAND_CHAT(spec, "[name] - Spectate another player or join spectators")
{
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)player->GetPawn();
if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
if (args.ArgC() < 2)
{
if (player->m_iTeamNum() == CS_TEAM_SPECTATOR)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Already spectating.");
}
else
{
if (pPawn && pPawn->IsAlive())
pPawn->CommitSuicide(false, true);
player->SwitchTeam(CS_TEAM_SPECTATOR);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Moved to spectators.");
}
return;
}
int iCommandPlayer = player ? player->GetPlayerSlot() : -1;
int iNumClients = 0;
int pSlot[MAXPLAYERS];
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlot, NO_MULTIPLE | NO_SELF | NO_DEAD | NO_SPECTATOR | NO_IMMUNITY))
return;
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[0]);
if (!pTarget)
return;
if (player->m_iTeamNum() != CS_TEAM_SPECTATOR)
{
if (pPawn && pPawn->IsAlive())
pPawn->CommitSuicide(false, true);
player->SwitchTeam(CS_TEAM_SPECTATOR);
}
// 1 frame delay as observer services will be null on same frame as spectator team switch
CHandle<CCSPlayerController> hPlayer = player->GetHandle();
CHandle<CCSPlayerController> hTarget = pTarget->GetHandle();
CTimer::Create(0.0f, TIMERFLAG_MAP | TIMERFLAG_ROUND, [hPlayer, hTarget]() {
CCSPlayerController* pPlayer = hPlayer.Get();
CCSPlayerController* pTargetPlayer = hTarget.Get();
if (!pPlayer || !pTargetPlayer)
return -1.0f;
CPlayer_ObserverServices* pObserverServices = pPlayer->GetPawn()->m_pObserverServices();
if (!pObserverServices)
return -1.0f;
pObserverServices->m_iObserverMode = OBS_MODE_IN_EYE;
pObserverServices->m_iObserverLastMode = OBS_MODE_ROAMING;
pObserverServices->m_hObserverTarget = pTargetPlayer->GetPawn();
ClientPrint(pPlayer, HUD_PRINTTALK, CHAT_PREFIX "Spectating player %s.", pTargetPlayer->GetPlayerName());
return -1.0f;
});
}
CON_COMMAND_CHAT(getpos, "- Get your position and angles")
{
if (!player)
return;
Vector vecAbsOrigin = player->GetPawn()->GetAbsOrigin();
QAngle angRotation = player->GetPawn()->GetAbsRotation();
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "setpos %f %f %f;setang %f %f %f", vecAbsOrigin.x, vecAbsOrigin.y, vecAbsOrigin.z, angRotation.x, angRotation.y, angRotation.z);
ClientPrint(player, HUD_PRINTCONSOLE, "setpos %f %f %f;setang %f %f %f", vecAbsOrigin.x, vecAbsOrigin.y, vecAbsOrigin.z, angRotation.x, angRotation.y, angRotation.z);
}
CON_COMMAND_CHAT(info, "<name> - Get a player's information")
{
if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !info <name>");
return;
}
int iNumClients = 0;
int pSlots[MAXPLAYERS];
ETargetType nType;
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlots, NO_BOT | NO_IMMUNITY, nType))
return;
ZEPlayer* pPlayer = player ? player->GetZEPlayer() : nullptr;
bool bIsAdmin = pPlayer ? pPlayer->IsAdminFlagSet(ADMFLAG_RCON) : true;
for (int i = 0; i < iNumClients; i++)
{
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]);
ZEPlayer* zpTarget = pTarget->GetZEPlayer();
ClientPrint(player, HUD_PRINTCONSOLE, "%s", pTarget->GetPlayerName());
ClientPrint(player, HUD_PRINTCONSOLE, "\tUser ID: %i", g_pEngineServer2->GetPlayerUserId(pTarget->GetPlayerSlot()).Get());
if (zpTarget->IsAuthenticated())
ClientPrint(player, HUD_PRINTCONSOLE, "\tSteam64 ID: %llu", zpTarget->GetSteamId64());
else
ClientPrint(player, HUD_PRINTCONSOLE, "\tSteam64 ID: %llu (Unauthenticated)", zpTarget->GetUnauthenticatedSteamId());
if (bIsAdmin)
ClientPrint(player, HUD_PRINTCONSOLE, "\tIP Address: %s", zpTarget->GetIpAddress());
}
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Printed matching player%s information to console.", (iNumClients == 1) ? "'s" : "s'");
}
CON_COMMAND_CHAT(showteam, "<name> - Get a player's current team")
{
if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !showteam <name>");
return;
}
int iNumClients = 0;
int pSlots[MAXPLAYERS];
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlots, NO_MULTIPLE | NO_IMMUNITY))
return;
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[0]);
switch (pTarget->m_iTeamNum())
{
case CS_TEAM_SPECTATOR:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is a\x08 spectator\x01.", pTarget->GetPlayerName());
break;
case CS_TEAM_T:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is a\x09 terrorist\x01.", pTarget->GetPlayerName());
break;
case CS_TEAM_CT:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is a\x0B counter-terrorist\x01.", pTarget->GetPlayerName());
break;
default:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is not on a team.", pTarget->GetPlayerName());
}
}
// Because sv_fullupdate doesn't work
CON_COMMAND_F(cs2f_fullupdate, "- Force a full update for all clients.", FCVAR_LINKED_CONCOMMAND | FCVAR_SPONLY)
{
g_playerManager->FullUpdateAllClients();
}
#if _DEBUG
CON_COMMAND_CHAT(myuid, "- Test")
{
if (!player)
return;
int iPlayer = player->GetPlayerSlot();
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Your userid is %i, slot: %i, retrieved slot: %i", g_pEngineServer2->GetPlayerUserId(iPlayer).Get(), iPlayer, g_playerManager->GetSlotFromUserId(g_pEngineServer2->GetPlayerUserId(iPlayer).Get()));
}
CON_COMMAND_CHAT(myhandle, "- Test")
{
if (!player)
return;
int entry = player->GetHandle().GetEntryIndex();
int serial = player->GetHandle().GetSerialNumber();
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "entry index: %d serial number: %d", entry, serial);
}
CON_COMMAND_CHAT(fl, "- Flashlight")
{
if (!player)
return;
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)player->GetPawn();
auto ptr = pPawn->m_pMovementServices->m_nButtons().m_pButtonStates();
Vector origin = pPawn->GetAbsOrigin();
Vector forward;
AngleVectors(pPawn->m_angEyeAngles(), &forward);
origin.z += 64.0f;
origin += forward * 54.0f; // The minimum distance such that an awp wouldn't block the light
CBarnLight* pLight = CreateEntityByName<CBarnLight>("light_barn");
pLight->m_bEnabled = true;
pLight->m_Color->SetColor(255, 255, 255, 255);
pLight->m_flBrightness = 1.0f;
pLight->m_flRange = 2048.0f;
pLight->m_flSoftX = 1.0f;
pLight->m_flSoftY = 1.0f;
pLight->m_flSkirt = 0.5f;
pLight->m_flSkirtNear = 1.0f;
pLight->m_vSizeParams->Init(45.0f, 45.0f, 0.03f);
pLight->m_nCastShadows = 1;
pLight->m_nDirectLight = 3;
pLight->Teleport(&origin, &pPawn->m_angEyeAngles(), nullptr);
// Have to use keyvalues for this since the schema prop is a resource handle
CEntityKeyValues* pKeyValues = new CEntityKeyValues();
pKeyValues->SetString("lightcookie", "materials/effects/lightcookies/flashlight.vtex");
pLight->DispatchSpawn(pKeyValues);
pLight->SetParent(pPawn);
pLight->AcceptInput("SetParentAttachmentMaintainOffset", g_cvarFlashLightAttachment.Get().String());
}
CON_COMMAND_CHAT(say, "<message> - Say something using console")
{
ClientPrintAll(HUD_PRINTTALK, "%s", args.ArgS());
}
CON_COMMAND_CHAT(test_target, "<name> [blocked flag] [...] - Test string targetting")
{
if (!player)
return;
if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !test_target <name> [blocked flag] [...]");
return;
}
uint64 iBlockedFlags = NO_TARGET_BLOCKS;
for (int i = 1; i < args.ArgC(); i++)
if (!V_stricmp(args[i], "NO_RANDOM"))
iBlockedFlags |= NO_RANDOM;
else if (!V_stricmp(args[i], "NO_MULTIPLE"))
iBlockedFlags |= NO_MULTIPLE;
else if (!V_stricmp(args[i], "NO_SELF"))
iBlockedFlags |= NO_SELF;
else if (!V_stricmp(args[i], "NO_BOT"))
iBlockedFlags |= NO_BOT;
else if (!V_stricmp(args[i], "NO_HUMAN"))
iBlockedFlags |= NO_HUMAN;
else if (!V_stricmp(args[i], "NO_UNAUTHENTICATED"))
iBlockedFlags |= NO_UNAUTHENTICATED;
else if (!V_stricmp(args[i], "NO_DEAD"))
iBlockedFlags |= NO_DEAD;
else if (!V_stricmp(args[i], "NO_ALIVE"))
iBlockedFlags |= NO_ALIVE;
else if (!V_stricmp(args[i], "NO_TERRORIST"))
iBlockedFlags |= NO_TERRORIST;
else if (!V_stricmp(args[i], "NO_COUNTER_TERRORIST"))
iBlockedFlags |= NO_COUNTER_TERRORIST;
else if (!V_stricmp(args[i], "NO_SPECTATOR"))
iBlockedFlags |= NO_SPECTATOR;
else if (!V_stricmp(args[i], "NO_IMMUNITY"))
iBlockedFlags |= NO_IMMUNITY;
int iNumClients = 0;
int pSlots[MAXPLAYERS];
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlots, iBlockedFlags))
return;
for (int i = 0; i < iNumClients; i++)
{
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Targeting %s", pTarget->GetPlayerName());
Message("Targeting %s\n", pTarget->GetPlayerName());
}
}
CON_COMMAND_CHAT(particle, "- Spawn a particle")
{
if (!player)
return;
Vector vecAbsOrigin = player->GetPawn()->GetAbsOrigin();
vecAbsOrigin.z += 64.0f;
CParticleSystem* particle = CreateEntityByName<CParticleSystem>("info_particle_system");
particle->m_bStartActive(true);
particle->m_iszEffectName(args[1]);
particle->Teleport(&vecAbsOrigin, nullptr, nullptr);
particle->DispatchSpawn();
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have spawned a particle with effect name: %s", particle->m_iszEffectName().String());
Message("You have spawned a particle with effect name: %s\n", particle->m_iszEffectName().String());
}
CON_COMMAND_CHAT(particle_kv, "- Spawn a particle but using keyvalues to spawn")
{
if (!player)
return;
Vector vecAbsOrigin = player->GetPawn()->GetAbsOrigin();
vecAbsOrigin.z += 64.0f;
CParticleSystem* particle = CreateEntityByName<CParticleSystem>("info_particle_system");
CEntityKeyValues* pKeyValues = new CEntityKeyValues();
pKeyValues->SetString("effect_name", args[1]);
pKeyValues->SetBool("start_active", true);
pKeyValues->SetVector("origin", vecAbsOrigin);
particle->DispatchSpawn(pKeyValues);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have spawned a particle using keyvalues with effect name: %s", particle->m_iszEffectName().String());
Message("You have spawned a particle using keyvalues with effect name: %s\n", particle->m_iszEffectName().String());
}
CON_COMMAND_CHAT(dispatch_particle, "- Test")
{
if (!player)
return;
CRecipientFilter filter;
filter.AddAllPlayers();
player->GetPawn()->DispatchParticle(args[1], &filter);
}
CON_COMMAND_CHAT(emitsound, "- Emit a sound from the entity under crosshair")
{
if (!player)
return;
CBaseEntity* pEntity = UTIL_FindPickerEntity(player);
if (!pEntity)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No entity found");
return;
}
pEntity->EmitSound(args[1]);
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Playing %s on %s", args[1], pEntity->GetClassname());