using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MonitorDoorButtons.Utilities;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MonitorDoorButtons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Add the door button panel to the main monitor in the front of the ship to open/close the door while monitoring.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+0d53bf7d2d09b7d20df63ba2c673d87187f189cb")]
[assembly: AssemblyProduct("MonitorDoorButtons")]
[assembly: AssemblyTitle("MonitorDoorButtons")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 MonitorDoorButtons
{
[BepInPlugin("MonitorDoorButtons", "MonitorDoorButtons", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
private static readonly Harmony harmony = new Harmony("MonitorDoorButtons");
public static ManualLogSource CLog;
private static bool betterMonitors;
private static bool biggerButtons;
private void Awake()
{
ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ButtonsOnMonitor", false, "Moves the buttons onto the monitors above display controls and removes the back panel and power meter; required for GI bettermonitors compatability");
ConfigEntry<bool> val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BiggerButtons", false, "Makes the monitor buttons bigger, requires ButtonsOnMonitor to be true");
betterMonitors = val.Value;
biggerButtons = val2.Value;
CLog = ((BaseUnityPlugin)this).Logger;
CLog.LogInfo((object)"Plugin MonitorDoorButtons is loaded!");
harmony.PatchAll();
}
public static bool? GetConfig(int index)
{
return index switch
{
1 => betterMonitors,
2 => biggerButtons,
_ => null,
};
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MonitorDoorButtons";
public const string PLUGIN_NAME = "MonitorDoorButtons";
public const string PLUGIN_VERSION = "1.1.1";
}
}
namespace MonitorDoorButtons.Utilities
{
public static class Console
{
public static bool DebugState;
public static void Log(string message)
{
SendLog(message, "Log");
}
public static void LogInfo(string message)
{
SendLog(message, "LogInfo");
}
public static void LogError(string message)
{
SendLog(message, "LogError");
}
public static void LogWarning(string message)
{
SendLog(message, "LogWarning");
}
public static void LogDebug(string message)
{
SendLog(message, "LogDebug");
}
public static void LogFatal(string message)
{
SendLog(message, "LogFatal");
}
public static void LogMessage(string message)
{
SendLog(message, "LogMessage");
}
private static void SendLog(string message, string level = null)
{
if (!DebugState)
{
return;
}
switch (level)
{
case "LogInfo":
Plugin.CLog.LogInfo((object)message);
return;
case "LogError":
Plugin.CLog.LogError((object)message);
return;
case "LogWarning":
Plugin.CLog.LogWarning((object)message);
return;
case "LogDebug":
Plugin.CLog.LogDebug((object)message);
return;
case "LogFatal":
Plugin.CLog.LogFatal((object)message);
return;
case "LogMessage":
Plugin.CLog.LogMessage((object)message);
return;
}
if (level != "Log")
{
Debug.Log((object)("[" + level + "]: " + message));
}
else
{
Debug.Log((object)message);
}
}
}
}
namespace MonitorDoorButtons.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
private static Transform MonitorWall;
private static Transform DoorPanel;
private static InteractTrigger DoorStartButtonTrigger;
private static InteractTrigger DoorStopButtonTrigger;
private static TextMeshProUGUI DoorPanelMeter;
public static Transform MonitorDoorPanel;
private static Transform MonitorStartButton;
private static Transform MonitorStopButton;
private static InteractTrigger MonitorStartButtonTrigger;
private static InteractTrigger MonitorStopButtonTrigger;
private static TextMeshProUGUI MonitorDoorPanelMeter;
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void StartPatch()
{
MonitorDoorButtons.Utilities.Console.LogInfo("StartOfRound.Start() called");
GetObjectReferences();
if (!((Object)(object)MonitorWall == (Object)null) && !((Object)(object)DoorPanel == (Object)null))
{
CreateMonitorDoorPanel();
}
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void UpdatePatch()
{
if (!((Object)(object)DoorPanelMeter == (Object)null) && !((Object)(object)MonitorDoorPanelMeter == (Object)null))
{
((TMP_Text)MonitorDoorPanelMeter).SetText(((TMP_Text)DoorPanelMeter).text, true);
}
}
private static void GetObjectReferences()
{
MonitorWall = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall").transform;
if ((Object)(object)MonitorWall == (Object)null)
{
MonitorDoorButtons.Utilities.Console.LogError("StartOfRound.GetMonitorButton() could not find MonitorWall");
return;
}
DoorPanel = GameObject.Find("Environment/HangarShip/AnimatedShipDoor/HangarDoorButtonPanel").transform;
Transform val = DoorPanel.Find("StartButton").Find("Cube (2)");
Transform val2 = DoorPanel.Find("StopButton").Find("Cube (3)");
if ((Object)(object)DoorPanel == (Object)null || (Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
MonitorDoorButtons.Utilities.Console.LogError("StartOfRound.GetDoorPanel() could not find HangarDoorButtonPanel references");
return;
}
DoorStartButtonTrigger = ((Component)val).GetComponent<InteractTrigger>();
DoorStopButtonTrigger = ((Component)val2).GetComponent<InteractTrigger>();
DoorPanelMeter = ((Component)DoorPanel.Find("ElevatorPanelScreen/Image/meter")).GetComponent<TextMeshProUGUI>();
}
private static void CreateMonitorDoorPanel()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)MonitorWall.Find("MonitorDoorPanel") != (Object)null)
{
MonitorDoorButtons.Utilities.Console.LogError("StartOfRound.CreateMonitorDoorPanel() MonitorDoorPanel already exists");
return;
}
MonitorDoorPanel = Object.Instantiate<Transform>(DoorPanel, MonitorWall);
((Object)MonitorDoorPanel).name = "MonitorDoorPanel";
MonitorDoorPanel.localPosition = new Vector3(-0.2f, -1.7f, 0.15f);
MonitorDoorPanel.localEulerAngles = new Vector3(90f, 90f, 0f);
MonitorDoorButtons.Utilities.Console.LogInfo("StartOfRound.CreateMonitorDoorPanel() created: " + ((Object)MonitorDoorPanel).name);
MonitorStartButton = MonitorDoorPanel.Find("StartButton").Find("Cube (2)");
MonitorStopButton = MonitorDoorPanel.Find("StopButton").Find("Cube (3)");
if ((Object)(object)MonitorStartButton == (Object)null || (Object)(object)MonitorStopButton == (Object)null)
{
MonitorDoorButtons.Utilities.Console.LogError("StartOfRound.CreateMonitorDoorPanel() could not find MonitorDoorPanel references");
return;
}
if (Plugin.GetConfig(1) == true)
{
ArrayList arrayList = new ArrayList { "StartButton", "StopButton", "Audio" };
for (int i = 0; i < MonitorDoorPanel.childCount; i++)
{
GameObject gameObject = ((Component)MonitorDoorPanel.GetChild(i)).gameObject;
if (!arrayList.Contains(((Object)gameObject).name))
{
Object.Destroy((Object)(object)gameObject);
}
}
Object.Destroy((Object)(object)((Component)MonitorDoorPanel).GetComponent<MeshRenderer>());
MonitorDoorPanel.localRotation = new Quaternion(0.5417f, 0.4545f, -0.4545f, 0.5417f);
if (Plugin.GetConfig(2) == true)
{
((Component)MonitorDoorPanel).transform.localPosition = new Vector3(-0.23f, -1.6f, -0.17f);
}
else
{
((Component)MonitorDoorPanel).transform.localPosition = new Vector3(-0.23f, -1.8f, -0.145f);
((Component)MonitorDoorPanel).transform.localScale = new Vector3(-0.75f, -0.75f, -0.75f);
}
}
MonitorStartButtonTrigger = ((Component)MonitorStartButton).GetComponent<InteractTrigger>();
MonitorStopButtonTrigger = ((Component)MonitorStopButton).GetComponent<InteractTrigger>();
((UnityEvent<PlayerControllerB>)(object)MonitorStartButtonTrigger.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB player)
{
CustomTrigger(player, DoorStartButtonTrigger, MonitorStartButton);
});
((UnityEvent<PlayerControllerB>)(object)MonitorStopButtonTrigger.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB player)
{
CustomTrigger(player, DoorStopButtonTrigger, MonitorStopButton, "Close");
});
MonitorDoorPanelMeter = ((Component)MonitorDoorPanel.Find("ElevatorPanelScreen/Image/meter")).GetComponent<TextMeshProUGUI>();
}
private static void CustomTrigger(PlayerControllerB sender, InteractTrigger originalTrigger, Transform trigger, string state = "Open")
{
((UnityEvent<PlayerControllerB>)(object)originalTrigger.onInteract).Invoke(sender);
((Component)trigger).GetComponent<AnimatedObjectTrigger>().triggerAnimator.SetTrigger(state + "Door");
MonitorDoorButtons.Utilities.Console.LogMessage("StartOfRound.CustomTrigger() called for " + ((Object)trigger).name + " with state " + state);
}
}
}