From e5a9bac2adbbc46a683b6d71cfc61788c5b15455 Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Tue, 23 Jul 2013 14:25:03 +0000
Subject: [PATCH] Added "File -> Open Map in current WAD" command (default
 shortcut is Ctrl-Shift-O). Fixed some errors in non-UDMF <-> UDMF map
 conversion. Updated ISS setup script (not tested). Removed some unused
 variables.

---
 .../ZDoomFamily_template.txt                  |  17 +-
 Setup/builder2_setup.iss                      |  19 +-
 Source/Core/Config/ScriptConfiguration.cs     |   6 +-
 Source/Core/Controls/ArgumentBox.cs           |   6 +-
 Source/Core/Controls/DockersControl.cs        |   6 +-
 Source/Core/Data/DataManager.cs               |   8 +-
 Source/Core/General/General.cs                |  22 +-
 Source/Core/General/MapManager.cs             | 224 ++++++++++--------
 Source/Core/IO/SerializerStream.cs            |   4 +-
 Source/Core/Resources/Actions.cfg             |  12 +
 Source/Core/VisualModes/VisualMode.cs         |   4 +-
 Source/Core/Windows/MainForm.Designer.cs      |  35 ++-
 Source/Core/Windows/MainForm.cs               |   1 +
 .../BuilderModes/Interface/PreferencesForm.cs |   4 +-
 .../ColorPicker/Windows/LightColorPicker.cs   |   7 +-
 15 files changed, 228 insertions(+), 147 deletions(-)

diff --git a/Build/Configurations/Configs for other games/ZDoomFamily_template.txt b/Build/Configurations/Configs for other games/ZDoomFamily_template.txt
index 9d12b42e2..aaed596ad 100644
--- a/Build/Configurations/Configs for other games/ZDoomFamily_template.txt	
+++ b/Build/Configurations/Configs for other games/ZDoomFamily_template.txt	
@@ -38,25 +38,28 @@ include("Includes\\ZDoom_common.cfg", "mapformat_udmf");
 !!!!!!!!!!!!! GAME STUFF !!!!!!!!!!!!!
 !Keep only the one that's appropriate!
 // Settings common to Doom games
-include("Includes\\ZDoom_common.cfg", "game_doom");
+include("Includes\\Game_Doom.cfg");
 
 // Settings common to Heretic games
-include("Includes\\ZDoom_common.cfg", "game_heretic");
+include("Includes\\Game_Heretic.cfg");
 
 // Settings common to Hexen games
-include("Includes\\ZDoom_common.cfg", "game_hexen");
+include("Includes\\Game_Hexen.cfg");
 
 // Settings common to Strife games
-include("Includes\\ZDoom_common.cfg", "game_strife");
+include("Includes\\Game_Strife.cfg");
 
 // Settings common to Chex Quest games
-include("Includes\\ZDoom_common.cfg", "game_chex");
+include("Includes\\Game_Chex.cfg");
 
 // Settings common to Chex Quest 3 games
-include("Includes\\ZDoom_common.cfg", "game_chex3");
+include("Includes\\Game_Chex3.cfg");
 
 // Settings common to Harmony games
-include("Includes\\ZDoom_common.cfg", "game_harmony");
+include("Includes\\Game_Harmony.cfg");
+
+// Settings common to Action Doom 2 games
+include("Includes\\Game_Action2.cfg");
 !!!!!!!!!!!!! GAME STUFF !!!!!!!!!!!!!
 
 !!!!Keep only one of each category!!!!
diff --git a/Setup/builder2_setup.iss b/Setup/builder2_setup.iss
index fcdc52d65..435bfac70 100644
--- a/Setup/builder2_setup.iss
+++ b/Setup/builder2_setup.iss
@@ -40,33 +40,44 @@ Source: Builder.exe; DestDir: {app}; Flags: ignoreversion
 Source: GZBuilder.cfg; DestDir: {app}; Flags: ignoreversion
 Source: Refmanual.chm; DestDir: {app}; Flags: ignoreversion
 Source: DevIL.dll; DestDir: {app}; Flags: ignoreversion
-Source: Sharpzip.dll; DestDir: {app}; Flags: ignoreversion
+Source: SharpCompress.3.5.dll; DestDir: {app}; Flags: ignoreversion
 Source: Scintilla.dll; DestDir: {app}; Flags: ignoreversion
 Source: Trackbar.dll; DestDir: {app}; Flags: ignoreversion
 Source: SlimDX.dll; DestDir: {app}; Flags: ignoreversion
 Source: GPL.txt; DestDir: {app}; Flags: ignoreversion
 Source: Compilers\*; DestDir: {app}\Compilers; Flags: ignoreversion recursesubdirs
 Source: Configurations\*; DestDir: {app}\Configurations; Flags: ignoreversion recursesubdirs
