Decompiled source of WingsOfTheForgottenGods v1.1.1

WingsOfTheForgottenGods.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using WingsOfTheForgottenGods.Abilities;
using WingsOfTheForgottenGods.Abilities.Hraesvelgr;
using WingsOfTheForgottenGods.Abilities.Nidhogg;
using WingsOfTheForgottenGods.Abilities.Tyr;
using WingsOfTheForgottenGods.Assets;
using WingsOfTheForgottenGods.Audio;
using WingsOfTheForgottenGods.Commands;
using WingsOfTheForgottenGods.Config;
using WingsOfTheForgottenGods.Core;
using WingsOfTheForgottenGods.Flight;
using WingsOfTheForgottenGods.Items;
using WingsOfTheForgottenGods.Localization;
using WingsOfTheForgottenGods.Network;
using WingsOfTheForgottenGods.Visuals;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Wings Of The Forgotten Gods")]
[assembly: AssemblyDescription("Craftable animated wings and controlled flight for Valheim")]
[assembly: AssemblyCompany("DarkSpider")]
[assembly: AssemblyProduct("Wings Of The Forgotten Gods")]
[assembly: InternalsVisibleTo("WingsOfTheForgottenGods.LogicTests")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: ComVisible(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[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 WingsOfTheForgottenGods
{
	[BepInPlugin("darkspider.wingsoftheforgottengods", "Wings Of The Forgotten Gods", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	internal sealed class WingsOfTheForgottenGodsPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "darkspider.wingsoftheforgottengods";

		internal const string PluginName = "Wings Of The Forgotten Gods";

		internal const string PluginVersion = "1.1.1";

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			ModLog.Init(((BaseUnityPlugin)this).Logger);
			WingConfig.Bind(((BaseUnityPlugin)this).Config);
			WingLocalization.Register();
			PrefabManager.OnVanillaPrefabsAvailable += WingItemRegistry.Register;
			WingCommands.Register();
			_harmony = new Harmony("darkspider.wingsoftheforgottengods");
			_harmony.PatchAll(typeof(WingsOfTheForgottenGodsPlugin).Assembly);
			ModLog.Info("Wings Of The Forgotten Gods 1.1.1 loaded. Test command: wfg.spawn.hraesvelgr");
		}

		private void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			WingFlightRuntime.Sync(localPlayer);
			WingFlightRuntime.FrameTick(localPlayer, Time.deltaTime);
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= WingItemRegistry.Register;
			WingFlightRuntime.Clear();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace WingsOfTheForgottenGods.Visuals
{
	internal static class NidhoggVfx
	{
		private const string ChargeAudioClip = "nidhogg_tentacle_charge";

		internal static void StartCast(GameObject wingVisual, Transform owner, float duration, float impactDelay, float elapsed)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)wingVisual != (Object)null)
			{
				NidhoggWingVeinVfx nidhoggWingVeinVfx = wingVisual.GetComponent<NidhoggWingVeinVfx>();
				if ((Object)(object)nidhoggWingVeinVfx == (Object)null)
				{
					nidhoggWingVeinVfx = wingVisual.AddComponent<NidhoggWingVeinVfx>();
				}
				nidhoggWingVeinVfx.Begin(duration, elapsed);
			}
			if ((Object)(object)owner != (Object)null)
			{
				WingAbilityAudio.PlayAt("nidhogg_tentacle_charge", owner.position, 0.5f, 2.5f, 24f, elapsed, 0.96f);
				NidhoggCastConduitVfx.Spawn(wingVisual, owner, duration, impactDelay, elapsed);
				NidhoggGroundPulseVfx.Spawn(owner, Mathf.Max(0f, impactDelay - elapsed));
			}
		}

		internal static Material CreateMaterial(string name)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("UI/Default");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = name
			};
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", new Color(0.52f, 0.006f, 0.012f, 0.94f));
			}
			return val2;
		}

		internal static Material CreateTendrilMaterial(string name)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Standard") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = name
			};
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.028f, 0.001f, 0.002f, 1f);
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", val3);
			}
			if (val2.HasProperty("_BaseColor"))
			{
				val2.SetColor("_BaseColor", val3);
			}
			if (val2.HasProperty("_EmissionColor"))
			{
				val2.EnableKeyword("_EMISSION");
				val2.SetColor("_EmissionColor", new Color(0.38f, 0.008f, 0.014f, 1f));
			}
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", 0.08f);
			}
			if (val2.HasProperty("_Glossiness"))
			{
				val2.SetFloat("_Glossiness", 0.68f);
			}
			return val2;
		}

		internal static Material CreateCrimsonLineMaterial(string name)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("UI/Default");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = name
			};
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", new Color(0.48f, 0.012f, 0.018f, 0.95f));
			}
			return val2;
		}

		internal static LineRenderer CreateLine(Transform parent, string name, Material material, float width)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			obj.useWorldSpace = true;
			((Renderer)obj).sharedMaterial = material;
			obj.widthMultiplier = width;
			obj.numCapVertices = 5;
			obj.numCornerVertices = 3;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			obj.startColor = new Color(0.62f, 0.008f, 0.014f, 0.94f);
			obj.endColor = new Color(0.025f, 0f, 0.002f, 0.82f);
			return obj;
		}
	}
	internal sealed class NidhoggWingVeinVfx : MonoBehaviour
	{
		private sealed class VeinPath
		{
			internal readonly Transform[] Bones;

			internal readonly Vector3[] Positions;

			internal readonly LineRenderer Vein;

			internal readonly LineRenderer Clot;

			internal readonly float Phase;

			internal VeinPath(Transform[] bones, LineRenderer vein, LineRenderer clot, float phase)
			{
				Bones = bones;
				Positions = (Vector3[])(object)new Vector3[bones.Length];
				Vein = vein;
				Clot = clot;
				Phase = phase;
			}
		}

		private readonly List<VeinPath> _paths = new List<VeinPath>(12);

		private Material _material;

		private float _startedAt;

		private float _duration;

		internal void Begin(float duration, float elapsed)
		{
			Clear();
			_duration = Mathf.Max(0.1f, duration);
			_startedAt = Time.time - Mathf.Clamp(elapsed, 0f, _duration);
			_material = NidhoggVfx.CreateMaterial("Nidhogg living veins");
			if ((Object)(object)_material == (Object)null)
			{
				return;
			}
			Transform val = FindSkeletonRoot();
			if (!((Object)(object)val == (Object)null))
			{
				List<Transform[]> list = new List<Transform[]>(12);
				List<Transform> working = new List<Transform>(32) { val };
				CollectLeafPaths(val, working, list);
				list.Sort((Transform[] left, Transform[] right) => PathLength(right).CompareTo(PathLength(left)));
				int num = Mathf.Min(10, list.Count);
				for (int num2 = 0; num2 < num; num2++)
				{
					LineRenderer vein = NidhoggVfx.CreateLine(((Component)this).transform, "Nidhogg vein " + num2, _material, 0.025f + (float)(num2 % 3) * 0.006f);
					LineRenderer val2 = NidhoggVfx.CreateLine(((Component)this).transform, "Nidhogg clot " + num2, _material, 0.095f + (float)(num2 % 2) * 0.025f);
					val2.positionCount = 2;
					_paths.Add(new VeinPath(list[num2], vein, val2, (float)num2 * 0.73f));
				}
			}
		}

		private void LateUpdate()
		{
			if (_duration <= 0f)
			{
				return;
			}
			float num = Time.time - _startedAt;
			if (num >= _duration)
			{
				Clear();
				Object.Destroy((Object)(object)this);
				return;
			}
			float num2 = Mathf.Clamp01(num / _duration);
			float growth = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num2 / 0.72f));
			float alpha = ((num2 < 0.76f) ? 1f : (1f - Mathf.InverseLerp(0.76f, 1f, num2)));
			for (int i = 0; i < _paths.Count; i++)
			{
				UpdatePath(_paths[i], growth, alpha, num);
			}
		}

		private void UpdatePath(VeinPath path, float growth, float alpha, float age)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_0060: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			int num = path.Bones.Length;
			if (num < 2)
			{
				return;
			}
			float num2 = growth * (float)(num - 1);
			int num3 = Mathf.Clamp(Mathf.FloorToInt(num2), 0, num - 1);
			float num4 = num2 - (float)num3;
			Vector3 val = path.Bones[num3].position;
			if (num3 + 1 < num)
			{
				val = Vector3.Lerp(val, path.Bones[num3 + 1].position, num4);
			}
			for (int i = 0; i < num; i++)
			{
				Vector3 val2 = ((i <= num3) ? path.Bones[i].position : val);
				Vector3 val3 = ((i + 1 >= num) ? (val2 - path.Bones[i - 1].position) : (path.Bones[i + 1].position - val2));
				Vector3 val4 = Vector3.Cross(val3, Vector3.up);
				if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
				{
					val4 = ((Component)this).transform.right;
				}
				else
				{
					((Vector3)(ref val4)).Normalize();
				}
				float num5 = Mathf.Sin(age * 15f + (float)i * 1.17f + path.Phase) * 0.018f;
				path.Positions[i] = val2 + val4 * num5;
			}
			path.Vein.positionCount = num;
			path.Vein.SetPositions(path.Positions);
			Color startColor = default(Color);
			((Color)(ref startColor))..ctor(0.68f, 0.006f, 0.012f, 0.94f * alpha);
			Color endColor = default(Color);
			((Color)(ref endColor))..ctor(0.025f, 0f, 0.002f, 0.84f * alpha);
			path.Vein.startColor = startColor;
			path.Vein.endColor = endColor;
			float num6 = Mathf.Clamp01(growth * 1.1f - path.Phase % 0.31f);
			Vector3 val5 = Sample(path.Bones, num6);
			Vector3 val6 = Sample(path.Bones, Mathf.Min(1f, num6 + 0.012f));
			path.Clot.SetPosition(0, val5);
			path.Clot.SetPosition(1, val6);
			float num7 = alpha * Mathf.Sin(num6 * (float)Math.PI);
			Color val7 = default(Color);
			((Color)(ref val7))..ctor(0.92f, 0.012f, 0.018f, Mathf.Clamp01(num7));
			path.Clot.startColor = val7;
			path.Clot.endColor = val7;
		}

		private Transform FindSkeletonRoot()
		{
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (val.childCount == 2 && CountDescendants(val) > 100)
				{
					return val;
				}
			}
			return null;
		}

		private static int CountDescendants(Transform root)
		{
			int num = 1;
			for (int i = 0; i < root.childCount; i++)
			{
				num += CountDescendants(root.GetChild(i));
			}
			return num;
		}

		private static void CollectLeafPaths(Transform current, List<Transform> working, List<Transform[]> output)
		{
			if (current.childCount == 0)
			{
				output.Add(working.ToArray());
				return;
			}
			for (int i = 0; i < current.childCount; i++)
			{
				Transform child = current.GetChild(i);
				working.Add(child);
				CollectLeafPaths(child, working, output);
				working.RemoveAt(working.Count - 1);
			}
		}

		private static float PathLength(Transform[] path)
		{
			//IL_0010: 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)
			float num = 0f;
			for (int i = 1; i < path.Length; i++)
			{
				num += Vector3.Distance(path[i - 1].position, path[i].position);
			}
			return num;
		}

		private static Vector3 Sample(Transform[] path, float t)
		{
			//IL_0004: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (path.Length == 0)
			{
				return Vector3.zero;
			}
			if (path.Length == 1)
			{
				return path[0].position;
			}
			float num = Mathf.Clamp01(t) * (float)(path.Length - 1);
			int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, path.Length - 2);
			return Vector3.Lerp(path[num2].position, path[num2 + 1].position, num - (float)num2);
		}

		private void Clear()
		{
			for (int i = 0; i < _paths.Count; i++)
			{
				if ((Object)(object)_paths[i].Vein != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_paths[i].Vein).gameObject);
				}
				if ((Object)(object)_paths[i].Clot != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_paths[i].Clot).gameObject);
				}
			}
			_paths.Clear();
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
			_material = null;
			_duration = 0f;
		}
	}
	internal sealed class NidhoggCastConduitVfx : MonoBehaviour
	{
		private const int TubeCount = 6;

		private const int PointCount = 10;

		private readonly NidhoggTubeRenderer[] _tubes = new NidhoggTubeRenderer[6];

		private readonly Vector3[][] _points = new Vector3[6][];

		private readonly Transform[] _clots = (Transform[])(object)new Transform[6];

		private Transform _owner;

		private Transform _leftWing;

		private Transform _rightWing;

		private Transform _chest;

		private Transform _rightHand;

		private Material _material;

		private Light _glow;

		private float _startedAt;

		private float _duration;

		private float _impactDelay;

		private Vector3 _groundPoint;

		internal static void Spawn(GameObject wingVisual, Transform owner, float duration, float impactDelay, float elapsed)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)owner == (Object)null))
			{
				GameObject val = new GameObject("Nidhogg body conduit");
				val.transform.SetParent(owner, false);
				val.AddComponent<NidhoggCastConduitVfx>().Initialize(wingVisual, owner, duration, impactDelay, elapsed);
			}
		}

		private void Initialize(GameObject wingVisual, Transform owner, float duration, float impactDelay, float elapsed)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			_owner = owner;
			_duration = Mathf.Max(0.1f, duration);
			_impactDelay = Mathf.Clamp(impactDelay, 0.1f, _duration);
			_startedAt = Time.time - Mathf.Clamp(elapsed, 0f, _duration);
			ResolveWingRoots(wingVisual);
			ResolveHumanBones(owner);
			_groundPoint = owner.position + owner.forward * 0.42f + owner.up * 0.035f;
			_material = NidhoggVfx.CreateTendrilMaterial("Nidhogg body conduit");
			if ((Object)(object)_material == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			for (int i = 0; i < 6; i++)
			{
				GameObject val = new GameObject("Body conduit " + i);
				val.transform.SetParent(((Component)this).transform, false);
				_tubes[i] = val.AddComponent<NidhoggTubeRenderer>();
				_points[i] = (Vector3[])(object)new Vector3[10];
				_tubes[i].Initialize(_material, 10, 9);
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)val2).name = "Body conduit clot " + i;
				val2.transform.SetParent(((Component)this).transform, false);
				Collider component = val2.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Renderer component2 = val2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.sharedMaterial = _material;
					component2.shadowCastingMode = (ShadowCastingMode)1;
				}
				_clots[i] = val2.transform;
				_clots[i].localScale = Vector3.zero;
			}
			GameObject val3 = new GameObject("Nidhogg conduit glow");
			val3.transform.SetParent(((Component)this).transform, false);
			_glow = val3.AddComponent<Light>();
			_glow.type = (LightType)2;
			_glow.color = new Color(0.78f, 0.008f, 0.012f, 1f);
			_glow.range = 4.2f;
			_glow.shadows = (LightShadows)0;
			_glow.intensity = 0f;
		}

		private void LateUpdate()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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)
			//IL_00dd: 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_00a5: 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_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_00bb: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: 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_020e: 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_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: 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_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: 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_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_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: 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_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_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time - _startedAt;
			if ((Object)(object)_owner == (Object)null || num >= _duration)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Vector3 up = _owner.up;
			Vector3 right = _owner.right;
			Vector3 forward = _owner.forward;
			Vector3 val = (((Object)(object)_chest != (Object)null) ? _chest.position : (_owner.position + up * 1.28f));
			Vector3 val2 = (((Object)(object)_rightHand != (Object)null) ? _rightHand.position : (_owner.position + forward * 0.48f + up * 0.2f + right * 0.22f));
			if (num < _impactDelay * 0.45f)
			{
				_groundPoint = _owner.position + forward * 0.42f + up * 0.035f;
			}
			float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / Mathf.Max(0.1f, _impactDelay * 0.82f)));
			float num3 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(_impactDelay - 0.1f, _impactDelay + 0.12f, num));
			float num4 = ((num <= _impactDelay + 0.28f) ? 1f : (1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(_impactDelay + 0.28f, _duration, num))));
			float num5 = num2 * num4;
			for (int i = 0; i < 6; i++)
			{
				float num6 = ((i % 2 == 0) ? (-1f) : 1f);
				Transform val3 = ((num6 < 0f) ? _leftWing : _rightWing);
				Vector3 val4 = (((Object)(object)val3 != (Object)null) ? val3.position : (val - forward * 0.28f + right * num6 * 0.62f));
				float num7 = (float)i * 1.37f;
				Vector3[] array = _points[i];
				for (int j = 0; j < 10; j++)
				{
					float num8 = (float)j / 9f;
					Vector3 val5;
					if (num8 < 0.43f)
					{
						float num9 = num8 / 0.43f;
						val5 = Vector3.Lerp(val4, val, num9);
						val5 -= forward * Mathf.Sin(num9 * (float)Math.PI) * (0.18f + (float)i * 0.008f);
					}
					else if (num8 < 0.76f)
					{
						float num10 = (num8 - 0.43f) / 0.33f;
						val5 = Vector3.Lerp(val, val2, num10);
					}
					else
					{
						float num11 = (num8 - 0.76f) / 0.24f;
						Vector3 val6 = Vector3.Lerp(val2, _groundPoint, num11);
						val5 = Vector3.Lerp(val2, val6, num3);
					}
					float num12 = Mathf.Sin(num * 15f + (float)j * 1.21f + num7) * 0.025f * num5;
					float num13 = Mathf.Sin(num * 7.4f + (float)j * 0.83f - num7) * 0.018f * num5;
					array[j] = val5 + right * num12 + up * num13;
				}
				float num14 = 0.78f + 0.22f * Mathf.Sin(num * 18f + num7);
				_tubes[i].UpdateTube(array, (0.034f + (float)(i % 3) * 0.008f) * num5 * num14, num * 15f + num7);
				Transform val7 = _clots[i];
				if ((Object)(object)val7 != (Object)null)
				{
					float num15 = Mathf.Clamp01(num2 * 1.18f - (float)i * 0.035f);
					if (num3 > 0.05f)
					{
						num15 = Mathf.Lerp(num15, 1f, num3);
					}
					val7.position = Sample(array, num15);
					float num16 = (0.1f + (float)(i % 2) * 0.025f) * num5 * num14;
					val7.localScale = Vector3.one * num16;
				}
			}
			((Component)_glow).transform.position = Vector3.Lerp(val, val2, num3 * 0.65f);
			_glow.intensity = num5 * (1.05f + 0.4f * Mathf.Sin(num * 17f));
		}

		private void ResolveWingRoots(GameObject wingVisual)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)wingVisual == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren = wingVisual.GetComponentsInChildren<Transform>(true);
			Transform val = null;
			foreach (Transform val2 in componentsInChildren)
			{
				if (val2.childCount == 2 && CountDescendants(val2) > 100)
				{
					val = val2;
					break;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				Transform child = val.GetChild(0);
				Transform child2 = val.GetChild(1);
				float num = Vector3.Dot(child.position - _owner.position, _owner.right);
				float num2 = Vector3.Dot(child2.position - _owner.position, _owner.right);
				if (num <= num2)
				{
					_leftWing = child;
					_rightWing = child2;
				}
				else
				{
					_leftWing = child2;
					_rightWing = child;
				}
			}
		}

		private void ResolveHumanBones(Transform owner)
		{
			Animator[] componentsInChildren = ((Component)owner).GetComponentsInChildren<Animator>(true);
			foreach (Animator val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val.isHuman)
				{
					_chest = val.GetBoneTransform((HumanBodyBones)8) ?? val.GetBoneTransform((HumanBodyBones)7);
					_rightHand = val.GetBoneTransform((HumanBodyBones)18);
					break;
				}
			}
		}

		private static int CountDescendants(Transform root)
		{
			int num = 1;
			for (int i = 0; i < root.childCount; i++)
			{
				num += CountDescendants(root.GetChild(i));
			}
			return num;
		}

		private static Vector3 Sample(Vector3[] points, float t)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(t) * (float)(points.Length - 1);
			int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, points.Length - 2);
			return Vector3.Lerp(points[num2], points[num2 + 1], num - (float)num2);
		}

		private void OnDestroy()
		{
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
		}
	}
	internal sealed class NidhoggGroundPulseVfx : MonoBehaviour
	{
		private const float WaveDuration = 0.62f;

		private const float FadeDuration = 0.8f;

		private const float Radius = 20f;

		private const string EruptAudioClip = "nidhogg_tentacle_erupt";

		private Transform _follow;

		private float _activateAt;

		private float _startedAt = -1f;

		private Material _ringMaterial;

		private Material _tendrilMaterial;

		private LineRenderer _ring;

		private LineRenderer _ringGlow;

		private Light _impactGlow;

		private readonly NidhoggTubeRenderer[] _tendrils = new NidhoggTubeRenderer[12];

		private readonly Transform[] _clots = (Transform[])(object)new Transform[12];

		private readonly Vector3[] _ringPoints = (Vector3[])(object)new Vector3[65];

		private readonly Vector3[][] _tendrilPoints = new Vector3[12][];

		private Vector3 _origin;

		internal static void Spawn(Transform follow, float delay)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new GameObject("Nidhogg ground pulse").AddComponent<NidhoggGroundPulseVfx>().Initialize(follow, delay);
		}

		private void Initialize(Transform follow, float delay)
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			_follow = follow;
			_activateAt = Time.time + Mathf.Max(0f, delay);
			_ringMaterial = NidhoggVfx.CreateCrimsonLineMaterial("Nidhogg crimson ground ring");
			_tendrilMaterial = NidhoggVfx.CreateTendrilMaterial("Nidhogg ground tendrils");
			if ((Object)(object)_ringMaterial == (Object)null || (Object)(object)_tendrilMaterial == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			_ring = NidhoggVfx.CreateLine(((Component)this).transform, "Dark binding wave", _ringMaterial, 0.14f);
			_ring.loop = true;
			_ring.positionCount = _ringPoints.Length;
			_ringGlow = NidhoggVfx.CreateLine(((Component)this).transform, "Crimson binding wave glow", _ringMaterial, 0.46f);
			_ringGlow.loop = true;
			_ringGlow.positionCount = _ringPoints.Length;
			_impactGlow = ((Component)this).gameObject.AddComponent<Light>();
			_impactGlow.type = (LightType)2;
			_impactGlow.color = new Color(0.85f, 0.008f, 0.012f, 1f);
			_impactGlow.range = 7.5f;
			_impactGlow.shadows = (LightShadows)0;
			_impactGlow.intensity = 0f;
			for (int i = 0; i < _tendrils.Length; i++)
			{
				GameObject val = new GameObject("Ground tendril " + i);
				val.transform.SetParent(((Component)this).transform, false);
				_tendrils[i] = val.AddComponent<NidhoggTubeRenderer>();
				_tendrilPoints[i] = (Vector3[])(object)new Vector3[10];
				_tendrils[i].Initialize(_tendrilMaterial, _tendrilPoints[i].Length, 8);
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)val2).name = "Ground clot " + i;
				val2.transform.SetParent(((Component)this).transform, false);
				Collider component = val2.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Renderer component2 = val2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.sharedMaterial = _tendrilMaterial;
					component2.shadowCastingMode = (ShadowCastingMode)1;
				}
				_clots[i] = val2.transform;
				_clots[i].localScale = Vector3.zero;
			}
			SetAlpha(0f);
		}

		private void Update()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _activateAt)
			{
				return;
			}
			if (_startedAt < 0f)
			{
				_startedAt = Time.time;
				_origin = (((Object)(object)_follow != (Object)null) ? _follow.position : ((Component)this).transform.position);
				_origin.y += 0.08f;
				((Component)this).transform.position = _origin;
				WingAbilityAudio.PlayAt("nidhogg_tentacle_erupt", _origin, 0.7f, 3f, 28f, 0f, 0.94f);
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					GameCamera.instance.AddShake(_origin, 26f, 1.15f, false);
				}
			}
			float num = Time.time - _startedAt;
			if (num >= 1.4200001f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float wave = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 0.62f));
			float num2 = ((num <= 0.62f) ? 1f : (1f - Mathf.InverseLerp(0.62f, 1.4200001f, num)));
			num2 *= Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 0.12f));
			UpdateRing(wave, num);
			UpdateTendrils(wave, num2, num);
			SetAlpha(num2);
			if ((Object)(object)_impactGlow != (Object)null)
			{
				_impactGlow.intensity = num2 * (1.3f + 0.45f * Mathf.Sin(num * 17f));
			}
		}

		private void UpdateRing(float wave, float age)
		{
			//IL_0066: 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)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Lerp(0.4f, 20f, wave);
			for (int i = 0; i < _ringPoints.Length; i++)
			{
				float num2 = (float)i / (float)(_ringPoints.Length - 1) * (float)Math.PI * 2f;
				float num3 = Mathf.Sin(num2 * 7f + age * 11f) * Mathf.Lerp(0.05f, 0.38f, wave);
				float num4 = num + num3;
				_ringPoints[i] = _origin + new Vector3(Mathf.Cos(num2) * num4, Mathf.Sin(num2 * 5f + age * 8f) * 0.06f, Mathf.Sin(num2) * num4);
			}
			_ring.SetPositions(_ringPoints);
			_ringGlow.SetPositions(_ringPoints);
		}

		private void UpdateTendrils(float wave, float alpha, float age)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _tendrils.Length; i++)
			{
				float num = (float)i / (float)_tendrils.Length * (float)Math.PI * 2f + Mathf.Sin(age * 2.4f + (float)i * 1.71f) * 0.09f;
				Vector3[] array = _tendrilPoints[i];
				for (int j = 0; j < array.Length; j++)
				{
					float num2 = (float)j / (float)(array.Length - 1);
					float num3 = 20f * wave * num2;
					float num4 = Mathf.Sin(age * (5f + (float)i * 0.11f) + (float)j * 1.07f + (float)i * 1.33f) * (0.05f + num2 * 0.2f) + Mathf.Sin(age * 2.1f + (float)j * 0.51f - (float)i) * 0.055f * num2;
					float num5 = num + num4;
					array[j] = _origin + new Vector3(Mathf.Cos(num5) * num3, 0.025f + Mathf.Sin((float)j * 1.42f + age * 7.5f + (float)i * 0.73f) * 0.075f * num2, Mathf.Sin(num5) * num3);
				}
				float num6 = 0.82f + 0.18f * Mathf.Sin(age * 10f + (float)i * 0.91f);
				float radius = (0.06f + (float)(i % 3) * 0.012f) * alpha * num6;
				_tendrils[i].UpdateTube(array, radius, age * 13f + (float)i * 0.77f);
				Transform val = _clots[i];
				if ((Object)(object)val != (Object)null)
				{
					float t = Mathf.Clamp01(wave * 1.12f - (float)(i % 4) * 0.028f);
					val.position = Sample(array, t);
					float num7 = (0.13f + 0.025f * Mathf.Sin(age * 14f + (float)i)) * alpha;
					val.localScale = Vector3.one * num7;
				}
			}
		}

		private static Vector3 Sample(Vector3[] points, float t)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(t) * (float)(points.Length - 1);
			int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, points.Length - 2);
			return Vector3.Lerp(points[num2], points[num2 + 1], num - (float)num2);
		}

		private void SetAlpha(float alpha)
		{
			//IL_004e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			Color startColor = default(Color);
			((Color)(ref startColor))..ctor(0.58f, 0.012f, 0.018f, 0.9f * alpha);
			Color endColor = default(Color);
			((Color)(ref endColor))..ctor(0.07f, 0.001f, 0.002f, 0.62f * alpha);
			if ((Object)(object)_ring != (Object)null)
			{
				_ring.startColor = startColor;
				_ring.endColor = endColor;
			}
			if ((Object)(object)_ringGlow != (Object)null)
			{
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.006f, 0.012f, 0.24f * alpha);
				_ringGlow.startColor = val;
				_ringGlow.endColor = val;
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_ringMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_ringMaterial);
			}
			if ((Object)(object)_tendrilMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_tendrilMaterial);
			}
		}
	}
	internal sealed class NidhoggTubeRenderer : MonoBehaviour
	{
		private Mesh _mesh;

		private Vector3[] _vertices;

		private Vector3[] _normals;

		private int _pointCount;

		private int _radialSegments;

		internal void Initialize(Material material, int pointCount, int radialSegments)
		{
			//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_00dd: Expected O, but got Unknown
			_pointCount = pointCount;
			_radialSegments = radialSegments;
			_vertices = (Vector3[])(object)new Vector3[pointCount * radialSegments];
			_normals = (Vector3[])(object)new Vector3[_vertices.Length];
			int[] array = new int[(pointCount - 1) * radialSegments * 6];
			int num = 0;
			for (int i = 0; i < pointCount - 1; i++)
			{
				for (int j = 0; j < radialSegments; j++)
				{
					int num2 = (j + 1) % radialSegments;
					int num3 = i * radialSegments + j;
					int num4 = i * radialSegments + num2;
					int num5 = (i + 1) * radialSegments + j;
					int num6 = (i + 1) * radialSegments + num2;
					array[num++] = num3;
					array[num++] = num5;
					array[num++] = num4;
					array[num++] = num4;
					array[num++] = num5;
					array[num++] = num6;
				}
			}
			_mesh = new Mesh
			{
				name = ((Object)((Component)this).gameObject).name + " mesh"
			};
			_mesh.MarkDynamic();
			_mesh.vertices = _vertices;
			_mesh.normals = _normals;
			_mesh.triangles = array;
			((Component)this).gameObject.AddComponent<MeshFilter>().sharedMesh = _mesh;
			MeshRenderer obj = ((Component)this).gameObject.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
			((Renderer)obj).receiveShadows = true;
		}

		internal void UpdateTube(Vector3[] worldPoints, float radius, float pulsePhase)
		{
			//IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_mesh == (Object)null || worldPoints == null || worldPoints.Length != _pointCount)
			{
				return;
			}
			for (int i = 0; i < _pointCount; i++)
			{
				Vector3 val = ((i == 0) ? (worldPoints[1] - worldPoints[0]) : ((i != _pointCount - 1) ? (worldPoints[i + 1] - worldPoints[i - 1]) : (worldPoints[i] - worldPoints[i - 1])));
				if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
				{
					val = Vector3.up;
				}
				((Vector3)(ref val)).Normalize();
				Vector3 val2 = ((Mathf.Abs(Vector3.Dot(val, Vector3.up)) > 0.88f) ? Vector3.forward : Vector3.up);
				Vector3 val3 = Vector3.Cross(val, val2);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				val3 = Vector3.Cross(val, normalized);
				Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
				float num = (float)i / (float)(_pointCount - 1);
				float num2 = radius * (0.78f + 0.22f * Mathf.Sin(pulsePhase + (float)i * 1.41f)) * Mathf.Lerp(1.05f, 0.58f, num);
				for (int j = 0; j < _radialSegments; j++)
				{
					float num3 = (float)j / (float)_radialSegments * (float)Math.PI * 2f;
					Vector3 val4 = normalized * Mathf.Cos(num3) + normalized2 * Mathf.Sin(num3);
					int num4 = i * _radialSegments + j;
					_vertices[num4] = ((Component)this).transform.InverseTransformPoint(worldPoints[i] + val4 * num2);
					Vector3[] normals = _normals;
					val3 = ((Component)this).transform.InverseTransformDirection(val4);
					normals[num4] = ((Vector3)(ref val3)).normalized;
				}
			}
			_mesh.vertices = _vertices;
			_mesh.normals = _normals;
			_mesh.RecalculateBounds();
		}

		private void OnDestroy()
		{
			if ((Object)(object)_mesh != (Object)null)
			{
				Object.Destroy((Object)(object)_mesh);
			}
			_mesh = null;
		}
	}
	internal sealed class NidhoggBindVfx : MonoBehaviour
	{
		private const string HoldAudioClip = "nidhogg_tentacle_hold";

		private const int MaximumAudibleLoops = 4;

		private static int _activeAudioLoops;

		private readonly NidhoggTubeRenderer[] _tubes = new NidhoggTubeRenderer[9];

		private readonly Transform[] _clots = (Transform[])(object)new Transform[9];

		private readonly Vector3[][] _points = new Vector3[9][];

		private Character _target;

		private Material _material;

		private float _startedAt;

		private float _duration;

		private Light _glow;

		private AudioSource _holdAudio;

		private bool _ownsAudioSlot;

		internal static NidhoggBindVfx Attach(Character target, float duration)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				return null;
			}
			GameObject val = new GameObject("Nidhogg binding tendrils");
			val.transform.SetParent(((Component)target).transform, false);
			NidhoggBindVfx nidhoggBindVfx = val.AddComponent<NidhoggBindVfx>();
			nidhoggBindVfx.Initialize(target, duration);
			return nidhoggBindVfx;
		}

		private void Initialize(Character target, float duration)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			_target = target;
			_duration = Mathf.Max(0.1f, duration);
			_startedAt = Time.time;
			_material = NidhoggVfx.CreateTendrilMaterial("Nidhogg binding");
			if ((Object)(object)_material == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			_glow = ((Component)this).gameObject.AddComponent<Light>();
			_glow.type = (LightType)2;
			_glow.color = new Color(0.82f, 0.006f, 0.012f, 1f);
			_glow.range = Mathf.Max(2.8f, target.GetRadius() * 4.2f);
			_glow.shadows = (LightShadows)0;
			_glow.intensity = 0f;
			if (_activeAudioLoops < 4)
			{
				float pitch = 0.94f + (float)(((Object)target).GetInstanceID() & 7) * 0.01f;
				float startTime = (float)(((Object)target).GetInstanceID() & 0xF) * 0.31f;
				_holdAudio = WingAbilityAudio.PlayLoopOn(((Component)this).gameObject, "nidhogg_tentacle_hold", 0.15f, 1.5f, 17f, startTime, pitch);
				if ((Object)(object)_holdAudio != (Object)null)
				{
					_activeAudioLoops++;
					_ownsAudioSlot = true;
				}
			}
			for (int i = 0; i < _tubes.Length; i++)
			{
				GameObject val = new GameObject("Binding tendril " + i);
				val.transform.SetParent(((Component)this).transform, false);
				_tubes[i] = val.AddComponent<NidhoggTubeRenderer>();
				_points[i] = (Vector3[])(object)new Vector3[10];
				_tubes[i].Initialize(_material, _points[i].Length, 10);
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)val2).name = "Living clot " + i;
				val2.transform.SetParent(((Component)this).transform, false);
				Collider component = val2.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Renderer component2 = val2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.sharedMaterial = _material;
					component2.shadowCastingMode = (ShadowCastingMode)1;
				}
				_clots[i] = val2.transform;
				_clots[i].localScale = Vector3.zero;
			}
		}

		private void LateUpdate()
		{
			//IL_00f7: 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_0249: 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_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_target == (Object)null || Time.time - _startedAt >= _duration)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float num = Time.time - _startedAt;
			float num2 = Mathf.Clamp01(num / _duration);
			float num3 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 0.28f));
			float num4 = ((num2 < 0.84f) ? 1f : (1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.84f, 1f, num2))));
			float num5 = num3 * num4;
			if ((Object)(object)_glow != (Object)null)
			{
				_glow.intensity = num5 * (0.9f + 0.32f * Mathf.Sin(num * 13f));
			}
			float num6 = Mathf.Max(0.4f, _target.GetRadius() * 1.4f);
			float num7 = Mathf.Max(1.2f, _target.GetTopPoint().y - ((Component)_target).transform.position.y);
			for (int i = 0; i < _tubes.Length; i++)
			{
				float num8 = (float)i / (float)_tubes.Length * (float)Math.PI * 2f + Mathf.Sin(num * (1.7f + (float)i * 0.035f) + (float)i * 1.93f) * 0.24f;
				Vector3[] array = _points[i];
				for (int j = 0; j < array.Length; j++)
				{
					float num9 = (float)j / (float)(array.Length - 1);
					float num10 = num8 + num9 * (1.82f + Mathf.Sin(num * 3.1f + (float)i) * 0.32f) + Mathf.Sin(num * 6.2f + (float)i * 1.41f + (float)j * 0.78f) * 0.22f + Mathf.Sin(num * 2.25f - (float)i + (float)j * 0.39f) * 0.09f;
					float num11 = 0.88f + 0.12f * Mathf.Sin(num * 4.8f + (float)i * 0.84f + (float)j * 0.31f);
					float num12 = num6 * (1f - num9 * 0.56f) * num5 * num11;
					array[j] = ((Component)_target).transform.position + new Vector3(Mathf.Cos(num10) * num12, 0.04f + num7 * num9 * 0.82f + Mathf.Sin(num * 7.2f + (float)j * 1.16f + (float)i) * (0.045f + num9 * 0.075f) * num5, Mathf.Sin(num10) * num12);
				}
				float radius = (0.082f + (float)(i % 3) * 0.016f) * num5;
				_tubes[i].UpdateTube(array, radius, num * 13.5f + (float)i * 0.91f);
				Transform val = _clots[i];
				if ((Object)(object)val != (Object)null)
				{
					float t = Mathf.Repeat(num * 0.76f + (float)i * 0.137f, 1f);
					val.position = Sample(array, t);
					float num13 = 0.145f + 0.05f * Mathf.Sin(num * 14f + (float)i);
					val.localScale = Vector3.one * num13 * num5;
				}
			}
		}

		private static Vector3 Sample(Vector3[] points, float t)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(t) * (float)(points.Length - 1);
			int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, points.Length - 2);
			return Vector3.Lerp(points[num2], points[num2 + 1], num - (float)num2);
		}

		internal void StopNow()
		{
			if ((Object)(object)this != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void OnDestroy()
		{
			if (_ownsAudioSlot)
			{
				_ownsAudioSlot = false;
				_activeAudioLoops = Mathf.Max(0, _activeAudioLoops - 1);
			}
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
			}
		}
	}
	internal sealed class WingEquipmentDisplay : MonoBehaviour
	{
		private VisEquipment _equipment;

		private Player _owner;

		private WingVisualController _visual;

		private WingFlightState _state;

		private bool _powered;

		private int _lastCommand;

		private int _lastAnimation;

		private bool _animationPaused;

		private WingDefinition _definition;

		internal static void Sync(VisEquipment equipment, int shoulderHash)
		{
			if ((Object)(object)equipment == (Object)null)
			{
				return;
			}
			WingDefinition wingDefinition = WingCatalog.FindByItemHash(shoulderHash);
			WingEquipmentDisplay wingEquipmentDisplay = ((Component)equipment).GetComponent<WingEquipmentDisplay>();
			if (wingDefinition == null)
			{
				if ((Object)(object)wingEquipmentDisplay != (Object)null)
				{
					wingEquipmentDisplay.SetEquipped(equipped: false);
				}
				return;
			}
			if ((Object)(object)wingEquipmentDisplay == (Object)null)
			{
				wingEquipmentDisplay = ((Component)equipment).gameObject.AddComponent<WingEquipmentDisplay>();
			}
			wingEquipmentDisplay._equipment = equipment;
			if (wingEquipmentDisplay._definition != wingDefinition)
			{
				wingEquipmentDisplay.DestroyVisual();
				wingEquipmentDisplay._definition = wingDefinition;
			}
			wingEquipmentDisplay.SetEquipped(equipped: true);
		}

		private void SetEquipped(bool equipped)
		{
			if (!equipped)
			{
				DestroyVisual();
				Object.Destroy((Object)(object)this);
			}
			else
			{
				EnsureVisual();
			}
		}

		private void Update()
		{
			EnsureVisual();
			if (_visual == null)
			{
				return;
			}
			_visual.RefreshAnchor();
			if ((Object)(object)_owner == (Object)null || !WingNetworkState.TryRead(_owner, out var snapshot))
			{
				return;
			}
			if (snapshot.State != _state)
			{
				WingFlightState state = _state;
				_state = snapshot.State;
				_visual.SetState(state, _state, snapshot.WaterLaunch);
			}
			if (snapshot.Powered != _powered)
			{
				_powered = snapshot.Powered;
				_visual.SetPoweredTravel(_powered);
			}
			_visual.SetFlightAttitude(snapshot.Pitch, snapshot.Bank, _powered, Time.deltaTime);
			if (snapshot.AnimationValue != 0 && snapshot.AnimationValue != _lastAnimation)
			{
				_lastAnimation = snapshot.AnimationValue;
				_visual.ApplyNetworkAnimation(snapshot.Animation, WingNetworkState.AnimationElapsedSeconds(snapshot.AnimationStarted));
			}
			if (snapshot.AnimationPaused != _animationPaused)
			{
				_animationPaused = snapshot.AnimationPaused;
				_visual.ApplyNetworkAnimationPaused(_animationPaused);
			}
			if (snapshot.AnimationValue == 0 && snapshot.CommandValue != 0 && snapshot.CommandValue != _lastCommand)
			{
				_lastCommand = snapshot.CommandValue;
				if (snapshot.Command == WingNetworkState.VisualCommand.FlightFlap)
				{
					_visual.RequestFlightFlap();
				}
				else if (snapshot.Command == WingNetworkState.VisualCommand.LightFlightFlap)
				{
					_visual.RequestLightFlightFlap();
				}
			}
		}

		private void EnsureVisual()
		{
			if (_visual != null)
			{
				return;
			}
			_owner = (((Object)(object)_equipment != (Object)null) ? (_equipment.m_playerComponent ?? ((Component)_equipment).GetComponentInParent<Player>()) : ((Component)this).GetComponentInParent<Player>());
			if ((Object)(object)_owner == (Object)null)
			{
				return;
			}
			ZNetView component = ((Component)_owner).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
			{
				((Behaviour)this).enabled = false;
				return;
			}
			_visual = new WingVisualController();
			if (_definition == null || !_visual.Create(_owner, _definition))
			{
				_visual = null;
				return;
			}
			_state = WingFlightState.Grounded;
			_powered = false;
			if (WingNetworkState.TryRead(_owner, out var snapshot))
			{
				_lastCommand = snapshot.CommandValue;
			}
		}

		private void DestroyVisual()
		{
			_visual?.Destroy();
			_visual = null;
			_owner = null;
			_state = WingFlightState.Grounded;
			_powered = false;
			_lastCommand = 0;
			_lastAnimation = 0;
			_animationPaused = false;
		}

		private void OnDestroy()
		{
			DestroyVisual();
		}
	}
	internal static class WingRagdollVisual
	{
		internal static void EnsureNetworkDisplay(Ragdoll ragdoll)
		{
			if ((Object)(object)ragdoll != (Object)null && (Object)(object)((Component)ragdoll).GetComponent<RagdollWingNetworkDisplay>() == (Object)null)
			{
				((Component)ragdoll).gameObject.AddComponent<RagdollWingNetworkDisplay>().Initialize(ragdoll);
			}
		}

		internal static bool Attach(Ragdoll ragdoll, WingDefinition definition)
		{
			if ((Object)(object)ragdoll == (Object)null || definition == null)
			{
				return false;
			}
			GameObject val = WingAssetBundle.LoadPrefab(definition.VisualPrefab);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)ragdoll).transform);
			((Object)val2).name = definition.VisualPrefab + "_ragdoll";
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Animator componentInChildren = val2.GetComponentInChildren<Animator>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.Play("Wing_Folded_Idle", 0, 0f);
			}
			Transform val3 = ResolveChest(ragdoll);
			val2.AddComponent<RagdollWingFollower>().Initialize(((Component)ragdoll).transform, val3);
			Rigidbody body = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponentInParent<Rigidbody>() : null);
			val2.AddComponent<WingSecondaryMotion>().Initialize(((Component)ragdoll).transform, body, componentInChildren);
			return true;
		}

		private static Transform ResolveChest(Ragdoll ragdoll)
		{
			Animator[] componentsInChildren = ((Component)ragdoll).GetComponentsInChildren<Animator>(true);
			foreach (Animator val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val.isHuman)
				{
					Transform val2 = val.GetBoneTransform((HumanBodyBones)54) ?? val.GetBoneTransform((HumanBodyBones)8) ?? val.GetBoneTransform((HumanBodyBones)7);
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
			}
			string[] obj = new string[5] { "UpperChest", "Chest", "Spine2", "Spine1", "Spine" };
			Transform[] componentsInChildren2 = ((Component)ragdoll).GetComponentsInChildren<Transform>(true);
			string[] array = obj;
			foreach (string b in array)
			{
				Transform[] array2 = componentsInChildren2;
				foreach (Transform val3 in array2)
				{
					string text = ((Object)val3).name;
					int num = text.LastIndexOf(':');
					if (num >= 0)
					{
						text = text.Substring(num + 1);
					}
					if (string.Equals(text, b, StringComparison.OrdinalIgnoreCase))
					{
						return val3;
					}
				}
			}
			return ((Component)ragdoll).transform;
		}
	}
	internal sealed class RagdollWingNetworkDisplay : MonoBehaviour
	{
		private Ragdoll _ragdoll;

		private bool _attached;

		private float _giveUpAt;

		internal void Initialize(Ragdoll ragdoll)
		{
			_ragdoll = ragdoll;
			_giveUpAt = Time.time + 3f;
		}

		private void Update()
		{
			if (!_attached && !((Object)(object)_ragdoll == (Object)null))
			{
				if (WingNetworkState.TryReadRagdollEquipment(_ragdoll, out var definition))
				{
					_attached = WingRagdollVisual.Attach(_ragdoll, definition);
				}
				else if (Time.time >= _giveUpAt)
				{
					Object.Destroy((Object)(object)this);
				}
			}
		}
	}
	internal sealed class RagdollWingFollower : MonoBehaviour
	{
		private Transform _root;

		private Transform _anchor;

		private Quaternion _rootFrameInAnchor;

		internal void Initialize(Transform root, Transform anchor)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			_root = root;
			_anchor = (((Object)(object)anchor != (Object)null) ? anchor : root);
			_rootFrameInAnchor = Quaternion.Inverse(_anchor.rotation) * root.rotation;
		}

		private void LateUpdate()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)_anchor == (Object)null))
			{
				Quaternion val = _anchor.rotation * _rootFrameInAnchor;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(WingConfig.AttachRight.Value, WingConfig.AttachUp.Value, 0f - WingConfig.AttachBack.Value);
				((Component)this).transform.position = _anchor.position + val * val2;
				((Component)this).transform.rotation = val * Quaternion.Euler(WingConfig.AttachPitch.Value, WingConfig.AttachYaw.Value, WingConfig.AttachRoll.Value);
				((Component)this).transform.localScale = Vector3.one * Mathf.Max(0.001f, WingConfig.WingScale.Value);
			}
		}
	}
	internal sealed class WingVisualController
	{
		private const string Folded = "Wing_Folded_Idle";

		private const string Unfold = "Wing_Unfold";

		private const string Fold = "Wing_Fold";

		private const string JumpFlap = "Wing_Jump_Flap";

		private const string Takeoff = "Wing_Takeoff";

		private const string ClimbLoop = "Wing_Climb_Loop";

		private const string ClimbExit = "Wing_Climb_Exit";

		private const string Glide = "Wing_Glide";

		private const string GlideToFlight = "Wing_Glide_To_Flight";

		private const string FlightToGlide = "Wing_Flight_To_Glide";

		private const string FlightLoop = "Wing_Flight_Loop";

		private const string FlightFlap = "Wing_Flight_Flap";

		private const string FlightLightFlap = "Wing_Flight_Light_Flap";

		private const string GroundAttackRight = "Wing_Ground_Attack_R";

		private const string GroundAttackLeft = "Wing_Ground_Attack_L";

		private const string GlideAttackRight = "Wing_Glide_Attack_R";

		private const string GlideAttackLeft = "Wing_Glide_Attack_L";

		internal const float BladeAttackDuration = 1.2833333f;

		internal const float BladeAttackReleaseDuration = 0.8f;

		private const float BladeAttackHoldNormalizedTime = 29f / 76f;

		private const float NidhoggCastStartTime = 49f / 60f;

		internal const float NidhoggAnimationHoldAt = 0.78f;

		internal const float NidhoggAnimationResumeAt = 1.3f;

		internal const float NidhoggAnimationPlaybackSpeed = 0.72f;

		private Player _owner;

		private GameObject _instance;

		private Animator _animator;

		private WingFollower _follower;

		private WingPlayerFlightPose _playerPose;

		private NidhoggCastAnimationDriver _nidhoggCastDriver;

		private WingFlightState _state;

		private bool _poweredTravel;

		private bool _waterLaunch;

		private float _flightFlapStartedAt = -1f;

		private float _flightFlapDuration = 0.9f;

		private Transform[] _rightBladeLaunchBones;

		private Transform[] _leftBladeLaunchBones;

		private bool _bladeAttackActive;

		private bool _bladeAttackPaused;

		internal bool Create(Player owner, WingDefinition definition)
		{
			Destroy();
			GameObject val = WingAssetBundle.LoadPrefab(definition.VisualPrefab);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_owner = owner;
			_instance = Object.Instantiate<GameObject>(val, ((Component)owner).transform);
			((Object)_instance).name = definition.VisualPrefab + "_runtime";
			Collider[] componentsInChildren = _instance.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			_animator = _instance.GetComponentInChildren<Animator>(true);
			if ((Object)(object)_animator == (Object)null)
			{
				ModLog.Error("Wing prefab has no Animator: " + definition.VisualPrefab);
				Destroy();
				return false;
			}
			AnimationClip val2 = ((IEnumerable<AnimationClip>)_animator.runtimeAnimatorController.animationClips).FirstOrDefault((Func<AnimationClip, bool>)((AnimationClip clip) => ((Object)clip).name == "Wing_Flight_Flap"));
			_flightFlapDuration = (((Object)(object)val2 != (Object)null) ? Mathf.Max(0.1f, val2.length) : 0.9f);
			Animator val3 = ResolveBodyAnimator(owner);
			_playerPose = _instance.AddComponent<WingPlayerFlightPose>();
			_playerPose.Initialize(owner, val3, _animator);
			_nidhoggCastDriver = _instance.AddComponent<NidhoggCastAnimationDriver>();
			_follower = _instance.AddComponent<WingFollower>();
			_follower.SetAnchor(owner, ResolveChest(owner, val3), val3);
			_instance.AddComponent<WingSecondaryMotion>().Initialize(((Component)owner).transform, ((Component)owner).GetComponent<Rigidbody>(), _animator);
			WingAnimationEventReceiver wingAnimationEventReceiver = ((Component)_animator).gameObject.GetComponent<WingAnimationEventReceiver>();
			if ((Object)(object)wingAnimationEventReceiver == (Object)null)
			{
				wingAnimationEventReceiver = ((Component)_animator).gameObject.AddComponent<WingAnimationEventReceiver>();
			}
			wingAnimationEventReceiver.SetOwner(owner);
			CacheBladeLaunchBones();
			_animator.Play("Wing_Folded_Idle", 0, 0f);
			return true;
		}

		internal void SetState(WingFlightState previous, WingFlightState next, bool waterLaunch)
		{
			_state = next;
			_waterLaunch = waterLaunch;
			_playerPose?.SetState(next);
			if (next == WingFlightState.Grounded || next == WingFlightState.Takeoff)
			{
				_poweredTravel = false;
				_playerPose?.SetFlying(flying: false);
			}
			WingNetworkState.PublishFlags(_owner, _state, _waterLaunch, _poweredTravel);
			if (next != WingFlightState.Flight)
			{
				_flightFlapStartedAt = -1f;
			}
			if ((Object)(object)_animator == (Object)null)
			{
				return;
			}
			switch (next)
			{
			case WingFlightState.Grounded:
				Play(WingFlightRules.ShouldPlayGroundFold(previous) ? "Wing_Fold" : "Wing_Folded_Idle", 0.08f);
				break;
			case WingFlightState.Takeoff:
				Play(waterLaunch ? "Wing_Takeoff" : "Wing_Jump_Flap", 0.04f);
				break;
			case WingFlightState.Climb:
				if (_poweredTravel)
				{
					_flightFlapStartedAt = Time.time;
					Play("Wing_Flight_Flap", 0.08f);
				}
				else if (previous != WingFlightState.Takeoff)
				{
					Play("Wing_Climb_Loop", 0.1f);
				}
				break;
			case WingFlightState.Glide:
				switch (previous)
				{
				case WingFlightState.Grounded:
				case WingFlightState.Airborne:
					Play("Wing_Unfold", 0.22f);
					break;
				case WingFlightState.Takeoff:
				case WingFlightState.Climb:
					Play("Wing_Climb_Exit", 0.18f);
					break;
				case WingFlightState.Flight:
				case WingFlightState.Exhausted:
					Play("Wing_Flight_To_Glide", 0.1f);
					break;
				default:
					Play("Wing_Glide", 0.1f);
					break;
				}
				break;
			case WingFlightState.Flight:
				Play((previous == WingFlightState.Glide) ? "Wing_Glide_To_Flight" : "Wing_Flight_Loop", 0.1f);
				break;
			case WingFlightState.Exhausted:
				Play((previous == WingFlightState.Flight) ? "Wing_Flight_To_Glide" : "Wing_Glide", 0.1f);
				break;
			case WingFlightState.Airborne:
				break;
			}
		}

		internal void SetPoweredTravel(bool powered)
		{
			_playerPose?.SetFlying(powered);
			if (_poweredTravel == powered)
			{
				return;
			}
			_poweredTravel = powered;
			WingNetworkState.PublishFlags(_owner, _state, _waterLaunch, _poweredTravel);
			if (!((Object)(object)_animator == (Object)null) && _state != WingFlightState.Takeoff)
			{
				if (powered && _state == WingFlightState.Climb)
				{
					RequestFlightFlap();
				}
				else if (!powered && _state == WingFlightState.Climb)
				{
					Play("Wing_Climb_Loop", 0.12f);
				}
			}
		}

		internal void SetFlightAttitude(float pitch, float bank, bool powered, float dt)
		{
			float pitch2 = (powered ? pitch : 0f);
			float bank2 = (powered ? bank : 0f);
			_follower?.SetFlightAttitude(pitch2, bank2, powered);
			_playerPose?.SetFlightAttitude(pitch2, bank2);
			WingNetworkState.PublishAttitude(_owner, pitch2, bank2);
		}

		internal void RequestFlightFlap()
		{
			if ((Object)(object)_animator != (Object)null && (!(_flightFlapStartedAt >= 0f) || !(Time.time - _flightFlapStartedAt < _flightFlapDuration)))
			{
				WingNetworkState.PublishCommand(_owner, WingNetworkState.VisualCommand.FlightFlap);
				_flightFlapStartedAt = Time.time;
				Play("Wing_Flight_Flap", 0.08f);
			}
		}

		internal void RequestLightFlightFlap()
		{
			if ((Object)(object)_animator != (Object)null && _state == WingFlightState.Flight)
			{
				WingNetworkState.PublishCommand(_owner, WingNetworkState.VisualCommand.LightFlightFlap);
				Play("Wing_Flight_Light_Flap", 0.16f);
			}
		}

		internal void RequestBladeAttack(bool leftWing, bool airborne)
		{
			if (!((Object)(object)_animator == (Object)null))
			{
				_flightFlapStartedAt = -1f;
				string state = ((!airborne) ? (leftWing ? "Wing_Ground_Attack_L" : "Wing_Ground_Attack_R") : (leftWing ? "Wing_Glide_Attack_L" : "Wing_Glide_Attack_R"));
				Play(state, 0.06f);
				_playerPose?.StartTyrAttack(leftWing, airborne, 0f);
			}
		}

		internal void RequestNidhoggCast(float duration, float impactDelay)
		{
			if (!((Object)(object)_animator == (Object)null))
			{
				SetBladeAttackPaused(paused: false, publish: true);
				_bladeAttackActive = false;
				_flightFlapStartedAt = -1f;
				WingNetworkState.PublishAnimationPaused(_owner, paused: false);
				WingNetworkState.PublishAnimation(_owner, WingNetworkState.VisualAnimation.NidhoggCast);
				_animator.CrossFadeInFixedTime("Wing_Flight_Flap", 0.14f, 0, 49f / 60f);
				_nidhoggCastDriver?.Begin(_animator, duration, 0f);
				_playerPose?.StartNidhoggCast(duration, 0f);
				NidhoggVfx.StartCast(_instance, ((Object)(object)_owner != (Object)null) ? ((Component)_owner).transform : null, duration, impactDelay, 0f);
			}
		}

		internal void CompleteNidhoggCast()
		{
			if (!((Object)(object)_animator == (Object)null))
			{
				_nidhoggCastDriver?.StopNow();
				switch (_state)
				{
				case WingFlightState.Grounded:
				case WingFlightState.Airborne:
					Play("Wing_Folded_Idle", 0.24f);
					break;
				case WingFlightState.Glide:
					Play("Wing_Glide", 0.24f);
					break;
				case WingFlightState.Flight:
					Play("Wing_Flight_Loop", 0.22f);
					break;
				case WingFlightState.Climb:
					Play("Wing_Climb_Loop", 0.22f);
					break;
				default:
					SetState(_state, _state, _waterLaunch);
					break;
				}
			}
		}

		internal bool SetBladeAttackHeld(bool held)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			bool bladeAttackPaused = _bladeAttackPaused;
			if ((Object)(object)_animator == (Object)null || !_bladeAttackActive)
			{
				return bladeAttackPaused;
			}
			if (!held)
			{
				SetBladeAttackPaused(paused: false, publish: true);
				return bladeAttackPaused;
			}
			if (_bladeAttackPaused)
			{
				return true;
			}
			if (_animator.IsInTransition(0))
			{
				return false;
			}
			AnimatorStateInfo currentAnimatorStateInfo = _animator.GetCurrentAnimatorStateInfo(0);
			if (!IsBladeAttackState(currentAnimatorStateInfo))
			{
				return false;
			}
			if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime < 29f / 76f)
			{
				return false;
			}
			SetBladeAttackPaused(paused: true, publish: true);
			return true;
		}

		internal void CompleteBladeAttack()
		{
			SetBladeAttackPaused(paused: false, publish: true);
			_bladeAttackActive = false;
		}

		internal bool TryGetBladeLaunchPosition(bool leftWing, int index, int count, out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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)
			position = default(Vector3);
			Transform[] array = (leftWing ? _leftBladeLaunchBones : _rightBladeLaunchBones);
			if (array == null || array.Length == 0 || count <= 0 || index < 0 || index >= count)
			{
				return false;
			}
			int num = ((count == 1) ? (array.Length / 2) : Mathf.RoundToInt((float)index * ((float)array.Length - 1f) / ((float)count - 1f)));
			Transform val = array[Mathf.Clamp(num, 0, array.Length - 1)];
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			position = val.position;
			return true;
		}

		internal float GetLiftFactor()
		{
			//IL_0037: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_animator == (Object)null)
			{
				return 0f;
			}
			AnimatorStateInfo val = (_animator.IsInTransition(0) ? _animator.GetNextAnimatorStateInfo(0) : _animator.GetCurrentAnimatorStateInfo(0));
			float time = ((AnimatorStateInfo)(ref val)).normalizedTime - Mathf.Floor(((AnimatorStateInfo)(ref val)).normalizedTime);
			if (((AnimatorStateInfo)(ref val)).IsName("Wing_Jump_Flap") || ((AnimatorStateInfo)(ref val)).IsName("Wing_Takeoff"))
			{
				return Stroke(time, 0.225f, 0.6f);
			}
			if (((AnimatorStateInfo)(ref val)).IsName("Wing_Flight_Flap"))
			{
				return Stroke(time, 23f / 90f, 34f / 45f);
			}
			if (((AnimatorStateInfo)(ref val)).IsName("Wing_Climb_Loop"))
			{
				return Stroke(time, 4f / 15f, 23f / 30f);
			}
			return 0f;
		}

		internal bool TryGetClimbPhase(out float phase)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			phase = 0f;
			if ((Object)(object)_animator == (Object)null)
			{
				return false;
			}
			AnimatorStateInfo val = _animator.GetCurrentAnimatorStateInfo(0);
			if (!((AnimatorStateInfo)(ref val)).IsName("Wing_Climb_Loop") && _animator.IsInTransition(0))
			{
				AnimatorStateInfo nextAnimatorStateInfo = _animator.GetNextAnimatorStateInfo(0);
				if (((AnimatorStateInfo)(ref nextAnimatorStateInfo)).IsName("Wing_Climb_Loop"))
				{
					val = nextAnimatorStateInfo;
				}
			}
			if (!((AnimatorStateInfo)(ref val)).IsName("Wing_Climb_Loop"))
			{
				return false;
			}
			phase = Mathf.Repeat(((AnimatorStateInfo)(ref val)).normalizedTime, 1f);
			return true;
		}

		internal void RefreshAnchor()
		{
			if ((Object)(object)_follower != (Object)null && (Object)(object)_follower.Anchor == (Object)null)
			{
				Animator bodyAnimator = ResolveBodyAnimator(_owner);
				_follower.SetAnchor(_owner, ResolveChest(_owner, bodyAnimator), bodyAnimator);
			}
			if ((Object)(object)_animator != (Object)null && _poweredTravel && _flightFlapStartedAt >= 0f && Time.time - _flightFlapStartedAt >= _flightFlapDuration)
			{
				_flightFlapStartedAt = -1f;
				Play((_state == WingFlightState.Flight) ? "Wing_Flight_Loop" : "Wing_Climb_Loop", 0.1f);
			}
		}

		internal void Destroy()
		{
			SetBladeAttackPaused(paused: false, publish: true);
			if ((Object)(object)_instance != (Object)null)
			{
				Object.Destroy((Object)(object)_instance);
			}
			_owner = null;
			_instance = null;
			_animator = null;
			_follower = null;
			_playerPose = null;
			_nidhoggCastDriver = null;
			_state = WingFlightState.Grounded;
			_poweredTravel = false;
			_waterLaunch = false;
			_flightFlapStartedAt = -1f;
			_flightFlapDuration = 0.9f;
			_rightBladeLaunchBones = null;
			_leftBladeLaunchBones = null;
			_bladeAttackActive = false;
			_bladeAttackPaused = false;
		}

		private void Play(string state, float blend)
		{
			SetBladeAttackPaused(paused: false, publish: true);
			WingNetworkState.PublishAnimationPaused(_owner, paused: false);
			_bladeAttackActive = IsBladeAttackState(state);
			WingNetworkState.PublishAnimation(_owner, NetworkAnimationForState(state));
			_animator.CrossFadeInFixedTime(state, blend, 0, 0f);
		}

		internal void ApplyNetworkAnimation(WingNetworkState.VisualAnimation animation, float elapsed)
		{
			if ((Object)(object)_animator == (Object)null)
			{
				return;
			}
			string text = StateForNetworkAnimation(animation);
			if (!string.IsNullOrEmpty(text))
			{
				SetBladeAttackPaused(paused: false, publish: false);
				_bladeAttackActive = IsBladeAttackState(text);
				float num = ClipLength(text);
				float num2 = ((!IsLoopingState(text)) ? Mathf.Clamp(elapsed, 0f, Mathf.Max(0f, num - 0.001f)) : ((num > 0.001f) ? Mathf.Repeat(elapsed, num) : 0f));
				if (animation == WingNetworkState.VisualAnimation.NidhoggCast)
				{
					num2 = Mathf.Clamp(49f / 60f + NidhoggAnimationElapsed(elapsed), 0f, Mathf.Max(0f, num - 0.001f));
				}
				_animator.CrossFadeInFixedTime(text, 0.05f, 0, num2);
				if (_bladeAttackActive)
				{
					bool leftWing = animation == WingNetworkState.VisualAnimation.GroundAttackLeft || animation == WingNetworkState.VisualAnimation.GlideAttackLeft;
					bool airborne = animation == WingNetworkState.VisualAnimation.GlideAttackRight || animation == WingNetworkState.VisualAnimation.GlideAttackLeft;
					_playerPose?.StartTyrAttack(leftWing, airborne, num2);
				}
				else
				{
					_playerPose?.CancelTyrAttack();
				}
				if (animation == WingNetworkState.VisualAnimation.NidhoggCast)
				{
					_nidhoggCastDriver?.Begin(_animator, 2.2f, elapsed);
					_playerPose?.StartNidhoggCast(2.2f, elapsed);
					NidhoggVfx.StartCast(_instance, ((Object)(object)_owner != (Object)null) ? ((Component)_owner).transform : null, 2.2f, 1.12f, elapsed);
				}
				else if (text == "Wing_Flight_Flap")
				{
					_flightFlapStartedAt = Time.time - Mathf.Min(elapsed, _flightFlapDuration);
				}
			}
		}

		private static float NidhoggAnimationElapsed(float elapsed)
		{
			if (elapsed <= 0.78f)
			{
				return elapsed * 0.72f;
			}
			if (elapsed < 1.3f)
			{
				return 0.5616f;
			}
			return (0.78f + elapsed - 1.3f) * 0.72f;
		}

		internal void ApplyNetworkAnimationPaused(bool paused)
		{
			if (!((Object)(object)_animator == (Object)null) && _bladeAttackActive)
			{
				SetBladeAttackPaused(paused, publish: false);
			}
		}

		private void SetBladeAttackPaused(bool paused, bool publish)
		{
			if ((Object)(object)_animator != (Object)null)
			{
				_animator.speed = (paused ? 0f : 1f);
			}
			if (_bladeAttackPaused != paused)
			{
				_bladeAttackPaused = paused;
				if (publish)
				{
					WingNetworkState.PublishAnimationPaused(_owner, paused);
				}
			}
		}

		private static bool IsBladeAttackState(string state)
		{
			switch (state)
			{
			default:
				return state == "Wing_Glide_Attack_L";
			case "Wing_Ground_Attack_R":
			case "Wing_Ground_Attack_L":
			case "Wing_Glide_Attack_R":
				return true;
			}
		}

		private static bool IsBladeAttackState(AnimatorStateInfo state)
		{
			if (!((AnimatorStateInfo)(ref state)).IsName("Wing_Ground_Attack_R") && !((AnimatorStateInfo)(ref state)).IsName("Wing_Ground_Attack_L") && !((AnimatorStateInfo)(ref state)).IsName("Wing_Glide_Attack_R"))
			{
				return ((AnimatorStateInfo)(ref state)).IsName("Wing_Glide_Attack_L");
			}
			return true;
		}

		private float ClipLength(string state)
		{
			Animator animator = _animator;
			if ((Object)(object)((animator != null) ? animator.runtimeAnimatorController : null) == (Object)null)
			{
				return 0f;
			}
			AnimationClip[] animationClips = _animator.runtimeAnimatorController.animationClips;
			foreach (AnimationClip val in animationClips)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == state)
				{
					return val.length;
				}
			}
			return 0f;
		}

		private static bool IsLoopingState(string state)
		{
			switch (state)
			{
			default:
				return state == "Wing_Climb_Loop";
			case "Wing_Folded_Idle":
			case "Wing_Glide":
			case "Wing_Flight_Loop":
				return true;
			}
		}

		private static WingNetworkState.VisualAnimation NetworkAnimationForState(string state)
		{
			return state switch
			{
				"Wing_Folded_Idle" => WingNetworkState.VisualAnimation.Folded, 
				"Wing_Unfold" => WingNetworkState.VisualAnimation.Unfold, 
				"Wing_Fold" => WingNetworkState.VisualAnimation.Fold, 
				"Wing_Jump_Flap" => WingNetworkState.VisualAnimation.JumpFlap, 
				"Wing_Takeoff" => WingNetworkState.VisualAnimation.Takeoff, 
				"Wing_Climb_Loop" => WingNetworkState.VisualAnimation.ClimbLoop, 
				"Wing_Climb_Exit" => WingNetworkState.VisualAnimation.ClimbExit, 
				"Wing_Glide" => WingNetworkState.VisualAnimation.Glide, 
				"Wing_Glide_To_Flight" => WingNetworkState.VisualAnimation.GlideToFlight, 
				"Wing_Flight_To_Glide" => WingNetworkState.VisualAnimation.FlightToGlide, 
				"Wing_Flight_Loop" => WingNetworkState.VisualAnimation.FlightLoop, 
				"Wing_Flight_Flap" => WingNetworkState.VisualAnimation.FlightFlap, 
				"Wing_Flight_Light_Flap" => WingNetworkState.VisualAnimation.FlightLightFlap, 
				"Wing_Ground_Attack_R" => WingNetworkState.VisualAnimation.GroundAttackRight, 
				"Wing_Ground_Attack_L" => WingNetworkState.VisualAnimation.GroundAttackLeft, 
				"Wing_Glide_Attack_R" => WingNetworkState.VisualAnimation.GlideAttackRight, 
				"Wing_Glide_Attack_L" => WingNetworkState.VisualAnimation.GlideAttackLeft, 
				_ => WingNetworkState.VisualAnimation.None, 
			};
		}

		private static string StateForNetworkAnimation(WingNetworkState.VisualAnimation animation)
		{
			return animation switch
			{
				WingNetworkState.VisualAnimation.Folded => "Wing_Folded_Idle", 
				WingNetworkState.VisualAnimation.Unfold => "Wing_Unfold", 
				WingNetworkState.VisualAnimation.Fold => "Wing_Fold", 
				WingNetworkState.VisualAnimation.JumpFlap => "Wing_Jump_Flap", 
				WingNetworkState.VisualAnimation.Takeoff => "Wing_Takeoff", 
				WingNetworkState.VisualAnimation.ClimbLoop => "Wing_Climb_Loop", 
				WingNetworkState.VisualAnimation.ClimbExit => "Wing_Climb_Exit", 
				WingNetworkState.VisualAnimation.Glide => "Wing_Glide", 
				WingNetworkState.VisualAnimation.GlideToFlight => "Wing_Glide_To_Flight", 
				WingNetworkState.VisualAnimation.FlightToGlide => "Wing_Flight_To_Glide", 
				WingNetworkState.VisualAnimation.FlightLoop => "Wing_Flight_Loop", 
				WingNetworkState.VisualAnimation.FlightFlap => "Wing_Flight_Flap", 
				WingNetworkState.VisualAnimation.FlightLightFlap => "Wing_Flight_Light_Flap", 
				WingNetworkState.VisualAnimation.GroundAttackRight => "Wing_Ground_Attack_R", 
				WingNetworkState.VisualAnimation.GroundAttackLeft => "Wing_Ground_Attack_L", 
				WingNetworkState.VisualAnimation.GlideAttackRight => "Wing_Glide_Attack_R", 
				WingNetworkState.VisualAnimation.GlideAttackLeft => "Wing_Glide_Attack_L", 
				WingNetworkState.VisualAnimation.NidhoggCast => "Wing_Flight_Flap", 
				_ => null, 
			};
		}

		private void CacheBladeLaunchBones()
		{
			_rightBladeLaunchBones = (Transform[])(object)new Transform[14];
			_leftBladeLaunchBones = (Transform[])(object)new Transform[14];
			Transform[] componentsInChildren = _instance.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				for (int j = 101; j < 115; j++)
				{
					int num = j - 101;
					if (((Object)val).name == "bone_right." + j.ToString("000"))
					{
						_rightBladeLaunchBones[num] = val;
					}
					else if (((Object)val).name == "bone_left." + j.ToString("000"))
					{
						_leftBladeLaunchBones[num] = val;
					}
				}
			}
		}

		private static float Stroke(float time, float start, float end)
		{
			if (time <= start || time >= end)
			{
				return 0f;
			}
			return Mathf.Sin(Mathf.InverseLerp(start, end, time) * (float)Math.PI);
		}

		private static Animator ResolveBodyAnimator(Player player)
		{
			GameObject val = ((player != null) ? ((Character)player).GetVisual() : null);
			Animator[] array = (((Object)(object)val != (Object)null) ? val.GetComponentsInChildren<Animator>(true) : ((Component)player).GetComponentsInChildren<Animator>(true));
			foreach (Animator val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && val2.isHuman)
				{
					return val2;
				}
			}
			return null;
		}

		private static Transform ResolveChest(Player player, Animator bodyAnimator = null)
		{
			bodyAnimator = bodyAnimator ?? ResolveBodyAnimator(player);
			if ((Object)(object)bodyAnimator != (Object)null)
			{
				Transform val = bodyAnimator.GetBoneTransform((HumanBodyBones)54) ?? bodyAnimator.GetBoneTransform((HumanBodyBones)8) ?? bodyAnimator.GetBoneTransform((HumanBodyBones)7);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			GameObject val2 = ((player != null) ? ((Character)player).GetVisual() : null);
			Transform[] array = (((Object)(object)val2 != (Object)null) ? val2.GetComponentsInChildren<Transform>(true) : ((Component)player).GetComponentsInChildren<Transform>(true));
			string[] array2 = new string[5] { "UpperChest", "Chest", "Spine2", "Spine1", "Spine" };
			foreach (string b in array2)
			{
				Transform[] array3 = array;
				foreach (Transform val3 in array3)
				{
					string text = ((Object)val3).name;
					int num = text.LastIndexOf(':');
					if (num >= 0)
					{
						text = text.Substring(num + 1);
					}
					if (string.Equals(text, b, StringComparison.OrdinalIgnoreCase))
					{
						return val3;
					}
				}
			}
			return ((Component)player).transform;
		}
	}
	internal sealed class WingAnimationEventReceiver : MonoBehaviour
	{
		private Player _owner;

		internal void SetOwner(Player owner)
		{
			_owner = owner;
		}

		public void HW_WingImpulse(AnimationEvent animationEvent)
		{
			if (animationEvent != null)
			{
				WingFlightRuntime.OnAnimationImpulse(_owner, animationEvent.stringParameter, animationEvent.intParameter);
			}
		}

		public void HW_TyrBladeRelease(AnimationEvent animationEvent)
		{
			if (animationEvent != null)
			{
				WingFlightRuntime.OnBladeRelease(_owner, animationEvent.stringParameter);
			}
		}
	}
	internal sealed class NidhoggCastAnimationDriver : MonoBehaviour
	{
		private Animator _animator;

		private float _startedAt;

		private float _duration;

		private bool _active;

		internal void Begin(Animator animator, float duration, float elapsed)
		{
			StopNow();
			_animator = animator;
			_startedAt = Time.time - Mathf.Max(0f, elapsed);
			_duration = Mathf.Max(0.05f, duration);
			_active = (Object)(object)_animator != (Object)null;
			UpdateSpeed(Mathf.Max(0f, elapsed));
		}

		internal void StopNow()
		{
			if ((Object)(object)_animator != (Object)null)
			{
				_animator.speed = 1f;
			}
			_animator = null;
			_active = false;
		}

		private void Update()
		{
			if (_active && !((Object)(object)_animator == (Object)null))
			{
				float num = Time.time - _startedAt;
				if (num >= _duration)
				{
					StopNow();
				}
				else
				{
					UpdateSpeed(num);
				}
			}
		}

		private void UpdateSpeed(float elapsed)
		{
			bool flag = elapsed >= 0.78f && elapsed < 1.3f;
			if ((Object)(object)_animator != (Object)null)
			{
				_animator.speed = (flag ? 0f : 0.72f);
			}
		}

		private void OnDisable()
		{
			StopNow();
		}
	}
	[DefaultExecutionOrder(150)]
	internal sealed class WingPlayerFlightPose : MonoBehaviour
	{
		private sealed class BoneOffset
		{
			internal readonly Transform Bone;

			private Quaternion _beforeLocal;

			private Quaternion _appliedLocal;

			private bool _pending;

			private Vector3 _beforeLocalPosition;

			private Vector3 _appliedLocalPosition;

			private bool _positionPending;

			internal BoneOffset(Transform bone)
			{
				Bone = bone;
			}

			internal void Apply(Quaternion worldOffset)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Bone == (Object)null))
				{
					CaptureRotation();
					Bone.rotation = worldOffset * Bone.rotation;
					_appliedLocal = Bone.localRotation;
				}
			}

			internal void SetWorldRotation(Quaternion worldRotation)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Bone == (Object)null))
				{
					CaptureRotation();
					Bone.rotation = worldRotation;
					_appliedLocal = Bone.localRotation;
				}
			}

			internal void SetLocalRotation(Quaternion localRotation)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Bone == (Object)null))
				{
					CaptureRotation();
					Bone.localRotation = localRotation;
					_appliedLocal = Bone.localRotation;
				}
			}

			internal void ApplyWorldPositionOffset(Vector3 worldOffset)
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: 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_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: 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)
				if (!((Object)(object)Bone == (Object)null) && !((Object)(object)Bone.parent == (Object)null))
				{
					if (!_positionPending)
					{
						_beforeLocalPosition = Bone.localPosition;
						_positionPending = true;
					}
					Transform bone = Bone;
					bone.localPosition += Bone.parent.InverseTransformVector(worldOffset);
					_appliedLocalPosition = Bone.localPosition;
				}
			}

			private void CaptureRotation()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				if (!_pending)
				{
					_beforeLocal = Bone.localRotation;
					_pending = true;
				}
			}

			internal void Restore()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: 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_0060: 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_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Bone == (Object)null)
				{
					return;