Decompiled source of Vindsail v1.0.0

Vindsail.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Vindsail")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+80b0cd103cb3edc1d56ae71521467442193d5bbb")]
[assembly: AssemblyProduct("Vindsail")]
[assembly: AssemblyTitle("Vindsail")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Vindsail
{
	public class VindsailCloth : MonoBehaviour
	{
		private const int Across = 10;

		private const int Along = 6;

		private static Mesh s_mesh;

		private static Texture2D s_weave;

		private static AudioClip s_snap;

		private static bool s_shaderWarned;

		private Transform m_player;

		private MeshRenderer m_canopy;

		private LineRenderer[] m_lines;

		private AudioSource m_audio;

		private Material m_material;

		private int m_tier = -1;

		internal static VindsailCloth Attach(Player player)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("VindsailCloth");
			val.transform.SetParent(((Component)player).transform, false);
			VindsailCloth vindsailCloth = val.AddComponent<VindsailCloth>();
			vindsailCloth.m_player = ((Component)player).transform;
			vindsailCloth.Build();
			vindsailCloth.Hide();
			return vindsailCloth;
		}

		internal static Material Linen(Color color)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0058: 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)
			Shader val = FindShader();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val);
			if ((Object)(object)s_weave == (Object)null)
			{
				s_weave = Weave();
			}
			val2.mainTexture = (Texture)(object)s_weave;
			if (val2.HasProperty("_MainTex"))
			{
				val2.SetTexture("_MainTex", (Texture)(object)s_weave);
			}
			val2.color = color;
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", color);
			}
			return val2;
		}

		internal void Show(int tier, float bank)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0047: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			if (!((Component)this).gameObject.activeSelf)
			{
				((Component)this).gameObject.SetActive(true);
			}
			tier = Mathf.Clamp(tier, 1, 4);
			if ((Object)(object)m_material != (Object)null && tier != m_tier)
			{
				m_tier = tier;
				Color val = TierColor(tier);
				m_material.color = val;
				if (m_material.HasProperty("_Color"))
				{
					m_material.SetColor("_Color", val);
				}
			}
			float num = 1f + (float)(tier - 1) * 0.06f;
			float num2 = Mathf.Sin(Time.time * 1.7f) * 2.4f;
			((Component)this).transform.localPosition = new Vector3(0f, 2.12f, -0.22f);
			((Component)this).transform.localRotation = Quaternion.Euler(-7f + num2 * 0.25f, 0f, 0f - bank);
			((Component)this).transform.localScale = new Vector3(num, 1f, num);
			PlaceLines();
		}

		internal void Hide()
		{
			if (((Component)this).gameObject.activeSelf)
			{
				((Component)this).gameObject.SetActive(false);
			}
		}

		internal void PlayOpen()
		{
			if (VindsailPlugin.OpenSound.Value && !((Object)(object)m_audio == (Object)null))
			{
				if ((Object)(object)s_snap == (Object)null)
				{
					s_snap = Snap();
				}
				if (!((Object)(object)s_snap == (Object)null))
				{
					m_audio.clip = s_snap;
					m_audio.volume = Mathf.Clamp01(VindsailPlugin.SoundVolume.Value);
					m_audio.spatialBlend = 1f;
					m_audio.Play();
				}
			}
		}

		private void Build()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)s_mesh == (Object)null)
			{
				s_mesh = Canopy();
			}
			GameObject val = new GameObject("canopy");
			val.transform.SetParent(((Component)this).transform, false);
			val.AddComponent<MeshFilter>().sharedMesh = s_mesh;
			m_canopy = val.AddComponent<MeshRenderer>();
			((Renderer)m_canopy).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)m_canopy).receiveShadows = false;
			m_material = Linen(TierColor(1));
			if ((Object)(object)m_material != (Object)null)
			{
				((Renderer)m_canopy).sharedMaterial = m_material;
			}
			m_lines = (LineRenderer[])(object)new LineRenderer[4];
			for (int i = 0; i < m_lines.Length; i++)
			{
				GameObject val2 = new GameObject("riser");
				val2.transform.SetParent(((Component)this).transform, false);
				LineRenderer val3 = val2.AddComponent<LineRenderer>();
				val3.positionCount = 2;
				val3.startWidth = 0.025f;
				val3.endWidth = 0.012f;
				val3.useWorldSpace = true;
				((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
				Material val4 = Linen(new Color(0.45f, 0.38f, 0.28f, 1f));
				if ((Object)(object)val4 != (Object)null)
				{
					((Renderer)val3).material = val4;
				}
				val3.startColor = new Color(0.55f, 0.46f, 0.32f, 0.9f);
				val3.endColor = new Color(0.35f, 0.3f, 0.22f, 0.9f);
				m_lines[i] = val3;
			}
			m_audio = ((Component)this).gameObject.AddComponent<AudioSource>();
			m_audio.playOnAwake = false;
			m_audio.spatialBlend = 1f;
			m_audio.minDistance = 2f;
			m_audio.maxDistance = 18f;
		}

		private void PlaceLines()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)m_player == (Object)null) && m_lines != null)
			{
				Vector3 val = m_player.TransformPoint(new Vector3(-0.22f, 1.35f, 0.08f));
				Vector3 val2 = m_player.TransformPoint(new Vector3(0.22f, 1.35f, 0.08f));
				Vector3[] array = (Vector3[])(object)new Vector3[4]
				{
					((Component)this).transform.TransformPoint(new Vector3(-1.45f, 0.05f, 0.55f)),
					((Component)this).transform.TransformPoint(new Vector3(-0.7f, 0.2f, 0.7f)),
					((Component)this).transform.TransformPoint(new Vector3(0.7f, 0.2f, 0.7f)),
					((Component)this).transform.TransformPoint(new Vector3(1.45f, 0.05f, 0.55f))
				};
				for (int i = 0; i < m_lines.Length; i++)
				{
					m_lines[i].SetPosition(0, (i < 2) ? val : val2);
					m_lines[i].SetPosition(1, array[i]);
				}
			}
		}

		private static Color TierColor(int tier)
		{
			//IL_002a: 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_005e: 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)
			return (Color)(tier switch
			{
				2 => new Color(0.78f, 0.58f, 0.32f, 1f), 
				3 => new Color(0.55f, 0.68f, 0.74f, 1f), 
				4 => new Color(0.28f, 0.32f, 0.46f, 1f), 
				_ => new Color(0.9f, 0.84f, 0.68f, 1f), 
			});
		}

		private static Mesh Canopy()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			int num = 11;
			int num2 = 7;
			int num3 = num * num2;
			Vector3[] array = (Vector3[])(object)new Vector3[num3];
			Vector2[] array2 = (Vector2[])(object)new Vector2[num3];
			float num4 = 3.3f;
			float num5 = 1.85f;
			for (int i = 0; i < num2; i++)
			{
				float num6 = (float)i / 6f;
				for (int j = 0; j < num; j++)
				{
					float num7 = (float)j / 10f;
					float num8 = (num7 - 0.5f) * num4;
					float num9 = (num6 - 0.35f) * num5;
					float num10 = (1f - Mathf.Pow(num8 / (num4 * 0.5f), 2f)) * 0.42f * (0.55f + 0.45f * num6);
					int num11 = i * num + j;
					array[num11] = new Vector3(num8, num10, num9);
					array2[num11] = new Vector2(num7, num6);
				}
			}
			int[] array3 = new int[720];
			int num12 = 0;
			for (int k = 0; k < 6; k++)
			{
				for (int l = 0; l < 10; l++)
				{
					int num13 = k * num + l;
					int num14 = num13 + 1;
					int num15 = num13 + num;
					int num16 = num15 + 1;
					array3[num12++] = num13;
					array3[num12++] = num15;
					array3[num12++] = num14;
					array3[num12++] = num14;
					array3[num12++] = num15;
					array3[num12++] = num16;
					array3[num12++] = num13;
					array3[num12++] = num14;
					array3[num12++] = num15;
					array3[num12++] = num14;
					array3[num12++] = num16;
					array3[num12++] = num15;
				}
			}
			Mesh val = new Mesh
			{
				name = "vindsail_canopy",
				vertices = array,
				uv = array2,
				triangles = array3
			};
			val.RecalculateNormals();
			val.RecalculateBounds();
			return val;
		}

		private static Texture2D Weave()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00c6: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					bool flag = j < 2 || i < 2 || j >= 62 || i >= 62;
					bool flag2 = i / 4 % 2 == 0;
					bool num = Mathf.Abs(j - 32) < i - 18 && i > 20 && i < 48 && Mathf.Abs(j - 32) > i - 26;
					Color val2 = (flag ? new Color(0.28f, 0.2f, 0.1f, 1f) : (flag2 ? new Color(0.93f, 0.88f, 0.74f, 1f) : new Color(0.82f, 0.74f, 0.56f, 1f)));
					if (num)
					{
						((Color)(ref val2))..ctor(0.55f, 0.28f, 0.16f, 1f);
					}
					array[i * 64 + j] = val2;
				}
			}
			val.SetPixels(array);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			val.Apply(false, true);
			return val;
		}

		private static AudioClip Snap()
		{
			float[] array = new float[7000];
			Random random = new Random(7);
			for (int i = 0; i < 7000; i++)
			{
				float num = (float)i / 7000f;
				float num2 = Mathf.Sin(Mathf.Clamp01(num * 1.4f) * MathF.PI) * (1f - num);
				float num3 = (float)random.NextDouble() * 2f - 1f;
				float num4 = Mathf.Sin(num * 90f) * Mathf.Exp((0f - num) * 10f);
				array[i] = (num3 * 0.55f + num4) * num2 * 0.4f;
			}
			AudioClip obj = AudioClip.Create("vindsail_snap", 7000, 1, 22050, false);
			obj.SetData(array, 0);
			return obj;
		}

		private static Shader FindShader()
		{
			Shader obj = Shader.Find("Custom/Creature") ?? Shader.Find("Custom/Piece") ?? Shader.Find("Diffuse") ?? Shader.Find("Unlit/Texture") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)obj == (Object)null && !s_shaderWarned)
			{
				s_shaderWarned = true;
				VindsailPlugin.Log.LogWarning((object)"Vindsail: no cloth shader, the canopy will be missing.");
			}
			return obj;
		}
	}
	public class VindsailFlight : MonoBehaviour
	{
		private static readonly FieldRef<Character, float> s_air = AccessTools.FieldRefAccess<Character, float>("m_maxAirAltitude");

		private static readonly FieldRef<Character, Rigidbody> s_body = AccessTools.FieldRefAccess<Character, Rigidbody>("m_body");

		private const string ZdoOpen = "VindsailOpen";

		private const string ZdoTier = "VindsailTier";

		private Player m_player;

		private VindsailCloth m_cloth;

		private bool m_open;

		private int m_tier = 1;

		private float m_sink = 7.5f;

		private float m_glide = 7f;

		private float m_stamina = 14f;

		private float m_said;

		private float m_bank;

		private bool m_savedMode;

		private CollisionDetectionMode m_detect;

		private static readonly RaycastHit[] s_ground = (RaycastHit[])(object)new RaycastHit[16];

		internal static VindsailFlight Local { get; private set; }

		internal bool IsOpen => m_open;

		internal int Tier => m_tier;

		internal float WindLeft
		{
			get
			{
				if ((Object)(object)m_player == (Object)null || m_stamina <= 0.01f)
				{
					return 0f;
				}
				return Mathf.Max(0f, m_player.GetStamina() / m_stamina);
			}
		}

		private void Awake()
		{
			m_player = ((Component)this).GetComponent<Player>();
			if ((Object)(object)m_player == (Object)null)
			{
				Object.Destroy((Object)(object)this);
			}
			else if ((Object)(object)m_player == (Object)(object)Player.m_localPlayer)
			{
				Local = this;
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Local == (Object)(object)this)
			{
				Local = null;
			}
			if ((Object)(object)m_cloth != (Object)null)
			{
				m_cloth.Hide();
			}
		}

		private void Update()
		{
			if ((Object)(object)m_player == (Object)null)
			{
				return;
			}
			if ((Object)(object)m_player != (Object)(object)Player.m_localPlayer)
			{
				Mirror();
				return;
			}
			if ((Object)(object)Local != (Object)(object)this)
			{
				Local = this;
			}
			if (!VindsailPlugin.Enabled.Value || ((Character)m_player).IsDead())
			{
				Shut(pin: false);
				return;
			}
			ItemData val = VindsailItem.Equipped(m_player);
			if (val == null)
			{
				if (m_open)
				{
					Shut(pin: false);
				}
				else if (Pressed() && Airborne() && VindsailItem.Carried(m_player) != null)
				{
					Say("Equip the Vindsail.");
				}
				Show(open: false);
				return;
			}
			VindsailPlugin.SailTier sailTier = VindsailPlugin.TierOf(val.m_quality);
			m_tier = Mathf.Clamp(val.m_quality, 1, 4);
			m_sink = sailTier.Sink;
			m_glide = sailTier.Glide;
			m_stamina = sailTier.Stamina;
			if (((Character)m_player).IsSwimming() || ((Character)m_player).IsAttached() || ((Character)m_player).IsDebugFlying() || ((Character)m_player).IsFlying())
			{
				Shut(pin: false);
				Show(open: false);
				return;
			}
			if (m_open && ((Character)m_player).IsOnGround())
			{
				Shut(pin: false);
			}
			if (Pressed() && !Typing())
			{
				if (m_open)
				{
					Shut(pin: false);
				}
				else
				{
					TryOpen();
				}
			}
			if (m_open)
			{
				Drain();
			}
			Show(m_open);
			Publish();
		}

		private void Mirror()
		{
			ZNetView component = ((Component)m_player).GetComponent<ZNetView>();
			bool flag = false;
			int tier = 1;
			if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null)
			{
				flag = component.GetZDO().GetBool("VindsailOpen", false);
				tier = component.GetZDO().GetInt("VindsailTier", 1);
			}
			if ((Object)(object)m_cloth == (Object)null)
			{
				m_cloth = VindsailCloth.Attach(m_player);
			}
			if (flag)
			{
				m_cloth.Show(tier, 0f);
			}
			else
			{
				m_cloth.Hide();
			}
		}

		private void TryOpen()
		{
			//IL_0025: 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)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (!Airborne())
			{
				return;
			}
			float num = s_air.Invoke((Character)(object)m_player) - ((Component)m_player).transform.position.y;
			if (num < VindsailPlugin.MinDrop.Value)
			{
				if (num >= 0.75f)
				{
					Say("The cloth needs open air.");
				}
				return;
			}
			float num2 = Mathf.Max(0f, VindsailPlugin.OpenStamina.Value);
			if (m_player.GetStamina() < num2 + 1f)
			{
				Say("Not enough stamina to catch the wind.");
				return;
			}
			if (num2 > 0f)
			{
				((Character)m_player).UseStamina(num2);
			}
			Rigidbody val = s_body.Invoke((Character)(object)m_player);
			if ((Object)(object)val != (Object)null && !val.isKinematic)
			{
				m_detect = val.collisionDetectionMode;
				m_savedMode = true;
				val.collisionDetectionMode = (CollisionDetectionMode)2;
			}
			m_open = true;
			if ((Object)(object)m_cloth == (Object)null)
			{
				m_cloth = VindsailCloth.Attach(m_player);
			}
			m_cloth.PlayOpen();
		}

		private void Drain()
		{
			float num = m_stamina * Time.deltaTime * DiveStamina();
			if (m_player.GetStamina() <= num)
			{
				float stamina = m_player.GetStamina();
				if (stamina > 0f)
				{
					((Character)m_player).UseStamina(stamina);
				}
				Shut(pin: true);
				Say("The cloth goes slack.");
			}
			else
			{
				((Character)m_player).UseStamina(num);
			}
		}

		private void Shut(bool pin)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!m_open)
			{
				return;
			}
			m_open = false;
			if (pin)
			{
				Pin();
			}
			if (m_savedMode && (Object)(object)m_player != (Object)null)
			{
				Rigidbody val = s_body.Invoke((Character)(object)m_player);
				if ((Object)(object)val != (Object)null && !val.isKinematic)
				{
					val.collisionDetectionMode = m_detect;
				}
				m_savedMode = false;
			}
		}

		private void Show(bool open)
		{
			if ((Object)(object)m_cloth == (Object)null)
			{
				m_cloth = VindsailCloth.Attach(m_player);
			}
			if (open)
			{
				m_cloth.Show(m_tier, m_bank);
			}
			else
			{
				m_cloth.Hide();
			}
		}

		private void Publish()
		{
			ZNetView component = ((Component)m_player).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner() && component.GetZDO() != null)
			{
				component.GetZDO().Set("VindsailOpen", m_open);
				component.GetZDO().Set("VindsailTier", m_tier);
			}
		}

		internal void ApplyMotion(float dt)
		{
			//IL_0049: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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_0204: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: 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_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: 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_03bc: Unknown result type (might be due to invalid IL or missing references)
			if (!m_open || (Object)(object)m_player == (Object)null || dt <= 0f)
			{
				return;
			}
			Rigidbody val = s_body.Invoke((Character)(object)m_player);
			if ((Object)(object)val == (Object)null || val.isKinematic)
			{
				return;
			}
			Vector3 val2 = ((Character)m_player).GetLookDir();
			if ((Object)(object)GameCamera.instance != (Object)null)
			{
				val2 = ((Component)GameCamera.instance).transform.forward;
			}
			float num = Mathf.Clamp01(0f - val2.y);
			float num2 = Mathf.Clamp01(val2.y);
			float num3 = Mathf.Lerp(1f, 2.6f, num) * Mathf.Lerp(1f, 0.3f, num2);
			float num4 = Mathf.Lerp(1f, 1.4f, num) * Mathf.Lerp(1f, 0.55f, num2);
			Vector3 val3 = val2;
			val3.y = 0f;
			if (((Vector3)(ref val3)).sqrMagnitude < 0.04f)
			{
				val3 = ((Component)m_player).transform.forward;
				val3.y = 0f;
			}
			if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
			{
				val3 = Vector3.forward;
			}
			((Vector3)(ref val3)).Normalize();
			Vector3 val4 = Vector3.Cross(Vector3.up, val3);
			float num5 = 0f;
			if (ZInput.GetButton("Left"))
			{
				num5 -= 1f;
			}
			if (ZInput.GetButton("Right"))
			{
				num5 += 1f;
			}
			float num6 = (ZInput.GetButton("Backward") ? 0.35f : 1f);
			m_bank = Mathf.MoveTowards(m_bank, Mathf.Clamp(num5 * 22f, -28f, 28f), 80f * dt);
			Vector3 val5 = val3 * (m_glide * num4 * num6) + val4 * (num5 * m_glide * 0.65f);
			float num7 = m_glide * num4 * 1.05f;
			if (((Vector3)(ref val5)).sqrMagnitude > num7 * num7)
			{
				val5 = ((Vector3)(ref val5)).normalized * num7;
			}
			Vector3 linearVelocity = val.linearVelocity;
			float num8 = GroundGap();
			if (((Character)m_player).IsOnGround() || num8 < 1.25f)
			{
				if (linearVelocity.y < 0f)
				{
					linearVelocity.y = 0f;
					val.linearVelocity = linearVelocity;
				}
				Shut(pin: true);
				return;
			}
			Vector3 val6 = new Vector3(linearVelocity.x, 0f, linearVelocity.z);
			float num9 = Mathf.Clamp01(((Vector3)(ref val6)).magnitude / Mathf.Max(1f, m_glide));
			float num10 = m_sink * num3 * Mathf.Lerp(1.2f, 1f, num9);
			float num11 = num8 - 1.25f;
			num10 = Mathf.Min(num10, num11 / Mathf.Max(dt, 0.02f));
			float num12 = Mathf.Max(0f, 0f - linearVelocity.y - num10);
			float num13 = Mathf.Min(m_glide * 0.85f, num12 * 0.55f);
			val5 += val3 * num13;
			float num14 = VindsailPlugin.CatchRate.Value;
			if (!float.IsFinite(num14) || num14 < 1f)
			{
				num14 = 40f;
			}
			float num15 = VindsailPlugin.SteerRate.Value;
			if (!float.IsFinite(num15) || num15 < 1f)
			{
				num15 = 28f;
			}
			linearVelocity.y = Mathf.MoveTowards(linearVelocity.y, 0f - num10, num14 * dt);
			Vector3 val7 = Vector3.MoveTowards(new Vector3(linearVelocity.x, 0f, linearVelocity.z), val5, num15 * dt);
			linearVelocity.x = val7.x;
			linearVelocity.z = val7.z;
			val.linearVelocity = linearVelocity;
			Pin();
		}

		private float GroundGap()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)m_player).transform.position;
			float num = 80f;
			float num2 = default(float);
			if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(position, ref num2))
			{
				num = position.y - num2;
			}
			int num3 = Physics.RaycastNonAlloc(position + Vector3.up * 0.35f, Vector3.down, s_ground, 40f, -5, (QueryTriggerInteraction)1);
			for (int i = 0; i < num3; i++)
			{
				Collider collider = ((RaycastHit)(ref s_ground[i])).collider;
				if ((Object)(object)collider == (Object)null)
				{
					continue;
				}
				Transform transform = ((Component)collider).transform;
				if (!((Object)(object)transform == (Object)(object)((Component)m_player).transform) && !transform.IsChildOf(((Component)m_player).transform))
				{
					float num4 = ((RaycastHit)(ref s_ground[i])).distance - 0.35f;
					if (num4 < num)
					{
						num = num4;
					}
				}
			}
			return num;
		}

		internal void Pin()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)m_player == (Object)null))
			{
				s_air.Invoke((Character)(object)m_player) = ((Component)m_player).transform.position.y;
			}
		}

		private bool Airborne()
		{
			if ((Object)(object)m_player != (Object)null && !((Character)m_player).IsOnGround() && !((Character)m_player).IsSwimming())
			{
				return !((Character)m_player).IsAttached();
			}
			return false;
		}

		private float DiveStamina()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_player == (Object)null)
			{
				return 1f;
			}
			float num = Mathf.Clamp01(0f - ((Character)m_player).GetLookDir().y);
			return 1f + num * 0.35f;
		}

		private bool Pressed()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (ZInput.GetButtonDown("Jump"))
			{
				return true;
			}
			KeyboardShortcut value = VindsailPlugin.OpenKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
			{
				return ((KeyboardShortcut)(ref value)).IsDown();
			}
			return false;
		}

		private static bool Typing()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)Cursor.lockState != 1)
			{
				return true;
			}
			if (Menu.IsVisible() || Console.IsVisible() || InventoryGui.IsVisible())
			{
				return true;
			}
			if (TextInput.IsVisible() || Minimap.InTextInput())
			{
				return true;
			}
			if ((Object)(object)Chat.instance != (Object)null)
			{
				return Chat.instance.IsChatDialogWindowVisible();
			}
			return false;
		}

		private void Say(string text)
		{
			if (!(Time.time < m_said) && !((Object)(object)m_player == (Object)null))
			{
				m_said = Time.time + 1.6f;
				((Character)m_player).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	internal static class VindsailPlayerAwake
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).GetComponent<VindsailFlight>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<VindsailFlight>();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateMotion")]
	internal static class VindsailMotion
	{
		private static void Postfix(Character __instance, float dt)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				VindsailFlight component = ((Component)__instance).GetComponent<VindsailFlight>();
				if ((Object)(object)component != (Object)null && component.IsOpen)
				{
					component.ApplyMotion(dt);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateGroundContact")]
	internal static class VindsailLanding
	{
		private static void Prefix(Character __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				VindsailFlight component = ((Component)__instance).GetComponent<VindsailFlight>();
				if ((Object)(object)component != (Object)null && component.IsOpen)
				{
					component.Pin();
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class VindsailHands
	{
		private static bool Prefix(Humanoid __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !VindsailPlugin.BlockAttacks.Value)
			{
				return true;
			}
			VindsailFlight component = ((Component)__instance).GetComponent<VindsailFlight>();
			if (!((Object)(object)component == (Object)null))
			{
				return !component.IsOpen;
			}
			return true;
		}
	}
	internal static class VindsailItem
	{
		internal const string PrefabName = "DFG_Vindsail";

		internal const string ItemName = "Vindsail";

		internal const string ItemDesc = "A stitched wind-cloth worn on the belt. Step off something high and press Jump to open it. Look where you want to go. It drinks stamina. When the stamina runs out, the cloth shuts and the rest of the fall is yours.";

		private static bool s_registered;

		internal static void Initialize()
		{
			PrefabManager.OnVanillaPrefabsAvailable += Register;
		}

		internal static bool IsSail(ItemData item)
		{
			if (item == null || item.m_shared == null)
			{
				return false;
			}
			if ((Object)(object)item.m_dropPrefab != (Object)null && ((Object)item.m_dropPrefab).name == "DFG_Vindsail")
			{
				return true;
			}
			return item.m_shared.m_name == "Vindsail";
		}

		internal static ItemData Equipped(Player player)
		{
			if ((Object)(object)player == (Object)null || ((Humanoid)player).GetInventory() == null)
			{
				return null;
			}
			List<ItemData> equippedItems = ((Humanoid)player).GetInventory().GetEquippedItems();
			if (equippedItems == null)
			{
				return null;
			}
			for (int i = 0; i < equippedItems.Count; i++)
			{
				if (IsSail(equippedItems[i]))
				{
					return equippedItems[i];
				}
			}
			return null;
		}

		internal static ItemData Carried(Player player)
		{
			if ((Object)(object)player == (Object)null || ((Humanoid)player).GetInventory() == null)
			{
				return null;
			}
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (IsSail(allItem))
				{
					return allItem;
				}
			}
			return null;
		}

		private static void Register()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			if (s_registered || !VindsailPlugin.Enabled.Value)
			{
				return;
			}
			try
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("BeltStrength");
				if ((Object)(object)prefab == (Object)null)
				{
					prefab = PrefabManager.Instance.GetPrefab("Wishbone");
				}
				if ((Object)(object)prefab == (Object)null)
				{
					VindsailPlugin.Log.LogWarning((object)"Vindsail: no utility item to clone.");
					return;
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab("DFG_Vindsail", prefab);
				if ((Object)(object)val == (Object)null)
				{
					VindsailPlugin.Log.LogError((object)"Vindsail: the utility clone failed.");
					return;
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null || component.m_itemData == null || component.m_itemData.m_shared == null)
				{
					VindsailPlugin.Log.LogError((object)"Vindsail: the clone has no item data.");
					return;
				}
				SharedData shared = component.m_itemData.m_shared;
				shared.m_name = "Vindsail";
				shared.m_description = "A stitched wind-cloth worn on the belt. Step off something high and press Jump to open it. Look where you want to go. It drinks stamina. When the stamina runs out, the cloth shuts and the rest of the fall is yours.";
				shared.m_itemType = (ItemType)18;
				shared.m_maxStackSize = 1;
				shared.m_maxQuality = 4;
				shared.m_weight = 1.5f;
				shared.m_useDurability = false;
				shared.m_movementModifier = 0f;
				shared.m_equipStatusEffect = null;
				Sprite val2 = LoadIcon();
				if ((Object)(object)val2 != (Object)null)
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 };
				}
				FoldIntoBundle(val);
				bool flag = !(AccessTools.TypeByName("Pebble.PebblePlugin") != null) || !VindsailPlugin.VendorOnly.Value;
				ItemConfig val3 = new ItemConfig
				{
					Name = "Vindsail",
					Description = "A stitched wind-cloth worn on the belt. Step off something high and press Jump to open it. Look where you want to go. It drinks stamina. When the stamina runs out, the cloth shuts and the rest of the fall is yours.",
					Icon = val2
				};
				if (flag)
				{
					val3.CraftingStation = CraftingStations.Workbench;
					val3.MinStationLevel = 1;
					val3.Amount = 1;
					val3.Requirements = WorkbenchCost();
				}
				ItemManager.Instance.AddItem(new CustomItem(val, false, val3));
				s_registered = true;
				VindsailPlugin.Log.LogInfo((object)(flag ? "Vindsail: registered, with a workbench recipe." : "Vindsail: registered. Pebble sells it."));
			}
			catch (Exception ex)
			{
				VindsailPlugin.Log.LogError((object)("Vindsail: item registration failed: " + ex));
			}
		}

		private static RequirementConfig[] WorkbenchCost()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			List<VindsailShop.CostLine> list = VindsailShop.Parse(VindsailPlugin.T1Cost.Value);
			if (list.Count == 0)
			{
				list = VindsailShop.Parse("Coins:480,TrollHide:2,LeatherScraps:8,FineWood:6,Resin:6");
			}
			RequirementConfig[] array = (RequirementConfig[])(object)new RequirementConfig[list.Count];
			for (int i = 0; i < list.Count; i++)
			{
				int num = Mathf.Max(1, list[i].Amount);
				array[i] = new RequirementConfig
				{
					Item = list[i].Prefab,
					Amount = num,
					AmountPerLevel = Mathf.Max(1, num / 2)
				};
			}
			return array;
		}

		private static void FoldIntoBundle(GameObject item)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				val = GameObject.CreatePrimitive((PrimitiveType)3);
				Collider component = val.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
				((Object)val).name = "vindsail_bundle";
				val.transform.SetParent(item.transform, false);
				val.transform.localPosition = new Vector3(0.02f, 0.04f, 0f);
				val.transform.localRotation = Quaternion.Euler(18f, 24f, 8f);
				val.transform.localScale = new Vector3(0.22f, 0.07f, 0.15f);
				Renderer component2 = val.GetComponent<Renderer>();
				Material val2 = VindsailCloth.Linen(new Color(0.86f, 0.78f, 0.6f, 1f));
				if ((Object)(object)component2 != (Object)null && (Object)(object)val2 != (Object)null)
				{
					component2.sharedMaterial = val2;
					component2.shadowCastingMode = (ShadowCastingMode)0;
				}
				Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val3 in componentsInChildren)
				{
					if ((Object)(object)((Component)val3).gameObject != (Object)(object)val)
					{
						val3.enabled = false;
					}
				}
			}
			catch (Exception ex)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				VindsailPlugin.Log.LogWarning((object)("Vindsail: kept the belt mesh, the folded bundle failed: " + ex.Message));
			}
		}

		private static Sprite LoadIcon()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", "icon.png");
				if (!File.Exists(path))
				{
					return null;
				}
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					return null;
				}
				((Texture)val).filterMode = (FilterMode)1;
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception ex)
			{
				VindsailPlugin.Log.LogWarning((object)("Vindsail: icon skipped: " + ex.Message));
				return null;
			}
		}
	}
	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })]
	internal static class VindsailTooltip
	{
		private static void Postfix(ItemData __instance, ref string __result)
		{
			if (VindsailItem.IsSail(__instance) && !string.IsNullOrEmpty(__result))
			{
				VindsailPlugin.SailTier sailTier = VindsailPlugin.TierOf(__instance.m_quality);
				__result = __result + "\n<color=#FFD760>" + sailTier.Name + "</color>\nDescent <color=#A8D4FF>" + sailTier.Sink.ToString("0.0") + " m/s</color>\nGlide <color=#A8D4FF>" + sailTier.Glide.ToString("0.0") + " m/s</color>\nStamina <color=#A8D4FF>" + sailTier.Stamina.ToString("0.0") + "/s</color>";
			}
		}
	}
	[BepInPlugin("com.dfg.vindsail", "Vindsail", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class VindsailPlugin : BaseUnityPlugin
	{
		internal readonly struct SailTier
		{
			public readonly string Name;

			public readonly float Sink;

			public readonly float Glide;

			public readonly float Stamina;

			public readonly string Cost;

			public SailTier(string name, float sink, float glide, float stamina, string cost)
			{
				Name = name;
				Sink = sink;
				Glide = glide;
				Stamina = stamina;
				Cost = cost;
			}
		}

		public const string PluginGUID = "com.dfg.vindsail";

		public const string PluginName = "Vindsail";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> VendorOnly;

		internal static ConfigEntry<bool> BlockAttacks;

		internal static ConfigEntry<bool> OpenSound;

		internal static ConfigEntry<float> SoundVolume;

		internal static ConfigEntry<float> MinDrop;

		internal static ConfigEntry<float> OpenStamina;

		internal static ConfigEntry<float> CatchRate;

		internal static ConfigEntry<float> SteerRate;

		internal static ConfigEntry<KeyboardShortcut> OpenKey;

		internal static ConfigEntry<float> T1Sink;

		internal static ConfigEntry<float> T1Glide;

		internal static ConfigEntry<float> T1Stamina;

		internal static ConfigEntry<float> T2Sink;

		internal static ConfigEntry<float> T2Glide;

		internal static ConfigEntry<float> T2Stamina;

		internal static ConfigEntry<float> T3Sink;

		internal static ConfigEntry<float> T3Glide;

		internal static ConfigEntry<float> T3Stamina;

		internal static ConfigEntry<float> T4Sink;

		internal static ConfigEntry<float> T4Glide;

		internal static ConfigEntry<float> T4Stamina;

		internal static ConfigEntry<string> T1Cost;

		internal static ConfigEntry<string> T2Cost;

		internal static ConfigEntry<string> T3Cost;

		internal static ConfigEntry<string> T4Cost;

		private const string General = "1 - General";

		private const string Flight = "2 - Flight";

		private const string Tiers = "3 - Cloth";

		private const string Shop = "4 - Pebble";

		private bool m_shopRegistered;

		private float m_shopWait;

		private GUIStyle m_hud;

		internal static VindsailPlugin Instance { get; private set; }

		internal static SailTier TierOf(int quality)
		{
			return Mathf.Clamp(quality, 1, 4) switch
			{
				2 => new SailTier("Stitched", Safe(T2Sink.Value, 1.6f), Safe(T2Glide.Value, 15f), Safe(T2Stamina.Value, 6f), T2Cost.Value), 
				3 => new SailTier("Windwoven", Safe(T3Sink.Value, 1.15f), Safe(T3Glide.Value, 17f), Safe(T3Stamina.Value, 4.5f), T3Cost.Value), 
				4 => new SailTier("Stormcloth", Safe(T4Sink.Value, 0.85f), Safe(T4Glide.Value, 19f), Safe(T4Stamina.Value, 3.2f), T4Cost.Value), 
				_ => new SailTier("Sailcloth", Safe(T1Sink.Value, 2.2f), Safe(T1Glide.Value, 13f), Safe(T1Stamina.Value, 8f), T1Cost.Value), 
			};
		}

		private static float Safe(float value, float fallback)
		{
			if (!float.IsFinite(value) || !(value > 0f))
			{
				return fallback;
			}
			return value;
		}

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Bind();
			if (!Enabled.Value)
			{
				Log.LogInfo((object)"Vindsail is disabled in config.");
				return;
			}
			try
			{
				new Harmony("com.dfg.vindsail").PatchAll(typeof(VindsailPlugin).Assembly);
				Log.LogInfo((object)"Vindsail: patches applied.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Vindsail: patches failed: " + ex));
			}
			VindsailItem.Initialize();
		}

		private void Update()
		{
			if (Enabled.Value && !m_shopRegistered)
			{
				m_shopWait += Time.deltaTime;
				if (!(AccessTools.TypeByName("Pebble.PebbleAPI") == null) || !(m_shopWait < 8f))
				{
					m_shopRegistered = true;
					RegisterShop();
				}
			}
		}

		private void OnGUI()
		{
			//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)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_008d: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			VindsailFlight local = VindsailFlight.Local;
			if (!((Object)(object)local == (Object)null) && local.IsOpen && !((Object)(object)Player.m_localPlayer == (Object)null) && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Console.IsVisible())
			{
				if (m_hud == null)
				{
					m_hud = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontSize = 16,
						fontStyle = (FontStyle)1
					};
					m_hud.normal.textColor = new Color(0.96f, 0.9f, 0.75f, 1f);
				}
				SailTier sailTier = TierOf(local.Tier);
				float windLeft = local.WindLeft;
				string text = (float.IsPositiveInfinity(windLeft) ? "holds" : (windLeft.ToString("0") + "s of wind"));
				string text2 = "Vindsail  ·  " + sailTier.Name + "  ·  " + text;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)Screen.width * 0.5f - 220f, (float)Screen.height - 118f, 440f, 26f);
				Color textColor = m_hud.normal.textColor;
				m_hud.normal.textColor = new Color(0f, 0f, 0f, 0.75f);
				GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text2, m_hud);
				m_hud.normal.textColor = textColor;
				GUI.Label(val, text2, m_hud);
			}
		}

		private void Bind()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Turn the cloth off without removing the mod.");
			VendorOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "VendorOnly", true, "When Pebble is installed, he is the only way to buy the cloth and its stitches. With Pebble absent, the workbench still has the recipe.");
			BlockAttacks = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "BlockAttacks", true, "Both hands are on the cloth, so attacks do not start while it is open.");
			OpenSound = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "OpenSound", true, "A short cloth-snap when the sail opens.");
			SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "SoundVolume", 0.45f, new ConfigDescription("How loud the snap is.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			MinDrop = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Flight", "MinDrop", 2.5f, new ConfigDescription("Metres already fallen before Jump opens the cloth. A normal hop stays under this, so Jump still jumps. Damage in this game starts after 4 m, so the default opens while the drop is still free.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 12f), Array.Empty<object>()));
			OpenStamina = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Flight", "OpenStamina", 8f, new ConfigDescription("Stamina spent to open the cloth.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			CatchRate = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Flight", "CatchRate", 40f, new ConfigDescription("How fast a hard fall is pulled up to the cloth's descent, in m/s per second. The fall counter is pinned the whole time, so the catch itself does not deal damage.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 80f), Array.Empty<object>()));
			SteerRate = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Flight", "SteerRate", 28f, new ConfigDescription("How fast the horizontal speed chases the direction you are looking, in m/s per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 60f), Array.Empty<object>()));
			OpenKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Flight", "OpenKey", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "An extra key that opens and closes the cloth. Jump always does it too, and Jump follows the binding in the game's own controls.");
			T1Sink = BindPair("3 - Cloth", "SailclothSink", 2.2f, "Sailcloth descent, metres per second, while you are looking level.");
			T1Glide = BindPair("3 - Cloth", "SailclothGlide", 13f, "Sailcloth speed along the way you are looking, metres per second.");
			T1Stamina = BindPair("3 - Cloth", "SailclothStamina", 8f, "Sailcloth stamina drained per second.");
			T2Sink = BindPair("3 - Cloth", "StitchedSink", 1.6f, "Stitched descent, metres per second, while you are looking level.");
			T2Glide = BindPair("3 - Cloth", "StitchedGlide", 15f, "Stitched speed along the way you are looking, metres per second.");
			T2Stamina = BindPair("3 - Cloth", "StitchedStamina", 6f, "Stitched stamina drained per second.");
			T3Sink = BindPair("3 - Cloth", "WindwovenSink", 1.15f, "Windwoven descent, metres per second, while you are looking level.");
			T3Glide = BindPair("3 - Cloth", "WindwovenGlide", 17f, "Windwoven speed along the way you are looking, metres per second.");
			T3Stamina = BindPair("3 - Cloth", "WindwovenStamina", 4.5f, "Windwoven stamina drained per second.");
			T4Sink = BindPair("3 - Cloth", "StormclothSink", 0.85f, "Stormcloth descent, metres per second, while you are looking level.");
			T4Glide = BindPair("3 - Cloth", "StormclothGlide", 19f, "Stormcloth speed along the way you are looking, metres per second.");
			T4Stamina = BindPair("3 - Cloth", "StormclothStamina", 3.2f, "Stormcloth stamina drained per second.");
			T1Cost = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Pebble", "SailclothCost", "Coins:480,TrollHide:2,LeatherScraps:8,FineWood:6,Resin:6", "What Pebble charges for the first cloth. Prefab:amount, separated by commas. Coins are taken from the pocket and then the bank.");
			T2Cost = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Pebble", "StitchedCost", "Coins:360,TrollHide:4,LeatherScraps:6,BoneFragments:8", "What the second stitch costs. The cloth has to be Sailcloth already.");
			T3Cost = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Pebble", "WindwovenCost", "Coins:720,WolfPelt:4,FineWood:10,Iron:2", "What the third stitch costs.");
			T4Cost = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Pebble", "StormclothCost", "Coins:1400,LoxPelt:2,LinenThread:10,Silver:4", "What the last stitch costs.");
		}

		private ConfigEntry<float> BindPair(string section, string key, float value, string description)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 40f), Array.Empty<object>()));
		}

		private void RegisterShop()
		{
			Type type = AccessTools.TypeByName("Pebble.PebbleAPI");
			if (type == null)
			{
				Log.LogInfo((object)"Vindsail: Pebble is not loaded, so the workbench has the recipe.");
				return;
			}
			MethodInfo methodInfo = null;
			MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo2 in methods)
			{
				if (!(methodInfo2.Name != "RegisterTab"))
				{
					ParameterInfo[] parameters = methodInfo2.GetParameters();
					if (parameters.Length == 2 && parameters[1].ParameterType == typeof(Action<Rect>))
					{
						methodInfo = methodInfo2;
						break;
					}
				}
			}
			if (methodInfo == null)
			{
				Log.LogWarning((object)"Vindsail: this Pebble build has no shop tab that receives a body rect. Rebuild Pebble.");
				return;
			}
			try
			{
				methodInfo.Invoke(null, new object[2]
				{
					"Vindsail",
					new Action<Rect>(VindsailShop.Draw)
				});
				Log.LogInfo((object)"Vindsail: Pebble sells the cloth.");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Vindsail: could not register the Pebble tab: " + ex.Message));
			}
		}
	}
	internal static class VindsailShop
	{
		internal readonly struct CostLine
		{
			public readonly string Prefab;

			public readonly int Amount;

			public CostLine(string prefab, int amount)
			{
				Prefab = prefab;
				Amount = amount;
			}
		}

		private static Texture2D s_white;

		private static string s_status = "Pebble keeps the cloth under the counter until you ask.";

		private static GUIStyle s_title;

		private static GUIStyle s_body;

		private static GUIStyle s_small;

		internal static List<CostLine> Parse(string text)
		{
			List<CostLine> list = new List<CostLine>();
			if (string.IsNullOrWhiteSpace(text))
			{
				return list;
			}
			string[] array = text.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Trim().Split(':');
				if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0 && array2[0].Trim().Length > 0)
				{
					list.Add(new CostLine(array2[0].Trim(), result));
				}
			}
			return list;
		}

		internal static void Draw(Rect body)
		{
			//IL_001c: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null)
			{
				GUI.Label(body, "Pebble has no one to sell to.", s_body);
				return;
			}
			float num = 12f;
			float num2 = (((Rect)(ref body)).width - num) * 0.56f;
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(((Rect)(ref body)).x, ((Rect)(ref body)).y, num2, ((Rect)(ref body)).height);
			Rect rect2 = default(Rect);
			((Rect)(ref rect2))..ctor(((Rect)(ref body)).x + num2 + num, ((Rect)(ref body)).y, ((Rect)(ref body)).width - num2 - num, ((Rect)(ref body)).height);
			DrawBox(rect, new Color(0.09f, 0.11f, 0.16f, 0.94f), new Color(0.74f, 0.58f, 0.28f, 0.85f));
			DrawBox(rect2, new Color(0.09f, 0.11f, 0.16f, 0.94f), new Color(0.22f, 0.28f, 0.38f, 0.9f));
			ItemData val = VindsailItem.Carried(localPlayer);
			float num3 = ((Rect)(ref rect)).y + 12f;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num3, ((Rect)(ref rect)).width - 24f, 22f), "Vindsail", s_title);
			num3 += 24f;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num3, ((Rect)(ref rect)).width - 24f, 52f), "A wind-cloth for the belt. Jump opens it once you are already falling. Look where you want to go. The utility slot is the price: the cloth or the Megingjord, not both.", s_body);
			num3 += 58f;
			Rect rect3 = default(Rect);
			for (int i = 1; i <= 4; i++)
			{
				VindsailPlugin.SailTier sailTier = VindsailPlugin.TierOf(i);
				bool flag = val != null && Mathf.Clamp(val.m_quality, 1, 4) == i;
				bool flag2 = val != null && val.m_quality >= i;
				((Rect)(ref rect3))..ctor(((Rect)(ref rect)).x + 12f, num3, ((Rect)(ref rect)).width - 24f, 34f);
				DrawBox(rect3, flag ? new Color(0.16f, 0.13f, 0.07f, 0.95f) : new Color(0.07f, 0.09f, 0.12f, 0.8f), flag ? new Color(0.74f, 0.58f, 0.28f, 1f) : new Color(0.18f, 0.22f, 0.3f, 0.7f));
				string text = (flag ? "▸ " : (flag2 ? "✓ " : "· "));
				GUI.Label(new Rect(((Rect)(ref rect3)).x + 8f, ((Rect)(ref rect3)).y + 2f, ((Rect)(ref rect3)).width - 16f, 16f), text + sailTier.Name, s_small);
				GUI.Label(new Rect(((Rect)(ref rect3)).x + 8f, ((Rect)(ref rect3)).y + 16f, ((Rect)(ref rect3)).width - 16f, 16f), sailTier.Sink.ToString("0.0") + " m/s down   " + sailTier.Glide.ToString("0.0") + " m/s   " + sailTier.Stamina.ToString("0") + " stam/s", s_body);
				num3 += 38f;
			}
			DrawOffer(rect2, localPlayer, val);
			GUI.Label(new Rect(((Rect)(ref body)).x + 8f, ((Rect)(ref body)).yMax - 22f, ((Rect)(ref body)).width - 16f, 18f), s_status, s_body);
		}

		private static void DrawOffer(Rect rect, Player player, ItemData sail)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref rect)).y + 12f;
			if (sail == null)
			{
				GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 22f), "Buy the cloth", s_title);
				num += 26f;
				GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 36f), "Sailcloth. The later stitches are bought onto this same cloth.", s_body);
				num += 40f;
				if (OfferButton(rect, ref num, player, VindsailPlugin.T1Cost.Value, "BUY THE CLOTH"))
				{
					Buy(player);
				}
				return;
			}
			int num2 = Mathf.Clamp(sail.m_quality, 1, 4);
			if (num2 >= 4)
			{
				GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 22f), "Stormcloth", s_title);
				num += 28f;
				GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 48f), "Pebble has nothing further to stitch. The cloth is as slow, as far, and as light on stamina as he knows how to make it.", s_body);
				return;
			}
			VindsailPlugin.SailTier tier = VindsailPlugin.TierOf(num2 + 1);
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 22f), "Stitch: " + tier.Name, s_title);
			num += 26f;
			string text = (sail.m_equipped ? "It is on your belt." : "It is in your pack. Equip it to fly.");
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, num, ((Rect)(ref rect)).width - 24f, 36f), "Your cloth is " + VindsailPlugin.TierOf(num2).Name + ". " + text, s_body);
			num += 40f;
			if (OfferButton(rect, ref num, player, tier.Cost, "STITCH " + tier.Name.ToUpperInvariant()))
			{
				Upgrade(player, sail, num2 + 1, tier);
			}
		}

		private static bool OfferButton(Rect rect, ref float y, Player player, string cost, string label)
		{
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			List<CostLine> list = Parse(cost);
			bool flag = true;
			for (int i = 0; i < list.Count; i++)
			{
				CostLine costLine = list[i];
				long num = ((costLine.Prefab == "Coins") ? Funds(player) : ((Humanoid)player).GetInventory().CountItems(Shared(costLine.Prefab), -1, true));
				bool flag2 = num >= costLine.Amount;
				if (!flag2)
				{
					flag = false;
				}
				string text = (flag2 ? "✓  " : "✗  ") + Nice(costLine.Prefab) + "   " + num.ToString("N0") + " / " + costLine.Amount.ToString("N0");
				GUI.Label(new Rect(((Rect)(ref rect)).x + 16f, y, ((Rect)(ref rect)).width - 32f, 18f), text, s_small);
				y += 18f;
			}
			y += 10f;
			Rect val = new Rect(((Rect)(ref rect)).x + 16f, y, ((Rect)(ref rect)).width - 32f, 36f);
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = (flag ? new Color(0.22f, 0.48f, 0.28f, 1f) : new Color(0.22f, 0.2f, 0.16f, 1f));
			bool result = GUI.Button(val, label);
			GUI.backgroundColor = backgroundColor;
			return result;
		}

		private static void Buy(Player player)
		{
			if (VindsailItem.Carried(player) != null)
			{
				s_status = "You already carry a Vindsail.";
				return;
			}
			List<CostLine> lines = Parse(VindsailPlugin.T1Cost.Value);
			if (!CanPay(player, lines, out var missing))
			{
				s_status = missing;
			}
			else if (!Take(player, lines))
			{
				s_status = "Pebble could not take the payment.";
			}
			else if (!Give(player))
			{
				s_status = "The cloth is registered, but it could not be handed over. Check the log.";
				VindsailPlugin.Log.LogWarning((object)"Vindsail: payment taken and the item prefab was missing.");
			}
			else
			{
				s_status = "Pebble folds a Sailcloth into your pack.";
				((Character)player).Message((MessageType)2, "Pebble folds a Vindsail into your pack.", 0, (Sprite)null, false);
			}
		}

		private static void Upgrade(Player player, ItemData sail, int quality, VindsailPlugin.SailTier tier)
		{
			List<CostLine> lines = Parse(tier.Cost);
			if (!CanPay(player, lines, out var missing))
			{
				s_status = missing;
				return;
			}
			if (!Take(player, lines))
			{
				s_status = "Pebble could not take the payment.";
				return;
			}
			sail.m_quality = quality;
			s_status = "Pebble stitches the cloth up to " + tier.Name + ".";
			((Character)player).Message((MessageType)2, "The Vindsail is now " + tier.Name + ".", 0, (Sprite)null, false);
		}

		private static bool CanPay(Player player, List<CostLine> lines, out string missing)
		{
			for (int i = 0; i < lines.Count; i++)
			{
				CostLine costLine = lines[i];
				long num = ((costLine.Prefab == "Coins") ? Funds(player) : ((Humanoid)player).GetInventory().CountItems(Shared(costLine.Prefab), -1, true));
				if (num < costLine.Amount)
				{
					missing = "Short " + Nice(costLine.Prefab) + ": " + num.ToString("N0") + " of " + costLine.Amount.ToString("N0") + ".";
					return false;
				}
			}
			missing = null;
			return true;
		}

		private static bool Take(Player player, List<CostLine> lines)
		{
			int num = 0;
			for (int i = 0; i < lines.Count; i++)
			{
				if (lines[i].Prefab == "Coins")
				{
					num += lines[i].Amount;
				}
			}
			if (num > 0 && !PayCoins(player, num))
			{
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			for (int j = 0; j < lines.Count; j++)
			{
				if (!(lines[j].Prefab == "Coins"))
				{
					inventory.RemoveItem(Shared(lines[j].Prefab), lines[j].Amount, -1, true);
				}
			}
			return true;
		}

		private static bool Give(Player player)
		{
			//IL_007e: 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_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_0097: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				val = ObjectDB.instance.GetItemPrefab("DFG_Vindsail");
			}
			if ((Object)(object)val == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
			{
				val = ZNetScene.instance.GetPrefab("DFG_Vindsail");
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (!((Humanoid)player).GetInventory().AddItem(val, 1))
			{
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null)
				{
					return false;
				}
				ItemDrop.DropItem(component.m_itemData, 1, ((Component)player).transform.position + Vector3.up * 0.5f, Quaternion.identity);
				((Character)player).Message((MessageType)2, "Inventory full. The cloth is at your feet.", 0, (Sprite)null, false);
			}
			return true;
		}

		private static long Funds(Player player)
		{
			try
			{
				Type type = AccessTools.TypeByName("Pebble.PebbleBank");
				MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "GetAvailableFunds", (Type[])null, (Type[])null) : null);
				if (methodInfo != null)
				{
					object obj = methodInfo.Invoke(null, new object[1] { player });
					if (obj is long result)
					{
						return result;
					}
					if (obj is int num)
					{
						return num;
					}
				}
			}
			catch (Exception ex)
			{
				VindsailPlugin.Log.LogWarning((object)("Vindsail: bank funds unreadable: " + ex.Message));
			}
			return ((Humanoid)player).GetInventory().CountItems(Shared("Coins"), -1, true);
		}

		private static bool PayCoins(Player player, int amount)
		{
			try
			{
				Type type = AccessTools.TypeByName("Pebble.PebbleBank");
				MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "DeductFunds", new Type[2]
				{
					typeof(Player),
					typeof(int)
				}, (Type[])null) : null);
				if (methodInfo != null)
				{
					return (bool)methodInfo.Invoke(null, new object[2] { player, amount });
				}
			}
			catch (Exception ex)
			{
				VindsailPlugin.Log.LogWarning((object)("Vindsail: bank payment failed: " + ex.Message));
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			string text = Shared("Coins");
			if (inventory.CountItems(text, -1, true) < amount)
			{
				return false;
			}
			inventory.RemoveItem(text, amount, -1, true);
			return true;
		}

		private static string Shared(string prefab)
		{
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
				ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val != (Object)null && val.m_itemData != null && val.m_itemData.m_shared != null)
				{
					return val.m_itemData.m_shared.m_name;
				}
			}
			return prefab;
		}

		private static string Nice(string prefab)
		{
			return prefab switch
			{
				"Coins" => "Coins", 
				"TrollHide" => "Troll hide", 
				"LeatherScraps" => "Leather scraps", 
				"FineWood" => "Fine wood", 
				"Resin" => "Resin", 
				"BoneFragments" => "Bone fragments", 
				"WolfPelt" => "Wolf pelt", 
				"Iron" => "Iron", 
				"LoxPelt" => "Lox pelt", 
				"LinenThread" => "Linen thread", 
				"Silver" => "Silver", 
				_ => prefab, 
			};
		}

		private static void Ensure()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0020: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_006d: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)s_white == (Object)null)
			{
				s_white = new Texture2D(1, 1);
				s_white.SetPixel(0, 0, Color.white);
				s_white.Apply();
			}
			if (s_title == null)
			{
				s_title = new GUIStyle(GUI.skin.label)
				{
					fontSize = 16,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3,
					wordWrap = false
				};
				s_title.normal.textColor = new Color(1f, 0.84f, 0.38f, 1f);
				s_body = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					wordWrap = true,
					alignment = (TextAnchor)0
				};
				s_body.normal.textColor = new Color(0.78f, 0.82f, 0.88f, 1f);
				s_small = new GUIStyle(s_body)
				{
					fontStyle = (FontStyle)1
				};
				s_small.normal.textColor = new Color(0.92f, 0.95f, 0.98f, 1f);
			}
		}

		private static void DrawBox(Rect rect, Color fill, Color border)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			GUI.color = fill;
			GUI.DrawTexture(rect, (Texture)(object)s_white);
			GUI.color = border;
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - 1f, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white);
			GUI.color = color;
		}
	}
}