-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
221 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace MiraAPI.Events.Vanilla.Map; | ||
|
||
/// <summary> | ||
/// Sabotage from Vanilla Among Us. | ||
/// </summary> | ||
public class PlayerOpenSabotageEvent : MiraCancelableEvent | ||
{ | ||
/// <summary> | ||
/// Gets the MapBehaviour. | ||
/// </summary> | ||
public MapBehaviour MapBehaviour { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlayerOpenSabotageEvent"/> class. | ||
/// </summary> | ||
/// <param name="mapBehaviour">The MapBehaviour.</param> | ||
public PlayerOpenSabotageEvent(MapBehaviour mapBehaviour) | ||
{ | ||
MapBehaviour = mapBehaviour; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace MiraAPI.Events.Vanilla.Usables; | ||
|
||
/// <summary> | ||
/// Event for if a <see cref="PlayerControl"/> can use an <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally. | ||
/// </summary> | ||
public class PlayerCanUseEvent : PlayerUseEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlayerCanUseEvent"/> class. | ||
/// </summary> | ||
/// <param name="usable">The IUsable.</param> | ||
public PlayerCanUseEvent(IUsable usable) : base(usable) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace MiraAPI.Events.Vanilla; | ||
|
||
/// <summary> | ||
/// Event for <see cref="PlayerControl"/> using a <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally. | ||
/// </summary> | ||
public class PlayerUseEvent : MiraCancelableEvent | ||
{ | ||
/// <summary> | ||
/// Gets the instance of <see cref="IUsable"/> that was used. | ||
/// </summary> | ||
public IUsable Usable { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the IUsable is a <see cref="Console"/>, <see cref="MapConsole"/>, or <see cref="SystemConsole"/>. | ||
/// </summary> | ||
public bool IsPrimaryConsole { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the IUsable is a <see cref="Vent"/>. | ||
/// </summary> | ||
public bool IsVent { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlayerUseEvent"/> class. | ||
/// </summary> | ||
/// <param name="usable">The IUsable.</param> | ||
public PlayerUseEvent(IUsable usable) | ||
{ | ||
Usable = usable; | ||
|
||
IsPrimaryConsole = usable.TryCast<Console>() || usable.TryCast<SystemConsole>() || usable.TryCast<MapConsole>(); | ||
IsVent = usable.TryCast<Vent>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using HarmonyLib; | ||
using MiraAPI.Events; | ||
using MiraAPI.Events.Vanilla.Usables; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace MiraAPI.Patches.Events; | ||
|
||
[HarmonyPatch] | ||
public static class CanUsePatches | ||
{ | ||
public static IEnumerable<MethodBase> TargetMethods() | ||
{ | ||
yield return AccessTools.Method(typeof(Console), nameof(Console.CanUse)); | ||
yield return AccessTools.Method(typeof(MapConsole), nameof(MapConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(SystemConsole), nameof(SystemConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(Ladder), nameof(Ladder.CanUse)); | ||
yield return AccessTools.Method(typeof(PlatformConsole), nameof(PlatformConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(OpenDoorConsole), nameof(OpenDoorConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(DoorConsole), nameof(DoorConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(OptionsConsole), nameof(OptionsConsole.CanUse)); | ||
yield return AccessTools.Method(typeof(ZiplineConsole), nameof(ZiplineConsole.CanUse)); | ||
} | ||
|
||
[HarmonyPriority(Priority.Last)] | ||
[HarmonyPrefix] | ||
public static bool CanUsePatch(Il2CppSystem.Object __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse) | ||
{ | ||
var @event = new PlayerCanUseEvent(__instance.Cast<IUsable>()); | ||
MiraEventManager.InvokeEvent(@event); | ||
|
||
canUse = couldUse = false; | ||
|
||
return !@event.IsCancelled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using HarmonyLib; | ||
using MiraAPI.Events; | ||
using MiraAPI.Events.Vanilla.Map; | ||
|
||
namespace MiraAPI.Patches.Events; | ||
|
||
/// <summary> | ||
/// Patch for map related MiraEvents. | ||
/// </summary> | ||
[HarmonyPatch] | ||
public static class MapBehaviourPatches | ||
{ | ||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(MapBehaviour), nameof(MapBehaviour.ShowSabotageMap))] | ||
public static bool MapShowSabotagePatch(MapBehaviour __instance) | ||
{ | ||
var @event = new PlayerOpenSabotageEvent(__instance); | ||
MiraEventManager.InvokeEvent(@event); | ||
return !@event.IsCancelled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using HarmonyLib; | ||
using MiraAPI.Events; | ||
using MiraAPI.Events.Vanilla; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace MiraAPI.Patches.Events; | ||
|
||
[HarmonyPatch] | ||
public static class UsePatches | ||
{ | ||
public static IEnumerable<MethodBase> TargetMethods() | ||
{ | ||
yield return AccessTools.Method(typeof(Console), nameof(Console.Use)); | ||
yield return AccessTools.Method(typeof(MapConsole), nameof(MapConsole.Use)); | ||
yield return AccessTools.Method(typeof(SystemConsole), nameof(SystemConsole.Use)); | ||
yield return AccessTools.Method(typeof(Vent), nameof(Vent.Use)); | ||
yield return AccessTools.Method(typeof(Ladder), nameof(Ladder.Use)); | ||
yield return AccessTools.Method(typeof(PlatformConsole), nameof(PlatformConsole.Use)); | ||
yield return AccessTools.Method(typeof(OpenDoorConsole), nameof(OpenDoorConsole.Use)); | ||
yield return AccessTools.Method(typeof(DoorConsole), nameof(DoorConsole.Use)); | ||
yield return AccessTools.Method(typeof(OptionsConsole), nameof(OptionsConsole.Use)); | ||
yield return AccessTools.Method(typeof(ZiplineConsole), nameof(ZiplineConsole.Use)); | ||
} | ||
|
||
[HarmonyPriority(Priority.Last)] | ||
[HarmonyPrefix] | ||
public static bool UsePatch(Il2CppSystem.Object __instance) | ||
{ | ||
var @event = new PlayerUseEvent(__instance.Cast<IUsable>()); | ||
MiraEventManager.InvokeEvent(@event); | ||
|
||
return !@event.IsCancelled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters