refact(sdvxhook2) Use new config api

Summary:

Test Plan:
Summary:

Test Plan:
This commit is contained in:
icex2
2024-08-17 12:50:14 +02:00
parent d1c346595c
commit ee85ad4447
17 changed files with 364 additions and 534 deletions

View File

@@ -650,7 +650,6 @@ $(zipdir)/sdvx-05-to-06.zip: \
build/bin/indep-64/sdvxio.dll \
dist/sdvx5/config.bat \
dist/sdvx5/gamestart.bat \
dist/sdvx5/sdvxhook2.conf \
dist/sdvx5/launcher.xml \
dist/shared/ea3-ident.xml \
dist/shared/ea3-license.xml \

View File

@@ -20,6 +20,18 @@ set CONTENT_DIR=%CD%\..
set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools
set MODULES_DIR=%CONTENT_DIR%\modules
if not exist "%BEMANITOOLS_DIR%" (
echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist.
pause
exit 1
)
if not exist "%MODULES_DIR%" (
echo The game modules directory "%MODULES_DIR%" does not exist.
pause
exit 1
)
:: Keep that data vanilla, no need to copy these around anymore
:: Just add them to the env PATH so launcher can find the libs and game executable
:: Remark: This also requires admin privileges to propage correctly to launcher
@@ -31,4 +43,6 @@ set PATH=^
:: Current working dir is the game's root folder
cd /d %CONTENT_DIR%
%BEMANITOOLS_DIR%\launcher %BEMANITOOLS_DIR%\launcher.xml --config %BEMANITOOLS_DIR%\sdvxhook2.conf %*
%BEMANITOOLS_DIR%\launcher.exe^
%BEMANITOOLS_DIR%\launcher.xml^
%*

View File

@@ -58,15 +58,79 @@
<eamuse>
<config kind="file">bemanitools/ea3-service.xml</config>
</eamuse>
<hook>
<hook_dlls>
<dll __type="str">sdvxhook2.dll</dll>
</hook_dlls>
<before_hook_dlls>
</before_hook_dlls>
<iat_hook_dlls>
</iat_hook_dlls>
</hook>
<hooks>
<hook>
<enable __type="bool">1</enable>
<path __type="str">sdvxhook2.dll</path>
<config kind="inline">
<hook>
<adapter>
<!-- IP of adapter to force override with -->
<override_ip __type="str"></override_ip>
</adapter>
<gfx>
<device>
<!-- D3D9ex device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter -->
<adapter __type="s32">-1</adapter>
<!-- Forced refresh rate, -1 to not force any (try 59 or 60 if monitor check fails to lock on high refresh rate monitors) -->
<forced_refresh_rate __type="s32">-1</forced_refresh_rate>
<!-- Orientation to force monitor into, -1 to use default, 0, 1, 2, 3 to do 0, 90, 180, 270 degrees -->
<force_orientation __type="s32">-1</force_orientation>
<!-- Force a screen resolution (width), -1 to disable. Use this if the game does not auto detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720. -->
<force_screen_res>
<width __type="s32">-1</width>
<height __type="s32">-1</height>
</force_screen_res>
</device>
<window>
<!-- Run the game windowed -->
<windowed __type="bool">0</windowed>
<!-- Run the game in a framed window (requires windowed option) -->
<framed __type="bool">1</framed>
<!-- Confine mouse cursor to window -->
<confined __type="bool">0</confined>
<!-- Windowed width, -1 for default size -->
<width __type="s32">1080</width>
<!-- Windowed height, -1 for default size -->
<height __type="s32">1920</height>
<!-- Windowed X, -1 for default X position -->
<x __type="s32">-1</x>
<!-- Windowed Y, -1 for default Y position -->
<y __type="s32">-1</y>
</window>
</gfx>
<camera>
<!-- Disables the camera emulation -->
<disable_emu __type="bool">0</disable_emu>
<device_1>
<!-- Disable camera 1. Use, i.e., if you only have one camera and want it to be mapped to camera 2 ingame. -->
<disable __type="bool">1</disable>
<!-- Override camera device ID 1 detection (copy from device manager, do not escape) Leave blank to automatically detect -->
<id __type="str"></id>
</device_1>
</camera>
<io>
<!-- Disable card reader emulation and enable usage of real card reader hardware on COM2 -->
<disable_card_reader_emu __type="bool">0</disable_card_reader_emu>
<!-- Disable BIO2 emulation and enable usage of real BIO2 hardware -->
<disable_bio2_emu __type="bool">0</disable_bio2_emu>
<!-- Disables the poll limiter, warning very high CPU usage may arise -->
<disable_poll_limiter __type="bool">0</disable_poll_limiter>
<!-- Forces game to think headphones are attached -->
<force_headphones __type="bool">0</force_headphones>
<!-- Disables the built in file hooks, requiring manual file creation (/dev/raw/j.dest) -->
<disable_file_hooks __type="bool">0</disable_file_hooks>
<!-- Disables the built in power control hooks, allowing game to modify system power settings -->
<disable_power_hooks __type="bool">0</disable_power_hooks>
<!-- Disables the built in NVAPI control hooks, allowing game to modify system monitor settings -->
<disable_nvapi_hooks __type="bool">0</disable_nvapi_hooks>
<!-- Emulates the card reader on COM1 instead of COM2 -->
<com1_card_reader __type="bool">0</com1_card_reader>
</io>
</hook>
</config>
</hook>
</hooks>
<debug>
<remote_debugger __type="bool">0</remote_debugger>
<log_property_configs __type="bool">0</log_property_configs>

