Пример #1
0
        public void SaveData(Stream stream)
        {
            //Initialize our IO
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open our IO
            IO.Open();
            //Write our header string
            IO.Out.WriteAsciiString(RTHDataHeader.HeaderString, 4);
            //Write our header version
            IO.Out.Write(RTHDataHeader.Version);
            //Write our block count
            IO.Out.Write(RTH_Data_Blocks.Count);
            //Write our patch type
            IO.Out.Write((int)RTH_Data_Header.Patch_Type);
            //Write our author name
            IO.Out.WriteAsciiString(RTH_Data_Header.Author_Name, 32);
            //Write our patch description
            IO.Out.WriteAsciiString(RTH_Data_Header.Patch_Description, 256);
            //Write our author IP
            IO.Out.WriteAsciiString(RTH_Data_Header.Watermark, 16);
            //Loop through our blocks
            for (int index = 0; index < RTH_Data_Blocks.Count; index++)
            {
                //Write our memory offset
                IO.Out.Write(RTH_Data_Blocks[index].Memory_Offset);
                //Write our block size
                IO.Out.Write(RTH_Data_Blocks[index].Block_Size);
                //Write our data block
                IO.Out.Write(RTH_Data_Blocks[index].Data_Block);
            }
            //Close our IO
            IO.Close();
        }
Пример #2
0
        public static void PokeRTHData(RTHData RTH_Data)
        {
            //If our XDKName is set
            if (AppSettings.Settings.XDKName == "")
            {
                throw new Exception(
                          "The Xbox Development Kit could not be connected to because it's means of connection were not set.");
            }
            //Initialize our XDC360
            XboxDebugCommunicator xdc = new XboxDebugCommunicator(AppSettings.Settings.XDKName);

            //Connect
            xdc.Connect();
            //Get our Xbox Memory Stream
            XboxMemoryStream xbms = xdc.ReturnXboxMemoryStream();
            //Initialize our Endian IO
            EndianIO IO = new EndianIO(xbms, EndianType.BigEndian);

            //Open our IO
            IO.Open();
            //Loop through every RTH Data Block
            for (int index = 0; index < RTH_Data.RTH_Data_Blocks.Count; index++)
            {
                //Go to that RTH Data Block's memory offset
                IO.Out.BaseStream.Position = RTH_Data.RTH_Data_Blocks[index].Memory_Offset;
                //Write our data
                IO.Out.Write(RTH_Data.RTH_Data_Blocks[index].Data_Block);
            }
            //Close our IO
            IO.Close();
            //Close our Xbox Memory Stream
            xbms.Close();
            //Disconnect from our Xbox Development Kit
            xdc.Disconnect();
        }
Пример #3
0
        private void ChangeHaloODSTFillMode()
        {
            //If the user didnt set the XDK name.
            if (AppSettings.Settings.XDKName == "")
            {
                //Show our error.
                MessageBox.Show(
                    "The Xbox Development Kit could not be connected to because it's means of connection were not set.");

                //Stop processing code in this stub.
                return;
            }

            //Initialize our Xbox Debug Communicator, with our XDK name/IP.
            XboxDebugCommunicator xdc = new XboxDebugCommunicator(AppSettings.Settings.XDKName);

            //Connect to our Xbox Debug Communicator.
            xdc.Connect();

            //Create an Xbox Memory Stream.
            XboxMemoryStream xbms = xdc.ReturnXboxMemoryStream();

            //Create an endian IO for our Memory Stream.
            EndianIO IO = new EndianIO(xbms, EndianType.BigEndian);

            //Open our IO.
            IO.Open();

            //Go to the address of the fillmode.
            IO.SeekTo(0x821A8C60);

            //If our solid item is checked.
            if (menuButtonItem32.Checked)
            {
                //Write our solid value.
                IO.Out.Write(0x38800000);
            }

            //Otherwise if our Point item is checked.
            else if (menuButtonItem33.Checked)
            {
                //Write our point value.
                IO.Out.Write(0x38800001);
            }

            //Otherwise if our Wireframe item is checked.
            else if (menuButtonItem34.Checked)
            {
                //Write our wireframe value.
                IO.Out.Write(0x38800025);
            }

            //Close our IO.
            IO.Close();

            //Disconnect from our Xbox.
            xdc.Disconnect();
        }
Пример #4
0
 public void OpenIO()
 {
     //Close our IO first incase.
     CloseIO();
     //Initialize our IO
     IO = new EndianIO(FileName, EndianType.BigEndian);
     //Open our IO
     IO.Open();
 }
        private void buttonX9_Click(object sender, EventArgs e)
        {
            //If the Xbox_Debug_Communicator isn't null
            if (Xbox_Debug_Communicator != null)
            {
                //If it is connected..
                if (Xbox_Debug_Communicator.Connected)
                {
                    //Get our memory stream.
                    XboxMemoryStream xms = Xbox_Debug_Communicator.ReturnXboxMemoryStream();

                    //Create our IO
                    EndianIO IO = new EndianIO(xms, EndianType.BigEndian);

                    //Open our IO
                    IO.Open();

                    //Go to our offset
                    IO.In.BaseStream.Position = 0x3A00C000 + 0x1A874;

                    //Read our macbin
                    byte[] macbin = IO.In.ReadBytes(0x1D0);

                    //Close our IO
                    IO.Close();

                    //Create our savefiledialog
                    SaveFileDialog sfd = new SaveFileDialog();

                    //Set our filter
                    sfd.Filter = "Mac Bin(.bin)|*.bin";

                    //Show our dialog, if the result is OK
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        //Create our IO
                        IO = new EndianIO(new FileStream(sfd.FileName, FileMode.Create), EndianType.BigEndian);

                        //Open our IO
                        IO.Open();

                        //Write our macbin data.
                        IO.Out.Write(macbin);

                        //Close our IO
                        IO.Close();

                        //Show our messagebox
                        MessageBox.Show("Done.");
                    }
                    return;
                }
            }

            //We aren't connected
            MessageBox.Show("You are not connected.");
        }
Пример #6
0
        public BLFImageFile(Stream stream)
        {
            EndianIO iO = new EndianIO(stream, EndianType.BigEndian);

            iO.Open();
            this.BLFHeader = new BLF_Header(iO, 0);
            this.BLFImage  = Image.FromStream(new MemoryStream(iO.In.ReadBytes(this.BLFHeader.FileContentSize)));
            this.EOFFooter = new EOF_Footer(iO, (int)iO.In.BaseStream.Position);
            iO.Close();
        }
