[Scummvm-git-logs] scummvm master -> 18ba1461e03a10b7c92f1089a5c9d8fc5e381b5e

antoniou79 a.antoniou79 at gmail.com
Sat Jul 25 13:56:26 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
18ba1461e0 SKY: Fix loading the wrong saved file from ScummVM menu


Commit: 18ba1461e03a10b7c92f1089a5c9d8fc5e381b5e
    https://github.com/scummvm/scummvm/commit/18ba1461e03a10b7c92f1089a5c9d8fc5e381b5e
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2020-07-25T16:53:41+03:00

Commit Message:
SKY: Fix loading the wrong saved file from ScummVM menu

Changed paths:
    engines/sky/control.cpp
    engines/sky/detection.cpp


diff --git a/engines/sky/control.cpp b/engines/sky/control.cpp
index 07a56cef7b..f74cb370c2 100644
--- a/engines/sky/control.cpp
+++ b/engines/sky/control.cpp
@@ -1463,6 +1463,10 @@ uint16 Control::restoreGameFromFile(bool autoSave) {
 	return res;
 }
 
+/**
+* @param slot The slot index in the ScummVM Save file manager. "0" is the auto-save slot.
+* @return The result of the restore attempt. A value from "onClick return codes" eg GAME_RESTORED, RESTORE_FAILED etc
+*/
 uint16 Control::quickXRestore(uint16 slot) {
 	uint16 result;
 	if (!_controlPanel)
diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp
index 60224e2d0a..b9dd4172ae 100644
--- a/engines/sky/detection.cpp
+++ b/engines/sky/detection.cpp
@@ -380,20 +380,37 @@ void SkyMetaEngine::removeSaveState(const char *target, int slot) const {
 
 namespace Sky {
 Common::Error SkyEngine::loadGameState(int slot) {
-	uint16 result = _skyControl->quickXRestore(slot - 1);
+	// We don't need to offset "slot" here. Both loadGameState and quickXRestore
+	// are called with the ScummVM Save File Manager's "slot" as argument
+	uint16 result = _skyControl->quickXRestore(slot);
 	return (result == GAME_RESTORED) ? Common::kNoError : Common::kUnknownError;
 }
 
+/**
+* Manually saving a game should save it into ScummVM Save File Managers slots 1 or greater.
+* ScummVM Save file manager's slot 0 is reserved for the autosave.
+* However, natively, the index 0 (_selectedGame) is the first manually saved game.
+* @param slot is the save slot on the ScummVM file manager's list
+*
+*/
 Common::Error SkyEngine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
 	// prevent writing to autosave slot when user selects it manually
-	// ie. from the ScummVM in-game menu Save panel
+	// ie. from the ScummVM in-game menu Save feature
 	// This also secures _selectedGame which is unsigned integer (uint16)
 	// from overflowing in the subtraction below
-	if (!isAutosave && slot <= 0) {
+	if (slot < 0 || (!isAutosave && slot == 0)) {
 		return Common::kWritePermissionDenied;
 	}
 	// Set the save slot and save the game
-	_skyControl->_selectedGame = isAutosave ? 0 : slot - 1;
+	// _selectedGame value is one unit lower than the ScummVM's Save File Manager's slot value
+	// Note that *_selectedGame* value 0 corresponds to a manually saved game (the first in order)
+	//   whereas *slot* value 0 corresponds to the autosave
+	if (slot > 0) {
+		// We don't care for updating the _selectedGame when slot == 0
+		// (in the case of autosave) but we do include the check for slot > 0
+		// to guard from overflow, which would be bad practice to allow.
+		_skyControl->_selectedGame = slot - 1;
+	}
 	if (_skyControl->saveGameToFile(false, nullptr, isAutosave) != GAME_SAVED)
 		return Common::kWritePermissionDenied;
 
@@ -403,8 +420,9 @@ Common::Error SkyEngine::saveGameState(int slot, const Common::String &desc, boo
 	_skyControl->loadDescriptions(saveGameTexts);
 
 	// Update the save game description at the given slot
-	if (!isAutosave)
-		saveGameTexts[slot - 1] = desc;
+	if (!isAutosave) {
+		saveGameTexts[_skyControl->_selectedGame] = desc;
+	}
 
 	// Save the updated descriptions
 	_skyControl->saveDescriptions(saveGameTexts);




More information about the Scummvm-git-logs mailing list