From b0f307f427c600376f868934488d6fe751124e65 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Sun, 9 Jun 2024 00:50:54 +0200 Subject: [PATCH] Fixed option loading, thanks @Hay1tsme, close #16 --- cmhook/dllmain.c | 12 +++++----- mu3io/mu3io.h | 2 +- platform/platform.c | 2 +- platform/vfs.c | 54 ++++++++++++++++++++++++++++++++++++++++++--- platform/vfs.h | 2 +- unityhook/hook.c | 6 ++--- 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/cmhook/dllmain.c b/cmhook/dllmain.c index 687601a..65556da 100644 --- a/cmhook/dllmain.c +++ b/cmhook/dllmain.c @@ -55,6 +55,12 @@ static DWORD CALLBACK cm_pre_startup(void) goto fail; } + hr = cm_dll_init(&cm_hook_cfg.dll, cm_hook_mod); + + if (FAILED(hr)) { + goto fail; + } + hr = sg_reader_hook_init(&cm_hook_cfg.aime, 1, 1, cm_hook_mod); if (FAILED(hr)) { @@ -67,12 +73,6 @@ static DWORD CALLBACK cm_pre_startup(void) goto fail; } - hr = cm_dll_init(&cm_hook_cfg.dll, cm_hook_mod); - - if (FAILED(hr)) { - goto fail; - } - hr = cm_io4_hook_init(&cm_hook_cfg.io4); if (FAILED(hr)) { diff --git a/mu3io/mu3io.h b/mu3io/mu3io.h index 2f3b263..1fddac0 100644 --- a/mu3io/mu3io.h +++ b/mu3io/mu3io.h @@ -151,7 +151,7 @@ HRESULT mu3_io_led_init(void); that the board 0 is called from mu3 and the board 1 is called from amdaemon. So the library must be able to handle both calls, using shared memory f.e. This is up to the developer to decide how to handle this, recommended way is - to use the amdaemon process as the main one and the mu3 call as a sub one. + to use the amdaemon process as the main one and the mu3 process as a sub one. Minimum API version: 0x0101 */ diff --git a/platform/platform.c b/platform/platform.c index 6b11c2c..5a1b5f6 100644 --- a/platform/platform.c +++ b/platform/platform.c @@ -76,7 +76,7 @@ HRESULT platform_hook_init( return hr; } - hr = vfs_hook_init(&cfg->vfs); + hr = vfs_hook_init(&cfg->vfs, game_id); if (FAILED(hr)) { return hr; diff --git a/platform/vfs.c b/platform/vfs.c index c44bbb0..26e4d34 100644 --- a/platform/vfs.c +++ b/platform/vfs.c @@ -9,6 +9,9 @@ #include "hooklib/path.h" #include "hooklib/reg.h" +#include "hook/procaddr.h" +#include "hook/table.h" + #include "platform/vfs.h" #include "util/dprintf.h" @@ -31,6 +34,26 @@ static HRESULT vfs_path_hook_option( static HRESULT vfs_reg_read_amfs(void *bytes, uint32_t *nbytes); static HRESULT vfs_reg_read_appdata(void *bytes, uint32_t *nbytes); +static wchar_t* hook_System_getAppRootPath(); +static wchar_t* (*next_System_getAppRootPath)(); + +static wchar_t* hook_AppImage_getOptionMountRootPath(); +static wchar_t* (*next_AppImage_getOptionMountRootPath)(); + +static const struct hook_symbol amdaemon_syms[] = { + { + .name = "System_getAppRootPath", + .patch = hook_System_getAppRootPath, + .link = (void **) &next_System_getAppRootPath, + }, + { + .name = "AppImage_getOptionMountRootPath", + .patch = hook_AppImage_getOptionMountRootPath, + .link = (void **) &next_AppImage_getOptionMountRootPath, + }, +}; + +static wchar_t game[5] = {0}; static wchar_t vfs_nthome_real[MAX_PATH]; static const wchar_t vfs_nthome[] = L"C:\\Documents and Settings\\AppUser"; static const size_t vfs_nthome_len = _countof(vfs_nthome) - 1; @@ -55,7 +78,7 @@ static const struct reg_hook_val vfs_reg_vals[] = { static struct vfs_config vfs_config; -HRESULT vfs_hook_init(const struct vfs_config *config) +HRESULT vfs_hook_init(const struct vfs_config *config, const char* game_id) { wchar_t temp[MAX_PATH]; size_t nthome_len; @@ -68,6 +91,8 @@ HRESULT vfs_hook_init(const struct vfs_config *config) return S_FALSE; } + mbstowcs(game, game_id, 4); + if (config->amfs[0] == L'\0') { dprintf("Vfs: FATAL: AMFS path not specified in INI file\n"); @@ -175,6 +200,13 @@ HRESULT vfs_hook_init(const struct vfs_config *config) return hr; } + proc_addr_table_push( + NULL, + "amdaemon_api.dll", + amdaemon_syms, + _countof(amdaemon_syms) + ); + return S_OK; } @@ -287,8 +319,6 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count) } switch (src[0]) { - // case L'D': // later AMDaemon versions default to D: for AMFS if it can't find it - // case L'd': case L'e': case L'E': redir = vfs_config.amfs; @@ -479,3 +509,21 @@ static HRESULT vfs_reg_read_appdata(void *bytes, uint32_t *nbytes) { return reg_hook_read_wstr(bytes, nbytes, L"Y:\\"); } + +static wchar_t* hook_System_getAppRootPath() +{ + wchar_t *path = malloc(sizeof(wchar_t) * MAX_PATH); + wcscpy_s(path, MAX_PATH, vfs_config.appdata); + wcscat_s(path, MAX_PATH, game); + wcscat_s(path, MAX_PATH, L"\\"); + + return path; +} + +static wchar_t* hook_AppImage_getOptionMountRootPath() +{ + wchar_t *path = malloc(sizeof(wchar_t) * MAX_PATH); + wcscpy_s(path, MAX_PATH, vfs_config.option); + + return path; +} diff --git a/platform/vfs.h b/platform/vfs.h index 8767305..a7e513f 100644 --- a/platform/vfs.h +++ b/platform/vfs.h @@ -12,4 +12,4 @@ struct vfs_config { wchar_t option[MAX_PATH]; }; -HRESULT vfs_hook_init(const struct vfs_config *config); +HRESULT vfs_hook_init(const struct vfs_config *config, const char* game_id); diff --git a/unityhook/hook.c b/unityhook/hook.c index 02a1e38..bd380f9 100644 --- a/unityhook/hook.c +++ b/unityhook/hook.c @@ -24,11 +24,13 @@ static const wchar_t *target_modules[] = { L"mono.dll", L"mono-2.0-bdwgc.dll", L"cri_ware_unity.dll", + L"amdaemon_api.dll", L"SerialPortAPI.dll", L"C300usb.dll", L"C300FWDLusb.dll", L"apmled.dll", - L"apmmount.dll", + L"HKBSys_api.dll", + L"amptw.dll" }; static const size_t target_modules_len = _countof(target_modules); @@ -138,9 +140,7 @@ static HMODULE WINAPI hook_LoadLibraryW(const wchar_t *name) path_hook_insert_hooks(result); // printer_hook_insert_hooks(result); - reg_hook_insert_hooks(result); - proc_addr_insert_hooks(result); serial_hook_apply_hooks(result); iohook_apply_hooks(result);