(ReadAssetBundle): method moved to AssetDeserializer.

This commit is contained in:
morkt 2017-04-13 21:02:17 +04:00
parent 12c2690ae3
commit 403c769d49
2 changed files with 30 additions and 32 deletions

View File

@ -251,7 +251,7 @@ namespace GameRes.Formats.Unity
var asset_bundle = asset.Objects.FirstOrDefault (x => x.TypeId == bundle_type_id);
if (asset_bundle != null)
{
id_map = asset.ReadAssetBundle (file, asset_bundle);
id_map = ReadAssetBundle (file, asset_bundle);
}
}
if (null == id_map)
@ -290,6 +290,35 @@ namespace GameRes.Formats.Unity
}
}
Dictionary<long, string> ReadAssetBundle (Stream input, UnityObject bundle)
{
using (var reader = bundle.Open (input))
{
var name = reader.ReadString(); // m_Name
reader.Align();
int count = reader.ReadInt32(); // m_PreloadTable
for (int i = 0; i < count; ++i)
{
reader.ReadInt32(); // m_FileID
reader.ReadInt64(); // m_PathID
}
count = reader.ReadInt32(); // m_Container
var id_map = new Dictionary<long, string> (count+1);
id_map[bundle.PathId] = name;
for (int i = 0; i < count; ++i)
{
name = reader.ReadString();
reader.Align();
reader.ReadInt32(); // preloadIndex
reader.ReadInt32(); // preloadSize
reader.ReadInt32(); // m_FileID
long id = reader.ReadInt64();
id_map[id] = name;
}
return id_map;
}
}
string GetObjectName (Stream input, UnityObject obj)
{
TypeTree type;

View File

@ -130,37 +130,6 @@ namespace GameRes.Formats.Unity
throw new ApplicationException (string.Format ("Duplicate asset object {0} (PathId: {1})", obj, obj.PathId));
m_objects[obj.PathId] = obj;
}
public Dictionary<long, string> ReadAssetBundle (Stream input, UnityObject bundle)
{
using (var stream = new StreamRegion (input, bundle.Offset, bundle.Size, true))
using (var reader = new AssetReader (stream, ""))
{
reader.SetupReaders (m_format, m_is_little_endian);
var name = reader.ReadString(); // m_Name
reader.Align();
var id_map = new Dictionary<long, string>();
id_map[bundle.PathId] = name;
int count = reader.ReadInt32(); // m_PreloadTable
for (int i = 0; i < count; ++i)
{
reader.ReadInt32(); // m_FileID
reader.ReadInt64(); // m_PathID
}
count = reader.ReadInt32(); // m_Container
for (int i = 0; i < count; ++i)
{
name = reader.ReadString();
reader.Align();
reader.ReadInt32(); // preloadIndex
reader.ReadInt32(); // preloadSize
reader.ReadInt32(); // m_FileID
long id = reader.ReadInt64();
id_map[id] = name;
}
return id_map;
}
}
}
internal class AssetRef