From 72231d330dd48a1d9ccacb0daa23e894f269a070 Mon Sep 17 00:00:00 2001
From: spherallic <spherallic@gmail.com>
Date: Tue, 30 May 2023 16:49:18 +0200
Subject: [PATCH] Revert "Fixed: consequential duplicate maps weren't handled
 properly"

This reverts commit 6bd76dee4e4597ec512269ee24a56812d9d85912.
---
 Source/Core/General/MapManager.cs | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs
index 2c9baa92..29141dff 100644
--- a/Source/Core/General/MapManager.cs
+++ b/Source/Core/General/MapManager.cs
@@ -1452,11 +1452,15 @@ namespace CodeImp.DoomBuilder
             //
             while (true)
             {
-                int nextindex = target.FindLumpIndex(targetmapname, tgtheaderindex);
+                int nextindex = target.FindLumpIndex(targetmapname, tgtheaderindex + 1);
                 // note that this (and the original algorithm too) would break if you have a patch or a texture named MAP01 for example...
                 // this is the case for multiple megawads that have level selection screen (Duel40-style), but luckily most of them are using the PK3 format.
                 if (nextindex < 0) break; // next lump not found
-
+                // remove the header lump
+                target.RemoveAt(nextindex, false);
+                writeheaders = true;
+                //
+                tgtheaderindex = nextindex;
                 // try to detect the format used for this map.
                 // if more than one format matches, do... idk what actually.
                 // todo: move this code out and call it something like DetectMapConfiguration
@@ -1496,7 +1500,7 @@ namespace CodeImp.DoomBuilder
                 {
                     int matches = 0;
                     int maxcnt = lst.Count;
-                    int checkindex = nextindex+1;
+                    int checkindex = nextindex;
                     foreach (string lmp in lst)
                     {
                         if (checkindex >= target.Lumps.Count)
@@ -1517,7 +1521,7 @@ namespace CodeImp.DoomBuilder
                 // if we didn't find anything it's weird...
                 if (trylist != null)
                 {
-                    int checkindex = nextindex+1;
+                    int checkindex = nextindex;
                     foreach (string lmp in trylist)
                     {
                         if (checkindex >= target.Lumps.Count)
@@ -1527,11 +1531,6 @@ namespace CodeImp.DoomBuilder
                         else break; // stop deleting on first non-matching lump
                     }
                 }
-
-                // how if trylist was not null, we need to remove the header as well.
-                target.RemoveAt(nextindex, false);
-                writeheaders = true;
-                tgtheaderindex = nextindex;
             }
 
             if (writeheaders) target.WriteHeaders();
-- 
GitLab