Decompiled source of Trigger Railgunner v0.19.0

BepInEx/plugins/TriggerRailgunner/TriggerRailgunner.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Railgunner.Backpack;
using EntityStates.Railgunner.Reload;
using EntityStates.Railgunner.Scope;
using EntityStates.Railgunner.Weapon;
using HarmonyLib;
using R2API;
using RoR2;
using RoR2.Projectile;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
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: AssemblyVersion("0.19.0.0")]
namespace TriggerRailgunner;

internal sealed class SourceBone
{
	internal string Name;

	internal string Semantic;

	internal int Parent;

	internal byte Secondary;

	internal Vector3 Position;
}
internal sealed class AssetData
{
	internal SourceBone[] Bones;

	internal Vector3[] Positions;

	internal Vector3[] Normals;

	internal Vector2[] UV;

	internal BoneWeight[] Weights;

	internal int[] Triangles;

	internal string[] MorphNames;

	internal int[][] MorphIndices;

	internal Vector3[][] MorphOffsets;

	internal Texture2D Diffuse;

	internal Texture2D Emission;

	private static int Count(BinaryReader r, int max)
	{
		int num = r.ReadInt32();
		if (num < 0 || num > max)
		{
			throw new InvalidDataException("Invalid mesh count: " + num);
		}
		return num;
	}

	private static string Text(BinaryReader r)
	{
		int num = Count(r, 4096);
		byte[] array = r.ReadBytes(num);
		if (array.Length != num)
		{
			throw new EndOfStreamException();
		}
		return Encoding.UTF8.GetString(array);
	}

	private static Vector3 V3(BinaryReader r)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
	}

	internal static AssetData Load(string directory, string stem)
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		AssetData assetData = new AssetData();
		using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(Path.Combine(directory, stem + ".trgmesh"))))
		{
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "TRGSKN02")
			{
				throw new InvalidDataException("Wrong mesh format");
			}
			int num = Count(binaryReader, 1024);
			int num2 = Count(binaryReader, 200000);
			int num3 = Count(binaryReader, 2000000);
			if (num == 0 || num2 == 0 || num3 % 3 != 0)
			{
				throw new InvalidDataException("Empty or invalid mesh");
			}
			assetData.Bones = new SourceBone[num];
			for (int i = 0; i < num; i++)
			{
				SourceBone sourceBone = new SourceBone
				{
					Name = Text(binaryReader),
					Parent = binaryReader.ReadInt32(),
					Position = V3(binaryReader),
					Secondary = binaryReader.ReadByte(),
					Semantic = Text(binaryReader)
				};
				if (sourceBone.Parent < -1 || sourceBone.Parent >= num || sourceBone.Parent == i)
				{
					throw new InvalidDataException("Invalid bone parent");
				}
				assetData.Bones[i] = sourceBone;
			}
			for (int j = 0; j < num; j++)
			{
				int num4 = j;
				int num5 = 0;
				while (num4 >= 0)
				{
					if (++num5 > num)
					{
						throw new InvalidDataException("Bone cycle");
					}
					num4 = assetData.Bones[num4].Parent;
				}
			}
			assetData.Positions = (Vector3[])(object)new Vector3[num2];
			assetData.Normals = (Vector3[])(object)new Vector3[num2];
			assetData.UV = (Vector2[])(object)new Vector2[num2];
			assetData.Weights = (BoneWeight[])(object)new BoneWeight[num2];
			for (int k = 0; k < num2; k++)
			{
				assetData.Positions[k] = V3(binaryReader);
				assetData.Normals[k] = V3(binaryReader);
				assetData.UV[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				BoneWeight val = default(BoneWeight);
				((BoneWeight)(ref val)).boneIndex0 = binaryReader.ReadInt32();
				((BoneWeight)(ref val)).boneIndex1 = binaryReader.ReadInt32();
				((BoneWeight)(ref val)).boneIndex2 = binaryReader.ReadInt32();
				((BoneWeight)(ref val)).boneIndex3 = binaryReader.ReadInt32();
				((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
				BoneWeight val2 = val;
				if (((BoneWeight)(ref val2)).boneIndex0 < 0 || ((BoneWeight)(ref val2)).boneIndex0 >= num || ((BoneWeight)(ref val2)).boneIndex1 < 0 || ((BoneWeight)(ref val2)).boneIndex1 >= num || ((BoneWeight)(ref val2)).boneIndex2 < 0 || ((BoneWeight)(ref val2)).boneIndex2 >= num || ((BoneWeight)(ref val2)).boneIndex3 < 0 || ((BoneWeight)(ref val2)).boneIndex3 >= num || Mathf.Abs(((BoneWeight)(ref val2)).weight0 + ((BoneWeight)(ref val2)).weight1 + ((BoneWeight)(ref val2)).weight2 + ((BoneWeight)(ref val2)).weight3 - 1f) > 0.001f)
				{
					throw new InvalidDataException("Invalid bone weights");
				}
				assetData.Weights[k] = val2;
			}
			assetData.Triangles = new int[num3];
			for (int l = 0; l < num3; l++)
			{
				int num6 = binaryReader.ReadInt32();
				if (num6 < 0 || num6 >= num2)
				{
					throw new InvalidDataException("Invalid triangle");
				}
				assetData.Triangles[l] = num6;
			}
			int num7 = Count(binaryReader, 256);
			assetData.MorphNames = new string[num7];
			assetData.MorphIndices = new int[num7][];
			assetData.MorphOffsets = new Vector3[num7][];
			for (int m = 0; m < num7; m++)
			{
				assetData.MorphNames[m] = Text(binaryReader);
				int num8 = Count(binaryReader, num2);
				assetData.MorphIndices[m] = new int[num8];
				assetData.MorphOffsets[m] = (Vector3[])(object)new Vector3[num8];
				for (int n = 0; n < num8; n++)
				{
					int num9 = binaryReader.ReadInt32();
					if (num9 < 0 || num9 >= num2)
					{
						throw new InvalidDataException("Invalid morph vertex");
					}
					assetData.MorphIndices[m][n] = num9;
					assetData.MorphOffsets[m][n] = V3(binaryReader);
				}
			}
			if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
			{
				throw new InvalidDataException("Unexpected mesh data");
			}
		}
		assetData.Diffuse = LoadTexture(Path.Combine(directory, stem + ".png"));
		assetData.Emission = LoadTexture(Path.Combine(directory, stem + "_emission.png"));
		return assetData;
	}

	internal static Texture2D LoadTexture(string file)
	{
		//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_0017: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, false);
		if (!ImageConversion.LoadImage(val, File.ReadAllBytes(file), true))
		{
			throw new InvalidDataException("Cannot load texture " + file);
		}
		((Object)val).name = Path.GetFileNameWithoutExtension(file);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Texture)val).anisoLevel = 4;
		return val;
	}

	internal Mesh CreateMesh(Matrix4x4[] bind, bool rigid)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0072: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		Mesh val = new Mesh
		{
			name = (rigid ? "TriggerRifle" : "TriggerBody"),
			indexFormat = (IndexFormat)1
		};
		val.vertices = Positions;
		val.normals = Normals;
		val.uv = UV;
		val.triangles = Triangles;
		val.bindposes = bind;
		if (rigid)
		{
			BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[Positions.Length];
			for (int i = 0; i < array.Length; i++)
			{
				int num = i;
				BoneWeight val2 = default(BoneWeight);
				((BoneWeight)(ref val2)).boneIndex0 = 0;
				((BoneWeight)(ref val2)).weight0 = 1f;
				array[num] = val2;
			}
			val.boneWeights = array;
		}
		else
		{
			val.boneWeights = Weights;
		}
		val.RecalculateBounds();
		val.RecalculateTangents();
		for (int j = 0; j < MorphNames.Length; j++)
		{
			Vector3[] array2 = (Vector3[])(object)new Vector3[Positions.Length];
			for (int k = 0; k < MorphIndices[j].Length; k++)
			{
				array2[MorphIndices[j][k]] = MorphOffsets[j][k];
			}
			val.AddBlendShapeFrame(MorphNames[j], 100f, array2, (Vector3[])null, (Vector3[])null);
		}
		return val;
	}
}
internal sealed class ItemDisplayHider
{
	private readonly HashSet<ItemDisplay> seen = new HashSet<ItemDisplay>();

