mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 04:13:32 +08:00
refactoring UXAssist and CheatEnabler
This commit is contained in:
33
UXAssist/Common/PatchImpl.cs
Normal file
33
UXAssist/Common/PatchImpl.cs
Normal 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() { }
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -6,6 +8,11 @@ namespace UXAssist.Common;
|
||||
|
||||
public static class Util
|
||||
{
|
||||
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
|
||||
{
|
||||
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
|
||||
}
|
||||
|
||||
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
|
||||
{
|
||||
if (assembly == null)
|
||||
|
||||
Reference in New Issue
Block a user