Decompiled source of AntiNoLimitChatbox v1.0.1

plugins/AntiNoLimitChatbox/AntiNoLimitChatbox.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[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("AntiNoLimitChatbox")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AntiNoLimitChatbox")]
[assembly: AssemblyTitle("AntiNoLimitChatbox")]
[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 AntiNoLimitChatbox
{
	[BepInPlugin("AntiNoLimitChatbox", "Anti No Limit Chatbox", "1.0.0")]
	public class AntiNoLimitChatbox : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		private Harmony harmony;

		public static ConfigEntry<string> CharacterLimit;

		public static ConfigEntry<bool> OnlyTakeCharacterLimit;

		public static ConfigEntry<bool> FullyDisableChat;

		public static ConfigEntry<bool> ShamePlayer;

		public static ConfigEntry<string> ShameMessage;

		public 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("AntiNoLimitChatbox");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			Logger.LogInfo((object)"Anti No Limit Chatbox has loaded!");
			LoadConfig();
		}

		private void LoadConfig()
		{
			CharacterLimit = ((BaseUnityPlugin)this).Config.Bind<string>("Config", "CharacterLimit", "50", "Character limit that has to be hit before doing any actions!");
			OnlyTakeCharacterLimit = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "OnlyTakeCharacterLimit", true, "Will only take the amount the character limit is set to!");
			FullyDisableChat = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "FullyDisableChat", false, "Will fully disable the chat!");
			ShamePlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "ShamePlayer", true, "Will replace their message with the shame message!");
			ShameMessage = ((BaseUnityPlugin)this).Config.Bind<string>("Config", "ShameMessage", "I'm a big dummy", "Message sent to shame the user for being annoying!");
		}
	}
	public class PluginInfo
	{
		public const string PLUGIN_GUID = "AntiNoLimitChatbox";

		public const string PLUGIN_NAME = "Anti No Limit Chatbox";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AntiNoLimitChatbox.Patches
{
	[HarmonyPatch]
	public class PlayerAvatarPatches
	{
		private static List<string> GameMessages = new List<string>();

		[HarmonyPatch(typeof(ChatManager), "PossessChat")]
		[HarmonyPrefix]
		public static void PossessChat(PossessChatID _possessChatID, string message, float typingSpeed, Color _possessColor, float _messageDelay = 0f, bool sendInTaxmanChat = false, int sendInTaxmanChatEmojiInt = 0, UnityEvent eventExecutionAfterMessageIsDone = null)
		{
			GameMessages.Add(message);
		}

		[HarmonyPatch(typeof(PlayerAvatar), "ChatMessageSpeak")]
		[HarmonyPrefix]
		public static bool ChatMessageSpeak(ref string _message, bool crouching)
		{
			if (GameMessages.Contains(_message))
			{
				GameMessages.Remove(_message);
				return true;
			}
			if (AntiNoLimitChatbox.FullyDisableChat.Value)
			{
				return false;
			}
			if (AntiNoLimitChatbox.OnlyTakeCharacterLimit.Value)
			{
				_message = new string(_message.Take(int.Parse(AntiNoLimitChatbox.CharacterLimit.Value)).ToArray());
				return true;
			}
			if (_message.Length > int.Parse(AntiNoLimitChatbox.CharacterLimit.Value))
			{
				_message = AntiNoLimitChatbox.ShameMessage.Value;
				return AntiNoLimitChatbox.ShamePlayer.Value;
			}
			return true;
		}
	}
}