mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2026-10-03 12:17:59 +03:00
Version 1.08 with public source code release.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DUMMY NOT RELEASED YET
|
||||
@@ -0,0 +1 @@
|
||||
DUMMY NOT RELEASED YET
|
||||
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* Hook library for Pump It Up: Fiesta 2
|
||||
*/
|
||||
#define LOG_MODULE "f2hook"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "capnhook/hook/lib-main.h"
|
||||
#include "capnhook/hooklib/redir.h"
|
||||
|
||||
#include "hook/core/piu-utils.h"
|
||||
|
||||
#include "hook/patch/amixer-block.h"
|
||||
#include "hook/patch/gfx.h"
|
||||
#include "hook/patch/hasp.h"
|
||||
#include "hook/patch/hdd-check.h"
|
||||
#include "hook/patch/hook-mon.h"
|
||||
#include "hook/patch/main-loop.h"
|
||||
#include "hook/patch/mounts.h"
|
||||
#include "hook/patch/piuio.h"
|
||||
#include "hook/patch/piuio-exit.h"
|
||||
#include "hook/patch/redir.h"
|
||||
#include "hook/patch/sigsegv.h"
|
||||
#include "hook/patch/sound.h"
|
||||
#include "hook/patch/usb-emu.h"
|
||||
#include "hook/patch/usb-init-fix.h"
|
||||
#include "hook/patch/usb-mnt.h"
|
||||
#include "hook/patch/usbfs.h"
|
||||
|
||||
#include "util/fs.h"
|
||||
#include "util/glibc.h"
|
||||
#include "util/sys-info.h"
|
||||
|
||||
#include "options.h"
|
||||
|
||||
/* Compiled binary data from data folder. Symbols are defined by compiler */
|
||||
extern const uint8_t _binary_f2hook_hdd_raw_start[];
|
||||
extern const uint8_t _binary_f2hook_hdd_raw_end[];
|
||||
extern const uint8_t _binary_f2hook_hasp_key_start[];
|
||||
extern const uint8_t _binary_f2hook_hasp_key_end[];
|
||||
|
||||
static void f2hook_bootstrapping(int argc, char** argv, struct f2hook_options* options, char** game_data_path)
|
||||
{
|
||||
log_assert(argc >= 0);
|
||||
log_assert(argv);
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
if (hook_core_piu_block_non_piu_process_recursion(argc, argv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
hook_core_piu_log_init(argc, argv);
|
||||
|
||||
if (!f2hook_options_init(argc, argv, options)) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
hook_core_piu_log_info(argc, argv);
|
||||
|
||||
*game_data_path = hook_core_piu_utils_get_and_verify_game_data_path(argc, argv);
|
||||
|
||||
hook_core_piu_utils_verify_root_user();
|
||||
|
||||
hook_core_piu_utils_fix_locale();
|
||||
|
||||
log_info("Initializing, piu game data path: %s", *game_data_path);
|
||||
}
|
||||
|
||||
static void f2hook_patch_fs_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
patch_hook_mon_init(
|
||||
options->patch.hook_mon.io,
|
||||
options->patch.hook_mon.file,
|
||||
options->patch.hook_mon.fs,
|
||||
options->patch.hook_mon.usb,
|
||||
options->patch.hook_mon.open);
|
||||
|
||||
patch_redir_init();
|
||||
}
|
||||
|
||||
static void f2hook_fs_redir_settings(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
if (options->game.settings) {
|
||||
if (!util_fs_path_exists(options->game.settings)) {
|
||||
log_info("Settings path %s does not exist, creating", options->game.settings);
|
||||
|
||||
if (!util_fs_mkdir(options->game.settings)) {
|
||||
log_error("Creating directory %s failed", options->game.settings);
|
||||
}
|
||||
}
|
||||
|
||||
char* abs_path = util_fs_get_abs_path(options->game.settings);
|
||||
|
||||
cnh_redir_add("/SETTINGS", abs_path);
|
||||
free(abs_path);
|
||||
} else {
|
||||
log_warn("No settings path specified");
|
||||
}
|
||||
}
|
||||
|
||||
static void f2hook_fs_redir_usb()
|
||||
{
|
||||
/* Needed on newer kernels */
|
||||
cnh_redir_add("/proc/bus/usb/devices", "/sys/kernel/debug/usb/devices");
|
||||
patch_usbfs_init();
|
||||
}
|
||||
|
||||
static void f2hook_fs_redirs_init(struct f2hook_options* options, const char* game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
f2hook_fs_redir_settings(options);
|
||||
|
||||
f2hook_fs_redir_usb();
|
||||
}
|
||||
|
||||
static void f2hook_patch_fs_mounting_init()
|
||||
{
|
||||
patch_mounts_init();
|
||||
|
||||
patch_usb_mnt_init();
|
||||
}
|
||||
|
||||
static void f2hook_patch_gfx_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
patch_gfx_init();
|
||||
|
||||
if (options->patch.gfx.windowed) {
|
||||
patch_gfx_force_window_mode();
|
||||
}
|
||||
}
|
||||
|
||||
static void f2hook_patch_main_loop_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
patch_main_loop_init(false, options->patch.main_loop.disable_built_in_inputs, false);
|
||||
|
||||
if (options->patch.main_loop.x11_input_handler_api_lib) {
|
||||
char* abs_path_x11_input_hook_lib = util_fs_get_abs_path(options->patch.main_loop.x11_input_handler_api_lib);
|
||||
|
||||
patch_main_loop_add_x11_input_handler(abs_path_x11_input_hook_lib);
|
||||
free(abs_path_x11_input_hook_lib);
|
||||
}
|
||||
}
|
||||
|
||||
static void f2hook_patch_sound_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
patch_sound_init(options->patch.sound.device);
|
||||
patch_axmier_block_init();
|
||||
}
|
||||
|
||||
static void f2hook_patch_sigsegv_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
patch_sigsegv_init(options->patch.sigsegv.halt_on_segv);
|
||||
}
|
||||
|
||||
static void f2hook_patch_dongle_init()
|
||||
{
|
||||
patch_hasp_init((const uint8_t*) _binary_f2hook_hasp_key_start,
|
||||
((uintptr_t) &_binary_f2hook_hasp_key_end - (uintptr_t) &_binary_f2hook_hasp_key_start));
|
||||
}
|
||||
|
||||
static void f2hook_patch_hdd_check_init()
|
||||
{
|
||||
patch_hdd_check_init((const uint8_t*) _binary_f2hook_hdd_raw_start,
|
||||
((uintptr_t) &_binary_f2hook_hdd_raw_end - (uintptr_t) &_binary_f2hook_hdd_raw_start));
|
||||
}
|
||||
|
||||
static void f2hook_patch_piuio_init(struct f2hook_options* options)
|
||||
{
|
||||
log_assert(options);
|
||||
|
||||
/* Hook before IO emulation */
|
||||
if (options->patch.piuio.exit_test_serv) {
|
||||
patch_piuio_exit_init();
|
||||
}
|
||||
|
||||
patch_usb_init_fix_init();
|
||||
patch_usb_emu_init();
|
||||
|
||||
if (options->patch.piuio.api_lib) {
|
||||
char* abs_path_iolib = util_fs_get_abs_path(options->patch.piuio.api_lib);
|
||||
|
||||
patch_piuio_init(abs_path_iolib);
|
||||
free(abs_path_iolib);
|
||||
}
|
||||
}
|
||||
|
||||
void f2hook_constructor(void)
|
||||
{
|
||||
/* Nothing here */
|
||||
}
|
||||
|
||||
void f2hook_destructor(void)
|
||||
{
|
||||
/* Nothing here */
|
||||
}
|
||||
|
||||
void f2hook_trap_before_main(int argc, char** argv)
|
||||
{
|
||||
log_assert(argc >= 0);
|
||||
log_assert(argv);
|
||||
|
||||
char* game_data_path;
|
||||
struct f2hook_options options;
|
||||
|
||||
f2hook_bootstrapping(argc, argv, &options, &game_data_path);
|
||||
f2hook_patch_fs_init(&options);
|
||||
f2hook_fs_redirs_init(&options, game_data_path);
|
||||
f2hook_patch_fs_mounting_init();
|
||||
f2hook_patch_gfx_init(&options);
|
||||
f2hook_patch_main_loop_init(&options);
|
||||
f2hook_patch_sound_init(&options);
|
||||
f2hook_patch_sigsegv_init(&options);
|
||||
f2hook_patch_dongle_init();
|
||||
f2hook_patch_hdd_check_init();
|
||||
f2hook_patch_piuio_init(&options);
|
||||
|
||||
free(game_data_path);
|
||||
|
||||
log_info("Hooking finished");
|
||||
}
|
||||
|
||||
void f2hook_trap_after_main(void)
|
||||
{
|
||||
patch_piuio_shutdown();
|
||||
}
|
||||
|
||||
LIB_MAIN_CONSTRUCTOR(f2hook_constructor);
|
||||
LIB_MAIN_DESTRUCTOR(f2hook_destructor);
|
||||
LIB_MAIN_TRAP_MAIN(f2hook_trap_before_main, f2hook_trap_after_main);
|
||||
@@ -0,0 +1,195 @@
|
||||
#include "hook/f2/options.h"
|
||||
|
||||
#include "util/options.h"
|
||||
|
||||
#define F2HOOK_OPTIONS_STR_GAME_SETTINGS "game.settings"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_GFX_WINDOWED "patch.gfx.windowed"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FILE "patch.hook_mon.file"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FS "patch.hook_mon.fs"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO "patch.hook_mon.io"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN "patch.hook_mon.open"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB "patch.hook_mon.usb"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_DISABLE_BUILT_IN_INPUTS "patch.hook_main_loop.disable_built_in_inputs"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER "patch_hook_main_loop.x11_input_handler"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER "patch.net_profile.server"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID "patch.net_profile.machine_id"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB "patch.piuio.emu_lib"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV "patch.piuio_exit.test_serv"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE "patch.sound.device"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV "patch.sigsegv.halt_on_segv"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE "util.log.file"
|
||||
#define F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL "util.log.level"
|
||||
|
||||
const struct util_options_def f2hook_options_def[] = {
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_GAME_SETTINGS,
|
||||
.description = "Path to game settings (SETTINGS) folder",
|
||||
.param = 's',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = "./save",
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_GFX_WINDOWED,
|
||||
.description = "Force game into window mode",
|
||||
.param = 'w',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FILE,
|
||||
.description = "Enable file call monitoring",
|
||||
.param = 'f',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FS,
|
||||
.description = "Enable file system related call monitoring",
|
||||
.param = 'g',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO,
|
||||
.description = "Enable IO syscall monitoring",
|
||||
.param = 'i',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN,
|
||||
.description = "Enable any file/IO open call monitoring",
|
||||
.param = 'j',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB,
|
||||
.description = "Enable libusb call monitoring",
|
||||
.param = 'u',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_DISABLE_BUILT_IN_INPUTS,
|
||||
.description = "Disable the built in keyboard inputs for test (F1), service (F2) and clear (F3)",
|
||||
.param = 'k',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER,
|
||||
.description = "Path to a library implementing the x11-input-handler api to capture X11 keyboard inputs",
|
||||
.param = 'q',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = NULL,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER,
|
||||
.description = "Address and port of pumpnet server (e.g. 127.0.0.1:1234)",
|
||||
.param = 'n',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = NULL,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID,
|
||||
.description = "Machine id for pumpnet",
|
||||
.param = 'm',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = "0",
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB,
|
||||
.description = "Path to library implementing the piuio api for piuio emulation",
|
||||
.param = 'p',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = NULL,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV,
|
||||
.description = "Enable game exit on Test + Service",
|
||||
.param = 'e',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE,
|
||||
.description = "Select the sound device to open on snd_pcm_open",
|
||||
.param = 'a',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = "dmix",
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV,
|
||||
.description = "Halt on sigsegv to attach a debugger to the process",
|
||||
.param = 'd',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.str = false,
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE,
|
||||
.description = "Print the log output to the specified file",
|
||||
.param = 'o',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = "pumptools.log",
|
||||
},
|
||||
{
|
||||
.name = F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL,
|
||||
.description = "Set the log level (0-4)",
|
||||
.param = 'l',
|
||||
.type = UTIL_OPTIONS_TYPE_INT,
|
||||
.default_value.i = LOG_LEVEL_DEBUG,
|
||||
},
|
||||
};
|
||||
|
||||
const struct util_options_defs f2hook_options_defs = {
|
||||
.usage_header =
|
||||
"Pumptools f2hook for Pump It Up: Fiesta 2, build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n"
|
||||
"Usage: LD_PRELOAD=./f2hook.so [game exec] [game data path] <options>",
|
||||
.usage_param = 'h',
|
||||
.defs = f2hook_options_def,
|
||||
.ndefs = lengthof(f2hook_options_def)
|
||||
};
|
||||
|
||||
bool f2hook_options_init(int argc, char** argv, struct f2hook_options* options)
|
||||
{
|
||||
log_assert(argv);
|
||||
log_assert(options);
|
||||
|
||||
struct util_options_opts* options_opt;
|
||||
|
||||
util_options_init(argc, argv);
|
||||
options_opt = util_options_get(&f2hook_options_defs);
|
||||
|
||||
if (!options_opt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
options->game.settings = util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_GAME_SETTINGS);
|
||||
options->patch.gfx.windowed = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_GFX_WINDOWED);
|
||||
options->patch.hook_mon.file = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FILE);
|
||||
options->patch.hook_mon.fs = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FS);
|
||||
options->patch.hook_mon.io = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO);
|
||||
options->patch.hook_mon.open = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN);
|
||||
options->patch.hook_mon.usb = util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB);
|
||||
options->patch.main_loop.disable_built_in_inputs = util_options_get_bool(options_opt,
|
||||
F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_DISABLE_BUILT_IN_INPUTS);
|
||||
options->patch.main_loop.x11_input_handler_api_lib =
|
||||
util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER);
|
||||
options->patch.net.server = util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER);
|
||||
options->patch.net.machine_id = strtoul(
|
||||
util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID),
|
||||
NULL,
|
||||
16);
|
||||
options->patch.piuio.api_lib = util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB);
|
||||
options->patch.piuio.exit_test_serv =
|
||||
util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV);
|
||||
options->patch.sound.device = util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE);
|
||||
options->patch.sigsegv.halt_on_segv =
|
||||
util_options_get_bool(options_opt, F2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV);
|
||||
options->log.file = util_options_get_str(options_opt, F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE);
|
||||
options->log.level =
|
||||
(enum util_log_level) util_options_get_int(options_opt, F2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef F2HOOK_OPTIONS_H
|
||||
#define F2HOOK_OPTIONS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
struct f2hook_options {
|
||||
struct game {
|
||||
const char* settings;
|
||||
} game;
|
||||
|
||||
struct patch {
|
||||
struct gfx {
|
||||
bool windowed;
|
||||
} gfx;
|
||||
|
||||
struct hook_mon {
|
||||
bool file;
|
||||
bool fs;
|
||||
bool io;
|
||||
bool open;
|
||||
bool usb;
|
||||
} hook_mon;
|
||||
|
||||
struct main_loop {
|
||||
bool disable_built_in_inputs;
|
||||
const char* x11_input_handler_api_lib;
|
||||
} main_loop;
|
||||
|
||||
struct net {
|
||||
const char* server;
|
||||
uint32_t machine_id;
|
||||
} net;
|
||||
|
||||
struct piuio {
|
||||
const char* api_lib;
|
||||
bool exit_test_serv;
|
||||
} piuio;
|
||||
|
||||
struct sound {
|
||||
const char* device;
|
||||
} sound;
|
||||
|
||||
struct sigsegv {
|
||||
bool halt_on_segv;
|
||||
} sigsegv;
|
||||
} patch;
|
||||
|
||||
struct log {
|
||||
const char* file;
|
||||
enum util_log_level level;
|
||||
} log;
|
||||
};
|
||||
|
||||
bool f2hook_options_init(int argc, char** argv, struct f2hook_options* options);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user