Inheritance: BaseField
Ejemplo n.º 1
0
        private void LoadENTControls(object[] entArray)
        {
            this.selectedTagType = Maps.map[mapIndex].SelectedMeta.type;

            this.toolStripTagType.Text = "[" + this.selectedTagType.ToString() + "]";
            this.toolStripTagName.Text = Maps.map[mapIndex].SelectedMeta.name;
            //this.Padding = new Padding(10);
            int colorSpaceCount = 4;

            // Custom Plugins access
            ra = new RegistryAccess(Microsoft.Win32.Registry.CurrentUser, RegistryAccess.RegPaths.Halo2CustomPlugins + pluginName + "\\" + this.selectedTagType);
            if (pluginName == null)
                ra.CloseReg();

            foreach (object o in entArray)
            {
                IFPIO.BaseObject tempbase = (IFPIO.BaseObject)o;
                if (tempbase.visible == false)
                    if (Meta_Editor.MetaEditor.ShowInvisibles == false)
                        continue;

                // skip hidden custom plugins variables (mark reflexives to be removed if empty)
                bool skipEmptyReflex = false;
                if (ra.isOpen && ra.getValue(tempbase.offset.ToString()) == bool.FalseString)
                    if (tempbase.ObjectType == IFPIO.ObjectEnum.Struct)
                        skipEmptyReflex = true;
                    else
                        continue;

                switch (tempbase.ObjectType)
                {
                    case IFPIO.ObjectEnum.Struct:
                        {
                            if (Meta_Editor.MetaEditor.ShowReflexives == false)
                                break;
                            // tempLabel is a blank space located above reflexives
                            Label tempLabel = new Label();
                            tempLabel.AutoSize = true;
                            tempLabel.Location = new System.Drawing.Point(0, 0);
                            tempLabel.Name = "label1";
                            tempLabel.Dock = DockStyle.Top;
                            tempLabel.Size = new System.Drawing.Size(35, 13);
                            tempLabel.TabIndex = tabIndex;

                            // tempReflexive is the reflexive and all data (incl other reflexives) within it
                            ReflexiveControl tempReflexive = new ReflexiveControl(mapIndex, Maps.map[mapIndex].SelectedMeta.offset, ((IFPIO.Reflexive)tempbase).HasCount, tempbase.lineNumber, this);
                            //tempReflexive.Location = new System.Drawing.Point(10, 0);
                            tempReflexive.Name = "reflexive";
                            tempReflexive.TabIndex = tabIndex;
                            tempReflexive.LoadENTControls( (IFPIO.Reflexive)tempbase, ((IFPIO.Reflexive)tempbase).items,
                                                           true, 0, ref tabIndex, tempbase.offset.ToString());

                            // Label, Combobox & Button are always added ( = 3)
                            if (!(tempReflexive.Controls.Count <= 2 && skipEmptyReflex))
                            {
                                this.Controls[0].Controls.Add(tempLabel);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                this.Controls[0].Controls.Add(tempReflexive);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            }
                            break;
                        }
                    case IFPIO.ObjectEnum.Ident:
                        {
                            if (Meta_Editor.MetaEditor.ShowIdents == false)
                                break;
                            Ident tempident = new Ident(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.Ident)tempbase).hasTagType, tempbase.lineNumber);
                            tempident.Name = "ident";
                            tempident.TabIndex = tabIndex;
                            tempident.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            tempident.Tag = "[" + tempident.Controls[2].Text + "] "
                                            + tempident.Controls[1].Text;
                            tempident.Controls[1].ContextMenuStrip = identContext;
                            this.Controls[0].Controls.Add(tempident);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.StringID:
                        {
                            if (Meta_Editor.MetaEditor.ShowSIDs == false)
                                break;
                            SID tempSID = new SID(tempbase.name, mapIndex, tempbase.offset, tempbase.lineNumber);
                            tempSID.Name = "sid";
                            tempSID.TabIndex = tabIndex;
                            tempSID.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempSID);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Float:
                        {
                            if (Meta_Editor.MetaEditor.ShowFloats == false)
                                break;
                            DataValues tempFloat = new DataValues(tempbase.name, mapIndex, tempbase.offset, IFPIO.ObjectEnum.Float, tempbase.lineNumber);
                            tempFloat.TabIndex = tabIndex;
                            tempFloat.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempFloat);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.String32:
                        {
                            if (Meta_Editor.MetaEditor.ShowString32s == false && tempbase.ObjectType == IFPIO.ObjectEnum.String32)
                                break;
                            EntStrings tempstring = new EntStrings(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.IFPString)tempbase).size, ((IFPIO.IFPString)tempbase).type, tempbase.lineNumber);
                            tempstring.Name = "string";
                            tempstring.TabIndex = tabIndex;
                            tempstring.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempstring);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.UnicodeString256:
                        {
                            if (Meta_Editor.MetaEditor.ShowUnicodeString256s == false)
                                break;
                            goto case IFPIO.ObjectEnum.String32;
                        }
                    case IFPIO.ObjectEnum.String256:
                        {
                            if (Meta_Editor.MetaEditor.ShowString256s == false)
                                break;
                            goto case IFPIO.ObjectEnum.String32;
                        }
                    case IFPIO.ObjectEnum.UnicodeString64:
                        {
                            if (Meta_Editor.MetaEditor.ShowUnicodeString64s == false)
                                break;
                            goto case IFPIO.ObjectEnum.String32;
                        }
                    case IFPIO.ObjectEnum.String:
                        {
                            if (Meta_Editor.MetaEditor.ShowString32s == false && tempbase.ObjectType == IFPIO.ObjectEnum.String32)
                                break;
                            EntStrings tempstring = new EntStrings(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.IFPString)tempbase).size, ((IFPIO.IFPString)tempbase).type, tempbase.lineNumber);
                            tempstring.Name = "string";
                            tempstring.TabIndex = tabIndex;
                            tempstring.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempstring);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Int:
                        {
                            if (((IFPIO.IFPInt)tempbase).entIndex.nulled == true)
                            {
                                if ((Meta_Editor.MetaEditor.ShowInts == false && tempbase.ObjectType == IFPIO.ObjectEnum.Int)
                                    || (Meta_Editor.MetaEditor.ShowShorts == false && tempbase.ObjectType == IFPIO.ObjectEnum.Short)
                                    || (Meta_Editor.MetaEditor.ShowUshorts == false && tempbase.ObjectType == IFPIO.ObjectEnum.UShort)
                                    || (Meta_Editor.MetaEditor.ShowUints == false && tempbase.ObjectType == IFPIO.ObjectEnum.UInt))
                                    break;
                                DataValues tempdatavalues = new DataValues(tempbase.name, mapIndex, tempbase.offset, tempbase.ObjectType, tempbase.lineNumber);
                                tempdatavalues.TabIndex = tabIndex;
                                tempdatavalues.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempdatavalues);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            }
                            else
                            {
                                if ((Meta_Editor.MetaEditor.ShowBlockIndex32s == false && (tempbase.ObjectType == IFPIO.ObjectEnum.Int | tempbase.ObjectType == IFPIO.ObjectEnum.UInt))
                                    || (Meta_Editor.MetaEditor.ShowBlockIndex16s == false && (tempbase.ObjectType == IFPIO.ObjectEnum.Short | tempbase.ObjectType == IFPIO.ObjectEnum.UShort))
                                    || (Meta_Editor.MetaEditor.ShowBlockIndex8s == false && tempbase.ObjectType == IFPIO.ObjectEnum.Byte))
                                    break;
                                Indices tempdatavalues = new Indices(tempbase.name, mapIndex, tempbase.offset, tempbase.ObjectType, ((IFPIO.IFPInt)tempbase).entIndex);
                                tempdatavalues.TabIndex = tabIndex;
                                this.Controls[0].Controls.Add(tempdatavalues);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            }
                            break;
                        }
                    case IFPIO.ObjectEnum.Short:
                        {
                            goto case IFPIO.ObjectEnum.Int;
                        }
                    case IFPIO.ObjectEnum.UShort:
                        {
                            goto case IFPIO.ObjectEnum.Int;
                        }
                    case IFPIO.ObjectEnum.UInt:
                        {
                            goto case IFPIO.ObjectEnum.Int;
                        }
                    case IFPIO.ObjectEnum.Unknown:
                        {
                            if (Meta_Editor.MetaEditor.ShowUndefineds == false)
                                break;
                            DataValues tempUnknown = new DataValues(tempbase.name, mapIndex, tempbase.offset, IFPIO.ObjectEnum.Unknown, tempbase.lineNumber);
                            tempUnknown.TabIndex = tabIndex;
                            tempUnknown.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempUnknown);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Byte_Flags:
                        {
                            if (Meta_Editor.MetaEditor.ShowBitmask8s == false)
                                break;
                            Bitmask tempbitmask = new Bitmask(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.Bitmask)tempbase).bitmaskSize, ((IFPIO.Bitmask)tempbase).options, tempbase.lineNumber);
                            tempbitmask.TabIndex = tabIndex;
                            tempbitmask.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempbitmask);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Word_Flags:
                        {
                            if (Meta_Editor.MetaEditor.ShowBitmask16s == false)
                                break;
                            Bitmask tempbitmask = new Bitmask(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.Bitmask)tempbase).bitmaskSize, ((IFPIO.Bitmask)tempbase).options, tempbase.lineNumber);
                            tempbitmask.TabIndex = tabIndex;
                            tempbitmask.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempbitmask);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Long_Flags:
                        {
                            if (Meta_Editor.MetaEditor.ShowBitmask32s == false)
                                break;
                            Bitmask tempbitmask = new Bitmask(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.Bitmask)tempbase).bitmaskSize, ((IFPIO.Bitmask)tempbase).options, tempbase.lineNumber);
                            tempbitmask.TabIndex = tabIndex;
                            tempbitmask.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempbitmask);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Char_Enum:
                        {
                            if (Meta_Editor.MetaEditor.ShowEnum8s == false)
                                break;
                            Enums tempenum = new Enums(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.IFPEnum)tempbase).enumSize, ((IFPIO.IFPEnum)tempbase).options, tempbase.lineNumber);
                            tempenum.TabIndex = tabIndex;
                            tempenum.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempenum);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Enum:
                        {
                            if (Meta_Editor.MetaEditor.ShowEnum16s == false)
                                break;
                            Enums tempenum = new Enums(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.IFPEnum)tempbase).enumSize, ((IFPIO.IFPEnum)tempbase).options, tempbase.lineNumber);
                            tempenum.TabIndex = tabIndex;
                            tempenum.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempenum);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Long_Enum:
                        {
                            if (Meta_Editor.MetaEditor.ShowEnum32s == false)
                                break;
                            Enums tempenum = new Enums(tempbase.name, mapIndex, tempbase.offset, ((IFPIO.IFPEnum)tempbase).enumSize, ((IFPIO.IFPEnum)tempbase).options, tempbase.lineNumber);
                            tempenum.TabIndex = tabIndex;
                            tempenum.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempenum);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.Byte:
                        {
                            if (((IFPIO.IFPByte)tempbase).entIndex.nulled == true)
                            {
                                if (Meta_Editor.MetaEditor.ShowBytes == false)
                                    break;
                                DataValues tempByte = new DataValues(tempbase.name, mapIndex, tempbase.offset, IFPIO.ObjectEnum.Byte, tempbase.lineNumber);
                                tempByte.TabIndex = tabIndex;
                                this.Controls[0].Controls.Add(tempByte);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            }
                            else
                            {
                                if (Meta_Editor.MetaEditor.ShowBlockIndex8s == false)
                                    break;
                                Indices tempdatavalues = new Indices(tempbase.name, mapIndex, tempbase.offset, tempbase.ObjectType, ((IFPIO.IFPByte)tempbase).entIndex);
                                tempdatavalues.TabIndex = tabIndex;
                                this.Controls[0].Controls.Add(tempdatavalues);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            }
                            break;
                        }
                    case IFPIO.ObjectEnum.Unused:
                        {
                            DataValues tempUnknown = new DataValues(tempbase.name, mapIndex, tempbase.offset, IFPIO.ObjectEnum.Unused, tempbase.lineNumber);
                            tempUnknown.TabIndex = tabIndex;
                            tempUnknown.Populate(Maps.map[mapIndex].SelectedMeta.offset);
                            this.Controls[0].Controls.Add(tempUnknown);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                            break;
                        }
                    case IFPIO.ObjectEnum.TagType:
                        continue;
                        break;
                }

                if (!(tempbase is IFPIO.Reflexive))
                    ToolTip1.SetToolTip(this.Controls[0].Controls[0].Controls[0], "offset: " + tempbase.offset.ToString());

                if (this.Controls[0].Controls.Count > 0 && this.Controls[0].Controls[0] is DataValues)
                {
                    //if (((tempbase.name.ToLower().Contains(" a") & tempbase.name[tempbase.name.ToLower().IndexOf(" a")]) ||
                    //     tempbase.name.ToLower().Contains("alpha"))& alphaControl == null)
                    if (ColorWheel.checkForColor(tempbase.name, alphaControl, " a", "alpha"))
                    {
                        alphaControl = (DataValues)this.Controls[0].Controls[0];
                        colorSpaceCount = 0;
                    }
                    //if (tempbase.name.ToLower().Contains(" r") & redControl == null)
                    else if (ColorWheel.checkForColor(tempbase.name, redControl, " r", "red"))
                    {
                        redControl = (DataValues)this.Controls[0].Controls[0];
                        colorSpaceCount = 0;
                    }
                    //if (tempbase.name.ToLower().Contains(" g") & greenControl == null)
                    else if (ColorWheel.checkForColor(tempbase.name, greenControl, " g", "green"))
                    {
                        greenControl = (DataValues)this.Controls[0].Controls[0];
                        colorSpaceCount = 0;
                    }
                    //if (tempbase.name.ToLower().Contains(" b") & blueControl == null)
                    else if (ColorWheel.checkForColor(tempbase.name, blueControl, " b", "blue"))
                    {
                        blueControl = (DataValues)this.Controls[0].Controls[0];
                        colorSpaceCount = 0;
                    }
                    else
                    {
                        colorSpaceCount++;
                        if (colorSpaceCount == 1)
                        {
                            alphaControl = null;
                            redControl = null;
                            greenControl = null;
                            blueControl = null;
                        }
                    }
                    if (redControl != null & greenControl != null & blueControl != null)
                    {
                        // Create the new ColorWheel class, indicating
                        // the locations of the color wheel itself, the
                        // brightness area, and the position of the selected color.
                        ColorWheel cw = new ColorWheel();

                        if (alphaControl != null)
                            cw.setTextBox(alphaControl.textBox1, Color.White);
                        cw.setTextBox(redControl.textBox1, Color.Red);
                        cw.setTextBox(greenControl.textBox1, Color.Green);
                        cw.setTextBox(blueControl.textBox1, Color.Blue);

                        //p.I.AddRange(new Rectangle[] { SelectedColorRectangle });
                        cw.Dock = DockStyle.Top;
                        this.Controls[0].Controls.Add(cw);
                        this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                        // Reset for next batch
                        colorSpaceCount++;
                        alphaControl = null;
                        redControl = null;
                        greenControl = null;
                        blueControl = null;
                    }
                }
                else colorSpaceCount++;
                tabIndex++;
            }
            ra.CloseReg();
        }
