WUPS 0.8.0 support

This commit is contained in:
Maschell 2023-12-26 15:16:57 +01:00
parent e29f1c1921
commit a7b9626818
4 changed files with 207 additions and 252 deletions

View File

@ -1,6 +1,6 @@
FROM ghcr.io/wiiu-env/devkitppc:20230621 FROM ghcr.io/wiiu-env/devkitppc:20231112
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20231221-ca17105 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
WORKDIR project WORKDIR project

View File

@ -1,8 +1,9 @@
#include "globals.h" #include "globals.h"
int gPreferSystemSettings = 1; bool gPreferSystemSettings = DEFAULT_PREFER_SYSTEM_SETTINGS;
int gSkipOwnRegion = 1; bool gSkipOwnRegion = DEFAULT_SKIP_OWN_REGION;
int gAutoDetection = 1; bool gAutoDetection = DEFAULT_AUTO_DETECTION_VALUE;
int gForceSettingsEnabled = 0; int gForceSettingsEnabled = 0;
Lanuages gDefaultLanguage = LANG_ENGLISH; Lanuages gDefaultLanguage = LANG_ENGLISH;
int32_t gDefaultCountry = 78; int32_t gDefaultCountry = 78;
@ -12,9 +13,9 @@ Lanuages gCurrentLanguage = gDefaultLanguage;
int32_t gCurrentCountry = gDefaultCountry; int32_t gCurrentCountry = gDefaultCountry;
MCPRegion gCurrentProductArea = gDefaultProductArea; MCPRegion gCurrentProductArea = gDefaultProductArea;
Lanuages gDefaultLangForEUR = LANG_ENGLISH; Lanuages gDefaultLangForEUR = DEFAULT_LANG_FOR_EUR;
int32_t gDefaultCountryForEUR = 110; int32_t gDefaultCountryForEUR = DEFAULT_COUNTRY_FOR_EUR;
Lanuages gDefaultLangForUSA = LANG_ENGLISH; Lanuages gDefaultLangForUSA = DEFAULT_LANG_FOR_USA;
int32_t gDefaultCountryForUSA = 49; int32_t gDefaultCountryForUSA = DEFAULT_COUNTRY_FOR_USA;
Lanuages gDefaultLangForJPN = LANG_JAPANESE; Lanuages gDefaultLangForJPN = DEFAULT_LANG_FOR_JPN;
int32_t gDefaultCountryForJPN = 1; int32_t gDefaultCountryForJPN = DEFAULT_COUNTRY_FOR_JPN;

View File

@ -20,10 +20,15 @@ enum Lanuages {
LANG_RUSSKI = 10, LANG_RUSSKI = 10,
}; };
#define DEFAULT_AUTO_DETECTION_VALUE true
extern bool gAutoDetection;
#define DEFAULT_PREFER_SYSTEM_SETTINGS true
extern bool gPreferSystemSettings;
#define DEFAULT_SKIP_OWN_REGION true
extern bool gSkipOwnRegion;
extern int gPreferSystemSettings;
extern int gSkipOwnRegion;
extern int gAutoDetection;
extern Lanuages gDefaultLanguage; extern Lanuages gDefaultLanguage;
extern int32_t gDefaultCountry; extern int32_t gDefaultCountry;
extern MCPRegion gDefaultProductArea; extern MCPRegion gDefaultProductArea;
@ -32,9 +37,20 @@ extern Lanuages gCurrentLanguage;
extern int32_t gCurrentCountry; extern int32_t gCurrentCountry;
extern MCPRegion gCurrentProductArea; extern MCPRegion gCurrentProductArea;
#define DEFAULT_LANG_FOR_EUR LANG_ENGLISH
#define DEFAULT_COUNTRY_FOR_EUR 110
#define DEFAULT_LANG_FOR_USA LANG_ENGLISH
#define DEFAULT_COUNTRY_FOR_USA 49
#define DEFAULT_LANG_FOR_JPN LANG_JAPANESE
#define DEFAULT_COUNTRY_FOR_JPN 1
extern Lanuages gDefaultLangForEUR; extern Lanuages gDefaultLangForEUR;
extern int32_t gDefaultCountryForEUR; extern int32_t gDefaultCountryForEUR;
extern Lanuages gDefaultLangForUSA; extern Lanuages gDefaultLangForUSA;
extern int32_t gDefaultCountryForUSA; extern int32_t gDefaultCountryForUSA;
extern Lanuages gDefaultLangForJPN; extern Lanuages gDefaultLangForJPN;
extern int32_t gDefaultCountryForJPN; extern int32_t gDefaultCountryForJPN;

