From b550efd4a99c5e7b0135a704459e89990d86a0b7 Mon Sep 17 00:00:00 2001 From: Tau Date: Tue, 5 Mar 2019 13:29:56 -0500 Subject: [PATCH] zinput: Add stub DirectInput implementation Initial D Zero has some incomplete built-in PC input support, we need to disable it so that it does not interfere with our JVS emulation. --- meson.build | 1 + precompiled.h | 1 + zinput/dllmain.c | 146 +++++++++++++++++++++++++++++++++++++++++++++ zinput/meson.build | 17 ++++++ zinput/zinput.def | 4 ++ 5 files changed, 169 insertions(+) create mode 100644 zinput/dllmain.c create mode 100644 zinput/meson.build create mode 100644 zinput/zinput.def diff --git a/meson.build b/meson.build index 9a2a757..d74e52e 100644 --- a/meson.build +++ b/meson.build @@ -40,3 +40,4 @@ subdir('aimeio') subdir('cardhook') subdir('chunihook') subdir('minihook') +subdir('zinput') diff --git a/precompiled.h b/precompiled.h index 24058e9..149b5ac 100644 --- a/precompiled.h +++ b/precompiled.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/zinput/dllmain.c b/zinput/dllmain.c new file mode 100644 index 0000000..5ed8ad5 --- /dev/null +++ b/zinput/dllmain.c @@ -0,0 +1,146 @@ +#include +#include + +#include +#include +#include + +#include "hook/process.h" +#include "hook/table.h" + +#include "util/dprintf.h" + +static unsigned long WINAPI my_AddRef(IUnknown *self); + +static unsigned long WINAPI my_Release(IUnknown *self); + +static HRESULT WINAPI my_CreateDevice( + IDirectInput8W *self, + REFGUID rguid, + LPDIRECTINPUTDEVICE8W * lplpDirectInputDevice, + LPUNKNOWN pUnkOuter); + +static HRESULT WINAPI my_EnumDevices( + IDirectInput8W *self, + DWORD dwDevType, + LPDIENUMDEVICESCALLBACKW lpCallback, + LPVOID pvRef, + DWORD dwFlags); + +static HRESULT WINAPI my_SetDataFormat( + IDirectInputDevice8W *self, + LPCDIDATAFORMAT lpdf); + +static HRESULT WINAPI my_SetCooperativeLevel( + IDirectInputDevice8W *self, + HWND hwnd, + DWORD flags); + +static HRESULT WINAPI my_Acquire(IDirectInputDevice8W *self); + +static HRESULT WINAPI my_GetDeviceState( + IDirectInputDevice8W *self, + DWORD cbData, + LPVOID lpvData); + +static const IDirectInput8WVtbl api_vtbl = { + .AddRef = (void *) my_AddRef, + .Release = (void *) my_Release, + .CreateDevice = my_CreateDevice, + .EnumDevices = my_EnumDevices, +}; + +static const IDirectInput8W api = { (void *) &api_vtbl }; + +static const IDirectInputDevice8WVtbl dev_vtbl = { + .AddRef = (void *) my_AddRef, + .Release = (void *) my_Release, + .SetDataFormat = my_SetDataFormat, + .SetCooperativeLevel= my_SetCooperativeLevel, + .Acquire = my_Acquire, + .Unacquire = my_Acquire, // not a c&p error + .GetDeviceState = my_GetDeviceState, +}; + +static const IDirectInputDevice8W dev = { (void *) &dev_vtbl }; + +HRESULT WINAPI DirectInput8Create( + HINSTANCE hinst, + DWORD dwVersion, + REFIID riidltf, + LPVOID *ppvOut, + LPUNKNOWN punkOuter) +{ + dprintf("%s\n", __func__); + *ppvOut = (void *) &api; + + return S_OK; +} + +static unsigned long WINAPI my_AddRef(IUnknown *self) +{ + return 1; +} + +static unsigned long WINAPI my_Release(IUnknown *self) +{ + return 1; +} + +static HRESULT WINAPI my_CreateDevice( + IDirectInput8W *self, + REFGUID rguid, + LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice, + LPUNKNOWN pUnkOuter) +{ + dprintf("%s\n", __func__); + *lplpDirectInputDevice = (void *) &dev; + + return S_OK; +} + +static HRESULT WINAPI my_EnumDevices( + IDirectInput8W *self, + DWORD dwDevType, + LPDIENUMDEVICESCALLBACKW lpCallback, + LPVOID pvRef, + DWORD dwFlags) +{ + dprintf("%s\n", __func__); + + return S_OK; +} + +static HRESULT WINAPI my_SetDataFormat( + IDirectInputDevice8W *self, + LPCDIDATAFORMAT lpdf) +{ + dprintf("%s\n", __func__); + + return S_OK; +} + +static HRESULT WINAPI my_SetCooperativeLevel( + IDirectInputDevice8W *self, + HWND hwnd, + DWORD flags) +{ + dprintf("%s\n", __func__); + + return S_OK; +} + +static HRESULT WINAPI my_Acquire(IDirectInputDevice8W *self) +{ + return S_OK; +} + +static HRESULT WINAPI my_GetDeviceState( + IDirectInputDevice8W *self, + DWORD cbData, + LPVOID lpvData) +{ + memset(lpvData, 0, cbData); + + return S_OK; +} diff --git a/zinput/meson.build b/zinput/meson.build new file mode 100644 index 0000000..24de1c7 --- /dev/null +++ b/zinput/meson.build @@ -0,0 +1,17 @@ +shared_library( + 'zinput', + name_prefix : '', + include_directories : inc, + implicit_include_directories : false, + vs_module_defs : 'zinput.def', + c_pch : '../precompiled.h', + dependencies : [ + capnhook.get_variable('hook_dep'), + ], + link_with : [ + util_lib, + ], + sources : [ + 'dllmain.c', + ], +) diff --git a/zinput/zinput.def b/zinput/zinput.def new file mode 100644 index 0000000..09c60cb --- /dev/null +++ b/zinput/zinput.def @@ -0,0 +1,4 @@ +LIBRARY zinput + +EXPORTS + DirectInput8Create