private async void BtnInfo_Click(object?sender, RoutedEventArgs e) { if (bundleInst != null && comboBox.SelectedItem != null) { int index = (int)((ComboBoxItem)comboBox.SelectedItem).Tag; string bunAssetName = bundleInst.file.bundleInf6.dirInf[index].name; //when we make a modification to an assets file in the bundle, //we replace the assets file in the manager. this way, all we //have to do is not reload from the bundle if our assets file //has been modified MemoryStream assetStream; if (!newFiles.ContainsKey(bunAssetName)) { byte[] assetData = BundleHelper.LoadAssetDataFromBundle(bundleInst.file, index); assetStream = new MemoryStream(assetData); } else { //unused if the file already exists assetStream = null; } //warning: does not update if you import an assets file onto //a file that wasn't originally an assets file var fileInf = BundleHelper.GetDirInfo(bundleInst.file, index); bool isAssetsFile = bundleInst.file.IsAssetsFile(bundleInst.file.reader, fileInf); if (isAssetsFile) { string assetMemPath = Path.Combine(bundleInst.path, bunAssetName); AssetsFileInstance fileInst = am.LoadAssetsFile(assetStream, assetMemPath, true); if (!await LoadOrAskTypeData(fileInst)) { return; } if (bundleInst != null && fileInst.parentBundle == null) { fileInst.parentBundle = bundleInst; } InfoWindow info = new InfoWindow(am, new List <AssetsFileInstance> { fileInst }, true); info.Closing += InfoWindow_Closing; info.Show(); } else { await MessageBoxUtil.ShowDialog(this, "Error", "This doesn't seem to be a valid assets file.\n" + "If you want to export a non-assets file,\n" + "use Export."); } } }
private async void BtnOk_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e) { var fileInsts = new List <AssetsFileInstance>(); var replacerLists = new Dictionary <AssetsFileInstance, List <AssetsReplacer> >(); foreach (LoadModPackageTreeFileInfo fileItem in affectedFiles.Items) { if (fileItem.selected && File.Exists(fileItem.fullPath)) { AssetsFileInstance fileInst = am.LoadAssetsFile(fileItem.fullPath, true); fileInsts.Add(fileInst); if (!replacerLists.ContainsKey(fileInst)) { replacerLists[fileInst] = new List <AssetsReplacer>(); } foreach (AssetsReplacer replacer in fileItem.assetDesc.replacers) { replacerLists[fileInst].Add(replacer); } } } if (fileInsts.Count == 0) { await MessageBoxUtil.ShowDialog(this, "Error", "Did not load any files. Did you select any (double click) or set the correct base path?"); return; } if (!await LoadOrAskTypeData(fileInsts[0])) { Close(false); return; } InfoWindow info = new InfoWindow(am, fileInsts, false); foreach (KeyValuePair <AssetsFileInstance, List <AssetsReplacer> > kvp in replacerLists) { AssetsFileInstance fileInst = kvp.Key; List <AssetsReplacer> replacerList = kvp.Value; foreach (AssetsReplacer replacer in replacerList) { info.Workspace.AddReplacer(fileInst, replacer); } } info.Show(); //temporary hack Hide(); info.Closed += (object?sender, EventArgs e) => { Close(true); }; }
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); } } } }
private async void BtnInfo_Click(object?sender, RoutedEventArgs e) { //when dependency loading is supported: //make sure cab:// dependencies in the bundle are loaded as well if (bundleInst != null && comboBox.SelectedItem != null) { int index = (int)((ComboBoxItem)comboBox.SelectedItem).Tag; string bunAssetName = bundleInst.file.bundleInf6.dirInf[index].name; //when we make a modification to an assets file in the bundle, //we replace the assets file in the manager. this way, all we //have to do is not reload from the bundle if our assets file //has been modified MemoryStream assetStream; if (!newFiles.ContainsKey(bunAssetName)) { byte[] assetData = BundleHelper.LoadAssetDataFromBundle(bundleInst.file, index); assetStream = new MemoryStream(assetData); } else { //unused if the file already exists assetStream = null; } //warning: does not update if you import an assets file onto //a file that wasn't originally an assets file var fileInf = BundleHelper.GetDirInfo(bundleInst.file, index); bool isAssetsFile = bundleInst.file.IsAssetsFile(bundleInst.file.reader, fileInf); if (isAssetsFile) { AssetsFileInstance fileInst = am.LoadAssetsFile(assetStream, bundleInst.path, true); am.LoadClassDatabaseFromPackage(fileInst.file.typeTree.unityVersion); InfoWindow info = new InfoWindow(am, fileInst, bunAssetName, true); info.Closing += InfoWindowClosing; info.Show(); } else { await MessageBoxUtil.ShowDialog(this, "Error", "This doesn't seem to be a valid assets file.\n" + "If you want to export a non-assets file,\n" + "use Export."); } } }
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); } } } }