-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add buttonwatch - Prints a message every time an entity fires OnPressed to players with buttonwatch enabled - Adds c_bw for players with ADMFLAG_GENERIC to toggle buttonwatch on and off (disabled by default) - Uses output hooking stuff from cs#: https://github.com/roflmuffin/CounterStrikeSharp/blob/f8451c2818a26380b49229655956e3058c3855ff/configs/addons/counterstrikesharp/gamedata/gamedata.json#L223-L228 * Clarify comment and decrease timer delay * Disable buttonwatch by default, as it breaks CS# - Add config cs2fixes.jsonc for configs that require a restart to changes - Fix c_bw using console instead of chat for command echo * Add console printing modes and anti-spam * Remove timer that was needed with old ClientPrint * Delay when user pref is grabbed * Remove this as not being used anymore by bw * Make IO detour more modular * Fix issues * Restructure to move out of entities.cpp/h * adjustments * Fix stupid error from refactor * Null check pActivator --------- Co-authored-by: Vauff <[email protected]>
- Loading branch information
1 parent
85af0af
commit 153ae27
Showing
15 changed files
with
326 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/** | ||
* ============================================================================= | ||
* CS2Fixes | ||
* Copyright (C) 2023-2024 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 "ctimer.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" | ||
#include "detours.h" | ||
#include "cs2fixes.h" | ||
#include "commands.h" | ||
|
||
CON_COMMAND_F(cs2f_enable_button_watch, "INCOMPATIBLE WITH CS#. Whether to enable button watch or not.", FCVAR_LINKED_CONCOMMAND | FCVAR_SPONLY | FCVAR_PROTECTED) | ||
{ | ||
if (args.ArgC() < 2) | ||
{ | ||
Msg("%s %i\n", args[0], IsButtonWatchEnabled()); | ||
return; | ||
} | ||
|
||
if (!V_StringToBool(args[1], false) || !SetupFireOutputInternalDetour()) | ||
mapIOFunctions.erase("buttonwatch"); | ||
else if (!IsButtonWatchEnabled()) | ||
mapIOFunctions["buttonwatch"] = ButtonWatch; | ||
} | ||
|
||
CON_COMMAND_CHAT_FLAGS(bw, "- Toggle button watch display", ADMFLAG_GENERIC) | ||
{ | ||
if (!IsButtonWatchEnabled()) | ||
{ | ||
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; | ||
} | ||
} | ||
|
||
bool IsButtonWatchEnabled() | ||
{ | ||
return std::any_of(mapIOFunctions.begin(), mapIOFunctions.end(), [](const auto& p) { | ||
return p.first == "buttonwatch"; | ||
}); | ||
} | ||
|
||
std::map <int, bool> mapRecentEnts; | ||
void ButtonWatch(const CEntityIOOutput* pThis, CEntityInstance* pActivator, CEntityInstance* pCaller, const CVariant* value, float flDelay) | ||
{ | ||
if (!IsButtonWatchEnabled() || 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(); | ||
|
||
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(((CBaseEntity*)pCaller)->GetName()); | ||
|
||
for (int i = 0; i < gpGlobals->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; | ||
new CTimer(5.0f, true, true, [iIndex]() | ||
{ | ||
mapRecentEnts.erase(iIndex); | ||
return -1.0f; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* ============================================================================= | ||
* CS2Fixes | ||
* Copyright (C) 2023-2024 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/>. | ||
*/ | ||
|
||
#pragma once | ||
#include "detours.h" | ||
|
||
bool IsButtonWatchEnabled(); | ||
void ButtonWatch(const CEntityIOOutput* pThis, CEntityInstance* pActivator, CEntityInstance* pCaller, const CVariant* value, float flDelay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* ============================================================================= | ||
* CS2Fixes | ||
* Copyright (C) 2023-2024 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/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Bandaid needed for #include "string_t.h" to compile... | ||
#ifndef NULL | ||
#define NULL 0 | ||
#endif | ||
|
||
#include <string_t.h> | ||
#include <entityhandle.h> | ||
#include <entitysystem.h> | ||
#include <entityinstance.h> | ||
|
||
struct EntityIOConnectionDesc_t | ||
{ | ||
string_t m_targetDesc; | ||
string_t m_targetInput; | ||
string_t m_valueOverride; | ||
CEntityHandle m_hTarget; | ||
EntityIOTargetType_t m_nTargetType; | ||
int32 m_nTimesToFire; | ||
float m_flDelay; | ||
}; | ||
|
||
struct EntityIOConnection_t : EntityIOConnectionDesc_t | ||
{ | ||
bool m_bMarkedForRemoval; | ||
EntityIOConnection_t* m_pNext; | ||
}; | ||
|
||
struct EntityIOOutputDesc_t | ||
{ | ||
const char* m_pName; | ||
uint32 m_nFlags; | ||
uint32 m_nOutputOffset; | ||
}; | ||
|
||
class CEntityIOOutput | ||
{ | ||
public: | ||
void* vtable; | ||
EntityIOConnection_t* m_pConnections; | ||
EntityIOOutputDesc_t* m_pDesc; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.