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
32namespace Twp {
33
34struct 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
43public:
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
54private:
55 const byte *_buf = nullptr;
56 int64 _bufSize = 0;
57 int64 _pos = 0;
58};
59
61public:
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
71private:
72 byte *_buf = nullptr;
73 int64 _bufSize = 0;
74 int64 _pos = 0;
75};
76
78public:
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
89private:
90 Common::SeekableReadStream *_s = nullptr;
91 int _previous = 0;
92 int _start = 0;
93 int _size = 0;
94 XorKey _key;
95};
96
98public:
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
109private:
110 Common::SeekableReadStream *_s = nullptr;
111 int64 _start = 0;
112 int64 _size = 0;
113};
114
116public:
118
120
121private:
122 Common::JSONValue *readHash();
123 Common::String readString(uint32 i);
124 Common::JSONValue *readValue();
125 Common::JSONValue *readArray();
126
127private:
128 Common::SeekableReadStream *_stream = nullptr;
129 Common::Array<int> _offsets;
130};
131
133public:
135
136 void open(Common::SeekableWriteStream *stream);
137 void write(const Common::JSONObject &obj);
138
139private:
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
152private:
153 Common::SeekableWriteStream *_s = nullptr;
155};
156
158 int offset, size;
159};
160
162
164public:
165 friend class GGPackEntryReader;
166
167public:
169
170 bool open(Common::SeekableReadStream *s, const XorKey &key);
171
172 bool assetExists(const char *asset) { return _entries.contains(asset); }
173
174private:
175 XorKey _key;
176 GGPackEntries _entries;
177 Common::SeekableReadStream *_s = nullptr;
178};
179
181public:
182 void init(const XorKey &key);
183 bool assetExists(const char *asset);
184
185 bool containsDLC() const;
186
187public:
189};
190
192public:
193 GGBnutReader();
194
195 bool open(Common::SeekableReadStream *s);
196
197 uint32 read(void *dataPtr, uint32 dataSize) override;
198 bool eos() const override;
199
200private:
201 Common::SeekableReadStream *_s = nullptr;
202 int _cursor = 0;
203};
204
206public:
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
219private:
221 MemStream _ms;
222};
223
224} // namespace Twp
225
226#endif
Definition: hashmap.h:85
Definition: json.h:90
Definition: stream.h:385
Definition: stream.h:745
Definition: stream.h:351
Definition: str.h:59
Definition: ggpack.h:191
uint32 read(void *dataPtr, uint32 dataSize) override
bool eos() const override
Definition: ggpack.h:115
Definition: ggpack.h:132
Definition: ggpack.h:163
Definition: ggpack.h:205
uint32 read(void *dataPtr, uint32 dataSize) override
int64 pos() const override
int64 size() const override
bool eos() const override
bool seek(int64 offset, int whence=SEEK_SET) override
Definition: ggpack.h:180
Definition: ggpack.h:42
int64 size() const
uint32 read(void *dataPtr, uint32 dataSize)
int64 pos() const
bool eos() const
bool seek(int64 offset, int whence=SEEK_SET)
Definition: ggpack.h:60
uint32 write(const void *dataPtr, uint32 dataSize) override
bool seek(int64 offset, int whence=SEEK_SET) override
int64 size() const override
int64 pos() const override
Definition: ggpack.h:97
bool eos() const
bool seek(int64 offset, int whence=SEEK_SET)
int64 size() const
uint32 read(void *dataPtr, uint32 dataSize)
int64 pos() const
Definition: ggpack.h:77
bool seek(int64 offset, int whence=SEEK_SET)
uint32 read(void *dataPtr, uint32 dataSize)
int64 pos() const
bool eos() const
int64 size() const
bool contains(const Key &key) const
Definition: hashmap.h:598
Definition: ggpack.h:157
Definition: ggpack.h:34