From cef4c74acf7c35a0208456d2853af0ea729e11e9 Mon Sep 17 00:00:00 2001 From: Moonling <52844176+VelouriasMoon@users.noreply.github.com> Date: Mon, 13 Feb 2023 00:39:09 -0400 Subject: [PATCH] Added support for Chain Loader Mod --- Ishtar/Form1.cs | 44 +++++++++++++------------------ Ishtar/IO/Helpers.cs | 22 +++++++++++++--- Ishtar/IO/Merger.cs | 40 +++++++++++++++++++++++++--- Ishtar/Ishtar.csproj | 3 +++ Ishtar/Program.cs | 30 ++++++++++++++++++++- Ishtar/Tables/DT_SpawnerList.json | 1 + 6 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 Ishtar/Tables/DT_SpawnerList.json diff --git a/Ishtar/Form1.cs b/Ishtar/Form1.cs index 7c4cba6..a4945f9 100644 --- a/Ishtar/Form1.cs +++ b/Ishtar/Form1.cs @@ -16,6 +16,7 @@ using QueenIO.Structs; using Ishtar.IO; using System.Threading; +using QueenIO.Mods; namespace Ishtar { @@ -26,16 +27,16 @@ public Form1() InitializeComponent(); if (File.Exists("Settings.json")) { - Settings.Read("Settings.json"); - TB_ModsPath.Text = settings.Mods_Path; + Global.Settings.Read("Settings.json"); + TB_ModsPath.Text = Global.settings.Mods_Path; } else - settings = new Settings(); + Global.settings = new Global.Settings(); #if DEBUG button1.Visible = true; #endif } - static Settings settings; + private volatile int threads; private void MakeTables(object sender, EventArgs e) @@ -104,6 +105,14 @@ private void MakeTables(object sender, EventArgs e) string json = JsonConvert.SerializeObject(data); File.WriteAllText($"Output\\{Path.GetFileNameWithoutExtension(file)}.json", json); } + else if (file.Contains("DT_SpawnerList")) + { + Relic relic = Blood.Open(file); + ModControlFrameworkListData data = new ModControlFrameworkListData(); + data.Read(relic.GetDataTable()); + string json = JsonConvert.SerializeObject(data); + File.WriteAllText($"Output\\{Path.GetFileNameWithoutExtension(file)}.json", json); + } else { Relic relic = Blood.Open(file); @@ -128,30 +137,13 @@ private void B_GetModsPath_Click(object sender, EventArgs e) if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { TB_ModsPath.Text = dialog.FileName; - settings.Mods_Path = dialog.FileName; - Settings.Save(); + Global.settings.Mods_Path = dialog.FileName; + Global.Settings.Save(); } } } - class Settings - { - public string Mods_Path { get; set; } - - public static void Read(string infile) - { - string json = File.ReadAllText(infile); - settings = JsonConvert.DeserializeObject(json); - } - - public static void Save() - { - string json = JsonConvert.SerializeObject(settings); - if (File.Exists("Settings.json")) - File.Delete("Settings.json"); - File.WriteAllText("Settings.json", json); - } - } + private void Merge_Tables_Click(object sender, EventArgs e) { @@ -175,8 +167,8 @@ private void Merge() string[] MergableFiles = Directory.GetFiles("Tables", "*.json"); Helpers.Log("richTextBox1", $"Found {paks.Length} pak files"); Helpers.Log("richTextBox1", $"Found {MergableFiles.Length} base tables for mergeing"); - if (Directory.Exists("Merged")) - Directory.Delete("Merged", true); + //if (Directory.Exists("Merged")) + // Directory.Delete("Merged", true); if (Directory.Exists("ZZZZZ-MergePatch")) Directory.Delete("ZZZZZ-MergePatch", true); Helpers.LogClear("richTextBox1"); diff --git a/Ishtar/IO/Helpers.cs b/Ishtar/IO/Helpers.cs index 8b59c44..2c0ab5a 100644 --- a/Ishtar/IO/Helpers.cs +++ b/Ishtar/IO/Helpers.cs @@ -6,12 +6,13 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Net.WebRequestMethods; namespace Ishtar.IO { - internal class Helpers + public class Helpers { - internal static string[] ListPak(string infile) + public static string[] ListPak(string infile) { string[] list; using (Process process = new Process()) @@ -40,7 +41,7 @@ internal static string[] ListPak(string infile) return result.ToArray(); } - internal static void ExtractPak(string infile, string outpath = "Temp") + public static void ExtractPak(string infile, string outpath = "Temp") { using (Process process = new Process()) { @@ -75,5 +76,20 @@ public static void LogClear(string richTextBox) else RTB.Clear(); } + + public static string HashFile(byte[] infile) + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + var hash = md5.ComputeHash(infile); + string s = BitConverter.ToString(hash).Replace("-", ""); + return s; + } + } + + public static string HashString(string s) + { + return HashFile(Encoding.UTF8.GetBytes(s)); + } } } diff --git a/Ishtar/IO/Merger.cs b/Ishtar/IO/Merger.cs index 73dec13..645ad3f 100644 --- a/Ishtar/IO/Merger.cs +++ b/Ishtar/IO/Merger.cs @@ -2,13 +2,11 @@ using QueenIO; using QueenIO.Tables; using QueenIO.Structs; -using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; +using QueenIO.Mods; namespace Ishtar.IO { @@ -31,6 +29,7 @@ public enum types Mask, Visibility, Common, + Mod, } } @@ -39,6 +38,7 @@ public enum types public static void ListMergeablePaks(string[] infiles, string[] Tables) { + Global.settings.Paks.Clear(); Helpers.Log("richTextBox1", $"Checking Paks for mergeable files..."); Parallel.ForEach(infiles, pak => { @@ -48,11 +48,13 @@ public static void ListMergeablePaks(string[] infiles, string[] Tables) bool added = LoggedPaks.TryAdd(Path.GetFileNameWithoutExtension(pak), pak); if (added) { + Global.settings.Paks.Add(Helpers.HashFile(File.ReadAllBytes(pak)), Path.GetFileName(pak)); //Helpers.Log("richTextBox1", $"Meragable files found in {Path.GetFileNameWithoutExtension(pak)}"); } } }); Helpers.Log("richTextBox1", $"Found {LoggedPaks.Count} paks for merging"); + Global.Settings.Save(); } @@ -151,6 +153,16 @@ public static void Merge(string[] infiles, string[] Tables, bool PartialMerge = } Visibility((InnerPartsVisibilityByOuter)MergeFiles[name].Table, (InnerPartsVisibilityByOuter)MergeFiles[name].VanillaTable, relic, PartialMerge); } + else if (tbl.Contains("DT_SpawnerList")) + { + if (!MergeFiles.ContainsKey(name)) + { + ModControlFrameworkListData data = JsonConvert.DeserializeObject(File.ReadAllText(tbl)); + ModControlFrameworkListData vanilla = JsonConvert.DeserializeObject(File.ReadAllText(tbl)); + MergeFiles.TryAdd(name, new MergeFile() { Path = outpath, relic = relic, Table = data, VanillaTable = vanilla, Type = (MergeFile.types)7 }); + } + ModControl((ModControlFrameworkListData)MergeFiles[name].Table, (ModControlFrameworkListData)MergeFiles[name].VanillaTable, relic, PartialMerge); + } else { if (!MergeFiles.ContainsKey(name)) @@ -202,6 +214,10 @@ private static void Export() case MergeFile.types.Common: file.relic.WriteDataTable(((BasicCustomizationListData)file.Table).Make()); break; + case MergeFile.types.Mod: + file.relic.WriteDataTable(((ModControlFrameworkListData)file.Table).Make()); + file.Path = $"ZZZZZ-MergePatch\\CodeVein\\Content\\Characters\\Blueprints\\Player\\Core\\ModControlFramework\\{Path.GetFileName(file.Path)}"; + break; default: return; } @@ -338,5 +354,23 @@ private static void Common(BasicCustomizationListData basicCustomizationListData } } } + + private static void ModControl(ModControlFrameworkListData modControlFrameworkListData, ModControlFrameworkListData Vanilla, Relic relic, bool PartialMerge = false) + { + ModControlFrameworkListData modControlFrameworkListData1 = new ModControlFrameworkListData(); + modControlFrameworkListData1.Read(relic.GetDataTable()); + foreach(var modcontrol in modControlFrameworkListData1.SpawnerList) + { + ModControlFrameworkData mod = modControlFrameworkListData.SpawnerList.FirstOrDefault(x => x.Name == modcontrol.Name); + ModControlFrameworkData mod2 = Vanilla.SpawnerList.FirstOrDefault(x => x.Name == modcontrol.Name); + if (!modControlFrameworkListData.SpawnerList.Contains(mod)) + modControlFrameworkListData.SpawnerList.Add(modcontrol); + else if (!PartialMerge && !mod.Equals(modcontrol) && !mod2.Equals(modcontrol)) + { + int i = modControlFrameworkListData.SpawnerList.IndexOf(mod); + modControlFrameworkListData.SpawnerList[i] = modcontrol; + } + } + } } } diff --git a/Ishtar/Ishtar.csproj b/Ishtar/Ishtar.csproj index 3f164db..6a8b3c1 100644 --- a/Ishtar/Ishtar.csproj +++ b/Ishtar/Ishtar.csproj @@ -183,6 +183,9 @@ Always + + Always + diff --git a/Ishtar/Program.cs b/Ishtar/Program.cs index 714b0d3..fabeebe 100644 --- a/Ishtar/Program.cs +++ b/Ishtar/Program.cs @@ -1,5 +1,8 @@ -using System; +using Ishtar.Properties; +using Newtonsoft.Json; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; @@ -19,4 +22,29 @@ static void Main() Application.Run(new Form1()); } } + + public static class Global + { + public static Settings settings; + + public class Settings + { + public string Mods_Path { get; set; } + public Dictionary Paks { get; set; } = new Dictionary(); + + public static void Read(string infile) + { + string json = File.ReadAllText(infile); + settings = JsonConvert.DeserializeObject(json); + } + + public static void Save() + { + string json = JsonConvert.SerializeObject(settings); + if (File.Exists("Settings.json")) + File.Delete("Settings.json"); + File.WriteAllText("Settings.json", json); + } + } + } } diff --git a/Ishtar/Tables/DT_SpawnerList.json b/Ishtar/Tables/DT_SpawnerList.json new file mode 100644 index 0000000..a9e8824 --- /dev/null +++ b/Ishtar/Tables/DT_SpawnerList.json @@ -0,0 +1 @@ +{"SpawnerList":[{"Name":"Debug","StructType":"STR_Spawners","Key":{"Name":"Key_2_5889D6384413CE94CB77A8A04D9557F5","StructType":"Key","KeyName":"Backslash"},"Spawner":"/Game/Characters/Blueprints/Player/Core/ModControlFramework/Spawner/BP_Spawner_Debug.BP_Spawner_Debug_C"}]} \ No newline at end of file