Example #1
0
        public void InternalizeRawChunk(int rawPoolIndex)
        {
            //Get the raw chunk data
            byte[] rawChunk = Map.RawInformation.GetCompressedRawDataFromPoolIndex(rawPoolIndex);

            //Calculate the size to insert
            int paddingSize = ExtraFunctions.CalculatePadding((int)rawChunk.Length, 0x1000);

            //Block size to insert into the raw table
            int blockSize = paddingSize + (int)rawChunk.Length;

            //Open our IO
            Map.OpenIO();

            //Go to our external map index offset.
            Map.IO.Out.BaseStream.Position = Map.RawInformation.RawPools[rawPoolIndex].ChunkOffset + 4;

            //Write our value
            Map.IO.Out.Write((short)-1);

            //Skip 2 bytes
            Map.IO.Out.BaseStream.Position += 2;

            //Write our new raw data chunk offset.
            Map.IO.Out.Write((uint)Map.MapHeader.RawTableSize);

            //Close our IO
            Map.CloseIO();

            //Create our array for our bytes to insert
            byte[] dataToInsert = new byte[blockSize];
            for (int i = 0; i < dataToInsert.Length; i++)
            {
                dataToInsert[i] = 0xFF;
            }
            Array.Copy(rawChunk, dataToInsert, (int)rawChunk.Length);

            //Time to start inserting the block..
            ExtraFunctions.InsertBytes(Map.FileName, Map.MapHeader.RawTableOffset + Map.MapHeader.RawTableSize, dataToInsert);



            Map.OpenIO();
            Map.IO.Out.BaseStream.Position = 1160;
            Map.IO.Out.Write((map.MapHeader.RawTableSize + blockSize));
            Map.IO.Out.BaseStream.Position = 1144;
            Map.IO.Out.Write((map.MapHeader.localeTableAddressModifier + blockSize));
            Map.CloseIO();
        }
Example #2
0
        public void SaveLocale(int LocaleTableIndex, int StringIndex, string strName)
        {
            //Get our Locale Table
            LocaleHandler.LocaleTable selectedTable = LocaleTables[LocaleTableIndex];

            //Compare our string lengths.
            if (selectedTable.LocaleStrings[StringIndex].Name.Length == strName.Length)
            {
                //Open our IO
                Map.OpenIO();

                //Go to that locale's position
                Map.IO.Out.BaseStream.Position = selectedTable.LocaleTableOffset +
                                                 selectedTable.LocaleStrings[StringIndex].Offset;

                //Write our new locale.
                Map.IO.Out.WriteAsciiString(strName, strName.Length);

                //Close our IO
                Map.CloseIO();
            }
            else
            {
                //Get our variables
                int differenceStringLength = strName.Length - selectedTable.LocaleStrings[StringIndex].Name.Length;
                int oldTableSize           = selectedTable.LocaleTableSize;
                int newTableSize           = selectedTable.LocaleTableSize + differenceStringLength;
                int oldTableSizePadded     = oldTableSize + ExtraFunctions.CalculatePadding(oldTableSize, 0x1000);
                int newTableSizePadded     = newTableSize + ExtraFunctions.CalculatePadding(newTableSize, 0x1000);
                int differenceTableSize    = newTableSizePadded - oldTableSizePadded;

                //Let's recalculate some variables.

                //Open our IO
                Map.OpenIO();

                //Go to our following string index's position
                Map.IO.Out.BaseStream.Position = selectedTable.LocaleTableIndexOffset + ((StringIndex + 1) * 8);

                //Loop for every string after.
                for (int i = StringIndex + 1; i < selectedTable.LocaleCount; i++)
                {
                    //Skip 4 bytes
                    Map.IO.Out.BaseStream.Position += 4;
                    //Write our new index
                    Map.IO.Out.Write(selectedTable.LocaleStrings[i].Offset + differenceStringLength);
                }

                //Let's shift our other tables

                //Loop for each table after this one.
                for (int i = LocaleTableIndex + 1; i < LocaleTables.Count; i++)
                {
                    //Go to that table's offset.
                    Map.IO.Out.BaseStream.Position = LocaleTables[i].Offset + 8;

                    //Shift our values
                    LocaleTables[i].LocaleTableOffset      += differenceTableSize;
                    LocaleTables[i].LocaleTableIndexOffset += differenceTableSize;

                    //Write our values.
                    Map.IO.Out.Write((LocaleTables[i].LocaleTableIndexOffset - Map.MapHeader.localeTableAddressModifier));
                    Map.IO.Out.Write((LocaleTables[i].LocaleTableOffset - Map.MapHeader.localeTableAddressModifier));
                }

                byte[] restOfTable = new byte[0];
                try
                {
                    //Read the rest of our table after we'll insert
                    Map.IO.In.BaseStream.Position = selectedTable.LocaleTableOffset + selectedTable.LocaleStrings[StringIndex + 1].Offset;
                    restOfTable = Map.IO.In.ReadBytes(oldTableSize - selectedTable.LocaleStrings[StringIndex].Offset);
                }
                catch { }
                //Close our IO
                Map.CloseIO();

                //Check our difference.
                if (differenceTableSize > 0)
                {
                    //Insert
                    ExtraFunctions.InsertBytes(Map.FileName, selectedTable.LocaleTableOffset + oldTableSizePadded, differenceTableSize);
                }
                else if (differenceTableSize < 0)
                {
                    //Delete
                    ExtraFunctions.DeleteBytes(Map.FileName, selectedTable.LocaleTableOffset + newTableSizePadded, oldTableSizePadded - newTableSizePadded);
                }

                //Open our IO
                Map.OpenIO();

                //Let's write our new strings name.
                Map.IO.Out.BaseStream.Position = selectedTable.LocaleTableOffset + selectedTable.LocaleStrings[StringIndex].Offset;
                Map.IO.Out.WriteAsciiString(strName, strName.Length + 1);

                //Write the ending of our table
                Map.IO.Out.Write(restOfTable);

                Map.IO.Out.Write(new byte[newTableSizePadded - newTableSize]);

                //Lets go write our new locale table size
                Map.IO.Out.BaseStream.Position = selectedTable.Offset + 4;

                //Write our new size.
                Map.IO.Out.Write(newTableSize);

                //Close our IO
                Map.CloseIO();

                //Set our new table size
                selectedTable.LocaleTableSize = newTableSize;
            }



            //Open our IO
            Map.OpenIO();

            //Go back to the beginning of the table
            Map.IO.SeekTo(selectedTable.LocaleTableOffset);
            byte[] hash = SHA1.Create().ComputeHash(Map.IO.In.ReadBytes(
                                                        selectedTable.LocaleTableSize));
            //Seek to where the hash is
            Map.IO.SeekTo(selectedTable.Offset + 0x24);
            //Write it
            Map.IO.Out.Write(hash);

            //Go back to the beginning of the index table
            Map.IO.SeekTo(selectedTable.LocaleTableIndexOffset);
            hash = SHA1.Create().ComputeHash(Map.IO.In.ReadBytes(0x08 * selectedTable.LocaleCount));
            //Seek to where the hash is
            Map.IO.SeekTo(selectedTable.Offset + 0x10);
            //Write it
            Map.IO.Out.Write(hash);
            //Close our IO
            Map.CloseIO();
        }
