From bbc145cbee168ce8d79c191f0b45052fba156522 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Jan 2020 21:09:45 +0100 Subject: [PATCH] - enabled the Blood RFS parser. Seems to work but there's not that much material to use it on so the mileage may vary. --- source/blood/src/barf.cpp | 138 +++++++++++++----------- source/blood/src/blood.cpp | 6 +- source/common/filesystem/filesystem.cpp | 36 ++----- source/common/filesystem/filesystem.h | 1 + source/common/filesystem/resourcefile.h | 1 + source/common/utility/namedef.h | 1 + 6 files changed, 94 insertions(+), 89 deletions(-) diff --git a/source/blood/src/barf.cpp b/source/blood/src/barf.cpp index 84cfbd697..21dba183e 100644 --- a/source/blood/src/barf.cpp +++ b/source/blood/src/barf.cpp @@ -152,7 +152,7 @@ private: char _fileName[BMAX_PATH]; // [30] public: - int Open(const char *fileName); + int Open(int lumpnum); void Close(); void Increment(); void SkipBeyondValue(char value); @@ -162,13 +162,11 @@ public: void UnsetMark(); }; -int RFS::Open(const char *fileName) +int RFS::Open(int lumpnum) { - strcpy(_fileName, fileName); - - auto hFile = fileSystem.OpenFileReader(fileName, 0); + auto hFile = fileSystem.OpenFileReader(lumpnum); if (!hFile.isOpen()) { - initprintf("BARF: Error opening file %s", _fileName); + initprintf("BARF: Error opening file %d", lumpnum); return 1; } @@ -176,7 +174,7 @@ int RFS::Open(const char *fileName) buffer.Resize(fileSize); _ptr = buffer.Data(); if (_ptr == NULL) { - initprintf("BARF: Not enough memory to read %s", _fileName); + initprintf("BARF: Not enough memory to read %d", lumpnum); return 1; } @@ -235,30 +233,32 @@ void RFS::UnsetMark() void RFS::ScriptError(const char *message) { // TODO + TArray msg; char *p = _pStartLine; while (*p != '\n') { if (isprint(*p)) - putchar(*p); + msg.Push(*p); else - putchar(' '); + msg.Push(' '); p++; } - putchar('\n'); + msg.Push('\n'); p = _pStartLine; while (p < _pMark) { - putchar(' '); + msg.Push(' '); p++; } - puts("^"); + msg.Push('^'); + msg.Push(0); - initprintf("Error in %s line %d: %s\n\n", _fileName, _curLine, message); + initprintf("Error in %s line %d: %s\n\n%s", _fileName, _curLine, message, msg.Data()); } uint8_t RFS::GetNextTag() @@ -447,21 +447,21 @@ uint8_t RFS::GetNextTag() // qAssert(1==0); // TODO - what to return here } -void ParseScript(const char *scriptFileName) +void ParseScript(int lumpnum) { char text[256]; char char256_1[256]; char char256_2[256]; char fileName[BMAX_PATH]; char inp[BMAX_PATH]; - char zScriptDirectory[BMAX_PATH], zTemp1[BMAX_PATH], zTemp2[BMAX_PATH]; + //char zScriptDirectory[BMAX_PATH], zTemp1[BMAX_PATH], zTemp2[BMAX_PATH]; - SplitPath(scriptFileName, zScriptDirectory, zTemp1, zTemp2); + //SplitPath(scriptFileName, zScriptDirectory, zTemp1, zTemp2); RFS rfs; // AddExtension(name, ".RFS"); - if (rfs.Open(scriptFileName)) + if (rfs.Open(lumpnum)) { return; } @@ -706,7 +706,9 @@ void ParseScript(const char *scriptFileName) } else { - ParseScript(scriptBuffer); + // too dangerous if we want to cumulatively collect all RFS files + //fileSystem.Rehash(); + //ParseScript(scriptBuffer); } } break; @@ -801,32 +803,32 @@ void ParseScript(const char *scriptFileName) // loc_12471: if (tag != kTagColon) // marked orange in IDA { - while (1) + while (1) + { + if (tag == kTagPreload) { - if (tag == kTagPreload) - { - nFlags |= DICT_LOAD; - tag = rfs.GetNextTag(); + nFlags |= DICT_LOAD; + tag = rfs.GetNextTag(); - if (tag == kTagColon) { - break; - } - } - else if (tag == kTagPrelock) - { - nFlags |= DICT_LOCK; - tag = rfs.GetNextTag(); - - if (tag == kTagColon) { - break; - } - } - else { - rfs.ScriptError("':' expected"); - rfs.SkipBeyondValue(';'); - goto START; // FIXME + if (tag == kTagColon) { + break; } } + else if (tag == kTagPrelock) + { + nFlags |= DICT_LOCK; + tag = rfs.GetNextTag(); + + if (tag == kTagColon) { + break; + } + } + else { + rfs.ScriptError("':' expected"); + rfs.SkipBeyondValue(';'); + goto START; // FIXME + } + } } nBytes = 0; @@ -838,24 +840,24 @@ void ParseScript(const char *scriptFileName) switch (tag) { - case kTagString: - { - memcpy(&buffer[nBytes], scriptBuffer, strlen(scriptBuffer) + 1); - nBytes += strlen(scriptBuffer) + 1; - break; - } - case kTagConstant: - { - memcpy(&buffer[nBytes], &scriptValue, sizeof(scriptValue)); - nBytes += sizeof(scriptValue); - break; - } - default: - { - rfs.ScriptError("Constant expected"); - rfs.SkipBeyondValue(';'); - goto START; // FIXME - } + case kTagString: + { + memcpy(&buffer[nBytes], scriptBuffer, strlen(scriptBuffer) + 1); + nBytes += strlen(scriptBuffer) + 1; + break; + } + case kTagConstant: + { + memcpy(&buffer[nBytes], &scriptValue, sizeof(scriptValue)); + nBytes += sizeof(scriptValue); + break; + } + default: + { + rfs.ScriptError("Constant expected"); + rfs.SkipBeyondValue(';'); + goto START; // FIXME + } } tag = rfs.GetNextTag(); @@ -884,9 +886,9 @@ void ParseScript(const char *scriptFileName) rfs.Close(); } -void addMemoryResource(char *filePath, char flags, int ID) +void addMemoryResource(char* filePath, char flags, int ID) { - char zDirectory[BMAX_PATH]; + char zDirectory[BMAX_PATH]; char zFilename[BMAX_PATH]; char zType[BMAX_PATH]; @@ -895,4 +897,20 @@ void addMemoryResource(char *filePath, char flags, int ID) fileSystem.AddFromBuffer(zFilename, zType, buffer, nBytes, ID, flags); } + +void ReadAllRFS() +{ + bool found = false; + auto numf = fileSystem.GetNumEntries(); + for (int i = 0; i < numf; i++) + { + auto rl = fileSystem.GetResourceType(i); + if (rl == NAME_RFS) + { + ParseScript(i); + found = true; + } + } + if (found) fileSystem.Rehash(); +} END_BLD_NS diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 7cb521331..c35da5788 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -1125,17 +1125,17 @@ void ClockStrobe() //gGameClock++; } +void ReadAllRFS(); + int GameInterface::app_main() { memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS)); gGameOptions.nMonsterSettings = !userConfig.nomonsters; bQuickStart = userConfig.nologo; - + ReadAllRFS(); #ifdef USE_QHEAP Resource::heap = new QHeap(nMaxAlloc); #endif - //gSysRes.Init(pUserRFF ? pUserRFF : "BLOOD.RFF"); - //gGuiRes.Init("GUI.RFF"); HookReplaceFunctions(); diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index ee086b958..373edd0fd 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -100,7 +100,7 @@ void FileSystem::DeleteAll () // //========================================================================== -int FileSystem::InitMultipleFiles (TArray &filenames, const TArray &deletelumps, int maingamefiles) +int FileSystem::InitMultipleFiles(TArray& filenames, const TArray& deletelumps, int maingamefiles) { int numfiles; @@ -108,7 +108,7 @@ int FileSystem::InitMultipleFiles (TArray &filenames, const TArray &filenames, const TArray &filenames, const TArrayLumpName[l] != NAME_None) - { - hash = int(lump->LumpName[l]) % NumEntries; - } - else if (lump->ResourceId >= 0) - { - hash = int(lump->ResourceId) % NumEntries; - } - auto nh = FileInfo.Size() - 1; - NextFileIndex[l][nh] = FirstFileIndex[l][hash]; - FirstFileIndex[l][hash] = nh; - } + NumEntries++; } //========================================================================== @@ -996,11 +985,6 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int flags) return true; } - // Check if a lump with this name already exists. - // Blood does not allow re-replacing external resources. - auto prevlump = FindFile(filename); - if (prevlump >= 0 && FileInfo[prevlump].rfnum == -1) return true; - // Create a clone of the resource to give it new lookup properties. auto newlump = new FClonedLump(FileInfo[lump].lump); newlump->LumpNameSetup(filename.GetChars()); diff --git a/source/common/filesystem/filesystem.h b/source/common/filesystem/filesystem.h index e89f31430..3c9a5eedd 100644 --- a/source/common/filesystem/filesystem.h +++ b/source/common/filesystem/filesystem.h @@ -83,6 +83,7 @@ public: int InitMultipleFiles (TArray &filenames, const TArray &todelete, int maingamefiles); void DeleteStuff(const TArray& deletelumps, int numgamefiles); + void Rehash(); void AddFile (const char *filename, FileReader *wadinfo = NULL, bool nosubdirflag = false); void AddAdditionalFile(const char* filename, FileReader* wadinfo = NULL) {} diff --git a/source/common/filesystem/resourcefile.h b/source/common/filesystem/resourcefile.h index 922416c04..6c3b59ea0 100644 --- a/source/common/filesystem/resourcefile.h +++ b/source/common/filesystem/resourcefile.h @@ -171,6 +171,7 @@ struct FMemoryLump : public FResourceLump { FMemoryLump(const void* data, int length) { + LumpSize = length; Cache.Resize(length); memcpy(Cache.Data(), data, length); } diff --git a/source/common/utility/namedef.h b/source/common/utility/namedef.h index f63706660..535d6a20f 100644 --- a/source/common/utility/namedef.h +++ b/source/common/utility/namedef.h @@ -18,6 +18,7 @@ xx(WAV) xx(OGG) xx(FLAC) xx(VOC) +xx(RFS) xx(Controlmessage) xx(MainMenu)