SMSMod-BoxPause/Plugin.cs
2024-05-02 19:19:44 +02:00

32 lines
1.4 KiB
C#

using BepInEx;
using UnityEngine;
namespace BoxPause
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_NAME} is loaded!");
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
var obj = GameObject.Find("Player");
if (obj == null || !obj.active) return;
//Logger.Log(BepInEx.Logging.LogLevel.Message, "Escape has been pressed.");
if (obj.GetComponent<PlayerInteraction>().InInteraction)
{
//Logger.Log(BepInEx.Logging.LogLevel.Message, "Box is being held. Invoking Pause method.");
var mng = GameObject.Find("Escape Menu").GetComponent<EscapeMenuManager>();
var prop = typeof(EscapeMenuManager).GetProperty("OpenEscapeMenu", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var memb = typeof(EscapeMenuManager).GetField("m_Paused", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
prop.SetValue(mng, (bool)memb.GetValue(mng) == false);
}
}
}
}
}