	private readonly List<Renderer> renderers = new List<Renderer>();

	private readonly List<bool> rendererFlags = new List<bool>();

	private readonly List<Light> lights = new List<Light>();

	private readonly List<bool> lightFlags = new List<bool>();

	internal void Scan(Transform model)
	{
		ItemDisplay[] componentsInChildren = ((Component)model).GetComponentsInChildren<ItemDisplay>(true);
		foreach (ItemDisplay val in componentsInChildren)
		{
			if (!Object.op_Implicit((Object)(object)val) || !seen.Add(val))
			{
				continue;
			}
			Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren2)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					renderers.Add(val2);
					rendererFlags.Add(val2.forceRenderingOff);
					val2.forceRenderingOff = true;
				}
			}
			Light[] componentsInChildren3 = ((Component)val).GetComponentsInChildren<Light>(true);
			foreach (Light val3 in componentsInChildren3)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					lights.Add(val3);
					lightFlags.Add(((Behaviour)val3).enabled);
					((Behaviour)val3).enabled = false;
				}
			}
		}
	}

	internal void KeepHidden()
	{
		for (int i = 0; i < renderers.Count; i++)
		{
			if (Object.op_Implicit((Object)(object)renderers[i]))
			{
				renderers[i].forceRenderingOff = true;
			}
		}
		for (int j = 0; j < lights.Count; j++)
		{
			if (Object.op_Implicit((Object)(object)lights[j]))
			{
				((Behaviour)lights[j]).enabled = false;
			}
		}
	}

	internal void Restore()
	{
		for (int i = 0; i < renderers.Count; i++)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)renderers[i]))
				{
					renderers[i].forceRenderingOff = rendererFlags[i];
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Trigger item display restore: " + ex));
			}
		}
		for (int j = 0; j < lights.Count; j++)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)lights[j]))
				{
					((Behaviour)lights[j]).enabled = lightFlags[j];
				}
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Trigger item display light restore: " + ex2));
			}
		}
		renderers.Clear();
		rendererFlags.Clear();
		lights.Clear();
		lightFlags.Clear();
		seen.Clear();
	}
}
internal sealed class MenuPoseData
{
	internal readonly Matrix4x4[] Deformations;

	internal readonly Matrix4x4 Weapon;

	internal readonly Vector3 AnkleCenter;

	private MenuPoseData(Matrix4x4[] deformations, Matrix4x4 weapon, Vector3 ankleCenter)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		Deformations = deformations;
		Weapon = weapon;
		AnkleCenter = ankleCenter;
	}

	private static float Scalar(BinaryReader reader)
	{
		float num = reader.ReadSingle();
		if (float.IsNaN(num) || float.IsInfinity(num))
		{
			throw new InvalidDataException("Non-finite menu pose value");
		}
		return num;
	}

	private static Vector3 Position(BinaryReader r)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(Scalar(r), Scalar(r), Scalar(r));
	}

	private static Quaternion Rotation(BinaryReader r)
	{
		//IL_001f: 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_002c: 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_003a: 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_0048: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		Quaternion val = default(Quaternion);
		((Quaternion)(ref val))..ctor(Scalar(r), Scalar(r), Scalar(r), Scalar(r));
		if (Mathf.Abs(val.x * val.x + val.y * val.y + val.z * val.z + val.w * val.w - 1f) > 0.001f)
		{
			throw new InvalidDataException("Invalid menu pose rotation");
		}
		return val;
	}

	private static string Name(BinaryReader r)
	{
		int num = r.ReadInt32();
		if (num < 0 || num > 4096)
		{
			throw new InvalidDataException("Invalid menu pose bone name");
		}
		byte[] array = r.ReadBytes(num);
		if (array.Length != num)
		{
			throw new EndOfStreamException();
		}
		return Encoding.UTF8.GetString(array);
	}

	internal static MenuPoseData Load(string file, AssetData source)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: 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)
		//IL_01a9: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		using BinaryReader binaryReader = new BinaryReader(File.OpenRead(file));
		if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "TRGPOSE1")
		{
			throw new InvalidDataException("Wrong menu pose format");
		}
		int num = binaryReader.ReadInt32();
		if (num != source.Bones.Length)
		{
			throw new InvalidDataException("Menu pose skeleton mismatch");
		}
		Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[num];
		Vector3 val = Vector3.zero;
		Vector3 val2 = Vector3.zero;
		bool flag = false;
		bool flag2 = false;
		for (int i = 0; i < num; i++)
		{
			if (Name(binaryReader) != source.Bones[i].Name)
			{
				throw new InvalidDataException("Menu pose bone order mismatch");
			}
			Vector3 val3 = Position(binaryReader);
			Quaternion val4 = Rotation(binaryReader);
			array[i] = Matrix4x4.TRS(val3, val4, Vector3.one) * Matrix4x4.Translate(-source.Bones[i].Position);
			if (!flag && source.Bones[i].Semantic == "foot.l")
			{
				val = val3;
				flag = true;
			}
			if (!flag2 && source.Bones[i].Semantic == "foot.r")
			{
				val2 = val3;
				flag2 = true;
			}
		}
		Vector3 val5 = Position(binaryReader);
		Quaternion val6 = Rotation(binaryReader);
		float num2 = Scalar(binaryReader);
		if (!flag || !flag2 || num2 < 0.1f || num2 > 3f)
		{
			throw new InvalidDataException("Invalid menu pose anchors");
		}
		if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
		{
			throw new InvalidDataException("Unexpected menu pose data");
		}
		return new MenuPoseData(array, Matrix4x4.TRS(val5, val6, Vector3.one * num2), (val + val2) * 0.5f);
	}
}
internal sealed class NativeModelEffects
{
	internal sealed class Visibility
	{
		private readonly List<Renderer> renderers = new List<Renderer>();

		private readonly List<bool> rendererFlags = new List<bool>();

		private readonly List<Behaviour> lights = new List<Behaviour>();

		private readonly List<bool> lightFlags = new List<bool>();

		internal int RendererCount => renderers.Count;

		internal int LightCount => lights.Count;

		internal void Add(Renderer r)
		{
			renderers.Add(r);
			rendererFlags.Add(r.forceRenderingOff);
		}

		internal void Add(Behaviour light)
		{
			lights.Add(light);
			lightFlags.Add(light.enabled);
		}

		internal void KeepHidden()
		{
			foreach (Renderer renderer in renderers)
			{
				if (Object.op_Implicit((Object)(object)renderer))
				{
					renderer.forceRenderingOff = true;
				}
			}
			foreach (Behaviour light in lights)
			{
				if (Object.op_Implicit((Object)(object)light))
				{
					light.enabled = false;
				}
			}
		}

