-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathbuttonwatch.cpp
More file actions
128 lines (111 loc) · 4.8 KB
/
Copy pathbuttonwatch.cpp
File metadata and controls
128 lines (111 loc) · 4.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
/**
* =============================================================================
* 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 "buttonwatch.h"
#include "commands.h"
#include "cs2fixes.h"
#include "ctimer.h"
#include "detours.h"
#include "entity.h"
#include "entity/cbaseplayercontroller.h"
#include "entity/ccsplayercontroller.h"
#include "entity/ccsplayerpawn.h"
#include "entity/cgameplayerequip.h"
#include "entity/cgamerules.h"
#include "entity/clogiccase.h"
#include "entity/cpointviewcontrol.h"
CConVar<bool> g_cvarEnableButtonWatch("cs2f_enable_button_watch", FCVAR_NONE, "Whether to enable button watch or not.", false);
CON_COMMAND_CHAT_FLAGS(bw, "- Toggle button watch display", ADMFLAG_GENERIC)
{
if (!g_cvarEnableButtonWatch.Get())
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Button watch is disabled on this server.");
return;
}
if (!player)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot use this command from the server console.");
return;
}
ZEPlayer* zpPlayer = player->GetZEPlayer();
if (!zpPlayer)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Something went wrong, please wait a moment before trying this command again.");
return;
}
zpPlayer->CycleButtonWatch();
switch (zpPlayer->GetButtonWatchMode())
{
case 0:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have\x02 disabled\1 button watch.");
break;
case 1:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have\x04 enabled\1 button watch in chat.");
break;
case 2:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have\x04 enabled\1 button watch in console.");
break;
case 3:
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have\x04 enabled\1 button watch in chat and console.");
break;
}
}
std::map<int, bool> mapRecentEnts;
void ButtonWatch(const CEntityIOOutput* pThis, CEntityInstance* pActivator, CEntityInstance* pCaller, float flDelay)
{
if (!GetGlobals() || V_stricmp(pThis->m_pDesc->m_pName, "OnPressed") || !pActivator || !((CBaseEntity*)pActivator)->IsPawn() || !pCaller || mapRecentEnts.contains(pCaller->GetEntityIndex().Get()))
return;
CCSPlayerController* ccsPlayer = CCSPlayerController::FromPawn(static_cast<CCSPlayerPawn*>(pActivator));
std::string strPlayerName = ccsPlayer->GetPlayerName();
const char* pszButtonName = ((CBaseEntity*)pCaller)->GetName();
if (!V_strcasecmp("game_playerdie", pszButtonName) || !V_strcasecmp("game_playerkill", pszButtonName) || !V_strcasecmp("game_playerjoin", pszButtonName) || !V_strcasecmp("game_playerspawn", pszButtonName) || !V_strcasecmp("game_playerleave", pszButtonName))
return;
ZEPlayer* zpPlayer = ccsPlayer->GetZEPlayer();
std::string strPlayerID = "";
if (zpPlayer && !zpPlayer->IsFakeClient())
{
strPlayerID = std::to_string(zpPlayer->IsAuthenticated() ? zpPlayer->GetSteamId64() : zpPlayer->GetUnauthenticatedSteamId64());
strPlayerID = "(" + strPlayerID + ")";
}
std::string strButton = std::to_string(pCaller->GetEntityIndex().Get()) + " " + std::string(pszButtonName);
for (int i = 0; i < GetGlobals()->maxClients; i++)
{
CCSPlayerController* ccsPlayer = CCSPlayerController::FromSlot(i);
if (!ccsPlayer)
continue;
ZEPlayer* zpPlayer = ccsPlayer->GetZEPlayer();
if (!zpPlayer)
continue;
if (zpPlayer->GetButtonWatchMode() % 2 == 1)
ClientPrint(ccsPlayer, HUD_PRINTTALK, " \x02[BW]\x0C %s\1 pressed button \x0C%s\1", strPlayerName.c_str(), strButton.c_str());
if (zpPlayer->GetButtonWatchMode() >= 2)
{
ClientPrint(ccsPlayer, HUD_PRINTCONSOLE, "------------------------------------ [ButtonWatch] ------------------------------------");
ClientPrint(ccsPlayer, HUD_PRINTCONSOLE, "Player: %s %s", strPlayerName.c_str(), strPlayerID.c_str());
ClientPrint(ccsPlayer, HUD_PRINTCONSOLE, "Button: %s", strButton.c_str());
ClientPrint(ccsPlayer, HUD_PRINTCONSOLE, "---------------------------------------------------------------------------------------");
}
}
// Limit each button to only printing out at most once every 5 seconds
int iIndex = pCaller->GetEntityIndex().Get();
mapRecentEnts[iIndex] = true;
CTimer::Create(5.0f, TIMERFLAG_NONE, [iIndex]() {
mapRecentEnts.erase(iIndex);
return -1.0f;
});
}