diff --git a/Program.cs b/Program.cs index cc2890e..f9d49f4 100644 --- a/Program.cs +++ b/Program.cs @@ -1,12 +1,127 @@ -namespace TaikoNus3BankTemplateFix +using System.Linq; +using TaikoNus3BankTemplateFix.Properties; + +namespace TaikoNus3BankTemplateFix { internal class Program { + static int Similarity(byte[] buff, byte[] template) + { + if (buff.Length < template.Length) return 0; + int c = 0; + for (int i = 0; i < template.Length; i++) + { + if (buff[i] == template[i]) c++; + } + return c * 100 / template.Length; + } + + 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); + } + + private static int Read32(byte[] b, int pos) + { + int x = 0; + x |= b[pos++]; + x |= b[pos++] << 8; + x |= b[pos++] << 16; + x |= b[pos++] << 24; + return x; + } + + private static void Write16(byte[] b, int pos, uint x) + { + b[pos++] = (byte)(x & 0xFF); x >>= 8; + b[pos++] = (byte)(x & 0xFF); + } + + private static int Read16(byte[] b, int pos) + { + int x = 0; + x |= b[pos++]; + x |= b[pos++] << 8; + return x; + } + + private static byte[] ReadBytes(byte[] b, int pos, int count) + { + var result = new byte[count]; + for (int i = 0; i < count; i++) + result[i] = b[pos++]; + return result; + } + + private static void WriteBytes(byte[] b, int pos, byte[] src, int count) + { + for(int i=0;i !a.StartsWith("-")); + foreach (var file in new_args) + { + Console.WriteLine(file); + try + { + var input = File.ReadAllBytes(file); + var new_similarity = Similarity(input, Resources.song_ABCDEF_nus3bank); + + if (new_similarity > 90) + continue; + + if (Similarity(input, Resources.song_ABCDEF_nus3bank_old) < 90 && !force) + { + Console.WriteLine("This file doesn't resemble the old template. Use -f option to force it being converted to the new template (only if you know what you're doing)."); + continue; + } + + // once we are sure that the nus3bank is in the old tempalte, we can convert it to the new one + + var idsp = input.Skip(Resources.song_ABCDEF_nus3bank_old.Length).ToArray(); + + var length = Read32(input, 0x4); + + if (length != idsp.Length) + { + Console.WriteLine("Inconsistency fonud when getting IDSP length. Skipping the file..."); + continue; + } + + var songName = ReadBytes(input, 0xAA, 6); + + var uniqId = Read16(input, 0xB4); + + int bb = Read32(input, 0xDDC); + + var header = Resources.song_ABCDEF_nus3bank.ToArray(); + + Write32(header, 0x4, (uint)idsp.Length); + WriteBytes(header, 0xAA, songName, 6); + WriteBytes(header, 0x612, songName, 6); + Write16(header, 0xB4, (uint)uniqId); + Write32(header, 0x4C, (uint)idsp.Length); + Write32(header, 0x628, (uint)idsp.Length); + Write32(header, 0x74C, (uint)idsp.Length); + Write32(header, 0x4, (uint)idsp.Length); + Write32(header, 0x6C4, (uint)bb); + File.WriteAllBytes(file, header.Concat(idsp).ToArray()); + } + catch(Exception ex) + { + Console.WriteLine("Error"); + Console.WriteLine(ex.Message); + } + } } } } \ No newline at end of file diff --git a/Properties/PublishProfiles/FolderProfile.pubxml b/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..5032492 --- /dev/null +++ b/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,19 @@ + + + + + Release + Any CPU + bin\Release\net6.0\publish\win-x86\ + FileSystem + <_TargetId>Folder + net6.0 + win-x86 + true + true + true + true + + \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..b63f6b2 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "TaikoNus3BankTemplateFix": { + "commandName": "Project", + "commandLineArgs": "C:\\Users\\NotImpLife\\Desktop\\nus\\exports\\all9\\nus3banks\\song_abc.nus3bank C:\\Users\\NotImpLife\\Desktop\\nus\\exports\\all9\\nus3banks\\old.nus3bank" + } + } +} \ No newline at end of file diff --git a/TaikoNus3BankTemplateFix.csproj b/TaikoNus3BankTemplateFix.csproj index 74abf5c..ac4dd53 100644 --- a/TaikoNus3BankTemplateFix.csproj +++ b/TaikoNus3BankTemplateFix.csproj @@ -5,6 +5,23 @@ net6.0 enable enable + Taiko Nus3Bank Template Fix + NotImplementedLife + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + +