From 717de7800c9bd6b822d56771393beec42f3bc1bb Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 9 Jul 2009 15:54:18 +0000 Subject: Applied patch #2818845 - "SCI: resource.map detection for SCI1/1.1 fixed", with some slight formatting changes svn-id: r42300 --- engines/sci/resource.cpp | 54 +++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'engines/sci/resource.cpp') diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index 30e917557d..a1d7fa7a41 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -728,26 +728,39 @@ int ResourceManager::detectMapVersion() { } return SCI_VERSION_0; } - // SCI1E/L and some SCI1.1 maps have last directory entry set to 0xFF - // and offset set to filesize - // SCI1 have 6-bytes entries, while SCI1.1 have 5-byte entries - file.seek(1, SEEK_SET); - uint16 off1, off = file.readUint16LE(); - uint16 nEntries = off / 3; - file.seek(1, SEEK_CUR); - file.seek(off - 3, SEEK_SET); - if (file.readByte() == 0xFF && file.readUint16LE() == file.size()) { - file.seek(3, SEEK_SET); - for (int i = 0; i < nEntries; i++) { - file.seek(1, SEEK_CUR); - off1 = file.readUint16LE(); - if ((off1 - off) % 5 && (off1 - off) % 6 == 0) - return SCI_VERSION_1; - if ((off1 - off) % 5 == 0 && (off1 - off) % 6) - return SCI_VERSION_1_1; - off = off1; + + // SCI1 and SCI1.1 maps consist of a fixed 3-byte header, a directory list (3-bytes each) that has one entry + // of id FFh and points to EOF. The actual entries have 6-bytes on SCI1 and 5-bytes on SCI1.1 + byte directoryType = 0; + uint16 directoryOffset = 0; + uint16 lastDirectoryOffset = 0; + uint16 directorySize = 0; + int mapDetected = 0; + file.seek(0, SEEK_SET); + while (!file.eos()) { + directoryType = file.readByte(); + directoryOffset = file.readUint16LE(); + if ((directoryType < 0x80) || ((directoryType > 0xA0) && (directoryType != 0xFF))) + break; + // Offset is above file size? -> definitely not SCI1/SCI1.1 + if (directoryOffset > file.size()) + break; + if (lastDirectoryOffset) { + directorySize = directoryOffset - lastDirectoryOffset; + if ((directorySize % 5) && (directorySize % 6 == 0)) + mapDetected = SCI_VERSION_1; + if ((directorySize % 5 == 0) && (directorySize % 6)) + mapDetected = SCI_VERSION_1_1; } - return SCI_VERSION_1; + if (directoryType==0xFF) { + // FFh entry needs to point to EOF + if (directoryOffset != file.size()) + break; + if (mapDetected) + return mapDetected; + return SCI_VERSION_1; + } + lastDirectoryOffset = directoryOffset; } #ifdef ENABLE_SCI32 @@ -974,6 +987,9 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) { res->file_offset = offset & (((~bMask) << 24) | 0xFFFFFF); res->id = resId; res->source = getVolume(map, offset >> bShift); + if (!res->source) { + warning("Could not get volume for resource %d, VolumeID %d\n", resId, offset >> bShift); + } _resMap.setVal(resId, res); } } while (!file.eos()); -- cgit v1.2.3 From 0aa83f14c760ae790b738e5957fb8c3d9930697f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 9 Jul 2009 15:59:20 +0000 Subject: Fix wrong format arugment. svn-id: r42301 --- engines/sci/resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/resource.cpp') diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index a1d7fa7a41..9d791f615c 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -988,7 +988,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) { res->id = resId; res->source = getVolume(map, offset >> bShift); if (!res->source) { - warning("Could not get volume for resource %d, VolumeID %d\n", resId, offset >> bShift); + warning("Could not get volume for resource %d, VolumeID %d\n", id, offset >> bShift); } _resMap.setVal(resId, res); } -- cgit v1.2.3 From 1ac515c629898f7642d55588141d6168293a9331 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 9 Jul 2009 16:16:08 +0000 Subject: By comparing the commit log of r42300, it seems that "off" was renamed to "lastDirectoryOffset". I changed the SCI32 specific code to use that now. I can't assure this is anyhow correct, so anyone with knowledge of this code please check it. svn-id: r42303 --- engines/sci/resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/resource.cpp') diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index 9d791f615c..b248729503 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -766,7 +766,7 @@ int ResourceManager::detectMapVersion() { #ifdef ENABLE_SCI32 // late SCI1.1 and SCI32 maps have last directory entry set to 0xFF // offset set to filesize and 4 more bytes - file.seek(off - 7, SEEK_SET); + file.seek(lastDirectoryOffset - 7, SEEK_SET); if (file.readByte() == 0xFF && file.readUint16LE() == file.size()) return SCI_VERSION_32; // TODO : check if there is a difference between these maps #endif -- cgit v1.2.3 From 5d0d67e5742d9a65ad9c944a86ff3223ff967042 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 9 Jul 2009 16:23:22 +0000 Subject: Add fixme about SCI32 specific code. svn-id: r42305 --- engines/sci/resource.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/sci/resource.cpp') diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index b248729503..6d33c77179 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -766,6 +766,12 @@ int ResourceManager::detectMapVersion() { #ifdef ENABLE_SCI32 // late SCI1.1 and SCI32 maps have last directory entry set to 0xFF // offset set to filesize and 4 more bytes + + // TODO/FIXME: This code was not updated in r43000, which changed the behavior of this + // function a lot. To make it compile again "off" was changed to the newly introduced + // "lastDirectoryOffset". This is probably not the correct fix, since before r43000 + // the loop above could not prematurely terminate and thus this would always check the + // last directory entry instead of the last checked directory entry. file.seek(lastDirectoryOffset - 7, SEEK_SET); if (file.readByte() == 0xFF && file.readUint16LE() == file.size()) return SCI_VERSION_32; // TODO : check if there is a difference between these maps -- cgit v1.2.3 From e8e9b882275b8dc5d77db3b1faaf30466c7b7a31 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 9 Jul 2009 16:24:59 +0000 Subject: Oops specify the correct revsision number in the fixme. svn-id: r42306 --- engines/sci/resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/resource.cpp') diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index 6d33c77179..5fdc286894 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -767,7 +767,7 @@ int ResourceManager::detectMapVersion() { // late SCI1.1 and SCI32 maps have last directory entry set to 0xFF // offset set to filesize and 4 more bytes - // TODO/FIXME: This code was not updated in r43000, which changed the behavior of this + // TODO/FIXME: This code was not updated in r42300, which changed the behavior of this // function a lot. To make it compile again "off" was changed to the newly introduced // "lastDirectoryOffset". This is probably not the correct fix, since before r43000 // the loop above could not prematurely terminate and thus this would always check the -- cgit v1.2.3