Decompiled source of XiaoHeiDaGeHeJi v0.5.28

plugins/RiftSurvivor.dll

Decompiled 21 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using EntityStates;
using EntityStates.Engi.EngiMissilePainter;
using EntityStates.Engi.EngiWeapon;
using EntityStates.Mage.Weapon;
using KinematicCharacterController;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.CharacterAI;
using RoR2.ContentManagement;
using RoR2.Orbs;
using RoR2.Skills;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RiftSurvivor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.28.0")]
[assembly: AssemblyInformationalVersion("0.5.28+82b9b89f0a03e2d5443fc43e9b44b3159fdc549a")]
[assembly: AssemblyProduct("RiftSurvivor")]
[assembly: AssemblyTitle("RiftSurvivor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
namespace RiftSurvivor;

public sealed class CombatStatusHud : MonoBehaviour
{
	private static BuffDef stormClock;

	private static BuffDef replayClock;

	private static Font font;

	private CharacterBody body;

	private float stormEnds;

	private float replayEnds;

	private float nextPublish;

	private float nextDraw;

	private readonly Dictionary<SkillIcon, Text> badges = new Dictionary<SkillIcon, Text>();

	private readonly HashSet<SkillIcon> visibleIcons = new HashSet<SkillIcon>();

	private readonly List<SkillIcon> staleIcons = new List<SkillIcon>();

	internal static void Register()
	{
		stormClock = Clock("JieStormRemaining");
		replayClock = Clock("XiaoheiReplayRemaining");
		CharacterBody.onBodyStartGlobal += delegate(CharacterBody owner)
		{
			if (Object.op_Implicit((Object)(object)((Component)owner).GetComponent<JieSwords>()) || Object.op_Implicit((Object)(object)((Component)owner).GetComponent<XiaoheiCombat>()) || Object.op_Implicit((Object)(object)((Component)owner).GetComponent<CuiVitals>()) || Object.op_Implicit((Object)(object)((Component)owner).GetComponent<WeiVitals>()))
			{
				Ensure(owner);
			}
		};
	}

	private static BuffDef Clock(string name)
	{
		BuffDef obj = ScriptableObject.CreateInstance<BuffDef>();
		((Object)obj).name = name;
		obj.canStack = (obj.isHidden = (obj.ignoreGrowthNectar = true));
		if (!ContentAddition.AddBuffDef(obj))
		{
			throw new InvalidOperationException(name);
		}
		return obj;
	}

	private static CombatStatusHud Ensure(CharacterBody owner)
	{
		return ((Component)owner).GetComponent<CombatStatusHud>() ?? ((Component)owner).gameObject.AddComponent<CombatStatusHud>();
	}

	internal static void Storm(CharacterBody owner)
	{
		Ensure(owner).stormEnds = Time.fixedTime + 6f;
	}

	internal static void Replay(CharacterBody owner)
	{
		Ensure(owner).replayEnds = Time.fixedTime + 4f;
	}

	private void Awake()
	{
		body = ((Component)this).GetComponent<CharacterBody>();
	}

	private void FixedUpdate()
	{
		if (NetworkServer.active && !(Time.fixedTime < nextPublish) && Object.op_Implicit((Object)(object)body))
		{
			nextPublish = Time.fixedTime + 0.1f;
			bool flag = DownedRescue.IsUp(body);
			Publish(stormClock, flag ? stormEnds : 0f);
			Publish(replayClock, flag ? replayEnds : 0f);
		}
	}

	private void Publish(BuffDef buff, float ends)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Clamp(Mathf.CeilToInt((ends - Time.fixedTime) * 10f), 0, 60);
		if (body.GetBuffCount(buff) != num)
		{
			body.SetBuffCount(buff.buffIndex, num);
		}
	}

	private void LateUpdate()
	{
		if (!NetworkClient.active || !Object.op_Implicit((Object)(object)body) || Time.unscaledTime < nextDraw)
		{
			return;
		}
		nextDraw = Time.unscaledTime + 0.1f;
		visibleIcons.Clear();
		bool flag = Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive;
		foreach (HUD instances in HUD.instancesList)
		{
			if (!Object.op_Implicit((Object)(object)instances) || (Object)(object)instances.targetBodyObject != (Object)(object)((Component)this).gameObject || !flag)
			{
				continue;
			}
			SkillIcon[] componentsInChildren = ((Component)instances).GetComponentsInChildren<SkillIcon>(true);
			foreach (SkillIcon val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.targetSkill) || (Object)(object)val.targetSkill.characterBody != (Object)(object)body)
				{
					continue;
				}
				string text = Status(val.targetSkill);
				if (!string.IsNullOrEmpty(text))
				{
					if (!badges.TryGetValue(val, out var value) || !Object.op_Implicit((Object)(object)value))
					{
						value = (badges[val] = CreateBadge(val));
					}
					if (Object.op_Implicit((Object)(object)value))
					{
						value.text = text;
						visibleIcons.Add(val);
					}
				}
			}
		}
		staleIcons.Clear();
		foreach (KeyValuePair<SkillIcon, Text> badge in badges)
		{
			if (!visibleIcons.Contains(badge.Key))
			{
				if (Object.op_Implicit((Object)(object)badge.Value))
				{
					Object.Destroy((Object)(object)((Component)badge.Value).gameObject);
				}
				staleIcons.Add(badge.Key);
			}
		}
		foreach (SkillIcon staleIcon in staleIcons)
		{
			badges.Remove(staleIcon);
		}
	}

	private string Status(GenericSkill skill)
	{
		SkillLocator skillLocator = body.skillLocator;
		if (!Object.op_Implicit((Object)(object)skillLocator))
		{
			return null;
		}
		if (Object.op_Implicit((Object)(object)((Component)body).GetComponent<JieSwords>()))
		{
			if ((Object)(object)skill == (Object)(object)skillLocator.secondary)
			{
				return $"插剑 {JieSwords.Count(skill)}/9";
			}
			if ((Object)(object)skill == (Object)(object)skillLocator.utility && JieFlight.IsRiding(body))
			{
				return "御剑中";
			}
			float num = (float)body.GetBuffCount(stormClock) * 0.1f;
			if ((Object)(object)skill == (Object)(object)skillLocator.special && num > 0f)
			{
				return $"施放 {num:0.0}s";
			}
		}
		else if (Object.op_Implicit((Object)(object)((Component)body).GetComponent<XiaoheiCombat>()))
		{
			if ((Object)(object)skill == (Object)(object)skillLocator.primary)
			{
				return $"连中 {XiaoheiCombat.HitProgress(body)}/3";
			}
			if ((Object)(object)skill == (Object)(object)skillLocator.special)
			{
				float num2 = (float)body.GetBuffCount(replayClock) * 0.1f;
				return $"高光 {XiaoheiCombat.Highlights(body)}/3" + ((num2 > 0f) ? $"\n分身 {num2:0.0}s" : "");
			}
			XiaoheiBlink component = ((Component)body).GetComponent<XiaoheiBlink>();
			if ((Object)(object)skill == (Object)(object)skillLocator.utility && Object.op_Implicit((Object)(object)component) && component.HasOrigin)
			{
				return $"回位 {component.OriginRemaining:0.0}s";
			}
		}
		else if (Object.op_Implicit((Object)(object)((Component)body).GetComponent<CuiVitals>()))
		{
			if ((Object)(object)skill == (Object)(object)skillLocator.primary)
			{
				return $"护盾 {body.healthComponent.barrier:0}/{body.healthComponent.fullBarrier:0}";
			}
			if ((Object)(object)skill == (Object)(object)skillLocator.utility)
			{
				EntityStateMachine val = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Body");
				if (Object.op_Implicit((Object)(object)val) && val.state is CuiChargeWindup cuiChargeWindup)
				{
					return $"蓄力 {cuiChargeWindup.HeldSeconds:0.0}/2s";
				}
			}
			if ((Object)(object)skill == (Object)(object)skillLocator.secondary || (Object)(object)skill == (Object)(object)skillLocator.special)
			{
				return $"泵感 {CuiVitals.PumpCount(body)}/6" + (CuiVitals.IsFull(body) ? "\n强化就绪" : "");
			}
		}
		else if (Object.op_Implicit((Object)(object)((Component)body).GetComponent<WeiVitals>()) && (Object)(object)skill == (Object)(object)skillLocator.primary)
		{
			return $"燃脂 {WeiVitals.Stacks(body)}/3";
		}
		return null;
	}

	internal static Font LabelFont()
	{
		if (!Object.op_Implicit((Object)(object)font))
		{
			font = Font.CreateDynamicFontFromOSFont(new string[3] { "Microsoft YaHei", "SimHei", "Arial" }, 14);
		}
		return font;
	}

	private static Text CreateBadge(SkillIcon icon)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)icon.iconImage))
		{
			return null;
		}
		GameObject val = new GameObject("RosterSkillStatus", new Type[3]
		{
			typeof(RectTransform),
			typeof(Text),
			typeof(Outline)
		});
		val.transform.SetParent(((Component)icon.iconImage).transform, false);
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = new Vector2(0f, 1f);
		val2.anchorMax = Vector2.one;
		val2.pivot = new Vector2(0.5f, 0f);
		val2.anchoredPosition = new Vector2(0f, 4f);
		val2.sizeDelta = new Vector2(0f, 32f);
		Text component = val.GetComponent<Text>();
		component.font = LabelFont();
		component.fontSize = 14;
		component.resizeTextForBestFit = true;
		component.resizeTextMinSize = 9;
		component.resizeTextMaxSize = 14;
		component.supportRichText = false;
		((Graphic)component).color = new Color(0.75f, 1f, 0.92f);
		component.alignment = (TextAnchor)7;
		((Graphic)component).raycastTarget = false;
		((Shadow)val.GetComponent<Outline>()).effectColor = new Color(0f, 0f, 0f, 0.9f);
		return component;
	}

	private void OnDestroy()
	{
		foreach (Text value in badges.Values)
		{
			if (Object.op_Implicit((Object)(object)value))
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}
		badges.Clear();
	}
}
internal static class CombatVisuals
{
	private static Shader vertexShader;

