public IEnumerable <AssetFile> BuildAssetsFileInstance(Stream stream) { List <AssetFile> result = new List <AssetFile>(); classPackage = new ClassDatabasePackage(); Console.WriteLine("Reading class-data..."); using (var reader = new AssetsFileReader(new FileStream("classdata.tpk", FileMode.Open, FileAccess.Read, FileShare.Read))) { classPackage.Read(reader); } var file = new AssetBundleFile(); activeBundleFile = file; Console.WriteLine("Reading bundleFileStream..."); file.Read(new AssetsFileReader(stream), true); file.reader.Position = 0; Stream memoryStream = new MemoryStream(); Console.WriteLine("Unpacking bundleFile..."); file.Unpack(file.reader, new AssetsFileWriter(memoryStream)); memoryStream.Position = 0; file.Close(); file = new AssetBundleFile(); file.Read(new AssetsFileReader(memoryStream)); Console.WriteLine("file.bundleInf6.dirInf.Length: " + file.bundleInf6.dirInf.Length); for (int i = 0; i < file.bundleInf6.dirInf.Length; i++) { try { if (file.IsAssetsFile(file.reader, file.bundleInf6.dirInf[i])) { byte[] assetData = BundleHelper.LoadAssetDataFromBundle(file, i); var mainStream = new MemoryStream(assetData); activeStreams.Add(mainStream); string mainName = file.bundleInf6.dirInf[i].name; var fileInstance = new AssetsFileInstance(mainStream, mainName, ""); ClassDatabaseFile classDBFile = LoadClassDatabaseFromPackage(fileInstance.file.typeTree.unityVersion); if (classDBFile == null) { Console.WriteLine("classDatabaseFile was null? Okay, that's probably bad. Continuing anyway..."); } result.Add(new AssetFile(fileInstance, classDBFile)); } } catch (Exception e) { Console.WriteLine("caught exception while reading AssetsFile: " + e); //guess it's not an assetsFile then? } } Console.WriteLine("found " + result.Count + " AssetFiles"); return(result); }
public ClassDatabasePackage LoadClassPackage(Stream stream) { classPackage = new ClassDatabasePackage(); classPackage.Read(new AssetsFileReader(stream)); return(classPackage); }