Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add song update functionality #185

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Script/Data/SongInfo.Sources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public partial class SongInfo {
{ "tbrbdlc", "The Beatles: Rock Band DLC" },
{ "tbrbcdlc", "The Beatles: Rock Band Custom DLC Project" },
{ "rbacdc", "AC/DC Live: Rock Band Track Pack" },
{ "lrb", "Lego Rock Band" },
{ "lego", "Lego Rock Band" },
{ "rbn", "Rock Band Network" },
{ "ugc", "Rock Band Network 1.0" },
{ "ugc_plus", "Rock Band Network 2.0" },
Expand Down
4 changes: 4 additions & 0 deletions Assets/Script/Serialization/Xbox/XboxMoggData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public XboxMoggData(string str) {
MoggPath = str;
}

public void UpdateMoggPath(string str){
MoggPath = str;
}

public void ParseMoggHeader() {
using var fs = new FileStream(MoggPath, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
Expand Down
48 changes: 47 additions & 1 deletion Assets/Script/Serialization/Xbox/XboxRawfileBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

namespace YARG.Serialization {
public static class XboxRawfileBrowser {
public static List<XboxSong> BrowseFolder(string folder) {
public static List<XboxSong> BrowseFolder(string folder, string folder_update) {
var songList = new List<XboxSong>();
var dtaTree = new DataArray();
var dtaUpdate = new DataArray();

// Attempt to read songs.dta
try {
Expand All @@ -24,11 +25,33 @@ public static List<XboxSong> BrowseFolder(string folder) {
return null;
}

// Attempt to read songs_updates.dta, if update folder was provided
if(folder_update != null){
try {
using var sr = new StreamReader(Path.Combine(folder_update, "songs_updates.dta"), Encoding.GetEncoding("iso-8859-1"));
dtaUpdate = DTX.FromDtaString(sr.ReadToEnd());

Debug.Log("Successfully read update dta");
} catch (Exception ee) {
Debug.LogError($"Failed to parse songs_updates.dta for `{folder_update}`.");
Debug.LogException(ee);
return null;
}
}

// Read each song the dta file lists
for (int i = 0; i < dtaTree.Count; i++) {
try {
var currentArray = (DataArray) dtaTree[i];
var currentSong = new XboxSong(folder, currentArray);

// if updates were provided
if(folder_update != null){
// if dtaUpdate has the matching shortname, update that XboxSong
if(dtaUpdate.Array(currentSong.ShortName) is DataArray dtaMissing){
currentSong.UpdateSong(folder_update, dtaMissing);
}
}

if (currentSong.IsValidSong()) {
songList.Add(currentSong);
Expand All @@ -43,6 +66,29 @@ public static List<XboxSong> BrowseFolder(string folder) {

return songList;
}

public static void BrowseUpdateFolder(string folder, List<XboxSong> baseSongs){
var dtaTree = new DataArray();

// Attempt to read songs_updates.dta
try {
using var sr = new StreamReader(Path.Combine(folder, "songs_updates.dta"), Encoding.GetEncoding("iso-8859-1"));
dtaTree = DTX.FromDtaString(sr.ReadToEnd());

Debug.Log("Successfully read update dta");
} catch (Exception e) {
Debug.LogError($"Failed to parse songs_updates.dta for `{folder}`.");
Debug.LogException(e);
return;
}

// Read each song the update dta lists
for(int i = 0; i < dtaTree.Count; i++){
Debug.Log(dtaTree[i].Name);
// if(baseSongs.ShortName)
}
}

}
// public static class RockBandSTFS {
// static RockBandSTFS() {}
Expand Down
32 changes: 32 additions & 0 deletions Assets/Script/Serialization/Xbox/XboxSong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace YARG.Serialization {
public class XboxSong {
public string ShortName { get; private set; }
public string MidiFile { get; private set; }
public string MidiUpdateFile { get; private set; }

private string songFolderPath;

Expand Down Expand Up @@ -45,6 +46,37 @@ public XboxSong(string pathName, DataArray dta) {
}
}

public void UpdateSong(string pathUpdateName, DataArray dta_update){
songDta.ParseFromDta(dta_update);
// if dta_update.Array("song") is not null, parse for any MoggDta as well
if(dta_update.Array("song") is DataArray moggUpdateDta)
moggDta.ParseFromDta(moggUpdateDta);

// if extra_authoring has disc_update, grab update midi
if(songDta.discUpdate){
MidiUpdateFile = Path.Combine(pathUpdateName, ShortName, $"{ShortName}_update.mid");
}

// if update mogg exists, grab it and parse it
string moggUpdatePath = Path.Combine(pathUpdateName, ShortName, $"{ShortName}_update.mogg");
if(File.Exists(moggUpdatePath)){
moggDta.UpdateMoggPath(moggUpdatePath);
moggDta.ParseMoggHeader();
// moggDta.ParseFromDta(dta_update.Array("song"));
moggDta.CalculateMoggBassInfo();
}

// if album_art == TRUE AND alternate_path == TRUE, grab update png
if(songDta.albumArt && songDta.alternatePath){
Debug.Log($"new album art, grabbing it now");
// make a new image here, cuz what if an old one exists?
img = new XboxImage(Path.Combine(pathUpdateName, ShortName, "gen", $"{ShortName}_keep.png_xbox"));

// Do some preliminary parsing here in the header to get DXT format, width and height, etc
img.ParseImageHeader();
}
}

public bool IsValidSong() {
// Skip if the song doesn't have notes
if (!File.Exists(MidiFile)) {
Expand Down
25 changes: 25 additions & 0 deletions Assets/Script/Serialization/Xbox/XboxSongData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using DtxCS.DataTypes;
using UnityEngine;

// complete GH DX songs.dta additions:
// artist (songalbum, author (as in chart author), songyear, songgenre, songorigin,
Expand All @@ -27,6 +28,8 @@ public class XboxSongData {
public byte? albumTrackNumber;
public byte vocalParts = 1;
public bool fake = false;
public bool alternatePath = false;
public bool discUpdate = false;
public (uint start, uint end) preview;
public short[] realGuitarTuning, realBassTuning;
public string[] solos;
Expand Down Expand Up @@ -122,6 +125,28 @@ public void ParseFromDta(DataArray dta) {
realBassTuning = new short[4];
for (int b = 0; b < 4; b++) realBassTuning[b] = (short) ((DataAtom) bassTunes[b]).Int;
break;
case "alternate_path":
if (dtaArray[1] is DataSymbol symAltPath)
alternatePath = (symAltPath.Name.ToUpper() == "TRUE");
else if (dtaArray[1] is DataAtom atmAltPath)
alternatePath = (atmAltPath.Int != 0);
break;
case "extra_authoring":
for(int ea = 1; ea < dtaArray.Count; ea++){
if(dtaArray[ea] is DataSymbol symEA){
if(symEA.Name == "disc_update"){
discUpdate = true;
break;
}
}
else if(dtaArray[ea] is DataAtom atmEA){
if(atmEA.String == "disc_update"){
discUpdate = true;
break;
}
}
}
break;
case "quickplay": //used in GH
for (int q = 1; q < dtaArray.Count; q++) {
DataArray innerQPArray = (DataArray) dtaArray[q];
Expand Down
4 changes: 3 additions & 1 deletion Assets/Script/SongLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ private static void ReadSongInfo() {
// Rock Band con file

// Read all of the songs in the file
var files = XboxRawfileBrowser.BrowseFolder(info.path);
// Apply any song updates, if they exist
// Debug.Log($"song path root: {info.root}");
var files = XboxRawfileBrowser.BrowseFolder(info.path, Path.Combine(info.root, "songs_updates"));

// Convert each to a SongInfo
foreach (var file in files) {
Expand Down