	private static Shader textureShader;

	private static Shader radianceShader;

	private static Material trailMaterial;

	private static readonly Dictionary<Texture2D, Texture2D> readablePalettes = new Dictionary<Texture2D, Texture2D>();

	private static Texture2D ribbonMask;

	private static Texture2D moteMask;

	internal static Shader VertexShader
	{
		get
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)vertexShader))
			{
				return vertexShader = Addressables.LoadAssetAsync<Shader>((object)"RoR2/Base/Shaders/HGVertexOnly.shader").WaitForCompletion();
			}
			return vertexShader;
		}
	}

	internal static Shader TextureShader
	{
		get
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)textureShader))
			{
				return textureShader = Addressables.LoadAssetAsync<Shader>((object)"RoR2/Base/Shaders/HGStandard.shader").WaitForCompletion();
			}
			return textureShader;
		}
	}

	internal static void ApplyReadability(Material material, Texture emission = null, float glow = 0f)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_007a: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: 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_01a6: Expected O, but got Unknown
		//IL_0234: 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_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: 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_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Expected O, but got Unknown
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: 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_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		Texture mainTexture = material.mainTexture;
		Texture2D val = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
		if (!Object.op_Implicit((Object)(object)val) || !((Texture)val).isReadable)
		{
			return;
		}
		if (!readablePalettes.TryGetValue(val, out var value))
		{
			Color32[] pixels = val.GetPixels32();
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val2 = Color32.op_Implicit(pixels[i]);
				float num = 1f - Mathf.SmoothStep(0.35f, 0.8f, Mathf.Max(new float[3] { val2.r, val2.g, val2.b }));
				val2.r = Mathf.Lerp(val2.r, Mathf.Min(0.985f, 0.065f + 0.97f * Mathf.Pow(val2.r, 0.85f)), num);
				val2.g = Mathf.Lerp(val2.g, Mathf.Min(0.985f, 0.065f + 0.97f * Mathf.Pow(val2.g, 0.85f)), num);
				val2.b = Mathf.Lerp(val2.b, Mathf.Min(0.985f, 0.065f + 0.97f * Mathf.Pow(val2.b, 0.85f)), num);
				pixels[i] = Color32.op_Implicit(val2);
			}
			value = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, false)
			{
				name = ((Object)val).name + "Readable",
				filterMode = ((Texture)val).filterMode,
				wrapMode = ((Texture)val).wrapMode
			};
			value.SetPixels32(pixels);
			value.Apply(false, false);
			readablePalettes.Add(val, value);
			readablePalettes.Add(value, value);
		}
		material.mainTexture = (Texture)(object)value;
		if (!material.HasProperty("_EmTex"))
		{
			return;
		}
		Color32[] pixels2 = value.GetPixels32();
		Texture2D val3 = (Texture2D)(object)((emission is Texture2D) ? emission : null);
		Color32[] array = ((Object.op_Implicit((Object)(object)val3) && ((Texture)val3).isReadable) ? val3.GetPixels32() : null);
		float num2 = Mathf.Max(1f, glow * 1.25f);
		Color32[] array2 = (Color32[])(object)new Color32[pixels2.Length];
		for (int j = 0; j < array2.Length; j++)
		{
			Color val4 = Color32.op_Implicit(pixels2[j]);
			float num3 = 1f - Mathf.SmoothStep(0.35f, 0.8f, Mathf.Max(new float[3] { val4.r, val4.g, val4.b }));
			Color linear = ((Color)(ref val4)).linear;
			Color val5;
			if (array == null || j >= array.Length)
			{
				val5 = Color.black;
			}
			else
			{
				Color val6 = Color32.op_Implicit(array[j]);
				val5 = ((Color)(ref val6)).linear;
			}
			Color val7 = val5;
			linear.r = Mathf.Max(Mathf.Max(0.008f, linear.r * 0.16f) * num3 / num2, val7.r);
			linear.g = Mathf.Max(Mathf.Max(0.008f, linear.g * 0.16f) * num3 / num2, val7.g);
			linear.b = Mathf.Max(Mathf.Max(0.008f, linear.b * 0.16f) * num3 / num2, val7.b);
			linear.a = 1f;
			array2[j] = Color32.op_Implicit(((Color)(ref linear)).gamma);
		}
		Texture2D val8 = new Texture2D(((Texture)value).width, ((Texture)value).height, (TextureFormat)4, false)
		{
			name = ((Object)material).name + "ReadabilityFill",
			filterMode = ((Texture)value).filterMode,
			wrapMode = ((Texture)value).wrapMode
		};
		val8.SetPixels32(array2);
		val8.Apply(false, false);
		material.SetTexture("_EmTex", (Texture)(object)val8);
		if (material.HasProperty("_EmColor"))
		{
			material.SetColor("_EmColor", Color.white);
		}
		if (material.HasProperty("_EmPower"))
		{
			material.SetFloat("_EmPower", num2);
		}
	}

	internal static Material Surface(string name, Texture palette, float smoothness, Texture emission = null, float glow = 0f)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(TextureShader)
		{
			name = name,
			mainTexture = palette
		};
		if (val.HasProperty("_Color"))
		{
			val.SetColor("_Color", Color.white);
		}
		if (val.HasProperty("_Cull"))
		{
			val.SetFloat("_Cull", 0f);
		}
		if (val.HasProperty("_NormalStrength"))
		{
			val.SetFloat("_NormalStrength", 0f);
		}
		if (val.HasProperty("_Smoothness"))
		{
			val.SetFloat("_Smoothness", smoothness);
		}
		if (val.HasProperty("_SpecularStrength"))
		{
			val.SetFloat("_SpecularStrength", 0.3f);
		}
		if (Object.op_Implicit((Object)(object)emission) && val.HasProperty("_EmTex"))
		{
			val.SetTexture("_EmTex", emission);
			if (val.HasProperty("_EmColor"))
			{
				val.SetColor("_EmColor", Color.white);
			}
			if (val.HasProperty("_EmPower"))
			{
				val.SetFloat("_EmPower", glow);
			}
		}
		ApplyReadability(val, emission, glow);
		return val;
	}

	internal static void SmoothNormals(Mesh mesh, float angle = 48f)
	{
		//IL_002b: 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_003e: 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_0056: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_010d: 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_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		mesh.RecalculateNormals();
		Vector3[] vertices = mesh.vertices;
		Vector3[] normals = mesh.normals;
		Vector3[] array = (Vector3[])(object)new Vector3[normals.Length];
		Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
		Vector3Int key = default(Vector3Int);
		for (int i = 0; i < vertices.Length; i++)
		{
			Vector3 val = vertices[i] * 100000f;
			((Vector3Int)(ref key))..ctor(Mathf.RoundToInt(val.x), Mathf.RoundToInt(val.y), Mathf.RoundToInt(val.z));
			if (!dictionary.TryGetValue(key, out var value))
			{
				dictionary.Add(key, value = new List<int>());
			}
			value.Add(i);
		}
		float num = Mathf.Cos(angle * (MathF.PI / 180f));
		foreach (List<int> value2 in dictionary.Values)
		{
			foreach (int item in value2)
			{
				Vector3 val2 = Vector3.zero;
				foreach (int item2 in value2)
				{
					if (Vector3.Dot(normals[item], normals[item2]) >= num)
					{
						val2 += normals[item2];
					}
				}
				array[item] = ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val2)).normalized : normals[item]);
			}
		}
		mesh.normals = array;
	}

	internal static Material Stroke(string name)
	{
		return SoftRadiance(name, ribbon: true);
	}

	internal static Material SoftRadiance(string name, bool ribbon)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		Material val = Radiance(name);
		Texture2D val2 = (ribbon ? ribbonMask : moteMask);
		if (!Object.op_Implicit((Object)(object)val2))
		{
			val2 = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = (ribbon ? "SoftEnergyRibbon" : "SoftEnergyMote"),
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = Mathf.Abs(((float)i + 0.5f) / 64f * 2f - 1f);
					float num2 = Mathf.Abs(((float)j + 0.5f) / 64f * 2f - 1f);
					float num3 = (ribbon ? num : Mathf.Sqrt(num * num + num2 * num2));
					float num4 = 1f - Mathf.SmoothStep(0.05f, 1f, num3);
					array[i * 64 + j] = new Color(1f, 1f, 1f, num4 * num4);
				}
			}
			val2.SetPixels(array);
			val2.Apply(false, true);
			if (ribbon)
			{
				ribbonMask = val2;
			}
			else
			{
				moteMask = val2;
			}
		}
		val.SetTexture("_MainTex", (Texture)(object)val2);
		return val;
	}

	internal static Material Radiance(string name)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)radianceShader))
		{
			radianceShader = Addressables.LoadAssetAsync<Shader>((object)"RoR2/Base/Shaders/HGCloudRemap.shader").WaitForCompletion();
		}
		Material val = new Material(radianceShader)
		{
			name = name,
			renderQueue = 3000
		};
		string[] array = new string[3] { "_MainTex", "_Cloud1Tex", "_Cloud2Tex" };
		foreach (string text in array)
		{
			if (val.HasProperty(text))
			{
				val.SetTexture(text, (Texture)(object)Texture2D.whiteTexture);
			}
		}
		if (val.HasProperty("_TintColor"))
		{
			val.SetColor("_TintColor", Color.white);
		}
		if (val.HasProperty("_AlphaBoost"))
		{
			val.SetFloat("_AlphaBoost", 1f);
		}
		if (val.HasProperty("_AlphaBias"))
		{
			val.SetFloat("_AlphaBias", 0f);
		}
		if (val.HasProperty("_SrcBlend"))
		{
			val.SetFloat("_SrcBlend", 5f);
		}
		if (val.HasProperty("_DstBlend"))
		{
			val.SetFloat("_DstBlend", 1f);
		}
		if (val.HasProperty("_ZWrite"))
		{
			val.SetFloat("_ZWrite", 0f);
		}
		if (val.HasProperty("_Cull"))
		{
			val.SetFloat("_Cull", 0f);
		}
		val.EnableKeyword("DISABLEREMAP");
		val.EnableKeyword("VERTEXCOLOR");
		return val;
	}

	internal static Material PaletteSurface(Mesh mesh, string name, float smoothness)
	{
		//IL_0020: 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_0055: 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)
		List<Color32> list = new List<Color32>();
		Vector2[] array = (Vector2[])(object)new Vector2[mesh.vertexCount];
		Color32[] colors = mesh.colors32;
		for (int i = 0; i < colors.Length; i++)
		{
			int num = list.IndexOf(colors[i]);
			if (num < 0)
			{
				num = list.Count;
				list.Add(colors[i]);
			}
			array[i] = new Vector2((float)num, 0.5f);
		}
		for (int j = 0; j < array.Length; j++)
		{
			array[j].x = (array[j].x + 0.5f) / (float)list.Count;
		}
		mesh.uv = array;
		return Surface(name, (Texture)(object)FriendSkin.Palette(name + "Palette", list.ToArray()), smoothness);
	}

	internal static void Initialize()
	{
		if (!Object.op_Implicit((Object)(object)VertexShader) || !Object.op_Implicit((Object)(object)TextureShader))
		{
			throw new InvalidOperationException("Combat shaders failed to load.");
		}
	}

	internal static GameObject EffectPrefab(string name)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_001b: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.SetActive(false);
		GameObject val2 = PrefabAPI.InstantiateClone(val, name, false);
		Object.Destroy((Object)val);
		val2.SetActive(true);
		return val2;
	}

	internal static void Trail(Transform parent, Color color, float width, float lifetime)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_009f: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)trailMaterial))
		{
			trailMaterial = Stroke("CombatSwordTrail");
		}
		TrailRenderer val = ((Component)parent).gameObject.AddComponent<TrailRenderer>();
		((Renderer)val).sharedMaterial = trailMaterial;
		val.time = lifetime;
		val.minVertexDistance = 0.08f;
		val.widthMultiplier = width;
		val.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 0.72f),
			new Keyframe(0.12f, 1f),
			new Keyframe(1f, 0f)
		});
		val.startColor = color;
		val.endColor = new Color(color.r, color.g, color.b, 0f);
		val.numCapVertices = 4;
		val.numCornerVertices = 4;
		((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val).receiveShadows = false;
	}
}
public sealed class CuiChargeWindup : AimedMeleeState
{
	internal const float MaxHold = 2f;

