Summary description for Meta.
Example #1
0
        /// <summary>
        /// The h 2 parsed prtm.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void H2ParsedPRTM(ref Meta meta)
        {
            string[] temps = meta.name.Split('\\');
            name = temps[temps.Length - 1];

            BoundingBox = new BoundingBoxContainer();

            BinaryReader BR = new BinaryReader(meta.MS);

            RawDataMetaChunks = new RawDataMetaChunk[1];
            RawDataMetaChunks[0] = new PRTMRawDataMetaChunk(ref meta);

            BR.BaseStream.Position = 28;
            int tempshad = BR.ReadInt32();
            int shadid = meta.Map.Functions.ForMeta.FindMetaByID(tempshad);
            Shaders = new ShaderContainer();
            Shaders.Shader = new ShaderInfo[1];
            Shaders.Shader[0] = new ShaderInfo(shadid, meta.Map);

            // LOD = new LODInfo(ref meta, meta.Map, ref RawDataMetaChunks);
            Display = new DisplayedInfo();
            Display.Chunk.Add(0);
            Display.ShaderIndex = new int[1];
            Display.ShaderIndex[0] = 0;

            // MessageBox.Show("test");
        }
Example #2
0
 public Enums(Meta meta, string iEntName, Map map, int iOffsetInChunk, int iType, object[] ioptions, int iLineNumber)
 {
     this.meta = meta;
     this.LineNumber = iLineNumber;
     this.Options = ioptions;
     this.enumType = iType;
     this.size = iType / 8;
     this.chunkOffset = iOffsetInChunk;
     this.map = map;
     this.EntName = iEntName;
     InitializeComponent();
     this.Size = this.PreferredSize;
     this.Dock = DockStyle.Top;
     this.Controls[0].Text = EntName;
     switch (iType)
     {
         case 8:
             {
                 this.Controls[2].Text = "Enum8";
                 break;
             }
         case 16:
             {
                 this.Controls[2].Text = "Enum16";
                 break;
             }
         case 32:
             {
                 this.Controls[2].Text = "Enum32";
                 break;
             }
     }
     this.AutoSize = false;
 }
Example #3
0
 public DataValues(Meta meta, string iEntName, Map map, int iOffsetInChunk, IFPIO.ObjectEnum type, int iLineNumber)
 {
     this.meta = meta;
     this.LineNumber = iLineNumber;
     this.chunkOffset = iOffsetInChunk;
     this.map = map;
     this.EntName = iEntName;
     InitializeComponent();
     this.Dock = DockStyle.Top;
     this.Controls[0].Text = EntName;
     this.Controls[2].Text = type.ToString();
     this.ValueType = type;
     switch (this.ValueType)
     {
         case IFPIO.ObjectEnum.Byte:
             this.size = 1;
             break;
         case IFPIO.ObjectEnum.Short:
         case IFPIO.ObjectEnum.UShort:
             this.size = 2;
             break;
         case IFPIO.ObjectEnum.Int:
         case IFPIO.ObjectEnum.UInt:
         case IFPIO.ObjectEnum.Float:
         case IFPIO.ObjectEnum.Unknown:
             this.size = 4;
             break;
         case IFPIO.ObjectEnum.Unused:
             this.size = 0;
             break;
     }
     this.AutoSize = false;
 }
        public MetaEditorControlPage(Meta meta, MapForms.MapForm mapForm)
        {
            InitializeComponent();

            // Try to draw treeview nodes to "hide" "disabled" nodes; fail. Still leaves space where node is
            //treeViewTagReflexives.DrawMode = TreeViewDrawMode.OwnerDrawAll;
            //treeViewTagReflexives.DrawNode += new DrawTreeNodeEventHandler(myTreeView_DrawNode);

            this.MapForm = mapForm;
            this.map = mapForm.map;

            this.meta = meta;
            this.BR = new BinaryReader(meta.MS);
            // Create a backup of the Tags memory stream, for restoring, comparing, etc
            msBackup = new MemoryStream(meta.MS.ToArray());
            msDebug = new MemoryStream((int)meta.MS.Length);

            mainReflexive = createReflexiveList();  // Done
            refreshTreeListing(mainReflexive);      // Done

            this.treeViewTagReflexives.Sort();
            treeViewTagReflexives.SelectedNode = treeViewTagReflexives.Nodes[0];
            // Default Peek/Poke to "Single Value"
            this.tscbApplyTo.SelectedIndex = 0;
        }
Example #5
0
        /// <summary>
        /// Creates a color wheel with associated (A)RGB text boxes
        /// </summary>
        /// <param name="meta"></param>
        /// <param name="iEntName">Control display name</param>
        /// <param name="map"></param>
        /// <param name="iOffsetInChunk"></param>
        /// <param name="hasAlphaChannel">True if ARGB, False for RGB</param>
        /// <param name="valueType">Float for 0f-1f, Int for 0-255</param>
        /// <param name="iLineNumber"></param>
        public argb_color(Meta meta, string iEntName, Map map, int iOffsetInChunk, bool hasAlphaChannel, IFPIO.ObjectEnum valueType,int iLineNumber)
        {
            InitializeComponent();

            this.meta = meta;
            this.LineNumber = iLineNumber;
            this.chunkOffset = iOffsetInChunk;
            this.map = map;
            this.EntName = " " + iEntName + " ";
            this.Dock = DockStyle.Top;
            this.Controls[0].Text = EntName;
            this.hasAlpha = hasAlphaChannel;
            this.ValueType = valueType;
            switch (valueType)
            {
                case IFPIO.ObjectEnum.Byte:
                    this.eachSize = 1;
                    break;
                case IFPIO.ObjectEnum.Short:
                case IFPIO.ObjectEnum.UShort:
                    this.eachSize = 2;
                    break;
                case IFPIO.ObjectEnum.Int:
                case IFPIO.ObjectEnum.UInt:
                case IFPIO.ObjectEnum.Float:
                case IFPIO.ObjectEnum.Unknown:
                    this.eachSize = 4;
                    break;
            }
            this.size = (hasAlpha ? eachSize * 4 : eachSize * 3);

            CW = new ColorWheel();
            CW.Location = new Point(180, 5);

            Red = new DataValues(meta, "Red", map, iOffsetInChunk, valueType, iLineNumber);
            Red.BackColor = System.Drawing.Color.DarkRed;
            CW.setTextBox(Red.textBox1, Color.Red);

            Blue = new DataValues(meta, "Blue", map, iOffsetInChunk + eachSize, valueType, iLineNumber);
            Blue.BackColor = System.Drawing.Color.DarkBlue;
            CW.setTextBox(Blue.textBox1, Color.Blue);

            Green = new DataValues(meta, "Green", map, iOffsetInChunk + eachSize * 2, valueType, iLineNumber);
            Green.BackColor = System.Drawing.Color.FromArgb(10, 80, 35);
            CW.setTextBox(Green.textBox1, Color.Green);

            if (hasAlpha)
            {
                Alpha = new DataValues(meta, "Alpha", map, iOffsetInChunk + eachSize * 3, valueType, iLineNumber);
                Alpha.BackColor = System.Drawing.Color.Gray;
                CW.setTextBox(Alpha.textBox1, Color.White);
                gbRGBColor.Controls.Add(Alpha);
            }

            gbRGBColor.Controls.Add(CW);
            CW.BringToFront();
            gbRGBColor.Controls.Add(Green);
            gbRGBColor.Controls.Add(Blue);
            gbRGBColor.Controls.Add(Red);
        }
