From f11eb5ae4634b534bc5227ced8ea354e01474f81 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Sat, 24 Jan 2026 16:59:25 +0100 Subject: [PATCH] fix zyph's mess + fix chat during game causing black screen --- Modules/Translator.cs | 16 +++++++++++-- Modules/Utils.cs | 50 +++++++++++++++++++++++++++++++++++++-- Patches/TextBoxPatch.cs | 1 - Resources/Lang/ar_SA.json | 2 +- Resources/Lang/cs_CZ.json | 2 +- Resources/Lang/de_DE.json | 2 +- Resources/Lang/ro_RO.json | 2 +- Resources/Lang/sr_CS.json | 2 +- Resources/Lang/vi_VN.json | 2 +- 9 files changed, 68 insertions(+), 11 deletions(-) diff --git a/Modules/Translator.cs b/Modules/Translator.cs index a5782fbaa..6ef3d66d5 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -48,6 +48,8 @@ public static class Translator foreach (string jsonFileName in jsonFileNames) { + Logger.Warn($"Loading lang file: {jsonFileName}", "Translator"); + // Read the JSON file content using Stream resourceStream = assembly.GetManifestResourceStream(jsonFileName); @@ -55,6 +57,8 @@ public static class Translator { using StreamReader reader = new(resourceStream); string jsonContent = reader.ReadToEnd(); + + File.WriteAllText($"{Main.DataPath}/{LanguageFolderName}/debug_{jsonFileName}.json", jsonContent); // Deserialize the JSON into a dictionary var jsonDictionary = JsonSerializer.Deserialize>(jsonContent); @@ -76,10 +80,10 @@ public static class Translator } // Convert the resulting translation map to JSON - JsonSerializer.Serialize(TranslateMaps, new JsonSerializerOptions + File.WriteAllText($"{Main.DataPath}/{LanguageFolderName}/debug.json", JsonSerializer.Serialize(TranslateMaps, new JsonSerializerOptions { WriteIndented = true - }); + })); } catch (Exception ex) { Logger.Error($"Error: {ex}", "Translator"); } @@ -112,6 +116,14 @@ public static class Translator { // If the textString is not already in the translation map, add it if (!translationMaps.ContainsKey(textString)) translationMaps[textString] = []; + + if (translationMaps[textString].ContainsKey(languageId)) + { + Logger.Warn( + $"Overwriting translation: {textString} ({languageId})", + "Translator" + ); + } // Add or update the translation for the current id and textString translationMaps[textString][languageId] = translation.Replace("\\n", "\n").Replace("\\r", "\r"); diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 5f8e369e6..5c1c267c8 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1865,7 +1865,10 @@ public static class Utils title = title.Replace("color=", string.Empty); if (GameStates.CurrentServerType == GameStates.ServerType.Vanilla) + { text = ReplaceHexColorsWithSafeColors(text); + text = ReplaceDigitsOutsideRichText(text); + } PlayerControl sender = !addToHistory || GameStates.CurrentServerType == GameStates.ServerType.Vanilla ? PlayerControl.LocalPlayer : Main.AllAlivePlayerControls.MinBy(x => x.PlayerId) ?? Main.AllPlayerControls.MinBy(x => x.PlayerId) ?? PlayerControl.LocalPlayer; @@ -2182,7 +2185,7 @@ public static class Utils foreach (char c in text) { - if (char.IsDigit(c) && digitCount == 5) + if (c is >= '0' and <= '9' && digitCount == 5) { int lastNewline = sb.ToString().LastIndexOf('\n'); @@ -2316,6 +2319,37 @@ public static class Utils return CachedLetterOnlyHexColors; } + + static string ReplaceDigitsOutsideRichText(string text) + { + if (string.IsNullOrWhiteSpace(text)) return text; + + StringBuilder sb = new(text.Length); + bool insideTag = false; + + foreach (char c in text) + { + switch (c) + { + case '<': + insideTag = true; + sb.Append(c); + continue; + case '>': + insideTag = false; + sb.Append(c); + continue; + case >= '0' and <= '9' when !insideTag: + sb.Append((char)('0' + (c - '0'))); + break; + default: + sb.Append(c); + break; + } + } + + return sb.ToString(); + } } public static HashSet DirtyName = []; @@ -4459,7 +4493,19 @@ public static class Utils public static void SetChatVisibleForAll() { if (!GameStates.IsInGame) return; - Main.AllAlivePlayerControls.Do(x => x.SetChatVisible(true)); + + PlayerControl[] aapc = Main.AllAlivePlayerControls; + + if (Options.CurrentGameMode is CustomGameMode.Mingle or CustomGameMode.Quiz or CustomGameMode.NaturalDisasters) + { + foreach (var pc in aapc) + { + var dummyImp = aapc.FirstOrDefault(x => x != pc); + if (dummyImp != null) dummyImp.RpcSetRoleDesync(RoleTypes.Impostor, pc.OwnerId); + } + } + + aapc.Do(x => x.SetChatVisible(true)); } public static bool TryCast(this Il2CppObjectBase obj, out T casted) where T : Il2CppObjectBase diff --git a/Patches/TextBoxPatch.cs b/Patches/TextBoxPatch.cs index b076cf8d2..ba52695af 100644 --- a/Patches/TextBoxPatch.cs +++ b/Patches/TextBoxPatch.cs @@ -255,7 +255,6 @@ public static class TextBoxPatch if (length <= i) break; int skip = poll ? input.TakeWhile(x => x != '?').Count(x => x == ' ') - 1 : 0; - Logger.Warn($"args.Length: {args.Length}, spaces: {spaces}, i: {i}, args: {string.Join('*', args)}", "debug"); string arg = poll ? i == 0 ? string.Join(' ', args[..++skip]) : args[spaces - 1 < i ? skip + i + spaces : skip + i] : spaces > length && i == length - 1 ? string.Join(' ', args[i..^length]) : args[spaces > i ? i : i + spaces]; string argName = command.Arguments.Split(' ')[i]; diff --git a/Resources/Lang/ar_SA.json b/Resources/Lang/ar_SA.json index 2cb6319d3..893db128d 100644 --- a/Resources/Lang/ar_SA.json +++ b/Resources/Lang/ar_SA.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "104", "TextBelowVersionText": "", "HostText": "مضيف - EHR", "IconColor": "00a5ff", diff --git a/Resources/Lang/cs_CZ.json b/Resources/Lang/cs_CZ.json index d129ed827..d209c81f8 100644 --- a/Resources/Lang/cs_CZ.json +++ b/Resources/Lang/cs_CZ.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "105", "TextBelowVersionText": "", "HostText": "EHR - Host", "IconColor": "#00a5ff", diff --git a/Resources/Lang/de_DE.json b/Resources/Lang/de_DE.json index 04dea841f..c0658db48 100644 --- a/Resources/Lang/de_DE.json +++ b/Resources/Lang/de_DE.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "9", "TextBelowVersionText": "", "HostText": "EHR - Host", "IconColor": "#00a5ff", diff --git a/Resources/Lang/ro_RO.json b/Resources/Lang/ro_RO.json index 7d406d840..4c7d53b57 100644 --- a/Resources/Lang/ro_RO.json +++ b/Resources/Lang/ro_RO.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "106", "TextBelowVersionText": "", "HostText": "EHR - Host", "IconColor": "#00a5ff", diff --git a/Resources/Lang/sr_CS.json b/Resources/Lang/sr_CS.json index e55406a80..603b70786 100644 --- a/Resources/Lang/sr_CS.json +++ b/Resources/Lang/sr_CS.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "107", "TextBelowVersionText": "", "HostText": "EHR - Domaćin", "IconColor": "#00a5ff", diff --git a/Resources/Lang/vi_VN.json b/Resources/Lang/vi_VN.json index c14507135..604923def 100644 --- a/Resources/Lang/vi_VN.json +++ b/Resources/Lang/vi_VN.json @@ -1,5 +1,5 @@ { - "LanguageID": "0", + "LanguageID": "108", "TextBelowVersionText": "", "HostText": "EHR - Host", "IconColor": "#00a5ff",