refact(sdvxhook2-cn): Use new config api

Summary:

Test Plan:
Summary:

Test Plan:
Summary:

Test Plan:
Summary:

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

View File

@@ -667,7 +667,6 @@ $(zipdir)/sdvx-05-cn.zip: \
build/bin/indep-64/sdvxio.dll \
dist/sdvx5/config.bat \
dist/sdvx5/gamestart-cn.bat \
dist/sdvx5/sdvxhook2-cn.conf \
dist/sdvx5/launcher-cn.xml \
dist/shared/ea3-ident.xml \
dist/shared/ea3-license.xml \
@@ -683,6 +682,7 @@ $(zipdir)/sdvx-hwio-x86.zip: \
build/bin/indep-32/sdvxio-bio2.dll \
build/bin/indep-32/vigem-sdvxio.exe \
dist/sdvx/eamio-icca.xml \
dist/sdvx/sdvxio-bio2.xml \
| $(zipdir)/
$(V)echo ... $@
$(V)zip -j $@ $^
@@ -694,6 +694,7 @@ $(zipdir)/sdvx-hwio-x64.zip: \
build/bin/indep-64/sdvxio-bio2.dll \
build/bin/indep-64/vigem-sdvxio.exe \
dist/sdvx/eamio-icca.xml \
dist/sdvx/sdvxio-bio2.xml \
| $(zipdir)/
$(V)echo ... $@
$(V)zip -j $@ $^

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-cn.xml --config %BEMANITOOLS_DIR%\sdvxhook2-cn.conf %*
%BEMANITOOLS_DIR%\launcher.exe^
%BEMANITOOLS_DIR%\launcher-cn.xml^
%*

View File

@@ -58,15 +58,63 @@
<eamuse>
<config kind="file">bemanitools/ea3-service.xml</config>
</eamuse>
<hook>
<hook_dlls>
<dll __type="str">sdvxhook2-cn.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-cn.dll</path>
<config kind="inline">
<hook>
<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">720</width>
<!-- Windowed height, -1 for default size -->
<height __type="s32">1280</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>
<cn>
<!-- Disable IO emulation and enable usage of real KFCA hardware -->
<disable_io_emu __type="bool">0</disable_io_emu>
<!-- Path to unis version file under the prop.s folder -->
<unis_path __type="str">prop/unis.xml</unis_path>
</cn>
</hook>
</config>
</hook>
</hooks>
<debug>
<remote_debugger __type="bool">0</remote_debugger>
<log_property_configs __type="bool">0</log_property_configs>

View File

@@ -1,24 +0,0 @@
# Disable IO emulation and enable usage of real KFCA hardware
io.disable_io_emu=false
# Path to unis version file under the prop.s folder
cn.unis_path=prop/unis.xml
# Run the game in a framed window (requires windowed option)
gfx.framed=true
# Run the game windowed
gfx.windowed=false
# Windowed width, -1 for default size
gfx.window_width=720
# Windowed height, -1 for default size
gfx.window_height=1280
# Disables the camera emulation
cam.disable_emu=false
# Override camera device ID detection (copy from device manager, do not escape)
cam.device_id1=

View File

@@ -22,7 +22,6 @@ libs_sdvxhook2-cn := \
d3d9exhook \
hook \
hooklib \
cconfig \
util \
iface \
iface-io \
@@ -32,7 +31,8 @@ libs_sdvxhook2-cn := \
src_sdvxhook2-cn := \
acio.c \
kfca.c \
dllmain.c \
config-cn.c \
dllmain.c \
kfca.c \
sdvxhook2-cn.c \
unis-version.c \

View File

