diff options
-rw-r--r-- | engines/sci/engine/game.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.h | 6 | ||||
-rw-r--r-- | engines/sci/resource.cpp | 33 | ||||
-rw-r--r-- | engines/sci/resource.h | 8 |
4 files changed, 31 insertions, 20 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index d7fdd9be6e..232e0eca55 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -127,9 +127,7 @@ int game_init(EngineState *s) { srand(g_system->getMillis()); // Initialize random number generator -// script_dissect(0, s->_selectorNames); - // The first entry in the export table of script 0 points to the game object - s->_gameObj = s->_segMan->lookupScriptExport(0, 0); + s->_gameObj = g_sci->getResMan()->findGameObject(); #ifdef USE_OLD_MUSIC_FUNCTIONS if (s->sfx_init_flags & SFX_STATE_FLAG_NOSOUND) diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 24d3f3fc1c..30d62f50b0 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -112,12 +112,6 @@ public: SegmentId getScriptSegment(int script_nr, ScriptLoadType load); // TODO: document this - reg_t lookupScriptExport(int script_nr, int export_index) { - SegmentId seg = getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD); - return make_reg(seg, getScript(seg)->validateExportFunc(export_index)); - } - - // TODO: document this reg_t getClassAddress(int classnr, ScriptLoadType lock, reg_t caller); /** diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index cc3a2b0d1a..d336cbab38 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -1913,26 +1913,37 @@ bool ResourceManager::hasSci1Voc900() { #define READ_UINT16(ptr) (!isSci11Mac() ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) -Common::String ResourceManager::findSierraGameId() { +reg_t ResourceManager::findGameObject(bool addSci11ScriptOffset) { Resource *script = findResource(ResourceId(kResourceTypeScript, 0), false); + int extraBytes = 0; + if (getSciVersion() == SCI_VERSION_0_EARLY || getSciVersion() >= SCI_VERSION_1_1) + extraBytes = 2; + + int16 offset = READ_UINT16(script->data + extraBytes + 4 + 2); + + // In SCI1.1 and newer, the heap is appended at the end of the script, + // so adjust the offset accordingly + if (getSciVersion() >= SCI_VERSION_1_1 && addSci11ScriptOffset) + offset += script->size; + + return make_reg(1, offset); +} + +Common::String ResourceManager::findSierraGameId() { // In SCI0-SCI1, the heap is embedded in the script. In SCI1.1+, it's separated Resource *heap = 0; - byte *seeker = 0; - Common::String sierraId; + int nameSelector = 3; - // Seek to the name selector of the first export if (getSciVersion() < SCI_VERSION_1_1) { - const int nameSelector = 3; - int extraSci0EarlyBytes = (getSciVersion() == SCI_VERSION_0_EARLY) ? 2 : 0; - byte *exportPtr = script->data + extraSci0EarlyBytes + 4 + 2; - seeker = script->data + READ_UINT16(script->data + READ_UINT16(exportPtr) + nameSelector * 2); + heap = findResource(ResourceId(kResourceTypeScript, 0), false); } else { - const int nameSelector = 5 + 3; heap = findResource(ResourceId(kResourceTypeHeap, 0), false); - byte *exportPtr = script->data + 4 + 2 + 2; - seeker = heap->data + READ_UINT16(heap->data + READ_UINT16(exportPtr) + nameSelector * 2); + nameSelector += 5; } + // Seek to the name selector of the first export + byte *seeker = heap->data + READ_UINT16(heap->data + findGameObject(false).offset + nameSelector * 2); + Common::String sierraId; sierraId += (const char *)seeker; return sierraId; diff --git a/engines/sci/resource.h b/engines/sci/resource.h index dbd99f633d..8147763f4f 100644 --- a/engines/sci/resource.h +++ b/engines/sci/resource.h @@ -296,6 +296,14 @@ public: */ Common::String findSierraGameId(); + /** + * Finds the location of the game object from script 0 + * @param addSci11ScriptOffset: Adjust the return value for SCI1.1 and newer + * games. Needs to be false when the heap is accessed directly inside + * findSierraGameId(). + */ + reg_t findGameObject(bool addSci11ScriptOffset = true); + protected: // Maximum number of bytes to allow being allocated for resources // Note: maxMemory will not be interpreted as a hard limit, only as a restriction |