From 8da836ccfba95136788d816dd16ffb197b5727fb Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Sun, 5 Jul 2026 15:25:57 +0000 Subject: [PATCH] epay: compatibility fixes (fixes #109) (#110) Untested, I don't have a real e-money server to verify this with Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/110 Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> --- common/platform/epay.c | 118 ++++++----------------------------------- common/platform/epay.h | 1 - 2 files changed, 17 insertions(+), 102 deletions(-) diff --git a/common/platform/epay.c b/common/platform/epay.c index 6193a2d..e30f8e2 100644 --- a/common/platform/epay.c +++ b/common/platform/epay.c @@ -14,6 +14,8 @@ #include +#include "hook/iohook.h" +#include "hooklib/serial.h" #include "util/dprintf.h" static HRESULT misc_read_thinca_adapter(void *bytes, uint32_t *nbytes); @@ -49,65 +51,13 @@ static struct thinca_main* (*next_ThincaPaymentGetInstance)(uint64_t ver); static struct thinca_main* thinca_stub; -static const struct reg_hook_val epay_adapter_keys[] = { - { - .name = L"TfpsAimeRwAdapter", - .read = misc_read_thinca_adapter, - .type = REG_SZ, - } -}; - -static const struct reg_hook_val epay_tcap_keys[] = { - { - .name = L"CaLocation", - .read = misc_read_ca_loc, - .type = REG_SZ, - }, - { - .name = L"ThincaTcapClientPath", - .read = misc_read_ca_client_loc, - .type = REG_SZ, - }, - { - .name = L"ClientNetworkTimeout", - .read = misc_read_network_timeout, - .type = REG_DWORD, - } -}; - -static const struct reg_hook_val epay_tcap_url0_keys[] = { - { - .name = L"Pattern", - .read = misc_read_pattern0, - .type = REG_SZ, - }, - { - .name = L"ClientNetworkTimeout", - .read = misc_read_network_timeout0, - .type = REG_DWORD, - } -}; - -static const struct reg_hook_val epay_tcap_url1_keys[] = { - { - .name = L"Pattern", - .read = misc_read_pattern1, - .type = REG_SZ, - }, - { - .name = L"ClientNetworkTimeout", - .read = misc_read_network_timeout1, - .type = REG_DWORD, - } -}; - static const struct hook_symbol epay_syms[] = { { .name = "ThincaPaymentGetVersion", .patch = my_ThincaPaymentGetVersion, .link = (void **) &next_ThincaPaymentGetVersion, .ordinal = 1, - }, + }, { .name = "__imp_ThincaPaymentGetInstance", .patch = my_ThincaPaymentGetInstance, @@ -122,61 +72,14 @@ static const struct hook_symbol epay_syms[] = { } }; -HRESULT epay_apply_registry_hooks(){ - HRESULT hr = reg_hook_push_key( - HKEY_LOCAL_MACHINE, - L"SOFTWARE\\TFPaymentService\\ThincaRwAdapter", - epay_adapter_keys, - _countof(epay_adapter_keys)); - - if (FAILED(hr)) { - return hr; - } - - hr = reg_hook_push_key( - HKEY_LOCAL_MACHINE, - L"SOFTWARE\\TFPaymentService\\ThincaTcapClient", - epay_tcap_keys, - _countof(epay_tcap_keys)); - - if (FAILED(hr)) { - return hr; - } - - hr = reg_hook_push_key( - HKEY_LOCAL_MACHINE, - L"SOFTWARE\\TFPaymentService\\ThincaTcapClient\\URL0", - epay_tcap_url0_keys, - _countof(epay_tcap_url0_keys)); - - if (FAILED(hr)) { - return hr; - } - - hr = reg_hook_push_key( - HKEY_LOCAL_MACHINE, - L"SOFTWARE\\TFPaymentService\\ThincaTcapClient\\URL1", - epay_tcap_url1_keys, - _countof(epay_tcap_url1_keys)); - - return hr; -} - HRESULT epay_hook_init(const struct epay_config *cfg) { - HRESULT hr; + HRESULT hr = S_OK; assert(cfg != NULL); if (!cfg->enable) { return S_FALSE; } - hr = epay_apply_registry_hooks(); - if (FAILED(hr)){ - return hr; - } - - dprintf("EPay: Registry initialized\n"); - // HACK:(?) the DLLs are loaded dynamically so we just preload it and apply DNS and VFS hooks to it HMODULE thincahttpclient = LoadLibraryA("thincahttpclient.dll"); if (thincahttpclient != NULL){ @@ -191,8 +94,21 @@ HRESULT epay_hook_init(const struct epay_config *cfg) { if (thincatcapclient != NULL){ path_hook_insert_hooks(thincatcapclient); } + HMODULE aime_adapter = LoadLibraryA("aime_rw_adapterMD.dll"); + if (aime_adapter != NULL){ + path_hook_insert_hooks(aime_adapter); + serial_hook_apply_hooks(aime_adapter); + iohook_apply_hooks(aime_adapter); + } + HMODULE aime_adapter_debug = LoadLibraryA("aime_rw_adapterMDD.dll"); + if (aime_adapter_debug != NULL){ + path_hook_insert_hooks(aime_adapter_debug); + serial_hook_apply_hooks(aime_adapter_debug); + iohook_apply_hooks(aime_adapter_debug); + } if (cfg->hook) { + hook_table_apply( NULL, "ThincaPayment.dll", diff --git a/common/platform/epay.h b/common/platform/epay.h index 70aa886..f972eaf 100644 --- a/common/platform/epay.h +++ b/common/platform/epay.h @@ -63,4 +63,3 @@ struct thinca_main { #pragma pack(pop) HRESULT epay_hook_init(const struct epay_config *cfg); -HRESULT epay_apply_registry_hooks(); \ No newline at end of file