aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Frieger2009-03-05 22:19:29 +0000
committerGreg Frieger2009-03-05 22:19:29 +0000
commit5e133bbf933941eb37157d7e5b12b85f97b1d4bb (patch)
tree4cf49d0c9460198c169d7978bec01d8f2d1021d7
parent7ef3a59a2cbea1046c31161e3a37a89ed0252dce (diff)
downloadscummvm-rg350-5e133bbf933941eb37157d7e5b12b85f97b1d4bb.tar.gz
scummvm-rg350-5e133bbf933941eb37157d7e5b12b85f97b1d4bb.tar.bz2
scummvm-rg350-5e133bbf933941eb37157d7e5b12b85f97b1d4bb.zip
readResourcePatchesSCI0 and readResourcePatchesSCI1 merged. Some clean-ups
svn-id: r39138
-rw-r--r--engines/sci/scicore/resource.cpp5
-rw-r--r--engines/sci/scicore/resource.h21
-rw-r--r--engines/sci/scicore/resource_map.cpp2
-rw-r--r--engines/sci/scicore/resource_patch.cpp184
4 files changed, 80 insertions, 132 deletions
diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp
index 71645a67ad..a2d7f5f84a 100644
--- a/engines/sci/scicore/resource.cpp
+++ b/engines/sci/scicore/resource.cpp
@@ -381,10 +381,7 @@ int ResourceManager::scanNewSources(int *detected_version, ResourceSource *sourc
source->scanned = true;
switch (source->source_type) {
case kSourceDirectory:
- if (_sciVersion <= SCI_VERSION_01)
- readResourcePatchesSCI0(source);
- else
- readResourcePatchesSCI1(source);
+ readResourcePatches(source);
break;
case kSourceExtMap:
if (preset_version <= SCI_VERSION_01_VGA_ODD /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) {
diff --git a/engines/sci/scicore/resource.h b/engines/sci/scicore/resource.h
index 2bde681bad..6059d521d2 100644
--- a/engines/sci/scicore/resource.h
+++ b/engines/sci/scicore/resource.h
@@ -166,7 +166,9 @@ public:
byte *data;
uint16 number;
ResourceType type;
- uint16 id; /* contains number and type */
+ uint16 id; // contains number and type.
+ // TODO: maybe use uint32 and set id = RESOURCE_HASH()
+ // for all SCI versions
unsigned int size;
unsigned int file_offset; /* Offset in file */
byte status;
@@ -275,15 +277,11 @@ protected:
/**--- Resource map decoding functions ---*/
/* Reads the SCI0 resource.map file from a local directory
- ** Parameters: (char *) path: (unused)
- ** (int) sci_version: SCI resource version
** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise
*/
int readResourceMapSCI0(ResourceSource *map, int *sci_version);
/* Reads the SCI1 resource.map file from a local directory
- ** Parameters: (char *) path: (unused)
- ** (int) sci_version: SCI resource version
** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise
*/
int readResourceMapSCI1(ResourceSource *map, ResourceSource *vol, int *sci_version);
@@ -296,20 +294,11 @@ protected:
/**--- Patch management functions ---*/
- //! Reads SCI0 patch files from a local directory
- /** @paramParameters: ResourceSource *source
- * @return : (int) 0 on success, an SCI_ERROR_* code otherwise
- */
- int readResourcePatchesSCI0(ResourceSource *source);
-
//! Reads SCI1 patch files from a local directory
/** @paramParameters: ResourceSource *source
- * @return : (int) 0 on success, an SCI_ERROR_* code otherwise
*/
- int readResourcePatchesSCI1(ResourceSource *source);
-
- void process_patch(ResourceSource *source, Common::ArchiveMember &member,
- ResourceType restype, int resnumber);
+ void readResourcePatches(ResourceSource *source);
+ void processPatch(ResourceSource *source, const char *filename, ResourceType restype, int resnumber);
void printLRU();
void addToLRU(Resource *res);
diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp
index 8f9e50a494..7956ce1c41 100644
--- a/engines/sci/scicore/resource_map.cpp
+++ b/engines/sci/scicore/resource_map.cpp
@@ -120,7 +120,7 @@ int ResourceManager::detectOddSCI01(Common::File &file) {
}
int ResourceManager::resReadEntry(ResourceSource *map, byte *buf, Resource *res, int sci_version) {
- res->id = buf[0] | (buf[1] << 8);
+ res->id = READ_LE_UINT16(buf);//buf[0] | (buf[1] << 8);
res->type = (ResourceType)SCI0_RESID_GET_TYPE(buf);
res->number = SCI0_RESID_GET_NUMBER(buf);
res->status = SCI_STATUS_NOMALLOC;
diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp
index 695f33fb01..87d5b14307 100644
--- a/engines/sci/scicore/resource_patch.cpp
+++ b/engines/sci/scicore/resource_patch.cpp
@@ -25,6 +25,7 @@
#include "common/archive.h"
#include "common/file.h"
+#include "common/debug.h"
#include "sci/scicore/resource.h"
#include "sci/sci_memory.h"
@@ -40,132 +41,93 @@ void sci1_sprintf_patch_file_name(char *string, Resource *res) {
}
// version-agnostic patch application
-void ResourceManager::process_patch(ResourceSource *source,
- Common::ArchiveMember &member, ResourceType restype, int resnumber) {
+void ResourceManager::processPatch(ResourceSource *source,
+ const char *filename, ResourceType restype, int resnumber) {
Common::File file;
+ Resource *newrsc;
+ uint32 resId = RESOURCE_HASH(restype, resnumber);
+ byte patchtype, patch_data_offset;
+ int fsize;
- if (restype == kResourceTypeInvalid)
+ if (resnumber == -1)
return;
-
- printf("Patching \"%s\": ", member.getName().c_str());
- if (!file.open(member.createReadStream(), member.getName()))
+ if (!file.open(filename)) {
perror("""__FILE__"": (""__LINE__""): failed to open");
- else {
- byte filehdr[2];
- int fsize = file.size();
- if (fsize < 3) {
- printf("File too small\n");
- return;
- }
-
- uint32 resId = RESOURCE_HASH(restype, resnumber);
- Resource *newrsc;
- int patch_data_offset;
-
- file.read(filehdr, 2);
-
- patch_data_offset = filehdr[1];
-
- if ((filehdr[0] & 0x7f) != restype) {
- printf("Failed; resource type mismatch\n");
- } else if (patch_data_offset + 2 >= fsize) {
- printf("Failed; patch starting at offset %d can't be in file of size %d\n", filehdr[1] + 2, fsize);
- } else {
- // Adjust for file offset
- fsize -= patch_data_offset;
-
- // Prepare destination, if neccessary
- if (_resMap.contains(resId) == false) {
- newrsc = new Resource;
- _resMap.setVal(resId, newrsc);
- } else
- newrsc = _resMap.getVal(resId);
-
- // Overwrite everything, because we're patching
- newrsc->size = fsize - 2;
- newrsc->id = resId;
- newrsc->number = resnumber;
- newrsc->status = SCI_STATUS_NOMALLOC;
- newrsc->type = restype;
- newrsc->source = source;
- newrsc->file_offset = 2 + patch_data_offset;
- printf("OK\n");
- }
+ return;
}
-}
-
-
-int ResourceManager::readResourcePatchesSCI0(ResourceSource *source) {
- Common::ArchiveMemberList files;
- SearchMan.listMatchingMembers(files, "*.???");
-
- for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
- const Common::String name = (*x)->getName();
- ResourceType restype = kResourceTypeInvalid;
- int resnumber = -1;
- unsigned int resname_len;
- char *endptr;
-
- for (int i = kResourceTypeView; i < kResourceTypeInvalid; i++)
- if (scumm_strnicmp(getResourceTypeName((ResourceType)i), name.c_str(), strlen(getResourceTypeName((ResourceType)i))) == 0)
- restype = (ResourceType)i;
-
- if (restype != kResourceTypeInvalid) {
- resname_len = strlen(getResourceTypeName(restype));
- if (name[resname_len] != '.')
- restype = kResourceTypeInvalid;
- else {
- resnumber = strtol(name.c_str() + 1 + resname_len, &endptr, 10); // Get resource number
- if ((*endptr != '\0') || (resname_len + 1 == name.size()))
- restype = kResourceTypeInvalid;
-
- if ((resnumber < 0) || (resnumber > 1000))
- restype = kResourceTypeInvalid;
- }
- }
-
- process_patch(source, **x, restype, resnumber);
+ fsize = file.size();
+ if (fsize < 3) {
+ debug("Patching %s failed - file too small", filename);
+ return;
}
+
+ patchtype = file.readByte() & 0x7F;
+ patch_data_offset = file.readByte();
- return 0;
+ if (patchtype != restype) {
+ debug("Patching %s failed - resource type mismatch", filename);
+ return;
+ }
+ if (patch_data_offset + 2 >= fsize) {
+ debug("Patching %s failed - patch starting at offset %d can't be in file of size %d",
+ filename, patch_data_offset + 2, fsize);
+ return;
+ }
+ // Prepare destination, if neccessary
+ if (_resMap.contains(resId) == false) {
+ newrsc = new Resource;
+ _resMap.setVal(resId, newrsc);
+ } else
+ newrsc = _resMap.getVal(resId);
+ // Overwrite everything, because we're patching
+ newrsc->id = resId;
+ newrsc->number = resnumber;
+ newrsc->status = SCI_STATUS_NOMALLOC;
+ newrsc->type = restype;
+ newrsc->source = source;
+ newrsc->size = fsize - patch_data_offset - 2;
+ newrsc->file_offset = 2 + patch_data_offset;
+ debug("Patching %s - OK", filename);
}
-int ResourceManager::readResourcePatchesSCI1(ResourceSource *source) {
- Common::ArchiveMemberList files;
- SearchMan.listMatchingMembers(files, "*.*");
- for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
- const Common::String name = (*x)->getName();
- ResourceType restype = kResourceTypeInvalid;
- int resnumber = -1;
- char *endptr;
- const char *dot = strchr(name.c_str(), '.');
+void ResourceManager::readResourcePatches(ResourceSource *source) {
+// Note: since some SCI1 games(KQ5 floppy, SQ4) might use SCI0 naming scheme for patch files
+// this function tries to read patch file with any supported naming scheme,
+// regardless of _sciVersion value
- for (int i = kResourceTypeView; i < kResourceTypeInvalid; i++) {
- if (dot != NULL) {
- if (scumm_strnicmp(getResourceTypeSuffix((ResourceType)i), dot + 1, 3) == 0) {
- restype = (ResourceType)i;
+ Common::String mask, name;
+ Common::ArchiveMemberList files;
+ int number;
+ const char *szResType;
+
+ for (int i = kResourceTypeView; i < kResourceTypeInvalid; i ++) {
+ files.clear();
+ szResType = getResourceTypeName((ResourceType)i);
+ // SCI0 naming - type.nnn
+ mask = szResType;
+ mask += ".???";
+ SearchMan.listMatchingMembers(files, mask);
+ // SCI1 and later naming - nnn.typ
+ mask = "*.";
+ mask += getResourceTypeSuffix((ResourceType)i);
+ SearchMan.listMatchingMembers(files, mask);
+ for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); x++) {
+ number = -1;
+ name = (*x)->getName();
+ if (isdigit(name[0])) {
+ // SCI1 scheme
+ number = atoi(name.c_str());
+ } else {
+ // SCI0 scheme
+ int resname_len = strlen(szResType);
+ if (scumm_strnicmp(name.c_str(), szResType, resname_len) == 0) {
+ number = atoi(name.c_str() + resname_len + 1);
}
}
+ processPatch(source, name.c_str(), (ResourceType)i, number);
}
-
- if (restype != kResourceTypeInvalid) {
- resnumber = strtol(name.c_str(), &endptr, 10); // Get resource number
-
- if (endptr != dot)
- restype = kResourceTypeInvalid;
-
- if (*(dot + 4) != '\0')
- restype = kResourceTypeInvalid;
-
- if ((resnumber < 0) || (resnumber > 8192))
- restype = kResourceTypeInvalid;
- }
-
- process_patch(source, **x, restype, resnumber);
}
-
- return 0;
}
} // End of namespace Sci