diff options
author | Colin Snover | 2016-09-04 16:30:47 -0500 |
---|---|---|
committer | Colin Snover | 2016-09-29 19:39:16 -0500 |
commit | 3f9172676526aa04983f148d1262af6ea9fb53ef (patch) | |
tree | e2729dc6ac8a5142147001dfdcc5856919706340 /engines/sci/engine/savegame.cpp | |
parent | 240b0ca3488231e0cfb9c56b1c21ccdd309f0908 (diff) | |
download | scummvm-rg350-3f9172676526aa04983f148d1262af6ea9fb53ef.tar.gz scummvm-rg350-3f9172676526aa04983f148d1262af6ea9fb53ef.tar.bz2 scummvm-rg350-3f9172676526aa04983f148d1262af6ea9fb53ef.zip |
SCI32: Rewrite kArray & kString
This change invalidates earlier SCI32 save games, which separated
arrays and strings in an incompatible manner. Old save games
contain invalid references to a string segment which no longer
exists, and contain incompatible array structures that lack
critical type information.
Diffstat (limited to 'engines/sci/engine/savegame.cpp')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 99 |
1 files changed, 32 insertions, 67 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index be2d7660cb..9def79c918 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -102,66 +102,6 @@ void syncWithSerializer(Common::Serializer &s, Node &obj) { syncWithSerializer(s, obj.value); } -#ifdef ENABLE_SCI32 -void syncWithSerializer(Common::Serializer &s, SciArray<reg_t> &obj) { - byte type = 0; - uint32 size = 0; - - if (s.isSaving()) { - type = (byte)obj.getType(); - size = obj.getSize(); - } - s.syncAsByte(type); - s.syncAsUint32LE(size); - if (s.isLoading()) { - obj.setType((int8)type); - - // HACK: Skip arrays that have a negative type - if ((int8)type < 0) - return; - - obj.setSize(size); - } - - for (uint32 i = 0; i < size; i++) { - reg_t value; - - if (s.isSaving()) - value = obj.getValue(i); - - syncWithSerializer(s, value); - - if (s.isLoading()) - obj.setValue(i, value); - } -} - -void syncWithSerializer(Common::Serializer &s, SciString &obj) { - uint32 size = 0; - - if (s.isSaving()) { - size = obj.getSize(); - s.syncAsUint32LE(size); - } else { - s.syncAsUint32LE(size); - obj.setSize(size); - } - - for (uint32 i = 0; i < size; i++) { - char value = 0; - - if (s.isSaving()) - value = obj.getValue(i); - - s.syncAsByte(value); - - if (s.isLoading()) - obj.setValue(i, value); - } -} - -#endif - #pragma mark - // By default, sync using syncWithSerializer, which in turn can easily be overloaded. @@ -292,9 +232,6 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { } else if (type == SEG_TYPE_ARRAY) { // Set the correct segment for SCI32 arrays _arraysSegId = i; - } else if (type == SEG_TYPE_STRING) { - // Set the correct segment for SCI32 strings - _stringSegId = i; } else if (s.getVersion() >= 36 && type == SEG_TYPE_BITMAP) { _bitmapSegId = i; #endif @@ -707,11 +644,39 @@ void ArrayTable::saveLoadWithSerializer(Common::Serializer &ser) { sync_Table<ArrayTable>(ser, *this); } -void StringTable::saveLoadWithSerializer(Common::Serializer &ser) { - if (ser.getVersion() < 18) - return; +void SciArray::saveLoadWithSerializer(Common::Serializer &s) { + uint16 size; + + if (s.isSaving()) { + size = _size; + } + + s.syncAsByte(_type); + s.syncAsByte(_elementSize); + s.syncAsUint16LE(size); + + if (s.isLoading()) { + resize(size); + } - sync_Table<StringTable>(ser, *this); + switch (_type) { + case kArrayTypeByte: + case kArrayTypeString: + s.syncBytes((byte *)_data, size); + break; + case kArrayTypeInt16: + for (int i = 0; i < size; ++i) { + s.syncAsUint16LE(((int16 *)_data)[i]); + } + break; + case kArrayTypeID: + for (int i = 0; i < size; ++i) { + syncWithSerializer(s, ((reg_t *)_data)[i]); + } + break; + default: + error("Attempt to sync invalid SciArray type %d", _type); + } } void BitmapTable::saveLoadWithSerializer(Common::Serializer &ser) { |