From 729c223091646561c78184a2a72ca45b0e233dec Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 22 Feb 2023 16:15:20 +0100 Subject: [PATCH] Fix connecting to a 3DS on Mii Maker --- Dockerfile | 4 ++-- README.md | 13 ++++++++---- src/main.cpp | 19 ++++++++++++++++++ src/utils/config.cpp | 9 +++++++++ src/utils/config.h | 47 +++++++++++++++++++++++--------------------- 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32c477b..cdfda2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM wiiuenv/devkitppc:20221228 +FROM wiiuenv/devkitppc:20230218 -COPY --from=wiiuenv/wiiupluginsystem:20230126 /artifacts $DEVKITPRO +COPY --from=wiiuenv/wiiupluginsystem:20230215 /artifacts $DEVKITPRO COPY --from=wiiuenv/libnotifications:20230126 /artifacts $DEVKITPRO COPY --from=wiiuenv/librpxloader:20220903 /artifacts $DEVKITPRO COPY --from=wiiuenv/libcurlwrapper:20230121 /artifacts $DEVKITPRO diff --git a/README.md b/README.md index f53822d..585833a 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,16 @@ Provides some simple patches for Wii U Menu and checks for Aroma updates. ## Usage Via the plugin config menu (press L, DPAD Down and Minus on the GamePad, Pro Controller or Classic Controller) you can configure the plugin. The available options are the following: + - **Wii U Menu patches**: - - Avoid "Format" dialog on Wii U Menu (UStealth): (Default is false) - - Skips the "Format"-nag when launching the Wii U Menu with a non-formatted external drive. - - Skip "Shutdown warning" on boot: (Default is true) - - Hide the "Shutdown warning" after shutting the console down by pressing the power button for 4 seconds. + - Avoid "Format" dialog on Wii U Menu (UStealth): (Default is false) + - Skips the "Format"-nag when launching the Wii U Menu with a non-formatted external drive. + - Skip "Shutdown warning" on boot: (Default is true) + - Hide the "Shutdown warning" after shutting the console down by pressing the power button for 4 seconds. +- **Other patches**: + - Allow error notifications (Default is true) + - Fix connecting to a 3DS in Mii Maker: (Default is true) + - Forces "nn::ndm::SuspendDaemonsAndDisconnectIfWireless" to always return success, this fixes connecting to the 3DS in Mii Maker. ## Building diff --git a/src/main.cpp b/src/main.cpp index f7a3739..15c63da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,8 @@ INITIALIZE_PLUGIN() { if (cat_config != nullptr) { LOAD_BOOL_FROM_STORAGE(cat_config, USTEALTH_CONFIG_ID, gActivateUStealth); LOAD_BOOL_FROM_STORAGE(cat_config, POWEROFFWARNING_CONFIG_ID, gSkip4SecondOffStatusCheck); + LOAD_BOOL_FROM_STORAGE(cat_config, FORCE_NDM_SUSPEND_SUCCESS_CONFIG_ID, gForceNDMSuspendSuccess); + LOAD_BOOL_FROM_STORAGE(cat_config, ALLOW_ERROR_NOTIFICATIONS, gAllowErrorNotifications); } wups_storage_item_t *cat_other = nullptr; @@ -92,6 +94,22 @@ DEINITIALIZE_PLUGIN() { RPXLoader_DeInitLibrary(); } +DECL_FUNCTION(uint32_t, SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv) { + auto res = real_SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv(); + + if (res != 0) { + DEBUG_FUNCTION_LINE_ERR("SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv returned %08X", res); + if (res == 0xA0B12C80 && gForceNDMSuspendSuccess) { + DEBUG_FUNCTION_LINE_INFO("Patch SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv to return 0 instead of %08X", res); + return 0; + } else if (gAllowErrorNotifications) { + NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 10.0f); + NotificationModule_AddErrorNotification("\"nn::ndm::SuspendDaemonsAndDisconnectIfWireless\" failed. Connection to 3DS not possible"); + } + } + return res; +} + DECL_FUNCTION(int32_t, IsStorageMaybePcFormatted, bool *isPcFormatted, nn::spm::StorageIndex *index) { // Make sure the index is valid int32_t res = real_IsStorageMaybePcFormatted(isPcFormatted, index); @@ -114,3 +132,4 @@ DECL_FUNCTION(bool, MCP_Get4SecondOffStatus, int32_t handle) { // Only replace for the Wii U Menu WUPS_MUST_REPLACE_FOR_PROCESS(IsStorageMaybePcFormatted, WUPS_LOADER_LIBRARY_NN_SPM, IsStorageMaybePcFormatted__Q2_2nn3spmFPbQ3_2nn3spm12StorageIndex, WUPS_FP_TARGET_PROCESS_WII_U_MENU); WUPS_MUST_REPLACE_FOR_PROCESS(MCP_Get4SecondOffStatus, WUPS_LOADER_LIBRARY_COREINIT, MCP_Get4SecondOffStatus, WUPS_FP_TARGET_PROCESS_WII_U_MENU); +WUPS_MUST_REPLACE(SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv, WUPS_LOADER_LIBRARY_NN_NDM, SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index ed5305a..314be15 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -4,6 +4,8 @@ bool gActivateUStealth = false; bool gSkip4SecondOffStatusCheck = true; bool gConfigMenuHintShown = false; bool gUpdateChecked = false; +bool gForceNDMSuspendSuccess = true; +bool gAllowErrorNotifications = true; std::string gLastHash = {}; void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) { @@ -11,6 +13,8 @@ void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) { if (WUPS_GetSubItem(nullptr, CAT_CONFIG, &cat_config) == WUPS_STORAGE_ERROR_SUCCESS) { PROCESS_BOOL_ITEM_CHANGED(cat_config, USTEALTH_CONFIG_ID, gActivateUStealth); PROCESS_BOOL_ITEM_CHANGED(cat_config, POWEROFFWARNING_CONFIG_ID, gSkip4SecondOffStatusCheck); + PROCESS_BOOL_ITEM_CHANGED(cat_config, FORCE_NDM_SUSPEND_SUCCESS_CONFIG_ID, gForceNDMSuspendSuccess); + PROCESS_BOOL_ITEM_CHANGED(cat_config, ALLOW_ERROR_NOTIFICATIONS, gAllowErrorNotifications); } else { DEBUG_FUNCTION_LINE_ERR("Failed to get sub item: %s", CAT_CONFIG); } @@ -28,10 +32,15 @@ WUPS_GET_CONFIG() { WUPSConfigCategoryHandle cat; WUPSConfig_AddCategoryByNameHandled(config, "Wii U Menu patches", &cat); + WUPSConfigCategoryHandle catOther; + WUPSConfig_AddCategoryByNameHandled(config, "Other patches", &catOther); WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, USTEALTH_CONFIG_ID, "Avoid \"Format\" dialog on Wii U Menu", gActivateUStealth, &boolItemChangedConfig); WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, POWEROFFWARNING_CONFIG_ID, "Skip \"Shutdown warning\" on boot", gSkip4SecondOffStatusCheck, &boolItemChangedConfig); + WUPSConfigItemBoolean_AddToCategoryHandled(config, catOther, ALLOW_ERROR_NOTIFICATIONS, "Allow error notifications", gAllowErrorNotifications, &boolItemChangedConfig); + WUPSConfigItemBoolean_AddToCategoryHandled(config, catOther, FORCE_NDM_SUSPEND_SUCCESS_CONFIG_ID, "Fix connecting to a 3DS in Mii Maker", gForceNDMSuspendSuccess, &boolItemChangedConfig); + return config; } diff --git a/src/utils/config.h b/src/utils/config.h index 9b52ff3..bdf6086 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -4,37 +4,38 @@ #include #include +#define CAT_CONFIG "config" +#define CAT_OTHER "other" -#define CAT_CONFIG "config" -#define CAT_OTHER "other" - -#define USTEALTH_CONFIG_ID "ustealth" -#define POWEROFFWARNING_CONFIG_ID "SkipPowerOffWarning" +#define USTEALTH_CONFIG_ID "ustealth" +#define POWEROFFWARNING_CONFIG_ID "SkipPowerOffWarning" +#define FORCE_NDM_SUSPEND_SUCCESS_CONFIG_ID "forceNDMSuspendSuccess" +#define ALLOW_ERROR_NOTIFICATIONS "allowErrorNotifications" -#define CONFIG_MENU_HINT_SHOWN_ID "configMenuHintShown" -#define LAST_UPDATE_HASH_ID "lastUpdateHash" +#define CONFIG_MENU_HINT_SHOWN_ID "configMenuHintShown" +#define LAST_UPDATE_HASH_ID "lastUpdateHash" -#define LOAD_BOOL_FROM_STORAGE(__cat, config_name, __variable__) \ - if ((storageRes = WUPS_GetBool(__cat, config_name, &__variable__)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \ - if (WUPS_StoreBool(__cat, config_name, __variable__) != WUPS_STORAGE_ERROR_SUCCESS) { \ - DEBUG_FUNCTION_LINE_WARN("Failed to store bool"); \ - } \ - } else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \ - DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ - } \ - while (0) - -#define LOAD_STRING_FROM_STORAGE(__cat, config_name, __string, __string_length) \ - if ((storageRes = WUPS_GetString(__cat, config_name, __string, __string_length)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \ - if (WUPS_StoreString(__cat, config_name, __string) != WUPS_STORAGE_ERROR_SUCCESS) { \ - DEBUG_FUNCTION_LINE_WARN("Failed to store string"); \ +#define LOAD_BOOL_FROM_STORAGE(__cat, config_name, __variable__) \ + if ((storageRes = WUPS_GetBool(__cat, config_name, &__variable__)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \ + if (WUPS_StoreBool(__cat, config_name, __variable__) != WUPS_STORAGE_ERROR_SUCCESS) { \ + DEBUG_FUNCTION_LINE_WARN("Failed to store bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ } \ } else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \ DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ } \ while (0) +#define LOAD_STRING_FROM_STORAGE(__cat, config_name, __string, __string_length) \ + if ((storageRes = WUPS_GetString(__cat, config_name, __string, __string_length)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \ + if (WUPS_StoreString(__cat, config_name, __string) != WUPS_STORAGE_ERROR_SUCCESS) { \ + DEBUG_FUNCTION_LINE_WARN("Failed to store string %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ + } \ + } else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \ + DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \ + } \ + while (0) + #define PROCESS_BOOL_ITEM_CHANGED(cat, __config__name, __variable__) \ if (std::string_view(item->configId) == __config__name) { \ DEBUG_FUNCTION_LINE_ERR("New value in %s: %d", __config__name, newValue); \ @@ -48,4 +49,6 @@ extern bool gActivateUStealth; extern bool gSkip4SecondOffStatusCheck; extern bool gConfigMenuHintShown; extern std::string gLastHash; -extern bool gUpdateChecked; \ No newline at end of file +extern bool gUpdateChecked; +extern bool gForceNDMSuspendSuccess; +extern bool gAllowErrorNotifications; \ No newline at end of file