Skip to content

Commit

Permalink
Implement support for API Version 3 (RPXLoader_GetPathOfSaveRedirection)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Mar 29, 2024
1 parent cad78bc commit f4a22de
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/wut/share/wut_rules

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
19 changes: 18 additions & 1 deletion include/rpxloader/rpxloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,31 @@ RPXLoaderStatus RPXLoader_UnmountCurrentRunningBundle();
*
* @param outBuffer buffer where the result will be stored
* @param outSize size of outBuffer
* @return RPX_LOADER_RESULT_SUCCESS: The path of the currently running executable has been written to outBuffer
* @return RPX_LOADER_RESULT_SUCCESS: The path of the currently running executable has been written to outBuffer. <br>
* RPX_LOADER_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded RPXLoaderModule version.<br>
* RPX_LOADER_RESULT_INVALID_ARGUMENT: The given outBuffer was NULL or outSize was 0 <br>
* RPX_LOADER_RESULT_LIB_UNINITIALIZED: "RPXLoader_Init()" was not called.<br>
* RPX_LOADER_RESULT_NOT_AVAILABLE: The path is not available.<br>
*/
RPXLoaderStatus RPXLoader_GetPathOfRunningExecutable(char *outBuffer, uint32_t outSize);

/**
* Returns the path currently used for /vol/save redirection <br>
* This function is not guaranteed to succeed, it only works if the executable is loaded via the RPXLoadingModule <br>
* The returned path is relative to the root of the sd card. <br>
* <br>
* Requires API version 3 or higher. <br>
*
* @param outBuffer buffer where the result will be stored
* @param outSize size of outBuffer
* @return RPX_LOADER_RESULT_SUCCESS: The path of the /vol/save redirection has been written to outBuffer.<br>
* RPX_LOADER_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded RPXLoaderModule version.<br>
* RPX_LOADER_RESULT_INVALID_ARGUMENT: The given outBuffer was NULL or outSize was 0 <br>
* RPX_LOADER_RESULT_LIB_UNINITIALIZED: "RPXLoader_Init()" was not called.<br>
* RPX_LOADER_RESULT_NOT_AVAILABLE: The path is not available.<br>
*/
RPXLoaderStatus RPXLoader_GetPathOfSaveRedirection(char *outBuffer, uint32_t outSize);

#ifdef __cplusplus
} // extern "C"
#endif
17 changes: 17 additions & 0 deletions source/rpxloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static RPXLoaderStatus (*sRLDisableContentRedirection)()
static RPXLoaderStatus (*sRLEnableContentRedirection)() = nullptr;
static RPXLoaderStatus (*sRLUnmountCurrentRunningBundle)() = nullptr;
static RPXLoaderStatus (*sRL_GetPathOfRunningExecutable)(char *outBuffer, uint32_t outSize) = nullptr;
static RPXLoaderStatus (*sRL_GetPathOfSaveRedirection)(char *outBuffer, uint32_t outSize) = nullptr;

const char *RPXLoader_GetStatusStr(RPXLoaderStatus status) {
switch (status) {
Expand Down Expand Up @@ -93,6 +94,11 @@ RPXLoaderStatus RPXLoader_InitLibrary() {
sRL_GetPathOfRunningExecutable = nullptr;
}

if (OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "RL_GetPathOfSaveRedirection", (void **) &sRL_GetPathOfSaveRedirection) != OS_DYNLOAD_OK) {
DEBUG_FUNCTION_LINE_WARN("FindExport RL_GetPathOfRunningExecutable failed.");
sRL_GetPathOfSaveRedirection = nullptr;
}

return RPX_LOADER_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -193,4 +199,15 @@ RPXLoaderStatus RPXLoader_GetPathOfRunningExecutable(char *outBuffer, uint32_t o
}

return reinterpret_cast<decltype(&RPXLoader_GetPathOfRunningExecutable)>(sRL_GetPathOfRunningExecutable)(outBuffer, outSize);
}

RPXLoaderStatus RPXLoader_GetPathOfSaveRedirection(char *outBuffer, uint32_t outSize) {
if (rpxLoaderVersion == RPX_LOADER_MODULE_VERSION_ERROR) {
return RPX_LOADER_RESULT_LIB_UNINITIALIZED;
}
if (sRL_GetPathOfSaveRedirection == nullptr || rpxLoaderVersion < 3) {
return RPX_LOADER_RESULT_UNSUPPORTED_COMMAND;
}

return reinterpret_cast<decltype(&RPXLoader_GetPathOfSaveRedirection)>(sRL_GetPathOfSaveRedirection)(outBuffer, outSize);
}

0 comments on commit f4a22de

Please sign in to comment.