From 7eb2a10cd91f048e03b5e89cbbd6a3d0fd5b8626 Mon Sep 17 00:00:00 2001 From: TheFatBastid Date: Sun, 14 May 2023 11:00:20 -0400 Subject: [PATCH 1/2] Changed to JsonConvert from JsonUtiltiy (#320) JsonUtility should not be used. --- Assets/Script/ThirdParty/TwitchController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Script/ThirdParty/TwitchController.cs b/Assets/Script/ThirdParty/TwitchController.cs index 83759045a..6038395ca 100644 --- a/Assets/Script/ThirdParty/TwitchController.cs +++ b/Assets/Script/ThirdParty/TwitchController.cs @@ -5,6 +5,7 @@ using YARG.PlayMode; using YARG.Song; using YARG.UI; +using Newtonsoft.Json; namespace YARG { public class TwitchController : MonoBehaviour { @@ -66,7 +67,7 @@ void OnSongStart(SongEntry song) { } // Convert to JSON - string json = JsonUtility.ToJson(song); + string json = JsonConvert.SerializeObject(song); // Write text to the file writer.Write(str); From a43eeef8c4d060472951542a52cbbc7f4080541a Mon Sep 17 00:00:00 2001 From: rjkiv <76180273+rjkiv@users.noreply.github.com> Date: Sun, 14 May 2023 11:01:02 -0400 Subject: [PATCH 2/2] added support for multiple shortname song arrays (#323) --- .../Xbox/MoggBassInfoGenerator.cs | 16 ++++++----- .../Serialization/Xbox/XboxCONFileBrowser.cs | 27 ++++++------------- .../Serialization/Xbox/XboxRawfileBrowser.cs | 22 ++++----------- .../Xbox/XboxSongUpdateBrowser.cs | 26 ++++++++++++++---- Assets/Script/Song/Scanning/SongScanThread.cs | 11 ++++---- 5 files changed, 49 insertions(+), 53 deletions(-) diff --git a/Assets/Script/Serialization/Xbox/MoggBassInfoGenerator.cs b/Assets/Script/Serialization/Xbox/MoggBassInfoGenerator.cs index 57bf85ff8..174f2decd 100644 --- a/Assets/Script/Serialization/Xbox/MoggBassInfoGenerator.cs +++ b/Assets/Script/Serialization/Xbox/MoggBassInfoGenerator.cs @@ -11,7 +11,7 @@ namespace YARG.Serialization { public static class MoggBASSInfoGenerator { - public static void Generate(ConSongEntry song, DataArray dta, DataArray dta_update_root){ + public static void Generate(ConSongEntry song, DataArray dta, List dta_update_roots = null){ var Tracks = new Dictionary(); float[] PanData = null, VolumeData = null; int[] CrowdChannels = null; @@ -21,12 +21,14 @@ public static void Generate(ConSongEntry song, DataArray dta, DataArray dta_upda dtas_to_parse.Add(dta); // determine whether or not we even NEED to parse the update dta for mogg information - if(dta_update_root != null){ - dta_update = dta_update_root.Array("song"); - if(dta_update != null){ - if(dta_update.Array("tracks") != null || dta_update.Array("pans") != null || - dta_update.Array("vols") != null || dta_update.Array("crowd_channels") != null) - dtas_to_parse.Add(dta_update); + if(dta_update_roots != null){ + foreach(var dta_update_root in dta_update_roots){ + dta_update = dta_update_root.Array("song"); + if(dta_update != null){ + if(dta_update.Array("tracks") != null || dta_update.Array("pans") != null || + dta_update.Array("vols") != null || dta_update.Array("crowd_channels") != null) + dtas_to_parse.Add(dta_update); + } } } diff --git a/Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs b/Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs index ef1cf3d4c..686d1d658 100644 --- a/Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs +++ b/Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs @@ -10,10 +10,9 @@ namespace YARG.Serialization { public static class XboxCONFileBrowser { - public static List BrowseCON(string conName, string update_folder, List update_shortnames){ + public static List BrowseCON(string conName, string update_folder, Dictionary> update_dict){ var songList = new List(); var dtaTree = new DataArray(); - var dtaUpdateTree = new DataArray(); // Attempt to read songs.dta STFS theCON = new STFS(conName); @@ -25,18 +24,6 @@ public static List BrowseCON(string conName, string update_folder, return null; } - // Attempt to read songs_updates.dta, if it exists - if(update_folder != string.Empty){ - try { - using var sr_upd = new StreamReader(Path.Combine(update_folder, "songs_updates.dta"), Encoding.GetEncoding("iso-8859-1")); - dtaUpdateTree = DTX.FromDtaString(sr_upd.ReadToEnd()); - } catch (Exception e_upd) { - Debug.LogError($"Failed to parse songs_updates.dta for `{update_folder}`."); - Debug.LogException(e_upd); - return null; - } - } - // Read each song the dta file lists for (int i = 0; i < dtaTree.Count; i++) { try { @@ -46,11 +33,14 @@ public static List BrowseCON(string conName, string update_folder, ConSongEntry currentSong = XboxDTAParser.ParseFromDta(currentArray); // check if song has applicable updates - bool songCanBeUpdated = (!String.IsNullOrEmpty(update_folder) && (update_shortnames.Find(s => s == currentSong.ShortName) != null)); + bool songCanBeUpdated = (update_dict.TryGetValue(currentSong.ShortName, out var val)); // if shortname was found in songs_updates.dta, update the metadata - if(songCanBeUpdated) - currentSong = XboxDTAParser.ParseFromDta(dtaUpdateTree.Array(currentSong.ShortName), currentSong); + if(songCanBeUpdated){ + foreach(var dtaUpdate in update_dict[currentSong.ShortName]){ + currentSong = XboxDTAParser.ParseFromDta(dtaUpdate, currentSong); + } + } // since Location is currently set to the name of the folder before mid/mogg/png, set those paths now // since we're dealing with a CON and not an ExCON, grab each relevant file's sizes and memory block offsets @@ -117,8 +107,7 @@ public static List BrowseCON(string conName, string update_folder, currentSong.MoggAddressAudioOffset = br.ReadInt32(); currentSong.MoggAudioLength = fs.Length - currentSong.MoggAddressAudioOffset; } - - MoggBASSInfoGenerator.Generate(currentSong, currentArray.Array("song"), dtaUpdateTree.Array(currentSong.ShortName)); + MoggBASSInfoGenerator.Generate(currentSong, currentArray.Array("song"), val); // Debug.Log($"{currentSong.ShortName}:\nMidi path: {currentSong.NotesFile}\nMogg path: {currentSong.MoggPath}\nImage path: {currentSong.ImagePath}"); diff --git a/Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs b/Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs index 60a55af3e..a744413b0 100644 --- a/Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs +++ b/Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs @@ -11,10 +11,9 @@ namespace YARG.Serialization { public static class ExCONBrowser { - public static List BrowseFolder(string folder, string update_folder, List update_shortnames){ + public static List BrowseFolder(string folder, string update_folder, Dictionary> update_dict){ var songList = new List(); var dtaTree = new DataArray(); - var dtaUpdateTree = new DataArray(); // Attempt to read songs.dta try { @@ -26,18 +25,6 @@ public static List BrowseFolder(string folder, string upd return null; } - // Attempt to read songs_updates.dta, if it exists - if(!String.IsNullOrEmpty(update_folder)){ - try { - using var sr_upd = new StreamReader(Path.Combine(update_folder, "songs_updates.dta"), Encoding.GetEncoding("iso-8859-1")); - dtaUpdateTree = DTX.FromDtaString(sr_upd.ReadToEnd()); - } catch (Exception e_upd) { - Debug.LogError($"Failed to parse songs_updates.dta for `{update_folder}`."); - Debug.LogException(e_upd); - return null; - } - } - // Read each song the dta file lists for (int i = 0; i < dtaTree.Count; i++) { try { @@ -46,11 +33,12 @@ public static List BrowseFolder(string folder, string upd var currentSong = XboxDTAParser.ParseFromDta(currentArray); // check if song has applicable updates - bool songCanBeUpdated = (!String.IsNullOrEmpty(update_folder) && (update_shortnames.Find(s => s == currentSong.ShortName) != null)); + bool songCanBeUpdated = (update_dict.TryGetValue(currentSong.ShortName, out var val)); // if shortname was found in songs_updates.dta, update the metadata if(songCanBeUpdated) - currentSong = XboxDTAParser.ParseFromDta(dtaUpdateTree.Array(currentSong.ShortName), currentSong); + foreach(var dtaUpdate in update_dict[currentSong.ShortName]) + currentSong = XboxDTAParser.ParseFromDta(dtaUpdate, currentSong); // since Location is currently set to the name of the folder before mid/mogg/png, set those paths now: @@ -97,7 +85,7 @@ public static List BrowseFolder(string folder, string upd currentSong.MoggHeader = br.ReadInt32(); currentSong.MoggAddressAudioOffset = br.ReadInt32(); currentSong.MoggAudioLength = fs.Length - currentSong.MoggAddressAudioOffset; - MoggBASSInfoGenerator.Generate(currentSong, currentArray.Array("song"), dtaUpdateTree.Array(currentSong.ShortName)); + MoggBASSInfoGenerator.Generate(currentSong, currentArray.Array("song"), val); // will validate the song outside of this class, in SongScanThread.cs // so okay to add to song list for now diff --git a/Assets/Script/Serialization/Xbox/XboxSongUpdateBrowser.cs b/Assets/Script/Serialization/Xbox/XboxSongUpdateBrowser.cs index ec57b7a3f..8a20dc9f1 100644 --- a/Assets/Script/Serialization/Xbox/XboxSongUpdateBrowser.cs +++ b/Assets/Script/Serialization/Xbox/XboxSongUpdateBrowser.cs @@ -11,9 +11,9 @@ namespace YARG.Serialization { public static class XboxSongUpdateBrowser { - public static List GetUpdatableShortnames(string update_folder){ - var songList = new List(); + public static Dictionary> FetchSongUpdates(string update_folder){ var dtaTree = new DataArray(); + var UpdateSongDict = new Dictionary>(); // Attempt to read songs_updates.dta try { @@ -28,14 +28,30 @@ public static List GetUpdatableShortnames(string update_folder){ // Read each shortname the dta file lists for (int i = 0; i < dtaTree.Count; i++) { try { - string currentName = ((DataArray) dtaTree[i]).Name; - songList.Add(currentName); + var currentArray = (DataArray) dtaTree[i]; + string currentName = currentArray.Name; + + if(UpdateSongDict.TryGetValue(currentName, out var value)){ + UpdateSongDict[currentName].Add(currentArray); + } + else { + var dArray = new List(); + dArray.Add(currentArray); + UpdateSongDict.Add(currentName, dArray); + } + } catch (Exception e) { Debug.Log($"Failed to get shortname, skipping..."); Debug.LogException(e); } } - return songList; + + // Debug.Log($"Song updates:"); + // foreach(var item in UpdateSongDict){ + // Debug.Log($"{item.Key} has update array count of {item.Value.Count}"); + // } + + return UpdateSongDict; } } } \ No newline at end of file diff --git a/Assets/Script/Song/Scanning/SongScanThread.cs b/Assets/Script/Song/Scanning/SongScanThread.cs index 22d6709ad..1073cf668 100644 --- a/Assets/Script/Song/Scanning/SongScanThread.cs +++ b/Assets/Script/Song/Scanning/SongScanThread.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using UnityEngine; +using DtxCS.DataTypes; using YARG.Serialization; using YARG.Song.Preparsers; @@ -22,7 +23,7 @@ public class SongScanThread { private int _songsScanned; private int _errorsEncountered; private string _updateFolderPath = string.Empty; - private List _updatableSongs = null; + private Dictionary> _songUpdateDict = new(); private readonly Dictionary> _songsByCacheFolder; private readonly Dictionary> _songErrors; @@ -139,8 +140,8 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection files = ExCONBrowser.BrowseFolder(songsPath, _updateFolderPath, _updatableSongs); + List files = ExCONBrowser.BrowseFolder(songsPath, _updateFolderPath, _songUpdateDict); foreach (ExtractedConSongEntry file in files) { // validate that the song is good to add in-game @@ -199,7 +200,7 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection SongsInsideCON = XboxCONFileBrowser.BrowseCON(file, _updateFolderPath, _updatableSongs); + List SongsInsideCON = XboxCONFileBrowser.BrowseCON(file, _updateFolderPath, _songUpdateDict); // for each CON song that was found (assuming some WERE found) if (SongsInsideCON != null) { foreach (ConSongEntry SongInsideCON in SongsInsideCON) {