2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:40:49 +00:00
|
|
|
* 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.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// RSC Resource file management module
|
2007-07-31 18:08:40 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-06 14:26:59 +00:00
|
|
|
#include "saga/actor.h"
|
2005-09-23 14:29:26 +00:00
|
|
|
#include "saga/animation.h"
|
2005-08-07 00:00:43 +00:00
|
|
|
#include "saga/interface.h"
|
2005-08-30 11:16:11 +00:00
|
|
|
#include "saga/music.h"
|
2008-12-22 14:13:15 +00:00
|
|
|
#include "saga/resource.h"
|
2005-10-04 23:38:19 +00:00
|
|
|
#include "saga/scene.h"
|
2005-08-07 00:00:43 +00:00
|
|
|
#include "saga/sndres.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2009-01-29 22:13:01 +00:00
|
|
|
#include "engines/advancedDetector.h"
|
2007-01-21 20:24:38 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
|
2005-07-19 19:05:52 +00:00
|
|
|
size_t i;
|
|
|
|
bool result;
|
2005-07-29 17:58:00 +00:00
|
|
|
byte tableInfo[RSC_TABLEINFO_SIZE];
|
2005-07-19 19:05:52 +00:00
|
|
|
byte *tableBuffer;
|
|
|
|
size_t tableSize;
|
2009-12-04 17:52:42 +00:00
|
|
|
uint32 count;
|
2005-08-04 10:23:49 +00:00
|
|
|
uint32 resourceTableOffset;
|
|
|
|
ResourceData *resourceData;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
if (contextSize < RSC_MIN_FILESIZE) {
|
2005-07-19 19:05:52 +00:00
|
|
|
return false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
_file.seek(contextOffset + contextSize - RSC_TABLEINFO_SIZE);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_file.read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
|
2005-07-19 19:05:52 +00:00
|
|
|
return false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
MemoryReadStreamEndian readS(tableInfo, RSC_TABLEINFO_SIZE, _isBigEndian);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceTableOffset = readS.readUint32();
|
2009-12-04 17:52:42 +00:00
|
|
|
count = readS.readUint32();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
// Check for sane table offset
|
2009-12-04 17:52:42 +00:00
|
|
|
if (resourceTableOffset != contextSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * count) {
|
2005-07-19 19:05:52 +00:00
|
|
|
return false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Load resource table
|
2009-12-04 17:52:42 +00:00
|
|
|
tableSize = RSC_TABLEENTRY_SIZE * count;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
tableBuffer = (byte *)malloc(tableSize);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
_file.seek(resourceTableOffset + contextOffset, SEEK_SET);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
result = (_file.read(tableBuffer, tableSize) == tableSize);
|
2005-07-19 19:05:52 +00:00
|
|
|
if (result) {
|
2009-12-04 17:52:42 +00:00
|
|
|
_table.resize(count);
|
2005-07-19 19:05:52 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
MemoryReadStreamEndian readS1(tableBuffer, tableSize, _isBigEndian);
|
2005-07-19 19:05:52 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
resourceData = &_table[i];
|
2005-08-04 10:23:49 +00:00
|
|
|
resourceData->offset = contextOffset + readS1.readUint32();
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceData->size = readS1.readUint32();
|
|
|
|
//sanity check
|
2009-12-04 17:52:42 +00:00
|
|
|
if ((resourceData->offset > (uint)_fileSize) || (resourceData->size > contextSize)) {
|
2005-07-19 19:05:52 +00:00
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
free(tableBuffer);
|
2005-08-04 10:23:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
|
2005-08-04 10:23:49 +00:00
|
|
|
size_t i;
|
2006-10-08 07:48:19 +00:00
|
|
|
const GamePatchDescription *patchDescription;
|
2005-08-04 10:23:49 +00:00
|
|
|
ResourceData *resourceData;
|
|
|
|
uint16 subjectResourceType;
|
|
|
|
ResourceContext *subjectContext;
|
|
|
|
uint32 subjectResourceId;
|
|
|
|
uint32 patchResourceId;
|
|
|
|
ResourceData *subjectResourceData;
|
|
|
|
byte *tableBuffer;
|
|
|
|
size_t tableSize;
|
|
|
|
bool isMacBinary;
|
2005-09-21 10:09:58 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_fileName == NULL) { // IHNM special case
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_file.open(_fileName)) {
|
2005-08-04 10:23:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
_fileSize = _file.size();
|
|
|
|
_isBigEndian = vm->isBigEndian();
|
2005-09-21 10:09:58 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_fileType & GAME_SWAPENDIAN)
|
|
|
|
_isBigEndian = !_isBigEndian;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
isMacBinary = (_fileType & GAME_MACBINARY) > 0;
|
|
|
|
_fileType &= ~GAME_MACBINARY;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-12-21 22:52:44 +00:00
|
|
|
if (!isMacBinary) {
|
2009-12-04 17:52:42 +00:00
|
|
|
if (!loadRes(0, _fileSize)) {
|
2008-12-22 14:13:15 +00:00
|
|
|
return false;
|
2005-08-04 10:23:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-12-04 17:52:42 +00:00
|
|
|
if (!loadMac()) {
|
2005-08-04 10:23:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-30 17:28:58 +00:00
|
|
|
//process internal patch files
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_fileType & GAME_PATCHFILE) {
|
|
|
|
subjectResourceType = ~GAME_PATCHFILE & _fileType;
|
|
|
|
subjectContext = resource->getContext((GameFileTypes)subjectResourceType);
|
2005-07-30 17:28:58 +00:00
|
|
|
if (subjectContext == NULL) {
|
2009-12-04 17:52:42 +00:00
|
|
|
error("ResourceContext::load() Subject context not found");
|
2005-07-30 17:28:58 +00:00
|
|
|
}
|
2009-12-04 17:52:42 +00:00
|
|
|
resource->loadResource(this, _table.size() - 1, tableBuffer, tableSize);
|
2005-07-30 17:28:58 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
MemoryReadStreamEndian readS2(tableBuffer, tableSize, _isBigEndian);
|
2005-07-30 17:28:58 +00:00
|
|
|
for (i = 0; i < tableSize / 8; i++) {
|
|
|
|
subjectResourceId = readS2.readUint32();
|
|
|
|
patchResourceId = readS2.readUint32();
|
2008-09-30 12:58:27 +00:00
|
|
|
subjectResourceData = subjectContext->getResourceData(subjectResourceId);
|
2009-12-04 17:52:42 +00:00
|
|
|
resourceData = getResourceData(patchResourceId);
|
2009-12-27 20:56:10 +00:00
|
|
|
subjectResourceData->patchData = new PatchData(&_file, _fileName);
|
2005-07-30 17:28:58 +00:00
|
|
|
subjectResourceData->offset = resourceData->offset;
|
|
|
|
subjectResourceData->size = resourceData->size;
|
|
|
|
}
|
2006-03-02 18:25:56 +00:00
|
|
|
free(tableBuffer);
|
2005-07-30 17:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//process external patch files
|
2009-12-04 17:52:42 +00:00
|
|
|
for (patchDescription = vm->getPatchDescriptions(); patchDescription && patchDescription->fileName; ++patchDescription) {
|
|
|
|
if ((patchDescription->fileType & _fileType) != 0) {
|
|
|
|
if (patchDescription->resourceId < _table.size()) {
|
|
|
|
resourceData = &_table[patchDescription->resourceId];
|
2009-12-27 20:56:10 +00:00
|
|
|
resourceData->patchData = new PatchData(patchDescription->fileName);
|
2005-08-04 10:23:49 +00:00
|
|
|
if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
|
|
|
|
resourceData->offset = 0;
|
|
|
|
resourceData->size = resourceData->patchData->_patchFile->size();
|
2007-08-25 16:44:44 +00:00
|
|
|
// ITE uses several patch files which are loaded and then not needed
|
|
|
|
// anymore (as they're in memory), so close them here. IHNM uses only
|
|
|
|
// 1 patch file, which is reused, so don't close it
|
2009-12-04 17:52:42 +00:00
|
|
|
if (vm->getGameId() == GID_ITE)
|
2007-08-25 16:44:44 +00:00
|
|
|
resourceData->patchData->_patchFile->close();
|
2005-08-04 10:23:49 +00:00
|
|
|
} else {
|
|
|
|
delete resourceData->patchData;
|
|
|
|
resourceData->patchData = NULL;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2008-01-27 14:32:08 +00:00
|
|
|
// Close the file if it's part of a series of files
|
|
|
|
// This prevents having all voice files open in IHNM for no reason, as each chapter uses
|
|
|
|
// a different voice file
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_serial > 0)
|
|
|
|
_file.close();
|
2008-01-27 14:32:08 +00:00
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
return true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
Resource::Resource(SagaEngine *vm): _vm(vm) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Resource::~Resource() {
|
|
|
|
clearContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resource::addContext(const char *fileName, uint16 fileType, bool isCompressed, int serial) {
|
2005-07-19 19:05:52 +00:00
|
|
|
ResourceContext *context;
|
2009-12-04 17:52:42 +00:00
|
|
|
context = createContext();
|
|
|
|
context->_fileName = fileName;
|
|
|
|
context->_fileType = fileType;
|
|
|
|
context->_isCompressed = isCompressed;
|
|
|
|
context->_serial = serial;
|
|
|
|
_contexts.push_back(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Resource::createContexts() {
|
2007-07-13 16:37:37 +00:00
|
|
|
bool soundFileInArray = false;
|
2006-12-19 04:35:08 +00:00
|
|
|
|
2007-12-23 02:33:58 +00:00
|
|
|
_vm->_voiceFilesExist = true;
|
|
|
|
|
2008-11-14 12:19:10 +00:00
|
|
|
struct SoundFileInfo {
|
2009-12-04 17:52:42 +00:00
|
|
|
int gameId;
|
2008-11-14 12:19:10 +00:00
|
|
|
char fileName[40];
|
|
|
|
bool isCompressed;
|
2009-12-04 17:52:42 +00:00
|
|
|
uint16 voiceFileAddType;
|
2008-11-14 12:19:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-28 04:12:01 +00:00
|
|
|
// If the Wyrmkeep credits file is found, set the Wyrmkeep version flag to true
|
|
|
|
if (Common::File::exists("graphics/credit3n.dlt")) {
|
|
|
|
_vm->_gf_wyrmkeep = true;
|
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
for (const ADGameFileDescription *gameFileDescription = _vm->getFilesDescriptions();
|
|
|
|
gameFileDescription->fileName; gameFileDescription++) {
|
|
|
|
addContext(gameFileDescription->fileName, gameFileDescription->fileType);
|
|
|
|
if (gameFileDescription->fileType == GAME_SOUNDFILE) {
|
2007-07-13 16:37:37 +00:00
|
|
|
soundFileInArray = true;
|
2009-12-04 17:52:42 +00:00
|
|
|
}
|
2007-07-13 16:37:37 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 12:19:10 +00:00
|
|
|
//// Detect and add SFX files ////////////////////////////////////////////////
|
2009-12-04 17:52:42 +00:00
|
|
|
SoundFileInfo sfxFiles[] = {
|
2009-12-04 19:00:40 +00:00
|
|
|
{ GID_ITE, "sounds.rsc", false, 0 },
|
|
|
|
{ GID_ITE, "sounds.cmp", true, 0 },
|
|
|
|
{ GID_ITE, "soundsd.rsc", false, 0 },
|
|
|
|
{ GID_ITE, "soundsd.cmp", true, 0 },
|
2009-01-02 19:10:51 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2009-12-04 19:00:40 +00:00
|
|
|
{ GID_IHNM, "sfx.res", false, 0 },
|
|
|
|
{ GID_IHNM, "sfx.cmp", true, 0 },
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SAGA2
|
2009-12-04 19:00:40 +00:00
|
|
|
{ GID_FTA2, "ftasound.hrs", false, 0 },
|
|
|
|
{ GID_DINO, "dinosnd.hrs", false, 0 },
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
2009-12-04 19:00:40 +00:00
|
|
|
{ -1, "", false, 0 }
|
2009-12-04 17:52:42 +00:00
|
|
|
};
|
2008-11-14 12:19:10 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
_soundFileName[0] = 0;
|
2007-08-01 14:19:55 +00:00
|
|
|
if (!soundFileInArray) {
|
2009-12-04 17:52:42 +00:00
|
|
|
for (SoundFileInfo *curSoundFile = sfxFiles; (curSoundFile->gameId != -1); curSoundFile++) {
|
|
|
|
if (curSoundFile->gameId != _vm->getGameId()) continue;
|
|
|
|
if (!Common::File::exists(curSoundFile->fileName)) continue;
|
|
|
|
strcpy(_soundFileName, curSoundFile->fileName);
|
|
|
|
addContext(_soundFileName, GAME_SOUNDFILE, curSoundFile->isCompressed);
|
|
|
|
break;
|
2007-07-13 16:37:37 +00:00
|
|
|
}
|
2007-08-01 14:19:55 +00:00
|
|
|
}
|
2007-07-13 16:37:37 +00:00
|
|
|
|
2008-11-14 12:19:10 +00:00
|
|
|
//// Detect and add voice files /////////////////////////////////////////////
|
2009-12-04 17:52:42 +00:00
|
|
|
SoundFileInfo voiceFiles[] = {
|
|
|
|
{ GID_ITE, "voices.rsc", false , (_soundFileName[0] == 0) ? GAME_SOUNDFILE : 0},
|
|
|
|
{ GID_ITE, "voices.cmp", true , (_soundFileName[0] == 0) ? GAME_SOUNDFILE : 0},
|
|
|
|
{ GID_ITE, "voicesd.rsc", false , (_soundFileName[0] == 0) ? GAME_SOUNDFILE : 0},
|
|
|
|
{ GID_ITE, "voicesd.cmp", true , (_soundFileName[0] == 0) ? GAME_SOUNDFILE : 0},
|
|
|
|
// The resources in the Wyrmkeep combined Windows/Mac/Linux CD version are little endian, but
|
|
|
|
// the voice file is big endian. If we got such a version with mixed files, mark this voice file
|
|
|
|
// as big endian
|
|
|
|
{ GID_ITE, "inherit the earth voices", false , _vm->isBigEndian() ? 0 : GAME_SWAPENDIAN},
|
|
|
|
{ GID_ITE, "inherit the earth voices.cmp", true , _vm->isBigEndian() ? 0 : GAME_SWAPENDIAN},
|
|
|
|
{ GID_ITE, "ite voices.bin", false , GAME_MACBINARY},
|
2009-01-02 19:10:51 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2009-12-04 17:52:42 +00:00
|
|
|
{ GID_IHNM, "voicess.res", false , 0},
|
|
|
|
{ GID_IHNM, "voicess.cmp", true , 0},
|
|
|
|
{ GID_IHNM, "voicesd.res", false , 0},
|
|
|
|
{ GID_IHNM, "voicesd.cmp", true , 0},
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SAGA2
|
2009-12-04 17:52:42 +00:00
|
|
|
{ GID_FTA2, "ftavoice.hrs", false , 0},
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
2009-12-04 19:00:40 +00:00
|
|
|
{ -1, "", false , 0}
|
2009-12-04 17:52:42 +00:00
|
|
|
};
|
2008-12-22 14:13:15 +00:00
|
|
|
|
2008-11-14 12:19:10 +00:00
|
|
|
// Detect and add voice files
|
2009-12-04 17:52:42 +00:00
|
|
|
_voicesFileName[0][0] = 0;
|
|
|
|
for (SoundFileInfo *curSoundFile = voiceFiles; (curSoundFile->gameId != -1); curSoundFile++) {
|
|
|
|
if (curSoundFile->gameId != _vm->getGameId()) continue;
|
|
|
|
if (!Common::File::exists(curSoundFile->fileName)) continue;
|
2008-11-14 12:19:10 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
strcpy(_voicesFileName[0], curSoundFile->fileName);
|
|
|
|
addContext(_voicesFileName[0], GAME_VOICEFILE | curSoundFile->voiceFileAddType, curSoundFile->isCompressed);
|
2008-11-14 12:19:10 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
// Special cases
|
|
|
|
if (!scumm_stricmp(curSoundFile->fileName, "voicess.res") ||
|
|
|
|
!scumm_stricmp(curSoundFile->fileName, "voicess.cmp")) {
|
2007-08-01 14:19:55 +00:00
|
|
|
// IHNM has multiple voice files
|
2009-12-04 17:52:42 +00:00
|
|
|
for (size_t i = 1; i <= 6; i++) { // voices1-voices6
|
2009-12-04 19:58:10 +00:00
|
|
|
sprintf(_voicesFileName[i], "voices%i.%s", (uint)i, curSoundFile->isCompressed ? "cmp" : "res");
|
2009-12-04 17:52:42 +00:00
|
|
|
if (i == 4) {
|
|
|
|
// The German and French versions of IHNM don't have Nimdok's chapter,
|
|
|
|
// therefore the voices file for that chapter is missing
|
|
|
|
if (!Common::File::exists(_voicesFileName[i])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addContext(_voicesFileName[i], GAME_VOICEFILE, curSoundFile->isCompressed, i);
|
2007-08-01 14:19:55 +00:00
|
|
|
}
|
2007-07-13 16:37:37 +00:00
|
|
|
}
|
2009-12-04 17:52:42 +00:00
|
|
|
break;
|
2007-08-01 14:19:55 +00:00
|
|
|
}
|
2007-07-13 16:37:37 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_voicesFileName[0][0] == 0) {
|
2009-12-30 15:24:16 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-11-14 12:19:10 +00:00
|
|
|
// The Macintosh version of IHNM has no voices.res, and it has all
|
|
|
|
// its voice files in subdirectories, so don't do anything here
|
2009-12-04 17:52:42 +00:00
|
|
|
_contexts.push_back(new VoiceResourceContext_RES());
|
2007-07-13 16:37:37 +00:00
|
|
|
} else {
|
2009-12-30 15:24:16 +00:00
|
|
|
#endif
|
2008-11-14 12:19:10 +00:00
|
|
|
warning("No voice file found, voices will be disabled");
|
|
|
|
_vm->_voicesEnabled = false;
|
|
|
|
_vm->_subtitlesEnabled = true;
|
|
|
|
_vm->_voiceFilesExist = false;
|
2009-12-30 15:24:16 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2008-11-14 12:19:10 +00:00
|
|
|
}
|
2009-12-30 15:24:16 +00:00
|
|
|
#endif
|
2008-11-14 12:19:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
//// Detect and add music files /////////////////////////////////////////
|
|
|
|
SoundFileInfo musicFiles[] = {
|
2009-12-04 19:00:40 +00:00
|
|
|
{ GID_ITE, "music.rsc", false, 0 },
|
|
|
|
{ GID_ITE, "music.cmp", true, 0 },
|
|
|
|
{ GID_ITE, "musicd.rsc", false, 0 },
|
|
|
|
{ GID_ITE, "musicd.cmp", true, 0 },
|
|
|
|
{ -1, "", false , 0}
|
2008-11-14 12:19:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check for digital music in ITE
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
for (SoundFileInfo *curSoundFile = musicFiles; (curSoundFile->gameId != -1); curSoundFile++) {
|
|
|
|
if (curSoundFile->gameId != _vm->getGameId()) continue;
|
|
|
|
if (!Common::File::exists(curSoundFile->fileName)) continue;
|
|
|
|
strcpy(_musicFileName, curSoundFile->fileName);
|
|
|
|
addContext(_musicFileName, GAME_DIGITALMUSICFILE, curSoundFile->isCompressed);
|
|
|
|
break;
|
2007-07-13 16:37:37 +00:00
|
|
|
}
|
2006-12-19 04:35:08 +00:00
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
for (ResourceContextList::iterator i = _contexts.begin(); i != _contexts.end(); ++i) {
|
|
|
|
if (!(*i)->load(_vm, this)) {
|
2005-07-19 19:05:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
return true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Resource::clearContexts() {
|
2009-12-04 17:52:42 +00:00
|
|
|
ResourceContextList::iterator i = _contexts.begin();
|
|
|
|
while (i != _contexts.end()) {
|
|
|
|
ResourceContext * context = *i;
|
|
|
|
i = _contexts.erase(i);
|
|
|
|
delete context;
|
2005-06-21 13:55:18 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
2005-01-02 20:29:27 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Resource::loadResource(ResourceContext *context, uint32 resourceId, byte*&resourceBuffer, size_t &resourceSize) {
|
|
|
|
Common::File *file;
|
|
|
|
uint32 resourceOffset;
|
|
|
|
ResourceData *resourceData;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(8, "loadResource %d", resourceId);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2008-09-30 12:58:27 +00:00
|
|
|
resourceData = context->getResourceData(resourceId);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
file = context->getFile(resourceData);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceOffset = resourceData->offset;
|
|
|
|
resourceSize = resourceData->size;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceBuffer = (byte*)malloc(resourceSize);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
file->seek((long)resourceOffset, SEEK_SET);
|
2004-12-15 00:24:12 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (file->read(resourceBuffer, resourceSize) != resourceSize) {
|
|
|
|
error("Resource::loadResource() failed to read");
|
2004-12-15 00:24:12 +00:00
|
|
|
}
|
2007-08-27 09:30:23 +00:00
|
|
|
|
|
|
|
// ITE uses several patch files which are loaded and then not needed
|
|
|
|
// anymore (as they're in memory), so close them here. IHNM uses only
|
|
|
|
// 1 patch file, which is reused, so don't close it
|
2008-12-21 15:59:05 +00:00
|
|
|
if (resourceData->patchData != NULL && _vm->getGameId() == GID_ITE)
|
2007-08-01 09:02:28 +00:00
|
|
|
file->close();
|
2004-12-15 00:24:12 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
ResourceContext *Resource::getContext(uint16 fileType, int serial) {
|
|
|
|
for (ResourceContextList::const_iterator i = _contexts.begin(); i != _contexts.end(); ++i) {
|
|
|
|
ResourceContext * context = *i;
|
|
|
|
if ((context->fileType() & fileType) && (context->serial() == serial)) {
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
} // End of namespace Saga
|