[memfile] Add support for faking files in memory

This commit is contained in:
Will Xyen
2020-10-18 14:46:34 -07:00
parent be5a773cb7
commit 3d4df4cd64
9 changed files with 375 additions and 1 deletions

View File

@@ -9,11 +9,13 @@
#define SDVXHOOK2_CONFIG_IO_DISABLE_BIO2_EMU_KEY "io.disable_bio2_emu"
#define SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY "io.disable_poll_limiter"
#define SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY "io.force_headphones"
#define SDVXHOOK2_CONFIG_IO_DISABLE_FILE_HOOKS_KEY "io.disable_file_hooks"
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE false
void sdvxhook2_config_io_init(struct cconfig *config)
{
@@ -41,6 +43,12 @@ void sdvxhook2_config_io_init(struct cconfig *config)
SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE,
"Forces game to think headphones are attached");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_FILE_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE,
"Disables the built in file hooks, requiring manual file creation (/dev/raw/j.dest)");
}
void sdvxhook2_config_io_get(
@@ -93,4 +101,16 @@ void sdvxhook2_config_io_get(
SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_FILE_HOOKS_KEY,
&config_io->disable_file_hooks,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_FILE_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE);
}
}

View File

@@ -10,6 +10,7 @@ struct sdvxhook2_config_io {
bool disable_bio2_emu;
bool disable_poll_limiter;
bool force_headphones;
bool disable_file_hooks;
};
void sdvxhook2_config_io_init(struct cconfig *config);

View File

@@ -14,6 +14,7 @@
#include "hooklib/adapter.h"
#include "hooklib/app.h"
#include "hooklib/config-adapter.h"
#include "hooklib/memfile.h"
#include "hooklib/rs232.h"
#include "bio2emu/emu.h"
@@ -51,6 +52,21 @@ static struct bio2emu_port bio2_emu = {
.dispatcher = bio2_emu_bi2a_dispatch_request,
};
static void attach_dest_fd_intercept(const char *sidcode)
{
char region = sidcode[3];
if (region == 'X') {
region = 'J';
}
char target_file[8] = "\\x.dest";
target_file[1] = tolower(region);
// can only capture these by ending path due to /dev/raw being mountable
memfile_hook_add_fd(target_file, ENDING_MATCH, NULL, 0);
}
static bool my_dll_entry_init(char *sidcode, struct property_node *param)
{
struct cconfig *config;
@@ -113,12 +129,21 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iohook_push_handler(ac_io_port_dispatch_irp);
iohook_push_handler(bio2emu_port_dispatch_irp);
if (!config_io.disable_file_hooks) {
memfile_hook_init();
iohook_push_handler(memfile_hook_dispatch_irp);
attach_dest_fd_intercept(sidcode);
}
rs232_hook_init();
rs232_hook_limit_hooks();
if (!config_io.disable_bio2_emu) {
bio2emu_init();
bio2_emu_bi2a_init(&bio2_emu, config_io.disable_poll_limiter, config_io.force_headphones);
bio2_emu_bi2a_init(
&bio2_emu,
config_io.disable_poll_limiter,
config_io.force_headphones);
}
if (!config_io.disable_card_reader_emu) {
@@ -157,6 +182,10 @@ static bool my_dll_entry_main(void)
sdvx_io_fini();
}
if (!config_io.disable_file_hooks) {
memfile_hook_fini();
}
return result;
}