From e596dd38480da2c5d5ac0f3dc55171fef6835931 Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 23 Jan 2019 01:36:31 +0100 Subject: [PATCH] Added ultrawide patch --- src/Components/Modules/QuickPatch.cpp | 61 +++++++++++++++++++++++++++ src/Components/Modules/QuickPatch.hpp | 5 +++ 2 files changed, 66 insertions(+) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 7d5b9ed7..40f50e62 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -191,6 +191,63 @@ 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 = + { + "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"); + + // register enumeration dvar + return Game::Dvar_RegisterEnum(name, values.data(), defaultVal, flags, description); + } + + void QuickPatch::SetAspectRatio() + { + // set the aspect ratio + Utils::Hook::Set(0x66E1C78, r_customAspectRatio->current.value); + } + + __declspec(naked) void QuickPatch::SetAspectRatioStub() + { + __asm + { + cmp eax, 4; + ja goToDefaultCase; + je useCustomRatio; + + // execute switch statement code + push 0x005063FC; + retn; + + goToDefaultCase: + push 0x005064FC; + retn; + + useCustomRatio: + // set custom resolution + pushad; + call SetAspectRatio; + popad; + + // set widescreen to 1 + mov eax, 1; + + // continue execution + push 0x00506495; + retn; + } + } + QuickPatch::QuickPatch() { QuickPatch::FrameTime = 0; @@ -209,6 +266,10 @@ namespace Components // Javelin fix 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(); + // 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 7b07d545..e97bd065 100644 --- a/src/Components/Modules/QuickPatch.hpp +++ b/src/Components/Modules/QuickPatch.hpp @@ -32,5 +32,10 @@ namespace Components static Game::dvar_t* sv_enableBounces; static void BounceStub(); + + static Game::dvar_t* 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(); }; }