2016-03-01 15:47:10 +00:00
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// WAD I/O functions.
//
//-----------------------------------------------------------------------------
# ifndef __W_WAD__
# define __W_WAD__
# include "files.h"
# include "doomdef.h"
# include "tarray.h"
class FResourceFile ;
struct FResourceLump ;
class FTexture ;
struct wadinfo_t
{
// Should be "IWAD" or "PWAD".
2017-03-08 17:47:52 +00:00
uint32_t Magic ;
uint32_t NumLumps ;
uint32_t InfoTableOfs ;
2016-03-01 15:47:10 +00:00
} ;
struct wadlump_t
{
2017-03-08 17:47:52 +00:00
uint32_t FilePos ;
uint32_t Size ;
2016-03-01 15:47:10 +00:00
char Name [ 8 ] ;
} ;
# define IWAD_ID MAKE_ID('I','W','A','D')
# define PWAD_ID MAKE_ID('P','W','A','D')
// [RH] Namespaces from BOOM.
typedef enum {
ns_hidden = - 1 ,
ns_global = 0 ,
ns_sprites ,
ns_flats ,
ns_colormaps ,
ns_acslibrary ,
ns_newtextures ,
ns_bloodraw ,
ns_bloodsfx ,
ns_bloodmisc ,
ns_strifevoices ,
ns_hires ,
ns_voxels ,
// These namespaces are only used to mark lumps in special subdirectories
// so that their contents doesn't interfere with the global namespace.
// searching for data in these namespaces works differently for lumps coming
// from Zips or other files.
ns_specialzipdirectory ,
ns_sounds ,
ns_patches ,
ns_graphics ,
ns_music ,
ns_firstskin ,
} namespace_t ;
enum ELumpFlags
{
2018-03-11 11:33:46 +00:00
LUMPF_MAYBEFLAT = 1 , // might be a flat outside F_START/END
LUMPF_ZIPFILE = 2 , // contains a full path
LUMPF_EMBEDDED = 4 , // from an embedded WAD
LUMPF_BLOODCRYPT = 8 , // encrypted
LUMPF_COMPRESSED = 16 , // compressed
LUMPF_SEQUENTIAL = 32 , // compressed but a sequential reader can be retrieved.
2016-03-01 15:47:10 +00:00
} ;
// [RH] Copy an 8-char string and uppercase it.
void uppercopy ( char * to , const char * from ) ;
// A lump in memory.
class FMemLump
{
public :
FMemLump ( ) ;
FMemLump ( const FMemLump & copy ) ;
FMemLump & operator = ( const FMemLump & copy ) ;
~ FMemLump ( ) ;
void * GetMem ( ) { return Block . Len ( ) = = 0 ? NULL : ( void * ) Block . GetChars ( ) ; }
size_t GetSize ( ) { return Block . Len ( ) ; }
FString GetString ( ) { return Block ; }
private :
FMemLump ( const FString & source ) ;
FString Block ;
friend class FWadCollection ;
} ;
2019-02-07 12:12:39 +00:00
struct FolderEntry
{
const char * name ;
unsigned lumpnum ;
} ;
2016-03-01 15:47:10 +00:00
class FWadCollection
{
public :
FWadCollection ( ) ;
~ FWadCollection ( ) ;
// The wadnum for the IWAD
2017-09-13 08:19:03 +00:00
int GetIwadNum ( ) { return IwadIndex ; }
void SetIwadNum ( int x ) { IwadIndex = x ; }
2016-03-01 15:47:10 +00:00
void InitMultipleFiles ( TArray < FString > & filenames ) ;
2018-03-11 17:32:00 +00:00
void AddFile ( const char * filename , FileReader * wadinfo = NULL ) ;
2016-03-01 15:47:10 +00:00
int CheckIfWadLoaded ( const char * name ) ;
const char * GetWadName ( int wadnum ) const ;
const char * GetWadFullName ( int wadnum ) const ;
int GetFirstLump ( int wadnum ) const ;
int GetLastLump ( int wadnum ) const ;
2018-02-22 11:51:45 +00:00
int GetLumpCount ( int wadnum ) const ;
2016-03-01 15:47:10 +00:00
int CheckNumForName ( const char * name , int namespc ) ;
int CheckNumForName ( const char * name , int namespc , int wadfile , bool exact = true ) ;
int GetNumForName ( const char * name , int namespc ) ;
2017-03-08 17:47:52 +00:00
inline int CheckNumForName ( const uint8_t * name ) { return CheckNumForName ( ( const char * ) name , ns_global ) ; }
2016-03-01 15:47:10 +00:00
inline int CheckNumForName ( const char * name ) { return CheckNumForName ( name , ns_global ) ; }
inline int CheckNumForName ( const FString & name ) { return CheckNumForName ( name . GetChars ( ) ) ; }
2017-03-08 17:47:52 +00:00
inline int CheckNumForName ( const uint8_t * name , int ns ) { return CheckNumForName ( ( const char * ) name , ns ) ; }
2016-03-01 15:47:10 +00:00
inline int GetNumForName ( const char * name ) { return GetNumForName ( name , ns_global ) ; }
inline int GetNumForName ( const FString & name ) { return GetNumForName ( name . GetChars ( ) , ns_global ) ; }
2017-03-08 17:47:52 +00:00
inline int GetNumForName ( const uint8_t * name ) { return GetNumForName ( ( const char * ) name ) ; }
inline int GetNumForName ( const uint8_t * name , int ns ) { return GetNumForName ( ( const char * ) name , ns ) ; }
2016-03-01 15:47:10 +00:00
int CheckNumForFullName ( const char * name , bool trynormal = false , int namespc = ns_global ) ;
int CheckNumForFullName ( const char * name , int wadfile ) ;
int GetNumForFullName ( const char * name ) ;
inline int CheckNumForFullName ( const FString & name , bool trynormal = false , int namespc = ns_global ) { return CheckNumForFullName ( name . GetChars ( ) , trynormal , namespc ) ; }
inline int CheckNumForFullName ( const FString & name , int wadfile ) { return CheckNumForFullName ( name . GetChars ( ) , wadfile ) ; }
inline int GetNumForFullName ( const FString & name ) { return GetNumForFullName ( name . GetChars ( ) ) ; }
void SetLinkedTexture ( int lump , FTexture * tex ) ;
FTexture * GetLinkedTexture ( int lump ) ;
void ReadLump ( int lump , void * dest ) ;
2018-11-10 10:56:18 +00:00
TArray < uint8_t > ReadLumpIntoArray ( int lump , int pad = 0 ) ; // reads lump into a writable buffer and optionally adds some padding at the end. (FMemLump isn't writable!)
2016-03-01 15:47:10 +00:00
FMemLump ReadLump ( int lump ) ;
FMemLump ReadLump ( const char * name ) { return ReadLump ( GetNumForName ( name ) ) ; }
2018-03-11 17:32:00 +00:00
FileReader OpenLumpReader ( int lump ) ; // opens a reader that redirects to the containing file's one.
FileReader ReopenLumpReader ( int lump , bool alwayscache = false ) ; // opens an independent reader.
2018-03-10 12:46:35 +00:00
2016-03-01 15:47:10 +00:00
int FindLump ( const char * name , int * lastlump , bool anyns = false ) ; // [RH] Find lumps with duplication
int FindLumpMulti ( const char * * names , int * lastlump , bool anyns = false , int * nameindex = NULL ) ; // same with multiple possible names
bool CheckLumpName ( int lump , const char * name ) ; // [RH] True if lump's name == name
2017-03-08 17:47:52 +00:00
static uint32_t LumpNameHash ( const char * name ) ; // [RH] Create hash key from an 8-char name
2016-03-01 15:47:10 +00:00
int LumpLength ( int lump ) const ;
int GetLumpOffset ( int lump ) ; // [RH] Returns offset of lump in the wadfile
int GetLumpFlags ( int lump ) ; // Return the flags for this lump
void GetLumpName ( char * to , int lump ) const ; // [RH] Copies the lump name to to using uppercopy
void GetLumpName ( FString & to , int lump ) const ;
const char * GetLumpFullName ( int lump ) const ; // [RH] Returns the lump's full name
FString GetLumpFullPath ( int lump ) const ; // [RH] Returns wad's name + lump's full name
int GetLumpFile ( int lump ) const ; // [RH] Returns wadnum for a specified lump
int GetLumpNamespace ( int lump ) const ; // [RH] Returns the namespace a lump belongs to
int GetLumpIndexNum ( int lump ) const ; // Returns the RFF index number for this lump
2018-03-19 19:02:38 +00:00
FResourceLump * GetLumpRecord ( int lump ) const ; // Returns the FResourceLump, in case the caller wants to have direct access to the lump cache.
2016-03-01 15:47:10 +00:00
bool CheckLumpName ( int lump , const char * name ) const ; // [RH] Returns true if the names match
2019-02-11 23:19:44 +00:00
unsigned GetLumpsInFolder ( const char * path , TArray < FolderEntry > & result , bool atomic ) const ;
2016-03-01 15:47:10 +00:00
bool IsEncryptedFile ( int lump ) const ;
int GetNumLumps ( ) const ;
int GetNumWads ( ) const ;
int AddExternalFile ( const char * filename ) ;
2018-02-22 06:21:19 +00:00
int AddData ( const char * filename , int length ) ;
2016-03-01 15:47:10 +00:00
protected :
struct LumpRecord ;
TArray < FResourceFile * > Files ;
TArray < LumpRecord > LumpInfo ;
2018-11-02 08:51:44 +00:00
TArray < uint32_t > Hashes ; // one allocation for all hash lists.
2017-03-08 17:47:52 +00:00
uint32_t * FirstLumpIndex ; // [RH] Hashing stuff moved out of lumpinfo structure
uint32_t * NextLumpIndex ;
2016-03-01 15:47:10 +00:00
2017-03-08 17:47:52 +00:00
uint32_t * FirstLumpIndex_FullName ; // The same information for fully qualified paths from .zips
uint32_t * NextLumpIndex_FullName ;
2016-03-01 15:47:10 +00:00
2018-11-02 08:51:44 +00:00
uint32_t NumLumps = 0 ; // Not necessarily the same as LumpInfo.Size()
2017-03-08 17:47:52 +00:00
uint32_t NumWads ;
2016-03-01 15:47:10 +00:00
2017-09-13 08:19:03 +00:00
int IwadIndex ;
2016-03-01 15:47:10 +00:00
void InitHashChains ( ) ; // [RH] Set up the lumpinfo hashing
private :
void RenameSprites ( ) ;
void RenameNerve ( ) ;
void FixMacHexen ( ) ;
void DeleteAll ( ) ;
2019-09-13 11:55:53 +00:00
void MoveLumpsInFolder ( const char * ) ;
2018-03-11 17:32:00 +00:00
FileReader * GetFileReader ( int wadnum ) ; // Gets a FileReader object to the entire WAD
2016-03-01 15:47:10 +00:00
} ;
extern FWadCollection Wads ;
# endif