Improve behavior of savestates made while game is assuming the state of the inserted memory card.
Fixes https://bugs.dolphin-emu.org/issues/12220
This looks pretty convoluted but I hope the comments make it clear what's happening and why.
Considering this prevents save corruption, we should merge this once it is reviewed and good to go.
Is this still planning to be merged?
Considering I've yet to see anyone yell about corrupted savedata in the many years this issue has potentially existed, it's probably not particularly critical. If you want to merge it sure, if not eh, that's probably okay. I'll rebase it tomorrow just in case.
pOkE
There was a request for me to rebase this on Discord, so I did.
I will note, however, that looking back on this I'm not 100% sure this whole DisableWrites() -> wait for a few frames approach is even necessary at all. It's probably okay but it would probably also work just fine if we, immediately after loading the state is done but before handing back to the actual emulation logic, just run the
m_status.EXTINT = 1;
m_system.GetExpansionInterface().UpdateInterrupts();
code in the relevant CEXIChannel so that the game is notified of the 'unplugged' memory card before it has the chance to run any writes.
I will also note that we should probably fix folder memory cards not storing their card ID / header before considering merging this, as this will make the situtation where you suddenly have a 'different' memory card after loading a savestate much more likely. e: https://github.com/dolphin-emu/dolphin/pull/13231