From 1ac8533b1f60d5695fb7095d7da9157689bdef6e Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Sun, 21 Feb 2016 20:32:42 +0100 Subject: SCI32: Fix save patching for ScummVM dialog - Patch game super object for saving instead of game object - Remove re-adding planes+screen items, game::replay does that We would only have to do that for soft-failing on restore - Change debug levels of kNumLoops/kNumCels to 9 - Add special comment about -info- selector in syncWithScripts() This should now make ScummVM menu saving work properly at least in SQ6. --- engines/sci/engine/kgraphics.cpp | 4 ++-- engines/sci/engine/savegame.cpp | 11 ++++++----- engines/sci/graphics/frameout.cpp | 2 ++ engines/sci/sci.cpp | 22 +++++++++++++++++----- 4 files changed, 27 insertions(+), 12 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 0b945c1eec..91d241fb79 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -492,7 +492,7 @@ reg_t kNumLoops(EngineState *s, int argc, reg_t *argv) { loopCount = g_sci->_gfxCache->kernelViewGetLoopCount(viewId); - debugC(kDebugLevelGraphics, "NumLoops(view.%d) = %d", viewId, loopCount); + debugC(9, kDebugLevelGraphics, "NumLoops(view.%d) = %d", viewId, loopCount); return make_reg(0, loopCount); } @@ -505,7 +505,7 @@ reg_t kNumCels(EngineState *s, int argc, reg_t *argv) { celCount = g_sci->_gfxCache->kernelViewGetCelCount(viewId, loopNo); - debugC(kDebugLevelGraphics, "NumCels(view.%d, %d) = %d", viewId, loopNo, celCount); + debugC(9, kDebugLevelGraphics, "NumCels(view.%d, %d) = %d", viewId, loopNo, celCount); return make_reg(0, celCount); } diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 1b56e667bf..851e4fc07e 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -1096,11 +1096,12 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { if (g_sci->_gfxPorts) g_sci->_gfxPorts->saveLoadWithSerializer(ser); -#ifdef ENABLE_SCI32 - // Add current planes/screen elements of freshly loaded VM, only when our ScummVM dialogs are patched in - if (getSciVersion() >= SCI_VERSION_2) - g_sci->_gfxFrameout->syncWithScripts(true); -#endif + // SCI32: + // Current planes/screen elements of freshly loaded VM are re-added by scripts in [gameID]::replay + // We don't have to do that in here. + // But we may have to do it ourselves in case we ever implement some soft-error handling in case + // a saved game can't be restored. That way we can restore the game screen. + // see _gfxFrameout->syncWithScripts() Vocabulary *voc = g_sci->getVocabulary(); if (ser.getVersion() >= 30 && voc) diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp index 8a7a4856d1..260bd27684 100644 --- a/engines/sci/graphics/frameout.cpp +++ b/engines/sci/graphics/frameout.cpp @@ -210,6 +210,8 @@ void GfxFrameout::syncWithScripts(bool addElements) { // read selector "-info-" of this object // TODO: Seems to have been changed for SCI3 + // Do NOT use getInfoSelector in here. SCI3 games did not use infoToa, but an actual selector. + // Maybe that selector is just a straight copy, but it needs to get verified/checked. uint16 castInfoSelector = readSelectorValue(segMan, castObject, SELECTOR(_info_)); if (castInfoSelector & kInfoFlagViewInserted) { diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 49eb31de53..cce0235fd5 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -576,17 +576,29 @@ void SciEngine::patchGameSaveRestore() { } } + const Object *patchObjectSave = nullptr; + + if (getSciVersion() < SCI_VERSION_2) { + // Patch gameobject ::save for now for SCI0 - SCI1.1 + // TODO: It seems this was never adjusted to superclass, but adjusting it now may cause + // issues with some game. Needs to get checked and then possibly changed. + patchObjectSave = gameObject; + } else { + // Patch superclass ::save for SCI32 + patchObjectSave = gameSuperObject; + } + // Search for gameobject ::save, if there is one patch that one too - uint16 gameObjectMethodCount = gameObject->getMethodCount(); - for (uint16 methodNr = 0; methodNr < gameObjectMethodCount; methodNr++) { - uint16 selectorId = gameObject->getFuncSelector(methodNr); + uint16 patchObjectMethodCount = patchObjectSave->getMethodCount(); + for (uint16 methodNr = 0; methodNr < patchObjectMethodCount; methodNr++) { + uint16 selectorId = patchObjectSave->getFuncSelector(methodNr); Common::String methodName = _kernel->getSelectorName(selectorId); if (methodName == "save") { if (_gameId != GID_FAIRYTALES) { // Fairy Tales saves automatically without a dialog if (kernelIdSave != kernelIdRestore) - patchGameSaveRestoreCode(segMan, gameObject->getFunction(methodNr), kernelIdSave); + patchGameSaveRestoreCode(segMan, patchObjectSave->getFunction(methodNr), kernelIdSave); else - patchGameSaveRestoreCodeSci21(segMan, gameObject->getFunction(methodNr), kernelIdSave, false); + patchGameSaveRestoreCodeSci21(segMan, patchObjectSave->getFunction(methodNr), kernelIdSave, false); } break; } -- cgit v1.2.3