ScummVM API documentation
ggpack.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 TWP_GGPACK_H
23 #define TWP_GGPACK_H
24 
25 #include "common/hash-str.h"
26 #include "common/stream.h"
27 #include "common/list.h"
28 #include "common/path.h"
29 #include "common/stablemap.h"
30 #include "common/formats/json.h"
31 
32 namespace Twp {
33 
34 struct XorKey {
35  XorKey() {}
36  XorKey(const Common::Array<int> &mb, int m) : magicBytes(mb), multiplier(m) {}
37 
38  Common::Array<int> magicBytes;
39  int multiplier = 0;
40 };
41 
43 public:
44  MemStream();
45 
46  bool open(const byte *buf, int64 bufSize);
47  uint32 read(void *dataPtr, uint32 dataSize);
48  bool eos() const;
49 
50  int64 pos() const;
51  int64 size() const;
52  bool seek(int64 offset, int whence = SEEK_SET);
53 
54 private:
55  const byte *_buf = nullptr;
56  int64 _bufSize = 0;
57  int64 _pos = 0;
58 };
59 
61 public:
62  OutMemStream();
63 
64  bool open(byte *buf, int64 bufSize);
65  uint32 write(const void *dataPtr, uint32 dataSize) override;
66 
67  int64 pos() const override;
68  int64 size() const override;
69  bool seek(int64 offset, int whence = SEEK_SET) override;
70 
71 private:
72  byte *_buf = nullptr;
73  int64 _bufSize = 0;
74  int64 _pos = 0;
75 };
76 
78 public:
79  XorStream();
80 
81  bool open(Common::SeekableReadStream *stream, int len, const XorKey &key);
82  uint32 read(void *dataPtr, uint32 dataSize);
83  bool eos() const;
84 
85  int64 pos() const;
86  int64 size() const;
87  bool seek(int64 offset, int whence = SEEK_SET);
88 
89 private:
90  Common::SeekableReadStream *_s = nullptr;
91  int _previous = 0;
92  int _start = 0;
93  int _size = 0;
94  XorKey _key;
95 };
96 
98 public:
99  RangeStream();
100 
101  bool open(Common::SeekableReadStream *stream, int64 size);
102  uint32 read(void *dataPtr, uint32 dataSize);
103  bool eos() const;
104 
105  int64 pos() const;
106  int64 size() const;
107  bool seek(int64 offset, int whence = SEEK_SET);
108 
109 private:
110  Common::SeekableReadStream *_s = nullptr;
111  int64 _start = 0;
112  int64 _size = 0;
113 };
114 
116 public:
118 
120 
121 private:
122  Common::JSONValue *readHash();
123  Common::String readString(uint32 i);
124  Common::JSONValue *readValue();
125  Common::JSONValue *readArray();
126 
127 private:
128  Common::SeekableReadStream *_stream = nullptr;
129  Common::Array<int> _offsets;
130 };
131 
133 public:
135 
136  void open(Common::SeekableWriteStream *stream);
137  void write(const Common::JSONObject &obj);
138 
139 private:
140  void writeMarker(byte marker);
141  void writeString(const Common::String &s);
142  void writeRawString(const Common::String &s);
143  void writeNull();
144  void writeInt(int value);
145  void writeFloat(float value);
146  void writeArray(const Common::JSONArray &arr);
147  void writeValue(const Common::JSONValue *obj);
148  void writeMap(const Common::JSONObject &obj);
149  void writeKeys();
150  void writeKey(const Common::String &key);
151 
152 private:
153  Common::SeekableWriteStream *_s = nullptr;
155 };
156 
157 struct GGPackEntry {
158  int offset, size;
159 };
160 
162 
164 public:
165  friend class GGPackEntryReader;
166 
167 public:
168  GGPackDecoder();
169 
170  bool open(Common::SeekableReadStream *s, const XorKey &key);
171 
172  bool assetExists(const char *asset) { return _entries.contains(asset); }
173 
174 private:
175  XorKey _key;
176  GGPackEntries _entries;
177  Common::SeekableReadStream *_s = nullptr;
178 };
179 
180 class GGPackSet {
181 public:
182  void init(const XorKey &key);
183  bool assetExists(const char *asset);
184 
185  bool containsDLC() const;
186 
187 public:
189 };
190 
192 public:
193  GGBnutReader();
194 
195  bool open(Common::SeekableReadStream *s);
196 
197  uint32 read(void *dataPtr, uint32 dataSize) override;
198  bool eos() const override;
199 
200 private:
201  Common::SeekableReadStream *_s = nullptr;
202  int _cursor = 0;
203 };
204 
206 public:
208 
209  bool open(GGPackDecoder &pack, const Common::String &entry);
210  bool open(GGPackSet &packs, const Common::String &entry);
211 
212  uint32 read(void *dataPtr, uint32 dataSize) override;
213  bool eos() const override;
214 
215  int64 pos() const override;
216  int64 size() const override;
217  bool seek(int64 offset, int whence = SEEK_SET) override;
218 
219 private:
220  Common::Array<byte> _buf;
221  MemStream _ms;
222 };
223 
224 } // namespace Twp
225 
226 #endif
Definition: ggpack.h:163
Definition: str.h:59
Definition: ggpack.h:97
Definition: ggpack.h:77
Definition: ggpack.h:42
Definition: ggpack.h:191
Definition: stream.h:745
Definition: json.h:90
Definition: ggpack.h:157
Definition: ggpack.h:132
Definition: hashmap.h:85
Definition: ggpack.h:115
Definition: ggpack.h:60
Definition: stream.h:351
Definition: stream.h:385
Definition: ggpack.h:180
Definition: ggpack.h:34
Definition: ggpack.h:205
Definition: achievements_tables.h:27