diff --git a/Inkay-pretendo.wps b/Inkay-pretendo.wps index 38cc626..5c11d8c 100644 Binary files a/Inkay-pretendo.wps and b/Inkay-pretendo.wps differ diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 0000000..560a262 --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,85 @@ +// +// Created by ash on 10/12/22. +// + +#include "config.h" + +#include "utils/logger.h" +#include +#include + +#include +#include + +bool Config::connect_to_network = true; +bool Config::need_relaunch = false; + +void Config::Init() { + WUPSStorageError storageRes = WUPS_OpenStorage(); + if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + } + else { + // Try to get value from storage + if ((storageRes = WUPS_GetBool(nullptr, "connect_to_network", &connect_to_network)) == WUPS_STORAGE_ERROR_NOT_FOUND) { + bool skipPatches = false; + if ((storageRes = WUPS_GetBool(nullptr, "skipPatches", &skipPatches)) != WUPS_STORAGE_ERROR_NOT_FOUND) { + // Migrate old config value + connect_to_network = !skipPatches; + } + // Add the value to the storage if it's missing. + if (WUPS_StoreBool(nullptr, "connect_to_network", connect_to_network) != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to store bool"); + } + } + else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + } + + // Close storage + if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to close storage"); + } + } +} + +static void connect_to_network_changed(ConfigItemBoolean* item, bool new_value) { + DEBUG_FUNCTION_LINE("New value in skipPatchesChanged: %d", new_value); + if (new_value != Config::connect_to_network) { + Config::need_relaunch = true; + } + Config::connect_to_network = new_value; + WUPS_StoreInt(nullptr, "connect_to_network", Config::connect_to_network); +} + +WUPS_GET_CONFIG() { + // We open the storage so we can persist the configuration the user did. + if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to open storage"); + return 0; + } + + WUPSConfigHandle config; + WUPSConfig_CreateHandled(&config, "Inkay"); + + WUPSConfigCategoryHandle cat; + WUPSConfig_AddCategoryByNameHandled(config, "Patching", &cat); + + WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, "connect_to_network", "Connect to the Pretendo network", Config::connect_to_network, &connect_to_network_changed); + + return config; +} + +WUPS_CONFIG_CLOSED() { + // Save all changes + if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE("Failed to close storage"); + } + + if (Config::need_relaunch) { + // Need to reload the console so the patches reset + OSForceFullRelaunch(); + SYSLaunchMenu(); + Config::need_relaunch = false; + } +} diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..1d97de1 --- /dev/null +++ b/src/config.h @@ -0,0 +1,19 @@ +// +// Created by ash on 10/12/22. +// + +#ifndef INKAY_CONFIG_H +#define INKAY_CONFIG_H + +class Config { +public: + static void Init(); + + // wups config items + static bool connect_to_network; + + // private stuff + static bool need_relaunch; +}; + +#endif //INKAY_CONFIG_H diff --git a/src/main.cpp b/src/main.cpp index 1edd5bf..2483d60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -24,11 +23,10 @@ #include #include #include -#include -#include #include "wut_extra.h" #include #include "url_patches.h" +#include "config.h" /** Mandatory plugin information. @@ -42,9 +40,6 @@ WUPS_PLUGIN_LICENSE("ISC"); WUPS_USE_STORAGE("inkay"); -bool skipPatches = false; -bool prevSkipValue = false; - #include #include @@ -94,29 +89,7 @@ static bool is555(MCP_SystemVersion version) { INITIALIZE_PLUGIN() { WHBLogUdpInit(); - WUPSStorageError storageRes = WUPS_OpenStorage(); - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - else { - // Try to get value from storage - if ((storageRes = WUPS_GetBool(nullptr, "skipPatches", &skipPatches)) == WUPS_STORAGE_ERROR_NOT_FOUND) { - // Add the value to the storage if it's missing. - if (WUPS_StoreBool(nullptr, "skipPatches", skipPatches) != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to store bool"); - } - } - else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - - prevSkipValue = skipPatches; - - // Close storage - if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to close storage"); - } - } + Config::Init(); auto res = Mocha_InitLibrary(); @@ -139,7 +112,7 @@ INITIALIZE_PLUGIN() { os_version.major, os_version.minor, os_version.patch, os_version.region ); - if (!skipPatches) { + if (Config::connect_to_network) { if (is555(os_version)) { Mocha_IOSUKernelWrite32(0xE1019F78, 0xE3A00001); // mov r0, #1 } @@ -165,50 +138,6 @@ DEINITIALIZE_PLUGIN() { Mocha_DeInitLibrary(); } -void skipPatchesChanged(ConfigItemBoolean* item, bool newValue) { - DEBUG_FUNCTION_LINE("New value in skipPatchesChanged: %d", newValue); - skipPatches = newValue; - // If the value has changed, we store it in the storage. - WUPS_StoreInt(nullptr, "skipPatches", skipPatches); -} - -WUPS_GET_CONFIG() { - // We open the storage so we can persist the configuration the user did. - if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to open storage"); - return 0; - } - - WUPSConfigHandle config; - WUPSConfig_CreateHandled(&config, "Inkay"); - - WUPSConfigCategoryHandle cat; - WUPSConfig_AddCategoryByNameHandled(config, "Patching", &cat); - - WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, "skipPatches", "Skip Pretendo Network patches", skipPatches, &skipPatchesChanged); - - return config; -} - -bool isRelaunching = false; - -WUPS_CONFIG_CLOSED() { - // Save all changes - if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE("Failed to close storage"); - } - - if (prevSkipValue != skipPatches) { - if (!isRelaunching) { - // Need to reload the console so the patches reset - OSForceFullRelaunch(); - SYSLaunchMenu(); - isRelaunching = true; - } - } - prevSkipValue = skipPatches; -} - bool checkForOlvLibs() { OSDynLoad_Module olv_handle = 0; OSDynLoad_Error dret; @@ -252,7 +181,7 @@ ON_APPLICATION_START() { return; } - if (!skipPatches) { + if (Config::connect_to_network) { OSDynLoad_Acquire("nn_olv", &olv_handle); DEBUG_FUNCTION_LINE("Inkay: olv! %08x\n", olv_handle); @@ -268,7 +197,6 @@ ON_APPLICATION_START() { else { DEBUG_FUNCTION_LINE("Inkay: Miiverse patches skipped."); } - } ON_APPLICATION_ENDS() {