	private bool accepted;

	private GameObject aura;

	internal float HeldSeconds => Mathf.Min(((EntityState)this).fixedAge, 2f);

	public override void OnEnter()
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00d8: 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)
		base.OnEnter();
		accepted = AcceptSlot(Object.op_Implicit((Object)(object)((EntityState)this).skillLocator) ? ((EntityState)this).skillLocator.utility : null, costsStock: true);
		if (!accepted)
		{
			if (((EntityState)this).isAuthority)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
			return;
		}
		if (NetworkServer.active)
		{
			((EntityState)this).GetComponent<CuiVitals>().BeginCharge();
		}
		((BaseState)this).StartAimMode(2.3f, false);
		CuiMotion.Play(((EntityState)this).characterBody, "aim", 2f);
		if (NetworkClient.active)
		{
			aura = new GameObject("CuiChargeWindupAura");
			aura.transform.SetParent(((EntityState)this).characterBody.coreTransform, false);
			RadiantGeometry radiantGeometry = aura.AddComponent<RadiantGeometry>();
			radiantGeometry.Arc("ChargeGatheringRing", new Color(1f, 0.65f, 0.08f, 0.65f), 0.7f, 0.065f, 20f, 135f);
			radiantGeometry.Arc("ChargeGatheringOrbit", new Color(1f, 0.92f, 0.65f, 0.65f), 0.64f, 0.025f, 200f, 135f);
		}
	}

	public override void FixedUpdate()
	{
		//IL_0039: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_00b8: 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)
		((EntityState)this).FixedUpdate();
		if (!accepted)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)aura))
		{
			float num = Mathf.Clamp01(((EntityState)this).fixedAge / 2f);
			aura.transform.localScale = Vector3.one * Mathf.Lerp(0.65f, 1.25f, num);
			Transform transform = aura.transform;
			Ray aimRay = ((BaseState)this).GetAimRay();
			transform.rotation = Util.QuaternionSafeLookRotation(((Ray)(ref aimRay)).direction) * Quaternion.Euler(0f, 0f, ((EntityState)this).fixedAge * 100f);
		}
		if (((EntityState)this).isAuthority)
		{
			if (Object.op_Implicit((Object)(object)((EntityState)this).characterMotor))
			{
				CharacterMotor characterMotor = ((EntityState)this).characterMotor;
				characterMotor.velocity *= 0.85f;
			}
			if (!((BaseSkillState)this).IsKeyDownAuthority() || ((EntityState)this).fixedAge >= 2f || !((EntityState)this).characterBody.isPlayerControlled)
			{
				((EntityState)this).outer.SetNextState((EntityState)(object)new ShoulderCharge
				{
					heldSeconds = Mathf.Min(((EntityState)this).fixedAge, 2f)
				});
			}
		}
	}

	public override void OnExit()
	{
		if (accepted && NetworkServer.active && Object.op_Implicit((Object)(object)((EntityState)this).characterBody))
		{
			((EntityState)this).GetComponent<CuiVitals>().EndChargeWindup();
		}
		if (Object.op_Implicit((Object)(object)aura))
		{
			Object.Destroy((Object)(object)aura);
		}
		CuiMotion.Stop(((EntityState)this).characterBody, "aim");
		((EntityState)this).OnExit();
	}

	public override InterruptPriority GetMinimumInterruptPriority()
	{
		return (InterruptPriority)2;
	}
}
[DisallowMultipleComponent]
[DefaultExecutionOrder(31100)]
internal sealed class CuiFistGlow : MonoBehaviour
{
	private sealed class Hand
	{
		internal Transform joint;

		internal MeshRenderer surface;

		internal MeshRenderer halo;

		internal TrailRenderer trail;

		internal Material trailMaterial;

		internal readonly MaterialPropertyBlock surfaceBlock = new MaterialPropertyBlock();

		internal readonly MaterialPropertyBlock haloBlock = new MaterialPropertyBlock();

		internal bool visible;
	}

	private static readonly int Tint = Shader.PropertyToID("_TintColor");

	private static readonly Mesh[] handMeshes = (Mesh[])(object)new Mesh[2];

	private static Mesh haloMesh;

	private static Material surfaceMaterial;

	private static Material haloMaterial;

	private readonly Hand[] hands = new Hand[2];

	private CharacterModel owner;

	private CharacterBody body;

	private SkinnedMeshRenderer bodyRenderer;

	private RendererInfo[] registered;

	private string cue;

	private float cueTime;

	private float pump;

