Try to get the environment path from IOSU to support IOSU reloading

This commit is contained in:
Maschell 2021-12-28 15:40:37 +01:00
parent e3b8de0204
commit f926166929

View File

@ -5,6 +5,7 @@
#include <sysapp/launch.h> #include <sysapp/launch.h>
#include <coreinit/foreground.h> #include <coreinit/foreground.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <nn/act/client_cpp.h> #include <nn/act/client_cpp.h>
#include <coreinit/dynload.h> #include <coreinit/dynload.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
@ -61,10 +62,27 @@ int main(int argc, char **argv) {
WHBLogUdpInit(); WHBLogUdpInit();
} }
DEBUG_FUNCTION_LINE("Hello from EnvironmentLoader!");
char environmentPath[0x100];
memset(environmentPath, 0, sizeof(environmentPath));
auto handle = IOS_Open("/dev/mcp", IOS_OPEN_READ);
if (handle >= 0) {
int in = 0xF9; // IPC_CUSTOM_COPY_ENVIRONMENT_PATH
if (IOS_Ioctl(handle, 100, &in, sizeof(in), environmentPath, sizeof(environmentPath)) == IOS_ERROR_OK) {
DEBUG_FUNCTION_LINE("Boot into %s", environmentPath);
}
IOS_Close(handle);
}
// 0x100 because before the .text section is a .init section // 0x100 because before the .text section is a .init section
// Currently the size of the .init is ~ 0x24 bytes. We substract 0x100 to be safe. // Currently the size of the .init is ~ 0x24 bytes. We substract 0x100 to be safe.
uint32_t textSectionStart = textStart() - 0x1000; uint32_t textSectionStart = textStart() - 0x1000;
std::string environment_path = std::string(environmentPath);
if (strncmp(environmentPath, "fs:/vol/external01/wiiu/environments/", strlen("fs:/vol/external01/wiiu/environments/")) != 0) {
DirList environmentDirs("fs:/vol/external01/wiiu/environments/", nullptr, DirList::Dirs, 1); DirList environmentDirs("fs:/vol/external01/wiiu/environments/", nullptr, DirList::Dirs, 1);
std::map<std::string, std::string> environmentPaths; std::map<std::string, std::string> environmentPaths;
@ -81,11 +99,13 @@ int main(int argc, char **argv) {
btn = vpad_data.hold | vpad_data.trigger; btn = vpad_data.hold | vpad_data.trigger;
} }
std::string environment_path = "fs:/vol/external01/wiiu/environments/default"; environment_path = "fs:/vol/external01/wiiu/environments/default";
if ((btn & VPAD_BUTTON_X) == VPAD_BUTTON_X) { if ((btn & VPAD_BUTTON_X) == VPAD_BUTTON_X) {
environment_path = EnvironmentSelectionScreen(environmentPaths); environment_path = EnvironmentSelectionScreen(environmentPaths);
DEBUG_FUNCTION_LINE("Selected %s", environment_path.c_str()); DEBUG_FUNCTION_LINE("Selected %s", environment_path.c_str());
} }
}
DirList setupModules(environment_path + "/modules/setup", ".rpx", DirList::Files, 1); DirList setupModules(environment_path + "/modules/setup", ".rpx", DirList::Files, 1);
setupModules.SortList(); setupModules.SortList();