Fixed regression from commit #49332 (merging of the SCI0 and SCI11 relocate functions, where the SCI0 equivalent had a +1 count): it seems that we should skip over zero exports, however the total number of valid exports remains the same. Fixes KQ5 and QFG2. This also fixes the relocation calculation of script 71 in SQ3, so remove the comment that the script has broken relocation entries

svn-id: r49394
This commit is contained in:
Filippos Karapetis 2010-06-02 15:31:20 +00:00
parent a8deacfc7e
commit c4bdca72d7

View file

@ -101,7 +101,7 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
_localsSegment = 0; _localsSegment = 0;
_localsBlock = NULL; _localsBlock = NULL;
_markedAsDeleted = 0; _markedAsDeleted = false;
} }
Script::~Script() { Script::~Script() {
@ -306,17 +306,20 @@ void Script::relocate(reg_t block) {
"Relocation block outside of script\n"); "Relocation block outside of script\n");
int count = READ_SCI11ENDIAN_UINT16(heap + block.offset); int count = READ_SCI11ENDIAN_UINT16(heap + block.offset);
int exportIndex = 0;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (i * 2)) + heapOffset; int pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset;
// This occurs in SCI01/SCI1 games where every other export // This occurs in SCI01/SCI1 games where every usually one export
// value is zero. I have no idea what it's supposed to mean. // value is zero. It seems that in this situation, we should skip
// // the export and move to the next one, though the total count
// Yes, there is code in the original to handle this situation, // of valid exports remains the same
// but we need an example of it happening in order to determine if (!pos) {
// what to do. exportIndex++;
if (!pos) pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset;
continue; // FIXME: Just ignore it for now. if (!pos)
error("Script::relocate(): Consecutive zero exports found");
}
if (!relocateLocal(block.segment, pos)) { if (!relocateLocal(block.segment, pos)) {
bool done = false; bool done = false;
@ -339,18 +342,19 @@ void Script::relocate(reg_t block) {
} }
if (!done) { if (!done) {
printf("While processing relocation block %04x:%04x:\n", PRINT_REG(block)); debug("While processing relocation block %04x:%04x:\n", PRINT_REG(block));
printf("Relocation failed for index %04x (%d/%d)\n", pos, i + 1, count); debug("Relocation failed for index %04x (%d/%d)\n", pos, exportIndex + 1, count);
if (_localsBlock) if (_localsBlock)
printf("- locals: %d at %04x\n", _localsBlock->_locals.size(), _localsOffset); debug("- locals: %d at %04x\n", _localsBlock->_locals.size(), _localsOffset);
else else
printf("- No locals\n"); debug("- No locals\n");
for (it = _objects.begin(), k = 0; it != end; ++it, ++k) for (it = _objects.begin(), k = 0; it != end; ++it, ++k)
printf("- obj#%d at %04x w/ %d vars\n", k, it->_value.getPos().offset, it->_value.getVarCount()); debug("- obj#%d at %04x w/ %d vars\n", k, it->_value.getPos().offset, it->_value.getVarCount());
// SQ3 script 71 has broken relocation entries. debug("Trying to continue anyway...\n");
printf("Trying to continue anyway...\n");
} }
} }
exportIndex++;
} }
} }