Compare commits

...

7 Commits

Author SHA1 Message Date
Maschell 98a78f5167 Bump softprops/action-gh-release from 1 to 2 2024-04-27 13:33:04 +02:00
Maschell 74a32e38af Update Dockerfile 2024-04-27 13:33:04 +02:00
Maschell 64414543b9 Bump version 2024-04-27 13:33:04 +02:00
Maschell f0f849cd93 Move wups config code into a new file 2024-04-27 13:33:04 +02:00
Maschell 4a83db1ff7 Update .gitignore to ignore any zip files 2024-04-27 13:33:04 +02:00
Maschell 24974dfd07 Update Dockerfile 2024-04-27 13:33:04 +02:00
Maschell c470f08766 WUPS 0.8.0 support 2024-04-27 13:33:04 +02:00
9 changed files with 149 additions and 127 deletions

View File

@ -48,7 +48,7 @@ jobs:
- name: zip artifact
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps
- name: Create Release
uses: "softprops/action-gh-release@v1"
uses: "softprops/action-gh-release@v2"
with:
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
draft: false

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ cmake-build-debug/
.idea/
*.rpx
*.txt
*.zip

View File

@ -1,7 +1,7 @@
FROM ghcr.io/wiiu-env/devkitppc:20230621
FROM ghcr.io/wiiu-env/devkitppc:20240423
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240425 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libcontentredirection:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libcontentredirection:20240424 /artifacts $DEVKITPRO
WORKDIR project

9
src/globals.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "globals.h"
bool gAutoApplySingleModpack = DEFAULT_AUTO_APPLY_SINGLE_MODPACK;
bool gSkipPrepareIfSingleModpack = DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK;
bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED;
CRLayerHandle gContentLayerHandle = 0;
CRLayerHandle gAocLayerHandle = 0;

View File

@ -1,12 +1,21 @@
#pragma once
#include "version.h"
#include <content_redirection/redirection.h>
#define VERSION "v0.1.3"
#define VERSION "v0.1.4"
#define VERSION_FULL VERSION VERSION_EXTRA
#define AUTO_APPLY_SINGLE_MODPACK_STRING "autoApplySingleModpack"
#define SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING "skipPrepareForSingleModpack"
#define SDCAFIINE_ENABLED_STRING "sdCafiineEnabled"
#define DEFAULT_AUTO_APPLY_SINGLE_MODPACK false
#define DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK false
#define DEFAULT_SDCAFIINE_ENABLED true
extern bool gAutoApplySingleModpack;
extern bool gSkipPrepareIfSingleModpack;
extern bool gSDCafiineEnabled;
extern CRLayerHandle gAocLayerHandle;
extern CRLayerHandle gContentLayerHandle;

View File

