From 9c8ff41181955048abd602f1d58639e2082182c7 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 14 Jun 2012 12:14:04 +0300 Subject: SCI: Add known large SCI3 scripts --- engines/sci/engine/script.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 8b26969f4a..5f0118b5b6 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -115,6 +115,13 @@ void Script::init(int script_nr, ResourceManager *resMan) { // scheme. We need an overlaying mechanism, or a mechanism to split script parts // in different segments to handle these. For now, simply stop when such a script // is found. + // + // Known large SCI 3 scripts are: + // Lighthouse: 9, 220, 270, 351, 360, 490, 760, 765, 800 + // LSL7: 240, 511, 550 + // Phantasmagoria 2: none (hooray!) + // RAMA: 70 + // // TODO: Remove this once such a mechanism is in place if (script->size > 65535) error("TODO: SCI script %d is over 64KB - it's %d bytes long. This can't " -- cgit v1.2.3 From 577d7e41c9ca2c498dc85e41c373fbdca8d2ed41 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 11:44:54 +0300 Subject: SCI: Change Script::getObject() to accept a reg_t This is needed for upcoming changes to the Script class --- engines/sci/engine/script.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 5f0118b5b6..08f7922b1e 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -243,16 +243,16 @@ const byte *Script::getSci3ObjectsPointer() { return ptr; } -Object *Script::getObject(uint16 offset) { - if (_objects.contains(offset)) - return &_objects[offset]; +Object *Script::getObject(reg_t pos) { + if (_objects.contains(pos.offset)) + return &_objects[pos.offset]; else return 0; } -const Object *Script::getObject(uint16 offset) const { - if (_objects.contains(offset)) - return &_objects[offset]; +const Object *Script::getObject(reg_t pos) const { + if (_objects.contains(pos.offset)) + return &_objects[pos.offset]; else return 0; } @@ -746,7 +746,7 @@ Common::Array Script::listAllDeallocatable(SegmentId segId) const { Common::Array Script::listAllOutgoingReferences(reg_t addr) const { Common::Array tmp; if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) { - const Object *obj = getObject(addr.offset); + const Object *obj = getObject(addr); if (obj) { // Note all local variables, if we have a local variable environment if (_localsSegment) -- cgit v1.2.3 From e1ae1108601cce0ad7aeab5f3e017f630f02e7ea Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 11:48:56 +0300 Subject: SCI: Clean up the script initialization code --- engines/sci/engine/script.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 08f7922b1e..f8c5539325 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -37,17 +37,22 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) { _buf = NULL; _bufSize = 0; _scriptSize = 0; - _heapSize = 0; - _synonyms = NULL; _heapStart = NULL; + _heapSize = 0; + _exportTable = NULL; + _numExports = 0; + _synonyms = NULL; + _numSynonyms = 0; _localsOffset = 0; _localsSegment = 0; _localsBlock = NULL; _localsCount = 0; + _lockers = 1; + _markedAsDeleted = false; } @@ -65,25 +70,11 @@ void Script::freeScript() { void Script::init(int script_nr, ResourceManager *resMan) { Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - if (!script) error("Script %d not found", script_nr); - _localsOffset = 0; - _localsBlock = NULL; - _localsCount = 0; - - _markedAsDeleted = false; - _nr = script_nr; - _buf = 0; - _heapStart = 0; - - _scriptSize = script->size; - _bufSize = script->size; - _heapSize = 0; - - _lockers = 1; + _bufSize = _scriptSize = script->size; if (getSciVersion() == SCI_VERSION_0_EARLY) { _bufSize += READ_LE_UINT16(script->data) * 2; @@ -163,11 +154,6 @@ void Script::load(ResourceManager *resMan) { memcpy(_heapStart, heap->data, heap->size); } - _exportTable = 0; - _numExports = 0; - _synonyms = 0; - _numSynonyms = 0; - if (getSciVersion() <= SCI_VERSION_1_LATE) { _exportTable = (const uint16 *)findBlockSCI0(SCI_OBJ_EXPORTS); if (_exportTable) { -- cgit v1.2.3 From 9aaefbd53665cd03359ad692d64e3fc437f97202 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 11:53:19 +0300 Subject: SCI: _propertyOffsetsSci3 and classpos should be 32-bit integers These are needed for future handling of large SCI3 script files --- engines/sci/engine/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index f8c5539325..18e23f36b5 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -546,7 +546,7 @@ void Script::initializeClasses(SegManager *segMan) { uint16 marker; bool isClass = false; - uint16 classpos; + uint32 classpos; int16 species = 0; while (true) { -- cgit v1.2.3 From 562a8a980c22eab85144558050e5fa5e425612c4 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 12:53:17 +0300 Subject: SCI: Further cleanup of the script code Merge the init() and load() Script methods and reset the script when necessary --- engines/sci/engine/script.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 18e23f36b5..7714983120 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -32,12 +32,21 @@ namespace Sci { -Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) { +Script::Script() : SegmentObj(SEG_TYPE_SCRIPT), _buf(NULL) { + freeScript(); +} + +Script::~Script() { + freeScript(); +} + +void Script::freeScript() { _nr = 0; + + free(_buf); _buf = NULL; _bufSize = 0; _scriptSize = 0; - _heapStart = NULL; _heapSize = 0; @@ -52,23 +61,13 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) { _localsCount = 0; _lockers = 1; - _markedAsDeleted = false; + _objects.clear(); } -Script::~Script() { +void Script::load(int script_nr, ResourceManager *resMan) { freeScript(); -} - -void Script::freeScript() { - free(_buf); - _buf = NULL; - _bufSize = 0; - - _objects.clear(); -} -void Script::init(int script_nr, ResourceManager *resMan) { Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0); if (!script) error("Script %d not found", script_nr); @@ -118,11 +117,6 @@ void Script::init(int script_nr, ResourceManager *resMan) { error("TODO: SCI script %d is over 64KB - it's %d bytes long. This can't " "be handled at the moment, thus stopping", script_nr, script->size); } -} - -void Script::load(ResourceManager *resMan) { - Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0); - assert(script != 0); uint extraLocalsWorkaround = 0; if (g_sci->getGameId() == GID_FANMADE && _nr == 1 && script->size == 11140) { -- cgit v1.2.3 From 160732b2f73a5df173c1fa867f82fa2913ec2236 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 21:47:22 +0300 Subject: Revert "SCI: Change Script::getObject() to accept a reg_t" This reverts commit 577d7e41c9ca2c498dc85e41c373fbdca8d2ed41. --- engines/sci/engine/script.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 7714983120..0ed9598b41 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -223,16 +223,16 @@ const byte *Script::getSci3ObjectsPointer() { return ptr; } -Object *Script::getObject(reg_t pos) { - if (_objects.contains(pos.offset)) - return &_objects[pos.offset]; +Object *Script::getObject(uint16 offset) { + if (_objects.contains(offset)) + return &_objects[offset]; else return 0; } -const Object *Script::getObject(reg_t pos) const { - if (_objects.contains(pos.offset)) - return &_objects[pos.offset]; +const Object *Script::getObject(uint16 offset) const { + if (_objects.contains(offset)) + return &_objects[offset]; else return 0; } @@ -726,7 +726,7 @@ Common::Array Script::listAllDeallocatable(SegmentId segId) const { Common::Array Script::listAllOutgoingReferences(reg_t addr) const { Common::Array tmp; if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) { - const Object *obj = getObject(addr); + const Object *obj = getObject(addr.offset); if (obj) { // Note all local variables, if we have a local variable environment if (_localsSegment) -- cgit v1.2.3 From 5ca22a1104d2e1ca0a7b7f5ac159b5c721e13ead Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 21:52:03 +0300 Subject: SCI: Fix warnings Thanks to DrMcCoy for reporting them --- engines/sci/engine/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 0ed9598b41..ca7eaad383 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -199,7 +199,7 @@ void Script::load(int script_nr, ResourceManager *resMan) { _localsOffset = 0; if (_localsOffset + _localsCount * 2 + 1 >= (int)_bufSize) { - error("Locals extend beyond end of script: offset %04x, count %d vs size %d", _localsOffset, _localsCount, _bufSize); + error("Locals extend beyond end of script: offset %04x, count %d vs size %d", _localsOffset, _localsCount, (int)_bufSize); //_localsCount = (_bufSize - _localsOffset) >> 1; } } -- cgit v1.2.3 From 041b1447c02616c0f285556bb453e79268da7dce Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 22:02:13 +0300 Subject: SCI: Replace RAW_IS_OBJECT with a method --- engines/sci/engine/script.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index ca7eaad383..d09b5ace80 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -725,7 +725,7 @@ Common::Array Script::listAllDeallocatable(SegmentId segId) const { Common::Array Script::listAllOutgoingReferences(reg_t addr) const { Common::Array tmp; - if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) { + if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && offsetIsObject(addr.offset)) { const Object *obj = getObject(addr.offset); if (obj) { // Note all local variables, if we have a local variable environment @@ -761,4 +761,8 @@ Common::Array Script::listObjectReferences() const { return tmp; } +bool Script::offsetIsObject(uint16 offset) const { + return (READ_SCI11ENDIAN_UINT16((const byte *)_buf + offset + SCRIPT_OBJECT_MAGIC_OFFSET) == SCRIPT_OBJECT_MAGIC_NUMBER); +} + } // End of namespace Sci -- cgit v1.2.3 From a0add53c6003a8ed42324d4bacc7f4745ee25543 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 15 Jun 2012 22:24:35 +0300 Subject: SCI: Change getClassAddress() to only require the caller segment The caller offset is never actually used inside the function --- engines/sci/engine/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index d09b5ace80..d018872b43 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -653,7 +653,7 @@ void Script::initializeObjectsSci11(SegManager *segMan, SegmentId segmentId) { // Copy base from species class, as we need its selector IDs obj->setSuperClassSelector( - segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, NULL_REG)); + segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, 0)); // If object is instance, get -propDict- from class and set it for this // object. This is needed for ::isMemberOf() to work. @@ -686,7 +686,7 @@ void Script::initializeObjectsSci3(SegManager *segMan, SegmentId segmentId) { reg_t reg = make_reg(segmentId, seeker - _buf); Object *obj = scriptObjInit(reg); - obj->setSuperClassSelector(segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, NULL_REG)); + obj->setSuperClassSelector(segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, 0)); seeker += READ_SCI11ENDIAN_UINT16(seeker + 2); } -- cgit v1.2.3 From 2b50824133ced47f1d8fb6407a1e0212a7eeb41c Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 18 Jun 2012 05:21:59 +0300 Subject: SCI: Add setter/getter methods to reg_t's No functionality change has been made with this commit. This avoids setting and getting the reg_t members directly, and is the basis of any future work on large SCI3 scripts (larger than 64KB) --- engines/sci/engine/script.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index d018872b43..897ceccad3 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -239,14 +239,14 @@ const Object *Script::getObject(uint16 offset) const { Object *Script::scriptObjInit(reg_t obj_pos, bool fullObjectInit) { if (getSciVersion() < SCI_VERSION_1_1 && fullObjectInit) - obj_pos.offset += 8; // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET) + obj_pos.incOffset(8); // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET) - if (obj_pos.offset >= _bufSize) + if (obj_pos.getOffset() >= _bufSize) error("Attempt to initialize object beyond end of script"); // Get the object at the specified position and init it. This will // automatically "allocate" space for it in the _objects map if necessary. - Object *obj = &_objects[obj_pos.offset]; + Object *obj = &_objects[obj_pos.getOffset()]; obj->init(_buf, obj_pos, fullObjectInit); return obj; @@ -269,9 +269,9 @@ static bool relocateBlock(Common::Array &block, int block_location, Segme error("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location); return false; } - block[idx].segment = segment; // Perform relocation + block[idx].setSegment(segment); // Perform relocation if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) - block[idx].offset += scriptSize; + block[idx].incOffset(scriptSize); return true; } @@ -310,23 +310,23 @@ void Script::relocateSci0Sci21(reg_t block) { heapOffset = _scriptSize; } - if (block.offset >= (uint16)heapSize || - READ_SCI11ENDIAN_UINT16(heap + block.offset) * 2 + block.offset >= (uint16)heapSize) + if (block.getOffset() >= (uint16)heapSize || + READ_SCI11ENDIAN_UINT16(heap + block.getOffset()) * 2 + block.getOffset() >= (uint16)heapSize) error("Relocation block outside of script"); - int count = READ_SCI11ENDIAN_UINT16(heap + block.offset); + int count = READ_SCI11ENDIAN_UINT16(heap + block.getOffset()); int exportIndex = 0; int pos = 0; for (int i = 0; i < count; i++) { - pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; + pos = READ_SCI11ENDIAN_UINT16(heap + block.getOffset() + 2 + (exportIndex * 2)) + heapOffset; // This occurs in SCI01/SCI1 games where usually one export value is // zero. It seems that in this situation, we should skip the export and // move to the next one, though the total count of valid exports remains // the same if (!pos) { exportIndex++; - pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; + pos = READ_SCI11ENDIAN_UINT16(heap + block.getOffset() + 2 + (exportIndex * 2)) + heapOffset; if (!pos) error("Script::relocate(): Consecutive zero exports found"); } @@ -335,12 +335,12 @@ void Script::relocateSci0Sci21(reg_t block) { // We only relocate locals and objects here, and ignore relocation of // code blocks. In SCI1.1 and newer versions, only locals and objects // are relocated. - if (!relocateLocal(block.segment, pos)) { + if (!relocateLocal(block.getSegment(), pos)) { // Not a local? It's probably an object or code block. If it's an // object, relocate it. const ObjMap::iterator end = _objects.end(); for (ObjMap::iterator it = _objects.begin(); it != end; ++it) - if (it->_value.relocateSci0Sci21(block.segment, pos, _scriptSize)) + if (it->_value.relocateSci0Sci21(block.getSegment(), pos, _scriptSize)) break; } @@ -357,7 +357,7 @@ void Script::relocateSci3(reg_t block) { const byte *seeker = relocStart; while (seeker < _buf + _bufSize) { // TODO: Find out what UINT16 at (seeker + 8) means - it->_value.relocateSci3(block.segment, + it->_value.relocateSci3(block.getSegment(), READ_SCI11ENDIAN_UINT32(seeker), READ_SCI11ENDIAN_UINT32(seeker + 4), _scriptSize); @@ -466,7 +466,7 @@ bool Script::isValidOffset(uint16 offset) const { } SegmentRef Script::dereference(reg_t pointer) { - if (pointer.offset > _bufSize) { + if (pointer.getOffset() > _bufSize) { error("Script::dereference(): Attempt to dereference invalid pointer %04x:%04x into script segment (script size=%d)", PRINT_REG(pointer), (uint)_bufSize); return SegmentRef(); @@ -474,8 +474,8 @@ SegmentRef Script::dereference(reg_t pointer) { SegmentRef ret; ret.isRaw = true; - ret.maxSize = _bufSize - pointer.offset; - ret.raw = _buf + pointer.offset; + ret.maxSize = _bufSize - pointer.getOffset(); + ret.raw = _buf + pointer.getOffset(); return ret; } @@ -653,7 +653,7 @@ void Script::initializeObjectsSci11(SegManager *segMan, SegmentId segmentId) { // Copy base from species class, as we need its selector IDs obj->setSuperClassSelector( - segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, 0)); + segMan->getClassAddress(obj->getSuperClassSelector().getOffset(), SCRIPT_GET_LOCK, 0)); // If object is instance, get -propDict- from class and set it for this // object. This is needed for ::isMemberOf() to work. @@ -686,7 +686,7 @@ void Script::initializeObjectsSci3(SegManager *segMan, SegmentId segmentId) { reg_t reg = make_reg(segmentId, seeker - _buf); Object *obj = scriptObjInit(reg); - obj->setSuperClassSelector(segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, 0)); + obj->setSuperClassSelector(segMan->getClassAddress(obj->getSuperClassSelector().getOffset(), SCRIPT_GET_LOCK, 0)); seeker += READ_SCI11ENDIAN_UINT16(seeker + 2); } @@ -703,7 +703,7 @@ void Script::initializeObjects(SegManager *segMan, SegmentId segmentId) { } reg_t Script::findCanonicAddress(SegManager *segMan, reg_t addr) const { - addr.offset = 0; + addr.setOffset(0); return addr; } @@ -725,8 +725,8 @@ Common::Array Script::listAllDeallocatable(SegmentId segId) const { Common::Array Script::listAllOutgoingReferences(reg_t addr) const { Common::Array tmp; - if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && offsetIsObject(addr.offset)) { - const Object *obj = getObject(addr.offset); + if (addr.getOffset() <= _bufSize && addr.getOffset() >= (uint)-SCRIPT_OBJECT_MAGIC_OFFSET && offsetIsObject(addr.getOffset())) { + const Object *obj = getObject(addr.getOffset()); if (obj) { // Note all local variables, if we have a local variable environment if (_localsSegment) -- cgit v1.2.3 From c1eb93bc5a9866787f27add5ca1d821e1470a4be Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 23 Jun 2012 21:20:43 +0300 Subject: SCI: Clean up validateExportFunc() and related functions Also renamed some SCI3 related code to indicate when it's SCI3 specific --- engines/sci/engine/script.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 897ceccad3..80aaedfece 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -385,7 +385,7 @@ void Script::setLockers(int lockers) { _lockers = lockers; } -uint16 Script::validateExportFunc(int pubfunct, bool relocate) { +uint16 Script::validateExportFunc(int pubfunct, bool relocateSci3) { bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); if (_numExports <= pubfunct) { @@ -398,15 +398,15 @@ uint16 Script::validateExportFunc(int pubfunct, bool relocate) { uint16 offset; - if (getSciVersion() != SCI_VERSION_3 || !relocate) { + if (getSciVersion() != SCI_VERSION_3) { offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct); } else { - offset = relocateOffsetSci3(pubfunct * 2 + 22); + if (!relocateSci3) + offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct) + getCodeBlockOffsetSci3(); + else + offset = relocateOffsetSci3(pubfunct * 2 + 22); } - if (offset >= _bufSize) - error("Invalid export function pointer"); - // Check if the offset found points to a second export table (e.g. script 912 // in Camelot and script 306 in KQ4). Such offsets are usually small (i.e. < 10), // thus easily distinguished from actual code offsets. @@ -419,11 +419,23 @@ uint16 Script::validateExportFunc(int pubfunct, bool relocate) { if (secondExportTable) { secondExportTable += 3; // skip header plus 2 bytes (secondExportTable is a uint16 pointer) offset = READ_SCI11ENDIAN_UINT16(secondExportTable + pubfunct); - if (offset >= _bufSize) - error("Invalid export function pointer"); } } + if (!offset) { +#ifdef ENABLE_SCI32 + // WORKAROUNDS for invalid (empty) exports + if (g_sci->getGameId() == GID_TORIN && _nr == 64036) { + } else if (g_sci->getGameId() == GID_RAMA && _nr == 64908) { + } else +#endif + error("Request for invalid exported function 0x%x of script %d", pubfunct, _nr); + return NULL; + } + + if (offset >= _bufSize) + error("Invalid export function pointer"); + return offset; } @@ -551,7 +563,7 @@ void Script::initializeClasses(SegManager *segMan) { if (getSciVersion() <= SCI_VERSION_1_LATE && !marker) break; - if (getSciVersion() >= SCI_VERSION_1_1 && marker != 0x1234) + if (getSciVersion() >= SCI_VERSION_1_1 && marker != SCRIPT_OBJECT_MAGIC_NUMBER) break; if (getSciVersion() <= SCI_VERSION_1_LATE) { -- cgit v1.2.3 From 20b677080881580706652b17dd5a4c3ed3e36c07 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 23 Jun 2012 21:38:46 +0300 Subject: SCI: Change the program counter (PC) to be a 32-bit variable This is needed for future support of large SCI3 scripts. The program counter is isolated and does not interfere with other parts of the VM, plus it does not get stored in saved games, so it's pretty straightforward to convert --- engines/sci/engine/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 80aaedfece..57334b89aa 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -385,7 +385,7 @@ void Script::setLockers(int lockers) { _lockers = lockers; } -uint16 Script::validateExportFunc(int pubfunct, bool relocateSci3) { +uint32 Script::validateExportFunc(int pubfunct, bool relocateSci3) { bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); if (_numExports <= pubfunct) { @@ -396,7 +396,7 @@ uint16 Script::validateExportFunc(int pubfunct, bool relocateSci3) { if (exportsAreWide) pubfunct *= 2; - uint16 offset; + uint32 offset; if (getSciVersion() != SCI_VERSION_3) { offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct); -- cgit v1.2.3 From 7e66cbd468a5b89eaf170d5e0fb3bb312365628c Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 26 Jun 2012 11:12:37 +0300 Subject: SCI: Rename a parameter in validateExportFunc() This ensures that it won't be confused with a function with the same name --- engines/sci/engine/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 57334b89aa..d4143dcceb 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -385,7 +385,7 @@ void Script::setLockers(int lockers) { _lockers = lockers; } -uint32 Script::validateExportFunc(int pubfunct, bool relocateSci3) { +uint32 Script::validateExportFunc(int pubfunct, bool relocSci3) { bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); if (_numExports <= pubfunct) { @@ -401,7 +401,7 @@ uint32 Script::validateExportFunc(int pubfunct, bool relocateSci3) { if (getSciVersion() != SCI_VERSION_3) { offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct); } else { - if (!relocateSci3) + if (!relocSci3) offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct) + getCodeBlockOffsetSci3(); else offset = relocateOffsetSci3(pubfunct * 2 + 22); -- cgit v1.2.3 From cc7768869690261d0f6ee3fddc8f0800307813bb Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 28 Jun 2012 03:29:34 +0300 Subject: SCI: Remove an incorrect error check in validateExportFunc() --- engines/sci/engine/script.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index d4143dcceb..037f4ab700 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -422,16 +422,9 @@ uint32 Script::validateExportFunc(int pubfunct, bool relocSci3) { } } - if (!offset) { -#ifdef ENABLE_SCI32 - // WORKAROUNDS for invalid (empty) exports - if (g_sci->getGameId() == GID_TORIN && _nr == 64036) { - } else if (g_sci->getGameId() == GID_RAMA && _nr == 64908) { - } else -#endif - error("Request for invalid exported function 0x%x of script %d", pubfunct, _nr); - return NULL; - } + // Note that it's perfectly normal to return a zero offset, especially in + // SCI1.1 and newer games. Examples include script 64036 in Torin's Passage, + // script 64908 in the demo of RAMA and script 1013 in KQ6 floppy. if (offset >= _bufSize) error("Invalid export function pointer"); -- cgit v1.2.3 From 8f754ced422eec38766e3d0dd50c82c6fe862f53 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 7 Oct 2012 12:21:32 +0200 Subject: SCI: Flip assert This way the assert is checking that the allocated buffer is large enough for the memcpy that follows it. --- engines/sci/engine/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/script.cpp') diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 037f4ab700..36d2841b07 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -144,7 +144,7 @@ void Script::load(int script_nr, ResourceManager *resMan) { _heapStart = _buf + _scriptSize; - assert(_bufSize - _scriptSize <= heap->size); + assert(_bufSize - _scriptSize >= heap->size); memcpy(_heapStart, heap->data, heap->size); } -- cgit v1.2.3