ScummVM API documentation
resource.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef CHEWY_RESOURCE_H
23 #define CHEWY_RESOURCE_H
24 
25 #include "common/scummsys.h"
26 #include "common/file.h"
27 #include "common/str.h"
28 #include "common/memstream.h"
29 #include "common/rect.h"
30 
31 namespace Chewy {
32 
33 enum ResourceType {
34  kResourceUnknown = -1,
35  kResourcePCX = 0, // unused
36  kResourceTBF = 1, // background art, contained in TGPs
37  kResourceTAF = 2,
38  kResourceTFF = 3,
39  kResourceVOC = 4, // speech and SFX, contained in TVPs
40  kResourceTPF = 5, // unused
41  kResourceTMF = 6, // music, similar to a MOD file, contained in details.tap
42  kResourceMOD = 7, // unused
43  kResourceRAW = 8, // unused
44  kResourceLBM = 9, // unused
45  kResourceRDI = 10,
46  kResourceTXT = 11,
47  kResourceIIB = 12,
48  kResourceSIB = 13,
49  kResourceEIB = 14,
50  kResourceATS = 15, // unused
51  kResourceSAA = 16, // unused
52  kResourceFLC = 17, // unused
53  kResourceAAD = 18, // unused
54  kResourceADS = 19, // unused
55  kResourceADH = 20, // used in txt/diah.adh
56  kResourceTGP = 21, // container for background art, used in back/comic.tgp, back/episode1.tgp and back/gbook.tgp
57  kResourceTVP = 22, // container for speech, used in sound/speech.tvp
58  kResourceTTP = 23, // unused
59  kResourceTAP = 24, // container for sound effects, music and cutscenes, used in sound/details.tap and cut/cut.tap
60  kResourceCFO = 25, // unused
61  kResourceTCF = 26, // error messages, used in err/err_e.tcf (English) and err/err_d.tcf (German)
62  kResourceGEP = 27 // barriers / walkable areas
63 };
64 
65 // Generic chunk header
66 struct Chunk {
67  uint32 size;
68  uint16 num; // same as the type below, used in chunks where the type is substituted with count
69  ResourceType type;
70  uint32 pos; // position of the actual data
71 };
72 
73 // TBF (background) chunk header
74 struct TBFChunk {
75  // TBF chunk header
76  // ID (TBF, followed by a zero)
77  uint16 screenMode;
78  uint16 compressionFlag;
79  uint32 size;
80  uint16 width;
81  uint16 height;
82  uint8 palette[3 * 256];
83  uint8 *data;
84 };
85 
86 // TAF (sprite) image data chunk header - 15 bytes
87 struct TAFChunk {
88  uint16 compressionFlag;
89  uint16 width;
90  uint16 height;
91  // 4 bytes next sprite offset
92  // 4 bytes sprite image offset
93  // 1 byte padding
94  uint8 *data;
95 };
96 
97 // Sound chunk header
98 struct SoundChunk {
99  uint32 size;
100  uint8 *data;
101 };
102 
103 // Video chunk header
104 struct VideoChunk {
105  // ID (CFA, followed by a zero)
106  uint32 size;
107  uint16 frameCount;
108  uint16 width;
109  uint16 height;
110  uint32 frameDelay; // in ms
111  uint32 firstFrameOffset;
112 };
113 
114 // Dialog chunk header (AdsBlock)
115 // Original values are in diah.adh, and are synced
116 // to saved games
117 struct DialogChunk {
118  bool show[6];
119  uint8 next[6];
120  uint8 flags[6];
121 };
122 
123 enum VideoFrameType {
124  kVideoFrameNormal = 0xF1FA,
125  kVideoFrameCustom = 0xFAF1
126 };
127 
130 
131 class Resource {
132 public:
133  Resource(const Common::Path &filename);
134  virtual ~Resource();
135 
136  ResourceType getType() const {
137  return _resType;
138  }
139  uint32 getSize() const {
140  return _stream.size();
141  }
142  uint32 findLargestChunk(uint start, uint end);
143  uint32 getChunkCount() const;
144  Chunk *getChunk(uint num);
145  virtual uint8 *getChunkData(uint num);
146 
147 protected:
148  void initSprite(const Common::Path &filename);
149  void unpackRLE(uint8 *buffer, uint32 compressedSize, uint32 uncompressedSize);
150  void decrypt(uint8 *data, uint32 size);
151 
152  Common::File _stream;
153  uint16 _chunkCount;
154  ResourceType _resType;
155  bool _encrypted;
156 
157  // Sprite specific
158  uint8 _spritePalette[3 * 256];
159  uint32 _allSize;
160  uint16 _spriteCorrectionsCount;
161  uint16 *_spriteCorrectionsTable;
162 
163  ChunkList _chunkList;
164 };
165 
166 class SpriteResource : public Resource {
167 public:
168  SpriteResource(const Common::Path &filename) : Resource(filename) {}
169  virtual ~SpriteResource() {}
170 
171  TAFChunk *getSprite(uint num);
172  uint32 getSpriteData(uint num, uint8 **buf, bool initBuffer);
173  uint8 *getSpritePalette() { return _spritePalette; }
174  uint32 getAllSize() { return _allSize; }
175  uint16 getSpriteCorrectionsCount() { return _spriteCorrectionsCount; }
176  uint16 *getSpriteCorrectionsTable() { return _spriteCorrectionsTable; }
177 };
178 
179 class BackgroundResource : public Resource {
180 public:
181  BackgroundResource(const Common::Path &filename) : Resource(filename) {}
182  virtual ~BackgroundResource() {}
183 
184  TBFChunk *getImage(uint num, bool fixPalette);
185 };
186 
187 class SoundResource : public Resource {
188 public:
189  SoundResource(const Common::Path &filename) : Resource(filename) {}
190  virtual ~SoundResource() {}
191 
192  SoundChunk *getSound(uint num);
193 };
194 
195 class VideoResource : public Resource {
196 public:
197  VideoResource(const Common::Path &filename) : Resource(filename) {}
198  virtual ~VideoResource() {}
199 
200  VideoChunk *getVideoHeader(uint num);
201  Common::SeekableReadStream *getVideoStream(uint num);
202 };
203 
204 class DialogResource : public Resource {
205 public:
206  DialogResource(const Common::Path &filename);
207  virtual ~DialogResource();
208 
209  DialogChunk *getDialog(uint dialog, uint block);
210  bool isItemShown(uint dialog, uint block, uint num);
211  void setItemShown(uint dialog, uint block, uint num, bool shown);
212  bool hasExitBit(uint dialog, uint block, uint num);
213  bool hasRestartBit(uint dialog, uint block, uint num);
214  bool hasShowBit(uint dialog, uint block, uint num);
215  uint8 getNextBlock(uint dialog, uint block, uint num);
216 
217  void loadStream(Common::SeekableReadStream *s);
218  void saveStream(Common::WriteStream *s);
219 
220  uint32 getStreamSize() const {
221  return _stream.size();
222  }
223 
224 private:
226  byte *_dialogBuffer;
227 };
228 
229 class BarrierResource : public Resource {
230 public:
231  BarrierResource(const Common::Path &filename) : Resource(filename) {}
232  virtual ~BarrierResource() {}
233 
234  void init(int16 room, int16 bgWidth, int16 bgHeight);
235 
236  int16 getX() const { return _x; }
237  int16 getY() const { return _y; }
238  int16 getLevel() const { return _level; }
239  int16 getWidth() const { return _w; }
240  int16 getHeight() const { return _h; }
241  uint8 *getData() { return getChunkData(_room); }
242 
243 private:
244  int16 _x = 0, _y = 0, _level = 0, _w = 0, _h = 0, _room = 0;
245 };
246 
247 } // namespace Chewy
248 
249 #endif
Definition: resource.h:98
Definition: resource.h:229
Definition: stream.h:77
Definition: resource.h:117
Definition: resource.h:179
Definition: memstream.h:394
Definition: resource.h:166
Definition: path.h:52
Definition: stream.h:745
Definition: resource.h:104
Definition: file.h:47
Definition: resource.h:66
Definition: resource.h:204
Definition: resource.h:131
Definition: resource.h:87
Definition: ani_dat.h:25
Definition: resource.h:74
Definition: resource.h:187
Definition: resource.h:195