		internal void Restore()
		{
			for (int i = 0; i < renderers.Count; i++)
			{
				try
				{
					if (Object.op_Implicit((Object)(object)renderers[i]))
					{
						renderers[i].forceRenderingOff = rendererFlags[i];
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Trigger native renderer restore: " + ex));
				}
			}
			for (int j = 0; j < lights.Count; j++)
			{
				try
				{
					if (Object.op_Implicit((Object)(object)lights[j]))
					{
						lights[j].enabled = lightFlags[j];
					}
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogWarning((object)("Trigger native light restore: " + ex2));
				}
			}
			renderers.Clear();
			rendererFlags.Clear();
			lights.Clear();
			lightFlags.Clear();
		}
	}

	private readonly HashSet<string> prefabComponents = new HashSet<string>(StringComparer.Ordinal);

	internal NativeModelEffects(Transform prefab)
	{
		Renderer[] componentsInChildren = ((Component)prefab).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer c in componentsInChildren)
		{
			Remember(prefab, (Component)(object)c);
		}
		Light[] componentsInChildren2 = ((Component)prefab).GetComponentsInChildren<Light>(true);
		foreach (Light c2 in componentsInChildren2)
		{
			Remember(prefab, (Component)(object)c2);
		}
		LensFlare[] componentsInChildren3 = ((Component)prefab).GetComponentsInChildren<LensFlare>(true);
		foreach (LensFlare c3 in componentsInChildren3)
		{
			Remember(prefab, (Component)(object)c3);
		}
	}

	private void Remember(Transform root, Component c)
	{
		if (Object.op_Implicit((Object)(object)c))
		{
			prefabComponents.Add(Key(root, c));
		}
	}

