Decompiled source of ExitPointerForHost v1.0.3

plugins/ExitPointer.dll

Decompiled 3 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.Logging;
using ExitPointer.Utils;
using HarmonyLib;
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.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+9f031ca8c947853d6a5ccde75c2e5de22f63ef93")]
[assembly: AssemblyProduct("overfirec_ExitPointer")]
[assembly: AssemblyTitle("ExitPointer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ExitPointerClass(GameObject pointer)
		{
			_pointer = pointer ?? throw new ArgumentNullException("pointer");
			_rectTransform = _pointer.GetComponent<RectTransform>();
		}

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

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

		internal void MovePointer(Camera camera, Transform targetTransform)
		{
			//IL_0013: 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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			_rectTransform.anchoredPosition = CalculatePos(camera, targetTransform, new Vector2(860f, 520f), new Vector2(430f, 260f), new Vector2(430f, 210f));
		}

		private Vector2 CalculatePos(Camera Cam, Transform TargetTransform, Vector2 ScreenSize, Vector2 ScreenCenter, Vector2 EllipticalRadius)
		{
			//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_0011: 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_001d: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_012b: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_016c: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(Cam.WorldToScreenPoint(TargetTransform.position));
			Vector3 forward = ((Component)Cam).transform.forward;
			Vector3 val2 = ((Component)TargetTransform).transform.position - ((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;
			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("ExitPointer", "overfirec_ExitPointer", "1.0.2")]
	public class ExitPointerPluginRegister : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("ExitPointer");

		private static ExitPointerPluginRegister? _instance;

		internal const string MainExitPointer = "MainExitPointer";

		internal const string FireExitPointer = "FireExitPointer";

		private static ManualLogSource? LOGSource { get; set; }

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

		private void Awake()
		{
			_instance = this;
			LOGSource = Logger.CreateLogSource("ExitPointer");
			_harmony.PatchAll();
			Log("ExitPointer version: 1.0.2 loading...", (LogLevel)16);
			TryLoadResource();
		}

		private void OnDisable()
		{
			_harmony.UnpatchSelf();
			ManualLogSource? lOGSource = LOGSource;
			if (lOGSource != null)
			{
				lOGSource.Dispose();
			}
			_instance = null;
		}

		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)
			{
				Log(ex.ToString(), (LogLevel)2);
				OnDisable();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ExitPointer";

		public const string PLUGIN_NAME = "overfirec_ExitPointer";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace ExitPointer.Utils
{
	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.PluginInfo
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Overfirec_ExitPointer";

		public const string PLUGIN_NAME = "ExitPointer";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
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;

		internal static bool IsAlready;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPostfix(ref HUDManager __instance)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			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);
			}
			_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)
		{
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory && GameNetworkManager.Instance.isHostingGame)
			{
				if ((Object)(object)PlayerCamera == (Object)null || Entrances == null || (Object)(object)Entrances.Item1 == (Object)null || (Object)(object)Entrances.Item2 == (Object)null)
				{
					PlayerCamera = GameNetworkManager.Instance.localPlayerController.gameplayCamera;
					Entrances = Extensions.GetExitPosition();
					ExitPointerPluginRegister.Log("Try to get Entrances...", (LogLevel)16);
				}
				_mainExitPointer?.SetActive(active: true);
				_fireExitPointer?.SetActive(active: true);
				_mainExitPointer.MovePointer(PlayerCamera, Entrances.Item1);
				_fireExitPointer.MovePointer(PlayerCamera, Entrances.Item2);
			}
			else
			{
				_mainExitPointer?.SetActive(active: false);
				_fireExitPointer?.SetActive(active: false);
			}
		}
	}
}