Decompiled source of 184Derelict v1.2.0

DerelictMoonPlugin.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DerelictMoonPlugin.NetcodePatcher;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DerelictMoonPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A plugin for the LC Derelict Moon mod")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+8faa2f5e59c480f6c5c80095c065afdd200b746b")]
[assembly: AssemblyProduct("DerelictMoonPlugin")]
[assembly: AssemblyTitle("DerelictMoonPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DerelictMoonPlugin
{
	[BepInPlugin("DerelictMoonPlugin", "DerelictMoonPlugin", "1.2.0")]
	public class DerelictMoonPlugin : BaseUnityPlugin
	{
		public static DerelictMoonPlugin instance;

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private void Awake()
		{
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin DerelictMoonPlugin is loaded!");
			NetcodePatcher();
		}
	}
	public static class ListShuffler
	{
		public static void ShuffleInSync<T1, T2>(IList<T1> list1, IList<T2> list2, Random random)
		{
			if (list1.Count != list2.Count)
			{
				throw new ArgumentException("Lists must have the same length.");
			}
			int count = list1.Count;
			for (int num = count - 1; num > 0; num--)
			{
				int num2 = random.Next(0, num + 1);
				int index = num;
				int index2 = num2;
				T1 value = list1[num2];
				T1 value2 = list1[num];
				list1[index] = value;
				list1[index2] = value2;
				index2 = num;
				index = num2;
				T2 value3 = list2[num2];
				T2 value4 = list2[num];
				list2[index2] = value3;
				list2[index] = value4;
			}
		}
	}
	public class RingPortalStormEvent : NetworkBehaviour
	{
		public List<float> deliveryTimes = new List<float>();

		[SerializeField]
		private float maxStartTimeDelay = 120f;

		[SerializeField]
		private GameObject shipmentsContainer;

		[SerializeField]
		private GameObject shipmentPositionsObject;

		[SerializeField]
		private float maxRotationSpeed = 5f;

		[SerializeField]
		private float rotationSpeedChangeDuration = 10f;

		[SerializeField]
		private float cooldownDuration = 5f;

		[SerializeField]
		private float movementDuration = 30f;

		[SerializeField]
		private AnimationCurve movementCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);

		[SerializeField]
		private float maxTiltAngle = 25f;

		[SerializeField]
		private float tiltChangeDuration = 30f;

		[SerializeField]
		private AudioClip[] startMovingSounds;

		[SerializeField]
		private AudioClip[] ringMovementSounds;

		[SerializeField]
		private AudioClip startSpinningSound;

		[SerializeField]
		private float fadeOutDuration = 1f;

		private AudioSource audioSource;

		private Coroutine soundCoroutine;

		private Animator animator;

		private Vector3 targetRotation;

		private Random seededRandom;

		private List<GameObject> shipments = new List<GameObject>();

		private List<Transform> shipmentPositions = new List<Transform>();

		private float timer;

		private float timeDelay;

		private int shipmentItemNum;

		private bool isPortalOpenAnimationFinished;

		private bool isPortalCloseAnimationFinished;

		private bool isDelivering;

		private NetworkVariable<int> currentShipmentIndex = new NetworkVariable<int>(0, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		private NetworkVariable<int> sharedSeed = new NetworkVariable<int>(StartOfRound.Instance.randomMapSeed, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		private NetworkVariable<bool> shipmentSettledOnServer = new NetworkVariable<bool>(false, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public override void OnNetworkSpawn()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				sharedSeed.Value = StartOfRound.Instance.randomMapSeed + 42;
			}
		}

		private void Start()
		{
			Debug.Log((object)"RingPortalStormEvent: Start method called");
			animator = ((Component)this).GetComponent<Animator>();
			InitializeShipmentPositions();
			InitializeShipments();
			if (shipmentPositions.Count != shipments.Count)
			{
				Debug.LogError((object)"RingPortalStormEvent: Mismatch in number of shipments and delivery locations!");
			}
			audioSource = ((Component)this).GetComponent<AudioSource>();
			if ((Object)(object)audioSource == (Object)null)
			{
				audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			seededRandom = new Random(sharedSeed.Value);
			timeDelay = (float)seededRandom.NextDouble() * maxStartTimeDelay;
			for (int i = 0; i < deliveryTimes.Count; i++)
			{
				deliveryTimes[i] += timeDelay;
			}
			ListShuffler.ShuffleInSync(shipmentPositions, shipments, seededRandom);
		}

		private void Update()
		{
			if (currentShipmentIndex.Value >= deliveryTimes.Count)
			{
				Debug.Log((object)"RingPortalStormEvent: All shipments delivered, disabling station");
				((Behaviour)this).enabled = false;
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				timer += Time.deltaTime;
				if (currentShipmentIndex.Value < deliveryTimes.Count && timer >= deliveryTimes[currentShipmentIndex.Value] && !isDelivering)
				{
					Debug.Log((object)$"RingPortalStormEvent: Starting delivery sequence for shipment {currentShipmentIndex.Value}");
					((MonoBehaviour)this).StartCoroutine(PerformDeliverySequence());
				}
			}
		}

		private void InitializeShipments()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			Debug.Log((object)"RingPortalStormEvent: Initializing shipments");
			if ((Object)(object)shipmentsContainer == (Object)null)
			{
				Debug.LogError((object)"RingPortalStormEvent: Shipments container is not assigned!");
				return;
			}
			foreach (Transform item in shipmentsContainer.transform)
			{
				Transform val = item;
				shipments.Add(((Component)val).gameObject);
				Debug.Log((object)("Added shipment: " + ((Object)val).name));
			}
			Debug.Log((object)$"Total shipments: {shipments.Count}");
		}

		private void InitializeShipmentPositions()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"RingPortalStormEvent: Initializing shipment positions");
			if ((Object)(object)shipmentPositionsObject == (Object)null)
			{
				Debug.LogError((object)"RingPortalStormEvent: ShipmentPositions object is not assigned!");
				return;
			}
			foreach (Transform item in shipmentPositionsObject.transform)
			{
				Transform val = item;
				shipmentPositions.Add(val);
				Debug.Log((object)$"Added shipment position: {((Object)val).name} at {val.position}");
			}
			Debug.Log((object)$"Total shipment positions: {shipmentPositions.Count}");
		}

		[ClientRpc]
		private void PlayMovementSoundsClientRpc()
		{
			//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))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3134008275u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3134008275u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (soundCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(soundCoroutine);
				}
				soundCoroutine = ((MonoBehaviour)this).StartCoroutine(MovementSoundSequence());
			}
		}

		private IEnumerator MovementSoundSequence()
		{
			if (startMovingSounds.Length != 0)
			{
				AudioClip val = startMovingSounds[seededRandom.Next(startMovingSounds.Length)];
				audioSource.PlayOneShot(val);
				yield return (object)new WaitForSeconds(val.length);
			}
			while (true)
			{
				if (ringMovementSounds.Length != 0)
				{
					AudioClip val2 = ringMovementSounds[seededRandom.Next(ringMovementSounds.Length)];
					audioSource.clip = val2;
					audioSource.Play();
					yield return (object)new WaitForSeconds(val2.length);
				}
				else
				{
					yield return null;
				}
			}
		}

		[ClientRpc]
		private void StopMovementSoundsClientRpc()
		{
			//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))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1328377033u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1328377033u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (soundCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(soundCoroutine);
					soundCoroutine = null;
				}
				((MonoBehaviour)this).StartCoroutine(FadeOutSound());
			}
		}

		private IEnumerator FadeOutSound()
		{
			float startVolume = audioSource.volume;
			float deltaVolume = startVolume * Time.deltaTime / fadeOutDuration;
			while (audioSource.volume > 0f)
			{
				AudioSource obj = audioSource;
				obj.volume -= deltaVolume;
				yield return null;
			}
			audioSource.Stop();
			audioSource.volume = startVolume;
		}

		[ClientRpc]
		private void PlayStartSpinningSoundClientRpc()
		{
			//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)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1280932741u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1280932741u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && (Object)(object)startSpinningSound != (Object)null)
				{
					audioSource.clip = startSpinningSound;
					audioSource.Play();
				}
			}
		}

		private IEnumerator PerformDeliverySequence()
		{
			Debug.Log((object)"RingPortalStormEvent: Starting delivery sequence");
			isDelivering = true;
			shipmentSettledOnServer.Value = false;
			animator.SetBool("isPortalActive", false);
			animator.SetBool("isPortalOpenFinished", false);
			animator.SetBool("isPortalCloseFinished", false);
			isPortalOpenAnimationFinished = false;
			isPortalCloseAnimationFinished = false;
			PlayMovementSoundsClientRpc();
			Debug.Log((object)"RingPortalStormEvent: Moving to next position");
			yield return ((MonoBehaviour)this).StartCoroutine(MoveToNextPosition());
			StopMovementSoundsClientRpc();
			yield return (object)new WaitForSeconds(fadeOutDuration + 0.5f);
			PlayStartSpinningSoundClientRpc();
			Debug.Log((object)"RingPortalStormEvent: Increasing rotation speed");
			yield return ((MonoBehaviour)this).StartCoroutine(IncreaseRotationSpeed());
			Debug.Log((object)"RingPortalStormEvent: Activating portal");
			animator.SetBool("isPortalActive", true);
			animator.SetBool("isPortalOpenFinished", false);
			Debug.Log((object)"RingPortalStormEvent: Waiting for portal open animation to finish");
			yield return (object)new WaitUntil((Func<bool>)(() => isPortalOpenAnimationFinished));
			Debug.Log((object)"RingPortalStormEvent: Portal open animation finished");
			yield return ((MonoBehaviour)this).StartCoroutine(DecreaseRotationSpeed());
			yield return (object)new WaitForSeconds(cooldownDuration);
			Debug.Log((object)"RingPortalStormEvent: Spawning and dropping shipment");
			yield return ((MonoBehaviour)this).StartCoroutine(SpawnAndDropShipmentServer());
			yield return (object)new WaitForSeconds(cooldownDuration);
			Debug.Log((object)"RingPortalStormEvent: Closing portal");
			animator.SetBool("isPortalActive", false);
			animator.SetBool("isPortalCloseFinished", false);
			Debug.Log((object)"RingPortalStormEvent: Waiting for portal close animation to finish");
			yield return (object)new WaitUntil((Func<bool>)(() => isPortalCloseAnimationFinished));
			Debug.Log((object)"RingPortalStormEvent: Portal close animation finished");
			Debug.Log((object)$"RingPortalStormEvent: Preparing for next delivery. Current index: {currentShipmentIndex}");
			NetworkVariable<int> obj = currentShipmentIndex;
			int value = obj.Value;
			obj.Value = value + 1;
			yield return ((MonoBehaviour)this).StartCoroutine(SetRandomTilt());
			Debug.Log((object)"RingPortalStormEvent: Delivery sequence completed");
			isDelivering = false;
		}

		private IEnumerator MoveToNextPosition()
		{
			int index = currentShipmentIndex.Value % shipmentPositions.Count;
			Vector3 startPosition = ((Component)this).transform.position;
			Vector3 targetPosition = shipmentPositions[index].position;
			targetPosition.y = startPosition.y;
			Quaternion rotation = ((Component)this).transform.rotation;
			Vector3 startRotation = ((Quaternion)(ref rotation)).eulerAngles;
			Vector3 levelRotation = new Vector3(0f, startRotation.y, 0f);
			float elapsedTime = 0f;
			while (elapsedTime < movementDuration)
			{
				float num = elapsedTime / movementDuration;
				float num2 = movementCurve.Evaluate(num);
				Vector3 position = Vector3.Slerp(startPosition, targetPosition, num2);
				((Component)this).transform.position = position;
				Vector3 val = Vector3.Slerp(startRotation, levelRotation, num2);
				((Component)this).transform.rotation = Quaternion.Euler(val);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			((Component)this).transform.position = targetPosition;
			((Component)this).transform.rotation = Quaternion.Euler(levelRotation);
			Debug.Log((object)"RingPortalStormEvent: Finished moving to next position");
		}

		private IEnumerator IncreaseRotationSpeed()
		{
			Debug.Log((object)"RingPortalStormEvent: Starting to increase rotation speed");
			float elapsedTime = 0f;
			while (elapsedTime < rotationSpeedChangeDuration)
			{
				float num = elapsedTime / rotationSpeedChangeDuration;
				float num2 = Mathf.Lerp(1f, maxRotationSpeed, num);
				float num3 = Mathf.Lerp(0.5f, maxRotationSpeed * 0.75f, num);
				animator.SetFloat("RotSpeedOuter", num2);
				animator.SetFloat("RotSpeedInner", num3);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			Debug.Log((object)"RingPortalStormEvent: Finished increasing rotation speed");
		}

		private IEnumerator DecreaseRotationSpeed()
		{
			Debug.Log((object)"RingPortalStormEvent: Starting to decrease rotation speed");
			float elapsedTime = 0f;
			while (elapsedTime < rotationSpeedChangeDuration * 0.2f)
			{
				float num = elapsedTime / (rotationSpeedChangeDuration * 0.2f);
				float num2 = Mathf.Lerp(maxRotationSpeed, 1f, num);
				float num3 = Mathf.Lerp(maxRotationSpeed * 0.75f, 0.5f, num);
				animator.SetFloat("RotSpeedOuter", num2);
				animator.SetFloat("RotSpeedInner", num3);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
		}

		private IEnumerator SetRandomTilt()
		{
			Debug.Log((object)"RingPortalStormEvent: tilting the station");
			float num = (float)seededRandom.NextDouble() * maxTiltAngle;
			float num2 = (float)seededRandom.NextDouble() * maxTiltAngle;
			RingPortalStormEvent ringPortalStormEvent = this;
			Quaternion rotation = ((Component)this).transform.rotation;
			ringPortalStormEvent.targetRotation = new Vector3(num, ((Quaternion)(ref rotation)).eulerAngles.y, num2);
			float elapsedTime = 0f;
			rotation = ((Component)this).transform.rotation;
			Vector3 startRotation = ((Quaternion)(ref rotation)).eulerAngles;
			while (elapsedTime < tiltChangeDuration)
			{
				float num3 = elapsedTime / tiltChangeDuration;
				Vector3 val = Vector3.Slerp(startRotation, targetRotation, num3);
				((Component)this).transform.rotation = Quaternion.Euler(val);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
		}

		private IEnumerator SpawnAndDropShipmentServer()
		{
			int settledObjectCount = 0;
			Action<GameObject> onObjectSettled = delegate
			{
				settledObjectCount++;
			};
			PrepareShipmentClientRpc();
			ShipmentCollisionHandler.OnObjectSettled += onObjectSettled;
			yield return (object)new WaitUntil((Func<bool>)(() => settledObjectCount == shipmentItemNum - 1));
			Debug.Log((object)"RingPortalStormEvent: Shipment dropped");
			ShipmentCollisionHandler.OnObjectSettled -= onObjectSettled;
			shipmentSettledOnServer.Value = true;
		}

		private IEnumerator SpawnAndDropShipmentClient()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => shipmentSettledOnServer.Value));
			Debug.Log((object)"RingPortalStormEvent: Shipment dropped");
		}

		[ClientRpc]
		private void PrepareShipmentClientRpc()
		{
			//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))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1372235156u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1372235156u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			Debug.Log((object)$"RingPortalStormEvent: Spawning shipment {currentShipmentIndex.Value % shipments.Count}");
			GameObject val3 = shipments[currentShipmentIndex.Value % shipments.Count];
			AudioSource component = val3.GetComponent<AudioSource>();
			AlignShipment(val3);
			Transform[] componentsInChildren = val3.GetComponentsInChildren<Transform>(true);
			Transform[] array = componentsInChildren;
			foreach (Transform val4 in array)
			{
				ShipmentCollisionHandler component2 = ((Component)val4).gameObject.GetComponent<ShipmentCollisionHandler>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = true;
				}
			}
			if (component != null)
			{
				component.Play();
			}
			shipmentItemNum = componentsInChildren.Length;
		}

		private void AlignShipment(GameObject shipment)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0029: 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_0034: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0052: 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_0058: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = shipment.transform;
			Vector3 val = shipmentsContainer.transform.InverseTransformPoint(transform.position);
			Quaternion val2 = Quaternion.Inverse(shipmentsContainer.transform.rotation) * transform.rotation;
			Vector3 position = ((Component)this).transform.TransformPoint(val);
			Quaternion rotation = ((Component)this).transform.rotation * val2;
			transform.position = position;
			transform.rotation = rotation;
		}

		public void OnPortalOpenAnimationFinished()
		{
			Debug.Log((object)"RingPortalStormEvent: Portal open animation finished");
			animator.SetBool("isPortalOpenFinished", true);
			isPortalOpenAnimationFinished = true;
		}

		public void OnPortalCloseAnimationFinished()
		{
			Debug.Log((object)"RingPortalStormEvent: Portal close animation finished");
			animator.SetBool("isPortalCloseFinished", true);
			isPortalCloseAnimationFinished = true;
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_RingPortalStormEvent()
		{
			//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(3134008275u, new RpcReceiveHandler(__rpc_handler_3134008275));
			NetworkManager.__rpc_func_table.Add(1328377033u, new RpcReceiveHandler(__rpc_handler_1328377033));
			NetworkManager.__rpc_func_table.Add(1280932741u, new RpcReceiveHandler(__rpc_handler_1280932741));
			NetworkManager.__rpc_func_table.Add(1372235156u, new RpcReceiveHandler(__rpc_handler_1372235156));
		}

		private static void __rpc_handler_3134008275(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((RingPortalStormEvent)(object)target).PlayMovementSoundsClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1328377033(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((RingPortalStormEvent)(object)target).StopMovementSoundsClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1280932741(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((RingPortalStormEvent)(object)target).PlayStartSpinningSoundClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1372235156(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((RingPortalStormEvent)(object)target).PrepareShipmentClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "RingPortalStormEvent";
		}
	}
	public class ShipmentCollisionHandler : NetworkBehaviour
	{
		[SerializeField]
		private float settlementThreshold = 0.1f;

		[SerializeField]
		private float initialCheckDelay = 0.5f;

		[SerializeField]
		private float checkInterval = 0.1f;

		[SerializeField]
		private float maxTimeToSettle = 15f;

		[SerializeField]
		private float killVelocityThreshold = 1f;

		private bool hasCollided;

		private MeshCollider meshCollider;

		private BoxCollider boxCollider;

		private Rigidbody rb;

		private AudioSource impactSound;

		private NavMeshObstacle navMeshObstacle;

		private ParticleSystem smokeExplosion;

		private NetworkTransform networkTransform;

		public static event Action<GameObject> OnObjectSettled;

		private void Start()
		{
			rb = ((Component)this).GetComponent<Rigidbody>();
			impactSound = ((Component)this).GetComponent<AudioSource>();
			meshCollider = ((Component)this).GetComponent<MeshCollider>();
			boxCollider = ((Component)this).GetComponent<BoxCollider>();
			navMeshObstacle = ((Component)this).GetComponent<NavMeshObstacle>();
			smokeExplosion = ((Component)this).GetComponent<ParticleSystem>();
			networkTransform = ((Component)this).GetComponent<NetworkTransform>();
			MeshRenderer component = ((Component)this).GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).enabled = true;
			}
			if ((Object)(object)networkTransform != (Object)null)
			{
				((Behaviour)networkTransform).enabled = true;
			}
			if ((Object)(object)navMeshObstacle != (Object)null)
			{
				navMeshObstacle.carving = false;
			}
			if ((Object)(object)meshCollider != (Object)null)
			{
				meshCollider.convex = true;
				((Collider)meshCollider).enabled = true;
			}
			if ((Object)(object)boxCollider != (Object)null && ((NetworkBehaviour)this).IsServer)
			{
				((Collider)boxCollider).enabled = true;
				((Collider)boxCollider).isTrigger = true;
			}
			((MonoBehaviour)this).StartCoroutine(WaitAndEnablePhysics(1f));
		}

		private IEnumerator WaitAndEnablePhysics(float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			if ((Object)(object)rb != (Object)null)
			{
				if (((NetworkBehaviour)this).IsServer)
				{
					rb.useGravity = true;
					rb.isKinematic = false;
				}
				else
				{
					rb.useGravity = false;
					rb.isKinematic = true;
				}
			}
			else
			{
				Debug.LogError((object)"ShipmentCollisionHandler: Rigidbody is not assigned!");
			}
		}

		private void OnCollisionEnter(Collision collision)
		{
			//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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			if (!hasCollided && (collision.gameObject.CompareTag("Grass") || collision.gameObject.CompareTag("Aluminum")))
			{
				OnCollisionEnterEffect();
			}
			else
			{
				if (!collision.gameObject.CompareTag("Player"))
				{
					return;
				}
				PlayerControllerB component = collision.gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null)
				{
					Vector3 velocity = rb.velocity;
					if (((Vector3)(ref velocity)).magnitude > killVelocityThreshold)
					{
						NotifyPlayerKillClientRpc(new NetworkBehaviourReference((NetworkBehaviour)(object)component), rb.velocity);
					}
				}
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).gameObject.layer == LayerMask.NameToLayer("Enemies") && ((NetworkBehaviour)this).IsServer)
			{
				EnemyAI component = ((Component)other).gameObject.GetComponent<EnemyAI>();
				if ((Object)(object)component != (Object)null)
				{
					Debug.Log((object)"ShipmentCollisionHandler: Enemy crushed by falling debris");
					component.KillEnemyOnOwnerClient(false);
				}
			}
		}

		private void OnCollisionEnterEffect()
		{
			hasCollided = true;
			PlayEffectsClientRpc();
			((MonoBehaviour)this).StartCoroutine(CheckIfSettled());
		}

		[ClientRpc]
		private void PlayEffectsClientRpc()
		{
			//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))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2851645643u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2851645643u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				AudioSource obj = impactSound;
				if (obj != null)
				{
					obj.Play();
				}
				ParticleSystem obj2 = smokeExplosion;
				if (obj2 != null)
				{
					obj2.Play();
				}
			}
		}

		[ClientRpc]
		private void NotifyPlayerKillClientRpc(NetworkBehaviourReference playerRef, Vector3 killVelocity)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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 val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(972820659u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref playerRef, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref killVelocity);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 972820659u, val, (RpcDelivery)0);
			}
			PlayerControllerB val3 = default(PlayerControllerB);
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !StartOfRound.Instance.shipIsLeaving && ((NetworkBehaviourReference)(ref playerRef)).TryGet<PlayerControllerB>(ref val3, (NetworkManager)null))
			{
				Debug.Log((object)$"ShipmentCollisionHandler: Player {val3.actualClientId} was crushed by falling debris");
				if ((Object)(object)val3 == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					val3.KillPlayer(killVelocity, true, (CauseOfDeath)8, 0, default(Vector3));
				}
			}
		}

		private IEnumerator CheckIfSettled()
		{
			float elapsedTime = initialCheckDelay;
			yield return (object)new WaitForSeconds(initialCheckDelay);
			while (true)
			{
				Vector3 velocity = rb.velocity;
				if (!(((Vector3)(ref velocity)).magnitude > settlementThreshold) || !(elapsedTime < maxTimeToSettle))
				{
					break;
				}
				yield return (object)new WaitForSeconds(checkInterval);
				elapsedTime += checkInterval;
			}
			ShipmentCollisionHandler.OnObjectSettled?.Invoke(((Component)this).gameObject);
			yield return (object)new WaitForSeconds(0.5f);
			SetObjectSettledClientRpc();
			yield return (object)new WaitForSeconds(0.5f);
			Vector3 position = rb.position;
			Quaternion rotation = rb.rotation;
			Vector3 restingPosition = position;
			SyncSettledObjectClientRpc(restingPosition, rotation);
		}

		[ClientRpc]
		private void SetObjectSettledClientRpc()
		{
			//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))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(235186220u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 235186220u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				rb.useGravity = false;
				rb.isKinematic = true;
				if ((Object)(object)meshCollider != (Object)null)
				{
					meshCollider.convex = false;
				}
				if ((Object)(object)boxCollider != (Object)null)
				{
					((Collider)boxCollider).isTrigger = false;
					((Collider)boxCollider).enabled = false;
				}
				if ((Object)(object)navMeshObstacle != (Object)null)
				{
					navMeshObstacle.carving = true;
				}
			}
		}

		[ClientRpc]
		private void SyncSettledObjectClientRpc(Vector3 restingPosition, Quaternion restingRotation)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_0096: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3622365502u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref restingPosition);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref restingRotation);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3622365502u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((NetworkBehaviour)this).IsServer)
				{
					((MonoBehaviour)this).StartCoroutine(SyncSettledObjectCoroutine(restingPosition, restingRotation));
				}
			}
		}

		private IEnumerator SyncSettledObjectCoroutine(Vector3 restingPosition, Quaternion restingRotation)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float interpSyncTime = 3f;
			float currSyncTime = 0f;
			Vector3 startPos = rb.position;
			Quaternion startRot = rb.rotation;
			while (currSyncTime < interpSyncTime)
			{
				rb.position = Vector3.Lerp(startPos, restingPosition, currSyncTime / interpSyncTime);
				rb.rotation = Quaternion.Slerp(startRot, restingRotation, currSyncTime / interpSyncTime);
				currSyncTime += 0.02f;
				yield return (object)new WaitForSeconds(0.02f);
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_ShipmentCollisionHandler()
		{
			//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(2851645643u, new RpcReceiveHandler(__rpc_handler_2851645643));
			NetworkManager.__rpc_func_table.Add(972820659u, new RpcReceiveHandler(__rpc_handler_972820659));
			NetworkManager.__rpc_func_table.Add(235186220u, new RpcReceiveHandler(__rpc_handler_235186220));
			NetworkManager.__rpc_func_table.Add(3622365502u, new RpcReceiveHandler(__rpc_handler_3622365502));
		}

		private static void __rpc_handler_2851645643(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ShipmentCollisionHandler)(object)target).PlayEffectsClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_972820659(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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkBehaviourReference playerRef = default(NetworkBehaviourReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref playerRef, default(ForNetworkSerializable));
				Vector3 killVelocity = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref killVelocity);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ShipmentCollisionHandler)(object)target).NotifyPlayerKillClientRpc(playerRef, killVelocity);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_235186220(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ShipmentCollisionHandler)(object)target).SetObjectSettledClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3622365502(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0043: 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)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 restingPosition = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref restingPosition);
				Quaternion restingRotation = default(Quaternion);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref restingRotation);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ShipmentCollisionHandler)(object)target).SyncSettledObjectClientRpc(restingPosition, restingRotation);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "ShipmentCollisionHandler";
		}
	}
	internal class ToxicFumes : MonoBehaviour
	{
		[SerializeField]
		protected float damageTime = 3f;

		[SerializeField]
		protected float drunknessPower = 1.5f;

		[SerializeField]
		protected int damageAmount = 5;

		protected float damageTimer;

		protected bool isPoisoningLocalPlayer;

		protected virtual void OnTriggerStay(Collider other)
		{
			ApplyToxicEffect(other);
		}

		internal void ApplyToxicEffect(Collider other)
		{
			if (!((Component)other).CompareTag("Player"))
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if (!((Object)(object)component != (Object)null) || !((Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController) || component.isInHangarShipRoom)
			{
				return;
			}
			if (component.beamUpParticle.isPlaying || component.isPlayerDead)
			{
				isPoisoningLocalPlayer = false;
				return;
			}
			isPoisoningLocalPlayer = true;
			damageTimer += Time.deltaTime;
			component.drunknessInertia = Mathf.Clamp(component.drunknessInertia + Time.deltaTime / drunknessPower * component.drunknessSpeed, 0.1f, 10f);
			component.increasingDrunknessThisFrame = true;
			if (damageTimer >= damageTime)
			{
				ApplyDamage(component);
				damageTimer = 0f;
			}
		}

		protected virtual void ApplyDamage(PlayerControllerB playerController)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			playerController.DamagePlayer(damageAmount, true, true, (CauseOfDeath)5, 0, false, default(Vector3));
		}

		internal void OnTriggerExit(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && (Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					isPoisoningLocalPlayer = false;
				}
			}
		}

		protected virtual void Update()
		{
			if (!isPoisoningLocalPlayer && !(damageTimer <= 0f))
			{
				damageTimer = Mathf.Clamp(damageTimer - Time.deltaTime, 0f, damageTime);
			}
		}
	}
	internal class ToxicFogWeather : ToxicFumes
	{
		[SerializeField]
		private float damageProb = 0.25f;

		private Random seededRandom;

		private LocalVolumetricFog toxicVolumetricFog;

		private bool isToxified;

		private void Start()
		{
			seededRandom = new Random(StartOfRound.Instance.randomMapSeed + 42);
			toxicVolumetricFog = ((Component)this).GetComponent<LocalVolumetricFog>();
		}

		protected override void ApplyDamage(PlayerControllerB playerController)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (seededRandom.NextDouble() < (double)damageProb)
			{
				playerController.DamagePlayer(damageAmount, true, true, (CauseOfDeath)5, 0, false, default(Vector3));
			}
		}

		protected override void OnTriggerStay(Collider other)
		{
			if (isToxified)
			{
				ApplyToxicEffect(other);
			}
		}

		private void ToxifyFog()
		{
			((Behaviour)TimeOfDay.Instance.foggyWeather).enabled = false;
			toxicVolumetricFog.parameters.meanFreePath = seededRandom.Next((int)TimeOfDay.Instance.currentWeatherVariable, (int)TimeOfDay.Instance.currentWeatherVariable2);
			((Behaviour)toxicVolumetricFog).enabled = true;
			isToxified = true;
		}

		private void PurifyFog()
		{
			((Behaviour)toxicVolumetricFog).enabled = false;
			isToxified = false;
		}

		protected override void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			if ((int)TimeOfDay.Instance.currentLevelWeather == 3 && !isToxified)
			{
				ToxifyFog();
			}
			else if ((int)TimeOfDay.Instance.currentLevelWeather != 3 && isToxified)
			{
				PurifyFog();
			}
			base.Update();
		}

		private void OnDestroy()
		{
			PurifyFog();
		}
	}
	internal class InteriorHazardSpawner : MonoBehaviour
	{
		public GameObject hazardPrefab;

		public int minNumberOfHazards = 10;

		public int maxNumberOfHazards = 20;

		public float spawnRadius = 20f;

		public float minDistanceBetweenHazards = 5f;

		public float minDistanceFromEntrances = 15f;

		private int numberOfHazards;

		private List<Vector3> spawnedPositions;

		private Vector3[] randomMapObjectsPositions;

		private Vector3[] entrancePositions;

		private Random random;

		private int maxAttempts;

		private void Start()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			if ((Object)(object)hazardPrefab == (Object)null)
			{
				Debug.LogError((object)"InteriorHazardSpawner: Hazard prefab is not assigned!");
			}
			else
			{
				((UnityEvent)StartOfRound.Instance.StartNewRoundEvent).AddListener(new UnityAction(OnNewRound));
			}
		}

		private void OnNewRound()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			InitializeSpawner();
			SpawnHazards();
			((UnityEvent)StartOfRound.Instance.StartNewRoundEvent).RemoveListener(new UnityAction(OnNewRound));
			((Behaviour)this).enabled = false;
		}

		private void InitializeSpawner()
		{
			//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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			random = new Random(StartOfRound.Instance.randomMapSeed + 422);
			numberOfHazards = random.Next(minNumberOfHazards, maxNumberOfHazards + 1);
			spawnedPositions = new List<Vector3>(numberOfHazards);
			maxAttempts = numberOfHazards * 3;
			EntranceTeleport[] array = (from entrance in Object.FindObjectsOfType<EntranceTeleport>()
				where !entrance.isEntranceToBuilding
				select entrance).ToArray();
			SpawnSyncedObject[] array2 = Object.FindObjectsOfType<SpawnSyncedObject>();
			entrancePositions = (Vector3[])(object)new Vector3[array.Length];
			for (int i = 0; i < array.Length; i++)
			{
				entrancePositions[i] = ((Component)array[i]).transform.position;
			}
			randomMapObjectsPositions = (Vector3[])(object)new Vector3[array2.Length];
			for (int j = 0; j < array2.Length; j++)
			{
				randomMapObjectsPositions[j] = ((Component)array2[j]).transform.position;
			}
		}

		private void SpawnHazards()
		{
			//IL_0002: 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_002c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			NavMeshHit navHit = default(NavMeshHit);
			for (int i = 0; i < maxAttempts; i++)
			{
				if (spawnedPositions.Count >= numberOfHazards)
				{
					break;
				}
				int num = random.Next(randomMapObjectsPositions.Length);
				Vector3 objectPosition = randomMapObjectsPositions[num];
				Vector3 validSpawnPosition = GetValidSpawnPosition(objectPosition, ref navHit);
				if (validSpawnPosition != Vector3.zero)
				{
					GameObject val = Object.Instantiate<GameObject>(hazardPrefab, validSpawnPosition, Quaternion.identity);
					val.transform.SetParent(((Component)this).transform);
					spawnedPositions.Add(validSpawnPosition);
				}
			}
			Debug.Log((object)$"InteriorHazardSpawner: Spawned {spawnedPositions.Count} hazards out of {numberOfHazards}");
		}

		private Vector3 GetValidSpawnPosition(Vector3 objectPosition, ref NavMeshHit navHit)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Vector3 randomNavMeshPositionInBoxPredictable = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(objectPosition, spawnRadius, navHit, random, -1);
			if (IsPositionValid(randomNavMeshPositionInBoxPredictable))
			{
				return randomNavMeshPositionInBoxPredictable;
			}
			return Vector3.zero;
		}

		private bool IsPositionValid(Vector3 position)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_005f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			float num = minDistanceBetweenHazards * minDistanceBetweenHazards;
			float num2 = minDistanceFromEntrances * minDistanceFromEntrances;
			Vector3 val;
			for (int i = 0; i < spawnedPositions.Count; i++)
			{
				val = position - spawnedPositions[i];
				if (((Vector3)(ref val)).sqrMagnitude < num)
				{
					return false;
				}
			}
			for (int j = 0; j < entrancePositions.Length; j++)
			{
				val = position - entrancePositions[j];
				if (((Vector3)(ref val)).sqrMagnitude < num2)
				{
					return false;
				}
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DerelictMoonPlugin";

		public const string PLUGIN_NAME = "DerelictMoonPlugin";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace DerelictMoonPlugin.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}