Decompiled source of ExitPointer v1.1.0

BepInEx/plugins/ExitPointer.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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitPointer.Utils;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExitPointer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+3d268640b07d3dbe77d181a2024d1bbc5d057b63")]
[assembly: AssemblyProduct("overfirec_ExitPointer")]
[assembly: AssemblyTitle("ExitPointer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ExitPointer
{
	internal class ExitPointerClass
	{
		private readonly GameObject _pointer;

		private RectTransform _rectTransform;

		internal bool isActive;

		internal ExitPointerClass(GameObject pointer)
		{
			_pointer = pointer ?? throw new ArgumentNullException("pointer");
			_rectTransform = _pointer.GetComponent<RectTransform>();
		}

		internal void SetDefaultStatus(Transform parent, Vector3 scale)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			_pointer.transform.SetParent(((Component)parent).transform, false);
			_pointer.transform.localScale = scale;
		}

		internal void SetActive(bool active)
		{
			_pointer.SetActive(active);
			isActive = active;
		}

		internal void MovePointer(Camera camera, Vector3 targetPosition, int ScreenWidth, int ScreenHeight)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			_rectTransform.anchoredPosition = CalculatePos(camera, targetPosition, new Vector2((float)ScreenWidth, (float)ScreenHeight), new Vector2((float)ScreenWidth / 2f, (float)ScreenHeight / 2f), new Vector2(430f, 210f));
		}

		internal void SetLocalScale(float x)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			_pointer.transform.localScale = new Vector3(x, x + 0.02f, 1f);
		}

		private Vector2 CalculatePos(Camera Cam, Vector3 TargetPosition, Vector2 ScreenSize, Vector2 ScreenCenter, Vector2 EllipticalRadius)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_009e: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(Cam.WorldToScreenPoint(TargetPosition));
			Vector3 forward = ((Component)Cam).transform.forward;
			Vector3 val2 = TargetPosition - ((Component)Cam).transform.position;
			bool flag = false;
			if (Vector3.Dot(forward, val2) <= 0f)
			{
				val.x = ScreenSize.x - val.x;
				val.y = ScreenSize.y - val.y;
				flag = true;
			}
			if (val.x < 0f || val.x > ScreenSize.x || val.y < 0f || val.y > ScreenSize.y)
			{
				flag = true;
			}
			val -= ScreenCenter;
			val.y /= ScreenSize.x / 860f;
			val.x /= ScreenSize.y / 520f;
			if (flag || Mathf.Pow(val.x / EllipticalRadius.x, 2f) + Mathf.Pow(val.y / EllipticalRadius.y, 2f) > 1f)
			{
				float num = Mathf.Sqrt(Mathf.Pow(EllipticalRadius.x * EllipticalRadius.y * val.x, 2f) / (Mathf.Pow(val.x * EllipticalRadius.y, 2f) + Mathf.Pow(EllipticalRadius.x * val.y, 2f)));
				if (Mathf.Sign(num) != Mathf.Sign(val.x))
				{
					num *= -1f;
				}
				float y = num * (val.y / val.x);
				val.x = num;
				val.y = y;
			}
			return val;
		}
	}
	[BepInPlugin("Overfirec.ExitPointer", "ExitPointer", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ExitPointerPluginRegister : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "Overfirec.ExitPointer";

		public const string PLUGIN_NAME = "ExitPointer";

		public const string PLUGIN_VERSION = "1.1.0";

		internal static ExitPointerPluginRegister? Instance;

		internal static ConfigEntry<float> pointerSize;

		private const string MainExitPointerFileName = "MainExitPointer";

		private const string FireExitPointerFileName = "FireExitPointer";

		private static Harmony? Harmony { get; set; }

		private static ManualLogSource? LOGSource { get; set; }

		internal static Tuple<Texture2D, Texture2D>? PointerTextures { get; private set; }

		private void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Instance = this;
			LOGSource = Logger.CreateLogSource("ExitPointer");
			Harmony = new Harmony("ExitPointer");
			TryLoadResource();
			Harmony.PatchAll();
			pointerSize = ((BaseUnityPlugin)this).Config.Bind<float>("ExitPointer Config", "PointerSize", 0.25f, "Pointer size");
			if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
			{
				ConfigManager.SetUpConfig();
			}
			Log("Overfirec.ExitPointer version: 1.1.0 successfully loaded!", (LogLevel)16);
		}

		private void Disable()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			ManualLogSource? lOGSource = LOGSource;
			if (lOGSource != null)
			{
				lOGSource.Dispose();
			}
			Instance = null;
			Log("ExitPointerPluginRegister disabled!", (LogLevel)16);
		}

		internal static void Log(string message, LogLevel level = 16)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (LOGSource == null)
			{
				Logger.CreateLogSource("overfirec_ExitPointer").LogError((object)"Log source not found!");
			}
			else
			{
				LOGSource.Log(level, (object)message);
			}
		}

		private void TryLoadResource()
		{
			try
			{
				Tuple<Texture2D, Texture2D> tuple = new Tuple<Texture2D, Texture2D>(ResourcesLoader.LoadResource("MainExitPointer"), ResourcesLoader.LoadResource("FireExitPointer"));
				if (tuple.Item1 == null || tuple.Item2 == null)
				{
					throw new NullReferenceException("Pointer texture can't be loaded!");
				}
				PointerTextures = tuple;
				Log("Resources loaded successfully!", (LogLevel)16);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.Log((LogLevel)2, (object)ex.Message);
				Disable();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ExitPointer";

		public const string PLUGIN_NAME = "overfirec_ExitPointer";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace ExitPointer.Utils
{
	public class ConfigManager
	{
		internal static void SetUpConfig()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_002c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			ConfigEntry<float> pointerSize = ExitPointerPluginRegister.pointerSize;
			FloatSliderOptions val = new FloatSliderOptions
			{
				RequiresRestart = false
			};
			((BaseRangeOptions<float>)val).Min = 0f;
			((BaseRangeOptions<float>)val).Max = 0.98f;
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(pointerSize, val);
			val2 = new FloatSliderConfigItem(ExitPointerPluginRegister.pointerSize, false);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
		}
	}
	public static class ResourcesLoader
	{
		private static byte[] ReadAllBytes(this Stream inStream)
		{
			if (inStream is MemoryStream memoryStream)
			{
				return memoryStream.ToArray();
			}
			using MemoryStream memoryStream2 = new MemoryStream();
			inStream.CopyTo(memoryStream2);
			return memoryStream2.ToArray();
		}

		internal static Texture2D? LoadResource(string resourceName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = executingAssembly.GetName().Name + ".Image." + resourceName + ".png";
				Texture2D val = new Texture2D(0, 0);
				ImageConversion.LoadImage(val, executingAssembly.GetManifestResourceStream(name).ReadAllBytes());
				return val;
			}
			catch (Exception ex)
			{
				ExitPointerPluginRegister.Log("Error loading resource " + resourceName + ": " + ex.Message, (LogLevel)2);
				return null;
			}
		}

		internal static GameObject? SetGameObject(string objectName, Texture2D arrowTexture2D)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = new GameObject(objectName);
				val.AddComponent<Image>();
				val.GetComponent<Image>().sprite = Sprite.Create(arrowTexture2D, new Rect(0f, 0f, (float)((Texture)arrowTexture2D).width, (float)((Texture)arrowTexture2D).height), new Vector2(0.5f, 0.5f));
				return val;
			}
			catch
			{
				return null;
			}
		}
	}
	internal static class Extensions
	{
		internal static Tuple<Transform, Transform>? GetExitPosition()
		{
			EntranceTeleport[] array = Object.FindObjectsByType<EntranceTeleport>((FindObjectsSortMode)0);
			Transform val = null;
			Transform val2 = null;
			if (array != null && array.Length != 0)
			{
				for (int i = 0; i < array.Length; i++)
				{
					string name = ((Object)array[i]).name;
					if (!(name == "EntranceTeleportA(Clone)"))
					{
						if (name == "EntranceTeleportB(Clone)")
						{
							val2 = array[i].entrancePoint;
						}
					}
					else
					{
						val = array[i].entrancePoint;
					}
				}
			}
			if ((Object)(object)val2 != (Object)null && (Object)(object)val != (Object)null)
			{
				return new Tuple<Transform, Transform>(val, val2);
			}
			return null;
		}
	}
}
namespace ExitPointer.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class HUDManagerPatch
	{
		private static ExitPointerClass? _mainExitPointer;

		private static ExitPointerClass? _fireExitPointer;

		internal static Camera? PlayerCamera;

		internal static Tuple<Transform, Transform>? Entrances;

		private static int yOffset = 2;

		private static float totalTime = 0f;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(ref HUDManager __instance)
		{
			//IL_00a9: 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)
			PlayerCamera = null;
			Entrances = null;
			Tuple<Texture2D, Texture2D> pointerTextures = ExitPointerPluginRegister.PointerTextures;
			Tuple<GameObject, GameObject> tuple = Tuple.Create<GameObject, GameObject>(ResourcesLoader.SetGameObject("MainExitPointer", pointerTextures.Item1), ResourcesLoader.SetGameObject("FireExitPointer", pointerTextures.Item2));
			try
			{
				_mainExitPointer = new ExitPointerClass(tuple.Item1);
				_fireExitPointer = new ExitPointerClass(tuple.Item2);
			}
			catch (Exception ex)
			{
				ExitPointerPluginRegister.Log("Error while creating ExitPointers: " + ex.Message, (LogLevel)2);
				return;
			}
			_mainExitPointer.SetActive(active: false);
			_fireExitPointer.SetActive(active: false);
			_mainExitPointer.SetDefaultStatus(((Component)__instance.loadingDarkenScreen).transform, new Vector3(0.25f, 0.27f, 1f));
			_fireExitPointer.SetDefaultStatus(((Component)__instance.loadingDarkenScreen).transform, new Vector3(0.25f, 0.27f, 1f));
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePostfix(ref HUDManager __instance)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			if (!StartOfRound.Instance.inShipPhase && RoundManager.Instance.currentLevel.sceneName != "CompanyBuilding" && GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				if ((Object)(object)PlayerCamera == (Object)null)
				{
					PlayerCamera = GameNetworkManager.Instance.localPlayerController.gameplayCamera;
				}
				if (Entrances == null)
				{
					Entrances = Extensions.GetExitPosition();
				}
			}
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory && (Object)(object)PlayerCamera != (Object)null && Entrances != null)
			{
				if (!_mainExitPointer.isActive)
				{
					_mainExitPointer.SetActive(active: true);
				}
				if (!_fireExitPointer.isActive)
				{
					_fireExitPointer.SetActive(active: true);
				}
				Vector3 position = ((Component)Entrances.Item1).transform.position;
				Vector3 position2 = ((Component)Entrances.Item2).transform.position;
				int width = __instance.playerScreenTexture.texture.width;
				int height = __instance.playerScreenTexture.texture.height;
				_mainExitPointer.MovePointer(PlayerCamera, new Vector3(position.x, position.y + (float)yOffset, position.z), width, height);
				_fireExitPointer.MovePointer(PlayerCamera, new Vector3(position2.x, position2.y + (float)yOffset, position2.z), width, height);
				_mainExitPointer.SetLocalScale(ExitPointerPluginRegister.pointerSize.Value);
				_fireExitPointer.SetLocalScale(ExitPointerPluginRegister.pointerSize.Value);
			}
			else
			{
				_mainExitPointer?.SetActive(active: false);
				_fireExitPointer?.SetActive(active: false);
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		internal static void StartRound()
		{
			if (RoundManager.Instance.currentLevel.sceneName != "CompanyBuilding")
			{
				HUDManagerPatch.PlayerCamera = null;
				HUDManagerPatch.Entrances = null;
			}
		}
	}
}