2021-10-15 20:06:51 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using OWML.Common;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using QSB.Anglerfish.Patches;
|
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;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.ConversationSync.Patches;
|
|
|
|
|
using QSB.DeathSync.Patches;
|
2021-11-09 19:39:56 +00:00
|
|
|
|
using QSB.EchoesOfTheEye.LightSensorSync.Patches;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.ElevatorSync.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;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.LogSync.Patches;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using QSB.MeteorSync.Patches;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.OrbSync.Patches;
|
2021-04-18 08:29:12 +00:00
|
|
|
|
using QSB.Player.Patches;
|
2021-03-28 16:53:05 +00:00
|
|
|
|
using QSB.PoolSync.Patches;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.QuantumSync.Patches;
|
2021-03-30 16:28:05 +00:00
|
|
|
|
using QSB.RoastingSync.Patches;
|
2021-11-03 09:18:52 +00:00
|
|
|
|
using QSB.SatelliteSync.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;
|
2021-07-24 20:25:29 +00:00
|
|
|
|
using QSB.Tools.ProbeLauncherTool.Patches;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using QSB.Tools.SignalscopeTool.FrequencySync.Patches;
|
2021-11-25 15:25:17 +00:00
|
|
|
|
using QSB.Tools.TranslatorTool.TranslationSync.Patches;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
using QSB.Utility;
|
2021-11-29 22:57:13 +00:00
|
|
|
|
using QSB.ZeroGCaveSync.Patches;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
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
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private static List<QSBPatch> _patchList = new();
|
|
|
|
|
private static List<QSBPatchTypes> _patchedTypes = new();
|
2020-12-14 20:41:56 +00:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
public static Dictionary<QSBPatchTypes, Harmony> TypeToInstance = new();
|
2021-10-15 20:06:51 +00:00
|
|
|
|
|
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(),
|
2020-12-31 12:10:55 +00:00
|
|
|
|
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(),
|
2021-03-28 16:53:05 +00:00
|
|
|
|
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(),
|
2021-10-30 15:15:06 +00:00
|
|
|
|
new LauncherPatches(),
|
2021-11-03 09:18:52 +00:00
|
|
|
|
new SolanumPatches(),
|
2021-11-08 20:55:53 +00:00
|
|
|
|
new SatelliteProjectorPatches(),
|
2021-11-10 01:56:45 +00:00
|
|
|
|
new LightSensorPatches(),
|
2021-11-11 02:40:02 +00:00
|
|
|
|
new AnglerPatches(),
|
2021-11-11 05:13:49 +00:00
|
|
|
|
new MeteorClientPatches(),
|
2021-11-23 08:41:05 +00:00
|
|
|
|
new MeteorServerPatches(),
|
2021-11-29 22:57:13 +00:00
|
|
|
|
new TravelerControllerPatches(),
|
|
|
|
|
new ZeroGCavePatches()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
};
|
2020-11-03 21:11:10 +00:00
|
|
|
|
|
2021-10-16 13:12:28 +00:00
|
|
|
|
TypeToInstance = new Dictionary<QSBPatchTypes, Harmony>
|
|
|
|
|
{
|
2021-10-16 13:15:25 +00:00
|
|
|
|
{ QSBPatchTypes.OnClientConnect, new Harmony("QSB.Client") },
|
|
|
|
|
{ QSBPatchTypes.OnServerClientConnect, new Harmony("QSB.Server") },
|
|
|
|
|
{ QSBPatchTypes.OnNonServerClientConnect, new Harmony("QSB.NonServer") },
|
|
|
|
|
{ QSBPatchTypes.RespawnTime, new Harmony("QSB.Death") }
|
2021-10-16 13:12:28 +00:00
|
|
|
|
};
|
2021-10-15 20:06:51 +00:00
|
|
|
|
|
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-11-18 16:00:51 +00:00
|
|
|
|
if (_patchedTypes.Contains(type))
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Tried to patch type {type}, when it has already been patched!", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 22:03:10 +00:00
|
|
|
|
OnPatchType?.SafeInvoke(type);
|
2021-10-16 22:19:49 +00:00
|
|
|
|
//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))
|
|
|
|
|
{
|
2021-10-16 22:19:49 +00:00
|
|
|
|
//DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info);
|
2021-10-15 20:06:51 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-10-16 13:12:28 +00:00
|
|
|
|
patch.DoPatches(TypeToInstance[type]);
|
2021-11-18 16:00:51 +00:00
|
|
|
|
_patchedTypes.Add(type);
|
2021-10-15 20:06:51 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2021-10-24 09:47:25 +00:00
|
|
|
|
DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error);
|
2021-10-15 20:06:51 +00:00
|
|
|
|
}
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-09 17:18:01 +00:00
|
|
|
|
|
|
|
|
|
public static void DoUnpatchType(QSBPatchTypes type)
|
|
|
|
|
{
|
2021-11-18 16:00:51 +00:00
|
|
|
|
if (!_patchedTypes.Contains(type))
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Tried to unpatch type {type}, when it is either unpatched or was never patched.", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 17:18:01 +00:00
|
|
|
|
OnUnpatchType?.SafeInvoke(type);
|
2021-10-16 22:19:49 +00:00
|
|
|
|
//DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
|
2021-10-16 13:12:28 +00:00
|
|
|
|
TypeToInstance[type].UnpatchSelf();
|
2021-11-18 16:00:51 +00:00
|
|
|
|
_patchedTypes.Remove(type);
|
2021-02-09 17:18:01 +00:00
|
|
|
|
}
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2021-11-10 01:56:45 +00:00
|
|
|
|
}
|