Decompiled source of PronounsIndicator v2.1.1

PronounsIndicator.dll

Decompiled 11 months 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using LC_API.ClientAPI;
using LC_API.GameInterfaceAPI.Features;
using LC_API.Networking;
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("PronounsIndicator")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds pronouns to the username")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PronounsIndicator")]
[assembly: AssemblyTitle("PronounsIndicator")]
[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 PronounsIndicator
{
	[BepInPlugin("faejr.pronounsindicator", "Pronouns Indicator", "2.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "faejr.pronounsindicator";

		public const string ModName = "Pronouns Indicator";

		public const string ModVersion = "2.1.0";

		public static ManualLogSource logger;

		public static ConfigEntry<string> pronouns;

		public static bool Initialized { get; private set; }

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin faejr.pronounsindicator is loaded!");
			Initialized = false;
			pronouns = ((BaseUnityPlugin)this).Config.Bind<string>("pronouns", "pronouns", "", (ConfigDescription)null);
			CommandHandler.RegisterCommand("pronouns", (Action<string[]>)delegate(string[] args)
			{
				if (args.Length != 0 && args[0].Contains("/") && args[0].Length < 19)
				{
					((ConfigEntryBase)pronouns).SetSerializedValue(args[0]);
					PronounManager.SendPronouns();
				}
			});
		}

		internal void Start()
		{
			Initialize();
		}

		internal void OnDestroy()
		{
			Initialize();
		}

		private void Initialize()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (!Initialized)
			{
				Initialized = true;
				GameObject val = new GameObject("PronounIndicator");
				Object.DontDestroyOnLoad((Object)(object)val);
				val.AddComponent<PronounManager>();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Pronoun Manager Started!");
				Network.RegisterAll(typeof(PronounManager));
			}
		}
	}
	internal class PronounManager : MonoBehaviour
	{
		private const string SIG_SEND_PRONOUNS = "PronounIndicatorSendPronouns";

		private const string SIG_REQ_PRONOUNS = "PronounIndicatorRequestPronouns";

		private static int playerCount;

		private static float lobbyCheckTimer = 0f;

		private static bool checkPronouns = true;

		public void Update()
		{
			if ((Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				if (playerCount < GameNetworkManager.Instance.connectedPlayers)
				{
					lobbyCheckTimer = -4.5f;
					checkPronouns = true;
				}
				playerCount = GameNetworkManager.Instance.connectedPlayers;
			}
			if (lobbyCheckTimer < 0f)
			{
				lobbyCheckTimer += Time.deltaTime;
			}
			else if (checkPronouns && (Object)(object)HUDManager.Instance != (Object)null)
			{
				checkPronouns = false;
				Plugin.logger.LogInfo((object)"Requesting pronouns...");
				RequestPronouns();
				SendPronouns();
			}
		}

		[NetworkMessage("PronounIndicatorSendPronouns", false)]
		public static void ReceivedPronounsHandler(ulong senderId, string pronouns)
		{
			Plugin.logger.LogInfo((object)$"{senderId}: {pronouns}");
			AddPronounsToBillboardText(senderId, pronouns);
		}

		public static void AddPronounsToBillboardText(ulong senderId, string pronouns)
		{
			string playerUsername = StartOfRound.Instance.allPlayerScripts[senderId].playerUsername;
			((TMP_Text)Player.Get(senderId).PlayerController.usernameBillboardText).text = playerUsername + "<br>(" + pronouns + ")";
		}

		[NetworkMessage("PronounIndicatorRequestPronouns", false)]
		public static void RequestPronounsHandler(ulong senderId)
		{
			Plugin.logger.LogInfo((object)$"{senderId} requested pronouns");
			SendPronouns();
		}

		public static void SendPronouns()
		{
			string value = Plugin.pronouns.Value;
			if (!Utility.IsNullOrWhiteSpace(value))
			{
				Plugin.logger.LogInfo((object)"Sending pronouns...");
				Network.Broadcast<string>("PronounIndicatorSendPronouns", value);
			}
		}

		public static void RequestPronouns()
		{
			Network.Broadcast("PronounIndicatorRequestPronouns");
		}
	}
}