Finally got XACT music packs to load in again. Next up is loading in WAV files.

This commit is contained in:
2018-02-03 11:50:56 -08:00
parent 5426a98885
commit 1fb92f7cf7
5 changed files with 100 additions and 27 deletions

View File

@ -49,6 +49,8 @@ namespace StardewSymphonyRemastered.Framework
string rawName = FileName.Substring(0, FileName.Length - 4); string rawName = FileName.Substring(0, FileName.Length - 4);
string cueName = rawName + "CueList.txt"; string cueName = rawName + "CueList.txt";
//Not used as the music pack can change between loads
/*
if (File.Exists(cueName)) if (File.Exists(cueName))
{ {
string[] arr = File.ReadAllLines(cueName); string[] arr = File.ReadAllLines(cueName);
@ -59,6 +61,7 @@ namespace StardewSymphonyRemastered.Framework
} }
return names; return names;
} }
*/
string hexDumpContents = HexDump(array); string hexDumpContents = HexDump(array);
string rawHexName = rawName + "HexDump.txt"; string rawHexName = rawName + "HexDump.txt";
@ -89,20 +92,25 @@ namespace StardewSymphonyRemastered.Framework
foreach (var split in splits) foreach (var split in splits)
{ {
if (split == "") continue; if (split == "") continue;
try try
{ {
Game1.waveBank = musicPack.WaveBank; Game1.waveBank = musicPack.WaveBank;
Game1.soundBank = musicPack.SoundBank; Game1.soundBank = musicPack.SoundBank;
if (Game1.soundBank.GetCue(split) != null) if (Game1.soundBank.GetCue(split) != null)
cleanCueNames.Add(split); {
cleanCueNames.Add(split);
}
reset.Invoke(); reset.Invoke();
} }
catch { } catch(Exception err)
{
reset.Invoke();
}
} }
return cleanCueNames; return cleanCueNames;
} }

View File

@ -223,8 +223,27 @@ namespace StardewSymphonyRemastered.Framework
/// Adds a valid xwb music pack to the list of music packs available. /// Adds a valid xwb music pack to the list of music packs available.
/// </summary> /// </summary>
/// <param name="xwbMusicPack"></param> /// <param name="xwbMusicPack"></param>
public void addMusicPack(XACTMusicPack xwbMusicPack) /// <param name="displayLogInformation">Whether or not to display the process to the console. Will include information from the pack's metadata. Default:False</param>
/// <param name="xwbMusicPack">If displayLogInformation is also true this will display the name of all of the songs in the music pack when it is added in.</param>
public void addMusicPack(XACTMusicPack xwbMusicPack,bool displayLogInformation=false,bool displaySongs=false)
{ {
if (displayLogInformation == true)
{
StardewSymphony.ModMonitor.Log("Adding a new music pack!");
StardewSymphony.ModMonitor.Log(" Name:" + xwbMusicPack.musicPackInformation.name);
StardewSymphony.ModMonitor.Log(" Author:" + xwbMusicPack.musicPackInformation.author);
StardewSymphony.ModMonitor.Log(" Description:" + xwbMusicPack.musicPackInformation.description);
StardewSymphony.ModMonitor.Log(" Version Info:" + xwbMusicPack.musicPackInformation.versionInfo);
StardewSymphony.ModMonitor.Log(" Song List:");
if (displaySongs == true)
{
foreach(var songname in xwbMusicPack.songInformation.listOfSongsWithoutTriggers)
{
StardewSymphony.ModMonitor.Log(" " + songname);
}
}
}
this.musicPacks.Add(xwbMusicPack.musicPackInformation.name,xwbMusicPack); this.musicPacks.Add(xwbMusicPack.musicPackInformation.name,xwbMusicPack);
} }
} }

View File

