[Scummvm-cvs-logs] SF.net SVN: scummvm: [29771] scummvm/trunk/engines/agi

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sat Dec 8 19:25:03 CET 2007


Revision: 29771
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29771&view=rev
Author:   thebluegr
Date:     2007-12-08 10:25:00 -0800 (Sat, 08 Dec 2007)

Log Message:
-----------
Saving and loading in Winnie the Pooh should now be endian and alignment safe. Note that this breaks older saved games and it's no longer possible to use saved games from the original game interpreter

Modified Paths:
--------------
    scummvm/trunk/engines/agi/preagi_winnie.cpp
    scummvm/trunk/engines/agi/preagi_winnie.h

Modified: scummvm/trunk/engines/agi/preagi_winnie.cpp
===================================================================
--- scummvm/trunk/engines/agi/preagi_winnie.cpp	2007-12-08 18:19:09 UTC (rev 29770)
+++ scummvm/trunk/engines/agi/preagi_winnie.cpp	2007-12-08 18:25:00 UTC (rev 29771)
@@ -31,12 +31,14 @@
 
 #include "common/events.h"
 #include "common/savefile.h"
+#include "common/stream.h"
 
 namespace Agi {
 
 // default attributes
-#define IDA_DEFAULT		0x0F
-#define IDA_DEFAULT_REV	0xF0
+#define IDA_DEFAULT				0x0F
+#define IDA_DEFAULT_REV			0xF0
+#define WTP_SAVEGAME_VERSION	1
 
 void Winnie::parseRoomHeader(WTP_ROOM_HDR *roomHdr, byte *buffer, int len) {
 	bool isBigEndian = (_vm->getPlatform() == Common::kPlatformAmiga);
@@ -1192,33 +1194,73 @@
 }
 
 void Winnie::saveGame() {
-	uint8 *buffer = (uint8 *)malloc(sizeof(WTP_SAVE_GAME));
-	memcpy(buffer, &_game, sizeof(WTP_SAVE_GAME));
 	Common::OutSaveFile* outfile;
 	char szFile[256] = {0};
+	int i = 0;
 
 	sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
 	if (!(outfile = _vm->getSaveFileMan()->openForSaving(szFile)))
 		return;
-	outfile->write(buffer, sizeof(WTP_SAVE_GAME));
+
+	outfile->writeUint32BE(MKID_BE('WINN'));	// header
+	outfile->writeByte(WTP_SAVEGAME_VERSION);
+
+	outfile->writeByte(_game.fSound);
+	outfile->writeByte(_game.nMoves);
+	outfile->writeByte(_game.nObjMiss);
+	outfile->writeByte(_game.nObjRet);
+	outfile->writeByte(_game.iObjHave);
+
+	for(i = 0; i < IDI_WTP_MAX_FLAG; i++)
+		outfile->writeByte(_game.fGame[i]);
+
+	for(i = 0; i < IDI_WTP_MAX_OBJ_MISSING; i++)
+		outfile->writeByte(_game.iUsedObj[i]);
+
+	for(i = 0; i < IDI_WTP_MAX_ROOM_OBJ; i++)
+		outfile->writeByte(_game.iObjRoom[i]);
+
+	outfile->finalize();
+
+	if (outfile->ioFailed())
+		warning("Can't write file '%s'. (Disk full?)", szFile);
+
 	delete outfile;
-
-	free(buffer);
 }
 
 void Winnie::loadGame() {
-	uint8 *buffer = (uint8 *)malloc(sizeof(WTP_SAVE_GAME));
 	Common::InSaveFile* infile;
 	char szFile[256] = {0};
+	int saveVersion = 0;
+	int i = 0;
 
 	sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
 	if (!(infile = _vm->getSaveFileMan()->openForLoading(szFile)))
 		return;
-	infile->read(buffer, sizeof(WTP_SAVE_GAME));
+
+	if (infile->readUint32BE() != MKID_BE('WINN'))
+		error("Winnie::loadGame wrong save game format");
+
+	saveVersion = infile->readByte();
+	if (saveVersion != WTP_SAVEGAME_VERSION)
+		warning("Old save game version (%d, current version is %d). Will try and read anyway, but don't be surprised if bad things happen", saveVersion, WTP_SAVEGAME_VERSION);
+
+	_game.fSound = infile->readByte();
+	_game.nMoves = infile->readByte();
+	_game.nObjMiss = infile->readByte();
+	_game.nObjRet = infile->readByte();
+	_game.iObjHave = infile->readByte();
+
+	for(i = 0; i < IDI_WTP_MAX_FLAG; i++)
+		_game.fGame[i] = infile->readByte();
+
+	for(i = 0; i < IDI_WTP_MAX_OBJ_MISSING; i++)
+		_game.iUsedObj[i] = infile->readByte();
+
+	for(i = 0; i < IDI_WTP_MAX_ROOM_OBJ; i++)
+		_game.iObjRoom[i] = infile->readByte();
+
 	delete infile;
-
-	memcpy(&_game, buffer, sizeof(WTP_SAVE_GAME));
-	free(buffer);
 }
 
 // Console-related functions

Modified: scummvm/trunk/engines/agi/preagi_winnie.h
===================================================================
--- scummvm/trunk/engines/agi/preagi_winnie.h	2007-12-08 18:19:09 UTC (rev 29770)
+++ scummvm/trunk/engines/agi/preagi_winnie.h	2007-12-08 18:25:00 UTC (rev 29771)
@@ -274,23 +274,14 @@
 // savegame
 
 struct WTP_SAVE_GAME {
-	uint16	reserved0;	// 10c2			unused
-	uint16	fSound;		// 10c4
-	uint16	nMoves;		// 10c6
-	uint16	nObjMiss;	// 10c8
-	uint16	nObjRet;	// 10ca
-	uint16	reserved1;	// 10ce			unused
-	uint16	reserved2;	// 10cf			unused
-	uint16	reserved3;	// 10d0			unused
-	uint16	iObjHave;	// 10d2
-	uint16	o10d4;		// 10d4		can be ignored
-	uint16	o10d6;		// 10d6		can be ignored
-	uint16	o10d8;		// 10d8		can be ignored
-	uint8	fGame[IDI_WTP_MAX_FLAG];			// 10da
-	uint8	iUsedObj[IDI_WTP_MAX_OBJ_MISSING];	// 1102
-	uint8	iObjRoom[IDI_WTP_MAX_ROOM_OBJ];		// 110c
-	uint16	o1136;		// 1136		can be ignored
-	uint16	o1138;		// 1138		can be ignored
+	uint8	fSound;
+	uint8	nMoves;
+	uint8	nObjMiss;
+	uint8	nObjRet;
+	uint8	iObjHave;
+	uint8	fGame[IDI_WTP_MAX_FLAG];
+	uint8	iUsedObj[IDI_WTP_MAX_OBJ_MISSING];
+	uint8	iObjRoom[IDI_WTP_MAX_ROOM_OBJ];
 };
 
 #define IDI_XOR_KEY			0x80


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