Decompiled source of TylerWuMod v1.0.0

BepInEx/plugins/TylerWuMod/TylerWu.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TylerWu.Model;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TylerWu
{
	[BepInPlugin("wes.tylerwu", "TylerWuMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "wes.tylerwu";

		public const string Name = "TylerWuMod";

		public const string Version = "1.0.0";

		public static ManualLogSource Log;

		public static string PluginDir;

		public static ConfigEntry<int> Rarity;

		public static ConfigEntry<int> MinValue;

		public static ConfigEntry<int> MaxValue;

		public static ConfigEntry<int> MaskedCount;

		public static ConfigEntry<float> SpawnRadius;

		public static ConfigEntry<bool> AllMaskedAreTyler;

		private void Awake()
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Rarity = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Rarity", 30, "How often Tyler Wu spawns as scrap on moons (vanilla scrap is roughly 5-100). 0 = never spawns on its own.");
			MinValue = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "MinValue", 150, "Lowest value, before the game's usual 0.4x scrap multiplier.");
			MaxValue = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "MaxValue", 300, "Highest value, before the game's usual 0.4x scrap multiplier.");
			MaskedCount = ((BaseUnityPlugin)this).Config.Bind<int>("Consume", "MaskedCount", 5, "How many Masked appear when Tyler is consumed.");
			SpawnRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Consume", "SpawnRadius", 2.5f, "How spread out they appear around the spot, in metres.");
			AllMaskedAreTyler = ((BaseUnityPlugin)this).Config.Bind<bool>("Masked", "AllMaskedAreTyler", false, "Give every Masked Tyler's body, not only the ones Tyler spawns. Everyone in the lobby should use the same setting.");
			TylerAssets.Load(Path.Combine(PluginDir, "tyler-atlas.png"));
			TylerRunner.Create();
			new Harmony("wes.tylerwu").PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)("TylerWuMod 1.0.0 loaded. Atlas: " + (((Object)(object)TylerAssets.Atlas != (Object)null) ? "OK" : "MISSING") + ", model parts: " + TylerAssets.Parts.Count));
		}
	}
	public class TylerRunner : MonoBehaviour
	{
		public static TylerRunner Instance;

		public static void Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			GameObject val = new GameObject("TylerWuRunner");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			Instance = val.AddComponent<TylerRunner>();
		}
	}
	public static class TylerAssets
	{
		public const float FigurineHeight = 0.3f;

		public static Texture2D Atlas;

		public static Rig Rig;

		public static List<Part> Parts;

		public static float ModelHeight;

		private static Material material;

		private static Mesh figurine;

		public static Material Material
		{
			get
			{
				//IL_0039: 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_0043: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)material != (Object)null)
				{
					return material;
				}
				Shader val = Shader.Find("HDRP/Lit");
				material = (((Object)(object)val != (Object)null) ? new Material(val) : new Material(Shader.Find("Standard")));
				((Object)material).name = "TylerWuMat";
				SetTex("_BaseColorMap", (Texture)(object)Atlas);
				SetTex("_MainTex", (Texture)(object)Atlas);
				SetColor("_BaseColor", Color.white);
				SetFloat("_Smoothness", 0.15f);
				SetFloat("_Metallic", 0f);
				SetFloat("_DoubleSidedEnable", 1f);
				SetFloat("_CullMode", 0f);
				SetFloat("_CullModeForward", 0f);
				material.EnableKeyword("_DOUBLESIDED_ON");
				try
				{
					Type type = Type.GetType("UnityEngine.Rendering.HighDefinition.HDMaterial, Unity.RenderPipelines.HighDefinition.Runtime");
					MethodInfo methodInfo = ((type != null) ? type.GetMethod("ValidateMaterial", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(Material) }, null) : null);
					if (methodInfo != null)
					{
						methodInfo.Invoke(null, new object[1] { material });
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("HDMaterial.ValidateMaterial failed: " + ex.Message));
				}
				return material;
			}
		}

		public static Mesh Figurine
		{
			get
			{
				if ((Object)(object)figurine == (Object)null)
				{
					figurine = Combined(0.3f / ModelHeight, "TylerFigurine");
				}
				return figurine;
			}
		}

		public static void Load(string atlasPath)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			Rig = new Rig();
			Parts = TylerBuilder.Build(Rig);
			ModelHeight = 0f;
			foreach (Part part in Parts)
			{
				foreach (V3 po in part.Pos)
				{
					if (po.Y > ModelHeight)
					{
						ModelHeight = po.Y;
					}
				}
			}
			if (File.Exists(atlasPath))
			{
				Atlas = new Texture2D(2, 2, (TextureFormat)4, true);
				ImageConversion.LoadImage(Atlas, File.ReadAllBytes(atlasPath));
				((Object)Atlas).name = "TylerAtlas";
				((Texture)Atlas).wrapMode = (TextureWrapMode)1;
				((Texture)Atlas).anisoLevel = 4;
				Atlas.Apply(true, false);
			}
			else
			{
				Plugin.Log.LogError((object)("Missing " + atlasPath + " - Tyler will be untextured."));
			}
		}

		public static Vector3 U(V3 v)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(0f - v.X, v.Y, v.Z);
		}

		private static void SetTex(string p, Texture t)
		{
			if (material.HasProperty(p))
			{
				material.SetTexture(p, t);
			}
		}

		private static void SetColor(string p, Color c)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (material.HasProperty(p))
			{
				material.SetColor(p, c);
			}
		}

		private static void SetFloat(string p, float v)
		{
			if (material.HasProperty(p))
			{
				material.SetFloat(p, v);
			}
		}

		public static Mesh Combined(float scale, string name)
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_004e: 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_006d: 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)
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			foreach (Part part in Parts)
			{
				int count = list.Count;
				for (int i = 0; i < part.Pos.Count; i++)
				{
					list.Add(U(part.Pos[i]) * scale);
					list2.Add(U(part.Nrm[i]));
					list3.Add(new Vector2(part.U[i], part.V[i]));
				}
				for (int j = 0; j < part.Tri.Count; j += 3)
				{
					list4.Add(count + part.Tri[j]);
					list4.Add(count + part.Tri[j + 2]);
					list4.Add(count + part.Tri[j + 1]);
				}
			}
			Mesh val = new Mesh();
			((Object)val).name = name;
			if (list.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(list);
			val.SetNormals(list2);
			val.SetUVs(0, list3);
			val.SetTriangles(list4, 0);
			val.RecalculateBounds();
			return val;
		}
	}
	public class TylerItem : GrabbableObject
	{
		private bool consumed;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0098: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!buttonDown || consumed)
			{
				return;
			}
			PlayerControllerB playerHeldBy = base.playerHeldBy;
			if ((Object)(object)playerHeldBy == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.inShipPhase)
			{
				if (flag && (Object)(object)HUDManager.Instance != (Object)null)
				{
					HUDManager.Instance.DisplayTip("Tyler Wu", "Tyler can't be consumed in orbit. Land on a moon first.", false, false, "LC_Tip1");
				}
				return;
			}
			consumed = true;
			Vector3 position = ((Component)playerHeldBy).transform.position;
			bool isInsideFactory = playerHeldBy.isInsideFactory;
			TylerEvents.Record(position, isInsideFactory);
			Plugin.Log.LogInfo((object)(playerHeldBy.playerUsername + " consumed Tyler Wu at " + ((Vector3)(ref position)).ToString("F1") + (isInsideFactory ? " (inside)" : " (outside)")));
			if (((NetworkBehaviour)this).IsServer && (Object)(object)TylerRunner.Instance != (Object)null)
			{
				((MonoBehaviour)TylerRunner.Instance).StartCoroutine(TylerSpawner.Spawn(position));
			}
			if (flag)
			{
				playerHeldBy.DestroyItemInSlotAndSync(playerHeldBy.currentItemSlot);
				playerHeldBy.KillPlayer(Vector3.zero, false, (CauseOfDeath)0, 0, default(Vector3), false);
			}
		}
	}
	public static class TylerEvents
	{
		private class Ev
		{
			public Vector3 Pos;

			public float Time;

			public bool Inside;

			public int Left;
		}

		private static readonly List<Ev> events = new List<Ev>();

		public static void Record(Vector3 pos, bool inside)
		{
			//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)
			Ev ev = new Ev();
			ev.Pos = pos;
			ev.Time = Time.realtimeSinceStartup;
			ev.Inside = inside;
			ev.Left = Math.Max(0, Plugin.MaskedCount.Value);
			events.Add(ev);
		}

		public static bool Claim(Vector3 maskedPos, out bool inside)
		{
			//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)
			inside = true;
			float now = Time.realtimeSinceStartup;
			events.RemoveAll((Ev x) => now - x.Time > 20f || x.Left <= 0);
			float num = Plugin.SpawnRadius.Value + 8f;
			foreach (Ev @event in events)
			{
				if (!(Vector3.Distance(@event.Pos, maskedPos) > num))
				{
					@event.Left--;
					inside = @event.Inside;
					return true;
				}
			}
			return false;
		}
	}
	public static class TylerSpawner
	{
		public static int LastSpawnCount;

		public static IEnumerator Spawn(Vector3 pos)
		{
			//IL_0008: 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)
			yield return (object)new WaitForSeconds(0.4f);
			EnemyType masked = null;
			EnemyType[] array = Resources.FindObjectsOfTypeAll<EnemyType>();
			foreach (EnemyType val in array)
			{
				if ((Object)(object)val.enemyPrefab != (Object)null && (Object)(object)val.enemyPrefab.GetComponent<MaskedPlayerEnemy>() != (Object)null)
				{
					masked = val;
					break;
				}
			}
			if ((Object)(object)masked == (Object)null || (Object)(object)RoundManager.Instance == (Object)null)
			{
				Plugin.Log.LogError((object)"Can't spawn Tyler Masked: Masked enemy type not found.");
				yield break;
			}
			int n = Mathf.Clamp(Plugin.MaskedCount.Value, 0, 50);
			for (int j = 0; j < n; j++)
			{
				Vector3 randomNavMeshPositionInRadiusSpherical = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(pos, Plugin.SpawnRadius.Value, default(NavMeshHit));
				RoundManager.Instance.SpawnEnemyGameObject(randomNavMeshPositionInRadiusSpherical, Random.Range(0f, 360f), -1, masked);
			}
			LastSpawnCount = n;
			Plugin.Log.LogInfo((object)("Spawned " + n + " Tyler Masked."));
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy), "Start")]
	internal static class MaskedStartPatch
	{
		[HarmonyPostfix]
		private static void Postfix(MaskedPlayerEnemy __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				bool inside;
				bool flag = TylerEvents.Claim(((Component)__instance).transform.position, out inside);
				if (flag || Plugin.AllMaskedAreTyler.Value)
				{
					if (flag && ((EnemyAI)__instance).isOutside == inside)
					{
						((EnemyAI)__instance).SetEnemyOutside(!inside);
					}
					if ((Object)(object)((Component)__instance).GetComponent<TylerSkin>() == (Object)null)
					{
						((Component)__instance).gameObject.AddComponent<TylerSkin>().Init(__instance, flag);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Tyler Masked setup failed: " + ex));
			}
		}
	}
}
namespace TylerWu.Model
{
	public struct V3
	{
		public float X;

