[Scummvm-cvs-logs] SF.net SVN: scummvm:[50333] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Sat Jun 26 19:21:50 CEST 2010


Revision: 50333
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50333&view=rev
Author:   mthreepwood
Date:     2010-06-26 17:21:50 +0000 (Sat, 26 Jun 2010)

Log Message:
-----------
Fix saving while viewing the inventory in Riven and cleanup the save/load code.

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/resource.cpp
    scummvm/trunk/engines/mohawk/riven.cpp
    scummvm/trunk/engines/mohawk/riven_saveload.cpp
    scummvm/trunk/engines/mohawk/riven_saveload.h

Modified: scummvm/trunk/engines/mohawk/resource.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/resource.cpp	2010-06-26 16:54:09 UTC (rev 50332)
+++ scummvm/trunk/engines/mohawk/resource.cpp	2010-06-26 17:21:50 UTC (rev 50333)
@@ -103,7 +103,7 @@
 		else
 			debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x  NameTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset, _types[i].name_table_offset);
 
-		//Resource Table
+		// Resource Table
 		_mhk->seek(_rsrc.abs_offset + _types[i].resource_table_offset);
 		_types[i].resTable.resources = _mhk->readUint16BE();
 

Modified: scummvm/trunk/engines/mohawk/riven.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven.cpp	2010-06-26 16:54:09 UTC (rev 50332)
+++ scummvm/trunk/engines/mohawk/riven.cpp	2010-06-26 17:21:50 UTC (rev 50333)
@@ -29,6 +29,7 @@
 #include "common/keyboard.h"
 
 #include "mohawk/graphics.h"
+#include "mohawk/resource.h"
 #include "mohawk/riven.h"
 #include "mohawk/riven_external.h"
 #include "mohawk/riven_saveload.h"

Modified: scummvm/trunk/engines/mohawk/riven_saveload.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven_saveload.cpp	2010-06-26 16:54:09 UTC (rev 50332)
+++ scummvm/trunk/engines/mohawk/riven_saveload.cpp	2010-06-26 17:21:50 UTC (rev 50333)
@@ -23,6 +23,7 @@
  *
  */
 
+#include "mohawk/resource.h"
 #include "mohawk/riven.h"
 #include "mohawk/riven_saveload.h"
 
@@ -31,11 +32,9 @@
 namespace Mohawk {
 
 RivenSaveLoad::RivenSaveLoad(MohawkEngine_Riven *vm, Common::SaveFileManager *saveFileMan) : _vm(vm), _saveFileMan(saveFileMan) {
-	_loadFile = new MohawkArchive();
 }
 
 RivenSaveLoad::~RivenSaveLoad() {
-	delete _loadFile;
 }
 
 Common::StringArray RivenSaveLoad::generateSaveGameList() {
@@ -63,7 +62,8 @@
 	case 8:
 		return aspit;
 	}
-	error ("Unknown old stack ID %d", oldID);
+
+	error("Unknown old stack ID %d", oldID);
 	return 0;
 }
 
@@ -86,7 +86,8 @@
 	case tspit:
 		return 4;
 	}
-	error ("Unknown new stack ID %d", newID);
+
+	error("Unknown new stack ID %d", newID);
 	return 0;
 }
 
@@ -94,26 +95,28 @@
 	if (_vm->getFeatures() & GF_DEMO) // Don't load games in the demo
 		return false;
 
-	Common::InSaveFile *loadFile;
-	if (!(loadFile = _saveFileMan->openForLoading(filename.c_str())))
+	Common::InSaveFile *loadFile =  _saveFileMan->openForLoading(filename);
+	if (!loadFile)
 		return false;
-	debug (0, "Loading game from \'%s\'", filename.c_str());
 
-	_loadFile->open(loadFile);
+	debug(0, "Loading game from \'%s\'", filename.c_str());
 
+	MohawkArchive *mhk = new MohawkArchive();
+	mhk->open(loadFile);
+
 	// First, let's make sure we're using a saved game file from this version of Riven by checking the VERS resource
-	Common::SeekableReadStream *vers = _loadFile->getRawData(ID_VERS, 1);
+	Common::SeekableReadStream *vers = mhk->getRawData(ID_VERS, 1);
 	uint32 saveGameVersion = vers->readUint32BE();
 	delete vers;
 	if ((saveGameVersion == kCDSaveGameVersion && (_vm->getFeatures() & GF_DVD))
 		|| (saveGameVersion == kDVDSaveGameVersion && !(_vm->getFeatures() & GF_DVD))) {
-		warning ("Incompatible saved game versions. No support for this yet.");
-		delete _loadFile;
+		warning("Incompatible saved game versions. No support for this yet.");
+		delete mhk;
 		return false;
 	}
 
 	// Now, we'll read in the variable values.
-	Common::SeekableReadStream *vars = _loadFile->getRawData(ID_VARS, 1);
+	Common::SeekableReadStream *vars = mhk->getRawData(ID_VARS, 1);
 	Common::Array<uint32> rawVariables;
 
 	while (!vars->eos()) {
@@ -126,7 +129,7 @@
 
 	// Next, we set the variables based on the name found by the index in the VARS resource.
 	// TODO: Merge with code in mohawk.cpp for loading names?
-	Common::SeekableReadStream *names = _loadFile->getRawData(ID_NAME, 1);
+	Common::SeekableReadStream *names = mhk->getRawData(ID_NAME, 1);
 
 	uint16 namesCount = names->readUint16BE();
 	uint16 *stringOffsets = new uint16[namesCount];
@@ -151,9 +154,10 @@
 			c = (char)names->readByte();
 		}
 
