Decompiled source of RemoteLever v1.0.1

RemoteLever.dll

Decompiled 19 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RemoteLever")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RemoteLever")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0947733e-d699-4472-8c49-1d8d08d42652")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RemoteLever;

[BepInPlugin("azumi.remotelever", "RemoteLever", "1.0.1")]
public class RemoteLeverPlugin : BaseUnityPlugin
{
	public const string ModGUID = "azumi.remotelever";

	public const string ModName = "RemoteLever";

	public const string ModVersion = "1.0.1";

	internal static ManualLogSource Log;

	internal static ConfigEntry<string> LeverKeybind;

	private Harmony harmony;

	private void Awake()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		LeverKeybind = ((BaseUnityPlugin)this).Config.Bind<string>("General", "LeverKey", "F5", "Key used for remote ship lever activation.");
		harmony = new Harmony("azumi.remotelever");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"RemoteLever loaded successfully.");
	}
}
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
	private static float lastPressTime;

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void UpdatePatch()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		if (Keyboard.current == null)
		{
			return;
		}
		if (!Enum.TryParse<Key>(RemoteLeverPlugin.LeverKeybind.Value, ignoreCase: true, out Key result))
		{
			RemoteLeverPlugin.Log.LogWarning((object)("Invalid keybind in config: " + RemoteLeverPlugin.LeverKeybind.Value));
		}
		else
		{
			if (!((ButtonControl)Keyboard.current[result]).wasPressedThisFrame || Time.time - lastPressTime < 0.5f)
			{
				return;
			}
			lastPressTime = Time.time;
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				HUDManager.Instance.DisplayTip("Remote Lever", "Only the host can control the ship.", false, false, "LC_Tip1");
				return;
			}
			StartMatchLever val = Object.FindObjectOfType<StartMatchLever>();
			if ((Object)(object)val == (Object)null)
			{
				RemoteLeverPlugin.Log.LogWarning((object)"StartMatchLever not found.");
				return;
			}
			if (!((Object)(object)StartOfRound.Instance == (Object)null))
			{
				try
				{
					if (StartOfRound.Instance.inShipPhase)
					{
						RemoteLeverPlugin.Log.LogInfo((object)"Triggering landing remotely...");
						val.LeverAnimation();
						val.StartGame();
						HUDManager.Instance.AddTextToChatOnServer("<color=#00FFFF>[RemoteLever]</color> Ship landing initiated remotely.", -1);
					}
					else if (!StartOfRound.Instance.shipHasLanded)
					{
						RemoteLeverPlugin.Log.LogWarning((object)"Ship has not landed yet.");
					}
					else if (StartOfRound.Instance.shipIsLeaving)
					{
						RemoteLeverPlugin.Log.LogWarning((object)"Ship is already leaving.");
					}
					else if (StartOfRound.Instance.shipLeftAutomatically)
					{
						RemoteLeverPlugin.Log.LogWarning((object)"Ship already left automatically.");
					}
					else
					{
						RemoteLeverPlugin.Log.LogInfo((object)"Triggering departure remotely...");
						val.LeverAnimation();
						val.EndGame();
						HUDManager.Instance.AddTextToChatOnServer("<color=#00FFFF>[RemoteLever]</color> Ship departure initiated remotely.", -1);
					}
					return;
				}
				catch (Exception ex)
				{
					RemoteLeverPlugin.Log.LogError((object)ex);
					return;
				}
			}
			RemoteLeverPlugin.Log.LogWarning((object)"StartOfRound.Instance is null.");
		}
	}
}