Example #6
0
        /// <summary>
        /// The get frames from halo 2 model.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void GetFramesFromHalo2Model(ref Meta meta)
        {
            BinaryReader BR = new BinaryReader(meta.MS);
            BR.BaseStream.Position = 72;
            int tempc = BR.ReadInt32();
            int tempr = BR.ReadInt32() - meta.magic - meta.offset;
            for (int x = 0; x < tempc; x++)
            {
                FrameInfo f = new FrameInfo();
                BR.BaseStream.Position = tempr + (96 * x);
                f.Name = meta.Map.Strings.Name[BR.ReadUInt16()];
                BR.ReadUInt16();
                f.Parent = BR.ReadInt16();
                f.Child = BR.ReadInt16();
                f.Sibling = BR.ReadInt16();
                BR.BaseStream.Position = tempr + (96 * x) + 12;
                f.x = BR.ReadSingle();
                f.y = BR.ReadSingle();
                f.z = BR.ReadSingle();
                f.i = BR.ReadSingle();
                f.j = BR.ReadSingle();
                f.k = BR.ReadSingle();
                f.w = BR.ReadSingle();
                f.matrix = Matrix.Identity;

                Quaternion q = new Quaternion(f.i, f.j, f.k, f.w);
                f.matrix.Multiply(Matrix.Translation(f.x, f.y, f.z));
                f.matrix.RotateQuaternion(q);

                BR.ReadSingle();

                f.skinweightmatrix = Matrix.Identity;
                f.skinweightmatrix.M11 = BR.ReadSingle();
                f.skinweightmatrix.M12 = BR.ReadSingle();
                f.skinweightmatrix.M13 = BR.ReadSingle();
                f.skinweightmatrix.M14 = 0.0f;

                f.skinweightmatrix.M21 = BR.ReadSingle();
                f.skinweightmatrix.M22 = BR.ReadSingle();
                f.skinweightmatrix.M23 = BR.ReadSingle();
                f.skinweightmatrix.M24 = 0.0f;

                f.skinweightmatrix.M31 = BR.ReadSingle();
                f.skinweightmatrix.M32 = BR.ReadSingle();
                f.skinweightmatrix.M33 = BR.ReadSingle();
                f.skinweightmatrix.M34 = 0.0f;

                f.skinweightmatrix.M41 = BR.ReadSingle();
                f.skinweightmatrix.M42 = BR.ReadSingle();
                f.skinweightmatrix.M43 = BR.ReadSingle();
                f.skinweightmatrix.M44 = 1.0f;

                f.DistanceFromParent = BR.ReadSingle();

                // f.matrix.MultiplyTranspose(f.skinweightmatrix);//=Matrix.Transformation(new Vector3(0, 0, 0), new Quaternion(),new Vector3(1,1,1), new Vector3(0, 0, 0), q, new Vector3(f.x, f.y, f.z));
                Frame.Add(f);
            }
        }
Example #7
0
        public void loadMeta(Meta meta, HaloVersionEnum HaloVersion, string FileName)
        {
            this.fileName = fileName;
            this.HaloVersion = HaloVersion;
            this.meta = meta;

            loadFile();

            createTreeListing();
        }
Example #8
0
        /// <summary>
        /// The build meta.
        /// </summary>
        /// <param name="metasplit">The metasplit.</param>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Meta BuildMeta(MetaSplitter metasplit, Map map)
        {
            metasize = 0;
            MetaStream = new MemoryStream(metasplit.Header.chunksize);
            BinaryWriter BW = new BinaryWriter(MetaStream);

            // BW.BaseStream.Position = 0;
            // BW.Write(metasplit.Header.MS.ToArray(), 0, metasplit.Header.chunksize);
            metasize += metasplit.Header.chunksize;

            TagIndex = metasplit.TagIndex;

            Meta m = new Meta(map);

            List<Meta.Item> NewItems = new List<Meta.Item>();

            // Major error here! Size is not calculated right!
            RecursivelyAddPiecesToMeta(metasplit.Header, ref NewItems, ref BW);

            m.items = NewItems;
            if (MetaStream.Length % 4 != 0)
            {
                metasize += (int)MetaStream.Length % 4;
                MetaStream.SetLength(MetaStream.Length + MetaStream.Length % 4);
            }

            m.MS = MetaStream;
            m.size = metasize;
            m.type = metasplit.type;
            m.name = metasplit.name;
            m.rawType = metasplit.rawtype;
            m.raw = metasplit.raw;
            m.magic = metasplit.magic;
            m.offset = metasplit.offset;

            m.TagIndex = TagIndex;
            m.RelinkReferences();
            m.WriteReferences();

            // m.items.Clear();
            // MetaScanner Ms = new MetaScanner();
            if (m.rawType != RawDataContainerType.Empty)
            {
                map.OpenMap(MapTypes.Internal);
                m.raw = map.Functions.ForMeta.ReadRaw(m.TagIndex, false);
                map.CloseMap();
            }

            // map.OpenMap(MapTypes.Internal);
            // IFPIO ifp=IFP.IFPHashMap.GetIfp(m.type);
            // m.parsed = true;
            // Ms.ScanWithIFP(ref ifp, ref m, map) ;
            // map.CloseMap();
            return m;
        }
Example #9
0
 public StringBox(Meta meta, string iEntName, Map map, int iOffsetInChunk, int iLineNumber, int chunkCount)
 {
     this.meta = meta;
     this.LineNumber = iLineNumber;
     this.chunkOffset = iOffsetInChunk;
     this.map = map;
     this.EntName = iEntName;
     this.size = chunkCount;
     InitializeComponent();
     this.Size = this.PreferredSize;
     this.Dock = DockStyle.Top;
     this.label3.Text = EntName;
     this.AutoSize = false;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParsedBitmap"/> class.
 /// </summary>
 /// <param name="meta">The meta.</param>
 /// <param name="map">The map.</param>
 /// <remarks></remarks>
 public ParsedBitmap(ref Meta meta, Map map)
 {
     BitmapHeader = new HaloBitmapHeader(ref meta);
     switch (map.HaloVersion)
     {
         case HaloVersionEnum.Halo2:
         case HaloVersionEnum.Halo2Vista:
             ReadH2ParsedBitmap(ref meta);
             break;
         case HaloVersionEnum.HaloCE:
         case HaloVersionEnum.Halo1:
             ReadCEParsedBitmap(ref meta);
             break;
     }
 }
Example #11
0
        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="tagIndex">Index of the tag.</param>
        /// <param name="metasplit">The metasplit.</param>
        /// <remarks></remarks>
        public void Add(int tagIndex, MetaSplitter metasplit)
        {
            // TagIndex - Global Variable
            this.TagIndex = tagIndex;

            ArrayList metas = new ArrayList(0);

            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                // sender.setProgressBar(x / map.IndexHeader.metaCount);
                Meta m = new Meta(map);
                m.ReadMetaFromMap(x, true);

                // Read meta layout of TAG from .ENT file
                IFPIO ifpx = IFPHashMap.GetIfp(m.type, map.HaloVersion);

                m.headersize = ifpx.headerSize;

                if (m.type == "sbsp")
                {
                }
                else
                {
                    // anything but "sbsp"
                    m.scanner.ScanWithIFP(ref ifpx);

                    // metaScanner.ScanManually(ref m, ref map);
                }

                metas.Add(m);
            }

            // sender.setProgressBar(0);
            Meta targetTag = (Meta)metas[tagIndex];

            Meta tempm = MetaBuilder.BuildMeta(metasplit, map); // (Meta) metas[TagIndex];
            metas[tagIndex] = tempm;

            // ((Meta)metas[TagIndex]).RelinkReferences(map);
            SizeOfShift = tempm.size - targetTag.size;

            // Map IS already open? I guess it's a safety check.
            map.OpenMap(MapTypes.Internal);
            FixReflexives(metas);

            map.CloseMap();
        }
