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 SHERLOCK_SCALPEL_TSAGE_RESOURCES_H
23 #define SHERLOCK_SCALPEL_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 #include "sherlock/screen.h"
34 
35 namespace Sherlock {
36 namespace Scalpel {
37 namespace TsAGE {
38 
39 // Magic number used by original game to identify valid memory blocks
40 const uint32 MEMORY_ENTRY_ID = 0xE11DA722;
41 
42 const int MEMORY_POOL_SIZE = 1000;
43 
44 enum ResourceType { RES_LIBRARY, RES_STRIP, RES_IMAGE, RES_PALETTE, RES_VISAGE, RES_SOUND, RES_MESSAGE,
45  RES_FONT, RES_POINTER, RES_BANK, RES_SND_DRIVER, RES_PRIORITY, RES_CONTROL, RES_WALKRGNS,
46  RES_BITMAP, RES_SAVE, RES_SEQUENCE,
47  // Return to Ringworld specific resource types
48  RT17, RT18, RT19, RT20, RT21, RT22, RT23, RT24, RT25, RT26, RT27, RT28, RT29, RT30, RT31
49 };
50 
51 class SectionEntry {
52 public:
53  ResourceType resType;
54  uint16 resNum;
55  uint32 fileOffset;
56 
57  SectionEntry() {
58  resType = RES_LIBRARY;
59  resNum = 0;
60  fileOffset = 0;
61  }
62 };
63 
65 public:
66  uint16 id;
67  bool isCompressed;
68  uint32 fileOffset;
69  uint32 size;
70  uint32 uncompressedSize;
71 
72  ResourceEntry() {
73  id = 0;
74  isCompressed = false;
75  fileOffset = 0;
76  size = 0;
77  uncompressedSize = 0;
78  }
79 };
80 
82 
83 class SectionList : public Common::List<SectionEntry> {
84 public:
85  uint32 fileOffset;
86 
87  SectionList() {
88  fileOffset = 0;
89  }
90 };
91 
92 class BitReader {
93 private:
94  Common::ReadStream &_stream;
95  uint8 _remainder, _bitsLeft;
96  byte readByte() { return _stream.eos() ? 0 : _stream.readByte(); }
97 public:
98  BitReader(Common::ReadStream &s) : _stream(s) {
99  numBits = 9;
100  _remainder = 0;
101  _bitsLeft = 0;
102  }
103  uint16 readToken();
104 
105  int numBits;
106 };
107 
108 class TLib {
109 private:
110  Common::StringArray _resStrings;
111 private:
112  Common::File _file;
113  Common::Path _filename;
114  ResourceList _resources;
115  SectionList _sections;
116 
117  void loadSection(uint32 fileOffset);
118  void loadIndex();
119 
120  static bool scanIndex(Common::File &f, ResourceType resType, int rlbNum, int resNum, ResourceEntry &resEntry);
121  static void loadSection(Common::File &f, ResourceList &resources);
122 public:
123  TLib(const Common::Path &filename);
124  ~TLib();
125 
126  const Common::Path &getFilename() { return _filename; }
127  const SectionList &getSections() { return _sections; }
128  Common::SeekableReadStream *getResource(uint16 id, bool suppressErrors = false);
129  Common::SeekableReadStream *getResource(ResourceType resType, uint16 resNum, uint16 rlbNum, bool suppressErrors = false);
130  uint32 getResourceStart(ResourceType resType, uint16 resNum, uint16 rlbNum, ResourceEntry &entry);
131  void getPalette(byte palette[PALETTE_SIZE], int paletteNum);
132 };
133 
134 } // end of namespace TsAGE
135 } // end of namespace Scalpel
136 } // end of namespace Sherlock
137 
138 #endif
Definition: resources.h:108
Definition: resources.h:83
virtual bool eos() const =0
Definition: resources.h:51
Definition: animation.h:29
Definition: resources.h:92
Definition: path.h:52
Definition: stream.h:745
byte readByte()
Definition: stream.h:434
Definition: file.h:47
Definition: blueforce_dialogs.h:30
Definition: stream.h:385
Definition: resources.h:64