Ejemplo n.º 2
0
        private void loadControls(TreeNode Location)
        {
            toolTip1.AutoPopDelay = 10000;
            reflexiveData rd = (reflexiveData)Location.Tag;

            if (rd.chunkCount > 100000) // Some very large number
                throw new Exception("\"" + rd.node.Text + "\" appears to contain " + rd.chunkCount + "chunks!\n"
                    + "Try reloading tag. If problem persists, you likely have a corrupt map!");

            int chNum = rd.chunkSelected;
            bool enabled = rd.chunkCount != 0;
            int metaOffset = rd.baseOffset;

            // Make our panel non-visibile while we create our controls
            Panel panel = this.panelMetaEditor;
            panel.Visible = false;

            // Dispose of each control and also add a safety  in case we somehow go into an endless loop (max 1000)
            int safetyCount = 1000;
            while (panel.Controls.Count > 0 && safetyCount > 0)
            {
                panel.Controls[0].Dispose();
                safetyCount--;
            }
            // Should be empty, but clear anyways.
            panel.Controls.Clear();

            Object[] o;
            if (rd.reflexive == null)
                o = ifp.items;
            else
                o = rd.reflexive.items;

            bool labelFound = false;
            int tabIndex = 0;
            // These are used to detect color fields and replace with a ColorWheel control
            // Stores the control for an Alpha Color value
            DataValues alphaControl = null;
            // Stores the control for a blue Color value
            DataValues blueControl = null;
            // Stores the control for a green Color value
            DataValues greenControl = null;
            // Stores the control for a red Color value
            DataValues redControl = null;
            // Keeps track of how many controls are between fields; Colors need to be adjacent
            int colorSpaceCount = 4;

            foreach (IFPIO.BaseObject ctl in o)
            {
                tabIndex++;
                try
                {
                    switch (ctl.ObjectType)
                    {
                        case IFPIO.ObjectEnum.Struct:
                            {
            #if DEBUG
                                if (((IFPIO.Reflexive)ctl).chunkSize == 1)
                                {
                                    System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
                                    BR.BaseStream.Position = ctl.offset + metaOffset;
                                    int chunkCount = BR.ReadInt32();
                                    if (chunkCount == 0)
                                        continue;
                                    int chunkOffset = BR.ReadInt32() - meta.magic;
                                    int tagIndex = map.Functions.ForMeta.FindMetaByOffset(chunkOffset);

                                    StringBox sb = new StringBox(meta, ctl.name + " (reflexive)", map, ctl.offset, ctl.lineNumber, 0);

                                    if (enabled) sb.Populate(metaOffset, tagIndex == meta.TagIndex);
                                    if (sb.size > 0)
                                    {
                                        panelMetaEditor.Controls.Add(sb);
                                        sb.BringToFront();
                                    }
                                    //panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                }
            #endif
                                /*
                            if (Meta_Editor.MetaEditor.ShowReflexives == false)
                                break;
                            // tempLabel is a blank space located above reflexives
                            Label tempLabel = new Label();
                            tempLabel.AutoSize = true;
                            tempLabel.Location = new System.Drawing.Point(0, 0);
                            tempLabel.Name = "label1";
                            tempLabel.Dock = DockStyle.Top;
                            tempLabel.Size = new System.Drawing.Size(35, 13);
                            tempLabel.TabIndex = tabIndex;

                            // tempReflexive is the reflexive and all data (incl other reflexives) within it
                            ReflexiveControl tempReflexive = new ReflexiveControl(mapnumber, meta.offset, ((IFPIO.Reflexive)ctl).HasCount, ctl.lineNumber, this);
                            //tempReflexive.Location = new System.Drawing.Point(10, 0);
                            tempReflexive.Name = "reflexive";
                            tempReflexive.TabIndex = tabIndex;
                            tempReflexive.LoadENTControls((IFPIO.Reflexive)ctl, ((IFPIO.Reflexive)ctl).items,
                                                           true, 0, ref tabIndex, ctl.offset.ToString());

                            // Label, Combobox & Button are always added ( = 3)
                            if (!(tempReflexive.Controls.Count <= 2 && skipEmptyReflex))
                            {
                                panelMetaEditor.Controls.Add(tempLabel);
                                panelMetaEditor.Controls[panelMetaEditor.Controls.Count - 1].BringToFront();
                                panelMetaEditor.Controls.Add(tempReflexive);
                                panelMetaEditor.Controls[panelMetaEditor.Controls.Count - 1].BringToFront();
                            }
                            break;
                            */
                                continue;
                            }
                        case IFPIO.ObjectEnum.Block:
                            {
                                Ident tempident = new Ident(meta, ctl.name, map, ctl.offset + 4, true, ctl.lineNumber);
                                tempident.Name = "ident";
                                tempident.TabIndex = tabIndex;
                                if (enabled) tempident.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempident.Tag = "[" + tempident.Controls[2].Text + "] "
                                                + tempident.Controls[1].Text;
                                //tempident.Controls[1].ContextMenuStrip = identContext;
                                panelMetaEditor.Controls.Add(tempident);
                                tempident.BringToFront();
                                panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                tempident.ContextMenuStrip = cmIdent;
                                break;
                            }
                        case IFPIO.ObjectEnum.TagType:
                            continue;
                        case IFPIO.ObjectEnum.Ident:
                            {
                                if (MetaEditor.MetaEditor.ShowIdents == false)
                                    break;
                                Ident tempident = new Ident(meta, ctl.name, map, ctl.offset, ((IFPIO.Ident)ctl).hasTagType, ctl.lineNumber);
                                tempident.Name = "ident";
                                tempident.TabIndex = tabIndex;
                                if (enabled) tempident.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempident.Tag = "[" + tempident.Controls[2].Text + "] "
                                                + tempident.Controls[1].Text;
                                panelMetaEditor.Controls.Add(tempident);
                                tempident.BringToFront();
                                panelMetaEditor.Controls[0].Controls[1].MouseEnter += new EventHandler(cbIdent_MouseEnter);
                                panelMetaEditor.Controls[0].Controls[1].MouseLeave += new EventHandler(cbIdent_MouseLeave);
                                panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                tempident.ContextMenuStrip = cmIdent;
                                // Hide the Mass Field Editor for Idents in the parent node
                                if (treeViewTagReflexives.SelectedNode.Parent == null)
                                    tsIdentOpenMassFieldEdit.Enabled = false;
                                else
                                    tsIdentOpenMassFieldEdit.Enabled = true;
                                break;
                            }
                        case IFPIO.ObjectEnum.StringID:
                            {
                                if (MetaEditor.MetaEditor.ShowSIDs == false)
                                    break;
                                SID tempSID = new SID(meta, ctl.name, map, ctl.offset, ctl.lineNumber);
                                tempSID.Name = "sid";
                                tempSID.TabIndex = tabIndex;
                                if (enabled) tempSID.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempSID);
                                tempSID.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Float:
                            {
                                if (MetaEditor.MetaEditor.ShowFloats == false)
                                    break;
                                DataValues tempFloat = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Float, ctl.lineNumber);
                                tempFloat.TabIndex = tabIndex;
                                if (enabled) tempFloat.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempFloat);
                                tempFloat.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.String32:
                            {
                                if (MetaEditor.MetaEditor.ShowString32s == false && ctl.ObjectType == IFPIO.ObjectEnum.String32)
                                    break;
                                EntStrings tempstring = new EntStrings(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPString)ctl).size, ((IFPIO.IFPString)ctl).type, ctl.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                panelMetaEditor.Controls.Add(tempstring);
                                if (enabled) tempstring.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempstring.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.UnicodeString256:
                            {
                                if (MetaEditor.MetaEditor.ShowUnicodeString256s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.String256:
                            {
                                if (MetaEditor.MetaEditor.ShowString256s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.UnicodeString64:
                            {
                                if (MetaEditor.MetaEditor.ShowUnicodeString64s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.String:
                            {
                                if (MetaEditor.MetaEditor.ShowString32s == false && ctl.ObjectType == IFPIO.ObjectEnum.String32)
                                    break;
                                EntStrings tempstring = new EntStrings(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPString)ctl).size, ((IFPIO.IFPString)ctl).type, ctl.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                if (enabled) tempstring.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempstring);
                                tempstring.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Byte:
                            {
                                if (((IFPIO.IFPByte)ctl).entIndex.nulled == true)
                                {
                                    if (MetaEditor.MetaEditor.ShowBytes == false)
                                        break;
                                    DataValues tempByte = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Byte, ctl.lineNumber);
                                    tempByte.TabIndex = tabIndex;
                                    if (enabled) tempByte.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                    panelMetaEditor.Controls.Add(tempByte);
                                    tempByte.BringToFront();
                                }
                                else
                                {
                                    if (MetaEditor.MetaEditor.ShowBlockIndex8s == false)
                                        break;
                                    Indices tempDataValues = new Indices(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ((IFPIO.IFPByte)ctl).entIndex);
                                    tempDataValues.TabIndex = tabIndex;
                                    panelMetaEditor.Controls.Add(tempDataValues);
                                    tempDataValues.BringToFront();
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Int:
                            {
                                if (((IFPIO.IFPInt)ctl).entIndex.nulled == true)
                                {
                                    if ((MetaEditor.MetaEditor.ShowInts == false && ctl.ObjectType == IFPIO.ObjectEnum.Int)
                                        || (MetaEditor.MetaEditor.ShowShorts == false && ctl.ObjectType == IFPIO.ObjectEnum.Short)
                                        || (MetaEditor.MetaEditor.ShowUshorts == false && ctl.ObjectType == IFPIO.ObjectEnum.UShort)
                                        || (MetaEditor.MetaEditor.ShowUints == false && ctl.ObjectType == IFPIO.ObjectEnum.UInt))
                                        break;
                                    DataValues tempdatavalues = new DataValues(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ctl.lineNumber);
                                    tempdatavalues.TabIndex = tabIndex;
                                    if (enabled) tempdatavalues.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                    panelMetaEditor.Controls.Add(tempdatavalues);
                                    tempdatavalues.BringToFront();
                                }
                                else
                                {
                                    if ((MetaEditor.MetaEditor.ShowBlockIndex32s == false && (ctl.ObjectType == IFPIO.ObjectEnum.Int | ctl.ObjectType == IFPIO.ObjectEnum.UInt))
                                        || (MetaEditor.MetaEditor.ShowBlockIndex16s == false && (ctl.ObjectType == IFPIO.ObjectEnum.Short | ctl.ObjectType == IFPIO.ObjectEnum.UShort))
                                        || (MetaEditor.MetaEditor.ShowBlockIndex8s == false && ctl.ObjectType == IFPIO.ObjectEnum.Byte))
                                        break;
                                    Indices tempdatavalues = new Indices(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ((IFPIO.IFPInt)ctl).entIndex);
                                    tempdatavalues.TabIndex = tabIndex;
                                    if (enabled) tempdatavalues.Populate(metaOffset, rd.parent.baseOffset);
                                    panelMetaEditor.Controls.Add(tempdatavalues);
                                    tempdatavalues.BringToFront();
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Short:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.UShort:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.UInt:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.Unknown:
                            {
                                if (MetaEditor.MetaEditor.ShowUndefineds == false)
                                    break;
                                DataValues tempUnknown = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Unknown, ctl.lineNumber);
                                tempUnknown.TabIndex = tabIndex;
                                if (enabled) tempUnknown.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempUnknown);
                                tempUnknown.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Byte_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask8s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();
                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    // Control mouse in/out for extra description popup box
                                    cntl.MouseEnter += new EventHandler(cntl_MouseEnter);
                                    cntl.MouseLeave += new EventHandler(cntl_MouseLeave);

                                    int optionNum = int.Parse(cntl.Tag.ToString());
                                    if (optionNum < tempbitmask.Options.Length && tempbitmask.Options[optionNum].description != null)
                                        cntl.ForeColor = Color.DarkGoldenrod;

                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << optionNum).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Word_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask16s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();
                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    // Control mouse in/out for extra description popup box
                                    cntl.MouseEnter += new EventHandler(cntl_MouseEnter);
                                    cntl.MouseLeave += new EventHandler(cntl_MouseLeave);

                                    int optionNum = int.Parse(cntl.Tag.ToString());
                                    if (optionNum < tempbitmask.Options.Length && tempbitmask.Options[optionNum].description != null)
                                        cntl.ForeColor = Color.DarkGoldenrod;
                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << optionNum).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Long_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask32s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();

                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    // Control mouse in/out for extra description popup box
                                    cntl.MouseEnter += new EventHandler(cntl_MouseEnter);
                                    cntl.MouseLeave += new EventHandler(cntl_MouseLeave);

                                    int optionNum = int.Parse(cntl.Tag.ToString());
                                    if (optionNum < tempbitmask.Options.Length && tempbitmask.Options[optionNum].description != null)
                                        cntl.ForeColor = Color.DarkGoldenrod;
                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << optionNum).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Char_Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum8s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum16s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Long_Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum32s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Unused:
                            {
                                DataValues tempUnknown = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Unused, ctl.lineNumber);
                                tempUnknown.size = ((IFPIO.Unused)ctl).size;
                                tempUnknown.TabIndex = tabIndex;
                                if (enabled) tempUnknown.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                if (tempUnknown.ValueType == IFPIO.ObjectEnum.Unused)
                                    tempUnknown.textBox1.Text = "unused (size " + tempUnknown.size + ")";
                                panelMetaEditor.Controls.Add(tempUnknown);
                                tempUnknown.BringToFront();

                                tempUnknown.meta.MS.Position = metaOffset + ctl.offset;
                                byte[] tempB = new byte[((IFPIO.Unused)ctl).size];
                                tempUnknown.meta.MS.Read(tempB, 0, tempB.Length);
                                toolTip1.SetToolTip(tempUnknown.Controls[1], toHex(tempB));
                                toolTip1.SetToolTip(tempUnknown.Controls[1], BitConverter.ToString(tempB).Replace('-', ' '));
                                toolTip1.IsBalloon = true;
                                break;
                            }
                        case IFPIO.ObjectEnum.ARGB_Color:
                            {
                                if (MetaEditor.MetaEditor.ShowFloats == false)
                                    break;
                                argb_color tempARGBColor = new argb_color(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPColor)ctl).hasAlpha, ((IFPIO.IFPColor)ctl).type, ctl.lineNumber);
                                tempARGBColor.TabIndex = tabIndex;
                                if (enabled) tempARGBColor.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempARGBColor);
                                tempARGBColor.BringToFront();
                                break;
                            }
                        default:
                            break;
                    }

            #if DEBUG
                    if (((BaseField)panelMetaEditor.Controls[0]).size == 0)
                    {
                        string s = panelMetaEditor.Controls[0].GetType().ToString();
                        switch (panelMetaEditor.Controls[0].GetType().ToString())
                        {
                            case "entity.MetaEditor2.DataValues":
                                if (((DataValues)panelMetaEditor.Controls[0]).ValueType != IFPIO.ObjectEnum.Unused)
                                    MessageBox.Show("WARNING: 0 Sized control: " + ((DataValues)panelMetaEditor.Controls[0]).ValueType);
                                break;
                            default:
                                MessageBox.Show("WARNING: 0 Sized control: " + panelMetaEditor.Controls[0].Name);
                                break;
                        }
                    }
            #endif
                    // Should always be true, but for safety
                    if (panelMetaEditor.Controls[0] is BaseField)
                    {
                        // Set extra description text for control if it exists
                        if (ctl.description != null)
                        {
                            ((BaseField)panelMetaEditor.Controls[0]).description = ctl.description;
                            //((BaseField)panelMetaEditor.Controls[0]).Controls[0].Text += "*";// +((BaseField)panelMetaEditor.Controls[0]).Controls[0].Text;
                            ((BaseField)panelMetaEditor.Controls[0]).Controls[0].ForeColor = Color.DarkGoldenrod;
                        }
                    }

                    // Control mouse in/out for extra description popup box
                    panelMetaEditor.Controls[0].Controls[0].MouseEnter += new EventHandler(cntl_MouseEnter);
                    panelMetaEditor.Controls[0].Controls[0].MouseLeave += new EventHandler(cntl_MouseLeave);

                    // Control when a control receives focus
                    panelMetaEditor.Controls[0].Controls[1].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);

                    // Make sure we are in a reflexive and that we don't already have a menustrip
                    if (treeViewTagReflexives.SelectedNode.Parent != null && panelMetaEditor.Controls[0].ContextMenuStrip == null)
                    {
                        panelMetaEditor.Controls[0].Controls[1].ContextMenuStrip = cmMassField;
                    }

                    if (ctl.ObjectType != IFPIO.ObjectEnum.Struct)
                    {
                        int temp = ctl.offset;
                        // Take into account that idents actually start at -4 due to tags preceding
                        if (ctl.ObjectType == IFPIO.ObjectEnum.Ident)
                            temp -= 4;

                        string tip =
                                "offset in reflexive: " + (temp).ToString() + " (" + toHex(temp) + ")" +
                                "\n         offset in tag: " + (rd.baseOffset + temp).ToString() + " (" + toHex(rd.baseOffset + temp) + ")" +
                                "\n        offset in map: " + (rd.baseOffset + meta.offset + temp).ToString() + " (" + toHex(rd.baseOffset + meta.offset + temp) + ")";

                        #region Change A,R,G,B color fields to ARGB_color control
                        if (panelMetaEditor.Controls.Count > 0 && panelMetaEditor.Controls[0] is DataValues)
                        {
                            // if (((ctl.name.ToLower().Contains(" a") & ctl.name[ctl.name.ToLower().IndexOf(" a")]) ||
                            // ctl.name.ToLower().Contains("alpha"))& alphaControl == null)
                            if (ColorWheel.checkForColor(ctl.name, alphaControl, " a", "alpha"))
                            {
                                alphaControl = (DataValues)panelMetaEditor.Controls[0];
                                colorSpaceCount = 0;
                            }

                                // if (ctl.name.ToLower().Contains(" r") & redControl == null)
                            else if (ColorWheel.checkForColor(ctl.name, redControl, " r", "red"))
                            {
                                redControl = (DataValues)panelMetaEditor.Controls[0];
                                colorSpaceCount = 0;
                            }

                                // if (ctl.name.ToLower().Contains(" g") & greenControl == null)
                            else if (ColorWheel.checkForColor(ctl.name, greenControl, " g", "green"))
                            {
                                greenControl = (DataValues)panelMetaEditor.Controls[0];
                                colorSpaceCount = 0;
                            }

                                // if (ctl.name.ToLower().Contains(" b") & blueControl == null)
                            else if (ColorWheel.checkForColor(ctl.name, blueControl, " b", "blue"))
                            {
                                blueControl = (DataValues)panelMetaEditor.Controls[0];
                                colorSpaceCount = 0;
                            }
                            else
                            {
                                colorSpaceCount++;
                                if (colorSpaceCount == 1)
                                {
                                    alphaControl = null;
                                    redControl = null;
                                    greenControl = null;
                                    blueControl = null;
                                }
                            }

                            if (redControl != null & greenControl != null & blueControl != null)
                            {
                                // Create the new argb_color class
                                argb_color tempARGBColor = new argb_color(
                                    meta,
                                    redControl.EntName.ToUpper().Replace(" R", string.Empty).Replace("RED",string.Empty),
                                    map,
                                    alphaControl != null ? alphaControl.chunkOffset : redControl.chunkOffset,
                                    alphaControl != null,
                                    ctl.ObjectType,
                                    alphaControl != null ? alphaControl.LineNumber : redControl.LineNumber
                                    );
                                tempARGBColor.TabIndex = tabIndex;
                                if (enabled) tempARGBColor.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);

                                // Remove the DataField controls & dispose of them
                                if (alphaControl != null)
                                {
                                    // Retrieve the first tooltip for the control from the alphaControl
                                    tip = toolTip1.GetToolTip(alphaControl);
                                    panelMetaEditor.Controls.Remove(alphaControl);
                                    alphaControl.Dispose();
                                }
                                else
                                    // Retrieve the first tooltip for the control from the redControl
                                    tip = toolTip1.GetToolTip(redControl);

                                panelMetaEditor.Controls.Remove(redControl);
                                redControl.Dispose();
                                panelMetaEditor.Controls.Remove(greenControl);
                                greenControl.Dispose();
                                panelMetaEditor.Controls.Remove(blueControl);
                                blueControl.Dispose();

                                // Add the argb_color control to the panel
                                panelMetaEditor.Controls.Add(tempARGBColor);

                                tempARGBColor.BringToFront();

                                // Reset for next batch
                                colorSpaceCount++;
                                alphaControl = null;
                                redControl = null;
                                greenControl = null;
                                blueControl = null;
                            }
                        }
                        else
                        {
                            colorSpaceCount++;
                        }
                        #endregion

                        #region Bitmask tooltip offsets
                        if (panelMetaEditor.Controls[0] is Bitmask)
                        {
                            Bitmask tempbitmask = ((Bitmask)panelMetaEditor.Controls[0]);
                            uint bitValue = uint.Parse(tempbitmask.Value);
                            string s = " = 0x" + bitValue.ToString("X4") + " (" + tempbitmask.Value + ")";
                            for (int i = 0; i < 32; i++)
                            {
                                s = ((1 << i & bitValue) == 0 ? "0" : "1") + s;
                                if (i % 4 == 3)
                                    s = " " + s;
                            }
                            tip += "\n\nBITMASK VALUE:\n" + s;
                        }
                        #endregion

                        toolTip1.SetToolTip(panelMetaEditor.Controls[0].Controls[0], tip);

                    }
                }
                catch (Exception ex)
                {

                    throw new Exception(ex.Message + "\nField Offset: " +ctl.offset + "\nName: " + ctl.name +"\nMeta Offset: " + metaOffset, ex);
                }

            }
            // Restore our panel visibility
            panel.Visible = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Populates the data for the given control
        /// </summary>
        /// <param name="c"></param>
        private void PopulateValue(Control c)
        {
            Control c2     = c.Controls[0];
            int     offset = (int)c2.Tag;

            BR.BaseStream.Position = offset;
            switch (FieldControl.GetType().ToString())
            {
            case "entity.MetaEditor2.DataValues":
                c2.Name = "DataValues";
                switch (((DataValues)FieldControl).ValueType)
                {
                case HaloMap.Plugins.IFPIO.ObjectEnum.Byte:
                    c2.Text = BR.ReadByte().ToString();
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.Short:
                    c2.Text = BR.ReadInt16().ToString();
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.UShort:
                    c2.Text = BR.ReadUInt16().ToString();
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.Int:
                    c2.Text = BR.ReadInt32().ToString();
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.UInt:
                    c2.Text = BR.ReadUInt32().ToString();
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.Float:
                    c2.Text = BR.ReadSingle().ToString();
                    break;
                }
                break;

            case "entity.MetaEditor2.EntStrings":
                EntStrings EntString = (EntStrings)FieldControl;
                if (EntString.entUnicode)
                {
                    c2.Text = Encoding.Unicode.GetString(BR.ReadBytes(EntString.length));
                }
                else
                {
                    c2.Text = Encoding.ASCII.GetString(BR.ReadBytes(EntString.length));
                }
                c2.Text = c2.Text.TrimEnd('\0');

                break;

            case "entity.MetaEditor2.Ident":
                ComboBox c3 = (ComboBox)c.Controls[1];
                if (((Ident)FieldControl).HasTagType)
                {
                    byte[] TagTypeBytes = BR.ReadBytes(4);
                    Array.Reverse(TagTypeBytes);
                    string TagType = ASCIIEncoding.ASCII.GetString(TagTypeBytes);

                    if (TagTypeBytes[0] == (char)0xFF)          // Null values contain four characters of 255 (0xFF)
                    {
                        c2.Text = "null";
                    }
                    else
                    {
                        c2.Text = TagType;
                    }
                }

                int tempint  = BR.ReadInt32();
                int TagIndex = FieldControl.map.Functions.ForMeta.FindMetaByID(tempint);
                if (TagIndex == -1)
                {
                    c3.Text = "null";
                }
                else
                {
                    if (!((Ident)FieldControl).HasTagType)
                    {
                        c2.Text = FieldControl.map.MetaInfo.TagType[TagIndex];
                    }
                    c3.Text = FieldControl.map.FileNames.Name[TagIndex];
                }

                break;

            case "entity.MetaEditor2.SID":
                short SID = BR.ReadInt16();
                BR.BaseStream.Position += 1;
                byte SIDLength = BR.ReadByte();

                if (SIDLength == FieldControl.map.Strings.Length[SID])
                {
                    c2.Text = FieldControl.map.Strings.Name[SID];
                }
                else
                {
                    c2.Text = string.Empty;
                }
                break;

            case "entity.MetaEditor2.Enums":
                Enums Enum = (Enums)FieldControl;
                switch (Enum.enumType)
                {
                case 8:
                    byte EValue8 = BR.ReadByte();
                    c2.Text = (string)((ComboBox)c2).Items[EValue8];
                    break;

                case 16:
                    short EValue16 = BR.ReadInt16();
                    c2.Text = (string)((ComboBox)c2).Items[EValue16];
                    break;

                case 32:
                    int EValue32 = BR.ReadInt32();
                    c2.Text = (string)((ComboBox)c2).Items[EValue32];
                    break;
                }
                break;

            case "entity.MetaEditor2.Indices":
                Indices indices = (Indices)FieldControl;
                int     Value   = 0;
                switch (indices.ValueType)
                {
                case HaloMap.Plugins.IFPIO.ObjectEnum.Short:
                {
                    Value = BR.ReadInt16();
                    break;
                }

                case HaloMap.Plugins.IFPIO.ObjectEnum.Int:
                {
                    Value = BR.ReadInt32();
                    break;
                }

                case HaloMap.Plugins.IFPIO.ObjectEnum.UShort:
                {
                    Value = (int)BR.ReadUInt16();
                    break;
                }

                case HaloMap.Plugins.IFPIO.ObjectEnum.UInt:
                {
                    Value = (int)BR.ReadUInt32();
                    break;
                }

                case HaloMap.Plugins.IFPIO.ObjectEnum.Byte:
                {
                    Value = (int)BR.ReadByte();
                    break;
                }
                }
                if (Value == -1)
                {
                    c2.Text = indices.IndicesList[indices.IndicesList.Count - 1];
                }
                else
                {
                    c2.Text = indices.IndicesList[Value];
                }
                break;
            }
        }
