diff --git a/CheatEnabler/CheatEnabler.cs b/CheatEnabler/CheatEnabler.cs index de8545f..4334c97 100644 --- a/CheatEnabler/CheatEnabler.cs +++ b/CheatEnabler/CheatEnabler.cs @@ -4,6 +4,7 @@ using BepInEx; using CheatEnabler.Patches; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler; @@ -96,26 +97,23 @@ public class CheatEnabler : BaseUnityPlugin CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false, "Buildings invincible"); UIConfigWindow.Init(); - _patches = Util.GetTypesFiltered(Assembly.GetExecutingAssembly(), - t => string.Equals(t.Namespace, "CheatEnabler.Patches", StringComparison.Ordinal) || string.Equals(t.Namespace, "CheatEnabler.Functions", StringComparison.Ordinal)); - _patches?.Do(type => type.GetMethod("Init")?.Invoke(null, null)); + ModFeatureRegistry.Discover(Assembly.GetExecutingAssembly()); + ModFeatureRegistry.InitAll(); } - private Type[] _patches; - private void Start() { - _patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null)); + ModFeatureRegistry.StartAll(); } private void OnDestroy() { - _patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null)); + ModFeatureRegistry.UninitAll(); } private void Update() { if (VFInput.inputing) return; - FactoryPatch.OnInputUpdate(); + ModFeatureRegistry.OnInputUpdateAll(); } } \ No newline at end of file diff --git a/CheatEnabler/Functions/DysonSphereFunctions.cs b/CheatEnabler/Functions/DysonSphereFunctions.cs index 5306c14..683b639 100644 --- a/CheatEnabler/Functions/DysonSphereFunctions.cs +++ b/CheatEnabler/Functions/DysonSphereFunctions.cs @@ -7,9 +7,11 @@ using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Functions; +[ModFeature("DysonSphereFunctions")] public static class DysonSphereFunctions { public static ConfigEntry IllegalDysonShellFunctionsEnabled; diff --git a/CheatEnabler/Functions/PlanetFunctions.cs b/CheatEnabler/Functions/PlanetFunctions.cs index 54471c9..371232d 100644 --- a/CheatEnabler/Functions/PlanetFunctions.cs +++ b/CheatEnabler/Functions/PlanetFunctions.cs @@ -1,7 +1,9 @@ using Random = UnityEngine.Random; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Functions; +[ModFeature("PlanetFunctions")] public static class PlanetFunctions { public static void BuryAllVeins(bool bury) diff --git a/CheatEnabler/Functions/PlayerFunctions.cs b/CheatEnabler/Functions/PlayerFunctions.cs index 2bb2c97..607d26a 100644 --- a/CheatEnabler/Functions/PlayerFunctions.cs +++ b/CheatEnabler/Functions/PlayerFunctions.cs @@ -1,9 +1,11 @@ using System; using System.Linq; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Functions; +[ModFeature("PlayerFunctions")] public static class PlayerFunctions { public static void Init() diff --git a/CheatEnabler/Patches/CombatPatch.cs b/CheatEnabler/Patches/CombatPatch.cs index 4f2e671..2288466 100644 --- a/CheatEnabler/Patches/CombatPatch.cs +++ b/CheatEnabler/Patches/CombatPatch.cs @@ -4,9 +4,11 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Patches; +[ModFeature("Combat")] public static class CombatPatch { public static ConfigEntry MechaInvincibleEnabled; diff --git a/CheatEnabler/Patches/DysonSpherePatch.cs b/CheatEnabler/Patches/DysonSpherePatch.cs index ab4a86a..b2f24d3 100644 --- a/CheatEnabler/Patches/DysonSpherePatch.cs +++ b/CheatEnabler/Patches/DysonSpherePatch.cs @@ -4,10 +4,12 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; using GameLogicProc = UXAssist.Common.GameLogic; namespace CheatEnabler.Patches; +[ModFeature("DysonSphere")] public class DysonSpherePatch : PatchImpl { public static ConfigEntry SkipBulletEnabled; diff --git a/CheatEnabler/Patches/FactoryPatch.cs b/CheatEnabler/Patches/FactoryPatch.cs index 033981e..968c4bb 100644 --- a/CheatEnabler/Patches/FactoryPatch.cs +++ b/CheatEnabler/Patches/FactoryPatch.cs @@ -8,10 +8,12 @@ using HarmonyLib; using UnityEngine; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.ModFeatures; using GameLogicProc = UXAssist.Common.GameLogic; namespace CheatEnabler.Patches; +[ModFeature("Factory")] public class FactoryPatch : PatchImpl { public static ConfigEntry ImmediateEnabled; diff --git a/CheatEnabler/Patches/GamePatch.cs b/CheatEnabler/Patches/GamePatch.cs index 9dae83e..9ab8f0c 100644 --- a/CheatEnabler/Patches/GamePatch.cs +++ b/CheatEnabler/Patches/GamePatch.cs @@ -5,9 +5,11 @@ using BepInEx.Configuration; using HarmonyLib; using UnityEngine.Bindings; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Patches; +[ModFeature("Game")] public static class GamePatch { public static ConfigEntry DevShortcutsEnabled; diff --git a/CheatEnabler/Patches/PlanetPatch.cs b/CheatEnabler/Patches/PlanetPatch.cs index 85773df..5d3a4e8 100644 --- a/CheatEnabler/Patches/PlanetPatch.cs +++ b/CheatEnabler/Patches/PlanetPatch.cs @@ -4,9 +4,11 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Patches; +[ModFeature("Planet")] public static class PlanetPatch { public static ConfigEntry WaterPumpAnywhereEnabled; diff --git a/CheatEnabler/Patches/PlayerPatch.cs b/CheatEnabler/Patches/PlayerPatch.cs index 82a0fce..3dd7525 100644 --- a/CheatEnabler/Patches/PlayerPatch.cs +++ b/CheatEnabler/Patches/PlayerPatch.cs @@ -3,9 +3,11 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Patches; +[ModFeature("Player")] public static class PlayerPatch { public static ConfigEntry InstantHandCraftEnabled; diff --git a/CheatEnabler/Patches/ResourcePatch.cs b/CheatEnabler/Patches/ResourcePatch.cs index 3b4e214..9608118 100644 --- a/CheatEnabler/Patches/ResourcePatch.cs +++ b/CheatEnabler/Patches/ResourcePatch.cs @@ -3,9 +3,11 @@ using System.Reflection.Emit; using BepInEx.Configuration; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.ModFeatures; namespace CheatEnabler.Patches; +[ModFeature("Resource")] public static class ResourcePatch { public static ConfigEntry InfiniteResourceEnabled; diff --git a/UXAssist/Common/ModFeatures/ModFeatureRegistry.cs b/UXAssist/Common/ModFeatures/ModFeatureRegistry.cs index bad9b39..16ffc77 100644 --- a/UXAssist/Common/ModFeatures/ModFeatureRegistry.cs +++ b/UXAssist/Common/ModFeatures/ModFeatureRegistry.cs @@ -55,8 +55,9 @@ public static class ModFeatureRegistry if (!_discoveredAssemblies.Add(assembly)) return; var staticTypes = Util.GetTypesFiltered(assembly, t => - t.IsClass && t.IsAbstract && t.IsSealed && - Attribute.IsDefined(t, typeof(ModFeatureAttribute))); + t.IsClass && !t.IsInterface && + Attribute.IsDefined(t, typeof(ModFeatureAttribute)) && + !typeof(IModFeature).IsAssignableFrom(t)); foreach (var type in staticTypes.OrderBy(GetOrder)) {