Esempio n. 1
0
        private void bCShort_Click(object sender, EventArgs e)
        {
            short s;

            if (!short.TryParse(tbFloat.Text, out s))
            {
                MessageBox.Show("Invalid word");
                return;
            }
            byte[] b   = TypeConverter.ss2h(s);
            var    pos = (int)hexBox1.SelectionStart;

            bytes[pos + 0] = b[0];
            bytes[pos + 1] = b[1];
            hexBox1.Refresh();
        }
Esempio n. 2
0
        private void bSave_Click(object sender, EventArgs e)
        {
            var bytes = new List <byte>();

            for (int j = 0; j < boxes.Count; j++)
            {
                var          vt       = valueTypes[j];
                string       tbText   = boxes[j].Text;
                NumberStyles numStyle = NumberStyles.Any;
                if (tbText.StartsWith("0x"))
                {
                    numStyle = NumberStyles.HexNumber;
                    tbText   = tbText.Substring(2);
                }
                if (!boxes[j].Enabled)
                {
                    continue;
                }
                switch (vt)
                {
                case ElementValueType.Byte:
                {
                    byte b;
                    if (!byte.TryParse(tbText, numStyle, null, out b))
                    {
                        MessageBox.Show("Invalid byte: " + tbText, "Error");
                        return;
                    }
                    bytes.Add(b);
                    break;
                }

                case ElementValueType.Short:
                {
                    short s;
                    if (!short.TryParse(tbText, numStyle, null, out s))
                    {
                        MessageBox.Show("Invalid short: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.ss2h(s);
                    bytes.Add(conv[0]);
                    bytes.Add(conv[1]);
                    break;
                }

                case ElementValueType.UShort:
                {
                    ushort s;
                    if (!ushort.TryParse(tbText, numStyle, null, out s))
                    {
                        MessageBox.Show("Invalid ushort: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.s2h(s);
                    bytes.Add(conv[0]);
                    bytes.Add(conv[1]);
                    break;
                }

                case ElementValueType.Int:
                {
                    int i;
                    if (!int.TryParse(tbText, numStyle, null, out i))
                    {
                        MessageBox.Show("Invalid int: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.si2h(i);
                    bytes.AddRange(conv);
                    break;
                }

                case ElementValueType.UInt:
                {
                    uint i;
                    if (!uint.TryParse(tbText, numStyle, null, out i))
                    {
                        MessageBox.Show("Invalid uint: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.i2h(i);
                    bytes.AddRange(conv);
                    break;
                }

                case ElementValueType.Float:
                {
                    float f;
                    if (!float.TryParse(tbText, numStyle, null, out f))
                    {
                        MessageBox.Show("Invalid float: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.f2h(f);
                    bytes.AddRange(conv);
                    break;
                }

                case ElementValueType.FormID:
                {
                    uint i;
                    if (!uint.TryParse(tbText, NumberStyles.AllowHexSpecifier, null, out i))
                    {
                        MessageBox.Show("Invalid formID: " + tbText, "Error");
                        return;
                    }
                    byte[] conv = TypeConverter.i2h(i);
                    bytes.AddRange(conv);
                    break;
                }

                case ElementValueType.String:
                {
                    byte[] conv = System.Text.Encoding.Default.GetBytes(tbText);
                    bytes.AddRange(conv);
                    bytes.Add(0);
                    break;
                }

                case ElementValueType.BString:
                {
                    bytes.AddRange(TypeConverter.s2h((ushort)tbText.Length));
                    bytes.AddRange(System.Text.Encoding.Default.GetBytes(tbText));
                    break;
                }

                case ElementValueType.IString:
                {
                    bytes.AddRange(TypeConverter.si2h(tbText.Length));
                    bytes.AddRange(System.Text.Encoding.Default.GetBytes(tbText));
                    break;
                }

                case ElementValueType.LString:
                {
                    uint i;
                    var  ltag = boxes[j].Tag as lTag;
                    if (ltag != null)
                    {
                        if (!ltag.cb.Checked)
                        {
                            if (!uint.TryParse(ltag.id.Text, NumberStyles.AllowHexSpecifier, null, out i))
                            {
                                MessageBox.Show("Invalid string id: " + ltag.id.Text, "Error");
                                return;
                            }
                            byte[] conv = TypeConverter.i2h(i);
                            bytes.AddRange(conv);
                        }
                        else
                        {
                            byte[] conv = System.Text.Encoding.Default.GetBytes(ltag.str.Text);
                            bytes.AddRange(conv);
                            bytes.Add(0);
                        }
                    }
                    break;
                }

                case ElementValueType.Str4:
                {
                    var txtbytes = new byte[] { 0x32, 0x32, 0x32, 0x32 };
                    System.Text.Encoding.Default.GetBytes(tbText, 0, Math.Min(4, tbText.Length), txtbytes, 0);
                    bytes.AddRange(txtbytes);
                }
                break;

                default:
                    throw new ApplicationException();
                }
            }
            sr.SetData(bytes.ToArray());
            Close();
        }
Esempio n. 3
0
        private void bSave_Click(object sender, EventArgs e)
        {
            bSave.Focus();
            uint flags, datestamp;

            if (!uint.TryParse(tbDateStamp.Text, NumberStyles.AllowHexSpecifier, null, out datestamp))
            {
                tbDateStamp.Focus();
                MessageBox.Show("Invalid value specified for datestamp");
                return;
            }
            if (!uint.TryParse(tbFlags.Text, NumberStyles.AllowHexSpecifier, null, out flags))
            {
                tbFlags.Focus();
                MessageBox.Show("Invalid value specified for flags");
                return;
            }
            var grouptype = (uint)cmbGroupType.SelectedIndex;

            byte[] data;
            switch (cmbGroupType.SelectedIndex)
            {
            case 0:
                if (tbRecType.TextLength != 4)
                {
                    tbRecType.Focus();
                    MessageBox.Show("Invalid parent record type. Needs to be 4 characters!");
                    return;
                }
                data = new byte[4];
                Encoding.CP1252.GetBytes(tbRecType.Text, 0, 4, data, 0);
                break;

            case 2:
            case 3:
                uint block;
                if (!uint.TryParse(tbBlock.Text, out block))
                {
                    tbBlock.Focus();
                    MessageBox.Show("Invalid value specified for block id");
                    return;
                }
                data = TypeConverter.i2h(block);
                break;

            case 4:
            case 5:
                short x, y;
                if (!short.TryParse(tbX.Text, out x))
                {
                    tbX.Focus();
                    MessageBox.Show("Invalid value specified for x coord");
                    return;
                }
                if (!short.TryParse(tbY.Text, out y))
                {
                    tbY.Focus();
                    MessageBox.Show("Invalid value specified for y coord");
                    return;
                }
                data = new byte[4];
                TypeConverter.ss2h(x, data, 2);
                TypeConverter.ss2h(y, data, 0);
                break;

            case 1:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                uint parent;
                if (!uint.TryParse(tbParent.Text, NumberStyles.AllowHexSpecifier, null, out parent))
                {
                    tbParent.Focus();
                    MessageBox.Show("Invalid value specified for parent");
                    return;
                }
                data = TypeConverter.i2h(parent);
                break;

            default:
                cmbGroupType.Focus();
                MessageBox.Show("Sanity check failed; invalid group type");
                return;
            }
            gr.flags     = flags;
            gr.dateStamp = datestamp;
            gr.groupType = grouptype;
            gr.SetData(data);
            gr.UpdateShortDescription();
            this.DialogResult = DialogResult.OK;
        }
Esempio n. 4
0
        private void bSave_Click(object sender, EventArgs e)
        {
            uint flags, datestamp;

            if (!uint.TryParse(tbDateStamp.Text, NumberStyles.AllowHexSpecifier, null, out datestamp))
            {
                MessageBox.Show("Invalid value specified for datestamp");
                return;
            }
            if (!uint.TryParse(tbFlags.Text, NumberStyles.AllowHexSpecifier, null, out flags))
            {
                MessageBox.Show("Invalid value specified for flags");
                return;
            }
            var grouptype = (uint)cmbGroupType.SelectedIndex;

            byte[] data;
            switch (cmbGroupType.SelectedIndex)
            {
            case 0:
                data = Encoding.CP1252.GetBytes(tbRecType.Text);
                break;

            case 2:
            case 3:
                uint block;
                if (!uint.TryParse(tbBlock.Text, out block))
                {
                    MessageBox.Show("Invalid value specified for block id");
                    return;
                }
                data = TypeConverter.i2h(block);
                break;

            case 4:
            case 5:
                short x, y;
                if (!short.TryParse(tbX.Text, out x))
                {
                    MessageBox.Show("Invalid value specified for x coord");
                    return;
                }
                if (!short.TryParse(tbY.Text, out y))
                {
                    MessageBox.Show("Invalid value specified for y coord");
                    return;
                }
                data = new byte[4];
                TypeConverter.ss2h(x, data, 2);
                TypeConverter.ss2h(y, data, 0);
                break;

            case 1:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                uint parent;
                if (!uint.TryParse(tbParent.Text, NumberStyles.AllowHexSpecifier, null, out parent))
                {
                    MessageBox.Show("Invalid value specified for parent");
                    return;
                }
                data = TypeConverter.i2h(parent);
                break;

            default:
                MessageBox.Show("Sanity check failed; invalid group type");
                return;
            }
            gr.flags     = flags;
            gr.dateStamp = datestamp;
            gr.groupType = grouptype;
            gr.SetData(data);
        }