feat(ddrhook1): Use sdk-hook and support new config api

Summary:

Test Plan:
Summary:

Test Plan:
This commit is contained in:
icex2
2024-08-17 12:50:14 +02:00
parent 4a751a13aa
commit d4ad25f110
13 changed files with 302 additions and 649 deletions

View File

@@ -2,6 +2,7 @@ avsdlls += ddrhook1
ldflags_ddrhook1 := \
-lws2_32 \
-lshlwapi \
deplibs_ddrhook1 := \
avs \
@@ -10,9 +11,9 @@ avslibs_ddrhook1 := \
avs-ext \
libs_ddrhook1 := \
sdk-hook \
core \
acioemu \
cconfig \
ddrhook-util \
p3ioemu \
p3io \
@@ -20,16 +21,19 @@ libs_ddrhook1 := \
hooklib \
util \
security \
iface \
iface-core \
iface-io \
module \
mxml \
src_ddrhook1 := \
avs-boot.c \
ddrhook1.c \
dllmain.c \
config-ddrhook1.c \
config-eamuse.c \
config-gfx.c \
config-security.c \
master.c \
filesystem.c \
master.c \

View File

@@ -1,129 +1,17 @@
#include <string.h>
#include "cconfig/cconfig-util.h"
#include "core/config-ext.h"
#include "ddrhook1/config-ddrhook1.h"
#include "iface-core/log.h"
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY "ddrhook1.use_com4_emu"
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY "ddrhook1.use_15khz"
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED "ddrhook1.usbmem_enabled"
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P1 "ddrhook1.usbmem_path_p1"
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P2 "ddrhook1.usbmem_path_p2"
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE true
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE false
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE false
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED false
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P1 "usbmem_p1"
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P2 "usbmem_p2"
void ddrhook1_config_ddrhook1_init(struct cconfig *config)
{
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE,
"Don't emulate P3IO COM4 and its downstream devices, use the Windows "
"COM4 port instead");
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE,
"SD cabinet mode");
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE,
"Use 15 kHz monitor mode");
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED,
"Enable USB memory data emulation");
cconfig_util_set_str(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P1,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P1,
"Specify path for P1 USB memory data");
cconfig_util_set_str(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P2,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P2,
"Specify path for P2 USB memory data");
}
void ddrhook1_config_ddrhook1_get(
struct ddrhook1_config_ddrhook1 *config_ddrhook1, struct cconfig *config)
const bt_core_config_t *config,
ddrhook1_config_ddrhook1_t *config_ddrhook1)
{
if (!cconfig_util_get_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY,
&config_ddrhook1->use_com4_emu,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE);
}
if (!cconfig_util_get_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY,
&config_ddrhook1->standard_def,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE);
}
if (!cconfig_util_get_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
&config_ddrhook1->use_15khz,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE);
}
if (!cconfig_util_get_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
&config_ddrhook1->usbmem_enabled,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED);
}
if (!cconfig_util_get_str(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P1,
config_ddrhook1->usbmem_path_p1,
sizeof(config_ddrhook1->usbmem_path_p1) - 1,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P1)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P1,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P1);
}
if (!cconfig_util_get_str(
config,
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P2,
config_ddrhook1->usbmem_path_p2,
sizeof(config_ddrhook1->usbmem_path_p2) - 1,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P2)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH_P2,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH_P2);
}
bt_core_config_ext_bool_get(config, "game/use_com4_emu", &config_ddrhook1->use_com4_emu);
bt_core_config_ext_bool_get(config, "game/standard_def", &config_ddrhook1->standard_def);
bt_core_config_ext_bool_get(config, "game/use_15khz", &config_ddrhook1->use_15khz);
bt_core_config_ext_bool_get(config, "game/usbmem/enabled", &config_ddrhook1->usbmem_enabled);
bt_core_config_ext_str_get(config, "game/usbmem/path_p1", config_ddrhook1->usbmem_path_p1, sizeof(config_ddrhook1->usbmem_path_p1));
bt_core_config_ext_str_get(config, "game/usbmem/path_p2", config_ddrhook1->usbmem_path_p2, sizeof(config_ddrhook1->usbmem_path_p2));
}