Example #12
0
 /// <summary>
 /// Creates a new EntStrings class for a set-length unicode or ASCII string.
 /// </summary>
 /// <param name="meta">The controls meta data</param>
 /// <param name="iEntName">The identifying name of the meta string</param>
 /// <param name="map">The metas map file</param>
 /// <param name="iOffsetInChunk">The offset to the string in the memory stream</param>
 /// <param name="ilength">The set length of the string (usually 32, 64 or 256, but will handle any length strings)</param>
 /// <param name="itype">Set to false for ASCII strings, true for Unicode (UTF-8) strings</param>
 /// <param name="iLineNumber">The associated line number</param>
 public EntStrings(Meta meta, string iEntName, Map map, int iOffsetInChunk, int ilength, bool itype, int iLineNumber)
 {
     this.meta = meta;
     this.LineNumber = iLineNumber;
     this._entUnicode = itype;
     this._length = ilength;
     this.size = this._length;
     this.map = map;
     this.EntName = iEntName;
     this.chunkOffset = iOffsetInChunk;
     InitializeComponent();
     this.label2.Text = EntName;
     this.Dock = DockStyle.Top;
     this.Size = this.PreferredSize;
     this.AutoSize = false;
     this.Leave += new EventHandler(String_Leave);
 }
        public MetaEditorControlPage(Meta meta, MapForms.MapForm mapForm)
        {
            InitializeComponent();

            this.MapForm = mapForm;
            this.map = mapForm.map;

            this.meta = meta;
            this.BR = new BinaryReader(meta.MS);
            // Create a backup of the Tags memory stream, for restoring, comparing, etc
            msBackup = new MemoryStream(meta.MS.ToArray());
            msDebug = new MemoryStream((int)meta.MS.Length);

            createTreeListing();
            this.treeViewTagReflexives.Sort();
            treeViewTagReflexives.SelectedNode = treeViewTagReflexives.Nodes[0];
        }
Example #14
0
        public SID(Meta meta, string iEntName, Map map, int iOffsetInChunk,int iLineNumber)
        {
            this.meta = meta;
            this.LineNumber = iLineNumber;
            this.chunkOffset = iOffsetInChunk;
            this.map = map;
            this.EntName = iEntName;
            this.size = 4;
            InitializeComponent();
            this.Size = this.PreferredSize;
            this.Dock = DockStyle.Top;
            this.Controls[0].Text = EntName;
            this.AutoSize = false;

            //this.comboBox1.DataSource = map.Strings.Name;
            this.comboBox1.DataSource = null;    // Loading data source takes a long time. Only do it when needed.
        }
