From 133d1b43d83f4a86a7b2a02b48fedf0d27a6b569 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 4 Oct 2021 19:11:37 +0100 Subject: [PATCH] New asm wrapper --- src/Components/Modules/Dvar.cpp | 13 ++++++++++--- src/Components/Modules/Dvar.hpp | 1 + src/Game/Functions.cpp | 26 ++++++++++++++------------ src/Game/Functions.hpp | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index a4bf57f4..4b0eece8 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -263,14 +263,21 @@ namespace Components return Game::Dvar_SetFromStringByNameFromSource(dvar, value, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL); } + void Dvar::Dvar_Reset(Game::dvar_t* var, Game::DvarSetSource source) + { + assert(var != nullptr); + OutputDebugStringA(Utils::String::VA("Dvar pointer: %p\n")); + Game::Dvar_SetVariant(var, var->reset, source); + } + void Dvar::ResetDvarsValue() { - for (auto it = Dvar::ChangedDvars.begin(); it != Dvar::ChangedDvars.end(); ++it) + auto it = Dvar::ChangedDvars.begin(); + while (it != Dvar::ChangedDvars.end()) { auto var = Dvar::Var(*it).get(); - Game::Dvar_SetVariant(var, var->reset, Game::DVAR_SOURCE_INTERNAL); + Dvar::Dvar_Reset(var, Game::DVAR_SOURCE_INTERNAL); it = Dvar::ChangedDvars.erase(it); - --it; // Go back one step because of erase } } diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 894714c0..2a23ef8e 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -50,6 +50,7 @@ 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 ResetDvarsValue(); private: diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index b0893511..ff8a4c45 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -1493,29 +1493,31 @@ namespace Game } } - __declspec(naked) void Dvar_SetVariant(dvar_t*, DvarValue, DvarSetSource) + __declspec(naked) void Dvar_SetVariant(dvar_t*, DvarValue, int) { __asm { pushad - mov ecx, [esp + 20h + 20h] - mov edx, [esp + 24h + 20h] // source - push edx + mov edx, [esp + 8h + 20h] // First 4 bytes of DvarValue + mov ecx, [esp + 18h + 20h] // Source + push ecx // Push from right to left - mov edx, [esp + 8h + 20h] // dvar pointer + mov ecx, [esp + 8h + 20h] // dvar_t pointer, because of last push it's not at esp + 4 anymore - sub esp, 10h // What does this mean for the offsets ? Copy paste + sub esp, 10h // Reserve space for DvarValue mov eax, esp - mov [eax], ecx // DvarValue ?? Legit have no clue + mov [eax], edx // DvarValue - mov ecx, [esp + 0Ch+ 20h] - mov [eax + 4], edx // First arg is dvar pointer - mov edx, [esp + 10h + 20h] - mov [eax + 8], ecx + // 20h + 10h because of sub esp, 10h + mov edx, [esp + 10h + 30h] // Second 4 bytes of DvarValue + mov [eax + 4], edx + mov edx, [esp + 16h + 30h] // Third 4 bytes of DvarValue + mov [eax + 8], edx + mov edx, [esp + 1Ah + 30h] // Fourth 4 bytes of DvarValue mov [eax + 0Ch], edx - mov eax, [esp + 8h + 20h] // var pointer + mov eax, [ecx] // dvar_t pointer mov ebx, 0x647400 call ebx diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index d8c72fa3..80580e69 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1078,5 +1078,5 @@ namespace Game void AimAssist_UpdateTweakables(int localClientNum); void AimAssist_UpdateAdsLerp(const AimInput* input); - void Dvar_SetVariant(dvar_t* var, DvarValue value, DvarSetSource source); + void Dvar_SetVariant(dvar_t* var, DvarValue value, int source); }