View File

@@ -1,69 +0,0 @@
# Disable card reader emulation and enable usage of real card reader hardware on COM2
io.disable_card_reader_emu=false
# Disable BIO2 emulation and enable usage of real BIO2 hardware
io.disable_bio2_emu=false
# Disables the poll limiter, warning very high CPU usage may arise
io.disable_poll_limiter=false
# Forces game to think headphones are attached
io.force_headphones=false
# Disables the built in file hooks, requiring manual file creation (/dev/raw/j.dest)
io.disable_file_hooks=false
# Disables the built in power control hooks, allowing game to modify system power settings
io.disable_power_hooks=false
# Disables the built in NVAPI control hooks, allowing game to modify system monitor settings
io.disable_nvapi_hooks=false
# Emulates the card reader on COM1 instead of COM2
io.com1_card_reader=false
# Run the game in a framed window (requires windowed option)
gfx.framed=true
# Run the game windowed
gfx.windowed=false
# Confine mouse cursor to window
gfx.confined=false
# Windowed width, -1 for default size
gfx.window_width=1080
# Windowed height, -1 for default size
gfx.window_height=1920
# Windowed X, -1 for default X position
gfx.window_x=-1
# Windowed Y, -1 for default Y position
gfx.window_y=-1
# Forced refresh rate, -1 to not force any (try 59 or 60 if monitor check fails to lock on high refresh rate monitors)
gfx.forced_refresh_rate=-1
# D3D9ex device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter
gfx.device_adapter=-1
# Orientation to force monitor into, -1 to use default, 0, 1, 2, 3 to do 0, 90, 180, 270 degrees
gfx.force_orientation=-1
# Force a screen resolution (width), -1 to disable. Use this if the game does not auto detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720.
gfx.force_screen_res.width=-1
# Force a screen resolution (height), -1 to disable. Use this if the game does not auto detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720.
gfx.force_screen_res.height=-1
# Disables the camera emulation
cam.disable_emu=false
# Override camera device ID detection (copy from device manager, do not escape)
cam.device_id1=
# IP of adapter to force override with
adapter.override_ip=

View File

