vfs: hook System_getAppRootPath for unity games

This commit is contained in:
Hay1tsme 2024-04-07 17:55:38 -04:00
parent 16f7272751
commit 434382ce4b
3 changed files with 35 additions and 3 deletions

View File

@ -75,7 +75,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;

View File

@ -8,6 +8,8 @@
#include "hooklib/path.h"
#include "hooklib/reg.h"
#include "hook/procaddr.h"
#include "hook/table.h"
#include "platform/vfs.h"
@ -31,6 +33,18 @@ 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* my_System_getAppRootPath();
static wchar_t* (*next_System_getAppRootPath)();
static const struct hook_symbol amdaemon_syms[] = {
{
.name = "System_getAppRootPath",
.patch = my_System_getAppRootPath,
.link = (void **) &next_System_getAppRootPath,
},
};
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 +69,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 +82,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 +191,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;
}
@ -473,3 +496,12 @@ static HRESULT vfs_reg_read_appdata(void *bytes, uint32_t *nbytes)
{
return reg_hook_read_wstr(bytes, nbytes, vfs_config.appdata);
}
static wchar_t* my_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;
}

View File

@ -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);