Fix crashes during WW startup

svn-id: r23944
This commit is contained in:
Travis Howell 2006-09-20 06:39:27 +00:00
parent 68360e4dde
commit e63717a2eb
8 changed files with 169 additions and 58 deletions

View File

@ -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"},

View File

@ -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 {

View File

@ -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();

View File

@ -15,6 +15,7 @@ MODULE_OBJS := \
midiparser_s1d.o \
oracle.o \
res.o \
rooms.o \
saveload.o \
simon.o \
sound.o \

View File

@ -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) {

114
engines/simon/rooms.cpp Normal file
View File

@ -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

View File

@ -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);

View File

@ -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);