diff options
author | Max Horn | 2006-02-25 11:12:44 +0000 |
---|---|---|
committer | Max Horn | 2006-02-25 11:12:44 +0000 |
commit | 1f987027f8f901e48f064cdc766064f4bf4b6fc9 (patch) | |
tree | a012a7aa9f50ba936ea30ba582f5a3bae86d74ea /engines | |
parent | eef3ac0e73801774ee6b9fffc17849845d026ea8 (diff) | |
download | scummvm-rg350-1f987027f8f901e48f064cdc766064f4bf4b6fc9.tar.gz scummvm-rg350-1f987027f8f901e48f064cdc766064f4bf4b6fc9.tar.bz2 scummvm-rg350-1f987027f8f901e48f064cdc766064f4bf4b6fc9.zip |
Removed last two uses of MKID
svn-id: r20872
Diffstat (limited to 'engines')
-rw-r--r-- | engines/saga/saveload.cpp | 41 | ||||
-rw-r--r-- | engines/scumm/saveload.cpp | 40 |
2 files changed, 47 insertions, 34 deletions
diff --git a/engines/saga/saveload.cpp b/engines/saga/saveload.cpp index 761ae49521..d9eb7cc4d4 100644 --- a/engines/saga/saveload.cpp +++ b/engines/saga/saveload.cpp @@ -135,9 +135,12 @@ void SagaEngine::fillSaveList() { if (_saveMarks[i]) { name = calcSaveFileName(i); if ((in = _saveFileMan->openForLoading(name)) != NULL) { - in->read(&_saveHeader, sizeof(_saveHeader)); + _saveHeader.type = in->readUint32BE(); + _saveHeader.size = in->readUint32LE(); + _saveHeader.version = in->readUint32LE(); + in->read(_saveHeader.name, sizeof(_saveHeader.name)); - if (_saveHeader.type != MKID('SAGA')) { + if (_saveHeader.type != MKID_BE('SAGA')) { error("SagaEngine::load wrong format"); } strcpy(_saveFiles[_saveFilesCount].name, _saveHeader.name); @@ -168,13 +171,18 @@ void SagaEngine::save(const char *fileName, const char *saveName) { return; } - _saveHeader.type = MKID('SAGA'); + _saveHeader.type = MKID_BE('SAGA'); _saveHeader.size = 0; - _saveHeader.version = TO_LE_32(CURRENT_SAGA_VER); + _saveHeader.version = CURRENT_SAGA_VER; strncpy(_saveHeader.name, saveName, SAVE_TITLE_SIZE); out->write(&_saveHeader, sizeof(_saveHeader)); + out->writeUint32BE(_saveHeader.type); + out->writeUint32LE(_saveHeader.size); + out->writeUint32LE(_saveHeader.version); + out->write(_saveHeader.name, sizeof(_saveHeader.name)); + // Original game title memset(title, 0, TITLESIZE); strncpy(title, getGameDescription()->title, TITLESIZE); @@ -221,18 +229,17 @@ void SagaEngine::load(const char *fileName) { return; } - in->read(&_saveHeader, sizeof(_saveHeader)); - - _saveHeader.size = FROM_LE_32(_saveHeader.size); - _saveHeader.version = FROM_LE_32(_saveHeader.version); - - // This save was written in native endianness (fix that, so warning will show up) - if (_saveHeader.version > CURRENT_SAGA_VER) { -#ifdef SCUMM_LITTLE_ENDIAN - _saveHeader.version = TO_BE_32(_saveHeader.version); -#else - _saveHeader.version = TO_LE_32(_saveHeader.version); -#endif + _saveHeader.type = in->readUint32BE(); + _saveHeader.size = in->readUint32LE(); + _saveHeader.version = in->readUint32LE(); + in->read(_saveHeader.name, sizeof(_saveHeader.name)); + + // Some older saves were not written in an endian safe fashion. + // We try to detect this here by checking for extremly high version values. + // If found, we retry with the data swapped. + // FIXME: Maybe display a warning/error message instead? + if (_saveHeader.version > 0xFFFFFF) { + _saveHeader.version = SWAP_BYTES_32(_saveHeader.version); } debug(2, "Save version: %x", _saveHeader.version); @@ -240,7 +247,7 @@ void SagaEngine::load(const char *fileName) { if (_saveHeader.version < 4) warning("This savegame is not endian-safe. There may be problems"); - if (_saveHeader.type != MKID('SAGA')) { + if (_saveHeader.type != MKID_BE('SAGA')) { error("SagaEngine::load wrong format"); } diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 80d309bacf..8a6bd17089 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -102,11 +102,14 @@ bool ScummEngine::saveState(int slot, bool compat) { memcpy(hdr.name, _saveLoadName, sizeof(hdr.name)); - hdr.type = MKID('SCVM'); + hdr.type = MKID_BE('SCVM'); hdr.size = 0; - hdr.ver = TO_LE_32(CURRENT_VER); + hdr.ver = CURRENT_VER; - out->write(&hdr, sizeof(hdr)); + out->writeUint32BE(hdr.type); + out->writeUint32LE(hdr.size); + out->writeUint32LE(hdr.ver); + out->write(hdr.name, sizeof(hdr.name)); saveThumbnail(out); saveInfos(out); @@ -123,6 +126,14 @@ bool ScummEngine::saveState(int slot, bool compat) { return true; } +static bool loadSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &hdr) { + hdr.type = in->readUint32BE(); + hdr.size = in->readUint32LE(); + hdr.ver = in->readUint32LE(); + in->read(hdr.name, sizeof(hdr.name)); + return !in->ioFailed() && hdr.type == MKID_BE('SCVM'); +} + bool ScummEngine::loadState(int slot, bool compat) { char filename[256]; Common::InSaveFile *in; @@ -134,16 +145,16 @@ bool ScummEngine::loadState(int slot, bool compat) { if (!(in = _saveFileMan->openForLoading(filename))) return false; - in->read(&hdr, sizeof(hdr)); - if (hdr.type != MKID('SCVM')) { + if (!loadSaveGameHeader(in, hdr)) { warning("Invalid savegame '%s'", filename); delete in; return false; } // In older versions of ScummVM, the header version was not endian safe. - // We account for that by retrying once with swapped byte order. - if (hdr.ver > CURRENT_VER) + // We account for that by retrying once with swapped byte order in case + // we see a version that is higher than anything we'd expect... + if (hdr.ver > 0xFFFFFF) hdr.ver = SWAP_BYTES_32(hdr.ver); // Reject save games which are too old or too new. Note that @@ -432,20 +443,19 @@ bool ScummEngine::getSavegameName(int slot, char *desc) { char filename[256]; Common::InSaveFile *in; SaveGameHeader hdr; - int len; makeSavegameName(filename, slot, false); if (!(in = _saveFileMan->openForLoading(filename))) { strcpy(desc, ""); return false; } - len = in->read(&hdr, sizeof(hdr)); - delete in; - if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { + if (!loadSaveGameHeader(in, hdr)) { + delete in; strcpy(desc, "Invalid savegame"); return false; } + delete in; if (hdr.ver > CURRENT_VER) hdr.ver = TO_LE_32(hdr.ver); @@ -469,15 +479,13 @@ Graphics::Surface *ScummEngine::loadThumbnailFromSlot(int slot) { char filename[256]; Common::InSaveFile *in; SaveGameHeader hdr; - int len; makeSavegameName(filename, slot, false); if (!(in = _saveFileMan->openForLoading(filename))) { return 0; } - len = in->read(&hdr, sizeof(hdr)); - if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { + if (!loadSaveGameHeader(in, hdr)) { delete in; return 0; } @@ -499,15 +507,13 @@ bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) { char filename[256]; Common::InSaveFile *in; SaveGameHeader hdr; - int len; makeSavegameName(filename, slot, false); if (!(in = _saveFileMan->openForLoading(filename))) { return false; } - len = in->read(&hdr, sizeof(hdr)); - if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { + if (!loadSaveGameHeader(in, hdr)) { delete in; return false; } |