Decompiled source of CruiserCheckpoint v1.0.4

CruiserCheckpoint.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.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 CruiserCheckpoint
{
	[BepInPlugin("com.custom.cruisercheckpoint", "CruiserCheckpoint", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<Key> savePointKey;

		internal static ConfigEntry<Key> teleportKey;

		internal static ConfigEntry<Key> toggleMagnetKey;

		internal static ConfigEntry<Key> toggleMenuKey;

		internal static bool carGodMode = false;

		internal static bool playerGodMode = false;

		internal static bool infiniteJumpFuel = false;

		internal static bool menuOpen = false;

		internal static int waitingForRebind = 0;

		internal static Vector3? savedPosition = null;

		internal static Quaternion savedRotation = Quaternion.identity;

		private void Awake()
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			savePointKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "SavePointKey", (Key)40, "Key to save the Cruiser checkpoint");
			teleportKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "TeleportKey", (Key)38, "Key to teleport the Cruiser back to the checkpoint");
			toggleMagnetKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ToggleMagnetKey", (Key)36, "Key to toggle the ship magnet on/off");
			toggleMenuKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ToggleMenuKey", (Key)32, "Key to open/close the Cruiser mod menu");
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Key>(savePointKey, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Key>(teleportKey, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Key>(toggleMagnetKey, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Key>(toggleMenuKey, false));
			GameObject val = new GameObject("CruiserCheckpointGUI");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<CruiserMenuGUI>();
			Harmony.CreateAndPatchAll(typeof(PlayerInputPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(VehiclePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlayerGodModePatch), (string)null);
			Logger.LogInfo((object)"CruiserCheckpoint 1.0.4 loaded!");
		}

		internal static void ToggleMenu()
		{
			menuOpen = !menuOpen;
			waitingForRebind = 0;
			if (menuOpen)
			{
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
			}
			else if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && !GameNetworkManager.Instance.localPlayerController.quickMenuManager.isMenuOpen)
			{
				Cursor.visible = false;
				Cursor.lockState = (CursorLockMode)1;
			}
		}

		internal static void SaveCruiserPoint()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			VehicleController val = Object.FindObjectOfType<VehicleController>();
			if ((Object)(object)val == (Object)null)
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Cruiser Checkpoint", "Cruiser not found!", true, false, "LC_Tip1");
				}
				return;
			}
			savedPosition = ((Component)val).transform.position;
			savedRotation = ((Component)val).transform.rotation;
			HUDManager instance2 = HUDManager.Instance;
			if (instance2 != null)
			{
				instance2.DisplayTip("Cruiser Checkpoint", "Jump point saved!", false, false, "LC_Tip1");
			}
		}

		internal static void TeleportCruiser()
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			if (!savedPosition.HasValue)
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Cruiser Checkpoint", "Save a point first!", true, false, "LC_Tip1");
				}
				return;
			}
			VehicleController val = Object.FindObjectOfType<VehicleController>();
			if (!((Object)(object)val == (Object)null))
			{
				val.magnetedToShip = false;
				((Component)val).transform.SetParent((Transform)null, true);
				if ((Object)(object)val.mainRigidbody != (Object)null)
				{
					bool isKinematic = val.mainRigidbody.isKinematic;
					val.mainRigidbody.isKinematic = true;
					val.mainRigidbody.velocity = Vector3.zero;
					val.mainRigidbody.angularVelocity = Vector3.zero;
					val.mainRigidbody.position = savedPosition.Value;
					val.mainRigidbody.rotation = savedRotation;
					((Component)val).transform.SetPositionAndRotation(savedPosition.Value, savedRotation);
					Physics.SyncTransforms();
					val.mainRigidbody.isKinematic = isKinematic;
					val.mainRigidbody.velocity = Vector3.zero;
					val.mainRigidbody.angularVelocity = Vector3.zero;
				}
				else
				{
					((Component)val).transform.SetPositionAndRotation(savedPosition.Value, savedRotation);
				}
				val.syncedPosition = savedPosition.Value;
				val.syncedRotation = savedRotation;
				HUDManager instance2 = HUDManager.Instance;
				if (instance2 != null)
				{
					instance2.DisplayTip("Cruiser Checkpoint", "Cruiser teleported!", false, false, "LC_Tip1");
				}
			}
		}

		internal static void ToggleShipMagnet()
		{
			if (!((Object)(object)StartOfRound.Instance == (Object)null))
			{
				bool flag = !StartOfRound.Instance.magnetOn;
				StartOfRound.Instance.SetMagnetOnServerRpc(flag);
				string text = (flag ? "ON" : "OFF");
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Ship Magnet", "Magnet turned " + text, false, false, "LC_Tip1");
				}
			}
		}
	}
	internal class CruiserMenuGUI : MonoBehaviour
	{
		private Rect windowRect = new Rect(40f, 40f, 310f, 380f);

		private Texture2D bgTex;

		private GUIStyle boxStyle;

		private GUIStyle titleStyle;

		private GUIStyle subTitleStyle;

		private GUIStyle btnOnStyle;

		private GUIStyle btnOffStyle;

		private GUIStyle keyBtnStyle;

		private void InitStyles()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)bgTex != (Object)null))
			{
				bgTex = new Texture2D(1, 1);
				bgTex.SetPixel(0, 0, new Color(0.1f, 0.11f, 0.14f, 0.95f));
				bgTex.Apply();
				boxStyle = new GUIStyle(GUI.skin.box);
				boxStyle.normal.background = bgTex;
				titleStyle = new GUIStyle(GUI.skin.label);
				titleStyle.fontSize = 15;
				titleStyle.fontStyle = (FontStyle)1;
				titleStyle.alignment = (TextAnchor)4;
				titleStyle.normal.textColor = new Color(1f, 0.45f, 0.2f);
				subTitleStyle = new GUIStyle(GUI.skin.label);
				subTitleStyle.fontSize = 12;
				subTitleStyle.fontStyle = (FontStyle)1;
				subTitleStyle.alignment = (TextAnchor)4;
				subTitleStyle.normal.textColor = new Color(0.75f, 0.75f, 0.75f);
				btnOnStyle = new GUIStyle(GUI.skin.button);
				btnOnStyle.fontSize = 13;
				btnOnStyle.fontStyle = (FontStyle)1;
				btnOnStyle.normal.textColor = new Color(0.35f, 1f, 0.45f);
				btnOffStyle = new GUIStyle(GUI.skin.button);
				btnOffStyle.fontSize = 13;
				btnOffStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f);
				keyBtnStyle = new GUIStyle(GUI.skin.button);
				keyBtnStyle.fontSize = 12;
				keyBtnStyle.normal.textColor = new Color(0.4f, 0.85f, 1f);
			}
		}

		private void OnGUI()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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)
			//IL_006f: Invalid comparison between Unknown and I4
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.menuOpen)
			{
				return;
			}
			InitStyles();
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
			if (Plugin.waitingForRebind != 0 && Keyboard.current != null)
			{
				Enumerator<KeyControl> enumerator = Keyboard.current.allKeys.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						KeyControl current = enumerator.Current;
						if (current == null || !((ButtonControl)current).wasPressedThisFrame || (int)current.keyCode == 0)
						{
							continue;
						}
						if ((int)current.keyCode == 60)
						{
							Plugin.waitingForRebind = 0;
							break;
						}
						if (Plugin.waitingForRebind == 1)
						{
							Plugin.savePointKey.Value = current.keyCode;
						}
						if (Plugin.waitingForRebind == 2)
						{
							Plugin.teleportKey.Value = current.keyCode;
						}
						if (Plugin.waitingForRebind == 3)
						{
							Plugin.toggleMagnetKey.Value = current.keyCode;
						}
						if (Plugin.waitingForRebind == 4)
						{
							Plugin.toggleMenuKey.Value = current.keyCode;
						}
						Plugin.waitingForRebind = 0;
						break;
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}
			windowRect = GUI.Window(849201, windowRect, new WindowFunction(DrawWindow), "", boxStyle);
		}

		private void DrawWindow(int id)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(10f, 10f, 290f, 26f), "CRUISER PRACTICE MENU", titleStyle);
			if (GUI.Button(new Rect(15f, 45f, 280f, 34f), "Player God Mode: " + (Plugin.playerGodMode ? "ON" : "OFF"), Plugin.playerGodMode ? btnOnStyle : btnOffStyle))
			{
				Plugin.playerGodMode = !Plugin.playerGodMode;
			}
			if (GUI.Button(new Rect(15f, 85f, 280f, 34f), "Car God Mode: " + (Plugin.carGodMode ? "ON" : "OFF"), Plugin.carGodMode ? btnOnStyle : btnOffStyle))
			{
				Plugin.carGodMode = !Plugin.carGodMode;
			}
			if (GUI.Button(new Rect(15f, 125f, 280f, 34f), "Infinite Jump Fuel: " + (Plugin.infiniteJumpFuel ? "ON" : "OFF"), Plugin.infiniteJumpFuel ? btnOnStyle : btnOffStyle))
			{
				Plugin.infiniteJumpFuel = !Plugin.infiniteJumpFuel;
			}
			GUI.Label(new Rect(10f, 168f, 290f, 22f), "--- KEYBINDS (Click to Rebind) ---", subTitleStyle);
			string text = ((Plugin.waitingForRebind == 1) ? "Press any key..." : $"Save Point Key: [{Plugin.savePointKey.Value}]");
			if (GUI.Button(new Rect(15f, 195f, 280f, 30f), text, keyBtnStyle))
			{
				Plugin.waitingForRebind = 1;
			}
			string text2 = ((Plugin.waitingForRebind == 2) ? "Press any key..." : $"Teleport Key: [{Plugin.teleportKey.Value}]");
			if (GUI.Button(new Rect(15f, 231f, 280f, 30f), text2, keyBtnStyle))
			{
				Plugin.waitingForRebind = 2;
			}
			string text3 = ((Plugin.waitingForRebind == 3) ? "Press any key..." : $"Magnet Key: [{Plugin.toggleMagnetKey.Value}]");
			if (GUI.Button(new Rect(15f, 267f, 280f, 30f), text3, keyBtnStyle))
			{
				Plugin.waitingForRebind = 3;
			}
			string text4 = ((Plugin.waitingForRebind == 4) ? "Press any key..." : $"Menu Key: [{Plugin.toggleMenuKey.Value}]");
			if (GUI.Button(new Rect(15f, 303f, 280f, 30f), text4, keyBtnStyle))
			{
				Plugin.waitingForRebind = 4;
			}
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 11;
			val.alignment = (TextAnchor)4;
			val.normal.textColor = Color.gray;
			GUI.Label(new Rect(10f, 345f, 290f, 22f), $"Press [{Plugin.toggleMenuKey.Value}] to close", val);
			GUI.DragWindow(new Rect(0f, 0f, 310f, 40f));
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	internal class PlayerInputPatch
	{
		private static void Postfix(PlayerControllerB __instance)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || __instance.isTypingChat || Keyboard.current == null || Plugin.waitingForRebind != 0)
			{
				return;
			}
			KeyControl val = Keyboard.current[Plugin.toggleMenuKey.Value];
			if (val != null && ((ButtonControl)val).wasPressedThisFrame)
			{
				Plugin.ToggleMenu();
			}
			if (!Plugin.menuOpen)
			{
				KeyControl val2 = Keyboard.current[Plugin.savePointKey.Value];
				if (val2 != null && ((ButtonControl)val2).wasPressedThisFrame)
				{
					Plugin.SaveCruiserPoint();
				}
				KeyControl val3 = Keyboard.current[Plugin.teleportKey.Value];
				if (val3 != null && ((ButtonControl)val3).wasPressedThisFrame)
				{
					Plugin.TeleportCruiser();
				}
				KeyControl val4 = Keyboard.current[Plugin.toggleMagnetKey.Value];
				if (val4 != null && ((ButtonControl)val4).wasPressedThisFrame)
				{
					Plugin.ToggleShipMagnet();
				}
			}
		}
	}
	[HarmonyPatch(typeof(VehicleController))]
	internal class VehiclePatch
	{
		private static readonly FieldInfo destroyNextFrameField = typeof(VehicleController).GetField("destroyNextFrame", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo turboBoostsField = typeof(VehicleController).GetField("turboBoosts", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(VehicleController __instance)
		{
			if (Plugin.carGodMode)
			{
				destroyNextFrameField?.SetValue(__instance, false);
				__instance.carDestroyed = false;
				if (__instance.carHP < 30)
				{
					__instance.carHP = 30;
				}
			}
			if (Plugin.infiniteJumpFuel)
			{
				turboBoostsField?.SetValue(__instance, 5);
			}
		}

		[HarmonyPatch("DestroyCar")]
		[HarmonyPrefix]
		private static bool PreventDestroyCar()
		{
			return !Plugin.carGodMode;
		}

		[HarmonyPatch("DealPermanentDamage")]
		[HarmonyPrefix]
		private static bool PreventDealPermanentDamage()
		{
			return !Plugin.carGodMode;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerGodModePatch
	{
		[HarmonyPatch("DamagePlayer")]
		[HarmonyPrefix]
		private static bool PreventDamage(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && Plugin.playerGodMode)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool PreventKill(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && Plugin.playerGodMode)
			{
				return false;
			}
			return true;
		}
	}
}