From 7bc99d911a1e96baaa2558da1d7fad2a085ad975 Mon Sep 17 00:00:00 2001 From: nesquack Date: Wed, 29 May 2024 00:57:14 -0400 Subject: [PATCH] maybe add double stripped version dialog back --- AudioClipPlugin/Program.cs | 29 +++++++-------- FontPlugin/Program.cs | 19 ++++------ TextAssetPlugin/Program.cs | 8 +--- TexturePlugin/EditTextureOption.cs | 13 ++----- TexturePlugin/ExportTextureOption.cs | 4 +- TexturePlugin/ImportTextureOption.cs | 13 +++---- UABEAvalonia/Forms/MainWindow.axaml.cs | 26 +++++++++++-- UABEAvalonia/Forms/VersionWindow.axaml | 33 +++++++++++++++++ UABEAvalonia/Forms/VersionWindow.axaml.cs | 45 +++++++++++++++++++++++ UABEAvalonia/UABEAvalonia.csproj | 9 +++++ 10 files changed, 142 insertions(+), 57 deletions(-) create mode 100644 UABEAvalonia/Forms/VersionWindow.axaml create mode 100644 UABEAvalonia/Forms/VersionWindow.axaml.cs diff --git a/AudioClipPlugin/Program.cs b/AudioClipPlugin/Program.cs index 16f7c83..0a1b7fb 100644 --- a/AudioClipPlugin/Program.cs +++ b/AudioClipPlugin/Program.cs @@ -1,16 +1,15 @@ using AssetsTools.NET; using AssetsTools.NET.Extra; using Avalonia.Controls; +using Avalonia.Platform.Storage; +using Fmod5Sharp; +using Fmod5Sharp.FmodTypes; using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Threading.Tasks; using UABEAvalonia; using UABEAvalonia.Plugins; -using Fmod5Sharp; -using Fmod5Sharp.FmodTypes; -using Avalonia.Platform.Storage; namespace AudioPlugin { @@ -37,16 +36,14 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Export) return false; - int classId = am.ClassDatabase.FindAssetClassByName("AudioClip").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.AudioClip) return false; } return true; } - + public async Task ExecutePlugin(Window win, AssetWorkspace workspace, List selection) { if (selection.Count > 1) @@ -74,7 +71,7 @@ public async Task BatchExport(Window win, AssetWorkspace workspace, List BatchExport(Window win, AssetWorkspace workspace, List SingleExport(Window win, AssetWorkspace workspace, List< AssetTypeValueField baseField = workspace.GetBaseField(cont); string name = baseField["m_Name"].AsString; name = PathUtils.ReplaceInvalidPathChars(name); - - CompressionFormat compressionFormat = (CompressionFormat) baseField["m_CompressionFormat"].AsInt; + + CompressionFormat compressionFormat = (CompressionFormat)baseField["m_CompressionFormat"].AsInt; string extension = GetExtension(compressionFormat); var selectedFile = await win.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions() @@ -142,7 +139,7 @@ public async Task SingleExport(Window win, AssetWorkspace workspace, List< { return false; } - + if (!FsbLoader.TryLoadFsbFromByteArray(resourceData, out FmodSoundBank bank)) { return false; @@ -155,7 +152,7 @@ public async Task SingleExport(Window win, AssetWorkspace workspace, List< // since fmod5sharp gives us malformed wav data, we have to correct it FixWAV(ref sampleData); } - + File.WriteAllBytes(selectedFilePath, sampleData); return true; @@ -210,7 +207,7 @@ private static string GetExtension(CompressionFormat format) _ => "" }; } - + private bool GetAudioBytes(AssetContainer cont, string filepath, ulong offset, ulong size, out byte[] audioData) { if (string.IsNullOrEmpty(filepath)) @@ -265,7 +262,7 @@ private bool GetAudioBytes(AssetContainer cont, string filepath, ulong offset, u // if that fails, check current directory string resourceFileName = Path.Combine(assetsFileDirectory, Path.GetFileName(filepath)); - + if (File.Exists(resourceFileName)) { // read from file diff --git a/FontPlugin/Program.cs b/FontPlugin/Program.cs index 107d5a7..03f4a80 100644 --- a/FontPlugin/Program.cs +++ b/FontPlugin/Program.cs @@ -2,7 +2,6 @@ using AssetsTools.NET.Extra; using Avalonia.Controls; using Avalonia.Platform.Storage; -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -13,14 +12,14 @@ namespace FontPlugin { public static class FontHelper - { + { public static AssetTypeValueField GetByteArrayFont(AssetWorkspace workspace, AssetContainer font) { AssetTypeTemplateField fontTemp = workspace.GetTemplateField(font); AssetTypeTemplateField fontData = fontTemp.Children.FirstOrDefault(f => f.Name == "m_FontData"); if (fontData == null) return null; - + // m_FontData.Array fontData.Children[0].ValueType = AssetValueType.ByteArray; @@ -46,16 +45,14 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Import) return false; - int classId = am.ClassDatabase.FindAssetClassByName("Font").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.Font) return false; } return true; } - + public async Task ExecutePlugin(Window win, AssetWorkspace workspace, List selection) { if (selection.Count > 1) @@ -135,7 +132,7 @@ public async Task SingleImport(Window win, AssetWorkspace workspace, List< return true; } } - + public class ExportFontOption : UABEAPluginOption { public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, List selection, out string name) @@ -145,16 +142,14 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Export) return false; - int classId = am.ClassDatabase.FindAssetClassByName("Font").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.Font) return false; } return true; } - + public async Task ExecutePlugin(Window win, AssetWorkspace workspace, List selection) { if (selection.Count > 1) diff --git a/TextAssetPlugin/Program.cs b/TextAssetPlugin/Program.cs index 13ff6f0..4b29fd7 100644 --- a/TextAssetPlugin/Program.cs +++ b/TextAssetPlugin/Program.cs @@ -33,11 +33,9 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Import) return false; - int classId = am.ClassDatabase.FindAssetClassByName("TextAsset").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.TextAsset) return false; } return true; @@ -142,11 +140,9 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Export) return false; - int classId = am.ClassDatabase.FindAssetClassByName("TextAsset").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.TextAsset) return false; } return true; diff --git a/TexturePlugin/EditTextureOption.cs b/TexturePlugin/EditTextureOption.cs index 84e2479..6e73f69 100644 --- a/TexturePlugin/EditTextureOption.cs +++ b/TexturePlugin/EditTextureOption.cs @@ -1,15 +1,12 @@ -using AssetsTools.NET.Extra; +using AssetsTools.NET; +using AssetsTools.NET.Extra; using AssetsTools.NET.Texture; -using AssetsTools.NET; using Avalonia.Controls; -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Threading.Tasks; -using UABEAvalonia.Plugins; using UABEAvalonia; +using UABEAvalonia.Plugins; namespace TexturePlugin { @@ -25,11 +22,9 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (selection.Count != 1) return false; - int classId = am.ClassDatabase.FindAssetClassByName("Texture2D").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.Texture2D) return false; } return true; diff --git a/TexturePlugin/ExportTextureOption.cs b/TexturePlugin/ExportTextureOption.cs index 8f1c3a5..fc4774c 100644 --- a/TexturePlugin/ExportTextureOption.cs +++ b/TexturePlugin/ExportTextureOption.cs @@ -25,11 +25,9 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (action != UABEAPluginAction.Export) return false; - int classId = am.ClassDatabase.FindAssetClassByName("Texture2D").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.Texture2D) return false; } return true; diff --git a/TexturePlugin/ImportTextureOption.cs b/TexturePlugin/ImportTextureOption.cs index 8d02ea9..ec7b7f9 100644 --- a/TexturePlugin/ImportTextureOption.cs +++ b/TexturePlugin/ImportTextureOption.cs @@ -1,16 +1,15 @@ -using AssetsTools.NET.Extra; +using AssetsTools.NET; +using AssetsTools.NET.Extra; using AssetsTools.NET.Texture; -using AssetsTools.NET; using Avalonia.Controls; -using System; +using Avalonia.Platform.Storage; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using UABEAvalonia.Plugins; using UABEAvalonia; -using Avalonia.Platform.Storage; +using UABEAvalonia.Plugins; namespace TexturePlugin { @@ -26,11 +25,9 @@ public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, if (selection.Count <= 1) return false; - int classId = am.ClassDatabase.FindAssetClassByName("Texture2D").ClassId; - foreach (AssetContainer cont in selection) { - if (cont.ClassId != classId) + if (cont.ClassId != (int)AssetClassID.Texture2D) return false; } return true; diff --git a/UABEAvalonia/Forms/MainWindow.axaml.cs b/UABEAvalonia/Forms/MainWindow.axaml.cs index 55a3bad..ca5cf36 100644 --- a/UABEAvalonia/Forms/MainWindow.axaml.cs +++ b/UABEAvalonia/Forms/MainWindow.axaml.cs @@ -108,7 +108,7 @@ async void OpenFiles(string[] files) { AssetsFileInstance fileInst = am.LoadAssetsFile(selectedFile, true); - if (!LoadOrAskTypeData(fileInst)) + if (!await LoadOrAskTypeData(fileInst)) return; List fileInstances = new List(); @@ -369,7 +369,7 @@ private async void BtnInfo_Click(object? sender, RoutedEventArgs e) if (BundleInst != null && fileInst.parentBundle == null) fileInst.parentBundle = BundleInst; - if (!LoadOrAskTypeData(fileInst)) + if (!await LoadOrAskTypeData(fileInst)) return; // don't check for info open here @@ -584,7 +584,7 @@ private void InfoWindow_Closing(object? sender, System.ComponentModel.CancelEven } } - private bool LoadOrAskTypeData(AssetsFileInstance fileInst) + private async Task LoadOrAskTypeData(AssetsFileInstance fileInst) { string uVer = fileInst.file.Metadata.UnityVersion; if (uVer == "0.0.0" && fileInst.parentBundle != null) @@ -592,6 +592,26 @@ private bool LoadOrAskTypeData(AssetsFileInstance fileInst) uVer = fileInst.parentBundle.file.Header.EngineVersion; } + if (uVer == "0.0.0") + { + VersionWindow window = new VersionWindow(uVer); + uVer = await window.ShowDialog(this); + if (uVer == string.Empty) + { + if (!fileInst.file.Metadata.TypeTreeEnabled) + { + // if we have no type tree, there's no way we're loading anything + await MessageBoxUtil.ShowDialog(this, "Error", "You must enter a Unity version to load a typetree-stripped file."); + return false; + } + else + { + // bad, but we can at least rely on the type tree for most things + uVer = "0.0.0"; + } + } + } + am.LoadClassDatabaseFromPackage(uVer); return true; } diff --git a/UABEAvalonia/Forms/VersionWindow.axaml b/UABEAvalonia/Forms/VersionWindow.axaml new file mode 100644 index 0000000..f1e89d3 --- /dev/null +++ b/UABEAvalonia/Forms/VersionWindow.axaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + This bundle has a double stripped version. Please provide the engine version for this file. Cancelling this dialog may cause some functionality to fail. + + 0.0.0f0 + + + + + + + + + + + diff --git a/UABEAvalonia/Forms/VersionWindow.axaml.cs b/UABEAvalonia/Forms/VersionWindow.axaml.cs new file mode 100644 index 0000000..5ce92d7 --- /dev/null +++ b/UABEAvalonia/Forms/VersionWindow.axaml.cs @@ -0,0 +1,45 @@ +using AssetsTools.NET.Extra; +using Avalonia; +using Avalonia.Controls; + +namespace UABEAvalonia +{ + public partial class VersionWindow : Window + { + public VersionWindow() + { + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + //generated events + btnOk.Click += BtnYes_Click; + btnCancel.Click += BtnNo_Click; + } + + public VersionWindow(string ver) : this() + { + boxVer.Text = ver; + } + + private async void BtnYes_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + string returnText = boxVer.Text ?? string.Empty; + try + { + _ = new UnityVersion(returnText); + } + catch + { + await MessageBoxUtil.ShowDialog(this, "Error", "Invalid version string. Example: 2019.4.1f1"); + return; + } + Close(returnText); + } + + private void BtnNo_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Close(string.Empty); + } + } +} diff --git a/UABEAvalonia/UABEAvalonia.csproj b/UABEAvalonia/UABEAvalonia.csproj index 7912e2a..cba24b7 100644 --- a/UABEAvalonia/UABEAvalonia.csproj +++ b/UABEAvalonia/UABEAvalonia.csproj @@ -55,6 +55,11 @@ + + + Designer + + ExportBatchChooseTypeDialog.axaml @@ -65,6 +70,10 @@ ImportSerializedDialog.axaml + + Code + VersionWindow.axaml +