View File

@ -47,13 +47,13 @@ DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, struct UCSysConfig
return result; return result;
} }
if (strcmp(settings->name, "cafe.language") == 0) { if (std::string_view("cafe.language") == settings->name) {
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.language found!"); DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.language found!");
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing language..."); DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing language...");
DEBUG_FUNCTION_LINE("UCReadSysConfig: original lang %d, new %d", *((int *) settings->data), gCurrentLanguage); DEBUG_FUNCTION_LINE("UCReadSysConfig: original lang %d, new %d", *((int *) settings->data), gCurrentLanguage);
*((int *) settings->data) = gCurrentLanguage; *((int *) settings->data) = gCurrentLanguage;
} }
if (strcmp(settings->name, "cafe.cntry_reg") == 0) { if (std::string_view("cafe.cntry_reg") == settings->name) {
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.cntry_reg found!"); DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.cntry_reg found!");
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing cntry_reg..."); DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing cntry_reg...");
DEBUG_FUNCTION_LINE("UCReadSysConfig: original cntry_reg %d, new %d", *((int *) settings->data), gCurrentCountry); DEBUG_FUNCTION_LINE("UCReadSysConfig: original cntry_reg %d, new %d", *((int *) settings->data), gCurrentCountry);
@ -83,9 +83,6 @@ DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, struct UCSysConfig
#define VAL_DEFAULT_COUNTRY_USA "default_cntry_reg_usa" #define VAL_DEFAULT_COUNTRY_USA "default_cntry_reg_usa"
#define VAL_DEFAULT_COUNTRY_JPN "default_cntry_reg_jpn" #define VAL_DEFAULT_COUNTRY_JPN "default_cntry_reg_jpn"
extern "C" void ACPInitialize();
extern "C" void ACPFinalize();
DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) { DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) {
int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, metaxml, device); int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, metaxml, device);
if (metaxml != nullptr) { if (metaxml != nullptr) {
@ -116,10 +113,9 @@ void bootStuff() {
bool forceConfigMenu = false; bool forceConfigMenu = false;
auto *acpMetaXml = (ACPMetaXml *) memalign(0x40, sizeof(ACPMetaXml)); auto *acpMetaXml = (ACPMetaXml *) memalign(0x40, sizeof(ACPMetaXml));
memset(acpMetaXml, 0, sizeof(ACPMetaXml));
uint32_t regionFromXML = 0; uint32_t regionFromXML = 0;
if (acpMetaXml) { if (acpMetaXml) {
memset(acpMetaXml, 0, sizeof(ACPMetaXml));
ACPInitialize(); ACPInitialize();
auto res = ACPGetTitleMetaXml(OSGetTitleID(), acpMetaXml); auto res = ACPGetTitleMetaXml(OSGetTitleID(), acpMetaXml);
if (res >= 0) { if (res >= 0) {
@ -208,49 +204,35 @@ void bootStuff() {
} }
} }
} }
WUPSStorageError storageError;
wups_storage_item_t *root = nullptr; auto rootStorage = WUPSStorageAPI::GetSubItem(CAT_GENERAL_ROOT, storageError);
auto resa = WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root); if (!rootStorage) {
if (resa != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to read %s subitem", CAT_GENERAL_ROOT); DEBUG_FUNCTION_LINE_ERR("Failed to read %s subitem", CAT_GENERAL_ROOT);
return; return;
} }
auto titleSettings = rootStorage->GetOrCreateSubItem(CAT_TITLE_SETTINGS, storageError);
wups_storage_item_t *title_settings; if (!titleSettings) {
if (WUPS_GetSubItem(root, CAT_TITLE_SETTINGS, &title_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
if (WUPS_CreateSubItem(root, CAT_TITLE_SETTINGS, &title_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("WUPS_CreateSubItem %s failed", CAT_TITLE_SETTINGS); DEBUG_FUNCTION_LINE_ERR("WUPS_CreateSubItem %s failed", CAT_TITLE_SETTINGS);
return; return;
} }
}
char buffer[18]; char buffer[18];
snprintf(buffer, 17, "%016llX", OSGetTitleID()); snprintf(buffer, 17, "%016llX", OSGetTitleID());
wups_storage_item_t *curTitleItem; auto curTitle = titleSettings->GetOrCreateSubItem(buffer, storageError);
if (WUPS_GetSubItem(title_settings, buffer, &curTitleItem) != WUPS_STORAGE_ERROR_SUCCESS) {
if (WUPS_CreateSubItem(title_settings, buffer, &curTitleItem) != WUPS_STORAGE_ERROR_SUCCESS) { if (!curTitle) {
DEBUG_FUNCTION_LINE_ERR("WUPS_CreateSubItem %s failed", buffer); DEBUG_FUNCTION_LINE_ERR("WUPS_CreateSubItem %s failed", buffer);
return; return;
} }
storageError = curTitle->GetOrStoreDefault(VAL_LANGUAGE, gCurrentLanguage, gCurrentLanguage);
if (storageError != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or store current Language");
} }
storageError = curTitle->GetOrStoreDefault(VAL_PRODUCT_AREA, gCurrentProductArea, gCurrentProductArea);
if (curTitleItem != nullptr) { if (storageError != WUPS_STORAGE_ERROR_SUCCESS) {
if (WUPS_GetInt(curTitleItem, VAL_LANGUAGE, (int32_t *) &gCurrentLanguage) != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("Failed to get or store current Language");
WUPS_StoreInt(curTitleItem, VAL_LANGUAGE, gDefaultLanguage);
gCurrentLanguage = gDefaultLanguage;
}
/*
if (WUPS_GetInt(curTitleItem, VAL_COUNTRY, (int32_t *) &gCurrentCountry) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(curTitleItem, VAL_COUNTRY, gDefaultCountry);
gCurrentCountry = gDefaultCountry;
}*/
if (WUPS_GetInt(curTitleItem, VAL_PRODUCT_AREA, (int32_t *) &gCurrentProductArea) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(curTitleItem, VAL_PRODUCT_AREA, gDefaultProductArea);
gCurrentProductArea = gDefaultProductArea;
} }
bool isWiiUMenu = false; bool isWiiUMenu = false;
@ -264,7 +246,7 @@ void bootStuff() {
if (real_product_area_valid && (regionFromXML & real_product_area) == real_product_area) { if (real_product_area_valid && (regionFromXML & real_product_area) == real_product_area) {
if (gSkipOwnRegion && !forceConfigMenu) { if (gSkipOwnRegion && !forceConfigMenu) {
// If the want to skip checks for own region and we were able // If the want to skip checks for own region, and we were able
// to tell the region of the current title don't show the menu. // to tell the region of the current title don't show the menu.
showMenu = false; showMenu = false;
return; return;
@ -275,65 +257,61 @@ void bootStuff() {
if (forceConfigMenu || (!isWiiUMenu && showMenu)) { if (forceConfigMenu || (!isWiiUMenu && showMenu)) {
ConfigUtils::openConfigMenu(); ConfigUtils::openConfigMenu();
// Save settings to storage // Save settings to storage
WUPS_StoreInt(curTitleItem, VAL_LANGUAGE, gCurrentLanguage); curTitle->Store(VAL_LANGUAGE, gCurrentLanguage);
//WUPS_StoreInt(curTitleItem, VAL_COUNTRY, gCurrentCountry); curTitle->Store(VAL_PRODUCT_AREA, gCurrentProductArea);
WUPS_StoreInt(curTitleItem, VAL_PRODUCT_AREA, gCurrentProductArea);
} }
DEBUG_FUNCTION_LINE("Language will be force to %d", gCurrentLanguage); DEBUG_FUNCTION_LINE("Language will be force to %d", gCurrentLanguage);
DEBUG_FUNCTION_LINE("Country will be force to %d", gDefaultCountry); DEBUG_FUNCTION_LINE("Country will be force to %d", gDefaultCountry);
DEBUG_FUNCTION_LINE("Product Area will be forced to %d", gCurrentProductArea); DEBUG_FUNCTION_LINE("Product Area will be forced to %d", gCurrentProductArea);
}
} }
std::optional<WUPSStorageSubItem> rootSettingsStorage = {};
std::optional<WUPSStorageSubItem> generalSettingsStorage = {};
ON_APPLICATION_START() { ON_APPLICATION_START() {
initLogging(); initLogging();
WUPS_OpenStorage(); WUPSStorageError storageError;
rootSettingsStorage = WUPSStorageAPI::GetOrCreateSubItem(CAT_GENERAL_ROOT, storageError);
wups_storage_item_t *root; if (!rootSettingsStorage) {
if (WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root) != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("Failed to get or create %s subitem", CAT_GENERAL_ROOT);
WUPS_CreateSubItem(nullptr, CAT_GENERAL_ROOT, &root);
} }
wups_storage_item_t *general_settings; generalSettingsStorage = rootSettingsStorage->GetOrCreateSubItem(CAT_GENERAL_SETTINGS, storageError);
if (WUPS_GetSubItem(root, CAT_GENERAL_SETTINGS, &general_settings) != WUPS_STORAGE_ERROR_SUCCESS) { if (!generalSettingsStorage) {
WUPS_CreateSubItem(root, CAT_GENERAL_SETTINGS, &general_settings); DEBUG_FUNCTION_LINE_ERR("Failed to get or create %s subitem", CAT_GENERAL_SETTINGS);
} else {
if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_AUTO_DETECTION, gAutoDetection, DEFAULT_AUTO_DETECTION_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
}
if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_PREFER_SYSTEM_SETTINGS, gPreferSystemSettings, DEFAULT_PREFER_SYSTEM_SETTINGS)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
}
if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_SKIP_OWN_REGION, gSkipOwnRegion, DEFAULT_SKIP_OWN_REGION)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
} }
if (WUPS_GetInt(general_settings, VAL_AUTO_DETECTION, (int32_t *) &gAutoDetection) != WUPS_STORAGE_ERROR_SUCCESS) { if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_LANG_EUR, gDefaultLangForEUR, DEFAULT_LANG_FOR_EUR)) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_AUTO_DETECTION, gAutoDetection); DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
} }
if (WUPS_GetInt(general_settings, VAL_PREFER_SYSTEM_SETTINGS, (int32_t *) &gPreferSystemSettings) != WUPS_STORAGE_ERROR_SUCCESS) { if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_COUNTRY_EUR, gDefaultCountryForEUR, DEFAULT_COUNTRY_FOR_EUR)) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_PREFER_SYSTEM_SETTINGS, gPreferSystemSettings); DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
} }
if (WUPS_GetInt(general_settings, VAL_SKIP_OWN_REGION, (int32_t *) &gSkipOwnRegion) != WUPS_STORAGE_ERROR_SUCCESS) { if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_LANG_USA, gDefaultLangForUSA, DEFAULT_LANG_FOR_USA)) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_SKIP_OWN_REGION, gSkipOwnRegion); DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
}
if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_COUNTRY_USA, gDefaultCountryForUSA, DEFAULT_COUNTRY_FOR_USA)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
} }
if (WUPS_GetInt(general_settings, VAL_DEFAULT_LANG_EUR, (int32_t *) &gDefaultLangForEUR) != WUPS_STORAGE_ERROR_SUCCESS) { if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_LANG_JPN, gDefaultLangForJPN, DEFAULT_LANG_FOR_JPN)) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_DEFAULT_LANG_EUR, gDefaultLangForEUR); DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
} }
if ((storageError = generalSettingsStorage->GetOrStoreDefault(VAL_DEFAULT_COUNTRY_JPN, gDefaultCountryForJPN, DEFAULT_COUNTRY_FOR_JPN)) != WUPS_STORAGE_ERROR_SUCCESS) {
if (WUPS_GetInt(general_settings, VAL_DEFAULT_COUNTRY_EUR, &gDefaultCountryForEUR) != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE_WARN("Failed to get or store default: %s", WUPSStorageAPI::GetStatusStr(storageError).data());
WUPS_StoreInt(general_settings, VAL_DEFAULT_COUNTRY_EUR, gDefaultCountryForEUR);
} }
if (WUPS_GetInt(general_settings, VAL_DEFAULT_LANG_USA, (int32_t *) &gDefaultLangForUSA) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_DEFAULT_LANG_USA, gDefaultLangForUSA);
}
if (WUPS_GetInt(general_settings, VAL_DEFAULT_COUNTRY_USA, &gDefaultCountryForUSA) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_DEFAULT_COUNTRY_USA, gDefaultCountryForUSA);
}
if (WUPS_GetInt(general_settings, VAL_DEFAULT_LANG_JPN, (int32_t *) &gDefaultLangForJPN) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_DEFAULT_LANG_JPN, gDefaultLangForJPN);
}
if (WUPS_GetInt(general_settings, VAL_DEFAULT_COUNTRY_JPN, &gDefaultCountryForJPN) != WUPS_STORAGE_ERROR_SUCCESS) {
WUPS_StoreInt(general_settings, VAL_DEFAULT_COUNTRY_JPN, gDefaultCountryForJPN);
} }
gForceSettingsEnabled = 1; gForceSettingsEnabled = 1;
@ -345,114 +323,68 @@ ON_APPLICATION_START() {
bootStuff(); bootStuff();
WUPS_CloseStorage(); WUPSStorageAPI::SaveStorage();
} }
void auto_detection_changed(ConfigItemBoolean *item, bool newValue) { void bool_item_changed(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in auto_detection changed: %d", newValue); DEBUG_FUNCTION_LINE("Value changed for %s: %d", item->identifier ? item->identifier : "[UNKNOWN]", newValue);
wups_storage_item_t *root; if (std::string_view(VAL_DEFAULT_LANG_USA) == item->identifier) {
if (WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
wups_storage_item_t *general_settings;
if (WUPS_GetSubItem(root, CAT_GENERAL_SETTINGS, &general_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
WUPS_StoreInt(general_settings, VAL_AUTO_DETECTION, newValue);
gAutoDetection = newValue; gAutoDetection = newValue;
} if (generalSettingsStorage) {
generalSettingsStorage->Store(VAL_AUTO_DETECTION, gAutoDetection);
void prefer_system_changed(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in prefer_system_settings changed: %d", newValue);
wups_storage_item_t *root;
if (WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
} }
} else if (std::string_view(VAL_PREFER_SYSTEM_SETTINGS) == item->identifier) {
wups_storage_item_t *general_settings;
if (WUPS_GetSubItem(root, CAT_GENERAL_SETTINGS, &general_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
WUPS_StoreInt(general_settings, VAL_PREFER_SYSTEM_SETTINGS, newValue);
gPreferSystemSettings = newValue; gPreferSystemSettings = newValue;
} if (generalSettingsStorage) {
generalSettingsStorage->Store(VAL_PREFER_SYSTEM_SETTINGS, gPreferSystemSettings);
void skip_own_region_changed(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in skip_own_region_changed changed: %d", newValue);
wups_storage_item_t *root;
if (WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
} }
} else if (std::string_view(VAL_SKIP_OWN_REGION) == item->identifier) {
wups_storage_item_t *general_settings;
if (WUPS_GetSubItem(root, CAT_GENERAL_SETTINGS, &general_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
WUPS_StoreInt(general_settings, VAL_SKIP_OWN_REGION, newValue);
gPreferSystemSettings = newValue; gPreferSystemSettings = newValue;
if (generalSettingsStorage) {
generalSettingsStorage->Store(VAL_SKIP_OWN_REGION, gSkipOwnRegion);
}
}
} }
void default_lang_changed(ConfigItemMultipleValues *item, uint32_t newValue) { void default_lang_changed(ConfigItemMultipleValues *item, uint32_t newValue) {
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue); DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
wups_storage_item_t *root; if (std::string_view(VAL_DEFAULT_LANG_EUR) == item->identifier) {
if (WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
wups_storage_item_t *general_settings;
if (WUPS_GetSubItem(root, CAT_GENERAL_SETTINGS, &general_settings) != WUPS_STORAGE_ERROR_SUCCESS) {
return;
}
WUPS_StoreInt(general_settings, item->configId, (int32_t) newValue);
if (strcmp(item->configId, VAL_DEFAULT_LANG_EUR) == 0) {
DEBUG_FUNCTION_LINE("Updated default eur lang"); DEBUG_FUNCTION_LINE("Updated default eur lang");
gDefaultLangForEUR = (Lanuages) newValue; gDefaultLangForEUR = (Lanuages) newValue;
} else if (strcmp(item->configId, VAL_DEFAULT_LANG_USA) == 0) { } else if (std::string_view(VAL_DEFAULT_LANG_USA) == item->identifier) {
DEBUG_FUNCTION_LINE("Updated default usa lang"); DEBUG_FUNCTION_LINE("Updated default usa lang");
gDefaultLangForUSA = (Lanuages) newValue; gDefaultLangForUSA = (Lanuages) newValue;
} else if (strcmp(item->configId, VAL_DEFAULT_LANG_JPN) == 0) { } else if (std::string_view(VAL_DEFAULT_LANG_JPN) == item->identifier) {
DEBUG_FUNCTION_LINE("Updated default jpn lang"); DEBUG_FUNCTION_LINE("Updated default jpn lang");
gDefaultLangForJPN = (Lanuages) newValue; gDefaultLangForJPN = (Lanuages) newValue;
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected identifier for default_lang_changed");
return;
}
if (generalSettingsStorage) {
generalSettingsStorage->Store(item->identifier, (int32_t) newValue);
} else {
DEBUG_FUNCTION_LINE_WARN("Failed to store into general settings: sub-item was nullopt");
} }
} }
void getConfigInfoForLangMap(std::map<Lanuages, const char *> &curLangMap, ConfigItemMultipleValuesPair *pair, uint32_t default_lang, uint32_t *default_index, uint32_t *len) { static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
uint32_t i = 0; try {
for (auto &curEntry : curLangMap) { WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
if (default_lang == curEntry.first) {
*default_index = i;
}
pair[i].value = curEntry.first;
pair[i].valueName = (char *) curEntry.second;
i++;
}
*len = i;
}
WUPS_GET_CONFIG() { root.add(WUPSConfigItemBoolean::Create(VAL_DEFAULT_LANG_USA, "Auto detect region/language",
// We open the storage so we can persist the configuration the user did. DEFAULT_AUTO_DETECTION_VALUE, gAutoDetection,
WUPS_OpenStorage(); &bool_item_changed));
root.add(WUPSConfigItemBoolean::Create(VAL_SKIP_OWN_REGION, "Force auto detection for in-region titles",
DEFAULT_SKIP_OWN_REGION, gSkipOwnRegion,
&bool_item_changed));
root.add(WUPSConfigItemBoolean::Create(VAL_PREFER_SYSTEM_SETTINGS, "Prefer system settings for in-region titles",
DEFAULT_PREFER_SYSTEM_SETTINGS, gPreferSystemSettings,
&bool_item_changed));
WUPSConfigHandle config; constexpr WUPSConfigItemMultipleValues::ValuePair eur_lang_map[] = {
WUPSConfig_CreateHandled(&config, "Region Free Plugin");
WUPSConfigCategoryHandle cat;
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &cat);
WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, VAL_DEFAULT_LANG_USA, "Auto detect region/language", gAutoDetection, &auto_detection_changed);
WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, VAL_SKIP_OWN_REGION, "Force auto detection for in-region titles", gSkipOwnRegion, &skip_own_region_changed);
WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, VAL_PREFER_SYSTEM_SETTINGS, "Prefer system settings for in-region titles", gPreferSystemSettings, &prefer_system_changed);
std::map<Lanuages, const char *> eur_lang_map{
{LANG_ENGLISH, "English"}, {LANG_ENGLISH, "English"},
{LANG_FRANCAIS, "Francais"}, {LANG_FRANCAIS, "Francais"},
{LANG_DEUTSCH, "Deutsch"}, {LANG_DEUTSCH, "Deutsch"},
@ -463,36 +395,42 @@ WUPS_GET_CONFIG() {
{LANG_RUSSKI, "Russki"}, {LANG_RUSSKI, "Russki"},
}; };
std::map<Lanuages, const char *> usa_lang_map{ root.add(WUPSConfigItemMultipleValues::CreateFromValue(VAL_DEFAULT_LANG_EUR, "Default language for EUR",
DEFAULT_LANG_FOR_EUR, gDefaultLangForEUR,
eur_lang_map,
default_lang_changed));
constexpr WUPSConfigItemMultipleValues::ValuePair usa_lang_map[] = {
{LANG_ENGLISH, "English"}, {LANG_ENGLISH, "English"},
{LANG_FRANCAIS, "Francais"}, {LANG_FRANCAIS, "Francais"},
{LANG_ESPANOL, "Espanol"}, {LANG_ESPANOL, "Espanol"},
{LANG_PORTUGUES, "Portugues"}}; {LANG_PORTUGUES, "Portugues"}};
ConfigItemMultipleValuesPair lang_eur_pair[eur_lang_map.size()]; root.add(WUPSConfigItemMultipleValues::CreateFromValue(VAL_DEFAULT_LANG_USA, "Default language for USA",
uint32_t number_lang_eur_values = 0; DEFAULT_LANG_FOR_USA, gDefaultLangForUSA,
uint32_t default_index_eur = 0; usa_lang_map,
default_lang_changed));
getConfigInfoForLangMap(eur_lang_map, lang_eur_pair, gDefaultLangForEUR, &default_index_eur, &number_lang_eur_values); } catch (std::exception &e) {
OSReport("Exception T_T : %s\n", e.what());
WUPSConfigItemMultipleValues_AddToCategoryHandled(config, cat, VAL_DEFAULT_LANG_EUR, "Default language for EUR", default_index_eur, lang_eur_pair, number_lang_eur_values, return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
&default_lang_changed); }
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
ConfigItemMultipleValuesPair lang_usa_pair[eur_lang_map.size()];
uint32_t number_lang_usa_values = 0;
uint32_t default_index_usa = 0;
getConfigInfoForLangMap(usa_lang_map, lang_usa_pair, gDefaultLangForUSA, &default_index_usa, &number_lang_usa_values);
WUPSConfigItemMultipleValues_AddToCategoryHandled(config, cat, VAL_DEFAULT_LANG_USA, "Default language for USA", default_index_usa, lang_usa_pair, number_lang_usa_values,
&default_lang_changed);
return config;
} }
WUPS_CONFIG_CLOSED() { static void ConfigMenuClosedCallback() {
// Save all changes // Save all changes
WUPS_CloseStorage(); WUPSStorageAPI::SaveStorage();
}
INITIALIZE_PLUGIN() {
initLogging();
WUPSConfigAPIOptionsV1 configOptions = {.name = "Region Free Plugin"};
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
}
deinitLogging();
} }
DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, struct MCPSysProdSettings *settings) { DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, struct MCPSysProdSettings *settings) {