Example #15
0
        /// <summary>
        /// The split with ifp.
        /// </summary>
        /// <param name="ifp">The ifp.</param>
        /// <param name="meta">The meta.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void SplitWithIFP(ref IFPIO ifp, ref Meta meta, Map map)
        {
            this.type = meta.type;
            this.TagIndex = meta.TagIndex;
            this.name = meta.name;
            this.offset = meta.offset;
            this.magic = meta.magic;
            this.raw = meta.raw;
            this.rawtype = meta.rawType;
            map.OpenMap(MapTypes.Internal);
            if (ifp.items != null)
            {
                map.BR.BaseStream.Position = meta.offset;
                Header = new SplitReflexive();
                Header.offset = 0;
                Header.Chunks = new List<SplitReflexive>();
                Header.translation = 0;

                // Header.MS = new MemoryStream(ifp.headerSize);
                // Header.MS.Write(map.BR.ReadBytes(ifp.headerSize), 0, ifp.headerSize);
                Header.chunksize = ifp.headerSize;
                Header.chunkcount = 1;
                Header.splitReflexiveType = SplitReflexive.SplitReflexiveType.Container;
                Header.realtranslation = meta.offset;
                if (meta.type == "sbsp")
                {
                    int p = map.BSP.FindBSPNumberByBSPIdent(meta.ident);
                    CycleElements(
                        ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.BSP.sbsp[p].magic);
                }
                else if (meta.type == "ltmp")
                {
                    int p = map.BSP.FindBSPNumberByLightMapIdent(meta.ident);
                    CycleElements(
                        ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.BSP.sbsp[p].magic);
                }
                else
                {
                    // not "sbsp" or "ltmp"
                    CycleElements(ref Header, ifp.items, ref meta, meta.offset, map, meta.TagIndex, map.SecondaryMagic);
                }
            }

            map.CloseMap();
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetaItemComparer"/> class.
        /// </summary>
        /// <param name="currentForm">The current form.</param>
        /// <remarks></remarks>
        public MetaItemComparer(MapForm currentForm)
        {
            Map map = currentForm.map;

            int counter = 0;
            for (counter = 0; counter < map.MapHeader.fileCount; counter++)
            {
                currentForm.SetProgressBar(counter * 100 / map.MapHeader.fileCount);

                ifpMeta = new Meta(map);
                manualMeta = new Meta(map);
                manualMeta.ReadMetaFromMap(counter, false);
                ifpMeta.ReadMetaFromMap(counter, false);

                // parse ifp and scan meta with it
                try
                {
                    IFPIO io = IFPHashMap.GetIfp(ifpMeta.type, map.HaloVersion);

                    ifpMeta.headersize = io.headerSize;
                    manualMeta.headersize = io.headerSize;
                    try
                    {
                        ifpMeta.scanner.ScanWithIFP(ref io);
                    }
                    catch (Exception ex)
                    {
                        Global.ShowErrorMsg("Broken IFP - " + ifpMeta.type, ex);
                    }

                    manualMeta.scanner.ScanManually();
                    check(map);
                }
                catch (Exception ex)
                {
                    Globals.Global.ShowErrorMsg(string.Empty, ex);
                }

            }

            currentForm.SetProgressBar(0);
        }
Example #17
0
        /// <summary>
        /// The (Tag Type &) Ident Class
        /// </summary>
        /// <param name="meta">The controls meta data</param>
        /// <param name="iEntName">The identifying name of the meta string</param>
        /// <param name="map">The metas map file</param>
        /// <param name="iOffsetInChunk">The offset to the string in the memory stream</param>
        /// <param name="idoesHaveTagType">States whether there is a preceding Tag Type or just an Ident</param>
        /// <param name="iLineNumber">The associated line number</param>
        public Ident(Meta meta, string iEntName, Map map, int iOffsetInChunk, bool idoesHaveTagType, int iLineNumber)
        {
            InitializeComponent();
            this.meta = meta;
            this.LineNumber = iLineNumber;
            this.doesHaveTagType = idoesHaveTagType;

            // Even though !iDoesHaveTagType does not save a Tag Type, it is still loaded through the Ident
            if (!idoesHaveTagType)
                this.label1.Text = "Ident";
            this.size = 4 + (this.doesHaveTagType ? 4 : 0);
            this.map = map;
            this.EntName = iEntName;
            // Offset - 4 to account for Tag Type if applicable
            this.chunkOffset = iOffsetInChunk - (idoesHaveTagType ? 4 : 0);
            this.label4.Text = EntName;
            this.Dock = DockStyle.Top;
            //this.Size = this.PreferredSize;
            this.AutoSize = false;
        }
Example #18
0
        /// <summary>
        /// Opens a new tab and loads the meta into it
        /// </summary>
        /// <param name="meta">The meta to load into the new tab</param>
        /// <param name="allowDuplicate">if false, will look for a tab with the same meta and activate.
        /// if true, will open a new tab with a duplicated meta</param>
        /// <returns>Page Number of active tab</returns>
        public int addNewTab( Meta meta, bool allowDuplicate)
        {
            string typeAndTag = "[" + meta.type.ToLower() + "] " + meta.name.Substring(meta.name.LastIndexOf('\\') + 1);

            if (!allowDuplicate)
                for (int i = 0; i < this.tabs.Tabs.Count; i++)
                    if (this.tabs.Tabs[i].Text == typeAndTag)
                    {
                        this.tabs.SelectedTabIndex = i;
                        //this.tabs.SelectedTab.Focus();
                        return i;
                    }

            MetaEditorControlPage mecp = new MetaEditorControlPage(meta, mapForm);
            this.BackColor = bgColor;
            this.ForeColor = fgColor;
            mecp.setFormColors(fgColor, bgColor);

            // mapName = map.filePath.Substring(map.filePath.LastIndexOf('\\') + 1).ToUpper() +
            TabItem tp = tabs.CreateTab(typeAndTag);
            mecp.Parent = tp.AttachedControl;
            mecp.Dock = DockStyle.Fill;
            tp.Tooltip = "[" + @meta.type.ToLower() + "] " + @meta.name;

            this.tabs.AllowDrop = true;
            //this.tabs.DragDrop += new DragEventHandler(tp_DragDrop);
            //this.tabs.DragEnter += new DragEventHandler(tp_DragEnter);
            //this.tabs.DragLeave += new EventHandler(tp_DragLeave);
            //// These tabs don't change selected index till MouseUp, so do it on MouseDown!
            //this.tabs.MouseDown += new MouseEventHandler(tabControl1_MouseDown);
            //this.tabs.MouseMove += new MouseEventHandler(tabControl1_MouseMove);

            this.tabs.SelectedTabIndex = tabs.Tabs.IndexOf(tp);

            this.WindowState = FormWindowState.Normal;
            this.Show();
            this.Focus();

            return tabs.Tabs.IndexOf(tp);
        }
Example #19
0
 /// <summary>
 /// The Bitmask class
 /// </summary>
 /// <param name="meta">The controls meta data</param>
 /// <param name="iEntName">The identifying name of the meta string</param>
 /// <param name="map">The metas map file</param>
 /// <param name="iOffsetInChunk">The offset to the string in the memory stream</param>
 /// <param name="iBitCount">8 for Bitmask8, 16 for Bitmask16, 32 for Bitmask32 types</param>
 /// <param name="ioptions">The array of options available</param>
 /// <param name="iLineNumber"></param>
 public Bitmask(Meta meta, string iEntName, Map map, int iOffsetInChunk, int iBitCount, IFPIO.Option[] ioptions, int iLineNumber)
 {
     this.meta = meta;
     this.LineNumber = iLineNumber;
     this.Options = ioptions;
     this.Bits = new bool[iBitCount];
     this.visibleBits = new bool[iBitCount];
     this.bitCount = iBitCount;
     this.size = iBitCount / 8;
     this.chunkOffset = iOffsetInChunk;
     this.map = map;
     this.EntName = iEntName;
     InitializeComponent();
     this.label1.Text = "Bitmask" + iBitCount.ToString();
     this.label1.Left -= iBitCount.ToString().Length * 8;
     this.getLongestName();
     this.MakeControls();
     this.Size = this.PreferredSize;
     this.Dock = DockStyle.Top;
     this.Controls[0].Text = EntName;
     this.AutoSize = true;
 }
Example #20
0
        /// <summary>
        /// The dissect meta.
        /// </summary>
        /// <param name="m">The m.</param>
        /// <remarks></remarks>
        public static void DissectMeta(ref Meta m)
        {
            object tempobject = Results[m.type];
            if (tempobject == null)
            {
                MetaResult mr = new MetaResult();
                IFPIO io = IFPHashMap.GetIfp(m.type, m.Map.HaloVersion);
                mr.IFP = io;
                Results.Add(m.type, mr);
                tempobject = Results[m.type];
            }

            MetaResult CurrentResult = tempobject as MetaResult;

            // figure out headersize for current meta
            int headersize = m.size;
            for (int x = 0; x < m.items.Count; x++)
            {
                if (m.items[x].type == Meta.ItemType.Reflexive)
                {
                    Meta.Reflexive tempr = m.items[x] as Meta.Reflexive;
                    if (tempr.translation < headersize && tempr.intag == m.TagIndex)
                    {
                        headersize = tempr.translation;
                    }
                }
            }

            if (CurrentResult.HeaderSizes.IndexOf(headersize) == -1)
            {
                CurrentResult.HeaderSizes.Add(headersize);
            }

            //
            AnalyzeReferences(ref m);
        }
Example #21
0
        /// <summary>
        /// The read h 2 parsed bitmap.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void ReadH2ParsedBitmap(ref Meta meta)
        {
            BinaryReader BR = new BinaryReader(meta.MS);
            BR.BaseStream.Position = 68;
            int tempc = BR.ReadInt32();
            int tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
            headersize = tempr;
            Properties = new BitmapInfo[tempc];
            int okay = -1;
            for (int x = 0; x < tempc; x++)
            {
                Properties[x] = new BitmapInfo(tempr + (116 * x), ref meta);
                if (Properties[x].bitsPerPixel == 0)
                {
                    okay = x;
                }

                if (Properties[x].format == 23)
                {
                }
            }

            if (okay != -1)
            {
                MessageBox.Show(
                    Properties[okay].formatname +
                    "\nFormat not supported, please inform developer of above format name.");
            }
        }
Example #22
0
 /// <summary>
 /// The read ce parsed bitmap.
 /// </summary>
 /// <param name="meta">The meta.</param>
 /// <remarks></remarks>
 public void ReadCEParsedBitmap(ref Meta meta)
 {
     using (BinaryReader BR = new BinaryReader(meta.MS))
     {
         int tempr;
         if (meta.Map.MetaInfo.external[meta.TagIndex])
         {
             BR.BaseStream.Position = 96;
             int tempc = BR.ReadInt32();
             tempr = BR.ReadInt32();
             headersize = tempr;
             Properties = new BitmapInfo[tempc];
             for (int x = 0; x < tempc; x++)
             {
                 Properties[x] = new BitmapInfo(tempr + (48 * x), ref meta);
             }
         }
         else
         {
             BR.BaseStream.Position = 96;
             int tempc = BR.ReadInt32();
             tempr = BR.ReadInt32() - meta.Map.PrimaryMagic - meta.Map.MetaInfo.Offset[meta.TagIndex];
             headersize = tempr;
             Properties = new BitmapInfo[tempc];
             for (int x = 0; x < tempc; x++)
             {
                 Properties[x] = new BitmapInfo(tempr + (48 * x), ref meta);
             }
         }
     }
 }
Example #23
0
        // visualchunkindex is for lightmaps only
        /// <summary>
        /// The find chunk and decode.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="chunknumber">The chunknumber.</param>
        /// <param name="mipmap">The mipmap.</param>
        /// <param name="meta">The meta.</param>
        /// <param name="map">The map.</param>
        /// <param name="visualchunkindex">The visualchunkindex.</param>
        /// <param name="bspnumber">The bspnumber.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public Bitmap FindChunkAndDecode(
            int bitmap, 
            int chunknumber, 
            int mipmap, 
            ref Meta meta, 
            Map map, 
            int visualchunkindex, 
            int bspnumber)
        {
            for (int x = 0; x < meta.raw.rawChunks.Count; x++)
            {
                BitmapRawDataChunk tempb = (BitmapRawDataChunk)meta.raw.rawChunks[x];
                if (tempb.inchunk == bitmap && tempb.num == chunknumber)
                {
                    int width = this.Properties[bitmap].width >> chunknumber;
                    int height = this.Properties[bitmap].height >> chunknumber;
                    int depth = this.Properties[bitmap].depth >> chunknumber;
                    depth = depth < 1 ? 1 : depth;
                    int pixeloff = this.Properties[bitmap].pixelOffset;
                    int bpp = this.Properties[bitmap].bitsPerPixel;

                    int offset = 0;
                    byte[] guh;
                    #region 2D & 3D (Volume) Textures
                    if (this.Properties[bitmap].typename != BitmapType.BITM_TYPE_CUBEMAP)
                    {
                        for (int i = 0; i < mipmap; i++)
                        {
                            //offset += Math.Max(width >> i, 1) * Math.Max(height >> i, 1) * Math.Max(depth >> i, 1) * (bpp >> 3);
                            switch (this.Properties[bitmap].formatname)
                            {
                                case BitmapFormat.BITM_FORMAT_DXT1:
                                    offset += Math.Max( Math.Max(width >> i, 1) * Math.Max(height >> i, 1) * Math.Max(depth >> i, 1) * (bpp >> 3) / 8, 8);
                                    break;
                                case BitmapFormat.BITM_FORMAT_DXT2AND3:
                                case BitmapFormat.BITM_FORMAT_DXT4AND5:
                                    offset += Math.Max(Math.Max(width >> i, 1) * Math.Max(height >> i, 1) * Math.Max(depth >> i, 1) * (bpp >> 3) / 4, 16);
                                    break;
                                /*
                                case BitmapFormat.BITM_FORMAT_DXT1:
                                    offset /= 8;
                                    break;
                                case BitmapFormat.BITM_FORMAT_DXT2AND3:
                                case BitmapFormat.BITM_FORMAT_DXT4AND5:
                                    offset /= 4;
                                    break;
                                */
                                default:
                                    offset += Math.Max(width >> i, 1) * Math.Max(height >> i, 1) * Math.Max(depth >> i, 1) * (bpp >> 3);
                                    break;
                            }
                        }

                        // XZodia hack to fix issue in 03b_newmombosa, 2nd BSP, G8B8 bitmap issue
                        if (offset > tempb.size)
                            offset = tempb.size;
                        int tempsize = tempb.size - offset;
                        guh = new byte[tempsize];
                        Array.Copy(tempb.MS.ToArray(), offset, guh, 0, tempsize);
                    }
                    #endregion
                    #region Cubemap
                    else
                    {
                        for (int i = 0; i < mipmap; i++)
                        {
                            offset += tempb.mipmaps[i].size;
                        }

                        int tempsize = tempb.size - offset * 6;
                        guh = new byte[tempsize];
                        tempsize /= 6;
                        for (int i = 0; i < 6; i++)
                        {
                            Array.Copy(
                                tempb.MS.ToArray(), i * (offset + tempsize) + offset, guh, i * tempsize, tempsize);
                        }
                    }
                    #endregion

                    width = Math.Max(width >> mipmap, 1);
                    height = Math.Max(height >> mipmap, 1);
                    depth = Math.Max(depth >> mipmap, 1);

                    int widthPad = 0;

                    // 2D AY8 bitmaps are 64 byte padded?
                    int padding = (this.Properties[bitmap].formatname == BitmapFormat.BITM_FORMAT_AY8)
                                ? 64 : 16;
                    if (this.Properties[bitmap].width % padding != 0 && width % padding != 0)
                        widthPad += padding - (width % padding);

                    Bitmap b;
                    try
                    {
                        b = DecodeBitm(
                            guh,
                            height,
                            width + widthPad,
                            depth,
                            bpp,
                            this.Properties[bitmap].typename,
                            this.Properties[bitmap].formatname,
                            this.Properties[bitmap].swizzle,
                            map,
                            visualchunkindex,
                            bspnumber);
                    }
                    catch
                    {
                        b = DecodeBitm(
                            guh,
                            height,
                            width,
                            depth,
                            bpp,
                            this.Properties[bitmap].typename,
                            this.Properties[bitmap].formatname,
                            this.Properties[bitmap].swizzle,
                            map,
                            visualchunkindex,
                            bspnumber);
                    }
                    return b;
                }
            }

            return null;
        }
