Decompiled source of Colorable CozyLights v1.0.3

BepInEx/Plugins/Colorable_Cozy_Lights.dll

Decompiled 3 weeks 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 ConfigEntry<float> Brightness;

		internal static ManualLogSource Logger;

		private Harmony harmony;

		private void Awake()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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");
			Brightness = ((BaseUnityPlugin)this).Config.Bind<float>("Cozy Light Color", "Cozy Lights Brightness", 138f, "Decimals allowed. Brightness off the light. Please don't surpass 1000, its too bright. 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 float brightness = 0f;

		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()
		{
			normalizedR = (float)Plugin.colorConfigR.Value / 100f;
			normalizedG = (float)Plugin.colorConfigG.Value / 100f;
			normalizedB = (float)Plugin.colorConfigB.Value / 100f;
			SetCozyLights();
		}

		public void SetCozyLights()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			brightness = Plugin.Brightness.Value;
			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.intensity = brightness;
							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";
	}
}