diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index a1fc116a..a1747309 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -9,11 +9,23 @@ namespace Components { std::unordered_map> ClientCommand::HandlersSV; + bool ClientCommand::CheatsEnabled; + + ClientCommand::CheatsScopedLock::CheatsScopedLock() + { + CheatsEnabled = true; + } + + ClientCommand::CheatsScopedLock::~CheatsScopedLock() + { + CheatsEnabled = false; + } + bool ClientCommand::CheatsOk(const Game::gentity_s* ent) { const auto entNum = ent->s.number; - if (!(*Game::g_cheats)->current.enabled) + if (!(*Game::g_cheats)->current.enabled && !CheatsEnabled) { Logger::Debug("Cheats are disabled!"); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65)); @@ -351,12 +363,16 @@ namespace Components GSC::Script::AddMethod("Noclip", [](const Game::scr_entref_t entref) // gsc: self Noclip(); { auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); + + CheatsScopedLock cheatsLock; Cmd_Noclip_f(ent, nullptr); }); GSC::Script::AddMethod("Ufo", [](const Game::scr_entref_t entref) // gsc: self Ufo(); { auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); + + CheatsScopedLock cheatsLock; Cmd_UFO_f(ent, nullptr); }); } @@ -502,6 +518,8 @@ namespace Components // Hook call to ClientCommand in SV_ExecuteClientCommand so we may add custom commands Utils::Hook(0x6259FA, ClientCommandStub, HOOK_CALL).install()->quick(); + CheatsEnabled = false; + AddCheatCommands(); AddScriptFunctions(); AddScriptMethods(); diff --git a/src/Components/Modules/ClientCommand.hpp b/src/Components/Modules/ClientCommand.hpp index b6b39cb5..cb545bfe 100644 --- a/src/Components/Modules/ClientCommand.hpp +++ b/src/Components/Modules/ClientCommand.hpp @@ -13,6 +13,15 @@ namespace Components private: static std::unordered_map> HandlersSV; + static bool CheatsEnabled; + + class CheatsScopedLock + { + public: + CheatsScopedLock(); + ~CheatsScopedLock(); + }; + static void ClientCommandStub(int clientNum); static void AddCheatCommands(); static void AddDevelopmentCommands();