Skip to content

Commit

Permalink
Savestates: Warn on savestate load and saves without mcd activity
Browse files Browse the repository at this point in the history
[SAVEVERSION+]
F0bes committed Dec 18, 2024
1 parent 72a9f18 commit a2c7542
Showing 6 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions pcsx2/SIO/Sio.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

#include "SIO/SioTypes.h"
#include "SIO/Memcard/MemoryCardProtocol.h"
#include "Counters.h"

#include "Host.h"
#include "IconsPromptFont.h"
@@ -128,6 +129,8 @@ void AutoEject::ClearAll()
// unsafe to shutdown the VM due to memcard access.
static std::atomic_uint32_t currentBusyTicks = 0;

uint32_t sioLastFrameMcdBusy = 0;

void MemcardBusy::Decrement()
{
if (currentBusyTicks.load(std::memory_order_relaxed) == 0)
@@ -139,6 +142,7 @@ void MemcardBusy::Decrement()
void MemcardBusy::SetBusy()
{
currentBusyTicks.store(300, std::memory_order_release);
sioLastFrameMcdBusy = g_FrameCount;
}

bool MemcardBusy::IsBusy()
@@ -149,4 +153,15 @@ bool MemcardBusy::IsBusy()
void MemcardBusy::ClearBusy()
{
currentBusyTicks.store(0, std::memory_order_release);
sioLastFrameMcdBusy = 0;
}

#include "common/Console.h"
void MemcardBusy::CheckSaveStateDependency()
{
if (g_FrameCount - sioLastFrameMcdBusy > NUM_FRAMES_BEFORE_SAVESTATE_DEPENDENCY_WARNING)
{
Host::AddIconOSDMessage("MemcardBusy", ICON_PF_MEMORY_CARD,
TRANSLATE_SV("MemoryCard", "The virtual console hasn't saved to your memory card for quite some time. Savestates should not be used in place of in-game saves."), Host::OSD_INFO_DURATION);
}
}
9 changes: 9 additions & 0 deletions pcsx2/SIO/Sio.h
Original file line number Diff line number Diff line change
@@ -118,10 +118,19 @@ namespace AutoEject
extern void ClearAll();
} // namespace AutoEject

// ~1 hour of memory card inactivity.
constexpr u32 NUM_FRAMES_BEFORE_SAVESTATE_DEPENDENCY_WARNING = 60 * 60 * 60;

// Set to the current frame count when there is memory card activity.
// Used to detect the last frame when memory card activity was detected,
// and if it exceeds a certain threshold, warns on savestate save/load.
extern uint32_t sioLastFrameMcdBusy;

namespace MemcardBusy
{
extern void Decrement();
extern void SetBusy();
extern bool IsBusy();
extern void ClearBusy();
extern void CheckSaveStateDependency();
}
1 change: 1 addition & 0 deletions pcsx2/SIO/Sio2.cpp
Original file line number Diff line number Diff line change
@@ -541,5 +541,6 @@ bool Sio2::DoState(StateWrapper& sw)
}
}

sw.Do(&sioLastFrameMcdBusy);
return sw.IsGood();
}
5 changes: 3 additions & 2 deletions pcsx2/SaveState.cpp
Original file line number Diff line number Diff line change
@@ -15,12 +15,13 @@
#include "Host.h"
#include "MTGS.h"
#include "MTVU.h"
#include "SIO/Pad/Pad.h"
#include "Patch.h"
#include "R3000A.h"
#include "SIO/Multitap/MultitapProtocol.h"
#include "SIO/Pad/Pad.h"
#include "SIO/Sio.h"
#include "SIO/Sio0.h"
#include "SIO/Sio2.h"
#include "SIO/Multitap/MultitapProtocol.h"
#include "SPU2/spu2.h"
#include "SaveState.h"
#include "StateWrapper.h"
2 changes: 1 addition & 1 deletion pcsx2/SaveState.h
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ enum class FreezeAction
// [SAVEVERSION+]
// This informs the auto updater that the users savestates will be invalidated.

static const u32 g_SaveVersion = (0x9A51 << 16) | 0x0000;
static const u32 g_SaveVersion = (0x9A52 << 16) | 0x0000;


// the freezing data between submodules and core
2 changes: 2 additions & 0 deletions pcsx2/VMManager.cpp
Original file line number Diff line number Diff line change
@@ -1818,6 +1818,7 @@ bool VMManager::DoLoadState(const char* filename)
MTGS::PresentCurrentFrame();
}

MemcardBusy::CheckSaveStateDependency();
return true;
}

@@ -1866,6 +1867,7 @@ bool VMManager::DoSaveState(const char* filename, s32 slot_for_message, bool zip
}

Host::OnSaveStateSaved(filename);
MemcardBusy::CheckSaveStateDependency();
return true;
}

0 comments on commit a2c7542

Please sign in to comment.