Example #24
0
        /// <summary>
        /// The convert c eto h 2 parsed bitmap.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void ConvertCEtoH2ParsedBitmap(ref Meta meta, Map map)
        {
            meta.MS = new MemoryStream();
            meta.items.Clear();
            BinaryWriter BW = new BinaryWriter(meta.MS);
            BitmapHeader.WriteHeaderHaloBitmapHeader(ref BW);
            BW.BaseStream.Position = 32;
            BW.Write(new char[44]);
            int size = 76;

            int tempc = 1;
            int tempr = meta.offset + size + meta.magic;
            BW.BaseStream.Position = 60;
            BW.Write(tempc);
            BW.Write(tempr);
            Meta.Reflexive reflex = new Meta.Reflexive();
            reflex.offset = 60;
            reflex.translation = size;

            reflex.intag = meta.TagIndex;
            reflex.intagname = meta.name;
            reflex.intagtype = meta.type;

            reflex.chunkcount = tempc;
            reflex.pointstoTagIndex = meta.TagIndex;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            meta.items.Add(reflex);

            tempc = 1;
            tempr = meta.offset + size + 60 + meta.magic;
            BW.BaseStream.Position = 128;
            BW.Write(tempc);
            BW.Write(tempr);
            reflex = new Meta.Reflexive();
            reflex.offset = 128;
            reflex.translation = size + 60;

            reflex.intag = meta.TagIndex;
            reflex.intagname = meta.name;
            reflex.intagtype = meta.type;

            reflex.chunkcount = tempc;
            reflex.pointstoTagIndex = meta.TagIndex;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            meta.items.Add(reflex);
            BW.BaseStream.Position = size;
            BW.Write(new char[92]);
            size += 92;

            tempc = Properties.Length;
            tempr = meta.offset + size + meta.magic;
            BW.BaseStream.Position = 68;
            BW.Write(tempc);
            BW.Write(tempr);
            reflex = new Meta.Reflexive();
            reflex.offset = 68;
            reflex.translation = size;

            reflex.intag = meta.TagIndex;
            reflex.intagname = meta.name;
            reflex.intagtype = meta.type;

            reflex.chunkcount = tempc;
            reflex.pointstoTagIndex = meta.TagIndex;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            reflex.pointstotagname = meta.name;
            reflex.pointstotagtype = meta.type;
            meta.items.Add(reflex);

            for (int x = 0; x < tempc; x++)
            {
                BW.BaseStream.Position = size + (x * 116);
                BW.Write(new char[116]);

                BW.BaseStream.Position = size + (x * 116);
                Properties[x].Write(ref BW);
                int neg = -1;
                meta.raw.rawChunks[x].pointerMetaOffset = size + (x * 116) + 28;
                BW.BaseStream.Position = meta.raw.rawChunks[x].pointerMetaOffset + 4;
                BW.Write(neg);
                BW.Write(neg);
                BW.Write(neg);
                BW.Write(neg);
                BW.Write(neg);
                BW.Write(meta.raw.rawChunks[x].size);
                Meta.Ident id = new Meta.Ident();
                id.offset = size + (x * 116) + 76;
                BW.BaseStream.Position = id.offset;
                BW.Write(meta.ident);
                id.pointstoTagIndex = meta.TagIndex;
                id.pointstotagname = meta.name;
                id.pointstotagtype = meta.type;
                id.intag = meta.TagIndex;
                id.intagname = meta.name;
                id.intagtype = meta.type;
                id.ident = meta.ident;
                meta.items.Add(id);
            }

            meta.size = size + (Properties.Length * 116);
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetaScanner"/> class.
 /// </summary>
 /// <param name="meta">The meta.</param>
 /// <remarks></remarks>
 public MetaScanner(Meta meta)
 {
     this.meta = meta;
 }
Example #26
0
        /// <summary>
        /// The bitmap internalize.
        /// </summary>
        /// <param name="bitmapMeta">The bitmap meta.</param>
        /// <remarks></remarks>
        public static void bitmapInternalize(Meta bitmapMeta)
        {
            if (bitmapMeta.raw.rawChunks[0].rawLocation == MapTypes.Internal)
            {
                return;
            }

            string sharedMapPath = string.Empty;
            switch (bitmapMeta.raw.rawChunks[0].rawLocation)
            {
                case MapTypes.Internal:
                    sharedMapPath = bitmapMeta.Map.filePath;
                    break;
                case MapTypes.Bitmaps:
                    sharedMapPath = Prefs.pathBitmaps;
                    break;
                case MapTypes.MainMenu:
                    sharedMapPath = Prefs.pathMainmenu;
                    break;
                case MapTypes.MPShared:
                    sharedMapPath = Prefs.pathShared;
                    break;
                case MapTypes.SPShared:
                    sharedMapPath = Prefs.pathSPShared;
                    break;
            }

            Map sharedMap = Map.LoadFromFile(sharedMapPath);

            //long sizeToShift = 0;

            sharedMap.OpenMap(MapTypes.Internal);
            bitmapMeta.Map.OpenMap(MapTypes.Internal, false);

            // Find size of aall raw chunks and insert that amount into our bitmapMeta.Map
            long rawSize = biGetRawTotalSize(bitmapMeta.raw, true);
            shift(bitmapMeta.Map.FS, bitmapMeta.Map.MapHeader.indexOffset, rawSize);

            long offsetInShared;
            long offsetToWrite = bitmapMeta.Map.MapHeader.indexOffset;
            bitmapMeta.Map.BW.BaseStream.Position = offsetToWrite;
            byte[] rawData;

            // loop for each tag
            int tempRawSize;

            // loop for each chunk
            for (int j = 0; j < bitmapMeta.raw.rawChunks.Count; j++)
            {
                // loop for each LOD
                {
                    // for (int k = 0; k < bitmapMeta.raw.rawChunks.lod.Count; k++)
                    tempRawSize = bitmapMeta.raw.rawChunks[j].size; // .lods.get(k).rawSize;
                    offsetInShared = bitmapMeta.raw.rawChunks[j].offset;
                    rawData = new byte[tempRawSize];

                    // RandomAccessFileSP shared = sharedMaps.get(selectedTag.bitmChunks[j].rawLocation);

                    // reads the data into the array
                    sharedMap.BR.BaseStream.Position = offsetInShared;
                    sharedMap.BR.BaseStream.Read(rawData, 0, rawData.Length);

                    bitmapMeta.raw.rawChunks[j].offset = (int)bitmapMeta.Map.BW.BaseStream.Position;
                    bitmapMeta.raw.rawChunks[j].rawLocation = MapTypes.Internal;

                    bitmapMeta.Map.BW.Write(rawData);

                    // writes padding after chunk
                    int paddingSize = genPaddingSize(tempRawSize, 512);
                    bitmapMeta.Map.BW.Write(genPadding(paddingSize, 0));

                    offsetToWrite += tempRawSize + paddingSize;
                }
            }

            // fix pointers to point to internal bitmapMeta.Map
            for (int j = 0; j < bitmapMeta.raw.rawChunks.Count; j++)
            {
                {
                    // for (int k = 0; k < selectedTag.bitmChunks[j].lods.size(); k++)
                    bitmapMeta.Map.BW.BaseStream.Position = bitmapMeta.offset + rawSize +
                                                 bitmapMeta.raw.rawChunks[j].pointerMetaOffset; // +28; //+ (k * 4);
                    bitmapMeta.Map.BW.Write(bitmapMeta.raw.rawChunks[j].offset); // 37063680
                }
            }

            biUpdateMapInfo(bitmapMeta.Map, (int)rawSize);

            sharedMap.CloseMap();
            bitmapMeta.Map.CloseMap();
        }
Example #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HaloBitmapHeader"/> class.
 /// </summary>
 /// <param name="meta">The meta.</param>
 /// <remarks></remarks>
 public HaloBitmapHeader(ref Meta meta)
 {
     BinaryReader BR = new BinaryReader(meta.MS);
     BR.BaseStream.Position = 0;
     type = BR.ReadInt16();
     format = BR.ReadInt16();
     usage = BR.ReadInt16();
     usageflags = BR.ReadInt16();
     detailfadefactor = BR.ReadSingle();
     sharpenamount = BR.ReadSingle();
     bumpheight = BR.ReadSingle();
     spritebudgesize = BR.ReadInt16();
     spritebudgetcount = BR.ReadInt16();
     colorplatewidth = BR.ReadInt16();
     colorplateheight = BR.ReadInt16();
     compressedcolorplatedata = BR.ReadInt16();
 }
Example #28
0
            /// <summary>
            /// Initializes a new instance of the <see cref="BitmapInfo"/> class.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public BitmapInfo(int offset, ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = offset;
                tagtype = BR.ReadChars(4);
                width = BR.ReadUInt16();
                height = BR.ReadUInt16();
                depth = BR.ReadUInt16();
                type = BR.ReadUInt16();
                typename = (BitmapType)type;

                // case BitmapFormat.BITM_TYPE_LIGHTMAP:
                format = BR.ReadUInt16();
                formatname = (BitmapFormat)format;
                switch (formatname)
                {
                    case BitmapFormat.BITM_FORMAT_A8:
                    case BitmapFormat.BITM_FORMAT_P8:
                    case BitmapFormat.BITM_FORMAT_Y8:
                    case BitmapFormat.BITM_FORMAT_AY8:
                    case BitmapFormat.BITM_FORMAT_LIGHTMAP:
                        bitsPerPixel = 8;
                        break;
                    case BitmapFormat.BITM_FORMAT_A1R5G5B5:
                    case BitmapFormat.BITM_FORMAT_A4R4G4B4:
                    case BitmapFormat.BITM_FORMAT_A8Y8:
                    case BitmapFormat.BITM_FORMAT_R5G6B5:
                    case BitmapFormat.BITM_FORMAT_G8B8:
                  case BitmapFormat.BITM_FORMAT_UNKNOWN:
                        bitsPerPixel = 16;
                        break;
                    case BitmapFormat.BITM_FORMAT_X8R8G8B8:
                    case BitmapFormat.BITM_FORMAT_A8R8G8B8:
                    case BitmapFormat.BITM_FORMAT_DXT1:
                    case BitmapFormat.BITM_FORMAT_DXT2AND3:
                    case BitmapFormat.BITM_FORMAT_DXT4AND5:
                        bitsPerPixel = 32;
                        break;
                    default:
                        bitsPerPixel = 0;
                        break;
                }

                flags = BR.ReadUInt16();

                // if ((flags & 0x1000) == 0x1000) { swizzle = true; }
                if ((flags & 0x8) == 0x8)
                {
                    swizzle = true;
                }

                regPointX = BR.ReadUInt16();
                regPointY = BR.ReadUInt16();
                mipMapCount = BR.ReadUInt16();
                pixelOffset = BR.ReadUInt16();
            }
