From 384fad89e37af698f60f273ee4099ac3a8cb5fd0 Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Mon, 9 Jun 2025 04:30:39 -0700 Subject: [PATCH] iidxhook9: add reverb ex fix --- src/main/iidxhook9/Module.mk | 1 + src/main/iidxhook9/dllmain.c | 3 ++ src/main/iidxhook9/reverbfix.c | 56 ++++++++++++++++++++++++++++++++++ src/main/iidxhook9/reverbfix.h | 6 ++++ 4 files changed, 66 insertions(+) create mode 100644 src/main/iidxhook9/reverbfix.c create mode 100644 src/main/iidxhook9/reverbfix.h diff --git a/src/main/iidxhook9/Module.mk b/src/main/iidxhook9/Module.mk index 09e56a8..ce1a00c 100644 --- a/src/main/iidxhook9/Module.mk +++ b/src/main/iidxhook9/Module.mk @@ -30,4 +30,5 @@ libs_iidxhook9 := \ src_iidxhook9 := \ config-io.c \ fs-hook.c \ + reverbfix.c \ dllmain.c \ diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c index 7044d21..5927c96 100644 --- a/src/main/iidxhook9/dllmain.c +++ b/src/main/iidxhook9/dllmain.c @@ -27,6 +27,7 @@ #include "iidxhook9/config-io.h" #include "iidxhook9/fs-hook.h" +#include "iidxhook9/reverbfix.h" #include "camhook/cam.h" #include "camhook/config-cam.h" @@ -165,6 +166,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook9_fs_hooks_init(); } + reverbfixhook_init(); + rs232_hook_init(); rs232_hook_limit_hooks(); diff --git a/src/main/iidxhook9/reverbfix.c b/src/main/iidxhook9/reverbfix.c new file mode 100644 index 0000000..880b332 --- /dev/null +++ b/src/main/iidxhook9/reverbfix.c @@ -0,0 +1,56 @@ +#define LOG_MODULE "reverbfix-hook" + +// clang-format off +// Don't format because the order is important here +#include +#include +// clang-format on + +#include + +#include + +#include "hook/com-proxy.h" +#include "hook/table.h" + +#include "iidxhook9/reverbfix.h" + +#include "util/log.h" + +DEFINE_GUID(GUID_DSFX_STANDARD_I3DL2REVERB, 0xEF985E71,0xD5C7,0x42D4,0xBA,0x4D,0x2D,0x07,0x3E,0x2E,0x96,0xF4); +DEFINE_GUID(GUID_DSFX_WAVES_REVERB, 0x87FC0268,0x9A55,0x4360,0x95,0xAA,0x00,0x4A,0x1D,0x9D,0xE2,0x6C); + +static HRESULT my_CoCreateInstance( + REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv); + +static HRESULT (*real_CoCreateInstance)( + REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv); + +static const struct hook_symbol reverbfix_ole_syms[] = { + {.name = "CoCreateInstance", + .patch = my_CoCreateInstance, + .link = (void **) &real_CoCreateInstance}, +}; + +static HRESULT my_CoCreateInstance( + REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) +{ + HRESULT result = real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); + if (result == REGDB_E_CLASSNOTREG) { + if (IsEqualGUID(rclsid, &GUID_DSFX_STANDARD_I3DL2REVERB)) { + // replace effect used by REVERB EX with REVERB, based on CDmoSoundFx classes + result = real_CoCreateInstance(&GUID_DSFX_WAVES_REVERB, pUnkOuter, dwClsContext, riid, ppv); + + log_info("DSFX_STANDARD_I3DL2REVERB class missing, replaced with DSFX_WAVES_REVERB"); + } + } + + return result; +} + +void reverbfixhook_init() +{ + hook_table_apply( + NULL, "Ole32.dll", reverbfix_ole_syms, lengthof(reverbfix_ole_syms)); + log_info("Inserted reverbfix hook"); +} diff --git a/src/main/iidxhook9/reverbfix.h b/src/main/iidxhook9/reverbfix.h new file mode 100644 index 0000000..013db3b --- /dev/null +++ b/src/main/iidxhook9/reverbfix.h @@ -0,0 +1,6 @@ +#ifndef REVERBFIXHOOK_H +#define REVERBFIXHOOK_H + +void reverbfixhook_init(); + +#endif