Example #3
0
        /// <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 List <MetaHeader_DataBlock> GetMetaHeaderDataBlocksMapped(bool FindVoids, bool FindIdents, bool FindChildren)
        {
            int num;

            Plugin_Scanning_Regions = new List <PluginScanningRegion>();
            Plugin_Data_Blocks      = new List <PluginDataBlock>();
            MetaHeader_Data_Blocks  = new List <MetaHeader_DataBlock>();
            Tag_Idents = new List <Tag_Ident>();
            Tag_Voids  = new List <Tag_Void>();
            PluginScanningRegion region = new PluginScanningRegion {
                Offset = Map.Map_Header.RawTableOffset + Map.Map_Header.RawTableSize
            };

            region.Size = Map.Index_Header.tagInfoHeaderOffset - region.Offset;
            Plugin_Scanning_Regions.Add(region);
            PluginScanningRegion region2 = new PluginScanningRegion {
                Offset = (Map.Map_Header.indexOffset + 0x2c) + ExtraFunctions.CalculatePadding(Map.Map_Header.indexOffset + 0x2c, 0x1000)
            };

            region2.Size = new LocaleHandler(Map).LocaleTables[0].LocaleTableIndexOffset - region2.Offset;
            Plugin_Scanning_Regions.Add(region2);
            foreach (HaloMap.TagItem item in Map.Index_Items)
            {
                MetaHeader_DataBlock block = new MetaHeader_DataBlock(item);
                Plugin_Data_Blocks.Add(block);
                MetaHeader_Data_Blocks.Add(block);
                Application.DoEvents();
            }
            Map.OpenIO();
            for (num = 0; num < Plugin_Scanning_Regions.Count; num++)
            {
                PluginScanningRegion region3 = Plugin_Scanning_Regions[num];
                Map.IO.In.BaseStream.Position = region3.Offset;
                while (Map.IO.In.BaseStream.Position < (region3.Offset + region3.Size))
                {
                    double num2    = ((Map.IO.In.BaseStream.Position - region3.Offset) / ((double)region3.Size)) * 100.0;
                    int    count   = Map.IO.In.ReadInt32();
                    int    pointer = Map.IO.In.ReadInt32() - Map.Map_Header.mapMagic;
                    int    num5    = Map.IO.In.ReadInt32();
                    if (((num5 == 0) && ((count > 0) && (count < 0x927c0))) && PointerIsInRegions(count, pointer))
                    {
                        Reflexive_DataBlock block2 = new Reflexive_DataBlock {
                            Count   = count,
                            Offset  = (int)(Map.IO.In.BaseStream.Position - 12L),
                            Pointer = pointer
                        };
                        Plugin_Data_Blocks.Add(block2);
                    }
                    else if ((PointerIsInRegions(pointer + Map.Map_Header.mapMagic, num5 - Map.Map_Header.mapMagic) && ((pointer + Map.Map_Header.mapMagic) > 0)) && ((pointer + Map.Map_Header.mapMagic) < 0x927c0))
                    {
                        Stream baseStream = Map.IO.In.BaseStream;
                        baseStream.Position -= 8L;
                    }
                    else if (FindIdents)
                    {
                        Stream stream2 = Map.IO.In.BaseStream;
                        stream2.Position -= 12L;
                        string str     = Map.IO.In.ReadAsciiString(4);
                        Stream stream3 = Map.IO.In.BaseStream;
                        stream3.Position += 8L;
                        int num6            = Map.IO.In.ReadInt32();
                        int tagIndexByIdent = Map.GetTagIndexByIdent(num6);
                        if ((tagIndexByIdent != -1) && (Map.Index_Items[tagIndexByIdent].Class == str))
                        {
                            Tag_Ident ident = new Tag_Ident {
                                Offset = ((int)Map.IO.In.BaseStream.Position) - 0x10
                            };
                            Tag_Idents.Add(ident);
                        }
                        else
                        {
                            Stream stream4 = Map.IO.In.BaseStream;
                            stream4.Position -= 12L;
                            if (FindVoids)
                            {
                                Stream stream5 = Map.IO.In.BaseStream;
                                stream5.Position -= 4L;
                                uint num8  = Map.IO.In.ReadUInt32();
                                int  num9  = Map.IO.In.ReadInt32();
                                int  num10 = Map.IO.In.ReadInt32();
                                pointer = Map.IO.In.ReadInt32() - Map.Map_Header.mapMagic;
                                int num11 = Map.IO.In.ReadInt32();
                                if (((PointerIsInRegions((int)num8, pointer) && (num8 > 0)) && ((num9 == 0) && (num10 == 0))) && (num11 == 0))
                                {
                                    Tag_Void @void = new Tag_Void {
                                        Offset = ((int)Map.IO.In.BaseStream.Position) - 20
                                    };
                                    Tag_Voids.Add(@void);
                                }
                                else
                                {
                                    Stream stream6 = Map.IO.In.BaseStream;
                                    stream6.Position -= 0x10L;
                                }
                            }
                            else
                            {
                                Stream stream7 = Map.IO.In.BaseStream;
                                stream7.Position -= 4L;
                            }
                        }
                    }
                }
            }
            Map.CloseIO();
            for (num = 0; num < Plugin_Data_Blocks.Count; num++)
            {
                CalculateStructureSize(Plugin_Data_Blocks[num]);
            }
            if (FindChildren)
            {
                for (num = 0; num < Plugin_Data_Blocks.Count; num++)
                {
                    MapChildren(Plugin_Data_Blocks[num]);
                }
            }
            return(MetaHeader_Data_Blocks);
        }
