示例#1
0
        private static TreeViewItem GenerateValueNode(BINValue value, bool createFieldProperty = true)
        {
            TreeViewItem entryNode = new TreeViewItem();

            if (IsPrimitiveValue(value.Type.Value))
            {
                entryNode.Header = ProcessPrimitiveValue(value, createFieldProperty);
            }
            else if (value.Type == BINValueType.Container)
            {
                entryNode.Header = BINGlobal.GetField(value.Property);

                foreach (TreeViewItem node in ProcessContainer(value))
                {
                    entryNode.Items.Add(node);
                }
            }
            else if (value.Type == BINValueType.Structure || value.Type == BINValueType.Embedded)
            {
                entryNode.Header = "";

                if (createFieldProperty)
                {
                    entryNode.Header += BINGlobal.GetField(value.Property) + " : ";
                }

                entryNode.Header += BINGlobal.GetClass((value.Value as BINStructure).Property);

                foreach (TreeViewItem node in ProcessStructure(value))
                {
                    entryNode.Items.Add(node);
                }
            }
            else if (value.Type == BINValueType.Map)
            {
                entryNode.Header = BINGlobal.GetField(value.Property);

                foreach (TreeViewItem node in ProcessMap(value))
                {
                    entryNode.Items.Add(node);
                }
            }
            else if (value.Type == BINValueType.Optional)
            {
                entryNode.Header = BINGlobal.GetField(value.Property);
            }

            else if (value.Type == BINValueType.Container2)
            {
                entryNode.Header = BINGlobal.GetField(value.Property);
            }

            return(entryNode);
        }
示例#2
0
        private static List <TreeViewItem> ProcessStructure(BINValue value)
        {
            BINStructure        structure = value.Value as BINStructure;
            List <TreeViewItem> nodes     = new List <TreeViewItem>();

            foreach (BINValue structureValue in structure.Values)
            {
                nodes.Add(GenerateValueNode(structureValue));
            }

            return(nodes);
        }
示例#3
0
        private static List <TreeViewItem> ProcessContainer(BINValue value)
        {
            BINContainer        container = value.Value as BINContainer;
            List <TreeViewItem> nodes     = new List <TreeViewItem>();

            foreach (BINValue containerValue in container.Values)
            {
                nodes.Add(GenerateValueNode(containerValue, false));
            }

            return(nodes);
        }
示例#4
0
        private static object Serialize(List <BINValue> values, Type type)
        {
            object   constructedClass     = Activator.CreateInstance(type);
            TypeInfo constructedClassInfo = constructedClass.GetType().GetTypeInfo();

            foreach (PropertyInfo propertyInfo in constructedClassInfo.GetProperties())
            {
                uint     propertyHash = GetValueAttributeHash(propertyInfo);
                BINValue value        = values.Find(x => x.Property == propertyHash);

                if (value != null)
                {
                    if (IsPrimitiveType(value.Type.Value))
                    {
                        propertyInfo.SetValue(constructedClass, value.Value);
                    }
                    else if (value.Type == BINValueType.Hash)
                    {
                        propertyInfo.SetValue(constructedClass, new Hash((uint)value.Value));
                    }
                    else if (value.Type == BINValueType.LinkOffset)
                    {
                        Type   linkType = typeof(Link <>).MakeGenericType(propertyInfo.PropertyType.GenericTypeArguments[0]);
                        object link     = Activator.CreateInstance(linkType, new object[] { (uint)value.Value });

                        propertyInfo.SetValue(constructedClass, link);
                    }
                    else if (value.Type == BINValueType.Optional)
                    {
                        Type   optionalType = typeof(Optional <>).MakeGenericType(propertyInfo.PropertyType.GenericTypeArguments[0]);
                        object optional     = Activator.CreateInstance(optionalType, new object[] { SerializeOptional(value, propertyInfo) });

                        propertyInfo.SetValue(constructedClass, optional);
                    }
                    else if (value.Type == BINValueType.Structure || value.Type == BINValueType.Embedded)
                    {
                        propertyInfo.SetValue(constructedClass, SerializeStructure(value));
                    }
                    else if (value.Type == BINValueType.Container)
                    {
                        propertyInfo.SetValue(constructedClass, SerializeContainer(value, propertyInfo));
                    }
                    else if (value.Type == BINValueType.Map)
                    {
                        propertyInfo.SetValue(constructedClass, SerializeMap(value, propertyInfo));
                    }
                }
            }


            return(constructedClass);
        }
示例#5
0
        private static object SerializeStructure(BINValue value)
        {
            BINStructure structure = value.Value as BINStructure;

            if (_classMap.ContainsKey(structure.Property))
            {
                return(Serialize(structure.Values, _classMap[structure.Property]));
            }
            else
            {
                return(null);
            }
        }
