From 43749f30a8a1c740b35879cf9caa7a6f1c97c4d8 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 3 Sep 2022 16:55:20 +0200 Subject: [PATCH] Use the latest version of the CRGetVersion implementation --- include/content_redirection/redirection.h | 13 +++++++++---- source/utils.cpp | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/content_redirection/redirection.h b/include/content_redirection/redirection.h index a9c7600..5ecbacf 100644 --- a/include/content_redirection/redirection.h +++ b/include/content_redirection/redirection.h @@ -52,7 +52,7 @@ typedef enum ContentRedirectionStatus { typedef uint32_t CRLayerHandle; typedef uint32_t ContentRedirectionVersion; -#define CONTENT_REDIRECT_MODULE_VERSION 0x00000001 +#define CONTENT_REDIRECTION_MODULE_VERSION_ERROR 0xFFFFFFFF typedef enum ContentRedirectionApiErrorType { CONTENT_REDIRECTION_API_ERROR_NONE = 0, @@ -73,10 +73,15 @@ typedef enum ContentRedirectionApiErrorType { ContentRedirectionStatus ContentRedirection_InitLibrary(); /** - * Returns the API Version of the Content Redirection Module. - * @return The ContentRedirectionVersion of the Module + * Retrieves the API Version of the loaded ContentRedirectionModule.
+ *
+ * @param outVersion pointer to the variable where the version will be stored. + * + * @return CONTENT_REDIRECTION_RESULT_SUCCESS: The API version has been store in the version ptr.
+ * CONTENT_REDIRECTION_RESULT_INVALID_ARGUMENT: Invalid version pointer.
+ * CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR: Retrieving the module version failed. */ -ContentRedirectionVersion ContentRedirection_GetVersion(); +ContentRedirectionStatus ContentRedirection_GetVersion(ContentRedirectionVersion *outVersion); /** * Adds a a FSLayers that redirects the /vol/content or /vol/save fs calles for the Game/Wii U Menu process. diff --git a/source/utils.cpp b/source/utils.cpp index a59b9b7..9284e54 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -8,10 +8,13 @@ static OSDynLoad_Module sModuleHandle = nullptr; static ContentRedirectionApiErrorType (*sCRAddFSLayer)(CRLayerHandle *, const char *, const char *, FSLayerType) = nullptr; static ContentRedirectionApiErrorType (*sCRRemoveFSLayer)(CRLayerHandle) = nullptr; static ContentRedirectionApiErrorType (*sCRSetActive)(CRLayerHandle) = nullptr; -static ContentRedirectionVersion (*sCRGetVersion)() = nullptr; +static ContentRedirectionApiErrorType (*sCRGetVersion)(ContentRedirectionVersion *) = nullptr; static ContentRedirectionApiErrorType (*sCRAddDevice)(const devoptab_t *, int *) = nullptr; static ContentRedirectionApiErrorType (*sCRRemoveDevice)(const char *) = nullptr; + +static ContentRedirectionVersion sContentRedirectionVersion = CONTENT_REDIRECTION_MODULE_VERSION_ERROR; + ContentRedirectionStatus ContentRedirection_InitLibrary() { if (OSDynLoad_Acquire("homebrew_content_redirection", &sModuleHandle) != OS_DYNLOAD_OK) { OSReport("ContentRedirection_Init: OSDynLoad_Acquire failed.\n"); @@ -22,8 +25,8 @@ ContentRedirectionStatus ContentRedirection_InitLibrary() { OSReport("ContentRedirection_Init: CRGetVersion failed.\n"); return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT; } - auto res = ContentRedirection_GetVersion(); - if (res != CONTENT_REDIRECT_MODULE_VERSION) { + auto res = ContentRedirection_GetVersion(&sContentRedirectionVersion); + if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) { return CONTENT_REDIRECTION_RESULT_UNSUPPORTED_VERSION; } @@ -55,13 +58,17 @@ ContentRedirectionStatus ContentRedirection_InitLibrary() { return CONTENT_REDIRECTION_RESULT_SUCCESS; } -ContentRedirectionVersion GetVersion(); -ContentRedirectionVersion ContentRedirection_GetVersion() { +ContentRedirectionApiErrorType GetVersion(ContentRedirectionVersion *); +ContentRedirectionStatus ContentRedirection_GetVersion(ContentRedirectionVersion *outVariable) { if (sCRGetVersion == nullptr) { return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED; } - return reinterpret_cast(sCRGetVersion)(); + auto res = reinterpret_cast(sCRGetVersion)(outVariable); + if (res == CONTENT_REDIRECTION_API_ERROR_NONE) { + return CONTENT_REDIRECTION_RESULT_SUCCESS; + } + return res == CONTENT_REDIRECTION_API_ERROR_INVALID_ARG ? CONTENT_REDIRECTION_RESULT_INVALID_ARGUMENT : CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR; }