[Scummvm-cvs-logs] SF.net SVN: scummvm:[47430] tools/trunk
mthreepwood at users.sourceforge.net
mthreepwood at users.sourceforge.net
Fri Jan 22 04:50:49 CET 2010
Revision: 47430
http://scummvm.svn.sourceforge.net/scummvm/?rev=47430&view=rev
Author: mthreepwood
Date: 2010-01-22 03:50:49 +0000 (Fri, 22 Jan 2010)
Log Message:
-----------
Rename MohawkFile and OldMohawkFile to MohawkArchive and LivingBooksArchive_v1 for consistency with the trunk.
Modified Paths:
--------------
tools/trunk/Makefile.common
tools/trunk/engines/mohawk/deriven.cpp
tools/trunk/engines/mohawk/extract_mohawk.cpp
Added Paths:
-----------
tools/trunk/engines/mohawk/archive.cpp
tools/trunk/engines/mohawk/archive.h
Removed Paths:
-------------
tools/trunk/engines/mohawk/mohawk_file.cpp
tools/trunk/engines/mohawk/mohawk_file.h
Modified: tools/trunk/Makefile.common
===================================================================
--- tools/trunk/Makefile.common 2010-01-22 03:43:57 UTC (rev 47429)
+++ tools/trunk/Makefile.common 2010-01-22 03:50:49 UTC (rev 47430)
@@ -135,8 +135,8 @@
$(UTILS)
deriven_OBJS := \
+ engines/mohawk/archive.o \
engines/mohawk/deriven.o \
- engines/mohawk/mohawk_file.o \
common/hashmap.o \
common/memorypool.o \
common/str.o \
@@ -167,8 +167,8 @@
$(UTILS)
extract_mohawk_OBJS := \
+ engines/mohawk/archive.o \
engines/mohawk/extract_mohawk.o \
- engines/mohawk/mohawk_file.o \
common/hashmap.o \
common/memorypool.o \
common/str.o \
Copied: tools/trunk/engines/mohawk/archive.cpp (from rev 47428, tools/trunk/engines/mohawk/mohawk_file.cpp)
===================================================================
--- tools/trunk/engines/mohawk/archive.cpp (rev 0)
+++ tools/trunk/engines/mohawk/archive.cpp 2010-01-22 03:50:49 UTC (rev 47430)
@@ -0,0 +1,421 @@
+/* mohawk_file - Mohawk file parser
+ * Copyright (C) 2009 The ScummVM project
+ *
+ * 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 "engines/mohawk/archive.h"
+
+inline uint32 SWAP_BYTES_32(uint32 a) {
+ const uint16 low = (uint16)a, high = (uint16)(a >> 16);
+ return ((uint32)(uint16)((low >> 8) | (low << 8)) << 16)
+ | (uint16)((high >> 8) | (high << 8));
+}
+
+Common::String MohawkArchive::tag2string(uint32 tag) {
+ char str[5];
+ str[0] = (char)(tag >> 24);
+ str[1] = (char)(tag >> 16);
+ str[2] = (char)(tag >> 8);
+ str[3] = (char)tag;
+ str[4] = '\0';
+ // Replace non-printable chars by dot
+ for (int i = 0; i < 4; ++i) {
+ if (!isprint(str[i]))
+ str[i] = '.';
+ }
+ return Common::String(str);
+}
+
+MohawkArchive::MohawkArchive() {
+ _mhk = NULL;
+ _curFile.clear();
+ _types = NULL;
+ _fileTable = NULL;
+ _curExType = 0;
+ _curExTypeIndex = 0;
+}
+
+void MohawkArchive::close() {
+ delete _mhk; _mhk = NULL;
+ delete[] _types; _types = NULL;
+ delete[] _fileTable; _fileTable = NULL;
+
+ _curFile.clear();
+ _curExType = 0;
+ _curExTypeIndex = 0;
+}
+
+void MohawkArchive::open(Common::SeekableReadStream *stream) {
+ // Make sure no other file is open...
+ close();
+ _mhk = stream;
+
+ if (_mhk->readUint32BE() != ID_MHWK)
+ error ("Could not find tag \'MHWK\'");
+
+ _fileSize = _mhk->readUint32BE();
+
+ if (_mhk->readUint32BE() != ID_RSRC)
+ error ("Could not find tag \'RSRC\'");
+
+ _rsrc.size = _mhk->readUint32BE();
+ _rsrc.filesize = _mhk->readUint32BE();
+ _rsrc.abs_offset = _mhk->readUint32BE();
+ _rsrc.file_table_offset = _mhk->readUint16BE();
+ _rsrc.file_table_size = _mhk->readUint16BE();
+
+ debug (3, "Absolute Offset = %08x", _rsrc.abs_offset);
+
+ /////////////////////////////////
+ //Resource Dir
+ /////////////////////////////////
+
+ // Type Table
+ _mhk->seek(_rsrc.abs_offset);
+ _typeTable.name_offset = _mhk->readUint16BE();
+ _typeTable.resource_types = _mhk->readUint16BE();
+
+ debug (0, "Name List Offset = %04x Number of Resource Types = %04x", _typeTable.name_offset, _typeTable.resource_types);
+
+ _types = new Type[_typeTable.resource_types];
+
+ for (uint16 i = 0; i < _typeTable.resource_types; i++) {
+ _types[i].tag = _mhk->readUint32BE();
+ _types[i].resource_table_offset = _mhk->readUint16BE();
+ _types[i].name_table_offset = _mhk->readUint16BE();
+
+ // HACK: Zoombini's SND resource starts will a NULL.
+ if (_types[i].tag == ID_SND)
+ debug (3, "Type[%02d]: Tag = \'SND\' ResTable Offset = %04x NameTable Offset = %04x", i, _types[i].resource_table_offset, _types[i].name_table_offset);
+ else
+ debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x NameTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset, _types[i].name_table_offset);
+
+ //Resource Table
+ _mhk->seek(_rsrc.abs_offset + _types[i].resource_table_offset);
+ _types[i].resTable.resources = _mhk->readUint16BE();
+
+ debug (3, "Resources = %04x", _types[i].resTable.resources);
+
+ _types[i].resTable.entries = new Type::ResourceTable::Entries[_types[i].resTable.resources];
+
+ for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
+ _types[i].resTable.entries[j].id = _mhk->readUint16BE();
+ _types[i].resTable.entries[j].index = _mhk->readUint16BE();
+
+ debug (4, "Entry[%02x]: ID = %04x (%d) Index = %04x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].index);
+ }
+
+ // Name Table
+ _mhk->seek(_rsrc.abs_offset + _types[i].name_table_offset);
+ _types[i].nameTable.num = _mhk->readUint16BE();
+
+ debug (3, "Names = %04x", _types[i].nameTable.num);
+
+ _types[i].nameTable.entries = new Type::NameTable::Entries[_types[i].nameTable.num];
+
+ for (uint16 j = 0; j < _types[i].nameTable.num; j++) {
+ _types[i].nameTable.entries[j].offset = _mhk->readUint16BE();
+ _types[i].nameTable.entries[j].index = _mhk->readUint16BE();
+
+ debug (4, "Entry[%02x]: Name List Offset = %04x Index = %04x", j, _types[i].nameTable.entries[j].offset, _types[i].nameTable.entries[j].index);
+
+ // Name List
+ uint32 pos = _mhk->pos();
+ _mhk->seek(_rsrc.abs_offset + _typeTable.name_offset + _types[i].nameTable.entries[j].offset);
+ char c = (char)_mhk->readByte();
+ while (c != 0) {
+ _types[i].nameTable.entries[j].name += c;
+ c = (char)_mhk->readByte();
+ }
+
+ debug (3, "Name = \'%s\'", _types[i].nameTable.entries[j].name.c_str());
+
+ // Get back to next entry
+ _mhk->seek(pos);
+ }
+
+ // Return to next TypeTable entry
+ _mhk->seek(_rsrc.abs_offset + (i + 1) * 8 + 4);
+
+ debug (3, "\n");
+ }
+
+ _mhk->seek(_rsrc.abs_offset + _rsrc.file_table_offset);
+ _fileTableAmount = _mhk->readUint32BE();
+ _fileTable = new FileTable[_fileTableAmount];
+
+ for (uint32 i = 0; i < _fileTableAmount; i++) {
+ _fileTable[i].offset = _mhk->readUint32BE();
+ _fileTable[i].dataSize = _mhk->readUint16BE();
+ _fileTable[i].dataSize += _mhk->readByte() << 16; // Get bits 15-24 of dataSize too
+ _fileTable[i].flags = _mhk->readByte();
+ _fileTable[i].unk = _mhk->readUint16BE();
+
+ // Add in another 3 bits for file size from the flags.
+ // The flags are useless to us except for doing this ;)
+ _fileTable[i].dataSize += (_fileTable[i].flags & 7) << 24;
+
+ debug (4, "File[%02x]: Offset = %08x DataSize = %07x Flags = %02x Unk = %04x", i, _fileTable[i].offset, _fileTable[i].dataSize, _fileTable[i].flags, _fileTable[i].unk);
+ }
+}
+
+bool MohawkArchive::hasResource(uint32 tag, uint16 id) {
+ if (!_mhk)
+ return false;
+
+ int16 typeIndex = getTypeIndex(tag);
+
+ if (typeIndex < 0)
+ return false;
+
+ return (getIdIndex(typeIndex, id) >= 0);
+}
+
+MohawkOutputStream MohawkArchive::getRawData(uint32 tag, uint16 id) {
+ MohawkOutputStream output = { 0, 0, 0, 0, "" };
+
+ if (!_mhk)
+ return output;
+
+ int16 typeIndex = getTypeIndex(tag);
+
+ if (typeIndex < 0)
+ return output;
+
+ int16 idIndex = getIdIndex(typeIndex, id);
+
+ if (idIndex < 0)
+ return output;
+
+ // Note: the fileTableIndex is based off 1, not 0. So, subtract 1
+ uint16 fileTableIndex = _types[typeIndex].resTable.entries[idIndex].index - 1;
+
+ // WORKAROUND: tMOV resources pretty much ignore the size part of the file table,
+ // as the original just passed the full Mohawk file to QuickTime and the offset.
+ // We need to do this because of the way Mohawk is set up (this is much more "proper"
+ // than passing _mhk at the right offset). We may want to do that in the future, though.
+ if (_types[typeIndex].tag == ID_TMOV) {
+ if (fileTableIndex == _fileTableAmount)
+ output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _mhk->size());
+ else
+ output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex + 1].offset);
+ } else
+ output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + _fileTable[fileTableIndex].dataSize);
+ output.tag = tag;
+ output.id = id;
+ output.index = fileTableIndex;
+ if (idIndex < _types[typeIndex].nameTable.num)
+ output.name = _types[typeIndex].nameTable.entries[idIndex].name;
+
+ return output;
+}
+
+MohawkOutputStream MohawkArchive::getNextFile() {
+ MohawkOutputStream output = { 0, 0, 0, 0, "" };
+
+ if (_curExType >= _typeTable.resource_types) // No more!
+ return output;
+
+ if (_curExTypeIndex >= _types[_curExType].resTable.resources) {
+ _curExType++;
+ _curExTypeIndex = 0;
+
+ if (_curExType >= _typeTable.resource_types) // No more!
+ return output;
+ }
+
+ uint16 fileTableIndex = _types[_curExType].resTable.entries[_curExTypeIndex].index - 1;
+
+ // For some unknown reason, all tMOV resources have incorrect sizes. We correct this by getting the differences between offsets.
+ uint32 dataSize = 0;
+ if (_types[_curExType].tag == ID_TMOV)
+ dataSize = _fileTable[fileTableIndex + 1].offset - _fileTable[fileTableIndex].offset;
+ else
+ dataSize = _fileTable[fileTableIndex].dataSize;
+
+ output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + dataSize, false);
+ output.tag = _types[_curExType].tag;
+ output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
+ output.index = fileTableIndex;
+
+ if (_curExTypeIndex < _types[_curExType].nameTable.num)
+ output.name = _types[_curExType].nameTable.entries[_curExTypeIndex].name;
+
+ _curExTypeIndex++;
+ return output;
+}
+
+void LivingBooksArchive_v1::open(Common::SeekableReadStream *stream) {
+ close();
+ _mhk = stream;
+
+ // This is for the "old" Mohawk resource format used in some older
+ // Living Books. It is very similar, just missing the MHWK tag and
+ // some other minor differences, especially with the file table
+ // being merged into the resource table.
+
+ uint32 headerSize = _mhk->readUint32BE();
+
+ // NOTE: There are differences besides endianness! (Subtle changes,
+ // but different).
+
+ if (headerSize == 6) { // We're in Big Endian mode (Macintosh)
+ _mhk->readUint16BE(); // Resource Table Size
+ _typeTable.resource_types = _mhk->readUint16BE();
+ _types = new OldType[_typeTable.resource_types];
+
+ debug (0, "Old Mohawk File (Macintosh): Number of Resource Types = %04x", _typeTable.resource_types);
+
+ for (uint16 i = 0; i < _typeTable.resource_types; i++) {
+ _types[i].tag = _mhk->readUint32BE();
+ _types[i].resource_table_offset = (uint16)_mhk->readUint32BE() + 6;
+ _mhk->readUint32BE(); // Unknown (always 0?)
+
+ debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset);
+
+ uint32 oldPos = _mhk->pos();
+
+ // Resource Table/File Table
+ _mhk->seek(_types[i].resource_table_offset);
+ _types[i].resTable.resources = _mhk->readUint16BE();
+ _types[i].resTable.entries = new OldType::ResourceTable::Entries[_types[i].resTable.resources];
+
+ for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
+ _types[i].resTable.entries[j].id = _mhk->readUint16BE();
+ _types[i].resTable.entries[j].offset = _mhk->readUint32BE();
+ _types[i].resTable.entries[j].size = _mhk->readByte() << 16;
+ _types[i].resTable.entries[j].size += _mhk->readUint16BE();
+ _mhk->skip(5); // Unknown (always 0?)
+
+ debug (4, "Entry[%02x]: ID = %04x (%d)\tOffset = %08x, Size = %08x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].offset, _types[i].resTable.entries[j].size);
+ }
+
+ _mhk->seek(oldPos);
+ debug (3, "\n");
+ }
+ } else if (SWAP_BYTES_32(headerSize) == 6) { // We're in Little Endian mode (Windows)
+ _mhk->readUint16LE(); // Resource Table Size
+ _typeTable.resource_types = _mhk->readUint16LE();
+ _types = new OldType[_typeTable.resource_types];
+
+ debug (0, "Old Mohawk File (Windows): Number of Resource Types = %04x", _typeTable.resource_types);
+
+ for (uint16 i = 0; i < _typeTable.resource_types; i++) {
+ _types[i].tag = _mhk->readUint32LE();
+ _types[i].resource_table_offset = _mhk->readUint16LE() + 6;
+ _mhk->readUint16LE(); // Unknown (always 0?)
+
+ debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset);
+
+ uint32 oldPos = _mhk->pos();
+
+ // Resource Table/File Table
+ _mhk->seek(_types[i].resource_table_offset);
+ _types[i].resTable.resources = _mhk->readUint16LE();
+ _types[i].resTable.entries = new OldType::ResourceTable::Entries[_types[i].resTable.resources];
+
+ for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
+ _types[i].resTable.entries[j].id = _mhk->readUint16LE();
+ _types[i].resTable.entries[j].offset = _mhk->readUint32LE();
+ _types[i].resTable.entries[j].size = _mhk->readUint16LE();
+ _mhk->readUint32LE(); // Unknown (always 0?)
+
+ debug (4, "Entry[%02x]: ID = %04x (%d)\tOffset = %08x, Size = %08x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].offset, _types[i].resTable.entries[j].size);
+ }
+
+ _mhk->seek(oldPos);
+ debug (3, "\n");
+ }
+ } else
+ error("Could not determine type of Old Mohawk resource");
+
+}
+
+MohawkOutputStream LivingBooksArchive_v1::getRawData(uint32 tag, uint16 id) {
+ MohawkOutputStream output = { 0, 0, 0, 0, "" };
+
+ if (!_mhk)
+ return output;
+
+ int16 typeIndex = getTypeIndex(tag);
+
+ if (typeIndex < 0)
+ return output;
+
+ int16 idIndex = getIdIndex(typeIndex, id);
+
+ if (idIndex < 0)
+ return output;
+
+ output.stream = new Common::SeekableSubReadStream(_mhk, _types[typeIndex].resTable.entries[idIndex].offset, _types[typeIndex].resTable.entries[idIndex].offset + _types[typeIndex].resTable.entries[idIndex].size);
+ output.tag = tag;
+ output.id = id;
+ output.index = idIndex;
+
+ return output;
+}
+
+MohawkOutputStream LivingBooksArchive_v1::getNextFile() {
+ MohawkOutputStream output = { 0, 0, 0, 0, "" };
+
+ if (_curExType >= _typeTable.resource_types) // No more!
+ return output;
+
+ if (_curExTypeIndex >= _types[_curExType].resTable.resources) {
+ _curExType++;
+ _curExTypeIndex = 0;
+
+ if (_curExType >= _typeTable.resource_types) // No more!
+ return output;
+ }
+
+ output.stream = new Common::SeekableSubReadStream(_mhk, _types[_curExType].resTable.entries[_curExTypeIndex].offset, _types[_curExType].resTable.entries[_curExTypeIndex].offset + _types[_curExType].resTable.entries[_curExTypeIndex].size);
+ output.tag = _types[_curExType].tag;
+ output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
+ output.index = _curExType;
+
+ _curExTypeIndex++;
+ return output;
+}
+
+MohawkArchive *MohawkArchive::createMohawkArchive(Common::SeekableReadStream *stream) {
+ uint32 headerTag = stream->readUint32BE();
+
+ MohawkArchive *mohawkArchive = 0;
+
+ if (headerTag == ID_MHWK) {
+ stream->readUint32BE(); // File size, ignore
+ headerTag = stream->readUint32BE();
+ if (headerTag == ID_RSRC)
+ mohawkArchive = new MohawkArchive();
+ } else if (headerTag == ID_LBRC) {
+ printf("Detected Living Books v2 archive - not yet supported!\n");
+ } else if (headerTag == 6 || SWAP_BYTES_32(headerTag) == 6) {
+ // Assume the Living Books v1 archive format
+ mohawkArchive = new LivingBooksArchive_v1();
+ }
+
+ stream->seek(0);
+
+ if (mohawkArchive)
+ mohawkArchive->open(stream);
+
+ return mohawkArchive;
+}
Copied: tools/trunk/engines/mohawk/archive.h (from rev 47428, tools/trunk/engines/mohawk/mohawk_file.h)
===================================================================
--- tools/trunk/engines/mohawk/archive.h (rev 0)
+++ tools/trunk/engines/mohawk/archive.h 2010-01-22 03:50:49 UTC (rev 47430)
@@ -0,0 +1,268 @@
+/* mohawk_file - Mohawk file parser
+ * Copyright (C) 2009 The ScummVM project
+ *
+ * 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$
+ *
+ */
+
+#ifndef MOHAWK_ARCHIVE_H
+#define MOHAWK_ARCHIVE_H
+
+#include "common/str.h"
+#include "utils/stream.h"
+
+// Main FourCC's
+#define ID_MHWK MKID_BE('MHWK') // Main FourCC
+#define ID_RSRC MKID_BE('RSRC') // Resource Directory Tag
+#define ID_LBRC MKID_BE('LBRC') // Living Books v2 FourCC
+
+// Myst Resource FourCC's
+#define ID_CLRC MKID_BE('CLRC') // Cursor Hotspots
+#define ID_EXIT MKID_BE('EXIT') // Card Exit Scripts
+#define ID_HINT MKID_BE('HINT') // Specifies Cursors in What Area
+#define ID_INIT MKID_BE('INIT') // Card Entrance Scripts
+#define ID_MSND MKID_BE('MSND') // Standard Mohawk Sound
+#define ID_RLST MKID_BE('RLST') // Resource List, Specifies HotSpots
+#define ID_RSFL MKID_BE('RSFL') // ??? (system.dat only)
+#define ID_VIEW MKID_BE('VIEW') // Card Details
+#define ID_WDIB MKID_BE('WDIB') // LZ-Compressed Windows Bitmap
+
+// Myst Masterpiece Edition Resource FourCC's (In addition to Myst FourCC's)
+#define ID_HELP MKID_BE('HELP') // Help Chunk
+#define ID_MJMP MKID_BE('MJMP') // MSND Jumps (To reduce MSND duplication)
+#define ID_PICT MKID_BE('PICT') // JPEG/PICT Image
+
+// Riven Resource FourCC's
+#define ID_BLST MKID_BE('BLST') // Card Hotspot Enabling Lists
+#define ID_CARD MKID_BE('CARD') // Card Scripts
+#define ID_FLST MKID_BE('FLST') // Card SFXE Lists
+#define ID_HSPT MKID_BE('HSPT') // Card Hotspots
+#define ID_MLST MKID_BE('MLST') // Card Movie Lists
+#define ID_NAME MKID_BE('NAME') // Object Names
+#define ID_PLST MKID_BE('PLST') // Card Picture Lists
+#define ID_RMAP MKID_BE('RMAP') // Card Code
+#define ID_SFXE MKID_BE('SFXE') // Water Effect Animations
+#define ID_SLST MKID_BE('SLST') // Card Ambient Sound Lists
+#define ID_TMOV MKID_BE('tMOV') // Game Movie
+
+// Riven Saved Game FourCC's
+#define ID_VARS MKID_BE('VARS') // Saved Game Variable Values
+#define ID_VERS MKID_BE('VERS') // Version Info
+#define ID_ZIPS MKID_BE('ZIPS') // Zip Mode Status
+
+// Zoombini Resource FourCC's
+#define ID_SND MKID_BE('\0SND') // Standard Mohawk Sound
+#define ID_CURS MKID_BE('CURS') // Cursor?
+#define ID_SCRB MKID_BE('SCRB') // ???
+#define ID_SCRS MKID_BE('SCRS') // ???
+#define ID_NODE MKID_BE('NODE') // ???
+#define ID_PATH MKID_BE('PATH') // ???
+#define ID_SHPL MKID_BE('SHPL') // ???
+
+// Living Books Resource FourCC's
+#define ID_TCUR MKID_BE('tCUR') // Cursor
+#define ID_BITL MKID_BE('BITL') // ???
+#define ID_CTBL MKID_BE('CTBL') // Color Table?
+#define ID_SCRP MKID_BE('SCRP') // Script?
+#define ID_SPR MKID_BE('SPR#') // Sprites?
+#define ID_VRSN MKID_BE('VRSN') // Version?
+#define ID_ANI MKID_BE('ANI ') // Animation?
+#define ID_SHP MKID_BE('SHP#') // ???
+
+// JamesMath Resource FourCC's
+#define ID_TANM MKID_BE('tANM') // Animation?
+#define ID_TMFO MKID_BE('tMFO') // ???
+
+// Mohawk Wave Tags
+#define ID_WAVE MKID_BE('WAVE') // Game Sound (Third Tag)
+#define ID_ADPC MKID_BE('ADPC') // Game Sound Chunk
+#define ID_DATA MKID_BE('Data') // Game Sound Chunk
+#define ID_CUE MKID_BE('Cue#') // Game Sound Chunk
+
+// Mohawk MIDI Tags
+#define ID_MIDI MKID_BE('MIDI') // Game Sound (Third Tag), instead of WAVE
+#define ID_PRG MKID_BE('Prg#') // Midi Program?
+
+// Old Mohawk Resource FourCC's
+#define ID_WAV MKID_BE('WAV ') // Old Sound Resource
+#define ID_BMAP MKID_BE('BMAP') // Standard Mohawk Bitmap
+
+// Common Resource FourCC's
+#define ID_TBMP MKID_BE('tBMP') // Standard Mohawk Bitmap
+#define ID_TWAV MKID_BE('tWAV') // Standard Mohawk Sound
+#define ID_TPAL MKID_BE('tPAL') // Standard Mohawk Palette
+#define ID_TCNT MKID_BE('tCNT') // ??? (CSWorld, CSAmtrak, JamesMath)
+#define ID_TSCR MKID_BE('tSCR') // Script? Screen? (CSWorld, CSAmtrak, Treehouse)
+#define ID_STRL MKID_BE('STRL') // String List (Zoombini, CSWorld, CSAmtrak)
+#define ID_TBMH MKID_BE('tBMH') // Standard Mohawk Bitmap
+#define ID_TMID MKID_BE('tMID') // Standard Mohawk MIDI
+#define ID_REGS MKID_BE('REGS') // ??? (Zoombini, Treehouse)
+#define ID_BYTS MKID_BE('BYTS') // Database Entry (CSWorld, CSAmtrak)
+#define ID_INTS MKID_BE('INTS') // ??? (CSWorld, CSAmtrak)
+#define ID_BBOX MKID_BE('BBOX') // Boxes? (CSWorld, CSAmtrak)
+#define ID_SYSX MKID_BE('SYSX') // MIDI Sysex
+
+#define tag2str(x) MohawkArchive::tag2string(x).c_str()
+
+struct MohawkOutputStream {
+ Common::SeekableSubReadStream *stream;
+ uint32 tag;
+ uint32 id;
+ uint32 index;
+ Common::String name;
+};
+
+struct FileTable {
+ uint32 offset;
+ uint32 dataSize; // Really 27 bits
+ byte flags; // Mostly useless except for the bottom 3 bits which are part of the size
+ uint16 unk; // Always 0
+};
+
+struct Type {
+ Type() { resTable.entries = NULL; nameTable.entries = NULL; }
+ ~Type() { delete[] resTable.entries; delete[] nameTable.entries; }
+
+ //Type Table
+ uint32 tag;
+ uint16 resource_table_offset;
+ uint16 name_table_offset;
+
+ struct ResourceTable {
+ uint16 resources;
+ struct Entries {
+ uint16 id;
+ uint16 index;
+ } *entries;
+ } resTable;
+
+ struct NameTable {
+ uint16 num;
+ struct Entries {
+ uint16 offset;
+ uint16 index;
+ // Name List
+ Common::String name;
+ } *entries;
+ } nameTable;
+};
+
+struct TypeTable {
+ uint16 name_offset;
+ uint16 resource_types;
+};
+
+struct RSRC_Header {
+ uint32 size;
+ uint32 filesize;
+ uint32 abs_offset;
+ uint16 file_table_offset;
+ uint16 file_table_size;
+};
+
+class MohawkArchive {
+public:
+ MohawkArchive();
+ virtual ~MohawkArchive() { close(); }
+
+ // Detect new/old Mohawk archive format. Return NULL if the file is neither.
+ static MohawkArchive *createMohawkArchive(Common::SeekableReadStream *stream);
+
+ virtual void open(Common::SeekableReadStream *stream);
+ void close();
+
+ bool hasResource(uint32 tag, uint16 id);
+ virtual MohawkOutputStream getRawData(uint32 tag, uint16 id);
+ virtual MohawkOutputStream getNextFile();
+
+ static Common::String tag2string(uint32 tag);
+
+protected:
+ Common::SeekableReadStream *_mhk;
+ TypeTable _typeTable;
+ Common::String _curFile;
+
+ // Extraction Variables
+ uint32 _curExType;
+ uint32 _curExTypeIndex;
+
+ FileTable *_fileTable;
+
+private:
+ bool _hasData;
+ uint32 _fileSize;
+ RSRC_Header _rsrc;
+ Type *_types;
+ uint16 _nameTableAmount;
+ uint16 _resourceTableAmount;
+ uint16 _fileTableAmount;
+
+ virtual int16 getTypeIndex(uint32 tag) {
+ for (uint16 i = 0; i < _typeTable.resource_types; i++)
+ if (_types[i].tag == tag)
+ return i;
+ return -1; // not found
+ }
+
+ virtual int16 getIdIndex(int16 typeIndex, uint16 id) {
+ for (uint16 i = 0; i < _types[typeIndex].resTable.resources; i++)
+ if (_types[typeIndex].resTable.entries[i].id == id)
+ return i;
+ return -1; // not found
+ }
+};
+
+class LivingBooksArchive_v1 : public MohawkArchive {
+public:
+ LivingBooksArchive_v1() : MohawkArchive() {}
+ ~LivingBooksArchive_v1() {}
+
+ void open(Common::SeekableReadStream *stream);
+ MohawkOutputStream getRawData(uint32 tag, uint16 id);
+ MohawkOutputStream getNextFile();
+
+private:
+ struct OldType {
+ uint32 tag;
+ uint16 resource_table_offset;
+ struct ResourceTable {
+ uint16 resources;
+ struct Entries {
+ uint16 id;
+ uint32 offset;
+ uint32 size;
+ } *entries;
+ } resTable;
+ } *_types;
+
+ int16 getTypeIndex(uint32 tag) {
+ for (uint16 i = 0; i < _typeTable.resource_types; i++)
+ if (_types[i].tag == tag)
+ return i;
+ return -1; // not found
+ }
+
+ int16 getIdIndex(int16 typeIndex, uint16 id) {
+ for (uint16 i = 0; i < _types[typeIndex].resTable.resources; i++)
+ if (_types[typeIndex].resTable.entries[i].id == id)
+ return i;
+ return -1; // not found
+ }
+};
+
+#endif
Modified: tools/trunk/engines/mohawk/deriven.cpp
===================================================================
--- tools/trunk/engines/mohawk/deriven.cpp 2010-01-22 03:43:57 UTC (rev 47429)
+++ tools/trunk/engines/mohawk/deriven.cpp 2010-01-22 03:50:49 UTC (rev 47430)
@@ -20,7 +20,7 @@
*
*/
-#include "mohawk_file.h"
+#include "engines/mohawk/archive.h"
#include "util.h"
#include "utils/file.h"
@@ -95,8 +95,8 @@
printf("Usage: %s <mohawk archive> [CARD or HSPT] [id]\n", appName);
}
-Common::StringList getNameList(MohawkFile *mohawkFile, uint16 id) {
- MohawkOutputStream nameResource = mohawkFile->getRawData(ID_NAME, id);
+Common::StringList getNameList(MohawkArchive *mohawkArchive, uint16 id) {
+ MohawkOutputStream nameResource = mohawkArchive->getRawData(ID_NAME, id);
Common::StringList nameList;
uint16 namesCount = nameResource.stream->readUint16BE();
@@ -207,12 +207,12 @@
}
// Open the file as a Mohawk archive
- MohawkFile *mohawkFile = new MohawkFile();
- mohawkFile->open(new Common::File(file));
+ MohawkArchive *mohawkArchive = new MohawkArchive();
+ mohawkArchive->open(new Common::File(file));
// Load in Variable/External Command Names'
- Common::StringList exNames = getNameList(mohawkFile, 3);
- Common::StringList varNames = getNameList(mohawkFile, 4);
+ Common::StringList exNames = getNameList(mohawkArchive, 3);
+ Common::StringList varNames = getNameList(mohawkArchive, 4);
uint32 tag = READ_BE_UINT32(argv[2]);
uint32 cardId = (uint16)atoi(argv[3]);
@@ -221,7 +221,7 @@
printf("\n\nDumping scripts for card %d!\n", cardId);
printf("==================================\n\n");
- MohawkOutputStream cardStream = mohawkFile->getRawData(ID_CARD, cardId);
+ MohawkOutputStream cardStream = mohawkArchive->getRawData(ID_CARD, cardId);
cardStream.stream->readUint32BE(); // Skip first 4 bytes
dumpScript(cardStream.stream, varNames, exNames, 0);
@@ -231,7 +231,7 @@
printf("\n\nDumping scripts for card %d hotspots!\n", cardId);
printf("===========================================\n\n");
- MohawkOutputStream hsptStream = mohawkFile->getRawData(ID_HSPT, cardId);
+ MohawkOutputStream hsptStream = mohawkArchive->getRawData(ID_HSPT, cardId);
uint16 hotspotCount = hsptStream.stream->readUint16BE();
for (uint16 i = 0; i < hotspotCount; i++) {
Modified: tools/trunk/engines/mohawk/extract_mohawk.cpp
===================================================================
--- tools/trunk/engines/mohawk/extract_mohawk.cpp 2010-01-22 03:43:57 UTC (rev 47429)
+++ tools/trunk/engines/mohawk/extract_mohawk.cpp 2010-01-22 03:50:49 UTC (rev 47430)
@@ -20,7 +20,7 @@
*
*/
-#include "mohawk_file.h"
+#include "engines/mohawk/archive.h"
#include "util.h"
#include "utils/file.h"
@@ -198,9 +198,9 @@
}
// Open the file as a Mohawk archive
- MohawkFile *mohawkFile = MohawkFile::createMohawkFile(new Common::File(file));
+ MohawkArchive *mohawkArchive = MohawkArchive::createMohawkArchive(new Common::File(file));
- if (!mohawkFile) {
+ if (!mohawkArchive) {
printf("\'%s\' is not a valid Mohawk archive\n", argv[archiveArg]);
fclose(file);
return 1;
@@ -213,7 +213,7 @@
uint32 tag = READ_BE_UINT32(argv[archiveArg + 1]);
uint16 id = (uint16)atoi(argv[archiveArg + 2]);
- MohawkOutputStream output = mohawkFile->getRawData(tag, id);
+ MohawkOutputStream output = mohawkArchive->getRawData(tag, id);
if (output.stream) {
outputMohawkStream(output, doConversion);
@@ -222,17 +222,18 @@
printf ("Could not find specified data!\n");
}
} else {
- MohawkOutputStream output = mohawkFile->getNextFile();
+ MohawkOutputStream output = mohawkArchive->getNextFile();
while (output.stream) {
outputMohawkStream(output, doConversion);
delete output.stream;
- output = mohawkFile->getNextFile();
+ output = mohawkArchive->getNextFile();
}
}
printf("Done!\n");
free(outputBuffer);
- mohawkFile->close();
+ mohawkArchive->close();
fclose(file);
+ delete mohawkArchive;
return 0;
}
Deleted: tools/trunk/engines/mohawk/mohawk_file.cpp
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.cpp 2010-01-22 03:43:57 UTC (rev 47429)
+++ tools/trunk/engines/mohawk/mohawk_file.cpp 2010-01-22 03:50:49 UTC (rev 47430)
@@ -1,419 +0,0 @@
-/* mohawk_file - Mohawk file parser
- * Copyright (C) 2009 The ScummVM project
- *
- * 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 "mohawk_file.h"
-
-inline uint32 SWAP_BYTES_32(uint32 a) {
- const uint16 low = (uint16)a, high = (uint16)(a >> 16);
- return ((uint32)(uint16)((low >> 8) | (low << 8)) << 16)
- | (uint16)((high >> 8) | (high << 8));
-}
-
-Common::String MohawkFile::tag2string(uint32 tag) {
- char str[5];
- str[0] = (char)(tag >> 24);
- str[1] = (char)(tag >> 16);
- str[2] = (char)(tag >> 8);
- str[3] = (char)tag;
- str[4] = '\0';
- // Replace non-printable chars by dot
- for (int i = 0; i < 4; ++i) {
- if (!isprint(str[i]))
- str[i] = '.';
- }
- return Common::String(str);
-}
-
-MohawkFile::MohawkFile() {
- _mhk = NULL;
- _curFile.clear();
- _types = NULL;
- _fileTable = NULL;
- _curExType = 0;
- _curExTypeIndex = 0;
-}
-
-void MohawkFile::close() {
- delete _mhk; _mhk = NULL;
- delete[] _types; _types = NULL;
- delete[] _fileTable; _fileTable = NULL;
-
- _curFile.clear();
- _curExType = 0;
- _curExTypeIndex = 0;
-}
-
-void MohawkFile::open(Common::SeekableReadStream *stream) {
- // Make sure no other file is open...
- close();
- _mhk = stream;
-
- if (_mhk->readUint32BE() != ID_MHWK)
- error ("Could not find tag \'MHWK\'");
-
- _fileSize = _mhk->readUint32BE();
-
- if (_mhk->readUint32BE() != ID_RSRC)
- error ("Could not find tag \'RSRC\'");
-
- _rsrc.size = _mhk->readUint32BE();
- _rsrc.filesize = _mhk->readUint32BE();
- _rsrc.abs_offset = _mhk->readUint32BE();
- _rsrc.file_table_offset = _mhk->readUint16BE();
- _rsrc.file_table_size = _mhk->readUint16BE();
-
- debug (3, "Absolute Offset = %08x", _rsrc.abs_offset);
-
- /////////////////////////////////
- //Resource Dir
- /////////////////////////////////
-
- // Type Table
- _mhk->seek(_rsrc.abs_offset);
- _typeTable.name_offset = _mhk->readUint16BE();
- _typeTable.resource_types = _mhk->readUint16BE();
-
- debug (0, "Name List Offset = %04x Number of Resource Types = %04x", _typeTable.name_offset, _typeTable.resource_types);
-
- _types = new Type[_typeTable.resource_types];
-
- for (uint16 i = 0; i < _typeTable.resource_types; i++) {
- _types[i].tag = _mhk->readUint32BE();
- _types[i].resource_table_offset = _mhk->readUint16BE();
- _types[i].name_table_offset = _mhk->readUint16BE();
-
- // HACK: Zoombini's SND resource starts will a NULL.
- if (_types[i].tag == ID_SND)
- debug (3, "Type[%02d]: Tag = \'SND\' ResTable Offset = %04x NameTable Offset = %04x", i, _types[i].resource_table_offset, _types[i].name_table_offset);
- else
- debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x NameTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset, _types[i].name_table_offset);
-
- //Resource Table
- _mhk->seek(_rsrc.abs_offset + _types[i].resource_table_offset);
- _types[i].resTable.resources = _mhk->readUint16BE();
-
- debug (3, "Resources = %04x", _types[i].resTable.resources);
-
- _types[i].resTable.entries = new Type::ResourceTable::Entries[_types[i].resTable.resources];
-
- for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
- _types[i].resTable.entries[j].id = _mhk->readUint16BE();
- _types[i].resTable.entries[j].index = _mhk->readUint16BE();
-
- debug (4, "Entry[%02x]: ID = %04x (%d) Index = %04x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].index);
- }
-
- // Name Table
- _mhk->seek(_rsrc.abs_offset + _types[i].name_table_offset);
- _types[i].nameTable.num = _mhk->readUint16BE();
-
- debug (3, "Names = %04x", _types[i].nameTable.num);
-
- _types[i].nameTable.entries = new Type::NameTable::Entries[_types[i].nameTable.num];
-
- for (uint16 j = 0; j < _types[i].nameTable.num; j++) {
- _types[i].nameTable.entries[j].offset = _mhk->readUint16BE();
- _types[i].nameTable.entries[j].index = _mhk->readUint16BE();
-
- debug (4, "Entry[%02x]: Name List Offset = %04x Index = %04x", j, _types[i].nameTable.entries[j].offset, _types[i].nameTable.entries[j].index);
-
- // Name List
- uint32 pos = _mhk->pos();
- _mhk->seek(_rsrc.abs_offset + _typeTable.name_offset + _types[i].nameTable.entries[j].offset);
- char c = (char)_mhk->readByte();
- while (c != 0) {
- _types[i].nameTable.entries[j].name += c;
- c = (char)_mhk->readByte();
- }
-
- debug (3, "Name = \'%s\'", _types[i].nameTable.entries[j].name.c_str());
-
- // Get back to next entry
- _mhk->seek(pos);
- }
-
- // Return to next TypeTable entry
- _mhk->seek(_rsrc.abs_offset + (i + 1) * 8 + 4);
-
- debug (3, "\n");
- }
-
- _mhk->seek(_rsrc.abs_offset + _rsrc.file_table_offset);
- _fileTableAmount = _mhk->readUint32BE();
- _fileTable = new FileTable[_fileTableAmount];
-
- for (uint32 i = 0; i < _fileTableAmount; i++) {
- _fileTable[i].offset = _mhk->readUint32BE();
- _fileTable[i].dataSize = _mhk->readUint16BE();
- _fileTable[i].dataSize += _mhk->readByte() << 16; // Get bits 15-24 of dataSize too
- _fileTable[i].flags = _mhk->readByte();
- _fileTable[i].unk = _mhk->readUint16BE();
-
- // Add in another 3 bits for file size from the flags.
- // The flags are useless to us except for doing this ;)
- _fileTable[i].dataSize += (_fileTable[i].flags & 7) << 24;
-
- debug (4, "File[%02x]: Offset = %08x DataSize = %07x Flags = %02x Unk = %04x", i, _fileTable[i].offset, _fileTable[i].dataSize, _fileTable[i].flags, _fileTable[i].unk);
- }
-}
-
-bool MohawkFile::hasResource(uint32 tag, uint16 id) {
- if (!_mhk)
- return false;
-
- int16 typeIndex = getTypeIndex(tag);
-
- if (typeIndex < 0)
- return false;
-
- return (getIdIndex(typeIndex, id) >= 0);
-}
-
-MohawkOutputStream MohawkFile::getRawData(uint32 tag, uint16 id) {
- MohawkOutputStream output = { 0, 0, 0, 0, "" };
-
- if (!_mhk)
- return output;
-
- int16 typeIndex = getTypeIndex(tag);
-
- if (typeIndex < 0)
- return output;
-
- int16 idIndex = getIdIndex(typeIndex, id);
-
- if (idIndex < 0)
- return output;
-
- // Note: the fileTableIndex is based off 1, not 0. So, subtract 1
- uint16 fileTableIndex = _types[typeIndex].resTable.entries[idIndex].index - 1;
-
- // WORKAROUND: tMOV resources pretty much ignore the size part of the file table,
- // as the original just passed the full Mohawk file to QuickTime and the offset.
- // We need to do this because of the way Mohawk is set up (this is much more "proper"
- // than passing _mhk at the right offset). We may want to do that in the future, though.
- if (_types[typeIndex].tag == ID_TMOV) {
- if (fileTableIndex == _fileTableAmount)
- output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _mhk->size());
- else
- output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex + 1].offset);
- } else
- output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + _fileTable[fileTableIndex].dataSize);
- output.tag = tag;
- output.id = id;
- output.index = fileTableIndex;
- if (idIndex < _types[typeIndex].nameTable.num)
- output.name = _types[typeIndex].nameTable.entries[idIndex].name;
-
- return output;
-}
-
-MohawkOutputStream MohawkFile::getNextFile() {
- MohawkOutputStream output = { 0, 0, 0, 0, "" };
-
- if (_curExType >= _typeTable.resource_types) // No more!
- return output;
-
- if (_curExTypeIndex >= _types[_curExType].resTable.resources) {
- _curExType++;
- _curExTypeIndex = 0;
-
- if (_curExType >= _typeTable.resource_types) // No more!
- return output;
- }
-
- uint16 fileTableIndex = _types[_curExType].resTable.entries[_curExTypeIndex].index - 1;
-
- // For some unknown reason, all tMOV resources have incorrect sizes. We correct this by getting the differences between offsets.
- uint32 dataSize = 0;
- if (_types[_curExType].tag == ID_TMOV)
- dataSize = _fileTable[fileTableIndex + 1].offset - _fileTable[fileTableIndex].offset;
- else
- dataSize = _fileTable[fileTableIndex].dataSize;
-
- output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + dataSize, false);
- output.tag = _types[_curExType].tag;
- output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
- output.index = fileTableIndex;
-
- if (_curExTypeIndex < _types[_curExType].nameTable.num)
- output.name = _types[_curExType].nameTable.entries[_curExTypeIndex].name;
-
- _curExTypeIndex++;
- return output;
-}
-
-void OldMohawkFile::open(Common::SeekableReadStream *stream) {
- close();
- _mhk = stream;
-
- // This is for the "old" Mohawk resource format used in some older
- // Living Books. It is very similar, just missing the MHWK tag and
- // some other minor differences, especially with the file table
- // being merged into the resource table.
-
- uint32 headerSize = _mhk->readUint32BE();
-
- // NOTE: There are differences besides endianness! (Subtle changes,
- // but different).
-
- if (headerSize == 6) { // We're in Big Endian mode (Macintosh)
- _mhk->readUint16BE(); // Resource Table Size
- _typeTable.resource_types = _mhk->readUint16BE();
- _types = new OldType[_typeTable.resource_types];
-
- debug (0, "Old Mohawk File (Macintosh): Number of Resource Types = %04x", _typeTable.resource_types);
-
- for (uint16 i = 0; i < _typeTable.resource_types; i++) {
- _types[i].tag = _mhk->readUint32BE();
- _types[i].resource_table_offset = (uint16)_mhk->readUint32BE() + 6;
- _mhk->readUint32BE(); // Unknown (always 0?)
-
- debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset);
-
- uint32 oldPos = _mhk->pos();
-
- // Resource Table/File Table
- _mhk->seek(_types[i].resource_table_offset);
- _types[i].resTable.resources = _mhk->readUint16BE();
- _types[i].resTable.entries = new OldType::ResourceTable::Entries[_types[i].resTable.resources];
-
- for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
- _types[i].resTable.entries[j].id = _mhk->readUint16BE();
- _types[i].resTable.entries[j].offset = _mhk->readUint32BE();
- _types[i].resTable.entries[j].size = _mhk->readByte() << 16;
- _types[i].resTable.entries[j].size += _mhk->readUint16BE();
- _mhk->skip(5); // Unknown (always 0?)
-
- debug (4, "Entry[%02x]: ID = %04x (%d)\tOffset = %08x, Size = %08x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].offset, _types[i].resTable.entries[j].size);
- }
-
- _mhk->seek(oldPos);
- debug (3, "\n");
- }
- } else if (SWAP_BYTES_32(headerSize) == 6) { // We're in Little Endian mode (Windows)
- _mhk->readUint16LE(); // Resource Table Size
- _typeTable.resource_types = _mhk->readUint16LE();
- _types = new OldType[_typeTable.resource_types];
-
- debug (0, "Old Mohawk File (Windows): Number of Resource Types = %04x", _typeTable.resource_types);
-
- for (uint16 i = 0; i < _typeTable.resource_types; i++) {
- _types[i].tag = _mhk->readUint32LE();
- _types[i].resource_table_offset = _mhk->readUint16LE() + 6;
- _mhk->readUint16LE(); // Unknown (always 0?)
-
- debug (3, "Type[%02d]: Tag = \'%s\' ResTable Offset = %04x", i, tag2str(_types[i].tag), _types[i].resource_table_offset);
-
- uint32 oldPos = _mhk->pos();
-
- // Resource Table/File Table
- _mhk->seek(_types[i].resource_table_offset);
- _types[i].resTable.resources = _mhk->readUint16LE();
- _types[i].resTable.entries = new OldType::ResourceTable::Entries[_types[i].resTable.resources];
-
- for (uint16 j = 0; j < _types[i].resTable.resources; j++) {
- _types[i].resTable.entries[j].id = _mhk->readUint16LE();
- _types[i].resTable.entries[j].offset = _mhk->readUint32LE();
- _types[i].resTable.entries[j].size = _mhk->readUint16LE();
- _mhk->readUint32LE(); // Unknown (always 0?)
-
- debug (4, "Entry[%02x]: ID = %04x (%d)\tOffset = %08x, Size = %08x", j, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].id, _types[i].resTable.entries[j].offset, _types[i].resTable.entries[j].size);
- }
-
- _mhk->seek(oldPos);
- debug (3, "\n");
- }
- } else
- error("Could not determine type of Old Mohawk resource");
-
-}
-
-MohawkOutputStream OldMohawkFile::getRawData(uint32 tag, uint16 id) {
- MohawkOutputStream output = { 0, 0, 0, 0, "" };
-
- if (!_mhk)
- return output;
-
- int16 typeIndex = getTypeIndex(tag);
-
- if (typeIndex < 0)
- return output;
-
- int16 idIndex = getIdIndex(typeIndex, id);
-
- if (idIndex < 0)
- return output;
-
- output.stream = new Common::SeekableSubReadStream(_mhk, _types[typeIndex].resTable.entries[idIndex].offset, _types[typeIndex].resTable.entries[idIndex].offset + _types[typeIndex].resTable.entries[idIndex].size);
- output.tag = tag;
- output.id = id;
- output.index = idIndex;
-
- return output;
-}
-
-MohawkOutputStream OldMohawkFile::getNextFile() {
- MohawkOutputStream output = { 0, 0, 0, 0, "" };
-
- if (_curExType >= _typeTable.resource_types) // No more!
- return output;
-
- if (_curExTypeIndex >= _types[_curExType].resTable.resources) {
- _curExType++;
- _curExTypeIndex = 0;
-
- if (_curExType >= _typeTable.resource_types) // No more!
- return output;
- }
-
- output.stream = new Common::SeekableSubReadStream(_mhk, _types[_curExType].resTable.entries[_curExTypeIndex].offset, _types[_curExType].resTable.entries[_curExTypeIndex].offset + _types[_curExType].resTable.entries[_curExTypeIndex].size);
- output.tag = _types[_curExType].tag;
- output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
- output.index = _curExType;
-
- _curExTypeIndex++;
- return output;
-}
-
-MohawkFile *MohawkFile::createMohawkFile(Common::SeekableReadStream *stream) {
- uint32 headerTag = stream->readUint32BE();
-
- MohawkFile *mohawkFile = 0;
-
- if (headerTag == ID_MHWK) {
- stream->readUint32BE(); // File size, ignore
- headerTag = stream->readUint32BE();
- if (headerTag == ID_RSRC)
- mohawkFile = new MohawkFile();
- } else if (headerTag == 6 || SWAP_BYTES_32(headerTag) == 6) {
- // Assume the old archive format
- mohawkFile = new OldMohawkFile();
- }
-
- stream->seek(0);
-
- if (mohawkFile)
- mohawkFile->open(stream);
-
- return mohawkFile;
-}
Deleted: tools/trunk/engines/mohawk/mohawk_file.h
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.h 2010-01-22 03:43:57 UTC (rev 47429)
+++ tools/trunk/engines/mohawk/mohawk_file.h 2010-01-22 03:50:49 UTC (rev 47430)
@@ -1,267 +0,0 @@
-/* mohawk_file - Mohawk file parser
- * Copyright (C) 2009 The ScummVM project
- *
- * 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$
- *
- */
-
-#ifndef MOHAWK_FILE_H
-#define MOHAWK_FILE_H
-
-#include "common/str.h"
-#include "utils/stream.h"
-
-// Main FourCC's
-#define ID_MHWK MKID_BE('MHWK') // Main FourCC
-#define ID_RSRC MKID_BE('RSRC') // Resource Directory Tag
-
-// Myst Resource FourCC's
-#define ID_CLRC MKID_BE('CLRC') // Cursor Hotspots
-#define ID_EXIT MKID_BE('EXIT') // Card Exit Scripts
-#define ID_HINT MKID_BE('HINT') // Specifies Cursors in What Area
-#define ID_INIT MKID_BE('INIT') // Card Entrance Scripts
-#define ID_MSND MKID_BE('MSND') // Standard Mohawk Sound
-#define ID_RLST MKID_BE('RLST') // Resource List, Specifies HotSpots
-#define ID_RSFL MKID_BE('RSFL') // ??? (system.dat only)
-#define ID_VIEW MKID_BE('VIEW') // Card Details
-#define ID_WDIB MKID_BE('WDIB') // LZ-Compressed Windows Bitmap
-
-// Myst Masterpiece Edition Resource FourCC's (In addition to Myst FourCC's)
-#define ID_HELP MKID_BE('HELP') // Help Chunk
-#define ID_MJMP MKID_BE('MJMP') // MSND Jumps (To reduce MSND duplication)
-#define ID_PICT MKID_BE('PICT') // JPEG/PICT Image
-
-// Riven Resource FourCC's
-#define ID_BLST MKID_BE('BLST') // Card Hotspot Enabling Lists
-#define ID_CARD MKID_BE('CARD') // Card Scripts
-#define ID_FLST MKID_BE('FLST') // Card SFXE Lists
-#define ID_HSPT MKID_BE('HSPT') // Card Hotspots
-#define ID_MLST MKID_BE('MLST') // Card Movie Lists
-#define ID_NAME MKID_BE('NAME') // Object Names
-#define ID_PLST MKID_BE('PLST') // Card Picture Lists
-#define ID_RMAP MKID_BE('RMAP') // Card Code
-#define ID_SFXE MKID_BE('SFXE') // Water Effect Animations
-#define ID_SLST MKID_BE('SLST') // Card Ambient Sound Lists
-#define ID_TMOV MKID_BE('tMOV') // Game Movie
-
-// Riven Saved Game FourCC's
-#define ID_VARS MKID_BE('VARS') // Saved Game Variable Values
-#define ID_VERS MKID_BE('VERS') // Version Info
-#define ID_ZIPS MKID_BE('ZIPS') // Zip Mode Status
-
-// Zoombini Resource FourCC's
-#define ID_SND MKID_BE('\0SND') // Standard Mohawk Sound
-#define ID_CURS MKID_BE('CURS') // Cursor?
-#define ID_SCRB MKID_BE('SCRB') // ???
-#define ID_SCRS MKID_BE('SCRS') // ???
-#define ID_NODE MKID_BE('NODE') // ???
-#define ID_PATH MKID_BE('PATH') // ???
-#define ID_SHPL MKID_BE('SHPL') // ???
-
-// Living Books Resource FourCC's
-#define ID_TCUR MKID_BE('tCUR') // Cursor
-#define ID_BITL MKID_BE('BITL') // ???
-#define ID_CTBL MKID_BE('CTBL') // Color Table?
-#define ID_SCRP MKID_BE('SCRP') // Script?
-#define ID_SPR MKID_BE('SPR#') // Sprites?
-#define ID_VRSN MKID_BE('VRSN') // Version?
-#define ID_ANI MKID_BE('ANI ') // Animation?
-#define ID_SHP MKID_BE('SHP#') // ???
-
-// JamesMath Resource FourCC's
-#define ID_TANM MKID_BE('tANM') // Animation?
-#define ID_TMFO MKID_BE('tMFO') // ???
-
-// Mohawk Wave Tags
-#define ID_WAVE MKID_BE('WAVE') // Game Sound (Third Tag)
-#define ID_ADPC MKID_BE('ADPC') // Game Sound Chunk
-#define ID_DATA MKID_BE('Data') // Game Sound Chunk
-#define ID_CUE MKID_BE('Cue#') // Game Sound Chunk
-
-// Mohawk MIDI Tags
-#define ID_MIDI MKID_BE('MIDI') // Game Sound (Third Tag), instead of WAVE
-#define ID_PRG MKID_BE('Prg#') // Midi Program?
-
-// Old Mohawk Resource FourCC's
-#define ID_WAV MKID_BE('WAV ') // Old Sound Resource
-#define ID_BMAP MKID_BE('BMAP') // Standard Mohawk Bitmap
-
-// Common Resource FourCC's
-#define ID_TBMP MKID_BE('tBMP') // Standard Mohawk Bitmap
-#define ID_TWAV MKID_BE('tWAV') // Standard Mohawk Sound
-#define ID_TPAL MKID_BE('tPAL') // Standard Mohawk Palette
-#define ID_TCNT MKID_BE('tCNT') // ??? (CSWorld, CSAmtrak, JamesMath)
-#define ID_TSCR MKID_BE('tSCR') // Script? Screen? (CSWorld, CSAmtrak, Treehouse)
-#define ID_STRL MKID_BE('STRL') // String List (Zoombini, CSWorld, CSAmtrak)
-#define ID_TBMH MKID_BE('tBMH') // Standard Mohawk Bitmap
-#define ID_TMID MKID_BE('tMID') // Standard Mohawk MIDI
-#define ID_REGS MKID_BE('REGS') // ??? (Zoombini, Treehouse)
-#define ID_BYTS MKID_BE('BYTS') // Database Entry (CSWorld, CSAmtrak)
-#define ID_INTS MKID_BE('INTS') // ??? (CSWorld, CSAmtrak)
-#define ID_BBOX MKID_BE('BBOX') // Boxes? (CSWorld, CSAmtrak)
-#define ID_SYSX MKID_BE('SYSX') // MIDI Sysex
-
-#define tag2str(x) MohawkFile::tag2string(x).c_str()
-
-struct MohawkOutputStream {
- Common::SeekableSubReadStream *stream;
- uint32 tag;
- uint32 id;
- uint32 index;
- Common::String name;
-};
-
-struct FileTable {
- uint32 offset;
- uint32 dataSize; // Really 27 bits
- byte flags; // Mostly useless except for the bottom 3 bits which are part of the size
- uint16 unk; // Always 0
-};
-
-struct Type {
- Type() { resTable.entries = NULL; nameTable.entries = NULL; }
- ~Type() { delete[] resTable.entries; delete[] nameTable.entries; }
-
- //Type Table
- uint32 tag;
- uint16 resource_table_offset;
- uint16 name_table_offset;
-
- struct ResourceTable {
- uint16 resources;
- struct Entries {
- uint16 id;
- uint16 index;
- } *entries;
- } resTable;
-
- struct NameTable {
- uint16 num;
- struct Entries {
- uint16 offset;
- uint16 index;
- // Name List
- Common::String name;
- } *entries;
- } nameTable;
-};
-
-struct TypeTable {
- uint16 name_offset;
- uint16 resource_types;
-};
-
-struct RSRC_Header {
- uint32 size;
- uint32 filesize;
- uint32 abs_offset;
- uint16 file_table_offset;
- uint16 file_table_size;
-};
-
-class MohawkFile {
-public:
- MohawkFile();
- virtual ~MohawkFile() { close(); }
-
- // Detect new/old Mohawk archive format. Return NULL if the file is neither.
- static MohawkFile *createMohawkFile(Common::SeekableReadStream *stream);
-
- virtual void open(Common::SeekableReadStream *stream);
- void close();
-
- bool hasResource(uint32 tag, uint16 id);
- virtual MohawkOutputStream getRawData(uint32 tag, uint16 id);
- virtual MohawkOutputStream getNextFile();
-
- static Common::String tag2string(uint32 tag);
-
-protected:
- Common::SeekableReadStream *_mhk;
- TypeTable _typeTable;
- Common::String _curFile;
-
- // Extraction Variables
- uint32 _curExType;
- uint32 _curExTypeIndex;
-
- FileTable *_fileTable;
-
-private:
- bool _hasData;
- uint32 _fileSize;
- RSRC_Header _rsrc;
- Type *_types;
- uint16 _nameTableAmount;
- uint16 _resourceTableAmount;
- uint16 _fileTableAmount;
-
- virtual int16 getTypeIndex(uint32 tag) {
- for (uint16 i = 0; i < _typeTable.resource_types; i++)
- if (_types[i].tag == tag)
- return i;
- return -1; // not found
- }
-
- virtual int16 getIdIndex(int16 typeIndex, uint16 id) {
- for (uint16 i = 0; i < _types[typeIndex].resTable.resources; i++)
- if (_types[typeIndex].resTable.entries[i].id == id)
- return i;
- return -1; // not found
- }
-};
-
-class OldMohawkFile : public MohawkFile {
-public:
- OldMohawkFile() : MohawkFile() {}
- ~OldMohawkFile() {}
-
- void open(Common::SeekableReadStream *stream);
- MohawkOutputStream getRawData(uint32 tag, uint16 id);
- MohawkOutputStream getNextFile();
-
-private:
- struct OldType {
- uint32 tag;
- uint16 resource_table_offset;
- struct ResourceTable {
- uint16 resources;
- struct Entries {
- uint16 id;
- uint32 offset;
- uint32 size;
- } *entries;
- } resTable;
- } *_types;
-
- int16 getTypeIndex(uint32 tag) {
- for (uint16 i = 0; i < _typeTable.resource_types; i++)
- if (_types[i].tag == tag)
- return i;
- return -1; // not found
- }
-
- int16 getIdIndex(int16 typeIndex, uint16 id) {
- for (uint16 i = 0; i < _types[typeIndex].resTable.resources; i++)
- if (_types[typeIndex].resTable.entries[i].id == id)
- return i;
- return -1; // not found
- }
-};
-
-#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list