diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index a339ee80dd..617d51c24d 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -433,11 +433,23 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) if (StartUp.bWii && DiscIO::IsNTSC(StartUp.m_region) && Config::Get(Config::SYSCONF_PAL60)) Config::SetCurrent(Config::SYSCONF_PAL60, false); - // Ensure any new settings are written to the SYSCONF if (StartUp.bWii) { - Core::BackupWiiSettings(); - ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta); + const bool want_determinism = Movie::IsMovieActive() || NetPlay::IsNetPlayRunning(); + Core::InitializeWiiRoot(want_determinism); + + // Ensure any new settings are written to the SYSCONF + if (!want_determinism) + { + Core::BackupWiiSettings(); + ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta); + } + else + { + ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta, [](const Config::Location& location) { + return Config::GetActiveLayerForConfig(location) >= Config::LayerType::Movie; + }); + } } const bool load_ipl = !StartUp.bWii && !StartUp.bHLE_BS2 && @@ -486,8 +498,14 @@ static void RestoreSYSCONF() void RestoreConfig() { - Core::RestoreWiiSettings(Core::RestoreReason::EmulationEnd); - RestoreSYSCONF(); + Core::ShutdownWiiRoot(); + + if (!Core::WiiRootIsTemporary()) + { + Core::RestoreWiiSettings(Core::RestoreReason::EmulationEnd); + RestoreSYSCONF(); + } + Config::ClearCurrentRunLayer(); Config::RemoveLayer(Config::LayerType::Movie); Config::RemoveLayer(Config::LayerType::Netplay); diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp index 65b46ec4bd..d3e340c68d 100644 --- a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ namespace ConfigLoaders { -void SaveToSYSCONF(Config::LayerType layer) +void SaveToSYSCONF(Config::LayerType layer, std::function predicate) { if (Core::IsRunning()) return; @@ -40,7 +41,10 @@ void SaveToSYSCONF(Config::LayerType layer) for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS) { std::visit( - [layer, &setting, &sysconf](auto* info) { + [&](auto* info) { + if (predicate && !predicate(info->GetLocation())) + return; + const std::string key = info->GetLocation().section + "." + info->GetLocation().key; if (setting.type == SysConf::Entry::Type::Long) diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h index 2082e405b3..1fc28674f5 100644 --- a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h @@ -4,16 +4,19 @@ #pragma once +#include #include namespace Config { class ConfigLayerLoader; enum class LayerType; +struct Location; } // namespace Config namespace ConfigLoaders { -void SaveToSYSCONF(Config::LayerType layer); +void SaveToSYSCONF(Config::LayerType layer, + std::function predicate = {}); std::unique_ptr GenerateBaseConfigLoader(); } // namespace ConfigLoaders diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 99e7624b55..2fe18a7e67 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -590,7 +590,7 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi return; // Initialise Wii filesystem contents. - // This is done here after Boot and not in HW to ensure that we operate + // This is done here after Boot and not in BootManager to ensure that we operate // with the correct title context since save copying requires title directories to exist. Common::ScopeGuard wiifs_guard{&Core::CleanUpWiiFileSystemContents}; if (SConfig::GetInstance().bWii) diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index 654164d960..6e2cf7d17b 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -25,7 +25,6 @@ #include "Core/HW/WII_IPC.h" #include "Core/IOS/IOS.h" #include "Core/State.h" -#include "Core/WiiRoot.h" namespace HW { @@ -52,8 +51,6 @@ void Init() if (SConfig::GetInstance().bWii) { - // The NAND should only be initialised once per emulation session. - Core::InitializeWiiRoot(Core::WantsDeterminism()); IOS::Init(); IOS::HLE::Init(); // Depends on Memory } @@ -64,7 +61,6 @@ void Shutdown() // IOS should always be shut down regardless of bWii because it can be running in GC mode (MIOS). IOS::HLE::Shutdown(); // Depends on Memory IOS::Shutdown(); - Core::ShutdownWiiRoot(); SystemTimers::Shutdown(); CPU::Shutdown(); diff --git a/Source/Core/Core/WiiRoot.cpp b/Source/Core/Core/WiiRoot.cpp index b042edc039..9503b70b9e 100644 --- a/Source/Core/Core/WiiRoot.cpp +++ b/Source/Core/Core/WiiRoot.cpp @@ -202,13 +202,18 @@ void InitializeWiiRoot(bool use_temporary) void ShutdownWiiRoot() { - if (!s_temp_wii_root.empty()) + if (WiiRootIsTemporary()) { File::DeleteDirRecursively(s_temp_wii_root); s_temp_wii_root.clear(); } } +bool WiiRootIsTemporary() +{ + return !s_temp_wii_root.empty(); +} + void BackupWiiSettings() { // Back up files which Dolphin can modify at boot, so that we can preserve the original contents. @@ -282,7 +287,7 @@ void InitializeWiiFileSystemContents() if (!CopySysmenuFilesToFS(fs.get(), File::GetSysDirectory() + WII_USER_DIR, "")) WARN_LOG_FMT(CORE, "Failed to copy initial System Menu files to the NAND"); - if (s_temp_wii_root.empty()) + if (!WiiRootIsTemporary()) return; // Generate a SYSCONF with default settings for the temporary Wii NAND. @@ -294,7 +299,7 @@ void InitializeWiiFileSystemContents() void CleanUpWiiFileSystemContents() { - if (s_temp_wii_root.empty() || !SConfig::GetInstance().bEnableMemcardSdWriting || + if (!WiiRootIsTemporary() || !SConfig::GetInstance().bEnableMemcardSdWriting || NetPlay::GetWiiSyncFS()) { return; diff --git a/Source/Core/Core/WiiRoot.h b/Source/Core/Core/WiiRoot.h index 7b069d0c07..ad4ac609b9 100644 --- a/Source/Core/Core/WiiRoot.h +++ b/Source/Core/Core/WiiRoot.h @@ -15,6 +15,8 @@ enum class RestoreReason void InitializeWiiRoot(bool use_temporary); void ShutdownWiiRoot(); +bool WiiRootIsTemporary(); + void BackupWiiSettings(); void RestoreWiiSettings(RestoreReason reason);