public TrackDetail GetTrackDetail(string songKey, string arrangmentName) { var sngEntry = _psarc.Entries.FirstOrDefault(x => x.Name == @"songs/bin/generic/" + songKey + "_" + arrangmentName + ".sng"); var jsonEntry = _psarc.Entries.FirstOrDefault(x => x.Name.StartsWith(@"manifests/songs") && x.Name.EndsWith("/" + songKey + "_" + arrangmentName + ".json")); if (sngEntry == null || jsonEntry == null) { return(null); } Attributes2014 att; using (var wrappedStream = new NonClosingStreamWrapper(jsonEntry.Data)) { using (var reader = new StreamReader(wrappedStream)) { var manifest = JsonConvert.DeserializeObject <Manifest2014 <Attributes2014> >(reader.ReadToEnd()); att = manifest.Entries.ToArray()[0].Value.ToArray()[0].Value; } } Sng2014File sngFile; using (var wrappedStream = new NonClosingStreamWrapper(sngEntry.Data)) { var platform = _archiveFile.GetPlatform(); sngFile = Sng2014File.ReadSng(wrappedStream, platform); } var sngObject = new Song2014(sngFile, att); return(new TrackDetail() { RockSmithSong = sngObject }); }
internal ArrangementData ExtractArrangementData(Attributes2014 attr) { string sngFilePath = $"songs/bin/generic/{attr.SongXml.Substring(20)}.sng"; var entry = _archive.TOC.Where(x => x.Name.Equals(sngFilePath)).FirstOrDefault(); if (entry == null) { throw new Exception($"Could not find arrangement sng {_filePath}/{sngFilePath}"); } ArrangementData data = null; _archive.InflateEntry(entry); entry.Data.Position = 0; var sng = Sng2014File.ReadSng(entry.Data, new RocksmithToolkitLib.Platform(RocksmithToolkitLib.GamePlatform.Pc, RocksmithToolkitLib.GameVersion.RS2014)); if (sng == null) { throw new Exception($"Could not read sng {_filePath}{sngFilePath}"); } data = new ArrangementData(sng); entry.Dispose(); return(data); }
/// <summary> /// Extract a particular arrangement of a song from the archive /// and return the corresponding Song2014 object. /// </summary> /// <param name="identifier">Identifier of the song to load.</param> /// <param name="arrangement">The arrangement to use.</param> /// <returns>A Song2014 object containing the arrangement.</returns> public Song2014 GetArrangement(string identifier, string arrangement) { // In order to instantiate a Rocksmith Song2014 object, we need both // the binary .sng file and the attributes contained in the corresponding // .json manifest. Console.WriteLine(" Opening arrangement {1} for song id {0}...", identifier, arrangement); Platform platform = new Platform(GamePlatform.Pc, GameVersion.RS2014); var jsonFile = archive.Entries.FirstOrDefault(x => x.Name.StartsWith("manifests/songs") && x.Name.EndsWith("/" + identifier + "_" + arrangement + ".json")); var sngFile = archive.Entries.FirstOrDefault(x => x.Name == "songs/bin/generic/" + identifier + "_" + arrangement + ".sng"); if (sngFile == null) { // this might be a Mac archive, try with Mac path sngFile = archive.Entries.FirstOrDefault(x => x.Name == "songs/bin/macos/" + identifier + "_" + arrangement + ".sng"); platform.platform = GamePlatform.Mac; } if (sngFile == null || jsonFile == null) { if (sngFile == null) { Console.WriteLine("sngFile is null."); } if (jsonFile == null) { Console.WriteLine("jsonFile is null."); } return(null); } // read out attributes from .json manifest Attributes2014 attr; using (var reader = new StreamReader(jsonFile.Data.OpenStream())) { var manifest = JsonConvert.DeserializeObject <Manifest2014 <Attributes2014> >( reader.ReadToEnd()); if (manifest == null) { return(null); } attr = manifest.Entries.ToArray()[0].Value.ToArray()[0].Value; } // get contents of .sng file Sng2014File sng = Sng2014File.ReadSng(sngFile.Data.OpenStream(), platform); return(new Song2014(sng, attr)); }
/// <summary> /// Extract a particular arrangement of a song from the archive /// and return the corresponding Song2014 object. /// </summary> /// <param name="identifier">Identifier (short title, aka key) of the song to load.</param> /// <param name="arrangement">The arrangement (lead, rythum, bass) to use.</param> /// <returns>A Song2014 object containing the arrangement.</returns> public Song2014 GetArrangement(string identifier, string arrangement) { // In order to instantiate a Rocksmith Song2014 object, we need both // the binary .sng file and the attributes contained in the corresponding // .json manifest. Console.WriteLine("GetArrangement called with identifier [{0}], arrangement {{{1}}}", identifier, arrangement); var sngFile = archive.Entries.FirstOrDefault(x => x.Name == "songs/bin/generic/" + identifier + "_" + arrangement + ".sng"); var jsonFile = archive.Entries.FirstOrDefault(x => x.Name.StartsWith("manifests/songs") && x.Name.EndsWith("/" + identifier + "_" + arrangement + ".json")); if (sngFile == null || jsonFile == null) { if (sngFile == null) { Console.WriteLine("sngFile is null."); } if (jsonFile == null) { Console.WriteLine("jsonFile is null."); } return(null); } // read out attributes from .json manifest Attributes2014 attr; using (var ms = new MemoryStream()) using (var reader = new StreamReader(ms, new UTF8Encoding(), false, 1024)) { jsonFile.Data.CopyTo(ms); ms.Position = 0; var manifest = JsonConvert.DeserializeObject <Manifest2014 <Attributes2014> >( reader.ReadToEnd()); if (manifest == null) { return(null); } attr = manifest.Entries.ToArray()[0].Value.ToArray()[0].Value; } // get contents of .sng file Sng2014File sng = Sng2014File.ReadSng(sngFile.Data, platform); return(new Song2014(sng, attr)); }