Decompiled source of BossFinder v1.0.0

BossFinder.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Splatform;
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("BossFinder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BossFinder")]
[assembly: AssemblyTitle("BossFinder")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BossFinder
{
	[BepInPlugin("zenox.bossfinder", "BossFinder", "1.0.0")]
	public class BossFinderPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "zenox.bossfinder";

		public const string PluginName = "BossFinder";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<float> UpdateInterval;

		private static readonly (string GlobalKey, string LocationName, string DisplayName)[] BossProgression = new(string, string, string)[7]
		{
			("defeated_eikthyr", "Eikthyrnir", "Eikthyr"),
			("defeated_gdking", "GDKing", "The Elder"),
			("defeated_bonemass", "Bonemass", "Bonemass"),
			("defeated_dragon", "Dragonqueen", "Moder"),
			("defeated_goblinking", "GoblinKing", "Yagluth"),
			("defeated_queen", "Mistlands_DvergrBossEntrance1", "The Queen"),
			("defeated_fader", "FaderLocation", "Fader")
		};

		private string currentBossTarget;

		private PinData pin;

		private Minimap pinOwner;

		private float timer;

		private bool loggedMissingLocation;

		private void Awake()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			ConfigLogDump.Schedule((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Logger);
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Shows a pin on the map and compass for the next boss in progression order, even if you haven't found its altar yet.");
			UpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "UpdateInterval", 5f, new ConfigDescription("Seconds between checks for the next boss.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BossFinder v1.0.0 loaded.");
		}

		private void Start()
		{
			ConfigEntry<bool> val = default(ConfigEntry<bool>);
			if (Chainloader.PluginInfos.TryGetValue("zenox.zenox", out var value) && (Object)(object)value.Instance != (Object)null && value.Instance.Config.TryGetEntry<bool>("BossFinder", "Enabled", ref val) && val.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[BossFinder] Zenox's built-in Boss Finder is on - this mod stays idle to avoid a second pin.");
				Enabled.Value = false;
			}
		}

		private void Update()
		{
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)Minimap.instance == (Object)null)
			{
				pin = null;
				pinOwner = null;
				currentBossTarget = null;
				return;
			}
			if ((Object)(object)pinOwner != (Object)(object)Minimap.instance)
			{
				pin = null;
				pinOwner = Minimap.instance;
				currentBossTarget = null;
			}
			timer += Time.deltaTime;
			if (timer < UpdateInterval.Value)
			{
				return;
			}
			timer = 0f;
			string text = null;
			string text2 = null;
			(string, string, string)[] bossProgression = BossProgression;
			for (int i = 0; i < bossProgression.Length; i++)
			{
				(string, string, string) tuple = bossProgression[i];
				if (!ZoneSystem.instance.GetGlobalKey(tuple.Item1))
				{
					text = tuple.Item3;
					text2 = tuple.Item2;
					break;
				}
			}
			if (text != currentBossTarget)
			{
				currentBossTarget = text;
				if (pin != null)
				{
					Minimap.instance.RemovePin(pin);
					pin = null;
				}
				if (text != null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[BossFinder] Next boss: " + text + "."));
				}
			}
			if (text == null || pin != null)
			{
				return;
			}
			LocationInstance val = default(LocationInstance);
			if (!ZoneSystem.instance.FindClosestLocation(text2, ((Component)localPlayer).transform.position, ref val))
			{
				if (!loggedMissingLocation)
				{
					loggedMissingLocation = true;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("[BossFinder] Could not find location '" + text2 + "' for '" + text + "' - the prefab name may differ in this game version."));
				}
			}
			else
			{
				pin = Minimap.instance.AddPin(val.m_position, (PinType)9, text, false, false, 0L, default(PlatformUserID));
			}
		}

		private void OnDestroy()
		{
			if (pin != null && (Object)(object)Minimap.instance != (Object)null)
			{
				Minimap.instance.RemovePin(pin);
			}
		}
	}
	internal static class ConfigLogDump
	{
		internal static void Schedule(BaseUnityPlugin plugin, ManualLogSource log)
		{
			((MonoBehaviour)plugin).StartCoroutine(Run(plugin, log));
		}

		private static IEnumerator Run(BaseUnityPlugin plugin, ManualLogSource log)
		{
			yield return null;
			yield return null;
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (ConfigDefinition key in plugin.Config.Keys)
				{
					string text = key.Key.ToLowerInvariant();
					if (text.Contains("pass") || text.Contains("token") || text.Contains("secret"))
					{
						continue;
					}
					ConfigEntryBase val = plugin.Config[key];
					if (!object.Equals(val.BoxedValue, val.DefaultValue))
					{
						if (stringBuilder.Length > 0)
						{
							stringBuilder.Append("; ");
						}
						stringBuilder.Append(key.Section).Append('.').Append(key.Key)
							.Append('=')
							.Append(val.BoxedValue);
						if (stringBuilder.Length > 1500)
						{
							stringBuilder.Append("; ...");
							break;
						}
					}
				}
				log.LogInfo((object)("[BossFinder] config (changed from default): " + ((stringBuilder.Length == 0) ? "none" : stringBuilder.ToString())));
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("[BossFinder] config dump failed: " + ex.Message));
			}
		}
	}
}