@@ -8,7 +8,7 @@
void camhook_config_cam_get(
const bt_core_config_t *config,
struct camhook_config_cam *config_cam,
camhook_config_cam_t *config_cam,
size_t num_cams,
bool use_port_layout)
{

View File

@@ -7,17 +7,17 @@
#define CAMHOOK_CONFIG_CAM_MAX 2
struct camhook_config_cam {
typedef struct camhook_config_cam {
bool disable_emu;
size_t num_devices;
int port_layout;
char device_id[CAMHOOK_CONFIG_CAM_MAX][MAX_PATH];
bool disable_camera[CAMHOOK_CONFIG_CAM_MAX];
};
} camhook_config_cam_t;
void camhook_config_cam_get(
const bt_core_config_t *config,
struct camhook_config_cam *config_cam,
camhook_config_cam_t *config_cam,
size_t num_cams,
bool use_port_layout);

View File

@@ -8,7 +8,7 @@
void d3d9exhook_config_gfx_get(
const bt_core_config_t *config,
struct d3d9exhook_config_gfx *config_gfx)
d3d9exhook_config_gfx_t *config_gfx)
{
bt_core_config_s32_get(config, "gfx/device/adapter", &config_gfx->device_adapter);
bt_core_config_s32_get(config, "gfx/device/forced_refresh_rate", &config_gfx->forced_refresh_rate);

View File

@@ -9,7 +9,7 @@
* Note: forced_refresh_rate sets the monitor's refresh rate
* (it does not limit FPS or anything)
*/
struct d3d9exhook_config_gfx {
typedef struct d3d9exhook_config_gfx {
bool framed;
bool windowed;
bool confined;
@@ -25,10 +25,10 @@ struct d3d9exhook_config_gfx {
int32_t width;
int32_t height;
} force_screen_res;
};
} d3d9exhook_config_gfx_t;
void d3d9exhook_config_gfx_get(
const bt_core_config_t *config,
struct d3d9exhook_config_gfx *config_gfx);
d3d9exhook_config_gfx_t *config_gfx);
#endif

View File

@@ -1,7 +1,7 @@
#include "hooklib/config-adapter.h"
void hooklib_config_adapter_get(
const bt_core_config_t *config, struct hooklib_config_adapter *config_adapter)
const bt_core_config_t *config, hooklib_config_adapter_t *config_adapter)
{
bt_core_config_str_get(config, "adapter/override_ip", config_adapter->override_ip, sizeof(config_adapter->override_ip));
}

View File

@@ -3,12 +3,12 @@
#include "iface-core/config.h"
struct hooklib_config_adapter {
typedef struct hooklib_config_adapter {
// this is larger on purpose, in case ppl enter the wrong stuff here
char override_ip[32];
};
} hooklib_config_adapter_t;
void hooklib_config_adapter_get(
const bt_core_config_t *config, struct hooklib_config_adapter *config_adapter);
const bt_core_config_t *config, hooklib_config_adapter_t *config_adapter);
#endif

View File

@@ -7,6 +7,7 @@ ldflags_sdvxhook2 := \
-lmf \
-lmfplat \
-lole32 \
-lws2_32 \
deplibs_sdvxhook2 := \
avs \
@@ -22,17 +23,18 @@ libs_sdvxhook2 := \
d3d9exhook \
hook \
hooklib \
cconfig \
util \
iface \
iface-io \
iface-core \
module \
security \
src_sdvxhook2 := \
acio.c \
bi2a.c \
dllmain.c \
config-io.c \
dllmain.c \
nvapi.c \
power.c \
sdvxhook2.c \

View File

