From 3015c6dd6a8499e03bcd38ec6cfac96951e32cca Mon Sep 17 00:00:00 2001 From: Zeo Date: Wed, 26 Feb 2025 18:26:07 +0000 Subject: [PATCH 1/2] Added method to override the intro team screen to be based on custom role --- MiraAPI/Patches/IntroCutscenePatches.cs | 42 +++---------------------- MiraAPI/Roles/ICustomRole.cs | 17 ++++++++++ 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index b98c58e..c3a8ead 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -32,7 +32,8 @@ public static class IntroCutscenePatches [HarmonyPrefix] [HarmonyPatch(nameof(IntroCutscene.BeginImpostor))] - public static void BeginImpostorPatch(IntroCutscene __instance) + [HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))] + public static void BeginImpostorPatch(IntroCutscene __instance, [HarmonyArgument(0)] ref Il2CppSystem.Collections.Generic.List yourTeam) { if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole) { @@ -45,46 +46,11 @@ public static class IntroCutscenePatches __instance.TeamTitle.color = introConfig.IntroTeamColor; __instance.TeamTitle.text = introConfig.IntroTeamTitle; __instance.ImpostorText.text = introConfig.IntroTeamDescription; + + customRole.SetupIntroTeam(__instance, ref yourTeam); } } - [HarmonyPrefix] - [HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))] - public static bool BeginCrewmatePatch(IntroCutscene __instance) - { - if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole) - { - return true; - } - - if (customRole.IntroConfiguration is { } introConfig) - { - __instance.BackgroundBar.material.SetColor(ShaderID.Color, introConfig.IntroTeamColor); - __instance.TeamTitle.color = introConfig.IntroTeamColor; - __instance.TeamTitle.text = introConfig.IntroTeamTitle; - __instance.ImpostorText.text = introConfig.IntroTeamDescription; - } - - if (customRole.Team is not ModdedRoleTeams.Custom) - { - return true; - } - - var barTransform = __instance.BackgroundBar.transform; - var position = barTransform.position; - position.y -= 0.25f; - barTransform.position = position; - - __instance.impostorScale = 1f; - - __instance.ourCrewmate = __instance.CreatePlayer( - 0, - Mathf.CeilToInt(7.5f), - PlayerControl.LocalPlayer.Data, - false); - return false; - } - /* [HarmonyPostfix] [HarmonyPatch(nameof(IntroCutscene.OnDestroy))] diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index a452d1e..f316bf3 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -63,6 +63,23 @@ public interface ICustomRole _ => null, }; + /// + /// Allows the role to specify who is shown on the intro team screen. + /// + /// The intro cutscene instance. + /// The reference to the list of player in the team. + void SetupIntroTeam(IntroCutscene instance, ref Il2CppSystem.Collections.Generic.List yourTeam) + { + if (Team == ModdedRoleTeams.Custom) + { + var team = new Il2CppSystem.Collections.Generic.List(); + + team.Add(PlayerControl.LocalPlayer); + + yourTeam = team; + } + } + /// /// Gets the parent mod of this role. /// From c9ff839f12bb67b4206364c5736d99c42496c3db Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:21:04 -0500 Subject: [PATCH 2/2] improve flexibility of setup team intro --- MiraAPI/Patches/IntroCutscenePatches.cs | 8 +++--- MiraAPI/Roles/ICustomRole.cs | 37 +++++++++++++------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index c3a8ead..415e9d6 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -33,11 +33,11 @@ public static class IntroCutscenePatches [HarmonyPrefix] [HarmonyPatch(nameof(IntroCutscene.BeginImpostor))] [HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))] - public static void BeginImpostorPatch(IntroCutscene __instance, [HarmonyArgument(0)] ref Il2CppSystem.Collections.Generic.List yourTeam) + public static bool BeginImpostorPatch(IntroCutscene __instance, [HarmonyArgument(0)] ref Il2CppSystem.Collections.Generic.List yourTeam) { if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole) { - return; + return true; } if (customRole.IntroConfiguration is { } introConfig) @@ -46,9 +46,9 @@ public static class IntroCutscenePatches __instance.TeamTitle.color = introConfig.IntroTeamColor; __instance.TeamTitle.text = introConfig.IntroTeamTitle; __instance.ImpostorText.text = introConfig.IntroTeamDescription; - - customRole.SetupIntroTeam(__instance, ref yourTeam); } + + return customRole.SetupIntroTeam(__instance, ref yourTeam); } /* diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index f316bf3..0adc386 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -63,23 +63,6 @@ public interface ICustomRole _ => null, }; - /// - /// Allows the role to specify who is shown on the intro team screen. - /// - /// The intro cutscene instance. - /// The reference to the list of player in the team. - void SetupIntroTeam(IntroCutscene instance, ref Il2CppSystem.Collections.Generic.List yourTeam) - { - if (Team == ModdedRoleTeams.Custom) - { - var team = new Il2CppSystem.Collections.Generic.List(); - - team.Add(PlayerControl.LocalPlayer); - - yourTeam = team; - } - } - /// /// Gets the parent mod of this role. /// @@ -175,6 +158,26 @@ public interface ICustomRole return (PlayerControl.LocalPlayer.Data.Role.IsImpostor && player.Data.Role.IsImpostor) || PlayerControl.LocalPlayer.Data.IsDead; } + /// + /// Allows the role to specify who is shown on the intro team screen. + /// + /// The intro cutscene instance. + /// The reference to the list of player in the team. + /// True to use the original team intro code, false to skip. + public virtual bool SetupIntroTeam(IntroCutscene instance, ref Il2CppSystem.Collections.Generic.List yourTeam) + { + if (Team == ModdedRoleTeams.Custom) + { + var team = new Il2CppSystem.Collections.Generic.List(); + + team.Add(PlayerControl.LocalPlayer); + + yourTeam = team; + } + + return true; + } + /// /// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role. ///