Decompiled source of ReservedPeeperSlot v1.0.5

ReservedPeeperSlot.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using ReservedItemSlotCore;
using ReservedItemSlotCore.Data;
using ReservedPeeperSlot.Compat;
using ReservedPeeperSlot.Input;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 ReservedPeeperSlot
{
	internal class Metadata
	{
		public const string GUID = "snacksbr.lethalcompany.reservedpeeperslot";

		public const string NAME = "ReservedPeeperSlot";

		public const string VERSION = "1.0.5";
	}
	[BepInPlugin("snacksbr.lethalcompany.reservedpeeperslot", "ReservedPeeperSlot", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		private readonly Harmony harmony = new Harmony("snacksbr.lethalcompany.reservedpeeperslot");

		internal static readonly ManualLogSource mls = Logger.CreateLogSource("ReservedPeeperSlot");

		public static ReservedItemSlotData PeeperSlot;

		public static ReservedItemData PeeperItemData;

		private void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Instance = this;
			Settings.Init();
			PeeperItemData = new ReservedItemData("Peeper", (PlayerBone)0, default(Vector3), default(Vector3));
			PeeperSlot = ReservedItemSlotData.CreateReservedItemSlotData("PeeperSlot", 668, 100);
			PeeperSlot.purchasePrice = Settings.PeeperPrice.Value;
			PeeperSlot.AddItemToReservedItemSlot(PeeperItemData);
			try
			{
				Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				ex.Types.Where((Type t) => t != null);
			}
			if (Settings.DeployPeeper.Value && InputUtils_Compat.Enabled)
			{
				InputUtils_Compat.Init();
			}
			harmony.PatchAll();
		}
	}
	public static class Settings
	{
		public static Dictionary<string, ConfigEntryBase> ConfigEntries = new Dictionary<string, ConfigEntryBase>();

		public static ConfigEntry<string> DeployPeeperKey;

		public static ConfigEntry<bool> DeployPeeper;

		public static ConfigEntry<int> PeeperPrice;

		public static void Init()
		{
			DeployPeeperKey = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("ReservedPeeperSlot", "DropPeeperKey", "<Keyboard>/t", "Keybind to drop the Peeper on the ground. (will be ignored if InputUtils is present)");
			DeployPeeper = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("ReservedPeeperSlot", "DeployPeeper", true, "Enable the keybind drop the Peeper.");
			PeeperPrice = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("ReservedPeeperSlot", "PeeperPrice", 0, "Price for the Peeper Slot. If set to 0 the slot will unlock automatically");
			ConfigEntries.Add(((ConfigEntryBase)DeployPeeperKey).Definition.Key, (ConfigEntryBase)(object)DeployPeeperKey);
			ConfigEntries.Add(((ConfigEntryBase)DeployPeeper).Definition.Key, (ConfigEntryBase)(object)DeployPeeper);
			ConfigEntries.Add(((ConfigEntryBase)PeeperPrice).Definition.Key, (ConfigEntryBase)(object)PeeperPrice);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ReservedPeeperSlot";

		public const string PLUGIN_NAME = "ReservedPeeperSlot";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ReservedPeeperSlot.Input
{
	internal class IngameKeybinds : LcInputActions
	{
		public static IngameKeybinds Instance = new IngameKeybinds();

		[InputAction("<Keyboard>/t", Name = "[ReservedPeeperSlot]\nDrop Peeper")]
		public InputAction DropPeeperAction { get; set; }

		internal static InputActionAsset GetAsset()
		{
			return ((LcInputActions)Instance).Asset;
		}
	}
	[HarmonyPatch]
	internal static class Keybinds
	{
		public static InputActionAsset Asset;

		public static InputActionMap ActionMap;

		private static InputAction DropPeeperAction;

		public static PlayerControllerB LocalPlayerController => StartOfRound.Instance?.localPlayerController;

		[HarmonyPatch(typeof(PreInitSceneScript), "Awake")]
		[HarmonyPrefix]
		public static void AddToKeybindMenu()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.DeployPeeper.Value)
			{
				if (InputUtils_Compat.Enabled)
				{
					Asset = InputUtils_Compat.Asset;
					ActionMap = Asset.actionMaps[0];
					DropPeeperAction = IngameKeybinds.Instance.DropPeeperAction;
				}
				else
				{
					Asset = ScriptableObject.CreateInstance<InputActionAsset>();
					ActionMap = new InputActionMap("ReservedPeeperSlot");
					InputActionSetupExtensions.AddActionMap(Asset, ActionMap);
					DropPeeperAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedPeeperSlot.DropPeeperAction", (InputActionType)0, Settings.DeployPeeperKey.Value, "Press", (string)null, (string)null, (string)null);
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable()
		{
			if (Settings.DeployPeeper.Value)
			{
				Asset.Enable();
				DropPeeperAction.performed += OnDropRadarBoosterPerformed;
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable()
		{
			if (Settings.DeployPeeper.Value)
			{
				Asset.Disable();
				DropPeeperAction.performed -= OnDropRadarBoosterPerformed;
			}
		}

		private static void OnDropRadarBoosterPerformed(CallbackContext context)
		{
			if ((Object)(object)LocalPlayerController == (Object)null || !LocalPlayerController.isPlayerControlled || (((NetworkBehaviour)LocalPlayerController).IsServer && !LocalPlayerController.isHostPlayerObject))
			{
				return;
			}
			try
			{
				if (SessionManager.unlockedReservedItemSlotsDict.TryGetValue(Plugin.PeeperSlot.slotName, out var value))
				{
					List<ReservedItemSlotData> list = new List<ReservedItemSlotData>(1) { value };
					if (list.Count > 0)
					{
						ReservedHotbarManager.ForceToggleReservedHotbar(list.ToArray());
						((MonoBehaviour)LocalPlayerController).StartCoroutine(ShuffleItems());
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.mls.LogError((object)ex.Message);
				Plugin.mls.LogError((object)ex.StackTrace);
				TextMeshProUGUI chatText = HUDManager.Instance.chatText;
				((TMP_Text)chatText).text = ((TMP_Text)chatText).text + "Error when dropping Peeper";
			}
		}

		private static IEnumerator ShuffleItems()
		{
			yield return (object)new WaitForSeconds(0.2f);
			if ((Object)(object)LocalPlayerController.currentlyHeldObjectServer != (Object)null)
			{
				LocalPlayerController.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
			}
			yield return (object)new WaitForSeconds(0.1f);
			ReservedHotbarManager.FocusReservedHotbarSlots(false, -1);
		}
	}
}
namespace ReservedPeeperSlot.Compat
{
	public static class InputUtils_Compat
	{
		internal static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.LethalCompanyInputUtils");

		internal static InputActionAsset Asset => IngameKeybinds.GetAsset();

		public static InputAction DropPeeperAction => IngameKeybinds.Instance.DropPeeperAction;

		internal static void Init()
		{
			if (Enabled && IngameKeybinds.Instance == null)
			{
				IngameKeybinds.Instance = new IngameKeybinds();
			}
		}
	}
}