示例#1
0
        public void WriteParams(System.Xml.XmlWriter writer, Dictionary <HavokClassNode, int> classNodes)
        {
            writer.WriteStartElement("hkobject");
            {
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "name");
                writer.WriteString(Name);
                writer.WriteEndElement();

                HavokClassNode c = string.IsNullOrEmpty(_class) ? null : HavokNode.GetClassNode(_class);
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "class");
                writer.WriteString(c != null ? HavokXML.GetObjectName(classNodes, c) : "null");
                writer.WriteEndElement();

                HavokClassNode e = string.IsNullOrEmpty(_enum) ? null : HavokNode.GetClassNode(_enum);
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "enum");
                writer.WriteString(e != null ? HavokXML.GetObjectName(classNodes, e) : "null");
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "type");
                string type = Type.ToString();
                if (type == "TYPE_CSTRING")
                {
                    type = "TYPE_STRINGPTR";
                }

                writer.WriteString(type);
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "subtype");
                writer.WriteString(SubType.ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "cArraySize");
                writer.WriteString(ArraySize.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "flags");
                writer.WriteString(((int)Flags).ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "offset");
                writer.WriteString(OffsetInStruct.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteComment(" attributes SERIALIZE_IGNORED ");
            }
            writer.WriteEndElement();
        }
        public override void OnPopulate()
        {
            hkVariant *    v         = (hkVariant *)Data;
            hkClass *      classData = (hkClass *)v->_classPtr.OffsetAddress;
            HavokClassNode entry     = HavokNode.GetClassNode(new String((sbyte *)classData->_namePtr.OffsetAddress), true);

            if (entry != null)
            {
                new HavokMetaObjectNode(entry as hkClassNode)
                .Initialize(this, v->_objectPtr.OffsetAddress, classData->_size);
            }
        }
示例#3
0
        public override bool OnInitialize()
        {
            if (_classNode == null)
            {
                return(false);
            }

            _className = _classNode.Name;

            HavokNode node = HavokNode;

            if (node._allSignatures.ContainsKey(_className))
            {
                _signature = HavokNode._allSignatures[_className];
            }

            node._dataSection._classCache.Add(this);

            if (_name == null)
            {
                _name = _classNode.Name;
            }

            _memberArray = new List <hkClassMemberNode>();

            //Youngest class has size for all inherited classes included
            if (_classNode._inheritance.Count > 0)
            {
                SetSizeInternal(_classNode._inheritance[0].Size);
            }

            foreach (hkClassNode c in _classNode._inheritance)
            {
                ResourceNode members = c.FindChild("Members", false);
                if (members != null)
                {
                    _memberArray.AddRange(members.Children.Select(x => x as hkClassMemberNode));
                }
            }

            return(_memberArray != null && _memberArray.Count > 0);
        }
