Decompiled source of Trigger Railgunner v0.7.0

BepInEx/plugins/TriggerRailgunner/TriggerRailgunner.dll

Decompiled 17 hours 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.Scope;
using EntityStates.Railgunner.Weapon;
using HarmonyLib;
using R2API;
using RoR2;
using RoR2.Projectile;
using RoR2.UI;
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.7.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.7.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> HideItemDisplays;

	internal static ConfigEntry<bool> ShotEffects;

	internal static ConfigEntry<bool> ChargeUiEnabled;

	internal static ConfigEntry<float> MenuIdleAmplitude;

	internal static ConfigEntry<bool> ScopeEnabled;

	internal static ConfigEntry<bool> UiEnabled;

	internal static ConfigEntry<float> ScopeOpacity;

	internal static ConfigEntry<float> WeaponScale;

	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_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: 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_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b4: Expected O, but got Unknown
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_068d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0692: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a1: Expected O, but got Unknown
		//IL_06a1: Expected O, but got Unknown
		//IL_0607: Unknown result type (might be due to invalid IL or missing references)
		//IL_060c: Unknown result type (might be due to invalid IL or missing references)
		//IL_061b: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		HairMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "HairMotion", true, "Light secondary hair motion. Disable if an animation clips.");
		CapeMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "CapeMotion", true, "Light secondary cape motion. Disable if an animation clips.");
		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, "Subtle breathing, weight shift and head motion on top of the Trigger menu pose. Feet and rifle grip stay in place. 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>()));
		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.");
		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.");
		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.");
		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 = 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
			{
				ScopeAsset = ScopeMeshData.Load(Path.Combine(text, "scope.trgscope"));
			}
			catch (Exception ex2)
			{
				ScopeAsset = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger scope graphics unavailable; native scope retained: " + ex2));
			}
			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 ex3)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger shots unavailable; native shots retained: " + ex3));
				}
			}
			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 ex4)
				{
					ScopeAsset = null;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger scope hook unavailable; native scope retained: " + ex4));
				}
			}
			if (TriggerFx.Ready)
			{
				try
				{
					TriggerFx.Install(harmony);
				}
				catch (Exception ex5)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger shot hooks unavailable; native shots retained: " + ex5));
				}
			}
			try
			{
				TriggerChargeUI.Install(harmony);
			}
			catch (Exception ex6)
			{
				TriggerChargeUI.Cleanup();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger special interface hooks unavailable; native interface retained: " + ex6));
			}
			try
			{
				TriggerUI.Install(harmony, (Texture)(object)val2);
			}
			catch (Exception ex7)
			{
				TriggerUI.Cleanup();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Trigger character UI unavailable; skin and scope retained: " + ex7));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Trigger 0.7.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 interface, hidden item displays, scope and animation guard retained. " + BodyAsset.Positions.Length + " body vertices, " + WeaponAsset.Positions.Length + " rifle vertices. Runtime visual validation required."));
		}
		catch (Exception ex8)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Trigger could not initialize: " + ex8));
			((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();
	}
}
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 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_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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_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_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_0101: 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_0116: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: 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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: 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_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: 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_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: 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_020a: 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_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: 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_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: 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 * Quaternion.LookRotation(new Vector3(0.94f, 0f, 0.342f), Vector3.up);
		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 * ((SupportContact - 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 Vector3[] lastTip;

	private readonly Vector3[] previousTip;

	private readonly bool[] initialized;

	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 static readonly string[] IdleJoints = new string[4] { "stomach", "chest", "neck", "head" };

	private int[] idleJointIndex;

	private int[] idleMask;

	private readonly Matrix4x4[] idleDelta = (Matrix4x4[])(object)new Matrix4x4[4];

	private readonly Matrix4x4[] idleCombined = (Matrix4x4[])(object)new Matrix4x4[16];

	private readonly float idlePhase = Random.value * 100f;

	internal Matrix4x4[] Bindposes => sourceInverse;

	internal int MappedCount { get; private set; }

	internal Vector3 RightGrip => ((Matrix4x4)(ref pose[rightHandIndex])).MultiplyPoint3x4(rightGripLocal);

	internal Vector3 MenuCenter => menuFeet + MenuUp * menuHeight * 0.55f;

	internal Vector3 MenuUp => menuAlignment * Vector3.up;

	internal Vector3 MenuRight => menuAlignment * Vector3.right;

	internal float MenuHeight => menuHeight;

	internal AssetData Source => data;

	internal float Scale => bodyScale;

	internal int BoneIndex(string semantic)
	{
		return Index(semantic);
	}

	internal Matrix4x4 Pose(int index)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return pose[index];
	}

	internal void SetPose(int index, Matrix4x4 value)
	{
		//IL_0007: 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_0015: Unknown result type (might be due to invalid IL or missing references)
		pose[index] = value;
		ReferencePose.Assign(Bones[index], value);
	}

	internal RigAdapter(AssetData asset, Transform model, Transform container, ReferencePose reference)
	{
		//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_021a: 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_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: 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_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Expected O, but got Unknown
		//IL_047f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0802: Unknown result type (might be due to invalid IL or missing references)
		//IL_0807: Unknown result type (might be due to invalid IL or missing references)
		//IL_080c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0816: Unknown result type (might be due to invalid IL or missing references)
		//IL_081b: Unknown result type (might be due to invalid IL or missing references)
		//IL_081e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0823: Unknown result type (might be due to invalid IL or missing references)
		//IL_082a: 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_0837: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04af: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0879: Unknown result type (might be due to invalid IL or missing references)
		//IL_088c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0896: Unknown result type (might be due to invalid IL or missing references)
		//IL_0860: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_089b: Unknown result type (might be due to invalid IL or missing references)
		//IL_08af: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04de: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_050c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_0567: Unknown result type (might be due to invalid IL or missing references)
		//IL_0571: Unknown result type (might be due to invalid IL or missing references)
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bf: 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_05fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_0630: Unknown result type (might be due to invalid IL or missing references)
		//IL_0632: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_0639: Unknown result type (might be due to invalid IL or missing references)
		//IL_0616: Unknown result type (might be due to invalid IL or missing references)
		//IL_061f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0624: Unknown result type (might be due to invalid IL or missing references)
		//IL_0629: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0704: Unknown result type (might be due to invalid IL or missing references)
		//IL_0729: Unknown result type (might be due to invalid IL or missing references)
		//IL_072e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0730: Unknown result type (might be due to invalid IL or missing references)
		//IL_0737: Unknown result type (might be due to invalid IL or missing references)
		//IL_073c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0741: Unknown result type (might be due to invalid IL or missing references)
		//IL_0719: Unknown result type (might be due to invalid IL or missing references)
		//IL_071b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
		data = asset;
		root = model;
		int num = asset.Bones.Length;
		Bones = (Transform[])(object)new Transform[num];
		drivers = (Transform[])(object)new Transform[num];
		targetInverse = (Matrix4x4[])(object)new Matrix4x4[num];
		targetBind = (Matrix4x4[])(object)new Matrix4x4[num];
		sourceInverse = (Matrix4x4[])(object)new Matrix4x4[num];
		pose = (Matrix4x4[])(object)new Matrix4x4[num];
		evaluated = new bool[num];
		retargetParent = new int[num];
		tail = (Vector3[])(object)new Vector3[num];
		lastTip = (Vector3[])(object)new Vector3[num];
		previousTip = (Vector3[])(object)new Vector3[num];
		initialized = new bool[num];
		Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>(StringComparer.OrdinalIgnoreCase);
		Transform[] componentsInChildren = ((Component)model).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (!dictionary.ContainsKey(((Object)val).name))
			{
				dictionary[((Object)val).name] = val;
			}
		}
		string[] array = new string[16]
		{
			"pelvis", "stomach", "chest", "head", "upper_arm.l", "upper_arm.r", "lower_arm.l", "lower_arm.r", "hand.l", "hand.r",
			"thigh.l", "thigh.r", "calf.l", "calf.r", "foot.l", "foot.r"
		};
		foreach (string text in array)
		{
			string text2 = reference.Resolve(text);
			if (text2 == null || !dictionary.ContainsKey(text2))
			{
				throw new InvalidOperationException("Railgunner bone missing: " + text);
			}
		}
		Vector3 val2 = reference.Position(reference.Resolve("pelvis"));
		Vector3 val3 = reference.Position(reference.Resolve("head"));
		int num2 = Index("pelvis");
		int num3 = Index("head");
		pelvisIndex = num2;
		rightHandIndex = Index("hand.r");
		int num4 = Index("foot.l");
		int num5 = Index("foot.r");
		Vector3 val4 = (menuFeet = (reference.Position(reference.Resolve("foot.l")) + reference.Pos