SCI: Fix support for ScummVM compressed audio volumes

The runtime code for this had previously relied on hot patching
volume file offsets at the moment that a resource was loaded,
instead of correcting file offsets when reading audio maps. The
code added for sanity checking audio volumes started to report
warnings because the offsets being received were for the original
uncompressed audio volume, which (naturally) is larger than the
compressed audio volume.

This commit also deduplicates code between addResource and
updateResource, and tweaks a validation-related error message for
improved clarity.

Fixes Trac#9764.
This commit is contained in:
Colin Snover 2017-05-10 00:33:43 -05:00
parent 53b0b82e87
commit dd13c3be43
3 changed files with 74 additions and 94 deletions

View file

@ -2013,20 +2013,7 @@ bool ResourceManager::validateResource(const ResourceId &resourceId, const Commo
void ResourceManager::addResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size, const Common::String &sourceMapLocation) {
// Adding new resource only if it does not exist
if (_resMap.contains(resId) == false) {
Common::SeekableReadStream *volumeFile = getVolumeFile(src);
if (volumeFile == nullptr) {
error("Could not open %s for reading", src->getLocationName().c_str());
}
if (validateResource(resId, sourceMapLocation, src->getLocationName(), offset, size, volumeFile->size())) {
Resource *res = new Resource(this, resId);
_resMap.setVal(resId, res);
res->_source = src;
res->_fileOffset = offset;
res->_size = size;
} else {
_hasBadResources = true;
}
updateResource(resId, src, offset, size, sourceMapLocation);
}
}
@ -2048,6 +2035,13 @@ Resource *ResourceManager::updateResource(ResourceId resId, ResourceSource *src,
error("Could not open %s for reading", src->getLocationName().c_str());
}
AudioVolumeResourceSource *avSrc = dynamic_cast<AudioVolumeResourceSource *>(src);
if (avSrc != nullptr && !avSrc->relocateMapOffset(offset, size)) {
warning("Compressed volume %s does not contain a valid entry for %s (map offset %u)", src->getLocationName().c_str(), resId.toString().c_str(), offset);
_hasBadResources = true;
return res;
}
if (validateResource(resId, sourceMapLocation, src->getLocationName(), offset, size, volumeFile->size())) {
if (res == nullptr) {
res = new Resource(this, resId);