SortItemsByOffset() public method

The sort items by offset.
public SortItemsByOffset ( ) : void
return void
Example #1
0
        /// <summary>
        /// The save recursive function.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <param name="metas">The metas.</param>
        /// <param name="parsed">The parsed.</param>
        /// <param name="pb">The pb.</param>
        /// <param name="percent">The percent.</param>
        /// <param name="percentsize">The percentsize.</param>
        /// <remarks></remarks>
        private void SaveRecursiveFunction(
            Meta meta, 
            ref ArrayList metas, 
            bool parsed, 
            ToolStripProgressBar pb, 
            float percent, 
            float percentsize)
        {
            int wtf = metas.Count;
            if (meta.items.Count == 0)
            {
                return;
            }

            float test = meta.items.Count;

            float currentpercentsize = percentsize / test;

            Item i = null;

            try
            {
                for (int x = 0; x < meta.items.Count; x++)
                {
                    i = meta.items[x];
                    if (i.type != ItemType.Ident)
                    {
                        continue;
                    }

                    float currentpercentage = percent + (currentpercentsize * x);
                    pb.Value = (int)currentpercentage;
                    Application.DoEvents();

                    Ident id = (Ident)i;

                    if (id.ident == -1)
                    {
                        continue;
                    }

                    if (id.ident == 0)
                    {
                        int tagIndex = Map.Functions.ForMeta.FindByNameAndTagType("sbsp", i.intagname);
                        id.ident = Map.MetaInfo.Ident[tagIndex];
                    }

                    bool exists = false;

                    for (int e = 0; e < metas.Count; e++)
                    {
                        Meta tempmeta = (Meta)metas[e];

                        // if (id.pointstotagtype  ==tempmeta.type&&id.pointstotagname ==tempmeta.name )
                        if (id.ident == tempmeta.ident)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    // Drag & drop w/ recursive locks up. num == -1
                    int num = Map.Functions.ForMeta.FindMetaByID(id.ident);
                    if (num < 0)
                    {
                        MessageBox.Show("ERROR! Not Found!");
                    }

                    Meta m = new Meta(Map);
                    if (parsed)
                    {
                        m.parsed = true;
                    }

                    m.ReadMetaFromMap(num, false);
                    if (m.type == "ltmp" | m.type == "matg")
                    {
                        continue;
                    }

                    if (m.type == "phmo" | m.type == "coll" | m.type == "jmad")
                    {
                        m.parsed = false;
                    }

                    if (m.type != "jmad")
                    {
                        IFPIO ifp = IFPHashMap.GetIfp(m.type, Map.HaloVersion);
                        m.headersize = ifp.headerSize;

                        m.scanner.ScanWithIFP(ref ifp);
                    }
                    else
                    {
                        m.scanner.ScanManually();
                    }

                    m.SortItemsByOffset();

                    metas.Add(m);

                    Application.DoEvents();
                    SaveRecursiveFunction(m, ref metas, parsed, pb, currentpercentage, currentpercentsize);
                }
            }
            catch (Exception e)
            {
                string addOn = "\nin [" + meta.type + "] " + meta.name;
                if (i.type == ItemType.Ident)
                    addOn = "\n" + i.description + ", Ident: " + ((Ident)i).ident + addOn;
                throw new Exception(e.Message + addOn, e.InnerException);
            }
        }
Example #2
0
        /// <summary>
        /// The save recursive function.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <param name="metas">The metas.</param>
        /// <param name="parsed">The parsed.</param>
        /// <param name="pb">The pb.</param>
        /// <param name="percent">The percent.</param>
        /// <param name="percentsize">The percentsize.</param>
        /// <remarks></remarks>
        private void SaveRecursiveFunction(
            Meta meta,
            ref ArrayList metas,
            bool parsed,
            ToolStripProgressBar pb,
            float percent,
            float percentsize)
        {
            int wtf = metas.Count;

            if (meta.items.Count == 0)
            {
                return;
            }

            float test = meta.items.Count;

            float currentpercentsize = percentsize / test;

            Item i = null;

            try
            {
                for (int x = 0; x < meta.items.Count; x++)
                {
                    i = meta.items[x];
                    if (i.type != ItemType.Ident)
                    {
                        continue;
                    }

                    float currentpercentage = percent + (currentpercentsize * x);
                    pb.Value = (int)currentpercentage;
                    Application.DoEvents();

                    Ident id = (Ident)i;

                    if (id.ident == -1)
                    {
                        continue;
                    }

                    if (id.ident == 0)
                    {
                        int tagIndex = Map.Functions.ForMeta.FindByNameAndTagType("sbsp", i.intagname);
                        id.ident = Map.MetaInfo.Ident[tagIndex];
                    }

                    bool exists = false;

                    for (int e = 0; e < metas.Count; e++)
                    {
                        Meta tempmeta = (Meta)metas[e];

                        // if (id.pointstotagtype  ==tempmeta.type&&id.pointstotagname ==tempmeta.name )
                        if (id.ident == tempmeta.ident)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    // Drag & drop w/ recursive locks up. num == -1
                    int num = Map.Functions.ForMeta.FindMetaByID(id.ident);
                    if (num < 0)
                    {
                        MessageBox.Show("ERROR! Not Found!");
                    }

                    Meta m = new Meta(Map);
                    if (parsed)
                    {
                        m.parsed = true;
                    }

                    m.ReadMetaFromMap(num, false);
                    if (m.type == "ltmp" | m.type == "matg")
                    {
                        continue;
                    }

                    if (m.type == "phmo" | m.type == "coll" | m.type == "jmad")
                    {
                        m.parsed = false;
                    }

                    if (m.type != "jmad")
                    {
                        IFPIO ifp = IFPHashMap.GetIfp(m.type, Map.HaloVersion);
                        m.headersize = ifp.headerSize;

                        m.scanner.ScanWithIFP(ref ifp);
                    }
                    else
                    {
                        m.scanner.ScanManually();
                    }

                    m.SortItemsByOffset();

                    metas.Add(m);

                    Application.DoEvents();
                    SaveRecursiveFunction(m, ref metas, parsed, pb, currentpercentage, currentpercentsize);
                }
            }
            catch (Exception e)
            {
                string addOn = "\nin [" + meta.type + "] " + meta.name;
                if (i.type == ItemType.Ident)
                {
                    addOn = "\n" + i.description + ", Ident: " + ((Ident)i).ident + addOn;
                }
                throw new Exception(e.Message + addOn, e.InnerException);
            }
        }
Example #3
0
        /// <summary>
        /// The get meta from tag index.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="map">The map.</param>
        /// <param name="manualScan">The manual scan.</param>
        /// <param name="parse">The parse.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta GetMetaFromTagIndex(int tag, Map map, bool manualScan, bool parse)
        {
            map.OpenMap(MapTypes.Internal);

            Meta meta = new Meta(map);

            meta.TagIndex = tag;
            meta.ScanMetaItems(manualScan, parse);

            map.CloseMap();

            meta.SortItemsByOffset();

            return meta;
        }
Example #4
0
        /// <summary>
        /// The save recursive.
        /// </summary>
        /// <param name="outputFilePath">The output file path.</param>
        /// <param name="parsed">The parsed.</param>
        /// <param name="pb">The pb.</param>
        /// <remarks></remarks>
        public void SaveRecursive(string outputFilePath, bool parsed, ToolStripProgressBar pb)
        {
            ArrayList metas = RecursivelyLoadMetas(parsed, pb);

            #region Get name tag name
            // Contains the orignal meta name
            string             origName   = ((Meta)metas[0]).name;
            Globals.askForName metaRename = new Globals.askForName("Enter new name for Meta", "Select Exported tag name:", "&Export Recursively", origName, origName.Substring(origName.LastIndexOf('\\') + 1), true);
            if (metaRename.ShowDialog() == DialogResult.Cancel)
            {
                pb.Value = 0;
                return;
            }
            // Contains the changed meta name
            string newName = metaRename.getTextBoxValue();
            metaRename.Dispose();
            #endregion

            // If set to true, will rename any linked tags with the same tag names
            // eg. [eqip] objects\powerups\shotgun_ammo\shotgun_ammo renamed to objects\powerups\shotgun_ammo_max\shotgun_ammo_max
            //    would also have it's name changed in [hltm] & [mode]
            bool recursivelyRenameTags = false;
            if (newName != this.name)
            {
                if (MessageBox.Show("Do you wish to recursively rename similar tags?\n", "Rename recursively?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    recursivelyRenameTags = true;
                }
            }



            int          y  = newName.LastIndexOf("\\") + 1;
            StreamWriter SW = new StreamWriter(new FileStream(
                                                   outputFilePath + "\\" + newName.Substring(y, newName.Length - y) + ".info", FileMode.Create));
            for (int x = 0; x < metas.Count; x++)
            {
                Meta m = (Meta)metas[x];

                string temp1 = m.name;

                #region Recursive Renaming
                List <string> backup = new List <string>();
                // Backup all the items PointsToTagName values &
                // change these to reflect recursive renaming
                // Rename the first Meta
                if (x == 0 && !recursivelyRenameTags)
                {
                    temp1 = newName;
                }
                else if (recursivelyRenameTags && temp1 == origName)
                {
                    temp1 = newName;
                    for (int i = 0; i < m.items.Count; i++)
                    {
                        switch (m.items[i].type)
                        {
                        case ItemType.Ident:
                            backup.Add(((Ident)m.items[i]).pointstotagname);
                            if (((Ident)m.items[i]).pointstotagname == this.name)
                            {
                                ((Ident)m.items[i]).pointstotagname = newName;
                            }
                            break;

                        case ItemType.Reflexive:
                            backup.Add(((Reflexive)m.items[i]).pointstotagname);
                            if (((Reflexive)m.items[i]).pointstotagname == this.name)
                            {
                                ((Reflexive)m.items[i]).pointstotagname = newName;
                            }
                            break;

                        default:
                            backup.Add(string.Empty);
                            break;
                        }
                    }
                }
                #endregion

                // directory to create
                int    loc   = temp1.LastIndexOf("\\") + 1;
                string temp2 = outputFilePath + "\\" + temp1.Substring(0, loc);
                Directory.CreateDirectory(temp2);

                // name of meta
                string tempname = temp1.Substring(loc, temp1.Length - loc);
                string temp3    = temp2 + tempname + "." + m.type;
                temp3 = temp3.Replace("<", "_");
                temp3 = temp3.Replace(">", "_");
                m.SortItemsByOffset();
                m.SaveMetaToFile(temp3, false);

                #region Recursive Renaming Restore
                // Restore Items PointsToTagName values
                if (recursivelyRenameTags)
                {
                    for (int i = 0; i < m.items.Count; i++)
                    {
                        switch (m.items[i].type)
                        {
                        case ItemType.Ident:
                            if (((Ident)m.items[i]).pointstotagname == this.name)
                            {
                                ((Ident)m.items[i]).pointstotagname = backup[i];
                            }
                            break;

                        case ItemType.Reflexive:
                            if (((Reflexive)m.items[i]).pointstotagname == this.name)
                            {
                                ((Reflexive)m.items[i]).pointstotagname = backup[i];
                            }
                            break;
                        }
                    }
                    backup.Clear();
                }
                #endregion

                SW.WriteLine(temp3);
            }

            SW.Flush();
            SW.Close();

            // Reset Progress Bar
            pb.Value = 0;
        }