1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef QUEEN_RESOURCE_H
24 #define QUEEN_RESOURCE_H
25 
26 #include "common/file.h"
27 #include "common/str-array.h"
28 #include "common/language.h"
29 #include "common/platform.h"
30 #include "queen/defs.h"
31 
32 namespace Queen {
33 
34 enum GameFeatures {
35 	GF_DEMO      = 1 << 0, // demo
36 	GF_TALKIE    = 1 << 1, // equivalent to cdrom version check
37 	GF_FLOPPY    = 1 << 2, // floppy, ie. non-talkie version
38 	GF_INTERVIEW = 1 << 3, // interview demo
39 	GF_REBUILT   = 1 << 4  // version rebuilt with the 'compression_queen' tool
40 };
41 
42 struct RetailGameVersion {
43 	char str[6];
44 	uint8 queenTblVersion;
45 	uint32 queenTblOffset;
46 	uint32 dataFileSize;
47 };
48 
49 struct DetectedGameVersion {
50 	Common::Platform platform;
51 	Common::Language language;
52 	uint8 features;
53 	uint8 compression;
54 	char str[6];
55 	uint8 queenTblVersion;
56 	uint32 queenTblOffset;
57 };
58 
59 struct ResourceEntry {
60 	char filename[13];
61 	uint8 bundle;
62 	uint32 offset;
63 	uint32 size;
64 };
65 
66 class Resource {
67 public:
68 
69 	Resource();
70 	~Resource();
71 
72 	//! loads a binary file
73 	uint8 *loadFile(const char *filename, uint32 skipBytes = 0, uint32 *size = NULL);
74 
75 	//! loads a text file
76 	void loadTextFile(const char *filename, Common::StringArray &stringList);
77 
78 	//! returns true if the file is present in the resource
fileExists(const char * filename)79 	bool fileExists(const char *filename) const { return resourceEntry(filename) != NULL; }
80 
81 	//! returns a reference to a sound file
82 	Common::File *findSound(const char *filename, uint32 *size);
83 
isDemo()84 	bool isDemo() const { return (_version.features & GF_DEMO) != 0; }
isInterview()85 	bool isInterview() const { return (_version.features & GF_INTERVIEW) != 0; }
isFloppy()86 	bool isFloppy() const { return (_version.features & GF_FLOPPY) != 0; }
isCD()87 	bool isCD() const { return (_version.features & GF_TALKIE) != 0; }
88 
89 	//! returns compression type for audio files
getCompression()90 	uint8 getCompression() const { return _version.compression; }
91 
92 	//! returns JAS version string (contains language, platform and version information)
getJASVersion()93 	const char *getJASVersion() const { return _version.str; }
94 
95 	//! returns the language of the game
getLanguage()96 	Common::Language getLanguage() const { return _version.language; }
97 
getPlatform()98 	Common::Platform getPlatform() const { return _version.platform; }
99 
100 	//! detect game version
101 	static bool detectVersion(DetectedGameVersion *ver, Common::File *f);
102 
103 	enum Version {
104 		VER_ENG_FLOPPY     = 0,
105 		VER_ENG_TALKIE     = 1,
106 		VER_FRE_FLOPPY     = 2,
107 		VER_FRE_TALKIE     = 3,
108 		VER_GER_FLOPPY     = 4,
109 		VER_GER_TALKIE     = 5,
110 		VER_ITA_FLOPPY     = 6,
111 		VER_ITA_TALKIE     = 7,
112 		VER_SPA_TALKIE     = 8,
113 		VER_HEB_TALKIE	   = 9,
114 		VER_DEMO_PCGAMES   = 10,
115 		VER_DEMO           = 11,
116 		VER_INTERVIEW      = 12,
117 		VER_AMI_ENG_FLOPPY = 13,
118 		VER_AMI_DEMO       = 14,
119 		VER_AMI_INTERVIEW  = 15,
120 
121 		VER_COUNT          = 16
122 	};
123 
124 	enum {
125 		JAS_VERSION_OFFSET_DEMO = 0x119A8,
126 		JAS_VERSION_OFFSET_INTV	= 0xCF8,
127 		JAS_VERSION_OFFSET_PC	= 0x12484
128 	};
129 
130 protected:
131 
132 	Common::File _resourceFile;
133 
134 	int _currentResourceFileNum;
135 
136 	DetectedGameVersion _version;
137 
138 	//! number of entries in resource table
139 	uint32 _resourceEntries;
140 
141 	ResourceEntry *_resourceTable;
142 
143 	//! verify the version of the selected game
144 	void checkJASVersion();
145 
146 	//! returns a reference to the ReseourceEntry for the specified filename
147 	ResourceEntry *resourceEntry(const char *filename) const;
148 
149 	//! seeks resource file to specific bundle and file offset
150 	void seekResourceFile(int num, uint32 offset);
151 
152 	//! extract the resource table for the specified game version
153 	void readTableFile(uint8 version, uint32 offset);
154 
155 	//! read the resource table from the specified file
156 	void readTableEntries(Common::File *file);
157 
158 	//! detect game version based on queen.1 datafile size
159 	static const RetailGameVersion *detectGameVersionFromSize(uint32 size);
160 
161 	//! resource table filename (queen.tbl)
162 	static const char *const _tableFilename;
163 
164 	//! known FOTAQ versions
165 	static const RetailGameVersion _gameVersions[];
166 
167 	//! resource table for english floppy version
168 	static ResourceEntry _resourceTablePEM10[];
169 };
170 
171 } // End of namespace Queen
172 
173 #endif
174