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.
|
2014-02-18 01:34:25 +00:00
|
|
|
*
|
2009-09-03 20:59:17 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-04 20:08:33 +00:00
|
|
|
#include "teenagent/resources.h"
|
|
|
|
#include "teenagent/teenagent.h"
|
2016-04-14 13:10:21 +00:00
|
|
|
#include "common/debug.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();
|
2016-12-05 14:29:23 +00:00
|
|
|
Common::String filename = "teenagent.dat";
|
|
|
|
if (!dat_file->open(filename.c_str())) {
|
2011-01-31 15:25:29 +00:00
|
|
|
delete dat_file;
|
2020-08-21 13:18:56 +00:00
|
|
|
|
|
|
|
const char *msg = _s("Unable to locate the '%s' engine data file.");
|
|
|
|
Common::U32String errorMessage = Common::U32String::format(_(msg), filename.c_str());
|
|
|
|
warning(msg, filename.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;
|
2020-08-21 13:18:56 +00:00
|
|
|
|
|
|
|
const char *msg = _s("The teenagent.dat file is compressed and zlib hasn't been included in this executable. Please decompress it");
|
|
|
|
Common::U32String errorMessage = _(msg);
|
|
|
|
warning(msg);
|
2012-07-15 00:07:01 +00:00
|
|
|
GUIErrorMessage(errorMessage);
|
2012-07-14 23:47:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-02 03:56:20 +00:00
|
|
|
dat->skip(CSEG_SIZE);
|
2012-07-05 10:43:49 +00:00
|
|
|
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");
|
2012-09-24 00:22:08 +00:00
|
|
|
font7.load(varia, 7, 11, 1);
|
|
|
|
font8.load(varia, 8, 31, 0);
|
2012-07-07 12:46:28 +00:00
|
|
|
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;
|
2013-08-03 00:42:42 +00:00
|
|
|
byte *dst = (byte *)surface.getPixels();
|
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-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_dogHasBoneFlag))
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(160);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 137:
|
2012-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_mansionTVOnFlag) == 1) {
|
|
|
|
if (dseg.get_byte(dsAddr_mansionVCRPlayingTapeFlag) == 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-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_FirstActTrialState) == 2) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(332);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-15 08:54:06 +00:00
|
|
|
case 37:
|
2012-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_act1GuardState) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(351);
|
2012-08-01 13:44:51 +00:00
|
|
|
} else if (dseg.get_byte(dsAddr_act1GuardState) == 2) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(364);
|
|
|
|
}
|
|
|
|
break;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
case 29:
|
2012-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_birdOnBarRadioAntennaFlag) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(380);
|
|
|
|
}
|
2013-07-19 18:49:15 +00:00
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
case 30:
|
2012-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_birdOnBarRadioAntennaFlag) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(381);
|
|
|
|
}
|
2013-07-19 18:49:15 +00:00
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
case 42:
|
2012-08-01 13:44:51 +00:00
|
|
|
if (dseg.get_byte(dsAddr_johnNotyOutsideMansionDoorFlag) == 1) {
|
2009-09-03 20:59:17 +00:00
|
|
|
return lan500.getStream(400);
|
|
|
|
}
|
2013-07-19 18:49:15 +00:00
|
|
|
break;
|
2019-11-14 03:28:11 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
return lan000.getStream(id);
|
|
|
|
}
|
2009-09-04 20:08:33 +00:00
|
|
|
|
|
|
|
} // End of namespace TeenAgent
|