Пример #7
0
        public void SaveInfoFile(Stream stream)
        {
            EndianIO nio = new EndianIO(stream, EndianType.BigEndian);

            nio.Open();
            nio.Out.WriteAsciiString("_blf", 4);
            nio.Out.Write(0x30);
            nio.Out.Write((short)1);
            nio.Out.Write((short)2);
            nio.Out.Write((short)(-2));
            nio.Out.Write(new byte[0x22]);
            nio.Out.WriteAsciiString("levl", 4);
            nio.Out.Write((short)0);
            nio.Out.Write(new byte[] { 0x4d, 80, 0, 3 });
            nio.Out.Write((short)1);
            nio.Out.Write(this.BLFHeader.Map_ID);
            nio.Out.Write(0x4c);
            nio.Out.BaseStream.Position = 0x44L;
            nio.Out.WriteUnicodeString(this.EnglishName, 0x20);
            nio.Out.WriteUnicodeString(this.JapaneseName, 0x20);
            nio.Out.WriteUnicodeString(this.GermanName, 0x20);
            nio.Out.WriteUnicodeString(this.FrenchName, 0x20);
            nio.Out.WriteUnicodeString(this.SpanishName, 0x20);
            nio.Out.WriteUnicodeString(this.LatinAmericaSpanishName, 0x20);
            nio.Out.WriteUnicodeString(this.ItalianName, 0x20);
            nio.Out.WriteUnicodeString(this.KoreanName, 0x20);
            nio.Out.WriteUnicodeString(this.ChineseName, 0x20);
            nio.Out.Write(new byte[0x40]);
            nio.Out.WriteUnicodeString(this.PortugueseName, 0x20);
            nio.Out.Write(new byte[0x40]);
            nio.Out.WriteUnicodeString(this.EnglishDescription, 0x80);
            nio.Out.WriteUnicodeString(this.JapaneseDescription, 0x80);
            nio.Out.WriteUnicodeString(this.GermanDescription, 0x80);
            nio.Out.WriteUnicodeString(this.FrenchDescription, 0x80);
            nio.Out.WriteUnicodeString(this.SpanishDescription, 0x80);
            nio.Out.WriteUnicodeString(this.LatinAmericanSpanishDescription, 0x80);
            nio.Out.WriteUnicodeString(this.ItalianDescription, 0x80);
            nio.Out.WriteUnicodeString(this.KoreanDescription, 0x80);
            nio.Out.WriteUnicodeString(this.ChineseDescription, 0x80);
            nio.Out.Write(new byte[0x100]);
            nio.Out.WriteUnicodeString(this.PortugueseDescription, 0x80);
            nio.Out.Write(new byte[0x100]);
            nio.Out.WriteAsciiString(this.MapImageFileName, 0x100);
            nio.Out.WriteAsciiString(this.MapFileName, 0x100);
            nio.Out.Write(new byte[0x3c3c]);
            int position = (int)nio.Stream.Position;

            nio.Out.WriteAsciiString("_eof", 4);
            nio.Out.Write(0x111);
            nio.Out.Write(0x10001);
            nio.Out.Write(position);
            nio.Out.Write((byte)3);
            nio.Out.Write(new byte[0x100]);
            nio.Close();
        }
Пример #8
0
        private void menuButtonItem28_Activate_1(object sender, EventArgs e)
        {
            //Inverse our check.
            menuButtonItem28.Checked = !menuButtonItem28.Checked;

            //Change our debug hud text.

            //If the user didnt set the XDK name.
            if (AppSettings.Settings.XDKName == "")
            {
                //Show our error.
                MessageBox.Show(
                    "The Xbox Development Kit could not be connected to because it's means of connection were not set.");

                //Stop processing code in this stub.
                return;
            }

            //Initialize our Xbox Debug Communicator, with our XDK name/IP.
            XboxDebugCommunicator xdc = new XboxDebugCommunicator(AppSettings.Settings.XDKName);

            //Connect to our Xbox Debug Communicator.
            xdc.Connect();

            //Create an Xbox Memory Stream.
            XboxMemoryStream xbms = xdc.ReturnXboxMemoryStream();

            //Create an endian IO for our Memory Stream.
            EndianIO IO = new EndianIO(xbms, EndianType.BigEndian);

            //Open our IO.
            IO.Open();

            //Goto the Address of the jump to the debug text.
            IO.SeekTo(0x821978B0);

            //If our print cam info item is checked..
            if (menuButtonItem28.Checked)
            {
                //Write our ASM value indicating a no operation.
                IO.Out.Write(0x60000000);//Nop
            }
            //Otherwise
            else
            {
                //Write our jump offset.
                IO.Out.Write(0x419A01D8);
            }

            //Close our IO.
            IO.Close();

            //Disconnect from our xbox.
            xdc.Disconnect();
        }
Пример #9
0
 private void menuBarItem2_BeforePopup(object sender, TD.SandBar.MenuPopupEventArgs e)
 {
     //If the XDK Name isn't blank
     if (AppSettings.Settings.XDKName != "")
     {
         //Initialize our Xbox Debug Communicator, with our Xbox Name
         XboxDebugCommunicator Xbox_Debug_Communicator = new XboxDebugCommunicator(AppSettings.Settings.XDKName);
         //Connect
         Xbox_Debug_Communicator.Connect();
         //Get the memoryStream
         XboxMemoryStream xbms = Xbox_Debug_Communicator.ReturnXboxMemoryStream();
         //Endian IO
         EndianIO IO = new EndianIO(xbms, EndianType.BigEndian);
         IO.Open();
         //Loop through every ident
         for (int i = 0; i < identGrid.Items.Count; i++)
         {
             //Get the offset
             int offset = int.Parse(identGrid.Items[i].SubItems[1].Text.Substring(2), System.Globalization.NumberStyles.HexNumber) + Map.MapHeader.mapMagic;
             try
             {
                 //Get the tagclass and name
                 string tagClass = identGrid.Items[i].SubItems[2].Text;
                 string tagName  = identGrid.Items[i].SubItems[3].Text;
                 //Get our tag ID
                 int tagID = Map.IndexItems[Map.GetTagIndexByClassAndName(tagClass, tagName)].Ident;
                 //Make our IO go to the offset
                 IO.Out.BaseStream.Position = offset;
                 //Write our tagclass
                 IO.Out.WriteAsciiString(tagClass, 4);
                 //Skip 8 bytes
                 IO.Out.BaseStream.Position += 8;
                 //Write our ID
                 IO.Out.Write(tagID);
             }
             catch
             {
             }
         }
         IO.Close();
         xbms.Close();
         //Disconnect
         Xbox_Debug_Communicator.Disconnect();
         MessageBox.Show("Done.");
     }
     else
     {
         //Show our error dialog
         MessageBox.Show("XDK Name/IP was not set. Please set it before continuing.");
         //Stop processing code.
         return;
     }
 }
