From 16c6d11916a3b1b72d55e97d1b6ff63c0d8b0f11 Mon Sep 17 00:00:00 2001 From: INeedBots Date: Sat, 2 Jan 2021 19:06:40 -0600 Subject: [PATCH] [XInput] Completed analog movement on server side --- src/Components/Modules/XInput.cpp | 50 +++++++++++++++++++++++++------ src/Components/Modules/XInput.hpp | 2 ++ src/Game/Functions.cpp | 2 ++ src/Game/Functions.hpp | 6 ++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/Components/Modules/XInput.cpp b/src/Components/Modules/XInput.cpp index c4dc50b8..88c27075 100644 --- a/src/Components/Modules/XInput.cpp +++ b/src/Components/Modules/XInput.cpp @@ -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(key ^ Game::MSG_ReadBits(msg, 16)); + + forward = static_cast(movementBits); + right = static_cast(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(0x60E501, 8); - Utils::Hook::Set(0x60E5CD, 8); + // send two bytes for sending movement data + Utils::Hook::Set(0x60E501, 16); + Utils::Hook::Set(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(0x492049, 8); - Utils::Hook::Set(0x492177, 8); + Utils::Hook(0x492127, XInput::MSG_ReadDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x492009, XInput::MSG_ReadDeltaUsercmdKeyStub2, HOOK_JUMP).install()->quick(); } } diff --git a/src/Components/Modules/XInput.hpp b/src/Components/Modules/XInput.hpp index 7a1b328a..6d92a134 100644 --- a/src/Components/Modules/XInput.hpp +++ b/src/Components/Modules/XInput.hpp @@ -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(); }; diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 63e01a18..ab9b913f 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -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); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 8b125c82..789a4b46 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -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;