Decompiled source of ProblematicPilotry v1.0.4

windblownleaves.problematicpilotry.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using ProblematicPilotry.Configuration;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("windblownleaves.problematicpilotry")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("ProblematicPilotry")]
[assembly: AssemblyTitle("windblownleaves.problematicpilotry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ProblematicPilotry
{
	[BepInPlugin("windblownleaves.problematicpilotry", "ProblematicPilotry", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ProblematicPilotry : BaseUnityPlugin
	{
		[PublicNetworkVariable]
		public LethalNetworkVariable<Vector3> networkPosition = new LethalNetworkVariable<Vector3>("networkPosition")
		{
			Value = Vector3.zero
		};

		[PublicNetworkVariable]
		public LethalNetworkVariable<Vector3> networkRotation = new LethalNetworkVariable<Vector3>("networkRotation")
		{
			Value = Vector3.zero
		};

		public static ProblematicPilotry Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static ProblematicPilotryConfig BoundConfig { get; private set; }

		private void Awake()
		{
			BoundConfig = new ProblematicPilotryConfig(((BaseUnityPlugin)this).Config);
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"windblownleaves.problematicpilotry v1.0.4 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("windblownleaves.problematicpilotry");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	[Serializable]
	public class SyncedInstance<T>
	{
		[NonSerialized]
		protected static int IntSize = 4;

		internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

		internal static bool IsClient => NetworkManager.Singleton.IsClient;

		internal static bool IsHost => NetworkManager.Singleton.IsHost;

		public static T Default { get; private set; }

		public static T Instance { get; private set; }

		public static bool Synced { get; internal set; }

		protected void InitInstance(T instance)
		{
			Default = instance;
			Instance = instance;
			IntSize = 4;
		}

		internal static void SyncInstance(byte[] data)
		{
			Instance = DeserializeFromBytes(data);
			Synced = true;
		}

		internal static void RevertSync()
		{
			Instance = Default;
			Synced = false;
		}

		public static byte[] SerializeToBytes(T val)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream memoryStream = new MemoryStream();
			try
			{
				binaryFormatter.Serialize(memoryStream, val);
				return memoryStream.ToArray();
			}
			catch (Exception arg)
			{
				ProblematicPilotry.Logger.LogError((object)$"Error serializing instance: {arg}");
				return null;
			}
		}

		public static T DeserializeFromBytes(byte[] data)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream serializationStream = new MemoryStream(data);
			try
			{
				return (T)binaryFormatter.Deserialize(serializationStream);
			}
			catch (Exception arg)
			{
				ProblematicPilotry.Logger.LogError((object)$"Error deserializing instance: {arg}");
				return default(T);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "windblownleaves.problematicpilotry";

		public const string PLUGIN_NAME = "ProblematicPilotry";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace ProblematicPilotry.Configuration
{
	[Serializable]
	public class ProblematicPilotryConfig : SyncedInstance<ProblematicPilotryConfig>
	{
		[HarmonyPatch(typeof(PlayerControllerB))]
		public class PlayerInitPatch
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static HandleNamedMessageDelegate <0>__OnRequestSync;

				public static HandleNamedMessageDelegate <1>__OnReceiveSync;
			}

			internal static ProblematicPilotryConfig BoundConfig { get; private set; }

			[HarmonyPatch("ConnectClientToPlayerObject")]
			[HarmonyPostfix]
			private static void InitializeLocalPlayer()
			{
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Expected O, but got Unknown
				BoundConfig = new ProblematicPilotryConfig(((BaseUnityPlugin)ProblematicPilotry.Instance).Config);
				if (SyncedInstance<ProblematicPilotryConfig>.IsHost)
				{
					CustomMessagingManager messageManager = SyncedInstance<ProblematicPilotryConfig>.MessageManager;
					object obj = <>O.<0>__OnRequestSync;
					if (obj == null)
					{
						HandleNamedMessageDelegate val = OnRequestSync;
						<>O.<0>__OnRequestSync = val;
						obj = (object)val;
					}
					messageManager.RegisterNamedMessageHandler("ModName_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
					SyncedInstance<ProblematicPilotryConfig>.Synced = true;
					return;
				}
				SyncedInstance<ProblematicPilotryConfig>.Synced = false;
				CustomMessagingManager messageManager2 = SyncedInstance<ProblematicPilotryConfig>.MessageManager;
				object obj2 = <>O.<1>__OnReceiveSync;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnReceiveSync;
					<>O.<1>__OnReceiveSync = val2;
					obj2 = (object)val2;
				}
				messageManager2.RegisterNamedMessageHandler("ModName_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
				RequestSync();
			}
		}

		public readonly ConfigEntry<float> chance;

		public readonly ConfigEntry<int> distance;

		public readonly ConfigEntry<bool> enableInCompany;

		public readonly ConfigEntry<bool> canLandOnContainer;

		public readonly ConfigEntry<int> extraSeconds;

		public readonly ConfigEntry<int> leaveAfterSeconds;

		public readonly ConfigEntry<int> heightLimit;

		public readonly ConfigEntry<bool> checkForNavmesh;

		public readonly ConfigEntry<bool> checkForCollisions;

		public readonly ConfigEntry<int> iterations;

		public readonly ConfigEntry<int> navMeshCheckDistance;

		public ProblematicPilotryConfig(ConfigFile cfg)
		{
			InitInstance(this);
			cfg.SaveOnConfigSet = false;
			chance = cfg.Bind<float>("Dropship", "Probability", 1f, "The probability the dropship will land in a different location than normal. Goes from 0.0 (0%) to 1.0 (100%).");
			distance = cfg.Bind<int>("Dropship", "MaximumDistance", 100, "Maximum distance the dropship can land away from its normal position - excessively high values (150+) may make it hard to reach (and also cause lag/failure to find a location).");
			enableInCompany = cfg.Bind<bool>("Dropship", "EnableInCompany", true, "Whether or not the dropship's location will be edited in the company building. Perhaps you'd like the company building as a sort of 'safe spot', whereas purchasing items on planets would be more risky?");
			canLandOnContainer = cfg.Bind<bool>("Dropship", "CanLandOnContainer", false, "Whether or not the dropship can land on containers. This affects only the company building. If you enable this, be aware that you will likely need a jetpack to get to your items.");
			extraSeconds = cfg.Bind<int>("Dropship", "ExtraSeconds", 30, "Extra seconds added to the dropship's stay timer to make up for more difficult-to-reach spots. Setting 30 here will roughly double (30 default + 30 extra) the timer.");
			leaveAfterSeconds = cfg.Bind<int>("Dropship", "LeaveAfterSeconds", 10, "After being opened, how many more seconds should the dropship stay? This helps if you have ExtraSeconds set to a high value, as in the vanilla game, opening the dropship does not affect its timer. Set to -1 to disable this feature.");
			heightLimit = cfg.Bind<int>("Dropship", "HeightLimit", 10, "The maximum height above the vanilla location the dropship should be able to land. This can be used to avoid the dropship landing on mountains or buildings. Setting this too low may cause failure to find a suitable location; set to -1 to disable.");
			checkForNavmesh = cfg.Bind<bool>("Dropship", "CheckForNavmesh", true, "Whether to make sure that the landing location has a navmesh (is part of the playable level). Disabling improves performance, but can land the dropship out of bounds.");
			checkForCollisions = cfg.Bind<bool>("Dropship", "CheckForCollisions", true, "Whether to make sure that the landing location is free of obstacles. Disabling improves performance, but can lead to the dropship landing partially inside objects.");
			iterations = cfg.Bind<int>("Dropship", "MaximumIterations", 100, "The maximum number of times the mod tries to find a valid location before the vanilla location is used. This is to prevent lag/lockup in case the system can't find a valid location.");
			navMeshCheckDistance = cfg.Bind<int>("Dropship", "NavMeshCheckDistance", 2, "The maximum search distance (from the raycast hit point) to scan when trying to find a valid navmesh point. If you don't know what this is, leave it at the default value.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}

		public static void RequestSync()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<ProblematicPilotryConfig>.IsClient)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(SyncedInstance<ProblematicPilotryConfig>.IntSize, (Allocator)2, -1);
			try
			{
				SyncedInstance<ProblematicPilotryConfig>.MessageManager.SendNamedMessage("ModName_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnRequestSync(ulong clientId, FastBufferReader _)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<ProblematicPilotryConfig>.IsHost)
			{
				return;
			}
			ProblematicPilotry.Logger.LogInfo((object)$"Config sync request received from client: {clientId}");
			byte[] array = SyncedInstance<ProblematicPilotryConfig>.SerializeToBytes(SyncedInstance<ProblematicPilotryConfig>.Instance);
			int num = array.Length;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num + SyncedInstance<ProblematicPilotryConfig>.IntSize, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
				SyncedInstance<ProblematicPilotryConfig>.MessageManager.SendNamedMessage("ModName_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3);
			}
			catch (Exception arg)
			{
				ProblematicPilotry.Logger.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnReceiveSync(ulong _, FastBufferReader reader)
		{
			//IL_002d: 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)
			if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<ProblematicPilotryConfig>.IntSize))
			{
				ProblematicPilotry.Logger.LogError((object)"Config sync error: Could not begin reading buffer.");
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				ProblematicPilotry.Logger.LogError((object)"Config sync error: Host could not sync.");
				return;
			}
			byte[] data = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
			SyncedInstance<ProblematicPilotryConfig>.SyncInstance(data);
			ProblematicPilotry.Logger.LogInfo((object)"Successfully synced config with host.");
		}
	}
}
namespace ProblematicPilotry.Patches
{
	[HarmonyPatch(typeof(ItemDropship))]
	public class DropshipLocationPatch
	{
		private static GameObject capsule;

		private static int maxDistance;

		private static float chance;

		private static Vector3 capsulePoint;

		private static Vector3 capsuleRotation;

		private static Vector3 originalCapsulePoint;

		private static Vector3 originalCapsuleRotation;

		private static bool networkEventsRegistered;

		private static LayerMask raycastMask;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		private static void SetupDropshipSystem()
		{
			//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_0038: 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)
			capsule = ((Component)((Component)Object.FindObjectOfType<ItemDropship>()).transform.parent).gameObject;
			originalCapsulePoint = capsule.transform.position;
			originalCapsuleRotation = capsule.transform.localEulerAngles;
			RegisterNetworkEvents();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		private static void UnsubscribeFromEvent()
		{
			UnregisterNetworkEvents();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
		private static void UnsubscribeDisconnect()
		{
			UnregisterNetworkEvents();
		}

		[HarmonyPatch("LandShipOnServer")]
		[HarmonyPrefix]
		private static void MoveItemDropshipPatch()
		{
			maxDistance = SyncedInstance<ProblematicPilotryConfig>.Instance.distance.Value;
			chance = SyncedInstance<ProblematicPilotryConfig>.Instance.chance.Value;
			if (SyncedInstance<ProblematicPilotryConfig>.Instance.enableInCompany.Value || !(StartOfRound.Instance.currentLevel.PlanetName == "71 Gordion"))
			{
				Debug.Log((object)StartOfRound.Instance.randomMapSeed);
				GenerateLocationAndMoveDropship();
			}
		}

		[HarmonyPatch("LandShipClientRpc")]
		[HarmonyPostfix]
		private static void AdjustItemDropshipTimerPatch(ref float ___shipTimer)
		{
			___shipTimer = -SyncedInstance<ProblematicPilotryConfig>.Instance.extraSeconds.Value;
		}

		[HarmonyPatch("OpenShipClientRpc")]
		[HarmonyPrefix]
		private static void SetLeaveTimerPatch(ref float ___shipTimer)
		{
			if (SyncedInstance<ProblematicPilotryConfig>.Instance.leaveAfterSeconds.Value >= 0 && ___shipTimer < 30f - (float)SyncedInstance<ProblematicPilotryConfig>.Instance.leaveAfterSeconds.Value)
			{
				___shipTimer = 30f - (float)SyncedInstance<ProblematicPilotryConfig>.Instance.leaveAfterSeconds.Value;
			}
		}

		private static void RegisterNetworkEvents()
		{
			if (!networkEventsRegistered)
			{
				ProblematicPilotry.Instance.networkPosition.OnValueChanged += UpdatePosition;
				ProblematicPilotry.Instance.networkRotation.OnValueChanged += UpdateRotation;
				networkEventsRegistered = true;
			}
		}

		private static void UnregisterNetworkEvents()
		{
			if (networkEventsRegistered)
			{
				ProblematicPilotry.Instance.networkPosition.OnValueChanged -= UpdatePosition;
				ProblematicPilotry.Instance.networkRotation.OnValueChanged -= UpdateRotation;
				networkEventsRegistered = false;
			}
		}

		private static void GenerateLocationAndMoveDropship()
		{
			//IL_0050: 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_0111: 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)
			if (Random.Range(0f, 1f) > chance)
			{
				UseOriginalLocation();
				return;
			}
			int num = LayerMask.NameToLayer("Triggers");
			int num2 = LayerMask.NameToLayer("NavigationSurface");
			raycastMask = LayerMask.op_Implicit(-1 & ~(1 << num) & ~(1 << num2));
			int num3 = 0;
			bool flag;
			do
			{
				flag = DoLevelRaycast();
				if (flag && SyncedInstance<ProblematicPilotryConfig>.Instance.checkForNavmesh.Value)
				{
					flag = DoNavmeshCast();
				}
				if (flag && SyncedInstance<ProblematicPilotryConfig>.Instance.checkForCollisions.Value)
				{
					flag = DoProbeRaycasts();
				}
				num3++;
				if (num3 >= SyncedInstance<ProblematicPilotryConfig>.Instance.iterations.Value)
				{
					UseOriginalLocation();
					return;
				}
			}
			while (!flag);
			Vector3 value = default(Vector3);
			((Vector3)(ref value))..ctor(capsulePoint.x, capsulePoint.y + 1.6f, capsulePoint.z);
			ProblematicPilotry.Instance.networkPosition.Value = value;
			ProblematicPilotry.Instance.networkRotation.Value = capsuleRotation;
		}

		public static void UpdatePosition(Vector3 position)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			capsule.transform.position = ProblematicPilotry.Instance.networkPosition.Value;
		}

		public static void UpdateRotation(Vector3 rotation)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			capsule.transform.eulerAngles = ProblematicPilotry.Instance.networkRotation.Value;
		}

		private static void UseOriginalLocation()
		{
			//IL_000b: 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)
			ProblematicPilotry.Instance.networkPosition.Value = originalCapsulePoint;
			ProblematicPilotry.Instance.networkRotation.Value = originalCapsuleRotation;
		}

		private static bool DoLevelRaycast()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(-maxDistance, maxDistance);
			float num2 = Random.Range(-maxDistance, maxDistance);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(originalCapsulePoint.x + num, 200f, originalCapsulePoint.z + num2);
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 250f, LayerMask.op_Implicit(raycastMask)))
			{
				if (((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name.ToLower().Contains("tree"))
				{
					return false;
				}
				if (((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name.ToLower().Contains("shipinside"))
				{
					return false;
				}
				if (!SyncedInstance<ProblematicPilotryConfig>.Instance.canLandOnContainer.Value && ((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name.ToLower().Contains("shippingcontainer"))
				{
					return false;
				}
				if (((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name.ToLower().Contains("dividedplane"))
				{
					return false;
				}
				if (((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name.ToLower().Contains("water"))
				{
					return false;
				}
				if (SyncedInstance<ProblematicPilotryConfig>.Instance.heightLimit.Value > -1 && ((RaycastHit)(ref val2)).point.y > originalCapsulePoint.y + (float)SyncedInstance<ProblematicPilotryConfig>.Instance.heightLimit.Value)
				{
					return false;
				}
				capsulePoint = ((RaycastHit)(ref val2)).point;
				capsuleRotation = new Vector3(-90f, originalCapsuleRotation.y, originalCapsuleRotation.z);
				return true;
			}
			return false;
		}

		private static bool DoNavmeshCast()
		{
			//IL_0001: 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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0057: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			NavMeshHit val = default(NavMeshHit);
			if (NavMesh.SamplePosition(capsulePoint, ref val, (float)SyncedInstance<ProblematicPilotryConfig>.Instance.navMeshCheckDistance.Value, -1))
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(((NavMeshHit)(ref val)).position.x, 200f, ((NavMeshHit)(ref val)).position.z);
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(val2, Vector3.down, ref val3, 250f, LayerMask.op_Implicit(raycastMask)))
				{
					if (((Object)((Component)((RaycastHit)(ref val3)).collider).gameObject).name.ToLower().Contains("tree"))
					{
						return false;
					}
					if (((Object)((Component)((RaycastHit)(ref val3)).collider).gameObject).name.ToLower().Contains("shipinside"))
					{
						return false;
					}
					if (!SyncedInstance<ProblematicPilotryConfig>.Instance.canLandOnContainer.Value && ((Object)((Component)((RaycastHit)(ref val3)).collider).gameObject).name.ToLower().Contains("shippingcontainer"))
					{
						return false;
					}
					if (((Object)((Component)((RaycastHit)(ref val3)).collider).gameObject).name.ToLower().Contains("dividedplane"))
					{
						return false;
					}
					if (((Object)((Component)((RaycastHit)(ref val3)).collider).gameObject).name.ToLower().Contains("water") && SyncedInstance<ProblematicPilotryConfig>.Instance.heightLimit.Value > -1 && ((RaycastHit)(ref val3)).point.y > originalCapsulePoint.y + (float)SyncedInstance<ProblematicPilotryConfig>.Instance.heightLimit.Value)
					{
						return false;
					}
					capsulePoint = ((RaycastHit)(ref val3)).point;
					capsuleRotation = new Vector3(-90f, originalCapsuleRotation.y, originalCapsuleRotation.z);
					return true;
				}
				return false;
			}
			return false;
		}

		private static bool DoProbeRaycasts()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			RaycastHit val = default(RaycastHit);
			for (int i = -2; i <= 2; i += 4)
			{
				for (int j = -2; j <= 2; j += 4)
				{
					if (Physics.Raycast(new Vector3(capsulePoint.x + (float)i, 200f, capsulePoint.z + (float)j), Vector3.down, ref val, 250f, LayerMask.op_Implicit(raycastMask)))
					{
						if (capsulePoint.y - ((RaycastHit)(ref val)).point.y < -1f)
						{
							return false;
						}
						continue;
					}
					return false;
				}
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}