diff --git a/src/Cafe/CafeSystem.cpp b/src/Cafe/CafeSystem.cpp index 79184393..20a76812 100644 --- a/src/Cafe/CafeSystem.cpp +++ b/src/Cafe/CafeSystem.cpp @@ -685,6 +685,22 @@ namespace CafeSystem fsc_unmount("/cemuBossStorage/", FSC_PRIORITY_BASE); } + void MountExtras() + { + for (const auto& [host_path, emulatedPath] : LaunchSettings::CosMounts()) + { + FSCDeviceHostFS_Mount(boost::nowide::narrow(emulatedPath), _pathToUtf8(host_path), FSC_PRIORITY_BASE); + } + } + + void UnmountExtras() + { + for (const auto& [_, emulatedPath] : LaunchSettings::CosMounts()) + { + fsc_unmount(boost::nowide::narrow(emulatedPath), FSC_PRIORITY_BASE); + } + } + PREPARE_STATUS_CODE LoadAndMountForegroundTitle(TitleId titleId) { cemuLog_log(LogType::Force, "Mounting title {:016x}", (uint64)titleId); @@ -838,6 +854,7 @@ namespace CafeSystem if (r != PREPARE_STATUS_CODE::SUCCESS) return r; InitVirtualMlcStorage(); + MountExtras(); return PREPARE_STATUS_CODE::SUCCESS; } @@ -881,6 +898,7 @@ namespace CafeSystem // load executable PrepareExecutable(); InitVirtualMlcStorage(); + MountExtras(); return PREPARE_STATUS_CODE::SUCCESS; } @@ -960,6 +978,9 @@ namespace CafeSystem std::string GetForegroundTitleArgStr() { + auto optional_arguments = LaunchSettings::CosArgstr(); + if (optional_arguments.has_value()) + return *optional_arguments; if (sLaunchModeIsStandalone) return ""; auto& update = sGameInfo_ForegroundTitle.GetUpdate(); @@ -1044,24 +1065,26 @@ namespace CafeSystem { if(!sSystemRunning) return; - coreinit::OSSchedulerEnd(); - Latte_Stop(); - // reset Cafe OS userspace modules - snd_core::reset(); - coreinit::OSAlarm_Shutdown(); - GX2::_GX2DriverReset(); - nn::save::ResetToDefaultState(); - coreinit::__OSDeleteAllActivePPCThreads(); - RPLLoader_UnloadAll(); + coreinit::OSSchedulerEnd(); + Latte_Stop(); + // reset Cafe OS userspace modules + snd_core::reset(); + coreinit::OSAlarm_Shutdown(); + GX2::_GX2DriverReset(); + nn::save::ResetToDefaultState(); + coreinit::__OSDeleteAllActivePPCThreads(); + RPLLoader_UnloadAll(); for(auto it = s_iosuModules.rbegin(); it != s_iosuModules.rend(); ++it) (*it)->TitleStop(); - // reset Cemu subsystems - PPCRecompiler_Shutdown(); - GraphicPack2::Reset(); - UnmountCurrentTitle(); - MlcStorageUnmountAllTitles(); - UnmountBaseDirectories(); - DestroyMemorySpace(); + // reset Cemu subsystems + PPCRecompiler_Shutdown(); + GraphicPack2::Reset(); + UnmountCurrentTitle(); + UnmountExtras(); + MlcStorageUnmountAllTitles(); + UnmountBaseDirectories(); + DestroyMemorySpace(); + LaunchSettings::ClearCosArgstr(); sSystemRunning = false; } diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp index 13ef6613..820f336c 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp @@ -4,6 +4,7 @@ #include "Cafe/OS/libs/coreinit/coreinit_OSScreen.h" #include "Cafe/CafeSystem.h" #include "Cafe/Filesystem/fsc.h" +#include "config/LaunchSettings.h" #include namespace coreinit @@ -544,6 +545,7 @@ namespace coreinit } std::mutex sCafeConsoleMutex; + bool s_forwardConsoleLogs; void WriteCafeConsole(CafeLogType cafeLogType, const char* msg, sint32 len) { @@ -556,6 +558,13 @@ namespace coreinit cafeLogBuffer.lineLength = 0; }; + if (s_forwardConsoleLogs) { + if (cafeLogType == CafeLogType::OSCONSOLE) { + fwrite(msg, 1, len, stdout); + } else { + fwrite(msg, 1, len, stderr); + } + } while (len) { char c = *msg; @@ -846,6 +855,7 @@ namespace coreinit { s_currentTitleId = CafeSystem::GetForegroundTitleId(); s_sdkVersion = CafeSystem::GetForegroundTitleSDKVersion(); + s_forwardConsoleLogs = LaunchSettings::ForwardConsoleLogging(); s_transitionToBackground = false; s_transitionToForeground = false; diff --git a/src/config/LaunchSettings.cpp b/src/config/LaunchSettings.cpp index 4ac12c53..2d4a5316 100644 --- a/src/config/LaunchSettings.cpp +++ b/src/config/LaunchSettings.cpp @@ -63,7 +63,7 @@ bool LaunchSettings::HandleCommandline(const std::vector& args) #endif ("game,g", po::wvalue(), "Path of game to launch") - ("title-id,t", po::value(), "Title ID of the title to be launched (overridden by --game)") + ("title-id,t", po::value(), "Title ID of the title to be launched (overridden by --game)") ("mlc,m", po::wvalue(), "Custom mlc folder location") ("fullscreen,f", po::value()->implicit_value(true), "Launch games in fullscreen mode") @@ -71,6 +71,10 @@ bool LaunchSettings::HandleCommandline(const std::vector& args) ("account,a", po::value(), "Persistent id of account") + ("cos-mounts", po::wvalue>()->composing(), "A series of mounts in the form of: (path on host:path within emulated system, e.g. `/tmp:/vol/temporary/`)") + ("forward-console-logging", "Forward OSReport, OSConsoleWrite, etc. to stdout/stderr.") + ("cos-argstr", po::value(), "A custom argstr used to override to the arguments to the first RPX that is launched, will be unset after the first launch.") + ("force-interpreter", po::value()->implicit_value(true), "Force interpreter CPU emulation, disables recompiler. Useful for debugging purposes where you want to get accurate memory accesses and stack traces.") ("force-multicore-interpreter", po::value()->implicit_value(true), "Force multi-core interpreter CPU emulation, disables recompiler. Only useful for getting stack traces, but slightly faster than the single-core interpreter mode.") ("enable-gdbstub", po::value()->implicit_value(true), "Enable GDB stub to debug executables inside Cemu using an external debugger"); @@ -189,6 +193,30 @@ bool LaunchSettings::HandleCommandline(const std::vector& args) if (vm.count("enable-gdbstub")) s_enable_gdbstub = vm["enable-gdbstub"].as(); + if (vm.count("forward-console-logging")) + { + requireConsole(); + s_forward_console_logging = true; + } + + if (vm.count("cos-argstr")) + s_cos_argstr = vm["cos-argstr"].as(); + + if (vm.count("cos-mounts")) + { + for (const auto& argument : vm["cos-mounts"].as>()) + { + size_t colon_location = argument.find(L':'); + if (colon_location == std::wstring::npos) + { + std::cerr << "Argument for a mount expects to be in the format: `path on host:path in emulated system`, was not: `" << boost::nowide::narrow(argument) << "`\n"; + continue; + } + + s_cos_mounts[argument.substr(0, colon_location)] = argument.substr(colon_location + 1); + } + } + std::wstring extract_path, log_path; std::string output_path; if (vm.count("extract")) diff --git a/src/config/LaunchSettings.h b/src/config/LaunchSettings.h index 13665cb7..df52a84b 100644 --- a/src/config/LaunchSettings.h +++ b/src/config/LaunchSettings.h @@ -2,6 +2,7 @@ #include #include +#include class LaunchSettings { @@ -16,7 +17,7 @@ public: static bool HandleCommandline(const std::vector& args); static std::optional GetLoadFile() { return s_load_game_file; } - static std::optional GetLoadTitleID() {return s_load_title_id;} + static std::optional GetLoadTitleID() {return s_load_title_id;} static std::optional GetMLCPath() { return s_mlc_path; } static std::optional RenderUpsideDownEnabled() { return s_render_upside_down; } @@ -24,6 +25,11 @@ public: static bool Verbose() { return s_verbose; } + static bool ForwardConsoleLogging() { return s_forward_console_logging; } + static std::optional CosArgstr() { return s_cos_argstr; } + static void ClearCosArgstr() { s_cos_argstr.reset(); } + static std::unordered_map& CosMounts() { return s_cos_mounts; } + static bool GDBStubEnabled() { return s_enable_gdbstub; } static bool NSightModeEnabled() { return s_nsight_mode; } @@ -37,14 +43,18 @@ public: private: inline static std::optional s_load_game_file{}; - inline static std::optional s_load_title_id{}; + inline static std::optional s_load_title_id{}; inline static std::optional s_mlc_path{}; inline static std::optional s_render_upside_down{}; inline static std::optional s_fullscreen{}; inline static bool s_verbose = false; - + + inline static bool s_forward_console_logging = false; + inline static std::optional s_cos_argstr{}; + inline static std::unordered_map s_cos_mounts{}; + inline static bool s_enable_gdbstub = false; inline static bool s_nsight_mode = false; @@ -59,5 +69,3 @@ private: static bool ExtractorTool(std::wstring_view wud_path, std::string_view output_path, std::wstring_view log_path); }; - -