[Scummvm-git-logs] scummvm master -> 0d7a8dc7dccf5c4a52ccb026ea87be77b4935241

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Jul 14 05:20:22 UTC 2021


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

Summary:
72ed20db10 SAGA2: Make Globals save size portable
6f7cab17c4 SAGA2: Make Calender save size portable
0d7a8dc7dc SAGA2: Make several save size calculations portable


Commit: 72ed20db108c5de65df33aaa913def4b2717e451
    https://github.com/scummvm/scummvm/commit/72ed20db108c5de65df33aaa913def4b2717e451
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-14T12:12:07+09:00

Commit Message:
SAGA2: Make Globals save size portable

Changed paths:
    engines/saga2/fta.h
    engines/saga2/main.cpp
    engines/saga2/saga2.h
    engines/saga2/saveload.h


diff --git a/engines/saga2/fta.h b/engines/saga2/fta.h
index 1f38a61fee..473ab9a891 100644
--- a/engines/saga2/fta.h
+++ b/engines/saga2/fta.h
@@ -189,7 +189,7 @@ void cleanupPathFinder(void);
  * ===================================================================== */
 
 void initGlobals(void);
-void saveGlobals(Common::OutSaveFile *out);
+void saveGlobals(Common::OutSaveFile *outS);
 void loadGlobals(Common::InSaveFile *in);
 inline void cleanupGlobals(void) {}      // do nothing
 
diff --git a/engines/saga2/main.cpp b/engines/saga2/main.cpp
index 58a29bba6f..c10cdfeeb5 100644
--- a/engines/saga2/main.cpp
+++ b/engines/saga2/main.cpp
@@ -625,22 +625,6 @@ extern bool         brotherBandingEnabled,
        combatBehaviorEnabled,
        backgroundSimulationPaused;
 
-//	This structure is used archiving any globals which will need to be saved
-//	in a save game file.
-
-struct GlobalsArchive {
-	int32           objectIndex,
-	                actorIndex;
-	bool            brotherBandingEnabled,
-	                centerActorIndicatorEnabled,
-	                interruptableMotionsPaused,
-	                objectStatesPaused,
-	                actorStatesPaused,
-	                actorTasksPaused,
-	                combatBehaviorEnabled,
-	                backgroundSimulationPaused;
-};
-
 //-----------------------------------------------------------------------
 //	Assign initial values to miscellaneous globals
 
@@ -657,22 +641,22 @@ void initGlobals(void) {
 	backgroundSimulationPaused = false;
 }
 