Пример #10
0
        public static byte[] ValueToBytes(float data)
        {
            MemoryStream ms = new MemoryStream();
            EndianIO     IO = new EndianIO(ms, EndianType.BigEndian);

            IO.Open();
            IO.Out.Write(data);
            IO.In.BaseStream.Position = 0;
            byte[] array = IO.In.ReadBytes((int)IO.In.BaseStream.Length);
            IO.Close();
            ms.Close();
            return(array);
        }
Пример #11
0
        /// <summary>
        /// This way of initializing an instance of RTH Data would allow you to read an existing RTH Data file, and rebuild it, or apply it.
        /// </summary>
        /// <param name="stream">This is the stream to read the existing RTH Data from</param>
        public RTHData(Stream stream)
        {
            //Initialize our IO
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open our IO
            IO.Open();
            //Initialize and read our RTHDataHeader
            RTH_Data_Header = new RTHDataHeader(IO);
            //Initialize RTH Blocks
            RTH_Data_Blocks = new RTHDataBlocks(IO);
            //Close our IO
            IO.Close();
        }
Пример #12
0
        public static byte[] ValueToBytes(float data, EndianType et)
        {
            var ms = new MemoryStream();
            var io = new EndianIO(ms, et);

            io.Open();
            io.Writer.Write(data);
            io.Reader.BaseStream.Position = 0;
            var array = io.Reader.ReadBytes((int)io.Reader.BaseStream.Length);

            io.Close();
            ms.Close();
            return(array);
        }
Пример #13
0
        public BLFImageFile(Stream stream)
        {
            //Create our instance of the IO
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open our IO
            IO.Open();
            //Read our BLF Header
            BLFHeader = new BLF_Header(IO, 0);
            //Read our image
            BLFImage = Image.FromStream(new MemoryStream(IO.In.ReadBytes(BLFHeader.FileContentSize)));
            //Read our End of File
            EOFFooter = new EOF_Footer(IO, (int)IO.In.BaseStream.Position);
            //CloseIO
            IO.Close();
        }
Пример #14
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (AppSettings.Settings.IP_and_XDK_Name == "")
     {
         OutputMessenger.OutputMessage("XDK Name not set. Please set it in settings before continuing.", this);
     }
     else
     {
         XboxDebugCommunicator communicator = new XboxDebugCommunicator(AppSettings.Settings.IP_and_XDK_Name);
         communicator.Connect();
         communicator.Freeze();
         XboxMemoryStream stream = communicator.ReturnXboxMemoryStream();
         EndianIO         nio    = new EndianIO(stream, EndianType.BigEndian);
         nio.Open();
         int    tagIndexByClassAndName = Map.GetTagIndexByClassAndName(cmbxClass.Text, cmbxName.Text);
         string str  = "Null";
         string name = "Null";
         if (tagIndexByClassAndName != -1)
         {
             str  = Map.Index_Items[tagIndexByClassAndName].Class;
             name = Map.Index_Items[tagIndexByClassAndName].Name;
         }
         for (int i = 0; i < IdentGrid.SelectedItems.Count; i++)
         {
             int num3 = int.Parse(IdentGrid.SelectedItems[i].SubItems[1].Text.Substring(2), NumberStyles.HexNumber) + Map.Map_Header.mapMagic;
             if (tagIndexByClassAndName != -1)
             {
                 nio.Out.BaseStream.Position = num3;
                 nio.Out.WriteAsciiString(str, 4);
             }
             nio.Out.BaseStream.Position = num3 + 12;
             if (tagIndexByClassAndName != -1)
             {
                 nio.Out.Write(Map.Index_Items[tagIndexByClassAndName].Ident);
             }
             else
             {
                 nio.Out.Write(-1);
             }
         }
         nio.Close();
         stream.Close();
         communicator.Unfreeze();
         communicator.Disconnect();
         OutputMessenger.OutputMessage("Sucessfully poked " + IdentGrid.SelectedItems.Count.ToString() + " tag references to: \"" + name + "." + str + "\"", IdentGrid);
     }
 }
Пример #15
0
        public void SaveBLFImage(Stream stream, BLFImageType imgType)
        {
            EndianIO nio = new EndianIO(stream, EndianType.BigEndian);

            nio.Open();
            nio.Out.WriteAsciiString("_blf", 4);
            nio.Out.Write(0x30);
            nio.Out.Write((short)1);
            nio.Out.Write((short)2);
            nio.Out.Write((short)(-2));
            nio.Out.Write(new byte[0x22]);
            nio.Out.WriteAsciiString("mapi", 4);
            MemoryStream stream2 = new MemoryStream();

            if ((imgType == BLFImageType.BaseImage) | (imgType == BLFImageType.BaseImage))
            {
                this.BLFImage.Save(stream2, ImageFormat.Jpeg);
            }
            else
            {
                this.BLFImage.Save(stream2, ImageFormat.Png);
            }
            byte[] buffer = stream2.ToArray();
            stream2.Close();
            nio.Out.Write((int)(buffer.Length + 20));
            nio.Out.Write((short)1);
            nio.Out.Write((short)1);
            nio.Out.Write((int)imgType);
            nio.Out.Write(buffer.Length);
            nio.Out.Write(buffer);
            int position = (int)nio.Stream.Position;

            nio.Out.WriteAsciiString("_eof", 4);
            nio.Out.Write(0x111);
            nio.Out.Write(0x10001);
            nio.Out.Write(position);
            nio.Out.Write((byte)3);
            nio.Out.Write(new byte[0x100]);
            nio.Close();
        }
Пример #16
0
        public static void PrintCamDebugInfo(bool printingCam)
        {
            string xboxName = AppSettings.Settings.IP_and_XDK_Name;

            if (xboxName != "")
            {
                XboxDebugCommunicator communicator = new XboxDebugCommunicator(xboxName);
                communicator.Connect();
                EndianIO nio = new EndianIO(communicator.ReturnXboxMemoryStream(), EndianType.BigEndian);
                nio.Open();
                communicator.Freeze();
                nio.Out.BaseStream.Position = 0x82191eecL;
                if (printingCam)
                {
                    nio.Out.Write(0x60000000);
                }
                else
                {
                    nio.Out.Write(0x419a01b0);
                }
                nio.Out.BaseStream.Position = 0x82191f04L;
                if (printingCam)
                {
                    nio.Out.Write(0x60000000);
                }
                else
                {
                    nio.Out.Write(0x419a01b0);
                }
                communicator.Unfreeze();
                nio.Close();
                communicator.Disconnect();
            }
            else
            {
                MessageBox.Show("XDK name not set. Please set it in settings before continuing.");
            }
        }
