1
0
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:
2024-09-17 01:49:25 +08:00
parent db0a9522da
commit fb916b3813
31 changed files with 858 additions and 1260 deletions

View 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() { }
}

View File

@@ -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)