mirror of
https://github.com/ZDoom/Raze.git
synced 2025-04-01 21:50:37 +00:00
- yet another backend update.
This commit is contained in:
parent
d34bad3045
commit
b95a5a4b2b
54 changed files with 837 additions and 446 deletions
|
@ -182,7 +182,7 @@ static void SetupGenMidi()
|
|||
auto genmidi = fileSystem.ReadFile(lump);
|
||||
|
||||
if (genmidi.GetSize() < 8 + 175 * 36 || memcmp(genmidi.GetMem(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi((uint8_t*)genmidi.GetString()+8);
|
||||
ZMusic_SetGenMidi(genmidi.GetBytes()+8);
|
||||
}
|
||||
|
||||
static void SetupWgOpn()
|
||||
|
|
|
@ -1003,7 +1003,7 @@ void FExecList::ExecCommands() const
|
|||
}
|
||||
}
|
||||
|
||||
void FExecList::AddPullins(TArray<FString> &wads, FConfigFile *config) const
|
||||
void FExecList::AddPullins(std::vector<std::string>& wads, FConfigFile *config) const
|
||||
{
|
||||
for (unsigned i = 0; i < Pullins.Size(); ++i)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#ifndef __C_DISPATCH_H__
|
||||
#define __C_DISPATCH_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
#include "c_console.h"
|
||||
|
@ -52,7 +54,7 @@ struct FExecList
|
|||
|
||||
void AddCommand(const char *cmd, const char *file = nullptr);
|
||||
void ExecCommands() const;
|
||||
void AddPullins(TArray<FString> &wads, FConfigFile *config) const;
|
||||
void AddPullins(std::vector<std::string> &wads, FConfigFile *config) const;
|
||||
};
|
||||
|
||||
extern bool ParsingKeyConf, UnsafeExecutionContext;
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "md5.h"
|
||||
#include "i_specialpaths.h"
|
||||
#include "i_system.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
extern FILE* Logfile;
|
||||
|
||||
|
|
|
@ -200,10 +200,13 @@ void FScanner :: OpenLumpNum (int lump)
|
|||
{
|
||||
Close ();
|
||||
{
|
||||
FileData mem = fileSystem.ReadFile(lump);
|
||||
ScriptBuffer = mem.GetString();
|
||||
auto mem = fileSystem.OpenFileReader(lump);
|
||||
auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength());
|
||||
mem.Read(buff, mem.GetLength());
|
||||
buff[mem.GetLength()] = 0;
|
||||
ScriptBuffer.UnlockBuffer();
|
||||
}
|
||||
ScriptName = fileSystem.GetFileFullPath(lump);
|
||||
ScriptName = fileSystem.GetFileFullPath(lump).c_str();
|
||||
LumpNum = lump;
|
||||
PrepareScript ();
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf)
|
|||
for(uint32_t i = 0; i < NumLumps; i++)
|
||||
{
|
||||
char n[9];
|
||||
uppercopy(n, fileinfo[i].Name);
|
||||
for(int j = 0; j < 8; j++) n[j] = toupper(fileinfo[i].Name[j]);
|
||||
n[8] = 0;
|
||||
// This needs to be done differently. We cannot simply assume that all lumps where the first character's high bit is set are compressed without verification.
|
||||
// This requires explicit toggling for precisely the files that need it.
|
||||
|
|
|
@ -36,27 +36,55 @@
|
|||
|
||||
// HEADER FILES ------------------------------------------------------------
|
||||
|
||||
#include <zlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "m_argv.h"
|
||||
#include "cmdlib.h"
|
||||
#include "filesystem.h"
|
||||
#include "m_crc32.h"
|
||||
#include "printf.h"
|
||||
#include "md5.h"
|
||||
#include "fs_findfile.h"
|
||||
#include "md5.hpp"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
#define NULL_INDEX (0xffffffff)
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static int MakeHash(const void* data, unsigned length = -1)
|
||||
{
|
||||
if (length == -1) length = (unsigned)strlen((const char*)data);
|
||||
return crc32(0, (const Bytef*)data, length);
|
||||
}
|
||||
|
||||
static void md5Hash(FileReader& reader, uint8_t* digest)
|
||||
{
|
||||
using namespace fs_private::md5;
|
||||
|
||||
md5_state_t state;
|
||||
md5_init(&state);
|
||||
md5_byte_t buffer[4096];
|
||||
while (auto len = reader.Read(buffer, 4096))
|
||||
{
|
||||
md5_append(&state, buffer, len);
|
||||
}
|
||||
md5_finish(&state, digest);
|
||||
}
|
||||
|
||||
|
||||
struct FileSystem::LumpRecord
|
||||
{
|
||||
FResourceLump *lump;
|
||||
LumpShortName shortName;
|
||||
FString longName;
|
||||
std::string longName;
|
||||
int rfnum;
|
||||
int Namespace;
|
||||
int resourceId;
|
||||
|
@ -70,7 +98,7 @@ struct FileSystem::LumpRecord
|
|||
|
||||
if (lump->Flags & LUMPF_SHORTNAME)
|
||||
{
|
||||
uppercopy(shortName.String, lump->getName());
|
||||
UpperCopy(shortName.String, lump->getName());
|
||||
shortName.String[8] = 0;
|
||||
longName = "";
|
||||
Namespace = lump->GetNamespace();
|
||||
|
@ -91,42 +119,41 @@ struct FileSystem::LumpRecord
|
|||
// Map some directories to WAD namespaces.
|
||||
// Note that some of these namespaces don't exist in WADS.
|
||||
// CheckNumForName will handle any request for these namespaces accordingly.
|
||||
Namespace = !strncmp(longName.GetChars(), "flats/", 6) ? ns_flats :
|
||||
!strncmp(longName.GetChars(), "textures/", 9) ? ns_newtextures :
|
||||
!strncmp(longName.GetChars(), "hires/", 6) ? ns_hires :
|
||||
!strncmp(longName.GetChars(), "sprites/", 8) ? ns_sprites :
|
||||
!strncmp(longName.GetChars(), "voxels/", 7) ? ns_voxels :
|
||||
!strncmp(longName.GetChars(), "colormaps/", 10) ? ns_colormaps :
|
||||
!strncmp(longName.GetChars(), "acs/", 4) ? ns_acslibrary :
|
||||
!strncmp(longName.GetChars(), "voices/", 7) ? ns_strifevoices :
|
||||
!strncmp(longName.GetChars(), "patches/", 8) ? ns_patches :
|
||||
!strncmp(longName.GetChars(), "graphics/", 9) ? ns_graphics :
|
||||
!strncmp(longName.GetChars(), "sounds/", 7) ? ns_sounds :
|
||||
!strncmp(longName.GetChars(), "music/", 6) ? ns_music :
|
||||
!strchr(longName.GetChars(), '/') ? ns_global :
|
||||
Namespace = !strncmp(longName.c_str(), "flats/", 6) ? ns_flats :
|
||||
!strncmp(longName.c_str(), "textures/", 9) ? ns_newtextures :
|
||||
!strncmp(longName.c_str(), "hires/", 6) ? ns_hires :
|
||||
!strncmp(longName.c_str(), "sprites/", 8) ? ns_sprites :
|
||||
!strncmp(longName.c_str(), "voxels/", 7) ? ns_voxels :
|
||||
!strncmp(longName.c_str(), "colormaps/", 10) ? ns_colormaps :
|
||||
!strncmp(longName.c_str(), "acs/", 4) ? ns_acslibrary :
|
||||
!strncmp(longName.c_str(), "voices/", 7) ? ns_strifevoices :
|
||||
!strncmp(longName.c_str(), "patches/", 8) ? ns_patches :
|
||||
!strncmp(longName.c_str(), "graphics/", 9) ? ns_graphics :
|
||||
!strncmp(longName.c_str(), "sounds/", 7) ? ns_sounds :
|
||||
!strncmp(longName.c_str(), "music/", 6) ? ns_music :
|
||||
!strchr(longName.c_str(), '/') ? ns_global :
|
||||
ns_hidden;
|
||||
|
||||
if (Namespace == ns_hidden) shortName.qword = 0;
|
||||
else
|
||||
{
|
||||
ptrdiff_t encodedResID = longName.LastIndexOf(".{");
|
||||
if (resourceId == -1 && encodedResID >= 0)
|
||||
ptrdiff_t encodedResID = longName.find_last_of(".{");
|
||||
if (resourceId == -1 && encodedResID != std::string::npos)
|
||||
{
|
||||
const char* p = longName.GetChars() + encodedResID;
|
||||
const char* p = longName.c_str() + encodedResID;
|
||||
char* q;
|
||||
int id = (int)strtoull(p+2, &q, 10); // only decimal numbers allowed here.
|
||||
if (q[0] == '}' && (q[1] == '.' || q[1] == 0))
|
||||
{
|
||||
FString toDelete(p, q - p + 1);
|
||||
longName.Substitute(toDelete, "");
|
||||
longName.erase(longName.begin() + encodedResID, longName.begin() + (q - p) + 1);
|
||||
resourceId = id;
|
||||
}
|
||||
}
|
||||
ptrdiff_t slash = longName.LastIndexOf('/');
|
||||
FString base = (slash >= 0) ? longName.Mid(slash + 1) : longName;
|
||||
auto dot = base.LastIndexOf('.');
|
||||
if (dot >= 0) base.Truncate(dot);
|
||||
uppercopy(shortName.String, base);
|
||||
ptrdiff_t slash = longName.find_last_of('/');
|
||||
std::string base = (slash != std::string::npos) ? longName.c_str() + (slash + 1) : longName.c_str();
|
||||
auto dot = base.find_last_of('.');
|
||||
if (dot != std::string::npos) base.resize(dot);
|
||||
UpperCopy(shortName.String, base.c_str());
|
||||
shortName.String[8] = 0;
|
||||
|
||||
// Since '\' can't be used as a file name's part inside a ZIP
|
||||
|
@ -170,7 +197,7 @@ FileSystem::~FileSystem ()
|
|||
|
||||
void FileSystem::DeleteAll ()
|
||||
{
|
||||
Hashes.Clear();
|
||||
Hashes.clear();
|
||||
NumEntries = 0;
|
||||
|
||||
// explicitly delete all manually added lumps.
|
||||
|
@ -178,12 +205,12 @@ void FileSystem::DeleteAll ()
|
|||
{
|
||||
if (frec.rfnum == -1) delete frec.lump;
|
||||
}
|
||||
FileInfo.Clear();
|
||||
for (int i = Files.Size() - 1; i >= 0; --i)
|
||||
FileInfo.clear();
|
||||
for (int i = (int)Files.size() - 1; i >= 0; --i)
|
||||
{
|
||||
delete Files[i];
|
||||
}
|
||||
Files.Clear();
|
||||
Files.clear();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -199,12 +226,11 @@ void FileSystem::DeleteAll ()
|
|||
|
||||
bool FileSystem::InitSingleFile(const char* filename, FileSystemMessageFunc Printf)
|
||||
{
|
||||
TArray<FString> filenames;
|
||||
filenames.Push(filename);
|
||||
std::vector<std::string> filenames = { filename };
|
||||
return InitMultipleFiles(filenames, nullptr, Printf);
|
||||
}
|
||||
|
||||
bool FileSystem::InitMultipleFiles (TArray<FString> &filenames, LumpFilterInfo* filter, FileSystemMessageFunc Printf, bool allowduplicates, FILE* hashfile)
|
||||
bool FileSystem::InitMultipleFiles (std::vector<std::string>& filenames, LumpFilterInfo* filter, FileSystemMessageFunc Printf, bool allowduplicates, FILE* hashfile)
|
||||
{
|
||||
int numfiles;
|
||||
|
||||
|
@ -215,29 +241,30 @@ bool FileSystem::InitMultipleFiles (TArray<FString> &filenames, LumpFilterInfo*
|
|||
// first, check for duplicates
|
||||
if (allowduplicates)
|
||||
{
|
||||
for (unsigned i=0;i<filenames.Size(); i++)
|
||||
for (size_t i=0;i<filenames.size(); i++)
|
||||
{
|
||||
for (unsigned j=i+1;j<filenames.Size(); j++)
|
||||
for (size_t j=i+1;j<filenames.size(); j++)
|
||||
{
|
||||
if (strcmp(filenames[i], filenames[j]) == 0)
|
||||
if (filenames[i] == filenames[j])
|
||||
{
|
||||
filenames.Delete(j);
|
||||
filenames.erase(filenames.begin() + j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned i=0;i<filenames.Size(); i++)
|
||||
for(size_t i=0;i<filenames.size(); i++)
|
||||
{
|
||||
AddFile (filenames[i], nullptr, filter, Printf, hashfile);
|
||||
AddFile(filenames[i].c_str(), nullptr, filter, Printf, hashfile);
|
||||
|
||||
if (i == (unsigned)MaxIwadIndex) MoveLumpsInFolder("after_iwad/");
|
||||
FStringf path("filter/%s", Files.Last()->GetHash());
|
||||
MoveLumpsInFolder(path);
|
||||
std::string path = "filter/%s";
|
||||
path += Files.back()->GetHash();
|
||||
MoveLumpsInFolder(path.c_str());
|
||||
}
|
||||
|
||||
NumEntries = FileInfo.Size();
|
||||
NumEntries = (uint32_t)FileInfo.size();
|
||||
if (NumEntries == 0)
|
||||
{
|
||||
return false;
|
||||
|
@ -259,8 +286,8 @@ bool FileSystem::InitMultipleFiles (TArray<FString> &filenames, LumpFilterInfo*
|
|||
|
||||
void FileSystem::AddLump(FResourceLump *lump)
|
||||
{
|
||||
FileSystem::LumpRecord *lumprec = &FileInfo[FileInfo.Reserve(1)];
|
||||
lumprec->SetFromLump(-1, lump);
|
||||
FileInfo.resize(FileInfo.size() + 1);
|
||||
FileInfo.back().SetFromLump(-1, lump);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -275,7 +302,7 @@ int FileSystem::AddExternalFile(const char *filename)
|
|||
{
|
||||
FResourceLump *lump = new FExternalLump(filename);
|
||||
AddLump(lump);
|
||||
return FileInfo.Size() - 1; // later
|
||||
return (int)FileInfo.size() - 1; // later
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -288,12 +315,14 @@ int FileSystem::AddExternalFile(const char *filename)
|
|||
|
||||
int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags)
|
||||
{
|
||||
FStringf fullname("%s.%s", name, type);
|
||||
std::string fullname = name;
|
||||
fullname += ':';
|
||||
fullname += type;
|
||||
auto newlump = new FMemoryLump(data, size);
|
||||
newlump->LumpNameSetup(fullname);
|
||||
newlump->LumpNameSetup(fullname.c_str());
|
||||
AddLump(newlump);
|
||||
FileInfo.Last().resourceId = id;
|
||||
return FileInfo.Size()-1;
|
||||
FileInfo.back().resourceId = id;
|
||||
return (int)FileInfo.size()-1;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -315,7 +344,7 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
|
|||
if (filer == nullptr)
|
||||
{
|
||||
// Does this exist? If so, is it a directory?
|
||||
if (!DirEntryExists(filename, &isdir))
|
||||
if (!FS_DirEntryExists(filename, &isdir))
|
||||
{
|
||||
if (Printf)
|
||||
{
|
||||
|
@ -352,30 +381,32 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
|
|||
|
||||
if (resfile != NULL)
|
||||
{
|
||||
if (!batchrun && Printf)
|
||||
if (Printf)
|
||||
Printf(FSMessageLevel::Message, "adding %s, %d lumps\n", filename, resfile->LumpCount());
|
||||
|
||||
uint32_t lumpstart = FileInfo.Size();
|
||||
uint32_t lumpstart = (uint32_t)FileInfo.size();
|
||||
|
||||
resfile->SetFirstLump(lumpstart);
|
||||
for (uint32_t i=0; i < resfile->LumpCount(); i++)
|
||||
{
|
||||
FResourceLump *lump = resfile->GetLump(i);
|
||||
FileSystem::LumpRecord *lump_p = &FileInfo[FileInfo.Reserve(1)];
|
||||
lump_p->SetFromLump(Files.Size(), lump);
|
||||
FileInfo.resize(FileInfo.size() + 1);
|
||||
FileSystem::LumpRecord *lump_p = &FileInfo.back();
|
||||
lump_p->SetFromLump((int)Files.size(), lump);
|
||||
}
|
||||
|
||||
Files.Push(resfile);
|
||||
Files.push_back(resfile);
|
||||
|
||||
for (uint32_t i=0; i < resfile->LumpCount(); i++)
|
||||
{
|
||||
FResourceLump *lump = resfile->GetLump(i);
|
||||
if (lump->Flags & LUMPF_EMBEDDED)
|
||||
{
|
||||
FString path;
|
||||
path.Format("%s:%s", filename, lump->getName());
|
||||
std::string path = filename;
|
||||
path += ':';
|
||||
path += lump->getName();
|
||||
auto embedded = lump->NewReader();
|
||||
AddFile(path, &embedded, filter, Printf, hashfile);
|
||||
AddFile(path.c_str(), &embedded, filter, Printf, hashfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,10 +418,8 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
|
|||
|
||||
if (filereader.isOpen())
|
||||
{
|
||||
MD5Context md5;
|
||||
filereader.Seek(0, FileReader::SeekSet);
|
||||
md5Update(filereader, md5, (unsigned)filereader.GetLength());
|
||||
md5.Final(cksum);
|
||||
md5Hash(filereader, cksum);
|
||||
|
||||
for (size_t j = 0; j < sizeof(cksum); ++j)
|
||||
{
|
||||
|
@ -409,10 +438,8 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
|
|||
|
||||
if (!(lump->Flags & LUMPF_EMBEDDED))
|
||||
{
|
||||
MD5Context md5;
|
||||
auto reader = lump->NewReader();
|
||||
md5Update(reader, md5, lump->LumpSize);
|
||||
md5.Final(cksum);
|
||||
md5Hash(filereader, cksum);
|
||||
|
||||
for (size_t j = 0; j < sizeof(cksum); ++j)
|
||||
{
|
||||
|
@ -444,7 +471,7 @@ int FileSystem::CheckIfResourceFileLoaded (const char *name) noexcept
|
|||
|
||||
if (strrchr (name, '/') != NULL)
|
||||
{
|
||||
for (i = 0; i < Files.Size(); ++i)
|
||||
for (i = 0; i < (unsigned)Files.size(); ++i)
|
||||
{
|
||||
if (stricmp (GetResourceFileFullName (i), name) == 0)
|
||||
{
|
||||
|
@ -454,10 +481,10 @@ int FileSystem::CheckIfResourceFileLoaded (const char *name) noexcept
|
|||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < Files.Size(); ++i)
|
||||
for (i = 0; i < (unsigned)Files.size(); ++i)
|
||||
{
|
||||
auto pth = ExtractFileBase(GetResourceFileName(i), true);
|
||||
if (stricmp (pth.GetChars(), name) == 0)
|
||||
auto pth = ExtractBaseName(GetResourceFileName(i), true);
|
||||
if (stricmp (pth.c_str(), name) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
@ -498,8 +525,8 @@ int FileSystem::CheckNumForName (const char *name, int space)
|
|||
return -1;
|
||||
}
|
||||
|
||||
uppercopy (uname, name);
|
||||
i = FirstLumpIndex[LumpNameHash (uname) % NumEntries];
|
||||
UpperCopy (uname, name);
|
||||
i = FirstLumpIndex[MakeHash(uname, 8) % NumEntries];
|
||||
|
||||
while (i != NULL_INDEX)
|
||||
{
|
||||
|
@ -536,8 +563,8 @@ int FileSystem::CheckNumForName (const char *name, int space, int rfnum, bool ex
|
|||
return CheckNumForName (name, space);
|
||||
}
|
||||
|
||||
uppercopy (uname, name);
|
||||
i = FirstLumpIndex[LumpNameHash (uname) % NumEntries];
|
||||
UpperCopy (uname, name);
|
||||
i = FirstLumpIndex[MakeHash (uname, 8) % NumEntries];
|
||||
|
||||
// If exact is true if will only find lumps in the same WAD, otherwise
|
||||
// also those in earlier WADs.
|
||||
|
@ -596,14 +623,14 @@ int FileSystem::CheckNumForFullName (const char *name, bool trynormal, int names
|
|||
uint32_t *nli = ignoreext ? NextLumpIndex_NoExt : NextLumpIndex_FullName;
|
||||
auto len = strlen(name);
|
||||
|
||||
for (i = fli[MakeKey(name) % NumEntries]; i != NULL_INDEX; i = nli[i])
|
||||
for (i = fli[MakeHash(name) % NumEntries]; i != NULL_INDEX; i = nli[i])
|
||||
{
|
||||
if (strnicmp(name, FileInfo[i].longName, len)) continue;
|
||||
if (strnicmp(name, FileInfo[i].longName.c_str(), len)) continue;
|
||||
if (FileInfo[i].longName[len] == 0) break; // this is a full match
|
||||
if (ignoreext && FileInfo[i].longName[len] == '.')
|
||||
{
|
||||
// is this the last '.' in the last path element, indicating that the remaining part of the name is only an extension?
|
||||
if (strpbrk(FileInfo[i].longName.GetChars() + len + 1, "./") == nullptr) break;
|
||||
if (strpbrk(FileInfo[i].longName.c_str() + len + 1, "./") == nullptr) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,10 +652,10 @@ int FileSystem::CheckNumForFullName (const char *name, int rfnum)
|
|||
return CheckNumForFullName (name);
|
||||
}
|
||||
|
||||
i = FirstLumpIndex_FullName[MakeKey (name) % NumEntries];
|
||||
i = FirstLumpIndex_FullName[MakeHash (name) % NumEntries];
|
||||
|
||||
while (i != NULL_INDEX &&
|
||||
(stricmp(name, FileInfo[i].longName) || FileInfo[i].rfnum != rfnum))
|
||||
(stricmp(name, FileInfo[i].longName.c_str()) || FileInfo[i].rfnum != rfnum))
|
||||
{
|
||||
i = NextLumpIndex_FullName[i];
|
||||
}
|
||||
|
@ -677,12 +704,12 @@ int FileSystem::FindFileWithExtensions(const char* name, const char *const *exts
|
|||
uint32_t* nli = NextLumpIndex_NoExt;
|
||||
auto len = strlen(name);
|
||||
|
||||
for (i = fli[MakeKey(name) % NumEntries]; i != NULL_INDEX; i = nli[i])
|
||||
for (i = fli[MakeHash(name) % NumEntries]; i != NULL_INDEX; i = nli[i])
|
||||
{
|
||||
if (strnicmp(name, FileInfo[i].longName, len)) continue;
|
||||
if (strnicmp(name, FileInfo[i].longName.c_str(), len)) continue;
|
||||
if (FileInfo[i].longName[len] != '.') continue; // we are looking for extensions but this file doesn't have one.
|
||||
|
||||
auto cp = FileInfo[i].longName.GetChars() + len + 1;
|
||||
auto cp = FileInfo[i].longName.c_str() + len + 1;
|
||||
// is this the last '.' in the last path element, indicating that the remaining part of the name is only an extension?
|
||||
if (strpbrk(cp, "./") != nullptr) continue; // No, so it cannot be a valid entry.
|
||||
|
||||
|
@ -718,7 +745,7 @@ int FileSystem::FindResource (int resid, const char *type, int filenum) const no
|
|||
{
|
||||
if (filenum > 0 && FileInfo[i].rfnum != filenum) continue;
|
||||
if (FileInfo[i].resourceId != resid) continue;
|
||||
auto extp = strrchr(FileInfo[i].longName, '.');
|
||||
auto extp = strrchr(FileInfo[i].longName.c_str(), '.');
|
||||
if (!extp) continue;
|
||||
if (!stricmp(extp + 1, type)) return i;
|
||||
}
|
||||
|
@ -797,31 +824,6 @@ int FileSystem::GetFileFlags (int lump)
|
|||
return FileInfo[lump].lump->Flags ^ FileInfo[lump].flags;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// LumpNameHash
|
||||
//
|
||||
// NOTE: s should already be uppercase, in contrast to the BOOM version.
|
||||
//
|
||||
// Hash function used for lump names.
|
||||
// Must be mod'ed with table size.
|
||||
// Can be used for any 8-character names.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
uint32_t FileSystem::LumpNameHash (const char *s)
|
||||
{
|
||||
const uint32_t *table = GetCRCTable ();
|
||||
uint32_t hash = 0xffffffff;
|
||||
int i;
|
||||
|
||||
for (i = 8; i > 0 && *s; --i, ++s)
|
||||
{
|
||||
hash = CRC1 (hash, *s, table);
|
||||
}
|
||||
return hash ^ 0xffffffff;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// InitHashChains
|
||||
|
@ -835,10 +837,10 @@ void FileSystem::InitHashChains (void)
|
|||
{
|
||||
unsigned int i, j;
|
||||
|
||||
NumEntries = FileInfo.Size();
|
||||
Hashes.Resize(8 * NumEntries);
|
||||
NumEntries = (uint32_t)FileInfo.size();
|
||||
Hashes.resize(8 * NumEntries);
|
||||
// Mark all buckets as empty
|
||||
memset(Hashes.Data(), -1, Hashes.Size() * sizeof(Hashes[0]));
|
||||
memset(Hashes.data(), -1, Hashes.size() * sizeof(Hashes[0]));
|
||||
FirstLumpIndex = &Hashes[0];
|
||||
NextLumpIndex = &Hashes[NumEntries];
|
||||
FirstLumpIndex_FullName = &Hashes[NumEntries * 2];
|
||||
|
@ -852,23 +854,23 @@ void FileSystem::InitHashChains (void)
|
|||
// Now set up the chains
|
||||
for (i = 0; i < (unsigned)NumEntries; i++)
|
||||
{
|
||||
j = LumpNameHash (FileInfo[i].shortName.String) % NumEntries;
|
||||
j = MakeHash (FileInfo[i].shortName.String, 8) % NumEntries;
|
||||
NextLumpIndex[i] = FirstLumpIndex[j];
|
||||
FirstLumpIndex[j] = i;
|
||||
|
||||
// Do the same for the full paths
|
||||
if (FileInfo[i].longName.IsNotEmpty())
|
||||
if (!FileInfo[i].longName.empty())
|
||||
{
|
||||
j = MakeKey(FileInfo[i].longName) % NumEntries;
|
||||
j = MakeHash(FileInfo[i].longName.c_str()) % NumEntries;
|
||||
NextLumpIndex_FullName[i] = FirstLumpIndex_FullName[j];
|
||||
FirstLumpIndex_FullName[j] = i;
|
||||
|
||||
FString nameNoExt = FileInfo[i].longName;
|
||||
auto dot = nameNoExt.LastIndexOf('.');
|
||||
auto slash = nameNoExt.LastIndexOf('/');
|
||||
if (dot > slash) nameNoExt.Truncate(dot);
|
||||
auto nameNoExt = FileInfo[i].longName;
|
||||
auto dot = nameNoExt.find_last_of('.');
|
||||
auto slash = nameNoExt.find_last_of('/');
|
||||
if ((dot > slash || slash == std::string::npos) && dot != std::string::npos) nameNoExt.resize(dot);
|
||||
|
||||
j = MakeKey(nameNoExt) % NumEntries;
|
||||
j = MakeHash(nameNoExt.c_str()) % NumEntries;
|
||||
NextLumpIndex_NoExt[i] = FirstLumpIndex_NoExt[j];
|
||||
FirstLumpIndex_NoExt[j] = i;
|
||||
|
||||
|
@ -878,8 +880,8 @@ void FileSystem::InitHashChains (void)
|
|||
|
||||
}
|
||||
}
|
||||
FileInfo.ShrinkToFit();
|
||||
Files.ShrinkToFit();
|
||||
FileInfo.shrink_to_fit();
|
||||
Files.shrink_to_fit();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -895,12 +897,6 @@ LumpShortName& FileSystem::GetShortName(int i)
|
|||
return FileInfo[i].shortName;
|
||||
}
|
||||
|
||||
FString& FileSystem::GetLongName(int i)
|
||||
{
|
||||
if ((unsigned)i >= NumEntries) throw FileSystemException("GetLongName: Invalid index");
|
||||
return FileInfo[i].longName;
|
||||
}
|
||||
|
||||
void FileSystem::RenameFile(int num, const char* newfn)
|
||||
{
|
||||
if ((unsigned)num >= NumEntries) throw FileSystemException("RenameFile: Invalid index");
|
||||
|
@ -925,25 +921,25 @@ static FResourceLump placeholderLump;
|
|||
|
||||
void FileSystem::MoveLumpsInFolder(const char *path)
|
||||
{
|
||||
if (FileInfo.Size() == 0)
|
||||
if (FileInfo.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto len = strlen(path);
|
||||
auto rfnum = FileInfo.Last().rfnum;
|
||||
auto rfnum = FileInfo.back().rfnum;
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < FileInfo.Size(); i++)
|
||||
size_t i;
|
||||
for (i = 0; i < FileInfo.size(); i++)
|
||||
{
|
||||
auto& li = FileInfo[i];
|
||||
if (li.rfnum >= GetIwadNum()) break;
|
||||
if (li.longName.Left(len).CompareNoCase(path) == 0)
|
||||
if (strnicmp(li.longName.c_str(), path, len) == 0)
|
||||
{
|
||||
FileInfo.Push(li);
|
||||
FileInfo.push_back(li);
|
||||
li.lump = &placeholderLump; // Make the old entry point to something empty. We cannot delete the lump record here because it'd require adjustment of all indices in the list.
|
||||
auto &ln = FileInfo.Last();
|
||||
ln.lump->LumpNameSetup(ln.longName.Mid(len));
|
||||
auto &ln = FileInfo.back();
|
||||
ln.lump->LumpNameSetup(ln.longName.c_str() + len);
|
||||
ln.SetFromLump(rfnum, ln.lump);
|
||||
}
|
||||
}
|
||||
|
@ -967,7 +963,7 @@ int FileSystem::FindLump (const char *name, int *lastlump, bool anyns)
|
|||
};
|
||||
LumpRecord *lump_p;
|
||||
|
||||
uppercopy (name8, name);
|
||||
UpperCopy (name8, name);
|
||||
|
||||
assert(lastlump != NULL && *lastlump >= 0);
|
||||
lump_p = &FileInfo[*lastlump];
|
||||
|
@ -1042,7 +1038,7 @@ int FileSystem::FindLumpFullName(const char* name, int* lastlump, bool noext)
|
|||
{
|
||||
while (lump_p < &FileInfo[NumEntries])
|
||||
{
|
||||
if (!stricmp(name, lump_p->longName))
|
||||
if (!stricmp(name, lump_p->longName.c_str()))
|
||||
{
|
||||
int lump = int(lump_p - &FileInfo[0]);
|
||||
*lastlump = lump + 1;
|
||||
|
@ -1056,10 +1052,10 @@ int FileSystem::FindLumpFullName(const char* name, int* lastlump, bool noext)
|
|||
auto len = strlen(name);
|
||||
while (lump_p < &FileInfo[NumEntries])
|
||||
{
|
||||
auto res = strnicmp(name, lump_p->longName, len);
|
||||
auto res = strnicmp(name, lump_p->longName.c_str(), len);
|
||||
if (res == 0)
|
||||
{
|
||||
auto p = lump_p->longName.GetChars() + len;
|
||||
auto p = lump_p->longName.c_str() + len;
|
||||
if (*p == 0 || (*p == '.' && strpbrk(p + 1, "./") == 0))
|
||||
{
|
||||
int lump = int(lump_p - &FileInfo[0]);
|
||||
|
@ -1096,14 +1092,6 @@ bool FileSystem::CheckFileName (int lump, const char *name)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FileSystem::GetFileShortName (char *to, int lump) const
|
||||
{
|
||||
if ((size_t)lump >= NumEntries)
|
||||
*to = 0;
|
||||
else
|
||||
uppercopy (to, FileInfo[lump].shortName.String);
|
||||
}
|
||||
|
||||
const char* FileSystem::GetFileShortName(int lump) const
|
||||
{
|
||||
if ((size_t)lump >= NumEntries)
|
||||
|
@ -1112,16 +1100,6 @@ const char* FileSystem::GetFileShortName(int lump) const
|
|||
return FileInfo[lump].shortName.String;
|
||||
}
|
||||
|
||||
void FileSystem::GetFileShortName(FString &to, int lump) const
|
||||
{
|
||||
if ((size_t)lump >= NumEntries)
|
||||
to = FString();
|
||||
else {
|
||||
to = FileInfo[lump].shortName.String;
|
||||
to.ToUpper();
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FileSystem :: GetFileFullName
|
||||
|
@ -1134,8 +1112,8 @@ const char *FileSystem::GetFileFullName (int lump, bool returnshort) const
|
|||
{
|
||||
if ((size_t)lump >= NumEntries)
|
||||
return NULL;
|
||||
else if (FileInfo[lump].longName.IsNotEmpty())
|
||||
return FileInfo[lump].longName;
|
||||
else if (!FileInfo[lump].longName.empty())
|
||||
return FileInfo[lump].longName.c_str();
|
||||
else if (returnshort)
|
||||
return FileInfo[lump].shortName.String;
|
||||
else return nullptr;
|
||||
|
@ -1149,13 +1127,15 @@ const char *FileSystem::GetFileFullName (int lump, bool returnshort) const
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FString FileSystem::GetFileFullPath(int lump) const
|
||||
std::string FileSystem::GetFileFullPath(int lump) const
|
||||
{
|
||||
FString foo;
|
||||
std::string foo;
|
||||
|
||||
if ((size_t) lump < NumEntries)
|
||||
{
|
||||
foo << GetResourceFileName(FileInfo[lump].rfnum) << ':' << GetFileFullName(lump);
|
||||
foo = GetResourceFileName(FileInfo[lump].rfnum);
|
||||
foo += ':';
|
||||
foo += +GetFileFullName(lump);
|
||||
}
|
||||
return foo;
|
||||
}
|
||||
|
@ -1211,7 +1191,7 @@ const char *FileSystem::GetResourceType(int lump) const
|
|||
return nullptr;
|
||||
else
|
||||
{
|
||||
auto p = strrchr(FileInfo[lump].longName.GetChars(), '.');
|
||||
auto p = strrchr(FileInfo[lump].longName.c_str(), '.');
|
||||
if (!p) return ""; // has no extension
|
||||
if (strchr(p, '/')) return ""; // the '.' is part of a directory.
|
||||
return p + 1;
|
||||
|
@ -1226,7 +1206,7 @@ const char *FileSystem::GetResourceType(int lump) const
|
|||
|
||||
int FileSystem::GetFileContainer (int lump) const
|
||||
{
|
||||
if ((size_t)lump >= FileInfo.Size())
|
||||
if ((size_t)lump >= FileInfo.size())
|
||||
return -1;
|
||||
return FileInfo[lump].rfnum;
|
||||
}
|
||||
|
@ -1254,25 +1234,26 @@ static int folderentrycmp(const void *a, const void *b)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &result, bool atomic) const
|
||||
unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector<FolderEntry> &result, bool atomic) const
|
||||
{
|
||||
FString path = inpath;
|
||||
FixPathSeperator(path);
|
||||
path.ToLower();
|
||||
if (path[path.Len() - 1] != '/') path += '/';
|
||||
result.Clear();
|
||||
for (unsigned i = 0; i < FileInfo.Size(); i++)
|
||||
std::string path = inpath;
|
||||
FixPathSeparator(&path.front());
|
||||
for (auto& c : path) c = tolower(c);
|
||||
if (path.back() != '/') path += '/';
|
||||
result.clear();
|
||||
for (size_t i = 0; i < FileInfo.size(); i++)
|
||||
{
|
||||
if (FileInfo[i].longName.IndexOf(path) == 0)
|
||||
if (FileInfo[i].longName.find_first_of(path) == 0)
|
||||
{
|
||||
// Only if it hasn't been replaced.
|
||||
if ((unsigned)fileSystem.CheckNumForFullName(FileInfo[i].longName) == i)
|
||||
if ((unsigned)fileSystem.CheckNumForFullName(FileInfo[i].longName.c_str()) == i)
|
||||
{
|
||||
result.Push({ FileInfo[i].longName.GetChars(), i });
|
||||
FolderEntry fe{ FileInfo[i].longName.c_str(), (uint32_t)i };
|
||||
result.push_back(fe);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.Size())
|
||||
if (result.size())
|
||||
{
|
||||
int maxfile = -1;
|
||||
if (atomic)
|
||||
|
@ -1284,14 +1265,14 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &r
|
|||
if (thisfile > maxfile) maxfile = thisfile;
|
||||
}
|
||||
// Delete everything from older files.
|
||||
for (int i = result.Size() - 1; i >= 0; i--)
|
||||
for (int i = (int)result.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.Delete(i);
|
||||
if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i);
|
||||
}
|
||||
}
|
||||
qsort(result.Data(), result.Size(), sizeof(FolderEntry), folderentrycmp);
|
||||
qsort(result.data(), result.size(), sizeof(FolderEntry), folderentrycmp);
|
||||
}
|
||||
return result.Size();
|
||||
return (unsigned)result.size();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1311,7 +1292,7 @@ void FileSystem::ReadFile (int lump, void *dest)
|
|||
if (numread != size)
|
||||
{
|
||||
throw FileSystemException("W_ReadFile: only read %ld of %ld on '%s'\n",
|
||||
numread, size, GetLongName(lump).GetChars());
|
||||
numread, size, FileInfo[lump].longName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1326,7 +1307,13 @@ void FileSystem::ReadFile (int lump, void *dest)
|
|||
|
||||
FileData FileSystem::ReadFile (int lump)
|
||||
{
|
||||
return FileData(FString(ELumpNum(lump)));
|
||||
if ((unsigned)lump >= (unsigned)FileInfo.size())
|
||||
{
|
||||
throw FileSystemException("ReadFile: %u >= NumEntries", lump);
|
||||
}
|
||||
auto lumpp = FileInfo[lump].lump;
|
||||
|
||||
return FileData(lumpp);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1340,7 +1327,7 @@ FileData FileSystem::ReadFile (int lump)
|
|||
|
||||
FileReader FileSystem::OpenFileReader(int lump)
|
||||
{
|
||||
if ((unsigned)lump >= (unsigned)FileInfo.Size())
|
||||
if ((unsigned)lump >= (unsigned)FileInfo.size())
|
||||
{
|
||||
throw FileSystemException("OpenFileReader: %u >= NumEntries", lump);
|
||||
}
|
||||
|
@ -1359,7 +1346,7 @@ FileReader FileSystem::OpenFileReader(int lump)
|
|||
|
||||
FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache)
|
||||
{
|
||||
if ((unsigned)lump >= (unsigned)FileInfo.Size())
|
||||
if ((unsigned)lump >= (unsigned)FileInfo.size())
|
||||
{
|
||||
throw FileSystemException("ReopenFileReader: %u >= NumEntries", lump);
|
||||
}
|
||||
|
@ -1398,7 +1385,7 @@ FileReader FileSystem::OpenFileReader(const char* name)
|
|||
|
||||
FileReader *FileSystem::GetFileReader(int rfnum)
|
||||
{
|
||||
if ((uint32_t)rfnum >= Files.Size())
|
||||
if ((uint32_t)rfnum >= Files.size())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1418,7 +1405,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept
|
|||
{
|
||||
const char *name, *slash;
|
||||
|
||||
if ((uint32_t)rfnum >= Files.Size())
|
||||
if ((uint32_t)rfnum >= Files.size())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1435,7 +1422,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept
|
|||
|
||||
int FileSystem::GetFirstEntry (int rfnum) const noexcept
|
||||
{
|
||||
if ((uint32_t)rfnum >= Files.Size())
|
||||
if ((uint32_t)rfnum >= Files.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -1450,7 +1437,7 @@ int FileSystem::GetFirstEntry (int rfnum) const noexcept
|
|||
|
||||
int FileSystem::GetLastEntry (int rfnum) const noexcept
|
||||
{
|
||||
if ((uint32_t)rfnum >= Files.Size())
|
||||
if ((uint32_t)rfnum >= Files.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -1465,7 +1452,7 @@ int FileSystem::GetLastEntry (int rfnum) const noexcept
|
|||
|
||||
int FileSystem::GetEntryCount (int rfnum) const noexcept
|
||||
{
|
||||
if ((uint32_t)rfnum >= Files.Size())
|
||||
if ((uint32_t)rfnum >= Files.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -1484,7 +1471,7 @@ int FileSystem::GetEntryCount (int rfnum) const noexcept
|
|||
|
||||
const char *FileSystem::GetResourceFileFullName (int rfnum) const noexcept
|
||||
{
|
||||
if ((unsigned int)rfnum >= Files.Size())
|
||||
if ((unsigned int)rfnum >= Files.size())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1501,17 +1488,17 @@ const char *FileSystem::GetResourceFileFullName (int rfnum) const noexcept
|
|||
|
||||
bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
|
||||
{
|
||||
FString name2=name, type2, path;
|
||||
std::string name2 = name, type2, path;
|
||||
|
||||
// The old code said 'filename' and ignored the path, this looked like a bug.
|
||||
FixPathSeperator(name2);
|
||||
auto lump = FindFile(name2);
|
||||
FixPathSeparator(&name2.front());
|
||||
auto lump = FindFile(name2.c_str());
|
||||
if (lump < 0) return false; // Does not exist.
|
||||
|
||||
auto oldlump = FileInfo[lump];
|
||||
ptrdiff_t slash = oldlump.longName.LastIndexOf('/');
|
||||
ptrdiff_t slash = oldlump.longName.find_last_of('/');
|
||||
|
||||
if (slash == -1)
|
||||
if (slash == std::string::npos)
|
||||
{
|
||||
FileInfo[lump].flags = LUMPF_FULLPATH;
|
||||
return true; // already is pathless.
|
||||
|
@ -1519,54 +1506,13 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
|
|||
|
||||
|
||||
// just create a new reference to the original data with a different name.
|
||||
oldlump.longName = oldlump.longName.Mid(slash + 1);
|
||||
oldlump.longName.erase(oldlump.longName.begin(), oldlump.longName.begin() + (slash + 1));
|
||||
oldlump.resourceId = id;
|
||||
oldlump.flags = LUMPF_FULLPATH;
|
||||
FileInfo.Push(oldlump);
|
||||
FileInfo.push_back(oldlump);
|
||||
return true;
|
||||
}
|
||||
|
||||
// FileData -----------------------------------------------------------------
|
||||
|
||||
FileData::FileData ()
|
||||
{
|
||||
}
|
||||
|
||||
FileData::FileData (const FileData ©)
|
||||
{
|
||||
Block = copy.Block;
|
||||
}
|
||||
|
||||
FileData &FileData::operator = (const FileData ©)
|
||||
{
|
||||
Block = copy.Block;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FileData::FileData (const FString &source)
|
||||
: Block (source)
|
||||
{
|
||||
}
|
||||
|
||||
FileData::~FileData ()
|
||||
{
|
||||
}
|
||||
|
||||
FString::FString (ELumpNum lumpnum)
|
||||
{
|
||||
auto lumpr = fileSystem.OpenFileReader ((int)lumpnum);
|
||||
auto size = lumpr.GetLength ();
|
||||
AllocBuffer (1 + size);
|
||||
auto numread = lumpr.Read (&Chars[0], size);
|
||||
Chars[size] = '\0';
|
||||
|
||||
if (numread != size)
|
||||
{
|
||||
throw FileSystemException("ConstructStringFromLump: Only read %ld of %ld bytes on lump %i (%s)\n",
|
||||
numread, size, lumpnum, fileSystem.GetFileFullName((int)lumpnum));
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// PrintLastError
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
|
||||
|
||||
#include "files.h"
|
||||
#include "tarray.h"
|
||||
#include "cmdlib.h"
|
||||
#include "zstring.h"
|
||||
#include "resourcefile.h"
|
||||
|
||||
class FResourceFile;
|
||||
|
@ -30,19 +27,34 @@ union LumpShortName
|
|||
class FileData
|
||||
{
|
||||
public:
|
||||
FileData ();
|
||||
FileData() { lump = nullptr; }
|
||||
const void *GetMem () { return lump->Cache; }
|
||||
size_t GetSize () { return lump->LumpSize; }
|
||||
const char* GetString () const { return (const char*)lump->Cache; }
|
||||
const uint8_t* GetBytes() const { return (const uint8_t*)lump->Cache; }
|
||||
|
||||
FileData& operator = (const FileData& copy) = delete;
|
||||
|
||||
FileData(const FileData& copy)
|
||||
{
|
||||
lump = copy.lump;
|
||||
lump->Lock();
|
||||
}
|
||||
|
||||
~FileData()
|
||||
{
|
||||
if (lump) lump->Unlock();
|
||||
}
|
||||
|
||||
FileData (const FileData ©);
|
||||
FileData &operator= (const FileData ©);
|
||||
~FileData ();
|
||||
const void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); }
|
||||
size_t GetSize () { return Block.Len(); }
|
||||
const char* GetString () const { return Block.GetChars(); }
|
||||
|
||||
private:
|
||||
FileData (const FString &source);
|
||||
FileData(FResourceLump* nlump)
|
||||
{
|
||||
lump = nlump;
|
||||
if (lump) lump->Lock();
|
||||
}
|
||||
|
||||
FString Block;
|
||||
FResourceLump* lump;
|
||||
|
||||
friend class FileSystem;
|
||||
};
|
||||
|
@ -67,7 +79,7 @@ public:
|
|||
void SetMaxIwadNum(int x) { MaxIwadIndex = x; }
|
||||
|
||||
bool InitSingleFile(const char *filename, FileSystemMessageFunc Printf = nullptr);
|
||||
bool InitMultipleFiles (TArray<FString> &filenames, LumpFilterInfo* filter = nullptr, FileSystemMessageFunc Printf = nullptr, bool allowduplicates = false, FILE* hashfile = nullptr);
|
||||
bool InitMultipleFiles (std::vector<std::string>& filenames, LumpFilterInfo* filter = nullptr, FileSystemMessageFunc Printf = nullptr, bool allowduplicates = false, FILE* hashfile = nullptr);
|
||||
void AddFile (const char *filename, FileReader *wadinfo, LumpFilterInfo* filter, FileSystemMessageFunc Printf, FILE* hashfile);
|
||||
int CheckIfResourceFileLoaded (const char *name) noexcept;
|
||||
void AddAdditionalFile(const char* filename, FileReader* wadinfo = NULL) {}
|
||||
|
@ -85,10 +97,8 @@ public:
|
|||
|
||||
inline int CheckNumForName (const uint8_t *name) { return CheckNumForName ((const char *)name, ns_global); }
|
||||
inline int CheckNumForName (const char *name) { return CheckNumForName (name, ns_global); }
|
||||
inline int CheckNumForName (const FString &name) { return CheckNumForName (name.GetChars()); }
|
||||
inline int CheckNumForName (const uint8_t *name, int ns) { return CheckNumForName ((const char *)name, ns); }
|
||||
inline int GetNumForName (const char *name) { return GetNumForName (name, ns_global); }
|
||||
inline int GetNumForName (const FString &name) { return GetNumForName (name.GetChars(), ns_global); }
|
||||
inline int GetNumForName (const uint8_t *name) { return GetNumForName ((const char *)name); }
|
||||
inline int GetNumForName (const uint8_t *name, int ns) { return GetNumForName ((const char *)name, ns); }
|
||||
|
||||
|
@ -105,25 +115,15 @@ public:
|
|||
return FindFile(name) >= 0;
|
||||
}
|
||||
|
||||
bool FileExists(const FString& name)
|
||||
{
|
||||
return FindFile(name) >= 0;
|
||||
}
|
||||
|
||||
bool FileExists(const std::string& name)
|
||||
{
|
||||
return FindFile(name.c_str()) >= 0;
|
||||
}
|
||||
|
||||
LumpShortName& GetShortName(int i); // may only be called before the hash chains are set up.
|
||||
FString& GetLongName(int i); // may only be called before the hash chains are set up.
|
||||
void RenameFile(int num, const char* fn);
|
||||
bool CreatePathlessCopy(const char* name, int id, int flags);
|
||||
|
||||
inline int CheckNumForFullName(const FString &name, bool trynormal = false, int namespc = ns_global) { return CheckNumForFullName(name.GetChars(), trynormal, namespc); }
|
||||
inline int CheckNumForFullName (const FString &name, int wadfile) { return CheckNumForFullName(name.GetChars(), wadfile); }
|
||||
inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); }
|
||||
|
||||
void ReadFile (int lump, void *dest);
|
||||
// These should only be used if the file data really needs padding.
|
||||
FileData ReadFile (int lump);
|
||||
|
@ -143,24 +143,19 @@ public:
|
|||
int FindResource(int resid, const char* type, int filenum = -1) const noexcept;
|
||||
int GetResource(int resid, const char* type, int filenum = -1) const;
|
||||
|
||||
|
||||
static uint32_t LumpNameHash (const char *name); // [RH] Create hash key from an 8-char name
|
||||
|
||||
int FileLength (int lump) const;
|
||||
int GetFileOffset (int lump); // [RH] Returns offset of lump in the wadfile
|
||||
int GetFileFlags (int lump); // Return the flags for this lump
|
||||
void GetFileShortName (char *to, int lump) const; // [RH] Copies the lump name to to using uppercopy
|
||||
void GetFileShortName (FString &to, int lump) const;
|
||||
const char* GetFileShortName(int lump) const;
|
||||
const char *GetFileFullName (int lump, bool returnshort = true) const; // [RH] Returns the lump's full name
|
||||
FString GetFileFullPath (int lump) const; // [RH] Returns wad's name + lump's full name
|
||||
std::string GetFileFullPath (int lump) const; // [RH] Returns wad's name + lump's full name
|
||||
int GetFileContainer (int lump) const; // [RH] Returns wadnum for a specified lump
|
||||
int GetFileNamespace (int lump) const; // [RH] Returns the namespace a lump belongs to
|
||||
void SetFileNamespace(int lump, int ns);
|
||||
int GetResourceId(int lump) const; // Returns the RFF index number for this lump
|
||||
const char* GetResourceType(int lump) const;
|
||||
bool CheckFileName (int lump, const char *name) const; // [RH] Returns true if the names match
|
||||
unsigned GetFilesInFolder(const char *path, TArray<FolderEntry> &result, bool atomic) const;
|
||||
unsigned GetFilesInFolder(const char *path, std::vector<FolderEntry> &result, bool atomic) const;
|
||||
|
||||
int GetNumEntries() const
|
||||
{
|
||||
|
@ -169,7 +164,7 @@ public:
|
|||
|
||||
int GetNumWads() const
|
||||
{
|
||||
return Files.Size();
|
||||
return (int)Files.size();
|
||||
}
|
||||
|
||||
void AddLump(FResourceLump* lump);
|
||||
|
@ -183,10 +178,10 @@ protected:
|
|||
|
||||
struct LumpRecord;
|
||||
|
||||
TArray<FResourceFile *> Files;
|
||||
TArray<LumpRecord> FileInfo;
|
||||
std::vector<FResourceFile *> Files;
|
||||
std::vector<LumpRecord> FileInfo;
|
||||
|
||||
TArray<uint32_t> Hashes; // one allocation for all hash lists.
|
||||
std::vector<uint32_t> Hashes; // one allocation for all hash lists.
|
||||
uint32_t *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure
|
||||
uint32_t *NextLumpIndex;
|
||||
|
||||
|
|
|
@ -157,15 +157,6 @@ static int FS_FindClose(void *const handle)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool DirEntryExists(const char* pathname, bool* isdir)
|
||||
{
|
||||
if (isdir) *isdir = false;
|
||||
struct stat info;
|
||||
bool res = stat(pathname, &info) == 0;
|
||||
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int FS_FindAttr(findstate_t *const fileinfo)
|
||||
{
|
||||
dirent *const ent = fileinfo->namelist[fileinfo->current];
|
||||
|
@ -387,3 +378,30 @@ bool ScanDirectory(std::vector<FileListEntry>& list, const char* dirpath, const
|
|||
return ScanDirectory(list, dirpath, match, "", nosubdir, readhidden);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DirEntryExists
|
||||
//
|
||||
// Returns true if the given path exists, be it a directory or a file.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FS_DirEntryExists(const char* pathname, bool* isdir)
|
||||
{
|
||||
if (isdir) *isdir = false;
|
||||
if (pathname == NULL || *pathname == 0)
|
||||
return false;
|
||||
|
||||
#ifndef _WIN32
|
||||
struct stat info;
|
||||
bool res = stat(pathname, &info) == 0;
|
||||
#else
|
||||
// Windows must use the wide version of stat to preserve non-standard paths.
|
||||
auto wstr = toWide(pathname);
|
||||
struct _stat64 info;
|
||||
bool res = _wstat64(wstr.c_str(), &info) == 0;
|
||||
#endif
|
||||
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ using FileList = std::vector<FileListEntry>;
|
|||
struct FCompressedBuffer;
|
||||
bool ScanDirectory(std::vector<FileListEntry>& list, const char* dirpath, const char* match, bool nosubdir = false, bool readhidden = false);
|
||||
bool WriteZip(const char* filename, const FCompressedBuffer* content, size_t contentcount);
|
||||
bool FS_DirEntryExists(const char* pathname, bool* isdir);
|
||||
|
||||
inline void FixPathSeparator(char* path)
|
||||
{
|
||||
|
|
416
source/common/filesystem/md5.hpp
Normal file
416
source/common/filesystem/md5.hpp
Normal file
|
@ -0,0 +1,416 @@
|
|||
#pragma once
|
||||
/*
|
||||
md5.hpp is a reformulation of the md5.h and md5.c code from
|
||||
http://www.opensource.apple.com/source/cups/cups-59/cups/md5.c to allow it to
|
||||
function as a component of a header only library. This conversion was done by
|
||||
Peter Thorson (webmaster@zaphoyd.com) in 2012 for the WebSocket++ project. The
|
||||
changes are released under the same license as the original (listed below)
|
||||
*/
|
||||
/*
|
||||
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
*/
|
||||
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
This code implements the MD5 Algorithm defined in RFC 1321, whose
|
||||
text is available at
|
||||
http://www.ietf.org/rfc/rfc1321.txt
|
||||
The code is derived from the text of the RFC, including the test suite
|
||||
(section A.5) but excluding the rest of Appendix A. It does not include
|
||||
any code or documentation that is identified in the RFC as being
|
||||
copyrighted.
|
||||
|
||||
The original and principal author of md5.h is L. Peter Deutsch
|
||||
<ghost@aladdin.com>. Other authors are noted in the change history
|
||||
that follows (in reverse chronological order):
|
||||
|
||||
2002-04-13 lpd Removed support for non-ANSI compilers; removed
|
||||
references to Ghostscript; clarified derivation from RFC 1321;
|
||||
now handles byte order either statically or dynamically.
|
||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
||||
added conditionalization for C++ compilation from Martin
|
||||
Purschke <purschke@bnl.gov>.
|
||||
1999-05-03 lpd Original version.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This package supports both compile-time and run-time determination of CPU
|
||||
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
|
||||
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
|
||||
* defined as non-zero, the code will be compiled to run only on big-endian
|
||||
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
|
||||
* run on either big- or little-endian CPUs, but will run slightly less
|
||||
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace fs_private {
|
||||
/// Provides MD5 hashing functionality
|
||||
namespace md5 {
|
||||
|
||||
typedef unsigned char md5_byte_t; /* 8-bit byte */
|
||||
typedef unsigned int md5_word_t; /* 32-bit word */
|
||||
|
||||
/* Define the state of the MD5 Algorithm. */
|
||||
typedef struct md5_state_s {
|
||||
md5_word_t count[2]; /* message length in bits, lsw first */
|
||||
md5_word_t abcd[4]; /* digest buffer */
|
||||
md5_byte_t buf[64]; /* accumulate block */
|
||||
} md5_state_t;
|
||||
|
||||
/* Initialize the algorithm. */
|
||||
inline void md5_init(md5_state_t* pms);
|
||||
|
||||
/* Append a string to the message. */
|
||||
inline void md5_append(md5_state_t* pms, md5_byte_t const* data, size_t nbytes);
|
||||
|
||||
/* Finish the message and return the digest. */
|
||||
inline void md5_finish(md5_state_t* pms, md5_byte_t digest[16]);
|
||||
|
||||
#undef ZSW_MD5_BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
|
||||
#ifdef ARCH_IS_BIG_ENDIAN
|
||||
# define ZSW_MD5_BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
|
||||
#else
|
||||
# define ZSW_MD5_BYTE_ORDER 0
|
||||
#endif
|
||||
|
||||
#define ZSW_MD5_T_MASK ((md5_word_t)~0)
|
||||
#define ZSW_MD5_T1 /* 0xd76aa478 */ (ZSW_MD5_T_MASK ^ 0x28955b87)
|
||||
#define ZSW_MD5_T2 /* 0xe8c7b756 */ (ZSW_MD5_T_MASK ^ 0x173848a9)
|
||||
#define ZSW_MD5_T3 0x242070db
|
||||
#define ZSW_MD5_T4 /* 0xc1bdceee */ (ZSW_MD5_T_MASK ^ 0x3e423111)
|
||||
#define ZSW_MD5_T5 /* 0xf57c0faf */ (ZSW_MD5_T_MASK ^ 0x0a83f050)
|
||||
#define ZSW_MD5_T6 0x4787c62a
|
||||
#define ZSW_MD5_T7 /* 0xa8304613 */ (ZSW_MD5_T_MASK ^ 0x57cfb9ec)
|
||||
#define ZSW_MD5_T8 /* 0xfd469501 */ (ZSW_MD5_T_MASK ^ 0x02b96afe)
|
||||
#define ZSW_MD5_T9 0x698098d8
|
||||
#define ZSW_MD5_T10 /* 0x8b44f7af */ (ZSW_MD5_T_MASK ^ 0x74bb0850)
|
||||
#define ZSW_MD5_T11 /* 0xffff5bb1 */ (ZSW_MD5_T_MASK ^ 0x0000a44e)
|
||||
#define ZSW_MD5_T12 /* 0x895cd7be */ (ZSW_MD5_T_MASK ^ 0x76a32841)
|
||||
#define ZSW_MD5_T13 0x6b901122
|
||||
#define ZSW_MD5_T14 /* 0xfd987193 */ (ZSW_MD5_T_MASK ^ 0x02678e6c)
|
||||
#define ZSW_MD5_T15 /* 0xa679438e */ (ZSW_MD5_T_MASK ^ 0x5986bc71)
|
||||
#define ZSW_MD5_T16 0x49b40821
|
||||
#define ZSW_MD5_T17 /* 0xf61e2562 */ (ZSW_MD5_T_MASK ^ 0x09e1da9d)
|
||||
#define ZSW_MD5_T18 /* 0xc040b340 */ (ZSW_MD5_T_MASK ^ 0x3fbf4cbf)
|
||||
#define ZSW_MD5_T19 0x265e5a51
|
||||
#define ZSW_MD5_T20 /* 0xe9b6c7aa */ (ZSW_MD5_T_MASK ^ 0x16493855)
|
||||
#define ZSW_MD5_T21 /* 0xd62f105d */ (ZSW_MD5_T_MASK ^ 0x29d0efa2)
|
||||
#define ZSW_MD5_T22 0x02441453
|
||||
#define ZSW_MD5_T23 /* 0xd8a1e681 */ (ZSW_MD5_T_MASK ^ 0x275e197e)
|
||||
#define ZSW_MD5_T24 /* 0xe7d3fbc8 */ (ZSW_MD5_T_MASK ^ 0x182c0437)
|
||||
#define ZSW_MD5_T25 0x21e1cde6
|
||||
#define ZSW_MD5_T26 /* 0xc33707d6 */ (ZSW_MD5_T_MASK ^ 0x3cc8f829)
|
||||
#define ZSW_MD5_T27 /* 0xf4d50d87 */ (ZSW_MD5_T_MASK ^ 0x0b2af278)
|
||||
#define ZSW_MD5_T28 0x455a14ed
|
||||
#define ZSW_MD5_T29 /* 0xa9e3e905 */ (ZSW_MD5_T_MASK ^ 0x561c16fa)
|
||||
#define ZSW_MD5_T30 /* 0xfcefa3f8 */ (ZSW_MD5_T_MASK ^ 0x03105c07)
|
||||
#define ZSW_MD5_T31 0x676f02d9
|
||||
#define ZSW_MD5_T32 /* 0x8d2a4c8a */ (ZSW_MD5_T_MASK ^ 0x72d5b375)
|
||||
#define ZSW_MD5_T33 /* 0xfffa3942 */ (ZSW_MD5_T_MASK ^ 0x0005c6bd)
|
||||
#define ZSW_MD5_T34 /* 0x8771f681 */ (ZSW_MD5_T_MASK ^ 0x788e097e)
|
||||
#define ZSW_MD5_T35 0x6d9d6122
|
||||
#define ZSW_MD5_T36 /* 0xfde5380c */ (ZSW_MD5_T_MASK ^ 0x021ac7f3)
|
||||
#define ZSW_MD5_T37 /* 0xa4beea44 */ (ZSW_MD5_T_MASK ^ 0x5b4115bb)
|
||||
#define ZSW_MD5_T38 0x4bdecfa9
|
||||
#define ZSW_MD5_T39 /* 0xf6bb4b60 */ (ZSW_MD5_T_MASK ^ 0x0944b49f)
|
||||
#define ZSW_MD5_T40 /* 0xbebfbc70 */ (ZSW_MD5_T_MASK ^ 0x4140438f)
|
||||
#define ZSW_MD5_T41 0x289b7ec6
|
||||
#define ZSW_MD5_T42 /* 0xeaa127fa */ (ZSW_MD5_T_MASK ^ 0x155ed805)
|
||||
#define ZSW_MD5_T43 /* 0xd4ef3085 */ (ZSW_MD5_T_MASK ^ 0x2b10cf7a)
|
||||
#define ZSW_MD5_T44 0x04881d05
|
||||
#define ZSW_MD5_T45 /* 0xd9d4d039 */ (ZSW_MD5_T_MASK ^ 0x262b2fc6)
|
||||
#define ZSW_MD5_T46 /* 0xe6db99e5 */ (ZSW_MD5_T_MASK ^ 0x1924661a)
|
||||
#define ZSW_MD5_T47 0x1fa27cf8
|
||||
#define ZSW_MD5_T48 /* 0xc4ac5665 */ (ZSW_MD5_T_MASK ^ 0x3b53a99a)
|
||||
#define ZSW_MD5_T49 /* 0xf4292244 */ (ZSW_MD5_T_MASK ^ 0x0bd6ddbb)
|
||||
#define ZSW_MD5_T50 0x432aff97
|
||||
#define ZSW_MD5_T51 /* 0xab9423a7 */ (ZSW_MD5_T_MASK ^ 0x546bdc58)
|
||||
#define ZSW_MD5_T52 /* 0xfc93a039 */ (ZSW_MD5_T_MASK ^ 0x036c5fc6)
|
||||
#define ZSW_MD5_T53 0x655b59c3
|
||||
#define ZSW_MD5_T54 /* 0x8f0ccc92 */ (ZSW_MD5_T_MASK ^ 0x70f3336d)
|
||||
#define ZSW_MD5_T55 /* 0xffeff47d */ (ZSW_MD5_T_MASK ^ 0x00100b82)
|
||||
#define ZSW_MD5_T56 /* 0x85845dd1 */ (ZSW_MD5_T_MASK ^ 0x7a7ba22e)
|
||||
#define ZSW_MD5_T57 0x6fa87e4f
|
||||
#define ZSW_MD5_T58 /* 0xfe2ce6e0 */ (ZSW_MD5_T_MASK ^ 0x01d3191f)
|
||||
#define ZSW_MD5_T59 /* 0xa3014314 */ (ZSW_MD5_T_MASK ^ 0x5cfebceb)
|
||||
#define ZSW_MD5_T60 0x4e0811a1
|
||||
#define ZSW_MD5_T61 /* 0xf7537e82 */ (ZSW_MD5_T_MASK ^ 0x08ac817d)
|
||||
#define ZSW_MD5_T62 /* 0xbd3af235 */ (ZSW_MD5_T_MASK ^ 0x42c50dca)
|
||||
#define ZSW_MD5_T63 0x2ad7d2bb
|
||||
#define ZSW_MD5_T64 /* 0xeb86d391 */ (ZSW_MD5_T_MASK ^ 0x14792c6e)
|
||||
|
||||
static void md5_process(md5_state_t* pms, md5_byte_t const* data /*[64]*/) {
|
||||
md5_word_t
|
||||
a = pms->abcd[0], b = pms->abcd[1],
|
||||
c = pms->abcd[2], d = pms->abcd[3];
|
||||
md5_word_t t;
|
||||
#if ZSW_MD5_BYTE_ORDER > 0
|
||||
/* Define storage only for big-endian CPUs. */
|
||||
md5_word_t X[16];
|
||||
#else
|
||||
/* Define storage for little-endian or both types of CPUs. */
|
||||
md5_word_t xbuf[16];
|
||||
md5_word_t const* X;
|
||||
#endif
|
||||
|
||||
{
|
||||
#if ZSW_MD5_BYTE_ORDER == 0
|
||||
/*
|
||||
* Determine dynamically whether this is a big-endian or
|
||||
* little-endian machine, since we can use a more efficient
|
||||
* algorithm on the latter.
|
||||
*/
|
||||
static int const w = 1;
|
||||
|
||||
if (*((md5_byte_t const*)&w)) /* dynamic little-endian */
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER <= 0 /* little-endian */
|
||||
{
|
||||
/*
|
||||
* On little-endian machines, we can process properly aligned
|
||||
* data without copying it.
|
||||
*/
|
||||
if (!((data - (md5_byte_t const*)0) & 3)) {
|
||||
/* data are properly aligned */
|
||||
X = (md5_word_t const*)data;
|
||||
}
|
||||
else {
|
||||
/* not aligned */
|
||||
std::memcpy(xbuf, data, 64);
|
||||
X = xbuf;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER == 0
|
||||
else /* dynamic big-endian */
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER >= 0 /* big-endian */
|
||||
{
|
||||
/*
|
||||
* On big-endian machines, we must arrange the bytes in the
|
||||
* right order.
|
||||
*/
|
||||
const md5_byte_t* xp = data;
|
||||
int i;
|
||||
|
||||
# if ZSW_MD5_BYTE_ORDER == 0
|
||||
X = xbuf; /* (dynamic only) */
|
||||
# else
|
||||
# define xbuf X /* (static only) */
|
||||
# endif
|
||||
for (i = 0; i < 16; ++i, xp += 4)
|
||||
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define ZSW_MD5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
|
||||
/* Round 1. */
|
||||
/* Let [abcd k s i] denote the operation
|
||||
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define ZSW_MD5_F(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + ZSW_MD5_F(b,c,d) + X[k] + Ti;\
|
||||
a = ZSW_MD5_ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 0, 7, ZSW_MD5_T1);
|
||||
SET(d, a, b, c, 1, 12, ZSW_MD5_T2);
|
||||
SET(c, d, a, b, 2, 17, ZSW_MD5_T3);
|
||||
SET(b, c, d, a, 3, 22, ZSW_MD5_T4);
|
||||
SET(a, b, c, d, 4, 7, ZSW_MD5_T5);
|
||||
SET(d, a, b, c, 5, 12, ZSW_MD5_T6);
|
||||
SET(c, d, a, b, 6, 17, ZSW_MD5_T7);
|
||||
SET(b, c, d, a, 7, 22, ZSW_MD5_T8);
|
||||
SET(a, b, c, d, 8, 7, ZSW_MD5_T9);
|
||||
SET(d, a, b, c, 9, 12, ZSW_MD5_T10);
|
||||
SET(c, d, a, b, 10, 17, ZSW_MD5_T11);
|
||||
SET(b, c, d, a, 11, 22, ZSW_MD5_T12);
|
||||
SET(a, b, c, d, 12, 7, ZSW_MD5_T13);
|
||||
SET(d, a, b, c, 13, 12, ZSW_MD5_T14);
|
||||
SET(c, d, a, b, 14, 17, ZSW_MD5_T15);
|
||||
SET(b, c, d, a, 15, 22, ZSW_MD5_T16);
|
||||
#undef SET
|
||||
|
||||
/* Round 2. */
|
||||
/* Let [abcd k s i] denote the operation
|
||||
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define ZSW_MD5_G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + ZSW_MD5_G(b,c,d) + X[k] + Ti;\
|
||||
a = ZSW_MD5_ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 1, 5, ZSW_MD5_T17);
|
||||
SET(d, a, b, c, 6, 9, ZSW_MD5_T18);
|
||||
SET(c, d, a, b, 11, 14, ZSW_MD5_T19);
|
||||
SET(b, c, d, a, 0, 20, ZSW_MD5_T20);
|
||||
SET(a, b, c, d, 5, 5, ZSW_MD5_T21);
|
||||
SET(d, a, b, c, 10, 9, ZSW_MD5_T22);
|
||||
SET(c, d, a, b, 15, 14, ZSW_MD5_T23);
|
||||
SET(b, c, d, a, 4, 20, ZSW_MD5_T24);
|
||||
SET(a, b, c, d, 9, 5, ZSW_MD5_T25);
|
||||
SET(d, a, b, c, 14, 9, ZSW_MD5_T26);
|
||||
SET(c, d, a, b, 3, 14, ZSW_MD5_T27);
|
||||
SET(b, c, d, a, 8, 20, ZSW_MD5_T28);
|
||||
SET(a, b, c, d, 13, 5, ZSW_MD5_T29);
|
||||
SET(d, a, b, c, 2, 9, ZSW_MD5_T30);
|
||||
SET(c, d, a, b, 7, 14, ZSW_MD5_T31);
|
||||
SET(b, c, d, a, 12, 20, ZSW_MD5_T32);
|
||||
#undef SET
|
||||
|
||||
/* Round 3. */
|
||||
/* Let [abcd k s t] denote the operation
|
||||
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define ZSW_MD5_H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + ZSW_MD5_H(b,c,d) + X[k] + Ti;\
|
||||
a = ZSW_MD5_ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 5, 4, ZSW_MD5_T33);
|
||||
SET(d, a, b, c, 8, 11, ZSW_MD5_T34);
|
||||
SET(c, d, a, b, 11, 16, ZSW_MD5_T35);
|
||||
SET(b, c, d, a, 14, 23, ZSW_MD5_T36);
|
||||
SET(a, b, c, d, 1, 4, ZSW_MD5_T37);
|
||||
SET(d, a, b, c, 4, 11, ZSW_MD5_T38);
|
||||
SET(c, d, a, b, 7, 16, ZSW_MD5_T39);
|
||||
SET(b, c, d, a, 10, 23, ZSW_MD5_T40);
|
||||
SET(a, b, c, d, 13, 4, ZSW_MD5_T41);
|
||||
SET(d, a, b, c, 0, 11, ZSW_MD5_T42);
|
||||
SET(c, d, a, b, 3, 16, ZSW_MD5_T43);
|
||||
SET(b, c, d, a, 6, 23, ZSW_MD5_T44);
|
||||
SET(a, b, c, d, 9, 4, ZSW_MD5_T45);
|
||||
SET(d, a, b, c, 12, 11, ZSW_MD5_T46);
|
||||
SET(c, d, a, b, 15, 16, ZSW_MD5_T47);
|
||||
SET(b, c, d, a, 2, 23, ZSW_MD5_T48);
|
||||
#undef SET
|
||||
|
||||
/* Round 4. */
|
||||
/* Let [abcd k s t] denote the operation
|
||||
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define ZSW_MD5_I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + ZSW_MD5_I(b,c,d) + X[k] + Ti;\
|
||||
a = ZSW_MD5_ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 0, 6, ZSW_MD5_T49);
|
||||
SET(d, a, b, c, 7, 10, ZSW_MD5_T50);
|
||||
SET(c, d, a, b, 14, 15, ZSW_MD5_T51);
|
||||
SET(b, c, d, a, 5, 21, ZSW_MD5_T52);
|
||||
SET(a, b, c, d, 12, 6, ZSW_MD5_T53);
|
||||
SET(d, a, b, c, 3, 10, ZSW_MD5_T54);
|
||||
SET(c, d, a, b, 10, 15, ZSW_MD5_T55);
|
||||
SET(b, c, d, a, 1, 21, ZSW_MD5_T56);
|
||||
SET(a, b, c, d, 8, 6, ZSW_MD5_T57);
|
||||
SET(d, a, b, c, 15, 10, ZSW_MD5_T58);
|
||||
SET(c, d, a, b, 6, 15, ZSW_MD5_T59);
|
||||
SET(b, c, d, a, 13, 21, ZSW_MD5_T60);
|
||||
SET(a, b, c, d, 4, 6, ZSW_MD5_T61);
|
||||
SET(d, a, b, c, 11, 10, ZSW_MD5_T62);
|
||||
SET(c, d, a, b, 2, 15, ZSW_MD5_T63);
|
||||
SET(b, c, d, a, 9, 21, ZSW_MD5_T64);
|
||||
#undef SET
|
||||
|
||||
/* Then perform the following additions. (That is increment each
|
||||
of the four registers by the value it had before this block
|
||||
was started.) */
|
||||
pms->abcd[0] += a;
|
||||
pms->abcd[1] += b;
|
||||
pms->abcd[2] += c;
|
||||
pms->abcd[3] += d;
|
||||
}
|
||||
|
||||
void md5_init(md5_state_t* pms) {
|
||||
pms->count[0] = pms->count[1] = 0;
|
||||
pms->abcd[0] = 0x67452301;
|
||||
pms->abcd[1] = /*0xefcdab89*/ ZSW_MD5_T_MASK ^ 0x10325476;
|
||||
pms->abcd[2] = /*0x98badcfe*/ ZSW_MD5_T_MASK ^ 0x67452301;
|
||||
pms->abcd[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void md5_append(md5_state_t* pms, md5_byte_t const* data, size_t nbytes) {
|
||||
md5_byte_t const* p = data;
|
||||
size_t left = nbytes;
|
||||
int offset = (pms->count[0] >> 3) & 63;
|
||||
md5_word_t nbits = (md5_word_t)(nbytes << 3);
|
||||
|
||||
if (nbytes <= 0)
|
||||
return;
|
||||
|
||||
/* Update the message length. */
|
||||
pms->count[1] += (md5_word_t)(nbytes >> 29);
|
||||
pms->count[0] += nbits;
|
||||
if (pms->count[0] < nbits)
|
||||
pms->count[1]++;
|
||||
|
||||
/* Process an initial partial block. */
|
||||
if (offset) {
|
||||
int copy = (offset + nbytes > 64 ? 64 - offset : static_cast<int>(nbytes));
|
||||
|
||||
std::memcpy(pms->buf + offset, p, copy);
|
||||
if (offset + copy < 64)
|
||||
return;
|
||||
p += copy;
|
||||
left -= copy;
|
||||
md5_process(pms, pms->buf);
|
||||
}
|
||||
|
||||
/* Process full blocks. */
|
||||
for (; left >= 64; p += 64, left -= 64)
|
||||
md5_process(pms, p);
|
||||
|
||||
/* Process a final partial block. */
|
||||
if (left)
|
||||
std::memcpy(pms->buf, p, left);
|
||||
}
|
||||
|
||||
void md5_finish(md5_state_t* pms, md5_byte_t digest[16]) {
|
||||
static md5_byte_t const pad[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
md5_byte_t data[8];
|
||||
int i;
|
||||
|
||||
/* Save the length before padding. */
|
||||
for (i = 0; i < 8; ++i)
|
||||
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
||||
/* Pad to 56 bytes mod 64. */
|
||||
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
||||
/* Append the length. */
|
||||
md5_append(pms, data, 8);
|
||||
for (i = 0; i < 16; ++i)
|
||||
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
|
||||
}
|
||||
|
||||
|
||||
} // md5
|
||||
} // fs_private
|
||||
|
|
@ -36,11 +36,7 @@
|
|||
|
||||
#include <zlib.h>
|
||||
#include "resourcefile.h"
|
||||
|
||||
// hashing is optional.
|
||||
#if __has_include("md5.h")
|
||||
#include "md5.h"
|
||||
#endif
|
||||
#include "md5.hpp"
|
||||
|
||||
std::string ExtractBaseName(const char* path, bool include_extension)
|
||||
{
|
||||
|
@ -360,26 +356,26 @@ int lumpcmp(const void * a, const void * b)
|
|||
|
||||
void FResourceFile::GenerateHash()
|
||||
{
|
||||
#if __has_include("md5.h")
|
||||
// hash the lump directory after sorting
|
||||
using namespace fs_private::md5;
|
||||
|
||||
auto n = snprintf(Hash, 48, "%08X-%04X-", (unsigned)Reader.GetLength(), NumLumps);
|
||||
|
||||
MD5Context md5;
|
||||
md5_state_t state;
|
||||
md5_init(&state);
|
||||
|
||||
uint8_t digest[16];
|
||||
for(uint32_t i = 0; i < NumLumps; i++)
|
||||
{
|
||||
auto lump = GetLump(i);
|
||||
md5.Update((const uint8_t*)lump->FullName.c_str(), (unsigned)lump->FullName.length() + 1);
|
||||
md5.Update((const uint8_t*)&lump->LumpSize, 4);
|
||||
md5_append(&state, (const uint8_t*)lump->FullName.c_str(), (unsigned)lump->FullName.length() + 1);
|
||||
md5_append(&state, (const uint8_t*)&lump->LumpSize, 4);
|
||||
}
|
||||
md5.Final(digest);
|
||||
md5_finish(&state, digest);
|
||||
for (auto c : digest)
|
||||
{
|
||||
n += snprintf(Hash + n, 3, "%02X", c);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -91,7 +91,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
|||
// Read the font's configuration.
|
||||
// This will not be done for the default fonts, because they are not atomic and the default content does not need it.
|
||||
|
||||
TArray<FolderEntry> folderdata;
|
||||
std::vector<FolderEntry> folderdata;
|
||||
if (filetemplate != nullptr)
|
||||
{
|
||||
FStringf path("fonts/%s/", filetemplate);
|
||||
|
@ -103,12 +103,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
|||
{
|
||||
FStringf infpath("fonts/%s/font.inf", filetemplate);
|
||||
|
||||
unsigned index = folderdata.FindEx([=](const FolderEntry &entry)
|
||||
size_t index;
|
||||
for(index = 0; index < folderdata.size(); index++)
|
||||
{
|
||||
return infpath.CompareNoCase(entry.name) == 0;
|
||||
});
|
||||
if (infpath.CompareNoCase(folderdata[i].name) == 0) break;
|
||||
}
|
||||
|
||||
if (index < folderdata.Size())
|
||||
if (index < folderdata.size())
|
||||
{
|
||||
FScanner sc;
|
||||
sc.OpenLumpNum(folderdata[index].lumpnum);
|
||||
|
@ -288,7 +289,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
|||
}
|
||||
}
|
||||
}
|
||||
if (folderdata.Size() > 0)
|
||||
if (folderdata.size() > 0)
|
||||
{
|
||||
// all valid lumps must be named with a hex number that represents its Unicode character index.
|
||||
for (auto &entry : folderdata)
|
||||
|
@ -397,7 +398,7 @@ public:
|
|||
}
|
||||
|
||||
};
|
||||
void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
|
||||
void FFont::ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
|
||||
{
|
||||
TMap<int, FGameTexture*> charMap;
|
||||
int minchar = INT_MAX;
|
||||
|
|
|
@ -125,7 +125,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
|
|||
FontName = name;
|
||||
|
||||
FileData data1 = fileSystem.ReadFile (lump);
|
||||
const uint8_t *data = (const uint8_t *)data1.GetMem();
|
||||
auto data = data1.GetBytes();
|
||||
|
||||
if (data[0] == 0xE1 && data[1] == 0xE6 && data[2] == 0xD5 && data[3] == 0x1A)
|
||||
{
|
||||
|
@ -475,7 +475,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
|
|||
void FSingleLumpFont::CheckFON1Chars()
|
||||
{
|
||||
FileData memLump = fileSystem.ReadFile(Lump);
|
||||
const uint8_t* data = (const uint8_t*)memLump.GetMem();
|
||||
auto data = memLump.GetBytes();
|
||||
const uint8_t* data_p;
|
||||
|
||||
data_p = data + 8;
|
||||
|
|
|
@ -109,7 +109,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
|
|||
int lump = -1;
|
||||
int folderfile = -1;
|
||||
|
||||
TArray<FolderEntry> folderdata;
|
||||
std::vector<FolderEntry> folderdata;
|
||||
FStringf path("fonts/%s/", name);
|
||||
|
||||
// Use a folder-based font only if it comes from a later file than the single lump version.
|
||||
|
@ -149,7 +149,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
|
|||
return font;
|
||||
}
|
||||
}
|
||||
if (folderdata.Size() > 0)
|
||||
if (folderdata.size() > 0)
|
||||
{
|
||||
font = new FFont(name, nullptr, name, 0, 0, 1, -1);
|
||||
if (translationsLoaded) font->LoadTranslations();
|
||||
|
|
|
@ -175,7 +175,7 @@ protected:
|
|||
|
||||
void FixXMoves();
|
||||
|
||||
void ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
|
||||
void ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
|
||||
|
||||
EFontType Type = EFontType::Unknown;
|
||||
FName AltFontName = NAME_None;
|
||||
|
|
|
@ -173,7 +173,7 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)
|
|||
|
||||
int len = fileSystem.FileLength(lump);
|
||||
FileData lumpd = fileSystem.ReadFile(lump);
|
||||
char * buffer = (char*)lumpd.GetMem();
|
||||
const char * buffer = lumpd.GetString();
|
||||
|
||||
if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 )
|
||||
{
|
||||
|
|
|
@ -70,15 +70,15 @@ private:
|
|||
{
|
||||
uint16_t numframes, framesize;
|
||||
};
|
||||
d3dhead * dhead;
|
||||
d3dpoly * dpolys;
|
||||
a3dhead * ahead;
|
||||
uint32_t * averts;
|
||||
const d3dhead * dhead;
|
||||
const d3dpoly * dpolys;
|
||||
const a3dhead * ahead;
|
||||
const uint32_t * averts;
|
||||
struct dxvert
|
||||
{
|
||||
int16_t x, y, z, pad;
|
||||
};
|
||||
dxvert * dxverts;
|
||||
const dxvert * dxverts;
|
||||
|
||||
// converted data structures
|
||||
struct UE1Vertex
|
||||
|
|
|
@ -63,12 +63,6 @@ bool IQMModel::Load(const char* path, int lumpnum, const char* buffer, int lengt
|
|||
uint32_t num_extensions = reader.ReadUInt32();
|
||||
uint32_t ofs_extensions = reader.ReadUInt32();
|
||||
|
||||
/*if (num_joints <= 0)
|
||||
{
|
||||
Printf("Invalid model: \"%s%s\", no joint data is present\n", path, fileSystem.GetLongName(mLumpNum).GetChars());
|
||||
return false;
|
||||
}*/
|
||||
|
||||
if (num_text == 0)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ void FDMDModel::LoadGeometry()
|
|||
{
|
||||
static int axis[3] = { VX, VY, VZ };
|
||||
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
|
||||
const char *buffer = (const char *)lumpdata.GetMem();
|
||||
auto buffer = lumpdata.GetString();
|
||||
texCoords = new FTexCoord[info.numTexCoords];
|
||||
memcpy(texCoords, buffer + info.offsetTexCoords, info.numTexCoords * sizeof(FTexCoord));
|
||||
|
||||
|
@ -502,7 +502,7 @@ void FMD2Model::LoadGeometry()
|
|||
static int axis[3] = { VX, VY, VZ };
|
||||
uint8_t *md2_frames;
|
||||
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
|
||||
const char *buffer = (const char *)lumpdata.GetMem();
|
||||
auto buffer = lumpdata.GetString();
|
||||
|
||||
texCoords = new FTexCoord[info.numTexCoords];
|
||||
memcpy(texCoords, (uint8_t*)buffer + info.offsetTexCoords, info.numTexCoords * sizeof(FTexCoord));
|
||||
|
|
|
@ -190,7 +190,7 @@ bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int le
|
|||
void FMD3Model::LoadGeometry()
|
||||
{
|
||||
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
|
||||
const char *buffer = (const char *)lumpdata.GetMem();
|
||||
auto buffer = lumpdata.GetString();
|
||||
md3_header_t * hdr = (md3_header_t *)buffer;
|
||||
md3_surface_t * surf = (md3_surface_t*)(buffer + LittleLong(hdr->Ofs_Surfaces));
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length)
|
||||
{
|
||||
FString objName = fileSystem.GetFileFullPath(lumpnum);
|
||||
auto objName = fileSystem.GetFileFullPath(lumpnum);
|
||||
FString objBuf(buffer, length);
|
||||
|
||||
// Do some replacements before we parse the OBJ string
|
||||
|
@ -101,7 +101,7 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length
|
|||
wObjBuf = nullptr;
|
||||
objBuf.UnlockBuffer();
|
||||
}
|
||||
sc.OpenString(objName, objBuf);
|
||||
sc.OpenString(objName.c_str(), objBuf);
|
||||
|
||||
FTextureID curMtl = FNullTextureID();
|
||||
OBJSurface *curSurface = nullptr;
|
||||
|
|
|
@ -69,26 +69,25 @@ bool FUE1Model::Load( const char *filename, int lumpnum, const char *buffer, int
|
|||
|
||||
void FUE1Model::LoadGeometry()
|
||||
{
|
||||
FileData lump, lump2;
|
||||
const char *buffer, *buffer2;
|
||||
lump = fileSystem.ReadFile(mDataLump);
|
||||
buffer = (char*)lump.GetMem();
|
||||
lump2 = fileSystem.ReadFile(mAnivLump);
|
||||
buffer2 = (char*)lump2.GetMem();
|
||||
FileData lump = fileSystem.ReadFile(mDataLump);
|
||||
buffer = lump.GetString();
|
||||
FileData lump2 = fileSystem.ReadFile(mAnivLump);
|
||||
buffer2 = lump2.GetString();
|
||||
// map structures
|
||||
dhead = (d3dhead*)(buffer);
|
||||
dpolys = (d3dpoly*)(buffer+sizeof(d3dhead));
|
||||
ahead = (a3dhead*)(buffer2);
|
||||
dhead = (const d3dhead*)(buffer);
|
||||
dpolys = (const d3dpoly*)(buffer+sizeof(d3dhead));
|
||||
ahead = (const a3dhead*)(buffer2);
|
||||
// detect deus ex format
|
||||
if ( (ahead->framesize/dhead->numverts) == 8 )
|
||||
{
|
||||
averts = NULL;
|
||||
dxverts = (dxvert*)(buffer2+sizeof(a3dhead));
|
||||
averts = nullptr;
|
||||
dxverts = (const dxvert*)(buffer2+sizeof(a3dhead));
|
||||
}
|
||||
else
|
||||
{
|
||||
averts = (uint32_t*)(buffer2+sizeof(a3dhead));
|
||||
dxverts = NULL;
|
||||
averts = (const uint32_t*)(buffer2+sizeof(a3dhead));
|
||||
dxverts = nullptr;
|
||||
}
|
||||
// set counters
|
||||
numVerts = dhead->numverts;
|
||||
|
|
|
@ -162,7 +162,7 @@ FVoxel *R_LoadKVX(int lumpnum)
|
|||
int i, j, n;
|
||||
|
||||
FileData lump = fileSystem.ReadFile(lumpnum); // FileData adds an extra 0 byte to the end.
|
||||
uint8_t *rawvoxel = (uint8_t *)lump.GetMem();
|
||||
auto rawvoxel = lump.GetBytes();
|
||||
int voxelsize = (int)(lump.GetSize()-1);
|
||||
|
||||
// Oh, KVX, why couldn't you have a proper header? We'll just go through
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "menu.h"
|
||||
#include "stats.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@ void MainWindow::SetNetStartProgress(int pos)
|
|||
if (NetStartPane != 0 && NetStartMaxPos > 1)
|
||||
{
|
||||
char buf[16];
|
||||
mysnprintf(buf, countof(buf), "%d/%d", pos, NetStartMaxPos);
|
||||
mysnprintf(buf, sizeof(buf), "%d/%d", pos, NetStartMaxPos);
|
||||
SetDlgItemTextA(NetStartPane, IDC_NETSTARTCOUNT, buf);
|
||||
SendDlgItemMessage(NetStartPane, IDC_NETSTARTPROGRESS, PBM_SETPOS, min(pos, NetStartMaxPos), 0);
|
||||
}
|
||||
|
|
|
@ -375,11 +375,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
|
||||
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
|
||||
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump);
|
||||
FileData vp_data = fileSystem.ReadFile(vp_lump);
|
||||
|
||||
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0);
|
||||
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump);
|
||||
FileData fp_data = fileSystem.ReadFile(fp_lump);
|
||||
|
||||
|
||||
|
||||
|
@ -410,8 +408,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
vp_comb << "#line 1\n";
|
||||
fp_comb << "#line 1\n";
|
||||
|
||||
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
|
||||
vp_comb << RemoveLayoutLocationDecl(GetStringFromLump(vp_lump), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(GetStringFromLump(fp_lump), "in").GetChars() << "\n";
|
||||
FString placeholder = "\n";
|
||||
|
||||
if (proc_prog_lump != NULL)
|
||||
|
@ -423,7 +421,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump, 0); // if it's a core shader, ignore overrides by user mods.
|
||||
if (pp_lump == -1) pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump);
|
||||
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
|
||||
FString pp_data = GetStringFromLump(pp_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
|
||||
{
|
||||
|
@ -434,14 +432,16 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat2.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat2.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
|
||||
if (pp_data.IndexOf("ProcessTexel") < 0)
|
||||
{
|
||||
|
@ -468,7 +468,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
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");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
}
|
||||
|
||||
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
|
||||
|
@ -491,7 +492,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog);
|
||||
FileData pp_data = fileSystem.ReadFile(pp_lump);
|
||||
fp_comb << pp_data.GetString() << "\n";
|
||||
fp_comb.AppendCStrPart(pp_data.GetString(), pp_data.GetSize()) << "\n";
|
||||
}
|
||||
|
||||
if (gl.flags & RFL_NO_CLIP_PLANES)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "hw_shaderpatcher.h"
|
||||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
|
@ -88,7 +89,9 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
}
|
||||
|
||||
|
|
|
@ -410,8 +410,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
vp_comb << "#line 1\n";
|
||||
fp_comb << "#line 1\n";
|
||||
|
||||
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
|
||||
vp_comb << RemoveLayoutLocationDecl(GetStringFromLump(vp_lump), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(GetStringFromLump(fp_lump), "in").GetChars() << "\n";
|
||||
FString placeholder = "\n";
|
||||
|
||||
if (proc_prog_lump.Len())
|
||||
|
@ -422,7 +422,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars());
|
||||
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
|
||||
auto ppf = fileSystem.ReadFile(pp_lump);
|
||||
FString pp_data = GetStringFromLump(pp_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
|
||||
{
|
||||
|
@ -433,14 +434,16 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat2.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat2.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
|
||||
if (pp_data.IndexOf("ProcessTexel") < 0)
|
||||
{
|
||||
|
@ -467,7 +470,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultlight.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultlight.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n";
|
||||
fp_comb.AppendCStrPart(pl_data.GetString(), pl_data.GetSize());
|
||||
}
|
||||
|
||||
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
|
||||
|
@ -490,7 +494,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog.GetChars());
|
||||
FileData pp_data = fileSystem.ReadFile(pp_lump);
|
||||
fp_comb << pp_data.GetString() << "\n";
|
||||
fp_comb.AppendCStrPart(pp_data.GetString(), pp_data.GetSize()) << "\n";
|
||||
}
|
||||
|
||||
if (gles.flags & RFL_NO_CLIP_PLANES)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "hw_shaderpatcher.h"
|
||||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
namespace OpenGLESRenderer
|
||||
{
|
||||
|
@ -88,7 +89,8 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "zvulkan/vulkanbuilders.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "filesystem.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
VkPPShader::VkPPShader(VulkanRenderDevice* fb, PPShader *shader) : fb(fb)
|
||||
{
|
||||
|
@ -66,7 +67,8 @@ FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defin
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars());
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
FString patchedCode;
|
||||
patchedCode.AppendFormat("#version %d\n", 450);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "filesystem.h"
|
||||
#include "engineerrors.h"
|
||||
#include "version.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
bool VkShaderManager::CompileNextShader()
|
||||
{
|
||||
|
@ -465,8 +466,7 @@ FString VkShaderManager::LoadPublicShaderLump(const char *lumpname)
|
|||
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
|
||||
if (lump == -1) lump = fileSystem.CheckNumForFullName(lumpname);
|
||||
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
|
||||
FileData data = fileSystem.ReadFile(lump);
|
||||
return data.GetString();
|
||||
return GetStringFromLump(lump);
|
||||
}
|
||||
|
||||
FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
|
||||
|
@ -474,7 +474,7 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
|
|||
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
|
||||
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
|
||||
FileData data = fileSystem.ReadFile(lump);
|
||||
return data.GetString();
|
||||
return GetStringFromLump(lump);
|
||||
}
|
||||
|
||||
VkPPShader* VkShaderManager::GetVkShader(PPShader* shader)
|
||||
|
|
|
@ -407,8 +407,6 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
|
|||
int lumpnum = baselump;
|
||||
auto fileno = fileSystem.GetFileContainer(lumpnum);
|
||||
|
||||
FString file = fileSystem.GetFileFullPath(lumpnum);
|
||||
|
||||
state.FileNo = fileno;
|
||||
|
||||
if (TokenMap.CountUsed() == 0)
|
||||
|
@ -503,7 +501,7 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
|
|||
// If the parser fails, there is no point starting the compiler, because it'd only flood the output with endless errors.
|
||||
if (FScriptPosition::ErrorCounter > 0)
|
||||
{
|
||||
I_Error("%d errors while parsing %s", FScriptPosition::ErrorCounter, fileSystem.GetFileFullPath(baselump).GetChars());
|
||||
I_Error("%d errors while parsing %s", FScriptPosition::ErrorCounter, fileSystem.GetFileFullPath(baselump).c_str());
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -517,7 +515,7 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
|
|||
if (Args->CheckParm("-dumpast"))
|
||||
{
|
||||
FString ast = ZCC_PrintAST(state.TopNode);
|
||||
FString filename = fileSystem.GetFileFullPath(baselump);
|
||||
FString filename = fileSystem.GetFileFullPath(baselump).c_str();
|
||||
filename.ReplaceChars(":\\/?|", '.');
|
||||
filename << ".ast";
|
||||
FileWriter *ff = FileWriter::Open(filename);
|
||||
|
|
|
@ -819,9 +819,7 @@ DEFINE_ACTION_FUNCTION(_Wads, GetLumpName)
|
|||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(lump);
|
||||
FString lumpname;
|
||||
fileSystem.GetFileShortName(lumpname, lump);
|
||||
ACTION_RETURN_STRING(lumpname);
|
||||
ACTION_RETURN_STRING(fileSystem.GetFileShortName(lump));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Wads, GetLumpFullName)
|
||||
|
@ -843,7 +841,7 @@ DEFINE_ACTION_FUNCTION(_Wads, ReadLump)
|
|||
PARAM_PROLOGUE;
|
||||
PARAM_INT(lump);
|
||||
const bool isLumpValid = lump >= 0 && lump < fileSystem.GetNumEntries();
|
||||
ACTION_RETURN_STRING(isLumpValid ? fileSystem.ReadFile(lump).GetString() : "");
|
||||
ACTION_RETURN_STRING(isLumpValid ? GetStringFromLump(lump) : FString());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "image.h"
|
||||
#include "textures.h"
|
||||
#include "palettecontainer.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
// Strife startup screen
|
||||
#define PEASANT_INDEX 0
|
||||
|
|
|
@ -217,7 +217,7 @@ static inline void drawframe(anim_t *anim, uint16_t framenumber)
|
|||
}
|
||||
|
||||
// <length> is the file size, for consistency checking.
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length)
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length)
|
||||
{
|
||||
if (memcmp(buffer, "LPF ", 4)) return -1;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ struct anim_t
|
|||
lp_descriptor * curlp; // header of large page currently in memory
|
||||
uint16_t * thepage; // buffer where current large page is loaded
|
||||
uint8_t imagebuffer[IMAGEBUFFERSIZE]; // buffer where anim frame is decoded
|
||||
uint8_t * buffer;
|
||||
const uint8_t * buffer;
|
||||
uint8_t pal[768];
|
||||
int32_t currentframe;
|
||||
};
|
||||
|
@ -105,7 +105,7 @@ struct anim_t
|
|||
//
|
||||
//****************************************************************************
|
||||
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length);
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length);
|
||||
|
||||
//****************************************************************************
|
||||
//
|
||||
|
|
|
@ -104,7 +104,7 @@ FAnmTexture::FAnmTexture (int lumpnum, int w, int h)
|
|||
void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
uint8_t *source = (uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
|
||||
anim_t anim;
|
||||
if (ANIM_LoadAnim(&anim, source, (int)lump.GetSize()) >= 0)
|
||||
|
|
|
@ -93,7 +93,7 @@ PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion)
|
|||
{
|
||||
int x, y;
|
||||
FileData data = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *indata = (const uint8_t *)data.GetMem();
|
||||
auto indata = data.GetBytes();
|
||||
|
||||
PalettedPixels Pixels(Width * Height);
|
||||
|
||||
|
|
|
@ -164,9 +164,7 @@ PalettedPixels FFontChar2::CreatePalettedPixels(int)
|
|||
|
||||
if (destSize < 0)
|
||||
{
|
||||
char name[9];
|
||||
fileSystem.GetFileShortName(name, SourceLump);
|
||||
name[8] = 0;
|
||||
auto name = fileSystem.GetFileShortName(SourceLump);
|
||||
I_FatalError("The font %s is corrupt", name);
|
||||
}
|
||||
return Pixels;
|
||||
|
|
|
@ -121,7 +121,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
|
|||
PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
|
||||
auto imgz = (const ImageHeader *)lump.GetMem();
|
||||
const uint8_t *data = (const uint8_t *)&imgz[1];
|
||||
|
||||
uint8_t *dest_p;
|
||||
|
|
|
@ -287,7 +287,7 @@ PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion)
|
|||
(cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) ||
|
||||
(cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1)))
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", fileSystem.GetFileFullPath(SourceLump).GetChars());
|
||||
Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", fileSystem.GetFileFullPath(SourceLump).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -382,7 +382,7 @@ PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion)
|
|||
}
|
||||
catch (int)
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", fileSystem.GetFileFullPath(SourceLump).GetChars());
|
||||
Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", fileSystem.GetFileFullPath(SourceLump).c_str());
|
||||
}
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
if (buff != NULL)
|
||||
|
@ -426,7 +426,7 @@ int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
(cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) ||
|
||||
(cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1)))
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", fileSystem.GetFileFullPath(SourceLump).GetChars());
|
||||
Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", fileSystem.GetFileFullPath(SourceLump).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -479,7 +479,7 @@ int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
}
|
||||
catch (int)
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", fileSystem.GetFileFullPath(SourceLump).GetChars());
|
||||
Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", fileSystem.GetFileFullPath(SourceLump).c_str());
|
||||
}
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
|
|
|
@ -148,7 +148,7 @@ int FQOITexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
size_t p = 14, run = 0;
|
||||
|
||||
size_t chunks_len = lump.GetSize() - 8;
|
||||
auto bytes = (const uint8_t*)lump.GetMem();
|
||||
auto bytes = lump.GetBytes();
|
||||
|
||||
for (int h = 0; h < Height; h++)
|
||||
{
|
||||
|
|
|
@ -155,9 +155,8 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
|
|||
Height = 200;
|
||||
|
||||
// Special case hack for Heretic's E2 end pic. This is not going to be exposed as an editing feature because the implications would be horrible.
|
||||
FString Name;
|
||||
fileSystem.GetFileShortName(Name, lumpnum);
|
||||
if (Name.CompareNoCase("E2END") == 0)
|
||||
auto Name = fileSystem.GetFileShortName(lumpnum);
|
||||
if (stricmp(Name, "E2END") == 0)
|
||||
{
|
||||
mPaletteLump = fileSystem.CheckNumForName("E2PAL");
|
||||
if (fileSystem.FileLength(mPaletteLump) < 768) mPaletteLump = -1;
|
||||
|
@ -174,7 +173,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
|
|||
PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
const uint8_t *source_p = source;
|
||||
uint8_t *dest_p;
|
||||
|
||||
|
@ -207,8 +206,8 @@ int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
{
|
||||
FileData lump = fileSystem.ReadFile(SourceLump);
|
||||
FileData plump = fileSystem.ReadFile(mPaletteLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
const uint8_t *psource = (const uint8_t *)plump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
auto psource = plump.GetBytes();
|
||||
PalEntry paldata[256];
|
||||
for (auto & pe : paldata)
|
||||
{
|
||||
|
|
|
@ -165,7 +165,7 @@ FStartupTexture::FStartupTexture (int lumpnum)
|
|||
bUseGamePalette = false;
|
||||
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
|
||||
// Initialize the bitmap palette.
|
||||
// the palette is static so that the notches can share it.
|
||||
|
@ -234,7 +234,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int
|
|||
PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
|
||||
|
||||
|
||||
|
@ -254,7 +254,7 @@ PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
|
|||
int FStartupTexture::CopyPixels(FBitmap *bmp, int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
PlanarToChunky((uint32_t*)bmp->GetPixels(), source + 48, startuppalette32, Width, Height);
|
||||
return 0;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height)
|
|||
PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
|
||||
|
||||
TArray<uint8_t> Work(Width*Height, true);
|
||||
|
@ -305,7 +305,7 @@ PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
|
|||
int FNotchTexture::CopyPixels(FBitmap *bmp, int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
|
||||
auto Work = (uint32_t*)bmp->GetPixels();
|
||||
for(int i = 0; i < Width * Height / 2; i++)
|
||||
|
@ -339,7 +339,7 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h)
|
|||
PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
const uint8_t *source = (const uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
PalettedPixels Pixels(Width*Height);
|
||||
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
|
||||
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source, Width, Height, Width, remap);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "texturemanager.h"
|
||||
#include "c_cvars.h"
|
||||
#include "hw_material.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
FTexture *CreateBrightmapTexture(FImageSource*);
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
#include "vectors.h"
|
||||
#include "animtexture.h"
|
||||
#include "formats/multipatchtexture.h"
|
||||
#include "basics.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
FTextureManager TexMan;
|
||||
|
||||
|
@ -451,7 +453,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype)
|
|||
{
|
||||
FString str;
|
||||
if (!usefullnames)
|
||||
fileSystem.GetFileShortName(str, lumpnum);
|
||||
str = fileSystem.GetFileShortName(lumpnum);
|
||||
else
|
||||
{
|
||||
auto fn = fileSystem.GetFileFullName(lumpnum);
|
||||
|
@ -485,7 +487,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype)
|
|||
}
|
||||
else
|
||||
{
|
||||
Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", fileSystem.GetFileFullPath(lumpnum).GetChars());
|
||||
Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", fileSystem.GetFileFullPath(lumpnum).c_str());
|
||||
return FTextureID(-1);
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +565,6 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype)
|
|||
{
|
||||
int firsttx = fileSystem.GetFirstEntry(wadnum);
|
||||
int lasttx = fileSystem.GetLastEntry(wadnum);
|
||||
FString Name;
|
||||
|
||||
if (!usefullnames)
|
||||
{
|
||||
|
@ -574,10 +575,9 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype)
|
|||
|
||||
for (; firsttx <= lasttx; ++firsttx)
|
||||
{
|
||||
auto Name = fileSystem.GetFileShortName(firsttx);
|
||||
if (fileSystem.GetFileNamespace(firsttx) == ns)
|
||||
{
|
||||
fileSystem.GetFileShortName(Name, firsttx);
|
||||
|
||||
if (fileSystem.CheckNumForName(Name, ns) == firsttx)
|
||||
{
|
||||
CreateTexture(firsttx, usetype);
|
||||
|
@ -618,7 +618,6 @@ void FTextureManager::AddHiresTextures (int wadnum)
|
|||
int firsttx = fileSystem.GetFirstEntry(wadnum);
|
||||
int lasttx = fileSystem.GetLastEntry(wadnum);
|
||||
|
||||
FString Name;
|
||||
TArray<FTextureID> tlist;
|
||||
|
||||
if (firsttx == -1 || lasttx == -1)
|
||||
|
@ -630,7 +629,7 @@ void FTextureManager::AddHiresTextures (int wadnum)
|
|||
{
|
||||
if (fileSystem.GetFileNamespace(firsttx) == ns_hires)
|
||||
{
|
||||
fileSystem.GetFileShortName (Name, firsttx);
|
||||
auto Name = fileSystem.GetFileShortName(firsttx);
|
||||
|
||||
if (fileSystem.CheckNumForName (Name, ns_hires) == firsttx)
|
||||
{
|
||||
|
@ -964,8 +963,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b
|
|||
for (int i= firsttx; i <= lasttx; i++)
|
||||
{
|
||||
bool skin = false;
|
||||
FString Name;
|
||||
fileSystem.GetFileShortName(Name, i);
|
||||
auto Name = fileSystem.GetFileShortName(i);
|
||||
|
||||
// Ignore anything not in the global namespace
|
||||
int ns = fileSystem.GetFileNamespace(i);
|
||||
|
@ -997,7 +995,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b
|
|||
if (iwad)
|
||||
{
|
||||
// We need to make an exception for font characters of the SmallFont coming from the IWAD to be able to construct the original font.
|
||||
if (Name.IndexOf("STCFN") != 0 && Name.IndexOf("FONTA") != 0) continue;
|
||||
if (strncmp(Name, "STCFN", 5) != 0 && strncmp(Name, "FONTA", 5) != 0) continue;
|
||||
force = true;
|
||||
}
|
||||
else continue;
|
||||
|
@ -1013,7 +1011,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b
|
|||
if (iwad)
|
||||
{
|
||||
// We need to make an exception for font characters of the SmallFont coming from the IWAD to be able to construct the original font.
|
||||
if (Name.IndexOf("STCFN") != 0 && Name.IndexOf("FONTA") != 0) continue;
|
||||
if (strncmp(Name, "STCFN", 5) != 0 && strncmp(Name, "FONTA", 5) != 0) continue;
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
|
@ -1110,7 +1108,7 @@ void FTextureManager::SortTexturesByType(int start, int end)
|
|||
|
||||
void FTextureManager::AddLocalizedVariants()
|
||||
{
|
||||
TArray<FolderEntry> content;
|
||||
std::vector<FolderEntry> content;
|
||||
fileSystem.GetFilesInFolder("localized/textures/", content, false);
|
||||
for (auto &entry : content)
|
||||
{
|
||||
|
@ -1513,9 +1511,7 @@ void FTextureManager::AdjustSpriteOffsets()
|
|||
if (fileSystem.GetFileContainer(i) > fileSystem.GetMaxIwadNum()) break; // we are past the IWAD
|
||||
if (fileSystem.GetFileNamespace(i) == ns_sprites && fileSystem.GetFileContainer(i) >= fileSystem.GetIwadNum() && fileSystem.GetFileContainer(i) <= fileSystem.GetMaxIwadNum())
|
||||
{
|
||||
char str[9];
|
||||
fileSystem.GetFileShortName(str, i);
|
||||
str[8] = 0;
|
||||
const char *str = fileSystem.GetFileShortName(i);
|
||||
FTextureID texid = TexMan.CheckForTexture(str, ETextureType::Sprite, 0);
|
||||
if (texid.isValid() && fileSystem.GetFileContainer(GetGameTexture(texid)->GetSourceLump()) > fileSystem.GetMaxIwadNum())
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "cmdlib.h"
|
||||
#include "fs_findfile.h"
|
||||
#include "filesystem.h"
|
||||
#include "files.h"
|
||||
#include "md5.h"
|
||||
|
||||
|
@ -1008,3 +1009,20 @@ void uppercopy(char* to, const char* from)
|
|||
to[i] = 0;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// GetStringFromLump
|
||||
//
|
||||
// Loads a zero terminated string from a lump in the file system
|
||||
//==========================================================================
|
||||
|
||||
FString GetStringFromLump(int lump)
|
||||
{
|
||||
FString ScriptBuffer;
|
||||
auto mem = fileSystem.OpenFileReader(lump);
|
||||
auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength());
|
||||
mem.Read(buff, mem.GetLength());
|
||||
buff[mem.GetLength()] = 0;
|
||||
ScriptBuffer.UnlockBuffer();
|
||||
return ScriptBuffer;
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ struct MD5Context;
|
|||
|
||||
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
|
||||
void uppercopy(char* to, const char* from);
|
||||
FString GetStringFromLump(int lump);
|
||||
|
||||
inline void fillshort(void* buff, size_t count, uint16_t clear)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int position, FConfigFile* config)
|
||||
bool D_AddFile(std::vector<std::string>& wadfiles, const char* file, bool check, int position, FConfigFile* config)
|
||||
{
|
||||
if (file == nullptr || *file == '\0')
|
||||
{
|
||||
|
@ -111,10 +111,10 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
|
|||
file = f;
|
||||
}
|
||||
|
||||
FString f = file;
|
||||
FixPathSeperator(f);
|
||||
if (position == -1) wadfiles.Push(f);
|
||||
else wadfiles.Insert(position, f);
|
||||
std::string f = file;
|
||||
for (auto& c : f) if (c == '\\') c = '/';
|
||||
if (position == -1) wadfiles.push_back(f);
|
||||
else wadfiles.insert(wadfiles.begin() + position, f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void D_AddWildFile(TArray<FString>& wadfiles, const char* value, const char *extension, FConfigFile* config)
|
||||
void D_AddWildFile(std::vector<std::string>& wadfiles, const char* value, const char *extension, FConfigFile* config)
|
||||
{
|
||||
if (value == nullptr || *value == '\0')
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ void D_AddWildFile(TArray<FString>& wadfiles, const char* value, const char *ext
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void D_AddConfigFiles(TArray<FString>& wadfiles, const char* section, const char* extension, FConfigFile *config)
|
||||
void D_AddConfigFiles(std::vector<std::string>& wadfiles, const char* section, const char* extension, FConfigFile *config)
|
||||
{
|
||||
if (config && config->SetSection(section))
|
||||
{
|
||||
|
@ -188,7 +188,7 @@ void D_AddConfigFiles(TArray<FString>& wadfiles, const char* section, const char
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void D_AddDirectory(TArray<FString>& wadfiles, const char* dir, const char *filespec, FConfigFile* config)
|
||||
void D_AddDirectory(std::vector<std::string>& wadfiles, const char* dir, const char *filespec, FConfigFile* config)
|
||||
{
|
||||
FileList list;
|
||||
if (ScanDirectory(list, dir, "*.wad", true))
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// Directory searching routines
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zstring.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class FConfigFile;
|
||||
|
||||
bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int position, FConfigFile* config);
|
||||
void D_AddWildFile(TArray<FString>& wadfiles, const char* value, const char *extension, FConfigFile* config);
|
||||
void D_AddConfigFiles(TArray<FString>& wadfiles, const char* section, const char* extension, FConfigFile* config);
|
||||
void D_AddDirectory(TArray<FString>& wadfiles, const char* dir, const char *filespec, FConfigFile* config);
|
||||
bool D_AddFile(std::vector<std::string>& wadfiles, const char* file, bool check, int position, FConfigFile* config);
|
||||
void D_AddWildFile(std::vector<std::string>& wadfiles, const char* value, const char *extension, FConfigFile* config);
|
||||
void D_AddConfigFiles(std::vector<std::string>& wadfiles, const char* section, const char* extension, FConfigFile* config);
|
||||
void D_AddDirectory(std::vector<std::string>& wadfiles, const char* dir, const char *filespec, FConfigFile* config);
|
||||
const char* BaseFileSearch(const char* file, const char* ext, bool lookfirstinprogdir, FConfigFile* config);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "m_swap.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
#include "m_png.h"
|
||||
|
||||
|
@ -663,9 +664,8 @@ int V_GetColorFromString(const char* cstr, FScriptPosition* sc)
|
|||
|
||||
FString V_GetColorStringByName(const char* name, FScriptPosition* sc)
|
||||
{
|
||||
FileData rgbNames;
|
||||
char* rgbEnd;
|
||||
char* rgb, * endp;
|
||||
const char* rgbEnd;
|
||||
const char* rgb, * endp;
|
||||
int rgblump;
|
||||
int c[3], step;
|
||||
size_t namelen;
|
||||
|
@ -680,9 +680,9 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc)
|
|||
return FString();
|
||||
}
|
||||
|
||||
rgbNames = fileSystem.ReadFile(rgblump);
|
||||
rgb = (char*)rgbNames.GetMem();
|
||||
rgbEnd = rgb + fileSystem.FileLength(rgblump);
|
||||
auto rgbNames = fileSystem.ReadFile(rgblump);
|
||||
rgb = rgbNames.GetString();
|
||||
rgbEnd = rgb + rgbNames.GetSize();
|
||||
step = 0;
|
||||
namelen = strlen(name);
|
||||
|
||||
|
@ -705,7 +705,7 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc)
|
|||
}
|
||||
else if (step < 3)
|
||||
{ // collect RGB values
|
||||
c[step++] = strtoul(rgb, &endp, 10);
|
||||
c[step++] = strtoul(rgb, (char**)&endp, 10);
|
||||
if (endp == rgb)
|
||||
{
|
||||
break;
|
||||
|
@ -930,7 +930,7 @@ int ReadPalette(int lumpnum, uint8_t* buffer)
|
|||
return 0;
|
||||
}
|
||||
FileData lump = fileSystem.ReadFile(lumpnum);
|
||||
uint8_t* lumpmem = (uint8_t*)lump.GetMem();
|
||||
auto lumpmem = lump.GetBytes();
|
||||
memset(buffer, 0, 768);
|
||||
|
||||
FileReader fr;
|
||||
|
|
|
@ -145,9 +145,6 @@ public:
|
|||
FString (const char *head, const char *tail);
|
||||
FString (char head, const FString &tail);
|
||||
|
||||
// Other constructors
|
||||
FString (ELumpNum); // Create from a lump
|
||||
|
||||
~FString ();
|
||||
|
||||
// Discard string's contents, create a new buffer, and lock it.
|
||||
|
|
|
@ -1079,8 +1079,6 @@ int ConCompiler::parsecommand()
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto data = fileSystem.ReadFile(fni);
|
||||
|
||||
temp_current_file = currentsourcefile;
|
||||
currentsourcefile = fni;
|
||||
|
||||
|
@ -1089,7 +1087,8 @@ int ConCompiler::parsecommand()
|
|||
temp_ifelse_check = checking_ifelse;
|
||||
checking_ifelse = 0;
|
||||
auto origtptr = textptr;
|
||||
textptr = data.GetString();
|
||||
auto textstring = GetStringFromLump(fni);
|
||||
textptr = textstring.GetChars();
|
||||
|
||||
do
|
||||
done = parsecommand();
|
||||
|
@ -3106,8 +3105,8 @@ void ConCompiler::compilecon(const char *filenam)
|
|||
I_FatalError("%s: Missing con file(s).", filenam);
|
||||
}
|
||||
Printf("Compiling: '%s'.\n", filenam);
|
||||
auto data = fileSystem.ReadFile(currentsourcefile);
|
||||
textptr = data.GetString();
|
||||
auto textstring = GetStringFromLump(currentsourcefile);
|
||||
textptr = textstring.GetChars();
|
||||
|
||||
line_number = 1;
|
||||
errorcount = warningcount = 0;
|
||||
|
|
Loading…
Reference in a new issue