	internal Visibility Capture(Transform model, bool menu, IEnumerable<Renderer> alreadyHidden)
	{
		Visibility visibility = new Visibility();
		HashSet<Renderer> hashSet = new HashSet<Renderer>(alreadyHidden);
		Renderer[] componentsInChildren = ((Component)model).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val) && !hashSet.Contains(val) && ShouldHide(model, (Component)(object)val, menu))
			{
				visibility.Add(val);
			}
		}
		Light[] componentsInChildren2 = ((Component)model).GetComponentsInChildren<Light>(true);
		foreach (Light val2 in componentsInChildren2)
		{
			if (Object.op_Implicit((Object)(object)val2) && ShouldHide(model, (Component)(object)val2, menu))
			{
				visibility.Add((Behaviour)(object)val2);
			}
		}
		LensFlare[] componentsInChildren3 = ((Component)model).GetComponentsInChildren<LensFlare>(true);
		foreach (LensFlare val3 in componentsInChildren3)
		{
			if (Object.op_Implicit((Object)(object)val3) && ShouldHide(model, (Component)(object)val3, menu))
			{
				visibility.Add((Behaviour)(object)val3);
			}
		}
		Plugin.Log.LogInfo((object)("Trigger native model cleanup: hiding " + visibility.RendererCount + " additional renderers and " + visibility.LightCount + " lights/flares on " + ((Object)model).name));
		return visibility;
	}

	private bool ShouldHide(Transform root, Component c, bool menu)
	{
		Transform val = c.transform;
		while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)root)
		{
			if (((Object)val).name == "TriggerVisuals")
			{
				return false;
			}
			val = val.parent;
		}
		if (Object.op_Implicit((Object)(object)c.GetComponentInParent<ItemDisplay>()))
		{
			return false;
		}
		if (menu || prefabComponents.Contains(Key(root, c)))
		{
			return true;
		}
		return !Object.op_Implicit((Object)(object)c.GetComponentInParent<EffectComponent>());
	}

	private static string Key(Transform root, Component c)
	{
		List<string> list = new List<string>();
		Transform val = c.transform;
		while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)root)
		{
			list.Add(((Object)val).name);
			val = val.parent;
		}
		list.Reverse();
		return string.Join("/", list.ToArray()) + "|" + ((object)c).GetType().FullName;
	}
}
[BepInPlugin("local.trigger.railgunner", "Trigger Railgunner", "0.19.0")]
[BepInDependency("com.bepis.r2api.skins", "1.4.7")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "local.trigger.railgunner";

	internal static ManualLogSource Log;

	internal static AssetData BodyAsset;

	internal static AssetData WeaponAsset;

	internal static ReferencePose Reference;

	internal static NativeModelEffects NativeEffects;

	internal static MenuPoseData MenuPoseAsset;

	internal static ScopeMeshData ScopeAsset;

	internal static SkinDef TriggerSkin;

	internal static ConfigEntry<bool> HairMotion;

	internal static ConfigEntry<bool> CapeMotion;

	internal static ConfigEntry<bool> MenuPoseEnabled;

	internal static ConfigEntry<float> MenuCloserBy;

	internal static ConfigEntry<float> MenuLeftShift;

	internal static ConfigEntry<bool> MenuIdleMotion;

	internal static ConfigEntry<bool> MenuGunCheck;

	internal static ConfigEntry<bool> HideItemDisplays;

	internal static ConfigEntry<bool> ShotEffects;

	internal static ConfigEntry<bool> ChargeUiEnabled;

	internal static ConfigEntry<bool> ReloadUiEnabled;

	internal static ConfigEntry<bool> WeakPointsEnabled;

	internal static ConfigEntry<float> MenuIdleAmplitude;

	internal static ConfigEntry<bool> ScopeEnabled;

	internal static ConfigEntry<bool> UiEnabled;

	internal static ConfigEntry<bool> ScopeAnimated;

	internal static ConfigEntry<bool> ZzzFont;

	internal static ConfigEntry<bool> CrosshairEnabled;

	internal static ConfigEntry<bool> Overheat;

	internal static ConfigEntry<bool> OverheatParticles;

	internal static ConfigEntry<float> OverheatBrightness;

	internal static ConfigEntry<bool> KillBanner;

	internal static ConfigEntry<float> KillBannerScale;

	internal static ConfigEntry<bool> ReloadGestureEnabled;

	internal static TriggerFont FontAsset;

	internal static string AssetsDir;

	internal static Texture2D BoostIcon;

	internal static ConfigEntry<float> ScopeOpacity;

	internal static ConfigEntry<float> WeaponScale;

	internal static ConfigEntry<float> GlowStrength;

	internal static ConfigEntry<Vector3> WeaponOffset;

	internal static ConfigEntry<Vector3> WeaponRotation;

	private static readonly Dictionary<int, int> Revisions = new Dictionary<int, int>();

	private Harmony harmony;

	private void Awake()
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Expected O, but got Unknown
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Expected O, but got Unknown
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Expected O, but got Unknown
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_0411: Expected O, but got Unknown
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Expected O, but got Unknown
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0761: Unknown result type (might be due to invalid IL or missing references)
		//IL_0770: Unknown result type (might be due to invalid IL or missing references)
		//IL_077e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0808: Unknown result type (might be due to invalid IL or missing references)
		//IL_0832: Unknown result type (might be due to invalid IL or missing references)
		//IL_083c: Expected O, but got Unknown
		//IL_0900: Unknown result type (might be due to invalid IL or missing references)
		//IL_0915: Unknown result type (might be due to invalid IL or missing references)
		//IL_091a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0929: Expected O, but got Unknown
		//IL_0929: Expected O, but got Unknown
		//IL_088f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0894: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a3: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		HairMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "HairMotion", true, "Hair physics (ponytail and locks): inertia, gravity, collisions with the body and the cape. Off = hair follows the animation rigidly.");
		CapeMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "CapeMotion", true, "Cape cloth physics: a 7-column sheet with inertia, gravity and collisions with the body. Off = cape follows the animation rigidly.");
		MenuPoseEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Menu", "TriggerPose", true, "Use the artwork-inspired Trigger pose on the survivor selection mannequin.");
		MenuCloserBy = ((BaseUnityPlugin)this).Config.Bind<float>("Menu", "CloserBy", 0.18f, new ConfigDescription("Bring the selection preview toward its camera by this fraction of the distance, keeping its feet on the floor. 0 restores the previous placement. Menu only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.35f), Array.Empty<object>()));
		MenuLeftShift = ((BaseUnityPlugin)this).Config.Bind<float>("Menu", "LeftShift", 0.12f, new ConfigDescription("Move the selection preview to screen-left, as a fraction of the mannequin height. Keeps the accepted camera distance and pose. Menu only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.3f), Array.Empty<object>()));
		MenuIdleMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Menu", "IdleMotion", true, "Natural idle on the Trigger menu pose: breathing, slow weight shift, the head looking around. Feet, rifle and hands stay in place. Menu only.");
		MenuGunCheck = ((BaseUnityPlugin)this).Config.Bind<bool>("Menu", "GunCheck", true, "Every 9-14 s Trigger lifts her rifle and inspects it, like her idle in Zenless Zone Zero. Requires IdleMotion. Menu only.");
		MenuIdleAmplitude = ((BaseUnityPlugin)this).Config.Bind<float>("Menu", "IdleAmplitude", 1f, new ConfigDescription("Strength of the menu idle motion. 0 freezes the pose, 1 is the default, 2 is twice as strong.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
		GlowStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "GlowStrength", 0.65f, new ConfigDescription("Brightness of the model's original emissive details. 0 turns them off. Restart required.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
		HideItemDisplays = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "HideItems", true, "Hide item and equipment displays on Trigger. They are placed for Railgunner's skeleton and float around Trigger's proportions.");
		ShotEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "TriggerShots", true, "Sky-blue shots and mines for players using the Trigger skin: pistol, scoped shots, supercharge and the mines' red glow. Cryo keeps its ice color. Restart required.");
		Overheat = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "Overheat", true, "The rifle overheats while the special (R, Supercharge) charges: the barrel, rail and vents glow red, orange then white-hot, flash sky-blue on the shot and cool down. Works with Supercharge and Cryocharge.");
		OverheatParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "OverheatParticles", true, "Sparks from the hot rifle and steam while it cools down. Requires Overheat.");
		OverheatBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "OverheatBrightness", 1f, new ConfigDescription("Brightness of the overheating glow.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 2f), Array.Empty<object>()));
		KillBanner = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "TargetEliminated", true, "Show a Zenless Zone Zero style TARGET ELIMINATED banner when you kill an enemy with a scoped or special (R) shot that hit its weak point.");
		KillBannerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "TargetEliminatedScale", 0.35f, new ConfigDescription("Size of the TARGET ELIMINATED banner (top-left of the screen). 1 is the original large size. Restart required.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1f), Array.Empty<object>()));
		ReloadGestureEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Weapon", "ReloadGesture", true, "During the active reload the left hand goes under the rifle's cell housing and slaps it in when you click in the window (the rifle kicks), slips off on a miss, or pushes it in slowly when the bar ends.");
		ChargeUiEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "TriggerSpecialUI", true, "Trigger-style special (R) charging, charged and rebooting gauges, same size and place as the native ones.");
		ReloadUiEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "TriggerReloadUI", true, "Trigger-style active reload bar after a scoped shot: metal end caps, sky-blue progress, orange perfect window. Same size and place as the native bar.");
		CrosshairEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "TriggerCrosshair", true, "Railgunner's normal crosshair in the Trigger scope colors (pale gold and orange).");
		ZzzFont = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "ZZZFont", true, "Draw the Trigger interface labels (crosshair, gauges) with Tektur, a free font close to Zenless Zone Zero's lettering.");
		WeakPointsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Scope", "TriggerWeakPoints", true, "Weak points in the scope shown as Trigger triangles that lock on with a short animation.");
		UiEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Interface", "TriggerUI", true, "Trigger portraits and gold character UI, only for players using the Trigger skin.");
		ScopeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Scope", "TriggerScope", true, "Use the gold Trigger scope interface for this skin. Restart required.");
		ScopeAnimated = ((BaseUnityPlugin)this).Config.Bind<bool>("Scope", "Animated", true, "Short, smooth scope opening (about 0.15 s) and a kick with rays on each shot.");
		ScopeOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Scope", "Opacity", 1f, new ConfigDescription("Opacity of the Trigger scope graphics.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 1f), Array.Empty<object>()));
		WeaponScale = ((BaseUnityPlugin)this).Config.Bind<float>("Weapon", "Scale", 1f, new ConfigDescription("Multiplier after matching the original grip-to-muzzle distance. Restart required.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 1.5f), Array.Empty<object>()));
		WeaponOffset = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Weapon", "Offset", Vector3.zero, "Fine adjustment in model space at the reference pose. Restart required.");
		WeaponRotation = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Weapon", "RotationOffset", Vector3.zero, "Optional local Euler angle correction in degrees after automatic upright rifle alignment. Default 0,0,0. Restart required.");
		try
		{
			string text = (AssetsDir = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "assets"));
			BodyAsset = AssetData.Load(text, "body");
			WeaponAsset = AssetData.Load(text, "weapon");
			try
			{
				MenuPoseAsset = MenuPoseData.Load(Path.Combine(text, "menu_pose.trgpose"), BodyAsset);
			}
			catch (Exception ex)
			{
				MenuPoseAsset = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger menu pose unavailable; base visual behavior retained: " + ex));
			}
			try
			{
				FontAsset = TriggerFont.Load(text);
			}
			catch (Exception ex2)
			{
				FontAsset = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger font unavailable; native labels retained: " + ex2));
			}
			try
			{
				BoostIcon = AssetData.LoadTexture(Path.Combine(text, "boost_icon.png"));
				((Texture)BoostIcon).wrapMode = (TextureWrapMode)1;
			}
			catch (Exception ex3)
			{
				BoostIcon = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger boost icon unavailable: " + ex3));
			}
			try
			{
				ScopeAsset = ScopeMeshData.Load(Path.Combine(text, "scope.trgscope"));
			}
			catch (Exception ex4)
			{
				ScopeAsset = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger scope graphics unavailable; native scope retained: " + ex4));
			}
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/Railgunner/RailgunnerBody.prefab").WaitForCompletion();
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("RailgunnerBody prefab was not found");
			}
			ModelLocator component = val.GetComponent<ModelLocator>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.modelTransform))
			{
				throw new InvalidOperationException("Railgunner ModelLocator missing");
			}
			CharacterModel component2 = ((Component)component.modelTransform).GetComponent<CharacterModel>();
			ModelSkinController component3 = ((Component)component.modelTransform).GetComponent<ModelSkinController>();
			if (!Object.op_Implicit((Object)(object)component2) || !Object.op_Implicit((Object)(object)component3) || component3.skins == null || component3.skins.Length == 0)
			{
				throw new InvalidOperationException("Railgunner base skin missing");
			}
			Reference = new ReferencePose(component.modelTransform);
			NativeEffects = new NativeModelEffects(component.modelTransform);
			Texture2D val2 = (File.Exists(Path.Combine(text, "icon.png")) ? AssetData.LoadTexture(Path.Combine(text, "icon.png")) : BodyAsset.Diffuse);
			if (ShotEffects.Value)
			{
				try
				{
					TriggerFx.Prepare();
				}
				catch (Exception ex5)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger shots unavailable; native shots retained: " + ex5));
				}
			}
			ProjectileGhostReplacement[] projectileGhostReplacements = ((IEnumerable<KeyValuePair<GameObject, GameObject>>)TriggerFx.GhostReplacements).Select((Func<KeyValuePair<GameObject, GameObject>, ProjectileGhostReplacement>)((KeyValuePair<GameObject, GameObject> g) => new ProjectileGhostReplacement
			{
				projectilePrefab = g.Key,
				projectileGhostReplacementPrefab = g.Value
			})).ToArray();
			Sprite icon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
			TriggerSkin = Skins.CreateNewSkinDef(new SkinDefInfo
			{
				Name = "skinTriggerRailgunner",
				NameToken = "Trigger (ZZZ)",
				RootObject = ((Component)component2).gameObject,
				Icon = icon,
				BaseSkins = (SkinDef[])(object)new SkinDef[1] { component3.skins[0] },
				RendererInfos = (RendererInfo[])(object)new RendererInfo[0],
				MeshReplacements = (MeshReplacement[])(object)new MeshReplacement[0],
				GameObjectActivations = (GameObjectActivation[])(object)new GameObjectActivation[0],
				ProjectileGhostReplacements = projectileGhostReplacements,
				MinionSkinReplacements = (MinionSkinReplacement[])(object)new MinionSkinReplacement[0]
			});
			if (!Skins.AddSkinToCharacter(val, TriggerSkin))
			{
				throw new InvalidOperationException("Skin registration failed");
			}
			harmony = new Harmony("local.trigger.railgunner");
			MethodInfo methodInfo = AccessTools.Method(typeof(ModelSkinController), "ApplySkinAsync", (Type[])null, (Type[])null);
			if (methodInfo != null && typeof(IEnumerator).IsAssignableFrom(methodInfo.ReturnType))
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AsyncPostfix", (Type[])null)
				{
					priority = 0
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				MethodInfo methodInfo2 = AccessTools.Method(typeof(ModelSkinController), "ApplySkin", new Type[1] { typeof(int) }, (Type[])null);
				if (methodInfo2 == null)
				{
					throw new MissingMethodException("Supported ModelSkinController.ApplySkin method missing");
				}
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Plugin), "SyncPrefix", (Type[])null), new HarmonyMethod(typeof(Plugin), "SyncPostfix", (Type[])null)
				{
					priority = 0
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (ScopeAsset != null)
			{
				try
				{
					TriggerScope.Install(harmony);
				}
				catch (Exception ex6)
				{
					ScopeAsset = null;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger scope hook unavailable; native scope retained: " + ex6));
				}
			}
			if (TriggerFx.Ready)
			{
				try
				{
					TriggerFx.Install(harmony);
				}
				catch (Exception ex7)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger shot hooks unavailable; native shots retained: " + ex7));
				}
			}
			try
			{
				TriggerKillBanner.Install(harmony);
			}
			catch (Exception ex8)
			{
				TriggerKillBanner.Cleanup();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger target eliminated banner unavailable: " + ex8));
			}
			try
			{
				TriggerChargeUI.Install(harmony);
			}
			catch (Exception ex9)
			{
				TriggerChargeUI.Cleanup();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger special interface hooks unavailable; native interface retained: " + ex9));
			}
			try
			{
				TriggerUI.Install(harmony, (Texture)(object)val2);
			}
			catch (Exception ex10)
			{
				TriggerUI.Cleanup();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger character UI unavailable; skin and scope retained: " + ex10));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Trigger 0.19.0 registered: Trigger portraits and gold character UI only for the selected skin; two-hand rifle, menu pose with idle motion, Trigger shots and mines, special charge and reload interfaces, hidden item displays, scope and animation guard retained. " + BodyAsset.Positions.Length + " body vertices, " + WeaponAsset.Positions.Length + " rifle vertices. Runtime visual validation required."));
		}
		catch (Exception ex11)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Trigger could not initialize: " + ex11));
			((Behaviour)this).enabled = false;
		}
	}

	private static bool Relevant(ModelSkinController c)
	{
		if (Object.op_Implicit((Object)(object)c) && c.skins != null)
		{
			return c.skins.Any((SkinDef s) => Object.op_Implicit((Object)(object)s) && ((Object)s).name == "skinTriggerRailgunner");
		}
		return false;
	}

	private static bool Selected(ModelSkinController c, int index)
	{
		if (Relevant(c) && index >= 0 && index < c.skins.Length && Object.op_Implicit((Object)(object)c.skins[index]))
		{
			return ((Object)c.skins[index]).name == "skinTriggerRailgunner";
		}
		return false;
	}

	private static void AsyncPostfix(ModelSkinController __instance, int __0, ref IEnumerator __result)
	{
		if (Relevant(__instance))
		{
			__result = ApplyAfter(__instance, __0, __result);
		}
	}

	private static IEnumerator ApplyAfter(ModelSkinController controller, int index, IEnumerator original)
	{
		int id = ((Object)controller).GetInstanceID();
		Revisions.TryGetValue(id, out var revision);
		revision++;
		Revisions[id] = revision;
		TriggerUI.SkinApplying(controller, index);
		Remove(controller);
		while (original != null && original.MoveNext())
		{
			yield return original.Current;
		}
		if (Object.op_Implicit((Object)(object)controller) && Revisions.TryGetValue(id, out var value) && value == revision)
		{
			Attach(controller, index);
		}
	}

	private static void SyncPrefix(ModelSkinController __instance, int __0)
	{
		if (Relevant(__instance))
		{
			TriggerUI.SkinApplying(__instance, __0);
			Remove(__instance);
		}
	}

	private static void SyncPostfix(ModelSkinController __instance, int __0)
	{
		Attach(__instance, __0);
	}

	private static void Remove(ModelSkinController controller)
	{
		TriggerVisual component = ((Component)controller).GetComponent<TriggerVisual>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.Cleanup();
			Object.Destroy((Object)(object)component);
		}
	}

	private static void Attach(ModelSkinController controller, int index)
	{
		TriggerUI.SkinApplying(controller, index);
		if (!Selected(controller, index))
		{
			return;
		}
		TriggerVisual triggerVisual = null;
		try
		{
			triggerVisual = ((Component)controller).gameObject.AddComponent<TriggerVisual>();
			triggerVisual.Configure();
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Trigger adaptation failed; original model retained. Send this log for correction: " + ex));
			if (Object.op_Implicit((Object)(object)triggerVisual))
			{
				triggerVisual.Cleanup();
				Object.Destroy((Object)(object)triggerVisual);
			}
		}
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		TriggerScope.Cleanup();
		TriggerChargeUI.Cleanup();
		TriggerUI.Cleanup();
		TriggerKillBanner.Cleanup();
	}
}
internal sealed class ReferencePose
{
	internal readonly Dictionary<string, Matrix4x4> Rest = new Dictionary<string, Matrix4x4>(StringComparer.OrdinalIgnoreCase);

