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

CON parsing redo #360

Merged
merged 2 commits into from
May 22, 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
5 changes: 3 additions & 2 deletions Assets/Script/Audio/Bass/BassAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Cysharp.Threading.Tasks;
using ManagedBass;
using UnityEngine;
using XboxSTFS;
using static XboxSTFS.XboxSTFSParser;
using YARG.Serialization;
using YARG.Song;
using Debug = UnityEngine.Debug;
Expand Down Expand Up @@ -222,8 +224,7 @@ public void LoadMogg(ExtractedConSongEntry exConSong, bool isSpeedUp, params Son
byte[] moggArray;
if (exConSong is ConSongEntry conSong) {
if (!conSong.UsingUpdateMogg)
moggArray = XboxCONInnerFileRetriever.RetrieveFile(conSong.Location,
conSong.MoggFileSize, conSong.MoggFileMemBlockOffsets)[conSong.MoggAddressAudioOffset..];
moggArray = XboxSTFSParser.GetFile(conSong.Location, conSong.FLMogg)[conSong.MoggAddressAudioOffset..];
else moggArray = File.ReadAllBytes(conSong.MoggPath)[conSong.MoggAddressAudioOffset..];
} else {
moggArray = File.ReadAllBytes(exConSong.MoggPath)[exConSong.MoggAddressAudioOffset..];
Expand Down
6 changes: 3 additions & 3 deletions Assets/Script/Serialization/Parser/MidiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Melanchall.DryWetMidi.Interaction;
using Melanchall.DryWetMidi.MusicTheory;
using UnityEngine;
using XboxSTFS;
using static XboxSTFS.XboxSTFSParser;
using YARG.Chart;
using YARG.Data;
using YARG.DiffDownsample;
Expand All @@ -28,9 +30,7 @@ public MidiParser(SongEntry songEntry, string[] files) : base(songEntry, files)
// get base midi - read it in latin1 if RB, UTF-8 if clon
if (songEntry.SongType == SongType.RbCon) {
var conSong = (ConSongEntry) songEntry;
using var stream = new MemoryStream(XboxCONInnerFileRetriever.RetrieveFile(
conSong.Location, conSong.MidiFileSize, conSong.MidiFileMemBlockOffsets
));
using var stream = new MemoryStream(XboxSTFSParser.GetFile(conSong.Location, conSong.FLMidi));
midi = MidiFile.Read(stream, new ReadingSettings() { TextEncoding = Encoding.GetEncoding("iso-8859-1") });
} else if (songEntry.SongType == SongType.ExtractedRbCon) {
midi = MidiFile.Read(files[0], new ReadingSettings() { TextEncoding = Encoding.GetEncoding("iso-8859-1") });
Expand Down
35 changes: 14 additions & 21 deletions Assets/Script/Serialization/Xbox/XboxCONFileBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using DtxCS.DataTypes;
using UnityEngine;
using XboxSTFS;
using static XboxSTFS.XboxSTFSParser;
using YARG.Song;

namespace YARG.Serialization {
Expand All @@ -15,12 +16,11 @@ public static List<ConSongEntry> BrowseCON(string conName,
Dictionary<SongProUpgrade, DataArray> upgrade_dict){
var songList = new List<ConSongEntry>();
var dtaTree = new DataArray();

STFS theCON = new STFS(conName);
var CONFileListings = XboxSTFSParser.GetCONFileListings(conName);

// Attempt to read upgrades.dta, if it exists
if(theCON.GetFileSize(Path.Combine("songs_upgrades", "upgrades.dta")) > 0){
var dtaUpgradeTree = DTX.FromPlainTextBytes(theCON.GetFile(Path.Combine("songs_upgrades", "upgrades.dta")));
if(CONFileListings.TryGetValue(Path.Combine("songs_upgrades", "upgrades.dta"), out var UpgradeFL)){
var dtaUpgradeTree = DTX.FromPlainTextBytes(XboxSTFSParser.GetFile(conName, UpgradeFL));

// Read each shortname the dta file lists
for (int i = 0; i < dtaUpgradeTree.Count; i++) {
Expand All @@ -30,8 +30,7 @@ public static List<ConSongEntry> BrowseCON(string conName,
upgr.ShortName = currentArray.Name;
upgr.UpgradeMidiPath = Path.Combine("songs_upgrades", $"{currentArray.Name}_plus.mid");
upgr.CONFilePath = conName;
upgr.UpgradeMidiFileSize = theCON.GetFileSize(upgr.UpgradeMidiPath);
upgr.UpgradeMidiFileMemBlockOffsets = theCON.GetMemOffsets(upgr.UpgradeMidiPath);
upgr.UpgradeFL = UpgradeFL;
upgrade_dict.Add(upgr, currentArray);
} catch (Exception e) {
Debug.Log($"Failed to get upgrade, skipping...");
Expand All @@ -42,7 +41,7 @@ public static List<ConSongEntry> BrowseCON(string conName,

// Attempt to read songs.dta
try {
dtaTree = DTX.FromPlainTextBytes(theCON.GetFile(Path.Combine("songs", "songs.dta")));
dtaTree = DTX.FromPlainTextBytes(XboxSTFSParser.GetFile(conName, CONFileListings[Path.Combine("songs", "songs.dta")]));
} catch (Exception e) {
Debug.LogError($"Failed to parse songs.dta for `{conName}`.");
Debug.LogException(e);
Expand Down Expand Up @@ -81,8 +80,7 @@ public static List<ConSongEntry> BrowseCON(string conName,

// capture base midi, and if an update midi was provided, capture that as well
currentSong.NotesFile = Path.Combine("songs", currentSong.Location, $"{currentSong.Location}.mid");
currentSong.MidiFileSize = theCON.GetFileSize(currentSong.NotesFile);
currentSong.MidiFileMemBlockOffsets = theCON.GetMemOffsets(currentSong.NotesFile);
currentSong.FLMidi = CONFileListings[currentSong.NotesFile];
if(songCanBeUpdated && currentSong.DiscUpdate){
string updateMidiPath = Path.Combine(update_folder, currentSong.ShortName, $"{currentSong.ShortName}_update.mid");
if(File.Exists(updateMidiPath)) currentSong.UpdateMidiPath = updateMidiPath;
Expand All @@ -102,16 +100,13 @@ public static List<ConSongEntry> BrowseCON(string conName,
}
if(!currentSong.UsingUpdateMogg){
currentSong.MoggPath = Path.Combine("songs", currentSong.Location, $"{currentSong.Location}.mogg");
currentSong.MoggFileSize = theCON.GetFileSize(currentSong.MoggPath);
currentSong.MoggFileMemBlockOffsets = theCON.GetMemOffsets(currentSong.MoggPath);
currentSong.FLMogg = CONFileListings[currentSong.MoggPath];
}

// capture base image (if one was provided), OR if update image was found, capture that instead
string imgPath = Path.Combine("songs", currentSong.Location, "gen", $"{currentSong.Location}_keep.png_xbox");
currentSong.ImageFileSize = theCON.GetFileSize(imgPath);
currentSong.ImageFileMemBlockOffsets = theCON.GetMemOffsets(imgPath);
if(currentSong.HasAlbumArt && currentSong.ImageFileSize > 0 && currentSong.ImageFileMemBlockOffsets != null)
currentSong.ImagePath = imgPath;
if(CONFileListings.TryGetValue(imgPath, out var imgVal)) currentSong.FLImg = imgVal;
if(currentSong.HasAlbumArt && imgVal != null) currentSong.ImagePath = imgPath;
if(songCanBeUpdated){
string imgUpdatePath = Path.Combine(update_folder, currentSong.ShortName, "gen", $"{currentSong.ShortName}_keep.png_xbox");
if(currentSong.HasAlbumArt && currentSong.AlternatePath){
Expand All @@ -125,13 +120,11 @@ public static List<ConSongEntry> BrowseCON(string conName,

// Parse the mogg
if(!currentSong.UsingUpdateMogg){
using var fs = new FileStream(conName, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
fs.Seek(currentSong.MoggFileMemBlockOffsets[0], SeekOrigin.Begin);
var MoggBytes = XboxSTFSParser.GetMoggHeader(conName, currentSong.FLMogg);

currentSong.MoggHeader = br.ReadInt32();
currentSong.MoggAddressAudioOffset = br.ReadInt32();
currentSong.MoggAudioLength = currentSong.MoggFileSize - currentSong.MoggAddressAudioOffset;
currentSong.MoggHeader = BitConverter.ToInt32(MoggBytes, 0);
currentSong.MoggAddressAudioOffset = BitConverter.ToInt32(MoggBytes, 4);
currentSong.MoggAudioLength = currentSong.FLMogg.size - currentSong.MoggAddressAudioOffset;
}
else{
using var fs = new FileStream(currentSong.MoggPath, FileMode.Open, FileAccess.Read);
Expand Down
46 changes: 0 additions & 46 deletions Assets/Script/Serialization/Xbox/XboxCONInnerFileRetriever.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Script/Serialization/Xbox/XboxCONInnerFileRetriever.cs.meta

This file was deleted.

Loading