diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs index a7d5a5d..72fe6fc 100644 --- a/MiraAPI.Example/Roles/ChameleonRole.cs +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -1,5 +1,4 @@ using MiraAPI.Roles; -using MiraAPI.Utilities.Assets; using TMPro; using UnityEngine; @@ -13,8 +12,12 @@ public class ChameloenRole : CrewmateRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.AcceptedGreen; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; - public int MaxPlayers => 2; + + public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) + { + MaxPlayers = 2, + OptionsScreenshot = ExampleAssets.Banner, + }; public void PlayerControlFixedUpdate(PlayerControl playerControl) { diff --git a/MiraAPI.Example/Roles/FreezerRole.cs b/MiraAPI.Example/Roles/FreezerRole.cs index 55e22c0..628ef6e 100644 --- a/MiraAPI.Example/Roles/FreezerRole.cs +++ b/MiraAPI.Example/Roles/FreezerRole.cs @@ -1,6 +1,4 @@ -using Il2CppInterop.Runtime.Attributes; -using MiraAPI.Roles; -using MiraAPI.Utilities.Assets; +using MiraAPI.Roles; using UnityEngine; namespace MiraAPI.Example.Roles; @@ -13,7 +11,10 @@ public class FreezerRole : ImpostorRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.Blue; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; - [HideFromIl2Cpp] - public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; - public int MaxPlayers => 2; + + public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) + { + OptionsScreenshot = ExampleAssets.Banner, + MaxPlayers = 2, + }; } diff --git a/MiraAPI.Example/Roles/NeutralKillerRole.cs b/MiraAPI.Example/Roles/NeutralKillerRole.cs index 820c334..90dec65 100644 --- a/MiraAPI.Example/Roles/NeutralKillerRole.cs +++ b/MiraAPI.Example/Roles/NeutralKillerRole.cs @@ -11,9 +11,13 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole public string RoleLongDescription => RoleDescription; public Color RoleColor => Color.magenta; public ModdedRoleTeams Team => ModdedRoleTeams.Neutral; - public bool UseVanillaKillButton => true; - public bool CanGetKilled => true; - public bool CanUseVent => true; + + public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this) + { + UseVanillaKillButton = true, + CanGetKilled = true, + CanUseVent = true + }; public override void SpawnTaskHeader(PlayerControl playerControl) { diff --git a/MiraAPI.Example/Roles/TeleporterRole.cs b/MiraAPI.Example/Roles/TeleporterRole.cs index c45f942..c48dacd 100644 --- a/MiraAPI.Example/Roles/TeleporterRole.cs +++ b/MiraAPI.Example/Roles/TeleporterRole.cs @@ -1,6 +1,4 @@ -using Il2CppInterop.Runtime.Attributes; -using MiraAPI.Roles; -using MiraAPI.Utilities.Assets; +using MiraAPI.Roles; using UnityEngine; namespace MiraAPI.Example.Roles; @@ -13,6 +11,9 @@ public class TeleporterRole : CrewmateRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => new Color32(221, 176, 152, 255); public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - [HideFromIl2Cpp] - public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; + + public CustomRoleConfiguration Configuration => new CustomRoleConfiguration() + { + OptionsScreenshot = ExampleAssets.Banner, + }; } diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 9029294..ee26822 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using HarmonyLib; +using HarmonyLib; using MiraAPI.PluginLoading; using MiraAPI.Roles; using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; -using Reactor.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; @@ -216,7 +215,7 @@ public static class LobbyViewPanePatches { var filteredRoles = SelectedMod.CustomRoles.Values .OfType() - .Where(x => !x.HideSettings && x.Team == team).ToList(); + .Where(x => !x.Configuration.HideSettings && x.Team == team).ToList(); if (filteredRoles.Count == 0) { @@ -285,7 +284,7 @@ public static class LobbyViewPanePatches chancePerGame, 61, customRole.RoleColor, - customRole.Icon.LoadAsset(), + customRole.Configuration.Icon.LoadAsset(), true); viewSettingsInfoPanelRoleVariant.titleText.color = @@ -370,7 +369,7 @@ public static class LobbyViewPanePatches role.StringName, maskLayer, role.TeamType == RoleTeamTypes.Crewmate, - customRole.Icon.LoadAsset()); + customRole.Configuration.Icon.LoadAsset()); viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); var num = viewPanel.yPosStart; diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 13eab93..554c18d 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -56,7 +56,7 @@ public static class RoleSettingMenuPatches var crewRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values .OfType() - .Where(role => role is { Team: ModdedRoleTeams.Crewmate, HideSettings: false }) + .Where(role => role is { Team: ModdedRoleTeams.Crewmate, Configuration.HideSettings: false }) .ToList() ?? []; if (crewRoles is { Count: > 0 }) @@ -82,7 +82,7 @@ public static class RoleSettingMenuPatches var impRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values .OfType() - .Where(role => role is { Team: ModdedRoleTeams.Impostor, HideSettings: false }) + .Where(role => role is { Team: ModdedRoleTeams.Impostor, Configuration.HideSettings: false }) .ToList() ?? []; if (impRoles is { Count: > 0 }) @@ -109,7 +109,7 @@ public static class RoleSettingMenuPatches var neutRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values .OfType() - .Where(role => role is { Team: ModdedRoleTeams.Neutral, HideSettings: false }) + .Where(role => role is { Team: ModdedRoleTeams.Neutral, Configuration.HideSettings: false }) .ToList() ?? []; if (neutRoles is { Count: > 0 }) @@ -159,7 +159,7 @@ public static class RoleSettingMenuPatches { var roleSetting = obj.Cast(); var role = roleSetting.Role as ICustomRole; - if (role is null or { HideSettings: true }) + if (role is null or { Configuration.HideSettings: true }) { return; } @@ -228,7 +228,7 @@ public static class RoleSettingMenuPatches renderer.material.SetInt(PlayerMaterial.MaskLayer, 20); } - foreach (var fontMat in newOpt.GetComponentsInChildren(true).Select(x=>x.fontMaterial)) + foreach (var fontMat in newOpt.GetComponentsInChildren(true).Select(x => x.fontMaterial)) { fontMat.SetFloat(ShaderID.StencilComp, 3f); fontMat.SetFloat(ShaderID.Stencil, 20); @@ -258,7 +258,7 @@ public static class RoleSettingMenuPatches role.StringName, new Il2CppReferenceArray(0)); __instance.roleScreenshot.sprite = Sprite.Create( - customRole.OptionsScreenshot.LoadAsset().texture, + customRole.Configuration.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100); diff --git a/MiraAPI/Patches/Roles/HudManagerPatches.cs b/MiraAPI/Patches/Roles/HudManagerPatches.cs index afe857f..25d9f64 100644 --- a/MiraAPI/Patches/Roles/HudManagerPatches.cs +++ b/MiraAPI/Patches/Roles/HudManagerPatches.cs @@ -29,9 +29,9 @@ public static class HudManagerPatches if (role is ICustomRole customRole) { - __instance.KillButton.ToggleVisible(isActive && customRole.UseVanillaKillButton && !flag); - __instance.ImpostorVentButton.ToggleVisible(isActive && customRole.CanUseVent && !flag); - __instance.SabotageButton.gameObject.SetActive(isActive && customRole.CanUseSabotage); + __instance.KillButton.ToggleVisible(isActive && customRole.Configuration.UseVanillaKillButton && !flag); + __instance.ImpostorVentButton.ToggleVisible(isActive && customRole.Configuration.CanUseVent && !flag); + __instance.SabotageButton.gameObject.SetActive(isActive && customRole.Configuration.CanUseSabotage); } if (_roleTab) @@ -56,7 +56,7 @@ public static class HudManagerPatches var role = local?.Data?.Role; - if (role is ICustomRole { RoleHintType: RoleHintType.RoleTab } customRole) + if (role is ICustomRole { Configuration.RoleHintType: RoleHintType.RoleTab } customRole) { customRole.HudUpdate(__instance); diff --git a/MiraAPI/Patches/Roles/KillButtonPatches.cs b/MiraAPI/Patches/Roles/KillButtonPatches.cs index 7b7010a..1516f57 100644 --- a/MiraAPI/Patches/Roles/KillButtonPatches.cs +++ b/MiraAPI/Patches/Roles/KillButtonPatches.cs @@ -36,7 +36,7 @@ public static class KillButtonPatches __instance.currentTarget = target; if (__instance.currentTarget) { - __instance.currentTarget.cosmetics.SetOutline(true, new Nullable(customRole.KillButtonOutlineColor)); + __instance.currentTarget.cosmetics.SetOutline(true, new Nullable(customRole.Configuration.KillButtonOutlineColor)); __instance.SetEnabled(); return false; } diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index 4f75a16..357b2eb 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -37,12 +37,12 @@ public static class RoleManagerPatches return true; } - if (role.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost) + if (role.Configuration.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost) { return true; } - plr.RpcSetRole(role.GhostRole); + plr.RpcSetRole(role.Configuration.GhostRole); return false; } } diff --git a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs index ed4f7b7..bfa9e9f 100644 --- a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs +++ b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs @@ -19,7 +19,7 @@ public static class RoleOptionsCollectionPatch return true; } - if (customRole.HideSettings) + if (customRole.Configuration.HideSettings) { __result = 0; return false; @@ -42,7 +42,7 @@ public static class RoleOptionsCollectionPatch return true; } - if (customRole.HideSettings) + if (customRole.Configuration.HideSettings) { __result = 0; return false; diff --git a/MiraAPI/Patches/Roles/SabotageButtonPatch.cs b/MiraAPI/Patches/Roles/SabotageButtonPatch.cs index b39ce3a..6706235 100644 --- a/MiraAPI/Patches/Roles/SabotageButtonPatch.cs +++ b/MiraAPI/Patches/Roles/SabotageButtonPatch.cs @@ -20,7 +20,7 @@ public class SabotageButtonPatch return true; } - if (!customRole.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled()) + if (!customRole.Configuration.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled()) { return false; } @@ -52,7 +52,7 @@ public class SabotageButtonPatch if (player.inVent || !GameManager.Instance.SabotagesEnabled() || player.petting) { - __instance.ToggleVisible(customRole.CanUseSabotage && GameManager.Instance.SabotagesEnabled()); + __instance.ToggleVisible(customRole.Configuration.CanUseSabotage && GameManager.Instance.SabotagesEnabled()); __instance.SetDisabled(); return false; } diff --git a/MiraAPI/Patches/VentPatches.cs b/MiraAPI/Patches/VentPatches.cs index eb1496e..77f1c1a 100644 --- a/MiraAPI/Patches/VentPatches.cs +++ b/MiraAPI/Patches/VentPatches.cs @@ -21,7 +21,7 @@ public static class VentPatches var @object = pc.Object; var role = @object.Data.Role; - var canVent = role is ICustomRole customRole ? customRole.CanUseVent : role.CanVent; + var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent : role.CanVent; var modifiers = @object.GetModifierComponent()?.ActiveModifiers; if (modifiers is null || modifiers.Count <= 0) diff --git a/MiraAPI/Roles/CustomRoleConfiguration.cs b/MiraAPI/Roles/CustomRoleConfiguration.cs new file mode 100644 index 0000000..c7775e6 --- /dev/null +++ b/MiraAPI/Roles/CustomRoleConfiguration.cs @@ -0,0 +1,107 @@ +using AmongUs.GameOptions; +using MiraAPI.Utilities.Assets; +using UnityEngine; + +namespace MiraAPI.Roles; + +/// +/// Used to configure the specific settings of a role. +/// +public struct CustomRoleConfiguration +{ + /// + /// Initializes a new instance of the struct. + /// + /// The role in which you are configuring. + public CustomRoleConfiguration(ICustomRole role) + { + MaxPlayers = 15; + OptionsScreenshot = Icon = MiraAssets.Empty; + AffectedByLightOnAirship = role.Team == ModdedRoleTeams.Crewmate; + KillButtonOutlineColor = role.Team switch + { + ModdedRoleTeams.Impostor => Palette.ImpostorRed, + ModdedRoleTeams.Crewmate => Palette.CrewmateBlue, + _ => role.RoleColor, + }; + RoleHintType = RoleHintType.RoleTab; + GhostRole = role.Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost; + CanGetKilled = role.Team == ModdedRoleTeams.Crewmate; + UseVanillaKillButton = role.Team == ModdedRoleTeams.Impostor; + CanUseVent = role.Team == ModdedRoleTeams.Impostor; + CanUseSabotage = role.Team == ModdedRoleTeams.Impostor; + TasksCountForProgress = role.Team == ModdedRoleTeams.Crewmate; + IsGhostRole = false; + HideSettings = IsGhostRole; + } + + /// + /// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. + /// + public int MaxPlayers; + + /// + /// Gets the Sprite used for the Role Options menu screenshot. + /// + public LoadableAsset OptionsScreenshot; + + /// + /// Gets the Sprite used for the Role Icon. + /// + public LoadableAsset Icon; + + /// + /// Gets a value indicating whether the role is affected by light affectors on Airship. + /// + public bool AffectedByLightOnAirship; + + /// + /// Gets a value indicating whether the role can be killed by vanilla murder system. + /// + public bool CanGetKilled; + + /// + /// Gets a value indicating whether the role should use the vanilla kill button. + /// + public bool UseVanillaKillButton; + + /// + /// Gets a value indicating whether the role can use vents. + /// + public bool CanUseVent; + + /// + /// Gets a value indicating whether the role can use the sabotage button. + /// + public bool CanUseSabotage; + + /// + /// Gets a value indicating whether the role's tasks count towards task progress. + /// + public bool TasksCountForProgress; + + /// + /// Gets a value indicating whether the role is a Ghost. + /// + public bool IsGhostRole; + + /// + /// Gets a value indicating whether the role should show up in the Role Options menu. + /// + public bool HideSettings; + + /// + /// Gets the outline color for the KillButton if is true. + /// + public Color KillButtonOutlineColor; + + /// + /// Gets the role hint style. See enum for all options. + /// + public RoleHintType RoleHintType; + + /// + /// Gets the Ghost role that is applied when the player is killed. + /// + public RoleTypes GhostRole; +} \ No newline at end of file diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 1588d91..92a5c8b 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -36,7 +36,7 @@ public static class CustomRoleManager { RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray(); - foreach (var role in CustomRoles.Values.Where(x=>x.IsDead)) + foreach (var role in CustomRoles.Values.Where(x => x.IsDead)) { RoleManager.GhostRoles.Add(role.Role); } @@ -84,21 +84,21 @@ public static class CustomRoleManager roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName); roleBehaviour.BlurbName = CustomStringName.CreateAndRegister(customRole.RoleDescription); roleBehaviour.BlurbNameLong = CustomStringName.CreateAndRegister(customRole.RoleLongDescription); - roleBehaviour.AffectedByLightAffectors = customRole.AffectedByLightOnAirship; - roleBehaviour.CanBeKilled = customRole.CanGetKilled; - roleBehaviour.CanUseKillButton = customRole.UseVanillaKillButton; - roleBehaviour.TasksCountTowardProgress = customRole.TasksCountForProgress; - roleBehaviour.CanVent = customRole.CanUseVent; - roleBehaviour.DefaultGhostRole = customRole.GhostRole; - roleBehaviour.MaxCount = customRole.MaxPlayers; - roleBehaviour.RoleScreenshot = customRole.OptionsScreenshot.LoadAsset(); + roleBehaviour.AffectedByLightAffectors = customRole.Configuration.AffectedByLightOnAirship; + roleBehaviour.CanBeKilled = customRole.Configuration.CanGetKilled; + roleBehaviour.CanUseKillButton = customRole.Configuration.UseVanillaKillButton; + roleBehaviour.TasksCountTowardProgress = customRole.Configuration.TasksCountForProgress; + roleBehaviour.CanVent = customRole.Configuration.CanUseVent; + roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole; + roleBehaviour.MaxCount = customRole.Configuration.MaxPlayers; + roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot.LoadAsset(); - if (customRole.IsGhostRole) + if (customRole.Configuration.IsGhostRole) { RoleManager.GhostRoles.Add(roleBehaviour.Role); } - var useTaskHint = customRole.RoleHintType is RoleHintType.TaskHint; + var useTaskHint = customRole.Configuration.RoleHintType is RoleHintType.TaskHint; var overridesTaskText = customRole.GetType().GetMethod("SpawnTaskHeader")?.DeclaringType == customRole.GetType(); if (useTaskHint && !overridesTaskText) @@ -108,7 +108,7 @@ public static class CustomRoleManager CustomRoles.Add(roleId, roleBehaviour); - if (customRole.HideSettings) + if (customRole.Configuration.HideSettings) { return roleBehaviour; } @@ -186,7 +186,7 @@ public static class CustomRoleManager internal static void SyncAllRoleSettings(int targetId = -1) { var data = CustomRoles.Values - .Where(x => x is ICustomRole { HideSettings: false }) + .Where(x => x is ICustomRole { Configuration.HideSettings: false }) .Select(x => ((ICustomRole)x).GetNetData()) .ChunkNetData(1000); @@ -216,7 +216,7 @@ public static class CustomRoleManager } var customRole = role as ICustomRole; - if (customRole is null or { HideSettings: true }) + if (customRole is null or { Configuration.HideSettings: true }) { continue; } diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 9fc2b61..53b7798 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -1,11 +1,8 @@ -using System.Text; -using AmongUs.GameOptions; -using BepInEx.Configuration; -using Il2CppInterop.Runtime.Attributes; +using BepInEx.Configuration; using MiraAPI.Modifiers; using MiraAPI.PluginLoading; using MiraAPI.Utilities; -using MiraAPI.Utilities.Assets; +using System.Text; using UnityEngine; namespace MiraAPI.Roles; @@ -40,82 +37,7 @@ public interface ICustomRole /// ModdedRoleTeams Team { get; } - /// - /// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. - /// - int MaxPlayers => 15; - - /// - /// Gets the Sprite used for the Role Options menu screenshot. - /// - [HideFromIl2Cpp] - LoadableAsset OptionsScreenshot => MiraAssets.Empty; - - /// - /// Gets the Sprite used for the Role Icon. - /// - [HideFromIl2Cpp] - LoadableAsset Icon => MiraAssets.Empty; - - /// - /// Gets a value indicating whether the role is affected by light affectors on Airship. - /// - bool AffectedByLightOnAirship => Team == ModdedRoleTeams.Crewmate; - - /// - /// Gets a value indicating whether the role can be killed by vanilla murder system. - /// - bool CanGetKilled => Team == ModdedRoleTeams.Crewmate; - - /// - /// Gets a value indicating whether the role should use the vanilla kill button. - /// - bool UseVanillaKillButton => Team == ModdedRoleTeams.Impostor; - - /// - /// Gets a value indicating whether the role can use vents. - /// - bool CanUseVent => Team == ModdedRoleTeams.Impostor; - - /// - /// Gets a value indicating whether the role can use the sabotage button. - /// - bool CanUseSabotage => Team == ModdedRoleTeams.Impostor; - - /// - /// Gets a value indicating whether the role's tasks count towards task progress. - /// - bool TasksCountForProgress => Team == ModdedRoleTeams.Crewmate; - - /// - /// Gets a value indicating whether the role is a Ghost. - /// - bool IsGhostRole => false; - - /// - /// Gets a value indicating whether the role should show up in the Role Options menu. - /// - bool HideSettings => IsGhostRole; - - /// - /// Gets the outline color for the KillButton if is true. - /// - Color KillButtonOutlineColor => Team switch - { - ModdedRoleTeams.Impostor => Palette.ImpostorRed, - ModdedRoleTeams.Crewmate => Palette.CrewmateBlue, - _ => RoleColor, - }; - - /// - /// Gets the role hint style. See enum for all options. - /// - RoleHintType RoleHintType => RoleHintType.RoleTab; - - /// - /// Gets the Ghost role that is applied when the player is killed. - /// - RoleTypes GhostRole => Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost; + CustomRoleConfiguration Configuration { get; } /// /// Gets the BepInEx ConfigDefinition for the amount of players that can have this role.