GLK: ADVSYS: Save/load fixes

This commit is contained in:
Paul Gilbert 2019-06-16 13:55:41 -07:00
parent 553bb74f8c
commit 919670a565
4 changed files with 18 additions and 7 deletions

View File

@ -103,6 +103,9 @@ bool AdvSys::singleAction() {
}
Common::Error AdvSys::readSaveData(Common::SeekableReadStream *rs) {
if ((int)rs->size() != _saveSize)
return Common::kReadingFailed;
rs->read(_saveArea, rs->size());
return Common::kNoError;
}

View File

@ -190,11 +190,21 @@ Common::Error GlkEngine::loadGameState(int slot) {
// so if present we can validate the save is for this game
for (QuetzalReader::Iterator it = r.begin(); it != r.end(); ++it) {
if ((*it)._id == ID_SCVM) {
// Skip over date/time & playtime
Common::SeekableReadStream *rs = it.getStream();
rs->skip(14);
byte interpType = rs->readByte();
byte language = rs->readByte();
Common::String md5 = QuetzalReader::readString(rs);
delete rs;
if (interpType != getInterpreterType() || language != getLanguage() || md5 != getGameMD5())
errCode = Common::kReadingFailed;
}
}
if (errCode != Common::kNoError) {
if (errCode == Common::kNoError) {
// Scan for an uncompressed memory chunk
errCode = Common::kReadingFailed; // Presume we won't find chunk
for (QuetzalReader::Iterator it = r.begin(); it != r.end(); ++it) {
@ -202,6 +212,7 @@ Common::Error GlkEngine::loadGameState(int slot) {
Common::SeekableReadStream *rs = it.getStream();
errCode = readSaveData(rs).getCode();
delete rs;
break;
}
}
}
@ -228,7 +239,7 @@ Common::Error GlkEngine::saveGameState(int slot, const Common::String &desc) {
errCode = writeGameData(&ws).getCode();
}
if (errCode != Common::kNoError) {
if (errCode == Common::kNoError) {
w.save(*file, desc);
}

View File

@ -45,10 +45,8 @@ bool QuetzalReader::open(Common::SeekableReadStream *stream, uint32 formType) {
uint32 size = stream->readUint32BE();
uint32 fileFormType = stream->readUint32BE();
if (formType != ID_IFSF)
return false;
if ((formType != 0 && fileFormType != formType) ||
(formType == 0 && (fileFormType == ID_IFZS || fileFormType == ID_IFSF)))
(formType == 0 && fileFormType != ID_IFZS && fileFormType != ID_IFSF))
return false;
if ((int)size > stream->size() || (size & 1) || (size < 4))
@ -112,7 +110,6 @@ bool QuetzalReader::getSavegameMetaInfo(Common::SeekableReadStream *rs, SaveStat
ssd.setDescription(readString(s));
delete s;
return true;
} else if ((*it)._id == ID_SCVM) {
Common::SeekableReadStream *s = it.getStream();
int year = s->readUint16BE();

View File

@ -781,7 +781,7 @@ FileStream::FileStream(Streams *streams, frefid_t fref, uint fmode, uint rock, b
Common::String fname = fref->_slotNumber == -1 ? fref->_filename : fref->getSaveName();
if (fmode == filemode_Write || fmode == filemode_ReadWrite || fmode == filemode_WriteAppend) {
_outFile = g_system->getSavefileManager()->openForSaving(fname, fref->_slotNumber != -1 && g_vm->getInterpreterType() != INTERPRETER_FROTZ);
_outFile = g_system->getSavefileManager()->openForSaving(fname, false);
if (!_outFile)
error("Could open file for writing - %s", fname.c_str());