233 lines
6.1 KiB
C
233 lines
6.1 KiB
C
#include <windows.h>
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "cconfig/cconfig-hook.h"
|
|
|
|
#include "ezusb-iidx-emu/nodes.h"
|
|
|
|
#include "ezusb2-emu/desc.h"
|
|
#include "ezusb2-emu/device.h"
|
|
|
|
#include "ezusb2-iidx-emu/msg.h"
|
|
|
|
#include "hook/d3d9.h"
|
|
|
|
#include "hooklib/acp.h"
|
|
#include "hooklib/adapter.h"
|
|
#include "hooklib/rs232.h"
|
|
#include "hooklib/setupapi.h"
|
|
|
|
#include "iface-core/log.h"
|
|
#include "iface-core/thread.h"
|
|
|
|
#include "iface-io/eam.h"
|
|
#include "iface-io/iidx.h"
|
|
|
|
#include "iidxhook-d3d9/bb-scale-hd.h"
|
|
|
|
#include "iidxhook-util/acio.h"
|
|
#include "iidxhook-util/config-gfx.h"
|
|
#include "iidxhook-util/config-io.h"
|
|
#include "iidxhook-util/d3d9.h"
|
|
|
|
#include "module/io-ext.h"
|
|
#include "module/io.h"
|
|
|
|
#include "sdk/module/core/log.h"
|
|
#include "sdk/module/core/thread.h"
|
|
#include "sdk/module/hook.h"
|
|
|
|
#include "util/str.h"
|
|
|
|
#define IIDXHOOK6_INFO_HEADER \
|
|
"iidxhook for Tricoro" \
|
|
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV)
|
|
#define IIDXHOOK6_CMD_USAGE \
|
|
"Usage: launcher.exe -K iidxhook6.dll <bm2dx.dll> [options...]"
|
|
|
|
static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = {
|
|
iidxhook_d3d9_bb_scale_hd_d3d9_irp_handler,
|
|
iidxhook_util_d3d9_irp_handler,
|
|
};
|
|
|
|
static struct iidxhook_config_io config_io;
|
|
static module_io_t *iidxhook_module_io_iidx;
|
|
static module_io_t *iidxhook_module_io_eam;
|
|
|
|
static void _iidxhook6_io_iidx_init(module_io_t **module)
|
|
{
|
|
bt_io_iidx_api_t api;
|
|
|
|
module_io_ext_load_and_init(
|
|
"iidxio.dll", "bt_module_io_iidx_api_get", module);
|
|
module_io_api_get(*module, &api);
|
|
bt_io_iidx_api_set(&api);
|
|
}
|
|
|
|
static void _iidxhook6_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
|
|
iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
|
|
{
|
|
struct iidxhook_util_d3d9_config d3d9_config;
|
|
|
|
iidxhook_util_d3d9_init_config(&d3d9_config);
|
|
|
|
d3d9_config.windowed = config_gfx->windowed;
|
|
d3d9_config.framed = config_gfx->framed;
|
|
d3d9_config.override_window_width = config_gfx->window_width;
|
|
d3d9_config.override_window_height = config_gfx->window_height;
|
|
d3d9_config.framerate_limit = config_gfx->frame_rate_limit;
|
|
d3d9_config.pci_vid = config_gfx->pci_id_vid;
|
|
d3d9_config.pci_pid = config_gfx->pci_id_pid;
|
|
d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate;
|
|
d3d9_config.device_adapter = config_gfx->device_adapter;
|
|
|
|
iidxhook_util_d3d9_configure(&d3d9_config);
|
|
|
|
// The "old"/current scaling feature does not work with 20-26 because
|
|
// the render engine changed and provides its own built-in scaling feature
|
|
if (config_gfx->scale_back_buffer_width > 0 &&
|
|
config_gfx->scale_back_buffer_height > 0) {
|
|
iidxhook_d3d9_bb_scale_hd_init(
|
|
config_gfx->scale_back_buffer_width,
|
|
config_gfx->scale_back_buffer_height);
|
|
}
|
|
|
|
hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers));
|
|
}
|
|
|
|
static bool
|
|
_iidxhook6_main_init(HMODULE game_module, const bt_core_config_t *config_)
|
|
{
|
|
struct cconfig *config;
|
|
|
|
struct iidxhook_config_gfx config_gfx;
|
|
|
|
config = cconfig_init();
|
|
|
|
iidxhook_config_gfx_init(config);
|
|
iidxhook_config_io_init(config);
|
|
|
|
if (!cconfig_hook_config_init(
|
|
config,
|
|
IIDXHOOK6_INFO_HEADER "\n" IIDXHOOK6_CMD_USAGE,
|
|
CCONFIG_CMD_USAGE_OUT_DBG)) {
|
|
cconfig_finit(config);
|
|
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
iidxhook_config_gfx_get(&config_gfx, config);
|
|
iidxhook_config_io_get(&config_io, config);
|
|
|
|
cconfig_finit(config);
|
|
|
|
log_info(IIDXHOOK6_INFO_HEADER);
|
|
|
|
acp_hook_init();
|
|
adapter_hook_init();
|
|
|
|
iidxhook6_setup_d3d9_hooks(&config_gfx);
|
|
|
|
if (!config_io.disable_io_emu) {
|
|
log_info("Starting IIDX IO backend");
|
|
|
|
_iidxhook6_io_iidx_init(&iidxhook_module_io_iidx);
|
|
|
|
if (!bt_io_iidx_init()) {
|
|
log_fatal("Initializing IIDX IO backend failed");
|
|
}
|
|
} else {
|
|
log_info("IIDX IO emulation backend disabled");
|
|
}
|
|
|
|
if (!config_io.disable_card_reader_emu) {
|
|
log_misc("Initializing card reader backend");
|
|
|
|
_iidxhook6_io_eam_init(&iidxhook_module_io_eam);
|
|
|
|
if (!bt_io_eam_init()) {
|
|
log_fatal("Initializing card reader backend failed");
|
|
}
|
|
} else {
|
|
log_info("Card reader emulation backend disabled");
|
|
}
|
|
|
|
/* iohooks are okay, even if emu is diabled since the fake handlers won't be
|
|
* used */
|
|
/* Set up IO emulation hooks _after_ IO API setup to allow
|
|
API implementations with real IO devices */
|
|
iohook_push_handler(ezusb2_emu_device_dispatch_irp);
|
|
iohook_push_handler(iidxhook_util_acio_dispatch_irp);
|
|
|
|
if (!config_io.disable_io_emu) {
|
|
hook_setupapi_init(&ezusb2_emu_desc_device.setupapi);
|
|
ezusb2_emu_device_hook_init(ezusb2_iidx_emu_msg_init());
|
|
}
|
|
|
|
/* Card reader emulation, same issue with hooking as IO emulation */
|
|
rs232_hook_init();
|
|
|
|
if (!config_io.disable_card_reader_emu) {
|
|
/* Do not use legacy mode, wave pass readers */
|
|
iidxhook_util_acio_init(false);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static void _iidxhook6_main_fini()
|
|
{
|
|
if (!config_io.disable_card_reader_emu) {
|
|
log_misc("Shutting down card reader backend");
|
|
bt_io_eam_fini();
|
|
|
|
bt_io_eam_api_clear();
|
|
module_io_free(&iidxhook_module_io_eam);
|
|
}
|
|
|
|
if (!config_io.disable_io_emu) {
|
|
log_misc("Shutting down IIDX IO backend");
|
|
bt_io_iidx_fini();
|
|
|
|
bt_io_iidx_api_clear();
|
|
module_io_free(&iidxhook_module_io_iidx);
|
|
}
|
|
}
|
|
|
|
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 = _iidxhook6_main_init;
|
|
api->v1.main_fini = _iidxhook6_main_fini;
|
|
}
|
|
|
|
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
|
|
{
|
|
return TRUE;
|
|
}
|