- enabled the Blood RFS parser.

Seems to work but there's not that much material to use it on so the mileage may vary.
This commit is contained in:
Christoph Oelckers 2020-01-22 21:09:45 +01:00
parent 3ed7856f53
commit bbc145cbee
6 changed files with 94 additions and 89 deletions

View file

@ -152,7 +152,7 @@ private:
char _fileName[BMAX_PATH]; // [30] char _fileName[BMAX_PATH]; // [30]
public: public:
int Open(const char *fileName); int Open(int lumpnum);
void Close(); void Close();
void Increment(); void Increment();
void SkipBeyondValue(char value); void SkipBeyondValue(char value);
@ -162,13 +162,11 @@ public:
void UnsetMark(); void UnsetMark();
}; };
int RFS::Open(const char *fileName) int RFS::Open(int lumpnum)
{ {
strcpy(_fileName, fileName); auto hFile = fileSystem.OpenFileReader(lumpnum);
auto hFile = fileSystem.OpenFileReader(fileName, 0);
if (!hFile.isOpen()) { if (!hFile.isOpen()) {
initprintf("BARF: Error opening file %s", _fileName); initprintf("BARF: Error opening file %d", lumpnum);
return 1; return 1;
} }
@ -176,7 +174,7 @@ int RFS::Open(const char *fileName)
buffer.Resize(fileSize); buffer.Resize(fileSize);
_ptr = buffer.Data(); _ptr = buffer.Data();
if (_ptr == NULL) { if (_ptr == NULL) {
initprintf("BARF: Not enough memory to read %s", _fileName); initprintf("BARF: Not enough memory to read %d", lumpnum);
return 1; return 1;
} }
@ -235,30 +233,32 @@ void RFS::UnsetMark()
void RFS::ScriptError(const char *message) void RFS::ScriptError(const char *message)
{ {
// TODO // TODO
TArray<char> msg;
char *p = _pStartLine; char *p = _pStartLine;
while (*p != '\n') while (*p != '\n')
{ {
if (isprint(*p)) if (isprint(*p))
putchar(*p); msg.Push(*p);
else else
putchar(' '); msg.Push(' ');
p++; p++;
} }
putchar('\n'); msg.Push('\n');
p = _pStartLine; p = _pStartLine;
while (p < _pMark) while (p < _pMark)
{ {
putchar(' '); msg.Push(' ');
p++; 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() uint8_t RFS::GetNextTag()
@ -447,21 +447,21 @@ uint8_t RFS::GetNextTag()
// qAssert(1==0); // TODO - what to return here // qAssert(1==0); // TODO - what to return here
} }
void ParseScript(const char *scriptFileName) void ParseScript(int lumpnum)
{ {
char text[256]; char text[256];
char char256_1[256]; char char256_1[256];
char char256_2[256]; char char256_2[256];
char fileName[BMAX_PATH]; char fileName[BMAX_PATH];
char inp[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; RFS rfs;
// AddExtension(name, ".RFS"); // AddExtension(name, ".RFS");
if (rfs.Open(scriptFileName)) if (rfs.Open(lumpnum))
{ {
return; return;
} }
@ -706,7 +706,9 @@ void ParseScript(const char *scriptFileName)
} }
else else
{ {
ParseScript(scriptBuffer); // too dangerous if we want to cumulatively collect all RFS files
//fileSystem.Rehash();
//ParseScript(scriptBuffer);
} }
} }
break; break;
@ -801,32 +803,32 @@ void ParseScript(const char *scriptFileName)
// loc_12471: // loc_12471:
if (tag != kTagColon) // marked orange in IDA 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) { if (tag == kTagColon) {
break; break;
}
}
else if (tag == kTagPrelock)
{
nFlags |= DICT_LOCK;
tag = rfs.GetNextTag();
if (tag == kTagColon) {
break;
}
}
else {
rfs.ScriptError("':' expected");
rfs.SkipBeyondValue(';');
goto START; // FIXME
} }
} }
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; nBytes = 0;
@ -838,24 +840,24 @@ void ParseScript(const char *scriptFileName)
switch (tag) switch (tag)
{ {
case kTagString: case kTagString:
{ {
memcpy(&buffer[nBytes], scriptBuffer, strlen(scriptBuffer) + 1); memcpy(&buffer[nBytes], scriptBuffer, strlen(scriptBuffer) + 1);
nBytes += strlen(scriptBuffer) + 1; nBytes += strlen(scriptBuffer) + 1;
break; break;
} }
case kTagConstant: case kTagConstant:
{ {
memcpy(&buffer[nBytes], &scriptValue, sizeof(scriptValue)); memcpy(&buffer[nBytes], &scriptValue, sizeof(scriptValue));
nBytes += sizeof(scriptValue); nBytes += sizeof(scriptValue);
break; break;
} }
default: default:
{ {
rfs.ScriptError("Constant expected"); rfs.ScriptError("Constant expected");
rfs.SkipBeyondValue(';'); rfs.SkipBeyondValue(';');
goto START; // FIXME goto START; // FIXME
} }
} }
tag = rfs.GetNextTag(); tag = rfs.GetNextTag();
@ -884,9 +886,9 @@ void ParseScript(const char *scriptFileName)
rfs.Close(); 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 zFilename[BMAX_PATH];
char zType[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); 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 END_BLD_NS

View file

