iw4x-client/src/Components/Modules/Elevators.cpp

127 lines
2.6 KiB
C++
Raw Normal View History

2021-11-29 07:26:53 -05:00
#include "STDInclude.hpp"
namespace Components
{
Game::dvar_t* Elevators::SV_EnableEasyElevators;
2021-11-29 12:16:18 -05:00
Game::dvar_t* Elevators::SV_DisableElevators;
2021-11-29 07:26:53 -05:00
__declspec(naked) void Elevators::PM_CorrectAllSolidStub()
{
__asm
{
push ecx
mov ecx, Elevators::SV_EnableEasyElevators
cmp byte ptr [ecx + 16], 1
pop ecx
// Always elevate if SV_EnableEasyElevators is set to 1
je elevate
// Original code
cmp byte ptr [eax + 0x29], 0
// Original code flow
jz elevate
2021-11-29 09:08:44 -05:00
// Go to conditional check for the loop
2021-11-29 07:26:53 -05:00
push 0x5734FF
retn
elevate:
2021-11-29 09:08:44 -05:00
// Continue with loop execution
2021-11-29 07:26:53 -05:00
push 0x57353D
retn
}
}
__declspec(naked) void Elevators::PM_CheckDuckStub()
{
__asm
{
push eax
mov eax, Elevators::SV_EnableEasyElevators
cmp byte ptr [eax + 16], 1
pop eax
// Always stand if SV_EnableEasyElevators is set to 1
je stand
// Original code
cmp byte ptr [esp + 0x38], 0
// Original code flow
jnz noStand
stand:
2021-11-29 09:08:44 -05:00
// Player is allowed to stand
2021-11-29 07:26:53 -05:00
push 0x570ED4
retn
noStand:
2021-11-29 09:08:44 -05:00
// Player will remain ducked
2021-11-29 07:26:53 -05:00
push 0x570EF4
retn
}
}
2021-11-29 12:16:18 -05:00
__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
}
}
2021-11-29 07:26:53 -05:00
Elevators::Elevators()
{
Dvar::OnInit([]
{
Elevators::SV_EnableEasyElevators = Game::Dvar_RegisterBool("sv_enableEasyElevators",
false, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED,
"Enable easy elevators for trickshotting");
2021-11-29 12:16:18 -05:00
Elevators::SV_DisableElevators = Game::Dvar_RegisterBool("sv_disableElevators",
false, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED,
"Disable elevators");
2021-11-29 07:26:53 -05:00
});
2021-11-29 12:16:18 -05:00
// Hook PM_CorrectAllSolid so we may skip PM_Trace check
2021-11-29 07:26:53 -05:00
Utils::Hook(0x5734F9, Elevators::PM_CorrectAllSolidStub, HOOK_JUMP).install()->quick();
Utils::Hook::Nop(0x5734FE, 1);
2021-11-29 12:16:18 -05:00
// Hook PM_CheckDuck so we may skip PM_Trace check
2021-11-29 07:26:53 -05:00
Utils::Hook(0x570ECD, Elevators::PM_CheckDuckStub, HOOK_JUMP).install()->quick();
2021-11-29 12:16:18 -05:00
// Hook PM_GroundTrace so me way skip PM_CorrectAllSolid (disable elevators)
Utils::Hook(0x573689, Elevators::PM_GroundTraceStub, HOOK_JUMP).install()->quick();
2021-11-29 07:26:53 -05:00
}
Elevators::~Elevators()
{
}
}