-void saveGlobals(Common::OutSaveFile *out) {
+void saveGlobals(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving globals");
 
-	out->write("GLOB", 4);
-	out->writeUint32LE(sizeof(GlobalsArchive));
-
+	outS->write("GLOB", 4);
+	CHUNK_BEGIN;
 	out->writeUint32LE(objectIndex);
 	out->writeUint32LE(actorIndex);
-	out->writeByte(brotherBandingEnabled);
-	out->writeByte(centerActorIndicatorEnabled);
-	out->writeByte(interruptableMotionsPaused);
-	out->writeByte(objectStatesPaused);
-	out->writeByte(actorStatesPaused);
-	out->writeByte(actorTasksPaused);
-	out->writeByte(combatBehaviorEnabled);
-	out->writeByte(backgroundSimulationPaused);
+	out->writeUint16LE(brotherBandingEnabled);
+	out->writeUint16LE(centerActorIndicatorEnabled);
+	out->writeUint16LE(interruptableMotionsPaused);
+	out->writeUint16LE(objectStatesPaused);
+	out->writeUint16LE(actorStatesPaused);
+	out->writeUint16LE(actorTasksPaused);
+	out->writeUint16LE(combatBehaviorEnabled);
+	out->writeUint16LE(backgroundSimulationPaused);
+	CHUNK_END;
 
 	debugC(3, kDebugSaveload, "... objectIndex = %d", objectIndex);
 	debugC(3, kDebugSaveload, "... actorIndex = %d", actorIndex);
@@ -691,14 +675,14 @@ void loadGlobals(Common::InSaveFile *in) {
 
 	objectIndex = in->readUint32LE();
 	actorIndex = in->readUint32LE();
-	brotherBandingEnabled = in->readByte();
-	centerActorIndicatorEnabled = in->readByte();
-	interruptableMotionsPaused = in->readByte();
-	objectStatesPaused = in->readByte();
-	actorStatesPaused = in->readByte();
-	actorTasksPaused = in->readByte();
-	combatBehaviorEnabled = in->readByte();
-	backgroundSimulationPaused = in->readByte();
+	brotherBandingEnabled = in->readUint16LE();
+	centerActorIndicatorEnabled = in->readUint16LE();
+	interruptableMotionsPaused = in->readUint16LE();
+	objectStatesPaused = in->readUint16LE();
+	actorStatesPaused = in->readUint16LE();
+	actorTasksPaused = in->readUint16LE();
+	combatBehaviorEnabled = in->readUint16LE();
+	backgroundSimulationPaused = in->readUint16LE();
 
 	debugC(3, kDebugSaveload, "... objectIndex = %d", objectIndex);
 	debugC(3, kDebugSaveload, "... actorIndex = %d", actorIndex);
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index b33c331a0c..cf521e6a5a 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -38,6 +38,10 @@ namespace Video {
 class SmackerDecoder;
 }
 
+namespace Common {
+class MemoryWriteStreamDynamic;
+}
+
 namespace Saga2 {
 
 class ContainerList;
diff --git a/engines/saga2/saveload.h b/engines/saga2/saveload.h
index 0b36a96e8a..bbedf045e5 100644
--- a/engines/saga2/saveload.h
+++ b/engines/saga2/saveload.h
@@ -27,8 +27,16 @@
 #ifndef SAGA2_LOADSAVE_H
 #define SAGA2_LOADSAVE_H
 
+#include "common/memstream.h"
+
 namespace Saga2 {
 
+#define CHUNK_BEGIN Common::MemoryWriteStreamDynamic *out = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES)
+
+#define CHUNK_END outS->writeUint32LE(out->size()); \
+	outS->write(out->getData(), out->size()); \
+	delete out
+
 /* ===================================================================== *
    SaveFileHeader class
  * ===================================================================== */


Commit: 6f7cab17c4cb86e32cad72c4389cf0fc6a676f55
    https://github.com/scummvm/scummvm/commit/6f7cab17c4cb86e32cad72c4389cf0fc6a676f55
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-14T12:13:35+09:00

Commit Message:
SAGA2: Make Calender save size portable

Changed paths:
    engines/saga2/calender.cpp
    engines/saga2/calender.h
    engines/saga2/tilemode.cpp


diff --git a/engines/saga2/calender.cpp b/engines/saga2/calender.cpp
index fcf8ee4376..0af6b40968 100644
--- a/engines/saga2/calender.cpp
+++ b/engines/saga2/calender.cpp
@@ -28,6 +28,8 @@
 #include "saga2/calender.h"
 #include "saga2/intrface.h"
 #include "saga2/localize.h"
+#include "saga2/saveload.h"
+
 
 namespace Saga2 {
 
@@ -67,7 +69,7 @@ void CalenderTime::read(Common::InSaveFile *in) {
 	debugC(3, kDebugSaveload, "... frameInHour = %d", frameInHour);
 }
 
-void CalenderTime::write(Common::OutSaveFile *out) {
+void CalenderTime::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeUint16LE(years);
 	out->writeUint16LE(weeks);
 	out->writeUint16LE(days);
@@ -264,23 +266,21 @@ void initCalender(void) {
 	calender.frameInHour    = 0;
 }
 
-void saveCalender(Common::OutSaveFile *out) {
+void saveCalender(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving calender");
 
-	out->write("CALE", 4);
-	out->writeUint32LE(sizeof(calenderPaused) + sizeof(calender));
-
-	out->writeByte(calenderPaused);
-
+	outS->write("CALE", 4);
+	CHUNK_BEGIN;
+	out->writeUint16LE(calenderPaused);
 	debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused);
-
 	calender.write(out);
+	CHUNK_END;
 }
 
 void loadCalender(Common::InSaveFile *in) {
 	debugC(2, kDebugSaveload, "Loading calender");
 
-	calenderPaused = in->readByte();
+	calenderPaused = in->readUint16LE();
 
 	debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused);
 
diff --git a/engines/saga2/calender.h b/engines/saga2/calender.h
index 84d2338db4..da0dd001af 100644
--- a/engines/saga2/calender.h
+++ b/engines/saga2/calender.h
@@ -59,7 +59,7 @@ public:
 	            frameInHour;
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	void update(void);
 	int lightLevel(int maxLevel);
@@ -97,7 +97,7 @@ uint32 operator - (const CalenderTime &time1, const CalenderTime &time2);
 
 void initCalender(void);
 
-void saveCalender(Common::OutSaveFile *out);
+void saveCalender(Common::OutSaveFile *outS);
 void loadCalender(Common::InSaveFile *in);
 
 bool isDayTime(void);
diff --git a/engines/saga2/tilemode.cpp b/engines/saga2/tilemode.cpp
index e6fcde75bf..2a1b22b48d 100644
--- a/engines/saga2/tilemode.cpp
+++ b/engines/saga2/tilemode.cpp
@@ -41,6 +41,7 @@
 #include "saga2/dispnode.h"
 #include "saga2/uidialog.h"
 #include "saga2/contain.h"
+#include "saga2/saveload.h"
 
 namespace Saga2 {
 
@@ -610,26 +611,16 @@ void initTileModeState(void) {
 	combatPaused = false;
 }
 
-void saveTileModeState(Common::OutSaveFile *out) {
+void saveTileModeState(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving TileModeState");
 
-	int32 size = 0;
-
 	assert(uiKeysEnabled);
 
-	//  Compute the number of bytes needed
-	size += sizeof(aggressiveActFlag)
-	        +   sizeof(inCombat)
-	        +   sizeof(combatPaused);
-	if (aggressiveActFlag)
-		size += sizeof(timeOfLastAggressiveAct);
-
-	out->write("TMST", 4);
-	out->writeUint32LE(size);
-
-	out->writeByte(aggressiveActFlag);
-	out->writeByte(inCombat);
-	out->writeByte(combatPaused);
+	outS->write("TMST", 4);
+	CHUNK_BEGIN;
+	out->writeUint16LE(aggressiveActFlag);
+	out->writeUint16LE(inCombat);
+	out->writeUint16LE(combatPaused);
 
 	debugC(3, kDebugSaveload, "... aggressiveActFlag = %d", aggressiveActFlag);
 	debugC(3, kDebugSaveload, "... inCombat = %d", inCombat);
@@ -637,15 +628,16 @@ void saveTileModeState(Common::OutSaveFile *out) {
 
 	if (aggressiveActFlag)
 		timeOfLastAggressiveAct.write(out);
+	CHUNK_END;
 }
 
 void loadTileModeState(Common::InSaveFile *in) {
 	assert(uiKeysEnabled);
 
 	//  Simply read in the data
-	aggressiveActFlag = in->readByte();
-	inCombat = in->readByte();
-	combatPaused = in->readByte();
+	aggressiveActFlag = in->readUint16LE();
+	inCombat = in->readUint16LE();
+	combatPaused = in->readUint16LE();
 
 	debugC(3, kDebugSaveload, "... aggressiveActFlag = %d", aggressiveActFlag);
 	debugC(3, kDebugSaveload, "... inCombat = %d", inCombat);


Commit: 0d7a8dc7dccf5c4a52ccb026ea87be77b4935241
    https://github.com/scummvm/scummvm/commit/0d7a8dc7dccf5c4a52ccb026ea87be77b4935241
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-14T14:19:21+09:00

Commit Message:
SAGA2: Make several save size calculations portable

Changed paths:
    engines/saga2/actor.cpp
    engines/saga2/actor.h
    engines/saga2/assign.cpp
    engines/saga2/assign.h
    engines/saga2/contain.cpp
    engines/saga2/contain.h
    engines/saga2/magic.h
    engines/saga2/motion.cpp
    engines/saga2/motion.h
    engines/saga2/objects.cpp
    engines/saga2/objects.h
    engines/saga2/patrol.cpp
    engines/saga2/patrol.h
    engines/saga2/player.cpp
    engines/saga2/rect.cpp
    engines/saga2/rect.h
    engines/saga2/speech.cpp
    engines/saga2/speech.h
    engines/saga2/spellio.cpp
    engines/saga2/spellio.h
    engines/saga2/spelshow.h
    engines/saga2/sprite.cpp
    engines/saga2/sprite.h
    engines/saga2/target.cpp
    engines/saga2/target.h
    engines/saga2/task.cpp
    engines/saga2/task.h
    engines/saga2/tcoords.h


diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index bb5a1f2ffa..cecf1b0cec 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -1199,7 +1199,7 @@ Actor::Actor(Common::InSaveFile *in) : GameObject(in) {
 
 	faction = in->readByte();
 	colorScheme = in->readByte();
-	appearanceID = in->readSint32LE();
+	appearanceID = in->readSint32BE();
 	attitude = in->readSByte();
 	mood = in->readSByte();
 
@@ -1332,7 +1332,7 @@ int32 Actor::archiveSize(void) {
 	return size;
 }
 
-void Actor::write(Common::OutSaveFile *out) {
+void Actor::write(Common::MemoryWriteStreamDynamic *out) {
 	ProtoObj    *holdProto = prototype;
 
 	debugC(3, kDebugSaveload, "Saving actor %d", thisID());
@@ -1343,14 +1343,14 @@ void Actor::write(Common::OutSaveFile *out) {
 	if (prototype != NULL)
 		prototype = &objectProtos[(ActorProto *)prototype - actorProtos];
 
-	GameObject::write(out);
+	GameObject::write(out, false);
 
 	//  Restore the prototype pointer
 	prototype = holdProto;
 
 	out->writeByte(faction);
 	out->writeByte(colorScheme);
-	out->writeSint32LE(appearanceID);
+	out->writeSint32BE(appearanceID);
 	out->writeSByte(attitude);
 	out->writeSByte(mood);
 
@@ -3540,27 +3540,18 @@ void initActors(void) {
 	actorList[2].disposition = dispositionPlayer + 2;
 }
 
-void saveActors(Common::OutSaveFile *out) {
+void saveActors(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving actors");
 
-	int32   archiveBufSize = 0;
-
-	//  Accumulate size of archive buffer
-
-	//  Add size of actor count
-	archiveBufSize += sizeof(int16);
-
-	for (int i = 0; i < kActorCount; i++)
-		archiveBufSize += actorList[i].archiveSize();
-
-	out->write("ACTR", 4);
-	out->writeUint32LE(archiveBufSize);
+	outS->write("ACTR", 4);
+	CHUNK_BEGIN;
 	out->writeSint16LE(kActorCount);
 
 	debugC(3, kDebugSaveload, "... kActorCount = %d", kActorCount);
 
 	for (int i = 0; i < kActorCount; ++i)
 		actorList[i].write(out);
+	CHUNK_END;
 }
 
 void loadActors(Common::InSaveFile *in) {
diff --git a/engines/saga2/actor.h b/engines/saga2/actor.h
index 188c5c6588..014cd2a371 100644
--- a/engines/saga2/actor.h
+++ b/engines/saga2/actor.h
@@ -28,6 +28,7 @@
 #define SAGA2_ACTOR_H
 
 #include "saga2/objects.h"
+#include "saga2/saveload.h"
 
 namespace Saga2 {
 
@@ -194,7 +195,7 @@ struct ActorAttributes {
 		violetMana = in->readSint16LE();
 	}
 
-	void write(Common::OutSaveFile *out) {
+	void write(Common::MemoryWriteStreamDynamic *out) {
 		out->writeByte(archery);
 		out->writeByte(swordcraft);
 		out->writeByte(shieldcraft);
@@ -735,7 +736,7 @@ public:
 	//  Return the number of bytes needed to archive this actor
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	static Actor *newActor(
 	    int16   protoNum,
diff --git a/engines/saga2/assign.cpp b/engines/saga2/assign.cpp
index 14e080a243..4152cea88e 100644
--- a/engines/saga2/assign.cpp
+++ b/engines/saga2/assign.cpp
@@ -87,7 +87,7 @@ inline int32 ActorAssignment::archiveSize(void) const {
 	return sizeof(startFrame) + sizeof(endFrame);
 }
 
-void ActorAssignment::write(Common::OutSaveFile *out) const {
+void ActorAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	out->writeUint16LE(startFrame);
 	out->writeUint16LE(endFrame);
 }
@@ -208,7 +208,7 @@ inline int32 PatrolRouteAssignment::archiveSize(void) const {
 	            +   sizeof(flags);
 }
 
-void PatrolRouteAssignment::write(Common::OutSaveFile *out) const {
+void PatrolRouteAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving PatrolRouteAssignment");
 
 	//  Let the base class write its data to the buffer
@@ -349,7 +349,7 @@ inline int32 HuntToBeNearLocationAssignment::archiveSize(void) const {
 	            +   sizeof(range);
 }
 
-void HuntToBeNearLocationAssignment::write(Common::OutSaveFile *out) const {
+void HuntToBeNearLocationAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToBeNearLocationAssignment");
 
 	//  Let the base class archive its data
@@ -452,7 +452,7 @@ inline int32 HuntToBeNearActorAssignment::archiveSize(void) const {
 	            +   sizeof(flags);
 }
 
-void HuntToBeNearActorAssignment::write(Common::OutSaveFile *out) const {
+void HuntToBeNearActorAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToBeNearActorAssignment");
 
 	//  Let the base class archive its data
@@ -547,7 +547,7 @@ inline int32 HuntToKillAssignment::archiveSize(void) const {
 	            +   sizeof(flags);
 }
 
-void HuntToKillAssignment::write(Common::OutSaveFile *out) const {
+void HuntToKillAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToKillAssignment");
 
 	//  Let the base class archive its data
@@ -637,7 +637,7 @@ inline int32 TetheredAssignment::archiveSize(void) const {
 	            +   sizeof(maxV);
 }
 
-void TetheredAssignment::write(Common::OutSaveFile *out) const {
+void TetheredAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving TetheredAssignment");
 
 	//  Let the base class archive its data
@@ -712,7 +712,7 @@ inline int32 AttendAssignment::archiveSize(void) const {
 	            +   sizeof(ObjectID);
 }
 
-void AttendAssignment::write(Common::OutSaveFile *out) const {
+void AttendAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving AttendAssignment");
 
 	//  Let the base class write its data to the buffer
@@ -784,7 +784,7 @@ int32 assignmentArchiveSize(Actor *a) {
 	return assign != NULL ? sizeof(int16) + assign->archiveSize() : 0;
 }
 
-void writeAssignment(Actor *a, Common::OutSaveFile *out) {
+void writeAssignment(Actor *a, Common::MemoryWriteStreamDynamic *out) {
 	ActorAssignment *assign = a->getAssignment();
 
 	if (assign != NULL) {
diff --git a/engines/saga2/assign.h b/engines/saga2/assign.h
index 0ca254205f..41de8fc482 100644
--- a/engines/saga2/assign.h
+++ b/engines/saga2/assign.h
@@ -73,7 +73,7 @@ public:
 	//  assignment
 	virtual int32 archiveSize(void) const;
 
-	virtual void write(Common::OutSaveFile *out) const;
+	virtual void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Construct a TaskStack for this assignment
 	TaskStack *createTask(void);
@@ -134,7 +134,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this assignment
 	int16 type(void) const;
@@ -202,7 +202,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	int16 type(void) const;
 
@@ -281,7 +281,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	int16 type(void) const;
 
@@ -352,7 +352,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Determine if assignment's time limit is up or if the actor is
 	//  already dead
@@ -398,7 +398,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 };
 
 /* ===================================================================== *
@@ -437,7 +437,7 @@ public:
 	//  assignment
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this assignment
 	int16 type(void) const;
@@ -455,7 +455,7 @@ protected:
 //  assignment in an archive buffer
 int32 assignmentArchiveSize(Actor *a);
 
-void writeAssignment(Actor *a, Common::OutSaveFile *out);
+void writeAssignment(Actor *a, Common::MemoryWriteStreamDynamic *out);
 void readAssignment(Actor *a, Common::InSaveFile *in);
 
 }
diff --git a/engines/saga2/contain.cpp b/engines/saga2/contain.cpp
index 4d1652463e..db9879ed67 100644
--- a/engines/saga2/contain.cpp
+++ b/engines/saga2/contain.cpp
@@ -1455,7 +1455,7 @@ void ContainerNode::read(Common::InSaveFile *in) {
 	debugC(4, kDebugSaveload, "... shown = %d", shown);
 }
 
-void ContainerNode::write(Common::OutSaveFile *out) {
+void ContainerNode::write(Common::MemoryWriteStreamDynamic *out) {
 	//  Store fields
 	out->writeUint16LE(object);
 	out->writeByte(type);
@@ -1784,18 +1784,15 @@ void initContainerNodes(void) {
 #endif
 }
 
-void saveContainerNodes(Common::OutSaveFile *out) {
+void saveContainerNodes(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving Container Nodes");
 
 	int i = 0;
 	int16 numNodes = 0;
-	int32 archiveBufSize;
 
 	//  Make sure there are no pending container view actions
 	g_vm->_containerList->doDeferredActions();
 
-	archiveBufSize = sizeof(numNodes);
-
 	//  Count the number of nodes to save
 	for (Common::List<ContainerNode *>::iterator it = g_vm->_containerList->_list.begin(); it != g_vm->_containerList->_list.end(); ++it) {
 		ContainerNode *n = *it;
@@ -1804,12 +1801,8 @@ void saveContainerNodes(Common::OutSaveFile *out) {
 			numNodes++;
 	}
 
-	//  Compute size of archive buffer
-	archiveBufSize += numNodes * ContainerNode::archiveSize();
-
-	out->write("CONT", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("CONT", 4);
+	CHUNK_BEGIN;
 	//  Store the number of nodes to save
 	out->writeSint16LE(numNodes);
 
@@ -1824,6 +1817,7 @@ void saveContainerNodes(Common::OutSaveFile *out) {
 			n->write(out);
 		}
 	}
+	CHUNK_END;
 }
 
 void loadContainerNodes(Common::InSaveFile *in) {
diff --git a/engines/saga2/contain.h b/engines/saga2/contain.h
index f0a1519cbc..5d1615fb61 100644
--- a/engines/saga2/contain.h
+++ b/engines/saga2/contain.h
@@ -451,7 +451,7 @@ public:
 	}
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Hide or show this container window.
 	void hide(void);
@@ -542,7 +542,7 @@ void initContainers(void);
 void cleanupContainers(void);
 
 void initContainerNodes(void);
-void saveContainerNodes(Common::OutSaveFile *out);
+void saveContainerNodes(Common::OutSaveFile *outS);
 void loadContainerNodes(Common::InSaveFile *in);
 void cleanupContainerNodes(void);
 
diff --git a/engines/saga2/magic.h b/engines/saga2/magic.h
index b7a29f26cf..1756f4659f 100644
--- a/engines/saga2/magic.h
+++ b/engines/saga2/magic.h
@@ -100,7 +100,7 @@ bool implementSpell(GameObject *enactor, GameObject *target, SkillProto *spell);
 
 // spell saving & loading
 void initSpellState(void);
-void saveSpellState(Common::OutSaveFile *out);
+void saveSpellState(Common::OutSaveFile *outS);
 void loadSpellState(Common::InSaveFile *in);
 void cleanupSpellState(void);
 
diff --git a/engines/saga2/motion.cpp b/engines/saga2/motion.cpp
index 814aa9f42e..758ec060db 100644
--- a/engines/saga2/motion.cpp
+++ b/engines/saga2/motion.cpp
@@ -384,7 +384,7 @@ int32 MotionTaskList::archiveSize(void) {
 	return size;
 }
 
-void MotionTaskList::write(Common::OutSaveFile *out) {
+void MotionTaskList::write(Common::MemoryWriteStreamDynamic *out) {
 	int16 motionTaskCount = _list.size();
 
 	//  Store the motion task count
@@ -825,7 +825,7 @@ int32 MotionTask::archiveSize(void) {
 	return size;
 }
 
-void MotionTask::write(Common::OutSaveFile *out) {
+void MotionTask::write(Common::MemoryWriteStreamDynamic *out) {
 	ObjectID    objectID;
 
 	//  Store the motion type and previous motion type
@@ -4809,17 +4809,13 @@ void initMotionTasks(void) {
 	//new (g_vm->_mTaskList) MotionTaskList;
 }
 
-void saveMotionTasks(Common::OutSaveFile *out) {
+void saveMotionTasks(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving MotionTasks");
 
-	int32   archiveBufSize;
-
-	archiveBufSize = g_vm->_mTaskList->archiveSize();
-
-	out->write("MOTN", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("MOTN", 4);
+	CHUNK_BEGIN;
 	g_vm->_mTaskList->write(out);
+	CHUNK_END;
 }
 
 void loadMotionTasks(Common::InSaveFile *in, int32 chunkSize) {
diff --git a/engines/saga2/motion.h b/engines/saga2/motion.h
index 54b99e500d..56196a8b00 100644
--- a/engines/saga2/motion.h
+++ b/engines/saga2/motion.h
@@ -263,7 +263,7 @@ private:
 	//  Return the number of bytes needed to archive this MotionTask
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	// motion task is finished.
 	void remove(int16 returnVal = motionInterrupted);
@@ -551,7 +551,7 @@ public:
 	//  in a buffer
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Cleanup the motion tasks
 	void cleanup(void);
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 7198613ba1..dfe26f68cf 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -42,6 +42,7 @@
 #include "saga2/spellbuk.h"
 #include "saga2/tilevect.h"
 #include "saga2/dispnode.h"
+#include "saga2/saveload.h"
 
 #include "saga2/methods.r"                    // generated by SAGA
 #include "saga2/pclass.r"
@@ -233,13 +234,15 @@ GameObject::GameObject(const ResourceGameObject &res) {
 GameObject::GameObject(Common::InSaveFile *in) {
 	debugC(3, kDebugSaveload, "Loading object %d", thisID());
 
-	read(in);
+	read(in, false);
 }
 
-void GameObject::read(Common::InSaveFile *in) {
+void GameObject::read(Common::InSaveFile *in, bool expandProto) {
 	debugC(3, kDebugSaveload, "Loading object %d", thisID());
 
 	int16 pInd = in->readSint16LE();
+	if (expandProto)
+		in->readSint16LE();
 	//  Convert the protoype index into an object proto pointer
 	prototype = pInd != -1
 	            ?   &objectProtos[pInd]
@@ -262,6 +265,22 @@ void GameObject::read(Common::InSaveFile *in) {
 	memset(&_data.reserved, 0, sizeof(_data.reserved));
 
 	_data.obj = this;
+
+	debugC(4, kDebugSaveload, "... protoIndex = %d", pInd);
+	debugC(4, kDebugSaveload, "... _data.location = (%d, %d, %d)",
+	       _data.location.u, _data.location.v, _data.location.z);
+	debugC(4, kDebugSaveload, "... _data.nameIndex = %d", _data.nameIndex);
+	debugC(4, kDebugSaveload, "... _data.parentID = %d", _data.parentID);
+	debugC(4, kDebugSaveload, "... _data.siblingID = %d", _data.siblingID);
+	debugC(4, kDebugSaveload, "... _data.childID = %d", _data.childID);
+	debugC(4, kDebugSaveload, "... _data.script = %d", _data.script);
+	debugC(4, kDebugSaveload, "... _data.objectFlags = %d", _data.objectFlags);
+	debugC(4, kDebugSaveload, "... _data.hitPoints = %d", _data.hitPoints);
+	debugC(4, kDebugSaveload, "... _data.bParam = %d", _data.bParam);
+	debugC(4, kDebugSaveload, "... _data.massCount = %d", _data.massCount);
+	debugC(4, kDebugSaveload, "... _data.missileFacing = %d", _data.missileFacing);
+	debugC(4, kDebugSaveload, "... _data.currentTAG.val = %d", _data.currentTAG.val);
+	debugC(4, kDebugSaveload, "... _data.sightCtr = %d", _data.sightCtr);
 }
 
 //-----------------------------------------------------------------------
@@ -272,12 +291,14 @@ int32 GameObject::archiveSize(void) {
 	return sizeof(GameObjectArchive);
 }
 
-void GameObject::write(Common::OutSaveFile *out) {
+void GameObject::write(Common::MemoryWriteStreamDynamic *out, bool expandProto) {
 	debugC(2, kDebugSaveload, "Saving object %d", thisID());
 
 	warning("STUB: GameObject::write: Pointer arithmetic");
 	int16 pInd = prototype != nullptr ? prototype - objectProtos : -1;
 	out->writeSint16LE(pInd);
+	if (expandProto)
+		out->writeSint16LE(0);
 	_data.location.write(out);
 	out->writeUint16LE(_data.nameIndex);
 	out->writeUint16LE(_data.parentID);
@@ -2681,14 +2702,14 @@ void initTempActorCount(void) {
 		tempActorCount[i] = 0;
 }
 
-void saveTempActorCount(Common::OutSaveFile *out) {
+void saveTempActorCount(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving TempActorCount");
 
-	out->write("ACNT", 4);
-	out->writeUint32LE(actorProtoCount * sizeof(uint16));
-
+	outS->write("ACNT", 4);
+	CHUNK_BEGIN;
 	for (int i = 0; i < actorProtoCount; ++i)
 		out->writeUint16LE(tempActorCount[i]);
+	CHUNK_END;
 }
 
 void loadTempActorCount(Common::InSaveFile *in, int32 chunkSize) {
@@ -2755,22 +2776,11 @@ void initWorlds(void) {
 	setCurrentMap(currentWorld->mapNum);
 }
 
-void saveWorlds(Common::OutSaveFile *out) {
+void saveWorlds(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving worlds");
 
-	int32 archiveBufSize = 0;
-
-	//  Accumulate size of archive buffer
-
-	//  Add size of the current world's ID
-	archiveBufSize += sizeof(ObjectID);
-
-	for (int i = 0; i < worldCount; i++)
-		archiveBufSize += worldList[i].archiveSize();
-
-	out->write("WRLD", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("WRLD", 4);
+	CHUNK_BEGIN;
 	out->writeUint16LE(currentWorld->thisID());
 
 	debugC(3, kDebugSaveload, "... currentWorld->thisID() = %d", currentWorld->thisID());
@@ -2792,6 +2802,7 @@ void saveWorlds(Common::OutSaveFile *out) {
 			debugC(4, kDebugSaveload, "...... sectArray[%d].childID = %d", j, sectArray[j].childID);
 		}
 	}
+	CHUNK_END;
 }
 
 void loadWorlds(Common::InSaveFile *in) {
@@ -2957,25 +2968,20 @@ void initObjects(void) {
 #endif
 }
 
-void saveObjects(Common::OutSaveFile *out) {
-	int32 archiveBufSize;
-
-	archiveBufSize = sizeof(objectLimboCount)
-	                 +   sizeof(actorLimboCount)
-	                 +   sizeof(importantLimboCount)
-	                 +   objectListSize;
-
-	out->write("OBJS", 4);
-	out->writeUint32LE(archiveBufSize);
-
+void saveObjects(Common::OutSaveFile *outS) {
+	outS->write("OBJS", 4);
+	CHUNK_BEGIN;
 	//  Store the limbo counts
 	out->writeSint16LE(objectLimboCount);
 	out->writeSint16LE(actorLimboCount);
 	out->writeSint16LE(importantLimboCount);
 
 	//  Store the object list
-	for (int i = 0; i < objectCount; i++)
-		objectList[i].write(out);
+	for (int i = 0; i < objectCount; i++) {
+		objectList[i].write(out, true);
+		out->writeUint16LE(0); // reserved bits
+	}
+	CHUNK_END;
 }
 
 void loadObjects(Common::InSaveFile *in) {
@@ -2988,8 +2994,10 @@ void loadObjects(Common::InSaveFile *in) {
 	if (objectList == nullptr)
 		error("Unable to load Objects");
 
-	for (int i = 0; i < objectCount; i++)
-		objectList[i].read(in);
+	for (int i = 0; i < objectCount; i++) {
+		objectList[i].read(in, true);
+		in->readUint16LE();
+	}
 }
 
 //-------------------------------------------------------------------
@@ -3065,7 +3073,7 @@ void Sector::read(Common::InSaveFile *in) {
 	childID = in->readUint16LE();
 }
 
-void Sector::write(Common::OutSaveFile *out) {
+void Sector::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeUint16LE(activationCount);
 	out->writeUint16LE(childID);
 }
@@ -3091,7 +3099,7 @@ void ActiveRegion::read(Common::InSaveFile *in) {
 	       region.min.u, region.min.v, region.min.z, region.max.u, region.max.v, region.max.z);
 }
 
-void ActiveRegion::write(Common::OutSaveFile *out) {
+void ActiveRegion::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeUint16LE(anchor);
 	anchorLoc.write(out);
 	out->writeUint16LE(worldID);
@@ -3251,18 +3259,16 @@ void initActiveRegions(void) {
 	}
 }
 
-void saveActiveRegions(Common::OutSaveFile *out) {
+void saveActiveRegions(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving ActiveRegions");
 
-	out->write("AREG", 4);
-
-	const int saveSize = ActiveRegion::kActiveRegionSize * playerActors;
-	out->writeUint32LE(saveSize);
-
+	outS->write("AREG", 4);
+	CHUNK_BEGIN;
 	for (int i = 0; i < playerActors; ++i) {
 		debugC(3, kDebugSaveload, "Saving Active Region %d", i);
 		activeRegionList[i].write(out);
 	}
+	CHUNK_END;
 }
 
 void loadActiveRegions(Common::InSaveFile *in) {
diff --git a/engines/saga2/objects.h b/engines/saga2/objects.h
index bf33d32903..387c345147 100644
--- a/engines/saga2/objects.h
+++ b/engines/saga2/objects.h
@@ -113,7 +113,7 @@ struct ObjectData {
 #include "common/pack-end.h"
 
 void     initActors(void);
-void     saveActors(Common::OutSaveFile *out);
+void     saveActors(Common::OutSaveFile *outS);
 void     loadActors(Common::InSaveFile *in);
 void     cleanupActors(void);
 class GameObject {
@@ -181,13 +181,13 @@ public:
 
 	GameObject(Common::InSaveFile *in);
 
-	void read(Common::InSaveFile *in);
+	void read(Common::InSaveFile *in, bool expandProto);
 
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out, bool expandProto);
 
 	//  returns the address of the object based on the ID, and this
 	//  includes accounting for actors.
@@ -736,7 +736,7 @@ public:
 	void activate(void);
 	void deactivate(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 	void read(Common::InSaveFile *in);
 };
 
@@ -855,7 +855,7 @@ public:
 	void update(void);
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Return the current region in tile point coords
 	TileRegion getRegion(void) {
@@ -882,7 +882,7 @@ void updateActiveRegions(void);
 ActiveRegion *getActiveRegion(PlayerActorID id);
 
 void initActiveRegions(void);
-void saveActiveRegions(Common::OutSaveFile *out);
+void saveActiveRegions(Common::OutSaveFile *outS);
 void loadActiveRegions(Common::InSaveFile *in);
 inline void cleanupActiveRegions(void) {}
 
@@ -1386,7 +1386,7 @@ void cleanupObjectSoundFXTable(void);
 void initTempActorCount(void);
 
 //  Save the array of temp actor counts
-void saveTempActorCount(Common::OutSaveFile *out);
+void saveTempActorCount(Common::OutSaveFile *outS);
 
 //  Load the array of temp actor counts
 void loadTempActorCount(Common::InSaveFile *in, int32 chunkSize);
@@ -1407,7 +1407,7 @@ uint16 getTempActorCount(uint16 protoNum);
 void initWorlds(void);
 
 //  Save worlds to the save file
-void saveWorlds(Common::OutSaveFile *out);
+void saveWorlds(Common::OutSaveFile *outS);
 
 //  Load worlds from the save file
 void loadWorlds(Common::InSaveFile *in);
@@ -1419,7 +1419,7 @@ void cleanupWorlds(void);
 void initObjects(void);
 
 //  Save the objects to the save file
-void saveObjects(Common::OutSaveFile *out);
+void saveObjects(Common::OutSaveFile *outS);
 
 //  Load the objects from the save file
 void loadObjects(Common::InSaveFile *in);
diff --git a/engines/saga2/patrol.cpp b/engines/saga2/patrol.cpp
index 4e53bbddd6..fcad4bf78c 100644
--- a/engines/saga2/patrol.cpp
+++ b/engines/saga2/patrol.cpp
@@ -110,7 +110,7 @@ void PatrolRouteIterator::read(Common::InSaveFile *in) {
 	_flags = in->readByte();
 }
 
-void PatrolRouteIterator::write(Common::OutSaveFile *out) const {
+void PatrolRouteIterator::write(Common::MemoryWriteStreamDynamic *out) const {
 	out->writeSint16LE(_routeNo);
 	out->writeSint16LE(_vertexNo);
 	out->writeByte(_mapNum);
diff --git a/engines/saga2/patrol.h b/engines/saga2/patrol.h
index 178d55fc64..254860f2ac 100644
--- a/engines/saga2/patrol.h
+++ b/engines/saga2/patrol.h
@@ -125,7 +125,7 @@ public:
 	PatrolRouteIterator(uint8 map, int16 rte, uint8 type, int16 startingPoint);
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 private:
 	void increment(void);		// Increment waypoint index
diff --git a/engines/saga2/player.cpp b/engines/saga2/player.cpp
index 0a2f37cfb4..7e9798bd32 100644
--- a/engines/saga2/player.cpp
+++ b/engines/saga2/player.cpp
@@ -935,14 +935,11 @@ void initPlayerActors(void) {
 	readyContainerSetup();
 }
 
-void savePlayerActors(Common::OutSaveFile *out) {
+void savePlayerActors(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving PlayerActors");
 
-	const int archiveSize = playerActors * 38;
-
-	out->write("PLYR", 4);
-	out->writeUint32LE(archiveSize);
-
+	outS->write("PLYR", 4);
+	CHUNK_BEGIN;
 	for (int i = 0; i < playerActors; i++) {
 		debugC(3, kDebugSaveload, "Saving PlayerActor %d", i);
 
@@ -978,6 +975,7 @@ void savePlayerActors(Common::OutSaveFile *out) {
 		debugC(4, kDebugSaveload, "... playerList[%d].vitalityMemory = %d", i, p->vitalityMemory);
 		debugC(4, kDebugSaveload, "... playerList[%d].notifiedOfAttack = %d", i, p->notifiedOfAttack);
 	}
+	CHUNK_END;
 }
 
 void loadPlayerActors(Common::InSaveFile *in) {
diff --git a/engines/saga2/rect.cpp b/engines/saga2/rect.cpp
index 1617ccc587..61eee99d3b 100644
--- a/engines/saga2/rect.cpp
+++ b/engines/saga2/rect.cpp
@@ -24,7 +24,6 @@
  *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
  */
 
-#include "common/savefile.h"
 #include "saga2/saga2.h"
 #include "saga2/rect.h"
 
@@ -35,7 +34,7 @@ void Point16::load(Common::SeekableReadStream *stream) {
 	y = stream->readSint16LE();
 }
 
-void Point16::write(Common::OutSaveFile *out) {
+void Point16::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeSint16LE(x);
 	out->writeSint16LE(y);
 }
@@ -47,7 +46,7 @@ void Rect16::read(Common::InSaveFile *in) {
 	height = in->readSint16LE();
 }
 
-void Rect16::write(Common::OutSaveFile *out) {
+void Rect16::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeSint16LE(x);
 	out->writeSint16LE(y);
 	out->writeSint16LE(width);
diff --git a/engines/saga2/rect.h b/engines/saga2/rect.h
index 336797d8e0..43db78cdc1 100644
--- a/engines/saga2/rect.h
+++ b/engines/saga2/rect.h
@@ -27,6 +27,8 @@
 #ifndef SAGA2_RECT_H
 #define SAGA2_RECT_H
 
+#include "common/memstream.h"
+
 namespace Saga2 {
 
 struct StaticPoint16 {
@@ -55,7 +57,7 @@ public:
 	}
 
 	void load(Common::SeekableReadStream *stream);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	// Point16 operators
 	friend Point16 operator+ (Point16 a, Point16 b) {
@@ -315,7 +317,7 @@ public:
 	}
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Rect16 operators
 
diff --git a/engines/saga2/speech.cpp b/engines/saga2/speech.cpp
index f1717884cf..52c32bf25e 100644
--- a/engines/saga2/speech.cpp
+++ b/engines/saga2/speech.cpp
@@ -195,7 +195,7 @@ int32 Speech::archiveSize(void) {
 	            +   sizeof(char) * charCount;
 }
 
-void Speech::write(Common::OutSaveFile *out) {
+void Speech::write(Common::MemoryWriteStreamDynamic *out) {
 	//  Store the sample count and character count
 	out->writeSint16LE(sampleCount);
 	out->writeSint16LE(charCount);
@@ -968,7 +968,7 @@ int32 SpeechTaskList::archiveSize(void) {
 	return size;
 }
 
-void SpeechTaskList::write(Common::OutSaveFile *out) {
+void SpeechTaskList::write(Common::MemoryWriteStreamDynamic *out) {
 	int i = 0;
 	int16 count = 0;
 
@@ -1142,17 +1142,13 @@ void initSpeechTasks(void) {
 	new (&speechList) SpeechTaskList;
 }
 
-void saveSpeechTasks(Common::OutSaveFile *out) {
+void saveSpeechTasks(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving Speech Tasks");
 
-	int32 archiveBufSize;
-
-	archiveBufSize = speechList.archiveSize();
-
-	out->write("SPCH", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("SPCH", 4);
+	CHUNK_BEGIN;
 	speechList.write(out);
+	CHUNK_END;
 }
 
 void loadSpeechTasks(Common::InSaveFile *in, int32 chunkSize) {
diff --git a/engines/saga2/speech.h b/engines/saga2/speech.h
index be127bc6fd..22c7c7a126 100644
--- a/engines/saga2/speech.h
+++ b/engines/saga2/speech.h
@@ -111,8 +111,6 @@ public:
 
 private:
 	//  Reconstruct this SpeechTask from an archive buffer
-	void *restore(void *buf);
-
 	void read(Common::InSaveFile *in);
 
 	//  Return the number of bytes needed to archive this SpeechTask
@@ -121,7 +119,7 @@ private:
 	//  Archive this SpeechTask in a buffer
 	void *archive(void *buf);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	bool setupActive(void);                  // render speech into temp image
 	bool displayText(void);
@@ -197,7 +195,7 @@ public:
 	//  Create an archive of the speech tasks in an archive buffer
 	void *archive(void *buf);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Cleanup the speech tasks
 	void cleanup(void);
@@ -232,7 +230,7 @@ extern SpeechTaskList &speechList;
 void initSpeechTasks(void);
 
 //  Save the speech tasks in a save file
-void saveSpeechTasks(Common::OutSaveFile *out);
+void saveSpeechTasks(Common::OutSaveFile *outS);
 void loadSpeechTasks(Common::InSaveFile *in, int32 chunkSize);
 
 //  Cleanup the speech task list
diff --git a/engines/saga2/spellio.cpp b/engines/saga2/spellio.cpp
index fb3dc9fc86..0935f0cc31 100644
--- a/engines/saga2/spellio.cpp
+++ b/engines/saga2/spellio.cpp
@@ -33,6 +33,7 @@
 #include "saga2/rect.h"
 #include "saga2/spellio.h"
 #include "saga2/spelshow.h"
+#include "saga2/saveload.h"
 
 namespace Saga2 {
 
@@ -213,10 +214,9 @@ void SpellStuff::addEffect(ResourceSpellEffect *rse) {
 void initSpellState(void) {
 }
 
-void saveSpellState(Common::OutSaveFile *out) {
+void saveSpellState(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving SpellState");
-
-	activeSpells.write(out);
+	activeSpells.write(outS);
 }
 
 void loadSpellState(Common::InSaveFile *in) {
@@ -294,7 +294,7 @@ void StorageSpellTarget::read(Common::InSaveFile *in) {
 	tag = ActiveItemID(tagID);
 }
 
-void StorageSpellTarget::write(Common::OutSaveFile *out) {
+void StorageSpellTarget::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeSint16LE(type);
 	loc.write(out);
 	out->writeUint16LE(obj);
@@ -320,7 +320,7 @@ void StorageSpellInstance::read(Common::InSaveFile *in) {
 	eListSize = in->readSint16LE();
 }
 
-void StorageSpellInstance::write(Common::OutSaveFile *out) {
+void StorageSpellInstance::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeSint32LE(implementAge);
 	out->writeUint16LE(effect);
 	warning("StorageSpellInstance::write: Check SpellID size");
@@ -377,12 +377,9 @@ size_t SpellDisplayList::saveSize(void) {
 	return total;
 }
 
-void SpellDisplayList::write(Common::OutSaveFile *out) {
-	size_t chunkSize = saveSize();
-
-	out->write("SPEL", 4);
-	out->writeUint32LE(chunkSize);
-
+void SpellDisplayList::write(Common::OutSaveFile *outS) {
+	outS->write("SPEL", 4);
+	CHUNK_BEGIN;
 	out->writeUint16LE(count);
 
 	debugC(3, kDebugSaveload, "... count = %d", count);
@@ -395,6 +392,7 @@ void SpellDisplayList::write(Common::OutSaveFile *out) {
 			spells[i]->writeEffect(out);
 		}
 	}
+	CHUNK_END;
 }
 
 void SpellDisplayList::read(Common::InSaveFile *in) {
@@ -440,7 +438,7 @@ size_t SpellInstance::saveSize(void) {
 	return total;
 }
 
-void SpellInstance::writeEffect(Common::OutSaveFile *out) {
+void SpellInstance::writeEffect(Common::MemoryWriteStreamDynamic *out) {
 	if (eList.count > 0 && !(maxAge > 0 && (age + 1) > maxAge))
 		for (int32 i = 0; i < eList.count; i++) {
 			StorageEffectron se = StorageEffectron(*eList.displayList[i].efx);
@@ -520,7 +518,7 @@ void StorageEffectron::read(Common::InSaveFile *in) {
 	age = in->readSint32LE();
 }
 
-void StorageEffectron::write(Common::OutSaveFile *out) {
+void StorageEffectron::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeUint32LE(flags);
 	size.write(out);
 	hitBox.write(out);
diff --git a/engines/saga2/spellio.h b/engines/saga2/spellio.h
index 5d9c7bca4e..30b2f88d1d 100644
--- a/engines/saga2/spellio.h
+++ b/engines/saga2/spellio.h
@@ -124,7 +124,7 @@ struct StorageSpellTarget {
 	StorageSpellTarget(SpellTarget &st);
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 };
 
 //-------------------------------------------------------------------
@@ -148,7 +148,7 @@ struct StorageSpellInstance {
 	StorageSpellInstance(SpellInstance &si);
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 };
 
 //-------------------------------------------------------------------
@@ -181,7 +181,7 @@ struct StorageEffectron {
 	StorageEffectron(Effectron &e);
 
 	void read(Common::InSaveFile *in);
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 };
 
 } // end of namespace Saga2
diff --git a/engines/saga2/spelshow.h b/engines/saga2/spelshow.h
index 9222048443..57f1565f1f 100644
--- a/engines/saga2/spelshow.h
+++ b/engines/saga2/spelshow.h
@@ -316,7 +316,7 @@ public:
 	void init(void);
 	void initEffect(TilePoint);
 	void readEffect(Common::InSaveFile *in, uint16 eListSize);
-	void writeEffect(Common::OutSaveFile *out);
+	void writeEffect(Common::MemoryWriteStreamDynamic *out);
 	void termEffect(void);
 	size_t saveSize(void);
 
@@ -349,7 +349,7 @@ public :
 	void buildList(void);
 	void updateStates(int32 deltaTime);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::OutSaveFile *outD);
 	void read(Common::InSaveFile *in);
 	void wipe(void);
 	size_t saveSize(void);
diff --git a/engines/saga2/sprite.cpp b/engines/saga2/sprite.cpp
index 8ca66fcd76..54f13021bc 100644
--- a/engines/saga2/sprite.cpp
+++ b/engines/saga2/sprite.cpp
@@ -614,7 +614,7 @@ void ActorPose::load(Common::SeekableReadStream *stream) {
 	rightObjectOffset.load(stream);
 }
 
-void ActorPose::write(Common::OutSaveFile *out) {
+void ActorPose::write(Common::MemoryWriteStreamDynamic *out) {
 	out->writeUint16LE(flags);
 
 	out->writeByte(actorFrameIndex);
diff --git a/engines/saga2/sprite.h b/engines/saga2/sprite.h
index 6594450cba..42296c5af1 100644
--- a/engines/saga2/sprite.h
+++ b/engines/saga2/sprite.h
@@ -135,7 +135,7 @@ struct ActorPose {
 	ActorPose(Common::SeekableReadStream *stream);
 	void load(Common::SeekableReadStream *stream);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 };
 
 //  A choreographed sequence of frames
diff --git a/engines/saga2/target.cpp b/engines/saga2/target.cpp
index 460f79922e..8f33438360 100644
--- a/engines/saga2/target.cpp
+++ b/engines/saga2/target.cpp
@@ -85,7 +85,7 @@ void readTarget(void *mem, Common::InSaveFile *in) {
 	}
 }
 
-void writeTarget(const Target *t, Common::OutSaveFile *out) {
+void writeTarget(const Target *t, Common::MemoryWriteStreamDynamic *out) {
 	out->writeSint16LE(t->getType());
 
 	t->write(out);
@@ -164,7 +164,7 @@ inline int32 LocationTarget::archiveSize(void) const {
 	return sizeof(loc);
 }
 
-void LocationTarget::write(Common::OutSaveFile *out) const {
+void LocationTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the target location
 	loc.write(out);
 }
@@ -348,7 +348,7 @@ inline int32 SpecificTileTarget::archiveSize(void) const {
 	return sizeof(tile);
 }
 
-void SpecificTileTarget::write(Common::OutSaveFile *out) const {
+void SpecificTileTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the tile ID
 	out->writeUint16LE(tile);
 }
@@ -408,7 +408,7 @@ inline int32 TilePropertyTarget::archiveSize(void) const {
 	return sizeof(tileProp);
 }
 
-void TilePropertyTarget::write(Common::OutSaveFile *out) const {
+void TilePropertyTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	out->writeSint16LE(tileProp);
 }
 
@@ -577,7 +577,7 @@ inline int32 SpecificMetaTileTarget::archiveSize(void) const {
 	return sizeof(MetaTileID);
 }
 
-void SpecificMetaTileTarget::write(Common::OutSaveFile *out) const {
+void SpecificMetaTileTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the MetaTileID
 	out->writeSint16LE(meta.map);
 	out->writeSint16LE(meta.index);
@@ -641,7 +641,7 @@ inline int32 MetaTilePropertyTarget::archiveSize(void) const {
 	return sizeof(metaProp);
 }
 
-void MetaTilePropertyTarget::write(Common::OutSaveFile *out) const {
+void MetaTilePropertyTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the MetaTilePropertyID
 	out->writeSint16LE(metaProp);
 }
@@ -916,7 +916,7 @@ inline int32 SpecificObjectTarget::archiveSize(void) const {
 	return sizeof(obj);
 }
 
-void SpecificObjectTarget::write(Common::OutSaveFile *out) const {
+void SpecificObjectTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the ObjectID
 	out->writeUint16LE(obj);
 }
@@ -1067,7 +1067,7 @@ inline int32 ObjectPropertyTarget::archiveSize(void) const {
 	return sizeof(objProp);
 }
 
-void ObjectPropertyTarget::write(Common::OutSaveFile *out) const {
+void ObjectPropertyTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the ObjectPropertyID
 	out->writeSint16LE(objProp);
 }
@@ -1166,7 +1166,7 @@ inline int32 SpecificActorTarget::archiveSize(void) const {
 	return sizeof(ObjectID);
 }
 
-void SpecificActorTarget::write(Common::OutSaveFile *out) const {
+void SpecificActorTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Convert the actor pointer to an actor ID;
 	ObjectID actorID = a != NULL ? a->thisID() : Nothing;
 
@@ -1350,7 +1350,7 @@ inline int32 ActorPropertyTarget::archiveSize(void) const {
 	return sizeof(actorProp);
 }
 
-void ActorPropertyTarget::write(Common::OutSaveFile *out) const {
+void ActorPropertyTarget::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Store the ActorPropertyID
 	out->writeSint16LE(actorProp);
 }
diff --git a/engines/saga2/target.h b/engines/saga2/target.h
index 3887b8d9eb..267bae36e6 100644
--- a/engines/saga2/target.h
+++ b/engines/saga2/target.h
@@ -57,7 +57,7 @@ class Target;
 void deleteTarget(Target *t);
 
 void readTarget(void *mem, Common::InSaveFile *in);
-void writeTarget(const Target *t, Common::OutSaveFile *out);
+void writeTarget(const Target *t, Common::MemoryWriteStreamDynamic *out);
 int32 targetArchiveSize(const Target *t);
 
 /* ===================================================================== *
@@ -142,7 +142,7 @@ public:
 	//  a buffer
 	virtual int32 archiveSize(void) const = 0;
 
-	virtual void write(Common::OutSaveFile *out) const = 0;
+	virtual void write(Common::MemoryWriteStreamDynamic *out) const = 0;
 
 	//  Return an integer representing the type of target
 	virtual int16 getType(void) const = 0;
@@ -194,7 +194,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -256,7 +256,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -290,7 +290,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -342,7 +342,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -378,7 +378,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -458,7 +458,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -509,7 +509,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -564,7 +564,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
@@ -623,7 +623,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of target
 	int16 getType(void) const;
diff --git a/engines/saga2/task.cpp b/engines/saga2/task.cpp
index 336a77c585..beaedf2d74 100644
--- a/engines/saga2/task.cpp
+++ b/engines/saga2/task.cpp
@@ -49,7 +49,7 @@ void readTask(TaskID id, Common::InSaveFile *in);
 //  specified Task
 int32 taskArchiveSize(Task *t);
 
-void writeTask(Task *t, Common::OutSaveFile *out);
+void writeTask(Task *t, Common::MemoryWriteStreamDynamic *out);
 
 #if DEBUG
 //  Debugging function used to check the integrity of the global task
@@ -116,7 +116,7 @@ public:
 	//  TaskStackList
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Place a TaskStack from the inactive list into the active
 	//  list.
@@ -212,7 +212,7 @@ int32 TaskStackList::archiveSize(void) {
 	return size;
 }
 
-void TaskStackList::write(Common::OutSaveFile *out) {
+void TaskStackList::write(Common::MemoryWriteStreamDynamic *out) {
 	int16 taskStackCount = 0;
 
 	//  Count the active task stacks
@@ -356,17 +356,13 @@ TaskStack *getTaskStackAddress(TaskStackID id) {
 void initTaskStacks(void) {
 }
 
-void saveTaskStacks(Common::OutSaveFile *out) {
+void saveTaskStacks(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving Task Stacks");
 
-	int32 archiveBufSize;
-
-	archiveBufSize = stackList.archiveSize();
-
-	out->write("TSTK", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("TSTK", 4);
+	CHUNK_BEGIN;
 	stackList.write(out);
+	CHUNK_END;
 }
 
 void loadTaskStacks(Common::InSaveFile *in, int32 chunkSize) {
@@ -417,7 +413,7 @@ public:
 	//  in a buffer
 	int32 archiveSize(void);
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	//  Place a Task from the inactive list into the active
 	//  list.
@@ -509,7 +505,7 @@ int32 TaskList::archiveSize(void) {
 	return size;
 }
 
-void TaskList::write(Common::OutSaveFile *out) {
+void TaskList::write(Common::MemoryWriteStreamDynamic *out) {
 	int16 taskCount = 0;
 
 	//  Count the active tasks
@@ -612,17 +608,13 @@ void initTasks(void) {
 	new (&taskList) TaskList;
 }
 
-void saveTasks(Common::OutSaveFile *out) {
+void saveTasks(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving Tasks");
 
-	int32 archiveBufSize;
-
-	archiveBufSize = taskList.archiveSize();
-
-	out->write("TASK", 4);
-	out->writeUint32LE(archiveBufSize);
-
+	outS->write("TASK", 4);
+	CHUNK_BEGIN;
 	taskList.write(out);
+	CHUNK_END;
 }
 
 void loadTasks(Common::InSaveFile *in, int32 chunkSize) {
@@ -736,7 +728,7 @@ int32 taskArchiveSize(Task *t) {
 	            +   t->archiveSize();
 }
 
-void writeTask(Task *t, Common::OutSaveFile *out) {
+void writeTask(Task *t, Common::MemoryWriteStreamDynamic *out) {
 	//  Store the task's type
 	out->writeSint16LE(t->getType());
 
@@ -770,7 +762,7 @@ inline int32 Task::archiveSize(void) const {
 	return sizeof(TaskStackID);      //  stack's ID
 }
 
-void Task::write(Common::OutSaveFile *out) const {
+void Task::write(Common::MemoryWriteStreamDynamic *out) const {
 	out->writeSint16LE(getTaskStackID(stack));
 }
 
@@ -796,7 +788,7 @@ int32 WanderTask::archiveSize(void) const {
 	            +   sizeof(counter);
 }
 
-void WanderTask::write(Common::OutSaveFile *out) const {
+void WanderTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	Task::write(out);
 
@@ -927,7 +919,7 @@ inline int32 TetheredWanderTask::archiveSize(void) const {
 	            +   sizeof(TaskID);      //  gotoTether ID
 }
 
-void TetheredWanderTask::write(Common::OutSaveFile *out) const {
+void TetheredWanderTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving TetheredWanderTask");
 
 	//  Let the base class archive its data
@@ -1090,7 +1082,7 @@ inline int32 GotoTask::archiveSize(void) const {
 	            +   sizeof(prevRunState);
 }
 
-void GotoTask::write(Common::OutSaveFile *out) const {
+void GotoTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	Task::write(out);
 
@@ -1249,7 +1241,7 @@ inline int32 GotoLocationTask::archiveSize(void) const {
 	            +   sizeof(runThreshold);
 }
 
-void GotoLocationTask::write(Common::OutSaveFile *out) const {
+void GotoLocationTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GotoLocationTask");
 
 	//  Let the base class archive its data
@@ -1340,7 +1332,7 @@ inline int32 GotoRegionTask::archiveSize(void) const {
 	            +   sizeof(regionMaxV);
 }
 
-void GotoRegionTask::write(Common::OutSaveFile *out) const {
+void GotoRegionTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GotoRegionTask");
 
 	//  Let the base class archive its data
@@ -1430,7 +1422,7 @@ inline int32 GotoObjectTargetTask::archiveSize(void) const {
 	            +   sizeof(lastKnownLoc);
 }
 
-void GotoObjectTargetTask::write(Common::OutSaveFile *out) const {
+void GotoObjectTargetTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	GotoTask::write(out);
 
@@ -1556,7 +1548,7 @@ inline int32 GotoObjectTask::archiveSize(void) const {
 	return GotoObjectTargetTask::archiveSize() + sizeof(ObjectID);
 }
 
-void GotoObjectTask::write(Common::OutSaveFile *out) const {
+void GotoObjectTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GotoObjectTask");
 
 	//  Let the base class archive its data
@@ -1623,7 +1615,7 @@ inline int32 GotoActorTask::archiveSize(void) const {
 	return GotoObjectTargetTask::archiveSize() + sizeof(ObjectID);
 }
 
-void GotoActorTask::write(Common::OutSaveFile *out) const {
+void GotoActorTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GotoActorTask");
 
 	//  Let the base class archive its data
@@ -1701,7 +1693,7 @@ inline int32 GoAwayFromTask::archiveSize(void) const {
 	return Task::archiveSize() + sizeof(TaskID) + sizeof(flags);
 }
 
-void GoAwayFromTask::write(Common::OutSaveFile *out) const {
+void GoAwayFromTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	Task::write(out);
 
@@ -1816,7 +1808,7 @@ int32 GoAwayFromObjectTask::archiveSize(void) const {
 	return GoAwayFromTask::archiveSize() + sizeof(ObjectID);
 }
 
-void GoAwayFromObjectTask::write(Common::OutSaveFile *out) const {
+void GoAwayFromObjectTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GoAwayFromObjectTask");
 
 	//  Let the base class archive its data
@@ -1897,7 +1889,7 @@ int32 GoAwayFromActorTask::archiveSize(void) const {
 	return GoAwayFromTask::archiveSize() + targetArchiveSize(getTarget());
 }
 
-void GoAwayFromActorTask::write(Common::OutSaveFile *out) const {
+void GoAwayFromActorTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving GoAwayFromActorTask");
 
 	//  Let the base class archive its data
@@ -1996,7 +1988,7 @@ inline int32 HuntTask::archiveSize(void) const {
 	return size;
 }
 
-void HuntTask::write(Common::OutSaveFile *out) const {
+void HuntTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	Task::write(out);
 
@@ -2154,7 +2146,7 @@ inline int32 HuntLocationTask::archiveSize(void) const {
 	            +   targetArchiveSize(getTarget());
 }
 
-void HuntLocationTask::write(Common::OutSaveFile *out) const {
+void HuntLocationTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	HuntTask::write(out);
 
@@ -2214,7 +2206,7 @@ inline int32 HuntToBeNearLocationTask::archiveSize(void) const {
 	            +   sizeof(targetEvaluateCtr);
 }
 
-void HuntToBeNearLocationTask::write(Common::OutSaveFile *out) const {
+void HuntToBeNearLocationTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToBeNearLocationTask");
 
 	//  Let the base class archive its data
@@ -2329,7 +2321,7 @@ inline int32 HuntObjectTask::archiveSize(void) const {
 	            +   targetArchiveSize(getTarget());
 }
 
-void HuntObjectTask::write(Common::OutSaveFile *out) const {
+void HuntObjectTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	HuntTask::write(out);
 
@@ -2395,7 +2387,7 @@ inline int32 HuntToBeNearObjectTask::archiveSize(void) const {
 	            +   sizeof(targetEvaluateCtr);
 }
 
-void HuntToBeNearObjectTask::write(Common::OutSaveFile *out) const {
+void HuntToBeNearObjectTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToBeNearObjectTask");
 
 	//  Let the base class archive its data
@@ -2525,7 +2517,7 @@ inline int32 HuntToPossessTask::archiveSize(void) const {
 	            +   sizeof(grabFlag);
 }
 
-void HuntToPossessTask::write(Common::OutSaveFile *out) const {
+void HuntToPossessTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToPossessTask");
 
 	//  Let the base class archive its data
@@ -2677,7 +2669,7 @@ inline int32 HuntActorTask::archiveSize(void) const {
 	            +   targetArchiveSize(getTarget());
 }
 
-void HuntActorTask::write(Common::OutSaveFile *out) const {
+void HuntActorTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	//  Let the base class archive its data
 	HuntTask::write(out);
 
@@ -2772,7 +2764,7 @@ inline int32 HuntToBeNearActorTask::archiveSize(void) const {
 	            +   sizeof(targetEvaluateCtr);
 }
 
-void HuntToBeNearActorTask::write(Common::OutSaveFile *out) const {
+void HuntToBeNearActorTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToBeNearActorTask");
 
 	//  Let the base class archive its data
@@ -2990,7 +2982,7 @@ inline int32 HuntToKillTask::archiveSize(void) const {
 	            +   sizeof(flags);
 }
 
-void HuntToKillTask::write(Common::OutSaveFile *out) const {
+void HuntToKillTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToKillTask");
 
 	//  Let the base class archive its data
@@ -3348,7 +3340,7 @@ inline int32 HuntToGiveTask::archiveSize(void) const {
 	            +   sizeof(ObjectID);                //  objToGive ID
 }
 
-void HuntToGiveTask::write(Common::OutSaveFile *out) const {
+void HuntToGiveTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving HuntToGiveTask");
 
 	//  Let base class archive its data
@@ -3499,7 +3491,7 @@ inline int32 BandTask::archiveSize(void) const {
 	            +   sizeof(targetEvaluateCtr);
 }
 
-void BandTask::write(Common::OutSaveFile *out) const {
+void BandTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving BandTask");
 
 	//  Let the base class archive its data
@@ -3882,7 +3874,7 @@ inline int32 FollowPatrolRouteTask::archiveSize(void) const {
 	            +   sizeof(counter);
 }
 
-void FollowPatrolRouteTask::write(Common::OutSaveFile *out) const {
+void FollowPatrolRouteTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving FollowPatrolRouteTask");
 
 	//  Let the base class archive its data
@@ -4065,7 +4057,7 @@ inline int32 AttendTask::archiveSize(void) const {
 }
 
 
-void AttendTask::write(Common::OutSaveFile *out) const {
+void AttendTask::write(Common::MemoryWriteStreamDynamic *out) const {
 	debugC(3, kDebugSaveload, "... Saving AttendTask");
 
 	//  Let the base class archive its data
@@ -4133,7 +4125,7 @@ bool AttendTask::operator == (const Task &t) const {
    TaskStack member functions
  * ===================================================================== */
 
-void TaskStack::write(Common::OutSaveFile *out) {
+void TaskStack::write(Common::MemoryWriteStreamDynamic *out) {
 	//  Store the stack bottom TaskID
 	out->writeSint16LE(stackBottomID);
 
diff --git a/engines/saga2/task.h b/engines/saga2/task.h
index e7c072c07a..da848cade4 100644
--- a/engines/saga2/task.h
+++ b/engines/saga2/task.h
@@ -86,7 +86,7 @@ TaskStack *getTaskStackAddress(TaskStackID id);
 //  Initialize the task stack list
 void initTaskStacks(void);
 
-void saveTaskStacks(Common::OutSaveFile *out);
+void saveTaskStacks(Common::OutSaveFile *outS);
 void loadTaskStacks(Common::InSaveFile *in, int32 chunkSize);
 
 //  Cleanup the task stacks
@@ -108,7 +108,7 @@ Task *getTaskAddress(TaskID id);
 //  Initialize the task list
 void initTasks(void);
 
-void saveTasks(Common::OutSaveFile *out);
+void saveTasks(Common::OutSaveFile *outS);
 void loadTasks(Common::InSaveFile *in, int32 chunkSize);
 
 //  Cleanup the task list
@@ -153,7 +153,7 @@ public:
 	//  in a buffer
 	virtual int32 archiveSize(void) const;
 
-	virtual void write(Common::OutSaveFile *out) const;
+	virtual void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	virtual int16 getType(void) const = 0;
@@ -193,7 +193,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -268,7 +268,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -317,7 +317,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -363,7 +363,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -419,7 +419,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -476,7 +476,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 private:
 	TilePoint destination(void);
@@ -521,7 +521,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -559,7 +559,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -619,7 +619,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -657,7 +657,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -693,7 +693,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -740,7 +740,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -789,7 +789,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 protected:
 	bool targetHasChanged(GotoTask *gotoTarget);
@@ -832,7 +832,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -876,7 +876,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 protected:
 	bool targetHasChanged(GotoTask *gotoTarget);
@@ -921,7 +921,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -975,7 +975,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -1022,7 +1022,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 protected:
 	bool targetHasChanged(GotoTask *gotoTarget);
@@ -1084,7 +1084,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -1150,7 +1150,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -1206,7 +1206,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -1334,7 +1334,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -1462,7 +1462,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 #if DEBUG
 	//  Debugging function used to mark this task and any sub tasks as
@@ -1515,7 +1515,7 @@ public:
 	//  a buffer
 	int32 archiveSize(void) const;
 
-	void write(Common::OutSaveFile *out) const;
+	void write(Common::MemoryWriteStreamDynamic *out) const;
 
 	//  Return an integer representing the type of this task
 	int16 getType(void) const;
@@ -1653,7 +1653,7 @@ public:
 		            +   sizeof(evalRate);
 	}
 
-	void write(Common::OutSaveFile *out);
+	void write(Common::MemoryWriteStreamDynamic *out);
 
 	void read(Common::InSaveFile *in);
 
diff --git a/engines/saga2/tcoords.h b/engines/saga2/tcoords.h
index acb84a899e..d2a6716ab9 100644
--- a/engines/saga2/tcoords.h
+++ b/engines/saga2/tcoords.h
@@ -28,6 +28,7 @@
 #define SAGA2_TCOORDS_H
 
 #include "common/savefile.h"
+#include "common/memstream.h"
 
 namespace Saga2 {
 
@@ -150,7 +151,7 @@ struct TilePoint {
 		z = stream->readSint16LE();
 	}
 
-	void write(Common::OutSaveFile *out) const {
+	void write(Common::MemoryWriteStreamDynamic *out) const {
 		out->writeSint16LE(u);
 		out->writeSint16LE(v);
 		out->writeSint16LE(z);
@@ -228,7 +229,7 @@ struct TileRegion {
 		max.load(in);
 	}
 
-	void write(Common::OutSaveFile *out) {
+	void write(Common::MemoryWriteStreamDynamic *out) {
 		min.write(out);
 		max.write(out);
 	}




More information about the Scummvm-git-logs mailing list