Decompiled source of CrosshairOverlay v1.1.3

CrosshairOverlay.dll

Decompiled 3 months ago
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(true)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CrosshairOverlay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A crosshair overlay mod for Straftat")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("kestrel.straftat.crosshairoverlay")]
[assembly: AssemblyTitle("CrosshairOverlay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CrosshairOverlay
{
	public static class Configs
	{
		public static ConfigEntry<FilterMode> filteringMode;

		public static ConfigEntry<float> width;

		public static ConfigEntry<float> height;

		public static ConfigEntry<float> offsetX;

		public static ConfigEntry<float> offsetY;

		public static ConfigEntry<bool> overlay;

		public static ConfigEntry<bool> hideDefault;

		public static ConfigEntry<bool> hideInMenus;

		public static ConfigEntry<bool> hideWhenScoped;

		public static ConfigEntry<string> filename;

		public static ConfigEntry<byte> tintR;

		public static ConfigEntry<byte> tintG;

		public static ConfigEntry<byte> tintB;

		public static ConfigEntry<byte> tintA;

		public static void BindTo(ConfigFile config)
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			filename = config.Bind<string>("General", "File name", "default-crosshair.png", "The name of the image file to load. png and jpeg formats are supported, and the file should be placed in the mod's directory. (" + Plugin.PluginPath + ")");
			overlay = config.Bind<bool>("General", "Overlay", true, "Wether the crosshair image should be on top of the UI. If disabled, the image will be under the UI. (NOTE: this does not include the 3D version of the player HUD~ the crosshair will always be above it.)");
			filteringMode = config.Bind<FilterMode>("General", "Image Filter Mode", (FilterMode)0, "The texture filtering mode to use for the crosshair image.");
			hideDefault = config.Bind<bool>("General", "Hide default crosshair", true, "Whether to hide the default crosshair~ this option uses the behaviour of ctrl+k, so the crosshair can be reenabled at any time.");
			hideInMenus = config.Bind<bool>("General", "Hide in menu", true, "Whether to hide the custom crosshair when in the main menu.");
			hideWhenScoped = config.Bind<bool>("General", "Hide when scoped", true, "Whether to hide the custom crosshair when aiming with a scoped weapon.");
			width = config.Bind<float>("Style.Size", "Width", 30f, "The width of the crosshair image.");
			height = config.Bind<float>("Style.Size", "Height", 30f, "The height of the crosshair image.");
			offsetX = config.Bind<float>("Style.Offset", "X Offset", 0f, "The X offset of the crosshair image.");
			offsetY = config.Bind<float>("Style.Offset", "Y Offset", 0f, "The Y offset of the crosshair image.");
			tintR = config.Bind<byte>("Style.Color", "1 Tint R", byte.MaxValue, new ConfigDescription("The red channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
			tintG = config.Bind<byte>("Style.Color", "2 Tint G", byte.MaxValue, new ConfigDescription("The green channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
			tintB = config.Bind<byte>("Style.Color", "3 Tint B", byte.MaxValue, new ConfigDescription("The blue channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
			tintA = config.Bind<byte>("Style.Color", "4 Tint A", byte.MaxValue, new ConfigDescription("The alpha channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
		}
	}
	[BepInPlugin("kestrel.straftat.crosshairoverlay", "CrosshairOverlay", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Crosshair))]
		public static class CrosshairPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPrefix]
			public static void SetupCrosshairOverlay(Crosshair __instance)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				if (Configs.hideDefault.Value)
				{
					((Component)__instance).transform.localScale = Vector3.zero;
				}
				SetupCrosshair(((Component)__instance).transform.parent);
				if (m_imageLoaded)
				{
					ReloadCrosshair();
				}
			}

			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			public static void UpdateOverlayVisibility(ref Crosshair __instance)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				if (m_queueImageReload && m_imageLoaded)
				{
					ReloadCrosshair();
					m_queueImageReload = false;
				}
				if (Configs.hideWhenScoped.Value && __instance.player != null && __instance.canScopeAim && __instance.player.isAiming)
				{
					m_root.SetActive(false);
					return;
				}
				if (Configs.hideInMenus.Value)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name == "MainMenu")
					{
						m_root.SetActive(false);
						return;
					}
				}
				m_root.SetActive(true);
			}
		}

		internal static ManualLogSource Logger;

		private static string m_imagePath;

		private static Sprite m_overlaySprite;

		private static GameObject m_root;

		private static Image m_image;

		private static RectTransform m_rectTransform;

		private static bool m_queueImageReload;

		private static bool m_imageLoaded;

		private static string loadBearingColonThree = ":3";

		public static Plugin Instance { get; private set; }

		public static string PluginPath { get; } = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));


		private void Awake()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (loadBearingColonThree != ":3")
			{
				Application.Quit();
			}
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Configs.BindTo(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Config.SettingChanged += OnConfigChanged;
			m_imagePath = Path.Combine(PluginPath, Configs.filename.Value);
			if (!File.Exists(m_imagePath))
			{
				Logger.LogWarning((object)("No image file found at " + m_imagePath));
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(LoadCrosshairImage());
			}
			new Harmony("kestrel.straftat.crosshairoverlay").PatchAll();
			Logger.LogInfo((object)"Hiiiiiiiiiiii :3");
		}

		private void OnConfigChanged(object sender, SettingChangedEventArgs e)
		{
			m_queueImageReload = true;
			if (e.ChangedSetting == Configs.filename)
			{
				m_imagePath = Path.Combine(PluginPath, Configs.filename.Value);
				if (!File.Exists(m_imagePath))
				{
					Logger.LogWarning((object)("No image file found at " + m_imagePath));
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(LoadCrosshairImage());
				}
			}
		}

		private static IEnumerator LoadCrosshairImage()
		{
			m_imageLoaded = false;
			UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("file:///" + Path.Combine(PluginPath, Configs.filename.Value));
			try
			{
				yield return uwr.SendWebRequest();
				if ((int)uwr.result != 1)
				{
					Logger.LogError((object)("Error while loading overlay image ~ " + uwr.error + "(the file at " + m_imagePath + " is probably invalid.)"));
				}
				else
				{
					Logger.LogInfo((object)"Found and loaded crosshair overlay!");
					Texture2D content = DownloadHandlerTexture.GetContent(uwr);
					m_overlaySprite = Sprite.Create(content, new Rect(0f, 0f, (float)((Texture)content).width, (float)((Texture)content).height), new Vector2(0.5f, 0.5f));
					m_imageLoaded = true;
				}
			}
			finally
			{
				((IDisposable)uwr)?.Dispose();
			}
		}

		private static void SetupCrosshair(Transform uiRoot = null)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			m_root = new GameObject("Crosshair Overlay");
			m_rectTransform = m_root.AddComponent<RectTransform>();
			m_root.AddComponent<CanvasGroup>().blocksRaycasts = false;
			m_image = m_root.AddComponent<Image>();
			if (Object.op_Implicit((Object)(object)uiRoot))
			{
				m_root.transform.SetParent(uiRoot, false);
			}
		}

		private static void ReloadCrosshair()
		{
			//IL_0025: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			m_rectTransform.sizeDelta = new Vector2(Configs.width.Value / 2f, Configs.height.Value / 2f);
			m_rectTransform.anchoredPosition = new Vector2(Configs.offsetX.Value, Configs.offsetY.Value);
			((Graphic)m_image).color = Color32.op_Implicit(new Color32(Configs.tintR.Value, Configs.tintG.Value, Configs.tintB.Value, Configs.tintA.Value));
			((Texture)m_overlaySprite.texture).filterMode = Configs.filteringMode.Value;
			m_image.sprite = m_overlaySprite;
			if (!Configs.overlay.Value)
			{
				m_root.transform.SetAsFirstSibling();
			}
			else
			{
				m_root.transform.SetAsLastSibling();
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "kestrel.straftat.crosshairoverlay";

		public const string PLUGIN_NAME = "CrosshairOverlay";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}