Skip to content

Commit

Permalink
add song update functionality (YARC-Official#185) (YARC-Official#221)
Browse files Browse the repository at this point in the history
Co-authored-by: rjkiv <76180273+rjkiv@users.noreply.github.com>
  • Loading branch information
2 people authored and RileyTheFox committed May 1, 2023
1 parent 23b066f commit ec3616d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 13 deletions.
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
20 changes: 10 additions & 10 deletions Assets/Script/Serialization/Xbox/XboxMoggData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class XboxMoggData {
public int Header { get; set; }

private uint MoggSize = 0;
private uint[] MoggOffsets = null;
private uint[] MoggOffsets = null;
private bool isFromCON = false;

public int MoggAddressAudioOffset { get; set; }
Expand All @@ -40,7 +40,7 @@ public XboxMoggData(string str) {
MoggPath = str;
}

public XboxMoggData(string str, uint size, uint[] offsets){
public XboxMoggData(string str, uint size, uint[] offsets) {
MoggPath = str;
MoggSize = size;
MoggOffsets = offsets;
Expand All @@ -50,19 +50,19 @@ public XboxMoggData(string str, uint size, uint[] offsets){
public void ParseMoggHeader() {
using var fs = new FileStream(MoggPath, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
if(isFromCON) fs.Seek(MoggOffsets[0], SeekOrigin.Begin);
if (isFromCON) fs.Seek(MoggOffsets[0], SeekOrigin.Begin);

Header = br.ReadInt32();
MoggAddressAudioOffset = br.ReadInt32();

if(isFromCON) MoggAudioLength = MoggSize - MoggAddressAudioOffset;
if (isFromCON) MoggAudioLength = MoggSize - MoggAddressAudioOffset;
else MoggAudioLength = fs.Length - MoggAddressAudioOffset;
}

public byte[] GetOggDataFromMogg(){
if(!isFromCON) //Raw
public byte[] GetOggDataFromMogg() {
if (!isFromCON) //Raw
return File.ReadAllBytes(MoggPath)[MoggAddressAudioOffset..];
else{ //CON
else { //CON
byte[] f = new byte[MoggSize];
uint lastSize = MoggSize % 0x1000;

Expand All @@ -71,9 +71,9 @@ public byte[] GetOggDataFromMogg(){
using var fs = new FileStream(MoggPath, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs, new ASCIIEncoding());
fs.Seek(MoggOffsets[i], SeekOrigin.Begin);
Array.Copy(br.ReadBytes((int)readLen), 0, f, i*0x1000, (int)readLen);
Array.Copy(br.ReadBytes((int) readLen), 0, f, i * 0x1000, (int) readLen);
});

return f[MoggAddressAudioOffset..];
}
}
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,5 +66,28 @@ 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)
}
}

}
}
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 @@ -42,6 +43,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 @@ -124,6 +127,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 @@ -289,7 +289,9 @@ private static void ReadSongInfo() {
// Rock Band CON rawfiles

// 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

0 comments on commit ec3616d

Please sign in to comment.