From 7d7b04f3eab5f10b1496216b02ecee738e28cc55 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 14 May 2022 16:19:26 +0200 Subject: [PATCH] Use latest librpxloader and libwupsbackend --- Dockerfile | 8 +++---- Makefile | 2 +- src/main.cpp | 10 +++++++++ src/utils/TcpReceiver.cpp | 47 +++++++++++++++++++-------------------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index c18b074..c668bc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM wiiuenv/devkitppc:20211229 +FROM wiiuenv/devkitppc:20220507 -COPY --from=wiiuenv/libwupsbackend:20211001 /artifacts $DEVKITPRO -COPY --from=wiiuenv/librpxloader:20211002 /artifacts $DEVKITPRO -COPY --from=wiiuenv/wiiupluginsystem:20220123 /artifacts $DEVKITPRO +COPY --from=wiiuenv/libwupsbackend:20220514 /artifacts $DEVKITPRO +COPY --from=wiiuenv/librpxloader:20220422 /artifacts $DEVKITPRO +COPY --from=wiiuenv/wiiupluginsystem:20220513 /artifacts $DEVKITPRO WORKDIR project \ No newline at end of file diff --git a/Makefile b/Makefile index 70ffb03..ab666d6 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ CXXFLAGS := $(CFLAGS) -std=gnu++17 ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUPS_ROOT)/share/libwupsbackend.ld -T$(WUMS_ROOT)/share/librpxloader.ld $(WUPSSPECS) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUPS_ROOT)/share/libwupsbackend.ld $(WUPSSPECS) ifeq ($(DEBUG),1) CXXFLAGS += -DDEBUG -g diff --git a/src/main.cpp b/src/main.cpp index 981c34f..cdfb3c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include "utils/TcpReceiver.h" #include "utils/logger.h" +#include +#include #include WUPS_PLUGIN_NAME("Wiiload"); @@ -12,6 +14,14 @@ WUPS_USE_WUT_DEVOPTAB(); TcpReceiver *thread = nullptr; +INITIALIZE_PLUGIN() { + RPXLoaderStatus error; + if ((error = RPXLoader_Init()) != RPX_LOADER_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("WiiLoad Plugin: Failed to init RPXLoader. Error %d", error); + OSFatal("WiiLoad Plugin: Failed to init RPXLoader."); + } +} + /* Entry point */ ON_APPLICATION_START() { initLogging(); diff --git a/src/utils/TcpReceiver.cpp b/src/utils/TcpReceiver.cpp index ffb550f..1326418 100644 --- a/src/utils/TcpReceiver.cpp +++ b/src/utils/TcpReceiver.cpp @@ -7,8 +7,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -148,7 +147,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { // Do we need to unzip this thing? if (haxx[4] > 0 || haxx[5] > 4) { - unsigned char *inflatedData = nullptr; + unsigned char *inflatedData; // We need to unzip... if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) { @@ -240,34 +239,34 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { } else if (inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] == 0x50 && inflatedData[0xA] == 0x4C) { auto newContainer = PluginUtils::getPluginForBuffer((char *) inflatedData, fileSize); if (newContainer) { - auto oldPlugins = PluginUtils::getLoadedPlugins(8); - std::vector finalList; + auto plugins = PluginUtils::getLoadedPlugins(32); - finalList.push_back(newContainer.value()); - for (auto &plugin : oldPlugins) { - if (plugin.metaInformation.getName() == newContainer->metaInformation.getName() && - plugin.metaInformation.getAuthor() == newContainer->metaInformation.getAuthor()) { - DEBUG_FUNCTION_LINE("Skipping duplicate"); - PluginUtils::destroyPluginContainer(plugin); - continue; - } else { - finalList.push_back(plugin); - } - } + auto &metaInformation = newContainer.value()->metaInformation; + + // remove plugins with the same name and author as our new plugin + + plugins.erase(std::remove_if(plugins.begin(), plugins.end(), + [metaInformation](auto &plugin) { + return plugin->metaInformation->getName() == metaInformation->getName() && + plugin->metaInformation->getAuthor() == metaInformation->getAuthor(); + }), + plugins.end()); + + // at the new plugin + plugins.push_back(std::move(newContainer.value())); #ifdef VERBOSE_DEBUG - for (auto &plugin : finalList) { - DEBUG_FUNCTION_LINE_VERBOSE("name: %s", plugin.getMetaInformation().getName().c_str()); - DEBUG_FUNCTION_LINE_VERBOSE("author: %s", plugin.getMetaInformation().getAuthor().c_str()); - DEBUG_FUNCTION_LINE_VERBOSE("handle: %08X", plugin.getPluginData().getHandle()); + for (auto &plugin : plugins) { + DEBUG_FUNCTION_LINE_VERBOSE("name: %s", plugin->getMetaInformation()->getName().c_str()); + DEBUG_FUNCTION_LINE_VERBOSE("author: %s", plugin->getMetaInformation()->getAuthor().c_str()); + DEBUG_FUNCTION_LINE_VERBOSE("handle: %08X", plugin->getPluginData()->getHandle()); DEBUG_FUNCTION_LINE_VERBOSE("===="); } #endif - if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) { - DEBUG_FUNCTION_LINE("Failed to load & link"); + if (PluginUtils::LoadAndLinkOnRestart(plugins) != 0) { + DEBUG_FUNCTION_LINE_ERR("Failed to load & link"); } - PluginUtils::destroyPluginContainer(finalList); free(loadAddress); free(inflatedData); @@ -305,7 +304,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { if (loadedRPX) { DEBUG_FUNCTION_LINE("Starting a homebrew title!"); - RL_LoadFromSDOnNextLaunch(file_path); + RPXLoader_LoadFromSDOnNextLaunch(file_path); uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); _SYSLaunchTitleWithStdArgsInNoSplash(titleID, nullptr);