diff options
-rw-r--r-- | engines/gob/draw_v1.cpp | 4 | ||||
-rw-r--r-- | engines/gob/draw_v2.cpp | 10 | ||||
-rw-r--r-- | engines/gob/game.cpp | 2 | ||||
-rw-r--r-- | engines/gob/game.h | 6 | ||||
-rw-r--r-- | engines/gob/game_v1.cpp | 59 | ||||
-rw-r--r-- | engines/gob/game_v2.cpp | 64 | ||||
-rw-r--r-- | engines/gob/init.cpp | 11 | ||||
-rw-r--r-- | engines/gob/inter_v1.cpp | 2 | ||||
-rw-r--r-- | engines/gob/scenery.cpp | 48 | ||||
-rw-r--r-- | engines/gob/scenery.h | 8 |
10 files changed, 110 insertions, 104 deletions
diff --git a/engines/gob/draw_v1.cpp b/engines/gob/draw_v1.cpp index 7307c169ba..31377059b7 100644 --- a/engines/gob/draw_v1.cpp +++ b/engines/gob/draw_v1.cpp @@ -60,7 +60,7 @@ void Draw_v1::printText(void) { _vm->_cdrom->playMultMusic(); - dataPtr = (char *)_vm->_game->_totTextData + _vm->_game->_totTextData->items[index].offset; + dataPtr = _vm->_game->_totTextData->dataPtr + _vm->_game->_totTextData->items[index].offset; ptr = dataPtr; if (_renderFlags & RENDERFLAG_CAPTUREPUSH) { @@ -334,7 +334,7 @@ void Draw_v1::spriteOperation(int16 operation) { offset = itemPtr->offset; if (offset >= 0) { dataBuf = - ((char *)_vm->_game->_totResourceTable) + + _vm->_game->_totResourceTable->dataPtr + szGame_TotResTable + szGame_TotResItem * _vm->_game->_totResourceTable->itemsCount + offset; } else { diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp index 426bf825dc..b9795153ca 100644 --- a/engines/gob/draw_v2.cpp +++ b/engines/gob/draw_v2.cpp @@ -124,10 +124,10 @@ void Draw_v2::printText(void) { _vm->_cdrom->playMultMusic(); - if (_vm->_game->_totTextData == 0) + if ((_vm->_game->_totTextData == 0) || (_vm->_game->_totTextData->dataPtr == 0)) return; - dataPtr = (char *)_vm->_game->_totTextData + _vm->_game->_totTextData->items[index].offset; + dataPtr = _vm->_game->_totTextData->dataPtr + _vm->_game->_totTextData->items[index].offset; ptr = dataPtr; if ((_renderFlags & 0x400) && (ptr[1] & 0x80)) @@ -380,7 +380,7 @@ void Draw_v2::printText(void) { case 10: // loc_12C93 str[0] = (char)255; - WRITE_LE_UINT16((uint16*)(str+1), ptr - (char *)_vm->_game->_totTextData); + WRITE_LE_UINT16((uint16*)(str+1), ptr - _vm->_game->_totTextData->dataPtr); str[3] = 0; ptr++; i = *ptr++; @@ -685,7 +685,7 @@ void Draw_v2::spriteOperation(int16 operation) { offset = itemPtr->offset; if (offset >= 0) { dataBuf = - ((char *)_vm->_game->_totResourceTable) + + _vm->_game->_totResourceTable->dataPtr + szGame_TotResTable + szGame_TotResItem * _vm->_game->_totResourceTable->itemsCount + offset; } else { @@ -714,7 +714,7 @@ void Draw_v2::spriteOperation(int16 operation) { if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) { if (_fonts[_fontIndex]->extraData == 0) { if (((signed) _textToPrint[0]) == -1) { - dataBuf = (char*)_vm->_game->_totTextData + _textToPrint[1] + 1; + dataBuf = _vm->_game->_totTextData->dataPtr + _textToPrint[1] + 1; len = *dataBuf++; for (i = 0; i < len; i++) { _vm->_video->drawLetter(READ_LE_UINT16(dataBuf), _destSpriteX, diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp index 8b01ccc71d..646b390fc1 100644 --- a/engines/gob/game.cpp +++ b/engines/gob/game.cpp @@ -372,7 +372,7 @@ char *Game::loadTotResource(int16 id) { itemPtr = &_totResourceTable->items[id]; offset = itemPtr->offset; if (offset >= 0) { - return ((char *)_totResourceTable) + szGame_TotResTable + + return _totResourceTable->dataPtr + szGame_TotResTable + szGame_TotResItem * _totResourceTable->itemsCount + offset; } else { return (char *)(_imFileData + (int32)READ_LE_UINT32(&((int32 *)_imFileData)[-offset - 1])); diff --git a/engines/gob/game.h b/engines/gob/game.h index 426d081fc7..9ffc1b103d 100644 --- a/engines/gob/game.h +++ b/engines/gob/game.h @@ -58,7 +58,8 @@ public: struct TotResTable { int16 itemsCount; byte unknown; - TotResItem items[1]; + TotResItem *items; + char *dataPtr; } GCC_PACK; #define szGame_ExtItem (4 + 2 + 2 + 2) @@ -85,7 +86,8 @@ public: #define szGame_TotTextTable (2) struct TotTextTable { int16 itemsCount; - TotTextItem items[1]; + TotTextItem *items; + char *dataPtr; } GCC_PACK; struct InputDesc { diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp index 43c66761db..3bbb59a873 100644 --- a/engines/gob/game_v1.cpp +++ b/engines/gob/game_v1.cpp @@ -23,6 +23,7 @@ #include "common/stdafx.h" #include "common/endian.h" +#include "common/stream.h" #include "gob/gob.h" #include "gob/global.h" @@ -53,9 +54,6 @@ void Game_v1::playTot(int16 skipPlay) { int16 _captureCounter; int16 breakFrom; int16 nestLevel; - char needTextFree; - char needFreeResTable; - char *curPtr; int32 variablesCount; char *filePtr; char *savedIP; @@ -105,9 +103,6 @@ void Game_v1::playTot(int16 skipPlay) { _extTable = 0; _extHandle = -1; - needFreeResTable = 1; - needTextFree = 1; - _totToLoad[0] = 0; if (_curTotFile[0] == 0 && _totFileData == 0) @@ -133,40 +128,38 @@ void Game_v1::playTot(int16 skipPlay) { filePtr = (char *)_totFileData + 0x30; + _totTextData = 0; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = _totFileData; - _totTextData = - (TotTextTable *) (curPtr + - READ_LE_UINT32((char *)_totFileData + 0x30)); + _totTextData = new TotTextTable; + _totTextData->dataPtr = (_totFileData + READ_LE_UINT32((char *)_totFileData + 0x30)); + Common::MemoryReadStream totTextData((byte *) _totTextData->dataPtr, 4294967295U); - _totTextData->itemsCount = (int16)READ_LE_UINT16(&_totTextData->itemsCount); + _totTextData->itemsCount = totTextData.readSint16LE(); + _totTextData->items = new TotTextItem[_totTextData->itemsCount]; for (i = 0; i < _totTextData->itemsCount; ++i) { - _totTextData->items[i].offset = (int16)READ_LE_UINT16(&_totTextData->items[i].offset); - _totTextData->items[i].size = (int16)READ_LE_UINT16(&_totTextData->items[i].size); + _totTextData->items[i].offset = totTextData.readSint16LE(); + _totTextData->items[i].size = totTextData.readSint16LE(); } - - needTextFree = 0; } filePtr = (char *)_totFileData + 0x34; + _totResourceTable = 0; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = _totFileData; + _totResourceTable = new TotResTable; + _totResourceTable->dataPtr = _totFileData + READ_LE_UINT32((char *)_totFileData + 0x34); + Common::MemoryReadStream totResTable((byte *) _totResourceTable->dataPtr, 4294967295U); - _totResourceTable = - (TotResTable *)(curPtr + - READ_LE_UINT32((char *)_totFileData + 0x34)); - - _totResourceTable->itemsCount = (int16)READ_LE_UINT16(&_totResourceTable->itemsCount); + _totResourceTable->itemsCount = totResTable.readSint16LE(); + _totResourceTable->unknown = totResTable.readByte(); + _totResourceTable->items = new TotResItem[_totResourceTable->itemsCount]; for (i = 0; i < _totResourceTable->itemsCount; ++i) { - _totResourceTable->items[i].offset = (int32)READ_LE_UINT32(&_totResourceTable->items[i].offset); - _totResourceTable->items[i].size = (int16)READ_LE_UINT16(&_totResourceTable->items[i].size); - _totResourceTable->items[i].width = (int16)READ_LE_UINT16(&_totResourceTable->items[i].width); - _totResourceTable->items[i].height = (int16)READ_LE_UINT16(&_totResourceTable->items[i].height); + _totResourceTable->items[i].offset = totResTable.readSint32LE(); + _totResourceTable->items[i].size = totResTable.readSint16LE(); + _totResourceTable->items[i].width = totResTable.readSint16LE(); + _totResourceTable->items[i].height = totResTable.readSint16LE(); } - - needFreeResTable = 0; } loadImFile(); @@ -200,12 +193,16 @@ void Game_v1::playTot(int16 skipPlay) { delete[] _totFileData; _totFileData = 0; - if (needTextFree) - delete[] _totTextData; + if (_totTextData) { + delete[] _totTextData->items; + delete _totTextData; + } _totTextData = 0; - if (needFreeResTable) - delete[] _totResourceTable; + if (_totResourceTable) { + delete[] _totResourceTable->items; + delete _totResourceTable; + } _totResourceTable = 0; delete[] _imFileData; diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp index e02ac9f7f5..025c86b73a 100644 --- a/engines/gob/game_v2.cpp +++ b/engines/gob/game_v2.cpp @@ -53,9 +53,6 @@ void Game_v2::playTot(int16 skipPlay) { int16 _captureCounter; int16 breakFrom; int16 nestLevel; - char needTextFree; - char needFreeResTable; - char *curPtr; int32 variablesCount; char *filePtr; char *savedIP; @@ -105,9 +102,6 @@ void Game_v2::playTot(int16 skipPlay) { _extTable = 0; _extHandle = -1; - needFreeResTable = 1; - needTextFree = 1; - _totToLoad[0] = 0; if (_curTotFile[0] == 0 && _totFileData == 0) @@ -133,45 +127,44 @@ void Game_v2::playTot(int16 skipPlay) { filePtr = (char *)_totFileData + 0x30; + _totTextData = 0; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = _totFileData; + _totTextData = new TotTextTable; if (READ_LE_UINT32(filePtr) == 0) - _totTextData = (TotTextTable *) loadLocTexts(); + _totTextData->dataPtr = loadLocTexts(); else - _totTextData = - (TotTextTable *) (curPtr + - READ_LE_UINT32((char *)_totFileData + 0x30)); + _totTextData->dataPtr = (_totFileData + READ_LE_UINT32((char *)_totFileData + 0x30)); - if (_totTextData != 0) { - _totTextData->itemsCount = (int16)READ_LE_UINT16(&_totTextData->itemsCount); + _totTextData->items = 0; + if (_totTextData->dataPtr != 0) { + Common::MemoryReadStream totTextData((byte *) _totTextData->dataPtr, 4294967295U); + _totTextData->itemsCount = totTextData.readSint16LE(); + _totTextData->items = new TotTextItem[_totTextData->itemsCount]; for (i = 0; i < _totTextData->itemsCount; ++i) { - _totTextData->items[i].offset = (int16)READ_LE_UINT16(&_totTextData->items[i].offset); - _totTextData->items[i].size = (int16)READ_LE_UINT16(&_totTextData->items[i].size); + _totTextData->items[i].offset = totTextData.readSint16LE(); + _totTextData->items[i].size = totTextData.readSint16LE(); } } - - needTextFree = 0; } filePtr = (char *)_totFileData + 0x34; + _totResourceTable = 0; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = _totFileData; + _totResourceTable = new TotResTable; + _totResourceTable->dataPtr = _totFileData + READ_LE_UINT32((char *)_totFileData + 0x34); + Common::MemoryReadStream totResTable((byte *) _totResourceTable->dataPtr, 4294967295U); - _totResourceTable = - (TotResTable *)(curPtr + - READ_LE_UINT32((char *)_totFileData + 0x34)); - - _totResourceTable->itemsCount = (int16)READ_LE_UINT16(&_totResourceTable->itemsCount); + _totResourceTable->itemsCount = totResTable.readSint16LE(); + _totResourceTable->unknown = totResTable.readByte(); + _totResourceTable->items = new TotResItem[_totResourceTable->itemsCount]; for (i = 0; i < _totResourceTable->itemsCount; ++i) { - _totResourceTable->items[i].offset = (int32)READ_LE_UINT32(&_totResourceTable->items[i].offset); - _totResourceTable->items[i].size = (int16)READ_LE_UINT16(&_totResourceTable->items[i].size); - _totResourceTable->items[i].width = (int16)READ_LE_UINT16(&_totResourceTable->items[i].width); - _totResourceTable->items[i].height = (int16)READ_LE_UINT16(&_totResourceTable->items[i].height); + _totResourceTable->items[i].offset = totResTable.readSint32LE(); + _totResourceTable->items[i].size = totResTable.readSint16LE(); + _totResourceTable->items[i].width = totResTable.readSint16LE(); + _totResourceTable->items[i].height = totResTable.readSint16LE(); } - - needFreeResTable = 0; } loadImFile(); @@ -204,12 +197,17 @@ void Game_v2::playTot(int16 skipPlay) { delete[] _totFileData; _totFileData = 0; - if (needTextFree) - delete[] _totTextData; + if (_totTextData) { + if (_totTextData->items) + delete[] _totTextData->items; + delete _totTextData; + } _totTextData = 0; - if (needFreeResTable) - delete[] _totResourceTable; + if (_totResourceTable) { + delete[] _totResourceTable->items; + delete _totResourceTable; + } _totResourceTable = 0; delete[] _imFileData; diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp index 8f0311b1fc..299288878b 100644 --- a/engines/gob/init.cpp +++ b/engines/gob/init.cpp @@ -217,8 +217,15 @@ memBlocks = word ptr -2*/ delete[] _vm->_global->_inter_variables; delete[] _vm->_game->_totFileData; - delete[] _vm->_game->_totTextData; - delete[] _vm->_game->_totResourceTable; + if (_vm->_game->_totTextData) { + if (_vm->_game->_totTextData->items) + delete[] _vm->_game->_totTextData->items; + delete _vm->_game->_totTextData; + } + if (_vm->_game->_totResourceTable) { + delete[] _vm->_game->_totResourceTable->items; + delete _vm->_game->_totResourceTable; + } } for (i = 0; i < 4; i++) { diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp index 7a3449f7f0..1db6498945 100644 --- a/engines/gob/inter_v1.cpp +++ b/engines/gob/inter_v1.cpp @@ -1263,7 +1263,7 @@ bool Inter_v1::o1_loadCursor(char &cmdCount, int16 &counter, int16 &retFlag) { if (offset >= 0) { dataBuf = - ((char *)_vm->_game->_totResourceTable) + szGame_TotResTable + + _vm->_game->_totResourceTable->dataPtr + szGame_TotResTable + szGame_TotResItem * _vm->_game->_totResourceTable->itemsCount + offset; } else { dataBuf = _vm->_game->_imFileData + (int32)READ_LE_UINT32(&((int32 *)_vm->_game->_imFileData)[-offset - 1]); diff --git a/engines/gob/scenery.cpp b/engines/gob/scenery.cpp index a3556ae1be..88bd39e9c7 100644 --- a/engines/gob/scenery.cpp +++ b/engines/gob/scenery.cpp @@ -51,7 +51,6 @@ Scenery::Scenery(GobEngine *vm) : _vm(vm) { } for (i = 0; i < 10; i++) { _staticPictCount[i] = 0; - _staticFromExt[i] = 0; _staticResId[i] = 0; _animPictCount[i] = 0; _animResId[i] = 0; @@ -78,6 +77,7 @@ int16 Scenery::loadStatic(char search) { int16 resId; int16 i; int16 sceneryIndex; + char *extData; char *dataPtr; Static *ptr; int16 offset; @@ -87,6 +87,7 @@ int16 Scenery::loadStatic(char search) { int16 sprResId; int16 sprIndex; + extData = 0; _vm->_inter->evalExpr(&sceneryIndex); tmp = _vm->_inter->load16(); backsPtr = (int16 *)_vm->_global->_inter_execPtr; @@ -109,35 +110,37 @@ int16 Scenery::loadStatic(char search) { _staticResId[sceneryIndex] = resId; if (resId >= 30000) { - _staticFromExt[sceneryIndex] = 1; - dataPtr = _vm->_game->loadExtData(resId, 0, 0); - } else { - _staticFromExt[sceneryIndex] = 0; + extData = _vm->_game->loadExtData(resId, 0, 0); + dataPtr = extData; + } else dataPtr = _vm->_game->loadTotResource(resId); - } ptr = &_statics[sceneryIndex]; - ptr->dataPtr = dataPtr; ptr->layersCount = (int16)READ_LE_UINT16(dataPtr); dataPtr += 2; - ptr->layers = new StaticLayer*[ptr->layersCount]; + ptr->layers = new StaticLayer[ptr->layersCount]; ptr->pieces = new PieceDesc*[picsCount]; ptr->piecesFromExt = new int8[picsCount]; for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); - ptr->layers[i] = (StaticLayer *)(dataPtr + offset - 2); - - ptr->layers[i]->planeCount = (int16)READ_LE_UINT16(&ptr->layers[i]->planeCount); - - for (int j = 0; j < ptr->layers[i]->planeCount; ++j) { - ptr->layers[i]->planes[j].destX = (int16)READ_LE_UINT16(&ptr->layers[i]->planes[j].destX); - ptr->layers[i]->planes[j].destY = (int16)READ_LE_UINT16(&ptr->layers[i]->planes[j].destY); + Common::MemoryReadStream layerData((byte *) (dataPtr + offset), 4294967295U); + + ptr->layers[i].planeCount = layerData.readSint16LE(); + + ptr->layers[i].planes = new StaticPlane[ptr->layers[i].planeCount]; + for (int j = 0; j < ptr->layers[i].planeCount; ++j) { + ptr->layers[i].planes[j].pictIndex = layerData.readByte(); + ptr->layers[i].planes[j].pieceIndex = layerData.readByte(); + ptr->layers[i].planes[j].drawOrder = layerData.readByte(); + ptr->layers[i].planes[j].destX = layerData.readSint16LE(); + ptr->layers[i].planes[j].destY = layerData.readSint16LE(); + ptr->layers[i].planes[j].transp = layerData.readByte(); } - ptr->layers[i]->backResId = (int16)READ_LE_UINT16(backsPtr); + ptr->layers[i].backResId = (int16)READ_LE_UINT16(backsPtr); backsPtr++; } @@ -187,6 +190,8 @@ int16 Scenery::loadStatic(char search) { _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } } + if (extData != 0) + delete[] extData; return sceneryIndex + 100; } @@ -213,13 +218,12 @@ void Scenery::freeStatic(int16 index) { } } + for (i = 0; i < _statics[index].layersCount; i++) + delete[] _statics[index].layers[i].planes; delete[] _statics[index].layers; delete[] _statics[index].pieces; delete[] _statics[index].piecesFromExt; - if (_staticFromExt[index] == 1) - delete[] _statics[index].dataPtr; - _staticFromExt[index] = 0; _staticPictCount[index] = -1; } @@ -243,7 +247,7 @@ void Scenery::renderStatic(int16 scenery, int16 layer) { if (layer >= ptr->layersCount) return; - layerPtr = ptr->layers[layer]; + layerPtr = &ptr->layers[layer]; _vm->_draw->_spriteLeft = layerPtr->backResId; if (_vm->_draw->_spriteLeft != -1) { @@ -305,7 +309,7 @@ void Scenery::updateStatic(int16 orderFrom) { if (_curStaticLayer >= _statics[_curStatic].layersCount) return; - layerPtr = _statics[_curStatic].layers[_curStaticLayer]; + layerPtr = &_statics[_curStatic].layers[_curStaticLayer]; pictPtr = _statics[_curStatic].pieces; planeCount = layerPtr->planeCount; @@ -433,7 +437,7 @@ int16 Scenery::loadAnim(char search) { for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); - Common::MemoryReadStream layerData((byte *) (dataPtr + offset - 2), 65535); + Common::MemoryReadStream layerData((byte *) (dataPtr + offset - 2), 4294967295U); ptr->layers[i].unknown0 = layerData.readSint16LE(); ptr->layers[i].posX = layerData.readSint16LE(); diff --git a/engines/gob/scenery.h b/engines/gob/scenery.h index 582238d2d9..e8121b9398 100644 --- a/engines/gob/scenery.h +++ b/engines/gob/scenery.h @@ -47,7 +47,7 @@ public: struct StaticLayer { int16 backResId; int16 planeCount; - StaticPlane planes[1]; + StaticPlane *planes; } GCC_PACK; // Animations @@ -74,12 +74,11 @@ public: struct Static { int16 layersCount; - StaticLayer **layers; + StaticLayer *layers; PieceDesc **pieces; int8 *piecesFromExt; - char *dataPtr; Static() : layersCount(0), layers(0), pieces(0), - piecesFromExt(0), dataPtr(0) {} + piecesFromExt(0) {} }; struct Animation { @@ -99,7 +98,6 @@ public: char _staticPictToSprite[70]; int16 _staticPictCount[10]; Static _statics[10]; - char _staticFromExt[10]; int16 _staticResId[10]; char _animPictToSprite[70]; |