diff --git a/ClanServer/ClanServer.csproj b/ClanServer/ClanServer.csproj index 62c44f2..902bff5 100644 --- a/ClanServer/ClanServer.csproj +++ b/ClanServer/ClanServer.csproj @@ -7,6 +7,14 @@ true + + + + + + + + diff --git a/ClanServer/Data/L44/ClanMusicInfo.cs b/ClanServer/Data/L44/ClanMusicInfo.cs new file mode 100644 index 0000000..9d7e198 --- /dev/null +++ b/ClanServer/Data/L44/ClanMusicInfo.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; +using System.Threading.Tasks; +using System.Reflection; +using System.IO; + +using eAmuseCore.KBinXML; +using eAmuseCore.Compression; + +namespace ClanServer.Data.L44 +{ + public class ClanMusicInfo + { + static ClanMusicInfo() + { + Instance = Task.Run(() => + { + foreach (string name in Assembly.GetExecutingAssembly().GetManifestResourceNames()) + { + if (name.EndsWith("music_info_l44_8.kbin", StringComparison.InvariantCultureIgnoreCase)) + { + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) + using (MemoryStream ms = new MemoryStream()) + { + stream.CopyTo(ms); + return new ClanMusicInfo( + new KBinXML( + LZ77.Decompress( + ms.ToArray() + ).ToArray() + ).Document + ); + } + } + } + + return null; + }); + } + + public static Task Instance { get; private set; } + + private readonly XDocument doc; + + private ClanMusicInfo(XDocument doc) + { + this.doc = doc; + + BuildMusicList(); + } + + private List musicIdList; + public IList MusicIdList { get => musicIdList.AsReadOnly(); } + + private void BuildMusicList() + { + XElement body = doc.Root.Element("music_data").Element("body"); + var musicData = body.Elements("data"); + + musicIdList = new List(musicData.Count()); + + foreach (XElement musicEntry in musicData) + { + musicIdList.Add(int.Parse(musicEntry.Element("music_id").Value)); + } + } + + private static readonly Random rng = new Random(); + + public List GetRandomSongs(int num) + { + HashSet candidateIndexes = new HashSet(); + while (candidateIndexes.Count < num) + candidateIndexes.Add(rng.Next(0, musicIdList.Count)); + + List result = new List(num); + result.AddRange(candidateIndexes.Select(i => musicIdList[i])); + + for (int i = result.Count - 1; i > 0; --i) + { + int k = rng.Next(i + 1); + int v = result[i]; + result[i] = result[k]; + result[k] = v; + } + + return result; + } + } +} diff --git a/ClanServer/Data/L44/music_info_l44_8.kbin b/ClanServer/Data/L44/music_info_l44_8.kbin new file mode 100644 index 0000000..19fbd15 Binary files /dev/null and b/ClanServer/Data/L44/music_info_l44_8.kbin differ diff --git a/eAmuseTest/Program.cs b/eAmuseTest/Program.cs index 852b7da..b729699 100644 --- a/eAmuseTest/Program.cs +++ b/eAmuseTest/Program.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.IO; using System.Text; using System.Linq; using System.Xml.Linq; @@ -33,7 +34,7 @@ namespace eAmuseTest KBinXML kbinxml = new KBinXML(rawData.ToArray()); - Console.WriteLine(kbinxml.ToString()); + Console.WriteLine(kbinxml); //GenerateEchidnaSQL(kbinxml); } diff --git a/eAmuseTest/Properties/launchSettings.json b/eAmuseTest/Properties/launchSettings.json new file mode 100644 index 0000000..a765d5f --- /dev/null +++ b/eAmuseTest/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "eAmuseTest": { + "commandName": "Project", + "workingDirectory": "." + } + } +} \ No newline at end of file