diff options
-rw-r--r-- | engines/sci/engine/kernel.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/script.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/script.h | 1 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 |
5 files changed, 8 insertions, 5 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index c99bc4fe47..3a33c928e7 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -376,7 +376,7 @@ uint16 Kernel::findRegType(reg_t reg) { case SEG_TYPE_SCRIPT: if (reg.offset <= (*(Script *)mobj).getBufSize() && reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && - RAW_IS_OBJECT((*(Script *)mobj).getBuf(reg.offset)) ) { + (*(Script *)mobj).offsetIsObject(reg.offset)) { result |= ((Script *)mobj)->getObject(reg.offset) ? SIG_TYPE_OBJECT : SIG_TYPE_REFERENCE; } else result |= SIG_TYPE_REFERENCE; 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<reg_t> Script::listAllDeallocatable(SegmentId segId) const { Common::Array<reg_t> Script::listAllOutgoingReferences(reg_t addr) const { Common::Array<reg_t> 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<reg_t> 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 diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h index df7f42cc0d..0c99f13235 100644 --- a/engines/sci/engine/script.h +++ b/engines/sci/engine/script.h @@ -89,6 +89,7 @@ public: void syncLocalsBlock(SegManager *segMan); ObjMap &getObjectMap() { return _objects; } const ObjMap &getObjectMap() const { return _objects; } + bool offsetIsObject(uint16 offset) const; public: Script(); diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 20a8240641..eaa587e3f9 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -227,7 +227,7 @@ Object *SegManager::getObject(reg_t pos) const { } else if (mobj->getType() == SEG_TYPE_SCRIPT) { Script *scr = (Script *)mobj; if (pos.offset <= scr->getBufSize() && pos.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET - && RAW_IS_OBJECT(scr->getBuf(pos.offset))) { + && scr->offsetIsObject(pos.offset)) { obj = scr->getObject(pos.offset); } } diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index cdd9b9a06e..67b9dd44eb 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -61,8 +61,6 @@ struct Class { reg_t reg; ///< offset; script-relative offset, segment: 0 if not instantiated }; -#define RAW_IS_OBJECT(datablock) (READ_SCI11ENDIAN_UINT16(((const byte *) datablock) + SCRIPT_OBJECT_MAGIC_OFFSET) == SCRIPT_OBJECT_MAGIC_NUMBER) - // A reference to an object's variable. // The object is stored as a reg_t, the variable as an index into _variables struct ObjVarRef { |