diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 62489689..261ca031 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -178,6 +178,11 @@ namespace Components return Dvar::Register(name, username.data(), Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).get(); } + Game::dvar_t* Dvar::SetFromStringByNameExternal(const char* dvar, const char* value) + { + return Game::Dvar_SetFromStringByNameFromSource(dvar, value, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL); + } + Dvar::Dvar() { // set flags of cg_drawFPS to archive @@ -211,6 +216,15 @@ namespace Components // Hook dvar 'name' registration Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).install()->quick(); + + // Don't allow setting cheat protected dvars via menus + Utils::Hook(0x63C897, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); + Utils::Hook(0x63CA96, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); + Utils::Hook(0x63CDB5, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); + Utils::Hook(0x635E47, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); + + // Entirely block setting cheat dvars internally without sv_cheats + //Utils::Hook(0x4F52EC, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); } Dvar::~Dvar() diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 01cae6da..b12ed8c7 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -58,5 +58,7 @@ namespace Components static Utils::Signal RegistrationSignal; static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description); + + static Game::dvar_t* SetFromStringByNameExternal(const char* dvar, const char* value); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 849d26b4..cf10cbd2 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -215,6 +215,8 @@ namespace Game SEH_StringEd_GetString_t SEH_StringEd_GetString = SEH_StringEd_GetString_t(0x44BB30); + Dvar_SetFromStringByName_t Dvar_SetFromStringByName = Dvar_SetFromStringByName_t(0x4F52E0); + Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource = Dvar_SetFromStringByNameFromSource_t(0x4FC770); Dvar_SetStringByName_t Dvar_SetStringByName = Dvar_SetStringByName_t(0x44F060); SL_ConvertToString_t SL_ConvertToString = SL_ConvertToString_t(0x4EC1D0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 998f3738..dd8783fc 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -194,6 +194,12 @@ namespace Game typedef dvar_t* (__cdecl * Dvar_RegisterColor_t)(const char* name, float r, float g, float b, float a, int flags, const char* description); extern Dvar_RegisterColor_t Dvar_RegisterColor; + typedef dvar_t*(__cdecl * Dvar_SetFromStringByName_t)(const char* cvar, const char* value); + extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName; + + typedef dvar_t*(__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* cvar, const char* value, DvarSetSource source); + extern Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource; + typedef void(__cdecl * Dvar_SetStringByName_t)(const char* cvar, const char* value); extern Dvar_SetStringByName_t Dvar_SetStringByName; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 8b64af60..9ff1a83e 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -87,6 +87,14 @@ namespace Game DVAR_FLAG_NONEXISTENT = 0xFFFFFFFF //no such dvar } dvar_flag; + enum DvarSetSource + { + DVAR_SOURCE_INTERNAL = 0x0, + DVAR_SOURCE_EXTERNAL = 0x1, + DVAR_SOURCE_SCRIPT = 0x2, + DVAR_SOURCE_DEVGUI = 0x3, + }; + typedef enum { DVAR_TYPE_BOOL = 0,