	internal void Bind(CuiRig rig, SkinnedMeshRenderer renderer, CharacterModel model, CharacterBody character)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_00b2: 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_00c7: Expected O, but got Unknown
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: 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_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: 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)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: 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_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: 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_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Expected O, but got Unknown
		if (Application.isBatchMode || (int)SystemInfo.graphicsDeviceType == 4 || rig == null || !Object.op_Implicit((Object)(object)rig.Root) || !Object.op_Implicit((Object)(object)renderer) || !Object.op_Implicit((Object)(object)renderer.sharedMesh))
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)owner) && (Object)(object)owner != (Object)(object)model)
		{
			RemoveRenderers();
		}
		owner = model;
		body = character;
		bodyRenderer = renderer;
		if (!Object.op_Implicit((Object)(object)surfaceMaterial))
		{
			surfaceMaterial = CombatVisuals.Radiance("CuiFistSurfaceLight");
		}
		if (!Object.op_Implicit((Object)(object)haloMaterial))
		{
			haloMaterial = CombatVisuals.SoftRadiance("CuiFistSoftBloom", ribbon: false);
		}
		if (!Object.op_Implicit((Object)(object)haloMesh))
		{
			haloMesh = new Mesh
			{
				name = "CuiFistBloomQuad"
			};
			haloMesh.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f)
			};
			haloMesh.uv = (Vector2[])(object)new Vector2[4]
			{
				Vector2.zero,
				Vector2.right,
				Vector2.one,
				Vector2.up
			};
			haloMesh.colors = (Color[])(object)new Color[4]
			{
				Color.white,
				Color.white,
				Color.white,
				Color.white
			};
			haloMesh.triangles = new int[6] { 0, 1, 2, 0, 2, 3 };
			haloMesh.RecalculateBounds();
			haloMesh.UploadMeshData(true);
		}
		for (int i = 0; i < hands.Length; i++)
		{
			string text = ((i == 0) ? "LeftHand" : "RightHand");
			if (rig.Bones.TryGetValue(text, out var value) && Object.op_Implicit((Object)(object)value))
			{
				if (!Object.op_Implicit((Object)(object)handMeshes[i]))
				{
					handMeshes[i] = ExtractHand(renderer.sharedMesh, Array.IndexOf(CuiRig.Names, text));
				}
				Hand hand = hands[i];
				if (hand == null)
				{
					hand = (hands[i] = new Hand());
					hand.surface = View(text + "GoldenSkin", handMeshes[i], surfaceMaterial, value);
					hand.halo = View(text + "SoftGlow", haloMesh, haloMaterial, value);
					((Component)hand.halo).gameObject.AddComponent<CuiFistBillboard>();
					Transform transform = ((Component)hand.halo).transform;
					Bounds bounds = handMeshes[i].bounds;
					transform.localPosition = ((Bounds)(ref bounds)).center;
					((Component)hand.halo).transform.localScale = Vector3.one * 0.27f;
					Transform transform2 = new GameObject(text + "StrikeTrail").transform;
					((Component)transform2).gameObject.layer = ((Component)renderer).gameObject.layer;
					transform2.SetParent(value, false);
					bounds = handMeshes[i].bounds;
					transform2.localPosition = ((Bounds)(ref bounds)).center;
					CombatVisuals.Trail(transform2, new Color(1f, 0.64f, 0.12f, 0.72f), 0.065f, 0.11f);
					hand.trail = ((Component)transform2).GetComponent<TrailRenderer>();
					hand.trailMaterial = ((Renderer)hand.trail).sharedMaterial;
					hand.trail.minVertexDistance = 0.012f;
					hand.trail.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
					{
						new Keyframe(0f, 1f),
						new Keyframe(0.5f, 0.65f),
						new Keyframe(1f, 0f)
					});
					hand.trail.emitting = false;
				}
				hand.joint = value;
				((Component)hand.surface).transform.SetParent(value, false);
				((Component)hand.halo).transform.SetParent(value, false);
				((Component)hand.trail).transform.SetParent(value, false);
			}
		}
		RegisterRenderers();
	}

	internal void Show(string animation, float normalizedTime)
	{
		cue = animation;
		cueTime = normalizedTime;
	}

	private void LateUpdate()
	{
		//IL_0292: 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_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)bodyRenderer))
		{
			return;
		}
		RegisterRenderers();
		bool flag = cue != "death" && !((Renderer)bodyRenderer).forceRenderingOff && (Object.op_Implicit((Object)(object)owner) ? (owner.invisibilityCount <= 0) : ((Renderer)bodyRenderer).enabled) && (!Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.healthComponent) || body.healthComponent.alive);
		float num = (Object.op_Implicit((Object)(object)body) ? Time.time : Time.unscaledTime);
		float num2 = (Object.op_Implicit((Object)(object)body) ? Time.deltaTime : Time.unscaledDeltaTime);
		pump = Mathf.Lerp(pump, (float)CuiVitals.PumpCount(body) / 6f, 1f - Mathf.Exp(-9f * num2));
		bool flag2 = cue == "jab" || cue == "cross" || cue == "uppercut";
		float num3 = (flag2 ? (Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.08f, 0.3f, cueTime)) * (1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.48f, 0.85f, cueTime)))) : 0f);
		bool flag3 = cue == "slamHeavy" || cue == "ready";
		for (int i = 0; i < hands.Length; i++)
		{
			Hand hand = hands[i];
			if (hand != null && Object.op_Implicit((Object)(object)hand.joint))
			{
				bool flag4 = flag2 && ((cue == "jab") ? (i == 0) : (i == 1));
				float num4 = (flag4 ? num3 : (flag3 ? 0.3f : 0f));
				float num5 = 0.96f + 0.04f * Mathf.Sin(num * 2.5f + (float)i * 0.4f);
				float num6 = (0.48f + pump * 0.72f + num4 * 1.65f) * num5;
				((Renderer)hand.surface).GetPropertyBlock(hand.surfaceBlock);
				hand.surfaceBlock.SetColor(Tint, new Color(num6, num6, num6, 1f));
				((Renderer)hand.surface).SetPropertyBlock(hand.surfaceBlock);
				((Renderer)hand.halo).GetPropertyBlock(hand.haloBlock);
				hand.haloBlock.SetColor(Tint, new Color(1f, 0.56f + num4 * 0.18f, 0.085f + num4 * 0.15f, 0.075f + pump * 0.085f + num4 * 0.15f));
				((Renderer)hand.halo).SetPropertyBlock(hand.haloBlock);
				((Component)hand.halo).transform.localScale = Vector3.one * (0.27f + pump * 0.035f + num4 * 0.045f);
				MeshRenderer surface = hand.surface;
				MeshRenderer halo = hand.halo;
				bool flag5 = (((Renderer)hand.trail).forceRenderingOff = !flag);
				bool forceRenderingOff = (((Renderer)halo).forceRenderingOff = flag5);
				((Renderer)surface).forceRenderingOff = forceRenderingOff;
				if (!flag || !hand.visible)
				{
					hand.trail.Clear();
				}
				hand.trail.emitting = flag && flag4 && cueTime > 0.15f && cueTime < 0.61f;
				hand.trail.widthMultiplier = 0.065f * Mathf.Max(0.01f, Mathf.Abs(hand.joint.lossyScale.y));
				hand.visible = flag;
			}
		}
	}

	private MeshRenderer View(string name, Mesh mesh, Material material, Transform joint)
	{
		//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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name)
		{
			layer = ((Component)bodyRenderer).gameObject.layer
		};
		val.transform.SetParent(joint, false);
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		MeshRenderer obj = val.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = material;
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)obj).receiveShadows = false;
		((Renderer)obj).lightProbeUsage = (LightProbeUsage)0;
		((Renderer)obj).reflectionProbeUsage = (ReflectionProbeUsage)0;
		return obj;
	}

	private static Mesh ExtractHand(Mesh source, int bone)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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_01dc: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Expected O, but got Unknown
		Vector3[] vertices = source.vertices;
		Vector3[] normals = source.normals;
		BoneWeight[] boneWeights = source.boneWeights;
		Matrix4x4 val = source.bindposes[bone];
		int[] array = new int[vertices.Length];
		List<Vector3> list = new List<Vector3>();
		List<Color> list2 = new List<Color>();
		List<int> list3 = new List<int>();
		for (int i = 0; i < vertices.Length; i++)
		{
			array[i] = -1;
			if (((BoneWeight)(ref boneWeights[i])).boneIndex0 == bone && !(((BoneWeight)(ref boneWeights[i])).weight0 < 0.999f))
			{
				array[i] = list.Count;
				Vector3 val2 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(vertices[i]);
				Vector3 val3 = ((Matrix4x4)(ref val)).MultiplyVector(normals[i]);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				list.Add(val2 + normalized * 0.0015f);
				float num = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.025f, -0.1f, val2.y));
				list2.Add(new Color(1f, 0.6f + num * 0.18f, 0.12f + num * 0.15f, 0.16f + num * 0.44f));
			}
		}
		int[] triangles = source.triangles;
		for (int j = 0; j < triangles.Length; j += 3)
		{
			int num2 = array[triangles[j]];
			int num3 = array[triangles[j + 1]];
			int num4 = array[triangles[j + 2]];
			if (num2 >= 0 && num3 >= 0 && num4 >= 0)
			{
				list3.Add(num2);
				list3.Add(num3);
				list3.Add(num4);
			}
		}
		if (list.Count == 0 || list3.Count == 0)
		{
			throw new InvalidOperationException("Cui hand has no matching vertices.");
		}
		Mesh val4 = new Mesh
		{
			name = "CuiFistGlow_" + CuiRig.Names[bone]
		};
		val4.SetVertices(list);
		val4.SetColors(list2);
		val4.SetTriangles(list3, 0);
		val4.RecalculateNormals();
		val4.RecalculateBounds();
		val4.UploadMeshData(true);
		return val4;
	}

	private void RegisterRenderers()
	{
		if (!Object.op_Implicit((Object)(object)owner) || owner.baseRendererInfos == null || owner.baseRendererInfos == registered)
		{
			return;
		}
		List<RendererInfo> infos = new List<RendererInfo>(owner.baseRendererInfos);
		Hand[] array = hands;
		foreach (Hand hand in array)
		{
			if (hand != null)
			{
				Include((Renderer)(object)hand.surface, surfaceMaterial);
				Include((Renderer)(object)hand.halo, haloMaterial);
				Include((Renderer)(object)hand.trail, hand.trailMaterial);
			}
		}
		registered = ((infos.Count == owner.baseRendererInfos.Length) ? owner.baseRendererInfos : infos.ToArray());
		owner.baseRendererInfos = registered;
		owner.materialsDirty = true;
		void Include(Renderer renderer, Material material)
		{
			//IL_002f: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!infos.Exists((RendererInfo info) => (Object)(object)info.renderer == (Object)(object)renderer))
			{
				infos.Add(new RendererInfo
				{
					renderer = renderer,
					defaultMaterial = material,
					defaultShadowCastingMode = (ShadowCastingMode)0,
					ignoreOverlays = true,
					hideOnDeath = true
				});
			}
		}
	}

	private void RemoveRenderers()
	{
		if (!Object.op_Implicit((Object)(object)owner) || owner.baseRendererInfos == null)
		{
			return;
		}
		List<RendererInfo> list = new List<RendererInfo>(owner.baseRendererInfos);
		list.RemoveAll((RendererInfo info) => Array.Exists(hands, (Hand hand) => hand != null && ((object)info.renderer == hand.surface || (object)info.renderer == hand.halo || (object)info.renderer == hand.trail)));
		owner.baseRendererInfos = list.ToArray();
		owner.materialsDirty = true;
		registered = null;
	}

	private void OnDisable()
	{
		Hand[] array = hands;
		foreach (Hand hand in array)
		{
			if (hand != null)
			{
				if (Object.op_Implicit((Object)(object)hand.surface))
				{
					((Renderer)hand.surface).forceRenderingOff = true;
				}
				if (Object.op_Implicit((Object)(object)hand.halo))
				{
					((Renderer)hand.halo).forceRenderingOff = true;
				}
				if (Object.op_Implicit((Object)(object)hand.trail))
				{
					hand.trail.emitting = false;
					hand.trail.Clear();
				}
				hand.visible = false;
			}
		}
	}

	private void OnDestroy()
	{
		RemoveRenderers();
		Hand[] array = hands;
		foreach (Hand hand in array)
		{
			if (hand != null)
			{
				if (Object.op_Implicit((Object)(object)hand.surface))
				{
					Object.Destroy((Object)(object)((Component)hand.surface).gameObject);
				}
				if (Object.op_Implicit((Object)(object)hand.halo))
				{
					Object.Destroy((Object)(object)((Component)hand.halo).gameObject);
				}
				if (Object.op_Implicit((Object)(object)hand.trail))
				{
					Object.Destroy((Object)(object)((Component)hand.trail).gameObject);
				}
			}
		}
	}
}
internal sealed class CuiFistBillboard : MonoBehaviour
{
	private void OnWillRenderObject()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		Camera current = Camera.current;
		if (Object.op_Implicit((Object)(object)current))
		{
			((Component)this).transform.rotation = ((Component)current).transform.rotation;
		}
	}
}
[DefaultExecutionOrder(31000)]
internal sealed class CuiGear : MonoBehaviour
{
	[Serializable]
	private sealed class Document
	{
		public Piece[] parts;
	}