Ejemplo n.º 4
0
        private void SaveFieldChange(Control c)
        {
            BW.BaseStream.Position = (int)c.Tag;
            switch (FieldControl.GetType().ToString())
            {
            // For bytes, (u)int16, (u)int32
            // *This section complete (? may still be missing types)*
            case "entity.MetaEditor2.DataValues":
                long  Value;
                float FValue;
                if (long.TryParse(c.Text, out Value))
                {
                    switch (((DataValues)FieldControl).ValueType)
                    {
                    case HaloMap.Plugins.IFPIO.ObjectEnum.Byte:
                        BW.Write((byte)Value);
                        c.Text = ((byte)Value).ToString();
                        break;

                    case HaloMap.Plugins.IFPIO.ObjectEnum.Short:
                        BW.Write((Int16)Value);
                        c.Text = ((Int16)Value).ToString();
                        break;

                    case HaloMap.Plugins.IFPIO.ObjectEnum.UShort:
                        BW.Write((UInt16)Value);
                        c.Text = ((UInt16)Value).ToString();
                        break;

                    case HaloMap.Plugins.IFPIO.ObjectEnum.Int:
                        BW.Write((Int32)Value);
                        c.Text = ((Int32)Value).ToString();
                        break;

                    case HaloMap.Plugins.IFPIO.ObjectEnum.UInt:
                        BW.Write((UInt32)Value);
                        c.Text = ((UInt32)Value).ToString();
                        break;
                    }
                }
                else if (float.TryParse(c.Text, out FValue))
                {
                    switch (((DataValues)FieldControl).ValueType)
                    {
                    case HaloMap.Plugins.IFPIO.ObjectEnum.Float:
                        BW.Write((float)FValue);
                        c.Text = ((float)FValue).ToString();
                        break;
                    }
                }
                else
                {
                    this.Enabled = false;
                    // In case of error, reset to saved value
                    PopulateValue(c.Parent);
                    this.Enabled = true;
                }
                break;

            // *This section Complete*
            case "entity.MetaEditor2.EntStrings":
                EntStrings EntString   = (EntStrings)FieldControl;
                byte[]     StringBytes = Encoding.ASCII.GetBytes(c.Text.ToCharArray());
                Array.Resize(ref StringBytes, EntString.length);
                BW.Write(StringBytes);
                break;

            // *This section Complete*
            case "entity.MetaEditor2.Ident":
                ComboBox TagType = (ComboBox)c.Parent.Controls[0];
                ComboBox Ident   = (ComboBox)c.Parent.Controls[1];

                BW.BaseStream.Position = (int)TagType.Tag;

                if (((Ident)FieldControl).HasTagType)
                {
                    if (TagType.Text != "null")
                    {
                        byte[] TagTypeBytes = ASCIIEncoding.ASCII.GetBytes(TagType.Text);
                        Array.Reverse(TagTypeBytes);
                        BW.Write(TagTypeBytes);
                    }
                    else
                    {
                        byte[] TagTypeBytes = new byte[4] {
                            0xFF, 0xFF, 0xFF, 0xFF
                        };
                        BW.Write(TagTypeBytes);
                    }
                }
                int Index = FieldControl.map.Functions.ForMeta.FindByNameAndTagType(TagType.Text, Ident.Text);
                if (Index != -1)
                {
                    BW.Write(FieldControl.map.MetaInfo.Ident[Index]);
                }
                else
                {
                    BW.Write((int)-1);
                }
                break;

            // *This section Complete*
            case "entity.MetaEditor2.SID":
                SIDData sd = (SIDData)((ComboBox)c).SelectedItem;
                BW.Write((short)sd.Index);
                BW.Write((byte)0);
                BW.Write((byte)FieldControl.map.Strings.Length[sd.Index]);
                //FieldControl.map.Strings.Name[(c.Text)];
                break;

            // *This section Complete*
            case "entity.MetaEditor2.Enums":
                Enums Enum = (Enums)FieldControl;
                HaloMap.Plugins.IFPIO.Option o = (HaloMap.Plugins.IFPIO.Option)Enum.Options[((ComboBox)c).SelectedIndex];
                switch (Enum.enumType)
                {
                case 8:
                    BW.Write((byte)o.value);
                    break;

                case 16:
                    BW.Write((short)o.value);
                    break;

                case 32:
                    BW.Write((int)o.value);
                    break;
                }
                break;

            // *This section Complete*
            case "entity.MetaEditor2.Indices":
                Indices indices    = (Indices)FieldControl;
                int     IndexValue = indices.IndicesList.IndexOf(c.Text);
                // Last listing is for nulled resources
                if (IndexValue == indices.IndicesList.Count - 1)
                {
                    IndexValue = -1;
                }
                switch (indices.ValueType)
                {
                case HaloMap.Plugins.IFPIO.ObjectEnum.Byte:
                    BW.Write((byte)IndexValue);
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.Short:
                    BW.Write((short)IndexValue);
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.UShort:
                    BW.Write((ushort)IndexValue);
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.Int:
                    BW.Write((int)IndexValue);
                    break;

                case HaloMap.Plugins.IFPIO.ObjectEnum.UInt:
                    BW.Write((uint)IndexValue);
                    break;
                }
                break;
            }
        }
