diff --git a/cmake/src/main/hook/nxa/CMakeLists.txt b/cmake/src/main/hook/nxa/CMakeLists.txt index 8f57a75..81c4d37 100644 --- a/cmake/src/main/hook/nxa/CMakeLists.txt +++ b/cmake/src/main/hook/nxa/CMakeLists.txt @@ -16,4 +16,4 @@ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${HDD_RAW} ${DOG_KEY}) set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC") set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") -target_link_libraries(${PROJECT_NAME} asset-nxa crypt hook-core microdog40 patch ptapi-io-piuio-util util dl pthread) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} asset-nxa crypt hook-core microdog40 patch ptapi-io-piuio-util pumpnet-lib util dl pthread curl) \ No newline at end of file diff --git a/dist/conf/nxahook.conf b/dist/conf/nxahook.conf index 444b9a7..7df30cd 100644 --- a/dist/conf/nxahook.conf +++ b/dist/conf/nxahook.conf @@ -31,6 +31,12 @@ patch.net_profile.server= # [int]: Machine id for pumpnet patch.net_profile.machine_id=0000000000000000 +# [bool (0/1/)]: Enable verbose log output for pumpnet related things, e.g. logging network traffic +patch.net_profile.verbose_log_output=0 + +# [str]: Path to a folder containing the client key, certificate and CA bundle to enable https communication +patch.net_profile.cert_dir_path= + # [str]: Path to library implementing the piuio api for piuio emulation patch.piuio.emu_lib= diff --git a/src/main/hook/nxa/main.c b/src/main/hook/nxa/main.c index 64609bc..fcbb889 100644 --- a/src/main/hook/nxa/main.c +++ b/src/main/hook/nxa/main.c @@ -16,6 +16,7 @@ #include "hook/patch/main-loop.h" #include "hook/patch/microdog40.h" #include "hook/patch/mounts.h" +#include "hook/patch/net-profile.h" #include "hook/patch/piuio-exit.h" #include "hook/patch/piuio.h" #include "hook/patch/redir.h" @@ -280,6 +281,18 @@ static void nxahook_patch_profile() nxahook_profile_gen_init(); } +static void nxahook_patch_pumpnet(struct nxahook_options *options) +{ + if (options->patch.net.server && options->patch.net.machine_id != 0) { + patch_net_profile_init( + ASSET_GAME_VERSION_NXA, + options->patch.net.server, + options->patch.net.machine_id, + options->patch.net.cert_dir_path, + options->patch.net.verbose_log_output); + } +} + void nxahook_constructor(void) { /* Nothing here */ @@ -309,6 +322,11 @@ void nxahook_trap_before_main(int argc, char **argv) nxahook_patch_dongle_init(); nxahook_patch_hdd_check_init(); nxahook_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 + nxahook_patch_pumpnet(&options); nxahook_patch_profile(); free(game_data_path); @@ -318,6 +336,7 @@ void nxahook_trap_before_main(int argc, char **argv) void nxahook_trap_after_main(void) { + patch_net_profile_shutdown(); patch_piuio_shutdown(); } diff --git a/src/main/hook/nxa/options.c b/src/main/hook/nxa/options.c index 8d2368d..64b6a80 100644 --- a/src/main/hook/nxa/options.c +++ b/src/main/hook/nxa/options.c @@ -16,6 +16,10 @@ #define NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER "patch.net_profile.server" #define NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID \ "patch.net_profile.machine_id" +#define NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT \ + "patch.net_profile.verbose_log_output" +#define NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH \ + "patch.net_profile.cert_dir_path" #define NXAHOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB "patch.piuio.emu_lib" #define NXAHOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV \ "patch.piuio_exit.test_serv" @@ -118,6 +122,25 @@ const struct util_options_def nxahook_options_def[] = { .is_secret_data = true, .default_value.str = "0000000000000000", }, + { + .name = NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT, + .description = "Enable verbose log output for pumpnet related things, " + "e.g. logging network traffic", + .param = 'v', + .type = UTIL_OPTIONS_TYPE_BOOL, + .is_secret_data = false, + .default_value.b = false, + }, + { + .name = NXAHOOK_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", + .param = 'c', + .type = UTIL_OPTIONS_TYPE_STR, + .is_secret_data = false, + .default_value.str = NULL, + }, { .name = NXAHOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB, .description = @@ -212,11 +235,15 @@ bool nxahook_options_init( options_opt, NXAHOOK_OPTIONS_STR_PATCH_HOOK_MAIN_LOOP_X11_INPUT_HANDLER); options->patch.net.server = util_options_get_str( options_opt, NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_SERVER); - options->patch.net.machine_id = strtoul( + options->patch.net.machine_id = strtoull( util_options_get_str( options_opt, NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_MACHINE_ID), NULL, 16); + options->patch.net.verbose_log_output = util_options_get_bool( + options_opt, NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_VERBOSE_LOG_OUTPUT); + options->patch.net.cert_dir_path = util_options_get_str( + options_opt, NXAHOOK_OPTIONS_STR_PATCH_NET_PROFILE_CERT_DIR_PATH); options->patch.piuio.api_lib = util_options_get_str( options_opt, NXAHOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB); options->patch.piuio.exit_test_serv = util_options_get_bool( diff --git a/src/main/hook/nxa/options.h b/src/main/hook/nxa/options.h index a7717e6..bca36c4 100644 --- a/src/main/hook/nxa/options.h +++ b/src/main/hook/nxa/options.h @@ -31,7 +31,9 @@ struct nxahook_options { struct net { const char *server; - uint32_t machine_id; + uint64_t machine_id; + bool verbose_log_output; + const char *cert_dir_path; } net; struct piuio { diff --git a/src/main/hook/patch/net-profile.c b/src/main/hook/patch/net-profile.c index 8413550..4c186bb 100644 --- a/src/main/hook/patch/net-profile.c +++ b/src/main/hook/patch/net-profile.c @@ -5,6 +5,8 @@ #include "asset/nx2/lib/usb-rank.h" #include "asset/nx2/lib/usb-save.h" +#include "asset/nxa/lib/usb-rank.h" +#include "asset/nxa/lib/usb-save.h" #include "capnhook/hook/filehook.h" @@ -77,25 +79,44 @@ static bool _patch_net_profile_close_pumpnet_profile_file( static const struct profile_virtual_mnt_point_info _patch_net_profile_virtual_mnt_point_infos[] = { + {.player = + {{.file_info = + {{.player = 0, + .file_type = PUMPNET_LIB_FILE_TYPE_SAVE, + .file_path = "/mnt/0/nx2save.bin", + .file_size = ASSET_NX2_USB_SAVE_SIZE}, + {.player = 0, + .file_type = PUMPNET_LIB_FILE_TYPE_RANK, + .file_path = "/mnt/0/nx2rank.bin", + .file_size = ASSET_NX2_USB_RANK_SIZE}}}, + {.file_info = + {{.player = 1, + .file_type = PUMPNET_LIB_FILE_TYPE_SAVE, + .file_path = "/mnt/1/nx2save.bin", + .file_size = ASSET_NX2_USB_SAVE_SIZE}, + {.player = 1, + .file_type = PUMPNET_LIB_FILE_TYPE_RANK, + .file_path = "/mnt/1/nx2rank.bin", + .file_size = ASSET_NX2_USB_RANK_SIZE}}}}}, {.player = { {.file_info = {{.player = 0, .file_type = PUMPNET_LIB_FILE_TYPE_SAVE, - .file_path = "/mnt/0/nx2save.bin", - .file_size = ASSET_NX2_USB_SAVE_SIZE}, + .file_path = "/mnt/0/nxasave.bin", + .file_size = ASSET_NXA_USB_SAVE_SIZE}, {.player = 0, .file_type = PUMPNET_LIB_FILE_TYPE_RANK, - .file_path = "/mnt/0/nx2rank.bin", - .file_size = ASSET_NX2_USB_RANK_SIZE}}}, + .file_path = "/mnt/0/nxarank.bin", + .file_size = ASSET_NXA_USB_RANK_SIZE}}}, {.file_info = {{.player = 1, .file_type = PUMPNET_LIB_FILE_TYPE_SAVE, - .file_path = "/mnt/1/nx2save.bin", - .file_size = ASSET_NX2_USB_SAVE_SIZE}, + .file_path = "/mnt/1/nxasave.bin", + .file_size = ASSET_NXA_USB_SAVE_SIZE}, {.player = 1, .file_type = PUMPNET_LIB_FILE_TYPE_RANK, - .file_path = "/mnt/1/nx2rank.bin", - .file_size = ASSET_NX2_USB_RANK_SIZE}}}, + .file_path = "/mnt/1/nxarank.bin", + .file_size = ASSET_NXA_USB_RANK_SIZE}}}, }}}; static const struct profile_virtual_mnt_point_info @@ -566,10 +587,10 @@ void patch_net_profile_init( idx = 0; break; - // case PUMPNET_LIB_GAME_NXA: - // idx = 1; - // break; - // + case ASSET_GAME_VERSION_NXA: + idx = 1; + break; + // case PUMPNET_LIB_GAME_FST: // idx = 2; // break; @@ -581,7 +602,6 @@ void patch_net_profile_init( // case PUMPNET_LIB_GAME_F2: // idx = 4; // break; - case ASSET_GAME_VERSION_NXA: case ASSET_GAME_VERSION_FIESTA: case ASSET_GAME_VERSION_FIESTA_EX: case ASSET_GAME_VERSION_FIESTA_2: diff --git a/src/main/pumpnet/lib/pumpnet.c b/src/main/pumpnet/lib/pumpnet.c index a3be8ae..bcf9af8 100644 --- a/src/main/pumpnet/lib/pumpnet.c +++ b/src/main/pumpnet/lib/pumpnet.c @@ -29,6 +29,9 @@ static char *_pumpnet_lib_get_endpoint_save( case ASSET_GAME_VERSION_NX2: return util_str_merge(server_addr, USBPROFILE_ENDPOINT "/nx2/save"); + case ASSET_GAME_VERSION_NXA: + return util_str_merge(server_addr, USBPROFILE_ENDPOINT "/nxa/save"); + default: log_die("Unsupported game version %d", game); return NULL; @@ -42,6 +45,9 @@ static char *_pumpnet_lib_get_endpoint_rank( case ASSET_GAME_VERSION_NX2: return util_str_merge(server_addr, USBPROFILE_ENDPOINT "/nx2/rank"); + case ASSET_GAME_VERSION_NXA: + return util_str_merge(server_addr, USBPROFILE_ENDPOINT "/nxa/rank"); + default: log_die("Unsupported game version %d", game); return NULL;