@@ -1,55 +1,10 @@
#include "cconfig/cconfig-util.h"
#include "iface-core/log.h"
#include "core/config-ext.h"
#include "sdvxhook2-cn/config-cn.h"
#define SDVXHOOK2_CN_CONFIG_DISABLE_IO_EMU_KEY "io.disable_io_emu"
#define SDVXHOOK2_CN_CONFIG_UNIS_PATH_KEY "cn.unis_path"
#define SDVXHOOK2_CN_CONFIG_DEFAULT_DISABLE_IO_EMU_VALUE false
#define SDVXHOOK2_CN_CONFIG_DEFAULT_UNIS_PATH_VALUE "prop/unis.xml"
void sdvxhook2_cn_config_init(struct cconfig *config)
{
cconfig_util_set_bool(
config,
SDVXHOOK2_CN_CONFIG_DISABLE_IO_EMU_KEY,
SDVXHOOK2_CN_CONFIG_DEFAULT_DISABLE_IO_EMU_VALUE,
"Disable IO emulation and enable usage of real KFCA hardware");
cconfig_util_set_str(
config,
SDVXHOOK2_CN_CONFIG_UNIS_PATH_KEY,
SDVXHOOK2_CN_CONFIG_DEFAULT_UNIS_PATH_VALUE,
"Path to unis version file under the prop.s folder");
}
void sdvxhook2_cn_config_get(
struct sdvxhook2_cn_config *cn_config, struct cconfig *config)
const bt_core_config_t *config, sdvxhook2_cn_config_t *config_out)
{
if (!cconfig_util_get_bool(
config,
SDVXHOOK2_CN_CONFIG_DISABLE_IO_EMU_KEY,
&cn_config->disable_io_emu,
SDVXHOOK2_CN_CONFIG_DEFAULT_DISABLE_IO_EMU_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
SDVXHOOK2_CN_CONFIG_DISABLE_IO_EMU_KEY,
SDVXHOOK2_CN_CONFIG_DEFAULT_DISABLE_IO_EMU_VALUE);
}
if (!cconfig_util_get_str(
config,
SDVXHOOK2_CN_CONFIG_UNIS_PATH_KEY,
cn_config->unis_path,
sizeof(cn_config->unis_path),
SDVXHOOK2_CN_CONFIG_DEFAULT_UNIS_PATH_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
SDVXHOOK2_CN_CONFIG_UNIS_PATH_KEY,
SDVXHOOK2_CN_CONFIG_DEFAULT_UNIS_PATH_VALUE);
}
bt_core_config_ext_bool_get(config, "io/disable_io_emu", &config_out->disable_io_emu);
bt_core_config_ext_str_get(config, "cn/unis_path", config_out->unis_path, sizeof(config_out->unis_path));
}

View File

@@ -1,18 +1,16 @@
#ifndef SDVXHOOK2_CN_CONFIG_H
#define SDVXHOOK2_CN_CONFIG_H
#include <windows.h>
#include <stdbool.h>
#include "cconfig/cconfig.h"
#include "api/core/config.h"
struct sdvxhook2_cn_config {
typedef struct sdvxhook2_cn_config {
bool disable_io_emu;
char unis_path[256];
};
void sdvxhook2_cn_config_init(struct cconfig *config);
} sdvxhook2_cn_config_t;
void sdvxhook2_cn_config_get(
struct sdvxhook2_cn_config *cn_config, struct cconfig *config);
const bt_core_config_t *config, sdvxhook2_cn_config_t *config_out);
#endif

View File

