Decompiled source of CrosshairChanger v1.0.7

CrosshairChanger.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using CrosshairChanger.Utils;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CrosshairChanger")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/blacks7ar/CrosshairChanger/")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyProduct("CrosshairChanger")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("35FA340D-737C-40D9-9B32-8FFFEE249D80")]
[assembly: AssemblyFileVersion("1.0.7")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.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 CrosshairChanger
{
	[BepInPlugin("blacks7ar.CrosshairChanger", "CrosshairChanger", "1.0.7")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		public static class CrosshairPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
			public static void HudAwake_Prefix(Hud __instance, Player player)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)player != (Object)(object)Player.m_localPlayer) && !((Object)(object)__instance.m_crosshair == (Object)null))
				{
					((Graphic)__instance.m_crosshair).color = _crosshairColor.Value;
					((Component)__instance.m_crosshair).transform.localScale = new Vector3(_crosshairSize.Value, _crosshairSize.Value);
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(Hud), "Awake")]
			public static bool HudAwake_Prefix(Hud __instance)
			{
				if ((Object)(object)__instance.m_crosshair == (Object)null)
				{
					return false;
				}
				Sprite _default = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite x) => ((Object)x).name == "crosshair"));
				_crosshairSelection.SettingChanged += delegate
				{
					Image component2 = ((Component)__instance.m_crosshair).gameObject.GetComponent<Image>();
					component2.sprite = (Sprite)(_crosshairSelection.Value switch
					{
						CrosshairSelection.Crosshair1 => CrosshairSetup._crosshair01, 
						CrosshairSelection.ArrowsToEye => CrosshairSetup._crosshair02, 
						CrosshairSelection.Biohazard => CrosshairSetup._crosshair03, 
						CrosshairSelection.Bullseye => CrosshairSetup._crosshair04, 
						CrosshairSelection.Circle => CrosshairSetup._crosshair05, 
						CrosshairSelection.CodeCommit => CrosshairSetup._crosshair06, 
						CrosshairSelection.Compress => CrosshairSetup._crosshair07, 
						CrosshairSelection.Crosshair2 => CrosshairSetup._crosshair08, 
						CrosshairSelection.Ellipsis => CrosshairSetup._crosshair09, 
						CrosshairSelection.Eye => CrosshairSetup._crosshair10, 
						CrosshairSelection.Crosshair3 => CrosshairSetup._crosshair11, 
						CrosshairSelection.Radiation => CrosshairSetup._crosshair12, 
						CrosshairSelection.Default => _default, 
						_ => ((Component)__instance.m_crosshair).gameObject.GetComponent<Image>().sprite, 
					});
				};
				Image component = ((Component)__instance.m_crosshair).gameObject.GetComponent<Image>();
				component.sprite = (Sprite)(_crosshairSelection.Value switch
				{
					CrosshairSelection.Crosshair1 => CrosshairSetup._crosshair01, 
					CrosshairSelection.ArrowsToEye => CrosshairSetup._crosshair02, 
					CrosshairSelection.Biohazard => CrosshairSetup._crosshair03, 
					CrosshairSelection.Bullseye => CrosshairSetup._crosshair04, 
					CrosshairSelection.Circle => CrosshairSetup._crosshair05, 
					CrosshairSelection.CodeCommit => CrosshairSetup._crosshair06, 
					CrosshairSelection.Compress => CrosshairSetup._crosshair07, 
					CrosshairSelection.Crosshair2 => CrosshairSetup._crosshair08, 
					CrosshairSelection.Ellipsis => CrosshairSetup._crosshair09, 
					CrosshairSelection.Eye => CrosshairSetup._crosshair10, 
					CrosshairSelection.Crosshair3 => CrosshairSetup._crosshair11, 
					CrosshairSelection.Radiation => CrosshairSetup._crosshair12, 
					CrosshairSelection.Default => _default, 
					_ => ((Component)__instance.m_crosshair).gameObject.GetComponent<Image>().sprite, 
				});
				return true;
			}
		}

		private const string modGUID = "blacks7ar.CrosshairChanger";

		public const string modName = "CrosshairChanger";

		public const string modAuthor = "blacks7ar";

		public const string modVersion = "1.0.7";

		public const string modLink = "https://valheim.thunderstore.io/package/blacks7ar/CrosshairChanger/";

		private static readonly Harmony _harmony = new Harmony("blacks7ar.CrosshairChanger");

		private static ConfigEntry<Color> _crosshairColor;

		private static ConfigEntry<float> _crosshairSize;

		private static ConfigEntry<CrosshairSelection> _crosshairSelection;

		public void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			CrosshairSetup.Init();
			_crosshairColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Crosshair Color", new Color(255f, 255f, 255f), new ConfigDescription("Crosshair color.", (AcceptableValueBase)null, Array.Empty<object>()));
			_crosshairSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Crosshair Size", 1.5f, new ConfigDescription("Crosshair size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
			_crosshairSelection = ((BaseUnityPlugin)this).Config.Bind<CrosshairSelection>("General", "Crosshair Option", CrosshairSelection.Default, new ConfigDescription("Custom crosshairs.", (AcceptableValueBase)null, Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			((BaseUnityPlugin)this).Config.Save();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}
	}
}
namespace CrosshairChanger.Utils
{
	public enum CrosshairSelection
	{
		Default,
		Radiation,
		Eye,
		Ellipsis,
		Compress,
		CodeCommit,
		Circle,
		Bullseye,
		Biohazard,
		ArrowsToEye,
		Crosshair1,
		Crosshair2,
		Crosshair3
	}
	public static class CrosshairSetup
	{
		private static AssetBundle crosshairBundle;

		public static Sprite _crosshair01;

		public static Sprite _crosshair02;

		public static Sprite _crosshair03;

		public static Sprite _crosshair04;

		public static Sprite _crosshair05;

		public static Sprite _crosshair06;

		public static Sprite _crosshair07;

		public static Sprite _crosshair08;

		public static Sprite _crosshair09;

		public static Sprite _crosshair10;

		public static Sprite _crosshair11;

		public static Sprite _crosshair12;

		public static void Init()
		{
			crosshairBundle = GetAssetBundleFromResources("crosshairsbundle");
			_crosshair01 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_01.png");
			_crosshair02 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_02.png");
			_crosshair03 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_03.png");
			_crosshair04 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_04.png");
			_crosshair05 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_05.png");
			_crosshair06 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_06.png");
			_crosshair07 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_07.png");
			_crosshair08 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_08.png");
			_crosshair09 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_09.png");
			_crosshair10 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_10.png");
			_crosshair11 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_11.png");
			_crosshair12 = crosshairBundle.LoadAsset<Sprite>("Assets/CustomAssets/CustomCrosshairs/crosshairs_12.png");
		}

		private static AssetBundle GetAssetBundleFromResources(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = executingAssembly.GetManifestResourceNames().Single((string x) => x.EndsWith(filename));
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			return AssetBundle.LoadFromStream(stream);
		}
	}
}