		public float Y;

		public float Z;

		public float Length => (float)Math.Sqrt(X * X + Y * Y + Z * Z);

		public V3 Normalized
		{
			get
			{
				float length = Length;
				if (!(length > 1E-08f))
				{
					return new V3(0f, 1f, 0f);
				}
				return this * (1f / length);
			}
		}

		public V3(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		public static V3 operator +(V3 a, V3 b)
		{
			return new V3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
		}

		public static V3 operator -(V3 a, V3 b)
		{
			return new V3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
		}

		public static V3 operator *(V3 a, float s)
		{
			return new V3(a.X * s, a.Y * s, a.Z * s);
		}

		public static float Dot(V3 a, V3 b)
		{
			return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
		}

		public static V3 Cross(V3 a, V3 b)
		{
			return new V3(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
		}

		public static V3 Lerp(V3 a, V3 b, float t)
		{
			return a + (b - a) * t;
		}
	}
	public struct UVRect
	{
		public float U0;

		public float V0;

		public float U1;

		public float V1;

		public float CU => (U0 + U1) * 0.5f;

		public float CV => (V0 + V1) * 0.5f;

		public UVRect(float u0, float v0, float u1, float v1)
		{
			U0 = u0;
			V0 = v0;
			U1 = u1;
			V1 = v1;
		}

		public float U(float s)
		{
			return U0 + (U1 - U0) * Clamp01(s);
		}

		public float V(float t)
		{
			return V0 + (V1 - V0) * Clamp01(t);
		}

		private static float Clamp01(float x)
		{
			if (!(x < 0f))
			{
				if (!(x > 1f))
				{
					return x;
				}
				return 1f;
			}
			return 0f;
		}
	}
	public static class Atlas
	{
		public const int Size = 1024;

		public static readonly UVRect Face = Px(0, 0, 512, 512);

		public static readonly UVRect Chest = Px(512, 0, 1024, 512);

		public static readonly UVRect HatTop = Px(0, 512, 512, 768);

		public static readonly UVRect HatUnder = Px(512, 512, 1024, 768);

		public static readonly UVRect Skin = Px(0, 768, 128, 1024);

		public static readonly UVRect Hair = Px(128, 768, 256, 1024);

		public static readonly UVRect Shorts = Px(256, 768, 384, 1024);

		public static readonly UVRect Shoe = Px(384, 768, 512, 1024);

		public static readonly UVRect Sole = Px(512, 768, 640, 1024);

		public static readonly UVRect Strap = Px(640, 768, 768, 1024);

		public static readonly UVRect SkinShade = Px(768, 768, 896, 1024);

		private static UVRect Px(int x0, int y0, int x1, int y1)
		{
			float num = 1024f;
			return new UVRect((float)(x0 + 3) / num, 1f - (float)(y1 - 3) / num, (float)(x1 - 3) / num, 1f - (float)(y0 + 3) / num);
		}
	}
	public sealed class Part
	{
		public string Name;

		public string Bone;

		public V3 A;

		public V3 B;

		public readonly List<V3> Pos = new List<V3>();

		public readonly List<V3> Nrm = new List<V3>();

		public readonly List<float> U = new List<float>();

		public readonly List<float> V = new List<float>();

		public readonly List<int> Tri = new List<int>();

		private readonly List<int> group = new List<int>();

		public Part(string name, string bone, V3 a, V3 b)
		{
			Name = name;
			Bone = bone;
			A = a;
			B = b;
		}

		public int Add(V3 p, float u, float v, int smoothGroup)
		{
			Pos.Add(p);
			U.Add(u);
			V.Add(v);
			group.Add(smoothGroup);
			Nrm.Add(new V3(0f, 1f, 0f));
			return Pos.Count - 1;
		}

		public void Quad(int bl, int br, int tr, int tl)
		{
			Tri.Add(bl);
			Tri.Add(br);
			Tri.Add(tr);
			Tri.Add(bl);
			Tri.Add(tr);
			Tri.Add(tl);
		}

		public void Transform(Func<V3, V3> f)
		{
			for (int i = 0; i < Pos.Count; i++)
			{
				Pos[i] = f(Pos[i]);
			}
		}

		public void ComputeNormals()
		{
			Dictionary<string, V3> dictionary = new Dictionary<string, V3>();
			string[] array = new string[Pos.Count];
			for (int i = 0; i < Pos.Count; i++)
			{
				V3 v = Pos[i];
				array[i] = group[i] + ":" + Math.Round(v.X * 2000f) + "," + Math.Round(v.Y * 2000f) + "," + Math.Round(v.Z * 2000f);
				if (!dictionary.ContainsKey(array[i]))
				{
					dictionary[array[i]] = new V3(0f, 0f, 0f);
				}
			}
			for (int j = 0; j < Tri.Count; j += 3)
			{
				V3 v2 = Pos[Tri[j]];
				V3 v3 = Pos[Tri[j + 1]];
				V3 v4 = Pos[Tri[j + 2]];
				V3 v5 = V3.Cross(v3 - v2, v4 - v2);
				for (int k = 0; k < 3; k++)
				{
					dictionary[array[Tri[j + k]]] += v5;
				}
			}
			for (int l = 0; l < Pos.Count; l++)
			{
				Nrm[l] = dictionary[array[l]].Normalized;
			}
		}
	}
	public sealed class Rig
	{
		public V3 Hips = new V3(0f, 0.95f, 0f);

		public V3 Neck = new V3(0f, 1.48f, 0f);

		public V3 HeadCenter = new V3(0f, 1.675f, 0.025f);

		public V3 HeadTop = new V3(0f, 1.86f, 0.025f);

		public V3 ShoulderL = new V3(0.33f, 1.4f, 0f);

		public V3 ElbowL = new V3(0.43f, 1.13f, -0.01f);

		public V3 WristL = new V3(0.47f, 0.88f, 0f);

		public V3 HipL = new V3(0.14f, 0.9f, 0f);

		public V3 KneeL = new V3(0.15f, 0.5f, 0.01f);

		public V3 AnkleL = new V3(0.15f, 0.09f, 0f);

		public static V3 Mirror(V3 v)
		{
			return new V3(0f - v.X, v.Y, v.Z);
		}
	}
	public static class TylerBuilder
	{
		private const float Deg = (float)Math.PI / 180f;

		public static List<Part> Build(Rig r)
		{
			List<Part> list = new List<Part>();
			list.Add(Shorts(r));
			list.Add(Torso(r));
			list.Add(NeckPart(r));
			list.Add(Head(r));
			int[] array = new int[2] { 1, -1 };
			foreach (int num in array)
			{
				string text = ((num > 0) ? ".L" : ".R");
				Func<V3, V3> func = ((num > 0) ? ((Func<V3, V3>)((V3 v) => v)) : new Func<V3, V3>(Rig.Mirror));
				list.Add(Limb("upperarm" + text, "upperarm" + text, func(r.ShoulderL), func(r.ElbowL), 0.095f, 0.08f, Atlas.Skin, null, 0f));
				Part part = Limb("lowerarm" + text, "lowerarm" + text, func(r.ElbowL), func(r.WristL), 0.077f, 0.06f, Atlas.Skin, null, 0f);
				V3 normalized = (func(r.WristL) - func(r.ElbowL)).Normalized;
				Ellipsoid(part, 1, func(r.WristL) + normalized * 0.07f, 0.045f, 0.075f, 0.06f, Atlas.Skin);
				list.Add(part);
				list.Add(Limb("thigh" + text, "thigh" + text, func(r.HipL), func(r.KneeL), 0.155f, 0.11f, Atlas.Skin, Atlas.Shorts, 0.5f));
				list.Add(Limb("shin" + text, "shin" + text, func(r.KneeL), func(r.AnkleL), 0.098f, 0.07f, Atlas.Skin, null, 0f));
				list.Add(Foot("foot" + text, func(r.AnkleL)));
			}
			foreach (Part item in list)
			{
				item.ComputeNormals();
			}
			return list;
		}

		private static void Loft(Part p, int group, float cx, float cz, float[] ys, float[] rx, float[] rz, float th0, float th1, int segs, Func<V3, float, float, float[]> uvOf)
		{
			int[,] array = new int[ys.Length, segs + 1];
			for (int i = 0; i < ys.Length; i++)
			{
				for (int j = 0; j <= segs; j++)
				{
					float num = th0 + (th1 - th0) * (float)j / (float)segs;
					V3 v = new V3(cx + rx[i] * (float)Math.Sin(num), ys[i], cz + rz[i] * (float)Math.Cos(num));
					float[] array2 = uvOf(v, num, (float)i / (float)(ys.Length - 1));
					array[i, j] = p.Add(v, array2[0], array2[1], group);
				}
			}
			for (int k = 0; k < ys.Length - 1; k++)
			{
				for (int l = 0; l < segs; l++)
				{
					p.Quad(array[k, l], array[k, l + 1], array[k + 1, l + 1], array[k + 1, l]);
				}
			}
		}

		private static void LoftFrontBack(Part p, int group, float cx, float cz, float[] ys, float[] rx, float[] rz, int segs, UVRect? front, float xMin, float xMax, float yMin, float yMax, UVRect back)
		{
			Func<V3, float, float, float[]> uvOf = (V3 pos, float th, float t) => (!front.HasValue) ? new float[2] { back.CU, back.CV } : new float[2]
			{
				front.Value.U((pos.X - xMin) / (xMax - xMin)),
				front.Value.V((pos.Y - yMin) / (yMax - yMin))
			};
			Func<V3, float, float, float[]> uvOf2 = (V3 pos, float th, float t) => new float[2] { back.CU, back.CV };
			Loft(p, group, cx, cz, ys, rx, rz, -(float)Math.PI / 2f, (float)Math.PI / 2f, segs / 2, uvOf);
			Loft(p, group, cx, cz, ys, rx, rz, (float)Math.PI / 2f, 4.712389f, segs / 2, uvOf2);
		}

		private static void Ellipsoid(Part p, int group, V3 c, float rx, float ry, float rz, UVRect swatch)
		{
			int num = 10;
			float[] array = new float[num + 1];
			float[] array2 = new float[num + 1];
			float[] array3 = new float[num + 1];
			for (int i = 0; i <= num; i++)
			{
				double num2 = -Math.PI / 2.0 + Math.PI * (double)i / (double)num;
				array[i] = c.Y + ry * (float)Math.Sin(num2);
				array2[i] = rx * (float)Math.Cos(num2);
				array3[i] = rz * (float)Math.Cos(num2);
			}
			Loft(p, group, c.X, c.Z, array, array2, array3, 0f, (float)Math.PI * 2f, 14, (V3 pos, float th, float t) => new float[2] { swatch.CU, swatch.CV });
		}

		private static Part Limb(string name, string bone, V3 a, V3 b, float ra, float rb, UVRect swatch, UVRect? top, float split)
		{
			Part part = new Part(name, bone, a, b);
			if (top.HasValue)
			{
				V3 b2 = V3.Lerp(a, b, split);
				float num = ra + (rb - ra) * split;
				Capsule(part, 0, a, b2, ra * 1.06f, num * 1.06f, top.Value, capA: true, capB: false);
				Capsule(part, 1, V3.Lerp(a, b, split - 0.04f), b, num, rb, swatch, capA: false, capB: true);
			}
			else
			{
				Capsule(part, 0, a, b, ra, rb, swatch, capA: true, capB: true);
			}
			return part;
		}

		private static void Capsule(Part p, int group, V3 a, V3 b, float ra, float rb, UVRect swatch, bool capA, bool capB)
		{
			V3 normalized = (b - a).Normalized;
			V3 a2 = ((Math.Abs(normalized.Y) < 0.9f) ? new V3(0f, 1f, 0f) : new V3(0f, 0f, 1f));
			V3 normalized2 = V3.Cross(a2, normalized).Normalized;
			V3 v = V3.Cross(normalized, normalized2);
			float length = (b - a).Length;
			List<float> list = new List<float>();
			List<float> list2 = new List<float>();
			int num = 4;
			if (capA)
			{
				for (int num2 = num; num2 >= 1; num2--)
				{
					double num3 = Math.PI / 2.0 * (double)num2 / (double)num;
					list.Add((0f - ra) * (float)Math.Sin(num3));
					list2.Add(ra * (float)Math.Cos(num3));
				}
			}
			list.Add(0f);
			list2.Add(ra);
			list.Add(length);
			list2.Add(rb);
			if (capB)
			{
				for (int i = 1; i <= num; i++)
				{
					double num4 = Math.PI / 2.0 * (double)i / (double)num;
					list.Add(length + rb * (float)Math.Sin(num4));
					list2.Add(rb * (float)Math.Cos(num4));
				}
			}
			int num5 = 14;
			int[,] array = new int[list.Count, num5 + 1];
			for (int j = 0; j < list.Count; j++)
			{
				for (int k = 0; k <= num5; k++)
				{
					double num6 = Math.PI * 2.0 * (double)k / (double)num5;
					V3 p2 = a + normalized * list[j] + (normalized2 * (float)Math.Cos(num6) + v * (float)Math.Sin(num6)) * list2[j];
					array[j, k] = p.Add(p2, swatch.CU, swatch.CV, group);
				}
			}
			for (int l = 0; l < list.Count - 1; l++)
			{
				for (int m = 0; m < num5; m++)
				{
					p.Quad(array[l, m], array[l, m + 1], array[l + 1, m + 1], array[l + 1, m]);
				}
			}
		}

		private static Part Shorts(Rig r)
		{
			Part part = new Part("shorts", "hips", r.Hips, r.Neck);
			float[] ys = new float[5] { 0.7f, 0.76f, 0.86f, 0.95f, 0.99f };
			float[] rx = new float[5] { 0.25f, 0.28f, 0.29f, 0.285f, 0.28f };
			float[] rz = new float[5] { 0.19f, 0.215f, 0.225f, 0.225f, 0.22f };
			LoftFrontBack(part, 0, 0f, 0f, ys, rx, rz, 28, null, 0f, 1f, 0f, 1f, Atlas.Shorts);
			return part;
		}

		private static Part Torso(Rig r)
		{
			Part part = new Part("torso", "spine", r.Hips, r.Neck);
			float[] ys = new float[9] { 0.93f, 1f, 1.08f, 1.17f, 1.26f, 1.34f, 1.4f, 1.45f, 1.49f };
			float[] rx = new float[9] { 0.275f, 0.305f, 0.315f, 0.305f, 0.295f, 0.28f, 0.255f, 0.2f, 0.11f };
			float[] rz = new float[9] { 0.215f, 0.255f, 0.265f, 0.245f, 0.225f, 0.2f, 0.17f, 0.13f, 0.095f };
			LoftFrontBack(part, 0, 0f, 0f, ys, rx, rz, 32, Atlas.Chest, -0.315f, 0.315f, 0.97f, 1.47f, Atlas.SkinShade);
			return part;
		}

		private static Part NeckPart(Rig r)
		{
			Part part = new Part("neck", "neck", r.Neck, r.HeadCenter);
			float[] ys = new float[3] { 1.42f, 1.5f, 1.57f };
			float[] rx = new float[3] { 0.1f, 0.095f, 0.09f };
			float[] rz = new float[3] { 0.09f, 0.085f, 0.085f };
			LoftFrontBack(part, 0, 0f, 0.01f, ys, rx, rz, 16, null, 0f, 1f, 0f, 1f, Atlas.Skin);
			return part;
		}

		private static Part Head(Rig r)
		{
			Part part = new Part("head", "head", r.Neck, r.HeadTop);
			V3 c = r.HeadCenter;
			float rx = 0.162f;
			float ry = 0.185f;
			float num = 0.165f;
			int num2 = 14;
			float[] array = new float[num2 + 1];
			float[] array2 = new float[num2 + 1];
			float[] array3 = new float[num2 + 1];
			for (int i = 0; i <= num2; i++)
			{
				double num3 = -Math.PI / 2.0 + Math.PI * (double)i / (double)num2;
				array[i] = c.Y + ry * (float)Math.Sin(num3);
				float num4 = 1f + 0.06f * (float)Math.Exp(0.0 - Math.Pow((num3 + 0.35) / 0.45, 2.0));
				array2[i] = rx * num4 * (float)Math.Cos(num3);
				array3[i] = num * (float)Math.Cos(num3);
			}
			float faceTop = c.Y + ry * 0.48f;
			float earLine = c.Y + ry * 0.1f;
			Func<V3, float, float, float[]> uvOf = (V3 pos, float th, float t) => new float[2]
			{
				Atlas.Face.U((pos.X - (c.X - rx)) / (2f * rx)),
				Atlas.Face.V((pos.Y - (c.Y - ry)) / (faceTop - (c.Y - ry)))
			};
			Func<V3, float, float, float[]> uvOf2 = delegate(V3 pos, float th, float t)
			{
				float num31 = Math.Abs(Wrap(th)) / ((float)Math.PI / 180f);
				UVRect uVRect = ((num31 < 112f && pos.Y < earLine) ? Atlas.Skin : Atlas.Hair);
				return new float[2] { uVRect.CU, uVRect.CV };
			};
			Loft(part, 0, c.X, c.Z, array, array2, array3, -1.2217305f, 1.2217305f, 16, uvOf);
			Loft(part, 0, c.X, c.Z, array, array2, array3, 1.2217305f, 5.061455f, 24, uvOf2);
			float num5 = c.Y + ry * 0.55f;
			float num6 = 0.25f;
			float num7 = 0.38f;
			int num8 = 7;
			int num9 = 32;
			float[] array4 = new float[num8 + 1];
			float[] array5 = new float[num8 + 1];
			float[] array6 = new float[num8 + 1];
			float[] array7 = new float[num8 + 1];
			for (int num10 = 0; num10 <= num8; num10++)
			{
				float num11 = (float)num10 / (float)num8;
				array4[num10] = num5 + num6 * num11;
				array5[num10] = num7 * (1f - num11);
				array6[num10] = array4[num10] - 0.012f;
				array7[num10] = array5[num10] * 0.985f;
			}
			Func<V3, float, float, float[]> uvOf3 = (V3 pos, float th, float t) => new float[2]
			{
				Atlas.HatTop.U(Math.Abs(Wrap(th)) / (float)Math.PI),
				Atlas.HatTop.V(1f - t)
			};
			Func<V3, float, float, float[]> func = (V3 pos, float th, float t) => new float[2]
			{
				Atlas.HatUnder.U(Math.Abs(Wrap(th)) / (float)Math.PI),
				Atlas.HatUnder.V(t)
			};
			int count = part.Pos.Count;
			Loft(part, 1, c.X, c.Z + 0.01f, array4, array5, array5, -(float)Math.PI, (float)Math.PI, num9, uvOf3);
			_ = part.Pos.Count;
			int[,] array8 = new int[num8 + 1, num9 + 1];
			for (int num12 = 0; num12 <= num8; num12++)
			{
				for (int num13 = 0; num13 <= num9; num13++)
				{
					float num14 = (-180f + 360f * (float)num13 / (float)num9) * ((float)Math.PI / 180f);
					V3 v = new V3(c.X + array7[num12] * (float)Math.Sin(num14), array6[num12], c.Z + 0.01f + array7[num12] * (float)Math.Cos(num14));
					float[] array9 = func(v, num14, (float)num12 / (float)num8);
					array8[num12, num13] = part.Add(v, array9[0], array9[1], 2);
				}
			}
			for (int num15 = 0; num15 < num8; num15++)
			{
				for (int num16 = 0; num16 < num9; num16++)
				{
					part.Quad(array8[num15, num16], array8[num15 + 1, num16], array8[num15 + 1, num16 + 1], array8[num15, num16 + 1]);
				}
			}
			for (int num17 = 0; num17 < num9; num17++)
			{
				float num18 = (-180f + 360f * (float)num17 / (float)num9) * ((float)Math.PI / 180f);
				float num19 = (-180f + 360f * (float)(num17 + 1) / (float)num9) * ((float)Math.PI / 180f);
				int bl = part.Add(new V3(c.X + array7[0] * (float)Math.Sin(num18), array6[0], c.Z + 0.01f + array7[0] * (float)Math.Cos(num18)), Atlas.HatUnder.U(0.5f), Atlas.HatUnder.V(0.05f), 3);
				int br = part.Add(new V3(c.X + array7[0] * (float)Math.Sin(num19), array6[0], c.Z + 0.01f + array7[0] * (float)Math.Cos(num19)), Atlas.HatUnder.U(0.5f), Atlas.HatUnder.V(0.05f), 3);
				int tr = part.Add(new V3(c.X + array5[0] * (float)Math.Sin(num19), array4[0], c.Z + 0.01f + array5[0] * (float)Math.Cos(num19)), Atlas.HatUnder.U(0.5f), Atlas.HatUnder.V(0.05f), 3);
				int tl = part.Add(new V3(c.X + array5[0] * (float)Math.Sin(num18), array4[0], c.Z + 0.01f + array5[0] * (float)Math.Cos(num18)), Atlas.HatUnder.U(0.5f), Atlas.HatUnder.V(0.05f), 3);
				part.Quad(bl, br, tr, tl);
			}
			float num20 = -0.12217305f;
			V3 pivot = default(V3);
			ref V3 reference = ref pivot;
			reference = new V3(c.X, num5, c.Z);
			float cs = (float)Math.Cos(num20);
			float sn = (float)Math.Sin(num20);
			Func<V3, V3> func2 = delegate(V3 v8)
			{
				V3 v7 = v8 - pivot;
				return pivot + new V3(v7.X * cs - v7.Y * sn, v7.X * sn + v7.Y * cs, v7.Z);
			};
			int count2 = part.Pos.Count;
			int[] array10 = new int[2] { 1, -1 };
			foreach (int num22 in array10)
			{
				V3 v2 = func2(new V3((float)num22 * 0.22f, num5 - 0.012f, c.Z + 0.01f));
				V3 v3 = new V3((float)num22 * 0.19f, c.Y - 0.08f, c.Z + 0.13f);
				V3 v4 = new V3(0f, c.Y - ry - 0.012f, c.Z + 0.07f);
				int num23 = 10;
				int num24 = -1;
				int num25 = -1;
				for (int num26 = 0; num26 <= num23; num26++)
				{
					float num27 = (float)num26 / (float)num23;
					V3 v5 = v2 * ((1f - num27) * (1f - num27)) + v3 * (2f * (1f - num27) * num27) + v4 * (num27 * num27);
					V3 normalized = ((v3 - v2) * (2f * (1f - num27)) + (v4 - v3) * (2f * num27)).Normalized;
					V3 normalized2 = (v5 - c).Normalized;
					V3 v6 = V3.Cross(normalized, normalized2).Normalized * 0.007f;
					int num28 = part.Add(v5 - v6, Atlas.Strap.CU, Atlas.Strap.CV, 4 + num22);
					int num29 = part.Add(v5 + v6, Atlas.Strap.CU, Atlas.Strap.CV, 4 + num22);
					if (num24 >= 0)
					{
						part.Quad(num24, num25, num29, num28);
						part.Quad(num25, num24, num28, num29);
					}
					num24 = num28;
					num25 = num29;
				}
			}
			for (int num30 = count; num30 < count2; num30++)
			{
				part.Pos[num30] = func2(part.Pos[num30]);
			}
			return part;
		}

		private static Part Foot(string name, V3 ankle)
		{
			Part part = new Part(name, "foot" + name.Substring(4), ankle, ankle + new V3(0f, -0.07f, 0.16f));
			Ellipsoid(part, 0, new V3(ankle.X, 0.055f, ankle.Z + 0.055f), 0.065f, 0.055f, 0.135f, Atlas.Shoe);
			Ellipsoid(part, 1, new V3(ankle.X, 0.012f, ankle.Z + 0.055f), 0.068f, 0.012f, 0.138f, Atlas.Sole);
			return part;
		}

		private static float Wrap(float th)
		{
			while ((double)th > Math.PI)
			{
				th -= (float)Math.PI * 2f;
			}
			while ((double)th < -Math.PI)
			{
				th += (float)Math.PI * 2f;
			}
			return th;
		}
	}
}
namespace TylerWu
{
	public static class TylerRegistry
	{
		public const uint NetworkHash = 2047994049u;

