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

88 lines
1.8 KiB
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
2017-01-19 16:23:59 -05:00
namespace Components
{
2022-08-10 18:21:58 -04:00
Dvar::Var Lean::BGLean;
2017-01-19 16:23:59 -05:00
Game::kbutton_t Lean::in_leanleft;
Game::kbutton_t Lean::in_leanright;
void Lean::IN_LeanLeft_Up()
{
2022-08-10 18:21:58 -04:00
Game::IN_KeyUp(&in_leanleft);
2017-01-19 16:23:59 -05:00
}
void Lean::IN_LeanLeft_Down()
{
2022-08-10 18:21:58 -04:00
Game::IN_KeyDown(&in_leanleft);
2017-01-19 16:23:59 -05:00
}
void Lean::IN_LeanRight_Up()
{
2022-08-10 18:21:58 -04:00
Game::IN_KeyUp(&in_leanright);
2017-01-19 16:23:59 -05:00
}
void Lean::IN_LeanRight_Down()
{
2022-08-10 18:21:58 -04:00
Game::IN_KeyDown(&in_leanright);
2017-01-19 16:23:59 -05:00
}
2022-08-10 18:21:58 -04:00
void Lean::SetLeanFlags(Game::usercmd_s* cmd)
2017-01-19 16:23:59 -05:00
{
2022-08-10 18:21:58 -04:00
if ((in_leanleft.active || in_leanleft.wasPressed) && BGLean.get<bool>())
2017-01-19 16:23:59 -05:00
{
2022-08-10 18:21:58 -04:00
cmd->buttons |= Game::CMD_BUTTON_LEAN_LEFT;
2017-01-19 16:23:59 -05:00
}
2022-08-10 18:21:58 -04:00
if ((in_leanright.active || in_leanright.wasPressed) && BGLean.get<bool>())
2017-01-19 16:23:59 -05:00
{
2022-08-10 18:21:58 -04:00
cmd->buttons |= Game::CMD_BUTTON_LEAN_RIGHT;
2017-01-19 16:23:59 -05:00
}
2022-08-10 18:21:58 -04:00
in_leanleft.wasPressed = false;
in_leanright.wasPressed = false;
2017-01-19 16:23:59 -05:00
}
2022-08-10 18:21:58 -04:00
void __declspec(naked) Lean::CL_CmdButtons_Stub()
2017-01-19 16:23:59 -05:00
{
__asm
{
// CL_CmdButtons
mov ecx, 5A6510h
call ecx
2017-02-01 07:44:25 -05:00
pushad
2017-01-19 16:23:59 -05:00
push esi
2022-08-10 18:21:58 -04:00
call SetLeanFlags
2017-01-19 16:23:59 -05:00
pop esi
2017-02-01 07:44:25 -05:00
popad
2017-01-19 16:23:59 -05:00
retn
}
}
2022-08-10 18:21:58 -04:00
void Lean::PM_UpdateLean_Stub(Game::playerState_s* ps, float msec, Game::usercmd_s* cmd, void(*capsuleTrace)(Game::trace_t*, const float*, const float*, const Game::Bounds*, int, int))
{
if (BGLean.get<bool>())
{
Game::PM_UpdateLean(ps, msec, cmd, capsuleTrace);
}
}
2017-01-19 16:23:59 -05:00
Lean::Lean()
{
2022-08-10 18:21:58 -04:00
Command::AddRaw("+leanleft", IN_LeanLeft_Down, true);
Command::AddRaw("-leanleft", IN_LeanLeft_Up, true);
Command::AddRaw("+leanright", IN_LeanRight_Down, true);
Command::AddRaw("-leanright", IN_LeanRight_Up, true);
Utils::Hook(0x5A6D84, CL_CmdButtons_Stub, HOOK_CALL).install()->quick();
2017-01-19 16:23:59 -05:00
2022-08-10 18:21:58 -04:00
Utils::Hook(0x4A0C72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
Utils::Hook(0x4A0D72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
2017-01-19 16:23:59 -05:00
2022-08-10 18:21:58 -04:00
BGLean = Dvar::Register<bool>("bg_lean", true,
Game::DVAR_CODINFO, "Enable CoD4 leaning");
2017-01-19 16:23:59 -05:00
}
}