Skip to content

Commit

Permalink
Add support for the first functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jul 31, 2023
1 parent c9b54b0 commit a293ce1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
26 changes: 26 additions & 0 deletions include/modpack_loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef enum ModpackLoaderStatus {
MODPACK_LOADER_RESULT_UNKNOWN_ERROR = -0x1000,
} ModpackLoaderStatus;

typedef uint32_t MPLModpackHandle;
typedef uint32_t ModpackLoaderVersion;

#define MODPACK_LOADER_MODULE_VERSION_ERROR 0xFFFFFFFF
Expand Down Expand Up @@ -50,6 +51,31 @@ ModpackLoaderStatus ModpackLoader_DeInitLibrary();
*/
ModpackLoaderStatus ModpackLoader_GetVersion(ModpackLoaderVersion *outVersion);

/**
*
* @param path. Path to a .wuhb with a valid /vol/content/modpack.ini. This path is supposed to be related to the root of the SD card.
* @param outHandle
* @return
*/
ModpackLoaderStatus ModpackLoader_ParseModpackByPath(const char *path, MPLModpackHandle *outHandle);

/**
* !!! Calling this function unmounts the currently running WUHB !!!
* @param outHandle
* @return
*/
ModpackLoaderStatus ModpackLoader_ParseModpackFromCurrentlyRunningWUHB(MPLModpackHandle *outHandle);

ModpackLoaderStatus ModpackLoader_CheckIfLaunchable(MPLModpackHandle handle, bool *readyToLaunchOut);

/**
*
* @param handle
* @param launchedOut
* @return
*/
ModpackLoaderStatus ModpackLoader_LaunchModpack(MPLModpackHandle handle, bool *launchedOut);

#ifdef __cplusplus
} // extern "C"
#endif
72 changes: 70 additions & 2 deletions source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

static OSDynLoad_Module sModuleHandle = nullptr;

static ModpackLoaderStatus (*sMPLGetversion)(ModpackLoaderVersion *) = nullptr;
static ModpackLoaderStatus (*sMPLGetversion)(ModpackLoaderVersion *) = nullptr;
static ModpackLoaderStatus (*sMPLParseModpackByPath)(const char *, MPLModpackHandle *) = nullptr;
static ModpackLoaderStatus (*sMPLParseModpackFromCurrentlyRunningWUHB)(MPLModpackHandle *) = nullptr;
static ModpackLoaderStatus (*sMPLCheckIfLaunchable)(MPLModpackHandle, bool *) = nullptr;
static ModpackLoaderStatus (*sMPLLaunchModpack)(MPLModpackHandle, bool *) = nullptr;

static ModpackLoaderVersion sModpackLoaderVersion = MODPACK_LOADER_MODULE_VERSION_ERROR;

Expand Down Expand Up @@ -49,6 +53,26 @@ ModpackLoaderStatus ModpackLoader_InitLibrary() {
return MODPACK_LOADER_RESULT_UNSUPPORTED_VERSION;
}

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

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

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

if (OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "MPLLaunchModpack", (void **) &sMPLLaunchModpack) != OS_DYNLOAD_OK) {
DEBUG_FUNCTION_LINE_WARN("FindExport MPLLaunchModpack failed.");
sMPLCheckIfLaunchable = nullptr;
}

return MODPACK_LOADER_RESULT_SUCCESS;
}

Expand All @@ -70,4 +94,48 @@ ModpackLoaderStatus ModpackLoader_GetVersion(ModpackLoaderVersion *outVariable)
}

return reinterpret_cast<decltype(&ModpackLoader_GetVersion)>(sMPLGetversion)(outVariable);
}
}

ModpackLoaderStatus ModpackLoader_ParseModpackFromCurrentlyRunningWUHB(MPLModpackHandle *outHandle) {
if (sModpackLoaderVersion == MODPACK_LOADER_MODULE_VERSION_ERROR) {
return MODPACK_LOADER_RESULT_LIB_UNINITIALIZED;
}
if (sMPLParseModpackFromCurrentlyRunningWUHB == nullptr || sModpackLoaderVersion < 1) {
return MODPACK_LOADER_RESULT_UNSUPPORTED_COMMAND;
}

return reinterpret_cast<decltype(&ModpackLoader_ParseModpackFromCurrentlyRunningWUHB)>(sMPLParseModpackFromCurrentlyRunningWUHB)(outHandle);
}

ModpackLoaderStatus ModpackLoader_ParseModpackByPath(const char *path, MPLModpackHandle *outHandle) {
if (sModpackLoaderVersion == MODPACK_LOADER_MODULE_VERSION_ERROR) {
return MODPACK_LOADER_RESULT_LIB_UNINITIALIZED;
}
if (sMPLParseModpackByPath == nullptr || sModpackLoaderVersion < 1) {
return MODPACK_LOADER_RESULT_UNSUPPORTED_COMMAND;
}

return reinterpret_cast<decltype(&ModpackLoader_ParseModpackByPath)>(sMPLParseModpackByPath)(path, outHandle);
}

ModpackLoaderStatus ModpackLoader_CheckIfLaunchable(MPLModpackHandle handle, bool *readyToLaunchOut) {
if (sModpackLoaderVersion == MODPACK_LOADER_MODULE_VERSION_ERROR) {
return MODPACK_LOADER_RESULT_LIB_UNINITIALIZED;
}
if (sMPLCheckIfLaunchable == nullptr || sModpackLoaderVersion < 1) {
return MODPACK_LOADER_RESULT_UNSUPPORTED_COMMAND;
}

return reinterpret_cast<decltype(&ModpackLoader_CheckIfLaunchable)>(sMPLCheckIfLaunchable)(handle, readyToLaunchOut);
}

ModpackLoaderStatus ModpackLoader_LaunchModpack(MPLModpackHandle handle, bool *launchedOut) {
if (sModpackLoaderVersion == MODPACK_LOADER_MODULE_VERSION_ERROR) {
return MODPACK_LOADER_RESULT_LIB_UNINITIALIZED;
}
if (sMPLLaunchModpack == nullptr || sModpackLoaderVersion < 1) {
return MODPACK_LOADER_RESULT_UNSUPPORTED_COMMAND;
}

return reinterpret_cast<decltype(&ModpackLoader_LaunchModpack)>(sMPLLaunchModpack)(handle, launchedOut);
}

0 comments on commit a293ce1

Please sign in to comment.