Decompiled source of IwotasticsCompassMod v1.3.0

IwotasticsCompassMod.dll

Decompiled 5 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 TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("IwotasticsCompassMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A simple Lethal Company mod that adds a compass to the top of the screen, so you don't get as lost.")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+45081b83b36a93f289e3f8ecc85987b584b60b22")]
[assembly: AssemblyProduct("IwotasticsCompassMod")]
[assembly: AssemblyTitle("IwotasticsCompassMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 IwotasticsCompassMod
{
	public class HUDCompassBehaviour : MonoBehaviour
	{
		private TextMeshProUGUI tmpText;

		public TMP_FontAsset compassFontAsset;

		private const string COMPASS_STRING = "|--:--N--:--|--:--E--:--|--:--S--:--|--:--W--:--|--:--N--:--|";

		private const int COMPASS_WINDOW = 13;

		private const float COMPASS_STEP_SIZE = 7.5f;

		private void Start()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			tmpText = ((Component)this).gameObject.AddComponent<TextMeshProUGUI>();
			((Graphic)tmpText).color = Color.green;
			((TMP_Text)tmpText).fontSize = 24f;
			((TMP_Text)tmpText).alignment = (TextAlignmentOptions)514;
			if ((Object)(object)compassFontAsset != (Object)null)
			{
				((TMP_Text)tmpText).font = compassFontAsset;
			}
			Debug.Log((object)"Compass loaded!");
		}

		private void Update()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Vector3 forward = ((Component)GameNetworkManager.Instance.localPlayerController.turnCompassCamera).transform.forward;
			float x = forward.x;
			float z = forward.z;
			float num = 360f - (Mathf.Atan2(z, x) * 57.29578f + 180f);
			int startIndex = Mathf.FloorToInt((num + 3.75f) / 7.5f);
			((TMP_Text)tmpText).text = "|--:--N--:--|--:--E--:--|--:--S--:--|--:--W--:--|--:--N--:--|".Substring(startIndex, 13);
		}
	}
	public class HUDManagerHooks
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "Start")]
		private static void StartHook(ref HUDManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject();
			val.transform.SetParent(__instance.HUDContainer.transform, false);
			Vector3 localPosition = default(Vector3);
			((Vector3)(ref localPosition))..ctor(Plugin.CompassPosX.Value, Plugin.CompassPosY.Value, 0f);
			val.transform.localPosition = localPosition;
			HUDCompassBehaviour hUDCompassBehaviour = val.AddComponent<HUDCompassBehaviour>();
			hUDCompassBehaviour.compassFontAsset = (((Object)(object)__instance.weightCounter == (Object)null) ? null : ((TMP_Text)__instance.weightCounter).font);
			if (Plugin.ShouldMoveClockDown.Value)
			{
				Vector3 localPosition2 = default(Vector3);
				((Vector3)(ref localPosition2))..ctor(Plugin.CompassPosX.Value, Plugin.CompassPosY.Value + 8f, 0f);
				val.transform.localPosition = localPosition2;
				Transform transform = ((Component)__instance.Clock.canvasGroup).transform;
				Vector3 localPosition3 = transform.localPosition;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(localPosition3.x, localPosition3.y - 27f, localPosition3.z);
				Debug.Log((object)$"Set clock position to {val2}");
				transform.localPosition = val2;
			}
		}
	}
	[BepInPlugin("IwotasticsCompassMod", "IwotasticsCompassMod", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<float> CompassPosX;

		public static ConfigEntry<float> CompassPosY;

		public static ConfigEntry<bool> ShouldMoveClockDown;

		private void Awake()
		{
			CompassPosX = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CompassPosX", 0f, "X coordinate of the compass position (0 means it's in the center of the screen)");
			CompassPosY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CompassPosY", 185f, "Y coordinate of the compass position (0 means it's in the center of the screen)");
			ShouldMoveClockDown = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShouldMoveClockDown", true, "Push the clock down a little so that the compass doesn't clip over it");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin IwotasticsCompassMod (v1.3.0) was loaded successfully.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching compass into HUDManager...");
			Harmony.CreateAndPatchAll(typeof(HUDManagerHooks), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Finished patching HUDManager!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "IwotasticsCompassMod";

		public const string PLUGIN_NAME = "IwotasticsCompassMod";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}