Skip to content

Commit

Permalink
Disable buttonwatch by default, as it breaks CS#
Browse files Browse the repository at this point in the history
- Add config cs2fixes.jsonc for configs that require a restart to changes
- Fix c_bw using console instead of chat for command echo
  • Loading branch information
Frozen-H2O committed Jul 10, 2024
1 parent 5959487 commit 29820fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions configs/cs2fixes.jsonc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Configs in this file require a server restart to change
{
"enable_button_watch": false // Whether to enable button watch or not. CS# BREAKS WITH THIS ENABLED.
}
24 changes: 22 additions & 2 deletions src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "votemanager.h"
#include "map_votes.h"
#include <vector>
#include <fstream>
#include "vendor/nlohmann/json.hpp"

using json = nlohmann::json;

extern IVEngineServer2 *g_pEngineServer2;
extern CGameEntitySystem *g_pEntitySystem;
Expand Down Expand Up @@ -1416,16 +1420,32 @@ CON_COMMAND_CHAT_FLAGS(add_dc, "<name> <SteamID 64> <IP Address> - Adds a fake p

CON_COMMAND_CHAT_FLAGS(bw, "- Toggle button watch display", ADMFLAG_GENERIC)
{

std::ifstream ifsConfig((std::string(Plat_GetGameDirectory()) + "\\csgo\\addons\\cs2fixes\\configs\\cs2fixes.jsonc"), std::fstream::in);
if (!ifsConfig.is_open())
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Button watch is disabled on this server.");
return;
}

json jConfig = json::parse(ifsConfig, nullptr, true, true);
if (jConfig.empty() || !jConfig.value("enable_button_watch", false))
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Button watch is disabled on this server.");
return;
}


if (!player)
{
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console.");
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_PRINTCONSOLE, CHAT_PREFIX "Something went wrong...");
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Something went wrong...");
return;
}

Expand Down
16 changes: 16 additions & 0 deletions src/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@
#include "serversideclient.h"
#include "networksystem/inetworkserializer.h"
#include "map_votes.h"
#include <fstream>
#include "vendor/nlohmann/json.hpp"
#include "tier0/vprof.h"

#include "tier0/memdbgon.h"


using json = nlohmann::json;

extern CGlobalVars *gpGlobals;
extern CGameEntitySystem *g_pEntitySystem;
extern IGameEventManager2 *g_gameEventManager;
Expand Down Expand Up @@ -596,6 +601,17 @@ bool InitDetours(CGameConfig *gameConfig)

FOR_EACH_VEC(g_vecDetours, i)
{
if (!V_strcmp(g_vecDetours[i]->GetName(), "CEntityIOOutput_FireOutputInternal"))
{
std::ifstream ifsConfig((std::string(Plat_GetGameDirectory()) + "\\csgo\\addons\\cs2fixes\\configs\\cs2fixes.jsonc"), std::fstream::in);
if (!ifsConfig.is_open())
continue;

json jConfig = json::parse(ifsConfig, nullptr, true, true);
if (jConfig.empty() || !jConfig.value("enable_button_watch", false))
continue;
}

if (!g_vecDetours[i]->CreateDetour(gameConfig))
success = false;

Expand Down

0 comments on commit 29820fa

Please sign in to comment.