From 59ad491d080cffe3d65393f6d962553cee9ca065 Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 3 Nov 2019 16:12:58 -0500 Subject: [PATCH] idzhook: Fold zinput into idzhook --- idzhook/config.c | 9 +++++++ idzhook/config.h | 8 ++++++ idzhook/dllmain.c | 2 ++ idzhook/meson.build | 2 ++ zinput/dllmain.c => idzhook/zinput.c | 39 +++++++++++++++++++++++++--- idzhook/zinput.h | 7 +++++ meson.build | 1 - zinput/meson.build | 17 ------------ zinput/zinput.def | 4 --- 9 files changed, 64 insertions(+), 25 deletions(-) rename zinput/dllmain.c => idzhook/zinput.c (80%) create mode 100644 idzhook/zinput.h delete mode 100644 zinput/meson.build delete mode 100644 zinput/zinput.def diff --git a/idzhook/config.c b/idzhook/config.c index 899a29e5..03315043 100644 --- a/idzhook/config.c +++ b/idzhook/config.c @@ -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); } diff --git a/idzhook/config.h b/idzhook/config.h index d26d28c4..6e3acdd0 100644 --- a/idzhook/config.h +++ b/idzhook/config.h @@ -1,5 +1,6 @@ #pragma once +#include #include #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); diff --git a/idzhook/dllmain.c b/idzhook/dllmain.c index 400ff5e0..c02b991a 100644 --- a/idzhook/dllmain.c +++ b/idzhook/dllmain.c @@ -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 */ diff --git a/idzhook/meson.build b/idzhook/meson.build index f8766926..f4a3e8b1 100644 --- a/idzhook/meson.build +++ b/idzhook/meson.build @@ -26,5 +26,7 @@ shared_library( 'dllmain.c', 'jvs.c', 'jvs.h', + 'zinput.c', + 'zinput.h', ], ) diff --git a/zinput/dllmain.c b/idzhook/zinput.c similarity index 80% rename from zinput/dllmain.c rename to idzhook/zinput.c index 5ed8ad5b..e748d9df 100644 --- a/zinput/dllmain.c +++ b/idzhook/zinput.c @@ -5,11 +5,20 @@ #include #include -#include "hook/process.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); @@ -64,14 +73,38 @@ static const IDirectInputDevice8WVtbl dev_vtbl = { static const IDirectInputDevice8W dev = { (void *) &dev_vtbl }; -HRESULT WINAPI DirectInput8Create( +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("%s\n", __func__); + dprintf("ZInput: Blocking built-in DirectInput support\n"); *ppvOut = (void *) &api; return S_OK; diff --git a/idzhook/zinput.h b/idzhook/zinput.h new file mode 100644 index 00000000..cea1b374 --- /dev/null +++ b/idzhook/zinput.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +#include "idzhook/config.h" + +HRESULT zinput_hook_init(struct zinput_config *cfg); diff --git a/meson.build b/meson.build index d77c7049..00ff0be9 100644 --- a/meson.build +++ b/meson.build @@ -51,4 +51,3 @@ subdir('divahook') subdir('idzhook') subdir('minihook') subdir('mu3hook') -subdir('zinput') diff --git a/zinput/meson.build b/zinput/meson.build deleted file mode 100644 index 24de1c74..00000000 --- a/zinput/meson.build +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 2de751d8..00000000 --- a/zinput/zinput.def +++ /dev/null @@ -1,4 +0,0 @@ -LIBRARY zinput - -EXPORTS - DirectInput8Create@20