2019-03-05 18:29:56 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <dinput.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-11-03 21:12:58 +00:00
|
|
|
#include "idzhook/config.h"
|
|
|
|
#include "idzhook/zinput.h"
|
|
|
|
|
2019-03-05 18:29:56 +00:00
|
|
|
#include "hook/table.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
2019-11-03 21:12:58 +00:00
|
|
|
HRESULT WINAPI hook_DirectInput8Create(
|
|
|
|
HINSTANCE hinst,
|
|
|
|
DWORD dwVersion,
|
|
|
|
REFIID riidltf,
|
|
|
|
LPVOID *ppvOut,
|
|
|
|
LPUNKNOWN punkOuter);
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static unsigned long WINAPI hook_AddRef(IUnknown *self);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static unsigned long WINAPI hook_Release(IUnknown *self);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_CreateDevice(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInput8W *self,
|
|
|
|
REFGUID rguid,
|
|
|
|
LPDIRECTINPUTDEVICE8W * lplpDirectInputDevice,
|
|
|
|
LPUNKNOWN pUnkOuter);
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_EnumDevices(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInput8W *self,
|
|
|
|
DWORD dwDevType,
|
|
|
|
LPDIENUMDEVICESCALLBACKW lpCallback,
|
|
|
|
LPVOID pvRef,
|
|
|
|
DWORD dwFlags);
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_SetDataFormat(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
LPCDIDATAFORMAT lpdf);
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_SetCooperativeLevel(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
HWND hwnd,
|
|
|
|
DWORD flags);
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_Acquire(IDirectInputDevice8W *self);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_Unacquire(IDirectInputDevice8W *self);
|
|
|
|
|
|
|
|
static HRESULT WINAPI hook_GetDeviceState(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
DWORD cbData,
|
|
|
|
LPVOID lpvData);
|
|
|
|
|
|
|
|
static const IDirectInput8WVtbl api_vtbl = {
|
2019-11-03 21:14:26 +00:00
|
|
|
.AddRef = (void *) hook_AddRef,
|
|
|
|
.Release = (void *) hook_Release,
|
|
|
|
.CreateDevice = hook_CreateDevice,
|
|
|
|
.EnumDevices = hook_EnumDevices,
|
2019-03-05 18:29:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const IDirectInput8W api = { (void *) &api_vtbl };
|
|
|
|
|
|
|
|
static const IDirectInputDevice8WVtbl dev_vtbl = {
|
2019-11-03 21:14:26 +00:00
|
|
|
.AddRef = (void *) hook_AddRef,
|
|
|
|
.Release = (void *) hook_Release,
|
|
|
|
.SetDataFormat = hook_SetDataFormat,
|
|
|
|
.SetCooperativeLevel= hook_SetCooperativeLevel,
|
|
|
|
.Acquire = hook_Acquire,
|
|
|
|
.Unacquire = hook_Unacquire,
|
|
|
|
.GetDeviceState = hook_GetDeviceState,
|
2019-03-05 18:29:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const IDirectInputDevice8W dev = { (void *) &dev_vtbl };
|
|
|
|
|
2019-11-03 21:12:58 +00:00
|
|
|
static const struct hook_symbol zinput_hook_syms[] = {
|
|
|
|
{
|
|
|
|
.name = "DirectInput8Create",
|
|
|
|
.patch = hook_DirectInput8Create,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT zinput_hook_init(struct zinput_config *cfg)
|
|
|
|
{
|
|
|
|
assert(cfg != NULL);
|
|
|
|
|
|
|
|
if (!cfg->enable) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_table_apply(
|
|
|
|
NULL,
|
|
|
|
"dinput8.dll",
|
|
|
|
zinput_hook_syms,
|
|
|
|
_countof(zinput_hook_syms));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI hook_DirectInput8Create(
|
2019-03-05 18:29:56 +00:00
|
|
|
HINSTANCE hinst,
|
|
|
|
DWORD dwVersion,
|
|
|
|
REFIID riidltf,
|
|
|
|
LPVOID *ppvOut,
|
|
|
|
LPUNKNOWN punkOuter)
|
|
|
|
{
|
2019-11-03 21:12:58 +00:00
|
|
|
dprintf("ZInput: Blocking built-in DirectInput support\n");
|
2019-03-05 18:29:56 +00:00
|
|
|
*ppvOut = (void *) &api;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static unsigned long WINAPI hook_AddRef(IUnknown *self)
|
2019-03-05 18:29:56 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static unsigned long WINAPI hook_Release(IUnknown *self)
|
2019-03-05 18:29:56 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_CreateDevice(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInput8W *self,
|
|
|
|
REFGUID rguid,
|
|
|
|
LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice,
|
|
|
|
LPUNKNOWN pUnkOuter)
|
|
|
|
{
|
2019-11-03 21:14:26 +00:00
|
|
|
dprintf("ZInput: %s\n", __func__);
|
2019-03-05 18:29:56 +00:00
|
|
|
*lplpDirectInputDevice = (void *) &dev;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_EnumDevices(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInput8W *self,
|
|
|
|
DWORD dwDevType,
|
|
|
|
LPDIENUMDEVICESCALLBACKW lpCallback,
|
|
|
|
LPVOID pvRef,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
2019-11-03 21:14:26 +00:00
|
|
|
dprintf("ZInput: %s\n", __func__);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_SetDataFormat(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
LPCDIDATAFORMAT lpdf)
|
|
|
|
{
|
2019-11-03 21:14:26 +00:00
|
|
|
dprintf("ZInput: %s\n", __func__);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_SetCooperativeLevel(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
HWND hwnd,
|
|
|
|
DWORD flags)
|
|
|
|
{
|
2019-11-03 21:14:26 +00:00
|
|
|
dprintf("ZInput: %s\n", __func__);
|
2019-03-05 18:29:56 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_Acquire(IDirectInputDevice8W *self)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI hook_Unacquire(IDirectInputDevice8W *self)
|
2019-03-05 18:29:56 +00:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 21:14:26 +00:00
|
|
|
static HRESULT WINAPI hook_GetDeviceState(
|
2019-03-05 18:29:56 +00:00
|
|
|
IDirectInputDevice8W *self,
|
|
|
|
DWORD cbData,
|
|
|
|
LPVOID lpvData)
|
|
|
|
{
|
|
|
|
memset(lpvData, 0, cbData);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|