Decompiled source of RepoChatPasteEnablerAndRepeatMessagerMod v1.0.3

plugins\REPO-Chat-Paste-Enabler-&-Repeat-Messager-Plugin.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Timers;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("REPO-Chat-Paste-Enabler-&-Repeat-Messager-Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("A mod from Arcane.")]
[assembly: AssemblyTitle("REPO-Chat-Paste-Enabler-&-Repeat-Messager-Plugin")]
[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 Root
{
	[BepInPlugin("arcane.plugin.repo.chat.paste.enabler.repeat.messager", "Chat Paste Enabler & Repeat Messager", "1.0.0")]
	[HarmonyPatch]
	internal class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "arcane.plugin.repo.chat.paste.enabler.repeat.messager";

		private const string PLUGIN_NAME = "Chat Paste Enabler & Repeat Messager";

		private const string PLUGIN_VERSION = "1.0.0";

		private const int MAX_ALLOWED_CHAT_MESSAGE_LENGTH = 50;

		private ConfigEntry<bool> allowPastingTextInChatWhenResultingMessageWillBeLongerThanMaxAllowedLengthConfigEntry;

		private ConfigEntry<string> toggleAutoMessageSenderKeybindConfigEntry;

		private ConfigEntry<string> messageToSendConfigEntry;

		private ConfigEntry<int> timeIntervalBetweenEachMessageInMsConfigEntry;

		private Timer autoMessageSenderTimer;

		private static Plugin instance;

		public ManualLogSource Logger => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"Loading...");
			instance = this;
			new Harmony("arcane.plugin.repo.chat.paste.enabler.repeat.messager").PatchAll();
			allowPastingTextInChatWhenResultingMessageWillBeLongerThanMaxAllowedLengthConfigEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowPastingTextInChatWhenResultingMessageWillBeLongerThanMaxAllowedLength", false, (ConfigDescription)null);
			string text = "F2";
			toggleAutoMessageSenderKeybindConfigEntry = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ToggleAutoMessageSenderKeybind", text, "This option can be used to set the keybind to enable/disable the auto message sender which repeatedly sends a user-specified message via chat.");
			if (!Enum.GetNames(typeof(KeyCode)).Contains(toggleAutoMessageSenderKeybindConfigEntry.Value))
			{
				Logger.LogError((object)("An invalid toggle auto message sender keybind was specified. Falling back to default value: '" + text + "'."));
				toggleAutoMessageSenderKeybindConfigEntry.Value = text;
			}
			messageToSendConfigEntry = ((BaseUnityPlugin)this).Config.Bind<string>("General", "MessageToSend", "/gamble 4000", "This option can be used to set the message that is sent via chat when the auto message sender is enabled.");
			timeIntervalBetweenEachMessageInMsConfigEntry = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TimeIntervalBetweenEachMessageInMs", 2000, "This option can be used to set the number of milliseconds between each message sent by the auto message sender.");
			autoMessageSenderTimer = new Timer(timeIntervalBetweenEachMessageInMsConfigEntry.Value);
			autoMessageSenderTimer.Elapsed += OnAutoMessageSenderTimerElapsed;
			Logger.LogInfo((object)"Loaded successfully.");
		}

		private void OnAutoMessageSenderTimerElapsed(object source, ElapsedEventArgs e)
		{
			ChatManager.instance.AddLetterToChat(GUIUtility.systemCopyBuffer);
			ChatManager.instance.ForceConfirmChat();
		}

		[HarmonyPatch(typeof(ChatManager), "Update")]
		[HarmonyPostfix]
		private static void ChatManagerUpdatePostfixPatch(ChatManager __instance)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKey((KeyCode)306) && Input.GetKeyDown((KeyCode)118) && (instance.allowPastingTextInChatWhenResultingMessageWillBeLongerThanMaxAllowedLengthConfigEntry.Value || (!instance.allowPastingTextInChatWhenResultingMessageWillBeLongerThanMaxAllowedLengthConfigEntry.Value && __instance.chatMessage.Length + GUIUtility.systemCopyBuffer.Length <= 50)))
			{
				__instance.AddLetterToChat(GUIUtility.systemCopyBuffer);
			}
			if (Input.GetKeyDown((KeyCode)Enum.Parse(typeof(KeyCode), instance.toggleAutoMessageSenderKeybindConfigEntry.Value)))
			{
				if (instance.autoMessageSenderTimer.Enabled)
				{
					instance.Logger.LogInfo((object)"Disabled auto message sender.");
					instance.autoMessageSenderTimer.Stop();
				}
				else
				{
					instance.Logger.LogInfo((object)"Enabled auto message sender.");
					instance.autoMessageSenderTimer.Start();
				}
			}
		}
	}
}