Decompiled source of RightClickSkip v1.1.0

RightClickSkip.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SuperFantasyKingdom;
using SuperFantasyKingdom.UI;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("RightClickSkip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+66fc831e2d07ffd4f0e39ceffd8b1e95bb0e6dc0")]
[assembly: AssemblyProduct("Right Click Skip")]
[assembly: AssemblyTitle("RightClickSkip")]
[assembly: AssemblyVersion("1.1.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 RightClickSkip
{
	[BepInPlugin("ownly.rightclickskip", "Right Click Skip", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const int IntervalMs = 25;

		private const int MaxMs = 20000;

		private const int VK_RBUTTON = 2;

		private static volatile bool s_Running;

		[DllImport("user32.dll")]
		private static extern short GetAsyncKeyState(int vKey);

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).PatchAll();
			Thread thread = new Thread(SplashPump);
			thread.IsBackground = true;
			thread.Start();
		}

		private void Update()
		{
			s_Running = true;
		}

		private static void SplashPump()
		{
			Stopwatch stopwatch = Stopwatch.StartNew();
			bool flag = false;
			try
			{
				while (stopwatch.ElapsedMilliseconds < 20000 && !s_Running)
				{
					if ((GetAsyncKeyState(2) & 0x8000) != 0)
					{
						flag = true;
					}
					if (flag)
					{
						SplashScreen.Stop((StopBehavior)0);
					}
					Thread.Sleep(25);
				}
			}
			catch
			{
			}
		}
	}
	internal static class Skipper
	{
		internal const float Sentinel = -1f;

		internal static readonly FieldInfo JustSkipped = AccessTools.Field(typeof(GameInputManager), "m_JustSkipped");

		internal static readonly FieldInfo CaptionTimer = AccessTools.Field(typeof(UINewDayCaption), "m_WaitTimer");

		internal static UINewDayCaption Caption;

		internal static bool CaptionArmed;

		internal static bool VanillaSkipped(GameInputManager input)
		{
			return !(-1f).Equals(JustSkipped.GetValue(input));
		}

		internal static bool TrySkipDayCaption()
		{
			if (!CaptionArmed || CaptionTimer == null || (Object)(object)Caption == (Object)null || !((Component)Caption).gameObject.activeSelf)
			{
				return false;
			}
			CaptionTimer.SetValue(Caption, 0.0001f);
			return true;
		}
	}
	[HarmonyPatch(typeof(UINewDayCaption), "Awake")]
	internal static class Patch_LearnDayCaption
	{
		private static void Postfix(UINewDayCaption __instance)
		{
			Skipper.Caption = __instance;
			Skipper.CaptionArmed = false;
		}
	}
	[HarmonyPatch(typeof(UINewDayCaption), "AfterGameStarting")]
	internal static class Patch_ArmDayCaption
	{
		private static void Postfix()
		{
			Skipper.CaptionArmed = true;
		}
	}
	[HarmonyPatch(typeof(GameInputManager), "Skip")]
	internal static class Patch_SkipDayCaption
	{
		private static void Prefix(GameInputManager __instance)
		{
			try
			{
				if (Skipper.JustSkipped != null)
				{
					Skipper.JustSkipped.SetValue(__instance, -1f);
				}
			}
			catch
			{
			}
		}

		private static void Postfix(GameInputManager __instance, CallbackContext context)
		{
			try
			{
				if (((CallbackContext)(ref context)).performed && !(Skipper.JustSkipped == null) && !PauseMenuManger.Instance.InMenu() && !Skipper.VanillaSkipped(__instance) && Skipper.TrySkipDayCaption())
				{
					Skipper.JustSkipped.SetValue(__instance, Time.time);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(GameInputManager), "GameCancel")]
	internal static class Patch_RightClickSkips
	{
		private static bool Prefix(GameInputManager __instance, CallbackContext context)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((CallbackContext)(ref context)).performed || Skipper.JustSkipped == null || PauseMenuManger.Instance.InMenu())
				{
					return true;
				}
				if (((CallbackContext)(ref context)).control == null || !(((CallbackContext)(ref context)).control.device is Mouse))
				{
					return true;
				}
				object value = Skipper.JustSkipped.GetValue(__instance);
				__instance.Skip(context);
				if (Skipper.VanillaSkipped(__instance))
				{
					return false;
				}
				Skipper.JustSkipped.SetValue(__instance, value);
			}
			catch
			{
			}
			return true;
		}
	}
}