From 79be9e12d5971308d8571b29428af6dd53ed94a0 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 29 Nov 2021 17:16:18 +0000 Subject: [PATCH] Add dvar to disable elevators entirely --- src/Components/Modules/Elevators.cpp | 44 ++++++++++++++++++++++++++-- src/Components/Modules/Elevators.hpp | 2 ++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Elevators.cpp b/src/Components/Modules/Elevators.cpp index cd71382a..a932782c 100644 --- a/src/Components/Modules/Elevators.cpp +++ b/src/Components/Modules/Elevators.cpp @@ -3,6 +3,7 @@ namespace Components { Game::dvar_t* Elevators::SV_EnableEasyElevators; + Game::dvar_t* Elevators::SV_DisableElevators; __declspec(naked) void Elevators::PM_CorrectAllSolidStub() { @@ -63,6 +64,39 @@ namespace Components } } + __declspec(naked) void Elevators::PM_GroundTraceStub() + { + __asm + { + push eax + mov eax, Elevators::SV_DisableElevators + cmp byte ptr [eax + 16], 1 + pop eax + + // Always skip PM_CorrectAllSolid if SV_DisableElevators is set to 1 + je noElevators + + // Original code + cmp byte ptr [esp + 0x50], 0 + rep movsd + mov esi, [esp + 0x58] + + // Original code flow + push 0x573694 + retn + + noElevators: + + // Original code + rep movsd + mov esi, [esp + 0x58] + + // Jump over call to PM_CorrectAllSolid + push 0x5736AE + retn + } + } + Elevators::Elevators() { Dvar::OnInit([] @@ -70,14 +104,20 @@ namespace Components Elevators::SV_EnableEasyElevators = Game::Dvar_RegisterBool("sv_enableEasyElevators", false, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "Enable easy elevators for trickshotting"); + Elevators::SV_DisableElevators = Game::Dvar_RegisterBool("sv_disableElevators", + false, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, + "Disable elevators"); }); - // Place hook PM_CorrectAllSolid so we may skip PM_Trace check + // Hook PM_CorrectAllSolid so we may skip PM_Trace check Utils::Hook(0x5734F9, Elevators::PM_CorrectAllSolidStub, HOOK_JUMP).install()->quick(); Utils::Hook::Nop(0x5734FE, 1); - // Place hook PM_CheckDuck so we may skip PM_Trace check + // Hook PM_CheckDuck so we may skip PM_Trace check Utils::Hook(0x570ECD, Elevators::PM_CheckDuckStub, HOOK_JUMP).install()->quick(); + + // Hook PM_GroundTrace so me way skip PM_CorrectAllSolid (disable elevators) + Utils::Hook(0x573689, Elevators::PM_GroundTraceStub, HOOK_JUMP).install()->quick(); } Elevators::~Elevators() diff --git a/src/Components/Modules/Elevators.hpp b/src/Components/Modules/Elevators.hpp index f5af25fd..c01b2c98 100644 --- a/src/Components/Modules/Elevators.hpp +++ b/src/Components/Modules/Elevators.hpp @@ -10,8 +10,10 @@ namespace Components private: static Game::dvar_t* SV_EnableEasyElevators; + static Game::dvar_t* SV_DisableElevators; static void PM_CorrectAllSolidStub(); static void PM_CheckDuckStub(); + static void PM_GroundTraceStub(); }; }