Ejemplo n.º 1
0
        private void LoadTxdRelationships(RbfStructure rbfstruct)
        {
            TxdRelationships = new Dictionary <string, string>();
            //StringBuilder sblist = new StringBuilder();
            foreach (var child in rbfstruct.Children)
            {
                var childstruct = child as RbfStructure;
                if ((childstruct != null) && (childstruct.Name == "txdRelationships"))
                {
                    foreach (var txdrel in childstruct.Children)
                    {
                        var txdrelstruct = txdrel as RbfStructure;
                        if ((txdrelstruct != null) && (txdrelstruct.Name == "item"))
                        {
                            string parentstr = string.Empty;
                            string childstr  = string.Empty;
                            foreach (var item in txdrelstruct.Children)
                            {
                                var itemstruct = item as RbfStructure;
                                if ((itemstruct != null))
                                {
                                    var    strbytes = itemstruct.Children[0] as RbfBytes;
                                    string thisstr  = string.Empty;
                                    if (strbytes != null)
                                    {
                                        thisstr = Encoding.ASCII.GetString(strbytes.Value).Replace("\0", "");
                                    }
                                    switch (item.Name)
                                    {
                                    case "parent":
                                        parentstr = thisstr;
                                        break;

                                    case "child":
                                        childstr = thisstr;
                                        break;
                                    }
                                }
                            }
                            if ((!string.IsNullOrEmpty(parentstr)) && (!string.IsNullOrEmpty(childstr)))
                            {
                                if (!TxdRelationships.ContainsKey(childstr))
                                {
                                    TxdRelationships.Add(childstr, parentstr);
                                }
                                else
                                {
                                }
                                //sblist.AppendLine(childstr + ": " + parentstr);
                            }
                        }
                    }
                }
            }
            //string alltxdmap = sblist.ToString();
            //if (!string.IsNullOrEmpty(alltxdmap))
            //{
            //}
        }
Ejemplo n.º 2
0
        private void ParseElement(DataReader reader, int descriptorIndex, byte dataType)
        {
            var descriptor = descriptors[descriptorIndex];

            switch (dataType)
            {
            case 0:     // open element...
            {
                var structureValue = new RbfStructure();
                structureValue.Name = descriptor.Name;

                if (current != null)
                {
                    current.AddChild(structureValue);
                    stack.Push(current);
                }

                current = structureValue;

                var x1 = reader.ReadInt16();
                var x2 = reader.ReadInt16();
                current.PendingAttributes = reader.ReadInt16();
                break;
            }

            case 0x10:
            {
                var intValue = new RbfUint32();
                intValue.Name  = descriptor.Name;
                intValue.Value = reader.ReadUInt32();
                current.AddChild(intValue);
                break;
            }

            case 0x20:
            {
                var booleanValue = new RbfBoolean();
                booleanValue.Name  = descriptor.Name;
                booleanValue.Value = true;
                current.AddChild(booleanValue);
                break;
            }

            case 0x30:
            {
                var booleanValue = new RbfBoolean();
                booleanValue.Name  = descriptor.Name;
                booleanValue.Value = false;
                current.AddChild(booleanValue);
                break;
            }

            case 0x40:
            {
                var floatValue = new RbfFloat();
                floatValue.Name  = descriptor.Name;
                floatValue.Value = reader.ReadSingle();
                current.AddChild(floatValue);
                break;
            }

            case 0x50:
            {
                var floatVectorValue = new RbfFloat3();
                floatVectorValue.Name = descriptor.Name;
                floatVectorValue.X    = reader.ReadSingle();
                floatVectorValue.Y    = reader.ReadSingle();
                floatVectorValue.Z    = reader.ReadSingle();
                current.AddChild(floatVectorValue);
                break;
            }

            case 0x60:
            {
                var valueLength = reader.ReadInt16();
                var valueBytes  = reader.ReadBytes(valueLength);
                var value       = Encoding.ASCII.GetString(valueBytes);
                var stringValue = new RbfString();
                stringValue.Name  = descriptor.Name;
                stringValue.Value = value;
                current.AddChild(stringValue);
                break;
            }

            default:
                throw new Exception("Unsupported data type.");
            }
        }
Ejemplo n.º 3
0
        private static IRbfType Traverse(XNode node)
        {
            if (node is XElement element)
            {
                if (element.Attribute("value") != null)
                {
                    var val = element.Attribute("value").Value;
                    if (!string.IsNullOrEmpty(val))
                    {
                        var rval = CreateValueNode(element.Name.LocalName, val);
                        if (rval != null)
                        {
                            return(rval);
                        }
                    }
                }
                else if ((element.Attributes().Count() == 3) && (element.Attribute("x") != null) && (element.Attribute("y") != null) && (element.Attribute("z") != null))
                {
                    FloatUtil.TryParse(element.Attribute("x").Value, out float x);
                    FloatUtil.TryParse(element.Attribute("y").Value, out float y);
                    FloatUtil.TryParse(element.Attribute("z").Value, out float z);
                    return(new RbfFloat3()
                    {
                        Name = element.Name.LocalName,
                        X = x,
                        Y = y,
                        Z = z
                    });
                }
                else if ((element.Elements().Count() == 0) && (element.Attributes().Count() == 0) && (!element.IsEmpty)) //else if (element.Name == "type" || element.Name == "key" || element.Name == "platform")
                {
                    var bytearr   = Encoding.ASCII.GetBytes(element.Value);
                    var bytearrnt = new byte[bytearr.Length + 1];
                    Buffer.BlockCopy(bytearr, 0, bytearrnt, 0, bytearr.Length);
                    var bytes = new RbfBytes()
                    {
                        Value = bytearrnt
                    };
                    var struc = new RbfStructure()
                    {
                        Name = element.Name.LocalName
                    };
                    struc.Children.Add(bytes);
                    return(struc);
                }

                var n = new RbfStructure();
                n.Name     = element.Name.LocalName;
                n.Children = element.Nodes().Select(c => Traverse(c)).ToList();

                foreach (var attr in element.Attributes())
                {
                    var val  = attr.Value;
                    var aval = CreateValueNode(attr.Name.LocalName, val);
                    if (aval != null)
                    {
                        n.Attributes.Add(aval);
                    }
                }

                return(n);
            }
            else if (node is XText text)
            {
                byte[] bytes       = null;
                var    contentAttr = node.Parent?.Attribute("content");
                if (contentAttr != null)
                {
                    if (contentAttr.Value == "char_array")
                    {
                        bytes = GetByteArray(text.Value);
                    }
                    else if (contentAttr.Value == "short_array")
                    {
                        bytes = GetUshortArray(text.Value);
                    }
                    else
                    {
                    }
                }
                else
                {
                    bytes = Encoding.ASCII.GetBytes(text.Value).Concat(new byte[] { 0x00 }).ToArray();
                }
                if (bytes != null)
                {
                    return(new RbfBytes()
                    {
                        Name = "",
                        Value = bytes
                    });
                }
            }

            return(null);
        }