ScummVM API documentation
resources.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_RESOURCES_H
29 #define GOB_RESOURCES_H
30 
31 #include "common/str.h"
32 
33 namespace Common {
34 class Path;
35 class SeekableReadStream;
36 }
37 
38 namespace Gob {
39 
40 class GobEngine;
41 
42 class Resource {
43 public:
44  Resource(byte *data, int32 size, bool needFree = true,
45  int16 width = 0, int16 height = 0);
46  ~Resource();
47 
48  byte *getData () const;
49  int32 getSize () const;
50  int16 getWidth () const;
51  int16 getHeight() const;
52 
53  Common::SeekableReadStream *stream() const;
54 
55 private:
56  byte *_data;
57  int32 _size;
58  int16 _width;
59  int16 _height;
60  bool _needFree;
61 
63 };
64 
65 class TextItem {
66 public:
67  TextItem(byte *data, int32 size);
68  ~TextItem();
69 
70  byte *getData() const;
71  int32 getSize() const;
72 
73  Common::SeekableReadStream *stream() const;
74 
75 private:
76  byte *_data;
77  int32 _size;
78 
80 };
81 
82 class Resources {
83 public:
84  Resources(GobEngine *vm);
85  ~Resources();
86 
87  bool load(const Common::String &fileName);
88  void unload(bool del = true);
89 
90  bool isLoaded() const;
91 
92  Resource *getResource(uint16 id, int16 *width = 0, int16 *height = 0) const;
93  TextItem *getTextItem(uint16 id) const;
94 
95  byte *getTexts() const;
96 
97  bool dumpResource(const Resource &resource,
98  const Common::Path &fileName) const;
99  bool dumpResource(const Resource &resource, uint16 id,
100  const Common::String &ext = "dmp") const;
101 
102 private:
103  // Structure sizes in the files
104  static const int kTOTResItemSize = 4 + 2 + 2 + 2;
105  static const int kTOTResTableSize = 2 + 1;
106  static const int kEXTResItemSize = 4 + 2 + 2 + 2;
107  static const int kEXTResTableSize = 2 + 1;
108  static const int kTOTTextTableSize = 2;
109  static const int kTOTTextItemSize = 2 + 2;
110 
111  enum ResourceType {
112  kResourceTOT = 0,
113  kResourceIM,
114  kResourceEXT,
115  kResourceEX
116  };
117 
118  struct TOTResourceItem {
119  ResourceType type;
120  uint16 size;
121  int16 width;
122  int16 height;
123  union {
124  int32 offset;
125  int32 index;
126  };
127  };
128 
129  struct TOTResourceTable {
130  int16 itemsCount;
131  byte unknown;
132  TOTResourceItem *items;
133  uint32 dataOffset;
134 
135  TOTResourceTable();
136  ~TOTResourceTable();
137  };
138 
139  struct EXTResourceItem {
140  ResourceType type;
141  int32 offset;
142  uint16 size;
143  int16 width;
144  int16 height;
145  bool packed;
146  };
147 
148  struct EXTResourceTable {
149  int16 itemsCount;
150  byte unknown;
151  EXTResourceItem *items;
152 
153  EXTResourceTable();
154  ~EXTResourceTable();
155  };
156 
157  struct TOTTextItem {
158  uint16 offset;
159  int16 size;
160  };
161 
162  struct TOTTextTable {
163  bool needFree;
164  int16 itemsCount;
165 
166  byte *data;
167  int32 size;
168 
169  TOTTextItem *items;
170 
171  TOTTextTable();
172  ~TOTTextTable();
173  };
174 
175  GobEngine *_vm;
176 
177  Common::String _fileBase;
178  Common::String _totFile;
179  Common::String _extFile;
180  Common::String _exFile;
181 
182  byte *_totData;
183  uint32 _totSize;
184 
185  byte *_imData;
186  uint32 _imSize;
187 
188  bool _hasLOM;
189  int32 _totResStart;
190 
191  TOTResourceTable *_totResourceTable;
192  EXTResourceTable *_extResourceTable;
193  TOTTextTable *_totTextTable;
194 
195  bool loadTOTResourceTable();
196  bool loadEXTResourceTable();
197  bool loadTOTTextTable(const Common::String &fileBase);
198  bool loadIMFile();
199  bool loadEXFile();
200 
201  byte *loadTOTLocTexts(const Common::String &fileBase, int32 &size);
202  bool getLocTextFile(char *locTextFile, int language);
203  Common::String getLocTextFile(const Common::String &fileBase, int language);
204 
205  Resource *getTOTResource(uint16 id) const;
206  Resource *getEXTResource(uint16 id) const;
207 
208  byte *getTOTData(TOTResourceItem &totItem) const;
209  byte *getIMData(TOTResourceItem &totItem) const;
210  byte *getEXTData(EXTResourceItem &extItem, uint32 &size) const;
211  byte *getEXData(EXTResourceItem &extItem, uint32 &size) const;
212 };
213 
214 } // End of namespace Gob
215 
216 #endif // GOB_RESOURCES_H
Definition: gob.h:163
Definition: str.h:59
Definition: path.h:52
Definition: stream.h:745
Path
Definition: game.h:75
Definition: anifile.h:40
Definition: resources.h:65
Definition: algorithm.h:29
Definition: resources.h:82
Definition: resources.h:42