2002-05-22 12:20:36 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2001-10-09 14:30:12 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2001-2005 The ScummVM project
|
2001-10-09 14:30:12 +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.
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2002-12-24 16:10:31 +00:00
|
|
|
#include "common/str.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
|
2005-05-13 10:23:56 +00:00
|
|
|
#include "scumm/charset.h"
|
2003-09-11 10:32:15 +00:00
|
|
|
#include "scumm/dialogs.h"
|
|
|
|
#include "scumm/imuse.h"
|
2004-01-06 17:28:29 +00:00
|
|
|
#include "scumm/imuse_digi/dimuse.h"
|
2005-04-09 20:22:31 +00:00
|
|
|
#include "scumm/intern.h"
|
2003-09-11 10:32:15 +00:00
|
|
|
#include "scumm/object.h"
|
|
|
|
#include "scumm/resource.h"
|
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/sound.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
#include "scumm/util.h"
|
2003-09-11 10:32:15 +00:00
|
|
|
#include "scumm/verbs.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
namespace Scumm {
|
|
|
|
|
2005-10-17 15:00:23 +00:00
|
|
|
enum {
|
|
|
|
RF_LOCK = 0x80,
|
|
|
|
RF_USAGE = 0x7F,
|
|
|
|
RF_USAGE_MAX = RF_USAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-03 22:10:10 +00:00
|
|
|
extern const char *resTypeFromId(int id);
|
|
|
|
|
2005-03-06 13:23:29 +00:00
|
|
|
static uint16 newTag2Old(uint32 newTag);
|
2005-03-31 23:11:39 +00:00
|
|
|
static const byte *findResourceSmall(uint32 tag, const byte *searchin);
|
2002-07-16 21:03:14 +00:00
|
|
|
|
2005-10-19 19:26:53 +00:00
|
|
|
static bool checkTryMedia(BaseScummFile *handle);
|
|
|
|
|
2004-07-26 17:14:57 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
/* Open a room */
|
2005-04-10 17:38:09 +00:00
|
|
|
void ScummEngine::openRoom(const int room) {
|
2005-04-04 00:12:41 +00:00
|
|
|
int room_offs;
|
2003-04-29 03:32:08 +00:00
|
|
|
bool result;
|
|
|
|
char buf[128];
|
|
|
|
char buf2[128] = "";
|
2003-07-28 16:55:06 +00:00
|
|
|
byte encByte = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_GENERAL, "openRoom(%d)", room);
|
2002-12-22 21:58:16 +00:00
|
|
|
assert(room >= 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
/* Don't load the same room again */
|
|
|
|
if (_lastLoadedRoom == room)
|
|
|
|
return;
|
|
|
|
_lastLoadedRoom = room;
|
|
|
|
|
|
|
|
/* Room -1 means close file */
|
2002-04-11 17:19:16 +00:00
|
|
|
if (room == -1) {
|
2001-10-09 14:30:12 +00:00
|
|
|
deleteRoomOffsets();
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->close();
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-10 17:38:09 +00:00
|
|
|
const int diskNumber = (room == 0 ? 0 : res.roomno[rtRoom][room]);
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
/* Either xxx.lfl or monkey.xxx file name */
|
2002-12-21 12:34:17 +00:00
|
|
|
while (1) {
|
2005-04-04 00:12:41 +00:00
|
|
|
room_offs = room ? res.roomoffs[rtRoom][room] : 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-21 12:34:17 +00:00
|
|
|
if (room_offs == -1)
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2005-02-14 03:12:41 +00:00
|
|
|
if (room_offs != 0 && room != 0 && _heversion < 98) {
|
2004-09-19 00:15:17 +00:00
|
|
|
_fileOffset = res.roomoffs[rtRoom][room];
|
2005-03-02 05:01:52 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2005-04-04 00:12:41 +00:00
|
|
|
if (_version <= 3) {
|
|
|
|
sprintf(buf, "%.2d.lfl", room);
|
|
|
|
// Maniac Mansion demo has .man instead of .lfl
|
|
|
|
if (_gameId == GID_MANIAC)
|
|
|
|
sprintf(buf2, "%.2d.man", room);
|
|
|
|
encByte = (_features & GF_USE_KEY) ? 0xFF : 0;
|
|
|
|
} else if (_features & GF_SMALL_HEADER) {
|
|
|
|
if (room == 0 || room >= 900) {
|
|
|
|
sprintf(buf, "%.3d.lfl", room);
|
|
|
|
encByte = 0;
|
|
|
|
if (openResourceFile(buf, encByte)) {
|
|
|
|
return;
|
|
|
|
}
|
2005-04-10 17:38:09 +00:00
|
|
|
askForDisk(buf, diskNumber);
|
2005-04-04 00:12:41 +00:00
|
|
|
|
|
|
|
} else {
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf, "disk%.2d.lec", diskNumber);
|
2005-04-04 00:12:41 +00:00
|
|
|
encByte = 0x69;
|
|
|
|
}
|
|
|
|
} else {
|
2002-06-27 10:40:37 +00:00
|
|
|
|
2004-06-06 02:20:53 +00:00
|
|
|
if (_heversion >= 70) { // Windows titles
|
2004-09-07 12:54:41 +00:00
|
|
|
if (_heversion >= 98) {
|
2005-02-14 03:12:41 +00:00
|
|
|
int disk = 0;
|
|
|
|
if (_heV7DiskOffsets)
|
|
|
|
disk = _heV7DiskOffsets[room];
|
|
|
|
|
|
|
|
switch(disk) {
|
|
|
|
case 2:
|
|
|
|
sprintf(buf, "%s.%s", _gameName.c_str(), "(b)");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sprintf(buf, "%s.%s", _gameName.c_str(), "(a)");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(buf, "%s.%s", _gameName.c_str(), "he0");
|
|
|
|
}
|
2004-09-07 12:54:41 +00:00
|
|
|
} else
|
2004-08-26 14:35:38 +00:00
|
|
|
sprintf(buf, "%s.he%.1d", _gameName.c_str(), room == 0 ? 0 : 1);
|
2003-08-29 02:39:05 +00:00
|
|
|
} else if (_version >= 7) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (room > 0 && (_version == 8))
|
2005-04-16 12:42:09 +00:00
|
|
|
VAR(VAR_CURRENTDISK) = diskNumber;
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf, "%s.la%d", _gameName.c_str(), diskNumber);
|
2003-11-13 10:51:02 +00:00
|
|
|
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf2, "%s.%.3d", _gameName.c_str(), diskNumber);
|
2005-04-20 01:33:44 +00:00
|
|
|
} else if (_heversion >= 60) {
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf, "%s.he%.1d", _gameName.c_str(), diskNumber);
|
2005-04-04 00:12:41 +00:00
|
|
|
} else {
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf, "%s.%.3d", _gameName.c_str(), diskNumber);
|
2003-04-29 03:32:08 +00:00
|
|
|
if (_gameId == GID_SAMNMAX)
|
2005-04-10 17:38:09 +00:00
|
|
|
sprintf(buf2, "%s.sm%.1d", _gameName.c_str(), diskNumber);
|
2003-04-29 03:32:08 +00:00
|
|
|
}
|
2002-06-27 10:40:37 +00:00
|
|
|
|
2003-07-28 16:55:06 +00:00
|
|
|
encByte = (_features & GF_USE_KEY) ? 0x69 : 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 17:58:47 +00:00
|
|
|
// If we have substitute
|
2005-06-19 18:16:27 +00:00
|
|
|
if (_substResFileNameIndex > 0 && !(_platform == Common::kPlatformNES || _platform == Common::kPlatformC64)) {
|
2005-01-29 17:58:47 +00:00
|
|
|
char tmpBuf[128];
|
|
|
|
|
2005-04-09 11:59:43 +00:00
|
|
|
generateSubstResFileName(buf, tmpBuf, sizeof(tmpBuf));
|
2005-01-29 17:58:47 +00:00
|
|
|
strcpy(buf, tmpBuf);
|
2005-04-09 11:59:43 +00:00
|
|
|
generateSubstResFileName(buf2, tmpBuf, sizeof(tmpBuf));
|
2005-01-29 17:58:47 +00:00
|
|
|
strcpy(buf2, tmpBuf);
|
|
|
|
}
|
|
|
|
|
2003-07-28 16:55:06 +00:00
|
|
|
result = openResourceFile(buf, encByte);
|
2004-02-29 00:18:45 +00:00
|
|
|
if ((result == false) && (buf2[0])) {
|
2003-07-28 16:55:06 +00:00
|
|
|
result = openResourceFile(buf2, encByte);
|
2004-02-29 00:18:45 +00:00
|
|
|
// We have .man files so set demo mode
|
|
|
|
if (_gameId == GID_MANIAC)
|
|
|
|
_demoMode = true;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-04-29 03:32:08 +00:00
|
|
|
if (result) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (room == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2005-04-03 22:56:02 +00:00
|
|
|
deleteRoomOffsets();
|
2001-10-09 14:30:12 +00:00
|
|
|
readRoomsOffsets();
|
2004-09-19 00:15:17 +00:00
|
|
|
_fileOffset = res.roomoffs[rtRoom][room];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (_fileOffset != 8)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error("Room %d not in %s", room, buf);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-10 17:38:09 +00:00
|
|
|
askForDisk(buf, diskNumber);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
sprintf(buf, "%.3d.lfl", room);
|
2003-07-28 16:55:06 +00:00
|
|
|
encByte = 0;
|
|
|
|
if (openResourceFile(buf, encByte))
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
2005-04-10 17:38:09 +00:00
|
|
|
askForDisk(buf, diskNumber);
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (1);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
deleteRoomOffsets();
|
2002-12-22 21:58:16 +00:00
|
|
|
_fileOffset = 0; // start of file
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::closeRoom() {
|
2002-12-22 21:58:16 +00:00
|
|
|
if (_lastLoadedRoom != -1) {
|
|
|
|
_lastLoadedRoom = -1;
|
|
|
|
deleteRoomOffsets();
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->close();
|
2002-12-22 21:58:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/** Delete the currently loaded room offsets. */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::deleteRoomOffsets() {
|
2003-12-26 23:11:35 +00:00
|
|
|
for (int i = 0; i < _numRooms; i++) {
|
2004-09-19 00:15:17 +00:00
|
|
|
if (res.roomoffs[rtRoom][i] != 0xFFFFFFFF)
|
|
|
|
res.roomoffs[rtRoom][i] = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/** Read room offsets */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::readRoomsOffsets() {
|
2005-04-03 22:56:02 +00:00
|
|
|
int num, room;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
debug(9, "readRoomOffsets()");
|
|
|
|
|
2005-04-10 00:33:31 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(12, SEEK_SET); // Directly searching for the room offset block would be more generic...
|
2005-04-10 00:33:31 +00:00
|
|
|
} else {
|
|
|
|
_fileHandle->seek(16, SEEK_SET);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
num = _fileHandle->readByte();
|
2002-12-24 02:18:02 +00:00
|
|
|
while (num--) {
|
2005-03-30 21:59:12 +00:00
|
|
|
room = _fileHandle->readByte();
|
2004-09-19 00:15:17 +00:00
|
|
|
if (res.roomoffs[rtRoom][room] != 0xFFFFFFFF) {
|
2005-03-30 21:59:12 +00:00
|
|
|
res.roomoffs[rtRoom][room] = _fileHandle->readUint32LE();
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->readUint32LE();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
bool ScummEngine::openFile(BaseScummFile &file, const char *filename, bool resourceFile) {
|
2004-07-26 17:14:57 +00:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if (!_containerFile.isEmpty()) {
|
2005-09-17 00:24:51 +00:00
|
|
|
char name[128];
|
|
|
|
|
2004-07-26 23:15:01 +00:00
|
|
|
file.close();
|
|
|
|
file.open(_containerFile.c_str());
|
|
|
|
assert(file.isOpen());
|
2005-06-19 18:16:27 +00:00
|
|
|
|
2005-09-17 00:24:51 +00:00
|
|
|
strncpy(name, filename, 128);
|
|
|
|
|
|
|
|
// Some Mac demos (i.e. DOTT) have bundled file names different
|
|
|
|
// from target name. dottdemo.000 vs tentacle.000. So we should
|
|
|
|
// substitute those names too
|
2005-11-19 03:37:34 +00:00
|
|
|
if (resourceFile == true) {
|
|
|
|
if (_substResFileNameIndexBundle == 0) {
|
|
|
|
int substLastIndex = 0;
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
while (substLastIndex != -1) {
|
|
|
|
if (file.openSubFile(name))
|
|
|
|
break;
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
substLastIndex = generateSubstResFileName(filename, name, sizeof(name), substLastIndex + 1);
|
|
|
|
}
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
if (substLastIndex == 0)
|
|
|
|
substLastIndex = -1;
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
_substResFileNameIndexBundle = substLastIndex;
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
if (substLastIndex != -1)
|
|
|
|
debug(5, "Generated substitute in Mac bundle: [%s -> %s]", filename, name);
|
|
|
|
}
|
2005-09-17 00:24:51 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
if (_substResFileNameIndexBundle != -1)
|
|
|
|
generateSubstResFileName(filename, name, sizeof(name), _substResFileNameIndexBundle);
|
|
|
|
}
|
2005-09-17 00:24:51 +00:00
|
|
|
|
|
|
|
result = file.openSubFile(name);
|
2004-07-26 17:14:57 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-07-26 17:14:57 +00:00
|
|
|
if (!result) {
|
2004-07-26 23:15:01 +00:00
|
|
|
file.close();
|
|
|
|
result = file.open(filename);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-07-26 17:14:57 +00:00
|
|
|
return result;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-07-26 23:15:01 +00:00
|
|
|
bool ScummEngine::openResourceFile(const char *filename, byte encByte) {
|
|
|
|
debugC(DEBUG_GENERAL, "openResourceFile(%s)", filename);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-11-19 03:37:34 +00:00
|
|
|
if (openFile(*_fileHandle, filename, true)) {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->setEnc(encByte);
|
2004-07-26 23:15:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::askForDisk(const char *filename, int disknum) {
|
2003-01-02 10:36:17 +00:00
|
|
|
char buf[128];
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2005-05-14 23:28:22 +00:00
|
|
|
#ifndef DISABLE_SCUMM_7_8
|
2003-01-02 10:36:17 +00:00
|
|
|
char result;
|
|
|
|
|
2004-04-26 07:47:12 +00:00
|
|
|
_imuseDigital->stopAllSounds();
|
2003-04-20 00:56:23 +00:00
|
|
|
|
2003-05-24 22:17:45 +00:00
|
|
|
#ifdef MACOSX
|
2004-02-05 22:39:13 +00:00
|
|
|
sprintf(buf, "Cannot find file: '%s'\nPlease insert disc %d.\nPress OK to retry, Quit to exit", filename, disknum);
|
2003-05-24 22:17:45 +00:00
|
|
|
#else
|
2004-06-28 00:00:33 +00:00
|
|
|
sprintf(buf, "Cannot find file: '%s'\nInsert disc %d into drive %s\nPress OK to retry, Quit to exit", filename, disknum, _gameDataPath.c_str());
|
2003-05-24 22:17:45 +00:00
|
|
|
#endif
|
2003-01-02 10:36:17 +00:00
|
|
|
|
2004-03-28 13:28:44 +00:00
|
|
|
result = displayMessage("Quit", buf);
|
2004-08-11 21:49:58 +00:00
|
|
|
if (!result) {
|
2004-04-08 11:48:35 +00:00
|
|
|
error("Cannot find file: '%s'", filename);
|
2004-04-04 12:36:50 +00:00
|
|
|
}
|
2005-05-14 23:28:22 +00:00
|
|
|
#endif
|
2005-07-30 21:11:48 +00:00
|
|
|
} else {
|
2003-01-02 10:36:17 +00:00
|
|
|
sprintf(buf, "Cannot find file: '%s'", filename);
|
2003-11-02 02:18:16 +00:00
|
|
|
InfoDialog dialog(this, (char*)buf);
|
2003-09-11 10:32:15 +00:00
|
|
|
runDialog(dialog);
|
2004-04-08 11:48:35 +00:00
|
|
|
error("Cannot find file: '%s'", filename);
|
2003-01-02 10:36:17 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::readIndexFile() {
|
2002-04-11 17:19:16 +00:00
|
|
|
uint32 blocktype, itemsize;
|
2001-10-09 14:30:12 +00:00
|
|
|
int numblock = 0;
|
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_GENERAL, "readIndexFile()");
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-22 21:58:16 +00:00
|
|
|
closeRoom();
|
2001-10-09 14:30:12 +00:00
|
|
|
openRoom(0);
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 5) {
|
2005-04-10 00:33:31 +00:00
|
|
|
// Figure out the sizes of various resources
|
2005-03-30 21:59:12 +00:00
|
|
|
while (!_fileHandle->eof()) {
|
2001-11-26 19:57:57 +00:00
|
|
|
blocktype = fileReadDword();
|
2005-03-30 21:59:12 +00:00
|
|
|
itemsize = _fileHandle->readUint32BE();
|
|
|
|
if (_fileHandle->ioFailed())
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (blocktype) {
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DOBJ'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_numGlobalObjects = _fileHandle->readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
|
|
|
case MKID('DROO'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_numRooms = _fileHandle->readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DSCR'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_numScripts = _fileHandle->readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DCOS'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_numCostumes = _fileHandle->readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DSOU'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_numSounds = _fileHandle->readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(itemsize - 8, SEEK_CUR);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->clearIOFailed();
|
|
|
|
_fileHandle->seek(0, SEEK_SET);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 19:26:53 +00:00
|
|
|
#ifndef DISABLE_HE
|
|
|
|
if (checkTryMedia(_fileHandle)) {
|
|
|
|
displayMessage(NULL, "You're trying to run game encrypted by ActiveMark. This is not supported.");
|
|
|
|
_quit = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 22:59:43 +00:00
|
|
|
while (true) {
|
2001-10-16 10:01:48 +00:00
|
|
|
blocktype = fileReadDword();
|
2005-04-17 22:59:43 +00:00
|
|
|
itemsize = _fileHandle->readUint32BE();
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
if (_fileHandle->ioFailed())
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
numblock++;
|
2005-04-17 22:59:43 +00:00
|
|
|
readIndexBlock(blocktype, itemsize);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
// if (numblock!=9)
|
|
|
|
// error("Not enough blocks read from directory");
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-12-22 21:58:16 +00:00
|
|
|
closeRoom();
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 19:26:53 +00:00
|
|
|
|
|
|
|
#ifndef DISABLE_HE
|
|
|
|
|
|
|
|
#define TRYMEDIA_MARK_LEN 6
|
|
|
|
|
|
|
|
bool checkTryMedia(BaseScummFile *handle) {
|
|
|
|
byte buf[TRYMEDIA_MARK_LEN];
|
2005-10-21 15:26:57 +00:00
|
|
|
bool matched = true;
|
2005-10-19 19:26:53 +00:00
|
|
|
const byte magic[2][TRYMEDIA_MARK_LEN] =
|
|
|
|
{{ 0x00, 'T', 'M', 'S', 'A', 'M' },
|
|
|
|
{ 'i', '=', '$', ':', '(', '$' }}; // Same but 0x69 xored
|
|
|
|
|
|
|
|
handle->read(buf, TRYMEDIA_MARK_LEN);
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
matched = true;
|
|
|
|
for (int j = 0; j < TRYMEDIA_MARK_LEN; j++)
|
2005-10-21 15:26:57 +00:00
|
|
|
if (buf[j] != magic[i][j]) {
|
2005-10-19 19:26:53 +00:00
|
|
|
matched = false;
|
2005-10-21 15:26:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-10-19 19:26:53 +00:00
|
|
|
|
|
|
|
if (matched)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matched)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
handle->seek(0, SEEK_SET);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-05-14 22:56:41 +00:00
|
|
|
#ifndef DISABLE_SCUMM_7_8
|
2005-04-20 23:33:35 +00:00
|
|
|
void ScummEngine_v7::readIndexBlock(uint32 blocktype, uint32 itemsize) {
|
|
|
|
int num;
|
|
|
|
char *ptr;
|
|
|
|
switch (blocktype) {
|
|
|
|
case MKID('ANAM'): // Used by: The Dig, FT
|
|
|
|
debug(9, "found ANAM block, reading audio names");
|
|
|
|
num = _fileHandle->readUint16LE();
|
|
|
|
ptr = (char*)malloc(num * 9);
|
|
|
|
_fileHandle->read(ptr, num * 9);
|
|
|
|
_imuseDigital->setAudioNames(num, ptr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ScummEngine::readIndexBlock(blocktype, itemsize);
|
|
|
|
}
|
|
|
|
}
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2005-04-20 23:33:35 +00:00
|
|
|
|
2005-05-14 14:06:37 +00:00
|
|
|
#ifndef DISABLE_HE
|
2005-04-17 22:59:43 +00:00
|
|
|
void ScummEngine_v70he::readIndexBlock(uint32 blocktype, uint32 itemsize) {
|
|
|
|
int i;
|
|
|
|
switch (blocktype) {
|
|
|
|
case MKID('DLFL'):
|
|
|
|
i = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->seek(-2, SEEK_CUR);
|
|
|
|
_heV7RoomOffsets = (byte *)calloc(2 + (i * 4), 1);
|
|
|
|
_fileHandle->read(_heV7RoomOffsets, (2 + (i * 4)) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DISK'):
|
|
|
|
i = _fileHandle->readUint16LE();
|
|
|
|
_heV7DiskOffsets = (byte *)calloc(i, 1);
|
|
|
|
_fileHandle->read(_heV7DiskOffsets, i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ScummEngine::readIndexBlock(blocktype, itemsize);
|
|
|
|
}
|
|
|
|
}
|
2005-05-14 14:06:37 +00:00
|
|
|
#endif
|
2005-04-17 22:59:43 +00:00
|
|
|
|
|
|
|
void ScummEngine::readIndexBlock(uint32 blocktype, uint32 itemsize) {
|
|
|
|
int i;
|
|
|
|
switch (blocktype) {
|
|
|
|
case MKID('DCHR'):
|
|
|
|
case MKID('DIRF'):
|
|
|
|
readResTypeList(rtCharset, MKID('CHAR'), "charset");
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-17 22:59:43 +00:00
|
|
|
case MKID('DOBJ'):
|
|
|
|
debug(9, "found DOBJ block, reading object table");
|
|
|
|
readGlobalObjects();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('RNAM'):
|
|
|
|
// Names of rooms. Maybe we should put them into a table, for use by the debugger?
|
|
|
|
if (_heversion >= 80) {
|
|
|
|
for (int room; (room = _fileHandle->readUint16LE()); ) {
|
2005-10-22 10:48:14 +00:00
|
|
|
char buf[100];
|
2005-04-17 22:59:43 +00:00
|
|
|
i = 0;
|
2005-10-22 10:48:14 +00:00
|
|
|
for (byte s; (s = _fileHandle->readByte()) && i < ARRAYSIZE(buf) - 1; ) {
|
2005-04-17 22:59:43 +00:00
|
|
|
buf[i++] = s;
|
|
|
|
}
|
|
|
|
buf[i] = 0;
|
|
|
|
debug(5, "Room %d: '%s'", room, buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int room; (room = _fileHandle->readByte()); ) {
|
|
|
|
char buf[10];
|
|
|
|
_fileHandle->read(buf, 9);
|
|
|
|
buf[9] = 0;
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
buf[i] ^= 0xFF;
|
|
|
|
debug(5, "Room %d: '%s'", room, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-17 22:59:43 +00:00
|
|
|
case MKID('DIRM'):
|
|
|
|
readResTypeList(rtImage, MKID('AWIZ'), "images");
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-17 22:59:43 +00:00
|
|
|
case MKID('DIRT'):
|
|
|
|
readResTypeList(rtTalkie, MKID('TLKE'), "talkie");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('SVER'):
|
|
|
|
_fileHandle->seek(itemsize - 8, SEEK_CUR);
|
2005-08-14 01:41:52 +00:00
|
|
|
debug(0, "SVER index block not yet handled, skipping");
|
2005-04-17 22:59:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('INIB'):
|
|
|
|
_fileHandle->seek(itemsize - 8, SEEK_CUR);
|
|
|
|
debug(2, "INIB index block not yet handled, skipping");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DIRI'):
|
|
|
|
readResTypeList(rtRoomImage, MKID('RMIM'), "room image");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DIRR'):
|
|
|
|
case MKID('DROO'):
|
|
|
|
readResTypeList(rtRoom, MKID('ROOM'), "room");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DRSC'):
|
|
|
|
readResTypeList(rtRoomScripts, MKID('RMSC'), "room script");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DSCR'):
|
|
|
|
case MKID('DIRS'):
|
|
|
|
readResTypeList(rtScript, MKID('SCRP'), "script");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DCOS'):
|
|
|
|
case MKID('DIRC'):
|
|
|
|
readResTypeList(rtCostume, MKID('COST'), "costume");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('MAXS'):
|
|
|
|
readMAXS(itemsize);
|
|
|
|
allocateArrays();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DIRN'):
|
|
|
|
case MKID('DSOU'):
|
|
|
|
readResTypeList(rtSound, MKID('SOUN'), "sound");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('AARY'):
|
|
|
|
readArrayFromIndexFile();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('LECF'):
|
|
|
|
_fileHandle->seek(itemsize - 8, SEEK_CUR);
|
|
|
|
debug(2, "LECF index block not yet handled, skipping");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error("Bad ID %04X('%s') found in index file directory!", blocktype,
|
|
|
|
tag2str(blocktype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::readArrayFromIndexFile() {
|
2004-01-19 20:27:31 +00:00
|
|
|
error("readArrayFromIndexFile() not supported in pre-V6 games");
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::readResTypeList(int id, uint32 tag, const char *name) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int num;
|
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-06-05 15:14:19 +00:00
|
|
|
debug(9, "readResTypeList(%s,%s,%s)", resTypeFromId(id), tag2str(TO_BE_32(tag)), name);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2005-03-30 21:59:12 +00:00
|
|
|
num = _fileHandle->readUint32LE();
|
2002-08-29 16:57:43 +00:00
|
|
|
else
|
2005-04-03 22:10:10 +00:00
|
|
|
num = _fileHandle->readUint16LE();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-04-03 22:10:10 +00:00
|
|
|
if (num != res.num[id]) {
|
|
|
|
error("Invalid number of %ss (%d) in directory", name, num);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2005-04-03 22:10:10 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2005-03-30 21:59:12 +00:00
|
|
|
res.roomno[id][i] = _fileHandle->readByte();
|
|
|
|
res.roomoffs[id][i] = _fileHandle->readUint32LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-05-01 22:19:10 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2005-03-30 21:59:12 +00:00
|
|
|
res.roomno[id][i] = _fileHandle->readByte();
|
2003-05-01 22:19:10 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < num; i++) {
|
2005-03-30 21:59:12 +00:00
|
|
|
res.roomoffs[id][i] = _fileHandle->readUint32LE();
|
2004-09-18 23:48:48 +00:00
|
|
|
|
|
|
|
if (id == rtRoom && _heversion >= 70)
|
|
|
|
_heV7RoomIntOffsets[i] = res.roomoffs[id][i];
|
2003-05-01 22:19:10 +00:00
|
|
|
}
|
2004-06-06 02:20:53 +00:00
|
|
|
|
2004-06-06 02:36:44 +00:00
|
|
|
if (_heversion >= 70) {
|
2004-06-07 00:26:08 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2005-03-30 21:59:12 +00:00
|
|
|
res.globsize[id][i] = _fileHandle->readUint32LE();
|
2004-06-07 00:26:08 +00:00
|
|
|
}
|
2004-06-06 02:36:44 +00:00
|
|
|
}
|
2002-11-28 23:47:58 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) {
|
2004-06-05 15:14:19 +00:00
|
|
|
debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name, tag2str(TO_BE_32(tag)), num, mode);
|
2003-05-18 21:03:57 +00:00
|
|
|
assert(id >= 0 && id < (int)(ARRAYSIZE(res.mode)));
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2004-09-02 03:54:29 +00:00
|
|
|
if (num >= 8000)
|
|
|
|
error("Too many %ss (%d) in directory", name, num);
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
res.mode[id] = mode;
|
|
|
|
res.num[id] = num;
|
|
|
|
res.tags[id] = tag;
|
|
|
|
res.name[id] = name;
|
2002-05-01 17:16:47 +00:00
|
|
|
res.address[id] = (byte **)calloc(num, sizeof(void *));
|
|
|
|
res.flags[id] = (byte *)calloc(num, sizeof(byte));
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (mode) {
|
2002-05-01 17:16:47 +00:00
|
|
|
res.roomno[id] = (byte *)calloc(num, sizeof(byte));
|
|
|
|
res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32));
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2004-06-07 00:26:08 +00:00
|
|
|
|
2004-06-22 13:52:39 +00:00
|
|
|
if (_heversion >= 70) {
|
2004-06-07 00:26:08 +00:00
|
|
|
res.globsize[id] = (uint32 *)calloc(num, sizeof(uint32));
|
2004-09-18 23:48:48 +00:00
|
|
|
|
|
|
|
if (id == rtRoom)
|
|
|
|
_heV7RoomIntOffsets = (uint32 *)calloc(num, sizeof(uint32));
|
2004-06-22 13:52:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::loadCharset(int no) {
|
2002-04-13 04:39:04 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_GENERAL, "loadCharset(%d)", no);
|
2002-03-31 09:06:51 +00:00
|
|
|
|
2002-05-11 20:00:32 +00:00
|
|
|
/* FIXME - hack around crash in Indy4 (occurs if you try to load after dieing) */
|
|
|
|
if (_gameId == GID_INDY4 && no == 0)
|
|
|
|
no = 1;
|
2002-04-11 15:22:02 +00:00
|
|
|
|
2004-06-26 05:08:02 +00:00
|
|
|
/* for Humongous catalogs */
|
|
|
|
if (_heversion >= 70 && _numCharsets == 1) {
|
2005-08-14 01:41:52 +00:00
|
|
|
debug(0, "Not loading charset as it doesn't seem to exist?");
|
2004-06-26 05:08:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
assert(no < (int)sizeof(_charsetData) / 16);
|
2003-12-26 23:11:35 +00:00
|
|
|
checkRange(_numCharsets - 1, 1, no, "Loading illegal charset %d");
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
ptr = getResourceAddress(rtCharset, no);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
|
|
|
_charsetData[no][i + 1] = ptr[i + 14];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::nukeCharset(int i) {
|
2003-12-26 23:11:35 +00:00
|
|
|
checkRange(_numCharsets - 1, 1, i, "Nuking illegal charset %d");
|
2005-03-31 21:39:31 +00:00
|
|
|
res.nukeResource(rtCharset, i);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::ensureResourceLoaded(int type, int i) {
|
2003-04-30 13:23:31 +00:00
|
|
|
void *addr = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-03-02 11:57:11 +00:00
|
|
|
if ((type == rtRoom) && i > 0x7F && _version < 7 && _heversion <= 71) {
|
2002-11-23 13:53:46 +00:00
|
|
|
i = _resourceMapper[i & 0x7F];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 11:03:41 +00:00
|
|
|
// FIXME - TODO: This check used to be "i==0". However, that causes
|
|
|
|
// problems when using this function to ensure charset 0 is loaded.
|
2003-05-01 14:35:21 +00:00
|
|
|
// This is done for many games, e.g. Zak256 or Indy3 (EGA and VGA).
|
|
|
|
// For now we restrict the check to anything which is not a charset.
|
2003-05-01 11:40:21 +00:00
|
|
|
// Question: Why was this check like that in the first place?
|
2003-05-01 14:35:21 +00:00
|
|
|
// Answer: costumes with an index of zero in the newer games at least.
|
|
|
|
// TODO: determine why the heck anything would try to load a costume
|
|
|
|
// with id 0. Is that "normal", or is it caused by yet another bug in
|
|
|
|
// our code base? After all we also have to add special cases for many
|
2005-07-30 21:11:48 +00:00
|
|
|
// of our script opcodes that check for the (invalid) actor 0... so
|
2003-05-01 14:35:21 +00:00
|
|
|
// maybe both issues are related...
|
|
|
|
if (type != rtCharset && i == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
if (i <= res.num[type])
|
|
|
|
addr = res.address[type][i];
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (addr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
loadResource(type, i);
|
|
|
|
|
2004-08-14 03:16:32 +00:00
|
|
|
if (_version == 5 && type == rtRoom && i == _roomResource)
|
2005-03-02 11:57:11 +00:00
|
|
|
VAR(VAR_ROOM_FLAG) = 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::loadResource(int type, int idx) {
|
2002-11-28 23:47:58 +00:00
|
|
|
int roomNr;
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 fileOffs;
|
|
|
|
uint32 size, tag;
|
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "loadResource(%s,%d)", resTypeFromId(type),idx);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (type == rtCharset && (_features & GF_SMALL_HEADER)) {
|
|
|
|
loadCharset(idx);
|
|
|
|
return (1);
|
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
roomNr = getResourceRoomNr(type, idx);
|
2002-05-08 06:57:27 +00:00
|
|
|
|
|
|
|
if (idx >= res.num[type])
|
|
|
|
error("%s %d undefined %d %d", res.name[type], idx, res.num[type], roomNr);
|
|
|
|
|
|
|
|
if (roomNr == 0)
|
|
|
|
roomNr = _roomResource;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-06-22 13:52:39 +00:00
|
|
|
if (type == rtRoom) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-24 02:18:02 +00:00
|
|
|
fileOffs = 8;
|
2004-06-24 05:55:04 +00:00
|
|
|
else if (_heversion >= 70)
|
2004-09-18 23:48:48 +00:00
|
|
|
fileOffs = _heV7RoomIntOffsets[idx];
|
2002-12-24 02:18:02 +00:00
|
|
|
else
|
|
|
|
fileOffs = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-03-08 08:42:11 +00:00
|
|
|
fileOffs = res.roomoffs[type][idx];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (fileOffs == 0xFFFFFFFF)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
openRoom(roomNr);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(fileOffs + _fileOffset, SEEK_SET);
|
2002-08-29 20:01:27 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
2005-04-20 18:21:30 +00:00
|
|
|
if ((_version == 3) && !(_platform == Common::kPlatformAmiga) && (type == rtSound)) {
|
2003-08-12 16:09:41 +00:00
|
|
|
return readSoundResourceSmallHeader(type, idx);
|
|
|
|
} else {
|
2005-03-30 21:59:12 +00:00
|
|
|
size = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->seek(-2, SEEK_CUR);
|
2003-08-12 16:09:41 +00:00
|
|
|
}
|
2002-11-28 23:47:58 +00:00
|
|
|
} else if (_features & GF_SMALL_HEADER) {
|
2005-04-04 00:12:41 +00:00
|
|
|
if (_version == 4)
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(8, SEEK_CUR);
|
|
|
|
size = _fileHandle->readUint32LE();
|
|
|
|
tag = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->seek(-6, SEEK_CUR);
|
2005-04-20 18:21:30 +00:00
|
|
|
if ((type == rtSound) && !(_platform == Common::kPlatformAmiga) && !(_platform == Common::kPlatformFMTowns)) {
|
2002-11-28 23:47:58 +00:00
|
|
|
return readSoundResourceSmallHeader(type, idx);
|
2003-05-03 12:48:18 +00:00
|
|
|
}
|
2002-11-28 23:47:58 +00:00
|
|
|
} else {
|
|
|
|
if (type == rtSound) {
|
|
|
|
return readSoundResource(type, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
tag = fileReadDword();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-06-22 13:52:39 +00:00
|
|
|
if (tag != res.tags[type] && _heversion < 70) {
|
2002-12-24 02:03:35 +00:00
|
|
|
error("%s %d not in room %d at %d+%d in file %s",
|
|
|
|
res.name[type], idx, roomNr,
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileOffset, fileOffs, _fileHandle->name());
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
size = _fileHandle->readUint32BE();
|
|
|
|
_fileHandle->seek(-8, SEEK_CUR);
|
2002-11-28 23:47:58 +00:00
|
|
|
}
|
2005-04-06 17:31:35 +00:00
|
|
|
_fileHandle->read(res.createResource(type, idx, size), size);
|
2002-11-28 23:47:58 +00:00
|
|
|
|
2002-12-31 02:09:57 +00:00
|
|
|
// dump the resource if requested
|
|
|
|
if (_dumpScripts && type == rtScript) {
|
2002-11-28 23:47:58 +00:00
|
|
|
dumpResource("script-", idx, getResourceAddress(rtScript, idx));
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
if (!_fileHandle->ioFailed()) {
|
2002-11-28 23:47:58 +00:00
|
|
|
return 1;
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
res.nukeResource(type, idx);
|
2002-11-28 23:47:58 +00:00
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
error("Cannot read resource");
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getResourceRoomNr(int type, int idx) {
|
2004-06-21 10:06:52 +00:00
|
|
|
if (type == rtRoom && _heversion < 70)
|
2002-03-08 08:42:11 +00:00
|
|
|
return idx;
|
|
|
|
return res.roomno[type][idx];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getResourceSize(int type, int idx) {
|
2003-07-21 21:28:47 +00:00
|
|
|
byte *ptr = getResourceAddress(type, idx);
|
|
|
|
MemBlkHeader *hdr = (MemBlkHeader *)(ptr - sizeof(MemBlkHeader));
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-07-21 21:28:47 +00:00
|
|
|
return hdr->size;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
byte *ScummEngine::getResourceAddress(int type, int idx) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
2005-10-14 12:36:46 +00:00
|
|
|
|
|
|
|
if (_heversion >= 80 && type == rtString)
|
|
|
|
idx &= ~0x33539000;
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
if (!res.validateResource("getResourceAddress", type, idx))
|
2002-09-25 03:04:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if (!res.address[type]) {
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), res.address[type] == NULL", resTypeFromId(type), idx);
|
2002-03-16 18:03:28 +00:00
|
|
|
return NULL;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2002-03-16 18:03:28 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
if (res.mode[type] && !res.address[type][idx]) {
|
|
|
|
ensureResourceLoaded(type, idx);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if (!(ptr = (byte *)res.address[type][idx])) {
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
return NULL;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
res.setResourceCounter(type, idx, 1);
|
2001-11-14 18:40:39 +00:00
|
|
|
|
2004-04-04 23:29:10 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
|
2001-12-11 13:34:15 +00:00
|
|
|
return ptr + sizeof(MemBlkHeader);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
byte *ScummEngine::getStringAddress(int i) {
|
2005-04-09 20:22:31 +00:00
|
|
|
byte *addr = getResourceAddress(rtString, i);
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *ScummEngine_v6::getStringAddress(int i) {
|
2004-11-27 13:10:41 +00:00
|
|
|
byte *addr = getResourceAddress(rtString, i);
|
|
|
|
if (addr == NULL)
|
2003-01-26 06:17:25 +00:00
|
|
|
return NULL;
|
2005-04-09 20:22:31 +00:00
|
|
|
return ((ScummEngine_v6::ArrayHeader *)addr)->data;
|
2001-10-24 20:12:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
byte *ScummEngine::getStringAddressVar(int i) {
|
2004-11-27 13:10:41 +00:00
|
|
|
return getStringAddress(_scummVars[i]);
|
2002-04-21 19:38:00 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
void ResourceManager::increaseResourceCounter() {
|
|
|
|
int i, j;
|
|
|
|
byte counter;
|
|
|
|
|
|
|
|
for (i = rtFirst; i <= rtLast; i++) {
|
|
|
|
for (j = num[i]; --j >= 0;) {
|
|
|
|
counter = flags[i][j] & RF_USAGE;
|
|
|
|
if (counter && counter < RF_USAGE_MAX) {
|
|
|
|
setResourceCounter(i, j, counter + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
|
|
|
|
flags[type][idx] &= ~RF_USAGE;
|
|
|
|
flags[type][idx] |= flag;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
|
|
|
|
#define SAFETY_AREA 2
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
byte *ResourceManager::createResource(int type, int idx, uint32 size) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
2005-04-06 17:31:35 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "res.createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
if (!validateResource("allocating", type, idx))
|
2002-09-25 03:04:28 +00:00
|
|
|
return NULL;
|
2005-08-14 20:46:02 +00:00
|
|
|
|
|
|
|
if (_vm->_version <= 2) {
|
|
|
|
// Nuking and reloading a resource can be harmful in some
|
|
|
|
// cases. For instance, Zak tries to reload the intro music
|
|
|
|
// while it's playing. See bug #1253171.
|
|
|
|
|
|
|
|
if (address[type][idx] && (type == rtSound || type == rtScript || type == rtCostume))
|
|
|
|
return address[type][idx] + sizeof(MemBlkHeader);
|
|
|
|
}
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
nukeResource(type, idx);
|
2001-10-10 10:02:33 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
expireResources(size);
|
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
ptr = (byte *)calloc(size + sizeof(MemBlkHeader) + SAFETY_AREA, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL) {
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Out of memory while allocating %d", size);
|
|
|
|
}
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
_allocatedSize += size;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
address[type][idx] = ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
((MemBlkHeader *)ptr)->size = size;
|
2005-04-06 17:31:35 +00:00
|
|
|
setResourceCounter(type, idx, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
return ptr + sizeof(MemBlkHeader); /* skip header */
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
ResourceManager::ResourceManager(ScummEngine *vm) {
|
|
|
|
memset(this, 0, sizeof(ResourceManager));
|
|
|
|
_vm = vm;
|
|
|
|
// _allocatedSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResourceManager::validateResource(const char *str, int type, int idx) const {
|
|
|
|
if (type < rtFirst || type > rtLast || (uint) idx >= (uint)num[type]) {
|
2005-08-14 01:41:52 +00:00
|
|
|
error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
|
2002-09-25 03:04:28 +00:00
|
|
|
return false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-09-25 03:04:28 +00:00
|
|
|
return true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
void ResourceManager::nukeResource(int type, int idx) {
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
2005-03-31 21:39:31 +00:00
|
|
|
if (!address[type])
|
2002-08-29 20:01:27 +00:00
|
|
|
return;
|
2002-03-14 13:57:28 +00:00
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
assert(idx >= 0 && idx < num[type]);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-10-17 15:00:23 +00:00
|
|
|
ptr = address[type][idx];
|
|
|
|
if (ptr != NULL) {
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
|
2005-03-31 21:39:31 +00:00
|
|
|
address[type][idx] = 0;
|
|
|
|
flags[type][idx] = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
_allocatedSize -= ((MemBlkHeader *)ptr)->size;
|
2001-11-05 19:21:49 +00:00
|
|
|
free(ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
const byte *ScummEngine::findResourceData(uint32 tag, const byte *ptr) {
|
2003-04-28 13:16:37 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
error("findResourceData must not be used in GF_OLD_BUNDLE games");
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2003-06-26 00:47:39 +00:00
|
|
|
ptr = findResourceSmall(tag, ptr);
|
2002-08-29 20:01:27 +00:00
|
|
|
else
|
2003-06-26 00:47:39 +00:00
|
|
|
ptr = findResource(tag, ptr);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-11-26 19:57:57 +00:00
|
|
|
return NULL;
|
2002-08-29 20:01:27 +00:00
|
|
|
return ptr + _resourceHeaderSize;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getResourceDataSize(const byte *ptr) const {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-12-27 17:51:58 +00:00
|
|
|
return 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2003-04-12 20:12:52 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
2005-03-31 23:11:39 +00:00
|
|
|
return READ_LE_UINT16(ptr) - _resourceHeaderSize;
|
2003-04-12 20:12:52 +00:00
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2005-03-31 23:11:39 +00:00
|
|
|
return READ_LE_UINT32(ptr) - _resourceHeaderSize;
|
2002-04-11 17:19:16 +00:00
|
|
|
else
|
2005-03-31 23:11:39 +00:00
|
|
|
return READ_BE_UINT32(ptr - 4) - _resourceHeaderSize;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
void ResourceManager::lock(int type, int i) {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("Locking", type, i))
|
|
|
|
return;
|
2005-03-31 21:39:31 +00:00
|
|
|
flags[type][i] |= RF_LOCK;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
void ResourceManager::unlock(int type, int i) {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("Unlocking", type, i))
|
|
|
|
return;
|
2005-03-31 21:39:31 +00:00
|
|
|
flags[type][i] &= ~RF_LOCK;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 15:00:23 +00:00
|
|
|
bool ResourceManager::isLocked(int type, int i) const {
|
2005-10-18 08:56:14 +00:00
|
|
|
if (!validateResource("isLocked", type, i))
|
2005-10-17 15:00:23 +00:00
|
|
|
return false;
|
|
|
|
return (flags[type][i] & RF_LOCK) != 0;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
bool ScummEngine::isResourceInUse(int type, int i) const {
|
2005-03-31 21:39:31 +00:00
|
|
|
if (!res.validateResource("isResourceInUse", type, i))
|
2002-09-25 03:04:28 +00:00
|
|
|
return false;
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (type) {
|
2001-11-05 19:21:49 +00:00
|
|
|
case rtRoom:
|
|
|
|
return _roomResource == (byte)i;
|
2005-05-23 03:44:10 +00:00
|
|
|
case rtRoomImage:
|
|
|
|
return _roomResource == (byte)i;
|
2002-12-27 19:48:30 +00:00
|
|
|
case rtRoomScripts:
|
|
|
|
return _roomResource == (byte)i;
|
2001-11-05 19:21:49 +00:00
|
|
|
case rtScript:
|
|
|
|
return isScriptInUse(i);
|
|
|
|
case rtCostume:
|
|
|
|
return isCostumeInUse(i);
|
|
|
|
case rtSound:
|
2003-09-07 17:14:56 +00:00
|
|
|
return _sound->isSoundInUse(i);
|
2005-05-13 10:23:56 +00:00
|
|
|
case rtCharset:
|
|
|
|
return _charset->getCurID() == i;
|
2006-01-05 07:06:47 +00:00
|
|
|
case rtSpoolBuffer:
|
|
|
|
return _sound->isSoundRunning(10000 + i);
|
2001-11-05 19:21:49 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
void ResourceManager::expireResources(uint32 size) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-11-05 19:21:49 +00:00
|
|
|
byte flag;
|
|
|
|
byte best_counter;
|
2002-04-13 04:39:04 +00:00
|
|
|
int best_type, best_res = 0;
|
2001-11-06 21:29:23 +00:00
|
|
|
uint32 oldAllocatedSize;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
if (_expireCounter != 0xFF) {
|
|
|
|
_expireCounter = 0xFF;
|
|
|
|
increaseResourceCounter();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
if (size + _allocatedSize < _maxHeapThreshold)
|
2001-11-05 19:21:49 +00:00
|
|
|
return;
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
oldAllocatedSize = _allocatedSize;
|
2001-11-06 21:29:23 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
do {
|
|
|
|
best_type = 0;
|
|
|
|
best_counter = 2;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = rtFirst; i <= rtLast; i++)
|
2005-04-06 17:31:35 +00:00
|
|
|
if (mode[i]) {
|
|
|
|
for (j = num[i]; --j >= 0;) {
|
|
|
|
flag = flags[i][j];
|
|
|
|
if (!(flag & RF_LOCK) && flag >= best_counter && address[i][j] && !_vm->isResourceInUse(i, j)) {
|
2001-11-05 19:21:49 +00:00
|
|
|
best_counter = flag;
|
|
|
|
best_type = i;
|
|
|
|
best_res = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!best_type)
|
|
|
|
break;
|
2005-04-06 17:31:35 +00:00
|
|
|
nukeResource(best_type, best_res);
|
|
|
|
} while (size + _allocatedSize > _minHeapThreshold);
|
2001-11-06 21:29:23 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
increaseResourceCounter();
|
2001-11-07 18:10:52 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
void ResourceManager::freeResources() {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
|
|
|
for (i = rtFirst; i <= rtLast; i++) {
|
2005-03-31 21:39:31 +00:00
|
|
|
for (j = num[i]; --j >= 0;) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (isResourceLoaded(i, j))
|
|
|
|
nukeResource(i, j);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2005-03-31 21:39:31 +00:00
|
|
|
free(address[i]);
|
|
|
|
free(flags[i]);
|
|
|
|
free(roomno[i]);
|
|
|
|
free(roomoffs[i]);
|
2004-06-07 00:26:08 +00:00
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
free(globsize[i]);
|
2004-06-22 13:52:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source) {
|
2002-02-24 17:25:03 +00:00
|
|
|
byte *alloced;
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, len;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
res.nukeResource(type, resindex);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-28 01:57:19 +00:00
|
|
|
len = resStrLen(source) + 1;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-09 22:45:19 +00:00
|
|
|
if (len <= 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
alloced = res.createResource(type, resindex, len);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (!source) {
|
|
|
|
alloced[0] = fetchScriptByte();
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < len; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
alloced[i] = *_scriptPointer++;
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
alloced[i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-31 21:39:31 +00:00
|
|
|
bool ResourceManager::isResourceLoaded(int type, int idx) const {
|
2004-07-31 23:20:37 +00:00
|
|
|
if (!validateResource("isResourceLoaded", type, idx))
|
2002-09-25 03:04:28 +00:00
|
|
|
return false;
|
2005-03-31 21:39:31 +00:00
|
|
|
return address[type][idx] != NULL;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
void ResourceManager::resourceStats() {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-11-07 18:10:52 +00:00
|
|
|
uint32 lockedSize = 0, lockedNum = 0;
|
|
|
|
byte flag;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = rtFirst; i <= rtLast; i++)
|
2005-04-06 17:31:35 +00:00
|
|
|
for (j = num[i]; --j >= 0;) {
|
|
|
|
flag = flags[i][j];
|
|
|
|
if (flag & RF_LOCK && address[i][j]) {
|
|
|
|
lockedSize += ((MemBlkHeader *)address[i][j])->size;
|
2001-11-07 18:10:52 +00:00
|
|
|
lockedNum++;
|
|
|
|
}
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2005-04-06 17:31:35 +00:00
|
|
|
debug(1, "Total allocated size=%d, locked=%d(%d)", _allocatedSize, lockedSize, lockedNum);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2005-04-09 20:26:51 +00:00
|
|
|
void ScummEngine_v5::readMAXS(int blockSize) {
|
2005-11-05 10:46:28 +00:00
|
|
|
debug(9, "ScummEngine_v5 readMAXS: MAXS has blocksize %d", blockSize);
|
2004-06-26 12:57:11 +00:00
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
_numVariables = _fileHandle->readUint16LE(); // 800
|
|
|
|
_fileHandle->readUint16LE(); // 16
|
|
|
|
_numBitVariables = _fileHandle->readUint16LE(); // 2048
|
|
|
|
_numLocalObjects = _fileHandle->readUint16LE(); // 200
|
|
|
|
_numArray = 50;
|
|
|
|
_numVerbs = 100;
|
|
|
|
// Used to be 50, which wasn't enough for MI2 and FOA. See bugs
|
|
|
|
// #933610, #936323 and #941275.
|
|
|
|
_numNewNames = 150;
|
|
|
|
_objectRoomTable = NULL;
|
2004-06-06 02:20:53 +00:00
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
_fileHandle->readUint16LE(); // 50
|
|
|
|
_numCharsets = _fileHandle->readUint16LE(); // 9
|
|
|
|
_fileHandle->readUint16LE(); // 100
|
|
|
|
_fileHandle->readUint16LE(); // 50
|
|
|
|
_numInventory = _fileHandle->readUint16LE(); // 80
|
|
|
|
_numGlobalScripts = 200;
|
|
|
|
|
|
|
|
_shadowPaletteSize = 256;
|
|
|
|
|
|
|
|
_numFlObject = 50;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
if (_shadowPaletteSize)
|
2002-05-01 17:16:47 +00:00
|
|
|
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2005-05-14 22:56:41 +00:00
|
|
|
#ifndef DISABLE_SCUMM_7_8
|
2005-04-09 20:22:31 +00:00
|
|
|
void ScummEngine_v8::readMAXS(int blockSize) {
|
2005-11-05 10:46:28 +00:00
|
|
|
debug(9, "ScummEngine_v8 readMAXS: MAXS has blocksize %d", blockSize);
|
2005-04-09 20:22:31 +00:00
|
|
|
|
2005-04-10 13:16:49 +00:00
|
|
|
_fileHandle->seek(50, SEEK_CUR); // Skip over SCUMM engine version
|
|
|
|
_fileHandle->seek(50, SEEK_CUR); // Skip over data file version
|
2005-04-09 20:22:31 +00:00
|
|
|
_numVariables = _fileHandle->readUint32LE(); // 1500
|
|
|
|
_numBitVariables = _fileHandle->readUint32LE(); // 2048
|
|
|
|
_fileHandle->readUint32LE(); // 40
|
|
|
|
_numScripts = _fileHandle->readUint32LE(); // 458
|
|
|
|
_numSounds = _fileHandle->readUint32LE(); // 789
|
|
|
|
_numCharsets = _fileHandle->readUint32LE(); // 1
|
|
|
|
_numCostumes = _fileHandle->readUint32LE(); // 446
|
|
|
|
_numRooms = _fileHandle->readUint32LE(); // 95
|
|
|
|
_fileHandle->readUint32LE(); // 80
|
|
|
|
_numGlobalObjects = _fileHandle->readUint32LE(); // 1401
|
|
|
|
_fileHandle->readUint32LE(); // 60
|
|
|
|
_numLocalObjects = _fileHandle->readUint32LE(); // 200
|
|
|
|
_numNewNames = _fileHandle->readUint32LE(); // 100
|
|
|
|
_numFlObject = _fileHandle->readUint32LE(); // 128
|
|
|
|
_numInventory = _fileHandle->readUint32LE(); // 80
|
|
|
|
_numArray = _fileHandle->readUint32LE(); // 200
|
|
|
|
_numVerbs = _fileHandle->readUint32LE(); // 50
|
|
|
|
|
|
|
|
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
_numGlobalScripts = 2000;
|
|
|
|
|
|
|
|
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
|
|
|
|
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine_v7::readMAXS(int blockSize) {
|
2005-11-05 10:46:28 +00:00
|
|
|
debug(9, "ScummEngine_v7 readMAXS: MAXS has blocksize %d", blockSize);
|
2005-04-09 20:22:31 +00:00
|
|
|
|
2005-04-10 13:16:49 +00:00
|
|
|
_fileHandle->seek(50, SEEK_CUR); // Skip over SCUMM engine version
|
|
|
|
_fileHandle->seek(50, SEEK_CUR); // Skip over data file version
|
2005-04-09 20:22:31 +00:00
|
|
|
_numVariables = _fileHandle->readUint16LE();
|
|
|
|
_numBitVariables = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->readUint16LE();
|
|
|
|
_numGlobalObjects = _fileHandle->readUint16LE();
|
|
|
|
_numLocalObjects = _fileHandle->readUint16LE();
|
|
|
|
_numNewNames = _fileHandle->readUint16LE();
|
|
|
|
_numVerbs = _fileHandle->readUint16LE();
|
|
|
|
_numFlObject = _fileHandle->readUint16LE();
|
|
|
|
_numInventory = _fileHandle->readUint16LE();
|
|
|
|
_numArray = _fileHandle->readUint16LE();
|
|
|
|
_numRooms = _fileHandle->readUint16LE();
|
|
|
|
_numScripts = _fileHandle->readUint16LE();
|
|
|
|
_numSounds = _fileHandle->readUint16LE();
|
|
|
|
_numCharsets = _fileHandle->readUint16LE();
|
|
|
|
_numCostumes = _fileHandle->readUint16LE();
|
|
|
|
|
|
|
|
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
if ((_gameId == GID_FT) && (_features & GF_DEMO) &&
|
2005-04-20 18:21:30 +00:00
|
|
|
(_platform == Common::kPlatformPC))
|
2005-04-09 20:22:31 +00:00
|
|
|
_numGlobalScripts = 300;
|
|
|
|
else
|
|
|
|
_numGlobalScripts = 2000;
|
|
|
|
|
|
|
|
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
|
|
|
|
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
|
|
|
|
}
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2005-04-09 20:22:31 +00:00
|
|
|
|
|
|
|
void ScummEngine_v6::readMAXS(int blockSize) {
|
2005-11-05 10:46:28 +00:00
|
|
|
debug(0, "ScummEngine_v6 readMAXS: MAXS has blocksize %d", blockSize);
|
2005-04-09 20:22:31 +00:00
|
|
|
|
|
|
|
_numVariables = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->readUint16LE();
|
|
|
|
_numBitVariables = _fileHandle->readUint16LE();
|
|
|
|
_numLocalObjects = _fileHandle->readUint16LE();
|
|
|
|
_numArray = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->readUint16LE();
|
|
|
|
_numVerbs = _fileHandle->readUint16LE();
|
|
|
|
_numFlObject = _fileHandle->readUint16LE();
|
|
|
|
_numInventory = _fileHandle->readUint16LE();
|
|
|
|
_numRooms = _fileHandle->readUint16LE();
|
|
|
|
_numScripts = _fileHandle->readUint16LE();
|
|
|
|
_numSounds = _fileHandle->readUint16LE();
|
|
|
|
_numCharsets = _fileHandle->readUint16LE();
|
|
|
|
_numCostumes = _fileHandle->readUint16LE();
|
|
|
|
_numGlobalObjects = _fileHandle->readUint16LE();
|
|
|
|
_numNewNames = 50;
|
|
|
|
|
|
|
|
_objectRoomTable = NULL;
|
|
|
|
_numGlobalScripts = 200;
|
|
|
|
|
|
|
|
if (_heversion >= 70) {
|
|
|
|
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
}
|
|
|
|
|
2005-10-21 02:26:24 +00:00
|
|
|
if (_heversion <= 70) {
|
|
|
|
_shadowPaletteSize = 256;
|
|
|
|
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
|
|
|
|
}
|
2005-04-09 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
void ScummEngine::readGlobalObjects() {
|
|
|
|
int i;
|
|
|
|
int num = _fileHandle->readUint16LE();
|
|
|
|
assert(num == _numGlobalObjects);
|
|
|
|
|
|
|
|
_fileHandle->read(_objectOwnerTable, num);
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
_objectStateTable[i] = _objectOwnerTable[i] >> OF_STATE_SHL;
|
|
|
|
_objectOwnerTable[i] &= OF_OWNER_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
_fileHandle->read(_classData, num * sizeof(uint32));
|
|
|
|
|
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
|
|
|
// Correct the endianess if necessary
|
|
|
|
for (i = 0; i != num; i++)
|
|
|
|
_classData[i] = FROM_LE_32(_classData[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-05-14 22:56:41 +00:00
|
|
|
#ifndef DISABLE_SCUMM_7_8
|
2005-04-09 20:22:31 +00:00
|
|
|
void ScummEngine_v8::readGlobalObjects() {
|
|
|
|
int i;
|
|
|
|
int num = _fileHandle->readUint32LE();
|
|
|
|
assert(num == _numGlobalObjects);
|
|
|
|
|
2005-04-23 16:52:11 +00:00
|
|
|
_objectIDMap = new ObjectNameId[num];
|
|
|
|
_objectIDMapSize = num;
|
2005-04-09 20:22:31 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2005-04-23 16:52:11 +00:00
|
|
|
// Add to object name-to-id map
|
|
|
|
_fileHandle->read(_objectIDMap[i].name, 40);
|
|
|
|
_objectIDMap[i].id = i;
|
|
|
|
|
2005-04-09 20:22:31 +00:00
|
|
|
_objectStateTable[i] = _fileHandle->readByte();
|
|
|
|
_objectRoomTable[i] = _fileHandle->readByte();
|
|
|
|
_classData[i] = _fileHandle->readUint32LE();
|
|
|
|
}
|
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-23 16:52:11 +00:00
|
|
|
// Finally, sort the object name->ID map, so we can later use
|
|
|
|
// bsearch on it. For this we (ab)use strcmp, which works fine
|
|
|
|
// since the table entries start with a string.
|
|
|
|
qsort(_objectIDMap, _objectIDMapSize, sizeof(ObjectNameId),
|
|
|
|
(int (*)(const void*, const void*))strcmp);
|
2005-04-09 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine_v7::readGlobalObjects() {
|
|
|
|
int num = _fileHandle->readUint16LE();
|
|
|
|
assert(num == _numGlobalObjects);
|
|
|
|
|
|
|
|
_fileHandle->read(_objectStateTable, num);
|
|
|
|
_fileHandle->read(_objectRoomTable, num);
|
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
|
|
|
|
|
|
|
_fileHandle->read(_classData, num * sizeof(uint32));
|
|
|
|
|
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
|
|
|
// Correct the endianess if necessary
|
|
|
|
for (int i = 0; i != num; i++)
|
|
|
|
_classData[i] = FROM_LE_32(_classData[i]);
|
|
|
|
#endif
|
|
|
|
}
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2005-04-09 20:22:31 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::allocateArrays() {
|
2002-03-14 13:57:28 +00:00
|
|
|
// Note: Buffers are now allocated in scummMain to allow for
|
2002-04-11 17:19:16 +00:00
|
|
|
// early GUI init.
|
|
|
|
|
2002-05-01 17:16:47 +00:00
|
|
|
_objectOwnerTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
_objectStateTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
_classData = (uint32 *)calloc(_numGlobalObjects, sizeof(uint32));
|
|
|
|
_newNames = (uint16 *)calloc(_numNewNames, sizeof(uint16));
|
|
|
|
|
|
|
|
_inventory = (uint16 *)calloc(_numInventory, sizeof(uint16));
|
|
|
|
_verbs = (VerbSlot *)calloc(_numVerbs, sizeof(VerbSlot));
|
|
|
|
_objs = (ObjectData *)calloc(_numLocalObjects, sizeof(ObjectData));
|
2004-08-26 23:30:28 +00:00
|
|
|
_roomVars = (int32 *)calloc(_numRoomVariables, sizeof(int32));
|
2003-05-08 15:48:50 +00:00
|
|
|
_scummVars = (int32 *)calloc(_numVariables, sizeof(int32));
|
2002-05-01 17:16:47 +00:00
|
|
|
_bitVars = (byte *)calloc(_numBitVariables >> 3, 1);
|
2005-10-14 02:13:33 +00:00
|
|
|
if (_heversion >= 60) {
|
2004-08-02 05:09:53 +00:00
|
|
|
_arraySlot = (byte *)calloc(_numArray, 1);
|
2005-10-19 12:15:36 +00:00
|
|
|
}
|
|
|
|
if (_heversion >= 70) {
|
2005-10-14 02:13:33 +00:00
|
|
|
_storedFlObjects = (ObjectData *)calloc(100, sizeof(ObjectData));
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-24 02:18:02 +00:00
|
|
|
allocResTypeData(rtCostume, (_features & GF_NEW_COSTUMES) ? MKID('AKOS') : MKID('COST'),
|
|
|
|
_numCostumes, "costume", 1);
|
2001-11-26 19:57:57 +00:00
|
|
|
allocResTypeData(rtRoom, MKID('ROOM'), _numRooms, "room", 1);
|
2004-09-27 10:25:45 +00:00
|
|
|
allocResTypeData(rtRoomImage, MKID('RMIM'), _numRooms, "room image", 1);
|
2002-07-04 15:48:17 +00:00
|
|
|
allocResTypeData(rtRoomScripts, MKID('RMSC'), _numRooms, "room script", 1);
|
2003-09-14 20:34:48 +00:00
|
|
|
allocResTypeData(rtSound, MKID('SOUN'), _numSounds, "sound", 2);
|
2001-11-26 19:57:57 +00:00
|
|
|
allocResTypeData(rtScript, MKID('SCRP'), _numScripts, "script", 1);
|
|
|
|
allocResTypeData(rtCharset, MKID('CHAR'), _numCharsets, "charset", 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
allocResTypeData(rtObjectName, MKID('NONE'), _numNewNames, "new name", 0);
|
|
|
|
allocResTypeData(rtInventory, MKID('NONE'), _numInventory, "inventory", 0);
|
|
|
|
allocResTypeData(rtTemp, MKID('NONE'), 10, "temp", 0);
|
|
|
|
allocResTypeData(rtScaleTable, MKID('NONE'), 5, "scale table", 0);
|
2003-05-13 23:42:41 +00:00
|
|
|
allocResTypeData(rtActorName, MKID('NONE'), _numActors, "actor name", 0);
|
2002-04-11 17:19:16 +00:00
|
|
|
allocResTypeData(rtVerb, MKID('NONE'), _numVerbs, "verb", 0);
|
|
|
|
allocResTypeData(rtString, MKID('NONE'), _numArray, "array", 0);
|
|
|
|
allocResTypeData(rtFlObject, MKID('NONE'), _numFlObject, "flobject", 0);
|
|
|
|
allocResTypeData(rtMatrix, MKID('NONE'), 10, "boxes", 0);
|
2004-06-26 12:57:11 +00:00
|
|
|
allocResTypeData(rtImage, MKID('AWIZ'), _numImages, "images", 1);
|
2004-09-08 05:58:36 +00:00
|
|
|
allocResTypeData(rtTalkie, MKID('TLKE'), _numTalkies, "talkie", 1);
|
2004-09-07 13:23:26 +00:00
|
|
|
|
2006-01-05 07:06:47 +00:00
|
|
|
if (_heversion >= 70) {
|
|
|
|
allocResTypeData(rtSpoolBuffer, MKID('NONE'), 9, "spool buffer", 0);
|
|
|
|
}
|
2001-11-06 21:41:56 +00:00
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
|
2003-07-19 18:18:01 +00:00
|
|
|
char buf[256];
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File out;
|
2003-07-19 18:18:01 +00:00
|
|
|
|
|
|
|
uint32 size;
|
|
|
|
if (length >= 0)
|
|
|
|
size = length;
|
|
|
|
else if (_features & GF_OLD_BUNDLE)
|
|
|
|
size = READ_LE_UINT16(ptr);
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
|
|
|
size = READ_LE_UINT32(ptr);
|
|
|
|
else
|
|
|
|
size = READ_BE_UINT32(ptr + 4);
|
|
|
|
|
|
|
|
#if defined(MACOS_CARBON)
|
|
|
|
sprintf(buf, ":dumps:%s%d.dmp", tag, idx);
|
|
|
|
#else
|
|
|
|
sprintf(buf, "dumps/%s%d.dmp", tag, idx);
|
|
|
|
#endif
|
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
out.open(buf, Common::File::kFileWriteMode);
|
2003-12-25 15:09:23 +00:00
|
|
|
if (out.isOpen() == false)
|
|
|
|
return;
|
|
|
|
out.write(ptr, size);
|
2003-07-19 18:18:01 +00:00
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
ResourceIterator::ResourceIterator(const byte *searchin, bool smallHeader)
|
|
|
|
: _ptr(searchin), _smallHeader(smallHeader) {
|
|
|
|
assert(searchin);
|
|
|
|
if (_smallHeader) {
|
|
|
|
_size = READ_LE_UINT32(searchin);
|
|
|
|
_pos = 6;
|
|
|
|
_ptr = searchin + 6;
|
|
|
|
} else {
|
|
|
|
_size = READ_BE_UINT32(searchin + 4);
|
|
|
|
_pos = 8;
|
|
|
|
_ptr = searchin + 8;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const byte *ResourceIterator::findNext(uint32 tag) {
|
|
|
|
uint32 size = 0;
|
|
|
|
const byte *result = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
if (_smallHeader) {
|
|
|
|
uint16 smallTag = newTag2Old(tag);
|
|
|
|
do {
|
|
|
|
if (_pos >= _size)
|
|
|
|
return 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
result = _ptr;
|
|
|
|
size = READ_LE_UINT32(result);
|
|
|
|
if ((int32)size <= 0)
|
|
|
|
return 0; // Avoid endless loop
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
_pos += size;
|
|
|
|
_ptr += size;
|
|
|
|
} while (READ_LE_UINT16(result + 4) != smallTag);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (_pos >= _size)
|
|
|
|
return 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
result = _ptr;
|
|
|
|
size = READ_BE_UINT32(result + 4);
|
|
|
|
if ((int32)size <= 0)
|
|
|
|
return 0; // Avoid endless loop
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
_pos += size;
|
|
|
|
_ptr += size;
|
|
|
|
} while (READ_UINT32(result) != tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
const byte *ScummEngine::findResource(uint32 tag, const byte *searchin) {
|
2003-06-26 13:54:29 +00:00
|
|
|
uint32 curpos, totalsize, size;
|
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
debugC(DEBUG_RESOURCE, "findResource(%s, %lx)", tag2str(tag), searchin);
|
2003-06-26 13:54:29 +00:00
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
if (!searchin) {
|
|
|
|
if (_heversion >= 70) {
|
|
|
|
searchin = _resourceLastSearchBuf;
|
|
|
|
totalsize = _resourceLastSearchSize;
|
|
|
|
curpos = 0;
|
|
|
|
} else {
|
|
|
|
assert(searchin);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
searchin += 4;
|
|
|
|
_resourceLastSearchSize = totalsize = READ_BE_UINT32(searchin);
|
|
|
|
curpos = 8;
|
|
|
|
searchin += 4;
|
|
|
|
}
|
2003-06-26 13:54:29 +00:00
|
|
|
|
|
|
|
while (curpos < totalsize) {
|
2004-06-23 01:36:57 +00:00
|
|
|
if (READ_UINT32(searchin) == tag) {
|
|
|
|
_resourceLastSearchBuf = searchin;
|
2003-06-26 13:54:29 +00:00
|
|
|
return searchin;
|
2004-06-23 01:36:57 +00:00
|
|
|
}
|
2003-06-26 13:54:29 +00:00
|
|
|
|
|
|
|
size = READ_BE_UINT32(searchin + 4);
|
|
|
|
if ((int32)size <= 0) {
|
2003-10-17 16:28:29 +00:00
|
|
|
error("(%s) Not found in %d... illegal block len %d", tag2str(tag), 0, size);
|
2003-06-26 13:54:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const byte *findResourceSmall(uint32 tag, const byte *searchin) {
|
|
|
|
uint32 curpos, totalsize, size;
|
|
|
|
uint16 smallTag;
|
|
|
|
|
|
|
|
smallTag = newTag2Old(tag);
|
2003-07-17 14:03:15 +00:00
|
|
|
if (smallTag == 0)
|
|
|
|
return NULL;
|
2003-06-26 13:54:29 +00:00
|
|
|
|
|
|
|
assert(searchin);
|
|
|
|
|
|
|
|
totalsize = READ_LE_UINT32(searchin);
|
|
|
|
searchin += 6;
|
|
|
|
curpos = 6;
|
|
|
|
|
|
|
|
while (curpos < totalsize) {
|
|
|
|
size = READ_LE_UINT32(searchin);
|
|
|
|
|
|
|
|
if (READ_LE_UINT16(searchin + 4) == smallTag)
|
|
|
|
return searchin;
|
|
|
|
|
|
|
|
if ((int32)size <= 0) {
|
2003-10-17 16:28:29 +00:00
|
|
|
error("(%s) Not found in %d... illegal block len %d", tag2str(tag), 0, size);
|
2003-06-26 13:54:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-03-06 13:23:29 +00:00
|
|
|
uint16 newTag2Old(uint32 newTag) {
|
|
|
|
switch (newTag) {
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('RMHD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4448); // HD
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('IM00')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('EXCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5845); // EX
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('ENCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4E45); // EN
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('SCAL')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4153); // SA
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('LSCR')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x534C); // LS
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('OBCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x434F); // OC
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('OBIM')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x494F); // OI
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('SMAP')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('CLUT')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4150); // PA
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('BOXD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5842); // BX
|
2003-08-28 01:10:36 +00:00
|
|
|
case (MKID('CYCL')):
|
|
|
|
return (0x4343); // CC
|
2004-08-22 06:16:16 +00:00
|
|
|
case (MKID('EPAL')):
|
|
|
|
return (0x5053); // SP
|
2002-04-11 17:19:16 +00:00
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
}
|
2002-04-21 19:38:00 +00:00
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
const char *resTypeFromId(int id) {
|
2002-04-26 14:13:39 +00:00
|
|
|
static char buf[100];
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
switch (id) {
|
|
|
|
case rtRoom:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Room";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtScript:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Script";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtCostume:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Costume";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtSound:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Sound";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtInventory:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Inventory";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtCharset:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Charset";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtString:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "String";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtVerb:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Verb";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtActorName:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "ActorName";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtBuffer:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Buffer";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtScaleTable:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "ScaleTable";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtTemp:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Temp";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtFlObject:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "FlObject";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtMatrix:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Matrix";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtBox:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Box";
|
2004-08-30 00:10:36 +00:00
|
|
|
case rtObjectName:
|
|
|
|
return "ObjectName";
|
|
|
|
case rtRoomScripts:
|
|
|
|
return "RoomScripts";
|
|
|
|
case rtRoomImage:
|
|
|
|
return "RoomImage";
|
2004-06-26 12:57:11 +00:00
|
|
|
case rtImage:
|
|
|
|
return "Image";
|
2004-09-07 13:23:26 +00:00
|
|
|
case rtTalkie:
|
|
|
|
return "Talkie";
|
2006-01-05 07:06:47 +00:00
|
|
|
case rtSpoolBuffer:
|
|
|
|
return "SpoolBuffer";
|
2004-08-30 00:10:36 +00:00
|
|
|
case rtNumTypes:
|
|
|
|
return "NumTypes";
|
2002-07-07 20:32:26 +00:00
|
|
|
default:
|
|
|
|
sprintf(buf, "%d", id);
|
2003-06-25 23:49:54 +00:00
|
|
|
return buf;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
} // End of namespace Scumm
|