From 45b07cbdcd97f2015dca5873c7949e9991ce23d4 Mon Sep 17 00:00:00 2001 From: comex Date: Mon, 20 Apr 2015 22:24:21 -0400 Subject: [PATCH] Fix determinism issues with Wiimote netplay. - Change the Wiimote emulation SYSCONF R/W to use the temporary NAND if in use. - Fix up SysConf API so this actually works. Kind of a hack. Like I said, this can be cleaned up when configuration is synced... --- Source/Core/Common/SysConf.cpp | 12 ++++++++---- .../Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/SysConf.cpp b/Source/Core/Common/SysConf.cpp index a0d3aa1f04..047114774a 100644 --- a/Source/Core/Common/SysConf.cpp +++ b/Source/Core/Common/SysConf.cpp @@ -38,6 +38,10 @@ void SysConf::Clear() bool SysConf::LoadFromFile(const std::string& filename) { + if (m_IsValid) + Clear(); + m_IsValid = false; + // Basic check if (!File::Exists(filename)) { @@ -67,6 +71,7 @@ bool SysConf::LoadFromFile(const std::string& filename) if (LoadFromFileInternal(f.ReleaseHandle())) { m_Filename = filename; + m_IsValid = true; return true; } } @@ -107,6 +112,7 @@ bool SysConf::LoadFromFileInternal(FILE *fh) f.ReadArray(curEntry.name, curEntry.nameLength); curEntry.name[curEntry.nameLength] = '\0'; // Get length of data + curEntry.data = nullptr; curEntry.dataLength = 0; switch (curEntry.type) { @@ -362,6 +368,7 @@ void SysConf::GenerateSysConf() g.WriteBytes("SCed", 4); m_Filename = m_FilenameDefault; + m_IsValid = true; } bool SysConf::SaveToFile(const std::string& filename) @@ -418,11 +425,8 @@ void SysConf::UpdateLocation() bool SysConf::Reload() { - if (m_IsValid) - Clear(); - std::string& filename = m_Filename.empty() ? m_FilenameDefault : m_Filename; - m_IsValid = LoadFromFile(filename); + LoadFromFile(filename); return m_IsValid; } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 243b121c9f..bfd90e4652 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/CommonPaths.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" @@ -35,11 +36,25 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De , m_ACLEndpoint(0) , m_last_ticks(0) { + SysConf* sysconf; + std::unique_ptr owned_sysconf; + if (Core::g_want_determinism) + { + // See SysConf::UpdateLocation for comment about the Future. + owned_sysconf.reset(new SysConf()); + sysconf = owned_sysconf.get(); + sysconf->LoadFromFile(File::GetUserPath(D_SESSION_WIIROOT_IDX) + DIR_SEP WII_SYSCONF_DIR DIR_SEP WII_SYSCONF); + } + else + { + sysconf = SConfig::GetInstance().m_SYSCONF; + } + // Activate only first Wiimote by default _conf_pads BT_DINF; SetUsbPointer(this); - if (!SConfig::GetInstance().m_SYSCONF->GetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads))) + if (!sysconf->GetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads))) { PanicAlertT("Trying to read from invalid SYSCONF\nWiimote bt ids are not available"); } @@ -83,7 +98,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De // save now so that when games load sysconf file it includes the new Wiimotes // and the correct order for connected Wiimotes - if (!SConfig::GetInstance().m_SYSCONF->SetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads)) || !SConfig::GetInstance().m_SYSCONF->Save()) + if (!sysconf->SetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads)) || !sysconf->Save()) PanicAlertT("Failed to write BT.DINF to SYSCONF"); }