From 8a68e563e002c418d0522f5986e111cd54383ad3 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 17 Aug 2024 12:51:00 +0200 Subject: [PATCH] feat(popnhook1): Use sdk-hook and new config api Summary: Test Plan: --- Module.mk | 8 +- dist/popn/gamestart-15.bat | 47 +++++- dist/popn/gamestart-16.bat | 47 +++++- dist/popn/gamestart-17.bat | 47 +++++- dist/popn/gamestart-18.bat | 47 +++++- dist/popn/inject-15.xml | 68 ++++++++ dist/popn/inject-16.xml | 68 ++++++++ dist/popn/inject-17.xml | 68 ++++++++ dist/popn/inject-18.xml | 68 ++++++++ dist/popn/popnhook-15.conf | 23 --- dist/popn/popnhook-16.conf | 23 --- dist/popn/popnhook-17.conf | 23 --- dist/popn/popnhook-18.conf | 23 --- src/main/popnhook1/Module.mk | 5 +- src/main/popnhook1/config-eamuse.c | 147 +--------------- src/main/popnhook1/config-eamuse.h | 11 +- src/main/popnhook1/config-gfx.c | 92 +--------- src/main/popnhook1/config-gfx.h | 17 +- src/main/popnhook1/config-sec.c | 81 +-------- src/main/popnhook1/config-sec.h | 15 +- src/main/popnhook1/dllmain.c | 259 +++++------------------------ src/main/popnhook1/popnhook1.c | 196 ++++++++++++++++++++++ src/main/popnhook1/popnhook1.def | 6 + src/main/popnhook1/popnhook1.h | 9 + 24 files changed, 754 insertions(+), 644 deletions(-) create mode 100644 dist/popn/inject-15.xml create mode 100644 dist/popn/inject-16.xml create mode 100644 dist/popn/inject-17.xml create mode 100644 dist/popn/inject-18.xml delete mode 100644 dist/popn/popnhook-15.conf delete mode 100644 dist/popn/popnhook-16.conf delete mode 100644 dist/popn/popnhook-17.conf delete mode 100644 dist/popn/popnhook-18.conf create mode 100644 src/main/popnhook1/popnhook1.c create mode 100644 src/main/popnhook1/popnhook1.h diff --git a/Module.mk b/Module.mk index e22b0dc..e410660 100644 --- a/Module.mk +++ b/Module.mk @@ -887,10 +887,10 @@ $(zipdir)/popn-15-to-18.zip: \ dist/popn/gamestart-16.bat \ dist/popn/gamestart-17.bat \ dist/popn/gamestart-18.bat \ - dist/popn/popnhook-15.conf \ - dist/popn/popnhook-16.conf \ - dist/popn/popnhook-17.conf \ - dist/popn/popnhook-18.conf \ + dist/popn/inject-15.xml \ + dist/popn/inject-16.xml \ + dist/popn/inject-17.xml \ + dist/popn/inject-18.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ diff --git a/dist/popn/gamestart-15.bat b/dist/popn/gamestart-15.bat index f9b6709..b1cf433 100644 --- a/dist/popn/gamestart-15.bat +++ b/dist/popn/gamestart-15.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data and prog cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\prog\2007091800 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_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 inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist e\bookkeeping mkdir e\bookkeeping if not exist e\CONF\NVRAM mkdir e\CONF\NVRAM if not exist e\CONF\NVRAM\0 mkdir e\CONF\NVRAM\0 @@ -12,5 +54,6 @@ if not exist e\CONF\RAW mkdir e\CONF\RAW if not exist e\settings mkdir e\settings if not exist e\UP mkdir e\UP -inject popnhook1.dll ezusb.dll=ezusb2-popn-shim.dll popn15.exe --config popnhook-15.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\inject-15.xml^ + %* \ No newline at end of file diff --git a/dist/popn/gamestart-16.bat b/dist/popn/gamestart-16.bat index 8841818..7f1deed 100644 --- a/dist/popn/gamestart-16.bat +++ b/dist/popn/gamestart-16.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data and prog cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\prog\2008052700 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_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 inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist e\bookkeeping mkdir e\bookkeeping if not exist e\CONF\NVRAM mkdir e\CONF\NVRAM if not exist e\CONF\NVRAM\0 mkdir e\CONF\NVRAM\0 @@ -12,5 +54,6 @@ if not exist e\CONF\RAW mkdir e\CONF\RAW if not exist e\settings mkdir e\settings if not exist e\UP mkdir e\UP -inject popnhook1.dll ezusb.dll=ezusb2-popn-shim.dll popn16.exe --config popnhook-16.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\inject-16.xml^ + %* \ No newline at end of file diff --git a/dist/popn/gamestart-17.bat b/dist/popn/gamestart-17.bat index e35442d..e8d0bca 100644 --- a/dist/popn/gamestart-17.bat +++ b/dist/popn/gamestart-17.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data and prog cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\prog\2009022500 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_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 inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist e\bookkeeping mkdir e\bookkeeping if not exist e\CONF\NVRAM mkdir e\CONF\NVRAM if not exist e\CONF\NVRAM\0 mkdir e\CONF\NVRAM\0 @@ -12,5 +54,6 @@ if not exist e\CONF\RAW mkdir e\CONF\RAW if not exist e\settings mkdir e\settings if not exist e\UP mkdir e\UP -inject popnhook1.dll ezusb.dll=ezusb2-popn-shim.dll popn17.exe --config popnhook-17.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\inject-17.xml^ + %* \ No newline at end of file diff --git a/dist/popn/gamestart-18.bat b/dist/popn/gamestart-18.bat index 8cbce7c..40b748f 100644 --- a/dist/popn/gamestart-18.bat +++ b/dist/popn/gamestart-18.bat @@ -1,7 +1,49 @@ @echo off +:: Keep all vars scoped to this script +setlocal + +:: Game doesn't work properly when not run with administrator privileges +>nul 2>&1 net session + +if %errorlevel% neq 0 ( + echo This script requires administrative privileges. + echo Please run the script as an administrator. + pause + exit 1 +) + +:: Script expects to be located in a subfolder "bemanitools" in the root folder +:: next to the folders data and prog cd /d %~dp0 +set CONTENT_DIR=%CD%\.. +set BEMANITOOLS_DIR=%CONTENT_DIR%\bemanitools +set REVISION_DIR=%CONTENT_DIR%\prog\2010040500 + +if not exist "%BEMANITOOLS_DIR%" ( + echo The bemanitools directory "%BEMANITOOLS_DIR%" does not exist. + pause + exit 1 +) + +if not exist "%REVISION_DIR%" ( + echo The game modules directory "%REVISION_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 inject can find the libs and game executable +:: Remark: This also requires admin privileges to propage correctly to inject +set PATH=^ +%REVISION_DIR%;^ +%BEMANITOOLS_DIR%;^ +%PATH% + +:: Current working dir is the selected game revision root folder +cd /d %REVISION_DIR% + if not exist e\bookkeeping mkdir e\bookkeeping if not exist e\CONF\NVRAM mkdir e\CONF\NVRAM if not exist e\CONF\NVRAM\0 mkdir e\CONF\NVRAM\0 @@ -12,5 +54,6 @@ if not exist e\CONF\RAW mkdir e\CONF\RAW if not exist e\settings mkdir e\settings if not exist e\UP mkdir e\UP -inject popnhook1.dll ezusb.dll=ezusb2-popn-shim.dll popn18.exe --config popnhook-18.conf %* - +%BEMANITOOLS_DIR%\inject.exe^ + %BEMANITOOLS_DIR%\inject-18.xml^ + %* \ No newline at end of file diff --git a/dist/popn/inject-15.xml b/dist/popn/inject-15.xml new file mode 100644 index 0000000..3d0ecdb --- /dev/null +++ b/dist/popn/inject-15.xml @@ -0,0 +1,68 @@ + + + 1 + + + popn15.exe + + + inject + + + + 1 + ezusb.dll + ezusb2-popn-shim.dll + + + 1 + popnhook1.dll + + + + + localhost:80 + 0101020304050607086F + 0101020304050607086F + + + 1 + 1 + 0 + 0 + + + GQG15JAA + + + + + + + 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/dist/popn/inject-16.xml b/dist/popn/inject-16.xml new file mode 100644 index 0000000..c476612 --- /dev/null +++ b/dist/popn/inject-16.xml @@ -0,0 +1,68 @@ + + + 1 + + + popn16.exe + + + inject + + + + 1 + ezusb.dll + ezusb2-popn-shim.dll + + + 1 + popnhook1.dll + + + + + localhost:80 + 0101020304050607086F + 0101020304050607086F + + + 1 + 1 + 0 + 0 + + + GQH16JAA + + + + + + + 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/dist/popn/inject-17.xml b/dist/popn/inject-17.xml new file mode 100644 index 0000000..001cecb --- /dev/null +++ b/dist/popn/inject-17.xml @@ -0,0 +1,68 @@ + + + 1 + + + popn17.exe + + + inject + + + + 1 + ezusb.dll + ezusb2-popn-shim.dll + + + 1 + popnhook1.dll + + + + + localhost:80 + 0101020304050607086F + 0101020304050607086F + + + 1 + 1 + 0 + 0 + + + GQI17JAA + + + + + + + 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/dist/popn/inject-18.xml b/dist/popn/inject-18.xml new file mode 100644 index 0000000..d516ea5 --- /dev/null +++ b/dist/popn/inject-18.xml @@ -0,0 +1,68 @@ + + + 1 + + + popn18.exe + + + inject + + + + 1 + ezusb.dll + ezusb2-popn-shim.dll + + + 1 + popnhook1.dll + + + + + localhost:80 + 0101020304050607086F + 0101020304050607086F + + + 1 + 1 + 0 + 0 + + + GCJ39JAA + + + + + + + 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/dist/popn/popnhook-15.conf b/dist/popn/popnhook-15.conf deleted file mode 100644 index c429407..0000000 --- a/dist/popn/popnhook-15.conf +++ /dev/null @@ -1,23 +0,0 @@ -# URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. -eamuse.server=localhost:80 - -# PCBID -eamuse.pcbid=0101020304050607086F - -# EAMID -eamuse.eamid=0101020304050607086F - -# Run the game windowed -gfx.windowed=false - -# Run the game in a framed window (requires windowed option) -gfx.framed=false - -# Windowed width, 0 for default size -gfx.window_width=0 - -# Windowed height, 0 for default size -gfx.window_height=0 - -# Security black plug mcode id string (e.g. GQC02JAA). -sec.black_plug_mcode=GQG15JAA diff --git a/dist/popn/popnhook-16.conf b/dist/popn/popnhook-16.conf deleted file mode 100644 index 4c7affa..0000000 --- a/dist/popn/popnhook-16.conf +++ /dev/null @@ -1,23 +0,0 @@ -# URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. -eamuse.server=localhost:80 - -# PCBID -eamuse.pcbid=0101020304050607086F - -# EAMID -eamuse.eamid=0101020304050607086F - -# Run the game windowed -gfx.windowed=false - -# Run the game in a framed window (requires windowed option) -gfx.framed=false - -# Windowed width, 0 for default size -gfx.window_width=0 - -# Windowed height, 0 for default size -gfx.window_height=0 - -# Security black plug mcode id string (e.g. GQC02JAA). -sec.black_plug_mcode=GQH16JAA diff --git a/dist/popn/popnhook-17.conf b/dist/popn/popnhook-17.conf deleted file mode 100644 index cd32bd1..0000000 --- a/dist/popn/popnhook-17.conf +++ /dev/null @@ -1,23 +0,0 @@ -# URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. -eamuse.server=localhost:80 - -# PCBID -eamuse.pcbid=0101020304050607086F - -# EAMID -eamuse.eamid=0101020304050607086F - -# Run the game windowed -gfx.windowed=false - -# Run the game in a framed window (requires windowed option) -gfx.framed=false - -# Windowed width, 0 for default size -gfx.window_width=0 - -# Windowed height, 0 for default size -gfx.window_height=0 - -# Security black plug mcode id string (e.g. GQC02JAA). -sec.black_plug_mcode=GQI17JAA \ No newline at end of file diff --git a/dist/popn/popnhook-18.conf b/dist/popn/popnhook-18.conf deleted file mode 100644 index bb11e6a..0000000 --- a/dist/popn/popnhook-18.conf +++ /dev/null @@ -1,23 +0,0 @@ -# URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. -eamuse.server=localhost:80 - -# PCBID -eamuse.pcbid=0101020304050607086F - -# EAMID -eamuse.eamid=0101020304050607086F - -# Run the game windowed -gfx.windowed=false - -# Run the game in a framed window (requires windowed option) -gfx.framed=false - -# Windowed width, 0 for default size -gfx.window_width=0 - -# Windowed height, 0 for default size -gfx.window_height=0 - -# Security black plug mcode id string (e.g. GQC02JAA). -sec.black_plug_mcode=GCJ39JAA \ No newline at end of file diff --git a/src/main/popnhook1/Module.mk b/src/main/popnhook1/Module.mk index 15128ab..26cfe69 100644 --- a/src/main/popnhook1/Module.mk +++ b/src/main/popnhook1/Module.mk @@ -6,6 +6,7 @@ deplibs_popnhook1 := \ ldflags_popnhook1 := \ -lws2_32 \ -liphlpapi \ + -lshlwapi \ libs_popnhook1 := \ core \ @@ -17,7 +18,6 @@ libs_popnhook1 := \ acioemu \ hook \ hooklib \ - cconfig \ util \ ezusb \ security \ @@ -26,6 +26,8 @@ libs_popnhook1 := \ iface-io \ iface-core \ module \ + sdk-hook \ + mxml \ src_popnhook1 := \ avs-boot.c \ @@ -35,3 +37,4 @@ src_popnhook1 := \ d3d9.c \ dllmain.c \ filesystem.c \ + popnhook1.c \ diff --git a/src/main/popnhook1/config-eamuse.c b/src/main/popnhook1/config-eamuse.c index c860333..8ca994f 100644 --- a/src/main/popnhook1/config-eamuse.c +++ b/src/main/popnhook1/config-eamuse.c @@ -1,145 +1,12 @@ -#include - -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" +#include "core/config-ext.h" #include "popnhook1/config-eamuse.h" -#include "security/mcode.h" - -#define POPNHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server" -#define POPNHOOK1_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid" -#define POPNHOOK1_CONFIG_EAMUSE_EAMID_KEY "eamuse.eamid" - -#define POPNHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE "localhost:80" -#define POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE security_id_default -#define POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN \ - sizeof(security_id_default) -#define POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE security_id_default -#define POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN \ - sizeof(security_id_default) - -const struct net_addr popnhook1_eamuse_default_server = { - .type = NET_ADDR_TYPE_HOSTNAME, - .hostname.host = "localhost", - .hostname.port = 80, -}; - -void popnhook1_config_eamuse_init(struct cconfig *config) -{ - cconfig_util_set_str( - config, - POPNHOOK1_CONFIG_EAMUSE_SERVER_KEY, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE, - "URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 " - "(e.g. 127.0.0.1:80) of the target eamuse server. The port is " - "optional " - "but defaults to 80."); - - cconfig_util_set_data( - config, - POPNHOOK1_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t *) &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, - "PCBID"); - - cconfig_util_set_data( - config, - POPNHOOK1_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t *) &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, - "EAMID"); -} - void popnhook1_config_eamuse_get( - struct popnhook1_config_eamuse *config_eamuse, struct cconfig *config) + const bt_core_config_t *config, + popnhook1_config_eamuse_t *config_out) { - char server_url[1024]; - char *tmp; - char *tmp2; - - memset(config_eamuse, 0, sizeof(struct popnhook1_config_eamuse)); - - if (!cconfig_util_get_str( - config, - POPNHOOK1_CONFIG_EAMUSE_SERVER_KEY, - server_url, - sizeof(server_url), - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%s'", - POPNHOOK1_CONFIG_EAMUSE_SERVER_KEY, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE); - } - - if (!net_str_parse(server_url, &config_eamuse->server)) { - memcpy( - &config_eamuse->server, - &popnhook1_eamuse_default_server, - sizeof(config_eamuse->server)); - tmp = net_addr_to_str(&config_eamuse->server); - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default", - tmp); - free(tmp); - } - - if (!cconfig_util_get_data( - config, - POPNHOOK1_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t *) &config_eamuse->pcbid, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, - (uint8_t *) &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) { - tmp = security_id_to_str( - &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default", - tmp); - free(tmp); - } - - if (!security_id_verify(&config_eamuse->pcbid)) { - tmp = security_id_to_str( - &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); - tmp2 = security_id_to_str(&config_eamuse->pcbid, false); - log_warning( - "PCBID verification of '%s' failed, fallback to default " - "PCBID '%s'", - tmp2, - tmp); - free(tmp); - free(tmp2); - } - - if (!cconfig_util_get_data( - config, - POPNHOOK1_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t *) &config_eamuse->eamid, - POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, - (uint8_t *) &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) { - tmp = security_id_to_str( - &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default", - tmp); - free(tmp); - } - - if (!security_id_verify(&config_eamuse->eamid)) { - tmp = security_id_to_str( - &POPNHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); - tmp2 = security_id_to_str(&config_eamuse->eamid, false); - log_warning( - "EAMID verification of '%s' failed, fallback to default " - "EAMID '%s'", - tmp2, - tmp); - free(tmp); - free(tmp2); - } -} + bt_core_config_ext_net_addr_get(config, "eamuse/server", &config_out->server); + bt_core_config_ext_security_id_get(config, "eamuse/pcbid", &config_out->pcbid); + bt_core_config_ext_security_id_get(config, "eamuse/eamid", &config_out->eamid); +} \ No newline at end of file diff --git a/src/main/popnhook1/config-eamuse.h b/src/main/popnhook1/config-eamuse.h index c08c50d..ad5732d 100644 --- a/src/main/popnhook1/config-eamuse.h +++ b/src/main/popnhook1/config-eamuse.h @@ -1,21 +1,20 @@ #ifndef POPNHOOK1_CONFIG_EAMUSE_H #define POPNHOOK1_CONFIG_EAMUSE_H -#include "cconfig/cconfig.h" +#include "api/core/config.h" #include "security/id.h" #include "util/net.h" -struct popnhook1_config_eamuse { +typedef struct popnhook1_config_eamuse { struct net_addr server; struct security_id pcbid; struct security_id eamid; -}; - -void popnhook1_config_eamuse_init(struct cconfig *config); +} popnhook1_config_eamuse_t; void popnhook1_config_eamuse_get( - struct popnhook1_config_eamuse *config_eamuse, struct cconfig *config); + const bt_core_config_t *config, + popnhook1_config_eamuse_t *config_out); #endif \ No newline at end of file diff --git a/src/main/popnhook1/config-gfx.c b/src/main/popnhook1/config-gfx.c index c95fc11..5e9cfda 100644 --- a/src/main/popnhook1/config-gfx.c +++ b/src/main/popnhook1/config-gfx.c @@ -1,8 +1,4 @@ -#include - -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" +#include "core/config-ext.h" #include "popnhook1/config-gfx.h" @@ -11,86 +7,12 @@ #define POPNHOOK1_CONFIG_GFX_WINDOW_WIDTH_KEY "gfx.window_width" #define POPNHOOK1_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height" -#define POPNHOOK1_CONFIG_GFX_DEFAULT_FRAMED_VALUE false -#define POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false -#define POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE -1 -#define POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE -1 - -void popnhook1_config_gfx_init(struct cconfig *config) -{ - cconfig_util_set_bool( - config, - POPNHOOK1_CONFIG_GFX_WINDOWED_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE, - "Run the game windowed"); - - cconfig_util_set_bool( - config, - POPNHOOK1_CONFIG_GFX_FRAMED_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_FRAMED_VALUE, - "Run the game in a framed window (requires windowed option)"); - - cconfig_util_set_int( - config, - POPNHOOK1_CONFIG_GFX_WINDOW_WIDTH_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE, - "Windowed width, -1 for default size"); - - cconfig_util_set_int( - config, - POPNHOOK1_CONFIG_GFX_WINDOW_HEIGHT_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE, - "Windowed height, -1 for default size"); -} - void popnhook1_config_gfx_get( - struct popnhook1_config_gfx *config_gfx, struct cconfig *config) + const bt_core_config_t *config, + popnhook1_config_gfx_t *out_config) { - if (!cconfig_util_get_bool( - config, - POPNHOOK1_CONFIG_GFX_WINDOWED_KEY, - &config_gfx->windowed, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - POPNHOOK1_CONFIG_GFX_WINDOWED_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE); - } - - if (!cconfig_util_get_bool( - config, - POPNHOOK1_CONFIG_GFX_FRAMED_KEY, - &config_gfx->framed, - POPNHOOK1_CONFIG_GFX_DEFAULT_FRAMED_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - POPNHOOK1_CONFIG_GFX_FRAMED_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_FRAMED_VALUE); - } - - if (!cconfig_util_get_int( - config, - POPNHOOK1_CONFIG_GFX_WINDOW_WIDTH_KEY, - &config_gfx->window_width, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - POPNHOOK1_CONFIG_GFX_WINDOW_WIDTH_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE); - } - - if (!cconfig_util_get_int( - config, - POPNHOOK1_CONFIG_GFX_WINDOW_HEIGHT_KEY, - &config_gfx->window_height, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - POPNHOOK1_CONFIG_GFX_WINDOW_HEIGHT_KEY, - POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE); - } + bt_core_config_bool_get(config, "gfx/windowed", &out_config->windowed); + bt_core_config_bool_get(config, "gfx/framed", &out_config->framed); + bt_core_config_s32_get(config, "gfx/window_width", &out_config->window_width); + bt_core_config_s32_get(config, "gfx/window_height", &out_config->window_height); } diff --git a/src/main/popnhook1/config-gfx.h b/src/main/popnhook1/config-gfx.h index a0eeba4..29e38ae 100644 --- a/src/main/popnhook1/config-gfx.h +++ b/src/main/popnhook1/config-gfx.h @@ -1,21 +1,20 @@ #ifndef POPNHOOK1_CONFIG_GFX_H #define POPNHOOK1_CONFIG_GFX_H -#include "cconfig/cconfig.h" +#include +#include -#include "popnhook1/d3d9.h" +#include "api/core/config.h" -// see struct popnhook1_d3d9_config for more info -struct popnhook1_config_gfx { +typedef struct popnhook1_config_gfx { bool framed; bool windowed; int32_t window_width; int32_t window_height; -}; - -void popnhook1_config_gfx_init(struct cconfig *config); +} popnhook1_config_gfx_t; void popnhook1_config_gfx_get( - struct popnhook1_config_gfx *config_gfx, struct cconfig *config); - + const bt_core_config_t *config, + popnhook1_config_gfx_t *out_config); + #endif \ No newline at end of file diff --git a/src/main/popnhook1/config-sec.c b/src/main/popnhook1/config-sec.c index 61749b3..1d21f87 100644 --- a/src/main/popnhook1/config-sec.c +++ b/src/main/popnhook1/config-sec.c @@ -1,81 +1,10 @@ -#include -#include - -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" +#include "core/config-ext.h" #include "popnhook1/config-sec.h" -#include "security/mcode.h" -#include "security/rp.h" - -#include "util/mem.h" - -#define POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY "sec.black_plug_mcode" - -#define POPNHOOK1_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE \ - popnhook1_security_default_black_plug_mcode - -static const struct security_mcode popnhook1_security_default_black_plug_mcode = - { - .header = SECURITY_MCODE_HEADER, - .unkn = SECURITY_MCODE_UNKN_Q, - .game = SECURITY_MCODE_GAME_POPN_15, - .region = SECURITY_MCODE_REGION_JAPAN, - .cabinet = SECURITY_MCODE_CABINET_A, - .revision = SECURITY_MCODE_REVISION_A, -}; - -void popnhook1_config_sec_init(struct cconfig *config) -{ - char *tmp; - - tmp = security_mcode_to_str( - &POPNHOOK1_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE); - - cconfig_util_set_str( - config, - POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, - tmp, - "Security black plug mcode id string (e.g. GQC02JAA)."); - - free(tmp); -} - void popnhook1_config_sec_get( - struct popnhook1_config_sec *config_sec, struct cconfig *config) + const bt_core_config_t *config, + popnhook1_config_sec_t *out_config) { - char tmp_mcode[sizeof(struct security_mcode) + 1]; - char *tmp_str; - - tmp_str = security_mcode_to_str( - &POPNHOOK1_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE); - - if (!cconfig_util_get_str( - config, - POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, - tmp_mcode, - sizeof(tmp_mcode) - 1, - tmp_str)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%s'", - POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, - tmp_str); - } - - if (!security_mcode_parse(tmp_mcode, &config_sec->black_plug_mcode)) { - log_warning( - "Invalid format for value of key '%s' specified, fallback " - "to default '%s'", - POPNHOOK1_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, - tmp_str); - memcpy( - &config_sec->black_plug_mcode, - &POPNHOOK1_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE, - sizeof(POPNHOOK1_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE)); - } - - free(tmp_str); -} + bt_core_config_ext_security_mcode_get(config, "sec/black_plug_mcode", &out_config->black_plug_mcode); +} \ No newline at end of file diff --git a/src/main/popnhook1/config-sec.h b/src/main/popnhook1/config-sec.h index 51671b8..1b889b3 100644 --- a/src/main/popnhook1/config-sec.h +++ b/src/main/popnhook1/config-sec.h @@ -1,17 +1,16 @@ #ifndef POPNHOOK1_CONFIG_SEC_H #define POPNHOOK1_CONFIG_SEC_H -#include "cconfig/cconfig.h" +#include "api/core/config.h" #include "security/mcode.h" -struct popnhook1_config_sec { - struct security_mcode black_plug_mcode; -}; - -void popnhook1_config_sec_init(struct cconfig *config); +typedef struct popnhook1_config_sec { + security_mcode_t black_plug_mcode; +} popnhook1_config_sec_t; void popnhook1_config_sec_get( - struct popnhook1_config_sec *config_sec, struct cconfig *config); - + const bt_core_config_t *config, + popnhook1_config_sec_t *out_config); + #endif \ No newline at end of file diff --git a/src/main/popnhook1/dllmain.c b/src/main/popnhook1/dllmain.c index dab99ca..3c6abb0 100644 --- a/src/main/popnhook1/dllmain.c +++ b/src/main/popnhook1/dllmain.c @@ -1,241 +1,70 @@ -#include - #include -#include -#include - -#include "cconfig/cconfig-hook.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/node-security-plug.h" - -#include "hook/d3d9.h" #include "hook/table.h" -#include "hooklib/adapter.h" +#include "popnhook1/popnhook1.h" -#include "iface-core/log.h" -#include "iface-core/thread.h" +#include "main/sdk-hook/dllentry.h" -#include "iface-io/eam.h" -#include "iface-io/popn.h" - -#include "module/io-ext.h" -#include "module/io.h" - -#include "popnhook1/avs-boot.h" -#include "popnhook1/config-eamuse.h" -#include "popnhook1/config-gfx.h" -#include "popnhook1/config-sec.h" -#include "popnhook1/d3d9.h" -#include "popnhook1/filesystem.h" - -#include "popnhook-util/acio.h" -#include "popnhook-util/mixer.h" - -#include "util/cmdline.h" #include "util/defs.h" -#include "ezusb2-emu/desc.h" -#include "ezusb2-emu/device.h" +static DWORD STDCALL _popnhook1_dllmain_my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo); +static DWORD(STDCALL *_popnhook1_dllmain_real_GetStartupInfoA)(LPSTARTUPINFOA lpStartupInfo); -#include "popnhook-util/acio.h" +static bool _popnhook1_dllmain_getstartupinfoa_call_check; -#include "ezusb2-popn-emu/msg.h" - -#include "hooklib/rs232.h" - -#include "security/rp-sign-key.h" - -#define POPNHOOK1_INFO_HEADER \ - "popnhook1 for pop'n music 15, 16, 17, 18" \ - ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) -#define POPNHOOK1_CMD_USAGE \ - "Usage: inject.exe popnhook1.dll [options...]" - -static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo); -static DWORD(STDCALL *real_GetStartupInfoA)(LPSTARTUPINFOA lpStartupInfo); - -static bool popnhook1_init_check; -static module_io_t *popnhook_module_io_popn; -static module_io_t *popnhook_module_io_eam; - -static const struct hook_symbol init_hook_syms[] = { +static const struct hook_symbol _popnhook1_dllmain_hook_syms[] = { { .name = "GetStartupInfoA", - .patch = my_GetStartupInfoA, - .link = (void **) &real_GetStartupInfoA, + .patch = _popnhook1_dllmain_my_GetStartupInfoA, + .link = (void **) &_popnhook1_dllmain_real_GetStartupInfoA, }, }; -static void _popnhook1_log_init() +static DWORD STDCALL +_popnhook1_dllmain_my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo) { - 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 _popnhook1_io_popn_init(module_io_t **module) -{ - bt_io_popn_api_t api; - - module_io_ext_load_and_init( - "popnio.dll", "bt_module_io_popn_api_get", module); - module_io_api_get(*module, &api); - bt_io_popn_api_set(&api); -} - -static void _popnhook1_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 popnhook_setup_d3d9_hooks( - const struct popnhook1_config_gfx *config_gfx, const bool texture_usage_fix) -{ - struct popnhook1_d3d9_config d3d9_config; - - popnhook1_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.texture_usage_fix = texture_usage_fix; - - popnhook1_d3d9_init(); - popnhook1_d3d9_configure(&d3d9_config); -} - -static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo) -{ - struct cconfig *config; - - struct popnhook1_config_eamuse config_eamuse; - struct popnhook1_config_gfx config_gfx; - struct popnhook1_config_sec config_sec; - - if (popnhook1_init_check) - goto skip; - - popnhook1_init_check = true; - - log_info("-------------------------------------------------------------"); - log_info("----------------- Start popnhook1 hook init -----------------"); - log_info("-------------------------------------------------------------"); - - config = cconfig_init(); - - popnhook1_config_eamuse_init(config); - popnhook1_config_gfx_init(config); - popnhook1_config_sec_init(config); - - if (!cconfig_hook_config_init( - config, - POPNHOOK1_INFO_HEADER "\n" POPNHOOK1_CMD_USAGE, - CCONFIG_CMD_USAGE_OUT_DBG)) { - cconfig_finit(config); - exit(EXIT_FAILURE); + if (_popnhook1_dllmain_getstartupinfoa_call_check) { + return _popnhook1_dllmain_real_GetStartupInfoA(lpStartupInfo); } - popnhook1_config_gfx_get(&config_gfx, config); - popnhook1_config_eamuse_get(&config_eamuse, config); - popnhook1_config_sec_get(&config_sec, config); + _popnhook1_dllmain_getstartupinfoa_call_check = true; - cconfig_finit(config); + bt_hook_dllentry_main_init(); - popnhook_setup_d3d9_hooks( - &config_gfx, - // pop'n music 16 requires a patch for the texture usage to not crash on - // newer Windows - memcmp( - config_sec.black_plug_mcode.game, - SECURITY_MCODE_GAME_POPN_16, - sizeof(config_sec.black_plug_mcode.game)) == 0); - - popnhook1_avs_boot_init(); - popnhook1_avs_boot_set_eamuse_addr(&config_eamuse.server); - - /* Round plug security */ - - ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( - &config_sec.black_plug_mcode); - ezusb_iidx_emu_node_security_plug_set_plug_white_mcode( - &security_mcode_eamuse); - ezusb_iidx_emu_node_security_plug_set_plug_black_sign_key( - &security_rp_sign_key_black_popn); - ezusb_iidx_emu_node_security_plug_set_plug_white_sign_key( - &security_rp_sign_key_white_eamuse); - - ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); - ezusb_iidx_emu_node_security_plug_set_eamid(&config_eamuse.eamid); - - /* Start up POPNIO.DLL */ - - log_info("Starting pop'n IO backend"); - - _popnhook1_io_popn_init(&popnhook_module_io_popn); - - if (!bt_io_popn_init()) { - log_fatal("Initializing pop'n IO backend failed"); - } - - /* Start up EAMIO.DLL */ - - log_misc("Initializing card reader backend"); - - _popnhook1_io_eam_init(&popnhook_module_io_eam); - - if (!bt_io_eam_init()) { - log_fatal("Initializing card reader backend failed"); - } - - iohook_push_handler(ezusb2_emu_device_dispatch_irp); - iohook_push_handler(popnhook_acio_dispatch_irp); - - hook_setupapi_init(&ezusb2_emu_desc_device.setupapi); - ezusb2_emu_device_hook_init(ezusb2_popn_emu_msg_init()); - - rs232_hook_init(); - - popnhook_acio_init(true); - - adapter_hook_init(); - filesystem_init(); - popnhook_mixer_hook_init(); - - log_info("-------------------------------------------------------------"); - log_info("------------------ End popnhook1 hook init ------------------"); - log_info("-------------------------------------------------------------"); - -skip: - return real_GetStartupInfoA(lpStartupInfo); + return _popnhook1_dllmain_real_GetStartupInfoA(lpStartupInfo); } -BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) +// 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) { - return TRUE; + if (reason == DLL_PROCESS_ATTACH) { + bt_hook_dllentry_init( + mod, + "popnhook1", + bt_module_core_config_api_set, + bt_module_core_log_api_set, + bt_module_core_thread_api_set, + bt_module_hook_api_get); + + _popnhook1_dllmain_getstartupinfoa_call_check = false; + + hook_table_apply( + NULL, "kernel32.dll", _popnhook1_dllmain_hook_syms, lengthof(_popnhook1_dllmain_hook_syms)); + + } 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", _popnhook1_dllmain_hook_syms, lengthof(_popnhook1_dllmain_hook_syms)); + + // 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(); + } } - // Use bemanitools core APIs - core_log_bt_core_api_set(); - core_thread_crt_core_api_set(); - - _popnhook1_log_init(); - - hook_table_apply( - NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); - return TRUE; -} +} \ No newline at end of file diff --git a/src/main/popnhook1/popnhook1.c b/src/main/popnhook1/popnhook1.c new file mode 100644 index 0000000..0ae96c6 --- /dev/null +++ b/src/main/popnhook1/popnhook1.c @@ -0,0 +1,196 @@ +#include + +#include + +#include +#include + +#include "ezusb-emu/node-security-plug.h" + +#include "hook/d3d9.h" + +#include "hooklib/adapter.h" + +#include "iface-core/config.h" +#include "iface-core/log.h" +#include "iface-core/thread.h" + +#include "iface-io/eam.h" +#include "iface-io/popn.h" + +#include "module/io-ext.h" +#include "module/io.h" + +#include "popnhook1/avs-boot.h" +#include "popnhook1/config-eamuse.h" +#include "popnhook1/config-gfx.h" +#include "popnhook1/config-sec.h" +#include "popnhook1/d3d9.h" +#include "popnhook1/filesystem.h" + +#include "popnhook-util/acio.h" +#include "popnhook-util/mixer.h" + +#include "util/cmdline.h" +#include "util/defs.h" + +#include "ezusb2-emu/desc.h" +#include "ezusb2-emu/device.h" + +#include "popnhook-util/acio.h" + +#include "ezusb2-popn-emu/msg.h" + +#include "hooklib/rs232.h" + +#include "sdk/module/core/config.h" +#include "sdk/module/core/log.h" +#include "sdk/module/core/thread.h" +#include "sdk/module/hook.h" + +#include "security/rp-sign-key.h" + +static module_io_t *popnhook_module_io_popn; +static module_io_t *popnhook_module_io_eam; + +static void _popnhook1_io_popn_init(module_io_t **module) +{ + bt_io_popn_api_t api; + + module_io_ext_load_and_init( + "popnio.dll", "bt_module_io_popn_api_get", module); + module_io_api_get(*module, &api); + bt_io_popn_api_set(&api); +} + +static void _popnhook1_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 popnhook_setup_d3d9_hooks( + const popnhook1_config_gfx_t *config_gfx, const bool texture_usage_fix) +{ + struct popnhook1_d3d9_config d3d9_config; + + popnhook1_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.texture_usage_fix = texture_usage_fix; + + popnhook1_d3d9_init(); + popnhook1_d3d9_configure(&d3d9_config); +} + +static bool +_popnhook1_main_init(HMODULE game_module, const bt_core_config_t *config) +{ + popnhook1_config_eamuse_t config_eamuse; + popnhook1_config_gfx_t config_gfx; + popnhook1_config_sec_t config_sec; + + log_info("popnhook1 for pop'n music 15, 16, 17, 18"); + log_info("build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)); + + popnhook1_config_gfx_get(config, &config_gfx); + popnhook1_config_eamuse_get(config, &config_eamuse); + popnhook1_config_sec_get(config, &config_sec); + + popnhook_setup_d3d9_hooks( + &config_gfx, + // pop'n music 16 requires a patch for the texture usage to not crash on + // newer Windows + memcmp( + config_sec.black_plug_mcode.game, + SECURITY_MCODE_GAME_POPN_16, + sizeof(config_sec.black_plug_mcode.game)) == 0); + + popnhook1_avs_boot_init(); + popnhook1_avs_boot_set_eamuse_addr(&config_eamuse.server); + + /* Round plug security */ + + ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( + &config_sec.black_plug_mcode); + ezusb_iidx_emu_node_security_plug_set_plug_white_mcode( + &security_mcode_eamuse); + ezusb_iidx_emu_node_security_plug_set_plug_black_sign_key( + &security_rp_sign_key_black_popn); + ezusb_iidx_emu_node_security_plug_set_plug_white_sign_key( + &security_rp_sign_key_white_eamuse); + + ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); + ezusb_iidx_emu_node_security_plug_set_eamid(&config_eamuse.eamid); + + /* Start up POPNIO.DLL */ + + log_info("Starting pop'n IO backend"); + + _popnhook1_io_popn_init(&popnhook_module_io_popn); + + if (!bt_io_popn_init()) { + log_fatal("Initializing pop'n IO backend failed"); + } + + /* Start up EAMIO.DLL */ + + log_misc("Initializing card reader backend"); + + _popnhook1_io_eam_init(&popnhook_module_io_eam); + + if (!bt_io_eam_init()) { + log_fatal("Initializing card reader backend failed"); + } + + iohook_push_handler(ezusb2_emu_device_dispatch_irp); + iohook_push_handler(popnhook_acio_dispatch_irp); + + hook_setupapi_init(&ezusb2_emu_desc_device.setupapi); + ezusb2_emu_device_hook_init(ezusb2_popn_emu_msg_init()); + + rs232_hook_init(); + + popnhook_acio_init(true); + + adapter_hook_init(); + filesystem_init(); + popnhook_mixer_hook_init(); + + return true; +} + +static void _popnhook1_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 = _popnhook1_main_init; + api->v1.main_fini = _popnhook1_main_fini; +} \ No newline at end of file diff --git a/src/main/popnhook1/popnhook1.def b/src/main/popnhook1/popnhook1.def index 9573263..9fe2c52 100644 --- a/src/main/popnhook1/popnhook1.def +++ b/src/main/popnhook1/popnhook1.def @@ -2,3 +2,9 @@ LIBRARY popnhook1 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 \ No newline at end of file diff --git a/src/main/popnhook1/popnhook1.h b/src/main/popnhook1/popnhook1.h new file mode 100644 index 0000000..5c1a1d2 --- /dev/null +++ b/src/main/popnhook1/popnhook1.h @@ -0,0 +1,9 @@ +#ifndef POPNHOOK1_H +#define POPNHOOK1_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 \ No newline at end of file