- more file system refactoring.

* moved the sprite renaming out of the file system entirely into a caller-provided callback.
* renamed several functions to closer match the terms of a file system.
* moved the VM interface out of the implementation.
This commit is contained in:
Christoph Oelckers 2020-04-11 13:26:42 +02:00
parent 6bccde3b51
commit c1bb7de23a
61 changed files with 929 additions and 767 deletions

View file

@ -36,6 +36,8 @@
#include "cmdlib.h" #include "cmdlib.h"
#include "findfile.h" #include "findfile.h"
#include "files.h"
#include "md5.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -1032,3 +1034,36 @@ FString M_ZLibError(int zerr)
return errs[-zerr - 1]; return errs[-zerr - 1];
} }
} }
void md5Update(FileReader& file, MD5Context& md5, unsigned len)
{
uint8_t readbuf[8192];
unsigned t;
while (len > 0)
{
t = std::min<unsigned>(len, sizeof(readbuf));
len -= t;
t = (long)file.Read(readbuf, t);
md5.Update(readbuf, t);
}
}
//==========================================================================
//
// uppercoppy
//
// [RH] Copy up to 8 chars, upper-casing them in the process
//==========================================================================
void uppercopy(char* to, const char* from)
{
int i;
for (i = 0; i < 8 && from[i]; i++)
to[i] = toupper(from[i]);
for (; i < 8; i++)
to[i] = 0;
}

View file

@ -84,4 +84,10 @@ inline int32_t Scale(int32_t a, int32_t b, int32_t c)
return (int32_t)(((int64_t)a * b) / c); return (int32_t)(((int64_t)a * b) / c);
} }
class FileReader;
struct MD5Context;
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
void uppercopy(char* to, const char* from);
#endif #endif

View file

