int Script::relocateOffsetSci3(uint32 offset) const { int relocStart = _buf->getUint32LEAt(8); int relocCount = _buf->getUint16LEAt(18); SciSpan<const byte> seeker = _buf->subspan(relocStart); for (int i = 0; i < relocCount; ++i) { if (seeker.getUint32SEAt(0) == offset) { return _buf->getUint16SEAt(offset) + seeker.getUint32SEAt(4); } seeker += 10; } return -1; }
void Script::relocateSci3(const SegmentId segmentId) { SciSpan<const byte> relocEntry = _buf->subspan(_buf->getUint32SEAt(8)); const uint relocCount = _buf->getUint16SEAt(18); for (uint i = 0; i < relocCount; ++i) { const uint location = relocEntry.getUint32SEAt(0); const uint offset = relocEntry.getUint32SEAt(4); if (!relocateLocal(segmentId, location, offset)) { const ObjMap::iterator end = _objects.end(); for (ObjMap::iterator it = _objects.begin(); it != end; ++it) { if (it->_value.relocateSci3(segmentId, location, offset, _script.size())) { break; } } } relocEntry += 10; } }
uint32 Script::getRelocationOffset(const uint32 offset) const { if (getSciVersion() == SCI_VERSION_3) { SciSpan<const byte> relocStart = _buf->subspan(_buf->getUint32SEAt(8)); const uint relocCount = _buf->getUint16SEAt(18); for (uint i = 0; i < relocCount; ++i) { if (offset == relocStart.getUint32SEAt(0)) { return relocStart.getUint32SEAt(4); } relocStart += 10; } } else { const SciSpan<const uint16> relocTable = getRelocationTableSci0Sci21(); for (uint i = 0; i < relocTable.size(); ++i) { if (relocTable.getUint16SEAt(i) == offset) { return getHeapOffset(); } } } return kNoRelocation; }