-		// WORKAROUND: Some versions have two extra variables. However, the saves are
-		// still compatible with other saves of the same version. Are these used in the
-		// original interpreter anywhere? (They come from DVD v1.1)
+		// TODO: Some versions have two extra variables. However, the saves are
+		// still compatible with other saves of the same version (they come from DVD v1.1).
+		// There are used in the whark number puzzle. I thought jleftpos and jrightpos were
+		// for this purpose.
 		if (name == "dropLeftStart" || name == "dropRightStart")
 			continue;
 
@@ -161,11 +165,11 @@
 
 		*var = rawVariables[i];
 
-		if (!scumm_stricmp(name.c_str(), "CurrentStackID"))
+		if (name.equalsIgnoreCase("CurrentStackID"))
 			stackID = mapOldStackIDToNew(rawVariables[i]);
-		else if (!scumm_stricmp(name.c_str(), "CurrentCardID"))
+		else if (name.equalsIgnoreCase("CurrentCardID"))
 			cardID = rawVariables[i];
-		else if (!scumm_stricmp(name.c_str(), "ReturnStackID"))
+		else if (name.equalsIgnoreCase("ReturnStackID"))
 			*var = mapOldStackIDToNew(rawVariables[i]);
 	}
 
@@ -179,7 +183,7 @@
 	_vm->_zipModeData.clear();
 
 	// Finally, we load in zip mode data.
-	Common::SeekableReadStream *zips = _loadFile->getRawData(ID_ZIPS, 1);
+	Common::SeekableReadStream *zips = mhk->getRawData(ID_ZIPS, 1);
 	uint16 zipsRecordCount = zips->readUint16BE();
 	for (uint16 i = 0; i < zipsRecordCount; i++) {
 		ZipMode zip;
@@ -189,10 +193,10 @@
 		zip.id = zips->readUint16BE();
 		_vm->_zipModeData.push_back(zip);
 	}
+
 	delete zips;
+	delete mhk;
 
-	delete _loadFile;
-	_loadFile = NULL;
 	return true;
 }
 
@@ -211,7 +215,14 @@
 	for (uint32 i = 0; i < _vm->getVarCount(); i++) {
 		stream->writeUint32BE(0); // Unknown
 		stream->writeUint32BE(0); // Unknown
-		stream->writeUint32BE(_vm->getGlobalVar(i));
+
+		// Remap returnstackid here because we don't actually want to change
+		// our internal returnstackid.
+		uint32 variable = _vm->getGlobalVar(i);
+		if (_vm->getGlobalVarName(i) == "returnstackid")
+			variable = mapNewStackIDToOld(variable);
+
+		stream->writeUint32BE(variable);
 	}
 
 	return stream;
@@ -257,17 +268,17 @@
 	// Note, this code is still WIP. It works quite well for now.
 
 	// Make sure we have the right extension
-	if (!filename.hasSuffix(".rvn") && !filename.hasSuffix(".RVN"))
+	if (!filename.matchString("*.rvn", true))
 		filename += ".rvn";
 
 	// Convert class variables to variable numbers
 	*_vm->matchVarToString("currentstackid") = mapNewStackIDToOld(_vm->getCurStack());
 	*_vm->matchVarToString("currentcardid") = _vm->getCurCard();
-	*_vm->matchVarToString("returnstackid") = mapNewStackIDToOld(*_vm->matchVarToString("returnstackid"));
 
-	Common::OutSaveFile *saveFile;
-	if (!(saveFile = _saveFileMan->openForSaving(filename.c_str())))
+	Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(filename);
+	if (!saveFile)
 		return false;
+
 	debug (0, "Saving game to \'%s\'", filename.c_str());
 
 	Common::MemoryWriteStreamDynamic *versSection = genVERSSection();
@@ -392,7 +403,7 @@
 
 void RivenSaveLoad::deleteSave(Common::String saveName) {
 	debug (0, "Deleting save file \'%s\'", saveName.c_str());
-	_saveFileMan->removeSavefile(saveName.c_str());
+	_saveFileMan->removeSavefile(saveName);
 }
 
 } // End of namespace Mohawk

Modified: scummvm/trunk/engines/mohawk/riven_saveload.h
===================================================================
--- scummvm/trunk/engines/mohawk/riven_saveload.h	2010-06-26 16:54:09 UTC (rev 50332)
+++ scummvm/trunk/engines/mohawk/riven_saveload.h	2010-06-26 17:21:50 UTC (rev 50333)
@@ -29,8 +29,6 @@
 #include "common/savefile.h"
 #include "common/str.h"
 
-#include "mohawk/resource.h"
-
 namespace Mohawk {
 
 class MohawkEngine_Riven;
@@ -53,7 +51,6 @@
 private:
 	MohawkEngine_Riven *_vm;
 	Common::SaveFileManager *_saveFileMan;
-	MohawkArchive *_loadFile;
 
 	Common::MemoryWriteStreamDynamic *genVERSSection();
 	Common::MemoryWriteStreamDynamic *genNAMESection();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list