Decompiled source of SignalTranslatorDisplay v1.0.5

BepInEx/plugins/SignalTranslatorDisplay/SignalTranslatorDisplay.dll

Decompiled 2 months ago
using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[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("SignalTranslatorDisplay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+e223274ccb5ad36d5e9232d1ca4237134ee26e63")]
[assembly: AssemblyProduct("SignalTranslatorDisplay")]
[assembly: AssemblyTitle("SignalTranslatorDisplay")]
[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 SignalTranslatorDisplay
{
	[BepInPlugin("Dev1A3.SignalTranslatorDisplay", "SignalTranslatorDisplay", "1.0.1")]
	internal class PluginLoader : BaseUnityPlugin
	{
		private const string modGUID = "Dev1A3.SignalTranslatorDisplay";

		private readonly Harmony harmony = new Harmony("Dev1A3.SignalTranslatorDisplay");

		private const string modVersion = "1.0.1";

		private static bool initialized;

		public static PluginLoader Instance { get; private set; }

		private void Awake()
		{
			if (!initialized)
			{
				initialized = true;
				Instance = this;
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				harmony.PatchAll(executingAssembly);
				SignalTranslatorConfig.InitConfig();
			}
		}

		public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
		{
			config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
		}
	}
	internal class SignalTranslatorConfig
	{
		public static ConfigEntry<bool> OriginalEnabled;

		public static ConfigEntry<bool> ChatEnabled;

		public static ConfigEntry<bool> TipEnabled;

		public static void InitConfig()
		{
			PluginLoader.Instance.BindConfig(ref OriginalEnabled, "Settings", "Default Popup", defaultValue: true, "Should the signal transmission be shown as the default popup?");
			PluginLoader.Instance.BindConfig(ref ChatEnabled, "Settings", "Chat Message", defaultValue: true, "Should the signal transmission be shown as a chat message?");
			PluginLoader.Instance.BindConfig(ref TipEnabled, "Settings", "Small Popup", defaultValue: false, "Should the signal transmission be shown as a small popup?");
		}
	}
	[HarmonyPatch]
	internal class Patch
	{
		private static MethodInfo AddChatMessage = AccessTools.Method(typeof(HUDManager), "AddChatMessage", (Type[])null, (Type[])null);

		[HarmonyPatch(typeof(HUDManager), "DisplaySignalTranslatorMessage")]
		[HarmonyPrefix]
		internal static bool DisplaySignalTranslatorMessage(ref IEnumerator __result, HUDManager __instance, string signalMessage, int seed, SignalTranslator signalTranslator)
		{
			if ((Object)(object)signalTranslator != (Object)null)
			{
				__result = DisplayMessageCoroutine(__instance, signalMessage, seed, signalTranslator);
			}
			return false;
		}

		private static IEnumerator DisplayMessageCoroutine(HUDManager __instance, string signalMessage, int seed, SignalTranslator signalTranslator)
		{
			Random signalMessageRandom = new Random(seed + StartOfRound.Instance.randomMapSeed);
			if (SignalTranslatorConfig.OriginalEnabled.Value)
			{
				__instance.signalTranslatorAnimator.SetBool("transmitting", true);
			}
			signalTranslator.localAudio.Play();
			__instance.UIAudio.PlayOneShot(signalTranslator.startTransmissionSFX, 1f);
			((TMP_Text)__instance.signalTranslatorText).text = "";
			yield return (object)new WaitForSeconds(1.21f);
			if ((Object)(object)signalTranslator != (Object)null)
			{
				string text = "Receiving Signal";
				if (SignalTranslatorConfig.ChatEnabled.Value)
				{
					AddChatMessage?.Invoke(__instance, new object[2] { signalMessage, text });
				}
				if (SignalTranslatorConfig.TipEnabled.Value)
				{
					((TMP_Text)__instance.tipsPanelHeader).text = text;
					((TMP_Text)__instance.tipsPanelBody).text = signalMessage;
					__instance.tipsPanelAnimator.SetTrigger("TriggerHint");
				}
			}
			if (SignalTranslatorConfig.OriginalEnabled.Value)
			{
				for (int i = 0; i < signalMessage.Length; i++)
				{
					if ((Object)(object)signalTranslator == (Object)null)
					{
						break;
					}
					if (!((Component)signalTranslator).gameObject.activeSelf)
					{
						break;
					}
					__instance.UIAudio.PlayOneShot(signalTranslator.typeTextClips[Random.Range(0, signalTranslator.typeTextClips.Length)]);
					TextMeshProUGUI signalTranslatorText = __instance.signalTranslatorText;
					((TMP_Text)signalTranslatorText).text = ((TMP_Text)signalTranslatorText).text + signalMessage[i];
					float num = Mathf.Min((float)signalMessageRandom.Next(-1, 4) * 0.5f, 0f);
					yield return (object)new WaitForSeconds(0.7f + num);
				}
			}
			if ((Object)(object)signalTranslator != (Object)null)
			{
				__instance.UIAudio.PlayOneShot(signalTranslator.finishTypingSFX);
				signalTranslator.localAudio.Stop();
			}
			yield return (object)new WaitForSeconds(0.5f);
			__instance.signalTranslatorAnimator.SetBool("transmitting", false);
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SignalTranslatorDisplay";

		public const string PLUGIN_NAME = "SignalTranslatorDisplay";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}