Decompiled source of BetterCompass v1.0.2

Mods/BetterCompass.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BetterCompass;
using HarmonyLib;
using Il2CppScheduleOne.UI.Compass;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(BetterCompassMod), "BetterCompass", "1.0.0", "Barvaz", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[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 BetterCompass
{
	public class BetterCompassMod : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Melon<BetterCompassMod>.Logger.Msg("Initialized BetterCompass");
		}
	}
}
namespace BetterCompass.Patches
{
	[HarmonyPatch]
	public class CompassPatch
	{
		private const float MinAlpha = 0.1f;

		private static bool IsElementActive(Element e)
		{
			if (e.Visible)
			{
				return e.Transform != null;
			}
			return false;
		}

		[HarmonyPatch(typeof(CompassManager), "UpdateElements")]
		[HarmonyPrefix]
		private static bool UpdateElementsPrefix(CompassManager __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<float, int> dictionary = new Dictionary<float, int>();
			List<(Element, float, float)> list = new List<(Element, float, float)>();
			Vector3 position = __instance.cam.position;
			Enumerator<Element> enumerator = __instance.elements.GetEnumerator();
			float num = default(float);
			float num2 = default(float);
			while (enumerator.MoveNext())
			{
				Element current = enumerator.Current;
				if (!IsElementActive(current))
				{
					SetInactiveElement(current);
					continue;
				}
				__instance.GetCompassData(current.Transform.position, ref num, ref num2);
				num2 = Mathf.Max(0.1f, num2);
				list.Add((current, num, num2));
				if (Mathf.Approximately(num2, 0.1f))
				{
					dictionary[num] = ((!dictionary.TryGetValue(num, out var value)) ? 1 : (value + 1));
				}
			}
			foreach (var (element, num3, num4) in list)
			{
				UpdateElement(element, position, num3, num4, Mathf.Approximately(num4, 0.1f) && dictionary[num3] > 1);
			}
			return false;
		}

		[HarmonyPatch(typeof(CompassManager), "UpdateElement")]
		[HarmonyPrefix]
		private static bool UpdateElementPrefix(CompassManager __instance, Element element)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (!IsElementActive(element))
			{
				SetInactiveElement(element);
				return false;
			}
			float xPos = default(float);
			float num = default(float);
			__instance.GetCompassData(element.Transform.position, ref xPos, ref num);
			UpdateElement(element, __instance.cam.position, xPos, Mathf.Max(0.1f, num), hideLabel: false);
			return false;
		}

		private static void UpdateElement(Element element, Vector3 cam, float xPos, float alpha, bool hideLabel)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			element.Group.alpha = alpha;
			element.Rect.anchoredPosition = new Vector2(xPos, 0f);
			((TMP_Text)element.DistanceLabel).text = (hideLabel ? "" : (Mathf.CeilToInt(Vector3.Distance(cam, element.Transform.position)) + "m"));
			((Component)element.Rect).gameObject.SetActive(true);
		}

		private static void SetInactiveElement(Element element)
		{
			element.Group.alpha = 0f;
			((Component)element.Rect).gameObject.SetActive(false);
		}
	}
}