From 99fbe4e9ffd89624dc05f6862c3ad076ecf45d17 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 18 Sep 2022 14:46:16 +1000 Subject: [PATCH] VMManager: Reload save state ELF in internals We should serialize this in the state at some point. --- pcsx2/SaveState.cpp | 20 ++++++++++++++++++++ pcsx2/VMManager.cpp | 7 ------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index 1e220671af..a2d8f93e15 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -215,6 +215,10 @@ SaveStateBase& SaveStateBase::FreezeBios() SaveStateBase& SaveStateBase::FreezeInternals() { +#ifdef PCSX2_CORE + const u32 previousCRC = ElfCRC; +#endif + // Print this until the MTVU problem in gifPathFreeze is taken care of (rama) if (THREAD_VU1) Console.Warning("MTVU speedhack is enabled, saved states may not be stable"); @@ -235,8 +239,24 @@ SaveStateBase& SaveStateBase::FreezeInternals() StringUtil::Strlcpy(localDiscSerial, DiscSerial.c_str(), sizeof(localDiscSerial)); Freeze(localDiscSerial); if (IsLoading()) + { DiscSerial = localDiscSerial; +#ifdef PCSX2_CORE + if (ElfCRC != previousCRC) + { + // HACK: LastELF isn't in the save state... Load it before we go too far into restoring state. + // When we next bump save states, we should include it. We need this for achievements, because + // we want to load and activate achievements before restoring any of their tracked state. + if (const std::string& elf_override = VMManager::Internal::GetElfOverride(); !elf_override.empty()) + cdvdReloadElfInfo(fmt::format("host:{}", elf_override)); + else + cdvdReloadElfInfo(); + } +#endif + } + + // Third Block - Cycle Timers and Events // ------------------------------------- FreezeTag( "Cycles" ); diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index ab815b7bed..dcaa39669c 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -1152,13 +1152,6 @@ bool VMManager::DoLoadState(const char* filename) { Host::OnSaveStateLoading(filename); SaveState_UnzipFromDisk(filename); - - // HACK: LastELF isn't in the save state... - if (!s_elf_override.empty()) - cdvdReloadElfInfo(fmt::format("host:{}", s_elf_override)); - else - cdvdReloadElfInfo(); - UpdateRunningGame(false, false); Host::OnSaveStateLoaded(filename, true); return true;