using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Preferences;
using MenuHotkey;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MenuHotkeyMod), "Menu Hotkey", "1.0.0", "PenguinInABox", null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MenuHotkey")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MenuHotkey")]
[assembly: AssemblyTitle("MenuHotkey")]
[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 MenuHotkey
{
public class MenuHotkeyMod : MelonMod
{
private MelonPreferences_Entry<KeyCode> _menuKey;
private MelonPreferences_Entry<float> _holdSeconds;
private float _heldTime;
private bool _triggered;
public override void OnInitializeMelon()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
MelonPreferences_Category val = MelonPreferences.CreateCategory("MenuHotkey", "Menu Hotkey");
_menuKey = val.CreateEntry<KeyCode>("MenuKey", (KeyCode)109, "Hold this key to return to the main menu", (string)null, false, false, (ValueValidator)null, (string)null);
_holdSeconds = val.CreateEntry<float>("HoldSeconds", 1f, "How long the key must be held, in seconds", (string)null, false, false, (ValueValidator)null, (string)null);
MelonLogger.Msg("Menu Hotkey loaded - hold " + ((object)_menuKey.Value/*cast due to .constrained prefix*/).ToString() + " for " + _holdSeconds.Value + "s to return to the main menu.");
}
public override void OnUpdate()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
int num = ((_menuKey == null) ? 109 : ((int)_menuKey.Value));
float num2 = ((_holdSeconds != null) ? _holdSeconds.Value : 1f);
if (!Input.GetKey((KeyCode)num) || IsTypingInAField())
{
_heldTime = 0f;
_triggered = false;
}
else if (!_triggered)
{
_heldTime += Time.unscaledDeltaTime;
if (_heldTime >= num2)
{
_triggered = true;
GoToMainMenu();
}
}
}
private static bool IsTypingInAField()
{
try
{
EventSystem current = EventSystem.current;
if ((Object)(object)current == (Object)null)
{
return false;
}
GameObject currentSelectedGameObject = current.currentSelectedGameObject;
if ((Object)(object)currentSelectedGameObject == (Object)null)
{
return false;
}
TMP_InputField component = currentSelectedGameObject.GetComponent<TMP_InputField>();
if ((Object)(object)component != (Object)null && component.isFocused)
{
return true;
}
InputField component2 = currentSelectedGameObject.GetComponent<InputField>();
if ((Object)(object)component2 != (Object)null && component2.isFocused)
{
return true;
}
return false;
}
catch
{
return false;
}
}
private static void GoToMainMenu()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
try
{
Scene activeScene = SceneManager.GetActiveScene();
if (!(((Scene)(ref activeScene)).name == SceneNames.MainMenuSceneName))
{
TransitionController val = Object.FindFirstObjectByType<TransitionController>();
if (!((Object)(object)val == (Object)null))
{
MelonLogger.Msg("Menu Hotkey: returning to the main menu.");
val.TransitionToNewScene(SceneNames.MainMenuSceneName);
}
}
}
catch (Exception ex)
{
MelonLogger.Error("Menu Hotkey failed: " + ex);
}
}
}
}