SCI: Move decompress & readResourceInfo to Resource; more cleanup
svn-id: r49835
This commit is contained in:
parent
4392cdaee1
commit
583a966d8c
3 changed files with 49 additions and 48 deletions
|
@ -338,8 +338,7 @@ void MacResourceForkResourceSource::loadResource(Resource *res) {
|
||||||
if (!stream)
|
if (!stream)
|
||||||
error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
|
error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
|
||||||
|
|
||||||
ResourceManager *resMan = g_sci->getResMan();
|
int error = res->decompress(stream);
|
||||||
int error = resMan->decompress(res, stream);
|
|
||||||
if (error) {
|
if (error) {
|
||||||
warning("Error %d occured while reading %s from Mac resource file: %s",
|
warning("Error %d occured while reading %s from Mac resource file: %s",
|
||||||
error, res->_id.toString().c_str(), sci_error_types[error]);
|
error, res->_id.toString().c_str(), sci_error_types[error]);
|
||||||
|
@ -436,8 +435,7 @@ void ResourceSource::loadResource(Resource *res) {
|
||||||
|
|
||||||
fileStream->seek(res->_fileOffset, SEEK_SET);
|
fileStream->seek(res->_fileOffset, SEEK_SET);
|
||||||
|
|
||||||
ResourceManager *resMan = g_sci->getResMan();
|
int error = res->decompress(fileStream);
|
||||||
int error = resMan->decompress(res, fileStream);
|
|
||||||
|
|
||||||
if (_resourceFile)
|
if (_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
|
@ -631,18 +629,18 @@ void ResourceManager::scanNewSources() {
|
||||||
|
|
||||||
void DirectoryResourceSource::scanSource() {
|
void DirectoryResourceSource::scanSource() {
|
||||||
ResourceManager *resMan = g_sci->getResMan();
|
ResourceManager *resMan = g_sci->getResMan();
|
||||||
resMan->readResourcePatches(this);
|
resMan->readResourcePatches();
|
||||||
|
|
||||||
// We can't use getSciVersion() at this point, thus using _volVersion
|
// We can't use getSciVersion() at this point, thus using _volVersion
|
||||||
if (resMan->_volVersion >= ResourceManager::kResVersionSci11) // SCI1.1+
|
if (resMan->_volVersion >= kResVersionSci11) // SCI1.1+
|
||||||
resMan->readResourcePatchesBase36(this);
|
resMan->readResourcePatchesBase36();
|
||||||
|
|
||||||
resMan->readWaveAudioPatches();
|
resMan->readWaveAudioPatches();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtMapResourceSource::scanSource() {
|
void ExtMapResourceSource::scanSource() {
|
||||||
ResourceManager *resMan = g_sci->getResMan();
|
ResourceManager *resMan = g_sci->getResMan();
|
||||||
if (resMan->_mapVersion < ResourceManager::kResVersionSci1Late)
|
if (resMan->_mapVersion < kResVersionSci1Late)
|
||||||
resMan->readResourceMapSCI0(this);
|
resMan->readResourceMapSCI0(this);
|
||||||
else
|
else
|
||||||
resMan->readResourceMapSCI1(this);
|
resMan->readResourceMapSCI1(this);
|
||||||
|
@ -881,7 +879,7 @@ const char *ResourceManager::versionDescription(ResVersion version) const {
|
||||||
return "Version not valid";
|
return "Version not valid";
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceManager::ResVersion ResourceManager::detectMapVersion() {
|
ResVersion ResourceManager::detectMapVersion() {
|
||||||
Common::SeekableReadStream *fileStream = 0;
|
Common::SeekableReadStream *fileStream = 0;
|
||||||
byte buff[6];
|
byte buff[6];
|
||||||
ResourceSource *rsrc= 0;
|
ResourceSource *rsrc= 0;
|
||||||
|
@ -971,7 +969,7 @@ ResourceManager::ResVersion ResourceManager::detectMapVersion() {
|
||||||
return kResVersionUnknown;
|
return kResVersionUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceManager::ResVersion ResourceManager::detectVolVersion() {
|
ResVersion ResourceManager::detectVolVersion() {
|
||||||
Common::SeekableReadStream *fileStream = 0;
|
Common::SeekableReadStream *fileStream = 0;
|
||||||
ResourceSource *rsrc;
|
ResourceSource *rsrc;
|
||||||
|
|
||||||
|
@ -1143,7 +1141,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
|
||||||
debugC(1, kDebugLevelResMan, "Patching %s - OK", source->getLocationName().c_str());
|
debugC(1, kDebugLevelResMan, "Patching %s - OK", source->getLocationName().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::readResourcePatchesBase36(ResourceSource *source) {
|
void ResourceManager::readResourcePatchesBase36() {
|
||||||
// The base36 encoded audio36 and sync36 resources use a different naming scheme, because they
|
// The base36 encoded audio36 and sync36 resources use a different naming scheme, because they
|
||||||
// cannot be described with a single resource number, but are a result of a
|
// cannot be described with a single resource number, but are a result of a
|
||||||
// <number, noun, verb, cond, seq> tuple. Please don't be confused with the normal audio patches
|
// <number, noun, verb, cond, seq> tuple. Please don't be confused with the normal audio patches
|
||||||
|
@ -1227,7 +1225,7 @@ void ResourceManager::readResourcePatchesBase36(ResourceSource *source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::readResourcePatches(ResourceSource *source) {
|
void ResourceManager::readResourcePatches() {
|
||||||
// Note: since some SCI1 games(KQ5 floppy, SQ4) might use SCI0 naming scheme for patch files
|
// 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,
|
// this function tries to read patch file with any supported naming scheme,
|
||||||
// regardless of s_sciVersion value
|
// regardless of s_sciVersion value
|
||||||
|
@ -1515,7 +1513,7 @@ Resource *ResourceManager::updateResource(ResourceId resId, ResourceSource *src,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream *file,
|
int Resource::readResourceInfo(Common::SeekableReadStream *file,
|
||||||
uint32 &szPacked, ResourceCompression &compression) {
|
uint32 &szPacked, ResourceCompression &compression) {
|
||||||
// SCI0 volume format: {wResId wPacked+4 wUnpacked wCompression} = 8 bytes
|
// SCI0 volume format: {wResId wPacked+4 wUnpacked wCompression} = 8 bytes
|
||||||
// SCI1 volume format: {bResType wResNumber wPacked+4 wUnpacked wCompression} = 9 bytes
|
// SCI1 volume format: {bResType wResNumber wPacked+4 wUnpacked wCompression} = 9 bytes
|
||||||
|
@ -1525,7 +1523,8 @@ int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream
|
||||||
uint32 wCompression, szUnpacked;
|
uint32 wCompression, szUnpacked;
|
||||||
ResourceType type;
|
ResourceType type;
|
||||||
|
|
||||||
switch (_volVersion) {
|
ResourceManager *resMan = g_sci->getResMan();
|
||||||
|
switch (resMan->_volVersion) {
|
||||||
case kResVersionSci0Sci1Early:
|
case kResVersionSci0Sci1Early:
|
||||||
case kResVersionSci1Middle:
|
case kResVersionSci1Middle:
|
||||||
w = file->readUint16LE();
|
w = file->readUint16LE();
|
||||||
|
@ -1552,8 +1551,8 @@ int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream
|
||||||
case kResVersionSci11Mac:
|
case kResVersionSci11Mac:
|
||||||
// Doesn't store this data in the resource. Fortunately,
|
// Doesn't store this data in the resource. Fortunately,
|
||||||
// we already have this data.
|
// we already have this data.
|
||||||
type = res->_id.type;
|
type = _id.type;
|
||||||
number = res->_id.number;
|
number = _id.number;
|
||||||
szPacked = file->size();
|
szPacked = file->size();
|
||||||
szUnpacked = file->size();
|
szUnpacked = file->size();
|
||||||
wCompression = 0;
|
wCompression = 0;
|
||||||
|
@ -1575,8 +1574,8 @@ int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream
|
||||||
if ((file->eos() || file->err()))
|
if ((file->eos() || file->err()))
|
||||||
return SCI_ERROR_IO_ERROR;
|
return SCI_ERROR_IO_ERROR;
|
||||||
|
|
||||||
res->_id = ResourceId(type, number);
|
_id = ResourceId(type, number);
|
||||||
res->size = szUnpacked;
|
size = szUnpacked;
|
||||||
|
|
||||||
// checking compression method
|
// checking compression method
|
||||||
switch (wCompression) {
|
switch (wCompression) {
|
||||||
|
@ -1612,13 +1611,13 @@ int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream
|
||||||
return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0;
|
return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResourceManager::decompress(Resource *res, Common::SeekableReadStream *file) {
|
int Resource::decompress(Common::SeekableReadStream *file) {
|
||||||
int error;
|
int error;
|
||||||
uint32 szPacked = 0;
|
uint32 szPacked = 0;
|
||||||
ResourceCompression compression = kCompUnknown;
|
ResourceCompression compression = kCompUnknown;
|
||||||
|
|
||||||
// fill resource info
|
// fill resource info
|
||||||
error = readResourceInfo(res, file, szPacked, compression);
|
error = readResourceInfo(file, szPacked, compression);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
@ -1646,15 +1645,15 @@ int ResourceManager::decompress(Resource *res, Common::SeekableReadStream *file)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
warning("Resource %s: Compression method %d not supported", res->_id.toString().c_str(), compression);
|
warning("Resource %s: Compression method %d not supported", _id.toString().c_str(), compression);
|
||||||
return SCI_ERROR_UNKNOWN_COMPRESSION;
|
return SCI_ERROR_UNKNOWN_COMPRESSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
res->data = new byte[res->size];
|
data = new byte[size];
|
||||||
res->_status = kResStatusAllocated;
|
_status = kResStatusAllocated;
|
||||||
error = res->data ? dec->unpack(file, res->data, szPacked, res->size) : SCI_ERROR_RESOURCE_TOO_BIG;
|
error = data ? dec->unpack(file, data, szPacked, size) : SCI_ERROR_RESOURCE_TOO_BIG;
|
||||||
if (error)
|
if (error)
|
||||||
res->unalloc();
|
unalloc();
|
||||||
|
|
||||||
delete dec;
|
delete dec;
|
||||||
return error;
|
return error;
|
||||||
|
@ -1683,7 +1682,7 @@ ResourceCompression ResourceManager::getViewCompression() {
|
||||||
uint32 szPacked;
|
uint32 szPacked;
|
||||||
ResourceCompression compression;
|
ResourceCompression compression;
|
||||||
|
|
||||||
if (readResourceInfo(res, fileStream, szPacked, compression)) {
|
if (res->readResourceInfo(fileStream, szPacked, compression)) {
|
||||||
if (res->_source->_resourceFile)
|
if (res->_source->_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -167,6 +167,7 @@ class Resource {
|
||||||
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
||||||
// ease transition to the ResourceSource class system.
|
// ease transition to the ResourceSource class system.
|
||||||
friend class ResourceSource;
|
friend class ResourceSource;
|
||||||
|
friend class PatchResourceSource;
|
||||||
friend class WaveResourceSource;
|
friend class WaveResourceSource;
|
||||||
friend class AudioVolumeResourceSource;
|
friend class AudioVolumeResourceSource;
|
||||||
friend class MacResourceForkResourceSource;
|
friend class MacResourceForkResourceSource;
|
||||||
|
@ -192,24 +193,37 @@ public:
|
||||||
void writeToStream(Common::WriteStream *stream) const;
|
void writeToStream(Common::WriteStream *stream) const;
|
||||||
uint32 getAudioCompressionType() const;
|
uint32 getAudioCompressionType() const;
|
||||||
|
|
||||||
bool loadPatch(Common::SeekableReadStream *file);
|
|
||||||
bool loadFromPatchFile();
|
|
||||||
bool loadFromWaveFile(Common::SeekableReadStream *file);
|
|
||||||
bool loadFromAudioVolumeSCI1(Common::SeekableReadStream *file);
|
|
||||||
bool loadFromAudioVolumeSCI11(Common::SeekableReadStream *file);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32 _fileOffset; /**< Offset in file */
|
int32 _fileOffset; /**< Offset in file */
|
||||||
ResourceStatus _status;
|
ResourceStatus _status;
|
||||||
uint16 _lockers; /**< Number of places where this resource was locked */
|
uint16 _lockers; /**< Number of places where this resource was locked */
|
||||||
ResourceSource *_source;
|
ResourceSource *_source;
|
||||||
|
|
||||||
|
bool loadPatch(Common::SeekableReadStream *file);
|
||||||
|
bool loadFromPatchFile();
|
||||||
|
bool loadFromWaveFile(Common::SeekableReadStream *file);
|
||||||
|
bool loadFromAudioVolumeSCI1(Common::SeekableReadStream *file);
|
||||||
|
bool loadFromAudioVolumeSCI11(Common::SeekableReadStream *file);
|
||||||
|
int decompress(Common::SeekableReadStream *file);
|
||||||
|
int readResourceInfo(Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualTo> ResourceMap;
|
typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualTo> ResourceMap;
|
||||||
|
|
||||||
|
enum ResVersion {
|
||||||
|
kResVersionUnknown,
|
||||||
|
kResVersionSci0Sci1Early,
|
||||||
|
kResVersionSci1Middle,
|
||||||
|
kResVersionSci1Late,
|
||||||
|
kResVersionSci11,
|
||||||
|
kResVersionSci11Mac,
|
||||||
|
kResVersionSci32
|
||||||
|
};
|
||||||
|
|
||||||
class ResourceManager {
|
class ResourceManager {
|
||||||
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
||||||
// ease transition to the ResourceSource class system.
|
// ease transition to the ResourceSource class system.
|
||||||
|
friend class Resource; // For _volVersion
|
||||||
friend class ResourceSource;
|
friend class ResourceSource;
|
||||||
friend class DirectoryResourceSource;
|
friend class DirectoryResourceSource;
|
||||||
friend class PatchResourceSource;
|
friend class PatchResourceSource;
|
||||||
|
@ -221,16 +235,6 @@ class ResourceManager {
|
||||||
friend class MacResourceForkResourceSource;
|
friend class MacResourceForkResourceSource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ResVersion {
|
|
||||||
kResVersionUnknown,
|
|
||||||
kResVersionSci0Sci1Early,
|
|
||||||
kResVersionSci1Middle,
|
|
||||||
kResVersionSci1Late,
|
|
||||||
kResVersionSci11,
|
|
||||||
kResVersionSci11Mac,
|
|
||||||
kResVersionSci32
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SCI resource manager.
|
* Creates a new SCI resource manager.
|
||||||
*/
|
*/
|
||||||
|
@ -393,8 +397,6 @@ protected:
|
||||||
Common::SeekableReadStream *getVolumeFile(ResourceSource *source);
|
Common::SeekableReadStream *getVolumeFile(ResourceSource *source);
|
||||||
void loadResource(Resource *res);
|
void loadResource(Resource *res);
|
||||||
void freeOldResources();
|
void freeOldResources();
|
||||||
int decompress(Resource *res, Common::SeekableReadStream *file);
|
|
||||||
int readResourceInfo(Resource *res, Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
|
|
||||||
void addResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size = 0);
|
void addResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size = 0);
|
||||||
Resource *updateResource(ResourceId resId, ResourceSource *src, uint32 size);
|
Resource *updateResource(ResourceId resId, ResourceSource *src, uint32 size);
|
||||||
void removeAudioResource(ResourceId resId);
|
void removeAudioResource(ResourceId resId);
|
||||||
|
@ -437,8 +439,8 @@ protected:
|
||||||
/**
|
/**
|
||||||
* Reads patch files from a local directory.
|
* Reads patch files from a local directory.
|
||||||
*/
|
*/
|
||||||
void readResourcePatches(ResourceSource *source);
|
void readResourcePatches();
|
||||||
void readResourcePatchesBase36(ResourceSource *source);
|
void readResourcePatchesBase36();
|
||||||
void processPatch(ResourceSource *source, ResourceType resourceType, uint16 resourceNr, uint32 tuple = 0);
|
void processPatch(ResourceSource *source, ResourceType resourceType, uint16 resourceNr, uint32 tuple = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -319,8 +319,8 @@ int ResourceManager::readAudioMapSCI11(ResourceSource *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n & 0x40) {
|
if (n & 0x40) {
|
||||||
// This seems to define the size of raw lipsync data (at least in kq6), may also just be general appended
|
// This seems to define the size of raw lipsync data (at least
|
||||||
// data
|
// in kq6), may also just be general appended data.
|
||||||
syncSize += READ_LE_UINT16(ptr);
|
syncSize += READ_LE_UINT16(ptr);
|
||||||
ptr += 2;
|
ptr += 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue