2008-04-20 14:43:56 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/endian.h"
|
2008-04-23 17:21:49 +00:00
|
|
|
#include "sound/mixer.h"
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
#include "made/resource.h"
|
|
|
|
#include "made/graphics.h"
|
|
|
|
#include "made/sound.h"
|
|
|
|
|
|
|
|
namespace Made {
|
|
|
|
|
|
|
|
/* Resource */
|
|
|
|
|
|
|
|
Resource::~Resource() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PictureResource */
|
|
|
|
|
2008-04-21 20:20:34 +00:00
|
|
|
PictureResource::PictureResource() : _picture(NULL), _picturePalette(NULL) {
|
|
|
|
_hasPalette = false;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PictureResource::~PictureResource() {
|
2008-04-21 20:20:34 +00:00
|
|
|
if (_picture) {
|
2008-04-20 15:36:40 +00:00
|
|
|
delete _picture;
|
2008-04-21 20:20:34 +00:00
|
|
|
_picture = 0;
|
|
|
|
}
|
|
|
|
if (_picturePalette) {
|
|
|
|
delete[] _picturePalette;
|
|
|
|
_picturePalette = 0;
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PictureResource::load(byte *source, int size) {
|
2009-01-22 13:04:29 +00:00
|
|
|
if (READ_BE_UINT32(source) == MKID_BE('Flex')) {
|
|
|
|
loadChunked(source, size);
|
|
|
|
} else {
|
|
|
|
loadRaw(source, size);
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2009-01-22 13:04:29 +00:00
|
|
|
void PictureResource::loadRaw(byte *source, int size) {
|
|
|
|
// Loads a "raw" picture as used in RtZ, LGoP2, Manhole:N&E and Rodney's Funscreen
|
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-21 20:20:34 +00:00
|
|
|
_hasPalette = (sourceS->readByte() != 0);
|
2008-05-26 11:07:18 +00:00
|
|
|
byte cmdFlags = sourceS->readByte();
|
|
|
|
byte pixelFlags = sourceS->readByte();
|
|
|
|
byte maskFlags = sourceS->readByte();
|
2008-04-20 14:43:56 +00:00
|
|
|
uint16 cmdOffs = sourceS->readUint16LE();
|
|
|
|
uint16 pixelOffs = sourceS->readUint16LE();
|
|
|
|
uint16 maskOffs = sourceS->readUint16LE();
|
|
|
|
uint16 lineSize = sourceS->readUint16LE();
|
2008-04-20 17:15:31 +00:00
|
|
|
/*uint16 u = */sourceS->readUint16LE();
|
2008-04-20 14:43:56 +00:00
|
|
|
uint16 width = sourceS->readUint16LE();
|
|
|
|
uint16 height = sourceS->readUint16LE();
|
2008-05-26 11:07:18 +00:00
|
|
|
|
|
|
|
if (cmdFlags || pixelFlags || maskFlags) {
|
2009-01-22 13:04:29 +00:00
|
|
|
warning("PictureResource::loadRaw() Graphic has flags set (%d, %d, %d)", cmdFlags, pixelFlags, maskFlags);
|
2008-05-26 11:07:18 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 20:12:06 +00:00
|
|
|
_paletteColorCount = (cmdOffs - 18) / 3; // 18 = sizeof header
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
debug(2, "width = %d; height = %d\n", width, height);
|
|
|
|
|
2008-04-21 20:20:34 +00:00
|
|
|
if (_hasPalette) {
|
2008-04-23 20:12:06 +00:00
|
|
|
_picturePalette = new byte[_paletteColorCount * 3];
|
|
|
|
sourceS->read(_picturePalette, _paletteColorCount * 3);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_picture = new Graphics::Surface();
|
|
|
|
_picture->create(width, height, 1);
|
|
|
|
|
2008-05-26 11:07:18 +00:00
|
|
|
decompressImage(source, *_picture, cmdOffs, pixelOffs, maskOffs, lineSize, cmdFlags, pixelFlags, maskFlags);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
delete sourceS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-22 13:04:29 +00:00
|
|
|
void PictureResource::loadChunked(byte *source, int size) {
|
|
|
|
// Loads a "chunked" picture as used in Manhole EGA
|
|
|
|
|
|
|
|
Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size);
|
|
|
|
|
2009-01-22 19:09:05 +00:00
|
|
|
byte cmdFlags = 0, pixelFlags = 0, maskFlags = 0;
|
2009-01-22 13:04:29 +00:00
|
|
|
uint16 cmdOffs = 0, pixelOffs = 0, maskOffs = 0;
|
|
|
|
uint16 lineSize = 0, width = 0, height = 0;
|
|
|
|
|
|
|
|
sourceS->skip(36); // skip the "Flex" header
|
|
|
|
|
|
|
|
_hasPalette = false;
|
|
|
|
|
|
|
|
while (!sourceS->eos()) {
|
|
|
|
|
|
|
|
uint32 chunkType = sourceS->readUint32BE();
|
|
|
|
uint32 chunkSize = sourceS->readUint32BE();
|
|
|
|
|
|
|
|
if (sourceS->eos())
|
|
|
|
break;
|
|
|
|
|
|
|
|
debug(0, "chunkType = %08X; chunkSize = %d", chunkType, chunkSize);
|
|
|
|
|
|
|
|
if (chunkType == MKID_BE('Rect')) {
|
|
|
|
debug(0, "Rect");
|
|
|
|
sourceS->skip(4);
|
|
|
|
height = sourceS->readUint16BE();
|
|
|
|
width = sourceS->readUint16BE();
|
|
|
|
debug(0, "width = %d; height = %d", width, height);
|
|
|
|
} else if (chunkType == MKID_BE('fMap')) {
|
|
|
|
debug(0, "fMap");
|
|
|
|
lineSize = sourceS->readUint16BE();
|
|
|
|
sourceS->skip(11);
|
|
|
|
cmdFlags = sourceS->readByte();
|
|
|
|
cmdOffs = sourceS->pos();
|
|
|
|
sourceS->skip(chunkSize - 14);
|
|
|
|
debug(0, "lineSize = %d; cmdFlags = %d; cmdOffs = %04X", lineSize, cmdFlags, cmdOffs);
|
|
|
|
} else if (chunkType == MKID_BE('fLCo')) {
|
|
|
|
debug(0, "fLCo");
|
|
|
|
sourceS->skip(9);
|
|
|
|
pixelFlags = sourceS->readByte();
|
|
|
|
pixelOffs = sourceS->pos();
|
|
|
|
sourceS->skip(chunkSize - 10);
|
|
|
|
debug(0, "pixelFlags = %d; pixelOffs = %04X", pixelFlags, pixelOffs);
|
|
|
|
} else if (chunkType == MKID_BE('fPix')) {
|
|
|
|
debug(0, "fPix");
|
|
|
|
sourceS->skip(9);
|
|
|
|
maskFlags = sourceS->readByte();
|
|
|
|
maskOffs = sourceS->pos();
|
|
|
|
sourceS->skip(chunkSize - 10);
|
|
|
|
debug(0, "maskFlags = %d; maskOffs = %04X", maskFlags, maskOffs);
|
|
|
|
} else if (chunkType == MKID_BE('fGCo')) {
|
|
|
|
debug(0, "fGCo");
|
|
|
|
_hasPalette = true;
|
|
|
|
_paletteColorCount = chunkSize / 3;
|
|
|
|
_picturePalette = new byte[_paletteColorCount * 3];
|
|
|
|
sourceS->read(_picturePalette, _paletteColorCount * 3);
|
|
|
|
} else {
|
|
|
|
error("PictureResource::loadChunked() Invalid chunk %08X at %08X", chunkType, sourceS->pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cmdOffs || !pixelOffs /*|| !maskOffs*/ || !lineSize || !width || !height) {
|
|
|
|
error("PictureResource::loadChunked() Error parsing the picture data, one or more chunks/parameters are missing");
|
|
|
|
}
|
|
|
|
|
|
|
|
_picture = new Graphics::Surface();
|
|
|
|
_picture->create(width, height, 1);
|
|
|
|
|
|
|
|
decompressImage(source, *_picture, cmdOffs, pixelOffs, maskOffs, lineSize, cmdFlags, pixelFlags, maskFlags);
|
|
|
|
|
|
|
|
delete sourceS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
/* AnimationResource */
|
|
|
|
|
|
|
|
AnimationResource::AnimationResource() {
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationResource::~AnimationResource() {
|
2008-05-20 19:56:49 +00:00
|
|
|
for (uint i = 0; i < _frames.size(); i++)
|
|
|
|
delete _frames[i];
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationResource::load(byte *source, int size) {
|
|
|
|
Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size);
|
|
|
|
|
|
|
|
sourceS->readUint32LE();
|
|
|
|
sourceS->readUint32LE();
|
|
|
|
sourceS->readUint16LE();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
_flags = sourceS->readUint16LE();
|
|
|
|
_width = sourceS->readUint16LE();
|
|
|
|
_height = sourceS->readUint16LE();
|
|
|
|
sourceS->readUint32LE();
|
|
|
|
uint16 frameCount = sourceS->readUint16LE();
|
|
|
|
sourceS->readUint16LE();
|
|
|
|
sourceS->readUint16LE();
|
|
|
|
|
|
|
|
for (uint16 i = 0; i < frameCount; i++) {
|
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
sourceS->seek(26 + i * 4);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
uint32 frameOffs = sourceS->readUint32LE();
|
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
sourceS->seek(frameOffs);
|
2008-04-20 14:43:56 +00:00
|
|
|
sourceS->readUint32LE();
|
|
|
|
sourceS->readUint32LE();
|
|
|
|
|
|
|
|
uint16 frameWidth = sourceS->readUint16LE();
|
|
|
|
uint16 frameHeight = sourceS->readUint16LE();
|
|
|
|
uint16 cmdOffs = sourceS->readUint16LE();
|
|
|
|
sourceS->readUint16LE();
|
|
|
|
uint16 pixelOffs = sourceS->readUint16LE();
|
|
|
|
sourceS->readUint16LE();
|
|
|
|
uint16 maskOffs = sourceS->readUint16LE();
|
|
|
|
sourceS->readUint16LE();
|
|
|
|
uint16 lineSize = sourceS->readUint16LE();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
Graphics::Surface *frame = new Graphics::Surface();
|
|
|
|
frame->create(frameWidth, frameHeight, 1);
|
|
|
|
|
2008-05-26 11:07:18 +00:00
|
|
|
decompressImage(source + frameOffs, *frame, cmdOffs, pixelOffs, maskOffs, lineSize, 0, 0, 0, _flags & 1);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
_frames.push_back(frame);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete sourceS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SoundResource */
|
|
|
|
|
|
|
|
SoundResource::SoundResource() : _soundSize(0), _soundData(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundResource::~SoundResource() {
|
2009-01-13 16:18:22 +00:00
|
|
|
delete[] _soundData;
|
|
|
|
delete _soundEnergyArray;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundResource::load(byte *source, int size) {
|
|
|
|
uint16 chunkCount = READ_LE_UINT16(source + 8);
|
|
|
|
uint16 chunkSize = READ_LE_UINT16(source + 12);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
_soundSize = chunkCount * chunkSize;
|
2008-04-20 15:36:40 +00:00
|
|
|
_soundData = new byte[_soundSize];
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2009-01-13 16:18:22 +00:00
|
|
|
_soundEnergyArray = new SoundEnergyArray;
|
|
|
|
|
|
|
|
decompressSound(source + 14, _soundData, chunkSize, chunkCount, _soundEnergyArray);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 17:21:49 +00:00
|
|
|
Audio::AudioStream *SoundResource::getAudioStream(int soundRate, bool loop) {
|
|
|
|
byte flags = Audio::Mixer::FLAG_UNSIGNED;
|
2009-01-01 15:06:43 +00:00
|
|
|
if (loop)
|
2008-04-23 17:21:49 +00:00
|
|
|
flags |= Audio::Mixer::FLAG_LOOP;
|
|
|
|
|
|
|
|
return Audio::makeLinearInputStream(_soundData, _soundSize, soundRate, flags, 0, 0);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void SoundResourceV1::load(byte *source, int size) {
|
2009-01-25 01:58:16 +00:00
|
|
|
_soundSize = size * 4;
|
2009-01-16 23:20:17 +00:00
|
|
|
_soundData = new byte[_soundSize];
|
2009-01-25 01:58:16 +00:00
|
|
|
ManholeEgaSoundDecompressor dec;
|
|
|
|
dec.decompress(source, _soundData, size);
|
2009-01-16 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
/* MenuResource */
|
|
|
|
|
|
|
|
MenuResource::MenuResource() {
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuResource::~MenuResource() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuResource::load(byte *source, int size) {
|
2008-04-20 15:36:40 +00:00
|
|
|
_strings.clear();
|
|
|
|
Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size);
|
|
|
|
sourceS->skip(4); // skip "MENU"
|
|
|
|
uint16 count = sourceS->readUint16LE();
|
|
|
|
for (uint16 i = 0; i < count; i++) {
|
|
|
|
uint16 offs = sourceS->readUint16LE();
|
|
|
|
const char *string = (const char*)(source + offs);
|
|
|
|
_strings.push_back(string);
|
|
|
|
debug(2, "%02d: %s\n", i, string);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
fflush(stdout);
|
2008-04-20 15:36:40 +00:00
|
|
|
delete sourceS;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 20:56:10 +00:00
|
|
|
const char *MenuResource::getString(uint index) const {
|
2008-04-23 20:12:06 +00:00
|
|
|
if (index < _strings.size())
|
|
|
|
return _strings[index].c_str();
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-25 11:05:56 +00:00
|
|
|
/* FontResource */
|
2008-04-23 23:22:02 +00:00
|
|
|
|
2008-04-25 11:05:56 +00:00
|
|
|
FontResource::FontResource() : _data(NULL), _size(0) {
|
2008-04-23 23:22:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-25 11:05:56 +00:00
|
|
|
FontResource::~FontResource() {
|
2008-04-23 23:22:02 +00:00
|
|
|
if (_data)
|
|
|
|
delete[] _data;
|
|
|
|
}
|
|
|
|
|
2008-04-25 11:05:56 +00:00
|
|
|
void FontResource::load(byte *source, int size) {
|
2008-04-23 23:22:02 +00:00
|
|
|
_data = new byte[size];
|
|
|
|
_size = size;
|
|
|
|
memcpy(_data, source, size);
|
|
|
|
}
|
|
|
|
|
2008-04-25 11:05:56 +00:00
|
|
|
int FontResource::getHeight() const {
|
|
|
|
return _data[0];
|
|
|
|
}
|
2008-04-24 18:45:11 +00:00
|
|
|
|
2008-04-28 10:56:21 +00:00
|
|
|
int FontResource::getCharWidth(uint c) const {
|
2008-04-25 11:05:56 +00:00
|
|
|
byte *charData = getCharData(c);
|
|
|
|
if (charData)
|
|
|
|
return charData[0];
|
|
|
|
else
|
|
|
|
return 0;
|
2008-04-24 18:45:11 +00:00
|
|
|
}
|
|
|
|
|
2008-04-28 10:56:21 +00:00
|
|
|
byte *FontResource::getChar(uint c) const {
|
2008-04-25 11:05:56 +00:00
|
|
|
byte *charData = getCharData(c);
|
|
|
|
if (charData)
|
|
|
|
return charData + 1;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-28 10:56:21 +00:00
|
|
|
int FontResource::getTextWidth(const char *text) {
|
|
|
|
int width = 0;
|
|
|
|
if (text) {
|
|
|
|
int len = strlen(text);
|
|
|
|
for (int pos = 0; pos < len; pos++)
|
|
|
|
width += getCharWidth(text[pos]);
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *FontResource::getCharData(uint c) const {
|
2008-04-25 11:05:56 +00:00
|
|
|
if (c < 28 || c > 255)
|
|
|
|
return NULL;
|
|
|
|
return _data + 1 + (c - 28) * (getHeight() + 1);
|
|
|
|
}
|
|
|
|
|
2008-05-05 10:45:11 +00:00
|
|
|
/* GenericResource */
|
2008-04-25 11:05:56 +00:00
|
|
|
|
2008-05-05 10:45:11 +00:00
|
|
|
GenericResource::GenericResource() : _data(NULL), _size(0) {
|
2008-04-25 11:05:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 10:45:11 +00:00
|
|
|
GenericResource::~GenericResource() {
|
2008-04-24 18:45:11 +00:00
|
|
|
if (_data)
|
|
|
|
delete[] _data;
|
|
|
|
}
|
|
|
|
|
2008-05-05 10:45:11 +00:00
|
|
|
void GenericResource::load(byte *source, int size) {
|
2008-04-24 18:45:11 +00:00
|
|
|
_data = new byte[size];
|
|
|
|
_size = size;
|
|
|
|
memcpy(_data, source, size);
|
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
/* ResourceReader */
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
ResourceReader::ResourceReader() {
|
|
|
|
_isV1 = false;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
ResourceReader::~ResourceReader() {
|
|
|
|
if (!_isV1) {
|
|
|
|
delete _fd;
|
|
|
|
} else {
|
|
|
|
delete _fdPics;
|
|
|
|
delete _fdSounds;
|
|
|
|
delete _fdMusic;
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
// V2
|
|
|
|
void ResourceReader::open(const char *filename) {
|
2008-04-20 15:36:40 +00:00
|
|
|
_fd = new Common::File();
|
|
|
|
_fd->open(filename);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
_fd->skip(0x18); // skip header for now
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
uint16 indexCount = _fd->readUint16LE();
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
for (uint16 i = 0; i < indexCount; i++) {
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
uint32 resType = _fd->readUint32BE();
|
|
|
|
uint32 indexOffs = _fd->readUint32LE();
|
|
|
|
_fd->readUint32LE();
|
|
|
|
_fd->readUint32LE();
|
|
|
|
_fd->readUint32LE();
|
|
|
|
_fd->readUint16LE();
|
|
|
|
_fd->readUint16LE();
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
// We don't need ARCH, FREE and OMNI resources
|
|
|
|
if (resType == kResARCH || resType == kResFREE || resType == kResOMNI)
|
|
|
|
continue;
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
//debug(2, "resType = %08X; indexOffs = %d\n", resType, indexOffs);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
uint32 oldOffs = _fd->pos();
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
ResourceSlots *resSlots = new ResourceSlots();
|
|
|
|
_fd->seek(indexOffs);
|
|
|
|
loadIndex(resSlots);
|
|
|
|
_resSlots[resType] = resSlots;
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
_fd->seek(oldOffs);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
_cacheCount = 0;
|
2009-01-16 23:20:17 +00:00
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
// V1
|
|
|
|
void ResourceReader::openResourceBlocks() {
|
|
|
|
_isV1 = true;
|
|
|
|
_fdPics = new Common::File();
|
|
|
|
_fdSounds = new Common::File();
|
|
|
|
_fdMusic = new Common::File();
|
|
|
|
|
|
|
|
openResourceBlock("pics.blk", _fdPics, kResFLEX);
|
|
|
|
openResourceBlock("snds.blk", _fdSounds, kResSNDS);
|
|
|
|
openResourceBlock("music.blk", _fdMusic, kResMIDI);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::openResourceBlock(const char *filename, Common::File *blockFile, uint32 resType) {
|
|
|
|
blockFile->open(filename);
|
|
|
|
|
|
|
|
blockFile->readUint16LE(); // Skip unused
|
|
|
|
uint16 count = blockFile->readUint16LE();
|
|
|
|
blockFile->readUint16LE(); // Skip unused
|
|
|
|
uint32 type = blockFile->readUint32BE();
|
|
|
|
if (type != kResFLEX)
|
|
|
|
warning("openResourceBlocks: resource header is not 'FLEX'");
|
|
|
|
|
|
|
|
_resSlots[resType] = new ResourceSlots();
|
|
|
|
|
2009-01-22 13:04:29 +00:00
|
|
|
// Add dummy entry since the resources are 1-based
|
|
|
|
_resSlots[resType]->push_back(ResourceSlot(0, 0));
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
for (uint16 i = 0; i < count; i++) {
|
|
|
|
uint32 offset = blockFile->readUint32LE();
|
|
|
|
blockFile->readUint32LE();
|
|
|
|
uint32 size = blockFile->readUint32LE();
|
|
|
|
_resSlots[resType]->push_back(ResourceSlot(offset, size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PictureResource *ResourceReader::getPicture(int index) {
|
2008-04-20 15:36:40 +00:00
|
|
|
return createResource<PictureResource>(kResFLEX, index);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
AnimationResource *ResourceReader::getAnimation(int index) {
|
2008-04-20 15:36:40 +00:00
|
|
|
return createResource<AnimationResource>(kResANIM, index);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
SoundResource *ResourceReader::getSound(int index) {
|
|
|
|
if (!_isV1)
|
|
|
|
return createResource<SoundResource>(kResSNDS, index);
|
|
|
|
else
|
|
|
|
return createResource<SoundResourceV1>(kResSNDS, index);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
MenuResource *ResourceReader::getMenu(int index) {
|
2008-04-20 15:36:40 +00:00
|
|
|
return createResource<MenuResource>(kResMENU, index);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
FontResource *ResourceReader::getFont(int index) {
|
2008-04-24 18:45:11 +00:00
|
|
|
return createResource<FontResource>(kResFONT, index);
|
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
GenericResource *ResourceReader::getXmidi(int index) {
|
2008-05-05 10:45:11 +00:00
|
|
|
return createResource<GenericResource>(kResXMID, index);
|
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
GenericResource *ResourceReader::getMidi(int index) {
|
2008-05-05 10:45:11 +00:00
|
|
|
return createResource<GenericResource>(kResMIDI, index);
|
2008-04-25 11:05:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::loadIndex(ResourceSlots *slots) {
|
2008-04-20 15:36:40 +00:00
|
|
|
_fd->readUint32LE(); // skip INDX
|
|
|
|
_fd->readUint32LE(); // skip index size
|
|
|
|
_fd->readUint32LE(); // skip unknown
|
|
|
|
_fd->readUint32LE(); // skip res type
|
|
|
|
uint16 count = _fd->readUint16LE();
|
|
|
|
_fd->readUint16LE(); // skip unknown count
|
|
|
|
_fd->readUint16LE(); // skip unknown count
|
|
|
|
for (uint16 i = 0; i < count; i++) {
|
|
|
|
uint32 offs = _fd->readUint32LE();
|
|
|
|
uint32 size = _fd->readUint32LE();
|
|
|
|
slots->push_back(ResourceSlot(offs, size));
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::freeResource(Resource *resource) {
|
2008-04-20 15:36:40 +00:00
|
|
|
tossResourceFromCache(resource->slot);
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
bool ResourceReader::loadResource(ResourceSlot *slot, byte *&buffer, uint32 &size) {
|
|
|
|
int offset = !_isV1 ? 62 : 0;
|
2008-04-20 14:43:56 +00:00
|
|
|
if (slot && slot->size > 0) {
|
2009-01-16 23:20:17 +00:00
|
|
|
size = slot->size - offset;
|
2008-04-20 15:36:40 +00:00
|
|
|
buffer = new byte[size];
|
2009-01-16 23:20:17 +00:00
|
|
|
debug(2, "ResourceReader::loadResource() %08X", slot->offs + offset);
|
|
|
|
_fd->seek(slot->offs + offset);
|
2008-04-20 15:36:40 +00:00
|
|
|
_fd->read(buffer, size);
|
|
|
|
return true;
|
2008-04-20 14:43:56 +00:00
|
|
|
} else {
|
2008-04-20 15:36:40 +00:00
|
|
|
return false;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
ResourceSlot *ResourceReader::getResourceSlot(uint32 resType, uint index) {
|
2008-04-20 15:36:40 +00:00
|
|
|
ResourceSlots *slots = _resSlots[resType];
|
|
|
|
if (index >= 1 && index < slots->size()) {
|
2008-05-09 07:22:22 +00:00
|
|
|
return &slots->operator[](index);
|
2008-04-20 14:43:56 +00:00
|
|
|
} else {
|
2008-04-20 15:36:40 +00:00
|
|
|
return NULL;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
Resource *ResourceReader::getResourceFromCache(ResourceSlot *slot) {
|
2008-04-20 15:36:40 +00:00
|
|
|
if (slot->res)
|
|
|
|
slot->refCount++;
|
|
|
|
return slot->res;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::addResourceToCache(ResourceSlot *slot, Resource *res) {
|
2008-05-09 07:22:22 +00:00
|
|
|
if (_cacheCount >= kMaxResourceCacheCount)
|
2008-04-20 15:36:40 +00:00
|
|
|
purgeCache();
|
|
|
|
slot->res = res;
|
2008-05-09 07:22:22 +00:00
|
|
|
slot->refCount = 1;
|
2008-04-20 15:36:40 +00:00
|
|
|
_cacheCount++;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::tossResourceFromCache(ResourceSlot *slot) {
|
2008-05-09 07:22:22 +00:00
|
|
|
if (slot->res)
|
2008-04-20 15:36:40 +00:00
|
|
|
slot->refCount--;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 23:20:17 +00:00
|
|
|
void ResourceReader::purgeCache() {
|
|
|
|
debug(2, "ResourceReader::purgeCache()");
|
2008-04-20 15:36:40 +00:00
|
|
|
for (ResMap::const_iterator resTypeIter = _resSlots.begin(); resTypeIter != _resSlots.end(); ++resTypeIter) {
|
|
|
|
ResourceSlots *slots = (*resTypeIter)._value;
|
|
|
|
for (ResourceSlots::iterator slotIter = slots->begin(); slotIter != slots->end(); ++slotIter) {
|
|
|
|
ResourceSlot *slot = &(*slotIter);
|
|
|
|
if (slot->refCount <= 0 && slot->res) {
|
|
|
|
delete slot->res;
|
|
|
|
slot->res = NULL;
|
|
|
|
slot->refCount = 0;
|
|
|
|
_cacheCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Made
|