mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
WIP
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user