		public static Item Item;

		public static GameObject Prefab;

		public static bool NetworkRegistered;

		public static string SourceItemName = "";

		private static readonly string[] PreferredSources = new string[7] { "Toy cube", "Rubber Ducky", "Magnifying glass", "Perfume bottle", "Toothpaste", "Mug", "Hairdryer" };

		public static void CreateAndRegister()
		{
			if ((Object)(object)Prefab == (Object)null)
			{
				Create();
			}
			if ((Object)(object)Prefab != (Object)null && !NetworkRegistered && (Object)(object)NetworkManager.Singleton != (Object)null)
			{
				NetworkManager.Singleton.AddNetworkPrefab(Prefab);
				NetworkRegistered = true;
				Plugin.Log.LogInfo((object)("Tyler Wu scrap registered (based on '" + SourceItemName + "')."));
			}
		}

		private static bool Usable(Item it)
		{
			if ((Object)(object)it == (Object)null || (Object)(object)it.spawnPrefab == (Object)null || !it.isScrap || it.twoHanded)
			{
				return false;
			}
			GrabbableObject component = it.spawnPrefab.GetComponent<GrabbableObject>();
			if ((Object)(object)component != (Object)null && ((object)component).GetType() == typeof(PhysicsProp))
			{
				return (Object)(object)it.spawnPrefab.GetComponent<NetworkObject>() != (Object)null;
			}
			return false;
		}