Пример #17
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            //If the XDK Name isn't blank
            if (AppSettings.Settings.XDKName != "")
            {
                //Initialize our Xbox Debug Communicator, with our Xbox Name
                XboxDebugCommunicator Xbox_Debug_Communicator = new XboxDebugCommunicator(AppSettings.Settings.XDKName);
                //Connect
                Xbox_Debug_Communicator.Connect();

                //Get our memory stream
                XboxMemoryStream xbms = Xbox_Debug_Communicator.ReturnXboxMemoryStream();

                //Create our IO
                EndianIO IO = new EndianIO(xbms, EndianType.BigEndian);

                //Open our IO
                IO.Open();

                //If we are to remove soft barriers
                if (chkRemoveSoftBarriers.Checked)
                {
                }

                //Close our IO
                IO.Close();

                //Disconnect
                Xbox_Debug_Communicator.Disconnect();
                //Null our communicator
                Xbox_Debug_Communicator = null;
            }
            else
            {
                MessageBox.Show("No XDK Name is set. Please set it in settings before continuing.");
            }
        }
Пример #18
0
        public InfoFile(Stream stream)
        {
            EndianIO iO = new EndianIO(stream, EndianType.BigEndian);

            iO.Open();
            this.BLFHeader               = new BLF_Header(iO, 0);
            iO.In.BaseStream.Position    = 0x44L;
            this.EnglishName             = iO.In.ReadUnicodeString(0x20);
            this.JapaneseName            = iO.In.ReadUnicodeString(0x20);
            this.GermanName              = iO.In.ReadUnicodeString(0x20);
            this.FrenchName              = iO.In.ReadUnicodeString(0x20);
            this.SpanishName             = iO.In.ReadUnicodeString(0x20);
            this.LatinAmericaSpanishName = iO.In.ReadUnicodeString(0x20);
            this.ItalianName             = iO.In.ReadUnicodeString(0x20);
            this.KoreanName              = iO.In.ReadUnicodeString(0x20);
            this.ChineseName             = iO.In.ReadUnicodeString(0x20);
            iO.In.ReadBytes(0x40);
            this.PortugueseName = iO.In.ReadUnicodeString(0x20);
            iO.In.ReadBytes(0x40);
            this.EnglishDescription              = iO.In.ReadUnicodeString(0x80);
            this.JapaneseDescription             = iO.In.ReadUnicodeString(0x80);
            this.GermanDescription               = iO.In.ReadUnicodeString(0x80);
            this.FrenchDescription               = iO.In.ReadUnicodeString(0x80);
            this.SpanishDescription              = iO.In.ReadUnicodeString(0x80);
            this.LatinAmericanSpanishDescription = iO.In.ReadUnicodeString(0x80);
            this.ItalianDescription              = iO.In.ReadUnicodeString(0x80);
            this.KoreanDescription               = iO.In.ReadUnicodeString(0x80);
            this.ChineseDescription              = iO.In.ReadUnicodeString(0x80);
            iO.In.ReadBytes(0x100);
            this.PortugueseDescription = iO.In.ReadUnicodeString(0x80);
            iO.In.ReadBytes(0x100);
            this.MapImageFileName = iO.In.ReadAsciiString(0x100);
            this.MapFileName      = iO.In.ReadAsciiString(0x100);
            iO.In.ReadBytes(0xbb74);
            this.EOFFooter = new EOF_Footer(iO, (int)iO.In.BaseStream.Position);
            iO.Close();
        }
Пример #19
0
 public static byte[] ValueToBytes(float data, EndianType et)
 {
     var ms = new MemoryStream();
     var io = new EndianIO(ms, et);
     io.Open();
     io.Writer.Write(data);
     io.Reader.BaseStream.Position = 0;
     var array = io.Reader.ReadBytes((int)io.Reader.BaseStream.Length);
     io.Close();
     ms.Close();
     return array;
 }
