aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore
diff options
context:
space:
mode:
authorJordi Vilalta Prat2009-02-28 23:46:50 +0000
committerJordi Vilalta Prat2009-02-28 23:46:50 +0000
commit7050c7b03f0f7b107df62488fd4dc2f37b704d3b (patch)
tree102ee5f2a5cecb29f1de285d0ea9f004477a37f7 /engines/sci/scicore
parent8e39ac9f12fb95ffda80116389d03f050beabd90 (diff)
downloadscummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.tar.gz
scummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.tar.bz2
scummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.zip
SCI: Use the ResourceType enum instead of integers where it makes sense
svn-id: r38988
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r--engines/sci/scicore/decompress0.cpp10
-rw-r--r--engines/sci/scicore/decompress01.cpp8
-rw-r--r--engines/sci/scicore/decompress1.cpp14
-rw-r--r--engines/sci/scicore/decompress11.cpp11
-rw-r--r--engines/sci/scicore/resource.cpp67
-rw-r--r--engines/sci/scicore/resource.h81
-rw-r--r--engines/sci/scicore/resource_map.cpp18
-rw-r--r--engines/sci/scicore/resource_patch.cpp45
-rw-r--r--engines/sci/scicore/script.cpp2
-rw-r--r--engines/sci/scicore/vocab.cpp12
-rw-r--r--engines/sci/scicore/vocab_debug.cpp12
11 files changed, 162 insertions, 118 deletions
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp
index 6b3775ff5c..1e9c263845 100644
--- a/engines/sci/scicore/decompress0.cpp
+++ b/engines/sci/scicore/decompress0.cpp
@@ -244,11 +244,13 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
return SCI_ERROR_IO_ERROR;
result->number = result->id & 0x07ff;
- result->type = result->id >> 11;
+ uint8 type = result->id >> 11;
- if ((result->number > sci_max_resource_nr[sci_version]) || (result->type > sci_invalid_resource))
+ if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid))
return SCI_ERROR_DECOMPRESSION_INSANE;
+ result->type = (ResourceType)type;
+
compressedLength = stream.readUint16LE();
result->size = stream.readUint16LE();
compressionMethod = stream.readUint16LE();
@@ -280,7 +282,7 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
#ifdef _SCI_DECOMPRESS_DEBUG
fprintf(stderr, "Resource %s.%03hi encrypted with method %hi at %.2f%%"
" ratio\n",
- sci_resource_types[result->type], result->number, compressionMethod,
+ getResourceTypeName(result->type), result->number, compressionMethod,
(result->size == 0) ? -1.0 :
(100.0 * compressedLength / result->size));
fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
@@ -324,7 +326,7 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
default:
fprintf(stderr, "Resource %s.%03hi: Compression method %hi not "
- "supported!\n", sci_resource_types[result->type], result->number,
+ "supported!\n", getResourceTypeName(result->type), result->number,
compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp
index e74b85def7..e87d61cf28 100644
--- a/engines/sci/scicore/decompress01.cpp
+++ b/engines/sci/scicore/decompress01.cpp
@@ -500,11 +500,13 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version)
return SCI_ERROR_IO_ERROR;
result->number = result->id & 0x07ff;
- result->type = result->id >> 11;
+ uint8 type = result->id >> 11;
- if ((result->number > sci_max_resource_nr[sci_version] || (result->type > sci_invalid_resource)))
+ if ((result->number > sci_max_resource_nr[sci_version] || (type > kResourceTypeInvalid)))
return SCI_ERROR_DECOMPRESSION_INSANE;
+ result->type = (ResourceType)type;
+
compressedLength = stream.readUint16LE();
result->size = stream.readUint16LE();
compressionMethod = stream.readUint16LE();
@@ -611,7 +613,7 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version)
default:
fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
- "supported!\n", sci_resource_types[result->type], result->number,
+ "supported!\n", getResourceTypeName(result->type), result->number,
compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp
index 51b13e49a7..c42f436bba 100644
--- a/engines/sci/scicore/decompress1.cpp
+++ b/engines/sci/scicore/decompress1.cpp
@@ -278,22 +278,26 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
return SCI_ERROR_IO_ERROR;
result->number = result->id & 0x07ff;
- result->type = result->id >> 11;
+ uint16 type = result->id >> 11;
- if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (result->type > sci_invalid_resource))
+ if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (type > kResourceTypeInvalid))
return SCI_ERROR_DECOMPRESSION_INSANE;
+
+ result->type = (ResourceType)type;
} else {
result->id = stream.readByte();
if (stream.err())
return SCI_ERROR_IO_ERROR;
- result->type = result->id & 0x7f;
+ uint16 type = result->id & 0x7f;
result->number = stream.readUint16LE();
if (stream.err())
return SCI_ERROR_IO_ERROR;
- if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (result->type > sci_invalid_resource))
+ if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (type > kResourceTypeInvalid))
return SCI_ERROR_DECOMPRESSION_INSANE;
+
+ result->type = (ResourceType)type;
}
compressedLength = stream.readUint16LE();
@@ -399,7 +403,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
default:
fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
- "supported!\n", sci_resource_types[result->type], result->number,
+ "supported!\n", getResourceTypeName(result->type), result->number,
compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp
index 39ff53c070..aff87c9fdf 100644
--- a/engines/sci/scicore/decompress11.cpp
+++ b/engines/sci/scicore/decompress11.cpp
@@ -49,9 +49,10 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version)
if (stream.err())
return SCI_ERROR_IO_ERROR;
- result->type = result->id & 0x7f;
- if ((result->type > sci_invalid_resource))
+ uint16 type = result->id & 0x7f;
+ if (type > kResourceTypeInvalid)
return SCI_ERROR_DECOMPRESSION_INSANE;
+ result->type = (ResourceType)type;
result->number = stream.readUint16LE();
compressedLength = stream.readUint16LE();
@@ -91,7 +92,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
fprintf(stderr, "Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%%"
" ratio\n",
- result->number, sci_resource_type_suffixes[result->type],
+ result->number, getResourceTypeSuffix(result->type),
compressionMethod,
(result->size == 0) ? -1.0 :
(100.0 * compressedLength / result->size));
@@ -130,7 +131,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version)
case 3:
case 4: // NYI
fprintf(stderr, "Resource %d.%s: Warning: compression type #%d not yet implemented\n",
- result->number, sci_resource_type_suffixes[result->type], compressionMethod);
+ result->number, getResourceTypeSuffix(result->type), compressionMethod);
free(result->data);
result->data = NULL;
result->status = SCI_STATUS_NOMALLOC;
@@ -138,7 +139,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version)
default:
fprintf(stderr, "Resource %d.%s: Compression method SCI1/%hi not "
- "supported!\n", result->number, sci_resource_type_suffixes[result->type],
+ "supported!\n", result->number, getResourceTypeSuffix(result->type),
compressionMethod);
free(result->data);
result->data = NULL; // So that we know that it didn't work
diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp
index 75448d6ab9..e7b9fc34c2 100644
--- a/engines/sci/scicore/resource.cpp
+++ b/engines/sci/scicore/resource.cpp
@@ -65,19 +65,28 @@ const char *sci_error_types[] = {
"SCI version is unsupported"
};
-const char *sci_resource_types[] = {"view", "pic", "script", "text", "sound",
- "memory", "vocab", "font", "cursor",
- "patch", "bitmap", "palette", "cdaudio",
- "audio", "sync", "message", "map", "heap"
- };
// These are the 18 resource types supported by SCI1
+const char *resourceTypeNames[] = {
+ "view", "pic", "script", "text", "sound",
+ "memory", "vocab", "font", "cursor",
+ "patch", "bitmap", "palette", "cdaudio",
+ "audio", "sync", "message", "map", "heap"
+};
-const char *sci_resource_type_suffixes[] = {"v56", "p56", "scr", "tex", "snd",
- " ", "voc", "fon", "cur", "pat",
- "bit", "pal", "cda", "aud", "syn",
- "msg", "map", "hep"
- };
+const char *resourceTypeSuffixes[] = {
+ "v56", "p56", "scr", "tex", "snd",
+ " ", "voc", "fon", "cur", "pat",
+ "bit", "pal", "cda", "aud", "syn",
+ "msg", "map", "hep"
+};
+const char *getResourceTypeName(ResourceType restype) {
+ return resourceTypeNames[restype];
+}
+
+const char *getResourceTypeSuffix(ResourceType restype) {
+ return resourceTypeSuffixes[restype];
+}
int resourcecmp(const void *first, const void *second);
@@ -133,7 +142,7 @@ void ResourceManager::addAltSource(Resource *res, ResourceSource *source, unsign
res->alt_sources = rsrc;
}
-Resource *ResourceManager::findResourceUnsorted(Resource *res, int res_nr, int type, int number) {
+Resource *ResourceManager::findResourceUnsorted(Resource *res, int res_nr, ResourceType type, int number) {
int i;
for (i = 0; i < res_nr; i++)
if (res[i].number == number && res[i].type == type)
@@ -258,7 +267,7 @@ void ResourceManager::loadResource(Resource *res, bool protect) {
if (error) {
sciprintf("Error %d occured while reading %s.%03d from resource file: %s\n",
- error, sci_resource_types[res->type], res->number, sci_error_types[error]);
+ error, getResourceTypeName(res->type), res->number, sci_error_types[error]);
if (protect)
memcpy(res, &backup, sizeof(Resource));
@@ -271,7 +280,7 @@ void ResourceManager::loadResource(Resource *res, bool protect) {
}
-Resource *ResourceManager::testResource(int type, int number) {
+Resource *ResourceManager::testResource(ResourceType type, int number) {
Resource binseeker;
binseeker.type = type;
binseeker.number = number;
@@ -290,7 +299,7 @@ int sci_test_view_type(ResourceManager *mgr) {
mgr->_sciVersion = SCI_VERSION_AUTODETECT;
for (i = 0; i < 1000; i++) {
- res = mgr->testResource(sci_view, i);
+ res = mgr->testResource(kResourceTypeView, i);
if (!res)
continue;
@@ -315,7 +324,7 @@ int sci_test_view_type(ResourceManager *mgr) {
// Try the same thing with pics
for (i = 0; i < 1000; i++) {
- res = mgr->testResource(sci_pic, i);
+ res = mgr->testResource(kResourceTypePic, i);
if (!res)
continue;
@@ -479,7 +488,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
if (version == SCI_VERSION_AUTODETECT)
switch (resmap_version) {
case SCI_VERSION_0:
- if (testResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
+ if (testResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
version = sci_test_view_type(this);
if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
@@ -487,12 +496,12 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
sciprintf("Resmgr: Detected SCI0\n");
version = SCI_VERSION_0;
}
- } else if (testResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
+ } else if (testResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
version = sci_test_view_type(this);
if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
} else {
- if (testResource(sci_vocab, 912)) {
+ if (testResource(kResourceTypeVocab, 912)) {
sciprintf("Resmgr: Running KQ1 or similar, using SCI0 resource encoding\n");
version = SCI_VERSION_0;
} else {
@@ -515,7 +524,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
sciprintf("Resmgr: Detected Jones/CD or similar\n");
break;
case SCI_VERSION_1: {
- Resource *res = testResource(sci_script, 0);
+ Resource *res = testResource(kResourceTypeScript, 0);
_sciVersion = version = SCI_VERSION_1_EARLY;
loadResource(res, true);
@@ -611,7 +620,7 @@ void ResourceManager::addToLRU(Resource *res) {
_memoryLRU += res->size;
#if (SCI_VERBOSE_RESMGR > 1)
fprintf(stderr, "Adding %s.%03d (%d bytes) to lru control: %d bytes total\n",
- sci_resource_types[res->type], res->number, res->size,
+ getResourceTypeName(res->type), res->number, res->size,
mgr->_memoryLRU);
#endif
@@ -626,7 +635,7 @@ void ResourceManager::printLRU() {
while (res) {
fprintf(stderr, "\t%s.%03d: %d bytes\n",
- sci_resource_types[res->type], res->number,
+ getResourceTypeName(res->type), res->number,
res->size);
mem += res->size;
++entries;
@@ -650,18 +659,18 @@ void ResourceManager::freeOldResources(int last_invulnerable) {
removeFromLRU(goner);
unalloc(goner);
#ifdef SCI_VERBOSE_RESMGR
- sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", sci_resource_types[goner->type], goner->number, goner->size);
+ sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", getResourceTypeName(goner->type), goner->number, goner->size);
#endif
}
}
-Resource *ResourceManager::findResource(int type, int number, int lock) {
+Resource *ResourceManager::findResource(ResourceType type, int number, int lock) {
Resource *retval;
if (number >= sci_max_resource_nr[_sciVersion]) {
int modded_number = number % sci_max_resource_nr[_sciVersion];
sciprintf("[resmgr] Requested invalid resource %s.%d, mapped to %s.%d\n",
- sci_resource_types[type], number, sci_resource_types[type], modded_number);
+ getResourceTypeName(type), number, getResourceTypeName(type), modded_number);
number = modded_number;
}
@@ -697,23 +706,23 @@ Resource *ResourceManager::findResource(int type, int number, int lock) {
if (retval->data)
return retval;
else {
- sciprintf("Resmgr: Failed to read %s.%03d\n", sci_resource_types[retval->type], retval->number);
+ sciprintf("Resmgr: Failed to read %s.%03d\n", getResourceTypeName(retval->type), retval->number);
return NULL;
}
}
-void ResourceManager::unlockResource(Resource *res, int resnum, int restype) {
+void ResourceManager::unlockResource(Resource *res, int resnum, ResourceType restype) {
if (!res) {
- if (restype >= ARRAYSIZE(sci_resource_types))
+ if (restype == kResourceTypeInvalid)
sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d!\n", restype, resnum);
else
- sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d!\n", sci_resource_types[restype], resnum);
+ sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d!\n", getResourceTypeName(restype), resnum);
return;
}
if (res->status != SCI_STATUS_LOCKED) {
sciprintf("Resmgr: Warning: Attempt to unlock unlocked resource %s.%03d\n",
- sci_resource_types[res->type], res->number);
+ getResourceTypeName(res->type), res->number);
return;
}
diff --git a/engines/sci/scicore/resource.h b/engines/sci/scicore/resource.h
index 3d74ecb982..abbe6a77ac 100644
--- a/engines/sci/scicore/resource.h
+++ b/engines/sci/scicore/resource.h
@@ -97,30 +97,48 @@ enum ResSourceType {
extern const char *sci_error_types[];
extern const char *sci_version_types[];
-extern const char *sci_resource_types[];
-extern const char *sci_resource_type_suffixes[]; /* Suffixes for SCI1 patch files */
extern const int sci_max_resource_nr[]; /* Highest possible resource numbers */
-enum ResourceTypes {
- sci_view = 0, sci_pic, sci_script, sci_text,
- sci_sound, sci_memory, sci_vocab, sci_font,
- sci_cursor, sci_patch, sci_bitmap, sci_palette,
- sci_cdaudio, sci_audio, sci_sync, sci_message,
- sci_map, sci_heap, sci_invalid_resource
+enum ResourceType {
+ kResourceTypeView = 0,
+ kResourceTypePic,
+ kResourceTypeScript,
+ kResourceTypeText,
+ kResourceTypeSound,
+ kResourceTypeMemory,
+ kResourceTypeVocab,
+ kResourceTypeFont,
+ kResourceTypeCursor,
+ kResourceTypePatch,
+ kResourceTypeBitmap,
+ kResourceTypePalette,
+ kResourceTypeCdAudio,
+ kResourceTypeAudio,
+ kResourceTypeSync,
+ kResourceTypeMessage,
+ kResourceTypeMap,
+ kResourceTypeHeap,
+ kResourceTypeInvalid
};
-#define sci0_last_resource sci_patch
-#define sci1_last_resource sci_heap
+const char *getResourceTypeName(ResourceType restype);
+// Suffixes for SCI1 patch files
+const char *getResourceTypeSuffix(ResourceType restype);
+
+#define sci0_last_resource kResourceTypePatch
+#define sci1_last_resource kResourceTypeHeap
/* Used for autodetection */
+#if 0
struct resource_index_struct {
unsigned short resource_id;
unsigned int resource_location;
}; /* resource type as stored in the resource.map file */
typedef struct resource_index_struct resource_index_t;
+#endif
struct ResourceSource {
ResSourceType source_type;
@@ -147,7 +165,7 @@ public:
// to let the rest of the engine compile without changes
unsigned char *data;
unsigned short number;
- unsigned short type;
+ ResourceType type;
uint16 id; /* contains number and type */
unsigned int size;
unsigned int file_offset; /* Offset in file */
@@ -163,6 +181,7 @@ public:
class ResourceManager {
public:
int _sciVersion; /* SCI resource version to use */
+
/**
* Creates a new FreeSCI resource manager.
* @param version The SCI version to look for; use SCI_VERSION_AUTODETECT
@@ -180,7 +199,9 @@ public:
** Returns: A pointer to the added source structure, or NULL if an error occurred.
*/
ResourceSource *addPatchDir(const char *path);
+
ResourceSource *getVolume(ResourceSource *map, int volume_nr);
+
//! Add a volume to the resource manager's list of sources.
/** @param map The map associated with this volume
* @param filename The name of the volume to add
@@ -190,17 +211,20 @@ public:
*/
ResourceSource *addVolume(ResourceSource *map, const char *filename,
int number, int extended_addressing);
+
//! Add an external (i.e. separate file) map resource to the resource manager's list of sources.
/** @param file_name The name of the volume to add
* @return A pointer to the added source structure, or NULL if an error occurred.
*/
ResourceSource *addExternalMap(const char *file_name);
+
//! Scans newly registered resource sources for resources, earliest addition first.
/** @param detected_version: Pointer to the detected version number,
* used during startup. May be NULL.
* @return One of SCI_ERROR_*.
*/
int scanNewSources(int *detected_version, ResourceSource *source);
+
//! Looks up a resource's data
/** @param type: The resource type to look for
* @param number: The resource number to search
@@ -209,16 +233,18 @@ public:
* @note Locked resources are guaranteed not to have their contents freed until
* they are unlocked explicitly (by unlockResource).
*/
- Resource *findResource(int type, int number, int lock);
+ Resource *findResource(ResourceType type, int number, int lock);
+
/* Unlocks a previously locked resource
** (Resource *) res: The resource to free
- ** (int) type: Type of the resource to check (for error checking)
** (int) number: Number of the resource to check (ditto)
+ ** (ResourceType) type: Type of the resource to check (for error checking)
** Returns : (void)
*/
- void unlockResource(Resource *res, int restype, int resnum);
+ void unlockResource(Resource *res, int restype, ResourceType resnum);
+
/* Tests whether a resource exists
- ** (int) type: Type of the resource to check
+ ** (ResourceType) type: Type of the resource to check
** (int) number: Number of the resource to check
** Returns : (Resource *) non-NULL if the resource exists, NULL otherwise
** This function may often be much faster than finding the resource
@@ -227,7 +253,7 @@ public:
** it should be used with care, as it may be unallocated.
** Use scir_find_resource() if you want to use the data contained in the resource.
*/
- Resource *testResource(int type, int number);
+ Resource *testResource(ResourceType type, int number);
protected:
int _maxMemory; /* Config option: Maximum total byte number allocated */
@@ -239,24 +265,25 @@ protected:
Resource *lru_first, *lru_last; // Pointers to the first and last LRU queue entries
// LRU queue: lru_first points to the most recent entry
-
/* Frees a block of resources and associated data
** Parameters: (Resource *) resources: The resources to free
** (int) _resourcesNr: Number of resources in the block
** Returns : (void)
*/
void freeResources(Resource *resources, int _resourcesNr);
+
/* Finds a resource matching type.number in an unsorted Resource block
** To be used during initial resource loading, when the resource list
** may not have been sorted yet.
** Parameters: (Resource *) res: Pointer to the block to search in
** (int) res_nr: Number of Resource structs allocated and defined
** in the block pointed to by res
- ** (int) type: Type of the resource to look for
+ ** (ResourceType) type: Type of the resource to look for
** (int) number: Number of the resource to look for
** Returns : (Resource) The matching resource entry, or NULL if not found
*/
- Resource *findResourceUnsorted(Resource *res, int res_nr, int type, int number);
+ Resource *findResourceUnsorted(Resource *res, int res_nr, ResourceType type, int number);
+
/* Adds an alternative source to a resource
** Parameters: (Resource *) res: The resource to add to
** (ResourceSource *) source: The source of the resource
@@ -264,8 +291,9 @@ protected:
** is stored at
** Returns : (void)
*/
- int addAppropriateSources();
void addAltSource(Resource *res, ResourceSource *source, unsigned int file_offset);
+
+ int addAppropriateSources();
void freeResourceSources(ResourceSource *rss);
void freeAltSources(resource_altsource_t *dynressrc);
@@ -282,17 +310,19 @@ protected:
** 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);
+
int isSCI10or11(int *types);
int detectOddSCI01(Common::File &file);
int resReadEntry(ResourceSource *map, byte *buf, Resource *res, int sci_version);
- int resTypeSCI1(int ofs, int *types, int lastrt);
- int parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt);
+ ResourceType resTypeSCI1(int ofs, int *types, ResourceType lastrt);
+ int parseHeaderSCI1(Common::ReadStream &stream, int *types, ResourceType *lastrt);
/**--- Patch management functions ---*/
@@ -319,8 +349,9 @@ protected:
** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise
*/
int readResourcePatchesSCI1(ResourceSource *source);
- void process_patch(ResourceSource *source, Common::ArchiveMember &member, int restype,
- int resnumber);
+
+ void process_patch(ResourceSource *source, Common::ArchiveMember &member,
+ ResourceType restype, int resnumber);
void printLRU();
void addToLRU(Resource *res);
@@ -372,7 +403,6 @@ protected:
** encountered.
*/
-
int decompress11(Resource *result, Common::ReadStream &stream, int sci_version);
/* Decrypts resource data and stores the result for SCI1.1-style compression.
** Parameters : result: The Resource the decompressed data is stored in.
@@ -382,7 +412,6 @@ protected:
** encountered.
*/
-
int decrypt2(uint8* dest, uint8* src, int length, int complength);
/* Huffman token decryptor - defined in decompress0.c and used in decompress01.c
*/
diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp
index dc2ad4f8bb..cb07c97d16 100644
--- a/engines/sci/scicore/resource_map.cpp
+++ b/engines/sci/scicore/resource_map.cpp
@@ -121,7 +121,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->type = SCI0_RESID_GET_TYPE(buf);
+ res->type = (ResourceType)SCI0_RESID_GET_TYPE(buf);
res->number = SCI0_RESID_GET_NUMBER(buf);
res->status = SCI_STATUS_NOMALLOC;
@@ -156,20 +156,20 @@ int ResourceManager::resReadEntry(ResourceSource *map, byte *buf, Resource *res,
return 0;
}
-int ResourceManager::resTypeSCI1(int ofs, int *types, int lastrt) {
- int i, last = -1;
+ResourceType ResourceManager::resTypeSCI1(int ofs, int *types, ResourceType lastrt) {
+ ResourceType last = kResourceTypeInvalid;
- for (i = 0; i <= sci1_last_resource;i++)
+ for (int i = 0; i <= sci1_last_resource; i++)
if (types[i]) {
if (types[i] > ofs)
return last;
- last = i;
+ last = (ResourceType)i;
}
return lastrt;
}
-int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt) {
+int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, ResourceType *lastrt) {
unsigned char rtype;
unsigned char offset[2];
int read_ok;
@@ -184,7 +184,7 @@ int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, int
read_ok = 0;
if (rtype != 0xff) {
types[rtype&0x7f] = (offset[1] << 8) | (offset[0]);
- *lastrt = rtype & 0x7f;
+ *lastrt = (ResourceType)(rtype & 0x7f);
}
size += 3;
} while (read_ok && (rtype != 0xFF));
@@ -344,7 +344,7 @@ int ResourceManager::isSCI10or11(int *types) {
int this_restype = 0;
int next_restype = 1;
- while (next_restype <= sci_heap) {
+ while (next_restype <= kResourceTypeHeap) {
int could_be_10 = 0;
int could_be_11 = 0;
@@ -381,7 +381,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map, ResourceSource *vo
int *types = (int *)sci_malloc(sizeof(int) * (sci1_last_resource + 1));
int i;
byte buf[SCI1_RESMAP_ENTRIES_SIZE];
- int lastrt;
+ ResourceType lastrt;
int entrysize;
int entry_size_selector;
diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp
index 05d97f5e48..2cbeb2b52c 100644
--- a/engines/sci/scicore/resource_patch.cpp
+++ b/engines/sci/scicore/resource_patch.cpp
@@ -32,19 +32,19 @@
namespace Sci {
void sci0_sprintf_patch_file_name(char *string, Resource *res) {
- sprintf(string, "%s.%03i", sci_resource_types[res->type], res->number);
+ sprintf(string, "%s.%03i", getResourceTypeName(res->type), res->number);
}
void sci1_sprintf_patch_file_name(char *string, Resource *res) {
- sprintf(string, "%d.%s", res->number, sci_resource_type_suffixes[res->type]);
+ sprintf(string, "%d.%s", res->number, getResourceTypeSuffix(res->type));
}
// version-agnostic patch application
void ResourceManager::process_patch(ResourceSource *source,
- Common::ArchiveMember &member, int restype, int resnumber) {
+ Common::ArchiveMember &member, ResourceType restype, int resnumber) {
Common::File file;
- if (restype == sci_invalid_resource)
+ if (restype == kResourceTypeInvalid)
return;
printf("Patching \"%s\": ", member.getName().c_str());
@@ -103,28 +103,26 @@ int ResourceManager::readResourcePatchesSCI0(ResourceSource *source) {
for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
const Common::String name = (*x)->getName();
- int restype = sci_invalid_resource;
+ ResourceType restype = kResourceTypeInvalid;
int resnumber = -1;
- int i;
unsigned int resname_len;
char *endptr;
- for (i = sci_view; i < sci_invalid_resource; i++)
- if (scumm_strnicmp(sci_resource_types[i], name.c_str(), strlen(sci_resource_types[i])) == 0)
- restype = i;
+ 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 != sci_invalid_resource) {
-
- resname_len = strlen(sci_resource_types[restype]);
+ if (restype != kResourceTypeInvalid) {
+ resname_len = strlen(getResourceTypeName(restype));
if (name[resname_len] != '.')
- restype = sci_invalid_resource;
+ 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 = sci_invalid_resource;
+ restype = kResourceTypeInvalid;
if ((resnumber < 0) || (resnumber > 1000))
- restype = sci_invalid_resource;
+ restype = kResourceTypeInvalid;
}
}
@@ -140,31 +138,30 @@ int ResourceManager::readResourcePatchesSCI1(ResourceSource *source) {
for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
const Common::String name = (*x)->getName();
- int restype = sci_invalid_resource;
+ ResourceType restype = kResourceTypeInvalid;
int resnumber = -1;
- int i;
char *endptr;
const char *dot = strchr(name.c_str(), '.');
- for (i = sci_view; i < sci_invalid_resource; i++) {
+ for (int i = kResourceTypeView; i < kResourceTypeInvalid; i++) {
if (dot != NULL) {
- if (scumm_strnicmp(sci_resource_type_suffixes[i], dot + 1, 3) == 0) {
- restype = i;
+ if (scumm_strnicmp(getResourceTypeSuffix((ResourceType)i), dot + 1, 3) == 0) {
+ restype = (ResourceType)i;
}
}
}
- if (restype != sci_invalid_resource) {
+ if (restype != kResourceTypeInvalid) {
resnumber = strtol(name.c_str(), &endptr, 10); // Get resource number
if (endptr != dot)
- restype = sci_invalid_resource;
+ restype = kResourceTypeInvalid;
if (*(dot + 4) != '\0')
- restype = sci_invalid_resource;
+ restype = kResourceTypeInvalid;
if ((resnumber < 0) || (resnumber > 8192))
- restype = sci_invalid_resource;
+ restype = kResourceTypeInvalid;
}
process_patch(source, **x, restype, resnumber);
diff --git a/engines/sci/scicore/script.cpp b/engines/sci/scicore/script.cpp
index ab8259c7ec..6651dfdcde 100644
--- a/engines/sci/scicore/script.cpp
+++ b/engines/sci/scicore/script.cpp
@@ -329,7 +329,7 @@ static void script_dump_class(char *data, int seeker, int objsize, const Common:
void script_dissect(ResourceManager *resmgr, int res_no, const Common::StringList &selectorNames) {
int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned int _seeker = 0;
- Resource *script = resmgr->findResource(sci_script, res_no, 0);
+ Resource *script = resmgr->findResource(kResourceTypeScript, res_no, 0);
word_t **words;
int word_count;
diff --git a/engines/sci/scicore/vocab.cpp b/engines/sci/scicore/vocab.cpp
index e6d242328c..9af387b967 100644
--- a/engines/sci/scicore/vocab.cpp
+++ b/engines/sci/scicore/vocab.cpp
@@ -75,12 +75,12 @@ word_t **vocab_get_words(ResourceManager *resmgr, int *word_counter) {
Resource *resource;
// First try to load the SCI0 vocab resource.
- resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0);
+ resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0);
vocab_version = 0;
if (!resource) {
warning("SCI0: Could not find a main vocabulary, trying SCI01");
- resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0);
+ resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0);
vocab_version = 1;
}
@@ -179,7 +179,7 @@ static inline unsigned int inverse_16(unsigned int foo) {
suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) {
int counter = 0;
suffix_t **suffices;
- Resource *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1);
+ Resource *resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1);
unsigned int seeker = 1;
if (!resource) {
@@ -226,8 +226,8 @@ suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) {
void vocab_free_suffices(ResourceManager *resmgr, suffix_t **suffices, int suffices_nr) {
int i;
- resmgr->unlockResource(resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0),
- VOCAB_RESOURCE_SUFFIX_VOCAB, sci_vocab);
+ resmgr->unlockResource(resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0),
+ VOCAB_RESOURCE_SUFFIX_VOCAB, kResourceTypeVocab);
for (i = 0; i < suffices_nr; i++)
free(suffices[i]);
@@ -241,7 +241,7 @@ void vocab_free_branches(parse_tree_branch_t *parser_branches) {
}
parse_tree_branch_t *vocab_get_branches(ResourceManager * resmgr, int *branches_nr) {
- Resource *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0);
+ Resource *resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0);
parse_tree_branch_t *retval;
int i;
diff --git a/engines/sci/scicore/vocab_debug.cpp b/engines/sci/scicore/vocab_debug.cpp
index a2e2739a8f..622dbe559d 100644
--- a/engines/sci/scicore/vocab_debug.cpp
+++ b/engines/sci/scicore/vocab_debug.cpp
@@ -159,7 +159,7 @@ int *vocabulary_get_classes(ResourceManager *resmgr, int* count) {
int *c;
unsigned int i;
- if ((r = resmgr->findResource(sci_vocab, 996, 0)) == NULL)
+ if ((r = resmgr->findResource(kResourceTypeVocab, 996, 0)) == NULL)
return 0;
c = (int *)sci_malloc(sizeof(int) * r->size / 2);
@@ -174,7 +174,7 @@ int *vocabulary_get_classes(ResourceManager *resmgr, int* count) {
int vocabulary_get_class_count(ResourceManager *resmgr) {
Resource* r;
- if ((r = resmgr->findResource(sci_vocab, 996, 0)) == 0)
+ if ((r = resmgr->findResource(kResourceTypeVocab, 996, 0)) == 0)
return 0;
return r->size / 4;
@@ -183,7 +183,7 @@ int vocabulary_get_class_count(ResourceManager *resmgr) {
bool vocabulary_get_snames(ResourceManager *resmgr, sci_version_t version, Common::StringList &selectorNames) {
int count;
- Resource *r = resmgr->findResource(sci_vocab, 997, 0);
+ Resource *r = resmgr->findResource(kResourceTypeVocab, 997, 0);
if (!r) // No such resource?
return false;
@@ -218,7 +218,7 @@ int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char
opcode* vocabulary_get_opcodes(ResourceManager *resmgr) {
opcode* o;
int count, i = 0;
- Resource* r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_OPCODES, 0);
+ Resource* r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES, 0);
// if the resource couldn't be loaded, leave
if (r == NULL) {
@@ -295,7 +295,7 @@ static char **_vocabulary_get_knames0alt(int *names, Resource *r) {
static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) {
char** t;
int count, i, index = 2, empty_to_add = 1;
- Resource *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
+ Resource *r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES, 0);
if (!r) { // No kernel name table found? Fall back to default table
t = (char **)sci_malloc((SCI0_KNAMES_DEFAULT_ENTRIES_NR + 1) * sizeof(char*));
@@ -345,7 +345,7 @@ static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) {
static char **vocabulary_get_knames1(ResourceManager *resmgr, int *count) {
char **t = NULL;
unsigned int size = 64, used = 0, pos = 0;
- Resource *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
+ Resource *r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES, 0);
while (pos < r->size) {
int len;