@@ -1,180 +1,16 @@
#include "cconfig/cconfig-util.h"
#include "iface-core/log.h"
#include "core/config-ext.h"
#include "sdvxhook2/config-io.h"
#define SDVXHOOK2_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \
"io.disable_card_reader_emu"
#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_DISABLE_POWER_HOOKS_KEY "io.disable_power_hooks"
#define SDVXHOOK2_CONFIG_IO_DISABLE_NVAPI_HOOKS_KEY "io.disable_nvapi_hooks"
#define SDVXHOOK2_CONFIG_IO_COM1_CARD_READER_KEY "io.com1_card_reader"
#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
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POWER_HOOKS_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE false
#define SDVXHOOK2_CONFIG_IO_DEFAULT_COM1_CARD_READER_VALUE false
void sdvxhook2_config_io_init(struct cconfig *config)
{
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE,
"Disable card reader emulation and enable usage of real card reader "
"hardware on COM2");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE,
"Disable BIO2 emulation and enable usage of real BIO2 hardware");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE,
"Disables the poll limiter, warning very high CPU usage may arise");
cconfig_util_set_bool(
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)");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_POWER_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POWER_HOOKS_VALUE,
"Disables the built in power control hooks, allowing game to modify "
"system power settings");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_NVAPI_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE,
"Disables the built in NVAPI control hooks, allowing game to modify "
"system monitor settings");
cconfig_util_set_bool(
config,
SDVXHOOK2_CONFIG_IO_COM1_CARD_READER_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_COM1_CARD_READER_VALUE,
"Emulates the card reader on COM1 instead of COM2");
}
void sdvxhook2_config_io_get(
struct sdvxhook2_config_io *config_io, struct cconfig *config)
const bt_core_config_t *config, sdvxhook2_config_io_t *config_out)
{
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
&config_io->disable_card_reader_emu,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
&config_io->disable_bio2_emu,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
&config_io->disable_poll_limiter,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY,
&config_io->force_headphones,
SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
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);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_POWER_HOOKS_KEY,
&config_io->disable_power_hooks,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POWER_HOOKS_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_POWER_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POWER_HOOKS_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_DISABLE_NVAPI_HOOKS_KEY,
&config_io->disable_nvapi_hooks,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_DISABLE_NVAPI_HOOKS_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE);
}
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CONFIG_IO_COM1_CARD_READER_KEY,
&config_io->com1_card_reader,
SDVXHOOK2_CONFIG_IO_DEFAULT_COM1_CARD_READER_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CONFIG_IO_COM1_CARD_READER_KEY,
SDVXHOOK2_CONFIG_IO_DEFAULT_COM1_CARD_READER_VALUE);
}
}
bt_core_config_ext_bool_get(config, "io/disable_card_reader_emu", &config_out->disable_card_reader_emu);
bt_core_config_ext_bool_get(config, "io/disable_bio2_emu", &config_out->disable_bio2_emu);
bt_core_config_ext_bool_get(config, "io/disable_poll_limiter", &config_out->disable_poll_limiter);
bt_core_config_ext_bool_get(config, "io/force_headphones", &config_out->force_headphones);
bt_core_config_ext_bool_get(config, "io/disable_file_hooks", &config_out->disable_file_hooks);
bt_core_config_ext_bool_get(config, "io/disable_power_hooks", &config_out->disable_power_hooks);
bt_core_config_ext_bool_get(config, "io/disable_nvapi_hooks", &config_out->disable_nvapi_hooks);
bt_core_config_ext_bool_get(config, "io/com1_card_reader", &config_out->com1_card_reader);
}

View File

@@ -1,11 +1,11 @@
#ifndef SDVXHOOK2_CONFIG_IO_H
#define SDVXHOOK2_CONFIG_IO_H
#include <windows.h>
#include <stdbool.h>
#include "cconfig/cconfig.h"
#include "api/core/config.h"
struct sdvxhook2_config_io {
typedef struct sdvxhook2_config_io {
bool disable_card_reader_emu;
bool disable_bio2_emu;
bool disable_poll_limiter;
@@ -14,11 +14,9 @@ struct sdvxhook2_config_io {
bool disable_power_hooks;
bool disable_nvapi_hooks;
bool com1_card_reader;
};
void sdvxhook2_config_io_init(struct cconfig *config);
} sdvxhook2_config_io_t;
void sdvxhook2_config_io_get(
struct sdvxhook2_config_io *config_io, struct cconfig *config);
const bt_core_config_t *config, sdvxhook2_config_io_t *config_out);
#endif

View File

