void Script::load(ResourceManager *resMan) { Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0); assert(script != 0); uint extraLocalsWorkaround = 0; if (g_sci->getGameId() == GID_FANMADE && _nr == 1 && script->size == 11140) { // WORKAROUND: Script 1 in Ocean Battle doesn't have enough locals to // fit the string showing how many shots are left (a nasty script bug, // corrupting heap memory). We add 10 more locals so that it has enough // space to use as the target for its kFormat operation. Fixes bug // #3059871. extraLocalsWorkaround = 10; } _bufSize += extraLocalsWorkaround * 2; _buf = (byte *)malloc(_bufSize); assert(_buf); assert(_bufSize >= script->size); memcpy(_buf, script->data, script->size); // Check scripts for matching signatures and patch those, if found matchSignatureAndPatch(_nr, _buf, script->size); if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) { Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, _nr), 0); assert(heap != 0); _heapStart = _buf + _scriptSize; assert(_bufSize - _scriptSize <= heap->size); memcpy(_heapStart, heap->data, heap->size); } _exportTable = 0; _numExports = 0; _synonyms = 0; _numSynonyms = 0; if (getSciVersion() <= SCI_VERSION_1_LATE) { _exportTable = (const uint16 *)findBlockSCI0(SCI_OBJ_EXPORTS); if (_exportTable) { _numExports = READ_SCI11ENDIAN_UINT16(_exportTable + 1); _exportTable += 3; // skip header plus 2 bytes (_exportTable is a uint16 pointer) } _synonyms = findBlockSCI0(SCI_OBJ_SYNONYMS); if (_synonyms) { _numSynonyms = READ_SCI11ENDIAN_UINT16(_synonyms + 2) / 4; _synonyms += 4; // skip header } const byte* localsBlock = findBlockSCI0(SCI_OBJ_LOCALVARS); if (localsBlock) { _localsOffset = localsBlock - _buf + 4; _localsCount = (READ_LE_UINT16(_buf + _localsOffset - 2) - 4) >> 1; // half block size } } else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) {
void Script::load(ResourceManager *resMan) { Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0); assert(script != 0); _buf = (byte *)malloc(_bufSize); assert(_buf); assert(_bufSize >= script->size); memcpy(_buf, script->data, script->size); // Check scripts for matching signatures and patch those, if found matchSignatureAndPatch(_nr, _buf, script->size); if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) { Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, _nr), 0); assert(heap != 0); _heapStart = _buf + _scriptSize; assert(_bufSize - _scriptSize <= heap->size); memcpy(_heapStart, heap->data, heap->size); } _exportTable = 0; _numExports = 0; _synonyms = 0; _numSynonyms = 0; if (getSciVersion() <= SCI_VERSION_1_LATE) { _exportTable = (const uint16 *)findBlockSCI0(SCI_OBJ_EXPORTS); if (_exportTable) { _numExports = READ_SCI11ENDIAN_UINT16(_exportTable + 1); _exportTable += 3; // skip header plus 2 bytes (_exportTable is a uint16 pointer) } _synonyms = findBlockSCI0(SCI_OBJ_SYNONYMS); if (_synonyms) { _numSynonyms = READ_SCI11ENDIAN_UINT16(_synonyms + 2) / 4; _synonyms += 4; // skip header } const byte* localsBlock = findBlockSCI0(SCI_OBJ_LOCALVARS); if (localsBlock) { _localsOffset = localsBlock - _buf + 4; _localsCount = (READ_LE_UINT16(_buf + _localsOffset - 2) - 4) >> 1; // half block size } } else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) {