Пример #1
0
        private static VLTBaseType CloneObjectWithReflection(VLTBaseType originalValue, VLTBaseType newValue, VltClass vltClass, VltClassField vltClassField,
                                                             VltCollection vltCollection)
        {
            PropertyInfo[] properties = originalValue.GetType()
                                        .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                        .Where(p => p.SetMethod?.IsPublic ?? false)
                                        .ToArray();

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType.IsSubclassOf(typeof(VLTBaseType)))
                {
                    propertyInfo.SetValue(newValue, CloneObjectWithReflection(
                                              propertyInfo.GetValue(originalValue) as VLTBaseType,
                                              Activator.CreateInstance(propertyInfo.PropertyType, vltClass, vltClassField, vltCollection) as
                                              VLTBaseType,
                                              vltClass, vltClassField, vltCollection));
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(newValue, new string(propertyInfo.GetValue(originalValue) as string));
                }
                else if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType.IsEnum)
                {
                    propertyInfo.SetValue(newValue, propertyInfo.GetValue(originalValue));
                }
                else if (propertyInfo.PropertyType.IsArray && propertyInfo.GetValue(originalValue) != null)
                {
                    propertyInfo.SetValue(newValue, ((Array)propertyInfo.GetValue(originalValue)).Clone());
                }
            }

            return(newValue);
        }
Пример #2
0
        private void tvFields_AfterSelect(object A_0, TreeViewEventArgs A_1)
        {
            object tag = A_1.Node.Tag;

            if (tag is VLTBaseType && !(tag is VLTArrayType))
            {
                VLTBaseType bb = tag as VLTBaseType;
                //bb.l(); // MW: TODO: What is l() supposed to be?
                DataSet   dataSet   = new DataSet("DataItem");
                DataTable dataTable = dataSet.Tables.Add("Values");
                dataTable.Columns.Add("Name", typeof(string));
                dataTable.Columns.Add("Value", typeof(string));
                Type        type   = bb.GetType();
                FieldInfo[] fields = type.GetFields();
                foreach (FieldInfo fieldInfo in fields)
                {
                    object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(DataValueAttribute), false);
                    if (customAttributes != null && customAttributes.Length == 1 && customAttributes[0] is DataValueAttribute)
                    {
                        DataValueAttribute dataValueAttribute = customAttributes[0] as DataValueAttribute;
                        DataRow            dataRow            = dataTable.NewRow();
                        dataRow[0] = dataValueAttribute.Name;
                        object value = fieldInfo.GetValue(bb);
                        if (value == null)
                        {
                            dataRow[1] = "(null)";
                        }
                        else
                        {
                            if (dataValueAttribute.Hex)
                            {
                                dataRow[1] = string.Format("0x{0:x}", value);
                            }
                            else
                            {
                                dataRow[1] = value.ToString();
                            }
                        }
                        dataTable.Rows.Add(dataRow);
                    }
                }
                this.dataGrid.DataSource = dataSet;
                this.dataGrid.DataMember = "Values";

                // This gets rid of the extra row in the table that appears when viewing a sub-node (e.x. junkman --> default)
                CurrencyManager currencyManager = (CurrencyManager)this.BindingContext[dataSet, "Values"];
                ((DataView)currencyManager.List).AllowNew    = false;
                ((DataView)currencyManager.List).AllowEdit   = false;
                ((DataView)currencyManager.List).AllowDelete = false;

                this.lblFieldType.Text = "Type: " + HashTracker.getValueForHash(bb.typeHash);
                if (BuildConfig.DEBUG)
                {
                    this.writeToConsole("bb.GetType(): " + type.ToString());                       // Here, we're getting the proper type! Great!
                    this.writeToConsole("bb.j(): " + string.Format("0x{0:x}", bb.typeHash));       // Here, we're derping! OMG!
                }
                UnknownBA ba   = bb.dr1.b01.a(VLTOtherValue.VLTMAGIC) as UnknownBA;
                string    text = ba.sa1[0];
                this.lblFieldOffset.Text = string.Format("Offset: {0}:0x{1:x}  ({2})", bb.isVltOffset ? "vlt" : "bin", bb.ui1, text);
                this.dataGrid.Update();
            }
            else
            {
                this.lblFieldType.Text   = "";
                this.lblFieldOffset.Text = "";
                this.dataGrid.DataSource = null;
                this.dataGrid.Update();
            }
        }
Пример #3
0
        private void tvFields_AfterSelect(object sender, TreeViewEventArgs e)
        {
            object tag = e.Node.Tag;

            if (tag is VLTBaseType && !(tag is VLTArrayType))
            {
                VLTBaseType bb = tag as VLTBaseType;
                //bb.l(); // MW: TODO: What is l() supposed to be?
                DataSet   dataSet   = new DataSet("DataItem");
                DataTable dataTable = dataSet.Tables.Add("Values");
                dataTable.Columns.Add("Name", typeof(string));
                dataTable.Columns.Add("Value", typeof(string));
                Type        type   = bb.GetType();
                FieldInfo[] fields = type.GetFields();
                foreach (FieldInfo fieldInfo in fields)
                {
                    object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(DataValueAttribute), false);
                    if (customAttributes != null && customAttributes.Length == 1 && customAttributes[0] is DataValueAttribute)
                    {
                        DataValueAttribute dataValueAttribute = customAttributes[0] as DataValueAttribute;
                        DataRow            dataRow            = dataTable.NewRow();
                        dataRow[0] = dataValueAttribute.Name;
                        object value = fieldInfo.GetValue(bb);
                        if (value == null)
                        {
                            dataRow[1] = "(null)";
                        }
                        else
                        {
                            if (dataValueAttribute.Hex)
                            {
                                dataRow[1] = string.Format("0x{0:x}", value);
                            }
                            else
                            {
                                dataRow[1] = value.ToString();
                            }
                        }
                        dataTable.Rows.Add(dataRow);
                    }
                }
                this.dataGrid.DataSource = dataSet;
                this.dataGrid.DataMember = "Values";

                this.lblFieldType.Text = "Type: " + HashTracker.getValueForHash(bb.typeHash);

                /*
                 * if( BuildConfig.DEBUG )
                 * {
                 *      this.writeToConsole( "bb.GetType(): " + type.ToString() ); // Here, we're getting the proper type! Great!
                 *      this.writeToConsole( "bb.j(): " + string.Format( "0x{0:x}", bb.ui2 ) ); // Here, we're derping! OMG!
                 * }*/
                UnknownBA ba   = bb.dr1.b01.a(VLTOtherValue.VLTMAGIC) as UnknownBA;
                string    text = ba.sa1[0];
                this.lblFieldOffset.Text = string.Format("Offset: {0}:0x{1:x}  ({2})", bb.isVltOffset ? "vlt" : "bin", bb.ui1, text);
                this.dataGrid.Update();
            }
            else
            {
                this.lblFieldType.Text   = "";
                this.lblFieldOffset.Text = "";
                this.dataGrid.DataSource = null;
                this.dataGrid.Update();
            }
        }