	[Serializable]
	private sealed class Piece
	{
		public string kind;

		public float[] color;

		public float[] vertices;

		public int[] triangles;
	}

	private sealed class Prop
	{
		internal Mesh mesh;

		internal Material material;
	}

	private static readonly Vector3 RightGrip = new Vector3(0.035f, -0.032f, 0.015f);

	private static readonly Vector3 LeftGrip = new Vector3(-0.035f, -0.032f, 0.015f);

	private static Prop plateAsset;

	private static Prop shakerAsset;

	private static bool loadFailed;

	private Transform root;

	private Transform rightHand;

	private Transform leftHand;

	private CharacterModel owner;

	private SkinnedMeshRenderer bodyRenderer;

	private MeshRenderer plate;

	private MeshRenderer heldCup;

	private MeshRenderer thrownCup;

	private RendererInfo[] registered;

	private CharacterBody receiver;

	private bool pending;

	private bool flying;

	private float releaseAt;

	private float flightStart;

	private float flightDuration;

	private float arcHeight;

	private Vector3 launchPoint;

	private Quaternion launchRotation;

	internal void Bind(CuiRig rig, SkinnedMeshRenderer renderer, CharacterModel model)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		if (Application.isBatchMode || (int)SystemInfo.graphicsDeviceType == 4 || rig == null || !Object.op_Implicit((Object)(object)rig.Root) || !Object.op_Implicit((Object)(object)renderer) || loadFailed || !rig.Bones.TryGetValue("RightHand", out var value) || !rig.Bones.TryGetValue("LeftHand", out var value2) || !Object.op_Implicit((Object)(object)value) || !Object.op_Implicit((Object)(object)value2))
		{
			return;
		}
		if (plateAsset == null)
		{
			Material sharedMaterial = ((Renderer)renderer).sharedMaterial;
			if (!Object.op_Implicit((Object)(object)sharedMaterial) || !Object.op_Implicit((Object)(object)sharedMaterial.shader))
			{
				return;
			}
			try
			{
				LoadProps(sharedMaterial.shader);
			}
			catch (Exception ex)
			{
				loadFailed = true;
				Debug.LogWarning((object)("[CuiGe] Unable to load gym props: " + ex.Message));
				return;
			}
		}
		if (Object.op_Implicit((Object)(object)owner) && (Object)(object)owner != (Object)(object)model)
		{
			RemoveRenderers();
		}
		root = rig.Root;
		rightHand = value;
		leftHand = value2;
		owner = model;
		bodyRenderer = renderer;
		plate = Prepare(plate, plateAsset, "CuiIronPlate");
		heldCup = Prepare(heldCup, shakerAsset, "CuiHeldShaker");
		thrownCup = Prepare(thrownCup, shakerAsset, "CuiFlyingShaker");
		RegisterRenderers();
	}

	internal void Show(string cue, float normalizedTime, Quaternion plateOrientation, Quaternion shakerOrientation)
	{
		//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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)root) && Object.op_Implicit((Object)(object)plate) && Object.op_Implicit((Object)(object)leftHand) && Object.op_Implicit((Object)(object)rightHand))
		{
			bool flag = cue == "slam" || cue == "slamHeavy";
			bool flag2 = cue == "drink" || cue == "aim" || cue == "throw";
			SetVisible((Renderer)(object)plate, flag);
			SetVisible((Renderer)(object)heldCup, flag2 && (cue != "throw" || normalizedTime < 0.42f));
			if (flag)
			{
				Vector3 val = (rightHand.TransformPoint(RightGrip) + leftHand.TransformPoint(LeftGrip)) * 0.5f;
				((Component)plate).transform.localPosition = root.InverseTransformPoint(val);
				((Component)plate).transform.localRotation = plateOrientation;
			}
			if (flag2)
			{
				((Component)heldCup).transform.localPosition = root.InverseTransformPoint(rightHand.TransformPoint(RightGrip));
				((Component)heldCup).transform.localRotation = shakerOrientation;
			}
		}
	}

	internal void Throw(CharacterBody target, float delay)
	{
		if (Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)thrownCup))
		{
			receiver = target;
			releaseAt = Time.time + Mathf.Max(0f, delay);
			pending = true;
		}
	}

	private void LateUpdate()
	{
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)root) || !Object.op_Implicit((Object)(object)bodyRenderer) || !Object.op_Implicit((Object)(object)thrownCup))
		{
			return;
		}
		RegisterRenderers();
		bool flag = ((Renderer)bodyRenderer).forceRenderingOff || (!Object.op_Implicit((Object)(object)owner) && !((Renderer)bodyRenderer).enabled);
		MeshRenderer obj = plate;
		MeshRenderer obj2 = heldCup;
		bool flag2 = (((Renderer)thrownCup).forceRenderingOff = flag);
		bool forceRenderingOff = (((Renderer)obj2).forceRenderingOff = flag2);
		((Renderer)obj).forceRenderingOff = forceRenderingOff;
		float time = Time.time;
		if (!Object.op_Implicit((Object)(object)receiver))
		{
			if (pending || flying)
			{
				EndFlight();
			}
			return;
		}
		if (pending && time >= releaseAt)
		{
			pending = false;
			flying = true;
			launchPoint = rightHand.TransformPoint(RightGrip);
			launchRotation = ((Component)heldCup).transform.rotation;
			flightStart = time;
			float num = Vector3.Distance(launchPoint, receiver.corePosition);
			flightDuration = Mathf.Clamp(0.18f + num * 0.008f, 0.2f, 0.4f);
			arcHeight = Mathf.Clamp(0.18f + num * 0.07f, 0.2f, 1.4f);
			SetVisible((Renderer)(object)thrownCup, visible: true);
		}
		if (flying)
		{
			float num2 = Mathf.Clamp01((time - flightStart) / flightDuration);
			((Component)thrownCup).transform.position = Vector3.Lerp(launchPoint, receiver.corePosition, num2) + Vector3.up * (4f * num2 * (1f - num2) * arcHeight);
			((Component)thrownCup).transform.rotation = launchRotation * Quaternion.Euler(235f * num2, 0f, 0f);
			if (num2 >= 1f)
			{
				EndFlight();
			}
		}
	}

	private void EndFlight()
	{
		pending = (flying = false);
		receiver = null;
		SetVisible((Renderer)(object)thrownCup, visible: false);
	}

	private MeshRenderer Prepare(MeshRenderer instance, Prop asset, string label)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)instance))
		{
			GameObject val = new GameObject(label)
			{
				layer = ((Component)bodyRenderer).gameObject.layer
			};
			val.AddComponent<MeshFilter>().sharedMesh = asset.mesh;
			instance = val.AddComponent<MeshRenderer>();
			((Renderer)instance).sharedMaterial = asset.material;
			((Renderer)instance).shadowCastingMode = ((Renderer)bodyRenderer).shadowCastingMode;
			((Renderer)instance).receiveShadows = ((Renderer)bodyRenderer).receiveShadows;
		}
		((Component)instance).transform.SetParent(root, false);
		((Component)instance).transform.localScale = Vector3.one;
		SetVisible((Renderer)(object)instance, visible: false);
		return instance;
	}

	private static void SetVisible(Renderer prop, bool visible)
	{
		if (Object.op_Implicit((Object)(object)prop) && ((Component)prop).gameObject.activeSelf != visible)
		{
			((Component)prop).gameObject.SetActive(visible);
		}
	}

	private void RegisterRenderers()
	{
		List<RendererInfo> updated;
		if (Object.op_Implicit((Object)(object)owner) && Object.op_Implicit((Object)(object)bodyRenderer))
		{
			RendererInfo[] baseRendererInfos = owner.baseRendererInfos;
			if (baseRendererInfos != null && baseRendererInfos != registered)
			{
				updated = new List<RendererInfo>(baseRendererInfos);
				Include(plate, plateAsset);
				Include(heldCup, shakerAsset);
				Include(thrownCup, shakerAsset);
				registered = ((updated.Count == baseRendererInfos.Length) ? baseRendererInfos : updated.ToArray());
				owner.baseRendererInfos = registered;
				owner.materialsDirty = true;
			}
		}
		void Include(MeshRenderer renderer, Prop asset)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (!updated.Exists((RendererInfo info) => (Object)(object)info.renderer == (Object)(object)renderer))
			{
				updated.Add(new RendererInfo
				{
					renderer = (Renderer)(object)renderer,
					defaultMaterial = asset.material,
					defaultShadowCastingMode = ((Renderer)bodyRenderer).shadowCastingMode,
					ignoreOverlays = false
				});
			}
		}
	}

	private void RemoveRenderers()
	{
		if (Object.op_Implicit((Object)(object)owner) && owner.baseRendererInfos != null)
		{
			List<RendererInfo> list = new List<RendererInfo>(owner.baseRendererInfos);
			list.RemoveAll((RendererInfo info) => (object)info.renderer == plate || (object)info.renderer == heldCup || (object)info.renderer == thrownCup);
			owner.baseRendererInfos = list.ToArray();
			owner.materialsDirty = true;
			registered = null;
		}
	}

	private void OnDestroy()
	{
		RemoveRenderers();
		if (Object.op_Implicit((Object)(object)plate))
		{
			Object.Destroy((Object)(object)((Component)plate).gameObject);
		}
		if (Object.op_Implicit((Object)(object)heldCup))
		{
			Object.Destroy((Object)(object)((Component)heldCup).gameObject);
		}
		if (Object.op_Implicit((Object)(object)thrownCup))
		{
			Object.Destroy((Object)(object)((Component)thrownCup).gameObject);
		}
	}

	private static void LoadProps(Shader shader)
	{
		Document document;
		using (Stream stream = typeof(CuiGear).Assembly.GetManifestResourceStream("RiftSurvivor.props.json"))
		{
			using StreamReader streamReader = new StreamReader(stream ?? throw new InvalidDataException("Embedded prop mesh missing."));
			document = JsonUtility.FromJson<Document>(streamReader.ReadToEnd());
		}
		if (document?.parts == null)
		{
			throw new InvalidDataException("No prop parts found.");
		}
		plateAsset = BuildProp("plate", document.parts, shader);
		shakerAsset = BuildProp("shaker", document.parts, shader);
	}

	private static Prop BuildProp(string kind, Piece[] all, Shader shader)
	{
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Expected O, but got Unknown
		//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_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: 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)
		Piece[] array = Array.FindAll(all, (Piece p) => p.kind == kind);
		if (array.Length == 0)
		{
			throw new InvalidDataException("Missing prop: " + kind);
		}
		List<Vector3> list = new List<Vector3>();
		List<Vector2> list2 = new List<Vector2>();
		List<int> list3 = new List<int>();
		Color32[] array2 = (Color32[])(object)new Color32[array.Length];
		for (int num = 0; num < array.Length; num++)
		{
			Piece piece = array[num];
			float[] color = piece.color;
			if (color == null || color.Length != 3 || piece.vertices == null || piece.vertices.Length % 3 != 0 || piece.triangles == null || piece.triangles.Length % 3 != 0)
			{
				throw new InvalidDataException("Invalid geometry for " + kind);
			}
			int count = list.Count;
			for (int num2 = 0; num2 < piece.vertices.Length; num2 += 3)
			{
				list.Add(new Vector3(piece.vertices[num2], piece.vertices[num2 + 1], piece.vertices[num2 + 2]));
				list2.Add(new Vector2(((float)num + 0.5f) / (float)array.Length, 0.5f));
			}
			int[] triangles = piece.triangles;
			foreach (int num4 in triangles)
			{
				if (num4 < 0 || num4 >= list.Count - count)
				{
					throw new InvalidDataException("Invalid prop triangle.");
				}
				list3.Add(count + num4);
			}
			array2[num] = Color32.op_Implicit(new Color(piece.color[0], piece.color[1], piece.color[2], 1f));
		}
		Mesh val = new Mesh
		{
			name = "CuiGear_" + kind
		};
		val.SetVertices(list);
		val.SetUVs(0, list2);
		val.SetTriangles(list3, 0);
		CombatVisuals.SmoothNormals(val, 42f);
		val.RecalculateBounds();
		val.UploadMeshData(true);
		Texture2D val2 = new Texture2D(array2.Length, 1, (TextureFormat)4, false, false)
		{
			name = ((Object)val).name + "Palette",
			filterMode = (FilterMode)0,
			wrapMode = (TextureWrapMode)1
		};
		val2.SetPixels32(array2);
		val2.Apply(false, false);
		Material material = CombatVisuals.Surface(((Object)val).name + "Material", (Texture)(object)val2, (kind == "plate") ? 0.42f : 0.28f);
		return new Prop
		{
			mesh = val,
			material = material
		};
	}
}
[DisallowMultipleComponent]
[DefaultExecutionOrder(30500)]
public sealed class CuiMotion : MonoBehaviour
{
	[Serializable]
	private sealed class Library
	{
		public Clip[] clips;
	}

