Decompiled source of Tripod Invasion v1.0.2

Mods/Tripod invasion.dll

Decompiled 42 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.SDK.Modules;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Tripod_invasion;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Tripod Invasion", "1.0.0", "jenni", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Tripod invasion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Tripod invasion")]
[assembly: AssemblyTitle("Tripod invasion")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace Tripod_invasion
{
	public enum AircraftKind
	{
		F22,
		A10,
		B2,
		AH60,
		UH60,
		B52
	}
	public static class AssetLoader
	{
		private class ParsedObj
		{
			public List<Vector3> Vertices = new List<Vector3>();

			public List<Vector2> UVs = new List<Vector2>();

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

			public List<int> Triangles = new List<int>();

			public bool HasUVs;

			public bool HasNormals;

			public string MtlLib;

			public List<string> MatNames = new List<string>();

			public List<List<int>> SubTris = new List<List<int>>();

			public int CurrentSub = -1;

			public void UseMaterial(string name)
			{
				int num = MatNames.IndexOf(name);
				if (num < 0)
				{
					MatNames.Add(name);
					SubTris.Add(new List<int>());
					num = MatNames.Count - 1;
				}
				CurrentSub = num;
			}
		}

		private class ObjMaterialInfo
		{
			public string ObjPath;

			public string MtlLib;

			public string BaseName;

			public List<string> MatNames;
		}

		private class MtlEntry
		{
			public string MapKd;

			public Color Kd = Color.white;

			public bool HasKd;
		}

		private class MeshBuilder
		{
			private readonly List<Vector3> _v = new List<Vector3>();

			private readonly List<Vector2> _uv = new List<Vector2>();

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

			private void AddTri(int a, int b, int c, Vector3 outward)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				if (Vector3.Dot(Vector3.Cross(_v[b] - _v[a], _v[c] - _v[a]), outward) > 0f)
				{
					int num = b;
					b = c;
					c = num;
				}
				_t.Add(a);
				_t.Add(b);
				_t.Add(c);
			}

			private void AddQuad(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 outward)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				int count = _v.Count;
				_v.Add(p0);
				_uv.Add(new Vector2(0f, 0f));
				_v.Add(p1);
				_uv.Add(new Vector2(1f, 0f));
				_v.Add(p2);
				_uv.Add(new Vector2(1f, 1f));
				_v.Add(p3);
				_uv.Add(new Vector2(0f, 1f));
				AddTri(count, count + 1, count + 2, outward);
				AddTri(count, count + 2, count + 3, outward);
			}

			public void AddBox(Vector3 center, Vector3 size)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				AddTaperedBox(center, size, Vector2.one, Vector2.one);
			}

			public void AddTaperedBox(Vector3 center, Vector3 size, Vector2 rearScale, Vector2 frontScale)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: 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_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: 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_011a: 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_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: 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)
				//IL_0061: 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_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = size * 0.5f;
				Vector3[] array = (Vector3[])(object)new Vector3[8];
				for (int i = 0; i < 8; i++)
				{
					float num = (((i & 1) == 0) ? (-1f) : 1f);
					float num2 = (((i & 2) == 0) ? (-1f) : 1f);
					float num3 = (((i & 4) == 0) ? (-1f) : 1f);
					Vector2 val2 = ((num3 < 0f) ? rearScale : frontScale);
					array[i] = center + new Vector3(num * val.x * val2.x, num2 * val.y * val2.y, num3 * val.z);
				}
				int[,] array2 = new int[6, 4]
				{
					{ 0, 2, 3, 1 },
					{ 4, 5, 7, 6 },
					{ 0, 4, 6, 2 },
					{ 1, 3, 7, 5 },
					{ 0, 1, 5, 4 },
					{ 2, 6, 7, 3 }
				};
				for (int j = 0; j < 6; j++)
				{
					Vector3 val3 = array[array2[j, 0]];
					Vector3 val4 = array[array2[j, 1]];
					Vector3 val5 = array[array2[j, 2]];
					Vector3 val6 = array[array2[j, 3]];
					Vector3 val7 = (val3 + val4 + val5 + val6) * 0.25f;
					AddQuad(val3, val4, val5, val6, val7 - center);
				}
			}

			public void AddCylinder(Vector3 center, float radius, float length, int axis, int segments)
			{
				//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_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: 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_0052: 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_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: 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_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: 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_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0210: 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_0225: Unknown result type (might be due to invalid IL or missing references)
				//IL_022a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0244: Unknown result type (might be due to invalid IL or missing references)
				//IL_0254: Unknown result type (might be due to invalid IL or missing references)
				//IL_0256: Unknown result type (might be due to invalid IL or missing references)
				//IL_0259: Unknown result type (might be due to invalid IL or missing references)
				//IL_025e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_028d: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = (Vector3)(axis switch
				{
					1 => Vector3.up, 
					0 => Vector3.right, 
					_ => Vector3.forward, 
				});
				Vector3 val2 = ((axis == 1) ? Vector3.right : Vector3.up);
				Vector3 val3 = Vector3.Cross(val, val2);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				val3 = Vector3.Cross(normalized, val);
				val2 = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = center - val * (length * 0.5f);
				Vector3 val5 = center + val * (length * 0.5f);
				for (int i = 0; i < segments; i++)
				{
					float num = (float)Math.PI * 2f * (float)i / (float)segments;
					float num2 = (float)Math.PI * 2f * (float)(i + 1) / (float)segments;
					Vector3 val6 = val2 * Mathf.Cos(num) + normalized * Mathf.Sin(num);
					Vector3 val7 = val2 * Mathf.Cos(num2) + normalized * Mathf.Sin(num2);
					AddQuad(val4 + val6 * radius, val4 + val7 * radius, val5 + val7 * radius, val5 + val6 * radius, (val6 + val7) * 0.5f);
					int count = _v.Count;
					_v.Add(val4);
					_uv.Add(new Vector2(0.5f, 0.5f));
					_v.Add(val4 + val6 * radius);
					_uv.Add(new Vector2(0f, 0f));
					_v.Add(val4 + val7 * radius);
					_uv.Add(new Vector2(1f, 0f));
					AddTri(count, count + 1, count + 2, -val);
					count = _v.Count;
					_v.Add(val5);
					_uv.Add(new Vector2(0.5f, 0.5f));
					_v.Add(val5 + val6 * radius);
					_uv.Add(new Vector2(0f, 0f));
					_v.Add(val5 + val7 * radius);
					_uv.Add(new Vector2(1f, 0f));
					AddTri(count, count + 1, count + 2, val);
				}
			}

			public void AddEllipsoid(Vector3 center, Vector3 radii, int slices, int stacks)
			{
				//IL_006f: 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_0077: 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_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: 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_0135: Unknown result type (might be due to invalid IL or missing references)
				int count = _v.Count;
				Vector3 val = default(Vector3);
				for (int i = 0; i <= stacks; i++)
				{
					float num = (float)i / (float)stacks;
					float num2 = (float)Math.PI * num;
					for (int j = 0; j <= slices; j++)
					{
						float num3 = (float)j / (float)slices;
						float num4 = (float)Math.PI * 2f * num3;
						((Vector3)(ref val))..ctor(Mathf.Sin(num2) * Mathf.Cos(num4), Mathf.Cos(num2), Mathf.Sin(num2) * Mathf.Sin(num4));
						_v.Add(center + new Vector3(val.x * radii.x, val.y * radii.y, val.z * radii.z));
						_uv.Add(new Vector2(num3, num));
					}
				}
				int num5 = slices + 1;
				for (int k = 0; k < stacks; k++)
				{
					for (int l = 0; l < slices; l++)
					{
						int num6 = count + k * num5 + l;
						int num7 = num6 + 1;
						int num8 = num6 + num5;
						int c = num8 + 1;
						AddTri(num6, num8, num7, _v[num6] - center);
						AddTri(num7, num8, c, _v[num7] - center);
					}
				}
			}

			public void AddPrism(Vector2[] outline, float yBottom, float yTop)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: Unknown result type (might be due to invalid IL or missing references)
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0140: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: 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)
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0205: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: 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_022c: Unknown result type (might be due to invalid IL or missing references)
				//IL_023c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0253: Unknown result type (might be due to invalid IL or missing references)
				//IL_0263: Unknown result type (might be due to invalid IL or missing references)
				//IL_027a: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Unknown result type (might be due to invalid IL or missing references)
				int num = outline.Length;
				Vector2 val = Vector2.zero;
				for (int i = 0; i < num; i++)
				{
					val += outline[i];
				}
				val /= (float)num;
				float num2 = 0f;
				for (int j = 0; j < num; j++)
				{
					Vector2 val2 = outline[j];
					Vector2 val3 = outline[(j + 1) % num];
					num2 += val2.x * val3.y - val3.x * val2.y;
				}
				float num3 = ((num2 >= 0f) ? 1f : (-1f));
				Vector3 val6 = default(Vector3);
				Vector3 val7 = default(Vector3);
				Vector3 val8 = default(Vector3);
				Vector3 val9 = default(Vector3);
				for (int k = 0; k < num; k++)
				{
					Vector2 val4 = outline[k];
					Vector2 val5 = outline[(k + 1) % num];
					((Vector3)(ref val6))..ctor(val4.x, yBottom, val4.y);
					((Vector3)(ref val7))..ctor(val5.x, yBottom, val5.y);
					((Vector3)(ref val8))..ctor(val4.x, yTop, val4.y);
					((Vector3)(ref val9))..ctor(val5.x, yTop, val5.y);
					Vector2 val10 = val5 - val4;
					Vector3 outward = new Vector3(val10.y, 0f, 0f - val10.x) * num3;
					AddQuad(val6, val7, val9, val8, outward);
					int count = _v.Count;
					_v.Add(new Vector3(val.x, yTop, val.y));
					_uv.Add(new Vector2(0.5f, 0.5f));
					_v.Add(val8);
					_uv.Add(new Vector2(0f, 0f));
					_v.Add(val9);
					_uv.Add(new Vector2(1f, 0f));
					AddTri(count, count + 1, count + 2, Vector3.up);
					int count2 = _v.Count;
					_v.Add(new Vector3(val.x, yBottom, val.y));
					_uv.Add(new Vector2(0.5f, 0.5f));
					_v.Add(val6);
					_uv.Add(new Vector2(0f, 0f));
					_v.Add(val7);
					_uv.Add(new Vector2(1f, 0f));
					AddTri(count2, count2 + 1, count2 + 2, Vector3.down);
				}
			}

			public Mesh ToMesh(string name, float target, bool groundPivot, bool scaleByZLength)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: 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_0083: Expected O, but got Unknown
				List<Vector3> list = new List<Vector3>(_v);
				NormalizeVertices(list, target, groundPivot, scaleByZLength);
				Mesh val = new Mesh
				{
					name = name,
					indexFormat = (IndexFormat)(list.Count > 65000),
					vertices = Il2CppStructArray<Vector3>.op_Implicit(list.ToArray()),
					uv = Il2CppStructArray<Vector2>.op_Implicit(_uv.ToArray()),
					triangles = Il2CppStructArray<int>.op_Implicit(_t.ToArray())
				};
				val.RecalculateNormals();
				val.RecalculateBounds();
				return val;
			}
		}

		public const string FolderName = "TripodInvasion";

		public static bool FlipHandedness = true;

		public const float HoodTargetSize = 38f;

		public static bool NormalizeLoadedAudio = false;

		private const int ProceduralRate = 22050;

		private static readonly string[] TextureExtensions = new string[3] { ".png", ".jpg", ".jpeg" };

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

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

		private static readonly Dictionary<string, AudioClip> _clipCache = new Dictionary<string, AudioClip>();

		private static readonly HashSet<string> _missingLogged = new HashSet<string>();

		private static readonly string[] ExpectedMeshes = new string[9] { "TripodHood.obj", "F22.obj", "A10.obj", "B2.obj", "AH60.obj", "UH60.obj", "B52.obj", "Tank.obj", "Truck.obj" };

		private static readonly string[] ExpectedTextures = new string[9] { "TripodHood", "F22", "A10", "B2", "AH60", "UH60", "B52", "Tank", "Truck" };

		private static readonly string[] ExpectedAudio = new string[15]
		{
			"horn.wav", "heatray.wav", "footstep.wav", "creak.wav", "hiss.wav", "thunder.wav", "f22flyover.wav", "a10flyover.wav", "a10brrrt.wav", "b2flyover.wav",
			"rotor.wav", "minigun.wav", "b52flyover.wav", "siren.wav", "nuke.wav"
		};

		private static readonly Dictionary<int, ObjMaterialInfo> _meshMaterialInfo = new Dictionary<int, ObjMaterialInfo>();

		private static readonly Dictionary<int, Material[]> _meshMaterials = new Dictionary<int, Material[]>();

		private static readonly string[] BaseColorWords = new string[6] { "basecolor", "base_color", "diffuse", "albedo", "color", "col" };

		private static readonly string[] ShaderChain = new string[4] { "Sprites/Default", "Unlit/Texture", "Unlit/Color", "Hidden/InternalErrorShader" };

		private static Shader _cachedShader;

		public static string FolderPath => Path.Combine(MelonEnvironment.UserDataDirectory, "TripodInvasion");

		public static void EnsureFolderExists()
		{
			try
			{
				if (!Directory.Exists(FolderPath))
				{
					Directory.CreateDirectory(FolderPath);
					MelonLogger.Msg("[AssetLoader] Created asset folder: " + FolderPath);
				}
				string path = Path.Combine(FolderPath, "README.txt");
				if (!File.Exists(path))
				{
					File.WriteAllText(path, BuildReadmeText());
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[AssetLoader] Could not create asset folder: " + ex);
			}
		}

		private static string BuildReadmeText()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("TRIPOD INVASION - custom asset folder");
			stringBuilder.AppendLine("=====================================");
			stringBuilder.AppendLine("Every file below is OPTIONAL. If a file is missing the mod builds a procedural");
			stringBuilder.AppendLine("replacement, so you can add assets one at a time.");
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("MODELS (.obj, Wavefront):");
			string[] expectedMeshes = ExpectedMeshes;
			foreach (string text in expectedMeshes)
			{
				stringBuilder.AppendLine("  " + text);
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("TEXTURES (.png / .jpg / .jpeg, same base name as the model):");
			expectedMeshes = ExpectedTextures;
			foreach (string text2 in expectedMeshes)
			{
				stringBuilder.AppendLine("  " + text2 + ".png");
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("AUDIO (.wav, 8/16/24-bit PCM or 32-bit float, mono or stereo):");
			expectedMeshes = ExpectedAudio;
			foreach (string text3 in expectedMeshes)
			{
				stringBuilder.AppendLine("  " + text3);
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("AIRCRAFT ORIENTATION OVERRIDE:");
			stringBuilder.AppendLine("  The mod auto-detects which way an aircraft model points. If a jet still flies");
			stringBuilder.AppendLine("  sideways or backwards, create a text file next to it, e.g. F22.orient, containing");
			stringBuilder.AppendLine("  a single number: the extra yaw in degrees (try 90, 180 or 270).");
			stringBuilder.AppendLine("  Delete the file to go back to auto-detect.");
			return stringBuilder.ToString();
		}

		public static void LogStatus()
		{
			MelonLogger.Msg("[AssetLoader] ---- asset status (" + FolderPath + ") ----");
			string[] expectedMeshes = ExpectedMeshes;
			foreach (string fileName in expectedMeshes)
			{
				LogOne("mesh   ", fileName);
			}
			expectedMeshes = ExpectedTextures;
			foreach (string text in expectedMeshes)
			{
				LogOne("texture", (FindFile(text, TextureExtensions) != null) ? Path.GetFileName(FindFile(text, TextureExtensions)) : (text + ".png"));
			}
			expectedMeshes = ExpectedAudio;
			foreach (string fileName2 in expectedMeshes)
			{
				LogOne("audio  ", fileName2);
			}
		}

		private static void LogOne(string kind, string fileName)
		{
			bool flag = FindFileExact(fileName) != null;
			MelonLogger.Msg("[AssetLoader]   " + kind + "  " + fileName.PadRight(18) + (flag ? "FOUND" : "procedural fallback"));
		}

		public static void ClearCache()
		{
			foreach (KeyValuePair<string, Mesh> item in _meshCache)
			{
				if ((Object)(object)item.Value != (Object)null)
				{
					Object.Destroy((Object)(object)item.Value);
				}
			}
			foreach (KeyValuePair<string, Texture2D> item2 in _textureCache)
			{
				if ((Object)(object)item2.Value != (Object)null)
				{
					Object.Destroy((Object)(object)item2.Value);
				}
			}
			foreach (KeyValuePair<string, AudioClip> item3 in _clipCache)
			{
				if ((Object)(object)item3.Value != (Object)null)
				{
					Object.Destroy((Object)(object)item3.Value);
				}
			}
			_meshCache.Clear();
			_textureCache.Clear();
			_clipCache.Clear();
			_missingLogged.Clear();
		}

		private static string FindFileExact(string fileName)
		{
			try
			{
				if (!Directory.Exists(FolderPath))
				{
					return null;
				}
				string[] files = Directory.GetFiles(FolderPath);
				foreach (string text in files)
				{
					if (string.Equals(Path.GetFileName(text), fileName, StringComparison.OrdinalIgnoreCase))
					{
						return text;
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[AssetLoader] File lookup failed: " + ex.Message);
			}
			return null;
		}

		private static string FindFile(string baseName, string[] extensions)
		{
			foreach (string text in extensions)
			{
				string text2 = FindFileExact(baseName + text);
				if (text2 != null)
				{
					return text2;
				}
			}
			return null;
		}

		private static void LogMissingOnce(string what)
		{
			if (_missingLogged.Add(what))
			{
				MelonLogger.Msg("[AssetLoader] " + what + " not found, using procedural fallback.");
			}
		}

		private static void Persist(Object o)
		{
			if (o != (Object)null)
			{
				o.hideFlags = (HideFlags)61;
			}
		}

		public static Mesh LoadCustomHoodObj()
		{
			return LoadCustomVehicleObj("TripodHood.obj", 38f, groundPivot: true);
		}

		public static Mesh LoadCustomVehicleObj(string objFileName, float targetMaxDimension, bool groundPivot = false)
		{
			string key = "obj:" + objFileName.ToLowerInvariant() + ":" + targetMaxDimension.ToString("F2", CultureInfo.InvariantCulture) + ":" + groundPivot;
			if (_meshCache.TryGetValue(key, out Mesh value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = FindFileExact(objFileName);
			if (text == null)
			{
				LogMissingOnce(objFileName);
				return null;
			}
			ParsedObj parsedObj = ParseObjFile(text);
			if (parsedObj == null)
			{
				return null;
			}
			NormalizeVertices(parsedObj.Vertices, targetMaxDimension, groundPivot, scaleByZLength: false);
			bool allowSubMeshes = !string.Equals(objFileName, "TripodHood.obj", StringComparison.OrdinalIgnoreCase);
			Mesh val = BuildMesh(parsedObj, Path.GetFileNameWithoutExtension(objFileName), allowSubMeshes);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			RegisterMaterialInfo(val, text, parsedObj);
			_meshCache[key] = val;
			MelonLogger.Msg("[AssetLoader] Loaded " + objFileName + " (" + parsedObj.Vertices.Count + " verts, " + parsedObj.Triangles.Count / 3 + " tris)");
			return val;
		}

		public static Mesh LoadAircraftObj(string objFileName, float targetLength)
		{
			string key = "air:" + objFileName.ToLowerInvariant() + ":" + targetLength.ToString("F2", CultureInfo.InvariantCulture);
			if (_meshCache.TryGetValue(key, out Mesh value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = FindFileExact(objFileName);
			if (text == null)
			{
				LogMissingOnce(objFileName);
				return null;
			}
			ParsedObj parsedObj = ParseObjFile(text);
			if (parsedObj == null)
			{
				return null;
			}
			OrientAircraftNoseToPositiveZ(parsedObj.Vertices, objFileName);
			NormalizeVertices(parsedObj.Vertices, targetLength, groundPivot: false, scaleByZLength: true);
			Mesh val = BuildMesh(parsedObj, Path.GetFileNameWithoutExtension(objFileName));
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			RegisterMaterialInfo(val, text, parsedObj);
			_meshCache[key] = val;
			MelonLogger.Msg("[AssetLoader] Loaded aircraft " + objFileName + " (" + parsedObj.Vertices.Count + " verts)");
			return val;
		}

		private static bool TryFloat(string s, out float value)
		{
			return float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
		}

		private static ParsedObj ParseObjFile(string path)
		{
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				List<Vector3> list = new List<Vector3>();
				List<Vector2> list2 = new List<Vector2>();
				List<Vector3> list3 = new List<Vector3>();
				ParsedObj parsedObj = new ParsedObj();
				Dictionary<(int, int, int), int> remap = new Dictionary<(int, int, int), int>();
				char[] separator = new char[2] { ' ', '\t' };
				float num = (FlipHandedness ? (-1f) : 1f);
				foreach (string item in File.ReadLines(path))
				{
					string text = item.Trim();
					if (text.Length < 2 || text[0] == '#')
					{
						continue;
					}
					string[] array = text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
					if (array.Length == 0)
					{
						continue;
					}
					switch (array[0])
					{
					case "v":
					{
						if (array.Length >= 4 && TryFloat(array[1], out var value6) && TryFloat(array[2], out var value7) && TryFloat(array[3], out var value8))
						{
							list.Add(new Vector3(value6 * num, value7, value8));
						}
						break;
					}
					case "vt":
					{
						if (array.Length >= 3 && TryFloat(array[1], out var value4) && TryFloat(array[2], out var value5))
						{
							list2.Add(new Vector2(value4, value5));
						}
						break;
					}
					case "vn":
					{
						if (array.Length >= 4 && TryFloat(array[1], out var value) && TryFloat(array[2], out var value2) && TryFloat(array[3], out var value3))
						{
							list3.Add(new Vector3(value * num, value2, value3));
						}
						break;
					}
					case "f":
						ParseFace(array, list, list2, list3, parsedObj, remap);
						break;
					case "mtllib":
						if (text.Length > 7)
						{
							parsedObj.MtlLib = text.Substring(7).Trim();
						}
						break;
					case "usemtl":
						parsedObj.UseMaterial((text.Length > 7) ? text.Substring(7).Trim() : "");
						break;
					}
				}
				if (parsedObj.Vertices.Count == 0 || parsedObj.Triangles.Count == 0)
				{
					MelonLogger.Warning("[AssetLoader] " + Path.GetFileName(path) + " contained no usable geometry.");
					return null;
				}
				parsedObj.HasUVs = list2.Count > 0;
				parsedObj.HasNormals = list3.Count > 0;
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
				if (FindFileExact(fileNameWithoutExtension + ".flipv") != null)
				{
					for (int i = 0; i < parsedObj.UVs.Count; i++)
					{
						parsedObj.UVs[i] = new Vector2(parsedObj.UVs[i].x, 1f - parsedObj.UVs[i].y);
					}
					MelonLogger.Msg("[AssetLoader] " + fileNameWithoutExtension + ": texture flipped vertically (.flipv file).");
				}
				MelonLogger.Msg("[AssetLoader] " + Path.GetFileName(path) + ": " + (parsedObj.HasUVs ? "has" : "NO") + " texture coordinates, " + Mathf.Max(1, parsedObj.MatNames.Count) + " material(s)" + ((parsedObj.MatNames.Count > 1) ? (" [" + string.Join(", ", parsedObj.MatNames.ToArray()) + "]") : "") + ((parsedObj.MtlLib != null) ? (", material file " + parsedObj.MtlLib) : ""));
				if (!parsedObj.HasUVs)
				{
					MelonLogger.Warning("[AssetLoader] " + Path.GetFileName(path) + " has no texture coordinates (UVs), so no texture can line up on it. Re-export it with UVs.");
				}
				return parsedObj;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[AssetLoader] Failed to parse " + Path.GetFileName(path) + ": " + ex);
				return null;
			}
		}

		private static void ParseFace(string[] tokens, List<Vector3> rawV, List<Vector2> rawVt, List<Vector3> rawVn, ParsedObj result, Dictionary<(int, int, int), int> remap)
		{
			//IL_00ee: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			int num = tokens.Length - 1;
			if (num < 3)
			{
				return;
			}
			int[] array = new int[num];
			for (int i = 0; i < num; i++)
			{
				string[] array2 = tokens[i + 1].Split('/');
				int num2 = ResolveIndex(array2[0], rawV.Count);
				int num3 = ((array2.Length > 1 && array2[1].Length > 0) ? ResolveIndex(array2[1], rawVt.Count) : (-1));
				int num4 = ((array2.Length > 2 && array2[2].Length > 0) ? ResolveIndex(array2[2], rawVn.Count) : (-1));
				if (num2 < 0 || num2 >= rawV.Count)
				{
					return;
				}
				if (num3 >= rawVt.Count)
				{
					num3 = -1;
				}
				if (num4 >= rawVn.Count)
				{
					num4 = -1;
				}
				(int, int, int) key = (num2, num3, num4);
				if (!remap.TryGetValue(key, out var value))
				{
					value = (remap[key] = result.Vertices.Count);
					result.Vertices.Add(rawV[num2]);
					result.UVs.Add((num3 >= 0) ? rawVt[num3] : Vector2.zero);
					result.Normals.Add((num4 >= 0) ? rawVn[num4] : Vector3.zero);
				}
				array[i] = value;
			}
			if (result.CurrentSub < 0)
			{
				result.UseMaterial("");
			}
			List<int> list = result.SubTris[result.CurrentSub];
			for (int j = 1; j < num - 1; j++)
			{
				int item = array[0];
				int item2 = (FlipHandedness ? array[j + 1] : array[j]);
				int item3 = (FlipHandedness ? array[j] : array[j + 1]);
				result.Triangles.Add(item);
				result.Triangles.Add(item2);
				result.Triangles.Add(item3);
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
			}
		}

		private static int ResolveIndex(string token, int count)
		{
			if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return -1;
			}
			if (result > 0)
			{
				return result - 1;
			}
			if (result < 0)
			{
				return count + result;
			}
			return -1;
		}

		private static Mesh BuildMesh(ParsedObj obj, string name, bool allowSubMeshes = true)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Mesh val = new Mesh();
				((Object)val).name = name;
				val.indexFormat = (IndexFormat)(obj.Vertices.Count > 65000);
				val.vertices = Il2CppStructArray<Vector3>.op_Implicit(obj.Vertices.ToArray());
				int num = 0;
				for (int i = 0; i < obj.SubTris.Count; i++)
				{
					if (obj.SubTris[i].Count > 0)
					{
						num++;
					}
				}
				if (num > 1 && allowSubMeshes)
				{
					List<string> list = new List<string>();
					val.subMeshCount = num;
					int num2 = 0;
					for (int j = 0; j < obj.SubTris.Count; j++)
					{
						if (obj.SubTris[j].Count != 0)
						{
							val.SetTriangles(Il2CppStructArray<int>.op_Implicit(obj.SubTris[j].ToArray()), num2++);
							list.Add(obj.MatNames[j]);
						}
					}
					obj.MatNames = list;
				}
				else
				{
					val.triangles = Il2CppStructArray<int>.op_Implicit(obj.Triangles.ToArray());
					string text = null;
					for (int k = 0; k < obj.SubTris.Count; k++)
					{
						if (obj.SubTris[k].Count > 0)
						{
							text = obj.MatNames[k];
						}
					}
					obj.MatNames = new List<string>();
					if (!string.IsNullOrEmpty(text))
					{
						obj.MatNames.Add(text);
					}
				}
				if (obj.HasUVs)
				{
					val.uv = Il2CppStructArray<Vector2>.op_Implicit(obj.UVs.ToArray());
				}
				bool flag = obj.HasNormals;
				if (flag)
				{
					for (int l = 0; l < obj.Normals.Count; l++)
					{
						Vector3 val2 = obj.Normals[l];
						if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
						{
							flag = false;
							break;
						}
					}
				}
				if (flag)
				{
					val.normals = Il2CppStructArray<Vector3>.op_Implicit(obj.Normals.ToArray());
				}
				else
				{
					val.RecalculateNormals();
				}
				val.RecalculateBounds();
				Persist((Object)(object)val);
				return val;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[AssetLoader] Mesh build failed for " + name + ": " + ex);
				return null;
			}
		}

		private static void NormalizeVertices(List<Vector3> verts, float target, bool groundPivot, bool scaleByZLength)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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)
			GetBounds(verts, out var min, out var max);
			Vector3 val = max - min;
			float num = (scaleByZLength ? val.z : Mathf.Max(val.x, Mathf.Max(val.y, val.z)));
			if (num < 1E-05f)
			{
				num = 1f;
			}
			float num2 = target / num;
			Vector3 val2 = (min + max) * 0.5f;
			float num3 = (groundPivot ? min.y : val2.y);
			for (int i = 0; i < verts.Count; i++)
			{
				Vector3 val3 = verts[i];
				verts[i] = new Vector3((val3.x - val2.x) * num2, (val3.y - num3) * num2, (val3.z - val2.z) * num2);
			}
		}

		private static void GetBounds(List<Vector3> verts, out Vector3 min, out Vector3 max)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0043: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
			max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
			for (int i = 0; i < verts.Count; i++)
			{
				Vector3 val = verts[i];
				if (val.x < min.x)
				{
					min.x = val.x;
				}
				if (val.y < min.y)
				{
					min.y = val.y;
				}
				if (val.z < min.z)
				{
					min.z = val.z;
				}
				if (val.x > max.x)
				{
					max.x = val.x;
				}
				if (val.y > max.y)
				{
					max.y = val.y;
				}
				if (val.z > max.z)
				{
					max.z = val.z;
				}
			}
		}

		private static void OrientAircraftNoseToPositiveZ(List<Vector3> verts, string objFileName)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			string text = FindFileExact(Path.GetFileNameWithoutExtension(objFileName) + ".orient");
			if (text != null)
			{
				try
				{
					if (TryFloat(File.ReadAllText(text).Trim(), out var value))
					{
						RotateYaw(verts, value);
						MelonLogger.Msg("[AssetLoader] " + objFileName + ": manual orientation override " + value + " deg");
						return;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("[AssetLoader] Bad .orient file: " + ex.Message);
				}
			}
			GetBounds(verts, out var min, out var max);
			Vector3 val = max - min;
			bool isFlyingWing = objFileName.ToLowerInvariant().Contains("b2");
			if (FuselageIsAlongX(verts, val, min, max, isFlyingWing))
			{
				RotateYaw(verts, 90f);
				GetBounds(verts, out min, out max);
				val = max - min;
			}
			float num = Mathf.Max(val.z * 0.15f, 0.0001f);
			float num2 = SlabWidthX(verts, max.z - num, max.z);
			float num3 = SlabWidthX(verts, min.z, min.z + num);
			if (num2 > num3)
			{
				RotateYaw(verts, 180f);
			}
		}

		private static float MirrorMismatch(List<Vector3> verts, bool useX, float lo, float hi)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			int[] array = new int[32];
			float num = Mathf.Max(hi - lo, 0.0001f);
			for (int i = 0; i < verts.Count; i++)
			{
				int num2 = Mathf.Clamp((int)(((useX ? verts[i].x : verts[i].z) - lo) / num * 32f), 0, 31);
				array[num2]++;
			}
			float num3 = 0f;
			for (int j = 0; j < 16; j++)
			{
				num3 += (float)Mathf.Abs(array[j] - array[31 - j]);
			}
			return num3 / (float)Mathf.Max(1, verts.Count);
		}

		private static bool FuselageIsAlongX(List<Vector3> verts, Vector3 size, Vector3 min, Vector3 max, bool isFlyingWing)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			float num = MirrorMismatch(verts, useX: true, min.x, max.x);
			float num2 = MirrorMismatch(verts, useX: false, min.z, max.z);
			if (Mathf.Abs(num - num2) < 0.03f)
			{
				if (!isFlyingWing)
				{
					return size.x > size.z;
				}
				return false;
			}
			return num > num2;
		}

		private static float SlabWidthX(List<Vector3> verts, float zMin, float zMax)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			float num2 = float.MinValue;
			for (int i = 0; i < verts.Count; i++)
			{
				Vector3 val = verts[i];
				if (!(val.z < zMin) && !(val.z > zMax))
				{
					if (val.x < num)
					{
						num = val.x;
					}
					if (val.x > num2)
					{
						num2 = val.x;
					}
				}
			}
			if (!(num2 > num))
			{
				return 0f;
			}
			return num2 - num;
		}

		private static void RotateYaw(List<Vector3> verts, float degrees)
		{
			//IL_000b: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Euler(0f, degrees, 0f);
			for (int i = 0; i < verts.Count; i++)
			{
				verts[i] = val * verts[i];
			}
		}

		public static Texture2D LoadCustomVehicleTexture(string baseFileName)
		{
			string key = "tex:" + baseFileName.ToLowerInvariant();
			if (_textureCache.TryGetValue(key, out Texture2D value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = FindFile(baseFileName, TextureExtensions);
			if (text == null)
			{
				LogMissingOnce(baseFileName + ".png/.jpg");
				return null;
			}
			Texture2D val = LoadTextureFile(text);
			if ((Object)(object)val != (Object)null)
			{
				_textureCache[key] = val;
			}
			return val;
		}

		private static Texture2D LoadTextureFile(string path)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			string key = "texpath:" + path.ToLowerInvariant();
			if (_textureCache.TryGetValue(key, out Texture2D value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
				if (!ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
				{
					MelonLogger.Warning("[AssetLoader] Could not decode " + Path.GetFileName(path));
					Object.Destroy((Object)(object)val);
					return null;
				}
				if (Main.QuestMode)
				{
					val = ShrinkForQuest(val, path);
				}
				((Object)val).name = fileNameWithoutExtension;
				((Texture)val).wrapMode = (TextureWrapMode)0;
				((Texture)val).filterMode = (FilterMode)2;
				((Texture)val).anisoLevel = 4;
				Persist((Object)(object)val);
				_textureCache[key] = val;
				MelonLogger.Msg("[AssetLoader] Loaded texture " + Path.GetFileName(path) + " (" + ((Texture)val).width + "x" + ((Texture)val).height + ")");
				return val;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[AssetLoader] Texture load failed for " + fileNameWithoutExtension + ": " + ex);
				return null;
			}
		}

		private static Texture2D ShrinkForQuest(Texture2D tex, string path)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			try
			{
				int num = (path.ToLowerInvariant().Contains("tripod") ? 1024 : 512);
				int width = ((Texture)tex).width;
				int height = ((Texture)tex).height;
				if (width <= num && height <= num)
				{
					tex.Apply(true, true);
					return tex;
				}
				float num2 = (float)num / (float)Math.Max(width, height);
				int num3 = Math.Max(4, (int)((float)width * num2));
				int num4 = Math.Max(4, (int)((float)height * num2));
				RenderTexture temporary = RenderTexture.GetTemporary(num3, num4, 0, (RenderTextureFormat)0);
				RenderTexture active = RenderTexture.active;
				Graphics.Blit((Texture)(object)tex, temporary);
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(num3, num4, (TextureFormat)4, true);
				val.ReadPixels(new Rect(0f, 0f, (float)num3, (float)num4), 0, 0);
				val.Apply(true, true);
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				Object.Destroy((Object)(object)tex);
				return val;
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[AssetLoader] Quest texture shrink failed, using full size: " + ex.Message);
				return tex;
			}
		}

		private static void RegisterMaterialInfo(Mesh mesh, string objPath, ParsedObj obj)
		{
			ObjMaterialInfo objMaterialInfo = new ObjMaterialInfo();
			objMaterialInfo.ObjPath = objPath;
			objMaterialInfo.MtlLib = obj.MtlLib;
			objMaterialInfo.BaseName = Path.GetFileNameWithoutExtension(objPath);
			objMaterialInfo.MatNames = new List<string>(obj.MatNames);
			_meshMaterialInfo[((Object)mesh).GetInstanceID()] = objMaterialInfo;
		}

		public static Material[] GetMaterialsFor(Mesh mesh, Color fallbackTint, string fallbackTextureBase, bool useProcedural)
		{
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mesh == (Object)null)
			{
				return (Material[])(object)new Material[0];
			}
			int instanceID = ((Object)mesh).GetInstanceID();
			if (_meshMaterials.TryGetValue(instanceID, out Material[] value) && value != null)
			{
				bool flag = true;
				for (int i = 0; i < value.Length; i++)
				{
					if ((Object)(object)value[i] == (Object)null)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					return value;
				}
				_meshMaterials.Remove(instanceID);
			}
			_meshMaterialInfo.TryGetValue(instanceID, out ObjMaterialInfo value2);
			int num = Mathf.Max(1, mesh.subMeshCount);
			Dictionary<string, MtlEntry> dictionary = null;
			string preferDir = null;
			if (value2 != null)
			{
				string text = null;
				if (!string.IsNullOrEmpty(value2.MtlLib))
				{
					text = FindFileAnywhere(Path.GetFileName(value2.MtlLib.Replace('\\', '/')));
				}
				if (text == null)
				{
					text = FindFileAnywhere(value2.BaseName + ".mtl");
				}
				if (text != null)
				{
					dictionary = ParseMtl(text);
					preferDir = Path.GetDirectoryName(text);
				}
				else if (value2.MatNames.Count > 1)
				{
					MelonLogger.Warning("[AssetLoader] " + value2.BaseName + ".obj uses " + value2.MatNames.Count + " materials but its .mtl file is not in the folder (" + (value2.MtlLib ?? (value2.BaseName + ".mtl")) + "). Copy it and its texture images in, or the parts will share one texture.");
				}
			}
			Material[] array = (Material[])(object)new Material[num];
			for (int j = 0; j < num; j++)
			{
				string text2 = ((value2 != null && j < value2.MatNames.Count) ? value2.MatNames[j] : null);
				Texture2D val = null;
				Color val2 = fallbackTint;
				bool flag2 = false;
				MtlEntry value3 = null;
				if (dictionary != null && text2 != null)
				{
					dictionary.TryGetValue(text2, out value3);
				}
				if (value3 != null)
				{
					if (!string.IsNullOrEmpty(value3.MapKd))
					{
						val = LoadTextureNamed(value3.MapKd, value2.BaseName, preferDir);
					}
					if (value3.HasKd)
					{
						val2 = value3.Kd;
						flag2 = true;
					}
				}
				if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(text2))
				{
					string text3 = FindBaseColorFor(text2, preferDir);
					if (text3 != null)
					{
						val = LoadTextureFile(text3);
					}
				}
				if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(text2))
				{
					string text4 = FindFile(text2, TextureExtensions);
					if (text4 != null)
					{
						val = LoadTextureFile(text4);
					}
				}
				if ((Object)(object)val == (Object)null && (num == 1 || dictionary == null))
				{
					val = (useProcedural ? GetTextureOrFallback(fallbackTextureBase) : LoadCustomVehicleTexture(fallbackTextureBase));
				}
				Color tint = (((Object)(object)val != (Object)null) ? Color.white : (flag2 ? val2 : fallbackTint));
				array[j] = CreateSafeMaterial(val, tint, fallbackTextureBase + "_" + (text2 ?? j.ToString()));
				Persist((Object)(object)array[j]);
			}
			_meshMaterials[instanceID] = array;
			return array;
		}

		private static Dictionary<string, MtlEntry> ParseMtl(string path)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, MtlEntry> dictionary = new Dictionary<string, MtlEntry>();
			try
			{
				MtlEntry mtlEntry = null;
				foreach (string item in File.ReadLines(path))
				{
					string text = item.Trim();
					if (text.Length == 0 || text[0] == '#')
					{
						continue;
					}
					if (text.StartsWith("newmtl", StringComparison.OrdinalIgnoreCase))
					{
						mtlEntry = new MtlEntry();
						dictionary[text.Substring(6).Trim()] = mtlEntry;
					}
					else if (mtlEntry != null && text.StartsWith("map_Kd", StringComparison.OrdinalIgnoreCase))
					{
						mtlEntry.MapKd = StripMapOptions(text.Substring(6).Trim());
					}
					else if (mtlEntry != null && text.StartsWith("Kd ", StringComparison.OrdinalIgnoreCase))
					{
						string[] array = text.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
						if (array.Length >= 4 && TryFloat(array[1], out var value) && TryFloat(array[2], out var value2) && TryFloat(array[3], out var value3))
						{
							mtlEntry.Kd = new Color(value, value2, value3, 1f);
							mtlEntry.HasKd = true;
						}
					}
				}
				MelonLogger.Msg("[AssetLoader] Read " + Path.GetFileName(path) + " (" + dictionary.Count + " materials)");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[AssetLoader] Could not read " + Path.GetFileName(path) + ": " + ex.Message);
			}
			return dictionary;
		}

		private static string StripMapOptions(string s)
		{
			string[] array = s.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
			int i;
			int num2;
			for (i = 0; i < array.Length && array[i].StartsWith("-"); i += 1 + num2)
			{
				int num;
				switch (array[i].ToLowerInvariant())
				{
				default:
					num = 1;
					break;
				case "-mm":
					num = 2;
					break;
				case "-s":
				case "-o":
				case "-t":
					num = 3;
					break;
				}
				num2 = num;
			}
			if (i >= array.Length)
			{
				if (array.Length == 0)
				{
					return s;
				}
				return array[^1];
			}
			return string.Join(" ", array, i, array.Length - i);
		}

		private static Texture2D LoadTextureNamed(string mapPath, string modelName, string preferDir)
		{
			string fileName = Path.GetFileName(mapPath.Replace('\\', '/'));
			string text = Path.GetExtension(fileName).ToLowerInvariant();
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
			string text2 = null;
			string[] array = ((!string.IsNullOrEmpty(preferDir)) ? new string[2] { preferDir, FolderPath } : new string[1] { FolderPath });
			for (int i = 0; i < array.Length; i++)
			{
				if (text2 != null)
				{
					break;
				}
				switch (text)
				{
				case ".png":
				case ".jpg":
				case ".jpeg":
					text2 = FindFileUnder(array[i], fileName);
					break;
				}
				for (int j = 0; j < TextureExtensions.Length; j++)
				{
					if (text2 != null)
					{
						break;
					}
					text2 = FindFileUnder(array[i], fileNameWithoutExtension + TextureExtensions[j]);
				}
			}
			if (text2 == null)
			{
				LogMissingOnce(fileName + " (needed by " + modelName + "; Unity can only load .png/.jpg, so convert other formats)");
				return null;
			}
			return LoadTextureFile(text2);
		}

		private static string FindBaseColorFor(string matName, string preferDir)
		{
			try
			{
				string text = matName.ToLowerInvariant();
				string[] array = ((!string.IsNullOrEmpty(preferDir)) ? new string[2] { preferDir, FolderPath } : new string[1] { FolderPath });
				foreach (string text2 in array)
				{
					if (string.IsNullOrEmpty(text2) || !Directory.Exists(text2))
					{
						continue;
					}
					string[] files = Directory.GetFiles(text2, "*", SearchOption.AllDirectories);
					for (int j = 0; j < 3; j++)
					{
						string[] baseColorWords = BaseColorWords;
						foreach (string value in baseColorWords)
						{
							string[] array2 = files;
							foreach (string text3 in array2)
							{
								string text4 = Path.GetExtension(text3).ToLowerInvariant();
								if (text4 != ".png" && text4 != ".jpg" && text4 != ".jpeg")
								{
									continue;
								}
								string text5 = Path.GetFileName(text3).ToLowerInvariant();
								string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text5);
								if (!text5.Contains(value) && !fileNameWithoutExtension.EndsWith("_c") && !fileNameWithoutExtension.EndsWith("_d"))
								{
									continue;
								}
								string text6 = Path.GetFileName(Path.GetDirectoryName(text3) ?? "").ToLowerInvariant();
								bool num;
								if (j != 0)
								{
									if (j != 1)
									{
										if (text6.Length <= 2)
										{
											continue;
										}
										if (text.Contains(text6))
										{
											goto IL_016b;
										}
										num = text6.Contains(text);
									}
									else
									{
										num = text5.Contains(text);
									}
								}
								else
								{
									num = text6 == text;
								}
								if (!num)
								{
									continue;
								}
								goto IL_016b;
								IL_016b:
								return text3;
							}
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static string FindFileAnywhere(string fileName)
		{
			return FindFileUnder(FolderPath, fileName);
		}

		private static string FindFileUnder(string root, string fileName)
		{
			try
			{
				if (string.IsNullOrEmpty(root) || !Directory.Exists(root) || string.IsNullOrEmpty(fileName))
				{
					return null;
				}
				string[] files = Directory.GetFiles(root, "*", SearchOption.AllDirectories);
				foreach (string text in files)
				{
					if (string.Equals(Path.GetFileName(text), fileName, StringComparison.OrdinalIgnoreCase))
					{
						return text;
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[AssetLoader] File search failed: " + ex.Message);
			}
			return null;
		}

		public static Texture2D GetTextureOrFallback(string baseFileName)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadCustomVehicleTexture(baseFileName);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			string key = "proctex:" + baseFileName.ToLowerInvariant();
			if (_textureCache.TryGetValue(key, out Texture2D value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture2D val2;
			switch (baseFileName.ToLowerInvariant())
			{
			case "tripodhood":
				val2 = MakeNoiseTexture(128, new Color(0.17f, 0.18f, 0.2f), new Color(0.32f, 0.2f, 0.14f), 7, 0.55f);
				break;
			case "tank":
			case "truck":
				val2 = MakeNoiseTexture(128, new Color(0.24f, 0.28f, 0.18f), new Color(0.38f, 0.36f, 0.22f), 11, 0.45f);
				break;
			default:
				val2 = MakeNoiseTexture(128, new Color(0.38f, 0.4f, 0.43f), new Color(0.26f, 0.28f, 0.31f), 5, 0.3f);
				break;
			}
			((Object)val2).name = "proc_" + baseFileName;
			Persist((Object)(object)val2);
			_textureCache[key] = val2;
			return val2;
		}

		private static Texture2D MakeNoiseTexture(int size, Color a, Color b, int seed, float contrast)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, true);
			Color32[] array = (Color32[])(object)new Color32[size * size];
			Random random = new Random(seed);
			float[,] array2 = new float[9, 9];
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					array2[j, i] = (float)random.NextDouble();
				}
			}
			for (int k = 0; k <= 8; k++)
			{
				array2[8, k] = array2[0, k];
				array2[k, 8] = array2[k, 0];
			}
			for (int l = 0; l < size; l++)
			{
				for (int m = 0; m < size; m++)
				{
					float num = (float)m / (float)size * 8f;
					float num2 = (float)l / (float)size * 8f;
					int num3 = (int)num;
					int num4 = (int)num2;
					float num5 = Smooth(num - (float)num3);
					float num6 = Smooth(num2 - (float)num4);
					float num7 = Mathf.Lerp(Mathf.Lerp(array2[num3, num4], array2[num3 + 1, num4], num5), Mathf.Lerp(array2[num3, num4 + 1], array2[num3 + 1, num4 + 1], num5), num6);
					float num8 = (float)random.NextDouble() * 0.12f;
					float num9 = Mathf.Clamp01(0.5f + (num7 - 0.5f) * contrast * 2f + num8 - 0.06f);
					Color val2 = Color.Lerp(a, b, num9);
					array[l * size + m] = new Color32((byte)(val2.r * 255f), (byte)(val2.g * 255f), (byte)(val2.b * 255f), byte.MaxValue);
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply(true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)1;
			return val;
		}

		private static float Smooth(float t)
		{
			return t * t * (3f - 2f * t);
		}

		public static Shader GetSafeShader()
		{
			if ((Object)(object)_cachedShader != (Object)null)
			{
				return _cachedShader;
			}
			string[] shaderChain = ShaderChain;
			for (int i = 0; i < shaderChain.Length; i++)
			{
				Shader val = Shader.Find(shaderChain[i]);
				if ((Object)(object)val != (Object)null)
				{
					_cachedShader = val;
					return val;
				}
			}
			MelonLogger.Warning("[AssetLoader] No safe shader found; materials may render pink.");
			return null;
		}

		public static Material CreateSafeMaterial(Texture2D texture, Color tint, string name = "TripodMat")
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Shader safeShader = GetSafeShader();
			if ((Object)(object)safeShader == (Object)null)
			{
				return null;
			}
			Material val = new Material(safeShader);
			((Object)val).name = name;
			tint.a = 1f;
			val.color = tint;
			if ((Object)(object)texture != (Object)null)
			{
				val.mainTexture = (Texture)(object)texture;
			}
			if (val.HasProperty("_Cull"))
			{
				val.SetInt("_Cull", 2);
			}
			return val;
		}

		public static Material CreateTexturedMaterial(string textureBaseName, Color tint)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return CreateSafeMaterial(GetTextureOrFallback(textureBaseName), tint, textureBaseName + "_Mat");
		}

		public static AudioClip LoadWavFile(string fileName)
		{
			string key = "wav:" + fileName.ToLowerInvariant();
			if (_clipCache.TryGetValue(key, out AudioClip value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = FindFileExact(fileName);
			if (text == null)
			{
				LogMissingOnce(fileName);
				return null;
			}
			try
			{
				if (!DecodeWav(File.ReadAllBytes(text), out float[] samples, out int channels, out int rate))
				{
					MelonLogger.Warning("[AssetLoader] Unsupported WAV format: " + fileName);
					return null;
				}
				if (NormalizeLoadedAudio)
				{
					NormalizePeak(samples, 0.97f);
				}
				int num = samples.Length / channels;
				AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(fileName), num, channels, rate, false);
				val.SetData(Il2CppStructArray<float>.op_Implicit(samples), 0);
				Persist((Object)(object)val);
				_clipCache[key] = val;
				MelonLogger.Msg("[AssetLoader] Loaded audio " + fileName + " (" + ((float)num / (float)rate).ToString("F1", CultureInfo.InvariantCulture) + "s, " + channels + "ch, " + rate + "Hz)");
				return val;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[AssetLoader] WAV load failed for " + fileName + ": " + ex);
				return null;
			}
		}

		private static bool DecodeWav(byte[] d, out float[] samples, out int channels, out int rate)
		{
			samples = null;
			channels = 0;
			rate = 0;
			if (d.Length < 44)
			{
				return false;
			}
			if (d[0] != 82 || d[1] != 73 || d[2] != 70 || d[3] != 70)
			{
				return false;
			}
			if (d[8] != 87 || d[9] != 65 || d[10] != 86 || d[11] != 69)
			{
				return false;
			}
			int num = 0;
			int num2 = 0;
			int num3 = -1;
			int num4 = 0;
			int num5 = 12;
			while (num5 + 8 <= d.Length)
			{
				string text = Encoding.ASCII.GetString(d, num5, 4);
				int num6 = BitConverter.ToInt32(d, num5 + 4);
				int num7 = num5 + 8;
				if (num6 < 0)
				{
					break;
				}
				if (text == "fmt ")
				{
					num = BitConverter.ToUInt16(d, num7);
					channels = BitConverter.ToUInt16(d, num7 + 2);
					rate = BitConverter.ToInt32(d, num7 + 4);
					num2 = BitConverter.ToUInt16(d, num7 + 14);
					if (num == 65534 && num6 >= 26)
					{
						num = BitConverter.ToUInt16(d, num7 + 24);
					}
				}
				else if (text == "data")
				{
					num3 = num7;
					num4 = Math.Min(num6, d.Length - num7);
					break;
				}
				num5 = num7 + num6 + (num6 & 1);
			}
			if (num3 < 0 || channels < 1 || channels > 8 || rate < 8000)
			{
				return false;
			}
			bool flag = num == 1;
			bool flag2 = num == 3;
			if (!flag && !flag2)
			{
				return false;
			}
			int num8 = num2 / 8;
			if (num8 < 1 || num8 > 4)
			{
				return false;
			}
			if (flag2 && num2 != 32)
			{
				return false;
			}
			int num9 = num4 / num8;
			num9 -= num9 % channels;
			samples = new float[num9];
			for (int i = 0; i < num9; i++)
			{
				int num10 = num3 + i * num8;
				float num11;
				if (flag2)
				{
					num11 = BitConverter.ToSingle(d, num10);
				}
				else
				{
					switch (num2)
					{
					case 8:
						num11 = (float)(d[num10] - 128) / 128f;
						break;
					case 16:
						num11 = (float)BitConverter.ToInt16(d, num10) / 32768f;
						break;
					case 24:
					{
						int num12 = d[num10] | (d[num10 + 1] << 8) | (d[num10 + 2] << 16);
						if ((num12 & 0x800000) != 0)
						{
							num12 |= -16777216;
						}
						num11 = (float)num12 / 8388608f;
						break;
					}
					default:
						num11 = (float)BitConverter.ToInt32(d, num10) / 2.1474836E+09f;
						break;
					}
				}
				samples[i] = num11;
			}
			return true;
		}

		private static void NormalizePeak(float[] buf, float peak)
		{
			float num = 0f;
			for (int i = 0; i < buf.Length; i++)
			{
				float num2 = Mathf.Abs(buf[i]);
				if (num2 > num)
				{
					num = num2;
				}
			}
			if (!(num < 0.0001f))
			{
				float num3 = peak / num;
				for (int j = 0; j < buf.Length; j++)
				{
					buf[j] *= num3;
				}
			}
		}

		public static AudioClip GetClip(string name)
		{
			string text = (name.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) ? name : (name + ".wav"));
			AudioClip val = LoadWavFile(text);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			string key = "synth:" + text.ToLowerInvariant();
			if (_clipCache.TryGetValue(key, out AudioClip value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			AudioClip val2 = SynthesizeClip(Path.GetFileNameWithoutExtension(text).ToLowerInvariant());
			_clipCache[key] = val2;
			return val2;
		}

		private static AudioClip SynthesizeClip(string name)
		{
			float[] array = name switch
			{
				"horn" => SynthHorn(), 
				"heatray" => SynthHeatRay(), 
				"footstep" => SynthFootstep(), 
				"creak" => SynthCreak(), 
				"hiss" => SynthHiss(), 
				"thunder" => SynthThunder(), 
				"f22flyover" => SynthJetPass(7f, 3.2f, 1.1f, 950f, 520f, 450f, 6000f, 90f, 0.16f, 0.9f, 21), 
				"a10flyover" => SynthJetPass(7.5f, 3.5f, 1.3f, 1500f, 260f, 250f, 3200f, 70f, 0.2f, 0.8f, 22), 
				"a10brrrt" => SynthGau8(), 
				"ambience" => SynthAmbience(), 
				"b2flyover" => SynthJetPass(10f, 4.8f, 2.2f, 120f, 30f, 60f, 700f, 42f, 0.3f, 1f, 23), 
				"rotor" => SynthRotor(), 
				"minigun" => SynthMinigun(), 
				"b52flyover" => SynthJetPass(12f, 6f, 2.6f, 90f, 25f, 50f, 600f, 38f, 0.3f, 1f, 24), 
				"siren" => SynthSiren(), 
				_ => SynthHiss(), 
			};
			NormalizePeak(array, 0.92f);
			FadeEdges(array, 0.008f);
			AudioClip obj = AudioClip.Create("proc_" + name, array.Length, 1, 22050, false);
			obj.SetData(Il2CppStructArray<float>.op_Implicit(array), 0);
			Persist((Object)(object)obj);
			return obj;
		}

		private static float[] NewBuffer(float seconds)
		{
			return new float[Mathf.Max(1, (int)(seconds * 22050f))];
		}

		private static float Noise(Random r)
		{
			return (float)(r.NextDouble() * 2.0 - 1.0);
		}

		private static void LowPass(float[] b, float cutoffHz)
		{
			float num = 1f / ((float)Math.PI * 2f * cutoffHz);
			float num2 = 4.5351473E-05f;
			float num3 = num2 / (num + num2);
			float num4 = 0f;
			for (int i = 0; i < b.Length; i++)
			{
				num4 = (b[i] = num4 + num3 * (b[i] - num4));
			}
		}

		private static void HighPass(float[] b, float cutoffHz)
		{
			float num = 1f / ((float)Math.PI * 2f * cutoffHz);
			float num2 = 4.5351473E-05f;
			float num3 = num2 / (num + num2);
			float num4 = 0f;
			for (int i = 0; i < b.Length; i++)
			{
				num4 += num3 * (b[i] - num4);
				b[i] -= num4;
			}
		}

		private static void FadeEdges(float[] b, float seconds)
		{
			int num = Mathf.Min(b.Length / 2, (int)(seconds * 22050f));
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / (float)num;
				b[i] *= num2;
				b[b.Length - 1 - i] *= num2;
			}
		}

		private static float[] SynthHorn()
		{
			float num = 4.6f;
			float[] array = NewBuffer(num);
			float num2 = 0f;
			float num3 = 0f;
			float num4 = (float)Math.PI * 2f;
			for (int i = 0; i < array.Length; i++)
			{
				float num5 = (float)i / 22050f;
				float num6 = 1f + 0.006f * (float)Math.Sin(num4 * 5.2f * num5);
				float num7 = 1f - 0.035f * Mathf.Clamp01((num5 - 2.8f) / 1.8f);
				float num8 = 58f * num6 * num7;
				num2 += num4 * num8 / 22050f;
				num3 += num4 * num8 * 1.498f / 22050f;
				float num9 = (float)Math.Sin(num2) + 0.7f * (float)Math.Sin(2f * num2) + 0.5f * (float)Math.Sin(3f * num2 + 0.5f) + 0.35f * (float)Math.Sin(4f * num2) + 0.2f * (float)Math.Sin(6f * num2) + 0.25f * (float)Math.Sin(num3);
				num9 = (float)Math.Tanh(num9 * 1.4f);
				float num10 = Smooth(Mathf.Clamp01(num5 / 0.5f));
				float num11 = Mathf.Clamp01((num - num5) / 1.8f);
				array[i] = num9 * num10 * num11 * 0.8f;
			}
			return array;
		}

		private static float[] SynthHeatRay()
		{
			float[] array = NewBuffer(2f);
			Random random = new Random(31);
			float num = (float)Math.PI * 2f;
			float num2 = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = (float)i / 22050f;
				float num4 = 0.5f * (float)Math.Sin(num * 140f * num3 + 3f * (float)Math.Sin(num * 7f * num3)) + 0.25f * (float)Math.Sin(num * 280f * num3);
				if (random.NextDouble() < 0.0018)
				{
					num2 = 0.9f;
				}
				num2 *= 0.985f;
				array[i] = num4 + Noise(random) * (0.1f + num2);
			}
			HighPass(array, 60f);
			return array;
		}

		private static float[] SynthFootstep()
		{
			float[] array = NewBuffer(1.4f);
			Random r = new Random(41);
			float num = 0f;
			float num2 = (float)Math.PI * 2f;
			float[] array2 = new float[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = Noise(r);
			}
			LowPass(array2, 180f);
			for (int j = 0; j < array.Length; j++)
			{
				float num3 = (float)j / 22050f;
				num += num2 * (28f + 55f * (float)Math.Exp((0f - num3) * 14f)) / 22050f;
				float num4 = (float)Math.Sin(num) * (float)Math.Exp((0f - num3) * 5f);
				float num5 = array2[j] * 6f * (float)Math.Exp((0f - num3) * 9f) * 0.7f;
				float num6 = ((float)Math.Sin(num2 * 410f * num3) + 0.6f * (float)Math.Sin(num2 * 713f * num3)) * (float)Math.Exp((0f - num3) * 18f) * 0.25f;
				array[j] = num4 + num5 + num6;
			}
			return array;
		}

		private static float[] SynthCreak()
		{
			float num = 1.8f;
			float[] array = NewBuffer(num);
			Random r = new Random(51);
			float num2 = 0f;
			float num3 = (float)Math.PI * 2f;
			for (int i = 0; i < array.Length; i++)
			{
				float num4 = (float)i / 22050f;
				float num5 = 70f + 40f * (float)Math.Sin(num3 * 0.9f * num4) + 20f * (float)Math.Sin(num3 * 2.3f * num4);
				num2 += num3 * num5 / 22050f;
				float num6 = 2f * (num2 / num3 % 1f) - 1f;
				float num7 = 1f + 0.6f * (float)Math.Sin(num3 * 11f * num4);
				float num8 = (float)Math.Pow((float)Math.Sin((float)Math.PI * num4 / num), 2.0);
				array[i] = (num6 * 0.7f + Noise(r) * 0.3f) * num7 * num8;
			}
			LowPass(array, 900f);
			return array;
		}

		private static float[] SynthHiss()
		{
			float[] array = NewBuffer(1.5f);
			Random r = new Random(61);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Noise(r);
			}
			HighPass(array, 1800f);
			LowPass(array, 9000f);
			for (int j = 0; j < array.Length; j++)
			{
				float num = (float)j / 22050f;
				array[j] *= Smooth(Mathf.Clamp01(num / 0.08f)) * (float)Math.Exp((0f - Mathf.Max(0f, num - 0.08f)) * 2.2f);
			}
			return array;
		}

		private static float[] SynthThunder()
		{
			float[] array = NewBuffer(4f);
			Random r = new Random(71);
			float[] array2 = new float[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = Noise(r);
			}
			LowPass(array2, 120f);
			for (int j = 0; j < array.Length; j++)
			{
				float num = (float)j / 22050f;
				float num2 = Noise(r) * (float)Math.Exp((0f - num) * 30f);
				float num3 = array2[j] * 12f * ((float)Math.Exp((0f - num) * 0.8f) + 0.6f * (float)Math.Exp((0f - Math.Abs(num - 0.5f)) * 3f) + 0.4f * (float)Math.Exp((0f - Math.Abs(num - 1.3f)) * 3f));
				array[j] = num2 + num3 * 0.5f;
			}
			return array;
		}

		private static float[] SynthJetPass(float len, float center, float sigma, float toneBase, float toneDoppler, float noiseHp, float noiseLp, float rumbleHz, float toneAmp, float noiseAmp, int seed)
		{
			float[] array = NewBuffer(len);
			Random r = new Random(seed);
			float[] array2 = new float[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = Noise(r);
			}
			HighPass(array2, noiseHp);
			LowPass(array2, noiseLp);
			float num = 0f;
			float num2 = 0f;
			float num3 = (float)Math.PI * 2f;
			for (int j = 0; j < array.Length; j++)
			{
				float num4 = (float)j / 22050f;
				float num5 = (num4 - center) / sigma;
				float num6 = (float)Math.Exp((0f - num5) * num5);
				float num7 = toneBase + toneDoppler * (float)Math.Tanh((center - num4) * 1.2f);
				num += num3 * num7 / 22050f;
				num2 += num3 * rumbleHz / 22050f;
				array[j] = num6 * (array2[j] * noiseAmp * 4f + (float)Math.Sin(num) * toneAmp + (float)Math.Sin(num2) * 0.5f + (float)Math.Sin(num2 * 1.46f) * 0.25f);
			}
			return array;
		}

		private static float[] SynthAmbience()
		{
			float num = 6f;
			float[] array = NewBuffer(num);
			float num2 = (float)Math.PI * 2f;
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = (float)i / (float)array.Length * num;
				float num4 = 0.78f + 0.22f * (float)Math.Sin(num2 * 0.5f * num3);
				float num5 = (float)Math.Sin(num2 * 39f * num3) * 0.55f + (float)Math.Sin(num2 * 58.5f * num3) * 0.35f + (float)Math.Sin(num2 * 83f * num3 + 1f) * 0.18f;
				array[i] = num5 * num4;
			}
			return array;
		}

		private static float[] SynthRotor()
		{
			float[] array = NewBuffer(4f);
			Random r = new Random(91);
			float[] array2 = new float[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = Noise(r);
			}
			LowPass(array2, 380f);
			float num = (float)Math.PI * 2f;
			for (int j = 0; j < array.Length; j++)
			{
				float num2 = (float)j / 22050f;
				float num3 = (float)Math.Exp((0f - num2 * 17f % 1f) * 9f);
				float num4 = (float)Math.Sin(num * 34f * num2) * 0.35f * num3;
				float num5 = (float)Math.Sin(num * 78f * num2) * (0.5f + 0.5f * (float)Math.Sin(num * 4f * num2)) * 0.08f;
				float num6 = (float)Math.Sin(num * 1180f * num2) * 0.025f;
				array[j] = array2[j] * (0.25f + 1.6f * num3) + num4 + num5 + num6;
			}
			return array;
		}

		private static float[] SynthSiren()
		{
			float[] array = NewBuffer(8f);
			float num = 0f;
			float num2 = (float)Math.PI * 2f;
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = (float)i / 22050f;
				float num4 = 560f + 300f * (float)Math.Sin(num2 * num3 / 4f - (float)Math.PI / 2f) + 4f * (float)Math.Sin(num2 * 5.5f * num3);
				num += num2 * num4 / 22050f;
				array[i] = (float)Math.Sin(num) * 0.6f + (float)Math.Sin(num * 2f) * 0.25f + (float)Math.Sin(num * 3f) * 0.1f;
			}
			return array;
		}

		private static float[] SynthMinigun()
		{
			float[] array = NewBuffer(2f);
			Random r = new Random(97);
			int num = 441;
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = (float)Math.Exp((float)(-(i % num)) / ((float)num * 0.18f));
				array[i] = Noise(r) * (0.15f + num2) + (float)Math.Sin((float)Math.PI * 200f * (float)i / 22050f) * 0.3f * num2;
			}
			HighPass(array, 180f);
			return array;
		}

		private static float[] SynthGau8()
		{
			float num = 1.8f;
			float[] array = NewBuffer(num);
			Random r = new Random(81);
			int num2 = 339;
			float num3 = (float)Math.PI * 2f;
			for (int i = 0; i < array.Length; i++)
			{
				float num4 = (float)i / 22050f;
				int num5 = i % num2;
				float num6 = (float)Math.Exp((float)(-num5) / 132.3f);
				float num7 = (float)Math.Sin(num3 * 60f * (float)num5 / 22050f) * (float)Math.Exp((float)(-num5) / 264.6f) * 0.8f;
				float num8 = Mathf.Clamp01(num4 / 0.12f) * Mathf.Clamp01((num - num4) / 0.2f);
				array[i] = (Noise(r) * num6 + num7) * num8;
			}
			LowPass(array, 4500f);
			return array;
		}

		public static Mesh GetHoodMesh()
		{
			Mesh val = LoadCustomHoodObj();
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return GetOrBuildProcedural("proc:hood", () => BuildFallbackHood());
		}

		public static Mesh GetTankMesh()
		{
			Mesh val = LoadCustomVehicleObj("Tank.obj", 9f, groundPivot: true);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return GetOrBuildProcedural("proc:tank", () => BuildFallbackTank());
		}

		public static Mesh GetTruckMesh()
		{
			Mesh val = LoadCustomVehicleObj("Truck.obj", 8f, groundPivot: true);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return GetOrBuildProcedural("proc:truck", () => BuildFallbackTruck());
		}

		public static Mesh GetAircraftMesh(AircraftKind kind, float targetLength)
		{
			Mesh val = LoadAircraftObj(kind.ToString() + ".obj", targetLength);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return GetOrBuildProcedural("proc:" + kind.ToString() + ":" + targetLength.ToString("F1", CultureInfo.InvariantCulture), () => BuildFallbackAircraft(kind, targetLength));
		}

		private static Mesh GetOrBuildProcedural(string key, Func<Mesh> build)
		{
			if (_meshCache.TryGetValue(key, out Mesh value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Mesh val = build();
			if ((Object)(object)val != (Object)null)
			{
				Persist((Object)(object)val);
				_meshCache[key] = val;
			}
			return val;
		}

		private static Mesh BuildFallbackHood()
		{
			//IL_0015: 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_0047: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.AddEllipsoid(new Vector3(0f, 11f, 0f), new Vector3(19f, 11f, 15f), 24, 14);
			meshBuilder.AddTaperedBox(new Vector3(0f, 12.5f, -13f), new Vector3(15f, 3.4f, 7f), new Vector2(1f, 1f), new Vector2(0.7f, 0.5f));
			meshBuilder.AddTaperedBox(new Vector3(0f, 2.2f, 0f), new Vector3(10f, 4.4f, 10f), new Vector2(1f, 1f), new Vector2(0.8f, 0.8f));
			return meshBuilder.ToMesh("proc_TripodHood", 38f, groundPivot: true, scaleByZLength: false);
		}

		private static Mesh BuildFallbackTank()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.AddTaperedBox(new Vector3(0f, 1f, 0f), new Vector3(3.6f, 1.4f, 7.4f), Vector2.one, new Vector2(0.85f, 0.6f));
			meshBuilder.AddBox(new Vector3(-1.9f, 0.6f, 0f), new Vector3(0.7f, 1.2f, 7.8f));
			meshBuilder.AddBox(new Vector3(1.9f, 0.6f, 0f), new Vector3(0.7f, 1.2f, 7.8f));
			meshBuilder.AddTaperedBox(new Vector3(0f, 2.15f, -0.3f), new Vector3(2.6f, 0.9f, 3.2f), Vector2.one, new Vector2(0.8f, 0.8f));
			meshBuilder.AddCylinder(new Vector3(0f, 2.25f, 3.4f), 0.14f, 4.6f, 2, 8);
			return meshBuilder.ToMesh("proc_Tank", 9f, groundPivot: true, scaleByZLength: false);
		}

		private static Mesh BuildFallbackTruck()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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)
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.AddBox(new Vector3(0f, 0.9f, 0f), new Vector3(2.6f, 0.6f, 7f));
			meshBuilder.AddTaperedBox(new Vector3(0f, 1.9f, 2.4f), new Vector3(2.5f, 1.6f, 2f), Vector2.one, new Vector2(0.95f, 0.8f));
			meshBuilder.AddBox(new Vector3(0f, 1.6f, -1.1f), new Vector3(2.5f, 1f, 4.2f));
			float[] array = new float[3] { 2.4f, -0.4f, -2.4f };
			foreach (float num in array)
			{
				meshBuilder.AddCylinder(new Vector3(-1.25f, 0.55f, num), 0.55f, 0.45f, 0, 12);
				meshBuilder.AddCylinder(new Vector3(1.25f, 0.55f, num), 0.55f, 0.45f, 0, 12);
			}
			meshBuilder.AddCylinder(new Vector3(0f, 2.5f, -1.2f), 0.07f, 1.4f, 2, 8);
			return meshBuilder.ToMesh("proc_Truck", 8f, groundPivot: true, scaleByZLength: false);
		}

		private static Mesh BuildFallbackAircraft(AircraftKind kind, float length)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be