@ -848,7 +848,7 @@ CCMD (wdir)
Printf ("usage: wdir <wadfile>\n"); Printf ("usage: wdir <wadfile>\n");
return; return;
} }
int wadnum = fileSystem.CheckIfWadLoaded (argv[1]); int wadnum = fileSystem.CheckIfResourceFileLoaded (argv[1]);
if (wadnum < 0) if (wadnum < 0)
{ {
Printf ("%s must be loaded to view its directory.\n", argv[1]); Printf ("%s must be loaded to view its directory.\n", argv[1]);

View file

@ -270,11 +270,10 @@ FIWadManager::FIWadManager(const char *firstfn, const char *optfn)
{ {
FileSystem check; FileSystem check;
TArray<FString> fns; TArray<FString> fns;
TArray<FString> deletes;
fns.Push(firstfn); fns.Push(firstfn);
if (optfn) fns.Push(optfn); if (optfn) fns.Push(optfn);
check.InitMultipleFiles(fns, deletes, true); check.InitMultipleFiles(fns, true);
if (check.GetNumLumps() > 0) if (check.GetNumLumps() > 0)
{ {
int num = check.CheckNumForName("IWADINFO"); int num = check.CheckNumForName("IWADINFO");

View file

@ -103,6 +103,7 @@
#include "s_music.h" #include "s_music.h"
#include "swrenderer/r_swcolormaps.h" #include "swrenderer/r_swcolormaps.h"
#include "findfile.h" #include "findfile.h"
#include "md5.h"
EXTERN_CVAR(Bool, hud_althud) EXTERN_CVAR(Bool, hud_althud)
EXTERN_CVAR(Int, vr_mode) EXTERN_CVAR(Int, vr_mode)
@ -2018,11 +2019,10 @@ static FString ParseGameInfo(TArray<FString> &pwads, const char *fn, const char
static FString CheckGameInfo(TArray<FString> & pwads) static FString CheckGameInfo(TArray<FString> & pwads)
{ {
TArray<FString> deletes;
FileSystem check; FileSystem check;
// Open the entire list as a temporary file system and look for a GAMEINFO lump. The last one will automatically win. // Open the entire list as a temporary file system and look for a GAMEINFO lump. The last one will automatically win.
check.InitMultipleFiles(pwads, deletes, true); check.InitMultipleFiles(pwads, true);
if (check.GetNumLumps() > 0) if (check.GetNumLumps() > 0)
{ {
int num = check.CheckNumForName("GAMEINFO"); int num = check.CheckNumForName("GAMEINFO");
@ -2030,7 +2030,7 @@ static FString CheckGameInfo(TArray<FString> & pwads)
{ {
// Found one! // Found one!
auto data = check.ReadLumpIntoArray(num); auto data = check.ReadLumpIntoArray(num);
auto wadname = check.GetWadName(check.GetLumpFile(num)); auto wadname = check.GetResourceFileName(check.GetLumpFile(num));
return ParseGameInfo(pwads, wadname, (const char*)data.Data(), data.Size()); return ParseGameInfo(pwads, wadname, (const char*)data.Data(), data.Size());
} }
} }
@ -2321,6 +2321,336 @@ static void NewFailure ()
I_FatalError ("Failed to allocate memory from system heap"); I_FatalError ("Failed to allocate memory from system heap");
} }
//==========================================================================
//
// RenameSprites
//
// Renames sprites in IWADs so that unique actors can have unique sprites,
// making it possible to import any actor from any game into any other
// game without jumping through hoops to resolve duplicate sprite names.
// You just need to know what the sprite's new name is.
//
//==========================================================================
static void RenameSprites(FileSystem &fileSystem, const TArray<FString>& deletelumps)
{
bool renameAll;
bool MNTRZfound = false;
const char* altbigfont = gameinfo.gametype == GAME_Strife ? "SBIGFONT" : (gameinfo.gametype & GAME_Raven) ? "HBIGFONT" : "DBIGFONT";
static const uint32_t HereticRenames[] =
{ MAKE_ID('H','E','A','D'), MAKE_ID('L','I','C','H'), // Ironlich
};
static const uint32_t HexenRenames[] =
{ MAKE_ID('B','A','R','L'), MAKE_ID('Z','B','A','R'), // ZBarrel
MAKE_ID('A','R','M','1'), MAKE_ID('A','R','_','1'), // MeshArmor
MAKE_ID('A','R','M','2'), MAKE_ID('A','R','_','2'), // FalconShield
MAKE_ID('A','R','M','3'), MAKE_ID('A','R','_','3'), // PlatinumHelm
MAKE_ID('A','R','M','4'), MAKE_ID('A','R','_','4'), // AmuletOfWarding
MAKE_ID('S','U','I','T'), MAKE_ID('Z','S','U','I'), // ZSuitOfArmor and ZArmorChunk
MAKE_ID('T','R','E','1'), MAKE_ID('Z','T','R','E'), // ZTree and ZTreeDead
MAKE_ID('T','R','E','2'), MAKE_ID('T','R','E','S'), // ZTreeSwamp150
MAKE_ID('C','A','N','D'), MAKE_ID('B','C','A','N'), // ZBlueCandle
MAKE_ID('R','O','C','K'), MAKE_ID('R','O','K','K'), // rocks and dirt in a_debris.cpp
MAKE_ID('W','A','T','R'), MAKE_ID('H','W','A','T'), // Strife also has WATR
MAKE_ID('G','I','B','S'), MAKE_ID('P','O','L','5'), // RealGibs
MAKE_ID('E','G','G','M'), MAKE_ID('P','R','K','M'), // PorkFX
MAKE_ID('I','N','V','U'), MAKE_ID('D','E','F','N'), // Icon of the Defender
};
static const uint32_t StrifeRenames[] =
{ MAKE_ID('M','I','S','L'), MAKE_ID('S','M','I','S'), // lots of places
MAKE_ID('A','R','M','1'), MAKE_ID('A','R','M','3'), // MetalArmor
MAKE_ID('A','R','M','2'), MAKE_ID('A','R','M','4'), // LeatherArmor
MAKE_ID('P','M','A','P'), MAKE_ID('S','M','A','P'), // StrifeMap
MAKE_ID('T','L','M','P'), MAKE_ID('T','E','C','H'), // TechLampSilver and TechLampBrass
MAKE_ID('T','R','E','1'), MAKE_ID('T','R','E','T'), // TreeStub
MAKE_ID('B','A','R','1'), MAKE_ID('B','A','R','C'), // BarricadeColumn
MAKE_ID('S','H','T','2'), MAKE_ID('M','P','U','F'), // MaulerPuff
MAKE_ID('B','A','R','L'), MAKE_ID('B','B','A','R'), // StrifeBurningBarrel
MAKE_ID('T','R','C','H'), MAKE_ID('T','R','H','L'), // SmallTorchLit
MAKE_ID('S','H','R','D'), MAKE_ID('S','H','A','R'), // glass shards
MAKE_ID('B','L','S','T'), MAKE_ID('M','A','U','L'), // Mauler
MAKE_ID('L','O','G','G'), MAKE_ID('L','O','G','W'), // StickInWater
MAKE_ID('V','A','S','E'), MAKE_ID('V','A','Z','E'), // Pot and Pitcher
MAKE_ID('C','N','D','L'), MAKE_ID('K','N','D','L'), // Candle
MAKE_ID('P','O','T','1'), MAKE_ID('M','P','O','T'), // MetalPot
MAKE_ID('S','P','I','D'), MAKE_ID('S','T','L','K'), // Stalker
};
const uint32_t* renames;
int numrenames;
switch (gameinfo.gametype)
{
case GAME_Doom:
default:
// Doom's sprites don't get renamed.
renames = nullptr;
numrenames = 0;
break;
case GAME_Heretic:
renames = HereticRenames;
numrenames = sizeof(HereticRenames) / 8;
break;
case GAME_Hexen:
renames = HexenRenames;
numrenames = sizeof(HexenRenames) / 8;
break;
case GAME_Strife:
renames = StrifeRenames;
numrenames = sizeof(StrifeRenames) / 8;
break;
}
unsigned NumFiles = fileSystem.GetNumLumps();
for (uint32_t i = 0; i < NumFiles; i++)
{
// check for full Minotaur animations. If this is not found
// some frames need to be renamed.
if (fileSystem.GetLumpNamespace(i) == ns_sprites)
{
auto& shortName = fileSystem.GetShortName(i);
if (shortName.dword == MAKE_ID('M', 'N', 'T', 'R') && shortName.String[4] == 'Z')
{
MNTRZfound = true;
break;
}
}
}
renameAll = !!Args->CheckParm("-oldsprites") || nospriterename;
for (uint32_t i = 0; i < NumFiles; i++)
{
auto& shortName = fileSystem.GetShortName(i);
if (fileSystem.GetLumpNamespace(i) == ns_sprites)
{
// Only sprites in the IWAD normally get renamed
if (renameAll || fileSystem.GetLumpFile(i) == fileSystem.GetIwadNum())
{
for (int j = 0; j < numrenames; ++j)
{
if (shortName.dword == renames[j * 2])
{
shortName.dword = renames[j * 2 + 1];
}
}
if (gameinfo.gametype == GAME_Hexen)
{
if (fileSystem.CheckLumpName(i, "ARTIINVU"))
{
shortName.String[4] = 'D'; shortName.String[5] = 'E';
shortName.String[6] = 'F'; shortName.String[7] = 'N';
}
}
}
if (!MNTRZfound)
{
if (shortName.dword == MAKE_ID('M', 'N', 'T', 'R'))
{
for (size_t fi : {4, 6})
{
if (shortName.String[fi] >= 'F' && shortName.String[fi] <= 'K')
{
shortName.String[fi] += 'U' - 'F';
}
}
}
}
// When not playing Doom rename all BLOD sprites to BLUD so that
// the same blood states can be used everywhere
if (!(gameinfo.gametype & GAME_DoomChex))
{
if (shortName.dword == MAKE_ID('B', 'L', 'O', 'D'))
{
shortName.dword = MAKE_ID('B', 'L', 'U', 'D');
}
}
}
else if (fileSystem.GetLumpNamespace(i) == ns_global)
{
int fn = fileSystem.GetLumpFile(i);
if (fn >= fileSystem.GetIwadNum() && fn <= fileSystem.GetMaxIwadNum() && deletelumps.Find(shortName.String) < deletelumps.Size())
{
shortName.String[0] = 0; // Lump must be deleted from directory.
}
// Rename the game specific big font lumps so that the font manager does not have to do problematic special checks for them.
else if (!strcmp(shortName.String, altbigfont))
{
strcpy(shortName.String, "BIGFONT");
}
}
}
}
//==========================================================================
//
// RenameNerve
//
// Renames map headers and map name pictures in nerve.wad so as to load it
// alongside Doom II and offer both episodes without causing conflicts.
// MD5 checksum for NERVE.WAD: 967d5ae23daf45196212ae1b605da3b0 (3,819,855)
// MD5 checksum for Unity version of NERVE.WAD: 4214c47651b63ee2257b1c2490a518c9 (3,821,966)
//
//==========================================================================
void RenameNerve(FileSystem& fileSystem)
{
if (gameinfo.gametype != GAME_Doom)
return;
const int numnerveversions = 2;
bool found = false;
uint8_t cksum[16];
static const uint8_t nerve[numnerveversions][16] = {
{ 0x96, 0x7d, 0x5a, 0xe2, 0x3d, 0xaf, 0x45, 0x19,
0x62, 0x12, 0xae, 0x1b, 0x60, 0x5d, 0xa3, 0xb0 },
{ 0x42, 0x14, 0xc4, 0x76, 0x51, 0xb6, 0x3e, 0xe2,
0x25, 0x7b, 0x1c, 0x24, 0x90, 0xa5, 0x18, 0xc9 }
};
size_t nervesize[numnerveversions] = { 3819855, 3821966 }; // NERVE.WAD's file size
int w = fileSystem.GetIwadNum();
while (++w < fileSystem.GetNumWads())
{
auto fr = fileSystem.GetFileReader(w);
int isizecheck = -1;
if (fr == NULL)
{
continue;
}
for (int icheck = 0; icheck < numnerveversions; icheck++)
if (fr->GetLength() == (long)nervesize[icheck])
isizecheck = icheck;
if (isizecheck == -1)
{
// Skip MD5 computation when there is a
// cheaper way to know this is not the file
continue;
}
fr->Seek(0, FileReader::SeekSet);
MD5Context md5;
md5Update(*fr, md5, (unsigned)fr->GetLength());
md5.Final(cksum);
if (memcmp(nerve[isizecheck], cksum, 16) == 0)
{
found = true;
break;
}
}
if (!found)
return;
for (int i = fileSystem.GetFirstLump(w); i <= fileSystem.GetLastLump(w); i++)
{
auto& shortName = fileSystem.GetShortName(i);
// Only rename the maps from NERVE.WAD
if (shortName.dword == MAKE_ID('C', 'W', 'I', 'L'))
{
shortName.String[0] = 'N';
}
else if (shortName.dword == MAKE_ID('M', 'A', 'P', '0'))
{
shortName.String[6] = shortName.String[4];
shortName.String[5] = '0';
shortName.String[4] = 'L';
shortName.dword = MAKE_ID('L', 'E', 'V', 'E');
}
}
}
//==========================================================================
//
// FixMacHexen
//
// Discard all extra lumps in Mac version of Hexen IWAD (demo or full)
// to avoid any issues caused by names of these lumps, including:
// * Wrong height of small font
// * Broken life bar of mage class
//
//==========================================================================
void FixMacHexen(FileSystem& fileSystem)
{
if (GAME_Hexen != gameinfo.gametype)
{
return;
}
FileReader* reader = fileSystem.GetFileReader(fileSystem.GetIwadNum());
auto iwadSize = reader->GetLength();
static const long DEMO_SIZE = 13596228;
static const long BETA_SIZE = 13749984;
static const long FULL_SIZE = 21078584;
if (DEMO_SIZE != iwadSize
&& BETA_SIZE != iwadSize
&& FULL_SIZE != iwadSize)
{
return;
}
reader->Seek(0, FileReader::SeekSet);
uint8_t checksum[16];
MD5Context md5;
md5Update(*reader, md5, (unsigned)iwadSize);
md5.Final(checksum);
static const uint8_t HEXEN_DEMO_MD5[16] =
{
0x92, 0x5f, 0x9f, 0x50, 0x00, 0xe1, 0x7d, 0xc8,
0x4b, 0x0a, 0x6a, 0x3b, 0xed, 0x3a, 0x6f, 0x31
};
static const uint8_t HEXEN_BETA_MD5[16] =
{
0x2a, 0xf1, 0xb2, 0x7c, 0xd1, 0x1f, 0xb1, 0x59,
0xe6, 0x08, 0x47, 0x2a, 0x1b, 0x53, 0xe4, 0x0e
};
static const uint8_t HEXEN_FULL_MD5[16] =
{
0xb6, 0x81, 0x40, 0xa7, 0x96, 0xf6, 0xfd, 0x7f,
0x3a, 0x5d, 0x32, 0x26, 0xa3, 0x2b, 0x93, 0xbe
};
const bool isBeta = 0 == memcmp(HEXEN_BETA_MD5, checksum, sizeof checksum);
if (!isBeta
&& 0 != memcmp(HEXEN_DEMO_MD5, checksum, sizeof checksum)
&& 0 != memcmp(HEXEN_FULL_MD5, checksum, sizeof checksum))
{
return;
}
static const int EXTRA_LUMPS = 299;
// Hexen Beta is very similar to Demo but it has MAP41: Maze at the end of the WAD
// So keep this map if it's present but discard all extra lumps
const int lastLump = fileSystem.GetLastLump(fileSystem.GetIwadNum()) - (isBeta ? 12 : 0);
assert(fileSystem.GetFirstLump(fileSystem.GetIwadNum()) + 299 < lastLump);
for (int i = lastLump - EXTRA_LUMPS + 1; i <= lastLump; ++i)
{
auto& shortName = fileSystem.GetShortName(i);
shortName.String[0] = '\0';
}
}
//========================================================================== //==========================================================================
// //
// D_DoomMain // D_DoomMain
@ -2504,7 +2834,14 @@ static int D_DoomMain_Internal (void)
static const char* reserved[] = { "mapinfo", "zmapinfo", "gameinfo", "sndinfo", "sbarinfo", "menudef", "gldefs", "animdefs", "decorate", "zscript", "maps/" }; static const char* reserved[] = { "mapinfo", "zmapinfo", "gameinfo", "sndinfo", "sbarinfo", "menudef", "gldefs", "animdefs", "decorate", "zscript", "maps/" };
for (auto p : reserved) lfi.requiredPrefixes.Push(p); for (auto p : reserved) lfi.requiredPrefixes.Push(p);
fileSystem.InitMultipleFiles (allwads, iwad_info->DeleteLumps, false, &lfi); lfi.postprocessFunc = [&]()
{
RenameNerve(fileSystem);
RenameSprites(fileSystem, iwad_info->DeleteLumps);
FixMacHexen(fileSystem);
};
fileSystem.InitMultipleFiles (allwads, false, &lfi);
allwads.Clear(); allwads.Clear();
allwads.ShrinkToFit(); allwads.ShrinkToFit();
SetMapxxFlag(); SetMapxxFlag();

View file

@ -156,7 +156,7 @@ CCMD (mapchecksum)
else else
{ {
map->GetChecksum(cksum); map->GetChecksum(cksum);
const char *wadname = fileSystem.GetWadName(fileSystem.GetLumpFile(map->lumpnum)); const char *wadname = fileSystem.GetResourceFileName(fileSystem.GetLumpFile(map->lumpnum));
delete map; delete map;
for (size_t j = 0; j < sizeof(cksum); ++j) for (size_t j = 0; j < sizeof(cksum); ++j)
{ {
@ -367,7 +367,7 @@ CCMD(listmaps)
if (map != NULL) if (map != NULL)
{ {
Printf("%s: '%s' (%s)\n", info->MapName.GetChars(), info->LookupLevelName().GetChars(), Printf("%s: '%s' (%s)\n", info->MapName.GetChars(), info->LookupLevelName().GetChars(),
fileSystem.GetWadName(fileSystem.GetLumpFile(map->lumpnum))); fileSystem.GetResourceFileName(fileSystem.GetLumpFile(map->lumpnum)));
delete map; delete map;
} }
} }

View file

@ -1765,7 +1765,7 @@ static bool CheckSingleWad (const char *name, bool &printRequires, bool printwar
{ {
return true; return true;
} }
if (fileSystem.CheckIfWadLoaded (name) < 0) if (fileSystem.CheckIfResourceFileLoaded (name) < 0)
{ {
if (printwarn) if (printwarn)
{ {
@ -2129,13 +2129,13 @@ static void PutSaveWads (FSerializer &arc)
const char *name; const char *name;
// Name of IWAD // Name of IWAD
name = fileSystem.GetWadName (fileSystem.GetIwadNum()); name = fileSystem.GetResourceFileName (fileSystem.GetIwadNum());
arc.AddString("Game WAD", name); arc.AddString("Game WAD", name);
// Name of wad the map resides in // Name of wad the map resides in
if (fileSystem.GetLumpFile (primaryLevel->lumpnum) > fileSystem.GetIwadNum()) if (fileSystem.GetLumpFile (primaryLevel->lumpnum) > fileSystem.GetIwadNum())
{ {
name = fileSystem.GetWadName (fileSystem.GetLumpFile (primaryLevel->lumpnum)); name = fileSystem.GetResourceFileName (fileSystem.GetLumpFile (primaryLevel->lumpnum));
arc.AddString("Map WAD", name); arc.AddString("Map WAD", name);
} }
} }
@ -2776,7 +2776,7 @@ void G_DoPlayDemo (void)
demolump = fileSystem.CheckNumForFullName (defdemoname, true); demolump = fileSystem.CheckNumForFullName (defdemoname, true);
if (demolump >= 0) if (demolump >= 0)
{ {
int demolen = fileSystem.LumpLength (demolump); int demolen = fileSystem.FileLength (demolump);
demobuffer = (uint8_t *)M_Malloc(demolen); demobuffer = (uint8_t *)M_Malloc(demolen);
fileSystem.ReadLump (demolump, demobuffer); fileSystem.ReadLump (demolump, demobuffer);
} }

View file

@ -519,7 +519,7 @@ void SBarInfo::ParseSBarInfo(int lump)
else if (fileSystem.GetLumpFile(baselump) > 0) else if (fileSystem.GetLumpFile(baselump) > 0)
{ {
I_FatalError("File %s is overriding core lump sbarinfo/%s.txt.", I_FatalError("File %s is overriding core lump sbarinfo/%s.txt.",
fileSystem.GetWadFullName(fileSystem.GetLumpFile(baselump)), sc.String); fileSystem.GetResourceFileFullName(fileSystem.GetLumpFile(baselump)), sc.String);
} }
ParseSBarInfo(baselump); ParseSBarInfo(baselump);
} }

View file

@ -2490,7 +2490,7 @@ bool D_LoadDehLump(int lumpnum)
auto ls = LumpFileNum; auto ls = LumpFileNum;
LumpFileNum = fileSystem.GetLumpFile(lumpnum); LumpFileNum = fileSystem.GetLumpFile(lumpnum);
PatchSize = fileSystem.LumpLength(lumpnum); PatchSize = fileSystem.FileLength(lumpnum);
PatchName = fileSystem.GetLumpFullPath(lumpnum); PatchName = fileSystem.GetLumpFullPath(lumpnum);
PatchFile = new char[PatchSize + 1]; PatchFile = new char[PatchSize + 1];

View file

@ -125,7 +125,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
FontName = name; FontName = name;
FMemLump data1 = fileSystem.ReadLump (lump); FileData data1 = fileSystem.ReadLump (lump);
const uint8_t *data = (const uint8_t *)data1.GetMem(); const uint8_t *data = (const uint8_t *)data1.GetMem();
if (data[0] == 0xE1 && data[1] == 0xE6 && data[2] == 0xD5 && data[3] == 0x1A) if (data[0] == 0xE1 && data[1] == 0xE6 && data[2] == 0xD5 && data[3] == 0x1A)
@ -539,7 +539,7 @@ int FSingleLumpFont::BMFCompare(const void *a, const void *b)
void FSingleLumpFont::CheckFON1Chars (double *luminosity) void FSingleLumpFont::CheckFON1Chars (double *luminosity)
{ {
FMemLump memLump = fileSystem.ReadLump(Lump); FileData memLump = fileSystem.ReadLump(Lump);
const uint8_t* data = (const uint8_t*) memLump.GetMem(); const uint8_t* data = (const uint8_t*) memLump.GetMem();
uint8_t used[256], reverse[256]; uint8_t used[256], reverse[256];

View file

@ -856,7 +856,7 @@ void FMapInfoParser::ParseCluster()
{ {
// Check if this comes from either Hexen.wad or Hexdd.wad and if so, map to the string table. // Check if this comes from either Hexen.wad or Hexdd.wad and if so, map to the string table.
int fileno = fileSystem.GetLumpFile(lump); int fileno = fileSystem.GetLumpFile(lump);
auto fn = fileSystem.GetWadName(fileno); auto fn = fileSystem.GetResourceFileName(fileno);
if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD"))) if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD")))
{ {
FStringf key("TXT_%.5s_%s", fn, clusterinfo->ExitText.GetChars()); FStringf key("TXT_%.5s_%s", fn, clusterinfo->ExitText.GetChars());
@ -1987,7 +1987,7 @@ level_info_t *FMapInfoParser::ParseMapHeader(level_info_t &defaultinfo)
{ {
// Try to localize Hexen's map names. This does not use the above feature to allow these names to be unique. // Try to localize Hexen's map names. This does not use the above feature to allow these names to be unique.
int fileno = fileSystem.GetLumpFile(sc.LumpNum); int fileno = fileSystem.GetLumpFile(sc.LumpNum);
auto fn = fileSystem.GetWadName(fileno); auto fn = fileSystem.GetResourceFileName(fileno);
if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD"))) if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD")))
{ {
FStringf key("TXT_%.5s_%s", fn, levelinfo->MapName.GetChars()); FStringf key("TXT_%.5s_%s", fn, levelinfo->MapName.GetChars());
@ -2217,7 +2217,7 @@ void FMapInfoParser::ParseMapInfo (int lump, level_info_t &gamedefaults, level_i
if (fileSystem.GetLumpFile(sc.LumpNum) == 0) if (fileSystem.GetLumpFile(sc.LumpNum) == 0)
{ {
I_FatalError("File %s is overriding core lump %s.", I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetWadFullName(fileSystem.GetLumpFile(inclump)), sc.String); fileSystem.GetResourceFileFullName(fileSystem.GetLumpFile(inclump)), sc.String);
} }
} }
FScanner saved_sc = sc; FScanner saved_sc = sc;
@ -2410,7 +2410,7 @@ void G_ParseMapInfo (FString basemapinfo)
if (fileSystem.GetLumpFile(baselump) > 0) if (fileSystem.GetLumpFile(baselump) > 0)
{ {
I_FatalError("File %s is overriding core lump %s.", I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetWadFullName(fileSystem.GetLumpFile(baselump)), basemapinfo.GetChars()); fileSystem.GetResourceFileName(fileSystem.GetLumpFile(baselump)), basemapinfo.GetChars());
} }
parse.ParseMapInfo(baselump, gamedefaults, defaultinfo); parse.ParseMapInfo(baselump, gamedefaults, defaultinfo);
} }

View file

@ -162,8 +162,8 @@ void D_LoadWadSettings ()
while ((lump = fileSystem.FindLump ("KEYCONF", &lastlump)) != -1) while ((lump = fileSystem.FindLump ("KEYCONF", &lastlump)) != -1)
{ {
FMemLump data = fileSystem.ReadLump (lump); FileData data = fileSystem.ReadLump (lump);
const char *eof = (char *)data.GetMem() + fileSystem.LumpLength (lump); const char *eof = (char *)data.GetMem() + fileSystem.FileLength (lump);
const char *conf = (char *)data.GetMem(); const char *conf = (char *)data.GetMem();
while (conf < eof) while (conf < eof)

View file

@ -39,6 +39,22 @@
#include "w_wad.h" #include "w_wad.h"
#include "engineerrors.h" #include "engineerrors.h"
struct wadinfo_t
{
// Should be "IWAD" or "PWAD".
uint32_t Magic;
uint32_t NumLumps;
uint32_t InfoTableOfs;
};
struct wadlump_t
{
uint32_t FilePos;
uint32_t Size;
char Name[8];
};
//========================================================================== //==========================================================================
// //
// Wad Lump (with console doom LZSS support) // Wad Lump (with console doom LZSS support)

View file

@ -685,19 +685,4 @@ int FExternalLump::FillCache()
} }
bool FMemoryFile::Open(bool quiet, LumpFilterInfo*)
{
FString name(ExtractFileBase(FileName));
FString fname(ExtractFileBase(FileName, true));
Lumps.Resize(1);
Lumps[0].LumpNameSetup(fname);
Lumps[0].Owner = this;
Lumps[0].Position = 0;
Lumps[0].LumpSize = (int)Reader.GetLength();
Lumps[0].Flags = 0;
NumLumps = 1;
return true;
}

View file

@ -13,6 +13,7 @@ struct LumpFilterInfo
// The following are for checking if the root directory of a zip can be removed. // The following are for checking if the root directory of a zip can be removed.
TArray<FString> reservedFolders; TArray<FString> reservedFolders;
TArray<FString> requiredPrefixes; TArray<FString> requiredPrefixes;
std::function<void()> postprocessFunc;
}; };
class FResourceFile; class FResourceFile;
@ -86,11 +87,11 @@ struct FResourceLump
friend class FWadFile; // this still needs direct access. friend class FWadFile; // this still needs direct access.
int LumpSize; int LumpSize;
int RefCount;
protected: protected:
FString FullName; // only valid for files loaded from a non-wad archive FString FullName;
public: public:
uint8_t Flags; uint8_t Flags;
int8_t RefCount;
char * Cache; char * Cache;
FResourceFile * Owner; FResourceFile * Owner;
@ -199,20 +200,25 @@ struct FExternalLump : public FResourceLump
}; };
struct FMemoryFile : public FUncompressedFile struct FMemoryLump : public FResourceLump
{ {
FMemoryFile(const char *_filename, const void *sdata, int length) FMemoryLump(const void* data, int length)
: FUncompressedFile(_filename)
{ {
Reader.OpenMemoryArray(sdata, length); RefCount = INT_MAX / 2;
LumpSize = length;
Cache = new char[length];
memcpy(Cache, data, length);
} }
bool Open(bool quiet, LumpFilterInfo* filter); virtual int FillCache() override
{
RefCount = INT_MAX / 2; // Make sure it never counts down to 0 by resetting it to something high each time it is used.
return 1;
}
}; };
#endif #endif

View file

@ -459,7 +459,7 @@ void STAT_ChangeLevel(const char *newl, FLevelLocals *Level)
wad = fileSystem.GetLumpFile(map->lumpnum); wad = fileSystem.GetLumpFile(map->lumpnum);
delete map; delete map;
} }
const char * name = fileSystem.GetWadName(wad); const char * name = fileSystem.GetResourceFileName(wad);
FString section = ExtractFileBase(name) + "." + StartEpisode->mEpisodeMap; FString section = ExtractFileBase(name) + "." + StartEpisode->mEpisodeMap;
section.ToUpper(); section.ToUpper();

View file

@ -64,7 +64,7 @@ void FTextureManager::InitSwitchList ()
if (lump != -1) if (lump != -1)
{ {
FMemLump lumpdata = fileSystem.ReadLump (lump); FileData lumpdata = fileSystem.ReadLump (lump);
const char *alphSwitchList = (const char *)lumpdata.GetMem(); const char *alphSwitchList = (const char *)lumpdata.GetMem();
const char *list_p; const char *list_p;
FSwitchDef *def1, *def2; FSwitchDef *def1, *def2;

View file

@ -182,8 +182,8 @@ void FTextureManager::InitAnimated (void)
int lumpnum = fileSystem.CheckNumForName ("ANIMATED"); int lumpnum = fileSystem.CheckNumForName ("ANIMATED");
if (lumpnum != -1) if (lumpnum != -1)
{ {
FMemLump animatedlump = fileSystem.ReadLump (lumpnum); FileData animatedlump = fileSystem.ReadLump (lumpnum);
int animatedlen = fileSystem.LumpLength(lumpnum); int animatedlen = fileSystem.FileLength(lumpnum);
const uint8_t *animdefs = (const uint8_t *)animatedlump.GetMem(); const uint8_t *animdefs = (const uint8_t *)animatedlump.GetMem();
const uint8_t *anim_p; const uint8_t *anim_p;
FTextureID pic1, pic2; FTextureID pic1, pic2;

View file

@ -81,7 +81,7 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
: FImageSource(lumpnum) : FImageSource(lumpnum)
{ {
Width = 320; Width = 320;
Height = uint16_t(fileSystem.LumpLength(lumpnum) / 320); Height = uint16_t(fileSystem.FileLength(lumpnum) / 320);
bUseGamePalette = true; bUseGamePalette = true;
} }
@ -94,7 +94,7 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
TArray<uint8_t> FAutomapTexture::CreatePalettedPixels(int conversion) TArray<uint8_t> FAutomapTexture::CreatePalettedPixels(int conversion)
{ {
int x, y; int x, y;
FMemLump data = fileSystem.ReadLump (SourceLump); FileData data = fileSystem.ReadLump (SourceLump);
const uint8_t *indata = (const uint8_t *)data.GetMem(); const uint8_t *indata = (const uint8_t *)data.GetMem();
TArray<uint8_t> Pixels(Width * Height, true); TArray<uint8_t> Pixels(Width * Height, true);

View file

@ -238,12 +238,12 @@ static int CountTiles (const void *tiles)
static int BuildPaletteTranslation(int lump) static int BuildPaletteTranslation(int lump)
{ {
if (fileSystem.LumpLength(lump) < 768) if (fileSystem.FileLength(lump) < 768)
{ {
return false; return false;
} }
FMemLump data = fileSystem.ReadLump(lump); FileData data = fileSystem.ReadLump(lump);
const uint8_t *ipal = (const uint8_t *)data.GetMem(); const uint8_t *ipal = (const uint8_t *)data.GetMem();
FRemapTable opal; FRemapTable opal;
@ -316,7 +316,7 @@ void FTextureManager::InitBuildTiles()
if (fileSystem.CheckNumForFullName(name) != i) continue; // This palette is hidden by a later one. Do not process if (fileSystem.CheckNumForFullName(name) != i) continue; // This palette is hidden by a later one. Do not process
FString base = ExtractFileBase(name, true); FString base = ExtractFileBase(name, true);
base.ToLower(); base.ToLower();
if (base.Compare("palette.dat") == 0 && fileSystem.LumpLength(i) >= 768) // must be a valid palette, i.e. at least 256 colors. if (base.Compare("palette.dat") == 0 && fileSystem.FileLength(i) >= 768) // must be a valid palette, i.e. at least 256 colors.
{ {
FString path = ExtractFilePath(name); FString path = ExtractFilePath(name);
if (path.IsNotEmpty() && path.Back() != '/') path += '/'; if (path.IsNotEmpty() && path.Back() != '/') path += '/';
@ -336,7 +336,7 @@ void FTextureManager::InitBuildTiles()
BuildTileData.Reserve(1); BuildTileData.Reserve(1);
auto &artdata = BuildTileData.Last(); auto &artdata = BuildTileData.Last();
artdata.Resize(fileSystem.LumpLength(lumpnum)); artdata.Resize(fileSystem.FileLength(lumpnum));
fileSystem.ReadLump(lumpnum, &artdata[0]); fileSystem.ReadLump(lumpnum, &artdata[0]);
if ((numtiles = CountTiles(&artdata[0])) > 0) if ((numtiles = CountTiles(&artdata[0])) > 0)

View file

@ -79,7 +79,7 @@ FFlatTexture::FFlatTexture (int lumpnum)
int area; int area;
int bits; int bits;
area = fileSystem.LumpLength (lumpnum); area = fileSystem.FileLength (lumpnum);
switch (area) switch (area)
{ {

View file

@ -122,7 +122,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion) TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion)
{ {
FMemLump lump = fileSystem.ReadLump (SourceLump); FileData lump = fileSystem.ReadLump (SourceLump);
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem(); const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
const uint8_t *data = (const uint8_t *)&imgz[1]; const uint8_t *data = (const uint8_t *)&imgz[1];

View file

@ -170,10 +170,10 @@ TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
const column_t *maxcol; const column_t *maxcol;
int x; int x;
FMemLump lump = fileSystem.ReadLump (SourceLump); FileData lump = fileSystem.ReadLump (SourceLump);
const patch_t *patch = (const patch_t *)lump.GetMem(); const patch_t *patch = (const patch_t *)lump.GetMem();
maxcol = (const column_t *)((const uint8_t *)patch + fileSystem.LumpLength (SourceLump) - 3); maxcol = (const column_t *)((const uint8_t *)patch + fileSystem.FileLength (SourceLump) - 3);
remap = ImageHelpers::GetRemap(conversion == luminance, isalpha); remap = ImageHelpers::GetRemap(conversion == luminance, isalpha);
// Special case for skies // Special case for skies
@ -275,12 +275,12 @@ int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion)
void FPatchTexture::DetectBadPatches () void FPatchTexture::DetectBadPatches ()
{ {
// The patch must look like it is large enough for the rules to apply to avoid using this on truly empty patches. // The patch must look like it is large enough for the rules to apply to avoid using this on truly empty patches.
if (fileSystem.LumpLength(SourceLump) < Width * Height / 2) return; if (fileSystem.FileLength(SourceLump) < Width * Height / 2) return;
// Check if this patch is likely to be a problem. // Check if this patch is likely to be a problem.
// It must be 256 pixels tall, and all its columns must have exactly // It must be 256 pixels tall, and all its columns must have exactly
// one post, where each post has a supposed length of 0. // one post, where each post has a supposed length of 0.
FMemLump lump = fileSystem.ReadLump (SourceLump); FileData lump = fileSystem.ReadLump (SourceLump);
const patch_t *realpatch = (patch_t *)lump.GetMem(); const patch_t *realpatch = (patch_t *)lump.GetMem();
const uint32_t *cofs = realpatch->columnofs; const uint32_t *cofs = realpatch->columnofs;
int x, x2 = LittleShort(realpatch->width); int x, x2 = LittleShort(realpatch->width);

View file

@ -162,7 +162,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic) if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic)
{ {
mPaletteLump = fileSystem.CheckNumForName("E2PAL"); mPaletteLump = fileSystem.CheckNumForName("E2PAL");
if (fileSystem.LumpLength(mPaletteLump) < 768) mPaletteLump = -1; if (fileSystem.FileLength(mPaletteLump) < 768) mPaletteLump = -1;
} }
else bUseGamePalette = true; else bUseGamePalette = true;
} }
@ -175,7 +175,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
TArray<uint8_t> FRawPageTexture::CreatePalettedPixels(int conversion) TArray<uint8_t> FRawPageTexture::CreatePalettedPixels(int conversion)
{ {
FMemLump lump = fileSystem.ReadLump (SourceLump); FileData lump = fileSystem.ReadLump (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem(); const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *source_p = source; const uint8_t *source_p = source;
uint8_t *dest_p; uint8_t *dest_p;
@ -207,8 +207,8 @@ int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion)
if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion); if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion);
else else
{ {
FMemLump lump = fileSystem.ReadLump(SourceLump); FileData lump = fileSystem.ReadLump(SourceLump);
FMemLump plump = fileSystem.ReadLump(mPaletteLump); FileData plump = fileSystem.ReadLump(mPaletteLump);
const uint8_t *source = (const uint8_t *)lump.GetMem(); const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *psource = (const uint8_t *)plump.GetMem(); const uint8_t *psource = (const uint8_t *)plump.GetMem();
PalEntry paldata[256]; PalEntry paldata[256];

View file

@ -294,7 +294,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi
} }
// Check whether the amount of names reported is correct. // Check whether the amount of names reported is correct.
int lumplength = fileSystem.LumpLength(patcheslump); int lumplength = fileSystem.FileLength(patcheslump);
if (numpatches > uint32_t((lumplength - 4) / 8)) if (numpatches > uint32_t((lumplength - 4) / 8))
{ {
Printf("PNAMES lump is shorter than required (%u entries reported but only %d bytes (%d entries) long\n", Printf("PNAMES lump is shorter than required (%u entries reported but only %d bytes (%d entries) long\n",
@ -406,13 +406,13 @@ void FMultipatchTextureBuilder::AddTexturesLumps(int lump1, int lump2, int patch
if (lump1 >= 0) if (lump1 >= 0)
{ {
FMemLump texdir = fileSystem.ReadLump(lump1); FileData texdir = fileSystem.ReadLump(lump1);
AddTexturesLump(texdir.GetMem(), fileSystem.LumpLength(lump1), lump1, patcheslump, firstdup, true); AddTexturesLump(texdir.GetMem(), fileSystem.FileLength(lump1), lump1, patcheslump, firstdup, true);
} }
if (lump2 >= 0) if (lump2 >= 0)
{ {
FMemLump texdir = fileSystem.ReadLump(lump2); FileData texdir = fileSystem.ReadLump(lump2);
AddTexturesLump(texdir.GetMem(), fileSystem.LumpLength(lump2), lump2, patcheslump, firstdup, false); AddTexturesLump(texdir.GetMem(), fileSystem.FileLength(lump2), lump2, patcheslump, firstdup, false);
} }
} }

View file

@ -607,7 +607,7 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype)
} }
StartScreen->Progress(); StartScreen->Progress();
} }
else if (ns == ns_flats && fileSystem.GetLumpFlags(firsttx) & LUMPF_MAYBEFLAT) else if (ns == ns_flats && fileSystem.GetFileFlags(firsttx) & LUMPF_MAYBEFLAT)
{ {
if (fileSystem.CheckNumForName (Name, ns) < firsttx) if (fileSystem.CheckNumForName (Name, ns) < firsttx)
{ {
@ -963,7 +963,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b
if (ns == ns_global) if (ns == ns_global)
{ {
// In Zips all graphics must be in a separate namespace. // In Zips all graphics must be in a separate namespace.
if (fileSystem.GetLumpFlags(i) & LUMPF_FULLPATH) continue; if (fileSystem.GetFileFlags(i) & LUMPF_FULLPATH) continue;
// Ignore lumps with empty names. // Ignore lumps with empty names.
if (fileSystem.CheckLumpName(i, "")) continue; if (fileSystem.CheckLumpName(i, "")) continue;
@ -1366,7 +1366,7 @@ int FTextureManager::GuesstimateNumTextures ()
break; break;
default: default:
if (fileSystem.GetLumpFlags(i) & LUMPF_MAYBEFLAT) numtex++; if (fileSystem.GetFileFlags(i) & LUMPF_MAYBEFLAT) numtex++;
break; break;
} }
@ -1547,7 +1547,7 @@ void FTextureManager::GenerateGlobalBrightmapFromColormap()
int lump = fileSystem.CheckNumForName("COLORMAP"); int lump = fileSystem.CheckNumForName("COLORMAP");
if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps); if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps);
if (lump == -1) return; if (lump == -1) return;
FMemLump cmap = fileSystem.ReadLump(lump); FileData cmap = fileSystem.ReadLump(lump);
uint8_t palbuffer[768]; uint8_t palbuffer[768];
ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer); ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer);

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,7 @@
#include "files.h" #include "files.h"
#include "doomdef.h" #include "doomdef.h"
#include "tarray.h" #include "tarray.h"
#include "cmdlib.h"
#include "zstring.h" #include "zstring.h"
#include "resourcefiles/resourcefile.h" #include "resourcefiles/resourcefile.h"
@ -19,43 +20,30 @@ class FResourceFile;
struct FResourceLump; struct FResourceLump;
class FTexture; class FTexture;
struct wadinfo_t union LumpShortName
{ {
// Should be "IWAD" or "PWAD". char String[9];
uint32_t Magic;
uint32_t NumLumps; uint32_t dword; // These are for accessing the first 4 or 8 chars of
uint32_t InfoTableOfs; uint64_t qword; // Name as a unit without breaking strict aliasing rules
}; };
struct wadlump_t
{
uint32_t FilePos;
uint32_t Size;
char Name[8];
};
#define IWAD_ID MAKE_ID('I','W','A','D')
#define PWAD_ID MAKE_ID('P','W','A','D')
// [RH] Copy an 8-char string and uppercase it.
void uppercopy (char *to, const char *from);
// A lump in memory. // A lump in memory.
class FMemLump class FileData
{ {
public: public:
FMemLump (); FileData ();
FMemLump (const FMemLump &copy); FileData (const FileData &copy);
FMemLump &operator= (const FMemLump &copy); FileData &operator= (const FileData &copy);
~FMemLump (); ~FileData ();
void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); } void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); }
size_t GetSize () { return Block.Len(); } size_t GetSize () { return Block.Len(); }
FString GetString () { return Block; } FString GetString () { return Block; }
private: private:
FMemLump (const FString &source); FileData (const FString &source);
FString Block; FString Block;
@ -82,12 +70,12 @@ public:
void SetMaxIwadNum(int x) { MaxIwadIndex = x; } void SetMaxIwadNum(int x) { MaxIwadIndex = x; }
void InitSingleFile(const char *filename, bool quiet = false); void InitSingleFile(const char *filename, bool quiet = false);
void InitMultipleFiles (TArray<FString> &filenames, const TArray<FString> &deletelumps, bool quiet = false, LumpFilterInfo* filter = nullptr); void InitMultipleFiles (TArray<FString> &filenames, bool quiet = false, LumpFilterInfo* filter = nullptr);
void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter); void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter);
int CheckIfWadLoaded (const char *name); int CheckIfResourceFileLoaded (const char *name) noexcept;
const char *GetWadName (int wadnum) const; const char *GetResourceFileName (int filenum) const noexcept;
const char *GetWadFullName (int wadnum) const; const char *GetResourceFileFullName (int wadnum) const noexcept;
int GetFirstLump(int wadnum) const; int GetFirstLump(int wadnum) const;
int GetLastLump(int wadnum) const; int GetLastLump(int wadnum) const;
@ -109,6 +97,11 @@ public:
int CheckNumForFullName (const char *name, bool trynormal = false, int namespc = ns_global, bool ignoreext = false); int CheckNumForFullName (const char *name, bool trynormal = false, int namespc = ns_global, bool ignoreext = false);
int CheckNumForFullName (const char *name, int wadfile); int CheckNumForFullName (const char *name, int wadfile);
int GetNumForFullName (const char *name); int GetNumForFullName (const char *name);
int FindFile(const char* name)
{
return CheckNumForFullName(name);
}
LumpShortName& GetShortName(int i); // may only be called before the hash chains are set up.
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, 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 CheckNumForFullName (const FString &name, int wadfile) { return CheckNumForFullName(name.GetChars(), wadfile); }
@ -119,9 +112,9 @@ public:
void ReadLump (int lump, void *dest); void ReadLump (int lump, void *dest);
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!) TArray<uint8_t> ReadLumpIntoArray(int lump, int pad = 0); // reads lump into a writable buffer and optionally adds some padding at the end. (FileData isn't writable!)
FMemLump ReadLump (int lump); FileData ReadLump (int lump);
FMemLump ReadLump (const char *name) { return ReadLump (GetNumForName (name)); } FileData ReadLump (const char *name) { return ReadLump (GetNumForName (name)); }
FileReader OpenLumpReader(int lump); // opens a reader that redirects to the containing file's one. 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. FileReader ReopenLumpReader(int lump, bool alwayscache = false); // opens an independent reader.
@ -130,11 +123,16 @@ public:
int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names 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 bool CheckLumpName (int lump, const char *name); // [RH] True if lump's name == name
int FindFileWithExtensions(const char* name, const char* const* exts, int count);
int FindResource(int resid, const char* type, int filenum) const noexcept;
int GetResource(int resid, const char* type, int filenum) const;
static uint32_t LumpNameHash (const char *name); // [RH] Create hash key from an 8-char name static uint32_t LumpNameHash (const char *name); // [RH] Create hash key from an 8-char name
int LumpLength (int lump) const; int FileLength (int lump) const;
int GetLumpOffset (int lump); // [RH] Returns offset of lump in the wadfile int GetFileOffset (int lump); // [RH] Returns offset of lump in the wadfile
int GetLumpFlags (int lump); // Return the flags for this lump int GetFileFlags (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 (char *to, int lump) const; // [RH] Copies the lump name to to using uppercopy
void GetLumpName (FString &to, int lump) const; void GetLumpName (FString &to, int lump) const;
const char* GetLumpName(int lump) const; const char* GetLumpName(int lump) const;
@ -149,7 +147,7 @@ public:
int GetNumLumps() const int GetNumLumps() const
{ {
return NumLumps; return NumEntries;
} }
int GetNumWads() const int GetNumWads() const
@ -157,14 +155,18 @@ public:
return Files.Size(); return Files.Size();
} }
void AddLump(FResourceLump* lump);
int AddExternalFile(const char *filename); int AddExternalFile(const char *filename);
int AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags);
FileReader* GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
void InitHashChains();
protected: protected:
struct LumpRecord; struct LumpRecord;
TArray<FResourceFile *> Files; TArray<FResourceFile *> Files;
TArray<LumpRecord> LumpInfo; TArray<LumpRecord> FileInfo;
TArray<uint32_t> Hashes; // one allocation for all hash lists. TArray<uint32_t> Hashes; // one allocation for all hash lists.
uint32_t *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure uint32_t *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure
@ -176,22 +178,19 @@ protected:
uint32_t *FirstLumpIndex_NoExt; // The same information for fully qualified paths from .zips uint32_t *FirstLumpIndex_NoExt; // The same information for fully qualified paths from .zips
uint32_t *NextLumpIndex_NoExt; uint32_t *NextLumpIndex_NoExt;
uint32_t NumLumps = 0; // Not necessarily the same as LumpInfo.Size() uint32_t* FirstLumpIndex_ResId; // The same information for fully qualified paths from .zips
uint32_t* NextLumpIndex_ResId;
uint32_t NumEntries = 0; // Not necessarily the same as FileInfo.Size()
uint32_t NumWads; uint32_t NumWads;
int IwadIndex = -1; int IwadIndex = -1;
int MaxIwadIndex = -1; int MaxIwadIndex = -1;
void InitHashChains (); // [RH] Set up the lumpinfo hashing
private: private:
void RenameSprites(const TArray<FString> &deletelumps);
void RenameNerve();
void FixMacHexen();
void DeleteAll(); void DeleteAll();
void MoveLumpsInFolder(const char *); void MoveLumpsInFolder(const char *);
FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
}; };
extern FileSystem fileSystem; extern FileSystem fileSystem;

