示例#1
0
        private void AddElement(ElementStructure es)
        {
            int a = -1, b = 0, c = 0;

            AddElement(es, ref a, null, ref b, ref c);
        }
示例#2
0
        private void AddElement(ElementStructure es, ref int offset, byte[] data, ref int groupOffset, ref int CurrentGroup)
        {
            Panel panel1 = new Panel();

            panel1.AutoSize = true;
            panel1.Width    = fpanel1.Width - 10;
            panel1.Height   = 1;
            panel1.Anchor   = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            int  ypos      = 0;
            uint flagValue = 0; // value if flags is set
            bool hasFlags  = (es.options == null && es.flags != null);

            TextBox tb = new TextBox();

            boxes.Add(tb);
            if (es.group != 0)
            {
                CheckBox cb = new CheckBox();
                cb.Text = "Use this value?";
                panel1.Controls.Add(cb);
                cb.Location = new System.Drawing.Point(10, ypos);
                ypos       += 24;
                cb.Tag      = new cbTag(es.group, tb);
                if (CurrentGroup != es.group)
                {
                    cb.Checked = true;
                }
                else
                {
                    tb.Enabled = false;
                }
                cb.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
            }
            if (es.optional || es.repeat > 0 && repeatcount > 0)
            {
                CheckBox cb = new CheckBox();
                cb.Text = "Use this value?";
                panel1.Controls.Add(cb);
                cb.Location = new System.Drawing.Point(10, ypos);
                ypos       += 24;
                cb.Tag      = new repeatCbTag(tb, elements.Count);
                if (data == null)
                {
                    tb.Enabled = false;
                }
                else
                {
                    cb.Checked = true;
                }
                cb.CheckedChanged += new EventHandler(RepeatCheckBox_CheckedChanged);
            }
            if ((CurrentGroup == 0 && es.group != 0) || (CurrentGroup != 0 && es.group != 0 && CurrentGroup != es.group))
            {
                CurrentGroup = es.group;
                groupOffset  = offset;
            }
            else if (CurrentGroup != 0 && es.group == 0)
            {
                CurrentGroup = 0;
            }
            else if (CurrentGroup != 0 && CurrentGroup == es.group)
            {
                offset = groupOffset;
            }

            valueTypes.Add(es.type);
            if (data != null)
            {
                switch (es.type)
                {
                case ElementValueType.UInt:
                {
                    var v = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X8") : v.ToString();
                    offset   += 4;
                }
                break;

                case ElementValueType.Int:
                {
                    var v = TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X8") : v.ToString();
                    offset   += 4;
                }
                break;

                case ElementValueType.FormID:
                    tb.Text = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]).ToString("X8");
                    offset += 4;
                    break;

                case ElementValueType.Float:
                    tb.Text = TypeConverter.h2f(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]).ToString();
                    offset += 4;
                    break;

                case ElementValueType.UShort:
                {
                    var v = TypeConverter.h2s(data[offset], data[offset + 1]);
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X4") : v.ToString();
                    offset   += 2;
                } break;

                case ElementValueType.Short:
                {
                    var v = TypeConverter.h2ss(data[offset], data[offset + 1]);
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X4") : v.ToString();
                    offset   += 2;
                } break;

                case ElementValueType.Byte:
                {
                    var v = data[offset];
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X2") : v.ToString();
                    offset++;
                } break;

                case ElementValueType.SByte:
                {
                    var v = (sbyte)data[offset];
                    flagValue = (uint)v;
                    tb.Text   = hasFlags || es.hexview ? "0x" + v.ToString("X2") : v.ToString();
                    offset++;
                } break;

                case ElementValueType.String:
                {
                    string s = "";
                    while (data[offset] != 0)
                    {
                        s += (char)data[offset++];
                    }
                    offset++;
                    tb.Text   = s;
                    tb.Width += 200;
                } break;

                case ElementValueType.BString:
                {
                    int    len = TypeConverter.h2s(data[offset], data[offset + 1]);
                    string s   = System.Text.Encoding.ASCII.GetString(data, offset + 2, len);
                    offset    = offset + (2 + len);
                    tb.Text   = s;
                    tb.Width += 200;
                } break;

                case ElementValueType.fstring:
                    tb.Text   = sr.GetStrData();
                    tb.Width += 200;
                    break;

                case ElementValueType.LString:
                {
                    uint id = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                    tb.Text = id.ToString("X8");
                    tb.Tag  = new lTag(tb, data, offset);
                    offset += data.Length;
                } break;

                default:
                    throw new ApplicationException();
                }
            }
            else
            {
                if (es.type == ElementValueType.String || es.type == ElementValueType.BString ||
                    es.type == ElementValueType.fstring || es.type == ElementValueType.LString)
                {
                    tb.Width += 200;
                }
                if (removedStrings.ContainsKey(boxes.Count - 1))
                {
                    tb.Text = removedStrings[boxes.Count - 1];
                }
            }
            Label l = new Label();

            l.AutoSize = true;
            string tmp = es.type.ToString();

            l.Text = tmp + ": " + es.name + (es.desc != null ? (" (" + es.desc + ")") : "");
            panel1.Controls.Add(tb);
            tb.Location = new System.Drawing.Point(10, ypos);
            if (es.multiline)
            {
                tb.Multiline = true;
                ypos        += tb.Height * 5;
                tb.Height   *= 6;
            }
            panel1.Controls.Add(l);
            l.Location = new System.Drawing.Point(tb.Right + 10, ypos + 3);
            string[] options = null;
            if (es.type == ElementValueType.FormID)
            {
                ypos += 28;
                Button b = new Button();
                b.Text   = "FormID lookup";
                b.Click += new EventHandler(LookupFormID_Click);
                panel1.Controls.Add(b);
                b.Location = new System.Drawing.Point(20, ypos);
                TextBox tb2 = new TextBox();
                tb2.Width   += 200;
                tb2.ReadOnly = true;
                panel1.Controls.Add(tb2);
                tb2.Location = new System.Drawing.Point(b.Right + 10, ypos);
                b.Tag        = new bTag(tb, tb2);
                if (es.FormIDType != null)
                {
                    if (cachedFormIDs.ContainsKey(es.FormIDType))
                    {
                        options = cachedFormIDs[es.FormIDType];
                    }
                    else
                    {
                        options = formIDScan(es.FormIDType);
                        cachedFormIDs[es.FormIDType] = options;
                    }
                }
            }
            else if (es.type == ElementValueType.LString)
            {
                ypos += 24;
                lTag ltag = tb.Tag as lTag;

                ltag.cb         = new CheckBox();
                ltag.cb.Width   = ltag.cb.Height;
                ltag.cb.Checked = (ltag.data.Length != 4);
                panel1.Controls.Add(ltag.cb);
                ltag.cb.Location = new System.Drawing.Point(8, ypos);

                ltag.str        = new TextBox();
                ltag.str.Width += (200 - ltag.cb.Width + 8);
                panel1.Controls.Add(ltag.str);
                ltag.str.Location = new System.Drawing.Point(ltag.cb.Location.X + ltag.cb.Width + 8, ypos);

                string s = null;
                if (strIDLookup != null)
                {
                    s = strIDLookup(uint.Parse(ltag.id.Text, System.Globalization.NumberStyles.HexNumber, null));
                }
                if (s == null)
                {
                    int i = ltag.offset;
                    while (!char.IsControl((char)data[i]))
                    {
                        s += (char)data[i++];
                    }
                }
                ltag.str.Text = s;

                ypos += 24;
            }
            else if (es.options != null)
            {
                options = es.options;
            }
            if (options != null)
            {
                ypos += 28;
                ComboBox cmb = new ComboBox();
                cmb.Tag    = tb;
                cmb.Width += 200;
                for (int j = 0; j < options.Length; j += 2)
                {
                    cmb.Items.Add(new comboBoxItem(options[j], options[j + 1]));
                }
                cmb.KeyPress             += new KeyPressEventHandler(cb_KeyPress);
                cmb.ContextMenu           = new ContextMenu();
                cmb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
                panel1.Controls.Add(cmb);
                cmb.Location = new System.Drawing.Point(20, ypos);
            }
            if (hasFlags) // add flags combo box to the side
            {
                FlagComboBox ccb = new FlagComboBox();
                ccb.Tag = tb;
                ccb.SetItems(es.flags);
                ccb.SetState(flagValue);
                ccb.TextChanged += delegate(object sender, EventArgs e)
                {
                    uint    value = ccb.GetState();
                    TextBox text  = ccb.Tag as TextBox;
                    text.Text = "0x" + value.ToString("X");
                };
                ccb.Location = new System.Drawing.Point(l.Location.X + l.Width + 10, tb.Top);
                ccb.Width    = Math.Max(ccb.Width, this.Width - 50 - (ccb.Location.X));
                ccb.Anchor   = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                panel1.Controls.Add(ccb);
            }
            fpanel1.Controls.Add(panel1);
            elements.Add(panel1);
        }
        private void AddElement(ElementStructure es, ref int offset, byte[] data, ref int groupOffset, ref int CurrentGroup)
        {
            Panel panel1 = new Panel();
            panel1.AutoSize = true;
            panel1.Width = fpanel1.Width-10;
            panel1.Height = 1;
            panel1.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            int ypos = 0;
            uint flagValue = 0; // value if flags is set
            bool hasFlags = (es.options == null && es.flags != null);

            TextBox tb = new TextBox();
            boxes.Add(tb);
            if (es.group != 0)
            {
                CheckBox cb = new CheckBox();
                cb.Text = "Use this value?";
                panel1.Controls.Add(cb);
                cb.Location = new System.Drawing.Point(10, ypos);
                ypos += 24;
                cb.Tag = new cbTag(es.group, tb);
                if (CurrentGroup != es.group) cb.Checked = true;
                else tb.Enabled = false;
                cb.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
            }
            if (es.optional || es.repeat > 0 && repeatcount > 0)
            {
                CheckBox cb = new CheckBox();
                cb.Text = "Use this value?";
                panel1.Controls.Add(cb);
                cb.Location = new System.Drawing.Point(10, ypos);
                ypos += 24;
                cb.Tag = new repeatCbTag(tb, elements.Count);
                if (data == null)
                {
                    tb.Enabled = false;
                }
                else
                {
                    cb.Checked = true;
                }
                cb.CheckedChanged += new EventHandler(RepeatCheckBox_CheckedChanged);
            }
            if ((CurrentGroup == 0 && es.group != 0) || (CurrentGroup != 0 && es.group != 0 && CurrentGroup != es.group))
            {
                CurrentGroup = es.group;
                groupOffset = offset;
            }
            else if (CurrentGroup != 0 && es.group == 0)
            {
                CurrentGroup = 0;
            }
            else if (CurrentGroup != 0 && CurrentGroup == es.group)
            {
                offset = groupOffset;
            }

            valueTypes.Add(es.type);
            if (data != null)
            {
                switch (es.type)
                {
                    case ElementValueType.UInt:
                        {
                            var v = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X8") : v.ToString();
                            offset += 4;
                        }
                        break;
                    case ElementValueType.Int:
                        {
                            var v = TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X8") : v.ToString();
                            offset += 4;
                        }
                        break;
                    case ElementValueType.FormID:
                        tb.Text = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]).ToString("X8");
                        offset += 4;
                        break;
                    case ElementValueType.Float:
                        tb.Text = TypeConverter.h2f(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]).ToString();
                        offset += 4;
                        break;
                    case ElementValueType.UShort:
                        {
                            var v = TypeConverter.h2s(data[offset], data[offset + 1]);
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X4") : v.ToString();
                            offset += 2;
                        } break;
                    case ElementValueType.Short:
                        {
                            var v = TypeConverter.h2ss(data[offset], data[offset + 1]);
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X4") : v.ToString();
                            offset += 2;
                        } break;
                    case ElementValueType.Byte:
                        {
                            var v = data[offset];
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X2") : v.ToString();
                            offset++;
                        } break;
                    case ElementValueType.SByte:
                        {
                            var v = (sbyte)data[offset];
                            flagValue = (uint)v;
                            tb.Text = hasFlags || es.hexview ? "0x" + v.ToString("X2") : v.ToString();
                            offset++;
                        } break;
                    case ElementValueType.String:
                        {
                            string s = "";
                            while (data[offset] != 0) s += (char)data[offset++];
                            offset++;
                            tb.Text = s;
                            tb.Width += 200;
                        } break;
                    case ElementValueType.BString:
                        {
                            int len = TypeConverter.h2s(data[offset], data[offset + 1]);
                            string s = System.Text.Encoding.ASCII.GetString(data, offset + 2, len);
                            offset = offset + (2 + len);
                            tb.Text = s;
                            tb.Width += 200;
                        } break;
                    case ElementValueType.fstring:
                        tb.Text = sr.GetStrData();
                        tb.Width += 200;
                        break;
                    case ElementValueType.LString:
                        {
                            uint id = TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
                            tb.Text = id.ToString("X8");
                            tb.Tag = new lTag(tb, data, offset);
                            offset += data.Length;
                        } break;
                    default:
                        throw new ApplicationException();
                }
            }
            else
            {
                if (es.type == ElementValueType.String || es.type == ElementValueType.BString
                    || es.type == ElementValueType.fstring || es.type == ElementValueType.LString)
                    tb.Width += 200;
                if (removedStrings.ContainsKey(boxes.Count - 1)) tb.Text = removedStrings[boxes.Count - 1];
            }
            Label l = new Label();
            l.AutoSize = true;
            string tmp = es.type.ToString();
            l.Text = tmp + ": " + es.name + (es.desc != null ? (" (" + es.desc + ")") : "");
            panel1.Controls.Add(tb);
            tb.Location = new System.Drawing.Point(10, ypos);
            if (es.multiline)
            {
                tb.Multiline = true;
                ypos += tb.Height * 5;
                tb.Height *= 6;
            }
            panel1.Controls.Add(l);
            l.Location = new System.Drawing.Point(tb.Right + 10, ypos + 3);
            string[] options = null;
            if (es.type == ElementValueType.FormID)
            {
                ypos += 28;
                Button b = new Button();
                b.Text = "FormID lookup";
                b.Click += new EventHandler(LookupFormID_Click);
                panel1.Controls.Add(b);
                b.Location = new System.Drawing.Point(20, ypos);
                TextBox tb2 = new TextBox();
                tb2.Width += 200;
                tb2.ReadOnly = true;
                panel1.Controls.Add(tb2);
                tb2.Location = new System.Drawing.Point(b.Right + 10, ypos);
                b.Tag = new bTag(tb, tb2);
                if (es.FormIDType != null)
                {
                    if (cachedFormIDs.ContainsKey(es.FormIDType))
                    {
                        options = cachedFormIDs[es.FormIDType];
                    }
                    else
                    {
                        options = formIDScan(es.FormIDType);
                        cachedFormIDs[es.FormIDType] = options;
                    }
                }
            }
            else if (es.type == ElementValueType.LString)
            {
                ypos += 24;
                lTag ltag = tb.Tag as lTag;

                ltag.cb = new CheckBox();
                ltag.cb.Width = ltag.cb.Height;
                ltag.cb.Checked = (ltag.data.Length != 4);
                panel1.Controls.Add(ltag.cb);
                ltag.cb.Location = new System.Drawing.Point(8, ypos);

                ltag.str = new TextBox();
                ltag.str.Width += (200 - ltag.cb.Width + 8);
                panel1.Controls.Add(ltag.str);
                ltag.str.Location = new System.Drawing.Point(ltag.cb.Location.X + ltag.cb.Width + 8, ypos);

                string s = null;
                if (strIDLookup != null)
                {
                    s = strIDLookup(uint.Parse(ltag.id.Text, System.Globalization.NumberStyles.HexNumber, null));
                }
                if (s == null)
                {
                    int i = ltag.offset;
                    while (!char.IsControl((char)data[i]))
                        s += (char)data[i++];
                }
                ltag.str.Text = s;

                ypos += 24;

            }
            else if (es.options != null)
            {
                options = es.options;
            }
            if (options != null)
            {
                ypos += 28;
                ComboBox cmb = new ComboBox();
                cmb.Tag = tb;
                cmb.Width += 200;
                for (int j = 0; j < options.Length; j += 2)
                {
                    cmb.Items.Add(new comboBoxItem(options[j], options[j + 1]));
                }
                cmb.KeyPress += new KeyPressEventHandler(cb_KeyPress);
                cmb.ContextMenu = new ContextMenu();
                cmb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
                panel1.Controls.Add(cmb);
                cmb.Location = new System.Drawing.Point(20, ypos);
            }
            if (hasFlags) // add flags combo box to the side
            {
                FlagComboBox ccb = new FlagComboBox();
                ccb.Tag = tb;
                ccb.SetItems(es.flags);
                ccb.SetState(flagValue);
                ccb.TextChanged += delegate(object sender, EventArgs e)
                {
                    uint value = ccb.GetState();
                    TextBox text = ccb.Tag as TextBox;
                    text.Text = "0x" + value.ToString("X");
                };
                ccb.Location = new System.Drawing.Point(l.Location.X + l.Width + 10, tb.Top);
                ccb.Width = Math.Max(ccb.Width, this.Width - 50 - (ccb.Location.X));
                ccb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                panel1.Controls.Add(ccb);
            }
            fpanel1.Controls.Add(panel1);
            elements.Add(panel1);
        }
