Skip to content

Commit

Permalink
Boot: Initialize Wii root before saving SYSCONF file
Browse files Browse the repository at this point in the history
Fixes netplay and movie overrides of SYSCONF settings not applying.
  • Loading branch information
JosJuice committed Mar 7, 2021
1 parent 359ed53 commit 46dbb45
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
28 changes: 23 additions & 5 deletions Source/Core/Core/BootManager.cpp
Expand Up @@ -433,11 +433,23 @@ bool BootCore(std::unique_ptr<BootParameters> 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 &&
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <cstring>
#include <functional>
#include <list>
#include <map>
#include <memory>
Expand All @@ -29,7 +30,7 @@

namespace ConfigLoaders
{
void SaveToSYSCONF(Config::LayerType layer)
void SaveToSYSCONF(Config::LayerType layer, std::function<bool(const Config::Location&)> predicate)
{
if (Core::IsRunning())
return;
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/Core/ConfigLoaders/BaseConfigLoader.h
Expand Up @@ -4,16 +4,19 @@

#pragma once

#include <functional>
#include <memory>

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<bool(const Config::Location&)> predicate = {});
std::unique_ptr<Config::ConfigLayerLoader> GenerateBaseConfigLoader();
} // namespace ConfigLoaders
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.cpp
Expand Up @@ -590,7 +590,7 @@ static void EmuThread(std::unique_ptr<BootParameters> 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)
Expand Down
4 changes: 0 additions & 4 deletions Source/Core/Core/HW/HW.cpp
Expand Up @@ -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
{
Expand All @@ -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
}
Expand All @@ -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();
Expand Down
11 changes: 8 additions & 3 deletions Source/Core/Core/WiiRoot.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/WiiRoot.h
Expand Up @@ -15,6 +15,8 @@ enum class RestoreReason
void InitializeWiiRoot(bool use_temporary);
void ShutdownWiiRoot();

bool WiiRootIsTemporary();

void BackupWiiSettings();
void RestoreWiiSettings(RestoreReason reason);

Expand Down

0 comments on commit 46dbb45

Please sign in to comment.