GBA Serialize: Fix loading savegames from savestates
Jeffrey Pfau jeffrey@endrift.com
Fri, 26 Feb 2016 23:47:00 -0800
3 files changed,
22 insertions(+),
10 deletions(-)
M
CHANGES
→
CHANGES
@@ -16,6 +16,7 @@ - Shaders: Fix AGS-001 shader with some bad drivers
- GBA Memory: Fix mirror on non-overdumped Classic NES games - Qt: Initialize m_useBios - GBA Serialize: Fix memory corruption bug in GBAExtdataSerialize + - GBA Serialize: Fix loading savegames from savestates Misc: - GBA: Slightly optimize GBAProcessEvents - Qt: Add preset for DualShock 4
M
src/gba/savedata.c
→
src/gba/savedata.c
@@ -126,7 +126,26 @@ return true;
} bool GBASavedataLoad(struct GBASavedata* savedata, struct VFile* in) { - if (savedata->data) { + if (savedata->vf) { + off_t read = 0; + uint8_t buffer[2048]; + memset(buffer, 0xFF, sizeof(buffer)); + savedata->vf->seek(savedata->vf, 0, SEEK_SET); + while (savedata->vf->seek(savedata->vf, 0, SEEK_CUR) < savedata->vf->size(savedata->vf)) { + savedata->vf->write(savedata->vf, buffer, sizeof(buffer)); + } + savedata->vf->seek(savedata->vf, 0, SEEK_SET); + if (in) { + do { + read = in->read(in, buffer, sizeof(buffer)); + read = savedata->vf->write(savedata->vf, buffer, read); + } while (read == sizeof(buffer)); + } + return read >= 0; + } else if (savedata->data) { + if (!in && savedata->type != SAVEDATA_FORCE_NONE) { + return false; + } switch (savedata->type) { case SAVEDATA_SRAM: return in->read(in, savedata->data, SIZE_CART_SRAM) == SIZE_CART_SRAM;@@ -140,14 +159,6 @@ case SAVEDATA_AUTODETECT:
case SAVEDATA_FORCE_NONE: return true; } - } else if (savedata->vf) { - off_t read = 0; - uint8_t buffer[2048]; - do { - in->read(in, buffer, read); - read = savedata->vf->write(savedata->vf, buffer, sizeof(buffer)); - } while (read == sizeof(buffer)); - return read >= 0; } return true; }
M
src/gba/serialize.c
→
src/gba/serialize.c
@@ -458,8 +458,8 @@ }
} if (flags & SAVESTATE_SAVEDATA && GBAExtdataGet(&extdata, EXTDATA_SAVEDATA, &item)) { struct VFile* svf = VFileFromMemory(item.data, item.size); + GBASavedataLoad(&gba->memory.savedata, svf); if (svf) { - GBASavedataLoad(&gba->memory.savedata, svf); svf->close(svf); } }