Пример #20
0
        public static void WriteEMF(string FilePath, ModelInfo Mi, Permutation.LOD LOD,
                                    bool ExportNodes, bool ExportMakers, System.Windows.Forms.TreeView treeView)
        {
            // Create our file
            EndianIO io = new EndianIO(FilePath, EndianType.LittleEndian);

            io.Open();

            // Write out our header
            io.Out.Write(0x21666D65); // emf!
            io.Out.Write(0x00000001); // version #1

            // Write our model name
            io.Out.Write(Mi.Name.ToCharArray());
            io.Out.Write((byte)0x00);

            // Write our nodes
            if (ExportNodes)
            {
                io.Out.Write(Mi.Nodes.Count);
                for (int x = 0; x < Mi.Nodes.Count; x++)
                {
                    io.Out.Write(Mi.Nodes[x].Name.ToCharArray());
                    io.Out.Write((byte)0x00);
                    io.Out.Write(Mi.Nodes[x].ParentNodeIndex);
                    io.Out.Write(Mi.Nodes[x].DefaultTranslationX);
                    io.Out.Write(Mi.Nodes[x].DefaultTranslationY);
                    io.Out.Write(Mi.Nodes[x].DefaultTranslationZ);
                    io.Out.Write(Mi.Nodes[x].DefaultRotationI);
                    io.Out.Write(Mi.Nodes[x].DefaultRotationJ);
                    io.Out.Write(Mi.Nodes[x].DefaultRotationK);
                    io.Out.Write(Mi.Nodes[x].DefaultRotationW);
                }
            }
            else
            {
                io.Out.Write((int)0);
            }

            // Write out our marker groups
            if (ExportMakers)
            {
                io.Out.Write(Mi.MarkerGroups.Count);
                for (int x = 0; x < Mi.MarkerGroups.Count; x++)
                {
                    // Write our group name
                    io.Out.Write(Mi.MarkerGroups[x].Name.ToCharArray());
                    io.Out.Write((byte)0x00);

                    // Write out our markers
                    io.Out.Write(Mi.MarkerGroups[x].Markers.Count);
                    for (int y = 0; y < Mi.MarkerGroups[x].Markers.Count; y++)
                    {
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].RegionIndex);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].PermutationIndex);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].NodeIndex);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].TranslationX);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].TranslationY);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].TranslationZ);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].RotationI);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].RotationJ);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].RotationK);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].RotationW);
                        io.Out.Write(Mi.MarkerGroups[x].Markers[y].Scale);
                    }
                }
            }
            else
            {
                io.Out.Write((int)0);
            }

            // See how many regions are checked
            int count = 0;

            for (int x = 0; x < treeView.Nodes.Count; x++)
            {
                if (treeView.Nodes[x].Checked)
                {
                    count++;
                }
            }

            // Write out our regions
            io.Out.Write(count);
            for (int x = 0; x < treeView.Nodes.Count; x++)
            {
                // Only if this region is slected
                if (treeView.Nodes[x].Checked)
                {
                    // Write our region name
                    io.Out.Write(Mi.Regions[x].Name.ToCharArray());
                    io.Out.Write((byte)0x00);

                    // Get our perm count
                    int pcount = 0;
                    for (int y = 0; y < treeView.Nodes[x].Nodes.Count; y++)
                    {
                        if (treeView.Nodes[x].Nodes[y].Checked)
                        {
                            pcount++;
                        }
                    }

                    // Write our perms
                    io.Out.Write(pcount);
                    for (int y = 0; y < treeView.Nodes[x].Nodes.Count; y++)
                    {
                        // Only if this perm is slected
                        if (treeView.Nodes[x].Nodes[y].Checked)
                        {
                            // Write our perm name
                            io.Out.Write(Mi.Regions[x].Permutations[y].Name.ToCharArray());
                            io.Out.Write((byte)0x00);

                            // Get our model part from this perms LOD
                            ModelPart part = Mi.ModelParts[Mi.Regions[x].Permutations[y].LODs[(int)LOD]];

                            // Write out our vertex format
                            io.Out.Write(part.VertexFormat);

                            #region Old Code

                            /*
                             * // Write out our submeshs
                             * io.Out.Write(part.Submeshes.Count);
                             * for (int z = 0; z < part.Submeshes.Count; z++)
                             * {
                             *  // Write our vertex data
                             *  io.Out.Write(part.totalVertexCount);
                             *  for (int v = 0; v < part.totalVertexCount; v++)
                             *  {
                             *      io.Out.Write(part.VertexData[v].X);
                             *      io.Out.Write(part.VertexData[v].Y);
                             *      io.Out.Write(part.VertexData[v].Z);
                             *      io.Out.Write(part.VertexData[v].textureU);
                             *      io.Out.Write(part.VertexData[v].textureV);
                             *
                             *      // If we have bone id's and skin weights
                             *      if (part.VertexFormat == 2)
                             *      {
                             *          io.Out.Write(part.VertexData[v].boneID1);
                             *          io.Out.Write(part.VertexData[v].boneID2);
                             *          io.Out.Write(part.VertexData[v].boneID3);
                             *          io.Out.Write(part.VertexData[v].boneID4);
                             *          io.Out.Write(part.VertexData[v].VertWeight1);
                             *          io.Out.Write(part.VertexData[v].VertWeight2);
                             *          io.Out.Write(part.VertexData[v].VertWeight3);
                             *          io.Out.Write(part.VertexData[v].VertWeight4);
                             *      }
                             *  }
                             *
                             *  // Lets create our triangle list first
                             *  List<ushort> triangleList = new List<ushort>();
                             *  for (int s = 0; s < part.Submeshes.Count; s++)
                             *  {
                             *      for (int i = part.Submeshes[s].SubsetIndex;
                             *          i < part.Submeshes[s].SubsetIndex +
                             *          part.Submeshes[s].SubsetCount; i++)
                             *      {
                             *          triangleList.AddRange(createTriangleList(
                             *                part.triangleStripData,
                             *                part.Subsets[i].FaceStart,
                             *                part.Subsets[i].FaceLength));
                             *      }
                             *  }
                             *
                             *  // Write our face data
                             *  io.Out.Write(triangleList.Count / 3);
                             *  for (int f = 0; f < triangleList.Count; f += 3)
                             *  {
                             *      io.Out.Write(triangleList[f]);
                             *      io.Out.Write(triangleList[f + 1]);
                             *      io.Out.Write(triangleList[f + 2]);
                             *  }
                             * }*/
                            #endregion

                            // We only have 1 submeshs
                            io.Out.Write((int)1);

                            // Lets write all our verts
                            // Write our vertex data
                            io.Out.Write(part.totalVertexCount);
                            for (int v = 0; v < part.totalVertexCount; v++)
                            {
                                io.Out.Write(part.VertexData[v].X);
                                io.Out.Write(part.VertexData[v].Y);
                                io.Out.Write(part.VertexData[v].Z);
                                io.Out.Write(part.VertexData[v].textureU);
                                io.Out.Write(part.VertexData[v].textureV);

                                // If we have bone id's and skin weights
                                if (part.VertexFormat == 2)
                                {
                                    io.Out.Write(part.VertexData[v].boneID1);
                                    io.Out.Write(part.VertexData[v].boneID2);
                                    io.Out.Write(part.VertexData[v].boneID3);
                                    io.Out.Write(part.VertexData[v].boneID4);
                                    io.Out.Write(part.VertexData[v].VertWeight1);
                                    io.Out.Write(part.VertexData[v].VertWeight2);
                                    io.Out.Write(part.VertexData[v].VertWeight3);
                                    io.Out.Write(part.VertexData[v].VertWeight4);
                                }
                            }

                            // Lets create our triangle list first
                            List <ushort> triangleList = new List <ushort>();

                            /*for (int s = 0; s < part.Submeshes.Count; s++)
                             * {
                             *  for (int i = part.Submeshes[s].SubsetIndex;
                             *      i < part.Submeshes[s].SubsetIndex +
                             *      part.Submeshes[s].SubsetCount; i++)
                             *  {
                             *      triangleList.AddRange(createTriangleList(
                             *            part.triangleStripData,
                             *            part.Subsets[i].FaceStart,
                             *            part.Subsets[i].FaceLength));
                             *  }
                             * }*/
                            triangleList.AddRange(createTriangleList(
                                                      part.triangleStripData,
                                                      0,
                                                      part.totalFaceCount));

                            // Write our face data
                            io.Out.Write(triangleList.Count / 3);
                            for (int f = 0; f < triangleList.Count; f += 3)
                            {
                                io.Out.Write(triangleList[f]);
                                io.Out.Write(triangleList[f + 1]);
                                io.Out.Write(triangleList[f + 2]);
                            }
                        }
                    }
                }
            }

            // Close our new file
            io.Close();
        }
