From 926493290b089df3abe7dde9203daa91d0174907 Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Tue, 26 Dec 2023 06:25:26 -0500 Subject: [PATCH] fix chunihook --- chunihook/chuni-dll.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/chunihook/chuni-dll.c b/chunihook/chuni-dll.c index 72393e9..5867f66 100644 --- a/chunihook/chuni-dll.c +++ b/chunihook/chuni-dll.c @@ -39,6 +39,19 @@ const struct dll_bind_sym chuni_dll_syms[] = { } }; +/* Helper function to determine upon dll_bind failure whether the required functions were found + NOTE: relies on symbols order declared above */ +static HRESULT has_enough_symbols(uint16_t version, uint8_t count) +{ + if ( version <= 0x0101 && count == 7 ) + return S_OK; + + if ( version >= 0x0102 && count == 9 ) + return S_OK; + + return E_FAIL; +} + struct chuni_dll chuni_dll; // Copypasta DLL binding and diagnostic message boilerplate. @@ -98,16 +111,24 @@ HRESULT chuni_dll_init(const struct chuni_dll_config *cfg, HINSTANCE self) } sym = chuni_dll_syms; + const struct dll_bind_sym *init_sym = &sym[0]; hr = dll_bind(&chuni_dll, src, &sym, _countof(chuni_dll_syms)); if (FAILED(hr)) { if (src != self) { - dprintf("Chunithm IO: Custom IO DLL does not provide function " - "\"%s\". Please contact your IO DLL's developer for " - "further assistance.\n", - sym->sym); + // Might still be ok depending on external dll API version + int bind_count = sym - init_sym; + if ( has_enough_symbols(chuni_dll.api_version, bind_count) == S_OK ) + { + hr = S_OK; + } else { + dprintf("Chunithm IO: Custom IO DLL does not provide function " + "\"%s\". Please contact your IO DLL's developer for " + "further assistance.\n", + sym->sym); - goto end; + goto end; + } } else { dprintf("Internal error: could not reflect \"%s\"\n", sym->sym); }