Decompiled source of Engine Trim Color v1.0.0

EngineTrimColor.dll

Decompiled 6 days 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.Client.Player.Interactions;
using CG.Client.Ship.Views;
using CG.Game;
using CG.Space;
using Gameplay.Ship;
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("Engine_Trim_Color")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Engine_Trim_Color")]
[assembly: AssemblyTitle("Engine_Trim_Color")]
[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 Engine_Trim_Color
{
	[HarmonyPatch(typeof(AbstractPlayerControlledShip), "Awake")]
	internal class AbstractPlayerControlledShipPatch
	{
		private static void Postfix()
		{
			Configs.UpdateColorConfig();
		}
	}
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.enginetrimcolor";

		internal const string PLUGIN_NAME = "Engine Trim Color";

		internal const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("id107.enginetrimcolor", "Engine Trim Color", "1.0.0")]
	[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.enginetrimcolor");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.enginetrimcolor is loaded!");
		}
	}
	internal class Configs
	{
		private static readonly FieldInfo diodeSetting = AccessTools.Field(typeof(Diode), "setting");

		private static readonly FieldInfo settingNeutralColor = AccessTools.Field(typeof(DiodeSetting), "neutralColor");

		internal static Color DefaultColor = new Color(0f, 4f, 10f, 1f);

		internal static Color CurrentColor;

		internal static ConfigEntry<float> TrimColorR;

		internal static ConfigEntry<float> TrimColorG;

		internal static ConfigEntry<float> TrimColorB;

		internal static void UpdateColorConfig()
		{
			TrimColorR.Value = CurrentColor.r;
			TrimColorG.Value = CurrentColor.g;
			TrimColorB.Value = CurrentColor.b;
			try
			{
				Diode[] componentsInChildren = ((Component)(from a in ((AbstractCloneStarObject)((AbstractCloneStarObject)ClientGame.Current.PlayerShip).GameObject.GetComponentInChildren<ShipEngine>()).GameObject.GetComponentsInChildren<AbstractInteractable>()
					where ((Object)a).name == "TrimAdvisoryPanel"
					select a).First()).gameObject.GetComponentsInChildren<Diode>();
				IEnumerable<DiodeSetting> enumerable = ((IEnumerable<Diode>)componentsInChildren).Select((Func<Diode, DiodeSetting>)((Diode d) => (DiodeSetting)diodeSetting.GetValue(d))).Distinct();
				CollectionExtensions.Do<DiodeSetting>(enumerable, (Action<DiodeSetting>)delegate(DiodeSetting setting)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					settingNeutralColor.SetValue(setting, CurrentColor);
				});
				CollectionExtensions.Do<Diode>((IEnumerable<Diode>)componentsInChildren, (Action<Diode>)delegate(Diode d)
				{
					d.SetPoweredColorNegative();
					d.SetPoweredColorNeutral();
				});
			}
			catch (NullReferenceException)
			{
			}
		}

		internal static void Load(BepinPlugin plugin)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			TrimColorR = ((BaseUnityPlugin)plugin).Config.Bind<float>("TrimColor", "TrimColorR", DefaultColor.r, (ConfigDescription)null);
			TrimColorG = ((BaseUnityPlugin)plugin).Config.Bind<float>("TrimColor", "TrimColorG", DefaultColor.g, (ConfigDescription)null);
			TrimColorB = ((BaseUnityPlugin)plugin).Config.Bind<float>("TrimColor", "TrimColorB", DefaultColor.b, (ConfigDescription)null);
			CurrentColor = new Color(TrimColorR.Value, TrimColorG.Value, TrimColorB.Value, 1f);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Engine Trim Color";
		}

		public override void Draw()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (GUITools.DrawColorPicker(new Rect(8f, 58f, 480f, 160f), "Engine Trim Color", ref Configs.CurrentColor, Configs.DefaultColor, false, 0f, 20f))
			{
				Configs.UpdateColorConfig();
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "18107";

		public override string Description => "Makes the engine trim colors customisable";
	}
}