diff --git a/src/Helpers/RoleHelper.cs b/src/Helpers/RoleHelper.cs index 133baa4..777c4c0 100644 --- a/src/Helpers/RoleHelper.cs +++ b/src/Helpers/RoleHelper.cs @@ -82,6 +82,26 @@ internal static class RoleHelper return string.Empty; } + /// + /// Determines whether a role type is cliant side and can be desynced. + /// + /// The role type to check. + /// True if the role can be desynced to other clients, false otherwise. + internal static bool CanDesyncRole(this RoleTypes role) + { + if (role is RoleTypes.Phantom or RoleTypes.Viper) + { + return false; + } + + if (role is RoleTypes.Noisemaker) + { + return false; + } + + return true; + } + /// /// Dictionary mapping role types to their hexadecimal color codes. /// diff --git a/src/Patches/Gameplay/Managers/RoleManagerPatch.cs b/src/Patches/Gameplay/Managers/RoleManagerPatch.cs index fe0b616..152d83b 100644 --- a/src/Patches/Gameplay/Managers/RoleManagerPatch.cs +++ b/src/Patches/Gameplay/Managers/RoleManagerPatch.cs @@ -16,7 +16,7 @@ internal static class RoleManagerPatch private static readonly Random random = new(); // Check if client is verified Better Among Us user - private static Func SendTo(PlayerControl target) + private static Func FilterTargetClients(PlayerControl target) { return (clientData) => { @@ -164,9 +164,9 @@ internal static class RoleManagerPatch // Desync role to hide special role from non-BAU players if (BetterGameSettings.DesyncRoles.GetBool()) { - if (kvp.Key is not (RoleTypes.Phantom or RoleTypes.Viper)) + if (kvp.Key.CanDesyncRole()) { - AmongUsClient.Instance.SendRpcImmediatelyDesync(pc.NetId, RpcCalls.SetRole, SendOption.None, SendTo(pc), writer => + AmongUsClient.Instance.SendRpcImmediatelyDesync(pc.NetId, RpcCalls.SetRole, SendOption.None, FilterTargetClients(pc), writer => { writer.Write((ushort)RoleTypes.Impostor); writer.Write(false); @@ -204,9 +204,9 @@ internal static class RoleManagerPatch // Desync role to hide special role from non-BAU players if (BetterGameSettings.DesyncRoles.GetBool()) { - if (kvp.Key is not RoleTypes.Noisemaker) + if (kvp.Key.CanDesyncRole()) { - AmongUsClient.Instance.SendRpcImmediatelyDesync(pc.NetId, RpcCalls.SetRole, SendOption.None, SendTo(pc), writer => + AmongUsClient.Instance.SendRpcImmediatelyDesync(pc.NetId, RpcCalls.SetRole, SendOption.None, FilterTargetClients(pc), writer => { writer.Write((ushort)RoleTypes.Crewmate); writer.Write(false); @@ -351,7 +351,7 @@ internal static class RoleManagerPatch // Desync ghost role to hide it from non-BAU players if (BetterGameSettings.DesyncRoles.GetBool()) { - AmongUsClient.Instance.SendRpcImmediatelyDesync(player.NetId, RpcCalls.SetRole, SendOption.None, SendTo(player), writer => + AmongUsClient.Instance.SendRpcImmediatelyDesync(player.NetId, RpcCalls.SetRole, SendOption.None, FilterTargetClients(player), writer => { writer.Write((ushort)player.Data.Role.DefaultGhostRole); writer.Write(false);