From 23c8635ca01d635e7820b4fdde9593e968fd35e3 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 25 Apr 2024 14:05:23 +0200 Subject: [PATCH] Add support for API 3 --- Dockerfile | 4 +- Dockerfile.buildlocal | 2 +- Makefile | 2 +- include/wups_backend/PluginUtils.h | 8 ++-- include/wups_backend/api.h | 4 +- include/wups_backend/import_defines.h | 6 +++ source/PluginUtils.cpp | 16 +++---- source/api.cpp | 60 +++++++++++++++++++++++---- 8 files changed, 74 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index edaa45e..56f43b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ -FROM ghcr.io/wiiu-env/devkitppc:20231112 - -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240302-3b5cc2f /artifacts $DEVKITPRO +FROM ghcr.io/wiiu-env/devkitppc:20240423 WORKDIR tmp_build COPY . . diff --git a/Dockerfile.buildlocal b/Dockerfile.buildlocal index 1b1e606..bb8c5c8 100644 --- a/Dockerfile.buildlocal +++ b/Dockerfile.buildlocal @@ -1,3 +1,3 @@ -FROM ghcr.io/wiiu-env/devkitppc:20231112 +FROM ghcr.io/wiiu-env/devkitppc:20240423 WORKDIR project \ No newline at end of file diff --git a/Makefile b/Makefile index 1cd20a2..eaec28b 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ include $(DEVKITPRO)/wut/share/wut_rules WUPS_ROOT := $(DEVKITPRO)/wups export VER_MAJOR := 1 -export VER_MINOR := 2 +export VER_MINOR := 3 export VER_PATCH := 0 VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) diff --git a/include/wups_backend/PluginUtils.h b/include/wups_backend/PluginUtils.h index 364c734..13272c0 100644 --- a/include/wups_backend/PluginUtils.h +++ b/include/wups_backend/PluginUtils.h @@ -26,15 +26,15 @@ const char *GetStatusStr(PluginBackendApiErrorType err); namespace PluginUtils { -std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err); +std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr); -std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err); +std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr); std::vector getLoadedPlugins(PluginBackendApiErrorType &err); -std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err); +std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr); -std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err); +std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr); PluginBackendApiErrorType LoadAndLinkOnRestart(const std::vector &plugins); diff --git a/include/wups_backend/api.h b/include/wups_backend/api.h index 8bda107..6226b43 100644 --- a/include/wups_backend/api.h +++ b/include/wups_backend/api.h @@ -30,9 +30,9 @@ PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(wups_backend_plugin PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(wups_backend_plugin_data_handle *output, char *buffer, size_t size); -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path, PluginBackendPluginParseError *errOut); -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size, PluginBackendPluginParseError *errOut); PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, const wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size); diff --git a/include/wups_backend/import_defines.h b/include/wups_backend/import_defines.h index c6b6785..bca349b 100644 --- a/include/wups_backend/import_defines.h +++ b/include/wups_backend/import_defines.h @@ -69,3 +69,9 @@ typedef enum PluginBackendApiErrorType { PLUGIN_BACKEND_API_ERROR_LIB_UNINITIALIZED = 0xFFFFFFF7, PLUGIN_BACKEND_API_ERROR_UNSUPPORTED_COMMAND = 0xFFFFFFF6, } PluginBackendApiErrorType; + +typedef enum PluginBackendPluginParseError { + PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_NONE = 0, + PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_UNKNOWN = -1, + PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION = -2, +} PluginBackendPluginParseError; diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index 43aa571..3039a12 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -45,26 +45,26 @@ static std::optional getMetaInformation(const wups_backen info.size); } -std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) { +std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr) { wups_backend_plugin_information info = {}; - if ((err = WUPSBackend_GetPluginMetaInformationByBuffer(&info, buffer, size)) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetPluginMetaInformationByBuffer(&info, buffer, size, &parseErr)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for buffer %08X with size %08X", buffer, size); return {}; } return getMetaInformation(info, err); } -std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err) { +std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr) { wups_backend_plugin_information info = {}; - if ((err = WUPSBackend_GetPluginMetaInformationByPath(&info, path.c_str())) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetPluginMetaInformationByPath(&info, path.c_str(), &parseErr)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for %s", path.c_str()); return {}; } return getMetaInformation(info, err); } -std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err) { - auto metaInfoOpt = getMetaInformationForPath(path, err); +std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr) { + auto metaInfoOpt = getMetaInformationForPath(path, err, parseErr); if (!metaInfoOpt) { DEBUG_FUNCTION_LINE_ERR("Failed to get MetaInformation for path %s", path.c_str()); return {}; @@ -79,8 +79,8 @@ std::optional getPluginForPath(const std::string &path, PluginB return PluginContainer(PluginData(dataHandle), std::move(metaInfoOpt.value())); } -std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) { - auto metaInfoOpt = getMetaInformationForBuffer(buffer, size, err); +std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr) { + auto metaInfoOpt = getMetaInformationForBuffer(buffer, size, err, parseErr); if (!metaInfoOpt) { DEBUG_FUNCTION_LINE_ERR("Failed to get MetaInformation for buffer %08X (%d bytes)", buffer, size); return {}; diff --git a/source/api.cpp b/source/api.cpp index 45da567..12bd6f0 100644 --- a/source/api.cpp +++ b/source/api.cpp @@ -14,11 +14,18 @@ static PluginBackendApiErrorType (*sWUPSGetSectionInformationForPlugin)( uint32_t buffer_size, uint32_t *out_count) = nullptr; -static PluginBackendApiErrorType (*sWUPSGetNumberOfLoadedPlugins)(uint32_t *out) = nullptr; -static PluginBackendApiErrorType (*sWUPSWillReloadPluginsOnNextLaunch)(bool *out) = nullptr; +static PluginBackendApiErrorType (*sWUPSGetNumberOfLoadedPlugins)(uint32_t *out) = nullptr; +static PluginBackendApiErrorType (*sWUPSWillReloadPluginsOnNextLaunch)(bool *out) = nullptr; static PluginBackendApiErrorType (*sWUPSGetSectionMemoryAddresses)(wups_backend_plugin_container_handle handle, void **textAddress, - void **dataAddress) = nullptr; + void **dataAddress) = nullptr; +static PluginBackendApiErrorType (*sWUPSGetPluginMetaInformationByPathEx)(wups_backend_plugin_information *output, + const char *path, + PluginBackendPluginParseError *err) = nullptr; +static PluginBackendApiErrorType (*sWUPSGetPluginMetaInformationByBufferEx)(wups_backend_plugin_information *output, + char *buffer, + size_t size, + PluginBackendPluginParseError *err) = nullptr; static bool sLibInitDone = false; @@ -81,6 +88,16 @@ PluginBackendApiErrorType WUPSBackend_InitLibrary() { sWUPSGetSectionMemoryAddresses = nullptr; } + if (OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSGetPluginMetaInformationByPathEx", (void **) &sWUPSGetPluginMetaInformationByPathEx) != OS_DYNLOAD_OK) { + DEBUG_FUNCTION_LINE_WARN("FindExport WUPSGetPluginMetaInformationByPathEx failed."); + sWUPSGetPluginMetaInformationByPathEx = nullptr; + } + + if (OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSGetPluginMetaInformationByBufferEx", (void **) &sWUPSGetPluginMetaInformationByBufferEx) != OS_DYNLOAD_OK) { + DEBUG_FUNCTION_LINE_WARN("FindExport WUPSGetPluginMetaInformationByBufferEx failed."); + sWUPSGetPluginMetaInformationByBufferEx = nullptr; + } + auto res = WUPSBackend_GetApiVersion(&sWUPSAPIVersion); if (res != PLUGIN_BACKEND_API_ERROR_NONE) { sWUPSAPIVersion = WUPS_BACKEND_MODULE_API_VERSION_ERROR; @@ -204,14 +221,39 @@ PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(wups_backend_plug return WUPSLoadPluginAsDataByBuffer(output, buffer, size); } -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path) { - PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); - return WUPSGetPluginMetaInformationByPath(output, path); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path, PluginBackendPluginParseError *err) { + if (sWUPSAPIVersion == WUPS_BACKEND_MODULE_API_VERSION_ERROR || sWUPSGetPluginMetaInformationByPathEx == nullptr || sWUPSAPIVersion < 3) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); + auto res = WUPSGetPluginMetaInformationByPath(output, path); + if (err) { + *err = res == PLUGIN_BACKEND_API_ERROR_NONE ? PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_NONE : PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_UNKNOWN; + } + return res; + } + + if (output == nullptr || path == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + + return reinterpret_cast(sWUPSGetPluginMetaInformationByPathEx)(output, path, err); } -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size) { - PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); - return WUPSGetPluginMetaInformationByBuffer(output, buffer, size); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size, PluginBackendPluginParseError *err) { + if (sWUPSAPIVersion == WUPS_BACKEND_MODULE_API_VERSION_ERROR || sWUPSGetPluginMetaInformationByBufferEx == nullptr || sWUPSAPIVersion < 3) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); + + auto res = WUPSGetPluginMetaInformationByBuffer(output, buffer, size); + if (err) { + *err = res == PLUGIN_BACKEND_API_ERROR_NONE ? PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_NONE : PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_UNKNOWN; + } + return res; + } + + if (output == nullptr || buffer == nullptr || size == 0) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + + return reinterpret_cast(sWUPSGetPluginMetaInformationByBufferEx)(output, buffer, size, err); } PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, const wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size) {