1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 10:53:31 +08:00

refactoring UXAssist and CheatEnabler

This commit is contained in:
2024-09-17 01:49:25 +08:00
parent db0a9522da
commit fb916b3813
31 changed files with 858 additions and 1260 deletions

View File

@@ -0,0 +1,33 @@
using HarmonyLib;
namespace UXAssist.Common;
public class PatchImpl<T> where T : new()
{
private static T Instance { get; } = new();
private Harmony _patch;
public static void Enable(bool enable)
{
if (Instance is not PatchImpl<T> thisInstance)
{
UXAssist.Logger.LogError($"PatchImpl<{typeof(T).Name}> is not inherited correctly");
return;
}
if (enable)
{
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T));
thisInstance.OnEnable();
return;
}
thisInstance.OnDisable();
thisInstance._patch?.UnpatchSelf();
thisInstance._patch = null;
}
protected static Harmony GetPatch() => (Instance as PatchImpl<T>)?._patch;
protected virtual void OnEnable() { }
protected virtual void OnDisable() { }
}