Decompiled source of FlyingShips v0.0.4

FlyingShips/FlyingShips.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FlyingShips.Components;
using FlyingShips.Config;
using FlyingShips.Flight;
using FlyingShips.Prefabs;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("My Monsters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Monsters")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FlyingShips
{
	[BepInPlugin("pl.jungle.flyingships", "Flying Ships", "0.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FlyingShipsMod : BaseUnityPlugin
	{
		public const string ModGUID = "pl.jungle.flyingships";

		public const string ModName = "Flying Ships";

		public const string ModVersion = "0.0.4";

		public const string FlightCoreItem = "SurtlingCore";

		public const int FlightCoreAmount = 5;

		public const string AscendButton = "FlyingShips_Ascend";

		public const string DescendButton = "FlyingShips_Descend";

		public const string FlightFuelPrefab = "FlyingShipFuel";

		public const string FlightFuelName = "Esencja Lotu";

		private Harmony _harmony;

		private CustomLocalization _localization;

		private void Awake()
		{
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Expected O, but got Unknown
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Expected O, but got Unknown
			Logger.LogInfo((object)"Flying Ships 0.0.4 loading...");
			FlightConfig.Bind(((BaseUnityPlugin)this).Config);
			_localization = LocalizationManager.Instance.GetLocalization();
			CustomLocalization localization = _localization;
			string text = "Polish";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_esencja_lotu", "Esencja Lotu" },
				{ "item_esencja_lotu_desc", "Magiczne paliwo do latajacych statkow." },
				{ "flyingships_ascend", "Wznieś statek" },
				{ "flyingships_descend", "Opusc statek" },
				{ "fs_controls", "Tryb lotu: PageUp start/gora, PageDown dol/ladowanie, W/S przod/tyl, A/D skret" },
				{ "fs_no_fuel", "Brak paliwa: Esencja Lotu" },
				{ "fs_flight_on", "Tryb lotu wlaczony" },
				{ "fs_flight_off", "Ladowanie zakonczone" },
				{ "fs_fuel_only_inventory", "Paliwo tylko w ekwipunku - w razie potrzeby wyladujesz awaryjnie" },
				{ "fs_no_backup_fuel", "Brak zapasowego paliwa - w razie potrzeby wyladujesz awaryjnie" },
				{ "fs_fuel_burned", "Spalono Esencje Lotu" },
				{ "fs_last_fuel", "To byla ostatnia Esencja Lotu!" },
				{ "fs_fuel_out", "Paliwo sie skonczylo! Statek schodzi awaryjnie..." },
				{ "fs_emergency_landed", "Wyladowano awaryjnie. Uzupelnij Esencje Lotu." },
				{ "fs_ship_req", "Wymaga" },
				{ "fs_ship_controls", "PageUp start/gora, PageDown dol/ladowanie. Wymaga paliwa: Esencja Lotu." },
				{ "fs_ship_storage", "Ma wlasny schowek pokladowy." },
				{ "fs_ship_storage_name", "schowek" }
			});
			CustomLocalization localization2 = _localization;
			text = "English";
			localization2.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_esencja_lotu", "Flight Essence" },
				{ "item_esencja_lotu_desc", "Magic fuel for flying ships." },
				{ "flyingships_ascend", "Ascend ship" },
				{ "flyingships_descend", "Descend ship" },
				{ "fs_controls", "Flight mode: PageUp start/up, PageDown down/land, W/S forward/back, A/D turn" },
				{ "fs_no_fuel", "No fuel: Flight Essence" },
				{ "fs_flight_on", "Flight mode enabled" },
				{ "fs_flight_off", "Landing complete" },
				{ "fs_fuel_only_inventory", "Fuel only in inventory - you'll land in emergency if needed" },
				{ "fs_no_backup_fuel", "No backup fuel - you'll land in emergency if needed" },
				{ "fs_fuel_burned", "Burned Flight Essence" },
				{ "fs_last_fuel", "That was the last Flight Essence!" },
				{ "fs_fuel_out", "Fuel depleted! Ship descending in emergency..." },
				{ "fs_emergency_landed", "Emergency landing. Refill Flight Essence." },
				{ "fs_ship_req", "Requires" },
				{ "fs_ship_controls", "PageUp start/up, PageDown down/land. Requires fuel: Flight Essence." },
				{ "fs_ship_storage", "Has its own onboard storage." },
				{ "fs_ship_storage_name", "storage" }
			});
			InputManager.Instance.AddButton("pl.jungle.flyingships", new ButtonConfig
			{
				Name = "FlyingShips_Ascend",
				Key = (KeyCode)280,
				HintToken = "$flyingships_ascend"
			});
			InputManager.Instance.AddButton("pl.jungle.flyingships", new ButtonConfig
			{
				Name = "FlyingShips_Descend",
				Key = (KeyCode)281,
				HintToken = "$flyingships_descend"
			});
			FlightStatusEffect.Register();
			PrefabManager.OnVanillaPrefabsAvailable += CreateFlyingShips;
			try
			{
				_harmony = new Harmony("pl.jungle.flyingships");
				_harmony.PatchAll();
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Harmony patch failed, ale lodki nadal sprobuja sie dodac: {arg}");
			}
		}

		private void CreateFlyingShips()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= CreateFlyingShips;
			FlightFuelFactory.Create();
			FlyingShipFactory.CreateAll();
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= CreateFlyingShips;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace FlyingShips.Prefabs
{
	public static class FlightFuelFactory
	{
		public static void Create()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			if ((Object)(object)PrefabManager.Instance.GetPrefab("FlyingShipFuel") != (Object)null)
			{
				return;
			}
			ItemConfig val = new ItemConfig
			{
				Name = "$item_esencja_lotu",
				Description = "$item_esencja_lotu_desc",
				Amount = 1,
				CraftingStation = "forge"
			};
			val.AddRequirement("SurtlingCore", 1, 0);
			val.AddRequirement("Iron", 2, 0);
			val.AddRequirement("Resin", 10, 0);
			CustomItem val2 = new CustomItem("FlyingShipFuel", "SurtlingCore", val);
			ItemManager.Instance.AddItem(val2);
			GameObject prefab = PrefabManager.Instance.GetPrefab("FlyingShipFuel");
			if ((Object)(object)prefab != (Object)null)
			{
				ItemDrop component = prefab.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_itemData.m_dropPrefab = prefab;
					component.m_itemData.m_shared.m_name = "$item_esencja_lotu";
					component.m_itemData.m_shared.m_description = "$item_esencja_lotu_desc";
					component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { FuelVisuals.CreateIcon() };
				}
			}
		}
	}
	public static class FlightFuelPrefabSetup
	{
		public static void Setup()
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("FlyingShipFuel");
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogWarning((object)"FlightFuelPrefabSetup: brak prefabu FlyingShipFuel!");
				return;
			}
			ItemDrop component = prefab.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"FlightFuelPrefabSetup: brak ItemDrop na FlyingShipFuel!");
			}
			else
			{
				component.m_itemData.m_dropPrefab = prefab;
			}
		}
	}
	public static class FlyingShipFactory
	{
		private static readonly (string source, string newName, string displayName, int storageWidth, int storageHeight, int flightCoreCost)[] ShipVariants = new(string, string, string, int, int, int)[3]
		{
			("Raft", "FlyingRaft", "Latajaca Tratwa", 3, 2, 5),
			("Karve", "FlyingKarve", "Latajaca Karave", 4, 3, 10),
			("VikingShip", "FlyingVikingShip", "Latajacy Langskip", 6, 4, 15)
		};

		public static void CreateAll()
		{
			(string, string, string, int, int, int)[] shipVariants = ShipVariants;
			for (int i = 0; i < shipVariants.Length; i++)
			{
				(string, string, string, int, int, int) tuple = shipVariants[i];
				try
				{
					Create(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5, tuple.Item6);
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"Blad przy tworzeniu {tuple.Item2} z {tuple.Item1}: {arg}");
				}
			}
		}

		private static void Create(string sourceName, string newName, string displayName, int storageWidth, int storageHeight, int flightCoreCost)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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)
			//IL_013d: Expected O, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Expected O, but got Unknown
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab(sourceName);
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogWarning((object)("Nie znaleziono prefaba: " + sourceName));
			}
			else
			{
				if ((Object)(object)PrefabManager.Instance.GetPrefab(newName) != (Object)null)
				{
					return;
				}
				Piece component = prefab.GetComponent<Piece>();
				if ((Object)(object)component == (Object)null)
				{
					Logger.LogWarning((object)(sourceName + ": brak komponentu Piece"));
					return;
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab(newName, prefab);
				Piece component2 = val.GetComponent<Piece>();
				component2.m_waterPiece = false;
				component2.m_groundOnly = false;
				component2.m_noInWater = false;
				component2.m_name = displayName;
				component2.m_description = (component.m_description ?? string.Empty) + $"\n<color=#8be9fd>$fs_ship_req {flightCoreCost} $item_esencja_lotu</color>" + "\n<color=#8be9fd>$fs_ship_controls</color>\n<color=#8be9fd>$fs_ship_storage</color>";
				List<Requirement> list = new List<Requirement>();
				Requirement[] resources = component.m_resources;
				foreach (Requirement val2 in resources)
				{
					if ((Object)(object)val2.m_resItem != (Object)null)
					{
						list.Add(new Requirement
						{
							m_resItem = val2.m_resItem,
							m_amount = val2.m_amount,
							m_recover = val2.m_recover
						});
					}
				}
				GameObject prefab2 = PrefabManager.Instance.GetPrefab("FlyingShipFuel");
				if ((Object)(object)prefab2 == (Object)null)
				{
					Logger.LogWarning((object)(newName + ": nie znaleziono prefabu FlyingShipFuel, brak wymagania Esencji Lotu."));
				}
				else
				{
					ItemDrop component3 = prefab2.GetComponent<ItemDrop>();
					if ((Object)(object)component3 == (Object)null)
					{
						Logger.LogWarning((object)(newName + ": FlyingShipFuel nie ma komponentu ItemDrop."));
					}
					else
					{
						list.Add(new Requirement
						{
							m_resItem = component3,
							m_amount = flightCoreCost,
							m_recover = true
						});
					}
				}
				component2.m_resources = list.ToArray();
				PieceConfig val3 = new PieceConfig
				{
					Name = displayName,
					Description = component2.m_description,
					PieceTable = "_HammerPieceTable",
					Icon = component.m_icon
				};
				CustomPiece val4 = new CustomPiece(val, false, val3);
				PieceManager.Instance.AddPiece(val4);
				if ((Object)(object)val.GetComponent<FlightController>() == (Object)null)
				{
					val.AddComponent<FlightController>();
				}
			}
		}
	}
	public static class FuelVisuals
	{
		public static readonly Color FlightBlue = new Color(0.15f, 0.75f, 1f, 1f);

		public static readonly Color FlightBlueGlow = new Color(0.05f, 0.65f, 1f, 1f);

		public static void Tint(GameObject fuelPrefab)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = fuelPrefab.transform.Find("FlyingShipFuelBlueVisual");
			if ((Object)(object)val != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			}
			Renderer[] componentsInChildren = fuelPrefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				val2.enabled = false;
			}
			Light[] componentsInChildren2 = fuelPrefab.GetComponentsInChildren<Light>(true);
			foreach (Light val3 in componentsInChildren2)
			{
				((Behaviour)val3).enabled = false;
			}
			ParticleSystem[] componentsInChildren3 = fuelPrefab.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val4 in componentsInChildren3)
			{
				val4.Stop(true, (ParticleSystemStopBehavior)0);
				((Component)val4).gameObject.SetActive(false);
			}
			TrailRenderer[] componentsInChildren4 = fuelPrefab.GetComponentsInChildren<TrailRenderer>(true);
			foreach (TrailRenderer val5 in componentsInChildren4)
			{
				((Renderer)val5).enabled = false;
			}
			GameObject val6 = new GameObject("FlyingShipFuelBlueVisual");
			val6.transform.SetParent(fuelPrefab.transform);
			val6.transform.localPosition = Vector3.zero;
			val6.transform.localRotation = Quaternion.identity;
			val6.transform.localScale = Vector3.one;
			GameObject val7 = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val7).name = "BlueEssenceCube";
			val7.transform.SetParent(val6.transform);
			val7.transform.localPosition = Vector3.zero;
			val7.transform.localRotation = Quaternion.Euler(18f, 35f, 12f);
			val7.transform.localScale = new Vector3(0.42f, 0.42f, 0.42f);
			Collider component = val7.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			Renderer component2 = val7.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				Material material = component2.material;
				SetMaterialColor(material, "_Color", FlightBlue);
				SetMaterialColor(material, "_BaseColor", FlightBlue);
				SetMaterialColor(material, "_EmissionColor", FlightBlueGlow * 4f);
				material.color = FlightBlue;
				component2.material = material;
			}
			Light val8 = val6.AddComponent<Light>();
			val8.type = (LightType)2;
			val8.color = FlightBlueGlow;
			val8.range = 7f;
			val8.intensity = 3.5f;
			ParticleSystem val9 = val6.AddComponent<ParticleSystem>();
			MainModule main = val9.main;
			((MainModule)(ref main)).startColor = new MinMaxGradient(FlightBlueGlow);
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.8f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.25f);
			((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.18f);
			((MainModule)(ref main)).maxParticles = 40;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = true;
			EmissionModule emission = val9.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(18f);
			ShapeModule shape = val9.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.28f;
			ColorOverLifetimeModule colorOverLifetime = val9.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val10 = new Gradient();
			val10.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(FlightBlueGlow, 0f),
				new GradientColorKey(FlightBlue, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.9f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val10);
		}

		private static void SetMaterialColor(Material material, string propertyName, Color color)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (material.HasProperty(propertyName))
			{
				if (propertyName == "_EmissionColor")
				{
					material.EnableKeyword("_EMISSION");
				}
				material.SetColor(propertyName, color);
			}
		}

		public static Sprite CreateIcon()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00b4: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_00f9: 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_01a4: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			((Object)val).name = "FlyingShipFuelBlueIcon";
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.03f, 0.25f, 0.55f, 1f);
			Color flightBlue = FlightBlue;
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.75f, 0.95f, 1f, 1f);
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(31.5f, 31.5f);
			Vector2 val6 = default(Vector2);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					((Vector2)(ref val6))..ctor((float)j, (float)i);
					float num = Mathf.Abs(val6.x - val5.x) + Mathf.Abs(val6.y - val5.y);
					float num2 = Vector2.Distance(val6, val5);
					if (num < 22f)
					{
						float num3 = Mathf.Clamp01(num / 22f);
						Color val7 = Color.Lerp(flightBlue, val3, num3);
						if (j < 30 && i > 35 && num < 13f)
						{
							val7 = Color.Lerp(val7, val4, 0.65f);
						}
						val.SetPixel(j, i, val7);
					}
					else if (num2 < 30f)
					{
						float num4 = Mathf.Clamp01((30f - num2) / 30f) * 0.35f;
						val.SetPixel(j, i, new Color(FlightBlueGlow.r, FlightBlueGlow.g, FlightBlueGlow.b, num4));
					}
					else
					{
						val.SetPixel(j, i, val2);
					}
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
		}
	}
	public static class ShipStorageHelper
	{
		public static void Ensure(GameObject clone, string storageNameToken, int storageWidth, int storageHeight)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			Container[] componentsInChildren = clone.GetComponentsInChildren<Container>(true);
			Container[] array = componentsInChildren;
			foreach (Container val in array)
			{
				Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_chest_wood");
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogWarning((object)"ShipStorageHelper: nie znaleziono piece_chest_wood!");
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(prefab);
			((Object)val2).name = "ShipStorage";
			val2.transform.SetParent(clone.transform);
			val2.transform.localPosition = new Vector3(0f, 0f, 0f);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			ZNetView component = val2.GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			Container component2 = val2.GetComponent<Container>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_name = storageNameToken;
				component2.m_width = storageWidth;
				component2.m_height = storageHeight;
				component2.m_autoDestroyEmpty = false;
			}
			Piece component3 = val2.GetComponent<Piece>();
			if ((Object)(object)component3 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component3);
			}
			WearNTear component4 = val2.GetComponent<WearNTear>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.m_health = 9999f;
				component4.m_noSupportWear = true;
			}
		}
	}
}
namespace FlyingShips.Patches
{
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	public static class FlightFuelDropPatch
	{
		private static void Postfix()
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("FlyingShipFuel");
			if (!((Object)(object)prefab == (Object)null))
			{
				ItemDrop component = prefab.GetComponent<ItemDrop>();
				if (!((Object)(object)component == (Object)null))
				{
					component.m_itemData.m_dropPrefab = prefab;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Ship), "UpdateSail")]
	public static class SailBlockPatch
	{
		private static readonly FieldRef<Ship, float> SailPositionRef = AccessTools.FieldRefAccess<Ship, float>("m_sailPosition");