示例#4
0
        public static void Serialize(HavokNode node, string outFile)
        {
            using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None,
                                                      0x1000, FileOptions.SequentialScan))
            {
                using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
                {
                    writer.Flush();
                    stream.Position = 0;

                    node.Populate();

                    Dictionary <HavokClassNode, int> classIDs = new Dictionary <HavokClassNode, int>();
                    int i = 1;
                    foreach (HavokSectionNode s in node.Children)
                    {
                        foreach (HavokClassNode c in s._classCache)
                        {
                            if (!classIDs.ContainsKey(c))
                            {
                                classIDs.Add(c, i++);
                            }
                        }
                    }

                    //RecursiveGetClassIDsData(ref classIDs, node, node._dataSection);

                    HavokClassNode          rootClass = node._dataSection.Children[0] as HavokClassNode;
                    List <HavokSectionNode> sections  =
                        node.Children.Select(x => x as HavokSectionNode)
                        .Where(x => x != node._dataSection).ToList();
                    sections.Add(node._dataSection);

                    writer.WriteStartDocument();
                    {
                        writer.WriteStartElement("hkpackfile");
                        writer.WriteAttributeString("classversion", "11");
                        writer.WriteAttributeString("contentsversion", "hk_2014.1.0-r1");
                        writer.WriteAttributeString("toplevelobject", GetObjectName(classIDs, rootClass));
                        writer.WriteAttributeString("maxpredicate", "21");
                        writer.WriteAttributeString("predicates", "");
                        {
                            foreach (HavokSectionNode s in sections)
                            {
                                writer.WriteStartElement("hksection");
                                writer.WriteAttributeString("name", s.Name == "Classes" ? "__types__" : "__data__");
                                {
                                    for (int x = s._classCache.Count - 1; x >= 0; x--)
                                    {
                                        HavokClassNode c = s._classCache[x];

                                        //HavokCommonArrayNode array = null;
                                        //if (c.Parent is cmPointerNode && c.Parent.Parent is HavokCommonArrayNode)
                                        //    array = c.Parent.Parent as HavokCommonArrayNode;
                                        //else if  (c.Parent is HavokCommonArrayNode)
                                        //    array = c.Parent as HavokCommonArrayNode;
                                        //if (array != null)
                                        //{
                                        //    //ResourceNode[] nodes = array.FindChildrenByClassType(null, typeof(HavokMetaObjectNode));
                                        //    //if (nodes != null && nodes.Length > 0)
                                        //        continue;
                                        //}

                                        writer.WriteStartElement("hkobject");
                                        writer.WriteAttributeString("name", GetObjectName(classIDs, c));
                                        writer.WriteAttributeString("class", SwapName(c._className));
                                        writer.WriteAttributeString("signature", GetSignature(c._className));
                                        {
                                            c.WriteParams(writer, classIDs);
                                        }
                                        writer.WriteEndElement();
                                    }
                                }
                                writer.WriteEndElement();
                            }
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndDocument();
                }
            }
        }
示例#5
0
        private static void RecursiveGetClassIDsClasses(ref Dictionary <HavokClassNode, int> classIDs, HavokNode node,
                                                        ResourceNode e)
        {
            if (e is hkClassNode)
            {
                hkClassNode type = e as hkClassNode;
                if (!string.IsNullOrEmpty(type.ParentClass))
                {
                    HavokClassNode c = node.GetClassNode(type.ParentClass);
                    classIDs.Add(c, classIDs.Count + 1);
                }

                ResourceNode members = type.FindChild("Members", false);
                foreach (hkClassMemberNode member in members.Children)
                {
                    if (!string.IsNullOrEmpty(member._class))
                    {
                        HavokClassNode c = node.GetClassNode(member._class);
                        classIDs.Add(c, classIDs.Count + 1);
                    }

                    if (!string.IsNullOrEmpty(member._enum))
                    {
                        HavokClassNode c = node.GetClassNode(member._enum);
                        classIDs.Add(c, classIDs.Count + 1);
                    }
                }

                if (!classIDs.ContainsKey(type))
                {
                    classIDs.Add(type, classIDs.Count + 1);
                }
            }
        }
示例#6
0
        private static void RecursiveGetClassIDsData(ref Dictionary <HavokClassNode, int> classIDs, HavokNode node,
                                                     ResourceNode e)
        {
            if (e is HavokMetaObjectNode || e is hkClassNode)
            {
                HavokClassNode data = e as HavokClassNode;
                HavokClassNode type = node.GetClassNode(data._className);
                RecursiveGetClassIDsClasses(ref classIDs, node, type);
                classIDs.Add(data, classIDs.Count + 1);
            }

            for (int i = e.Children.Count - 1; i >= 0; i--)
            {
                RecursiveGetClassIDsData(ref classIDs, node, e.Children[i]);
            }
        }
示例#7
0
        public void GetInheritance()
        {
            _inheritance = new List <hkClassNode>();
            ResourceNode current = this;

            //First, get classes inheriting this one
TOP:
            bool found = false;

            if (current != null)
            {
                foreach (HavokSectionNode section in HavokNode.Children)
                {
                    if (section._classCache != null && section != HavokNode._dataSection)
                    {
                        foreach (HavokClassNode c in section._classCache)
                        {
                            hkClassNode x = c as hkClassNode;
                            if (x != null && x != this && x.ParentClass == current.Name)
                            {
                                current = x;
                                _inheritance.Insert(0, x);
                                found = true;
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
            }
            if (found)
            {
                goto TOP;
            }

            current = this;

            //Now add this class and the classes it inherits
            while (current != null && current is hkClassNode)
            {
                hkClassNode cNode = (hkClassNode)current;

                _inheritance.Add(cNode);

                if (HavokNode.AssignClassParents)
                {
                    current = current.Parent;
                }
                else if (!String.IsNullOrEmpty(cNode.ParentClass))
                {
                    current = null;
                    HavokClassNode parent = HavokNode.GetClassNode(cNode.ParentClass);
                    if (parent is hkClassNode)
                    {
                        current = parent;
                    }
                }
            }

            //Start with the eldest class, added last
            _inheritance.Reverse();
        }
示例#8
0
        public override void OnPopulate()
        {
            VoidPtr addr = WorkingUncompressed.Address;

            foreach (hkClassMemberNode member in _memberArray)
            {
                hkClassMember.Type type = member.Type;
                bool zero = type == hkClassMember.Type.TYPE_ZERO;
                if (zero)
                {
                    type = member.SubType;
                }

                hkClassNode     memberClass = null;
                hkClassEnumNode memberEnum  = null;

                if (!string.IsNullOrEmpty(member._class))
                {
                    HavokClassNode c = HavokNode.GetClassNode(member._class);
                    if (c is hkClassNode)
                    {
                        memberClass = c as hkClassNode;
                    }

                    if (memberClass == null)
                    {
                        Console.WriteLine("Could not find " + member._class + " class");
                    }
                }

                if (!string.IsNullOrEmpty(member._enum))
                {
                    //Loop through inheritance starting with the eldest class, added last
                    foreach (hkClassNode c in _classNode._inheritance)
                    {
                        ResourceNode enums = c.FindChild("Enums", false);
                        if (enums != null)
                        {
                            foreach (hkClassEnumNode e in enums.Children)
                            {
                                if (e.Name == member._enum)
                                {
                                    memberEnum = e;
                                    break;
                                }
                            }
                        }
                    }

                    if (memberEnum == null)
                    {
                        Console.WriteLine("Could not find " + member._enum + " enum in " + _classNode.Name + " class");
                    }
                }

                ClassMemberInstanceNode instance = TryGetMember(type);
                if (instance != null)
                {
                    switch (type)
                    {
                    case hkClassMember.Type.TYPE_SIMPLEARRAY:
                    case hkClassMember.Type.TYPE_ARRAY:
                    case hkClassMember.Type.TYPE_INPLACEARRAY:
                    case hkClassMember.Type.TYPE_HOMOGENEOUSARRAY:
                    case hkClassMember.Type.TYPE_POINTER:
                    case hkClassMember.Type.TYPE_FUNCTIONPOINTER:
                        type = member.SubType;
                        break;
                    }

                    instance._isZero      = zero;
                    instance._name        = member._name;
                    instance._memberType  = type;
                    instance._memberFlags = member._flags;
                    instance._classNode   = memberClass;
                    instance._enumNode    = memberEnum;

                    instance.Initialize(this, addr + member._structOffset, instance.GetSize());
                }
            }
        }