Пример #21
0
        public static ModelInfo GetModelInfo(HaloMap Map, int TagIndex)
        {
            // Create our structure to hold the info
            ModelInfo mi = new ModelInfo();

            // Get our Name
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset);
            mi.Name = Map.StringTable.StringItems[(Map.StringTable.GetStringItemIndexByID(Map, Map.IO.In.ReadInt32()))].Name;

            // Get our Region info first
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 12);
            int regionCount   = Map.IO.In.ReadInt32();
            int regionPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            mi.Regions = new List <Region>();
            for (int x = 0; x < regionCount; x++)
            {
                Region region = new Region();

                Map.IO.SeekTo(regionPointer + (16 * x));
                region.Name = Map.StringTable.StringItems[Map.StringTable.GetStringItemIndexByID(Map, Map.IO.In.ReadInt32())].Name;
                int permutationCount   = Map.IO.In.ReadInt32();
                int permutationPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;
                region.Permutations = new List <Permutation>();
                Map.IO.SeekTo(permutationPointer);
                for (int y = 0; y < permutationCount; y++)
                {
                    Permutation perm = new Permutation();
                    perm.Name = Map.StringTable.StringItems[Map.StringTable.GetStringItemIndexByID(Map, Map.IO.In.ReadInt32())].Name;
                    perm.LODs = new List <short>();
                    for (int l = 0; l < 6; l++)
                    {
                        perm.LODs.Add(Map.IO.In.ReadInt16());
                    }
                    region.Permutations.Add(perm);
                }

                mi.Regions.Add(region);
            }

            // Get our nodes
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 48);
            int nodeCount   = Map.IO.In.ReadInt32();
            int nodePointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            mi.Nodes = new List <Node>();
            Map.IO.SeekTo(nodePointer);
            for (int x = 0; x < nodeCount; x++)
            {
                mi.Nodes.Add(new Node(Map, Map.IO.In));
            }

            // Get our marker groups
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 60);
            int markerGroupCount   = Map.IO.In.ReadInt32();
            int markerGroupPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            mi.MarkerGroups = new List <MarkerGroup>();
            for (int x = 0; x < markerGroupCount; x++)
            {
                Map.IO.SeekTo(markerGroupPointer + (16 * x));
                mi.MarkerGroups.Add(new MarkerGroup(Map, Map.IO.In));
            }

            // Read our shaders
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 72);
            mi.shaderid = new int[Map.IO.In.ReadInt32()];
            int pointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            for (int x = 0; x < mi.shaderid.Length; x++)
            {
                Map.IO.SeekTo(pointer + (x * 0x24) + 0xC);
                mi.shaderid[x] = Map.IO.In.ReadInt32();
            }

            // Get our model info first
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 104);
            int modelPartCount   = Map.IO.In.ReadInt32();
            int modelPartPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            mi.ModelParts = new List <ModelPart>();
            for (int x = 0; x < modelPartCount; x++)
            {
                ModelPart part = new ModelPart();

                Map.IO.SeekTo(modelPartPointer + (76 * x));
                int submeshCount   = Map.IO.In.ReadInt32();
                int submeshPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;
                part.Submeshes = new List <Submesh>();
                Map.IO.SeekTo(submeshPointer);
                for (int y = 0; y < submeshCount; y++)
                {
                    Submesh submesh = new Submesh();

                    submesh.ShaderIndex = Map.IO.In.ReadInt16();
                    Map.IO.In.ReadInt16();
                    submesh.FaceStart   = Map.IO.In.ReadInt16();
                    submesh.FaceLength  = Map.IO.In.ReadInt16();
                    submesh.SubsetIndex = Map.IO.In.ReadInt16();
                    submesh.SubsetCount = Map.IO.In.ReadInt16();
                    submesh.Flags       = Map.IO.In.ReadInt16();
                    submesh.VertexCount = Map.IO.In.ReadInt16();

                    part.totalVertexCount += submesh.VertexCount;
                    part.totalFaceCount   += submesh.FaceLength;

                    part.Submeshes.Add(submesh);
                }

                Map.IO.SeekTo(modelPartPointer + (76 * x) + 12);
                int subsetCount   = Map.IO.In.ReadInt32();
                int subsetPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;
                part.Subsets = new List <Subset>();
                Map.IO.SeekTo(subsetPointer);
                for (int y = 0; y < subsetCount; y++)
                {
                    Subset subset = new Subset();

                    subset.FaceStart     = Map.IO.In.ReadInt16();
                    subset.FaceLength    = Map.IO.In.ReadInt16();
                    subset.SubmeshParent = Map.IO.In.ReadInt16();
                    subset.VertexCount   = Map.IO.In.ReadInt16();

                    part.Subsets.Add(subset);
                }

                Map.IO.SeekTo(modelPartPointer + (76 * x) + 32);
                part.RawIdentifier = Map.IO.In.ReadInt32();

                Map.IO.SeekTo(modelPartPointer + (76 * x) + 46);
                part.VertexFormat  = Map.IO.In.ReadByte();
                part.UnknownFormat = Map.IO.In.ReadByte();

                part.triangleStripData = new ushort[part.totalFaceCount];
                part.VertexData        = new Vertex[part.totalVertexCount];

                mi.ModelParts.Add(part);
            }

            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 116);
            int boundingBoxCount   = Map.IO.In.ReadInt32();
            int boundingBoxPointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;

            mi.BoundingBox = new BoundingBox();
            Map.IO.SeekTo(boundingBoxPointer + 4);
            mi.BoundingBox.xMin = Map.IO.In.ReadSingle();
            mi.BoundingBox.xMax = Map.IO.In.ReadSingle();
            mi.BoundingBox.yMin = Map.IO.In.ReadSingle();
            mi.BoundingBox.yMax = Map.IO.In.ReadSingle();
            mi.BoundingBox.zMin = Map.IO.In.ReadSingle();
            mi.BoundingBox.zMax = Map.IO.In.ReadSingle();
            mi.BoundingBox.uMin = Map.IO.In.ReadSingle();
            mi.BoundingBox.uMax = Map.IO.In.ReadSingle();
            mi.BoundingBox.vMin = Map.IO.In.ReadSingle();
            mi.BoundingBox.vMax = Map.IO.In.ReadSingle();

            // Get our raw ID now
            Map.IO.SeekTo(Map.IndexItems[TagIndex].Offset + 224);
            int rawid = Map.IO.In.ReadInt32();

            // Lets load our raw data now
            mi.Data = Map.RawInformation.GetRawDataFromID(rawid);

            // Now lets start to breakdown our raw data
            EndianIO rawIo = new EndianIO(mi.Data, EndianType.BigEndian);

            rawIo.Open();

            for (int x = 0; x < mi.ModelParts.Count; x++)
            {
                // Get our model part
                ModelPart mp = mi.ModelParts[x];

                int unknownSize = 1;
                if (mp.UnknownFormat == 0 ||
                    mp.UnknownFormat == 2)
                {
                    unknownSize = 4;
                }
                else if (mp.UnknownFormat == 3)
                {
                    unknownSize = 12;
                }

                for (int z = 0; z < mi.ModelParts[x].totalVertexCount; z++)
                {
                    mp.VertexData[z].X =
                        decompressShort(rawIo.In.ReadUInt16(), mi.BoundingBox.xMin, mi.BoundingBox.xMax);
                    mp.VertexData[z].Y =
                        decompressShort(rawIo.In.ReadUInt16(), mi.BoundingBox.yMin, mi.BoundingBox.yMax);
                    mp.VertexData[z].Z =
                        decompressShort(rawIo.In.ReadUInt16(), mi.BoundingBox.zMin, mi.BoundingBox.zMax);
                    mp.VertexData[z].padding  = rawIo.In.ReadBytes(2);
                    mp.VertexData[z].textureU =
                        decompressShort(rawIo.In.ReadUInt16(), mi.BoundingBox.uMin, mi.BoundingBox.uMax);
                    mp.VertexData[z].textureV = 1 -
                                                decompressShort(rawIo.In.ReadUInt16(), mi.BoundingBox.vMin, mi.BoundingBox.vMax);
                    mp.VertexData[z].extra = rawIo.In.ReadBytes(12);
                    if (mp.VertexFormat == 2)
                    {
                        mp.VertexData[z].boneID1     = rawIo.In.ReadByte();
                        mp.VertexData[z].boneID2     = rawIo.In.ReadByte();
                        mp.VertexData[z].boneID3     = rawIo.In.ReadByte();
                        mp.VertexData[z].boneID4     = rawIo.In.ReadByte();
                        mp.VertexData[z].VertWeight1 = (float)rawIo.In.ReadByte() / 0xFF;
                        mp.VertexData[z].VertWeight2 = (float)rawIo.In.ReadByte() / 0xFF;
                        mp.VertexData[z].VertWeight3 = (float)rawIo.In.ReadByte() / 0xFF;
                        mp.VertexData[z].VertWeight4 = (float)rawIo.In.ReadByte() / 0xFF;
                    }
                }

                //Read the unkown
                byte[] unknwon = rawIo.In.ReadBytes(mp.totalVertexCount * unknownSize);

                //Make sure we are padded
                rawIo.Stream.Position = getPaddedOffset((int)rawIo.Stream.Position);

                //Save back our model part
                mi.ModelParts[x] = mp;
            }

            //Now that we have read the vertex data lets read the face data
            for (int x = 0; x < mi.ModelParts.Count; x++)
            {
                // Get our model part
                ModelPart mp = mi.ModelParts[x];

                for (int y = 0; y < mp.totalFaceCount; y++)
                {
                    mp.triangleStripData[y] = rawIo.In.ReadUInt16();
                }

                rawIo.Stream.Position = getPaddedOffset((int)rawIo.Stream.Position);
            }

            // Lets return our bitmap now
            return(mi);
        }