		private static void Postfix(Ship __instance, float dt)
		{
			FlightController component = ((Component)__instance).GetComponent<FlightController>();
			if (!((Object)(object)component == (Object)null) && component.IsFlying)
			{
				SailPositionRef.Invoke(__instance) = 0f;
			}
		}
	}
	[HarmonyPatch]
	public static class ShipFlightPatch
	{
		private static MethodBase _targetMethod;

		private static readonly FieldInfo SemanField = AccessTools.Field(typeof(Character), "m_seman");

		private static bool _childrenLogged = false;

		private static bool Prepare()
		{
			_targetMethod = AccessTools.Method(typeof(Ship), "CustomFixedUpdate", (Type[])null, (Type[])null) ?? AccessTools.Method(typeof(Ship), "FixedUpdate", (Type[])null, (Type[])null) ?? AccessTools.Method(typeof(Ship), "Update", (Type[])null, (Type[])null);
			if (_targetMethod == null)
			{
				Logger.LogWarning((object)"FlyingShips: nie znaleziono metody Ship do patchowania.");
				return false;
			}
			return true;
		}

		private static MethodBase TargetMethod()
		{
			return _targetMethod;
		}

		private static void Postfix(Ship __instance)
		{
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_090a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			FlightController component = ((Component)__instance).GetComponent<FlightController>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && FlightStatusEffect.Effect != null)
			{
				object? obj = SemanField?.GetValue(localPlayer);
				SEMan val = (SEMan)((obj is SEMan) ? obj : null);
				if (val != null)
				{
					if (component.IsFlying)
					{
						val.AddStatusEffect(FlightStatusEffect.Effect.StatusEffect.NameHash(), true, 1, 1f, (short)(-1));
					}
					else
					{
						val.RemoveStatusEffect(FlightStatusEffect.Effect.StatusEffect.NameHash(), false);
					}
				}
			}
			Player localPlayer2 = Player.m_localPlayer;
			if ((Object)(object)localPlayer2 == (Object)null || (Object)(object)localPlayer2.GetControlledShip() != (Object)(object)__instance)
			{
				FlightZdo.SyncFlightFromZdo(component2, component);
				return;
			}
			ShipBob shipBob = ((Component)__instance).GetComponent<ShipBob>();
			if ((Object)(object)shipBob == (Object)null)
			{
				shipBob = ((Component)__instance).gameObject.AddComponent<ShipBob>();
				Transform val2 = null;
				string[] array = new string[10] { "ship", "Ship", "karve", "Karve", "raft", "Raft", "VikingShip", "viking_ship", "hull", "Hull" };
				string[] array2 = array;
				foreach (string text in array2)
				{
					Transform val3 = ((Component)__instance).transform.Find(text);
					if ((Object)(object)val3 != (Object)null)
					{
						val2 = val3;
						break;
					}
				}
				if ((Object)(object)val2 == (Object)null)
				{
					foreach (Transform item in ((Component)__instance).transform)
					{
						Transform val4 = item;
						if ((Object)(object)((Component)val4).GetComponentInChildren<Renderer>() != (Object)null)
						{
							val2 = val4;
							break;
						}
					}
				}
				if ((Object)(object)val2 == (Object)(object)((Component)__instance).transform)
				{
					val2 = null;
				}
				shipBob.visualRoot = val2;
				if ((Object)(object)val2 == (Object)null)
				{
					Logger.LogWarning((object)"FlyingShips: nie znaleziono wizualnego roota statku, bujanie wylaczone.");
				}
				else
				{
					Logger.LogInfo((object)("FlyingShips: bujanie podpiete do '" + ((Object)val2).name + "'"));
				}
			}
			Rigidbody val5 = ((Component)__instance).GetComponent<Rigidbody>() ?? ((Component)__instance).GetComponentInChildren<Rigidbody>();
			if ((Object)(object)val5 == (Object)null)
			{
				return;
			}
			if (!component.HasShownControls && (Object)(object)MessageHud.instance != (Object)null)
			{
				component.HasShownControls = true;
				MessageHud.instance.ShowMessage((MessageType)2, "$fs_controls", 0, (Sprite)null, false, true);
			}
			if ((Object)(object)component2 != (Object)null && !component2.IsOwner())
			{
				component2.ClaimOwnership();
			}
			bool flag = Input.GetKey((KeyCode)280) || (ZInput.instance != null && ZInput.GetButton("FlyingShips_Ascend"));
			bool flag2 = flag && !component.AscendWasDown;
			component.AscendWasDown = flag;
			bool flag3 = Input.GetKey((KeyCode)281) || (ZInput.instance != null && ZInput.GetButton("FlyingShips_Descend"));
			bool flag4 = Input.GetKey((KeyCode)119) || (ZInput.instance != null && ZInput.GetButton("Forward"));
			bool flag5 = Input.GetKey((KeyCode)115) || (ZInput.instance != null && ZInput.GetButton("Backward"));
			bool flag6 = Input.GetKey((KeyCode)97) || (ZInput.instance != null && ZInput.GetButton("Left"));
			bool flag7 = Input.GetKey((KeyCode)100) || (ZInput.instance != null && ZInput.GetButton("Right"));
			float num = 0f;
			if (flag)
			{
				num += 1f;
			}
			if (flag3)
			{
				num -= 1f;
			}
			float num2 = 0f;
			if (flag4)
			{
				num2 += 1f;
			}
			if (flag5)
			{
				num2 -= 1f;
			}
			float num3 = 0f;
			if (flag6)
			{
				num3 -= 1f;
			}
			if (flag7)
			{
				num3 += 1f;
			}
			float num4 = ((Component)__instance).transform.position.y - 1000f;
			if ((Object)(object)ZoneSystem.instance != (Object)null)
			{
				num4 = ZoneSystem.instance.GetGroundHeight(((Component)__instance).transform.position);
			}
			float num5 = ((Component)__instance).transform.position.y - num4;
			bool flag8 = num5 < 3f;
			if (!component.IsFlying)
			{
				val5.useGravity = true;
				FlightZdo.SetFlightState(component2, component, isFlying: false, 0f, engineOn: false);
				if (!flag2 || component.ForcedDescent)
				{
					return;
				}
				if (!FlightFuel.HasFuel(__instance, localPlayer2))
				{
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, "$fs_no_fuel", 0, (Sprite)null, false, true);
					}
					return;
				}
				component.IsFlying = true;
				component.FuelTimer = 0f;
				FlightZdo.SetFlightState(component2, component, isFlying: true, 0f, engineOn: true);
				component.CurrentForwardSpeed = 0f;
				component.CurrentVerticalSpeed = 0f;
				component.LastForwardSpeed = 0f;
				component.CurrentBank = 0f;
				component.CurrentPitch = 0f;
				component.ForcedDescent = false;
				component.HasWarnedLowFuel = false;
				MessageHud instance2 = MessageHud.instance;
				if (instance2 != null)
				{
					instance2.ShowMessage((MessageType)2, "$fs_flight_on", 0, (Sprite)null, false, true);
				}
				Inventory shipInventory = FlightFuel.GetShipInventory(__instance);
				bool flag9 = FlightFuel.InventoryHasFlightFuel(shipInventory);
				bool flag10 = ((Humanoid)localPlayer2).GetInventory() != null && FlightFuel.InventoryHasFlightFuel(((Humanoid)localPlayer2).GetInventory());
				if (!flag9)
				{
					if (flag10)
					{
						MessageHud instance3 = MessageHud.instance;
						if (instance3 != null)
						{
							instance3.ShowMessage((MessageType)2, "$fs_fuel_only_inventory", 0, (Sprite)null, false, true);
						}
					}
					else
					{
						MessageHud instance4 = MessageHud.instance;
						if (instance4 != null)
						{
							instance4.ShowMessage((MessageType)2, "$fs_no_backup_fuel", 0, (Sprite)null, false, true);
						}
					}
				}
			}
			if (component.IsFlying && flag3 && flag8)
			{
				val5.useGravity = true;
				component.CurrentForwardSpeed = 0f;
				component.CurrentVerticalSpeed = 0f;
				component.LastForwardSpeed = 0f;
				component.CurrentBank = 0f;
				component.CurrentPitch = 0f;
				FlightZdo.SetFlightState(component2, component, isFlying: false, 0f, engineOn: false);
				MessageHud instance5 = MessageHud.instance;
				if (instance5 != null)
				{
					instance5.ShowMessage((MessageType)2, "$fs_flight_off", 0, (Sprite)null, false, true);
				}
				return;
			}
			if (component.IsFlying)
			{
				component.FuelTimer += Time.fixedDeltaTime;
				float num6 = 60f / Mathf.Max(0.1f, FlightConfig.FuelPerMinute.Value);
				if (component.FuelTimer >= num6)
				{
					component.FuelTimer = 0f;
					FlightZdo.SetFuelTimer(component2, component, 0f);
					if (FlightFuel.ConsumeFuel(__instance, localPlayer2))
					{
						MessageHud instance6 = MessageHud.instance;
						if (instance6 != null)
						{
							instance6.ShowMessage((MessageType)1, "$fs_fuel_burned", 0, (Sprite)null, false, true);
						}
						Inventory shipInventory2 = FlightFuel.GetShipInventory(__instance);
						if (!FlightFuel.InventoryHasFlightFuel(shipInventory2) && (((Humanoid)localPlayer2).GetInventory() == null || !FlightFuel.InventoryHasFlightFuel(((Humanoid)localPlayer2).GetInventory())) && !component.HasWarnedLowFuel)
						{
							component.HasWarnedLowFuel = true;
							MessageHud instance7 = MessageHud.instance;
							if (instance7 != null)
							{
								instance7.ShowMessage((MessageType)2, "$fs_last_fuel", 0, (Sprite)null, false, true);
							}
						}
						FlightZdo.SetEngineOn(component2, component, engineOn: true);
					}
					else if (!component.ForcedDescent)
					{
						component.ForcedDescent = true;
						MessageHud instance8 = MessageHud.instance;
						if (instance8 != null)
						{
							instance8.ShowMessage((MessageType)2, "$fs_fuel_out", 0, (Sprite)null, false, true);
						}
						FlightZdo.SetEngineOn(component2, component, engineOn: false);
					}
				}
			}
			FlightZdo.SetFuelTimer(component2, component, component.FuelTimer);
			val5.useGravity = false;
			val5.isKinematic = false;
			FlightInput input = new FlightInput
			{
				Vertical = num,
				Move = num2,
				Turn = num3,
				GroundHeight = num4,
				HeightAboveGround = num5
			};
			FlightPhysics.Apply(__instance, val5, component, input, component2);
			if ((Object)(object)shipBob != (Object)null)
			{
				bool flag11 = Mathf.Abs(num2) < 0.01f && Mathf.Abs(num3) < 0.01f && Mathf.Abs(num) < 0.01f;
				shipBob.shouldBob = component.IsFlying && flag11;
				float num7 = ((Component)__instance).transform.position.y - (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetGroundHeight(((Component)__instance).transform.position) : 0f);
				shipBob.ampPos = Mathf.Lerp(0.08f, 0.25f, Mathf.InverseLerp(20f, 100f, num7));
			}
			Transform val6 = ((Component)__instance).transform.Find("ControlGui");
			if ((Object)(object)val6 != (Object)null)
			{
				((Component)val6).gameObject.SetActive(!component.IsFlying);
			}
			val5.WakeUp();
		}
	}
}
namespace FlyingShips.Flight
{
	public static class FlightFuel
	{
		public static bool ConsumeFuel(Ship ship, Player player)
		{
			Inventory shipInventory = GetShipInventory(ship);
			if (TryConsumeOneFuelFromInventory(shipInventory))
			{
				return true;
			}
			Inventory sourceInventory = (((Object)(object)player != (Object)null) ? ((Humanoid)player).GetInventory() : null);
			if (TryConsumeOneFuelFromInventory(sourceInventory))
			{
				return true;
			}
			return false;
		}

		public static bool HasFuel(Ship ship, Player player)
		{
			Inventory shipInventory = GetShipInventory(ship);
			if (InventoryHasFlightFuel(shipInventory))
			{
				return true;
			}
			Inventory sourceInventory = (((Object)(object)player != (Object)null) ? ((Humanoid)player).GetInventory() : null);
			return InventoryHasFlightFuel(sourceInventory);
		}

		public static int CountFuel(Inventory inv)
		{
			if (inv == null)
			{
				return 0;
			}
			int num = 0;
			foreach (ItemData allItem in inv.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "$item_esencja_lotu")
				{
					num += allItem.m_stack;
				}
			}
			return num;
		}

		public static bool InventoryHasFlightFuel(Inventory sourceInventory)
		{
			if (sourceInventory == null)
			{
				return false;
			}
			List<ItemData> allItems = sourceInventory.GetAllItems();
			foreach (ItemData item in allItems)
			{
				if (IsFlightFuel(item))
				{
					return true;
				}
			}
			return false;
		}

		private static bool TryConsumeOneFuelFromInventory(Inventory sourceInventory)
		{
			if (sourceInventory == null)
			{
				return false;
			}
			foreach (ItemData item in sourceInventory.GetAllItems().ToList())
			{
				if (!IsFlightFuel(item))
				{
					continue;
				}
				sourceInventory.RemoveItem(item, 1);
				return true;
			}
			return false;
		}

