2009-09-03 20:59:17 +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.
|
|
|
|
*/
|
|
|
|
|
2009-09-04 20:08:33 +00:00
|
|
|
#include "teenagent/resources.h"
|
|
|
|
#include "teenagent/teenagent.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2012-07-15 00:07:01 +00:00
|
|
|
#include "common/translation.h"
|
2009-09-05 08:16:35 +00:00
|
|
|
#include "common/zlib.h"
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-04 20:08:33 +00:00
|
|
|
namespace TeenAgent {
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2012-07-26 08:18:57 +00:00
|
|
|
Resources::Resources() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Resources::~Resources() {
|
2009-09-03 20:59:17 +00:00
|
|
|
off.close();
|
|
|
|
on.close();
|
|
|
|
ons.close();
|
|
|
|
lan000.close();
|
|
|
|
lan500.close();
|
|
|
|
mmm.close();
|
|
|
|
sam_mmm.close();
|
|
|
|
sam_sam.close();
|
2010-05-07 07:56:57 +00:00
|
|
|
voices.close();
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
/*
|
|
|
|
quick note on varia resources:
|
|
|
|
1: Mark's animations (with head)
|
|
|
|
2: Mark's idle animation
|
|
|
|
3: Inventory background
|
|
|
|
4: Inventory items
|
|
|
|
5: Metropolis palette
|
|
|
|
6: TEENAGENT logo (flames)
|
|
|
|
7: Small font
|
|
|
|
8: Bigger font
|
|
|
|
9: Metropolis software house
|
|
|
|
10: quit registered
|
|
|
|
11: quit shareware
|
|
|
|
*/
|
|
|
|
|
2012-07-05 10:43:49 +00:00
|
|
|
#define CSEG_SIZE 46000 // 0xb3b0
|
|
|
|
#define DSEG_SIZE 59280 // 0xe790
|
|
|
|
#define ESEG_SIZE 35810 // 0x8be2
|
|
|
|
|
2012-07-11 12:03:32 +00:00
|
|
|
void Resources::precomputeDialogOffsets() {
|
|
|
|
dialogOffsets.push_back(0);
|
|
|
|
int n = 0;
|
|
|
|
uint8 current, last = 0xff;
|
|
|
|
for (uint i = 0; i < eseg.size(); i++) {
|
|
|
|
current = eseg.get_byte(i);
|
|
|
|
|
|
|
|
if (n == 4) {
|
|
|
|
dialogOffsets.push_back(i);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current != 0x00 && last == 0x00)
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
if (current == 0x00)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
last = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(1, "Resources::precomputeDialogOffsets() - Found %d dialogs", dialogOffsets.size());
|
|
|
|
for (uint i = 0; i < dialogOffsets.size(); i++)
|
|
|
|
debug(1, "\tDialog #%d: Offset 0x%04x", i, dialogOffsets[i]);
|
|
|
|
}
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
bool Resources::loadArchives(const ADGameDescription *gd) {
|
2011-01-31 15:25:29 +00:00
|
|
|
Common::File *dat_file = new Common::File();
|
|
|
|
if (!dat_file->open("teenagent.dat")) {
|
|
|
|
delete dat_file;
|
2012-07-15 00:07:01 +00:00
|
|
|
Common::String errorMessage = _("You're missing the 'teenagent.dat' file. Get it from the ScummVM website");
|
2009-09-05 08:16:35 +00:00
|
|
|
warning("%s", errorMessage.c_str());
|
2012-07-15 00:07:01 +00:00
|
|
|
GUIErrorMessage(errorMessage);
|
2009-09-05 08:16:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-14 23:14:37 +00:00
|
|
|
|
2012-07-14 23:27:51 +00:00
|
|
|
// teenagent.dat used to be compressed with zlib compression. The usage of
|
|
|
|
// zlib here is no longer needed, and it's maintained only for backwards
|
|
|
|
// compatibility.
|
2011-01-31 15:25:29 +00:00
|
|
|
Common::SeekableReadStream *dat = Common::wrapCompressedReadStream(dat_file);
|
2012-07-14 23:47:06 +00:00
|
|
|
|
|
|
|
#if !defined(USE_ZLIB)
|
|
|
|
uint16 header = dat->readUint16BE();
|
|
|
|
bool isCompressed = (header == 0x1F8B ||
|
|
|
|
((header & 0x0F00) == 0x0800 &&
|
|
|
|
header % 31 == 0));
|
|
|
|
dat->seek(-2, SEEK_CUR);
|
|
|
|
|
|
|
|
if (isCompressed) {
|
|
|
|
// teenagent.dat is compressed, but zlib hasn't been compiled in
|
|
|
|
delete dat;
|
2012-07-15 00:07:01 +00:00
|
|
|
Common::String errorMessage = _("The teenagent.dat file is compressed and zlib hasn't been included in this executable. Please decompress it");
|
2012-07-14 23:47:06 +00:00
|
|
|
warning("%s", errorMessage.c_str());
|
2012-07-15 00:07:01 +00:00
|
|
|
GUIErrorMessage(errorMessage);
|
2012-07-14 23:47:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-05 10:43:49 +00:00
|
|
|
cseg.read(dat, CSEG_SIZE);
|
|
|
|
dseg.read(dat, DSEG_SIZE);
|
|
|
|
eseg.read(dat, ESEG_SIZE);
|
2011-01-31 15:25:29 +00:00
|
|
|
delete dat;
|
2009-09-05 08:16:35 +00:00
|
|
|
|
2012-07-11 12:03:32 +00:00
|
|
|
precomputeDialogOffsets();
|
|
|
|
|
2012-07-07 12:46:28 +00:00
|
|
|
FilePack varia;
|
|
|
|
varia.open("varia.res");
|
|
|
|
font7.load(varia, 7);
|
|
|
|
font7.width_pack = 1;
|
|
|
|
font7.height = 11;
|
|
|
|
font8.load(varia, 8);
|
|
|
|
font8.height = 31;
|
|
|
|
varia.close();
|
2010-03-18 23:24:32 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
off.open("off.res");
|
|
|
|
on.open("on.res");
|
|
|
|
ons.open("ons.res");
|
|
|
|
lan000.open("lan_000.res");
|
|
|
|
lan500.open("lan_500.res");
|
|
|
|
mmm.open("mmm.res");
|
|
|
|
sam_mmm.open("sam_mmm.res");
|
|
|
|
sam_sam.open("sam_sam.res");
|
2010-05-07 07:56:57 +00:00
|
|
|
voices.open("voices.res");
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-05 08:16:35 +00:00
|
|
|
return true;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
void Resources::loadOff(Graphics::Surface &surface, byte *palette, int id) {
|
2010-03-18 23:30:29 +00:00
|
|
|
uint32 size = off.getSize(id);
|
2009-09-03 20:59:17 +00:00
|
|
|
if (size == 0) {
|
|
|
|
error("invalid background %d", id);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-04 21:01:39 +00:00
|
|
|
|
|
|
|
const uint bufferSize = 64768;
|
|
|
|
byte *buf = (byte *)malloc(bufferSize);
|
|
|
|
if (!buf)
|
|
|
|
error("[Resources::loadOff] Cannot allocate buffer");
|
|
|
|
|
|
|
|
off.read(id, buf, bufferSize);
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
byte *src = buf;
|
|
|
|
byte *dst = (byte *)surface.pixels;
|
2009-09-03 20:59:17 +00:00
|
|
|
memcpy(dst, src, 64000);
|
|
|
|
memcpy(palette, buf + 64000, 768);
|
2011-06-04 21:01:39 +00:00
|
|
|
|
|
|
|
free(buf);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Common::SeekableReadStream *Resources::loadLan(uint32 id) const {
|
2009-09-15 08:54:06 +00:00
|
|
|
return id <= 500 ? loadLan000(id) : lan500.getStream(id - 500);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Common::SeekableReadStream *Resources::loadLan000(uint32 id) const {
|
2009-09-15 08:54:06 +00:00
|
|
|
switch (id) {
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
case 81:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbad))
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(160);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 137:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbc5) == 1) {
|
|
|
|
if (dseg.get_byte(0xdbc6) == 1)
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(203);
|
2009-09-15 08:54:06 +00:00
|
|
|
else
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(202);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-15 08:54:06 +00:00
|
|
|
case 25:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbdf) == 2) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(332);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-15 08:54:06 +00:00
|
|
|
case 37:
|
2009-09-03 20:59:17 +00:00
|
|
|
if (dseg.get_byte(0xdbe2) == 1) {
|
|
|
|
return lan500.getStream(351);
|
|
|
|
} else if (dseg.get_byte(0xdbe2) == 2) {
|
|
|
|
return lan500.getStream(364);
|
|
|
|
}
|
|
|
|
break;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
case 29:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbe7) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(380);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 30:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbe7) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(381);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 42:
|
2012-07-12 20:03:47 +00:00
|
|
|
if (dseg.get_byte(0xdbec) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lan000.getStream(id);
|
|
|
|
}
|
2009-09-04 20:08:33 +00:00
|
|
|
|
|
|
|
} // End of namespace TeenAgent
|