View file

@ -307,7 +307,7 @@ bool FIntermissionActionTextscreen::ParseKey(FScanner &sc)
{ {
// Check if this comes from either Hexen.wad or Hexdd.wad and if so, map to the string table. // Check if this comes from either Hexen.wad or Hexdd.wad and if so, map to the string table.
int fileno = fileSystem.GetLumpFile(lump); int fileno = fileSystem.GetLumpFile(lump);
auto fn = fileSystem.GetWadName(fileno); auto fn = fileSystem.GetResourceFileName(fileno);
if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD"))) if (fn && (!stricmp(fn, "HEXEN.WAD") || !stricmp(fn, "HEXDD.WAD")))
{ {
FStringf key("TXT_%.5s_%s", fn, sc.String); FStringf key("TXT_%.5s_%s", fn, sc.String);

View file

@ -752,7 +752,7 @@ static int FindGLNodesInWAD(int labellump)
{ {
if (fileSystem.GetLumpFile(lump)==wadfile) if (fileSystem.GetLumpFile(lump)==wadfile)
{ {
FMemLump mem = fileSystem.ReadLump(lump); FileData mem = fileSystem.ReadLump(lump);
if (MatchHeader(fileSystem.GetLumpFullName(labellump), (const char *)mem.GetMem())) return lump; if (MatchHeader(fileSystem.GetLumpFullName(labellump), (const char *)mem.GetMem())) return lump;
} }
} }
@ -858,7 +858,7 @@ bool MapLoader::LoadGLNodes(MapData * map)
bool mapinwad = map->InWad; bool mapinwad = map->InWad;
FResourceFile * f_gwa = map->resource; FResourceFile * f_gwa = map->resource;
const char * name = fileSystem.GetWadFullName(lumpfile); const char * name = fileSystem.GetResourceFileFullName(lumpfile);
if (mapinwad) if (mapinwad)
{ {

View file

@ -1158,7 +1158,7 @@ void MapLoader::LoadSectors (MapData *map, FMissingTextureTracker &missingtex)
template<class nodetype, class subsectortype> template<class nodetype, class subsectortype>
bool MapLoader::LoadNodes (MapData * map) bool MapLoader::LoadNodes (MapData * map)
{ {
FMemLump data; FileData data;
int j; int j;
int k; int k;
nodetype *mn; nodetype *mn;
@ -2151,7 +2151,7 @@ void MapLoader::ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec
sd->SetTexture(side_t::mid, FNullTextureID()); sd->SetTexture(side_t::mid, FNullTextureID());
} }
else if ((lumpnum = fileSystem.CheckNumForName (msd->midtexture)) > 0 && else if ((lumpnum = fileSystem.CheckNumForName (msd->midtexture)) > 0 &&
fileSystem.LumpLength (lumpnum) == 65536) fileSystem.FileLength (lumpnum) == 65536)
{ {
*alpha = (short)DetermineTranslucency (lumpnum); *alpha = (short)DetermineTranslucency (lumpnum);
sd->SetTexture(side_t::mid, FNullTextureID()); sd->SetTexture(side_t::mid, FNullTextureID());

View file

@ -155,10 +155,10 @@ bool MapLoader::LoadScriptFile (const char *name, bool include, int type)
FileReader lump = fileSystem.ReopenLumpReader (lumpnum); FileReader lump = fileSystem.ReopenLumpReader (lumpnum);
auto fn = fileSystem.GetLumpFile(lumpnum); auto fn = fileSystem.GetLumpFile(lumpnum);
auto wadname = fileSystem.GetWadName(fn); auto wadname = fileSystem.GetResourceFileName(fn);
if (stricmp(wadname, "STRIFE0.WAD") && stricmp(wadname, "STRIFE1.WAD") && stricmp(wadname, "SVE.WAD")) name = nullptr; // Only localize IWAD content. if (stricmp(wadname, "STRIFE0.WAD") && stricmp(wadname, "STRIFE1.WAD") && stricmp(wadname, "SVE.WAD")) name = nullptr; // Only localize IWAD content.
bool res = LoadScriptFile(name, lumpnum, lump, fileSystem.LumpLength(lumpnum), include, type); bool res = LoadScriptFile(name, lumpnum, lump, fileSystem.FileLength(lumpnum), include, type);
return res; return res;
} }

View file

@ -204,7 +204,7 @@ void FSavegameManager::ReadSaveStrings()
// old, incompatible savegame. List as not usable. // old, incompatible savegame. List as not usable.
oldVer = true; oldVer = true;
} }
else if (iwad.CompareNoCase(fileSystem.GetWadName(fileSystem.GetIwadNum())) == 0) else if (iwad.CompareNoCase(fileSystem.GetResourceFileName(fileSystem.GetIwadNum())) == 0)
{ {
missing = !G_CheckSaveGameWads(arc, false); missing = !G_CheckSaveGameWads(arc, false);
} }

View file

@ -40,8 +40,11 @@
#include "w_wad.h" #include "w_wad.h"
#include "md5.h" #include "md5.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "cmdlib.h"
#define IWAD_ID MAKE_ID('I','W','A','D')
#define PWAD_ID MAKE_ID('P','W','A','D')
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
inline bool P_IsBuildMap(MapData *map) inline bool P_IsBuildMap(MapData *map)
{ {

View file

@ -223,7 +223,7 @@ bool FScriptLoader::ParseInfo(MapData * map)
// Try a global FS lump // Try a global FS lump
int lumpnum=fileSystem.CheckNumForName("FSGLOBAL"); int lumpnum=fileSystem.CheckNumForName("FSGLOBAL");
if (lumpnum<0) return false; if (lumpnum<0) return false;
lumpsize=fileSystem.LumpLength(lumpnum); lumpsize=fileSystem.FileLength(lumpnum);
if (lumpsize==0) return false; if (lumpsize==0) return false;
fsglobal=true; fsglobal=true;
lump=new char[lumpsize+3]; lump=new char[lumpsize+3];

View file

@ -417,7 +417,7 @@ void DFsScript::ParseInclude(FLevelLocals *Level, char *lumpname)
return; return;
} }
int lumplen=fileSystem.LumpLength(lumpnum); int lumplen=fileSystem.FileLength(lumpnum);
lump=new char[lumplen+10]; lump=new char[lumplen+10];
fileSystem.ReadLump(lumpnum,lump); fileSystem.ReadLump(lumpnum,lump);

View file

@ -2224,7 +2224,7 @@ bool FBehavior::Init(FLevelLocals *Level, int lumpnum, FileReader * fr, int len,
// 2. Corrupt modules won't be reported when a level is being loaded if this function quits before // 2. Corrupt modules won't be reported when a level is being loaded if this function quits before
// adding it to the list. // adding it to the list.
if (fr == NULL) len = fileSystem.LumpLength (lumpnum); if (fr == NULL) len = fileSystem.FileLength (lumpnum);
@ -2318,7 +2318,7 @@ bool FBehavior::Init(FLevelLocals *Level, int lumpnum, FileReader * fr, int len,
if ((Level->flags2 & LEVEL2_HEXENHACK) && gameinfo.gametype == GAME_Hexen && lumpnum == -1 && reallumpnum > 0) if ((Level->flags2 & LEVEL2_HEXENHACK) && gameinfo.gametype == GAME_Hexen && lumpnum == -1 && reallumpnum > 0)
{ {
int fileno = fileSystem.GetLumpFile(reallumpnum); int fileno = fileSystem.GetLumpFile(reallumpnum);
const char * filename = fileSystem.GetWadName(fileno); const char * filename = fileSystem.GetResourceFileName(fileno);
if (!stricmp(filename, "HEXEN.WAD") || !stricmp(filename, "HEXDD.WAD")) if (!stricmp(filename, "HEXEN.WAD") || !stricmp(filename, "HEXDD.WAD"))
{ {
ShouldLocalize = true; ShouldLocalize = true;

View file

@ -392,7 +392,7 @@ void player_t::SetLogNumber (int num)
if (lumpnum != -1) if (lumpnum != -1)
{ {
auto fn = fileSystem.GetLumpFile(lumpnum); auto fn = fileSystem.GetLumpFile(lumpnum);
auto wadname = fileSystem.GetWadName(fn); auto wadname = fileSystem.GetResourceFileName(fn);
if (!stricmp(wadname, "STRIFE0.WAD") || !stricmp(wadname, "STRIFE1.WAD") || !stricmp(wadname, "SVE.WAD")) if (!stricmp(wadname, "STRIFE0.WAD") || !stricmp(wadname, "STRIFE1.WAD") || !stricmp(wadname, "SVE.WAD"))
{ {
// If this is an original IWAD text, try looking up its lower priority string version first. // If this is an original IWAD text, try looking up its lower priority string version first.

View file

@ -115,7 +115,7 @@ static int DoomSpecificInfo (char *buffer, char *end)
} }
p += snprintf(buffer + p, size - p, "\n"); p += snprintf(buffer + p, size - p, "\n");
for (i = 0; (arg = fileSystem.GetWadName(i)) != NULL; ++i) for (i = 0; (arg = fileSystem.GetResourceFileName(i)) != NULL; ++i)
{ {
p += snprintf(buffer + p, size - p, "\nWad %d: %s", i, arg); p += snprintf(buffer + p, size - p, "\nWad %d: %s", i, arg);
} }

View file

@ -242,7 +242,7 @@ void R_InitColormaps (bool allowCustomColormap)
for (unsigned j = 1; j < fakecmaps.Size(); j++) for (unsigned j = 1; j < fakecmaps.Size(); j++)
{ {
if (fileSystem.LumpLength (fakecmaps[j].lump) >= 256) if (fileSystem.FileLength (fakecmaps[j].lump) >= 256)
{ {
int k, r, g, b; int k, r, g, b;
auto lump = fileSystem.OpenLumpReader (fakecmaps[j].lump); auto lump = fileSystem.OpenLumpReader (fakecmaps[j].lump);

View file

@ -407,8 +407,8 @@ static unsigned FindModel(const char * path, const char * modelfile)
if (!Models[i]->mFileName.CompareNoCase(fullname)) return i; if (!Models[i]->mFileName.CompareNoCase(fullname)) return i;
} }
int len = fileSystem.LumpLength(lump); int len = fileSystem.FileLength(lump);
FMemLump lumpd = fileSystem.ReadLump(lump); FileData lumpd = fileSystem.ReadLump(lump);
char * buffer = (char*)lumpd.GetMem(); char * buffer = (char*)lumpd.GetMem();
if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 ) if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 )

View file

@ -170,7 +170,7 @@ bool FDMDModel::Load(const char * path, int lumpnum, const char * buffer, int le
void FDMDModel::LoadGeometry() void FDMDModel::LoadGeometry()
{ {
static int axis[3] = { VX, VY, VZ }; static int axis[3] = { VX, VY, VZ };
FMemLump lumpdata = fileSystem.ReadLump(mLumpNum); FileData lumpdata = fileSystem.ReadLump(mLumpNum);
const char *buffer = (const char *)lumpdata.GetMem(); const char *buffer = (const char *)lumpdata.GetMem();
texCoords = new FTexCoord[info.numTexCoords]; texCoords = new FTexCoord[info.numTexCoords];
memcpy(texCoords, buffer + info.offsetTexCoords, info.numTexCoords * sizeof(FTexCoord)); memcpy(texCoords, buffer + info.offsetTexCoords, info.numTexCoords * sizeof(FTexCoord));
@ -496,7 +496,7 @@ void FMD2Model::LoadGeometry()
{ {
static int axis[3] = { VX, VY, VZ }; static int axis[3] = { VX, VY, VZ };
uint8_t *md2_frames; uint8_t *md2_frames;
FMemLump lumpdata = fileSystem.ReadLump(mLumpNum); FileData lumpdata = fileSystem.ReadLump(mLumpNum);
const char *buffer = (const char *)lumpdata.GetMem(); const char *buffer = (const char *)lumpdata.GetMem();
texCoords = new FTexCoord[info.numTexCoords]; texCoords = new FTexCoord[info.numTexCoords];

View file

@ -185,7 +185,7 @@ bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int le
void FMD3Model::LoadGeometry() void FMD3Model::LoadGeometry()
{ {
FMemLump lumpdata = fileSystem.ReadLump(mLumpNum); FileData lumpdata = fileSystem.ReadLump(mLumpNum);
const char *buffer = (const char *)lumpdata.GetMem(); const char *buffer = (const char *)lumpdata.GetMem();
md3_header_t * hdr = (md3_header_t *)buffer; md3_header_t * hdr = (md3_header_t *)buffer;
md3_surface_t * surf = (md3_surface_t*)(buffer + LittleLong(hdr->Ofs_Surfaces)); md3_surface_t * surf = (md3_surface_t*)(buffer + LittleLong(hdr->Ofs_Surfaces));

View file

@ -62,7 +62,7 @@ bool FUE1Model::Load( const char *filename, int lumpnum, const char *buffer, int
void FUE1Model::LoadGeometry() void FUE1Model::LoadGeometry()
{ {
FMemLump lump, lump2; FileData lump, lump2;
const char *buffer, *buffer2; const char *buffer, *buffer2;
lump = fileSystem.ReadLump(mDataLump); lump = fileSystem.ReadLump(mDataLump);
buffer = (char*)lump.GetMem(); buffer = (char*)lump.GetMem();

View file

@ -490,7 +490,7 @@ static void R_CreatePlayerTranslation (float h, float s, float v, const FPlayerC
bases = s; bases = s;
basev = v; basev = v;
if (colorset != NULL && colorset->Lump >= 0 && fileSystem.LumpLength(colorset->Lump) < 256) if (colorset != NULL && colorset->Lump >= 0 && fileSystem.FileLength(colorset->Lump) < 256)
{ // Bad table length. Ignore it. { // Bad table length. Ignore it.
colorset = NULL; colorset = NULL;
} }
@ -511,7 +511,7 @@ static void R_CreatePlayerTranslation (float h, float s, float v, const FPlayerC
} }
else else
{ {
FMemLump translump = fileSystem.ReadLump(colorset->Lump); FileData translump = fileSystem.ReadLump(colorset->Lump);
const uint8_t *trans = (const uint8_t *)translump.GetMem(); const uint8_t *trans = (const uint8_t *)translump.GetMem();
for (i = start; i <= end; ++i) for (i = start; i <= end; ++i)
{ {

View file

@ -949,7 +949,7 @@ CCMD (skins)
static void R_CreateSkinTranslation (const char *palname) static void R_CreateSkinTranslation (const char *palname)
{ {
FMemLump lump = fileSystem.ReadLump (palname); FileData lump = fileSystem.ReadLump (palname);
const uint8_t *otherPal = (uint8_t *)lump.GetMem(); const uint8_t *otherPal = (uint8_t *)lump.GetMem();
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)

View file

@ -284,7 +284,7 @@ int ReadPalette(int lumpnum, uint8_t *buffer)
{ {
return 0; return 0;
} }
FMemLump lump = fileSystem.ReadLump(lumpnum); FileData lump = fileSystem.ReadLump(lumpnum);
uint8_t *lumpmem = (uint8_t*)lump.GetMem(); uint8_t *lumpmem = (uint8_t*)lump.GetMem();
memset(buffer, 0, 768); memset(buffer, 0, 768);

View file

@ -178,7 +178,7 @@ FVoxel *R_LoadKVX(int lumpnum)
int mip, maxmipsize; int mip, maxmipsize;
int i, j, n; int i, j, n;
FMemLump lump = fileSystem.ReadLump(lumpnum); // FMemLump adds an extra 0 byte to the end. FileData lump = fileSystem.ReadLump(lumpnum); // FileData adds an extra 0 byte to the end.
uint8_t *rawvoxel = (uint8_t *)lump.GetMem(); uint8_t *rawvoxel = (uint8_t *)lump.GetMem();
int voxelsize = (int)(lump.GetSize()-1); int voxelsize = (int)(lump.GetSize()-1);

View file

@ -333,11 +333,11 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0); int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump); if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump);
FMemLump vp_data = fileSystem.ReadLump(vp_lump); FileData vp_data = fileSystem.ReadLump(vp_lump);
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0); int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0);
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump); if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump);
FMemLump fp_data = fileSystem.ReadLump(fp_lump); FileData fp_data = fileSystem.ReadLump(fp_lump);
@ -385,7 +385,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
{ {
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump); int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump); if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump);
FMemLump pp_data = fileSystem.ReadLump(pp_lump); FileData pp_data = fileSystem.ReadLump(pp_lump);
if (pp_data.GetString().IndexOf("ProcessMaterial") < 0) if (pp_data.GetString().IndexOf("ProcessMaterial") < 0)
{ {
@ -394,7 +394,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
// add ProcessMaterial function that calls the older ProcessTexel function // add ProcessMaterial function that calls the older ProcessTexel function
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0); int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp"); if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp");
FMemLump pl_data = fileSystem.ReadLump(pl_lump); FileData pl_data = fileSystem.ReadLump(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars(); fp_comb << "\n" << pl_data.GetString().GetChars();
if (pp_data.GetString().IndexOf("ProcessTexel") < 0) if (pp_data.GetString().IndexOf("ProcessTexel") < 0)
@ -420,7 +420,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
{ {
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultlight.fp", 0); int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultlight.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp"); if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp");
FMemLump pl_data = fileSystem.ReadLump(pl_lump); FileData pl_data = fileSystem.ReadLump(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars(); fp_comb << "\n" << pl_data.GetString().GetChars();
} }
} }
@ -435,7 +435,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
{ {
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0); int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog); if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog);
FMemLump pp_data = fileSystem.ReadLump(pp_lump); FileData pp_data = fileSystem.ReadLump(pp_lump);
fp_comb << pp_data.GetString().GetChars() << "\n"; fp_comb << pp_data.GetString().GetChars() << "\n";
} }

View file

@ -424,7 +424,7 @@ static void InitBoomColormaps ()
remap[0] = 0; remap[0] = 0;
for (j = 1; j < fakecmaps.Size(); j++) for (j = 1; j < fakecmaps.Size(); j++)
{ {
if (fileSystem.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) if (fileSystem.FileLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256)
{ {
int k, r; int k, r;
auto lump = fileSystem.OpenLumpReader (fakecmaps[j].lump); auto lump = fileSystem.OpenLumpReader (fakecmaps[j].lump);

View file

@ -380,7 +380,7 @@ normal:
FString V_GetColorStringByName (const char *name, FScriptPosition *sc) FString V_GetColorStringByName (const char *name, FScriptPosition *sc)
{ {
FMemLump rgbNames; FileData rgbNames;
char *rgbEnd; char *rgbEnd;
char *rgb, *endp; char *rgb, *endp;
int rgblump; int rgblump;
@ -399,7 +399,7 @@ FString V_GetColorStringByName (const char *name, FScriptPosition *sc)
rgbNames = fileSystem.ReadLump (rgblump); rgbNames = fileSystem.ReadLump (rgblump);
rgb = (char *)rgbNames.GetMem(); rgb = (char *)rgbNames.GetMem();
rgbEnd = rgb + fileSystem.LumpLength (rgblump); rgbEnd = rgb + fileSystem.FileLength (rgblump);
step = 0; step = 0;
namelen = strlen (name); namelen = strlen (name);

View file

@ -347,7 +347,7 @@ FString VkShaderManager::LoadPublicShaderLump(const char *lumpname)
{ {
int lump = fileSystem.CheckNumForFullName(lumpname); int lump = fileSystem.CheckNumForFullName(lumpname);
if (lump == -1) I_Error("Unable to load '%s'", lumpname); if (lump == -1) I_Error("Unable to load '%s'", lumpname);
FMemLump data = fileSystem.ReadLump(lump); FileData data = fileSystem.ReadLump(lump);
return data.GetString(); return data.GetString();
} }
@ -355,6 +355,6 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
{ {
int lump = fileSystem.CheckNumForFullName(lumpname, 0); int lump = fileSystem.CheckNumForFullName(lumpname, 0);
if (lump == -1) I_Error("Unable to load '%s'", lumpname); if (lump == -1) I_Error("Unable to load '%s'", lumpname);
FMemLump data = fileSystem.ReadLump(lump); FileData data = fileSystem.ReadLump(lump);
return data.GetString(); return data.GetString();
} }

View file

@ -1276,7 +1276,7 @@ void ParseDecorate (FScanner &sc, PNamespace *ns)
if (includefile != 0) if (includefile != 0)
{ {
I_FatalError("File %s is overriding core lump %s.", I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetWadFullName(includefile), sc.String); fileSystem.GetResourceFileFullName(includefile), sc.String);
} }
} }
FScanner newscanner; FScanner newscanner;

View file

@ -3141,6 +3141,85 @@ DEFINE_ACTION_FUNCTION_NATIVE(_AltHUD, GetLatency, Net_GetLatency)
return numret; return numret;
} }
//==========================================================================
//
// file system
//
//==========================================================================
//==========================================================================
//
// W_NumLumps
//
//==========================================================================
DEFINE_ACTION_FUNCTION(_Wads, GetNumLumps)
{
PARAM_PROLOGUE;
ACTION_RETURN_INT(fileSystem.GetNumLumps());
}
DEFINE_ACTION_FUNCTION(_Wads, CheckNumForName)
{
PARAM_PROLOGUE;
PARAM_STRING(name);
PARAM_INT(ns);
PARAM_INT(wadnum);
PARAM_BOOL(exact);
ACTION_RETURN_INT(fileSystem.CheckNumForName(name, ns, wadnum, exact));
}
DEFINE_ACTION_FUNCTION(_Wads, CheckNumForFullName)
{
PARAM_PROLOGUE;
PARAM_STRING(name);
ACTION_RETURN_INT(fileSystem.CheckNumForFullName(name));
}
DEFINE_ACTION_FUNCTION(_Wads, FindLump)
{
PARAM_PROLOGUE;
PARAM_STRING(name);
PARAM_INT(startlump);
PARAM_INT(ns);
const bool isLumpValid = startlump >= 0 && startlump < fileSystem.GetNumLumps();
ACTION_RETURN_INT(isLumpValid ? fileSystem.FindLump(name, &startlump, 0 != ns) : -1);
}
DEFINE_ACTION_FUNCTION(_Wads, GetLumpName)
{
PARAM_PROLOGUE;
PARAM_INT(lump);
FString lumpname;
fileSystem.GetLumpName(lumpname, lump);
ACTION_RETURN_STRING(lumpname);
}
DEFINE_ACTION_FUNCTION(_Wads, GetLumpFullName)
{
PARAM_PROLOGUE;
PARAM_INT(lump);
ACTION_RETURN_STRING(fileSystem.GetLumpFullName(lump));
}
DEFINE_ACTION_FUNCTION(_Wads, GetLumpNamespace)
{
PARAM_PROLOGUE;
PARAM_INT(lump);
ACTION_RETURN_INT(fileSystem.GetLumpNamespace(lump));
}
DEFINE_ACTION_FUNCTION(_Wads, ReadLump)
{
PARAM_PROLOGUE;
PARAM_INT(lump);
const bool isLumpValid = lump >= 0 && lump < fileSystem.GetNumLumps();
ACTION_RETURN_STRING(isLumpValid ? fileSystem.ReadLump(lump).GetString() : FString());
}
//========================================================================== //==========================================================================
// //
// //

View file

@ -426,7 +426,7 @@ static void DoParse(int lumpnum)
if (fileno == 0 && fileno2 != 0) if (fileno == 0 && fileno2 != 0)
{ {
I_FatalError("File %s is overriding core lump %s.", I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetWadFullName(fileSystem.GetLumpFile(lumpnum)), Includes[i].GetChars()); fileSystem.GetResourceFileFullName(fileSystem.GetLumpFile(lumpnum)), Includes[i].GetChars());
} }
ParseSingleFile(nullptr, nullptr, lumpnum, parser, state); ParseSingleFile(nullptr, nullptr, lumpnum, parser, state);

View file

@ -191,7 +191,7 @@ static void SetupWgOpn()
{ {
return; return;
} }
FMemLump data = fileSystem.ReadLump(lump); FileData data = fileSystem.ReadLump(lump);
ZMusic_SetWgOpn(data.GetMem(), (uint32_t)data.GetSize()); ZMusic_SetWgOpn(data.GetMem(), (uint32_t)data.GetSize());
} }
@ -202,7 +202,7 @@ static void SetupDMXGUS()
{ {
return; return;
} }
FMemLump data = fileSystem.ReadLump(lump); FileData data = fileSystem.ReadLump(lump);
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize()); ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
} }

View file

@ -441,7 +441,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
} }
if (handle == nullptr) if (handle == nullptr)
{ {
if (fileSystem.LumpLength (lumpnum) == 0) if (fileSystem.FileLength (lumpnum) == 0)
{ {
return false; return false;
} }

View file

@ -279,7 +279,7 @@ void FScanner :: OpenLumpNum (int lump)
{ {
Close (); Close ();
{ {
FMemLump mem = fileSystem.ReadLump(lump); FileData mem = fileSystem.ReadLump(lump);
ScriptBuffer = mem.GetString(); ScriptBuffer = mem.GetString();
} }
ScriptName = fileSystem.GetLumpFullPath(lump); ScriptName = fileSystem.GetLumpFullPath(lump);

View file

@ -1016,7 +1016,7 @@ void DoomSpecificInfo (char *buffer, size_t bufflen)
FString cmdline(GetCommandLineW()); FString cmdline(GetCommandLineW());
buffer += mysnprintf (buffer, buffend - buffer, "\r\nCommand line: %s\r\n", cmdline.GetChars() ); buffer += mysnprintf (buffer, buffend - buffer, "\r\nCommand line: %s\r\n", cmdline.GetChars() );
for (i = 0; (arg = fileSystem.GetWadName (i)) != NULL; ++i) for (i = 0; (arg = fileSystem.GetResourceFileName (i)) != NULL; ++i)
{ {
buffer += mysnprintf (buffer, buffend - buffer, "\r\nWad %d: %s", i, arg); buffer += mysnprintf (buffer, buffend - buffer, "\r\nWad %d: %s", i, arg);
} }

View file

@ -526,7 +526,7 @@ int RunEndoom()
bool blinking = false, blinkstate = false; bool blinking = false, blinkstate = false;
int i; int i;
if (endoom_lump < 0 || fileSystem.LumpLength (endoom_lump) != 4000) if (endoom_lump < 0 || fileSystem.FileLength (endoom_lump) != 4000)
{ {
return 0; return 0;
} }

View file

@ -413,9 +413,9 @@ FHexenStartupScreen::FHexenStartupScreen(int max_progress, long& hr)
int notch_lump = fileSystem.CheckNumForName("NOTCH"); int notch_lump = fileSystem.CheckNumForName("NOTCH");
hr = -1; hr = -1;
if (startup_lump < 0 || fileSystem.LumpLength(startup_lump) != 153648 || !ST_Util_CreateStartupWindow() || if (startup_lump < 0 || fileSystem.FileLength(startup_lump) != 153648 || !ST_Util_CreateStartupWindow() ||
netnotch_lump < 0 || fileSystem.LumpLength(netnotch_lump) != ST_NETNOTCH_WIDTH / 2 * ST_NETNOTCH_HEIGHT || netnotch_lump < 0 || fileSystem.FileLength(netnotch_lump) != ST_NETNOTCH_WIDTH / 2 * ST_NETNOTCH_HEIGHT ||
notch_lump < 0 || fileSystem.LumpLength(notch_lump) != ST_NOTCH_WIDTH / 2 * ST_NOTCH_HEIGHT) notch_lump < 0 || fileSystem.FileLength(notch_lump) != ST_NOTCH_WIDTH / 2 * ST_NOTCH_HEIGHT)
{ {
NetNotchBits = NotchBits = NULL; NetNotchBits = NotchBits = NULL;
return; return;
@ -579,7 +579,7 @@ FHereticStartupScreen::FHereticStartupScreen(int max_progress, long& hr)
uint8_t* font; uint8_t* font;
hr = -1; hr = -1;
if (loading_lump < 0 || fileSystem.LumpLength(loading_lump) != 4000 || !ST_Util_CreateStartupWindow()) if (loading_lump < 0 || fileSystem.FileLength(loading_lump) != 4000 || !ST_Util_CreateStartupWindow())
{ {
return; return;
} }
@ -722,7 +722,7 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, long& hr)
StartupPics[i] = NULL; StartupPics[i] = NULL;
} }
if (startup_lump < 0 || fileSystem.LumpLength(startup_lump) != 64000 || !ST_Util_CreateStartupWindow()) if (startup_lump < 0 || fileSystem.FileLength(startup_lump) != 64000 || !ST_Util_CreateStartupWindow())
{ {
return; return;
} }
@ -742,7 +742,7 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, long& hr)
int lumpnum = fileSystem.CheckNumForName(StrifeStartupPicNames[i]); int lumpnum = fileSystem.CheckNumForName(StrifeStartupPicNames[i]);
int lumplen; int lumplen;
if (lumpnum >= 0 && (lumplen = fileSystem.LumpLength(lumpnum)) == StrifeStartupPicSizes[i]) if (lumpnum >= 0 && (lumplen = fileSystem.FileLength(lumpnum)) == StrifeStartupPicSizes[i])
{ {
auto lumpr = fileSystem.OpenLumpReader(lumpnum); auto lumpr = fileSystem.OpenLumpReader(lumpnum);
StartupPics[i] = new uint8_t[lumplen]; StartupPics[i] = new uint8_t[lumplen];
@ -1061,7 +1061,7 @@ uint8_t* ST_Util_LoadFont(const char* filename)
{ // font not found { // font not found
return NULL; return NULL;
} }
lumplen = fileSystem.LumpLength(lumpnum); lumplen = fileSystem.FileLength(lumpnum);
height = lumplen / 256; height = lumplen / 256;
if (height * 256 != lumplen) if (height * 256 != lumplen)
{ // font is a bad size { // font is a bad size