diff --git a/Makefile b/Makefile index 8c961de..72a3a66 100644 --- a/Makefile +++ b/Makefile @@ -21,9 +21,9 @@ WUT_ROOT := $(DEVKITPRO)/wut #------------------------------------------------------------------------------- TARGET := Inkay-pretendo BUILD := build -SOURCES := src src/patches src/utils src/ext/inih +SOURCES := src src/patches src/utils src/ext/inih common DATA := data -INCLUDES := src src/ext/inih +INCLUDES := src src/ext/inih src/lang common #------------------------------------------------------------------------------- # options for code generation @@ -103,7 +103,7 @@ all: $(BUILD) $(BUILD): - @[ -d $@ ] || mkdir -p $@ + @$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD)) @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile @$(MAKE) --no-print-directory -C $(CURDIR)/plugin -f $(CURDIR)/plugin/Makefile mkdir -p dist/ diff --git a/plugin/src/Notification.cpp b/common/Notification.cpp similarity index 100% rename from plugin/src/Notification.cpp rename to common/Notification.cpp diff --git a/plugin/src/Notification.h b/common/Notification.h similarity index 100% rename from plugin/src/Notification.h rename to common/Notification.h diff --git a/common/lang.cpp b/common/lang.cpp new file mode 100644 index 0000000..3f32b17 --- /dev/null +++ b/common/lang.cpp @@ -0,0 +1,44 @@ +// +// Created by ash on 21/11/24. +// + +#include "lang.h" + +config_strings get_config_strings(nn::swkbd::LanguageType language) { + switch (language) { + case nn::swkbd::LanguageType::English: + default: return { +#include "en_US.lang" + }; + case nn::swkbd::LanguageType::Spanish: return { +#include "es_ES.lang" + }; + case nn::swkbd::LanguageType::French: return { +#include "fr_FR.lang" + }; + case nn::swkbd::LanguageType::Italian: return { +#include "it_IT.lang" + }; + case nn::swkbd::LanguageType::German: return { +#include "de_DE.lang" + }; + case nn::swkbd::LanguageType::SimplifiedChinese: return { +#include "zh_CN.lang" + }; + case nn::swkbd::LanguageType::TraditionalChinese: return { +#include "zh_Hant.lang" + }; + case nn::swkbd::LanguageType::Portuguese: return { +#include "pt_BR.lang" + }; + case nn::swkbd::LanguageType::Japanese: return { +#include "ja_JP.lang" + }; + case nn::swkbd::LanguageType::Dutch: return { +#include "nl_NL.lang" + }; + case nn::swkbd::LanguageType::Russian: return { +#include "ru_RU.lang" + }; + } +} diff --git a/common/lang.h b/common/lang.h new file mode 100644 index 0000000..6e557fe --- /dev/null +++ b/common/lang.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +struct config_strings { + const char *plugin_name; + std::string_view network_category; + std::string_view connect_to_network_setting; + std::string_view other_category; + std::string_view reset_wwp_setting; + std::string_view press_a_action; + std::string_view restart_to_apply_action; + std::string_view need_menu_action; + std::string_view using_nintendo_network; + std::string_view using_pretendo_network; + std::string_view multiplayer_port_display; + std::string_view module_not_found; + std::string_view module_init_not_found; +}; + +config_strings get_config_strings(nn::swkbd::LanguageType language); diff --git a/src/utils/sysconfig.cpp b/common/sysconfig.cpp similarity index 83% rename from src/utils/sysconfig.cpp rename to common/sysconfig.cpp index 97ae4a3..102a3cf 100644 --- a/src/utils/sysconfig.cpp +++ b/common/sysconfig.cpp @@ -1,6 +1,5 @@ /* Copyright 2024 Pretendo Network contributors Copyright 2024 Ash Logan - Copyright 2023 Maschell Copyright 2020-2022 V10lator Copyright 2022 Xpl0itU @@ -81,8 +80,8 @@ static void get_mcp_config() { mcp_os_version = os_version; DEBUG_FUNCTION_LINE_VERBOSE("Running on %d.%d.%d%c; %s%s", - os_version.major, os_version.minor, os_version.patch, os_version.region - config.code_id, config.serial_id + os_version.major, os_version.minor, os_version.patch, os_version.region + config.code_id, config.serial_id ); } @@ -97,3 +96,20 @@ MCPSystemVersion get_console_os_version() { return mcp_os_version.value_or((MCPSystemVersion) { .major = 5, .minor = 5, .patch = 5, .region = 'E' }); } + +static inline int digit(char a) { + if (a < '0' || a > '9') return 0; + return a - '0'; +} + +unsigned short get_console_peertopeer_port() { + const char * serial = get_console_serial(); + + unsigned short port = 50000 + + (digit(serial[4]) * 1000) + + (digit(serial[5]) * 100 ) + + (digit(serial[6]) * 10 ) + + (digit(serial[7]) * 1 ); + + return port; +} diff --git a/src/utils/sysconfig.h b/common/sysconfig.h similarity index 86% rename from src/utils/sysconfig.h rename to common/sysconfig.h index 3b3e075..d517fc7 100644 --- a/src/utils/sysconfig.h +++ b/common/sysconfig.h @@ -11,5 +11,6 @@ nn::swkbd::LanguageType get_system_language(); const char * get_console_serial(); MCPSystemVersion get_console_os_version(); +unsigned short get_console_peertopeer_port(); #endif //INKAY_SYSCONFIG_H diff --git a/src/utils/scope_exit.h b/common/utils/scope_exit.h similarity index 100% rename from src/utils/scope_exit.h rename to common/utils/scope_exit.h diff --git a/plugin/Makefile b/plugin/Makefile index 125fb0c..fee7a0b 100644 --- a/plugin/Makefile +++ b/plugin/Makefile @@ -21,9 +21,9 @@ WUMS_ROOT := $(DEVKITPRO)/wums #------------------------------------------------------------------------------- TARGET := Inkay-pretendo BUILD := build -SOURCES := src src/utils +SOURCES := src src/utils ../common DATA := data -INCLUDES := src ../src/lang +INCLUDES := src ../src/lang ../common #DEBUG := 1 #------------------------------------------------------------------------------- diff --git a/plugin/src/config.cpp b/plugin/src/config.cpp index a0fc590..5ce07a8 100644 --- a/plugin/src/config.cpp +++ b/plugin/src/config.cpp @@ -19,65 +19,29 @@ #include "wut_extra.h" #include "utils/logger.h" -#include "utils/sysconfig.h" +#include "sysconfig.h" +#include "lang.h" #include #include #include #include +#include #include #include #include #include #include +#include + +static config_strings strings; bool Config::connect_to_network = true; bool Config::need_relaunch = false; bool Config::unregister_task_item_pressed = false; bool Config::is_wiiu_menu = false; -static config_strings strings; - -config_strings get_config_strings(nn::swkbd::LanguageType language) { - switch (language) { - case nn::swkbd::LanguageType::English: - default: return { -#include "en_US.lang" - }; - case nn::swkbd::LanguageType::Spanish: return { -#include "es_ES.lang" - }; - case nn::swkbd::LanguageType::French: return { -#include "fr_FR.lang" - }; - case nn::swkbd::LanguageType::Italian: return { -#include "it_IT.lang" - }; - case nn::swkbd::LanguageType::German: return { -#include "de_DE.lang" - }; - case nn::swkbd::LanguageType::SimplifiedChinese: return { -#include "zh_CN.lang" - }; - case nn::swkbd::LanguageType::TraditionalChinese: return { -#include "zh_Hant.lang" - }; - case nn::swkbd::LanguageType::Portuguese: return { -#include "pt_BR.lang" - }; - case nn::swkbd::LanguageType::Japanese: return { -#include "ja_JP.lang" - }; - case nn::swkbd::LanguageType::Dutch: return { -#include "nl_NL.lang" - }; - case nn::swkbd::LanguageType::Russian: return { -#include "ru_RU.lang" - }; - } -} - static WUPSConfigAPICallbackStatus report_error(WUPSConfigAPIStatus err) { DEBUG_FUNCTION_LINE_VERBOSE("WUPS config error: %s", WUPSConfigAPI_GetStatusStr(err)); return WUPSCONFIG_API_CALLBACK_RESULT_ERROR; @@ -174,6 +138,12 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa res = network_cat->add(std::move(*connect_item), err); if (!res) return report_error(err); + { + std::string multiplayer_port_text = std::vformat(strings.multiplayer_port_display, std::make_format_args(get_console_peertopeer_port())); + res = network_cat->add(WUPSConfigItemStub::Create(multiplayer_port_text), err); + if (!res) return report_error(err); + } + res = root.add(std::move(*network_cat), err); if (!res) return report_error(err); diff --git a/plugin/src/config.h b/plugin/src/config.h index 845f9f5..0928d5e 100644 --- a/plugin/src/config.h +++ b/plugin/src/config.h @@ -5,9 +5,6 @@ #ifndef INKAY_CONFIG_H #define INKAY_CONFIG_H -#include -#include - class Config { public: static void Init(); @@ -24,21 +21,4 @@ public: static bool unregister_task_item_pressed; }; -struct config_strings { - const char *plugin_name; - std::string_view network_category; - std::string_view connect_to_network_setting; - std::string_view other_category; - std::string_view reset_wwp_setting; - std::string_view press_a_action; - std::string_view restart_to_apply_action; - std::string_view need_menu_action; - std::string_view using_nintendo_network; - std::string_view using_pretendo_network; - std::string_view module_not_found; - std::string_view module_init_not_found; -}; - -config_strings get_config_strings(nn::swkbd::LanguageType language); - #endif //INKAY_CONFIG_H diff --git a/plugin/src/main.cpp b/plugin/src/main.cpp index dfb4ba6..4845a38 100644 --- a/plugin/src/main.cpp +++ b/plugin/src/main.cpp @@ -16,33 +16,12 @@ along with this program. If not, see . */ -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include #include #include "config.h" #include "module.h" -#include "Notification.h" - -#include -#include -#include -#include -#include - -#include #define INKAY_VERSION "v2.6.0" @@ -60,8 +39,6 @@ WUPS_USE_STORAGE("inkay"); WUPS_USE_WUT_DEVOPTAB(); -#include "utils/sysconfig.h" - INITIALIZE_PLUGIN() { WHBLogCafeInit(); WHBLogUdpInit(); diff --git a/plugin/src/module.cpp b/plugin/src/module.cpp index 77a2249..5fd9c2a 100644 --- a/plugin/src/module.cpp +++ b/plugin/src/module.cpp @@ -20,7 +20,8 @@ #include "config.h" #include "Notification.h" #include "utils/logger.h" -#include "utils/sysconfig.h" +#include "sysconfig.h" +#include "lang.h" static OSDynLoad_Module module; static void (*moduleInitialize)(bool) = nullptr; diff --git a/plugin/src/utils/sysconfig.cpp b/plugin/src/utils/sysconfig.cpp deleted file mode 100644 index cef6d78..0000000 --- a/plugin/src/utils/sysconfig.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2024 Pretendo Network contributors - Copyright 2024 Ash Logan - Copyright 2020-2022 V10lator - Copyright 2022 Xpl0itU - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "sysconfig.h" -#include "utils/logger.h" - -#include -#include - -nn::swkbd::LanguageType get_system_language() { - static std::optional cached_language{}; - if (cached_language) return *cached_language; - - UCHandle handle = UCOpen(); - if (handle >= 0) { - nn::swkbd::LanguageType language; - - UCSysConfig settings __attribute__((__aligned__(0x40))) = { - .name = "cafe.language", - .access = 0, - .dataType = UC_DATATYPE_UNSIGNED_INT, - .error = UC_ERROR_OK, - .dataSize = sizeof(language), - .data = &language, - }; - - UCError err = UCReadSysConfig(handle, 1, &settings); - UCClose(handle); - if (err != UC_ERROR_OK) { - DEBUG_FUNCTION_LINE("Error reading UC: %d!", err); - return nn::swkbd::LanguageType::English; - } else { - DEBUG_FUNCTION_LINE_VERBOSE("System language found: %d", language); - cached_language = language; - return language; - } - } else { - DEBUG_FUNCTION_LINE("Error opening UC: %d", handle); - return nn::swkbd::LanguageType::English; - } -} diff --git a/plugin/src/utils/sysconfig.h b/plugin/src/utils/sysconfig.h deleted file mode 100644 index 3bac817..0000000 --- a/plugin/src/utils/sysconfig.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// Created by ash on 9/04/24. -// - -#ifndef INKAY_SYSCONFIG_H -#define INKAY_SYSCONFIG_H - -#include - -nn::swkbd::LanguageType get_system_language(); - -#endif //INKAY_SYSCONFIG_H diff --git a/src/Notification.cpp b/src/Notification.cpp deleted file mode 100644 index cc6177e..0000000 --- a/src/Notification.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2024 Pretendo Network contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "Notification.h" -#include -#include - -void ShowNotification(const char* notification) { - auto err1 = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, - NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, true); - auto err2 = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, - NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, - 15.0f); - - if (err1 != NOTIFICATION_MODULE_RESULT_SUCCESS || err2 != NOTIFICATION_MODULE_RESULT_SUCCESS) return; - - NotificationModule_AddInfoNotification(notification); -} diff --git a/src/Notification.h b/src/Notification.h deleted file mode 100644 index ebdc7a3..0000000 --- a/src/Notification.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void ShowNotification(const char* notification); diff --git a/src/config.cpp b/src/config.cpp index 67519c8..56c8740 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -20,44 +20,3 @@ bool Config::connect_to_network = false; bool Config::initialized = false; bool Config::shown_uninitialized_warning = false; - -static config_strings strings; - -config_strings get_config_strings(nn::swkbd::LanguageType language) { - switch (language) { - case nn::swkbd::LanguageType::English: - default: return { -#include "lang/en_US.lang" - }; - case nn::swkbd::LanguageType::Spanish: return { -#include "lang/es_ES.lang" - }; - case nn::swkbd::LanguageType::French: return { -#include "lang/fr_FR.lang" - }; - case nn::swkbd::LanguageType::Italian: return { -#include "lang/it_IT.lang" - }; - case nn::swkbd::LanguageType::German: return { -#include "lang/de_DE.lang" - }; - case nn::swkbd::LanguageType::SimplifiedChinese: return { -#include "lang/zh_CN.lang" - }; - case nn::swkbd::LanguageType::TraditionalChinese: return { -#include "lang/zh_Hant.lang" - }; - case nn::swkbd::LanguageType::Portuguese: return { -#include "lang/pt_BR.lang" - }; - case nn::swkbd::LanguageType::Japanese: return { -#include "lang/ja_JP.lang" - }; - case nn::swkbd::LanguageType::Dutch: return { -#include "lang/nl_NL.lang" - }; - case nn::swkbd::LanguageType::Russian: return { -#include "lang/ru_RU.lang" - }; - } -} diff --git a/src/config.h b/src/config.h index 3d6f08f..96f6775 100644 --- a/src/config.h +++ b/src/config.h @@ -17,22 +17,4 @@ public: static bool shown_uninitialized_warning; }; -struct config_strings { - const char *plugin_name; - std::string_view network_category; - std::string_view connect_to_network_setting; - std::string_view other_category; - std::string_view reset_wwp_setting; - std::string_view press_a_action; - std::string_view restart_to_apply_action; - std::string_view need_menu_action; - std::string_view using_nintendo_network; - std::string_view using_pretendo_network; - std::string_view multiplayer_port_display; - std::string_view module_not_found; - std::string_view module_init_not_found; -}; - -config_strings get_config_strings(nn::swkbd::LanguageType language); - #endif //INKAY_CONFIG_H diff --git a/src/main.cpp b/src/main.cpp index 0d2c066..12ba0e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,8 @@ WUMS_USE_WUT_DEVOPTAB(); #include "patches/eshop_applet.h" #include "patches/olv_applet.h" #include "patches/game_peertopeer.h" -#include "utils/sysconfig.h" +#include "sysconfig.h" +#include "lang.h" //thanks @Gary#4139 :p static void write_string(uint32_t addr, const char *str) { diff --git a/src/patches/game_peertopeer.cpp b/src/patches/game_peertopeer.cpp index 01a6fc6..c464117 100644 --- a/src/patches/game_peertopeer.cpp +++ b/src/patches/game_peertopeer.cpp @@ -15,30 +15,13 @@ #include #include "game_peertopeer.h" -#include "utils/sysconfig.h" +#include "sysconfig.h" #include "utils/logger.h" #include "utils/rpl_info.h" #include "utils/replace_mem.h" #include -static inline int digit(char a) { - if (a < '0' || a > '9') return 0; - return a - '0'; -} - -unsigned short peertopeer_port() { - const char * serial = get_console_serial(); - - unsigned short port = 50000 + - (digit(serial[4]) * 1000) + - (digit(serial[5]) * 100 ) + - (digit(serial[6]) * 10 ) + - (digit(serial[7]) * 1 ); - - return port; -} - static void minecraft_peertopeer_patch() { std::optional minecraft = search_for_rpl("Minecraft.Client.rpx"); if (!minecraft) { @@ -46,7 +29,7 @@ static void minecraft_peertopeer_patch() { return; } - auto port = peertopeer_port(); + auto port = get_console_peertopeer_port(); DEBUG_FUNCTION_LINE_VERBOSE("Will use port %d. %08x", port, minecraft->textAddr); uint32_t *target_func = rpl_addr(*minecraft, 0x03579530); diff --git a/src/patches/game_peertopeer.h b/src/patches/game_peertopeer.h index e26862b..8211c00 100644 --- a/src/patches/game_peertopeer.h +++ b/src/patches/game_peertopeer.h @@ -14,4 +14,3 @@ #pragma once void peertopeer_patch(); -unsigned short peertopeer_port();