Exemple #1
0
        public MediumLevelRecordEditor(SubRecord sr, SubrecordStructure ss, dFormIDLookupS formIDLookup, dFormIDScan formIDScan, dLStringLookup strIDLookup)
        {
            InitializeComponent();
            this.Icon = Properties.Resources.tesv_ico;
            SuspendLayout();
            this.sr           = sr;
            this.ss           = ss;
            this.formIDLookup = formIDLookup;
            this.formIDScan   = formIDScan;
            this.strIDLookup  = strIDLookup;

            int offset = 0;

            byte[] data = sr.GetReadonlyData();
            boxes      = new List <TextBox>(ss.elements.Length);
            valueTypes = new List <ElementValueType>(ss.elements.Length);
            elements   = new List <Panel>();
            int groupOffset  = 0;
            int CurrentGroup = 0;

            try
            {
                for (int i = 0; i < ss.elements.Length; i++)
                {
                    if (ss.elements[i].optional && offset == data.Length)
                    {
                        AddElement(ss.elements[i]);
                    }
                    else
                    {
                        AddElement(ss.elements[i], ref offset, data, ref groupOffset, ref CurrentGroup);
                        if (ss.elements[i].repeat > 0)
                        {
                            repeatcount++;
                            if (offset < data.Length)
                            {
                                i--;
                            }
                        }
                    }
                }
                if (ss.elements[ss.elements.Length - 1].repeat > 0 && repeatcount > 0)
                {
                    AddElement(ss.elements[ss.elements.Length - 1]);
                }
            }
            catch
            {
                MessageBox.Show("The subrecord doesn't appear to conform to the expected structure.\n" +
                                "Saving is disabled, and the formatted information may be incorrect", "Warning");
                bSave.Enabled = false;
            }
            ResumeLayout();
        }
        public MediumLevelRecordEditor(SubRecord sr, SubrecordStructure ss, dFormIDLookupS formIDLookup, dFormIDScan formIDScan, dLStringLookup strIDLookup)
        {
            InitializeComponent();
            this.Icon = Properties.Resources.tesv_ico;
            SuspendLayout();
            this.sr = sr;
            this.ss = ss;
            this.formIDLookup = formIDLookup;
            this.formIDScan = formIDScan;
            this.strIDLookup = strIDLookup;

            int offset = 0;
            byte[] data = sr.GetReadonlyData();
            boxes = new List<TextBox>(ss.elements.Length);
            valueTypes = new List<ElementValueType>(ss.elements.Length);
            elements = new List<Panel>();
            int groupOffset = 0;
            int CurrentGroup = 0;
            try
            {
                for (int i = 0; i < ss.elements.Length; i++)
                {
                    if (ss.elements[i].optional && offset == data.Length)
                    {
                        AddElement(ss.elements[i]);
                    }
                    else
                    {
                        AddElement(ss.elements[i], ref offset, data, ref groupOffset, ref CurrentGroup);
                        if (ss.elements[i].repeat > 0)
                        {
                            repeatcount++;
                            if (offset < data.Length) i--;
                        }
                    }
                }
                if (ss.elements[ss.elements.Length - 1].repeat > 0 && repeatcount > 0)
                {
                    AddElement(ss.elements[ss.elements.Length - 1]);
                }
            }
            catch
            {
                MessageBox.Show("The subrecord doesn't appear to conform to the expected structure.\n" +
                    "Saving is disabled, and the formatted information may be incorrect", "Warning");
                bSave.Enabled = false;
            }
            ResumeLayout();
        }
Exemple #3
0
        private static bool MatchRecordCheckCondition(Dictionary<int, Conditional> conditions, SubrecordStructure ss)
        {
            if (ss.Condition == CondType.Exists)
            {
                if (conditions.ContainsKey(ss.CondID)) return true;
                else return false;
            }
            else if (ss.Condition == CondType.Missing)
            {
                if (conditions.ContainsKey(ss.CondID)) return false;
                else return true;
            }
            if (!conditions.ContainsKey(ss.CondID)) return false;
            Conditional cond = conditions[ss.CondID];
            switch (cond.type)
            {
                case ElementValueType.SByte:
                case ElementValueType.Byte:
                case ElementValueType.UShort:
                case ElementValueType.Short:
                case ElementValueType.Int:
                case ElementValueType.UInt:
                case ElementValueType.FormID:
                    {
                        int i = Convert.ToInt32(cond.value), i2;
                        if (!int.TryParse(ss.CondOperand, out i2)) return false;
                        switch (ss.Condition)
                        {
                            case CondType.Equal: return i == i2;
                            case CondType.Not: return i != i2;
                            case CondType.Less: return i < i2;
                            case CondType.Greater: return i > i2;
                            case CondType.GreaterEqual: return i >= i2;
                            case CondType.LessEqual: return i <= i2;
                            default: return false;
                        }
                    }
                case ElementValueType.Float:
                    {
                        float i = (float)cond.value, i2;
                        if (!float.TryParse(ss.CondOperand, out i2)) return false;
                        switch (ss.Condition)
                        {
                            case CondType.Equal: return i == i2;
                            case CondType.Not: return i != i2;
                            case CondType.Less: return i < i2;
                            case CondType.Greater: return i > i2;
                            case CondType.GreaterEqual: return i >= i2;
                            case CondType.LessEqual: return i <= i2;
                            default: return false;
                        }
                    }
                case ElementValueType.fstring:
                case ElementValueType.BString:
                case ElementValueType.String:
                    {
                        string s = (string)cond.value;
                        switch (ss.Condition)
                        {
                            case CondType.Equal: return s == ss.CondOperand;
                            case CondType.Not: return s != ss.CondOperand;
                            case CondType.StartsWith: return s.StartsWith(ss.CondOperand);
                            case CondType.EndsWith: return s.EndsWith(ss.CondOperand);
                            case CondType.Contains: return s.Contains(ss.CondOperand);
                            default: return false;
                        }
                    }
                case ElementValueType.LString:
                    {
                        int i = (int)cond.value, i2;
                        if (!int.TryParse(ss.CondOperand, out i2)) return false;
                        switch (ss.Condition)
                        {
                            case CondType.Equal: return i == i2;
                            case CondType.Not: return i != i2;
                            case CondType.Less: return i < i2;
                            case CondType.Greater: return i > i2;
                            case CondType.GreaterEqual: return i >= i2;
                            case CondType.LessEqual: return i <= i2;
                            default: return false;
                        }
                    }

                default: return false;
            }
        }