Skip to content

Commit

Permalink
Add support for API 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 25, 2024
1 parent 9493c4f commit d43ab7e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 28 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 . .
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.buildlocal
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ghcr.io/wiiu-env/devkitppc:20231112
FROM ghcr.io/wiiu-env/devkitppc:20240423

WORKDIR project
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions include/wups_backend/PluginUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const char *GetStatusStr(PluginBackendApiErrorType err);

namespace PluginUtils {

std::optional<PluginMetaInformation> getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err);
std::optional<PluginMetaInformation> getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr);

std::optional<PluginMetaInformation> getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err);
std::optional<PluginMetaInformation> getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr);

std::vector<PluginContainer> getLoadedPlugins(PluginBackendApiErrorType &err);

std::optional<PluginContainer> getPluginForPath(const std::string &path, PluginBackendApiErrorType &err);
std::optional<PluginContainer> getPluginForPath(const std::string &path, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr);

std::optional<PluginContainer> getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err);
std::optional<PluginContainer> getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err, PluginBackendPluginParseError &parseErr);

PluginBackendApiErrorType LoadAndLinkOnRestart(const std::vector<PluginContainer> &plugins);

Expand Down
4 changes: 2 additions & 2 deletions include/wups_backend/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions include/wups_backend/import_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 8 additions & 8 deletions source/PluginUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ static std::optional<PluginMetaInformation> getMetaInformation(const wups_backen
info.size);
}

std::optional<PluginMetaInformation> getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) {
std::optional<PluginMetaInformation> 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<PluginMetaInformation> getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err) {
std::optional<PluginMetaInformation> 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<PluginContainer> getPluginForPath(const std::string &path, PluginBackendApiErrorType &err) {
auto metaInfoOpt = getMetaInformationForPath(path, err);
std::optional<PluginContainer> 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 {};
Expand All @@ -79,8 +79,8 @@ std::optional<PluginContainer> getPluginForPath(const std::string &path, PluginB
return PluginContainer(PluginData(dataHandle), std::move(metaInfoOpt.value()));
}

std::optional<PluginContainer> getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) {
auto metaInfoOpt = getMetaInformationForBuffer(buffer, size, err);
std::optional<PluginContainer> 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 {};
Expand Down
60 changes: 51 additions & 9 deletions source/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<decltype(&WUPSBackend_GetPluginMetaInformationByPath)>(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<decltype(&WUPSBackend_GetPluginMetaInformationByBuffer)>(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) {
Expand Down

0 comments on commit d43ab7e

Please sign in to comment.