mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
using HarmonyLib;
|
|
using InnerNet;
|
|
using MiraAPI.GameModes;
|
|
|
|
namespace MiraAPI.Patches.GameModes;
|
|
|
|
[HarmonyPatch]
|
|
internal static class ConsolePatches
|
|
{
|
|
[HarmonyPrefix, HarmonyPatch(typeof(Console), nameof(Console.CanUse))]
|
|
public static bool CanUsePatch(Console __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
|
{
|
|
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance)
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
if (CustomGameModeManager.ActiveMode != null && !CustomGameModeManager.ActiveMode.CanUseTasks(__instance))
|
|
{
|
|
canUse = couldUse = false;
|
|
return false;
|
|
}
|
|
|
|
var task = __instance.FindTask(pc.Object);
|
|
|
|
if (task && task.GetComponent<SabotageTask>())
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
canUse = false;
|
|
couldUse = false;
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(SystemConsole), nameof(SystemConsole.CanUse))]
|
|
public static bool SystemCanUsePatch(SystemConsole __instance, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
|
{
|
|
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance)
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
if (CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanUseSystemConsole(__instance))
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
canUse = couldUse = false;
|
|
return false;
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(MapConsole), nameof(MapConsole.CanUse))]
|
|
public static bool MapCanUsePatch(MapConsole __instance, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
|
{
|
|
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance)
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
if (CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanUseMapConsole(__instance))
|
|
{
|
|
canUse = couldUse = true;
|
|
return true;
|
|
}
|
|
|
|
canUse = couldUse = false;
|
|
return false;
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(MapConsole), nameof(MapConsole.Use))]
|
|
public static bool MapUsePatch(MapConsole __instance)
|
|
{
|
|
return AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance || CustomGameModeManager.ActiveMode == null ||
|
|
CustomGameModeManager.ActiveMode.CanUseMapConsole(__instance);
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(SystemConsole), nameof(SystemConsole.Use))]
|
|
public static bool SystemUsePatch(SystemConsole __instance)
|
|
{
|
|
return AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance || CustomGameModeManager.ActiveMode == null ||
|
|
CustomGameModeManager.ActiveMode.CanUseSystemConsole(__instance);
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(Console), nameof(Console.Use))]
|
|
public static bool ConsoleUsePatch(Console __instance)
|
|
{
|
|
return AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started || !ShipStatus.Instance || CustomGameModeManager.ActiveMode == null ||
|
|
CustomGameModeManager.ActiveMode.CanUseTasks(__instance);
|
|
}
|
|
}
|