Decompiled source of StarshipDeliveryMod v1.1.3

Laventin.StarshipDeliveryMod.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using StarshipDeliveryMod;
using StarshipDeliveryMod.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[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: AssemblyCompany("Laventin.StarshipDeliveryMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+e922e2ea09793b9e0a8064da04ac3e5fbfce553b")]
[assembly: AssemblyProduct("StarshipDelivery")]
[assembly: AssemblyTitle("Laventin.StarshipDeliveryMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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;
		}
	}
}
public class AxisBillboardSprite : MonoBehaviour
{
	private Camera? mainCamera;

	private Transform? axisRef;

	private void Start()
	{
		mainCamera = StartOfRoundPatch.CurrentCam;
		StartOfRoundPatch.onCameraChange = (Action<Camera>)Delegate.Combine(StartOfRoundPatch.onCameraChange, new Action<Camera>(UpdateCamera));
		axisRef = ((Component)this).transform.parent;
	}

	private void Update()
	{
		//IL_002b: 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_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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: 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)
		//IL_0077: 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)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)mainCamera == (Object)null) && !((Object)(object)axisRef == (Object)null))
		{
			float num = Vector3.Dot(axisRef.up, ((Component)mainCamera).transform.position - ((Component)this).transform.position);
			Vector3 val = ((Component)mainCamera).transform.position - axisRef.up * num;
			((Component)this).transform.LookAt(val, axisRef.up);
		}
	}

	private void UpdateCamera(Camera cam)
	{
		mainCamera = cam;
	}
}
public class RelativeSizeBillboardSprite : MonoBehaviour
{
	public float sizeMultiplier = 0.0015f;

	private Camera? mainCamera;

	private void Start()
	{
		mainCamera = StartOfRoundPatch.CurrentCam;
		StartOfRoundPatch.onCameraChange = (Action<Camera>)Delegate.Combine(StartOfRoundPatch.onCameraChange, new Action<Camera>(UpdateCamera));
	}

	private void Update()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)mainCamera == (Object)null))
		{
			((Component)this).transform.LookAt(((Component)mainCamera).transform);
			float num = Vector3.Distance(((Component)this).transform.position, ((Component)mainCamera).transform.position);
			float num2 = num * sizeMultiplier;
			((Component)this).transform.localScale = new Vector3(num2, num2, num2);
		}
	}

	private void UpdateCamera(Camera cam)
	{
		mainCamera = cam;
	}
}
public class StarshipAnimationEvents : MonoBehaviour
{
	private GameObject landingFxPrefab = null;

	private GameObject liftoffFxPrefab = null;

	private Vector3 spawnPosition;

	private AudioSource? audioSrc;

	private AudioClip? landingSFX;

	private AudioClip? liftoffSFX;

	private AudioClip? sonicBoomSFX;

	public void Start()
	{
		audioSrc = ((Component)this).GetComponent<AudioSource>();
		audioSrc.maxDistance = 2000f;
		landingSFX = StarshipDelivery.Ressources.LoadAsset<AudioClip>("assets/audioclip/starshiplanding.wav");
		liftoffSFX = StarshipDelivery.Ressources.LoadAsset<AudioClip>("assets/audioclip/starshipliftoff.wav");
		sonicBoomSFX = StarshipDelivery.Ressources.LoadAsset<AudioClip>("assets/audioclip/sonicboom.wav");
	}

	public void InitFX(GameObject _landingFxPrefab, GameObject _liftoffFxPrefab, Transform _liftoffPosition)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		landingFxPrefab = _landingFxPrefab;
		liftoffFxPrefab = _liftoffFxPrefab;
		spawnPosition = _liftoffPosition.position + new Vector3(0f, -1.42f, 0f);
	}

	public void Landing()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Object.Instantiate<GameObject>(landingFxPrefab, spawnPosition, Quaternion.Euler(-90f, 0f, 0f));
		Object.Destroy((Object)(object)val, 8f);
	}

	public void Liftoff()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Object.Instantiate<GameObject>(liftoffFxPrefab, spawnPosition, Quaternion.Euler(-90f, 0f, 0f));
		Object.Destroy((Object)(object)val, 8f);
	}

	public void BigCamShake()
	{
		//IL_0030: 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)
		Camera? currentCam = StartOfRoundPatch.CurrentCam;
		Transform val = ((currentCam != null) ? ((Component)currentCam).transform.Find("PlayerAudioListener") : null);
		if (!((Object)(object)val == (Object)null))
		{
			float num = Vector3.Distance(((Component)this).transform.position, val.position);
			if (num < 60f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)3);
			}
		}
	}

	public void LongCamShake()
	{
		//IL_0030: 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)
		Camera? currentCam = StartOfRoundPatch.CurrentCam;
		Transform val = ((currentCam != null) ? ((Component)currentCam).transform.Find("PlayerAudioListener") : null);
		if (!((Object)(object)val == (Object)null))
		{
			float num = Vector3.Distance(((Component)this).transform.position, val.position);
			if (num < 60f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)2);
			}
		}
	}

	private void LandingSFX()
	{
		if ((Object)(object)audioSrc != (Object)null)
		{
			audioSrc.spatialBlend = 1f;
			audioSrc.PlayOneShot(landingSFX);
		}
	}

	private void LiftoffSFX()
	{
		if ((Object)(object)audioSrc != (Object)null)
		{
			audioSrc.spatialBlend = 1f;
			audioSrc.PlayOneShot(liftoffSFX);
		}
	}

	private void SonicBoomSFX()
	{
		if ((Object)(object)audioSrc != (Object)null)
		{
			ConfigEntry<bool>? enableSonicBoom = ConfigSettings.enableSonicBoom;
			if (enableSonicBoom != null && enableSonicBoom.Value)
			{
				audioSrc.spatialBlend = 0.2f;
				audioSrc.PlayOneShot(sonicBoomSFX);
			}
		}
	}
}
namespace StarshipDeliveryMod
{
	internal class CustomPositioningTool : MonoBehaviour
	{
		private bool isToolActive = false;

		private bool isShipPlaced = false;

		private bool isTweakMenuOpen = false;

		private bool isPopupOpen = false;

		private LayerMask layerMask;

		private GameObject? dummyShipPrefab;

		private GameObject? dummyShip = null;

		private Camera? cam = null;

