From 720477853dcd4f99a1b5af63b5e8d330131506f0 Mon Sep 17 00:00:00 2001 From: Kaede Date: Fri, 24 Nov 2023 21:50:17 +0200 Subject: [PATCH] Full subverter support --- Marsey/MarseyPatcher.cs | 7 +++- Marsey/PatchAssemblyManager.cs | 4 +- Marsey/Subversion/Subverse.cs | 39 +++++++++++++++++++ Marsey/Subversion/Subverter.cs | 2 +- .../MainWindowTabs/PatchesTabViewModel.cs | 27 ++++++++++++- .../Views/MainWindowTabs/PatchesTabView.xaml | 3 +- 6 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 Marsey/Subversion/Subverse.cs diff --git a/Marsey/MarseyPatcher.cs b/Marsey/MarseyPatcher.cs index c4c3b2f..ca44076 100644 --- a/Marsey/MarseyPatcher.cs +++ b/Marsey/MarseyPatcher.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading; using HarmonyLib; +using Marsey.Subversion; namespace Marsey; @@ -23,10 +24,12 @@ public class MarseyPatcher public static void Boot(Assembly? robClientAssembly) { if (robClientAssembly == null) throw new Exception("Robust.Client was null."); - + Utility.SetupFlags(); GameAssemblyManager.Init(new Harmony(MarseyVars.Identifier)); + + if (Subverse.InitSubverter()) Subverse.PatchSubverter(); GameAssemblyManager.GetGameAssemblies(out var clientAss, out var robustSharedAss, out var clientSharedAss); @@ -34,7 +37,7 @@ public static void Boot(Assembly? robClientAssembly) FileHandler.LoadAssemblies(new []{"Marsey", "Enabled"}); - PatchAssemblyManager.InitLogger(); + PatchAssemblyManager.InitLogger(PatchAssemblyManager.GetPatchList()); GameAssemblyManager.PatchProc(PatchAssemblyManager.GetPatchList()); } diff --git a/Marsey/PatchAssemblyManager.cs b/Marsey/PatchAssemblyManager.cs index 1145db4..d8559c0 100644 --- a/Marsey/PatchAssemblyManager.cs +++ b/Marsey/PatchAssemblyManager.cs @@ -81,9 +81,9 @@ public static void InitAssembly(Assembly assembly, bool subverter = false) /// Executed only by the loader. /// MarseyLogger example can be found in the BasePatch MarseyPatch example. /// - public static void InitLogger() + public static void InitLogger(List patches) { - foreach (MarseyPatch patch in _patchAssemblies) + foreach (MarseyPatch patch in patches) { Assembly assembly = patch.Asm; diff --git a/Marsey/Subversion/Subverse.cs b/Marsey/Subversion/Subverse.cs new file mode 100644 index 0000000..4979b87 --- /dev/null +++ b/Marsey/Subversion/Subverse.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace Marsey.Subversion; + +public static class Subverse +{ + private static MarseyPatch? _subverter = null; + + public static bool InitSubverter() + { + if (_subverter != null) + return true; + + Subverter.LoadSubverts(); + List patches = Subverter.GetSubverterPatches(); + foreach (MarseyPatch p in patches) + { + if (p.Name == "Subverter") + { + AssignSubverter(p); + PatchAssemblyManager.InitLogger(patches); + patches.RemoveAll(p => p.Name == "Subverter"); + return true; + } + } + + return false; + } + + private static void AssignSubverter(MarseyPatch subverter) + { + _subverter = subverter; + } + + public static void PatchSubverter() + { + if (_subverter != null) GameAssemblyManager.PatchProc(new List() { _subverter }); + } +} \ No newline at end of file diff --git a/Marsey/Subversion/Subverter.cs b/Marsey/Subversion/Subverter.cs index a9e4484..facb4a5 100644 --- a/Marsey/Subversion/Subverter.cs +++ b/Marsey/Subversion/Subverter.cs @@ -24,7 +24,7 @@ public static void AddSubvert(MarseyPatch patch) _subverterPatches.Add(patch); } - public static void SubversionPatch() + public static void SubversionPatcher() { } diff --git a/SS14.Launcher/ViewModels/MainWindowTabs/PatchesTabViewModel.cs b/SS14.Launcher/ViewModels/MainWindowTabs/PatchesTabViewModel.cs index a642410..9c2112d 100644 --- a/SS14.Launcher/ViewModels/MainWindowTabs/PatchesTabViewModel.cs +++ b/SS14.Launcher/ViewModels/MainWindowTabs/PatchesTabViewModel.cs @@ -16,7 +16,7 @@ namespace SS14.Launcher.ViewModels.MainWindowTabs public class PatchesTabViewModel : MainWindowTabViewModel { public override string Name => "Plugins"; - + public bool SubverterPresent { get; set; } public ObservableCollection MarseyPatches { get; } = new ObservableCollection(); public ObservableCollection SubverterPatches { get; } = new ObservableCollection(); @@ -25,6 +25,7 @@ public class PatchesTabViewModel : MainWindowTabViewModel public PatchesTabViewModel() { + SubverterPresent = Subverse.InitSubverter(); OpenMarseyPatchDirectoryCommand = new RelayCommand(() => OpenPatchDirectory("Marsey")); OpenSubverterPatchDirectoryCommand = new RelayCommand(() => OpenPatchDirectory("Subversion")); LoadPatches(); @@ -33,8 +34,9 @@ public PatchesTabViewModel() private void LoadPatches() { FileHandler.LoadAssemblies(); - Subverter.LoadSubverts(); LoadPatchList(PatchAssemblyManager.GetPatchList(), MarseyPatches, "marseypatches"); + if (!SubverterPresent) return; + //Subverter.LoadSubverts(); LoadPatchList(Subverter.GetSubverterPatches(), SubverterPatches, "subverterpatches"); } @@ -70,4 +72,25 @@ public class PathToFileNameConverter : IValueConverter { return value; } +} + +public class BooleanToVisibilityConverter : IValueConverter +{ + public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool booleanValue) + { + return booleanValue; + } + throw new InvalidOperationException("Invalid boolean value"); + } + + public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool visibilityValue) + { + return visibilityValue; + } + throw new InvalidOperationException("Invalid visibility value"); + } } \ No newline at end of file diff --git a/SS14.Launcher/Views/MainWindowTabs/PatchesTabView.xaml b/SS14.Launcher/Views/MainWindowTabs/PatchesTabView.xaml index 5728ac7..8565a3c 100644 --- a/SS14.Launcher/Views/MainWindowTabs/PatchesTabView.xaml +++ b/SS14.Launcher/Views/MainWindowTabs/PatchesTabView.xaml @@ -8,6 +8,7 @@ x:Class="SS14.Launcher.Views.MainWindowTabs.PatchesTabView" Name="PatchesTab"> + @@ -40,7 +41,7 @@ - +