aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/resource.h
blob: 18e8f80fb2ed375734c287eeb0378659e93b3bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/scummsys.h"
#include "common/endian.h"
#include "common/file.h"
#include "common/str.h"

#ifndef MOHAWK_RESOURCE_H
#define MOHAWK_RESOURCE_H

namespace Mohawk {

// 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') // Cursor Hints
#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/WDIB 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 Codes
#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') // QuickTime Movie

// Riven Saved Game FourCC's
#define ID_VARS MKID_BE('VARS') // 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') // Feature Script
#define ID_SCRS MKID_BE('SCRS') // Snoid Script
#define ID_NODE MKID_BE('NODE') // Walk Node
#define ID_PATH MKID_BE('PATH') // Walk Path
#define ID_SHPL MKID_BE('SHPL') // Shape List

// Living Books Resource FourCC's
#define ID_TCUR MKID_BE('tCUR') // Cursor
#define ID_BITL MKID_BE('BITL') // Book Item List
#define ID_CTBL MKID_BE('CTBL') // Color Table
#define ID_SCRP MKID_BE('SCRP') // Script
#define ID_SPR  MKID_BE('SPR#') // Sprite?
#define ID_VRSN MKID_BE('VRSN') // Version
#define ID_ANI  MKID_BE('ANI ') // Animation
#define ID_SHP  MKID_BE('SHP#') // Shape
#define ID_WAV  MKID_BE('WAV ') // Old Sound Resource
#define ID_BMAP MKID_BE('BMAP') // Old Mohawk Bitmap
#define ID_BCOD MKID_BE('BCOD') // Book Code

// JamesMath Resource FourCC's
#define ID_TANM MKID_BE('tANM') // Animation?
#define ID_TMFO MKID_BE('tMFO') // ???

// CSTime Resource FourCC's
#define ID_CINF MKID_BE('CINF') // Case Info
#define ID_CONV MKID_BE('CONV') // Conversation
#define ID_HOTS MKID_BE('HOTS') // Hotspot
#define ID_INVO MKID_BE('INVO') // Inventory Object
#define ID_QARS MKID_BE('QARS') // Question and Responses
#define ID_SCEN MKID_BE('SCEN') // Scene
#define ID_STRI MKID_BE('STRI') // String Entry?

// 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 Patch

// 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') // Shape Count (CSWorld, CSAmtrak, JamesMath)
#define ID_TSCR MKID_BE('tSCR') // Script (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') // Registration Data - Shape Offsets (Zoombini, Treehouse)
#define ID_BYTS MKID_BE('BYTS') // Byte Array? (Used as Database Entry in CSWorld, CSAmtrak)
#define ID_INTS MKID_BE('INTS') // uint16 Array? (CSWorld, CSAmtrak)
#define ID_BBOX MKID_BE('BBOX') // Boxes? (CSWorld, CSAmtrak)
#define ID_SYSX MKID_BE('SYSX') // MIDI Sysex

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 {
	uint16 version;
	uint16 compaction;
	uint32 filesize;
	uint32 abs_offset;
	uint16 file_table_offset;
	uint16 file_table_size;
};

class MohawkArchive {
public:
	MohawkArchive();
	virtual ~MohawkArchive() { close(); }

	bool open(const Common::String &filename);
	virtual bool open(Common::SeekableReadStream *stream);
	void close();

	virtual bool hasResource(uint32 tag, uint16 id);
	virtual bool hasResource(uint32 tag, const Common::String &resName);
	virtual Common::SeekableReadStream *getResource(uint32 tag, uint16 id);
	virtual uint32 getOffset(uint32 tag, uint16 id);
	virtual uint16 findResourceID(uint32 type, const Common::String &resName);
	Common::String getName(uint32 tag, uint16 id);

protected:
	Common::SeekableReadStream *_mhk;
	TypeTable _typeTable;
	Common::String _curFile;

private:
	RSRC_Header _rsrc;
	Type *_types;
	FileTable *_fileTable;
	uint16 _nameTableAmount;
	uint16 _resourceTableAmount;
	uint16 _fileTableAmount;

	int getTypeIndex(uint32 tag);
	int getIDIndex(int typeIndex, uint16 id);
	int getIDIndex(int typeIndex, const Common::String &resName);
};

class LivingBooksArchive_v1 : public MohawkArchive {
public:
	LivingBooksArchive_v1() : MohawkArchive() {}
	~LivingBooksArchive_v1() {}

	bool hasResource(uint32 tag, uint16 id);
	bool hasResource(uint32 tag, const Common::String &resName) { return false; }
	virtual bool open(Common::SeekableReadStream *stream);
	Common::SeekableReadStream *getResource(uint32 tag, uint16 id);
	Common::SeekableReadStream *getResource(uint32 tag, const Common::String &resName) { return 0; }
	uint32 getOffset(uint32 tag, uint16 id);
	uint16 findResourceID(uint32 type, const Common::String &resName) { return 0xFFFF; }

protected:
	struct OldType {
		uint32 tag;
		uint16 resource_table_offset;
		struct ResourceTable {
			uint16 resources;
			struct Entries {
				uint16 id;
				uint32 offset;
				uint32 size;
			} *entries;
		} resTable;
	} *_types;

private:
	int getTypeIndex(uint32 tag);
	int getIDIndex(int typeIndex, uint16 id);
};

class DOSArchive_v2 : public LivingBooksArchive_v1 {
public:
	DOSArchive_v2() : LivingBooksArchive_v1() {}
	~DOSArchive_v2() {}

	virtual bool open(Common::SeekableReadStream *stream);
};

} // End of namespace Mohawk

#endif