Decompiled source of JevIntroSkip v1.0.6

JevIntroSkip.dll

Decompiled 4 days ago
using System;
using System.Collections;
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 HarmonyLib;
using JevIntroSkip.Config;
using JevIntroSkip.Features;
using JevIntroSkip.Infrastructure;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("JevIntroSkip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+dfe460ebef828152ab2a086a1b69735da66818b3")]
[assembly: AssemblyProduct("JevIntroSkip")]
[assembly: AssemblyTitle("JevIntroSkip")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[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 JevIntroSkip
{
	[BepInPlugin("JevMods.JevIntroSkip", "JevIntroSkip", "1.0.6")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "JevMods.JevIntroSkip";

		public const string PluginName = "JevIntroSkip";

		private IFeature[] _features;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			GameEvents events = (GameEvents.Instance = new GameEvents());
			ModSettings settings = new ModSettings(((BaseUnityPlugin)this).Config);
			_features = new IFeature[4]
			{
				new LogoSkipFeature(events, settings),
				new CinematicSkipFeature(events, settings),
				new LoreTextSkipFeature(events, settings),
				new ValkyrieFlightSkipFeature(events, settings)
			};
			IFeature[] features = _features;
			for (int i = 0; i < features.Length; i++)
			{
				features[i].Enable();
			}
			_harmony = new Harmony("JevMods.JevIntroSkip");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if (_features != null)
			{
				IFeature[] features = _features;
				for (int i = 0; i < features.Length; i++)
				{
					features[i].Disable();
				}
			}
			GameEvents.Instance = null;
		}
	}
	internal static class BuildInfo
	{
		public const string Version = "1.0.6";
	}
}
namespace JevIntroSkip.Patches
{
	internal static class FejdStartupPatches
	{
		[HarmonyPatch(typeof(FejdStartup), "TryPlayIntroCinematic")]
		private static class TryPlayIntroCinematic
		{
			private static void Prefix()
			{
				GameEvents.Instance?.RaiseStartupCinematicStarting();
			}
		}
	}
	internal static class GamePatches
	{
		[HarmonyPatch(typeof(Game), "ShowIntro")]
		private static class ShowIntro
		{
			private static bool Prefix(Game __instance)
			{
				bool skip = false;
				GameEvents.Instance?.RaiseIntroShowing(__instance, ref skip);
				return !skip;
			}
		}

		[HarmonyPatch(typeof(Game), "SpawnPlayer")]
		private static class SpawnPlayer
		{
			private static void Prefix(ref bool spawnValkyrie)
			{
				GameEvents.Instance?.RaisePlayerSpawning(ref spawnValkyrie);
			}
		}
	}
	internal static class SceneLoaderPatches
	{
		[HarmonyPatch(typeof(SceneLoader), "FadeLogo")]
		private static class FadeLogo
		{
			private static bool Prefix(ref IEnumerator __result)
			{
				bool skip = false;
				GameEvents.Instance?.RaiseLogoFading(ref skip);
				if (skip)
				{
					__result = Enumerable.Empty<object>().GetEnumerator();
				}
				return !skip;
			}
		}
	}
}
namespace JevIntroSkip.Infrastructure
{
	public sealed class GameEvents : IGameEvents
	{
		internal static GameEvents Instance { get; set; }

		public event LogoFadingHandler LogoFading;

		public event Action StartupCinematicStarting;

		public event IntroShowingHandler IntroShowing;

		public event PlayerSpawningHandler PlayerSpawning;

		internal void RaiseLogoFading(ref bool skip)
		{
			this.LogoFading?.Invoke(ref skip);
		}

		internal void RaiseStartupCinematicStarting()
		{
			this.StartupCinematicStarting?.Invoke();
		}

		internal void RaiseIntroShowing(Game game, ref bool skip)
		{
			this.IntroShowing?.Invoke(game, ref skip);
		}

		internal void RaisePlayerSpawning(ref bool spawnValkyrie)
		{
			this.PlayerSpawning?.Invoke(ref spawnValkyrie);
		}
	}
	public interface IGameEvents
	{
		event LogoFadingHandler LogoFading;

		event Action StartupCinematicStarting;

		event IntroShowingHandler IntroShowing;

		event PlayerSpawningHandler PlayerSpawning;
	}
	public delegate void IntroShowingHandler(Game game, ref bool skip);
	public delegate void LogoFadingHandler(ref bool skip);
	public delegate void PlayerSpawningHandler(ref bool spawnValkyrie);
}
namespace JevIntroSkip.Features
{
	public sealed class CinematicSkipFeature : IFeature
	{
		private readonly IGameEvents _events;

		private readonly IModSettings _settings;

		public CinematicSkipFeature(IGameEvents events, IModSettings settings)
		{
			_events = events;
			_settings = settings;
		}

		public void Enable()
		{
			_events.StartupCinematicStarting += OnStartupCinematicStarting;
		}

		public void Disable()
		{
			_events.StartupCinematicStarting -= OnStartupCinematicStarting;
		}

		private void OnStartupCinematicStarting()
		{
			if (_settings.SkipCinematic)
			{
				Game.m_hasStartedOnce = true;
			}
		}
	}
	public interface IFeature
	{
		void Enable();

		void Disable();
	}
	public sealed class LogoSkipFeature : IFeature
	{
		private readonly IGameEvents _events;

		private readonly IModSettings _settings;

		public LogoSkipFeature(IGameEvents events, IModSettings settings)
		{
			_events = events;
			_settings = settings;
		}

		public void Enable()
		{
			_events.LogoFading += OnLogoFading;
		}

		public void Disable()
		{
			_events.LogoFading -= OnLogoFading;
		}

		private void OnLogoFading(ref bool skip)
		{
			skip = _settings.SkipLogos;
		}
	}
	public sealed class LoreTextSkipFeature : IFeature
	{
		private readonly IGameEvents _events;

		private readonly IModSettings _settings;

		public LoreTextSkipFeature(IGameEvents events, IModSettings settings)
		{
			_events = events;
			_settings = settings;
		}

		public void Enable()
		{
			_events.IntroShowing += OnIntroShowing;
		}

		public void Disable()
		{
			_events.IntroShowing -= OnIntroShowing;
		}

		private void OnIntroShowing(Game game, ref bool skip)
		{
			if (_settings.SkipLoreText)
			{
				game.m_inIntro = true;
				skip = true;
			}
		}
	}
	public sealed class ValkyrieFlightSkipFeature : IFeature
	{
		private readonly IGameEvents _events;

		private readonly IModSettings _settings;

		public ValkyrieFlightSkipFeature(IGameEvents events, IModSettings settings)
		{
			_events = events;
			_settings = settings;
		}

		public void Enable()
		{
			_events.PlayerSpawning += OnPlayerSpawning;
		}

		public void Disable()
		{
			_events.PlayerSpawning -= OnPlayerSpawning;
		}

		private void OnPlayerSpawning(ref bool spawnValkyrie)
		{
			if (_settings.SkipValkyrieFlight)
			{
				spawnValkyrie = false;
			}
		}
	}
}
namespace JevIntroSkip.Config
{
	public interface IModSettings
	{
		bool SkipLogos { get; }

		bool SkipCinematic { get; }

		bool SkipLoreText { get; }

		bool SkipValkyrieFlight { get; }
	}
	public sealed class ModSettings : IModSettings
	{
		private readonly ConfigEntry<bool> _skipLogos;

		private readonly ConfigEntry<bool> _skipCinematic;

		private readonly ConfigEntry<bool> _skipLoreText;

		private readonly ConfigEntry<bool> _skipValkyrieFlight;

		public bool SkipLogos => _skipLogos.Value;

		public bool SkipCinematic => _skipCinematic.Value;

		public bool SkipLoreText => _skipLoreText.Value;

		public bool SkipValkyrieFlight => _skipValkyrieFlight.Value;

		public ModSettings(ConfigFile file)
		{
			_skipLogos = file.Bind<bool>("Startup", "SkipLogos", true, "Skips the Coffee Stain and Iron Gate logos shown when the game starts.");
			_skipCinematic = file.Bind<bool>("Startup", "SkipCinematic", true, "Skips the intro cinematic video shown before the main menu.");
			_skipLoreText = file.Bind<bool>("NewWorld", "SkipLoreText", true, "Skips the lore text shown when a new character enters a world.");
			_skipValkyrieFlight = file.Bind<bool>("NewWorld", "SkipValkyrieFlight", true, "Skips the Valkyrie flight and spawns a new character straight at the start point.");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}