diff options
Diffstat (limited to 'engines/sci/engine/savegame.cpp')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 6955225fe5..c64d5b6272 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -219,25 +219,30 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { syncArray<Class>(s, _classTable); - // Now that all scripts are loaded, init their objects - for (uint i = 0; i < _heap.size(); i++) { - if (!_heap[i] || _heap[i]->getType() != SEG_TYPE_SCRIPT) - continue; + // Now that all scripts are loaded, init their objects. + // Just like in Script::initializeObjectsSci0, we do two passes + // in case an object is loaded before its base. + int passes = getSciVersion() < SCI_VERSION_1_1 ? 2 : 1; + for (int pass = 1; pass <= passes; ++pass) { + for (uint i = 0; i < _heap.size(); i++) { + if (!_heap[i] || _heap[i]->getType() != SEG_TYPE_SCRIPT) + continue; - Script *scr = (Script *)_heap[i]; - scr->syncLocalsBlock(this); + Script *scr = (Script *)_heap[i]; + scr->syncLocalsBlock(this); - ObjMap objects = scr->getObjectMap(); - for (ObjMap::iterator it = objects.begin(); it != objects.end(); ++it) { - reg_t addr = it->_value.getPos(); - Object *obj = scr->scriptObjInit(addr, false); + ObjMap objects = scr->getObjectMap(); + for (ObjMap::iterator it = objects.begin(); it != objects.end(); ++it) { + reg_t addr = it->_value.getPos(); + Object *obj = scr->scriptObjInit(addr, false); - if (getSciVersion() < SCI_VERSION_1_1) { - if (!obj->initBaseObject(this, addr, false)) { - // TODO/FIXME: This should not be happening at all. It might indicate a possible issue - // with the garbage collector. It happens for example in LSL5 (German, perhaps English too). - warning("Failed to locate base object for object at %04X:%04X; skipping", PRINT_REG(addr)); - objects.erase(addr.toUint16()); + if (pass == 2) { + if (!obj->initBaseObject(this, addr, false)) { + // TODO/FIXME: This should not be happening at all. It might indicate a possible issue + // with the garbage collector. It happens for example in LSL5 (German, perhaps English too). + warning("Failed to locate base object for object at %04X:%04X; skipping", PRINT_REG(addr)); + objects.erase(addr.toUint16()); + } } } } @@ -484,7 +489,7 @@ void Script::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(_nr); if (s.isLoading()) - load(_nr, g_sci->getResMan()); + load(_nr, g_sci->getResMan(), g_sci->getScriptPatcher()); s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _bufSize s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _scriptSize s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _heapSize @@ -855,16 +860,13 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { return; } - if ((meta.version < MINIMUM_SAVEGAME_VERSION) || - (meta.version > CURRENT_SAVEGAME_VERSION)) { - /* - if (meta.version < MINIMUM_SAVEGAME_VERSION) - warning("Old savegame version detected, unable to load it"); - else - warning("Savegame version is %d, maximum supported is %0d", meta.version, CURRENT_SAVEGAME_VERSION); - */ - - showScummVMDialog("The format of this saved game is obsolete, unable to load it"); + if ((meta.version < MINIMUM_SAVEGAME_VERSION) || (meta.version > CURRENT_SAVEGAME_VERSION)) { + if (meta.version < MINIMUM_SAVEGAME_VERSION) { + showScummVMDialog("The format of this saved game is obsolete, unable to load it"); + } else { + Common::String msg = Common::String::format("Savegame version is %d, maximum supported is %0d", meta.version, CURRENT_SAVEGAME_VERSION); + showScummVMDialog(msg); + } s->r_acc = TRUE_REG; // signal failure return; @@ -873,8 +875,6 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { if (meta.gameObjectOffset > 0 && meta.script0Size > 0) { Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false); if (script0->size != meta.script0Size || g_sci->getGameObject().getOffset() != meta.gameObjectOffset) { - //warning("This saved game was created with a different version of the game, unable to load it"); - showScummVMDialog("This saved game was created with a different version of the game, unable to load it"); s->r_acc = TRUE_REG; // signal failure |