diff options
author | Travis Howell | 2006-09-20 06:39:27 +0000 |
---|---|---|
committer | Travis Howell | 2006-09-20 06:39:27 +0000 |
commit | e63717a2eb4df76fb97736daebb40b72c2f888fa (patch) | |
tree | 3326874a5d61b5940fea0dea912b6daad4ed795b /engines | |
parent | 68360e4ddedd8806d269320bac91ab6cace34a18 (diff) | |
download | scummvm-rg350-e63717a2eb4df76fb97736daebb40b72c2f888fa.tar.gz scummvm-rg350-e63717a2eb4df76fb97736daebb40b72c2f888fa.tar.bz2 scummvm-rg350-e63717a2eb4df76fb97736daebb40b72c2f888fa.zip |
Fix crashes during WW startup
svn-id: r23944
Diffstat (limited to 'engines')
-rw-r--r-- | engines/simon/game.cpp | 1 | ||||
-rw-r--r-- | engines/simon/intern.h | 7 | ||||
-rw-r--r-- | engines/simon/items.cpp | 39 | ||||
-rw-r--r-- | engines/simon/module.mk | 1 | ||||
-rw-r--r-- | engines/simon/res.cpp | 58 | ||||
-rw-r--r-- | engines/simon/rooms.cpp | 114 | ||||
-rw-r--r-- | engines/simon/simon.cpp | 3 | ||||
-rw-r--r-- | engines/simon/simon.h | 4 |
8 files changed, 169 insertions, 58 deletions
diff --git a/engines/simon/game.cpp b/engines/simon/game.cpp index cde814605b..9b32fe90b1 100644 --- a/engines/simon/game.cpp +++ b/engines/simon/game.cpp @@ -590,6 +590,7 @@ static GameFileDescription FEEBLEFILES_ES_GameFiles[] = { static GameFileDescription WAXWORKS_GameFiles[] = { { "gamepc", GAME_BASEFILE, "7751e9358e894e32ef40ef3b3bae0f2a"}, { "icon.dat", GAME_ICONFILE, "ef1b8ad3494cf103dc10a99fe152ef9a"}, + { "roomslst", GAME_RMSLFILE, "e3758c46ab8f3c23a1ac012bd607108d"}, { "stripped.txt", GAME_STRFILE, "f259e3e07a1cde8d0404a767d815e12c"}, { "tbllist", GAME_TBLFILE, "95c44bfc380770a6b6dd0dfcc69e80a0"}, { "xtbllist", GAME_XTBLFILE, "6c7b3db345d46349a5226f695c03e20f"}, diff --git a/engines/simon/intern.h b/engines/simon/intern.h index 52deded6a5..3d82d6f284 100644 --- a/engines/simon/intern.h +++ b/engines/simon/intern.h @@ -176,10 +176,11 @@ enum GameFileTypes { GAME_ICONFILE = 1 << 1, GAME_GMEFILE = 1 << 2, GAME_STRFILE = 1 << 3, - GAME_TBLFILE = 1 << 4, - GAME_XTBLFILE = 1 << 5, + GAME_RMSLFILE = 1 << 4, + GAME_TBLFILE = 1 << 5, + GAME_XTBLFILE = 1 << 6, - GAME_GFXIDXFILE = 1 << 6 + GAME_GFXIDXFILE = 1 << 7 }; enum GameIds { diff --git a/engines/simon/items.cpp b/engines/simon/items.cpp index be3b39cd68..fbe8591de6 100644 --- a/engines/simon/items.cpp +++ b/engines/simon/items.cpp @@ -679,7 +679,12 @@ void SimonEngine::o_random() { void SimonEngine::o_goto() { // 55: set itemA parent - setItemParent(me(), getNextItemPtr()); + uint item = getNextItemID(); + if (_itemArrayPtr[item] == NULL) { + setItemParent(me(), NULL); + loadRoomItems(item); + } + setItemParent(me(), _itemArrayPtr[item]); } void SimonEngine::o_oset() { @@ -1542,38 +1547,6 @@ void SimonEngine::o_unfreezeZones() { // Waxworks 1 Opcodes // ----------------------------------------------------------------------- -uint16 SimonEngine::getDoorState(Item *item, uint16 d) { - uint16 mask = 3; - uint16 n; - - SubRoom *subRoom = (SubRoom *)findChildOfType(item, 1); - if (subRoom == NULL) - return 0; - - d <<= 1; - mask <<= d; - n = subRoom->roomExitStates & mask; - n >>= d; - - return n; -} - -uint16 SimonEngine::getExitOf(Item *item, uint16 d) { - uint16 x; - uint16 y = 0; - - SubRoom *subRoom = (SubRoom *)findChildOfType(item, 1); - if (subRoom == NULL) - return 0; - x = d; - while (x > y) { - if (getDoorState(item, y) == 0) - d--; - y++; - } - return subRoom->roomExit[d]; -} - void SimonEngine::oww_whereTo() { // 85: where to Item *i = getNextItemPtr(); diff --git a/engines/simon/module.mk b/engines/simon/module.mk index dfd6a3e56b..0c98b65d34 100644 --- a/engines/simon/module.mk +++ b/engines/simon/module.mk @@ -15,6 +15,7 @@ MODULE_OBJS := \ midiparser_s1d.o \ oracle.o \ res.o \ + rooms.o \ saveload.o \ simon.o \ sound.o \ diff --git a/engines/simon/res.cpp b/engines/simon/res.cpp index 28f1e23946..212b66bcbe 100644 --- a/engines/simon/res.cpp +++ b/engines/simon/res.cpp @@ -269,27 +269,6 @@ void SimonEngine::loadGamePcFile() { in.close(); - if (getGameType() == GType_WW) { - /* Read list of TABLE resources */ - in.open(getFileName(GAME_XTBLFILE)); - if (in.isOpen() == false) { - error("loadGamePcFile: Can't load table resources file '%s'", getFileName(GAME_XTBLFILE)); - } - - file_size = in.size(); - - _xtblList = (byte *)malloc(file_size); - if (_xtblList == NULL) - error("loadGamePcFile: Out of memory for strip table list"); - in.read(_xtblList, file_size); - in.close(); - - /* Remember the current state */ - _xsubroutineListOrg = _subroutineList; - _xtablesHeapPtrOrg = _tablesHeapPtr; - _xtablesHeapCurPosOrg = _tablesHeapCurPos; - } - /* Read list of TABLE resources */ in.open(getFileName(GAME_TBLFILE)); if (in.isOpen() == false) { @@ -323,6 +302,43 @@ void SimonEngine::loadGamePcFile() { error("loadGamePcFile: Out of memory for strip text list"); in.read(_strippedTxtMem, file_size); in.close(); + + if (getGameType() != GType_WW) + return; + + /* Read list of ROOM ITEMS resources */ + in.open(getFileName(GAME_RMSLFILE)); + if (in.isOpen() == false) { + error("loadGamePcFile: Can't load room resources file '%s'", getFileName(GAME_XTBLFILE)); + } + + file_size = in.size(); + + _roomsList = (byte *)malloc(file_size); + if (_roomsList == NULL) + error("loadGamePcFile: Out of memory for room items list"); + in.read(_roomsList, file_size); + in.close(); + + /* Read list of XTABLE resources */ + in.open(getFileName(GAME_XTBLFILE)); + if (in.isOpen() == false) { + error("loadGamePcFile: Can't load xtable resources file '%s'", getFileName(GAME_XTBLFILE)); + } + + file_size = in.size(); + + _xtblList = (byte *)malloc(file_size); + if (_xtblList == NULL) + error("loadGamePcFile: Out of memory for strip xtable list"); + in.read(_xtblList, file_size); + in.close(); + + /* Remember the current state */ + _xsubroutineListOrg = _subroutineList; + _xtablesHeapPtrOrg = _tablesHeapPtr; + _xtablesHeapCurPosOrg = _tablesHeapCurPos; + } void SimonEngine::readGamePcText(Common::File *in) { diff --git a/engines/simon/rooms.cpp b/engines/simon/rooms.cpp new file mode 100644 index 0000000000..3752d4cf37 --- /dev/null +++ b/engines/simon/rooms.cpp @@ -0,0 +1,114 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001 Ludvig Strigeus + * Copyright (C) 2001-2006 The ScummVM project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/stdafx.h" + +#include "simon/simon.h" +#include "simon/intern.h" + +using Common::File; + +namespace Simon { + +uint16 SimonEngine::getDoorState(Item *item, uint16 d) { + uint16 mask = 3; + uint16 n; + + SubRoom *subRoom = (SubRoom *)findChildOfType(item, 1); + if (subRoom == NULL) + return 0; + + d <<= 1; + mask <<= d; + n = subRoom->roomExitStates & mask; + n >>= d; + + return n; +} + +uint16 SimonEngine::getExitOf(Item *item, uint16 d) { + uint16 x; + uint16 y = 0; + + SubRoom *subRoom = (SubRoom *)findChildOfType(item, 1); + if (subRoom == NULL) + return 0; + x = d; + while (x > y) { + if (getDoorState(item, y) == 0) + d--; + y++; + } + return subRoom->roomExit[d]; +} + +bool SimonEngine::loadRoomItems(uint item) { + byte *p; + uint i, min_num, max_num; + char filename[30]; + File in; + + p = _roomsList; + if (p == NULL) + return 0; + + while (*p) { + for (i = 0; *p; p++, i++) + filename[i] = *p; + filename[i] = 0; + p++; + + for (;;) { + min_num = (p[0] * 256) | p[1]; + p += 2; + + if (min_num == 0) + break; + + max_num = (p[0] * 256) | p[1]; + p += 2; + + if (item >= min_num && item <= max_num) { + + in.open(filename); + if (in.isOpen() == false) { + error("loadRoomItems: Can't load rooms file '%s'", filename); + } + + for (i = min_num; i <= max_num; i++) { + _itemArrayPtr[i] = (Item *)allocateItem(sizeof(Item)); + in.readUint16BE(); + readItemFromGamePc(&in, _itemArrayPtr[i]); + } + in.close(); + + return 1; + } + } + } + + debug(1,"loadRoomItems: didn't find %d", item); + return 0; +} + +} // End of namespace Simon diff --git a/engines/simon/simon.cpp b/engines/simon/simon.cpp index 9a254c28ce..0ccce68968 100644 --- a/engines/simon/simon.cpp +++ b/engines/simon/simon.cpp @@ -105,6 +105,8 @@ SimonEngine::SimonEngine(OSystem *syst) _stringIdLocalMin = 0; _stringIdLocalMax = 0; + _roomsList = 0; + _xtblList = 0; _xtablesHeapPtrOrg = 0; _xtablesHeapCurPosOrg = 0; @@ -769,7 +771,6 @@ Item *SimonEngine::getNextItemPtr() { case -7: return actor(); case -9: - assert (derefItem(me()->parent) != NULL); return derefItem(me()->parent); default: return derefItem(a); diff --git a/engines/simon/simon.h b/engines/simon/simon.h index cc1d49764f..148f9d47ef 100644 --- a/engines/simon/simon.h +++ b/engines/simon/simon.h @@ -222,6 +222,8 @@ protected: byte **_localStringtable; uint _stringIdLocalMin, _stringIdLocalMax; + byte *_roomsList; + byte *_xtblList; byte *_xtablesHeapPtrOrg; uint _xtablesHeapCurPosOrg; @@ -631,6 +633,8 @@ protected: bool loadTablesIntoMem(uint subr_id); bool loadXTablesIntoMem(uint subr_id); + bool loadRoomItems(uint item); + uint loadTextFile(const char *filename, byte *dst); Common::File *openTablesFile(const char *filename); void closeTablesFile(Common::File *in); |