From a03c4e0d93ab46ff182a757934da5b02cc15fa3c Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Sat, 11 May 2024 01:45:20 -0700 Subject: [PATCH] iidxhook9: add fs hook for F drive --- src/main/iidxhook9/Module.mk | 1 + src/main/iidxhook9/dllmain.c | 4 +++ src/main/iidxhook9/fs-hook.c | 50 ++++++++++++++++++++++++++++++++++++ src/main/iidxhook9/fs-hook.h | 6 +++++ 4 files changed, 61 insertions(+) create mode 100644 src/main/iidxhook9/fs-hook.c create mode 100644 src/main/iidxhook9/fs-hook.h diff --git a/src/main/iidxhook9/Module.mk b/src/main/iidxhook9/Module.mk index 30384f1..09e56a8 100644 --- a/src/main/iidxhook9/Module.mk +++ b/src/main/iidxhook9/Module.mk @@ -29,4 +29,5 @@ libs_iidxhook9 := \ src_iidxhook9 := \ config-io.c \ + fs-hook.c \ dllmain.c \ diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c index b7ae85a..577d35b 100644 --- a/src/main/iidxhook9/dllmain.c +++ b/src/main/iidxhook9/dllmain.c @@ -26,6 +26,7 @@ #include "bio2emu-iidx/bi2a.h" #include "iidxhook9/config-io.h" +#include "iidxhook9/fs-hook.h" #include "camhook/cam.h" #include "camhook/config-cam.h" @@ -159,6 +160,9 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) } else { memfile_hook_add_fd("d:\\\\001rom.txt", ABSOLUTE_MATCH, "LDJ", 3); } + + // redirect F:\ drive to vfs (used for video recording) + iidxhook9_fs_hooks_init(); } rs232_hook_init(); diff --git a/src/main/iidxhook9/fs-hook.c b/src/main/iidxhook9/fs-hook.c new file mode 100644 index 0000000..b7e0df2 --- /dev/null +++ b/src/main/iidxhook9/fs-hook.c @@ -0,0 +1,50 @@ +#define LOG_MODULE "fs-hook" + +#include +#include + +#include "hook/table.h" + +#include "imports/avs.h" + +#include "iidxhook9/fs-hook.h" + +#include "util/log.h" +#include "util/str.h" + +static void *(*real_avs_fs_mount)(const char *dest, const char *src, const char *fs_type, const char *options); +static void *my_avs_fs_mount(const char *dest, const char *src, const char *fs_type, const char *options); + +static const struct hook_symbol avs_fs_hook_syms[] = { + {.name = "XCgsqzn000004b", // avs_fs_mount + .ordinal = 76, + .patch = my_avs_fs_mount, + .link = (void **) &real_avs_fs_mount}, +}; + +static void *my_avs_fs_mount(const char *dest, const char *src, const char *fs_type, const char *options) +{ + // quick check for "F:\" + if (src[0] == 'F' && src[1] == ':' && src[2] == '\0') { + const char* dev_folder_drive = "dev/vfs/drive_f/"; + log_misc("Redirecting %s to %s", src, dev_folder_drive); + + CreateDirectoryA("dev/vfs/", NULL); + CreateDirectoryA("dev/vfs/drive_f/", NULL); + + return real_avs_fs_mount(dest, dev_folder_drive, fs_type, options); + } + + return real_avs_fs_mount(dest, src, fs_type, options); +} + +void iidxhook9_fs_hooks_init() +{ + hook_table_apply( + NULL, + "avs2-core.dll", + avs_fs_hook_syms, + lengthof(avs_fs_hook_syms)); + + log_info("Inserted avs fs hooks"); +} diff --git a/src/main/iidxhook9/fs-hook.h b/src/main/iidxhook9/fs-hook.h new file mode 100644 index 0000000..4b0d514 --- /dev/null +++ b/src/main/iidxhook9/fs-hook.h @@ -0,0 +1,6 @@ +#ifndef IIDXHOOK9_FS_HOOKS_H +#define IIDXHOOK9_FS_HOOKS_H + +void iidxhook9_fs_hooks_init(); + +#endif