Decompiled source of MysticalWeapons BETA v1.6.7

plugins/MysticalWeapons.dll

Decompiled 10 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MysticalWeapons.Armor;
using MysticalWeapons.Hallows;
using MysticalWeapons.Weapons;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("ModelExporter")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MysticalWeapons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+34721825d4570e2931c33f0595554b7864ca7c58")]
[assembly: AssemblyProduct("MysticalWeapons")]
[assembly: AssemblyTitle("MysticalWeapons")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MysticalWeapons
{
	internal static class ItemReport
	{
		private static ConfigEntry<bool> _enabled;

		private static bool _done;

		private const int Layer = 31;

		private const int Panel = 512;

		private static readonly Vector3 Stage = new Vector3(0f, 5000f, 0f);

		private static string OutputDir => Path.Combine(Paths.BepInExRootPath, "MysticalItemReport");

		public static void BindConfig(ConfigFile cfg)
		{
			_enabled = cfg.Bind<bool>("Debug", "ItemReport", false, "For mod developers: on startup, compare how each item looks next to its vanilla peer (log + images in BepInEx/MysticalItemReport).");
		}

		public static void Schedule(ObjectDB db)
		{
			if (!_done && _enabled != null && _enabled.Value && Object.op_Implicit((Object)(object)Plugin.Instance))
			{
				_done = true;
				((MonoBehaviour)Plugin.Instance).StartCoroutine(Run(db));
			}
		}

		private static IEnumerator Run(ObjectDB db)
		{
			yield return null;
			if (!Object.op_Implicit((Object)(object)db))
			{
				yield break;
			}
			try
			{
				Directory.CreateDirectory(OutputDir);
				StringBuilder stringBuilder = new StringBuilder();
				List<GameObject> vanilla = VanillaCraftables(db);
				foreach (MysticalItem item in Plugin.Items)
				{
					if (item.Enabled.Value && Object.op_Implicit((Object)(object)item.Prefab))
					{
						string text = item.VanillaPeer ?? item.SourceName;
						GameObject itemPrefab = db.GetItemPrefab(text);
						stringBuilder.Append(Describe(item.Prefab, itemPrefab, text, vanilla));
						if (Object.op_Implicit((Object)(object)itemPrefab))
						{
							Render(item.Prefab, itemPrefab, Path.Combine(OutputDir, item.PrefabName + ".png"));
						}
					}
				}
				File.WriteAllText(Path.Combine(OutputDir, "report.txt"), stringBuilder.ToString());
				Plugin.Log.LogInfo((object)("Item report (left: mystical item, right: vanilla peer; images in " + OutputDir + "):\n" + stringBuilder));
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Item report failed: {arg}");
			}
		}

		private static string Describe(GameObject ours, GameObject peer, string peerName, List<GameObject> vanilla)
		{
			List<string[]> list = new List<string[]>
			{
				Row("Triangles", ours, peer, (GameObject p) => Triangles(p, worn: false).ToString()),
				Row("Worn triangles", ours, peer, (GameObject p) => Triangles(p, worn: true).ToString()),
				Row("Textures", ours, peer, Textures)
			};
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("== " + ((Object)ours).name + " vs " + (Object.op_Implicit((Object)(object)peer) ? ((Object)peer).name : (peerName + " (not found)")) + " ==");
			int totalWidth = list.Max((string[] r) => r[0].Length) + 2;
			int totalWidth2 = list.Max((string[] r) => r[1].Length) + 3;
			foreach (string[] item in list)
			{
				if (!(item[1] == item[2]) || (!(item[1] == "0") && !(item[1] == "-")))
				{
					stringBuilder.AppendLine(item[0].PadRight(totalWidth) + item[1].PadRight(totalWidth2) + item[2]);
				}
			}
			stringBuilder.AppendLine("Max in slot".PadRight(totalWidth) + MaxInSlot(ours, vanilla));
			stringBuilder.AppendLine();
			return stringBuilder.ToString();
		}

		private static List<GameObject> VanillaCraftables(ObjectDB db)
		{
			HashSet<string> ours = new HashSet<string>(Plugin.Items.Select((MysticalItem i) => i.PrefabName));
			return (from r in db.m_recipes
				where Object.op_Implicit((Object)(object)r) && r.m_enabled && Object.op_Implicit((Object)(object)r.m_item) && !ours.Contains(((Object)r.m_item).name)
				select ((Component)r.m_item).gameObject).Distinct().ToList();
		}

		private static IEnumerable<GameObject> SameSlot(GameObject prefab, List<GameObject> vanilla)
		{
			return vanilla.Where((GameObject p) => Shared(p).m_itemType == Shared(prefab).m_itemType && Shared(p).m_skillType == Shared(prefab).m_skillType);
		}

		private static string MaxInSlot(GameObject ours, List<GameObject> vanilla)
		{
			List<GameObject> list = SameSlot(ours, vanilla).ToList();
			if (list.Count == 0)
			{
				return "-";
			}
			GameObject val = list.OrderByDescending((GameObject p) => Triangles(p, worn: false)).First();
			string text = $"{((Object)val).name}: {Triangles(val, worn: false)}";
			if (!IsArmor(ours))
			{
				return text;
			}
			GameObject val2 = list.OrderByDescending((GameObject p) => Triangles(p, worn: true)).First();
			return text + $" (worn: {((Object)val2).name}: {Triangles(val2, worn: true)})";
		}

		private static string[] Row(string label, GameObject ours, GameObject peer, Func<GameObject, string> value)
		{
			return new string[3]
			{
				label,
				value(ours),
				Object.op_Implicit((Object)(object)peer) ? value(peer) : "?"
			};
		}

		private static SharedData Shared(GameObject prefab)
		{
			return prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
		}

		private static bool IsArmor(GameObject prefab)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			ItemType itemType = Shared(prefab).m_itemType;
			if ((int)itemType != 6 && (int)itemType != 7 && (int)itemType != 11)
			{
				return (int)itemType == 17;
			}
			return true;
		}

		private static int Triangles(GameObject prefab, bool worn)
		{
			List<Renderer> list = Renderers(prefab, worn);
			if (worn && list.Count == 0 && IsArmor(prefab))
			{
				list = (from r in Renderers(prefab, worn: false)
					where UnderAttach(prefab, r)
					select r).ToList();
			}
			int num = 0;
			foreach (Renderer item in list)
			{
				Mesh val = MeshOf(item);
				if (Object.op_Implicit((Object)(object)val))
				{
					for (int num2 = 0; num2 < val.subMeshCount; num2++)
					{
						num += (int)val.GetIndexCount(num2) / 3;
					}
				}
			}
			return num;
		}

		private static string Textures(GameObject prefab)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			HashSet<Texture> hashSet = new HashSet<Texture>();
			foreach (Renderer item in Renderers(prefab, worn: false).Concat(Renderers(prefab, worn: true)))
			{
				Material[] sharedMaterials = item.sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val) && val.HasProperty("_MainTex"))
					{
						Texture texture = val.GetTexture("_MainTex");
						if (Object.op_Implicit((Object)(object)texture) && hashSet.Add(texture))
						{
							string key = $"{texture.width}x{texture.height}";
							dictionary[key] = ((!dictionary.TryGetValue(key, out var value)) ? 1 : (value + 1));
						}
					}
				}
			}
			if (dictionary.Count != 0)
			{
				return string.Join(", ", dictionary.Select((KeyValuePair<string, int> kv) => (kv.Value <= 1) ? kv.Key : $"{kv.Key} x{kv.Value}"));
			}
			return "none";
		}

		private static List<Renderer> Renderers(GameObject prefab, bool worn)
		{
			HashSet<Renderer> hashSet = new HashSet<Renderer>();
			LODGroup[] componentsInChildren = prefab.GetComponentsInChildren<LODGroup>(true);
			Renderer[] renderers;
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				LOD[] lODs = componentsInChildren[i].GetLODs();
				for (int j = 1; j < lODs.Length; j++)
				{
					renderers = lODs[j].renderers;
					foreach (Renderer val in renderers)
					{
						if (Object.op_Implicit((Object)(object)val))
						{
							hashSet.Add(val);
						}
					}
				}
			}
			List<Renderer> list = new List<Renderer>();
			renderers = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in renderers)
			{
				if (!val2.enabled || hashSet.Contains(val2) || (!(val2 is MeshRenderer) && !(val2 is SkinnedMeshRenderer)))
				{
					continue;
				}
				bool flag = false;
				bool flag2 = false;
				Transform val3 = ((Component)val2).transform;
				while (Object.op_Implicit((Object)(object)val3) && (Object)(object)val3 != (Object)(object)prefab.transform)
				{
					if (((Object)val3).name == "attach_skin")
					{
						flag = true;
					}
					else if (!((Component)val3).gameObject.activeSelf)
					{
						flag2 = true;
					}
					val3 = val3.parent;
				}
				if (!flag2 && flag == worn)
				{
					list.Add(val2);
				}
			}
			return list;
		}

		private static bool UnderAttach(GameObject prefab, Renderer r)
		{
			Transform val = ((Component)r).transform;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)prefab.transform)
			{
				if (((Object)val).name == "attach")
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private static Mesh MeshOf(Renderer r)
		{
			SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
			if (val == null)
			{
				MeshFilter component = ((Component)r).GetComponent<MeshFilter>();
				if (component == null)
				{
					return null;
				}
				return component.sharedMesh;
			}
			return val.sharedMesh;
		}

		private static GameObject VisualCopy(GameObject prefab)
		{
			//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)
			//IL_001e: Expected O, but got Unknown
			//IL_0024: 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_0039: 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_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ItemReport_" + ((Object)prefab).name)
			{
				layer = 31
			};
			val.transform.position = Stage;
			Matrix4x4 worldToLocalMatrix = prefab.transform.worldToLocalMatrix;
			foreach (Renderer item in Renderers(prefab, worn: false))
			{
				Mesh val2 = MeshOf(item);
				if (Object.op_Implicit((Object)(object)val2))
				{
					Matrix4x4 val3 = worldToLocalMatrix * ((Component)item).transform.localToWorldMatrix;
					GameObject val4 = new GameObject(((Object)item).name)
					{
						layer = 31
					};
					val4.transform.SetParent(val.transform, false);
					val4.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val3)).GetColumn(3));
					val4.transform.localRotation = ((Matrix4x4)(ref val3)).rotation;
					val4.transform.localScale = ((Matrix4x4)(ref val3)).lossyScale;
					val4.AddComponent<MeshFilter>().sharedMesh = val2;
					MeshRenderer obj = val4.AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterials = item.sharedMaterials;
					((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			return val;
		}

		private static Bounds BoundsOf(GameObject go)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>();
			if (componentsInChildren.Length == 0)
			{
				return new Bounds(go.transform.position, Vector3.one * 0.1f);
			}
			Bounds bounds = componentsInChildren[0].bounds;
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				((Bounds)(ref bounds)).Encapsulate(val.bounds);
			}
			return bounds;
		}

		private static float Span(Bounds b, Vector3 dir)
		{
			//IL_0002: 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_001a: 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_0033: 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)
			return Mathf.Abs(((Bounds)(ref b)).size.x * dir.x) + Mathf.Abs(((Bounds)(ref b)).size.y * dir.y) + Mathf.Abs(((Bounds)(ref b)).size.z * dir.z);
		}

		private static void DrawGrid(Texture2D image)
		{
			//IL_002e: 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)
			Color val = default(Color);
			((Color)(ref val))..ctor(0.12f, 0.12f, 0.13f);
			for (int i = 1; i < 4; i++)
			{
				for (int j = -3; j < 3; j++)
				{
					for (int k = 0; k < ((Texture)image).width; k++)
					{
						image.SetPixel(k, i * 512 + j, val);
						if (i == 2)
						{
							image.SetPixel(i * 512 + j, k, val);
						}
					}
				}
			}
		}

		private static void Render(GameObject oursPrefab, GameObject peerPrefab, string path)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//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_0049: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: 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_00c8: 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_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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: 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_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: 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)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: 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_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: 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_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: 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_041d: 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_0453: Unknown result type (might be due to invalid IL or missing references)
			GameObject[] array = (GameObject[])(object)new GameObject[2]
			{
				VisualCopy(oursPrefab),
				VisualCopy(peerPrefab)
			};
			GameObject val = new GameObject("ItemReportCamera");
			GameObject val2 = new GameObject("ItemReportLight");
			RenderTexture val3 = new RenderTexture(512, 512, 24, (RenderTextureFormat)0)
			{
				antiAliasing = 4
			};
			Texture2D val4 = new Texture2D(2048, 2048, (TextureFormat)3, false);
			AmbientMode ambientMode = RenderSettings.ambientMode;
			Color ambientLight = RenderSettings.ambientLight;
			RenderTexture active = RenderTexture.active;
			try
			{
				RenderSettings.ambientMode = (AmbientMode)3;
				RenderSettings.ambientLight = new Color(0.55f, 0.55f, 0.6f);
				Camera val5 = val.AddComponent<Camera>();
				((Behaviour)val5).enabled = false;
				val5.orthographic = true;
				val5.clearFlags = (CameraClearFlags)2;
				val5.backgroundColor = new Color(0.32f, 0.33f, 0.35f);
				val5.cullingMask = int.MinValue;
				val5.renderingPath = (RenderingPath)1;
				val5.nearClipPlane = 0.01f;
				val5.farClipPlane = 100f;
				val5.targetTexture = val3;
				Light val6 = val2.AddComponent<Light>();
				val6.type = (LightType)1;
				val6.intensity = 1.2f;
				val6.color = new Color(1f, 0.97f, 0.92f);
				val6.cullingMask = int.MinValue;
				val6.shadows = (LightShadows)0;
				Bounds[] array2 = array.Select(BoundsOf).ToArray();
				Vector3 size = ((Bounds)(ref array2[1])).size;
				List<int> axes = new List<int> { 0, 1, 2 };
				axes.Sort((int a, int b) => ((Vector3)(ref size))[b].CompareTo(((Vector3)(ref size))[a]));
				Vector3 val7 = Axis(0);
				Vector3 val8 = Axis(1);
				Vector3 val9 = Axis(2);
				(Vector3, Vector3)[] obj = new(Vector3, Vector3)[8]
				{
					(val9, val7),
					(-val9, val7),
					(val8, val7),
					(-val8, val7),
					(-val7, val8),
					(val7, val8),
					default((Vector3, Vector3)),
					default((Vector3, Vector3))
				};
				Vector3 val10 = val9 + val8 * 0.8f - val7 * 0.4f;
				obj[6] = (((Vector3)(ref val10)).normalized, val7);
				val10 = -val9 - val8 * 0.8f - val7 * 0.4f;
				obj[7] = (((Vector3)(ref val10)).normalized, val7);
				(Vector3, Vector3)[] array3 = obj;
				for (int num = 0; num < array3.Length; num++)
				{
					(Vector3, Vector3) tuple = array3[num];
					Vector3 item = tuple.Item1;
					Vector3 up = tuple.Item2;
					val10 = up - Vector3.Dot(up, item) * item;
					up = ((Vector3)(ref val10)).normalized;
					Vector3 right = Vector3.Cross(up, item);
					float num2 = array2.Max((Bounds b) => Mathf.Max(Span(b, up), Span(b, right)));
					val5.orthographicSize = num2 * 0.55f;
					((Component)val6).transform.rotation = Quaternion.LookRotation(item - up * 0.6f + right * 0.4f, up);
					for (int num3 = 0; num3 < 2; num3++)
					{
						for (int num4 = 0; num4 < array.Length; num4++)
						{
							array[num4].SetActive(num4 == num3);
						}
						Bounds val11 = array2[num3];
						Transform transform = ((Component)val5).transform;
						Vector3 center = ((Bounds)(ref val11)).center;
						val10 = ((Bounds)(ref val11)).extents;
						transform.SetPositionAndRotation(center - item * (((Vector3)(ref val10)).magnitude + 5f), Quaternion.LookRotation(item, up));
						val5.Render();
						RenderTexture.active = val3;
						val4.ReadPixels(new Rect(0f, 0f, 512f, 512f), (num % 2 * 2 + num3) * 512, (3 - num / 2) * 512);
					}
				}
				DrawGrid(val4);
				val4.Apply();
				File.WriteAllBytes(path, ImageConversion.EncodeToPNG(val4));
				Vector3 Axis(int i)
				{
					//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_001e: Unknown result type (might be due to invalid IL or missing references)
					Vector3 zero = Vector3.zero;
					((Vector3)(ref zero))[axes[i]] = 1f;
					return zero;
				}
			}
			finally
			{
				RenderTexture.active = active;
				RenderSettings.ambientMode = ambientMode;
				RenderSettings.ambientLight = ambientLight;
				GameObject[] array4 = array;
				for (int num5 = 0; num5 < array4.Length; num5++)
				{
					Object.DestroyImmediate((Object)(object)array4[num5]);
				}
				Object.DestroyImmediate((Object)(object)val);
				Object.DestroyImmediate((Object)(object)val2);
				Object.DestroyImmediate((Object)(object)val4);
				val3.Release();
				Object.DestroyImmediate((Object)(object)val3);
			}
		}
	}
	internal class MeshBuilder
	{
		public struct Station
		{
			public float Y;

			public float Left;

			public float Right;

			public float Thickness;

			public Station(float y, float left, float right, float thickness)
			{
				Y = y;
				Left = left;
				Right = right;
				Thickness = thickness;
			}

			public Station(float y, float halfWidth, float thickness)
				: this(y, halfWidth, halfWidth, thickness)
			{
			}
		}

		public readonly List<Vector3> Verts = new List<Vector3>();

		public readonly List<Vector3> Normals = new List<Vector3>();

		public readonly List<Vector2> Uvs = new List<Vector2>();

		public readonly List<int>[] Tris;

		public Texture2D[] Textures;

		public bool ProjectUvs;

		public readonly List<BoneWeight> Weights = new List<BoneWeight>();

		public readonly List<string> BoneNames = new List<string>();

		public readonly List<Matrix4x4> Bindposes = new List<Matrix4x4>();

		public bool IsSkinned
		{
			get
			{
				if (BoneNames.Count > 0)
				{
					return Weights.Count == Verts.Count;
				}
				return false;
			}
		}

		public int TriangleCount
		{
			get
			{
				int num = 0;
				List<int>[] tris = Tris;
				foreach (List<int> list in tris)
				{
					num += list.Count;
				}
				return num / 3;
			}
		}

		public MeshBuilder(int submeshes)
		{
			Tris = new List<int>[submeshes];
			for (int i = 0; i < submeshes; i++)
			{
				Tris[i] = new List<int>();
			}
		}

		public static Vector3 V(Vector2 p, float z)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(p.x, p.y, z);
		}

		public void Tri(int sub, Vector3 a, Vector3 b, Vector3 c)
		{
			//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_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			//IL_0064: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0045: 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_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_004e: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 val = Vector3.Cross(b - a, c - a);
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-12f))
			{
				((Vector3)(ref val)).Normalize();
				Vector2 ua = Vector2.zero;
				Vector2 val2 = Vector2.zero;
				Vector2 val3 = Vector2.zero;
				if (ProjectUvs)
				{
					ua = Project(a, val);
					val2 = Project(b, val);
					val3 = Project(c, val);
				}
				Add(sub, a, b, c, val, val, val, ua, val2, val3);
				Add(sub, a, c, b, -val, -val, -val, ua, val3, val2);
			}
		}

		private static Vector2 Project(Vector3 p, Vector3 n)
		{
			//IL_0000: 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_0018: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_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_0038: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Abs(n.x);
			float num2 = Mathf.Abs(n.y);
			float num3 = Mathf.Abs(n.z);
			if (num >= num2 && num >= num3)
			{
				return new Vector2(p.z, p.y);
			}
			if (num2 >= num3)
			{
				return new Vector2(p.x, p.z);
			}
			return new Vector2(p.x, p.y);
		}

		public void ScaleUvs(int sub, float scale)
		{
			//IL_0037: 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)
			HashSet<int> hashSet = new HashSet<int>();
			foreach (int item in Tris[sub])
			{
				if (hashSet.Add(item))
				{
					List<Vector2> uvs = Uvs;
					int index = item;
					uvs[index] *= scale;
				}
			}
		}

		public void Tri(int sub, Vector3 a, Vector3 b, Vector3 c, Vector2 ua, Vector2 ub, Vector2 uc, Vector3? na = null, Vector3? nb = null, Vector3? nc = null, BoneWeight? wa = null, BoneWeight? wb = null, BoneWeight? wc = null)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_005f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_0098: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			_ = Verts.Count;
			Vector3 val = Vector3.Cross(b - a, c - a);
			if (((Vector3)(ref val)).sqrMagnitude < 1E-12f)
			{
				return;
			}
			((Vector3)(ref val)).Normalize();
			if (!na.HasValue || !nb.HasValue || !nc.HasValue)
			{
				Add(sub, a, b, c, val, val, val, ua, ub, uc);
				Add(sub, a, c, b, -val, -val, -val, ua, uc, ub);
				return;
			}
			bool flag = Vector3.Dot(na.Value + nb.Value + nc.Value, val) < 0f;
			if (!flag)
			{
				Add(sub, a, b, c, na.Value, nb.Value, nc.Value, ua, ub, uc);
			}
			else
			{
				Add(sub, a, c, b, na.Value, nc.Value, nb.Value, ua, uc, ub);
			}
			if (wa.HasValue && wb.HasValue && wc.HasValue)
			{
				Weights.Add(wa.Value);
				Weights.Add(flag ? wc.Value : wb.Value);
				Weights.Add(flag ? wb.Value : wc.Value);
			}
		}

		private void Add(int sub, Vector3 a, Vector3 b, Vector3 c, Vector3 na, Vector3 nb, Vector3 nc, Vector2 ua, Vector2 ub, Vector2 uc)
		{
			//IL_0012: 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_002a: 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_0044: 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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			int count = Verts.Count;
			Verts.Add(a);
			Verts.Add(b);
			Verts.Add(c);
			Normals.Add(na);
			Normals.Add(nb);
			Normals.Add(nc);
			Uvs.Add(ua);
			Uvs.Add(ub);
			Uvs.Add(uc);
			Tris[sub].Add(count);
			Tris[sub].Add(count + 1);
			Tris[sub].Add(count + 2);
		}

		public void Quad(int sub, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_000e: 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)
			Tri(sub, a, b, c);
			Tri(sub, a, c, d);
		}

		public void Slab(int sub, Vector2[] poly, float h)
		{
			//IL_0008: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002a: 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_003f: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0087: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < poly.Length - 1; i++)
			{
				Tri(sub, V(poly[0], h), V(poly[i], h), V(poly[i + 1], h));
				Tri(sub, V(poly[0], 0f - h), V(poly[i], 0f - h), V(poly[i + 1], 0f - h));
			}
			for (int j = 0; j < poly.Length; j++)
			{
				Vector2 p = poly[j];
				Vector2 p2 = poly[(j + 1) % poly.Length];
				Quad(sub, V(p, h), V(p2, h), V(p2, 0f - h), V(p, 0f - h));
			}
		}

		public void Box(int sub, Rect r, float h)
		{
			//IL_0018: 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_0032: 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_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)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			Slab(sub, (Vector2[])(object)new Vector2[4]
			{
				new Vector2(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin),
				new Vector2(((Rect)(ref r)).xMax, ((Rect)(ref r)).yMin),
				new Vector2(((Rect)(ref r)).xMax, ((Rect)(ref r)).yMax),
				new Vector2(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMax)
			}, h);
		}

		public void Ribbon(int sub, Vector2[] path, float halfWidth, float h)
		{
			//IL_000b: 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_0020: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_003f: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_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_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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < path.Length - 1; i++)
			{
				Vector2 val = path[i + 1] - path[i];
				Vector2 normalized = ((Vector2)(ref val)).normalized;
				Vector2 val2 = new Vector2(0f - normalized.y, normalized.x) * halfWidth;
				Vector2 val3 = normalized * halfWidth * 0.5f;
				Slab(sub, (Vector2[])(object)new Vector2[4]
				{
					path[i] - val3 - val2,
					path[i + 1] + val3 - val2,
					path[i + 1] + val3 + val2,
					path[i] - val3 + val2
				}, h);
			}
		}

		public void Prism(int sub, float y0, float y1, float radius, int sides = 8, float x = 0f)
		{
			Taper(sub, y0, y1, radius, radius, sides, x);
		}

		public void Taper(int sub, float y0, float y1, float r0, float r1, int sides = 8, float x = 0f)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			//IL_0069: 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_007a: 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_00a5: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[sides];
			Vector3[] array2 = (Vector3[])(object)new Vector3[sides];
			Vector3 val = default(Vector3);
			for (int i = 0; i < sides; i++)
			{
				float num = ((float)i + 0.5f) * (float)Math.PI * 2f / (float)sides;
				((Vector3)(ref val))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num));
				array[i] = val * r0 + new Vector3(x, y0, 0f);
				array2[i] = val * r1 + new Vector3(x, y1, 0f);
			}
			for (int j = 0; j < sides; j++)
			{
				int num2 = (j + 1) % sides;
				Quad(sub, array[j], array[num2], array2[num2], array2[j]);
				if (j > 0 && j < sides - 1)
				{
					Tri(sub, array[0], array[j], array[num2]);
					Tri(sub, array2[0], array2[j], array2[num2]);
				}
			}
		}

		public void Blade(int sub, params Station[] s)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00b3: 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_00c1: 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_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_0044: 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)
			for (int i = 0; i < s.Length - 1; i++)
			{
				Vector3[] array = Ring(s[i]);
				Vector3[] array2 = Ring(s[i + 1]);
				for (int j = 0; j < 4; j++)
				{
					int num = (j + 1) % 4;
					Quad(sub, array[j], array[num], array2[num], array2[j]);
				}
			}
			Vector3[] array3 = Ring(s[0]);
			Vector3[] array4 = Ring(s[^1]);
			Quad(sub, array3[0], array3[1], array3[2], array3[3]);
			Quad(sub, array4[0], array4[1], array4[2], array4[3]);
			static Vector3[] Ring(Station st)
			{
				//IL_001a: 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_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_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)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				return (Vector3[])(object)new Vector3[4]
				{
					new Vector3(0f - st.Left, st.Y, 0f),
					new Vector3(0f, st.Y, st.Thickness),
					new Vector3(st.Right, st.Y, 0f),
					new Vector3(0f, st.Y, 0f - st.Thickness)
				};
			}
		}

		public Mesh ToMesh(string name)
		{
			//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_0017: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name + "_mesh"
			};
			if (Verts.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(Verts);
			val.SetNormals(Normals);
			val.SetUVs(0, Uvs);
			val.subMeshCount = Tris.Length;
			for (int i = 0; i < Tris.Length; i++)
			{
				val.SetTriangles(Tris[i], i);
			}
			if (IsSkinned)
			{
				val.boneWeights = Weights.ToArray();
				val.bindposes = Bindposes.ToArray();
			}
			val.RecalculateBounds();
			val.RecalculateTangents();
			return val;
		}
	}
	internal struct ModelPlacement
	{
		public bool AutoAlign;

		public bool FitToOriginal;

		public Vector3 Rotation;

		public Vector3 Offset;

		public float Scale;

		public Vector3 Stretch;

		public bool CleanMaterials;
	}
	internal static class ModelUtil
	{
		[HarmonyPatch(typeof(VisEquipment), "AttachBackItem")]
		private static class BackFramePatch
		{
			private static void Postfix(VisEquipment __instance, GameObject __result)
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: 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_0104: 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_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: 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_0147: 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_015c: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: 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_018a: 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_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: 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_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_020a: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)__result) || !((Object)__result).name.StartsWith("attach_back"))
				{
					return;
				}
				foreach (Transform item in __result.transform)
				{
					Transform val = item;
					if (((Object)val).name.EndsWith("_backframe"))
					{
						Transform transform = ((Component)__instance).transform;
						SkinnedMeshRenderer bodyModel = __instance.m_bodyModel;
						Transform[] array = (Transform[])(Object.op_Implicit((Object)(object)bodyModel) ? ((Array)bodyModel.bones) : ((Array)new Transform[0]));
						Matrix4x4[] array2 = (Matrix4x4[])((Object.op_Implicit((Object)(object)bodyModel) && Object.op_Implicit((Object)(object)bodyModel.sharedMesh)) ? ((Array)bodyModel.sharedMesh.bindposes) : ((Array)new Matrix4x4[0]));
						int num = Array.FindIndex(array, (Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name == "Spine2");
						Matrix4x4 val2 = Matrix4x4.TRS(BackPosition, Quaternion.Euler(8f, 0f, 0f), Vector3.one);
						if (num < 0 || num >= array2.Length)
						{
							val.SetPositionAndRotation(transform.TransformPoint(BackPosition), transform.rotation * Quaternion.Euler(8f, 0f, 0f));
							Vector3 lossyScale = val.parent.lossyScale;
							val.localScale = new Vector3(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z);
							continue;
						}
						Matrix4x4 val3 = transform.worldToLocalMatrix * ((Component)bodyModel).transform.localToWorldMatrix * ((Matrix4x4)(ref array2[num])).inverse;
						Matrix4x4 val4 = ((Matrix4x4)(ref val3)).inverse * val2;
						__result.transform.SetParent(array[num], false);
						__result.transform.localPosition = Vector3.zero;
						__result.transform.localRotation = Quaternion.identity;
						__result.transform.localScale = Vector3.one;
						val.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(3));
						val.localRotation = ((Matrix4x4)(ref val4)).rotation;
						val.localScale = ((Matrix4x4)(ref val4)).lossyScale;
					}
				}
			}
		}

		private struct TexturedTri
		{
			public Texture2D Texture;

			public Vector2 Ua;

			public Vector2 Ub;

			public Vector2 Uc;

			public Color Tint;
		}

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

		private const string BackFrame = "_backframe";

		private const float BackAngle = 30f;

		private static readonly Vector3 BackPosition = new Vector3(0f, 1.35f, -0.22f);

		private const float BackTilt = 8f;

		private const float BackGap = 0.03f;

		private const float GripDepth = 0.9f;

		private static readonly string[] SpectralShaders = new string[3] { "Sprites/Default", "UI/Default", "Legacy Shaders/Particles/Alpha Blended" };

		private static Shader _spectralShader;

		private static bool _spectralLookedUp;

		public static string CustomModelDir => Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? "", "models");

		public static MeshBuilder LoadCustomModel(string prefabName, int submeshes)
		{
			return LoadModelFile(Path.Combine(CustomModelDir, prefabName + ".obj"), submeshes, prefabName);
		}

		public static void ClearTextureCache()
		{
			TextureCache.Clear();
		}

		public static MeshBuilder LoadModelFile(string path, int submeshes, string label)
		{
			//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_0097: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				MeshBuilder meshBuilder = new MeshBuilder(submeshes);
				Dictionary<int, string> dictionary = ObjImport.Load(path, meshBuilder);
				meshBuilder.Textures = (Texture2D[])(object)new Texture2D[submeshes];
				foreach (KeyValuePair<int, string> item in dictionary)
				{
					string fullPath = Path.GetFullPath(item.Value);
					if (!TextureCache.TryGetValue(fullPath, out var value))
					{
						if (!File.Exists(fullPath))
						{
							Plugin.Log.LogWarning((object)(label + ": texture " + fullPath + " not found"));
							continue;
						}
						value = new Texture2D(2, 2, (TextureFormat)4, true)
						{
							name = Path.GetFileName(fullPath)
						};
						if (!LoadImage(value, File.ReadAllBytes(fullPath)))
						{
							continue;
						}
						TextureCache[fullPath] = value;
					}
					meshBuilder.Textures[item.Key] = value;
				}
				Plugin.Log.LogInfo((object)($"{label}: using custom model {path} ({meshBuilder.TriangleCount} triangles, " + $"{dictionary.Count} textures)"));
				return meshBuilder;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)(label + ": could not load " + path + ", using the default model. " + ex.Message));
				return null;
			}
		}

		public static Sprite LoadSprite(string path)
		{
			//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: Expected O, but got Unknown
			//IL_003f: 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)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = Path.GetFileName(path)
			};
			if (!LoadImage(val, File.ReadAllBytes(path)))
			{
				return null;
			}
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		public static void AddRenderer(GameObject go, MeshBuilder builder, MaterialSpec[] specs, Material baseMat, string name)
		{
			Mesh sharedMesh = builder.ToMesh(name);
			Material[] array = (Material[])(object)new Material[specs.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = MakeMaterial(baseMat, specs[i], $"{name}_mat{i}", (builder.Textures != null && i < builder.Textures.Length) ? builder.Textures[i] : null, clean: false);
			}
			if (builder.IsSkinned)
			{
				SkinnedMeshRenderer obj = go.AddComponent<SkinnedMeshRenderer>();
				obj.sharedMesh = sharedMesh;
				((Renderer)obj).sharedMaterials = array;
				go.AddComponent<SkinBoneNames>().Names = builder.BoneNames.ToArray();
			}
			else
			{
				go.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
				((Renderer)go.AddComponent<MeshRenderer>()).sharedMaterials = array;
			}
			if (array.Length != 0)
			{
				LogMaterial(name, baseMat, array[0]);
			}
		}

		private static void LogMaterial(string name, Material source, Material mat)
		{
			Plugin.Log.LogInfo((object)(name + ": material from " + (Object.op_Implicit((Object)(object)source) ? ((Object)source).name : "none") + ", shader " + ((Object)mat.shader).name + ", " + string.Format("metallic {0:0.##}, gloss {1:0.##}, ", F("_Metallic"), F("_Glossiness")) + "emission " + (mat.IsKeywordEnabled("_EMISSION") ? "on" : "off")));
			float F(string prop)
			{
				if (!mat.HasProperty(prop))
				{
					return float.NaN;
				}
				return mat.GetFloat(prop);
			}
		}

		private static bool LoadImage(Texture2D tex, byte[] data)
		{
			MethodInfo method = typeof(ImageConversion).GetMethod("LoadImage", new Type[2]
			{
				typeof(Texture2D),
				typeof(byte[])
			});
			if (method != null)
			{
				return (bool)method.Invoke(null, new object[2] { tex, data });
			}
			return false;
		}

		public static void GradeTexture(Texture2D tex, Color multiply, Color glow, float glowAmount)
		{
			//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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0076: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Color[] pixels = tex.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val = pixels[i];
				float grayscale = ((Color)(ref val)).grayscale;
				float num = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.25f, 0.7f, grayscale));
				Color val2 = glow * (glowAmount * (0.15f + 0.85f * num));
				pixels[i] = new Color(Mathf.Clamp01(grayscale * multiply.r + val2.r), Mathf.Clamp01(grayscale * multiply.g + val2.g), Mathf.Clamp01(grayscale * multiply.b + val2.b), val.a);
			}
			tex.SetPixels(pixels);
			tex.Apply(true);
		}

		public static MaterialSpec[] WithTextures(MaterialSpec[] specs, MeshBuilder builder)
		{
			//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)
			MaterialSpec[] array = (MaterialSpec[])specs.Clone();
			for (int i = 0; i < array.Length; i++)
			{
				if (builder.Textures != null && i < builder.Textures.Length && Object.op_Implicit((Object)(object)builder.Textures[i]))
				{
					array[i].Color = Color.white;
					array[i].Gloss = array[i].TexturedGloss;
				}
			}
			return array;
		}

		public static GameObject ReplaceModel(GameObject prefab, string name, MeshBuilder builder, MaterialSpec[] specs, ModelPlacement place, Material baseMatOverride = null)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_0253: 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_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: 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_028d: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: 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_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: 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_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			//IL_00cb: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindDeep(prefab.transform, "attach") ?? prefab.transform;
			Material val2 = baseMatOverride;
			bool flag = false;
			Bounds value = default(Bounds);
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				if (!(val3 is MeshRenderer) && !(val3 is SkinnedMeshRenderer))
				{
					continue;
				}
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = val3.sharedMaterial;
				}
				val3.enabled = false;
				MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
				object obj2;
				if (!Object.op_Implicit((Object)(object)component))
				{
					Renderer obj = ((val3 is SkinnedMeshRenderer) ? val3 : null);
					obj2 = ((obj != null) ? ((SkinnedMeshRenderer)obj).sharedMesh : null);
				}
				else
				{
					obj2 = component.sharedMesh;
				}
				Mesh val4 = (Mesh)obj2;
				if (!Object.op_Implicit((Object)(object)val4) || !((Component)val3).transform.IsChildOf(val))
				{
					continue;
				}
				Bounds bounds = val4.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val5 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					Vector3 val6 = val.InverseTransformPoint(((Component)val3).transform.TransformPoint(val5));
					if (!flag)
					{
						((Bounds)(ref value))..ctor(val6, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref value)).Encapsulate(val6);
					}
				}
			}
			Plugin.Log.LogInfo((object)$"{name}: original model bounds center {((Bounds)(ref value)).center}, size {((Bounds)(ref value)).size}");
			Mesh val7 = builder.ToMesh(name);
			Material[] array = (Material[])(object)new Material[specs.Length];
			for (int k = 0; k < array.Length; k++)
			{
				array[k] = MakeMaterial(val2, specs[k], $"{name}_mat{k}", (builder.Textures != null && k < builder.Textures.Length) ? builder.Textures[k] : null, place.CleanMaterials);
			}
			if (array.Length != 0)
			{
				LogMaterial(name, val2, array[0]);
			}
			GameObject val8 = new GameObject(name + "_model")
			{
				layer = ((Component)val).gameObject.layer
			};
			val8.transform.SetParent(val, false);
			val8.AddComponent<MeshFilter>().sharedMesh = val7;
			((Renderer)val8.AddComponent<MeshRenderer>()).sharedMaterials = array;
			Fit(name, val7.bounds, flag ? new Bounds?(value) : ((Bounds?)null), place, out var rotation, out var position, out var scale);
			val8.transform.localRotation = rotation;
			val8.transform.localPosition = position;
			val8.transform.localScale = Vector3.Scale(Vector3.one * scale, (place.Stretch == Vector3.zero) ? Vector3.one : place.Stretch);
			return val8;
		}

		private static void Fit(string name, Bounds ours, Bounds? original, ModelPlacement place, out Quaternion rotation, out Vector3 position, out float scale)
		{
			//IL_0013: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0071: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f4: Unknown result type (might be due to invalid IL or missing references)
			rotation = ((place.AutoAlign && original.HasValue) ? AlignToHandle(original.Value) : Quaternion.identity);
			rotation *= Quaternion.Euler(place.Rotation);
			scale = place.Scale;
			position = place.Offset;
			if (place.FitToOriginal && original.HasValue)
			{
				Bounds val = RotatedBounds(ours, rotation);
				float num = scale;
				Bounds value = original.Value;
				scale = num * (((Bounds)(ref value)).size.MaxComponent() / Mathf.Max(((Bounds)(ref val)).size.MaxComponent(), 0.0001f));
				Vector3 val2 = position;
				value = original.Value;
				position = val2 + (((Bounds)(ref value)).center - ((Bounds)(ref val)).center * scale);
				Plugin.Log.LogInfo((object)$"{name}: fitted custom model at {position}, scale {scale:0.###}");
			}
		}

		public static bool ReplaceSkinnedModel(GameObject prefab, string name, GameObject model, ModelPlacement place)
		{
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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_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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: 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_0288: 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_0296: 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_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: 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_03d3: Unknown result type (might be due to invalid IL or missing references)
			Transform val = prefab.transform.Find("attach_skin");
			SkinnedMeshRenderer val2 = (Object.op_Implicit((Object)(object)val) ? ((IEnumerable<SkinnedMeshRenderer>)((Component)val).GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer r) => Object.op_Implicit((Object)(object)r.sharedMesh))) : null);
			Transform[] array = (Transform[])(Object.op_Implicit((Object)(object)val2) ? ((Array)val2.bones) : ((Array)new Transform[0]));
			int[] array2 = new int[2]
			{
				Array.FindIndex(array, (Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name.EndsWith("RightHand")),
				Array.FindIndex(array, (Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name.EndsWith("LeftHand"))
			};
			if (array2.Any((int h) => h < 0))
			{
				Plugin.Log.LogWarning((object)(name + ": no hand bones under attach_skin, the model only shows on the ground"));
				return false;
			}
			Matrix4x4[] array3 = (Matrix4x4[])(object)new Matrix4x4[array.Length];
			Mesh sharedMesh = model.GetComponent<MeshFilter>().sharedMesh;
			Vector3[] vertices = sharedMesh.vertices;
			Vector3[] normals = sharedMesh.normals;
			Vector2[] uv = sharedMesh.uv;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<BoneWeight> list4 = new List<BoneWeight>();
			List<int>[] array4 = new List<int>[sharedMesh.subMeshCount];
			for (int num = 0; num < array4.Length; num++)
			{
				array4[num] = new List<int>();
			}
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				int num3 = array2[num2];
				Transform val3 = array[num3];
				bool flag = num2 == 1;
				if (!GripFrame(val3, out var rotation, out var position))
				{
					Plugin.Log.LogWarning((object)(name + ": no finger bones under " + ((Object)val3).name + ", the blade follows the bone's own axes"));
				}
				Fit(name, sharedMesh.bounds, null, place, out var rotation2, out var position2, out var scale);
				Matrix4x4 val4 = (flag ? Matrix4x4.Scale(new Vector3(1f, 1f, -1f)) : Matrix4x4.identity);
				Matrix4x4 val5 = Matrix4x4.TRS(position, rotation, Vector3.one) * val4 * Matrix4x4.TRS(position2, rotation2, Vector3.one * scale);
				int count = list.Count;
				for (int num4 = 0; num4 < vertices.Length; num4++)
				{
					list.Add(((Matrix4x4)(ref val5)).MultiplyPoint3x4(vertices[num4]));
					Vector3 val6 = ((Matrix4x4)(ref val5)).MultiplyVector(normals[num4]);
					list2.Add(((Vector3)(ref val6)).normalized);
					list3.Add((num4 < uv.Length) ? uv[num4] : Vector2.zero);
					BoneWeight item = default(BoneWeight);
					((BoneWeight)(ref item)).boneIndex0 = num3;
					((BoneWeight)(ref item)).weight0 = 1f;
					list4.Add(item);
				}
				for (int num5 = 0; num5 < array4.Length; num5++)
				{
					int[] triangles = sharedMesh.GetTriangles(num5);
					for (int num6 = 0; num6 < triangles.Length; num6 += 3)
					{
						array4[num5].Add(count + triangles[num6]);
						array4[num5].Add(count + triangles[flag ? (num6 + 2) : (num6 + 1)]);
						array4[num5].Add(count + triangles[flag ? (num6 + 1) : (num6 + 2)]);
					}
				}
				Vector3 lossyScale = val3.lossyScale;
				array3[num3] = Matrix4x4.Scale(new Vector3(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z));
				Plugin.Log.LogInfo((object)($"{name}: blade {num2 + 1} on bone {num3} '{((Object)val3).name}' (bone scale {lossyScale}), " + string.Format("grip at {0}{1}", position, flag ? ", mirrored" : "")));
			}
			Mesh val7 = new Mesh
			{
				name = name + "_skinned"
			};
			val7.SetVertices(list);
			val7.SetNormals(list2);
			val7.SetUVs(0, list3);
			val7.subMeshCount = array4.Length;
			for (int num7 = 0; num7 < array4.Length; num7++)
			{
				val7.SetTriangles(array4[num7], num7);
			}
			val7.boneWeights = list4.ToArray();
			val7.bindposes = array3;
			val7.RecalculateBounds();
			val2.sharedMesh = val7;
			((Renderer)val2).sharedMaterials = ((Renderer)model.GetComponent<MeshRenderer>()).sharedMaterials;
			((Renderer)val2).enabled = true;
			return true;
		}

		public static void AddCrossedBackModel(GameObject prefab, string name, GameObject model, ModelPlacement place)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0142: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("attach_back");
			val.layer = model.layer;
			val.transform.SetParent(prefab.transform, false);
			val.transform.SetSiblingIndex(0);
			val.SetActive(false);
			Transform transform = new GameObject(name + "_backframe").transform;
			((Component)transform).gameObject.layer = model.layer;
			transform.SetParent(val.transform, false);
			Mesh sharedMesh = model.GetComponent<MeshFilter>().sharedMesh;
			Material[] sharedMaterials = ((Renderer)model.GetComponent<MeshRenderer>()).sharedMaterials;
			float num = Mathf.Sin((float)Math.PI / 6f);
			float num2 = Mathf.Cos((float)Math.PI / 6f);
			for (int i = 0; i < 2; i++)
			{
				float num3 = ((i == 0) ? (-1f) : 1f);
				GameObject val2 = new GameObject($"{name}_back{i + 1}")
				{
					layer = model.layer
				};
				val2.transform.SetParent(transform, false);
				val2.transform.localRotation = Quaternion.LookRotation(new Vector3((0f - num3) * num2, num, 0f), new Vector3(num3 * num, num2, 0f));
				val2.transform.localPosition = new Vector3(0f, 0f, -0.03f * (float)i);
				val2.transform.localScale = new Vector3((i == 0) ? (0f - place.Scale) : place.Scale, place.Scale, place.Scale);
				val2.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
				((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterials = sharedMaterials;
			}
		}

		private static bool GripFrame(Transform hand, out Quaternion rotation, out Vector3 position)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			rotation = Quaternion.identity;
			position = Vector3.zero;
			Transform val = FindDeep(hand, ((Object)hand).name + "Index1");
			Transform val2 = FindDeep(hand, ((Object)hand).name + "Middle1");
			Transform val3 = FindDeep(hand, ((Object)hand).name + "Pinky1");
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3))
			{
				return false;
			}
			Vector3 val4 = Local(val) - Local(val3);
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			Vector3 val5 = Local(val2);
			val4 = Vector3.ProjectOnPlane(val5, normalized);
			Vector3 normalized2 = ((Vector3)(ref val4)).normalized;
			rotation = Quaternion.LookRotation(Vector3.Cross(normalized2, normalized), normalized);
			position = val5 * 0.9f;
			return true;
			Vector3 Local(Transform t)
			{
				//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_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)
				return Vector3.Scale(hand.InverseTransformPoint(t.position), hand.lossyScale);
			}
		}

		private static Bounds RotatedBounds(Bounds b, Quaternion rotation)
		{
			//IL_0002: 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_000a: 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_001f: 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_0029: 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_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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(rotation * ((Bounds)(ref b)).center, Vector3.zero);
			for (int i = 0; i < 8; i++)
			{
				((Bounds)(ref result)).Encapsulate(rotation * (((Bounds)(ref b)).center + Vector3.Scale(((Bounds)(ref b)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))))));
			}
			return result;
		}

		private static float MaxComponent(this Vector3 v)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(v.x, Mathf.Max(v.y, v.z));
		}

		private static Quaternion AlignToHandle(Bounds b)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 size = ((Bounds)(ref b)).size;
			List<int> list = new List<int> { 0, 1, 2 };
			list.Sort((int a, int c) => ((Vector3)(ref size))[c].CompareTo(((Vector3)(ref size))[a]));
			Vector3 zero = Vector3.zero;
			int num = list[0];
			Vector3 center = ((Bounds)(ref b)).center;
			((Vector3)(ref zero))[num] = ((((Vector3)(ref center))[list[0]] < 0f) ? (-1f) : 1f);
			Vector3 zero2 = Vector3.zero;
			((Vector3)(ref zero2))[list[1]] = 1f;
			return Quaternion.LookRotation(Vector3.Cross(zero2, zero), zero);
		}

		private static Material MakeMaterial(Material baseMat, MaterialSpec spec, string name, Texture2D texture, bool clean)
		{
			//IL_001a: 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_0020: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: 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_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			Material val = (Object.op_Implicit((Object)(object)baseMat) ? new Material(baseMat) : new Material(Shader.Find("Standard")));
			((Object)val).name = name;
			string[] array;
			if (!clean)
			{
				array = new string[4] { "_MainTex", "_BumpMap", "_MetallicGlossMap", "_EmissionMap" };
				foreach (string text in array)
				{
					if (val.HasProperty(text))
					{
						val.SetTexture(text, (Texture)null);
					}
				}
				if (Object.op_Implicit((Object)(object)texture) && val.HasProperty("_MainTex"))
				{
					val.SetTexture("_MainTex", (Texture)(object)texture);
				}
				val.color = spec.Color;
				if (val.HasProperty("_Glossiness"))
				{
					val.SetFloat("_Glossiness", spec.Gloss);
				}
				if (((Color)(ref spec.Emission)).maxColorComponent > 0f && val.HasProperty("_EmissionColor"))
				{
					val.EnableKeyword("_EMISSION");
					val.SetColor("_EmissionColor", spec.Emission);
					if (Object.op_Implicit((Object)(object)texture) && val.HasProperty("_EmissionMap"))
					{
						val.SetTexture("_EmissionMap", (Texture)(object)texture);
					}
				}
				return val;
			}
			List<string> list = new List<string>();
			array = val.GetTexturePropertyNames();
			foreach (string text2 in array)
			{
				if (Object.op_Implicit((Object)(object)val.GetTexture(text2)))
				{
					val.SetTexture(text2, (Texture)null);
					list.Add(text2);
				}
			}
			array = new string[4] { "_DETAIL_MULX2", "_PARALLAXMAP", "_NORMALMAP", "_METALLICGLOSSMAP" };
			foreach (string text3 in array)
			{
				val.DisableKeyword(text3);
			}
			if (list.Count > 0)
			{
				Plugin.Log.LogInfo((object)(name + ": cleared textures " + string.Join(", ", list)));
			}
			List<string> list2 = new List<string>();
			array = val.GetPropertyNames((MaterialPropertyType)2);
			foreach (string text4 in array)
			{
				list2.Add($"{text4} {val.GetVector(text4)}");
			}
			if (list2.Count > 0)
			{
				Plugin.Log.LogInfo((object)(name + ": inherited colours " + string.Join(", ", list2)));
			}
			if (val.HasProperty("_MetalColor"))
			{
				val.SetColor("_MetalColor", Color.white);
			}
			if (Object.op_Implicit((Object)(object)texture) && val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)texture);
			}
			val.color = spec.Color;
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", spec.Gloss);
			}
			if (((Color)(ref spec.