예제 #1
0
파일: Asset.cs 프로젝트: zxc120/GARbro
        object[] DeserializeArray(AssetReader input, int length, TypeTree elem)
        {
            var array = new object[length];

            for (int i = 0; i < length; ++i)
            {
                array[i] = DeserializeType(input, elem);
            }
            return(array);
        }
예제 #2
0
파일: Asset.cs 프로젝트: zxc120/GARbro
        public void Load(AssetReader reader)
        {
            int format = reader.Format;

            m_version = reader.ReadCString();
            var platform = reader.ReadInt32();

            if (format >= 13)
            {
                bool has_type_trees = reader.ReadBool();
                int  count          = reader.ReadInt32();
                for (int i = 0; i < count; ++i)
                {
                    int class_id = reader.ReadInt32();
                    if (format >= 17)
                    {
                        reader.ReadByte();
                        int script_id = reader.ReadInt16();
                        if (114 == class_id)
                        {
                            if (script_id >= 0)
                            {
                                class_id = -2 - script_id;
                            }
                            else
                            {
                                class_id = -1;
                            }
                        }
                    }
                    m_class_ids.Add(class_id);
                    byte[] hash = reader.ReadBytes(class_id < 0 ? 0x20 : 0x10);
                    m_hashes[class_id] = hash;
                    if (has_type_trees)
                    {
                        var tree = new TypeTree(format);
                        tree.Load(reader);
                        m_type_trees[class_id] = tree;
                    }
                }
            }
            else
            {
                int count = reader.ReadInt32();
                for (int i = 0; i < count; ++i)
                {
                    int class_id = reader.ReadInt32();
                    var tree     = new TypeTree(format);
                    tree.Load(reader);
                    m_type_trees[class_id] = tree;
                }
            }
        }
예제 #3
0
파일: Asset.cs 프로젝트: zxc120/GARbro
        void LoadRaw(AssetReader reader)
        {
            Type    = reader.ReadCString();
            Name    = reader.ReadCString();
            Size    = reader.ReadInt32();
            Index   = reader.ReadUInt32();
            IsArray = reader.ReadInt32() != 0;
            Version = reader.ReadInt32();
            Flags   = reader.ReadInt32();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                var child = new TypeTree(m_format);
                child.Load(reader);
                Children.Add(child);
            }
        }
예제 #4
0
파일: Asset.cs 프로젝트: zxc120/GARbro
        void LoadBlob(AssetReader reader)
        {
            int count        = reader.ReadInt32();
            int buffer_bytes = reader.ReadInt32();
            var node_data    = reader.ReadBytes(24 * count);

            m_data = reader.ReadBytes(buffer_bytes);

            var parents = new Stack <TypeTree>();

            parents.Push(this);
            using (var buf = new BinMemoryStream(node_data))
            {
                for (int i = 0; i < count; ++i)
                {
                    int      version = buf.ReadInt16();
                    int      depth   = buf.ReadUInt8();
                    TypeTree current;
                    if (0 == depth)
                    {
                        current = this;
                    }
                    else
                    {
                        while (parents.Count > depth)
                        {
                            parents.Pop();
                        }
                        current = new TypeTree(m_format);
                        parents.Peek().Children.Add(current);
                        parents.Push(current);
                    }
                    current.Version = version;
                    current.IsArray = buf.ReadUInt8() != 0;
                    current.Type    = GetString(buf.ReadInt32());
                    current.Name    = GetString(buf.ReadInt32());
                    current.Size    = buf.ReadInt32();
                    current.Index   = buf.ReadUInt32();
                    current.Flags   = buf.ReadInt32();
                }
            }
        }
예제 #5
0
파일: Asset.cs 프로젝트: zxc120/GARbro
        object DeserializeType(AssetReader input, TypeTree node)
        {
            object obj = null;

            if (node.IsArray)
            {
                int size       = input.ReadInt32();
                var data_field = node.Children.FirstOrDefault(n => n.Name == "data");
                if (data_field != null)
                {
                    if ("TypelessData" == node.Type)
                    {
                        obj = input.ReadBytes(size * data_field.Size);
                    }
                    else
                    {
                        obj = DeserializeArray(input, size, data_field);
                    }
                }
            }
            else if (node.Size < 0)
            {
                if (node.Type == "string")
                {
                    obj = input.ReadString();
                    if (node.Children[0].IsAligned)
                    {
                        input.Align();
                    }
                }
                else if (node.Type == "StreamingInfo")
                {
                    var info = new StreamingInfo();
                    info.Load(input);
                    obj = info;
                }
                else
                {
                    throw new NotImplementedException("Unknown class encountered in asset deserialzation.");
                }
            }
            else if ("int" == node.Type)
            {
                obj = input.ReadInt32();
            }
            else if ("unsigned int" == node.Type)
            {
                obj = input.ReadUInt32();
            }
            else if ("bool" == node.Type)
            {
                obj = input.ReadBool();
            }
            else
            {
                input.Position += node.Size;
            }
            if (node.IsAligned)
            {
                input.Align();
            }
            return(obj);
        }