	internal ReferencePose(Transform model)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		Transform[] componentsInChildren = ((Component)model).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (!Rest.ContainsKey(((Object)val).name))
			{
				Rest[((Object)val).name] = model.worldToLocalMatrix * val.localToWorldMatrix;
			}
		}
	}

	internal string Resolve(string semantic)
	{
		foreach (string key in Aliases(semantic))
		{
			if (Rest.ContainsKey(key))
			{
				return Rest.Keys.First((string k) => string.Equals(k, key, StringComparison.OrdinalIgnoreCase));
			}
		}
		return null;
	}

	internal static IEnumerable<string> Aliases(string s)
	{
		yield return s;
		if (s == "pelvis")
		{
			yield return "hips";
		}
		if (s == "stomach")
		{
			yield return "spine";
		}
		if (s == "chest")
		{
			yield return "spine.002";
		}
		if (s == "neck")
		{
			yield return "neck.001";
		}
		if (s.StartsWith("toe."))
		{
			yield return s.Replace("toe.", "toes.");
		}
		if (!s.StartsWith("thumb") && !s.StartsWith("index") && !s.StartsWith("middle") && !s.StartsWith("ring") && !s.StartsWith("pinky"))
		{
			yield break;
		}
		int num = s.IndexOf('.');
		if (num < 1)
		{
			yield break;
		}
		string side = s.Substring(num + 1);
		int joint = s[num - 1] - 48;
		string kind = s.Substring(0, num - 1);
		int num2;
		switch (kind)
		{
		case "thumb":
			if (joint != 0)
			{
				yield return "thumb." + joint + "." + side;
				yield return "thumb" + joint + "." + side;
				yield return "thumb.0" + joint + "." + side;
			}
			yield break;
		default:
			num2 = 4;
			break;
		case "ring":
			num2 = 3;
			break;
		case "middle":
			num2 = 2;
			break;
		case "index":
			num2 = 1;
			break;
		}
		int digit = num2;
		yield return "finger" + digit + "." + joint + "." + side;
		yield return kind + "." + joint + "." + side;
		yield return "finger." + digit + "." + joint + "." + side;
	}

	internal Vector3 Position(string key)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 val = Rest[key];
		return Vector4.op_Implicit(((Matrix4x4)(ref val)).GetColumn(3));
	}

	internal static Quaternion Frame(Vector3 direction, Vector3 forward)
	{
		//IL_0017: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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)
		Vector3 val = ((((Vector3)(ref direction)).sqrMagnitude > 1E-08f) ? ((Vector3)(ref direction)).normalized : Vector3.up);
		Vector3 val2 = Vector3.ProjectOnPlane(forward, val);
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
		{
			val2 = Vector3.ProjectOnPlane(Vector3.right, val);
		}
		return Quaternion.LookRotation(((Vector3)(ref val2)).normalized, val);
	}

	internal static void Assign(Transform t, Matrix4x4 m)
	{
		//IL_0004: 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_0016: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		t.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(3));
		t.localRotation = ((Matrix4x4)(ref m)).rotation;
		Vector3 val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(0));
		float magnitude = ((Vector3)(ref val)).magnitude;
		val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(1));
		float magnitude2 = ((Vector3)(ref val)).magnitude;
		val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(2));
		t.localScale = new Vector3(magnitude, magnitude2, ((Vector3)(ref val)).magnitude);
	}
}
internal sealed class ReloadGesture
{
	private enum Phase
	{
		Idle,
		Reach,
		Ready,
		Slap,
		Miss,
		Finish,
		Return
	}

