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; }
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; }