public OpenBundleDialog(AssetsManager helper, string filePath) { InitializeComponent(); this.filePath = filePath; fileName = Path.GetFileName(filePath); inst = helper.LoadBundleFile(filePath); file = inst.file; uint compressionMethod = file.bundleHeader6.flags & 0x3F; if (compressionMethod == 0) { justThisFile.Enabled = true; fileAndDependencies.Enabled = true; compressBundle.Enabled = true; status.Text = $"Opening bundle file {fileName}..."; } else { decompressBundle.Enabled = true; decompressBundleInMemory.Enabled = true; if (compressionMethod == 1) { status.Text = $"Opening bundle file {fileName} (LZMA)..."; } else if (compressionMethod == 2 || compressionMethod == 3) { status.Text = $"Opening bundle file {fileName} (LZ4)..."; } else { status.Text = $"Opening bundle file {fileName} (???)..."; } } }
private void LoadBundleFile(string path) { OpenBundleDialog openFile = new OpenBundleDialog(helper, path); openFile.ShowDialog(); if (openFile.selection > -1) { AssetBundleFile bundleFile = openFile.file; BundleFileInstance bundleInst = openFile.inst; List <byte[]> files = BundleHelper.LoadAllAssetsDataFromBundle(bundleFile); if (files.Count > 0) { if (files.Count > 1) { for (int i = 1; i < files.Count; i++) { MemoryStream stream = new MemoryStream(files[i]); string name = bundleFile.bundleInf6.dirInf[i].name; AssetsFileInstance inst = helper.LoadAssetsFile(stream, name, openFile.selection == 1); inst.parentBundle = bundleInst; } } MemoryStream mainStream = new MemoryStream(files[0]); string mainName = bundleFile.bundleInf6.dirInf[0].name; AssetsFileInstance mainInst = helper.LoadAssetsFile(mainStream, mainName, openFile.selection == 1); mainInst.parentBundle = bundleInst; LoadMainAssetsFile(mainInst); } else { MessageBox.Show("No valid assets files found in the bundle.", "Assets View"); } } }
private void LoadBundle(string path) { BundleInst = Am.LoadBundleFile(path, false); Loader = new BundleLoader(BundleInst); Loader.ShowDialog(); if (!Loader.Loaded) { return; } cboxBundleContents.Enabled = true; btnExport.Enabled = true; btnImport.Enabled = true; btnRemove.Enabled = true; btnInfo.Enabled = true; var infos = BundleInst.file.bundleInf6.dirInf; cboxBundleContents.Items.Clear(); foreach (var info in infos) { cboxBundleContents.Items.Add(info.name); } cboxBundleContents.SelectedIndex = 0; lblFileName.Text = BundleInst.name; }
private async void AskLoadCompressedBundle(BundleFileInstance bundleInst) { const string fileOption = "File"; const string memoryOption = "Memory"; const string cancelOption = "Cancel"; string result = await MessageBoxUtil.ShowDialogCustom( this, "Note", "This bundle is compressed. Decompress to file or memory?", fileOption, memoryOption, cancelOption); if (result == fileOption) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save as..."; sfd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "All files", Extensions = new List <string>() { "*" } } }; string savePath; while (true) { savePath = await sfd.ShowAsync(this); if (savePath == "" || savePath == null) { return; } if (Path.GetFullPath(savePath) == Path.GetFullPath(bundleInst.path)) { await MessageBoxUtil.ShowDialog(this, "File in use", "Since this file is already open in UABEA, you must pick a new file name (sorry!)"); continue; } else { break; } } DecompressToFile(bundleInst, savePath); } else if (result == memoryOption) { DecompressToMemory(bundleInst); } else //if (result == cancelOption || result == closeOption) { return; } LoadBundle(bundleInst); }
private void CompressBundle(BundleFileInstance bundleInst, string path, AssetBundleCompressionType compType) { using (FileStream fs = File.OpenWrite(path)) using (AssetsFileWriter w = new AssetsFileWriter(fs)) { bundleInst.file.Pack(bundleInst.file.reader, w, compType); } }
private void SaveBundle(BundleFileInstance bundleInst, string path) { using (FileStream fs = File.OpenWrite(path)) using (AssetsFileWriter w = new AssetsFileWriter(fs)) { bundleInst.file.Write(w, newFiles.Values.ToList()); } modified = false; }
private async void MenuOpen_Click(object?sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open assets or bundle file"; ofd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "All files", Extensions = new List <string>() { "*" } } }; string[] files = await ofd.ShowAsync(this); if (files.Length > 0) { string selectedFile = files[0]; DetectedFileType fileType = AssetBundleDetector.DetectFileType(selectedFile); CloseAllFiles(); if (fileType == DetectedFileType.AssetsFile) { string assetName = Path.GetFileNameWithoutExtension(selectedFile); AssetsFileInstance fileInst = am.LoadAssetsFile(selectedFile, true); am.LoadClassDatabaseFromPackage(fileInst.file.typeTree.unityVersion); InfoWindow info = new InfoWindow(am, fileInst, assetName, false); info.Show(); } else if (fileType == DetectedFileType.BundleFile) { bundleInst = am.LoadBundleFile(selectedFile, false); //don't pester user to decompress if it's only the header that is compressed if (AssetBundleUtil.IsBundleDataCompressed(bundleInst.file)) { AskLoadCompressedBundle(bundleInst); } else { if ((bundleInst.file.bundleHeader6.flags & 0x3F) != 0) //header is compressed (most likely) { DecompressToMemory(bundleInst); } LoadBundle(bundleInst); } } } }
/// <summary> /// Manually check if the asset is bundled by comparing the decompressed and compressed block sizes. /// </summary> /// <param name="bundleFile">The file to check</param> /// <returns>true if the bundle is compressed</returns> private static bool IsPacked(BundleFileInstance bundleFile) { foreach (var block in bundleFile.file.bundleInf6.blockInf) { if (block.decompressedSize > block.compressedSize) { return(true); } } return(false); }
private void CloseAllFiles() { newFiles.Clear(); changesUnsaved = false; changesMade = false; am.UnloadAllAssetsFiles(true); am.UnloadAllBundleFiles(); comboItems = new ObservableCollection <ComboBoxItem>(); comboBox.Items = comboItems; bundleInst = null; lblFileName.Text = "No file opened."; }
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; }
/// <summary> /// Unpack the specified bundle instance and return a new instance of the unpacked version. /// </summary> /// <param name="manager">The assets manager</param> /// <param name="bundle">The bundle to unpack</param> /// <param name="unpackedFile">The unpacked bundle file</param> /// <returns></returns> private static BundleFileInstance Unpack( AssetsManager manager, BundleFileInstance bundle, string unpackedFile ) { using var unpackedStream = File.OpenWrite(unpackedFile); using var reader = new AssetsFileReader(bundle.stream); using var writer = new AssetsFileWriter(unpackedStream); bundle.file.Unpack(reader, writer); writer.Flush(); // Close the stream so assetsManager can open the file unpackedStream.Close(); return(manager.LoadBundleFile(unpackedFile)); }
private void LoadBundle(BundleFileInstance bundleInst) { var infos = bundleInst.file.bundleInf6.dirInf; comboItems = new ObservableCollection <ComboBoxItem>(); for (int i = 0; i < infos.Length; i++) { var info = infos[i]; comboItems.Add(new ComboBoxItem() { Content = info.name, Tag = i }); } comboBox.Items = comboItems; comboBox.SelectedIndex = 0; lblFileName.Text = bundleInst.name; }
private async void AskLoadCompressedBundle(BundleFileInstance bundleInst) { const string fileOption = "File"; const string memoryOption = "Memory"; const string cancelOption = "Cancel"; string result = await MessageBoxUtil.ShowDialogCustom( this, "Note", "This bundle is compressed. Decompress to file or memory?", fileOption, memoryOption, cancelOption); if (result == fileOption) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save as..."; sfd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "All files", Extensions = new List <string>() { "*" } } }; string savePath = await sfd.ShowAsync(this); if (savePath == null) { return; } DecompressToFile(bundleInst, savePath); } else if (result == memoryOption) { DecompressToMemory(bundleInst); } else //if (result == cancelOption || result == closeOption) { return; } LoadBundle(bundleInst); }
public bool Load(FileStream bundleStream) { bundle = manager.LoadBundleFile(bundleStream); // The LO bundles don't indicate they are packed when checking the header flags. We check the reported // asset sizes and unpack if needed. if (IsPacked(bundle)) { bundle = Unpack(manager, bundle, unpackFile); } var files = BundleHelper.LoadAllAssetsDataFromBundle(bundle.file); assetsFileStream = new MemoryStream(files[0]); assetsFile = manager.LoadAssetsFile(assetsFileStream, bundle.file.bundleInf6.dirInf[0].name, true); assetsFile.table.GenerateQuickLookupTree(); manager.UpdateDependencies(); manager.LoadClassDatabaseFromPackage(assetsFile.file.typeTree.unityVersion); return(true); }
public BundleDecompression(BundleFileInstance bundleInst) { InitializeComponent(); BundleInst = bundleInst; }
private static void ReadGameInfo(AssetsManager assetsManager) { string gameDataPath = MelonUtils.GetGameDataDirectory(); AssetsFileInstance instance = null; try { string bundlePath = Path.Combine(gameDataPath, "globalgamemanagers"); if (!File.Exists(bundlePath)) { bundlePath = Path.Combine(gameDataPath, "mainData"); } if (!File.Exists(bundlePath)) { bundlePath = Path.Combine(gameDataPath, "data.unity3d"); if (!File.Exists(bundlePath)) { return; } BundleFileInstance bundleFile = assetsManager.LoadBundleFile(bundlePath); instance = assetsManager.LoadAssetsFileFromBundle(bundleFile, "globalgamemanagers"); } else { instance = assetsManager.LoadAssetsFile(bundlePath, true); } if (instance == null) { return; } assetsManager.LoadIncludedClassPackage(); if (!instance.file.typeTree.hasTypeTree) { assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); } EngineVersion = UnityVersion.Parse(instance.file.typeTree.unityVersion); List <AssetFileInfoEx> assetFiles = instance.table.GetAssetsOfType(129); if (assetFiles.Count > 0) { AssetFileInfoEx playerSettings = assetFiles.First(); AssetTypeInstance assetTypeInstance = null; try { assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } catch (Exception ex) { if (MelonDebug.IsEnabled()) { MelonLogger.Error(ex); MelonLogger.Warning("Attempting to use Large Class Package..."); } assetsManager.LoadIncludedLargeClassPackage(); assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } if (assetTypeInstance != null) { AssetTypeValueField playerSettings_baseField = assetTypeInstance.GetBaseField(); AssetTypeValueField bundleVersion = playerSettings_baseField.Get("bundleVersion"); if (bundleVersion != null) { GameVersion = bundleVersion.GetValue().AsString(); } AssetTypeValueField companyName = playerSettings_baseField.Get("companyName"); if (companyName != null) { GameDeveloper = companyName.GetValue().AsString(); } AssetTypeValueField productName = playerSettings_baseField.Get("productName"); if (productName != null) { GameName = productName.GetValue().AsString(); } } } } catch (Exception ex) { if (MelonDebug.IsEnabled()) { MelonLogger.Error(ex); } MelonLogger.Error("Failed to Initialize Assets Manager!"); } if (instance != null) { instance.file.Close(); } }
private static void CompressBundle(BundleFileInstance bundleInst, string path, AssetBundleCompressionType compType) { using var fs = File.OpenWrite(path); using var writer = new AssetsFileWriter(fs); bundleInst.file.Pack(bundleInst.file.reader, writer, compType); }
private void LoadBundleFile(string path) { OpenBundleDialog openFile = new OpenBundleDialog(helper, path); openFile.ShowDialog(); if (openFile.selection > -1) { AssetBundleFile bundleFile = openFile.file; BundleFileInstance bundleInst = openFile.inst; List <byte[]> files = BundleHelper.LoadAllAssetsDataFromBundle(bundleFile); string rootPath = Path.GetDirectoryName(openFile.inst.path); if (files.Count > 0) { int mainIndex = -1; for (int i = 0; i < files.Count; i++) { if (files[i] == null) { continue; } if (mainIndex == -1) { mainIndex = i; } else { MemoryStream stream = new MemoryStream(files[i]); string name = bundleFile.bundleInf6.dirInf[i].name; AssetsFileInstance inst = helper.LoadAssetsFile(stream, name, openFile.selection == 1, rootPath); inst.parentBundle = bundleInst; } } //if (files.Count > 1) //{ // for (int i = 1; i < files.Count; i++) // { // MemoryStream stream = new MemoryStream(files[i]); // string name = bundleFile.bundleInf6.dirInf[i].name; // AssetsFileInstance inst = helper.LoadAssetsFile(stream, name, openFile.selection == 1, rootPath); // inst.parentBundle = bundleInst; // } //} //MemoryStream mainStream = new MemoryStream(files[0]); //string mainName = bundleFile.bundleInf6.dirInf[0].name; //AssetsFileInstance mainInst = helper.LoadAssetsFile(mainStream, mainName, openFile.selection == 1, rootPath); //mainInst.parentBundle = bundleInst; MemoryStream mainStream = new MemoryStream(files[mainIndex]); string mainName = bundleFile.bundleInf6.dirInf[mainIndex].name; AssetsFileInstance mainInst = helper.LoadAssetsFile(mainStream, mainName, openFile.selection == 1, rootPath); mainInst.parentBundle = bundleInst; LoadMainAssetsFile(mainInst); if (openFile.selection == 1) { helper.LoadAssetsFile(currentFile.stream, currentFile.path, true); UpdateDependencies(); } } else { MessageBox.Show("No valid assets files found in the bundle.", "Assets View"); } } }
public BundleLoader(BundleFileInstance bundleInst) { InitializeComponent(); BundleInst = bundleInst; }
private async void MenuOpen_Click(object?sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open assets or bundle file"; ofd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "All files", Extensions = new List <string>() { "*" } } }; string[] files = await ofd.ShowAsync(this); if (files != null && files.Length > 0) { string selectedFile = files[0]; DetectedFileType fileType = AssetBundleDetector.DetectFileType(selectedFile); CloseAllFiles(); //can you even have split bundles? if (fileType != DetectedFileType.Unknown) { if (selectedFile.EndsWith(".split0")) { string?splitFilePath = await AskLoadSplitFile(selectedFile); if (splitFilePath == null) { return; } else { selectedFile = splitFilePath; } } } if (fileType == DetectedFileType.AssetsFile) { AssetsFileInstance fileInst = am.LoadAssetsFile(selectedFile, true); if (!await LoadOrAskTypeData(fileInst)) { return; } InfoWindow info = new InfoWindow(am, new List <AssetsFileInstance> { fileInst }, false); info.Show(); } else if (fileType == DetectedFileType.BundleFile) { bundleInst = am.LoadBundleFile(selectedFile, false); //don't pester user to decompress if it's only the header that is compressed if (AssetBundleUtil.IsBundleDataCompressed(bundleInst.file)) { AskLoadCompressedBundle(bundleInst); } else { if ((bundleInst.file.bundleHeader6.flags & 0x3F) != 0) //header is compressed (most likely) { bundleInst.file.UnpackInfoOnly(); } LoadBundle(bundleInst); } } } }