Decompiled source of LethalKuchServer v1.1.0

LethalKuchServer.dll

Decompiled 10 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalKuchServer.NetcodePatcher;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
	}
}
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 LethalKuchQOL.Lobby
{
	[HarmonyPatch(typeof(ItemDropship), "Update")]
	public static class FastDelivery
	{
		private static readonly FieldRef<ItemDropship, Terminal> TerminalRef = AccessTools.FieldRefAccess<ItemDropship, Terminal>("terminalScript");

		[HarmonyPrefix]
		private static void Prefix(ItemDropship __instance)
		{
			if (!Plugin.CfgFastDelivery.Value || !((NetworkBehaviour)__instance).IsServer || __instance.deliveringOrder)
			{
				return;
			}
			Terminal val = TerminalRef.Invoke(__instance);
			if (!((Object)(object)val == (Object)null) && (val.orderedItemsFromTerminal.Count > 0 || val.orderedVehicleFromTerminal != -1) && !((Object)(object)StartOfRound.Instance == (Object)null) && StartOfRound.Instance.shipHasLanded)
			{
				float num = 40f - Plugin.CfgDeliverySeconds.Value;
				if (__instance.shipTimer < num)
				{
					__instance.shipTimer = num;
				}
				__instance.playersFirstOrder = false;
			}
		}
	}
	public class KuchNet : NetworkBehaviour
	{
		public NetworkVariable<bool> AllowClientSell = new NetworkVariable<bool>(true, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public NetworkVariable<bool> AnnounceSells = new NetworkVariable<bool>(true, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public static KuchNet Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			Instance = this;
			if (((NetworkBehaviour)this).IsServer)
			{
				AllowClientSell.Value = Plugin.CfgAllowClientSell.Value;
				AnnounceSells.Value = Plugin.CfgAnnounceSells.Value;
			}
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		public override void OnNetworkDespawn()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
			((NetworkBehaviour)this).OnNetworkDespawn();
		}

		public void RequestSell(List<GrabbableObject> items)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			NetworkObjectReference[] array = (from g in items
				where (Object)(object)g != (Object)null
				select ((Component)g).GetComponent<NetworkObject>() into n
				where (Object)(object)n != (Object)null
				select n).Select((Func<NetworkObject, NetworkObjectReference>)((NetworkObject n) => new NetworkObjectReference(n))).ToArray();
			if (array.Length != 0)
			{
				SellServerRpc(array);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void SellServerRpc(NetworkObjectReference[] refs, ServerRpcParams rpc = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(1410248950u, rpc, (RpcDelivery)0);
				bool flag = refs != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(refs, default(ForNetworkSerializable));
				}
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 1410248950u, rpc, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			ulong senderClientId = rpc.Receive.SenderClientId;
			if (senderClientId != 0L && !AllowClientSell.Value)
			{
				DeniedClientRpc(Target(senderClientId));
				return;
			}
			DepositItemsDesk val2 = Object.FindObjectOfType<DepositItemsDesk>();
			if ((Object)(object)val2 == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.inShipPhase)
			{
				return;
			}
			List<GrabbableObject> list = new List<GrabbableObject>();
			NetworkObject val4 = default(NetworkObject);
			for (int i = 0; i < refs.Length; i++)
			{
				NetworkObjectReference val3 = refs[i];
				if (((NetworkObjectReference)(ref val3)).TryGet(ref val4, (NetworkManager)null))
				{
					GrabbableObject componentInChildren = ((Component)val4).GetComponentInChildren<GrabbableObject>();
					if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.isHeld && componentInChildren.itemProperties.isScrap)
					{
						list.Add(componentInChildren);
					}
				}
			}
			if (list.Count != 0)
			{
				((MonoBehaviour)this).StartCoroutine(SellRoutine(val2, list, refs, senderClientId));
			}
		}

		private static ClientRpcParams Target(ulong id)
		{
			//IL_0002: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			return new ClientRpcParams
			{
				Send = new ClientRpcSendParams
				{
					TargetClientIds = new ulong[1] { id }
				}
			};
		}

		private IEnumerator SellRoutine(DepositItemsDesk desk, List<GrabbableObject> items, NetworkObjectReference[] refs, ulong sender)
		{
			HideItemsClientRpc(refs);
			int value = (int)((float)items.Sum((GrabbableObject g) => g.scrapValue) * StartOfRound.Instance.companyBuyingRate);
			foreach (GrabbableObject item in items)
			{
				NetworkObject component = ((Component)item).GetComponent<NetworkObject>();
				if ((Object)(object)component != (Object)null)
				{
					desk.AddObjectToDeskServerRpc(NetworkObjectReference.op_Implicit(component));
				}
			}
			yield return (object)new WaitForSeconds(0.5f);
			desk.SellItemsOnServer();
			if (AnnounceSells.Value)
			{
				PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.actualClientId == sender));
				AnnounceClientRpc(((Object)(object)val != (Object)null) ? val.playerUsername : "Someone", items.Count, value);
			}
		}

		[ClientRpc]
		private void HideItemsClientRpc(NetworkObjectReference[] refs)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1739003948u, val2, (RpcDelivery)0);
				bool flag = refs != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(refs, default(ForNetworkSerializable));
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1739003948u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			DepositItemsDesk val3 = Object.FindObjectOfType<DepositItemsDesk>();
			if ((Object)(object)val3 == (Object)null)
			{
				return;
			}
			NetworkObject val5 = default(NetworkObject);
			for (int i = 0; i < refs.Length; i++)
			{
				NetworkObjectReference val4 = refs[i];
				if (((NetworkObjectReference)(ref val4)).TryGet(ref val5, (NetworkManager)null))
				{
					GrabbableObject componentInChildren = ((Component)val5).GetComponentInChildren<GrabbableObject>();
					if (!((Object)(object)componentInChildren == (Object)null))
					{
						componentInChildren.EnablePhysics(false);
						componentInChildren.EnableItemMeshes(false);
						((Component)componentInChildren).transform.SetParent(((Component)val3.deskObjectsContainer).transform);
						((Component)componentInChildren).transform.localPosition = Vector3.zero;
					}
				}
			}
		}

		[ClientRpc]
		private void AnnounceClientRpc(string who, int count, int value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2332989801u, val2, (RpcDelivery)0);
				bool flag = who != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(who, false);
				}
				BytePacker.WriteValueBitPacked(val, count);
				BytePacker.WriteValueBitPacked(val, value);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2332989801u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Scrap sold", $"{who} sold {count} items for ${value}.", false, false, "LC_Tip1");
				}
			}
		}

		[ClientRpc]
		private void DeniedClientRpc(ClientRpcParams p = default(ClientRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1275051820u, p, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1275051820u, p, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip("Sell denied", "The host has disabled client selling.", true, false, "LC_Tip1");
				}
			}
		}

		public void SetAllowClientSell(bool v)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				AllowClientSell.Value = v;
				Plugin.CfgAllowClientSell.Value = v;
			}
		}

		public void SetAnnounceSells(bool v)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				AnnounceSells.Value = v;
				Plugin.CfgAnnounceSells.Value = v;
			}
		}

		protected override void __initializeVariables()
		{
			if (AllowClientSell == null)
			{
				throw new Exception("KuchNet.AllowClientSell cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)AllowClientSell).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)AllowClientSell, "AllowClientSell");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)AllowClientSell);
			if (AnnounceSells == null)
			{
				throw new Exception("KuchNet.AnnounceSells cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)AnnounceSells).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)AnnounceSells, "AnnounceSells");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)AnnounceSells);
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_KuchNet()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1410248950u, new RpcReceiveHandler(__rpc_handler_1410248950));
			NetworkManager.__rpc_func_table.Add(1739003948u, new RpcReceiveHandler(__rpc_handler_1739003948));
			NetworkManager.__rpc_func_table.Add(2332989801u, new RpcReceiveHandler(__rpc_handler_2332989801));
			NetworkManager.__rpc_func_table.Add(1275051820u, new RpcReceiveHandler(__rpc_handler_1275051820));
		}

		private static void __rpc_handler_1410248950(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				NetworkObjectReference[] refs = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref refs, default(ForNetworkSerializable));
				}
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((KuchNet)(object)target).SellServerRpc(refs, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1739003948(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0088: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				NetworkObjectReference[] refs = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref refs, default(ForNetworkSerializable));
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((KuchNet)(object)target).HideItemsClientRpc(refs);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2332989801(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string who = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref who, false);
				}
				int count = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref count);
				int value = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref value);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((KuchNet)(object)target).AnnounceClientRpc(who, count, value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1275051820(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ClientRpcParams client = rpcParams.Client;
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((KuchNet)(object)target).DeniedClientRpc(client);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "KuchNet";
		}
	}
	public class LobbyPanel : MonoBehaviour
	{
		private bool open;

		private GUIStyle panel;

		private GUIStyle title;

		private GUIStyle label;

		private GUIStyle hint;

		private GUIStyle on;

		private GUIStyle off;

		private bool styled;

		private CursorLockMode prevLock;

		private void Update()
		{
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current.f9Key).wasPressedThisFrame)
			{
				SetOpen(!open);
			}
		}

		private void SetOpen(bool o)
		{
			//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_0081: Unknown result type (might be due to invalid IL or missing references)
			open = o;
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if (o)
			{
				prevLock = Cursor.lockState;
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				if ((Object)(object)val != (Object)null)
				{
					val.disableLookInput = true;
				}
				return;
			}
			if ((Object)(object)val != (Object)null)
			{
				val.disableLookInput = false;
			}
			if ((Object)(object)val != (Object)null && !val.quickMenuManager.isMenuOpen && !val.inTerminalMenu)
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
			else
			{
				Cursor.lockState = prevLock;
			}
			Plugin.Save();
		}

		private static Texture2D Solid(Color c)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}

		private void Style()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0061: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00eb: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_01dc: 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_01ed: 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_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Expected O, but got Unknown
			if (!styled)
			{
				styled = true;
				GUIStyle val = new GUIStyle(GUI.skin.box);
				val.normal.background = Solid(new Color(0.06f, 0.09f, 0.12f, 0.96f));
				val.padding = new RectOffset(18, 18, 14, 14);
				panel = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 20,
					fontStyle = (FontStyle)1
				};
				val2.normal.textColor = new Color(0.45f, 0.75f, 1f);
				title = val2;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14
				};
				val3.normal.textColor = new Color(0.92f, 0.94f, 0.97f);
				label = val3;
				GUIStyle val4 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 11,
					wordWrap = true
				};
				val4.normal.textColor = new Color(0.55f, 0.62f, 0.7f);
				hint = val4;
				Texture2D background = Solid(new Color(0.45f, 0.75f, 1f));
				Texture2D background2 = Solid(new Color(0.22f, 0.25f, 0.3f));
				GUIStyle val5 = new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 54f,
					fixedHeight = 24f,
					fontSize = 11,
					fontStyle = (FontStyle)1
				};
				val5.normal.background = background;
				val5.normal.textColor = Color.black;
				val5.hover.background = background;
				val5.hover.textColor = Color.black;
				val5.active.background = background;
				on = val5;
				GUIStyle val6 = new GUIStyle(on);
				val6.normal.background = background2;
				val6.normal.textColor = new Color(0.85f, 0.85f, 0.9f);
				val6.hover.background = background2;
				val6.hover.textColor = Color.white;
				val6.active.background = background2;
				off = val6;
			}
		}

		private void OnGUI()
		{
			//IL_0040: 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)
			if (!open)
			{
				return;
			}
			Style();
			float num = 460f;
			float num2 = 420f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
			GUI.Box(val, GUIContent.none, panel);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 18f, ((Rect)(ref val)).y + 14f, num - 36f, num2 - 28f));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("LethalKuchServer", title, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label("v1.1.0   F9 to close", hint, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(8f);
			NetworkManager singleton = NetworkManager.Singleton;
			KuchNet instance = KuchNet.Instance;
			bool flag = (Object)(object)singleton != (Object)null && singleton.IsListening;
			bool flag2 = flag && singleton.IsHost;
			string obj = ((!flag) ? "Not in a lobby" : ((!((Object)(object)instance == (Object)null)) ? (flag2 ? "Synced. You are the host." : "Synced with host.") : (flag2 ? "Spawning..." : "Host does not have LethalKuchServer")));
			GUILayout.Label("STATUS", hint, Array.Empty<GUILayoutOption>());
			GUILayout.Label(obj, label, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label(flag2 ? "HOST OPTIONS (synced to everyone)" : "HOST OPTIONS (read-only)", hint, Array.Empty<GUILayoutOption>());
			bool flag3 = (((Object)(object)instance != (Object)null) ? instance.AllowClientSell.Value : Plugin.CfgAllowClientSell.Value);
			bool flag4 = (((Object)(object)instance != (Object)null) ? instance.AnnounceSells.Value : Plugin.CfgAnnounceSells.Value);
			if (Row("Clients can use sell commands", "Non-host players may sell via the terminal.", flag3, flag2 || (Object)(object)instance == (Object)null))
			{
				flag3 = !flag3;
				if ((Object)(object)instance != (Object)null)
				{
					instance.SetAllowClientSell(flag3);
				}
				else
				{
					Plugin.CfgAllowClientSell.Value = flag3;
				}
			}
			if (Row("Announce sells to everyone", "HUD tip with who sold what for how much.", flag4, flag2 || (Object)(object)instance == (Object)null))
			{
				flag4 = !flag4;
				if ((Object)(object)instance != (Object)null)
				{
					instance.SetAnnounceSells(flag4);
				}
				else
				{
					Plugin.CfgAnnounceSells.Value = flag4;
				}
			}
			bool value = Plugin.CfgFastDelivery.Value;
			bool flag5 = flag2 || !flag;
			if (Row("Fast item delivery", "Dropship arrives after the time below instead of 40 s.", value, flag5))
			{
				Plugin.CfgFastDelivery.Value = !value;
			}
			if (Plugin.CfgFastDelivery.Value)
			{
				GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
				GUILayout.Label("Delivery time", label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
				GUI.enabled = flag5;
				float num3 = Mathf.Round(GUILayout.HorizontalSlider(Plugin.CfgDeliverySeconds.Value, 0f, 40f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) }));
				GUI.enabled = true;
				GUILayout.Label(num3 + " s", label, Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
				if (flag5 && !Mathf.Approximately(num3, Plugin.CfgDeliverySeconds.Value))
				{
					Plugin.CfgDeliverySeconds.Value = num3;
				}
			}
			GUILayout.Space(6f);
			GUILayout.Label("Settings save to the host's config and apply to the next lobby too. Client features live in LethalKuchClient (F12).", hint, Array.Empty<GUILayoutOption>());
			GUILayout.EndArea();
		}

		private bool Row(string name, string desc, bool value, bool editable)
		{
			GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label(name, label, Array.Empty<GUILayoutOption>());
			GUILayout.Label(desc, hint, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.FlexibleSpace();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			GUI.enabled = editable;
			bool num = GUILayout.Button(value ? "ON" : "OFF", value ? on : off, Array.Empty<GUILayoutOption>());
			GUI.enabled = true;
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			return num && editable;
		}
	}
	[BepInPlugin("ishred.LethalKuchServer", "LethalKuchServer", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		private static class Patches
		{
			[HarmonyPatch(typeof(GameNetworkManager), "Start")]
			[HarmonyPostfix]
			private static void RegisterPrefab()
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				if (!((Object)(object)Prefab != (Object)null))
				{
					Prefab = new GameObject("ishred.LethalKuchServer Prefab");
					((Object)Prefab).hideFlags = (HideFlags)61;
					Object.DontDestroyOnLoad((Object)(object)Prefab);
					NetworkObject obj = Prefab.AddComponent<NetworkObject>();
					typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, Hash("ishred.LethalKuchServer"));
					Prefab.AddComponent<KuchNet>();
					Prefab.SetActive(false);
					NetworkManager.Singleton.AddNetworkPrefab(Prefab);
					Log.LogInfo((object)"Network prefab registered.");
				}
			}

			[HarmonyPatch(typeof(StartOfRound), "Awake")]
			[HarmonyPostfix]
			private static void SpawnOnHost()
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (!((Object)(object)singleton == (Object)null) && singleton.IsHost && !((Object)(object)Prefab == (Object)null))
				{
					GameObject obj = Object.Instantiate<GameObject>(Prefab);
					obj.SetActive(true);
					obj.GetComponent<NetworkObject>().Spawn(false);
					Log.LogInfo((object)"KuchNet spawned by host.");
				}
			}
		}

		public const string GUID = "ishred.LethalKuchServer";

		public const string NAME = "LethalKuchServer";

		public const string VERSION = "1.1.0";

		internal static ManualLogSource Log;

		internal static GameObject Prefab;

		internal static ConfigEntry<bool> CfgAllowClientSell;

		internal static ConfigEntry<bool> CfgAnnounceSells;

		internal static ConfigEntry<bool> CfgFastDelivery;

		internal static ConfigEntry<float> CfgDeliverySeconds;

		private static Plugin inst;

		internal static void Save()
		{
			Plugin plugin = inst;
			if (plugin != null)
			{
				((BaseUnityPlugin)plugin).Config.Save();
			}
		}

		private void Awake()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			inst = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CfgAllowClientSell = ((BaseUnityPlugin)this).Config.Bind<bool>("Host", "AllowClientSell", true, "Host only: non-host players may use the sell terminal commands.");
			CfgAnnounceSells = ((BaseUnityPlugin)this).Config.Bind<bool>("Host", "AnnounceSells", true, "Host only: show everyone a HUD tip when scrap is sold via command.");
			CfgFastDelivery = ((BaseUnityPlugin)this).Config.Bind<bool>("Host", "FastDelivery", true, "Host only: item dropship arrives faster.");
			CfgDeliverySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Host", "DeliverySeconds", 3f, new ConfigDescription("Seconds of landed time before the dropship comes. Vanilla 40 (20 first order).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			NetcodeInit();
			Harmony val = new Harmony("ishred.LethalKuchServer");
			val.PatchAll(typeof(Patches));
			val.PatchAll(typeof(FastDelivery));
			GameObject val2 = new GameObject("LethalKuchServer");
			Object.DontDestroyOnLoad((Object)val2);
			((Object)val2).hideFlags = (HideFlags)61;
			val2.AddComponent<LobbyPanel>();
			Log.LogInfo((object)"LethalKuchServer 1.1.0 loaded. F9 opens the server panel.");
		}

		private static void NetcodeInit()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private static uint Hash(string s)
		{
			return s.Aggregate(17u, (uint c, char ch) => (c * 31) ^ ch);
		}
	}
}
namespace LethalKuchServer.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}