Example #5
0
        public List <MetaHeader_DataBlock> GetMetaHeaderDataBlocksMapped(bool FindIdents, bool FindChildren)
        {
            //Let's initialize our lists.
            Plugin_Scanning_Regions = new List <PluginScanningRegion>();
            Plugin_Data_Blocks      = new List <PluginDataBlock>();
            MetaHeader_Data_Blocks  = new List <MetaHeader_DataBlock>();
            Tag_Idents = new List <Tag_Ident>();

            //Let's make our first region
            PluginScanningRegion pluginScanRegion = new PluginScanningRegion();

            pluginScanRegion.Offset = Map.MapHeader.RawTableOffset + Map.MapHeader.RawTableSize;
            pluginScanRegion.Size   = Map.IndexHeader.tagInfoHeaderOffset - pluginScanRegion.Offset;
            //Add it to our list
            Plugin_Scanning_Regions.Add(pluginScanRegion);

            //Let's make our second region
            PluginScanningRegion pluginScanRegion2 = new PluginScanningRegion();

            pluginScanRegion2.Offset = Map.MapHeader.indexOffset + 40 + ExtraFunctions.CalculatePadding(Map.MapHeader.indexOffset + 40, 0x1000);
            pluginScanRegion2.Size   = new LocaleHandler(Map).LocaleTables[0].LocaleTableIndexOffset - pluginScanRegion2.Offset;
            //Add it to our list
            Plugin_Scanning_Regions.Add(pluginScanRegion2);

            //Loop through each of our tags
            foreach (HaloMap.TagItem tagItem in Map.IndexItems)
            {
                //Initialize our metaheader_datablock
                MetaHeader_DataBlock mhdb = new MetaHeader_DataBlock(tagItem);

                //Add it to our list
                Plugin_Data_Blocks.Add(mhdb);
                MetaHeader_Data_Blocks.Add(mhdb);

                //Unfreeze
                Application.DoEvents();
            }

            //Open our IO
            Map.OpenIO();



            //Loop through each scan region
            for (int i = 0; i < Plugin_Scanning_Regions.Count; i++)
            {
                //Set our plugin scanning region
                PluginScanningRegion scanRegion = Plugin_Scanning_Regions[i];

                //Make our IO go to the scan regions position
                Map.IO.In.BaseStream.Position = scanRegion.Offset;

                while (Map.IO.In.BaseStream.Position < (scanRegion.Offset + scanRegion.Size))
                {
                    double percent = (((double)Map.IO.In.BaseStream.Position - scanRegion.Offset) / (double)scanRegion.Size) * 100;
                    //Possible count
                    int count   = Map.IO.In.ReadInt32();
                    int pointer = Map.IO.In.ReadInt32() - Map.MapHeader.mapMagic;
                    int zeros   = Map.IO.In.ReadInt32();

                    //If our zero data = 0
                    if (zeros == 0)
                    {
                        //If our count is valid.
                        if (count > 0 && count < 600000)
                        {
                            //If our pointer is valid.
                            if (PointerIsInRegions(count, pointer))
                            {
                                //Let's initialize our reflexive data block
                                Reflexive_DataBlock rdb = new Reflexive_DataBlock();
                                rdb.Count   = count;
                                rdb.Offset  = (int)(Map.IO.In.BaseStream.Position - 12);
                                rdb.Pointer = pointer;

                                //Add it to our list
                                Plugin_Data_Blocks.Add(rdb);

                                //Go to our FoundAReflexive location
                                goto FoundAReflexive;
                            }
                        }
                    }
                    //Determine how much to jump back
                    if (PointerIsInRegions(pointer + Map.MapHeader.mapMagic, zeros - Map.MapHeader.mapMagic) && pointer + Map.MapHeader.mapMagic > 0 && pointer + Map.MapHeader.mapMagic < 600000)
                    {
                        //There's a potential reflexive 8 bytes back!
                        Map.IO.In.BaseStream.Position -= 8;
                    }
                    else
                    {
                        //If we are to find idents.
                        if (FindIdents)
                        {
                            //Didn't find anything. Go back and scan for idents
                            Map.IO.In.BaseStream.Position -= 12;

                            //Read our 4 values
                            string tagClass = Map.IO.In.ReadAsciiString(4);

                            //Skip 4 bytes
                            Map.IO.In.BaseStream.Position += 8;

                            //Read our id
                            int ident = Map.IO.In.ReadInt32();

                            //Get our index
                            int index = Map.GetTagIndexByIdent(ident);

                            //If our index isn't -1
                            if (index != -1)
                            {
                                //If our tag's class == tagclass
                                if (Map.IndexItems[index].Class == tagClass)
                                {
                                    //Initialize our new ident
                                    Tag_Ident id = new Tag_Ident();
                                    //Set our offset.
                                    id.Offset = ((int)Map.IO.In.BaseStream.Position - 16);
                                    //Add it to our list
                                    Tag_Idents.Add(id);
                                    //Go to our found ident spot
                                    goto FoundIdent;
                                }
                            }
                            //We didn't find an ident. Go back
                            Map.IO.In.BaseStream.Position -= 12;

                            //Where we go if we found an ident
                            FoundIdent :;
                        }
                        else
                        {
                            //If we aren't to find idents.
                            //Go 4 bytes back.
                            Map.IO.In.BaseStream.Position -= 4;
                        }
                    }
                    //Where we'll jump to if we found a reflex, so we dont go back 8 bytes for no reason, wasting time.
                    FoundAReflexive :;
                }
            }

            //Close our IO
            Map.CloseIO();

            //Let's calculate our sizes.. Loop through each data block
            for (int i = 0; i < Plugin_Data_Blocks.Count; i++)
            {
                CalculateStructureSize(Plugin_Data_Blocks[i]);
            }

            //If we are to map children.
            if (FindChildren)
            {
                //Let's map our children. Loop through each plugin data block
                for (int i = 0; i < Plugin_Data_Blocks.Count; i++)
                {
                    MapChildren(Plugin_Data_Blocks[i]);
                }
            }

            //Return our meta blocks
            return(MetaHeader_Data_Blocks);
        }