Decompiled source of ACompass revived v1.1.1

ACompass.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using ACompass.NetcodePatcher;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Friskzips.patch;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("ACompass")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3-alpha.0.2+8b2da66df728d4504593eb40d1802a75a0321995")]
[assembly: AssemblyProduct("ACompass")]
[assembly: AssemblyTitle("ACompass")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 Friskzips
{
	public class LethalConfigCompatibility
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
				}
				return _enabled.Value;
			}
		}

		internal static void initLethalConfig()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			EnumDropDownConfigItem<Plugin.configHudPosition> val = new EnumDropDownConfigItem<Plugin.configHudPosition>(Plugin.position, new EnumDropDownOptions
			{
				RequiresRestart = false
			});
			BoolCheckBoxConfigItem val2 = new BoolCheckBoxConfigItem(Plugin.oldTexture, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(Plugin.alignToShipRadar, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
			LethalConfigManager.SetModDescription("Original mod by alekso56");
			LethalConfigManager.SkipAutoGen();
		}
	}
	[BepInPlugin("Friskzips.ACompass", "ACompass revived", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public enum configHudPosition
		{
			Bottom,
			Top
		}

		private readonly Harmony _harmony = new Harmony("Friskzips.ACompass");

		public static Plugin Instance { get; set; }

		public static ConfigEntry<configHudPosition> position { get; private set; }

		public static ConfigEntry<bool> oldTexture { get; private set; }

		public static ConfigEntry<bool> alignToShipRadar { get; private set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0079: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00aa: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00db: Expected O, but got Unknown
			Log.LogInfo((object)"Applying patches...");
			ApplyPluginPatch();
			Log.LogInfo((object)"Patches applied!");
			Log.LogInfo((object)"Loading assets...");
			Friskzips.patch.ACompass.loadAssets();
			Log.LogInfo((object)"Loading config...");
			position = ((BaseUnityPlugin)this).Config.Bind<configHudPosition>(new ConfigDefinition("Hud", "Position"), configHudPosition.Bottom, new ConfigDescription("The compass position it can be Bottom or Top.\nDefault: Bottom", (AcceptableValueBase)null, Array.Empty<object>()));
			oldTexture = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Hud", "Old texture"), false, new ConfigDescription("If you want the old texture of the original mod.\nDefault: False", (AcceptableValueBase)null, Array.Empty<object>()));
			alignToShipRadar = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Hud", "Align to the ship monitor"), true, new ConfigDescription("If you want the compass to align to the ship monitor.\nDefault: True", (AcceptableValueBase)null, Array.Empty<object>()));
			Log.LogInfo((object)"Config loaded!");
			Log.LogDebug((object)"Looking for lethal config...");
			if (LethalConfigCompatibility.enabled)
			{
				Log.LogInfo((object)"LethalConfig found!");
				LethalConfigCompatibility.initLethalConfig();
			}
			Log.LogInfo((object)"ACompass revived loaded!");
			Log.LogInfo((object)"Original mod by alekso56");
		}

		private void ApplyPluginPatch()
		{
			_harmony.PatchAll(typeof(Friskzips.patch.ACompass));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Friskzips.ACompass";

		public const string PLUGIN_NAME = "ACompass revived";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace Friskzips.patch
{
	internal class ACompass : MonoBehaviour
	{
		public class CompassUpdater : MonoBehaviour
		{
			public RawImage CompassImage;

			public Transform toFollow;

			private RawImage m_RawImage;

			private readonly Texture m_TextureOld = (Texture)(object)CompassAssets.LoadAsset<Texture2D>("compass_shifted");

			private readonly Texture m_Texture = (Texture)(object)CompassAssets.LoadAsset<Texture2D>("compass_shifted2");

			public void setFollow(Transform user)
			{
				toFollow = user;
			}

			private void LateUpdate()
			{
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				UpdateCompassHeading();
				if (oldTexture != Plugin.oldTexture.Value || !firstTimeTexture)
				{
					oldTexture = Plugin.oldTexture.Value;
					firstTimeTexture = true;
					if (!Plugin.oldTexture.Value)
					{
						CompassImage.texture = m_Texture;
					}
					if (Plugin.oldTexture.Value)
					{
						CompassImage.texture = m_TextureOld;
					}
				}
				if (position != (int)Plugin.position.Value)
				{
					position = (int)Plugin.position.Value;
					if (position == 0)
					{
						((Component)this).transform.localPosition = new Vector3(0f, -224.4849f, 0f);
					}
					if (position == 1)
					{
						((Component)this).transform.localPosition = new Vector3(0f, 218.5156f, 0f);
					}
					Plugin.Log.LogDebug((object)("pos " + ((Component)this).transform.localPosition.x + ", " + ((Component)this).transform.localPosition.y + ", " + ((Component)this).transform.localPosition.z));
					Plugin.Log.LogDebug((object)("pos enum " + position));
				}
			}

			private void UpdateCompassHeading()
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)GameNetworkManager.Instance == (Object)null || (Object)(GameNetworkManager.Instance.localPlayerController?.turnCompassCamera) == (Object)null)
				{
					return;
				}
				toFollow = ((Component)GameNetworkManager.Instance.localPlayerController.turnCompassCamera).transform;
				if (!((Object)CompassImage == (Object)null) && !((Object)toFollow == (Object)null))
				{
					Quaternion val;
					if (Plugin.alignToShipRadar.Value)
					{
						Vector2 right = Vector2.right;
						Quaternion rotation = toFollow.rotation;
						val = rotation;
						Vector2 val2 = right * ((((Quaternion)(ref val)).eulerAngles.y + 45f - 45f) / 360f);
						CompassImage.uvRect = new Rect(val2, Vector2.one);
					}
					else
					{
						Vector2 right2 = Vector2.right;
						Quaternion rotation2 = toFollow.rotation;
						val = rotation2;
						Vector2 val3 = right2 * ((((Quaternion)(ref val)).eulerAngles.y - 45f) / 360f);
						CompassImage.uvRect = new Rect(val3, Vector2.one);
					}
				}
			}
		}

		private static CompassUpdater updater;

		public static AssetBundle CompassAssets;

		public static bool loaded = false;

		public static bool oldTexture = false;

		public static bool firstTimeTexture = false;

		public static int position = 69;

		public static void loadAssets()
		{
			if (!loaded)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				CompassAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "compass"));
				if ((Object)(object)CompassAssets == (Object)null)
				{
					Plugin.Log.LogError((object)"Failed to load AssetBundle!");
					return;
				}
				Plugin.Log.LogInfo((object)"AsssetBundle loaded!");
				loaded = true;
			}
		}

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPostfix]
		public static void AddCompass(HUDManager __instance)
		{
			//IL_007a: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = __instance.HUDContainer.transform;
			Debug.Log((object)("Attaching compass to :" + (object)transform));
			GameObject val = CompassAssets.LoadAsset<GameObject>("assets/compass/mask.prefab");
			GameObject val2 = Object.Instantiate<GameObject>(val);
			val2 = Object.Instantiate<GameObject>(val2, transform);
			updater = val2.AddComponent<CompassUpdater>();
			updater.CompassImage = ((Component)val2.transform.GetChild(0)).GetComponentInChildren<RawImage>();
			Plugin.Log.LogDebug((object)val2.transform.position.y);
			Transform val3 = val2.transform.Find("Compass");
			Transform val4 = ((Component)val3).transform.Find("Indicator");
			val4.position = new Vector3(val4.position.x, val4.position.y - 0.017f, val4.position.z);
			val4.localScale = new Vector3(val4.localScale.x - 0.5f, val4.localScale.y - 0.7f, val4.localScale.z);
			position = 69;
			firstTimeTexture = false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace ACompass.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}