diff --git a/src/core/memory_card.h b/src/core/memory_card.h index c95131bf0..e29f59feb 100644 --- a/src/core/memory_card.h +++ b/src/core/memory_card.h @@ -18,6 +18,8 @@ public: static std::unique_ptr Create(); static std::unique_ptr Open(std::string_view filename); + const MemoryCardImage::DataArray& GetData() const { return m_data; } + void Reset(); bool DoState(StateWrapper& sw); diff --git a/src/core/pad.cpp b/src/core/pad.cpp index a09aa7d39..e18aa6caa 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -100,13 +100,37 @@ bool Pad::DoState(StateWrapper& sw) { Log_WarningPrintf("Skipping loading memory card %u from save state.", i + 1u); - MemoryCard dummy_card; - if (!sw.DoMarker("MemoryCard") || !dummy_card.DoState(sw)) + std::unique_ptr card_from_state = std::make_unique(); + if (!sw.DoMarker("MemoryCard") || !card_from_state->DoState(sw)) return false; - // we do need to reset the existing card though, in case it was in the middle of a write + // does the content of the memory card match? if (m_memory_cards[i]) - m_memory_cards[i]->Reset(); + { + if (m_memory_cards[i]->GetData() == card_from_state->GetData()) + { + Log_DevPrintf("Using memory card %u state from save state", i); + m_memory_cards[i] = std::move(card_from_state); + } + else + { + g_host_interface->AddFormattedOSDMessage( + 20.0f, + g_host_interface->TranslateString( + "OSDMessage", "Memory card %u from save state does match current card data. Simulating replugging."), + i + 1u); + + m_memory_cards[i]->Reset(); + } + } + else + { + g_host_interface->AddFormattedOSDMessage( + 20.0f, + g_host_interface->TranslateString("OSDMessage", + "Memory card %u present in save state but not in system. Ignoring card."), + i + 1u); + } continue; } @@ -114,13 +138,19 @@ bool Pad::DoState(StateWrapper& sw) if (card_present && !m_memory_cards[i]) { g_host_interface->AddFormattedOSDMessage( - 2.0f, "Memory card %u present in save state but not in system. Creating temporary card.", i + 1u); + 20.0f, + g_host_interface->TranslateString( + "OSDMessage", "Memory card %u present in save state but not in system. Creating temporary card."), + i + 1u); m_memory_cards[i] = MemoryCard::Create(); } else if (!card_present && m_memory_cards[i]) { g_host_interface->AddFormattedOSDMessage( - 2.0f, "Memory card %u present in system but not in save state. Removing card.", i + 1u); + 20.0f, + g_host_interface->TranslateString("OSDMessage", + "Memory card %u present in system but not in save state. Removing card."), + i + 1u); m_memory_cards[i].reset(); }