1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 03:33:29 +08:00

WIP for UXAssist new features

This commit is contained in:
2025-04-13 20:05:20 +08:00
parent cdd71006b8
commit 5674d601ec
7 changed files with 302 additions and 112 deletions

View File

@@ -27,25 +27,27 @@ public class PatchSetCallbackFlagAttribute(PatchCallbackFlag flag) : Attribute
public class PatchImpl<T> where T : PatchImpl<T>, new()
{
private static T Instance { get; } = new();
private Harmony _patch;
protected static T Instance { get; } = new();
protected Harmony _patch;
public static void Enable(bool enable)
{
var thisInstance = Instance;
if (enable)
{
if (thisInstance._patch != null) return;
var guid = typeof(T).GetCustomAttribute<PatchGuidAttribute>()?.Guid ?? $"PatchImpl.{typeof(T).FullName ?? typeof(T).ToString()}";
var callOnEnableBefore = typeof(T).GetCustomAttributes<PatchSetCallbackFlagAttribute>().Any(n => n.Flag == PatchCallbackFlag.CallOnEnableBeforePatch);
if (callOnEnableBefore) thisInstance.OnEnable();
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid);
thisInstance._patch = Harmony.CreateAndPatchAll(typeof(T), guid);
if (!callOnEnableBefore) thisInstance.OnEnable();
return;
}
if (thisInstance._patch == null) return;
var callOnDisableAfter = typeof(T).GetCustomAttributes<PatchSetCallbackFlagAttribute>().Any(n => n.Flag == PatchCallbackFlag.CallOnDisableAfterUnpatch);
if (!callOnDisableAfter) thisInstance.OnDisable();
thisInstance._patch?.UnpatchSelf();
thisInstance._patch.UnpatchSelf();
thisInstance._patch = null;
if (callOnDisableAfter) thisInstance.OnDisable();
}