Decompiled source of CopyChat v1.0.0

plugins/CopyChat.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CopyChat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+44c6f0897d142ebfcf240ccd71c01999232f177d")]
[assembly: AssemblyProduct("CopyChat")]
[assembly: AssemblyTitle("CopyChat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 CopyChat
{
	[BepInPlugin("com.jai.ontogether.copychat", "Copy Chat", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CopyChat Loaded");
			Harmony val = new Harmony("com.jai.ontogether.copychat");
			MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("TextChannelManager"), "AddMessageUI", new Type[4]
			{
				typeof(string),
				typeof(string),
				typeof(bool),
				typeof(int)
			}, (Type[])null);
			val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AddMessageUI_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void AddMessageUI_Postfix(string userName, string text, bool isLocal, int senderIndex)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				UIManager i = MonoSingleton<UIManager>.I;
				if ((Object)(object)i == (Object)null)
				{
					return;
				}
				Transform val = (isLocal ? i.TextContentLocalTransform : i.TextContentGlobalTransform);
				if ((Object)(object)val == (Object)null || val.childCount == 0)
				{
					return;
				}
				GameObject gameObject = ((Component)val.GetChild(val.childCount - 1)).gameObject;
				if ((Object)(object)gameObject == (Object)null || (Object)(object)gameObject.GetComponent<ChatCopyHandler>() != (Object)null)
				{
					return;
				}
				TMP_Text componentInChildren = gameObject.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren == (Object)null)
				{
					return;
				}
				((Graphic)componentInChildren).color = Color.green;
				((Graphic)componentInChildren).raycastTarget = true;
				ChatCopyHandler handler = gameObject.AddComponent<ChatCopyHandler>();
				handler.content = text;
				((UnityEvent)gameObject.AddComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					handler.DoCopy();
				});
				if ((Object)(object)gameObject.GetComponent<Image>() == (Object)null)
				{
					((Graphic)gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.01f);
				}
				Transform parent = gameObject.transform.parent;
				int num = 0;
				while ((Object)(object)parent != (Object)null && num < 10)
				{
					Image component = ((Component)parent).GetComponent<Image>();
					if ((Object)(object)component != (Object)null)
					{
						((Graphic)component).raycastTarget = false;
					}
					parent = parent.parent;
					num++;
				}
			}
			catch
			{
			}
		}
	}
	public class ChatCopyHandler : MonoBehaviour
	{
		public string content;

		public void DoCopy()
		{
			if (!string.IsNullOrEmpty(content))
			{
				GUIUtility.systemCopyBuffer = Regex.Replace(content, "<.*?>", string.Empty);
				ShowToast("\ud83d\udccb Copied!");
			}
		}

		private void ShowToast(string message)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_006a: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CopyToast", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 0.5f);
			component.anchorMax = new Vector2(1f, 0.5f);
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(10f, 0f);
			component.sizeDelta = new Vector2(250f, 50f);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).text = message;
			((TMP_Text)obj).fontSize = 24f;
			((Graphic)obj).color = new Color(0.2f, 1f, 0.2f);
			((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
			((TMP_Text)obj).fontStyle = (FontStyles)1;
			Shadow obj2 = val.AddComponent<Shadow>();
			obj2.effectColor = new Color(0f, 0f, 0f, 0.8f);
			obj2.effectDistance = new Vector2(2f, -2f);
			val.AddComponent<ToastAnimator>();
		}
	}
	public class ToastAnimator : MonoBehaviour
	{
		private TextMeshProUGUI text;

		private float speed = 40f;

		private float timer;

		private void Start()
		{
			text = ((Component)this).GetComponent<TextMeshProUGUI>();
		}

		private void Update()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			timer += Time.deltaTime;
			((Component)this).transform.Translate(Vector3.right * speed * Time.deltaTime);
			if ((Object)(object)text != (Object)null)
			{
				float num = Mathf.Lerp(1f, 0f, timer / 1.5f);
				((Graphic)text).color = new Color(0.2f, 1f, 0.2f, num);
			}
			if (timer >= 1.5f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
}