@ -1125,17 +1125,17 @@ void ClockStrobe()
//gGameClock++; //gGameClock++;
} }
void ReadAllRFS();
int GameInterface::app_main() int GameInterface::app_main()
{ {
memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS)); memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS));
gGameOptions.nMonsterSettings = !userConfig.nomonsters; gGameOptions.nMonsterSettings = !userConfig.nomonsters;
bQuickStart = userConfig.nologo; bQuickStart = userConfig.nologo;
ReadAllRFS();
#ifdef USE_QHEAP #ifdef USE_QHEAP
Resource::heap = new QHeap(nMaxAlloc); Resource::heap = new QHeap(nMaxAlloc);
#endif #endif
//gSysRes.Init(pUserRFF ? pUserRFF : "BLOOD.RFF");
//gGuiRes.Init("GUI.RFF");
HookReplaceFunctions(); HookReplaceFunctions();

View file

@ -100,7 +100,7 @@ void FileSystem::DeleteAll ()
// //
//========================================================================== //==========================================================================
int FileSystem::InitMultipleFiles (TArray<FString> &filenames, const TArray<FString> &deletelumps, int maingamefiles) int FileSystem::InitMultipleFiles(TArray<FString>& filenames, const TArray<FString>& deletelumps, int maingamefiles)
{ {
int numfiles; int numfiles;
@ -108,7 +108,7 @@ int FileSystem::InitMultipleFiles (TArray<FString> &filenames, const TArray<FStr
DeleteAll(); DeleteAll();
numfiles = 0; numfiles = 0;
for(unsigned i=0;i<filenames.Size(); i++) for (unsigned i = 0; i < filenames.Size(); i++)
{ {
int baselump = NumEntries; int baselump = NumEntries;
bool nosubdirflag = false; bool nosubdirflag = false;
@ -118,16 +118,21 @@ int FileSystem::InitMultipleFiles (TArray<FString> &filenames, const TArray<FStr
fn++; fn++;
nosubdirflag = true; nosubdirflag = true;
} }
AddFile (filenames[i], nullptr, nosubdirflag); AddFile(filenames[i], nullptr, nosubdirflag);
} }
NumEntries = FileInfo.Size(); NumEntries = FileInfo.Size();
if (NumEntries == 0) if (NumEntries == 0)
{ {
return 0; return 0;
} }
DeleteStuff(deletelumps, maingamefiles); DeleteStuff(deletelumps, maingamefiles);
Rehash();
return NumEntries;
}
void FileSystem::Rehash()
{
// [RH] Set up hash table // [RH] Set up hash table
Hashes.Resize(NumLookupModes * 2 * NumEntries); Hashes.Resize(NumLookupModes * 2 * NumEntries);
for (int i = 0; i < NumLookupModes; i++) for (int i = 0; i < NumLookupModes; i++)
@ -138,7 +143,6 @@ int FileSystem::InitMultipleFiles (TArray<FString> &filenames, const TArray<FStr
InitHashChains (); InitHashChains ();
FileInfo.ShrinkToFit(); FileInfo.ShrinkToFit();
Files.ShrinkToFit(); Files.ShrinkToFit();
return NumEntries;
} }
//========================================================================== //==========================================================================
@ -480,22 +484,7 @@ void FileSystem::AddLump(FResourceLump *lump)
{ {
FileRecord rec = { -1, lump}; FileRecord rec = { -1, lump};
FileInfo.Push(rec); FileInfo.Push(rec);
NumEntries++;
for (int l = 0; l < NumLookupModes; l++)
{
int hash = 0;
if (l != (int)ELookupMode::IdWithType && lump->LumpName[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;
}
} }
//========================================================================== //==========================================================================
@ -996,11 +985,6 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int flags)
return true; 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. // Create a clone of the resource to give it new lookup properties.
auto newlump = new FClonedLump(FileInfo[lump].lump); auto newlump = new FClonedLump(FileInfo[lump].lump);
newlump->LumpNameSetup(filename.GetChars()); newlump->LumpNameSetup(filename.GetChars());

View file

@ -83,6 +83,7 @@ public:
int InitMultipleFiles (TArray<FString> &filenames, const TArray<FString> &todelete, int maingamefiles); int InitMultipleFiles (TArray<FString> &filenames, const TArray<FString> &todelete, int maingamefiles);
void DeleteStuff(const TArray<FString>& deletelumps, int numgamefiles); void DeleteStuff(const TArray<FString>& deletelumps, int numgamefiles);
void Rehash();
void AddFile (const char *filename, FileReader *wadinfo = NULL, bool nosubdirflag = false); void AddFile (const char *filename, FileReader *wadinfo = NULL, bool nosubdirflag = false);
void AddAdditionalFile(const char* filename, FileReader* wadinfo = NULL) {} void AddAdditionalFile(const char* filename, FileReader* wadinfo = NULL) {}

View file

@ -171,6 +171,7 @@ struct FMemoryLump : public FResourceLump
{ {
FMemoryLump(const void* data, int length) FMemoryLump(const void* data, int length)
{ {
LumpSize = length;
Cache.Resize(length); Cache.Resize(length);
memcpy(Cache.Data(), data, length); memcpy(Cache.Data(), data, length);
} }

View file

@ -18,6 +18,7 @@ xx(WAV)
xx(OGG) xx(OGG)
xx(FLAC) xx(FLAC)
xx(VOC) xx(VOC)
xx(RFS)
xx(Controlmessage) xx(Controlmessage)
xx(MainMenu) xx(MainMenu)