Пример #22
0
        public InfoFile(Stream stream)
        {
            //Initialize our IO.
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open the IO
            IO.Open();

            //Read our blf header, which is at offset 0
            BLFHeader = new BLF_Header(IO, 0);

            //Go to our entry table
            IO.In.BaseStream.Position = 0x44;

            //Read our Names
            EnglishName             = IO.In.ReadUnicodeString(0x20);
            JapaneseName            = IO.In.ReadUnicodeString(0x20);
            GermanName              = IO.In.ReadUnicodeString(0x20);
            FrenchName              = IO.In.ReadUnicodeString(0x20);
            SpanishName             = IO.In.ReadUnicodeString(0x20);
            LatinAmericaSpanishName = IO.In.ReadUnicodeString(0x20);
            ItalianName             = IO.In.ReadUnicodeString(0x20);
            KoreanName              = IO.In.ReadUnicodeString(0x20);
            ChineseName             = IO.In.ReadUnicodeString(0x20);

            //Skip unimportant
            IO.In.ReadBytes(0x40);

            PortugueseName = IO.In.ReadUnicodeString(0x20);

            //Skip unimportant
            IO.In.ReadBytes(0x40);

            //Read our descriptions
            EnglishDescription              = IO.In.ReadUnicodeString(0x80);
            JapaneseDescription             = IO.In.ReadUnicodeString(0x80);
            GermanDescription               = IO.In.ReadUnicodeString(0x80);
            FrenchDescription               = IO.In.ReadUnicodeString(0x80);
            SpanishDescription              = IO.In.ReadUnicodeString(0x80);
            LatinAmericanSpanishDescription = IO.In.ReadUnicodeString(0x80);
            ItalianDescription              = IO.In.ReadUnicodeString(0x80);
            KoreanDescription               = IO.In.ReadUnicodeString(0x80);
            ChineseDescription              = IO.In.ReadUnicodeString(0x80);

            //Skip unimportant
            IO.In.ReadBytes(0x100);

            PortugueseDescription = IO.In.ReadUnicodeString(0x80);

            //Skip unimportant
            IO.In.ReadBytes(0x100);

            //Read the resource filenames
            MapImageFileName = IO.In.ReadAsciiString(0x100);
            MapFileName      = IO.In.ReadAsciiString(0x100);

            //Skip unimportant
            IO.In.ReadBytes(0x3C3C);

            //Read our End of file footer
            EOFFooter = new EOF_Footer(IO, (int)IO.In.BaseStream.Position);

            //Close our IO
            IO.Close();
        }
