- Roll back filesystem changes. These were causing instabilities in the master branch that were interfering with development.

This commit is contained in:
Rachael Alexanderson 2025-01-03 09:02:12 -05:00
commit f3b0c3ac5e
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0
90 changed files with 1349 additions and 1582 deletions

View file

@ -58,22 +58,52 @@ struct wadlump_t
char Name[8];
};
//==========================================================================
//
// Wad file
//
//==========================================================================
class FWadFile : public FResourceFile
{
bool IsMarker(int lump, const char *marker);
void SetNamespace(const char *startmarker, const char *endmarker, namespace_t space, FileSystemMessageFunc Printf, bool flathack=false);
void SkinHack (FileSystemMessageFunc Printf);
public:
FWadFile(const char * filename, FileReader &file, StringPool* sp);
bool Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf);
};
//==========================================================================
//
// FWadFile::FWadFile
//
// Initializes a WAD file
//
//==========================================================================
FWadFile::FWadFile(const char *filename, FileReader &file, StringPool* sp)
: FResourceFile(filename, file, sp)
{
}
//==========================================================================
//
// Open it
//
//==========================================================================
static bool OpenWAD(FResourceFile* file, FileSystemFilterInfo*, FileSystemMessageFunc Printf)
bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf)
{
wadinfo_t header;
uint32_t InfoTableOfs;
bool isBigEndian = false; // Little endian is assumed until proven otherwise
auto Reader = file->GetContainerReader();
auto wadSize = Reader->GetLength();
auto wadSize = Reader.GetLength();
Reader->Read(&header, sizeof(header));
uint32_t NumLumps = LittleLong(header.NumLumps);
Reader.Read(&header, sizeof(header));
NumLumps = LittleLong(header.NumLumps);
InfoTableOfs = LittleLong(header.InfoTableOfs);
// Check to see if the little endian interpretation is valid
@ -87,16 +117,16 @@ static bool OpenWAD(FResourceFile* file, FileSystemFilterInfo*, FileSystemMessag
// Check again to detect broken wads
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
{
Printf(FSMessageLevel::Error, "%s: Bad directory offset.\n", file->GetFileName());
Printf(FSMessageLevel::Error, "%s: Bad directory offset.\n", FileName);
return false;
}
}
Reader->Seek(InfoTableOfs, FileReader::SeekSet);
auto fd = Reader->Read(NumLumps * sizeof(wadlump_t));
Reader.Seek(InfoTableOfs, FileReader::SeekSet);
auto fd = Reader.Read(NumLumps * sizeof(wadlump_t));
auto fileinfo = (const wadlump_t*)fd.data();
auto Entries = file->AllocateEntries(NumLumps);
AllocateEntries(NumLumps);
for(uint32_t i = 0; i < NumLumps; i++)
{
@ -113,17 +143,17 @@ static bool OpenWAD(FResourceFile* file, FileSystemFilterInfo*, FileSystemMessag
else if (ishigh > 1)
{
// This may not end up printing something proper because we do not know what encoding might have been used.
Printf(FSMessageLevel::Warning, "%s: Lump name %.8s contains invalid characters\n", file->GetFileName(), fileinfo[i].Name);
n[0] = 0;
Printf(FSMessageLevel::Warning, "%s: Lump name %.8s contains invalid characters\n", FileName, fileinfo[i].Name);
}
Entries[i].FileName = nullptr;
Entries[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos);
Entries[i].CompressedSize = Entries[i].Length = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size);
Entries[i].Namespace = ns_global;
Entries[i].Flags = ishigh? RESFF_SHORTNAME | RESFF_COMPRESSED : RESFF_SHORTNAME;
Entries[i].Method = ishigh == 1? METHOD_LZSS : METHOD_STORED;
Entries[i].FileName = file->NormalizeFileName(n, 0, true);
Entries[i].FileName = stringpool->Strdup(n);
// This doesn't set up the namespace yet.
}
for (uint32_t i = 0; i < NumLumps; i++)
@ -131,21 +161,250 @@ static bool OpenWAD(FResourceFile* file, FileSystemFilterInfo*, FileSystemMessag
if (Entries[i].Method == METHOD_LZSS)
{
// compressed size is implicit.
Entries[i].CompressedSize = (i == NumLumps - 1 ? Reader->GetLength() : Entries[i + 1].Position) - Entries[i].Position;
Entries[i].CompressedSize = (i == NumLumps - 1 ? Reader.GetLength() : Entries[i + 1].Position) - Entries[i].Position;
}
}
file->GenerateHash(); // Do this before the lump processing below.
GenerateHash(); // Do this before the lump processing below.
SetNamespace("s_start", "s_end", ns_sprites, Printf);
SetNamespace("f_start", "f_end", ns_flats, Printf, true);
SetNamespace("c_start", "c_end", ns_colormaps, Printf);
SetNamespace("a_start", "a_end", ns_acslibrary, Printf);
SetNamespace("tx_start", "tx_end", ns_newtextures, Printf);
SetNamespace("v_start", "v_end", ns_strifevoices, Printf);
SetNamespace("hi_start", "hi_end", ns_hires, Printf);
SetNamespace("vx_start", "vx_end", ns_voxels, Printf);
SkinHack(Printf);
return true;
}
//==========================================================================
//
// IsMarker
//
// (from BOOM)
//
//==========================================================================
inline bool FWadFile::IsMarker(int lump, const char *marker)
{
if (Entries[lump].FileName[0] == marker[0])
{
return (!strcmp(Entries[lump].FileName, marker) ||
(marker[1] == '_' && !strcmp(Entries[lump].FileName +1, marker)));
}
else return false;
}
//==========================================================================
//
// SetNameSpace
//
// Sets namespace information for the lumps. It always looks for the first
// x_START and the last x_END lump, except when loading flats. In this case
// F_START may be absent and if that is the case all lumps with a size of
// 4096 will be flagged appropriately.
//
//==========================================================================
// This class was supposed to be local in the function but GCC
// does not like that.
struct Marker
{
int markertype;
unsigned int index;
};
void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, namespace_t space, FileSystemMessageFunc Printf, bool flathack)
{
bool warned = false;
int numstartmarkers = 0, numendmarkers = 0;
unsigned int i;
std::vector<Marker> markers;
for(i = 0; i < NumLumps; i++)
{
if (IsMarker(i, startmarker))
{
Marker m = { 0, i };
markers.push_back(m);
numstartmarkers++;
}
else if (IsMarker(i, endmarker))
{
Marker m = { 1, i };
markers.push_back(m);
numendmarkers++;
}
}
if (numstartmarkers == 0)
{
if (numendmarkers == 0) return; // no markers found
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName, endmarker, startmarker);
if (flathack)
{
// We have found no F_START but one or more F_END markers.
// mark all lumps before the last F_END marker as potential flats.
unsigned int end = markers[markers.size()-1].index;
for(unsigned int ii = 0; ii < end; ii++)
{
if (Entries[ii].Length == 4096)
{
// We can't add this to the flats namespace but
// it needs to be flagged for the texture manager.
Printf(FSMessageLevel::DebugNotify, "%s: Marking %s as potential flat\n", FileName, Entries[ii].FileName);
Entries[ii].Flags |= RESFF_MAYBEFLAT;
}
}
}
return;
}
i = 0;
while (i < markers.size())
{
int start, end;
if (markers[i].markertype != 0)
{
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName, endmarker, startmarker);
i++;
continue;
}
start = i++;
// skip over subsequent x_START markers
while (i < markers.size() && markers[i].markertype == 0)
{
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", FileName, startmarker);
i++;
continue;
}
// same for x_END markers
while (i < markers.size()-1 && (markers[i].markertype == 1 && markers[i+1].markertype == 1))
{
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", FileName, endmarker);
i++;
continue;
}
// We found a starting marker but no end marker. Ignore this block.
if (i >= markers.size())
{
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName, startmarker, endmarker);
end = NumLumps;
}
else
{
end = markers[i++].index;
}
// we found a marked block
Printf(FSMessageLevel::DebugNotify, "%s: Found %s block at (%d-%d)\n", FileName, startmarker, markers[start].index, end);
for(int j = markers[start].index + 1; j < end; j++)
{
if (Entries[j].Namespace != ns_global)
{
if (!warned)
{
Printf(FSMessageLevel::Warning, "%s: Overlapping namespaces found (lump %d)\n", FileName, j);
}
warned = true;
}
else if (space == ns_sprites && Entries[j].Length < 8)
{
// sf 26/10/99:
// ignore sprite lumps smaller than 8 bytes (the smallest possible)
// in size -- this was used by some dmadds wads
// as an 'empty' graphics resource
Printf(FSMessageLevel::DebugWarn, "%s: Skipped empty sprite %s (lump %d)\n", FileName, Entries[j].FileName, j);
}
else
{
Entries[j].Namespace = space;
}
}
}
}
//==========================================================================
//
// W_SkinHack
//
// Tests a wad file to see if it contains an S_SKIN marker. If it does,
// every lump in the wad is moved into a new namespace. Because skins are
// only supposed to replace player sprites, sounds, or faces, this should
// not be a problem. Yes, there are skins that replace more than that, but
// they are such a pain, and breaking them like this was done on purpose.
// This also renames any S_SKINxx lumps to just S_SKIN.
//
//==========================================================================
void FWadFile::SkinHack (FileSystemMessageFunc Printf)
{
// this being static is not a problem. The only relevant thing is that each skin gets a different number.
static int namespc = ns_firstskin;
bool skinned = false;
bool hasmap = false;
uint32_t i;
for (i = 0; i < NumLumps; i++)
{
auto lump = &Entries[i];
if (!strnicmp(lump->FileName, "S_SKIN", 6))
{ // Wad has at least one skin.
lump->FileName = "S_SKIN";
if (!skinned)
{
skinned = true;
uint32_t j;
for (j = 0; j < NumLumps; j++)
{
Entries[j].Namespace = namespc;
}
namespc++;
}
}
// needless to say, this check is entirely useless these days as map names can be more diverse..
if ((lump->FileName[0] == 'M' &&
lump->FileName[1] == 'A' &&
lump->FileName[2] == 'P' &&
lump->FileName[3] >= '0' && lump->FileName[3] <= '9' &&
lump->FileName[4] >= '0' && lump->FileName[4] <= '9' &&
lump->FileName[5] == '\0')
||
(lump->FileName[0] == 'E' &&
lump->FileName[1] >= '0' && lump->FileName[1] <= '9' &&
lump->FileName[2] == 'M' &&
lump->FileName[3] >= '0' && lump->FileName[3] <= '9' &&
lump->FileName[4] == '\0'))
{
hasmap = true;
}
}
if (skinned && hasmap)
{
Printf(FSMessageLevel::Attention, "%s: The maps will not be loaded because it has a skin.\n", FileName);
Printf(FSMessageLevel::Attention, "You should remove the skin from the wad to play these maps.\n");
}
}
//==========================================================================
//
// File open
//
//==========================================================================
FResourceFile *CheckWad(const char *filename, FileReader &file, FileSystemFilterInfo* filter, FileSystemMessageFunc Printf, StringPool* sp)
FResourceFile *CheckWad(const char *filename, FileReader &file, LumpFilterInfo* filter, FileSystemMessageFunc Printf, StringPool* sp)
{
char head[4];
@ -156,8 +415,8 @@ FResourceFile *CheckWad(const char *filename, FileReader &file, FileSystemFilter
file.Seek(0, FileReader::SeekSet);
if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4))
{
auto rf = new FResourceFile(filename, file, sp, FResourceFile::NO_FOLDERS | FResourceFile::NO_EXTENSIONS | FResourceFile::SHORTNAMES);
if (OpenWAD(rf, filter, Printf)) return rf;
auto rf = new FWadFile(filename, file, sp);
if (rf->Open(filter, Printf)) return rf;
file = rf->Destroy();
}