diff options
Diffstat (limited to 'engines/teenagent/resources.cpp')
| -rw-r--r-- | engines/teenagent/resources.cpp | 105 |
1 files changed, 75 insertions, 30 deletions
diff --git a/engines/teenagent/resources.cpp b/engines/teenagent/resources.cpp index 597ca670c0..442d0abf16 100644 --- a/engines/teenagent/resources.cpp +++ b/engines/teenagent/resources.cpp @@ -22,18 +22,15 @@ #include "teenagent/resources.h" #include "teenagent/teenagent.h" #include "common/textconsole.h" +#include "common/translation.h" #include "common/zlib.h" namespace TeenAgent { -Resources::Resources() {} - -Resources *Resources::instance() { - static Resources i; - return &i; +Resources::Resources() { } -void Resources::deinit() { +Resources::~Resources() { off.close(); on.close(); ons.close(); @@ -60,32 +57,80 @@ quick note on varia resources: 11: quit shareware */ +#define CSEG_SIZE 46000 // 0xb3b0 +#define DSEG_SIZE 59280 // 0xe790 +#define ESEG_SIZE 35810 // 0x8be2 + +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]); +} + bool Resources::loadArchives(const ADGameDescription *gd) { Common::File *dat_file = new Common::File(); if (!dat_file->open("teenagent.dat")) { delete dat_file; - Common::String errorMessage = "You're missing the 'teenagent.dat' file. Get it from the ScummVM website"; - GUIErrorMessage(errorMessage); + Common::String errorMessage = _("You're missing the 'teenagent.dat' file. Get it from the ScummVM website"); warning("%s", errorMessage.c_str()); + GUIErrorMessage(errorMessage); return false; } + + // 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. Common::SeekableReadStream *dat = Common::wrapCompressedReadStream(dat_file); - cseg.read(dat, 0xb3b0); - dseg.read(dat, 0xe790); - eseg.read(dat, 0x8be2); +#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; + Common::String errorMessage = _("The teenagent.dat file is compressed and zlib hasn't been included in this executable. Please decompress it"); + warning("%s", errorMessage.c_str()); + GUIErrorMessage(errorMessage); + return false; + } +#endif + + dat->skip(CSEG_SIZE); + dseg.read(dat, DSEG_SIZE); + eseg.read(dat, ESEG_SIZE); delete dat; - { - 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(); - } + precomputeDialogOffsets(); + + FilePack varia; + varia.open("varia.res"); + font7.load(varia, 7, 11, 1); + font8.load(varia, 8, 31, 0); + varia.close(); off.open("off.res"); on.open("on.res"); @@ -130,13 +175,13 @@ Common::SeekableReadStream *Resources::loadLan000(uint32 id) const { switch (id) { case 81: - if (dseg.get_byte(0xDBAD)) + if (dseg.get_byte(dsAddr_dogHasBoneFlag)) return lan500.getStream(160); break; case 137: - if (dseg.get_byte(0xDBC5) == 1) { - if (dseg.get_byte(0xDBC6) == 1) + if (dseg.get_byte(dsAddr_mansionTVOnFlag) == 1) { + if (dseg.get_byte(dsAddr_mansionVCRPlayingTapeFlag) == 1) return lan500.getStream(203); else return lan500.getStream(202); @@ -144,31 +189,31 @@ Common::SeekableReadStream *Resources::loadLan000(uint32 id) const { break; case 25: - if (dseg.get_byte(0xDBDF) == 2) { + if (dseg.get_byte(dsAddr_FirstActTrialState) == 2) { return lan500.getStream(332); } break; case 37: - if (dseg.get_byte(0xdbe2) == 1) { + if (dseg.get_byte(dsAddr_act1GuardState) == 1) { return lan500.getStream(351); - } else if (dseg.get_byte(0xdbe2) == 2) { + } else if (dseg.get_byte(dsAddr_act1GuardState) == 2) { return lan500.getStream(364); } break; case 29: - if (dseg.get_byte(0xDBE7) == 1) { + if (dseg.get_byte(dsAddr_birdOnBarRadioAntennaFlag) == 1) { return lan500.getStream(380); } case 30: - if (dseg.get_byte(0xDBE7) == 1) { + if (dseg.get_byte(dsAddr_birdOnBarRadioAntennaFlag) == 1) { return lan500.getStream(381); } case 42: - if (dseg.get_byte(0xDBEC) == 1) { + if (dseg.get_byte(dsAddr_johnNotyOutsideMansionDoorFlag) == 1) { return lan500.getStream(400); } } |
