Decompiled source of seneaL LiveMarks BugFix v1.0.0

seneaL_LiveMarks_BugFix.dll

Decompiled 6 hours 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("seneaL_LiveMarks_BugFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("seneaL_LiveMarks_BugFix")]
[assembly: AssemblyTitle("seneaL_LiveMarks_BugFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SeneaLUI.LiveMarksSafety;

[BepInPlugin("avesatanas.senealui.livemarksbugfix", "SeneaL LiveMarks Bug Fix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	private const string Guid = "avesatanas.senealui.livemarksbugfix";

	private static ManualLogSource Log;

	private static readonly Type LiveMarks = AccessTools.TypeByName("SeneaLUI.Map.LiveMarks");

	private static readonly Type Track = AccessTools.TypeByName("SeneaLUI.Map.LiveMarks+Track");

	private static readonly FieldInfo Tracks = ((LiveMarks == null) ? null : AccessTools.Field(LiveMarks, "Tracks"));

	private static readonly FieldInfo Pin = ((Track == null) ? null : AccessTools.Field(Track, "Pin"));

	private static readonly MethodInfo Clear = ((Tracks == null) ? null : AccessTools.Method(Tracks.FieldType, "Clear", (Type[])null, (Type[])null));

	private static readonly MethodInfo RemovePin = AccessTools.Method(typeof(Minimap), "RemovePin", new Type[1] { typeof(PinData) }, (Type[])null);

	private void Awake()
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		MethodInfo methodInfo = AccessTools.Method(typeof(Player), "SetLocalPlayer", (Type[])null, (Type[])null);
		if (Tracks == null || Pin == null || Clear == null || RemovePin == null || methodInfo == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"SeneaL LiveMarks contract not found; bug fix disabled.");
			return;
		}
		HarmonyMethod val = new HarmonyMethod(typeof(Plugin), "ClearStaleTracks", (Type[])null);
		val.priority = 800;
		val.before = new string[1] { "seneaL.valheim.ui" };
		HarmonyMethod val2 = val;
		new Harmony("avesatanas.senealui.livemarksbugfix").Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"SeneaL LiveMarks bug fix enabled.");
	}

	private static void ClearStaleTracks()
	{
		try
		{
			List<PinData> list = new List<PinData>();
			foreach (object item in (IEnumerable)Tracks.GetValue(null))
			{
				object value = item.GetType().GetProperty("Value").GetValue(item, null);
				object? value2 = Pin.GetValue(value);
				PinData val = (PinData)((value2 is PinData) ? value2 : null);
				if (val != null)
				{
					list.Add(val);
				}
			}
			Clear.Invoke(Tracks.GetValue(null), null);
			Minimap instance = Minimap.instance;
			if (!((Object)(object)instance != (Object)null))
			{
				return;
			}
			foreach (PinData item2 in list)
			{
				instance.RemovePin(item2);
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("LiveMarks bug-fix cleanup failed: " + ex));
		}
	}
}