From b95616ee665a004675ce3cfa4d9580540c0bfc44 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Mon, 6 Jul 2026 11:20:38 +0200 Subject: [PATCH] some fixes --- Modules/EAC.cs | 4 ++-- Modules/Translator.cs | 4 +++- Patches/ChatCommandPatch.cs | 29 +++++++---------------------- Patches/PlayerControlPatch.cs | 6 +----- Patches/ReversePatches.cs | 14 ++++++++++++++ Resources/Lang/en_US.json | 2 +- 6 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 Patches/ReversePatches.cs diff --git a/Modules/EAC.cs b/Modules/EAC.cs index 64225edd5..fe3bfbcd4 100644 --- a/Modules/EAC.cs +++ b/Modules/EAC.cs @@ -6,6 +6,7 @@ using System.Linq; using AmongUs.GameOptions; using AmongUs.QuickChat; using BepInEx.Unity.IL2CPP.Utils.Collections; +using EHR.Patches.ReversePatches; using HarmonyLib; using Hazel; using InnerNet; @@ -1251,8 +1252,7 @@ internal static class InitializePlayerTimeoutPatch { player.Visible = false; bool exit = false; - AssertWithTimeoutPatch.AllowCall = true; - yield return player.AssertWithTimeout((Func)(() => GameData.Instance != null && player.Data != null && !player.Data.IsIncomplete), (Action)(() => + yield return player.AssertWithTimeout_Unpatched((Func)(() => GameData.Instance != null && player.Data != null && !player.Data.IsIncomplete), (Action)(() => { if (player == null || player.Pointer == IntPtr.Zero) { diff --git a/Modules/Translator.cs b/Modules/Translator.cs index c7603a93b..f873f2d32 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -350,7 +350,9 @@ public static class Translator public static string FixRoleName(this string infoLong, CustomRoles role) { - return OriginalRoleNames.TryGetValue(role, out var d) && d.TryGetValue(GetUserTrueLang(), out var o) ? infoLong.Replace(o, role.ToColoredString(), StringComparison.OrdinalIgnoreCase) : infoLong; + if (!OriginalRoleNames.TryGetValue(role, out var d) || !d.TryGetValue(GetUserTrueLang(), out var o)) return infoLong; + string modifiedName = role.ToColoredString(); + return infoLong.Contains(modifiedName) ? infoLong : infoLong.Replace(o, modifiedName, StringComparison.OrdinalIgnoreCase); } public static bool LangHasSensitiveOutlineText() diff --git a/Patches/ChatCommandPatch.cs b/Patches/ChatCommandPatch.cs index fd433f674..4324e3d4e 100644 --- a/Patches/ChatCommandPatch.cs +++ b/Patches/ChatCommandPatch.cs @@ -2045,7 +2045,7 @@ internal static class ChatCommands if (GameStates.IsLobby || !player.FriendCode.GetDevUser().up) return; string subArgs = text.Remove(0, 8); - string setRole = FixRoleNameInput(subArgs.Trim()); + string setRole = subArgs.Trim().Replace("着", "者"); foreach (CustomRoles rl in Main.CustomRoleValues) { @@ -2713,9 +2713,8 @@ internal static class ChatCommands private static void RCommand(PlayerControl player, string text, string[] args) { string subArgs = text.Remove(0, 2); - byte to = player.AmOwner && ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) || ClientControlGUI.BroadcastRoleInfo) - ? byte.MaxValue : player.PlayerId; - ClientControlGUI.BroadcastRoleInfo = false; + byte to = player.AmOwner && ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) || ClientControlGUI.BroadcastRoleInfo) ? byte.MaxValue : player.PlayerId; + ClientControlGUI.BroadcastRoleInfo = false; SendRolesInfo(subArgs, to); } @@ -3262,17 +3261,6 @@ internal static class ChatCommands return true; } - private static string FixRoleNameInput(string text) - { - text = text.Replace("着", "者").Trim().ToLower(); - - return text switch - { - "schrodingers cat" or "schrodingerscat" or "cat" => "Schrödinger's Cat", - _ => text - }; - } - public static bool GetRoleByName(string name, out CustomRoles role) { role = new(); @@ -3291,7 +3279,7 @@ internal static class ChatCommands result += mc[i]; //匹配结果是完整的数字,此处可以不做拼接的 } - name = FixRoleNameInput(result.Replace("是", string.Empty).Trim()); + name = result.Replace("是", string.Empty).Trim().Replace("着", "者"); } else name = name.Trim().ToLower(); @@ -3324,10 +3312,6 @@ internal static class ChatCommands } role = role.Trim().ToLower(); - if (role.StartsWith("/r")) _ = role.Replace("/r", string.Empty); - if (role.StartsWith("/up")) _ = role.Replace("/up", string.Empty); - if (role.EndsWith("\r\n")) _ = role.Replace("\r\n", string.Empty); - if (role.EndsWith("\n")) _ = role.Replace("\n", string.Empty); if (role == "") { @@ -3335,7 +3319,8 @@ internal static class ChatCommands return; } - role = FixRoleNameInput(role).ToLower().Trim().Replace(" ", string.Empty); + string originalInput = role; + role = role.Replace("着", "者").ToLower().Trim().Replace(" ", string.Empty); foreach (CustomRoles rl in Main.CustomRoleValues) { @@ -3343,7 +3328,7 @@ internal static class ChatCommands string roleName = Regex.Replace(GetString(rl.ToString()).RemoveHtmlTags().ToLower().Trim().TrimStart('*'), @"[^\p{L}-]+", string.Empty); - if (role == roleName) + if (role == roleName || (originalInput is "schrodingers cat" or "schrodingerscat" or "cat" && rl == CustomRoles.SchrodingersCat)) { if ((isDev || isUp) && GameStates.IsLobby) { diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 44fc96395..c8707cc27 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -2603,13 +2603,9 @@ internal static class PlayerControlLocalSetRolePatch [HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.AssertWithTimeout))] internal static class AssertWithTimeoutPatch { - public static bool AllowCall; - public static bool Prefix() { - bool allow = AllowCall; - AllowCall = false; - return allow; + return false; } } diff --git a/Patches/ReversePatches.cs b/Patches/ReversePatches.cs new file mode 100644 index 000000000..bbecab4ad --- /dev/null +++ b/Patches/ReversePatches.cs @@ -0,0 +1,14 @@ +using System; +using HarmonyLib; + +namespace EHR.Patches.ReversePatches; + +public static class ReversePatches +{ + [HarmonyReversePatch] + [HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.AssertWithTimeout))] + internal static Il2CppSystem.Collections.IEnumerator AssertWithTimeout_Unpatched(this PlayerControl __instance, Func assertion, Action onTimeout, float timeoutInSeconds) + { + throw new Exception("Reverse Patch Stub"); + } +} \ No newline at end of file diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index f8dee4f1e..9208d4b24 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -2498,7 +2498,7 @@ "Berserker.LowerKillCooldown": "Lower Kill Cooldown", "Blockade": "Blockade", "BlockadeInfo": "Place Blockades", - "BlockadeInfoLong": "(Neutrals):\\nAs the Blockade, you can vanish/pet/shapeshift to place blockades. No one other than you can go through them. All blockades disappear when a meeting starts.", + "BlockadeInfoLong": "(Neutrals):\\nAs the Blockade, you can vanish/pet/shapeshift to place blockades. No one other than you can go through them. All blockades disappear when a meeting starts.\\nKill everyone to win!", "Blockade.BlockadeRadius": "Blockade Radius", "BloodKnight": "Blood Knight", "BloodKnightInfo": "Killing gives you a temporary shield",