1
0
mirror of synced 2024-11-30 14:14:29 +01:00
TaikoSoundEditor/NUS3Bank.cs

66 lines
2.1 KiB
C#
Raw Normal View History

2023-10-01 18:40:41 +02:00
using System.Drawing.Text;
using System.IO;
2023-07-17 10:20:00 +02:00
using System.Linq;
2023-10-01 18:40:41 +02:00
using TaikoSoundEditor.Commons.Utils;
2023-07-17 10:20:00 +02:00
using TaikoSoundEditor.Properties;
namespace TaikoSoundEditor
{
internal static class NUS3Bank
{
private static void Write32(byte[] b, int pos, uint x)
{
b[pos++] = (byte)(x & 0xFF); x >>= 8;
b[pos++] = (byte)(x & 0xFF); x >>= 8;
b[pos++] = (byte)(x & 0xFF); x >>= 8;
b[pos] = (byte)(x & 0xFF);
}
public static byte[] GetNus3Bank(string songId, int uniqueId, byte[] idsp, float demostart)
{
2023-07-19 07:10:25 +02:00
Logger.Info($"Creating NUS3BANK");
Logger.Info($"songId = {songId}");
Logger.Info($"uniqId = {uniqueId}");
Logger.Info($"idsp.len = {idsp.Length}");
Logger.Info($"demostart = {demostart}");
2023-10-01 18:40:41 +02:00
using (var ms = new MemoryStream())
{
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
var header = Resources.song_ABCDEF_nus3bank.ToArray();
2023-07-17 11:58:05 +02:00
2023-10-01 18:40:41 +02:00
Write32(header, 0x4, (uint)idsp.Length);
for (int i = 0; i < songId.Length; i++)
{
header[0xAA + i] = (byte)songId[i];
header[0x612 + i] = (byte)songId[i];
}
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
for (int i = songId.Length; i < 6; i++)
{
header[0xAA + i] = 0;
header[0x612 + i] = 0;
}
2023-07-19 07:25:05 +02:00
2023-10-01 18:40:41 +02:00
header[0xB4] = (byte)(uniqueId & 0xFF);
header[0xB5] = (byte)((uniqueId >> 8) & 0xFF);
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
Write32(header, 0x4C, (uint)idsp.Length);
Write32(header, 0x628, (uint)idsp.Length);
Write32(header, 0x74C, (uint)idsp.Length);
Write32(header, 0x4, (uint)idsp.Length);
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
uint bb = (uint)(demostart * 1000);
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
Write32(header, 0x6C4, bb);
2023-07-17 10:20:00 +02:00
2023-10-01 18:40:41 +02:00
ms.Write(header);
ms.Write(idsp);
return ms.ToArray();
}
}
private static void Write(this MemoryStream ms, byte[] bytes) => ms.Write(bytes, 0, bytes.Length);
2023-07-17 10:20:00 +02:00
}
}