		private static bool IsFlightFuel(ItemData item)
		{
			if (item == null)
			{
				return false;
			}
			if (item.m_shared == null)
			{
				return false;
			}
			return item.m_shared.m_name == "$item_esencja_lotu";
		}

		public static Inventory GetShipInventory(Ship ship)
		{
			if ((Object)(object)ship == (Object)null)
			{
				return null;
			}
			Container val = ((Component)ship).GetComponent<Container>() ?? ((Component)ship).GetComponentInChildren<Container>();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return val.GetInventory();
		}
	}
	public struct FlightInput
	{
		public float Vertical;

		public float Move;

		public float Turn;

		public float GroundHeight;

		public float HeightAboveGround;
	}
	public static class FlightPhysics
	{
		public static void Apply(Ship ship, Rigidbody body, FlightController flight, FlightInput input, ZNetView znv)
		{
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: 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_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			float fixedDeltaTime = Time.fixedDeltaTime;
			float num = input.Vertical;
			float move = input.Move;
			float num2 = input.Turn;
			float heightAboveGround = input.HeightAboveGround;
			if (flight.ForcedDescent)
			{
				num = -1f;
				num2 *= 0.6f;
				if (heightAboveGround < 3f)
				{
					body.useGravity = true;
					flight.ForcedDescent = false;
					flight.CurrentForwardSpeed = 0f;
					flight.CurrentVerticalSpeed = 0f;
					flight.LastForwardSpeed = 0f;
					flight.CurrentBank = 0f;
					flight.CurrentPitch = 0f;
					FlightZdo.SetFlightState(znv, flight, isFlying: false, 0f, engineOn: false);
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, "$fs_emergency_landed", 0, (Sprite)null, false, true);
					}
					return;
				}
				flight.CurrentVerticalSpeed = Mathf.MoveTowards(flight.CurrentVerticalSpeed, 0f - FlightConfig.EmergencyDescentSpeed.Value, FlightConfig.AccelVertical.Value * fixedDeltaTime);
				flight.CurrentForwardSpeed = Mathf.MoveTowards(flight.CurrentForwardSpeed, 0f, FlightConfig.DecelForward.Value * fixedDeltaTime);
			}
			float num3 = move * FlightConfig.ForwardSpeed.Value;
			if (Mathf.Abs(num3) > 0.01f)
			{
				flight.CurrentForwardSpeed = Mathf.MoveTowards(flight.CurrentForwardSpeed, num3, FlightConfig.AccelForward.Value * fixedDeltaTime);
			}
			else
			{
				flight.CurrentForwardSpeed = Mathf.MoveTowards(flight.CurrentForwardSpeed, 0f, FlightConfig.DecelForward.Value * fixedDeltaTime);
			}
			if (!flight.ForcedDescent)
			{
				if (num != 0f)
				{
					float num4 = num * FlightConfig.VerticalSpeed.Value;
					flight.CurrentVerticalSpeed = Mathf.MoveTowards(flight.CurrentVerticalSpeed, num4, FlightConfig.AccelVertical.Value * fixedDeltaTime);
				}
				else
				{
					flight.CurrentVerticalSpeed = Mathf.MoveTowards(flight.CurrentVerticalSpeed, 0f, FlightConfig.DecelVertical.Value * fixedDeltaTime);
				}
			}
			float num5 = ((Component)ship).transform.position.y - input.GroundHeight;
			if (num5 >= FlightConfig.MaxFlightHeight.Value)
			{
				float num6 = num5 - FlightConfig.MaxFlightHeight.Value;
				flight.CurrentVerticalSpeed = Mathf.Min(flight.CurrentVerticalSpeed, (0f - num6) * 2f);
			}
			Vector3 forward = ((Component)ship).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3 linearVelocity = body.linearVelocity;
			Vector3 val = forward * flight.CurrentForwardSpeed;
			linearVelocity.x = val.x;
			linearVelocity.z = val.z;
			linearVelocity.y = flight.CurrentVerticalSpeed;
			body.linearVelocity = linearVelocity;
			Vector3 angularVelocity = body.angularVelocity;
			float num7 = num2 * FlightConfig.TurnSpeed.Value;
			angularVelocity.y = Mathf.MoveTowards(angularVelocity.y, num7, FlightConfig.TurnSpeed.Value * 4f * fixedDeltaTime);
			angularVelocity.x *= 0.1f;
			angularVelocity.z *= 0.1f;
			body.angularVelocity = angularVelocity;
			float num8 = (0f - num2) * FlightConfig.MaxBank.Value;
			float num9 = (flight.CurrentForwardSpeed - flight.LastForwardSpeed) / Mathf.Max(fixedDeltaTime, 0.0001f);
			flight.LastForwardSpeed = flight.CurrentForwardSpeed;
			float num10 = (0f - num9) * FlightConfig.PitchFromAccel.Value;
			num10 = Mathf.Clamp(num10, -10f, 10f);
			flight.CurrentBank = Mathf.Lerp(flight.CurrentBank, num8, fixedDeltaTime * 3f);
			flight.CurrentPitch = Mathf.Lerp(flight.CurrentPitch, num10, fixedDeltaTime * 3f);
			Vector3 eulerAngles = ((Component)ship).transform.eulerAngles;
			Quaternion val2 = Quaternion.Euler(flight.CurrentPitch, eulerAngles.y, flight.CurrentBank);
			((Component)ship).transform.rotation = Quaternion.Slerp(((Component)ship).transform.rotation, val2, fixedDeltaTime * FlightConfig.LevelStabilization.Value);
		}
	}
	public static class FlightStatusEffect
	{
		public const string EffectName = "FlyingShipEsencja";

		private static int _lastCount = -1;

		public static CustomStatusEffect Effect { get; private set; }

		public static void Register()
		{
			//IL_0036: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			StatusEffect val = ScriptableObject.CreateInstance<StatusEffect>();
			((Object)val).name = "FlyingShipEsencja";
			val.m_ttl = 0f;
			val.m_name = "Esencja Lotu";
			val.m_icon = FuelVisuals.CreateIcon();
			val.m_startMessageType = (MessageType)1;
			val.m_stopMessageType = (MessageType)1;
			Effect = new CustomStatusEffect(val, false);
			ItemManager.Instance.AddStatusEffect(Effect);
		}

		public static void UpdateName(int fuelCount)
		{
			if (Effect != null && !((Object)(object)Effect.StatusEffect == (Object)null) && _lastCount != fuelCount)
			{
				_lastCount = fuelCount;
				Effect.StatusEffect.m_name = $"Esencja Lotu: {fuelCount}";
			}
		}
	}
	public static class FlightZdo
	{
		public const string ZdoFlyingKey = "fs_flying";

		public const string ZdoEngineOnKey = "fs_engineOn";

		public const string ZdoFuelTimerKey = "fs_fuel";

		public const string ZdoForcedDescentKey = "fs_forcedDescent";

		public static void SyncFlightFromZdo(ZNetView znv, FlightController flight)
		{
			if (!((Object)(object)flight == (Object)null))
			{
				ZDO val = (((Object)(object)znv != (Object)null) ? znv.GetZDO() : null);
				if (val == null)
				{
					flight.SetGlow(flight.IsFlying);
					return;
				}
				flight.FuelTimer = val.GetFloat("fs_fuel", 0f);
				flight.ForcedDescent = val.GetBool("fs_forcedDescent", false);
				bool glow = val.GetBool("fs_engineOn", flight.IsFlying);
				flight.SetGlow(glow);
			}
		}

		public static void SetFlightState(ZNetView znv, FlightController flight, bool isFlying, float fuelTimer, bool engineOn)
		{
			if ((Object)(object)flight != (Object)null)
			{
				flight.IsFlying = isFlying;
				flight.FuelTimer = fuelTimer;
				flight.SetGlow(engineOn);
			}
			ZDO val = (((Object)(object)znv != (Object)null) ? znv.GetZDO() : null);
			if (val != null)
			{
				val.Set("fs_flying", isFlying);
				val.Set("fs_fuel", fuelTimer);
				val.Set("fs_engineOn", engineOn);
				val.Set("fs_forcedDescent", (Object)(object)flight != (Object)null && flight.ForcedDescent);
			}
		}

		public static void SetFuelTimer(ZNetView znv, FlightController flight, float fuelTimer)
		{
			if ((Object)(object)flight != (Object)null)
			{
				flight.FuelTimer = fuelTimer;
			}
			ZDO val = (((Object)(object)znv != (Object)null) ? znv.GetZDO() : null);
			if (val != null)
			{
				val.Set("fs_fuel", fuelTimer);
			}
		}

		public static void SetEngineOn(ZNetView znv, FlightController flight, bool engineOn)
		{
			if ((Object)(object)flight != (Object)null)
			{
				flight.SetGlow(engineOn);
			}
			ZDO val = (((Object)(object)znv != (Object)null) ? znv.GetZDO() : null);
			if (val != null)
			{
				val.Set("fs_engineOn", engineOn);
			}
		}
	}
}
namespace FlyingShips.Config
{
	public static class FlightConfig
	{
		public static ConfigEntry<float> VerticalSpeed;

