Decompiled source of ColorfulRicoshots v1.0.1

ColorfulRicoshots.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Configgy;
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("ColorfulRicoshots")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ColorfulRicoshots")]
[assembly: AssemblyTitle("ColorfulRicoshots")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ColorfulRicoshots
{
	[BepInPlugin("ColorfulRicoshots.adry.ultrakill", "ColorfulRicoshots", "1.0.1")]
	public class ColorfulRicoshots : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Coin), "SpawnBeam")]
		public class SpawnBeamPatch
		{
			[HarmonyPostfix]
			private static void Postfix(ref GameObject __result)
			{
				if (!((Object)(object)__result == (Object)null))
				{
					LineRenderer component = __result.GetComponent<LineRenderer>();
					RevolverBeam component2 = __result.GetComponent<RevolverBeam>();
					HandleBeamColoring(component, component2, isFromCoin: true);
				}
			}
		}

		[HarmonyPatch(typeof(RevolverBeam), "Start")]
		public class RevolverBeamPatch
		{
			[HarmonyPostfix]
			private static void Postfix(RevolverBeam __instance)
			{
				if (!((Object)(object)__instance == (Object)null))
				{
					LineRenderer component = ((Component)__instance).GetComponent<LineRenderer>();
					HandleBeamColoring(component, __instance, isFromCoin: false);
				}
			}
		}

		[HarmonyPatch(typeof(Coin), "DelayedReflectRevolver")]
		public class CoinReflectPatch
		{
			[HarmonyPostfix]
			private static void Postfix(GameObject beam)
			{
				if (!((Object)(object)beam == (Object)null))
				{
					LineRenderer component = beam.GetComponent<LineRenderer>();
					RevolverBeam component2 = beam.GetComponent<RevolverBeam>();
					HandleBeamColoring(component, component2, isFromCoin: true);
				}
			}
		}

		[HarmonyPatch(typeof(SecondaryRevolver), "Shoot")]
		public class SecondaryRevolverPatch
		{
			[HarmonyPostfix]
			private static void Postfix(SecondaryRevolver __instance)
			{
				if (!((Object)(object)__instance?.secBeamPoint == (Object)null))
				{
					LineRenderer component = __instance.secBeamPoint.GetComponent<LineRenderer>();
					RevolverBeam component2 = __instance.secBeamPoint.GetComponent<RevolverBeam>();
					HandleBeamColoring(component, component2, isFromCoin: false);
				}
			}
		}

		private ConfigBuilder config;

		private static Random random = new Random();

		private static readonly string[] colors = new string[50]
		{
			"#FF0000", "#FFA500", "#FFFF00", "#00FF00", "#0000FF", "#4B0082", "#8B00FF", "#FF69B4", "#800080", "#FFFFFF",
			"#00FFFF", "#000080", "#006400", "#90EE90", "#800000", "#FF4500", "#4682B4", "#9370DB", "#48D1CC", "#FF1493",
			"#7CFC00", "#BDB76B", "#FF00FF", "#CD853F", "#8B4513", "#228B22", "#483D8B", "#2E8B57", "#B8860B", "#FF8C00",
			"#8FBC8F", "#BA55D3", "#4169E1", "#32CD32", "#FF69B4", "#DAA520", "#7B68EE", "#FF6347", "#20B2AA", "#9932CC",
			"#8B0000", "#556B2F", "#66CDAA", "#9400D3", "#CD5C5C", "#008B8B", "#BC8F8F", "#4B0082", "#00CED1", "#FF4040"
		};

		private static readonly string[] colorNames = new string[50]
		{
			"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", "Pink", "Purple", "White",
			"Cyan", "Navy Blue", "Dark Green", "Light Green", "Maroon", "Orange Red", "Steel Blue", "Medium Purple", "Turquoise", "Deep Pink",
			"Lawn Green", "Dark Khaki", "Magenta", "Peru", "Saddle Brown", "Forest Green", "Dark Slate Blue", "Sea Green", "Dark Goldenrod", "Dark Orange",
			"Dark Sea Green", "Medium Orchid", "Royal Blue", "Lime Green", "Hot Pink", "Goldenrod", "Medium Slate Blue", "Tomato", "Light Sea Green", "Dark Orchid",
			"Dark Red", "Dark Olive Green", "Medium Aquamarine", "Dark Violet", "Indian Red", "Dark Cyan", "Rosy Brown", "Dark Purple", "Dark Turquoise", "Crimson"
		};

		[Configgable("General", "Enable Mod", 0, "Enables or disables the ColorfulRicoshots mod.")]
		private static ConfigToggle modEnabled = new ConfigToggle(true);

		[Configgable("Beam", "Ricochet Beam Color", 1, "Changes the color of ricochet beams")]
		private static ConfigDropdown<string> ricochetBeamColor;

		private void Awake()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			string[] array = new string[colors.Length + 2];
			string[] array2 = new string[colors.Length + 2];
			array[0] = "default";
			array[1] = "rainbow";
			array2[0] = "Default";
			array2[1] = "Rainbow";
			for (int i = 0; i < colors.Length; i++)
			{
				array[i + 2] = colors[i];
				array2[i + 2] = colorNames[i];
			}
			ricochetBeamColor = new ConfigDropdown<string>(array, array2, 0);
			config = new ConfigBuilder("ColorfulRicoshots.adry.ultrakill", "ColorfulRicoshots");
			config.BuildAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ColorfulRicoshots is loaded!");
			Harmony val = new Harmony("ColorfulRicoshots.adry.ultrakill");
			val.PatchAll();
		}

		private static void ColorizeBeam(LineRenderer lineRenderer, Color color)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_001d: 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)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)lineRenderer == (Object)null))
			{
				Gradient val = new Gradient();
				val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(color, 0f),
					new GradientColorKey(color, 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
				{
					new GradientAlphaKey(1f, 0f),
					new GradientAlphaKey(1f, 1f)
				});
				lineRenderer.colorGradient = val;
			}
		}

		private static void HandleBeamColoring(LineRenderer lineRenderer, RevolverBeam revolverBeam, bool isFromCoin)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if (!((ConfigValueElement<bool>)(object)modEnabled).GetValue() || (Object)(object)lineRenderer == (Object)null)
			{
				return;
			}
			if (!isFromCoin)
			{
				if (!((Object)(object)revolverBeam != (Object)null))
				{
					return;
				}
				if (revolverBeam.ricochetAmount <= 0 && !revolverBeam.hasBeenRicocheter)
				{
					Transform previouslyHitTransform = revolverBeam.previouslyHitTransform;
					if (!((Object)(object)((previouslyHitTransform != null) ? ((Component)previouslyHitTransform).GetComponent<Coin>() : null) != (Object)null))
					{
						return;
					}
				}
			}
			if (!(((ConfigValueElement<string>)(object)ricochetBeamColor).GetValue() == "default"))
			{
				string text = ((ConfigValueElement<string>)(object)ricochetBeamColor).GetValue();
				if (text == "rainbow")
				{
					text = colors[random.Next(colors.Length)];
				}
				Color color = default(Color);
				if (ColorUtility.TryParseHtmlString(text, ref color))
				{
					ColorizeBeam(lineRenderer, color);
				}
			}
		}
	}
}