diff --git a/MiraAPI/Events/Vanilla/UpdateSystemEvent.cs b/MiraAPI/Events/Vanilla/UpdateSystemEvent.cs new file mode 100644 index 0000000..3353c36 --- /dev/null +++ b/MiraAPI/Events/Vanilla/UpdateSystemEvent.cs @@ -0,0 +1,28 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Cancelable event that is invoked before a system is updated. Usually used for sabotage events. +/// +public class UpdateSystemEvent : MiraCancelableEvent +{ + /// + /// Gets the type of system that will be updated. + /// + public SystemTypes SystemType { get; } + + /// + /// Gets the byte amount the system is being updated by. + /// + public byte Amount { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The SystemType being updated. + /// Amount to update System to. + public UpdateSystemEvent(SystemTypes systemType, byte amount) + { + SystemType = systemType; + Amount = amount; + } +} diff --git a/MiraAPI/Patches/Events/HudButtonEventPatches.cs b/MiraAPI/Patches/Events/HudButtonEventPatches.cs index 212bb75..0643b4f 100644 --- a/MiraAPI/Patches/Events/HudButtonEventPatches.cs +++ b/MiraAPI/Patches/Events/HudButtonEventPatches.cs @@ -7,6 +7,7 @@ namespace MiraAPI.Patches.Events; /// /// Patch for button related MiraEvents. /// +[HarmonyPatch] public static class HudButtonEventPatches { [HarmonyPrefix] diff --git a/MiraAPI/Patches/Events/SabotageEventPatches.cs b/MiraAPI/Patches/Events/SabotageEventPatches.cs new file mode 100644 index 0000000..9cd6fc3 --- /dev/null +++ b/MiraAPI/Patches/Events/SabotageEventPatches.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla; + +namespace MiraAPI.Patches.Events; + +/// +/// Used for patching sabotage/system related MiraEvents. +/// +[HarmonyPatch] +public static class SabotageEventPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcUpdateSystem), typeof(SystemTypes), typeof(byte))] + public static bool ShipStatusRpcUpdateSystemPrefix(ShipStatus __instance, SystemTypes systemType, byte amount) + { + var @event = new UpdateSystemEvent(systemType, amount); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } +}