|
| 1 | +using HarmonyLib; |
| 2 | +using UnityEngine; |
| 3 | + |
| 4 | +namespace MalumMenu; |
| 5 | + |
| 6 | +[HarmonyPatch(typeof(Vent), nameof(Vent.CanUse))] |
| 7 | +public static class Vent_CanUse |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Postfix patch of Vent.CanUse to allow venting. |
| 11 | + /// </summary> |
| 12 | + /// <param name="__instance">The <c>Vent</c> instance.</param> |
| 13 | + /// <param name="pc">The <c>PlayerControl</c> of the player trying to use the vent.</param> |
| 14 | + /// <param name="canUse">Whether the player can currently use the vent, accounting for distance and physics obstacles.</param> |
| 15 | + /// <param name="couldUse">Whether the player's role and game state theoretically allow vent usage.</param> |
| 16 | + /// <param name="__result">The distance from the player to the vent, or -1 if the vent cannot be used.</param> |
| 17 | + public static void Postfix(Vent __instance, NetworkedPlayerInfo pc, ref bool canUse, ref bool couldUse, ref float __result) |
| 18 | + { |
| 19 | + if (!PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data) return; |
| 20 | + if (PlayerControl.LocalPlayer.Data.Role.CanVent || PlayerControl.LocalPlayer.Data.IsDead) return; |
| 21 | + if (!CheatToggles.useVents) return; |
| 22 | + var @object = pc.Object; |
| 23 | + |
| 24 | + var center = @object.Collider.bounds.center; |
| 25 | + var position = __instance.transform.position; |
| 26 | + var num = Vector2.Distance(center, position); |
| 27 | + |
| 28 | + // Allow usage of vents unless the vent is too far or there are objects blocking the player's path |
| 29 | + canUse = num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(@object.Collider, center, position, Constants.ShipOnlyMask, false); |
| 30 | + couldUse = true; |
| 31 | + __result = num; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +[HarmonyPatch(typeof(Vent), nameof(Vent.EnterVent))] |
| 36 | +public static class Vent_EnterVent |
| 37 | +{ |
| 38 | + /// <summary> |
| 39 | + /// Postfix patch of Vent.EnterVent to log when a player enters a vent, along with the room they entered it in. |
| 40 | + /// </summary> |
| 41 | + /// <param name="__instance">The <c>Vent</c> instance.</param> |
| 42 | + /// <param name="pc">The <c>PlayerControl</c> of the player entering the vent.</param> |
| 43 | + public static void Postfix(Vent __instance, PlayerControl pc) |
| 44 | + { |
| 45 | + if (!CheatToggles.logVents || !Utils.isShip) return; |
| 46 | + |
| 47 | + var (realPlayerName, displayPlayerName, isDisguised) = Utils.GetPlayerIdentity(pc); |
| 48 | + var room = Utils.GetRoomFromPosition(__instance.transform.position - (Vector3) pc.Collider.offset); |
| 49 | + var roomName = room != null ? room.RoomId.ToString() : "an unknown location"; |
| 50 | + ConsoleUI.Log(isDisguised |
| 51 | + ? $"{realPlayerName} (as {displayPlayerName}) entered a vent in {roomName}" |
| 52 | + : $"{realPlayerName} entered a vent in {roomName}"); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +[HarmonyPatch(typeof(Vent), nameof(Vent.ExitVent))] |
| 57 | +public static class Vent_ExitVent |
| 58 | +{ |
| 59 | + /// <summary> |
| 60 | + /// Postfix patch of Vent.ExitVent to log when a player exits a vent, along with the room they exited it in. |
| 61 | + /// </summary> |
| 62 | + /// <param name="__instance">The <c>Vent</c> instance.</param> |
| 63 | + /// <param name="pc">The <c>PlayerControl</c> of the player exiting the vent.</param> |
| 64 | + public static void Postfix(Vent __instance, PlayerControl pc) |
| 65 | + { |
| 66 | + if (!CheatToggles.logVents || !Utils.isShip) return; |
| 67 | + |
| 68 | + var (realPlayerName, displayPlayerName, isDisguised) = Utils.GetPlayerIdentity(pc); |
| 69 | + var room = Utils.GetRoomFromPosition(__instance.transform.position - (Vector3) pc.Collider.offset); |
| 70 | + var roomName = room != null ? room.RoomId.ToString() : "an unknown location"; |
| 71 | + ConsoleUI.Log(isDisguised |
| 72 | + ? $"{realPlayerName} (as {displayPlayerName}) exited a vent in {roomName}" |
| 73 | + : $"{realPlayerName} exited a vent in {roomName}"); |
| 74 | + } |
| 75 | +} |
0 commit comments