Decompiled source of VertexLibrary v1.0.0

plugins/VertexLibrary.dll

Decompiled 4 hours ago
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.Rendering;
using VertexLibrary.Caches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("com.github.lethalcompanymodding.vertexlibrary")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+373d99896a4d72508310b1ab14648a8e75382d7e")]
[assembly: AssemblyProduct("VertexLibrary")]
[assembly: AssemblyTitle("com.github.lethalcompanymodding.vertexlibrary")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/LethalCompanyModding/UnityVertexLibrary")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
internal static class LCMPluginInfo
{
	public const string PLUGIN_GUID = "com.github.lethalcompanymodding.vertexlibrary";

	public const string PLUGIN_NAME = "VertexLibrary";

	public const string PLUGIN_VERSION = "1.0.0";
}
namespace VertexLibrary
{
	public struct ExecutionOptions
	{
		public Action<LogType, Func<string>> LogHandler { get; set; }

		public int CullingMask { get; set; }

		public ISet<Type>? FilteredComponents { get; set; }

		public Matrix4x4 OverrideMatrix { get; set; }

		public IVertexCache VertexCache { get; set; }

		public ExecutionOptions()
		{
			//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)
			LogHandler = null;
			CullingMask = -1;
			FilteredComponents = new HashSet<Type>();
			OverrideMatrix = Matrix4x4.identity;
			VertexCache = VertexesExtensions.GlobalPartialCache;
		}
	}
	public enum LogType
	{
		None = 0,
		Fatal = 2,
		Error = 4,
		Warning = 8,
		Info1 = 16,
		Info2 = 32,
		Info3 = 64,
		Info4 = 128,
		Info = 240,
		Debug1 = 256,
		Debug2 = 512,
		Debug3 = 1024,
		Debug4 = 2048,
		Debug = 3840,
		All = 4094
	}
	[BepInPlugin("com.github.lethalcompanymodding.vertexlibrary", "VertexLibrary", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
	}
	public static class VertexesExtensions
	{
		public static IVertexCache GlobalCache { get; } = IVertexCache.CreateCache(partial: false);


		public static IVertexCache GlobalPartialCache { get; } = GlobalCache.AsPartial();


		public static event Action<LogType, Func<string>>? logEvent;

		public static Bounds? GetBounds(this GameObject target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.GetBounds(executionOptions);
		}

		public static bool TryGetBounds(this GameObject target, out Bounds bounds, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.TryGetBounds(out bounds, executionOptions);
		}

		public static Bounds? GetWorldBounds(this GameObject target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.GetWorldBounds(executionOptions);
		}

		public static bool TryGetWorldBounds(this GameObject target, out Bounds bounds, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.TryGetWorldBounds(out bounds, executionOptions);
		}

		public static float GetRadius(this GameObject target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.GetRadius(executionOptions);
		}

		public static Vector3[] GetVertexes(this GameObject target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			return target.transform.GetVertexes(executionOptions);
		}

		public static void CacheVertexes(GameObject target, ExecutionOptions executionOptions)
		{
			target.transform.CacheVertexes(executionOptions);
		}

		public static Bounds? GetBounds(this Transform target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			logEvent += executionOptions.LogHandler;
			try
			{
				List<Vector3> list = CollectionPool<List<Vector3>, Vector3>.Get();
				Matrix4x4 overrideMatrix = executionOptions.OverrideMatrix;
				target.GetChildVertexes(list, overrideMatrix, "", executionOptions, Logfunc);
				Bounds? bounds = ((IEnumerable<Vector3>)list).GetBounds();
				CollectionPool<List<Vector3>, Vector3>.Release(list);
				return bounds;
			}
			finally
			{
				logEvent -= executionOptions.LogHandler;
			}
			static string Logfunc(List<Vector3> vertexes)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				Bounds? bounds2 = ((IEnumerable<Vector3>)vertexes).GetBounds();
				if (!bounds2.HasValue)
				{
					return "";
				}
				object arg = bounds2.Value;
				Bounds value = bounds2.Value;
				object arg2 = ((Bounds)(ref value)).min;
				value = bounds2.Value;
				return $"{arg} Min {arg2} Max {((Bounds)(ref value)).max}";
			}
		}

		public static bool TryGetBounds(this Transform target, out Bounds bounds, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//IL_0001: 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)
			bounds = default(Bounds);
			Bounds? bounds2 = target.GetBounds(executionOptions);
			if (bounds2.HasValue)
			{
				bounds = bounds2.Value;
			}
			return bounds2.HasValue;
		}

		public static Bounds? GetWorldBounds(this Transform target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			logEvent += executionOptions.LogHandler;
			try
			{
				List<Vector3> list = CollectionPool<List<Vector3>, Vector3>.Get();
				Matrix4x4 localMatrix = Matrix4x4.TRS(target.position, target.rotation, target.lossyScale);
				target.GetChildVertexes(list, localMatrix, "", executionOptions, Logfunc);
				Bounds? bounds = ((IEnumerable<Vector3>)list).GetBounds();
				CollectionPool<List<Vector3>, Vector3>.Release(list);
				return bounds;
			}
			finally
			{
				logEvent -= executionOptions.LogHandler;
			}
			static string Logfunc(List<Vector3> vertexes)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				Bounds? bounds2 = ((IEnumerable<Vector3>)vertexes).GetBounds();
				if (!bounds2.HasValue)
				{
					return "";
				}
				object arg = bounds2.Value;
				Bounds value = bounds2.Value;
				object arg2 = ((Bounds)(ref value)).min;
				value = bounds2.Value;
				return $"{arg} Min {arg2} Max {((Bounds)(ref value)).max}";
			}
		}

		public static bool TryGetWorldBounds(this Transform target, out Bounds bounds, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//IL_0001: 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)
			bounds = default(Bounds);
			Bounds? worldBounds = target.GetWorldBounds(executionOptions);
			if (worldBounds.HasValue)
			{
				bounds = worldBounds.Value;
			}
			return worldBounds.HasValue;
		}

		public static float GetRadius(this Transform target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			logEvent += executionOptions.LogHandler;
			try
			{
				List<Vector3> list = CollectionPool<List<Vector3>, Vector3>.Get();
				Matrix4x4 localMatrix = Matrix4x4.TRS(target.position, target.rotation, target.lossyScale);
				target.GetChildVertexes(list, localMatrix, "", executionOptions, Logfunc);
				Bounds? bounds = ((IEnumerable<Vector3>)list).GetBounds();
				Vector3 origin;
				if (!bounds.HasValue)
				{
					origin = Vector3.zero;
				}
				else
				{
					Bounds valueOrDefault = bounds.GetValueOrDefault();
					origin = ((Bounds)(ref valueOrDefault)).center;
				}
				float item = list.GetFarthestPoint(origin).distance;
				CollectionPool<List<Vector3>, Vector3>.Release(list);
				return item;
			}
			finally
			{
				logEvent -= executionOptions.LogHandler;
			}
			static string Logfunc(List<Vector3> vertexes)
			{
				//IL_0025: 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_003c: 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_0053: 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_006b: Unknown result type (might be due to invalid IL or missing references)
				Bounds? bounds2 = ((IEnumerable<Vector3>)vertexes).GetBounds();
				if (!bounds2.HasValue)
				{
					return "Radius: 0";
				}
				object[] obj = new object[4] { bounds2.Value, null, null, null };
				Bounds value = bounds2.Value;
				obj[1] = ((Bounds)(ref value)).min;
				value = bounds2.Value;
				obj[2] = ((Bounds)(ref value)).max;
				value = bounds2.Value;
				obj[3] = vertexes.GetFarthestPoint(((Bounds)(ref value)).center);
				return string.Format("{0} Min {1} Max {2} Radius: {3}", obj);
			}
		}

		public static Vector3[] GetVertexes(this Transform target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			logEvent += executionOptions.LogHandler;
			try
			{
				List<Vector3> list = CollectionPool<List<Vector3>, Vector3>.Get();
				Matrix4x4 overrideMatrix = executionOptions.OverrideMatrix;
				target.GetChildVertexes(list, overrideMatrix, "", executionOptions, Logfunc);
				Vector3[] result = list.ToArray();
				CollectionPool<List<Vector3>, Vector3>.Release(list);
				return result;
			}
			finally
			{
				logEvent -= executionOptions.LogHandler;
			}
			static string Logfunc(List<Vector3> vertexes)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				Bounds? bounds = ((IEnumerable<Vector3>)vertexes).GetBounds();
				if (!bounds.HasValue)
				{
					return "";
				}
				object arg = bounds.Value;
				Bounds value = bounds.Value;
				object arg2 = ((Bounds)(ref value)).min;
				value = bounds.Value;
				return $"{arg} Min {arg2} Max {((Bounds)(ref value)).max}";
			}
		}

		public static void CacheVertexes(this Transform target, ExecutionOptions executionOptions = default(ExecutionOptions))
		{
			if (executionOptions.VertexCache == null)
			{
				throw new ArgumentNullException("executionOptions.VertexCache");
			}
			target.CacheChildVertexes("", executionOptions);
		}

		public static Bounds? GetBounds(this IEnumerable<Vector3> vertexes)
		{
			//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_0026: 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_0031: 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)
			using IEnumerator<Vector3> enumerator = vertexes.GetEnumerator();
			if (!enumerator.MoveNext())
			{
				return null;
			}
			Bounds value = new Bounds(enumerator.Current, Vector3.zero);
			while (enumerator.MoveNext())
			{
				((Bounds)(ref value)).Encapsulate(enumerator.Current);
			}
			return value;
		}

		public static (Vector3? point, float distance) GetFarthestPoint(this IEnumerable<Vector3> vertexes, Vector3 origin = default(Vector3))
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Vector3? item = null;
			float num = float.NegativeInfinity;
			foreach (Vector3 vertex in vertexes)
			{
				float num2 = Vector3.Distance(vertex, origin);
				if (num2 > num)
				{
					item = vertex;
					num = num2;
				}
			}
			return (item, num);
		}

		private static void GetChildVertexes(this Transform target, List<Vector3> outVertices, Matrix4x4 localMatrix, string path, ExecutionOptions executionOptions, Func<List<Vector3>, string> logFunc)
		{
			//IL_0088: 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_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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Expected O, but got Unknown
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: 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_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			string path2 = path;
			Transform target2 = target;
			Func<List<Vector3>, string> logFunc2 = logFunc;
			List<Vector3> outVertices2 = outVertices;
			VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => "Processing " + path2 + "/" + ((Object)target2).name);
			ISet<Type>? filteredComponents = executionOptions.FilteredComponents;
			Component val7 = default(Component);
			if (filteredComponents != null && filteredComponents.Any((Type c) => ((Component)target2).TryGetComponent(c, ref val7)))
			{
				VertexesExtensions.logEvent?.Invoke(LogType.Debug2, () => "Skipping " + path2 + "/" + ((Object)target2).name + "!");
				return;
			}
			List<Vector3> list = default(List<Vector3>);
			PooledObject<List<Vector3>> val = CollectionPool<List<Vector3>, Vector3>.Get(ref list);
			try
			{
				if ((executionOptions.CullingMask & (1 << ((Component)target2).gameObject.layer)) == 0)
				{
					VertexesExtensions.logEvent?.Invoke(LogType.Debug2, () => $"Ignoring {path2}/{((Object)target2).name} by the culling mask: {((Component)target2).gameObject.layer}");
				}
				else
				{
					List<Renderer> list2 = default(List<Renderer>);
					PooledObject<List<Renderer>> val2 = CollectionPool<List<Renderer>, Renderer>.Get(ref list2);
					try
					{
						((Component)target2).GetComponents<Renderer>(list2);
						List<Vector3> rVertices = default(List<Vector3>);
						foreach (Renderer renderer in list2.Where((Renderer r) => r.enabled))
						{
							PooledObject<List<Vector3>> val3 = CollectionPool<List<Vector3>, Vector3>.Get(ref rVertices);
							try
							{
								Renderer obj = renderer;
								SkinnedMeshRenderer val4 = (SkinnedMeshRenderer)(object)((obj is SkinnedMeshRenderer) ? obj : null);
								if (val4 == null)
								{
									if (!(renderer is MeshRenderer))
									{
										if (!(renderer is ParticleSystemRenderer))
										{
											Bounds bounds = renderer.bounds;
											rVertices.Add(((Bounds)(ref bounds)).min);
											rVertices.Add(new Vector3(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).max.z));
											rVertices.Add(new Vector3(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).max.z));
											rVertices.Add(new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).max.z));
											rVertices.Add(new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).min.z));
											rVertices.Add(new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).min.z));
											rVertices.Add(((Bounds)(ref bounds)).max);
										}
										goto IL_0515;
									}
									MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
									if ((Object)(object)component == (Object)null)
									{
										VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a MeshFilter");
										continue;
									}
									Mesh sharedMesh = component.sharedMesh;
									if ((Object)(object)sharedMesh == (Object)null)
									{
										VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a mesh");
										continue;
									}
									if (executionOptions.VertexCache != null && executionOptions.VertexCache.TryGetValue(sharedMesh, out Vector3[] vertices))
									{
										VertexesExtensions.logEvent?.Invoke(LogType.Debug3, () => "Cache hit " + path2 + "/" + ((Object)target2).name + " renderer " + ((object)renderer).GetType().Name);
										rVertices.AddRange(vertices);
									}
									else
									{
										if (sharedMesh.isReadable)
										{
											sharedMesh.GetVertices(rVertices);
										}
										else
										{
											sharedMesh.GetNonReadableVertices(rVertices);
										}
										if (executionOptions.VertexCache != null)
										{
											executionOptions.VertexCache[sharedMesh] = rVertices.ToArray();
										}
									}
									goto IL_0515;
								}
								Mesh sharedMesh2 = val4.sharedMesh;
								if ((Object)(object)sharedMesh2 == (Object)null)
								{
									VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a mesh");
									continue;
								}
								IVertexCache vertexCache = executionOptions.VertexCache;
								if (vertexCache != null && !vertexCache.IgnoreSkinnedRenders && executionOptions.VertexCache.TryGetValue(sharedMesh2, out Vector3[] vertices2))
								{
									VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => "Cache hit " + path2 + "/" + ((Object)target2).name + " renderer " + ((object)renderer).GetType().Name);
									rVertices.AddRange(vertices2);
								}
								else
								{
									Mesh val5 = new Mesh();
									val4.BakeMesh(val5, true);
									if (val5.isReadable)
									{
										val5.GetVertices(rVertices);
									}
									else
									{
										val5.GetNonReadableVertices(rVertices);
									}
									Object.Destroy((Object)(object)val5);
									if (executionOptions.VertexCache != null)
									{
										executionOptions.VertexCache[sharedMesh2] = rVertices.ToArray();
									}
								}
								goto IL_0515;
								IL_0515:
								VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => "Processing " + path2 + "/" + ((Object)target2).name + " renderer " + ((object)renderer).GetType().Name + " " + logFunc2?.Invoke(rVertices));
								list.AddRange(rVertices);
							}
							finally
							{
								((IDisposable)val3).Dispose();
							}
						}
					}
					finally
					{
						((IDisposable)val2).Dispose();
					}
				}
				foreach (Transform item in ((Component)target2).transform)
				{
					Transform val6 = item;
					if (((Component)val6).gameObject.activeSelf)
					{
						Matrix4x4 localMatrix2 = Matrix4x4.TRS(val6.localPosition, val6.localRotation, val6.localScale);
						List<Vector3> list3 = CollectionPool<List<Vector3>, Vector3>.Get();
						val6.GetChildVertexes(list3, localMatrix2, path2 + "/" + ((Object)target2).name, executionOptions, logFunc2);
						list.AddRange(list3);
						CollectionPool<List<Vector3>, Vector3>.Release(list3);
					}
				}
				outVertices2.AddRange(((IEnumerable<Vector3>)list).Select((Func<Vector3, Vector3>)((Matrix4x4)(object)localMatrix).MultiplyPoint3x4));
			}
			finally
			{
				((IDisposable)val).Dispose();
			}
			VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => "Completed " + path2 + "/" + ((Object)target2).name + " " + logFunc2?.Invoke(outVertices2));
		}

		private static void CacheChildVertexes(this Transform target, string path, ExecutionOptions executionOptions)
		{
			//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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			string path2 = path;
			Transform target2 = target;
			VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => "Caching " + path2 + "/" + ((Object)target2).name);
			ISet<Type>? filteredComponents = executionOptions.FilteredComponents;
			Component val4 = default(Component);
			if (filteredComponents != null && filteredComponents.Any((Type c) => ((Component)target2).TryGetComponent(c, ref val4)))
			{
				VertexesExtensions.logEvent?.Invoke(LogType.Debug2, () => "Skipping " + path2 + "/" + ((Object)target2).name + "!");
				return;
			}
			List<Renderer> list = default(List<Renderer>);
			PooledObject<List<Renderer>> val = CollectionPool<List<Renderer>, Renderer>.Get(ref list);
			try
			{
				((Component)target2).GetComponents<Renderer>(list);
				foreach (Renderer renderer in list.Where((Renderer r) => r.enabled))
				{
					Renderer obj = renderer;
					SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((obj is SkinnedMeshRenderer) ? obj : null);
					if (val2 == null)
					{
						if (!(renderer is MeshRenderer))
						{
							if (renderer is ParticleSystemRenderer)
							{
							}
						}
						else
						{
							MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
							if ((Object)(object)component == (Object)null)
							{
								VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a MeshFilter");
								continue;
							}
							Mesh sharedMesh = component.sharedMesh;
							if ((Object)(object)sharedMesh == (Object)null)
							{
								VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a mesh");
								continue;
							}
							if (!executionOptions.VertexCache.Cache.ContainsKey(sharedMesh))
							{
								if (sharedMesh.isReadable)
								{
									sharedMesh.CacheVertices(executionOptions);
								}
								else
								{
									sharedMesh.CacheNonReadableVertices(executionOptions);
								}
							}
						}
					}
					else
					{
						Mesh sharedMesh2 = val2.sharedMesh;
						if ((Object)(object)sharedMesh2 == (Object)null)
						{
							VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"{((object)renderer).GetType()} in {path2} is missing a mesh");
							continue;
						}
						if (!executionOptions.VertexCache.Cache.ContainsKey(sharedMesh2))
						{
							Mesh val3 = new Mesh();
							val2.BakeMesh(val3, true);
							if (val3.isReadable)
							{
								val3.CacheVertices(executionOptions, sharedMesh2);
							}
							else
							{
								val3.CacheNonReadableVertices(executionOptions, sharedMesh2);
							}
							Object.Destroy((Object)(object)val3);
						}
					}
					VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => "Caching " + path2 + "/" + ((Object)target2).name + " renderer " + ((object)renderer).GetType().Name);
					foreach (Transform item in ((Component)target2).transform)
					{
						Transform target3 = item;
						target3.CacheChildVertexes(path2 + "/" + ((Object)target2).name, executionOptions);
					}
				}
			}
			finally
			{
				((IDisposable)val).Dispose();
			}
		}

		private static void GetNonReadableVertices(this Mesh nonReadableMesh, List<Vector3> vertexes)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0064: 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)
			Mesh val = new Mesh();
			nonReadableMesh.vertexBufferTarget = (Target)1;
			if (nonReadableMesh.vertexBufferCount > 0)
			{
				GraphicsBuffer vertexBuffer = nonReadableMesh.GetVertexBuffer(0);
				int num = vertexBuffer.stride * vertexBuffer.count;
				byte[] array = ArrayPool<byte>.Shared.Rent(num);
				vertexBuffer.GetData((Array)array, 0, 0, num);
				int vertexAttributeCount = nonReadableMesh.vertexAttributeCount;
				NativeArray<VertexAttributeDescriptor> val2 = default(NativeArray<VertexAttributeDescriptor>);
				val2..ctor(vertexAttributeCount, (Allocator)2, (NativeArrayOptions)1);
				for (int i = 0; i < vertexAttributeCount; i++)
				{
					val2[i] = nonReadableMesh.GetVertexAttribute(i);
				}
				val.SetVertexBufferParams(nonReadableMesh.vertexCount, val2);
				val.SetVertexBufferData<byte>(array, 0, 0, num, 0, (MeshUpdateFlags)0);
				ArrayPool<byte>.Shared.Return(array);
				val2.Dispose();
				vertexBuffer.Dispose();
			}
			val.GetVertices(vertexes);
			Object.Destroy((Object)(object)val);
		}

		private static void CacheNonReadableVertices(this Mesh nonReadableMesh, ExecutionOptions executionOptions, Mesh? cacheKey = null)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			Mesh nonReadableMesh2 = nonReadableMesh;
			Mesh cacheKey2 = cacheKey;
			if (executionOptions.VertexCache.ContainsKey(nonReadableMesh2))
			{
				return;
			}
			nonReadableMesh2.vertexBufferTarget = (Target)1;
			if (nonReadableMesh2.vertexBufferCount <= 0)
			{
				return;
			}
			GraphicsBuffer verticesBuffer = nonReadableMesh2.GetVertexBuffer(0);
			int totalSize = verticesBuffer.stride * verticesBuffer.count;
			VertexAttributeDescriptor[] attributes = nonReadableMesh2.GetVertexAttributes();
			int count = nonReadableMesh2.vertexCount;
			IDictionary<Mesh, Vector3[]> vertexCache = executionOptions.VertexCache.Cache;
			VertexesExtensions.logEvent?.Invoke(LogType.Warning, () => $"Requesting vertexes for {nonReadableMesh2} from GPU");
			AsyncGPUReadback.Request(verticesBuffer, totalSize, 0, (Action<AsyncGPUReadbackRequest>)delegate(AsyncGPUReadbackRequest request)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: 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)
				verticesBuffer.Release();
				if (!vertexCache.ContainsKey(nonReadableMesh2))
				{
					Mesh val = new Mesh();
					NativeArray<byte> data = ((AsyncGPUReadbackRequest)(ref request)).GetData<byte>(0);
					val.SetVertexBufferParams(count, attributes);
					val.SetVertexBufferData<byte>(data, 0, 0, totalSize, 0, (MeshUpdateFlags)0);
					List<Vector3> tmp = default(List<Vector3>);
					PooledObject<List<Vector3>> val2 = CollectionPool<List<Vector3>, Vector3>.Get(ref tmp);
					try
					{
						val.GetVertices(tmp);
						VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => $"Cached {tmp.Count} vertexes for {nonReadableMesh2}");
						executionOptions.VertexCache[((Object)(object)cacheKey2 != (Object)null) ? cacheKey2 : nonReadableMesh2] = tmp.ToArray();
					}
					finally
					{
						((IDisposable)val2).Dispose();
					}
					Object.Destroy((Object)(object)val);
				}
			});
		}

		private static void CacheVertices(this Mesh readableMesh, ExecutionOptions executionOptions, Mesh? cacheKey = null)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Mesh readableMesh2 = readableMesh;
			if (executionOptions.VertexCache.ContainsKey(readableMesh2))
			{
				return;
			}
			List<Vector3> tmp = default(List<Vector3>);
			PooledObject<List<Vector3>> val = CollectionPool<List<Vector3>, Vector3>.Get(ref tmp);
			try
			{
				readableMesh2.GetVertices(tmp);
				VertexesExtensions.logEvent?.Invoke(LogType.Debug1, () => $"Cached {tmp.Count} vertexes for {readableMesh2}");
				executionOptions.VertexCache[(Mesh)(((Object)(object)cacheKey != (Object)null) ? ((object)cacheKey) : ((object)readableMesh2))] = tmp.ToArray();
			}
			finally
			{
				((IDisposable)val).Dispose();
			}
		}
	}
}
namespace VertexLibrary.Caches
{
	internal class FullVertexCache : IVertexCache
	{
		private IVertexCache? _complementaryCache;

