From 2f8e80d86aea20df8f996377cf74a5ee3cebc5d9 Mon Sep 17 00:00:00 2001 From: raphaeIl Date: Mon, 30 Dec 2024 21:14:06 -0500 Subject: [PATCH] exceldb dumper --- SCHALE.Common/Crypto/TableService.cs | 70 +++++++++++++++++++++++----- SCHALE.Common/SCHALE.Common.csproj | 2 + SCHALE.GameServer/GameServer.cs | 4 -- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/SCHALE.Common/Crypto/TableService.cs b/SCHALE.Common/Crypto/TableService.cs index 211c0a7..c636479 100644 --- a/SCHALE.Common/Crypto/TableService.cs +++ b/SCHALE.Common/Crypto/TableService.cs @@ -1,10 +1,12 @@ using Google.FlatBuffers; +using System.Data.SQLite; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using SCHALE.Common.Crypto.XXHash; using SCHALE.Common.FlatData; using System.Reflection; using System.Text; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace SCHALE.Common.Crypto { @@ -36,8 +38,60 @@ namespace SCHALE.Common.Crypto } #if DEBUG + public static List GetExcelList(Type type, string exceldbDir, string schema) + { + var excelList = new List(); + using (var dbConnection = new SQLiteConnection($"Data Source = {exceldbDir}")) + { + dbConnection.Open(); + var command = dbConnection.CreateCommand(); + command.CommandText = $"SELECT Bytes FROM {schema}"; + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + excelList.Add(type.GetMethod($"GetRootAs{type.Name}", BindingFlags.Static | BindingFlags.Public, [typeof(ByteBuffer)])! + .Invoke(null, [new ByteBuffer((byte[])reader[0])])); + } + } + } + + return excelList; + } + + public static void DumpExcelDB(string exceldbDir, string destDir) + { + Directory.CreateDirectory(destDir); + + using (var dbConnection = new SQLiteConnection($"Data Source = {exceldbDir}")) + { + dbConnection.Open(); + + string query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';"; + + using (var command = new SQLiteCommand(query, dbConnection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + string dbSchemaName = reader.GetString(0); + string excelName = dbSchemaName.Replace("DBSchema", "Excel"); + var type = Assembly.GetAssembly(typeof(AcademyFavorScheduleExcelTable))!.GetTypes().Where(t => t.IsAssignableTo(typeof(IFlatbufferObject)) && (t.Name.Equals(excelName))).FirstOrDefault(); + + var list = GetExcelList(type, exceldbDir, dbSchemaName); + + File.WriteAllText(Path.Join(destDir, $"{type.Name}.json"), JsonConvert.SerializeObject(list, Formatting.Indented, new StringEnumConverter())); + + Console.WriteLine($"Dumped {type.Name} from {dbSchemaName} successfully"); + } + } + } + } + public static void DumpExcels(string bytesDir, string destDir) { + Directory.CreateDirectory(destDir); + foreach (var type in Assembly.GetAssembly(typeof(AcademyFavorScheduleExcelTable))!.GetTypes().Where(t => t.IsAssignableTo(typeof(IFlatbufferObject)) && t.Name.EndsWith("ExcelTable"))) { var bytesFilePath = Path.Join(bytesDir, $"{type.Name}.bytes"); @@ -50,18 +104,10 @@ namespace SCHALE.Common.Crypto var bytes = File.ReadAllBytes(bytesFilePath); TableEncryptionService.XOR(type.Name, bytes); var inst = type.GetMethod($"GetRootAs{type.Name}", BindingFlags.Static | BindingFlags.Public, [typeof(ByteBuffer)])!.Invoke(null, [new ByteBuffer(bytes)]); - try - { - var obj = type.GetMethod("UnPack", BindingFlags.Instance | BindingFlags.Public)!.Invoke(inst, null); - File.WriteAllText(Path.Join(destDir, $"{type.Name}.json"), JsonConvert.SerializeObject(obj, Formatting.Indented, new StringEnumConverter())); - Console.WriteLine($"Dumped {type.Name} successfully"); - } - - catch (Exception e) - { - Console.WriteLine($"Error dumping ${type.Name}"); - } - + + var obj = type.GetMethod("UnPack", BindingFlags.Instance | BindingFlags.Public)!.Invoke(inst, null); + File.WriteAllText(Path.Join(destDir, $"{type.Name}.json"), JsonConvert.SerializeObject(obj, Formatting.Indented, new StringEnumConverter())); + Console.WriteLine($"Dumped {type.Name} successfully"); } } #endif diff --git a/SCHALE.Common/SCHALE.Common.csproj b/SCHALE.Common/SCHALE.Common.csproj index cd3babc..0e03d11 100644 --- a/SCHALE.Common/SCHALE.Common.csproj +++ b/SCHALE.Common/SCHALE.Common.csproj @@ -24,6 +24,8 @@ + + diff --git a/SCHALE.GameServer/GameServer.cs b/SCHALE.GameServer/GameServer.cs index 1b451fc..b28333c 100644 --- a/SCHALE.GameServer/GameServer.cs +++ b/SCHALE.GameServer/GameServer.cs @@ -21,10 +21,6 @@ namespace SCHALE.GameServer { public static async Task Main(string[] args) { - - //TableService.DumpExcels("E:\\documents\\Decompiling\\Extracted\\BlueArchiveJP\\SCHALE.GameServer.Custom\\SCHALE.GameServer\\SCHALE.GameServer\\bin\\Debug\\net8.0\\Resources\\excel", "E:\\documents\\Decompiling\\Extracted\\BlueArchiveJP\\SCHALE.GameServer.Custom\\SCHALE.GameServer\\SCHALE.GameServer\\bin\\Debug\\net8.0\\Resources\\dump"); - //return; - var config = new ConfigurationBuilder() .SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)!) .AddJsonFile("appsettings.json")