	[Serializable]
	private sealed class Clip
	{
		public string name;

		public float duration;

		public bool loop;

		public Track[] tracks;

		[NonSerialized]
		public Dictionary<string, Track> byBone;
	}

	[Serializable]
	private sealed class Track
	{
		public string bone;

		public Key[] keys;

		public void Sample(float t, out Quaternion rotation, out Vector3 offset)
		{
			//IL_0072: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			int i;
			for (i = 0; i < keys.Length - 1 && keys[i].t < t; i++)
			{
			}
			Key key = keys[Mathf.Max(0, i - 1)];
			Key key2 = keys[i];
			float num = ((key2.t > key.t) ? Mathf.Clamp01((t - key.t) / (key2.t - key.t)) : 0f);
			rotation = Quaternion.SlerpUnclamped(key.rotation, key2.rotation, num);
			offset = Vector3.LerpUnclamped(key.offset, key2.offset, num);
		}
	}

	[Serializable]
	private sealed class Key
	{
		public float t;

		public float[] r;

		public float[] p;

		[NonSerialized]
		public Quaternion rotation;

		[NonSerialized]
		public Vector3 offset;
	}

	private struct Cue
	{
		public string name;

		public float start;

		public float duration;

		public int serial;

		public bool Active(float now)
		{
			if (name != null)
			{
				return now < start + duration;
			}
			return false;
		}
	}

	private static Dictionary<string, Clip> library;

	private CuiRig rig;

	private CuiGear gear;

	private CuiFistGlow fistGlow;

	private CharacterBody body;

	private CharacterBody presentedBody;

	private CharacterBody pendingBottle;

	private float bottleRelease;

	private Transform[] bones;

	private string[] boneNames;

	private Quaternion[] previousRotations;

	private Transform hips;

	private Vector3 hipRest;

	private Vector3 previousHip;

	private Vector3 lastWorld;

	private Quaternion plate = Quaternion.identity;

	private Quaternion shaker = Quaternion.identity;

	private Quaternion previousPlate;

	private Quaternion previousShaker;

	private bool blendPlate;

	private bool blendShaker;

	private Cue action;

	private Cue dash;

	private Cue aim;

	private Cue ready;

	private Cue spawn;

	private Cue hit;

	private Cue death;

	private float queuedReady;

	private int serial;

	private int shownSerial;

	private Clip shown;

	private Clip locomotion;

	private float transitionStart;

	private float transitionLength;

	private float locomotionTime;

	private float horizontalSpeed;

	private float airborneTime;

	private float landingUntil;

	private bool sampledPosition;

	private bool wasGrounded;

	private bool moving;

	private bool dead;

	private bool sampledHealth;

	private float lastHealth;

	private float lastMaxHealth;

	private float lastBarrier;

	private float lastHitStamp;

	private float nextFlinch;

	private float Now
	{
		get
		{
			if (!Object.op_Implicit((Object)(object)body))
			{
				return Time.unscaledTime;
			}
			return Time.time;
		}
	}

