Fixing problems with the texts table in TOT files when the order of the texts and resources tables are switched in the TOT file

svn-id: r48124
This commit is contained in:
Sven Hesse 2010-02-25 15:22:26 +00:00
parent 151889a767
commit 6e07e3e642
3 changed files with 53 additions and 20 deletions

View File

@ -350,16 +350,13 @@ bool Resources::loadTOTTextTable(const Common::String &fileBase) {
_totTextTable = new TOTTextTable;
bool fromTOT;
if (totProps.textsOffset == 0) {
fromTOT = false;
_totTextTable->data = loadTOTLocTexts(fileBase, _totTextTable->size);
_totTextTable->needFree = true;
} else {
fromTOT = true;
_totTextTable->data = _totData + totProps.textsOffset - _totResStart;
_totTextTable->needFree = false;
_totTextTable->size = _totSize - totProps.textsOffset;
_totTextTable->size = totProps.textsSize;
}
if (_totTextTable->data) {
@ -372,9 +369,6 @@ bool Resources::loadTOTTextTable(const Common::String &fileBase) {
item.offset = totTextTable.readSint16LE();
item.size = totTextTable.readSint16LE();
if (fromTOT)
item.offset -= (totProps.textsOffset - _totResStart);
}
}
@ -572,14 +566,11 @@ TextItem *Resources::getTextItem(uint16 id) const {
if ((totItem.offset == 0xFFFF) || (totItem.size == 0))
return 0;
if ((totItem.offset + totItem.size) > (_totTextTable->size)) {
// HACK: Some Fascination versions (Amiga, Atari and first PC floppies) have a different header, which is a problem here.
// Playtoons also have the same problem (and workaround).
// TODO: Handle that in a proper way
if (((_vm->getGameType() == kGameTypeFascination) || (_vm->getGameType() == kGameTypePlaytoons)) && (_totTextTable->size < 0))
warning("totTextTable with negative size id:%d offset:%d in file %s : (size: %d)", id, totItem.offset, _totFile.c_str(), _totTextTable->size);
else
return 0;
warning("TOT text %d offset %d out of range (%s, %d, %d)",
id, totItem.offset, _totFile.c_str(), _totSize, totItem.size);
return 0;
}
return new TextItem(_totTextTable->data + totItem.offset, totItem.size);
@ -710,7 +701,8 @@ byte *Resources::getTOTData(TOTResourceItem &totItem) const {
int32 offset = _totResourceTable->dataOffset + totItem.offset - _totResStart;
if ((offset < 0) || (((uint32) (offset + totItem.size)) > _totSize)) {
warning("Skipping data id:%d offset:%d size :%d in file %s : out of _totTextTable", totItem.index, totItem.offset, totItem.size, _totFile.c_str());
warning("TOT data %d offset %d out of range (%s, %d, %d)",
totItem.index, totItem.offset, _totFile.c_str(), _totSize, totItem.size);
return 0;
}

View File

@ -97,11 +97,50 @@ bool TOTFile::getProperties(Properties &props) const {
for (int i = 0; i < 14; i++)
props.functions[i] = READ_LE_UINT16(_header + 100 + i * 2);
props.scriptEnd = _stream->size();
if (props.textsOffset > 0)
props.scriptEnd = MIN(props.scriptEnd, props.textsOffset);
if (props.resourcesOffset > 0)
props.scriptEnd = MIN(props.scriptEnd, props.resourcesOffset);
uint32 fileSize = _stream->size();
uint32 textsOffset = props.textsOffset;
uint32 resourcesOffset = props.resourcesOffset;
if (textsOffset == 0xFFFFFFFF)
textsOffset = 0;
if (resourcesOffset == 0xFFFFFFFF)
resourcesOffset = 0;
props.scriptEnd = fileSize;
if (textsOffset > 0)
props.scriptEnd = MIN(props.scriptEnd, textsOffset);
if (resourcesOffset > 0)
props.scriptEnd = MIN(props.scriptEnd, resourcesOffset);
// Calculate the sizes of the texts and resources tables for every possible order
if ((textsOffset > 0) && (resourcesOffset > 0)) {
// Both exists
if (props.textsOffset > resourcesOffset) {
// First resources, then texts
props.textsSize = fileSize - textsOffset;
props.resourcesSize = textsOffset - resourcesOffset;
} else {
// First texts, then resources
props.textsSize = resourcesOffset - textsOffset;
props.resourcesSize = fileSize - resourcesOffset;
}
} else if (textsOffset > 0) {
// Only the texts table exists
props.textsSize = fileSize - textsOffset;
props.resourcesSize = 0;
} else if (resourcesOffset > 0) {
// Only the resources table exists
props.textsSize = 0;
props.resourcesSize = fileSize - resourcesOffset;
} else {
// Both don't exists
props.textsSize = 0;
props.resourcesSize = 0;
}
return true;
}

View File

@ -53,6 +53,8 @@ public:
uint8 communHandling;
uint16 functions[14];
uint32 scriptEnd;
uint32 textsSize;
uint32 resourcesSize;
};
TOTFile(GobEngine *vm);