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"); } } }
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; } } }
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 static void PokePatch(string originalMap, string patchPath) { XboxDebugCommunicator debugCommunicator = new XboxDebugCommunicator(AppSettings.Settings.IP_and_XDK_Name); if (!debugCommunicator.Connected) { try { debugCommunicator.Connect(); } catch { } } XboxMemoryStream xboxMemoryStream = debugCommunicator.ReturnXboxMemoryStream(); debugCommunicator.Disconnect(); HaloReach3d.IO.EndianIO endianIo = new HaloReach3d.IO.EndianIO((Stream)xboxMemoryStream, HaloReach3d.IO.EndianType.BigEndian); endianIo.Open(); HaloMap haloMap = new HaloMap(originalMap); haloMap.ReloadMap(); int mapMagic = haloMap.Map_Header.mapMagic; haloMap.CloseIO(); BinaryReader binaryReader = new BinaryReader((Stream) new FileStream(patchPath, FileMode.Open, FileAccess.Read)); try { while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length - 8L) { int num = binaryReader.ReadInt32(); int count = binaryReader.ReadInt32(); endianIo.Out.BaseStream.Position = (long)(num + mapMagic); endianIo.Out.Write(binaryReader.ReadBytes(count)); } } catch { } binaryReader.Close(); endianIo.Close(); xboxMemoryStream.Close(); }
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(); }