1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 22:13:30 +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

@@ -3,24 +3,12 @@ using HarmonyLib;
namespace UXAssist.Common;
public static class GameLogic
public class GameLogic: PatchImpl<GameLogic>
{
private static Harmony _harmony;
public static Action OnDataLoaded;
public static Action OnGameBegin;
public static Action OnGameEnd;
public static void Init()
{
_harmony ??= Harmony.CreateAndPatchAll(typeof(GameLogic));
}
public static void Uninit()
{
_harmony?.UnpatchSelf();
_harmony = null;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), nameof(VFPreload.InvokeOnLoadWorkEnded))]
public static void VFPreload_InvokeOnLoadWorkEnded_Postfix()

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

View File

@@ -8,11 +8,13 @@ namespace UXAssist.Common;
public static class Util
{
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
public static Type[] GetTypesFiltered(Assembly assembly, Func<Type, bool> predicate)
{
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
return assembly.GetTypes().Where(predicate).ToArray();
}
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) => GetTypesFiltered(assembly, t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal));
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
{
if (assembly == null)