Decompiled source of AtlyssGLTF v0.1.0

com.unity.cloud.gltfast.dll

Decompiled a month ago
#define DEBUG
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AOT;
using GLTFast.Addons;
using GLTFast.FakeSchema;
using GLTFast.Jobs;
using GLTFast.Loading;
using GLTFast.Logging;
using GLTFast.Materials;
using GLTFast.Newtonsoft.Schema;
using GLTFast.Schema;
using GLTFast.Vertex;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Unity.Burst;
using Unity.Burst.CompilerServices;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using Unity.Jobs.LowLevel.Unsafe;
using Unity.Mathematics;
using Unity.Properties;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Scripting;
using UnityEngine.Scripting.APIUpdating;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: InternalsVisibleTo("Unity.Burst.Tests")]
[assembly: InternalsVisibleTo("Unity.Collections.BurstCompatibilityTestCodeGen")]
[assembly: InternalsVisibleTo("Unity.Collections.Tests")]
[assembly: InternalsVisibleTo("Unity.Collections.CodeGen")]
[assembly: InternalsVisibleTo("Unity.Collections.Editor")]
[assembly: InternalsVisibleTo("Unity.Collections.PerformanceTests")]
[assembly: InternalsVisibleTo("Unity.Entities")]
[assembly: InternalsVisibleTo("Unity.Entities.CodeGen")]
[assembly: InternalsVisibleTo("Unity.Entities.Tests")]
[assembly: InternalsVisibleTo("Unity.Entities.Editor")]
[assembly: InternalsVisibleTo("Unity.Entities.Editor.Tests")]
[assembly: InternalsVisibleTo("Unity.Entities.Graphics")]
[assembly: InternalsVisibleTo("Unity.Entities.Hybrid")]
[assembly: InternalsVisibleTo("Unity.Runtime")]
[assembly: InternalsVisibleTo("Unity.Runtime.Tests")]
[assembly: InternalsVisibleTo("Unity.Runtime.IO.Tests")]
[assembly: InternalsVisibleTo("Unity.Runtime.UnityInstance")]
[assembly: InternalsVisibleTo("Unity.Scenes")]
[assembly: InternalsVisibleTo("Unity.Scenes.Editor")]
[assembly: InternalsVisibleTo("Samples.GridPath.Tests")]
[assembly: InternalsVisibleTo("Unity.Entities.PerformanceTests")]
[assembly: InternalsVisibleTo("glTF-test-framework.Tests")]
[assembly: InternalsVisibleTo("glTFast.Editor.Tests")]
[assembly: InternalsVisibleTo("glTFast.Editor")]
[assembly: InternalsVisibleTo("glTFast.Export")]
[assembly: InternalsVisibleTo("glTFast.Tests")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("UnityEngine.CoreModule")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.unity.cloud.gltfast")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("com.unity.cloud.gltfast")]
[assembly: AssemblyTitle("com.unity.cloud.gltfast")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[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;
		}
	}
}
namespace GLTFast
{
	[Flags]
	internal enum AccessorUsage
	{
		Unknown = 0,
		Ignore = 1,
		Index = 2,
		IndexFlipped = 4,
		Position = 8,
		Normal = 0x10,
		Tangent = 0x20,
		UV = 0x40,
		Color = 0x80,
		InverseBindMatrix = 0x100,
		AnimationTimes = 0x200,
		Translation = 0x400,
		Rotation = 0x800,
		Scale = 0x1000,
		Weight = 0x2000,
		RequiredForInstantiation = 0x4000
	}
	public enum AnimationMethod
	{
		None,
		Legacy,
		Mecanim
	}
	internal static class AnimationUtils
	{
		private const float k_TimeEpsilon = 1E-05f;

		public static void AddTranslationCurves(AnimationClip clip, string animationPath, NativeArray<float> times, NativeArray<Vector3> translations, InterpolationType interpolationType)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			NativeArray<float3> values = translations.Reinterpret<float3>();
			AddVec3Curves(clip, animationPath, "localPosition.", times, values, interpolationType);
		}

