From b77e95a846b67bfa77678073f329a3ec8ac62bf4 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 10 Nov 2021 19:48:00 +0000 Subject: [PATCH 1/2] Refactor quick patch a bit --- src/Components/Modules/QuickPatch.cpp | 38 +++++++++++++-------------- src/Components/Modules/QuickPatch.hpp | 4 +-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 1ab8479b..33c8f84f 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -3,6 +3,7 @@ namespace Components { int QuickPatch::FrameTime = 0; + Dvar::Var QuickPatch::r_customAspectRatio; void QuickPatch::UnlockStats() { @@ -139,16 +140,15 @@ namespace Components } } - bool QuickPatch::InvalidNameCheck(char *dest, char *source, int size) + bool QuickPatch::InvalidNameCheck(char* dest, const char* source, int size) { - strncpy(dest, source, size - 1); - dest[size - 1] = 0; + Utils::Hook::Call(0x4D6F80)(dest, source, size); // I_strncpyz for (int i = 0; i < size - 1; i++) { if (!dest[i]) break; - if (dest[i] > 125 || dest[i] < 32 || dest[i] == '%') + if (dest[i] > 125 || dest[i] < 32 || dest[i] == '%') { return false; } @@ -172,7 +172,7 @@ namespace Components push 1; push kick_reason; push edi; - mov eax, 0x004D1600; + mov eax, 0x004D1600; // SV_DropClientInternal call eax; add esp, 12; popad; @@ -184,7 +184,6 @@ namespace Components } Game::dvar_t* QuickPatch::g_antilag; - __declspec(naked) void QuickPatch::ClientEventsFireWeaponStub() { __asm @@ -268,30 +267,31 @@ namespace Components } } - Game::dvar_t* QuickPatch::r_customAspectRatio; Game::dvar_t* QuickPatch::Dvar_RegisterAspectRatioDvar(const char* name, char**, int defaultVal, int flags, const char* description) { - static std::vector < char * > values = + static char* r_aspectRatioEnum[] = { - const_cast("auto"), - const_cast("standard"), - const_cast("wide 16:10"), - const_cast("wide 16:9"), - const_cast("custom"), - nullptr, + "auto", + "standard", + "wide 16:10", + "wide 16:9", + "custom", + nullptr }; // register custom aspect ratio dvar - r_customAspectRatio = Game::Dvar_RegisterFloat("r_customAspectRatio", 16.0f / 9.0f, 4.0f / 3.0f, 63.0f / 9.0f, flags, "Screen aspect ratio. Divide the width by the height in order to get the aspect ratio value. For example: 16 / 9 = 1,77"); + QuickPatch::r_customAspectRatio = Dvar::Register("r_customAspectRatio", + 16.0f / 9.0f, 4.0f / 3.0f, 63.0f / 9.0f, flags, + "Screen aspect ratio. Divide the width by the height in order to get the aspect ratio value. For example: 16 / 9 = 1,77"); // register enumeration dvar - return Game::Dvar_RegisterEnum(name, values.data(), defaultVal, flags, description); + return Game::Dvar_RegisterEnum(name, r_aspectRatioEnum, defaultVal, flags, description); } void QuickPatch::SetAspectRatio() { // set the aspect ratio - Utils::Hook::Set(0x66E1C78, r_customAspectRatio->current.value); + Utils::Hook::Set(0x66E1C78, r_customAspectRatio.get()); } __declspec(naked) void QuickPatch::SetAspectRatioStub() @@ -483,8 +483,8 @@ namespace Components Utils::Hook(0x578F52, QuickPatch::JavelinResetHookStub, HOOK_JUMP).install()->quick(); // Add ultrawide support - Utils::Hook(0x0051B13B, QuickPatch::Dvar_RegisterAspectRatioDvar, HOOK_CALL).install()->quick(); - Utils::Hook(0x005063F3, QuickPatch::SetAspectRatioStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x51B13B, QuickPatch::Dvar_RegisterAspectRatioDvar, HOOK_CALL).install()->quick(); + Utils::Hook(0x5063F3, QuickPatch::SetAspectRatioStub, HOOK_JUMP).install()->quick(); // Make sure preDestroy is called when the game shuts down Scheduler::OnShutdown(Loader::PreDestroy); diff --git a/src/Components/Modules/QuickPatch.hpp b/src/Components/Modules/QuickPatch.hpp index 008f4a05..6b13a5a1 100644 --- a/src/Components/Modules/QuickPatch.hpp +++ b/src/Components/Modules/QuickPatch.hpp @@ -28,13 +28,13 @@ namespace Components static void JavelinResetHookStub(); - static bool InvalidNameCheck(char *dest, char *source, int size); + static bool InvalidNameCheck(char* dest, const char* source, int size); static void InvalidNameStub(); static Game::dvar_t* sv_enableBounces; static void BounceStub(); - static Game::dvar_t* r_customAspectRatio; + static Dvar::Var r_customAspectRatio; static Game::dvar_t* Dvar_RegisterAspectRatioDvar(const char* name, char** enumValues, int defaultVal, int flags, const char* description); static void SetAspectRatioStub(); static void SetAspectRatio(); From f6c973bc76de9a33ef56b2d1559b75dc57b21eec Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 11 Nov 2021 16:47:42 +0000 Subject: [PATCH 2/2] Make DvarRegisterEnum accept const char** --- src/Components/Modules/QuickPatch.cpp | 2 +- src/Game/Functions.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 33c8f84f..59691749 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -269,7 +269,7 @@ namespace Components Game::dvar_t* QuickPatch::Dvar_RegisterAspectRatioDvar(const char* name, char**, int defaultVal, int flags, const char* description) { - static char* r_aspectRatioEnum[] = + static const char* r_aspectRatioEnum[] = { "auto", "standard", diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 2569dbcf..ae4198b9 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -247,7 +247,7 @@ namespace Game typedef dvar_t* (__cdecl * Dvar_RegisterInt_t)(const char* name, int defaultVal, int min, int max, int flags, const char* description); extern Dvar_RegisterInt_t Dvar_RegisterInt; - typedef dvar_t* (__cdecl * Dvar_RegisterEnum_t)(const char* name, char** enumValues, int defaultVal, int flags, const char* description); + typedef dvar_t* (__cdecl * Dvar_RegisterEnum_t)(const char* name, const char** enumValues, int defaultVal, int flags, const char* description); extern Dvar_RegisterEnum_t Dvar_RegisterEnum; typedef dvar_t* (__cdecl * Dvar_RegisterString_t)(const char* name, const char* defaultVal, int, const char*);