[Lean] Add option to disable

This commit is contained in:
Diavolo 2022-08-11 00:21:58 +02:00
parent 49ed76807b
commit 8a55ae1f30
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
6 changed files with 58 additions and 31 deletions

View File

@ -241,12 +241,12 @@ namespace Components
mov dl, byte ptr[edi + 1Ah] // to_forwardMove mov dl, byte ptr[edi + 1Ah] // to_forwardMove
mov dh, byte ptr[edi + 1Bh] // to_rightMove 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 dl, byte ptr [ebp + 1Ah] // from_forwardMove
mov dh, byte ptr[ebp + 1Bh] // from_rightMove mov dh, byte ptr [ebp + 1Bh] // from_rightMove
mov[esp + 2Ch], dx // from_buttons mov [esp + 2Ch], dx // from_buttons
// return back // return back
push 0x60E40E push 0x60E40E
@ -261,7 +261,7 @@ namespace Components
if (Game::MSG_ReadBit(msg)) 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); forward = static_cast<char>(movementBits);
right = static_cast<char>(movementBits >> 8); right = static_cast<char>(movementBits >> 8);
@ -274,6 +274,11 @@ namespace Components
to->forwardmove = forward; to->forwardmove = forward;
to->rightmove = right; 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() __declspec(naked) void Gamepad::MSG_ReadDeltaUsercmdKeyStub()

View File

