Decompiled source of SkipIntro v1.0.0

SkipIntro.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SkipIntro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SkipIntro")]
[assembly: AssemblyTitle("SkipIntro")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SkipIntro
{
	internal static class IntroPatches
	{
		private static bool moved;

		[HarmonyPatch(typeof(PreInitSceneScript), "SkipToFinalSetting")]
		[HarmonyPostfix]
		private static void AutoLaunch(PreInitSceneScript __instance)
		{
			LaunchMode value = Plugin.C.Launch.Value;
			if (value != LaunchMode.Off)
			{
				__instance.ChooseLaunchOption(value == LaunchMode.Online);
			}
		}

		[HarmonyPatch(typeof(PreInitSceneScript), "SetLaunchPanelsEnabled")]
		[HarmonyPrefix]
		private static bool HideLaunchScreen()
		{
			IngamePlayerSettings instance = IngamePlayerSettings.Instance;
			if (Plugin.C.Launch.Value != LaunchMode.Off && !((Object)(object)instance == (Object)null))
			{
				return !instance.settings.playerHasFinishedSetup;
			}
			return true;
		}

		[HarmonyPatch(typeof(InitializeGame), "Start")]
		[HarmonyPrefix]
		private static void SkipBoot(InitializeGame __instance)
		{
			MoveToMonitor();
			if (Plugin.C.SkipBoot.Value && ((!__instance.playColdOpenCinematic && !__instance.playColdOpenCinematic2) || !Plugin.C.PlayStoryScenes.Value))
			{
				__instance.runBootUpScreen = false;
			}
		}

		private static void MoveToMonitor()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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)
			int value = Plugin.C.StartupMonitor.Value;
			if (!moved && value >= 0)
			{
				moved = true;
				List<DisplayInfo> list = new List<DisplayInfo>();
				Screen.GetDisplayLayout(list);
				if (value >= list.Count)
				{
					Plugin.Log.LogWarning((object)$"StartupMonitor {value}: there are only {list.Count} monitors.");
					return;
				}
				DisplayInfo val = list[value];
				Screen.MoveMainWindowTo(ref val, Vector2Int.zero);
			}
		}
	}
	internal static class MenuPatches
	{
		private static Sprite whiteLogo;

		[HarmonyPatch(typeof(MenuManager), "Start")]
		[HarmonyPostfix]
		private static void MenuStart(MenuManager __instance)
		{
			if ((Object)(object)__instance.menuButtons != (Object)null)
			{
				((MonoBehaviour)__instance).StartCoroutine(Setup(__instance));
			}
		}

		[HarmonyPatch(typeof(MenuManager), "ClickHostButton")]
		[HarmonyPostfix]
		private static void Host(MenuManager __instance)
		{
			if (Plugin.C.HideLanWarning.Value && (Object)(object)__instance.lanWarningContainer != (Object)null)
			{
				__instance.lanWarningContainer.SetActive(false);
			}
		}

		private static IEnumerator Setup(MenuManager m)
		{
			yield return null;
			yield return null;
			Cfg c = Plugin.C;
			try
			{
				if (c.HideNews.Value && (Object)(object)m.NewsPanel != (Object)null)
				{
					m.NewsPanel.SetActive(false);
				}
				if (c.HideLanWarning.Value && (Object)(object)m.lanWarningContainer != (Object)null)
				{
					m.lanWarningContainer.SetActive(false);
				}
				if (c.HideLanText.Value && (Object)(object)m.launchedInLanModeText != (Object)null)
				{
					((Component)m.launchedInLanModeText).gameObject.SetActive(false);
				}
				Transform val = m.menuButtons.transform.Find("Credits");
				if (c.HideCredits.Value && (Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(false);
				}
				Transform val2 = m.menuButtons.transform.Find("HeaderImage");
				Vector3 position = (((Object)(object)val2 != (Object)null) ? val2.position : Vector3.zero);
				Transform transform = m.menuButtons.transform;
				Layout((RectTransform)(object)((transform is RectTransform) ? transform : null), (Object)(object)val != (Object)null && c.HideCredits.Value);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.position = position;
				}
				Tint(m);
				Transform val3 = (((Object)(object)m.menuButtons.transform.parent != (Object)null) ? m.menuButtons.transform.parent.Find("LoadingScreen") : null);
				Logo(val2);
				if ((Object)(object)val3 != (Object)null)
				{
					Logo(val3.Find("Image"));
					if (c.Colors.Value)
					{
						TMP_Text[] componentsInChildren = ((Component)val3).GetComponentsInChildren<TMP_Text>(true);
						foreach (TMP_Text val4 in componentsInChildren)
						{
							if ((Object)(object)((Component)val4).GetComponent<KeepColor>() == (Object)null)
							{
								((Component)val4).gameObject.AddComponent<KeepColor>().Set(val4, Cfg.Parse(c.TextColor.Value, ((Graphic)val4).color));
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Menu setup: " + ex.Message));
			}
			if (c.AutoHost.Value)
			{
				m.ClickHostButton();
			}
		}

		private static void Layout(RectTransform panel, bool creditsHidden)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			Cfg c = Plugin.C;
			if ((Object)(object)panel == (Object)null)
			{
				return;
			}
			List<RectTransform> list = (from t in (from Transform t in (IEnumerable)panel
					where ((Component)t).gameObject.activeSelf && (Object)(object)((Component)t).GetComponent<Button>() != (Object)null
					select t).OfType<RectTransform>()
				orderby (((Object)t).name == "QuitButton") ? 1 : 0
				select t).ToList();
			if (list.Count < 2)
			{
				return;
			}
			if (!c.Compact.Value)
			{
				if (creditsHidden)
				{
					float num = list.Min((RectTransform t) => t.anchoredPosition.y);
					for (int num2 = 0; num2 < list.Count; num2++)
					{
						list[num2].anchoredPosition = new Vector2(list[num2].anchoredPosition.x, num + (float)(list.Count - 1 - num2) * 39f);
					}
				}
				return;
			}
			panel.anchorMin = Vector2.zero;
			panel.anchorMax = Vector2.one;
			panel.offsetMin = Vector2.zero;
			panel.offsetMax = Vector2.zero;
			panel.pivot = new Vector2(0.5f, 0.5f);
			panel.anchoredPosition3D = Vector3.zero;
			((Transform)panel).localScale = Vector3.one;
			float value = c.LineHeight.Value;
			float num3 = c.Offset.Value / 100f;
			Rect rect = panel.rect;
			float num4 = num3 * ((Rect)(ref rect)).height - (float)list.Count * value / 2f;
			for (int num5 = 0; num5 < list.Count; num5++)
			{
				RectTransform obj = list[list.Count - 1 - num5];
				obj.anchoredPosition = new Vector2(obj.anchoredPosition.x, num4 + (float)num5 * value);
			}
			Vector3 localPosition = ((Transform)list[0]).localPosition;
			foreach (RectTransform item in list)
			{
				((Transform)item).localPosition = new Vector3(localPosition.x, ((Transform)item).localPosition.y, localPosition.z);
			}
		}

		private static void Logo(Transform t)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)t == (Object)null)
			{
				return;
			}
			Cfg c = Plugin.C;
			float num = Mathf.Clamp(c.LogoScale.Value, 5f, 300f) / 100f;
			if (!Mathf.Approximately(num, 1f))
			{
				t.localScale *= num;
			}
			Image component = ((Component)t).GetComponent<Image>();
			Color color = default(Color);
			if ((Object)(object)component == (Object)null || (Object)(object)component.sprite == (Object)null || !c.LogoRecolor.Value || !ColorUtility.TryParseHtmlString(c.LogoColor.Value.Trim(), ref color))
			{
				return;
			}
			try
			{
				if ((Object)(object)whiteLogo == (Object)null)
				{
					whiteLogo = Whiten(component.sprite);
				}
				component.sprite = whiteLogo;
				((Graphic)component).color = color;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Logo color: " + ex.Message));
			}
		}

		private static Sprite Whiten(Sprite s)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture = s.texture;
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
			Graphics.Blit((Texture)(object)texture, temporary);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), 0, 0);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			Color32[] pixels = val.GetPixels32();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i].r = byte.MaxValue;
				pixels[i].g = byte.MaxValue;
				pixels[i].b = byte.MaxValue;
			}
			val.SetPixels32(pixels);
			((Texture)val).filterMode = ((Texture)texture).filterMode;
			val.Apply(false, true);
			float x = s.pivot.x;
			Rect rect = s.rect;
			float num = x / ((Rect)(ref rect)).width;
			float y = s.pivot.y;
			rect = s.rect;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num, y / ((Rect)(ref rect)).height);
			return Sprite.Create(val, s.rect, val2, s.pixelsPerUnit);
		}

		private static void CenterBottom(TMP_Text text)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rectTransform = text.rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0f);
			rectTransform.anchorMax = val;
			rectTransform.anchorMin = val;
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.sizeDelta = new Vector2(Mathf.Max(rectTransform.sizeDelta.x, 400f), rectTransform.sizeDelta.y);
			rectTransform.anchoredPosition = new Vector2(0f, 4f);
			text.alignment = (TextAlignmentOptions)1026;
			text.enableWordWrapping = false;
		}

		private static void Tint(MenuManager m)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			Cfg c = Plugin.C;
			if ((Object)(object)m.versionNumberText != (Object)null)
			{
				string value = c.VersionText.Value;
				if (!string.IsNullOrEmpty(value))
				{
					((TMP_Text)m.versionNumberText).text = value.Replace("$VERSION", Mathf.Abs(GameNetworkManager.Instance.gameVersionNum).ToString()).Replace("\\n", "\n");
					((TMP_Text)m.versionNumberText).enableWordWrapping = false;
				}
				if (c.Colors.Value)
				{
					((Graphic)m.versionNumberText).color = Cfg.Parse(c.TextColor.Value, ((Graphic)m.versionNumberText).color);
				}
				if (c.VersionCentered.Value)
				{
					CenterBottom((TMP_Text)(object)m.versionNumberText);
				}
			}
			if (!c.Colors.Value)
			{
				return;
			}
			foreach (Transform item in m.menuButtons.transform)
			{
				AddTint(item);
			}
			Transform val = (((Object)(object)m.menuButtons.transform.parent != (Object)null) ? m.menuButtons.transform.parent.Find("SettingsPanel") : null);
			if (!c.ThemeSubMenus.Value || !((Object)(object)val != (Object)null))
			{
				return;
			}
			Button[] componentsInChildren = ((Component)val).GetComponentsInChildren<Button>(true);
			foreach (Button val2 in componentsInChildren)
			{
				if ((Object)(object)((Component)val2).transform.Find("SelectionHighlight") != (Object)null)
				{
					AddTint(((Component)val2).transform);
				}
			}
		}

		private static void AddTint(Transform t)
		{
			if ((Object)(object)((Component)t).GetComponent<Button>() != (Object)null && (Object)(object)((Component)t).GetComponent<Animator>() != (Object)null && (Object)(object)((Component)t).GetComponent<MenuTint>() == (Object)null)
			{
				((Component)t).gameObject.AddComponent<MenuTint>();
			}
		}
	}
	internal class MenuTint : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		private TMP_Text[] labels;

		private Image bar;

		private Color text;

		private Color barColor;

		private Color hiText;

		private void Awake()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			Animator component = ((Component)this).GetComponent<Animator>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			labels = ((Component)this).GetComponentsInChildren<TMP_Text>(true);
			TMP_Text[] array = labels;
			foreach (TMP_Text val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.faceColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
					val.enableVertexGradient = false;
					val.overrideColorTags = true;
				}
			}
			Transform val2 = ((Component)this).transform.Find("SelectionHighlight");
			bar = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Image>() : null);
			Cfg c = Plugin.C;
			text = Cfg.Parse(c.TextColor.Value, new Color(0.9f, 0.39f, 0.25f));
			barColor = Cfg.Parse(c.HighlightColor.Value, text);
			hiText = Cfg.Parse(c.HighlightTextColor.Value, Color.black);
			Paint(lit: false);
		}

		private void OnDisable()
		{
			Paint(lit: false);
		}

		public void OnPointerEnter(PointerEventData e)
		{
			Paint(lit: true);
		}

		public void OnPointerExit(PointerEventData e)
		{
			Paint(lit: false);
		}

		private void Paint(bool lit)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text[] array = labels;
			foreach (TMP_Text val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					((Graphic)val).color = (lit ? hiText : text);
				}
			}
			if ((Object)(object)bar != (Object)null)
			{
				((Behaviour)bar).enabled = lit;
				((Graphic)bar).color = barColor;
			}
		}
	}
	internal class KeepColor : MonoBehaviour
	{
		private TMP_Text text;

		private Color color;

		internal void Set(TMP_Text t, Color c)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			text = t;
			color = c;
			((Graphic)t).color = c;
		}

		private void LateUpdate()
		{
			//IL_0014: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)text != (Object)null && ((Graphic)text).color != color)
			{
				((Graphic)text).color = color;
			}
		}
	}
	public enum LaunchMode
	{
		Off,
		Online,
		LAN
	}
	[BepInPlugin("Miles.SkipIntro", "SkipIntro", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "Miles.SkipIntro";

		public const string Name = "SkipIntro";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static Cfg C;

		private static volatile bool sceneLoaded;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			Log = ((BaseUnityPlugin)this).Logger;
			C = new Cfg(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("Miles.SkipIntro");
			val.PatchAll(typeof(IntroPatches));
			val.PatchAll(typeof(MenuPatches));
			val.PatchAll(typeof(ShipPatches));
			if (C.SkipSplash.Value)
			{
				SceneManager.sceneLoaded += FirstScene;
				Thread thread = new Thread(StopSplash);
				thread.IsBackground = true;
				thread.Name = "SkipIntro splash";
				thread.Start();
			}
			Log.LogInfo((object)"SkipIntro 1.0.0 loaded.");
		}

		private static void FirstScene(Scene s, LoadSceneMode m)
		{
			if (!(((Scene)(ref s)).name != "InitScene") || !(((Scene)(ref s)).name != "InitSceneLANMode") || !(((Scene)(ref s)).name != "MainMenu"))
			{
				sceneLoaded = true;
				SceneManager.sceneLoaded -= FirstScene;
			}
		}

		private static void StopSplash()
		{
			Stopwatch stopwatch = Stopwatch.StartNew();
			while (!sceneLoaded && stopwatch.Elapsed.TotalSeconds < 60.0)
			{
				try
				{
					SplashScreen.Stop((StopBehavior)0);
				}
				catch
				{
				}
				Thread.Sleep(1);
			}
		}
	}
	internal class Cfg
	{
		internal readonly ConfigEntry<bool> SkipSplash;

		internal readonly ConfigEntry<bool> SkipBoot;

		internal readonly ConfigEntry<bool> PlayStoryScenes;

		internal readonly ConfigEntry<bool> AutoHost;

		internal readonly ConfigEntry<bool> HideLanWarning;

		internal readonly ConfigEntry<bool> HideLanText;

		internal readonly ConfigEntry<bool> HideNews;

		internal readonly ConfigEntry<bool> HideCredits;

		internal readonly ConfigEntry<LaunchMode> Launch;

		internal readonly ConfigEntry<bool> Compact;

		internal readonly ConfigEntry<float> LineHeight;

		internal readonly ConfigEntry<float> Offset;

		internal readonly ConfigEntry<bool> Colors;

		internal readonly ConfigEntry<bool> LogoRecolor;

		internal readonly ConfigEntry<bool> VersionCentered;

		internal readonly ConfigEntry<bool> ThemeSubMenus;

		internal readonly ConfigEntry<string> TextColor;

		internal readonly ConfigEntry<string> HighlightColor;

		internal readonly ConfigEntry<string> HighlightTextColor;

		internal readonly ConfigEntry<string> VersionText;

		internal readonly ConfigEntry<string> LogoColor;

		internal readonly ConfigEntry<float> LogoScale;

		internal readonly ConfigEntry<bool> AutoStart;

		internal readonly ConfigEntry<bool> NoFirstDaySpeaker;

		internal readonly ConfigEntry<float> AutoStartDelay;

		internal readonly ConfigEntry<int> StartupMonitor;

		internal Cfg(ConfigFile c)
		{
			SkipSplash = c.Bind<bool>("Intro", "SkipSplashScreens", true, "Skip the Unity and Zeekerss logos.");
			SkipBoot = c.Bind<bool>("Intro", "SkipBootAnimation", true, "Skip the booting-up computer screen.");
			PlayStoryScenes = c.Bind<bool>("Intro", "PlayStoryScenes", true, "Still play v81's one-time story scenes (cold opens) on the launch they're due. False = skip those too (you'd miss them for good).");
			Launch = c.Bind<LaunchMode>("Intro", "AutoLaunchMode", LaunchMode.Online, "Pick the launch mode for you: Online, LAN, or Off (ask like vanilla).");
			AutoHost = c.Bind<bool>("Intro", "AutoOpenHost", false, "Open the Host screen as soon as the menu loads.");
			StartupMonitor = c.Bind<int>("Intro", "StartupMonitor", -1, "Open the game on this monitor (0 = first, 1 = second...). -1 = don't move it.");
			HideCredits = c.Bind<bool>("Menu", "HideCredits", true, "Hide the Credits button.");
			HideLanWarning = c.Bind<bool>("Menu", "HideLanWarning", true, "Hide the warning popup when hosting a LAN game.");
			HideLanText = c.Bind<bool>("Menu", "HideLaunchedInLanText", true, "Hide the 'Launched in LAN mode' text.");
			HideNews = c.Bind<bool>("Menu", "HideNews", false, "Hide the news panel.");
			Compact = c.Bind<bool>("Menu", "CompactMenu", true, "Lay out the main menu buttons like Emblem: evenly spaced, centered at Offset, lined up on the left.");
			LineHeight = c.Bind<float>("Menu", "LineHeight", 40f, "Space between main menu buttons. Lower squishes the menu.");
			Offset = c.Bind<float>("Menu", "Offset", 30f, "Where the middle of the menu sits, in percent of the screen from the bottom (50 = centered).");
			VersionText = c.Bind<string>("Menu", "VersionText", "", "Version text on the menu. Use $VERSION for the number, e.g. [v$VERSION]. Empty = vanilla.");
			VersionCentered = c.Bind<bool>("Menu", "VersionCentered", true, "Move the version text to the bottom middle of the screen.");
			Colors = c.Bind<bool>("Menu Colors", "Enabled", true, "Use the colors below for the main menu.");
			TextColor = c.Bind<string>("Menu Colors", "Text", "#E66441", "Button text (hex, like #RRGGBB or #RRGGBBAA). Also used for the version and loading text.");
			HighlightColor = c.Bind<string>("Menu Colors", "Highlight", "#E66441", "Bar behind the button you point at.");
			HighlightTextColor = c.Bind<string>("Menu Colors", "HighlightText", "#000000", "Text of the button you point at.");
			ThemeSubMenus = c.Bind<bool>("Menu Colors", "SubMenus", true, "Use these colors for the buttons in the Settings menu too.");
			LogoScale = c.Bind<float>("Logo", "Scale", 70f, "Size of the Lethal Company logo on the menu and loading screen, in percent of vanilla.");
			LogoRecolor = c.Bind<bool>("Logo", "Recolor", false, "Paint the logo in the color below instead of the original red.");
			LogoColor = c.Bind<string>("Logo", "Color", "#FF3600", "Logo color when Recolor is on (hex). #FF3600 = the vanilla logo, #FFFFFF = white.");
			AutoStart = c.Bind<bool>("Ship", "AutoPullLever", false, "Pull the ship lever by itself when you're on the ship at the start (host).");
			AutoStartDelay = c.Bind<float>("Ship", "AutoPullLeverDelay", 1.5f, "Seconds before the lever is pulled.");
			NoFirstDaySpeaker = c.Bind<bool>("Ship", "MuteFirstDaySpeaker", false, "Stop the ship speaker's first-day message.");
		}

		internal static Color Parse(string hex, Color fallback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (!ColorUtility.TryParseHtmlString((hex ?? "").Trim(), ref result))
			{
				return fallback;
			}
			return result;
		}
	}
	internal static class ShipPatches
	{
		[HarmonyPatch(typeof(StartMatchLever), "Start")]
		[HarmonyPostfix]
		private static void LeverStart(StartMatchLever __instance)
		{
			if (Plugin.C.AutoStart.Value && (Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsHost)
			{
				((MonoBehaviour)__instance).StartCoroutine(Pull(__instance));
			}
		}

		private static IEnumerator Pull(StartMatchLever lever)
		{
			yield return (object)new WaitForSeconds(Mathf.Clamp(Plugin.C.AutoStartDelay.Value, 1f, 30f));
			if (!lever.leverHasBeenPulled)
			{
				lever.leverAnimatorObject.SetBool("pullLever", true);
				lever.leverHasBeenPulled = true;
				lever.triggerScript.interactable = false;
				lever.PullLever();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "firstDayAnimation")]
		[HarmonyPrefix]
		private static bool FirstDay(ref IEnumerator __result)
		{
			if (!Plugin.C.NoFirstDaySpeaker.Value)
			{
				return true;
			}
			__result = Nothing();
			return false;
		}

		private static IEnumerator Nothing()
		{
			yield break;
		}
	}
}