2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:20:17 +00:00
|
|
|
* Copyright (C) 2004-2005 The ScummVM project
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// RSC Resource file management module
|
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"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/rscfile.h"
|
2004-12-15 00:24:12 +00:00
|
|
|
#include "saga/stream.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
struct MacResMap {
|
|
|
|
int16 resAttr;
|
|
|
|
int16 typeOffset;
|
|
|
|
int16 nameOffset;
|
|
|
|
int16 numTypes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MacResource {
|
|
|
|
int16 id;
|
|
|
|
int16 nameOffset;
|
|
|
|
byte attr;
|
|
|
|
int32 dataOffset;
|
|
|
|
byte name[255];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MacResType {
|
|
|
|
uint32 id;
|
|
|
|
int16 items;
|
|
|
|
int16 maxItemId;
|
|
|
|
int16 offset;
|
|
|
|
MacResource *resources;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define ID_MIDI MKID_BE('Midi')
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
Resource::Resource(SagaEngine *vm): _vm(vm) {
|
|
|
|
_contexts = NULL;
|
|
|
|
_contextsCount = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
Resource::~Resource() {
|
|
|
|
clearContexts();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
bool Resource::loadSagaContext(ResourceContext *context, 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;
|
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
|
|
|
}
|
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
context->file->seek(contextOffset + contextSize - RSC_TABLEINFO_SIZE);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (context->file->read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
|
|
|
|
return false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian readS(tableInfo, RSC_TABLEINFO_SIZE, context->isBigEndian);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceTableOffset = readS.readUint32();
|
|
|
|
context->count = readS.readUint32();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
// Check for sane table offset
|
2005-08-04 10:23:49 +00:00
|
|
|
if (resourceTableOffset != contextSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * context->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
|
2005-07-19 19:05:52 +00:00
|
|
|
tableSize = RSC_TABLEENTRY_SIZE * context->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
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
context->file->seek(resourceTableOffset + contextOffset, SEEK_SET);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
result = (context->file->read(tableBuffer, tableSize) == tableSize);
|
|
|
|
if (result) {
|
|
|
|
context->table = (ResourceData *)calloc(context->count, sizeof(*context->table));
|
|
|
|
|
|
|
|
MemoryReadStreamEndian readS1(tableBuffer, tableSize, context->isBigEndian);
|
|
|
|
|
|
|
|
for (i = 0; i < context->count; i++) {
|
|
|
|
resourceData = &context->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
|
2005-08-04 10:23:49 +00:00
|
|
|
if ((resourceData->offset > context->file->size()) || (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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Resource::loadMacContext(ResourceContext *context) {
|
|
|
|
int32 macDataSize, macDataSizePad;
|
|
|
|
int32 macResSize, macResSizePad;
|
|
|
|
int32 macResOffset;
|
|
|
|
|
|
|
|
uint32 macMapLength;
|
|
|
|
uint32 macDataLength;
|
|
|
|
uint32 macMapOffset;
|
|
|
|
uint32 macDataOffset;
|
|
|
|
|
|
|
|
MacResMap macResMap;
|
|
|
|
MacResType *macResTypes;
|
|
|
|
|
|
|
|
MacResType *macResType;
|
|
|
|
MacResource *macResource;
|
|
|
|
int i, j;
|
|
|
|
byte macNameLen;
|
|
|
|
bool notSagaContext = false;
|
|
|
|
|
|
|
|
if (context->file->size() < RSC_MIN_FILESIZE + MAC_BINARY_HEADER_SIZE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->file->readByte() != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
context->file->readByte(); //MAX Name Len
|
|
|
|
context->file->seek(74);
|
|
|
|
if (context->file->readByte() != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
context->file->seek(82);
|
|
|
|
if (context->file->readByte() != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
macDataSize = context->file->readSint32BE();
|
|
|
|
macResSize = context->file->readSint32BE();
|
|
|
|
macDataSizePad = (((macDataSize + 127) >> 7) << 7);
|
|
|
|
macResSizePad = (((macResSize + 127) >> 7) << 7);
|
|
|
|
|
|
|
|
macResOffset = MAC_BINARY_HEADER_SIZE + macDataSizePad;
|
|
|
|
context->file->seek(macResOffset);
|
|
|
|
|
|
|
|
macDataOffset = context->file->readUint32BE() + macResOffset;
|
|
|
|
macMapOffset = context->file->readUint32BE() + macResOffset;
|
|
|
|
macDataLength = context->file->readUint32BE();
|
|
|
|
macMapLength = context->file->readUint32BE();
|
|
|
|
|
|
|
|
if (macDataOffset >= context->file->size() || macMapOffset >= context->file->size() ||
|
|
|
|
macDataLength + macMapLength > context->file->size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->file->seek(macMapOffset + 22);
|
|
|
|
|
|
|
|
macResMap.resAttr = context->file->readUint16BE();
|
|
|
|
macResMap.typeOffset = context->file->readUint16BE();
|
|
|
|
macResMap.nameOffset = context->file->readUint16BE();
|
|
|
|
macResMap.numTypes = context->file->readUint16BE();
|
|
|
|
macResMap.numTypes++;
|
|
|
|
|
|
|
|
context->file->seek(macMapOffset + macResMap.typeOffset + 2);
|
|
|
|
|
|
|
|
macResTypes = (MacResType *)calloc(macResMap.numTypes, sizeof(*macResTypes));
|
|
|
|
|
|
|
|
for (i = macResMap.numTypes, macResType = macResTypes; i > 0; i--, macResType++) {
|
|
|
|
macResType->id = context->file->readUint32BE();
|
|
|
|
macResType->items = context->file->readUint16BE();
|
|
|
|
macResType->offset = context->file->readUint16BE();
|
|
|
|
macResType->items++;
|
|
|
|
macResType->resources = (MacResource*)calloc(macResType->items, sizeof(*macResType->resources));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = macResMap.numTypes, macResType = macResTypes; i > 0; i--, macResType++) {
|
|
|
|
context->file->seek(macResType->offset + macMapOffset + macResMap.typeOffset);
|
|
|
|
|
|
|
|
for (j = macResType->items, macResource = macResType->resources; j > 0; j--, macResource++) {
|
|
|
|
macResource->id = context->file->readUint16BE();
|
|
|
|
macResource->nameOffset = context->file->readUint16BE();
|
|
|
|
macResource->dataOffset = context->file->readUint32BE();
|
|
|
|
macResSize = context->file->readUint32BE();
|
|
|
|
|
|
|
|
macResource->attr = macResource->dataOffset >> 24;
|
|
|
|
macResource->dataOffset &= 0xFFFFFF;
|
|
|
|
if (macResource->id > macResType->maxItemId) {
|
|
|
|
macResType->maxItemId = macResource->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = macResType->items, macResource = macResType->resources; j > 0; j--, macResource++) {
|
|
|
|
if (macResource->nameOffset != -1) {
|
|
|
|
context->file->seek(macResource->nameOffset + macMapOffset + macResMap.nameOffset);
|
|
|
|
macNameLen = context->file->readByte();
|
|
|
|
context->file->read(macResource->name, macNameLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
for (i = macResMap.numTypes, macResType = macResTypes; i > 0; i--, macResType++) {
|
|
|
|
//getting offsets & sizes of midi
|
|
|
|
if (((context->fileType & GAME_MUSICFILE_GM) > 0) && (macResType->id == ID_MIDI)) {
|
|
|
|
|
|
|
|
context->count = macResType->maxItemId + 1;
|
|
|
|
context->table = (ResourceData *)calloc(context->count, sizeof(*context->table));
|
|
|
|
for (j = macResType->items, macResource = macResType->resources; j > 0; j--, macResource++) {
|
|
|
|
context->file->seek(macDataOffset + macResource->dataOffset);
|
|
|
|
context->table[macResource->id].size = context->file->readUint32BE();
|
|
|
|
context->table[macResource->id].offset = context->file->pos();
|
|
|
|
}
|
|
|
|
notSagaContext = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//free
|
|
|
|
for (i = 0; i < macResMap.numTypes; i++) {
|
|
|
|
free(macResTypes[i].resources);
|
|
|
|
}
|
|
|
|
free(macResTypes);
|
|
|
|
|
|
|
|
if ((!notSagaContext) && (!loadSagaContext(context, MAC_BINARY_HEADER_SIZE, macDataSize))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Resource::loadContext(ResourceContext *context) {
|
|
|
|
size_t i;
|
|
|
|
int j;
|
|
|
|
GamePatchDescription *patchDescription;
|
|
|
|
ResourceData *resourceData;
|
|
|
|
uint16 subjectResourceType;
|
|
|
|
ResourceContext *subjectContext;
|
|
|
|
uint32 subjectResourceId;
|
|
|
|
uint32 patchResourceId;
|
|
|
|
ResourceData *subjectResourceData;
|
|
|
|
byte *tableBuffer;
|
|
|
|
size_t tableSize;
|
|
|
|
bool isMacBinary;
|
|
|
|
|
|
|
|
if (!context->file->open(context->fileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->isBigEndian = _vm->isBigEndian();
|
|
|
|
|
|
|
|
isMacBinary = (context->fileType & GAME_MACBINARY) > 0;
|
|
|
|
context->fileType &= ~GAME_MACBINARY;
|
|
|
|
|
|
|
|
if (isMacBinary) {
|
|
|
|
if (!loadMacContext(context)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!loadSagaContext(context, 0, context->file->size())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-30 17:28:58 +00:00
|
|
|
//process internal patch files
|
|
|
|
if (GAME_PATCHFILE & context->fileType) {
|
|
|
|
subjectResourceType = ~GAME_PATCHFILE & context->fileType;
|
2005-08-04 10:23:49 +00:00
|
|
|
subjectContext = getContext((GameFileTypes)subjectResourceType);
|
2005-07-30 17:28:58 +00:00
|
|
|
if (subjectContext == NULL) {
|
|
|
|
error("Resource::loadContext() Subject context not found");
|
|
|
|
}
|
|
|
|
loadResource(context, context->count - 1, tableBuffer, tableSize);
|
|
|
|
|
|
|
|
MemoryReadStreamEndian readS2(tableBuffer, tableSize, context->isBigEndian);
|
|
|
|
for (i = 0; i < tableSize / 8; i++) {
|
|
|
|
subjectResourceId = readS2.readUint32();
|
|
|
|
patchResourceId = readS2.readUint32();
|
|
|
|
subjectResourceData = getResourceData(subjectContext, subjectResourceId);
|
|
|
|
resourceData = getResourceData(context, patchResourceId);
|
|
|
|
subjectResourceData->patchData = new PatchData(context->file);
|
|
|
|
subjectResourceData->offset = resourceData->offset;
|
|
|
|
subjectResourceData->size = resourceData->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//process external patch files
|
2005-08-04 10:23:49 +00:00
|
|
|
for (j = 0; j < _vm->getGameDescription()->patchsCount; j++) {
|
|
|
|
patchDescription = &_vm->getGameDescription()->patchDescriptions[j];
|
|
|
|
if ((patchDescription->fileType & context->fileType) != 0) {
|
|
|
|
if (patchDescription->resourceId < context->count) {
|
|
|
|
resourceData = &context->table[patchDescription->resourceId];
|
|
|
|
resourceData->patchData = new PatchData(patchDescription);
|
|
|
|
if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
|
|
|
|
resourceData->offset = 0;
|
|
|
|
resourceData->size = resourceData->patchData->_patchFile->size();
|
|
|
|
} else {
|
|
|
|
delete resourceData->patchData;
|
|
|
|
resourceData->patchData = NULL;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-08-04 10:23:49 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-04 10:23:49 +00:00
|
|
|
return true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
bool Resource::createContexts() {
|
2005-07-23 15:23:01 +00:00
|
|
|
int i;
|
2005-07-19 19:05:52 +00:00
|
|
|
ResourceContext *context;
|
|
|
|
_contextsCount = _vm->getGameDescription()->filesCount;
|
|
|
|
_contexts = (ResourceContext*)calloc(_contextsCount, sizeof(*_contexts));
|
|
|
|
|
|
|
|
for (i = 0; i < _contextsCount; i++) {
|
|
|
|
context = &_contexts[i];
|
|
|
|
context->file = new Common::File();
|
|
|
|
context->fileName = _vm->getGameDescription()->filesDescriptions[i].fileName;
|
|
|
|
context->fileType = _vm->getGameDescription()->filesDescriptions[i].fileType;
|
2005-07-23 15:23:01 +00:00
|
|
|
context->serial = 0;
|
|
|
|
|
|
|
|
// IHNM has serveral different voice files, so we need to allow
|
|
|
|
// multiple resource contexts of the same type. We tell them
|
|
|
|
// apart by assigning each of the duplicates an unique serial
|
|
|
|
// number. The default behaviour when requesting a context will
|
|
|
|
// be to look for serial number 0.
|
2005-07-19 19:05:52 +00:00
|
|
|
|
2005-07-23 15:23:01 +00:00
|
|
|
for (int j = i - 1; j >= 0; j--) {
|
|
|
|
if (_contexts[j].fileType & context->fileType) {
|
|
|
|
context->serial = _contexts[j].serial + 1;
|
|
|
|
break;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (!loadContext(context)) {
|
|
|
|
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() {
|
|
|
|
int i;
|
|
|
|
size_t j;
|
|
|
|
ResourceContext *context;
|
|
|
|
if (_contexts == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for(i = 0; i < _contextsCount; i++) {
|
|
|
|
context = &_contexts[i];
|
|
|
|
delete context->file;
|
|
|
|
if (context->table != NULL) {
|
|
|
|
for(j = 0; j < context->count; j++) {
|
2005-07-26 19:40:58 +00:00
|
|
|
delete context->table[j].patchData;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
2005-01-02 20:29:27 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
free(context->table);
|
2005-06-21 13:55:18 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
free(_contexts);
|
|
|
|
_contexts = NULL;
|
|
|
|
}
|
2005-01-02 20:29:27 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
uint32 Resource::convertResourceId(uint32 resourceId) {
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if ((_vm->getGameType() == GType_ITE) && (_vm->getFeatures() & GF_MAC_RESOURCES)) {
|
|
|
|
if (resourceId > 1537) {
|
|
|
|
return resourceId - 2;
|
2005-01-02 20:29:27 +00:00
|
|
|
} else {
|
2005-07-19 19:05:52 +00:00
|
|
|
if (resourceId == 1535 || resourceId == 1536) {
|
|
|
|
error ("Wrong resource number %d for Mac ITE", resourceId);
|
|
|
|
}
|
2005-01-02 20:29:27 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
return resourceId;
|
|
|
|
}
|
2004-04-12 21:40:49 +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
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceData = getResourceData(context, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 23:14:11 +00:00
|
|
|
static int metaResourceTable[] = { 0, 326, 517, 677, 805, 968, 1165, 0, 1271 };
|
|
|
|
|
|
|
|
void Resource::loadGlobalResources(int chapter, int actorsEntrance) {
|
2005-08-06 16:05:13 +00:00
|
|
|
if (chapter < 0)
|
|
|
|
chapter = 8;
|
|
|
|
|
2005-08-05 23:14:11 +00:00
|
|
|
// TODO
|
|
|
|
//if (module.voiceLUT)
|
|
|
|
// free module.voiceLUT;
|
|
|
|
|
|
|
|
// TODO: close chapeter context, or rather reassign it in our case
|
|
|
|
|
|
|
|
ResourceContext *resourceContext;
|
|
|
|
|
|
|
|
resourceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
|
|
|
|
if (resourceContext == NULL) {
|
|
|
|
error("Resource::loadGlobalResources() resource context not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *resourcePointer;
|
|
|
|
size_t resourceLength;
|
|
|
|
|
|
|
|
_vm->_resource->loadResource(resourceContext, metaResourceTable[chapter],
|
|
|
|
resourcePointer, resourceLength);
|
|
|
|
|
2005-08-06 18:28:43 +00:00
|
|
|
if (resourceLength == 0) {
|
|
|
|
error("Resource::loadGlobalResources wrong resource");
|
|
|
|
}
|
2005-08-05 23:14:11 +00:00
|
|
|
MemoryReadStream metaS(resourcePointer, resourceLength);
|
|
|
|
|
|
|
|
_metaResource.sceneIndex = metaS.readSint16LE();
|
|
|
|
_metaResource.obectCount = metaS.readSint16LE();
|
|
|
|
_metaResource.field_4 = metaS.readSint32LE();
|
|
|
|
_metaResource.field_8 = metaS.readSint32LE();
|
|
|
|
_metaResource.mainSpritesID = metaS.readSint32LE();
|
|
|
|
_metaResource.objectResourceID = metaS.readSint32LE();
|
|
|
|
_metaResource.actorCount = metaS.readSint16LE();
|
|
|
|
_metaResource.field_16 = metaS.readSint32LE();
|
|
|
|
_metaResource.actorsResourceID = metaS.readSint32LE();
|
|
|
|
_metaResource.protagFaceSpritesID = metaS.readSint32LE();
|
|
|
|
_metaResource.field_22 = metaS.readSint32LE();
|
|
|
|
_metaResource.field_26 = metaS.readSint16LE();
|
2005-08-06 14:26:59 +00:00
|
|
|
_metaResource.protagStatesCount = metaS.readSint16LE();
|
|
|
|
_metaResource.protagStatesResourceID = metaS.readSint32LE();
|
2005-08-05 23:14:11 +00:00
|
|
|
_metaResource.cutawayListResourceID = metaS.readSint32LE();
|
|
|
|
_metaResource.songTableID = metaS.readSint32LE();
|
|
|
|
|
|
|
|
free(resourcePointer);
|
2005-08-06 14:26:59 +00:00
|
|
|
|
|
|
|
_vm->_actor->loadList(actorsEntrance, _metaResource.actorCount,
|
|
|
|
_metaResource.actorsResourceID, _metaResource.protagStatesCount,
|
|
|
|
_metaResource.protagStatesResourceID);
|
2005-08-06 16:05:13 +00:00
|
|
|
|
|
|
|
_vm->_actor->_protagonist->sceneNumber = _metaResource.sceneIndex;
|
|
|
|
|
|
|
|
|
2005-08-05 23:14:11 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
} // End of namespace Saga
|