public virtual int[] GetFloorMovementBound(WAD wad, SECTORS sector) { return(new int[2] { sector.floorHeight, sector.floorHeight }); }
public override int[] GetFloorMovementBound(WAD wad, SECTORS sector) { int[] bound = new int[2]; switch (target) { case FloorTarget.LowestNeighborFloor: if (direction == Direction.Up) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; sector.neighbors.ForEach(n => bound[0] = Math.Min(bound[0], n.floorHeight)); bound[1] = sector.floorHeight; break; case FloorTarget.NextNeighborFloor: if (direction == Direction.Up) { bound[0] = sector.floorHeight; bound[1] = sector.floorHeight; if (repeatable == Repeatable.Multiple) { sector.neighbors.ForEach(n => bound[1] = Math.Max(bound[1], n.floorHeight)); } else { int height = int.MaxValue; sector.neighbors.ForEach(n => height = (n.floorHeight > sector.floorHeight) ? Math.Min(height, n.floorHeight) : height); if (height < int.MaxValue) { bound[1] = height; } } } else if (direction == Direction.Down) { bound[0] = sector.floorHeight; bound[1] = sector.floorHeight; if (repeatable == Repeatable.Multiple) { sector.neighbors.ForEach(n => bound[0] = Math.Min(bound[0], n.floorHeight)); } else { int height = int.MaxValue; sector.neighbors.ForEach(n => height = (n.floorHeight < sector.floorHeight) ? Math.Max(height, n.floorHeight) : height); if (height < int.MaxValue) { bound[0] = height; } } } break; case FloorTarget.LowestNeighborCeiling: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = sector.ceilingHeight; sector.neighbors.ForEach(n => bound[1] = Math.Min(bound[1], n.ceilingHeight)); break; case FloorTarget.LowestNeighborCeilingMinus8: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = sector.ceilingHeight - 8; sector.neighbors.ForEach(n => bound[1] = Math.Min(bound[1], n.ceilingHeight - 8)); break; case FloorTarget.HighestNeighborFloor: if (direction == Direction.Up) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = -32000; sector.neighbors.ForEach(n => bound[0] = Math.Max(bound[0], n.floorHeight)); bound[1] = sector.floorHeight; break; case FloorTarget.HighestNeighborFloorPlus8: if (direction == Direction.Up) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = -32000 + 8; sector.neighbors.ForEach(n => bound[0] = Math.Max(bound[0], n.floorHeight + 8)); bound[1] = sector.floorHeight; break; case FloorTarget.Ceiling: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = sector.ceilingHeight; break; case FloorTarget.Absolute24: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = (repeatable == Repeatable.Multiple) ? sector.ceilingHeight : sector.floorHeight + 24; break; case FloorTarget.Absolute32: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = (repeatable == Repeatable.Multiple) ? sector.ceilingHeight : sector.floorHeight + 32; break; case FloorTarget.Absolute512: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = (repeatable == Repeatable.Multiple) ? sector.ceilingHeight : sector.floorHeight + 512; break; case FloorTarget.AbsShortestLowerTexture: if (direction == Direction.Down) { throw new Exception("Unexpected LineDefFloorType direction!"); } bound[0] = sector.floorHeight; bound[1] = sector.floorHeight; int texHeight = int.MaxValue; foreach (LINEDEFS line in sector.lines) { if (line.side1 != null && wad.textures.ContainsKey(line.side1.lowTex)) { texHeight = Math.Min(texHeight, wad.textures[line.side1.lowTex].mainTexture.height); } if (line.side2 != null && wad.textures.ContainsKey(line.side2.lowTex)) { texHeight = Math.Min(texHeight, wad.textures[line.side2.lowTex].mainTexture.height); } } if (texHeight < int.MaxValue) { bound[1] = (repeatable == Repeatable.Multiple) ? sector.ceilingHeight : sector.floorHeight + texHeight; } break; case FloorTarget.None: bound[0] = sector.floorHeight; bound[1] = sector.ceilingHeight; break; default: throw new Exception("Unexpected LineDefFloorType target!"); } return(bound); }
// OK clicked private void apply_Click(object sender, EventArgs e) { Configuration newcfg; WAD sourcewad; bool conflictingname; // Configuration selected? if (config.SelectedIndex == -1) { // Select a configuration! MessageBox.Show(this, "Please select a game configuration to use for editing your map.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); config.Focus(); return; } // Level name empty? if (levelname.Text.Length == 0) { // Enter a level name! MessageBox.Show(this, "Please enter a level name for your map.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); levelname.Focus(); return; } // Collect information ConfigurationInfo configinfo = General.Configs[config.SelectedIndex]; DataLocationList locations = datalocations.GetResources(); // When making a new map, check if we should warn the user for missing resources if (newmap && (locations.Count == 0) && (configinfo.Resources.Count == 0)) { if (MessageBox.Show(this, "You are about to make a map without selecting any resources. Textures, flats and " + "sprites may not be shown correctly or may not show up at all. Do you want to continue?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } } // Next checks are only for maps that are already opened if (!newmap) { // Now we check if the map name the user has given does already exist in the source WAD file // We have to warn the user about that, because it would create a level name conflict in the WAD // Level name changed and the map exists in a source wad? if ((levelname.Text != options.CurrentName) && (General.Map != null) && (General.Map.FilePathName != "") && File.Exists(General.Map.FilePathName)) { // Open the source wad file to check for conflicting name sourcewad = new WAD(General.Map.FilePathName, true); conflictingname = (sourcewad.FindLumpIndex(levelname.Text) > -1); sourcewad.Dispose(); // Names conflict? if (conflictingname) { // Show warning! if (General.ShowWarningMessage("The map name \"" + levelname.Text + "\" is already in use by another map or data lump in the source WAD file. Saving your map with this name will cause conflicting data lumps in the WAD file. Do you want to continue?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } } } // When the user changed the configuration to one that has a different read/write interface, // we have to warn the user that the map may not be compatible. // Configuration changed? if ((options.ConfigFile != "") && (General.Configs[config.SelectedIndex].Filename != options.ConfigFile)) { // Load the new cfg file newcfg = General.LoadGameConfiguration(General.Configs[config.SelectedIndex].Filename); if (newcfg == null) { return; } // Check if the config uses a different IO interface if (newcfg.ReadSetting("formatinterface", "") != General.Map.Config.FormatInterface) { // Warn the user about IO interface change if (General.ShowWarningMessage("The game configuration you selected uses a different file format than your current map. Because your map was not designed for this format it may cause the map to work incorrectly in the game. Do you want to continue?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.No) { // Reset to old configuration for (int i = 0; i < config.Items.Count; i++) { // Is this configuration the old config? if (string.Compare(General.Configs[i].Filename, options.ConfigFile, true) == 0) { // Select this item config.SelectedIndex = i; } } return; } } } } // Apply changes options.ClearResources(); options.ConfigFile = General.Configs[config.SelectedIndex].Filename; options.CurrentName = levelname.Text.Trim().ToUpper(); options.StrictPatches = strictpatches.Checked; options.CopyResources(datalocations.GetResources()); // Reset default drawing textures General.Settings.DefaultTexture = null; General.Settings.DefaultFloorTexture = null; General.Settings.DefaultCeilingTexture = null; // Hide window this.DialogResult = DialogResult.OK; this.Close(); }
// This loads the settings and attempt to find a suitable config private void LoadSettings() { string gameconfig; int index; // Busy Cursor.Current = Cursors.WaitCursor; // Check if the file exists if (!File.Exists(filepathname)) { // WAD file does not exist MessageBox.Show(this, "Could not open the WAD file: The file does not exist.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; this.Close(); return; } try { // Open the WAD file wadfile = new WAD(filepathname, true); } catch (Exception) { // Unable to open WAD file (or its config) MessageBox.Show(this, "Could not open the WAD file for reading. Please make sure the file you selected is valid and is not in use by any other application.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); if (wadfile != null) { wadfile.Dispose(); } this.DialogResult = DialogResult.Cancel; this.Close(); return; } // Open the Map Settings configuration string dbsfile = filepathname.Substring(0, filepathname.Length - 4) + ".dbs"; if (File.Exists(dbsfile)) { try { mapsettings = new Configuration(dbsfile, true); } catch (Exception) { mapsettings = new Configuration(true); } } else { mapsettings = new Configuration(true); } // Check strict patches box, check what game configuration is preferred if (options != null) { strictpatches.Checked = options.StrictPatches; gameconfig = options.ConfigFile; } else { strictpatches.Checked = mapsettings.ReadSetting("strictpatches", false); gameconfig = mapsettings.ReadSetting("gameconfig", ""); } //mxd. Fill script compilers list foreach (KeyValuePair <string, ScriptConfiguration> group in General.CompiledScriptConfigs) { scriptcompiler.Items.Add(group.Value); } // Go for all configurations foreach (ConfigurationInfo info in General.Configs) { // Add config name to list index = config.Items.Add(info); // Select this item if (info.Filename == gameconfig) { config.SelectedIndex = index; } } // Still no configuration selected? if (config.SelectedIndex == -1) { //mxd. Then go for all ENABLED configurations with resources to find a suitable one foreach (ConfigurationInfo info in General.Configs) { // Check if a resource location is set for this configuration, if so, match the wad against this configuration if (info.Enabled && info.Resources.Count > 0 && MatchConfiguration(info.Configuration, wadfile)) { //mxd. Already added? index = config.Items.IndexOf(info); // Select or add and select this item config.SelectedIndex = (index != -1 ? index : config.Items.Add(info)); break; } } } //mxd. Still no configuration selected? if (config.SelectedIndex == -1) { // Then go for all DISABLED configurations with resources to find a suitable one foreach (ConfigurationInfo info in General.Configs) { // Check if a resource location is set for this configuration, if so, match the wad against this configuration if (!info.Enabled && info.Resources.Count > 0 && MatchConfiguration(info.Configuration, wadfile)) { //mxd. Already added? index = config.Items.IndexOf(info); // Select or add and select this item config.SelectedIndex = (index != -1 ? index : config.Items.Add(info)); break; } } } //mxd. Still no configuration selected? if (config.SelectedIndex == -1) { //mxd. Then go for all ENABLED configurations without resources to find a suitable one foreach (ConfigurationInfo info in General.Configs) { // Check if a resource location is not set for this configuration, if so, match the wad against this configuration if (info.Enabled && info.Resources.Count == 0 && MatchConfiguration(info.Configuration, wadfile)) { //mxd. Already added? index = config.Items.IndexOf(info); // Select or add and select this item config.SelectedIndex = (index != -1 ? index : config.Items.Add(info)); break; } } } //mxd. Still no configuration selected? if (config.SelectedIndex == -1) { // Then go for all DISABLED configurations without resources to find a suitable one foreach (ConfigurationInfo info in General.Configs) { // Check if a resource location is not set for this configuration, if so, match the wad against this configuration if (!info.Enabled && info.Resources.Count == 0 && MatchConfiguration(info.Configuration, wadfile)) { //mxd. Already added? index = config.Items.IndexOf(info); // Select or add and select this item config.SelectedIndex = (index != -1 ? index : config.Items.Add(info)); break; } } } // [ZZ] dispose of wadfile wadfile.Dispose(); //mxd. Bail out if still no dice... if (config.SelectedIndex == -1 || mapslist.Items.Count == 0) { General.ShowWarningMessage("Unable to find maps using any game configuration.\nDoes this wad contain any maps at all?..", MessageBoxButtons.OK); cancel_Click(this, EventArgs.Empty); } else { // Show the window this.Opacity = 1; } // Done Cursor.Current = Cursors.Default; }
// mxd. This matches a WAD file with the specified game configuration // by checking if the specific lumps are detected private static bool MatchConfiguration(Configuration cfg, WAD wadfile) { int lumpsrequired = 0; // Get the map lump names IDictionary maplumpnames = cfg.ReadSetting("maplumpnames", new Hashtable()); // Count how many required lumps we have to find foreach (DictionaryEntry ml in maplumpnames) { // Ignore the map header (it will not be found because the name is different) if (ml.Key.ToString() != MapManager.CONFIG_MAP_HEADER) { // Read lump setting and count it if (cfg.ReadSetting("maplumpnames." + ml.Key + ".required", false)) { lumpsrequired++; } } } // Go for all the lumps in the wad for (int scanindex = 0; scanindex < (wadfile.Lumps.Count - 1); scanindex++) { // Make sure this lump is not part of the map. if (!maplumpnames.Contains(wadfile.Lumps[scanindex].Name)) { // Reset check int lumpsfound = 0; int checkoffset = 1; // Continue while still within bounds and lumps are still recognized while (((scanindex + checkoffset) < wadfile.Lumps.Count) && maplumpnames.Contains(wadfile.Lumps[scanindex + checkoffset].Name)) { string lumpname = wadfile.Lumps[scanindex + checkoffset].Name; //mxd. Lump cannot present in current map format, fail this check if (cfg.ReadSetting("maplumpnames." + lumpname + ".forbidden", false)) { lumpsfound = -1; break; } // Count the lump when it is marked as required if (cfg.ReadSetting("maplumpnames." + lumpname + ".required", false)) { lumpsfound++; } // Check the next lump checkoffset++; } // Map found? Let's call it a day :) if (lumpsfound >= lumpsrequired) { return(true); } } } return(false); }
public static void IOS(string[] args) { if (args.Length < 3) { IOS_help(); return; } string input = args[1]; string output = ""; bool fs = false; bool es = false; bool np = false; bool vp = false; int slot = -1; int version = -1; //Check if file exists if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_FILE_ERR"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E81); } else { Environment.Exit(0x00000003); } return; } //Get parameters for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-FS": fs = true; break; case "-ES": es = true; break; case "-NP": np = true; break; case "-VP": vp = true; break; case "-SLOT": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No slot set"); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_NO_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E89); } else { Environment.Exit(0x0000000B); } return; } if (!int.TryParse(args[i + 1], out slot)) { Console.WriteLine("Invalid slot {0}...", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8A); } else { Environment.Exit(0x0000000C); } return; } if (slot < 3 || slot > 255) { Console.WriteLine("Invalid slot {0}...", slot); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8A); } else { Environment.Exit(0x0000000C); } return; } break; case "-S": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No slot set"); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_NO_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E89); } else { Environment.Exit(0x0000000B); } return; } if (!int.TryParse(args[i + 1], out slot)) { Console.WriteLine("Invalid slot {0}...", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8A); } else { Environment.Exit(0x0000000C); } return; } if (slot < 3 || slot > 255) { Console.WriteLine("Invalid slot {0}...", slot); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_SLOT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8A); } else { Environment.Exit(0x0000000C); } return; } break; case "-V": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No version set"); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_NO_VERSION"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8B); } else { Environment.Exit(0x0000000D); } return; } if (!int.TryParse(args[i + 1], out version)) { Console.WriteLine("Invalid version {0}...", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_VERSION"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8C); } else { Environment.Exit(0x0000000E); } return; } if (version < 0 || version > 65535) { Console.WriteLine("Invalid version {0}...", version); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_INVALID_VERSION"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8C); } else { Environment.Exit(0x0000000E); } return; } break; case "-O": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_NO_OUTPUT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8D); } else { Environment.Exit(0x0000000F); } return; } output = args[i + 1]; break; } } //Main part (most of it was borrowed from PatchIOS) try { WAD ios = new WAD { KeepOriginalFooter = true }; if (BeQuiet.quiet > 2) { Console.Write("Loading File..."); } ios.LoadFile(input); if (BeQuiet.quiet > 2) { Console.Write("Done!\n"); } //Check if WAD is an IOS if ((ios.TitleID >> 32) != 1 || (ios.TitleID & 0xffffffff) > 255 || (ios.TitleID & 0xffffffff) < 3) { Console.WriteLine("Only IOS WADs can be patched..."); return; } IosPatcher patcher = new IosPatcher(); patcher.LoadIOS(ref ios); //apply patches if (fs == true) { if (BeQuiet.quiet > 2) { Console.WriteLine("Applying Fakesigning patch"); } patcher.PatchFakeSigning(); } if (es == true) { if (BeQuiet.quiet > 2) { Console.WriteLine("Applying ES_Identify patch"); } patcher.PatchEsIdentify(); } if (np == true) { if (BeQuiet.quiet > 2) { Console.WriteLine("Applying NAND permissions patch"); } patcher.PatchNandPermissions(); } if (vp == true) { if (BeQuiet.quiet > 2) { Console.WriteLine("Applying Version patch"); } patcher.PatchVP(); } if (slot > -1 || version > -1) { ios.FakeSign = true; } if (slot > -1) { if (BeQuiet.quiet > 2) { Console.WriteLine("Changing IOS slot to: {0}", slot); } ios.TitleID = (ulong)((1UL << 32) | (uint)slot); } if (version > -1) { if (BeQuiet.quiet > 2) { Console.WriteLine("Changing title version to: {0}", version); } ios.TitleVersion = (ushort)version; } //check if output was set if (output != "") { if (BeQuiet.quiet > 2) { Console.WriteLine("Saving to file: {0}", output); } ios.Save(output); } else { if (BeQuiet.quiet > 2) { Console.Write("Saving file..."); } if (output != "") { if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD") { output += ".wad"; } } ios.Save(input); if (BeQuiet.quiet > 2) { Console.Write("Done!\n"); } } if (BeQuiet.quiet > 1) { Console.WriteLine("Operation completed succesfully!"); } } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); Console.WriteLine("Error: SHARPII_NET_CORE_IOS_UNKNOWN"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E82); } else { Environment.Exit(0x00000004); } return; } return; }