コード例 #1
0
ファイル: Asset.cs プロジェクト: zxc120/GARbro
 public void Load(AssetReader reader)
 {
     PathId = reader.ReadId();
     Offset = reader.ReadUInt32() + Asset.DataOffset;
     Size   = reader.ReadUInt32();
     if (Asset.Format < 17)
     {
         TypeId  = reader.ReadInt32();
         ClassId = reader.ReadInt16();
     }
     else
     {
         var type_id  = reader.ReadInt32();
         var class_id = Asset.Tree.ClassIds[type_id];
         TypeId  = class_id;
         ClassId = class_id;
     }
     if (Asset.Format <= 10)
     {
         IsDestroyed = reader.ReadInt16() != 0;
     }
     if (Asset.Format >= 11 && Asset.Format < 17)
     {
         reader.ReadInt16();
     }
     if (Asset.Format >= 15 && Asset.Format < 17)
     {
         reader.ReadByte();
     }
 }
コード例 #2
0
ファイル: Asset.cs プロジェクト: x132321/GARbro
        public void Load(AssetReader input)
        {
            input.ReadInt32();  // header_size
            input.ReadUInt32(); // file_size
            m_format      = input.ReadInt32();
            m_data_offset = input.ReadUInt32();
            if (m_format >= 9)
            {
                m_is_little_endian = 0 == input.ReadInt32();
            }
            if (m_format >= 22)
            {
                input.ReadInt32();  // header_size
                input.ReadInt64();  // file_size
                m_data_offset = input.ReadInt64();
                input.ReadInt64();
            }
            input.SetupReaders(this);
            m_tree.Load(input);

            bool long_ids = Format >= 14;

            if (Format >= 7 && Format < 14)
            {
                long_ids = 0 != input.ReadInt32();
            }
            input.SetupReadId(long_ids);

            int obj_count = input.ReadInt32();

            for (int i = 0; i < obj_count; ++i)
            {
                input.Align();
                var obj = new UnityObject(this);
                obj.Load(input);
                RegisterObject(obj);
            }
            if (Format >= 11)
            {
                int count = input.ReadInt32();
                m_adds = new Dictionary <long, int> (count);
                for (int i = 0; i < count; ++i)
                {
                    input.Align();
                    var id = input.ReadId();
                    m_adds[id] = input.ReadInt32();
                }
            }
            if (Format >= 6)
            {
                int count = input.ReadInt32();
                m_refs = new List <AssetRef> (count);
                for (int i = 0; i < count; ++i)
                {
                    var asset_ref = AssetRef.Load(input);
                    m_refs.Add(asset_ref);
                }
            }
            input.ReadCString();
        }
コード例 #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
        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);
        }
コード例 #5
0
 public void Load(AssetReader reader)
 {
     Offset = reader.ReadUInt32();
     Size   = reader.ReadUInt32();
     Path   = reader.ReadString();
 }
