From c883e9d792937994962d5e505fdf5e2c14e64e7a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 19 Nov 2022 14:58:25 +1000 Subject: [PATCH] Sio: Only eject memory cards when loading state if changed [SAVEVERSION+] Regression from #6741. --- pcsx2/SaveState.h | 2 +- pcsx2/Sio.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pcsx2/SaveState.h b/pcsx2/SaveState.h index beadcf3efe..f250ccf19e 100644 --- a/pcsx2/SaveState.h +++ b/pcsx2/SaveState.h @@ -33,7 +33,7 @@ enum class FreezeAction // [SAVEVERSION+] // This informs the auto updater that the users savestates will be invalidated. -static const u32 g_SaveVersion = (0x9A31 << 16) | 0x0000; +static const u32 g_SaveVersion = (0x9A32 << 16) | 0x0000; // the freezing data between submodules and core diff --git a/pcsx2/Sio.cpp b/pcsx2/Sio.cpp index f0ee1ab3dd..22e928e81b 100644 --- a/pcsx2/Sio.cpp +++ b/pcsx2/Sio.cpp @@ -917,9 +917,34 @@ void SaveStateBase::sio2Freeze() Freeze(sio2); + // CRCs for memory cards. + // If the memory card hasn't changed when loading state, we can safely skip ejecting it. + u64 mcdCrcs[SIO::PORTS][SIO::SLOTS]; + if (IsSaving()) + { + for (u32 port = 0; port < SIO::PORTS; port++) + { + for (u32 slot = 0; slot < SIO::SLOTS; slot++) + mcdCrcs[port][slot] = mcds[port][slot].GetChecksum(); + } + } + Freeze(mcdCrcs); + if (IsLoading()) { - AutoEject::SetAll(); + bool ejected = false; + for (u32 port = 0; port < SIO::PORTS && !ejected; port++) + { + for (u32 slot = 0; slot < SIO::SLOTS; slot++) + { + if (mcdCrcs[port][slot] != mcds[port][slot].GetChecksum()) + { + AutoEject::SetAll(); + ejected = true; + break; + } + } + } // Restore fifoIn fifoIn.clear();