	private static void LoadLibrary()
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_0113: Unknown result type (might be due to invalid IL or missing references)
		if (library != null)
		{
			return;
		}
		using Stream stream = typeof(CuiMotion).Assembly.GetManifestResourceStream("RiftSurvivor.motion.json") ?? throw new InvalidDataException("Missing embedded Cui Ge motion library.");
		using StreamReader streamReader = new StreamReader(stream);
		Dictionary<string, Clip> dictionary = new Dictionary<string, Clip>(StringComparer.Ordinal);
		Clip[] clips = JsonUtility.FromJson<Library>(streamReader.ReadToEnd()).clips;
		foreach (Clip clip in clips)
		{
			clip.byBone = new Dictionary<string, Track>(StringComparer.Ordinal);
			Track[] tracks = clip.tracks;
			foreach (Track track in tracks)
			{
				Key[] keys = track.keys;
				foreach (Key key in keys)
				{
					Quaternion val = new Quaternion(key.r[0], key.r[1], key.r[2], key.r[3]);
					key.rotation = ((Quaternion)(ref val)).normalized;
					if (key.p != null && key.p.Length == 3)
					{
						key.offset = new Vector3(key.p[0], key.p[1], key.p[2]);
					}
				}
				clip.byBone.Add(track.bone, track);
			}
			dictionary.Add(clip.name, clip);
		}
		library = dictionary;
	}

	internal void Bind(CuiRig skeleton, CharacterModel model, CharacterBody character, SkinnedMeshRenderer renderer)
	{
		//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)
		LoadLibrary();
		if (rig == skeleton && (Object)(object)body == (Object)(object)character)
		{
			return;
		}
		rig = skeleton;
		body = character;
		hips = rig.Bones["Hips"];
		hipRest = hips.localPosition;
		boneNames = new string[rig.Bones.Count];
		bones = (Transform[])(object)new Transform[boneNames.Length];
		previousRotations = (Quaternion[])(object)new Quaternion[bones.Length];
		int num = 0;
		foreach (KeyValuePair<string, Transform> bone in rig.Bones)
		{
			boneNames[num] = bone.Key;
			bones[num++] = bone.Value;
		}
		gear = ((Component)this).GetComponent<CuiGear>();
		if (!Object.op_Implicit((Object)(object)gear))
		{
			gear = ((Component)this).gameObject.AddComponent<CuiGear>();
		}
		gear.Bind(rig, renderer, model);
		fistGlow = ((Component)this).GetComponent<CuiFistGlow>();
		if (!Object.op_Implicit((Object)(object)fistGlow))
		{
			fistGlow = ((Component)this).gameObject.AddComponent<CuiFistGlow>();
		}
		fistGlow.Bind(rig, renderer, model, body);
		if (Object.op_Implicit((Object)(object)pendingBottle) && Now - bottleRelease < 0.25f)
		{
			gear.Throw(pendingBottle, Mathf.Max(0f, bottleRelease - Now));
		}
		pendingBottle = null;
		shown = (locomotion = null);
		sampledPosition = (sampledHealth = false);
		if (Object.op_Implicit((Object)(object)character) && (Object)(object)character != (Object)(object)presentedBody)
		{
			presentedBody = character;
			death = default(Cue);
			dead = false;
			if (library.TryGetValue("spawn", out var value))
			{
				spawn = NewCue("spawn", value.duration);
			}
		}
		else if (!Object.op_Implicit((Object)(object)character))
		{
			death = default(Cue);
			dead = false;
		}
		Tick(0f);
	}

	private static CuiMotion Find(CharacterBody owner)
	{
		if (!Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)owner.modelLocator) || !Object.op_Implicit((Object)(object)owner.modelLocator.modelTransform))
		{
			return null;
		}
		CuiMotion componentInChildren = ((Component)owner.modelLocator.modelTransform).GetComponentInChildren<CuiMotion>(true);
		if (Object.op_Implicit((Object)(object)componentInChildren) && !Object.op_Implicit((Object)(object)componentInChildren.body))
		{
			componentInChildren.body = owner;
		}
		return componentInChildren;
	}

	public static void Play(CharacterBody body, string cue, float duration)
	{
		CuiMotion cuiMotion = Find(body);
		if (Object.op_Implicit((Object)(object)cuiMotion) && duration > 0f)
		{
			cuiMotion.PlayCue(cue, duration);
		}
	}

	public static void Stop(CharacterBody body, string cue)
	{
		CuiMotion cuiMotion = Find(body);
		if (Object.op_Implicit((Object)(object)cuiMotion))
		{
			if (cuiMotion.aim.name == cue)
			{
				cuiMotion.aim = default(Cue);
			}
			if (cuiMotion.dash.name == cue)
			{
				cuiMotion.dash = default(Cue);
			}
			if (cuiMotion.action.name == cue)
			{
				cuiMotion.action = default(Cue);
			}
			if (cue == "ready")
			{
				cuiMotion.queuedReady = 0f;
				cuiMotion.ready = default(Cue);
			}
		}
	}

	public static void ThrowBottle(CharacterBody source, CharacterBody target, float delay)
	{
		CuiMotion cuiMotion = Find(source);
		if (Object.op_Implicit((Object)(object)cuiMotion) && Object.op_Implicit((Object)(object)target))
		{
			if (Object.op_Implicit((Object)(object)cuiMotion.gear))
			{
				cuiMotion.gear.Throw(target, Mathf.Max(0f, delay));
				return;
			}
			cuiMotion.pendingBottle = target;
			cuiMotion.bottleRelease = cuiMotion.Now + delay;
		}
	}

	private void PlayCue(string name, float duration)
	{
		if (name == "ready")
		{
			queuedReady = duration;
		}
		else if (!(name == "aim") || aim.name == null)
		{
			spawn = (hit = default(Cue));
			Cue cue = NewCue(name, duration);
			if (name == "charge")
			{
				dash = cue;
			}
			else if (name == "aim")
			{
				aim = cue;
			}
			else
			{
				action = cue;
			}
			ready = default(Cue);
		}
	}

	private Cue NewCue(string name, float duration)
	{
		return new Cue
		{
			name = name,
			start = Now,
			duration = duration,
			serial = ++serial
		};
	}

	private void LateUpdate()
	{
		if (rig != null)
		{
			Tick(Object.op_Implicit((Object)(object)body) ? Time.deltaTime : Time.unscaledDeltaTime);
		}
	}

	private void Tick(float dt)
	{
		//IL_00a5: 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_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: 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_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_056c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Unknown result type (might be due to invalid IL or missing references)
		//IL_0579: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_051e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0520: Unknown result type (might be due to invalid IL or missing references)
		//IL_0524: Unknown result type (might be due to invalid IL or missing references)
		//IL_0529: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0611: Unknown result type (might be due to invalid IL or missing references)
		//IL_0617: Unknown result type (might be due to invalid IL or missing references)
		float now = Now;
		HealthComponent val = (Object.op_Implicit((Object)(object)body) ? body.healthComponent : null);
		bool flag = (Object.op_Implicit((Object)(object)val) ? (!DownedRescue.IsUp(body)) : dead);
		if (flag && !dead)
		{
			dead = true;
			ClearCues();
			if (library.TryGetValue("death", out var value))
			{
				death = NewCue("death", value.duration);
			}
		}
		if (flag && death.name == null)
		{
			gear.Show("", 1f, Quaternion.identity, Quaternion.identity);
			fistGlow.Show("death", 1f);
			return;
		}
		if (!flag)
		{
			if (dead)
			{
				death = default(Cue);
				sampledHealth = (sampledPosition = false);
			}
			dead = false;
			UpdateLocomotion(now, dt);
			if (Object.op_Implicit((Object)(object)body))
			{
				InputBankTest inputBank = body.inputBank;
				if (spawn.name != null && (!spawn.Active(now) || moving || action.Active(now) || dash.Active(now) || aim.name != null || (Object.op_Implicit((Object)(object)inputBank) && (((Vector3)(ref inputBank.moveVector)).sqrMagnitude > 0.01f || inputBank.jump.down || inputBank.sprint.down || inputBank.skill1.down || inputBank.skill2.down || inputBank.skill3.down || inputBank.skill4.down))))
				{
					spawn = default(Cue);
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					ObserveDamage(val, now);
				}
			}
		}
		Cue cue = (flag ? death : SelectCue(now));
		Clip value2;
		Clip clip = ((cue.name != null && library.TryGetValue(cue.name, out value2)) ? value2 : locomotion);
		float num = ((clip == locomotion) ? locomotionTime : ((now - cue.start) / Mathf.Max(0.001f, cue.duration)));
		num = (clip.loop ? Mathf.Repeat(num, 1f) : Mathf.Clamp01(num));
		if (shown != clip || shownSerial != cue.serial)
		{
			for (int i = 0; i < bones.Length; i++)
			{
				previousRotations[i] = bones[i].localRotation;
			}
			previousHip = hips.localPosition;
			previousPlate = plate;
			previousShaker = shaker;
			blendPlate = shown != null && shown.byBone.ContainsKey("Plate");
			blendShaker = shown != null && shown.byBone.ContainsKey("Shaker");
			transitionLength = ((shown == null) ? 0f : ((cue.name == null) ? 0.105f : Mathf.Min(0.07f, cue.duration * 0.15f)));
			transitionStart = now;
			shown = clip;
			shownSerial = cue.serial;
		}
		float num2 = ((transitionLength == 0f) ? 1f : Mathf.SmoothStep(0f, 1f, (now - transitionStart) / transitionLength));
		float num3 = 0f;
		if (!flag && shown != locomotion && shown.name != "spawn" && shown.name != "charge" && shown.name != "slam" && shown.name != "slamHeavy")
		{
			num3 = (wasGrounded ? Mathf.Clamp01((horizontalSpeed - 0.25f) / 2f) : 1f);
		}
		float t = ((num3 > 0f && locomotion.loop) ? Mathf.Repeat(locomotionTime, 1f) : Mathf.Clamp01(locomotionTime));
		for (int j = 0; j < bones.Length; j++)
		{
			string text = boneNames[j];
			if (shown.byBone.TryGetValue(text, out var value3))
			{
				value3.Sample(num, out var rotation, out var offset);
				if (num3 > 0f && IsLeg(text) && locomotion.byBone.TryGetValue(text, out var value4))
				{
					value4.Sample(t, out var rotation2, out var _);
					rotation = Quaternion.SlerpUnclamped(rotation, rotation2, num3);
				}
				bones[j].localRotation = Quaternion.SlerpUnclamped(previousRotations[j], rotation, num2);
				if ((Object)(object)bones[j] == (Object)(object)hips)
				{
					hips.localPosition = Vector3.LerpUnclamped(previousHip, hipRest + offset, num2);
				}
			}
		}
		plate = Prop(shown, "Plate", num, previousPlate, blendPlate ? num2 : 1f);
		shaker = Prop(shown, "Shaker", num, previousShaker, blendShaker ? num2 : 1f);
		gear.Show(shown.name, num, plate, shaker);
		fistGlow.Show(shown.name, num);
	}

	private static bool IsLeg(string name)
	{
		if (!name.EndsWith("Leg", StringComparison.Ordinal))
		{
			return name.EndsWith("Foot", StringComparison.Ordinal);
		}
		return true;
	}

	private static Quaternion Prop(Clip clip, string bone, float t, Quaternion from, float blend)
	{
		//IL_0021: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		if (!clip.byBone.TryGetValue(bone, out var value))
		{
			return Quaternion.identity;
		}
		value.Sample(t, out var rotation, out var _);
		return Quaternion.SlerpUnclamped(from, rotation, blend);
	}

	private Cue SelectCue(float now)
	{
		if (dash.Active(now))
		{
			return dash;
		}
		if (action.Active(now))
		{
			return action;
		}
		if (aim.name != null)
		{
			return aim;
		}
		if (queuedReady > 0f)
		{
			if (Object.op_Implicit((Object)(object)body) && CuiVitals.IsFull(body))
			{
				ready = NewCue("ready", queuedReady);
			}
			queuedReady = 0f;
		}
		if (ready.Active(now) && Object.op_Implicit((Object)(object)body) && CuiVitals.IsFull(body))
		{
			return ready;
		}
		if (hit.Active(now))
		{
			return hit;
		}
		if (!spawn.Active(now))
		{
			return default(Cue);
		}
		return spawn;
	}

	private void ObserveDamage(HealthComponent health, float now)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		float combinedHealth = health.combinedHealth;
		float fullCombinedHealth = health.fullCombinedHealth;
		float barrier = health.barrier;
		float t = health.lastHitTime.t;
		float num = Mathf.Min((lastMaxHealth > fullCombinedHealth && lastMaxHealth > 0f) ? (lastHealth * fullCombinedHealth / lastMaxHealth) : lastHealth, fullCombinedHealth) - combinedHealth;
		if (t > lastHitStamp)
		{
			num += Mathf.Max(0f, lastBarrier - barrier);
		}
		if (sampledHealth && now >= nextFlinch && num >= Mathf.Max(1f, fullCombinedHealth * 0.008f) && !action.Active(now) && !dash.Active(now) && aim.name == null && !ready.Active(now) && queuedReady <= 0f && library.TryGetValue("hit", out var value))
		{
			hit = NewCue("hit", value.duration);
			spawn = default(Cue);
			nextFlinch = now + 0.32f;
		}
		sampledHealth = true;
		lastHealth = combinedHealth;
		lastMaxHealth = fullCombinedHealth;
		lastBarrier = barrier;
		lastHitStamp = t;
	}

	private void UpdateLocomotion(float now, float dt)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_00ac: 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)
		string text = "lobby";
		if (Object.op_Implicit((Object)(object)body))
		{
			CharacterMotor characterMotor = body.characterMotor;
			Vector3 position = body.transform.position;
			bool flag = !Object.op_Implicit((Object)(object)characterMotor) || characterMotor.isGrounded;
			if (sampledPosition && dt > 0f)
			{
				Vector3 val = position - lastWorld;
				val.y = 0f;
				float num = ((Vector3)(ref val)).magnitude / dt;
				if (body.hasEffectiveAuthority && Object.op_Implicit((Object)(object)characterMotor))
				{
					Vector2 val2 = new Vector2(characterMotor.velocity.x, characterMotor.velocity.z);
					num = ((Vector2)(ref val2)).magnitude;
				}
				else if (((Vector3)(ref val)).sqrMagnitude > 9f)
				{
					num = 0f;
				}
				horizontalSpeed = Mathf.Lerp(horizontalSpeed, num, 1f - Mathf.Exp(-12f * dt));
				if (!flag)
				{
					airborneTime += dt;
				}
				else if (!wasGrounded)
				{
					if (airborneTime >= 0.1f)
					{
						landingUntil = now + library["land"].duration;
					}
					airborneTime = 0f;
				}
			}
			sampledPosition = true;
			lastWorld = position;
			wasGrounded = flag;
			moving = horizontalSpeed > (moving ? 0.32f : 0.6f);
			text = ((!flag) ? "air" : ((!(now < landingUntil)) ? (moving ? "run" : "idle") : "land"));
		}
		Clip clip = library[text];
		if (locomotion != clip)
		{
			locomotion = clip;
			locomotionTime = 0f;
			return;
		}
		float num2 = ((text == "run") ? Mathf.Clamp(horizontalSpeed / 7f, 0.45f, 2.75f) : 1f);
		locomotionTime += dt * num2 / clip.duration;
		if (clip.loop)
		{
			locomotionTime = Mathf.Repeat(locomotionTime, 1f);
		}
		else
		{
			locomotionTime = Mathf.Min(locomotionTime, 1f);
		}
	}

	private void ClearCues()
	{
		action = (dash = (aim = (ready = (spawn = (hit = default(Cue))))));
		queuedReady = 0f;
		pendingBottle = null;
	}

	private void OnDisable()
	{
		//IL_0023: 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)
		ClearCues();
		if (Object.op_Implicit((Object)(object)gear))
		{
			gear.Show("", 1f, Quaternion.identity, Quaternion.identity);
		}
		if (Object.op_Implicit((Object)(object)fistGlow))
		{
			fistGlow.Show("", 1f);
		}
		sampledPosition = (sampledHealth = (moving = false));
		horizontalSpeed = (airborneTime = (landingUntil = 0f));
		shown = (locomotion = null);
	}
}
internal sealed class CuiRig
{
	internal readonly Transform Root;