Ejemplo n.º 5
0
        private void loadControls(TreeNode Location)
        {
            toolTip1.AutoPopDelay = 10000;
            reflexiveData rd = (reflexiveData)Location.Tag;

            if (rd.chunkCount > 100000) // Some very large number
                throw new Exception("\"" + rd.node.Text + "\" appears to contain " + rd.chunkCount + "chunks!\n"
                    + "Try reloading tag. If problem persists, you likely have a corrupt map!");

            int chNum = rd.chunkSelected;
            bool enabled = rd.chunkCount != 0;
            int metaOffset = rd.baseOffset;

            // Make our panel non-visibile while we create our controls
            Panel panel = this.panelMetaEditor;
            panel.Visible = false;

            // Dispose of each control and also add a safety  in case we somehow go into an endless loop (max 1000)
            int safetyCount = 1000;
            while (panel.Controls.Count > 0 && safetyCount > 0)
            {
                panel.Controls[0].Dispose();
                safetyCount--;
            }
            // Should be empty, but clear anyways.
            panel.Controls.Clear();

            Object[] o;
            if (rd.reflexive == null)
                o = ifp.items;
            else
                o = rd.reflexive.items;

            bool labelFound = false;
            int tabIndex = 0;
            foreach (IFPIO.BaseObject ctl in o)
            {
                tabIndex++;
                try
                {
                    switch (ctl.ObjectType)
                    {
                        case IFPIO.ObjectEnum.Struct:
                            {
            #if DEBUG
                                if (((IFPIO.Reflexive)ctl).chunkSize == 1)
                                {
                                    System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
                                    BR.BaseStream.Position = ctl.offset + metaOffset;
                                    int chunkCount = BR.ReadInt32();
                                    if (chunkCount == 0)
                                        continue;
                                    int chunkOffset = BR.ReadInt32() - meta.magic;
                                    int tagIndex = map.Functions.ForMeta.FindMetaByOffset(chunkOffset);

                                    StringBox sb = new StringBox(meta, ctl.name + " (reflexive)", map, ctl.offset, ctl.lineNumber, 0);

                                    if (enabled) sb.Populate(metaOffset, tagIndex == meta.TagIndex);
                                    if (sb.size > 0)
                                    {
                                        panelMetaEditor.Controls.Add(sb);
                                        sb.BringToFront();
                                    }
                                    //panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                }
            #endif
                                /*
                            if (Meta_Editor.MetaEditor.ShowReflexives == false)
                                break;
                            // tempLabel is a blank space located above reflexives
                            Label tempLabel = new Label();
                            tempLabel.AutoSize = true;
                            tempLabel.Location = new System.Drawing.Point(0, 0);
                            tempLabel.Name = "label1";
                            tempLabel.Dock = DockStyle.Top;
                            tempLabel.Size = new System.Drawing.Size(35, 13);
                            tempLabel.TabIndex = tabIndex;

                            // tempReflexive is the reflexive and all data (incl other reflexives) within it
                            ReflexiveControl tempReflexive = new ReflexiveControl(mapnumber, meta.offset, ((IFPIO.Reflexive)ctl).HasCount, ctl.lineNumber, this);
                            //tempReflexive.Location = new System.Drawing.Point(10, 0);
                            tempReflexive.Name = "reflexive";
                            tempReflexive.TabIndex = tabIndex;
                            tempReflexive.LoadENTControls((IFPIO.Reflexive)ctl, ((IFPIO.Reflexive)ctl).items,
                                                           true, 0, ref tabIndex, ctl.offset.ToString());

                            // Label, Combobox & Button are always added ( = 3)
                            if (!(tempReflexive.Controls.Count <= 2 && skipEmptyReflex))
                            {
                                panelMetaEditor.Controls.Add(tempLabel);
                                panelMetaEditor.Controls[panelMetaEditor.Controls.Count - 1].BringToFront();
                                panelMetaEditor.Controls.Add(tempReflexive);
                                panelMetaEditor.Controls[panelMetaEditor.Controls.Count - 1].BringToFront();
                            }
                            break;
                            */
                                continue;
                            }
                        case IFPIO.ObjectEnum.Block:
                            {
                                Ident tempident = new Ident(meta, ctl.name, map, ctl.offset + 4, true, ctl.lineNumber);
                                tempident.Name = "ident";
                                tempident.TabIndex = tabIndex;
                                if (enabled) tempident.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempident.Tag = "[" + tempident.Controls[2].Text + "] "
                                                + tempident.Controls[1].Text;
                                //tempident.Controls[1].ContextMenuStrip = identContext;
                                panelMetaEditor.Controls.Add(tempident);
                                tempident.BringToFront();
                                panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                tempident.ContextMenuStrip = cmIdent;
                                break;
                            }
                        case IFPIO.ObjectEnum.TagType:
                            continue;
                        case IFPIO.ObjectEnum.Ident:
                            {
                                if (MetaEditor.MetaEditor.ShowIdents == false)
                                    break;
                                Ident tempident = new Ident(meta, ctl.name, map, ctl.offset, ((IFPIO.Ident)ctl).hasTagType, ctl.lineNumber);
                                tempident.Name = "ident";
                                tempident.TabIndex = tabIndex;
                                if (enabled) tempident.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempident.Tag = "[" + tempident.Controls[2].Text + "] "
                                                + tempident.Controls[1].Text;
                                //tempident.Controls[1].ContextMenuStrip = identContext;
                                panelMetaEditor.Controls.Add(tempident);
                                tempident.BringToFront();
                                panelMetaEditor.Controls[0].Controls[1].MouseEnter += new EventHandler(cbIdent_MouseEnter);
                                panelMetaEditor.Controls[0].Controls[1].MouseLeave += new EventHandler(cbIdent_MouseLeave);
                                panelMetaEditor.Controls[0].Controls[2].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                tempident.ContextMenuStrip = cmIdent;
                                break;
                            }
                        case IFPIO.ObjectEnum.StringID:
                            {
                                if (MetaEditor.MetaEditor.ShowSIDs == false)
                                    break;
                                SID tempSID = new SID(meta, ctl.name, map, ctl.offset, ctl.lineNumber);
                                tempSID.Name = "sid";
                                tempSID.TabIndex = tabIndex;
                                if (enabled) tempSID.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempSID);
                                tempSID.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Float:
                            {
                                if (MetaEditor.MetaEditor.ShowFloats == false)
                                    break;
                                DataValues tempFloat = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Float, ctl.lineNumber);
                                tempFloat.TabIndex = tabIndex;
                                if (enabled) tempFloat.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempFloat);
                                tempFloat.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.String32:
                            {
                                if (MetaEditor.MetaEditor.ShowString32s == false && ctl.ObjectType == IFPIO.ObjectEnum.String32)
                                    break;
                                EntStrings tempstring = new EntStrings(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPString)ctl).size, ((IFPIO.IFPString)ctl).type, ctl.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                panelMetaEditor.Controls.Add(tempstring);
                                if (enabled) tempstring.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                tempstring.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.UnicodeString256:
                            {
                                if (MetaEditor.MetaEditor.ShowUnicodeString256s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.String256:
                            {
                                if (MetaEditor.MetaEditor.ShowString256s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.UnicodeString64:
                            {
                                if (MetaEditor.MetaEditor.ShowUnicodeString64s == false)
                                    break;
                                goto case IFPIO.ObjectEnum.String32;
                            }
                        case IFPIO.ObjectEnum.String:
                            {
                                if (MetaEditor.MetaEditor.ShowString32s == false && ctl.ObjectType == IFPIO.ObjectEnum.String32)
                                    break;
                                EntStrings tempstring = new EntStrings(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPString)ctl).size, ((IFPIO.IFPString)ctl).type, ctl.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                if (enabled) tempstring.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempstring);
                                tempstring.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Byte:
                            {
                                if (((IFPIO.IFPByte)ctl).entIndex.nulled == true)
                                {
                                    if (MetaEditor.MetaEditor.ShowBytes == false)
                                        break;
                                    DataValues tempByte = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Byte, ctl.lineNumber);
                                    tempByte.TabIndex = tabIndex;
                                    if (enabled) tempByte.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                    panelMetaEditor.Controls.Add(tempByte);
                                    tempByte.BringToFront();
                                }
                                else
                                {
                                    if (MetaEditor.MetaEditor.ShowBlockIndex8s == false)
                                        break;
                                    Indices tempDataValues = new Indices(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ((IFPIO.IFPByte)ctl).entIndex);
                                    tempDataValues.TabIndex = tabIndex;
                                    panelMetaEditor.Controls.Add(tempDataValues);
                                    tempDataValues.BringToFront();
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Int:
                            {
                                if (((IFPIO.IFPInt)ctl).entIndex.nulled == true)
                                {
                                    if ((MetaEditor.MetaEditor.ShowInts == false && ctl.ObjectType == IFPIO.ObjectEnum.Int)
                                        || (MetaEditor.MetaEditor.ShowShorts == false && ctl.ObjectType == IFPIO.ObjectEnum.Short)
                                        || (MetaEditor.MetaEditor.ShowUshorts == false && ctl.ObjectType == IFPIO.ObjectEnum.UShort)
                                        || (MetaEditor.MetaEditor.ShowUints == false && ctl.ObjectType == IFPIO.ObjectEnum.UInt))
                                        break;
                                    DataValues tempdatavalues = new DataValues(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ctl.lineNumber);
                                    tempdatavalues.TabIndex = tabIndex;
                                    if (enabled) tempdatavalues.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                    panelMetaEditor.Controls.Add(tempdatavalues);
                                    tempdatavalues.BringToFront();
                                }
                                else
                                {
                                    if ((MetaEditor.MetaEditor.ShowBlockIndex32s == false && (ctl.ObjectType == IFPIO.ObjectEnum.Int | ctl.ObjectType == IFPIO.ObjectEnum.UInt))
                                        || (MetaEditor.MetaEditor.ShowBlockIndex16s == false && (ctl.ObjectType == IFPIO.ObjectEnum.Short | ctl.ObjectType == IFPIO.ObjectEnum.UShort))
                                        || (MetaEditor.MetaEditor.ShowBlockIndex8s == false && ctl.ObjectType == IFPIO.ObjectEnum.Byte))
                                        break;
                                    Indices tempdatavalues = new Indices(meta, ctl.name, map, ctl.offset, ctl.ObjectType, ((IFPIO.IFPInt)ctl).entIndex);
                                    tempdatavalues.TabIndex = tabIndex;
                                    panelMetaEditor.Controls.Add(tempdatavalues);
                                    tempdatavalues.BringToFront();
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Short:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.UShort:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.UInt:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }
                        case IFPIO.ObjectEnum.Unknown:
                            {
                                if (MetaEditor.MetaEditor.ShowUndefineds == false)
                                    break;
                                DataValues tempUnknown = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Unknown, ctl.lineNumber);
                                tempUnknown.TabIndex = tabIndex;
                                if (enabled) tempUnknown.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempUnknown);
                                tempUnknown.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Byte_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask8s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();
                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << int.Parse(cntl.Tag.ToString())).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Word_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask16s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();
                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << int.Parse(cntl.Tag.ToString())).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Long_Flags:
                            {
                                if (MetaEditor.MetaEditor.ShowBitmask32s == false)
                                    break;
                                Bitmask tempbitmask = new Bitmask(meta, ctl.name, map, ctl.offset, ((IFPIO.Bitmask)ctl).bitmaskSize, ((IFPIO.Bitmask)ctl).options, ctl.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                if (enabled) tempbitmask.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempbitmask);
                                tempbitmask.BringToFront();

                                foreach (Control cntl in tempbitmask.Controls[0].Controls)
                                {
                                    cntl.GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                                    toolTip1.SetToolTip(cntl, "Bit " + cntl.Tag.ToString() + " (Value = " + (1 << int.Parse(cntl.Tag.ToString())).ToString() + ")");
                                }
                                break;
                            }
                        case IFPIO.ObjectEnum.Char_Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum8s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum16s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Long_Enum:
                            {
                                if (MetaEditor.MetaEditor.ShowEnum32s == false)
                                    break;
                                Enums tempenum = new Enums(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPEnum)ctl).enumSize, ((IFPIO.IFPEnum)ctl).options, ctl.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                if (enabled) tempenum.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempenum);
                                tempenum.BringToFront();
                                break;
                            }
                        case IFPIO.ObjectEnum.Unused:
                            {
                                DataValues tempUnknown = new DataValues(meta, ctl.name, map, ctl.offset, IFPIO.ObjectEnum.Unused, ctl.lineNumber);
                                tempUnknown.size = ((IFPIO.Unused)ctl).size;
                                tempUnknown.TabIndex = tabIndex;
                                if (enabled) tempUnknown.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                if (tempUnknown.ValueType == IFPIO.ObjectEnum.Unused)
                                    tempUnknown.textBox1.Text = "unused (size " + tempUnknown.size + ")";
                                panelMetaEditor.Controls.Add(tempUnknown);
                                tempUnknown.BringToFront();

                                tempUnknown.meta.MS.Position = metaOffset + ctl.offset;
                                byte[] tempB = new byte[((IFPIO.Unused)ctl).size];
                                tempUnknown.meta.MS.Read(tempB, 0, tempB.Length);
                                toolTip1.SetToolTip(tempUnknown.Controls[1], toHex(tempB));
                                toolTip1.SetToolTip(tempUnknown.Controls[1], BitConverter.ToString(tempB).Replace('-', ' '));
                                toolTip1.IsBalloon = true;
                                break;
                            }
                        case IFPIO.ObjectEnum.ARGB_Color:
                            {
                                if (MetaEditor.MetaEditor.ShowFloats == false)
                                    break;
                                argb_color tempARGBColor = new argb_color(meta, ctl.name, map, ctl.offset, ((IFPIO.IFPColor)ctl).hasAlpha, ((IFPIO.IFPColor)ctl).type, ctl.lineNumber);
                                tempARGBColor.TabIndex = tabIndex;
                                if (enabled) tempARGBColor.Populate(metaOffset, rd.inTagNumber == meta.TagIndex);
                                panelMetaEditor.Controls.Add(tempARGBColor);
                                tempARGBColor.BringToFront();
                                break;
                            }
                        default:
                            break;
                    }

            #if DEBUG
                    if (((BaseField)panelMetaEditor.Controls[0]).size == 0)
                    {
                        string s = panelMetaEditor.Controls[0].GetType().ToString();
                        switch (panelMetaEditor.Controls[0].GetType().ToString())
                        {
                            case "entity.MetaEditor2.DataValues":
                                if (((DataValues)panelMetaEditor.Controls[0]).ValueType != IFPIO.ObjectEnum.Unused)
                                    MessageBox.Show("WARNING: 0 Sized control: " + ((DataValues)panelMetaEditor.Controls[0]).ValueType);
                                break;
                            default:
                                MessageBox.Show("WARNING: 0 Sized control: " + panelMetaEditor.Controls[0].Name);
                                break;
                        }
                    }
            #endif

                    panelMetaEditor.Controls[0].Controls[1].GotFocus += new EventHandler(MetaEditorControlPage_GotFocus);
                    if (ctl.ObjectType != IFPIO.ObjectEnum.Struct)
                    {
                        int temp = ctl.offset;
                        // Take into account that idents actually start at -4 due to tags preceding
                        if (ctl.ObjectType == IFPIO.ObjectEnum.Ident)
                            temp -= 4;

                        string tip =
                                "offset in reflexive: " + (temp).ToString() + " (" + toHex(temp) + ")" +
                                "\n         offset in tag: " + (rd.baseOffset + temp).ToString() + " (" + toHex(rd.baseOffset + temp) + ")" +
                                "\n        offset in map: " + (rd.baseOffset + meta.offset + temp).ToString() + " (" + toHex(rd.baseOffset + meta.offset + temp) + ")";

                        if (panelMetaEditor.Controls[0] is Bitmask)
                        {
                            Bitmask tempbitmask = ((Bitmask)panelMetaEditor.Controls[0]);
                            uint bitValue = uint.Parse(tempbitmask.Value);
                            string s = " = 0x" + bitValue.ToString("X4") + " (" + tempbitmask.Value + ")";
                            for (int i = 0; i < 32; i++)
                            {
                                s = ((1 << i & bitValue) == 0 ? "0" : "1") + s;
                                if (i % 4 == 3)
                                    s = " " + s;
                            }
                            tip += "\n\nBITMASK VALUE:\n" + s;
                        }

                        toolTip1.SetToolTip(panelMetaEditor.Controls[0].Controls[0], tip);

                    }
                }
                catch (Exception ex)
                {

                    throw new Exception(ex.Message + "\nField Offset: " +ctl.offset + "\nName: " + ctl.name +"\nMeta Offset: " + metaOffset, ex);
                }

            }
            // Restore our panel visibility
            panel.Visible = true;
        }