[Lean] Add option to disable
This commit is contained in:
@ -241,12 +241,12 @@ namespace Components
|
||||
mov dl, byte ptr[edi + 1Ah] // to_forwardMove
|
||||
mov dh, byte ptr[edi + 1Bh] // to_rightMove
|
||||
|
||||
mov[esp + 30h], dx // to_buttons
|
||||
mov [esp + 30h], dx // to_buttons
|
||||
|
||||
mov dl, byte ptr[ebp + 1Ah] // from_forwardMove
|
||||
mov dh, byte ptr[ebp + 1Bh] // from_rightMove
|
||||
mov dl, byte ptr [ebp + 1Ah] // from_forwardMove
|
||||
mov dh, byte ptr [ebp + 1Bh] // from_rightMove
|
||||
|
||||
mov[esp + 2Ch], dx // from_buttons
|
||||
mov [esp + 2Ch], dx // from_buttons
|
||||
|
||||
// return back
|
||||
push 0x60E40E
|
||||
@ -261,7 +261,7 @@ namespace Components
|
||||
|
||||
if (Game::MSG_ReadBit(msg))
|
||||
{
|
||||
short movementBits = static_cast<short>(key ^ Game::MSG_ReadBits(msg, 16));
|
||||
const auto movementBits = static_cast<short>(key ^ Game::MSG_ReadBits(msg, 16));
|
||||
|
||||
forward = static_cast<char>(movementBits);
|
||||
right = static_cast<char>(movementBits >> 8);
|
||||
@ -274,6 +274,11 @@ namespace Components
|
||||
|
||||
to->forwardmove = forward;
|
||||
to->rightmove = right;
|
||||
|
||||
if (!Lean::BGLean.get<bool>())
|
||||
{
|
||||
to->buttons &= ~(Game::CMD_BUTTON_LEAN_RIGHT | Game::CMD_BUTTON_LEAN_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void Gamepad::MSG_ReadDeltaUsercmdKeyStub()
|
||||
|
@ -2,46 +2,48 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
Dvar::Var Lean::BGLean;
|
||||
|
||||
Game::kbutton_t Lean::in_leanleft;
|
||||
Game::kbutton_t Lean::in_leanright;
|
||||
|
||||
void Lean::IN_LeanLeft_Up()
|
||||
{
|
||||
Game::IN_KeyUp(&Lean::in_leanleft);
|
||||
Game::IN_KeyUp(&in_leanleft);
|
||||
}
|
||||
|
||||
void Lean::IN_LeanLeft_Down()
|
||||
{
|
||||
Game::IN_KeyDown(&Lean::in_leanleft);
|
||||
Game::IN_KeyDown(&in_leanleft);
|
||||
}
|
||||
|
||||
void Lean::IN_LeanRight_Up()
|
||||
{
|
||||
Game::IN_KeyUp(&Lean::in_leanright);
|
||||
Game::IN_KeyUp(&in_leanright);
|
||||
}
|
||||
|
||||
void Lean::IN_LeanRight_Down()
|
||||
{
|
||||
Game::IN_KeyDown(&Lean::in_leanright);
|
||||
Game::IN_KeyDown(&in_leanright);
|
||||
}
|
||||
|
||||
void Lean::SetLeanFlags(Game::usercmd_s* cmds)
|
||||
void Lean::SetLeanFlags(Game::usercmd_s* cmd)
|
||||
{
|
||||
if (Lean::in_leanleft.active || Lean::in_leanleft.wasPressed)
|
||||
if ((in_leanleft.active || in_leanleft.wasPressed) && BGLean.get<bool>())
|
||||
{
|
||||
cmds->buttons |= BUTTON_FLAG_LEANLEFT;
|
||||
cmd->buttons |= Game::CMD_BUTTON_LEAN_LEFT;
|
||||
}
|
||||
|
||||
if (Lean::in_leanright.active || Lean::in_leanright.wasPressed)
|
||||
if ((in_leanright.active || in_leanright.wasPressed) && BGLean.get<bool>())
|
||||
{
|
||||
cmds->buttons |= BUTTON_FLAG_LEANRIGHT;
|
||||
cmd->buttons |= Game::CMD_BUTTON_LEAN_RIGHT;
|
||||
}
|
||||
|
||||
Lean::in_leanleft.wasPressed = false;
|
||||
Lean::in_leanright.wasPressed = false;
|
||||
in_leanleft.wasPressed = false;
|
||||
in_leanright.wasPressed = false;
|
||||
}
|
||||
|
||||
void __declspec(naked) Lean::CL_CmdButtonsStub()
|
||||
void __declspec(naked) Lean::CL_CmdButtons_Stub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
@ -51,21 +53,35 @@ namespace Components
|
||||
|
||||
pushad
|
||||
push esi
|
||||
call Lean::SetLeanFlags
|
||||
call SetLeanFlags
|
||||
pop esi
|
||||
popad
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Lean::Lean()
|
||||
{
|
||||
Command::AddRaw("+leanleft", Lean::IN_LeanLeft_Down, true);
|
||||
Command::AddRaw("-leanleft", Lean::IN_LeanLeft_Up, true);
|
||||
Command::AddRaw("+leanleft", IN_LeanLeft_Down, true);
|
||||
Command::AddRaw("-leanleft", IN_LeanLeft_Up, true);
|
||||
|
||||
Command::AddRaw("+leanright", Lean::IN_LeanRight_Down, true);
|
||||
Command::AddRaw("-leanright", Lean::IN_LeanRight_Up, true);
|
||||
Command::AddRaw("+leanright", IN_LeanRight_Down, true);
|
||||
Command::AddRaw("-leanright", IN_LeanRight_Up, true);
|
||||
|
||||
Utils::Hook(0x5A6D84, Lean::CL_CmdButtonsStub, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x5A6D84, CL_CmdButtons_Stub, HOOK_CALL).install()->quick();
|
||||
|
||||
Utils::Hook(0x4A0C72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x4A0D72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
||||
|
||||
BGLean = Dvar::Register<bool>("bg_lean", true,
|
||||
Game::DVAR_CODINFO, "Enable CoD4 leaning");
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define BUTTON_FLAG_LEANLEFT 0x40
|
||||
#define BUTTON_FLAG_LEANRIGHT 0x80
|
||||
|
||||
namespace Components
|
||||
{
|
||||
class Lean : public Component
|
||||
@ -10,6 +7,8 @@ namespace Components
|
||||
public:
|
||||
Lean();
|
||||
|
||||
static Dvar::Var BGLean;
|
||||
|
||||
private:
|
||||
static Game::kbutton_t in_leanleft;
|
||||
static Game::kbutton_t in_leanright;
|
||||
@ -20,7 +19,9 @@ namespace Components
|
||||
static void IN_LeanRight_Up();
|
||||
static void IN_LeanRight_Down();
|
||||
|
||||
static void CL_CmdButtonsStub();
|
||||
static void SetLeanFlags(Game::usercmd_s* cmds);
|
||||
static void CL_CmdButtons_Stub();
|
||||
static void SetLeanFlags(Game::usercmd_s* cmd);
|
||||
|
||||
static void 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));
|
||||
};
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define BUTTON_FLAG_LEANLEFT 0x40
|
||||
#define BUTTON_FLAG_LEANRIGHT 0x80
|
||||
|
||||
namespace Components
|
||||
{
|
||||
class SlowMotion : public Component
|
||||
|
Reference in New Issue
Block a user