Skip bex strings for freedoom if language lump is present (#2682)

This commit is contained in:
Ricardo Luís Vaz Silva 2024-08-21 00:08:57 -03:00 committed by GitHub
parent 4d18380956
commit 70cf707251
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 96 additions and 66 deletions

View file

@ -138,6 +138,10 @@ void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize,
{ {
iwad->nokeyboardcheats = true; iwad->nokeyboardcheats = true;
} }
else if (sc.Compare("SkipBexStringsIfLanguage"))
{
iwad->SkipBexStringsIfLanguage = true;
}
else if (sc.Compare("Compatibility")) else if (sc.Compare("Compatibility"))
{ {
sc.MustGetStringName("="); sc.MustGetStringName("=");

View file

@ -1782,7 +1782,7 @@ bool ConsiderPatches (const char *arg)
if ( (f = BaseFileSearch(args[i].GetChars(), ".deh", false, GameConfig)) || if ( (f = BaseFileSearch(args[i].GetChars(), ".deh", false, GameConfig)) ||
(f = BaseFileSearch(args[i].GetChars(), ".bex", false, GameConfig)) ) (f = BaseFileSearch(args[i].GetChars(), ".bex", false, GameConfig)) )
{ {
D_LoadDehFile(f); D_LoadDehFile(f, 0);
} }
} }
return argc > 0; return argc > 0;
@ -3396,7 +3396,7 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
auto numbasesounds = soundEngine->GetNumSounds(); auto numbasesounds = soundEngine->GetNumSounds();
// Load embedded Dehacked patches // Load embedded Dehacked patches
D_LoadDehLumps(FromIWAD); D_LoadDehLumps(FromIWAD, iwad_info->SkipBexStringsIfLanguage ? DEH_SKIP_BEX_STRINGS_IF_LANGUAGE : 0);
// [RH] Add any .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. // If there are none, try adding any in the config file.
@ -3413,13 +3413,13 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
if (stricmp (key, "Path") == 0 && FileExists (value)) if (stricmp (key, "Path") == 0 && FileExists (value))
{ {
if (!batchrun) Printf ("Applying patch %s\n", value); if (!batchrun) Printf ("Applying patch %s\n", value);
D_LoadDehFile(value); D_LoadDehFile(value, 0);
} }
} }
} }
// Load embedded Dehacked patches // Load embedded Dehacked patches
D_LoadDehLumps(FromPWADs); D_LoadDehLumps(FromPWADs, 0);
// Create replacements for dehacked pickups // Create replacements for dehacked pickups
FinishDehPatch(); FinishDehPatch();

View file

@ -86,6 +86,7 @@ struct FIWADInfo
int StartupType = FStartupInfo::DefaultStartup; // alternate startup type int StartupType = FStartupInfo::DefaultStartup; // alternate startup type
FString MapInfo; // Base mapinfo to load FString MapInfo; // Base mapinfo to load
bool nokeyboardcheats = false; // disable keyboard cheats bool nokeyboardcheats = false; // disable keyboard cheats
bool SkipBexStringsIfLanguage = false;
TArray<FString> Load; // Wads to be loaded with this one. TArray<FString> Load; // Wads to be loaded with this one.
TArray<FString> Lumps; // Lump names for identification TArray<FString> Lumps; // Lump names for identification
TArray<FString> DeleteLumps; // Lumps which must be deleted from the directory. TArray<FString> DeleteLumps; // Lumps which must be deleted from the directory.

View file

