[XInput] Completed analog movement on server side

This commit is contained in:
INeedBots 2021-01-02 19:06:40 -06:00
parent ef76acd8b4
commit 16c6d11916
4 changed files with 51 additions and 9 deletions

View File

@ -91,10 +91,39 @@ namespace Components
}
}
void XInput::ApplyMovement(Game::msg_t* msg, int key, Game::usercmd_s* from, Game::usercmd_s* to)
{
char forward;
char right;
if (Game::MSG_ReadBit(msg))
{
short movementBits = static_cast<short>(key ^ Game::MSG_ReadBits(msg, 16));
forward = static_cast<char>(movementBits);
right = static_cast<char>(movementBits >> 8);
}
else
{
forward = from->forwardmove;
right = from->rightmove;
}
to->forwardmove = forward;
to->rightmove = right;
}
__declspec(naked) void XInput::MSG_ReadDeltaUsercmdKeyStub()
{
__asm
{
push ebx // to
push ebp // from
push edi // key
push esi // msg
call XInput::ApplyMovement
add esp, 10h
// return back
push 0x4921BF
ret
@ -105,6 +134,13 @@ namespace Components
{
__asm
{
push ebx // to
push ebp // from
push edi // key
push esi // msg
call XInput::ApplyMovement
add esp, 10h
// return back
push 3
push esi
@ -124,16 +160,12 @@ namespace Components
// package the forward and right move components in the move buttons
Utils::Hook(0x60E38D, XInput::MSG_WriteDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick();
// send two bytes instead of one for sending movement data
Utils::Hook::Set<BYTE>(0x60E501, 8);
Utils::Hook::Set<BYTE>(0x60E5CD, 8);
// send two bytes for sending movement data
Utils::Hook::Set<BYTE>(0x60E501, 16);
Utils::Hook::Set<BYTE>(0x60E5CD, 16);
// make sure to parse the movement data properally and apply it
Utils::Hook(0x492191, XInput::MSG_ReadDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x492061, XInput::MSG_ReadDeltaUsercmdKeyStub2, HOOK_JUMP).install()->quick();
// read two bytes instead of one for receiveing movement data
Utils::Hook::Set<BYTE>(0x492049, 8);
Utils::Hook::Set<BYTE>(0x492177, 8);
Utils::Hook(0x492127, XInput::MSG_ReadDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x492009, XInput::MSG_ReadDeltaUsercmdKeyStub2, HOOK_JUMP).install()->quick();
}
}

View File

@ -19,6 +19,8 @@ namespace Components
static void MSG_WriteDeltaUsercmdKeyStub();
static void ApplyMovement(Game::msg_t* msg, int key, Game::usercmd_s* from, Game::usercmd_s* to);
static void MSG_ReadDeltaUsercmdKeyStub();
static void MSG_ReadDeltaUsercmdKeyStub2();
};

View File

@ -176,6 +176,8 @@ namespace Game
Menus_MenuIsInStack_t Menus_MenuIsInStack = Menus_MenuIsInStack_t(0x47ACB0);
MSG_Init_t MSG_Init = MSG_Init_t(0x45FCA0);
MSG_ReadBit_t MSG_ReadBit = MSG_ReadBit_t(0x476D20);
MSG_ReadBits_t MSG_ReadBits = MSG_ReadBits_t(0x4C3900);
MSG_ReadData_t MSG_ReadData = MSG_ReadData_t(0x4527C0);
MSG_ReadLong_t MSG_ReadLong = MSG_ReadLong_t(0x4C9550);
MSG_ReadShort_t MSG_ReadShort = MSG_ReadShort_t(0x40BDD0);

View File

@ -420,6 +420,12 @@ namespace Game
typedef int(__cdecl * MSG_ReadLong_t)(msg_t* msg);
extern MSG_ReadLong_t MSG_ReadLong;
typedef int(__cdecl * MSG_ReadBit_t)(msg_t* msg);
extern MSG_ReadBit_t MSG_ReadBit;
typedef int(__cdecl * MSG_ReadBits_t)(msg_t* msg, int bits);
extern MSG_ReadBits_t MSG_ReadBits;
typedef short(__cdecl * MSG_ReadShort_t)(msg_t* msg);
extern MSG_ReadShort_t MSG_ReadShort;