Decompiled source of Colorable CozyLights v1.0.2

BepInEx/Plugins/Colorable_Cozy_Lights.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Colorable_Cozy_Lights")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Adds a config to change the color of the cozy lights")]
[assembly: AssemblyTitle("Colorable_Cozy_Lights")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Colorable_Cozy_Lights
{
	[BepInPlugin("com.atomic.colorcozylights", "Color Cozy Lights", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CozyLights), "Update")]
		public class CozyLightsPatch
		{
			private static bool lastAnimatorState;

			private static void Postfix(CozyLights __instance)
			{
				if (__instance.cozyLightsAnimator.GetBool("on") && !lastAnimatorState)
				{
					CozyLightsManager cozyLightsManager = Object.FindObjectOfType<CozyLightsManager>();
					if ((Object)(object)cozyLightsManager != (Object)null)
					{
						cozyLightsManager.Initialize();
					}
				}
				lastAnimatorState = __instance.cozyLightsAnimator.GetBool("on");
			}
		}

		internal static ConfigEntry<int> colorConfigR;

		internal static ConfigEntry<int> colorConfigG;

		internal static ConfigEntry<int> colorConfigB;

		internal static ConfigEntry<bool> Rainbow;

		internal static ConfigEntry<float> RainbowSpeed;

		internal static ManualLogSource Logger;

		private Harmony harmony;

		private void Awake()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Color Cozy Lights has loaded! Checking and setting configs.");
			colorConfigR = ((BaseUnityPlugin)this).Config.Bind<int>("Cozy Light Color", "Cozy Lights Color - R", 53, "RGB value (0-255) for Red. YOU DONT NEED TO RESET THE GAME");
			colorConfigG = ((BaseUnityPlugin)this).Config.Bind<int>("Cozy Light Color", "Cozy Lights Color - G", 135, "RGB value (0-255) for Green. YOU DONT NEED TO RESET THE GAME");
			colorConfigB = ((BaseUnityPlugin)this).Config.Bind<int>("Cozy Light Color", "Cozy Lights Color - B", 255, "RGB value (0-255) for Blue. YOU DONT NEED TO RESET THE GAME");
			Rainbow = ((BaseUnityPlugin)this).Config.Bind<bool>("Cozy Light Color", "Rainbow", false, "Cycles through colors!. YOU DONT NEED TO RESET THE GAME");
			RainbowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Cozy Light Color", "Rainbow Speed", 0.05f, "Sets the speed of the rainbow, I am not responsible for any seizures people have for high amounts. YOU DONT NEED TO RESET THE GAME");
			harmony = new Harmony("com.atomic.colorcozylights.patch");
			harmony.PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "SampleSceneRelay")
			{
				GameObject val = GameObject.Find("Environment");
				val.AddComponent<CozyLightsManager>();
			}
		}
	}
	public class CozyLightsManager : MonoBehaviour
	{
		private float normalizedR;

		private float normalizedG;

		private float normalizedB;

		private float hue = 0f;

		private float rainbowSpeed = Plugin.RainbowSpeed.Value;

		private void Awake()
		{
			Initialize();
		}

		private void Update()
		{
			//IL_0068: 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_006f: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Rainbow.Value)
			{
				rainbowSpeed = Plugin.RainbowSpeed.Value;
				hue += rainbowSpeed * Time.deltaTime;
				if (hue > 1f)
				{
					hue = 0f;
				}
				Color val = Color.HSVToRGB(hue, 0.8f, 0.8f);
				normalizedR = val.r;
				normalizedG = val.g;
				normalizedB = val.b;
				SetCozyLights();
			}
		}

		public void Initialize()
		{
			SetCozyLights();
			normalizedR = (float)Plugin.colorConfigR.Value / 100f;
			normalizedG = (float)Plugin.colorConfigG.Value / 100f;
			normalizedB = (float)Plugin.colorConfigB.Value / 100f;
		}

		public void SetCozyLights()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("ShipCozyLights(Clone)");
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			foreach (Transform item in val.transform)
			{
				Transform val2 = item;
				foreach (Transform item2 in val2)
				{
					Transform val3 = item2;
					if (((Object)val3).name == "Light")
					{
						Light component = ((Component)val3).GetComponent<Light>();
						if ((Object)(object)component != (Object)null)
						{
							component.color = (Plugin.Rainbow.Value ? new Color(normalizedR, normalizedG, normalizedB) : new Color(normalizedR, normalizedG, normalizedB));
						}
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Colorable_Cozy_Lights";

		public const string PLUGIN_NAME = "Adds a config to change the color of the cozy lights";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}