From 5531726fc299b9428deccd5a24045d5808b4ed30 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 15 Aug 2024 13:24:43 +0200 Subject: [PATCH] feat(iidxhook1): Use sdk-hook and support config api Summary: Test Plan: Read any configuration values through bemanitools's configuration API abstraction. This still had to be hooked up when a hook dll is being loaded. The current implementation relies on an environment variable providing the path to the original inject configuration file, then it extracts the relevant hook configuration section for the currently loaded hook library. This adheres to the limitations of not having any other entry points than DllMain for a hook library (as of now). --- dist/iidx/gamestart-09.bat | 4 +- dist/iidx/inject-09.xml | 104 ++++++++ src/main/iidxhook-util/config-eamuse.c | 43 ++++ src/main/iidxhook-util/config-eamuse.h | 12 +- src/main/iidxhook-util/config-ezusb.c | 26 ++ src/main/iidxhook-util/config-ezusb.h | 10 +- src/main/iidxhook-util/config-gfx.c | 94 ++++++- src/main/iidxhook-util/config-gfx.h | 19 +- src/main/iidxhook-util/config-io.c | 10 + src/main/iidxhook-util/config-io.h | 10 +- src/main/iidxhook-util/config-misc.c | 11 + src/main/iidxhook-util/config-misc.h | 10 +- src/main/iidxhook-util/config-sec.c | 33 +++ src/main/iidxhook-util/config-sec.h | 10 +- src/main/iidxhook1/Module.mk | 4 +- src/main/iidxhook1/config-iidxhook1.c | 36 --- src/main/iidxhook1/config-iidxhook1.h | 15 -- src/main/iidxhook1/dllmain.c | 334 +++---------------------- src/main/iidxhook1/iidxhook1.c | 265 ++++++++++++++++++++ src/main/iidxhook1/iidxhook1.def | 7 +- src/main/iidxhook1/iidxhook1.h | 14 ++ src/main/inject/main.c | 3 + 22 files changed, 698 insertions(+), 376 deletions(-) create mode 100644 dist/iidx/inject-09.xml delete mode 100644 src/main/iidxhook1/config-iidxhook1.c delete mode 100644 src/main/iidxhook1/config-iidxhook1.h create mode 100644 src/main/iidxhook1/iidxhook1.c create mode 100644 src/main/iidxhook1/iidxhook1.h diff --git a/dist/iidx/gamestart-09.bat b/dist/iidx/gamestart-09.bat index 3f12785..bc1eecb 100755 --- a/dist/iidx/gamestart-09.bat +++ b/dist/iidx/gamestart-09.bat @@ -45,8 +45,6 @@ set PATH=^ cd /d %REVISION_DIR% %BEMANITOOLS_DIR%\inject.exe^ - %BEMANITOOLS_DIR%\iidxhook1.dll^ - %REVISION_DIR%\bm2dx.exe^ - -D^ + %BEMANITOOLS_DIR%\inject-09.xml^ --config %BEMANITOOLS_DIR%\iidxhook-09.conf^ %* \ No newline at end of file diff --git a/dist/iidx/inject-09.xml b/dist/iidx/inject-09.xml new file mode 100644 index 0000000..05c1b8d --- /dev/null +++ b/dist/iidx/inject-09.xml @@ -0,0 +1,104 @@ + + + 1 + + + bm2dx.exe + + inject + + + + 1 + iidxhook1.dll + + + + + C02 + + localhost:80 + 0101020304050607086F + 0101020304050607086F + + + + + -1 + + -1 + + 0.0 + + + 1 + 1 + + 0 + 0 + + + + 0 + 0 + + none + + + + -1.000000 + + 1 + + + + C02 + + + GEC02 + 0:0:0 + + GEC02JAA + + + 0 + + + + + .\ + 1 + 1 + + + + + + + 1 + misc + 8192 + + + 0 + 64 + discard_new + + + 1 + 1 + + + 1 + inject.log + 0 + 0 + 1 + + + + + 1 + 0 + + \ No newline at end of file diff --git a/src/main/iidxhook-util/config-eamuse.c b/src/main/iidxhook-util/config-eamuse.c index 239d875..e506b96 100644 --- a/src/main/iidxhook-util/config-eamuse.c +++ b/src/main/iidxhook-util/config-eamuse.c @@ -2,12 +2,16 @@ #include "cconfig/cconfig-util.h" +#include "core/config-ext.h" + #include "iidxhook-util/config-eamuse.h" #include "iface-core/log.h" #include "security/mcode.h" +#include "util/str.h" + #define IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY "eamuse.card_type" #define IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" #define IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid" @@ -167,3 +171,42 @@ void iidxhook_util_config_eamuse_get( free(tmp2); } } + +static void _iidxhook_util_config_eamuse_verify( + const iidxhook_util_config_eamuse_t *config) +{ + char *tmp; + + if (!str_eq(config->card_type, "C02") && + !str_eq(config->card_type, "D01") && + !str_eq(config->card_type, "E11") && + !str_eq(config->card_type, "ECO")) { + log_fatal("Invalid card_type in eamuse configuration: %s", config->card_type); + } + + if (!security_id_verify(&config->pcbid)) { + tmp = security_id_to_str(&config->pcbid, false); + log_fatal("Invalid pcbid in eamuse configuration: %s", tmp); + free(tmp); + } + + if (!security_id_verify(&config->eamid)) { + tmp = security_id_to_str(&config->eamid, false); + log_fatal("Invalid eamid in eamuse configuration: %s", tmp); + free(tmp); + } +} + +void iidxhook_util_config_eamuse_get2( + const bt_core_config_t *config, + iidxhook_util_config_eamuse_t *config_eamuse) +{ + bt_core_config_ext_str_get(config, "eamuse/card_type", config_eamuse->card_type, sizeof(config_eamuse->card_type)); + bt_core_config_ext_net_addr_get(config, "eamuse/server", &config_eamuse->server); + bt_core_config_ext_bin_get(config, "eamuse/pcbid", + (uint8_t *) &config_eamuse->pcbid, sizeof(config_eamuse->pcbid)); + bt_core_config_ext_bin_get(config, "eamuse/eamid", + (uint8_t *) &config_eamuse->eamid, sizeof(config_eamuse->eamid)); + + _iidxhook_util_config_eamuse_verify(config_eamuse); +} diff --git a/src/main/iidxhook-util/config-eamuse.h b/src/main/iidxhook-util/config-eamuse.h index b6b1d40..c20dd25 100644 --- a/src/main/iidxhook-util/config-eamuse.h +++ b/src/main/iidxhook-util/config-eamuse.h @@ -3,20 +3,26 @@ #include "cconfig/cconfig.h" +#include "iface-core/config.h" + #include "security/id.h" #include "util/net.h" -struct iidxhook_util_config_eamuse { +typedef struct iidxhook_util_config_eamuse { char card_type[4]; struct net_addr server; struct security_id pcbid; struct security_id eamid; -}; +} iidxhook_util_config_eamuse_t; void iidxhook_util_config_eamuse_init(struct cconfig *config); void iidxhook_util_config_eamuse_get( - struct iidxhook_util_config_eamuse *config_eamuse, struct cconfig *config); + iidxhook_util_config_eamuse_t *config_eamuse, struct cconfig *config); + +void iidxhook_util_config_eamuse_get2( + const bt_core_config_t *config, + iidxhook_util_config_eamuse_t *config_eamuse); #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c index e4568e4..08db60a 100644 --- a/src/main/iidxhook-util/config-ezusb.c +++ b/src/main/iidxhook-util/config-ezusb.c @@ -3,11 +3,14 @@ #include "cconfig/cconfig-util.h" +#include "core/config-ext.h" + #include "iidxhook-util/config-ezusb.h" #include "iface-core/log.h" #include "util/mem.h" +#include "util/str.h" #define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY \ "ezusb.api_call_monitoring" @@ -16,6 +19,21 @@ #define IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE false #define IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE 0 +static void _iidxhook_util_config_ezusb_board_type_get(const bt_core_config_t *config, int32_t *board_type) +{ + char tmp[8]; + + bt_core_config_ext_str_get(config, "ezusb/type", tmp, sizeof(tmp)); + + if (str_eq(tmp, "C02")) { + *board_type = 0; + } else if (str_eq(tmp, "D01")) { + *board_type = 1; + } else { + log_fatal("Invalid ezusb board type in configuration: %s", tmp); + } +} + void iidxhook_util_config_ezusb_init(struct cconfig *config) { cconfig_util_set_bool( @@ -69,3 +87,11 @@ void iidxhook_util_config_ezusb_get( config_ezusb->io_board_type = 0; } } + +void iidxhook_util_config_ezusb_get2( + const bt_core_config_t *config, + iidxhook_util_config_ezusb_t *config_ezusb) +{ + _iidxhook_util_config_ezusb_board_type_get(config, &config_ezusb->io_board_type); + bt_core_config_ext_bool_get(config, "ezusb/debug/api_call_monitoring", &config_ezusb->api_call_monitoring); +} \ No newline at end of file diff --git a/src/main/iidxhook-util/config-ezusb.h b/src/main/iidxhook-util/config-ezusb.h index 54d69fb..f4fdf2f 100644 --- a/src/main/iidxhook-util/config-ezusb.h +++ b/src/main/iidxhook-util/config-ezusb.h @@ -3,16 +3,20 @@ #include "cconfig/cconfig.h" -#include "security/mcode.h" +#include "iface-core/config.h" -struct iidxhook_util_config_ezusb { +typedef struct iidxhook_util_config_ezusb { bool api_call_monitoring; int32_t io_board_type; -}; +} iidxhook_util_config_ezusb_t; void iidxhook_util_config_ezusb_init(struct cconfig *config); void iidxhook_util_config_ezusb_get( struct iidxhook_util_config_ezusb *config_ezusb, struct cconfig *config); +void iidxhook_util_config_ezusb_get2( + const bt_core_config_t *config, + iidxhook_util_config_ezusb_t *config_ezusb); + #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-gfx.c b/src/main/iidxhook-util/config-gfx.c index 039778c..977252e 100644 --- a/src/main/iidxhook-util/config-gfx.c +++ b/src/main/iidxhook-util/config-gfx.c @@ -1,3 +1,4 @@ +#include #include #include "cconfig/cconfig-util.h" @@ -6,6 +7,8 @@ #include "iidxhook-util/config-gfx.h" +#include "util/str.h" + #define IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY "gfx.bgvideo_uv_fix" #define IIDXHOOK_CONFIG_GFX_FRAMED_KEY "gfx.framed" #define IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY "gfx.frame_rate_limit" @@ -270,7 +273,7 @@ void iidxhook_config_gfx_get( if (!cconfig_util_get_int( config, IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, - &config_gfx->window_width, + (int32_t*) &config_gfx->window_width, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE)) { log_warning( "Invalid value for key '%s' specified, fallback " @@ -282,7 +285,7 @@ void iidxhook_config_gfx_get( if (!cconfig_util_get_int( config, IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, - &config_gfx->window_height, + (int32_t*) &config_gfx->window_height, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE)) { log_warning( "Invalid value for key '%s' specified, fallback " @@ -357,7 +360,7 @@ void iidxhook_config_gfx_get( if (!cconfig_util_get_int( config, IIDXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY, - &config_gfx->forced_refresh_rate, + (int32_t*) &config_gfx->forced_refresh_rate, IIDXHOOK_CONFIG_GFX_DEFAULT_FORCED_RR_VALUE)) { log_warning( "Invalid value for key '%s' specified, fallback " @@ -369,7 +372,7 @@ void iidxhook_config_gfx_get( if (!cconfig_util_get_int( config, IIDXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY, - &config_gfx->device_adapter, + (int32_t*) &config_gfx->device_adapter, IIDXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE)) { log_warning( "Invalid value for key '%s' specified, fallback " @@ -390,3 +393,86 @@ void iidxhook_config_gfx_get( IIDXHOOK_CONFIG_GFX_DEFAULT_DIAGONAL_TEARING_FIX_VALUE); } } + +static void _iidxhook_util_config_gfx_verify(const iidxhook_config_gfx_t *config) +{ + if (config->frame_rate_limit < 0.0 || config->frame_rate_limit > 500.0) { + log_fatal("Invalid frame_rate_limit value in gfx configuration: %f", config->frame_rate_limit); + } + + if (!(fabs(config->monitor_check - (-1.0)) < 0.001 || + fabs(config->monitor_check) < 0.001 || + config->monitor_check < 500.0)) { + log_fatal("Invalid monitor_check value in gfx configuration: %f", config->monitor_check); + } + + if (config->window_width > 10000 || config->window_width < 0) { + log_fatal("Invalid window_width value in gfx configuration: %d", config->window_width); + } + + if (config->window_height > 10000 || config->window_height < 0) { + log_fatal("Invalid window_height value in gfx configuration: %d", config->window_height); + } + + if (config->scale_back_buffer_width > 10000) { + log_fatal("Invalid scale_back_buffer_width value in gfx configuration: %d", config->scale_back_buffer_width); + } + + if (config->scale_back_buffer_height > 10000) { + log_fatal("Invalid scale_back_buffer_height value in gfx configuration: %d", config->scale_back_buffer_height); + } + + if (config->forced_refresh_rate < -1 || config->forced_refresh_rate > 500) { + log_fatal("Invalid forced_refresh_rate value in gfx configuration: %d", config->forced_refresh_rate); + } + + if (config->device_adapter < -1 || config->device_adapter > 32) { + log_fatal("Invalid device_adapter value in gfx configuration: %d", config->device_adapter); + } +} + +static void _iidxhook_util_config_gfx_back_buffer_scale_filter_get( + const bt_core_config_t *config, + enum iidxhook_util_d3d9_back_buffer_scale_filter *filter) +{ + char tmp[16]; + + bt_core_config_str_get(config, "gfx/back_buffer_scale/filter", tmp, sizeof(tmp)); + + if (str_eq(tmp, "none")) { + *filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; + } else if (str_eq(tmp, "linear")) { + *filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR; + } else if (str_eq(tmp, "point")) { + *filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_POINT; + } else { + log_fatal("Invalid value for back_buffer_scale/filter in gfx config: %s", tmp); + } +} + +void iidxhook_util_config_gfx_get2( + const bt_core_config_t *config, + iidxhook_config_gfx_t *config_gfx) +{ + bt_core_config_s8_get(config, "gfx/device/adapter", &config_gfx->device_adapter); + bt_core_config_s16_get(config, "gfx/device/forced_refresh_rate", &config_gfx->forced_refresh_rate); + bt_core_config_float_get(config, "gfx/device/frame_rate_limit", &config_gfx->frame_rate_limit); + bt_core_config_u16_get(config, "gfx/device/pci_id_vid", &config_gfx->pci_id_vid); + bt_core_config_u16_get(config, "gfx/device/pci_id_pid", &config_gfx->pci_id_pid); + + bt_core_config_bool_get(config, "gfx/window/windowed", &config_gfx->windowed); + bt_core_config_bool_get(config, "gfx/window/framed", &config_gfx->framed); + bt_core_config_u16_get(config, "gfx/window/width", &config_gfx->window_width); + bt_core_config_u16_get(config, "gfx/window/height", &config_gfx->window_height); + + bt_core_config_u16_get(config, "gfx/back_buffer_scale/width", &config_gfx->scale_back_buffer_width); + bt_core_config_u16_get(config, "gfx/back_buffer_scale/height", &config_gfx->scale_back_buffer_height); + _iidxhook_util_config_gfx_back_buffer_scale_filter_get(config, &config_gfx->scale_back_buffer_filter); + + bt_core_config_bool_get(config, "gfx/game/bgvideo_uv_fix", &config_gfx->bgvideo_uv_fix); + bt_core_config_float_get(config, "gfx/game/monitor_check", &config_gfx->monitor_check); + bt_core_config_bool_get(config, "gfx/game/diagonal_tearing_fix", &config_gfx->diagonal_tearing_fix); + bt_core_config_bool_get(config, "gfx/game/happy_sky_ms_bg_fix", &config_gfx->happy_sky_ms_bg_fix); + + _iidxhook_util_config_gfx_verify(config_gfx); +} \ No newline at end of file diff --git a/src/main/iidxhook-util/config-gfx.h b/src/main/iidxhook-util/config-gfx.h index 6a73e62..da95aa9 100644 --- a/src/main/iidxhook-util/config-gfx.h +++ b/src/main/iidxhook-util/config-gfx.h @@ -3,10 +3,12 @@ #include "cconfig/cconfig.h" +#include "iface-core/config.h" + #include "iidxhook-util/d3d9.h" // see struct iidxhook_util_d3d9_config for more info -struct iidxhook_config_gfx { +typedef struct iidxhook_config_gfx { bool bgvideo_uv_fix; bool framed; float frame_rate_limit; @@ -14,19 +16,24 @@ struct iidxhook_config_gfx { uint16_t pci_id_vid; uint16_t pci_id_pid; bool windowed; - int32_t window_width; - int32_t window_height; + uint16_t window_width; + uint16_t window_height; uint16_t scale_back_buffer_width; uint16_t scale_back_buffer_height; enum iidxhook_util_d3d9_back_buffer_scale_filter scale_back_buffer_filter; - int32_t forced_refresh_rate; - int32_t device_adapter; + int16_t forced_refresh_rate; + int8_t device_adapter; bool diagonal_tearing_fix; -}; + bool happy_sky_ms_bg_fix; +} iidxhook_config_gfx_t; void iidxhook_config_gfx_init(struct cconfig *config); void iidxhook_config_gfx_get( struct iidxhook_config_gfx *config_gfx, struct cconfig *config); +void iidxhook_util_config_gfx_get2( + const bt_core_config_t *config, + iidxhook_config_gfx_t *config_gfx); + #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-io.c b/src/main/iidxhook-util/config-io.c index d8f8543..2898e9c 100644 --- a/src/main/iidxhook-util/config-io.c +++ b/src/main/iidxhook-util/config-io.c @@ -1,5 +1,7 @@ #include "cconfig/cconfig-util.h" +#include "core/config-ext.h" + #include "iface-core/log.h" #include "iidxhook-util/config-io.h" @@ -55,3 +57,11 @@ void iidxhook_config_io_get( IIDXHOOK_UTIL_CONFIG_IO_DEFAULT_DISABLE_IO_EMU_VALUE); } } + +void iidxhook_util_config_io_get2( + const bt_core_config_t *config, + iidxhook_config_io_t *config_io) +{ + bt_core_config_ext_bool_get(config, "io/disable_card_reader_emu", &config_io->disable_card_reader_emu); + bt_core_config_ext_bool_get(config, "io/disable_io_emu", &config_io->disable_io_emu); +} \ No newline at end of file diff --git a/src/main/iidxhook-util/config-io.h b/src/main/iidxhook-util/config-io.h index 0f63750..d6c187e 100644 --- a/src/main/iidxhook-util/config-io.h +++ b/src/main/iidxhook-util/config-io.h @@ -5,14 +5,20 @@ #include "cconfig/cconfig.h" -struct iidxhook_config_io { +#include "iface-core/config.h" + +typedef struct iidxhook_config_io { bool disable_card_reader_emu; bool disable_io_emu; -}; +} iidxhook_config_io_t; void iidxhook_config_io_init(struct cconfig *config); void iidxhook_config_io_get( struct iidxhook_config_io *config_io, struct cconfig *config); +void iidxhook_util_config_io_get2( + const bt_core_config_t *config, + iidxhook_config_io_t *config_io); + #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c index 308912a..caa6881 100644 --- a/src/main/iidxhook-util/config-misc.c +++ b/src/main/iidxhook-util/config-misc.c @@ -1,5 +1,7 @@ #include "cconfig/cconfig-util.h" +#include "core/config-ext.h" + #include "iface-core/log.h" #include "iidxhook-util/config-misc.h" @@ -74,3 +76,12 @@ void iidxhook_config_misc_get( IIDXHOOK_CONFIG_MISC_DEFAULT_SETTINGS_PATH_STUB_VALUE); } } + +void iidxhook_util_config_misc_get2( + const bt_core_config_t *config, + iidxhook_config_misc_t *config_misc) +{ + bt_core_config_ext_bool_get(config, "misc/disable_clock_set", &config_misc->disable_clock_set); + bt_core_config_ext_bool_get(config, "misc/rteffect_stub", &config_misc->rteffect_stub); + bt_core_config_ext_str_get(config, "misc/settings_path", config_misc->settings_path, sizeof(config_misc->settings_path)); +} diff --git a/src/main/iidxhook-util/config-misc.h b/src/main/iidxhook-util/config-misc.h index 743e83d..fd87fd3 100644 --- a/src/main/iidxhook-util/config-misc.h +++ b/src/main/iidxhook-util/config-misc.h @@ -5,15 +5,21 @@ #include "cconfig/cconfig.h" -struct iidxhook_config_misc { +#include "iface-core/config.h" + +typedef struct iidxhook_config_misc { bool disable_clock_set; bool rteffect_stub; char settings_path[MAX_PATH]; -}; +} iidxhook_config_misc_t; void iidxhook_config_misc_init(struct cconfig *config); void iidxhook_config_misc_get( struct iidxhook_config_misc *config_misc, struct cconfig *config); +void iidxhook_util_config_misc_get2( + const bt_core_config_t *config, + iidxhook_config_misc_t *config_misc); + #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-sec.c b/src/main/iidxhook-util/config-sec.c index 80aa27a..ece6003 100644 --- a/src/main/iidxhook-util/config-sec.c +++ b/src/main/iidxhook-util/config-sec.c @@ -3,6 +3,8 @@ #include "cconfig/cconfig-util.h" +#include "core/config-ext.h" + #include "iface-core/log.h" #include "iidxhook-util/config-sec.h" @@ -213,3 +215,34 @@ void iidxhook_config_sec_get( free(tmp_str); } + +static void _iidxhook_util_config_sec_security_mcode_get(const bt_core_config_t *config, const char *path, struct security_mcode *mcode) +{ + char tmp[sizeof(struct security_mcode) + 1]; + + bt_core_config_ext_str_get(config, path, tmp, sizeof(tmp)); + + if (!security_mcode_parse(tmp, mcode)) { + log_fatal("Parsing mcode failed: %s", tmp); + } +} + +static void _iidxhook_util_config_sec_boot_seeds_get(const bt_core_config_t *config, uint32_t *boot_seeds) +{ + char tmp[8]; + + bt_core_config_ext_str_get(config, "ezusb/security/boot/seed", tmp, sizeof(tmp)); + + if (!iidxhook_config_boot_seeds_parse(tmp, boot_seeds)) { + log_fatal("Parsing security boot seeds failed: %s", tmp); + } +} + +void iidxhook_util_config_sec_get2( + const bt_core_config_t *config, + iidxhook_config_sec_t *config_sec) +{ + _iidxhook_util_config_sec_security_mcode_get(config, "ezusb/security/boot/version", &config_sec->boot_version); + _iidxhook_util_config_sec_boot_seeds_get(config, config_sec->boot_seeds); + _iidxhook_util_config_sec_security_mcode_get(config, "ezusb/security/plug_black_mcode", &config_sec->black_plug_mcode); +} diff --git a/src/main/iidxhook-util/config-sec.h b/src/main/iidxhook-util/config-sec.h index 314940d..addc061 100644 --- a/src/main/iidxhook-util/config-sec.h +++ b/src/main/iidxhook-util/config-sec.h @@ -3,17 +3,23 @@ #include "cconfig/cconfig.h" +#include "iface-core/config.h" + #include "security/mcode.h" -struct iidxhook_config_sec { +typedef struct iidxhook_config_sec { struct security_mcode boot_version; uint32_t boot_seeds[3]; struct security_mcode black_plug_mcode; -}; +} iidxhook_config_sec_t; void iidxhook_config_sec_init(struct cconfig *config); void iidxhook_config_sec_get( struct iidxhook_config_sec *config_sec, struct cconfig *config); +void iidxhook_util_config_sec_get2( + const bt_core_config_t *config, + iidxhook_config_sec_t *config_sec); + #endif \ No newline at end of file diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk index 05e5e73..6ff7544 100644 --- a/src/main/iidxhook1/Module.mk +++ b/src/main/iidxhook1/Module.mk @@ -4,8 +4,10 @@ ldflags_iidxhook1 := \ -lws2_32 \ -liphlpapi \ -lpsapi \ + -lshlwapi \ libs_iidxhook1 := \ + sdk-hook \ core \ iidxhook-util \ ezusb-emu \ @@ -25,7 +27,7 @@ libs_iidxhook1 := \ mxml \ src_iidxhook1 := \ - config-iidxhook1.c \ dllmain.c \ + iidxhook1.c \ ezusb-mon.c \ log-ezusb.c \ diff --git a/src/main/iidxhook1/config-iidxhook1.c b/src/main/iidxhook1/config-iidxhook1.c deleted file mode 100644 index 6df2f42..0000000 --- a/src/main/iidxhook1/config-iidxhook1.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" - -#include "iidxhook1/config-iidxhook1.h" - -#define IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY "misc.happy_sky_ms_bg_fix" - -#define IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE false - -void iidxhook_config_iidxhook1_init(struct cconfig *config) -{ - cconfig_util_set_bool( - config, - IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, - IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE, - "Fix broken 3D background on Happy Sky's music select (if " - "appearing " - "completely white)"); -} - -void iidxhook_config_iidxhook1_get( - struct iidxhook_config_iidxhook1 *config_iidxhook1, struct cconfig *config) -{ - if (!cconfig_util_get_bool( - config, - IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, - &config_iidxhook1->happy_sky_ms_bg_fix, - IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, - IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE); - } -} \ No newline at end of file diff --git a/src/main/iidxhook1/config-iidxhook1.h b/src/main/iidxhook1/config-iidxhook1.h deleted file mode 100644 index bec1e48..0000000 --- a/src/main/iidxhook1/config-iidxhook1.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef IIDXHOOK_CONFIG_IIDXHOOK1_H -#define IIDXHOOK_CONFIG_IIDXHOOK1_H - -#include "cconfig/cconfig.h" - -struct iidxhook_config_iidxhook1 { - bool happy_sky_ms_bg_fix; -}; - -void iidxhook_config_iidxhook1_init(struct cconfig *config); - -void iidxhook_config_iidxhook1_get( - struct iidxhook_config_iidxhook1 *config_iidxhook1, struct cconfig *config); - -#endif \ No newline at end of file diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index 74995ed..5b0742b 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -1,332 +1,70 @@ #include -#include -#include -#include - -#include "cconfig/cconfig-hook.h" - -#include "core/boot.h" -#include "core/log-bt-ext.h" -#include "core/log-bt.h" -#include "core/log-sink-debug.h" -#include "core/thread-crt.h" - -#include "ezusb-emu/desc.h" -#include "ezusb-emu/device.h" -#include "ezusb-emu/node-security-plug.h" - -#include "ezusb-iidx-emu/msg.h" -#include "ezusb-iidx-emu/node-serial.h" -#include "ezusb-iidx-emu/nodes.h" - -#include "hook/d3d9.h" -#include "hook/iohook.h" #include "hook/table.h" -#include "hooklib/acp.h" -#include "hooklib/adapter.h" -#include "hooklib/setupapi.h" +#include "iidxhook1/iidxhook1.h" -#include "iface-core/log.h" -#include "iface-core/thread.h" - -#include "iface-io/eam.h" -#include "iface-io/iidx.h" - -#include "iidxhook-util/chart-patch.h" -#include "iidxhook-util/clock.h" -#include "iidxhook-util/config-eamuse.h" -#include "iidxhook-util/config-ezusb.h" -#include "iidxhook-util/config-gfx.h" -#include "iidxhook-util/config-misc.h" -#include "iidxhook-util/config-sec.h" -#include "iidxhook-util/d3d9.h" -#include "iidxhook-util/eamuse.h" -#include "iidxhook-util/effector.h" -#include "iidxhook-util/settings.h" - -#include "iidxhook1/config-iidxhook1.h" -#include "iidxhook1/ezusb-mon.h" -#include "iidxhook1/log-ezusb.h" - -#include "module/io-ext.h" -#include "module/io.h" +#include "main/sdk-hook/dllentry.h" #include "util/defs.h" -#include "util/proc.h" -#define IIDXHOOK1_INFO_HEADER \ - "iidxhook for 9th Style, 10th Style, RED and HAPPY SKY" \ - ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) -#define IIDXHOOK1_CMD_USAGE \ - "Usage: inject.exe iidxhook1.dll [options...]" +static HANDLE STDCALL _iidxhook1_dllmain_my_OpenProcess(DWORD, BOOL, DWORD); +static HANDLE(STDCALL *_iidxhook1_dllmain_real_OpenProcess)(DWORD, BOOL, DWORD); -static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { - iidxhook_util_d3d9_irp_handler, -}; +static bool _iidxhook1_dllmain_openprocess_call_check; -static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); -static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); - -static bool iidxhook_init_check; -static module_io_t *iidxhook_module_io_iidx; -static module_io_t *iidxhook_module_io_eam; - -static const struct hook_symbol init_hook_syms[] = { +static const struct hook_symbol _iidxhook1_dllmain_hook_syms[] = { { .name = "OpenProcess", - .patch = my_OpenProcess, - .link = (void **) &real_OpenProcess, + .patch = _iidxhook1_dllmain_my_OpenProcess, + .link = (void **) &_iidxhook1_dllmain_real_OpenProcess, }, }; -static void _iidxhook1_log_init() -{ - core_log_bt_ext_init_with_debug(); - // TODO change log level support - core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC); -} - -static void _iidxhook1_io_iidx_init(module_io_t **module) -{ - bt_io_iidx_api_t api; - - module_io_ext_load_and_init( - "iidxio.dll", "bt_module_io_iidx_api_get", module); - module_io_api_get(*module, &api); - bt_io_iidx_api_set(&api); -} - -static void _iidxhook1_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 void iidxhook1_setup_d3d9_hooks( - const struct iidxhook_config_gfx *config_gfx, - const struct iidxhook_config_iidxhook1 *config_iidxhook1) -{ - struct iidxhook_util_d3d9_config d3d9_config; - - if (!proc_is_module_loaded("d3d9.dll")) { - log_fatal( - "d3d8 hook module deprecated, using d3d9 hook modules requires " - "d3d8to9 to work! Could not detect loaded d3d9.dll"); - } - - iidxhook_util_d3d9_init_config(&d3d9_config); - - d3d9_config.windowed = config_gfx->windowed; - d3d9_config.framed = config_gfx->framed; - d3d9_config.override_window_width = config_gfx->window_width; - d3d9_config.override_window_height = config_gfx->window_height; - d3d9_config.framerate_limit = config_gfx->frame_rate_limit; - d3d9_config.iidx12_fix_song_select_bg = - config_iidxhook1->happy_sky_ms_bg_fix; - d3d9_config.iidx09_to_17_fix_uvs_bg_videos = config_gfx->bgvideo_uv_fix; - d3d9_config.scale_back_buffer_width = config_gfx->scale_back_buffer_width; - d3d9_config.scale_back_buffer_height = config_gfx->scale_back_buffer_height; - d3d9_config.scale_back_buffer_filter = config_gfx->scale_back_buffer_filter; - d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; - d3d9_config.device_adapter = config_gfx->device_adapter; - - if (config_gfx->monitor_check == 0) { - log_info("Auto monitor check enabled"); - - d3d9_config.iidx09_to_19_monitor_check_cb = - iidxhook_util_chart_patch_set_refresh_rate; - iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); - } else if (config_gfx->monitor_check > 0) { - log_info( - "Manual monitor check, resulting refresh rate: %f", - config_gfx->monitor_check); - - iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); - iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); - } - - iidxhook_util_d3d9_configure(&d3d9_config); - - hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers)); -} - -/** - * This seems to be a good entry point to intercept - * before the game calls anything important - */ static HANDLE STDCALL -my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) +_iidxhook1_dllmain_my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { - struct cconfig *config; - - struct iidxhook_util_config_ezusb config_ezusb; - struct iidxhook_util_config_eamuse config_eamuse; - struct iidxhook_config_gfx config_gfx; - struct iidxhook_config_iidxhook1 config_iidxhook1; - struct iidxhook_config_misc config_misc; - struct iidxhook_config_sec config_sec; - - if (iidxhook_init_check) { - goto skip; + if (_iidxhook1_dllmain_openprocess_call_check) { + return _iidxhook1_dllmain_real_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); } - iidxhook_init_check = true; + _iidxhook1_dllmain_openprocess_call_check = true; - log_info("-------------------------------------------------------------"); - log_info("--------------- Begin iidxhook my_OpenProcess ---------------"); - log_info("-------------------------------------------------------------"); + bt_hook_dllentry_main_init(); - config = cconfig_init(); - - iidxhook_util_config_ezusb_init(config); - iidxhook_util_config_eamuse_init(config); - iidxhook_config_gfx_init(config); - iidxhook_config_iidxhook1_init(config); - iidxhook_config_misc_init(config); - iidxhook_config_sec_init(config); - - if (!cconfig_hook_config_init( - config, - IIDXHOOK1_INFO_HEADER "\n" IIDXHOOK1_CMD_USAGE, - CCONFIG_CMD_USAGE_OUT_DBG)) { - cconfig_finit(config); - exit(EXIT_FAILURE); - } - - iidxhook_util_config_ezusb_get(&config_ezusb, config); - iidxhook_util_config_eamuse_get(&config_eamuse, config); - iidxhook_config_gfx_get(&config_gfx, config); - iidxhook_config_iidxhook1_get(&config_iidxhook1, config); - iidxhook_config_misc_get(&config_misc, config); - iidxhook_config_sec_get(&config_sec, config); - - cconfig_finit(config); - - log_info(IIDXHOOK1_INFO_HEADER); - log_info("Initializing iidxhook..."); - - /* Round plug security */ - - ezusb_iidx_emu_node_security_plug_set_boot_version( - &config_sec.boot_version); - ezusb_iidx_emu_node_security_plug_set_boot_seeds(config_sec.boot_seeds); - ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( - &config_sec.black_plug_mcode); - ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); - - /* Magnetic card reader (9th to HS) */ - - ezusb_iidx_emu_node_serial_set_card_attributes( - 0, true, config_eamuse.card_type); - - /* eAmusement server IP */ - - eamuse_set_addr(&config_eamuse.server); - eamuse_check_connection(); - - /* Patch rteffect.dll calls */ - - // TODO this doesn't work, because it's too late to apply this here - // this needs to be launched before bm2dx.exe even loads the rteffect.dll - // and runs DllMain of it (see also how this is done with the proxy - // ezusb.dll) - if (config_misc.rteffect_stub) { - effector_hook_init(); - } - - /* Settings paths */ - - if (strlen(config_misc.settings_path) > 0) { - settings_hook_set_path(config_misc.settings_path); - } - - /* Direct3D and USER32 hooks */ - - iidxhook1_setup_d3d9_hooks(&config_gfx, &config_iidxhook1); - - /* Disable operator menu clock setting system clock time */ - - if (config_misc.disable_clock_set) { - iidxhook_util_clock_hook_init(); - } - - /* Start up IIDXIO.DLL */ - - log_info("Starting IIDX IO backend"); - - _iidxhook1_io_iidx_init(&iidxhook_module_io_iidx); - - if (!bt_io_iidx_init()) { - log_fatal("Initializing IIDX IO backend failed"); - } - - /* Start up EAMIO.DLL */ - - log_misc("Initializing card reader backend"); - - _iidxhook1_io_eam_init(&iidxhook_module_io_eam); - - if (!bt_io_eam_init()) { - log_fatal("Initializing card reader backend failed"); - } - - /* Set up IO emulation hooks _after_ IO API setup to allow - API implementations with real IO devices */ - iohook_push_handler(ezusb_emu_device_dispatch_irp); - iohook_push_handler(iidxhook_util_chart_patch_dispatch_irp); - iohook_push_handler(settings_hook_dispatch_irp); - - hook_setupapi_init(&ezusb_emu_desc_device.setupapi); - ezusb_emu_device_hook_init( - ezusb_iidx_emu_msg_init(config_ezusb.io_board_type)); - - if (config_ezusb.api_call_monitoring) { - ezusb_log_hook_init(); - ezusb_mon_hook_init(); - } - - log_info("-------------------------------------------------------------"); - log_info("---------------- End iidxhook my_OpenProcess ----------------"); - log_info("-------------------------------------------------------------"); - -skip: - return real_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); + return _iidxhook1_dllmain_real_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); } -/** - * Hook library for 9th to Happy Sky - */ +// TODO find another call right before main exits to hook cleanup and stuff with +// bt_hook_dllentry_main_fini() + BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - core_boot_dll("iidxhook1"); + bt_hook_dllentry_init( + mod, + "iidxhook1", + bt_module_core_config_api_set, + bt_module_core_log_api_set, + bt_module_core_thread_api_set, + bt_module_hook_api_get); - _iidxhook1_log_init(); - - // Use bemanitools core APIs - core_log_bt_core_api_set(); - core_thread_crt_core_api_set(); - - /* Bootstrap hook for further init tasks (see above) */ + _iidxhook1_dllmain_openprocess_call_check = false; hook_table_apply( - NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); + NULL, "kernel32.dll", _iidxhook1_dllmain_hook_syms, lengthof(_iidxhook1_dllmain_hook_syms)); - /* Actual hooks for game specific stuff */ + } else if (reason == DLL_PROCESS_DETACH) { + // https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain#remarks + if (ctx == NULL) { + hook_table_revert(NULL, "kernel32.dll", _iidxhook1_dllmain_hook_syms, lengthof(_iidxhook1_dllmain_hook_syms)); - acp_hook_init(); - adapter_hook_init(); - eamuse_hook_init(); - settings_hook_init(); + // Hacky to have this here, should be close/right after application main exits, see TODO above + bt_hook_dllentry_main_fini(); + + bt_hook_dllentry_fini(); + } } return TRUE; -} +} \ No newline at end of file diff --git a/src/main/iidxhook1/iidxhook1.c b/src/main/iidxhook1/iidxhook1.c new file mode 100644 index 0000000..d61c708 --- /dev/null +++ b/src/main/iidxhook1/iidxhook1.c @@ -0,0 +1,265 @@ +#include + +#include +#include +#include + +#include "ezusb-emu/desc.h" +#include "ezusb-emu/device.h" +#include "ezusb-emu/node-security-plug.h" + +#include "ezusb-iidx-emu/msg.h" +#include "ezusb-iidx-emu/node-serial.h" +#include "ezusb-iidx-emu/nodes.h" + +#include "hook/d3d9.h" +#include "hook/iohook.h" + +#include "hooklib/acp.h" +#include "hooklib/adapter.h" +#include "hooklib/setupapi.h" + +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/iidx.h" + +#include "iidxhook-util/chart-patch.h" +#include "iidxhook-util/clock.h" +#include "iidxhook-util/config-eamuse.h" +#include "iidxhook-util/config-ezusb.h" +#include "iidxhook-util/config-gfx.h" +#include "iidxhook-util/config-misc.h" +#include "iidxhook-util/config-sec.h" +#include "iidxhook-util/d3d9.h" +#include "iidxhook-util/eamuse.h" +#include "iidxhook-util/effector.h" +#include "iidxhook-util/settings.h" + +#include "iidxhook1/ezusb-mon.h" +#include "iidxhook1/log-ezusb.h" + +#include "module/io-ext.h" +#include "module/io.h" + +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/hook.h" + +#include "util/defs.h" +#include "util/proc.h" + +static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { + iidxhook_util_d3d9_irp_handler, +}; + +static module_io_t *iidxhook_module_io_iidx; +static module_io_t *iidxhook_module_io_eam; + +static void _iidxhook1_io_iidx_init(module_io_t **module) +{ + bt_io_iidx_api_t api; + + module_io_ext_load_and_init( + "iidxio.dll", "bt_module_io_iidx_api_get", module); + module_io_api_get(*module, &api); + bt_io_iidx_api_set(&api); +} + +static void _iidxhook1_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 void iidxhook1_setup_d3d9_hooks( + const struct iidxhook_config_gfx *config_gfx) +{ + struct iidxhook_util_d3d9_config d3d9_config; + + if (!proc_is_module_loaded("d3d9.dll")) { + log_fatal( + "d3d8 hook module deprecated, using d3d9 hook modules requires " + "d3d8to9 to work! Could not detect loaded d3d9.dll"); + } + + iidxhook_util_d3d9_init_config(&d3d9_config); + + d3d9_config.windowed = config_gfx->windowed; + d3d9_config.framed = config_gfx->framed; + d3d9_config.override_window_width = config_gfx->window_width; + d3d9_config.override_window_height = config_gfx->window_height; + d3d9_config.framerate_limit = config_gfx->frame_rate_limit; + d3d9_config.iidx12_fix_song_select_bg = + config_gfx->happy_sky_ms_bg_fix; + d3d9_config.iidx09_to_17_fix_uvs_bg_videos = config_gfx->bgvideo_uv_fix; + d3d9_config.scale_back_buffer_width = config_gfx->scale_back_buffer_width; + d3d9_config.scale_back_buffer_height = config_gfx->scale_back_buffer_height; + d3d9_config.scale_back_buffer_filter = config_gfx->scale_back_buffer_filter; + d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; + d3d9_config.device_adapter = config_gfx->device_adapter; + + if (config_gfx->monitor_check == 0) { + log_info("Auto monitor check enabled"); + + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + } else if (config_gfx->monitor_check > 0) { + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); + + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); + } + + iidxhook_util_d3d9_configure(&d3d9_config); + + hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers)); +} + +static bool +_iidxhook1_main_init(HMODULE game_module, const bt_core_config_t *config) +{ + iidxhook_util_config_ezusb_t config_ezusb; + iidxhook_util_config_eamuse_t config_eamuse; + iidxhook_config_gfx_t config_gfx; + iidxhook_config_misc_t config_misc; + iidxhook_config_sec_t config_sec; + + log_info("iidxhook for 9th Style, 10th Style, RED and HAPPY SKY"); + log_info("build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)); + + iidxhook_util_config_ezusb_get2(config, &config_ezusb); + iidxhook_util_config_eamuse_get2(config, &config_eamuse); + iidxhook_util_config_gfx_get2(config, &config_gfx); + iidxhook_util_config_misc_get2(config, &config_misc); + iidxhook_util_config_sec_get2(config, &config_sec); + + acp_hook_init(); + adapter_hook_init(); + eamuse_hook_init(); + settings_hook_init(); + + /* Round plug security */ + + ezusb_iidx_emu_node_security_plug_set_boot_version( + &config_sec.boot_version); + ezusb_iidx_emu_node_security_plug_set_boot_seeds(config_sec.boot_seeds); + ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( + &config_sec.black_plug_mcode); + ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); + + /* Magnetic card reader (9th to HS) */ + + ezusb_iidx_emu_node_serial_set_card_attributes( + 0, true, config_eamuse.card_type); + + /* eAmusement server IP */ + + eamuse_set_addr(&config_eamuse.server); + eamuse_check_connection(); + + /* Patch rteffect.dll calls */ + + // TODO this doesn't work, because it's too late to apply this here + // this needs to be launched before bm2dx.exe even loads the rteffect.dll + // and runs DllMain of it (see also how this is done with the proxy + // ezusb.dll) + if (config_misc.rteffect_stub) { + effector_hook_init(); + } + + /* Settings paths */ + + if (strlen(config_misc.settings_path) > 0) { + settings_hook_set_path(config_misc.settings_path); + } + + /* Direct3D and USER32 hooks */ + + iidxhook1_setup_d3d9_hooks(&config_gfx); + + /* Disable operator menu clock setting system clock time */ + + if (config_misc.disable_clock_set) { + iidxhook_util_clock_hook_init(); + } + + /* Start up IIDXIO.DLL */ + + log_info("Starting IIDX IO backend"); + + _iidxhook1_io_iidx_init(&iidxhook_module_io_iidx); + + if (!bt_io_iidx_init()) { + log_fatal("Initializing IIDX IO backend failed"); + } + + /* Start up EAMIO.DLL */ + + log_misc("Initializing card reader backend"); + + _iidxhook1_io_eam_init(&iidxhook_module_io_eam); + + if (!bt_io_eam_init()) { + log_fatal("Initializing card reader backend failed"); + } + + /* Set up IO emulation hooks _after_ IO API setup to allow + API implementations with real IO devices */ + iohook_push_handler(ezusb_emu_device_dispatch_irp); + iohook_push_handler(iidxhook_util_chart_patch_dispatch_irp); + iohook_push_handler(settings_hook_dispatch_irp); + + hook_setupapi_init(&ezusb_emu_desc_device.setupapi); + ezusb_emu_device_hook_init( + ezusb_iidx_emu_msg_init(config_ezusb.io_board_type)); + + if (config_ezusb.api_call_monitoring) { + ezusb_log_hook_init(); + ezusb_mon_hook_init(); + } + + log_info("-------------------------------------------------------------"); + log_info("---------------- End iidxhook my_OpenProcess ----------------"); + log_info("-------------------------------------------------------------"); + + return true; +} +static void _iidxhook1_main_fini() +{ + // TODO cleanup +} + +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 = _iidxhook1_main_init; + api->v1.main_fini = _iidxhook1_main_fini; +} diff --git a/src/main/iidxhook1/iidxhook1.def b/src/main/iidxhook1/iidxhook1.def index eb7b5ff..b844b19 100644 --- a/src/main/iidxhook1/iidxhook1.def +++ b/src/main/iidxhook1/iidxhook1.def @@ -2,4 +2,9 @@ LIBRARY iidxhook1 EXPORTS DllMain@12 @1 NONAME - \ No newline at end of file + + ; 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 \ No newline at end of file diff --git a/src/main/iidxhook1/iidxhook1.h b/src/main/iidxhook1/iidxhook1.h new file mode 100644 index 0000000..3bf4378 --- /dev/null +++ b/src/main/iidxhook1/iidxhook1.h @@ -0,0 +1,14 @@ +#ifndef IIDXHOOK1_H +#define IIDXHOOK1_H + +#include "sdk/module/core/config.h" +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/hook.h" + +void bt_module_core_config_api_set(const bt_core_config_api_t *api); +void bt_module_core_log_api_set(const bt_core_log_api_t *api); +void bt_module_core_thread_api_set(const bt_core_thread_api_t *api); +void bt_module_hook_api_get(bt_hook_api_t *api); + +#endif \ No newline at end of file diff --git a/src/main/inject/main.c b/src/main/inject/main.c index 6bf3b65..1d28069 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -31,6 +31,9 @@ int main(int argc, char **argv) config_path = argv[1]; + // Duct-tape to allow access to config path and load config in hook dlls + SetEnvironmentVariable("INJECT_CONFIG_PATH", config_path); + // TODO make configurable // core_property_trace_log_enable(true); // core_property_node_trace_log_enable(true);