		private PlayerControllerB? playerController;

		private GameObject? canevasPrefab;

		private Transform? canvas;

		private Transform? tweakMenu;

		private Transform? tipsTexts;

		private Transform? choicePopup;

		private Transform? confirmPopup;

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

		private GameObject? lockTip;

		private GameObject? rotateTip;

		private GameObject? tweakOpenTip;

		private GameObject? processTip;

		private Sprite[]? lockIcons;

		private Text? confirmInfosText;

		private InputField? posXField;

		private InputField? posYField;

		private InputField? posZField;

		private InputField? rotXField;

		private InputField? rotYField;

		private InputField? rotZField;

		private static List<string> scenesToExclude = new List<string> { "SampleSceneRelay", "ColdOpen1", "InitScene", "InitSceneLANMode", "InitSceneLaunchOptions", "MainMenu" };

		public LevelDataList? storedLevelDataList = null;

		public InputAction? activateToolAction;

		public InputAction? exitPopupAction;

		public InputAction? lockDummyAction;

		public InputAction? unlockDummyAction;

		public InputAction? rotateAction;

		public InputAction? openTweakMenuAction;

		public InputAction? processAction;

		private void Start()
		{
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			activateToolAction = KeyBindManager.CreateInputAction("ActivateCustomPositionTool", "<Keyboard>/p", "press");
			exitPopupAction = KeyBindManager.CreateInputAction("ExitPopup", "<Keyboard>/escape", "press");
			lockDummyAction = KeyBindManager.CreateInputAction("LockDummy", "<Mouse>/leftButton", "press");
			unlockDummyAction = KeyBindManager.CreateInputAction("UnlockDummy", "<Keyboard>/l", "press");
			rotateAction = KeyBindManager.CreateInputAction("RotateDummy", "<Keyboard>/o", "hold");
			openTweakMenuAction = KeyBindManager.CreateInputAction("OpenTweakMenu", "<Keyboard>/i", "press");
			processAction = KeyBindManager.CreateInputAction("ProcessDummy", "<Keyboard>/k", "press");
			dummyShipPrefab = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/dummyshiptransform.prefab");
			canevasPrefab = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/custompositioningtoolcanvas.prefab");
			cam = StartOfRoundPatch.CurrentCam;
			playerController = StartOfRound.Instance.localPlayerController;
			layerMask = LayerMask.op_Implicit(LayerMask.op_Implicit(layerMask) | 1);
			layerMask = LayerMask.op_Implicit(LayerMask.op_Implicit(layerMask) | 0x100);
			StarshipDelivery.mls.LogInfo((object)">>> Custom Positioning Tool initialized");
		}

