From 1ebc396a2f14ec8224d574a15e2bf42936e775ee Mon Sep 17 00:00:00 2001 From: iAmAsval Date: Wed, 8 Jul 2020 23:24:17 +0200 Subject: [PATCH] sounds are auto-played as a playlist now (auto skip to the next one) --- .../PakReader/Parsers/Objects/EPakVersion.cs | 2 +- .../Parsers/Objects/FByteBulkData.cs | 12 ++++--- .../Parsers/Objects/FTexturePlatformData.cs | 4 +-- FModel/Utils/Assets.cs | 18 +++++----- .../Windows/SoundPlayer/AudioPlayer.xaml.cs | 34 +++++++++++++++++++ .../SoundPlayer/Visualization/OutputSource.cs | 1 - 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/FModel/PakReader/Parsers/Objects/EPakVersion.cs b/FModel/PakReader/Parsers/Objects/EPakVersion.cs index ffb0f9c6..4dd339de 100644 --- a/FModel/PakReader/Parsers/Objects/EPakVersion.cs +++ b/FModel/PakReader/Parsers/Objects/EPakVersion.cs @@ -1,4 +1,4 @@ -namespace PakReader.Parsers.Objects +namespace PakReader.Parsers.Objects { // NOTE: THIS IS NOT AN ACTUAL ENUM IN UE4. // LINK: https://github.com/EpicGames/UnrealEngine/blob/8b6414ae4bca5f93b878afadcc41ab518b09984f/Engine/Source/Runtime/PakFile/Public/IPlatformFilePak.h#L85 diff --git a/FModel/PakReader/Parsers/Objects/FByteBulkData.cs b/FModel/PakReader/Parsers/Objects/FByteBulkData.cs index 6db12e3c..a2f9bd8c 100644 --- a/FModel/PakReader/Parsers/Objects/FByteBulkData.cs +++ b/FModel/PakReader/Parsers/Objects/FByteBulkData.cs @@ -21,16 +21,20 @@ namespace PakReader.Parsers.Objects var BulkDataOffsetInFile = reader.ReadInt64(); Data = null; - if ((BulkDataFlags & (uint)EBulkDataFlags.BULKDATA_ForceInlinePayload) != 0) + if ((BulkDataFlags & (uint)EBulkDataFlags.BULKDATA_ForceInlinePayload) != 0 && ElementCount > 0) { Data = reader.ReadBytes((int)ElementCount); } if ((BulkDataFlags & (uint)EBulkDataFlags.BULKDATA_PayloadInSeperateFile) != 0) { - ubulk.Position = BulkDataOffsetInFile + ubulkOffset; - Data = new byte[ElementCount]; - ubulk.Read(Data, 0, (int)ElementCount); + if (ubulk != null) + { + ubulk.Position = BulkDataOffsetInFile + ubulkOffset; + Data = new byte[ElementCount]; + ubulk.Read(Data, 0, (int)ElementCount); + } + //else throw new FileLoadException("No ubulk specified for texture"); } } } diff --git a/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs b/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs index eab5c6a6..f2b54dfb 100644 --- a/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs +++ b/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace PakReader.Parsers.Objects @@ -25,7 +25,7 @@ namespace PakReader.Parsers.Objects if (FModel.Globals.Game.ActualGame == FModel.EGame.Valorant || FModel.Globals.Game.Version > EPakVersion.FNAME_BASED_COMPRESSION_METHOD) { - if (reader.ReadInt32() != 0) throw new FileLoadException("Too lazy to add virtual textures right now"); + if (reader.ReadInt32() != 0) throw new FileLoadException("VirtualTextures are not supported"); } } } diff --git a/FModel/Utils/Assets.cs b/FModel/Utils/Assets.cs index 5b859cc5..471e06d4 100644 --- a/FModel/Utils/Assets.cs +++ b/FModel/Utils/Assets.cs @@ -132,15 +132,6 @@ namespace FModel.Utils } break; } - case ".png": - { - using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension()); - asset.Position = 0; - ImageBoxVm.imageBoxViewModel.Set(SKBitmap.Decode(asset), mount + selected.PakEntry.Name); - break; - } - case ".ushaderbytecode": - break; case ".bnk": case ".pck": { @@ -157,6 +148,15 @@ namespace FModel.Utils }); break; } + case ".png": + { + using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension()); + asset.Position = 0; + ImageBoxVm.imageBoxViewModel.Set(SKBitmap.Decode(asset), mount + selected.PakEntry.Name); + break; + } + case ".ushaderbytecode": + break; default: AvalonEditVm.avalonEditViewModel.Set(GetJsonProperties(selected.PakEntry, mount, true), mount + selected.PakEntry.Name); break; diff --git a/FModel/Windows/SoundPlayer/AudioPlayer.xaml.cs b/FModel/Windows/SoundPlayer/AudioPlayer.xaml.cs index 0058e090..142e4b81 100644 --- a/FModel/Windows/SoundPlayer/AudioPlayer.xaml.cs +++ b/FModel/Windows/SoundPlayer/AudioPlayer.xaml.cs @@ -1,3 +1,4 @@ +using CSCore.SoundOut; using FModel.Discord; using FModel.ViewModels.ListBox; using FModel.ViewModels.SoundPlayer; @@ -190,12 +191,45 @@ namespace FModel.Windows.SoundPlayer Properties.Settings.Default.Save(); if (output == null) + { output = new OutputSource(d); + output.SourcePropertyChangedEvent += Output_SourcePropertyChangedEvent; + } else output.SwapDevice(d); } } + private void Output_SourcePropertyChangedEvent(object sender, SourcePropertyChangedEventArgs e) + { + switch (e.Property) + { + case ESourceProperty.PlaybackState: + if (output != null && output.Position == output.Length && (PlaybackState)e.Value == PlaybackState.Stopped) + { + Application.Current.Dispatcher.Invoke(delegate + { + PlayPauseImg.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/play.png")); + }); + + var selected = ListBoxVm.soundFiles.Where(x => x.FullPath.Equals(output.FileName)).FirstOrDefault(); + if (selected is ListBoxViewModel2 s) + { + int index = ListBoxVm.soundFiles.IndexOf(s); + if (index < ListBoxVm.soundFiles.Count - 1) + { + Application.Current.Dispatcher.Invoke(delegate + { + Sound_LstBox.SelectedIndex = index + 1; + OnPlayPauseClick(sender, null); + }); + } + } + } + break; + } + } + private void OnSelectedItemChanged(object sender, SelectionChangedEventArgs e) { if (sender is ListBox listBox && listBox.SelectedItem is ListBoxViewModel2 selectedItem) diff --git a/FModel/Windows/SoundPlayer/Visualization/OutputSource.cs b/FModel/Windows/SoundPlayer/Visualization/OutputSource.cs index 624c560d..f40d0bca 100644 --- a/FModel/Windows/SoundPlayer/Visualization/OutputSource.cs +++ b/FModel/Windows/SoundPlayer/Visualization/OutputSource.cs @@ -2,7 +2,6 @@ using CSCore.DSP; using CSCore.SoundOut; using CSCore.Streams; -using FModel.ViewModels.SoundPlayer; using System; using System.Threading; using System.Threading.Tasks;