@ -1,5 +1,6 @@
#include "main.h"
#include "globals.h"
#include "modpackSelector.h"
#include "utils/config.h"
#include "utils/logger.h"
#include <content_redirection/redirection.h>
#include <coreinit/title.h>
@ -13,63 +14,19 @@ WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL");
WUPS_USE_WUT_DEVOPTAB();
WUPS_USE_STORAGE("sdcafiine"); // Unqiue id for the storage api
CRLayerHandle contentLayerHandle __attribute__((section(".data"))) = 0;
CRLayerHandle aocLayerHandle __attribute__((section(".data"))) = 0;
bool gAutoApplySingleModpack = false;
bool gSkipPrepareIfSingleModpack = false;
bool gSDCafiineEnabled = true;
WUPS_USE_STORAGE("sdcafiine"); // Unique id for the storage api
INITIALIZE_PLUGIN() {
// But then use libcontentredirection instead.
ContentRedirectionStatus error;
if ((error = ContentRedirection_InitLibrary()) != CONTENT_REDIRECTION_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init ContentRedirection. Error %s %d", ContentRedirection_GetStatusStr(error), error);
OSFatal("Failed to init ContentRedirection.");
}
// Open storage to read values
WUPSStorageError storageRes = WUPS_OpenStorage();
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
} else {
// Try to get value from storage
if ((storageRes = WUPS_GetBool(nullptr, AUTO_APPLY_SINGLE_MODPACK_STRING, &gAutoApplySingleModpack)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
// Add the value to the storage if it's missing.
if (WUPS_StoreBool(nullptr, AUTO_APPLY_SINGLE_MODPACK_STRING, gAutoApplySingleModpack) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store bool");
}
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
}
InitStorageAndConfig();
if ((storageRes = WUPS_GetBool(nullptr, SDCAFIINE_ENABLED_STRING, &gSDCafiineEnabled)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
// Add the value to the storage if it's missing.
if (WUPS_StoreBool(nullptr, SDCAFIINE_ENABLED_STRING, gSDCafiineEnabled) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store bool");
}
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
}
if ((storageRes = WUPS_GetBool(nullptr, SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, &gSkipPrepareIfSingleModpack)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
// Add the value to the storage if it's missing.
if (WUPS_StoreBool(nullptr, SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, gSkipPrepareIfSingleModpack) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store bool");
}
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
}
// Close storage
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
}
contentLayerHandle = 0;
aocLayerHandle = 0;
gContentLayerHandle = 0;
gAocLayerHandle = 0;
}
/* Entry point */
@ -82,64 +39,14 @@ ON_APPLICATION_START() {
}
}
void autoApplySingleModpackChanged(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in gAutoApplySingleModpack: %d", newValue);
gAutoApplySingleModpack = newValue;
// If the value has changed, we store it in the storage.
WUPS_StoreInt(nullptr, AUTO_APPLY_SINGLE_MODPACK_STRING, gAutoApplySingleModpack);
}
void skipPrepareIfSingleModpackChanged(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in gSkipPrepareIfSingleModpack: %d", newValue);
gSkipPrepareIfSingleModpack = newValue;
// If the value has changed, we store it in the storage.
WUPS_StoreInt(nullptr, SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, gSkipPrepareIfSingleModpack);
}
void sdCafiineEnabledChanged(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE("New value in gSDCafiineEnabled: %d", newValue);
gSDCafiineEnabled = newValue;
// If the value has changed, we store it in the storage.
WUPS_StoreInt(nullptr, SDCAFIINE_ENABLED_STRING, gSDCafiineEnabled);
}
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_ERR("Failed to open storage");
return 0;
}
WUPSConfigHandle config;
WUPSConfig_CreateHandled(&config, "SDCafiine");
WUPSConfigCategoryHandle setting;
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &setting);
WUPSConfigCategoryHandle advanced;
WUPSConfig_AddCategoryByNameHandled(config, "Advanced settings", &advanced);
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, SDCAFIINE_ENABLED_STRING, "Enable SDCafiine (game needs to be restarted)", gSDCafiineEnabled, &sdCafiineEnabledChanged);
WUPSConfigItemBoolean_AddToCategoryHandled(config, advanced, AUTO_APPLY_SINGLE_MODPACK_STRING, "Auto apply the modpack if only one modpack exists", gAutoApplySingleModpack, &autoApplySingleModpackChanged);
WUPSConfigItemBoolean_AddToCategoryHandled(config, advanced, SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, "Skip \"Preparing modpack...\" screen", gSkipPrepareIfSingleModpack, &skipPrepareIfSingleModpackChanged);
return config;
}
WUPS_CONFIG_CLOSED() {
// Save all changes
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
}
ON_APPLICATION_ENDS() {
if (contentLayerHandle != 0) {
ContentRedirection_RemoveFSLayer(contentLayerHandle);
contentLayerHandle = 0;
if (gContentLayerHandle != 0) {
ContentRedirection_RemoveFSLayer(gContentLayerHandle);
gContentLayerHandle = 0;
}
if (aocLayerHandle != 0) {
ContentRedirection_RemoveFSLayer(aocLayerHandle);
aocLayerHandle = 0;
if (gAocLayerHandle != 0) {
ContentRedirection_RemoveFSLayer(gAocLayerHandle);
gAocLayerHandle = 0;
}
deinitLogging();
}

View File

@ -1,5 +1,5 @@
#include "modpackSelector.h"
#include "main.h"
#include "globals.h"
#include "utils/input.h"
#include "version.h"
#include <content_redirection/redirection.h>
@ -111,7 +111,7 @@ void HandleMultiModPacks(uint64_t titleID) {
DIR *dir = opendir(modTitleIDPathOld.c_str());
if (dir) {
if (!ScreenInit()) {
OSFatal("Please migrate sd:/sdcafiine to sd:/wiiu/sdcafiine.");
OSFatal("SDCafiine plugin: Please migrate sd:/sdcafiine to sd:/wiiu/sdcafiine.");
}
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
@ -226,16 +226,16 @@ void HandleMultiModPacks(uint64_t titleID) {
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
// We open the storage, so we can persist the configuration the user did.
if (WUPS_OpenStorage() == WUPS_STORAGE_ERROR_SUCCESS) {
gAutoApplySingleModpack = !gAutoApplySingleModpack;
// If the value has changed, we store it in the storage.
if (WUPS_StoreInt(nullptr, AUTO_APPLY_SINGLE_MODPACK_STRING, gAutoApplySingleModpack) != WUPS_STORAGE_ERROR_SUCCESS) {
}
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
// If the value has changed, we store it in the storage.
if (WUPSStorageAPI::Store(AUTO_APPLY_SINGLE_MODPACK_STRING, gAutoApplySingleModpack) == WUPS_STORAGE_ERROR_SUCCESS) {
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
} else {
DEBUG_FUNCTION_LINE_WARN("Failed to save to storage");
}
initScreen = 1;
} else if (buttonsTriggered & VPAD_BUTTON_B) {
break;
@ -252,8 +252,12 @@ void HandleMultiModPacks(uint64_t titleID) {
selected += per_page;
initScreen = 1;
}
if (selected < 0) { selected = 0; }
if (selected >= modTitlePath.size()) { selected = modTitlePath.size() - 1; }
if (selected < 0) {
selected = 0;
}
if (selected >= (int) modTitlePath.size()) {
selected = modTitlePath.size() - 1;
}
page = selected / per_page;
if (initScreen) {
@ -308,20 +312,18 @@ void HandleMultiModPacks(uint64_t titleID) {
KPADShutdown();
}
extern CRLayerHandle contentLayerHandle;
extern CRLayerHandle aocLayerHandle;
bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle);
bool ReplaceContent(const std::string &basePath, const std::string &modpack) {
bool contentRes = ReplaceContentInternal(basePath, "content", &contentLayerHandle);
bool aocRes = ReplaceContentInternal(basePath, "aoc", &aocLayerHandle);
bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle);
bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle);
if (!contentRes && !aocRes) {
auto screenWasAllocated = screenBuffer_0 != nullptr;
if (!ScreenInit()) {
OSFatal("Failed to apply the modpack.");
OSFatal("SDCafiine plugin: Failed to apply the modpack.");
}
uint32_t sleepTime = 3000;
DEBUG_FUNCTION_LINE_ERR("Failed to apply the modpack. Starting without mods.");
@ -394,7 +396,6 @@ bool ReplaceContentInternal(const std::string &basePath, const std::string &subd
DEBUG_FUNCTION_LINE("Redirect /vol/%s to %s", subdir.c_str(), fullPath.c_str());
} else {
DEBUG_FUNCTION_LINE_ERR("Failed to redirect /vol/%s to %s", subdir.c_str(), fullPath.c_str());
return false;
}
return true;

92
src/utils/config.cpp Normal file
View File

@ -0,0 +1,92 @@
#include "config.h"
#include "globals.h"
#include "logger.h"
#include <wups/config.h>
#include <wups/config/WUPSConfigItemBoolean.h>
#include <wups/config_api.h>
#include <wups/storage.h>
static void bool_item_callback(ConfigItemBoolean *item, bool newValue) {
if (!item || !item->identifier) {
DEBUG_FUNCTION_LINE_WARN("Invalid item or identifier in bool item callback");
return;
}
DEBUG_FUNCTION_LINE_VERBOSE("New value in %s changed: %d", item->identifier, newValue);
if (std::string_view(AUTO_APPLY_SINGLE_MODPACK_STRING) == item->identifier) {
gAutoApplySingleModpack = newValue;
} else if (std::string_view(SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING) == item->identifier) {
gSkipPrepareIfSingleModpack = newValue;
} else if (std::string_view(SDCAFIINE_ENABLED_STRING) == item->identifier) {
gSDCafiineEnabled = newValue;
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected boolean item: %s", item->identifier);
return;
}
WUPSStorageError err;
if ((err = WUPSStorageAPI::Store(item->identifier, newValue)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_WARN("Failed to store value %d to storage item \"%s\": %s (%d)", newValue, item->identifier, WUPSStorageAPI_GetStatusStr(err), err);
}
}
static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
try {
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
root.add(WUPSConfigItemBoolean::Create(SDCAFIINE_ENABLED_STRING,
"Enable SDCafiine (game needs to be restarted)",
DEFAULT_SDCAFIINE_ENABLED, gSDCafiineEnabled,
&bool_item_callback));
auto advancedSettings = WUPSConfigCategory::Create("Advanced settings");
advancedSettings.add(WUPSConfigItemBoolean::Create(AUTO_APPLY_SINGLE_MODPACK_STRING,
"Auto apply the modpack if only one modpack exists",
DEFAULT_AUTO_APPLY_SINGLE_MODPACK, gAutoApplySingleModpack,
&bool_item_callback));
advancedSettings.add(WUPSConfigItemBoolean::Create(SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING,
"Skip \"Preparing modpack...\" screen",
DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK, gSkipPrepareIfSingleModpack,
&bool_item_callback));
root.add(std::move(advancedSettings));
} catch (std::exception &e) {
DEBUG_FUNCTION_LINE_ERR("Exception: %s\n", e.what());
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
}
static void ConfigMenuClosedCallback() {
// Save all changes
WUPSStorageError err;
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
}
void InitStorageAndConfig() {
WUPSStorageError err;
if ((err = WUPSStorageAPI::GetOrStoreDefault(AUTO_APPLY_SINGLE_MODPACK_STRING, gAutoApplySingleModpack, DEFAULT_AUTO_APPLY_SINGLE_MODPACK)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", AUTO_APPLY_SINGLE_MODPACK_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(SDCAFIINE_ENABLED_STRING, gSDCafiineEnabled, DEFAULT_SDCAFIINE_ENABLED)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", SDCAFIINE_ENABLED_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, gSkipPrepareIfSingleModpack, DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", gSkipPrepareIfSingleModpack, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}
WUPSConfigAPIOptionsV1 configOptions = {.name = "SDCafiine"};
WUPSConfigAPIStatus configErr;
if ((configErr = WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback)) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init config api: %s (%d)", WUPSConfigAPI_GetStatusStr(configErr), configErr);
}
}

3
src/utils/config.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void InitStorageAndConfig();