1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 12:53:34 +08:00
This commit is contained in:
2024-09-18 01:41:08 +08:00
parent fb916b3813
commit bd512a6b78
17 changed files with 232 additions and 207 deletions

View File

@@ -1,7 +1,15 @@
using HarmonyLib;
using System;
using System.Reflection;
using HarmonyLib;
namespace UXAssist.Common;
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class PatchImplGuidAttribute(string guid) : Attribute
{
public string Guid { get; } = guid;
}
public class PatchImpl<T> where T : new()
{
private static T Instance { get; } = new();
@@ -17,7 +25,8 @@ public class PatchImpl<T> where T : new()
}
if (enable)
{
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T));
var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid;
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid);
thisInstance.OnEnable();
return;
}
@@ -26,7 +35,7 @@ public class PatchImpl<T> where T : new()
thisInstance._patch = null;
}
protected static Harmony GetPatch() => (Instance as PatchImpl<T>)?._patch;
public static Harmony GetHarmony() => (Instance as PatchImpl<T>)?._patch;
protected virtual void OnEnable() { }
protected virtual void OnDisable() { }