diff --git a/Source/Core/Data/WADReader.cs b/Source/Core/Data/WADReader.cs index 624fda83..c7cfa0bc 100755 --- a/Source/Core/Data/WADReader.cs +++ b/Source/Core/Data/WADReader.cs @@ -1140,7 +1140,7 @@ namespace CodeImp.DoomBuilder.Data { if (issuspended) throw new Exception("Data reader is suspended"); - return GetAllLumpsData("LUA_"); + return GetAllLumpsDataWithPrefix("LUA_"); } //mxd @@ -1192,6 +1192,25 @@ namespace CodeImp.DoomBuilder.Data return result; } + //mxd + private List GetAllLumpsDataWithPrefix(string prefix) + { + List result = new List(); + + // Find all lumps with given name + int lumpindex = file.FindLumpIndexWithPrefix(prefix); + while (lumpindex > -1) + { + // Add to collection + result.Add(new TextResourceData(this, file.Lumps[lumpindex].GetSafeStream(), prefix, lumpindex, true)); + + // Find next entry + lumpindex = file.FindLumpIndexWithPrefix(prefix, lumpindex + 1); + } + + return result; + } + #endregion #region ================== IO (mxd) diff --git a/Source/Core/IO/WAD.cs b/Source/Core/IO/WAD.cs index 43f4a76f..95bb73ee 100755 --- a/Source/Core/IO/WAD.cs +++ b/Source/Core/IO/WAD.cs @@ -568,6 +568,44 @@ namespace CodeImp.DoomBuilder.IO return -1; } + // This finds a lump with given prefix, returns -1 when not found + public int FindLumpIndexWithPrefix(string prefix) + { + // Do search + return FindLumpIndexWithPrefix(prefix, 0, lumps.Count - 1); + } + + // This finds a lump with given prefix, returns -1 when not found + public int FindLumpIndexWithPrefix(string prefix, int start) + { + // Do search + return FindLumpIndex(prefix, start, lumps.Count - 1); + } + + // This finds a lump with given prefix, returns -1 when not found + public int FindLumpIndexWithPrefix(string prefix, int start, int end) + { + if (prefix.Length > 8 || lumps.Count == 0 || start > lumps.Count - 1) return -1; //mxd. Can't be here. Go away! + + // Fix start/end when they exceed safe bounds + start = Math.Max(start, 0); + end = General.Clamp(end, 0, lumps.Count - 1); + + // Loop through the lumps + for (int i = start; i < end + 1; i++) + { + // Check if the lump name matches + if (lumps[i].Name.StartsWith(prefix)) + { + // Found the lump! + return i; + } + } + + // Nothing found + return -1; + } + //mxd. Same as above, but searches in reversed order // This finds a lump by name, returns null when not found