[XInput] Got lJoystick working

This commit is contained in:
INeedBots 2021-01-02 13:42:52 -06:00
parent 01dc00bd7f
commit a737dd16e4
3 changed files with 41 additions and 10 deletions

View File

@ -352,11 +352,9 @@ namespace Components
{
// execute our hook
pushad
pusha
call Script::StoreScriptBaseProgramNum
popa
popad
// execute overwritten code caused by the jump hook

View File

@ -3,12 +3,16 @@
namespace Components
{
XINPUT_STATE XInput::xiStates[XUSER_MAX_COUNT];
int XInput::xiPlayerNum = -1;
void XInput::PollXInputDevices()
{
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
XInput::xiPlayerNum = -1;
for (int i = XUSER_MAX_COUNT; i >= 0; i--)
{
XInputGetState(i, &xiStates[i]);
if (XInputGetState(i, &xiStates[i]) == ERROR_SUCCESS)
XInput::xiPlayerNum = i;
}
}
@ -17,14 +21,8 @@ namespace Components
__asm
{
// poll the xinput devices on every client frame
pusha
pushad
call XInput::PollXInputDevices
popad
popa
// execute the code we patched over
sub esp, 0Ch
push ebx
@ -37,8 +35,42 @@ namespace Components
}
}
void XInput::CL_GamepadMove(int localClientNum, Game::usercmd_s* cmd)
{
if (XInput::xiPlayerNum != -1)
{
XINPUT_STATE* xiState = &xiStates[xiPlayerNum];
cmd->rightmove = xiState->Gamepad.sThumbLX / 256;
cmd->forwardmove = xiState->Gamepad.sThumbLY / 256;
}
}
__declspec(naked) void XInput::CL_CreateCmdStub()
{
__asm
{
// do xinput!
push esi
push ebp
call XInput::CL_GamepadMove
add esp, 8h
// execute code we patched over
add esp, 4
fld st
pop ebx
// return back
push 0x5A6DBF
retn
}
}
XInput::XInput()
{
Utils::Hook(0x486970, XInput::CL_FrameStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x5A6DB9, XInput::CL_CreateCmdStub, HOOK_JUMP).install()->quick();
}
}

View File

@ -9,6 +9,7 @@ namespace Components
private:
static XINPUT_STATE xiStates[XUSER_MAX_COUNT];
static int xiPlayerNum;
static void CL_FrameStub();
static void PollXInputDevices();