Decompiled source of JapaneseTextInput v2.0.2

plugins/JapaneseTextInput.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JapaneseTextInput")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e3a81cca1410a5f75aeb91c5a1de120d92026c33")]
[assembly: AssemblyProduct("JapaneseTextInput")]
[assembly: AssemblyTitle("JapaneseTextInput")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace JapaneseTextInput
{
	[HarmonyPatch(typeof(MenuTextInput), "Update")]
	internal static class Patch_MenuTextInput_Ime
	{
		private static void Prefix(MenuTextInput __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			Input.imeCompositionMode = (IMECompositionMode)1;
			if ((Object)(object)__instance.textCursor != (Object)null)
			{
				Vector3 position = ((TMP_Text)__instance.textCursor).transform.position;
				Input.compositionCursorPos = new Vector2(position.x, (float)Screen.height - position.y);
			}
		}

		private static void Postfix(MenuTextInput __instance)
		{
			string compositionString = Input.compositionString;
			if (!string.IsNullOrEmpty(compositionString) && !((Object)(object)__instance.textMain == (Object)null))
			{
				TextMeshProUGUI textMain = __instance.textMain;
				((TMP_Text)textMain).text = ((TMP_Text)textMain).text + "【" + compositionString + "】";
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageServerListCreateNew), "Update")]
	internal static class Patch_MenuPageServerListCreateNew_ImeUpdate
	{
		private static bool s_wasComposing;

		internal static bool s_blockConfirm;

		private static void Prefix()
		{
			bool flag = !string.IsNullOrEmpty(Input.compositionString);
			s_blockConfirm = s_wasComposing && !flag;
			s_wasComposing = flag;
		}
	}
	[HarmonyPatch(typeof(MenuPageServerListCreateNew), "ButtonConfirm")]
	internal static class Patch_MenuPageServerListCreateNew_ButtonConfirm
	{
		private static bool Prefix()
		{
			if (Patch_MenuPageServerListCreateNew_ImeUpdate.s_blockConfirm)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "InputDown")]
	internal static class Patch_SemiFunc_InputDown_ImeBlock
	{
		private static bool Prefix(InputKey key, ref bool __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			if ((int)key == 13 && (Object)(object)ChatManager.instance != (Object)null && ChatManager.instance.StateIsActive() && (Patch_ChatManager_Ime.s_blockConfirm || !string.IsNullOrEmpty(Input.compositionString)))
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ChatManager), "Update")]
	internal static class Patch_ChatManager_Ime
	{
		private static bool s_wasComposing = false;

		internal static bool s_blockConfirm = false;

		private static readonly FieldInfo f_chatState = typeof(ChatManager).GetField("chatState", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void Prefix(ChatManager __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.StateIsActive())
			{
				s_blockConfirm = false;
				if (string.IsNullOrEmpty(Input.compositionString))
				{
					Input.imeCompositionMode = (IMECompositionMode)0;
				}
				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);
			}
			s_blockConfirm = s_wasComposing && string.IsNullOrEmpty(Input.compositionString);
		}

		private static void Postfix(ChatManager __instance)
		{
			if (s_blockConfirm && __instance.StateIsSend() && f_chatState != null)
			{
				f_chatState.SetValue(__instance, (object)(ChatState)1);
			}
			s_wasComposing = __instance.StateIsActive() && !string.IsNullOrEmpty(Input.compositionString);
			if (!__instance.StateIsActive())
			{
				return;
			}
			string compositionString = Input.compositionString;
			if (!string.IsNullOrEmpty(compositionString) && !((Object)(object)__instance.chatText == (Object)null))
			{
				string text = ((TMP_Text)__instance.chatText).text;
				bool flag = text.EndsWith("|");
				if (flag)
				{
					text = text.Substring(0, text.Length - 1);
				}
				((TMP_Text)__instance.chatText).text = text + "【" + compositionString + "】" + (flag ? "|" : "");
			}
		}
	}
	[HarmonyPatch(typeof(MenuTextInput), "Update")]
	internal static class Patch_MenuTextInput_Update
	{
		private static readonly FieldInfo f_textCurrent = typeof(MenuTextInput).GetField("textCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static bool s_warned = false;

		private static void Postfix(MenuTextInput __instance)
		{
			if (f_textCurrent == null)
			{
				if (!s_warned)
				{
					Plugin.Logger.LogWarning((object)"[JapaneseTextInput] MenuTextInput.textCurrent フィールドが見つかりません。ゲームのバージョンに対応していない可能性があります。");
					s_warned = true;
				}
			}
			else
			{
				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)
				{
					if (__instance.upperOnly)
					{
						systemCopyBuffer = systemCopyBuffer.ToUpper();
					}
					string text = ((string)f_textCurrent.GetValue(__instance)) ?? "";
					text += systemCopyBuffer;
					if (text.Length > __instance.maxLength)
					{
						text = text.Remove(__instance.maxLength);
					}
					f_textCurrent.SetValue(__instance, text);
					Plugin.Logger.LogDebug((object)("[Paste:Menu] '" + text + "'"));
				}
			}
		}
	}
	[HarmonyPatch(typeof(ChatManager), "Update")]
	internal static class Patch_ChatManager_Update
	{
		private const int MaxChatLength = 50;

		private static readonly FieldInfo f_chatMessage = typeof(ChatManager).GetField("chatMessage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static bool s_warned = false;

		private static void Postfix(ChatManager __instance)
		{
			if (f_chatMessage == null)
			{
				if (!s_warned)
				{
					Plugin.Logger.LogWarning((object)"[JapaneseTextInput] ChatManager.chatMessage フィールドが見つかりません。ゲームのバージョンに対応していない可能性があります。");
					s_warned = true;
				}
			}
			else
			{
				if (!__instance.StateIsActive() || (!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 = ((string)f_chatMessage.GetValue(__instance)) ?? "";
					string text2 = text + systemCopyBuffer;
					if (text2.Length > 50)
					{
						text2 = text2.Remove(50);
					}
					f_chatMessage.SetValue(__instance, text2);
					if ((Object)(object)__instance.chatText != (Object)null)
					{
						((TMP_Text)__instance.chatText).text = text2;
					}
					Plugin.Logger.LogDebug((object)("[Paste:Chat] '" + text2 + "'"));
				}
			}
		}
	}
	[BepInPlugin("com.sukunabikona.japanesetextinput", "Japanese Text Input", "2.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.sukunabikona.japanesetextinput";

		public const string Name = "Japanese Text Input";

		public const string Version = "2.0.0";

		internal static ManualLogSource Logger;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("com.sukunabikona.japanesetextinput");
			harmony.PatchAll();
			Logger.LogInfo((object)"Japanese Text Input v2.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}