From 30b21b2eea36c17c82e41285348234cd867c2104 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 12 Nov 2009 02:47:28 +0000 Subject: [PATCH] - Removed the one embedded DeHackEd lump restriction. SVN r1972 (trunk) --- docs/rh-log.txt | 1 + src/d_dehacked.cpp | 166 ++++++++++++++++++--------------------------- src/d_dehacked.h | 5 +- src/d_main.cpp | 23 ++++--- src/w_wad.cpp | 1 + 5 files changed, 83 insertions(+), 113 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 5c5a5d8c1..0cd8d0b35 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,5 @@ November 11, 2009 +- Removed the one embedded DeHackEd lump restriction. - Fixed: nofreeaim in P_SpawnPlayerMissile() was broken. - Fixed: MBF sky Y offsets were ignored. X offsets should also be applied to the sky cylinder, not the screen like Hexen scrolling skies. diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index b4901bc8a..29b0e22bb 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -285,6 +285,7 @@ static int PatchPars (int); static int PatchCodePtrs (int); static int PatchMusic (int); static int DoInclude (int); +static bool DoDehPatch(); static const struct { const char *name; @@ -2260,7 +2261,7 @@ static int DoInclude (int dummy) } } - DoDehPatch (path, false); + D_LoadDehFile(path); if (data != path) { @@ -2280,105 +2281,70 @@ static int DoInclude (int dummy) return GetLine(); } -void DoDehPatch (const char *patchfile, bool autoloading, int lump) +int D_LoadDehLumps() { - char file[256]; - int cont; - int filelen = 0; // Be quiet, gcc + int lastlump = 0, lumpnum, count = 0; - PatchFile = NULL; - PatchName = NULL; - - if (lump < 0) + while ((lumpnum = Wads.FindLump("DEHACKED", &lastlump)) >= 0) { - lump = Wads.CheckNumForName ("DEHACKED"); + count += D_LoadDehLump(lumpnum); } + return count; +} - if (lump >= 0 && autoloading) +bool D_LoadDehLump(int lumpnum) +{ + int filelen = Wads.LumpLength(lumpnum); + + PatchName = copystring(Wads.GetLumpFullPath(lumpnum)); + PatchFile = new char[filelen + 1]; + Wads.ReadLump(lumpnum, PatchFile); + PatchFile[filelen] = '\0'; // terminate with a '\0' character + return DoDehPatch(); +} + +bool D_LoadDehFile(const char *patchfile) +{ + FILE *deh; + + deh = fopen(patchfile, "rb"); + if (deh != NULL) { - // Execute the DEHACKED lump as a patch. - strcpy (file, "DEHACKED lump"); - filelen = Wads.LumpLength (lump); - if ( (PatchFile = new char[filelen + 1]) ) - { - Wads.ReadLump (lump, PatchFile); - } - else - { - Printf ("Not enough memory to apply patch\n"); - return; - } - } - else if (patchfile) - { - // Try to use patchfile as a patch. - FILE *deh; + int filelen = Q_filelength(deh); - strcpy (file, patchfile); - FixPathSeperator (file); - DefaultExtension (file, ".deh"); - - if ( !(deh = fopen (file, "rb")) ) - { - strcpy (file, patchfile); - FixPathSeperator (file); - DefaultExtension (file, ".bex"); - deh = fopen (file, "rb"); - } - - if (deh) - { - filelen = Q_filelength (deh); - if ( (PatchFile = new char[filelen + 1]) ) - { - fread (PatchFile, 1, filelen, deh); - fclose (deh); - PatchName = copystring (patchfile); - FixPathSeperator (PatchName); - } - } - - if (!PatchFile) - { - // Couldn't find it on disk, try reading it from a lump - lump = Wads.CheckNumForFullName(patchfile, true); - if (lump == -1) - { - // Compatibility fallback. It's just here because - // some WAD may need it. Should be deleted it it can - // be confirmed that nothing uses this case. - FString filebase(ExtractFileBase (patchfile)); - lump = Wads.CheckNumForName (filebase); - } - if (lump >= 0) - { - filelen = Wads.LumpLength (lump); - if ( (PatchFile = new char[filelen + 1]) ) - { - Wads.ReadLump (lump, PatchFile); - } - else - { - Printf ("Not enough memory to apply patch\n"); - return; - } - } - } - - if (!PatchFile) - { - Printf ("Could not open DeHackEd patch \"%s\"\n", file); - return; - } + PatchName = copystring(patchfile); + PatchFile = new char[filelen + 1]; + fread(PatchFile, 1, filelen, deh); + fclose(deh); + PatchFile[filelen] = '\0'; // terminate with a '\0' character + return DoDehPatch(); } else { - // Nothing to do. - return; + // Couldn't find it in the filesystem; try from a lump instead. + int lumpnum = Wads.CheckNumForFullName(patchfile, true); + if (lumpnum < 0) + { + // Compatibility fallback. It's just here because + // some WAD may need it. Should be deleted if it can + // be confirmed that nothing uses this case. + FString filebase(ExtractFileBase(patchfile)); + lumpnum = Wads.CheckNumForName(filebase); + } + if (lumpnum >= 0) + { + return D_LoadDehLump(lumpnum); + } } + Printf ("Could not open DeHackEd patch \"%s\"\n", patchfile); + return false; +} - // End file with a NULL for our parser - PatchFile[filelen] = 0; +static bool DoDehPatch() +{ + Printf("Adding dehacked patch %s\n", PatchName); + + int cont; dversion = pversion = -1; cont = 0; @@ -2386,10 +2352,10 @@ void DoDehPatch (const char *patchfile, bool autoloading, int lump) { if (PatchFile[25] < '3') { - if (PatchName != NULL) delete[] PatchName; + delete[] PatchName; delete[] PatchFile; - Printf (PRINT_BOLD, "\"%s\" is an old and unsupported DeHackEd patch\n", file); - return; + Printf (PRINT_BOLD, "\"%s\" is an old and unsupported DeHackEd patch\n", PatchFile); + return false; } PatchPt = strchr (PatchFile, '\n'); while ((cont = GetLine()) == 1) @@ -2399,10 +2365,10 @@ void DoDehPatch (const char *patchfile, bool autoloading, int lump) } if (!cont || dversion == -1 || pversion == -1) { - if (PatchName != NULL) delete[] PatchName; + delete[] PatchName; delete[] PatchFile; - Printf (PRINT_BOLD, "\"%s\" is not a DeHackEd patch file\n", file); - return; + Printf (PRINT_BOLD, "\"%s\" is not a DeHackEd patch file\n", PatchFile); + return false; } } else @@ -2412,7 +2378,7 @@ void DoDehPatch (const char *patchfile, bool autoloading, int lump) pversion = 6; PatchPt = PatchFile; while ((cont = GetLine()) == 1) - ; + {} } if (pversion != 6) @@ -2439,10 +2405,10 @@ void DoDehPatch (const char *patchfile, bool autoloading, int lump) if (!LoadDehSupp ()) { Printf ("Could not load DEH support data\n"); - if (PatchName != NULL) delete[] PatchName; - delete[] PatchFile; UnloadDehSupp (); - return; + delete[] PatchName; + delete[] PatchFile; + return false; } do @@ -2459,10 +2425,10 @@ void DoDehPatch (const char *patchfile, bool autoloading, int lump) } while (cont); UnloadDehSupp (); - if (PatchName != NULL) delete[] PatchName; + delete[] PatchName; delete[] PatchFile; Printf ("Patch installed\n"); - + return true; } static inline bool CompareLabel (const char *want, const BYTE *have) diff --git a/src/d_dehacked.h b/src/d_dehacked.h index 6967c083d..67473f071 100644 --- a/src/d_dehacked.h +++ b/src/d_dehacked.h @@ -56,8 +56,9 @@ public: bool droppedbymonster; }; - -void DoDehPatch (const char *patchfile, bool autoloading, int lumpnum=-1); +int D_LoadDehLumps(); +bool D_LoadDehLump(int lumpnum); +bool D_LoadDehFile(const char *filename); void FinishDehPatch (); #endif //__D_DEHACK_H__ diff --git a/src/d_main.cpp b/src/d_main.cpp index cad92cce6..a06340f68 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1483,9 +1483,9 @@ bool ConsiderPatches (const char *arg, const char *ext) for (i = 0; i < files->NumArgs(); ++i) { if ( (f = BaseFileSearch (files->GetArg (i), ".deh")) ) - DoDehPatch (f, false); + D_LoadDehFile(f); else if ( (f = BaseFileSearch (files->GetArg (i), ".bex")) ) - DoDehPatch (f, false); + D_LoadDehFile(f); } noDef = true; } @@ -1947,13 +1947,12 @@ void D_DoomMain (void) DecalLibrary.Clear (); DecalLibrary.ReadAllDecals (); - // [RH] Try adding .deh and .bex files on the command line. + // [RH] Add any .deh and .bex files on the command line. // If there are none, try adding any in the config file. + // Note that the command line overrides defaults from the config. - if (!ConsiderPatches ("-deh", ".deh") && - !ConsiderPatches ("-bex", ".bex") && - (gameinfo.gametype == GAME_Doom) && - GameConfig->SetSection ("Doom.DefaultDehacked")) + if ((ConsiderPatches("-deh", ".deh") | ConsiderPatches("-bex", ".bex")) == 0 && + gameinfo.gametype == GAME_Doom && GameConfig->SetSection ("Doom.DefaultDehacked")) { const char *key; const char *value; @@ -1963,17 +1962,19 @@ void D_DoomMain (void) if (stricmp (key, "Path") == 0 && FileExists (value)) { Printf ("Applying patch %s\n", value); - DoDehPatch (value, true); + D_LoadDehFile(value); } } } - DoDehPatch (NULL, true); // See if there's a patch in a PWAD - FinishDehPatch (); // Create replacements for dehacked pickups + // Load embedded Dehacked patches + D_LoadDehLumps(); + + // Create replacements for dehacked pickups + FinishDehPatch(); FActorInfo::StaticSetActorNums (); - // [RH] User-configurable startup strings. Because BOOM does. static const char *startupString[5] = { "STARTUP1", "STARTUP2", "STARTUP3", "STARTUP4", "STARTUP5" diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 4d1d554d9..3594c8b3f 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -832,6 +832,7 @@ int FWadCollection::FindLump (const char *name, int *lastlump, bool anyns) uppercopy (name8, name); + assert(lastlump != NULL && *lastlump >= 0); lump_p = &LumpInfo[*lastlump]; while (lump_p < &LumpInfo[NumLumps]) {