aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/script.cpp43
-rw-r--r--engines/sci/engine/script.h5
2 files changed, 33 insertions, 15 deletions
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 088cd9cb89..7f5a4c75be 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -168,7 +168,13 @@ void Script::load(ResourceManager *resMan) {
_localsOffset = _scriptSize + 4;
_localsCount = READ_SCI11ENDIAN_UINT16(_buf + _localsOffset - 2);
} else if (getSciVersion() == SCI_VERSION_3) {
- warning("TODO: Script::load(): SCI3 equivalent");
+ _localsCount = READ_LE_UINT16(_buf + 12);
+ _numExports = READ_LE_UINT16(_buf + 20);
+ // SCI3 local variables always start dword-aligned
+ if (_numExports % 2)
+ _localsOffset = 22 + _numExports * 2;
+ else
+ _localsOffset = 24 + _numExports * 2;
}
if (getSciVersion() == SCI_VERSION_0_EARLY) {
@@ -191,6 +197,24 @@ void Script::load(ResourceManager *resMan) {
}
}
+const byte *Script::getSci3ObjectsPointer() {
+ const byte *ptr = 0;
+
+ // SCI3 local variables always start dword-aligned
+ if (_numExports % 2)
+ ptr = _buf + 22 + _numExports * 2;
+ else
+ ptr = _buf + 24 + _numExports * 2;
+
+ // SCI3 object structures always start dword-aligned
+ if (_localsCount % 2)
+ ptr += 2 + _localsCount * 2;
+ else
+ ptr += _localsCount * 2;
+
+ return ptr;
+}
+
Object *Script::getObject(uint16 offset) {
if (_objects.contains(offset))
return &_objects[offset];
@@ -435,7 +459,8 @@ void Script::initialiseClasses(SegManager *segMan) {
seeker = _heapStart + 4 + READ_SCI11ENDIAN_UINT16(_heapStart + 2) * 2;
mult = 2;
} else if (getSciVersion() == SCI_VERSION_3) {
- warning("TODO: initialiseClasses(): SCI3 equivalent");
+ seeker = getSci3ObjectsPointer();
+ mult = 1;
}
if (!seeker)
@@ -567,19 +592,7 @@ void Script::initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId) {
}
void Script::initialiseObjectsSci3(SegManager *segMan, SegmentId segmentId) {
- const byte *seeker = _buf;
-
- // SCI3 local variables always start dword-aligned
- if (_numExports % 2)
- seeker = _buf + 22 + _numExports * 2;
- else
- seeker = _buf + 24 + _numExports * 2;
-
- // SCI3 object structures always start dword-aligned
- if (_localsCount % 2)
- seeker = seeker + 2 + _localsCount * 2;
- else
- seeker = seeker + _localsCount * 2;
+ const byte *seeker = getSci3ObjectsPointer();
while (READ_SCI11ENDIAN_UINT16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) {
reg_t reg = make_reg(segmentId, seeker - _buf);
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index 211427942d..2105d1e6de 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -261,6 +261,11 @@ private:
bool relocateLocal(SegmentId segment, int location);
/**
+ * Gets a pointer to the beginning of the objects in a SCI3 script
+ */
+ const byte *getSci3ObjectsPointer();
+
+ /**
* Initializes the script's objects (SCI0)
* @param segMan A reference to the segment manager
* @param segmentId The script's segment id