Decompiled source of SBGIntroSkip v0.1.0

Mods/SBGIntroSkip.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using SBGIntroSkip;
using UnityEngine;
using UnityEngine.Playables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(IntroSkipMod), "SBG Intro Skip", "0.1.0", "OpenAI", null)]
[assembly: MelonGame(null, "Super Battle Golf")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 SBGIntroSkip
{
	public sealed class IntroSkipMod : MelonMod
	{
		[HarmonyPatch(typeof(MainMenu), "Start")]
		private static class MainMenuStartPatch
		{
			private static void Postfix(MainMenu __instance)
			{
				if (IsEnabled() && !((Object)(object)__instance == (Object)null))
				{
					if (HasPendingLobbyJoin())
					{
						MelonLogger.Msg("Skipping intro patch for menu load with pending Steam lobby join.");
						return;
					}
					__instance.OnIntroMenuShown();
					HideIntroPresentation(__instance);
					MelonLogger.Msg("Skipped main menu intro.");
				}
			}
		}

		private static readonly FieldInfo StartupPlayableDirectorField = AccessTools.Field(typeof(MainMenu), "startupPlayableDirector");

		private static readonly FieldInfo IntroOverlayField = AccessTools.Field(typeof(MainMenu), "introOverlay");

		private static MelonPreferences_Category preferencesCategory;

		private static MelonPreferences_Entry<bool> skipIntroPreference;

		public override void OnInitializeMelon()
		{
			preferencesCategory = MelonPreferences.CreateCategory("SBGIntroSkip");
			skipIntroPreference = preferencesCategory.CreateEntry<bool>("SkipIntro", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			((MelonBase)this).HarmonyInstance.PatchAll(typeof(IntroSkipMod).Assembly);
			MelonLogger.Msg($"Skip intro enabled: {skipIntroPreference.Value}");
		}

		private static bool IsEnabled()
		{
			return skipIntroPreference?.Value ?? true;
		}

		private static bool HasPendingLobbyJoin()
		{
			return !string.IsNullOrEmpty(BNetworkManager.SteamLobbyIdToConnectToFromMainMenu);
		}

		private static void HideIntroPresentation(MainMenu mainMenu)
		{
			object? obj = StartupPlayableDirectorField?.GetValue(mainMenu);
			PlayableDirector val = (PlayableDirector)((obj is PlayableDirector) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				val.Stop();
				((Component)val).gameObject.SetActive(false);
			}
			object? obj2 = IntroOverlayField?.GetValue(mainMenu);
			GameObject val2 = (GameObject)((obj2 is GameObject) ? obj2 : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.SetActive(false);
			}
		}
	}
}