		public static void AddScaleCurves(AnimationClip clip, string animationPath, NativeArray<float> times, NativeArray<Vector3> translations, InterpolationType interpolationType)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			NativeArray<float3> values = translations.Reinterpret<float3>();
			AddVec3Curves(clip, animationPath, "localScale.", times, values, interpolationType);
		}

		public static void AddRotationCurves(AnimationClip clip, string animationPath, NativeArray<float> times, NativeArray<Quaternion> quaternions, InterpolationType interpolationType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0088: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_0274: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: 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_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: 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_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: 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_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: 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_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: 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_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: 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_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: 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_03b8: Unknown result type (might be due to invalid IL or missing references)
			AnimationCurve val = new AnimationCurve();
			AnimationCurve val2 = new AnimationCurve();
			AnimationCurve val3 = new AnimationCurve();
			AnimationCurve val4 = new AnimationCurve();
			NativeArray<quaternion> val5 = quaternions.Reinterpret<quaternion>();
			uint num = 0u;
			switch (interpolationType)
			{
			case InterpolationType.Step:
			{
				for (int k = 0; k < times.Length; k++)
				{
					float num6 = times[k];
					quaternion val14 = val5[k];
					val.AddKey(new Keyframe(num6, val14.value.x, float.PositiveInfinity, 0f));
					val2.AddKey(new Keyframe(num6, val14.value.y, float.PositiveInfinity, 0f));
					val3.AddKey(new Keyframe(num6, val14.value.z, float.PositiveInfinity, 0f));
					val4.AddKey(new Keyframe(num6, val14.value.w, float.PositiveInfinity, 0f));
				}
				break;
			}
			case InterpolationType.CubicSpline:
			{
				for (int j = 0; j < times.Length; j++)
				{
					float num5 = times[j];
					quaternion val11 = val5[j * 3];
					quaternion val12 = val5[j * 3 + 1];
					quaternion val13 = val5[j * 3 + 2];
					val.AddKey(new Keyframe(num5, val12.value.x, val11.value.x, val13.value.x, 0.5f, 0.5f));
					val2.AddKey(new Keyframe(num5, val12.value.y, val11.value.y, val13.value.y, 0.5f, 0.5f));
					val3.AddKey(new Keyframe(num5, val12.value.z, val11.value.z, val13.value.z, 0.5f, 0.5f));
					val4.AddKey(new Keyframe(num5, val12.value.w, val11.value.w, val13.value.w, 0.5f, 0.5f));
				}
				break;
			}
			default:
			{
				float num2 = times[0];
				quaternion val6 = val5[0];
				quaternion val7 = default(quaternion);
				((quaternion)(ref val7))..ctor(new float4(0f));
				quaternion val10 = default(quaternion);
				for (int i = 1; i < times.Length; i++)
				{
					float num3 = times[i];
					quaternion val8 = val5[i];
					if (num2 >= num3)
					{
						num++;
						continue;
					}
					if (math.dot(val6, val8) < 0f)
					{
						val8.value = -val8.value;
					}
					float num4 = num3 - num2;
					float4 val9 = val8.value - val6.value;
					if (num4 < 1E-05f)
					{
						val10.value.x = (((val9.x < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
						val10.value.y = (((val9.y < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
						val10.value.z = (((val9.z < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
						val10.value.w = (((val9.w < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
					}
					else
					{
						val10 = quaternion.op_Implicit(val9 / num4);
					}
					val.AddKey(new Keyframe(num2, val6.value.x, val7.value.x, val10.value.x));
					val2.AddKey(new Keyframe(num2, val6.value.y, val7.value.y, val10.value.y));
					val3.AddKey(new Keyframe(num2, val6.value.z, val7.value.z, val10.value.z));
					val4.AddKey(new Keyframe(num2, val6.value.w, val7.value.w, val10.value.w));
					val7 = val10;
					num2 = num3;
					val6 = val8;
				}
				val.AddKey(new Keyframe(num2, val6.value.x, val7.value.x, 0f));
				val2.AddKey(new Keyframe(num2, val6.value.y, val7.value.y, 0f));
				val3.AddKey(new Keyframe(num2, val6.value.z, val7.value.z, 0f));
				val4.AddKey(new Keyframe(num2, val6.value.w, val7.value.w, 0f));
				break;
			}
			}
			clip.SetCurve(animationPath, typeof(Transform), "localRotation.x", val);
			clip.SetCurve(animationPath, typeof(Transform), "localRotation.y", val2);
			clip.SetCurve(animationPath, typeof(Transform), "localRotation.z", val3);
			clip.SetCurve(animationPath, typeof(Transform), "localRotation.w", val4);
			if (num != 0)
			{
				ReportDuplicateKeyframes();
			}
		}

		public static string CreateAnimationPath(int nodeIndex, string[] nodeNames, int[] parentIndex)
		{
			StringBuilder stringBuilder = new StringBuilder();
			do
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Insert(0, '/');
				}
				stringBuilder.Insert(0, nodeNames[nodeIndex]);
				nodeIndex = parentIndex[nodeIndex];
			}
			while (nodeIndex >= 0);
			return stringBuilder.ToString();
		}

		public static void AddMorphTargetWeightCurves(AnimationClip clip, string animationPath, NativeArray<float> times, NativeArray<float> values, InterpolationType interpolationType, string[] morphTargetNames = null)
		{
			//IL_0052: 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)
			int num;
			if (morphTargetNames == null)
			{
				num = values.Length / times.Length;
				if (interpolationType == InterpolationType.CubicSpline)
				{
					num /= 3;
				}
			}
			else
			{
				num = morphTargetNames.Length;
			}
			for (int i = 0; i < num; i++)
			{
				string propertyPrefix = ((morphTargetNames == null) ? i.ToString() : morphTargetNames[i]);
				AddScalarCurve(clip, animationPath, propertyPrefix, i, num, times, values, interpolationType);
			}
		}

		private static void AddVec3Curves(AnimationClip clip, string animationPath, string propertyPrefix, NativeArray<float> times, NativeArray<float3> values, InterpolationType interpolationType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//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_0051: 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_0070: 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_008f: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_013b: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: 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_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_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			AnimationCurve val = new AnimationCurve();
			AnimationCurve val2 = new AnimationCurve();
			AnimationCurve val3 = new AnimationCurve();
			uint num = 0u;
			switch (interpolationType)
			{
			case InterpolationType.Step:
			{
				for (int k = 0; k < times.Length; k++)
				{
					float num6 = times[k];
					float3 val12 = values[k];
					val.AddKey(new Keyframe(num6, val12.x, float.PositiveInfinity, 0f));
					val2.AddKey(new Keyframe(num6, val12.y, float.PositiveInfinity, 0f));
					val3.AddKey(new Keyframe(num6, val12.z, float.PositiveInfinity, 0f));
				}
				break;
			}
			case InterpolationType.CubicSpline:
			{
				for (int j = 0; j < times.Length; j++)
				{
					float num5 = times[j];
					float3 val9 = values[j * 3];
					float3 val10 = values[j * 3 + 1];
					float3 val11 = values[j * 3 + 2];
					val.AddKey(new Keyframe(num5, val10.x, val9.x, val11.x, 0.5f, 0.5f));
					val2.AddKey(new Keyframe(num5, val10.y, val9.y, val11.y, 0.5f, 0.5f));
					val3.AddKey(new Keyframe(num5, val10.z, val9.z, val11.z, 0.5f, 0.5f));
				}
				break;
			}
			default:
			{
				float num2 = times[0];
				float3 val4 = values[0];
				float3 val5 = default(float3);
				((float3)(ref val5))..ctor(0f);
				float3 val8 = default(float3);
				for (int i = 1; i < times.Length; i++)
				{
					float num3 = times[i];
					float3 val6 = values[i];
					if (num2 >= num3)
					{
						num++;
						continue;
					}
					float num4 = num3 - num2;
					float3 val7 = val6 - val4;
					if (num4 < 1E-05f)
					{
						val8.x = (((val7.x < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
						val8.y = (((val7.y < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
						val8.z = (((val7.z < 0f) ^ (num4 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity);
					}
					else
					{
						val8 = val7 / num4;
					}
					val.AddKey(new Keyframe(num2, val4.x, val5.x, val8.x));
					val2.AddKey(new Keyframe(num2, val4.y, val5.y, val8.y));
					val3.AddKey(new Keyframe(num2, val4.z, val5.z, val8.z));
					val5 = val8;
					num2 = num3;
					val4 = val6;
				}
				val.AddKey(new Keyframe(num2, val4.x, val5.x, 0f));
				val2.AddKey(new Keyframe(num2, val4.y, val5.y, 0f));
				val3.AddKey(new Keyframe(num2, val4.z, val5.z, 0f));
				break;
			}
			}
			clip.SetCurve(animationPath, typeof(Transform), propertyPrefix + "x", val);
			clip.SetCurve(animationPath, typeof(Transform), propertyPrefix + "y", val2);
			clip.SetCurve(animationPath, typeof(Transform), propertyPrefix + "z", val3);
			if (num != 0)
			{
				ReportDuplicateKeyframes();
			}
		}

		private static void AddScalarCurve(AnimationClip clip, string animationPath, string propertyPrefix, int curveIndex, int valueStride, NativeArray<float> times, NativeArray<float> values, InterpolationType interpolationType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0052: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			AnimationCurve val = new AnimationCurve();
			uint num = 0u;
			switch (interpolationType)
			{
			case InterpolationType.Step:
			{
				for (int k = 0; k < times.Length; k++)
				{
					float num16 = times[k];
					int num17 = k * valueStride + curveIndex;
					float num18 = values[num17];
					val.AddKey(new Keyframe(num16, num18, float.PositiveInfinity, 0f));
				}
				break;
			}
			case InterpolationType.CubicSpline:
			{
				for (int j = 0; j < times.Length; j++)
				{
					float num11 = times[j];
					int num12 = j * valueStride + curveIndex;
					float num13 = values[num12 * 3];
					float num14 = values[num12 * 3 + 1];
					float num15 = values[num12 * 3 + 2];
					val.AddKey(new Keyframe(num11, num14, num13, num15, 0.5f, 0.5f));
				}
				break;
			}
			default:
			{
				float num2 = times[0];
				float num3 = values[curveIndex];
				float num4 = 0f;
				for (int i = 1; i < times.Length; i++)
				{
					float num5 = times[i];
					int num6 = i * valueStride + curveIndex;
					float num7 = values[num6];
					if (num2 >= num5)
					{
						num++;
						continue;
					}
					float num8 = num5 - num2;
					float num9 = num7 - num3;
					float num10 = ((!(num8 < 1E-05f)) ? (num9 / num8) : (((num9 < 0f) ^ (num8 < 0f)) ? float.NegativeInfinity : float.PositiveInfinity));
					val.AddKey(new Keyframe(num2, num3, num4, num10));
					num4 = num10;
					num2 = num5;
					num3 = num7;
				}
				val.AddKey(new Keyframe(num2, num3, num4, 0f));
				break;
			}
			}
			clip.SetCurve(animationPath, typeof(SkinnedMeshRenderer), "blendShape." + propertyPrefix, val);
			if (num != 0)
			{
				ReportDuplicateKeyframes();
			}
		}

		private static void ReportDuplicateKeyframes()
		{
			Debug.LogError((object)"Time of subsequent animation keyframes is not increasing (glTF-Validator error ACCESSOR_ANIMATION_INPUT_NON_INCREASING)");
		}
	}
	[Flags]
	public enum ComponentType
	{
		None = 0,
		Mesh = 2,
		Animation = 4,
		Camera = 8,
		Light = 0x10,
		All = -1
	}
	[RequireComponent(typeof(IDeferAgent))]
	[DefaultExecutionOrder(-1)]
	internal class DefaultDeferAgent : MonoBehaviour
	{
		private void OnEnable()
		{
			IDeferAgent component = ((Component)this).GetComponent<IDeferAgent>();
			if (component != null)
			{
				GltfImportBase.SetDefaultDeferAgent(component);
			}
		}

		private void OnDisable()
		{
			IDeferAgent component = ((Component)this).GetComponent<IDeferAgent>();
			if (component != null)
			{
				GltfImportBase.UnsetDefaultDeferAgent(component);
			}
		}
	}
	public class DontDestroyOnLoad : MonoBehaviour
	{
		private void Awake()
		{
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}
	}
	public enum Extension
	{
		DracoMeshCompression,
		LightsPunctual,
		MaterialsPbrSpecularGlossiness,
		MaterialsTransmission,
		MaterialsUnlit,
		MeshGPUInstancing,
		MeshQuantization,
		TextureBasisUniversal,
		TextureTransform,
		MaterialsClearcoat,
		MaterialsVariants,
		MeshoptCompression,
		MaterialsIor,
		MaterialsSheen,
		MaterialsSpecular
	}
	public static class ExtensionName
	{
		public const string DracoMeshCompression = "KHR_draco_mesh_compression";

		public const string MaterialsPbrSpecularGlossiness = "KHR_materials_pbrSpecularGlossiness";

		public const string MaterialsTransmission = "KHR_materials_transmission";

		public const string MaterialsUnlit = "KHR_materials_unlit";

		public const string MeshGPUInstancing = "EXT_mesh_gpu_instancing";

		public const string MeshoptCompression = "EXT_meshopt_compression";

		public const string MeshQuantization = "KHR_mesh_quantization";

		public const string TextureBasisUniversal = "KHR_texture_basisu";

		public const string TextureTransform = "KHR_texture_transform";

		public const string LightsPunctual = "KHR_lights_punctual";

		public const string MaterialsClearcoat = "KHR_materials_clearcoat";

		public const string MaterialsIor = "KHR_materials_ior";

		public const string MaterialsSheen = "KHR_materials_sheen";

		public const string MaterialsSpecular = "KHR_materials_specular";

		public const string MaterialsVariants = "KHR_materials_variants";

		public static string GetName(this Extension extension)
		{
			return extension switch
			{
				Extension.DracoMeshCompression => "KHR_draco_mesh_compression", 
				Extension.LightsPunctual => "KHR_lights_punctual", 
				Extension.MaterialsPbrSpecularGlossiness => "KHR_materials_pbrSpecularGlossiness", 
				Extension.MaterialsTransmission => "KHR_materials_transmission", 
				Extension.MaterialsUnlit => "KHR_materials_unlit", 
				Extension.MeshGPUInstancing => "EXT_mesh_gpu_instancing", 
				Extension.MeshQuantization => "KHR_mesh_quantization", 
				Extension.TextureBasisUniversal => "KHR_texture_basisu", 
				Extension.TextureTransform => "KHR_texture_transform", 
				Extension.MaterialsClearcoat => "KHR_materials_clearcoat", 
				Extension.MaterialsVariants => "KHR_materials_variants", 
				Extension.MeshoptCompression => "EXT_meshopt_compression", 
				Extension.MaterialsIor => "KHR_materials_ior", 
				Extension.MaterialsSpecular => "KHR_materials_specular", 
				Extension.MaterialsSheen => "KHR_materials_sheen", 
				_ => null, 
			};
		}
	}
	internal class FlatArray<T>
	{
		private readonly T[] m_Array;

		private readonly int[] m_Indices;

		public int Length => m_Array.Length;

		public T this[int key] => m_Array[key];

		public FlatArray(int[] indices)
		{
			m_Indices = indices;
			int num = indices[^1];
			m_Array = new T[num];
		}

		public int GetLength(int primaryIndex)
		{
			int num = m_Indices[primaryIndex];
			int num2 = m_Indices[primaryIndex + 1];
			return num2 - num;
		}

		public T GetValue(int primaryIndex, int secondaryIndex)
		{
			int index = GetIndex(primaryIndex, secondaryIndex);
			return m_Array[index];
		}

		public void SetValue(int primaryIndex, int secondaryIndex, T value)
		{
			int index = GetIndex(primaryIndex, secondaryIndex);
			m_Array[index] = value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private int GetIndex(int primaryIndex, int secondaryIndex)
		{
			int num = m_Indices[primaryIndex];
			int num2 = m_Indices[primaryIndex + 1];
			return num + secondaryIndex;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private void GetIndexRange(int primaryIndex, out int start, out int end)
		{
			start = m_Indices[primaryIndex];
			end = m_Indices[primaryIndex + 1];
		}

		public IEnumerable<T> Values(int primaryIndex)
		{
			GetIndexRange(primaryIndex, out var start, out var end);
			for (int i = start; i < end; i++)
			{
				yield return m_Array[i];
			}
		}
	}
	public class GameObjectBoundsInstantiator : GameObjectInstantiator
	{
		private Dictionary<uint, Bounds> m_NodeBounds;

		public GameObjectBoundsInstantiator(IGltfReadable gltf, Transform parent, ICodeLogger logger = null, InstantiationSettings settings = null)
			: base(gltf, parent, logger, settings)
		{
		}

		public override void BeginScene(string name, uint[] rootNodeIndices)
		{
			base.BeginScene(name, rootNodeIndices);
			m_NodeBounds = new Dictionary<uint, Bounds>();
		}

		public override void AddPrimitive(uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 0)
		{
			//IL_0027: 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_0048: 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_0052: 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_008d: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			base.AddPrimitive(nodeIndex, meshName, meshResult, joints, rootJoint, morphTargetWeights, meshNumeration);
			if (m_NodeBounds != null)
			{
				Bounds transformedBounds = GetTransformedBounds(meshResult.mesh.bounds, m_Parent.worldToLocalMatrix * m_Nodes[nodeIndex].transform.localToWorldMatrix);
				if (m_NodeBounds.TryGetValue(nodeIndex, out var value))
				{
					((Bounds)(ref transformedBounds)).Encapsulate(value);
					m_NodeBounds[nodeIndex] = transformedBounds;
				}
				else
				{
					m_NodeBounds[nodeIndex] = transformedBounds;
				}
			}
		}

		public Bounds? CalculateBounds()
		{
			//IL_0020: 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_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_004f: 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)
			if (m_NodeBounds == null)
			{
				return null;
			}
			bool flag = false;
			Bounds value = default(Bounds);
			foreach (Bounds value2 in m_NodeBounds.Values)
			{
				if (flag)
				{
					((Bounds)(ref value)).Encapsulate(value2);
					continue;
				}
				value = value2;
				flag = true;
			}
			return flag ? new Bounds?(value) : null;
		}

		private static Bounds GetTransformedBounds(Bounds b, Matrix4x4 transform)
		{
			//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_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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[8];
			Vector3 extents = ((Bounds)(ref b)).extents;
			for (int i = 0; i < 8; i++)
			{
				Vector3 center = ((Bounds)(ref b)).center;
				center.x += (((i & 1) == 0) ? extents.x : (0f - extents.x));
				center.y += (((i & 2) == 0) ? extents.y : (0f - extents.y));
				center.z += (((i & 4) == 0) ? extents.z : (0f - extents.z));
				array[i] = center;
			}
			return GeometryUtility.CalculateBounds(array, transform);
		}
	}
	public class GameObjectInstantiator : IInstantiator
	{
		public delegate void NodeCreatedDelegate(uint nodeIndex, GameObject gameObject);

		public delegate void MeshAddedDelegate(GameObject gameObject, uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 0);

		protected InstantiationSettings m_Settings;

		protected ICodeLogger m_Logger;

		protected IGltfReadable m_Gltf;

		protected Transform m_Parent;

		protected Dictionary<uint, GameObject> m_Nodes;

		private List<IMaterialsVariantsSlotInstance> m_InstanceSlots;

		public Transform SceneTransform { get; protected set; }

		public GameObjectSceneInstance SceneInstance { get; protected set; }

		public event NodeCreatedDelegate NodeCreated;

		public event MeshAddedDelegate MeshAdded;

		public event Action EndSceneCompleted;

		public GameObjectInstantiator(IGltfReadable gltf, Transform parent, ICodeLogger logger = null, InstantiationSettings settings = null)
		{
			m_Gltf = gltf;
			m_Parent = parent;
			m_Logger = logger;
			m_Settings = settings ?? new InstantiationSettings();
		}

		public virtual void BeginScene(string name, uint[] rootNodeIndices)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			m_Nodes = new Dictionary<uint, GameObject>();
			SceneInstance = new GameObjectSceneInstance();
			GameObject val;
			if (m_Settings.SceneObjectCreation == SceneObjectCreation.Never || (m_Settings.SceneObjectCreation == SceneObjectCreation.WhenMultipleRootNodes && rootNodeIndices.Length == 1))
			{
				val = ((Component)m_Parent).gameObject;
			}
			else
			{
				val = new GameObject(name ?? "Scene");
				val.transform.SetParent(m_Parent, false);
				val.layer = m_Settings.Layer;
			}
			SceneTransform = val.transform;
		}

		public void AddAnimation(AnimationClip[] animationClips)
		{
			if ((m_Settings.Mask & ComponentType.Animation) == 0 || animationClips == null)
			{
				return;
			}
			if (animationClips.Length != 0 && animationClips[0].legacy)
			{
				Animation val = ((Component)SceneTransform).gameObject.AddComponent<Animation>();
				for (int i = 0; i < animationClips.Length; i++)
				{
					AnimationClip val2 = animationClips[i];
					val.AddClip(val2, ((Object)val2).name);
					if (i < 1)
					{
						val.clip = val2;
					}
				}
				SceneInstance.SetLegacyAnimation(val);
			}
			else
			{
				((Component)SceneTransform).gameObject.AddComponent<Animator>();
			}
		}

		public void CreateNode(uint nodeIndex, uint? parentIndex, Vector3 position, Quaternion rotation, Vector3 scale)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001b: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject();
			val.SetActive(parentIndex.HasValue);
			val.transform.localScale = scale;
			val.transform.localPosition = position;
			val.transform.localRotation = rotation;
			val.layer = m_Settings.Layer;
			m_Nodes[nodeIndex] = val;
			val.transform.SetParent(parentIndex.HasValue ? m_Nodes[parentIndex.Value].transform : SceneTransform, false);
			this.NodeCreated?.Invoke(nodeIndex, val);
		}

		public virtual void SetNodeName(uint nodeIndex, string name)
		{
			((Object)m_Nodes[nodeIndex]).name = name ?? $"Node-{nodeIndex}";
		}

		public virtual void AddPrimitive(uint nodeIndex, string meshName, MeshResult meshResult, uint[] joints = null, uint? rootJoint = null, float[] morphTargetWeights = null, int meshNumeration = 0)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if ((m_Settings.Mask & ComponentType.Mesh) == 0)
			{
				return;
			}
			GameObject val;
			if (meshNumeration == 0)
			{
				val = m_Nodes[nodeIndex];
			}
			else
			{
				val = new GameObject(meshName);
				val.transform.SetParent(m_Nodes[nodeIndex].transform, false);
				val.layer = m_Settings.Layer;
			}
			bool flag = meshResult.mesh.blendShapeCount > 0;
			Renderer val4;
			if (joints == null && !flag)
			{
				MeshFilter val2 = val.AddComponent<MeshFilter>();
				val2.mesh = meshResult.mesh;
				MeshRenderer val3 = val.AddComponent<MeshRenderer>();
				val4 = (Renderer)(object)val3;
			}
			else
			{
				SkinnedMeshRenderer val5 = val.AddComponent<SkinnedMeshRenderer>();
				val5.updateWhenOffscreen = m_Settings.SkinUpdateWhenOffscreen;
				if (joints != null)
				{
					Transform[] array = (Transform[])(object)new Transform[joints.Length];
					for (int i = 0; i < array.Length; i++)
					{
						uint key = joints[i];
						array[i] = m_Nodes[key].transform;
					}
					val5.bones = array;
					if (rootJoint.HasValue)
					{
						val5.rootBone = m_Nodes[rootJoint.Value].transform;
					}
				}
				val5.sharedMesh = meshResult.mesh;
				if (morphTargetWeights != null)
				{
					for (int j = 0; j < morphTargetWeights.Length; j++)
					{
						float num = morphTargetWeights[j];
						val5.SetBlendShapeWeight(j, num);
					}
				}
				val4 = (Renderer)(object)val5;
			}
			Material[] array2 = (Material[])(object)new Material[meshResult.materialIndices.Length];
			for (int k = 0; k < array2.Length; k++)
			{
				Material val6 = m_Gltf.GetMaterial(meshResult.materialIndices[k]) ?? m_Gltf.GetDefaultMaterial();
				array2[k] = val6;
			}
			val4.sharedMaterials = array2;
			IMaterialsVariantsSlot[] materialsVariantsSlots = m_Gltf.GetMaterialsVariantsSlots(meshResult.meshIndex, meshNumeration);
			if (materialsVariantsSlots != null && materialsVariantsSlots.Length != 0)
			{
				if (m_InstanceSlots == null)
				{
					m_InstanceSlots = new List<IMaterialsVariantsSlotInstance>();
				}
				MaterialsVariantsSlotInstances materialsVariantsSlotInstances = new MaterialsVariantsSlotInstances(val4, materialsVariantsSlots);
				m_InstanceSlots.Add(materialsVariantsSlotInstances);
			}
			this.MeshAdded?.Invoke(val, nodeIndex, meshName, meshResult, joints, rootJoint, morphTargetWeights, meshNumeration);
		}

		public virtual void AddPrimitiveInstanced(uint nodeIndex, string meshName, MeshResult meshResult, uint instanceCount, NativeArray<Vector3>? positions, NativeArray<Quaternion>? rotations, NativeArray<Vector3>? scales, int meshNumeration = 0)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_0172: 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)
			if ((m_Settings.Mask & ComponentType.Mesh) == 0)
			{
				return;
			}
			Material[] array = (Material[])(object)new Material[meshResult.materialIndices.Length];
			for (int i = 0; i < array.Length; i++)
			{
				Material val = m_Gltf.GetMaterial(meshResult.materialIndices[i]) ?? m_Gltf.GetDefaultMaterial();
				val.enableInstancing = true;
				array[i] = val;
			}
			IMaterialsVariantsSlot[] materialsVariantsSlots = m_Gltf.GetMaterialsVariantsSlots(meshResult.meshIndex, meshNumeration);
			bool flag = materialsVariantsSlots != null && materialsVariantsSlots.Length != 0;
			Renderer[] array2 = (Renderer[])(object)(flag ? new Renderer[instanceCount] : null);
			for (int j = 0; j < instanceCount; j++)
			{
				GameObject val2 = new GameObject($"{meshName}_i{j}");
				val2.layer = m_Settings.Layer;
				Transform transform = val2.transform;
				transform.SetParent(m_Nodes[nodeIndex].transform, false);
				transform.localPosition = positions?[j] ?? Vector3.zero;
				transform.localRotation = rotations?[j] ?? Quaternion.identity;
				transform.localScale = scales?[j] ?? Vector3.one;
				MeshFilter val3 = val2.AddComponent<MeshFilter>();
				val3.mesh = meshResult.mesh;
				Renderer val4 = (Renderer)(object)val2.AddComponent<MeshRenderer>();
				val4.sharedMaterials = array;
				if (flag)
				{
					array2[j] = val4;
				}
			}
			if (flag)
			{
				if (m_InstanceSlots == null)
				{
					m_InstanceSlots = new List<IMaterialsVariantsSlotInstance>();
				}
				MultiMaterialsVariantsSlotInstances multiMaterialsVariantsSlotInstances = new MultiMaterialsVariantsSlotInstances(array2, materialsVariantsSlots);
				m_InstanceSlots.Add(multiMaterialsVariantsSlotInstances);
			}
		}

		public virtual void AddCamera(uint nodeIndex, uint cameraIndex)
		{
			if ((m_Settings.Mask & ComponentType.Camera) != 0)
			{
				CameraBase sourceCamera = m_Gltf.GetSourceCamera(cameraIndex);
				switch (sourceCamera.GetCameraType())
				{
				case CameraBase.Type.Orthographic:
				{
					GLTFast.Schema.CameraOrthographic orthographic = sourceCamera.Orthographic;
					AddCameraOrthographic(nodeIndex, orthographic.znear, (orthographic.zfar >= 0f) ? new float?(orthographic.zfar) : null, orthographic.xmag, orthographic.ymag, sourceCamera.name);
					break;
				}
				case CameraBase.Type.Perspective:
				{
					GLTFast.Schema.CameraPerspective perspective = sourceCamera.Perspective;
					AddCameraPerspective(nodeIndex, perspective.yfov, perspective.znear, perspective.zfar, (perspective.aspectRatio > 0f) ? new float?(perspective.aspectRatio) : null, sourceCamera.name);
					break;
				}
				}
			}
		}

		private void AddCameraPerspective(uint nodeIndex, float verticalFieldOfView, float nearClipPlane, float farClipPlane, float? aspectRatio, string cameraName)
		{
			float localScale;
			Camera val = CreateCamera(nodeIndex, cameraName, out localScale);
			val.orthographic = false;
			val.fieldOfView = verticalFieldOfView * 57.29578f;
			val.nearClipPlane = nearClipPlane * localScale;
			val.farClipPlane = farClipPlane * localScale;
		}

		private void AddCameraOrthographic(uint nodeIndex, float nearClipPlane, float? farClipPlane, float horizontal, float vertical, string cameraName)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			float localScale;
			Camera val = CreateCamera(nodeIndex, cameraName, out localScale);
			float valueOrDefault = farClipPlane.GetValueOrDefault(float.MaxValue);
			val.orthographic = true;
			val.nearClipPlane = nearClipPlane * localScale;
			val.farClipPlane = valueOrDefault * localScale;
			val.orthographicSize = vertical;
			val.projectionMatrix = Matrix4x4.Ortho(0f - horizontal, horizontal, 0f - vertical, vertical, nearClipPlane, valueOrDefault);
		}

		private Camera CreateCamera(uint nodeIndex, string cameraName, out float localScale)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//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_007e: 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_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_00b7: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = m_Nodes[nodeIndex];
			GameObject val2 = new GameObject(string.IsNullOrEmpty(cameraName) ? $"Camera-{nodeIndex}" : (((Object)val).name + "-Camera"));
			val2.layer = m_Settings.Layer;
			Transform transform = val2.transform;
			Transform transform2 = val.transform;
			transform.SetParent(transform2, false);
			Quaternion localRotation = Quaternion.Euler(0f, 180f, 0f);
			transform.localRotation = localRotation;
			Camera val3 = val2.AddComponent<Camera>();
			((Behaviour)val3).enabled = false;
			SceneInstance.AddCamera(val3);
			Matrix4x4 localToWorldMatrix = transform2.localToWorldMatrix;
			Vector3 lossyScale = ((Matrix4x4)(ref localToWorldMatrix)).lossyScale;
			localScale = (lossyScale.x + lossyScale.y + lossyScale.y) / 3f;
			return val3;
		}

		public void AddLightPunctual(uint nodeIndex, uint lightIndex)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if ((m_Settings.Mask & ComponentType.Light) != 0)
			{
				GameObject val = m_Nodes[nodeIndex];
				LightPunctual sourceLightPunctual = m_Gltf.GetSourceLightPunctual(lightIndex);
				if (sourceLightPunctual.GetLightType() != LightPunctual.Type.Point)
				{
					GameObject val2 = new GameObject(((Object)val).name + "_Orientation");
					val2.transform.SetParent(val.transform, false);
					val2.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
					val = val2;
				}
				Light val3 = val.AddComponent<Light>();
				sourceLightPunctual.ToUnityLight(val3, m_Settings.LightIntensityFactor);
				SceneInstance.AddLight(val3);
			}
		}

		public virtual void EndScene(uint[] rootNodeIndices)
		{
			if (m_InstanceSlots != null)
			{
				MaterialsVariantsControl materialsVariantsControl = new MaterialsVariantsControl(m_Gltf, m_InstanceSlots);
				SceneInstance.SetMaterialsVariantsControl(materialsVariantsControl);
			}
			if (rootNodeIndices != null)
			{
				foreach (uint key in rootNodeIndices)
				{
					m_Nodes[key].SetActive(true);
				}
			}
			this.EndSceneCompleted?.Invoke();
		}
	}
	public class GameObjectSceneInstance
	{
		private List<Camera> m_Cameras;

		private List<Light> m_Lights;

		public IReadOnlyList<Camera> Cameras => m_Cameras;

		public IReadOnlyList<Light> Lights => m_Lights;

		public MaterialsVariantsControl MaterialsVariantsControl { get; private set; }

		public Animation LegacyAnimation { get; private set; }

		internal void AddCamera(Camera camera)
		{
			if (m_Cameras == null)
			{
				m_Cameras = new List<Camera>();
			}
			m_Cameras.Add(camera);
		}

		internal void AddLight(Light light)
		{
			if (m_Lights == null)
			{
				m_Lights = new List<Light>();
			}
			m_Lights.Add(light);
		}

		internal void SetMaterialsVariantsControl(MaterialsVariantsControl control)
		{
			MaterialsVariantsControl = control;
		}

		internal void SetLegacyAnimation(Animation animation)
		{
			LegacyAnimation = animation;
		}
	}
	internal readonly struct GlbBinChunk
	{
		public int Start { get; }

		public uint Length { get; }

		public GlbBinChunk(int start, uint length)
		{
			Start = start;
			Length = length;
		}
	}
	public class GltfAsset : GltfAssetBase
	{
		[SerializeField]
		[Tooltip("URL to load the glTF from. Loading local file paths works by prefixing them with \"file://\"")]
		private string url;

		[SerializeField]
		[Tooltip("Automatically load at start.")]
		private bool loadOnStartup = true;

		[SerializeField]
		[Tooltip("Override scene to load (-1 loads glTFs default scene)")]
		private int sceneId = -1;

		[SerializeField]
		[Tooltip("If true, the first animation clip starts playing right after instantiation")]
		private bool playAutomatically = true;

		[SerializeField]
		[Tooltip("If checked, url is treated as relative StreamingAssets path.")]
		private bool streamingAsset;

		[SerializeField]
		private InstantiationSettings instantiationSettings;

		public string Url
		{
			get
			{
				return url;
			}
			set
			{
				url = value;
			}
		}

		public bool LoadOnStartup
		{
			get
			{
				return loadOnStartup;
			}
			set
			{
				loadOnStartup = value;
			}
		}

		protected int SceneId => sceneId;

		public bool PlayAutomatically => playAutomatically;

		public bool StreamingAsset
		{
			get
			{
				return streamingAsset;
			}
			set
			{
				streamingAsset = value;
			}
		}

		public InstantiationSettings InstantiationSettings
		{
			get
			{
				return instantiationSettings;
			}
			set
			{
				instantiationSettings = value;
			}
		}

		public GameObjectSceneInstance SceneInstance { get; protected set; }

		public string FullUrl => streamingAsset ? Path.Combine(Application.streamingAssetsPath, url) : url;

		protected virtual async void Start()
		{
			if (loadOnStartup && !string.IsNullOrEmpty(url))
			{
				await Load(FullUrl);
			}
		}

		public override async Task<bool> Load(string gltfUrl, IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
		{
			logger = logger ?? new ConsoleLogger();
			bool success = await base.Load(gltfUrl, downloadProvider, deferAgent, materialGenerator, logger);
			if (success)
			{
				if (deferAgent != null)
				{
					await deferAgent.BreakPoint();
				}
				success = ((sceneId < 0) ? (await Instantiate(logger)) : (await InstantiateScene(sceneId, logger)));
			}
			return success;
		}

		protected override IInstantiator GetDefaultInstantiator(ICodeLogger logger)
		{
			return new GameObjectInstantiator(base.Importer, ((Component)this).transform, logger, instantiationSettings);
		}

		protected override void PostInstantiation(IInstantiator instantiator, bool success)
		{
			SceneInstance = (instantiator as GameObjectInstantiator)?.SceneInstance;
			if (SceneInstance != null && playAutomatically)
			{
				Animation legacyAnimation = SceneInstance.LegacyAnimation;
				if ((Object)(object)legacyAnimation != (Object)null)
				{
					SceneInstance.LegacyAnimation.Play();
				}
			}
			base.PostInstantiation(instantiator, success);
		}

		public override void ClearScenes()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			if ((Object)(object)SceneInstance?.LegacyAnimation != (Object)null)
			{
				Object.Destroy((Object)(object)SceneInstance.LegacyAnimation);
			}
			SceneInstance = null;
		}
	}
	public abstract class GltfAssetBase : MonoBehaviour
	{
		[SerializeField]
		private ImportSettings importSettings;

		public ImportSettings ImportSettings
		{
			get
			{
				return importSettings;
			}
			set
			{
				importSettings = value;
			}
		}

		public GltfImport Importer { get; protected set; }

		public bool IsDone => Importer != null && Importer.LoadingDone;

		public int? CurrentSceneId { get; protected set; }

		public int SceneCount => Importer?.SceneCount ?? 0;

		public string[] SceneNames
		{
			get
			{
				if (Importer != null && Importer.SceneCount > 0)
				{
					string[] array = new string[Importer.SceneCount];
					for (int i = 0; i < array.Length; i++)
					{
						array[i] = Importer.GetSceneName(i);
					}
					return array;
				}
				return null;
			}
		}

		public virtual async Task<bool> Load(string gltfUrl, IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
		{
			Importer = new GltfImport(downloadProvider, deferAgent, materialGenerator, logger);
			return await Importer.Load(gltfUrl, importSettings);
		}

		public async Task<bool> Instantiate(ICodeLogger logger = null)
		{
			if (Importer == null)
			{
				return false;
			}
			IInstantiator instantiator = GetDefaultInstantiator(logger);
			bool success = await Importer.InstantiateMainSceneAsync(instantiator);
			PostInstantiation(instantiator, success);
			return success;
		}

		public virtual async Task<bool> InstantiateScene(int sceneIndex, ICodeLogger logger = null)
		{
			if (Importer == null)
			{
				return false;
			}
			IInstantiator instantiator = GetDefaultInstantiator(logger);
			bool success = await Importer.InstantiateSceneAsync(instantiator, sceneIndex);
			PostInstantiation(instantiator, success);
			return success;
		}

		protected async Task<bool> InstantiateScene(int sceneIndex, GameObjectInstantiator instantiator)
		{
			if (Importer == null)
			{
				return false;
			}
			bool success = await Importer.InstantiateSceneAsync((IInstantiator)instantiator, sceneIndex, default(CancellationToken));
			PostInstantiation(instantiator, success);
			return success;
		}

		public abstract void ClearScenes();

		public Material GetMaterial(int index = 0)
		{
			return Importer?.GetMaterial(index);
		}

		protected abstract IInstantiator GetDefaultInstantiator(ICodeLogger logger);

		protected virtual void PostInstantiation(IInstantiator instantiator, bool success)
		{
			CurrentSceneId = (success ? Importer.DefaultSceneIndex : null);
		}

		public void Dispose()
		{
			if (Importer != null)
			{
				Importer.Dispose();
				Importer = null;
			}
		}

		protected virtual void OnDestroy()
		{
			Dispose();
		}
	}
	public class GltfBoundsAsset : GltfAsset
	{
		[SerializeField]
		[Tooltip("If true, a box collider encapsulating the glTF asset is created")]
		private bool createBoxCollider = true;

		public bool CreateBoxCollider
		{
			get
			{
				return createBoxCollider;
			}
			set
			{
				createBoxCollider = value;
			}
		}

		public Bounds Bounds { get; private set; }

		public override async Task<bool> Load(string gltfUrl, IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
		{
			base.Importer = new GltfImport(downloadProvider, deferAgent, materialGenerator, logger);
			bool success = await base.Importer.Load(gltfUrl);
			if (success)
			{
				GameObjectBoundsInstantiator instantiator = (GameObjectBoundsInstantiator)GetDefaultInstantiator(logger);
				if (base.SceneId >= 0)
				{
					success = await base.Importer.InstantiateSceneAsync((IInstantiator)instantiator, base.SceneId, default(CancellationToken));
					base.CurrentSceneId = (success ? new int?(base.SceneId) : null);
				}
				else
				{
					success = await base.Importer.InstantiateMainSceneAsync((IInstantiator)instantiator, default(CancellationToken));
					base.CurrentSceneId = base.Importer.DefaultSceneIndex;
				}
				base.SceneInstance = instantiator.SceneInstance;
				if (success)
				{
					SetBounds(instantiator);
				}
			}
			return success;
		}

		public override async Task<bool> InstantiateScene(int sceneIndex, ICodeLogger logger = null)
		{
			GameObjectBoundsInstantiator instantiator = (GameObjectBoundsInstantiator)GetDefaultInstantiator(logger);
			bool success = await InstantiateScene(sceneIndex, instantiator);
			base.CurrentSceneId = (success ? new int?(sceneIndex) : null);
			base.SceneInstance = instantiator.SceneInstance;
			if (success)
			{
				SetBounds(instantiator);
			}
			return success;
		}

		protected override IInstantiator GetDefaultInstantiator(ICodeLogger logger)
		{
			return new GameObjectBoundsInstantiator(base.Importer, ((Component)this).transform, logger, base.InstantiationSettings);
		}

		private void SetBounds(GameObjectBoundsInstantiator instantiator)
		{
			//IL_002a: 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_0059: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Bounds? val = ((instantiator.SceneInstance != null) ? instantiator.CalculateBounds() : null);
			if (val.HasValue)
			{
				Bounds = val.Value;
				if (createBoxCollider)
				{
					BoxCollider val2 = ((Component)this).gameObject.AddComponent<BoxCollider>();
					Bounds bounds = Bounds;
					val2.center = ((Bounds)(ref bounds)).center;
					bounds = Bounds;
					val2.size = ((Bounds)(ref bounds)).size;
				}
			}
		}
	}
	internal enum ImageFormat
	{
		Unknown,
		PNG,
		Jpeg,
		Ktx
	}
	internal enum ChunkFormat : uint
	{
		Json = 1313821514u,
		Binary = 5130562u
	}
	public static class GltfGlobals
	{
		public const string GlbExt = ".glb";

		public const string GltfExt = ".gltf";

		public const string GltfPackageName = "com.unity.cloud.gltfast";

		public const uint GltfBinaryMagic = 1179937895u;

		public static bool IsGltfBinary(byte[] data)
		{
			uint num = BitConverter.ToUInt32(data, 0);
			return num == 1179937895;
		}
	}
	public class GltfImport : GltfImportBase<GLTFast.Schema.Root>
	{
		private static GltfJsonUtilityParser s_Parser;

		public GltfImport(IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
			: base(downloadProvider, deferAgent, materialGenerator, logger)
		{
		}

		protected override RootBase ParseJson(string json)
		{
			if (s_Parser == null)
			{
				s_Parser = new GltfJsonUtilityParser();
			}
			return s_Parser.ParseJson(json);
		}
	}
	public abstract class GltfImportBase<TRoot> : GltfImportBase, IGltfReadable<TRoot>, IGltfReadable, IMaterialProvider, IMaterialsVariantsProvider where TRoot : RootBase
	{
		private TRoot m_Root;

		protected override RootBase Root
		{
			get
			{
				return m_Root;
			}
			set
			{
				m_Root = (TRoot)value;
			}
		}

		public GltfImportBase(IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
			: base(downloadProvider, deferAgent, materialGenerator, logger)
		{
		}

		public TRoot GetSourceRoot()
		{
			return m_Root;
		}
	}
	public abstract class GltfImportBase : IGltfReadable, IMaterialProvider, IMaterialsVariantsProvider, IGltfBuffers, IDisposable
	{
		internal const int DefaultBatchCount = 512;

		private const int k_JsonParseSpeed = 80000000;

		private const int k_Base64DecodeSpeed = 150000000;

		private const string k_PrimitiveName = "Primitive";

		private static readonly HashSet<string> k_SupportedExtensions = new HashSet<string> { "KHR_materials_pbrSpecularGlossiness", "KHR_materials_unlit", "KHR_materials_variants", "KHR_texture_transform", "KHR_mesh_quantization", "KHR_materials_transmission", "EXT_mesh_gpu_instancing", "KHR_lights_punctual", "KHR_materials_clearcoat" };

		private static IDeferAgent s_DefaultDeferAgent;

		private static MeshComparer s_MeshComparer = new MeshComparer();

		private IDownloadProvider m_DownloadProvider;

		private IMaterialGenerator m_MaterialGenerator;

		private Dictionary<Type, ImportAddonInstance> m_ImportInstances;

		private ImportSettings m_Settings;

		private byte[][] m_Buffers;

		private GCHandle?[] m_BufferHandles;

		private NativeArray<byte>[] m_NativeBuffers;

		private GlbBinChunk[] m_BinChunks;

		private Dictionary<int, Task<IDownload>> m_DownloadTasks;

		private Dictionary<int, TextureDownloadBase> m_TextureDownloadTasks;

		private IDisposable[] m_AccessorData;

		private AccessorUsage[] m_AccessorUsage;

		private JobHandle m_AccessorJobsHandle;

		private List<MeshOrder> m_MeshOrders;

		private List<ImageCreateContext> m_ImageCreateContexts;

		private Texture2D[] m_Images;

		private Texture2D[] m_Textures;

		private ImageFormat[] m_ImageFormats;

		private bool[] m_ImageReadable;

		private bool[] m_ImageGamma;

		private GlbBinChunk? m_GlbBinChunk;

		private HashSet<int> m_MaterialPointsSupport;

		private bool m_DefaultMaterialPointsSupport;

		private Material[] m_Materials;

		private List<Object> m_Resources;

		private string[] m_NodeNames;

		private List<Mesh> m_Meshes;

		private FlatArray<MeshAssignment> m_MeshAssignments;

		private Matrix4x4[][] m_SkinsInverseBindMatrices;

		private AnimationClip[] m_AnimationClips;

		public ICodeLogger Logger { get; }

		public IDeferAgent DeferAgent { get; }

		protected abstract RootBase Root { get; set; }

		public bool LoadingDone { get; private set; }

		public bool LoadingError { get; private set; }

		public int MaterialCount
		{
			get
			{
				Material[] materials = m_Materials;
				return (materials != null) ? materials.Length : 0;
			}
		}

		public int ImageCount
		{
			get
			{
				Texture2D[] images = m_Images;
				return (images != null) ? images.Length : 0;
			}
		}

		public int TextureCount
		{
			get
			{
				Texture2D[] textures = m_Textures;
				return (textures != null) ? textures.Length : 0;
			}
		}

		public int? DefaultSceneIndex => (Root != null && Root.scene >= 0) ? new int?(Root.scene) : null;

		public int SceneCount => (Root?.Scenes?.Count).GetValueOrDefault();

		public IReadOnlyCollection<Mesh> Meshes => m_Meshes;

		public int MaterialsVariantsCount => Root.MaterialsVariantsCount;

		public event Action LoadAccessorDataEvent;

		public event Action<int, int, int[]> MeshResultAssigned;

		public GltfImportBase(IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			m_DownloadProvider = downloadProvider ?? new DefaultDownloadProvider();
			if (deferAgent == null)
			{
				if (s_DefaultDeferAgent != null)
				{
					IDeferAgent deferAgent2 = s_DefaultDeferAgent;
					Object val = (Object)((deferAgent2 is Object) ? deferAgent2 : null);
					if (val == null || !(val == (Object)null))
					{
						goto IL_006e;
					}
				}
				GameObject val2 = new GameObject("glTF-StableFramerate");
				Object.DontDestroyOnLoad((Object)(object)val2);
				SetDefaultDeferAgent(val2.AddComponent<TimeBudgetPerFrameDeferAgent>());
				val2.AddComponent<DefaultDeferAgent>();
				goto IL_006e;
			}
			DeferAgent = deferAgent;
			goto IL_0085;
			IL_006e:
			DeferAgent = s_DefaultDeferAgent;
			goto IL_0085;
			IL_0085:
			m_MaterialGenerator = materialGenerator ?? MaterialGenerator.GetDefaultMaterialGenerator();
			Logger = logger;
			ImportAddonRegistry.InjectAllAddons(this);
		}

		public static void SetDefaultDeferAgent(IDeferAgent deferAgent)
		{
			if (s_DefaultDeferAgent != null && s_DefaultDeferAgent != deferAgent)
			{
				Debug.LogWarning((object)"GltfImport.defaultDeferAgent got overruled! Make sure there is only one default at any time", (Object)((deferAgent is Object) ? deferAgent : null));
			}
			s_DefaultDeferAgent = deferAgent;
		}

		public static void UnsetDefaultDeferAgent(IDeferAgent deferAgent)
		{
			if (s_DefaultDeferAgent == deferAgent)
			{
				s_DefaultDeferAgent = null;
			}
		}

		public void AddImportAddonInstance<T>(T importInstance) where T : ImportAddonInstance
		{
			if (m_ImportInstances == null)
			{
				m_ImportInstances = new Dictionary<Type, ImportAddonInstance>();
			}
			m_ImportInstances[typeof(T)] = importInstance;
		}

		public T GetImportAddonInstance<T>() where T : ImportAddonInstance
		{
			if (m_ImportInstances == null)
			{
				return null;
			}
			if (m_ImportInstances.TryGetValue(typeof(T), out var value))
			{
				return (T)value;
			}
			return null;
		}

		public async Task<bool> Load(string url, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			return await Load(new Uri(url, UriKind.RelativeOrAbsolute), importSettings, cancellationToken);
		}

		public async Task<bool> Load(Uri url, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			m_Settings = importSettings ?? new ImportSettings();
			return await LoadFromUri(url, cancellationToken);
		}

		public async Task<bool> Load(byte[] data, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (GltfGlobals.IsGltfBinary(data))
			{
				return await LoadGltfBinary(data, uri, importSettings, cancellationToken);
			}
			string json = Encoding.UTF8.GetString(data, 0, data.Length);
			return await LoadGltfJson(json, uri, importSettings, cancellationToken);
		}

		public async Task<bool> LoadFile(string localPath, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			FileStream fs = new FileStream(localPath, FileMode.Open, FileAccess.Read);
			bool result2;
			try
			{
				bool result = await LoadStream(fs, uri, importSettings, cancellationToken);
				fs.Dispose();
				result2 = result;
			}
			finally
			{
				if (fs != null)
				{
					await fs.DisposeAsync();
				}
			}
			return result2;
		}

		public async Task<bool> LoadStream(Stream stream, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (!stream.CanRead)
			{
				Logger?.Error(LogCode.StreamError, "Not readable");
				return false;
			}
			long initialStreamPosition = (stream.CanSeek ? stream.Position : (-1));
			byte[] firstBytes = new byte[4];
			if (!(await stream.ReadToArrayAsync(firstBytes, 0, firstBytes.Length, cancellationToken)))
			{
				Logger?.Error(LogCode.StreamError, "First bytes");
				return false;
			}
			if (cancellationToken.IsCancellationRequested)
			{
				return false;
			}
			if (GltfGlobals.IsGltfBinary(firstBytes))
			{
				byte[] glbHeader = new byte[8];
				if (!(await stream.ReadToArrayAsync(glbHeader, 0, glbHeader.Length, cancellationToken)))
				{
					Logger?.Error(LogCode.StreamError, "glb header");
					return false;
				}
				uint length = BitConverter.ToUInt32(glbHeader, 4);
				if (length >= int.MaxValue)
				{
					Logger?.Error("glb exceeds 2GB limit.");
					return false;
				}
				byte[] data = new byte[length];
				Array.Copy(firstBytes, data, firstBytes.Length);
				Array.Copy(glbHeader, 0, data, firstBytes.Length, glbHeader.Length);
				int offset = firstBytes.Length + glbHeader.Length;
				int pendingBytes = (int)length - offset;
				if (!(await stream.ReadToArrayAsync(data, offset, pendingBytes, cancellationToken)))
				{
					Logger?.Error(LogCode.StreamError, "glb data");
				}
				return await LoadGltfBinary(data, uri, importSettings, cancellationToken);
			}
			StreamReader reader = new StreamReader(stream);
			string json;
			if (stream.CanSeek)
			{
				stream.Seek(initialStreamPosition, SeekOrigin.Begin);
				json = await reader.ReadToEndAsync();
			}
			else
			{
				string @string = Encoding.UTF8.GetString(firstBytes);
				json = @string + await reader.ReadToEndAsync();
			}
			reader.Dispose();
			bool flag = !cancellationToken.IsCancellationRequested;
			bool flag2 = flag;
			if (flag2)
			{
				flag2 = await LoadGltfJson(json, uri, importSettings, cancellationToken);
			}
			return flag2;
		}

		public async Task<bool> LoadGltfBinary(byte[] bytes, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			m_Settings = importSettings ?? new ImportSettings();
			bool success2 = await LoadGltfBinaryBuffer(bytes, uri);
			if (success2)
			{
				await LoadContent();
			}
			bool flag = success2;
			bool flag2 = flag;
			if (flag2)
			{
				flag2 = await Prepare();
			}
			success2 = flag2;
			DisposeVolatileData();
			LoadingError = !success2;
			LoadingDone = true;
			return success2;
		}

		public async Task<bool> LoadGltfJson(string json, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			m_Settings = importSettings ?? new ImportSettings();
			bool success2 = await LoadGltf(json, uri);
			if (success2)
			{
				await LoadContent();
			}
			bool flag = success2;
			bool flag2 = flag;
			if (flag2)
			{
				flag2 = await Prepare();
			}
			success2 = flag2;
			DisposeVolatileData();
			LoadingError = !success2;
			LoadingDone = true;
			return success2;
		}

		[Obsolete("Use InstantiateMainSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
		public bool InstantiateMainScene(Transform parent)
		{
			return InstantiateMainSceneAsync(parent).Result;
		}

		[Obsolete("Use InstantiateMainSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
		public bool InstantiateMainScene(IInstantiator instantiator)
		{
			return InstantiateMainSceneAsync(instantiator).Result;
		}

		[Obsolete("Use InstantiateSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
		public bool InstantiateScene(Transform parent, int sceneIndex = 0)
		{
			return InstantiateSceneAsync(parent, sceneIndex).Result;
		}

		[Obsolete("Use InstantiateSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
		public bool InstantiateScene(IInstantiator instantiator, int sceneIndex = 0)
		{
			return InstantiateSceneAsync(instantiator, sceneIndex).Result;
		}

		public async Task<bool> InstantiateMainSceneAsync(Transform parent, CancellationToken cancellationToken = default(CancellationToken))
		{
			GameObjectInstantiator instantiator = new GameObjectInstantiator(this, parent);
			return await InstantiateMainSceneAsync((IInstantiator)instantiator, cancellationToken);
		}

		public async Task<bool> InstantiateMainSceneAsync(IInstantiator instantiator, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (!LoadingDone || LoadingError)
			{
				return false;
			}
			if (Root.scene < 0)
			{
				Debug.LogWarning((object)"glTF has no (main) scene defined. No scene will be instantiated.");
				return true;
			}
			return await InstantiateSceneAsync(instantiator, Root.scene, cancellationToken);
		}

		public async Task<bool> InstantiateSceneAsync(Transform parent, int sceneIndex = 0, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (!LoadingDone || LoadingError)
			{
				return false;
			}
			if (sceneIndex < 0 || sceneIndex > Root.Scenes.Count)
			{
				return false;
			}
			GameObjectInstantiator instantiator = new GameObjectInstantiator(this, parent);
			return await InstantiateSceneAsync((IInstantiator)instantiator, sceneIndex, cancellationToken);
		}

		public async Task<bool> InstantiateSceneAsync(IInstantiator instantiator, int sceneIndex = 0, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (!LoadingDone || LoadingError)
			{
				return false;
			}
			if (sceneIndex < 0 || sceneIndex > Root.Scenes.Count)
			{
				return false;
			}
			await InstantiateSceneInternal(instantiator, sceneIndex);
			return true;
		}

		public void Dispose()
		{
			if (m_ImportInstances != null)
			{
				foreach (KeyValuePair<Type, ImportAddonInstance> importInstance in m_ImportInstances)
				{
					importInstance.Value.Dispose();
				}
				m_ImportInstances = null;
			}
			m_NodeNames = null;
			DisposeArray((IEnumerable<Object>)(object)m_Materials);
			m_Materials = null;
			DisposeArray((IEnumerable<Object>)(object)m_AnimationClips);
			m_AnimationClips = null;
			DisposeArray((IEnumerable<Object>)(object)m_Textures);
			m_Textures = null;
			if (m_AccessorData != null)
			{
				IDisposable[] accessorData = m_AccessorData;
				for (int i = 0; i < accessorData.Length; i++)
				{
					accessorData[i]?.Dispose();
				}
				m_AccessorData = null;
			}
			m_MeshAssignments = null;
			DisposeArray((IEnumerable<Object>)m_Meshes);
			m_Meshes = null;
			DisposeArray(m_Resources);
			m_Resources = null;
			static void DisposeArray(IEnumerable<Object> objects)
			{
				if (objects != null)
				{
					foreach (Object @object in objects)
					{
						SafeDestroy(@object);
					}
				}
			}
		}

		public string GetSceneName(int sceneIndex)
		{
			return Root?.Scenes?[sceneIndex]?.name;
		}

		public Material GetMaterial(int index = 0)
		{
			if (m_Materials != null && index >= 0 && index < m_Materials.Length)
			{
				return m_Materials[index];
			}
			return null;
		}

		public async Task<Material> GetMaterialAsync(int index)
		{
			return await GetMaterialAsync(index, default(CancellationToken));
		}

		public Task<Material> GetMaterialAsync(int index, CancellationToken cancellationToken)
		{
			return Task.FromResult<Material>(GetMaterial(index));
		}

		public Material GetDefaultMaterial()
		{
			m_MaterialGenerator.SetLogger(Logger);
			Material defaultMaterial = m_MaterialGenerator.GetDefaultMaterial(m_DefaultMaterialPointsSupport);
			m_MaterialGenerator.SetLogger(null);
			return defaultMaterial;
		}

		public async Task<Material> GetDefaultMaterialAsync()
		{
			return await GetDefaultMaterialAsync(default(CancellationToken));
		}

		public Task<Material> GetDefaultMaterialAsync(CancellationToken cancellationToken)
		{
			return Task.FromResult<Material>(GetDefaultMaterial());
		}

		public Texture2D GetImage(int index = 0)
		{
			if (m_Images != null && index >= 0 && index < m_Images.Length)
			{
				return m_Images[index];
			}
			return null;
		}

		public Texture2D GetTexture(int index = 0)
		{
			if (m_Textures != null && index >= 0 && index < m_Textures.Length)
			{
				return m_Textures[index];
			}
			return null;
		}

		public bool IsTextureYFlipped(int index = 0)
		{
			return false;
		}

		public AnimationClip[] GetAnimationClips()
		{
			return m_AnimationClips;
		}

		[Obsolete("Use Meshes instead.")]
		public Mesh[] GetMeshes()
		{
			if (m_Meshes == null || m_Meshes.Count < 1)
			{
				return Array.Empty<Mesh>();
			}
			return m_Meshes.ToArray();
		}

		public int GetMeshCount(int meshIndex)
		{
			return m_MeshAssignments.GetLength(meshIndex);
		}

		public IEnumerable<Mesh> GetMeshes(int meshIndex)
		{
			foreach (MeshAssignment item in m_MeshAssignments.Values(meshIndex))
			{
				yield return item.mesh;
			}
		}

		public Mesh GetMesh(int meshIndex, int meshNumeration)
		{
			return m_MeshAssignments.GetValue(meshIndex, meshNumeration).mesh;
		}

		public CameraBase GetSourceCamera(uint index)
		{
			if (Root?.Cameras != null && index < Root.Cameras.Count)
			{
				return Root.Cameras[(int)index];
			}
			return null;
		}

		public LightPunctual GetSourceLightPunctual(uint index)
		{
			if (Root?.Extensions?.KHR_lights_punctual.lights != null && index < Root.Extensions.KHR_lights_punctual.lights.Length)
			{
				return Root.Extensions.KHR_lights_punctual.lights[index];
			}
			return null;
		}

		public GLTFast.Schema.Scene GetSourceScene(int index = 0)
		{
			if (Root?.Scenes != null && index >= 0 && index < Root.Scenes.Count)
			{
				return Root.Scenes[index];
			}
			return null;
		}

		public MaterialBase GetSourceMaterial(int index = 0)
		{
			if (Root?.Materials != null && index >= 0 && index < Root.Materials.Count)
			{
				return Root.Materials[index];
			}
			return null;
		}

		public MeshBase GetSourceMesh(int meshIndex)
		{
			if (Root?.Meshes != null && meshIndex >= 0 && meshIndex < Root.Meshes.Count)
			{
				return Root.Meshes[meshIndex];
			}
			return null;
		}

		public MeshPrimitiveBase GetSourceMeshPrimitive(int meshIndex, int primitiveIndex)
		{
			if (Root?.Meshes != null && meshIndex >= 0 && meshIndex < Root.Meshes.Count)
			{
				MeshBase meshBase = Root.Meshes[meshIndex];
				if (meshBase?.Primitives != null && primitiveIndex >= 0 && primitiveIndex < meshBase.Primitives.Count)
				{
					return meshBase.Primitives[primitiveIndex];
				}
			}
			return null;
		}

		public IMaterialsVariantsSlot[] GetMaterialsVariantsSlots(int meshIndex, int meshNumeration)
		{
			List<IMaterialsVariantsSlot> list = null;
			int[] primitives = m_MeshAssignments.GetValue(meshIndex, meshNumeration).primitives;
			foreach (int primitiveIndex in primitives)
			{
				MeshPrimitiveBase sourceMeshPrimitive = GetSourceMeshPrimitive(meshIndex, primitiveIndex);
				if (sourceMeshPrimitive.Extensions?.KHR_materials_variants?.mappings != null)
				{
					if (list == null)
					{
						list = new List<IMaterialsVariantsSlot>();
					}
					list.Add(sourceMeshPrimitive);
				}
			}
			return list?.ToArray();
		}

		public NodeBase GetSourceNode(int index = 0)
		{
			if (Root?.Nodes != null && index >= 0 && index < Root.Nodes.Count)
			{
				return Root.Nodes[index];
			}
			return null;
		}

		public TextureBase GetSourceTexture(int index = 0)
		{
			if (Root?.Textures != null && index >= 0 && index < Root.Textures.Count)
			{
				return Root.Textures[index];
			}
			return null;
		}

		public GLTFast.Schema.Image GetSourceImage(int index = 0)
		{
			if (Root?.Images != null && index >= 0 && index < Root.Images.Count)
			{
				return Root.Images[index];
			}
			return null;
		}

		public Matrix4x4[] GetBindPoses(int skinId)
		{
			//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)
			if (m_SkinsInverseBindMatrices == null)
			{
				return null;
			}
			if (m_SkinsInverseBindMatrices[skinId] != null)
			{
				return m_SkinsInverseBindMatrices[skinId];
			}
			GLTFast.Schema.Skin skin = Root.Skins[skinId];
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[skin.joints.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Matrix4x4.identity;
			}
			m_SkinsInverseBindMatrices[skinId] = array;
			return array;
		}

		[Obsolete("Use GetAccessorData instead.")]
		public NativeSlice<byte> GetAccessor(int accessorIndex)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return GetAccessorData(accessorIndex);
		}

		public NativeSlice<byte> GetAccessorData(int accessorIndex)
		{
			//IL_0090: 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_005d: 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_0065: 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)
			if (Root?.Accessors == null || accessorIndex < 0 || accessorIndex >= Root?.Accessors.Count)
			{
				return default(NativeSlice<byte>);
			}
			AccessorBase accessorBase = Root.Accessors[accessorIndex];
			int byteStride;
			return ((IGltfBuffers)this).GetBufferView(accessorBase.bufferView, out byteStride, accessorBase.byteOffset, accessorBase.ByteSize);
		}

		void IGltfBuffers.GetAccessorDataAndByteStride(int index, out NativeSlice<byte> data, out int byteStride)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (Root?.Accessors == null || index < 0 || index >= Root?.Accessors.Count)
			{
				data = default(NativeSlice<byte>);
				byteStride = 0;
			}
			AccessorBase accessorBase = Root.Accessors[index];
			data = ((IGltfBuffers)this).GetBufferView(accessorBase.bufferView, out byteStride, accessorBase.byteOffset, accessorBase.ByteSize);
		}

		public string GetMaterialsVariantName(int index)
		{
			return Root.GetMaterialsVariantName(index);
		}

		private async Task<bool> LoadFromUri(Uri url, CancellationToken cancellationToken)
		{
			IDownload download = await m_DownloadProvider.Request(url);
			bool success = download.Success;
			if (cancellationToken.IsCancellationRequested)
			{
				return true;
			}
			if (success)
			{
				if ((download.IsBinary ?? UriHelper.IsGltfBinary(url)).GetValueOrDefault())
				{
					byte[] data = download.Data;
					download.Dispose();
					success = await LoadGltfBinaryBuffer(data, url);
				}
				else
				{
					string text = download.Text;
					download.Dispose();
					success = await LoadGltf(text, url);
				}
				if (success)
				{
					success = await LoadContent();
				}
				bool flag = success;
				bool flag2 = flag;
				if (flag2)
				{
					flag2 = await Prepare();
				}
				success = flag2;
			}
			else
			{
				Logger?.Error(LogCode.Download, download.Error, url.ToString());
			}
			DisposeVolatileData();
			LoadingError = !success;
			LoadingDone = true;
			return success;
		}

		private async Task<bool> LoadContent()
		{
			bool success = await WaitForBufferDownloads();
			m_DownloadTasks?.Clear();
			if (m_TextureDownloadTasks != null)
			{
				bool flag = success;
				bool flag2 = flag;
				if (flag2)
				{
					flag2 = await WaitForTextureDownloads();
				}
				success = flag2;
				m_TextureDownloadTasks.Clear();
			}
			return success;
		}

		protected abstract RootBase ParseJson(string json);

		private async Task<bool> ParseJsonAndLoadBuffers(string json, Uri baseUri)
		{
			float predictedTime = (float)json.Length / 80000000f;
			if (DeferAgent.ShouldDefer(predictedTime))
			{
				Root = await Task.Run(() => ParseJson(json));
			}
			else
			{
				Root = ParseJson(json);
			}
			if (Root == null)
			{
				Debug.LogError((object)"JsonParsingFailed");
				Logger?.Error(LogCode.JsonParsingFailed);
				return false;
			}
			if (!CheckExtensionSupport())
			{
				return false;
			}
			if (Root.Buffers != null)
			{
				int bufferCount = Root.Buffers.Count;
				if (bufferCount > 0)
				{
					m_Buffers = new byte[bufferCount][];
					m_BufferHandles = new GCHandle?[bufferCount];
					m_NativeBuffers = new NativeArray<byte>[bufferCount];
					m_BinChunks = new GlbBinChunk[bufferCount];
				}
				for (int i = 0; i < bufferCount; i++)
				{
					GLTFast.Schema.Buffer buffer = Root.Buffers[i];
					if (string.IsNullOrEmpty(buffer.uri))
					{
						continue;
					}
					if (buffer.uri.StartsWith("data:"))
					{
						Tuple<byte[], string> decodedBuffer = await DecodeEmbedBufferAsync(buffer.uri, timeCritical: true);
						m_Buffers[i] = decodedBuffer?.Item1;
						if (m_Buffers[i] == null)
						{
							Logger?.Error(LogCode.EmbedBufferLoadFailed);
							return false;
						}
					}
					else
					{
						LoadBuffer(i, UriHelper.GetUriString(buffer.uri, baseUri));
					}
				}
			}
			return true;
		}

		private bool CheckExtensionSupport()
		{
			if (!CheckExtensionSupport(Root.extensionsRequired))
			{
				return false;
			}
			CheckExtensionSupport(Root.extensionsUsed, required: false);
			return true;
		}

		private bool CheckExtensionSupport(IEnumerable<string> extensions, bool required = true)
		{
			if (extensions == null)
			{
				return true;
			}
			bool result = true;
			foreach (string extension in extensions)
			{
				bool flag = k_SupportedExtensions.Contains(extension);
				if (!flag && m_ImportInstances != null)
				{
					foreach (KeyValuePair<Type, ImportAddonInstance> importInstance in m_ImportInstances)
					{
						if (importInstance.Value.SupportsGltfExtension(extension))
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					continue;
				}
				switch (extension)
				{
				case "KHR_draco_mesh_compression":
					Logger?.Log((LogType)((!required) ? 2 : 0), LogCode.PackageMissing, "Draco for Unity", extension);
					break;
				case "EXT_meshopt_compression":
					Logger?.Log((LogType)((!required) ? 2 : 0), LogCode.PackageMissing, "meshoptimizer decompression for Unity", extension);
					break;
				case "KHR_texture_basisu":
					Logger?.Log((LogType)((!required) ? 2 : 0), LogCode.PackageMissing, "KTX for Unity", extension);
					break;
				default:
					if (required)
					{
						Logger?.Error(LogCode.ExtensionUnsupported, extension);
					}
					else
					{
						Logger?.Warning(LogCode.ExtensionUnsupported, extension);
					}
					break;
				}
				result = false;
			}
			return result;
		}

		private async Task<bool> LoadGltf(string json, Uri url)
		{
			Uri baseUri = UriHelper.GetBaseUri(url);
			bool success = await ParseJsonAndLoadBuffers(json, baseUri);
			if (success)
			{
				await LoadImages(baseUri);
			}
			return success;
		}

		private async Task LoadImages(Uri baseUri)
		{
			if (Root.Textures == null || Root.Images == null)
			{
				return;
			}
			m_Images = (Texture2D[])(object)new Texture2D[Root.Images.Count];
			m_ImageFormats = new ImageFormat[Root.Images.Count];
			if ((int)QualitySettings.activeColorSpace == 1)
			{
				m_ImageGamma = new bool[Root.Images.Count];
				if (Root.Materials != null)
				{
					for (int i = 0; i < Root.Materials.Count; i++)
					{
						MaterialBase mat = Root.Materials[i];
						if (mat.PbrMetallicRoughness != null)
						{
							SetImageGamma(mat.PbrMetallicRoughness.BaseColorTexture);
						}
						SetImageGamma(mat.EmissiveTexture);
						if (mat.Extensions?.KHR_materials_pbrSpecularGlossiness != null)
						{
							SetImageGamma(mat.Extensions.KHR_materials_pbrSpecularGlossiness.diffuseTexture);
							SetImageGamma(mat.Extensions.KHR_materials_pbrSpecularGlossiness.specularGlossinessTexture);
						}
					}
				}
			}
			HashSet<int>[] imageVariants = new HashSet<int>[m_Images.Length];
			foreach (TextureBase txt in Root.Textures)
			{
				int imageIndex = txt.GetImageIndex();
				if (imageIndex >= 0 && imageIndex < Root.Images.Count)
				{
					if (imageVariants[imageIndex] == null)
					{
						imageVariants[imageIndex] = new HashSet<int>();
					}
					imageVariants[imageIndex].Add(txt.sampler);
				}
			}
			if (!m_Settings.TexturesReadable)
			{
				m_ImageReadable = new bool[m_Images.Length];
				for (int j = 0; j < m_Images.Length; j++)
				{
					m_ImageReadable[j] = imageVariants[j] != null && imageVariants[j].Count > 1;
				}
			}
			List<Task> imageTasks = null;
			for (int imageIndex2 = 0; imageIndex2 < Root.Images.Count; imageIndex2++)
			{
				GLTFast.Schema.Image img = Root.Images[imageIndex2];
				if (!string.IsNullOrEmpty(img.uri) && img.uri.StartsWith("data:"))
				{
					Task<Tuple<byte[], string>> decodedBufferTask = DecodeEmbedBufferAsync(img.uri);
					if (imageTasks == null)
					{
						imageTasks = new List<Task>();
					}
					Task imageTask = LoadImageFromBuffer(decodedBufferTask, imageIndex2, img);
					imageTasks.Add(imageTask);
					continue;
				}
				ImageFormat imgFormat;
				if (m_ImageFormats[imageIndex2] == ImageFormat.Unknown)
				{
					imgFormat = (string.IsNullOrEmpty(img.mimeType) ? UriHelper.GetImageFormatFromUri(img.uri) : GetImageFormatFromMimeType(img.mimeType));
					m_ImageFormats[imageIndex2] = imgFormat;
				}
				else
				{
					imgFormat = m_ImageFormats[imageIndex2];
				}
				if (imgFormat != 0)
				{
					if (img.bufferView < 0)
					{
						if (!string.IsNullOrEmpty(img.uri))
						{
							LoadImage(imageIndex2, UriHelper.GetUriString(img.uri, baseUri), !m_Settings.TexturesReadable && !m_ImageReadable[imageIndex2], imgFormat == ImageFormat.Ktx);
						}
						else
						{
							Logger?.Error(LogCode.MissingImageURL);
						}
					}
				}
				else
				{
					Logger?.Error(LogCode.ImageFormatUnknown, imageIndex2.ToString(), img.uri);
				}
			}
			if (imageTasks != null)
			{
				await Task.WhenAll(imageTasks);
			}
			void SetImageGamma(TextureInfoBase txtInfo)
			{
				if (txtInfo != null && txtInfo.index >= 0 && txtInfo.index < Root.Textures.Count)
				{
					int imageIndex3 = Root.Textures[txtInfo.index].GetImageIndex();
					m_ImageGamma[imageIndex3] = true;
				}
			}
		}

		private async Task LoadImageFromBuffer(Task<Tuple<byte[], string>> decodeBufferTask, int imageIndex, GLTFast.Schema.Image img)
		{
			Tuple<byte[], string> decodedBuffer = await decodeBufferTask;
			await DeferAgent.BreakPoint();
			byte[] data = decodedBuffer.Item1;
			string mimeType = decodedBuffer.Item2;
			ImageFormat imgFormat = GetImageFormatFromMimeType(mimeType);
			if (data == null || imgFormat == ImageFormat.Unknown)
			{
				Logger?.Error(LogCode.EmbedImageLoadFailed);
				return;
			}
			if (m_ImageFormats[imageIndex] != 0 && m_ImageFormats[imageIndex] != imgFormat)
			{
				Logger?.Error(LogCode.EmbedImageInconsistentType, m_ImageFormats[imageIndex].ToString(), imgFormat.ToString());
			}
			m_ImageFormats[imageIndex] = imgFormat;
			if (m_ImageFormats[imageIndex] != ImageFormat.Jpeg && m_ImageFormats[imageIndex] != ImageFormat.PNG)
			{
				Logger?.Error(LogCode.EmbedImageUnsupportedType, m_ImageFormats[imageIndex].ToString());
			}
			bool forceSampleLinear = m_ImageGamma != null && !m_ImageGamma[imageIndex];
			Texture2D txt = CreateEmptyTexture(img, imageIndex, forceSampleLinear);
			ImageConversion.LoadImage(txt, data, !m_Settings.TexturesReadable && !m_ImageReadable[imageIndex]);
			m_Images[imageIndex] = txt;
		}

		private async Task<bool> WaitForBufferDownloads()
		{
			if (m_DownloadTasks != null)
			{
				foreach (KeyValuePair<int, Task<IDownload>> downloadPair in 

Marioalexsan.AtlyssGLTF.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using GLTFast;
using GLTFast.Export;
using GLTFast.Loading;
using GLTFast.Logging;
using GLTFast.Materials;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Burst;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("com.unity.cloud.gltfast")]
[assembly: IgnoresAccessChecksTo("UnityEngine.CoreModule")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Marioalexsan.AtlyssGLTF")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("AtlyssGLTF")]
[assembly: AssemblyTitle("Marioalexsan.AtlyssGLTF")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Marioalexsan.AtlyssGLTF
{
	[HarmonyPatch(typeof(ChatBehaviour), "Send_ChatMessage")]
	internal static class ChatCommands
	{
		private static bool Prefix(string _message, ChatBehaviour __instance)
		{
			if (string.IsNullOrEmpty(_message))
			{
				return true;
			}
			string[] array = _message.Split(" ", StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 0 || array[0] != "/gltf")
			{
				return true;
			}
			if (array.Length < 2)
			{
				HostConsole._current.Init_NetworkStatusMessage("Usage: /gltf <command> <params...>");
				return false;
			}
			switch (array[1])
			{
			case "force_readable_meshes":
				if (array.Length != 2)
				{
					HostConsole._current.Init_NetworkStatusMessage("Usage: /gltf force_readable_meshes");
					return false;
				}
				AtlyssGLTF.ForceReadableMeshes = !AtlyssGLTF.ForceReadableMeshes;
				HostConsole._current.Init_NetworkStatusMessage("Forced readable meshes is now " + (AtlyssGLTF.ForceReadableMeshes ? "on" : "off") + ".");
				return false;
			case "import":
				if (array.Length != 4)
				{
					HostConsole._current.Init_NetworkStatusMessage("Usage: /gltf import <obj_name> <path>");
					return false;
				}
				AtlyssGLTF.GLTFImportQueue.Enqueue((array[2], Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)AtlyssGLTF.Plugin).Info.Location), array[3])));
				return false;
			case "export":
				if (array.Length != 4)
				{
					HostConsole._current.Init_NetworkStatusMessage("Usage: /gltf export <obj_name> <path>");
					return false;
				}
				AtlyssGLTF.GLTFExportQueue.Enqueue((array[2], Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)AtlyssGLTF.Plugin).Info.Location), array[3])));
				return false;
			default:
				HostConsole._current.Init_NetworkStatusMessage("That command does not exist.");
				return false;
			}
		}
	}
	[BepInPlugin("Marioalexsan.AtlyssGLTF", "AtlyssGLTF", "0.1.0")]
	public class AtlyssGLTF : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static AtlyssGLTF Plugin { get; private set; }

		public static AssetBundle Bundle { get; private set; }

		public static Shader PBRMetallicRoughness { get; private set; }

		public static Shader PBRSpecularGlossiness { get; private set; }

		public static Shader Unlit { get; private set; }

		public static Shader ExportColor { get; private set; }

		public static Shader ExportMaskmap { get; private set; }

		public static Shader ExportMetalGloss { get; private set; }

		public static Shader ExportNormal { get; private set; }

		public static Shader ExportOcclusion { get; private set; }

		public static Shader ExportSmoothness { get; private set; }

		public static bool ForceReadableMeshes { get; internal set; } = false;


		internal static ManualLogSource Logger { get; private set; }

		internal static Queue<(string ObjectName, string Path)> GLTFImportQueue { get; } = new Queue<(string, string)>();


		internal static Queue<(string ObjectName, string Path)> GLTFExportQueue { get; } = new Queue<(string, string)>();


		private void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Plugin = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("AtlyssGLTF");
			_harmony.PatchAll();
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "gltf");
			Bundle = AssetBundle.LoadFromFile(text);
			if (Object.op_Implicit((Object)(object)Bundle))
			{
				PBRMetallicRoughness = LoadShader("assets/atlyss/shader/gltf/built-in/gltfpbrmetallicroughness.shader");
				PBRSpecularGlossiness = LoadShader("assets/atlyss/shader/gltf/built-in/gltfpbrspecularglossiness.shader");
				Unlit = LoadShader("assets/atlyss/shader/gltf/built-in/gltfunlit.shader");
				ExportColor = LoadShader("assets/atlyss/shader/gltf/export/gltfexportcolor.shader");
				ExportMaskmap = LoadShader("assets/atlyss/shader/gltf/export/gltfexportmaskmap.shader");
				ExportMetalGloss = LoadShader("assets/atlyss/shader/gltf/export/gltfexportmetalgloss.shader");
				ExportNormal = LoadShader("assets/atlyss/shader/gltf/export/gltfexportnormal.shader");
				ExportOcclusion = LoadShader("assets/atlyss/shader/gltf/export/gltfexportocclusion.shader");
				ExportSmoothness = LoadShader("assets/atlyss/shader/gltf/export/gltfexportsmoothness.shader");
				Logger.LogInfo((object)"Asset bundle items:");
				string[] allAssetNames = Bundle.GetAllAssetNames();
				foreach (string text2 in allAssetNames)
				{
					Logger.LogInfo((object)(" - " + text2));
				}
			}
			else
			{
				Logger.LogWarning((object)("Unable to load glTF shader bundle from " + text + "."));
			}
			Logger.LogInfo((object)"Initialized!");
			static Shader LoadShader(string path)
			{
				Shader val = Bundle.LoadAsset<Shader>(path);
				if (!Object.op_Implicit((Object)(object)val))
				{
					Logger.LogWarning((object)("glTF shader load failed: " + path + "."));
				}
				return val;
			}
		}

		public async Task Update()
		{
			if (GLTFImportQueue.Count > 0)
			{
				(string ObjectName, string Path) data2 = GLTFImportQueue.Dequeue();
				await ImportGLTFScene(data2.ObjectName, data2.Path);
			}
			if (GLTFExportQueue.Count > 0)
			{
				(string ObjectName, string Path) data = GLTFExportQueue.Dequeue();
				await ExportGLTFScene(data.ObjectName, data.Path);
			}
		}

		private async Task<GameObject> ImportGLTFScene(string objectName, string path)
		{
			try
			{
				GltfImport gltf = new GltfImport((IDownloadProvider)null, (IDeferAgent)null, (IMaterialGenerator)null, (ICodeLogger)null);
				await ((GltfImportBase)gltf).Load(new Uri(path), new ImportSettings
				{
					AnimationMethod = (AnimationMethod)2
				}, default(CancellationToken));
				GameObject gameObject = new GameObject(objectName);
				await ((GltfImportBase)gltf).InstantiateMainSceneAsync(gameObject.transform, default(CancellationToken));
				HostConsole._current.Init_NetworkStatusMessage("Imported glTF.");
				return gameObject;
			}
			catch (Exception ex)
			{
				Exception e = ex;
				HostConsole._current.Init_NetworkStatusMessage("Import failed! Check the console.");
				Logger.LogError((object)e);
				return null;
			}
		}

		private async Task ExportGLTFScene(string objectName, string path)
		{
			try
			{
				GameObject gameObject = GameObject.Find(objectName);
				if (!Object.op_Implicit((Object)(object)gameObject))
				{
					HostConsole._current.Init_NetworkStatusMessage("Object not found.");
					return;
				}
				GameObjectExport export = new GameObjectExport(new ExportSettings
				{
					Deterministic = true,
					Format = (GltfFormat)1
				}, (GameObjectExportSettings)null, (IMaterialExport)null, (IDeferAgent)null, (ICodeLogger)null);
				export.AddScene((GameObject[])(object)new GameObject[1] { gameObject }, (string)null);
				if (!(await export.SaveToFileAndDispose(path, default(CancellationToken))))
				{
					HostConsole._current.Init_NetworkStatusMessage("Something went wrong while exporting the glTF!");
				}
				HostConsole._current.Init_NetworkStatusMessage("Exported glTF!");
			}
			catch (Exception ex)
			{
				Exception e = ex;
				HostConsole._current.Init_NetworkStatusMessage("Export failed! Check the console.");
				Logger.LogError((object)e);
			}
		}
	}
	internal static class ModInfo
	{
		public const string PLUGIN_GUID = "Marioalexsan.AtlyssGLTF";

		public const string PLUGIN_NAME = "AtlyssGLTF";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace Marioalexsan.AtlyssGLTF.HarmonyPatches
{
	internal static class BurstManager
	{
		public static void Initialize()
		{
		}
	}
	[HarmonyPatch(typeof(BurstCompiler), "Compile", new Type[]
	{
		typeof(object),
		typeof(bool)
	})]
	internal static class BurstRemove
	{
		private unsafe static bool Prefix(object delegateObj, out void* __result)
		{
			if (delegateObj.GetType().Assembly == typeof(GltfAsset).Assembly)
			{
				__result = (void*)Marshal.GetFunctionPointerForDelegate(delegateObj);
				return false;
			}
			__result = null;
			return true;
		}
	}
	[HarmonyPatch(typeof(GltfWriter), "AddMesh")]
	internal static class GltfWriter_AddMesh
	{
		private static void Prefix(ref Mesh uMesh, ref VertexAttributeUsage attributeUsage)
		{
			if (!uMesh.isReadable)
			{
				uMesh = MakeReadableMeshCopy(uMesh);
			}
		}

		public static Mesh MakeReadableMeshCopy(Mesh nonReadableMesh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0020: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			((Object)val).name = ((Object)nonReadableMesh).name + "_copy";
			val.indexFormat = nonReadableMesh.indexFormat;
			CopyVertexBuffers(val, nonReadableMesh);
			val.subMeshCount = nonReadableMesh.subMeshCount;
			GraphicsBuffer indexBuffer = nonReadableMesh.GetIndexBuffer();
			int num = indexBuffer.stride * indexBuffer.count;
			byte[] array = new byte[num];
			indexBuffer.GetData((Array)array);
			val.SetIndexBufferParams(indexBuffer.count, nonReadableMesh.indexFormat);
			val.SetIndexBufferData<byte>(array, 0, 0, num, (MeshUpdateFlags)0);
			indexBuffer.Release();
			uint num2 = 0u;
			for (int i = 0; i < val.subMeshCount; i++)
			{
				uint indexCount = nonReadableMesh.GetIndexCount(i);
				val.SetSubMesh(i, new SubMeshDescriptor((int)num2, (int)indexCount, (MeshTopology)0), (MeshUpdateFlags)0);
				num2 += indexCount;
			}
			CopyBlendShapes(val, nonReadableMesh);
			val.RecalculateNormals();
			val.RecalculateBounds();
			val.boneWeights = nonReadableMesh.boneWeights;
			val.bindposes = nonReadableMesh.bindposes;
			return val;
		}

		private static void CopyBlendShapes(Mesh targetMesh, Mesh sourceMesh)
		{
			try
			{
				for (int i = 0; i < sourceMesh.blendShapeCount; i++)
				{
					string blendShapeName = sourceMesh.GetBlendShapeName(i);
					int blendShapeFrameCount = sourceMesh.GetBlendShapeFrameCount(i);
					for (int j = 0; j < blendShapeFrameCount; j++)
					{
						float blendShapeFrameWeight = sourceMesh.GetBlendShapeFrameWeight(i, j);
						Vector3[] array = (Vector3[])(object)new Vector3[sourceMesh.vertexCount];
						Vector3[] array2 = (Vector3[])(object)new Vector3[sourceMesh.vertexCount];
						Vector3[] array3 = (Vector3[])(object)new Vector3[sourceMesh.vertexCount];
						sourceMesh.GetBlendShapeFrameVertices(i, j, array, array2, array3);
						targetMesh.AddBlendShapeFrame(blendShapeName, blendShapeFrameWeight, array, array2, array3);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogException(ex);
			}
		}

		private static void CopyVertexBuffers(Mesh targetMesh, Mesh sourceMesh)
		{
			for (int i = 0; i < sourceMesh.vertexBufferCount; i++)
			{
				GraphicsBuffer vertexBuffer = sourceMesh.GetVertexBuffer(i);
				int num = vertexBuffer.stride * vertexBuffer.count;
				byte[] array = new byte[num];
				vertexBuffer.GetData((Array)array);
				targetMesh.SetVertexBufferParams(sourceMesh.vertexCount, sourceMesh.GetVertexAttributes());
				targetMesh.SetVertexBufferData<byte>(array, 0, 0, num, i, (MeshUpdateFlags)0);
				vertexBuffer.Release();
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class ReadableMesh
	{
		private static bool Prefix(ref bool __result)
		{
			if (!AtlyssGLTF.ForceReadableMeshes)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(ImageExport), "LoadBlitMaterial")]
	internal static class ImageExport_LoadBlitMaterial
	{
		private static bool Prefix(ref string shaderName, ref Material __result)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			string text = shaderName;
			if (1 == 0)
			{
			}
			Shader val = (Shader)(text switch
			{
				"glTFExportColor" => AtlyssGLTF.ExportColor, 
				"glTFExportNormal" => AtlyssGLTF.ExportNormal, 
				"glTFExportMetalGloss" => AtlyssGLTF.ExportMetalGloss, 
				"glTFExportOcclusion" => AtlyssGLTF.ExportOcclusion, 
				"glTFExportSmoothness" => AtlyssGLTF.ExportSmoothness, 
				_ => null, 
			});
			if (1 == 0)
			{
			}
			Shader val2 = val;
			if ((Object)(object)val2 == (Object)null)
			{
				return true;
			}
			__result = new Material(val2);
			return false;
		}
	}
	[HarmonyPatch(typeof(BuiltInMaterialGenerator), "FinderShaderMetallicRoughness")]
	internal static class FinderShaderMetallicRoughnessPatch
	{
		private static bool Prefix(BuiltInMaterialGenerator __instance, ref Shader __result)
		{
			__result = AtlyssGLTF.PBRMetallicRoughness;
			return false;
		}
	}
	[HarmonyPatch(typeof(BuiltInMaterialGenerator), "FinderShaderSpecularGlossiness")]
	internal static class FinderShaderSpecularGlossinessPatch
	{
		private static bool Prefix(BuiltInMaterialGenerator __instance, ref Shader __result)
		{
			__result = AtlyssGLTF.PBRSpecularGlossiness;
			return false;
		}
	}
	[HarmonyPatch(typeof(BuiltInMaterialGenerator), "FinderShaderUnlit")]
	internal static class FinderShaderUnlitPatch
	{
		private static bool Prefix(BuiltInMaterialGenerator __instance, ref Shader __result)
		{
			__result = AtlyssGLTF.Unlit;
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

Unity.Collections.LowLevel.ILSupport.dll

Decompiled a month ago
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Unity.Collections")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Never)]
[GeneratedCode("Unity.MonoScriptGenerator.MonoScriptInfoGenerator", null)]
internal class UnitySourceGeneratedAssemblyMonoScriptTypes_v1
{
	private struct MonoScriptData
	{
		public byte[] FilePathsData;

		public byte[] TypesData;

		public int TotalTypes;

		public int TotalFiles;

		public bool IsEditorOnly;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private static MonoScriptData Get()
	{
		MonoScriptData result = default(MonoScriptData);
		result.FilePathsData = new byte[144]
		{
			0, 0, 0, 1, 0, 0, 0, 136, 67, 58,
			92, 100, 101, 118, 92, 100, 111, 116, 115, 92,
			80, 97, 99, 107, 97, 103, 101, 115, 92, 99,
			111, 109, 46, 117, 110, 105, 116, 121, 46, 99,
			111, 108, 108, 101, 99, 116, 105, 111, 110, 115,
			92, 85, 110, 105, 116, 121, 46, 67, 111, 108,
			108, 101, 99, 116, 105, 111, 110, 115, 46, 76,
			111, 119, 76, 101, 118, 101, 108, 46, 73, 76,
			83, 117, 112, 112, 111, 114, 116, 92, 115, 111,
			117, 114, 99, 101, 92, 85, 110, 105, 116, 121,
			46, 67, 111, 108, 108, 101, 99, 116, 105, 111,
			110, 115, 46, 76, 111, 119, 76, 101, 118, 101,
			108, 46, 73, 76, 83, 117, 112, 112, 111, 114,
			116, 92, 73, 76, 83, 117, 112, 112, 111, 114,
			116, 46, 99, 115
		};
		result.TypesData = new byte[48]
		{
			0, 0, 0, 0, 43, 85, 110, 105, 116, 121,
			46, 67, 111, 108, 108, 101, 99, 116, 105, 111,
			110, 115, 46, 76, 111, 119, 76, 101, 118, 101,
			108, 46, 85, 110, 115, 97, 102, 101, 124, 73,
			76, 83, 117, 112, 112, 111, 114, 116
		};
		result.TotalFiles = 1;
		result.TotalTypes = 1;
		result.IsEditorOnly = false;
		return result;
	}
}
namespace Unity.Collections.LowLevel.Unsafe;

internal static class ILSupport
{
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public unsafe static void* AddressOf<T>(in T thing) where T : struct
	{
		return System.Runtime.CompilerServices.Unsafe.AsPointer(ref thing);
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public static ref T AsRef<T>(in T thing) where T : struct
	{
		return ref thing;
	}
}