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
22#ifndef TSAGE_RESOURCES_H
23#define TSAGE_RESOURCES_H
24
25#include "common/scummsys.h"
26#include "common/array.h"
27#include "common/file.h"
28#include "common/list.h"
29#include "common/str.h"
30#include "common/str-array.h"
31#include "common/util.h"
32#include "graphics/surface.h"
33
34namespace TsAGE {
35
36// Magic number used by original game to identify valid memory blocks
37const uint32 MEMORY_ENTRY_ID = 0xE11DA722;
38
39const int MEMORY_POOL_SIZE = 1000;
40
41enum ResourceType { RES_LIBRARY, RES_STRIP, RES_IMAGE, RES_PALETTE, RES_VISAGE, RES_SOUND, RES_MESSAGE,
42 RES_FONT, RES_POINTER, RES_BANK, RES_SND_DRIVER, RES_PRIORITY, RES_CONTROL, RES_WALKRGNS,
43 RES_BITMAP, RES_SAVE, RES_SEQUENCE,
44 // Return to Ringworld specific resource types
45 RT17, RT18, RT19, RT20, RT21, RT22, RT23, RT24, RT25, RT26, RT27, RT28, RT29, RT30, RT31
46};
47
49public:
50 uint32 id;
51 int16 index;
52 int lockCtr;
53 int criticalCtr;
54 uint8 tag;
55 uint32 size;
56
57 MemoryHeader() {
58 id = 0;
59 index = 0;
60 lockCtr = 0;
61 criticalCtr = 0;
62 tag = 0;
63 size = 0;
64 }
65};
66
68public:
69 ResourceType resType;
70 uint16 resNum;
71 uint32 fileOffset;
72
73 SectionEntry() {
74 resType = RES_LIBRARY;
75 resNum = 0;
76 fileOffset = 0;
77 }
78};
79
81public:
82 uint16 id;
83 bool isCompressed;
84 uint32 fileOffset;
85 uint32 size;
86 uint32 uncompressedSize;
87
89 id = 0;
90 isCompressed = false;
91 fileOffset = 0;
92 size = 0;
93 uncompressedSize = 0;
94 }
95};
96
98
99class SectionList : public Common::List<SectionEntry> {
100public:
101 uint32 fileOffset;
102
103 SectionList() {
104 fileOffset = 0;
105 }
106};
107
109private:
110 MemoryHeader **_memoryPool;
111public:
114
115 uint16 allocate(uint32 size);
116 byte *allocate2(uint32 size);
117 byte *lock(uint32 handle);
118 int indexOf(const byte *p);
119 void deallocate(const byte *p);
120 void deallocate(uint16 handle) { warning("TODO: MemoryManager::deallocate(handle)"); }
121 uint32 getSize(const byte *p);
122 void incLocks(const byte *p);
123};
124
126private:
127 Common::ReadStream &_stream;
128 uint8 _remainder, _bitsLeft;
129 byte readByte() { return _stream.eos() ? 0 : _stream.readByte(); }
130public:
131 BitReader(Common::ReadStream &s) : _stream(s) {
132 numBits = 9;
133 _remainder = 0;
134 _bitsLeft = 0;
135 }
136 uint16 readToken();
137
138 int numBits;
139};
140
141class TLib {
142private:
143 Common::StringArray _resStrings;
144 MemoryManager &_memoryManager;
145private:
147 Common::Path _filename;
148 ResourceList _resources;
149 SectionList _sections;
150
151 void loadSection(uint32 fileOffset);
152 void loadIndex();
153public:
154 TLib(MemoryManager &memManager, const Common::Path &filename);
155 ~TLib();
156
157 const Common::Path &getFilename() { return _filename; }
158 const SectionList &getSections() { return _sections; }
159 byte *getResource(uint16 id, bool suppressErrors = false);
160 byte *getResource(ResourceType resType, uint16 resNum, uint16 rlbNum, bool suppressErrors = false);
161 uint32 getResourceStart(ResourceType resType, uint16 resNum, uint16 rlbNum, ResourceEntry &entry);
162 bool getPalette(int paletteNum, byte *palData, uint *startNum, uint *numEntries);
163 byte *getSubResource(int resNum, int rlbNum, int index, uint *size, bool suppressErrors = false);
164 bool getMessage(int resNum, int lineNum, Common::String &result, bool suppressErrors = false);
165};
166
168private:
169 Common::Array<TLib *> _libList;
170public:
172
173 void addLib(const Common::Path &libName);
174
175 byte *getResource(uint16 id, bool suppressErrors = false);
176 byte *getResource(ResourceType resType, uint16 resNum, uint16 rlbNum, bool suppressErrors = false);
177 void getPalette(int paletteNum, byte *palData, uint *startNum, uint *numEntries, bool suppressErrors = false);
178 byte *getSubResource(int resNum, int rlbNum, int index, uint *size, bool suppressErrors = false);
179 Common::String getMessage(int resNum, int lineNum, bool suppressErrors = false);
180 TLib &first() { return **_libList.begin(); }
181
182 static bool scanIndex(Common::File &f, ResourceType resType, int rlbNum, int resNum, ResourceEntry &resEntry);
183 static void loadSection(Common::SeekableReadStream *f, ResourceList &resources);
184};
185
186
187} // end of namespace TsAGE
188
189#endif
iterator begin()
Definition: array.h:375
Definition: file.h:47
Definition: path.h:52
Definition: stream.h:385
virtual bool eos() const =0
byte readByte()
Definition: stream.h:434
Definition: stream.h:745
Definition: str.h:59
Definition: resources.h:125
Definition: resources.h:48
Definition: resources.h:108
Definition: resources.h:80
Definition: resources.h:167
Definition: resources.h:67
Definition: resources.h:99
Definition: resources.h:141
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1