diff --git a/src/imports/avs.h b/src/imports/avs.h index 5b23183..ff48a33 100644 --- a/src/imports/avs.h +++ b/src/imports/avs.h @@ -231,6 +231,7 @@ void property_node_datasize(struct property_node *node); bool std_getenv(const char *key, char *val, uint32_t nbytes); void std_setenv(const char *key, const char *val); +void* avs_fs_open(const char* path, int mode, int flags); int avs_fs_addfs(void *filesys_struct); int avs_fs_mount( const char *mountpoint, const char *fsroot, const char *fstype, void *data); diff --git a/src/imports/import_32_1304_avs.def b/src/imports/import_32_1304_avs.def index 2dea570..489944a 100644 --- a/src/imports/import_32_1304_avs.def +++ b/src/imports/import_32_1304_avs.def @@ -2,6 +2,7 @@ LIBRARY libavs-win32 EXPORTS avs_boot @237 NONAME + avs_fs_open @178 NONAME avs_net_ctrl @15 NONAME avs_shutdown @333 NONAME avs_thread_create @183 NONAME @@ -25,4 +26,4 @@ EXPORTS property_read_query_memsize @100 NONAME property_search @244 NONAME std_getenv @226 NONAME - std_setenv @114 NONAME + std_setenv @114 NONAME diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk index f41c0b3..78ea307 100644 --- a/src/main/iidxhook5/Module.mk +++ b/src/main/iidxhook5/Module.mk @@ -25,3 +25,4 @@ libs_iidxhook5 := \ src_iidxhook5 := \ dllmain.c \ + ifs-snd-redir.c \ diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index 7a03321..268bf39 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -40,6 +40,8 @@ #include "util/str.h" #include "util/thread.h" +#include "ifs-snd-redir.h" + #define IIDXHOOK5_INFO_HEADER \ "iidxhook for Lincle" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -179,6 +181,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) ezusb2_emu_device_hook_init(ezusb2_iidx_emu_msg_init()); } + iidxhook5_ifs_snd_redir_init(); + /* Card reader emulation, same issue with hooking as IO emulation */ rs232_hook_init(); diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c new file mode 100644 index 0000000..f4809bf --- /dev/null +++ b/src/main/iidxhook5/ifs-snd-redir.c @@ -0,0 +1,64 @@ +#define LOG_MODULE "ifs-snd-redir" + +#include +#include + +#include "hook/table.h" + +#include "imports/avs.h" + +#include "iidxhook5/ifs-snd-redir.h" + +#include "util/log.h" +#include "util/str.h" + +static void* (*real_avs_fs_open)(const char* path, int mode, int flags); +static void* my_avs_fs_open(const char* path, int mode, int flags); + +static const struct hook_symbol iidxhook5_ifs_snd_redir_hook_syms[] = { + {.name = "XC058ba50000b6", // avs_fs_open + .patch = my_avs_fs_open, + .link = (void **) &real_avs_fs_open}, +}; + +static void* my_avs_fs_open(const char* path, int mode, int flags) +{ + void* handle; + char redir_path[MAX_PATH]; + + // Trap virtual path /sd00/*, /sd01/*, /sd02/*, /sd03/* that contain + // sound data that is stored in ifs files in data/imagefs + // Create a generice override strategy by redirecting to local folder + // /sound/*. Check if open succeeds and return that. Otherwise, stay on + // imagefs path to stay compatible with stock data. + + if (!strncmp(path, "/sd0", 4)) { + strcpy(redir_path, "/data/sound"); + strcat(redir_path, &path[5]); + + log_misc("Sound data redirect: %s -> %s", path, redir_path); + + handle = real_avs_fs_open(redir_path, mode, flags); + + if (handle != NULL) { + log_misc("Success, use %s", redir_path); + return handle; + } else { + log_misc("Failure, use %s", path); + return real_avs_fs_open(path, mode, flags); + } + } + + return real_avs_fs_open(path, mode, flags); +} + +void iidxhook5_ifs_snd_redir_init() +{ + hook_table_apply( + NULL, + "libavs-win32.dll", + iidxhook5_ifs_snd_redir_hook_syms, + lengthof(iidxhook5_ifs_snd_redir_hook_syms)); + + log_info("Inserted ifs-snd-redir hooks"); +} diff --git a/src/main/iidxhook5/ifs-snd-redir.h b/src/main/iidxhook5/ifs-snd-redir.h new file mode 100644 index 0000000..e649081 --- /dev/null +++ b/src/main/iidxhook5/ifs-snd-redir.h @@ -0,0 +1,12 @@ +#ifndef IIDXHOOK5_IFS_SND_REDIR_H +#define IIDXHOOK5_IFS_SND_REDIR_H + +/** + * Redirect any reads from the ifs files in data/imagefs that contain + * sound data to local files in data/sound. Required to enable bemanitools + * monitor-check feature to trap open calls to all sound data and apply + * different monitor refresh values. + */ +void iidxhook5_ifs_snd_redir_init(); + +#endif