mirror of
https://github.com/BtbN/ClanServer.git
synced 2026-09-06 23:45:15 -05:00
Add music info loading infra
This commit is contained in:
@@ -7,6 +7,14 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Data\L44\music_info_l44_8.kbin" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\L44\music_info_l44_8.kbin" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
|
||||
92
ClanServer/Data/L44/ClanMusicInfo.cs
Normal file
92
ClanServer/Data/L44/ClanMusicInfo.cs
Normal file
@@ -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<ClanMusicInfo> Instance { get; private set; }
|
||||
|
||||
private readonly XDocument doc;
|
||||
|
||||
private ClanMusicInfo(XDocument doc)
|
||||
{
|
||||
this.doc = doc;
|
||||
|
||||
BuildMusicList();
|
||||
}
|
||||
|
||||
private List<int> musicIdList;
|
||||
public IList<int> MusicIdList { get => musicIdList.AsReadOnly(); }
|
||||
|
||||
private void BuildMusicList()
|
||||
{
|
||||
XElement body = doc.Root.Element("music_data").Element("body");
|
||||
var musicData = body.Elements("data");
|
||||
|
||||
musicIdList = new List<int>(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<int> GetRandomSongs(int num)
|
||||
{
|
||||
HashSet<int> candidateIndexes = new HashSet<int>();
|
||||
while (candidateIndexes.Count < num)
|
||||
candidateIndexes.Add(rng.Next(0, musicIdList.Count));
|
||||
|
||||
List<int> result = new List<int>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
ClanServer/Data/L44/music_info_l44_8.kbin
Normal file
BIN
ClanServer/Data/L44/music_info_l44_8.kbin
Normal file
Binary file not shown.
@@ -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);
|
||||
}
|
||||
|
||||
8
eAmuseTest/Properties/launchSettings.json
Normal file
8
eAmuseTest/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"eAmuseTest": {
|
||||
"commandName": "Project",
|
||||
"workingDirectory": "."
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user