@ -446,28 +446,28 @@ struct Key {
ptrdiff_t offset; ptrdiff_t offset;
}; };
static int PatchThing (int); static int PatchThing (int, int);
static int PatchSound (int); static int PatchSound (int, int);
static int PatchFrame (int); static int PatchFrame (int, int);
static int PatchSprite (int); static int PatchSprite (int, int);
static int PatchAmmo (int); static int PatchAmmo (int, int);
static int PatchWeapon (int); static int PatchWeapon (int, int);
static int PatchPointer (int); static int PatchPointer (int, int);
static int PatchCheats (int); static int PatchCheats (int, int);
static int PatchMisc (int); static int PatchMisc (int, int);
static int PatchText (int); static int PatchText (int, int);
static int PatchStrings (int); static int PatchStrings (int, int);
static int PatchPars (int); static int PatchPars (int, int);
static int PatchCodePtrs (int); static int PatchCodePtrs (int, int);
static int PatchMusic (int); static int PatchMusic (int, int);
static int DoInclude (int); static int DoInclude (int, int);
static int PatchSpriteNames(int); static int PatchSpriteNames(int, int);
static int PatchSoundNames(int); static int PatchSoundNames(int, int);
static bool DoDehPatch(); static bool DoDehPatch(int);
static const struct { static const struct {
const char *name; const char *name;
int (*func)(int); int (*func)(int, int);
} Modes[] = { } Modes[] = {
// These appear in .deh and .bex files // These appear in .deh and .bex files
{ "Thing", PatchThing }, { "Thing", PatchThing },
@ -491,7 +491,7 @@ static const struct {
{ NULL, NULL }, { NULL, NULL },
}; };
static int HandleMode (const char *mode, int num); static int HandleMode (const char *mode, int num, int flags);
static bool HandleKey (const struct Key *keys, void *structure, const char *key, int value); static bool HandleKey (const struct Key *keys, void *structure, const char *key, int value);
static bool ReadChars (char **stuff, int size); static bool ReadChars (char **stuff, int size);
static char *igets (void); static char *igets (void);
@ -509,14 +509,14 @@ static void PushTouchedActor(PClassActor *cls)
} }
static int HandleMode (const char *mode, int num) static int HandleMode (const char *mode, int num, int flags)
{ {
int i = 0; int i = 0;
while (Modes[i].name && stricmp (Modes[i].name, mode)) while (Modes[i].name && stricmp (Modes[i].name, mode))
i++; i++;
if (Modes[i].name) if (Modes[i].name)
return Modes[i].func (num); return Modes[i].func (num, flags);
// Handle unknown or unimplemented data // Handle unknown or unimplemented data
Printf ("Unknown chunk %s encountered. Skipping.\n", mode); Printf ("Unknown chunk %s encountered. Skipping.\n", mode);
@ -1181,7 +1181,7 @@ static void ClearBits2Stuff(AActor* defaults)
} }
static int PatchThing (int thingy) static int PatchThing (int thingy, int flags)
{ {
enum enum
{ {
@ -1776,7 +1776,7 @@ static int PatchThing (int thingy)
// real benefit to doing this, and it would be very difficult for // real benefit to doing this, and it would be very difficult for
// me to emulate it, I have disabled them entirely. // me to emulate it, I have disabled them entirely.
static int PatchSound (int soundNum) static int PatchSound (int soundNum, int flags)
{ {
int result; int result;
@ -1833,7 +1833,7 @@ DehBits sbits[] = {
}; };
static int PatchFrame (int frameNum) static int PatchFrame (int frameNum, int flags)
{ {
MBFArgs args{}; MBFArgs args{};
int result; int result;
@ -1983,7 +1983,7 @@ static int PatchFrame (int frameNum)
return result; return result;
} }
static int PatchSprite (int sprNum) static int PatchSprite (int sprNum, int flags)
{ {
int result; int result;
int offset = 0; int offset = 0;
@ -2025,7 +2025,7 @@ static int PatchSprite (int sprNum)
return result; return result;
} }
static int PatchAmmo (int ammoNum) static int PatchAmmo (int ammoNum, int flags)
{ {
PClassActor *ammoType = NULL; PClassActor *ammoType = NULL;
AActor *defaultAmmo = NULL; AActor *defaultAmmo = NULL;
@ -2116,7 +2116,7 @@ DehBits wbits[] = {
{ "NOAUTOSWITCHTO", WIF_NOAUTOSWITCHTO } { "NOAUTOSWITCHTO", WIF_NOAUTOSWITCHTO }
}; };
static int PatchWeapon (int weapNum) static int PatchWeapon (int weapNum, int flags)
{ {
int result; int result;
PClassActor *type = nullptr; PClassActor *type = nullptr;
@ -2324,7 +2324,7 @@ static int SetPointer(FState *state, PFunction *sym, int frame = 0)
return -1; return -1;
} }
static int PatchPointer (int ptrNum) static int PatchPointer (int ptrNum, int flags)
{ {
int result; int result;
@ -2386,7 +2386,7 @@ static int PatchPointer (int ptrNum)
return result; return result;
} }
static int PatchCheats (int dummy) static int PatchCheats (int dummy, int flags)
{ {
int result; int result;
@ -2398,7 +2398,7 @@ static int PatchCheats (int dummy)
return result; return result;
} }
static int PatchMisc (int dummy) static int PatchMisc (int dummy, int flags)
{ {
static const struct Key keys[] = { static const struct Key keys[] = {
{ "Initial Health", static_cast<ptrdiff_t>(myoffsetof(struct DehInfo,StartHealth)) }, { "Initial Health", static_cast<ptrdiff_t>(myoffsetof(struct DehInfo,StartHealth)) },
@ -2592,7 +2592,7 @@ static int PatchMisc (int dummy)
return result; return result;
} }
static int PatchPars (int dummy) static int PatchPars (int dummy, int flags)
{ {
char *space, mapname[8], *moredata; char *space, mapname[8], *moredata;
level_info_t *info; level_info_t *info;
@ -2658,7 +2658,7 @@ static int PatchPars (int dummy)
} }
static int PatchCodePtrs (int dummy) static int PatchCodePtrs (int dummy, int flags)
{ {
int result; int result;
@ -2733,7 +2733,7 @@ static int PatchCodePtrs (int dummy)
return result; return result;
} }
static int PatchMusic (int dummy) static int PatchMusic (int dummy, int flags)
{ {
int result; int result;
@ -2788,7 +2788,7 @@ static void ReplaceSpriteInData(const char* oldStr, const char* newStr)
} }
} }
static int PatchText (int oldSize) static int PatchText (int oldSize, int flags)
{ {
int newSize; int newSize;
char *oldStr; char *oldStr;
@ -2895,7 +2895,7 @@ donewithtext:
return result; return result;
} }
static int PatchStrings (int dummy) static int PatchStrings (int dummy, int flags)
{ {
int result; int result;
@ -2919,6 +2919,8 @@ static int PatchStrings (int dummy)
} }
} while (Line2 && *Line2); } while (Line2 && *Line2);
if(!(flags & DEH_SKIP_BEX_STRINGS_IF_LANGUAGE))
{
ReplaceSpecialChars (holdstring.LockBuffer()); ReplaceSpecialChars (holdstring.LockBuffer());
holdstring.UnlockBuffer(); holdstring.UnlockBuffer();
// Account for a discrepancy between Boom's and ZDoom's name for the red skull key pickup message // Account for a discrepancy between Boom's and ZDoom's name for the red skull key pickup message
@ -2928,11 +2930,12 @@ static int PatchStrings (int dummy)
DehStrings.Insert(ll, te); DehStrings.Insert(ll, te);
DPrintf (DMSG_SPAMMY, "%s set to:\n%s\n", Line1, holdstring.GetChars()); DPrintf (DMSG_SPAMMY, "%s set to:\n%s\n", Line1, holdstring.GetChars());
} }
}
return result; return result;
} }
static int PatchSoundNames (int dummy) static int PatchSoundNames (int dummy, int flags)
{ {
int result; int result;
@ -2949,7 +2952,7 @@ static int PatchSoundNames (int dummy)
return result; return result;
} }
static int PatchSpriteNames (int dummy) static int PatchSpriteNames (int dummy, int flags)
{ {
int result; int result;
@ -2985,7 +2988,7 @@ static int PatchSpriteNames (int dummy)
} }
static int DoInclude (int dummy) static int DoInclude (int dummy, int flags)
{ {
char *data; char *data;
int savedversion, savepversion, savepatchsize; int savedversion, savepversion, savepatchsize;
@ -3047,7 +3050,7 @@ static int DoInclude (int dummy)
} }
} }
D_LoadDehFile(path); D_LoadDehFile(path, flags);
if (data != path) if (data != path)
{ {
@ -3080,7 +3083,7 @@ static bool isDehFile(int lumpnum)
&& (0 == stricmp(extension, ".deh") || 0 == stricmp(extension, ".bex")); && (0 == stricmp(extension, ".deh") || 0 == stricmp(extension, ".bex"));
} }
int D_LoadDehLumps(DehLumpSource source) int D_LoadDehLumps(DehLumpSource source, int flags)
{ {
int lastlump = 0, lumpnum, count = 0; int lastlump = 0, lumpnum, count = 0;
@ -3099,7 +3102,20 @@ int D_LoadDehLumps(DehLumpSource source)
continue; continue;
} }
count += D_LoadDehLump(lumpnum); int filtered_flags = flags & ~DEH_SKIP_BEX_STRINGS_IF_LANGUAGE;
if((flags & DEH_SKIP_BEX_STRINGS_IF_LANGUAGE) && FromIWAD == source)
{
int iwadnum = fileSystem.GetIwadNum();
int lastlump2 = fileSystem.GetFirstEntry(iwadnum);
int lumpnum2 = fileSystem.FindLump("LANGUAGE", &lastlump2);
if(lumpnum2 >= 0 && fileSystem.GetFileContainer(lumpnum2) == iwadnum)
{
filtered_flags |= DEH_SKIP_BEX_STRINGS_IF_LANGUAGE;
}
}
count += D_LoadDehLump(lumpnum, filtered_flags);
} }
if (FromPWADs == source && 0 == PatchSize && dehload > 0) if (FromPWADs == source && 0 == PatchSize && dehload > 0)
@ -3112,7 +3128,7 @@ int D_LoadDehLumps(DehLumpSource source)
{ {
if (isDehFile(lumpnum)) if (isDehFile(lumpnum))
{ {
count += D_LoadDehLump(lumpnum); count += D_LoadDehLump(lumpnum, 0);
} }
} }
} }
@ -3122,7 +3138,7 @@ int D_LoadDehLumps(DehLumpSource source)
{ {
if (isDehFile(lumpnum)) if (isDehFile(lumpnum))
{ {
count += D_LoadDehLump(lumpnum); count += D_LoadDehLump(lumpnum, 0);
break; break;
} }
} }
@ -3132,7 +3148,7 @@ int D_LoadDehLumps(DehLumpSource source)
return count; return count;
} }
bool D_LoadDehLump(int lumpnum) bool D_LoadDehLump(int lumpnum, int flags)
{ {
auto ls = LumpFileNum; auto ls = LumpFileNum;
LumpFileNum = fileSystem.GetFileContainer(lumpnum); LumpFileNum = fileSystem.GetFileContainer(lumpnum);
@ -3143,13 +3159,13 @@ bool D_LoadDehLump(int lumpnum)
PatchFile = new char[PatchSize + 1]; PatchFile = new char[PatchSize + 1];
fileSystem.ReadFile(lumpnum, PatchFile); fileSystem.ReadFile(lumpnum, PatchFile);
PatchFile[PatchSize] = '\0'; // terminate with a '\0' character PatchFile[PatchSize] = '\0'; // terminate with a '\0' character
auto res = DoDehPatch(); auto res = DoDehPatch(flags);
LumpFileNum = ls; LumpFileNum = ls;
return res; return res;
} }
bool D_LoadDehFile(const char *patchfile) bool D_LoadDehFile(const char *patchfile, int flags)
{ {
FileReader fr; FileReader fr;
@ -3162,7 +3178,7 @@ bool D_LoadDehFile(const char *patchfile)
fr.Read(PatchFile, PatchSize); fr.Read(PatchFile, PatchSize);
fr.Close(); fr.Close();
PatchFile[PatchSize] = '\0'; // terminate with a '\0' character PatchFile[PatchSize] = '\0'; // terminate with a '\0' character
return DoDehPatch(); return DoDehPatch(flags);
} }
else else
{ {
@ -3178,14 +3194,14 @@ bool D_LoadDehFile(const char *patchfile)
} }
if (lumpnum >= 0) if (lumpnum >= 0)
{ {
return D_LoadDehLump(lumpnum); return D_LoadDehLump(lumpnum, flags);
} }
} }
Printf ("Could not open DeHackEd patch \"%s\"\n", patchfile); Printf ("Could not open DeHackEd patch \"%s\"\n", patchfile);
return false; return false;
} }
static bool DoDehPatch() static bool DoDehPatch(int flags)
{ {
if (!batchrun) Printf("Adding dehacked patch %s\n", PatchName.GetChars()); if (!batchrun) Printf("Adding dehacked patch %s\n", PatchName.GetChars());
@ -3276,7 +3292,7 @@ static bool DoDehPatch()
} }
else if (cont == 2) else if (cont == 2)
{ {
cont = HandleMode (Line1, atoi (Line2)); cont = HandleMode (Line1, atoi (Line2), flags);
} }
} while (cont); } while (cont);

