diff --git a/Dockerfile b/Dockerfile index e77c402..b93feba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,6 @@ FROM wiiuenv/devkitppc:20220303 COPY --from=wiiuenv/wiiupluginsystem:20220123 /artifacts $DEVKITPRO COPY --from=wiiuenv/librpxloader:20220212 /artifacts $DEVKITPRO +COPY --from=wiiuenv/libsdutils:20220303 /artifacts $DEVKITPRO WORKDIR project \ No newline at end of file diff --git a/Makefile b/Makefile index 0f384f8..8c9ad02 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ CFLAGS := -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ -CXXFLAGS := $(CFLAGS) +CXXFLAGS := $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/librpxloader.ld $(WUPSSPECS) @@ -46,7 +46,7 @@ CXXFLAGS += -DDEBUG -g CFLAGS += -DDEBUG -g endif -LIBS := -lwups -lwut -lrpxloader +LIBS := -lwups -lwut -lrpxloader -lsdutils #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/src/SaveRedirection.cpp b/src/SaveRedirection.cpp index 01c6d41..97f79cb 100644 --- a/src/SaveRedirection.cpp +++ b/src/SaveRedirection.cpp @@ -13,7 +13,7 @@ bool gInWiiUMenu __attribute__((section(".data"))); static FSStatus CallWithNewPath(const char *oldPath, const std::function &callFunctionWithPath) { - if (!gInWiiUMenu || strncmp(oldPath, "/vol/save/", 10) != 0) { + if (!sSDIsMounted || !gInWiiUMenu || strncmp(oldPath, "/vol/save/", 10) != 0) { return callFunctionWithPath(oldPath); } diff --git a/src/SaveRedirection.h b/src/SaveRedirection.h index eaac9f1..9d1df21 100644 --- a/src/SaveRedirection.h +++ b/src/SaveRedirection.h @@ -2,6 +2,7 @@ #include extern bool gInWiiUMenu; +extern bool sSDIsMounted; #define SAVE_REPLACEMENT_PATH "/vol/external01/wiiu/homebrew_on_menu_plugin" diff --git a/src/main.cpp b/src/main.cpp index 07b7841..37ca743 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "FileWrapper.h" +#include "SaveRedirection.h" #include "fileinfos.h" #include "filelist.h" #include "fs/FSUtils.h" @@ -16,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -58,13 +60,34 @@ INITIALIZE_PLUGIN() { OSInitMutex(&fileinfoMutex); } +bool sSDUtilsInitDone = false; +bool sSDIsMounted = false; +bool sTitleRebooting = false; + +void SDAttachedHandler(SDUtilsAttachStatus status) { + if (!sTitleRebooting) { + _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), 0); + sTitleRebooting = true; + } +} + ON_APPLICATION_START() { initLogging(); if (OSGetTitleID() == 0x0005001010040000L || // Wii U Menu JPN OSGetTitleID() == 0x0005001010040100L || // Wii U Menu USA - OSGetTitleID() == 0x0005001010040200L) { // Wii U Menu ERU - readCustomTitlesFromSD(); + OSGetTitleID() == 0x0005001010040200L) { // Wii U Menu EUR + + if (SDUtils_Init() >= 0) { + sSDUtilsInitDone = true; + sTitleRebooting = false; + SDUtils_AddAttachHandler(SDAttachedHandler); + } + if (SDUtils_IsSdCardMounted(&sSDIsMounted) >= 0 && sSDIsMounted) { + readCustomTitlesFromSD(); + } + } else { + gInWiiUMenu = false; } if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { @@ -75,8 +98,16 @@ ON_APPLICATION_START() { ON_APPLICATION_ENDS() { unmountAllRomfs(); + memset((void *) &gFileInfos, 0, sizeof(gFileInfos)); FileHandleWrapper_FreeAll(); deinitLogging(); + gInWiiUMenu = false; + if (sSDUtilsInitDone) { + SDUtils_RemoveAttachHandler(SDAttachedHandler); + SDUtils_DeInit(); + sSDUtilsInitDone = false; + } + sSDIsMounted = false; } void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf) {