Skip to content

Commit

Permalink
maybe add double stripped version dialog back
Browse files Browse the repository at this point in the history
  • Loading branch information
nesrak1 committed May 29, 2024
1 parent 5adb448 commit 7bc99d9
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 57 deletions.
29 changes: 13 additions & 16 deletions AudioClipPlugin/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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<bool> ExecutePlugin(Window win, AssetWorkspace workspace, List<AssetContainer> selection)
{
if (selection.Count > 1)
Expand Down Expand Up @@ -74,7 +71,7 @@ public async Task<bool> BatchExport(Window win, AssetWorkspace workspace, List<A

string name = baseField["m_Name"].AsString;
name = PathUtils.ReplaceInvalidPathChars(name);

CompressionFormat compressionFormat = (CompressionFormat)baseField["m_CompressionFormat"].AsInt;
string extension = GetExtension(compressionFormat);
string file = Path.Combine(dir, $"{name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.{extension}");
Expand All @@ -101,7 +98,7 @@ public async Task<bool> BatchExport(Window win, AssetWorkspace workspace, List<A
// since fmod5sharp gives us malformed wav data, we have to correct it
FixWAV(ref sampleData);
}

File.WriteAllBytes(file, sampleData);
}
return true;
Expand All @@ -114,8 +111,8 @@ public async Task<bool> 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()
Expand All @@ -142,7 +139,7 @@ public async Task<bool> SingleExport(Window win, AssetWorkspace workspace, List<
{
return false;
}

if (!FsbLoader.TryLoadFsbFromByteArray(resourceData, out FmodSoundBank bank))
{
return false;
Expand All @@ -155,7 +152,7 @@ public async Task<bool> 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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
19 changes: 7 additions & 12 deletions FontPlugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<bool> ExecutePlugin(Window win, AssetWorkspace workspace, List<AssetContainer> selection)
{
if (selection.Count > 1)
Expand Down Expand Up @@ -135,7 +132,7 @@ public async Task<bool> SingleImport(Window win, AssetWorkspace workspace, List<
return true;
}
}

public class ExportFontOption : UABEAPluginOption
{
public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, List<AssetContainer> selection, out string name)
Expand All @@ -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<bool> ExecutePlugin(Window win, AssetWorkspace workspace, List<AssetContainer> selection)
{
if (selection.Count > 1)
Expand Down
8 changes: 2 additions & 6 deletions TextAssetPlugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions TexturePlugin/EditTextureOption.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions TexturePlugin/ExportTextureOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 5 additions & 8 deletions TexturePlugin/ImportTextureOption.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand Down
26 changes: 23 additions & 3 deletions UABEAvalonia/Forms/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async void OpenFiles(string[] files)
{
AssetsFileInstance fileInst = am.LoadAssetsFile(selectedFile, true);

if (!LoadOrAskTypeData(fileInst))
if (!await LoadOrAskTypeData(fileInst))
return;

List<AssetsFileInstance> fileInstances = new List<AssetsFileInstance>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -584,14 +584,34 @@ private void InfoWindow_Closing(object? sender, System.ComponentModel.CancelEven
}
}

private bool LoadOrAskTypeData(AssetsFileInstance fileInst)
private async Task<bool> LoadOrAskTypeData(AssetsFileInstance fileInst)
{
string uVer = fileInst.file.Metadata.UnityVersion;
if (uVer == "0.0.0" && fileInst.parentBundle != null)
{
uVer = fileInst.parentBundle.file.Header.EngineVersion;
}

if (uVer == "0.0.0")
{
VersionWindow window = new VersionWindow(uVer);
uVer = await window.ShowDialog<string>(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;
}
Expand Down
33 changes: 33 additions & 0 deletions UABEAvalonia/Forms/VersionWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="140"
Width="300" Height="140"
Icon="/Assets/uabeavalonia16.ico"
x:Class="UABEAvalonia.VersionWindow"
Title="Version Select">
<Grid Margin="10,10,10,10">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" TextWrapping="WrapWithOverflow">This bundle has a double stripped version. Please provide the engine version for this file. Cancelling this dialog may cause some functionality to fail.</TextBlock>
<Label Grid.Column="0" Grid.Row="1">Engine Version</Label>
<TextBox Grid.Column="1" Grid.Row="1" Name="boxVer">0.0.0f0</TextBox>
</Grid>
<Grid VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Name="btnOk">Ok</Button>
<Button Grid.Column="1" Name="btnCancel">Cancel</Button>
</Grid>
</Grid>
</Window>
Loading

0 comments on commit 7bc99d9

Please sign in to comment.