		public static ConfigEntry<float> ForwardSpeed;

		public static ConfigEntry<float> TurnSpeed;

		public static ConfigEntry<float> LevelStabilization;

		public static ConfigEntry<float> FuelPerMinute;

		public static ConfigEntry<float> AccelForward;

		public static ConfigEntry<float> DecelForward;

		public static ConfigEntry<float> AccelVertical;

		public static ConfigEntry<float> DecelVertical;

		public static ConfigEntry<float> MaxFlightHeight;

		public static ConfigEntry<float> MaxBank;

		public static ConfigEntry<float> PitchFromAccel;

		public static ConfigEntry<float> HoverDamping;

		public static ConfigEntry<float> EmergencyDescentSpeed;

		public static void Bind(ConfigFile config)
		{
			VerticalSpeed = config.Bind<float>("Flight", "VerticalSpeed", 8f, "Vertical flight speed - how fast the ship ascends/descends (m/s).");
			ForwardSpeed = config.Bind<float>("Flight", "ForwardSpeed", 12f, "Forward flight speed - how fast the ship moves forward/backward (m/s).");
			TurnSpeed = config.Bind<float>("Flight", "TurnSpeed", 1.5f, "Turning speed - how fast the ship rotates left/right while flying.");
			LevelStabilization = config.Bind<float>("Flight", "LevelStabilization", 2f, "Auto-leveling strength - how strongly the ship returns to a level position.");
			FuelPerMinute = config.Bind<float>("Flight", "FuelPerMinute", 1f, "How many Flight Essence the ship consumes per minute of flight. Set to 0 to disable fuel consumption.");
			AccelForward = config.Bind<float>("Flight", "AccelForward", 8f, "Forward acceleration - how quickly the ship reaches max speed (m/s^2).");
			DecelForward = config.Bind<float>("Flight", "DecelForward", 6f, "Forward deceleration - how quickly the ship slows down when you release W/S (m/s^2).");
			AccelVertical = config.Bind<float>("Flight", "AccelVertical", 6f, "Vertical acceleration - how quickly the ship reaches max ascend/descend speed (m/s^2).");
			DecelVertical = config.Bind<float>("Flight", "DecelVertical", 5f, "Vertical deceleration - how quickly the ship slows down vertically when you release PageUp/PageDown (m/s^2).");
			MaxFlightHeight = config.Bind<float>("Flight", "MaxFlightHeight", 250f, "Maximum flight altitude above ground (m). The ship will not fly higher than this.");
			MaxBank = config.Bind<float>("Flight", "MaxBank", 12f, "Maximum bank angle when turning (degrees). Higher values make the ship lean more into turns.");
			PitchFromAccel = config.Bind<float>("Flight", "PitchFromAccel", 0.6f, "Pitch angle from acceleration (degrees per m/s^2). The ship tilts up when accelerating, down when decelerating.");
			HoverDamping = config.Bind<float>("Flight", "HoverDamping", 3f, "Hover damping - how strongly the ship stops vertical movement when you don't press PageUp/PageDown.");
			EmergencyDescentSpeed = config.Bind<float>("Flight", "EmergencyDescentSpeed", 5f, "Emergency descent speed when fuel runs out (m/s). The ship will descend at this speed until it lands.");
		}
	}
}
namespace FlyingShips.Components
{
	public class FlightController : MonoBehaviour
	{
		public bool HasShownControls;

