Add fs hook for F drive in iidxhook9 #303

Merged
willxinc merged 1 commits from fs-hook-fix into master 2024-05-12 03:17:40 +03:00
4 changed files with 61 additions and 0 deletions
+1
View File
@@ -29,4 +29,5 @@ libs_iidxhook9 := \
src_iidxhook9 := \
config-io.c \
fs-hook.c \
dllmain.c \
+4
View File
@@ -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();
+50
View File
@@ -0,0 +1,50 @@
#define LOG_MODULE "fs-hook"
#include <stdint.h>
#include <string.h>
#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
icex2 commented 2024-05-12 02:57:06 +03:00 (Migrated from github.com)
Review

suggestion: I guess it's fine to hook it like that, but that might introduce re-usability issues with different AVS versions. I suggest to at least ifdef guard it and check that the AVS_VERSION define is within the right version range. Probably just throw an error for now if it isn't, so the next dev has visibility on that matter at least and needs to double check.

suggestion: I guess it's fine to hook it like that, but that might introduce re-usability issues with different AVS versions. I suggest to at least ifdef guard it and check that the AVS_VERSION define is within the right version range. Probably just throw an error for now if it isn't, so the next dev has visibility on that matter at least and needs to double check.
willxinc commented 2024-05-12 03:07:21 +03:00 (Migrated from github.com)
Review

The hook is scoped to iidxhook9, so the symbol will always be that.

The hook is scoped to iidxhook9, so the symbol will always be that.
icex2 commented 2024-05-12 03:13:47 +03:00 (Migrated from github.com)
Review

Right, thanks for highlighting. Kinda missed that detail.

Right, thanks for highlighting. Kinda missed that detail.
.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') {
icex2 commented 2024-05-12 02:57:49 +03:00 (Migrated from github.com)
Review

question: Is it always capital 'F'? Seen some odd stuff in the past where they also used the lower-case drive letters because reasons.

question: Is it always capital 'F'? Seen some odd stuff in the past where they also used the lower-case drive letters because reasons.
willxinc commented 2024-05-12 03:07:26 +03:00 (Migrated from github.com)
Review

Yes

Yes
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);
icex2 commented 2024-05-12 02:59:26 +03:00 (Migrated from github.com)
Review

suggestion: Not happy with the solution as it forces you to a hardcoded path. Maybe someone still wants these recordings on a separate disk or usb thumb drive? How about making this path configurable? We also got d and e folders configurable, iirc.

suggestion: Not happy with the solution as it forces you to a hardcoded path. Maybe someone still wants these recordings on a separate disk or usb thumb drive? How about making this path configurable? We also got d and e folders configurable, iirc.
willxinc commented 2024-05-12 03:09:51 +03:00 (Migrated from github.com)
Review

Sounds reasonable, however this is not a regular path, but an AVS fs path instead, so I think exposing it might cause confusion, whereas most people should have a dev folder setup.

Sounds reasonable, however this is not a regular path, but an AVS fs path instead, so I think exposing it might cause confusion, whereas most people should have a dev folder setup.
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");
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef IIDXHOOK9_FS_HOOKS_H
#define IIDXHOOK9_FS_HOOKS_H
void iidxhook9_fs_hooks_init();
#endif