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

107 lines
2.9 KiB
C#
Raw Normal View History

using HarmonyLib;
using OWML.Common;
using OWML.Utils;
2021-04-29 17:30:45 +00:00
using QSB.Animation.NPC.Patches;
2021-04-23 23:10:29 +00:00
using QSB.Animation.Patches;
2021-03-29 22:36:51 +00:00
using QSB.CampfireSync.Patches;
using QSB.ConversationSync.Patches;
using QSB.DeathSync.Patches;
using QSB.ElevatorSync.Patches;
using QSB.FrequencySync.Patches;
2021-03-25 21:10:20 +00:00
using QSB.GeyserSync.Patches;
2021-06-11 13:34:27 +00:00
using QSB.Inputs.Patches;
2021-02-23 14:42:18 +00:00
using QSB.ItemSync.Patches;
using QSB.LogSync.Patches;
using QSB.OrbSync.Patches;
2021-04-18 08:29:12 +00:00
using QSB.Player.Patches;
using QSB.PoolSync.Patches;
using QSB.QuantumSync.Patches;
2021-03-30 16:28:05 +00:00
using QSB.RoastingSync.Patches;
2021-04-12 10:31:21 +00:00
using QSB.ShipSync.Patches;
2021-02-28 14:43:05 +00:00
using QSB.StatueSync.Patches;
2021-06-12 14:58:34 +00:00
using QSB.TimeSync.Patches;
using QSB.Tools.ProbeLauncherTool.Patches;
using QSB.TranslationSync.Patches;
2020-11-03 21:11:10 +00:00
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
namespace QSB.Patches
{
2020-12-02 21:29:53 +00:00
public static class QSBPatchManager
{
2021-02-06 22:03:10 +00:00
public static event Action<QSBPatchTypes> OnPatchType;
2021-02-09 17:18:01 +00:00
public static event Action<QSBPatchTypes> OnUnpatchType;
2020-11-04 20:01:28 +00:00
2020-12-14 21:20:53 +00:00
private static List<QSBPatch> _patchList = new List<QSBPatch>();
2020-12-14 20:41:56 +00:00
public static Harmony HarmonyInstance;
2020-12-14 21:20:53 +00:00
public static void Init()
2020-12-02 21:29:53 +00:00
{
_patchList = new List<QSBPatch>
{
new ConversationPatches(),
new DeathPatches(),
new ElevatorPatches(),
new OrbPatches(),
2020-12-21 19:41:53 +00:00
new LogPatches(),
2020-12-22 21:39:53 +00:00
new QuantumVisibilityPatches(),
2021-01-18 12:33:07 +00:00
new ServerQuantumPatches(),
new ClientQuantumPatches(),
new FrequencyPatches(),
2021-01-18 12:33:07 +00:00
new SpiralPatches(),
2021-02-23 14:42:18 +00:00
new QuantumPatches(),
2021-02-28 14:43:05 +00:00
new ItemPatches(),
2021-03-25 21:10:20 +00:00
new StatuePatches(),
new GeyserPatches(),
2021-03-29 22:36:51 +00:00
new PoolPatches(),
2021-03-30 16:28:05 +00:00
new CampfirePatches(),
2021-04-12 10:31:21 +00:00
new RoastingPatches(),
2021-04-23 23:10:29 +00:00
new PlayerPatches(),
2021-04-26 13:30:21 +00:00
new PlayerAnimationPatches(),
2021-05-10 13:30:38 +00:00
new CharacterAnimationPatches(),
2021-06-11 13:34:27 +00:00
new ShipPatches(),
2021-06-12 14:58:34 +00:00
new InputPatches(),
2021-06-22 20:02:09 +00:00
new TimePatches(),
2021-06-23 11:06:08 +00:00
new MapPatches(),
new RespawnPatches(),
new LauncherPatches()
2020-12-02 21:29:53 +00:00
};
2020-11-03 21:11:10 +00:00
HarmonyInstance = QSBCore.Helper.HarmonyHelper.GetValue<Harmony>("_harmony");
2020-12-02 21:29:53 +00:00
DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success);
}
2020-11-03 21:11:10 +00:00
2020-12-02 21:29:53 +00:00
public static void DoPatchType(QSBPatchTypes type)
{
2021-02-06 22:03:10 +00:00
OnPatchType?.SafeInvoke(type);
DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
2020-12-02 21:29:53 +00:00
foreach (var patch in _patchList.Where(x => x.Type == type))
{
DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info);
try
{
patch.DoPatches();
}
catch (Exception ex)
{
DebugLog.DebugWrite($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error);
}
2020-12-02 21:29:53 +00:00
}
}
2021-02-09 17:18:01 +00:00
public static void DoUnpatchType(QSBPatchTypes type)
{
OnUnpatchType?.SafeInvoke(type);
DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
2021-02-09 17:18:01 +00:00
foreach (var patch in _patchList.Where(x => x.Type == type))
{
DebugLog.DebugWrite($" - Unpatching in {patch.GetType().Name}", MessageType.Info);
2021-02-09 17:18:01 +00:00
patch.DoUnpatches();
}
}
2020-12-02 21:29:53 +00:00
}
2020-12-03 08:28:05 +00:00
}