From e681a4ff742821c4ba6bc0706e3515fda0afa08d Mon Sep 17 00:00:00 2001 From: "Imp11(dabao40)" Date: Sat, 5 Oct 2024 19:59:48 +0800 Subject: [PATCH] Update v1.2.9 --- TheOtherRoles/CustomGameModes/FreePlayGM.cs | 9 +++++---- TheOtherRoles/Modules/CustomOverlay.cs | 2 +- TheOtherRoles/Patches/MeetingPatch.cs | 4 +++- TheOtherRoles/RPC.cs | 20 +++++++++++++++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/TheOtherRoles/CustomGameModes/FreePlayGM.cs b/TheOtherRoles/CustomGameModes/FreePlayGM.cs index 8536f46..df6e09c 100644 --- a/TheOtherRoles/CustomGameModes/FreePlayGM.cs +++ b/TheOtherRoles/CustomGameModes/FreePlayGM.cs @@ -56,12 +56,13 @@ void SetWidget(int tab) if (tab == 0) { - inner = gui.Arrange(GUIAlignment.Center, RoleInfo.allRoleInfos.Where(x => x != RoleInfo.bomberB && x != RoleInfo.bomberA && x != RoleInfo.jackal - && x != RoleInfo.sidekick && x != RoleInfo.mimicA && x != RoleInfo.mimicK && x != RoleInfo.arsonist && x != RoleInfo.bountyHunter && !x.isModifier).Select(r => gui.RawButton(GUIAlignment.Center, roleMaskedTittleAttr, Helpers.cs(r.color, r.name), () => + inner = gui.Arrange(GUIAlignment.Center, RoleInfo.allRoleInfos.Where(x => x != RoleInfo.bomberB && x != RoleInfo.bomberA && x != RoleInfo.mimicA && x != RoleInfo.mimicK && x != RoleInfo.arsonist && x != RoleInfo.bountyHunter && !x.isModifier).Select(r => gui.RawButton(GUIAlignment.Center, roleMaskedTittleAttr, Helpers.cs(r.color, r.name), () => { bool isImpostorFormer = PlayerControl.LocalPlayer.Data.Role.IsImpostor; var formerRole = RoleInfo.getRoleInfoForPlayer(PlayerControl.LocalPlayer, false).FirstOrDefault(); if (formerRole == r) return; // Do nothing if the same role was given + if (formerRole.roleId == RoleId.Jackal) Jackal.clearAndReload(); + else if (formerRole.roleId == RoleId.Sidekick) Sidekick.clearAndReload(); RPCProcedure.erasePlayerRoles(PlayerControl.LocalPlayer.PlayerId); if (r.isImpostor() && !isImpostorFormer) PlayerControl.LocalPlayer.FastSetRole(RoleTypes.Impostor); else if (!r.isImpostor() && isImpostorFormer) PlayerControl.LocalPlayer.FastSetRole(RoleTypes.Crewmate); @@ -81,7 +82,7 @@ void SetWidget(int tab) cpt.addTaskToPlayer(CachedPlayer.LocalPlayer.PlayerId); } else if (r.roleId == RoleId.JekyllAndHyde) { CachedPlayer.LocalPlayer.PlayerControl.generateAndAssignTasks(JekyllAndHyde.numCommonTasks, JekyllAndHyde.numShortTasks, JekyllAndHyde.numLongTasks); - } else if (formerRole.roleId == RoleId.Fox || formerRole.roleId == RoleId.JekyllAndHyde || formerRole.roleId == RoleId.TaskMaster) { + } else if (formerRole.roleId is RoleId.Fox or RoleId.JekyllAndHyde or RoleId.TaskMaster) { var options = GameOptionsManager.Instance.currentNormalGameOptions; PlayerControl.LocalPlayer.generateAndAssignTasks(options.NumCommonTasks, options.NumShortTasks, options.NumLongTasks); } @@ -119,7 +120,7 @@ private static void FastSetRole(this PlayerControl targetPlayer, RoleTypes roleT roleBehaviour.Initialize(targetPlayer); targetPlayer.Data.Role = roleBehaviour; targetPlayer.Data.RoleType = roleType; - if (roleType != RoleTypes.ImpostorGhost && roleType != RoleTypes.CrewmateGhost) + if (roleType is not RoleTypes.ImpostorGhost and not RoleTypes.CrewmateGhost) targetPlayer.Data.RoleWhenAlive = new Il2CppSystem.Nullable(roleType); roleBehaviour.AdjustTasks(targetPlayer); } diff --git a/TheOtherRoles/Modules/CustomOverlay.cs b/TheOtherRoles/Modules/CustomOverlay.cs index 33fdd4a..283aaf3 100644 --- a/TheOtherRoles/Modules/CustomOverlay.cs +++ b/TheOtherRoles/Modules/CustomOverlay.cs @@ -134,7 +134,7 @@ public static void showInfoOverlay() } var rows = rolesText.Count(c => c == '\n'); - var maxY = Mathf.Max(1.15f, (2 * rows - 33) * 0.06f); + var maxY = Mathf.Max(1.15f, (2 * rows - 24) * 0.04f + 1.16f); scroller.enabled = true; scroller.ContentYBounds = new FloatRange(1.15f, maxY); scroller.ScrollToTop(); diff --git a/TheOtherRoles/Patches/MeetingPatch.cs b/TheOtherRoles/Patches/MeetingPatch.cs index 7913a96..f9a6418 100644 --- a/TheOtherRoles/Patches/MeetingPatch.cs +++ b/TheOtherRoles/Patches/MeetingPatch.cs @@ -593,14 +593,16 @@ static void guesserOnClick(int buttonTarget, MeetingHud __instance) { else __instance.playerStates.ToList().ForEach(x => { if (x.transform.FindChild("ShootButton") != null) UnityEngine.Object.Destroy(x.transform.FindChild("ShootButton").gameObject); }); + bool isSpecialRole = roleInfo == RoleInfo.niceshifter || roleInfo == RoleInfo.niceSwapper; // Shoot player and send chat info if activated MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.GuesserShoot, Hazel.SendOption.Reliable, -1); writer.Write(CachedPlayer.LocalPlayer.PlayerId); writer.Write(dyingTarget.PlayerId); writer.Write(focusedTarget.PlayerId); writer.Write((byte)roleInfo.roleId); + writer.Write(isSpecialRole); AmongUsClient.Instance.FinishRpcImmediately(writer); - RPCProcedure.guesserShoot(CachedPlayer.LocalPlayer.PlayerId, dyingTarget.PlayerId, focusedTarget.PlayerId, (byte)roleInfo.roleId); + RPCProcedure.guesserShoot(CachedPlayer.LocalPlayer.PlayerId, dyingTarget.PlayerId, focusedTarget.PlayerId, (byte)roleInfo.roleId, isSpecialRole); } })); diff --git a/TheOtherRoles/RPC.cs b/TheOtherRoles/RPC.cs index 48e0cdd..9766796 100644 --- a/TheOtherRoles/RPC.cs +++ b/TheOtherRoles/RPC.cs @@ -1486,6 +1486,7 @@ public static void jackalCreatesSidekick(byte targetId) { } public static void sidekickPromotes() { + if (FreePlayGM.isFreePlayGM) return; Jackal.removeCurrentJackal(); Jackal.jackal = Sidekick.sidekick; Jackal.canCreateSidekick = Jackal.jackalPromotedFromSidekickCanCreateSidekick; @@ -2467,7 +2468,15 @@ public static void lawyerWin() Lawyer.triggerLawyerWin = true; } - public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedTargetId, byte guessedRoleId) { + /// + /// Shoots the dying target during the meeting + /// + /// PlayerId of the Guesser + /// PlayerId of the dying target (i.e. wrong guess = Guesser, right guess = target) + /// The PlayerId the dying target has guessed + /// The RoleId the Guesser has guessed (2 same RoleIds for Swapper and Shifter) + /// Whether or not this is a Nice Shifter or a Nice Swapper etc. + public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedTargetId, byte guessedRoleId, bool isSpecialRole) { GameStatistics.Event.GameStatistics.RecordEvent(new(GameStatistics.EventVariation.Kill, killerId, 1 << dyingTargetId) { RelatedTag = killerId == dyingTargetId ? EventDetail.MisGuess : EventDetail.Guessed}); PlayerControl killer = Helpers.playerById(killerId); @@ -2644,7 +2653,11 @@ public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedT { PlayerControl guessedTarget = Helpers.playerById(guessedTargetId); PlayerControl sender = CachedPlayer.LocalPlayer.PlayerControl; - RoleInfo guessedRoleInfo = RoleInfo.allRoleInfos.FirstOrDefault(x => (byte)x.roleId == guessedRoleId); + RoleInfo guessedRoleInfo = RoleInfo.allRoleInfos.FirstOrDefault(x => (byte)x.roleId == guessedRoleId); + if (isSpecialRole) { + if ((RoleId)guessedRoleId == RoleId.Swapper) guessedRoleInfo = RoleInfo.niceSwapper; + else if ((RoleId)guessedRoleId == RoleId.Shifter) guessedRoleInfo = RoleInfo.niceshifter; + } string msg = ""; if (CachedPlayer.LocalPlayer.Data.IsDead && guessedTarget != null && guesser != null) { @@ -3385,7 +3398,8 @@ static void Postfix([HarmonyArgument(0)]byte callId, [HarmonyArgument(1)]Message byte dyingTarget = reader.ReadByte(); byte guessedTarget = reader.ReadByte(); byte guessedRoleId = reader.ReadByte(); - RPCProcedure.guesserShoot(killerId, dyingTarget, guessedTarget, guessedRoleId); + bool isSpecialRole = reader.ReadBoolean(); + RPCProcedure.guesserShoot(killerId, dyingTarget, guessedTarget, guessedRoleId, isSpecialRole); break; case (byte)CustomRPC.LawyerSetTarget: RPCProcedure.lawyerSetTarget(reader.ReadByte());