mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
WIP for UXAssist new features
This commit is contained in:
@@ -29,4 +29,11 @@ public static class KeyBindings
|
||||
|
||||
return new CombineKey((int)shortcut.MainKey, mod, ECombineKeyAction.OnceClick, false);
|
||||
}
|
||||
|
||||
public static bool IsKeyPressing(this PressKeyBind keyBind)
|
||||
{
|
||||
var defBind = keyBind.defaultBind;
|
||||
var overrideKey = VFInput.override_keys[defBind.id];
|
||||
return overrideKey.IsNull() ? defBind.key.GetKey() : overrideKey.GetKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user