Decompiled source of RadarTowerAlert v1.0.0

plugins/RadarTowerAlert.dll

Decompiled a day 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 Microsoft.CodeAnalysis;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("RadarTowerAlert")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3530f1a75a4f6ac0bdf23428feaf9cc6a2636cda")]
[assembly: AssemblyProduct("RadarTowerAlert")]
[assembly: AssemblyTitle("RadarTowerAlert")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 RadarTowerAlert
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("com.hunex.radartoweralert", "RadarTowerAlert", "1.0.0")]
	public class RadarTowerAlertPlugin : BaseUnityPlugin
	{
		private ConfigEntry<bool> enabledConfig;

		private ConfigEntry<bool> stageScanConfig;

		private ConfigEntry<bool> debugLoggingConfig;

		private ConfigEntry<bool> hotkeyEnabledConfig;

		private ConfigEntry<KeyCode> hotkeyConfig;

		private readonly string[] alertLines = new string[10] { "A carrier wave with nothing to carry.", "An empty channel has begun to whisper.", "The frequency is occupied. No one is transmitting.", "The frequency was empty a moment ago.", "The interference has a pattern. You recognize it.", "The signal was never meant for you.", "Silence, on a frequency that should not exist.", "The static changes when observed.", "The static is trying to tell you something.", "The transmission has no point of origin." };

		private string pendingMessage;

		private void Awake()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			enabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable RadarTowerAlert.");
			stageScanConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ScanOnStageStart", true, "Automatically check for Radar Towers after stage population.");
			hotkeyEnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableHotkey", false, "Enable the manual scan hotkey.");
			hotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Debug", "Hotkey", (KeyCode)289, "Key to manually scan for Radar Towers.");
			debugLoggingConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogging", false, "Log scan results to the BepInEx console.");
			Stage.onStageStartGlobal += OnStageStart;
			SceneDirector.onPostPopulateSceneServer += OnScenePopulated;
			ChatBox.OnEnable += new hook_OnEnable(ChatBox_OnEnable);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RadarTowerAlert loaded.");
		}

		private void OnDestroy()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Stage.onStageStartGlobal -= OnStageStart;
			SceneDirector.onPostPopulateSceneServer -= OnScenePopulated;
			ChatBox.OnEnable -= new hook_OnEnable(ChatBox_OnEnable);
		}

		private void Update()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (enabledConfig.Value && hotkeyEnabledConfig.Value && Input.GetKeyDown(hotkeyConfig.Value))
			{
				ScanForRadarTowers(manual: true);
			}
		}

		private void OnStageStart(Stage stage)
		{
			if (debugLoggingConfig.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Stage started: " + stage.sceneDef.baseSceneName));
			}
		}

		private void OnScenePopulated(SceneDirector director)
		{
			if (enabledConfig.Value && stageScanConfig.Value)
			{
				ScanForRadarTowers(manual: false);
			}
		}

		private void ChatBox_OnEnable(orig_OnEnable orig, ChatBox self)
		{
			orig.Invoke(self);
			if (!string.IsNullOrEmpty(pendingMessage))
			{
				Chat.AddMessage(pendingMessage);
				pendingMessage = null;
			}
		}

		private void ScanForRadarTowers(bool manual)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (!enabledConfig.Value)
			{
				return;
			}
			int num = 0;
			GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
			foreach (GameObject val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Scene scene = val.scene;
				if (!((Scene)(ref scene)).IsValid() || !val.activeInHierarchy)
				{
					continue;
				}
				string name = ((Object)val).name;
				if (name.IndexOf("RadarTower", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Radar Tower", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					num++;
					if (debugLoggingConfig.Value)
					{
						ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
						string[] obj = new string[5] { "Radar candidate: ", name, " (scene: ", null, null };
						scene = val.scene;
						obj[3] = ((Scene)(ref scene)).name;
						obj[4] = ")";
						logger.LogInfo((object)string.Concat(obj));
					}
				}
			}
			if (debugLoggingConfig.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Scan complete. Matches: " + num + "; Manual: " + manual));
			}
			AlertInChat(manual, num != 0);
		}

		private void AlertInChat(bool manual, bool found)
		{
			string text = "[RadarTowerAlert] ";
			string text2 = null;
			if (found)
			{
				text2 = alertLines[Random.Range(0, alertLines.Length)];
			}
			else if (manual)
			{
				text2 = "No carrier detected. The silence is deliberate.";
			}
			if (!string.IsNullOrEmpty(text2))
			{
				if (manual)
				{
					Chat.AddMessage(text + text2);
				}
				else
				{
					pendingMessage = text + text2;
				}
			}
		}
	}
}