segatools/swdchook/zinput.c

81 lines
1.7 KiB
C
Raw Normal View History

2023-07-13 22:52:50 +00:00
#include <windows.h>
2023-08-20 14:21:55 +00:00
#include <xinput.h>
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
#include <assert.h>
2023-07-13 22:52:50 +00:00
#include <stdlib.h>
#include "swdchook/config.h"
#include "swdchook/zinput.h"
#include "hook/table.h"
#include "util/dprintf.h"
2023-08-20 14:21:55 +00:00
DWORD WINAPI hook_XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState);
2023-07-13 22:52:50 +00:00
static const struct hook_symbol zinput_hook_syms[] = {
{
2023-08-20 14:21:55 +00:00
.name = "XInputGetState",
.patch = hook_XInputGetState,
.link = NULL
},
2023-07-13 22:52:50 +00:00
};
2023-08-20 14:21:55 +00:00
static struct zinput_config zinput_config;
static bool zinput_hook_initted;
void zinput_hook_init(struct zinput_config *cfg, HINSTANCE self)
2023-07-13 22:52:50 +00:00
{
assert(cfg != NULL);
if (!cfg->enable) {
2023-08-20 14:21:55 +00:00
return;
2023-07-13 22:52:50 +00:00
}
2023-08-20 14:21:55 +00:00
if (zinput_hook_initted) {
return;
}
memcpy(&zinput_config, cfg, sizeof(*cfg));
2023-07-13 22:52:50 +00:00
hook_table_apply(
NULL,
2023-08-20 14:21:55 +00:00
"XINPUT9_1_0.dll",
2023-07-13 22:52:50 +00:00
zinput_hook_syms,
_countof(zinput_hook_syms));
2023-08-20 14:21:55 +00:00
hook_table_apply(
NULL,
"XINPUT1_1.dll",
zinput_hook_syms,
_countof(zinput_hook_syms));
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
hook_table_apply(
NULL,
"XINPUT1_2.dll",
zinput_hook_syms,
_countof(zinput_hook_syms));
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
hook_table_apply(
NULL,
"XINPUT1_3.dll",
zinput_hook_syms,
_countof(zinput_hook_syms));
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
hook_table_apply(
NULL,
"XINPUT1_4.dll",
zinput_hook_syms,
_countof(zinput_hook_syms));
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
zinput_hook_initted = true;
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
dprintf("ZInput: Blocking built-in XInput support\n");
2023-07-13 22:52:50 +00:00
}
2023-08-20 14:21:55 +00:00
DWORD WINAPI hook_XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState)
2023-07-13 22:52:50 +00:00
{
2023-08-20 14:21:55 +00:00
// dprintf("ZInput: XInputGetState hook hit\n");
2023-07-13 22:52:50 +00:00
2023-08-20 14:21:55 +00:00
return ERROR_SUCCESS;
2023-07-13 22:52:50 +00:00
}