Пример #1
0
        /*
         * public TypeTree(TypeTree parent, uint format, int version, bool isArray, int size, int index, int flags, string type, string name)
         * {
         *  this.parent = parent;
         *  this.format = format;
         *
         *  this.version = version;
         *  this.isArray = isArray;
         *  this.size = size;
         *  this.index = index;
         *  this.flags = flags;
         *  this.type = type;
         *  this.name = name;
         * }
         */

        public static TypeTreeNode ReadTypeTree(uint format, ExtendedBinaryReader buf)
        {
            TypeTreeNode root = new TypeTreeNode();

            if (format == 10 || format >= 12)
            {
                int nodesCount        = buf.ReadInt32();
                int stringBufferBytes = buf.ReadInt32();

                int nodesize = format >= 19 ? 32 : 24;

                buf.BaseStream.Seek(nodesize * nodesCount, SeekOrigin.Current);
                byte[] stringData = buf.ReadBytes(stringBufferBytes);
                buf.BaseStream.Seek(-(nodesize * nodesCount + stringBufferBytes), SeekOrigin.Current);

                Stack <TypeTreeNode> stack = new Stack <TypeTreeNode>();

                stack.Push(root);

                using (var stringReader = new ExtendedBinaryReader(new MemoryStream(stringData)))
                {
                    for (int i = 0; i < nodesCount; i++)
                    {
                        short version = buf.ReadInt16();
                        byte  depth   = buf.ReadByte();

                        bool isArray = buf.ReadBoolean();

                        ushort typeIndex = buf.ReadUInt16();
                        string typeStr;
                        if (buf.ReadUInt16() == 0)
                        {
                            stringReader.BaseStream.Position = typeIndex;
                            typeStr = stringReader.ReadNullTerminatedString();
                        }
                        else
                        {
                            typeStr = baseStrings.ContainsKey(typeIndex) ? baseStrings[typeIndex] : typeIndex.ToString();
                        }

                        ushort nameIndex = buf.ReadUInt16();
                        string nameStr;
                        if (buf.ReadUInt16() == 0)
                        {
                            stringReader.BaseStream.Position = nameIndex;
                            nameStr = stringReader.ReadNullTerminatedString();
                        }
                        else
                        {
                            nameStr = baseStrings.ContainsKey(nameIndex) ? baseStrings[nameIndex] : nameIndex.ToString();
                        }

                        int   size        = buf.ReadInt32();
                        int   index       = buf.ReadInt32();
                        int   flags       = buf.ReadInt32();
                        ulong refTypeHash = 0;

                        if (format >= 19)
                        {
                            refTypeHash = buf.ReadUInt64();
                        }

                        TypeTreeNode t;
                        if (depth == 0)
                        {
                            t = root;
                        }
                        else
                        {
                            while (stack.Count > depth)
                            {
                                stack.Pop();
                            }
                            t = new TypeTreeNode();
                            stack.Peek().children.Add(t);
                            stack.Push(t);
                        }

                        t.version     = version;
                        t.isArray     = isArray;
                        t.type        = typeStr;
                        t.name        = nameStr;
                        t.size        = size;
                        t.index       = index;
                        t.flags       = flags;
                        t.refTypeHash = refTypeHash;
                    }
                }

                buf.BaseStream.Seek(stringBufferBytes, SeekOrigin.Current);
            }
            else
            {
                root.type    = buf.ReadNullTerminatedString();
                root.name    = buf.ReadNullTerminatedString();
                root.size    = buf.ReadInt32();
                root.index   = buf.ReadInt32();
                root.isArray = buf.ReadBoolean();
                root.version = buf.ReadInt32();
                root.flags   = buf.ReadInt32();

                int childCount = buf.ReadInt32();
                for (int i = 0; i < childCount; i++)
                {
                    root.children.Add(TypeTreeNode.ReadTypeTree(format, buf));
                }
            }

            return(root);
        }
Пример #2
0
        public TypeMetaData(uint format, ExtendedBinaryReader buf)
        {
            if (format >= 13)
            {
                hasTypeTrees = buf.ReadBoolean();

                int types_count = buf.ReadInt32();

                for (int i = 0; i < types_count; i++)
                {
                    int classID = buf.ReadInt32();
                    int scriptID;

                    if (format >= 17)
                    {
                        byte unk0 = buf.ReadByte();
                        scriptID = -1 - buf.ReadInt16();
                    }
                    else
                    {
                        scriptID = classID;
                    }

                    ClassIDs.Add(new ClassInfo {
                        scriptID = scriptID, classID = classID
                    });

                    byte[] hash;
                    if ((format < 16 && classID < 0) || (format >= 16 && classID == 114))
                    {
                        hash = buf.ReadBytes(0x20);
                    }
                    else
                    {
                        hash = buf.ReadBytes(0x10);
                    }

                    Hashes[classID] = hash;

                    if (hasTypeTrees)
                    {
                        TypeTrees.Add(classID, TypeTreeNode.ReadTypeTree(format, buf));

                        if (format >= 21)
                        {
                            int dependenciesCount = buf.ReadInt32();
                            var TypeDependencies  = (int[])buf.ReadValueArray <int>(dependenciesCount);
                        }
                    }
                }
            }
            else
            {
                int fieldsCount = buf.ReadInt32();
                for (int i = 0; i < fieldsCount; i++)
                {
                    int classID = buf.ReadInt32();
                    TypeTrees.Add(classID, TypeTreeNode.ReadTypeTree(format, buf));
                }
            }
        }