		private static Item PickSource()
		{
			Item[] array = Resources.FindObjectsOfTypeAll<Item>();
			string[] preferredSources = PreferredSources;
			foreach (string text in preferredSources)
			{
				Item[] array2 = array;
				foreach (Item val in array2)
				{
					if (val.itemName == text && Usable(val))
					{
						return val;
					}
				}
			}
			Item[] array3 = array;
			foreach (Item val2 in array3)
			{
				if (Usable(val2))
				{
					return val2;
				}
			}
			return null;
		}

		private static void Create()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01c2: 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_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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_039a: 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_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: 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_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_02dc: Unknown result type (might be due to invalid IL or missing references)
			Item val = PickSource();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"No vanilla scrap item to build Tyler Wu from.");
				return;
			}
			SourceItemName = val.itemName;
			GameObject val2 = new GameObject("TylerWuPrefabs");
			((Object)val2).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)val2);
			val2.SetActive(false);
			GameObject val3 = Object.Instantiate<GameObject>(val.spawnPrefab, val2.transform);
			((Object)val3).name = "TylerWuScrap";
			Vector3 localScale = val3.transform.localScale;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(1f / localScale.x, 1f / localScale.y, 1f / localScale.z);
			GrabbableObject component = val3.GetComponent<GrabbableObject>();
			TylerItem tylerItem = val3.AddComponent<TylerItem>();
			FieldInfo[] fields = typeof(GrabbableObject).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(tylerItem, fieldInfo.GetValue(component));
			}
			Object.DestroyImmediate((Object)(object)component);
			LODGroup[] componentsInChildren = val3.GetComponentsInChildren<LODGroup>(true);
			foreach (LODGroup val5 in componentsInChildren)
			{
				Object.DestroyImmediate((Object)(object)val5);
			}
			SkinnedMeshRenderer[] componentsInChildren2 = val3.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val6 in componentsInChildren2)
			{
				Object.DestroyImmediate((Object)(object)val6);
			}
			MeshRenderer[] componentsInChildren3 = val3.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val7 in componentsInChildren3)
			{
				MeshFilter component2 = ((Component)val7).GetComponent<MeshFilter>();
				Object.DestroyImmediate((Object)(object)val7);
				if ((Object)(object)component2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component2);
				}
			}
			GameObject val8 = new GameObject("TylerFigurine");
			val8.layer = val3.layer;
			val8.transform.SetParent(val3.transform, false);
			val8.transform.localRotation = Quaternion.identity;
			val8.transform.localScale = val4;
			val8.AddComponent<MeshFilter>().sharedMesh = TylerAssets.Figurine;
			MeshRenderer val9 = val8.AddComponent<MeshRenderer>();
			((Renderer)val9).sharedMaterial = TylerAssets.Material;
			((GrabbableObject)tylerItem).mainObjectRenderer = val9;
			bool flag = false;
			Collider[] components = val3.GetComponents<Collider>();
			foreach (Collider val10 in components)
			{
				flag |= val10.isTrigger;
				Object.DestroyImmediate((Object)(object)val10);
			}
			BoxCollider val11 = val3.AddComponent<BoxCollider>();
			((Collider)val11).isTrigger = flag;
			float num = 0.3f;
			val11.size = Vector3.Scale(new Vector3(0.2f, num, 0.18f), val4);
			val11.center = Vector3.Scale(new Vector3(0f, num * 0.5f, 0f), val4);
			ScanNodeProperties componentInChildren = val3.GetComponentInChildren<ScanNodeProperties>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.headerText = "Tyler Wu";
				((Component)componentInChildren).transform.localPosition = Vector3.Scale(new Vector3(0f, num * 0.6f, 0f), val4);
			}
			Item val12 = Object.Instantiate<Item>(val);
			((Object)val12).name = "TylerWuItem";
			val12.itemName = "Tyler Wu";
			val12.spawnPrefab = val3;
			val12.isScrap = true;
			val12.minValue = Math.Max(1, Plugin.MinValue.Value);
			val12.maxValue = Math.Max(val12.minValue, Plugin.MaxValue.Value);
			val12.weight = 1.12f;
			val12.twoHanded = false;
			val12.twoHandedAnimation = false;
			val12.syncUseFunction = true;
			val12.holdButtonUse = false;
			val12.requiresBattery = false;
			val12.toolTips = new string[1] { "Consume Tyler : [LMB]" };
			val12.restingRotation = Vector3.zero;
			val12.verticalOffset = 0.02f;
			val12.floorYOffset = 0;
			val12.meshVariants = (Mesh[])(object)new Mesh[0];
			val12.materialVariants = (Material[])(object)new Material[0];
			val12.itemId = 8137;
			val12.canBeInspected = false;
			val12.isConductiveMetal = false;
			val12.saveItemVariable = false;
			val12.positionOffset = new Vector3(0f, 0.02f, 0.06f);
			val12.rotationOffset = new Vector3(87.4f, 104.9f, 2.7f);
			((GrabbableObject)tylerItem).itemProperties = val12;
			((GrabbableObject)tylerItem).grabbable = true;
			NetworkObject component3 = val3.GetComponent<NetworkObject>();
			FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			field.SetValue(component3, 2047994049u);
			Item = val12;
			Prefab = val3;
		}

		public static void AddToGame(StartOfRound sor)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			if ((Object)(object)Item == (Object)null || (Object)(object)sor == (Object)null)
			{
				return;
			}
			if (!sor.allItemsList.itemsList.Contains(Item))
			{
				sor.allItemsList.itemsList.Add(Item);
			}
			int num = 0;
			SelectableLevel[] levels = sor.levels;
			foreach (SelectableLevel val in levels)
			{
				if ((Object)(object)val == (Object)null || val.spawnableScrap == null || val.spawnableScrap.Count == 0)
				{
					continue;
				}
				SpawnableItemWithRarity val2 = null;
				foreach (SpawnableItemWithRarity item in val.spawnableScrap)
				{
					if ((Object)(object)item.spawnableItem == (Object)(object)Item)
					{
						val2 = item;
					}
				}
				if (val2 == null && Plugin.Rarity.Value > 0)
				{
					val.spawnableScrap.Add(new SpawnableItemWithRarity(Item, Plugin.Rarity.Value));
				}
				else if (val2 != null)
				{
					val2.rarity = Plugin.Rarity.Value;
				}
				num++;
			}
			Plugin.Log.LogInfo((object)("Tyler Wu added to " + num + " moons (rarity " + Plugin.Rarity.Value + ")."));
		}

		public static int MoonsWithTyler(StartOfRound sor)
		{
			int num = 0;
			SelectableLevel[] levels = sor.levels;
			foreach (SelectableLevel val in levels)
			{
				if (!((Object)(object)val != (Object)null) || val.spawnableScrap == null)
				{
					continue;
				}
				foreach (SpawnableItemWithRarity item in val.spawnableScrap)
				{
					if ((Object)(object)item.spawnableItem == (Object)(object)Item)
					{
						num++;
						break;
					}
				}
			}
			return num;
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Start")]
	internal static class RegisterPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			try
			{
				TylerRegistry.CreateAndRegister();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Registering Tyler Wu failed: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	internal static class LevelsPatch
	{
		[HarmonyPostfix]
		private static void Postfix(StartOfRound __instance)
		{
			try
			{
				TylerRegistry.AddToGame(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Adding Tyler Wu to moons failed: " + ex));
			}
		}
	}
	public class TylerSkin : MonoBehaviour
	{
		private class Built
		{
			public int Bone;

			public Mesh Mesh;

			public string Name;
		}

		public static string LastBoneDump = "";

		public string Report = "";

		public bool Retargeted;

		public bool FromTyler;

		public bool Showing;

		private MaskedPlayerEnemy masked;

		private SkinnedMeshRenderer body;

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

		private readonly HashSet<Renderer> hidden = new HashSet<Renderer>();

		private readonly List<MeshRenderer> parts = new List<MeshRenderer>();

		private float nextRescan;

		private static readonly Dictionary<Mesh, List<Built>> cache = new Dictionary<Mesh, List<Built>>();

		private static readonly Dictionary<Mesh, string> cacheReport = new Dictionary<Mesh, string>();

		private static readonly Dictionary<string, string[]> Names = new Dictionary<string, string[]>
		{
			{
				"hips",
				new string[3] { "spine", "hips", "pelvis" }
			},
			{
				"spine",
				new string[4] { "spine.002", "spine.001", "chest", "spine1" }
			},
			{
				"neck",
				new string[2] { "neck", "neck.001" }
			},
			{
				"head",
				new string[2] { "spine.004", "head" }
			},
			{
				"upperarm.L",
				new string[5] { "arm.l_upper", "upper_arm.l", "upperarm.l", "upperarm_l", "leftupperarm" }
			},
			{
				"lowerarm.L",
				new string[5] { "arm.l_lower", "forearm.l", "lowerarm.l", "lowerarm_l", "leftlowerarm" }
			},
			{
				"hand.L",
				new string[3] { "hand.l", "hand_l", "lefthand" }
			},
			{
				"thigh.L",
				new string[5] { "thigh.l", "upperleg.l", "thigh_l", "upper_leg.l", "leftupperleg" }
			},
			{
				"shin.L",
				new string[6] { "shin.l", "calf.l", "lowerleg.l", "shin_l", "lower_leg.l", "leftlowerleg" }
			},
			{
				"foot.L",
				new string[3] { "foot.l", "foot_l", "leftfoot" }
			},
			{
				"toe.L",
				new string[4] { "toe.l", "toes.l", "toe_l", "lefttoes" }
			},
			{
				"upperarm.R",
				new string[5] { "arm.r_upper", "upper_arm.r", "upperarm.r", "upperarm_r", "rightupperarm" }
			},
			{
				"lowerarm.R",
				new string[5] { "arm.r_lower", "forearm.r", "lowerarm.r", "lowerarm_r", "rightlowerarm" }
			},
			{
				"hand.R",
				new string[3] { "hand.r", "hand_r", "righthand" }
			},
			{
				"thigh.R",
				new string[5] { "thigh.r", "upperleg.r", "thigh_r", "upper_leg.r", "rightupperleg" }
			},
			{
				"shin.R",
				new string[6] { "shin.r", "calf.r", "lowerleg.r", "shin_r", "lower_leg.r", "rightlowerleg" }
			},
			{
				"foot.R",
				new string[3] { "foot.r", "foot_r", "rightfoot" }
			},
			{
				"toe.R",
				new string[4] { "toe.r", "toes.r", "toe_r", "righttoes" }
			}
		};

		private static readonly Dictionary<string, string> EndOf = new Dictionary<string, string>
		{
			{ "upperarm.L", "lowerarm.L" },
			{ "lowerarm.L", "hand.L" },
			{ "thigh.L", "shin.L" },
			{ "shin.L", "foot.L" },
			{ "foot.L", "toe.L" },
			{ "upperarm.R", "lowerarm.R" },
			{ "lowerarm.R", "hand.R" },
			{ "thigh.R", "shin.R" },
			{ "shin.R", "foot.R" },
			{ "foot.R", "toe.R" }
		};

		public int PartCount => parts.Count;

		public void Init(MaskedPlayerEnemy m, bool fromTyler)
		{
			masked = m;
			FromTyler = fromTyler;
			body = m.rendererLOD0;
			if ((Object)(object)body == (Object)null || (Object)(object)body.sharedMesh == (Object)null || body.bones == null || body.bones.Length == 0)
			{
				body = null;
				int num = 0;
				SkinnedMeshRenderer[] componentsInChildren = ((Component)m).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val in componentsInChildren)
				{
					if ((Object)(object)val.sharedMesh != (Object)null && val.bones != null && val.bones.Length > num)
					{
						num = val.bones.Length;
						body = val;
					}
				}
			}
			Renderer[] array = (Renderer[])(object)new Renderer[3]
			{
				(Renderer)m.rendererLOD0,
				(Renderer)m.rendererLOD1,
				(Renderer)m.rendererLOD2
			};
			foreach (Renderer val2 in array)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					lods.Add(val2);
				}
			}
			if ((Object)(object)body != (Object)null && !lods.Contains((Renderer)(object)body))
			{
				lods.Add((Renderer)(object)body);
			}
			HideOriginals();
			List<Built> value = null;
			if ((Object)(object)body != (Object)null)
			{
				if (cache.TryGetValue(body.sharedMesh, out value))
				{
					Report = cacheReport[body.sharedMesh];
				}
				else
				{
					try
					{
						value = Retarget(body, out var report);
						cache[body.sharedMesh] = value;
						cacheReport[body.sharedMesh] = report;
						Report = report;
					}
					catch (Exception ex)
					{
						Report = "bones not matched (" + ex.Message + "), using a rigid Tyler";
						value = null;
					}
				}
			}
			if (value != null)
			{
				Retargeted = true;
				Transform[] bones = body.bones;
				foreach (Built item in value)
				{
					AddPart(item.Name, bones[item.Bone], item.Mesh);
				}
			}
			else
			{
				AddPart("whole", ((Component)masked).transform, TylerAssets.Combined(1.9f / TylerAssets.ModelHeight, "TylerRigid"));
			}
			LateUpdate();
			Plugin.Log.LogInfo((object)("Masked dressed as Tyler (" + parts.Count + " parts). " + Report));
		}

		private void AddPart(string name, Transform parent, Mesh mesh)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_005a: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TylerPart_" + name);
			val.layer = (((Object)(object)body != (Object)null) ? ((Component)body).gameObject.layer : ((Component)masked).gameObject.layer);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			((Renderer)val2).sharedMaterial = TylerAssets.Material;
			parts.Add(val2);
		}

		private void HideOriginals()
		{
			Renderer[] componentsInChildren = ((Component)masked).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !hidden.Contains(val) && !((Object)((Component)val).gameObject).name.StartsWith("TylerPart_"))
				{
					val.forceRenderingOff = true;
					hidden.Add(val);
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)masked == (Object)null)
			{
				return;
			}
			bool flag = lods.Count == 0;
			int num = (((Object)(object)body != (Object)null) ? ((Component)body).gameObject.layer : ((Component)masked).gameObject.layer);
			foreach (Renderer lod in lods)
			{
				if ((Object)(object)lod != (Object)null && lod.enabled && ((Component)lod).gameObject.activeInHierarchy && ((Component)lod).gameObject.layer != 23)
				{
					flag = true;
					num = ((Component)lod).gameObject.layer;
					break;
				}
			}
			Showing = flag;
			foreach (MeshRenderer part in parts)
			{
				if (!((Object)(object)part == (Object)null))
				{
					((Renderer)part).enabled = flag;
					if (((Component)part).gameObject.layer != num)
					{
						((Component)part).gameObject.layer = num;
					}
				}
			}
			if (Time.time >= nextRescan)
			{
				nextRescan = Time.time + 1f;
				HideOriginals();
			}
		}

		private static List<Built> Retarget(SkinnedMeshRenderer smr, out string report)
		{
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: 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_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: 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_02df: 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_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: 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_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: 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_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: 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_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: 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_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0657: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_068b: 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_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0642: Unknown result type (might be due to invalid IL or missing references)
			//IL_0647: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_070a: Unknown result type (might be due to invalid IL or missing references)
			//IL_070f: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0734: Unknown result type (might be due to invalid IL or missing references)
			//IL_0739: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_0771: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_081f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Expected O, but got Unknown
			Transform[] bones = smr.bones;
			Matrix4x4[] bind = smr.sharedMesh.bindposes;
			if (bind.Length != bones.Length)
			{
				throw new Exception("bind poses don't match bones");
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < bones.Length; i++)
			{
				if (!((Object)(object)bones[i] == (Object)null))
				{
					string key = ((Object)bones[i]).name.ToLowerInvariant();
					if (!dictionary.ContainsKey(key))
					{
						dictionary[key] = i;
					}
					stringBuilder.Append(((Object)bones[i]).name).Append(' ');
				}
			}
			LastBoneDump = stringBuilder.ToString();
			Dictionary<string, int> idx = new Dictionary<string, int>();
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, string[]> name in Names)
			{
				int num = -1;
				string[] value = name.Value;
				foreach (string key2 in value)
				{
					if (dictionary.TryGetValue(key2, out var value2))
					{
						num = value2;
						break;
					}
				}
				idx[name.Key] = num;
				if (num < 0 && name.Key != "neck" && name.Key != "spine" && !name.Key.StartsWith("toe"))
				{
					list.Add(name.Key);
				}
			}
			if (list.Count > 0)
			{
				throw new Exception("missing " + string.Join(",", list.ToArray()));
			}
			if (idx["spine"] < 0)
			{
				idx["spine"] = idx["hips"];
			}
			if (idx["neck"] < 0)
			{
				idx["neck"] = idx["head"];
			}
			Func<string, Vector3> func = delegate(string key3)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				Matrix4x4 inverse = ((Matrix4x4)(ref bind[idx[key3]])).inverse;
				return ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
			};
			Vector3 val = func("head") - func("hips");
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = func("thigh.R") - func("thigh.L");
			val2 -= normalized * Vector3.Dot(val2, normalized);
			Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
			Vector3 val3 = Vector3.Cross(normalized2, normalized);
			Vector3 normalized3 = ((Vector3)(ref val3)).normalized;
			Quaternion R = Quaternion.LookRotation(normalized3, normalized);
			Rig rig = TylerAssets.Rig;
			Vector3 val4 = (func("foot.L") + func("foot.R")) * 0.5f;
			float num2 = Vector3.Dot(func("head") - val4, normalized) / (rig.Neck.Y - rig.AnkleL.Y);
			if (!(num2 > 0.0001f) || float.IsInfinity(num2))
			{
				throw new Exception("bad scale " + num2);
			}
			float num3 = Mathf.Clamp(Vector3.Dot(func("head") - func("hips"), normalized) / (num2 * (rig.Neck.Y - rig.Hips.Y)), 0.6f, 1.6f);
			List<Built> list2 = new List<Built>();
			foreach (Part part in TylerAssets.Parts)
			{
				int num4;
				Func<Vector3, Vector3> func2;
				Quaternion val13;
				if (EndOf.TryGetValue(part.Bone, out var value3))
				{
					num4 = idx[part.Bone];
					Vector3 A = TylerAssets.U(part.A);
					Vector3 val5 = TylerAssets.U(part.B);
					Vector3 val6 = val5 - A;
					Vector3 dirC = ((Vector3)(ref val6)).normalized;
					Vector3 val7 = val5 - A;
					float magnitude = ((Vector3)(ref val7)).magnitude;
					Vector3 PA = func(part.Bone);
					Quaternion val8 = Quaternion.identity;
					float num5 = 1f;
					if (idx[value3] >= 0)
					{
						Vector3 val9 = func(value3);
						Vector3 val10 = R * dirC;
						Vector3 val11 = val9 - PA;
						val8 = Quaternion.FromToRotation(val10, ((Vector3)(ref val11)).normalized);
						Vector3 val12 = val9 - PA;
						num5 = Mathf.Clamp(((Vector3)(ref val12)).magnitude / (num2 * magnitude), 0.4f, 2.5f);
					}
					Quaternion QR = val8 * R;
					float kk = num5;
					float ss = num2;
					func2 = delegate(Vector3 c)
					{
						//IL_0000: 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_000c: 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_000f: 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_001c: Unknown result type (might be due to invalid IL or missing references)
						//IL_0022: Unknown result type (might be due to invalid IL or missing references)
						//IL_0027: Unknown result type (might be due to invalid IL or missing references)
						//IL_002c: 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_0034: 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_0047: Unknown result type (might be due to invalid IL or missing references)
						//IL_004c: Unknown result type (might be due to invalid IL or missing references)
						//IL_004d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0058: Unknown result type (might be due to invalid IL or missing references)
						//IL_005d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0062: Unknown result type (might be due to invalid IL or missing references)
						Vector3 val20 = c - A;
						float num9 = Vector3.Dot(val20, dirC);
						Vector3 val21 = val20 - dirC * num9;
						return PA + QR * ((dirC * (num9 * kk) + val21) * ss);
					};
					val13 = QR;
				}
				else
				{
					float num6 = 1f;
					Vector3 anchorC;
					Vector3 anchorG;
					if (part.Bone == "hips" || part.Bone == "spine")
					{
						anchorC = TylerAssets.U(rig.Hips);
						anchorG = func("hips");
						num6 = num3;
					}
					else
					{
						anchorC = TylerAssets.U(rig.Neck);
						anchorG = func("head");
					}
					num4 = idx[(part.Bone == "hips") ? "hips" : ((part.Bone == "spine") ? "spine" : ((part.Bone == "neck") ? "neck" : "head"))];
					float ss2 = num2;
					float kvv = num6;
					func2 = delegate(Vector3 c)
					{
						//IL_0000: 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_000c: 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_0019: 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_0059: Unknown result type (might be due to invalid IL or missing references)
						Vector3 val20 = c - anchorC;
						return anchorG + R * new Vector3(val20.x * ss2, val20.y * ss2 * kvv, val20.z * ss2);
					};
					val13 = R;
				}
				Matrix4x4 val14 = bind[num4];
				Vector3 val15 = Vector4.op_Implicit(((Matrix4x4)(ref val14)).GetColumn(0));
				Vector3 val16 = Vector4.op_Implicit(((Matrix4x4)(ref val14)).GetColumn(1));
				Vector3 val17 = Vector4.op_Implicit(((Matrix4x4)(ref val14)).GetColumn(2));
				bool flag = Vector3.Dot(Vector3.Cross(val15, val16), val17) < 0f;
				Vector3[] array = (Vector3[])(object)new Vector3[part.Pos.Count];
				Vector3[] array2 = (Vector3[])(object)new Vector3[part.Pos.Count];
				Vector2[] array3 = (Vector2[])(object)new Vector2[part.Pos.Count];
				for (int num7 = 0; num7 < array.Length; num7++)
				{
					ref Vector3 reference = ref array[num7];
					reference = ((Matrix4x4)(ref val14)).MultiplyPoint3x4(func2(TylerAssets.U(part.Pos[num7])));
					ref Vector3 reference2 = ref array2[num7];
					Vector3 val18 = ((Matrix4x4)(ref val14)).MultiplyVector(val13 * TylerAssets.U(part.Nrm[num7]));
					reference2 = ((Vector3)(ref val18)).normalized;
					ref Vector2 reference3 = ref array3[num7];
					reference3 = new Vector2(part.U[num7], part.V[num7]);
				}
				int[] array4 = new int[part.Tri.Count];
				for (int num8 = 0; num8 < array4.Length; num8 += 3)
				{
					array4[num8] = part.Tri[num8];
					array4[num8 + 1] = (flag ? part.Tri[num8 + 1] : part.Tri[num8 + 2]);
					array4[num8 + 2] = (flag ? part.Tri[num8 + 2] : part.Tri[num8 + 1]);
				}
				Mesh val19 = new Mesh();
				((Object)val19).name = "Tyler_" + part.Name;
				val19.vertices = array;
				val19.normals = array2;
				val19.uv = array3;
				val19.triangles = array4;
				val19.RecalculateBounds();
				Built built = new Built();
				built.Bone = num4;
				built.Mesh = val19;
				built.Name = part.Name;
				list2.Add(built);
			}
			report = "Fitted to skeleton: hips=" + ((Object)bones[idx["hips"]]).name + " spine=" + ((Object)bones[idx["spine"]]).name + " head=" + ((Object)bones[idx["head"]]).name + " arm=" + ((Object)bones[idx["upperarm.L"]]).name + " leg=" + ((Object)bones[idx["thigh.L"]]).name + " scale=" + num2.ToString("F3") + " torsoStretch=" + num3.ToString("F2") + " forward=" + ((Vector3)(ref normalized3)).ToString("F2") + " up=" + ((Vector3)(ref normalized)).ToString("F2");
			return list2;
		}
	}
}