Decompiled source of NoFreeMaps v1.0.0

NoFreeMaps.dll

Decompiled 3 weeks ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NoFreeMaps;

[BepInPlugin("com.custom.nofreemaps", "No Free Maps", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static bool AllowMap = false;

	public static bool MapLocked = false;

	public static float LockedZoom = 0f;

	public static Vector3 LockedOffset;

	public static FieldInfo f_largeZoom = AccessTools.Field(typeof(Minimap), "m_largeZoom");

	public static FieldInfo f_minZoom = AccessTools.Field(typeof(Minimap), "m_minZoom");

	public static FieldInfo f_mapOffset = AccessTools.Field(typeof(Minimap), "m_mapOffset");

	private void Awake()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"No Free Maps: map only via Vegvisir or Cartography Table");
		new Harmony("com.custom.nofreemaps").PatchAll();
	}

	public static void OpenMapFromVegvisir()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		Minimap instance = Minimap.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			AllowMap = true;
			instance.SetMapMode((MapMode)2);
			float num = (float)f_minZoom.GetValue(instance);
			f_largeZoom.SetValue(instance, num);
			LockedZoom = num;
			LockedOffset = (Vector3)f_mapOffset.GetValue(instance);
			MapLocked = true;
			AllowMap = false;
		}
	}

	public static void OpenMapFromTable()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		Minimap instance = Minimap.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			AllowMap = true;
			instance.SetMapMode((MapMode)2);
			LockedZoom = (float)f_largeZoom.GetValue(instance);
			LockedOffset = (Vector3)f_mapOffset.GetValue(instance);
			MapLocked = true;
			AllowMap = false;
		}
	}
}
[HarmonyPatch(typeof(Minimap), "SetMapMode")]
internal static class PatchSetMapMode
{
	private static bool Prefix(MapMode mode)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		if ((int)mode == 2 && !Plugin.AllowMap)
		{
			return false;
		}
		if ((int)mode != 2)
		{
			Plugin.MapLocked = false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(Minimap), "UpdateMap")]
internal static class PatchUpdateMap
{
	private static void Prefix(ref bool takeInput)
	{
		if (Plugin.MapLocked)
		{
			takeInput = false;
		}
	}

	private static void Postfix(Minimap __instance)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.MapLocked)
		{
			Plugin.f_largeZoom.SetValue(__instance, Plugin.LockedZoom);
			Plugin.f_mapOffset.SetValue(__instance, Plugin.LockedOffset);
		}
	}
}
[HarmonyPatch(typeof(Vegvisir), "Interact")]
internal static class PatchVegvisir
{
	private static void Prefix()
	{
		Plugin.AllowMap = true;
	}

	private static void Postfix(bool __result)
	{
		if (__result)
		{
			Plugin.OpenMapFromVegvisir();
		}
		Plugin.AllowMap = false;
	}
}
[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
{
	typeof(Switch),
	typeof(Humanoid),
	typeof(ItemData)
})]
internal static class PatchMapTableRead
{
	private static void Postfix()
	{
		Plugin.OpenMapFromTable();
	}
}
[HarmonyPatch(typeof(MapTable), "OnWrite", new Type[]
{
	typeof(Switch),
	typeof(Humanoid),
	typeof(ItemData)
})]
internal static class PatchMapTableWrite
{
	private static void Postfix()
	{
		Plugin.OpenMapFromTable();
	}
}