diff --git a/Dockerfile b/Dockerfile index 1d20c67..604a0fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM wiiuenv/devkitppc:20210101 +FROM wiiuenv/devkitppc:20210920 + +COPY --from=wiiuenv/wiiupluginsystem:20210924 /artifacts $DEVKITPRO WORKDIR tmp_build COPY . . diff --git a/Makefile b/Makefile index 222bb54..d251ebd 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,10 @@ TOPDIR ?= $(CURDIR) include $(DEVKITPRO)/wut/share/wut_rules +WUPS_ROOT := $(DEVKITPRO)/wups + export VER_MAJOR := 1 -export VER_MINOR := 0 +export VER_MINOR := 1 export VER_PATCH := 0 VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) @@ -33,14 +35,14 @@ INCLUDES := source \ #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS := -Wall -Werror -save-temps \ +CFLAGS := -Wall -Werror -save-temps -fno-exceptions -fno-rtti\ -ffunction-sections -fdata-sections \ $(MACHDEP) \ $(BUILD_CFLAGS) CFLAGS += $(INCLUDE) -D__WIIU__ -CXXFLAGS := $(CFLAGS) -std=gnu++17 +CXXFLAGS := $(CFLAGS) -std=c++20 ASFLAGS := $(MACHDEP) @@ -53,7 +55,7 @@ LIBS := # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := $(PORTLIBS) $(WUT_ROOT) +LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUPS_ROOT) #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional diff --git a/include/wups_backend/PluginContainer.h b/include/wups_backend/PluginContainer.h index ed06ad5..ba1470a 100644 --- a/include/wups_backend/PluginContainer.h +++ b/include/wups_backend/PluginContainer.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2019,2020 Maschell + * Copyright (C) 2019-2021 Maschell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,25 +17,27 @@ #pragma once +#include + #include "PluginMetaInformation.h" #include "PluginData.h" class PluginContainer { public: - PluginContainer(const PluginData &data, const PluginMetaInformation &metaInfo, uint32_t handle) : pluginData(data), metaInformation(metaInfo) { + PluginContainer(const PluginData &data, PluginMetaInformation metaInfo, uint32_t handle) : pluginData(data), metaInformation(std::move(metaInfo)) { this->handle = handle; } - uint32_t getHandle() const { + [[nodiscard]] uint32_t getHandle() const { return this->handle; } - const PluginMetaInformation &getMetaInformation() const { + [[nodiscard]] const PluginMetaInformation &getMetaInformation() const { return this->metaInformation; } - const PluginData &getPluginData() const { + [[nodiscard]] const PluginData &getPluginData() const { return pluginData; } diff --git a/include/wups_backend/PluginData.h b/include/wups_backend/PluginData.h index b3fb438..330db05 100644 --- a/include/wups_backend/PluginData.h +++ b/include/wups_backend/PluginData.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2019,2020 Maschell + * Copyright (C) 2019-2021 Maschell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,12 +16,14 @@ ****************************************************************************/ #pragma once +#include + class PluginData { public: - PluginData(uint32_t handle); + explicit PluginData(uint32_t handle); - uint32_t getHandle() const { + [[nodiscard]] uint32_t getHandle() const { return handle; } diff --git a/include/wups_backend/PluginMetaInformation.h b/include/wups_backend/PluginMetaInformation.h index 04fab24..62da9ba 100644 --- a/include/wups_backend/PluginMetaInformation.h +++ b/include/wups_backend/PluginMetaInformation.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2019,2020 Maschell + * Copyright (C) 2019-2021 Maschell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,72 +23,80 @@ class PluginMetaInformation { public: - const std::string getName() const { + [[nodiscard]] const std::string &getName() const { return name; } - const std::string getAuthor() const { + [[nodiscard]] const std::string &getAuthor() const { return this->author; } - const std::string getVersion() const { + [[nodiscard]] const std::string &getVersion() const { return this->version; } - const std::string getLicense() const { + [[nodiscard]] const std::string &getLicense() const { return this->license; } - const std::string getBuildTimestamp() const { + [[nodiscard]] const std::string &getBuildTimestamp() const { return this->buildtimestamp; } - const std::string getDescription() const { + [[nodiscard]] const std::string &getDescription() const { return this->description; } - const size_t getSize() const { + [[nodiscard]] const std::string &getId() const { + return this->description; + } + + [[nodiscard]] size_t getSize() const { return this->size; } - PluginMetaInformation(std::string name, - std::string author, - std::string version, - std::string license, - std::string buildtimestamp, - std::string description, + PluginMetaInformation(const std::string& name, + const std::string& author, + const std::string& version, + const std::string& license, + const std::string& buildtimestamp, + const std::string& description, + const std::string& id, size_t size); private: - PluginMetaInformation() { + PluginMetaInformation() = default; + + void setName(const std::string &name_) { + this->name = name_; } - void setName(const std::string &name) { - this->name = name; + void setAuthor(const std::string &author_) { + this->author = author_; } - void setAuthor(const std::string &author) { - this->author = author; + void setVersion(const std::string &version_) { + this->version = version_; } - void setVersion(const std::string &version) { - this->version = version; + void setLicense(const std::string &license_) { + this->license = license_; } - void setLicense(const std::string &license) { - this->license = license; + void setBuildTimestamp(const std::string &buildtimestamp_) { + this->buildtimestamp = buildtimestamp_; } - void setBuildTimestamp(const std::string &buildtimestamp) { - this->buildtimestamp = buildtimestamp; + void setDescription(const std::string &description_) { + this->description = description_; } - void setDescription(const std::string &description) { - this->description = description; + void setId(const std::string &id_) { + this->id = id_; } - void setSize(size_t size) { - this->size = size; + void setSize(size_t size_) { + this->size = size_; } std::string name; @@ -97,5 +105,6 @@ private: std::string license; std::string buildtimestamp; std::string description; - size_t size; + std::string id; + size_t size{}; }; diff --git a/include/wups_backend/import_defines.h b/include/wups_backend/import_defines.h new file mode 100644 index 0000000..077ded2 --- /dev/null +++ b/include/wups_backend/import_defines.h @@ -0,0 +1,47 @@ +/**************************************************************************** + * Copyright (C) 2019 - 2021 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ + +#pragma once + +typedef enum GetPluginInformationInputType { + PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0, + PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1, +} GetPluginInformationInputType; + +typedef uint32_t plugin_container_handle; +typedef uint32_t plugin_data_handle; + +/* plugin_information message */ +typedef struct __attribute__((__packed__)) plugin_information { + char id[256]; + char name[256]; + char author[256]; + char buildTimestamp[256]; + char description[256]; + char license[256]; + char version[256]; + size_t size; +} plugin_information; + +typedef enum PluginBackendApiErrorType { + PLUGIN_BACKEND_API_ERROR_NONE = 0, + PLUGIN_BACKEND_API_ERROR_INVALID_SIZE = 0xFFFFFFFF, + PLUGIN_BACKEND_API_ERROR_INVALID_ARG = 0xFFFFFFFE, + PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC = 0xFFFFFFFD, + PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND = 0xFFFFFFFC, +} PluginBackendApiErrorType; + diff --git a/source/PluginData.cpp b/source/PluginData.cpp index a15c1df..8959967 100644 --- a/source/PluginData.cpp +++ b/source/PluginData.cpp @@ -15,7 +15,6 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include "wups_backend/PluginData.h" PluginData::PluginData(uint32_t handle) { diff --git a/source/PluginMetaInformation.cpp b/source/PluginMetaInformation.cpp index db1de97..8956218 100644 --- a/source/PluginMetaInformation.cpp +++ b/source/PluginMetaInformation.cpp @@ -19,19 +19,22 @@ #include #include +#include -PluginMetaInformation::PluginMetaInformation(std::string name, - std::string author, - std::string version, - std::string license, - std::string buildtimestamp, - std::string description, - size_t size) { - this->name = name; - this->author = author; - this->size = size; - this->buildtimestamp = buildtimestamp; - this->description = description; - this->license = license; - this->version = version; +PluginMetaInformation::PluginMetaInformation(const std::string& name_, + const std::string& author_, + const std::string& version_, + const std::string& license_, + const std::string& buildtimestamp_, + const std::string& description_, + const std::string& id_, + size_t size_) { + this->name = name_; + this->author = author_; + this->size = size_; + this->buildtimestamp = buildtimestamp_; + this->description = description_; + this->license = license_; + this->version = version_; + this->id = id_; } diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index 8ce6eac..e037f8e 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -20,12 +20,6 @@ #include "wups_backend/PluginUtils.h" #include "imports.h" -#define ERROR_NONE 0 -#define ERROR_INVALID_SIZE 0xFFFFFFFF -#define ERROR_INVALID_ARG 0xFFFFFFFE -#define ERROR_FAILED_ALLOC 0xFFFFFFFD -#define ERROR_FILE_NOT_FOUND 0xFFFFFFFC - std::optional PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { plugin_information info; memset(&info, 0, sizeof(info)); @@ -40,6 +34,7 @@ std::optional PluginUtils::getMetaInformationForBuffer(ch info.license, info.buildTimestamp, info.description, + info.id, info.size); return metaInfo; @@ -48,7 +43,7 @@ std::optional PluginUtils::getMetaInformationForBuffer(ch std::optional PluginUtils::getMetaInformationForPath(const std::string &path) { plugin_information info; memset(&info, 0, sizeof(info)); - if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != ERROR_NONE) { + if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { // DEBUG_FUNCTION_LINE("Failed to load meta infos for %s\n", path.c_str()); return std::nullopt; } @@ -58,6 +53,7 @@ std::optional PluginUtils::getMetaInformationForPath(cons info.license, info.buildTimestamp, info.description, + info.id, info.size); return metaInfo; } @@ -69,12 +65,12 @@ std::optional PluginUtils::getPluginForPath(const std::string & } plugin_data_handle dataHandle; - if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != ERROR_NONE) { + if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { // DEBUG_FUNCTION_LINE("Failed to load data"); return std::nullopt; } - return PluginContainer(PluginData(dataHandle), metaInfoOpt.value(), ERROR_NONE); + return PluginContainer(PluginData(dataHandle), metaInfoOpt.value(), PLUGIN_BACKEND_API_ERROR_NONE); } std::optional PluginUtils::getPluginForBuffer(char *buffer, size_t size) { @@ -84,7 +80,7 @@ std::optional PluginUtils::getPluginForBuffer(char *buffer, siz } plugin_data_handle dataHandle; - if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != ERROR_NONE) { + if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { // DEBUG_FUNCTION_LINE("Failed to load data"); return std::nullopt; } @@ -94,13 +90,17 @@ std::optional PluginUtils::getPluginForBuffer(char *buffer, siz std::vector PluginUtils::getLoadedPlugins(uint32_t maxSize) { std::vector result; - plugin_container_handle *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle)); - if (!handles) { + auto *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle)); + if (handles == nullptr) { return result; } uint32_t realSize = 0; - if (WUPSGetLoadedPlugins(handles, maxSize, &realSize) != ERROR_NONE) { + for (uint32_t i = 0; i < maxSize; i++) { + handles[i] = 0xFFFFFFFF; + } + + if (WUPSGetLoadedPlugins(handles, maxSize, &realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { free(handles); // DEBUG_FUNCTION_LINE("Failed"); return result; @@ -111,26 +111,26 @@ std::vector PluginUtils::getLoadedPlugins(uint32_t maxSize) { return result; } - plugin_data_handle *dataHandles = (plugin_data_handle *) malloc(realSize * sizeof(plugin_data_handle)); - if(!dataHandles){ + auto *dataHandles = (plugin_data_handle *) malloc(realSize * sizeof(plugin_data_handle)); + if (!dataHandles) { free(handles); return result; } - if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != ERROR_NONE) { + if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { free(handles); free(dataHandles); // DEBUG_FUNCTION_LINE("Failed to get plugin data"); return result; } - plugin_information* information = (plugin_information *) malloc(realSize * sizeof(plugin_information)); - if(!information){ + auto *information = (plugin_information *) malloc(realSize * sizeof(plugin_information)); + if (!information) { free(handles); free(dataHandles); return result; } - if (WUPSGetMetaInformation(handles, information, realSize) != ERROR_NONE) { + if (WUPSGetMetaInformation(handles, information, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { free(handles); free(dataHandles); free(information); @@ -145,6 +145,7 @@ std::vector PluginUtils::getLoadedPlugins(uint32_t maxSize) { information[i].license, information[i].buildTimestamp, information[i].description, + information[i].id, information[i].size); PluginData pluginData((uint32_t) dataHandles[i]); result.emplace_back(pluginData, metaInfo, handles[i]); @@ -171,7 +172,7 @@ void PluginUtils::destroyPluginContainer(std::vector &plugins) uint32_t cntC = 0; uint32_t cntD = 0; - for (auto &plugin : plugins) { + for (auto &plugin: plugins) { if (plugin.getHandle() != 0) { container_handles[cntC] = plugin.getHandle(); cntC++; @@ -193,7 +194,7 @@ int32_t PluginUtils::LoadAndLinkOnRestart(std::vector &plugins) uint32_t dataSize = plugins.size(); plugin_data_handle handles[dataSize]; int i = 0; - for (auto &plugin:plugins) { + for (auto &plugin: plugins) { plugin_data_handle handle = plugin.getPluginData().getHandle(); if (handle == 0) { dataSize--; @@ -203,7 +204,5 @@ int32_t PluginUtils::LoadAndLinkOnRestart(std::vector &plugins) } } - int res = WUPSLoadAndLinkByDataHandle(handles, dataSize); - // DEBUG_FUNCTION_LINE("%d", res); - return res; + return WUPSLoadAndLinkByDataHandle(handles, dataSize);; } diff --git a/source/imports.h b/source/imports.h index 215e2fc..9870906 100644 --- a/source/imports.h +++ b/source/imports.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2019,2020 Maschell + * Copyright (C) 2019 - 2021 Maschell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,52 +17,35 @@ #pragma once +#include "wups_backend/import_defines.h" + #ifdef __cplusplus extern "C" { #endif -typedef enum GetPluginInformationInputType { - PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0, - PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1, -} GetPluginInformationInputType; +extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -typedef uint32_t plugin_container_handle; -typedef uint32_t plugin_data_handle; +extern PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size); -/* plugin_information message */ -typedef struct __attribute__((__packed__)) plugin_information { - char name[256]; - char author[256]; - char buildTimestamp[256]; - char description[256]; - char license[256]; - char version[256]; - size_t size; -} plugin_information; +extern PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -extern int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +extern PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out); -extern int32_t WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size); +extern PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path); -extern int32_t WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +extern PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); -extern int32_t WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out); +extern PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output); -extern int32_t WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path); +extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); -extern int32_t WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); +extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); -extern int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output); +extern PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size); -extern int32_t WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); +extern PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); -extern int32_t WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); - -extern int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size); - -extern int32_t WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); - -extern int32_t WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize); +extern PluginBackendApiErrorType WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize); #ifdef __cplusplus }