mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 06:15:38 +00:00
Pad: Load memory card from state when the data matches
A warning will be displayed when the card content does not match.
This commit is contained in:
parent
f26e75fa37
commit
3b68c4028d
|
@ -18,6 +18,8 @@ public:
|
|||
static std::unique_ptr<MemoryCard> Create();
|
||||
static std::unique_ptr<MemoryCard> Open(std::string_view filename);
|
||||
|
||||
const MemoryCardImage::DataArray& GetData() const { return m_data; }
|
||||
|
||||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
||||
|
|
|
@ -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<MemoryCard> card_from_state = std::make_unique<MemoryCard>();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue