Decompiled source of SuperDuperMappyZoomer v1.1.0

SuperDuperMappyZoomer.dll

Decompiled 2 months 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SuperDuperMappyZoomer
{
	[BepInPlugin("FoobyScroobs.SuperDuperMappyZoomer", "Super Duper Mappy Zoomer", "1.0.0")]
	public class SuperDuperMappyZoomerPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Minimap))]
		public static class MinimapPatches
		{
			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			public static void Awake_Postfix(Minimap __instance)
			{
				Debug.Log((object)"=== Minimap.Awake Patch Fired ===");
				__instance.m_maxZoom = maxZoomLimit;
				__instance.m_minZoom = minZoomLimit;
				Debug.Log((object)"Applied zoom limits via Harmony patch");
			}
		}

		private static ConfigEntry<float> zoomOutMultiplierConfig;

		private static ConfigEntry<float> zoomInMultiplierConfig;

		private static ConfigEntry<bool> showZoomInfoConfig;

		private const float defaultMaxZoom = 1f;

		private const float defaultMinZoom = 0.01f;

		private static float maxZoomLimit = 1f;

		private static float minZoomLimit = 0.01f;

		private static bool showZoomInfo = false;

		private Harmony harmony;

		private static bool minimapFound = false;

		private static float lastLoggedZoom = 0f;

		private void Awake()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			zoomInMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zoom Settings", "ZoomInMultiplier", 100f, "How much closer you can zoom IN compared to default. 1 = original setting, 100 = 100x closer, etc.");
			zoomOutMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zoom Settings", "ZoomOutMultiplier", 1f, "How much further you can zoom OUT compared to default. 1 = original setting, 2 = 2x further, etc.");
			showZoomInfoConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "ShowZoomInfo", false, "Show zoom level in console when zooming. WARNING: verbose -- logs every 'tick' of the scroll wheel!");
			float num = Mathf.Clamp(zoomOutMultiplierConfig.Value, 1f, 1000f);
			float num2 = Mathf.Clamp(zoomInMultiplierConfig.Value, 1f, 10000f);
			maxZoomLimit = 1f * num;
			minZoomLimit = 0.01f / num2;
			if (minZoomLimit <= 0f)
			{
				minZoomLimit = 0.0001f;
			}
			showZoomInfo = showZoomInfoConfig.Value;
			harmony = new Harmony("FoobyScroobs.SuperDuperMappyZoomer");
			harmony.PatchAll(typeof(MinimapPatches));
			Debug.Log((object)"=== Super Duper Mappy Zoomer v1.0.0 Loaded ===");
			Debug.Log((object)$"Config - Zoom out: {num}x, Zoom in: {num2}x");
			Debug.Log((object)$"Technical limits - Max: {maxZoomLimit}, Min: {minZoomLimit}");
			Debug.Log((object)$"Zoom info logging: {showZoomInfo}");
			if (zoomOutMultiplierConfig.Value != num)
			{
				Debug.LogWarning((object)$"ZoomOutMultiplier clamped from {zoomOutMultiplierConfig.Value} to {num}");
			}
			if (zoomInMultiplierConfig.Value != num2)
			{
				Debug.LogWarning((object)$"ZoomInMultiplier clamped from {zoomInMultiplierConfig.Value} to {num2}");
			}
		}

		private void Update()
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Invalid comparison between Unknown and I4
			if (!minimapFound && (Object)(object)Minimap.instance != (Object)null)
			{
				minimapFound = true;
				Debug.Log((object)"=== Minimap Found - Applying Zoom Limits ===");
				Debug.Log((object)$"Default Valheim limits - Min: {0.01f}, Max: {1f}");
				Debug.Log((object)$"Original limits - Min: {Minimap.instance.m_minZoom}, Max: {Minimap.instance.m_maxZoom}");
				Minimap.instance.m_maxZoom = maxZoomLimit;
				Minimap.instance.m_minZoom = minZoomLimit;
				Debug.Log((object)$"New limits - Min: {Minimap.instance.m_minZoom}, Max: {Minimap.instance.m_maxZoom}");
				float num = 0.01f / minZoomLimit;
				float num2 = maxZoomLimit / 1f;
				Debug.Log((object)$"You can now zoom IN {num:F0}x closer and OUT {num2:F0}x further!");
			}
			if (!showZoomInfo || !((Object)(object)Minimap.instance != (Object)null) || (int)Minimap.instance.m_mode != 2)
			{
				return;
			}
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (Mathf.Abs(axis) > 0.01f)
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(Minimap), "m_largeZoom");
				float num3 = (float)fieldInfo.GetValue(Minimap.instance);
				float num4 = 1f / num3;
				float num5 = 0.01f / num3;
				float num6 = num3 / 0.01f;
				string text = ((axis > 0f) ? "IN" : "OUT");
				string text2 = "";
				if (Mathf.Abs(num3 - lastLoggedZoom) < 1E-05f)
				{
					text2 = " [NO CHANGE - Limit reached?]";
				}
				else
				{
					lastLoggedZoom = num3;
				}
				if (num3 <= 0.01f)
				{
					Debug.Log((object)$"Scroll {text}: Zoom: {num3:F4} (Mag: {num4:F1}x) - {num5:F1}x closer{text2}");
				}
				else
				{
					Debug.Log((object)$"Scroll {text}: Zoom: {num3:F4} (Mag: {num4:F1}x) - {num6:F1}x further{text2}");
				}
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchAll("FoobyScroobs.SuperDuperMappyZoomer");
			}
		}
	}
}