mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Core: Pass Netplay SRAM through boot process.
This removes the Netplay classes touching emulated hardware structures before emulation even starts.
This commit is contained in:
parent
9963637463
commit
0a517ebdbd
@ -93,10 +93,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
|
||||
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(*netplay_settings));
|
||||
StartUp.bCopyWiiSaveNetplay = netplay_settings->copy_wii_save;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_SRAM_netplay_initialized = false;
|
||||
}
|
||||
|
||||
// Override out-of-region languages/countries to prevent games from crashing or behaving oddly
|
||||
if (!Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS))
|
||||
|
@ -511,7 +511,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
||||
AudioCommon::InitSoundStream();
|
||||
Common::ScopeGuard audio_guard{&AudioCommon::ShutdownSoundStream};
|
||||
|
||||
HW::Init();
|
||||
HW::Init(NetPlay::IsNetPlayRunning() ? &(boot_session_data.GetNetplaySettings()->sram) : nullptr);
|
||||
|
||||
Common::ScopeGuard hw_guard{[] {
|
||||
// We must set up this flag before executing HW::Shutdown()
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/IOFile.h"
|
||||
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
@ -24,7 +25,7 @@
|
||||
#include "DiscIO/Enums.h"
|
||||
|
||||
Sram g_SRAM;
|
||||
bool g_SRAM_netplay_initialized = false;
|
||||
bool s_using_overridden_sram = false;
|
||||
|
||||
namespace ExpansionInterface
|
||||
{
|
||||
@ -102,11 +103,17 @@ u8 SlotToEXIDevice(Slot slot)
|
||||
}
|
||||
}
|
||||
|
||||
void Init()
|
||||
void Init(const Sram* override_sram)
|
||||
{
|
||||
if (!g_SRAM_netplay_initialized)
|
||||
if (override_sram)
|
||||
{
|
||||
g_SRAM = *override_sram;
|
||||
s_using_overridden_sram = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM);
|
||||
s_using_overridden_sram = false;
|
||||
}
|
||||
|
||||
CEXIMemoryCard::Init();
|
||||
@ -151,6 +158,12 @@ void Shutdown()
|
||||
channel.reset();
|
||||
|
||||
CEXIMemoryCard::Shutdown();
|
||||
|
||||
if (!s_using_overridden_sram)
|
||||
{
|
||||
File::IOFile file(SConfig::GetInstance().m_strSRAM, "wb");
|
||||
file.WriteArray(&g_SRAM, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DoState(PointerWrap& p)
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Core/CoreTiming.h"
|
||||
|
||||
class PointerWrap;
|
||||
struct Sram;
|
||||
|
||||
namespace CoreTiming
|
||||
{
|
||||
@ -51,7 +52,7 @@ constexpr bool IsMemcardSlot(Slot slot)
|
||||
u8 SlotToEXIChannel(Slot slot);
|
||||
u8 SlotToEXIDevice(Slot slot);
|
||||
|
||||
void Init();
|
||||
void Init(const Sram* override_sram);
|
||||
void Shutdown();
|
||||
void DoState(PointerWrap& p);
|
||||
void PauseAndLock(bool doLock, bool unpauseOnUnlock);
|
||||
|
@ -139,15 +139,8 @@ CEXIIPL::CEXIIPL()
|
||||
FixSRAMChecksums(&g_SRAM);
|
||||
}
|
||||
|
||||
CEXIIPL::~CEXIIPL()
|
||||
{
|
||||
// SRAM
|
||||
if (!g_SRAM_netplay_initialized)
|
||||
{
|
||||
File::IOFile file(SConfig::GetInstance().m_strSRAM, "wb");
|
||||
file.WriteArray(&g_SRAM, 1);
|
||||
}
|
||||
}
|
||||
CEXIIPL::~CEXIIPL() = default;
|
||||
|
||||
void CEXIIPL::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(g_SRAM);
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace HW
|
||||
{
|
||||
void Init()
|
||||
void Init(const Sram* override_sram)
|
||||
{
|
||||
CoreTiming::Init();
|
||||
SystemTimers::PreInit();
|
||||
@ -41,7 +41,7 @@ void Init()
|
||||
VideoInterface::Init();
|
||||
SerialInterface::Init();
|
||||
ProcessorInterface::Init();
|
||||
ExpansionInterface::Init(); // Needs to be initialized before Memory
|
||||
ExpansionInterface::Init(override_sram); // Needs to be initialized before Memory
|
||||
HSP::Init();
|
||||
Memory::Init(); // Needs to be initialized before AddressSpace
|
||||
AddressSpace::Init();
|
||||
|
@ -4,10 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
class PointerWrap;
|
||||
struct Sram;
|
||||
|
||||
namespace HW
|
||||
{
|
||||
void Init();
|
||||
void Init(const Sram* override_sram);
|
||||
void Shutdown();
|
||||
void DoState(PointerWrap& p);
|
||||
} // namespace HW
|
||||
|
@ -139,4 +139,3 @@ void SetCardFlashID(Sram* sram, const u8* buffer, ExpansionInterface::Slot card_
|
||||
void FixSRAMChecksums(Sram* sram);
|
||||
|
||||
extern Sram g_SRAM;
|
||||
extern bool g_SRAM_netplay_initialized;
|
||||
|
@ -432,10 +432,6 @@ void NetPlayClient::OnData(sf::Packet& packet)
|
||||
OnDesyncDetected(packet);
|
||||
break;
|
||||
|
||||
case MessageID::SyncGCSRAM:
|
||||
OnSyncGCSRAM(packet);
|
||||
break;
|
||||
|
||||
case MessageID::SyncSaveData:
|
||||
OnSyncSaveData(packet);
|
||||
break;
|
||||
@ -893,6 +889,9 @@ void NetPlayClient::OnStartGame(sf::Packet& packet)
|
||||
packet >> m_net_settings.use_fma;
|
||||
packet >> m_net_settings.hide_remote_gbas;
|
||||
|
||||
for (size_t i = 0; i < sizeof(m_net_settings.sram); ++i)
|
||||
packet >> m_net_settings.sram[i];
|
||||
|
||||
m_net_settings.is_hosting = m_local_player->IsHost();
|
||||
}
|
||||
|
||||
@ -960,20 +959,6 @@ void NetPlayClient::OnDesyncDetected(sf::Packet& packet)
|
||||
m_dialog->OnDesync(frame, player);
|
||||
}
|
||||
|
||||
void NetPlayClient::OnSyncGCSRAM(sf::Packet& packet)
|
||||
{
|
||||
const size_t sram_settings_len = sizeof(g_SRAM) - offsetof(Sram, settings);
|
||||
u8 sram[sram_settings_len];
|
||||
for (u8& cell : sram)
|
||||
packet >> cell;
|
||||
|
||||
{
|
||||
std::lock_guard lkg(m_crit.game);
|
||||
memcpy(&g_SRAM.settings, sram, sram_settings_len);
|
||||
g_SRAM_netplay_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
|
||||
{
|
||||
SyncSaveDataID sub_id;
|
||||
|
@ -281,7 +281,6 @@ private:
|
||||
void OnPing(sf::Packet& packet);
|
||||
void OnPlayerPingData(sf::Packet& packet);
|
||||
void OnDesyncDetected(sf::Packet& packet);
|
||||
void OnSyncGCSRAM(sf::Packet& packet);
|
||||
void OnSyncSaveData(sf::Packet& packet);
|
||||
void OnSyncSaveDataNotify(sf::Packet& packet);
|
||||
void OnSyncSaveDataRaw(sf::Packet& packet);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Core/Config/SYSCONFSettings.h"
|
||||
#include "Core/HW/EXI/EXI.h"
|
||||
#include "Core/HW/EXI/EXI_Device.h"
|
||||
#include "Core/HW/Sram.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
@ -105,6 +106,8 @@ struct NetSettings
|
||||
bool use_fma = false;
|
||||
bool hide_remote_gbas = false;
|
||||
|
||||
Sram sram;
|
||||
|
||||
// These aren't sent over the network directly
|
||||
bool is_hosting = false;
|
||||
std::array<std::string, 4> gba_rom_paths{};
|
||||
@ -180,7 +183,6 @@ enum class MessageID : u8
|
||||
Pong = 0xE1,
|
||||
PlayerPingData = 0xE2,
|
||||
|
||||
SyncGCSRAM = 0xF0,
|
||||
SyncSaveData = 0xF1,
|
||||
SyncCodes = 0xF2,
|
||||
};
|
||||
|
@ -1436,20 +1436,9 @@ bool NetPlayServer::StartGame()
|
||||
const std::string region = Config::GetDirectoryForRegion(
|
||||
Config::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game_identifier)->GetRegion()));
|
||||
|
||||
// sync GC SRAM with clients
|
||||
if (!g_SRAM_netplay_initialized)
|
||||
{
|
||||
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
|
||||
InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM);
|
||||
g_SRAM_netplay_initialized = true;
|
||||
}
|
||||
sf::Packet srampac;
|
||||
srampac << MessageID::SyncGCSRAM;
|
||||
for (size_t i = 0; i < sizeof(g_SRAM) - offsetof(Sram, settings); ++i)
|
||||
{
|
||||
srampac << g_SRAM[offsetof(Sram, settings) + i];
|
||||
}
|
||||
SendAsyncToClients(std::move(srampac), 1);
|
||||
// load host's GC SRAM
|
||||
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
|
||||
InitSRAM(&m_settings.sram, SConfig::GetInstance().m_strSRAM);
|
||||
|
||||
// tell clients to start game
|
||||
sf::Packet spac;
|
||||
@ -1544,6 +1533,9 @@ bool NetPlayServer::StartGame()
|
||||
spac << m_settings.use_fma;
|
||||
spac << m_settings.hide_remote_gbas;
|
||||
|
||||
for (size_t i = 0; i < sizeof(m_settings.sram); ++i)
|
||||
spac << m_settings.sram[i];
|
||||
|
||||
SendAsyncToClients(std::move(spac));
|
||||
|
||||
m_start_pending = false;
|
||||
|
Loading…
Reference in New Issue
Block a user