2002-06-29 16:23:33 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-05-05 00:42:37 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
2002-06-29 16:23:33 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-06-29 16:23:33 +00:00
|
|
|
*
|
2006-02-11 12:46:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-06-29 16:23:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Resource file routines for Simon1/Simon2
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2006-04-14 04:22:49 +00:00
|
|
|
|
2002-11-10 15:24:17 +00:00
|
|
|
#include "common/file.h"
|
2006-04-14 04:22:49 +00:00
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/agos.h"
|
|
|
|
#include "agos/intern.h"
|
|
|
|
#include "agos/sound.h"
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
#include <zlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using Common::File;
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
uint16 AGOSEngine::to16Wrapper(uint value) {
|
2006-09-28 23:22:07 +00:00
|
|
|
if (getGameType() == GType_FF || getGameType() == GType_PP)
|
2005-11-10 01:18:09 +00:00
|
|
|
return TO_LE_16(value);
|
|
|
|
else
|
|
|
|
return TO_BE_16(value);
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
uint16 AGOSEngine::readUint16Wrapper(const void *src) {
|
2006-09-28 23:22:07 +00:00
|
|
|
if (getGameType() == GType_FF || getGameType() == GType_PP)
|
2005-10-12 00:35:54 +00:00
|
|
|
return READ_LE_UINT16(src);
|
|
|
|
else
|
|
|
|
return READ_BE_UINT16(src);
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
uint32 AGOSEngine::readUint32Wrapper(const void *src) {
|
2006-09-28 23:22:07 +00:00
|
|
|
if (getGameType() == GType_FF || getGameType() == GType_PP)
|
2006-04-07 14:27:28 +00:00
|
|
|
return READ_LE_UINT32(src);
|
|
|
|
else
|
|
|
|
return READ_BE_UINT32(src);
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::decompressData(const char *srcName, byte *dst, uint32 offset, uint32 srcSize, uint32 dstSize) {
|
2006-04-14 04:22:49 +00:00
|
|
|
#ifdef USE_ZLIB
|
|
|
|
File in;
|
|
|
|
in.open(srcName);
|
|
|
|
if (in.isOpen() == false)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("decompressData: Can't load %s", srcName);
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
in.seek(offset, SEEK_SET);
|
|
|
|
if (srcSize != dstSize) {
|
|
|
|
byte *srcBuffer = (byte *)malloc(srcSize);
|
|
|
|
|
|
|
|
if (in.read(srcBuffer, srcSize) != srcSize)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("decompressData: Read failed");
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
unsigned long decompressedSize = dstSize;
|
|
|
|
int result = uncompress(dst, &decompressedSize, srcBuffer, srcSize);
|
|
|
|
if (result != Z_OK)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("decompressData: Zlib uncompress error");
|
2006-04-14 04:22:49 +00:00
|
|
|
free(srcBuffer);
|
|
|
|
} else {
|
|
|
|
if (in.read(dst, dstSize) != dstSize)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("decompressData: Read failed");
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
#else
|
|
|
|
error("Zlib support is required for Amiga and Macintosh versions");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::loadOffsets(const char *filename, int number, uint32 &file, uint32 &offset, uint32 &srcSize, uint32 &dstSize) {
|
2006-03-22 06:21:17 +00:00
|
|
|
Common::File in;
|
|
|
|
|
|
|
|
int offsSize = (getPlatform() == Common::kPlatformAmiga) ? 16 : 12;
|
|
|
|
|
|
|
|
/* read offsets from index */
|
|
|
|
in.open(filename);
|
|
|
|
if (in.isOpen() == false) {
|
2006-08-27 05:02:48 +00:00
|
|
|
error("loadOffsets: Can't load index file '%s'", filename);
|
2006-03-22 06:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(number * offsSize, SEEK_SET);
|
|
|
|
offset = in.readUint32LE();
|
|
|
|
dstSize = in.readUint32LE();
|
|
|
|
srcSize = in.readUint32LE();
|
|
|
|
file = in.readUint32LE();
|
|
|
|
in.close();
|
|
|
|
}
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
int AGOSEngine::allocGamePcVars(Common::SeekableReadStream *in) {
|
2006-04-29 14:11:29 +00:00
|
|
|
uint item_array_size, item_array_inited, stringtable_num;
|
|
|
|
uint32 version;
|
2006-10-05 08:54:51 +00:00
|
|
|
uint i;
|
2006-04-29 14:11:29 +00:00
|
|
|
|
|
|
|
item_array_size = in->readUint32BE();
|
|
|
|
version = in->readUint32BE();
|
|
|
|
item_array_inited = in->readUint32BE();
|
|
|
|
stringtable_num = in->readUint32BE();
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
// First two items are predefined
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2) {
|
2006-10-05 08:54:51 +00:00
|
|
|
item_array_size += 2;
|
2006-09-28 23:22:07 +00:00
|
|
|
item_array_inited = item_array_size;
|
|
|
|
} else {
|
2006-10-16 04:31:09 +00:00
|
|
|
item_array_inited += 2;
|
2006-09-28 23:22:07 +00:00
|
|
|
item_array_size += 2;
|
|
|
|
}
|
2006-04-29 14:11:29 +00:00
|
|
|
|
|
|
|
if (version != 0x80)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("allocGamePcVars: Not a runtime database");
|
2006-04-29 14:11:29 +00:00
|
|
|
|
|
|
|
_itemArrayPtr = (Item **)calloc(item_array_size, sizeof(Item *));
|
|
|
|
if (_itemArrayPtr == NULL)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("allocGamePcVars: Out of memory for Item array");
|
2006-04-29 14:11:29 +00:00
|
|
|
|
|
|
|
_itemArraySize = item_array_size;
|
|
|
|
_itemArrayInited = item_array_inited;
|
|
|
|
|
2006-10-05 08:54:51 +00:00
|
|
|
for (i = 1; i < item_array_inited; i++) {
|
2006-04-29 14:11:29 +00:00
|
|
|
_itemArrayPtr[i] = (Item *)allocateItem(sizeof(Item));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The rest is cleared automatically by calloc
|
|
|
|
allocateStringTable(stringtable_num + 10);
|
|
|
|
_stringTabNum = stringtable_num;
|
|
|
|
|
|
|
|
return item_array_inited;
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::loadGamePcFile() {
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File in;
|
2006-10-16 04:31:09 +00:00
|
|
|
int fileSize;
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
if (getFileName(GAME_BASEFILE) != NULL) {
|
|
|
|
/* Read main gamexx file */
|
|
|
|
in.open(getFileName(GAME_BASEFILE));
|
|
|
|
if (in.isOpen() == false) {
|
|
|
|
error("loadGamePcFile: Can't load gamexx file '%s'", getFileName(GAME_BASEFILE));
|
|
|
|
}
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
if (getFeatures() & GF_CRUNCHED_GAMEPC) {
|
|
|
|
uint srcSize = in.size();
|
|
|
|
byte *srcBuf = (byte *)malloc(srcSize);
|
|
|
|
in.read(srcBuf, srcSize);
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
uint dstSize = READ_BE_UINT32(srcBuf + srcSize - 4);
|
|
|
|
byte *dstBuf = (byte *)malloc(dstSize);
|
|
|
|
decrunchFile(srcBuf, dstBuf, srcSize);
|
|
|
|
free(srcBuf);
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
Common::MemoryReadStream stream(dstBuf, dstSize);
|
|
|
|
readGamePcFile(&stream);
|
|
|
|
free(dstBuf);
|
|
|
|
} else {
|
|
|
|
readGamePcFile(&in);
|
|
|
|
}
|
|
|
|
in.close();
|
2002-06-29 16:23:33 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 14:59:16 +00:00
|
|
|
if (getFileName(GAME_TBLFILE) != NULL) {
|
|
|
|
/* Read list of TABLE resources */
|
|
|
|
in.open(getFileName(GAME_TBLFILE));
|
|
|
|
if (in.isOpen() == false) {
|
|
|
|
error("loadGamePcFile: Can't load table resources file '%s'", getFileName(GAME_TBLFILE));
|
|
|
|
}
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
fileSize = in.size();
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
_tblList = (byte *)malloc(fileSize);
|
2006-10-11 14:59:16 +00:00
|
|
|
if (_tblList == NULL)
|
|
|
|
error("loadGamePcFile: Out of memory for strip table list");
|
2006-10-15 04:15:48 +00:00
|
|
|
in.read(_tblList, fileSize);
|
2006-10-11 14:59:16 +00:00
|
|
|
in.close();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2006-10-11 14:59:16 +00:00
|
|
|
/* Remember the current state */
|
|
|
|
_subroutineListOrg = _subroutineList;
|
|
|
|
_tablesHeapPtrOrg = _tablesHeapPtr;
|
|
|
|
_tablesHeapCurPosOrg = _tablesHeapCurPos;
|
|
|
|
}
|
2005-10-06 14:34:24 +00:00
|
|
|
|
2006-10-11 14:59:16 +00:00
|
|
|
if (getFileName(GAME_STRFILE) != NULL) {
|
|
|
|
/* Read list of TEXT resources */
|
|
|
|
in.open(getFileName(GAME_STRFILE));
|
|
|
|
if (in.isOpen() == false)
|
|
|
|
error("loadGamePcFile: Can't load text resources file '%s'", getFileName(GAME_STRFILE));
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
fileSize = in.size();
|
|
|
|
_strippedTxtMem = (byte *)malloc(fileSize);
|
2006-10-11 14:59:16 +00:00
|
|
|
if (_strippedTxtMem == NULL)
|
|
|
|
error("loadGamePcFile: Out of memory for strip text list");
|
2006-10-15 04:15:48 +00:00
|
|
|
in.read(_strippedTxtMem, fileSize);
|
2006-10-11 14:59:16 +00:00
|
|
|
in.close();
|
|
|
|
}
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-11 14:59:16 +00:00
|
|
|
if (getFileName(GAME_RMSLFILE) != NULL) {
|
2006-10-05 03:43:40 +00:00
|
|
|
/* Read list of ROOM ITEMS resources */
|
|
|
|
in.open(getFileName(GAME_RMSLFILE));
|
|
|
|
if (in.isOpen() == false) {
|
2006-10-15 04:15:48 +00:00
|
|
|
error("loadGamePcFile: Can't load room resources file '%s'", getFileName(GAME_RMSLFILE));
|
2006-10-05 03:43:40 +00:00
|
|
|
}
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
fileSize = in.size();
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
_roomsList = (byte *)malloc(fileSize);
|
2006-10-05 03:43:40 +00:00
|
|
|
if (_roomsList == NULL)
|
|
|
|
error("loadGamePcFile: Out of memory for room items list");
|
2006-10-15 04:15:48 +00:00
|
|
|
in.read(_roomsList, fileSize);
|
2006-10-05 03:43:40 +00:00
|
|
|
in.close();
|
2006-09-20 06:39:27 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 14:59:16 +00:00
|
|
|
if (getFileName(GAME_XTBLFILE) != NULL) {
|
2006-10-05 03:43:40 +00:00
|
|
|
/* 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));
|
|
|
|
}
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
fileSize = in.size();
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-15 04:15:48 +00:00
|
|
|
_xtblList = (byte *)malloc(fileSize);
|
2006-10-05 03:43:40 +00:00
|
|
|
if (_xtblList == NULL)
|
|
|
|
error("loadGamePcFile: Out of memory for strip xtable list");
|
2006-10-15 04:15:48 +00:00
|
|
|
in.read(_xtblList, fileSize);
|
2006-10-05 03:43:40 +00:00
|
|
|
in.close();
|
2006-09-20 06:39:27 +00:00
|
|
|
|
2006-10-05 03:43:40 +00:00
|
|
|
/* Remember the current state */
|
|
|
|
_xsubroutineListOrg = _subroutineList;
|
|
|
|
_xtablesHeapPtrOrg = _tablesHeapPtr;
|
|
|
|
_xtablesHeapCurPosOrg = _tablesHeapCurPos;
|
|
|
|
}
|
2002-06-29 16:23:33 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
void AGOSEngine::readGamePcFile(Common::SeekableReadStream *in) {
|
|
|
|
int num_inited_objects;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
num_inited_objects = allocGamePcVars(in);
|
|
|
|
|
|
|
|
createPlayer();
|
|
|
|
readGamePcText(in);
|
|
|
|
|
|
|
|
for (i = 2; i < num_inited_objects; i++) {
|
|
|
|
readItemFromGamePc(in, _itemArrayPtr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
readSubroutineBlock(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::readGamePcText(Common::SeekableReadStream *in) {
|
2006-04-24 04:43:37 +00:00
|
|
|
_textSize = in->readUint32BE();
|
2006-04-24 06:02:47 +00:00
|
|
|
_textMem = (byte *)malloc(_textSize);
|
|
|
|
if (_textMem == NULL)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("readGamePcText: Out of text memory");
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-04-24 06:02:47 +00:00
|
|
|
in->read(_textMem, _textSize);
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-04-24 06:02:47 +00:00
|
|
|
setupStringTable(_textMem, _stringTabNum);
|
2002-06-29 16:23:33 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
void AGOSEngine::readItemFromGamePc(Common::SeekableReadStream *in, Item *item) {
|
2002-06-29 16:23:33 +00:00
|
|
|
uint32 type;
|
|
|
|
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2006-09-28 23:22:07 +00:00
|
|
|
item->itemName = (uint16)in->readUint32BE();
|
|
|
|
item->adjective = in->readUint16BE();
|
|
|
|
item->noun = in->readUint16BE();
|
|
|
|
item->state = in->readUint16BE();
|
|
|
|
in->readUint16BE();
|
2006-10-06 14:44:39 +00:00
|
|
|
item->next = (uint16)fileReadItemID(in);
|
2006-09-28 23:22:07 +00:00
|
|
|
item->child = (uint16)fileReadItemID(in);
|
|
|
|
item->parent = (uint16)fileReadItemID(in);
|
|
|
|
in->readUint16BE();
|
|
|
|
in->readUint16BE();
|
|
|
|
in->readUint16BE();
|
|
|
|
item->classFlags = in->readUint16BE();
|
|
|
|
item->children = NULL;
|
2006-10-04 07:10:22 +00:00
|
|
|
} else if (getGameType() == GType_ELVIRA2) {
|
|
|
|
item->itemName = (uint16)in->readUint32BE();
|
|
|
|
item->adjective = in->readUint16BE();
|
|
|
|
item->noun = in->readUint16BE();
|
|
|
|
item->state = in->readUint16BE();
|
2006-10-06 14:44:39 +00:00
|
|
|
item->next = (uint16)fileReadItemID(in);
|
2006-10-04 07:10:22 +00:00
|
|
|
item->child = (uint16)fileReadItemID(in);
|
|
|
|
item->parent = (uint16)fileReadItemID(in);
|
|
|
|
in->readUint16BE();
|
|
|
|
item->classFlags = in->readUint16BE();
|
|
|
|
item->children = NULL;
|
2006-09-28 23:22:07 +00:00
|
|
|
} else {
|
|
|
|
item->adjective = in->readUint16BE();
|
|
|
|
item->noun = in->readUint16BE();
|
|
|
|
item->state = in->readUint16BE();
|
2006-10-06 14:44:39 +00:00
|
|
|
item->next = (uint16)fileReadItemID(in);
|
2006-09-28 23:22:07 +00:00
|
|
|
item->child = (uint16)fileReadItemID(in);
|
|
|
|
item->parent = (uint16)fileReadItemID(in);
|
|
|
|
in->readUint16BE();
|
|
|
|
item->classFlags = in->readUint16BE();
|
|
|
|
item->children = NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2002-10-21 13:23:25 +00:00
|
|
|
type = in->readUint32BE();
|
2002-06-29 16:23:33 +00:00
|
|
|
while (type) {
|
2002-10-21 13:23:25 +00:00
|
|
|
type = in->readUint16BE();
|
2002-06-29 16:23:33 +00:00
|
|
|
if (type != 0)
|
|
|
|
readItemChildren(in, item, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
void AGOSEngine::readItemChildren(Common::SeekableReadStream *in, Item *item, uint type) {
|
2002-06-29 16:23:33 +00:00
|
|
|
if (type == 1) {
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2006-09-30 02:15:02 +00:00
|
|
|
SubRoom *subRoom = (SubRoom *)allocateChildBlock(item, 1, sizeof(SubRoom));
|
|
|
|
subRoom->roomShort = in->readUint32BE();
|
|
|
|
subRoom->roomLong = in->readUint32BE();
|
|
|
|
subRoom->flags = in->readUint16BE();
|
2006-09-28 23:22:07 +00:00
|
|
|
} else {
|
|
|
|
uint fr1 = in->readUint16BE();
|
|
|
|
uint fr2 = in->readUint16BE();
|
|
|
|
uint i, size;
|
|
|
|
uint j, k;
|
|
|
|
SubRoom *subRoom;
|
|
|
|
|
|
|
|
size = SubRoom_SIZE;
|
|
|
|
for (i = 0, j = fr2; i != 6; i++, j >>= 2)
|
|
|
|
if (j & 3)
|
|
|
|
size += sizeof(subRoom->roomExit[0]);
|
|
|
|
|
|
|
|
subRoom = (SubRoom *)allocateChildBlock(item, 1, size);
|
|
|
|
subRoom->subroutine_id = fr1;
|
|
|
|
subRoom->roomExitStates = fr2;
|
|
|
|
|
|
|
|
for (i = k = 0, j = fr2; i != 6; i++, j >>= 2)
|
|
|
|
if (j & 3)
|
|
|
|
subRoom->roomExit[k++] = (uint16)fileReadItemID(in);
|
|
|
|
}
|
2002-06-29 16:23:33 +00:00
|
|
|
} else if (type == 2) {
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2006-09-30 05:51:06 +00:00
|
|
|
SubObject *subObject = (SubObject *)allocateChildBlock(item, 2, sizeof(SubObject));
|
|
|
|
in->readUint32BE();
|
|
|
|
in->readUint32BE();
|
|
|
|
in->readUint32BE();
|
|
|
|
subObject->objectName = in->readUint32BE();
|
|
|
|
subObject->objectSize = in->readUint16BE();
|
|
|
|
subObject->objectWeight = in->readUint16BE();
|
|
|
|
subObject->objectFlags = in->readUint16BE();
|
|
|
|
} else {
|
|
|
|
uint32 fr = in->readUint32BE();
|
|
|
|
uint i, k, size;
|
|
|
|
SubObject *subObject;
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-09-30 05:51:06 +00:00
|
|
|
size = SubObject_SIZE;
|
|
|
|
for (i = 0; i != 16; i++)
|
|
|
|
if (fr & (1 << i))
|
|
|
|
size += sizeof(subObject->objectFlagValue[0]);
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-09-30 05:51:06 +00:00
|
|
|
subObject = (SubObject *)allocateChildBlock(item, 2, size);
|
|
|
|
subObject->objectFlags = fr;
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-09-30 05:51:06 +00:00
|
|
|
k = 0;
|
|
|
|
if (fr & 1) {
|
|
|
|
subObject->objectFlagValue[k++] = (uint16)in->readUint32BE();
|
|
|
|
}
|
|
|
|
for (i = 1; i != 16; i++)
|
|
|
|
if (fr & (1 << i))
|
|
|
|
subObject->objectFlagValue[k++] = in->readUint16BE();
|
2002-06-29 16:23:33 +00:00
|
|
|
|
2006-10-04 07:10:22 +00:00
|
|
|
if (getGameType() != GType_ELVIRA2)
|
|
|
|
subObject->objectName = (uint16)in->readUint32BE();
|
2006-09-30 05:51:06 +00:00
|
|
|
}
|
2006-09-28 23:22:07 +00:00
|
|
|
} else if (type == 4) {
|
2006-10-04 07:10:22 +00:00
|
|
|
if (getGameType() == GType_ELVIRA2) {
|
|
|
|
uint i, j, k, size;
|
|
|
|
uint id, x, y, z;
|
|
|
|
SubSuperRoom *subSuperRoom;
|
|
|
|
|
|
|
|
id = in->readUint16BE();
|
|
|
|
x = in->readUint16BE();
|
|
|
|
y = in->readUint16BE();
|
|
|
|
z = in->readUint16BE();
|
|
|
|
|
|
|
|
j = x * y * z;
|
|
|
|
size = SubSuperRoom_SIZE;
|
|
|
|
for (i = 0; i != j; i++)
|
2006-11-05 08:27:15 +00:00
|
|
|
size += sizeof(subSuperRoom->roomExitStates[0]);
|
2006-10-04 07:10:22 +00:00
|
|
|
|
|
|
|
subSuperRoom = (SubSuperRoom *)allocateChildBlock(item, 4, size);
|
|
|
|
subSuperRoom->subroutine_id = id;
|
|
|
|
subSuperRoom->roomX = x;
|
|
|
|
subSuperRoom->roomY = y;
|
|
|
|
subSuperRoom->roomZ = z;
|
|
|
|
|
|
|
|
for (i = k = 0; i != j; i++)
|
2006-11-05 08:27:15 +00:00
|
|
|
subSuperRoom->roomExitStates[k++] = in->readUint16BE();
|
2006-10-06 05:13:09 +00:00
|
|
|
} else if (getGameType() == GType_ELVIRA1) {
|
2006-10-04 07:10:22 +00:00
|
|
|
SubGenExit *genExit = (SubGenExit *)allocateChildBlock(item, 4, sizeof(SubGenExit));
|
|
|
|
genExit->dest[0] = (uint16)fileReadItemID(in);
|
|
|
|
genExit->dest[1] = (uint16)fileReadItemID(in);
|
|
|
|
genExit->dest[2] = (uint16)fileReadItemID(in);
|
|
|
|
genExit->dest[3] = (uint16)fileReadItemID(in);
|
|
|
|
genExit->dest[4] = (uint16)fileReadItemID(in);
|
|
|
|
genExit->dest[5] = (uint16)fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
}
|
2006-09-28 23:22:07 +00:00
|
|
|
} else if (type == 7) {
|
2006-09-30 02:15:02 +00:00
|
|
|
SubContainer *container = (SubContainer *)allocateChildBlock(item, 7, sizeof(SubContainer));
|
|
|
|
container->volume = in->readUint16BE();
|
|
|
|
container->flags = in->readUint16BE();
|
2006-09-19 11:59:13 +00:00
|
|
|
} else if (type == 8) {
|
2006-11-06 14:28:19 +00:00
|
|
|
SubChain *chain = (SubChain *)allocateChildBlock(item, 8, sizeof(SubChain));
|
2006-09-19 11:59:13 +00:00
|
|
|
chain->chChained = (uint16)fileReadItemID(in);
|
|
|
|
} else if (type == 9) {
|
|
|
|
setUserFlag(item, 0, in->readUint16BE());
|
|
|
|
setUserFlag(item, 1, in->readUint16BE());
|
|
|
|
setUserFlag(item, 2, in->readUint16BE());
|
|
|
|
setUserFlag(item, 3, in->readUint16BE());
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2006-09-28 23:22:07 +00:00
|
|
|
setUserFlag(item, 4, in->readUint16BE());
|
|
|
|
setUserFlag(item, 5, in->readUint16BE());
|
|
|
|
setUserFlag(item, 6, in->readUint16BE());
|
|
|
|
setUserFlag(item, 7, in->readUint16BE());
|
2006-09-30 02:15:02 +00:00
|
|
|
SubUserFlag *subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
|
|
|
|
subUserFlag->userItems[0] = (uint16)fileReadItemID(in);
|
2006-09-28 23:22:07 +00:00
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
fileReadItemID(in);
|
|
|
|
}
|
2006-09-19 11:59:13 +00:00
|
|
|
} else if (type == 255) {
|
2006-11-06 14:28:19 +00:00
|
|
|
SubInherit *inherit = (SubInherit *)allocateChildBlock(item, 255, sizeof(SubInherit));
|
2006-09-19 11:59:13 +00:00
|
|
|
inherit->inMaster = (uint16)fileReadItemID(in);
|
2002-06-29 16:23:33 +00:00
|
|
|
} else {
|
2005-10-09 09:03:37 +00:00
|
|
|
error("readItemChildren: invalid type %d", type);
|
2002-06-29 16:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-16 04:31:09 +00:00
|
|
|
uint fileReadItemID(Common::SeekableReadStream *in) {
|
2002-10-21 13:23:25 +00:00
|
|
|
uint32 val = in->readUint32BE();
|
2002-07-07 19:06:48 +00:00
|
|
|
if (val == 0xFFFFFFFF)
|
2002-06-29 16:23:33 +00:00
|
|
|
return 0;
|
|
|
|
return val + 2;
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::openGameFile() {
|
2007-01-01 05:44:34 +00:00
|
|
|
_gameFile = new File();
|
|
|
|
_gameFile->open(getFileName(GAME_GMEFILE));
|
2006-04-21 00:18:23 +00:00
|
|
|
|
2007-01-01 05:44:34 +00:00
|
|
|
if (!_gameFile->isOpen())
|
|
|
|
error("openGameFile: Can't load game file '%s'", getFileName(GAME_GMEFILE));
|
2006-04-21 00:18:23 +00:00
|
|
|
|
2007-01-01 05:44:34 +00:00
|
|
|
uint32 size = _gameFile->readUint32LE();
|
2006-04-21 00:18:23 +00:00
|
|
|
|
2007-01-01 05:44:34 +00:00
|
|
|
_gameOffsetsPtr = (uint32 *)malloc(size);
|
|
|
|
if (_gameOffsetsPtr == NULL)
|
|
|
|
error("openGameFile: Out of memory, game offsets");
|
2006-04-21 00:18:23 +00:00
|
|
|
|
2007-01-01 05:44:34 +00:00
|
|
|
_gameFile->seek(0, SEEK_SET);
|
|
|
|
|
|
|
|
for (uint r = 0; r < size / 4; r++)
|
|
|
|
_gameOffsetsPtr[r] = _gameFile->readUint32LE();
|
2006-04-21 00:18:23 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::readGameFile(void *dst, uint32 offs, uint32 size) {
|
2006-04-21 00:18:23 +00:00
|
|
|
_gameFile->seek(offs, SEEK_SET);
|
|
|
|
if (_gameFile->read(dst, size) != size)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("readGameFile: Read failed (%d,%d)", offs, size);
|
2006-04-21 00:18:23 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 04:22:49 +00:00
|
|
|
// Thanks to Stuart Caie for providing the original
|
|
|
|
// C conversion upon which this decruncher is based.
|
|
|
|
|
|
|
|
#define SD_GETBIT(var) do { \
|
|
|
|
if (!bits--) { \
|
|
|
|
s -= 4; \
|
|
|
|
if (s < src) \
|
|
|
|
return false; \
|
|
|
|
bb = READ_BE_UINT32(s); \
|
|
|
|
bits = 31; \
|
|
|
|
} \
|
|
|
|
(var) = bb & 1; \
|
|
|
|
bb >>= 1; \
|
|
|
|
}while (0)
|
|
|
|
|
|
|
|
#define SD_GETBITS(var, nbits) do { \
|
|
|
|
bc = (nbits); \
|
|
|
|
(var) = 0; \
|
|
|
|
while (bc--) { \
|
|
|
|
(var) <<= 1; \
|
|
|
|
SD_GETBIT(bit); \
|
|
|
|
(var) |= bit; \
|
|
|
|
} \
|
|
|
|
}while (0)
|
|
|
|
|
|
|
|
#define SD_TYPE_LITERAL (0)
|
|
|
|
#define SD_TYPE_MATCH (1)
|
|
|
|
|
2006-10-14 13:51:01 +00:00
|
|
|
bool AGOSEngine::decrunchFile(byte *src, byte *dst, uint32 size) {
|
2006-04-14 04:22:49 +00:00
|
|
|
byte *s = src + size - 4;
|
|
|
|
uint32 destlen = READ_BE_UINT32 (s);
|
|
|
|
uint32 bb, x, y;
|
|
|
|
byte *d = dst + destlen;
|
|
|
|
byte bc, bit, bits, type;
|
|
|
|
|
|
|
|
// Initialize bit buffer.
|
|
|
|
s -= 4;
|
|
|
|
bb = x = READ_BE_UINT32 (s);
|
|
|
|
bits = 0;
|
|
|
|
do {
|
|
|
|
x >>= 1;
|
|
|
|
bits++;
|
|
|
|
} while (x);
|
|
|
|
bits--;
|
|
|
|
|
|
|
|
while (d > dst) {
|
|
|
|
SD_GETBIT(x);
|
|
|
|
if (x) {
|
|
|
|
SD_GETBITS(x, 2);
|
|
|
|
switch (x) {
|
|
|
|
case 0:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 9;
|
|
|
|
y = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 10;
|
|
|
|
y = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 12;
|
|
|
|
SD_GETBITS(y, 8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
type = SD_TYPE_LITERAL;
|
|
|
|
x = 8;
|
|
|
|
y = 8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SD_GETBIT(x);
|
|
|
|
if (x) {
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 8;
|
|
|
|
y = 1;
|
|
|
|
} else {
|
|
|
|
type = SD_TYPE_LITERAL;
|
|
|
|
x = 3;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == SD_TYPE_LITERAL) {
|
|
|
|
SD_GETBITS(x, x);
|
|
|
|
y += x;
|
|
|
|
if ((int)(y + 1) > (d - dst))
|
|
|
|
return false; // Overflow?
|
|
|
|
do {
|
|
|
|
SD_GETBITS(x, 8);
|
|
|
|
*--d = x;
|
|
|
|
} while (y-- > 0);
|
|
|
|
} else {
|
|
|
|
if ((int)(y + 1) > (d - dst))
|
|
|
|
return false; // Overflow?
|
|
|
|
SD_GETBITS(x, x);
|
|
|
|
if ((d + x) > (dst + destlen))
|
|
|
|
return false; // Offset overflow?
|
|
|
|
do {
|
|
|
|
d--;
|
|
|
|
*d = d[x];
|
|
|
|
} while (y-- > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Successful decrunch.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef SD_GETBIT
|
|
|
|
#undef SD_GETBITS
|
|
|
|
#undef SD_TYPE_LITERAL
|
|
|
|
#undef SD_TYPE_MATCH
|
|
|
|
|
2006-10-19 11:13:28 +00:00
|
|
|
void AGOSEngine::loadVGABeardFile(uint id) {
|
2006-04-20 00:42:54 +00:00
|
|
|
uint32 offs, size;
|
|
|
|
|
2006-04-14 04:22:49 +00:00
|
|
|
if (getFeatures() & GF_OLD_BUNDLE) {
|
|
|
|
File in;
|
|
|
|
char filename[15];
|
2006-10-03 14:02:14 +00:00
|
|
|
if (id == 23)
|
|
|
|
id = 112;
|
|
|
|
else if (id == 328)
|
|
|
|
id = 119;
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
if (getPlatform() == Common::kPlatformAmiga) {
|
|
|
|
if (getFeatures() & GF_TALKIE)
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "0%d.out", id);
|
2006-04-14 04:22:49 +00:00
|
|
|
else
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "0%d.pkd", id);
|
2006-04-14 04:22:49 +00:00
|
|
|
} else {
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "0%d.VGA", id);
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
in.open(filename);
|
|
|
|
if (in.isOpen() == false)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("loadSimonVGAFile: Can't load %s", filename);
|
2006-04-14 04:22:49 +00:00
|
|
|
|
2006-04-20 00:42:54 +00:00
|
|
|
size = in.size();
|
2006-04-14 04:22:49 +00:00
|
|
|
if (getFeatures() & GF_CRUNCHED) {
|
2006-04-20 00:42:54 +00:00
|
|
|
byte *srcBuffer = (byte *)malloc(size);
|
|
|
|
if (in.read(srcBuffer, size) != size)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("loadSimonVGAFile: Read failed");
|
2006-04-20 00:42:54 +00:00
|
|
|
decrunchFile(srcBuffer, _vgaBufferPointers[11].vgaFile2, size);
|
|
|
|
free(srcBuffer);
|
2006-04-14 04:22:49 +00:00
|
|
|
} else {
|
|
|
|
if (in.read(_vgaBufferPointers[11].vgaFile2, size) != size)
|
2006-08-27 05:02:48 +00:00
|
|
|
error("loadSimonVGAFile: Read failed");
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
} else {
|
2006-10-03 14:02:14 +00:00
|
|
|
offs = _gameOffsetsPtr[id];
|
2006-04-14 04:22:49 +00:00
|
|
|
|
2006-10-03 14:02:14 +00:00
|
|
|
size = _gameOffsetsPtr[id + 1] - offs;
|
2006-04-21 00:18:23 +00:00
|
|
|
readGameFile(_vgaBufferPointers[11].vgaFile2, offs, size);
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-19 11:13:28 +00:00
|
|
|
void AGOSEngine::loadVGAVideoFile(uint id, uint type) {
|
2006-04-14 04:22:49 +00:00
|
|
|
File in;
|
|
|
|
char filename[15];
|
2006-10-19 11:13:28 +00:00
|
|
|
byte *dst;
|
2006-10-03 14:02:14 +00:00
|
|
|
uint32 file, offs, srcSize, dstSize;
|
2006-04-20 00:42:54 +00:00
|
|
|
uint extraBuffer = 0;
|
|
|
|
|
|
|
|
if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
|
|
|
|
// !!! HACK !!!
|
|
|
|
// Allocate more space for text to cope with foreign languages that use
|
|
|
|
// up more space than english. I hope 6400 bytes are enough. This number
|
|
|
|
// is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki
|
|
|
|
extraBuffer = (id == 5 ? 6400 : 0);
|
|
|
|
}
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
if (getFeatures() & GF_ZLIBCOMP) {
|
2006-10-03 14:02:14 +00:00
|
|
|
loadOffsets(getFileName(GAME_GFXIDXFILE), id * 3 + type, file, offs, srcSize, dstSize);
|
2006-04-14 04:22:49 +00:00
|
|
|
|
|
|
|
if (getPlatform() == Common::kPlatformAmiga)
|
|
|
|
sprintf(filename, "GFX%d.VGA", file);
|
|
|
|
else
|
|
|
|
sprintf(filename, "graphics.vga");
|
|
|
|
|
2006-04-20 00:42:54 +00:00
|
|
|
dst = allocBlock(dstSize + extraBuffer);
|
|
|
|
decompressData(filename, dst, offs, srcSize, dstSize);
|
2006-04-14 04:22:49 +00:00
|
|
|
} else if (getFeatures() & GF_OLD_BUNDLE) {
|
2006-10-11 14:59:16 +00:00
|
|
|
if (getPlatform() == Common::kPlatformAmiga || getPlatform() == Common::kPlatformAtariST) {
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getFeatures() & GF_TALKIE) {
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "%.3d%d.out", id, type);
|
2006-10-15 05:59:22 +00:00
|
|
|
} else if (getGameType() == GType_ELVIRA1 && getFeatures() & GF_DEMO) {
|
|
|
|
if (id == 20)
|
|
|
|
sprintf(filename, "D%d.out", type);
|
|
|
|
else if (id == 26)
|
|
|
|
sprintf(filename, "J%d.out", type);
|
|
|
|
else if (id == 27)
|
|
|
|
sprintf(filename, "K%d.out", type);
|
|
|
|
else if (id == 33)
|
|
|
|
sprintf(filename, "Q%d.out", type);
|
|
|
|
else if (id == 34)
|
|
|
|
sprintf(filename, "R%d.out", type);
|
|
|
|
else
|
|
|
|
sprintf(filename, "%.1d%d.out", id, type);
|
2006-10-06 05:13:09 +00:00
|
|
|
} else if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2) {
|
2006-10-19 11:13:28 +00:00
|
|
|
sprintf(filename, "%.2d%d.pkd", id, type);
|
2006-10-06 05:13:09 +00:00
|
|
|
} else {
|
2006-10-19 11:13:28 +00:00
|
|
|
sprintf(filename, "%.3d%d.pkd", id, type);
|
2006-10-06 05:13:09 +00:00
|
|
|
}
|
2006-04-14 04:22:49 +00:00
|
|
|
} else {
|
2006-10-06 05:13:09 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) {
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "%.2d%d.VGA", id, type);
|
2006-09-19 11:59:13 +00:00
|
|
|
} else {
|
2006-10-03 14:02:14 +00:00
|
|
|
sprintf(filename, "%.3d%d.VGA", id, type);
|
2006-09-19 11:59:13 +00:00
|
|
|
}
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
in.open(filename);
|
2006-10-19 11:13:28 +00:00
|
|
|
if (in.isOpen() == false) {
|
|
|
|
error("loadVGAVideoFile: Can't load %s", filename);
|
2006-10-14 01:15:28 +00:00
|
|
|
}
|
2006-10-03 14:02:14 +00:00
|
|
|
|
2006-10-14 01:15:28 +00:00
|
|
|
dstSize = srcSize = in.size();
|
2006-10-19 11:13:28 +00:00
|
|
|
if (getFeatures() & GF_CRUNCHED) {
|
2006-10-14 01:15:28 +00:00
|
|
|
byte *srcBuffer = (byte *)malloc(srcSize);
|
|
|
|
if (in.read(srcBuffer, srcSize) != srcSize)
|
2006-10-19 11:13:28 +00:00
|
|
|
error("loadVGAVideoFile: Read failed");
|
2006-10-14 01:15:28 +00:00
|
|
|
|
|
|
|
dstSize = READ_BE_UINT32(srcBuffer + srcSize - 4);
|
2007-02-08 23:37:17 +00:00
|
|
|
dst = allocBlock (dstSize + extraBuffer);
|
|
|
|
decrunchFile(srcBuffer, dst, srcSize);
|
2006-10-14 01:15:28 +00:00
|
|
|
free(srcBuffer);
|
|
|
|
} else {
|
2007-02-08 23:37:17 +00:00
|
|
|
dst = allocBlock(dstSize + extraBuffer);
|
|
|
|
if (in.read(dst, dstSize) != dstSize)
|
|
|
|
error("loadVGAVideoFile: Read failed");
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
2006-10-14 01:15:28 +00:00
|
|
|
in.close();
|
2006-04-14 04:22:49 +00:00
|
|
|
} else {
|
2006-10-03 14:02:14 +00:00
|
|
|
id = id * 2 + (type - 1);
|
2006-04-20 00:42:54 +00:00
|
|
|
offs = _gameOffsetsPtr[id];
|
2006-04-14 04:22:49 +00:00
|
|
|
|
2006-04-20 00:42:54 +00:00
|
|
|
dstSize = _gameOffsetsPtr[id + 1] - offs;
|
|
|
|
dst = allocBlock(dstSize + extraBuffer);
|
2006-04-21 00:18:23 +00:00
|
|
|
readGameFile(dst, offs, dstSize);
|
2006-04-14 04:22:49 +00:00
|
|
|
}
|
2006-10-19 11:13:28 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|