Libretro: Include extdata in savestates

This commit is contained in:
Vicki Pfau 2018-09-17 13:05:00 -07:00
parent 91eb813e56
commit 8be2e10c87
1 changed files with 19 additions and 8 deletions

View File

@ -11,6 +11,7 @@
#include <mgba/core/cheats.h> #include <mgba/core/cheats.h>
#include <mgba/core/core.h> #include <mgba/core/core.h>
#include <mgba/core/log.h> #include <mgba/core/log.h>
#include <mgba/core/serialize.h>
#include <mgba/core/version.h> #include <mgba/core/version.h>
#ifdef M_CORE_GB #ifdef M_CORE_GB
#include <mgba/gb/core.h> #include <mgba/gb/core.h>
@ -558,23 +559,33 @@ void retro_unload_game(void) {
} }
size_t retro_serialize_size(void) { size_t retro_serialize_size(void) {
return core->stateSize(core); struct VFile* vfm = VFileMemChunk(NULL, 0);
mCoreSaveStateNamed(core, vfm, SAVESTATE_SAVEDATA | SAVESTATE_RTC);
size_t size = vfm->size(vfm);
vfm->close(vfm);
return size;
} }
bool retro_serialize(void* data, size_t size) { bool retro_serialize(void* data, size_t size) {
if (size != retro_serialize_size()) { struct VFile* vfm = VFileMemChunk(NULL, 0);
mCoreSaveStateNamed(core, vfm, SAVESTATE_SAVEDATA | SAVESTATE_RTC);
if ((ssize_t) size > vfm->size(vfm)) {
size = vfm->size(vfm);
} else if ((ssize_t) size < vfm->size(vfm)) {
vfm->close(vfm);
return false; return false;
} }
core->saveState(core, data); vfm->seek(vfm, 0, SEEK_SET);
vfm->read(vfm, data, size);
vfm->close(vfm);
return true; return true;
} }
bool retro_unserialize(const void* data, size_t size) { bool retro_unserialize(const void* data, size_t size) {
if (size != retro_serialize_size()) { struct VFile* vfm = VFileFromConstMemory(data, size);
return false; bool success = mCoreLoadStateNamed(core, vfm, SAVESTATE_RTC);
} vfm->close(vfm);
core->loadState(core, data); return success;
return true;
} }
void retro_cheat_reset(void) { void retro_cheat_reset(void) {