From d948024895b32ac26c4191ff1d721fc341930c25 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 4 Oct 2021 21:03:56 +0100 Subject: [PATCH] Using new asm wrapper made by laupetin --- src/Components/Modules/Dvar.cpp | 41 ++++++++++++++++++++------------- src/Components/Modules/Dvar.hpp | 5 ++-- src/Game/Functions.cpp | 22 ++++++++---------- src/Game/Functions.hpp | 4 ++-- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 4b0eece8..71034d53 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -190,6 +190,25 @@ namespace Components Dvar::RegistrationSignal.connect(callback); } + void Dvar::DvarReset(Game::dvar_t* var, Game::DvarSetSource source) + { + assert(var != nullptr); + + Game::Dvar_SetVariant(var, var->reset, source); + } + + void Dvar::ResetDvarsValue() + { + auto it = Dvar::ChangedDvars.begin(); + while (it != Dvar::ChangedDvars.end()) + { + auto var = Dvar::Var(*it).get(); + assert(var != nullptr); + Dvar::DvarReset(var, Game::DVAR_SOURCE_INTERNAL); + it = Dvar::ChangedDvars.erase(it); + } + } + Game::dvar_t* Dvar::RegisterName(const char* name, const char* /*default*/, Game::dvar_flag flag, const char* description) { // Run callbacks @@ -259,26 +278,13 @@ namespace Components Game::dvar_t* Dvar::SetFromStringByNameExternal(const char* dvar, const char* value) { - Dvar::ChangedDvars.push_back(dvar); return Game::Dvar_SetFromStringByNameFromSource(dvar, value, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL); } - void Dvar::Dvar_Reset(Game::dvar_t* var, Game::DvarSetSource source) + void Dvar::DvarSetFromStringByNameStub(const char* var, const char* value) { - assert(var != nullptr); - OutputDebugStringA(Utils::String::VA("Dvar pointer: %p\n")); - Game::Dvar_SetVariant(var, var->reset, source); - } - - void Dvar::ResetDvarsValue() - { - auto it = Dvar::ChangedDvars.begin(); - while (it != Dvar::ChangedDvars.end()) - { - auto var = Dvar::Var(*it).get(); - Dvar::Dvar_Reset(var, Game::DVAR_SOURCE_INTERNAL); - it = Dvar::ChangedDvars.erase(it); - } + Dvar::ChangedDvars.push_back(var); + Utils::Hook::Call(0x4F52E0)(var, value); } Dvar::Dvar() @@ -348,6 +354,9 @@ namespace Components // Entirely block setting cheat dvars internally without sv_cheats //Utils::Hook(0x4F52EC, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); + + // Hook Dvar_SetFromStringByName inside CG_SetClientDvarFromServer so we can reset dvars when the player leaves the server + Utils::Hook(0x59386A, Dvar::DvarSetFromStringByNameStub, HOOK_CALL).install()->quick(); } Dvar::~Dvar() diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 2a23ef8e..9406e4c4 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -50,17 +50,18 @@ namespace Components template static Var Register(const char* name, T value, Flag flag, const char* description); template static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description); - static void Dvar_Reset(Game::dvar_t* var, Game::DvarSetSource source); + static void DvarReset(Game::dvar_t* var, Game::DvarSetSource source); static void ResetDvarsValue(); private: static Utils::Signal RegistrationSignal; + static std::vector ChangedDvars; 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); static Game::dvar_t* SetFromStringByNameSafeExternal(const char* dvar, const char* value); - static std::vector ChangedDvars; + static void DvarSetFromStringByNameStub(const char* var, const char* value); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index ff8a4c45..a4dbd637 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -1055,22 +1055,20 @@ namespace Game { __asm { - push eax pushad - mov edi, [esp + 2Ch] // name - push edi + mov eax, [esp + 0x4 + 0x20] // dvar + push[esp + 0x18 + 0x20] // source + push[esp + 0x18 + 0x20] // value + push[esp + 0x18 + 0x20] // value + push[esp + 0x18 + 0x20] // value + push[esp + 0x18 + 0x20] // value - mov edi, [esp + 2Ch] // type + mov ebx, 0x647400 + call ebx + add esp, 0x14 - mov eax, 5BB1B0h - call eax - - add esp, 4h - - mov [esp + 20h], eax popad - pop eax retn } @@ -1493,7 +1491,7 @@ namespace Game } } - __declspec(naked) void Dvar_SetVariant(dvar_t*, DvarValue, int) + __declspec(naked) void Dvar_SetVariant(dvar_t*, DvarValue, DvarSetSource) { __asm { diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 80580e69..d7d3959f 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1077,6 +1077,6 @@ namespace Game void AimAssist_UpdateTweakables(int localClientNum); void AimAssist_UpdateAdsLerp(const AimInput* input); - - void Dvar_SetVariant(dvar_t* var, DvarValue value, int source); + + void Dvar_SetVariant(dvar_t* var, DvarValue value, DvarSetSource source); }