From 76cb2a6a59cf01ae42508fc92aad1828c2c300a4 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:52:03 -0400 Subject: [PATCH] adjustment to vent patches --- MiraAPI/Patches/Roles/VentOutlinePatch.cs | 27 -------------- MiraAPI/Patches/Roles/VentPatches.cs | 45 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 MiraAPI/Patches/Roles/VentOutlinePatch.cs create mode 100644 MiraAPI/Patches/Roles/VentPatches.cs diff --git a/MiraAPI/Patches/Roles/VentOutlinePatch.cs b/MiraAPI/Patches/Roles/VentOutlinePatch.cs deleted file mode 100644 index 5e50e96..0000000 --- a/MiraAPI/Patches/Roles/VentOutlinePatch.cs +++ /dev/null @@ -1,27 +0,0 @@ -using HarmonyLib; -using MiraAPI.Roles; -using MiraAPI.Utilities; -using UnityEngine; - -namespace MiraAPI.Patches.Roles; - -/// -/// Set vent outline color based on the player's role. -/// -[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))] -public static class VentOutlinePatch -{ - public static void Postfix(Vent __instance, bool on, bool mainTarget) - { - if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole) - { - return; - } - - var color = customRole.RoleColor; - - __instance.myRend.material.SetFloat(ShaderID.Outline, on ? 1 : 0); - __instance.myRend.material.SetColor(ShaderID.OutlineColor, color); - __instance.myRend.material.SetColor(ShaderID.AddColor, mainTarget ? color : Color.clear); - } -} diff --git a/MiraAPI/Patches/Roles/VentPatches.cs b/MiraAPI/Patches/Roles/VentPatches.cs new file mode 100644 index 0000000..5ae7035 --- /dev/null +++ b/MiraAPI/Patches/Roles/VentPatches.cs @@ -0,0 +1,45 @@ +using HarmonyLib; +using MiraAPI.Roles; +using MiraAPI.Utilities; +using UnityEngine; + +namespace MiraAPI.Patches.Roles; + +/// +/// Vent patches for Roles. +/// +[HarmonyPatch(typeof(Vent))] +public static class VentPatches +{ + /// + /// Set CanVent of player to customRole CanUseVent because the original one isnt a property :(. + /// + [HarmonyPrefix] + [HarmonyPatch(nameof(Vent.CanUse))] + public static void CanUsePrefix(Vent __instance, NetworkedPlayerInfo pc) + { + if (pc.Role is ICustomRole customRole) + { + pc.Role.CanVent = customRole.CanUseVent; + } + } + + /// + /// Set outline to player's custom role color. + /// + [HarmonyPostfix] + [HarmonyPatch(nameof(Vent.SetOutline))] + public static void SetOutlinePostfix(Vent __instance, bool on, bool mainTarget) + { + if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole) + { + return; + } + + var color = customRole.RoleColor; + + __instance.myRend.material.SetFloat(ShaderID.Outline, on ? 1 : 0); + __instance.myRend.material.SetColor(ShaderID.OutlineColor, color); + __instance.myRend.material.SetColor(ShaderID.AddColor, mainTarget ? color : Color.clear); + } +}