2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2022-03-03 19:24:46 +00:00
|
|
|
// Copyright (C) 1999-2022 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file w_wad.h
|
|
|
|
/// \brief WAD I/O functions, wad resource definitions (some)
|
|
|
|
|
|
|
|
#ifndef __W_WAD__
|
|
|
|
#define __W_WAD__
|
|
|
|
|
|
|
|
#ifdef HWRENDER
|
|
|
|
#include "hardware/hw_data.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2018-11-23 15:58:16 +00:00
|
|
|
// a raw entry of the wad directory
|
|
|
|
// NOTE: This sits here and not in w_wad.c because p_setup.c makes use of it to load map WADs inside PK3s.
|
2018-11-25 10:35:19 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack(1)
|
|
|
|
#endif
|
2018-11-23 15:58:16 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT32 filepos; // file offset of the resource
|
|
|
|
UINT32 size; // size of the resource
|
|
|
|
char name[8]; // name of the resource
|
|
|
|
} ATTRPACK filelump_t;
|
2018-11-25 10:35:19 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack()
|
|
|
|
#endif
|
|
|
|
|
2018-11-23 15:58:16 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// ==============================================================
|
|
|
|
// WAD FILE STRUCTURE DEFINITIONS
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
// header of a wad file
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char identification[4]; // should be "IWAD" or "PWAD"
|
|
|
|
UINT32 numlumps; // how many resources
|
|
|
|
UINT32 infotableofs; // the 'directory' of resources
|
|
|
|
} wadinfo_t;
|
|
|
|
|
2017-04-30 12:49:33 +00:00
|
|
|
// Available compression methods for lumps.
|
2017-11-03 03:13:13 +00:00
|
|
|
typedef enum
|
2017-10-07 19:52:27 +00:00
|
|
|
{
|
2017-11-03 03:13:13 +00:00
|
|
|
CM_NOCOMPRESSION,
|
2018-11-25 10:11:50 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2017-11-03 03:13:13 +00:00
|
|
|
CM_DEFLATE,
|
2018-11-25 10:11:50 +00:00
|
|
|
#endif
|
2017-11-03 03:13:13 +00:00
|
|
|
CM_LZF,
|
2017-10-07 19:52:27 +00:00
|
|
|
CM_UNSUPPORTED
|
|
|
|
} compmethod;
|
2017-04-30 12:49:33 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// a memory entry of the wad directory
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned long position; // filelump_t filepos
|
|
|
|
unsigned long disksize; // filelump_t size
|
2020-04-21 08:21:41 +00:00
|
|
|
char name[9]; // filelump_t name[] e.g. "LongEntr"
|
|
|
|
char *longname; // e.g. "LongEntryName"
|
|
|
|
char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension"
|
2021-03-23 02:56:55 +00:00
|
|
|
char *diskpath; // path to the file e.g. "/usr/games/srb2/Addon/Folder/Subfolder/LongEntryName.extension"
|
2020-04-21 08:21:41 +00:00
|
|
|
size_t size; // real (uncompressed) size
|
2017-10-07 19:52:27 +00:00
|
|
|
compmethod compression; // lump compression method
|
2014-03-15 16:59:03 +00:00
|
|
|
} lumpinfo_t;
|
|
|
|
|
|
|
|
// =========================================================================
|
2019-12-11 10:44:46 +00:00
|
|
|
// 'VIRTUAL' RESOURCES
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char name[9];
|
|
|
|
UINT8* data;
|
|
|
|
size_t size;
|
|
|
|
} virtlump_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t numlumps;
|
|
|
|
virtlump_t* vlumps;
|
|
|
|
} virtres_t;
|
|
|
|
|
2019-12-15 23:04:48 +00:00
|
|
|
virtres_t* vres_GetMap(lumpnum_t);
|
|
|
|
void vres_Free(virtres_t*);
|
|
|
|
virtlump_t* vres_Find(const virtres_t*, const char*);
|
2019-12-11 10:44:46 +00:00
|
|
|
|
|
|
|
// =========================================================================
|
2014-03-15 16:59:03 +00:00
|
|
|
// DYNAMIC WAD LOADING
|
|
|
|
// =========================================================================
|
|
|
|
|
2021-12-02 22:50:44 +00:00
|
|
|
// Maximum of files that can be loaded
|
|
|
|
// (there is a max of simultaneous open files anyway)
|
|
|
|
#ifdef ENFORCE_WAD_LIMIT
|
|
|
|
#define MAX_WADFILES 2048 // This cannot be any higher than UINT16_MAX.
|
|
|
|
#else
|
|
|
|
#define MAX_WADFILES UINT16_MAX
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 21:50:52 +00:00
|
|
|
#define MAX_WADPATH 512
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#define lumpcache_t void *
|
|
|
|
|
2017-04-30 12:49:33 +00:00
|
|
|
// Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further.
|
2017-11-10 22:36:37 +00:00
|
|
|
typedef enum restype
|
|
|
|
{
|
|
|
|
RET_WAD,
|
|
|
|
RET_SOC,
|
|
|
|
RET_LUA,
|
2018-11-24 21:58:35 +00:00
|
|
|
RET_PK3,
|
2021-03-23 02:56:55 +00:00
|
|
|
RET_FOLDER,
|
2018-11-24 21:58:35 +00:00
|
|
|
RET_UNKNOWN,
|
2018-11-23 15:58:16 +00:00
|
|
|
} restype_t;
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
typedef struct wadfile_s
|
|
|
|
{
|
2021-03-23 02:56:55 +00:00
|
|
|
char *filename, *path;
|
2017-11-10 22:36:37 +00:00
|
|
|
restype_t type;
|
2014-03-15 16:59:03 +00:00
|
|
|
lumpinfo_t *lumpinfo;
|
|
|
|
lumpcache_t *lumpcache;
|
2019-09-11 19:59:28 +00:00
|
|
|
lumpcache_t *patchcache;
|
2014-03-15 16:59:03 +00:00
|
|
|
UINT16 numlumps; // this wad's number of resources
|
2021-09-12 21:08:06 +00:00
|
|
|
UINT16 foldercount; // folder count
|
2014-03-15 16:59:03 +00:00
|
|
|
FILE *handle;
|
|
|
|
UINT32 filesize; // for network
|
|
|
|
UINT8 md5sum[16];
|
2019-01-07 18:00:27 +00:00
|
|
|
|
2017-05-27 13:01:26 +00:00
|
|
|
boolean important; // also network - !W_VerifyNMUSlumps
|
2014-03-15 16:59:03 +00:00
|
|
|
} wadfile_t;
|
|
|
|
|
2021-03-23 02:56:55 +00:00
|
|
|
#define WADFILENUM(lumpnum) (UINT16)((lumpnum)>>16) // wad file number in upper word
|
2014-03-15 16:59:03 +00:00
|
|
|
#define LUMPNUM(lumpnum) (UINT16)((lumpnum)&0xFFFF) // lump number for this pwad
|
|
|
|
|
|
|
|
extern UINT16 numwadfiles;
|
2021-12-02 22:50:44 +00:00
|
|
|
extern wadfile_t **wadfiles;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char **files;
|
|
|
|
size_t numfiles;
|
|
|
|
} addfilelist_t;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
void W_Shutdown(void);
|
|
|
|
|
2017-02-16 21:55:17 +00:00
|
|
|
// Opens a WAD file. Returns the FILE * handle for the file, or NULL if not found or could not be opened
|
|
|
|
FILE *W_OpenWadFile(const char **filename, boolean useerrors);
|
2014-03-15 16:59:03 +00:00
|
|
|
// Load and add a wadfile to the active wad files, returns numbers of lumps, INT16_MAX on error
|
2020-02-02 03:32:08 +00:00
|
|
|
UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup);
|
2021-03-23 02:56:55 +00:00
|
|
|
// Adds a folder as a file
|
|
|
|
UINT16 W_InitFolder(const char *path, boolean mainfile, boolean startup);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2020-02-02 03:32:08 +00:00
|
|
|
// W_InitMultipleFiles exits if a file was not found, but not if all is okay.
|
2021-12-02 22:50:44 +00:00
|
|
|
void W_InitMultipleFiles(addfilelist_t *list);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2021-03-23 02:56:55 +00:00
|
|
|
#define W_FileHasFolders(wadfile) ((wadfile)->type == RET_PK3 || (wadfile)->type == RET_FOLDER)
|
|
|
|
|
2021-09-13 01:53:51 +00:00
|
|
|
INT32 W_IsPathToFolderValid(const char *path);
|
2021-09-12 21:08:06 +00:00
|
|
|
char *W_GetFullFolderPath(const char *path);
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);
|
|
|
|
const char *W_CheckNameForNum(lumpnum_t lumpnum);
|
|
|
|
|
|
|
|
UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump); // checks only in one pwad
|
2020-04-25 22:39:52 +00:00
|
|
|
UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump);
|
2017-05-01 14:37:32 +00:00
|
|
|
|
2020-02-08 03:41:45 +00:00
|
|
|
/* Find the first lump after F_START for instance. */
|
|
|
|
UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump);
|
2017-05-01 14:37:32 +00:00
|
|
|
|
|
|
|
UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump);
|
2017-05-28 19:47:15 +00:00
|
|
|
UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlump);
|
2017-05-01 14:37:32 +00:00
|
|
|
UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump);
|
|
|
|
|
2017-05-18 19:13:18 +00:00
|
|
|
lumpnum_t W_CheckNumForMap(const char *name);
|
2014-03-15 16:59:03 +00:00
|
|
|
lumpnum_t W_CheckNumForName(const char *name);
|
2020-04-25 22:39:52 +00:00
|
|
|
lumpnum_t W_CheckNumForLongName(const char *name);
|
2014-03-15 16:59:03 +00:00
|
|
|
lumpnum_t W_GetNumForName(const char *name); // like W_CheckNumForName but I_Error on LUMPERROR
|
2020-04-25 22:39:52 +00:00
|
|
|
lumpnum_t W_GetNumForLongName(const char *name);
|
2015-01-01 19:50:31 +00:00
|
|
|
lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, const char *blockend);
|
2014-03-25 02:17:59 +00:00
|
|
|
UINT8 W_LumpExists(const char *name); // Lua uses this.
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump);
|
|
|
|
size_t W_LumpLength(lumpnum_t lumpnum);
|
|
|
|
|
2018-01-10 16:51:23 +00:00
|
|
|
boolean W_IsLumpWad(lumpnum_t lumpnum); // for loading maps from WADs in PK3s
|
2019-03-03 22:09:34 +00:00
|
|
|
boolean W_IsLumpFolder(UINT16 wad, UINT16 lump); // for detecting folder "lumps"
|
2018-01-10 16:51:23 +00:00
|
|
|
|
2018-11-27 13:57:32 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2018-11-23 15:58:16 +00:00
|
|
|
void zerr(int ret); // zlib error checking
|
2018-11-27 13:57:32 +00:00
|
|
|
#endif
|
2017-10-07 22:18:25 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, size_t offset);
|
|
|
|
size_t W_ReadLumpHeader(lumpnum_t lump, void *dest, size_t size, size_t offest); // read all or a part of a lump
|
|
|
|
void W_ReadLumpPwad(UINT16 wad, UINT16 lump, void *dest);
|
|
|
|
void W_ReadLump(lumpnum_t lump, void *dest);
|
|
|
|
|
|
|
|
void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
|
|
|
void *W_CacheLumpNum(lumpnum_t lump, INT32 tag);
|
|
|
|
void *W_CacheLumpNumForce(lumpnum_t lumpnum, INT32 tag);
|
|
|
|
|
|
|
|
boolean W_IsLumpCached(lumpnum_t lump, void *ptr);
|
2019-09-11 19:59:28 +00:00
|
|
|
boolean W_IsPatchCached(lumpnum_t lump, void *ptr);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
void *W_CacheLumpName(const char *name, INT32 tag);
|
|
|
|
void *W_CachePatchName(const char *name, INT32 tag);
|
2020-04-25 22:39:52 +00:00
|
|
|
void *W_CachePatchLongName(const char *name, INT32 tag);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2020-03-17 18:23:13 +00:00
|
|
|
// Returns either a Software patch, or an OpenGL patch.
|
|
|
|
// Performs any necessary conversions from PNG images.
|
|
|
|
void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
|
|
|
void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag);
|
|
|
|
|
|
|
|
// Returns a Software patch.
|
|
|
|
// Performs any necessary conversions from PNG images.
|
|
|
|
void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
|
|
|
void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
void W_UnlockCachedPatch(void *patch);
|
|
|
|
|
|
|
|
void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5);
|
|
|
|
|
2020-11-29 04:51:21 +00:00
|
|
|
int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#endif // __W_WAD__
|