From ef300a9ea8fcd049886b65dfd7d599cd7babe9b8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 13:16:15 +0200 Subject: [PATCH] - lump flags cleanup. --- src/gamedata/resourcefiles/file_7z.cpp | 2 +- src/gamedata/resourcefiles/file_pak.cpp | 1 + src/gamedata/resourcefiles/file_rff.cpp | 6 +++--- src/gamedata/resourcefiles/file_wad.cpp | 2 +- src/gamedata/resourcefiles/file_zip.cpp | 2 +- src/gamedata/resourcefiles/resourcefile.h | 9 +++++++++ src/gamedata/textures/texturemanager.cpp | 2 +- src/gamedata/w_wad.cpp | 24 +++-------------------- src/gamedata/w_wad.h | 12 ------------ src/p_openmap.cpp | 11 ----------- src/p_setup.h | 1 - 11 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/gamedata/resourcefiles/file_7z.cpp b/src/gamedata/resourcefiles/file_7z.cpp index 27b596341..a7d1aec9c 100644 --- a/src/gamedata/resourcefiles/file_7z.cpp +++ b/src/gamedata/resourcefiles/file_7z.cpp @@ -292,7 +292,7 @@ bool F7ZFile::Open(bool quiet) lump_p->LumpNameSetup(name); lump_p->LumpSize = static_cast(SzArEx_GetFileSize(archPtr, i)); lump_p->Owner = this; - lump_p->Flags = LUMPF_ZIPFILE|LUMPF_COMPRESSED; + lump_p->Flags = LUMPF_FULLPATH|LUMPF_COMPRESSED; lump_p->Position = i; lump_p->CheckEmbedded(); lump_p++; diff --git a/src/gamedata/resourcefiles/file_pak.cpp b/src/gamedata/resourcefiles/file_pak.cpp index 2b4d39658..e61ab2f6b 100644 --- a/src/gamedata/resourcefiles/file_pak.cpp +++ b/src/gamedata/resourcefiles/file_pak.cpp @@ -108,6 +108,7 @@ bool FPakFile::Open(bool quiet) for(uint32_t i = 0; i < NumLumps; i++) { Lumps[i].LumpNameSetup(fileinfo[i].name); + Lumps[i].Flags = LUMPF_FULLPATH; Lumps[i].Owner = this; Lumps[i].Position = LittleLong(fileinfo[i].filepos); Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen); diff --git a/src/gamedata/resourcefiles/file_rff.cpp b/src/gamedata/resourcefiles/file_rff.cpp index 35402c3ad..e7c538733 100644 --- a/src/gamedata/resourcefiles/file_rff.cpp +++ b/src/gamedata/resourcefiles/file_rff.cpp @@ -159,7 +159,7 @@ bool FRFFFile::Open(bool quiet) Lumps[i].Owner = this; if (lumps[i].Flags & 0x10) { - Lumps[i].Flags |= LUMPF_BLOODCRYPT; + Lumps[i].Flags |= LUMPF_COMPRESSED; // flags the lump as not directly usable } Lumps[i].IndexNum = LittleLong(lumps[i].IndexNum); // Rearrange the name and extension to construct the fullname. @@ -207,7 +207,7 @@ FileReader *FRFFLump::GetReader() { // Don't return the reader if this lump is encrypted // In that case always force caching of the lump - if (!(Flags & LUMPF_BLOODCRYPT)) + if (!(Flags & LUMPF_COMPRESSED)) { return FUncompressedLump::GetReader(); } @@ -227,7 +227,7 @@ int FRFFLump::FillCache() { int res = FUncompressedLump::FillCache(); - if (Flags & LUMPF_BLOODCRYPT) + if (Flags & LUMPF_COMPRESSED) { int cryptlen = MIN (LumpSize, 256); uint8_t *data = (uint8_t *)Cache; diff --git a/src/gamedata/resourcefiles/file_wad.cpp b/src/gamedata/resourcefiles/file_wad.cpp index df60434d0..eb496cc04 100644 --- a/src/gamedata/resourcefiles/file_wad.cpp +++ b/src/gamedata/resourcefiles/file_wad.cpp @@ -187,7 +187,7 @@ bool FWadFile::Open(bool quiet) Lumps[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos); Lumps[i].LumpSize = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size); Lumps[i].Namespace = ns_global; - Lumps[i].Flags = Lumps[i].Compressed? LUMPF_COMPRESSED : 0; + Lumps[i].Flags = Lumps[i].Compressed ? LUMPF_COMPRESSED | LUMPF_SHORTNAME : LUMPF_SHORTNAME; Lumps[i].FullName = ""; // Check if the lump is within the WAD file and print a warning if not. diff --git a/src/gamedata/resourcefiles/file_zip.cpp b/src/gamedata/resourcefiles/file_zip.cpp index a96076335..6fd8b8bcb 100644 --- a/src/gamedata/resourcefiles/file_zip.cpp +++ b/src/gamedata/resourcefiles/file_zip.cpp @@ -340,7 +340,7 @@ bool FZipFile::Open(bool quiet) lump_p->LumpSize = LittleLong(zip_fh->UncompressedSize); lump_p->Owner = this; // The start of the Reader will be determined the first time it is accessed. - lump_p->Flags = LUMPF_ZIPFILE; + lump_p->Flags = LUMPF_FULLPATH; lump_p->NeedFileStart = true; lump_p->Method = uint8_t(zip_fh->Method); if (lump_p->Method != METHOD_STORED) lump_p->Flags |= LUMPF_COMPRESSED; diff --git a/src/gamedata/resourcefiles/resourcefile.h b/src/gamedata/resourcefiles/resourcefile.h index 643a81ede..2c6c1ec36 100644 --- a/src/gamedata/resourcefiles/resourcefile.h +++ b/src/gamedata/resourcefiles/resourcefile.h @@ -8,6 +8,15 @@ class FResourceFile; class FTexture; +enum ELumpFlags +{ + LUMPF_MAYBEFLAT = 1, // might be a flat outside F_START/END + LUMPF_FULLPATH = 2, // contains a full path. This will trigger extended namespace checks when looking up short names. + LUMPF_EMBEDDED = 4, // marks an embedded resource file for later processing. + LUMPF_SHORTNAME = 8, // the stored name is a short extension-less name + LUMPF_COMPRESSED = 16, // compressed or encrypted, i.e. cannot be read with the container file's reader. +}; + // This holds a compresed Zip entry with all needed info to decompress it. struct FCompressedBuffer { diff --git a/src/gamedata/textures/texturemanager.cpp b/src/gamedata/textures/texturemanager.cpp index ee5badce8..c5ef2c39f 100644 --- a/src/gamedata/textures/texturemanager.cpp +++ b/src/gamedata/textures/texturemanager.cpp @@ -963,7 +963,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b if (ns == ns_global) { // In Zips all graphics must be in a separate namespace. - if (Wads.GetLumpFlags(i) & LUMPF_ZIPFILE) continue; + if (Wads.GetLumpFlags(i) & LUMPF_FULLPATH) continue; // Ignore lumps with empty names. if (Wads.CheckLumpName(i, "")) continue; diff --git a/src/gamedata/w_wad.cpp b/src/gamedata/w_wad.cpp index dfd14858a..da6af300b 100644 --- a/src/gamedata/w_wad.cpp +++ b/src/gamedata/w_wad.cpp @@ -467,7 +467,7 @@ int FWadCollection::CheckNumForName (const char *name, int space) // from a Zip return that. WADs don't know these namespaces and single lumps must // work as well. if (space > ns_specialzipdirectory && lump->Namespace == ns_global && - !(lump->Flags & LUMPF_ZIPFILE)) break; + !(lump->Flags & LUMPF_FULLPATH)) break; } i = NextLumpIndex[i]; } @@ -1539,7 +1539,7 @@ FileReader FWadCollection::OpenLumpReader(int lump) auto rl = LumpInfo[lump].lump; auto rd = rl->GetReader(); - if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !(rl->Flags & (LUMPF_BLOODCRYPT | LUMPF_COMPRESSED))) + if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !(rl->Flags & LUMPF_COMPRESSED)) { FileReader rdr; rdr.OpenFilePart(*rd, rl->GetFileOffset(), rl->LumpSize); @@ -1558,7 +1558,7 @@ FileReader FWadCollection::ReopenLumpReader(int lump, bool alwayscache) auto rl = LumpInfo[lump].lump; auto rd = rl->GetReader(); - if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !alwayscache && !(rl->Flags & (LUMPF_BLOODCRYPT|LUMPF_COMPRESSED))) + if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !alwayscache && !(rl->Flags & LUMPF_COMPRESSED)) { int fileno = Wads.GetLumpFile(lump); const char *filename = Wads.GetWadFullName(fileno); @@ -1677,24 +1677,6 @@ const char *FWadCollection::GetWadFullName (int wadnum) const } -//========================================================================== -// -// IsEncryptedFile -// -// Returns true if the first 256 bytes of the lump are encrypted for Blood. -// -//========================================================================== - -bool FWadCollection::IsEncryptedFile(int lump) const -{ - if ((unsigned)lump >= (unsigned)NumLumps) - { - return false; - } - return !!(LumpInfo[lump].lump->Flags & LUMPF_BLOODCRYPT); -} - - // FMemLump ----------------------------------------------------------------- FMemLump::FMemLump () diff --git a/src/gamedata/w_wad.h b/src/gamedata/w_wad.h index 368f74a6d..55d91d548 100644 --- a/src/gamedata/w_wad.h +++ b/src/gamedata/w_wad.h @@ -67,16 +67,6 @@ typedef enum { ns_firstskin, } namespace_t; -enum ELumpFlags -{ - LUMPF_MAYBEFLAT=1, // might be a flat outside F_START/END - LUMPF_ZIPFILE=2, // contains a full path - LUMPF_EMBEDDED=4, // from an embedded WAD - LUMPF_BLOODCRYPT = 8, // encrypted - LUMPF_COMPRESSED = 16, // compressed - LUMPF_SEQUENTIAL = 32, // compressed but a sequential reader can be retrieved. -}; - // [RH] Copy an 8-char string and uppercase it. void uppercopy (char *to, const char *from); @@ -187,8 +177,6 @@ public: bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match unsigned GetLumpsInFolder(const char *path, TArray &result, bool atomic) const; - bool IsEncryptedFile(int lump) const; - int GetNumLumps() const { return NumLumps; diff --git a/src/p_openmap.cpp b/src/p_openmap.cpp index 7ab4ec104..a21b0ac73 100644 --- a/src/p_openmap.cpp +++ b/src/p_openmap.cpp @@ -164,19 +164,8 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // As such any special handling for other types of lumps is skipped. map->MapLumps[0].Reader = Wads.ReopenLumpReader(lump_name); strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(lump_name), 8); - map->Encrypted = Wads.IsEncryptedFile(lump_name); map->InWad = true; - if (map->Encrypted) - { // If it's encrypted, then it's a Blood file, presumably a map. - if (!P_IsBuildMap(map)) - { - delete map; - return NULL; - } - return map; - } - int index = 0; if (stricmp(Wads.GetLumpFullName(lump_name + 1), "TEXTMAP") != 0) diff --git a/src/p_setup.h b/src/p_setup.h index 0af26d101..55c7dfdcd 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -65,7 +65,6 @@ private: FileReader nofile; public: bool HasBehavior = false; - bool Encrypted = false; bool isText = false; bool InWad = false; int lumpnum = -1;