From 9f2ade3557324f47ecaad5a7a8299891957b7b9c Mon Sep 17 00:00:00 2001 From: Kaede Date: Sat, 18 May 2024 14:37:38 +0300 Subject: [PATCH 1/4] Move IPC from own project to Marsey --- Marsey.IPC/Marsey.IPC.csproj | 9 --------- {Marsey.IPC => Marsey/IPC}/Client.cs | 1 - {Marsey.IPC => Marsey/IPC}/Server.cs | 2 +- Marsey/Marsey.csproj | 4 ---- MarseyLoader.sln | 14 -------------- 5 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 Marsey.IPC/Marsey.IPC.csproj rename {Marsey.IPC => Marsey/IPC}/Client.cs (99%) rename {Marsey.IPC => Marsey/IPC}/Server.cs (98%) diff --git a/Marsey.IPC/Marsey.IPC.csproj b/Marsey.IPC/Marsey.IPC.csproj deleted file mode 100644 index 3a63532..0000000 --- a/Marsey.IPC/Marsey.IPC.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net8.0 - enable - enable - - - diff --git a/Marsey.IPC/Client.cs b/Marsey/IPC/Client.cs similarity index 99% rename from Marsey.IPC/Client.cs rename to Marsey/IPC/Client.cs index 03cbdcf..cfa3213 100644 --- a/Marsey.IPC/Client.cs +++ b/Marsey/IPC/Client.cs @@ -1,6 +1,5 @@ using System.IO.Pipes; - namespace Marsey.IPC; public class Client diff --git a/Marsey.IPC/Server.cs b/Marsey/IPC/Server.cs similarity index 98% rename from Marsey.IPC/Server.cs rename to Marsey/IPC/Server.cs index b0be120..0f9756e 100644 --- a/Marsey.IPC/Server.cs +++ b/Marsey/IPC/Server.cs @@ -12,7 +12,7 @@ public async Task ReadySend(string name, string data) byte[] buffer = Encoding.UTF8.GetBytes(data); await pipeServer.WriteAsync(buffer); - + pipeServer.Close(); } } diff --git a/Marsey/Marsey.csproj b/Marsey/Marsey.csproj index 9195370..86348c8 100644 --- a/Marsey/Marsey.csproj +++ b/Marsey/Marsey.csproj @@ -11,9 +11,5 @@ - - - - diff --git a/MarseyLoader.sln b/MarseyLoader.sln index ad0eba5..13dd0bb 100644 --- a/MarseyLoader.sln +++ b/MarseyLoader.sln @@ -46,8 +46,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marsey", "Marsey\Marsey.csp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marsey.Tests", "Marsey.Tests\Marsey.Tests.csproj", "{E47E0552-FF89-450D-880A-54B745481CD4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marsey.IPC", "Marsey.IPC\Marsey.IPC.csproj", "{97CFAE49-9274-447A-832C-55BC360235EE}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -145,18 +143,6 @@ Global {E47E0552-FF89-450D-880A-54B745481CD4}.Release|x64.Build.0 = Release|Any CPU {E47E0552-FF89-450D-880A-54B745481CD4}.Release|x86.ActiveCfg = Release|Any CPU {E47E0552-FF89-450D-880A-54B745481CD4}.Release|x86.Build.0 = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|x64.ActiveCfg = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|x64.Build.0 = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|x86.ActiveCfg = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Debug|x86.Build.0 = Debug|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|Any CPU.Build.0 = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|x64.ActiveCfg = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|x64.Build.0 = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|x86.ActiveCfg = Release|Any CPU - {97CFAE49-9274-447A-832C-55BC360235EE}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {31D3CCC5-36F4-48C3-8885-E029A2026B57} = {12BB41B7-34BA-44EF-9ECA-434A276D83BD} From efc1cbe9364e8b53a6d66ddf81d7de6f26b86e52 Mon Sep 17 00:00:00 2001 From: Kaede Date: Sat, 18 May 2024 15:33:17 +0300 Subject: [PATCH 2/4] Use IPCsey for patchlists --- Marsey/Game/Resources/ResMan.cs | 25 +++--- Marsey/IPC/Client.cs | 13 ++- Marsey/IPC/Server.cs | 5 +- Marsey/MarseyPatcher.cs | 2 +- Marsey/Misc/FileHandler.cs | 135 ++++++++++++++++++-------------- Marsey/Misc/Utility.cs | 2 +- Marsey/Patches/MarseyPatch.cs | 9 +-- Marsey/Subversion/Subverse.cs | 26 +++--- 8 files changed, 125 insertions(+), 92 deletions(-) diff --git a/Marsey/Game/Resources/ResMan.cs b/Marsey/Game/Resources/ResMan.cs index 1876aef..38977ac 100644 --- a/Marsey/Game/Resources/ResMan.cs +++ b/Marsey/Game/Resources/ResMan.cs @@ -20,10 +20,10 @@ public static class ResMan public static void Initialize() { ResourceTypes.Initialize(); - + _fork = MarseyPortMan.fork; // Peak spaghet moment - - // If were dumping the game we dont want to dump our own respack now would we + + // If we're dumping the game we don't want to dump our own respack now would we if (MarseyConf.Dumper) { MarseyDumper.Start(); @@ -31,11 +31,13 @@ public static void Initialize() } #if DEBUG - List enabledPacks = Marserializer.Deserialize([MarseyVars.MarseyResourceFolder], MarserializerFile) ?? []; + // Retrieve enabled resource packs data through named pipe + List enabledPacks = FileHandler.GetFilesFromPipe("ResourcePacksPipe"); + if (enabledPacks.Count == 0) return; - + MarseyLogger.Log(MarseyLogger.LogType.DEBG, $"Detecting {enabledPacks.Count} enabled resource packs."); - + foreach (string dir in enabledPacks) { InitializeRPack(dir, !MarseyConf.DisableResPackStrict); @@ -44,7 +46,8 @@ public static void Initialize() ResourceSwapper.Start(); #endif } - + + /// /// Executed by the launcher /// @@ -66,7 +69,7 @@ public static void LoadDir() private static void InitializeRPack(string path, bool strict = false) { ResourcePack rpack = new ResourcePack(path); - + try { rpack.ParseMeta(); @@ -76,7 +79,7 @@ private static void InitializeRPack(string path, bool strict = false) MarseyLogger.Log(MarseyLogger.LogType.FATL, e.ToString()); return; } - + AddRPack(rpack, strict); } @@ -84,10 +87,10 @@ private static void AddRPack(ResourcePack rpack, bool strict) { if (_resourcePacks.Any(rp => rp.Dir == rpack.Dir)) return; if (strict && rpack.Target != _fork && rpack.Target != "") return; - + _resourcePacks.Add(rpack); } public static List GetRPacks() => _resourcePacks; public static string? GetForkID() => _fork; -} \ No newline at end of file +} diff --git a/Marsey/IPC/Client.cs b/Marsey/IPC/Client.cs index cfa3213..9166216 100644 --- a/Marsey/IPC/Client.cs +++ b/Marsey/IPC/Client.cs @@ -1,4 +1,5 @@ using System.IO.Pipes; +using Marsey.Misc; namespace Marsey.IPC; @@ -6,11 +7,21 @@ public class Client { public string ConnRecv(string name) { + MarseyLogger.Log(MarseyLogger.LogType.DEBG, "IPC-Client", $"Trying to open client with pipe name {name}"); using NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", name, PipeDirection.In); - pipeClient.Connect(); + try + { + pipeClient.Connect(150); // Pipe should connect immediately + } + catch(TimeoutException) + { + MarseyLogger.Log(MarseyLogger.LogType.DEBG, "IPC-Client", $"Connection timed out on pipe {name}, pipe not being created?"); + return ""; + } using StreamReader reader = new StreamReader(pipeClient); return reader.ReadToEnd(); } } + diff --git a/Marsey/IPC/Server.cs b/Marsey/IPC/Server.cs index 0f9756e..b204a02 100644 --- a/Marsey/IPC/Server.cs +++ b/Marsey/IPC/Server.cs @@ -1,5 +1,6 @@ using System.IO.Pipes; using System.Text; +using Marsey.Misc; namespace Marsey.IPC; @@ -7,12 +8,14 @@ public class Server { public async Task ReadySend(string name, string data) { + MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Opening {name}"); await using NamedPipeServerStream pipeServer = new NamedPipeServerStream(name, PipeDirection.Out); await pipeServer.WaitForConnectionAsync(); byte[] buffer = Encoding.UTF8.GetBytes(data); await pipeServer.WriteAsync(buffer); - + + MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Closing {name}"); pipeServer.Close(); } } diff --git a/Marsey/MarseyPatcher.cs b/Marsey/MarseyPatcher.cs index a2cf670..3eb95e1 100644 --- a/Marsey/MarseyPatcher.cs +++ b/Marsey/MarseyPatcher.cs @@ -120,7 +120,7 @@ public void Boot() private void ExecPatcher() { // Prepare marseypatches - FileHandler.LoadAssemblies(marserializer: true, filename: Marsyfier.MarserializerFile); + FileHandler.LoadAssemblies(pipe: true); List patches = Marsyfier.GetMarseyPatches(); if (patches.Count != 0) diff --git a/Marsey/Misc/FileHandler.cs b/Marsey/Misc/FileHandler.cs index 7ff4f89..1be1b4a 100644 --- a/Marsey/Misc/FileHandler.cs +++ b/Marsey/Misc/FileHandler.cs @@ -17,70 +17,78 @@ namespace Marsey.Misc; public abstract class FileHandler { /// - /// - /// Serialize enabled mods. - /// Executed by the launcher at connection. - /// - /// - /// - /// We cant directly give marseys to the loader or tell it what mods to load because its started in a separate process. - /// Because of this we leave an array of paths to assemblies to enabled mods for the loader to read. - /// + /// Prepare data about enabled mods to send to the loader /// - public static void PrepareMods(string[]? path = null) +public static async Task PrepareMods(string[]? path = null) +{ + path ??= new[] { MarseyVars.MarseyFolder }; + string[] patchPath = new[] { MarseyVars.MarseyPatchFolder }; + string[] resPath = new[] { MarseyVars.MarseyResourceFolder }; + + List marseyPatches = Marsyfier.GetMarseyPatches(); + List subverterPatches = Subverter.GetSubverterPatches(); + List resourcePacks = ResMan.GetRPacks(); + + IPC.Server server = new(); + + // Prepare preloading MarseyPatches + List preloadpaths = marseyPatches + .Where(p => p is { Enabled: true, Preload: true }) + .Select(p => p.Asmpath) + .ToList(); + + // Send preloading MarseyPatches through named pipe + string preloadData = string.Join(",", preloadpaths); + Task preloadTask = server.ReadySend("PreloadMarseyPatchesPipe", preloadData); + + // If we actually do have any - remove them from the marseypatch list + if (preloadpaths.Count != 0) { - path ??= new[] { MarseyVars.MarseyFolder }; - string[] patchPath = new[] { MarseyVars.MarseyPatchFolder }; - string[] resPath = new[] { MarseyVars.MarseyResourceFolder }; - - List marseyPatches = Marsyfier.GetMarseyPatches(); - List subverterPatches = Subverter.GetSubverterPatches(); - List resourcePacks = ResMan.GetRPacks(); - - // Serialize preloading MarseyPatches - List preloadpaths = marseyPatches - .Where(p => p is { Enabled: true, Preload: true }) - .Select(p => p.Asmpath) - .ToList(); - - Marserializer.Serialize(patchPath, Marsyfier.PreloadMarserializerFile, preloadpaths); - - // If we actually do have any - remove them from the marseypatch list - if (preloadpaths.Count != 0) - marseyPatches.RemoveAll(p => preloadpaths.Contains(p.Asmpath)); - - // Serialize remaining MarseyPatches - List marseyAsmpaths = marseyPatches.Where(p => p.Enabled).Select(p => p.Asmpath).ToList(); - Marserializer.Serialize(patchPath, Marsyfier.MarserializerFile, marseyAsmpaths); - - // Serialize SubverterPatches - List subverterAsmpaths = subverterPatches.Where(p => p.Enabled).Select(p => p.Asmpath).ToList(); - Marserializer.Serialize(patchPath, Subverter.MarserializerFile, subverterAsmpaths); - - // Serialize ResourcePacks - List rpackPaths = resourcePacks.Where(rp => rp.Enabled).Select(rp => rp.Dir).ToList(); - Marserializer.Serialize(resPath, ResMan.MarserializerFile, rpackPaths); + marseyPatches.RemoveAll(p => preloadpaths.Contains(p.Asmpath)); } + // Prepare remaining MarseyPatches + List marseyAsmpaths = marseyPatches.Where(p => p.Enabled).Select(p => p.Asmpath).ToList(); + string marseyData = string.Join(",", marseyAsmpaths); + Task marseyTask = server.ReadySend("MarseyPatchesPipe", marseyData); + + // Prepare SubverterPatches + List subverterAsmpaths = subverterPatches.Where(p => p.Enabled).Select(p => p.Asmpath).ToList(); + string subverterData = string.Join(",", subverterAsmpaths); + Task subverterTask = server.ReadySend("SubverterPatchesPipe", subverterData); + +#if DEBUG + // Prepare ResourcePacks + List rpackPaths = resourcePacks.Where(rp => rp.Enabled).Select(rp => rp.Dir).ToList(); + string rpackData = string.Join(",", rpackPaths); + Task resourceTask = server.ReadySend("ResourcePacksPipe", rpackData); + + // Wait for all tasks to complete + await Task.WhenAll(preloadTask, marseyTask, subverterTask, resourceTask); +#else + // Wait for all tasks to complete + await Task.WhenAll(preloadTask, marseyTask, subverterTask); +#endif +} + + /// /// Loads assemblies from a specified folder. /// /// folder with patch dll's, set to "Marsey" by default - /// Are we loading from marserializer - /// Marserialized json filename - public static void LoadAssemblies(string[]? path = null, bool marserializer = false, string? filename = null) + /// Are we loading from an IPC pipe + /// Name of an IPC pipe to load the patches from + public static void LoadAssemblies(string[]? path = null, bool pipe = false, string pipename = "MarseyPatchesPipe") { path ??= new[] { MarseyVars.MarseyPatchFolder }; - if (!marserializer) + if (!pipe) { PatchListManager.RecheckPatches(); } - List files = marserializer && filename != null - ? Marserializer.Deserialize(path, filename) ?? new List() - : GetPatches(path); + List files = pipe ? GetFilesFromPipe(pipename) : GetPatches(path); foreach (string file in files) { @@ -88,6 +96,19 @@ public static void LoadAssemblies(string[]? path = null, bool marserializer = fa } } + /// + /// Retrieve a list of patch filepaths from pipe + /// + /// Name of the pipe + public static List GetFilesFromPipe(string name) + { + IPC.Client client = new(); + string data = client.ConnRecv(name); + + return string.IsNullOrEmpty(data) ? new List() : data.Split(',').ToList(); + } + + /// /// Loads an assembly from the specified file path and initializes it. /// @@ -136,7 +157,7 @@ public static List GetPatches(string[] subdir) { return Directory.GetFiles(path, "*.dll").ToList(); } - + MarseyLogger.Log(MarseyLogger.LogType.DEBG, $"Directory {path} does not exist"); return []; } @@ -153,20 +174,20 @@ public static List GetPatches(string[] subdir) public static void SaveAssembly(string path, string name, Stream asmStream) { Directory.CreateDirectory(path); - + string fullpath = Path.Combine(path, name); - + using FileStream st = new FileStream(fullpath, FileMode.Create, FileAccess.Write); asmStream.CopyTo(st); } - + /// public static void CheckRenameDirectory(string path) { // GetParent once shows itself, GetParent twice shows the actual parent - + if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) return; - + string dirName = Path.GetFileName(path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); string? parentDir = Directory.GetParent(Directory.GetParent(path)?.FullName ?? throw new InvalidOperationException())?.FullName; MarseyLogger.Log(MarseyLogger.LogType.DEBG, "FileHandler", $"Parentdir is {parentDir}"); @@ -174,7 +195,7 @@ public static void CheckRenameDirectory(string path) if (string.IsNullOrEmpty(dirName) || string.IsNullOrEmpty(parentDir)) return; string newPath = Path.Combine(parentDir, $"{dirName}{DateTime.Now:yyyyMMddHHmmss}"); - + if (Directory.Exists(newPath)) { MarseyLogger.Log(MarseyLogger.LogType.ERRO, "FileHandler", @@ -186,7 +207,7 @@ public static void CheckRenameDirectory(string path) // Completely evil, do not try-catch this - if it fails - it fails and kills everything. Directory.Move(path, newPath); } - + /// public static void CreateDir(string filePath) { @@ -196,7 +217,7 @@ public static void CreateDir(string filePath) Directory.CreateDirectory(directoryName); } } - + /// public static void SaveToFile(string filePath, MemoryStream stream) { diff --git a/Marsey/Misc/Utility.cs b/Marsey/Misc/Utility.cs index 816667b..35c34d3 100644 --- a/Marsey/Misc/Utility.cs +++ b/Marsey/Misc/Utility.cs @@ -69,7 +69,7 @@ private static bool CheckEnv(string envName) public static void ReadConf() { - Client MarseyConfPipeClient = new Client(); + IPC.Client MarseyConfPipeClient = new(); string config = MarseyConfPipeClient.ConnRecv("MarseyConf"); Dictionary envVars = config.Split(';') diff --git a/Marsey/Patches/MarseyPatch.cs b/Marsey/Patches/MarseyPatch.cs index 084550a..3b67d06 100644 --- a/Marsey/Patches/MarseyPatch.cs +++ b/Marsey/Patches/MarseyPatch.cs @@ -16,9 +16,6 @@ namespace Marsey.Patches; /// public static class Marsyfier { - public const string MarserializerFile = "patches.marsey"; - public const string PreloadMarserializerFile = "preload.marsey"; - public static List GetMarseyPatches() => PatchListManager.GetPatchList(); /// @@ -26,11 +23,9 @@ public static class Marsyfier /// public static void Preload(string[]? path = null) { - path ??= new[] { MarseyVars.MarseyPatchFolder }; - - List? preloads = Marserializer.Deserialize(path, filename: PreloadMarserializerFile); + List preloads = FileHandler.GetFilesFromPipe("PreloadMarseyPatchesPipe"); - if (preloads == null || preloads.Count == 0) return; + if (preloads.Count == 0) return; MarseyLogger.Log(MarseyLogger.LogType.INFO, "Preloader", $"Preloading {preloads.Count} patches."); diff --git a/Marsey/Subversion/Subverse.cs b/Marsey/Subversion/Subverse.cs index 57c5ae2..48b8f23 100644 --- a/Marsey/Subversion/Subverse.cs +++ b/Marsey/Subversion/Subverse.cs @@ -23,24 +23,24 @@ namespace Marsey.Subversion; public static class Subverse { private static List? _subverters = null; - + /// /// Check if we have any subversions enabled /// public static bool CheckSubversions() { - _subverters = Marserializer.Deserialize(new string[]{MarseyVars.MarseyPatchFolder}, Subverter.MarserializerFile); + _subverters = FileHandler.GetFilesFromPipe("SubverterPatchesPipe"); - return _subverters != null && _subverters.Count != 0; + return _subverters.Count != 0; } - + /// /// Patches subverter ahead of everything else /// This is done as we attach to the assembly loading function /// public static void PatchSubverter() { - + MethodInfo? Target = Helpers.GetMethod("Robust.Shared.ContentPack.ModLoader", "TryLoadModules"); MethodInfo? Postfix = Helpers.GetMethod(typeof(Subverse), "Postfix"); @@ -50,7 +50,7 @@ public static void PatchSubverter() Manual.Patch(Target, Postfix, HarmonyPatchType.Postfix); return; } - + MarseyLogger.Log(MarseyLogger.LogType.ERRO, "Subverter failed load!"); } @@ -58,34 +58,34 @@ private static void Postfix(object __instance) { MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Subversion", "Detour"); MethodInfo? loadGameAssemblyMethod = AccessTools.Method(AccessTools.TypeByName("Robust.Shared.ContentPack.BaseModLoader"), "InitMod"); - + if (loadGameAssemblyMethod == null) { MarseyLogger.Log(MarseyLogger.LogType.FATL, "Subversion", "Failed to find InitMod method."); return; } - + foreach (string path in _subverters!) { Assembly subverterAssembly = Assembly.LoadFrom(path); MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Subversion", $"Sideloading {path}"); AssemblyFieldHandler.InitLogger(subverterAssembly, subverterAssembly.FullName); - + loadGameAssemblyMethod.Invoke(__instance, new object[] { subverterAssembly }); - + MethodInfo? entryMethod = CheckEntry(subverterAssembly); if (entryMethod != null) { Doorbreak.Enter(entryMethod); } - + Subverter.Hide(subverterAssembly); } } - + private static MethodInfo? CheckEntry(Assembly assembly) { MethodInfo? entryMethod = AssemblyFieldHandler.GetEntry(assembly); return entryMethod; } -} \ No newline at end of file +} From 3edf4e4866cd1564938970f52defbaeba66341e2 Mon Sep 17 00:00:00 2001 From: Kaede Date: Sat, 18 May 2024 15:34:14 +0300 Subject: [PATCH 3/4] Demarserialization --- Marsey/Game/Resources/ResMan.cs | 1 - Marsey/Serializer/Marserializer.cs | 34 ------------------------------ Marsey/Subversion/Subverter.cs | 2 -- 3 files changed, 37 deletions(-) delete mode 100644 Marsey/Serializer/Marserializer.cs diff --git a/Marsey/Game/Resources/ResMan.cs b/Marsey/Game/Resources/ResMan.cs index 38977ac..e4a3ec4 100644 --- a/Marsey/Game/Resources/ResMan.cs +++ b/Marsey/Game/Resources/ResMan.cs @@ -10,7 +10,6 @@ namespace Marsey.Game.Resources; public static class ResMan { - public static readonly string MarserializerFile = "rpacks.marsey"; private static readonly List _resourcePacks = []; private static string? _fork; diff --git a/Marsey/Serializer/Marserializer.cs b/Marsey/Serializer/Marserializer.cs deleted file mode 100644 index f240a98..0000000 --- a/Marsey/Serializer/Marserializer.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Text.Json; -using System.Collections.Generic; -using System.IO; - -namespace Marsey.Serializer; - -/// -/// Handles patchlist serialization -/// -public static class Marserializer -{ - /// - public static void Serialize(string[]? path, string filename, List patches) - { - string jsonString = JsonSerializer.Serialize(patches); - string fullPath = Path.Combine(path ?? Array.Empty()); - fullPath = Path.Combine(fullPath, filename); - File.WriteAllText(fullPath, jsonString); - } - - /// - public static List? Deserialize(string[]? path, string filename) - { - string fullPath = Path.Combine(path ?? Array.Empty()); - fullPath = Path.Combine(fullPath, filename); - - if (!File.Exists(fullPath)) return null; - - string jsonString = File.ReadAllText(fullPath); - List? patches = JsonSerializer.Deserialize>(jsonString); - return patches; - } -} \ No newline at end of file diff --git a/Marsey/Subversion/Subverter.cs b/Marsey/Subversion/Subverter.cs index 71561cc..31e6fbd 100644 --- a/Marsey/Subversion/Subverter.cs +++ b/Marsey/Subversion/Subverter.cs @@ -14,8 +14,6 @@ namespace Marsey.Subversion; /// public static class Subverter { - public const string MarserializerFile = "subversion.marsey"; - /// /// Hides a subversion module from the game /// From bba9111acdc82de1012817e47dfb556f094cb6b0 Mon Sep 17 00:00:00 2001 From: Kaede Date: Sat, 18 May 2024 15:36:54 +0300 Subject: [PATCH 4/4] Move marsyfier into own class, remove references to Marsey.Serializer --- Marsey/Game/Resources/ResMan.cs | 2 -- Marsey/Misc/FileHandler.cs | 2 -- Marsey/Patches/MarseyPatch.cs | 43 --------------------------------- Marsey/Patches/Marsyfier.cs | 39 ++++++++++++++++++++++++++++++ Marsey/Subversion/Subverse.cs | 9 ------- 5 files changed, 39 insertions(+), 56 deletions(-) create mode 100644 Marsey/Patches/Marsyfier.cs diff --git a/Marsey/Game/Resources/ResMan.cs b/Marsey/Game/Resources/ResMan.cs index e4a3ec4..b10d4d6 100644 --- a/Marsey/Game/Resources/ResMan.cs +++ b/Marsey/Game/Resources/ResMan.cs @@ -3,8 +3,6 @@ using Marsey.Game.Resources.Dumper; using Marsey.Game.Resources.Reflection; using Marsey.Misc; -using Marsey.Serializer; -using Marsey.Stealthsey; namespace Marsey.Game.Resources; diff --git a/Marsey/Misc/FileHandler.cs b/Marsey/Misc/FileHandler.cs index 1be1b4a..873b417 100644 --- a/Marsey/Misc/FileHandler.cs +++ b/Marsey/Misc/FileHandler.cs @@ -1,11 +1,9 @@ using System.Reflection; using Marsey.Config; -using Marsey.Game.Patches; using Marsey.Game.Resources; using Marsey.Game.Resources.Dumper.Resource; using Marsey.PatchAssembly; using Marsey.Patches; -using Marsey.Serializer; using Marsey.Stealthsey; using Marsey.Subversion; diff --git a/Marsey/Patches/MarseyPatch.cs b/Marsey/Patches/MarseyPatch.cs index 3b67d06..29f4085 100644 --- a/Marsey/Patches/MarseyPatch.cs +++ b/Marsey/Patches/MarseyPatch.cs @@ -1,50 +1,7 @@ using System.Reflection; -using System.Collections.Generic; -using System.Text.Json.Serialization; -using Marsey.Config; -using Marsey.Game; -using Marsey.PatchAssembly; -using Marsey.Serializer; -using Marsey.Stealthsey; -using Marsey.Misc; -using Marsey.Stealthsey.Reflection; namespace Marsey.Patches; -/// -/// Manages MarseyPatch instances -/// -public static class Marsyfier -{ - public static List GetMarseyPatches() => PatchListManager.GetPatchList(); - - /// - /// Start preload of marseypatches that are flagged as such - /// - public static void Preload(string[]? path = null) - { - List preloads = FileHandler.GetFilesFromPipe("PreloadMarseyPatchesPipe"); - - if (preloads.Count == 0) return; - - MarseyLogger.Log(MarseyLogger.LogType.INFO, "Preloader", $"Preloading {preloads.Count} patches."); - - foreach (string patch in preloads) - { - MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Preloader", $"Preloading {patch}"); - FileHandler.LoadExactAssembly(patch); - } - - List preloadedPatches = GetMarseyPatches(); - - AssemblyFieldHandler.InitHelpers(preloadedPatches); - - if (preloadedPatches.Count != 0) Patcher.Patch(preloadedPatches); - - PatchListManager.ResetList(); - } -} - /// /// This class contains the data about a patch (called a Marsey), that is later used the loader to alter the game's functionality. /// diff --git a/Marsey/Patches/Marsyfier.cs b/Marsey/Patches/Marsyfier.cs new file mode 100644 index 0000000..0043e7c --- /dev/null +++ b/Marsey/Patches/Marsyfier.cs @@ -0,0 +1,39 @@ +using Marsey.Game; +using Marsey.Misc; +using Marsey.PatchAssembly; + +namespace Marsey.Patches; + +/// +/// Manages MarseyPatch instances +/// +public static class Marsyfier +{ + public static List GetMarseyPatches() => PatchListManager.GetPatchList(); + + /// + /// Start preload of marseypatches that are flagged as such + /// + public static void Preload(string[]? path = null) + { + List preloads = FileHandler.GetFilesFromPipe("PreloadMarseyPatchesPipe"); + + if (preloads.Count == 0) return; + + MarseyLogger.Log(MarseyLogger.LogType.INFO, "Preloader", $"Preloading {preloads.Count} patches."); + + foreach (string patch in preloads) + { + MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Preloader", $"Preloading {patch}"); + FileHandler.LoadExactAssembly(patch); + } + + List preloadedPatches = GetMarseyPatches(); + + AssemblyFieldHandler.InitHelpers(preloadedPatches); + + if (preloadedPatches.Count != 0) Patcher.Patch(preloadedPatches); + + PatchListManager.ResetList(); + } +} diff --git a/Marsey/Subversion/Subverse.cs b/Marsey/Subversion/Subverse.cs index 48b8f23..fd2787e 100644 --- a/Marsey/Subversion/Subverse.cs +++ b/Marsey/Subversion/Subverse.cs @@ -1,18 +1,9 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Reflection; using HarmonyLib; -using Marsey.Config; -using Marsey.Game; using Marsey.Game.Misc; using Marsey.Handbreak; -using Marsey.Stealthsey; using Marsey.Misc; using Marsey.PatchAssembly; -using Marsey.Serializer; -using Marsey.Stealthsey.Reflection; namespace Marsey.Subversion;