mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
event system fixes
This commit is contained in:
1 parent
13268ac70a
commit
a23de7b51c
6 files changed
+45
-40
No files matched your search
@@ -13,28 +13,12 @@ public static class ExampleEventHandlers
|
|||||||
// Register event handlers here
|
// Register event handlers here
|
||||||
MiraEventManager.RegisterEventHandler<MiraButtonClickEvent<FreezeButton>>(FreezeButtonClickHandler, 1);
|
MiraEventManager.RegisterEventHandler<MiraButtonClickEvent<FreezeButton>>(FreezeButtonClickHandler, 1);
|
||||||
MiraEventManager.RegisterEventHandler<MiraButtonCancelledEvent<FreezeButton>>(FreezeButtonCancelledHandler);
|
MiraEventManager.RegisterEventHandler<MiraButtonCancelledEvent<FreezeButton>>(FreezeButtonCancelledHandler);
|
||||||
MiraEventManager.RegisterEventHandler<EnterVentEvent>(EnterVentHandler);
|
MiraEventManager.RegisterEventHandler<UpdateSystemEvent>(UpdateSystemEventHandler);
|
||||||
MiraEventManager.RegisterEventHandler<ExitVentEvent>(ExitVentHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EnterVentHandler(EnterVentEvent @event)
|
public static void UpdateSystemEventHandler(UpdateSystemEvent @event)
|
||||||
{
|
{
|
||||||
Logger<ExamplePlugin>.Warning("Entering vent!");
|
Logger<ExamplePlugin>.Error(@event.SystemType.ToString());
|
||||||
var random = new System.Random();
|
|
||||||
if (random.Next(0, 2) == 0)
|
|
||||||
{
|
|
||||||
@event.Cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ExitVentHandler(ExitVentEvent @event)
|
|
||||||
{
|
|
||||||
Logger<ExamplePlugin>.Warning("Exiting vent!");
|
|
||||||
var random = new System.Random();
|
|
||||||
if (random.Next(0, 2) == 0)
|
|
||||||
{
|
|
||||||
@event.Cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example event handler
|
// Example event handler
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace MiraAPI.Events.Vanilla;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired when a player closes the doors in a room.
|
||||||
|
/// </summary>
|
||||||
|
public class CloseDoorsEvent : MiraCancelableEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the room that the doors were closed in.
|
||||||
|
/// </summary>
|
||||||
|
public SystemTypes Room { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="CloseDoorsEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="room">The room that was closed.</param>
|
||||||
|
public CloseDoorsEvent(SystemTypes room)
|
||||||
|
{
|
||||||
|
Room = room;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Events;
|
using MiraAPI.Events;
|
||||||
using MiraAPI.Events.Vanilla;
|
using MiraAPI.Events.Vanilla;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Events;
|
namespace MiraAPI.Patches.Events;
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,19 @@ namespace MiraAPI.Patches.Events;
|
|||||||
public static class SabotageEventPatches
|
public static class SabotageEventPatches
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.UpdateSystem), typeof(SystemTypes), typeof(PlayerControl), typeof(byte))]
|
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcUpdateSystem), typeof(SystemTypes), typeof(byte))]
|
||||||
public static bool ShipStatusUpdateSystemPrefix(ShipStatus __instance, SystemTypes systemType, PlayerControl player, byte amount)
|
public static bool ShipStatusUpdateSystemPrefix(ShipStatus __instance, SystemTypes systemType, byte amount)
|
||||||
{
|
{
|
||||||
var @event = new UpdateSystemEvent(systemType, player, amount);
|
var @event = new UpdateSystemEvent(systemType, PlayerControl.LocalPlayer, amount);
|
||||||
|
MiraEventManager.InvokeEvent(@event);
|
||||||
|
return !@event.IsCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcCloseDoorsOfType))]
|
||||||
|
public static bool ShipStatusCloseDoorsOfTypePrefix(ShipStatus __instance, SystemTypes type)
|
||||||
|
{
|
||||||
|
var @event = new CloseDoorsEvent(type);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
return !@event.IsCancelled;
|
return !@event.IsCancelled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ namespace MiraAPI.Patches.Events;
|
|||||||
public static class StartMeetingEventPatch
|
public static class StartMeetingEventPatch
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.ReportDeadBody))]
|
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CmdReportDeadBody))]
|
||||||
public static bool PlayerControlReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target)
|
public static bool PlayerControlCmdReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target)
|
||||||
{
|
{
|
||||||
var body = target != null ? Helpers.GetBodyById(target.PlayerId) : null;
|
var body = target != null ? Helpers.GetBodyById(target.PlayerId) : null;
|
||||||
|
|
||||||
var @event = new StartMeetingEvent(__instance, target, body);
|
var @event = new StartMeetingEvent(__instance, target, body);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
return !@event.IsCancelled;
|
return !@event.IsCancelled;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace MiraAPI.Patches.Events;
|
|||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
public static class VentEventPatches
|
public static class VentEventPatches
|
||||||
{
|
{
|
||||||
|
// necessary because Vent.Use is inlined in il2cpp.
|
||||||
private static bool _showButtons;
|
private static bool _showButtons;
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
@@ -24,8 +25,8 @@ public static class VentEventPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.CoEnterVent))]
|
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.RpcEnterVent))]
|
||||||
public static bool EnterVentPrefix(PlayerPhysics __instance, int id, ref Il2CppSystem.Collections.IEnumerator __result)
|
public static bool PlayerPhysicsRpcEnterVentPrefix(PlayerPhysics __instance, int id)
|
||||||
{
|
{
|
||||||
var pc = __instance.myPlayer;
|
var pc = __instance.myPlayer;
|
||||||
var vent = ShipStatus.Instance.AllVents.FirstOrDefault(v => v.Id == id);
|
var vent = ShipStatus.Instance.AllVents.FirstOrDefault(v => v.Id == id);
|
||||||
@@ -33,12 +34,6 @@ public static class VentEventPatches
|
|||||||
var @event = new EnterVentEvent(pc, vent);
|
var @event = new EnterVentEvent(pc, vent);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
|
|
||||||
if (@event.IsCancelled)
|
|
||||||
{
|
|
||||||
Logger<MiraApiPlugin>.Error("Enter vent event cancelled!");
|
|
||||||
__result = Helpers.EmptyCoroutine().WrapToIl2Cpp();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pc.AmOwner)
|
if (pc.AmOwner)
|
||||||
{
|
{
|
||||||
_showButtons = !@event.IsCancelled;
|
_showButtons = !@event.IsCancelled;
|
||||||
@@ -47,8 +42,8 @@ public static class VentEventPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.CoExitVent))]
|
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.RpcExitVent))]
|
||||||
public static bool ExitVentPrefix(PlayerPhysics __instance, int id, ref Il2CppSystem.Collections.IEnumerator __result)
|
public static bool PlayerPhysicsRpcExitVentPrefix(PlayerPhysics __instance, int id)
|
||||||
{
|
{
|
||||||
var pc = __instance.myPlayer;
|
var pc = __instance.myPlayer;
|
||||||
var vent = ShipStatus.Instance.AllVents.First(v => v.Id == id);
|
var vent = ShipStatus.Instance.AllVents.First(v => v.Id == id);
|
||||||
@@ -56,12 +51,6 @@ public static class VentEventPatches
|
|||||||
var @event = new ExitVentEvent(pc, vent);
|
var @event = new ExitVentEvent(pc, vent);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
|
|
||||||
if (@event.IsCancelled)
|
|
||||||
{
|
|
||||||
Logger<MiraApiPlugin>.Error("Exit vent event cancelled!");
|
|
||||||
__result = Helpers.EmptyCoroutine().WrapToIl2Cpp();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pc.AmOwner)
|
if (pc.AmOwner)
|
||||||
{
|
{
|
||||||
_showButtons = @event.IsCancelled;
|
_showButtons = @event.IsCancelled;
|
||||||
|
|||||||
Reference in new issue
Block a user