aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer2017-08-31 20:52:04 +0200
committerThierry Crozat2018-01-23 02:14:56 +0000
commit23f57ca83fac453afd9f04b619717cc9ddd03a75 (patch)
treeb044a2ab565ff170c87b3c24d16be5dfc3370078 /engines
parent68c52362e562863acbede225989842839be0e9d6 (diff)
downloadscummvm-rg350-23f57ca83fac453afd9f04b619717cc9ddd03a75.tar.gz
scummvm-rg350-23f57ca83fac453afd9f04b619717cc9ddd03a75.tar.bz2
scummvm-rg350-23f57ca83fac453afd9f04b619717cc9ddd03a75.zip
SUPERNOVA: Fixes de-/serialization of game state
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova/rooms.cpp55
-rw-r--r--engines/supernova/state.cpp19
2 files changed, 42 insertions, 32 deletions
diff --git a/engines/supernova/rooms.cpp b/engines/supernova/rooms.cpp
index 8ec0e4af2b..ba6f6538fe 100644
--- a/engines/supernova/rooms.cpp
+++ b/engines/supernova/rooms.cpp
@@ -33,27 +33,28 @@ bool Room::serialize(Common::WriteStream *out) {
if (out->err())
return false;
- out->writeByte(_id);
+ out->writeSint32LE(_id);
for (int i = 0; i < kMaxSection; ++i)
out->writeByte(_shown[i]);
int numObjects = 0;
while ((_objectState[numObjects]._id != INVALIDOBJECT) && (numObjects < kMaxObject))
++numObjects;
- out->writeByte(numObjects);
+ out->writeSint32LE(numObjects);
for (int i = 0; i < numObjects; ++i) {
- out->writeSint16LE(_objectState[i]._name.size() + 1);
- out->writeString(_objectState[i]._name.c_str());
- out->writeSint16LE(_objectState[i]._description.size() + 1);
- out->writeString(_objectState[i]._description.c_str());
+ out->writeUint32LE(_objectState[i]._name.size());
+ out->writeString(_objectState[i]._name);
+ out->writeUint32LE(_objectState[i]._description.size());
+ out->writeString(_objectState[i]._description);
+
out->writeByte(_objectState[i]._roomId);
- out->writeByte(_objectState[i]._id);
- out->writeSint16LE(_objectState[i]._type);
+ out->writeSint32LE(_objectState[i]._id);
+ out->writeSint32LE(_objectState[i]._type);
out->writeByte(_objectState[i]._click);
out->writeByte(_objectState[i]._click2);
out->writeByte(_objectState[i]._section);
- out->writeByte(_objectState[i]._exitRoom);
+ out->writeSint32LE(_objectState[i]._exitRoom);
out->writeByte(_objectState[i]._direction);
}
@@ -66,27 +67,37 @@ bool Room::deserialize(Common::ReadStream *in) {
if (in->err())
return false;
- in->readByte();
+ in->readSint32LE();
for (int i = 0; i < kMaxSection; ++i)
_shown[i] = in->readByte();
- int numObjects = in->readByte();
- int bufferSize = 0;
- char stringBuffer[256];
+ int numObjects = in->readSint32LE();
+ int stringLength = 0;
+ Common::SeekableReadStream *stream = NULL;
for (int i = 0; i < numObjects; ++i) {
- bufferSize = in->readSint16LE();
- in->read(stringBuffer, bufferSize > 256 ? 256 : bufferSize);
- _objectState[i]._name = stringBuffer;
- bufferSize = in->readSint16LE();
- in->read(stringBuffer, bufferSize > 256 ? 256 : bufferSize);
- _objectState[i]._description = stringBuffer;
+ stringLength = in->readUint32LE();
+ if (stringLength) {
+ stream = in->readStream(stringLength);
+ _objectState[i]._name = stream->readLine();
+ } else {
+ _objectState[i]._name = "";
+ }
+
+ stringLength = in->readUint32LE();
+ if (stringLength) {
+ stream = in->readStream(stringLength);
+ _objectState[i]._description = stream->readLine();
+ } else {
+ _objectState[i]._description = "";
+ }
+
_objectState[i]._roomId = in->readByte();
- _objectState[i]._id = static_cast<ObjectID>(in->readByte());
- _objectState[i]._type = static_cast<ObjectType>(in->readSint16LE());
+ _objectState[i]._id = static_cast<ObjectID>(in->readSint32LE());
+ _objectState[i]._type = static_cast<ObjectType>(in->readSint32LE());
_objectState[i]._click = in->readByte();
_objectState[i]._click2 = in->readByte();
_objectState[i]._section = in->readByte();
- _objectState[i]._exitRoom = static_cast<RoomID>(in->readByte());
+ _objectState[i]._exitRoom = static_cast<RoomID>(in->readSint32LE());
_objectState[i]._direction = in->readByte();
}
diff --git a/engines/supernova/state.cpp b/engines/supernova/state.cpp
index 90b2ae35c2..8985f475b9 100644
--- a/engines/supernova/state.cpp
+++ b/engines/supernova/state.cpp
@@ -56,13 +56,13 @@ bool GameManager::serialize(Common::WriteStream *out) {
out->writeByte(_state._dream);
// Inventory
- out->writeSByte(_inventory.getSize());
- out->writeSByte(_inventoryScroll);
+ out->writeSint32LE(_inventory.getSize());
+ out->writeSint32LE(_inventoryScroll);
for (int i = 0; i < _inventory.getSize(); ++i) {
Object *objectStateBegin = _rooms[_inventory.get(i)->_roomId]->getObject(0);
byte objectIndex = _inventory.get(i) - objectStateBegin;
- out->writeByte(_inventory.get(i)->_roomId);
- out->writeByte(objectIndex);
+ out->writeSint32LE(_inventory.get(i)->_roomId);
+ out->writeSint32LE(objectIndex);
}
// Rooms
@@ -75,9 +75,8 @@ bool GameManager::serialize(Common::WriteStream *out) {
bool GameManager::deserialize(Common::ReadStream *in) {
- if (in->err()) {
+ if (in->err())
return false;
- }
// GameState
_state._time = in->readSint32LE();
@@ -103,12 +102,12 @@ bool GameManager::deserialize(Common::ReadStream *in) {
_state._dream = in->readByte();
// Inventory
- int inventorySize = in->readSByte();
- _inventoryScroll = in->readSByte();
+ int inventorySize = in->readSint32LE();
+ _inventoryScroll = in->readSint32LE();
_inventory.clear();
for (int i = 0; i < inventorySize; ++i) {
- RoomID objectRoom = static_cast<RoomID>(in->readByte());
- int objectIndex = in->readByte();
+ RoomID objectRoom = static_cast<RoomID>(in->readSint32LE());
+ int objectIndex = in->readSint32LE();
_inventory.add(*_rooms[objectRoom]->getObject(objectIndex));
}