mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2026-09-29 18:27:55 +03:00
Appl new code style on whole code base
Use a similar code style to bemanitools though reduce indentation to 2 spaces. Also some other tweaks to be more similar to google style.
This commit is contained in:
+196
-179
@@ -14,8 +14,8 @@
|
||||
#include "hook/patch/microdog40.h"
|
||||
#include "hook/patch/mounts.h"
|
||||
#include "hook/patch/net-profile.h"
|
||||
#include "hook/patch/piuio.h"
|
||||
#include "hook/patch/piuio-exit.h"
|
||||
#include "hook/patch/piuio.h"
|
||||
#include "hook/patch/redir.h"
|
||||
#include "hook/patch/sigsegv.h"
|
||||
#include "hook/patch/sound.h"
|
||||
@@ -39,280 +39,297 @@ extern const uint8_t _binary_nx2hook_hdd_raw_end[];
|
||||
extern const uint8_t _binary_nx2hook_dog_key_start[];
|
||||
extern const uint8_t _binary_nx2hook_dog_key_end[];
|
||||
|
||||
static void nx2hook_bootstrapping(int argc, char** argv, struct nx2hook_options* options, char** game_data_path)
|
||||
static void nx2hook_bootstrapping(
|
||||
int argc,
|
||||
char **argv,
|
||||
struct nx2hook_options *options,
|
||||
char **game_data_path)
|
||||
{
|
||||
log_assert(argc >= 0);
|
||||
log_assert(argv);
|
||||
log_assert(options);
|
||||
log_assert(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;
|
||||
if (hook_core_piu_block_non_piu_process_recursion(argc, argv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
hook_core_piu_log_init(argc, argv);
|
||||
|
||||
if (!nx2hook_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();
|
||||
|
||||
log_info("Initializing, piu game data path: %s", *game_data_path);
|
||||
}
|
||||
|
||||
static void nx2hook_patch_fs_init(struct nx2hook_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 nx2hook_fs_redir_settings(struct nx2hook_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);
|
||||
}
|
||||
}
|
||||
|
||||
hook_core_piu_log_init(argc, argv);
|
||||
char *abs_path = util_fs_get_abs_path(options->game.settings);
|
||||
|
||||
if (!nx2hook_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();
|
||||
|
||||
log_info("Initializing, piu game data path: %s", *game_data_path);
|
||||
cnh_redir_add("/SETTINGS", abs_path);
|
||||
free(abs_path);
|
||||
} else {
|
||||
log_warn("No settings path specified");
|
||||
}
|
||||
}
|
||||
|
||||
static void nx2hook_patch_fs_init(struct nx2hook_options* options)
|
||||
static void nx2hook_fs_redir_script(
|
||||
struct nx2hook_options *options, const char *game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
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);
|
||||
char *path_tmp;
|
||||
|
||||
patch_redir_init();
|
||||
path_tmp = util_str_merge(game_data_path, "/SCRIPT");
|
||||
cnh_redir_add("/SCRIPT", path_tmp);
|
||||
free(path_tmp);
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redir_settings(struct nx2hook_options* options)
|
||||
static void nx2hook_fs_redir_fonts(
|
||||
struct nx2hook_options *options, const char *game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
if (options->game.settings) {
|
||||
if (!util_fs_path_exists(options->game.settings)) {
|
||||
log_info("Settings path %s does not exist, creating", options->game.settings);
|
||||
char *path_tmp;
|
||||
|
||||
if (!util_fs_mkdir(options->game.settings)) {
|
||||
log_error("Creating directory %s failed", options->game.settings);
|
||||
}
|
||||
}
|
||||
/* Fonts, game expects lower case files */
|
||||
path_tmp = util_str_merge(game_data_path, "/nx.ttf");
|
||||
cnh_redir_add("nx.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
char* abs_path = util_fs_get_abs_path(options->game.settings);
|
||||
path_tmp = util_str_merge(game_data_path, "/nxcn.ttf");
|
||||
cnh_redir_add("nxcn.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
cnh_redir_add("/SETTINGS", abs_path);
|
||||
free(abs_path);
|
||||
} else {
|
||||
log_warn("No settings path specified");
|
||||
}
|
||||
path_tmp = util_str_merge(game_data_path, "/nxpt.ttf");
|
||||
cnh_redir_add("nxpt.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
path_tmp = util_str_merge(game_data_path, "/nxtw.ttf");
|
||||
cnh_redir_add("nxtw.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redir_script(struct nx2hook_options* options, const char* game_data_path)
|
||||
static void nx2hook_fs_redir_mission(
|
||||
struct nx2hook_options *options, const char *game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
char* path_tmp;
|
||||
char *path_tmp;
|
||||
|
||||
path_tmp = util_str_merge(game_data_path, "/SCRIPT");
|
||||
cnh_redir_add("/SCRIPT", path_tmp);
|
||||
free(path_tmp);
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redir_fonts(struct nx2hook_options* options, const char* game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
char* path_tmp;
|
||||
|
||||
/* Fonts, game expects lower case files */
|
||||
path_tmp = util_str_merge(game_data_path, "/nx.ttf");
|
||||
cnh_redir_add("nx.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
path_tmp = util_str_merge(game_data_path, "/nxcn.ttf");
|
||||
cnh_redir_add("nxcn.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
path_tmp = util_str_merge(game_data_path, "/nxpt.ttf");
|
||||
cnh_redir_add("nxpt.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
|
||||
path_tmp = util_str_merge(game_data_path, "/nxtw.ttf");
|
||||
cnh_redir_add("nxtw.ttf", path_tmp);
|
||||
free(path_tmp);
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redir_mission(struct nx2hook_options* options, const char* game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
char* path_tmp;
|
||||
|
||||
/* mission.txt, game expects lower case file */
|
||||
path_tmp = util_str_merge(game_data_path, "/mission.txt");
|
||||
cnh_redir_add("/mission.txt", path_tmp);
|
||||
free(path_tmp);
|
||||
/* mission.txt, game expects lower case file */
|
||||
path_tmp = util_str_merge(game_data_path, "/mission.txt");
|
||||
cnh_redir_add("/mission.txt", path_tmp);
|
||||
free(path_tmp);
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redir_usb()
|
||||
{
|
||||
/* Needed on newer kernels */
|
||||
cnh_redir_add("/proc/bus/usb/devices", "/sys/kernel/debug/usb/devices");
|
||||
patch_usbfs_init();
|
||||
/* Needed on newer kernels */
|
||||
cnh_redir_add("/proc/bus/usb/devices", "/sys/kernel/debug/usb/devices");
|
||||
patch_usbfs_init();
|
||||
}
|
||||
|
||||
static void nx2hook_fs_redirs_init(struct nx2hook_options* options, const char* game_data_path)
|
||||
static void nx2hook_fs_redirs_init(
|
||||
struct nx2hook_options *options, const char *game_data_path)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
log_assert(options);
|
||||
log_assert(game_data_path);
|
||||
|
||||
/* Expecting all assets in the piu game (asset) folder. redirects for files
|
||||
that are not in there by default for reasons */
|
||||
nx2hook_fs_redir_settings(options);
|
||||
nx2hook_fs_redir_script(options, game_data_path);
|
||||
nx2hook_fs_redir_fonts(options, game_data_path);
|
||||
nx2hook_fs_redir_mission(options, game_data_path);
|
||||
/* Expecting all assets in the piu game (asset) folder. redirects for files
|
||||
that are not in there by default for reasons */
|
||||
nx2hook_fs_redir_settings(options);
|
||||
nx2hook_fs_redir_script(options, game_data_path);
|
||||
nx2hook_fs_redir_fonts(options, game_data_path);
|
||||
nx2hook_fs_redir_mission(options, game_data_path);
|
||||
|
||||
nx2hook_fs_redir_usb();
|
||||
nx2hook_fs_redir_usb();
|
||||
}
|
||||
|
||||
static void nx2hook_patch_fs_mounting_init()
|
||||
{
|
||||
patch_mounts_init();
|
||||
patch_mounts_init();
|
||||
|
||||
patch_usb_mnt_init();
|
||||
patch_usb_unlock_init();
|
||||
patch_usb_mnt_init();
|
||||
patch_usb_unlock_init();
|
||||
}
|
||||
|
||||
static void nx2hook_patch_gfx_init(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_gfx_init(struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
|
||||
patch_gfx_init();
|
||||
patch_gfx_init();
|
||||
|
||||
if (options->patch.gfx.windowed) {
|
||||
patch_gfx_force_window_mode();
|
||||
}
|
||||
if (options->patch.gfx.windowed) {
|
||||
patch_gfx_force_window_mode();
|
||||
}
|
||||
}
|
||||
|
||||
static void nx2hook_patch_main_loop_init(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_main_loop_init(struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
|
||||
patch_main_loop_init(false, options->patch.main_loop.disable_built_in_inputs, false);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
patch_main_loop_add_x11_input_handler(abs_path_x11_input_hook_lib);
|
||||
free(abs_path_x11_input_hook_lib);
|
||||
}
|
||||
}
|
||||
|
||||
static void nx2hook_patch_sound_init(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_sound_init(struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
|
||||
patch_sound_init(options->patch.sound.device);
|
||||
patch_sound_init(options->patch.sound.device);
|
||||
}
|
||||
|
||||
static void nx2hook_patch_sigsegv_init(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_sigsegv_init(struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
|
||||
patch_sigsegv_init(options->patch.sigsegv.halt_on_segv);
|
||||
patch_sigsegv_init(options->patch.sigsegv.halt_on_segv);
|
||||
}
|
||||
|
||||
static void nx2hook_patch_dongle_init()
|
||||
{
|
||||
patch_microdog40_init((const uint8_t*) _binary_nx2hook_dog_key_start,
|
||||
((uintptr_t) &_binary_nx2hook_dog_key_end - (uintptr_t) &_binary_nx2hook_dog_key_start));
|
||||
patch_microdog40_init(
|
||||
(const uint8_t *) _binary_nx2hook_dog_key_start,
|
||||
((uintptr_t) &_binary_nx2hook_dog_key_end -
|
||||
(uintptr_t) &_binary_nx2hook_dog_key_start));
|
||||
}
|
||||
|
||||
static void nx2hook_patch_hdd_check_init()
|
||||
{
|
||||
patch_hdd_check_init((const uint8_t*) _binary_nx2hook_hdd_raw_start,
|
||||
((uintptr_t) &_binary_nx2hook_hdd_raw_end - (uintptr_t) &_binary_nx2hook_hdd_raw_start));
|
||||
patch_hdd_check_init(
|
||||
(const uint8_t *) _binary_nx2hook_hdd_raw_start,
|
||||
((uintptr_t) &_binary_nx2hook_hdd_raw_end -
|
||||
(uintptr_t) &_binary_nx2hook_hdd_raw_start));
|
||||
}
|
||||
|
||||
static void nx2hook_patch_piuio_init(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_piuio_init(struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(options);
|
||||
log_assert(options);
|
||||
|
||||
/* Hook before IO emulation */
|
||||
if (options->patch.piuio.exit_test_serv) {
|
||||
patch_piuio_exit_init();
|
||||
}
|
||||
/* Hook before IO emulation */
|
||||
if (options->patch.piuio.exit_test_serv) {
|
||||
patch_piuio_exit_init();
|
||||
}
|
||||
|
||||
patch_usb_init_fix_init();
|
||||
patch_usb_emu_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);
|
||||
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);
|
||||
}
|
||||
patch_piuio_init(abs_path_iolib);
|
||||
free(abs_path_iolib);
|
||||
}
|
||||
}
|
||||
|
||||
static void nx2hook_patch_profile()
|
||||
{
|
||||
nx2hook_profile_gen_init();
|
||||
nx2hook_profile_gen_init();
|
||||
}
|
||||
|
||||
static void nx2hook_patch_pumpnet(struct nx2hook_options* options)
|
||||
static void nx2hook_patch_pumpnet(struct nx2hook_options *options)
|
||||
{
|
||||
if (options->patch.net.server && options->patch.net.machine_id != 0) {
|
||||
patch_net_profile_init(
|
||||
ASSET_GAME_VERSION_NX2,
|
||||
options->patch.net.server,
|
||||
options->patch.net.machine_id,
|
||||
options->patch.net.cert_dir_path,
|
||||
options->patch.net.verbose_log_output);
|
||||
}
|
||||
if (options->patch.net.server && options->patch.net.machine_id != 0) {
|
||||
patch_net_profile_init(
|
||||
ASSET_GAME_VERSION_NX2,
|
||||
options->patch.net.server,
|
||||
options->patch.net.machine_id,
|
||||
options->patch.net.cert_dir_path,
|
||||
options->patch.net.verbose_log_output);
|
||||
}
|
||||
}
|
||||
|
||||
void nx2hook_constructor(void)
|
||||
{
|
||||
/* Nothing here */
|
||||
/* Nothing here */
|
||||
}
|
||||
|
||||
void nx2hook_destructor(void)
|
||||
{
|
||||
/* Nothing here */
|
||||
/* Nothing here */
|
||||
}
|
||||
|
||||
void nx2hook_trap_before_main(int argc, char** argv)
|
||||
void nx2hook_trap_before_main(int argc, char **argv)
|
||||
{
|
||||
log_assert(argc >= 0);
|
||||
log_assert(argv);
|
||||
log_assert(argc >= 0);
|
||||
log_assert(argv);
|
||||
|
||||
char* game_data_path;
|
||||
struct nx2hook_options options;
|
||||
char *game_data_path;
|
||||
struct nx2hook_options options;
|
||||
|
||||
nx2hook_bootstrapping(argc, argv, &options, &game_data_path);
|
||||
nx2hook_patch_fs_init(&options);
|
||||
nx2hook_fs_redirs_init(&options, game_data_path);
|
||||
nx2hook_patch_fs_mounting_init();
|
||||
nx2hook_patch_gfx_init(&options);
|
||||
nx2hook_patch_main_loop_init(&options);
|
||||
nx2hook_patch_sound_init(&options);
|
||||
nx2hook_patch_sigsegv_init(&options);
|
||||
nx2hook_patch_dongle_init();
|
||||
nx2hook_patch_hdd_check_init();
|
||||
nx2hook_patch_piuio_init(&options);
|
||||
// Init order of pumpnet and auto profile generating important: pumpnet hook, if active, needs to be applied before
|
||||
// the auto gen profile hook. Otherwise, the game detects that no profile is available and auto generates one even
|
||||
// it should take the pumpnet route to grab a profile from a remote server
|
||||
nx2hook_patch_pumpnet(&options);
|
||||
nx2hook_patch_profile();
|
||||
nx2hook_bootstrapping(argc, argv, &options, &game_data_path);
|
||||
nx2hook_patch_fs_init(&options);
|
||||
nx2hook_fs_redirs_init(&options, game_data_path);
|
||||
nx2hook_patch_fs_mounting_init();
|
||||
nx2hook_patch_gfx_init(&options);
|
||||
nx2hook_patch_main_loop_init(&options);
|
||||
nx2hook_patch_sound_init(&options);
|
||||
nx2hook_patch_sigsegv_init(&options);
|
||||
nx2hook_patch_dongle_init();
|
||||
nx2hook_patch_hdd_check_init();
|
||||
nx2hook_patch_piuio_init(&options);
|
||||
// Init order of pumpnet and auto profile generating important: pumpnet hook,
|
||||
// if active, needs to be applied before the auto gen profile hook. Otherwise,
|
||||
// the game detects that no profile is available and auto generates one even
|
||||
// it should take the pumpnet route to grab a profile from a remote server
|
||||
nx2hook_patch_pumpnet(&options);
|
||||
nx2hook_patch_profile();
|
||||
|
||||
free(game_data_path);
|
||||
free(game_data_path);
|
||||
|
||||
log_info("Hooking finished");
|
||||
log_info("Hooking finished");
|
||||
}
|
||||
|
||||
void nx2hook_trap_after_main(void)
|
||||
{
|
||||
patch_net_profile_shutdown();
|
||||
patch_piuio_shutdown();
|
||||
patch_net_profile_shutdown();
|
||||
patch_piuio_shutdown();
|
||||
}
|
||||
|
||||
LIB_MAIN_CONSTRUCTOR(nx2hook_constructor);
|
||||
|
||||
+82
-53
@@ -9,16 +9,23 @@
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO "patch.hook_mon.io"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN "patch.hook_mon.open"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB "patch.hook_mon.usb"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_DISABLE_BUILT_IN_INPUTS "patch.hook_main_loop.disable_built_in_inputs"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER "patch_hook_main_loop.x11_input_handler"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_DISABLE_BUILT_IN_INPUTS \
|
||||
"patch.hook_main_loop.disable_built_in_inputs"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER \
|
||||
"patch_hook_main_loop.x11_input_handler"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER "patch.net_profile.server"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID "patch.net_profile.machine_id"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT "patch.net_profile.verbose_log_output"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH "patch.net_profile.cert_dir_path"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID \
|
||||
"patch.net_profile.machine_id"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT \
|
||||
"patch.net_profile.verbose_log_output"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH \
|
||||
"patch.net_profile.cert_dir_path"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB "patch.piuio.emu_lib"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV "patch.piuio_exit.test_serv"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV \
|
||||
"patch.piuio_exit.test_serv"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE "patch.sound.device"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV "patch.sigsegv.halt_on_segv"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV \
|
||||
"patch.sigsegv.halt_on_segv"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE "util.log.file"
|
||||
#define NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL "util.log.level"
|
||||
|
||||
@@ -73,22 +80,26 @@ const struct util_options_def nx2hook_options_def[] = {
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = NX2HOOK_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)",
|
||||
.name =
|
||||
NX2HOOK_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 = NX2HOOK_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",
|
||||
.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 = NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER,
|
||||
.description = "Address and port of pumpnet server (e.g. 127.0.0.1:1234)",
|
||||
.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,
|
||||
@@ -102,21 +113,25 @@ const struct util_options_def nx2hook_options_def[] = {
|
||||
},
|
||||
{
|
||||
.name = NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT,
|
||||
.description = "Enable verbose log output for pumpnet related things, e.g. logging network traffic",
|
||||
.description = "Enable verbose log output for pumpnet related things, "
|
||||
"e.g. logging network traffic",
|
||||
.param = 'v',
|
||||
.type = UTIL_OPTIONS_TYPE_BOOL,
|
||||
.default_value.b = false,
|
||||
},
|
||||
{
|
||||
.name = NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH,
|
||||
.description = "Path to a folder containing the client key, certificate and CA bundle to enable https communication",
|
||||
.description =
|
||||
"Path to a folder containing the client key, certificate and CA "
|
||||
"bundle to enable https communication",
|
||||
.param = 'c',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = NULL,
|
||||
},
|
||||
{
|
||||
.name = NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB,
|
||||
.description = "Path to library implementing the piuio api for piuio emulation",
|
||||
.description =
|
||||
"Path to library implementing the piuio api for piuio emulation",
|
||||
.param = 'p',
|
||||
.type = UTIL_OPTIONS_TYPE_STR,
|
||||
.default_value.str = NULL,
|
||||
@@ -167,49 +182,63 @@ const struct util_options_defs nx2hook_options_defs = {
|
||||
.ndefs = lengthof(nx2hook_options_def)
|
||||
};
|
||||
|
||||
bool nx2hook_options_init(int argc, char** argv, struct nx2hook_options* options)
|
||||
bool nx2hook_options_init(
|
||||
int argc, char **argv, struct nx2hook_options *options)
|
||||
{
|
||||
log_assert(argv);
|
||||
log_assert(options);
|
||||
log_assert(argv);
|
||||
log_assert(options);
|
||||
|
||||
struct util_options_opts* options_opt;
|
||||
struct util_options_opts *options_opt;
|
||||
|
||||
util_options_init(argc, argv);
|
||||
options_opt = util_options_get(&nx2hook_options_defs);
|
||||
util_options_init(argc, argv);
|
||||
options_opt = util_options_get(&nx2hook_options_defs);
|
||||
|
||||
if (!options_opt) {
|
||||
return false;
|
||||
}
|
||||
if (!options_opt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
options->game.settings = util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_GAME_SETTINGS);
|
||||
options->patch.gfx.windowed = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_GFX_WINDOWED);
|
||||
options->patch.hook_mon.file = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FILE);
|
||||
options->patch.hook_mon.fs = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FS);
|
||||
options->patch.hook_mon.io = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO);
|
||||
options->patch.hook_mon.open = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN);
|
||||
options->patch.hook_mon.usb = util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB);
|
||||
options->patch.main_loop.disable_built_in_inputs = util_options_get_bool(options_opt,
|
||||
NX2HOOK_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, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER);
|
||||
options->patch.net.server = util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER);
|
||||
options->patch.net.machine_id = strtoull(
|
||||
util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID),
|
||||
NULL,
|
||||
16);
|
||||
options->patch.net.verbose_log_output =
|
||||
util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT);
|
||||
options->patch.net.cert_dir_path =
|
||||
util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH);
|
||||
options->patch.piuio.api_lib = util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB);
|
||||
options->patch.piuio.exit_test_serv =
|
||||
util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV);
|
||||
options->patch.sound.device = util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE);
|
||||
options->patch.sigsegv.halt_on_segv =
|
||||
util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV);
|
||||
options->log.file = util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE);
|
||||
options->log.level =
|
||||
(enum util_log_level) util_options_get_int(options_opt, NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL);
|
||||
options->game.settings =
|
||||
util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_GAME_SETTINGS);
|
||||
options->patch.gfx.windowed = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_GFX_WINDOWED);
|
||||
options->patch.hook_mon.file = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FILE);
|
||||
options->patch.hook_mon.fs =
|
||||
util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_FS);
|
||||
options->patch.hook_mon.io =
|
||||
util_options_get_bool(options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_IO);
|
||||
options->patch.hook_mon.open = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_OPEN);
|
||||
options->patch.hook_mon.usb = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MON_USB);
|
||||
options->patch.main_loop.disable_built_in_inputs = util_options_get_bool(
|
||||
options_opt,
|
||||
NX2HOOK_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, NX2HOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER);
|
||||
options->patch.net.server = util_options_get_str(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER);
|
||||
options->patch.net.machine_id = strtoull(
|
||||
util_options_get_str(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID),
|
||||
NULL,
|
||||
16);
|
||||
options->patch.net.verbose_log_output = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT);
|
||||
options->patch.net.cert_dir_path = util_options_get_str(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH);
|
||||
options->patch.piuio.api_lib = util_options_get_str(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB);
|
||||
options->patch.piuio.exit_test_serv = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV);
|
||||
options->patch.sound.device =
|
||||
util_options_get_str(options_opt, NX2HOOK_OPTIONS_STR_PATCH_SOUND_DEVICE);
|
||||
options->patch.sigsegv.halt_on_segv = util_options_get_bool(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_SIGSEGV_HALT_ON_SEGV);
|
||||
options->log.file = util_options_get_str(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_FILE);
|
||||
options->log.level = (enum util_log_level) util_options_get_int(
|
||||
options_opt, NX2HOOK_OPTIONS_STR_PATCH_UTIL_LOG_LEVEL);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
+41
-40
@@ -7,55 +7,56 @@
|
||||
#include "util/log.h"
|
||||
|
||||
struct nx2hook_options {
|
||||
struct game {
|
||||
const char* settings;
|
||||
} game;
|
||||
struct game {
|
||||
const char *settings;
|
||||
} game;
|
||||
|
||||
struct patch {
|
||||
struct gfx {
|
||||
bool windowed;
|
||||
} gfx;
|
||||
struct patch {
|
||||
struct gfx {
|
||||
bool windowed;
|
||||
} gfx;
|
||||
|
||||
struct hook_mon {
|
||||
bool file;
|
||||
bool fs;
|
||||
bool io;
|
||||
bool open;
|
||||
bool usb;
|
||||
} hook_mon;
|
||||
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 main_loop {
|
||||
bool disable_built_in_inputs;
|
||||
const char *x11_input_handler_api_lib;
|
||||
} main_loop;
|
||||
|
||||
struct net {
|
||||
const char* server;
|
||||
uint64_t machine_id;
|
||||
bool verbose_log_output;
|
||||
const char* cert_dir_path;
|
||||
} net;
|
||||
struct net {
|
||||
const char *server;
|
||||
uint64_t machine_id;
|
||||
bool verbose_log_output;
|
||||
const char *cert_dir_path;
|
||||
} net;
|
||||
|
||||
struct piuio {
|
||||
const char* api_lib;
|
||||
bool exit_test_serv;
|
||||
} piuio;
|
||||
struct piuio {
|
||||
const char *api_lib;
|
||||
bool exit_test_serv;
|
||||
} piuio;
|
||||
|
||||
struct sound {
|
||||
const char* device;
|
||||
} sound;
|
||||
struct sound {
|
||||
const char *device;
|
||||
} sound;
|
||||
|
||||
struct sigsegv {
|
||||
bool halt_on_segv;
|
||||
} sigsegv;
|
||||
} patch;
|
||||
struct sigsegv {
|
||||
bool halt_on_segv;
|
||||
} sigsegv;
|
||||
} patch;
|
||||
|
||||
struct log {
|
||||
const char* file;
|
||||
enum util_log_level level;
|
||||
} log;
|
||||
struct log {
|
||||
const char *file;
|
||||
enum util_log_level level;
|
||||
} log;
|
||||
};
|
||||
|
||||
bool nx2hook_options_init(int argc, char** argv, struct nx2hook_options* options);
|
||||
bool nx2hook_options_init(
|
||||
int argc, char **argv, struct nx2hook_options *options);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,59 +12,65 @@
|
||||
|
||||
static bool nx2hook_profile_gen_is_creating_file;
|
||||
|
||||
// Do not use util_fs_path_exists here as this fopens and causes an endless recursion
|
||||
static bool nx2hook_profile_gen_check_if_exists(const char* path)
|
||||
// Do not use util_fs_path_exists here as this fopens and causes an endless
|
||||
// recursion
|
||||
static bool nx2hook_profile_gen_check_if_exists(const char *path)
|
||||
{
|
||||
return access(path, F_OK) != -1;
|
||||
return access(path, F_OK) != -1;
|
||||
}
|
||||
|
||||
static enum cnh_result nx2hook_profile_gen_filehook(struct cnh_filehook_irp *irp)
|
||||
static enum cnh_result
|
||||
nx2hook_profile_gen_filehook(struct cnh_filehook_irp *irp)
|
||||
{
|
||||
// nx2hook_profile_gen_is_creating_file: Avoid recursion of any file calls when creating the save/rank files
|
||||
if (irp->op != CNH_FILEHOOK_IRP_OP_OPEN || nx2hook_profile_gen_is_creating_file) {
|
||||
return cnh_filehook_invoke_next(irp);
|
||||
}
|
||||
|
||||
if (util_str_ends_with(irp->open_filename, "nx2save.bin") &&
|
||||
!nx2hook_profile_gen_check_if_exists(irp->open_filename)) {
|
||||
nx2hook_profile_gen_is_creating_file = true;
|
||||
|
||||
struct asset_nx2_usb_save* save = asset_nx2_usb_save_new();
|
||||
asset_nx2_usb_save_finalize(save);
|
||||
|
||||
log_info("No %s file found, generate new", irp->open_filename);
|
||||
|
||||
if (!asset_nx2_usb_save_save_to_file(irp->open_filename, save, true)) {
|
||||
log_error("Saving generated nx2save.bin file to %s failed", irp->open_filename);
|
||||
}
|
||||
|
||||
free(save);
|
||||
|
||||
nx2hook_profile_gen_is_creating_file = false;
|
||||
}
|
||||
|
||||
if (util_str_ends_with(irp->open_filename, "nx2rank.bin") &&
|
||||
!nx2hook_profile_gen_check_if_exists(irp->open_filename)) {
|
||||
nx2hook_profile_gen_is_creating_file = true;
|
||||
|
||||
struct asset_nx2_usb_rank* rank = asset_nx2_usb_rank_new();
|
||||
asset_nx2_usb_rank_finalize(rank);
|
||||
|
||||
log_info("No %s file found, generate new", irp->open_filename);
|
||||
|
||||
if (!asset_nx2_usb_rank_save_to_file(irp->open_filename, rank, true)) {
|
||||
log_error("Saving generated nx2rank.bin file to %s failed", irp->open_filename);
|
||||
}
|
||||
|
||||
free(rank);
|
||||
|
||||
nx2hook_profile_gen_is_creating_file = false;
|
||||
}
|
||||
|
||||
// nx2hook_profile_gen_is_creating_file: Avoid recursion of any file calls
|
||||
// when creating the save/rank files
|
||||
if (irp->op != CNH_FILEHOOK_IRP_OP_OPEN ||
|
||||
nx2hook_profile_gen_is_creating_file) {
|
||||
return cnh_filehook_invoke_next(irp);
|
||||
}
|
||||
|
||||
if (util_str_ends_with(irp->open_filename, "nx2save.bin") &&
|
||||
!nx2hook_profile_gen_check_if_exists(irp->open_filename)) {
|
||||
nx2hook_profile_gen_is_creating_file = true;
|
||||
|
||||
struct asset_nx2_usb_save *save = asset_nx2_usb_save_new();
|
||||
asset_nx2_usb_save_finalize(save);
|
||||
|
||||
log_info("No %s file found, generate new", irp->open_filename);
|
||||
|
||||
if (!asset_nx2_usb_save_save_to_file(irp->open_filename, save, true)) {
|
||||
log_error(
|
||||
"Saving generated nx2save.bin file to %s failed", irp->open_filename);
|
||||
}
|
||||
|
||||
free(save);
|
||||
|
||||
nx2hook_profile_gen_is_creating_file = false;
|
||||
}
|
||||
|
||||
if (util_str_ends_with(irp->open_filename, "nx2rank.bin") &&
|
||||
!nx2hook_profile_gen_check_if_exists(irp->open_filename)) {
|
||||
nx2hook_profile_gen_is_creating_file = true;
|
||||
|
||||
struct asset_nx2_usb_rank *rank = asset_nx2_usb_rank_new();
|
||||
asset_nx2_usb_rank_finalize(rank);
|
||||
|
||||
log_info("No %s file found, generate new", irp->open_filename);
|
||||
|
||||
if (!asset_nx2_usb_rank_save_to_file(irp->open_filename, rank, true)) {
|
||||
log_error(
|
||||
"Saving generated nx2rank.bin file to %s failed", irp->open_filename);
|
||||
}
|
||||
|
||||
free(rank);
|
||||
|
||||
nx2hook_profile_gen_is_creating_file = false;
|
||||
}
|
||||
|
||||
return cnh_filehook_invoke_next(irp);
|
||||
}
|
||||
|
||||
void nx2hook_profile_gen_init(void)
|
||||
{
|
||||
cnh_filehook_push_handler(nx2hook_profile_gen_filehook);
|
||||
cnh_filehook_push_handler(nx2hook_profile_gen_filehook);
|
||||
}
|
||||
Reference in New Issue
Block a user