	private static readonly FieldInfo AttemptedField = typeof(Reloading).GetField("hasAttempted", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly Vector3 Under = new Vector3(0f, -0.15f, 0.064f);

	private static readonly Vector3 Seat = new Vector3(0f, -0.122f, 0.064f);

	internal static readonly Quaternion HoldPalm = Quaternion.LookRotation(new Vector3(0.94f, 0f, 0.342f), Vector3.up);

	private static readonly Quaternion CellPalm = Quaternion.LookRotation(new Vector3(0.82f, 0f, 0.57f), Vector3.up);

	private Phase phase;

	private float t;

	private float returnFrom = 1f;

	private float kick;

	private float kickTime = -1f;

	private float kickSize;

	private Vector3 returnContact;

	private EntityState lastReload;

	private EntityState lastConfirm;

	private bool attemptedSeen;

	internal float Blend { get; private set; }

	internal Vector3 Contact { get; private set; }

	internal Quaternion Palm { get; private set; }

	internal float KickDegrees => kick;

	internal bool Active => phase != Phase.Idle;

	private static float Ease(float x)
	{
		x = Mathf.Clamp01(x);
		return x * x * (3f - 2f * x);
	}

	private static float EaseOut(float x)
	{
		x = Mathf.Clamp01(x);
		return 1f - (1f - x) * (1f - x);
	}

	internal void Update(EntityStateMachine[] machines, float dt)
	{
		//IL_011d: 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_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: 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_01e7: 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_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: 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_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: 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_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: 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_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: 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_02f7: 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_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		EntityState val = null;
		EntityState val2 = null;
		if (machines != null)
		{
			foreach (EntityStateMachine val3 in machines)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					if (val3.state is Reloading)
					{
						val = val3.state;
					}
					else if (val3.state is BoostConfirm)
					{
						val2 = val3.state;
					}
				}
			}
		}
		if (val != null && val != lastReload)
		{
			lastReload = val;
			attemptedSeen = false;
			if (phase == Phase.Idle || phase == Phase.Return)
			{
				Go(Phase.Reach);
			}
		}
		if (val2 != null && val2 != lastConfirm)
		{
			lastConfirm = val2;
			Go(Phase.Slap);
			Kick(4.5f);
		}
		if (val != null && !attemptedSeen && Attempted(val) && phase != Phase.Slap)
		{
			attemptedSeen = true;
			Go(Phase.Miss);
		}
		if (val == null && val2 == null && (phase == Phase.Reach || phase == Phase.Ready || phase == Phase.Miss))
		{
			Go(Phase.Finish);
			Kick(2.2f);
		}
		t += dt;
		Vector3 val4 = Under;
		float blend = 1f;
		switch (phase)
		{
		case Phase.Idle:
			blend = 0f;
			val4 = Under;
			break;
		case Phase.Reach:
			blend = Ease(t / 0.16f);
			if (t >= 0.16f)
			{
				Go(Phase.Ready);
			}
			break;
		case Phase.Ready:
			val4 = Under + new Vector3(0f, 0.004f * Mathf.Sin(t * 9f), 0f);
			break;
		case Phase.Slap:
			val4 = Vector3.LerpUnclamped(Under, Seat + new Vector3(0f, 0.006f, 0f), EaseOut(t / 0.055f));
			if (t > 0.055f)
			{
				val4 = Vector3.Lerp(Seat + new Vector3(0f, 0.006f, 0f), Seat, Ease((t - 0.055f) / 0.05f));
			}
			if (t >= 0.15f)
			{
				StartReturn(val4);
			}
			break;
		case Phase.Miss:
			if (t < 0.07f)
			{
				val4 = Vector3.Lerp(Under, Seat - new Vector3(0f, 0.012f, 0f), EaseOut(t / 0.07f));
			}
			else if (t < 0.2f)
			{
				float num = Ease((t - 0.07f) / 0.13f);
				val4 = Seat - new Vector3(0f, 0.012f, 0f) + new Vector3(0.006f * Mathf.Sin(num * 18f) * (1f - num), -0.03f * num, 0.035f * Mathf.Sin(num * MathF.PI));
			}
			else
			{
				val4 = Vector3.Lerp(Seat - new Vector3(0f, 0.042f, 0f), Under, Ease((t - 0.2f) / 0.15f));
			}
			break;
		case Phase.Finish:
			val4 = Vector3.Lerp(Under, Seat, Ease(t / 0.12f));
			if (t >= 0.2f)
			{
				StartReturn(val4);
			}
			break;
		case Phase.Return:
			blend = returnFrom * (1f - Ease(t / 0.2f));
			val4 = returnContact;
			if (t >= 0.2f)
			{
				phase = Phase.Idle;
				blend = 0f;
			}
			break;
		}
		Blend = blend;
		Contact = val4;
		Palm = CellPalm;
		if (kickTime >= 0f)
		{
			kickTime += dt;
			kick = kickSize * ((kickTime < 0.04f) ? EaseOut(kickTime / 0.04f) : (1f - Ease((kickTime - 0.04f) / 0.22f)));
			if (kickTime > 0.26f)
			{
				kickTime = -1f;
				kick = 0f;
			}
		}
	}

	private void Go(Phase p)
	{
		phase = p;
		t = 0f;
	}

	private void StartReturn(Vector3 from)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		returnContact = from;
		returnFrom = 1f;
		Go(Phase.Return);
	}

	private void Kick(float degrees)
	{
		kickSize = degrees;
		kickTime = 0f;
	}

	private static bool Attempted(EntityState s)
	{
		try
		{
			return AttemptedField != null && (bool)AttemptedField.GetValue(s);
		}
		catch
		{
			return false;
		}
	}

	internal void Reset()
	{
		phase = Phase.Idle;
		Blend = 0f;
		kick = 0f;
		kickTime = -1f;
	}
}
internal sealed class RifleGrip
{
	private sealed class Arm
	{
		private readonly RigAdapter rig;

