Decompiled source of JapaneseTextInput v1.0.0

plugins/JapaneseTextInput.dll

Decompiled a day 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+749ababde5242739e64855d122ffea093a78ed40")]
[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_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", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.sukunabikona.japanesetextinput";

		public const string Name = "Japanese Text Input";

		public const string Version = "1.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 v1.0.0 loaded.");
		}

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