	internal readonly Dictionary<string, Transform> Bones = new Dictionary<string, Transform>();

	internal readonly Transform[] OrderedBones;

	internal static readonly string[] Names = new string[15]
	{
		"Hips", "Chest", "Head", "LeftUpperArm", "LeftLowerArm", "LeftHand", "RightUpperArm", "RightLowerArm", "RightHand", "LeftUpperLeg",
		"LeftLowerLeg", "LeftFoot", "RightUpperLeg", "RightLowerLeg", "RightFoot"
	};

	private static readonly int[] Parents = new int[15]
	{
		-1, 0, 1, 1, 3, 4, 1, 6, 7, 0,
		9, 10, 0, 12, 13
	};

	internal CuiRig(Transform model, SkinnedMeshRenderer original, CharacterBody body, Vector3[] pivots)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		Root = new GameObject("CuiGeRig").transform;
		try
		{
			Align(model, original, body, pivots);
			OrderedBones = (Transform[])(object)new Transform[Names.Length];
			for (int i = 0; i < Names.Length; i++)
			{
				int num = Parents[i];
				Transform transform = new GameObject(Names[i]).transform;
				transform.SetParent((num < 0) ? Root : OrderedBones[num], false);
				transform.localPosition = pivots[i] - ((num < 0) ? Vector3.zero : pivots[num]);
				OrderedBones[i] = transform;
				Bones.Add(Names[i], transform);
			}
		}
		catch
		{
			Object.Destroy((Object)(object)((Component)Root).gameObject);
			throw;
		}
	}

	private void Align(Transform model, SkinnedMeshRenderer original, CharacterBody body, Vector3[] pivots)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: 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)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: 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_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: 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_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: 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_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0.01f, Mathf.Abs(model.lossyScale.y));
		Quaternion val = model.rotation;
		Vector3 val2 = (Object.op_Implicit((Object)(object)body) ? body.footPosition : model.position);
		Bounds bounds = ((Renderer)original).bounds;
		if (((Bounds)(ref bounds)).size.y > 0.1f)
		{
			num = ((Bounds)(ref bounds)).size.y / 1.85f;
			if (!Object.op_Implicit((Object)(object)body))
			{
				((Vector3)(ref val2))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z);
			}
		}
		Transform[] bones = original.bones;
		int num2 = Find(bones, "pelvis", "hips");
		int num3 = Find(bones, "head");
		int num4 = Find(bones, "thighl", "leftupperleg");
		int num5 = Find(bones, "thighr", "rightupperleg");
		Matrix4x4[] matrices;
		if (Object.op_Implicit((Object)(object)original.sharedMesh) && num2 >= 0 && num3 >= 0 && num4 >= 0 && num5 >= 0)
		{
			matrices = ReadBindposes(original.sharedMesh);
			if (Math.Max(Math.Max(num2, num3), Math.Max(num4, num5)) < matrices.Length)
			{
				Vector3 val3 = Rest(num3) - Rest(num2);
				Vector3 val4 = Vector3.ProjectOnPlane(Rest(num5) - Rest(num4), val3);
				if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f && ((Vector3)(ref val4)).sqrMagnitude > 1E-05f)
				{
					Vector3 val5 = Vector3.Cross(val4, val3);
					Vector3 val6 = ((Vector3)(ref val5)).normalized;
					int num6 = Find(bones, "toel", "toesl", "toe1l", "lefttoes");
					int num7 = Find(bones, "footl", "leftfoot");
					Vector3 val7 = ((num6 >= 0 && num6 < matrices.Length && num7 >= 0 && num7 < matrices.Length) ? (Rest(num6) - Rest(num7)) : model.forward);
					if (Vector3.Dot(val6, val7) < 0f)
					{
						val6 = -val6;
					}
					val = Quaternion.LookRotation(val6, ((Vector3)(ref val3)).normalized);
					num = ((Vector3)(ref val3)).magnitude / (pivots[2].y - pivots[0].y);
					val2 = Rest(num2) - val * (pivots[0] * num);
				}
			}
		}
		Root.SetPositionAndRotation(val2, val);
		Root.localScale = Vector3.one * num;
		Root.SetParent(model, true);
		Vector3 Rest(int i)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)original).transform;
			Matrix4x4 inverse = ((Matrix4x4)(ref matrices[i])).inverse;
			return transform.TransformPoint(((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero));
		}
	}

	private static Matrix4x4[] ReadBindposes(Mesh mesh)
	{
		try
		{
			return mesh.bindposes ?? Array.Empty<Matrix4x4>();
		}
		catch (UnityException)
		{
			return Array.Empty<Matrix4x4>();
		}
	}

	private static int Find(Transform[] bones, params string[] aliases)
	{
		for (int i = 0; i < bones.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)bones[i]))
			{
				string value = ((Object)bones[i]).name.Replace(".", "").Replace("_", "").Replace(" ", "")
					.ToLowerInvariant();
				if (A