using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
[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("CrackQuickMenus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrackQuickMenus")]
[assembly: AssemblyTitle("CrackQuickMenus")]
[assembly: AssemblyVersion("1.0.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 CrackQuickMenus
{
[BepInPlugin("com.altma.crackui.quickmenus", "CRACK Quick Menus", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "com.altma.crackui.quickmenus";
public const string Name = "CRACK Quick Menus";
public const string Version = "0.1.0";
internal static ConfigEntry<bool> OneClick;
internal static ConfigEntry<bool> KeepButtons;
internal static ConfigEntry<float> Cooldown;
private void Awake()
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
OneClick = ((BaseUnityPlugin)this).Config.Bind<bool>("Menus", "OneClick", true, "Menu buttons act on the first click.");
KeepButtons = ((BaseUnityPlugin)this).Config.Bind<bool>("Menus", "KeepButtons", true, "Menu buttons stay on screen after a click instead of shattering.");
Cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Menus", "Cooldown", 0.25f, "Seconds a kept button ignores further clicks after acting (stops accidental double clicks).");
new Harmony("com.altma.crackui.quickmenus").PatchAll(typeof(Plugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded, OneClick = {2}, KeepButtons = {3}", "CRACK Quick Menus", "0.1.0", OneClick.Value, KeepButtons.Value));
}
}
[HarmonyPatch(typeof(UIShatter), "OnPointerDown")]
internal static class ShatterClick
{
private static readonly FieldRef<UIShatter, int> Hits = AccessTools.FieldRefAccess<UIShatter, int>("_hits");
private static readonly FieldRef<UIShatter, int> HitsToShatter = AccessTools.FieldRefAccess<UIShatter, int>("_hitsToShatter");
private static readonly FieldRef<UIShatter, bool> Shattered = AccessTools.FieldRefAccess<UIShatter, bool>("_shattered");
private static readonly FieldRef<UIShatter, bool> Pending = AccessTools.FieldRefAccess<UIShatter, bool>("_pending");
private static readonly FieldRef<UIShatter, UnityEvent> OnShatter = AccessTools.FieldRefAccess<UIShatter, UnityEvent>("_onShatter");
private static readonly FieldRef<UIShatter, SoundDefinition> CrackSound = AccessTools.FieldRefAccess<UIShatter, SoundDefinition>("_crackSound");
private static readonly Action<UIShatter> Shake = AccessTools.MethodDelegate<Action<UIShatter>>(AccessTools.Method(typeof(UIShatter), "Shake", (Type[])null, (Type[])null), (object)null, true);
private static readonly Action<UIShatter, float> SnapCrack = AccessTools.MethodDelegate<Action<UIShatter, float>>(AccessTools.Method(typeof(UIShatter), "SnapCrack", (Type[])null, (Type[])null), (object)null, true);
private static readonly Dictionary<UIShatter, float> lastFired = new Dictionary<UIShatter, float>();
private static bool IsMenuButton(UIShatter s)
{
if ((Object)(object)((Component)s).GetComponent<Selectable>() != (Object)null)
{
return (Object)(object)((Component)s).GetComponentInParent<DreamUI>(true) == (Object)null;
}
return false;
}
private static bool Prefix(UIShatter __instance, PointerEventData eventData)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (Shattered.Invoke(__instance) || Pending.Invoke(__instance) || (eventData != null && (int)eventData.button != 0) || !IsMenuButton(__instance))
{
return true;
}
if (!Plugin.KeepButtons.Value)
{
if (Plugin.OneClick.Value)
{
Hits.Invoke(__instance) = Mathf.Max(Hits.Invoke(__instance), HitsToShatter.Invoke(__instance) - 1);
}
return true;
}
if (!Plugin.OneClick.Value && Hits.Invoke(__instance) + 1 < HitsToShatter.Invoke(__instance))
{
return true;
}
float unscaledTime = Time.unscaledTime;
if (lastFired.TryGetValue(__instance, out var value) && unscaledTime - value < Plugin.Cooldown.Value)
{
return false;
}
if (lastFired.Count > 64)
{
lastFired.Keys.Where((UIShatter k) => (Object)(object)k == (Object)null).ToList().ForEach(delegate(UIShatter k)
{
lastFired.Remove(k);
});
}
lastFired[__instance] = unscaledTime;
Hits.Invoke(__instance) = 0;
SnapCrack(__instance, 0f);
Shake(__instance);
SoundFX.Play(CrackSound.Invoke(__instance), 1f, 1f, 0f);
UnityEvent obj = OnShatter.Invoke(__instance);
if (obj != null)
{
obj.Invoke();
}
return false;
}
}
}