mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-08-05 10:20:13 +08:00
refactor(CheatEnabler): adopt ModFeatureRegistry from UXAssist
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<bool> IllegalDysonShellFunctionsEnabled;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<bool> MechaInvincibleEnabled;
|
||||
|
||||
@@ -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<DysonSpherePatch>
|
||||
{
|
||||
public static ConfigEntry<bool> SkipBulletEnabled;
|
||||
|
||||
@@ -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<FactoryPatch>
|
||||
{
|
||||
public static ConfigEntry<bool> ImmediateEnabled;
|
||||
|
||||
@@ -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<bool> DevShortcutsEnabled;
|
||||
|
||||
@@ -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<bool> WaterPumpAnywhereEnabled;
|
||||
|
||||
@@ -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<bool> InstantHandCraftEnabled;
|
||||
|
||||
@@ -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<bool> InfiniteResourceEnabled;
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user