refactor(CheatEnabler): adopt ModFeatureRegistry from UXAssist

This commit is contained in:
2026-06-23 03:33:19 +08:00
parent 39bdf06e88
commit 099f3ee35a
12 changed files with 29 additions and 10 deletions
+6 -8
View File
@@ -4,6 +4,7 @@ using BepInEx;
using CheatEnabler.Patches; using CheatEnabler.Patches;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler; namespace CheatEnabler;
@@ -96,26 +97,23 @@ public class CheatEnabler : BaseUnityPlugin
CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false, CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false,
"Buildings invincible"); "Buildings invincible");
UIConfigWindow.Init(); UIConfigWindow.Init();
_patches = Util.GetTypesFiltered(Assembly.GetExecutingAssembly(), ModFeatureRegistry.Discover(Assembly.GetExecutingAssembly());
t => string.Equals(t.Namespace, "CheatEnabler.Patches", StringComparison.Ordinal) || string.Equals(t.Namespace, "CheatEnabler.Functions", StringComparison.Ordinal)); ModFeatureRegistry.InitAll();
_patches?.Do(type => type.GetMethod("Init")?.Invoke(null, null));
} }
private Type[] _patches;
private void Start() private void Start()
{ {
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null)); ModFeatureRegistry.StartAll();
} }
private void OnDestroy() private void OnDestroy()
{ {
_patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null)); ModFeatureRegistry.UninitAll();
} }
private void Update() private void Update()
{ {
if (VFInput.inputing) return; if (VFInput.inputing) return;
FactoryPatch.OnInputUpdate(); ModFeatureRegistry.OnInputUpdateAll();
} }
} }
@@ -7,9 +7,11 @@ using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UnityEngine; using UnityEngine;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions; namespace CheatEnabler.Functions;
[ModFeature("DysonSphereFunctions")]
public static class DysonSphereFunctions public static class DysonSphereFunctions
{ {
public static ConfigEntry<bool> IllegalDysonShellFunctionsEnabled; public static ConfigEntry<bool> IllegalDysonShellFunctionsEnabled;
@@ -1,7 +1,9 @@
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions; namespace CheatEnabler.Functions;
[ModFeature("PlanetFunctions")]
public static class PlanetFunctions public static class PlanetFunctions
{ {
public static void BuryAllVeins(bool bury) public static void BuryAllVeins(bool bury)
@@ -1,9 +1,11 @@
using System; using System;
using System.Linq; using System.Linq;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Functions; namespace CheatEnabler.Functions;
[ModFeature("PlayerFunctions")]
public static class PlayerFunctions public static class PlayerFunctions
{ {
public static void Init() public static void Init()
+2
View File
@@ -4,9 +4,11 @@ using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Combat")]
public static class CombatPatch public static class CombatPatch
{ {
public static ConfigEntry<bool> MechaInvincibleEnabled; public static ConfigEntry<bool> MechaInvincibleEnabled;
+2
View File
@@ -4,10 +4,12 @@ using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using GameLogicProc = UXAssist.Common.GameLogic; using GameLogicProc = UXAssist.Common.GameLogic;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("DysonSphere")]
public class DysonSpherePatch : PatchImpl<DysonSpherePatch> public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
{ {
public static ConfigEntry<bool> SkipBulletEnabled; public static ConfigEntry<bool> SkipBulletEnabled;
+2
View File
@@ -8,10 +8,12 @@ using HarmonyLib;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using GameLogicProc = UXAssist.Common.GameLogic; using GameLogicProc = UXAssist.Common.GameLogic;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Factory")]
public class FactoryPatch : PatchImpl<FactoryPatch> public class FactoryPatch : PatchImpl<FactoryPatch>
{ {
public static ConfigEntry<bool> ImmediateEnabled; public static ConfigEntry<bool> ImmediateEnabled;
+2
View File
@@ -5,9 +5,11 @@ using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UnityEngine.Bindings; using UnityEngine.Bindings;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Game")]
public static class GamePatch public static class GamePatch
{ {
public static ConfigEntry<bool> DevShortcutsEnabled; public static ConfigEntry<bool> DevShortcutsEnabled;
+2
View File
@@ -4,9 +4,11 @@ using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Planet")]
public static class PlanetPatch public static class PlanetPatch
{ {
public static ConfigEntry<bool> WaterPumpAnywhereEnabled; public static ConfigEntry<bool> WaterPumpAnywhereEnabled;
+2
View File
@@ -3,9 +3,11 @@ using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Player")]
public static class PlayerPatch public static class PlayerPatch
{ {
public static ConfigEntry<bool> InstantHandCraftEnabled; public static ConfigEntry<bool> InstantHandCraftEnabled;
+2
View File
@@ -3,9 +3,11 @@ using System.Reflection.Emit;
using BepInEx.Configuration; using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures;
namespace CheatEnabler.Patches; namespace CheatEnabler.Patches;
[ModFeature("Resource")]
public static class ResourcePatch public static class ResourcePatch
{ {
public static ConfigEntry<bool> InfiniteResourceEnabled; public static ConfigEntry<bool> InfiniteResourceEnabled;
@@ -55,8 +55,9 @@ public static class ModFeatureRegistry
if (!_discoveredAssemblies.Add(assembly)) return; if (!_discoveredAssemblies.Add(assembly)) return;
var staticTypes = Util.GetTypesFiltered(assembly, t => var staticTypes = Util.GetTypesFiltered(assembly, t =>
t.IsClass && t.IsAbstract && t.IsSealed && t.IsClass && !t.IsInterface &&
Attribute.IsDefined(t, typeof(ModFeatureAttribute))); Attribute.IsDefined(t, typeof(ModFeatureAttribute)) &&
!typeof(IModFeature).IsAssignableFrom(t));
foreach (var type in staticTypes.OrderBy(GetOrder)) foreach (var type in staticTypes.OrderBy(GetOrder))
{ {