private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string[] names = Enum.GetNames(typeof(TextureFormat)); for (int i = 0; i < names.Length; i++) { if (comboBox1.Text == names[i].ToString()) { if (listView1.FocusedItem != null) { map.RawInformation.ExternalMaps.OpenIOs(); map.OpenIO(); int tag = (int)listView1.FocusedItem.Tag; TextureFormat textureFormat = (TextureFormat)Enum.Parse(typeof(TextureFormat), names[i]); try { OutputMessenger.OutputMessage("Trying to view bitmap as format: " + textureFormat.ToString(), this); pictureBox1.Image = bi.GeneratePreview(tag, textureFormat); } catch { Bitmap image = new Bitmap(200, 200); Graphics graphics = Graphics.FromImage(image); graphics.Clear(Color.Gray); string text = "Error Previewing!"; SizeF ef = graphics.MeasureString(text, new Font(FontFamily.GenericSerif, 15f)); graphics.DrawString(text, new Font(FontFamily.GenericSerif, 15f), Brushes.Black, new PointF(100f - (ef.Width / 2f), 100f - (ef.Height / 2f))); pictureBox1.Image = image; } map.CloseIO(); map.RawInformation.ExternalMaps.CloseIOs(); } break; } } }
private void button1_Click(object sender, EventArgs e) { if (treeView1.SelectedNode.Nodes.Count > 0) { for (int i = 0; i < treeView1.SelectedNode.Nodes.Count; i++) { map.OpenIO(); int ident = int.Parse(treeView1.SelectedNode.Nodes[i].Tag.ToString()); int num3 = int.Parse(textBox1.Text); int tagIndexByIdent = map.GetTagIndexByIdent(ident); int num5 = map.Index_Items[tagIndexByIdent].Offset + num3; map.IO.In.BaseStream.Position = num5; a1.Text = map.IO.In.ReadInt32().ToString(); a2.Text = map.IO.In.ReadInt32().ToString(); a3.Text = map.IO.In.ReadInt32().ToString(); a4.Text = map.IO.In.ReadInt32().ToString(); map.CloseIO(); for (int j = 0; j < treeView2.SelectedNode.Nodes.Count; j++) { map2.OpenIO(); ident = int.Parse(treeView2.SelectedNode.Nodes[j].Tag.ToString()); num3 = int.Parse(textBox1.Text); tagIndexByIdent = map2.GetTagIndexByIdent(ident); num5 = map2.Index_Items[tagIndexByIdent].Offset + num3; map2.IO.In.BaseStream.Position = num5; b1.Text = map2.IO.In.ReadInt32().ToString(); b2.Text = map2.IO.In.ReadInt32().ToString(); b3.Text = map2.IO.In.ReadInt32().ToString(); b4.Text = map2.IO.In.ReadInt32().ToString(); map2.CloseIO(); string text = a1.Text; string str2 = a2.Text; string str3 = a3.Text; string str4 = a4.Text; string str5 = b1.Text; string str6 = b2.Text; string str7 = b3.Text; string str8 = b4.Text; if ((((text == str5) && (str2 == str6)) && (str3 == str7)) && (str4 == str8)) { treeView2.LabelEdit = true; string str9 = treeView1.SelectedNode.Nodes[i].Text; treeView2.SelectedNode.Nodes[j].Text = str9; treeView2.SelectedNode.Nodes[j].BeginEdit(); treeView2.SelectedNode.Nodes[j].EndEdit(false); int tag = (int)treeView2.SelectedNode.Nodes[j].Tag; string tagPath = treeView2.SelectedNode.Nodes[j].Text; tagNameList2.SetPath(tag, tagPath); tagNameList2.Save(); treeView2.LabelEdit = false; break; } } } if (treeView1.SelectedNode.Nodes.Count == 0) { MessageBox.Show("Select a Class"); } } }
public void LoadBitmapTag(HaloMap Map, int TagIndex) { map = Map; Map.OpenIO(); map.RawInformation.ExternalMaps.CreateIOs(); map.RawInformation.ExternalMaps.OpenIOs(); tagIndex = TagIndex; bi = BitmapFunctions.GetBitmapInfo(map, tagIndex); listView1.Items.Clear(); for (int i = 0; i < bi.bitmapList.Count; i++) { string[] items = new string[] { i.ToString(), bi.bitmapList[i].Height.ToString(), bi.bitmapList[i].Width.ToString(), $"0x{bi.bitmapList[i].RawLength:X}", bi.bitmapList[i].Format.ToString(), bi.bitmapList[i].Type.ToString() }; ListViewItem item = new ListViewItem(items) { Tag = i }; listView1.Items.Add(item); } if (listView1.Items.Count > 0) { listView1.FocusedItem = listView1.Items[0]; listView1_SelectedIndexChanged(null, null); } map.RawInformation.ExternalMaps.CloseIOs(); Map.CloseIO(); }
public static void LoadPluginValues(HaloMap Map, Panel parentPanel, int parentOffset) { if (!((parentOffset <= 0) | (parentOffset > Map.Map_Header.fileSize))) { EndianIO iO = Map.IO; for (int i = 0; i < parentPanel.Controls.Count; i++) { if (!((Map.IO != null) && Map.IO.Opened)) { Map.OpenIO(); } switch (parentPanel.Controls[i].Name) { case "uiTagBlock": ((uiTagBlock)parentPanel.Controls[i]).LoadStructure(Map, parentOffset); break; case "uiBitmask": ((uiBitmask)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiValue": ((uiValue)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiSlider": ((uiSlider)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiEnum": ((uiEnum)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiIdent": ((uiIdent)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiByteArray": ((uiByteArray)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiTagData": ((uiTagData)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiColor": ((uiColor)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; case "uiStringID": ((uiStringID)parentPanel.Controls[i]).LoadValue(Map, parentOffset); break; } } Map.CloseIO(); } }
public void LoadStructure(HaloMap map, int parentOffset) { //Set our map instance Map = map; //Make sure the IO is open if (!Map.IOisOpen) { //If it isn't. Then open it Map.OpenIO(); } //Move to the structure position Map.IO.In.BaseStream.Position = parentOffset + ReflexiveData.Offset; //Read the chunkcount and assign it. ReflexiveData.ChunkCount = Map.IO.In.ReadInt32(); //Read the memoryPointer and assign it ReflexiveData.MemoryPointer = Map.IO.In.ReadInt32(); //Apply the memory address modifier to get the file offset of the pointer ReflexiveData.Pointer = ReflexiveData.MemoryPointer - Map.MapHeader.mapMagic; //Clear the chunkcomboBox comboChunks.Items.Clear(); //If its a chunkcount of 0... if (ReflexiveData.ChunkCount <= 0 | ReflexiveData.ChunkCount > 100000 | ReflexiveData.Pointer < 0 | ReflexiveData.Pointer >= (int)Map.IO.In.BaseStream.Length) { //Disable the combobox comboChunks.Enabled = false; //Clear the combobox text if any remaining... comboChunks.Text = ""; //Disable the value panel. pnlValues.Enabled = false; //Quit this function return; } //Otherwise... if (ReflexiveData.ChunkCount > 0) { //Set our last real offset lastRealOffset = parentOffset + ReflexiveData.Offset; //Enable our controls. comboChunks.Enabled = true; pnlValues.Enabled = true; //Populate our chunkBox for (int i = 0; i < ReflexiveData.ChunkCount; i++) { comboChunks.Items.Add(i + ": " + ReflexiveData.Name.ToLower() + " chunk"); } //Select the first item. comboChunks.SelectedIndex = 0; } }
public void LoadStructure(HaloMap map, int parentOffset) { Map = map; if (!((Map.IO != null) && Map.IO.Opened)) { Map.OpenIO(); } Map.IO.In.BaseStream.Position = parentOffset + ReflexiveData.Offset; parentoffset = parentOffset; int num = Map.IO.In.ReadInt32(); ReflexiveData.ChunkCount = num; ReflexiveData.MemoryPointer = Map.IO.In.ReadInt32(); int num2 = ReflexiveData.MemoryPointer - Map.Map_Header.mapMagic; ReflexiveData.Pointer = num2; SIZE = ReflexiveData.Size; textBox1.Text = ReflexiveData.Size.ToString(); txtcount.Text = num.ToString(); txtoffset.Text = num2.ToString(); cmbxChunks.Items.Clear(); if ((((ReflexiveData.ChunkCount <= 0) | (ReflexiveData.ChunkCount > 0x186a0)) | (ReflexiveData.Pointer < 0)) | (ReflexiveData.Pointer >= ((int)Map.IO.In.BaseStream.Length))) { pnlHeader.Enabled = true; cmbxChunks.Enabled = false; cmbxChunks.Text = ""; pnlValues.Enabled = false; txtcount.Text = "0"; txtoffset.Text = "0"; } else if (ReflexiveData.ChunkCount > 0) { fullOffset = parentOffset + ReflexiveData.Offset; cmbxChunks.Enabled = true; pnlValues.Enabled = true; pnlHeader.Enabled = true; for (int i = 0; i < ReflexiveData.ChunkCount; i++) { cmbxChunks.Items.Add(i + " - " + (ReflexiveData.ChunkCount - 1)); } cmbxChunks.SelectedIndex = 0; } }
public BitmapInfo(HaloMap Map, int TagIndex) { map = Map; map.OpenIO(); // Get our bitmap info first map.IO.SeekTo(map.IndexItems[TagIndex].Offset + 96); int count = map.IO.In.ReadInt32(); int pointer = map.IO.In.ReadInt32() - map.MapHeader.mapMagic; bitmapList = new List <BitmapSubmap>(); map.IO.SeekTo(pointer); for (int x = 0; x < count; x++) { bitmapList.Add(new BitmapSubmap(map.IO.In)); } // Get our raw ID now map.IO.SeekTo(map.IndexItems[TagIndex].Offset + 140); count = map.IO.In.ReadInt32(); pointer = map.IO.In.ReadInt32() - map.MapHeader.mapMagic; rawIdTable1 = new List <int>(); map.IO.SeekTo(pointer); for (int x = 0; x < count; x++) { rawIdTable1.Add(map.IO.In.ReadInt32()); map.IO.In.ReadInt32(); } // Get our raw ID now map.IO.SeekTo(map.IndexItems[TagIndex].Offset + 152); count = map.IO.In.ReadInt32(); pointer = map.IO.In.ReadInt32() - map.MapHeader.mapMagic; rawIdTable2 = new List <int>(); map.IO.SeekTo(pointer); for (int x = 0; x < count; x++) { rawIdTable2.Add(map.IO.In.ReadInt32()); map.IO.In.ReadInt32(); } map.CloseIO(); }
public LocaleHandler(HaloMap map) { //Set our instance of our HaloMap class Map = map; //Open our IO Map.OpenIO(); #region Get Matg Index //Create an integer to hold our matg Index int matgIndex = -1; //Loop through all the tags for (int i = 0; i < Map.IndexItems.Count; i++) { //If this tag's class is matg... if (Map.IndexItems[i].Class == "matg") { //Then set the index matgIndex = i; //Break out of the loop. break; } } #endregion #region Get Table Information //Initialuze our Locale Table list LocaleTables = new List <LocaleTable>(); //Loop for each language...(there's 12) for (int i = 0; i < 12; i++) { //Create our table instance LocaleTable unicTable = new LocaleTable(); //Set our language for this instance unicTable.Language = (LanguageType)i; //If we did find a matg tag. if (matgIndex != -1) { //Make our IO go to the position to read our information for our table. if (Map.Halo_Map_Version == HaloMap.HaloMapVersion.Halo3Retail) { unicTable.Offset = Map.IndexItems[matgIndex].Offset + 452 + ((int)unicTable.Language * 68); } else if (Map.Halo_Map_Version == HaloMap.HaloMapVersion.Halo3ODST) { unicTable.Offset = Map.IndexItems[matgIndex].Offset + 508 + ((int)unicTable.Language * 68); } map.IO.SeekTo(unicTable.Offset); //Read our count unicTable.LocaleCount = Map.IO.In.ReadInt32(); //Read our size unicTable.LocaleTableSize = Map.IO.In.ReadInt32(); //Read our index offset unicTable.LocaleTableIndexOffset = Map.IO.In.ReadInt32() + Map.MapHeader.localeTableAddressModifier; //Read our locale table offset unicTable.LocaleTableOffset = Map.IO.In.ReadInt32() + Map.MapHeader.localeTableAddressModifier; } //Add the language to our list... LocaleTables.Add(unicTable); } #endregion #region Load Strings //Loop through the localeTables for (int currentTableIndex = 0; currentTableIndex < LocaleTables.Count; currentTableIndex++) { //Get our LocaleTable instance LocaleTable currentTable = LocaleTables[currentTableIndex]; //Go to the LocaleTableIndexOffset Map.IO.In.BaseStream.Position = currentTable.LocaleTableIndexOffset; //Initialize our LocaleStringList currentTable.LocaleStrings = new List <LocaleTable.LocaleString>(); //Loop for each localeString for (int currentLocaleIndex = 0; currentLocaleIndex < currentTable.LocaleCount; currentLocaleIndex++) { //Skip 4 bytes. Map.IO.In.BaseStream.Position += 4; //Initialize an instance of a locale string LocaleTable.LocaleString currentLocaleString = new LocaleTable.LocaleString(); //Read it's offset currentLocaleString.Offset = Map.IO.In.ReadInt32(); //Add it to the list of Locales currentTable.LocaleStrings.Add(currentLocaleString); } //Read our strings //Loop for each string. for (int currentLocaleIndex = 0; currentLocaleIndex < currentTable.LocaleCount; currentLocaleIndex++) { //Go to the offset to read the locale. Map.IO.In.BaseStream.Position = currentTable.LocaleTableOffset + currentTable.LocaleStrings[currentLocaleIndex].Offset; //If we aren't at the last string if (currentLocaleIndex != currentTable.LocaleCount - 1) { //Calculate the length with (nextStringOffset - thisStringOffset) currentTable.LocaleStrings[currentLocaleIndex].Length = currentTable.LocaleStrings[currentLocaleIndex + 1].Offset - (currentTable.LocaleStrings[currentLocaleIndex].Offset + 1); } //if we are at the last string else { //Calculate the length with (endOfTable - thisStringOffset) currentTable.LocaleStrings[currentLocaleIndex].Length = currentTable.LocaleTableSize - (currentTable.LocaleStrings[currentLocaleIndex].Offset + 1); } //Read the string according to our length. currentTable.LocaleStrings[currentLocaleIndex].Name = Map.IO.In.ReadAsciiString(currentTable.LocaleStrings[currentLocaleIndex].Length); } } #endregion //Close our IO Map.CloseIO(); }
public void SaveProject(string directory, int mapID) { //Copy the .map files #region Map File Copy //Get our map short filename array string[] temp = MapLocation.Split('\\'); string mapshortform = temp[temp.Length - 1]; if (directory + mapshortform != MapLocation) { //If the file exists... if (File.Exists(directory + mapshortform)) { //Delete it. File.Delete(directory + mapshortform); } //Copy the map to the save project directory File.Copy(MapLocation, directory + mapshortform); } //Open this map HaloMap map = new HaloMap(directory + mapshortform); //Create our tag indexer int scnr_index = -1; //Loop through each tag till we find our scnr for (int i = 0; i < map.IndexItems.Count; i++) { if (map.IndexItems[i].Class == "scnr") { scnr_index = i; break; } } //If our scnr index hasnt been set. if (scnr_index == -1) { throw new Exception("Could not find [scnr] tag in the map file. Cannot continue."); } //Open IO map.OpenIO(); //Go to this tag's offset + 8 map.IO.Out.BaseStream.Position = map.IndexItems[scnr_index].Offset + 8; //Write our map id map.IO.Out.Write(mapID); //Close IO map.CloseIO(); #endregion //Save the blf's. #region BLF Images //Base bitmap BLFImageFile blfimage = new BLFImageFile(); blfimage.BLFImage = Image_File; string blfStarterString = directory + "m_" + mapshortform.Substring(0, mapshortform.Length - 4); blfimage.SaveBLFImage(new FileStream(blfStarterString + ".blf", FileMode.Create), BLFImageFile.BLFImageType.BaseImage); blfimage.SaveBLFImage(new FileStream(blfStarterString + "_sm.blf", FileMode.Create), BLFImageFile.BLFImageType.Sm); BLFImageTransformer.BLF_ImageResults blfimageresults = BLFImageTransformer.CreateTransformedImages(Image_File); blfimage.BLFImage = blfimageresults.FilmBitmap; blfimage.SaveBLFImage(new FileStream(blfStarterString + "_film.blf", FileMode.Create), BLFImageFile.BLFImageType.Film); blfimage.BLFImage = blfimageresults.ClipBitmap; blfimage.SaveBLFImage(new FileStream(blfStarterString + "_clip.blf", FileMode.Create), BLFImageFile.BLFImageType.Clip); blfimage.BLFImage = blfimageresults.VariantBitmap; blfimage.SaveBLFImage(new FileStream(blfStarterString + "_variant.blf", FileMode.Create), BLFImageFile.BLFImageType.Variant); #endregion //Save the mapinfo #region Map Info Info_File.BLFHeader = new BLF_Header(); Info_File.BLFHeader.Map_ID = mapID; Info_File.SaveInfoFile(new FileStream(directory + mapshortform + "info", FileMode.Create)); #endregion //Done.. MessageBox.Show("Done."); }
/// <summary> /// This function renames a tag. /// </summary> /// <param name="tagIndex">The index of the tag to rename.</param> /// <param name="newName">The new name of the tag to rename as.</param> public void RenameTag(int tagIndex, string newName) { //Get our tag instance HaloMap.TagItem tagItem = map.IndexItems[tagIndex]; //Compare our string lengths.. if (tagItem.Name.Length == newName.Length) { //They are the same length. Let's write our new string. //Open our IO map.OpenIO(); //Go to our tag_name_index_entry map.IO.In.BaseStream.Position = map.MapHeader.fileTableIndexOffset + (tagIndex * 4); //Read our tagnameoffset int tagNameOffset = map.IO.In.ReadInt32() + map.MapHeader.fileTableOffset; //Go to this position map.IO.In.BaseStream.Position = tagNameOffset; //Write our tagname map.IO.Out.WriteAsciiString(newName, tagItem.Name.Length); //Close our IO map.CloseIO(); //Set our tagname. map.IndexItems[tagIndex].Name = newName; } else { //Calculate our table difference. int differenceInStringLength = (tagItem.Name.Length - newName.Length); int newTableSizeUnpadded = map.MapHeader.fileTableSize - differenceInStringLength; int newTableSize = newTableSizeUnpadded + ExtraFunctions.CalculatePadding(newTableSizeUnpadded, 0x1000); int oldTableSize = map.MapHeader.fileTableSize + ExtraFunctions.CalculatePadding(map.MapHeader.fileTableSize, 0x1000); int differenceInSize = oldTableSize - newTableSize; //Open our IO map.OpenIO(); //Go to our tag_name_index_entry map.IO.In.BaseStream.Position = map.MapHeader.fileTableIndexOffset + (tagIndex * 4); //Read our tagnameoffset int tagNameOffset = map.IO.In.ReadInt32() + map.MapHeader.fileTableOffset; //Loop for each tag_name_index after it. for (int i = tagIndex + 1; i < map.IndexHeader.tagCount; i++) { //Go to our tag_name_index_entry map.IO.In.BaseStream.Position = map.MapHeader.fileTableIndexOffset + (i * 4); //Read our tagindex int tagOff = map.IO.In.ReadInt32(); //Recalculate it. tagOff -= differenceInStringLength; //Go to our tag_name_index_entry map.IO.Out.BaseStream.Position = map.MapHeader.fileTableIndexOffset + (i * 4); //Write it map.IO.Out.Write(tagOff); } //Close our IO map.CloseIO(); //If it's any different. if (differenceInSize > 0) { ExtraFunctions.DeleteBytes(map.FileName, map.MapHeader.fileTableOffset + newTableSize, oldTableSize - newTableSize); } else { ExtraFunctions.InsertBytes(map.FileName, map.MapHeader.fileTableOffset + oldTableSize, newTableSize - oldTableSize); } //Open our IO map.OpenIO(); //Go to this position map.IO.Out.BaseStream.Position = tagNameOffset; //Write our tagname map.IO.Out.WriteAsciiString(newName, newName.Length); map.IO.Out.Write((byte)0); for (int i = tagIndex + 1; i < map.IndexHeader.tagCount; i++) { //Write the tagname map.IO.Out.WriteAsciiString(map.IndexItems[i].Name, map.IndexItems[i].Name.Length); map.IO.Out.Write((byte)0); } //For the rest of our table, write the padding. byte[] padding = new byte[newTableSize - newTableSizeUnpadded]; //Write our padding map.IO.Out.Write(padding); //Recalculate some header values. map.IO.Out.BaseStream.Position = 20; map.IO.Out.Write(((map.MapHeader.virtSegmentStart - differenceInSize) + map.MapHeader.headerMagic)); map.IO.Out.BaseStream.Position = 700; map.IO.Out.Write(newTableSizeUnpadded); map.IO.Out.BaseStream.Position = 704; map.IO.Out.Write(((map.MapHeader.fileTableIndexOffset - differenceInSize) + map.MapHeader.headerMagic)); map.IO.Out.BaseStream.Position = 1136; map.IO.Out.Write((map.MapHeader.RawTableOffset - differenceInSize)); map.IO.Out.BaseStream.Position = 1144; map.IO.Out.Write((map.MapHeader.localeTableAddressModifier - differenceInSize)); //Close our IO map.CloseIO(); //Reload our map map.Reload(); } }
public static void SaveChangedValues(HaloMap Map, Panel parentPanel, int parentOffset) { EndianIO iO = Map.IO; for (int i = 0; i < parentPanel.Controls.Count; i++) { if (!((Map.IO != null) && Map.IO.Opened)) { Map.OpenIO(); } switch (parentPanel.Controls[i].Name) { case "uiTagBlock": ((uiTagBlock)parentPanel.Controls[i]).SaveStructure(Map, parentOffset); break; case "uiBitmask": { uiBitmask bitmask = (uiBitmask)parentPanel.Controls[i]; if (bitmask.Editted) { bitmask.SaveValue(Map.IO, parentOffset); } break; } case "uiValue": { uiValue value2 = (uiValue)parentPanel.Controls[i]; if (value2.Editted) { value2.SaveValue(Map.IO, parentOffset); } break; } case "uiEnum": { uiEnum enum2 = (uiEnum)parentPanel.Controls[i]; if (enum2.Editted) { enum2.SaveValue(Map.IO, parentOffset); } break; } case "uiIdent": { uiIdent ident = (uiIdent)parentPanel.Controls[i]; if (ident.Editted) { ident.SaveValue(Map.IO, parentOffset); } break; } case "uiByteArray": { uiByteArray array = (uiByteArray)parentPanel.Controls[i]; if (array.Editted) { array.SaveValue(Map.IO, parentOffset); } break; } case "uiColor": { uiColor color = (uiColor)parentPanel.Controls[i]; if (color.Editted) { color.SaveValue(Map.IO, parentOffset); } break; } case "uiTagData": { uiTagData data = (uiTagData)parentPanel.Controls[i]; if (data.Editted) { data.SaveValue(Map.IO, parentOffset); } break; } case "uiStringID": { uiStringID gid = (uiStringID)parentPanel.Controls[i]; if (gid.Editted) { gid.SaveValue(Map.IO, parentOffset); } break; } } } Map.CloseIO(); }
public static void LoadPluginUIAndValues(HaloMap Map, List <mValue> ValueList, Panel parentPanel, int parentOffset, List <string> sid) { int y = 1; if (!((parentOffset <= 0) | (parentOffset > Map.Map_Header.fileSize))) { EndianIO iO = Map.IO; foreach (mValue value2 in ValueList) { uiTagBlock block; uiBitmask bitmask; uiByteArray array; uiColor color; uiComment comment; uiEnum enum2; uiStringID gid; uiIdent ident; uiTagData data; uiValue value3; uiSlider slider; if (!((Map.IO != null) && Map.IO.Opened)) { Map.OpenIO(); } if (value2.Visible | TagEditorSettings.Visibility_Settings.Invisibles) { switch (value2.Attributes) { case mValue.ObjectAttributes.Comment: if (TagEditorSettings.Visibility_Settings.Comments) { goto Label_02A1; } break; case mValue.ObjectAttributes.ByteArray: if (TagEditorSettings.Visibility_Settings.ByteArray) { goto Label_01EF; } break; case mValue.ObjectAttributes.ColorBlock8: case mValue.ObjectAttributes.ColorBlock16: case mValue.ObjectAttributes.ColorBlock32: case mValue.ObjectAttributes.ColorBlockF: if (TagEditorSettings.Visibility_Settings.Color) { goto Label_0248; } break; case mValue.ObjectAttributes.TagBlock: if (TagEditorSettings.Visibility_Settings.TagBlock) { goto Label_0120; } break; case mValue.ObjectAttributes.TagData: if (TagEditorSettings.Visibility_Settings.TagData) { goto Label_03FD; } break; case mValue.ObjectAttributes.TagReference: if (TagEditorSettings.Visibility_Settings.Ident) { goto Label_03A4; } break; case mValue.ObjectAttributes.StringID: if (TagEditorSettings.Visibility_Settings.StringID) { goto Label_0349; } break; case mValue.ObjectAttributes.Unicode: case mValue.ObjectAttributes.String: case mValue.ObjectAttributes.Float: case mValue.ObjectAttributes.Int16: case mValue.ObjectAttributes.UInt16: case mValue.ObjectAttributes.Int32: case mValue.ObjectAttributes.UInt32: case mValue.ObjectAttributes.Byte: case mValue.ObjectAttributes.None: if (TagEditorSettings.Visibility_Settings.Other) { goto Label_0456; } break; case mValue.ObjectAttributes.Bitmask8: case mValue.ObjectAttributes.Bitmask16: case mValue.ObjectAttributes.Bitmask32: if (TagEditorSettings.Visibility_Settings.Bitmasks) { goto Label_0196; } break; case mValue.ObjectAttributes.Enum8: case mValue.ObjectAttributes.Enum16: case mValue.ObjectAttributes.Enum32: if (TagEditorSettings.Visibility_Settings.Enum) { goto Label_02F0; } break; case mValue.ObjectAttributes.Undefined: if (TagEditorSettings.Visibility_Settings.Undefined) { value3 = new uiValue(value2); value3.LoadValue(Map, parentOffset); value3.Location = new Point(0, y); y += value3.Height; parentPanel.Controls.Add(value3); } break; case mValue.ObjectAttributes.Slider: if (TagEditorSettings.Visibility_Settings.Other) { goto Label_04AA; } break; } } continue; Label_0120: block = new uiTagBlock((mTagBlock)value2); block.Location = new Point(6, y); LoadPluginUI(((mTagBlock)value2).Values, block.returnValuePanel(), sid); block.LoadStructure(Map, parentOffset); block.ResizeTagBlock(); y += block.Height + 2; parentPanel.Controls.Add(block); continue; Label_0196: bitmask = new uiBitmask((mBitmask)value2); bitmask.LoadValue(Map, parentOffset); bitmask.Location = new Point(0, y); y += bitmask.Height; parentPanel.Controls.Add(bitmask); continue; Label_01EF: array = new uiByteArray((mByteArray)value2); array.LoadValue(Map, parentOffset); array.Location = new Point(0, y); y += array.Height; parentPanel.Controls.Add(array); continue; Label_0248: color = new uiColor((mColorBlock)value2); color.LoadValue(Map, parentOffset); color.Location = new Point(0, y); y += color.Height; parentPanel.Controls.Add(color); continue; Label_02A1: comment = new uiComment((mComment)value2); comment.Location = new Point(0, y); y += comment.Height; parentPanel.Controls.Add(comment); continue; Label_02F0: enum2 = new uiEnum((mEnum)value2); enum2.LoadValue(Map, parentOffset); enum2.Location = new Point(0, y); y += enum2.Height; parentPanel.Controls.Add(enum2); continue; Label_0349: gid = new uiStringID((mStringID)value2, sid); gid.LoadValue(Map, parentOffset); gid.Location = new Point(0, y); y += gid.Height; parentPanel.Controls.Add(gid); continue; Label_03A4: ident = new uiIdent((mTagReference)value2); ident.LoadValue(Map, parentOffset); ident.Location = new Point(0, y); y += ident.Height; parentPanel.Controls.Add(ident); continue; Label_03FD: data = new uiTagData((mTagData)value2); data.LoadValue(Map, parentOffset); data.Location = new Point(0, y); y += data.Height; parentPanel.Controls.Add(data); continue; Label_0456: value3 = new uiValue(value2); value3.LoadValue(Map, parentOffset); value3.Location = new Point(0, y); y += value3.Height; parentPanel.Controls.Add(value3); continue; Label_04AA: slider = new uiSlider(value2); slider.LoadValue(Map, parentOffset); slider.Location = new Point(0, y); y += slider.Height; parentPanel.Controls.Add(slider); } } }
public void CreatePatch(HaloMap Orig, string ModdedMap, string PatchLocation, string Author, string Description) { //Write our patch file EndianIO pio = new EndianIO(PatchLocation, EndianType.LittleEndian); EndianIO mio = new EndianIO(ModdedMap, EndianType.LittleEndian); #region Old Code //Get our tag table starts for both maps int origTagTableStart = Orig.IndexItems[0].Offset; //Loop through all tags for (int index = 0; index < Orig.IndexHeader.tagCount; index++) { //If our indexed tag has a smaller offset than the current if (Orig.IndexItems[index].Offset < origTagTableStart) { //Set that offset as our starting point. origTagTableStart = Orig.IndexItems[index].Offset; } } /* * //Get our tag table starts for both maps * int modTagTableStart = Modded.IndexItems[0].Offset; * * //Loop through all tags * for (int index = 0; index < Modded.IndexHeader.tagCount; index++) * { * //If our indexed tag has a smaller offset than the current * if (Modded.IndexItems[index].Offset < modTagTableStart) * { * //Set that offset as our starting point. * modTagTableStart = Modded.IndexItems[index].Offset; * } * } */ //Get our table ends for both maps //int origTagTableEnd = new LocaleHandler(Orig).LocaleTables[0].LocaleTableIndexOffset; //int modTagTableEnd = new LocaleHandler(Modded).LocaleTables[0].LocaleTableIndexOffset; //Make sure our starts and ends match or else it won't be a good compare. //if (origTagTableStart != modTagTableStart && origTagTableEnd != modTagTableEnd) //{ //Show our error message // MessageBox.Show( // "The following two maps didn't not have the same meta table sizes and therefore... a patch cannot be properly made of these maps. The patching process will be discontinued."); //Stop processing code // return; // } #endregion //Open both map's IOs Orig.OpenIO(); pio.Open(); mio.Open(); pio.Out.Write(Author); pio.Out.Write(Description); //Setup our size and buffer size int perferdBuffSize = 0x1000000; int size = (int)Orig.IO.Stream.Length; //Create our 3 buffers, this way we don't have to mess around later byte[] obuf = new byte[perferdBuffSize], mbuf = new byte[perferdBuffSize], cbuf = new byte[perferdBuffSize]; //Set our positions Orig.IO.In.BaseStream.Position = origTagTableStart; mio.In.BaseStream.Position = origTagTableStart; //Now do our main compare loop :) unsafe { fixed(byte *pObuf = obuf, pMbuf = mbuf, pPbuf = cbuf) { int *ip1 = (int *)pObuf; int *ip2 = (int *)pMbuf; int *ip3 = (int *)pPbuf; int bufferSize = perferdBuffSize; int patchStart = 0; int patchSize = 0; for (int x = origTagTableStart; x < size; x += perferdBuffSize) { //Read our data bufferSize = Math.Min(perferdBuffSize, size - x); Orig.IO.In.Read(obuf, 0, bufferSize); mio.In.Read(mbuf, 0, bufferSize); //Lets compare for (int i = 0; i < bufferSize / 4; i++) { if (ip1[i] != ip2[i]) { //Are we just starting this patch? patchStart = x + (i * 4); patchSize = 0; while (i < (bufferSize / 4) && ip1[i] != ip2[i]) { ip3[patchSize / 4] = ip2[i]; i++; patchSize += 4; } //Lets write out this data pio.Out.Write(patchStart); pio.Out.Write(patchSize); pio.Out.Write(cbuf, 0, patchSize); } } } } } //Close up our patch pio.Close(); mio.Close(); }