@ -2,46 +2,48 @@
namespace Components namespace Components
{ {
Dvar::Var Lean::BGLean;
Game::kbutton_t Lean::in_leanleft; Game::kbutton_t Lean::in_leanleft;
Game::kbutton_t Lean::in_leanright; Game::kbutton_t Lean::in_leanright;
void Lean::IN_LeanLeft_Up() void Lean::IN_LeanLeft_Up()
{ {
Game::IN_KeyUp(&Lean::in_leanleft); Game::IN_KeyUp(&in_leanleft);
} }
void Lean::IN_LeanLeft_Down() void Lean::IN_LeanLeft_Down()
{ {
Game::IN_KeyDown(&Lean::in_leanleft); Game::IN_KeyDown(&in_leanleft);
} }
void Lean::IN_LeanRight_Up() void Lean::IN_LeanRight_Up()
{ {
Game::IN_KeyUp(&Lean::in_leanright); Game::IN_KeyUp(&in_leanright);
} }
void Lean::IN_LeanRight_Down() 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; in_leanleft.wasPressed = false;
Lean::in_leanright.wasPressed = false; in_leanright.wasPressed = false;
} }
void __declspec(naked) Lean::CL_CmdButtonsStub() void __declspec(naked) Lean::CL_CmdButtons_Stub()
{ {
__asm __asm
{ {
@ -51,21 +53,35 @@ namespace Components
pushad pushad
push esi push esi
call Lean::SetLeanFlags call SetLeanFlags
pop esi pop esi
popad popad
retn 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() Lean::Lean()
{ {
Command::AddRaw("+leanleft", Lean::IN_LeanLeft_Down, true); Command::AddRaw("+leanleft", IN_LeanLeft_Down, true);
Command::AddRaw("-leanleft", Lean::IN_LeanLeft_Up, true); Command::AddRaw("-leanleft", IN_LeanLeft_Up, true);
Command::AddRaw("+leanright", Lean::IN_LeanRight_Down, true); Command::AddRaw("+leanright", IN_LeanRight_Down, true);
Command::AddRaw("-leanright", Lean::IN_LeanRight_Up, 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");
} }
} }

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#define BUTTON_FLAG_LEANLEFT 0x40
#define BUTTON_FLAG_LEANRIGHT 0x80
namespace Components namespace Components
{ {
class Lean : public Component class Lean : public Component
@ -10,6 +7,8 @@ namespace Components
public: public:
Lean(); Lean();
static Dvar::Var BGLean;
private: private:
static Game::kbutton_t in_leanleft; static Game::kbutton_t in_leanleft;
static Game::kbutton_t in_leanright; static Game::kbutton_t in_leanright;
@ -20,7 +19,9 @@ namespace Components
static void IN_LeanRight_Up(); static void IN_LeanRight_Up();
static void IN_LeanRight_Down(); static void IN_LeanRight_Down();
static void CL_CmdButtonsStub(); static void CL_CmdButtons_Stub();
static void SetLeanFlags(Game::usercmd_s* cmds); 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));
}; };
} }

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#define BUTTON_FLAG_LEANLEFT 0x40
#define BUTTON_FLAG_LEANRIGHT 0x80
namespace Components namespace Components
{ {
class SlowMotion : public Component class SlowMotion : public Component

View File

@ -238,6 +238,7 @@ namespace Game
MSG_WriteLong_t MSG_WriteLong = MSG_WriteLong_t(0x41CA20); MSG_WriteLong_t MSG_WriteLong = MSG_WriteLong_t(0x41CA20);
MSG_WriteShort_t MSG_WriteShort = MSG_WriteShort_t(0x503B90); MSG_WriteShort_t MSG_WriteShort = MSG_WriteShort_t(0x503B90);
MSG_WriteString_t MSG_WriteString = MSG_WriteString_t(0x463820); MSG_WriteString_t MSG_WriteString = MSG_WriteString_t(0x463820);
MSG_ReadDeltaUsercmdKey_t MSG_ReadDeltaUsercmdKey = MSG_ReadDeltaUsercmdKey_t(0x491F00);
MSG_WriteBitsCompress_t MSG_WriteBitsCompress = MSG_WriteBitsCompress_t(0x4319D0); MSG_WriteBitsCompress_t MSG_WriteBitsCompress = MSG_WriteBitsCompress_t(0x4319D0);
MSG_ReadByte_t MSG_ReadByte = MSG_ReadByte_t(0x4C1C20); MSG_ReadByte_t MSG_ReadByte = MSG_ReadByte_t(0x4C1C20);
MSG_ReadBitsCompress_t MSG_ReadBitsCompress = MSG_ReadBitsCompress_t(0x4DCC30); MSG_ReadBitsCompress_t MSG_ReadBitsCompress = MSG_ReadBitsCompress_t(0x4DCC30);
@ -455,6 +456,7 @@ namespace Game
PM_playerTrace_t PM_playerTrace = PM_playerTrace_t(0x458980); PM_playerTrace_t PM_playerTrace = PM_playerTrace_t(0x458980);
PM_Trace_t PM_Trace = PM_Trace_t(0x441F60); PM_Trace_t PM_Trace = PM_Trace_t(0x441F60);
PM_GetEffectiveStance_t PM_GetEffectiveStance = PM_GetEffectiveStance_t(0x412540); PM_GetEffectiveStance_t PM_GetEffectiveStance = PM_GetEffectiveStance_t(0x412540);
PM_UpdateLean_t PM_UpdateLean = PM_UpdateLean_t(0x43DED0);
CL_MouseEvent_t CL_MouseEvent = CL_MouseEvent_t(0x4D7C50); CL_MouseEvent_t CL_MouseEvent = CL_MouseEvent_t(0x4D7C50);
IN_RecenterMouse_t IN_RecenterMouse = IN_RecenterMouse_t(0x463D80); IN_RecenterMouse_t IN_RecenterMouse = IN_RecenterMouse_t(0x463D80);

View File

@ -624,6 +624,9 @@ namespace Game
typedef void(__cdecl * MSG_WriteString_t)(msg_t* msg, const char *str); typedef void(__cdecl * MSG_WriteString_t)(msg_t* msg, const char *str);
extern MSG_WriteString_t MSG_WriteString; extern MSG_WriteString_t MSG_WriteString;
typedef bool(__cdecl * MSG_ReadDeltaUsercmdKey_t)(msg_t* msg, int key, const usercmd_s* from, usercmd_s* to);
extern MSG_ReadDeltaUsercmdKey_t MSG_ReadDeltaUsercmdKey;
typedef int(__cdecl * MSG_WriteBitsCompress_t)(bool trainHuffman, const char *from, char *to, int size); typedef int(__cdecl * MSG_WriteBitsCompress_t)(bool trainHuffman, const char *from, char *to, int size);
extern MSG_WriteBitsCompress_t MSG_WriteBitsCompress; extern MSG_WriteBitsCompress_t MSG_WriteBitsCompress;
@ -1110,6 +1113,9 @@ namespace Game
typedef EffectiveStance(__cdecl * PM_GetEffectiveStance_t)(const playerState_s* ps); typedef EffectiveStance(__cdecl * PM_GetEffectiveStance_t)(const playerState_s* ps);
extern PM_GetEffectiveStance_t PM_GetEffectiveStance; extern PM_GetEffectiveStance_t PM_GetEffectiveStance;
typedef void(__cdecl * PM_UpdateLean_t)(playerState_s* ps, float msec, usercmd_s* cmd, void(*capsuleTrace)(trace_t*, const float*, const float*, const Bounds*, int, int));
extern PM_UpdateLean_t PM_UpdateLean;
typedef int(__cdecl * CL_MouseEvent_t)(int x, int y, int dx, int dy); typedef int(__cdecl * CL_MouseEvent_t)(int x, int y, int dx, int dy);
extern CL_MouseEvent_t CL_MouseEvent; extern CL_MouseEvent_t CL_MouseEvent;