[XInput] Polling for input

This commit is contained in:
INeedBots 2021-01-02 01:17:37 -06:00
parent 39c14fd775
commit 01dc00bd7f
3 changed files with 46 additions and 1 deletions

View File

@ -2,7 +2,43 @@
namespace Components
{
XINPUT_STATE XInput::xiStates[XUSER_MAX_COUNT];
void XInput::PollXInputDevices()
{
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
{
XInputGetState(i, &xiStates[i]);
}
}
__declspec(naked) void XInput::CL_FrameStub()
{
__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
push ebp
push esi
// return back to original code
push 0x486976
retn
}
}
XInput::XInput()
{
Utils::Hook(0x486970, XInput::CL_FrameStub, HOOK_JUMP).install()->quick();
}
}

View File

@ -8,6 +8,12 @@ namespace Components
XInput();
private:
static XINPUT_STATE xiStates[XUSER_MAX_COUNT];
static void CL_FrameStub();
static void PollXInputDevices();
static void CL_CreateCmdStub();
static void CL_GamepadMove(int, Game::usercmd_s*);
};
}

View File

@ -48,6 +48,9 @@
#include <d3dx9tex.h>
#pragma comment(lib, "D3dx9.lib")
#include <Xinput.h>
#pragma comment (lib, "xinput.lib")
// Usefull for debugging
template <size_t S> class Sizer { };
#define BindNum(x, y) Sizer<x> y;