using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Korean_Chat")] [assembly: AssemblyDescription("Enable the IME to make able the Korean chat")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Korean_Chat")] [assembly: AssemblyCopyright("© 2025 whiteline7. All rights reserved")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("b8d219af-8857-4698-80f8-49ab71fb314d")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.1")] [module: UnverifiableCode] namespace Korean_Chat; [BepInPlugin("whiteline7.Korean_Chat", "Korean_Chat", "1.0.1")] public class KoreanChatPlugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static Harmony HarmonyInstance; internal static ConfigEntry cfg_Korean_Chat_Support; internal const int MaxChatLength = 50; internal static readonly FieldInfo ChatMessageField = typeof(ChatManager).GetField("chatMessage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal static bool ContainsKorean(string text) { if (string.IsNullOrEmpty(text)) { return false; } foreach (char c in text) { if (c >= '가' && c <= '힣') { return true; } if (c >= 'ㄱ' && c <= 'ㆎ') { return true; } } return false; } private void Awake() { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown cfg_Korean_Chat_Support = ((BaseUnityPlugin)this).Config.Bind("General", "Korean_Chat_Support", true, "true: 채팅에 한국어 지원을 활성화합니다. 채팅을 연 후 한영 변환키를 누르면 한국어 입력이 가능합니다.\nfalse: 한국어 지원을 비활성화합니다."); if (!cfg_Korean_Chat_Support.Value) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Korean_Chat is disabled in the config."); return; } Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"Korean_Chat v1.0.0 loaded."); HarmonyInstance = new Harmony("whiteline7.Korean_Chat"); HarmonyInstance.PatchAll(); } } [HarmonyPatch(typeof(ChatManager), "StateActive")] internal static class Patch_ChatManager_StateActive { private static string _lastComposition = ""; [HarmonyPrefix] private static void Prefix(ChatManager __instance, out string __state) { __state = null; if (KoreanChatPlugin.cfg_Korean_Chat_Support.Value && KoreanChatPlugin.ChatMessageField != null) { __state = (KoreanChatPlugin.ChatMessageField.GetValue(__instance) as string) ?? ""; } } [HarmonyPostfix] private static void Postfix(ChatManager __instance, string __state) { if (!KoreanChatPlugin.cfg_Korean_Chat_Support.Value || KoreanChatPlugin.ChatMessageField == null) { return; } string text = __state ?? ""; string text2 = Input.compositionString ?? ""; string text3 = Input.inputString ?? ""; int num = text3.Count((char c) => c == '\b'); bool num2 = !string.IsNullOrEmpty(text2); bool flag = !string.IsNullOrEmpty(_lastComposition) && string.IsNullOrEmpty(text2); int num3 = ((!num2 && !flag) ? num : 0); for (int num4 = 0; num4 < num3; num4++) { if (text.Length <= 0) { break; } text = text.Remove(text.Length - 1); } text3 = text3.Replace("\b", "").Replace("\r", "").Replace("\n", ""); if (text3.Contains(" ")) { while (text3.Length > 0 && text.EndsWith(text3[0].ToString())) { text3 = text3.Substring(1); } } text += text3; if (text.Length > 50) { text = text.Remove(50); } if (KoreanChatPlugin.ContainsKorean(text)) { text = text.Replace(" ", "\u00a0"); } if (string.IsNullOrEmpty(text)) { text = "\u00a0"; } KoreanChatPlugin.ChatMessageField.SetValue(__instance, text); _lastComposition = text2; } } [HarmonyPatch(typeof(ChatManager), "StateSend")] internal static class Patch_ChatManager_StateSend { [HarmonyPrefix] private static void Prefix(ChatManager __instance) { if (!KoreanChatPlugin.cfg_Korean_Chat_Support.Value || KoreanChatPlugin.ChatMessageField == null) { return; } string text = (KoreanChatPlugin.ChatMessageField.GetValue(__instance) as string) ?? ""; string text2 = Input.compositionString ?? ""; string lastComposition = Patch_ChatManager_Update.LastComposition; if (text.StartsWith("\u00a0")) { text = text.Substring(1); } string text3 = ((!string.IsNullOrEmpty(text2)) ? text2 : lastComposition); if (!string.IsNullOrEmpty(text3) && !text.EndsWith(text3)) { text += text3; } if (string.IsNullOrEmpty(text)) { KoreanChatPlugin.ChatMessageField.SetValue(__instance, ""); return; } if (text.Length > 50) { text = text.Remove(50); } KoreanChatPlugin.ChatMessageField.SetValue(__instance, text); } } [HarmonyPatch(typeof(ChatManager), "Update")] internal static class Patch_ChatManager_Update { private static bool _wasActive; internal static string LastComposition = ""; [HarmonyPostfix] private static void Postfix(ChatManager __instance) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (!KoreanChatPlugin.cfg_Korean_Chat_Support.Value || (Object)(object)__instance == (Object)null) { return; } bool flag = __instance.StateIsActive(); if (flag != _wasActive) { KoreanChatPlugin.Log.LogDebug((object)$"[Korean_Chat] Chat active state changed: {_wasActive} -> {flag}"); _wasActive = flag; } if (!flag) { Input.imeCompositionMode = (IMECompositionMode)2; return; } Input.imeCompositionMode = (IMECompositionMode)1; if ((Object)(object)__instance.chatText != (Object)null) { Vector3 position = ((TMP_Text)__instance.chatText).transform.position; Input.compositionCursorPos = new Vector2(position.x, (float)Screen.height - position.y); HandleComposition(__instance); HandlePaste(__instance); } LastComposition = Input.compositionString ?? ""; } private static void HandleComposition(ChatManager chatManager) { if (!(KoreanChatPlugin.ChatMessageField == null) && !((Object)(object)chatManager.chatText == (Object)null)) { string compositionString = Input.compositionString; string text = (KoreanChatPlugin.ChatMessageField.GetValue(chatManager) as string) ?? ""; if (text.StartsWith("\u00a0")) { text = text.Substring(1); } if (string.IsNullOrEmpty(compositionString)) { ((TMP_Text)chatManager.chatText).text = text + "|"; return; } ((TMP_Text)chatManager.chatText).richText = true; ((TMP_Text)chatManager.chatText).text = text + "" + compositionString + "|"; } } private static void HandlePaste(ChatManager chatManager) { if ((!Input.GetKey((KeyCode)306) && !Input.GetKey((KeyCode)305)) || !Input.GetKeyDown((KeyCode)118)) { return; } string systemCopyBuffer = GUIUtility.systemCopyBuffer; if (string.IsNullOrEmpty(systemCopyBuffer)) { return; } systemCopyBuffer = systemCopyBuffer.Replace("\r\n", "").Replace("\n", "").Replace("\r", ""); if (systemCopyBuffer.Length != 0) { string text = ((KoreanChatPlugin.ChatMessageField.GetValue(chatManager) as string) ?? "") + systemCopyBuffer; if (KoreanChatPlugin.ContainsKorean(text)) { text = text.Replace(" ", "\u00a0"); } if (text.Length > 50) { text = text.Remove(50); } KoreanChatPlugin.ChatMessageField.SetValue(chatManager, text); if ((Object)(object)chatManager.chatText != (Object)null) { ((TMP_Text)chatManager.chatText).text = text; } KoreanChatPlugin.Log.LogDebug((object)("[Korean_Chat] Pasted: '" + text + "'")); } } } [HarmonyPatch(typeof(SemiFunc), "InputDown")] internal static class Patch_SemiFunc_InputDown_ChatDelete { [HarmonyPrefix] private static bool Prefix(InputKey key, ref bool __result) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 if (!KoreanChatPlugin.cfg_Korean_Chat_Support.Value) { return true; } if ((int)key == 13 && (Object)(object)ChatManager.instance != (Object)null && ChatManager.instance.StateIsActive()) { __result = false; return false; } return true; } }