View File

@@ -3,35 +3,21 @@
#include <windows.h>
#include "cconfig/cconfig.h"
#include <stdbool.h>
/**
* Struct holding configuration values for game-specific items.
*/
struct ddrhook1_config_ddrhook1 {
#include "api/core/config.h"
typedef struct ddrhook1_config_ddrhook1 {
bool use_com4_emu;
bool standard_def;
bool use_15khz;
bool usbmem_enabled;
char usbmem_path_p1[MAX_PATH];
char usbmem_path_p2[MAX_PATH];
};
} ddrhook1_config_ddrhook1_t;
/**
* Initialize a cconfig structure with the basic structure and default values
* of this configuration.
*/
void ddrhook1_config_ddrhook1_init(struct cconfig *config);
/**
* Read the module specific config struct values from the provided cconfig
* struct.
*
* @param config_ddrhook1 Target module specific struct to read configuration
* values to.
* @param config cconfig struct holding the intermediate data to read from.
*/
void ddrhook1_config_ddrhook1_get(
struct ddrhook1_config_ddrhook1 *config_ddrhook1, struct cconfig *config);
const bt_core_config_t *config,
ddrhook1_config_ddrhook1_t *config_ddrhook1);
#endif

View File

@@ -1,145 +1,13 @@
#include <string.h>
#include "cconfig/cconfig-util.h"
#include "core/config-ext.h"
#include "ddrhook1/config-eamuse.h"
#include "iface-core/log.h"
#include "util/net.h"
#define DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
#define DDRHOOK1_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid"
#define DDRHOOK1_CONFIG_EAMUSE_EAMID_KEY "eamuse.eamid"
#define DDRHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE "localhost:80"
#define DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE security_id_default
#define DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN \
sizeof(security_id_default)
#define DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE security_id_default
#define DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN \
sizeof(security_id_default)
const struct net_addr ddrhook1_eamuse_default_server = {
.type = NET_ADDR_TYPE_HOSTNAME,
.hostname.host = "localhost",
.hostname.port = 80,
};
void ddrhook1_config_eamuse_init(struct cconfig *config)
{
cconfig_util_set_str(
config,
DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY,
DDRHOOK1_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,
DDRHOOK1_CONFIG_EAMUSE_PCBID_KEY,
(uint8_t *) &DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE,
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN,
"PCBID");
cconfig_util_set_data(
config,
DDRHOOK1_CONFIG_EAMUSE_EAMID_KEY,
(uint8_t *) &DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE,
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN,
"EAMID");
}
void ddrhook1_config_eamuse_get(
struct ddrhook1_config_eamuse *config_eamuse, struct cconfig *config)
const bt_core_config_t *config,
ddrhook1_config_eamuse_t *config_eamuse)
{
char server_url[1024];
char *tmp;
char *tmp2;
memset(config_eamuse, 0, sizeof(struct ddrhook1_config_eamuse));
if (!cconfig_util_get_str(
config,
DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY,
server_url,
sizeof(server_url),
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY,
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE);
}
if (!net_str_parse(server_url, &config_eamuse->server)) {
memcpy(
&config_eamuse->server,
&ddrhook1_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,
DDRHOOK1_CONFIG_EAMUSE_PCBID_KEY,
(uint8_t *) &config_eamuse->pcbid,
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN,
(uint8_t *) &DDRHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) {
tmp = security_id_to_str(
&DDRHOOK1_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(
&DDRHOOK1_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,
DDRHOOK1_CONFIG_EAMUSE_EAMID_KEY,
(uint8_t *) &config_eamuse->eamid,
DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN,
(uint8_t *) &DDRHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) {
tmp = security_id_to_str(
&DDRHOOK1_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(
&DDRHOOK1_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_eamuse->server);
bt_core_config_ext_security_id_get(config, "eamuse/pcbid", &config_eamuse->pcbid);
bt_core_config_ext_security_id_get(config, "eamuse/eamid", &config_eamuse->eamid);
}

View File

@@ -1,36 +1,20 @@
#ifndef DDRHOOK1_CONFIG_EAMUSE_H
#define DDRHOOK1_CONFIG_EAMUSE_H
#include "cconfig/cconfig.h"
#include "api/core/config.h"
#include "security/id.h"
#include "util/net.h"
/**
* Struct holding configuration values for eamuse related items.
*/
struct ddrhook1_config_eamuse {
typedef struct ddrhook1_config_eamuse {
struct net_addr server;
struct security_id pcbid;
struct security_id eamid;
};
} ddrhook1_config_eamuse_t;
/**
* Initialize a cconfig structure with the basic structure and default values
* of this configuration.
*/
void ddrhook1_config_eamuse_init(struct cconfig *config);
/**
* Read the module specific config struct values from the provided cconfig
* struct.
*
* @param config_eamuse Target module specific struct to read configuration
* values to.
* @param config cconfig struct holding the intermediate data to read from.
*/
void ddrhook1_config_eamuse_get(
struct ddrhook1_config_eamuse *config_eamuse, struct cconfig *config);
const bt_core_config_t *config,
ddrhook1_config_eamuse_t *config_eamuse);
#endif

View File

@@ -1,36 +1,12 @@
#include <string.h>
#include "cconfig/cconfig-util.h"
#include "core/config-ext.h"
#include "ddrhook1/config-gfx.h"
#include "iface-core/log.h"
#define DDRHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
#define DDRHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE true
void ddrhook1_config_gfx_init(struct cconfig *config)
{
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_GFX_WINDOWED_KEY,
DDRHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE,
"Run the game windowed");
}
void ddrhook1_config_gfx_get(
struct ddrhook1_config_gfx *config_gfx, struct cconfig *config)
const bt_core_config_t *config,
ddrhook1_config_gfx_t *config_gfx)
{
if (!cconfig_util_get_bool(
config,
DDRHOOK1_CONFIG_GFX_WINDOWED_KEY,
&config_gfx->windowed,
DDRHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
DDRHOOK1_CONFIG_GFX_WINDOWED_KEY,
DDRHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE);
}
bt_core_config_ext_bool_get(config, "gfx/windowed", &config_gfx->windowed);
}

View File

@@ -1,30 +1,16 @@
#ifndef DDRHOOK1_CONFIG_GFX_H
#define DDRHOOK1_CONFIG_GFX_H
#include "cconfig/cconfig.h"
#include <stdbool.h>
/**
* Struct holding configuration values for GFX related items.
*/
struct ddrhook1_config_gfx {
#include "api/core/config.h"
typedef struct ddrhook1_config_gfx {
bool windowed;
};
} ddrhook1_config_gfx_t;
/**
* Initialize a cconfig structure with the basic structure and default values
* of this configuration.
*/
void ddrhook1_config_gfx_init(struct cconfig *config);
/**
* Read the module specific config struct values from the provided cconfig
* struct.
*
* @param config_gfx Target module specific struct to read configuration
* values to.
* @param config cconfig struct holding the intermediate data to read from.
*/
void ddrhook1_config_gfx_get(
struct ddrhook1_config_gfx *config_gfx, struct cconfig *config);
const bt_core_config_t *config,
ddrhook1_config_gfx_t *config_gfx);
#endif

View File

@@ -1,75 +1,10 @@
#include <string.h>
#include "cconfig/cconfig-util.h"
#include "core/config-ext.h"
#include "ddrhook1/config-security.h"
#include "iface-core/log.h"
#include "security/mcode.h"
#include "util/net.h"
#define DDRHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode"
static const struct security_mcode security_mcode_ddr_x = {
.header = SECURITY_MCODE_HEADER,
.unkn = SECURITY_MCODE_UNKN_Q,
.game = SECURITY_MCODE_GAME_DDR_X,
.region = SECURITY_MCODE_REGION_JAPAN,
.cabinet = SECURITY_MCODE_CABINET_A,
.revision = SECURITY_MCODE_REVISION_A,
};
void ddrhook1_config_security_init(struct cconfig *config)
{
char *tmp;
tmp = security_mcode_to_str(&security_mcode_ddr_x);
cconfig_util_set_str(
config,
DDRHOOK1_CONFIG_SECURITY_MCODE_KEY,
tmp,
"Mcode of the game to run.");
free(tmp);
}
void ddrhook1_config_security_get(
struct ddrhook1_config_security *config_security, struct cconfig *config)
const bt_core_config_t *config,
ddrhook1_config_security_t *config_security)
{
char *tmp_default;
char mcode[9];
tmp_default = security_mcode_to_str(&security_mcode_ddr_x);
if (!cconfig_util_get_str(
config,
DDRHOOK1_CONFIG_SECURITY_MCODE_KEY,
mcode,
sizeof(mcode) - 1,
tmp_default)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
DDRHOOK1_CONFIG_SECURITY_MCODE_KEY,
tmp_default);
}
mcode[8] = '\0';
if (!security_mcode_parse(mcode, &config_security->mcode)) {
log_warning(
"Invalid mcode '%s' specified, fallback to default '%s'",
mcode,
tmp_default);
memcpy(
&config_security->mcode,
&security_mcode_ddr_x,
sizeof(struct security_mcode));
}
free(tmp_default);
}
bt_core_config_ext_security_mcode_get(config, "security/mcode", &config_security->mcode);
}

