Decompiled source of Herald Tracker v0.2.0

plugins/kruft.HeraldTracker.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using HeraldTracker.Patches;
using Il2CppInterop.Runtime.InteropTypes;
using UISystem;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;
using WildSkies.AI;
using WildSkies.Gameplay.Items;
using Wildskies.UI.Hud;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("kruft.HeraldTracker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6ca02c5713aca5c9db1afcc368625e6da456c20a")]
[assembly: AssemblyProduct("kruft.HeraldTracker")]
[assembly: AssemblyTitle("kruft.HeraldTracker")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HeraldTracker
{
	[BepInPlugin("kruft.heraldtracker", "Herald Tracker", "0.2.0")]
	public class HeraldTrackerPlugin : BasePlugin
	{
		public static ManualLogSource log = Logger.CreateLogSource("Herald Tracker");

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("kruft.HeraldTracker");
			val.PatchAll(typeof(Tracker));
			if (((BasePlugin)this).Config.Bind<bool>("General", "Herald_Tracking", true, "Whether to track the herald.").Value)
			{
				val.PatchAll(typeof(HeraldTracker.Patches.HeraldTracker));
			}
			if (((BasePlugin)this).Config.Bind<bool>("General", "Whale_Tracking", true, "Whether to track whales.").Value)
			{
				val.PatchAll(typeof(WhaleTracker));
			}
		}
	}
}
namespace HeraldTracker.Patches
{
	internal class HeraldTracker
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(HeraldMovementController), "Start")]
		private static void AddHeraldToCompass(HeraldMovementController __instance)
		{
			Tracker.Track("HeraldTracker", ((Component)__instance).gameObject.transform);
			HeraldTrackerPlugin.log.LogInfo((object)"Added Herald to compass.");
		}
	}
	public class Tracker
	{
		public static CompassHud _compassHud;

		public static void Notify(string message, Sprite icon = null)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			NotificationHud val = Object.FindFirstObjectByType<NotificationHud>();
			if ((Object)(object)val == (Object)null)
			{
				HeraldTrackerPlugin.log.LogWarning((object)"Notify: NotificationHud not found.");
				return;
			}
			if ((Object)(object)_compassHud == (Object)null)
			{
				HeraldTrackerPlugin.log.LogWarning((object)"Notify: CompassHud not found.");
				return;
			}
			icon = icon ?? _compassHud._compassIconPrefab._pingIcon;
			((HudElement)val).Show(((Il2CppObjectBase)new NotificationHudPayload(icon, new LocalizedString(TableReference.op_Implicit("General"), TableEntryReference.op_Implicit("ok.label")), false, (InventoryRarityType)1, "", "", false)).Cast<IPayload>());
			val._currentNotification._message.text = message;
		}

		public static void Track(string name, Transform target)
		{
			if ((Object)(object)_compassHud == (Object)null)
			{
				HeraldTrackerPlugin.log.LogWarning((object)"Track: CompassHud not found.");
			}
			else
			{
				_compassHud.OnPingPlaced(name, target);
			}
		}

		public static void Untrack(Transform target)
		{
			if ((Object)(object)_compassHud == (Object)null)
			{
				HeraldTrackerPlugin.log.LogWarning((object)"Untrack: CompassHud not found.");
			}
			else
			{
				_compassHud.OnPingCleared(target);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CompassHud), "Start")]
		private static void CacheCompassHud(CompassHud __instance)
		{
			_compassHud = __instance;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CompassHud), "OnDestroy")]
		private static void ClearCompassHud(CompassHud __instance)
		{
			_compassHud = null;
		}
	}
	internal class WhaleTracker
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(SkyWhaleCritter), "Init")]
		private static void AddWhaleToCompass(SkyWhaleCritter __instance)
		{
			Tracker.Track(((Object)__instance).name, ((Component)__instance).transform);
			Tracker.Notify("A whale has been spotted!");
			HeraldTrackerPlugin.log.LogInfo((object)"Added whale to compass.");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SkyWhaleCritter), "OnDisable")]
		private static void RemoveWhaleFromCompass(SkyWhaleCritter __instance)
		{
			Tracker.Untrack(((Component)__instance).transform);
			Tracker.Notify("The whale slips into the clouds...");
			HeraldTrackerPlugin.log.LogInfo((object)"Removed whale from compass.");
		}
	}
}