From 1f4a7b586cd9e5866cf7a7fc58f947caaa4fb9ed Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 12 Dec 2024 15:30:02 +0100 Subject: [PATCH] fix --- EHR.sln.DotSettings | 4 +++ Modules/CustomTeamManager.cs | 39 +++++++------------------ Modules/OptionHolder.cs | 6 +++- Patches/CredentialsPatch.cs | 56 +++++++++++++++++------------------- Patches/IntroPatch.cs | 36 ++++++++++++++--------- Resources/Lang/en_US.json | 1 + 6 files changed, 69 insertions(+), 73 deletions(-) diff --git a/EHR.sln.DotSettings b/EHR.sln.DotSettings index 182830a5a..f8bd80f08 100644 --- a/EHR.sln.DotSettings +++ b/EHR.sln.DotSettings @@ -1,9 +1,12 @@  SOLUTION + False 1 1 1 TOGETHER_SAME_LINE + False True NEVER AFK @@ -14,6 +17,7 @@ CK CNO CRLF + CTA CTF DLL DY diff --git a/Modules/CustomTeamManager.cs b/Modules/CustomTeamManager.cs index ca18ffad6..26a0b3522 100644 --- a/Modules/CustomTeamManager.cs +++ b/Modules/CustomTeamManager.cs @@ -22,10 +22,7 @@ internal static class CustomTeamManager CustomTeams = File.ReadAllLines("./EHR_DATA/CTA_Data.txt").Select(x => new CustomTeam(x)).ToHashSet(); RefreshCustomOptions(); } - catch (Exception e) - { - Utils.ThrowException(e); - } + catch (Exception e) { Utils.ThrowException(e); } } private static void RefreshCustomOptions() @@ -85,7 +82,6 @@ internal static class CustomTeamManager foreach (byte target in players) { if (player == target) continue; - TargetArrow.Add(player, target); } } @@ -95,7 +91,6 @@ internal static class CustomTeamManager public static string GetSuffix(PlayerControl seer) { if (seer == null || EnabledCustomTeams.Count == 0 || Main.HasJustStarted || !IsSettingEnabledForPlayerTeam(seer.PlayerId, CTAOption.Arrows)) return string.Empty; - return CustomTeamPlayerIds[GetCustomTeam(seer.PlayerId)].Aggregate(string.Empty, (s, id) => s + Utils.ColorString(Main.PlayerColors.GetValueOrDefault(id, Color.white), TargetArrow.GetArrows(seer, id))); } @@ -117,10 +112,10 @@ internal static class CustomTeamManager CustomTeam team = aliveTeamPlayers.Keys.First(); if (aliveTeamPlayers.Count == 1 && Main.AllAlivePlayerControls.All(x => - { - CustomTeam customTeam = GetCustomTeam(x.PlayerId); - return customTeam != null && customTeam.Equals(team); - })) + { + CustomTeam customTeam = GetCustomTeam(x.PlayerId); + return customTeam != null && customTeam.Equals(team); + })) { WinnerTeam = team; CustomWinnerHolder.ResetAndSetWinner(CustomWinner.CustomTeam); @@ -128,10 +123,7 @@ internal static class CustomTeamManager return true; } } - catch - { - return false; - } + catch { return false; } return false; } @@ -190,14 +182,8 @@ internal static class CustomTeamManager TeamMembers = parts[4].Split(',').Select(x => Enum.Parse(x, true)).ToList(); } - catch (Exception e) - { - Utils.ThrowException(e); - } - finally - { - CustomTeams.Add(this); - } + catch (Exception e) { Utils.ThrowException(e); } + finally { CustomTeams.Add(this); } } public List TeamMembers { get; } = []; @@ -218,14 +204,9 @@ internal static class CustomTeamManager internal class CustomTeamOptionGroup(CustomTeam team, BooleanOptionItem enabled, BooleanOptionItem knowRoles, BooleanOptionItem winWithOriginalTeam, BooleanOptionItem killEachOther, BooleanOptionItem guessEachOther, BooleanOptionItem arrows) { public readonly List AllOptions = [enabled, knowRoles, winWithOriginalTeam, killEachOther, guessEachOther, arrows]; - public CustomTeam Team { get; set; } = team; + public CustomTeam Team { get; } = team; - public BooleanOptionItem Enabled { get; set; } = enabled; - public BooleanOptionItem KnowRoles { get; set; } = knowRoles; - public BooleanOptionItem WinWithOriginalTeam { get; set; } = winWithOriginalTeam; - public BooleanOptionItem KillEachOther { get; set; } = killEachOther; - public BooleanOptionItem GuessEachOther { get; set; } = guessEachOther; - public BooleanOptionItem Arrows { get; set; } = arrows; + public BooleanOptionItem Enabled { get; } = enabled; } } diff --git a/Modules/OptionHolder.cs b/Modules/OptionHolder.cs index bdbdcc8fa..694227752 100644 --- a/Modules/OptionHolder.cs +++ b/Modules/OptionHolder.cs @@ -180,6 +180,7 @@ public static class Options public static OptionItem DisableSabotage; public static OptionItem DisableWhisperCommand; + public static OptionItem DisableSpectateCommand; public static OptionItem DisableReactorOnSkeldAndMira; public static OptionItem DisableReactorOnPolus; @@ -1822,6 +1823,9 @@ public static class Options DisableWhisperCommand = new BooleanOptionItem(22811, "DisableWhisperCommand", false, TabGroup.GameSettings) .SetColor(new Color32(255, 153, 153, byte.MaxValue)); + DisableSpectateCommand = new BooleanOptionItem(22812, "DisableSpectateCommand", false, TabGroup.GameSettings) + .SetColor(new Color32(255, 153, 153, byte.MaxValue)); + LoadingPercentage = 75; DisableDevices = new BooleanOptionItem(22900, "DisableDevices", false, TabGroup.GameSettings) @@ -2642,4 +2646,4 @@ public static class Options public static OptionItem VeteranAbilityChargesWhenFinishedTasks; // ReSharper restore NotAccessedField.Global -} +} \ No newline at end of file diff --git a/Patches/CredentialsPatch.cs b/Patches/CredentialsPatch.cs index fd6e60dab..dd9654b9a 100644 --- a/Patches/CredentialsPatch.cs +++ b/Patches/CredentialsPatch.cs @@ -47,20 +47,33 @@ internal static class PingTrackerUpdatePatch _ => "#ff4500" }; - var FPSGame = 1.0f / Time.deltaTime; - Color fpscolor = Color.green; + AppendSeparator(); + Sb.Append($"{ping} {GetString("PingText")}"); + AppendSeparator(); + Sb.Append(string.Format(GetString("Server"), Utils.GetRegionName())); - if (Main.ShowFps.Value) + if (Main.ShowFps.Value) { - var FPSGame = 1.0f / Time.deltaTime; - Color fpscolor = Color.green; + var fps = 1.0f / Time.deltaTime; - if (FPSGame < 20f) fpscolor = Color.red; - else if (FPSGame < 40f) fpscolor = Color.yellow; + Color fpscolor = fps switch + { + < 10f => Color.red, + < 30f => Color.yellow, + _ => Color.green + }; - Sb.Append($"\r\n{Utils.ColorString(fpscolor, Utils.ColorString(Color.cyan, GetString("FPSGame")) + ((int)FPSGame).ToString())}"); + AppendSeparator(); + Sb.Append($"{Utils.ColorString(fpscolor, Utils.ColorString(Color.cyan, GetString("FPSGame")) + ((int)fps))}"); } + if (GameStates.InGame) Sb.Append("\r\n."); + return; + + void AppendSeparator() => Sb.Append(GameStates.InGame ? " - " : "\r\n"); + } +} + [HarmonyPatch(typeof(VersionShower), nameof(VersionShower.Start))] internal static class VersionShowerStartPatch { @@ -135,10 +148,7 @@ static class FriendsListUIOpenPatch { try { - if (__instance.gameObject.activeSelf || __instance.currentSceneName == "") - { - __instance.Close(); - } + if (__instance.gameObject.activeSelf || __instance.currentSceneName == "") { __instance.Close(); } else { FriendsListBar[] componentsInChildren = __instance.GetComponentsInChildren(true); @@ -230,10 +240,7 @@ static class FriendsListUIOpenPatch ControllerManager.Instance.OpenOverlayMenu(__instance.name, __instance.BackButton, __instance.DefaultButtonSelected, __instance.ControllerSelectable); } } - catch (Exception e) - { - Utils.ThrowException(e); - } + catch (Exception e) { Utils.ThrowException(e); } return false; } @@ -268,14 +275,8 @@ internal static class TitleLogoPatch if (Ambience != null) { - try - { - __instance.playButton.transform.gameObject.SetActive(true); - } - catch (Exception ex) - { - Logger.Warn(ex.ToString(), "MainMenuLoader"); - } + try { __instance.playButton.transform.gameObject.SetActive(true); } + catch (Exception ex) { Logger.Warn(ex.ToString(), "MainMenuLoader"); } } if (!(LeftPanel = GameObject.Find("LeftPanel"))) return; @@ -298,10 +299,7 @@ internal static class TitleLogoPatch foreach (KeyValuePair, (Sprite, Color, Color, Color, Color)> kvp in mainButtons) kvp.Key.Do(button => FormatButtonColor(button, kvp.Value.Item2, kvp.Value.Item3, kvp.Value.Item4, kvp.Value.Item5)); - try - { - mainButtons.Keys.Flatten().DoIf(x => x != null, x => x.buttonText.color = Color.white); - } + try { mainButtons.Keys.Flatten().DoIf(x => x != null, x => x.buttonText.color = Color.white); } catch { } GameObject.Find("Divider")?.SetActive(false); @@ -442,4 +440,4 @@ internal static class OptionsMenuBehaviourOpenPatch return false; } -} +} \ No newline at end of file diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index c86d338c3..0e2b9cea2 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -132,7 +132,7 @@ internal static class SetUpRoleTextPatch foreach (CustomRoles subRole in Main.PlayerStates[lp.PlayerId].SubRoles) { - if (role is CustomRoles.LovingCrewmate or CustomRoles.LovingImpostor && subRole == CustomRoles.Lovers) continue; + if (role is CustomRoles.LovingCrewmate or CustomRoles.LovingImpostor && (subRole == CustomRoles.Lovers)) continue; __instance.RoleBlurbText.text += "\n" + Utils.ColorString(Utils.GetRoleColor(subRole), GetString($"{subRole}Info")); } @@ -147,7 +147,7 @@ internal static class SetUpRoleTextPatch { LateTask.New(() => { - if (AmongUsClient.Instance.IsGameOver || GameStates.IsLobby || lp == null) return; + if (AmongUsClient.Instance.IsGameOver || GameStates.IsLobby || (lp == null)) return; lp.SetName(Main.AllPlayerNames[lp.PlayerId]); }, 1f, "Reset Name For Modded Client"); @@ -198,8 +198,10 @@ internal static class CoBeginPatch sb.Append("------------Modded Settings------------\n"); foreach (OptionItem o in OptionItem.AllOptions) + { if (!o.IsCurrentlyHidden() && (o.Parent?.GetBool() ?? !o.GetString().Equals("0%"))) sb.Append($"{(o.Parent == null ? o.GetName(true, true).RemoveHtmlTags().PadRightV2(40) : $"┗ {o.GetName(true, true).RemoveHtmlTags()}".PadRightV2(41))}:{o.GetString().RemoveHtmlTags()}\n"); + } sb.Append("-------------Other Information-------------\n"); sb.Append($"Number of players: {Main.AllPlayerControls.Length}\n"); @@ -244,7 +246,7 @@ internal static class CoBeginPatch for (int i = charsInOneLine; i < longInfo.Length; i += charsInOneLine) { - if (tooLong && i > 296) break; + if (tooLong && (i > 296)) break; int index = longInfo.LastIndexOf(' ', i); if (index != -1) longInfo = longInfo.Insert(index + 1, "\n"); @@ -296,7 +298,7 @@ internal static class BeginCrewmatePatch return false; } - if (role == CustomRoles.LovingCrewmate || PlayerControl.LocalPlayer.Is(CustomRoles.Lovers)) + if ((role == CustomRoles.LovingCrewmate) || PlayerControl.LocalPlayer.Is(CustomRoles.Lovers)) { teamToDisplay = new(); teamToDisplay.Add(PlayerControl.LocalPlayer); @@ -313,8 +315,10 @@ internal static class BeginCrewmatePatch teamToDisplay = new(); foreach (PlayerControl pc in Main.AllPlayerControls) + { if (CustomTeamManager.AreInSameCustomTeam(pc.PlayerId, PlayerControl.LocalPlayer.PlayerId)) teamToDisplay.Add(pc); + } } } @@ -323,8 +327,10 @@ internal static class BeginCrewmatePatch teamToDisplay = new(); foreach (PlayerControl pc in Main.AllPlayerControls) - if (FFAManager.PlayerTeams.TryGetValue(pc.PlayerId, out int team) && team == ffaTeam) + { + if (FFAManager.PlayerTeams.TryGetValue(pc.PlayerId, out int team) && (team == ffaTeam)) teamToDisplay.Add(pc); + } } return true; @@ -392,7 +398,7 @@ internal static class BeginCrewmatePatch break; } - if (Main.LoversPlayers.Count == 2 && Main.LoversPlayers.Exists(x => x.IsLocalPlayer())) + if ((Main.LoversPlayers.Count == 2) && Main.LoversPlayers.Exists(x => x.IsLocalPlayer())) { __instance.TeamTitle.color = __instance.BackgroundBar.material.color = Utils.GetRoleColor(CustomRoles.Lovers); byte otherLoverId = Main.LoversPlayers.First(x => x.PlayerId != PlayerControl.LocalPlayer.PlayerId).PlayerId; @@ -489,7 +495,7 @@ internal static class BeginCrewmatePatch CustomRoles.Engineer or CustomRoles.EngineerEHR => GetIntroSound(RoleTypes.Engineer), - + CustomRoles.Scientist or CustomRoles.ScientistEHR or CustomRoles.Doctor or @@ -583,14 +589,16 @@ internal static class BeginCrewmatePatch { if (team.RoleRevealScreenTitle != "*") __instance.TeamTitle.text = team.RoleRevealScreenTitle; - if (team.RoleRevealScreenBackgroundColor != "*" && ColorUtility.TryParseHtmlString(team.RoleRevealScreenBackgroundColor, out Color bgColor)) __instance.TeamTitle.color = __instance.BackgroundBar.material.color = bgColor; + if ((team.RoleRevealScreenBackgroundColor != "*") && ColorUtility.TryParseHtmlString(team.RoleRevealScreenBackgroundColor, out Color bgColor)) __instance.TeamTitle.color = __instance.BackgroundBar.material.color = bgColor; __instance.ImpostorText.gameObject.SetActive(team.RoleRevealScreenSubtitle != "*"); __instance.ImpostorText.text = team.RoleRevealScreenSubtitle; foreach (PlayerControl pc in Main.AllPlayerControls) + { if (CustomTeamManager.AreInSameCustomTeam(pc.PlayerId, PlayerControl.LocalPlayer.PlayerId)) teamToDisplay.Add(pc); + } } } @@ -711,16 +719,14 @@ internal static class BeginCrewmatePatch return; - AudioClip GetAudioClipFromCustomRoleType() - { - return PlayerControl.LocalPlayer.GetCustomRoleTypes() switch + AudioClip GetAudioClipFromCustomRoleType() => + PlayerControl.LocalPlayer.GetCustomRoleTypes() switch { CustomRoleTypes.Impostor => GetIntroSound(RoleTypes.Impostor), CustomRoleTypes.Crewmate => GetIntroSound(RoleTypes.Crewmate), CustomRoleTypes.Neutral => GetIntroSound(RoleTypes.Shapeshifter), _ => GetIntroSound(RoleTypes.Crewmate) }; - } } private static AudioClip GetIntroSound(RoleTypes roleType) @@ -950,7 +956,7 @@ internal static class IntroCutsceneDestroyPatch _ => null }; - if (map != null && AmongUsClient.Instance.AmHost) aapc.Do(map.RandomTeleport); + if ((map != null) && AmongUsClient.Instance.AmHost) aapc.Do(map.RandomTeleport); } if (lp.HasDesyncRole()) @@ -975,9 +981,11 @@ internal static class IntroCutsceneDestroyPatch LateTask.New(() => Main.Instance.StartCoroutine(Utils.NotifyEveryoneAsync()), 3f, log: false); } else + { foreach (PlayerControl player in Main.AllPlayerControls) Main.PlayerStates[player.PlayerId].InitTask(player); + } Logger.Info("OnDestroy", "IntroCutscene"); } -} +} \ No newline at end of file diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index d4981628a..472f658d2 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -2419,6 +2419,7 @@ "MuteMessage": "<#ff0000>You're muted and cannot send messages. The mute will expire in <#ffff00>{0} seconds.", "WhisperTitle": "{0} <#ffffff>(ID <#00ffa5>{1}) whispers to you:", "DisableWhisperCommand": "Disable /whisper command", + "DisableSpectateCommand": "Disable /spectate command", "WhisperDisabled": "<#ff0000>X The /whisper command is disabled in this lobby.", "ThankYouForUsingEHR": "Thank you for using EHR!", "GMRoles": "【 ★ Roles ★ 】",