forked from TeamTofuShop/segatools
idzhook: Fold zinput into idzhook
This commit is contained in:
@ -19,4 +19,13 @@ void idz_hook_config_load(
|
||||
platform_config_load(&cfg->platform, filename);
|
||||
amex_config_load(&cfg->amex, filename);
|
||||
aime_config_load(&cfg->aime, filename);
|
||||
zinput_config_load(&cfg->zinput, filename);
|
||||
}
|
||||
|
||||
void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"zinput", L"enable", 1, filename);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "amex/config.h"
|
||||
@ -8,12 +9,19 @@
|
||||
|
||||
#include "platform/config.h"
|
||||
|
||||
struct zinput_config {
|
||||
bool enable;
|
||||
};
|
||||
|
||||
struct idz_hook_config {
|
||||
struct platform_config platform;
|
||||
struct amex_config amex;
|
||||
struct aime_config aime;
|
||||
struct zinput_config zinput;
|
||||
};
|
||||
|
||||
void idz_hook_config_load(
|
||||
struct idz_hook_config *cfg,
|
||||
const wchar_t *filename);
|
||||
|
||||
void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename);
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "idzhook/config.h"
|
||||
#include "idzhook/jvs.h"
|
||||
#include "idzhook/zinput.h"
|
||||
|
||||
#include "platform/platform.h"
|
||||
|
||||
@ -35,6 +36,7 @@ static DWORD CALLBACK idz_pre_startup(void)
|
||||
/* Hook Win32 APIs */
|
||||
|
||||
serial_hook_init();
|
||||
zinput_hook_init(&idz_hook_cfg.zinput);
|
||||
|
||||
/* Initialize emulation hooks */
|
||||
|
||||
|
@ -26,5 +26,7 @@ shared_library(
|
||||
'dllmain.c',
|
||||
'jvs.c',
|
||||
'jvs.h',
|
||||
'zinput.c',
|
||||
'zinput.h',
|
||||
],
|
||||
)
|
||||
|
179
idzhook/zinput.c
Normal file
179
idzhook/zinput.c
Normal file
@ -0,0 +1,179 @@
|
||||
#include <windows.h>
|
||||
#include <dinput.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "idzhook/config.h"
|
||||
#include "idzhook/zinput.h"
|
||||
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
|
||||
HRESULT WINAPI hook_DirectInput8Create(
|
||||
HINSTANCE hinst,
|
||||
DWORD dwVersion,
|
||||
REFIID riidltf,
|
||||
LPVOID *ppvOut,
|
||||
LPUNKNOWN punkOuter);
|
||||
|
||||
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 };
|
||||
|
||||
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(
|
||||
HINSTANCE hinst,
|
||||
DWORD dwVersion,
|
||||
REFIID riidltf,
|
||||
LPVOID *ppvOut,
|
||||
LPUNKNOWN punkOuter)
|
||||
{
|
||||
dprintf("ZInput: Blocking built-in DirectInput support\n");
|
||||
*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;
|
||||
}
|
7
idzhook/zinput.h
Normal file
7
idzhook/zinput.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "idzhook/config.h"
|
||||
|
||||
HRESULT zinput_hook_init(struct zinput_config *cfg);
|
Reference in New Issue
Block a user