From 0482eacb7c9a625c47a19c017304a3f4af2bd24c Mon Sep 17 00:00:00 2001
From: LJ Sonic <lamr@free.fr>
Date: Sat, 3 Jul 2021 19:58:59 +0200
Subject: [PATCH] Load add-ons in the order in which the -file and -folder
 arguments are specified

---
 src/d_main.c | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/src/d_main.c b/src/d_main.c
index 0d0e2434a4..7866ccbed4 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1253,34 +1253,25 @@ void D_SRB2Main(void)
 	// Do this up here so that WADs loaded through the command line can use ExecCfg
 	COM_Init();
 
-	// add any files specified on the command line with -file wadfile
-	// to the wad list
+	// Add any files specified on the command line with
+	// "-file <file>" or "-folder <folder>" to the add-on list
 	if (!((M_GetUrlProtocolArg() || M_CheckParm("-connect")) && !M_CheckParm("-server")))
 	{
-		if (M_CheckParm("-file"))
-		{
-			// the parms after p are wadfile names,
-			// until end of parms or another - preceded parm
-			while (M_IsNextParm())
-			{
-				const char *s = M_GetNextParm();
-
-				if (s) // Check for NULL?
-					D_AddFile(startuppwads, s);
-			}
-		}
+		INT32 addontype = 0;
+		INT32 i;
 
-		if (M_CheckParm("-folder"))
+		for (i = 1; i < myargc; i++)
 		{
-			// the parms after p are folder names,
-			// until end of parms or another - preceded parm
-			while (M_IsNextParm())
-			{
-				const char *s = M_GetNextParm();
-
-				if (s) // Check for NULL?
-					D_AddFolder(startuppwads, s);
-			}
+			if (!strcasecmp(myargv[i], "-file"))
+				addontype = 1;
+			else if (!strcasecmp(myargv[i], "-folder"))
+				addontype = 2;
+			else if (myargv[i][0] == '-' || myargv[i][0] == '+')
+				addontype = 0;
+			else if (addontype == 1)
+				D_AddFile(startuppwads, myargv[i]);
+			else if (addontype == 2)
+				D_AddFolder(startuppwads, myargv[i]);
 		}
 	}
 
-- 
GitLab