Decompiled source of BetterChat v1.1.1

plugins/BetterChat.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("BetterChat")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ae9505ba92c81c3b7dacf7f60b29296e576f07c8")]
[assembly: AssemblyProduct("BetterChat")]
[assembly: AssemblyTitle("BetterChat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BetterChat
{
	public static class Asset
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "betterchatbundle";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(typeof(BetterChatPlugin).Assembly.Location), "betterchatbundle".ToLower());

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	[BepInPlugin("Slendykray.BetterChat", "BetterChat", "1.0.0")]
	public class BetterChatPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Slendykray.BetterChat";

		public const string PluginAuthor = "Slendykray";

		public const string PluginName = "BetterChat";

		public const string PluginVersion = "1.0.0";

		public static PlayerChat currentChat;

		public static ChatBox defaultChatbox;

		private Vector2 defaultOffsetMax;

		private Vector2 defaultOffsetMin;

		public static ConfigEntry<float> playerChatPosY;

		public static ConfigEntry<float> playerChatHeight;

		public static ConfigEntry<float> defaultChatPosY;

		public static ConfigEntry<float> defaultChatHeight;

		public void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			Asset.Init();
			InitConfig();
			Chat.AddMessage_ChatMessageBase += new hook_AddMessage_ChatMessageBase(Chat_AddMessage_ChatMessageBase);
			HUD.Awake += new hook_Awake(HUD_Awake);
			AllyCardManager.Awake += new hook_Awake(AllyCardManager_Awake);
			ChatBox.Start += new hook_Start(ChatBox_Start);
			ChatBox.Awake += new hook_Awake(ChatBox_Awake);
		}

		private void ChatBox_Awake(orig_Awake orig, ChatBox self)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)((Component)self).transform).name.Contains("ChatBox, In Run"))
			{
				defaultOffsetMax = self.standardChatboxRect.offsetMax;
				defaultOffsetMin = self.standardChatboxRect.offsetMin;
			}
			orig.Invoke(self);
		}

		private void InitConfig()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			Sprite modIcon = Asset.mainBundle.LoadAsset<Sprite>("icon.png");
			ModSettingsManager.SetModIcon(modIcon);
			playerChatPosY = ((BaseUnityPlugin)this).Config.Bind<float>("PlayerChat", "playerChatPosY", 50f, "default: 50");
			playerChatHeight = ((BaseUnityPlugin)this).Config.Bind<float>("PlayerChat", "playerChatHeight", 170f, "default: 170");
			defaultChatPosY = ((BaseUnityPlugin)this).Config.Bind<float>("DefaultChat", "defaultChatPosY", 210f, "default: 210");
			defaultChatHeight = ((BaseUnityPlugin)this).Config.Bind<float>("DefaultChat", "defaultChatHeight", 140f, "default: 140");
			ModSettingsManager.AddOption((BaseOption)new SliderOption(playerChatPosY, new SliderConfig
			{
				min = 40f,
				max = 260f
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(playerChatHeight, new SliderConfig
			{
				min = 40f,
				max = 260f
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(defaultChatPosY, new SliderConfig
			{
				min = 40f,
				max = 260f
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(defaultChatHeight, new SliderConfig
			{
				min = 40f,
				max = 260f
			}));
			playerChatPosY.SettingChanged += delegate
			{
				SetShit();
			};
			playerChatHeight.SettingChanged += delegate
			{
				SetShit();
			};
			defaultChatPosY.SettingChanged += delegate
			{
				SetShit();
			};
			defaultChatHeight.SettingChanged += delegate
			{
				SetShit();
			};
		}

		private void SetShit()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			RectTransform standardChatboxRect = defaultChatbox.standardChatboxRect;
			RectTransform component = ((Component)((Component)currentChat).transform).GetComponent<RectTransform>();
			component.anchorMax = new Vector2(1f, 0.45f);
			standardChatboxRect.offsetMax = defaultOffsetMax;
			standardChatboxRect.offsetMin = defaultOffsetMin;
			defaultChatbox.allowExpandedChatbox = false;
			component.anchoredPosition = new Vector2(-155f, playerChatPosY.Value);
			standardChatboxRect.anchoredPosition = new Vector2(0f, defaultChatPosY.Value);
			component.SetSizeWithCurrentAnchors((Axis)1, playerChatHeight.Value);
			standardChatboxRect.SetSizeWithCurrentAnchors((Axis)1, defaultChatHeight.Value);
		}

		private void ChatBox_Start(orig_Start orig, ChatBox self)
		{
			orig.Invoke(self);
			if (((Object)((Component)self).transform).name.Contains("ChatBox, In Run"))
			{
				defaultChatbox = self;
				SetShit();
			}
		}

		private void AllyCardManager_Awake(orig_Awake orig, AllyCardManager self)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			RectTransform component = ((Component)self).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchorMin = new Vector2(0.11f, 0.45f);
			}
		}

		private void Chat_AddMessage_ChatMessageBase(orig_AddMessage_ChatMessageBase orig, ChatMessageBase message)
		{
			if (message is UserChatMessage && ((Object)((Component)ChatBox.instance).transform).name.Contains("ChatBox, In Run"))
			{
				if (Object.op_Implicit((Object)(object)currentChat))
				{
					currentChat.AddMessage(message.ConstructChatString());
				}
			}
			else
			{
				orig.Invoke(message);
			}
		}

		private void HUD_Awake(orig_Awake orig, HUD self)
		{
			orig.Invoke(self);
			GameObject val = Asset.mainBundle.LoadAsset<GameObject>("Chat");
			Transform val2 = self.mainContainer.transform.Find("MainUIArea/SpringCanvas/BottomLeftCluster/ChatBoxRoot");
			GameObject val3 = Object.Instantiate<GameObject>(val, val2);
			currentChat = val3.AddComponent<PlayerChat>();
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public class PlayerChat : MonoBehaviour
	{
		private int maxMessages = 30;

		private readonly Queue<string> messages = new Queue<string>();

		private TextMeshProUGUI chatText;

		public ScrollRect scrollRect;

		private bool shouldAutoScroll = true;

		private float fadeTimer;

		public CanvasGroup fadeGroup;

		public float fadeDuration = 5f;

		public float fadeWait = 5f;

		private float alpha;

		private void Start()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			Transform val = ((Component)this).transform.Find("Viewport/Content");
			GameObject val2 = new GameObject("ChatText", new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
			val2.transform.SetParent(((Component)val).transform, false);
			chatText = val2.GetComponent<TextMeshProUGUI>();
			((TMP_Text)chatText).fontSize = 20f;
			scrollRect = ((Component)this).GetComponent<ScrollRect>();
			((UnityEvent<Vector2>)(object)scrollRect.onValueChanged).AddListener((UnityAction<Vector2>)OnScroll);
			fadeGroup = ((Component)((Component)this).transform).GetComponent<CanvasGroup>();
		}

		private void OnScroll(Vector2 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			shouldAutoScroll = position.y <= 0.25f;
		}

		public void AddMessage(string message)
		{
			messages.Enqueue(message);
			while (messages.Count > maxMessages)
			{
				messages.Dequeue();
			}
			((TMP_Text)chatText).text = string.Join("\n", messages);
			Util.PlaySound("Play_UI_chatMessage", ((Component)RoR2Application.instance).gameObject);
			if (shouldAutoScroll)
			{
				Canvas.ForceUpdateCanvases();
				((LayoutGroup)((Component)scrollRect.content).GetComponent<VerticalLayoutGroup>()).CalculateLayoutInputVertical();
				((Component)scrollRect.content).GetComponent<ContentSizeFitter>().SetLayoutVertical();
				scrollRect.verticalNormalizedPosition = 0f;
			}
			ResetFadeTimer();
		}

		private void UpdateFade(float deltaTime)
		{
			fadeTimer -= deltaTime;
			if (Object.op_Implicit((Object)(object)fadeGroup))
			{
				if (Object.op_Implicit((Object)(object)ChatBox.instance) && ChatBox.instance.showInput)
				{
					ResetFadeTimer();
				}
				else if (fadeTimer < 0f)
				{
					alpha = 0f;
				}
				else if (fadeTimer < fadeDuration)
				{
					alpha = Mathf.Sqrt(Util.Remap(fadeTimer, fadeDuration, 0f, 1f, 0f));
				}
				else
				{
					alpha = 1f;
				}
				fadeGroup.alpha = alpha;
			}
		}

		private void ResetFadeTimer()
		{
			alpha = 1f;
			fadeTimer = fadeDuration + fadeWait;
		}

		private void Update()
		{
			UpdateFade(Time.deltaTime);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}