示例#6
0
        private static IEnumerable <string> ProcessBINValue(BINValue value)
        {
            List <string> strings = new List <string>();

            if (value.Type == BINValueType.String)
            {
                string valueString = value.Value as string;
                strings.Add(valueString);

                if ((valueString.StartsWith("ASSETS/", true, null) || valueString.StartsWith("LEVELS/", true, null)) && Path.GetExtension(valueString) == ".dds")
                {
                    int index = valueString.LastIndexOf('/');
                    strings.Add(valueString.Insert(index + 1, "2x_"));
                    strings.Add(valueString.Insert(index + 1, "4x_"));
                }

                if (value.Property == Cryptography.FNV32Hash("mapPath"))
                {
                    strings.Add("DATA/" + valueString + ".materials.bin");
                    strings.Add("DATA/" + valueString + ".mapgeo");
                }
            }
            else if (value.Type == BINValueType.Optional)
            {
                strings.AddRange(ProcessBINAdditionalData(value.Value as BINOptional));
            }
            else if (value.Type == BINValueType.Container)
            {
                strings.AddRange(ProcessBINContainer(value.Value as BINContainer));
            }
            else if (value.Type == BINValueType.Embedded || value.Type == BINValueType.Structure)
            {
                strings.AddRange(ProcessBINStructure(value.Value as BINStructure));
            }
            else if (value.Type == BINValueType.Map)
            {
                strings.AddRange(ProcessBINMap(value.Value as BINMap));
            }

            return(strings);
        }
示例#7
0
        private static object SerializeMap(BINValue value, PropertyInfo propertyInfo)
        {
            BINMap   map                = value.Value as BINMap;
            object   constructedMap     = Activator.CreateInstance(propertyInfo.PropertyType);
            TypeInfo constructedMapInfo = constructedMap.GetType().GetTypeInfo();

            foreach (KeyValuePair <BINValue, BINValue> pair in map.Values)
            {
                object pairKey   = map.KeyType == BINValueType.Hash ? new Hash((uint)pair.Key.Value) : pair.Key.Value;
                object pairValue = null;

                if (IsPrimitiveType(map.ValueType))
                {
                    pairValue = pair.Value.Value;
                }
                else if (map.ValueType == BINValueType.Hash)
                {
                    pairValue = new Hash((uint)pair.Value.Value);
                }
                else if (map.ValueType == BINValueType.LinkOffset)
                {
                    Type linkType = propertyInfo.PropertyType.GenericTypeArguments[1];
                    pairValue = Activator.CreateInstance(linkType, new object[] { (uint)pair.Value.Value });
                }
                else if (map.ValueType == BINValueType.Structure || map.ValueType == BINValueType.Embedded)
                {
                    pairValue = SerializeStructure(pair.Value);
                }
                else if (map.ValueType == BINValueType.Container)
                {
                    pairValue = SerializeContainer(value, propertyInfo);
                }

                constructedMapInfo.GetMethod("Add").Invoke(constructedMap, new[] { pairKey, pairValue });
            }

            return(constructedMap);
        }
示例#8
0
        private static object SerializeContainer(BINValue value, PropertyInfo propertyInfo)
        {
            BINContainer container           = value.Value as BINContainer;
            object       constructedList     = Activator.CreateInstance(propertyInfo.PropertyType);
            TypeInfo     constructedListInfo = constructedList.GetType().GetTypeInfo();

            if (IsPrimitiveType(container.EntryType))
            {
                foreach (BINValue containerValue in container.Values)
                {
                    constructedListInfo.GetMethod("Add").Invoke(constructedList, new[] { containerValue.Value });
                }
            }
            else if (container.EntryType == BINValueType.Embedded || container.EntryType == BINValueType.Structure)
            {
                foreach (BINValue containerValue in container.Values)
                {
                    constructedListInfo.GetMethod("Add").Invoke(constructedList, new[] { SerializeStructure(containerValue) });
                }
            }

            return(constructedList);
        }
示例#9
0
        private static object SerializeOptional(BINValue value, PropertyInfo propertyInfo)
        {
            BINOptional optional            = value.Value as BINOptional;
            object      constructedOptional = null;

            if (optional.Value != null)
            {
                if (IsPrimitiveType(optional.Type))
                {
                    constructedOptional = optional.Value.Value;
                }
                else if (value.Type == BINValueType.Hash)
                {
                    constructedOptional = new Hash((uint)optional.Value.Value);
                }
                else if (value.Type == BINValueType.LinkOffset)
                {
                    Type linkType = typeof(Link <>).MakeGenericType(propertyInfo.PropertyType.GenericTypeArguments[0]);
                    constructedOptional = Activator.CreateInstance(linkType, new object[] { (uint)value.Value });
                }
                else if (value.Type == BINValueType.Structure || value.Type == BINValueType.Embedded)
                {
                    constructedOptional = SerializeStructure(optional.Value);
                }
                else if (value.Type == BINValueType.Container)
                {
                    constructedOptional = SerializeContainer(optional.Value, propertyInfo);
                }
                else if (value.Type == BINValueType.Map)
                {
                    constructedOptional = SerializeMap(optional.Value, propertyInfo);
                }
            }

            return(constructedOptional);
        }
