Decompiled source of LaserSightEditor v1.0.0

LaserSightEditor.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LaserSightEditor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LaserSightEditor")]
[assembly: AssemblyTitle("LaserSightEditor")]
[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 LaserSightEditor
{
	[BepInPlugin("lasersighteditor", "Laser Sight Editor", "1.0.0")]
	public class LaserSightEditorPlugin : BaseUnityPlugin
	{
		public static ConfigEntry<Color> LaserColor;

		public static ConfigEntry<float> LaserWidth;

		public static ConfigEntry<float> EmissionIntensity;

		public static ConfigEntry<KeyCode> CycleColorKey;

		public static ConfigEntry<KeyCode> CycleIntensityKey;

		public static ManualLogSource Log;

		private static readonly Color[] ColorPresets = (Color[])(object)new Color[7]
		{
			Color.red,
			Color.green,
			Color.blue,
			Color.yellow,
			Color.cyan,
			Color.magenta,
			Color.white
		};

		private static readonly string[] ColorPresetNames = new string[7] { "Red", "Green", "Blue", "Yellow", "Cyan", "Magenta", "White" };

		private static readonly float[] IntensityPresets = new float[5] { 1f, 3f, 6f, 10f, 15f };

		private int _colorIndex = 0;

		private int _intensityIndex = 1;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			LaserColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Laser", "Color", Color.green, "Laser sight color");
			LaserWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Laser", "Width", 0.02f, "Laser line width");
			EmissionIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Laser", "EmissionIntensity", 3f, "HDR glow brightness multiplier");
			CycleColorKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "CycleColorKey", (KeyCode)290, "Key to cycle through preset laser colors");
			CycleIntensityKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "CycleIntensityKey", (KeyCode)291, "Key to cycle through preset glow intensities");
			Harmony.CreateAndPatchAll(typeof(LaserSightPatch), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Laser Sight Editor loaded!");
		}

		private void Update()
		{
			//IL_0006: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(CycleColorKey.Value))
			{
				_colorIndex = (_colorIndex + 1) % ColorPresets.Length;
				LaserColor.Value = ColorPresets[_colorIndex];
				Log.LogInfo((object)("Laser color changed to: " + ColorPresetNames[_colorIndex]));
			}
			if (Input.GetKeyDown(CycleIntensityKey.Value))
			{
				_intensityIndex = (_intensityIndex + 1) % IntensityPresets.Length;
				EmissionIntensity.Value = IntensityPresets[_intensityIndex];
				Log.LogInfo((object)("Laser glow intensity changed to: " + IntensityPresets[_intensityIndex]));
			}
		}
	}
	[HarmonyPatch(typeof(LaserSight), "SetLine")]
	public class LaserSightPatch
	{
		private static void Postfix(LaserSight __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			LineRenderer value = Traverse.Create((object)__instance).Field("_line").GetValue<LineRenderer>();
			if ((Object)(object)value == (Object)null)
			{
				return;
			}
			Color val = (value.endColor = (value.startColor = LaserSightEditorPlugin.LaserColor.Value));
			value.widthMultiplier = LaserSightEditorPlugin.LaserWidth.Value;
			Material[] materials = ((Renderer)value).materials;
			foreach (Material val3 in materials)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					if (val3.HasProperty("_Color"))
					{
						val3.SetColor("_Color", val);
					}
					if (val3.HasProperty("_Emission"))
					{
						val3.SetColor("_Emission", val * LaserSightEditorPlugin.EmissionIntensity.Value);
					}
				}
			}
			((Renderer)value).materials = materials;
		}
	}
}