Example #29
0
        /// <summary>
        /// The scan map for lay out.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="addexternalchunks">The addexternalchunks.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public MapLayout ScanMapForLayOut(Map map, bool addexternalchunks)
        {
            MapLayout layout = new MapLayout();

            for (int x = 0; x < map.BSP.sbsp.Length; x++)
            {
                LayOutChunk l = new LayOutChunk(0);
                l.rawType = RawDataContainerType.BSPMeta;
                l.startoffset = map.BSP.sbsp[x].offset;
                l.endoffset = map.BSP.sbsp[x].offset + map.BSP.sbsp[x].size;
                l.size = map.BSP.sbsp[x].size;
                layout.chunks.Add(l);
            }

            LayOutChunk lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.Header;
            lo.startoffset = 0;
            lo.size = 2048;
            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.StringsIndex;
                lo.startoffset = map.MapHeader.offsetToStringIndex;
                lo.size = map.MapHeader.scriptReferenceCount * 4;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Strings1;
                lo.startoffset = map.MapHeader.offsetToStringNames1;
                lo.size = map.MapHeader.scriptReferenceCount * 128;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Strings2;
                lo.startoffset = map.MapHeader.offsetToStringNames2;
                lo.size = map.MapHeader.sizeOfScriptReference;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.Crazy;
                lo.startoffset = map.MapHeader.offsetToCrazy;
                lo.size = map.MapHeader.sizeOfCrazy;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);

                lo = new LayOutChunk(0);
                lo.rawType = RawDataContainerType.FileNamesIndex;
                lo.startoffset = map.MapHeader.offsetTofileIndex;
                lo.size = map.MapHeader.fileCount * 4;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);
            }

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.FileNames;
            lo.startoffset = map.MapHeader.offsetTofileNames;
            lo.size = map.MapHeader.fileNamesSize;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo.size += map.Functions.Padding(lo.size, 512);
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.MetaIndex;
            lo.startoffset = map.MapHeader.indexOffset;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo.size = map.MapHeader.metaStart;
                lo.size += map.Functions.Padding(lo.size, 512);

                // map.MapHeader.fileSize - map.MapHeader.indexOffset;
            }
            else
            {
                lo.size = map.MapHeader.offsetTofileNames - map.MapHeader.indexOffset;

                // map.MetaInfo.Offset[map.IndexHeader.metaCount - 1] + map.MetaInfo.Size[map.IndexHeader.metaCount-1];
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            lo = new LayOutChunk(0);
            lo.rawType = RawDataContainerType.MetaData;
            lo.startoffset = map.MetaInfo.Offset[0];

            // How can you adjust for padding past the end of the file???
            lo.size = map.MapHeader.fileSize - lo.startoffset;
            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                int padding = map.Functions.Padding(lo.startoffset + lo.size, 4096);
                lo.size += padding;
            }

            lo.endoffset = lo.startoffset + lo.size;
            layout.chunks.Add(lo);

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                for (int x = 0; x < map.Unicode.ut.Length; x++)
                {
                    lo = new LayOutChunk(0);
                    lo.rawType = RawDataContainerType.UnicodeNamesIndex;
                    lo.startoffset = map.Unicode.ut[x].indexOffset;
                    lo.size = map.Unicode.ut[x].count * 8;
                    lo.size += map.Functions.Padding(lo.size, 512);
                    lo.endoffset = lo.startoffset + lo.size;
                    layout.chunks.Add(lo);

                    lo = new LayOutChunk(0);
                    lo.rawType = RawDataContainerType.UnicodeNames;
                    lo.startoffset = map.Unicode.ut[x].tableOffset;
                    lo.size = map.Unicode.ut[x].tableSize;
                    lo.size += map.Functions.Padding(lo.size, 512);
                    lo.endoffset = lo.startoffset + lo.size;
                    layout.chunks.Add(lo);
                }
            }

            map.OpenMap(MapTypes.Internal);
            for (int x = 0; x < map.IndexHeader.metaCount; x++)
            {
                if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                    map.HaloVersion == HaloVersionEnum.Halo2Vista)
                {
                    if (map.MetaInfo.TagType[x] == "snd!" | map.MetaInfo.TagType[x] == "ltmp")
                    {
                        continue;
                    }

                    Application.DoEvents();
                }

                Meta m = new Meta(map);
                m.offset = map.MetaInfo.Offset[x];

                // checks if type has raw data
                m.rawType = map.Functions.ForMeta.CheckForRaw(map.MetaInfo.TagType[x]);

                if (m.rawType != RawDataContainerType.Empty)
                {
                    m.raw = map.Functions.ForMeta.ReadRaw(x, true);
                    LayOutChunk l = new LayOutChunk(map.MapHeader.fileSize);

                    int tempint = layout.FindByType(m.rawType);
                    if (tempint == -1)
                    {
                        l = new LayOutChunk(map.MapHeader.fileSize);
                        l.rawType = m.rawType;
                        layout.chunks.Add(l);
                        tempint = layout.FindByType(m.rawType);
                    }
                    else
                    {
                        l = (LayOutChunk)layout.chunks[tempint];
                    }

                    for (int y = 0; y < m.raw.rawChunks.Count; y++)
                    {
                        RawDataChunk r = m.raw.rawChunks[y];
                        if (r.offset == -1)
                        {
                            continue;
                        }

                        if (r.rawLocation == MapTypes.Internal)
                        {
                            RawInfoChunk tempr = new RawInfoChunk();
                            tempr.offset = (uint)r.offset;
                            tempr.size = r.size;
                            tempr.rawType = r.rawDataType;
                            tempr.location = r.rawLocation;
                            tempr.offsetOfPointer = m.offset + r.pointerMetaOffset;
                            l.rawPieces.Add(tempr);
                        }
                        else if (addexternalchunks)
                        {
                            RawInfoChunk tempr = new RawInfoChunk();
                            tempr.offset = (uint)r.offset;
                            tempr.size = r.size;
                            tempr.rawType = r.rawDataType;
                            tempr.location = r.rawLocation;
                            tempr.offsetOfPointer = m.offset + r.pointerMetaOffset;
                            l.rawPieces.Add(tempr);
                        }

                        if (r.offset < l.startoffset && r.rawLocation == MapTypes.Internal)
                        {
                            l.startoffset = r.offset;
                            l.size = l.endoffset - l.startoffset;
                            layout.chunks[tempint] = l;
                        }

                        if (r.offset + r.size > l.endoffset && r.rawLocation == MapTypes.Internal)
                        {
                            l.endoffset = r.offset + r.size;
                            l.endoffset += map.Functions.Padding(l.endoffset, 512);
                            l.size = l.endoffset - l.startoffset;
                            layout.chunks[tempint] = l;
                        }
                    }
                }

                m = null;
                GC.WaitForPendingFinalizers();

                // GC.Collect();
            }

            map.CloseMap();

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                lo = new LayOutChunk(0);
                LayOutChunk templo = (LayOutChunk)layout.chunks[layout.FindByType(RawDataContainerType.Model)];
                lo.rawType = RawDataContainerType.Sound;
                lo.startoffset = 2048;
                lo.size = templo.startoffset - 2048;
                lo.size += map.Functions.Padding(lo.size, 512);
                lo.endoffset = lo.startoffset + lo.size;
                layout.chunks.Add(lo);
            }

            for (int y = 0; y < layout.chunks.Count; y++)
            {
                LayOutChunk l = (LayOutChunk)layout.chunks[y];
                if (l.size == 0)
                {
                    layout.chunks.RemoveAt(y);
                    y--;
                }
            }

            layout.SortChunksByOffset();
            layout.SortRawByOffset();

            return layout;
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="coll"/> class.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public coll(ref Meta meta)
        {
            BinaryReader BR = new BinaryReader(meta.MS);
            BR.BaseStream.Position = 28;
            int tempc = BR.ReadInt32();
            int tempr = BR.ReadInt32() - meta.magic - meta.offset;
            for (int xxx = 0; xxx < tempc; xxx++)
            {
                BR.BaseStream.Position = tempr + (xxx * 12);
                string index1string = meta.Map.Strings.Name[BR.ReadUInt16()];
                BR.BaseStream.Position = tempr + (xxx * 12) + 4;
                int tempcxx = BR.ReadInt32();
                int temprxx = BR.ReadInt32() - meta.magic - meta.offset;
                for (int xx = 0; xx < tempcxx; xx++)
                {
                    BR.BaseStream.Position = temprxx + (xx * 20);
                    string index2string = meta.Map.Strings.Name[BR.ReadUInt16()];
                    BR.BaseStream.Position = temprxx + (xx * 20) + 4;
                    int tempcx = BR.ReadInt32();
                    int temprx = BR.ReadInt32() - meta.magic - meta.offset;

                    // Meshes = new CollisionMesh[tempc];
                    for (int x = 0; x < tempcx; x++)
                    {
                        CollisionMesh cm = new CollisionMesh();
                        cm.index1 = xxx;
                        cm.index1string = index1string;
                        cm.index2 = xx;
                        cm.index2string = index2string;
                        if (ConditionStrings.IndexOf(cm.index2string) == -1)
                        {
                            ConditionStrings.Add(cm.index2string);
                        }

                        cm.index3 = x;

                        BR.BaseStream.Position = temprx + (x * 68) + 52;
                        int tempc2 = BR.ReadInt32();
                        int tempr2 = BR.ReadInt32() - meta.magic - meta.offset;

                        cm.Faces = new ushort[tempc2 * 3];
                        for (int y = 0; y < tempc2; y++)
                        {
                            BR.BaseStream.Position = tempr2 + (y * 12);
                            cm.Faces[y * 3] = BR.ReadUInt16();
                            cm.Faces[(y * 3) + 1] = BR.ReadUInt16();
                            cm.Faces[(y * 3) + 2] = cm.Faces[(y * 3) + 1]; // BR.ReadUInt16();
                        }

                        // ***** Test Code ****//
                        BR.BaseStream.Position = temprx + (x * 68) + 12;
                        tempc2 = BR.ReadInt32();
                        tempr2 = BR.ReadInt32() - meta.magic - meta.offset;
                        cm.Normals = new Vector4[tempc2];
                        for (int y = 0; y < tempc2; y++)
                        {
                            BR.BaseStream.Position = tempr2 + (y * 16) + 0;
                            cm.Normals[y].X = BR.ReadSingle();
                            cm.Normals[y].Y = BR.ReadSingle();
                            cm.Normals[y].Z = BR.ReadSingle();
                            cm.Normals[y].W = BR.ReadSingle();
                        }

                        BR.BaseStream.Position = temprx + (x * 68) + 44;
                        tempc2 = BR.ReadInt32();
                        tempr2 = BR.ReadInt32() - meta.magic - meta.offset;
                        cm.SurfaceData = new surfaceData[tempc2];
                        for (int y = 0; y < tempc2; y++)
                        {
                            BR.BaseStream.Position = tempr2 + (y * 8) + 0;
                            cm.SurfaceData[y] = new surfaceData();
                            cm.SurfaceData[y].Plane = BR.ReadInt16();
                        }

                        BR.BaseStream.Position = temprx + (x * 68) + 52;
                        tempc2 = BR.ReadInt32();
                        tempr2 = BR.ReadInt32() - meta.magic - meta.offset;

                        int[] startEdges = new int[tempc2];
                        int[] endEdges = new int[tempc2];
                        int[] forwardEdges = new int[tempc2];
                        int[] reverseEdges = new int[tempc2];
                        int[] face1 = new int[tempc2];
                        int[] face2 = new int[tempc2];
                        for (int y = 0; y < tempc2; y++)
                        {
                            BR.BaseStream.Position = tempr2 + (y * 12) + 0;
                            startEdges[y] = BR.ReadUInt16();
                            endEdges[y] = BR.ReadUInt16();

                            BR.BaseStream.Position = tempr2 + (y * 12) + 4;
                            forwardEdges[y] = BR.ReadUInt16();
                            reverseEdges[y] = BR.ReadUInt16();

                            BR.BaseStream.Position = tempr2 + (y * 12) + 8;
                            face1[y] = BR.ReadUInt16();
                            face2[y] = BR.ReadUInt16();
                        }

                        for (int y = 0; y < forwardEdges.Length; y++)
                        {
                            int cSurface = face1[y];
                            if (cm.SurfaceData[cSurface].Vertices == null)
                            {
                                cm.SurfaceData[cSurface].Vertices = new List<int>();
                                int edge = y;
                                int nextEdge = 0;
                                cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]);
                                do
                                {
                                    if (cSurface == face1[edge])
                                    {
                                        cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]);
                                        edge = forwardEdges[edge];
                                    }
                                    else if (cSurface == face2[edge])
                                    {
                                        cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]);
                                        edge = reverseEdges[edge];
                                    }

                                    if (cSurface == face1[edge])
                                    {
                                        nextEdge = endEdges[edge];
                                    }
                                    else if (cSurface == face2[edge])
                                    {
                                        nextEdge = startEdges[edge];
                                    }
                                }
                                while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge));
                            }
                        }

                        for (int y = 0; y < reverseEdges.Length; y++)
                        {
                            int cSurface = face2[y];
                            if (cm.SurfaceData[cSurface].Vertices == null)
                            {
                                cm.SurfaceData[cSurface].Vertices = new List<int>();
                                int edge = y;
                                int nextEdge = 0;
                                cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]);
                                do
                                {
                                    if (cSurface == face1[edge])
                                    {
                                        cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]);
                                        edge = forwardEdges[edge];
                                    }
                                    else if (cSurface == face2[edge])
                                    {
                                        cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]);
                                        edge = reverseEdges[edge];
                                    }

                                    if (cSurface == face1[edge])
                                    {
                                        nextEdge = endEdges[edge];
                                    }
                                    else if (cSurface == face2[edge])
                                    {
                                        nextEdge = startEdges[edge];
                                    }
                                }
                                while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge));
                            }
                        }

                        // ***** End Test Code ****//
                        BR.BaseStream.Position = temprx + (x * 68) + 60;
                        tempc2 = BR.ReadInt32();
                        tempr2 = BR.ReadInt32() - meta.magic - meta.offset;

                        // Meshes[x] = new CollisionMesh();
                        cm.Vertices = new Vector3[tempc2];
                        for (int y = 0; y < tempc2; y++)
                        {
                            BR.BaseStream.Position = tempr2 + (y * 16);
                            cm.Vertices[y].X = BR.ReadSingle();
                            cm.Vertices[y].Y = BR.ReadSingle();
                            cm.Vertices[y].Z = BR.ReadSingle();
                        }

                        Meshes.Add(cm);
                    }
                }
            }

            BR.BaseStream.Position = 36;
            tempc = BR.ReadInt32();
            tempr = BR.ReadInt32() - meta.magic - meta.offset;
            for (int xxx = 0; xxx < tempc; xxx++)
            {
                BR.BaseStream.Position = tempr + (20 * xxx);
                PathfindingSphere ps = new PathfindingSphere();
                ps.nodeindex = BR.ReadInt32();
                ps.position = new Vector3();
                ps.position.X = BR.ReadSingle();
                ps.position.Y = BR.ReadSingle();
                ps.position.Z = BR.ReadSingle();
                ps.radius = BR.ReadSingle();
                Spheres.Add(ps);
            }
        }
Example #31
0
 public Skin(Map map, Meta meta)
 {
     this.map = map;
     this.meta = meta;
     loadFontNames();
 }