Пример #23
0
        public void SaveInfoFile(Stream stream)
        {
            //Create our instance of our IO
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open our IO
            IO.Open();

            //BLF Header

            #region BLF Header

            //Write our _blf string
            IO.Out.WriteAsciiString("_blf", 0x4);
            //Write the headersize
            IO.Out.Write(48);
            //Write the unknown values
            IO.Out.Write((short)1);
            IO.Out.Write((short)2);
            IO.Out.Write((short)-2);
            //Write the whitespace of blank values
            IO.Out.Write(new byte[0x22]);
            //Write our ending portion
            IO.Out.WriteAsciiString("levl", 0x4);
            IO.Out.Write((short)0);
            IO.Out.Write(new byte[0x4] {
                0x4D, 0x50, 0x00, 0x03
            });
            IO.Out.Write((short)1);
            IO.Out.Write(BLFHeader.Map_ID);
            IO.Out.Write(76);

            #endregion

            //Write entires

            #region Entries

            //Go to our entry table
            IO.Out.BaseStream.Position = 0x44;

            //Write our names.
            IO.Out.WriteUnicodeString(EnglishName, 0x20);
            IO.Out.WriteUnicodeString(JapaneseName, 0x20);
            IO.Out.WriteUnicodeString(GermanName, 0x20);
            IO.Out.WriteUnicodeString(FrenchName, 0x20);
            IO.Out.WriteUnicodeString(SpanishName, 0x20);
            IO.Out.WriteUnicodeString(LatinAmericaSpanishName, 0x20);
            IO.Out.WriteUnicodeString(ItalianName, 0x20);
            IO.Out.WriteUnicodeString(KoreanName, 0x20);
            IO.Out.WriteUnicodeString(ChineseName, 0x20);

            //Write our blank
            IO.Out.Write(new byte[0x40]);

            //Finish reading our names
            IO.Out.WriteUnicodeString(PortugueseName, 0x20);

            //Write our blank
            IO.Out.Write(new byte[0x40]);

            //Write our descriptions
            IO.Out.WriteUnicodeString(EnglishDescription, 0x80);
            IO.Out.WriteUnicodeString(JapaneseDescription, 0x80);
            IO.Out.WriteUnicodeString(GermanDescription, 0x80);
            IO.Out.WriteUnicodeString(FrenchDescription, 0x80);
            IO.Out.WriteUnicodeString(SpanishDescription, 0x80);
            IO.Out.WriteUnicodeString(LatinAmericanSpanishDescription, 0x80);
            IO.Out.WriteUnicodeString(ItalianDescription, 0x80);
            IO.Out.WriteUnicodeString(KoreanDescription, 0x80);
            IO.Out.WriteUnicodeString(ChineseDescription, 0x80);

            //Write our blank
            IO.Out.Write(new byte[0x100]);

            //Finish reading descriptions
            IO.Out.WriteUnicodeString(PortugueseDescription, 0x80);

            //Write our blank
            IO.Out.Write(new byte[0x100]);

            //Write our resource filenames
            IO.Out.WriteAsciiString(MapImageFileName, 0x100);
            IO.Out.WriteAsciiString(MapFileName, 0x100);

            //Write unimportant
            IO.Out.Write(new byte[0x3C3C]);

            #endregion

            //TODO: Write the End of File Footer

            #region EOF Footer

            int totalSize = (int)IO.Stream.Position;
            IO.Out.WriteAsciiString("_eof", 4);
            IO.Out.Write(0x111);
            IO.Out.Write(0x10001);
            IO.Out.Write(totalSize);
            IO.Out.Write((byte)0x03);
            IO.Out.Write(new byte[0x100]);

            #endregion

            //Close our IO
            IO.Close();
        }
Пример #24
0
        public void SaveBLFImage(Stream stream, BLFImageType imgType)
        {
            //Create our instance of our IO
            EndianIO IO = new EndianIO(stream, EndianType.BigEndian);

            //Open our IO
            IO.Open();
            //Write our BLF Header

            #region BLF Header

            //Write our _blf string
            IO.Out.WriteAsciiString("_blf", 0x4);
            //Write the headersize
            IO.Out.Write(48);
            //Write the unknown values
            IO.Out.Write((short)1);
            IO.Out.Write((short)2);
            IO.Out.Write((short)-2);
            //Write the whitespace of blank values
            IO.Out.Write(new byte[0x22]);
            //Write our ending portion
            IO.Out.WriteAsciiString("mapi", 0x4);
            //Create our image stream.
            MemoryStream imageStream = new MemoryStream();
            //Write our image to the stream
            if (imgType == BLFImageType.BaseImage | imgType == BLFImageType.Sm)
            {
                BLFImage.Save(imageStream, ImageFormat.Jpeg);
            }
            else
            {
                BLFImage.Save(imageStream, ImageFormat.Png);
            }
            //Get a useable byte array from it
            byte[] imageData = imageStream.ToArray();
            //Close our imageStream
            imageStream.Close();
            //Write imageData.length+20
            IO.Out.Write(imageData.Length + 20);
            IO.Out.Write((short)1);
            IO.Out.Write((short)1);
            //Write our enum for image type.
            //JFIF = 0
            //PNG = 1
            IO.Out.Write((int)imgType);
            //Write our content File Size(image length)
            IO.Out.Write(imageData.Length);

            #endregion

            //Write our image data
            IO.Out.Write(imageData);
            //Write our End of File

            #region EOF Footer

            //get our current location for a size
            int totalSize = (int)IO.Stream.Position;
            //Write our EOF Data
            IO.Out.WriteAsciiString("_eof", 4);
            IO.Out.Write(0x111);
            IO.Out.Write(0x10001);
            IO.Out.Write(totalSize);
            IO.Out.Write((byte)0x03);
            IO.Out.Write(new byte[0x100]);

            #endregion

            //Close our IO
            IO.Close();
        }
Пример #25
0
        public static void LoadMap(LevelOption Level_Map, GameBuild build)
        {
            string xboxName = AppSettings.Settings.IP_and_XDK_Name;

            if (xboxName != "")
            {
                XboxDebugCommunicator communicator = new XboxDebugCommunicator(xboxName);
                try
                {
                    communicator.Connect();
                }
                catch (Exception ex)
                {
                    throw new Exception("Not Connected");
                }
                EndianIO nio = new EndianIO(communicator.ReturnXboxMemoryStream(), EndianType.BigEndian);
                nio.Open();
                communicator.Freeze();
                if (build == GameBuild.PreBeta)
                {
                    nio.Out.BaseStream.Position = 0x83b8dea8L;
                }
                else
                {
                    nio.Out.BaseStream.Position = 0x8357d140L;
                }
                nio.Out.WriteAsciiString(beta_mapScenarioPaths[(int)Level_Map], 0x100);
                if (build == GameBuild.PreBeta)
                {
                    nio.Out.BaseStream.Position = 0x83b7fe78L;
                }
                else
                {
                    nio.Out.BaseStream.Position = 0x8356f110L;
                }
                if (Level_Map <= LevelOption.boneyard)
                {
                    nio.Out.Write((int)AppSettings.Settings.Force_Load_MapType);
                }
                else
                {
                    byte[] buffer = new byte[4];
                    buffer[3] = 2;
                    nio.Out.Write(buffer);
                }
                if (build == GameBuild.PreBeta)
                {
                    nio.Out.BaseStream.Position = 0x83b7fe6eL;
                }
                else
                {
                    nio.Out.BaseStream.Position = 0x8356f106L;
                }
                nio.Out.Write((byte)1);
                communicator.Unfreeze();
                nio.Close();
                communicator.Disconnect();
            }
            else
            {
                MessageBox.Show("XDK name not set. Please set it in settings before continuing.");
            }
        }
Пример #26
0
        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();
        }