From 1302ed5a0ea543952cc55e480aabc50173eb1144 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 5 Aug 2022 04:08:43 +0200 Subject: [PATCH 01/16] Add AudioPCKFile --- .../Classes/FileTypes/AudioPCKFile.cs | 168 +++++++ .../Classes/IO/PCK/PCKAudioFileReader.cs | 115 +++++ .../Classes/IO/PCK/PCKAudioFileWriter.cs | 96 ++++ .../Forms/Utilities/Audio/AudioEditor.cs | 459 ++++++++---------- MinecraftUSkinEditor/PckStudio.csproj | 3 + 5 files changed, 572 insertions(+), 269 deletions(-) create mode 100644 MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs diff --git a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs new file mode 100644 index 00000000..fbf5c9cb --- /dev/null +++ b/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.FileTypes +{ + public class PCKAudioFile + { + public class InvalidCategoryException : Exception + { + public InvalidCategoryException(string message) : base(message) + { } + } + + public readonly int type = 1; + + public AudioCategory[] Categories { get; } = new AudioCategory[8]; + + public Dictionary Credits { get; } = new Dictionary(); + + public class AudioCategory + { + public enum EAudioType : int + { + Overworld, + Nether, + End, + Creative, + Menu, + Battle, + Tumble, + Glide, + Unused, + } + + public enum EAudioParameterType : int + { + unk0, // dimension music + unk1, // unused music ? + } + + public string Name { get; set; } = string.Empty; + public EAudioParameterType parameterType { get; } + public EAudioType audioType { get; } + public List SongNames { get; } = new List(); + + public AudioCategory(EAudioParameterType parameterType, EAudioType audioType) + { + this.parameterType = parameterType; + this.audioType = audioType; + } + + public AudioCategory(string name, EAudioParameterType parameterType, EAudioType audioType) : this(parameterType, audioType) + { + Name = name; + } + } + + public string[] GetCredits() => Credits.Values.ToArray(); + + public void AddCredits(params string[] credits) + { + foreach (var credit in credits) + { + AddCredit(credit); + } + } + + /// + /// Applies internal Credits to loc file + /// + public void ApplyCredits(LOCFile locFile) + { + foreach (var credit in Credits) + { + locFile.SetLocEntry(credit.Key, credit.Value); + } + } + + /// + /// Clears and sets the new supplied + /// + public void SetCredits(params string[] credits) + { + Credits.Clear(); + foreach (var credit in credits) + { + AddCredit(credit); + } + } + + public bool SetCredit(string creditId, string s) + { + if (!Credits.ContainsKey(creditId)) + return false; + Credits[creditId] = s; + return true; + } + + public void AddCredit(string credit) + { + Credits.Add($"IDS_CREDIT{(Credits.Count > 1 ? $"_{Credits.Count}" : string.Empty)}", credit); + } + + public void AddCreditId(string creditId) => Credits.Add(creditId, string.Empty); + + + /// + public bool HasCategory(AudioCategory.EAudioType category) => GetCategory(category) is AudioCategory; + + /// + public AudioCategory GetCategory(AudioCategory.EAudioType category) + { + if (category < AudioCategory.EAudioType.Overworld || + category > AudioCategory.EAudioType.Unused) + throw new InvalidCategoryException(nameof(category)); + return Categories[(int)category]; + } + + /// + public bool TryGetCategory(AudioCategory.EAudioType category, out AudioCategory audioCategory) + { + if (GetCategory(category) is AudioCategory a) + { + audioCategory = a; + return true; + } + audioCategory = null; + return false; + } + + public int GetCategoryCount() + { + int count = 0; + Array.ForEach(Categories, c => { if (c is not null) count++; }); + return count; + } + + /// True when category was created, otherwise false + /// + public bool AddCategory(AudioCategory.EAudioParameterType parameterType, AudioCategory.EAudioType category) + { + if (category < AudioCategory.EAudioType.Overworld || + category > AudioCategory.EAudioType.Unused) + throw new InvalidCategoryException(nameof(category)); + bool exists = HasCategory(category); + if (!exists) Categories[(int)category] = new AudioCategory(parameterType, category); + return !exists; + } + + /// True when category was created, otherwise false + /// + public bool AddCategory(AudioCategory.EAudioType category) + => AddCategory(AudioCategory.EAudioParameterType.unk0, category); + + /// True when category was removed, otherwise false + /// + public bool RemoveCategory(AudioCategory.EAudioType category) + { + bool exists = HasCategory(category); + if (exists) Categories[(int)category] = null; + return exists; + } + + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs new file mode 100644 index 00000000..ab7fee3e --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -0,0 +1,115 @@ +using PckStudio.Classes.FileTypes; +using PckStudio.Classes.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.IO.PCK +{ + + public class InvalidAudioPckException : Exception + { + public InvalidAudioPckException(string message) : base(message) + { } + } + + internal class PCKAudioFileReader : StreamDataReader + { + private PCKAudioFile _file; + private List LUT = new List(); + + + public static PCKAudioFile Read(Stream stream, bool isLittleEndian) + { + return new PCKAudioFileReader(isLittleEndian).ReadFromStream(stream); + } + + private PCKAudioFileReader(bool isLittleEndian) : base(isLittleEndian) + { + } + + private PCKAudioFile ReadFromStream(Stream stream) + { + int pck_type = ReadInt(stream); + if (pck_type > 0xf00000) // 03 00 00 00 == true + throw new OverflowException(nameof(pck_type)); + if (pck_type > 1) + throw new InvalidAudioPckException(nameof(pck_type)); + _file = new PCKAudioFile(); + ReadLookUpTabel(stream); + ReadCategories(stream); + ReadCategorySongs(stream); + return _file; + } + + private void ReadLookUpTabel(Stream stream) + { + int count = ReadInt(stream); + LUT = new List(count); + for (int i = 0; i < count; i++) + { + int index = ReadInt(stream); + LUT.Insert(index, ReadString(stream)); + } + } + + private void ReadCategories(Stream stream) + { + int categoryEntryCount = ReadInt(stream); + for (; 0 < categoryEntryCount; categoryEntryCount--) + { + var parameterType = (PCKAudioFile.AudioCategory.EAudioParameterType)ReadInt(stream); + var audioType = (PCKAudioFile.AudioCategory.EAudioType)ReadInt(stream); + string name = ReadString(stream); + Console.WriteLine(name); + _file.AddCategory(parameterType, audioType); + } + } + + private void ReadCategorySongs(Stream stream) + { + List credits = new List(); + List creditIds = new List(); + foreach (var c in _file.Categories) + { + if (c is null) continue; + int audioCount = ReadInt(stream); + for (; 0 < audioCount; audioCount--) + { + string key = LUT[ReadInt(stream)]; + string value = ReadString(stream); + switch (key) + { + case "CUENAME": + c.SongNames.Add(value); + break; + case "CREDIT": + credits.Add(value); + break; + case "CREDITID": + creditIds.Add(value); + _file.AddCreditId(value); + break; + default: + throw new InvalidDataException(nameof(key)); + } + } + }; + foreach (var credit in credits.Zip(creditIds, (str, id) => (str, id))) + { + _file.SetCredit(credit.id, credit.str); + } + } + + private string ReadString(Stream stream) + { + int len = ReadInt(stream); + string s = ReadString(stream, len, IsUsingLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode); + ReadInt(stream); // padding + return s; + } + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs new file mode 100644 index 00000000..5e727a72 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs @@ -0,0 +1,96 @@ +using PckStudio.Classes.FileTypes; +using PckStudio.Classes.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.IO.PCK +{ + internal class PCKAudioFileWriter : StreamDataWriter + { + + private PCKAudioFile _file; + private static readonly List LUT = new List + { + "CUENAME", + "CREDIT", + "CREDITID" + }; + + public static void Write(Stream stream, PCKAudioFile file, bool isLittleEndian) + { + new PCKAudioFileWriter(file, isLittleEndian).WriteToStream(stream); + } + + private PCKAudioFileWriter(PCKAudioFile file, bool isLittleEndian) : base(isLittleEndian) + { + _file = file; + } + + private void WriteToStream(Stream stream) + { + WriteInt(stream, _file.type); + WriteLookUpTable(stream); + WriteCategories(stream); + WriteCategorySongs(stream); + } + + private void WriteString(Stream stream, string s) + { + WriteInt(stream, s.Length); + WriteString(stream, s, IsUsingLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode); + WriteInt(stream, 0); // padding + } + + private void WriteLookUpTable(Stream stream) + { + WriteInt(stream, 3); + for (int i = 0; i < 3; i++) + { + WriteInt(stream, i); + WriteString(stream, LUT[i]); + } + } + + private void WriteCategories(Stream stream) + { + WriteInt(stream, _file.GetCategoryCount()); + foreach (var category in _file.Categories) + { + if (category is null) continue; + WriteInt(stream, (int)category.parameterType); + WriteInt(stream, (int)category.audioType); + WriteString(stream, category.Name); + } + } + + private void WriteCategorySongs(Stream stream) + { + bool addCredit = true; + foreach (var category in _file.Categories) + { + if (category is null) continue; + WriteInt(stream, category.SongNames.Count + (addCredit ? _file.Credits.Count * 2 : 0)); + foreach (var name in category.SongNames) + { + WriteInt(stream, LUT.IndexOf("CUENAME")); + WriteString(stream, name); + } + if (addCredit) + { + foreach (var credit in _file.Credits) + { + WriteInt(stream, LUT.IndexOf("CREDIT")); + WriteString(stream, credit.Value); + WriteInt(stream, LUT.IndexOf("CREDITID")); + WriteString(stream, credit.Key); + } + } + addCredit = false; + } + } + } +} diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs index 10b1b1fc..496bd304 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs @@ -9,9 +9,11 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MetroFramework.Forms; -using PckStudio; +using System.Collections; using PckStudio.Classes.FileTypes; using PckStudio.Classes.IO; +using PckStudio.Classes.IO.PCK; +using System.Diagnostics; // Audio Editor by MattNL // additional work and optimization by Miku-666 @@ -21,77 +23,124 @@ namespace PckStudio.Forms.Utilities public partial class AudioEditor : MetroForm { public bool saved = false; - public string credits = ""; public string defaultType = "yes"; - string WorkingDir = ""; string tempDir = ""; - PCKFile audioPCK = null; - PCKFile.FileData audioPCKFile; - bool _isLittleEndian; - public List cats = new List(); - public class NodeSorter : System.Collections.IComparer + PCKAudioFile audioFile = null; + PCKFile.FileData audioPCK; + LOCFile loc; + bool _isLittleEndian = false; + + public class CategorySorter : IComparer { public int Compare(object x, object y) { - if (x == null || y == null) return -1; - return ((x as TreeNode).Tag as PCKFile.FileData).type.CompareTo(((y as TreeNode).Tag as PCKFile.FileData).type); + if (x is TreeNode xt && y is TreeNode yt && + xt.Tag is PCKAudioFile.AudioCategory xcategory && + yt.Tag is PCKAudioFile.AudioCategory ycategory) + return xcategory.audioType.CompareTo(ycategory.audioType); + return -1; } } - public static readonly List Categories = new List - { - "Overworld", // 0 - "Nether", // 1 - "End", // 2 - "Creative", // 3 - "Menu/Loading", // 4 - "Battle", // 5 - "Tumble", // 6 - "Glide", // 7 - "Unused?" // 8 + public static readonly List Categories = new List + { + "Overworld", + "Nether", + "End", + "Creative", + "Menu/Loading", + "Battle", + "Tumble", + "Glide", + "Unused?" }; - internal string GetCategoryFromId(int categoryId) - { - return categoryId > -1 && categoryId < Categories.Count ? Categories[categoryId] : "Not valid"; - } + private string GetCategoryFromId(PCKAudioFile.AudioCategory.EAudioType categoryId) + { + return categoryId >= PCKAudioFile.AudioCategory.EAudioType.Overworld + && categoryId <= PCKAudioFile.AudioCategory.EAudioType.Unused ? Categories[(int)categoryId] : "Not valid"; + } - internal int GetCategoryId(string category) - { - return Categories.IndexOf(category); - } + private PCKAudioFile.AudioCategory.EAudioType GetCategoryId(string category) + { + return (PCKAudioFile.AudioCategory.EAudioType)Categories.IndexOf(category); + } - public static PCKFile.FileData CreateAudioPck(bool isLittle) + public static PCKFile.FileData CreateAudioPck(bool isLittle) { // create actual valid pck file structure - PCKFile audioPck = new PCKFile(1); // 1 = audio.pck - //audioPck.meta_data.Add("CUENAME"); - //audioPck.meta_data.Add("CREDIT"); - //audioPck.meta_data.Add("CREDITID"); - audioPck.Files.Add(new PCKFile.FileData("", 0)); - audioPck.Files.Add(new PCKFile.FileData("", 1)); - audioPck.Files.Add(new PCKFile.FileData("", 2)); - - // create a file data entry for current open pck file - PCKFile.FileData audioFileData = new PCKFile.FileData("audio.pck", 8); + PCKAudioFile audioPck = new PCKAudioFile(); + audioPck.AddCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld); + audioPck.AddCategory(PCKAudioFile.AudioCategory.EAudioType.Nether); + audioPck.AddCategory(PCKAudioFile.AudioCategory.EAudioType.End); + PCKFile.FileData pckFileData = new PCKFile.FileData("audio.pck", 8); using (var stream = new MemoryStream()) { - PCKFileWriter.Write(stream, audioPck, isLittle); - audioFileData.SetData(stream.ToArray()); + PCKAudioFileWriter.Write(stream, audioPck, isLittle); + pckFileData.SetData(stream.ToArray()); } - return audioFileData; + return pckFileData; } /// /// Overload that creates a new audio.pck file /// - /// - /// public AudioEditor(LOCFile locFile, bool isLittleEndian) : this(CreateAudioPck(isLittleEndian), locFile, isLittleEndian) { - } + public AudioEditor(PCKFile.FileData file, LOCFile locFile, bool isLittleEndian) + { + InitializeComponent(); + loc = locFile; + tempDir = Path.Combine(Directory.GetCurrentDirectory(), "temp"); + _isLittleEndian = isLittleEndian; + try + { + handleUtilFiles(); + //library = LoadLibrary(Path.Combine(tempDir, "mss32.dll")); + } + catch (IOException ex) + { + MessageBox.Show("Failed to get Binka conversion files", "Exception thrown"); + Close(); + } + if (isLittleEndian) Text += " (PS4/Vita)"; + + audioPCK = file; + using (var stream = new MemoryStream(file.data)) + { + audioFile = PCKAudioFileReader.Read(stream, isLittleEndian); + } + + foreach (var category in audioFile.Categories) + { + if (category is null) continue; + if (category.Name == "include_overworld" && + category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative && + audioFile.Categories[0] is PCKAudioFile.AudioCategory overworldCategory) + { + foreach(var name in category.SongNames.ToList()) + { + if (overworldCategory.SongNames.Contains(name)) + category.SongNames.Remove(name); + } + playOverworldInCreative.Checked = true; + } + + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType)); + treeNode.Tag = category; + treeNode.ImageIndex = (int)category.audioType; + treeNode.SelectedImageIndex = (int)category.audioType; + treeView1.Nodes.Add(treeNode); + } + + playOverworldInCreative.Enabled = audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Creative); + + treeView1.TreeViewNodeSorter = new CategorySorter(); + treeView1.Sort(); + } + // https://stackoverflow.com/a/25064568 by Alik Khilazhev -MattNL private void ExtractResource(string resName, string fName) { @@ -108,13 +157,13 @@ namespace PckStudio.Forms.Utilities private void handleUtilFiles(bool extractFiles = true) { - string asiPath = Path.Combine(tempDir, "binkawin.asi"); - string mssPath = Path.Combine(tempDir, "mss32.dll"); + //string asiPath = Path.Combine(tempDir, "binkawin.asi"); + //string mssPath = Path.Combine(tempDir, "mss32.dll"); string encoderPath = Path.Combine(tempDir, "binka_encode.exe"); // Deletes files so that System.IO exceptions are avoided - if (File.Exists(asiPath)) File.Delete(asiPath); - if (File.Exists(mssPath)) File.Delete(mssPath); + //if (File.Exists(asiPath)) File.Delete(asiPath); + //if (File.Exists(mssPath)) File.Delete(mssPath); if (File.Exists(encoderPath)) File.Delete(encoderPath); if (Directory.Exists(tempDir)) Directory.Delete(tempDir); @@ -151,165 +200,65 @@ namespace PckStudio.Forms.Utilities else MessageBox.Show("\"" + entry.Text + ".binka\" does not exist in the \"Data\" folder", "File missing"); } - LOCFile loc; - public AudioEditor(PCKFile.FileData MineFile, LOCFile locFile, bool isLittleEndian) - { - loc = locFile; - WorkingDir = Directory.GetCurrentDirectory(); - tempDir = Path.Combine(WorkingDir, "temp"); - try - { - handleUtilFiles(); - //library = LoadLibrary(Path.Combine(tempDir, "mss32.dll")); - } - catch (IOException ex) - { - MessageBox.Show("Failed to get Binka conversion files", "Exception thrown"); - this.Close(); - } - - _isLittleEndian = isLittleEndian; - if (isLittleEndian) Text += " (PS4/Vita)"; - InitializeComponent(); - audioPCKFile = MineFile; - using (var stream = new MemoryStream(audioPCKFile.data)) - { - audioPCK = PCKFileReader.Read(stream, isLittleEndian); - } - - //if (!audioPCK.meta_data.Contains("CUENAME") || audioPCK.type != 1) - //{ - // throw new Exception("This is not a valid audio.pck file"); - //} - foreach (PCKFile.FileData categoryFile in audioPCK.Files) - { - string CatString = GetCategoryFromId(categoryFile.type); - Console.WriteLine($"Category Found: {CatString} ({categoryFile.type})."); - foreach (var property in categoryFile.properties.ToArray()) - { - if (property.Item1 == "CREDITID") - { - loc.RemoveLocKey(property.Item2); - categoryFile.properties.Remove(property); - } - else if (property.Item1 == "CREDIT") - { - credits += property.Item2 + "\n"; - categoryFile.properties.Remove(property); - } - } - if (cats.Contains(GetCategoryFromId(categoryFile.type))) - { - Console.WriteLine("Duplicate category found, " + CatString + ". Combining..."); - audioPCK.Files.Remove(categoryFile); - audioPCK.Files.Find(category => category.filepath == GetCategoryFromId(categoryFile.type)).properties = categoryFile.properties; - } - else - { - if (categoryFile.filepath == "include_overworld" && categoryFile.type == 3) - { - PCKFile.FileData overworldMF = audioPCK.Files.Find(file => file.type == 0); - - foreach(ValueTuple property in categoryFile.properties.ToList()) - { - if (overworldMF.properties.Contains(property)) categoryFile.properties.Remove(property); - } - - playOverworldInCreative.Checked = true; - } - - TreeNode treeNode = new TreeNode(CatString); - treeNode.Tag = categoryFile; - treeNode.ImageIndex = categoryFile.type; - treeNode.SelectedImageIndex = categoryFile.type; - treeView1.Nodes.Add(treeNode); - cats.Add(GetCategoryFromId(categoryFile.type)); - } - } - - playOverworldInCreative.Enabled = cats.Contains(GetCategoryFromId(3)); - - treeView1.TreeViewNodeSorter = new NodeSorter(); - treeView1.Sort(); - } - private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { treeView2.Nodes.Clear(); - PCKFile.FileData mineFile = (PCKFile.FileData)e.Node.Tag; - foreach (var entry in mineFile.properties) + if (e.Node.Tag is PCKAudioFile.AudioCategory category) + foreach (var name in category.SongNames) { - var property = (ValueTuple)entry; - TreeNode meta = new TreeNode(); - meta.Text = property.Item2; - meta.Tag = entry; - treeView2.Nodes.Add(meta); + treeView2.Nodes.Add(name); } - credits = credits.TrimEnd('\n'); if (treeView2.Nodes.Count > 0) treeView2.SelectedNode = treeView2.Nodes[0]; } private void addCategoryStripMenuItem_Click(object sender, EventArgs e) { - try - { - string[] avalible = Categories.FindAll(str => - { - return !cats.Contains(str); - }).ToArray(); - addCategory add = new addCategory(avalible); //sets category adding dialog + string[] avalible = Categories.FindAll(str => !audioFile.HasCategory(GetCategoryId(str)) ).ToArray(); + if (avalible.Length > 0) + { + using addCategory add = new addCategory(avalible); //sets category adding dialog if (add.ShowDialog() == DialogResult.OK) - cats.Add(add.Category); - PCKFile.FileData file = new PCKFile.FileData(add.Category, GetCategoryId(add.Category)); - TreeNode addNode = new TreeNode(file.filepath) { Tag = file }; - audioPCK.Files.Add(file); - addNode.ImageIndex = GetCategoryId(add.Category); - addNode.SelectedImageIndex = GetCategoryId(add.Category); - treeView1.Nodes.Add(addNode); - treeView1.Sort(); - add.Dispose(); // diposes generated metadata adding dialog data - playOverworldInCreative.Enabled = cats.Contains(GetCategoryFromId(3)); + audioFile.AddCategory(GetCategoryId(add.Category)); } - catch (Exception ex) + else { - Console.WriteLine(ex.Message); MessageBox.Show("All possible categories are used", "There are no more categories that could be added"); } } private void addEntryMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode == null && !(treeView1.SelectedNode.Tag is PCKFile.FileData)) return; - - MainForm parent = Owner.Owner as MainForm; // Gets the MainForm so we can access the Save Location - string DataDirectory = Path.Combine(Path.GetDirectoryName(parent.saveLocation), "Data"); - if (!Directory.Exists(DataDirectory)) + if (treeView1.SelectedNode is TreeNode t && t.Tag is PCKAudioFile.AudioCategory && + // Gets the MainForm so we can access the Save Location + Owner.Owner is MainForm parent) { - MessageBox.Show("There is not a \"Data\" folder present in the pack folder", "Folder missing"); - return; + string DataDirectory = Path.Combine(Path.GetDirectoryName(parent.saveLocation), "Data"); + if (!Directory.Exists(DataDirectory)) + { + MessageBox.Show("There is not a \"Data\" folder present in the pack folder", "Folder missing"); + return; + } + + OpenFileDialog ofn = new OpenFileDialog(); + ofn.Multiselect = true; + ofn.Filter = "BINKA files (*.binka)|*.binka|WAV files (*.wav)|*.wav"; + ofn.Title = "Please choose WAV or BINKA files to add to your pack"; + ofn.ShowDialog(); + ofn.Dispose(); + if (string.IsNullOrEmpty(ofn.FileName)) return; // Return if name is null or if the user cancels + + ProcessEntries(ofn.FileNames, DataDirectory); } - - OpenFileDialog ofn = new OpenFileDialog(); - ofn.Multiselect = true; - ofn.Filter = "BINKA files (*.binka)|*.binka|WAV files (*.wav)|*.wav"; - ofn.Title = "Please choose WAV or BINKA files to add to your pack"; - ofn.ShowDialog(); - ofn.Dispose(); - if (String.IsNullOrEmpty(ofn.FileName)) return; // Return if name is null or if the user cancels - - ProcessEntries(ofn.FileNames, DataDirectory); } private void removeCategoryStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode == null) return; // makes sure you don't run this if there is nothing to delete - cats.Remove(treeView1.SelectedNode.Text); - if (audioPCK.Files.Remove((PCKFile.FileData)treeView1.SelectedNode.Tag)) + if (treeView1.SelectedNode is TreeNode main && + audioFile.RemoveCategory(GetCategoryId(treeView1.SelectedNode.Text))) { treeView2.Nodes.Clear(); - treeView1.SelectedNode.Remove(); + main.Remove(); } - playOverworldInCreative.Enabled = cats.Contains(GetCategoryFromId(3)); } public void treeView2_KeyDown(object sender, KeyEventArgs e) @@ -320,16 +269,13 @@ namespace PckStudio.Forms.Utilities private void removeEntryMenuItem_Click(object sender, EventArgs e) { - var mainNode = treeView1.SelectedNode; - var subNode = treeView2.SelectedNode; - if (subNode != null && - subNode.Tag is ValueTuple && - mainNode.Tag is PCKFile.FileData) + if (treeView1.SelectedNode is TreeNode main && + treeView2.SelectedNode is TreeNode sub && + sub.Tag is string s && + main.Tag is PCKAudioFile.AudioCategory category) { - var file = mainNode.Tag as PCKFile.FileData; - var property = (ValueTuple)subNode.Tag; - if (file.properties.Remove(property)) - subNode.Remove(); + if (category.SongNames.Remove(s)) + sub.Remove(); } } @@ -361,12 +307,14 @@ namespace PckStudio.Forms.Utilities int error_code = 0; await Task.Run(() => { - var process = new System.Diagnostics.Process(); - process.StartInfo.FileName = Path.Combine(tempDir, "binka_encode.exe"); - process.StartInfo.Arguments = "\"" + file + "\" \"" + new_loc + "\""; - process.StartInfo.UseShellExecute = true; - process.StartInfo.CreateNoWindow = true; - process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + var process = Process.Start(new ProcessStartInfo + { + FileName = Path.Combine(tempDir, "binka_encode.exe"), + Arguments = $"\"{file}\" \"{new_loc}\"", + UseShellExecute = true, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }); process.Start(); process.WaitForExit(); }); @@ -384,78 +332,74 @@ namespace PckStudio.Forms.Utilities File.Copy(file, Path.Combine(DataDirectory, Path.GetFileName(file))); } - TreeNode meta = new TreeNode(Path.GetFileNameWithoutExtension(file)); - var property = new ValueTuple("CUENAME", Path.GetFileNameWithoutExtension(file)); - meta.Tag = property; - treeView2.Nodes.Add(meta); - (treeView1.SelectedNode.Tag as PCKFile.FileData).properties.Add(property); + var songName = Path.GetFileNameWithoutExtension(file); + if (treeView1.SelectedNode is TreeNode t && t.Tag is PCKAudioFile.AudioCategory category) + { + category.SongNames.Add(songName); + treeView2.Nodes.Add(songName); + } } } } private void Binka_DragDrop(object sender, DragEventArgs e) { - if (treeView1.SelectedNode == null && !(treeView1.SelectedNode.Tag is PCKFile.FileData)) return; - - MainForm parent = Owner.Owner as MainForm; // Gets the MainForm so we can access the Save Location - string DataDirectory = Path.Combine(Path.GetDirectoryName(parent.saveLocation), "Data"); - if (!Directory.Exists(DataDirectory)) + if (treeView1.SelectedNode is TreeNode t && t.Tag is PCKFile.FileData && + // Gets the MainForm so we can access the Save Location + Owner.Owner is MainForm parent) { - MessageBox.Show("There is not a \"Data\" folder present in the pack folder", "Folder missing"); - return; - } + string DataDirectory = Path.Combine(Path.GetDirectoryName(parent.saveLocation), "Data"); + if (!Directory.Exists(DataDirectory)) + { + MessageBox.Show("There is not a \"Data\" folder present in the pack folder", "Folder missing"); + return; + } - ProcessEntries((string[])e.Data.GetData(DataFormats.FileDrop, false), DataDirectory); + ProcessEntries((string[])e.Data.GetData(DataFormats.FileDrop, false), DataDirectory); + } } private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { - if(!cats.Contains(GetCategoryFromId(0)) || - !cats.Contains(GetCategoryFromId(1)) || - !cats.Contains(GetCategoryFromId(2))) + if(!audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld) || + !audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Nether) || + !audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.End)) { MessageBox.Show("The game will crash upon loading your pack if the Overworld, Nether and End categories don't all exist.", "Mandatory Categories Missing"); return; } - bool emptyCat = false; - - List new_order = audioPCK.Files.OrderBy(fd => fd.type).ToList(); - - audioPCK.Files.Clear(); - - foreach (PCKFile.FileData mf in new_order) + PCKAudioFile.AudioCategory overworldCategory = audioFile.GetCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld); + foreach (var category in audioFile.Categories) { - audioPCK.Files.Add(mf); - if (mf.properties.Count == 0) emptyCat = true; + if (category is null) continue; + category.Name = ""; + if (playOverworldInCreative.Checked && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative) + { + foreach (var name in overworldCategory.SongNames) + { + if (!category.SongNames.Contains(name)) + { + category.SongNames.Add(name); + Console.WriteLine(name); + } + } + category.Name = "include_overworld"; + } } + bool emptyCat = false; + if (emptyCat) { MessageBox.Show("The game will crash upon loading your pack if a category is empty", "Empty Category"); return; } - using (StringReader reader = new StringReader(credits)) - { - string line; - int creditCount = 1; - while ((line = reader.ReadLine()) != null) - { - var credit = ("CREDIT", line); - string credit_id = "IDS_CREDIT" + (creditCount > 1 ? creditCount.ToString() : ""); - var creditid = ("CREDITID", credit_id); - audioPCK.Files[0].properties.Add(credit); - audioPCK.Files[0].properties.Add(creditid); - loc.AddLocKey(credit_id, line); - creditCount++; - Console.WriteLine(line); - } - } using (var stream = new MemoryStream()) { - PCKFileWriter.Write(stream, audioPCK, _isLittleEndian); - audioPCKFile.SetData(stream.ToArray()); + PCKAudioFileWriter.Write(stream, audioFile, _isLittleEndian); + audioPCK.SetData(stream.ToArray()); } saved = true; } @@ -477,39 +421,16 @@ namespace PckStudio.Forms.Utilities private void creditsEditorToolStripMenuItem_Click(object sender, EventArgs e) { - creditsEditor prompt = new creditsEditor(credits); - prompt.ShowDialog(); - credits = prompt.Credits; + var credits = string.Join("\n", audioFile.GetCredits()); + using creditsEditor prompt = new creditsEditor(credits); + if (prompt.ShowDialog() == DialogResult.OK) + audioFile.SetCredits(prompt.Credits.Split('\n')); } private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) { - if (saved != true) return; - PCKFile.FileData overworldMF = new PCKFile.FileData("", -1); - - foreach (PCKFile.FileData mf in audioPCK.Files) - { - mf.filepath = ""; - if (playOverworldInCreative.Checked && mf.type == 0) overworldMF = mf; - if (playOverworldInCreative.Checked && mf.type == 3 && overworldMF.type != -1) - { - foreach (ValueTuple property in overworldMF.properties) - { - if (property.Item1 == "CUENAME" && !mf.properties.Contains(property)) - { - mf.properties.Add(property); - Console.WriteLine(property.Item2); - } - } - mf.filepath = "include_overworld"; - } - } - - using (var stream = new MemoryStream()) - { - PCKFileWriter.Write(stream, audioPCK, _isLittleEndian); - audioPCKFile.SetData(stream.ToArray()); - } + if (saved) return; + saveToolStripMenuItem1_Click(sender, e); } } } diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index b5a97d46..88cd4914 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -140,10 +140,13 @@ + + + From 20806d68382c24f3a83df1f4addda4bef5e56428 Mon Sep 17 00:00:00 2001 From: Miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:42:04 +0200 Subject: [PATCH 02/16] Update CI to run on any branch --- .github/workflows/CI.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6f71acf9..19ec69e6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,9 +1,6 @@ name: .NET -on: - pull_request: - push: - branches: [ "main" ] +on: [push, pull_request] jobs: build: From 61f02c19c93abd1f470d758e772d8592b620ffb8 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Aug 2022 00:13:41 +0200 Subject: [PATCH 03/16] Fix AddingDuplicate Error when setting credits and add `GetCreditsString` Property --- MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs | 3 ++- MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs index fbf5c9cb..53c9ec52 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs @@ -59,6 +59,7 @@ namespace PckStudio.Classes.FileTypes } public string[] GetCredits() => Credits.Values.ToArray(); + public string GetCreditsString() => string.Join("\n", Credits.Values.ToArray()); public void AddCredits(params string[] credits) { @@ -101,7 +102,7 @@ namespace PckStudio.Classes.FileTypes public void AddCredit(string credit) { - Credits.Add($"IDS_CREDIT{(Credits.Count > 1 ? $"_{Credits.Count}" : string.Empty)}", credit); + Credits.Add($"IDS_CREDIT{(Credits.Count > 0 ? $"_{Credits.Count+1}" : string.Empty)}", credit); } public void AddCreditId(string creditId) => Credits.Add(creditId, string.Empty); diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs index 496bd304..d2809444 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs @@ -421,10 +421,10 @@ namespace PckStudio.Forms.Utilities private void creditsEditorToolStripMenuItem_Click(object sender, EventArgs e) { - var credits = string.Join("\n", audioFile.GetCredits()); - using creditsEditor prompt = new creditsEditor(credits); - if (prompt.ShowDialog() == DialogResult.OK) - audioFile.SetCredits(prompt.Credits.Split('\n')); + var credits = audioFile.GetCreditsString(); + using (creditsEditor prompt = new creditsEditor(credits)) + if (prompt.ShowDialog() == DialogResult.OK) + audioFile.SetCredits(prompt.Credits.Split('\n')); } private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) From 8522fabd601c71ae93d59edd32cc065897e020a8 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Aug 2022 01:04:51 +0200 Subject: [PATCH 04/16] Move AudioEditor to `Forms/Editor` and related files to `Additional-Popups` and renamed some namespaces related to `Additional-Popups` --- .../Audio/addCategory.Designer.cs | 2 +- .../Audio/addCategory.cs | 2 +- .../Audio/addCategory.resx | 0 .../Audio/creditsEditor.Designer.cs | 2 +- .../Audio/creditsEditor.cs | 2 +- .../Audio/creditsEditor.resx | 0 .../Audio/pleaseWait.Designer.cs | 2 +- .../Audio/pleaseWait.cs | 2 +- .../Audio/pleaseWait.resx | 0 .../Grf/AddParameter.Designer.cs | 2 +- .../Additional-Popups/Grf/AddParameter.cs | 2 +- .../Audio => Editor}/AudioEditor.Designer.cs | 2 +- .../Audio => Editor}/AudioEditor.cs | 21 +++++++--------- .../Audio => Editor}/AudioEditor.resx | 0 .../Forms/Editor/GRFEditor.cs | 2 +- MinecraftUSkinEditor/MainForm.cs | 5 ++-- MinecraftUSkinEditor/PckStudio.csproj | 24 +++++++++---------- 17 files changed, 33 insertions(+), 37 deletions(-) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/addCategory.Designer.cs (98%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/addCategory.cs (94%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/addCategory.resx (100%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/creditsEditor.Designer.cs (98%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/creditsEditor.cs (92%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/creditsEditor.resx (100%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/pleaseWait.Designer.cs (97%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/pleaseWait.cs (87%) rename MinecraftUSkinEditor/Forms/{Utilities => Additional-Popups}/Audio/pleaseWait.resx (100%) rename MinecraftUSkinEditor/Forms/{Utilities/Audio => Editor}/AudioEditor.Designer.cs (99%) rename MinecraftUSkinEditor/Forms/{Utilities/Audio => Editor}/AudioEditor.cs (96%) rename MinecraftUSkinEditor/Forms/{Utilities/Audio => Editor}/AudioEditor.resx (100%) diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.Designer.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.Designer.cs similarity index 98% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.Designer.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.Designer.cs index 225e34bb..cb7dbe12 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.Designer.cs @@ -1,4 +1,4 @@ -namespace PckStudio +namespace PckStudio.Forms.Additional_Popups.Audio { partial class addCategory { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.cs similarity index 94% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.cs index e0030883..aecd9c6b 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.cs @@ -10,7 +10,7 @@ using System.Windows.Forms; // Audio Editor by MattNL -namespace PckStudio +namespace PckStudio.Forms.Additional_Popups.Audio { public partial class addCategory : MetroFramework.Forms.MetroForm { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.resx b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.resx similarity index 100% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/addCategory.resx rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/addCategory.resx diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.Designer.cs similarity index 98% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.Designer.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.Designer.cs index 9287ccd5..72ab8658 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.Designer.cs @@ -1,4 +1,4 @@ -namespace PckStudio +namespace PckStudio.Forms.Additional_Popups.Audio { partial class creditsEditor { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.cs similarity index 92% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.cs index 8503a1b9..c769d246 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.cs @@ -10,7 +10,7 @@ using System.Windows.Forms; // Audio Editor by MattNL -namespace PckStudio +namespace PckStudio.Forms.Additional_Popups.Audio { public partial class creditsEditor : MetroFramework.Forms.MetroForm { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.resx b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.resx similarity index 100% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/creditsEditor.resx rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/creditsEditor.resx diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.Designer.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.Designer.cs similarity index 97% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.Designer.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.Designer.cs index 9b76cde6..3e8cd5fd 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.Designer.cs @@ -1,4 +1,4 @@ -namespace PckStudio.Forms.Utilities.Audio +namespace PckStudio.Forms.Additional_Popups.Audio { partial class pleaseWait { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.cs similarity index 87% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.cs rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.cs index 1c351e45..23fe5fcd 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using MetroFramework.Forms; -namespace PckStudio.Forms.Utilities.Audio +namespace PckStudio.Forms.Additional_Popups.Audio { public partial class pleaseWait : MetroForm { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.resx b/MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.resx similarity index 100% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/pleaseWait.resx rename to MinecraftUSkinEditor/Forms/Additional-Popups/Audio/pleaseWait.resx diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.Designer.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.Designer.cs index 5f33767f..0e4fac52 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.Designer.cs @@ -1,4 +1,4 @@ -namespace PckStudio.Forms.Utilities.Grf +namespace PckStudio.Forms.Additional_Popups.Grf { partial class AddParameter { diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.cs index 322fdf44..6a7c2252 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/Grf/AddParameter.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace PckStudio.Forms.Utilities.Grf +namespace PckStudio.Forms.Additional_Popups.Grf { public partial class AddParameter : MetroFramework.Forms.MetroForm { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs similarity index 99% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs rename to MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs index 024a9c19..9afe8a3a 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs @@ -1,5 +1,5 @@  -namespace PckStudio.Forms.Utilities +namespace PckStudio.Forms.Editor { partial class AudioEditor { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs similarity index 96% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs rename to MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index d2809444..4cf09777 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -1,24 +1,21 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Diagnostics; using MetroFramework.Forms; using System.Collections; using PckStudio.Classes.FileTypes; -using PckStudio.Classes.IO; using PckStudio.Classes.IO.PCK; -using System.Diagnostics; +using PckStudio.Forms.Additional_Popups.Audio; // Audio Editor by MattNL // additional work and optimization by Miku-666 -namespace PckStudio.Forms.Utilities +namespace PckStudio.Forms.Editor { public partial class AudioEditor : MetroForm { @@ -56,17 +53,17 @@ namespace PckStudio.Forms.Utilities }; private string GetCategoryFromId(PCKAudioFile.AudioCategory.EAudioType categoryId) - { - return categoryId >= PCKAudioFile.AudioCategory.EAudioType.Overworld - && categoryId <= PCKAudioFile.AudioCategory.EAudioType.Unused ? Categories[(int)categoryId] : "Not valid"; - } + => categoryId >= PCKAudioFile.AudioCategory.EAudioType.Overworld && + categoryId <= PCKAudioFile.AudioCategory.EAudioType.Unused + ? Categories[(int)categoryId] + : "Not valid"; private PCKAudioFile.AudioCategory.EAudioType GetCategoryId(string category) { return (PCKAudioFile.AudioCategory.EAudioType)Categories.IndexOf(category); } - public static PCKFile.FileData CreateAudioPck(bool isLittle) + public static PCKFile.FileData CreateAudioPck(bool isLittle) { // create actual valid pck file structure PCKAudioFile audioPck = new PCKAudioFile(); @@ -301,7 +298,7 @@ namespace PckStudio.Forms.Utilities if (Path.GetExtension(file) == ".wav") // Convert Wave to BINKA { Cursor.Current = Cursors.WaitCursor; - Audio.pleaseWait waitDiag = new Audio.pleaseWait(); + pleaseWait waitDiag = new pleaseWait(); waitDiag.Show(this); int error_code = 0; diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx similarity index 100% rename from MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx rename to MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx diff --git a/MinecraftUSkinEditor/Forms/Editor/GRFEditor.cs b/MinecraftUSkinEditor/Forms/Editor/GRFEditor.cs index 12ab3162..0e0fa29e 100644 --- a/MinecraftUSkinEditor/Forms/Editor/GRFEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/GRFEditor.cs @@ -1,6 +1,6 @@ using PckStudio.Classes.FileTypes; using PckStudio.Classes.IO.GRF; -using PckStudio.Forms.Utilities.Grf; +using PckStudio.Forms.Additional_Popups.Grf; using RichPresenceClient; using System; using System.Collections.Generic; diff --git a/MinecraftUSkinEditor/MainForm.cs b/MinecraftUSkinEditor/MainForm.cs index cec9986d..bce20f95 100644 --- a/MinecraftUSkinEditor/MainForm.cs +++ b/MinecraftUSkinEditor/MainForm.cs @@ -8,15 +8,14 @@ using System.Drawing.Drawing2D; using System.Diagnostics; using PckStudio.Properties; using Ohana3DS_Rebirth.Ohana; -using PckStudio.Forms; using System.Drawing.Imaging; using RichPresenceClient; using PckStudio.Classes.FileTypes; using PckStudio.Classes.IO; using PckStudio.Classes.IO.LOC; -using PckStudio.Forms.Utilities; using PckStudio.Classes.IO.GRF; -using PckStudio.Classes.Utils; +using PckStudio.Forms; +using PckStudio.Forms.Utilities; using PckStudio.Forms.Editor; namespace PckStudio diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index 88cd4914..589b6ce3 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -233,16 +233,16 @@ SetBulkSpeed.cs - + Form - + creditsEditor.cs - + Form - + addCategory.cs @@ -281,10 +281,10 @@ AddParameter.cs - + Form - + pleaseWait.cs @@ -329,10 +329,10 @@ FrameEditor.cs - + Form - + AudioEditor.cs @@ -458,11 +458,11 @@ SetBulkSpeed.cs - + creditsEditor.cs Designer - + addCategory.cs @@ -494,7 +494,7 @@ AddParameter.cs - + pleaseWait.cs @@ -529,7 +529,7 @@ FrameEditor.cs - + AudioEditor.cs Designer From a7a4c565e93e28068d5f4e492a2a42e91882d5bb Mon Sep 17 00:00:00 2001 From: MattNL Date: Fri, 5 Aug 2022 23:07:25 -0400 Subject: [PATCH 05/16] Fixed verify tool in audio editor --- MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 4cf09777..79e4cfca 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -29,7 +29,7 @@ namespace PckStudio.Forms.Editor public class CategorySorter : IComparer { - public int Compare(object x, object y) + public int Compare(object x, object y) // Sorts Tree Nodes by Audio Type { if (x is TreeNode xt && y is TreeNode yt && xt.Tag is PCKAudioFile.AudioCategory xcategory && @@ -102,7 +102,6 @@ namespace PckStudio.Forms.Editor MessageBox.Show("Failed to get Binka conversion files", "Exception thrown"); Close(); } - if (isLittleEndian) Text += " (PS4/Vita)"; audioPCK = file; using (var stream = new MemoryStream(file.data)) @@ -181,7 +180,7 @@ namespace PckStudio.Forms.Editor private void verifyFileLocationToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode.Tag == null || !(treeView1.SelectedNode.Tag is PCKFile.FileData) || !(treeView2.SelectedNode.Tag is ValueTuple)) return; + if (treeView1.SelectedNode.Tag == null || treeView2.SelectedNode.Tag == null) return; var entry = treeView2.SelectedNode; MainForm parent = Owner.Owner as MainForm; // Gets the MainForm so we can access the Save Location From 6466dfcf8e4a65bb26764a7fce7db2173e970d5c Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Aug 2022 06:23:41 +0200 Subject: [PATCH 06/16] Simplefied `PCKAudioFile.Categories` and removed null check when looping over `PCKAudioFile.Categories` --- .../{AudioPCKFile.cs => PCKAudioFile.cs} | 16 ++++-------- .../Classes/IO/PCK/PCKAudioFileReader.cs | 1 - .../Classes/IO/PCK/PCKAudioFileWriter.cs | 4 +-- .../Forms/Editor/AudioEditor.cs | 25 +++---------------- MinecraftUSkinEditor/PckStudio.csproj | 2 +- 5 files changed, 10 insertions(+), 38 deletions(-) rename MinecraftUSkinEditor/Classes/FileTypes/{AudioPCKFile.cs => PCKAudioFile.cs} (91%) diff --git a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs similarity index 91% rename from MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs rename to MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs index 53c9ec52..d81db2cf 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs @@ -16,7 +16,8 @@ namespace PckStudio.Classes.FileTypes public readonly int type = 1; - public AudioCategory[] Categories { get; } = new AudioCategory[8]; + public AudioCategory[] Categories => Array.FindAll(_categories, c => c is not null); + private AudioCategory[] _categories { get; } = new AudioCategory[8]; public Dictionary Credits { get; } = new Dictionary(); @@ -117,7 +118,7 @@ namespace PckStudio.Classes.FileTypes if (category < AudioCategory.EAudioType.Overworld || category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); - return Categories[(int)category]; + return _categories[(int)category]; } /// @@ -131,13 +132,6 @@ namespace PckStudio.Classes.FileTypes audioCategory = null; return false; } - - public int GetCategoryCount() - { - int count = 0; - Array.ForEach(Categories, c => { if (c is not null) count++; }); - return count; - } /// True when category was created, otherwise false /// @@ -147,7 +141,7 @@ namespace PckStudio.Classes.FileTypes category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); bool exists = HasCategory(category); - if (!exists) Categories[(int)category] = new AudioCategory(parameterType, category); + if (!exists) _categories[(int)category] = new AudioCategory(parameterType, category); return !exists; } @@ -161,7 +155,7 @@ namespace PckStudio.Classes.FileTypes public bool RemoveCategory(AudioCategory.EAudioType category) { bool exists = HasCategory(category); - if (exists) Categories[(int)category] = null; + if (exists) _categories[(int)category] = null; return exists; } diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs index ab7fee3e..bfa23923 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -75,7 +75,6 @@ namespace PckStudio.Classes.IO.PCK List creditIds = new List(); foreach (var c in _file.Categories) { - if (c is null) continue; int audioCount = ReadInt(stream); for (; 0 < audioCount; audioCount--) { diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs index 5e727a72..18628ec4 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs @@ -57,10 +57,9 @@ namespace PckStudio.Classes.IO.PCK private void WriteCategories(Stream stream) { - WriteInt(stream, _file.GetCategoryCount()); + WriteInt(stream, _file.Categories.Length); foreach (var category in _file.Categories) { - if (category is null) continue; WriteInt(stream, (int)category.parameterType); WriteInt(stream, (int)category.audioType); WriteString(stream, category.Name); @@ -72,7 +71,6 @@ namespace PckStudio.Classes.IO.PCK bool addCredit = true; foreach (var category in _file.Categories) { - if (category is null) continue; WriteInt(stream, category.SongNames.Count + (addCredit ? _file.Credits.Count * 2 : 0)); foreach (var name in category.SongNames) { diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 4cf09777..95df3e26 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -27,18 +27,6 @@ namespace PckStudio.Forms.Editor LOCFile loc; bool _isLittleEndian = false; - public class CategorySorter : IComparer - { - public int Compare(object x, object y) - { - if (x is TreeNode xt && y is TreeNode yt && - xt.Tag is PCKAudioFile.AudioCategory xcategory && - yt.Tag is PCKAudioFile.AudioCategory ycategory) - return xcategory.audioType.CompareTo(ycategory.audioType); - return -1; - } - } - public static readonly List Categories = new List { "Overworld", @@ -112,10 +100,9 @@ namespace PckStudio.Forms.Editor foreach (var category in audioFile.Categories) { - if (category is null) continue; if (category.Name == "include_overworld" && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative && - audioFile.Categories[0] is PCKAudioFile.AudioCategory overworldCategory) + audioFile.TryGetCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld, out PCKAudioFile.AudioCategory overworldCategory)) { foreach(var name in category.SongNames.ToList()) { @@ -125,17 +112,12 @@ namespace PckStudio.Forms.Editor playOverworldInCreative.Checked = true; } - TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType)); + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType), (int)category.audioType, (int)category.audioType); treeNode.Tag = category; - treeNode.ImageIndex = (int)category.audioType; - treeNode.SelectedImageIndex = (int)category.audioType; treeView1.Nodes.Add(treeNode); } playOverworldInCreative.Enabled = audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Creative); - - treeView1.TreeViewNodeSorter = new CategorySorter(); - treeView1.Sort(); } // https://stackoverflow.com/a/25064568 by Alik Khilazhev -MattNL @@ -213,7 +195,7 @@ namespace PckStudio.Forms.Editor string[] avalible = Categories.FindAll(str => !audioFile.HasCategory(GetCategoryId(str)) ).ToArray(); if (avalible.Length > 0) { - using addCategory add = new addCategory(avalible); //sets category adding dialog + using addCategory add = new addCategory(avalible); if (add.ShowDialog() == DialogResult.OK) audioFile.AddCategory(GetCategoryId(add.Category)); } @@ -369,7 +351,6 @@ namespace PckStudio.Forms.Editor PCKAudioFile.AudioCategory overworldCategory = audioFile.GetCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld); foreach (var category in audioFile.Categories) { - if (category is null) continue; category.Name = ""; if (playOverworldInCreative.Checked && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative) { diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index 589b6ce3..6dd425cd 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -140,7 +140,7 @@ - + From 46496d1e5f085e295fe959ab9d6b1cc1a87f40ef Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Aug 2022 06:38:25 +0200 Subject: [PATCH 07/16] Fixed Index Out of Range Exception when retriving available categories --- .../Classes/FileTypes/PCKAudioFile.cs | 2 +- MinecraftUSkinEditor/MainForm.cs | 22 ++++++------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs index d81db2cf..1fab8740 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs @@ -17,7 +17,7 @@ namespace PckStudio.Classes.FileTypes public readonly int type = 1; public AudioCategory[] Categories => Array.FindAll(_categories, c => c is not null); - private AudioCategory[] _categories { get; } = new AudioCategory[8]; + private AudioCategory[] _categories { get; } = new AudioCategory[9]; public Dictionary Credits { get; } = new Dictionary(); diff --git a/MinecraftUSkinEditor/MainForm.cs b/MinecraftUSkinEditor/MainForm.cs index bce20f95..4cb4bd9e 100644 --- a/MinecraftUSkinEditor/MainForm.cs +++ b/MinecraftUSkinEditor/MainForm.cs @@ -589,24 +589,16 @@ namespace PckStudio break; case 8 when file.filepath == "audio.pck": - try - { - if (!TryGetLocFile(out LOCFile locFile)) - throw new Exception("No .loc File found."); - AudioEditor audioEditor = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked); - audioEditor.ShowDialog(this); - if (audioEditor.saved) TrySetLocFile(locFile); - audioEditor.Dispose(); - } - catch (Exception ex) - { - MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + if (!TryGetLocFile(out LOCFile locFile)) + throw new Exception("No .loc File found."); + AudioEditor audioEditor = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked); + audioEditor.ShowDialog(this); + if (audioEditor.saved) TrySetLocFile(locFile); + audioEditor.Dispose(); break; case 9 when file.filepath == "colours.col": - if (file.size == 0) + if (file.FileSize == 0) { MessageBox.Show("No Color data found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); From 55faf154e61007a0c2db4786e5451c4120d9545c Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Aug 2022 06:38:25 +0200 Subject: [PATCH 08/16] Fixed Index Out of Range Exception when retriving available categories --- .../Classes/FileTypes/PCKAudioFile.cs | 2 +- MinecraftUSkinEditor/MainForm.cs | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs index d81db2cf..1fab8740 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs @@ -17,7 +17,7 @@ namespace PckStudio.Classes.FileTypes public readonly int type = 1; public AudioCategory[] Categories => Array.FindAll(_categories, c => c is not null); - private AudioCategory[] _categories { get; } = new AudioCategory[8]; + private AudioCategory[] _categories { get; } = new AudioCategory[9]; public Dictionary Credits { get; } = new Dictionary(); diff --git a/MinecraftUSkinEditor/MainForm.cs b/MinecraftUSkinEditor/MainForm.cs index bce20f95..fb67ed74 100644 --- a/MinecraftUSkinEditor/MainForm.cs +++ b/MinecraftUSkinEditor/MainForm.cs @@ -589,20 +589,12 @@ namespace PckStudio break; case 8 when file.filepath == "audio.pck": - try - { - if (!TryGetLocFile(out LOCFile locFile)) - throw new Exception("No .loc File found."); - AudioEditor audioEditor = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked); - audioEditor.ShowDialog(this); - if (audioEditor.saved) TrySetLocFile(locFile); - audioEditor.Dispose(); - } - catch (Exception ex) - { - MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + if (!TryGetLocFile(out LOCFile locFile)) + throw new Exception("No .loc File found."); + AudioEditor audioEditor = new AudioEditor(file, locFile, LittleEndianCheckBox.Checked); + audioEditor.ShowDialog(this); + if (audioEditor.saved) TrySetLocFile(locFile); + audioEditor.Dispose(); break; case 9 when file.filepath == "colours.col": From e5b2588b6fe5258e8603087f88ead41a42f790f4 Mon Sep 17 00:00:00 2001 From: MattNL Date: Sat, 6 Aug 2022 15:11:38 -0400 Subject: [PATCH 09/16] Fixed AddCategory feature not making nodes --- MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs | 6 ++++++ MinecraftUSkinEditor/MainForm.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 2977dc49..773d29c2 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -197,6 +197,12 @@ namespace PckStudio.Forms.Editor using addCategory add = new addCategory(avalible); if (add.ShowDialog() == DialogResult.OK) audioFile.AddCategory(GetCategoryId(add.Category)); + else return; + + var category = audioFile.GetCategory(GetCategoryId(add.Category)); + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType), (int)category.audioType, (int)category.audioType); + treeNode.Tag = category; + treeView1.Nodes.Add(treeNode); } else { diff --git a/MinecraftUSkinEditor/MainForm.cs b/MinecraftUSkinEditor/MainForm.cs index 4cb4bd9e..fb67ed74 100644 --- a/MinecraftUSkinEditor/MainForm.cs +++ b/MinecraftUSkinEditor/MainForm.cs @@ -598,7 +598,7 @@ namespace PckStudio break; case 9 when file.filepath == "colours.col": - if (file.FileSize == 0) + if (file.size == 0) { MessageBox.Show("No Color data found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); From 63fac543a869d5a81562da2e8134752c51812310 Mon Sep 17 00:00:00 2001 From: MattNL Date: Mon, 8 Aug 2022 12:39:56 -0400 Subject: [PATCH 10/16] Several small Audio Editor fixes --- .../Forms/Editor/AudioEditor.Designer.cs | 1 + .../Forms/Editor/AudioEditor.cs | 37 +++++++++++-------- .../Forms/Editor/AudioEditor.resx | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs index 9afe8a3a..bb4417b0 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs @@ -63,6 +63,7 @@ namespace PckStudio.Forms.Editor this.treeView1.LabelEdit = true; this.treeView1.Name = "treeView1"; this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); + this.treeView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown); // // contextMenuStrip1 // diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 773d29c2..c7fccafe 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -245,6 +245,12 @@ namespace PckStudio.Forms.Editor } } + private void treeView1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete) + removeCategoryStripMenuItem_Click(sender, e); + } + public void treeView2_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) @@ -253,13 +259,10 @@ namespace PckStudio.Forms.Editor private void removeEntryMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode is TreeNode main && - treeView2.SelectedNode is TreeNode sub && - sub.Tag is string s && - main.Tag is PCKAudioFile.AudioCategory category) + if (treeView2.SelectedNode != null && treeView1.SelectedNode.Tag is PCKAudioFile.AudioCategory category) { - if (category.SongNames.Remove(s)) - sub.Remove(); + category.SongNames.Remove(treeView2.SelectedNode.Text); + treeView2.SelectedNode.Remove(); } } @@ -273,11 +276,15 @@ namespace PckStudio.Forms.Editor bool duplicate_song = false; // To handle if a file already in the pack is dropped back in if (File.Exists(new_loc)) { - duplicate_song = File.ReadAllBytes(file).Length == File.ReadAllBytes(new_loc).Length; - if (!duplicate_song) + duplicate_song = File.ReadAllBytes(file) == File.ReadAllBytes(new_loc); + if (duplicate_song) { - DialogResult user_prompt = MessageBox.Show("\"" + Path.GetFileNameWithoutExtension(file) + ".binka\" already exists. Continuing will replace the existing file. Are you sure you want to continue moving the file? By pressing no, you will skip this file. You can also cancel all pending file operations.", "File already exists", MessageBoxButtons.YesNoCancel); - if (user_prompt == DialogResult.Cancel) break; + DialogResult user_prompt = MessageBox.Show("\"" + Path.GetFileNameWithoutExtension(file) + ".binka\" already exists. Continuing will replace the existing file. Are you sure you want to continue moving the file? By pressing no, the song entry will be added without moving the file. You can also cancel this operation and all files in queue.", "File already exists", MessageBoxButtons.YesNoCancel); + while (user_prompt == DialogResult.None) ; // Stops the editor from adding or processing the file until the user had made their choice + if (user_prompt == DialogResult.Cancel) + { + break; + } else if (user_prompt == DialogResult.No) continue; } } @@ -328,9 +335,9 @@ namespace PckStudio.Forms.Editor private void Binka_DragDrop(object sender, DragEventArgs e) { - if (treeView1.SelectedNode is TreeNode t && t.Tag is PCKFile.FileData && - // Gets the MainForm so we can access the Save Location - Owner.Owner is MainForm parent) + //MessageBox.Show((Owner.Owner as MainForm).saveLocation); + // Gets the MainForm so we can access the Save Location + if (treeView1.SelectedNode != null && Owner.Owner is MainForm parent) { string DataDirectory = Path.Combine(Path.GetDirectoryName(parent.saveLocation), "Data"); if (!Directory.Exists(DataDirectory)) @@ -349,7 +356,7 @@ namespace PckStudio.Forms.Editor !audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Nether) || !audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.End)) { - MessageBox.Show("The game will crash upon loading your pack if the Overworld, Nether and End categories don't all exist.", "Mandatory Categories Missing"); + MessageBox.Show("Your changes were not saved. The game will crash when loading your pack if the Overworld, Nether and End categories don't all exist with at least one valid song.", "Mandatory Categories Missing"); return; } @@ -412,7 +419,7 @@ namespace PckStudio.Forms.Editor private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) { - if (saved) return; + if (!saved) return; saveToolStripMenuItem1_Click(sender, e); } } diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx index 37e149c3..838a1802 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.resx @@ -166,7 +166,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk - MAAAAk1TRnQBSQFMAgEBCQEAATgBAAE4AQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA + MAAAAk1TRnQBSQFMAgEBCQEAAUABAAFAAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABMAMAAQEBAAEgBgABMBIAAzgB/wM1Af8DNQH/AzMB/wMwAf8DLwH/Ay0B/wMtAf8DJAH/AzsB/wM4 Af8DNQH/Ay0B/wMnAf8DNgH/AzIB/8AAAzgB/wN/Af8DeQH/A3kB/wN5Af8DcQH/A3EB/wN5Af8DeQH/ A3EB/wNxAf8DcQH/A3kB/wN5Af8DfwH/AzIB/8AAAzIB/wN2Af8DsAH/A7AB/wOvAf8DrwH/A68B/wOo From beca901b809a5cbd6ce8d220a5c85664962dc0a4 Mon Sep 17 00:00:00 2001 From: MattNL Date: Tue, 9 Aug 2022 04:00:16 -0400 Subject: [PATCH 11/16] fixed audio editor save issue --- MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index c7fccafe..63919d5e 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -419,8 +419,7 @@ namespace PckStudio.Forms.Editor private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) { - if (!saved) return; - saveToolStripMenuItem1_Click(sender, e); + if (saved) saveToolStripMenuItem1_Click(sender, e); } } } From 3ed5598a977f40cd7086651d13bb5166f5ae2d78 Mon Sep 17 00:00:00 2001 From: MattNL Date: Tue, 9 Aug 2022 05:16:10 -0400 Subject: [PATCH 12/16] slight change to audio file classes this also fixes the "Include Overworld songs in Creative" feature. The code for that functionality was already perfect, so that hasn't been touched at all. Just needed to adjust the class a little. (: --- .../Classes/FileTypes/PCKAudioFile.cs | 14 +++++--------- .../Classes/IO/PCK/PCKAudioFileReader.cs | 3 +-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs index 1fab8740..43ea24b4 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs @@ -47,17 +47,13 @@ namespace PckStudio.Classes.FileTypes public EAudioType audioType { get; } public List SongNames { get; } = new List(); - public AudioCategory(EAudioParameterType parameterType, EAudioType audioType) + public AudioCategory(string name, EAudioParameterType parameterType, EAudioType audioType) { + this.Name = name; this.parameterType = parameterType; this.audioType = audioType; } - - public AudioCategory(string name, EAudioParameterType parameterType, EAudioType audioType) : this(parameterType, audioType) - { - Name = name; - } - } + } public string[] GetCredits() => Credits.Values.ToArray(); public string GetCreditsString() => string.Join("\n", Credits.Values.ToArray()); @@ -135,13 +131,13 @@ namespace PckStudio.Classes.FileTypes /// True when category was created, otherwise false /// - public bool AddCategory(AudioCategory.EAudioParameterType parameterType, AudioCategory.EAudioType category) + public bool AddCategory(AudioCategory.EAudioParameterType parameterType, AudioCategory.EAudioType category, string name = "") { if (category < AudioCategory.EAudioType.Overworld || category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); bool exists = HasCategory(category); - if (!exists) _categories[(int)category] = new AudioCategory(parameterType, category); + if (!exists) _categories[(int)category] = new AudioCategory(name, parameterType, category); return !exists; } diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs index bfa23923..5137ba9b 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -64,8 +64,7 @@ namespace PckStudio.Classes.IO.PCK var parameterType = (PCKAudioFile.AudioCategory.EAudioParameterType)ReadInt(stream); var audioType = (PCKAudioFile.AudioCategory.EAudioType)ReadInt(stream); string name = ReadString(stream); - Console.WriteLine(name); - _file.AddCategory(parameterType, audioType); + _file.AddCategory(parameterType, audioType, name); } } From 7c0d3d46d4cc159f0f13b7f66c3bd90f67360c2f Mon Sep 17 00:00:00 2001 From: MattNL Date: Wed, 10 Aug 2022 14:27:24 -0400 Subject: [PATCH 13/16] fix to song order issue in AudioFileReader --- MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs index 5137ba9b..d7d6ada6 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -56,6 +56,7 @@ namespace PckStudio.Classes.IO.PCK } } + private List original_categories = new List(); private void ReadCategories(Stream stream) { int categoryEntryCount = ReadInt(stream); @@ -64,6 +65,9 @@ namespace PckStudio.Classes.IO.PCK var parameterType = (PCKAudioFile.AudioCategory.EAudioParameterType)ReadInt(stream); var audioType = (PCKAudioFile.AudioCategory.EAudioType)ReadInt(stream); string name = ReadString(stream); + // AddCategory puts the file's categories out of order and causes some songs to be put in the wrong categories + // This is my simple fix for the issue. + original_categories.Add(new PCKAudioFile.AudioCategory(name, parameterType, audioType)); _file.AddCategory(parameterType, audioType, name); } } @@ -72,7 +76,7 @@ namespace PckStudio.Classes.IO.PCK { List credits = new List(); List creditIds = new List(); - foreach (var c in _file.Categories) + foreach (var c in original_categories) { int audioCount = ReadInt(stream); for (; 0 < audioCount; audioCount--) @@ -82,7 +86,7 @@ namespace PckStudio.Classes.IO.PCK switch (key) { case "CUENAME": - c.SongNames.Add(value); + _file.GetCategory(c.audioType).SongNames.Add(value); break; case "CREDIT": credits.Add(value); From a7cdae416ba11ff6144a715016a4028123ce511e Mon Sep 17 00:00:00 2001 From: MattNL Date: Wed, 10 Aug 2022 14:44:05 -0400 Subject: [PATCH 14/16] optimized list in PCKAudioFileReader --- MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs index d7d6ada6..8b704a0a 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -56,7 +56,7 @@ namespace PckStudio.Classes.IO.PCK } } - private List original_categories = new List(); + private List original_audio_types = new List(); private void ReadCategories(Stream stream) { int categoryEntryCount = ReadInt(stream); @@ -67,7 +67,7 @@ namespace PckStudio.Classes.IO.PCK string name = ReadString(stream); // AddCategory puts the file's categories out of order and causes some songs to be put in the wrong categories // This is my simple fix for the issue. - original_categories.Add(new PCKAudioFile.AudioCategory(name, parameterType, audioType)); + original_audio_types.Add(audioType); _file.AddCategory(parameterType, audioType, name); } } @@ -76,7 +76,7 @@ namespace PckStudio.Classes.IO.PCK { List credits = new List(); List creditIds = new List(); - foreach (var c in original_categories) + foreach (var c in original_audio_types) { int audioCount = ReadInt(stream); for (; 0 < audioCount; audioCount--) @@ -86,7 +86,7 @@ namespace PckStudio.Classes.IO.PCK switch (key) { case "CUENAME": - _file.GetCategory(c.audioType).SongNames.Add(value); + _file.GetCategory(c).SongNames.Add(value); break; case "CREDIT": credits.Add(value); From b52de5bc0fb11c97cda1acca7d012de14fc6a672 Mon Sep 17 00:00:00 2001 From: MattNL Date: Wed, 10 Aug 2022 18:36:40 -0400 Subject: [PATCH 15/16] fixed small saving bug in AudioEditor --- .../Forms/Editor/AudioEditor.Designer.cs | 1 - MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs index bb4417b0..6d84aeb7 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.Designer.cs @@ -122,7 +122,6 @@ namespace PckStudio.Forms.Editor // resources.ApplyResources(this.saveToolStripMenuItem1, "saveToolStripMenuItem1"); this.saveToolStripMenuItem1.Name = "saveToolStripMenuItem1"; - this.saveToolStripMenuItem1.Click += new System.EventHandler(this.saveToolStripMenuItem1_Click); // // toolsToolStripMenuItem // diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 63919d5e..cbf8e8bd 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -77,6 +77,9 @@ namespace PckStudio.Forms.Editor public AudioEditor(PCKFile.FileData file, LOCFile locFile, bool isLittleEndian) { InitializeComponent(); + // so the Creative songs aren't combined until after the forms are closed. + // this will prevent potential problems with editing the categories after merging. + this.saveToolStripMenuItem1.Click += (sender, e) => saveToolStripMenuItem1_Click(sender, e, false); loc = locFile; tempDir = Path.Combine(Directory.GetCurrentDirectory(), "temp"); _isLittleEndian = isLittleEndian; @@ -350,7 +353,7 @@ namespace PckStudio.Forms.Editor } } - private void saveToolStripMenuItem1_Click(object sender, EventArgs e) + private void saveToolStripMenuItem1_Click(object sender, EventArgs e, bool combineCreative) { if(!audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld) || !audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Nether) || @@ -364,7 +367,7 @@ namespace PckStudio.Forms.Editor foreach (var category in audioFile.Categories) { category.Name = ""; - if (playOverworldInCreative.Checked && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative) + if (combineCreative && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative) { foreach (var name in overworldCategory.SongNames) { @@ -419,7 +422,7 @@ namespace PckStudio.Forms.Editor private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) { - if (saved) saveToolStripMenuItem1_Click(sender, e); + if (saved) saveToolStripMenuItem1_Click(sender, e, playOverworldInCreative.Checked); } } } From 00cc82b6c8e8c08a9e32d785ee48375b2e1a64dd Mon Sep 17 00:00:00 2001 From: Felix Miller Date: Wed, 10 Aug 2022 23:59:27 -0400 Subject: [PATCH 16/16] Creates a method of parsing and creating Bedrock JSON Sound files --- .../Classes/IO/Sounds/SoundIO.cs | 26 +++++++++++++++++++ .../Classes/IO/Sounds/Sounds.cs | 21 +++++++++++++++ MinecraftUSkinEditor/PckStudio.csproj | 2 ++ 3 files changed, 49 insertions(+) create mode 100644 MinecraftUSkinEditor/Classes/IO/Sounds/SoundIO.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/Sounds/Sounds.cs diff --git a/MinecraftUSkinEditor/Classes/IO/Sounds/SoundIO.cs b/MinecraftUSkinEditor/Classes/IO/Sounds/SoundIO.cs new file mode 100644 index 00000000..5815d356 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/Sounds/SoundIO.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace PckStudio.Classes.IO.Sounds +{ + public class SoundIO + { + public Dictionary Read(string Filepath) + { + var jObj = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(File.ReadAllText(Filepath)); + var dict = JsonConvert.DeserializeObject>(jObj.ToString()); + + return dict; + } + + public string Serialize(Dictionary input) + { + return JsonConvert.SerializeObject(input, Formatting.Indented); + } + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/Sounds/Sounds.cs b/MinecraftUSkinEditor/Classes/IO/Sounds/Sounds.cs new file mode 100644 index 00000000..a040eff3 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/Sounds/Sounds.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.IO.Sounds +{ + public class Type + { + public bool replace { get; set; } + public List sounds = new List(); + } + + public class Sound + { + public string name { get; set; } + public string type { get; set; } + public bool stream { get; set; } + } +} diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index c1e113f4..0188da44 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -149,6 +149,8 @@ + +