View File

@@ -1,34 +1,16 @@
#ifndef DDRHOOK1_CONFIG_SECURITY_H
#define DDRHOOK1_CONFIG_SECURITY_H
#include "cconfig/cconfig.h"
#include "api/core/config.h"
#include "security/mcode.h"
#include "util/net.h"
/**
* Struct holding configuration values for security related items.
*/
struct ddrhook1_config_security {
typedef struct ddrhook1_config_security {
struct security_mcode mcode;
};
} ddrhook1_config_security_t;
/**
* Initialize a cconfig structure with the basic structure and default values
* of this configuration.
*/
void ddrhook1_config_security_init(struct cconfig *config);
/**
* Read the module specific config struct values from the provided cconfig
* struct.
*
* @param config_security Target module specific struct to read configuration
* values to.
* @param config cconfig struct holding the intermediate data to read from.
*/
void ddrhook1_config_security_get(
struct ddrhook1_config_security *config_security, struct cconfig *config);
const bt_core_config_t *config,
ddrhook1_config_security_t *config_security);
#endif

View File

@@ -0,0 +1,192 @@
#include <windows.h>
#include <stdbool.h>
#include "ddrhook-util/_com4.h"
#include "ddrhook-util/extio.h"
#include "ddrhook-util/p3io.h"
#include "ddrhook-util/spike.h"
#include "ddrhook-util/usbmem.h"
#include "ddrhook1/avs-boot.h"
#include "ddrhook1/config-ddrhook1.h"
#include "ddrhook1/config-eamuse.h"
#include "ddrhook1/config-gfx.h"
#include "ddrhook1/config-security.h"
#include "ddrhook1/filesystem.h"
#include "ddrhook1/master.h"
#include "ddrhook-util/gfx.h"
#include "hook/iohook.h"
#include "hooklib/rs232.h"
#include "iface-core/config.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "iface-io/ddr.h"
#include "iface-io/eam.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "p3ioemu/emu.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"
bool standard_def;
bool _15khz;
static const hook_d3d9_irp_handler_t ddrhook1_d3d9_handlers[] = {
gfx_d3d9_irp_handler,
};
static module_io_t *_ddrhook1_module_io_ddr;
static module_io_t *_ddrhook1_module_io_eam;
static void _ddrhook1_io_ddr_init(module_io_t **module)
{
bt_io_ddr_api_t api;
module_io_ext_load_and_init(
"ddrio.dll", "bt_module_io_ddr_api_get", module);
module_io_api_get(*module, &api);
bt_io_ddr_api_set(&api);
}
static void _ddrhook1_io_eam_init(module_io_t **module)
{
bt_io_eam_api_t api;
module_io_ext_load_and_init(
"eamio.dll", "bt_module_io_eam_api_get", module);
module_io_api_get(*module, &api);
bt_io_eam_api_set(&api);
}
static bool
_ddrhook1_main_init(HMODULE game_module, const bt_core_config_t *config)
{
bool ok;
ddrhook1_config_ddrhook1_t config_ddrhook1;
ddrhook1_config_eamuse_t config_eamuse;
ddrhook1_config_gfx_t config_gfx;
ddrhook1_config_security_t config_security;
log_info("ddrhook1 for DDR X");
log_info("build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV));
ddrhook1_config_ddrhook1_get(config, &config_ddrhook1);
ddrhook1_config_eamuse_get(config, &config_eamuse);
ddrhook1_config_gfx_get(config, &config_gfx);
ddrhook1_config_security_get(config, &config_security);
standard_def = config_ddrhook1.standard_def;
_15khz = config_ddrhook1.use_15khz;
ddrhook1_master_insert_hooks(NULL);
ddrhook1_filesystem_hook_init();
hook_d3d9_init(
ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers));
ddrhook1_filesystem_hook_init();
ddrhook1_avs_boot_init();
ddrhook1_avs_boot_set_eamuse_addr(&config_eamuse.server);
iohook_push_handler(p3io_emu_dispatch_irp);
iohook_push_handler(extio_dispatch_irp);
iohook_push_handler(spike_dispatch_irp);
iohook_push_handler(usbmem_dispatch_irp);
if (config_ddrhook1.use_com4_emu) {
/* See ddrhook-util/p3io.c for details. */
iohook_push_handler(com4_dispatch_irp);
}
if (config_gfx.windowed) {
gfx_set_windowed();
}
rs232_hook_init();
p3io_ddr_init_with_plugs(
&config_security.mcode,
&config_eamuse.pcbid,
&config_eamuse.eamid,
#if AVS_VERSION >= 1002
&security_rp_sign_key_black_ddrx2,
#else
&security_rp_sign_key_black_ddrx,
#endif
&security_rp_sign_key_white_eamuse);
extio_init();
usbmem_init(
config_ddrhook1.usbmem_path_p1,
config_ddrhook1.usbmem_path_p2,
config_ddrhook1.usbmem_enabled);
spike_init();
com4_init();
log_info("Initializing DDR IO backend");
_ddrhook1_io_ddr_init(&_ddrhook1_module_io_ddr);
ok = bt_io_ddr_init();
if (!ok) {
log_fatal("Couldn't initialize DDR IO backend");
return false;
}
if (config_ddrhook1.use_com4_emu) {
log_info("Initializing card reader backend");
_ddrhook1_io_eam_init(&_ddrhook1_module_io_eam);
ok = bt_io_eam_init();
if (!ok) {
log_fatal("Couldn't initialize card reader backend");
return false;
}
}
return true;
}
static void _ddrhook1_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 = _ddrhook1_main_init;
api->v1.main_fini = _ddrhook1_main_fini;
}

