-
Notifications
You must be signed in to change notification settings - Fork 3
/
ResourceFile.h
359 lines (299 loc) · 8.58 KB
/
ResourceFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#ifndef __RESOURCEFILE_H
#define __RESOURCEFILE_H
#include "tarray.h"
#include "doomtype.h"
#include "files.h"
struct C7zArchive;
struct FZipCentralDirectoryInfo;
struct MapRecord
{
QWORD maplump;
const char* mapname;
};
//==========================================================================
//
//
//
//==========================================================================
class CResourceFile
{
CResourceFile * parent;
protected:
char * m_Filename;
int m_NumLumps;
static void SortMapList(TArray<MapRecord> & array);
public:
QWORD m_LumpStart;
CResourceFile(void);
virtual ~CResourceFile(void);
virtual int FindLump(const char * name)=0;
virtual int FindLumpByFullName(const char * name) { return -1; }
virtual void FindLumps(const char * name, TArray<QWORD> & list) =0;
virtual int GetLumpSize(int lump)=0;
virtual void * ReadLump(int lump)=0;
virtual void ReadLump(int lump, void * buffer)=0;
virtual void ReplaceLump(int lump, void * data, int length)=0;
virtual void Save(const char * filename)=0;
virtual void * CreateInMemory(int * length)=0;
virtual void GetMapList(TArray<MapRecord> & array) {}
virtual const char * GetLumpName(int lump)=0;
virtual const char * GetFullLumpName(int lump) { return NULL; }
virtual void GetAllSprites(TArray<QWORD> & list) {}
virtual void GetAllFlats(TArray<QWORD> & list) {}
virtual void GetAllTextures(TArray<QWORD> & list) {}
void SetParent(CResourceFile * p)
{
parent=p;
}
CResourceFile * GetParent() const
{
return parent;
}
const char * GetName() const
{
return m_Filename;
}
static CResourceFile * GetResourceFile(int no)
{
if (no>=0 && no<(int)OpenFiles.Size ()) return OpenFiles[no];
else return NULL;
}
void ChangeIndex(int newindex)
{
m_LumpStart=newindex;
}
static QWORD GlobalFindLump(const char * name);
static QWORD GlobalFindLumpByFullName(const char * name);
static bool GlobalFindLumps(const char * name, TArray<QWORD> & list);
static const char * GlobalGetLumpName(QWORD lump);
static const char * GlobalGetFullLumpName(QWORD lump);
static int GlobalGetLumpSize(QWORD lump);
static void * GlobalReadLump(QWORD lump);
static void GlobalReadLump(QWORD lump, void * buffer);
static void GlobalReplaceLump(QWORD lump, void * data, int length);
static void GlobalGetAllSprites(TArray<QWORD> & list);
static void GlobalGetAllFlats(TArray<QWORD> & list);
static void GlobalGetAllTextures(TArray<QWORD> & list);
static void AddResourceFile(const char * filename);
static void CloseResourceFile(const char * filename);
static void OpenResourceFiles(const TArray<const char *> & filenames);
static void OpenResourceFiles(const wxArrayString & filenames);
static void CloseResourceFiles();
static void SwitchIWAD(const char *newiwad);
static void GetMapList(const char * wad, TArray<MapRecord> & array);
static TArray<CResourceFile *> OpenFiles;
};
//==========================================================================
//
//
//
//==========================================================================
class CSingleLump : public CResourceFile
{
char * m_Data;
int m_Length;
char lumpname[9];
bool ismap;
public:
CSingleLump(const char * filename);
~CSingleLump(void);
virtual int FindLump(const char * name);
virtual void FindLumps(const char * name, TArray<QWORD> & list);
virtual int GetLumpSize(int lump);
virtual void * ReadLump(int lump);
virtual void ReadLump(int lump, void * buffer);
virtual void ReplaceLump(int lump, void * data, int length);
virtual void Save(const char * filename);
virtual void * CreateInMemory(int * length);
virtual const char * GetLumpName(int lump);
virtual void GetMapList(TArray<MapRecord> & array);
};
//==========================================================================
//
//
//
//==========================================================================
struct CWADLumpInfo
{
DWORD offset;
DWORD length;
char name[8];
};
struct CWADLump
{
DWORD offset;
DWORD length;
char name[9];
char * data;
};
class CWADFile : public CResourceFile
{
TArray<CWADLump> lumps;
TArray<MapRecord> mapnames;
bool IWAD;
FILE * m_File;
public:
CWADFile(const char * filename);
CWADFile(const char * name, const char * memory);
~CWADFile(void);
virtual int FindLump(const char * name);
virtual void FindLumps(const char * name, TArray<QWORD> & list);
virtual int GetLumpSize(int lump);
virtual void * ReadLump(int lump);
virtual void ReadLump(int lump, void * buffer);
virtual void ReplaceLump(int lump, void * data, int length);
virtual void Save(const char * filename);
virtual void * CreateInMemory(int * length);
virtual void GetMapList(TArray<MapRecord> & array);
virtual const char * GetLumpName(int lump);
virtual void GetAllSprites(TArray<QWORD> & list);
virtual void GetAllFlats(TArray<QWORD> & list);
virtual void GetAllTextures(TArray<QWORD> & list);
};
//==========================================================================
//
//
//
//==========================================================================
struct GrpEntry
{
char Name[12];
DWORD Size;
};
struct CGrpLump
{
char name[13];
DWORD length;
DWORD offset;
char * data;
};
class CGrpFile : public CResourceFile
{
TArray<CGrpLump> lumps;
TArray<MapRecord> mapnames;
bool IWAD;
FILE * m_File;
public:
CGrpFile(const char * filename);
~CGrpFile(void);
virtual int FindLump(const char * name);
virtual void FindLumps(const char * name, TArray<QWORD> & list);
virtual int GetLumpSize(int lump);
virtual void * ReadLump(int lump);
virtual void ReadLump(int lump, void * buffer);
virtual void ReplaceLump(int lump, void * data, int length);
virtual void Save(const char * filename);
virtual void * CreateInMemory(int * length);
virtual void GetMapList(TArray<MapRecord> & array);
virtual const char * GetLumpName(int lump);
};
struct RFFInfo
{
// Should be "RFF\x18"
uint32_t Magic;
uint32_t Version;
uint32_t DirOfs;
uint32_t NumLumps;
};
struct RFFLump
{
uint32_t DontKnow1[4];
uint32_t FilePos;
uint32_t Size;
uint32_t DontKnow2;
uint32_t Time;
uint8_t Flags;
char Extension[3];
char Name[8];
uint32_t IndexNum; // Used by .sfx, possibly others
};
struct CRffLump
{
char name[13];
bool encrypted;
DWORD length;
DWORD offset;
char* data;
};
class CRffFile : public CResourceFile
{
TArray<CRffLump> lumps;
TArray<MapRecord> mapnames;
bool IWAD;
FILE* m_File;
public:
CRffFile(const char* filename);
~CRffFile(void);
virtual int FindLump(const char* name);
virtual void FindLumps(const char* name, TArray<QWORD>& list);
virtual int GetLumpSize(int lump);
virtual void* ReadLump(int lump);
virtual void ReadLump(int lump, void* buffer);
virtual void ReplaceLump(int lump, void* data, int length);
virtual void Save(const char* filename);
virtual void* CreateInMemory(int* length);
virtual void GetMapList(TArray<MapRecord>& array);
virtual const char* GetLumpName(int lump);
};
//==========================================================================
//
//
//
//==========================================================================
//
// WADFILE I/O related stuff.
//
struct LumpRecord
{
char * fullname; // only valid for files loaded from a .zip file
char name[9];
BYTE method; // zip compression method
WORD flags;
WORD gpflags;
int position;
int size;
int compressedsize;
void * data;
};
class CZipFile :
public CResourceFile
{
protected:
FileReader *fin;
TArray<LumpRecord> lumps;
TArray<CWADFile *> embeddedWADs;
TArray<MapRecord> mapnames;
virtual void ReadLump(LumpRecord *l, void *Ptr);
private:
static DWORD FindCentralDir(FileReader * fin);
void ReadDirectory(FileReader *wadinfo);
public:
CZipFile(const char * filename, bool readdir = true);
~CZipFile(void);
virtual int FindLump(const char * name);
virtual int FindLumpByFullName(const char * name);
void FindLumps(const char * name, TArray<QWORD> & list);
virtual int GetLumpSize(int lump);
virtual void * ReadLump(int lump);
virtual void ReadLump(int lump, void * buffer);
virtual void ReplaceLump(int lump, void * data, int length);
virtual void Save(const char * filename);
virtual void * CreateInMemory(int * length);
virtual void GetMapList(TArray<MapRecord> & array);
virtual const char * GetLumpName(int lump);
virtual void GetAllSprites(TArray<QWORD> & list);
virtual void GetAllFlats(TArray<QWORD> & list);
virtual void GetAllTextures(TArray<QWORD> & list);
virtual const char * GetFullLumpName(int lump);
};
class C7zFile : public CZipFile
{
C7zArchive *Archive;
void ReadDirectory(FileReader *wadinfo);
protected:
virtual void ReadLump(LumpRecord *l, void *Ptr);
public:
C7zFile(const char * filename);
~C7zFile(void);
};
#endif