		internal readonly int Upper;

		internal readonly int Elbow;

		internal readonly int Hand;

		private readonly int[] upperBranch;

		private readonly int[] lowerBranch;

		private readonly int[] handBranch;

		private readonly float upperLength;

		private readonly float lowerLength;

		internal readonly float MaxReach;

		internal readonly Quaternion PalmToBone;

		internal readonly Vector3 ContactLocal;

		internal Arm(RigAdapter rig, string side)
		{
			//IL_009d: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01e6: 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_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			this.rig = rig;
			Upper = Require("upper_arm." + side);
			Elbow = Require("lower_arm." + side);
			Hand = Require("hand." + side);
			int num = Require("middle1." + side);
			int num2 = Require("index1." + side);
			int num3 = Require("pinky1." + side);
			SourceBone[] bones = rig.Source.Bones;
			upperLength = Vector3.Distance(bones[Upper].Position, bones[Elbow].Position);
			lowerLength = Vector3.Distance(bones[Elbow].Position, bones[Hand].Position);
			MaxReach = Mathf.Sqrt(upperLength * upperLength + lowerLength * lowerLength + 2f * upperLength * lowerLength * Mathf.Cos(MathF.PI / 10f));
			Vector3 val = bones[num].Position - bones[Hand].Position;
			Vector3 val2 = bones[num2].Position - bones[num3].Position;
			Vector3 val3 = Vector3.Cross(val, val2);
			Vector3 val4 = ((Vector3)(ref val3)).normalized * ((side == "l") ? (-1f) : 1f);
			Quaternion val5 = Quaternion.LookRotation(val, val4);
			Matrix4x4 inverse = ((Matrix4x4)(ref rig.Bindposes[Hand])).inverse;
			PalmToBone = Quaternion.Inverse(val5) * ((Matrix4x4)(ref inverse)).rotation;
			Vector3 val6 = bones[Hand].Position + val * 0.45f;
			val6 += val4 * ((side == "l") ? 0.014f : 0.012f);
			ContactLocal = ((Matrix4x4)(ref rig.Bindposes[Hand])).MultiplyPoint3x4(val6);
			upperBranch = Branch(Upper, (side == "l") ? "左腕補助" : "右腕補助");
			lowerBranch = Branch(Elbow, (side == "l") ? "左ひじ補助" : "右ひじ補助");
			handBranch = Branch(Hand, null);
		}

		private int Require(string name)
		{
			int num = rig.BoneIndex(name);
			if (num < 0)
			{
				throw new InvalidOperationException("Trigger grip joint missing: " + name);
			}
			return num;
		}

		private int[] Branch(int root, string helperPrefix)
		{
			List<int> list = new List<int>();
			SourceBone[] bones = rig.Source.Bones;
			for (int i = 0; i < bones.Length; i++)
			{
				int num = i;
				while (num >= 0 && num != root)
				{
					num = bones[num].Parent;
				}
				if (num == root || (helperPrefix != null && bones[i].Name.StartsWith(helperPrefix, StringComparison.Ordinal)))
				{
					list.Add(i);
				}
			}
			return list.ToArray();
		}

		private Vector3 Position(int i)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = rig.Pose(i);
			return Vector4.op_Implicit(((Matrix4x4)(ref val)).GetColumn(3));
		}