示例#4
0
 private static void MatchRecordAddConditionals(Dictionary<int, Conditional> conditions, SubRecord sr, ElementStructure[] ess)
 {
     int offset = 0;
     byte[] data = sr.GetReadonlyData();
     for (int j = 0; j < ess.Length; j++)
     {
         if (ess[j].CondID != 0)
         {
             switch (ess[j].type)
             {
                 case ElementValueType.Int:
                 case ElementValueType.FormID:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.Int, TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
                     offset += 4;
                     break;
                 case ElementValueType.UInt:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.UInt, (uint)TypeConverter.h2i(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
                     offset += 4;
                     break;
                 case ElementValueType.Float:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.Float, TypeConverter.h2f(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
                     offset += 4;
                     break;
                 case ElementValueType.Short:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.Short, (int)TypeConverter.h2ss(data[offset], data[offset + 1]));
                     offset += 2;
                     break;
                 case ElementValueType.UShort:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.UShort, TypeConverter.h2s(data[offset], data[offset + 1]));
                     offset += 2;
                     break;
                 case ElementValueType.SByte:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.SByte, (sbyte)data[offset]);
                     offset++;
                     break;
                 case ElementValueType.Byte:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.Byte, (int)data[offset]);
                     offset++;
                     break;
                 case ElementValueType.String:
                     {
                         string s = "";
                         while (data[offset] != 0) s += (char)data[offset++];
                         offset++;
                         conditions[ess[j].CondID] = new Conditional(ElementValueType.String, s);
                     }
                     break;
                 case ElementValueType.fstring:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.String, sr.GetStrData());
                     break;
                 case ElementValueType.BString:
                     {
                         int len = TypeConverter.h2s(data[offset], data[offset + 1]);
                         string s = System.Text.Encoding.ASCII.GetString(data, offset + 2, len);
                         offset = offset + (2 + len);
                         conditions[ess[j].CondID] = new Conditional(ElementValueType.String, s);
                     } break;
                 case ElementValueType.LString:
                     conditions[ess[j].CondID] = new Conditional(ElementValueType.Int, TypeConverter.h2si(data[offset], data[offset + 1], data[offset + 2], data[offset + 3]));
                     offset += 4;
                     break;
                 default:
                     throw new ApplicationException();
             }
         }
         else
         {
             switch (ess[j].type)
             {
                 case ElementValueType.Int:
                 case ElementValueType.UInt:
                 case ElementValueType.FormID:
                 case ElementValueType.Float:
                     offset += 4;
                     break;
                 case ElementValueType.UShort:
                 case ElementValueType.Short:
                     offset += 2;
                     break;
                 case ElementValueType.SByte:
                 case ElementValueType.Byte:
                     offset++;
                     break;
                 case ElementValueType.String:
                     while (data[offset] != 0) offset++;
                     offset++;
                     break;
                 case ElementValueType.fstring:
                     break;
                 case ElementValueType.LString:
                     break;
                 case ElementValueType.BString:
                     int len = TypeConverter.h2s(data[offset], data[offset + 1]);
                     offset += 2 + len;
                     break;
                 default:
                     throw new ApplicationException();
             }
         }
     }
 }
 private void AddElement(ElementStructure es)
 {
     int a = -1, b = 0, c = 0;
     AddElement(es, ref a, null, ref b, ref c);
 }