2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __RESFILE_H
|
|
|
|
#define __RESFILE_H
|
|
|
|
|
|
|
|
#include "files.h"
|
|
|
|
|
|
|
|
class FResourceFile;
|
|
|
|
class FTexture;
|
|
|
|
|
2016-09-21 23:28:05 +00:00
|
|
|
// This holds a compresed Zip entry with all needed info to decompress it.
|
|
|
|
struct FCompressedBuffer
|
|
|
|
{
|
|
|
|
unsigned mSize;
|
|
|
|
unsigned mCompressedSize;
|
|
|
|
int mMethod;
|
|
|
|
int mZipFlags;
|
|
|
|
unsigned mCRC32;
|
|
|
|
char *mBuffer;
|
|
|
|
|
|
|
|
bool Decompress(char *destbuffer);
|
|
|
|
void Clean()
|
|
|
|
{
|
|
|
|
mSize = mCompressedSize = 0;
|
|
|
|
if (mBuffer != nullptr)
|
|
|
|
{
|
|
|
|
delete[] mBuffer;
|
|
|
|
mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
struct FResourceLump
|
|
|
|
{
|
|
|
|
friend class FResourceFile;
|
|
|
|
|
|
|
|
int LumpSize;
|
|
|
|
FString FullName; // only valid for files loaded from a non-wad archive
|
|
|
|
union
|
|
|
|
{
|
|
|
|
char Name[9];
|
|
|
|
|
2017-03-08 17:44:37 +00:00
|
|
|
uint32_t dwName; // These are for accessing the first 4 or 8 chars of
|
2017-03-09 18:54:41 +00:00
|
|
|
uint64_t qwName; // Name as a unit without breaking strict aliasing rules
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
2017-03-08 17:44:37 +00:00
|
|
|
uint8_t Flags;
|
|
|
|
int8_t RefCount;
|
2016-03-01 15:47:10 +00:00
|
|
|
char * Cache;
|
|
|
|
FResourceFile * Owner;
|
|
|
|
FTexture * LinkedTexture;
|
|
|
|
int Namespace;
|
|
|
|
|
|
|
|
FResourceLump()
|
|
|
|
{
|
|
|
|
Cache = NULL;
|
|
|
|
Owner = NULL;
|
|
|
|
Flags = 0;
|
|
|
|
RefCount = 0;
|
|
|
|
Namespace = 0; // ns_global
|
|
|
|
*Name = 0;
|
|
|
|
LinkedTexture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FResourceLump();
|
2018-03-11 11:33:46 +00:00
|
|
|
virtual FileRdr *GetReader();
|
|
|
|
virtual FileRdr NewReader();
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual int GetFileOffset() { return -1; }
|
|
|
|
virtual int GetIndexNum() const { return 0; }
|
|
|
|
void LumpNameSetup(FString iname);
|
|
|
|
void CheckEmbedded();
|
2016-09-21 23:28:05 +00:00
|
|
|
virtual FCompressedBuffer GetRawData();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
void *CacheLump();
|
|
|
|
int ReleaseCache();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int FillCache() = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FResourceFile
|
|
|
|
{
|
|
|
|
public:
|
2018-03-11 11:33:46 +00:00
|
|
|
FileRdr Reader;
|
2016-03-01 15:47:10 +00:00
|
|
|
const char *Filename;
|
|
|
|
protected:
|
2017-03-08 17:44:37 +00:00
|
|
|
uint32_t NumLumps;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-03-11 11:33:46 +00:00
|
|
|
FResourceFile(const char *filename, FileRdr &r);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// for archives that can contain directories
|
|
|
|
void PostProcessArchive(void *lumps, size_t lumpsize);
|
|
|
|
|
|
|
|
private:
|
2017-03-08 17:44:37 +00:00
|
|
|
uint32_t FirstLump;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-03-08 17:44:37 +00:00
|
|
|
int FilterLumps(FString filtername, void *lumps, size_t lumpsize, uint32_t max);
|
|
|
|
int FilterLumpsByGameType(int gametype, void *lumps, size_t lumpsize, uint32_t max);
|
|
|
|
bool FindPrefixRange(FString filter, void *lumps, size_t lumpsize, uint32_t max, uint32_t &start, uint32_t &end);
|
|
|
|
void JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t max);
|
2018-03-11 11:33:46 +00:00
|
|
|
static FResourceFile *DoOpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
public:
|
2018-03-11 11:33:46 +00:00
|
|
|
static FResourceFile *OpenResourceFile(const char *filename, FileRdr &file, bool quiet = false, bool containeronly = false);
|
|
|
|
static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false);
|
2016-03-01 15:47:10 +00:00
|
|
|
static FResourceFile *OpenDirectory(const char *filename, bool quiet = false);
|
|
|
|
virtual ~FResourceFile();
|
2018-03-11 11:33:46 +00:00
|
|
|
FileRdr *GetReader() { return &Reader; }
|
2017-03-08 17:44:37 +00:00
|
|
|
uint32_t LumpCount() const { return NumLumps; }
|
|
|
|
uint32_t GetFirstLump() const { return FirstLump; }
|
|
|
|
void SetFirstLump(uint32_t f) { FirstLump = f; }
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
virtual void FindStrifeTeaserVoices ();
|
|
|
|
virtual bool Open(bool quiet) = 0;
|
|
|
|
virtual FResourceLump *GetLump(int no) = 0;
|
2016-09-21 19:57:24 +00:00
|
|
|
FResourceLump *FindLump(const char *name);
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FUncompressedLump : public FResourceLump
|
|
|
|
{
|
|
|
|
int Position;
|
|
|
|
|
2018-03-11 11:33:46 +00:00
|
|
|
virtual FileRdr *GetReader();
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual int FillCache();
|
|
|
|
virtual int GetFileOffset() { return Position; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Base class for uncompressed resource files (WAD, GRP, PAK and single lumps)
|
|
|
|
class FUncompressedFile : public FResourceFile
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
FUncompressedLump * Lumps;
|
|
|
|
|
|
|
|
|
2018-03-11 11:33:46 +00:00
|
|
|
FUncompressedFile(const char *filename, FileRdr &r);
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual ~FUncompressedFile();
|
|
|
|
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct FExternalLump : public FResourceLump
|
|
|
|
{
|
|
|
|
const char *filename; // the actual file name. This is not necessarily the same as the lump name!
|
|
|
|
|
|
|
|
FExternalLump(const char *_filename, int filesize = -1);
|
|
|
|
~FExternalLump();
|
|
|
|
virtual int FillCache();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-02-22 06:21:19 +00:00
|
|
|
struct FMemoryFile : public FUncompressedFile
|
|
|
|
{
|
|
|
|
FMemoryFile(const char *_filename, const void *sdata, int length)
|
2018-03-11 11:33:46 +00:00
|
|
|
: FUncompressedFile(_filename, FileRdr())
|
2018-02-22 06:21:19 +00:00
|
|
|
{
|
2018-03-11 11:33:46 +00:00
|
|
|
Reader.OpenMemoryArray(sdata, length);
|
2018-02-22 06:21:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 12:46:29 +00:00
|
|
|
bool Open(bool quiet);
|
2018-02-22 06:21:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
};
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:29 +00:00
|
|
|
#endif
|