		private void Rotate(int[] branch, Vector3 pivot, Quaternion rotation)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.Translate(pivot) * Matrix4x4.Rotate(rotation) * Matrix4x4.Translate(-pivot);
			foreach (int index in branch)
			{
				rig.SetPose(index, val * rig.Pose(index));
			}
		}

		internal void Solve(Vector3 target, Quaternion handRotation, Vector3 hint, float weight)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0026: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0045: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00fe: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: 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_01ee: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//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_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Position(Upper);
			Vector3 val2 = Position(Elbow);
			Vector3 val3 = Position(Hand);
			Matrix4x4 val4 = rig.Pose(Hand);
			Quaternion rotation = ((Matrix4x4)(ref val4)).rotation;
			target = Vector3.Lerp(val3, target, weight);
			handRotation = Quaternion.Slerp(rotation, handRotation, weight);
			float num = upperLength * rig.Scale;
			float num2 = lowerLength * rig.Scale;
			Vector3 val5 = target - val;
			float num3 = Mathf.Clamp(((Vector3)(ref val5)).magnitude, Mathf.Abs(num - num2) + 1E-05f, MaxReach * rig.Scale);
			Vector3 val6 = ((((Vector3)(ref val5)).sqrMagnitude > 1E-08f) ? ((Vector3)(ref val5)).normalized : Vector3.down);
			target = val + val6 * num3;
			float num4 = (num * num + num3 * num3 - num2 * num2) / (2f * num3);
			Vector3 val7 = Vector3.ProjectOnPlane(val2 - val, val6);
			val7 += Vector3.ProjectOnPlane(hint, val6) * (num * 0.28f);
			if (((Vector3)(ref val7)).sqrMagnitude < 1E-08f)
			{
				val7 = Vector3.ProjectOnPlane(Vector3.forward, val6);
			}
			if (((Vector3)(ref val7)).sqrMagnitude < 1E-08f)
			{
				val7 = Vector3.ProjectOnPlane(Vector3.right, val6);
			}
			Vector3 val8 = val + val6 * num4 + ((Vector3)(ref val7)).normalized * Mathf.Sqrt(Mathf.Max(0f, num * num - num4 * num4));
			Rotate(upperBranch, val, Quaternion.FromToRotation(val2 - val, val8 - val));
			val2 = Position(Elbow);
			val3 = Position(Hand);
			Rotate(lowerBranch, val2, Quaternion.FromToRotation(val3 - val2, target - val2));
			Vector3 val9 = Position(Hand) - val2;
			Vector3 normalized = ((Vector3)(ref val9)).normalized;
			val4 = rig.Pose(Hand);
			Vector3 val10 = Vector3.ProjectOnPlane(((Matrix4x4)(ref val4)).rotation * Vector3.forward, normalized);
			Vector3 val11 = Vector3.ProjectOnPlane(handRotation * Vector3.forward, normalized);
			if (((Vector3)(ref val10)).sqrMagnitude > 1E-08f && ((Vector3)(ref val11)).sqrMagnitude > 1E-08f)
			{
				Rotate(lowerBranch, val2, Quaternion.AngleAxis(Vector3.SignedAngle(val10, val11, normalized) * 0.7f, normalized));
			}
			val3 = Position(Hand);
			Matrix4x4 val12 = Matrix4x4.TRS(val3, handRotation, Vector3.one * rig.Scale);
			val4 = rig.Pose(Hand);
			Matrix4x4 val13 = val12 * ((Matrix4x4)(ref val4)).inverse;
			int[] array = handBranch;
			foreach (int index in array)
			{
				rig.SetPose(index, val13 * rig.Pose(index));
			}
		}
	}

	internal static readonly Vector3 RearContact = new Vector3(0f, -0.0364f, -0.0874f);

	internal static readonly Vector3 SupportContact = new Vector3(0f, 0.004f, 0.3f);

	private readonly RigAdapter rig;

	private readonly Arm left;

	private readonly Arm right;

	private readonly int pelvis;

	private readonly int head;

	private Vector3 previousUp;

	internal RifleGrip(RigAdapter rig)
	{
		this.rig = rig;
		left = new Arm(rig, "l");
		right = new Arm(rig, "r");
		pelvis = rig.BoneIndex("pelvis");
		head = rig.BoneIndex("head");
	}

	internal Quaternion UprightRotation(Vector3 barrel)
	{
		//IL_0017: 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_001c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_008b: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: 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_00ba: 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_0153: 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_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: 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_0124: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: 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_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		barrel = ((((Vector3)(ref barrel)).sqrMagnitude > 1E-08f) ? ((Vector3)(ref barrel)).normalized : Vector3.forward);
		Vector3 val = Position(head) - Position(pelvis);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		val = Position(right.Upper) - Position(left.Upper);
		Vector3 normalized2 = ((Vector3)(ref val)).normalized;
		Vector3 val2 = Vector3.ProjectOnPlane(normalized, barrel);
		if (((Vector3)(ref val2)).sqrMagnitude < 0.09f)
		{
			Vector3 val3 = Vector3.ProjectOnPlane(normalized2, barrel);
			Vector3 val4 = Vector3.Cross(barrel, val3);
			Vector3 val5 = Vector3.ProjectOnPlane(previousUp, barrel);
			if (((Vector3)(ref val5)).sqrMagnitude > 0.0001f && Vector3.Dot(val4, val5) < 0f)
			{
				val4 = -val4;
			}
			if (((Vector3)(ref val4)).sqrMagnitude > 1E-08f)
			{
				float num = Mathf.Clamp01((0.3f - ((Vector3)(ref val2)).magnitude) / 0.24f);
				num = num * num * (3f - 2f * num);
				val2 = Vector3.Lerp(((Vector3)(ref val2)).normalized, ((Vector3)(ref val4)).normalized, num);
			}
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
		{
			val2 = Vector3.ProjectOnPlane(previousUp, barrel);
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
		{
			val2 = Vector3.ProjectOnPlane(Vector3.up, barrel);
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
		{
			val2 = Vector3.ProjectOnPlane(Vector3.forward, barrel);
		}
		previousUp = ((Vector3)(ref val2)).normalized;
		return Quaternion.LookRotation(barrel, previousUp);
	}

	internal Matrix4x4 Apply(Quaternion rotation, float gunScale, Vector3 rear, float leftWeight, bool hold)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references)
		return Apply(rotation, gunScale, rear, leftWeight, hold, SupportContact, ReloadGesture.HoldPalm);
	}

	internal Matrix4x4 Apply(Quaternion rotation, float gunScale, Vector3 rear, float leftWeight, bool hold, Vector3 leftContact, Quaternion leftPalmLocal)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: 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_01fa: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		if (!hold)
		{
			return WeaponMatrix(rear, rotation, gunScale);
		}
		leftWeight = Mathf.Clamp01(leftWeight);
		Vector3 val = Position(head) - Position(pelvis);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		val = Position(right.Upper) - Position(left.Upper);
		Vector3 normalized2 = ((Vector3)(ref val)).normalized;
		Quaternion val2 = rotation * Quaternion.LookRotation(Vector3.forward, -Vector3.right);
		Quaternion val3 = rotation * leftPalmLocal;
		Quaternion val4 = val2 * right.PalmToBone;
		Quaternion val5 = val3 * left.PalmToBone;
		Vector3 val6 = val4 * right.ContactLocal * rig.Scale;
		Vector3 val7 = val5 * left.ContactLocal * rig.Scale;
		Vector3 val8 = rotation * ((leftContact - RearContact) * gunScale);
		Vector3 center = Position(right.Upper) + val6;
		Vector3 center2 = Position(left.Upper) - val8 + val7;
		for (int i = 0; i < 32; i++)
		{
			rear = InReach(rear, center, right.MaxReach * rig.Scale);
			if (leftWeight > 0.001f)
			{
				rear = InReach(rear, center2, left.MaxReach * rig.Scale);
			}
		}
		right.Solve(rear - val6, val4, -normalized + normalized2 * 0.3f, 1f);
		if (leftWeight > 0.001f)
		{
			left.Solve(rear + val8 - val7, val5, -normalized - normalized2 * 0.2f, leftWeight);
		}
		return WeaponMatrix(rear, rotation, gunScale);
	}

	private static Matrix4x4 WeaponMatrix(Vector3 rear, Quaternion rotation, float scale)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		return Matrix4x4.TRS(rear, rotation, Vector3.one * scale) * Matrix4x4.Translate(-RearContact);
	}

	private static Vector3 InReach(Vector3 point, Vector3 center, float radius)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0019: 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_0014: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = point - center;
		if (!(((Vector3)(ref val)).sqrMagnitude > radius * radius))
		{
			return point;
		}
		return center + ((Vector3)(ref val)).normalized * radius;
	}

	private Vector3 Position(int i)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 val = rig.Pose(i);
		return Vector4.op_Implicit(((Matrix4x4)(ref val)).GetColumn(3));
	}
}
internal sealed class RigAdapter
{
	private readonly AssetData data;

	private readonly Transform root;

	private readonly Transform[] drivers;

	private readonly Matrix4x4[] targetInverse;

	private readonly Matrix4x4[] targetBind;

	private readonly Matrix4x4[] sourceInverse;

	private readonly Matrix4x4[] pose;

	private readonly int[] retargetParent;

	private readonly bool[] evaluated;

	private readonly Vector3[] tail;

	private readonly Matrix4x4 fallback;

	private readonly int pelvisIndex;

	private readonly int rightHandIndex;

	private readonly Vector3 rightGripLocal;

	private readonly float bodyScale;

	private readonly Vector3 menuFeet;

	private readonly Quaternion menuAlignment;

	private readonly float menuHeight;

	private Vector3 groundOffset;

	private Matrix4x4 pelvisDelta;

	internal readonly Transform[] Bones;

	private const float GunCheckLength = 5.8f;

	private float gunCheckStart = -1f;

	private float nextGunCheck = -1f;

	private Quaternion[] palmFrame;

	private Vector3[] palmContact;

	private static readonly float[] RollKeys = new float[10] { 1.2f, 0f, 2f, -40f, 2.9f, -40f, 3.6f, 15f, 4.2f, 0f };

	private static readonly float[] TiltKeys = new float[8] { 1.2f, 0f, 2.4f, 10f, 3.4f, -5f, 4.4f, 0f };

	private static readonly string[] IdleJoints = new string[6] { "stomach