diff options
-rw-r--r-- | engines/sci/engine/script.cpp | 1 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 52 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 3 | ||||
-rw-r--r-- | engines/sci/engine/static_selectors.cpp | 7 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 |
5 files changed, 39 insertions, 26 deletions
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 2ac51a05ac..036bae3439 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -240,6 +240,7 @@ void Kernel::mapSelectors() { FIND_SELECTOR(subtitleLang); FIND_SELECTOR(parseLang); FIND_SELECTOR(overlay); + FIND_SELECTOR(newRoom); FIND_SELECTOR(setCursor); FIND_SELECTOR(topString); FIND_SELECTOR(scaleX); diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index b34549b6d0..de66aabf12 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -259,6 +259,10 @@ bool EngineState::autoDetectFeature(FeatureDetection featureDetection) { objName = "Game"; slc = _kernel->_selectorCache.play; break; + case kDetectLofsTypeFallback: + objName = "Game"; + slc = _kernel->_selectorCache.newRoom; + break; default: break; } @@ -285,32 +289,34 @@ bool EngineState::autoDetectFeature(FeatureDetection featureDetection) { int i = 0; byte argc; - if (featureDetection == kDetectLofsType && (opcode == op_lofsa || opcode == op_lofss)) { - uint16 lofs; + if (featureDetection == kDetectLofsType || featureDetection == kDetectLofsTypeFallback) { + if (opcode == op_lofsa || opcode == op_lofss) { + uint16 lofs; - // Load lofs operand - if (opsize & 1) { - if (offset >= script->_bufSize) - break; - lofs = script->_buf[offset++]; - } else { - if ((uint32)offset + 1 >= (uint32)script->_bufSize) - break; - lofs = READ_LE_UINT16(script->_buf + offset); - offset += 2; - } + // Load lofs operand + if (opsize & 1) { + if (offset >= script->_bufSize) + break; + lofs = script->_buf[offset++]; + } else { + if ((uint32)offset + 1 >= (uint32)script->_bufSize) + break; + lofs = READ_LE_UINT16(script->_buf + offset); + offset += 2; + } - // Check for going out of bounds when interpreting as abs/rel - if (lofs >= script->_bufSize) - _lofsType = SCI_VERSION_0_EARLY; + // Check for going out of bounds when interpreting as abs/rel + if (lofs >= script->_bufSize) + _lofsType = SCI_VERSION_0_EARLY; - if ((signed)offset + (int16)lofs < 0) - _lofsType = SCI_VERSION_1_MIDDLE; + if ((signed)offset + (int16)lofs < 0) + _lofsType = SCI_VERSION_1_MIDDLE; - if ((signed)offset + (int16)lofs >= (signed)script->_bufSize) - _lofsType = SCI_VERSION_1_MIDDLE; + if ((signed)offset + (int16)lofs >= (signed)script->_bufSize) + _lofsType = SCI_VERSION_1_MIDDLE; - return true; + return true; + } } while (g_opcode_formats[opcode][i]) { @@ -477,7 +483,9 @@ SciVersion EngineState::detectLofsType() { return _lofsType; } - if (!autoDetectFeature(kDetectLofsType)) { + // Either the init or the newRoom selectors of the Game + // object make calls to lofsa/lofss + if (!autoDetectFeature(kDetectLofsType) && !autoDetectFeature(kDetectLofsTypeFallback)) { warning("Lofs detection failed, taking an educated guess"); if (getSciVersion() >= SCI_VERSION_1_MIDDLE) diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index a4f07bb575..dcddf7c15c 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -107,7 +107,8 @@ enum FeatureDetection { kDetectMoveCountType = 1, kDetectSoundType = 2, kDetectSetCursorType = 3, - kDetectLofsType = 4 + kDetectLofsType = 4, + kDetectLofsTypeFallback = 5 }; class FileHandle { diff --git a/engines/sci/engine/static_selectors.cpp b/engines/sci/engine/static_selectors.cpp index b4fd18cd7a..eee558dc5a 100644 --- a/engines/sci/engine/static_selectors.cpp +++ b/engines/sci/engine/static_selectors.cpp @@ -74,9 +74,10 @@ static const SelectorRemap sci1SelectorRemap[] = { { "nodePtr", 44 }, { "cantBeHere", 57 }, { "topString", 101 }, { "flags", 102 }, { "init", 104 }, { "dispose", 105 }, { "caller", 134 }, { "cue", 136 }, { "owner", 150 }, - { "setVol", 156 }, { "setCursor", 183 }, { "completed", 210 }, - { "cycler", 215 }, { "distance", 224 }, { "canBeHere", 232 }, - { "syncTime", 247 }, { "syncCue", 248 }, { 0, 0 } + { "setVol", 156 }, { "newRoom", 173 }, { "setCursor", 183 }, + { "completed", 210 }, { "cycler", 215 }, { "distance", 224 }, + { "canBeHere", 232 }, { "syncTime", 247 }, { "syncCue", 248 }, + { 0, 0 } }; // Taken from KQ6 floppy (Full Game) diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 391338ec09..06c09a1a52 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -191,6 +191,8 @@ struct SelectorCache { Selector subtitleLang; Selector parseLang; + Selector newRoom; /** For SCI1 lofs parameter type autodetection fallback */ + Selector setCursor; /** For autodetection */ }; |