Decompiled source of ColorCrosshair v1.0.0

ColorCrosshair.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using ColorCrosshair.API;
using GTFO.API.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ColorCrosshair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ColorCrosshair")]
[assembly: AssemblyTitle("ColorCrosshair")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ColorCrosshair
{
	internal static class ColorPatch
	{
		public static void Init()
		{
			ColorCrosshairAPI.OnReload += RefreshDefaultColors;
		}

		public static void RefreshDefaultColors()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			CircleCrosshair circleCrosshair = GuiManager.CrosshairLayer.m_circleCrosshair;
			Color color = (circleCrosshair.m_crosshairColOrg = Configuration.defaultColor);
			circleCrosshair.SetColor(color);
			color = (circleCrosshair.m_chargeUpColOrg = Configuration.chargeColor);
			circleCrosshair.SetChargeUpColor(color);
		}

		[HarmonyPatch(typeof(CrosshairGuiLayer), "Setup")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void SetDefaultColors(CrosshairGuiLayer __instance, Transform root, string name)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0021: 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)
			CircleCrosshair circleCrosshair = __instance.m_circleCrosshair;
			Color color = (circleCrosshair.m_crosshairColOrg = Configuration.defaultColor);
			circleCrosshair.SetColor(color);
			color = (circleCrosshair.m_chargeUpColOrg = Configuration.chargeColor);
			circleCrosshair.SetChargeUpColor(color);
		}

		[HarmonyPatch(typeof(CrosshairGuiLayer), "TriggerChargeUpBlink")]
		[HarmonyWrapSafe]
		[HarmonyPrefix]
		private static void SetChargeNotificationColors(CrosshairGuiLayer __instance, ref Color blinkColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (((Color)(ref blinkColor)).Equals(Color.white))
			{
				blinkColor = Configuration.chargeBlinkColor;
			}
			else
			{
				blinkColor = Configuration.chargeWarningColor;
			}
		}

		[HarmonyPatch(typeof(CrosshairGuiLayer), "TriggerBlink")]
		[HarmonyWrapSafe]
		[HarmonyPrefix]
		private static void SetEnemyInRangeColor(CrosshairGuiLayer __instance, ref Color blinkColor)
		{
			//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)
			blinkColor = Configuration.enemyBlinkColor;
		}
	}
	internal static class Configuration
	{
		public static Color defaultColor = new Color(0.65f, 0.65f, 0.65f, 1f);

		public static Color chargeColor = new Color(0.85f, 0.85f, 0.85f, 0.7f);

		public static Color chargeBlinkColor = Color.white;

		public static Color chargeWarningColor = ColorExt.Red(0.6f);

		public static Color enemyBlinkColor = Color.white;

		private static ConfigFile configFile;

		internal static void Init()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ColorCrosshair.cfg"), true);
			BindAll(configFile);
			ColorCrosshairAPI.OnReload += OnFileChanged;
		}

		private static void OnFileChanged()
		{
			string text = "General Settings";
			configFile.Reload();
			SetField(ref defaultColor, (string)configFile[text, "Default Color"].BoxedValue);
			SetField(ref chargeColor, (string)configFile[text, "Chargeup Color"].BoxedValue);
			SetField(ref chargeBlinkColor, (string)configFile[text, "Charge Finished Color"].BoxedValue);
			SetField(ref chargeWarningColor, (string)configFile[text, "Charge Warning Color"].BoxedValue);
			SetField(ref enemyBlinkColor, (string)configFile[text, "Enemy In Range Color"].BoxedValue);
		}

		private static void SetField(ref Color field, string val)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!val.StartsWith('#'))
			{
				val = "#" + val;
			}
			Color val2 = default(Color);
			if (ColorUtility.TryParseHtmlString(val, ref val2))
			{
				field = val2;
			}
		}

		private static void BindAll(ConfigFile config)
		{
			string section = "General Settings";
			BindField(ref defaultColor, config, section, "Default Color", "The default color of the reticle.\nVanilla default: #7d7d7d99");
			BindField(ref chargeColor, config, section, "Chargeup Color", "The color for melee weapon charging progress.\nVanilla default: #BEBEBEAD");
			BindField(ref chargeBlinkColor, config, section, "Charge Finished Color", "The color that briefly blinks when melee weapon charging finishes.\nVanilla default: #FFFFFFFF");
			BindField(ref chargeWarningColor, config, section, "Charge Warning Color", "The color that briefly blinks when the melee weapon charge is about to expire.\nVanilla default: #FF000099");
			BindField(ref enemyBlinkColor, config, section, "Enemy In Range Color", "The color that briefly blinks when looking at an enemy in melee range while holding a melee weapon.\nVanilla default: #FFFFFFFF");
		}

		private static void BindField(ref Color field, ConfigFile config, string section, string key, string description)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			string value = config.Bind<string>(section, key, ColorUtility.ToHtmlStringRGBA(field), description).Value;
			SetField(ref field, value);
		}
	}
	[BepInPlugin("Dinorush.ColorCrosshair", "ColorCrosshair", "1.0.0")]
	internal sealed class Loader : BasePlugin
	{
		public const string MODNAME = "ColorCrosshair";

		[Conditional("DEBUG")]
		public static void DebugLog(object data)
		{
		}

		public override void Load()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			((BasePlugin)this).Log.LogMessage((object)"Loading ColorCrosshair");
			Configuration.Init();
			ColorPatch.Init();
			ColorCrosshairAPI.Init();
			new Harmony("ColorCrosshair").PatchAll(typeof(ColorPatch));
			((BasePlugin)this).Log.LogMessage((object)"Loaded ColorCrosshair");
		}
	}
}
namespace ColorCrosshair.API
{
	public static class ColorCrosshairAPI
	{
		public static Color DefaultColor => Configuration.defaultColor;

		public static Color ChargeColor => Configuration.chargeColor;

		public static Color ChargeBlinkColor => Configuration.chargeBlinkColor;

		public static Color ChargeWarningColor => Configuration.chargeWarningColor;

		public static Color EnemyBlinkColor => Configuration.enemyBlinkColor;

		public static event Action? OnReload;

		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "ColorCrosshair.cfg", false).FileChanged += new LiveEditEventHandler(RunOnFileChanged);
		}

		private static void RunOnFileChanged(LiveEditEventArgs _)
		{
			ColorCrosshairAPI.OnReload?.Invoke();
		}
	}
}