		private void Update()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			if (activateToolAction.triggered)
			{
				ActivateTool();
			}
			if (!isToolActive || (Object)(object)cam == (Object)null || (Object)(object)dummyShip == (Object)null)
			{
				return;
			}
			if (isPopupOpen)
			{
				if (exitPopupAction.triggered)
				{
					ExitPopup();
				}
				return;
			}
			if (!isShipPlaced && !isTweakMenuOpen)
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(((Component)cam).transform.position, ((Component)cam).transform.forward);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val, ref val2, 100f, LayerMask.op_Implicit(layerMask)))
				{
					dummyShip.transform.position = ((RaycastHit)(ref val2)).point;
					dummyShip.transform.up = ((RaycastHit)(ref val2)).normal;
				}
			}
			if (lockDummyAction.triggered)
			{
				isShipPlaced = true;
				UpdateUI();
			}
			if (unlockDummyAction.triggered && !isTweakMenuOpen)
			{
				isShipPlaced = false;
				UpdateUI();
			}
			if (rotateAction.IsPressed() && isShipPlaced && !isTweakMenuOpen)
			{
				dummyShip.transform.Rotate(Vector3.up * 100f * Time.deltaTime);
			}
			if (openTweakMenuAction.triggered && isShipPlaced)
			{
				OpenTweakMenu();
				UpdateUI();
			}
			if (processAction.triggered && isShipPlaced && !isTweakMenuOpen)
			{
				isPopupOpen = !isPopupOpen;
				OpenPopup(((Component)choicePopup).gameObject, isPopupOpen);
			}
		}

		private void OpenTweakMenu()
		{
			isTweakMenuOpen = !isTweakMenuOpen;
			if (isTweakMenuOpen)
			{
				InitTweakValues();
				LockPlayerCamera(_lock: true);
			}
			else
			{
				LockPlayerCamera(_lock: false);
			}
		}

		private void ActivateTool()
		{
			//IL_005b: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)dummyShipPrefab == (Object)null || (Object)(object)canevasPrefab == (Object)null)
			{
				return;
			}
			isToolActive = !isToolActive;
			if (isToolActive)
			{
				StarshipDelivery.mls.LogInfo((object)">>> Custom Positioning Tool on");
				dummyShip = Object.Instantiate<GameObject>(dummyShipPrefab, Vector3.zero, Quaternion.identity);
				Transform val = dummyShip.transform.Find("DummyShip/ItemShip");
				float num = val.localScale.x * (ConfigSettings.starshipSize.Value / 100f);
				val.localScale = new Vector3(num, num, num);
				canvas = Object.Instantiate<GameObject>(canevasPrefab, Vector3.zero, Quaternion.identity).transform;
				((Component)canvas).gameObject.AddComponent<CustomPositioningToolEvents>();
				InitUI();
				UpdateUI();
				CustomPositioningToolEvents component = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component.onFieldUpdate = (Action)Delegate.Combine(component.onFieldUpdate, new Action(UpdateTweakValues));
				CustomPositioningToolEvents component2 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component2.onCopyToClipboard = (Action)Delegate.Combine(component2.onCopyToClipboard, new Action(CopyJsonToClipboard));
				CustomPositioningToolEvents component3 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component3.onOverwriteFile = (Action)Delegate.Combine(component3.onOverwriteFile, new Action(CheckForDuplicatesLevelNames));
				CustomPositioningToolEvents component4 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component4.onCancel = (Action)Delegate.Combine(component4.onCancel, new Action(ExitPopup));
				CustomPositioningToolEvents component5 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component5.onConfirm = (Action)Delegate.Combine(component5.onConfirm, new Action(SaveToFile));
				return;
			}
			StarshipDelivery.mls.LogInfo((object)">>> Custom Positioning Tool off");
			isShipPlaced = false;
			isTweakMenuOpen = false;
			isPopupOpen = false;
			LockPlayerCamera(_lock: false);
			allPopups.Clear();
			UpdateUI();
			if ((Object)(object)canvas != (Object)null)
			{
				CustomPositioningToolEvents component6 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component6.onFieldUpdate = (Action)Delegate.Remove(component6.onFieldUpdate, new Action(UpdateTweakValues));
				CustomPositioningToolEvents component7 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component7.onCopyToClipboard = (Action)Delegate.Remove(component7.onCopyToClipboard, new Action(CopyJsonToClipboard));
				CustomPositioningToolEvents component8 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component8.onOverwriteFile = (Action)Delegate.Remove(component8.onOverwriteFile, new Action(CheckForDuplicatesLevelNames));
				CustomPositioningToolEvents component9 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component9.onCancel = (Action)Delegate.Remove(component9.onCancel, new Action(ExitPopup));
				CustomPositioningToolEvents component10 = ((Component)canvas).GetComponent<CustomPositioningToolEvents>();
				component10.onConfirm = (Action)Delegate.Remove(component10.onConfirm, new Action(SaveToFile));
			}
			if ((Object)(object)dummyShip != (Object)null)
			{
				Object.Destroy((Object)(object)dummyShip);
			}
			if ((Object)(object)canvas != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)canvas).gameObject);
			}
		}

		private void InitUI()
		{
			if (!((Object)(object)canvas == (Object)null))
			{
				tweakMenu = canvas.Find("TweakMenu");
				tipsTexts = canvas.Find("TipsTexts");
				choicePopup = canvas.Find("ChoicePopup");
				confirmPopup = canvas.Find("ConfirmPopup");
				((Component)tweakMenu).gameObject.SetActive(true);
				((Component)tipsTexts).gameObject.SetActive(true);
				((Component)choicePopup).gameObject.SetActive(true);
				((Component)confirmPopup).gameObject.SetActive(true);
				allPopups.Add(choicePopup);
				allPopups.Add(confirmPopup);
				lockTip = ((Component)tipsTexts.Find("Lock")).gameObject;
				rotateTip = ((Component)tipsTexts.Find("Rotate")).gameObject;
				tweakOpenTip = ((Component)tipsTexts.Find("TweakOpen")).gameObject;
				processTip = ((Component)tipsTexts.Find("Process")).gameObject;
				lockIcons = (Sprite[]?)(object)new Sprite[2]
				{
					StarshipDelivery.Ressources.LoadAsset<Sprite>("assets/sprite/lockicon.png"),
					StarshipDelivery.Ressources.LoadAsset<Sprite>("assets/sprite/unlockicon.png")
				};
				confirmInfosText = ((Component)confirmPopup.Find("ConfirmText")).GetComponent<Text>();
				posXField = ((Component)tweakMenu.Find("Pos_Layout/PosX_Layout/PosX_InputField")).GetComponent<InputField>();
				posYField = ((Component)tweakMenu.Find("Pos_Layout/PosY_Layout/PosY_InputField")).GetComponent<InputField>();
				posZField = ((Component)tweakMenu.Find("Pos_Layout/PosZ_Layout/PosZ_InputField")).GetComponent<InputField>();
				rotXField = ((Component)tweakMenu.Find("Rot_Layout/RotX_Layout/RotX_InputField")).GetComponent<InputField>();
				rotYField = ((Component)tweakMenu.Find("Rot_Layout/RotY_Layout/RotY_InputField")).GetComponent<InputField>();
				rotZField = ((Component)tweakMenu.Find("Rot_Layout/RotZ_Layout/RotZ_InputField")).GetComponent<InputField>();
				rotateTip.SetActive(false);
				tweakOpenTip.SetActive(false);
				processTip.SetActive(false);
				((Component)tweakMenu).gameObject.SetActive(false);
				((Component)choicePopup).gameObject.SetActive(false);
				((Component)confirmPopup).gameObject.SetActive(false);
			}
		}

		private void UpdateUI()
		{
			if (!isTweakMenuOpen)
			{
				((Component)tipsTexts).gameObject.SetActive(true);
				((Component)tweakMenu).gameObject.SetActive(false);
				if (isShipPlaced)
				{
					((Component)lockTip.transform.Find("Text")).GetComponent<Text>().text = "L";
					((Component)lockTip.transform.Find("KeyImage")).gameObject.SetActive(false);
					((Component)lockTip.transform.Find("Description")).GetComponent<Text>().text = "Unlock";
					((Component)lockTip.transform.Find("Image")).GetComponent<Image>().sprite = lockIcons[0];
					rotateTip.SetActive(true);
					tweakOpenTip.SetActive(true);
					processTip.SetActive(true);
				}
				else
				{
					((Component)lockTip.transform.Find("Text")).GetComponent<Text>().text = "";
					((Component)lockTip.transform.Find("KeyImage")).gameObject.SetActive(true);
					((Component)lockTip.transform.Find("Description")).GetComponent<Text>().text = "Lock";
					((Component)lockTip.transform.Find("Image")).GetComponent<Image>().sprite = lockIcons[1];
					rotateTip.SetActive(false);
					tweakOpenTip.SetActive(false);
					processTip.SetActive(false);
				}
			}
			else
			{
				((Component)tipsTexts).gameObject.SetActive(false);
				((Component)tweakMenu).gameObject.SetActive(true);
			}
		}

		private void InitTweakValues()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0040: 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)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			posXField.text = dummyShip.transform.position.x.ToString();
			posYField.text = dummyShip.transform.position.y.ToString();
			posZField.text = dummyShip.transform.position.z.ToString();
			rotXField.text = dummyShip.transform.eulerAngles.x.ToString();
			rotYField.text = dummyShip.transform.eulerAngles.y.ToString();
			rotZField.text = dummyShip.transform.eulerAngles.z.ToString();
			Debug.Log((object)dummyShip.transform.eulerAngles.x);
			Debug.Log((object)dummyShip.transform.eulerAngles.y);
			Debug.Log((object)dummyShip.transform.eulerAngles.z);
		}

		private void UpdateTweakValues()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			dummyShip.transform.position = new Vector3(GetCorrectFloat(posXField.text), GetCorrectFloat(posYField.text), GetCorrectFloat(posZField.text));
			dummyShip.transform.rotation = Quaternion.Euler(GetCorrectFloat(rotXField.text), GetCorrectFloat(rotYField.text), GetCorrectFloat(rotZField.text));
		}

		private void CopyJsonToClipboard()
		{
			LevelData levelData = GenerateLevelDataForTheDummy();
			string systemCopyBuffer = JsonConvert.SerializeObject((object)levelData, (Formatting)1);
			GUIUtility.systemCopyBuffer = systemCopyBuffer;
			StarshipDelivery.mls.LogInfo((object)">>> Json Snippet copied to Clipboard");
			ExitPopup();
		}

		private string? GetCurrentSceneName()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				if (!scenesToExclude.Contains(((Scene)(ref sceneAt)).name))
				{
					return ((Scene)(ref sceneAt)).name;
				}
			}
			return null;
		}

		private LevelData GenerateLevelDataForTheDummy()
		{
			//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)
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			string currentSceneName = GetCurrentSceneName();
			if (currentSceneName == null)
			{
				throw new InvalidOperationException(">>> Scene Name is not Valid");
			}
			Vector3 position = ((Component)dummyShip.transform.Find("DummyShip")).transform.position;
			Vector3 eulerAngles = ((Component)dummyShip.transform.Find("DummyShip")).transform.eulerAngles;
			Debug.Log((object)position);
			return new LevelData
			{
				levelName = currentSceneName,
				landingPosition = new LandingPosition
				{
					x = position.x,
					y = position.y,
					z = position.z
				},
				landingRotation = new LandingRotation
				{
					x = eulerAngles.x,
					y = eulerAngles.y,
					z = eulerAngles.z
				}
			};
		}

		private void CheckForDuplicatesLevelNames()
		{
			storedLevelDataList = LevelDataManager.GetLevelDataList(StarshipDelivery.LevelDataConfig);
			if (storedLevelDataList == null || storedLevelDataList.levelDatas == null)
			{
				return;
			}
			LevelData levelData = GenerateLevelDataForTheDummy();
			foreach (LevelData levelData2 in storedLevelDataList.levelDatas)
			{
				if (levelData2.levelName == levelData.levelName)
				{
					OpenPopup(((Component)confirmPopup).gameObject, _open: true);
					string text = confirmInfosText.text.Replace("[]", levelData2.levelName);
					confirmInfosText.text = text;
					return;
				}
			}
			SaveToFile();
		}

		private string GenerateJsonFile()
		{
			LevelData levelData = GenerateLevelDataForTheDummy();
			LevelData levelData2 = null;
			foreach (LevelData levelData3 in storedLevelDataList.levelDatas)
			{
				if (levelData3.levelName == levelData.levelName)
				{
					levelData2 = levelData3;
				}
			}
			if (levelData2 != null)
			{
				storedLevelDataList.levelDatas.Remove(levelData2);
			}
			storedLevelDataList.levelDatas.Add(levelData);
			return JsonConvert.SerializeObject((object)storedLevelDataList, (Formatting)1);
		}

		private void SaveToFile()
		{
			string contents = GenerateJsonFile();
			File.WriteAllText(StarshipDelivery.LevelDataConfigPath, contents);
			StarshipDelivery.mls.LogInfo((object)">>> ShipPositionConfig.json overwrited successifully !");
			ExitPopup();
			StarshipDelivery.LevelDataConfig = StarshipDelivery.InitializeShipPositionConfig();
			LevelDataManager.InitializeLevelDatas(StarshipDelivery.LevelDataConfig);
			ItemDropship val = Object.FindObjectOfType<ItemDropship>();
			if ((Object)(object)val == (Object)null)
			{
				StarshipDelivery.mls.LogError((object)"Could not override itemDropShip position. ItemDropShip is null!");
			}
			else
			{
				StarshipDelivery.SetDropShipPosition(val);
			}
		}

		private void OpenPopup(GameObject _popup, bool _open)
		{
			if (!((Object)(object)_popup == (Object)null))
			{
				isPopupOpen = _open;
				_popup.SetActive(_open);
				LockPlayerCamera(_open);
			}
		}

		private void ExitPopup()
		{
			foreach (Transform allPopup in allPopups)
			{
				((Component)allPopup).gameObject.SetActive(false);
			}
			isPopupOpen = false;
			LockPlayerCamera(_lock: false);
		}

		private void LockPlayerCamera(bool _lock)
		{
			if (!((Object)(object)playerController == (Object)null))
			{
				if (_lock)
				{
					playerController.disableLookInput = true;
					Cursor.visible = true;
					Cursor.lockState = (CursorLockMode)0;
				}
				else
				{
					playerController.disableLookInput = false;
					Cursor.visible = false;
					Cursor.lockState = (CursorLockMode)1;
				}
			}
		}

		private float GetCorrectFloat(string _text)
		{
			if (float.TryParse(_text, out var result))
			{
				return result;
			}
			return 0f;
		}
	}
	public class CustomPositioningToolEvents : MonoBehaviour
	{
		public Action? onFieldUpdate;

		public Action? onCopyToClipboard;

		public Action? onOverwriteFile;

		public Action? onCancel;

		public Action? onConfirm;

		public void OnValueAdded(InputField _field)
		{
			if (float.TryParse(_field.text, out var result))
			{
				_field.text = (result + 0.5f).ToString();
				onFieldUpdate?.Invoke();
			}
		}

		public void OnValueSubtracted(InputField _field)
		{
			if (float.TryParse(_field.text, out var result))
			{
				_field.text = (result - 0.5f).ToString();
				onFieldUpdate?.Invoke();
			}
		}

		public void OnValidateField()
		{
			Debug.Log((object)"ValidateField");
			onFieldUpdate?.Invoke();
		}

		public void OnCopyToClipboard()
		{
			onCopyToClipboard?.Invoke();
		}

		public void OnOverwriteFile()
		{
			onOverwriteFile?.Invoke();
		}

		public void OnCancel()
		{
			onCancel?.Invoke();
		}

		public void OnConfirm()
		{
			onConfirm?.Invoke();
		}

		public void ClosePannel(GameObject _panelToClose)
		{
			_panelToClose.SetActive(false);
		}
	}
	internal delegate void SimpleMethodDelegate();
	internal class KeyBindManager
	{
		public static InputActionMap? customActionMap;

		public static void BindKeyToMethod(SimpleMethodDelegate _method, string _inputName, string _key)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			SimpleMethodDelegate _method2 = _method;
			if (customActionMap == null)
			{
				customActionMap = new InputActionMap("CustomStarshipDeliveryMod");
			}
			InputAction val = customActionMap.FindAction(_inputName, false);
			if (val != null)
			{
				Debug.LogWarning((object)("InputAction with the name " + _inputName + " already exists."));
				return;
			}
			customActionMap.Disable();
			InputAction val2 = InputActionSetupExtensions.AddAction(customActionMap, _inputName, (InputActionType)0, (string)null, (string)null, (string)null, (string)null, (string)null);
			InputActionSetupExtensions.AddBinding(val2, "<Keyboard>/" + _key, (string)null, (string)null, (string)null);
			customActionMap.Enable();
			val2.performed += delegate
			{
				_method2();
			};
			StarshipDelivery.mls.LogInfo((object)("New Keybind created, " + _inputName + " bind to " + _key));
		}

		public static InputAction CreateInputAction(string _inputName, string _binding, string _interactions)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (customActionMap == null)
			{
				customActionMap = new InputActionMap("CustomStarshipDeliveryMod");
			}
			InputAction val = customActionMap.FindAction(_inputName, false);
			if (val != null)
			{
				Debug.LogWarning((object)("InputAction with the name " + _inputName + " already exists."));
				return val;
			}
			customActionMap.Disable();
			InputAction val2 = InputActionSetupExtensions.AddAction(customActionMap, _inputName, (InputActionType)0, (string)null, (string)null, (string)null, (string)null, (string)null);
			BindingSyntax val3 = InputActionSetupExtensions.AddBinding(val2, _binding, (string)null, (string)null, (string)null);
			((BindingSyntax)(ref val3)).WithInteraction(_interactions);
			customActionMap.Enable();
			return val2;
		}
	}
	public class LevelDataManager
	{
		public static Dictionary<string, LevelData_Unity> LevelDataDict = new Dictionary<string, LevelData_Unity>();

		public static void InitializeLevelDatas(string _textJSON)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			LevelDataDict.Clear();
			LevelDataList levelDataList = JsonConvert.DeserializeObject<LevelDataList>(_textJSON);
			if (levelDataList == null)
			{
				StarshipDelivery.mls.LogInfo((object)">>> Failed to convert JsonFile into an object");
				return;
			}
			Vector3 landingPosition = default(Vector3);
			Vector3 landingRotation = default(Vector3);
			foreach (LevelData levelData in levelDataList.levelDatas)
			{
				((Vector3)(ref landingPosition))..ctor(levelData.landingPosition.x, levelData.landingPosition.y, levelData.landingPosition.z);
				((Vector3)(ref landingRotation))..ctor(levelData.landingRotation.x, levelData.landingRotation.y, levelData.landingRotation.z);
				LevelData_Unity levelData_Unity = new LevelData_Unity(levelData.levelName, landingPosition, landingRotation);
				LevelDataDict.Add(levelData_Unity.levelName, levelData_Unity);
			}
		}

		public static LevelData_Unity? GetLevelDatas(string _levelName)
		{
			if (LevelDataDict.ContainsKey(_levelName))
			{
				return LevelDataDict[_levelName];
			}
			return null;
		}

		public static LevelDataList? GetLevelDataList(string _textJSON)
		{
			LevelDataList levelDataList = JsonConvert.DeserializeObject<LevelDataList>(_textJSON);
			if (levelDataList == null)
			{
				Debug.Log((object)">>> Failed to convert JsonFile into an object");
				return null;
			}
			return levelDataList;
		}
	}
	public class LandingPosition
	{
		public float x { get; set; }

		public float y { get; set; }

		public float z { get; set; }
	}
	public class LandingRotation
	{
		public float x { get; set; }

		public float y { get; set; }

		public float z { get; set; }
	}
	public class LevelData
	{
		public string? levelName { get; set; }

		public LandingPosition? landingPosition { get; set; }

		public LandingRotation? landingRotation { get; set; }
	}
	public class LevelDataList
	{
		public List<LevelData>? levelDatas { get; set; }
	}
	public class LevelData_Unity
	{
		public string levelName;

		public Vector3 landingPosition;

		public Vector3 landingRotation;

		public LevelData_Unity(string _levelName, Vector3 _landingPosition, Vector3 _landingRotation)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			levelName = _levelName;
			landingPosition = _landingPosition;
			landingRotation = _landingRotation;
		}
	}
	[BepInPlugin("Laventin.StarshipDeliveryMod", "StarshipDelivery", "1.1.1")]
	public class StarshipDelivery : BaseUnityPlugin
	{
		private const string modGUID = "Laventin.StarshipDeliveryMod";

		private const string modName = "StarshipDelivery";

		private const string modVersion = "1.1.1";

		private readonly Harmony harmony = new Harmony("Laventin.StarshipDeliveryMod");

		internal static StarshipDelivery Instance = null;

		internal static ManualLogSource mls = null;

		public static AssetBundle Ressources = null;

		public static string LevelDataConfig = null;

		public static string LevelDataConfigPath = null;

		public static bool AutoReplace = true;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Laventin.StarshipDeliveryMod");
			mls = ((BaseUnityPlugin)this).Logger;
			mls.LogInfo((object)">>> Starship Delivery Mod initialization...");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Ressources = AssetBundle.LoadFromFile(Path.Combine(directoryName, "starshipdelivery"));
			ConfigSettings.BindConfigSettings();
			if ((Object)(object)Ressources == (Object)null)
			{
				throw new InvalidDataException(">>> Failed to load custom assets");
			}
			LevelDataConfig = InitializeShipPositionConfig();
			LevelDataManager.InitializeLevelDatas(LevelDataConfig);
			mls.LogInfo((object)">>> ShipPositionConfig.json loaded");
			harmony.PatchAll(typeof(ItemDropshipPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			mls.LogInfo((object)">>> Starship Delivery Mod initialized successfully !");
		}

		public static void InitStarshipReplacement(ItemDropship _itemDropShip)
		{
			SetDropShipPosition(_itemDropShip);
			StarshipReplacement.ReplaceStarshipModel(((Component)_itemDropShip).gameObject);
		}

		public static void SetDropShipPosition(ItemDropship itemDropShip)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Scene scene = ((Component)itemDropShip).gameObject.scene;
			LevelData_Unity levelDatas = LevelDataManager.GetLevelDatas(((Scene)(ref scene)).name);
			if (levelDatas != null)
			{
				((Component)((Component)itemDropShip).transform.parent).transform.position = levelDatas.landingPosition;
				((Component)((Component)itemDropShip).transform.parent).transform.rotation = Quaternion.Euler(levelDatas.landingRotation);
				ManualLogSource obj = mls;
				string[] obj2 = new string[6] { ">>> current level : ", levelDatas.levelName, " -> changing ship position and rotation to fit Starship size at : ", null, null, null };
				Vector3 val = levelDatas.landingPosition;
				obj2[3] = ((object)(Vector3)(ref val)).ToString();
				obj2[4] = " - ";
				val = levelDatas.landingRotation;
				obj2[5] = ((object)(Vector3)(ref val)).ToString();
				obj.LogInfo((object)string.Concat(obj2));
			}
			else
			{
				mls.LogInfo((object)">>> ShipPositionConfig.json don't contain datas for this level, default ship position will be used");
			}
		}

		public static string InitializeShipPositionConfig()
		{
			string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DefaultShipPositions.json");
			string path2 = (LevelDataConfigPath = Path.Combine(Paths.ConfigPath, "ShipPositionConfig.json"));
			if (!File.Exists(path2))
			{
				mls.LogInfo((object)">>> ShipPositionConfig.json created !");
				string text = File.ReadAllText(path);
				File.WriteAllText(path2, text);
				return text;
			}
			LevelDataList levelDataList = LevelDataManager.GetLevelDataList(File.ReadAllText(path));
			LevelDataList configLevelDataList = LevelDataManager.GetLevelDataList(File.ReadAllText(path2));
			if (levelDataList == null || configLevelDataList == null)
			{
				throw new InvalidDataException(">>> Invalid or missing ship position data");
			}
			List<LevelData> list = levelDataList.levelDatas.Where((LevelData originalData) => !configLevelDataList.levelDatas.Any((LevelData configData) => configData.levelName == originalData.levelName)).ToList();
			if (list.Count() == 0)
			{
				return File.ReadAllText(path2);
			}
			foreach (LevelData item in list)
			{
				mls.LogInfo((object)(">>> Missing data for level " + item.levelName + " added in ShipPositionConfig.json"));
				configLevelDataList.levelDatas.Add(item);
			}
			string text2 = JsonConvert.SerializeObject((object)configLevelDataList, (Formatting)1);
			File.WriteAllText(path2, text2);
			return text2;
		}
	}
	public static class ConfigSettings
	{
		public static ConfigEntry<bool>? enableMusicEffects;

		public static ConfigEntry<bool>? enableSonicBoom;

		public static ConfigEntry<float>? sfxVolume;

		public static ConfigEntry<float>? starshipSize;

		public static ConfigEntry<bool>? customPositioningTool;

		public static void BindConfigSettings()
		{
			enableMusicEffects = ((BaseUnityPlugin)StarshipDelivery.Instance).Config.Bind<bool>("StarshipDeliveryMod Config", "Enable Music Effects", true, "Enable Effects on the Dropship Music such as Pitch Shift, Reverb, Distortion, etc.");
			enableSonicBoom = ((BaseUnityPlugin)StarshipDelivery.Instance).Config.Bind<bool>("StarshipDeliveryMod Config", "Enable Sonic Boom Sound", true, "Enable the sonic boom sound when the Starship is entering the atmosphere");
			sfxVolume = ((BaseUnityPlugin)StarshipDelivery.Instance).Config.Bind<float>("StarshipDeliveryMod Config", "SFX Volume", 100f, "(Range : 0 - 150 %) Change the volume of landing and liftoff SFX");
			sfxVolume.Value = Mathf.Clamp(sfxVolume.Value, 0f, 150f);
			starshipSize = ((BaseUnityPlugin)StarshipDelivery.Instance).Config.Bind<float>("StarshipDeliveryMod Config", "Starship Size", 100f, "(Range : 50 - 150 %) Change the size of the Starship");
			starshipSize.Value = Mathf.Clamp(starshipSize.Value, 50f, 150f);
			customPositioningTool = ((BaseUnityPlugin)StarshipDelivery.Instance).Config.Bind<bool>("StarshipDeliveryMod Debug", "Enable Custom Positioning Tool", false, "A built-in tool that can let you preview and change starship postion and rotation on custom moons, and allow to overwrite ShipPositionConfig.json file to save your changes. To open it in game, press [P]");
		}
	}
	internal class StarshipReplacement : MonoBehaviour
	{
		public static void ReplaceStarshipModel(GameObject _dropShip)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			StarshipDelivery.mls.LogInfo((object)">>> Ship replacement has begun");
			Transform[] componentsInChildren = ((Component)_dropShip.transform.GetChild(0)).GetComponentsInChildren<Transform>();
			Transform[] array = componentsInChildren;
			Renderer val2 = default(Renderer);
			Light val3 = default(Light);
			foreach (Transform val in array)
			{
				if (((Component)val).TryGetComponent<Renderer>(ref val2))
				{
					val2.enabled = false;
				}
				if (((Component)val).TryGetComponent<Light>(ref val3))
				{
					((Behaviour)val3).enabled = false;
				}
			}
			GameObject val4 = Object.Instantiate<GameObject>(StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/starshipmodel.prefab"), Vector3.zero, Quaternion.identity, _dropShip.gameObject.transform);
			((Object)val4).name = "StarshipModel";
			val4.transform.localPosition = new Vector3(0f, 0f, 0f);
			val4.transform.localRotation = Quaternion.Euler(180f, 90f, 90f);
			val4.transform.localScale = new Vector3(2f, 2f, 2f);
			Transform[] array2 = (Transform[])(object)new Transform[_dropShip.transform.Find("ItemSpawnPositions").childCount];
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j] = ((Component)_dropShip.transform.Find("ItemSpawnPositions")).transform.GetChild(j);
			}
			array2[0].localPosition = new Vector3(4.96f, 1.185f, 1.352f);
			array2[1].localPosition = new Vector3(5.14f, 0.509f, 1.352f);
			array2[2].localPosition = new Vector3(5.177f, -0.374f, 1.352f);
			array2[3].localPosition = new Vector3(5.058f, -1.069f, 1.352f);
			((Component)_dropShip.transform.Find("ItemShip/Trigger")).GetComponent<BoxCollider>().size = new Vector3(3f, 3f, 1f);
			((Component)_dropShip.transform.Find("ItemShip/KillTrigger")).GetComponent<BoxCollider>().size = new Vector3(2.8f, 2.8f, 1f);
			GameObject val5 = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/plumetrail.prefab");
			GameObject val6 = Object.Instantiate<GameObject>(val5, _dropShip.transform.position, Quaternion.identity, _dropShip.transform);
			((Object)val6.transform).name = "PlumeTrail";
			val6.transform.localPosition = new Vector3(0f, 0f, -7.1f);
			val6.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
			val6.transform.localScale = new Vector3(1f, 1f, 1f);
			GameObject val7 = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/reentryfx.prefab");
			GameObject val8 = Object.Instantiate<GameObject>(val7, _dropShip.transform.position, Quaternion.identity, _dropShip.transform);
			((Object)val8.transform).name = "ReentryFX";
			val8.transform.localPosition = new Vector3(-10.06f, 0f, 17.75f);
			val8.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
			val8.transform.localScale = new Vector3(20f, 20f, 20f);
			GameObject landingFxPrefab = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/starshiplandingfx.prefab");
			GameObject liftoffFxPrefab = StarshipDelivery.Ressources.LoadAsset<GameObject>("assets/prefabs/starshipliftofffx.prefab");
			Transform transform = ((Component)_dropShip.transform.GetParent().Find("ItemShipLandingPosition")).transform;
			_dropShip.AddComponent<StarshipSoundManager>();
			StarshipAnimationEvents starshipAnimationEvents = _dropShip.AddComponent<StarshipAnimationEvents>();
			starshipAnimationEvents.InitFX(landingFxPrefab, liftoffFxPrefab, transform);
			((Component)_dropShip.transform.Find("ReentryFX/ReentryLens")).gameObject.AddComponent<RelativeSizeBillboardSprite>();
			((Component)_dropShip.transform.Find("ReentryFX/ReentryGlow")).gameObject.AddComponent<RelativeSizeBillboardSprite>();
			((Component)_dropShip.transform.Find("StarshipModel/Engine.000/ThrusterContainer/ThrusterFlame")).gameObject.AddComponent<AxisBillboardSprite>();
			((Component)_dropShip.transform.Find("StarshipModel/Engine.001/ThrusterContainer/ThrusterFlame")).gameObject.AddComponent<AxisBillboardSprite>();
			((Component)_dropShip.transform.Find("StarshipModel/Engine.002/ThrusterContainer/ThrusterFlame")).gameObject.AddComponent<AxisBillboardSprite>();
			_dropShip.GetComponent<NavMeshObstacle>().size = new Vector3(8.5f, 8.5f, 6.46f);
			ReplaceStarshipAnimations(_dropShip);
			float num = _dropShip.transform.localScale.x * (ConfigSettings.starshipSize.Value / 100f);
			_dropShip.transform.localScale = new Vector3(num, num, num);
			StarshipDelivery.mls.LogInfo((object)(">>> Ship size set to " + ConfigSettings.starshipSize.Value + "%"));
			StarshipDelivery.mls.LogInfo((object)">>> Ship replacement is complete");
		}

		private static void ReplaceStarshipAnimations(GameObject _dropShip)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			Animator component = _dropShip.GetComponent<Animator>();
			AnimatorOverrideController val2 = (AnimatorOverrideController)(object)(component.runtimeAnimatorController = (RuntimeAnimatorController)new AnimatorOverrideController(component.runtimeAnimatorController));
			val2["ItemShipIdleGone"] = StarshipDelivery.Ressources.LoadAsset<AnimationClip>("assets/animationclip/itemshipidlegone.anim");
			val2["ItemShipLand"] = StarshipDelivery.Ressources.LoadAsset<AnimationClip>("assets/animationclip/itemshipland.anim");
			val2["ItemShipLeave"] = StarshipDelivery.Ressources.LoadAsset<AnimationClip>("assets/animationclip/itemshipleave.anim");
			val2["ItemShipOpenDoors"] = StarshipDelivery.Ressources.LoadAsset<AnimationClip>("assets/animationclip/itemshipopendoors.anim");
			val2["ItemShipDeliverTruck"] = StarshipDelivery.Ressources.LoadAsset<AnimationClip>("assets/animationclip/itemshipdelivertruck.anim");
			component.Rebind();
		}
	}
	internal class StarshipSoundManager : MonoBehaviour
	{
		private float dropShipVolume = 1f;

		private float musicVolume0 = 1f;

		private float musicVolume1 = 1f;

		private GameObject? musicObj;

		private GameObject? farMusicObj;

		private AudioMixer? audioMixer;

		private void Start()
		{
			StartOfRoundPatch.onEnteringDungeon = (Action<bool>)Delegate.Combine(StartOfRoundPatch.onEnteringDungeon, new Action<bool>(ReduceStarshipVolume));
			musicObj = ((Component)((Component)this).transform.Find("Music")).gameObject;
			farMusicObj = ((Component)musicObj.transform.Find("Music (1)")).gameObject;
			musicVolume0 = musicObj.GetComponent<AudioSource>().volume;
			musicVolume1 = farMusicObj.GetComponent<AudioSource>().volume;
			dropShipVolume *= ConfigSettings.sfxVolume.Value / 100f;
			StarshipDelivery.mls.LogInfo((object)(">>> Ship SFX volume set to " + ConfigSettings.sfxVolume.Value + "% ( " + dropShipVolume + " )"));
			ReduceStarshipVolume(_inDungeon: false);
			ReplaceAudioMixerGroup();
		}

		private void ReduceStarshipVolume(bool _inDungeon)
		{
			AudioSource component = ((Component)this).GetComponent<AudioSource>();
			if (_inDungeon)
			{
				component.volume = dropShipVolume * 0.1f;
				musicObj.GetComponent<AudioSource>().volume = musicVolume0 * 0.3f;
				farMusicObj.GetComponent<AudioSource>().volume = musicVolume1 * 0.3f;
				StarshipDelivery.mls.LogInfo((object)"Volume reduced");
			}
			else
			{
				component.volume = dropShipVolume;
				musicObj.GetComponent<AudioSource>().volume = musicVolume0;
				farMusicObj.GetComponent<AudioSource>().volume = musicVolume1;
				StarshipDelivery.mls.LogInfo((object)"Volume increased");
			}
		}

		private void ReplaceAudioMixerGroup()
		{
			audioMixer = StarshipDelivery.Ressources.LoadAsset<AudioMixer>("assets/audiomixercontroller/starshipmixer.mixer");
			AudioMixerGroup outputAudioMixerGroup = audioMixer.FindMatchingGroups("Master/SFXs")[0];
			AudioMixerGroup outputAudioMixerGroup2 = audioMixer.FindMatchingGroups("Master/DropshipMusic")[0];
			((Component)this).GetComponent<AudioSource>().outputAudioMixerGroup = outputAudioMixerGroup;
			ConfigEntry<bool>? enableMusicEffects = ConfigSettings.enableMusicEffects;
			if (enableMusicEffects != null && enableMusicEffects.Value)
			{
				musicObj.GetComponent<AudioSource>().outputAudioMixerGroup = outputAudioMixerGroup2;
				musicObj.GetComponent<AudioSource>().pitch = 0.82f;
				farMusicObj.GetComponent<AudioSource>().outputAudioMixerGroup = outputAudioMixerGroup2;
				farMusicObj.GetComponent<AudioSource>().pitch = 0.82f;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Laventin.StarshipDeliveryMod";

		public const string PLUGIN_NAME = "StarshipDelivery";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace StarshipDeliveryMod.Patches
{
	[HarmonyPatch(typeof(ItemDropship))]
	internal class ItemDropshipPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(ref ItemDropship __instance)
		{
			if (StarshipDelivery.AutoReplace)
			{
				StarshipDelivery.InitStarshipReplacement(__instance);
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePatch(ref ItemDropship __instance)
		{
			if (__instance.deliveringVehicle && !__instance.untetheredVehicle)
			{
				ItemDropship obj = __instance;
				obj.shipTimer -= Time.deltaTime;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void ConnectClientToPlayerObjectPatch(ref PlayerControllerB __instance)
		{
			ConfigEntry<bool>? customPositioningTool = ConfigSettings.customPositioningTool;
			if (customPositioningTool != null && customPositioningTool.Value && ((NetworkBehaviour)__instance).IsOwner)
			{
				((Component)__instance).gameObject.AddComponent<CustomPositioningTool>();
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		public static Action<Camera>? onCameraChange;

		public static Action<bool>? onEnteringDungeon;

		public static Dictionary<Camera, float> DefaultFarClipDict = new Dictionary<Camera, float>();

		private static List<string> scenesToExclude = new List<string> { "SampleSceneRelay", "ColdOpen1", "InitScene", "InitSceneLANMode", "InitSceneLaunchOptions", "MainMenu" };

		public static bool isALevelLoaded = false;

		public static bool isFarPlaneIncreased = false;

		public static Camera? CurrentCam { get; private set; }

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(ref StartOfRound __instance)
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			CheckIfALevelIsLoaded();
			if (!isALevelLoaded)
			{
				IncreaseCameraFarClip(isIncreased: false);
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePatch(ref StartOfRound __instance)
		{
			//IL_0023: 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)
			if (!isALevelLoaded)
			{
				return;
			}
			Camera? currentCam = CurrentCam;
			if (currentCam != null && ((Component)currentCam).transform.position.y < -100f && isFarPlaneIncreased)
			{
				IncreaseCameraFarClip(isIncreased: false);
				onEnteringDungeon?.Invoke(obj: true);
				return;
			}
			Camera? currentCam2 = CurrentCam;
			if (currentCam2 != null && ((Component)currentCam2).transform.position.y > -100f && !isFarPlaneIncreased)
			{
				IncreaseCameraFarClip(isIncreased: true);
				onEnteringDungeon?.Invoke(obj: false);
			}
		}

		[HarmonyPatch("SwitchCamera")]
		[HarmonyPostfix]
		public static void SwitchCameraPatch(ref StartOfRound __instance, ref Camera ___activeCamera)
		{
			CurrentCam = ___activeCamera;
			onCameraChange?.Invoke(___activeCamera);
			if (!DefaultFarClipDict.ContainsKey(CurrentCam))
			{
				DefaultFarClipDict.Add(CurrentCam, CurrentCam.farClipPlane);
				StarshipDelivery.mls.LogInfo((object)(">>> Camera values stored in this entry : " + ((Object)CurrentCam).name));
			}
		}

		public static void CheckIfALevelIsLoaded()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				if (!scenesToExclude.Contains(((Scene)(ref sceneAt)).name))
				{
					isALevelLoaded = true;
					return;
				}
			}
			isALevelLoaded = false;
		}

		public static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (!scenesToExclude.Contains(((Scene)(ref scene)).name))
			{
				IncreaseCameraFarClip(isIncreased: true);
				isALevelLoaded = true;
			}
		}

		public static void OnSceneUnloaded(Scene scene)
		{
			if (!scenesToExclude.Contains(((Scene)(ref scene)).name))
			{
				IncreaseCameraFarClip(isIncreased: false);
				isALevelLoaded = false;
			}
		}

		public static void IncreaseCameraFarClip(bool isIncreased)
		{
			if (!((Object)(object)CurrentCam == (Object)null))
			{
				isFarPlaneIncreased = isIncreased;
				if (isIncreased)
				{
					CurrentCam.farClipPlane = 5000f;
					StarshipDelivery.mls.LogInfo((object)">>> Camera far plane increased to 5000");
				}
				else if (!DefaultFarClipDict.ContainsKey(CurrentCam))
				{
					CurrentCam.farClipPlane = 400f;
					StarshipDelivery.mls.LogInfo((object)">>> Can't find entry in the Cam dictionnary, Camera far plane reset to default value : 400");
				}
				else
				{
					CurrentCam.farClipPlane = DefaultFarClipDict[CurrentCam];
					StarshipDelivery.mls.LogInfo((object)(">>> Camera far plane reset to the original stored value : " + DefaultFarClipDict[CurrentCam]));
				}
			}
		}
	}
}