using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MapNap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MapNap")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4bf9ac6a-7dbb-4441-a518-6d31e31d29ef")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 MapNap
{
internal static class LogBridge
{
private const string Prefix = "[MapNap] ";
internal static Action<string> Info { get; set; } = delegate(string s)
{
Debug.Log(Object.op_Implicit("[MapNap] " + s));
};
internal static Action<string> Warn { get; set; } = delegate(string s)
{
Debug.LogWarning(Object.op_Implicit("[MapNap] " + s));
};
internal static Action<string> Error { get; set; } = delegate(string s)
{
Debug.LogError(Object.op_Implicit("[MapNap] " + s));
};
internal static void UseUnityLogger()
{
Info = delegate(string s)
{
Debug.Log(Object.op_Implicit("[MapNap] " + s));
};
Warn = delegate(string s)
{
Debug.LogWarning(Object.op_Implicit("[MapNap] " + s));
};
Error = delegate(string s)
{
Debug.LogError(Object.op_Implicit("[MapNap] " + s));
};
}
}
internal static class ModCore
{
private static bool _initialized;
internal static void Init()
{
if (!_initialized)
{
_initialized = true;
LogBridge.Info("MapNap core initialized (Tab hold shows the map).");
}
}
internal static void Deinit()
{
if (_initialized)
{
_initialized = false;
PauseMapHold.Reset();
}
}
internal static void UpdateLoop()
{
if (_initialized)
{
PauseMapHold.OnUpdate();
}
}
}
internal static class PauseMapHold
{
private static PauseUi _pauseUi;
private static bool _ownedPause;
private static bool _restoreToMainOnExit;
internal static void OnUpdate()
{
if (Input.GetKeyDown((KeyCode)9))
{
OnTabDown();
}
else if (Input.GetKeyUp((KeyCode)9))
{
OnTabUp();
}
}
private static void OnTabDown()
{
PauseUi pauseUi = GetPauseUi();
if ((Object)(object)pauseUi == (Object)null)
{
LogBridge.Warn("Tab down -> PauseUi not found.");
_ownedPause = false;
_restoreToMainOnExit = false;
return;
}
if (SafeIsPaused(pauseUi))
{
LogBridge.Info("Tab down while already paused -> ignoring (no ownership).");
_ownedPause = false;
_restoreToMainOnExit = false;
return;
}
if (!SafeCanPause(pauseUi))
{
LogBridge.Info("Tab down -> CanPause() == false, ignoring.");
_ownedPause = false;
_restoreToMainOnExit = false;
return;
}
try
{
pauseUi.Pause();
_ownedPause = true;
_restoreToMainOnExit = true;
LogBridge.Info("Tab down -> PauseUi.Pause() (MapNap owns).");
}
catch (Exception value)
{
LogBridge.Error($"Tab down -> PauseUi.Pause() threw: {value}");
_ownedPause = false;
_restoreToMainOnExit = false;
return;
}
try
{
pauseUi.GoToMap();
LogBridge.Info("Tab down -> PauseUi.GoToMap().");
}
catch (Exception value2)
{
LogBridge.Error($"Tab down -> PauseUi.GoToMap() threw: {value2}");
}
}
private static void OnTabUp()
{
PauseUi pauseUi = _pauseUi;
if ((Object)(object)pauseUi == (Object)null)
{
_ownedPause = false;
_restoreToMainOnExit = false;
return;
}
if (_ownedPause)
{
try
{
if (SafeIsPaused(pauseUi))
{
if (_restoreToMainOnExit)
{
TryGoToMain(pauseUi);
}
pauseUi.Resume();
LogBridge.Info("Tab up -> PauseUi.Resume() (MapNap restore).");
}
}
catch (Exception value)
{
LogBridge.Error($"Tab up -> PauseUi.Resume() threw: {value}");
}
}
_ownedPause = false;
_restoreToMainOnExit = false;
}
private static PauseUi GetPauseUi()
{
if ((Object)(object)_pauseUi != (Object)null)
{
return _pauseUi;
}
try
{
UiManager instance = UiManager.Instance;
if ((Object)(object)instance != (Object)null && (Object)(object)instance.pause != (Object)null)
{
_pauseUi = instance.pause;
LogBridge.Info("Cached PauseUi from UiManager.Instance.");
return _pauseUi;
}
PauseHandler val = Object.FindObjectOfType<PauseHandler>();
if ((Object)(object)val != (Object)null && (Object)(object)val.pauseUi != (Object)null)
{
_pauseUi = val.pauseUi;
LogBridge.Info("Cached PauseUi from PauseHandler.");
return _pauseUi;
}
_pauseUi = Object.FindObjectOfType<PauseUi>();
if ((Object)(object)_pauseUi != (Object)null)
{
LogBridge.Info("Cached PauseUi via FindObjectOfType.");
return _pauseUi;
}
}
catch (Exception value)
{
LogBridge.Error($"Error locating PauseUi: {value}");
}
return _pauseUi;
}
private static bool SafeIsPaused(PauseUi ui)
{
try
{
return ui.IsPaused();
}
catch
{
return false;
}
}
private static bool SafeCanPause(PauseUi ui)
{
try
{
return ui.CanPause();
}
catch
{
return true;
}
}
private static void TryGoToMain(PauseUi ui)
{
try
{
ui.GoToMain();
LogBridge.Info("Tab up -> PauseUi.GoToMain() to restore default tab.");
}
catch (Exception value)
{
LogBridge.Error($"Tab up -> PauseUi.GoToMain() threw: {value}");
}
}
internal static void Reset()
{
_ownedPause = false;
_pauseUi = null;
_restoreToMainOnExit = false;
}
}
[BepInPlugin("com.maskoliver.mapnap", "MapNap", "1.0.0")]
public sealed class BepInEntry : BasePlugin
{
private sealed class UpdateDriver : MonoBehaviour
{
public UpdateDriver(IntPtr ptr)
: base(ptr)
{
}
private void Start()
{
try
{
ModCore.Init();
}
catch (Exception value)
{
LogBridge.Error($"MapNap init failed: {value}");
}
}
private void Update()
{
ModCore.UpdateLoop();
}
private void OnDestroy()
{
ModCore.Deinit();
}
}
private ManualLogSource _log;
private static GameObject _updateHost;
private static bool _driverRegistered;
public override void Load()
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
_log = Logger.CreateLogSource("MapNap");
LogBridge.Info = delegate(string s)
{
_log.LogInfo((object)s);
};
LogBridge.Warn = delegate(string s)
{
_log.LogWarning((object)s);
};
LogBridge.Error = delegate(string s)
{
_log.LogError((object)s);
};
if (!_driverRegistered)
{
ClassInjector.RegisterTypeInIl2Cpp<UpdateDriver>();
_driverRegistered = true;
}
_updateHost = new GameObject("MapNap_UpdateDriver");
Object.DontDestroyOnLoad((Object)(object)_updateHost);
((Object)_updateHost).hideFlags = (HideFlags)61;
_updateHost.AddComponent<UpdateDriver>();
_log.LogInfo((object)"MapNap (BepInEx) loaded.");
}
public override bool Unload()
{
if ((Object)(object)_updateHost != (Object)null)
{
Object.Destroy((Object)(object)_updateHost);
_updateHost = null;
}
ModCore.Deinit();
LogBridge.UseUnityLogger();
if (_log != null)
{
Logger.Sources.Remove((ILogSource)(object)_log);
_log = null;
}
return true;
}
}
}