Decompiled source of SignalTranslatorDisplay v1.0.7

BepInEx/plugins/SignalTranslatorDisplay/uk.1a3.signaltranslatordisplay.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
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("uk.1a3.signaltranslatordisplay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+3f47650fcc2c4fd5370caaac13d8429ae0840d76")]
[assembly: AssemblyProduct("SignalTranslatorDisplay")]
[assembly: AssemblyTitle("uk.1a3.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("uk.1a3.signaltranslatordisplay", "SignalTranslatorDisplay", "1.0.7")]
	internal class PluginLoader : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("uk.1a3.signaltranslatordisplay");

		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
	{
		[CompilerGenerated]
		private sealed class <DisplayMessageCoroutine>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public int seed;

			public HUDManager __instance;

			public SignalTranslator signalTranslator;

			public string signalMessage;

			private Random <signalMessageRandom>5__2;

			private int <i>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DisplayMessageCoroutine>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<signalMessageRandom>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Expected O, but got Unknown
				//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b4: Expected O, but got Unknown
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<signalMessageRandom>5__2 = 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 = "";
					<>2__current = (object)new WaitForSeconds(1.21f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					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)
					{
						<i>5__3 = 0;
						goto IL_0255;
					}
					goto IL_026b;
				case 2:
					<>1__state = -1;
					<i>5__3++;
					goto IL_0255;
				case 3:
					{
						<>1__state = -1;
						__instance.signalTranslatorAnimator.SetBool("transmitting", false);
						return false;
					}
					IL_0255:
					if (<i>5__3 < signalMessage.Length && !((Object)(object)signalTranslator == (Object)null) && ((Component)signalTranslator).gameObject.activeSelf)
					{
						__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>5__3];
						float num = Mathf.Min((float)<signalMessageRandom>5__2.Next(-1, 4) * 0.5f, 0f);
						<>2__current = (object)new WaitForSeconds(0.7f + num);
						<>1__state = 2;
						return true;
					}
					goto IL_026b;
					IL_026b:
					if ((Object)(object)signalTranslator != (Object)null)
					{
						__instance.UIAudio.PlayOneShot(signalTranslator.finishTypingSFX);
						signalTranslator.localAudio.Stop();
					}
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 3;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		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;
		}

		[IteratorStateMachine(typeof(<DisplayMessageCoroutine>d__2))]
		private static IEnumerator DisplayMessageCoroutine(HUDManager __instance, string signalMessage, int seed, SignalTranslator signalTranslator)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DisplayMessageCoroutine>d__2(0)
			{
				__instance = __instance,
				signalMessage = signalMessage,
				seed = seed,
				signalTranslator = signalTranslator
			};
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "uk.1a3.signaltranslatordisplay";

		public const string PLUGIN_NAME = "SignalTranslatorDisplay";

		public const string PLUGIN_VERSION = "1.0.7";
	}
}