@@ -1,263 +1,6 @@
#include <windows.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "cconfig/cconfig-hook.h"
#include "hooklib/acp.h"
#include "hooklib/adapter.h"
#include "hooklib/config-adapter.h"
#include "hooklib/memfile.h"
#include "hooklib/rs232.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "iface-io/eam.h"
#include "iface-io/sdvx.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "bio2emu/emu.h"
#include "sdvxhook2/acio.h"
#include "sdvxhook2/bi2a.h"
#include "sdvxhook2/config-io.h"
#include "sdvxhook2/nvapi.h"
#include "sdvxhook2/power.h"
#include "camhook/cam.h"
#include "camhook/config-cam.h"
#include "d3d9exhook/config-gfx.h"
#include "d3d9exhook/d3d9ex.h"
#include "sdk/module/core/log.h"
#include "sdk/module/core/thread.h"
#include "sdk/module/hook.h"
#include "util/str.h"
#define SDVXHOOK2_INFO_HEADER \
"sdvxhook for VW" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n"
#define SDVXHOOK2_CMD_USAGE \
"Usage: launcher.exe -K sdvxhook2.dll <soundvoltex.dll> [options...]"
struct sdvxhook2_config_io config_io;
struct camhook_config_cam config_cam;
struct d3d9exhook_config_gfx config_gfx;
struct hooklib_config_adapter config_adapter;
static module_io_t *_sdvxhook2_module_io_sdvx;
static module_io_t *_sdvxhook2_module_io_eam;
static struct bio2emu_port bio2_emu = {
.port = "COM4",
.wport = L"\\\\.\\COM4",
.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 void _sdvxhook2_io_sdvx_init(module_io_t **module)
{
bt_io_sdvx_api_t api;
module_io_ext_load_and_init(
"sdvxio.dll", "bt_module_io_sdvx_api_get", module);
module_io_api_get(*module, &api);
bt_io_sdvx_api_set(&api);
}
static void _sdvxhook2_io_eam_init(module_io_t **module)
{
bt_io_eam_api_t api;
module_io_ext_load_and_init(
"eamio.dll", "bt_module_io_eam_api_get", module);
module_io_api_get(*module, &api);
bt_io_eam_api_set(&api);
}
static bool
_sdvxhook2_main_init(HMODULE game_module, const bt_core_config_t *config_)
{
struct cconfig *config;
log_info("--- Begin sdvxhook dll_entry_init ---");
// TODO sidcode back-propagation required like jubeat, figure out
char *sidcode = NULL;
log_assert(sidcode);
config = cconfig_init();
sdvxhook2_config_io_init(config);
d3d9exhook_config_gfx_init(config);
camhook_config_cam_init(config, 1, false);
hooklib_config_adapter_init(config);
if (!cconfig_hook_config_init(
config,
SDVXHOOK2_INFO_HEADER "\n" SDVXHOOK2_CMD_USAGE,
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
cconfig_finit(config);
exit(EXIT_FAILURE);
}
sdvxhook2_config_io_get(&config_io, config);
camhook_config_cam_get(&config_cam, config, 1, false);
d3d9exhook_config_gfx_get(&config_gfx, config);
hooklib_config_adapter_get(&config_adapter, config);
cconfig_finit(config);
log_info(SDVXHOOK2_INFO_HEADER);
log_info("Initializing sdvxhook2...");
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
d3d9ex_configure(&config_gfx);
/* Start up sdvxio.DLL */
if (!config_io.disable_bio2_emu) {
log_info("Starting sdvx IO backend");
_sdvxhook2_io_sdvx_init(&_sdvxhook2_module_io_sdvx);
if (!bt_io_sdvx_init()) {
log_fatal("Initializing sdvx IO backend failed");
}
}
/* Start up EAMIO.DLL */
if (!config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
_sdvxhook2_io_eam_init(&_sdvxhook2_module_io_eam);
if (!bt_io_eam_init()) {
log_fatal("Initializing card reader backend failed");
}
}
/* iohooks are okay, even if emu is diabled since the fake handlers won't be
* used */
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);
}
if (!config_io.disable_card_reader_emu) {
ac_io_port_init(config_io.com1_card_reader);
}
if (!config_cam.disable_emu) {
camhook_init(&config_cam);
}
if (!config_io.disable_power_hooks) {
powerhook_init();
}
if (!config_io.disable_nvapi_hooks) {
nvapihook_init();
}
adapter_hook_override(config_adapter.override_ip);
log_info("--- End sdvxhook dll_entry_init ---");
return true;
}
static void _sdvxhook2_main_fini()
{
if (!config_cam.disable_emu) {
camhook_fini();
}
if (!config_io.disable_card_reader_emu) {
log_misc("Shutting down card reader backend");
bt_io_eam_fini();
bt_io_eam_api_clear();
module_io_free(&_sdvxhook2_module_io_eam);
}
if (!config_io.disable_bio2_emu) {
log_misc("Shutting down sdvx IO backend");
bt_io_sdvx_fini();
bt_io_sdvx_api_clear();
module_io_free(&_sdvxhook2_module_io_sdvx);
}
if (!config_io.disable_file_hooks) {
memfile_hook_fini();
}
}
void bt_module_core_log_api_set(const bt_core_log_api_t *api)
{
bt_core_log_api_set(api);
}
void bt_module_core_thread_api_set(const bt_core_thread_api_t *api)
{
bt_core_thread_api_set(api);
}
void bt_module_hook_api_get(bt_hook_api_t *api)
{
api->version = 1;
api->v1.main_init = _sdvxhook2_main_init;
api->v1.main_fini = _sdvxhook2_main_fini;
}
/**
* Hook library SDVX5+
*/
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
return TRUE;
}
}

