Decompiled source of DimmableLights v0.0.2

DimmableLights.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 CG;
using CG.Game;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[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("DimmableLights")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DimmableLights")]
[assembly: AssemblyTitle("DimmableLights")]
[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 DimmableLights
{
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.dimmablelights";

		internal const string PLUGIN_NAME = "DimmableLights";

		internal const string PLUGIN_VERSION = "0.0.2";
	}
	[BepInPlugin("id107.dimmablelights", "DimmableLights", "0.0.2")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.dimmablelights");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.dimmablelights is loaded!");
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<float> brightnessConfig;

		internal static Color Brightness { get; private set; }

		internal static void Load(BepinPlugin plugin)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			brightnessConfig = ((BaseUnityPlugin)plugin).Config.Bind<float>("DimmableLights", "brightness", 1f, (ConfigDescription)null);
			brightnessConfig.SettingChanged += delegate
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				Brightness = new Color(brightnessConfig.Value, brightnessConfig.Value, brightnessConfig.Value, 1f);
			};
			Brightness = new Color(brightnessConfig.Value, brightnessConfig.Value, brightnessConfig.Value, 1f);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Dimmable Lights";
		}

		public override void Draw()
		{
			GUILayout.Label($"Ship Brightness: {Configs.brightnessConfig.Value * 100f:0}%", Array.Empty<GUILayoutOption>());
			GUITools.DrawSlider(ref Configs.brightnessConfig, 0f, 1f);
		}
	}
	internal class LightManager
	{
		private static Dictionary<Light, (Color defaultColor, Color lastColor)> shipLights;

		internal static void SetShipLights()
		{
			ClientGame current = ClientGame.Current;
			object obj;
			if (current == null)
			{
				obj = null;
			}
			else
			{
				AbstractPlayerControlledShip playerShip = current.PlayerShip;
				if (playerShip == null)
				{
					obj = null;
				}
				else
				{
					GameObject gameObject = ((AbstractCloneStarObject)playerShip).GameObject;
					obj = ((gameObject == null) ? null : gameObject.GetComponentsInChildren<Light>()?.ToDictionary((Func<Light, Light>)((Light light) => light), (Func<Light, (Color, Color)>)((Light light) => (light.color, new Color(0f, 0f, 0f, 0f)))));
				}
			}
			shipLights = (Dictionary<Light, (Color defaultColor, Color lastColor)>)obj;
		}

		internal static void CheckLights(object sender, EventArgs e)
		{
			if (shipLights != null && shipLights.Count != 0 && !(Configs.brightnessConfig.Value >= 0.995f))
			{
				FixAllLights();
			}
		}

		private static void CheckFixLight(Light light, (Color defaultColor, Color lastColor) color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (light.color != color.lastColor)
			{
				color.defaultColor = light.color;
				color.lastColor = color.defaultColor * Configs.Brightness;
				shipLights[light] = (color.defaultColor, color.lastColor);
				light.color = color.lastColor;
			}
			else if (light.color != color.defaultColor * Configs.Brightness)
			{
				color.lastColor = color.defaultColor * Configs.Brightness;
				shipLights[light] = (color.defaultColor, color.lastColor);
				light.color = color.lastColor;
			}
		}

		private static void FixAllLights()
		{
			for (int i = 0; i < shipLights.Count; i++)
			{
				KeyValuePair<Light, (Color, Color)> keyValuePair = shipLights.ElementAt(i);
				if (!((Object)(object)keyValuePair.Key == (Object)null))
				{
					CheckFixLight(keyValuePair.Key, keyValuePair.Value);
				}
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PlayerShipPatch
	{
		private static void Postfix()
		{
			Tools.DelayDo((Action)LightManager.SetShipLights, 2000.0);
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)3;

		public override string Author => "18107";

		public override string Description => "Allows ship lights to be dimmed";

		public VoidManagerPlugin()
		{
			Events.Instance.LateUpdate += LightManager.CheckLights;
		}
	}
}