diff options
-rw-r--r-- | engines/macventure/hufflists.h | 57 | ||||
-rw-r--r-- | engines/macventure/macventure.cpp | 21 | ||||
-rw-r--r-- | engines/macventure/macventure.h | 5 | ||||
-rw-r--r-- | engines/macventure/module.mk | 1 | ||||
-rw-r--r-- | engines/macventure/text.cpp | 146 | ||||
-rw-r--r-- | engines/macventure/text.h | 56 | ||||
-rw-r--r-- | engines/macventure/world.cpp | 7 | ||||
-rw-r--r-- | engines/macventure/world.h | 2 |
8 files changed, 287 insertions, 8 deletions
diff --git a/engines/macventure/hufflists.h b/engines/macventure/hufflists.h new file mode 100644 index 0000000000..1ea4f21535 --- /dev/null +++ b/engines/macventure/hufflists.h @@ -0,0 +1,57 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_HUFFLIST_H +#define MACVENTURE_HUFFLIST_H + +namespace MacVenture { + +// The engine uses a <= comparison instead of ==, so I can't use Common::Huffman +class HuffmanLists { +public: + HuffmanLists() { + _numEntries = 0; + } + HuffmanLists(uint32 num, uint32 *lens, uint32 *masks, uint32 *symbols) { + _numEntries = num; + _lens = Common::Array<uint32>(lens, num); + _masks = Common::Array<uint32>(masks, num); + _symbols = Common::Array<uint32>(symbols, num); + } + ~HuffmanLists() {} + + + uint32 getNumEntries() const { return _numEntries; } + uint32 getLength(uint32 index) const { return _lens[index]; } + uint32 getMask(uint32 index) const { return _masks[index]; } + uint32 getSymbol(uint32 index) const { return _symbols[index]; } + +private: + uint32 _numEntries; + Common::Array<uint32> _lens; + Common::Array<uint32> _masks; + Common::Array<uint32> _symbols; +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 3b453563a6..2054c5eab6 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -42,6 +42,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _rnd = new Common::RandomSource("macventure"); _debugger= NULL; + _gui = NULL; debug("MacVenture::MacVentureEngine()"); } @@ -143,7 +144,7 @@ void MacVentureEngine::requestUnpause() { void MacVentureEngine::selectControl(ControlReference id) { ControlAction action = referenceToAction(id); - debug(7, "Select control %x", action); + debug(4, "Select control %x", action); _selectedControl = action; } @@ -154,7 +155,7 @@ void MacVentureEngine::activateCommand(ControlReference id) { _activeControl = kNoCommand; _activeControl = action; } - debug(7, "Activating Command %x... Command %x is active", action, _activeControl); + debug(4, "Activating Command %x... Command %x is active", action, _activeControl); } void MacVentureEngine::refreshReady() { @@ -213,7 +214,7 @@ void MacVentureEngine::processEvents() { } bool MacVenture::MacVentureEngine::runScriptEngine() { - debug(5, "MAIN: Running script engine"); + debug(4, "MAIN: Running script engine"); if (_haltedAtEnd) { _haltedAtEnd = false; if (_scriptEngine->resume()) { @@ -335,6 +336,14 @@ Common::String MacVentureEngine::getFilePath(FilePathID id) const { } } +bool MacVentureEngine::isOldText() const { + return _oldTextEncoding; +} + +const HuffmanLists * MacVentureEngine::getDecodingHuffman() const { + return _textHuffman; +} + // Data loading bool MacVentureEngine::loadGlobalSettings() { @@ -400,7 +409,7 @@ bool MacVentureEngine::loadTextHuffman() { // For some reason there are one lass mask than entries masks[i] = res->readUint16BE(); - uint8 *lengths = new uint8[numEntries]; + uint32 *lengths = new uint32[numEntries]; for (uint i = 0; i < numEntries; i++) lengths[i] = res->readByte(); @@ -408,8 +417,8 @@ bool MacVentureEngine::loadTextHuffman() { for (uint i = 0; i < numEntries; i++) values[i] = res->readByte(); - _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); - debug(5, "Text is huffman-encoded"); + _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); + debug(4, "Text is huffman-encoded"); return true; } return false; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 16d4d8de63..656aeaf2b6 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -33,6 +33,7 @@ #include "macventure/gui.h" #include "macventure/world.h" +#include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" @@ -158,6 +159,8 @@ public: Common::String getCommandsPausedString() const; const GlobalSettings& getGlobalSettings() const; Common::String getFilePath(FilePathID id) const; + bool isOldText() const; + const HuffmanLists *getDecodingHuffman() const; private: void processEvents(); @@ -193,7 +196,7 @@ private: // Attributes GameState _gameState; GlobalSettings _globalSettings; StringTable *_filenames; - Common::Huffman *_textHuffman; + HuffmanLists *_textHuffman; bool _oldTextEncoding; bool _paused, _halted, _cmdReady, _prepared; bool _haltedAtEnd, _haltedInSelection; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 2fac1b5347..47e0c702e4 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ detection.o \ gui.o \ object.o \ + text.o \ macventure.o \ world.o \ diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp new file mode 100644 index 0000000000..adac94bdd2 --- /dev/null +++ b/engines/macventure/text.cpp @@ -0,0 +1,146 @@ +/* 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. +* +*/ + +#include "macventure/text.h" + +namespace MacVenture { +TextAsset::TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman) { + _id = objid; + _container = container; + _huffman = huffman; + + if (isOld) { + decodeOld(); + } + else { + decodeHuffman(); + } +} + +void TextAsset::decodeOld() { + Common::SeekableReadStream *res = _container->getItem(_id); + uint16 strLen = res->readUint16BE(); + Common::BitStream32BELSB stream(res); + char* str = new char[strLen + 1]; + bool lowercase = false; + char c; + for (uint16 i = 0; i < strLen; i++) { + char val = stream.getBits(5); + if (val == 0x0) { // Space + c = ' '; + } + else if (val >= 0x1 && val <= 0x1A) { + if (lowercase) { // Ascii a-z + c = val + 0x60; + } + else { // Ascii A-Z + c = val + 0x40; + } + lowercase = true; + } + else if (val == 0x1B) { + if (lowercase) { + c = '.'; + } + else { + c = ','; + } + lowercase = true; + } + else if (val == 0x1C) { + if (lowercase) { + c = 0x27; // Ascii ' + } + else { + c = 0x22; // Ascii '"' + } + lowercase = true; + } + else if (val == 0x1D) { // Composite + warning("Composite strings not implemented"); + stream.getBits(16); + lowercase = true; + } + else if (val == 0x1E) { + c = stream.getBits(8); + lowercase = true; + } + else if (val == 0x1F) { + lowercase = !lowercase; + } + else { + warning("Unrecognized char in old text %d, pos %d", _id, i); + } + str[i] = c; + } + + str[strLen] = '\0'; + debug(7, "Decoded %d string (old): %s", _id, str); + _decoded = Common::String(str); +} + +void TextAsset::decodeHuffman() { + _decoded = Common::String("Huffman string"); + Common::SeekableReadStream *res = _container->getItem(_id); + Common::BitStream32BEMSB stream(res); + uint16 strLen = 0; + if (stream.getBit()) { + strLen = stream.getBits(15); + } + else { + strLen = stream.getBits(7); + } + + char* str = new char[strLen + 1]; + uint32 mask = 0; + uint32 symbol = 0; + char c; + for (uint16 i = 0; i < strLen; i++) { + mask = stream.peekBits(16); // The mask is OK, so it means that I don't know how to use the huffman + uint32 entry; + // Find the length index + for (entry = 0; entry < _huffman->getNumEntries(); entry++) { + if (mask < _huffman->getMask(entry)) break; + } + + stream.skip(_huffman->getLength(entry)); + + symbol = _huffman->getSymbol(entry); + + if (symbol == 1) { // 7-bit ascii + c = stream.getBits(7); + } + else if (symbol == 2) { // Composite + warning("Composite huffman strings not implemented"); + } + else { // Plain ascii + c = symbol & 0xFF; + } + + str[i] = c; + } + + str[strLen] = '\0'; + debug(7, "Decoded %d'th string (new): %s", _id, str); + _decoded = Common::String(str); +} +} // End of namespace MacVenture
\ No newline at end of file diff --git a/engines/macventure/text.h b/engines/macventure/text.h new file mode 100644 index 0000000000..3b3af926be --- /dev/null +++ b/engines/macventure/text.h @@ -0,0 +1,56 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_TEXT_H +#define MACVENTURE_TEXT_H + +#include "macventure/macventure.h" +#include "macventure/hufflists.h" + +namespace MacVenture { +typedef uint32 ObjID; + +class TextAsset { +public: + TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman); + ~TextAsset() {} + + const Common::String *decode() { + return &_decoded; + } + +private: + void decodeOld(); + void decodeHuffman(); + +private: + Container *_container; + ObjID _id; + const HuffmanLists *_huffman; + + Common::String _decoded; + +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index d8fd9b4e39..d919a1a639 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,7 +19,12 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); - + //_gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + _gameText = new Container("Shadowgate II/Shadow Text"); + + ObjID tid = (ObjID)1; + TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); + delete saveGameRes; saveGameFile.close(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index e5c728ef58..6931996100 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -25,11 +25,13 @@ #include "macventure/macventure.h" #include "macventure/container.h" +#include "macventure/text.h" namespace MacVenture { typedef uint32 ObjID; typedef Common::Array<uint16> AttributeGroup; +class TextAsset; enum ObjectAttributeID { kAttrParentObject = 0, |