@ -17,25 +17,23 @@ namespace StardewSymphonyRemastered.Framework
public Microsoft.Xna.Framework.Audio.WaveBank WaveBank; public Microsoft.Xna.Framework.Audio.WaveBank WaveBank;
public Microsoft.Xna.Framework.Audio.SoundBank SoundBank; public Microsoft.Xna.Framework.Audio.SoundBank SoundBank;
public Cue currentCue; public Cue currentCue;
public string WaveBankPath;
//Make Music pack meta data. Includes author, version, description. public string SoundBankPath;
public string XWBPath;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="directoryToXwb"></param> /// <param name="directoryToXwb"></param>
/// <param name="pathToXWB"></param> /// <param name="pathToWaveBank"></param>
public XACTMusicPack(string directoryToXwb,string pathToXWB) /// <param name="pathToSoundBank"></param>
public XACTMusicPack(string directoryToXwb,string pathToWaveBank,string pathToSoundBank)
{ {
this.directory = directoryToXwb; this.directory = directoryToXwb;
this.XWBPath = pathToXWB; this.WaveBankPath = pathToWaveBank;
this.SoundBankPath = pathToSoundBank;
this.songInformation = new SongSpecifics(); this.songInformation = new SongSpecifics();
this.currentCue = null; this.currentCue = null;
this.musicPackInformation = MusicPackMetaData.readFromJson(Path.Combine(directoryToXwb, "MusicPackInformation.json")); this.musicPackInformation = MusicPackMetaData.readFromJson(Path.Combine(directoryToXwb, "MusicPackInformation.json"));
@ -44,6 +42,10 @@ namespace StardewSymphonyRemastered.Framework
StardewSymphony.ModMonitor.Log("Error: MusicPackInformation.json not found at: " + directoryToXwb + ". Blank information will be put in place.",StardewModdingAPI.LogLevel.Warn); StardewSymphony.ModMonitor.Log("Error: MusicPackInformation.json not found at: " + directoryToXwb + ". Blank information will be put in place.",StardewModdingAPI.LogLevel.Warn);
this.musicPackInformation = new MusicPackMetaData("???","???","","0.0.0"); this.musicPackInformation = new MusicPackMetaData("???","???","","0.0.0");
} }
this.WaveBank = new WaveBank(Game1.audioEngine, this.WaveBankPath);
this.SoundBank = new SoundBank(Game1.audioEngine,this.SoundBankPath);
this.loadMusicFiles();
} }
/// <summary> /// <summary>
@ -51,7 +53,7 @@ namespace StardewSymphonyRemastered.Framework
/// </summary> /// </summary>
public override void loadMusicFiles() public override void loadMusicFiles()
{ {
this.songInformation.listOfSongsWithoutTriggers=StardewSymphonyRemastered.Framework.MusicHexProcessor.ProcessSongNamesFromHex(this,StardewSymphony.Reset,this.XWBPath); this.songInformation.listOfSongsWithoutTriggers=StardewSymphonyRemastered.Framework.MusicHexProcessor.ProcessSongNamesFromHex(this,StardewSymphony.Reset,this.SoundBankPath);
} }
/// <summary> /// <summary>
@ -62,7 +64,7 @@ namespace StardewSymphonyRemastered.Framework
private Cue getCue(string name) { private Cue getCue(string name) {
if (this.songInformation.isSongInList(name) == false) if (this.songInformation.isSongInList(name) == false)
{ {
StardewSymphony.ModMonitor.Log("Error! The song " + name + " could not be found in music pack " + this.musicPackInformation.name+". Please ensure that this song is part of this music pack located at: "+ this.XWBPath+ " or contact the music pack author: "+this.musicPackInformation.author,StardewModdingAPI.LogLevel.Error); StardewSymphony.ModMonitor.Log("Error! The song " + name + " could not be found in music pack " + this.musicPackInformation.name+". Please ensure that this song is part of this music pack located at: "+ this.WaveBankPath+ " or contact the music pack author: "+this.musicPackInformation.author,StardewModdingAPI.LogLevel.Error);
return null; return null;
} }
else else

View File

@ -42,6 +42,7 @@ namespace StardewSymphonyRemastered
public static string XACTMusicDirectory; public static string XACTMusicDirectory;
public static string TemplateMusicDirectory; public static string TemplateMusicDirectory;
public bool musicPacksInitialized;
public override void Entry(IModHelper helper) public override void Entry(IModHelper helper)
{ {
@ -52,7 +53,7 @@ namespace StardewSymphonyRemastered
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
musicManager = new MusicManager(); musicManager = new MusicManager();
MusicPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Music"); MusicPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Music");
@ -62,7 +63,24 @@ namespace StardewSymphonyRemastered
this.createDirectories(); this.createDirectories();
this.createBlankXACTTemplate(); this.createBlankXACTTemplate();
musicPacksInitialized = false;
}
private void GameEvents_UpdateTick(object sender, EventArgs e)
{
if (Game1.activeClickableMenu.GetType()!=typeof(StardewValley.Menus.TitleMenu)&& Game1.audioEngine.isNull()) return;
if (musicPacksInitialized == false)
{
initializeMusicPacks();
musicPacksInitialized = true;
}
}
public void initializeMusicPacks()
{
//load in all packs here. //load in all packs here.
loadXACTMusicPacks();
} }
public void createDirectories() public void createDirectories()
@ -80,7 +98,7 @@ namespace StardewSymphonyRemastered
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
if(!File.Exists(Path.Combine(path, "MusicPackInformation.json"))){ if(!File.Exists(Path.Combine(path, "MusicPackInformation.json"))){
MusicPackMetaData blankMetaData = new MusicPackMetaData(); MusicPackMetaData blankMetaData = new MusicPackMetaData("Omegas's Music Data Example","Omegasis","Just a simple example of how metadata is formated for music packs. Feel free to copy and edit this one!","1.0.0 CoolExample");
blankMetaData.writeToJson(Path.Combine(path, "MusicPackInformation.json")); blankMetaData.writeToJson(Path.Combine(path, "MusicPackInformation.json"));
} }
if (!File.Exists(Path.Combine(path, "readme.txt"))) if (!File.Exists(Path.Combine(path, "readme.txt")))
@ -96,27 +114,43 @@ namespace StardewSymphonyRemastered
string[] listOfDirectories= Directory.GetDirectories(XACTMusicDirectory); string[] listOfDirectories= Directory.GetDirectories(XACTMusicDirectory);
foreach(string folder in listOfDirectories) foreach(string folder in listOfDirectories)
{ {
string waveBank = Path.Combine(folder, "Wave Bank.xwb"); //This chunk essentially allows people to name .xwb and .xsb files whatever they want.
string soundBank = Path.Combine(folder, "Sound Bank.xwb"); string[] xwb=Directory.GetFiles(folder, "*.xwb");
string metaData = Path.Combine(folder, "MusicPackInformation.json"); string[] xsb = Directory.GetFiles(folder, "*.xsb");
if (!File.Exists(waveBank))
string[] debug = Directory.GetFiles(folder);
if (xwb.Length == 0)
{ {
ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There is no file Wave Bank.xwb located in this directory. AKA there is no valid music here.", LogLevel.Error); ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There is no wave bank music file: .xwb located in this directory. AKA there is no valid music here.", LogLevel.Error);
return;
}
if (xwb.Length >= 2)
{
ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There are too many wave bank music files or .xwbs located in this directory. Please ensure that there is only one music pack in this folder. You can make another music pack but putting a wave bank file in a different folder.", LogLevel.Error);
return; return;
} }
if (!File.Exists(soundBank)) if (xsb.Length == 0)
{ {
ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There is no file Sound Bank.xwb located in this directory. This is needed to play the music from Wave Bank.xwb", LogLevel.Error); ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There is no sound bank music file: .xsb located in this directory. AKA there is no valid music here.", LogLevel.Error);
return; return;
} }
if (xsb.Length >= 2)
{
ModMonitor.Log("Error loading in attempting to load music pack from: " + folder + ". There are too many sound bank music files or .xsbs located in this directory. Please ensure that there is only one sound reference file in this folder. You can make another music pack but putting a sound file in a different folder.", LogLevel.Error);
return;
}
string waveBank = xwb[0];
string soundBank = xsb[0];
string metaData = Path.Combine(folder, "MusicPackInformation.json");
if (!File.Exists(metaData)) if (!File.Exists(metaData))
{ {
ModMonitor.Log("WARNING! Loading in a music pack from: " + folder + ". There is no MusicPackInformation.json associated with this music pack meaning that while songs can be played from this pack, no information about it will be displayed.", LogLevel.Error); ModMonitor.Log("WARNING! Loading in a music pack from: " + folder + ". There is no MusicPackInformation.json associated with this music pack meaning that while songs can be played from this pack, no information about it will be displayed.", LogLevel.Error);
} }
StardewSymphonyRemastered.Framework.XACTMusicPack musicPack = new XACTMusicPack(folder, waveBank); StardewSymphonyRemastered.Framework.XACTMusicPack musicPack = new XACTMusicPack(folder, waveBank,soundBank);
musicManager.addMusicPack(musicPack); musicManager.addMusicPack(musicPack,true,true);
} }
} }

View File

@ -0,0 +1,10 @@
{
"Name": "Stardew Symphony",
"Author": "Alpha_Omegasis",
"Version": "2.0.0",
"Description": "Adding more music to the game one beep at a time. Now with streaming!",
"UniqueID": "Omegasis.StardewSymphony",
"EntryDll": "StardewSymphonyRemastered.dll",
"MinimumApiVersion": "2.0",
"UpdateKeys": [ "Nexus:425" ]
}