From 725c08afebdbe51aec8c79844a8f234a75fcee49 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 24 Jul 2022 01:08:01 +0200 Subject: [PATCH 1/2] [Script] Remove builtin God, demigod, notarget --- src/Components/Modules/ClientCommand.cpp | 69 ++---------------------- src/Components/Modules/ClientCommand.hpp | 4 +- src/Game/Structs.hpp | 2 +- 3 files changed, 6 insertions(+), 69 deletions(-) diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index 48077a44..fb052c94 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -26,11 +26,11 @@ namespace Components return true; } - void ClientCommand::Add(const char* name, std::function callback) + void ClientCommand::Add(const char* name, const std::function& callback) { const auto command = Utils::String::ToLower(name); - ClientCommand::HandlersSV[command] = std::move(callback); + ClientCommand::HandlersSV[command] = callback; } void ClientCommand::ClientCommandStub(const int clientNum) @@ -52,7 +52,7 @@ namespace Components return; } - Utils::Hook::Call(0x416790)(clientNum); + Utils::Hook::Call(0x416790)(clientNum); } void ClientCommand::AddCheatCommands() @@ -351,69 +351,6 @@ namespace Components void ClientCommand::AddScriptFunctions() { - Script::AddMethod("God", [](Game::scr_entref_t entref) // gsc: God(); - { - auto* ent = Game::GetEntity(entref); - - if (Game::Scr_GetNumParam() >= 1) - { - if (Game::Scr_GetInt(0)) - { - ent->flags |= Game::FL_GODMODE; - } - else - { - ent->flags &= ~Game::FL_GODMODE; - } - } - else - { - ent->flags ^= Game::FL_GODMODE; - } - }); - - Script::AddMethod("Demigod", [](Game::scr_entref_t entref) // gsc: Demigod(); - { - auto* ent = Game::GetEntity(entref); - - if (Game::Scr_GetNumParam() >= 1) - { - if (Game::Scr_GetInt(0)) - { - ent->flags |= Game::FL_DEMI_GODMODE; - } - else - { - ent->flags &= ~Game::FL_DEMI_GODMODE; - } - } - else - { - ent->flags ^= Game::FL_DEMI_GODMODE; - } - }); - - Script::AddMethod("Notarget", [](Game::scr_entref_t entref) // gsc: Notarget(); - { - auto* ent = Game::GetEntity(entref); - - if (Game::Scr_GetNumParam() >= 1) - { - if (Game::Scr_GetInt(0)) - { - ent->flags |= Game::FL_NOTARGET; - } - else - { - ent->flags &= ~Game::FL_NOTARGET; - } - } - else - { - ent->flags ^= Game::FL_NOTARGET; - } - }); - Script::AddFunction("DropAllBots", [] // gsc: DropAllBots(); { Game::SV_DropAllBots(); diff --git a/src/Components/Modules/ClientCommand.hpp b/src/Components/Modules/ClientCommand.hpp index 984b597f..60019358 100644 --- a/src/Components/Modules/ClientCommand.hpp +++ b/src/Components/Modules/ClientCommand.hpp @@ -7,13 +7,13 @@ namespace Components public: ClientCommand(); - static void Add(const char* name, std::function callback); + static void Add(const char* name, const std::function& callback); static bool CheatsOk(const Game::gentity_s* ent); private: static std::unordered_map> HandlersSV; - static void ClientCommandStub(const int clientNum); + static void ClientCommandStub(int clientNum); static void AddCheatCommands(); static void AddDevelopmentCommands(); static void AddScriptFunctions(); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 0d6b250b..efe17a76 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -296,7 +296,7 @@ namespace Game CON_BUILTIN_CHANNEL_COUNT, }; - enum entityFlag + enum { FL_GODMODE = 0x1, FL_DEMI_GODMODE = 0x2, From 0d530ef36e7ae94170970d1d78fe1193c12bbcc7 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 24 Jul 2022 12:37:58 +0200 Subject: [PATCH 2/2] [Structs] Use binary left shift in enum --- src/Game/Structs.hpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index efe17a76..af92e04d 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -298,24 +298,24 @@ namespace Game enum { - FL_GODMODE = 0x1, - FL_DEMI_GODMODE = 0x2, - FL_NOTARGET = 0x4, - FL_NO_KNOCKBACK = 0x8, - FL_NO_RADIUS_DAMAGE = 0x10, - FL_SUPPORTS_LINKTO = 0x1000, - FL_NO_AUTO_ANIM_UPDATE = 0x2000, - FL_GRENADE_TOUCH_DAMAGE = 0x4000, - FL_STABLE_MISSILES = 0x20000, - FL_REPEAT_ANIM_UPDATE = 0x40000, - FL_VEHICLE_TARGET = 0x80000, - FL_GROUND_ENT = 0x100000, - FL_CURSOR_HINT = 0x200000, - FL_MISSILE_ATTRACTOR = 0x800000, - FL_WEAPON_BEING_GRABBED = 0x1000000, - FL_DELETE = 0x2000000, - FL_BOUNCE = 0x4000000, - FL_MOVER_SLIDE = 0x8000000 + FL_GODMODE = 1 << 0, + FL_DEMI_GODMODE = 1 << 1, + FL_NOTARGET = 1 << 2, + FL_NO_KNOCKBACK = 1 << 3, + FL_NO_RADIUS_DAMAGE = 1 << 4, + FL_SUPPORTS_LINKTO = 1 << 12, + FL_NO_AUTO_ANIM_UPDATE = 1 << 13, + FL_GRENADE_TOUCH_DAMAGE = 1 << 14, + FL_STABLE_MISSILES = 1 << 17, + FL_REPEAT_ANIM_UPDATE = 1 << 18, + FL_VEHICLE_TARGET = 1 << 19, + FL_GROUND_ENT = 1 << 20, + FL_CURSOR_HINT = 1 << 21, + FL_MISSILE_ATTRACTOR = 1 << 23, + FL_WEAPON_BEING_GRABBED = 1 << 24, + FL_DELETE = 1 << 25, + FL_BOUNCE = 1 << 26, + FL_MOVER_SLIDE = 1 << 27 }; enum ClassNum : unsigned int