diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs index 52550a3..6f485d7 100644 --- a/MiraAPI.Example/Roles/ChameleonRole.cs +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -1,5 +1,6 @@ using AmongUs.GameOptions; using MiraAPI.Roles; +using Reactor.Utilities; using TMPro; using UnityEngine; @@ -19,6 +20,12 @@ public class ChameloenRole : CrewmateRole, ICustomRole IntroSound = CustomRoleUtils.GetIntroSound(RoleTypes.Shapeshifter), }; + public override void Initialize(PlayerControl player) + { + Player = player; + Logger.Error("Initializing ChamelonRole for player: " + player.PlayerId); + } + public void PlayerControlFixedUpdate(PlayerControl playerControl) { if (playerControl.MyPhysics.Velocity.magnitude > 0) diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index 63ed61a..57512e3 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -12,19 +12,19 @@ namespace MiraAPI.Patches.Roles; [HarmonyPatch(typeof(RoleManager))] public static class RoleManagerPatches { - [HarmonyPostfix] + [HarmonyPrefix] [HarmonyPatch(nameof(RoleManager.SetRole))] - public static void SetRolePatch(RoleManager __instance, PlayerControl targetPlayer, RoleTypes roleType) + public static bool SetRolePatch(RoleManager __instance, PlayerControl targetPlayer, RoleTypes roleType) { if (!targetPlayer) { - return; + return false; } var data = targetPlayer.Data; if (data == null) { Debug.LogError("It shouldn't be possible, but " + targetPlayer.name + " still doesn't have PlayerData during role selection."); - return; + return false; } if (data.Role) { @@ -47,7 +47,7 @@ public static class RoleManagerPatches { case true when !targetPlayer.Data.IsDead: targetPlayer.Die(DeathReason.Kill, false); - return; + return false; case false when targetPlayer.Data.IsDead: targetPlayer.Revive(); break; @@ -55,6 +55,8 @@ public static class RoleManagerPatches var @event = new SetRoleEvent(targetPlayer, roleType); MiraEventManager.InvokeEvent(@event); + + return false; } [HarmonyPostfix]