Decompiled source of SkipIntro v0.1.2

plugins/SkipIntro.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.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
{
	[BepInPlugin("chistix.skipintro", "SkipIntro", "0.1.2")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "chistix.skipintro";

		public const string Version = "0.1.2";

		private static ManualLogSource log;

		internal static ConfigEntry<bool> IntroVideo;

		internal static ConfigEntry<bool> Logos;

		private static FieldInfo showLogos;

		private static FieldInfo showHealthWarning;

		private static FieldInfo showSaveNotification;

		private static FieldInfo logosSkippable;

		private static FieldInfo skipAllAtOnce;

		private static FieldInfo skipped;

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_013c: Expected O, but got Unknown
			log = ((BaseUnityPlugin)this).Logger;
			IntroVideo = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IntroVideo", false, new ConfigDescription("The intro video on the first main menu after the game starts. Off: no video, the menu shows at once, as with the game's own setting \"Skip intro cinematic\" (that setting is not changed). Takes effect at the next start of the game. / Вступительный ролик при первом заходе в главное меню после запуска игры. Выключено - ролика нет, меню появляется сразу, как при игровой настройке «Пропускать вступительный ролик» (сама настройка игры не меняется). Действует со следующего запуска игры.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			Logos = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Logos", false, new ConfigDescription("The splash screens at start: the Coffee Stain and Iron Gate logos (2 seconds each) and the notice screens before loading, where the platform shows them. Off: none of them, the main menu starts loading at once. The Valheim logo with the loading bar stays: that is the real loading of the menu. Takes effect at the next start of the game. / Заставки при запуске: логотипы Coffee Stain и Iron Gate (по 2 секунды каждый) и экраны-предупреждения перед загрузкой, если платформа их показывает. Выключено - заставок нет, сразу идёт загрузка главного меню. Экран с логотипом Valheim и полосой загрузки остаётся: это настоящая загрузка меню. Действует со следующего запуска игры.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			showLogos = Flag("_showLogos");
			showHealthWarning = Flag("_showHealthWarning");
			showSaveNotification = Flag("_showSaveNotification");
			logosSkippable = Flag("_logosSkippable");
			skipAllAtOnce = Flag("_skipAllAtOnce");
			skipped = Flag("_skipped");
			Harmony val = new Harmony("chistix.skipintro");
			Patch(val, AccessTools.Method(typeof(FejdStartup), "TryPlayIntroCinematic", (Type[])null, (Type[])null), "IntroPrefix", prefix: true, "intro video");
			Patch(val, AccessTools.Method(typeof(SceneLoader), "Awake", (Type[])null, (Type[])null), "LoaderAwakePostfix", prefix: false, "splash logos");
			if (!Logos.Value)
			{
				SceneLoader[] array = Object.FindObjectsByType<SceneLoader>((FindObjectsSortMode)0);
				foreach (SceneLoader loader in array)
				{
					NoSplash(loader);
					Set(loader, logosSkippable, value: true);
					Set(loader, skipAllAtOnce, value: true);
					Set(loader, skipped, value: true);
					log.LogInfo((object)"Splash logos already on screen: cut short");
				}
			}
			log.LogInfo((object)("SkipIntro 0.1.2: intro video " + (IntroVideo.Value ? "shown" : "skipped") + ", splash logos " + (Logos.Value ? "shown" : "skipped")));
		}

		private static void LoaderAwakePostfix(SceneLoader __instance)
		{
			if (!Logos.Value)
			{
				NoSplash(__instance);
				log.LogInfo((object)"Splash logos skipped");
			}
		}

		private static void NoSplash(SceneLoader loader)
		{
			Set(loader, showLogos, value: false);
			Set(loader, showSaveNotification, value: false);
			Set(loader, showHealthWarning, value: false);
		}

		private static bool IntroPrefix(FejdStartup __instance, ref IEnumerator __result)
		{
			if (IntroVideo.Value)
			{
				return true;
			}
			__result = MenuAtOnce(__instance);
			return false;
		}

		private static IEnumerator MenuAtOnce(FejdStartup menu)
		{
			if (!Game.m_hasStartedOnce)
			{
				log.LogInfo((object)"Intro video skipped");
			}
			if ((Object)(object)menu != (Object)null && (Object)(object)menu.m_menuAnimator != (Object)null)
			{
				menu.m_menuAnimator.SetTrigger("FadeIn");
			}
			yield break;
		}

		private static FieldInfo Flag(string name)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(SceneLoader), name);
			if (fieldInfo != null && fieldInfo.FieldType == typeof(bool) && !fieldInfo.IsStatic)
			{
				return fieldInfo;
			}
			log.LogWarning((object)("SceneLoader." + name + " not found (the game changed?): that part of the splash stays as in the game"));
			return null;
		}

		private static void Set(SceneLoader loader, FieldInfo field, bool value)
		{
			if (field == null || (Object)(object)loader == (Object)null)
			{
				return;
			}
			try
			{
				field.SetValue(loader, value);
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("SceneLoader." + field.Name + ": " + ex.Message));
			}
		}

		private static void Patch(Harmony harmony, MethodBase target, string patch, bool prefix, string what)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (target == null)
			{
				log.LogWarning((object)("No game method for the " + what + " (the game changed?): it stays as in the game"));
				return;
			}
			try
			{
				HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(Plugin), patch, (Type[])null, (Type[])null));
				harmony.Patch(target, prefix ? val : null, prefix ? null : val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("Could not hook the " + what + " (" + target.DeclaringType?.Name + "." + target.Name + "): " + ex.Message));
			}
		}
	}
	internal sealed class ConfigurationManagerAttributes
	{
		public int? Order;
	}
}