Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/YARC-Official/YARG into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed May 14, 2023
2 parents 1146d80 + a43eeef commit 3897e28
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 54 deletions.
16 changes: 9 additions & 7 deletions Assets/Script/Serialization/Xbox/MoggBassInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataArray> dta_update_roots = null){
var Tracks = new Dictionary<string, int[]>();
float[] PanData = null, VolumeData = null;
int[] CrowdChannels = null;
Expand All @@ -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);
}
}
}

Expand Down
27 changes: 8 additions & 19 deletions Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

namespace YARG.Serialization {
public static class XboxCONFileBrowser {
public static List<ConSongEntry> BrowseCON(string conName, string update_folder, List<string> update_shortnames){
public static List<ConSongEntry> BrowseCON(string conName, string update_folder, Dictionary<string, List<DataArray>> update_dict){
var songList = new List<ConSongEntry>();
var dtaTree = new DataArray();
var dtaUpdateTree = new DataArray();

// Attempt to read songs.dta
STFS theCON = new STFS(conName);
Expand All @@ -25,18 +24,6 @@ public static List<ConSongEntry> 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 {
Expand All @@ -46,11 +33,14 @@ public static List<ConSongEntry> 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
Expand Down Expand Up @@ -117,8 +107,7 @@ public static List<ConSongEntry> 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}");

Expand Down
22 changes: 5 additions & 17 deletions Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

namespace YARG.Serialization {
public static class ExCONBrowser {
public static List<ExtractedConSongEntry> BrowseFolder(string folder, string update_folder, List<string> update_shortnames){
public static List<ExtractedConSongEntry> BrowseFolder(string folder, string update_folder, Dictionary<string, List<DataArray>> update_dict){
var songList = new List<ExtractedConSongEntry>();
var dtaTree = new DataArray();
var dtaUpdateTree = new DataArray();

// Attempt to read songs.dta
try {
Expand All @@ -26,18 +25,6 @@ public static List<ExtractedConSongEntry> 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 {
Expand All @@ -46,11 +33,12 @@ public static List<ExtractedConSongEntry> 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:

Expand Down Expand Up @@ -97,7 +85,7 @@ public static List<ExtractedConSongEntry> 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
Expand Down
26 changes: 21 additions & 5 deletions Assets/Script/Serialization/Xbox/XboxSongUpdateBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace YARG.Serialization {
public static class XboxSongUpdateBrowser {
public static List<string> GetUpdatableShortnames(string update_folder){
var songList = new List<string>();
public static Dictionary<string, List<DataArray>> FetchSongUpdates(string update_folder){
var dtaTree = new DataArray();
var UpdateSongDict = new Dictionary<string, List<DataArray>>();

// Attempt to read songs_updates.dta
try {
Expand All @@ -28,14 +28,30 @@ public static List<string> 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<DataArray>();
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;
}
}
}
11 changes: 6 additions & 5 deletions Assets/Script/Song/Scanning/SongScanThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading;
using UnityEngine;
using DtxCS.DataTypes;
using YARG.Serialization;
using YARG.Song.Preparsers;

Expand All @@ -22,7 +23,7 @@ public class SongScanThread {
private int _songsScanned;
private int _errorsEncountered;
private string _updateFolderPath = string.Empty;
private List<string> _updatableSongs = null;
private Dictionary<string, List<DataArray>> _songUpdateDict = new();

private readonly Dictionary<string, List<SongEntry>> _songsByCacheFolder;
private readonly Dictionary<string, List<SongError>> _songErrors;
Expand Down Expand Up @@ -139,8 +140,8 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection<Son
if (_updateFolderPath == string.Empty) {
_updateFolderPath = updatePath;
Debug.Log($"Song updates found at {_updateFolderPath}");
_updatableSongs = XboxSongUpdateBrowser.GetUpdatableShortnames(_updateFolderPath);
Debug.Log($"Total count of song updates found: {_updatableSongs.Count}");
_songUpdateDict = XboxSongUpdateBrowser.FetchSongUpdates(_updateFolderPath);
Debug.Log($"Total count of song updates found: {_songUpdateDict.Count}");
}
}

Expand All @@ -166,7 +167,7 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection<Son
// Raw CON folder, so don't scan anymore subdirectories here
string songsPath = Path.Combine(subDir, "songs");
if (File.Exists(Path.Combine(songsPath, "songs.dta"))) {
List<ExtractedConSongEntry> files = ExCONBrowser.BrowseFolder(songsPath, _updateFolderPath, _updatableSongs);
List<ExtractedConSongEntry> files = ExCONBrowser.BrowseFolder(songsPath, _updateFolderPath, _songUpdateDict);

foreach (ExtractedConSongEntry file in files) {
// validate that the song is good to add in-game
Expand Down Expand Up @@ -199,7 +200,7 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection<Son
using var br = new BinaryReader(fs);
string fHeader = Encoding.UTF8.GetString(br.ReadBytes(4));
if (fHeader == "CON " || fHeader == "LIVE") {
List<ConSongEntry> SongsInsideCON = XboxCONFileBrowser.BrowseCON(file, _updateFolderPath, _updatableSongs);
List<ConSongEntry> 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) {
Expand Down
3 changes: 2 additions & 1 deletion Assets/Script/ThirdParty/TwitchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using YARG.PlayMode;
using YARG.Song;
using YARG.UI;
using Newtonsoft.Json;

namespace YARG {
public class TwitchController : MonoBehaviour {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3897e28

Please sign in to comment.