		public bool IsFlying;

		public bool AscendWasDown;

		public float FuelTimer;

		public Light Glow;

		public float CurrentForwardSpeed;

		public float CurrentVerticalSpeed;

		public float LastForwardSpeed;

		public float CurrentBank;

		public float CurrentPitch;

		public bool ForcedDescent;

		public bool HasWarnedLowFuel;

		public void SetGlow(bool enabled)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Glow == (Object)null)
			{
				GameObject val = new GameObject("FlyingShipBlueGlow");
				val.transform.SetParent(((Component)this).transform);
				val.transform.localPosition = new Vector3(0f, -2.5f, 0f);
				Glow = val.AddComponent<Light>();
				Glow.type = (LightType)2;
				Glow.color = FuelVisuals.FlightBlueGlow;
				Glow.range = 16f;
				Glow.intensity = 0f;
			}
			Glow.intensity = (enabled ? 5f : 0f);
		}
	}
	public class ShipBob : MonoBehaviour
	{
		public Transform visualRoot;

		public Vector3 baseLocalPos;

		public Quaternion baseLocalRot;

		public float ampPos = 0.15f;

		public float ampPitch = 1.5f;

		public float ampRoll = 2f;

		public float ampYaw = 1f;

		public float freqPos = 0.6f;

		public float freqPitch = 0.45f;

		public float freqRoll = 0.35f;

		public float freqYaw = 0.25f;

		public float blend = 0f;

		public float blendSpeed = 1.5f;

		public bool shouldBob = false;

		public float seed;

		private bool _initialized;

		private void EnsureInit()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				_initialized = true;
				seed = Random.value * 100f;
				if ((Object)(object)visualRoot != (Object)null)
				{
					baseLocalPos = visualRoot.localPosition;
					baseLocalRot = visualRoot.localRotation;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			EnsureInit();
			if (!((Object)(object)visualRoot == (Object)null))
			{
				float num = (shouldBob ? 1f : 0f);
				blend = Mathf.MoveTowards(blend, num, Time.deltaTime * blendSpeed);
				if (blend <= 0.001f && num == 0f)
				{
					visualRoot.localPosition = baseLocalPos;
					visualRoot.localRotation = baseLocalRot;
					return;
				}
				float num2 = Time.time + seed;
				float num3 = Mathf.Sin(num2 * freqPitch * (float)Math.PI * 2f) * ampPitch;
				float num4 = Mathf.Sin(num2 * freqRoll * (float)Math.PI * 2f) * ampRoll;
				float num5 = Mathf.Sin(num2 * freqYaw * (float)Math.PI * 2f) * ampYaw;
				float num6 = Mathf.Sin(num2 * freqPos * (float)Math.PI * 2f) * ampPos;
				visualRoot.localRotation = baseLocalRot * Quaternion.Euler(num3 * blend, num5 * blend, num4 * blend);
				visualRoot.localPosition = baseLocalPos + new Vector3(0f, num6 * blend, 0f);
			}
		}
	}
}