View file

@ -40,9 +40,14 @@ enum DehLumpSource
FromPWADs FromPWADs
}; };
int D_LoadDehLumps(DehLumpSource source); enum DehFlags
bool D_LoadDehLump(int lumpnum); {
bool D_LoadDehFile(const char *filename); DEH_SKIP_BEX_STRINGS_IF_LANGUAGE = 1,
};
int D_LoadDehLumps(DehLumpSource source, int flags);
bool D_LoadDehLump(int lumpnum, int flags);
bool D_LoadDehFile(const char *filename, int flags);
void FinishDehPatch (); void FinishDehPatch ();
#endif //__D_DEHACK_H__ #endif //__D_DEHACK_H__

View file

@ -282,6 +282,7 @@ IWad
Mapinfo = "mapinfo/doom2.txt" Mapinfo = "mapinfo/doom2.txt"
MustContain = "MAP01", "FREEDM" MustContain = "MAP01", "FREEDM"
BannerColors = "32 54 43", "c6 dc d1" BannerColors = "32 54 43", "c6 dc d1"
SkipBexStringsIfLanguage
} }
IWad IWad
@ -294,6 +295,7 @@ IWad
Mapinfo = "mapinfo/doom2.txt" Mapinfo = "mapinfo/doom2.txt"
MustContain = "MAP01", "FREEDOOM" MustContain = "MAP01", "FREEDOOM"
BannerColors = "32 54 43", "c6 dc d1" BannerColors = "32 54 43", "c6 dc d1"
SkipBexStringsIfLanguage
} }
IWad IWad
@ -306,6 +308,7 @@ IWad
Mapinfo = "mapinfo/doom1.txt" Mapinfo = "mapinfo/doom1.txt"
MustContain = "E1M1", "E2M1", "E3M1", "FREEDOOM" MustContain = "E1M1", "E2M1", "E3M1", "FREEDOOM"
BannerColors = "32 54 43", "c6 dc d1" BannerColors = "32 54 43", "c6 dc d1"
SkipBexStringsIfLanguage
} }
IWad IWad
@ -317,6 +320,7 @@ IWad
Mapinfo = "mapinfo/doom1.txt" Mapinfo = "mapinfo/doom1.txt"
MustContain = "E1M1", "FREEDOOM" MustContain = "E1M1", "FREEDOOM"
BannerColors = "32 54 43", "c6 dc d1" BannerColors = "32 54 43", "c6 dc d1"
SkipBexStringsIfLanguage
} }
IWad IWad