diff --git a/source/dynload/dynload.cpp b/source/dynload/dynload.cpp index e6484c5..0d3a2ed 100644 --- a/source/dynload/dynload.cpp +++ b/source/dynload/dynload.cpp @@ -10,6 +10,11 @@ void initDynload() { DEBUG_FUNCTION_LINE_ERR("Failed to allocate gLoadedRPLData"); OSFatal("AromaBaseModule: Failed to allocate gLoadedRPLData"); } + gRPLData = (RPL_DATA *) malloc(sizeof(RPL_DATA) * gModuleData->number_modules); + if (!gRPLData) { + DEBUG_FUNCTION_LINE_ERR("Failed to allocate gRPLData"); + OSFatal("AromaBaseModule: Failed to allocate gRPLData"); + } DEBUG_FUNCTION_LINE("Patch functions for dynload patches"); for (uint32_t i = 0; i < dynload_function_replacements_size; i++) { diff --git a/source/dynload/dynload_function_replacements.cpp b/source/dynload/dynload_function_replacements.cpp index d1b3cb5..73df0b4 100644 --- a/source/dynload/dynload_function_replacements.cpp +++ b/source/dynload/dynload_function_replacements.cpp @@ -77,10 +77,14 @@ DECL_FUNCTION(LOADED_RPL *, LiFindRPLByName, char *name) { return real_LiFindRPLByName(name); } -DECL_FUNCTION(uint32_t, __OSDynLoad_InternalAcquire, char *name, void *out, uint32_t u1, uint32_t u2, uint32_t u3) { +DECL_FUNCTION(uint32_t, __OSDynLoad_InternalAcquire, char *name, RPL_DATA **out, uint32_t u1, uint32_t u2, uint32_t u3) { for (uint32_t i = 0; i < gModuleData->number_modules; i++) { auto *curModule = &gModuleData->modules[i]; if (strcmp(name, curModule->module_export_name) == 0) { + // OSDynLoad_IsModuleLoaded uses __OSDynLoad_InternalAcquire and expects out have a valid value. + // It uses the "handle", so don't need to fill the whole struct. + gRPLData[i].handle = MODULE_MAGIC | i; + *out = &gRPLData[i]; return 0; } } diff --git a/source/dynload/loader_defines.h b/source/dynload/loader_defines.h index 6fd6bf7..ce64a44 100644 --- a/source/dynload/loader_defines.h +++ b/source/dynload/loader_defines.h @@ -1,6 +1,7 @@ #pragma once #include +#include // see https://github.com/decaf-emu/decaf-emu/tree/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader struct LiImportTracking { @@ -35,6 +36,14 @@ struct LOADED_RPL { char u4[12]; }; +// https://github.com/decaf-emu/decaf-emu/blob/6feb1be1db3938e6da2d4a65fc0a7a8599fc8dd6/src/libdecaf/src/cafe/libraries/coreinit/coreinit_dynload.cpp#L40 +struct RPL_DATA { + uint32_t handle; + WUT_UNKNOWN_BYTES(0x94 - 0x4); +}; +WUT_CHECK_SIZE(RPL_DATA, 0x94); + + #define EXPORT_MASK 0xFFFF0000 #define EXPORT_MAGIC_MASK 0x0000FFFF #define FUNCTION_EXPORT_MAGIC 0x88660000 diff --git a/source/globals.cpp b/source/globals.cpp index 59aef61..cf07d78 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -2,4 +2,5 @@ module_information_t *gModuleData __attribute__((section(".data"))) = NULL; int32_t gSDMountRefCount __attribute__((section(".data"))) = 0; -LOADED_RPL *gLoadedRPLData __attribute__((section(".data"))) = nullptr; \ No newline at end of file +LOADED_RPL *gLoadedRPLData __attribute__((section(".data"))) = nullptr; +RPL_DATA *gRPLData __attribute__((section(".data"))) = nullptr; \ No newline at end of file diff --git a/source/globals.h b/source/globals.h index fd68b33..79e833d 100644 --- a/source/globals.h +++ b/source/globals.h @@ -3,4 +3,5 @@ extern module_information_t *gModuleData; extern int32_t gSDMountRefCount; -extern LOADED_RPL *gLoadedRPLData; \ No newline at end of file +extern LOADED_RPL *gLoadedRPLData; +extern RPL_DATA *gRPLData; \ No newline at end of file