+Source: Gldefs\*; DestDir: {app}\Gldefs; Flags: ignoreversion recursesubdirs
 Source: Scripting\*; DestDir: {app}\Scripting; Flags: ignoreversion recursesubdirs
 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
 Source: Plugins\BuilderModes.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\BuilderEffects.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\ColorPicker.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\CommentsPanel.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\CopyPasteSectorProps.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\NodesViewer.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\StairSectorBuilder.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\Statistics.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\TagExplorer.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\TagRange.dll; DestDir: {app}\Plugins; Flags: ignoreversion
+Source: Plugins\VisplaneExplorer.dll; DestDir: {app}\Plugins; Flags: ignoreversion
 Source: Plugins\Loadorder.cfg; DestDir: {app}\Plugins; Flags: ignoreversion onlyifdoesntexist
 Source: Sprites\*; DestDir: {app}\Sprites; Flags: ignoreversion recursesubdirs
 
 [Icons]
 Name: {group}\Doom Builder; Filename: {app}\Builder.exe
 Name: {group}\{cm:UninstallProgram,Doom Builder}; Filename: {uninstallexe}
-Name: {commondesktop}\Doom Builder; Filename: {app}\Builder.exe; Tasks: desktopicon
+Name: {commondesktop}\GZDoom Builder; Filename: {app}\Builder.exe; Tasks: desktopicon
 
 [Run]
 
 [UninstallDelete]
-Name: {localappdata}\Doom Builder; Type: filesandordirs
+//Name: {localappdata}\Doom Builder; Type: filesandordirs
 Name: {app}; Type: filesandordirs
 [InstallDelete]
 Name: {app}\Builder.pdb; Type: files
 [Registry]
-Root: HKLM; Subkey: SOFTWARE\CodeImp\Doom Builder\; ValueType: string; ValueName: Location; ValueData: {app}; Flags: uninsdeletevalue
+Root: HKLM; Subkey: SOFTWARE\CodeImp\GZDoom Builder\; ValueType: string; ValueName: Location; ValueData: {app}; Flags: uninsdeletevalue
 [Messages]
 ReadyLabel2a=Continue to begin with the installation, or click Back if you want to review or change any settings.
 [Code]
diff --git a/Source/Core/Config/ScriptConfiguration.cs b/Source/Core/Config/ScriptConfiguration.cs
index b97020dc3..02c6b268e 100644
--- a/Source/Core/Config/ScriptConfiguration.cs
+++ b/Source/Core/Config/ScriptConfiguration.cs
@@ -34,7 +34,7 @@ namespace CodeImp.DoomBuilder.Config
 		#region ================== Variables
 
 		// Original configuration
-		private Configuration cfg;
+		//private Configuration cfg;
 		
 		// Compiler settings
 		private CompilerInfo compiler;
@@ -97,7 +97,7 @@ namespace CodeImp.DoomBuilder.Config
 		internal ScriptConfiguration()
 		{
 			// Initialize
-			this.cfg = new Configuration();
+			//this.cfg = new Configuration();
 			this.keywords = new Dictionary<string, string>();
 			this.constants = new List<string>();
 			this.lowerkeywords = new Dictionary<string, string>();
@@ -128,7 +128,7 @@ namespace CodeImp.DoomBuilder.Config
 			IDictionary dic;
 			
 			// Initialize
-			this.cfg = cfg;
+			//this.cfg = cfg;
 			this.keywords = new Dictionary<string,string>();
 			this.constants = new List<string>();
 			this.lowerkeywords = new Dictionary<string, string>();
diff --git a/Source/Core/Controls/ArgumentBox.cs b/Source/Core/Controls/ArgumentBox.cs
index c25e739b5..c42a884d3 100644
--- a/Source/Core/Controls/ArgumentBox.cs
+++ b/Source/Core/Controls/ArgumentBox.cs
@@ -38,9 +38,7 @@ namespace CodeImp.DoomBuilder.Controls
 		#region ================== Variables
 		
 		private TypeHandler typehandler;
-		private bool ignorebuttonchange = false;
-        //mxd
-        private ArgumentInfo arginfo;
+		private bool ignorebuttonchange;
 		private bool gotTagArgument;
 		
 		#endregion
@@ -178,8 +176,6 @@ namespace CodeImp.DoomBuilder.Controls
 		// This sets up the control for a specific argument
 		public void Setup(ArgumentInfo arginfo)
 		{
-            this.arginfo = arginfo; //mxd
-            
             int oldvalue = 0;
 			
 			// Get the original value
diff --git a/Source/Core/Controls/DockersControl.cs b/Source/Core/Controls/DockersControl.cs
index b3cdc719f..d69b108dd 100644
--- a/Source/Core/Controls/DockersControl.cs
+++ b/Source/Core/Controls/DockersControl.cs
@@ -86,9 +86,11 @@ namespace CodeImp.DoomBuilder.Controls
 		public DockersControl()
 		{
 			InitializeComponent();
-			expandedwidth = (int)((float)this.Width * (this.CurrentAutoScaleDimensions.Width / this.AutoScaleDimensions.Width));
+			expandedwidth = (int)(this.Width * (this.CurrentAutoScaleDimensions.Width / this.AutoScaleDimensions.Width));
 			tabs.TabsOffsetTop = buttonTogglePinning.Bottom + 2; //mxd
-			buttonTogglePinning.Image = General.Settings.CollapseDockers ? CodeImp.DoomBuilder.Properties.Resources.Unpin : CodeImp.DoomBuilder.Properties.Resources.Pin; //mxd
+
+			if(General.Settings != null)
+				buttonTogglePinning.Image = General.Settings.CollapseDockers ? CodeImp.DoomBuilder.Properties.Resources.Unpin : CodeImp.DoomBuilder.Properties.Resources.Pin; //mxd
 		}
 		
 		#endregion
diff --git a/Source/Core/Data/DataManager.cs b/Source/Core/Data/DataManager.cs
index 8a8b61015..cdc35aed2 100644
--- a/Source/Core/Data/DataManager.cs
+++ b/Source/Core/Data/DataManager.cs
@@ -922,11 +922,9 @@ namespace CodeImp.DoomBuilder.Data
 				// Return texture
 				return textures[longname];
 			}
-			else
-			{
-				// Return null image
-				return new UnknownImage(Properties.Resources.UnknownImage);
-			}
+
+			// Return null image
+			return new UnknownImage(Properties.Resources.UnknownImage);
 		}
 		
 		#endregion
