qzdoom/src/w_wad.h

261 lines
8.0 KiB
C
Raw Normal View History

// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// DESCRIPTION:
// WAD I/O functions.
//
//-----------------------------------------------------------------------------
#ifndef __W_WAD__
#define __W_WAD__
#include "files.h"
#include "doomdef.h"
#include "tarray.h"
// [RH] Compare wad header as ints instead of chars
#define IWAD_ID MAKE_ID('I','W','A','D')
#define PWAD_ID MAKE_ID('P','W','A','D')
#define RFF_ID MAKE_ID('R','F','F',0x1a)
#define ZIP_ID MAKE_ID('P','K',3,4)
#define GRP_ID_0 MAKE_ID('K','e','n','S')
#define GRP_ID_1 MAKE_ID('i','l','v','e')
#define GRP_ID_2 MAKE_ID('r','m','a','n')
// [RH] Remove limit on number of WAD files
struct wadlist_t
{
wadlist_t *next;
char name[1]; // +size of string
};
extern wadlist_t *wadfiles;
//
// TYPES
//
struct wadinfo_t
{
// Should be "IWAD" or "PWAD".
DWORD Magic;
DWORD NumLumps;
DWORD InfoTableOfs;
};
struct wadlump_t
{
DWORD FilePos;
DWORD Size;
char Name[8];
};
enum
{
LUMPF_BLOODCRYPT = 1, // Lump uses Blood-style encryption
LUMPF_COMPRESSED = 2, // Zip-compressed
LUMPF_ZIPFILE = 4, // Inside a Zip file - used to enforce use of special directories insize Zips
LUMPF_NEEDFILESTART = 8, // Still need to process local file header to find file start inside a zip
LUMPF_EXTERNAL = 16, // Lump is from an external file that won't be kept open permanently
};
// [RH] Namespaces from BOOM.
typedef enum {
ns_global = 0,
ns_sprites,
ns_flats,
ns_colormaps,
ns_acslibrary,
ns_newtextures,
ns_bloodraw,
ns_bloodsfx,
ns_bloodmisc,
ns_strifevoices,
2006-04-14 16:25:57 +00:00
ns_hires,
// 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,
} namespace_t;
// [RH] Copy an 8-char string and uppercase it.
void uppercopy (char *to, const char *from);
2006-06-15 03:31:19 +00:00
// Perform Blood encryption/decryption.
void BloodCrypt (void *data, int key, int len);
// Locate central directory in a zip file.
DWORD Zip_FindCentralDir(FileReader * fin);
// A very loose reference to a lump on disk. This is really just a wrapper
// around the main wad's FILE object with a different length recorded. Since
// two lumps from the same wad share the same FILE, you cannot read from
// both of them independantly.
class FWadLump : public FileReader
{
public:
FWadLump ();
FWadLump (const FWadLump &copy);
2006-04-14 16:25:57 +00:00
#ifdef _DEBUG
FWadLump & operator= (const FWadLump &copy);
#endif
~FWadLump();
long Seek (long offset, int origin);
long Read (void *buffer, long len);
char *Gets(char *strbuf, int len);
private:
2006-06-15 03:31:19 +00:00
FWadLump (const FileReader &reader, long length, bool encrypted);
FWadLump (FILE *file, long length);
2006-04-14 16:25:57 +00:00
FWadLump (char * data, long length, bool destroy);
2006-06-15 03:31:19 +00:00
char *SourceData;
bool DestroySource;
bool Encrypted;
friend class FWadCollection;
};
2006-04-14 16:25:57 +00:00
// 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(); }
- Updated lempar.c to v1.31. - Added .txt files to the list of types (wad, zip, and pk3) that can be loaded without listing them after -file. - Fonts that are created by the ACS setfont command to wrap a texture now support animated textures. - FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn with the hardware 2D path instead of being restricted to the game palette. - Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1 on a Radeon 9000. - Added back the off-by-one palette handling, but in a much more limited scope than before. The skipped entry is assumed to always be at 248, and it is assumed that all Shader Model 1.4 cards suffer from this. That's because all SM1.4 cards are based on variants of the ATI R200 core, and the RV250 in a Radeon 9000 craps up like this. I see no reason to assume that other flavors of the R200 are any different. (Interesting note: With the Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the debug Direct3D 9 runtime, but it works perfectly fine with the retail Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its math inside pixel shaders. That would explain perfectly why I can't use constants greater than 1 with PS1.4 and why it can't do an exact mapping to every entry in the color palette. - Fixed: The software shaded drawer did not work for 2D, because its selected "color"map was replaced with the identitymap before being used. - Fixed: I cannot use Printf to output messages before the framebuffer was completely setup, meaning that Shader Model 1.4 cards could not change resolution. - I have decided to let remap palettes specify variable alpha values for their colors. D3DFB no longer forces them to 255. - Updated re2c to version 0.12.3. - Fixed: A_Wander used threshold as a timer, when it should have used reactiontime. - Fixed: A_CustomRailgun would not fire at all for actors without a target when the aim parameter was disabled. - Made the warp command work in multiplayer, again courtesy of Karate Chris. - Fixed: Trying to spawn a bot while not in a game made for a crashing time. (Patch courtesy of Karate Chris.) - Removed some floating point math from hu_scores.cpp that somebody's GCC gave warnings for (not mine, though). - Fixed: The SBarInfo drawbar command crashed if the sprite image was unavailable. - Fixed: FString::operator=(const char *) did not release its old buffer when being assigned to the null string. - The scanner no longer has an upper limit on the length of strings it accepts, though short strings will be faster than long ones. - Moved all the text scanning functions into a class. Mainly, this means that multiple script scanner states can be stored without being forced to do so recursively. I think I might be taking advantage of that in the near future. Possibly. Maybe. - Removed some potential buffer overflows from the decal parser. - Applied Blzut3's SBARINFO update #9: * Fixed: When using even length values in drawnumber it would cap to a 98 value instead of a 99 as intended. * The SBarInfo parser can now accept negatives for coordinates. This doesn't allow much right now, but later I plan to add better fullscreen hud support in which the negatives will be more useful. This also cleans up the source a bit since all calls for (x, y) coordinates are with the function getCoordinates(). - Added support for stencilling actors. - Added support for non-black colors specified with DTA_ColorOverlay to the software renderer. - Fixed: The inverse, gold, red, and green fixed colormaps each allocated space for 32 different colormaps, even though each only used the first one. - Added two new blending flags to make reverse subtract blending more useful: STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that gets blended with the background, since that seems like a good idea for reverse subtraction. They also work with the other two blending operations. - Added subtract and reverse subtract blending operations to the renderer. Since the ERenderStyle enumeration was getting rather unwieldy, I converted it into a new FRenderStyle structure that lets each parameter of the blending equation be set separately. This simplified the set up for the blend quite a bit, and it means a number of new combinations are available by setting the parameters properly. SVN r710 (trunk)
2008-01-25 23:57:44 +00:00
FString GetString () { return Block; }
private:
FMemLump (const FString &source);
FString Block;
friend class FWadCollection;
};
class FWadCollection
{
public:
FWadCollection ();
2006-04-14 16:25:57 +00:00
~FWadCollection ();
// The wadnum for the IWAD
enum { IWAD_FILENUM = 1 };
void InitMultipleFiles (wadlist_t **filenames);
2006-04-14 16:25:57 +00:00
void AddFile (const char *filename, const char * data=NULL,int length=-1);
int CheckIfWadLoaded (const char *name);
const char *GetWadName (int wadnum) const;
const char *GetWadFullName (int wadnum) const;
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);
inline int CheckNumForName (const BYTE *name) { return CheckNumForName ((const char *)name, ns_global); }
inline int CheckNumForName (const char *name) { return CheckNumForName (name, ns_global); }
inline int CheckNumForName (const BYTE *name, int ns) { return CheckNumForName ((const char *)name, ns); }
inline int GetNumForName (const char *name) { return GetNumForName (name, ns_global); }
inline int GetNumForName (const BYTE *name) { return GetNumForName ((const char *)name); }
inline int GetNumForName (const BYTE *name, int ns) { return GetNumForName ((const char *)name, ns); }
int CheckNumForFullName (const char *name, bool trynormal = false, int namespc = ns_global);
2006-04-14 16:25:57 +00:00
int CheckNumForFullName (const char *name, int wadfile);
int GetNumForFullName (const char *name);
void ReadLump (int lump, void *dest);
FMemLump ReadLump (int lump);
FMemLump ReadLump (const char *name) { return ReadLump (GetNumForName (name)); }
FWadLump OpenLumpNum (int lump);
FWadLump OpenLumpName (const char *name) { return OpenLumpNum (GetNumForName (name)); }
FWadLump *ReopenLumpNum (int lump); // Opens a new, independent FILE
FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication
bool CheckLumpName (int lump, const char *name); // [RH] True if lump's name == name
static DWORD LumpNameHash (const char *name); // [RH] Create hash key from an 8-char name
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
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
bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match
2006-04-14 12:58:52 +00:00
bool IsUncompressedFile(int lump) const;
2006-06-15 03:31:19 +00:00
bool IsEncryptedFile(int lump) const;
2006-04-14 16:25:57 +00:00
int GetNumLumps () const;
int GetNumWads () const;
int AddExternalFile(const char *filename);
protected:
class WadFileRecord;
struct LumpRecord;
DWORD *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure
DWORD *NextLumpIndex;
DWORD *FirstLumpIndex_FullName; // The same information for fully qualified paths from .zips
DWORD *NextLumpIndex_FullName;
2006-04-14 16:25:57 +00:00
TArray<LumpRecord> LumpInfo;
TArray<WadFileRecord *>Wads;
DWORD NumLumps; // Not necessarily the same as LumpInfo.Size()
DWORD NumWads;
void SkinHack (int baselump);
void InitHashChains (); // [RH] Set up the lumpinfo hashing
// [RH] Combine multiple marked ranges of lumps into one.
int MergeLumps (const char *start, const char *end, int name_space);
bool IsMarker (const LumpRecord *lump, const char *marker) const;
void FindStrifeTeaserVoices ();
private:
2006-04-14 16:25:57 +00:00
static int STACK_ARGS lumpcmp(const void * a, const void * b);
void ScanForFlatHack (int startlump);
void RenameSprites (int startlump);
void SetLumpAddress(LumpRecord *l);
void DeleteAll();
};
extern FWadCollection Wads;
#endif