mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2026-04-08 18:25:04 -05:00
Add support for DDR X
This commit is contained in:
parent
537b1fa384
commit
4be866e69e
20
Module.mk
20
Module.mk
|
|
@ -94,6 +94,7 @@ include src/main/config/Module.mk
|
|||
include src/main/d3d9exhook/Module.mk
|
||||
include src/main/ddrhook-util/Module.mk
|
||||
include src/main/ddrhook/Module.mk
|
||||
include src/main/ddrhookx/Module.mk
|
||||
include src/main/ddrio-mm/Module.mk
|
||||
include src/main/ddrio-smx/Module.mk
|
||||
include src/main/ddrio/Module.mk
|
||||
|
|
@ -566,6 +567,25 @@ $(zipdir)/sdvx-hwio-x64.zip: \
|
|||
$(V)echo ... $@
|
||||
$(V)zip -j $@ $^
|
||||
|
||||
$(zipdir)/ddr-11.zip: \
|
||||
build/bin/indep-32/inject.exe \
|
||||
build/bin/avs2_803-32/ddrhookx.dll \
|
||||
build/bin/avs2_803-32/unicorntail.dll \
|
||||
build/bin/indep-32/config.exe \
|
||||
build/bin/indep-32/ddrio.dll \
|
||||
build/bin/indep-32/ddrio-mm.dll \
|
||||
build/bin/indep-32/ddrio-smx.dll \
|
||||
build/bin/indep-32/eamio.dll \
|
||||
build/bin/indep-32/geninput.dll \
|
||||
dist/ddr/config.bat \
|
||||
dist/ddr/gamestart-11.bat \
|
||||
dist/ddr/gamestart-11-us.bat \
|
||||
dist/ddr/ddr-11.conf \
|
||||
dist/ddr/ddr-11-us.conf \
|
||||
| $(zipdir)/
|
||||
$(V)echo ... $@
|
||||
$(V)zip -j $@ $^
|
||||
|
||||
$(zipdir)/ddr-12-to-16.zip: \
|
||||
build/bin/avs2_1508-32/launcher.exe \
|
||||
build/bin/avs2_1508-32/ddrhook.dll \
|
||||
|
|
|
|||
20
dist/ddr/ddr-11-us.conf
vendored
Normal file
20
dist/ddr/ddr-11-us.conf
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# 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
|
||||
|
||||
# Mcode of the game to run.
|
||||
security.mcode=GQHDXUAA
|
||||
|
||||
# Emulate P3IO COM4 and its downstream devices. Uses the Windows COM4 port when disabled.
|
||||
ddrhookx.use_com4_emu=true
|
||||
|
||||
# SD cabinet mode
|
||||
ddrhookx.standard_def=false
|
||||
|
||||
# Run the game windowed
|
||||
gfx.windowed=false
|
||||
20
dist/ddr/ddr-11.conf
vendored
Normal file
20
dist/ddr/ddr-11.conf
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# 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
|
||||
|
||||
# Mcode of the game to run.
|
||||
security.mcode=GQHDXJAA
|
||||
|
||||
# Emulate P3IO COM4 and its downstream devices. Uses the Windows COM4 port when disabled.
|
||||
ddrhookx.use_com4_emu=true
|
||||
|
||||
# SD cabinet mode
|
||||
ddrhookx.standard_def=false
|
||||
|
||||
# Run the game windowed
|
||||
gfx.windowed=false
|
||||
11
dist/ddr/gamestart-11-us.bat
vendored
Normal file
11
dist/ddr/gamestart-11-us.bat
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@echo off
|
||||
|
||||
cd /d %~dp0
|
||||
|
||||
if not exist conf mkdir conf
|
||||
if not exist conf\nvram mkdir conf\nvram
|
||||
if not exist conf\raw mkdir conf\raw
|
||||
|
||||
regsvr32 /s xactengine2_10.dll
|
||||
|
||||
inject ddrhookx.dll DDR.exe --config ddr-11-us.conf %*
|
||||
11
dist/ddr/gamestart-11.bat
vendored
Normal file
11
dist/ddr/gamestart-11.bat
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@echo off
|
||||
|
||||
cd /d %~dp0
|
||||
|
||||
if not exist conf mkdir conf
|
||||
if not exist conf\nvram mkdir conf\nvram
|
||||
if not exist conf\raw mkdir conf\raw
|
||||
|
||||
regsvr32 /s xactengine2_10.dll
|
||||
|
||||
inject ddrhookx.dll DDR.exe --config ddr-11.conf %*
|
||||
|
|
@ -11,3 +11,8 @@ src_ddrhook-util := \
|
|||
guid.c \
|
||||
misc.c \
|
||||
monitor.c \
|
||||
extio.c \
|
||||
_com4.c \
|
||||
usbmem.c \
|
||||
spike.c \
|
||||
p3io.c \
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "bemanitools/ddrio.h"
|
||||
|
||||
#include "ddrhook/_com4.h"
|
||||
#include "ddrhook-util/_com4.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
152
src/main/ddrhook-util/p3io.c
Normal file
152
src/main/ddrhook-util/p3io.c
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bemanitools/ddrio.h"
|
||||
|
||||
#include "ddrhook-util/p3io.h"
|
||||
|
||||
#include "p3ioemu/emu.h"
|
||||
#include "p3ioemu/uart.h"
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
extern bool _15khz;
|
||||
extern bool standard_def;
|
||||
|
||||
static HRESULT p3io_ddr_read_jamma(void *ctx, uint32_t *state);
|
||||
static HRESULT p3io_ddr_set_outputs(void *ctx, uint32_t outputs);
|
||||
static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type);
|
||||
static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq);
|
||||
static HRESULT p3io_ddr_get_roundplug(
|
||||
void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom);
|
||||
|
||||
static const struct p3io_ops p3io_ddr_ops = {
|
||||
.read_jamma = p3io_ddr_read_jamma,
|
||||
.set_outputs = p3io_ddr_set_outputs,
|
||||
.get_cab_type = p3io_ddr_get_cab_type,
|
||||
.get_video_freq = p3io_ddr_get_video_freq,
|
||||
};
|
||||
|
||||
static const struct p3io_ops p3io_ddr_ops_with_plugs = {
|
||||
.read_jamma = p3io_ddr_read_jamma,
|
||||
.set_outputs = p3io_ddr_set_outputs,
|
||||
.get_cab_type = p3io_ddr_get_cab_type,
|
||||
.get_video_freq = p3io_ddr_get_video_freq,
|
||||
.get_roundplug = p3io_ddr_get_roundplug,
|
||||
};
|
||||
|
||||
static struct security_mcode p3io_ddr_mcode;
|
||||
static struct security_id p3io_ddr_pcbid;
|
||||
static struct security_id p3io_ddr_eamid;
|
||||
static struct security_rp_sign_key p3io_black_sign_key;
|
||||
static struct security_rp_sign_key p3io_white_sign_key;
|
||||
|
||||
void p3io_ddr_init(void)
|
||||
{
|
||||
/* COM4 isn't a real COM port, we configure the core P3IO emulator code to
|
||||
generate IRPs addressed to COM4 and then we possibly intercept them in
|
||||
_com4.c (or possibly don't, in which case the communications will be
|
||||
sent to the real COM4 on your system) */
|
||||
|
||||
p3io_uart_set_path(0, L"COM4");
|
||||
p3io_emu_init(&p3io_ddr_ops, NULL);
|
||||
}
|
||||
|
||||
void p3io_ddr_init_with_plugs(
|
||||
const struct security_mcode *mcode,
|
||||
const struct security_id *pcbid,
|
||||
const struct security_id *eamid,
|
||||
const struct security_rp_sign_key *black_sign_key,
|
||||
const struct security_rp_sign_key *white_sign_key)
|
||||
{
|
||||
memcpy(&p3io_ddr_mcode, mcode, sizeof(struct security_mcode));
|
||||
memcpy(&p3io_ddr_pcbid, pcbid, sizeof(struct security_id));
|
||||
memcpy(&p3io_ddr_eamid, eamid, sizeof(struct security_id));
|
||||
memcpy(&p3io_black_sign_key, black_sign_key, sizeof(struct security_rp_sign_key));
|
||||
memcpy(&p3io_white_sign_key, white_sign_key, sizeof(struct security_rp_sign_key));
|
||||
|
||||
/* COM4 isn't a real COM port, we configure the core P3IO emulator code to
|
||||
generate IRPs addressed to COM4 and then we possibly intercept them in
|
||||
_com4.c (or possibly don't, in which case the communications will be
|
||||
sent to the real COM4 on your system) */
|
||||
|
||||
p3io_uart_set_path(0, L"COM4");
|
||||
p3io_emu_init(&p3io_ddr_ops_with_plugs, NULL);
|
||||
}
|
||||
|
||||
void p3io_ddr_fini(void)
|
||||
{
|
||||
p3io_emu_fini();
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_read_jamma(void *ctx, uint32_t *state)
|
||||
{
|
||||
log_assert(state != NULL);
|
||||
|
||||
*state = ddr_io_read_pad();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_set_outputs(void *ctx, uint32_t outputs)
|
||||
{
|
||||
ddr_io_set_lights_p3io(outputs);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type)
|
||||
{
|
||||
if (standard_def) {
|
||||
*type = P3IO_CAB_TYPE_SD;
|
||||
} else {
|
||||
*type = P3IO_CAB_TYPE_HD;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq)
|
||||
{
|
||||
if (_15khz) {
|
||||
*freq = P3IO_VIDEO_FREQ_15KHZ;
|
||||
} else {
|
||||
*freq = P3IO_VIDEO_FREQ_31KHZ;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_get_roundplug(
|
||||
void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom)
|
||||
{
|
||||
struct security_rp3_eeprom eeprom_out;
|
||||
|
||||
if (plug_id == 0) {
|
||||
/* black */
|
||||
memcpy(rom, p3io_ddr_pcbid.id, sizeof(p3io_ddr_pcbid.id));
|
||||
security_rp3_generate_signed_eeprom_data(
|
||||
SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&p3io_black_sign_key,
|
||||
&p3io_ddr_mcode,
|
||||
&p3io_ddr_pcbid,
|
||||
&eeprom_out);
|
||||
} else {
|
||||
/* white */
|
||||
memcpy(rom, p3io_ddr_eamid.id, sizeof(p3io_ddr_eamid.id));
|
||||
security_rp3_generate_signed_eeprom_data(
|
||||
SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&p3io_white_sign_key,
|
||||
&security_mcode_eamuse,
|
||||
&p3io_ddr_eamid,
|
||||
&eeprom_out);
|
||||
}
|
||||
|
||||
memcpy(eeprom, &eeprom_out, sizeof(struct security_rp3_eeprom));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// TODO coinstock
|
||||
23
src/main/ddrhook-util/p3io.h
Normal file
23
src/main/ddrhook-util/p3io.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef DDRHOOK_P3IO_H
|
||||
#define DDRHOOK_P3IO_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "security/rp-sign-key.h"
|
||||
#include "security/rp3.h"
|
||||
|
||||
extern const wchar_t p3io_dev_node_prefix[];
|
||||
extern const wchar_t p3io_dev_node[];
|
||||
|
||||
void p3io_ddr_init(void);
|
||||
void p3io_ddr_init_with_plugs(
|
||||
const struct security_mcode *mcode,
|
||||
const struct security_id *pcbid,
|
||||
const struct security_id *eamid,
|
||||
const struct security_rp_sign_key *black_sign_key,
|
||||
const struct security_rp_sign_key *white_sign_key);
|
||||
void p3io_ddr_fini(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -15,11 +15,6 @@ libs_ddrhook := \
|
|||
ddrio \
|
||||
|
||||
src_ddrhook := \
|
||||
extio.c \
|
||||
dllmain.c \
|
||||
_com4.c \
|
||||
master.c \
|
||||
p3io.c \
|
||||
usbmem.c \
|
||||
spike.c
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@
|
|||
#include "bemanitools/ddrio.h"
|
||||
#include "bemanitools/eamio.h"
|
||||
|
||||
#include "ddrhook-util/_com4.h"
|
||||
#include "ddrhook-util/extio.h"
|
||||
#include "ddrhook-util/gfx.h"
|
||||
#include "ddrhook-util/p3io.h"
|
||||
#include "ddrhook-util/spike.h"
|
||||
#include "ddrhook-util/usbmem.h"
|
||||
|
||||
#include "ddrhook/_com4.h"
|
||||
#include "ddrhook/extio.h"
|
||||
#include "ddrhook/master.h"
|
||||
#include "ddrhook/p3io.h"
|
||||
#include "ddrhook/spike.h"
|
||||
#include "ddrhook/usbmem.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bemanitools/ddrio.h"
|
||||
|
||||
#include "ddrhook/p3io.h"
|
||||
|
||||
#include "p3ioemu/emu.h"
|
||||
#include "p3ioemu/uart.h"
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
extern bool _15khz;
|
||||
extern bool standard_def;
|
||||
|
||||
static HRESULT p3io_ddr_read_jamma(void *ctx, uint32_t *state);
|
||||
static HRESULT p3io_ddr_set_outputs(void *ctx, uint32_t outputs);
|
||||
static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type);
|
||||
static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq);
|
||||
|
||||
static const struct p3io_ops p3io_ddr_ops = {
|
||||
.read_jamma = p3io_ddr_read_jamma,
|
||||
.set_outputs = p3io_ddr_set_outputs,
|
||||
.get_cab_type = p3io_ddr_get_cab_type,
|
||||
.get_video_freq = p3io_ddr_get_video_freq,
|
||||
};
|
||||
|
||||
void p3io_ddr_init(void)
|
||||
{
|
||||
/* COM4 isn't a real COM port, we configure the core P3IO emulator code to
|
||||
generate IRPs addressed to COM4 and then we possibly intercept them in
|
||||
_com4.c (or possibly don't, in which case the communications will be
|
||||
sent to the real COM4 on your system) */
|
||||
|
||||
p3io_uart_set_path(0, L"COM4");
|
||||
p3io_emu_init(&p3io_ddr_ops, NULL);
|
||||
}
|
||||
|
||||
void p3io_ddr_fini(void)
|
||||
{
|
||||
p3io_emu_fini();
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_read_jamma(void *ctx, uint32_t *state)
|
||||
{
|
||||
log_assert(state != NULL);
|
||||
|
||||
*state = ddr_io_read_pad();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_set_outputs(void *ctx, uint32_t outputs)
|
||||
{
|
||||
ddr_io_set_lights_p3io(outputs);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type)
|
||||
{
|
||||
if (standard_def) {
|
||||
*type = P3IO_CAB_TYPE_SD;
|
||||
} else {
|
||||
*type = P3IO_CAB_TYPE_HD;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq)
|
||||
{
|
||||
if (_15khz) {
|
||||
*freq = P3IO_VIDEO_FREQ_15KHZ;
|
||||
} else {
|
||||
*freq = P3IO_VIDEO_FREQ_31KHZ;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// TODO coinstock
|
||||
// TODO round plug
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#ifndef DDRHOOK_P3IO_H
|
||||
#define DDRHOOK_P3IO_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
extern const wchar_t p3io_dev_node_prefix[];
|
||||
extern const wchar_t p3io_dev_node[];
|
||||
|
||||
void p3io_ddr_init(void);
|
||||
void p3io_ddr_fini(void);
|
||||
|
||||
#endif
|
||||
28
src/main/ddrhookx/Module.mk
Normal file
28
src/main/ddrhookx/Module.mk
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
avsdlls += ddrhookx
|
||||
|
||||
deplibs_ddrhookx := \
|
||||
avs \
|
||||
|
||||
libs_ddrhookx := \
|
||||
acioemu \
|
||||
cconfig \
|
||||
ddrhook-util \
|
||||
p3ioemu \
|
||||
p3io \
|
||||
hook \
|
||||
hooklib \
|
||||
util \
|
||||
eamio \
|
||||
ddrio \
|
||||
security \
|
||||
|
||||
src_ddrhookx := \
|
||||
avs-boot.c \
|
||||
dllmain.c \
|
||||
config-ddrhookx.c \
|
||||
config-eamuse.c \
|
||||
config-gfx.c \
|
||||
config-security.c \
|
||||
d3d9.c \
|
||||
master.c \
|
||||
filesystem.c \
|
||||
170
src/main/ddrhookx/avs-boot.c
Normal file
170
src/main/ddrhookx/avs-boot.c
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
#define LOG_MODULE "avs-boot"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hook/iohook.h"
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "imports/avs.h"
|
||||
|
||||
#include "ddrhookx/avs-boot.h"
|
||||
#include "ddrhookx/filesystem.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static void (*real_avs_boot)(
|
||||
struct property_node *config,
|
||||
void *std_heap,
|
||||
size_t sz_std_heap,
|
||||
void *avs_heap,
|
||||
size_t sz_avs_heap,
|
||||
avs_log_writer_t log_writer,
|
||||
void *log_context);
|
||||
static int (*real_ea3_boot)(struct property_node *config);
|
||||
|
||||
static int my_ea3_boot(struct property_node *config);
|
||||
|
||||
static void my_avs_boot(
|
||||
struct property_node *config,
|
||||
void *std_heap,
|
||||
size_t sz_std_heap,
|
||||
void *avs_heap,
|
||||
size_t sz_avs_heap,
|
||||
avs_log_writer_t log_writer,
|
||||
void *log_context);
|
||||
static struct net_addr ddrhookx_avs_boot_eamuse_server_addr;
|
||||
|
||||
static const struct hook_symbol ddrxhook_avs_hook_syms[] = {
|
||||
{.name = "avs_boot",
|
||||
.patch = my_avs_boot,
|
||||
.link = (void **) &real_avs_boot},
|
||||
};
|
||||
|
||||
static const struct hook_symbol ddrhookx_avs_ea3_hook_syms[] = {
|
||||
{.name = "ea3_boot",
|
||||
.patch = my_ea3_boot,
|
||||
.link = (void **) &real_ea3_boot},
|
||||
};
|
||||
|
||||
static void avs_boot_replace_property_str(
|
||||
struct property_node *node, const char *name, const char *val)
|
||||
{
|
||||
struct property_node *tmp;
|
||||
|
||||
tmp = property_search(NULL, node, name);
|
||||
|
||||
if (tmp) {
|
||||
property_node_remove(tmp);
|
||||
}
|
||||
|
||||
tmp = property_node_create(NULL, node, PROPERTY_TYPE_STR, name, val);
|
||||
|
||||
if (tmp) {
|
||||
property_node_datasize(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static void my_avs_boot(
|
||||
struct property_node *config,
|
||||
void *std_heap,
|
||||
size_t sz_std_heap,
|
||||
void *avs_heap,
|
||||
size_t sz_avs_heap,
|
||||
avs_log_writer_t log_writer,
|
||||
void *log_context)
|
||||
{
|
||||
log_info("Called my_avs_boot");
|
||||
|
||||
char nvram_path[MAX_PATH] = {0};
|
||||
char raw_path[MAX_PATH] = {0};
|
||||
|
||||
// Using the full path as part of the AVS paths seems to break on long paths.
|
||||
// So instead, just take the launcher folder relative to the main game directory.
|
||||
char *launcher_folder;
|
||||
get_launcher_path_parts(NULL, &launcher_folder);
|
||||
|
||||
if (launcher_folder) {
|
||||
strcpy(nvram_path, launcher_folder);
|
||||
strcat(nvram_path, "\\");
|
||||
|
||||
strcpy(raw_path, launcher_folder);
|
||||
strcat(raw_path, "\\");
|
||||
|
||||
free(launcher_folder);
|
||||
}
|
||||
|
||||
strcat(nvram_path, "conf\\nvram");
|
||||
strcat(raw_path, "conf\\raw");
|
||||
|
||||
log_misc("avs paths: %s %s\n", nvram_path, raw_path);
|
||||
|
||||
avs_boot_replace_property_str(
|
||||
config, "/fs/nvram/device", nvram_path);
|
||||
avs_boot_replace_property_str(
|
||||
config, "/fs/raw/device", raw_path);
|
||||
|
||||
real_avs_boot(
|
||||
config,
|
||||
std_heap,
|
||||
sz_std_heap,
|
||||
avs_heap,
|
||||
sz_avs_heap,
|
||||
log_writer_debug,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static int my_ea3_boot(struct property_node *config)
|
||||
{
|
||||
char *server_addr;
|
||||
|
||||
log_info("Called my_ea3_boot");
|
||||
|
||||
if (ddrhookx_avs_boot_eamuse_server_addr.type != NET_ADDR_TYPE_INVALID) {
|
||||
log_misc("Injecting network server address");
|
||||
|
||||
server_addr = net_addr_to_str(&ddrhookx_avs_boot_eamuse_server_addr);
|
||||
|
||||
avs_boot_replace_property_str(config, "network/services", server_addr);
|
||||
|
||||
free(server_addr);
|
||||
}
|
||||
|
||||
return real_ea3_boot(config);
|
||||
}
|
||||
|
||||
void ddrhookx_avs_boot_init()
|
||||
{
|
||||
hook_table_apply(
|
||||
NULL,
|
||||
"libavs-win32.dll",
|
||||
ddrxhook_avs_hook_syms,
|
||||
lengthof(ddrxhook_avs_hook_syms));
|
||||
|
||||
hook_table_apply(
|
||||
NULL,
|
||||
"libavs-win32-ea3.dll",
|
||||
ddrhookx_avs_ea3_hook_syms,
|
||||
lengthof(ddrhookx_avs_ea3_hook_syms));
|
||||
|
||||
memset(&ddrhookx_avs_boot_eamuse_server_addr, 0, sizeof(struct net_addr));
|
||||
|
||||
log_info("Inserted avs log hooks");
|
||||
}
|
||||
|
||||
void ddrhookx_avs_boot_set_eamuse_addr(const struct net_addr *server_addr)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = net_addr_to_str(server_addr);
|
||||
log_info("Setting eamuse server: %s", str);
|
||||
free(str);
|
||||
|
||||
memcpy(
|
||||
&ddrhookx_avs_boot_eamuse_server_addr,
|
||||
server_addr,
|
||||
sizeof(struct net_addr));
|
||||
}
|
||||
19
src/main/ddrhookx/avs-boot.h
Normal file
19
src/main/ddrhookx/avs-boot.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef DDRHOOKX_AVS_BOOT_H
|
||||
#define DDRHOOKX_AVS_BOOT_H
|
||||
|
||||
#include "util/net.h"
|
||||
|
||||
/**
|
||||
* Initialize hooking of avs_boot and ea3_boot. This re-enables avs logging
|
||||
* and injects a few important settings.
|
||||
*/
|
||||
void ddrhookx_avs_boot_init();
|
||||
|
||||
/**
|
||||
* Set the target eamuse server address.
|
||||
*
|
||||
* @param server_addr Address to target eamuse server.
|
||||
*/
|
||||
void ddrhookx_avs_boot_set_eamuse_addr(const struct net_addr *server_addr);
|
||||
|
||||
#endif
|
||||
54
src/main/ddrhookx/config-ddrhookx.c
Normal file
54
src/main/ddrhookx/config-ddrhookx.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhookx/config-ddrhookx.h"
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
#define DDRHOOKX_CONFIG_DDRHOOKX_USE_COM4_EMU_KEY "ddrhookx.use_com4_emu"
|
||||
#define DDRHOOKX_CONFIG_DDRHOOKX_STANDARD_DEF_KEY "ddrhookx.standard_def"
|
||||
|
||||
#define DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_USE_COM4_EMU_VALUE true
|
||||
#define DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_STANDARD_DEF_VALUE false
|
||||
|
||||
void ddrhookx_config_ddrhookx_init(struct cconfig *config)
|
||||
{
|
||||
cconfig_util_set_bool(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_USE_COM4_EMU_KEY,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_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,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_STANDARD_DEF_KEY,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_STANDARD_DEF_VALUE,
|
||||
"SD cabinet mode");
|
||||
}
|
||||
|
||||
void ddrhookx_config_ddrhookx_get(
|
||||
struct ddrhookx_config_ddrhookx *config_ddrhookx, struct cconfig *config)
|
||||
{
|
||||
if (!cconfig_util_get_bool(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_USE_COM4_EMU_KEY,
|
||||
&config_ddrhookx->use_com4_emu,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_USE_COM4_EMU_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%d'",
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_USE_COM4_EMU_KEY,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_USE_COM4_EMU_VALUE);
|
||||
}
|
||||
if (!cconfig_util_get_bool(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_STANDARD_DEF_KEY,
|
||||
&config_ddrhookx->standard_def,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_STANDARD_DEF_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%d'",
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_STANDARD_DEF_KEY,
|
||||
DDRHOOKX_CONFIG_DDRHOOKX_DEFAULT_STANDARD_DEF_VALUE);
|
||||
}
|
||||
}
|
||||
31
src/main/ddrhookx/config-ddrhookx.h
Normal file
31
src/main/ddrhookx/config-ddrhookx.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef DDRHOOKX_CONFIG_DDRHOOKX_H
|
||||
#define DDRHOOKX_CONFIG_DDRHOOKX_H
|
||||
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
/**
|
||||
* Struct holding configuration values for game-specific items.
|
||||
*/
|
||||
struct ddrhookx_config_ddrhookx {
|
||||
bool use_com4_emu;
|
||||
bool standard_def;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a cconfig structure with the basic structure and default values
|
||||
* of this configuration.
|
||||
*/
|
||||
void ddrhookx_config_ddrhookx_init(struct cconfig *config);
|
||||
|
||||
/**
|
||||
* Read the module specific config struct values from the provided cconfig
|
||||
* struct.
|
||||
*
|
||||
* @param config_ddrhookx Target module specific struct to read configuration
|
||||
* values to.
|
||||
* @param config cconfig struct holding the intermediate data to read from.
|
||||
*/
|
||||
void ddrhookx_config_ddrhookx_get(
|
||||
struct ddrhookx_config_ddrhookx *config_ddrhookx, struct cconfig *config);
|
||||
|
||||
#endif
|
||||
144
src/main/ddrhookx/config-eamuse.c
Normal file
144
src/main/ddrhookx/config-eamuse.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhookx/config-eamuse.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid"
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_EAMID_KEY "eamuse.eamid"
|
||||
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE "localhost:80"
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE security_id_default
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN \
|
||||
sizeof(security_id_default)
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE security_id_default
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN \
|
||||
sizeof(security_id_default)
|
||||
|
||||
const struct net_addr ddrhookx_eamuse_default_server = {
|
||||
.type = NET_ADDR_TYPE_HOSTNAME,
|
||||
.hostname.host = "localhost",
|
||||
.hostname.port = 80,
|
||||
};
|
||||
|
||||
void ddrhookx_config_eamuse_init(struct cconfig *config)
|
||||
{
|
||||
cconfig_util_set_str(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_EAMUSE_SERVER_KEY,
|
||||
DDRHOOKX_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,
|
||||
DDRHOOKX_CONFIG_EAMUSE_PCBID_KEY,
|
||||
(uint8_t *) &DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE,
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN,
|
||||
"PCBID");
|
||||
|
||||
cconfig_util_set_data(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_EAMUSE_EAMID_KEY,
|
||||
(uint8_t *) &DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE,
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN,
|
||||
"EAMID");
|
||||
}
|
||||
|
||||
void ddrhookx_config_eamuse_get(
|
||||
struct ddrhookx_config_eamuse *config_eamuse, struct cconfig *config)
|
||||
{
|
||||
char server_url[1024];
|
||||
char *tmp;
|
||||
char *tmp2;
|
||||
|
||||
memset(config_eamuse, 0, sizeof(struct ddrhookx_config_eamuse));
|
||||
|
||||
if (!cconfig_util_get_str(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_EAMUSE_SERVER_KEY,
|
||||
server_url,
|
||||
sizeof(server_url),
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%s'",
|
||||
DDRHOOKX_CONFIG_EAMUSE_SERVER_KEY,
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE);
|
||||
}
|
||||
|
||||
if (!net_str_parse(server_url, &config_eamuse->server)) {
|
||||
memcpy(
|
||||
&config_eamuse->server,
|
||||
&ddrhookx_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,
|
||||
DDRHOOKX_CONFIG_EAMUSE_PCBID_KEY,
|
||||
(uint8_t *) &config_eamuse->pcbid,
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN,
|
||||
(uint8_t *) &DDRHOOKX_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) {
|
||||
tmp = security_id_to_str(
|
||||
&DDRHOOKX_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(
|
||||
&DDRHOOKX_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,
|
||||
DDRHOOKX_CONFIG_EAMUSE_EAMID_KEY,
|
||||
(uint8_t *) &config_eamuse->eamid,
|
||||
DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN,
|
||||
(uint8_t *) &DDRHOOKX_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) {
|
||||
tmp = security_id_to_str(
|
||||
&DDRHOOKX_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(
|
||||
&DDRHOOKX_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);
|
||||
}
|
||||
}
|
||||
36
src/main/ddrhookx/config-eamuse.h
Normal file
36
src/main/ddrhookx/config-eamuse.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef DDRHOOKX_CONFIG_EAMUSE_H
|
||||
#define DDRHOOKX_CONFIG_EAMUSE_H
|
||||
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "security/id.h"
|
||||
|
||||
#include "util/net.h"
|
||||
|
||||
/**
|
||||
* Struct holding configuration values for eamuse related items.
|
||||
*/
|
||||
struct ddrhookx_config_eamuse {
|
||||
struct net_addr server;
|
||||
struct security_id pcbid;
|
||||
struct security_id eamid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a cconfig structure with the basic structure and default values
|
||||
* of this configuration.
|
||||
*/
|
||||
void ddrhookx_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 ddrhookx_config_eamuse_get(
|
||||
struct ddrhookx_config_eamuse *config_eamuse, struct cconfig *config);
|
||||
|
||||
#endif
|
||||
36
src/main/ddrhookx/config-gfx.c
Normal file
36
src/main/ddrhookx/config-gfx.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhookx/config-gfx.h"
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
#define DDRHOOKX_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
|
||||
|
||||
#define DDRHOOKX_CONFIG_GFX_DEFAULT_WINDOWED_VALUE true
|
||||
|
||||
void ddrhookx_config_gfx_init(struct cconfig *config)
|
||||
{
|
||||
cconfig_util_set_bool(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_GFX_WINDOWED_KEY,
|
||||
DDRHOOKX_CONFIG_GFX_DEFAULT_WINDOWED_VALUE,
|
||||
"Run the game windowed");
|
||||
}
|
||||
|
||||
void ddrhookx_config_gfx_get(
|
||||
struct ddrhookx_config_gfx *config_gfx, struct cconfig *config)
|
||||
{
|
||||
if (!cconfig_util_get_bool(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_GFX_WINDOWED_KEY,
|
||||
&config_gfx->windowed,
|
||||
DDRHOOKX_CONFIG_GFX_DEFAULT_WINDOWED_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%d'",
|
||||
DDRHOOKX_CONFIG_GFX_WINDOWED_KEY,
|
||||
DDRHOOKX_CONFIG_GFX_DEFAULT_WINDOWED_VALUE);
|
||||
}
|
||||
}
|
||||
30
src/main/ddrhookx/config-gfx.h
Normal file
30
src/main/ddrhookx/config-gfx.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef DDRHOOKX_CONFIG_GFX_H
|
||||
#define DDRHOOKX_CONFIG_GFX_H
|
||||
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
/**
|
||||
* Struct holding configuration values for GFX related items.
|
||||
*/
|
||||
struct ddrhookx_config_gfx {
|
||||
bool windowed;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a cconfig structure with the basic structure and default values
|
||||
* of this configuration.
|
||||
*/
|
||||
void ddrhookx_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 ddrhookx_config_gfx_get(
|
||||
struct ddrhookx_config_gfx *config_gfx, struct cconfig *config);
|
||||
|
||||
#endif
|
||||
75
src/main/ddrhookx/config-security.c
Normal file
75
src/main/ddrhookx/config-security.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhookx/config-security.h"
|
||||
|
||||
#include "security/mcode.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
|
||||
#define DDRHOOKX_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 ddrhookx_config_security_init(struct cconfig *config)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = security_mcode_to_str(&security_mcode_ddr_x);
|
||||
|
||||
cconfig_util_set_str(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_SECURITY_MCODE_KEY,
|
||||
tmp,
|
||||
"Mcode of the game to run.");
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void ddrhookx_config_security_get(
|
||||
struct ddrhookx_config_security *config_security, struct cconfig *config)
|
||||
{
|
||||
char *tmp_default;
|
||||
char mcode[9];
|
||||
|
||||
tmp_default =
|
||||
security_mcode_to_str(&security_mcode_ddr_x);
|
||||
|
||||
if (!cconfig_util_get_str(
|
||||
config,
|
||||
DDRHOOKX_CONFIG_SECURITY_MCODE_KEY,
|
||||
mcode,
|
||||
sizeof(mcode) - 1,
|
||||
tmp_default)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%s'",
|
||||
DDRHOOKX_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);
|
||||
}
|
||||
34
src/main/ddrhookx/config-security.h
Normal file
34
src/main/ddrhookx/config-security.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef DDRHOOKX_CONFIG_SECURITY_H
|
||||
#define DDRHOOKX_CONFIG_SECURITY_H
|
||||
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "security/mcode.h"
|
||||
|
||||
#include "util/net.h"
|
||||
|
||||
/**
|
||||
* Struct holding configuration values for security related items.
|
||||
*/
|
||||
struct ddrhookx_config_security {
|
||||
struct security_mcode mcode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a cconfig structure with the basic structure and default values
|
||||
* of this configuration.
|
||||
*/
|
||||
void ddrhookx_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 ddrhookx_config_security_get(
|
||||
struct ddrhookx_config_security *config_security, struct cconfig *config);
|
||||
|
||||
#endif
|
||||
281
src/main/ddrhookx/d3d9.c
Normal file
281
src/main/ddrhookx/d3d9.c
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
// TODO: Fix gray arrows on NVIDIA cards (also applies to X3)
|
||||
|
||||
#define LOG_MODULE "d3d9-hook"
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9core.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hook/com-proxy.h"
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "ddrhookx/d3d9.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str.h"
|
||||
#include "util/time.h"
|
||||
|
||||
static LONG(STDCALL *real_ChangeDisplaySettingsExA)(
|
||||
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
|
||||
static LONG(STDCALL *real_SetWindowLongW)(
|
||||
HWND hWnd, int nIndex, LONG dwNewLong);
|
||||
static BOOL(STDCALL *real_SetWindowPos)(
|
||||
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
|
||||
|
||||
static LONG STDCALL my_ChangeDisplaySettingsExA(
|
||||
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
|
||||
static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
|
||||
static BOOL STDCALL my_SetWindowPos(
|
||||
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
|
||||
|
||||
static struct ddrhookx_d3d9_config ddrhookx_d3d9_config;
|
||||
|
||||
static const struct hook_symbol misc_user32_syms[] = {
|
||||
{
|
||||
.name = "ChangeDisplaySettingsExA",
|
||||
.patch = my_ChangeDisplaySettingsExA,
|
||||
.link = (void **) &real_ChangeDisplaySettingsExA,
|
||||
},
|
||||
{
|
||||
.name = "SetWindowLongW",
|
||||
.patch = my_SetWindowLongW,
|
||||
.link = (void **) &real_SetWindowLongW,
|
||||
},
|
||||
{
|
||||
.name = "SetWindowPos",
|
||||
.patch = my_SetWindowPos,
|
||||
.link = (void **) &real_SetWindowPos,
|
||||
},
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static void ddrhookx_d3d9_calc_win_size_with_framed(
|
||||
HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, LPWINDOWPOS wp)
|
||||
{
|
||||
/* taken from dxwnd */
|
||||
RECT rect;
|
||||
DWORD style;
|
||||
int max_x, max_y;
|
||||
HMENU menu;
|
||||
|
||||
rect.left = x;
|
||||
rect.top = y;
|
||||
max_x = width;
|
||||
max_y = height;
|
||||
rect.right = x + max_x;
|
||||
rect.bottom = y + max_y;
|
||||
|
||||
style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
menu = GetMenu(hwnd);
|
||||
AdjustWindowRect(&rect, style, (menu != NULL));
|
||||
|
||||
/* shift down-right so that the border is visible
|
||||
and also update the iPosX,iPosY upper-left coordinates
|
||||
of the client area */
|
||||
|
||||
if (rect.left < 0) {
|
||||
rect.right -= rect.left;
|
||||
rect.left = 0;
|
||||
}
|
||||
|
||||
if (rect.top < 0) {
|
||||
rect.bottom -= rect.top;
|
||||
rect.top = 0;
|
||||
}
|
||||
|
||||
wp->x = rect.left;
|
||||
wp->y = rect.top;
|
||||
wp->cx = rect.right - rect.left;
|
||||
wp->cy = rect.bottom - rect.top;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong)
|
||||
{
|
||||
if (ddrhookx_d3d9_config.windowed && nIndex == GWL_STYLE) {
|
||||
dwNewLong |= WS_OVERLAPPEDWINDOW;
|
||||
}
|
||||
|
||||
return real_SetWindowLongW(hWnd, nIndex, dwNewLong);
|
||||
}
|
||||
|
||||
static BOOL STDCALL my_SetWindowPos(
|
||||
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
|
||||
{
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
WINDOWPOS wp;
|
||||
|
||||
ddrhookx_d3d9_calc_win_size_with_framed(hWnd, X, Y, cx, cy, &wp);
|
||||
|
||||
return real_SetWindowPos(
|
||||
hWnd, hWndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, uFlags);
|
||||
}
|
||||
|
||||
return real_SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
|
||||
}
|
||||
|
||||
static LONG STDCALL my_ChangeDisplaySettingsExA(
|
||||
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param)
|
||||
{
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
return DISP_CHANGE_SUCCESSFUL;
|
||||
}
|
||||
|
||||
return real_ChangeDisplaySettingsExA(
|
||||
dev_name, dev_mode, hwnd, flags, param);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
ddrhookx_d3d9_log_config(const struct ddrhookx_d3d9_config *config)
|
||||
{
|
||||
log_misc(
|
||||
"ddrhookx_d3d9_config\n"
|
||||
"windowed: %d\n",
|
||||
config->windowed);
|
||||
}
|
||||
|
||||
void ddrhookx_d3d9_init_config(struct ddrhookx_d3d9_config *config)
|
||||
{
|
||||
config->windowed = false;
|
||||
}
|
||||
|
||||
void ddrhookx_d3d9_hook_init()
|
||||
{
|
||||
ddrhookx_d3d9_init_config(&ddrhookx_d3d9_config);
|
||||
|
||||
hook_table_apply(
|
||||
NULL, "user32.dll", misc_user32_syms, lengthof(misc_user32_syms));
|
||||
|
||||
log_info("Initialized d3d9 hooks");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void ddrhookx_d3d9_configure(
|
||||
const struct ddrhookx_d3d9_config *config)
|
||||
{
|
||||
log_assert(config);
|
||||
|
||||
ddrhookx_d3d9_log_config(config);
|
||||
|
||||
memcpy(
|
||||
&ddrhookx_d3d9_config,
|
||||
config,
|
||||
sizeof(struct ddrhookx_d3d9_config));
|
||||
}
|
||||
|
||||
static void ddrhookx_d3d9_patch_window(struct hook_d3d9_irp *irp)
|
||||
{
|
||||
log_assert(irp);
|
||||
log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX);
|
||||
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
/* use a different style */
|
||||
irp->args.create_window_ex.style |= WS_OVERLAPPEDWINDOW;
|
||||
|
||||
/* also show mouse cursor */
|
||||
ShowCursor(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ddrhookx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp)
|
||||
{
|
||||
log_assert(irp);
|
||||
log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX);
|
||||
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
/* we have to adjust the window size, because the window needs to be a
|
||||
slightly bigger than the rendering resolution (window caption and
|
||||
stuff is included in the window size) */
|
||||
WINDOWPOS wp;
|
||||
|
||||
ddrhookx_d3d9_calc_win_size_with_framed(
|
||||
irp->args.create_window_ex.result,
|
||||
irp->args.create_window_ex.x,
|
||||
irp->args.create_window_ex.y,
|
||||
irp->args.create_window_ex.width,
|
||||
irp->args.create_window_ex.height,
|
||||
&wp);
|
||||
|
||||
SetWindowPos(
|
||||
irp->args.create_window_ex.result, 0, wp.x, wp.y, wp.cx, wp.cy, 0);
|
||||
|
||||
irp->args.create_window_ex.x = wp.x;
|
||||
irp->args.create_window_ex.y = wp.y;
|
||||
irp->args.create_window_ex.width = wp.cx;
|
||||
irp->args.create_window_ex.height = wp.cy;
|
||||
}
|
||||
}
|
||||
|
||||
static void ddrhookx_d3d9_create_device_apply_window_mode(
|
||||
struct hook_d3d9_irp *irp)
|
||||
{
|
||||
log_assert(irp);
|
||||
log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE);
|
||||
D3DPRESENT_PARAMETERS *pp = irp->args.ctx_create_device.pp;
|
||||
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
pp->Windowed = TRUE;
|
||||
pp->FullScreen_RefreshRateInHz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ddrhookx_d3d9_reset_apply_window_mode(
|
||||
struct hook_d3d9_irp *irp)
|
||||
{
|
||||
log_assert(irp);
|
||||
log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_RESET);
|
||||
D3DPRESENT_PARAMETERS *pp = irp->args.dev_reset.pp;
|
||||
|
||||
if (ddrhookx_d3d9_config.windowed) {
|
||||
pp->Windowed = TRUE;
|
||||
pp->FullScreen_RefreshRateInHz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT
|
||||
ddrhookx_d3d9_irp_handler(struct hook_d3d9_irp *irp)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
log_assert(irp);
|
||||
|
||||
switch (irp->op) {
|
||||
case HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX:
|
||||
ddrhookx_d3d9_patch_window(irp);
|
||||
|
||||
hr = hook_d3d9_irp_invoke_next(irp);
|
||||
|
||||
if (hr == S_OK) {
|
||||
ddrhookx_d3d9_fix_window_size_and_pos(irp);
|
||||
}
|
||||
|
||||
return hr;
|
||||
|
||||
case HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE:
|
||||
ddrhookx_d3d9_create_device_apply_window_mode(irp);
|
||||
hr = hook_d3d9_irp_invoke_next(irp);
|
||||
return hr;
|
||||
|
||||
case HOOK_D3D9_IRP_OP_DEV_RESET:
|
||||
ddrhookx_d3d9_reset_apply_window_mode(irp);
|
||||
hr = hook_d3d9_irp_invoke_next(irp);
|
||||
return hr;
|
||||
|
||||
default:
|
||||
return hook_d3d9_irp_invoke_next(irp);
|
||||
}
|
||||
|
||||
log_fatal("Illegal state");
|
||||
}
|
||||
18
src/main/ddrhookx/d3d9.h
Normal file
18
src/main/ddrhookx/d3d9.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef DDRHOOKX_D3D9_H
|
||||
#define DDRHOOKX_D3D9_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hook/d3d9.h"
|
||||
|
||||
struct ddrhookx_d3d9_config {
|
||||
bool windowed;
|
||||
};
|
||||
|
||||
void ddrhookx_d3d9_hook_init();
|
||||
void ddrhookx_d3d9_configure(
|
||||
const struct ddrhookx_d3d9_config *config);
|
||||
HRESULT ddrhookx_d3d9_irp_handler(struct hook_d3d9_irp *irp);
|
||||
|
||||
#endif
|
||||
4
src/main/ddrhookx/ddrhookx.def
Normal file
4
src/main/ddrhookx/ddrhookx.def
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
LIBRARY ddrhookx
|
||||
|
||||
EXPORTS
|
||||
DllMain@12 @1 NONAME
|
||||
197
src/main/ddrhookx/dllmain.c
Normal file
197
src/main/ddrhookx/dllmain.c
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "bemanitools/ddrio.h"
|
||||
#include "bemanitools/eamio.h"
|
||||
|
||||
#include "cconfig/cconfig-hook.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 "ddrhookx/avs-boot.h"
|
||||
#include "ddrhookx/config-ddrhookx.h"
|
||||
#include "ddrhookx/config-eamuse.h"
|
||||
#include "ddrhookx/config-gfx.h"
|
||||
#include "ddrhookx/config-security.h"
|
||||
#include "ddrhookx/d3d9.h"
|
||||
#include "ddrhookx/filesystem.h"
|
||||
#include "ddrhookx/master.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "hooklib/app.h"
|
||||
#include "hooklib/rs232.h"
|
||||
|
||||
#include "imports/avs.h"
|
||||
|
||||
#include "p3ioemu/emu.h"
|
||||
|
||||
#include "security/rp-sign-key.h"
|
||||
|
||||
#include "util/cmdline.h"
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
#define DDRHOOKX_INFO_HEADER \
|
||||
"ddrhookx for DDR X" \
|
||||
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
|
||||
#define DDRHOOKX_CMD_USAGE \
|
||||
"Usage: inject.exe ddrhookx.dll <ddr.exe> [options...]"
|
||||
|
||||
bool standard_def;
|
||||
bool _15khz;
|
||||
|
||||
static const hook_d3d9_irp_handler_t ddrhookx_d3d9_handlers[] = {
|
||||
ddrhookx_d3d9_irp_handler,
|
||||
};
|
||||
|
||||
static DWORD STDCALL my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
static DWORD(STDCALL *real_GetModuleFileNameA)(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
|
||||
static bool ddrhookx_init_check = false;
|
||||
|
||||
static const struct hook_symbol init_hook_syms[] = {
|
||||
{
|
||||
.name = "GetModuleFileNameA",
|
||||
.patch = my_GetModuleFileNameA,
|
||||
.link = (void **) &real_GetModuleFileNameA,
|
||||
},
|
||||
};
|
||||
|
||||
static void ddrhookx_setup_d3d9_hooks(
|
||||
const struct ddrhookx_config_gfx *config_gfx)
|
||||
{
|
||||
struct ddrhookx_d3d9_config d3d9_config;
|
||||
|
||||
d3d9_config.windowed = config_gfx->windowed;
|
||||
|
||||
ddrhookx_d3d9_configure(&d3d9_config);
|
||||
|
||||
hook_d3d9_init(ddrhookx_d3d9_handlers, lengthof(ddrhookx_d3d9_handlers));
|
||||
}
|
||||
|
||||
static DWORD STDCALL
|
||||
my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
{
|
||||
bool ok;
|
||||
struct cconfig *config;
|
||||
|
||||
struct ddrhookx_config_ddrhookx config_ddrhookx;
|
||||
struct ddrhookx_config_eamuse config_eamuse;
|
||||
struct ddrhookx_config_gfx config_gfx;
|
||||
struct ddrhookx_config_security config_security;
|
||||
|
||||
if (ddrhookx_init_check)
|
||||
goto skip;
|
||||
|
||||
log_info("--- Begin ddrhookx GetModuleFileNameA ---");
|
||||
|
||||
ddrhookx_init_check = true;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
ddrhookx_config_ddrhookx_init(config);
|
||||
ddrhookx_config_eamuse_init(config);
|
||||
ddrhookx_config_gfx_init(config);
|
||||
ddrhookx_config_security_init(config);
|
||||
|
||||
if (!cconfig_hook_config_init(
|
||||
config,
|
||||
DDRHOOKX_INFO_HEADER "\n" DDRHOOKX_CMD_USAGE,
|
||||
CCONFIG_CMD_USAGE_OUT_DBG)) {
|
||||
cconfig_finit(config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ddrhookx_config_ddrhookx_get(&config_ddrhookx, config);
|
||||
ddrhookx_config_eamuse_get(&config_eamuse, config);
|
||||
ddrhookx_config_gfx_get(&config_gfx, config);
|
||||
ddrhookx_config_security_get(&config_security, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
standard_def = config_ddrhookx.standard_def;
|
||||
|
||||
log_info(DDRHOOKX_INFO_HEADER);
|
||||
log_info("Initializing ddrhookx...");
|
||||
|
||||
ddrhookx_avs_boot_init();
|
||||
ddrhookx_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_ddrhookx.use_com4_emu) {
|
||||
/* See ddrhook/p3io.c for details. */
|
||||
iohook_push_handler(com4_dispatch_irp);
|
||||
}
|
||||
|
||||
ddrhookx_setup_d3d9_hooks(&config_gfx);
|
||||
|
||||
rs232_hook_init();
|
||||
|
||||
p3io_ddr_init_with_plugs(
|
||||
&config_security.mcode,
|
||||
&config_eamuse.pcbid,
|
||||
&config_eamuse.eamid,
|
||||
&security_rp_sign_key_black_ddrx,
|
||||
&security_rp_sign_key_white_eamuse);
|
||||
extio_init();
|
||||
usbmem_init();
|
||||
spike_init();
|
||||
com4_init();
|
||||
|
||||
log_info("Initializing DDR IO backend");
|
||||
|
||||
ok = ddr_io_init(thread_create, thread_join, thread_destroy);
|
||||
|
||||
if (!ok) {
|
||||
log_fatal("Couldn't initialize DDR IO backend");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config_ddrhookx.use_com4_emu) {
|
||||
log_info("Initializing card reader backend");
|
||||
|
||||
eam_io_set_loggers(
|
||||
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
|
||||
|
||||
ok = eam_io_init(thread_create, thread_join, thread_destroy);
|
||||
|
||||
if (!ok) {
|
||||
log_fatal("Couldn't initialize card reader backend");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
log_info("--- End ddrhookx GetModuleFileNameA ---");
|
||||
|
||||
skip:
|
||||
return real_GetModuleFileNameA(hModule, lpFilename, nSize);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
log_to_writer(log_writer_debug, NULL);
|
||||
|
||||
hook_table_apply(
|
||||
NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms));
|
||||
|
||||
master_insert_hooks(NULL);
|
||||
filesystem_hook_init();
|
||||
|
||||
ddrhookx_d3d9_hook_init();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
115
src/main/ddrhookx/filesystem.c
Normal file
115
src/main/ddrhookx/filesystem.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
static BOOL STDCALL my_SetCurrentDirectoryA(LPCTSTR lpPathName);
|
||||
static BOOL(STDCALL *real_SetCurrentDirectoryA)(LPCTSTR lpPathName);
|
||||
|
||||
static const struct hook_symbol filesystem_hook_syms[] = {
|
||||
{
|
||||
.name = "SetCurrentDirectoryA",
|
||||
.patch = my_SetCurrentDirectoryA,
|
||||
.link = (void **) &real_SetCurrentDirectoryA,
|
||||
},
|
||||
};
|
||||
|
||||
void get_launcher_path_parts(char **output_path, char **output_foldername) {
|
||||
// DDR sets the current directory on boot to "D:/HDX" and then uses
|
||||
// relative file paths for everything else.
|
||||
// This function is a helper function to make it easier to turn a path
|
||||
// into an absolute path relative to the launcher ("D:/HDX/ddr_datecode")
|
||||
// and not the current working directory ("D:/HDX") so that settings
|
||||
// can be saved in the same manner as every other game.
|
||||
char module_path[MAX_PATH];
|
||||
char launcher_path[MAX_PATH];
|
||||
|
||||
memset(launcher_path, 0, MAX_PATH);
|
||||
|
||||
if (output_path != NULL)
|
||||
*output_path = NULL;
|
||||
|
||||
if (output_foldername != NULL)
|
||||
*output_foldername = NULL;
|
||||
|
||||
if (GetModuleFileNameA(NULL, module_path, MAX_PATH) == 0)
|
||||
return;
|
||||
|
||||
char *filename_ptr = NULL;
|
||||
if (GetFullPathNameA(module_path, MAX_PATH, launcher_path, &filename_ptr) == 0)
|
||||
return;
|
||||
|
||||
if (filename_ptr != NULL)
|
||||
launcher_path[strlen(launcher_path) - strlen(filename_ptr) - 1] = 0;
|
||||
|
||||
// Trim tailing slashes
|
||||
for (int i = strlen(launcher_path) - 1; i > 0; i--) {
|
||||
if (launcher_path[i] != '\\' && launcher_path[i] != '/')
|
||||
break;
|
||||
|
||||
launcher_path[i] = 0;
|
||||
}
|
||||
|
||||
int idx_folder = 0;
|
||||
for (idx_folder = strlen(launcher_path); idx_folder - 1 > 0; idx_folder--) {
|
||||
if (launcher_path[idx_folder - 1] == '\\' || launcher_path[idx_folder - 1] == '/') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (output_foldername != NULL) {
|
||||
int len = strlen(launcher_path) - idx_folder;
|
||||
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
|
||||
*output_foldername = (char*)xmalloc(len + 1);
|
||||
memset(*output_foldername, 0, len + 1);
|
||||
strncpy(*output_foldername, launcher_path + idx_folder, len);
|
||||
}
|
||||
|
||||
if (output_path != NULL) {
|
||||
size_t len = idx_folder - 1 < 0 ? 0 : idx_folder - 1;
|
||||
|
||||
if (len > strlen(launcher_path))
|
||||
len = strlen(launcher_path);
|
||||
|
||||
*output_path = (char*)xmalloc(len + 1);
|
||||
memset(*output_path, 0, len + 1);
|
||||
strncpy(*output_path, launcher_path, len);
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL STDCALL my_SetCurrentDirectoryA(LPCTSTR lpPathName)
|
||||
{
|
||||
if (stricmp(lpPathName, "D:/HDX") == 0
|
||||
|| stricmp(lpPathName, "D:\\HDX") == 0) {
|
||||
char *new_path;
|
||||
get_launcher_path_parts(&new_path, NULL);
|
||||
|
||||
if (new_path != NULL) {
|
||||
bool r = real_SetCurrentDirectoryA(new_path);
|
||||
log_misc("Changed directory %s -> %s", lpPathName, new_path);
|
||||
free(new_path);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return real_SetCurrentDirectoryA(lpPathName);
|
||||
}
|
||||
|
||||
void filesystem_hook_init()
|
||||
{
|
||||
hook_table_apply(
|
||||
NULL, "kernel32.dll", filesystem_hook_syms, lengthof(filesystem_hook_syms));
|
||||
|
||||
log_info("Inserted filesystem hooks");
|
||||
}
|
||||
8
src/main/ddrhookx/filesystem.h
Normal file
8
src/main/ddrhookx/filesystem.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef DDRHOOKX_FILESYSTEM_H
|
||||
#define DDRHOOKX_FILESYSTEM_H
|
||||
|
||||
char *get_launcher_path_parts();
|
||||
|
||||
void filesystem_hook_init();
|
||||
|
||||
#endif
|
||||
66
src/main/ddrhookx/master.c
Normal file
66
src/main/ddrhookx/master.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "ddrhookx/master.h"
|
||||
|
||||
#include "ddrhook-util/dinput.h"
|
||||
#include "ddrhook-util/monitor.h"
|
||||
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "p3ioemu/devmgr.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
|
||||
static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
|
||||
|
||||
static HMODULE STDCALL my_LoadLibraryA(const char *name);
|
||||
|
||||
static const struct hook_symbol master_kernel32_syms[] = {
|
||||
{
|
||||
.name = "LoadLibraryA",
|
||||
.patch = my_LoadLibraryA,
|
||||
.link = (void **) &real_LoadLibraryA,
|
||||
},
|
||||
};
|
||||
|
||||
static HMODULE STDCALL my_LoadLibraryA(const char *name)
|
||||
{
|
||||
HMODULE result;
|
||||
|
||||
result = GetModuleHandleA(name);
|
||||
|
||||
if (result != NULL) {
|
||||
log_misc("LoadLibraryA(%s) -> %p [already loaded]", name, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
result = real_LoadLibraryA(name);
|
||||
log_misc("LoadLibraryA(%s) -> %p [newly loaded]", name, result);
|
||||
|
||||
if (result == NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
master_insert_hooks(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void master_insert_hooks(HMODULE target)
|
||||
{
|
||||
/* Insert all other hooks here */
|
||||
|
||||
p3io_setupapi_insert_hooks(target);
|
||||
monitor_setupapi_insert_hooks(target);
|
||||
dinput_init(target);
|
||||
|
||||
/* Insert dynamic loader hooks so that we can hook late-loaded modules */
|
||||
|
||||
hook_table_apply(
|
||||
target,
|
||||
"kernel32.dll",
|
||||
master_kernel32_syms,
|
||||
lengthof(master_kernel32_syms));
|
||||
|
||||
log_info("Inserted dynamic loader hooks into %p", target);
|
||||
}
|
||||
8
src/main/ddrhookx/master.h
Normal file
8
src/main/ddrhookx/master.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef DDRHOOK_MASTER_H
|
||||
#define DDRHOOK_MASTER_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void master_insert_hooks(HMODULE target);
|
||||
|
||||
#endif
|
||||
|
|
@ -71,6 +71,10 @@ static HRESULT(STDCALL *real_DrawPrimitiveUP)(
|
|||
const void *data,
|
||||
UINT stride);
|
||||
|
||||
static HRESULT(STDCALL *real_Reset)(
|
||||
IDirect3DDevice9 *self,
|
||||
D3DPRESENT_PARAMETERS *pp);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -136,6 +140,10 @@ static HRESULT STDCALL my_DrawPrimitiveUP(
|
|||
const void *data,
|
||||
UINT stride);
|
||||
|
||||
static HRESULT STDCALL my_Reset(
|
||||
IDirect3DDevice9 *self,
|
||||
D3DPRESENT_PARAMETERS *pp);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -194,6 +202,9 @@ hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp);
|
|||
static HRESULT
|
||||
hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp);
|
||||
|
||||
static HRESULT
|
||||
hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -218,6 +229,8 @@ static const hook_d3d9_irp_handler_t hook_d3d9_irp_real_handlers[] = {
|
|||
hook_d3d9_irp_handler_real_dev_set_render_state,
|
||||
[HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP] =
|
||||
hook_d3d9_irp_handler_real_dev_draw_primitive_up,
|
||||
[HOOK_D3D9_IRP_OP_DEV_RESET] =
|
||||
hook_d3d9_irp_handler_real_dev_reset,
|
||||
};
|
||||
|
||||
static const hook_d3d9_irp_handler_t *hook_d3d9_handlers;
|
||||
|
|
@ -488,6 +501,24 @@ static HRESULT STDCALL my_DrawPrimitiveUP(
|
|||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT STDCALL my_Reset(
|
||||
IDirect3DDevice9 *self,
|
||||
D3DPRESENT_PARAMETERS *pp)
|
||||
{
|
||||
struct hook_d3d9_irp irp;
|
||||
HRESULT hr;
|
||||
|
||||
memset(&irp, 0, sizeof(irp));
|
||||
|
||||
irp.op = HOOK_D3D9_IRP_OP_DEV_RESET;
|
||||
irp.args.dev_reset.self = self;
|
||||
irp.args.dev_reset.pp = pp;
|
||||
|
||||
hr = hook_d3d9_irp_invoke_next(&irp);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -528,7 +559,7 @@ static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp *irp)
|
|||
}
|
||||
|
||||
res = com_proxy_wrap(&api_proxy, api, sizeof(*api->lpVtbl));
|
||||
|
||||
|
||||
if (res != S_OK) {
|
||||
log_fatal("Wrapping com proxy failed: %08lx", res);
|
||||
}
|
||||
|
|
@ -657,6 +688,9 @@ hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp *irp)
|
|||
real_DrawPrimitiveUP = api_vtbl->DrawPrimitiveUP;
|
||||
api_vtbl->DrawPrimitiveUP = my_DrawPrimitiveUP;
|
||||
|
||||
real_Reset = api_vtbl->Reset;
|
||||
api_vtbl->Reset = my_Reset;
|
||||
|
||||
*irp->args.ctx_create_device.pdev = (IDirect3DDevice9 *) api_proxy;
|
||||
|
||||
return hr;
|
||||
|
|
@ -731,6 +765,16 @@ hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp)
|
|||
irp->args.dev_draw_primitive_up.stride);
|
||||
}
|
||||
|
||||
static HRESULT
|
||||
hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp)
|
||||
{
|
||||
log_assert(irp);
|
||||
|
||||
return real_Reset(
|
||||
irp->args.dev_reset.self,
|
||||
irp->args.dev_reset.pp);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ enum hook_d3d9_irp_op {
|
|||
HOOK_D3D9_IRP_OP_DEV_PRESENT = 9,
|
||||
HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE = 10,
|
||||
HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP = 11,
|
||||
HOOK_D3D9_IRP_OP_DEV_RESET = 12,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -161,6 +162,14 @@ struct hook_d3d9_irp {
|
|||
const void *data;
|
||||
UINT stride;
|
||||
} dev_draw_primitive_up;
|
||||
|
||||
/**
|
||||
* Params of IDirect3DDevice9_Reset.
|
||||
*/
|
||||
struct {
|
||||
IDirect3DDevice9 *self;
|
||||
D3DPRESENT_PARAMETERS *pp;
|
||||
} dev_reset;
|
||||
} args;
|
||||
|
||||
size_t next_handler;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ const struct security_rp_sign_key security_rp_sign_key_black_gfdmv8 = {
|
|||
const struct security_rp_sign_key security_rp_sign_key_black_ddrx = {
|
||||
.data = "573PROJE"};
|
||||
|
||||
const struct security_rp_sign_key security_rp_sign_key_black_ddrx2 = {
|
||||
.data = "BMPDDRAC"};
|
||||
|
||||
const struct security_rp_sign_key security_rp_sign_key_black_iidx = {
|
||||
.data = "2DXGLDAC"};
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@ extern const struct security_rp_sign_key security_rp_sign_key_black_gfdmv8;
|
|||
*/
|
||||
extern const struct security_rp_sign_key security_rp_sign_key_black_ddrx;
|
||||
|
||||
/**
|
||||
* Signing key used to create eeprom signatures for all black dongles used
|
||||
* on the following games:
|
||||
*
|
||||
* - DDR X2 and beyond
|
||||
*/
|
||||
extern const struct security_rp_sign_key security_rp_sign_key_black_ddrx2;
|
||||
|
||||
/**
|
||||
* Signing key used to create eeprom signatures for all black dongles used
|
||||
* on the following games:
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "ddrhook/p3io.h"
|
||||
#include "ddrhook/usbmem.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "hooklib/app.h"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user