View File

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

View File

@@ -0,0 +1,9 @@
#ifndef DDRHOOK1_H
#define DDRHOOK1_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

@@ -1,230 +1,72 @@
#include <windows.h>
#include <stdbool.h>
#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 "ddrhook-util/_com4.h"
#include "ddrhook-util/extio.h"
#include "ddrhook-util/p3io.h"
#include "ddrhook-util/spike.h"
#include "ddrhook-util/usbmem.h"
#include "ddrhook1/avs-boot.h"
#include "ddrhook1/config-ddrhook1.h"
#include "ddrhook1/config-eamuse.h"
#include "ddrhook1/config-gfx.h"
#include "ddrhook1/config-security.h"
#include "ddrhook1/filesystem.h"
#include "ddrhook1/master.h"
#include "ddrhook-util/gfx.h"
#include "hook/iohook.h"
#include "hook/table.h"
#include "hooklib/rs232.h"
#include "ddrhook1/ddrhook1.h"
#include "iface-core/log.h"
#include "iface-core/thread.h"
#include "main/sdk-hook/dllentry.h"
#include "iface-io/ddr.h"
#include "iface-io/eam.h"
#include "module/io-ext.h"
#include "module/io.h"
#include "p3ioemu/emu.h"
#include "sdk/module/core/log.h"
#include "sdk/module/core/thread.h"
#include "sdk/module/hook.h"
#include "security/rp-sign-key.h"
#include "util/cmdline.h"
#include "util/defs.h"
#define DDRHOOK1_INFO_HEADER \
"ddrhook1 for DDR X" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
#define DDRHOOK1_CMD_USAGE \
"Usage: inject.exe ddrhook1.dll <ddr.exe> [options...]"
static DWORD STDCALL
_ddrhook1_dllmain_my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
static DWORD(STDCALL *_ddrhook1_dllmain_real_GetModuleFileNameA)(
HMODULE hModule, LPSTR lpFilename, DWORD nSize);
bool standard_def;
bool _15khz;
static bool _ddrhook1_dllmain_getmodulefilenamea_call_check;
static const hook_d3d9_irp_handler_t ddrhook1_d3d9_handlers[] = {
gfx_d3d9_irp_handler,
static const struct hook_symbol _ddrhook1_dllmain_hook_syms[] = {
{
.name = "GetModuleFileNameA",
.patch = _ddrhook1_dllmain_my_GetModuleFileNameA,
.link = (void **) &_ddrhook1_dllmain_real_GetModuleFileNameA,
},
};
static module_io_t *_ddrhook1_module_io_ddr;
static module_io_t *_ddrhook1_module_io_eam;
static void _ddrhook1_io_ddr_init(module_io_t **module)
static DWORD STDCALL
_ddrhook1_dllmain_my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
{
bt_io_ddr_api_t api;
if (_ddrhook1_dllmain_getmodulefilenamea_call_check) {
return _ddrhook1_dllmain_real_GetModuleFileNameA(hModule, lpFilename, nSize);
}
module_io_ext_load_and_init(
"ddrio.dll", "bt_module_io_ddr_api_get", module);
module_io_api_get(*module, &api);
bt_io_ddr_api_set(&api);
_ddrhook1_dllmain_getmodulefilenamea_call_check = true;
bt_hook_dllentry_main_init();
return _ddrhook1_dllmain_real_GetModuleFileNameA(hModule, lpFilename, nSize);
}
static void _ddrhook1_io_eam_init(module_io_t **module)
// 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)
{
bt_io_eam_api_t api;
if (reason == DLL_PROCESS_ATTACH) {
bt_hook_dllentry_init(
mod,
"ddrhook1",
bt_module_core_config_api_set,
bt_module_core_log_api_set,
bt_module_core_thread_api_set,
bt_module_hook_api_get);
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);
}
_ddrhook1_dllmain_getmodulefilenamea_call_check = false;
static bool
_ddrhook1_main_init(HMODULE game_module, const bt_core_config_t *config_)
{
bool ok;
struct cconfig *config;
hook_table_apply(
NULL, "kernel32.dll", _ddrhook1_dllmain_hook_syms, lengthof(_ddrhook1_dllmain_hook_syms));
struct ddrhook1_config_ddrhook1 config_ddrhook1;
struct ddrhook1_config_eamuse config_eamuse;
struct ddrhook1_config_gfx config_gfx;
struct ddrhook1_config_security config_security;
} 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", _ddrhook1_dllmain_hook_syms, lengthof(_ddrhook1_dllmain_hook_syms));
ddrhook1_master_insert_hooks(NULL);
ddrhook1_filesystem_hook_init();
// Hacky to have this here, should be close/right after application main exits, see TODO above
bt_hook_dllentry_main_fini();
hook_d3d9_init(
ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers));
log_info("--- Begin ddrhook1 main ---");
config = cconfig_init();
ddrhook1_config_ddrhook1_init(config);
ddrhook1_config_eamuse_init(config);
ddrhook1_config_gfx_init(config);
ddrhook1_config_security_init(config);
if (!cconfig_hook_config_init(
config,
DDRHOOK1_INFO_HEADER "\n" DDRHOOK1_CMD_USAGE,
CCONFIG_CMD_USAGE_OUT_DBG)) {
cconfig_finit(config);
exit(EXIT_FAILURE);
}
ddrhook1_config_ddrhook1_get(&config_ddrhook1, config);
ddrhook1_config_eamuse_get(&config_eamuse, config);
ddrhook1_config_gfx_get(&config_gfx, config);
ddrhook1_config_security_get(&config_security, config);
cconfig_finit(config);
standard_def = config_ddrhook1.standard_def;
_15khz = config_ddrhook1.use_15khz;
log_info(DDRHOOK1_INFO_HEADER);
log_info("Initializing ddrhook1...");
ddrhook1_filesystem_hook_init();
ddrhook1_avs_boot_init();
ddrhook1_avs_boot_set_eamuse_addr(&config_eamuse.server);
iohook_push_handler(p3io_emu_dispatch_irp);
iohook_push_handler(extio_dispatch_irp);
iohook_push_handler(spike_dispatch_irp);
iohook_push_handler(usbmem_dispatch_irp);
if (config_ddrhook1.use_com4_emu) {
/* See ddrhook-util/p3io.c for details. */
iohook_push_handler(com4_dispatch_irp);
}
if (config_gfx.windowed) {
gfx_set_windowed();
}
rs232_hook_init();
p3io_ddr_init_with_plugs(
&config_security.mcode,
&config_eamuse.pcbid,
&config_eamuse.eamid,
#if AVS_VERSION >= 1002
&security_rp_sign_key_black_ddrx2,
#else
&security_rp_sign_key_black_ddrx,
#endif
&security_rp_sign_key_white_eamuse);
extio_init();
usbmem_init(
config_ddrhook1.usbmem_path_p1,
config_ddrhook1.usbmem_path_p2,
config_ddrhook1.usbmem_enabled);
spike_init();
com4_init();
log_info("Initializing DDR IO backend");
_ddrhook1_io_ddr_init(&_ddrhook1_module_io_ddr);
ok = bt_io_ddr_init();
if (!ok) {
log_fatal("Couldn't initialize DDR IO backend");
return false;
}
if (config_ddrhook1.use_com4_emu) {
log_info("Initializing card reader backend");
_ddrhook1_io_eam_init(&_ddrhook1_module_io_eam);
ok = bt_io_eam_init();
if (!ok) {
log_fatal("Couldn't initialize card reader backend");
return false;
bt_hook_dllentry_fini();
}
}
log_info("--- End ddrhook1 main ---");
return true;
}
static void _ddrhook1_main_fini()
{
// TODO cleanup
}
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 = _ddrhook1_main_init;
api->v1.main_fini = _ddrhook1_main_fini;
}
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
{
return TRUE;
}
}