コード例 #6
0
        public List <Entry> Parse(AssetReader input)
        {
            var asset = new Asset();

            asset.Load(input);
            var dir = new List <Entry>();

            m_bundles = new Dictionary <string, BundleEntry>();
            var used_names = new HashSet <string>();

            foreach (var obj in asset.Objects.Where(o => o.TypeId > 0))
            {
                input.Position = obj.Offset;
                AssetEntry entry = null;
                switch (obj.TypeId)
                {
                default:
                    break;

                case 28: // Texture2D
                {
                    var tex = new Texture2D();
                    tex.Load(input);
                    if (0 == tex.m_DataLength)
                    {
                        if (asset.Tree.Version.StartsWith("2017."))      // "2017.2.0f3" || "2017.1.1p1"
                        {
                            input.ReadInt64();
                        }
                        var stream_data = new StreamingInfo();
                        stream_data.Load(input);
                        if (!string.IsNullOrEmpty(stream_data.Path))
                        {
                            entry = new AssetEntry {
                                Name   = tex.m_Name,
                                Type   = "image",
                                Offset = stream_data.Offset,
                                Size   = stream_data.Size,
                                Bundle = GetBundle(stream_data.Path),
                            };
                        }
                    }
                    else
                    {
                        entry = new AssetEntry {
                            Name   = tex.m_Name,
                            Type   = "image",
                            Offset = obj.Offset,
                            Size   = obj.Size,
                        };
                    }
                    break;
                }

                case 83: // AudioClip
                {
                    var clip = new AudioClip();
                    clip.Load(input);
                    if (!string.IsNullOrEmpty(clip.m_Source))
                    {
                        entry = new AssetEntry {
                            Name   = clip.m_Name,
                            Type   = "audio",
                            Offset = clip.m_Offset,
                            Size   = (uint)clip.m_Size,
                            Bundle = GetBundle(clip.m_Source),
                        };
                    }
                    break;
                }

                case 49:  // TextAsset
                {
                    var name = input.ReadString();
                    input.Align();
                    uint size = input.ReadUInt32();
                    entry = new AssetEntry {
                        Name   = name,
                        Offset = input.Position,
                        Size   = size,
                    };
                    if (name.HasAnyOfExtensions("jpg", "png"))
                    {
                        entry.Type = "image";
                    }
                    break;
                }

                case 128: // Font
                {
                    entry = new AssetEntry {
                        Offset = obj.Offset,
                        Size   = obj.Size,
                    };
                    break;
                }
                }
                if (entry != null)
                {
                    entry.AssetObject = obj;
                    if (string.IsNullOrEmpty(entry.Name))
                    {
                        entry.Name = string.Format("{0:D4} [{1}]", obj.PathId, obj.TypeId);
                    }
                    else if (!used_names.Add(entry.Name))
                    {
                        entry.Name = string.Format("{0}-{1}", entry.Name, obj.PathId);
                    }
                    dir.Add(entry);
                }
            }
            return(dir);
        }
コード例 #7
0
ファイル: ArcASSET.cs プロジェクト: minhrg/GARbro
        public List <Entry> Parse(AssetReader input)
        {
            var asset = new Asset();

            asset.Load(input);
            var dir = new List <Entry>();

            m_bundles = new Dictionary <string, BundleEntry>();
            var used_names = new HashSet <string>();

            foreach (var obj in asset.Objects.Where(o => o.TypeId > 0))
            {
                input.Position = obj.Offset;
                AssetEntry entry = null;
                switch (obj.TypeId)
                {
                default:
                    break;

                case 28: // Texture2D
                {
                    var tex = new Texture2D();
                    tex.Load(input);
                    if (tex.m_StreamData != null && !string.IsNullOrEmpty(tex.m_StreamData.Path))
                    {
                        entry = new AssetEntry {
                            Name   = tex.m_Name,
                            Type   = "image",
                            Offset = tex.m_StreamData.Offset,
                            Size   = tex.m_StreamData.Size,
                            Bundle = GetBundle(tex.m_StreamData.Path),
                        };
                    }
                    break;
                }

                case 83: // AudioClip
                {
                    var clip = new AudioClip();
                    clip.Load(input);
                    if (!string.IsNullOrEmpty(clip.m_Source))
                    {
                        entry = new AssetEntry {
                            Name   = clip.m_Name,
                            Type   = "audio",
                            Offset = clip.m_Offset,
                            Size   = (uint)clip.m_Size,
                            Bundle = GetBundle(clip.m_Source),
                        };
                    }
                    break;
                }

                case 49:  // TextAsset
                {
                    var name = input.ReadString();
                    input.Align();
                    uint size = input.ReadUInt32();
                    entry = new AssetEntry {
                        Name   = name,
                        Offset = input.Position,
                        Size   = size,
                    };
                    break;
                }

                case 128: // Font
                {
                    entry = new AssetEntry {
                        Offset = obj.Offset,
                        Size   = obj.Size,
                    };
                    break;
                }
                }
                if (entry != null)
                {
                    entry.AssetObject = obj;
                    if (string.IsNullOrEmpty(entry.Name))
                    {
                        entry.Name = string.Format("{0:D4} [{1}]", obj.PathId, obj.TypeId);
                    }
                    else if (!used_names.Add(entry.Name))
                    {
                        entry.Name = string.Format("{0}-{1}", entry.Name, obj.PathId);
                    }
                    dir.Add(entry);
                }
            }
            return(dir);
        }