Skip to content

Commit

Permalink
SCI32: Fix selector search for SCI2/2.1 games with missing vocab.997
Browse files Browse the repository at this point in the history
Fixes Trac#9796.
  • Loading branch information
csnover committed May 24, 2017
1 parent 31c2aa8 commit fdb8761
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions engines/sci/engine/static_selectors.cpp
Expand Up @@ -151,6 +151,13 @@ static const ClassReference classReferences[] = {
{ 999, "Script", "init", kSelectorMethod, 0 },
{ 999, "Script", "dispose", kSelectorMethod, 2 },
{ 999, "Script", "changeState", kSelectorMethod, 3 }
#ifdef ENABLE_SCI32
,
{ 64929, "Sync", "syncTime", kSelectorVariable, 2 },
{ 64929, "Sync", "syncCue", kSelectorVariable, 3 },
{ 64999, "Obj", "init", kSelectorMethod, 1 },
{ 64999, "Obj", "doit", kSelectorMethod, 2 }
#endif
};

Common::StringArray Kernel::checkStaticSelectorNames() {
Expand Down Expand Up @@ -222,27 +229,35 @@ void Kernel::findSpecificSelectors(Common::StringArray &selectorNames) {
// We need to initialize script 0 here, to make sure that it's always
// located at segment 1.
_segMan->instantiateScript(0);
uint16 sci2Offset = (getSciVersion() >= SCI_VERSION_2) ? 64000 : 0;

// The Actor class contains the init, xLast and yLast selectors, which
// we reference directly. It's always in script 998, so we need to
// explicitly load it here.
if ((getSciVersion() >= SCI_VERSION_1_EGA_ONLY)) {
if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) {
uint16 actorScript = 998;
#ifdef ENABLE_SCI32
if (getSciVersion() >= SCI_VERSION_2) {
actorScript += 64000;
}
#endif

if (_resMan->testResource(ResourceId(kResourceTypeScript, actorScript + sci2Offset))) {
_segMan->instantiateScript(actorScript + sci2Offset);
if (_resMan->testResource(ResourceId(kResourceTypeScript, actorScript))) {
_segMan->instantiateScript(actorScript);

const Object *actorClass = _segMan->getObject(_segMan->findObjectByName("Actor"));

if (actorClass) {
// Find the xLast and yLast selectors, used in kDoBresen

const int offset = (getSciVersion() < SCI_VERSION_1_1) ? 3 : 0;
const int offset2 = (getSciVersion() >= SCI_VERSION_2) ? 12 : 0;
int offset = (getSciVersion() < SCI_VERSION_1_1) ? 3 : 0;
#ifdef ENABLE_SCI32
if (getSciVersion() >= SCI_VERSION_2) {
offset += 12;
}
#endif
// xLast and yLast always come between illegalBits and xStep
int illegalBitsSelectorPos = actorClass->locateVarSelector(_segMan, 15 + offset + offset2); // illegalBits
int xStepSelectorPos = actorClass->locateVarSelector(_segMan, 51 + offset + offset2); // xStep
int illegalBitsSelectorPos = actorClass->locateVarSelector(_segMan, 15 + offset); // illegalBits
int xStepSelectorPos = actorClass->locateVarSelector(_segMan, 51 + offset); // xStep
if (xStepSelectorPos - illegalBitsSelectorPos != 3) {
error("illegalBits and xStep selectors aren't found in "
"known locations. illegalBits = %d, xStep = %d",
Expand All @@ -257,19 +272,19 @@ void Kernel::findSpecificSelectors(Common::StringArray &selectorNames) {

selectorNames[xLastSelectorPos] = "xLast";
selectorNames[yLastSelectorPos] = "yLast";
} // if (actorClass)
}

_segMan->uninstantiateScript(998);
} // if (_resMan->testResource(ResourceId(kResourceTypeScript, 998)))
} // if ((getSciVersion() >= SCI_VERSION_1_EGA_ONLY))
_segMan->uninstantiateScript(actorScript);
}
}

// Find selectors from specific classes

for (int i = 0; i < ARRAYSIZE(classReferences); i++) {
if (!_resMan->testResource(ResourceId(kResourceTypeScript, classReferences[i].script + sci2Offset)))
if (!_resMan->testResource(ResourceId(kResourceTypeScript, classReferences[i].script)))
continue;

_segMan->instantiateScript(classReferences[i].script + sci2Offset);
_segMan->instantiateScript(classReferences[i].script);

const Object *targetClass = _segMan->getObject(_segMan->findObjectByName(classReferences[i].className));
int targetSelectorPos = 0;
Expand Down Expand Up @@ -303,7 +318,6 @@ void Kernel::findSpecificSelectors(Common::StringArray &selectorNames) {
}
}

// Reset the segment manager
_segMan->resetSegMan();
}

Expand Down

0 comments on commit fdb8761

Please sign in to comment.