private void decompressButton_Click(object sender, System.EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = Path.GetFileName(bundleStream.Name) + ".unpacked"; sfd.Filter = "All types (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) { note.Text = "Decompressing..."; decompressButton.Enabled = false; bundleFilename = sfd.FileName; FileStream fileStream = new FileStream(sfd.FileName, FileMode.Create); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += delegate { bundle.Unpack(reader, new AssetsFileWriter(fileStream)); fileStream.Position = 0; bundle = new AssetBundleFile(); bundle.Read(new AssetsFileReader(fileStream), false); fileStream.Close(); }; bw.RunWorkerCompleted += delegate { note.Text = "Done. Click Load to open the file."; decompressButton.Enabled = false; loadButton.Enabled = true; }; bw.RunWorkerAsync(); } }
private static AssetBundleFile DecompressBundle(string file, string?decompFile) { AssetBundleFile bun = new AssetBundleFile(); Stream fs = File.OpenRead(file); AssetsFileReader r = new AssetsFileReader(fs); bun.Read(r, true); if (bun.bundleHeader6.GetCompressionType() != 0) { Stream nfs; if (decompFile == null) { nfs = new MemoryStream(); } else { nfs = File.Open(decompFile, FileMode.Create, FileAccess.ReadWrite); } AssetsFileWriter w = new AssetsFileWriter(nfs); bun.Unpack(r, w); nfs.Position = 0; fs.Close(); fs = nfs; r = new AssetsFileReader(fs); bun = new AssetBundleFile(); bun.Read(r, false); } return(bun); }
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 static AssetBundleFile UnpackBundleToStream(AssetBundleFile file, Stream stream, bool freeOriginalStream = true) { file.Unpack(file.reader, new AssetsFileWriter(stream)); stream.Position = 0; AssetBundleFile newFile = new AssetBundleFile(); newFile.Read(new AssetsFileReader(stream), false); if (freeOriginalStream) { file.reader.Close(); } return(newFile); }
private void DecompressToMemory(BundleFileInstance bundleInst) { AssetBundleFile bundle = bundleInst.file; MemoryStream bundleStream = new MemoryStream(); bundle.Unpack(bundle.reader, new AssetsFileWriter(bundleStream)); bundleStream.Position = 0; AssetBundleFile newBundle = new AssetBundleFile(); newBundle.Read(new AssetsFileReader(bundleStream), false); bundle.reader.Close(); bundleInst.file = newBundle; }
private void DecompressToFile(BundleFileInstance bundleInst, string savePath) { AssetBundleFile bundle = bundleInst.file; FileStream bundleStream = File.Open(savePath, FileMode.Create); bundle.Unpack(bundle.reader, new AssetsFileWriter(bundleStream)); bundleStream.Position = 0; AssetBundleFile newBundle = new AssetBundleFile(); newBundle.Read(new AssetsFileReader(bundleStream), false); bundle.reader.Close(); bundleInst.file = newBundle; }
public static AssetBundleFile UnpackBundle(AssetBundleFile file, bool freeOriginalStream = true) { MemoryStream ms = new MemoryStream(); file.Unpack(file.reader, new AssetsFileWriter(ms)); ms.Position = 0; AssetBundleFile newFile = new AssetBundleFile(); newFile.Read(new AssetsFileReader(ms), false); if (freeOriginalStream) { file.reader.Close(); } return(newFile); }
private void DecompressBundle(Stream stream) { status.Text = "Decompressing..."; decompressBundle.Enabled = false; decompressBundleInMemory.Enabled = false; BackgroundWorker bw = new BackgroundWorker(); string error = string.Empty; bw.DoWork += delegate { try { file.reader.Position = 0; file.Unpack(file.reader, new AssetsFileWriter(stream)); stream.Position = 0; file = new AssetBundleFile(); file.Read(new AssetsFileReader(stream), false); inst.file = file; } catch (Exception ex) { error = ex.ToString(); } }; bw.RunWorkerCompleted += delegate { if (error != string.Empty) { MessageBox.Show("An error occurred:\n" + error, "Assets View", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { justThisFile.Enabled = true; fileAndDependencies.Enabled = true; compressBundle.Enabled = true; decompressBundle.Enabled = false; decompressBundleInMemory.Enabled = false; status.Text = $"Opening bundle file {fileName}..."; } }; bw.RunWorkerAsync(); }