From 73afc7d7f703bb6a4d001969627fb212d88f7d99 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 22 Oct 2022 19:33:34 -0700 Subject: [PATCH] 3DS: Allow loading ROM out of romfs if included --- src/platform/3ds/CMakeLists.txt | 2 +- src/platform/3ds/main.c | 63 +++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/platform/3ds/CMakeLists.txt b/src/platform/3ds/CMakeLists.txt index 7fd3e270f..893af0317 100644 --- a/src/platform/3ds/CMakeLists.txt +++ b/src/platform/3ds/CMakeLists.txt @@ -1,4 +1,4 @@ -set(USE_VFS_3DS ON CACHE BOOL "Use 3DS-specific file support") +set(USE_VFS_3DS OFF CACHE BOOL "Use 3DS-specific file support") mark_as_advanced(USE_VFS_3DS) find_program(3DSLINK 3dslink) diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 71fcc1aa2..fad2fd96b 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -817,7 +817,43 @@ THREAD_ENTRY _core2Test(void* context) { UNUSED(context); } -int main() { +bool setupRomfs(char* initialPath, size_t outLength, struct mGUIRunner* runner) { + int fd = open("romfs:/filename", O_RDONLY); + strcpy(initialPath, "romfs:/"); + if (fd < 0) { + return false; + } + size_t len = strlen(initialPath); + ssize_t size = read(fd, initialPath + len, outLength - len); + if (size > 0 && initialPath[len + size - 1] == '\n') { + initialPath[len + size - 1] = '\0'; + } + close(fd); + if (size <= 0) { + return false; + } + char basedir[64]; + mCoreConfigDirectory(basedir, sizeof(basedir)); + strlcat(basedir, "/forwarders", sizeof(basedir)); + FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, basedir), 0); + + mCoreConfigSetValue(&runner->config, "savegamePath", basedir); + mCoreConfigSetValue(&runner->config, "savestatePath", basedir); + mCoreConfigSetValue(&runner->config, "screenshotPath", basedir); + mCoreConfigSetValue(&runner->config, "cheatsPath", basedir); + return true; +} + +int main(int argc, char* argv[]) { + char initialPath[PATH_MAX] = { 0 }; + if (argc > 1) { + strncpy(initialPath, argv[1], sizeof(PATH_MAX)); + } else { + u8 hmac[0x20]; + memset(hmac, 0, sizeof(hmac)); + APT_ReceiveDeliverArg(initialPath, sizeof(initialPath), hmac, NULL, NULL); + } + rotation.d.sample = _sampleRotation; rotation.d.readTiltX = _readTiltX; rotation.d.readTiltY = _readTiltY; @@ -1046,9 +1082,32 @@ int main() { _map3DSKey(&runner.params.keyMap, KEY_CSTICK_UP, mGUI_INPUT_INCREASE_BRIGHTNESS); _map3DSKey(&runner.params.keyMap, KEY_CSTICK_DOWN, mGUI_INPUT_DECREASE_BRIGHTNESS); - mGUIRunloop(&runner); + Result res = romfsInit(); + bool useRomfs = false; + if (R_SUCCEEDED(res)) { + useRomfs = setupRomfs(initialPath, sizeof(initialPath), &runner); + if (!useRomfs) { + romfsExit(); + _cleanup(); + return 1; + } + } + + if (initialPath[0] == '/' || useRomfs) { + size_t i; + for (i = 0; runner.keySources[i].id; ++i) { + mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); + } + mGUIRun(&runner, initialPath); + } else { + mGUIRunloop(&runner); + } + mGUIDeinit(&runner); + if (useRomfs) { + romfsExit(); + } _cleanup(); return 0; }