quantum-space-buddies/QSB/Patches/QSBPatch.cs

40 lines
826 B
C#
Raw Normal View History

using HarmonyLib;
using QSB.Utility;
2022-03-22 17:56:41 +00:00
using System;
2021-06-18 20:54:32 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.Patches;
public abstract class QSBPatch
2020-11-03 21:11:10 +00:00
{
2022-03-03 03:46:33 +00:00
public abstract QSBPatchTypes Type { get; }
2021-06-18 20:54:32 +00:00
2022-03-03 03:46:33 +00:00
public void DoPatches(Harmony instance) => instance.PatchAll(GetType());
2022-03-22 17:56:41 +00:00
#region remote calls
protected static bool Remote { get; private set; }
protected static object RemoteData { get; private set; }
public static void RemoteCall(Action call, object data = null)
{
Remote = true;
RemoteData = data;
nameof(QSBPatch).Try("doing remote call", call);
2022-03-22 17:56:41 +00:00
Remote = false;
RemoteData = null;
}
public static T RemoteCall<T>(Func<T> call, object data = null)
{
Remote = true;
RemoteData = data;
var t = default(T);
nameof(QSBPatch).Try("doing remote call", () => t = call());
2022-03-22 17:56:41 +00:00
Remote = false;
RemoteData = null;
return t;
}
#endregion
}