From 94dc6ae05234b33677b10bca438819e59f6175fa Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 30 Apr 2017 12:38:50 -0500 Subject: SCI: Hold script data as mutable internally Script buffer data is modified after a script is loaded by savegame operations, and, in SCI16, by string operations. Casting away const to allow these mutations to happen is not a very good design, so this patch just changes the privately held reference to data to be mutable. (Public accessors still return immutable data.) --- engines/sci/engine/savegame.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'engines/sci/engine/savegame.cpp') diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 427e32deb3..5ba88d9417 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -467,7 +467,7 @@ void HunkTable::saveLoadWithSerializer(Common::Serializer &s) { void Script::syncStringHeap(Common::Serializer &s) { if (getSciVersion() < SCI_VERSION_1_1) { // Sync all of the SCI_OBJ_STRINGS blocks - SciSpan buf = (SciSpan &)*_buf; + SciSpan buf = *_buf; bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY); if (oldScriptHeader) @@ -490,7 +490,7 @@ void Script::syncStringHeap(Common::Serializer &s) { } else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1_LATE){ // Strings in SCI1.1 come after the object instances - SciSpan buf = _heap.subspan(4 + _heap.getUint16SEAt(2) * 2); + SciSpan buf = _heap.subspan(4 + _heap.getUint16SEAt(2) * 2); // Skip all of the objects while (buf.getUint16SEAt(0) == SCRIPT_OBJECT_MAGIC_NUMBER) @@ -502,8 +502,7 @@ void Script::syncStringHeap(Common::Serializer &s) { } else if (getSciVersion() == SCI_VERSION_3) { const int stringOffset = _buf->getInt32SEAt(4); const int length = _buf->getInt32SEAt(8) - stringOffset; - SciSpan buf = _buf->subspan(stringOffset, length); - s.syncBytes(buf.getUnsafeDataAt(0, length), length); + s.syncBytes(_buf->getUnsafeDataAt(stringOffset, length), length); } } -- cgit v1.2.3