Decompiled source of MorCrosshairs v1.0.1

BepInEx/plugins/MorCrosshairs.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using MorCrosshairs.Assets;
using MorCrosshairs.Events;
using MorCrosshairs.Utils;
using On.RoR2.UI;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
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("OyasumiLiv")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("MIT")]
[assembly: AssemblyDescription("Allows you to customize the survivors' crosshairs.")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1+db7381430e420e1df5b235793d743ebc95877369")]
[assembly: AssemblyProduct("MorCrosshairs")]
[assembly: AssemblyTitle("MorCrosshairs")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/OyasumiLiv/MorCrosshairs")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace MorCrosshairs
{
	[BepInPlugin("OyasumiLiv.MorCrosshairs", "Mor' Crosshairs", "1.0.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Main : BaseUnityPlugin
	{
		public static ManualLogSource logger;

		private static ConfigEntry<Color> crosshairColor;

		private static ConfigEntry<float> crosshairScale;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			crosshairColor = ((BaseUnityPlugin)this).Config.Bind<Color>(McConfig.Crosshair.General, McConfig.Crosshair.Colour.key = "Color", McConfig.Crosshair.Colour.color = Color.white, McConfig.Crosshair.Colour.description = "Sets the crosshair color.");
			crosshairScale = ((BaseUnityPlugin)this).Config.Bind<float>(McConfig.Crosshair.General, McConfig.Crosshair.Scale.key = "Scale", McConfig.Crosshair.Scale.thickness = 1f, McConfig.Crosshair.Scale.description = "Sets the crosshair size, multiplied relative to the original crosshair scale.");
			CrosshairManager.UpdateCrosshair += new hook_UpdateCrosshair(CrosshairManagerOnUpdateCrosshair);
			Init(logger);
		}

		private void CrosshairManagerOnUpdateCrosshair(orig_UpdateCrosshair orig, CrosshairManager self, CharacterBody targetBody, Vector3 crosshairWorldPosition, Camera uiCamera)
		{
			//IL_0008: 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)
			new McUpdateCrosshair().CrosshairManager_UpdateCrosshair(orig, self, targetBody, crosshairWorldPosition, uiCamera, crosshairColor.Value, crosshairScale.Value);
		}

		private void Init(ManualLogSource console)
		{
			console.LogInfo((object)"Initializing setup!");
			McConfig.RiskOfOptions_Get("Allows you to customize the survivors' crosshairs.", BuildAssets.GetIcon());
			McConfig.RiskOfOptions_Get(crosshairColor, logger);
			McConfig.RiskOfOptions_Get(crosshairScale, logger);
		}
	}
}
namespace MorCrosshairs.Utils
{
	public static class McConfig
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public readonly struct Crosshair
		{
			[StructLayout(LayoutKind.Sequential, Size = 1)]
			public readonly struct Colour
			{
				public static string key { get; set; }

				public static string description { get; set; }

				public static Color color { get; set; }
			}

			[StructLayout(LayoutKind.Sequential, Size = 1)]
			public readonly struct Scale
			{
				public static string key { get; set; }

				public static string description { get; set; }

				public static float thickness { get; set; }
			}

			public static string General = "General";
		}

		public static void RiskOfOptions_Get(string description, Sprite? icon)
		{
			ModSettingsManager.SetModDescription(description);
			if ((Object)(object)icon != (Object)null)
			{
				ModSettingsManager.SetModIcon(icon);
			}
		}

		public static void RiskOfOptions_Get(ConfigEntry<Color> crosshairColor, ManualLogSource console)
		{
			RiskOfOptions_SetColor(crosshairColor, console);
		}

		public static void RiskOfOptions_Get(ConfigEntry<float> crosshairThickness, ManualLogSource console)
		{
			RiskOfOptions_SetScale(crosshairThickness, console);
		}

		private static void RiskOfOptions_SetColor(ConfigEntry<Color> crosshairColor, ManualLogSource? console = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new ColorOption(crosshairColor));
			if (console != null)
			{
				console.LogInfo((object)$"Risk Of Options: Set general crosshair color to {((ConfigEntryBase)crosshairColor).BoxedValue}");
			}
		}

		private static void RiskOfOptions_SetScale(ConfigEntry<float> crosshairScale, ManualLogSource? console = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new SliderOption(crosshairScale, (SliderConfig)new StepSliderConfig
			{
				min = 0.5f,
				max = 3f,
				increment = 0.1f
			}));
			if (console != null)
			{
				console.LogInfo((object)$"Risk Of Options: Set general crosshair scale to {((ConfigEntryBase)crosshairScale).BoxedValue}");
			}
		}
	}
}
namespace MorCrosshairs.Events
{
	public interface IEvents
	{
		void CrosshairManager_UpdateCrosshair(orig_UpdateCrosshair orig, CrosshairManager self, CharacterBody targetBody, Vector3 crosshairWorldPosition, Camera uiCamera, Color crosshairColor, float crosshairScale);
	}
	public class McUpdateCrosshair : IEvents
	{
		private readonly ManualLogSource _logger = Main.logger;

		public void CrosshairManager_UpdateCrosshair(orig_UpdateCrosshair orig, CrosshairManager self, CharacterBody targetBody, Vector3 crosshairWorldPosition, Camera uiCamera, Color crosshairColor, float crosshairScale)
		{
			//IL_0003: 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)
			orig.Invoke(self, targetBody, crosshairWorldPosition, uiCamera);
			if (!((Object)(object)self.crosshairController == (Object)null))
			{
				Graphic[] componentsInChildren = ((Component)self.crosshairController).GetComponentsInChildren<Graphic>(true);
				SetCrosshairColor(componentsInChildren, crosshairColor);
				SetCrosshairScale(self.crosshairController.rectTransform, crosshairScale);
			}
		}

		private void SetCrosshairScale(RectTransform crosshairScale, float multiplier)
		{
			//IL_0001: 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)
			((Transform)crosshairScale).localScale = Vector3.one * multiplier;
		}

		private void SetCrosshairColor(Graphic[] crosshairInstance, Color crosshairColor)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < crosshairInstance.Length; i++)
			{
				crosshairInstance[i].color = crosshairColor;
			}
		}
	}
}
namespace MorCrosshairs.Assets
{
	public class BuildAssets
	{
		public static Sprite GetIcon()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.png");
			if (!File.Exists(path))
			{
				Main.logger.LogInfo((object)"Icon not found.");
				return null;
			}
			Texture2D val = new Texture2D(256, 256, (TextureFormat)5, false);
			ImageConversion.LoadImage(val, File.ReadAllBytes(path));
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
		}
	}
}