-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* starting song upgrades * ex-CONs can now get ex-upgrades * songs_upgrades folder now captures upgrades within CONs * standalone songs_upgrades work * tweak rawfile browser to accept root folder * can now read excon upgrades * can apply upgrades from CON files
- Loading branch information
Showing
10 changed files
with
345 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Assets/Script/Serialization/Xbox/XboxSongUpgradeBrowser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using DtxCS; | ||
using DtxCS.DataTypes; | ||
using UnityEngine; | ||
using XboxSTFS; | ||
using YARG.Data; | ||
using YARG.Song; | ||
|
||
namespace YARG.Serialization { | ||
public static class XboxSongUpgradeBrowser { | ||
public static Dictionary<SongProUpgrade, DataArray> FetchSongUpgrades(string upgrade_folder){ | ||
var dtaTree = new DataArray(); | ||
var UpgradeSongDict = new Dictionary<SongProUpgrade, DataArray>(); | ||
|
||
// TODO: tweak this function so you parse raw upgrades, and THEN upgrades contained within CONs | ||
// FIRST, parse raw upgrades - start by attempting to read upgrades.dta | ||
if(File.Exists(Path.Combine(upgrade_folder, "upgrades.dta"))){ | ||
using var sr = new StreamReader(Path.Combine(upgrade_folder, "upgrades.dta"), Encoding.GetEncoding("iso-8859-1")); | ||
dtaTree = DTX.FromDtaString(sr.ReadToEnd()); | ||
|
||
// Read each shortname the dta file lists | ||
for (int i = 0; i < dtaTree.Count; i++) { | ||
try { | ||
var currentArray = (DataArray) dtaTree[i]; | ||
var upgr = new SongProUpgrade(); | ||
upgr.ShortName = currentArray.Name; | ||
upgr.UpgradeMidiPath = Path.Combine(upgrade_folder, $"{currentArray.Name}_plus.mid"); | ||
UpgradeSongDict.Add(upgr, currentArray); | ||
} catch (Exception e) { | ||
Debug.Log($"Failed to get upgrade, skipping..."); | ||
Debug.LogException(e); | ||
} | ||
} | ||
} | ||
|
||
// THEN, find any loose CONs in this directory and parse those for upgrades as well | ||
foreach (var file in Directory.EnumerateFiles(upgrade_folder)) { | ||
if(Path.GetExtension(file) != ".mid" && Path.GetExtension(file) != ".dta"){ | ||
// for each file found, read first 4 bytes and check for "CON " or "LIVE" | ||
using var fs = new FileStream(file, FileMode.Open, FileAccess.Read); | ||
using var br = new BinaryReader(fs); | ||
string fHeader = Encoding.UTF8.GetString(br.ReadBytes(4)); | ||
if (fHeader == "CON " || fHeader == "LIVE") { | ||
STFS thisUpgradeCON = new STFS(file); | ||
|
||
// attempt to read the CON's upgrades.dta | ||
try { | ||
dtaTree = DTX.FromPlainTextBytes(thisUpgradeCON.GetFile(Path.Combine("songs_upgrades", "upgrades.dta"))); | ||
} catch (Exception e) { | ||
Debug.LogError($"Failed to parse upgrades.dta for `{file}`."); | ||
Debug.LogException(e); | ||
continue; | ||
} | ||
|
||
// Read each shortname the dta file lists | ||
for(int i = 0; i < dtaTree.Count; i++){ | ||
try { | ||
var currentArray = (DataArray) dtaTree[i]; | ||
var upgr = new SongProUpgrade(); | ||
upgr.ShortName = currentArray.Name; | ||
upgr.UpgradeMidiPath = Path.Combine("songs_upgrades", $"{currentArray.Name}_plus.mid"); | ||
upgr.CONFilePath = file; | ||
upgr.UpgradeMidiFileSize = thisUpgradeCON.GetFileSize(upgr.UpgradeMidiPath); | ||
upgr.UpgradeMidiFileMemBlockOffsets = thisUpgradeCON.GetMemOffsets(upgr.UpgradeMidiPath); | ||
UpgradeSongDict.Add(upgr, currentArray); | ||
} catch (Exception e) { | ||
Debug.Log($"Failed to get upgrade, skipping..."); | ||
Debug.LogException(e); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
// Debug.Log($"Song upgrades:"); | ||
// foreach(var item in UpgradeSongDict){ | ||
// Debug.Log($"{item.Key.ShortName} has a pro upgrade"); | ||
// } | ||
|
||
return UpgradeSongDict; | ||
|
||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Script/Serialization/Xbox/XboxSongUpgradeBrowser.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.