diff --git a/Source/Core/General/General.cs b/Source/Core/General/General.cs
index 5b1186b8e..b0cc16b03 100644
--- a/Source/Core/General/General.cs
+++ b/Source/Core/General/General.cs
@@ -1124,7 +1124,27 @@ namespace CodeImp.DoomBuilder
 
 			openfile.Dispose();
 		}
-		
+
+		//mxd
+		// This loads a map from file
+		[BeginAction("openmapincurrentwad")]
+		internal static void OpenMapInCurrentWad() {
+			if (map == null || string.IsNullOrEmpty(map.FilePathName) || !File.Exists(map.FilePathName)){
+				General.Interface.DisplayStatus(StatusType.Warning, "Unable to open map form current WAD!");
+				return;
+			}
+
+			// Update main window
+			mainwindow.Update();
+
+			// Open map file
+			OpenMapFile(map.FilePathName, null);
+
+			//mxd
+			mainwindow.UpdateGZDoomPanel();
+			General.Settings.GZForceDefaultTextures = false;
+		}
+
 		// This opens the specified file
 		internal static void OpenMapFile(string filename, MapOptions options)
 		{
diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs
index 959511481..b231d6437 100644
--- a/Source/Core/General/MapManager.cs
+++ b/Source/Core/General/MapManager.cs
@@ -57,6 +57,7 @@ namespace CodeImp.DoomBuilder {
         private string filetitle;
         private string filepathname;
         private string temppath;
+		private string origmapconfigfile; //mxd. Map configuration, which was used to open the map.
 
         // Main objects
         private MapSet map;
@@ -255,6 +256,7 @@ namespace CodeImp.DoomBuilder {
             General.WriteLogLine("Loading game configuration...");
             configinfo = General.GetConfigurationInfo(options.ConfigFile);
             config = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
+			origmapconfigfile = options.ConfigFile;//mxd
             configinfo.ApplyDefaults(config);
             General.Editing.UpdateCurrentEditModes();
 
@@ -346,6 +348,7 @@ namespace CodeImp.DoomBuilder {
             General.WriteLogLine("Loading game configuration...");
             configinfo = General.GetConfigurationInfo(options.ConfigFile);
             config = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
+			origmapconfigfile = options.ConfigFile;//mxd
             configinfo.ApplyDefaults(config);
             General.Editing.UpdateCurrentEditModes();
 
@@ -618,7 +621,8 @@ namespace CodeImp.DoomBuilder {
                     targetwad = new WAD(newfilepathname);
 
                     // Copy all lumps, except the original map
-                    CopyAllLumpsExceptMap(origwad, targetwad, origmapname);
+					GameConfiguration origcfg = (origmapconfigfile == configinfo.Filename ? config : new GameConfiguration(General.LoadGameConfiguration(origmapconfigfile))); //mxd
+                    CopyAllLumpsExceptMap(origwad, targetwad, origcfg, origmapname);
 
                     // Close original file and delete it
                     origwad.Dispose();
@@ -861,9 +865,7 @@ namespace CodeImp.DoomBuilder {
                 l.Stream.Seek(0, SeekOrigin.Begin);
                 return new MemoryStream(l.Stream.ReadAllBytes());
             }
-            else {
-                return null;
-            }
+            return null;
         }
 
         // This writes a copy of the data to a lump in the temp file
@@ -935,13 +937,31 @@ namespace CodeImp.DoomBuilder {
             }
         }
 
+		//mxd. This is called on tempwad, which should only have the current map inside it.
+		private void removeUnneededLumps(WAD target, string mapname) {
+			//Get the list of lumps required by current map format
+			List<string> requiredLumps = new List<string>();
+			foreach (DictionaryEntry ml in config.MapLumpNames){
+				string lumpname = ml.Key.ToString();
+				if(lumpname == CONFIG_MAP_HEADER) lumpname = mapname;
+				requiredLumps.Add(lumpname);
+			}
+
+			//Remove lumps, which are not required
+			List<Lump> toRemove = new List<Lump>();
+			foreach (Lump lump in target.Lumps)
+				if (!requiredLumps.Contains(lump.Name)) toRemove.Add(lump);
+
+			foreach (Lump lump in toRemove) target.Remove(lump);
+		}
+
         // This copies all lumps, except those of a specific map
-        private void CopyAllLumpsExceptMap(WAD source, WAD target, string sourcemapname) {
+        private void CopyAllLumpsExceptMap(WAD source, WAD target, GameConfiguration mapconfig, string sourcemapname) {
             // Go for all lumps
             bool skipping = false;
             foreach (Lump srclump in source.Lumps) {
                 // Check if we should stop skipping lumps here
-                if (skipping && !config.MapLumpNames.Contains(srclump.Name)) {
+				if (skipping && !mapconfig.MapLumpNames.Contains(srclump.Name)) {
                     // Stop skipping
                     skipping = false;
                 }
@@ -1236,10 +1256,9 @@ namespace CodeImp.DoomBuilder {
                 // This also saves implicitly
                 return scriptwindow.AskSaveAll();
             }
-            else {
-                // No problems
-                return true;
-            }
+
+			// No problems
+			return true;
         }
 
         // This applies the changed status for internal scripts
@@ -1272,10 +1291,8 @@ namespace CodeImp.DoomBuilder {
                 // Check if scripts are changed			
                 return scriptschanged || scriptwindow.Editor.CheckImplicitChanges();
             }
-            else {
-                // Check if scripts are changed			
-                return scriptschanged;
-            }
+	
+            return scriptschanged;
         }
 
         // This compiles all lumps that require compiling and stores the results
@@ -1304,105 +1321,100 @@ namespace CodeImp.DoomBuilder {
             byte[] filedata;
             string reallumpname = lumpname;
 
+			//mxd. Does lump require compiling?
+			ScriptConfiguration scriptconfig = config.MapLumps[lumpname].script;
+			if (scriptconfig.Compiler == null) return true;
+
             // Find the lump
             if (lumpname == CONFIG_MAP_HEADER) reallumpname = TEMP_MAP_HEADER;
             Lump lump = tempwad.FindLump(reallumpname);
             if (lump == null) throw new Exception("No such lump in temporary wad file '" + reallumpname + "'.");
 
             // Determine source file
-            if (filepathname.Length > 0)
-                sourcefile = filepathname;
-            else
-                sourcefile = tempwad.Filename;
+            sourcefile = (filepathname.Length > 0 ? filepathname : tempwad.Filename);
 
             // New list of errors
             if (clearerrors) errors.Clear();
 
             // Determine the script configuration to use
-            ScriptConfiguration scriptconfig = config.MapLumps[lumpname].script;
-            if (scriptconfig.Compiler != null) {
-                try {
-                    // Initialize compiler
-                    compiler = scriptconfig.Compiler.Create();
-                } catch (Exception e) {
-                    // Fail
-                    errors.Add(new CompilerError("Unable to initialize compiler. " + e.GetType().Name + ": " + e.Message));
-                    return false;
-                }
-
-                try {
-                    // Write lump data to temp script file in compiler's temp directory
-                    inputfile = General.MakeTempFilename(compiler.Location, "tmp");
-                    lump.Stream.Seek(0, SeekOrigin.Begin);
-                    BinaryReader reader = new BinaryReader(lump.Stream);
-                    File.WriteAllBytes(inputfile, reader.ReadBytes((int)lump.Stream.Length));
-                } catch (Exception e) {
-                    // Fail
-                    compiler.Dispose();
-                    errors.Add(new CompilerError("Unable to write script to working file. " + e.GetType().Name + ": " + e.Message));
-                    return false;
-                }
-
-                // Make random output filename
-                outputfile = General.MakeTempFilename(compiler.Location, "tmp");
-
-                // Run compiler
-                compiler.Parameters = scriptconfig.Parameters;
-                compiler.InputFile = Path.GetFileName(inputfile);
-                compiler.OutputFile = Path.GetFileName(outputfile);
-                compiler.SourceFile = sourcefile;
-                compiler.WorkingDirectory = Path.GetDirectoryName(inputfile);
-                if (compiler.Run()) {
-                    // Process errors
-                    foreach (CompilerError e in compiler.Errors) {
-                        CompilerError newerror = e;
-
-                        // If the error's filename equals our temporary file,
-                        // use the lump name instead and prefix it with ?
-                        if (string.Compare(e.filename, inputfile, true) == 0)
-                            newerror.filename = "?" + reallumpname;
+			try {
+				// Initialize compiler
+				compiler = scriptconfig.Compiler.Create();
+			} catch(Exception e) {
+				// Fail
+				errors.Add(new CompilerError("Unable to initialize compiler. " + e.GetType().Name + ": " + e.Message));
+				return false;
+			}
+
+			try {
+				// Write lump data to temp script file in compiler's temp directory
+				inputfile = General.MakeTempFilename(compiler.Location, "tmp");
+				lump.Stream.Seek(0, SeekOrigin.Begin);
+				BinaryReader reader = new BinaryReader(lump.Stream);
+				File.WriteAllBytes(inputfile, reader.ReadBytes((int)lump.Stream.Length));
+			} catch(Exception e) {
+				// Fail
+				compiler.Dispose();
+				errors.Add(new CompilerError("Unable to write script to working file. " + e.GetType().Name + ": " + e.Message));
+				return false;
+			}
+
+			// Make random output filename
+			outputfile = General.MakeTempFilename(compiler.Location, "tmp");
+
+			// Run compiler
+			compiler.Parameters = scriptconfig.Parameters;
+			compiler.InputFile = Path.GetFileName(inputfile);
+			compiler.OutputFile = Path.GetFileName(outputfile);
+			compiler.SourceFile = sourcefile;
+			compiler.WorkingDirectory = Path.GetDirectoryName(inputfile);
+			if(compiler.Run()) {
+				// Process errors
+				foreach(CompilerError e in compiler.Errors) {
+					CompilerError newerror = e;
+
+					// If the error's filename equals our temporary file,
+					// use the lump name instead and prefix it with ?
+					if(string.Compare(e.filename, inputfile, true) == 0)
+						newerror.filename = "?" + reallumpname;
+
+					errors.Add(newerror);
+				}
 
-                        errors.Add(newerror);
-                    }
+				// No errors?
+				if(compiler.Errors.Length == 0) {
+					// Output file exists?
+					if(File.Exists(outputfile)) {
+						// Copy output file data into a lump?
+						if(!string.IsNullOrEmpty(scriptconfig.ResultLump)) {
+							// Do that now then
+							try {
+								filedata = File.ReadAllBytes(outputfile);
+							} catch(Exception e) {
+								// Fail
+								compiler.Dispose();
+								errors.Add(new CompilerError("Unable to read compiler output file. " + e.GetType().Name + ": " + e.Message));
+								return false;
+							}
+
+							// Store data
+							MemoryStream stream = new MemoryStream(filedata);
+							SetLumpData(scriptconfig.ResultLump, stream);
+						}
+					}
+				}
 
-                    // No errors?
-                    if (compiler.Errors.Length == 0) {
-                        // Output file exists?
-                        if (File.Exists(outputfile)) {
-                            // Copy output file data into a lump?
-                            if (!string.IsNullOrEmpty(scriptconfig.ResultLump)) {
-                                // Do that now then
-                                try {
-                                    filedata = File.ReadAllBytes(outputfile);
-                                } catch (Exception e) {
-                                    // Fail
-                                    compiler.Dispose();
-                                    errors.Add(new CompilerError("Unable to read compiler output file. " + e.GetType().Name + ": " + e.Message));
-                                    return false;
-                                }
-
-                                // Store data
-                                MemoryStream stream = new MemoryStream(filedata);
-                                SetLumpData(scriptconfig.ResultLump, stream);
-                            }
-                        }
-                    }
+				// Clean up
+				compiler.Dispose();
 
-                    // Clean up
-                    compiler.Dispose();
+				// Done
+				return true;
+			}
 
-                    // Done
-                    return true;
-                } else {
-                    // Fail
-                    compiler.Dispose();
-                    errors = null;
-                    return false;
-                }
-            } else {
-                // No compiler to run for this script type
-                return true;
-            }
+			// Fail
+			compiler.Dispose();
+			errors = null;
+			return false;
         }
 
         // This clears all compiler errors
@@ -1425,7 +1437,16 @@ namespace CodeImp.DoomBuilder {
                         AcsParserSE parser = new AcsParserSE();
                         parser.OnInclude = updateScriptsFromLocation;
                         parser.Parse(stream, "SCRIPTS", true);
-                        namedScripts.AddRange(parser.NamedScripts);
+
+						if(parser.NamedScripts.Count > 0 && (FormatInterface is DoomMapSetIO || FormatInterface is HexenMapSetIO)) {
+							List<string> names = new List<string>();
+							foreach(ScriptItem item in parser.NamedScripts)
+								names.Add("'" + item.Name + "'");
+							General.ErrorLogger.Add(ErrorType.Warning, "Current map format doesn't support named scripts! Following scripts will not work:" + string.Join(", ", names.ToArray()));
+						} else {
+							namedScripts.AddRange(parser.NamedScripts);
+						}
+
                         numberedScripts.AddRange(parser.NumberedScripts);
                         scriptincludes.AddRange(parser.Includes);
                     }
@@ -1611,6 +1632,10 @@ namespace CodeImp.DoomBuilder {
                 General.WriteLogLine("Initializing map format interface " + config.FormatInterface + "...");
                 io = MapSetIO.Create(config.FormatInterface, tempwad, this);
 
+				//mxd. Some lumps may've become unneeded during map format conversion. 
+				if(oldFormatInterface != config.FormatInterface)
+					removeUnneededLumps(tempwad, TEMP_MAP_HEADER);
+
                 // Create required lumps if they don't exist yet
                 CreateRequiredLumps(tempwad, TEMP_MAP_HEADER);
 
@@ -1626,6 +1651,7 @@ namespace CodeImp.DoomBuilder {
 					foreach(Thing t in General.Map.Map.Things) t.TranslateToUDMF();
 				}
 				General.Map.Map.UpdateCustomLinedefColors();
+				UpdateScriptNames(); //mxd
 
                 // Update interface
                 General.MainWindow.SetupInterface();
diff --git a/Source/Core/IO/SerializerStream.cs b/Source/Core/IO/SerializerStream.cs
index c8c8e5c5e..1cf2d494f 100644
--- a/Source/Core/IO/SerializerStream.cs
+++ b/Source/Core/IO/SerializerStream.cs
@@ -32,7 +32,7 @@ namespace CodeImp.DoomBuilder.IO
 
 		#region ================== Variables
 
-		private Stream stream;
+		//private Stream stream;
 		private BinaryWriter writer;
 		private Dictionary<string, ushort> stringstable;
 
@@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.IO
 		public SerializerStream(Stream stream)
 		{
 			// Initialize
-			this.stream = stream;
+			//this.stream = stream;
 			this.writer = new BinaryWriter(stream);
 			this.stringstable = new Dictionary<string, ushort>();
 		}
diff --git a/Source/Core/Resources/Actions.cfg b/Source/Core/Resources/Actions.cfg
index e7b1f95e2..2e4034968 100644
--- a/Source/Core/Resources/Actions.cfg
+++ b/Source/Core/Resources/Actions.cfg
@@ -68,6 +68,18 @@ openmap
 	allowscroll = false;
 }
 
+//mxd
+openmapincurrentwad
+{
+	title = "Open Map in current WAD";
+	category = "file";
+	description = "Opens an existing map from already loaded WAD file for viewing or modifying.";
+	allowkeys = true;
+	allowmouse = false;
+	allowscroll = false;
+	default = 196687; //Ctrl-Shift-O
+}
+
 closemap
 {
 	title = "Close Map";
diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs
index b4353c0a8..3061f4079 100644
--- a/Source/Core/VisualModes/VisualMode.cs
+++ b/Source/Core/VisualModes/VisualMode.cs
@@ -47,7 +47,7 @@ namespace CodeImp.DoomBuilder.VisualModes
 		
 		// Graphics
 		protected IRenderer3D renderer;
-		private Renderer3D renderer3d;
+		//private Renderer3D renderer3d;
 		
 		// Options
 		private bool processgeometry;
@@ -101,7 +101,7 @@ namespace CodeImp.DoomBuilder.VisualModes
 		{
 			// Initialize
 			this.renderer = General.Map.Renderer3D;
-			this.renderer3d = (Renderer3D)General.Map.Renderer3D;
+			//this.renderer3d = (Renderer3D)General.Map.Renderer3D;
 			this.blockmap = new VisualBlockMap();
 			this.allsectors = new Dictionary<Sector, VisualSector>(General.Map.Map.Sectors.Count);
 			this.allthings = new Dictionary<Thing,VisualThing>(General.Map.Map.Things.Count);
diff --git a/Source/Core/Windows/MainForm.Designer.cs b/Source/Core/Windows/MainForm.Designer.cs
index 06ed6d9f9..a5f43c71a 100644
--- a/Source/Core/Windows/MainForm.Designer.cs
+++ b/Source/Core/Windows/MainForm.Designer.cs
@@ -1,3 +1,5 @@
+using CodeImp.DoomBuilder.Controls;
+
 namespace CodeImp.DoomBuilder.Windows
 {
 	partial class MainForm
@@ -51,6 +53,7 @@ namespace CodeImp.DoomBuilder.Windows
 			this.menufile = new System.Windows.Forms.ToolStripMenuItem();
 			this.itemnewmap = new System.Windows.Forms.ToolStripMenuItem();
 			this.itemopenmap = new System.Windows.Forms.ToolStripMenuItem();
+			this.itemopenmapincurwad = new System.Windows.Forms.ToolStripMenuItem();
 			this.itemclosemap = new System.Windows.Forms.ToolStripMenuItem();
 			this.itemsavemap = new System.Windows.Forms.ToolStripMenuItem();
 			this.itemsavemapas = new System.Windows.Forms.ToolStripMenuItem();
@@ -295,13 +298,13 @@ namespace CodeImp.DoomBuilder.Windows
 			// 
 			this.seperatorfileopen.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
 			this.seperatorfileopen.Name = "seperatorfileopen";
-			this.seperatorfileopen.Size = new System.Drawing.Size(199, 6);
+			this.seperatorfileopen.Size = new System.Drawing.Size(220, 6);
 			// 
 			// seperatorfilerecent
 			// 
 			this.seperatorfilerecent.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
 			this.seperatorfilerecent.Name = "seperatorfilerecent";
-			this.seperatorfilerecent.Size = new System.Drawing.Size(199, 6);
+			this.seperatorfilerecent.Size = new System.Drawing.Size(220, 6);
 			// 
 			// seperatoreditgrid
 			// 
@@ -379,6 +382,7 @@ namespace CodeImp.DoomBuilder.Windows
 			this.menufile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.itemnewmap,
             this.itemopenmap,
+            this.itemopenmapincurwad,
             this.itemclosemap,
             this.seperatorfileopen,
             this.itemsavemap,
@@ -397,7 +401,7 @@ namespace CodeImp.DoomBuilder.Windows
 			this.itemnewmap.Image = global::CodeImp.DoomBuilder.Properties.Resources.File;
 			this.itemnewmap.Name = "itemnewmap";
 			this.itemnewmap.ShortcutKeyDisplayString = "";
-			this.itemnewmap.Size = new System.Drawing.Size(202, 22);
+			this.itemnewmap.Size = new System.Drawing.Size(223, 22);
 			this.itemnewmap.Tag = "builder_newmap";
 			this.itemnewmap.Text = "&New Map";
 			this.itemnewmap.Click += new System.EventHandler(this.InvokeTaggedAction);
@@ -406,15 +410,23 @@ namespace CodeImp.DoomBuilder.Windows
 			// 
 			this.itemopenmap.Image = global::CodeImp.DoomBuilder.Properties.Resources.OpenMap;
 			this.itemopenmap.Name = "itemopenmap";
-			this.itemopenmap.Size = new System.Drawing.Size(202, 22);
+			this.itemopenmap.Size = new System.Drawing.Size(223, 22);
 			this.itemopenmap.Tag = "builder_openmap";
 			this.itemopenmap.Text = "&Open Map...";
 			this.itemopenmap.Click += new System.EventHandler(this.InvokeTaggedAction);
 			// 
+			// itemopenmapincurwad
+			// 
+			this.itemopenmapincurwad.Name = "itemopenmapincurwad";
+			this.itemopenmapincurwad.Size = new System.Drawing.Size(223, 22);
+			this.itemopenmapincurwad.Tag = "builder_openmapincurrentwad";
+			this.itemopenmapincurwad.Text = "Open Map in current &WAD...";
+			this.itemopenmapincurwad.Click += new System.EventHandler(this.InvokeTaggedAction);
+			// 
 			// itemclosemap
 			// 
 			this.itemclosemap.Name = "itemclosemap";
-			this.itemclosemap.Size = new System.Drawing.Size(202, 22);
+			this.itemclosemap.Size = new System.Drawing.Size(223, 22);
 			this.itemclosemap.Tag = "builder_closemap";
 			this.itemclosemap.Text = "&Close Map";
 			this.itemclosemap.Click += new System.EventHandler(this.InvokeTaggedAction);
@@ -423,7 +435,7 @@ namespace CodeImp.DoomBuilder.Windows
 			// 
 			this.itemsavemap.Image = global::CodeImp.DoomBuilder.Properties.Resources.SaveMap;
 			this.itemsavemap.Name = "itemsavemap";
-			this.itemsavemap.Size = new System.Drawing.Size(202, 22);
+			this.itemsavemap.Size = new System.Drawing.Size(223, 22);
 			this.itemsavemap.Tag = "builder_savemap";
 			this.itemsavemap.Text = "&Save Map";
 			this.itemsavemap.Click += new System.EventHandler(this.InvokeTaggedAction);
@@ -431,7 +443,7 @@ namespace CodeImp.DoomBuilder.Windows
 			// itemsavemapas
 			// 
 			this.itemsavemapas.Name = "itemsavemapas";
-			this.itemsavemapas.Size = new System.Drawing.Size(202, 22);
+			this.itemsavemapas.Size = new System.Drawing.Size(223, 22);
 			this.itemsavemapas.Tag = "builder_savemapas";
 			this.itemsavemapas.Text = "Save Map &As...";
 			this.itemsavemapas.Click += new System.EventHandler(this.InvokeTaggedAction);
@@ -439,7 +451,7 @@ namespace CodeImp.DoomBuilder.Windows
 			// itemsavemapinto
 			// 
 			this.itemsavemapinto.Name = "itemsavemapinto";
-			this.itemsavemapinto.Size = new System.Drawing.Size(202, 22);
+			this.itemsavemapinto.Size = new System.Drawing.Size(223, 22);
 			this.itemsavemapinto.Tag = "builder_savemapinto";
 			this.itemsavemapinto.Text = "Save Map &Into...";
 			this.itemsavemapinto.Click += new System.EventHandler(this.InvokeTaggedAction);
@@ -448,19 +460,19 @@ namespace CodeImp.DoomBuilder.Windows
 			// 
 			this.seperatorfilesave.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
 			this.seperatorfilesave.Name = "seperatorfilesave";
-			this.seperatorfilesave.Size = new System.Drawing.Size(199, 6);
+			this.seperatorfilesave.Size = new System.Drawing.Size(220, 6);
 			// 
 			// itemnorecent
 			// 
 			this.itemnorecent.Enabled = false;
 			this.itemnorecent.Name = "itemnorecent";
-			this.itemnorecent.Size = new System.Drawing.Size(202, 22);
+			this.itemnorecent.Size = new System.Drawing.Size(223, 22);
 			this.itemnorecent.Text = "No recently opened files";
 			// 
 			// itemexit
 			// 
 			this.itemexit.Name = "itemexit";
-			this.itemexit.Size = new System.Drawing.Size(202, 22);
+			this.itemexit.Size = new System.Drawing.Size(223, 22);
 			this.itemexit.Text = "E&xit";
 			this.itemexit.Click += new System.EventHandler(this.itemexit_Click);
 			// 
@@ -2530,5 +2542,6 @@ namespace CodeImp.DoomBuilder.Windows
 		private System.Windows.Forms.ToolStripMenuItem screenshotToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem editAreaScreenshotToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem itemShortcutReference;
+		private System.Windows.Forms.ToolStripMenuItem itemopenmapincurwad;
 	}
 }
\ No newline at end of file
diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs
index 2b10d1420..195a544cf 100644
--- a/Source/Core/Windows/MainForm.cs
+++ b/Source/Core/Windows/MainForm.cs
@@ -2124,6 +2124,7 @@ namespace CodeImp.DoomBuilder.Windows
 			itemsavemapas.Enabled = (General.Map != null);
 			itemsavemapinto.Enabled = (General.Map != null);
 			itemtestmap.Enabled = (General.Map != null);
+			itemopenmapincurwad.Enabled = (General.Map != null); //mxd
 
 			// Toolbar icons
 			buttonnewmap.Enabled = itemnewmap.Enabled;
diff --git a/Source/Plugins/BuilderModes/Interface/PreferencesForm.cs b/Source/Plugins/BuilderModes/Interface/PreferencesForm.cs
index 525754846..fed9be645 100644
--- a/Source/Plugins/BuilderModes/Interface/PreferencesForm.cs
+++ b/Source/Plugins/BuilderModes/Interface/PreferencesForm.cs
@@ -27,7 +27,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 	{
 		#region ================== Variables
 
-		private PreferencesController controller;
+		//private PreferencesController controller;
 
 		#endregion
 
@@ -99,7 +99,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		// This sets up the form with the preferences controller
 		public void Setup(PreferencesController controller)
 		{
-			this.controller = controller;
+			//this.controller = controller;
 
 			// Add tab pages
 			foreach(TabPage p in tabs.TabPages)
diff --git a/Source/Plugins/ColorPicker/Windows/LightColorPicker.cs b/Source/Plugins/ColorPicker/Windows/LightColorPicker.cs
index 9b373aa98..3b30f1a89 100644
--- a/Source/Plugins/ColorPicker/Windows/LightColorPicker.cs
+++ b/Source/Plugins/ColorPicker/Windows/LightColorPicker.cs
@@ -287,12 +287,11 @@ namespace CodeImp.DoomBuilder.ColorPicker.Windows {
 
         //this is called only once
         private Color getThingColor(Thing thing) {
-            if (thing.Type == 1502) { //vavoom light
+            if (thing.Type == 1502) //vavoom light
                 return Color.White;
-            } else if (thing.Type == 1503) { //vavoom colored light
+			if (thing.Type == 1503)  //vavoom colored light
                 return Color.FromArgb((byte)thing.Args[1], (byte)thing.Args[2], (byte)thing.Args[3]);
-            }
-            return Color.FromArgb((byte)thing.Args[0], (byte)thing.Args[1], (byte)thing.Args[2]); ;
+            return Color.FromArgb((byte)thing.Args[0], (byte)thing.Args[1], (byte)thing.Args[2]);
         }
 
         //this sets data to use as a reference for relative mode
-- 
GitLab