@@ -1,170 +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/rs232.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "iface-io/sdvx.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "sdvxhook2-cn/acio.h"
#include "sdvxhook2-cn/config-cn.h"
#include "sdvxhook2-cn/unis-version.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_CN_INFO_HEADER \
"sdvxhook for VW CN" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n"
#define SDVXHOOK2_CN_CMD_USAGE \
"Usage: launcher.exe -K sdvxhook2.dll <soundvoltex.dll> [options...]"
struct sdvxhook2_cn_config config_cn;
struct camhook_config_cam config_cam;
struct d3d9exhook_config_gfx config_gfx;
static module_io_t *_sdvxhook2_cn_module_io_sdvx;
static void _sdvxhook2_cn_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 bool
_sdvxhook2_cn_main_init(HMODULE game_module, const bt_core_config_t *config_)
{
struct cconfig *config;
log_info("--- Begin sdvxhook dll_entry_init ---");
config = cconfig_init();
sdvxhook2_cn_config_init(config);
d3d9exhook_config_gfx_init(config);
camhook_config_cam_init(config, 1, false);
if (!cconfig_hook_config_init(
config,
SDVXHOOK2_CN_INFO_HEADER "\n" SDVXHOOK2_CN_CMD_USAGE,
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
cconfig_finit(config);
exit(EXIT_FAILURE);
}
sdvxhook2_cn_config_get(&config_cn, config);
camhook_config_cam_get(&config_cam, config, 1, false);
d3d9exhook_config_gfx_get(&config_gfx, config);
cconfig_finit(config);
log_info(SDVXHOOK2_CN_INFO_HEADER);
log_info("Initializing sdvxhook2-cn...");
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
d3d9ex_configure(&config_gfx);
/* Start up sdvxio.DLL */
if (!config_cn.disable_io_emu) {
log_info("Starting sdvx IO backend");
_sdvxhook2_cn_io_sdvx_init(&_sdvxhook2_cn_module_io_sdvx);
if (!bt_io_sdvx_init()) {
log_fatal("Initializing sdvx IO 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);
rs232_hook_init();
rs232_hook_limit_hooks();
if (!config_cn.disable_io_emu) {
ac_io_port_init();
}
// camera hooks
if (!config_cam.disable_emu) {
camhook_init(&config_cam);
}
unis_version_hook_init(config_cn.unis_path);
log_info("--- End sdvxhook dll_entry_init ---");
return true;
}
static void _sdvxhook2_cn_main_fini()
{
if (!config_cam.disable_emu) {
camhook_fini();
}
if (!config_cn.disable_io_emu) {
log_misc("Shutting down sdvx IO backend");
bt_io_sdvx_fini();
bt_io_sdvx_api_clear();
module_io_free(&_sdvxhook2_cn_module_io_sdvx);
}
}
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_cn_main_init;
api->v1.main_fini = _sdvxhook2_cn_main_fini;
}
/**
* Hook library SDVX5 CN
*/
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
return TRUE;
}
}

View File

@@ -0,0 +1,138 @@
#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/rs232.h"
#include "iface-core/config.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "iface-io/sdvx.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "sdvxhook2-cn/acio.h"
#include "sdvxhook2-cn/config-cn.h"
#include "sdvxhook2-cn/unis-version.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_cn_config_t _sdvxhook2_cn_config;
static camhook_config_cam_t _sdvxhook2_cn_config_cam;
static d3d9exhook_config_gfx_t _sdvxhook2_cn_config_gfx;
static module_io_t *_sdvxhook2_cn_module_io_sdvx;
static void _sdvxhook2_cn_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 bool
_sdvxhook2_cn_main_init(HMODULE game_module, const bt_core_config_t *config)
{
log_info("sdvxhook for Vivid Wave CN");
log_info("build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV));
sdvxhook2_cn_config_get(config, &_sdvxhook2_cn_config);
camhook_config_cam_get(config, &_sdvxhook2_cn_config_cam, 1, false);
d3d9exhook_config_gfx_get(config, &_sdvxhook2_cn_config_gfx);
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
d3d9ex_configure(&_sdvxhook2_cn_config_gfx);
/* Start up sdvxio.DLL */
if (!_sdvxhook2_cn_config.disable_io_emu) {
log_info("Starting sdvx IO backend");
_sdvxhook2_cn_io_sdvx_init(&_sdvxhook2_cn_module_io_sdvx);
if (!bt_io_sdvx_init()) {
log_fatal("Initializing sdvx IO 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);
rs232_hook_init();
rs232_hook_limit_hooks();
if (!_sdvxhook2_cn_config.disable_io_emu) {
ac_io_port_init();
}
// camera hooks
if (!_sdvxhook2_cn_config_cam.disable_emu) {
camhook_init(&_sdvxhook2_cn_config_cam);
}
unis_version_hook_init(_sdvxhook2_cn_config.unis_path);
return true;
}
static void _sdvxhook2_cn_main_fini()
{
if (!_sdvxhook2_cn_config_cam.disable_emu) {
camhook_fini();
}
if (!_sdvxhook2_cn_config.disable_io_emu) {
log_misc("Shutting down sdvx IO backend");
bt_io_sdvx_fini();
bt_io_sdvx_api_clear();
module_io_free(&_sdvxhook2_cn_module_io_sdvx);
}
}
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_cn_main_init;
api->v1.main_fini = _sdvxhook2_cn_main_fini;
}

View File

@@ -2,3 +2,9 @@ LIBRARY sdvxhook2-cn
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_CN_H
#define SDVXHOOK2_CN_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

View File

@@ -175,8 +175,6 @@ _sdvxhook2_main_init(HMODULE game_module, const bt_core_config_t *config)
adapter_hook_override(_sdvxhook2_config_adapter.override_ip);
log_info("--- End sdvxhook dll_entry_init ---");
return true;
}