#pragma pack(1)
#define FMOD_FNAME_SIZE 30
#define FSB_PADDING 16384
#define FSOUND_LOADMEMORYIOP 0x20000000

#define GetLowShort(x) ((unsigned short) (x))
#define GetHighShort(x) ((unsigned short) (((unsigned int) (x) >> 16) & 0xFFFF))

typedef struct
{
	unsigned int numFiles;
	unsigned int usedSize; // WAD file is padded to next 16384 byte multiple
} DATHeader;

typedef struct
{
	unsigned int qbKey;
	unsigned int offset;
	unsigned int fileSize;
	char reserved[8];
	char *fileData;
	char fileNameInFsb[FMOD_FNAME_SIZE + 1];
} DATEntry;

typedef struct
{
	DATHeader header;
	DATEntry *entries;
	char *datFileName;
	char *wadFileName;
} DATInfo;



void EndianSwap(unsigned int *x);
int ReadDatInfo(DATInfo *info);

int MakeAudioList(DATInfo *info);
int MakeAudioListSimple(DATInfo *info);

int CheckFileIdExists(DATInfo *info, unsigned int fileId);
int QbKeyStrToFileId(DATInfo *info, char *qbKeyStr, int *extraParam);

int ExtractAllFiles(DATInfo *info);
int ExtractWadFile(DATInfo *info, unsigned int fileId, char *outFileName);
int ReplaceWadItem(DATInfo *info, unsigned int fileId, char *addFileName);

int FreeDatInfo (DATInfo *info);

size_t fread_be (void *ptr, size_t size, size_t count, FILE *stream);
size_t fwrite_be (const void *ptr, size_t size, size_t count, FILE *stream);

int WriteOut(DATInfo *info);