		public bool IgnoreSkinnedRenders => false;

		public IDictionary<Mesh, Vector3[]> Cache { get; } = new Dictionary<Mesh, Vector3[]>();


		public FullVertexCache()
		{
		}

		public FullVertexCache(PartialVertexCache complementaryCache)
		{
			_complementaryCache = complementaryCache;
			Cache = complementaryCache.Cache;
		}

		public IVertexCache AsPartial()
		{
			if (_complementaryCache == null)
			{
				_complementaryCache = new PartialVertexCache(this);
			}
			return _complementaryCache;
		}

		public IVertexCache AsFull()
		{
			return this;
		}
	}
	public interface IVertexCache
	{
		bool IgnoreSkinnedRenders { get; }

		int CacheSize => Cache.Count;

		internal IDictionary<Mesh, Vector3[]> Cache { get; }

		Vector3[] this[Mesh mesh]
		{
			get
			{
				return Cache[mesh];
			}
			internal set
			{
				Cache[mesh] = value;
			}
		}

		bool ContainsKey(Mesh mesh)
		{
			return Cache.ContainsKey(mesh);
		}

		bool TryGetValue(Mesh mesh, out Vector3[] vertices)
		{
			return Cache.TryGetValue(mesh, out vertices);
		}

		IVertexCache AsPartial();

		IVertexCache AsFull();

		static IVertexCache CreateCache(bool partial)
		{
			if (partial)
			{
				return new PartialVertexCache();
			}
			return new FullVertexCache();
		}
	}
	internal class PartialVertexCache : IVertexCache
	{
		private IVertexCache? _complementaryCache;

		public bool IgnoreSkinnedRenders => true;

		public IDictionary<Mesh, Vector3[]> Cache { get; } = new Dictionary<Mesh, Vector3[]>();


		public PartialVertexCache()
		{
		}

		public PartialVertexCache(FullVertexCache complementaryCache)
		{
			_complementaryCache = complementaryCache;
			Cache = complementaryCache.Cache;
		}

		public IVertexCache AsPartial()
		{
			return this;
		}

		public IVertexCache AsFull()
		{
			if (_complementaryCache == null)
			{
				_complementaryCache = new FullVertexCache(this);
			}
			return _complementaryCache;
		}
	}
}