From 4fe3c50c7cb50c226226507e17c48fdcebcd9dab Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Apr 2021 17:05:53 +0200 Subject: [PATCH] - used the newly added game ID as reference for GAMEINFO to autoselect which game to start a mod with. While in GZDoom this uses the IWAD name, the same approach is a lot more problematic here because of name duplications with far more incompatible content. So this allows targeting a group of base games instead of one specific version. --- source/core/gamecontrol.cpp | 21 ++++++++++++++++----- source/core/gamecontrol.h | 1 + source/core/initfs.cpp | 18 +++++++++--------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index e2560c4a3..5bfdd21c6 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -123,7 +123,7 @@ FMemArena dump; // this is for memory blocks than cannot be deallocated without InputState inputState; int ShowStartupWindow(TArray &); -FString GetGameFronUserFiles(); +TArray GetGameFronUserFiles(); void InitFileSystem(TArray&); void I_SetWindowTitle(const char* caption); void S_ParseSndInfo(); @@ -643,14 +643,25 @@ static TArray SetupGame() int groupno = -1; - // If the user has specified a file name, let's see if we know it. - // - FString game = GetGameFronUserFiles(); + auto game = GetGameFronUserFiles(); if (userConfig.gamegrp.IsEmpty()) { - userConfig.gamegrp = game; + for (auto& str : game) + { + for (auto& grp : groups) + { + if (grp.FileInfo.gameid.CompareNoCase(str) == 0) + { + userConfig.gamegrp = grp.FileName; + goto foundit; + } + } + } } + foundit: + // If the user has specified a file name, let's see if we know it. + // if (userConfig.gamegrp.Len()) { FString gamegrplower = "/" + userConfig.gamegrp.MakeLower(); diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 292c9a4b4..1316ed8d4 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -139,6 +139,7 @@ struct GrpInfo FString defname; FString rtsname; FString gamefilter; + FString gameid; uint32_t CRC = 0; uint32_t dependencyCRC = 0; size_t size = 0; diff --git a/source/core/initfs.cpp b/source/core/initfs.cpp index 3ad2283f4..b0e6da37c 100644 --- a/source/core/initfs.cpp +++ b/source/core/initfs.cpp @@ -60,10 +60,10 @@ static const char* validexts[] = { "*.grp", "*.zip", "*.pk3", "*.pk4", "*.7z", " // //========================================================================== -static FString ParseGameInfo(TArray& pwads, const char* fn, const char* data, int size) +static TArray ParseGameInfo(TArray& pwads, const char* fn, const char* data, int size) { FScanner sc; - FString iwad; + TArray bases; int pos = 0; const char* lastSlash = strrchr(fn, '/'); @@ -78,7 +78,7 @@ static FString ParseGameInfo(TArray& pwads, const char* fn, const char* if (!nextKey.CompareNoCase("GAME")) { sc.MustGetString(); - iwad = sc.String; + bases.Push(sc.String); } else if (!nextKey.CompareNoCase("LOAD")) { @@ -136,7 +136,7 @@ static FString ParseGameInfo(TArray& pwads, const char* fn, const char* } while (sc.CheckToken(',')); } } - return iwad; + return bases; } //========================================================================== // @@ -144,7 +144,7 @@ static FString ParseGameInfo(TArray& pwads, const char* fn, const char* // //========================================================================== -static FString CheckGameInfo(TArray& pwads) +static TArray CheckGameInfo(TArray& pwads) { // scan the list of WADs backwards to find the last one that contains a GAMEINFO lump for (int i = pwads.Size() - 1; i >= 0; i--) @@ -184,15 +184,15 @@ static FString CheckGameInfo(TArray& pwads) if (FName(lmp->getName(), true) == gameinfo) { // Found one! - FString iwad = ParseGameInfo(pwads, resfile->FileName, (const char*)lmp->Lock(), lmp->LumpSize); + auto bases = ParseGameInfo(pwads, resfile->FileName, (const char*)lmp->Lock(), lmp->LumpSize); delete resfile; - return iwad; + return bases; } } delete resfile; } } - return ""; + return TArray(); } //========================================================================== @@ -201,7 +201,7 @@ static FString CheckGameInfo(TArray& pwads) // //========================================================================== -FString GetGameFronUserFiles() +TArray GetGameFronUserFiles() { TArray Files;