#ifndef __C_WAD_READER_H_INCLUDED__
#define __C_WAD_READER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_
#include "IReferenceCounted.h"
#include "IReadFile.h"
#include "irrArray.h"
#include "irrString.h"
#include "IFileSystem.h"
#include "CFileList.h"
namespace irr
{
namespace io
{
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( push, packing )
# pragma pack( 1 )
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error compiler not supported
#endif
enum eWADFileTypes
{
WAD_FORMAT_UNKNOWN = 0,
WAD_FORMAT_QUAKE2 = 1,
WAD_FORMAT_HALFLIFE = 2,
WAD_CMP_NONE = 0,
WAD_CMP_LZSS = 1,
WAD_TYP_NONE = 0,
WAD_TYP_LABEL = 1,
WAD_TYP_LUMPY = 64,
WAD_TYP_PALETTE = 64,
WAD_TYP_QTEX = 65,
WAD_TYP_QPIC = 66,
WAD_TYP_SOUND = 67,
WAD_TYP_MIPTEX = 68,
WAD_TYP_MIPTEX_HALFLIFE = 67,
WAD_TYP_FONT = 70,
};
struct SWADFileHeader
{
c8 tag[4];
u32 numlumps;
u32 infotableofs;
} PACK_STRUCT;
struct SWADFileEntryOriginal
{
u32 filepos;
u32 disksize;
u32 size;
u8 type;
u8 compression;
u8 pad[2];
u8 name[16];
} PACK_STRUCT;
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop, packing )
#endif
#undef PACK_STRUCT
struct SWADFileEntry
{
io::path simpleFileName;
bool operator < (const SWADFileEntry& other) const
{
return simpleFileName < other.simpleFileName;
}
io::path wadFileName;
SWADFileEntryOriginal header;
};
class CArchiveLoaderWAD : public IArchiveLoader
{
public:
CArchiveLoaderWAD(io::IFileSystem* fs);
virtual bool isALoadableFileFormat(const io::path& filename) const;
virtual bool isALoadableFileFormat(io::IReadFile* file) const;
virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const;
virtual IFileArchive* createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const;
virtual io::IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const;
private:
io::IFileSystem* FileSystem;
};
class CWADReader : public IFileArchive, virtual CFileList
{
public:
CWADReader(IReadFile* file, bool ignoreCase, bool ignorePaths);
virtual ~CWADReader();
virtual const io::path& getArchiveName() const;
virtual IReadFile* createAndOpenFile(const io::path& filename);
virtual IReadFile* createAndOpenFile(u32 index);
virtual const IFileList* getFileList() const;
virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_WAD; }
private:
io::path Type;
bool scanLocalHeader();
void extractFilename(SWADFileEntry* entry);
io::path Base;
io::path MountPoint;
IReadFile* File;
eWADFileTypes WadType;
SWADFileHeader Header;
io::IFileSystem* FileSystem;
};
}
}
#endif
#endif