Decompiled source of CustomCrosshair v1.0.0

CustomCrosshair.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using I2.Loc;
using Microsoft.CodeAnalysis;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.Input;
using PerfectRandom.Sulfur.Core.Items;
using PerfectRandom.Sulfur.Core.Units;
using PerfectRandom.Sulfur.Core.Weapons;
using PerfectRandom.Sulfur.Gameplay;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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("CustomCrosshair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomCrosshair")]
[assembly: AssemblyTitle("CustomCrosshair")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CustomCrosshair
{
	internal static class CrosshairAssets
	{
		private static Sprite _cached;

		private static string _cachedKey;

		public static string Directory => Path.Combine(Paths.ConfigPath, "CustomCrosshair");

		public static void EnsureDirectory()
		{
			try
			{
				System.IO.Directory.CreateDirectory(Directory);
				string path = Path.Combine(Directory, "example_ring.png");
				if (!File.Exists(path))
				{
					File.WriteAllBytes(path, MakeExampleRing(64));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not prepare image folder: " + ex.Message));
			}
		}

		public static void InvalidateImage()
		{
			if ((Object)(object)_cached != (Object)null)
			{
				if ((Object)(object)_cached.texture != (Object)null)
				{
					Object.Destroy((Object)(object)_cached.texture);
				}
				Object.Destroy((Object)(object)_cached);
			}
			_cached = null;
			_cachedKey = null;
		}

		public static Sprite GetImage(string fileName, bool pixelated)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			string text = fileName + "|" + pixelated;
			if ((Object)(object)_cached != (Object)null && _cachedKey == text)
			{
				return _cached;
			}
			InvalidateImage();
			_cachedKey = text;
			if (string.IsNullOrWhiteSpace(fileName))
			{
				return null;
			}
			string text2 = (Path.IsPathRooted(fileName) ? fileName : Path.Combine(Directory, fileName));
			if (!File.Exists(text2))
			{
				Plugin.Log.LogWarning((object)("Crosshair image not found: " + text2));
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(text2);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					Object.Destroy((Object)(object)val);
					Plugin.Log.LogWarning((object)("Crosshair image could not be decoded (PNG/JPG only): " + text2));
					return null;
				}
				((Object)val).name = Path.GetFileNameWithoutExtension(text2);
				((Texture)val).filterMode = (FilterMode)(!pixelated);
				((Texture)val).wrapMode = (TextureWrapMode)1;
				_cached = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)_cached).name = ((Object)val).name;
				Plugin.Log.LogInfo((object)$"Loaded crosshair image {text2} ({((Texture)val).width}x{((Texture)val).height})");
				return _cached;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Failed to load crosshair image " + text2 + ": " + ex.Message));
				return null;
			}
		}

		private static byte[] MakeExampleRing(int size)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			float num = (float)(size - 1) * 0.5f;
			float num2 = (float)size * 0.42f;
			float num3 = (float)size * 0.34f;
			float num4 = (float)size * 0.06f;
			Color[] array = (Color[])(object)new Color[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num5 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
					float num6 = Mathf.Clamp01(num2 - num5 + 0.5f) * Mathf.Clamp01(num5 - num3 + 0.5f);
					float num7 = Mathf.Clamp01(num4 - num5 + 0.5f);
					float num8 = Mathf.Max(num6, num7);
					array[i * size + j] = new Color(1f, 1f, 1f, num8);
				}
			}
			val.SetPixels(array);
			val.Apply();
			byte[] result = ImageConversion.EncodeToPNG(val);
			Object.Destroy((Object)(object)val);
			return result;
		}
	}
	public enum CrosshairStyle
	{
		Vanilla,
		Cross,
		Dot,
		CrossDot,
		Image
	}
	public enum ColorPreset
	{
		Custom,
		White,
		Green,
		Cyan,
		Yellow,
		Orange,
		Red,
		Magenta,
		Pink,
		Black
	}
	public sealed class CrosshairConfig
	{
		public readonly ConfigEntry<Key> ToggleKey;

		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<CrosshairStyle> Style;

		public readonly ConfigEntry<bool> ShowWhileAiming;

		public readonly ConfigEntry<bool> ShowForMelee;

		public readonly ConfigEntry<bool> ShowForNoCrosshairWeapons;

		public readonly ConfigEntry<float> LineLength;

		public readonly ConfigEntry<float> Thickness;

		public readonly ConfigEntry<float> Gap;

		public readonly ConfigEntry<float> DotSize;

		public readonly ConfigEntry<bool> HideTopLine;

		public readonly ConfigEntry<bool> DynamicSpread;

		public readonly ConfigEntry<float> SpreadInfluence;

		public readonly ConfigEntry<bool> Outline;

		public readonly ConfigEntry<float> OutlineThickness;

		public readonly ConfigEntry<ColorPreset> Preset;

		public readonly ConfigEntry<Color> CustomColor;

		public readonly ConfigEntry<float> Opacity;

		public readonly ConfigEntry<string> ImageFile;

		public readonly ConfigEntry<float> ImageSize;

		public readonly ConfigEntry<bool> ImageScalesWithSpread;

		public readonly ConfigEntry<bool> ImageUseColor;

		public readonly ConfigEntry<bool> ImagePixelated;

		public readonly ConfigEntry<bool> ScopeZoomEnabled;

		public readonly ConfigEntry<float> ZoomMin;

		public readonly ConfigEntry<float> ZoomMax;

		public readonly ConfigEntry<float> ZoomStep;

		public readonly ConfigEntry<bool> ZoomRememberPerWeapon;

		public readonly ConfigEntry<bool> ZoomIronSights;

		public readonly ConfigEntry<bool> ZoomShowText;

		private static readonly HashSet<string> LayoutOnly = new HashSet<string>
		{
			"LineLength", "Thickness", "Gap", "DotSize", "DynamicSpread", "SpreadInfluence", "OutlineThickness", "ImageSize", "ImageScalesWithSpread", "ToggleSettingsKey",
			"ShowWhileAiming", "ShowForMelee", "ShowForNoCrosshairWeapons", "ScopeZoomEnabled", "ZoomMin", "ZoomMax", "ZoomStep", "ZoomRememberPerWeapon", "ZoomIronSights", "ZoomShowText"
		};

		public int Version { get; private set; }

		public Color ResolvedColor
		{
			get
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				Color result = default(Color);
				switch (Preset.Value)
				{
				case ColorPreset.White:
					result = Color.white;
					break;
				case ColorPreset.Green:
					((Color)(ref result))..ctor(0.25f, 1f, 0.25f);
					break;
				case ColorPreset.Cyan:
					((Color)(ref result))..ctor(0.2f, 1f, 1f);
					break;
				case ColorPreset.Yellow:
					((Color)(ref result))..ctor(1f, 0.95f, 0.2f);
					break;
				case ColorPreset.Orange:
					((Color)(ref result))..ctor(1f, 0.64f, 0.08f);
					break;
				case ColorPreset.Red:
					((Color)(ref result))..ctor(1f, 0.2f, 0.2f);
					break;
				case ColorPreset.Magenta:
					((Color)(ref result))..ctor(1f, 0.2f, 1f);
					break;
				case ColorPreset.Pink:
					((Color)(ref result))..ctor(1f, 0.5f, 0.75f);
					break;
				case ColorPreset.Black:
					result = Color.black;
					break;
				default:
					result = CustomColor.Value;
					break;
				}
				result.a = Opacity.Value;
				return result;
			}
		}

		public Color OutlineColor
		{
			get
			{
				//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_000c: 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_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				Color resolvedColor = ResolvedColor;
				Color result = ((0.299f * resolvedColor.r + 0.587f * resolvedColor.g + 0.114f * resolvedColor.b < 0.35f) ? Color.white : Color.black);
				result.a = Opacity.Value * 0.9f;
				return result;
			}
		}

		public event Action Changed;

		public CrosshairConfig(ConfigFile f)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Expected O, but got Unknown
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Expected O, but got Unknown
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Expected O, but got Unknown
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Expected O, but got Unknown
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			ToggleKey = f.Bind<Key>("0.Hotkey", "ToggleSettingsKey", (Key)101, "Key that opens/closes the in-game settings window. Unity InputSystem key names, e.g. F8, F9, Insert, Home, Backquote. None = disabled.");
			Enabled = f.Bind<bool>("1.General", "Enabled", true, "Master switch. When false the game's own crosshair is left untouched.");
			Style = f.Bind<CrosshairStyle>("1.General", "Style", CrosshairStyle.CrossDot, "Vanilla = game's sprite (only the visibility options below apply). Cross = 4 lines. Dot = center dot. CrossDot = both. Image = PNG from the images folder.");
			ShowWhileAiming = f.Bind<bool>("2.Visibility", "ShowWhileAiming", false, "Keep the crosshair visible while aiming down sights (the game hides it).");
			ShowForMelee = f.Bind<bool>("2.Visibility", "ShowForMelee", true, "Show the crosshair while a melee weapon / fists are selected (the game hides it).");
			ShowForNoCrosshairWeapons = f.Bind<bool>("2.Visibility", "ShowForNoCrosshairWeapons", true, "Show the crosshair for weapons the game marks as 'no crosshair' (e.g. scoped rifles) when not aiming.");
			LineLength = f.Bind<float>("3.Shape", "LineLength", 10f, new ConfigDescription("Length of each line (HUD pixels).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 80f), Array.Empty<object>()));
			Thickness = f.Bind<float>("3.Shape", "Thickness", 2f, new ConfigDescription("Line thickness (HUD pixels).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 12f), Array.Empty<object>()));
			Gap = f.Bind<float>("3.Shape", "Gap", 5f, new ConfigDescription("Distance from the center to the start of each line, at rest.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 80f), Array.Empty<object>()));
			DotSize = f.Bind<float>("3.Shape", "DotSize", 3f, new ConfigDescription("Center dot size (HUD pixels).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			HideTopLine = f.Bind<bool>("3.Shape", "HideTopLine", false, "T-style crosshair: hide the top line.");
			DynamicSpread = f.Bind<bool>("3.Shape", "DynamicSpread", true, "Lines move outward with weapon spread / movement penalty, like the vanilla crosshair grows.");
			SpreadInfluence = f.Bind<float>("3.Shape", "SpreadInfluence", 1f, new ConfigDescription("How strongly spread widens the gap. 0 = static, 1 = same relative growth as vanilla, 2 = exaggerated.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			Outline = f.Bind<bool>("3.Shape", "Outline", true, "Draw a dark outline behind lines and dot for contrast on bright backgrounds.");
			OutlineThickness = f.Bind<float>("3.Shape", "OutlineThickness", 1f, new ConfigDescription("Outline width (HUD pixels).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
			Preset = f.Bind<ColorPreset>("4.Color", "Preset", ColorPreset.White, "Color preset. Choose Custom to use CustomColor.");
			CustomColor = f.Bind<Color>("4.Color", "CustomColor", Color.white, "RGBA hex, used when Preset = Custom. Alpha here is ignored; use Opacity.");
			Opacity = f.Bind<float>("4.Color", "Opacity", 1f, new ConfigDescription("Crosshair opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
			ImageFile = f.Bind<string>("5.Image", "ImageFile", "crosshair.png", "File name inside BepInEx/config/CustomCrosshair/. Used when Style = Image. An example_ring.png is generated there on first run.");
			ImageSize = f.Bind<float>("5.Image", "ImageSize", 32f, new ConfigDescription("Image size on screen (HUD pixels, square, aspect preserved).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 400f), Array.Empty<object>()));
			ImageScalesWithSpread = f.Bind<bool>("5.Image", "ImageScalesWithSpread", false, "Scale the image with weapon spread.");
			ImageUseColor = f.Bind<bool>("5.Image", "ImageUseColor", false, "Tint the image with the crosshair color (otherwise drawn as-is, only Opacity applies).");
			ImagePixelated = f.Bind<bool>("5.Image", "ImagePixelated", false, "Nearest-neighbour filtering (crisp pixel-art), otherwise bilinear.");
			ScopeZoomEnabled = f.Bind<bool>("6.ScopeZoom", "ScopeZoomEnabled", true, "While aiming through a scope, the mouse wheel changes magnification instead of switching weapons.");
			ZoomMin = f.Bind<float>("6.ScopeZoom", "ZoomMin", 0.5f, new ConfigDescription("Lowest zoom factor relative to the scope's own magnification (1 = vanilla).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 1f), Array.Empty<object>()));
			ZoomMax = f.Bind<float>("6.ScopeZoom", "ZoomMax", 4f, new ConfigDescription("Highest zoom factor relative to the scope's own magnification.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
			ZoomStep = f.Bind<float>("6.ScopeZoom", "ZoomStep", 0.25f, new ConfigDescription("Change per wheel notch.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
			ZoomRememberPerWeapon = f.Bind<bool>("6.ScopeZoom", "ZoomRememberPerWeapon", true, "Remember the chosen zoom for each weapon type until the game is closed.");
			ZoomIronSights = f.Bind<bool>("6.ScopeZoom", "ZoomIronSights", false, "Also allow wheel zoom when aiming with iron sights / red dots (no scope).");
			ZoomShowText = f.Bind<bool>("6.ScopeZoom", "ZoomShowText", true, "Briefly show the current magnification (e.g. 3.2x) after each change.");
			f.SettingChanged += delegate(object _, SettingChangedEventArgs e)
			{
				if (((e != null) ? e.ChangedSetting : null) != null && LayoutOnly.Contains(e.ChangedSetting.Definition.Key))
				{
					this.Changed?.Invoke();
				}
				else
				{
					Bump();
				}
			};
		}

		public void Bump()
		{
			Version++;
			this.Changed?.Invoke();
		}

		public void ResetAll(ConfigFile f)
		{
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in f)
			{
				item.Value.BoxedValue = item.Value.DefaultValue;
			}
			Bump();
		}
	}
	public sealed class CrosshairView : MonoBehaviour
	{
		private sealed class Piece
		{
			public RectTransform Rect;

			public Image Img;

			public RectTransform OutlineRect;

			public Image OutlineImg;

			public Vector2 Dir;

			public bool IsImage;
		}

		private static readonly List<CrosshairView> All = new List<CrosshairView>();

		private static readonly FieldRef<PlayerHUD, Vector2> BaseSizeRef = AccessTools.FieldRefAccess<PlayerHUD, Vector2>("_crosshairSize");

		private PlayerHUD _hud;

		private RectTransform _rect;

		private CanvasGroup _group;

		private Graphic[] _vanilla = (Graphic[])(object)new Graphic[0];

		private RectTransform _root;

		private readonly List<Piece> _pieces = new List<Piece>();

		private int _appliedVersion = int.MinValue;

		private float _restRatio = -1f;

		internal bool ForceVisibleThisFrame;

		internal bool SuppressCalibrationThisFrame;

		public static CrosshairView Attach(PlayerHUD hud)
		{
			RectTransform crosshair = hud.crosshair;
			CrosshairView crosshairView = ((Component)crosshair).GetComponent<CrosshairView>();
			if ((Object)(object)crosshairView == (Object)null)
			{
				crosshairView = ((Component)crosshair).gameObject.AddComponent<CrosshairView>();
				crosshairView.Init(hud);
			}
			return crosshairView;
		}

		private void Init(PlayerHUD hud)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			_hud = hud;
			_rect = (RectTransform)((Component)this).transform;
			_group = ((Component)this).GetComponent<CanvasGroup>();
			List<Graphic> list = new List<Graphic>();
			Graphic[] componentsInChildren = ((Component)this).GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val in componentsInChildren)
			{
				string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
				if (!text.Contains("hit") && !text.Contains("xcross"))
				{
					list.Add(val);
				}
			}
			_vanilla = list.ToArray();
			LogHierarchy();
			All.Add(this);
			Rebuild();
		}

		private void OnDestroy()
		{
			All.Remove(this);
		}

		public static void RebuildAll()
		{
			foreach (CrosshairView item in All)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.Rebuild();
				}
			}
		}

		private void LogHierarchy()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Crosshair hierarchy (").Append(_rect.sizeDelta).Append("):");
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				stringBuilder.Append("\n  ").Append(((Object)(object)val == (Object)(object)((Component)this).transform) ? "" : "  ").Append(((Object)val).name)
					.Append(" [");
				Component[] components = ((Component)val).GetComponents<Component>();
				foreach (Component val2 in components)
				{
					stringBuilder.Append(((object)val2).GetType().Name).Append(' ');
				}
				stringBuilder.Append(']');
				RectTransform val3 = (RectTransform)(object)((val is RectTransform) ? val : null);
				if (val3 != null)
				{
					stringBuilder.Append(" size=").Append(val3.sizeDelta);
				}
			}
			Plugin.Log.LogInfo((object)stringBuilder.ToString());
		}

		private void Rebuild()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			CrosshairConfig cfg = Plugin.Cfg;
			_appliedVersion = cfg.Version;
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_root).gameObject);
				_root = null;
			}
			_pieces.Clear();
			bool flag = cfg.Enabled.Value && cfg.Style.Value != CrosshairStyle.Vanilla;
			Graphic[] vanilla = _vanilla;
			foreach (Graphic val in vanilla)
			{
				if ((Object)(object)val != (Object)null)
				{
					((Behaviour)val).enabled = !flag;
				}
			}
			if (!flag)
			{
				return;
			}
			GameObject val2 = new GameObject("CustomCrosshairRoot", new Type[1] { typeof(RectTransform) });
			_root = (RectTransform)val2.transform;
			((Transform)_root).SetParent((Transform)(object)_rect, false);
			RectTransform root = _root;
			RectTransform root2 = _root;
			RectTransform root3 = _root;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			root3.pivot = val3;
			Vector2 anchorMin = (root2.anchorMax = val3);
			root.anchorMin = anchorMin;
			_root.anchoredPosition = Vector2.zero;
			_root.sizeDelta = Vector2.zero;
			((Transform)_root).localScale = Vector3.one;
			((Transform)_root).SetAsLastSibling();
			Color resolvedColor = cfg.ResolvedColor;
			Color outlineColor = cfg.OutlineColor;
			bool value = cfg.Outline.Value;
			CrosshairStyle value2 = cfg.Style.Value;
			if (value2 == CrosshairStyle.Cross || value2 == CrosshairStyle.CrossDot)
			{
				if (!cfg.HideTopLine.Value)
				{
					AddPiece("Top", Vector2.up, resolvedColor, outlineColor, value);
				}
				AddPiece("Bottom", Vector2.down, resolvedColor, outlineColor, value);
				AddPiece("Left", Vector2.left, resolvedColor, outlineColor, value);
				AddPiece("Right", Vector2.right, resolvedColor, outlineColor, value);
			}
			if (value2 == CrosshairStyle.Dot || value2 == CrosshairStyle.CrossDot)
			{
				AddPiece("Dot", Vector2.zero, resolvedColor, outlineColor, value);
			}
			if (value2 == CrosshairStyle.Image)
			{
				Sprite image = CrosshairAssets.GetImage(cfg.ImageFile.Value, cfg.ImagePixelated.Value);
				if ((Object)(object)image != (Object)null)
				{
					Color color = (Color)(cfg.ImageUseColor.Value ? resolvedColor : new Color(1f, 1f, 1f, cfg.Opacity.Value));
					Piece piece = AddPiece("Image", Vector2.zero, color, outlineColor, withOutline: false);
					piece.IsImage = true;
					piece.Img.sprite = image;
					piece.Img.preserveAspect = true;
				}
				else
				{
					AddPiece("Dot", Vector2.zero, resolvedColor, outlineColor, value);
				}
			}
			Layout(1f);
		}

		private Piece AddPiece(string name, Vector2 dir, Color color, Color outlineColor, bool withOutline)
		{
			//IL_0006: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_001e: 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)
			//IL_0040: Expected O, but got Unknown
			Piece piece = new Piece
			{
				Dir = dir
			};
			if (withOutline)
			{
				piece.OutlineImg = MakeImage(name + "Outline", outlineColor);
				piece.OutlineRect = (RectTransform)((Component)piece.OutlineImg).transform;
			}
			piece.Img = MakeImage(name, color);
			piece.Rect = (RectTransform)((Component)piece.Img).transform;
			_pieces.Add(piece);
			return piece;
		}

		private Image MakeImage(string name, Color color)
		{
			//IL_002e: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)_root, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			((Transform)val2).localScale = Vector3.one;
			Image component = val.GetComponent<Image>();
			component.sprite = null;
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			((MaskableGraphic)component).maskable = false;
			return component;
		}

		private void Layout(float spreadMult)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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)
			CrosshairConfig cfg = Plugin.Cfg;
			float num = cfg.Gap.Value * spreadMult;
			float value = cfg.LineLength.Value;
			float value2 = cfg.Thickness.Value;
			float value3 = cfg.OutlineThickness.Value;
			float value4 = cfg.DotSize.Value;
			float num2 = cfg.ImageSize.Value * (cfg.ImageScalesWithSpread.Value ? spreadMult : 1f);
			Vector2 val = default(Vector2);
			foreach (Piece piece in _pieces)
			{
				Vector2 anchoredPosition;
				if (piece.IsImage)
				{
					anchoredPosition = Vector2.zero;
					((Vector2)(ref val))..ctor(num2, num2);
				}
				else if (piece.Dir == Vector2.zero)
				{
					anchoredPosition = Vector2.zero;
					((Vector2)(ref val))..ctor(value4, value4);
				}
				else
				{
					anchoredPosition = piece.Dir * (num + value * 0.5f);
					val = ((piece.Dir.y != 0f) ? new Vector2(value2, value) : new Vector2(value, value2));
				}
				piece.Rect.anchoredPosition = anchoredPosition;
				piece.Rect.sizeDelta = val;
				if ((Object)(object)piece.OutlineRect != (Object)null)
				{
					piece.OutlineRect.anchoredPosition = anchoredPosition;
					piece.OutlineRect.sizeDelta = val + new Vector2(2f * value3, 2f * value3);
				}
			}
		}

		private void LateUpdate()
		{
			if (Plugin.Cfg != null)
			{
				if (_appliedVersion != Plugin.Cfg.Version)
				{
					Rebuild();
				}
				if ((Object)(object)_root != (Object)null)
				{
					Layout(SpreadMultiplier());
				}
				if (ForceVisibleThisFrame && (Object)(object)_group != (Object)null)
				{
					_group.alpha = 1f;
				}
				ForceVisibleThisFrame = false;
				SuppressCalibrationThisFrame = false;
			}
		}

		private float SpreadMultiplier()
		{
			//IL_0050: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			CrosshairConfig cfg = Plugin.Cfg;
			if (!cfg.DynamicSpread.Value || cfg.SpreadInfluence.Value <= 0f)
			{
				return 1f;
			}
			Vector2 val = (((Object)(object)_hud != (Object)null) ? BaseSizeRef.Invoke(_hud) : Vector2.zero);
			if (val.x <= 0.01f)
			{
				return 1f;
			}
			float num = _rect.sizeDelta.x / val.x;
			if (float.IsNaN(num) || float.IsInfinity(num) || num <= 0f)
			{
				return 1f;
			}
			if (!SuppressCalibrationThisFrame && (_restRatio < 0f || num < _restRatio))
			{
				_restRatio = num;
			}
			float num2 = ((_restRatio > 0f) ? _restRatio : num);
			float num3 = num / num2;
			num3 = Mathf.Clamp(num3, 0.2f, 6f);
			return 1f + (num3 - 1f) * cfg.SpreadInfluence.Value;
		}
	}
	[HarmonyPatch(typeof(PlayerHUD), "ManualUpdate")]
	internal static class PlayerHud_ManualUpdate_Patch
	{
		private static readonly FieldRef<PlayerHUD, bool> ConsumableSelected = AccessTools.FieldRefAccess<PlayerHUD, bool>("consumableSelected");

		private static readonly FieldRef<PlayerHUD, PlayerSetting> DisableCrosshairSetting = AccessTools.FieldRefAccess<PlayerHUD, PlayerSetting>("_disableCrosshair");

		private static bool _errorLogged;

		private static void Postfix(PlayerHUD __instance)
		{
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Invalid comparison between Unknown and I4
			try
			{
				CrosshairConfig cfg = Plugin.Cfg;
				if (cfg == null || !cfg.Enabled.Value)
				{
					return;
				}
				Player player = __instance.player;
				RectTransform crosshair = __instance.crosshair;
				if ((Object)(object)player == (Object)null || (Object)(object)crosshair == (Object)null)
				{
					return;
				}
				CrosshairView crosshairView = CrosshairView.Attach(__instance);
				EquipmentManager equipmentManager = player.equipmentManager;
				if ((Object)(object)equipmentManager == (Object)null)
				{
					return;
				}
				Weapon lastEquippedWeapon = equipmentManager.lastEquippedWeapon;
				Holdable currentHoldable = equipmentManager.CurrentHoldable;
				bool flag = (Object)(object)lastEquippedWeapon != (Object)null && ((Holdable)lastEquippedWeapon).bIsAimingDownSight;
				if (flag)
				{
					crosshairView.SuppressCalibrationThisFrame = true;
				}
				if (!cfg.ShowWhileAiming.Value && !cfg.ShowForMelee.Value && !cfg.ShowForNoCrosshairWeapons.Value)
				{
					return;
				}
				GameManager instance = StaticInstance<GameManager>.Instance;
				if ((Object)(object)instance != (Object)null && instance.IsGamePausedByState((LockStatePadlock)4))
				{
					return;
				}
				PlayerSetting val = DisableCrosshairSetting.Invoke(__instance);
				if (((Object)(object)val != (Object)null && val.currentValue != 0f) || ConsumableSelected.Invoke(__instance) || player.hideCrosshair || player.hideHUD)
				{
					return;
				}
				bool flag2 = false;
				if ((int)equipmentManager.weaponCurrentSlot != 10)
				{
					Weapon val2 = (Weapon)(object)((currentHoldable is Weapon) ? currentHoldable : null);
					if (val2 == null || !val2.IsMelee)
					{
						if ((Object)(object)lastEquippedWeapon != (Object)null && (object)currentHoldable == lastEquippedWeapon)
						{
							bool flag3 = (Object)(object)((Holdable)lastEquippedWeapon).ItemDefinition != (Object)null && !((Holdable)lastEquippedWeapon).ItemDefinition.showCrosshair;
							if (flag)
							{
								flag2 = cfg.ShowWhileAiming.Value;
							}
							else if (flag3)
							{
								flag2 = cfg.ShowForNoCrosshairWeapons.Value;
							}
						}
						goto IL_01c0;
					}
				}
				flag2 = cfg.ShowForMelee.Value;
				goto IL_01c0;
				IL_01c0:
				if (flag2)
				{
					if (!((Component)crosshair).gameObject.activeSelf)
					{
						((Component)crosshair).gameObject.SetActive(true);
					}
					crosshairView.ForceVisibleThisFrame = true;
				}
			}
			catch (Exception ex)
			{
				if (!_errorLogged)
				{
					_errorLogged = true;
					Plugin.Log.LogError((object)("Crosshair patch failed (further errors suppressed): " + ex));
				}
			}
		}
	}
	internal static class Lang
	{
		private static bool? _zh;

		public static bool IsChinese
		{
			get
			{
				if (!_zh.HasValue)
				{
					_zh = Detect();
				}
				return _zh.Value;
			}
		}

		public static void Refresh()
		{
			_zh = null;
		}

		public static string L(string zh, string en)
		{
			if (!IsChinese)
			{
				return en;
			}
			return zh;
		}

		private static bool Detect()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			try
			{
				string currentLanguageCode = LocalizationManager.CurrentLanguageCode;
				if (!string.IsNullOrEmpty(currentLanguageCode))
				{
					return currentLanguageCode.StartsWith("zh", StringComparison.OrdinalIgnoreCase);
				}
			}
			catch
			{
			}
			SystemLanguage systemLanguage = Application.systemLanguage;
			if ((int)systemLanguage != 6 && (int)systemLanguage != 40)
			{
				return (int)systemLanguage == 41;
			}
			return true;
		}
	}
	public static class OptionsRegistration
	{
		private sealed class Binding
		{
			public string Name;

			public Func<float> Get;

			public PlayerSetting Setting;
		}

		public const string OptionsScreenGuid = "com.sulfur.optionsscreen.settings";

		private const string OwnerName = "Custom Crosshair";

		private const string Prefix = "CustomCrosshair_";

		private static bool _done;

		private static Type _registry;

		private static object _category;

		private static readonly List<Binding> Bindings = new List<Binding>();

		private static bool _zh;

		private static readonly Type Cat = typeof(SettingCategory);

		public static void TryRegister()
		{
			if (!Chainloader.PluginInfos.ContainsKey("com.sulfur.optionsscreen.settings"))
			{
				Plugin.Log.LogInfo((object)"OptionsScreen Settings mod not present; configure via the .cfg file (auto-reloads on save).");
			}
			else
			{
				Register();
			}
		}

		public static void Register()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (_done)
			{
				return;
			}
			try
			{
				_registry = FindType("SulfurOptionsScreenSettings.ModOptionsRegistry");
				if (_registry == null)
				{
					Plugin.Log.LogInfo((object)"ModOptionsRegistry type not found; in-game menu disabled.");
					return;
				}
				_done = true;
				if (!OptionsScreenModIsCompatible())
				{
					Plugin.Log.LogWarning((object)("OptionsScreen Settings mod is out of date for this game version (OptionsScreenOption.SetSetting signature changed); its pages would hang on 'Loading...'. Not registering there. Use the " + ((object)Plugin.Cfg.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " settings window or the .cfg file instead."));
					return;
				}
				_zh = Lang.IsChinese;
				CrosshairConfig cfg = Plugin.Cfg;
				_category = _registry.GetMethod("RegisterModCategory", new Type[3]
				{
					typeof(string),
					typeof(string),
					typeof(int)
				}).Invoke(null, new object[3]
				{
					"Custom Crosshair",
					L("自定义准星", "Custom Crosshair"),
					9100
				});
				int num = 0;
				AddInfo("Info", L("改动立即生效。图片放在 BepInEx/config/CustomCrosshair/ 文件夹。", "Changes apply instantly. Put PNG files in BepInEx/config/CustomCrosshair/."), num++);
				AddBool(cfg.Enabled, L("启用自定义准星", "Enable custom crosshair"), num++, L("关闭后完全使用游戏原版准星。", "Off = the game's own crosshair, untouched."));
				AddEnum<CrosshairStyle>(cfg.Style, L("准星样式", "Style"), num++, new string[5]
				{
					L("原版", "Vanilla"),
					L("十字", "Cross"),
					L("圆点", "Dot"),
					L("十字+圆点", "Cross + dot"),
					L("自定义图片", "Image")
				}, L("原版 = 只应用下面的显示规则;图片 = 使用文件夹里的 PNG。", "Vanilla = only the visibility rules below apply; Image = PNG from the folder."));
				AddInfo("VisHeader", L("—— 显示规则 ——", "—— Visibility ——"), num++);
				AddBool(cfg.ShowWhileAiming, L("开镜/瞄准时也显示", "Show while aiming"), num++, L("游戏默认在机瞄/开镜时隐藏准星。", "The game hides the crosshair while aiming down sights."));
				AddBool(cfg.ShowForMelee, L("近战武器也显示", "Show for melee"), num++, L("拳头/近战武器时在屏幕中心显示准星。", "Show the crosshair with fists / melee weapons."));
				AddBool(cfg.ShowForNoCrosshairWeapons, L("无准星武器也显示", "Show for 'no crosshair' weapons"), num++, L("例如带瞄准镜的步枪,腰射时游戏不显示准星。", "E.g. scoped rifles, which the game draws no crosshair for when hip-firing."));
				AddInfo("ShapeHeader", L("—— 形状 ——", "—— Shape ——"), num++);
				AddSlider(cfg.LineLength, L("线长", "Line length"), num++, 1f);
				AddSlider(cfg.Thickness, L("线宽", "Thickness"), num++, 1f);
				AddSlider(cfg.Gap, L("中心间距", "Gap"), num++, 1f);
				AddSlider(cfg.DotSize, L("圆点大小", "Dot size"), num++, 1f);
				AddBool(cfg.HideTopLine, L("隐藏上方线条 (T 形)", "Hide top line (T-style)"), num++);
				AddBool(cfg.DynamicSpread, L("随散布扩张", "Dynamic spread"), num++, L("开火/移动时线条外扩,和原版准星放大一致。", "Lines move outward with spread, like the vanilla crosshair grows."));
				AddSlider(cfg.SpreadInfluence, L("扩张幅度", "Spread influence"), num++, 0.1f, decimals: true);
				AddBool(cfg.Outline, L("描边", "Outline"), num++);
				AddSlider(cfg.OutlineThickness, L("描边宽度", "Outline width"), num++, 0.5f, decimals: true);
				AddInfo("ColorHeader", L("—— 颜色 ——", "—— Color ——"), num++);
				AddEnum<ColorPreset>(cfg.Preset, L("颜色预设", "Color preset"), num++, new string[10]
				{
					L("自定义", "Custom"),
					L("白", "White"),
					L("绿", "Green"),
					L("青", "Cyan"),
					L("黄", "Yellow"),
					L("橙", "Orange"),
					L("红", "Red"),
					L("品红", "Magenta"),
					L("粉", "Pink"),
					L("黑", "Black")
				});
				AddColorChannel("CustomR", L("自定义 红", "Custom red"), 0, num++);
				AddColorChannel("CustomG", L("自定义 绿", "Custom green"), 1, num++);
				AddColorChannel("CustomB", L("自定义 蓝", "Custom blue"), 2, num++);
				AddSlider(cfg.Opacity, L("不透明度", "Opacity"), num++, 0.05f, decimals: true);
				AddInfo("ImageHeader", L("—— 自定义图片 ——", "—— Image ——"), num++);
				AddInfo("ImageName", L("当前文件: " + cfg.ImageFile.Value + "(在 cfg 里修改文件名)", "Current file: " + cfg.ImageFile.Value + " (change the name in the cfg)"), num++);
				AddSlider(cfg.ImageSize, L("图片大小", "Image size"), num++, 1f);
				AddBool(cfg.ImageScalesWithSpread, L("图片随散布缩放", "Image scales with spread"), num++);
				AddBool(cfg.ImageUseColor, L("图片使用准星颜色", "Tint image with color"), num++);
				AddBool(cfg.ImagePixelated, L("像素风 (不平滑)", "Pixelated (no smoothing)"), num++);
				AddButton("Reload", L("重新读取配置和图片", "Reload config and image"), L("重新读取", "Reload"), num++, Plugin.ReloadEverything);
				Plugin.Log.LogInfo((object)"Registered settings in the in-game Options menu (OptionsScreen Settings).");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("OptionsScreen integration failed; use the .cfg file instead. " + ex));
			}
		}

		public static void SyncFromConfig()
		{
			if (!_done)
			{
				return;
			}
			AsyncAssetLoading val = null;
			try
			{
				val = StaticInstance<AsyncAssetLoading>.Instance;
			}
			catch
			{
			}
			foreach (Binding binding in Bindings)
			{
				try
				{
					if ((Object)(object)binding.Setting == (Object)null && (Object)(object)val != (Object)null && val.playerSettings != null)
					{
						val.playerSettings.TryGetValue(binding.Name, out binding.Setting);
					}
					float num = binding.Get();
					PlayerPrefs.SetFloat("PlayerSetting_" + binding.Name, num);
					if ((Object)(object)binding.Setting != (Object)null)
					{
						binding.Setting.currentValue = num;
					}
				}
				catch
				{
				}
			}
		}

		private static string L(string zh, string en)
		{
			if (!_zh)
			{
				return en;
			}
			return zh;
		}

		private static bool OptionsScreenModIsCompatible()
		{
			try
			{
				return typeof(OptionsScreenOption).GetMethod("SetSetting", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(PlayerSetting) }, null) != null;
			}
			catch
			{
				return false;
			}
		}

		private static Type FindType(string fullName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					Type type = assembly.GetType(fullName, throwOnError: false);
					if (type != null)
					{
						return type;
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private static MethodInfo Method(string name, params Type[] args)
		{
			MethodInfo? method = _registry.GetMethod(name, BindingFlags.Static | BindingFlags.Public, null, args, null);
			if (method == null)
			{
				throw new MissingMethodException(_registry.FullName, name);
			}
			return method;
		}

		private static void Seed(string name, float value)
		{
			PlayerPrefs.SetFloat("PlayerSetting_" + name, value);
		}

		private static void Track(string name, Func<float> get, object setting)
		{
			Bindings.Add(new Binding
			{
				Name = name,
				Get = get,
				Setting = (PlayerSetting)((setting is PlayerSetting) ? setting : null)
			});
		}

		private static void AddInfo(string id, string label, int order)
		{
			Method("AddInfo", Cat, typeof(string), typeof(string), typeof(int), typeof(string)).Invoke(null, new object[5]
			{
				_category,
				"CustomCrosshair_" + id,
				label,
				order,
				null
			});
		}

		private static void AddBool(ConfigEntry<bool> entry, string label, int order, string tooltip = null)
		{
			string text = "CustomCrosshair_" + ((ConfigEntryBase)entry).Definition.Key;
			Seed(text, entry.Value ? 1f : 0f);
			Action<bool> action = delegate(bool v)
			{
				if (entry.Value != v)
				{
					entry.Value = v;
				}
			};
			object setting = Method("AddBool", Cat, typeof(string), typeof(string), typeof(bool), typeof(Action<bool>), typeof(int), typeof(string)).Invoke(null, new object[7] { _category, text, label, entry.Value, action, order, tooltip });
			Track(text, () => (!entry.Value) ? 0f : 1f, setting);
		}

		private static void AddSlider(ConfigEntry<float> entry, string label, int order, float step, bool decimals = false, string tooltip = null)
		{
			string text = "CustomCrosshair_" + ((ConfigEntryBase)entry).Definition.Key;
			AcceptableValueRange<float> val = ((ConfigEntryBase)entry).Description.AcceptableValues as AcceptableValueRange<float>;
			float num = val?.MinValue ?? 0f;
			float num2 = val?.MaxValue ?? 100f;
			Seed(text, entry.Value);
			Action<float> action = delegate(float v)
			{
				if (Mathf.Abs(entry.Value - v) > 0.0001f)
				{
					entry.Value = v;
				}
			};
			object setting = Method("AddSlider", Cat, typeof(string), typeof(string), typeof(float), typeof(float), typeof(float), typeof(float), typeof(bool), typeof(Action<float>), typeof(int), typeof(string)).Invoke(null, new object[11]
			{
				_category, text, label, entry.Value, num, num2, step, decimals, action, order,
				tooltip
			});
			Track(text, () => entry.Value, setting);
		}

		private static void AddEnum<T>(ConfigEntry<T> entry, string label, int order, string[] labels, string tooltip = null) where T : struct, Enum
		{
			string text = "CustomCrosshair_" + ((ConfigEntryBase)entry).Definition.Key;
			int num = Convert.ToInt32(entry.Value);
			Seed(text, num);
			Action<int> action = delegate(int i)
			{
				T val = (T)Enum.ToObject(typeof(T), i);
				if (!entry.Value.Equals(val))
				{
					entry.Value = val;
				}
			};
			object setting = Method("AddAlternative", Cat, typeof(string), typeof(string), typeof(string[]), typeof(int), typeof(Action<int>), typeof(int), typeof(string)).Invoke(null, new object[8] { _category, text, label, labels, num, action, order, tooltip });
			Track(text, () => Convert.ToInt32(entry.Value), setting);
		}

		private static void AddColorChannel(string id, string label, int channel, int order)
		{
			ConfigEntry<Color> entry = Plugin.Cfg.CustomColor;
			string text = "CustomCrosshair_" + id;
			Func<float> func = delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				Color value = entry.Value;
				return ((Color)(ref value))[channel];
			};
			Seed(text, func());
			Action<float> action = delegate(float v)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				Color value = entry.Value;
				if (Mathf.Abs(((Color)(ref value))[channel] - v) > 0.0001f)
				{
					((Color)(ref value))[channel] = v;
					entry.Value = value;
				}
			};
			object setting = Method("AddSlider", Cat, typeof(string), typeof(string), typeof(float), typeof(float), typeof(float), typeof(float), typeof(bool), typeof(Action<float>), typeof(int), typeof(string)).Invoke(null, new object[11]
			{
				_category,
				text,
				label,
				func(),
				0f,
				1f,
				0.05f,
				true,
				action,
				order,
				L("仅在颜色预设 = 自定义 时生效。", "Only used when Color preset = Custom.")
			});
			Track(text, func, setting);
		}

		private static void AddButton(string id, string label, string buttonText, int order, Action onPressed)
		{
			Method("AddButton", Cat, typeof(string), typeof(string), typeof(Action), typeof(string), typeof(int), typeof(string)).Invoke(null, new object[7]
			{
				_category,
				"CustomCrosshair_" + id,
				label,
				onPressed,
				buttonText,
				order,
				null
			});
		}
	}
	[BepInPlugin("com.melquine.sulfur.customcrosshair", "Custom Crosshair", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.melquine.sulfur.customcrosshair";

		public const string Name = "Custom Crosshair";

		public const string Version = "1.0.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static CrosshairConfig Cfg;

		private Harmony _harmony;

		private DateTime _lastCfgWrite;

		private float _nextCfgPoll;

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = new CrosshairConfig(((BaseUnityPlugin)this).Config);
			Cfg.Changed += OnConfigChanged;
			CrosshairAssets.EnsureDirectory();
			_harmony = new Harmony("com.melquine.sulfur.customcrosshair");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			((Component)this).gameObject.AddComponent<SettingsWindow>();
			((Component)this).gameObject.AddComponent<ZoomHud>();
			OptionsRegistration.TryRegister();
			_lastCfgWrite = GetCfgWriteTime();
			Log.LogInfo((object)string.Format("{0} {1} loaded. Settings window key: {2}. Config: {3}; images: {4}", "Custom Crosshair", "1.0.0", Cfg.ToggleKey.Value, ((BaseUnityPlugin)this).Config.ConfigFilePath, CrosshairAssets.Directory));
		}

		private void Update()
		{
			if (Time.unscaledTime < _nextCfgPoll)
			{
				return;
			}
			_nextCfgPoll = Time.unscaledTime + 2f;
			DateTime cfgWriteTime = GetCfgWriteTime();
			if (cfgWriteTime == _lastCfgWrite)
			{
				return;
			}
			_lastCfgWrite = cfgWriteTime;
			try
			{
				((BaseUnityPlugin)this).Config.Reload();
				OptionsRegistration.SyncFromConfig();
				Log.LogInfo((object)"Config file changed on disk, reloaded.");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Config reload failed: " + ex.Message));
			}
		}

		private void OnConfigChanged()
		{
			_lastCfgWrite = GetCfgWriteTime();
		}

		private DateTime GetCfgWriteTime()
		{
			try
			{
				return File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath) ? File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath) : DateTime.MinValue;
			}
			catch
			{
				return DateTime.MinValue;
			}
		}

		public static void ReloadEverything()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				return;
			}
			try
			{
				((BaseUnityPlugin)Instance).Config.Reload();
				CrosshairAssets.InvalidateImage();
				OptionsRegistration.SyncFromConfig();
				Cfg.Bump();
				Instance._lastCfgWrite = Instance.GetCfgWriteTime();
				Log.LogInfo((object)"Reloaded config and image.");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Reload failed: " + ex));
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class ScopeZoom
	{
		[HarmonyPatch(typeof(InputReader), "SelectByScroll")]
		private static class InputReader_SelectByScroll_Patch
		{
			private static bool _logged;

			private static bool Prefix(InputReader __instance, CallbackContext context)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					float direction = ((CallbackContext)(ref context)).ReadValue<Vector2>().y * ScrollMultiplier.Invoke(__instance);
					if (HandleScroll(__instance.equipmentManager, direction))
					{
						return false;
					}
				}
				catch (Exception ex)
				{
					if (!_logged)
					{
						_logged = true;
						Plugin.Log.LogError((object)("Scope zoom scroll patch failed: " + ex));
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(EquipmentManager), "SightWeapon")]
		private static class EquipmentManager_SightWeapon_Patch
		{
			private static bool _logged;

			private static void Postfix(EquipmentManager __instance)
			{
				try
				{
					OnSighted(__instance);
				}
				catch (Exception ex)
				{
					if (!_logged)
					{
						_logged = true;
						Plugin.Log.LogError((object)("Scope zoom sight patch failed: " + ex));
					}
				}
			}
		}

		[HarmonyPatch(typeof(EquipmentManager), "UnsightWeapon")]
		private static class EquipmentManager_UnsightWeapon_Patch
		{
			private static void Prefix()
			{
				End();
			}
		}

		[HarmonyPatch(typeof(EquipmentManager), "ResetADS")]
		private static class EquipmentManager_ResetADS_Patch
		{
			private static void Prefix()
			{
				End();
			}
		}

		private static readonly FieldRef<EquipmentManager, float> TargetFov = AccessTools.FieldRefAccess<EquipmentManager, float>("targetFOV");

		private static readonly FieldRef<InputReader, float> ScrollMultiplier = AccessTools.FieldRefAccess<InputReader, float>("mouseScrollMultiplier");

		private static readonly Dictionary<ItemId, float> Remembered = new Dictionary<ItemId, float>();

		private static Weapon _activeWeapon;

		private static WeaponAttachmentVisual _activeScope;

		private static float _activeScopeOriginalFov;

		private static float _activeBaselineFov;

		private static float _activeFactor = 1f;

		internal static float HudMagnification;

		internal static float HudUntil;

		private static CrosshairConfig Cfg => Plugin.Cfg;

		internal static bool IsZooming => (Object)(object)_activeWeapon != (Object)null;

		private static float ZoomedFov(float baselineFov, float factor)
		{
			float num = baselineFov * 0.5f * (MathF.PI / 180f);
			return Mathf.Clamp(2f * Mathf.Atan(Mathf.Tan(num) / Mathf.Max(0.05f, factor)) * 57.29578f, 1f, 170f);
		}

		private static float Magnification(float hipFov, float fov)
		{
			return Mathf.Tan(hipFov * 0.5f * (MathF.PI / 180f)) / Mathf.Tan(Mathf.Max(0.5f, fov) * 0.5f * (MathF.PI / 180f));
		}

		private static WeaponAttachmentVisual FindScope(EquipmentManager em, Weapon weapon)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			WeaponAttachmentVisual overridenADSby = ((Holdable)weapon).overridenADSby;
			if ((Object)(object)overridenADSby != (Object)null && (int)overridenADSby.AttachmentSlot == 2 && overridenADSby.worldADSFOV > 0f)
			{
				return overridenADSby;
			}
			List<WeaponAttachmentVisual> activeScopes = em.activeScopes;
			if (activeScopes != null)
			{
				for (int i = 0; i < activeScopes.Count; i++)
				{
					WeaponAttachmentVisual val = activeScopes[i];
					if ((Object)(object)val != (Object)null && val.primaryScope && val.worldADSFOV > 0f && ((Component)val).gameObject.activeSelf)
					{
						return val;
					}
				}
			}
			return null;
		}

		private static bool TryGetAimedWeapon(EquipmentManager em, out Weapon weapon)
		{
			weapon = (Weapon)(((Object)(object)em != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)weapon != (Object)null)
			{
				return ((Holdable)weapon).bIsAimingDownSight;
			}
			return false;
		}

		private static void OnSighted(EquipmentManager em)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (Cfg.ScopeZoomEnabled.Value && TryGetAimedWeapon(em, out var weapon))
			{
				float value = 1f;
				if (Cfg.ZoomRememberPerWeapon.Value && (Object)(object)weapon.weaponDefinition != (Object)null)
				{
					Remembered.TryGetValue(((ItemDefinition)weapon.weaponDefinition).id, out value);
				}
				if (value <= 0f)
				{
					value = 1f;
				}
				Begin(em, weapon);
				if ((Object)(object)_activeWeapon != (Object)null && Mathf.Abs(value - 1f) > 0.001f)
				{
					Apply(em, value, announce: false);
				}
			}
		}

		private static void Begin(EquipmentManager em, Weapon weapon)
		{
			WeaponAttachmentVisual val = FindScope(em, weapon);
			if ((Object)(object)val == (Object)null && !Cfg.ZoomIronSights.Value)
			{
				End();
			}
			else if (!((Object)(object)_activeWeapon == (Object)(object)weapon) || !((Object)(object)_activeScope == (Object)(object)val))
			{
				End();
				_activeWeapon = weapon;
				_activeScope = val;
				_activeScopeOriginalFov = (((Object)(object)val != (Object)null) ? val.worldADSFOV : 0f);
				_activeBaselineFov = TargetFov.Invoke(em);
				if (_activeBaselineFov <= 0f)
				{
					_activeBaselineFov = (((Object)(object)val != (Object)null) ? val.worldADSFOV : em.baseFOV);
				}
				_activeFactor = 1f;
			}
		}

		private static void Apply(EquipmentManager em, float factor, bool announce)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			factor = Mathf.Clamp(factor, Cfg.ZoomMin.Value, Cfg.ZoomMax.Value);
			_activeFactor = factor;
			float num = ZoomedFov(_activeBaselineFov, factor);
			TargetFov.Invoke(em) = num;
			if ((Object)(object)_activeScope != (Object)null)
			{
				_activeScope.worldADSFOV = num;
			}
			if (Cfg.ZoomRememberPerWeapon.Value && (Object)(object)_activeWeapon != (Object)null && (Object)(object)_activeWeapon.weaponDefinition != (Object)null)
			{
				Remembered[((ItemDefinition)_activeWeapon.weaponDefinition).id] = factor;
			}
			if (announce && Cfg.ZoomShowText.Value)
			{
				HudMagnification = Magnification(em.baseFOV, num);
				HudUntil = Time.unscaledTime + 1.5f;
			}
		}

		internal static void End()
		{
			if ((Object)(object)_activeScope != (Object)null && _activeScopeOriginalFov > 0f)
			{
				_activeScope.worldADSFOV = _activeScopeOriginalFov;
			}
			_activeScope = null;
			_activeWeapon = null;
			_activeFactor = 1f;
		}

		private static bool HandleScroll(EquipmentManager em, float direction)
		{
			if (!Cfg.ScopeZoomEnabled.Value || (Object)(object)em == (Object)null)
			{
				return false;
			}
			if (!TryGetAimedWeapon(em, out var weapon))
			{
				return false;
			}
			Begin(em, weapon);
			if ((Object)(object)_activeWeapon == (Object)null)
			{
				return false;
			}
			float num = Mathf.Max(0.05f, Cfg.ZoomStep.Value);
			float num2 = _activeFactor + ((direction > 0f) ? num : (0f - num));
			num2 = Mathf.Round(num2 / num) * num;
			Apply(em, num2, announce: true);
			return true;
		}

		internal static void Tick()
		{
			if ((Object)(object)_activeWeapon == (Object)null)
			{
				return;
			}
			try
			{
				GameManager instance = StaticInstance<GameManager>.Instance;
				EquipmentManager val = (((Object)(object)instance != (Object)null) ? instance.EquipmentManager : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val.CurrentHoldable != (Object)(object)_activeWeapon || !((Holdable)_activeWeapon).bIsAimingDownSight)
				{
					End();
				}
			}
			catch
			{
				End();
			}
		}
	}
	internal sealed class ZoomHud : MonoBehaviour
	{
		private GUIStyle _style;

		private void Update()
		{
			ScopeZoom.Tick();
		}

		private void OnGUI()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_002c: 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_0040: Expected O, but got Unknown
			if (!(Time.unscaledTime > ScopeZoom.HudUntil))
			{
				if (_style == null)
				{
					_style = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontSize = 22,
						fontStyle = (FontStyle)1
					};
				}
				float num = Mathf.Max(1f, (float)Screen.height / 1080f);
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				float num2 = (float)Screen.width / num;
				float num3 = (float)Screen.height / num;
				string text = ScopeZoom.HudMagnification.ToString("0.0") + "x";
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(num2 * 0.5f - 100f, num3 * 0.5f + 90f, 200f, 36f);
				Color color = GUI.color;
				GUI.color = new Color(0f, 0f, 0f, 0.8f);
				GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text, _style);
				GUI.color = new Color(1f, 0.85f, 0.4f, 1f);
				GUI.Label(val, text, _style);
				GUI.color = color;
			}
		}
	}
	internal sealed class SettingsWindow : MonoBehaviour
	{
		private const int WindowId = 1129467731;

		private bool _open;

		private bool _lockApplied;

		private bool _pausedByUs;

		private Rect _rect = new Rect(40f, 60f, 600f, 0f);

		private Vector2 _scroll;

		private bool _inputErrorLogged;

		private GUIStyle _header;

		private GUIStyle _hint;

		private GUIStyle _box;

		private Texture2D _swatch;

		private static string L(string zh, string en)
		{
			return Lang.L(zh, en);
		}

		private void Update()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Keyboard current = Keyboard.current;
				Key value = Plugin.Cfg.ToggleKey.Value;
				if (current != null && (int)value != 0 && ((ButtonControl)current[value]).wasPressedThisFrame)
				{
					Toggle();
				}
			}
			catch (Exception ex)
			{
				if (!_inputErrorLogged)
				{
					_inputErrorLogged = true;
					Plugin.Log.LogWarning((object)("Hotkey polling failed: " + ex.Message));
				}
			}
		}

		public void Toggle()
		{
			_open = !_open;
			if (_open)
			{
				Lang.Refresh();
			}
			ApplyLock(_open);
		}

		private void ApplyLock(bool on)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			if (on == _lockApplied)
			{
				return;
			}
			_lockApplied = on;
			try
			{
				GameManager instance = StaticInstance<GameManager>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.ModifyControllerLock((LockStatePadlock)1, on);
					instance.ModifyCursorState((LockStatePadlock)1, on);
					if (on)
					{
						_pausedByUs = (int)instance.gameState == 3;
						if (_pausedByUs)
						{
							instance.ModifyGamePauseState((LockStatePadlock)1, true);
						}
					}
					else if (_pausedByUs)
					{
						_pausedByUs = false;
						instance.ModifyGamePauseState((LockStatePadlock)1, false);
					}
					return;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Lock/cursor handling failed: " + ex.Message));
			}
			if (on)
			{
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
			}
		}

		private void OnDisable()
		{
			if (_open)
			{
				_open = false;
				ApplyLock(on: false);
			}
		}

		private void OnGUI()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (_open)
			{
				float num = Mathf.Max(1f, (float)Screen.height / 1080f);
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				EnsureStyles();
				_rect = GUILayout.Window(1129467731, _rect, new WindowFunction(DrawWindow), L("自定义准星 设置", "Custom Crosshair settings"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(600f) });
				float num2 = (float)Screen.width / num;
				float num3 = (float)Screen.height / num;
				((Rect)(ref _rect)).x = Mathf.Clamp(((Rect)(ref _rect)).x, 0f, Mathf.Max(0f, num2 - ((Rect)(ref _rect)).width));
				((Rect)(ref _rect)).y = Mathf.Clamp(((Rect)(ref _rect)).y, 0f, Mathf.Max(0f, num3 - 40f));
			}
		}

		private void EnsureStyles()
		{
			//IL_0014: 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_002d: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (_header == null)
			{
				_header = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1,
					fontSize = 14
				};
				_header.normal.textColor = new Color(1f, 0.75f, 0.3f);
				_hint = new GUIStyle(GUI.skin.label)
				{
					fontSize = 11,
					wordWrap = true
				};
				_hint.normal.textColor = new Color(0.8f, 0.8f, 0.8f);
				_box = new GUIStyle(GUI.skin.box);
				_swatch = new Texture2D(1, 1);
				_swatch.SetPixel(0, 0, Color.white);
				_swatch.Apply();
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0008: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0896: Unknown result type (might be due to invalid IL or missing references)
			CrosshairConfig cfg = Plugin.Cfg;
			_scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(Mathf.Min(760f, (float)Screen.height / Mathf.Max(1f, (float)Screen.height / 1080f) - 140f)) });
			GUILayout.Label(L("改动立即生效并自动保存。按 " + ((object)cfg.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " 关闭。", "Changes apply instantly and are saved. Press " + ((object)cfg.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " to close."), _hint, Array.Empty<GUILayoutOption>());
			Header(L("基本", "General"));
			Toggle(cfg.Enabled, L("启用自定义准星(关闭 = 完全原版)", "Enable custom crosshair (off = pure vanilla)"));
			EnumGrid<CrosshairStyle>(cfg.Style, L("样式", "Style"), new string[5]
			{
				L("原版", "Vanilla"),
				L("十字", "Cross"),
				L("圆点", "Dot"),
				L("十字+圆点", "Cross+dot"),
				L("图片", "Image")
			}, 5);
			Header(L("显示规则", "Visibility"));
			Toggle(cfg.ShowWhileAiming, L("开镜 / 机瞄时也显示", "Show while aiming down sights"));
			Toggle(cfg.ShowForMelee, L("近战 / 拳头时也显示", "Show for melee / fists"));
			Toggle(cfg.ShowForNoCrosshairWeapons, L("“无准星”武器(带镜步枪)腰射时也显示", "Show for 'no crosshair' weapons (scoped rifles)"));
			if (cfg.Style.Value == CrosshairStyle.Cross || cfg.Style.Value == CrosshairStyle.CrossDot || cfg.Style.Value == CrosshairStyle.Dot)
			{
				Header(L("形状", "Shape"));
				if (cfg.Style.Value != CrosshairStyle.Dot)
				{
					Slider(cfg.LineLength, L("线长", "Line length"), integer: true);
					Slider(cfg.Thickness, L("线宽", "Thickness"), integer: true);
					Slider(cfg.Gap, L("中心间距", "Gap"), integer: true);
					Toggle(cfg.HideTopLine, L("隐藏上方线条(T 形)", "Hide top line (T-style)"));
					Toggle(cfg.DynamicSpread, L("随散布向外扩张", "Dynamic spread"));
					if (cfg.DynamicSpread.Value)
					{
						Slider(cfg.SpreadInfluence, L("扩张幅度", "Spread influence"), integer: false);
					}
				}
				if (cfg.Style.Value != CrosshairStyle.Cross)
				{
					Slider(cfg.DotSize, L("圆点大小", "Dot size"), integer: true);
				}
				Toggle(cfg.Outline, L("描边", "Outline"));
				if (cfg.Outline.Value)
				{
					Slider(cfg.OutlineThickness, L("描边宽度", "Outline width"), integer: false);
				}
			}
			if (cfg.Style.Value != CrosshairStyle.Vanilla)
			{
				Header(L("颜色", "Color"));
				EnumGrid<ColorPreset>(cfg.Preset, L("预设", "Preset"), new string[10]
				{
					L("自定义", "Custom"),
					L("白", "White"),
					L("绿", "Green"),
					L("青", "Cyan"),
					L("黄", "Yellow"),
					L("橙", "Orange"),
					L("红", "Red"),
					L("品红", "Magenta"),
					L("粉", "Pink"),
					L("黑", "Black")
				}, 5);
				if (cfg.Preset.Value == ColorPreset.Custom)
				{
					Color value = cfg.CustomColor.Value;
					float num = ChannelSlider(L("红 R", "Red"), value.r);
					float num2 = ChannelSlider(L("绿 G", "Green"), value.g);
					float num3 = ChannelSlider(L("蓝 B", "Blue"), value.b);
					if (num != value.r || num2 != value.g || num3 != value.b)
					{
						cfg.CustomColor.Value = new Color(num, num2, num3, 1f);
					}
				}
				Slider(cfg.Opacity, L("不透明度", "Opacity"), integer: false);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(L("当前颜色:", "Current color:"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
				Color color = GUI.color;
				GUI.color = cfg.ResolvedColor;
				GUILayout.Box((Texture)(object)_swatch, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(60f),
					GUILayout.Height(18f)
				});
				GUI.color = color;
				GUILayout.EndHorizontal();
			}
			if (cfg.Style.Value == CrosshairStyle.Image)
			{
				Header(L("自定义图片", "Image"));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(L("文件名", "File name"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
				string text = GUILayout.TextField(cfg.ImageFile.Value, Array.Empty<GUILayoutOption>());
				if (text != cfg.ImageFile.Value)
				{
					cfg.ImageFile.Value = text;
				}
				GUILayout.EndHorizontal();
				GUILayout.Label(L("放在 BepInEx/config/CustomCrosshair/ 下,PNG 透明背景。改名后点“重新加载”。", "Place it in BepInEx/config/CustomCrosshair/ (PNG with alpha). Click Reload after editing."), _hint, Array.Empty<GUILayoutOption>());
				Slider(cfg.ImageSize, L("图片大小", "Image size"), integer: true);
				Toggle(cfg.ImageScalesWithSpread, L("随散布缩放", "Scale with spread"));
				Toggle(cfg.ImageUseColor, L("使用准星颜色着色", "Tint with crosshair color"));
				Toggle(cfg.ImagePixelated, L("像素风(不平滑)", "Pixelated (no smoothing)"));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(L("打开图片文件夹", "Open image folder"), Array.Empty<GUILayoutOption>()))
				{
					Application.OpenURL(CrosshairAssets.Directory);
				}
				if (GUILayout.Button(L("重新加载", "Reload"), Array.Empty<GUILayoutOption>()))
				{
					Plugin.ReloadEverything();
				}
				GUILayout.EndHorizontal();
			}
			Header(L("瞄准镜变倍", "Scope zoom"));
			Toggle(cfg.ScopeZoomEnabled, L("开镜时滚轮调节倍率(不开镜时滚轮照常切枪)", "Mouse wheel zoom while scoped (wheel still switches weapons when not scoped)"));
			if (cfg.ScopeZoomEnabled.Value)
			{
				Slider(cfg.ZoomMin, L("最低倍率系数", "Min factor"), integer: false);
				Slider(cfg.ZoomMax, L("最高倍率系数", "Max factor"), integer: false);
				Slider(cfg.ZoomStep, L("每格变化", "Step per notch"), integer: false);
				GUILayout.Label(L("系数相对该镜原本倍率:1 = 原版,2 = 两倍放大,0.5 = 一半。", "Factor is relative to the scope's own magnification: 1 = vanilla, 2 = twice, 0.5 = half."), _hint, Array.Empty<GUILayoutOption>());
				Toggle(cfg.ZoomRememberPerWeapon, L("每把武器记住上次倍率", "Remember zoom per weapon"));
				Toggle(cfg.ZoomIronSights, L("机瞄 / 红点也允许变倍", "Also for iron sights / red dots"));
				Toggle(cfg.ZoomShowText, L("变倍时短暂显示当前放大倍数", "Show magnification text when changed"));
			}
			GUILayout.Space(8f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(L("恢复全部默认", "Reset all to defaults"), Array.Empty<GUILayoutOption>()))
			{
				cfg.ResetAll(((BaseUnityPlugin)Plugin.Instance).Config);
			}
			if (GUILayout.Button(L("重新读取 cfg", "Reload cfg"), Array.Empty<GUILayoutOption>()))
			{
				Plugin.ReloadEverything();
			}
			if (GUILayout.Button(L("关闭", "Close"), Array.Empty<GUILayoutOption>()))
			{
				Toggle();
			}
			GUILayout.EndHorizontal();
			GUILayout.Label(L("提示:进入对局后按住准星看效果;窗口打开时游戏会暂停。", "Tip: open this in a run to see the crosshair live; the game pauses while the window is open."), _hint, Array.Empty<GUILayoutOption>());
			GUILayout.EndScrollView();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
		}

		private void Header(string text)
		{
			GUILayout.Space(6f);
			GUILayout.Label(text, _header, Array.Empty<GUILayoutOption>());
		}

		private static void Toggle(ConfigEntry<bool> e, string label)
		{
			bool flag = GUILayout.Toggle(e.Value, " " + label, Array.Empty<GUILayoutOption>());
			if (flag != e.Value)
			{
				e.Value = flag;
			}
		}

		private static void Slider(ConfigEntry<float> e, string label, bool integer)
		{
			AcceptableValueRange<float> val = ((ConfigEntryBase)e).Description.AcceptableValues as AcceptableValueRange<float>;
			float num = val?.MinValue ?? 0f;
			float num2 = val?.MaxValue ?? 100f;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			float num3 = GUILayout.HorizontalSlider(e.Value, num, num2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			num3 = ((!integer) ? (Mathf.Round(num3 * 20f) / 20f) : Mathf.Round(num3));
			GUILayout.Label(integer ? num3.ToString("0") : num3.ToString("0.00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(44f) });
			GUILayout.EndHorizontal();
			if (Mathf.Abs(num3 - e.Value) > 0.0001f)
			{
				e.Value = num3;
			}
		}

		private static float ChannelSlider(string label, float value)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			float num = GUILayout.HorizontalSlider(value, 0f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			num = Mathf.Round(num * 100f) / 100f;
			GUILayout.Label(num.ToString("0.00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(44f) });
			GUILayout.EndHorizontal();
			return num;
		}

		private static void EnumGrid<T>(ConfigEntry<T> e, string label, string[] names, int columns) where T : struct, Enum
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			int num = Convert.ToInt32(e.Value);
			int num2 = GUILayout.SelectionGrid(num, names, columns, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			if (num2 != num)
			{
				e.Value = (T)Enum.ToObject(typeof(T), num2);
			}
		}
	}
}