AssetEntry ReadTextAsset(Stream input, UnityObject obj) { var script = obj.Type.Children.FirstOrDefault(f => f.Name == "m_Script"); if (null == script) { return(null); } using (var reader = obj.Open(input)) { var name = reader.ReadString(); reader.Align(); uint size = reader.ReadUInt32(); var entry = new AssetEntry { AssetObject = obj, Offset = obj.Offset + reader.Position, Size = size, IsEncrypted = 0 != (script.Flags & 0x04000000), }; if (entry.IsEncrypted) { uint signature = reader.ReadUInt32(); if (0x0D15F641 == signature) { entry.Type = "image"; } else if (0x474E5089 == signature) { entry.Type = "image"; entry.IsEncrypted = false; } } return(entry); } }
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); }
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); }