feat!: Support for newer Aroma releases (#28)

* Fix aroma beta 17 incompatibilities (no network notification, no unregister boss tasks), and fix debug logger

* Update Dockerfile

* Fix logger.h

* Simplify notifcations

* Init nn::boss::Task

* Small fixes for the storage/config API usage

* Do a bunch of stuff, wish I knew what I did but I honestly forgot most of it (this is not considered a 100% functional commit

* Remove remnants of has_displayed_popup variables (not needed anymore)

* More notifications stuff

* Even more notifications stuff

* Fix notifications (yay) (thanks maschell)

* Disable debug by default

* Fix compiler warnings

* Update some stuff, cant test have to go

---------

Co-authored-by: Maschell <Maschell@gmx.de>
This commit is contained in:
TraceEntertains 2024-05-13 01:45:43 -04:00 committed by GitHub
commit b02db3f20b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 200 additions and 187 deletions

View file

@ -20,9 +20,10 @@
#include "wut_extra.h"
#include "utils/logger.h"
#include "utils/sysconfig.h"
#include <wups.h>
#include <wups/storage.h>
#include <wups/config.h>
#include <wups/config_api.h>
#include <wups/config/WUPSConfigItemBoolean.h>
#include <coreinit/title.h>
@ -36,94 +37,6 @@ bool Config::need_relaunch = false;
bool Config::unregister_task_item_pressed = false;
bool Config::is_wiiu_menu = 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");
}
}
uint64_t current_title_id = OSGetTitleID();
uint64_t wiiu_menu_tid = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_WII_U_MENU);
Config::is_wiiu_menu = (current_title_id == wiiu_menu_tid);
}
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);
}
static void unregister_task_item_pressed_cb(void *context, WUPSConfigButtons button) {
if (!Config::unregister_task_item_pressed && Config::is_wiiu_menu && button == WUPS_CONFIG_BUTTON_A) {
nn::act::Initialize();
Initialize__Q2_2nn4bossFv();
for (uint8_t i = 1; i <= nn::act::GetNumOfAccounts(); i++)
{
if (nn::act::IsSlotOccupied(i) == true)
{
if (nn::act::IsNetworkAccountEx(i) == true)
{
nn::boss::Task task;
nn::act::PersistentId persistentId = nn::act::GetPersistentIdEx(i);
__ct__Q3_2nn4boss4TaskFv(&task);
Initialize__Q3_2nn4boss4TaskFPCcUi(&task, "oltopic", persistentId);
uint32_t res = Unregister__Q3_2nn4boss4TaskFv(&task);
WHBLogPrintf("Unregistered oltopic for: SlotNo %d | Persistent ID %08x -> 0x%08x", i, persistentId, res);
}
}
}
Finalize__Q2_2nn4bossFv();
nn::act::Finalize();
Config::unregister_task_item_pressed = !Config::unregister_task_item_pressed;
Config::need_relaunch = true;
}
}
static bool unregister_task_item_is_movement_allowed(void *context) {
return true;
}
struct config_strings {
const char* plugin_name;
const char* network_category;
const char* connect_to_network_setting;
const char* other_category;
const char* reset_wwp_setting;
const char* press_a_action;
const char* restart_to_apply_action;
const char* need_menu_action;
};
config_strings strings;
constexpr config_strings get_config_strings(nn::swkbd::LanguageType language) {
@ -140,6 +53,7 @@ constexpr config_strings get_config_strings(nn::swkbd::LanguageType language) {
.restart_to_apply_action = "Restart to apply",
.need_menu_action = "From WiiU menu only"
};
case nn::swkbd::LanguageType::Spanish:
return {
.plugin_name = "Inkay",
@ -151,6 +65,7 @@ constexpr config_strings get_config_strings(nn::swkbd::LanguageType language) {
.restart_to_apply_action = "Reinicia para confirmar",
.need_menu_action = "Sólo desde el menú de WiiU",
};
case nn::swkbd::LanguageType::French:
return {
.plugin_name = "Inkay",
@ -173,70 +88,136 @@ constexpr config_strings get_config_strings(nn::swkbd::LanguageType language) {
.restart_to_apply_action = "Riavvia per applicare",
.need_menu_action = "Solo dal menu WiiU",
};
case nn::swkbd::LanguageType::German:
return {
.plugin_name = "Inkay",
.network_category = "Netzwerkauswahl",
.connect_to_network_setting = "Verbinde zum Pretendo Network",
.other_category = "Andere Einstellungen",
.reset_wwp_setting = "Wara Wara Plaza zurücksetzen",
.press_a_action = "Drücke A",
.restart_to_apply_action = "Neustarten zum Anwenden",
.need_menu_action = "Nur vom Wii U-Menü aus",
.plugin_name = "Inkay",
.network_category = "Netzwerkauswahl",
.connect_to_network_setting = "Verbinde zum Pretendo Network",
.other_category = "Andere Einstellungen",
.reset_wwp_setting = "Wara Wara Plaza zurücksetzen",
.press_a_action = "Drücke A",
.restart_to_apply_action = "Neustarten zum Anwenden",
.need_menu_action = "Nur vom Wii U-Menü aus",
};
}
}
static void connect_to_network_changed(ConfigItemBoolean* item, bool new_value) {
DEBUG_FUNCTION_LINE("connect_to_network changed to: %d", new_value);
if (new_value != Config::connect_to_network) {
Config::need_relaunch = true;
}
Config::connect_to_network = new_value;
if (WUPSStorageAPI::Store<bool>("connect_to_network", Config::connect_to_network) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to save \"connect_to_network\" value (%d)", Config::connect_to_network);
}
}
static void unregister_task_item_on_input_cb(void *context, WUPSConfigSimplePadData input) {
if (!Config::unregister_task_item_pressed && Config::is_wiiu_menu && ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A)) {
nn::act::Initialize();
Initialize__Q2_2nn4bossFv();
for (uint8_t i = 1; i <= nn::act::GetNumOfAccounts(); i++)
{
if (nn::act::IsSlotOccupied(i) && nn::act::IsNetworkAccountEx(i))
{
nn::boss::Task task{};
nn::act::PersistentId persistentId = nn::act::GetPersistentIdEx(i);
__ct__Q3_2nn4boss4TaskFv(&task);
Initialize__Q3_2nn4boss4TaskFPCcUi(&task, "oltopic", persistentId);
// bypasses compiler warning about unused variable
#ifdef DEBUG
uint32_t res = Unregister__Q3_2nn4boss4TaskFv(&task);
DEBUG_FUNCTION_LINE_VERBOSE("Unregistered oltopic for: SlotNo %d | Persistent ID %08x -> 0x%08x", i, persistentId, res);
#else
Unregister__Q3_2nn4boss4TaskFv(&task);
#endif
}
}
Finalize__Q2_2nn4bossFv();
nn::act::Finalize();
Config::unregister_task_item_pressed = !Config::unregister_task_item_pressed;
Config::need_relaunch = true;
}
}
static int32_t unregister_task_item_get_display_value(void *context, char *out_buf, int32_t out_size) {
if(!Config::is_wiiu_menu)
if (!Config::is_wiiu_menu)
strncpy(out_buf, strings.need_menu_action, out_size);
else
strncpy(out_buf, Config::unregister_task_item_pressed ? strings.restart_to_apply_action : strings.press_a_action, out_size);
return 0;
}
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;
}
static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
uint64_t current_title_id = OSGetTitleID();
uint64_t wiiu_menu_tid = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_WII_U_MENU);
Config::is_wiiu_menu = (current_title_id == wiiu_menu_tid);
// get translation strings
strings = get_config_strings(get_system_language());
WUPSConfigHandle config;
WUPSConfig_CreateHandled(&config, strings.plugin_name);
// create root config category
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
WUPSConfigCategoryHandle patching_cat;
WUPSConfig_AddCategoryByNameHandled(config, strings.network_category, &patching_cat);
try {
auto patching_cat = WUPSConfigCategory::Create(strings.network_category);
// config id display name default current value changed callback
patching_cat.add(WUPSConfigItemBoolean::Create("connect_to_network", strings.connect_to_network_setting, true, Config::connect_to_network, &connect_to_network_changed));
root.add(std::move(patching_cat));
WUPSConfigItemBoolean_AddToCategoryHandled(config, patching_cat, "connect_to_network", strings.connect_to_network_setting, Config::connect_to_network, &connect_to_network_changed);
WUPSConfigCategoryHandle boss_cat;
WUPSConfig_AddCategoryByNameHandled(config, strings.other_category, &boss_cat);
auto other_cat = WUPSConfigCategory::Create(strings.other_category);
WUPSConfigCallbacks_t unregisterTasksItemCallbacks = {
.getCurrentValueDisplay = unregister_task_item_get_display_value,
.getCurrentValueSelectedDisplay = unregister_task_item_get_display_value,
.onSelected = nullptr,
.restoreDefault = nullptr,
.isMovementAllowed = unregister_task_item_is_movement_allowed,
.callCallback = nullptr,
.onButtonPressed = unregister_task_item_pressed_cb,
.onDelete = nullptr
};
WUPSConfigAPIItemCallbacksV2 unregisterTasksItemCallbacks = {
.getCurrentValueDisplay = unregister_task_item_get_display_value,
.getCurrentValueSelectedDisplay = unregister_task_item_get_display_value,
.onSelected = nullptr,
.restoreDefault = nullptr,
.isMovementAllowed = nullptr,
.onCloseCallback = nullptr,
.onInput = unregister_task_item_on_input_cb,
.onInputEx = nullptr,
.onDelete = nullptr
};
WUPSConfigItemHandle unregisterTasksItem;
WUPSConfigItem_Create(&unregisterTasksItem, "unregister_task_item", strings.reset_wwp_setting, unregisterTasksItemCallbacks, &Config::unregister_task_item_pressed);
WUPSConfigCategory_AddItem(boss_cat, unregisterTasksItem);
WUPSConfigAPIItemOptionsV2 unregisterTasksItemOptions = {
.displayName = strings.reset_wwp_setting,
.context = nullptr,
.callbacks = unregisterTasksItemCallbacks,
};
return config;
WUPSConfigItemHandle unregisterTasksItem;
WUPSConfigAPIStatus err;
if ((err = WUPSConfigAPI_Item_Create(unregisterTasksItemOptions, &unregisterTasksItem)) != WUPSCONFIG_API_RESULT_SUCCESS) {
throw std::runtime_error(std::string("Failed to create config item: ").append(WUPSConfigAPI_GetStatusStr(err)));
}
if ((err = WUPSConfigAPI_Category_AddItem(other_cat.getHandle(), unregisterTasksItem)) != WUPSCONFIG_API_RESULT_SUCCESS) {
throw std::runtime_error(std::string("Failed to add config item: ").append(WUPSConfigAPI_GetStatusStr(err)));
}
root.add(std::move(other_cat));
}
catch (std::exception &e) {
DEBUG_FUNCTION_LINE("Creating config menu failed: %s", e.what());
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
}
WUPS_CONFIG_CLOSED() {
// Save all changes
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to close storage");
static void ConfigMenuClosedCallback() {
// Save all changes
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to save storage");
}
if (Config::need_relaunch) {
@ -246,3 +227,38 @@ WUPS_CONFIG_CLOSED() {
Config::need_relaunch = false;
}
}
void Config::Init() {
// Init the config api
WUPSConfigAPIOptionsV1 configOptions = { .name = "Inkay" };
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to initialize WUPS Config API");
return;
}
WUPSStorageError storageRes;
// Try to get value from storage
if ((storageRes = WUPSStorageAPI::Get<bool>("connect_to_network", Config::connect_to_network)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
DEBUG_FUNCTION_LINE("Connect to network value not found, attempting to migrate/create");
bool skipPatches = false;
if (WUPSStorageAPI::Get<bool>("skipPatches", skipPatches) == WUPS_STORAGE_ERROR_SUCCESS) {
// Migrate old config value
Config::connect_to_network = !skipPatches;
WUPSStorageAPI::DeleteItem("skipPatches");
}
// Add the value to the storage if it's missing.
if (WUPSStorageAPI::Store<bool>("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)", WUPSStorageAPI_GetStatusStr(storageRes), storageRes);
}
// Save storage
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to save storage");
}
}