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 PrimeTween;
using SuperFantasyKingdom;
using SuperFantasyKingdom.Tavern;
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.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+983789bdd86b61b103e1f0a5babbe0a583cd3930")]
[assembly: AssemblyProduct("Right Click Skip")]
[assembly: AssemblyTitle("RightClickSkip")]
[assembly: AssemblyVersion("1.2.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.2.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;
try
{
if (((Object)(object)CardPick.Bouncing != (Object)null || EnemyPick.Animating) && Mouse.current != null && Mouse.current.rightButton.wasPressedThisFrame && ((Object)(object)PauseMenuManger.Instance == (Object)null || !PauseMenuManger.Instance.InMenu()))
{
EnemyPick.Skip();
CardPick.Skip();
}
}
catch
{
}
}
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;
}
}
[HarmonyPatch(typeof(TavernFeast), "Skip", new Type[] { typeof(CallbackContext) })]
internal static class Patch_FeastRightClick
{
private static bool Prefix(TavernFeast __instance, CallbackContext context)
{
try
{
if (((CallbackContext)(ref context)).performed)
{
InputControl control = ((CallbackContext)(ref context)).control;
InputDevice obj = ((control != null) ? control.device : null);
Mouse val = (Mouse)(object)((obj is Mouse) ? obj : null);
if (val != null && (object)((CallbackContext)(ref context)).control == val.rightButton)
{
if (!((Component)__instance).gameObject.activeSelf || !((Behaviour)__instance).enabled || PauseMenuManger.Instance.InMenu() || !Traverse.Create((object)__instance).Field("m_IsDoneFeasting").GetValue<bool>())
{
return true;
}
__instance.Next(false);
return false;
}
}
return true;
}
catch
{
}
return true;
}
}
[HarmonyPatch(typeof(TavernSummary), "Skip", new Type[] { typeof(CallbackContext) })]
internal static class Patch_SummaryRightClick
{
private static bool Prefix(TavernSummary __instance, CallbackContext context)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
try
{
InputControl control = ((CallbackContext)(ref context)).control;
InputDevice obj = ((control != null) ? control.device : null);
Mouse val = (Mouse)(object)((obj is Mouse) ? obj : null);
if (val == null || (object)((CallbackContext)(ref context)).control != val.rightButton)
{
return true;
}
__instance.Continue(context);
return false;
}
catch
{
}
return true;
}
}
internal static class CardPick
{
internal static UICard Bouncing;
internal static void Skip()
{
UICard bouncing = Bouncing;
Bouncing = null;
if ((Object)(object)bouncing != (Object)null)
{
Tween.CompleteAll((object)((Component)bouncing).transform);
}
}
}
[HarmonyPatch]
internal static class Patch_CardPick
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(UIOverlayMerchant), "Select", new Type[1] { typeof(UICard) }, (Type[])null);
}
private static bool Prepare()
{
return TargetMethod() != null;
}
private static void Postfix(UICard selected)
{
CardPick.Bouncing = selected;
if (EnemyPick.Stage == EnemyPick.Step.Open)
{
EnemyPick.Stage = EnemyPick.Step.Picked;
}
}
}
internal static class EnemyPick
{
internal enum Step
{
Idle,
Open,
Picked,
Jumping,
Updated,
Done
}
internal static readonly MethodInfo UpdateInfos = AccessTools.Method(typeof(UIMerchantMonsterSelection), "UpdateInfos", (Type[])null, (Type[])null);
internal static readonly MethodInfo Finish = AccessTools.Method(typeof(UIMerchantMonsterSelection), "Finish", (Type[])null, (Type[])null);
internal static UIMerchantMonsterSelection Selection;
internal static Step Stage;
internal static bool Queued;
internal static bool Animating
{
get
{
if (Stage != Step.Picked && Stage != Step.Jumping)
{
return Stage == Step.Updated;
}
return true;
}
}
internal static void Skip()
{
if (Stage == Step.Picked)
{
Queued = true;
return;
}
if (Stage == Step.Jumping)
{
UpdateInfos.Invoke(Selection, null);
}
if (Stage == Step.Updated)
{
Finish.Invoke(Selection, null);
}
}
}
[HarmonyPatch]
internal static class Patch_EnemyPick
{
private static bool Prepare()
{
if (EnemyPick.UpdateInfos != null && EnemyPick.Finish != null)
{
return AccessTools.Method(typeof(UIMerchantMonsterSelection), "Callback", (Type[])null, (Type[])null) != null;
}
return false;
}
[HarmonyPatch(typeof(UIMerchantMonsterSelection), "Awake")]
[HarmonyPostfix]
private static void Reset(UIMerchantMonsterSelection __instance)
{
EnemyPick.Selection = __instance;
EnemyPick.Stage = EnemyPick.Step.Idle;
EnemyPick.Queued = false;
}
[HarmonyPatch(typeof(UIMerchantMonsterSelection), "Reroll")]
[HarmonyPostfix]
private static void Opened()
{
if (EnemyPick.Stage == EnemyPick.Step.Idle)
{
EnemyPick.Stage = EnemyPick.Step.Open;
}
}
[HarmonyPatch(typeof(UIMerchantMonsterSelection), "Callback")]
[HarmonyPostfix]
private static void Jumping(UIMerchantMonsterSelection __instance)
{
try
{
EnemyPick.Selection = __instance;
EnemyPick.Stage = EnemyPick.Step.Jumping;
if (EnemyPick.Queued)
{
EnemyPick.Queued = false;
EnemyPick.Skip();
}
}
catch
{
}
}
[HarmonyPatch(typeof(UIMerchantMonsterSelection), "UpdateInfos")]
[HarmonyPrefix]
private static bool Updating()
{
if (EnemyPick.Stage == EnemyPick.Step.Done)
{
return false;
}
EnemyPick.Stage = EnemyPick.Step.Updated;
return true;
}
[HarmonyPatch(typeof(UIMerchantMonsterSelection), "Finish")]
[HarmonyPrefix]
private static bool Finishing()
{
if (EnemyPick.Stage == EnemyPick.Step.Done)
{
return false;
}
EnemyPick.Stage = EnemyPick.Step.Done;
return true;
}
}
}