[ClientCommand]: Improve GSC methods (#962)

This commit is contained in:
Edo 2023-04-22 14:58:15 +02:00 committed by GitHub
parent 4dcbe32c54
commit 42e5132c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -9,11 +9,23 @@ namespace Components
{
std::unordered_map<std::string, std::function<void(Game::gentity_s*, const Command::ServerParams*)>> 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();

View File

@ -13,6 +13,15 @@ namespace Components
private:
static std::unordered_map<std::string, std::function<void(Game::gentity_s*, const Command::ServerParams*)>> HandlersSV;
static bool CheatsEnabled;
class CheatsScopedLock
{
public:
CheatsScopedLock();
~CheatsScopedLock();
};
static void ClientCommandStub(int clientNum);
static void AddCheatCommands();
static void AddDevelopmentCommands();