mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 02:53:29 +08:00
WIP
This commit is contained in:
@@ -10,22 +10,18 @@ public class PatchImplGuidAttribute(string guid) : Attribute
|
||||
public string Guid { get; } = guid;
|
||||
}
|
||||
|
||||
public class PatchImpl<T> where T : new()
|
||||
public class PatchImpl<T> where T : PatchImpl<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;
|
||||
}
|
||||
var thisInstance = Instance;
|
||||
if (enable)
|
||||
{
|
||||
var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid;
|
||||
var guid = typeof(T).GetCustomAttribute<PatchImplGuidAttribute>()?.Guid ?? $"PatchImpl.{typeof(T).FullName ?? typeof(T).ToString()}";
|
||||
thisInstance._patch ??= Harmony.CreateAndPatchAll(typeof(T), guid);
|
||||
thisInstance.OnEnable();
|
||||
return;
|
||||
@@ -35,7 +31,7 @@ public class PatchImpl<T> where T : new()
|
||||
thisInstance._patch = null;
|
||||
}
|
||||
|
||||
public static Harmony GetHarmony() => (Instance as PatchImpl<T>)?._patch;
|
||||
public static Harmony GetHarmony() => Instance._patch;
|
||||
|
||||
protected virtual void OnEnable() { }
|
||||
protected virtual void OnDisable() { }
|
||||
|
||||
Reference in New Issue
Block a user