diff --git a/games/idzhook/crt.c b/games/idzhook/crt.c new file mode 100644 index 0000000..2bd8be3 --- /dev/null +++ b/games/idzhook/crt.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include "hook/table.h" + +#include "crt.h" + +#include "util/dprintf.h" + +/* API hooks */ + +static int WINAPIV hook__stat64i32( + const char *path, + struct _stat64i32 *buffer +); + +/* Link pointers */ + +static int (WINAPIV *next__stat64i32)( + const char *path, + struct _stat64i32 *buffer +); + +static const char *target_executables[] = { + "InitialD0_DX11_Nu.exe", + "amdaemon.exe", +}; + +static const size_t target_executables_len = _countof(target_executables); + + +static const struct hook_symbol msvcr110_hooks[] = { + { + .name = "_stat64i32", + .patch = hook__stat64i32, + .link = (void**) &next__stat64i32 + } +}; + +void crt_hook_init(void) +{ + dprintf("CRT: Hooks init.\n"); + + hook_table_apply( + NULL, + "msvcr110.dll", + msvcr110_hooks, + _countof(msvcr110_hooks)); +} + +static int __cdecl hook__stat64i32( + const char *path, + struct _stat64i32 *buffer +) +{ + const char *target_executable; + + if (path != NULL) { + for (size_t i = 0; i < target_executables_len; i++) { + target_executable = target_executables[i]; + + if (strstr(path, target_executable)) { + dprintf("CRT: Bypassing size check for %s\n", path); + return 0; + } + } + } + + return next__stat64i32(path, buffer); +} diff --git a/games/idzhook/crt.h b/games/idzhook/crt.h new file mode 100644 index 0000000..27ba9ca --- /dev/null +++ b/games/idzhook/crt.h @@ -0,0 +1,3 @@ +#include + +void crt_hook_init(void); diff --git a/games/idzhook/dllmain.c b/games/idzhook/dllmain.c index b73a6a4..f501640 100644 --- a/games/idzhook/dllmain.c +++ b/games/idzhook/dllmain.c @@ -35,6 +35,7 @@ #include "idzhook/jvs.h" #include "idzhook/ffb.h" #include "idzhook/zinput.h" +#include "idzhook/crt.h" #include "platform/platform.h" @@ -86,6 +87,7 @@ static DWORD CALLBACK idz_pre_startup(void) gfx_dxgi_hook_init(&idz_hook_cfg.gfx, idz_hook_mod); zinput_hook_init(&idz_hook_cfg.zinput); dvd_hook_init(&idz_hook_cfg.dvd, idz_hook_mod); + crt_hook_init(); /* Initialize emulation hooks */ diff --git a/games/idzhook/meson.build b/games/idzhook/meson.build index 6649489..32e1dfb 100644 --- a/games/idzhook/meson.build +++ b/games/idzhook/meson.build @@ -24,6 +24,8 @@ shared_library( sources : [ 'config.c', 'config.h', + 'crt.c', + 'crt.h', 'dllmain.c', 'idz-dll.c', 'idz-dll.h',