1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-28 00:10:51 +01:00

feat(iidx19): imagefs override strategy with local file redir

This commit is contained in:
icex2 2023-04-01 20:47:37 +02:00 committed by icex2
parent 031836ef0e
commit ffe678de61
6 changed files with 84 additions and 1 deletions

View File

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

View File

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

View File

@ -25,3 +25,4 @@ libs_iidxhook5 := \
src_iidxhook5 := \
dllmain.c \
ifs-snd-redir.c \

View File

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

View File

@ -0,0 +1,64 @@
#define LOG_MODULE "ifs-snd-redir"
#include <stdint.h>
#include <string.h>
#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");
}

View File

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