Decompiled source of DefaultKit v1.4.0

DefaultKit.dll

Decompiled 2 hours 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 Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DefaultKit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DefaultKit")]
[assembly: AssemblyTitle("DefaultKit")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 DefaultKit
{
	internal static class Kit
	{
		public const string Walkie = "Walkie-talkie";

		private static readonly HashSet<GrabbableObject> items = new HashSet<GrabbableObject>();

		private static readonly HashSet<ulong> unresolvedIds = new HashSet<ulong>();

		public static void Clear()
		{
			items.Clear();
			unresolvedIds.Clear();
		}

		public static void Add(GrabbableObject item)
		{
			if ((Object)(object)item != (Object)null)
			{
				items.Add(item);
			}
		}

		public static void AddId(ulong id)
		{
			if (!TryResolve(id))
			{
				unresolvedIds.Add(id);
			}
		}

		public static bool IsKit(GrabbableObject item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			ResolvePending();
			return items.Contains(item);
		}

		public static int FindKit(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)null || p.ItemSlots == null)
			{
				return -1;
			}
			for (int i = 0; i < p.ItemSlots.Length; i++)
			{
				if (IsKit(p.ItemSlots[i]))
				{
					return i;
				}
			}
			return -1;
		}

		public static bool NeedsWalkie(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)null || p.ItemSlots == null)
			{
				return false;
			}
			GrabbableObject[] itemSlots = p.ItemSlots;
			foreach (GrabbableObject val in itemSlots)
			{
				if ((Object)(object)val != (Object)null && val.itemProperties.itemName == "Walkie-talkie")
				{
					return false;
				}
			}
			return true;
		}

		public static List<ulong> AliveIds()
		{
			items.RemoveWhere((GrabbableObject g) => (Object)(object)g == (Object)null);
			List<ulong> list = new List<ulong>();
			foreach (GrabbableObject item in items)
			{
				if ((Object)(object)((NetworkBehaviour)item).NetworkObject != (Object)null && ((NetworkBehaviour)item).NetworkObject.IsSpawned)
				{
					list.Add(((NetworkBehaviour)item).NetworkObjectId);
				}
			}
			return list;
		}

		public static IEnumerable<GrabbableObject> All()
		{
			items.RemoveWhere((GrabbableObject g) => (Object)(object)g == (Object)null);
			return items;
		}

		private static void ResolvePending()
		{
			if (unresolvedIds.Count != 0)
			{
				unresolvedIds.RemoveWhere(TryResolve);
			}
		}

		private static bool TryResolve(ulong id)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null)
			{
				return false;
			}
			if (!singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value))
			{
				return false;
			}
			GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			items.Add(component);
			return true;
		}
	}
	internal static class Net
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnRequest;

			public static HandleNamedMessageDelegate <1>__OnGive;

			public static HandleNamedMessageDelegate <2>__OnMark;

			public static HandleNamedMessageDelegate <3>__OnSyncRequest;

			public static HandleNamedMessageDelegate <4>__OnSync;
		}

		private const string ReqMsg = "DefaultKit_Request";

		private const string GiveMsg = "DefaultKit_Give";

		private const string MarkMsg = "DefaultKit_Mark";

		private const string SyncReqMsg = "DefaultKit_SyncReq";

		private const string SyncMsg = "DefaultKit_Sync";

		private static readonly Dictionary<ulong, GrabbableObject> pending = new Dictionary<ulong, GrabbableObject>();

		public unsafe static bool Register()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
				{
					return false;
				}
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				object obj = <>O.<0>__OnRequest;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnRequest;
					<>O.<0>__OnRequest = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("DefaultKit_Request", (HandleNamedMessageDelegate)obj);
				CustomMessagingManager customMessagingManager2 = singleton.CustomMessagingManager;
				object obj2 = <>O.<1>__OnGive;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnGive;
					<>O.<1>__OnGive = val2;
					obj2 = (object)val2;
				}
				customMessagingManager2.RegisterNamedMessageHandler("DefaultKit_Give", (HandleNamedMessageDelegate)obj2);
				CustomMessagingManager customMessagingManager3 = singleton.CustomMessagingManager;
				object obj3 = <>O.<2>__OnMark;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnMark;
					<>O.<2>__OnMark = val3;
					obj3 = (object)val3;
				}
				customMessagingManager3.RegisterNamedMessageHandler("DefaultKit_Mark", (HandleNamedMessageDelegate)obj3);
				CustomMessagingManager customMessagingManager4 = singleton.CustomMessagingManager;
				object obj4 = <>O.<3>__OnSyncRequest;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnSyncRequest;
					<>O.<3>__OnSyncRequest = val4;
					obj4 = (object)val4;
				}
				customMessagingManager4.RegisterNamedMessageHandler("DefaultKit_SyncReq", (HandleNamedMessageDelegate)obj4);
				CustomMessagingManager customMessagingManager5 = singleton.CustomMessagingManager;
				object obj5 = <>O.<4>__OnSync;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val5 = OnSync;
					<>O.<4>__OnSync = val5;
					obj5 = (object)val5;
				}
				customMessagingManager5.RegisterNamedMessageHandler("DefaultKit_Sync", (HandleNamedMessageDelegate)obj5);
				Kit.Clear();
				if (singleton.IsServer)
				{
					pending.Clear();
				}
				else
				{
					FastBufferWriter val6 = default(FastBufferWriter);
					((FastBufferWriter)(ref val6))..ctor(8, (Allocator)2, -1);
					try
					{
						bool flag = true;
						((FastBufferWriter)(ref val6)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
						singleton.CustomMessagingManager.SendNamedMessage("DefaultKit_SyncReq", 0uL, val6, (NetworkDelivery)2);
					}
					finally
					{
						((IDisposable)(*(FastBufferWriter*)(&val6))/*cast due to .constrained prefix*/).Dispose();
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				Status.AddError("Failed to register network messages: " + ex.Message);
				return false;
			}
		}

		public static void RequestKitDelayed(PlayerControllerB p, float delay)
		{
			if ((Object)(object)p != (Object)null && ((Behaviour)p).isActiveAndEnabled)
			{
				((MonoBehaviour)p).StartCoroutine(Delayed(delay));
			}
		}

		private static IEnumerator Delayed(float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			RequestKit();
		}

		public unsafe static void RequestKit()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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)
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)val == (Object)null || (Object)(object)singleton == (Object)null || val.isPlayerDead || !val.isPlayerControlled || !Kit.NeedsWalkie(val))
			{
				return;
			}
			if (singleton.IsServer)
			{
				ServerGive(singleton.LocalClientId);
				return;
			}
			FastBufferWriter val2 = default(FastBufferWriter);
			((FastBufferWriter)(ref val2))..ctor(8, (Allocator)2, -1);
			try
			{
				bool flag = true;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("DefaultKit_Request", 0uL, val2, (NetworkDelivery)2);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnGive(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ulong id = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			Kit.AddId(id);
			StartGrab(id);
		}

		private static void OnMark(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ulong id = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			Kit.AddId(id);
		}

		private static void OnSync(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong id = default(ulong);
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
				Kit.AddId(id);
			}
			Plugin.Log.LogInfo((object)$"Synced {num} default walkie(s) from host");
		}

		private static void StartGrab(ulong id)
		{
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val != (Object)null)
			{
				((MonoBehaviour)val).StartCoroutine(GrabRoutine(val, id));
			}
		}

		private static IEnumerator GrabRoutine(PlayerControllerB p, ulong id)
		{
			GrabbableObject item = null;
			float t = 0f;
			while ((Object)(object)item == (Object)null && t < 10f)
			{
				if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value))
				{
					item = ((Component)value).GetComponent<GrabbableObject>();
				}
				if ((Object)(object)item == (Object)null)
				{
					t += Time.deltaTime;
					yield return null;
				}
			}
			if ((Object)(object)item == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"Walkie {id} never spawned on this client");
				yield break;
			}
			for (int attempt = 0; attempt < 40; attempt++)
			{
				if ((Object)(object)item == (Object)null || p.isPlayerDead)
				{
					yield break;
				}
				if (item.isHeld)
				{
					if ((Object)(object)item.playerHeldBy == (Object)(object)p)
					{
						Plugin.Log.LogInfo((object)"Walkie received");
					}
					else
					{
						Plugin.Log.LogWarning((object)"Walkie was picked up by another player");
					}
					yield break;
				}
				if (CanGrabNow(p))
				{
					PlaceInFront(p, item);
					Physics.SyncTransforms();
					p.BeginGrabObject();
				}
				yield return (object)new WaitForSeconds(0.5f);
			}
			Plugin.Log.LogWarning((object)"Could not pick up the walkie automatically");
		}

		private static bool CanGrabNow(PlayerControllerB p)
		{
			if (p.isPlayerControlled && !p.isPlayerDead && !p.isGrabbingObjectAnimation && !p.inSpecialInteractAnimation && !p.twoHanded && !p.isTypingChat && !p.inTerminalMenu)
			{
				return !p.quickMenuManager.isMenuOpen;
			}
			return false;
		}

		private static void PlaceInFront(PlayerControllerB p, GrabbableObject item)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)p.gameplayCamera).transform;
			Vector3 val = transform.position + transform.forward * 0.35f;
			((Component)item).transform.position = val;
			item.startFallingPosition = (item.targetFloorPosition = (((Object)(object)((Component)item).transform.parent != (Object)null) ? ((Component)item).transform.parent.InverseTransformPoint(val) : val));
			item.fallTime = 1f;
			item.hasHitGround = true;
			item.reachedFloorTarget = true;
		}

		private static void OnRequest(ulong sender, FastBufferReader r)
		{
			if (NetworkManager.Singleton.IsServer)
			{
				ServerGive(sender);
			}
		}

		private unsafe static void ServerGive(ulong clientId)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = FindPlayer(clientId);
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !Kit.NeedsWalkie(val))
			{
				return;
			}
			pending.TryGetValue(clientId, out var value);
			if ((Object)(object)value == (Object)null || value.isHeld || (Object)(object)((NetworkBehaviour)value).NetworkObject == (Object)null || !((NetworkBehaviour)value).NetworkObject.IsSpawned)
			{
				value = Spawn("Walkie-talkie", val);
				if ((Object)(object)value == (Object)null)
				{
					return;
				}
				Plugin.Log.LogInfo((object)("Walkie spawned for " + val.playerUsername));
				pending[clientId] = value;
				Kit.Add(value);
				BroadcastMark(((NetworkBehaviour)value).NetworkObjectId);
			}
			if (clientId == NetworkManager.Singleton.LocalClientId)
			{
				StartGrab(((NetworkBehaviour)value).NetworkObjectId);
				return;
			}
			FastBufferWriter val2 = default(FastBufferWriter);
			((FastBufferWriter)(ref val2))..ctor(16, (Allocator)2, -1);
			try
			{
				ulong networkObjectId = ((NetworkBehaviour)value).NetworkObjectId;
				((FastBufferWriter)(ref val2)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DefaultKit_Give", clientId, val2, (NetworkDelivery)2);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private unsafe static void OnSyncRequest(ulong sender, FastBufferReader r)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsServer)
			{
				return;
			}
			List<ulong> list = Kit.AliveIds();
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8 + 8 * list.Count, (Allocator)2, -1);
			try
			{
				int count = list.Count;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
				foreach (ulong item in list)
				{
					ulong current = item;
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current, default(ForPrimitives));
				}
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("DefaultKit_Sync", sender, val, (NetworkDelivery)2);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private unsafe static void BroadcastMark(ulong id)
		{
			//IL_0035: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			FastBufferWriter val = default(FastBufferWriter);
			foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
			{
				if (connectedClientsId != singleton.LocalClientId)
				{
					((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
					try
					{
						((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
						singleton.CustomMessagingManager.SendNamedMessage("DefaultKit_Mark", connectedClientsId, val, (NetworkDelivery)2);
					}
					finally
					{
						((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
					}
				}
			}
		}

		private static GrabbableObject Spawn(string itemName, PlayerControllerB player)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Item val = StartOfRound.Instance.allItemsList.itemsList.Find((Item i) => i.itemName == itemName);
			if ((Object)(object)val == (Object)null)
			{
				Status.AddError("Item '" + itemName + "' not found");
				return null;
			}
			Vector3 val2 = ((Component)player).transform.position + Vector3.up;
			GameObject obj = Object.Instantiate<GameObject>(val.spawnPrefab, val2, Quaternion.identity, StartOfRound.Instance.propsContainer);
			obj.GetComponent<NetworkObject>().Spawn(false);
			return obj.GetComponent<GrabbableObject>();
		}

		private static PlayerControllerB FindPlayer(ulong clientId)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val != (Object)null && val.isPlayerControlled && val.actualClientId == clientId)
				{
					return val;
				}
			}
			return null;
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		private class KeepState
		{
			public int Slot;

			public GrabbableObject Item;
		}

		private static float lastTip;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		private static void OnConnect(PlayerControllerB __instance)
		{
			bool netOk = Net.Register();
			bool keyOk = WalkieKey.Apply();
			Status.PrintSession(NetworkManager.Singleton.IsServer, netOk, keyOk);
			Net.RequestKitDelayed(__instance, 3f);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
		private static void OnRevive()
		{
			Net.RequestKitDelayed(GameNetworkManager.Instance?.localPlayerController, 1.5f);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")]
		private static void OnLanded()
		{
			Net.RequestKitDelayed(GameNetworkManager.Instance?.localPlayerController, 0.5f);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		private static void BeforeDeath(PlayerControllerB __instance)
		{
			if (!((NetworkBehaviour)__instance).IsOwner || __instance.isPlayerDead || !__instance.AllowPlayerDeath())
			{
				return;
			}
			int num = Kit.FindKit(__instance);
			if (num >= 0)
			{
				GrabbableObject obj = __instance.ItemSlots[num];
				WalkieTalkie val = (WalkieTalkie)(object)((obj is WalkieTalkie) ? obj : null);
				if (val != null && __instance.speakingToWalkieTalkie)
				{
					val.SetLocalClientSpeaking(false);
				}
				__instance.DestroyItemInSlotAndSync(num);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")]
		private static bool BeforeDiscard(PlayerControllerB __instance)
		{
			if (!Plugin.PreventDrop.Value || !((NetworkBehaviour)__instance).IsOwner || __instance.isPlayerDead)
			{
				return true;
			}
			if (!Kit.IsKit(__instance.currentlyHeldObjectServer))
			{
				return true;
			}
			if (Time.time - lastTip > 3f && (Object)(object)HUDManager.Instance != (Object)null)
			{
				lastTip = Time.time;
				HUDManager.Instance.DisplayTip("Walkie-talkie", "Your default walkie can't be dropped.", false, false, "LC_Tip1");
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItems")]
		private static void BeforeDropAll(PlayerControllerB __instance, bool __1, out KeepState __state)
		{
			__state = null;
			if (!Plugin.PreventDrop.Value || __1 || __instance.isPlayerDead || !__instance.isPlayerControlled)
			{
				return;
			}
			int num = Kit.FindKit(__instance);
			if (num < 0)
			{
				return;
			}
			GrabbableObject val = __instance.ItemSlots[num];
			if ((Object)(object)__instance.currentlyHeldObjectServer == (Object)(object)val)
			{
				val.PocketItem();
				__instance.currentlyHeldObjectServer = null;
				if ((Object)(object)__instance.currentlyHeldObject == (Object)(object)val)
				{
					__instance.currentlyHeldObject = null;
				}
				__instance.isHoldingObject = false;
			}
			__instance.ItemSlots[num] = null;
			__state = new KeepState
			{
				Slot = num,
				Item = val
			};
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItems")]
		private static void AfterDropAll(PlayerControllerB __instance, KeepState __state)
		{
			if (__state != null && !((Object)(object)__state.Item == (Object)null))
			{
				GrabbableObject item = __state.Item;
				__instance.ItemSlots[__state.Slot] = item;
				__instance.carryWeight = Mathf.Clamp(__instance.carryWeight + (item.itemProperties.weight - 1f), 1f, 10f);
				if (((NetworkBehaviour)__instance).IsOwner && (Object)(object)HUDManager.Instance != (Object)null && __state.Slot < HUDManager.Instance.itemSlotIcons.Length)
				{
					Image obj = HUDManager.Instance.itemSlotIcons[__state.Slot];
					obj.sprite = item.itemProperties.itemIcon;
					((Behaviour)obj).enabled = true;
				}
				if (((NetworkBehaviour)__instance).IsOwner)
				{
					Plugin.Log.LogInfo((object)"Walkie kept (items were dropped by teleporter)");
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
		private static void BeforeSaveItems(out List<GrabbableObject> __state)
		{
			__state = new List<GrabbableObject>();
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			foreach (GrabbableObject item in Kit.All())
			{
				if (!item.deactivated)
				{
					item.deactivated = true;
					__state.Add(item);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
		private static void AfterSaveItems(List<GrabbableObject> __state)
		{
			if (__state == null)
			{
				return;
			}
			foreach (GrabbableObject item in __state)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.deactivated = false;
				}
			}
			if (__state.Count > 0)
			{
				Plugin.Log.LogInfo((object)$"Excluded {__state.Count} default walkie(s) from the save file");
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("defaultkit.lethalcompany", "DefaultKit", "1.4.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "defaultkit.lethalcompany";

		public const string NAME = "DefaultKit";

		public const string VERSION = "1.4.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> WalkieKey;

		internal static ConfigEntry<bool> PreventDrop;

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			WalkieKey = ((BaseUnityPlugin)this).Config.Bind<string>("General", "WalkieKey", "<Keyboard>/v", "Hold this key to talk through the walkie. Examples: <Keyboard>/v, <Keyboard>/b. Leave empty to use the ReservedWalkieSlot key.");
			PreventDrop = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PreventWalkieDrop", true, "If true, the walkie given by this mod can't be dropped, placed, or lost to the teleporter / inverse teleporter. Bought walkies work as normal.");
			Harmony val = new Harmony("defaultkit.lethalcompany");
			try
			{
				val.PatchAll();
			}
			catch (Exception ex)
			{
				Status.AddError("Failed to apply patches: " + ex);
			}
			Status.PrintStartup(val);
		}
	}
	internal static class Status
	{
		private const int ExpectedPatches = 7;

		private static readonly List<string> errors = new List<string>();

		public static void AddError(string msg)
		{
			errors.Add(msg);
			Plugin.Log.LogError((object)msg);
		}

		public static void PrintStartup(Harmony harmony)
		{
			ManualLogSource log = Plugin.Log;
			log.LogMessage((object)"================ DefaultKit ================");
			bool flag = CheckDependency("FlipMods.ReservedItemSlotCore", "ReservedItemSlotCore");
			bool flag2 = CheckDependency("FlipMods.ReservedWalkieSlot", "ReservedWalkieSlot");
			int num = 0;
			try
			{
				num = harmony.GetPatchedMethods().Count();
			}
			catch (Exception ex)
			{
				AddError("Could not count patches: " + ex.Message);
			}
			if (num >= 7)
			{
				log.LogInfo((object)$"Harmony patches: {num}/{7} OK");
			}
			else
			{
				AddError($"Harmony patches: {num}/{7} (missing patches)");
			}
			log.LogInfo((object)("Walkie key (config): " + Plugin.WalkieKey.Value));
			log.LogInfo((object)$"Prevent walkie drop (config): {Plugin.PreventDrop.Value}");
			if (flag && flag2 && errors.Count == 0)
			{
				log.LogMessage((object)"Status: ENABLED (v1.4.0)");
			}
			else
			{
				log.LogError((object)$"Status: ERROR ({errors.Count} problem(s), check the lines above)");
			}
			log.LogMessage((object)"============================================");
		}

		public static void PrintSession(bool isHost, bool netOk, bool keyOk)
		{
			ManualLogSource log = Plugin.Log;
			log.LogMessage((object)"------------ DefaultKit: session ------------");
			log.LogInfo((object)("Role: " + (isHost ? "HOST" : "CLIENT")));
			if (netOk)
			{
				log.LogInfo((object)"Network: OK");
			}
			else
			{
				log.LogError((object)"Network: ERROR (messages not registered)");
			}
			if (keyOk)
			{
				log.LogInfo((object)("Walkie key: " + Plugin.WalkieKey.Value + " OK"));
			}
			else
			{
				log.LogWarning((object)"Walkie key: NOT APPLIED (using ReservedWalkieSlot key)");
			}
			log.LogMessage((object)(netOk ? "Session status: ENABLED" : "Session status: ERROR"));
			log.LogMessage((object)"---------------------------------------------");
		}

		private static bool CheckDependency(string guid, string name)
		{
			if (Chainloader.PluginInfos.TryGetValue(guid, out var value))
			{
				Plugin.Log.LogInfo((object)$"{name}: OK ({value.Metadata.Version})");
				return true;
			}
			AddError(name + ": NOT FOUND");
			return false;
		}
	}
	internal static class WalkieKey
	{
		public static bool Apply()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			string value = Plugin.WalkieKey.Value;
			if (string.IsNullOrWhiteSpace(value))
			{
				return false;
			}
			bool flag = false;
			try
			{
				foreach (InputAction item in InputSystem.ListEnabledActions())
				{
					if (item == null || item.name == null || (item.name.IndexOf("ActivateWalkie", StringComparison.OrdinalIgnoreCase) < 0 && item.name.IndexOf("Activate Walkie", StringComparison.OrdinalIgnoreCase) < 0))
					{
						continue;
					}
					for (int i = 0; i < item.bindings.Count; i++)
					{
						InputBinding val = item.bindings[i];
						if (!((InputBinding)(ref val)).isComposite && ((InputBinding)(ref val)).path != null && ((InputBinding)(ref val)).path.StartsWith("<keyboard>", StringComparison.OrdinalIgnoreCase))
						{
							InputActionRebindingExtensions.ApplyBindingOverride(item, i, value);
							flag = true;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Status.AddError("Failed to change the walkie key: " + ex.Message);
				return false;
			}
			if (flag)
			{
				Plugin.Log.LogInfo((object)("Walkie key changed to " + value));
			}
			else
			{
				Plugin.Log.LogWarning((object)"ReservedWalkieSlot ActivateWalkie action not found");
			}
			return flag;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}