View File

@@ -0,0 +1,233 @@
#define LOG_MODULE "sdvxhook2"
#include <windows.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "hooklib/acp.h"
#include "hooklib/adapter.h"
#include "hooklib/config-adapter.h"
#include "hooklib/memfile.h"
#include "hooklib/rs232.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "iface-io/eam.h"
#include "iface-io/sdvx.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "bio2emu/emu.h"
#include "sdvxhook2/acio.h"
#include "sdvxhook2/bi2a.h"
#include "sdvxhook2/config-io.h"
#include "sdvxhook2/nvapi.h"
#include "sdvxhook2/power.h"
#include "camhook/cam.h"
#include "camhook/config-cam.h"
#include "d3d9exhook/config-gfx.h"
#include "d3d9exhook/d3d9ex.h"
#include "sdk/module/core/log.h"
#include "sdk/module/core/thread.h"
#include "sdk/module/hook.h"
#include "util/str.h"
static sdvxhook2_config_io_t _sdvxhook2_config_io;
static camhook_config_cam_t _sdvxhook2_config_cam;
static d3d9exhook_config_gfx_t _sdvxhook2_config_gfx;
static hooklib_config_adapter_t _sdvxhook2_config_adapter;
static module_io_t *_sdvxhook2_module_io_sdvx;
static module_io_t *_sdvxhook2_module_io_eam;
static struct bio2emu_port bio2_emu = {
.port = "COM4",
.wport = L"\\\\.\\COM4",
.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 void _sdvxhook2_io_sdvx_init(module_io_t **module)
{
bt_io_sdvx_api_t api;
module_io_ext_load_and_init(
"sdvxio.dll", "bt_module_io_sdvx_api_get", module);
module_io_api_get(*module, &api);
bt_io_sdvx_api_set(&api);
}
static void _sdvxhook2_io_eam_init(module_io_t **module)
{
bt_io_eam_api_t api;
module_io_ext_load_and_init(
"eamio.dll", "bt_module_io_eam_api_get", module);
module_io_api_get(*module, &api);
bt_io_eam_api_set(&api);
}
static bool
_sdvxhook2_main_init(HMODULE game_module, const bt_core_config_t *config)
{
log_info("sdvxhook for Vivid Wave and EXCEED GEAR");
log_info("build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV));
// TODO sidcode back-propagation required like jubeat, figure out, crash for now
char *sidcode = NULL;
log_fatal("DEV TODO: sidcode back-propagation missing");
log_assert(sidcode);
sdvxhook2_config_io_get(config, &_sdvxhook2_config_io);
camhook_config_cam_get(config, &_sdvxhook2_config_cam, 1, false);
d3d9exhook_config_gfx_get(config, &_sdvxhook2_config_gfx);
hooklib_config_adapter_get(config, &_sdvxhook2_config_adapter);
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
d3d9ex_configure(&_sdvxhook2_config_gfx);
/* Start up sdvxio.DLL */
if (!_sdvxhook2_config_io.disable_bio2_emu) {
log_info("Starting sdvx IO backend");
_sdvxhook2_io_sdvx_init(&_sdvxhook2_module_io_sdvx);
if (!bt_io_sdvx_init()) {
log_fatal("Initializing sdvx IO backend failed");
}
}
/* Start up EAMIO.DLL */
if (!_sdvxhook2_config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
_sdvxhook2_io_eam_init(&_sdvxhook2_module_io_eam);
if (!bt_io_eam_init()) {
log_fatal("Initializing card reader backend failed");
}
}
/* iohooks are okay, even if emu is diabled since the fake handlers won't be
* used */
iohook_push_handler(ac_io_port_dispatch_irp);
iohook_push_handler(bio2emu_port_dispatch_irp);
if (!_sdvxhook2_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 (!_sdvxhook2_config_io.disable_bio2_emu) {
bio2emu_init();
bio2_emu_bi2a_init(
&bio2_emu,
_sdvxhook2_config_io.disable_poll_limiter,
_sdvxhook2_config_io.force_headphones);
}
if (!_sdvxhook2_config_io.disable_card_reader_emu) {
ac_io_port_init(_sdvxhook2_config_io.com1_card_reader);
}
if (!_sdvxhook2_config_cam.disable_emu) {
camhook_init(&_sdvxhook2_config_cam);
}
if (!_sdvxhook2_config_io.disable_power_hooks) {
powerhook_init();
}
if (!_sdvxhook2_config_io.disable_nvapi_hooks) {
nvapihook_init();
}
adapter_hook_override(_sdvxhook2_config_adapter.override_ip);
log_info("--- End sdvxhook dll_entry_init ---");
return true;
}
static void _sdvxhook2_main_fini()
{
if (!_sdvxhook2_config_cam.disable_emu) {
camhook_fini();
}
if (!_sdvxhook2_config_io.disable_card_reader_emu) {
log_misc("Shutting down card reader backend");
bt_io_eam_fini();
bt_io_eam_api_clear();
module_io_free(&_sdvxhook2_module_io_eam);
}
if (!_sdvxhook2_config_io.disable_bio2_emu) {
log_misc("Shutting down sdvx IO backend");
bt_io_sdvx_fini();
bt_io_sdvx_api_clear();
module_io_free(&_sdvxhook2_module_io_sdvx);
}
if (!_sdvxhook2_config_io.disable_file_hooks) {
memfile_hook_fini();
}
}
void bt_module_core_config_api_set(const bt_core_config_api_t *api)
{
bt_core_config_api_set(api);
}
void bt_module_core_log_api_set(const bt_core_log_api_t *api)
{
bt_core_log_api_set(api);
}
void bt_module_core_thread_api_set(const bt_core_thread_api_t *api)
{
bt_core_thread_api_set(api);
}
void bt_module_hook_api_get(bt_hook_api_t *api)
{
api->version = 1;
api->v1.main_init = _sdvxhook2_main_init;
api->v1.main_fini = _sdvxhook2_main_fini;
}

View File

@@ -4,6 +4,7 @@ EXPORTS
DllMain@12 @1 NONAME
; Bemanitools 6 API
bt_module_core_config_api_set
bt_module_core_log_api_set
bt_module_core_thread_api_set
bt_module_hook_api_get

View File

@@ -0,0 +1,9 @@
#ifndef SDVXHOOK2_H
#define SDVXHOOK2_H
#include "sdk/module/core/config.h"
#include "sdk/module/core/log.h"
#include "sdk/module/core/thread.h"
#include "sdk/module/hook.h"
#endif