示例#10
0
        private static List <TreeViewItem> ProcessMap(BINValue value)
        {
            BINMap map = value.Value as BINMap;
            List <TreeViewItem> nodes = new List <TreeViewItem>();

            foreach (KeyValuePair <BINValue, BINValue> pair in map.Values)
            {
                TreeViewItem node = new TreeViewItem()
                {
                    Header = ProcessKeyValue(pair.Key)
                };

                if (map.ValueType != BINValueType.Structure && map.ValueType != BINValueType.Embedded)
                {
                    node.Header += " => " + (ProcessPrimitiveValue(pair.Value, false).Children[0] as TextBlock).Text;
                }
                else
                {
                    BINStructure structure = pair.Value.Value as BINStructure;
                    node.Header += " : " + BINGlobal.GetClass(structure.Property);

                    foreach (TreeViewItem structureNode in ProcessStructure(pair.Value))
                    {
                        node.Items.Add(structureNode);
                    }
                }

                nodes.Add(node);
            }

            return(nodes);

            string ProcessKeyValue(BINValue keyValue)
            {
                if (map.KeyType == BINValueType.Byte)
                {
                    return(((byte)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt16)
                {
                    return(((ushort)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt32)
                {
                    return(((uint)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.UInt64)
                {
                    return(((ulong)keyValue.Value).ToString());
                }
                else if (map.KeyType == BINValueType.String)
                {
                    return((string)keyValue.Value);
                }
                else if (map.KeyType == BINValueType.StringHash)
                {
                    return(((uint)keyValue.Value).ToString());
                }
                else
                {
                    return("");
                }
            }
        }
示例#11
0
        private static StackPanel ProcessPrimitiveValue(BINValue value, bool createFieldProperty = true)
        {
            StackPanel stackPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            if (createFieldProperty)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text   = BINGlobal.GetField(value.Property),
                    Margin = new Thickness(0, 0, 15, 0)
                });
            }

            if (value.Type == BINValueType.Boolean)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((bool)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.SByte)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((sbyte)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.Byte)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((byte)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.Int16)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((short)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.UInt16)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((ushort)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.Int32)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((int)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.UInt32)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((uint)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.Int64)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((long)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.UInt64)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((ulong)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.Float)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((float)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.FloatVector2)
            {
                Vector2 vector = value.Value as Vector2;

                stackPanel.Children.Add(new TextBlock()
                {
                    Text = string.Format("[ {0}, {1} ]", vector.X, vector.Y)
                });
            }
            else if (value.Type == BINValueType.FloatVector3)
            {
                Vector3 vector = value.Value as Vector3;

                stackPanel.Children.Add(new TextBlock()
                {
                    Text = string.Format("[ {0}, {1}, {2} ]", vector.X, vector.Y, vector.Z)
                });
            }
            else if (value.Type == BINValueType.FloatVector4)
            {
                Vector4 vector = value.Value as Vector4;

                stackPanel.Children.Add(new TextBlock()
                {
                    Text = string.Format("[ {0}, {1}, {2}, {3} ]", vector.X, vector.Y, vector.Z, vector.W)
                });
            }
            else if (value.Type == BINValueType.Matrix44)
            {
                R3DMatrix44 matrix = value.Value as R3DMatrix44;

                stackPanel.Children.Add(new TextBlock()
                {
                    Text = string.Format("[ {0}, {1}, {2}, {3} ]\n", matrix.M11, matrix.M12, matrix.M13, matrix.M14) +
                           string.Format("[ {0}, {1}, {2}, {3} ]\n", matrix.M21, matrix.M22, matrix.M23, matrix.M24) +
                           string.Format("[ {0}, {1}, {2}, {3} ]\n", matrix.M31, matrix.M32, matrix.M33, matrix.M34) +
                           string.Format("[ {0}, {1}, {2}, {3} ]", matrix.M41, matrix.M42, matrix.M43, matrix.M44)
                });
            }
            else if (value.Type == BINValueType.Color)
            {
                ColorRGBAVector4Byte color = value.Value as ColorRGBAVector4Byte;

                stackPanel.Children.Add(new TextBlock()
                {
                    Text = string.Format("[ {0}, {1}, {2}, {3} ]", color.R, color.G, color.B, color.A)
                });
            }
            else if (value.Type == BINValueType.String)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = (string)value.Value
                });
            }
            else if (value.Type == BINValueType.StringHash)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((uint)value.Value).ToString()
                });
            }
            else if (value.Type == BINValueType.LinkOffset)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = BINGlobal.GetEntry((uint)value.Value)
                });
            }
            else if (value.Type == BINValueType.FlagsBoolean)
            {
                stackPanel.Children.Add(new TextBlock()
                {
                    Text = ((bool)value.Value).ToString()
                });
            }

            return(stackPanel);
        }