Fixed option loading, thanks @Hay1tsme, close #16

This commit is contained in:
Dniel97 2024-06-09 00:50:54 +02:00
parent 7aa996193c
commit b0f307f427
Signed by untrusted user: Dniel97
GPG Key ID: 6180B3C768FB2E08
6 changed files with 63 additions and 15 deletions

View File

@ -55,6 +55,12 @@ static DWORD CALLBACK cm_pre_startup(void)
goto fail; 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); hr = sg_reader_hook_init(&cm_hook_cfg.aime, 1, 1, cm_hook_mod);
if (FAILED(hr)) { if (FAILED(hr)) {
@ -67,12 +73,6 @@ static DWORD CALLBACK cm_pre_startup(void)
goto fail; 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); hr = cm_io4_hook_init(&cm_hook_cfg.io4);
if (FAILED(hr)) { if (FAILED(hr)) {

View File

@ -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. 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. 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 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 */ Minimum API version: 0x0101 */

View File

@ -76,7 +76,7 @@ HRESULT platform_hook_init(
return hr; return hr;
} }
hr = vfs_hook_init(&cfg->vfs); hr = vfs_hook_init(&cfg->vfs, game_id);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; return hr;

View File

@ -9,6 +9,9 @@
#include "hooklib/path.h" #include "hooklib/path.h"
#include "hooklib/reg.h" #include "hooklib/reg.h"
#include "hook/procaddr.h"
#include "hook/table.h"
#include "platform/vfs.h" #include "platform/vfs.h"
#include "util/dprintf.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_amfs(void *bytes, uint32_t *nbytes);
static HRESULT vfs_reg_read_appdata(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 wchar_t vfs_nthome_real[MAX_PATH];
static const wchar_t vfs_nthome[] = L"C:\\Documents and Settings\\AppUser"; static const wchar_t vfs_nthome[] = L"C:\\Documents and Settings\\AppUser";
static const size_t vfs_nthome_len = _countof(vfs_nthome) - 1; 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; 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]; wchar_t temp[MAX_PATH];
size_t nthome_len; size_t nthome_len;
@ -68,6 +91,8 @@ HRESULT vfs_hook_init(const struct vfs_config *config)
return S_FALSE; return S_FALSE;
} }
mbstowcs(game, game_id, 4);
if (config->amfs[0] == L'\0') { if (config->amfs[0] == L'\0') {
dprintf("Vfs: FATAL: AMFS path not specified in INI file\n"); 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; return hr;
} }
proc_addr_table_push(
NULL,
"amdaemon_api.dll",
amdaemon_syms,
_countof(amdaemon_syms)
);
return S_OK; 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]) { 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':
case L'E': case L'E':
redir = vfs_config.amfs; 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:\\"); 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;
}

View File

@ -12,4 +12,4 @@ struct vfs_config {
wchar_t option[MAX_PATH]; 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);

View File

@ -24,11 +24,13 @@ static const wchar_t *target_modules[] = {
L"mono.dll", L"mono.dll",
L"mono-2.0-bdwgc.dll", L"mono-2.0-bdwgc.dll",
L"cri_ware_unity.dll", L"cri_ware_unity.dll",
L"amdaemon_api.dll",
L"SerialPortAPI.dll", L"SerialPortAPI.dll",
L"C300usb.dll", L"C300usb.dll",
L"C300FWDLusb.dll", L"C300FWDLusb.dll",
L"apmled.dll", L"apmled.dll",
L"apmmount.dll", L"HKBSys_api.dll",
L"amptw.dll"
}; };
static const size_t target_modules_len = _countof(target_modules); 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); path_hook_insert_hooks(result);
// printer_hook_insert_hooks(result); // printer_hook_insert_hooks(result);
reg_hook_insert_hooks(result); reg_hook_insert_hooks(result);
proc_addr_insert_hooks(result); proc_addr_insert_hooks(result);
serial_hook_apply_hooks(result); serial_hook_apply_hooks(result);
iohook_apply_hooks(result); iohook_apply_hooks(result);