Decompiled source of Skip Intro Video v1.0.2

SkipIntroVideo.dll

Decompiled 3 days ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SkipIntroVideo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+92471370a2fe857c1c8c0695256914b6f5f32373")]
[assembly: AssemblyProduct("SkipIntroVideo")]
[assembly: AssemblyTitle("SkipIntroVideo")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
internal static class ModInfo
{
	internal const string PLUGIN_GUID = "com.maxgerman.skipintrovideo";

	internal const string PLUGIN_NAME = "Skip Intro Video";

	internal const string PLUGIN_VERSION = "1.0.2";

	internal const string ASSEMBLY_VERSION = "1.0.2";

	internal const string FILE_VERSION = "1.0.2";

	internal const string INFORMATIONAL_VERSION = "1.0.2";

	internal const string HARMONY_ID = "com.maxgerman.skipintrovideo";

	internal const string LOG_PREFIX = "[Skip Intro] ";

	internal const string DISPLAY_NAME_SHORT = "Skip Intro";

	internal const string DISPLAY_NAME_LONG = "Skip Intro Video";
}
internal static class ModLog
{
	private static readonly ManualLogSource _bepInExLogger = Logger.CreateLogSource("Skip Intro Video");

	internal static void Log(string message, string tag = "")
	{
		_bepInExLogger.LogMessage((object)FormatMessage(message, tag));
	}

	internal static void Warn(string message, string tag = "")
	{
		_bepInExLogger.LogWarning((object)FormatMessage(message, tag));
	}

	internal static void Error(string message, string tag = "")
	{
		_bepInExLogger.LogError((object)FormatMessage(message, tag));
	}

	private static string FormatMessage(string message, string tag)
	{
		if (string.IsNullOrEmpty(tag))
		{
			return message;
		}
		return "[" + tag + "] " + message;
	}
}
namespace SkipIntroVideo
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SkipIntroVideo";

		public const string PLUGIN_NAME = "SkipIntroVideo";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SkipIntro
{
	[BepInPlugin("com.maxgerman.skipintrovideo", "Skip Intro Video", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(SceneLoader), "Awake")]
		private static class SceneLoaderPatches
		{
			private static void Postfix(SceneLoader __instance)
			{
				try
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(SceneLoader), "_showLogos");
					if (fieldInfo == null)
					{
						ModLog.Log("SceneLoader._showLogos field not found.");
						return;
					}
					fieldInfo.SetValue(__instance, false);
					ModLog.Log("SceneLoader logos disabled.");
				}
				catch (Exception arg)
				{
					ModLog.Log($"Error while disabling SceneLoader logos: {arg}");
				}
			}
		}

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			try
			{
				_harmony = new Harmony("com.maxgerman.skipintrovideo");
				_harmony.PatchAll(typeof(SceneLoaderPatches));
				PatchIntroCinematic();
				ModLog.Log("SkipIntro initialized successfully.");
			}
			catch (Exception arg)
			{
				ModLog.Log($"Error while initializing SkipIntro: {arg}");
			}
		}

		private void PatchIntroCinematic()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			try
			{
				Type type = FindType("FejdStartup");
				if (type == null)
				{
					ModLog.Log("FejdStartup type not found.");
					return;
				}
				Type type2 = type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((Type type3) => type3.Name.Contains("PlayIntroCinematic"));
				if (type2 == null)
				{
					ModLog.Log("PlayIntroCinematic coroutine type not found.");
					return;
				}
				ModLog.Log("Found coroutine: " + type2.FullName);
				MethodInfo method = type2.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					ModLog.Log("MoveNext method not found.");
					return;
				}
				_harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(Plugin), "SkipIntro", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ModLog.Log("PlayIntroCinematic patch applied successfully.");
			}
			catch (Exception arg)
			{
				ModLog.Log($"Error while patching intro cinematic: {arg}");
			}
		}

		private static bool SkipIntro()
		{
			ModLog.Log("Intro cinematic skipped.");
			return false;
		}

		private static Type FindType(string typeName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					Type type = assembly.GetTypes().FirstOrDefault((Type candidate) => candidate.Name == typeName);
					if (type != null)
					{
						return type;
					}
				}
				catch
				{
				}
			}
			return null;
		}
	}
}