Decompiled source of SIF Green house v0.1.4

BepInEx/plugins/SifGreenhouse/SifGreenhouse.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SifGreenhouse
{
	internal sealed class BoundaryVisuals
	{
		private GameObject root;

		private Mesh mesh;

		private Material material;

		private Texture2D texture;

		private float radius;

		private static bool warnedShader;

		internal bool Visible
		{
			get
			{
				if (Object.op_Implicit((Object)(object)root))
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		internal GameObject Root => root;

		internal void Sync(SifWard ward)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ward) || !Object.op_Implicit((Object)(object)ward.Area) || !ward.Enabled || Plugin.Stopping || Application.isBatchMode || (int)SystemInfo.graphicsDeviceType == 4 || (int)Heightmap.FindBiome(((Component)ward).transform.position) != 4)
			{
				if (Object.op_Implicit((Object)(object)root))
				{
					root.SetActive(false);
				}
			}
			else if (Object.op_Implicit((Object)(object)root) || Create(ward.Area))
			{
				root.transform.position = ((Component)ward).transform.position;
				if (radius != ward.Area.m_radius)
				{
					radius = ward.Area.m_radius;
					root.transform.localScale = Vector3.one * radius;
				}
				root.SetActive(true);
			}
		}

		private bool Create(PrivateArea area)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Expected O, but got Unknown
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Expected O, but got Unknown
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			float num = area.m_radius;
			Shader val = null;
			Material[] sharedMaterials = ((Renderer)area.m_model).sharedMaterials;
			foreach (Material val2 in sharedMaterials)
			{
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.shader) && ((Object)val2.shader).name == "Standard")
				{
					val = val2.shader;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = Shader.Find("Standard");
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				if (!warnedShader)
				{
					Debug.LogWarning((object)"[SIF Green house] Transparent boundary shader unavailable; visual disabled, gameplay unchanged.");
					warnedShader = true;
				}
				return false;
			}
			radius = num;
			root = new GameObject("SIF persistent greenhouse haze (local visual only)");
			int num2 = LayerMask.NameToLayer("Ignore Raycast");
			root.layer = ((num2 >= 0) ? num2 : 0);
			mesh = new Mesh
			{
				name = "SIF greenhouse boundary sphere"
			};
			Vector3[] array = (Vector3[])(object)new Vector3[1225];
			Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
			int[] array3 = new int[13824];
			int num3 = 0;
			for (int j = 0; j <= 24; j++)
			{
				for (int k = 0; k <= 48; k++)
				{
					float num4 = (float)k * (float)Math.PI * 2f / 48f;
					float num5 = (float)j * (float)Math.PI / 24f;
					int num6 = j * 49 + k;
					array[num6] = new Vector3(Mathf.Sin(num5) * Mathf.Cos(num4), Mathf.Cos(num5), Mathf.Sin(num5) * Mathf.Sin(num4));
					array2[num6] = new Vector2((float)k / 48f, (float)j / 24f);
				}
			}
			for (int l = 0; l < 24; l++)
			{
				for (int m = 0; m < 48; m++)
				{
					int num7 = l * 49 + m;
					int num8 = num7 + 1;
					int num9 = num7 + 48 + 1;
					int num10 = num9 + 1;
					int[] array4 = new int[12]
					{
						num7, num9, num8, num8, num9, num10, num8, num9, num7, num10,
						num9, num8
					};
					foreach (int num11 in array4)
					{
						array3[num3++] = num11;
					}
				}
			}
			mesh.vertices = array;
			mesh.uv = array2;
			mesh.triangles = array3;
			mesh.normals = array;
			mesh.RecalculateBounds();
			texture = new Texture2D(128, 64, (TextureFormat)4, false)
			{
				name = "SIF original translucent greenhouse tint",
				wrapMode = (TextureWrapMode)0
			};
			Color[] array5 = (Color[])(object)new Color[8192];
			for (int n = 0; n < 64; n++)
			{
				for (int num12 = 0; num12 < 128; num12++)
				{
					float u = (float)num12 / 128f;
					float v = (float)n / 64f;
					float num13 = Spot(u, v, 0.19f, 0.45f, 0.06f) + Spot(u, v, 0.73f, 0.62f, 0.04f);
					float num14 = Spot(u, v, 0.43f, 0.52f, 0.035f) + Spot(u, v, 0.88f, 0.39f, 0.025f);
					Color val3 = Color.Lerp(new Color(0.24f, 0.68f, 0.32f), new Color(0.88f, 0.76f, 0.22f), Mathf.Clamp01(num13 * 0.7f));
					val3 = Color.Lerp(val3, new Color(0.75f, 0.28f, 0.18f), Mathf.Clamp01(num14 * 0.55f));
					val3.a = 0.07f + Mathf.Clamp01(num13 + num14) * 0.03f;
					array5[n * 128 + num12] = val3;
				}
			}
			texture.SetPixels(array5);
			texture.Apply();
			material = new Material(val)
			{
				name = "SIF very transparent green haze"
			};
			material.mainTexture = (Texture)(object)texture;
			material.SetFloat("_Mode", 2f);
			material.SetOverrideTag("RenderType", "Transparent");
			material.SetInt("_SrcBlend", 5);
			material.SetInt("_DstBlend", 10);
			material.SetInt("_ZWrite", 0);
			material.DisableKeyword("_ALPHATEST_ON");
			material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			material.EnableKeyword("_ALPHABLEND_ON");
			material.SetColor("_Color", Color.white);
			material.SetFloat("_Metallic", 0f);
			material.SetFloat("_Glossiness", 0f);
			material.renderQueue = 3000;
			root.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = root.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			root.transform.localScale = Vector3.one * num;
			return true;
		}

		private static float Spot(float u, float v, float x, float y, float width)
		{
			float num = Mathf.Min(Mathf.Abs(u - x), 1f - Mathf.Abs(u - x));
			float num2 = v - y;
			return Mathf.Exp((0f - (num * num + num2 * num2)) / (width * width));
		}

		internal void Dispose()
		{
			if (Object.op_Implicit((Object)(object)root))
			{
				Object.Destroy((Object)(object)root);
			}
			if (Object.op_Implicit((Object)(object)mesh))
			{
				Object.Destroy((Object)(object)mesh);
			}
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
			if (Object.op_Implicit((Object)(object)texture))
			{
				Object.Destroy((Object)(object)texture);
			}
			root = null;
			mesh = null;
			material = null;
			texture = null;
		}
	}
	[HarmonyPatch(typeof(Plant), "UpdateHealth")]
	internal static class CropClimate
	{
		internal struct Snapshot
		{
			internal bool Changed;

			internal bool Cold;

			internal Biome Biome;
		}

		[HarmonyPrefix]
		private static void Prefix(Plant __instance, out Snapshot __state)
		{
			//IL_0015: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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)
			__state = default(Snapshot);
			if (Object.op_Implicit((Object)(object)__instance) && SifAreas.Contains(((Component)__instance).transform.position))
			{
				__state = new Snapshot
				{
					Changed = true,
					Cold = __instance.m_tolerateCold,
					Biome = __instance.m_biome
				};
				__instance.m_biome = (Biome)(__instance.m_biome | 4);
				__instance.m_tolerateCold = true;
			}
		}

		[HarmonyFinalizer]
		private static void Finalizer(Plant __instance, Snapshot __state)
		{
			//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)
			if (__state.Changed && Object.op_Implicit((Object)(object)__instance))
			{
				__instance.m_biome = __state.Biome;
				__instance.m_tolerateCold = __state.Cold;
			}
		}
	}
	[HarmonyPatch(typeof(Plant), "HaveRoof")]
	internal static class CropRoofClimate
	{
		[HarmonyPrefix]
		private static bool Prefix(Plant __instance, ref bool __result)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)__instance) && SifAreas.Contains(((Component)__instance).transform.position))
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class GourdRoofClimate
	{
		private static MethodInfo Find()
		{
			return AccessTools.Method(AccessTools.TypeByName("SmeagsPumpkin.GourdVine"), "HasRoom", new Type[1] { typeof(int) }, (Type[])null);
		}

		private static bool Prepare()
		{
			return Find() != null;
		}

		private static MethodBase TargetMethod()
		{
			return Find();
		}

		private static bool RoofRay(Vector3 origin, Vector3 direction, float distance, int layer, QueryTriggerInteraction triggers)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (direction == Vector3.up && Math.Abs(distance - 8f) < 0.001f && SifAreas.Contains(origin))
			{
				return false;
			}
			return Physics.Raycast(origin, direction, distance, layer, triggers);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo ray = AccessTools.Method(typeof(Physics), "Raycast", new Type[5]
			{
				typeof(Vector3),
				typeof(Vector3),
				typeof(float),
				typeof(int),
				typeof(QueryTriggerInteraction)
			}, (Type[])null);
			CodeInstruction[] array = list.Where((CodeInstruction c) => CodeInstructionExtensions.Calls(c, ray)).ToArray();
			if (array.Length != 1)
			{
				Debug.LogWarning((object)"[SIF Green house] Gourd roof compatibility skipped: unknown HasRoom ray contract.");
				return list;
			}
			array[0].opcode = OpCodes.Call;
			array[0].operand = AccessTools.Method(typeof(GourdRoofClimate), "RoofRay", (Type[])null, (Type[])null);
			return list;
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class CropPlacementClimate
	{
		private static Biome AllowedBiomes(Piece piece)
		{
			//IL_0001: 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_0007: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Biome onlyInBiome = piece.m_onlyInBiome;
			if ((int)onlyInBiome == 0 || !Object.op_Implicit((Object)(object)((Component)piece).GetComponent<Plant>()) || !SifAreas.Contains(((Component)piece).transform.position))
			{
				return onlyInBiome;
			}
			return (Biome)(onlyInBiome | 4);
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo field = AccessTools.Field(typeof(Piece), "m_onlyInBiome");
			CodeInstruction[] array = list.Where((CodeInstruction c) => c.opcode == OpCodes.Ldfld && object.Equals(c.operand, field)).ToArray();
			if (array.Length != 2)
			{
				Logger.CreateLogSource("SIF Crop Placement").LogWarning((object)"Expected two Piece.m_onlyInBiome reads; greenhouse placement relaxation disabled for this game version.");
				return list;
			}
			MethodInfo operand = AccessTools.Method(typeof(CropPlacementClimate), "AllowedBiomes", (Type[])null, (Type[])null);
			CodeInstruction[] array2 = array;
			foreach (CodeInstruction obj in array2)
			{
				obj.opcode = OpCodes.Call;
				obj.operand = operand;
			}
			return list;
		}
	}
	internal static class LocalWeather
	{
		[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
		private static class PlayerWeatherPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Expected O, but got Unknown
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				MethodInfo methodInfo = AccessTools.Method(typeof(EnvMan), "IsCold", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(EnvMan), "IsFreezing", (Type[])null, (Type[])null);
				MethodInfo methodInfo3 = AccessTools.Method(typeof(EnvMan), "IsWet", (Type[])null, (Type[])null);
				int num = 0;
				foreach (CodeInstruction item in list)
				{
					if (CodeInstructionExtensions.Calls(item, methodInfo) || CodeInstructionExtensions.Calls(item, methodInfo2) || CodeInstructionExtensions.Calls(item, methodInfo3))
					{
						num++;
					}
				}
				if (num != 3)
				{
					Debug.LogWarning((object)"[SIF Green house] Player weather method changed; local exposure patch was not applied.");
					return list;
				}
				List<CodeInstruction> list2 = new List<CodeInstruction>();
				foreach (CodeInstruction item2 in list)
				{
					list2.Add(item2);
					if (CodeInstructionExtensions.Calls(item2, methodInfo) || CodeInstructionExtensions.Calls(item2, methodInfo2) || CodeInstructionExtensions.Calls(item2, methodInfo3))
					{
						list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
						list2.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocalWeather), "EnvironmentalExposure", (Type[])null, (Type[])null)));
					}
				}
				return list2;
			}
		}

		private static readonly FieldInfo CurrentParticles = AccessTools.Field(typeof(EnvMan), "m_currentPSystems");

		private static readonly FieldInfo CurrentEnvironment = AccessTools.Field(typeof(EnvMan), "m_currentEnv");

		private static readonly Dictionary<ParticleSystem, Particle[]> Buffers = new Dictionary<ParticleSystem, Particle[]>();

		private static GameObject[] LastRoots;

		private static float NextParticleCheck;

		private static bool VisualsFailed;

		private static bool BudgetWarning;

		private static readonly List<ParticleSystem> Systems = new List<ParticleSystem>();

		private static bool EnvironmentalExposure(bool nativeValue, Player player)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (nativeValue)
			{
				if (Object.op_Implicit((Object)(object)player))
				{
					return !SifAreas.Contains(((Component)player).transform.position);
				}
				return true;
			}
			return false;
		}

		internal static void TickVisuals()
		{
			if (VisualsFailed || Time.unscaledTime < NextParticleCheck)
			{
				return;
			}
			NextParticleCheck = Time.unscaledTime + 0.1f;
			try
			{
				CullParticles();
			}
			catch (Exception ex)
			{
				VisualsFailed = true;
				Debug.LogWarning((object)("[SIF Green house] Local precipitation filter disabled safely: " + ex.Message));
			}
		}

		private static void CullParticles()
		{
			//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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Invalid comparison between Unknown and I4
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Invalid comparison between Unknown and I4
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			if (!SifAreas.HasAny || !Object.op_Implicit((Object)(object)EnvMan.instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (CurrentParticles == null || CurrentEnvironment == null)
			{
				throw new MissingFieldException("Native weather particle fields changed.");
			}
			EnvSetup val = (EnvSetup)((CurrentEnvironment == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if (val == null || (!val.m_isWet && !val.m_isFreezing && !(val.m_snowBuildup > 0f)))
			{
				return;
			}
			GameObject[] array = ((CurrentParticles == null) ? null : (CurrentParticles.GetValue(EnvMan.instance) as GameObject[]));
			if (array != LastRoots)
			{
				Systems.Clear();
				Buffers.Clear();
				LastRoots = array;
				if (array != null)
				{
					GameObject[] array2 = array;
					foreach (GameObject val2 in array2)
					{
						if (Object.op_Implicit((Object)(object)val2))
						{
							Systems.AddRange(val2.GetComponentsInChildren<ParticleSystem>(true));
						}
					}
				}
			}
			int num = 32768;
			foreach (ParticleSystem system in Systems)
			{
				if (!Object.op_Implicit((Object)(object)system) || !((Component)system).gameObject.activeInHierarchy || system.particleCount == 0)
				{
					continue;
				}
				MainModule main = system.main;
				int particleCount = system.particleCount;
				if (particleCount > 16384 || particleCount > num)
				{
					if (!BudgetWarning)
					{
						BudgetWarning = true;
						Debug.LogWarning((object)"[SIF Green house] Large weather particle system skipped to preserve frame time and outside particles.");
					}
					continue;
				}
				num -= particleCount;
				if (!Buffers.TryGetValue(system, out var value) || value.Length < particleCount)
				{
					value = (Particle[])(object)new Particle[particleCount];
					Buffers[system] = value;
				}
				int particles = system.GetParticles(value);
				bool flag = false;
				Transform val3 = (((int)((MainModule)(ref main)).simulationSpace == 2) ? ((MainModule)(ref main)).customSimulationSpace : ((Component)system).transform);
				for (int j = 0; j < particles; j++)
				{
					Vector3 val4 = ((Particle)(ref value[j])).position;
					if ((int)((MainModule)(ref main)).simulationSpace != 1 && Object.op_Implicit((Object)(object)val3))
					{
						val4 = val3.TransformPoint(val4);
					}
					if (SifAreas.Intersects(val4, 0f) && SifAreas.Contains(val4))
					{
						((Particle)(ref value[j])).remainingLifetime = 0f;
						flag = true;
					}
				}
				if (flag)
				{
					system.SetParticles(value, particles);
				}
			}
		}

		internal static void Clear()
		{
			Buffers.Clear();
			Systems.Clear();
			LastRoots = null;
		}
	}
	internal static class NightGrowth
	{
		internal const string BonusKey = "sif_night_growth_bonus_v1";

		internal const float RadiusFraction = 0.35f;

		internal static ConfigEntry<float> BonusPercent;

		internal static readonly HashSet<NightGrowthState> States = new HashSet<NightGrowthState>();

		internal static Type GourdType { get; private set; }

		internal static MethodInfo GourdHasRoom { get; private set; }

		internal static float Rate
		{
			get
			{
				if (BonusPercent != null)
				{
					return Mathf.Clamp(BonusPercent.Value, 0f, 100f) * 0.01f;
				}
				return 0.2f;
			}
		}

		internal static void Bind(ConfigFile config)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			GourdType = AccessTools.TypeByName("SmeagsPumpkin.GourdVine");
			GourdHasRoom = ((GourdType == null) ? null : AccessTools.Method(GourdType, "HasRoom", new Type[1] { typeof(int) }, (Type[])null));
			BonusPercent = config.Bind<float>("Night growth", "BonusPercent", 20f, new ConfigDescription("Additional growth rate while a healthy loaded owned crop stays at night within the central 35% radius of an active Mountain SIF ward. 20 means 1.20x progress, not a 20% shorter duration. No offline bonus or stacking.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		}

		internal static bool Eligible(Vector3 p)
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Invalid comparison between Unknown and I4
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Stopping || !Object.op_Implicit((Object)(object)EnvMan.instance) || !EnvMan.IsNight() || Rate <= 0f)
			{
				return false;
			}
			Heightmap val = Heightmap.FindHeightmap(p);
			if (!Object.op_Implicit((Object)(object)val) || (int)val.GetBiome(p, 0.02f, false) != 4)
			{
				return false;
			}
			foreach (SifWard ward in SifAreas.Wards)
			{
				if (Object.op_Implicit((Object)(object)ward) && ward.Enabled && Object.op_Implicit((Object)(object)ward.Area))
				{
					Heightmap val2 = Heightmap.FindHeightmap(((Component)ward).transform.position);
					if (Object.op_Implicit((Object)(object)val2) && (int)val2.GetBiome(((Component)ward).transform.position, 0.02f, false) == 4 && Utils.DistanceXZ(p, ((Component)ward).transform.position) <= ward.Area.m_radius * 0.35f)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static bool Crop(Plant p)
		{
			if (!Object.op_Implicit((Object)(object)p) || p.m_grownPrefabs == null || Utils.GetPrefabName(((Component)p).gameObject) == "SmeagsPumpkin_SwampTowerVinePlant")
			{
				return false;
			}
			Type gourdType = GourdType;
			GameObject[] grownPrefabs = p.m_grownPrefabs;
			foreach (GameObject val in grownPrefabs)
			{
				if (Object.op_Implicit((Object)(object)val) && (Object.op_Implicit((Object)(object)val.GetComponent<Pickable>()) || (gourdType != null && Object.op_Implicit((Object)(object)val.GetComponent(gourdType)))))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool CultivatedGourd(Component c)
		{
			if (!Object.op_Implicit((Object)(object)c) || GourdType == null || ((object)c).GetType() != GourdType)
			{
				return false;
			}
			string prefabName = Utils.GetPrefabName(c.gameObject);
			switch (prefabName)
			{
			default:
				return prefabName == "SmeagsPumpkin_HoneynutVine";
			case "SmeagsPumpkin_PumpkinVine":
			case "SmeagsPumpkin_KabochaVine":
			case "SmeagsPumpkin_CrookneckVine":
				return true;
			}
		}

		internal static void Attach(Component c)
		{
			if (!Plugin.Stopping && Object.op_Implicit((Object)(object)c) && !Object.op_Implicit((Object)(object)c.GetComponent<NightGrowthState>()))
			{
				Plant val = (Plant)(object)((c is Plant) ? c : null);
				if ((val != null) ? Crop(val) : CultivatedGourd(c))
				{
					c.gameObject.AddComponent<NightGrowthState>();
				}
			}
		}

		internal static void Clear()
		{
			foreach (NightGrowthState item in new List<NightGrowthState>(States))
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					((MonoBehaviour)item).CancelInvoke();
					Object.Destroy((Object)(object)item);
				}
			}
			States.Clear();
		}

		internal static double Earned(Plant plant)
		{
			ZNetView val = (Object.op_Implicit((Object)(object)plant) ? ((Component)plant).GetComponent<ZNetView>() : null);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return 0.0;
			}
			float num = val.GetZDO().GetFloat("sif_night_growth_bonus_v1", 0f);
			return (float.IsNaN(num) || float.IsInfinity(num)) ? 0f : Math.Max(0f, num);
		}
	}
	internal sealed class NightGrowthState : MonoBehaviour
	{
		private Plant plant;

		private Component vine;

		private ZNetView view;

		private bool sampled;

		private bool previousEligible;

		private long previousOwner;

		private double previousWorld;

		private double previousReal;

		private float previousRate;

		private static readonly MethodInfo Status = AccessTools.Method(typeof(Plant), "GetStatus", (Type[])null, (Type[])null);

		private void Awake()
		{
			plant = ((Component)this).GetComponent<Plant>();
			Type gourdType = NightGrowth.GourdType;
			vine = ((gourdType == null) ? null : ((Component)this).GetComponent(gourdType));
			view = ((Component)this).GetComponent<ZNetView>();
			NightGrowth.States.Add(this);
		}

		private void OnEnable()
		{
			sampled = false;
			((MonoBehaviour)this).InvokeRepeating("Sample", 0.5f, 0.5f);
		}

		private void OnDisable()
		{
			((MonoBehaviour)this).CancelInvoke();
			sampled = false;
		}

		private void OnDestroy()
		{
			NightGrowth.States.Remove(this);
		}

		internal void Sample()
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				sampled = false;
			}
			else
			{
				Step((double)ZNet.instance.GetTime().Ticks / 10000000.0, Time.realtimeSinceStartupAsDouble);
			}
		}

		internal void Step(double world, double real)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Stopping || !Object.op_Implicit((Object)(object)view) || !view.IsValid() || !view.IsOwner())
			{
				sampled = false;
				return;
			}
			ZDO zDO = view.GetZDO();
			long owner = zDO.GetOwner();
			bool flag = NightGrowth.Eligible(((Component)this).transform.position) && Healthy(zDO);
			float rate = NightGrowth.Rate;
			double num = world - previousWorld;
			double num2 = real - previousReal;
			if (sampled && owner == previousOwner && previousEligible && flag && num > 0.0 && num2 > 0.0 && num2 <= 2.5)
			{
				float num3 = (float)(Math.Min(num, num2 * 1.1 + 0.05) * (double)Math.Min(previousRate, rate));
				if (num3 > 0f && !float.IsNaN(num3) && !float.IsInfinity(num3))
				{
					string text = (Object.op_Implicit((Object)(object)plant) ? "sif_night_growth_bonus_v1" : "sgg_vine_progress");
					float num4 = zDO.GetFloat(text, 0f);
					if (!float.IsNaN(num4) && !float.IsInfinity(num4))
					{
						zDO.Set(text, Mathf.Min(1E+09f, Mathf.Max(0f, num4) + num3));
					}
				}
			}
			sampled = true;
			previousOwner = owner;
			previousEligible = flag;
			previousWorld = world;
			previousReal = real;
			previousRate = rate;
		}

		private bool Healthy(ZDO z)
		{
			if (Object.op_Implicit((Object)(object)plant))
			{
				if (!NightGrowth.Crop(plant) || Status == null)
				{
					return false;
				}
				return string.Equals(Status.Invoke(plant, null)?.ToString(), "Healthy", StringComparison.Ordinal);
			}
			if (!NightGrowth.CultivatedGourd(vine) || !z.GetBool("sgg_vine_init", false))
			{
				return false;
			}
			int num = z.GetInt("sgg_vine_capacity", 0);
			int num2 = z.GetInt("sgg_vine_stage", 0);
			int num3 = z.GetInt("sgg_vine_picked", 0);
			if (num < 1 || num2 < 1 || num2 >= num || (num3 & ((1 << num) - 1)) == (1 << num) - 1 || z.GetInt("sgg_vine_started", num2) < num2 + 1)
			{
				return false;
			}
			MethodInfo gourdHasRoom = NightGrowth.GourdHasRoom;
			if (gourdHasRoom != null)
			{
				return (bool)gourdHasRoom.Invoke(vine, new object[1] { num2 + 1 });
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Plant), "Awake")]
	internal static class NightPlantAttach
	{
		private static void Postfix(Plant __instance)
		{
			NightGrowth.Attach((Component)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(Plant), "TimeSincePlanted")]
	internal static class NightPlantElapsed
	{
		private static void Postfix(Plant __instance, ref double __result)
		{
			if (!Plugin.Stopping && NightGrowth.Crop(__instance))
			{
				NightGrowth.Attach((Component)(object)__instance);
				__result += NightGrowth.Earned(__instance);
			}
		}
	}
	[HarmonyPatch]
	internal static class NightGourdAttach
	{
		private static MethodInfo Find()
		{
			return AccessTools.Method(NightGrowth.GourdType, "Awake", (Type[])null, (Type[])null);
		}

		private static bool Prepare()
		{
			return Find() != null;
		}

		private static MethodBase TargetMethod()
		{
			return Find();
		}

		private static void Postfix(Component __instance)
		{
			NightGrowth.Attach(__instance);
		}
	}
	[BepInPlugin("swiggs.SifGreenhouse", "SIF Green house", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private Harmony harmony;

		internal static bool Stopping;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Stopping = false;
			NightGrowth.Bind(((BaseUnityPlugin)this).Config);
			harmony = new Harmony("swiggs.SifGreenhouse");
			harmony.PatchAll();
		}

		private void LateUpdate()
		{
			if (!Stopping)
			{
				LocalWeather.TickVisuals();
			}
		}

		private void OnDestroy()
		{
			Stopping = true;
			NightGrowth.Clear();
			foreach (SifWard ward in SifAreas.Wards)
			{
				if (Object.op_Implicit((Object)(object)ward))
				{
					((MonoBehaviour)ward).CancelInvoke();
					ward.ClearBoundary();
				}
			}
			LocalWeather.Clear();
			TerrainVisuals.RestoreAll();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	public sealed class SifWard : MonoBehaviour
	{
		internal PrivateArea Area;

		private ZNetView view;

		private bool previous;

		internal readonly BoundaryVisuals Boundary = new BoundaryVisuals();

		internal readonly WardSunlight Sunlight = new WardSunlight();

		internal bool Enabled
		{
			get
			{
				if (Object.op_Implicit((Object)(object)view) && view.IsValid())
				{
					return view.GetZDO().GetBool(ZDOVars.s_enabled, false);
				}
				return false;
			}
		}

		internal void ClearBoundary()
		{
			Boundary.Dispose();
			Sunlight.Dispose();
		}

		private void Awake()
		{
			Area = ((Component)this).GetComponent<PrivateArea>();
			view = ((Component)this).GetComponent<ZNetView>();
			SifAreas.Wards.Add(this);
			((MonoBehaviour)this).InvokeRepeating("Check", 0.25f, 0.25f);
		}

		private void Check()
		{
			if (!Plugin.Stopping)
			{
				bool enabled = Enabled;
				Boundary.Sync(this);
				Sunlight.Sync(this);
				if (enabled != previous)
				{
					previous = enabled;
					TerrainVisuals.Refresh();
				}
			}
		}

		private void OnDestroy()
		{
			((MonoBehaviour)this).CancelInvoke();
			Boundary.Dispose();
			Sunlight.Dispose();
			SifAreas.Wards.Remove(this);
			if (!Plugin.Stopping)
			{
				TerrainVisuals.Refresh();
			}
		}
	}
	internal static class SifAreas
	{
		internal static readonly List<SifWard> Wards = new List<SifWard>();

		internal static bool HasAny
		{
			get
			{
				if (Plugin.Stopping)
				{
					return false;
				}
				foreach (SifWard ward in Wards)
				{
					if (Object.op_Implicit((Object)(object)ward) && ward.Enabled)
					{
						return true;
					}
				}
				return false;
			}
		}

		internal static bool Intersects(Vector3 p, float radius)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Stopping)
			{
				return false;
			}
			foreach (SifWard ward in Wards)
			{
				if (Object.op_Implicit((Object)(object)ward) && ward.Enabled && Utils.DistanceXZ(((Component)ward).transform.position, p) < ward.Area.m_radius + radius)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool Contains(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if (!Intersects(p, 0f))
			{
				return false;
			}
			Heightmap val = Heightmap.FindHeightmap(p);
			if (Object.op_Implicit((Object)(object)val))
			{
				return (int)val.GetBiome(p, 0.02f, false) == 4;
			}
			return false;
		}
	}
	internal static class Registration
	{
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class Scene
		{
			private static void Postfix(ZNetScene __instance, Dictionary<int, GameObject> ___m_namedPrefabs)
			{
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Expected O, but got Unknown
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: 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_019d: Expected O, but got Unknown
				//IL_019f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ba: Expected O, but got Unknown
				GameObject prefab = __instance.GetPrefab("guard_stone");
				if (!Object.op_Implicit((Object)(object)prefab))
				{
					throw new InvalidOperationException("SIF: native ward template missing");
				}
				Piece component = prefab.GetComponent<Piece>();
				GameObject prefab2 = __instance.GetPrefab("AncientSeed");
				ItemDrop val = ((prefab2 != null) ? prefab2.GetComponent<ItemDrop>() : null);
				GameObject prefab3 = __instance.GetPrefab("TrinketBronzeHealth");
				ItemDrop val2 = ((prefab3 != null) ? prefab3.GetComponent<ItemDrop>() : null);
				if (!Object.op_Implicit((Object)(object)component) || component.m_resources == null || component.m_resources.Any((Requirement r) => r == null || !Object.op_Implicit((Object)(object)r.m_resItem)) || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
				{
					Debug.LogError((object)"[SIF Green house] Required native ward costs, AncientSeed or Heart of the Forest (TrinketBronzeHealth) unavailable. SIF registration disabled rather than using a cheaper recipe.");
					return;
				}
				GameObject val3 = new GameObject("SIF Prefab Storage");
				val3.SetActive(false);
				val3.transform.SetParent(((Component)__instance).transform, false);
				GameObject val4 = Object.Instantiate<GameObject>(prefab, val3.transform, false);
				((Object)val4).name = "SIF_GreenhouseWard";
				SifSceneResources resources = ((Component)__instance).gameObject.AddComponent<SifSceneResources>();
				PrivateArea component2 = val4.GetComponent<PrivateArea>();
				component2.m_name = "Sif's greenhouse";
				component2.m_radius = 12f;
				component2.m_enabledByDefault = false;
				Piece component3 = val4.GetComponent<Piece>();
				component3.m_name = "Sif's greenhouse";
				component3.m_description = "Activate Sif's blessing to grow crops in the Mountains. 12m radius. Cultivated soil and spacing still required; roofs are sheltered. Central 4.2m gains 20% faster growth at night by default. Snow visuals return when disabled. All players need this mod.";
				component3.m_icon = MakeIcon(resources);
				component3.m_resources = ((IEnumerable<Requirement>)component.m_resources).Select((Func<Requirement, Requirement>)((Requirement r) => new Requirement
				{
					m_resItem = r.m_resItem,
					m_amount = r.m_amount,
					m_amountPerLevel = r.m_amountPerLevel,
					m_extraAmountOnlyOneIngredient = r.m_extraAmountOnlyOneIngredient,
					m_upgraderResource = r.m_upgraderResource,
					m_recover = r.m_recover
				})).Concat((IEnumerable<Requirement>)(object)new Requirement[2]
				{
					new Requirement
					{
						m_resItem = val,
						m_amount = 3,
						m_recover = true
					},
					new Requirement
					{
						m_resItem = val2,
						m_amount = 1,
						m_recover = true
					}
				}).ToArray();
				SifArt.Build(val4, component2, resources);
				val4.AddComponent<SifWard>();
				val4.SetActive(true);
				Prefab = val4;
				__instance.m_prefabs.Add(val4);
				___m_namedPrefabs.Add(StringExtensionMethods.GetStableHashCode(((Object)val4).name), val4);
				Hammer();
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class DB
		{
			private static void Postfix()
			{
				Hammer();
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class Copy
		{
			private static void Postfix()
			{
				Hammer();
			}
		}

		internal static GameObject Prefab;

		private static Sprite MakeIcon(SifSceneResources resources)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			using Stream stream = typeof(Registration).Assembly.GetManifestResourceStream("SifGreenhouse.build-menu-icon.png");
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = resources.Own<Texture2D>(new Texture2D(2, 2, (TextureFormat)4, false));
			if (!(bool)AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[3]
			{
				typeof(Texture2D),
				typeof(byte[]),
				typeof(bool)
			}, (Type[])null).Invoke(null, new object[3] { val, array, false }))
			{
				return null;
			}
			return resources.Own<Sprite>(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f));
		}

		private static Requirement Cost(ZNetScene s, string id, int amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			return new Requirement
			{
				m_resItem = s.GetPrefab(id).GetComponent<ItemDrop>(),
				m_amount = amount,
				m_recover = true
			};
		}

		private static void Hammer()
		{
			ObjectDB instance = ObjectDB.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				GameObject itemPrefab = instance.GetItemPrefab("Hammer");
				obj = ((itemPrefab == null) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces);
			}
			PieceTable val = (PieceTable)obj;
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)Prefab) && !val.m_pieces.Contains(Prefab))
			{
				val.m_pieces.Add(Prefab);
			}
		}
	}
	internal sealed class SifSceneResources : MonoBehaviour
	{
		private readonly List<Object> owned = new List<Object>();

		internal T Own<T>(T asset) where T : Object
		{
			if (Object.op_Implicit((Object)(object)asset))
			{
				owned.Add((Object)(object)asset);
			}
			return asset;
		}

		private void OnDestroy()
		{
			foreach (Object item in owned)
			{
				if (Object.op_Implicit(item))
				{
					Object.Destroy(item);
				}
			}
			owned.Clear();
		}
	}
	internal static class SifArt
	{
		private sealed class Surface
		{
			internal List<Vector3> v = new List<Vector3>();

			internal List<Vector3> n = new List<Vector3>();

			internal List<Vector2> uv = new List<Vector2>();

			internal List<int>[] triangles;

			internal Surface(int count)
			{
				triangles = (from i in Enumerable.Range(0, count)
					select new List<int>()).ToArray();
			}

			internal void Add(Vector3 a, Vector3 b, Vector3 c, Vector3 na, Vector3 nb, Vector3 nc, Vector2 ua, Vector2 ub, Vector2 uc, int sub, bool recalc)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: 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_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				int count = v.Count;
				v.Add(a);
				v.Add(b);
				v.Add(c);
				uv.Add(ua);
				uv.Add(ub);
				uv.Add(uc);
				if (recalc)
				{
					Vector3 val = Vector3.Cross(b - a, c - a);
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					n.Add(normalized);
					n.Add(normalized);
					n.Add(normalized);
				}
				else
				{
					n.Add(na);
					n.Add(nb);
					n.Add(nc);
				}
				triangles[sub].Add(count);
				triangles[sub].Add(count + 1);
				triangles[sub].Add(count + 2);
			}
		}

		private static bool In(Vector2 p, float a, float b, float c, float d)
		{
			//IL_0000: 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_0012: 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)
			if (p.x >= a && p.x <= c && p.y >= b)
			{
				return p.y <= d;
			}
			return false;
		}

		private static bool Face(Vector2 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_007c: 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_00b7: 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_00ef: 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)
			if (!In(p, 0.643f, 0.701f, 0.812f, 0.822f) && !In(p, 0.831f, 0.026f, 0.915f, 0.161f) && !In(p, 0.837f, 0.826f, 0.929f, 0.891f) && !In(p, 0.511f, 0.896f, 0.581f, 0.988f) && !In(p, 0.881f, 0.216f, 0.915f, 0.259f) && !In(p, 0.929f, 0.215f, 0.963f, 0.258f) && !In(p, 0.84f, 0.936f, 0.855f, 0.967f) && !In(p, 0.91f, 0.936f, 0.923f, 0.965f) && !In(p, 0.027f, 0.937f, 0.036f, 0.953f))
			{
				return In(p, 0.09f, 0.937f, 0.094f, 0.954f);
			}
			return true;
		}

		private static bool BeardSeam(Vector2 p)
		{
			//IL_0000: 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)
			if (!In(p, 0.942f, 0.418f, 0.951f, 0.48f))
			{
				return In(p, 0.942f, 0.535f, 0.951f, 0.597f);
			}
			return true;
		}

		private static bool ReplaceTriangle(Vector3[] v, Vector2[] uv, int a, int b, int c, int sub)
		{
			//IL_0002: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0086: 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_00a0: 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_00ba: 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_00cd: 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_00ec: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			if (Face(uv[a]) && Face(uv[b]) && Face(uv[c]))
			{
				return true;
			}
			Vector3 val = v[a];
			Vector3 val2 = v[b];
			Vector3 val3 = v[c];
			if (val.y >= 0.98f && val2.y >= 0.98f && val3.y >= 0.98f && val.y <= 1.95f && val2.y <= 1.95f && val3.y <= 1.95f && val.z > 0.15f && val2.z > 0.15f && val3.z > 0.15f && (val.z + val2.z + val3.z) / 3f > 0.2f)
			{
				if (sub == 0)
				{
					return Mathf.Min(val.y, Mathf.Min(val2.y, val3.y)) > 1.1f;
				}
				return true;
			}
			return false;
		}

		private static bool Hood(Vector2 p)
		{
			//IL_0000: 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)
			if (!In(p, 0.474f, 0.027f, 0.598f, 0.245f))
			{
				return In(p, 0.652f, 0.027f, 0.776f, 0.245f);
			}
			return true;
		}

		private static Vector3Int Key(Vector3 p)
		{
			//IL_0000: 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_0022: 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)
			return new Vector3Int(Mathf.RoundToInt(p.x * 10000f), Mathf.RoundToInt(p.y * 10000f), Mathf.RoundToInt(p.z * 10000f));
		}

		private unsafe static string Edge(Vector3Int a, Vector3Int b)
		{
			string text = ((object)(*(Vector3Int*)(&a))/*cast due to .constrained prefix*/).ToString();
			string text2 = ((object)(*(Vector3Int*)(&b))/*cast due to .constrained prefix*/).ToString();
			if (string.CompareOrdinal(text, text2) >= 0)
			{
				return text2 + "/" + text;
			}
			return text + "/" + text2;
		}

		private static Vector2 WoodUV(Vector3 p)
		{
			//IL_0005: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(0.29f + p.x * 0.07f, 0.57f + Mathf.Clamp01((p.y - 0.94f) / 1.34f) * 0.17f);
		}

		private static float RobeDepth(Vector3 p)
		{
			//IL_000a: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			return 0.52f - 0.1f * (p.y - 1f) - 0.4f * p.x * p.x;
		}

		private static Vector3 Chest(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0029: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (p.y < 0.95f || p.y > 1.82f || p.z < 0.24f)
			{
				return p;
			}
			float num = Mathf.Clamp01((p.y - 0.95f) / 0.16f) * Mathf.Clamp01((1.82f - p.y) / 0.16f) * Mathf.Clamp01((0.52f - Mathf.Abs(p.x)) / 0.16f) * Mathf.Clamp01((p.z - 0.24f) / 0.07f);
			p.z = Mathf.Lerp(p.z, RobeDepth(p), num);
			return p;
		}

		private static float Cut(Vector3 p)
		{
			//IL_0000: 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_0044: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Exp(0f - Mathf.Pow((Mathf.Abs(p.x) - 0.098f) / 0.043f, 4f) - Mathf.Pow((p.y - 2.125f) / 0.014f, 2f));
			float num2 = Mathf.Exp(0f - Mathf.Pow(p.x / 0.069f, 6f) - Mathf.Pow((p.y - (1.968f + 0.01f * Mathf.Pow(p.x / 0.07f, 2f))) / 0.009f, 2f));
			return Mathf.Max(num, num2);
		}

		private static float Brooch(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			float x = p.x;
			float num = p.y - 1.48f;
			float num2 = Mathf.Sqrt(x * x + num * num);
			float num3 = Mathf.Clamp01((0.027f - Mathf.Abs(num2 - 0.132f)) / 0.008f);
			if (num < -0.065f && Mathf.Abs(x) < 0.073f)
			{
				num3 = 0f;
			}
			float num4 = 0f;
			for (int i = -1; i <= 1; i += 2)
			{
				float num5 = Mathf.Max(Mathf.Abs(x - (float)i * 0.098f), Mathf.Abs(num + 0.093f));
				num4 = Mathf.Max(num4, Mathf.Clamp01((0.034f - num5) / 0.008f));
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(-0.19f, -0.15f);
			Vector2 val2 = new Vector2(0.105f, 0.108f) - val;
			Vector2 val3 = new Vector2(x, num) - val;
			float num6 = Vector2.Dot(val3, val2) / ((Vector2)(ref val2)).sqrMagnitude;
			float num7 = 0f;
			if (num6 >= 0f && num6 <= 1f)
			{
				Vector2 val4 = val3 - val2 * num6;
				float magnitude = ((Vector2)(ref val4)).magnitude;
				num7 = Mathf.Clamp01((Mathf.Lerp(0.001f, 0.019f, num6) - magnitude) / 0.006f);
			}
			float num8 = Mathf.Clamp01((0.03f - Mathf.Max(Mathf.Abs(x - 0.105f), Mathf.Abs(num - 0.108f))) / 0.008f);
			return Mathf.Max(num3, Mathf.Max(num4, Mathf.Max(num7, num8)));
		}

		private static float VisageDepth(Vector3 p)
		{
			//IL_0000: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0050: 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_00e1: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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)
			if (p.y < 1.7f)
			{
				return RobeDepth(p) + 0.008f * Brooch(p);
			}
			float num = Mathf.Clamp01(1f - Mathf.Pow(p.x / 0.235f, 2f));
			float num2 = ((p.y < 1.86f) ? Mathf.Lerp(0.34f, 0.402f, (p.y - 1.78f) / 0.08f) : ((p.y < 2.08f) ? Mathf.Lerp(0.402f, 0.423f, (p.y - 1.86f) / 0.22f) : Mathf.Lerp(0.423f, 0.35f, (p.y - 2.08f) / 0.19f)));
			float num3 = 0.071f * Mathf.Exp(0f - Mathf.Pow(p.x / 0.032f, 2f) - Mathf.Pow((p.y - 2.065f) / 0.065f, 2f));
			float num4 = 0.008f * Mathf.Exp(0f - Mathf.Pow((Mathf.Abs(p.x) - 0.095f) / 0.055f, 2f) - Mathf.Pow((p.y - 2.168f) / 0.018f, 2f));
			float num5 = 0.29f + (num2 - 0.29f) * Mathf.Sqrt(num) + num3 + num4 - 0.017f * Cut(p);
			if (!(p.y < 1.86f))
			{
				return num5;
			}
			return Mathf.Lerp(RobeDepth(p), num5, Mathf.SmoothStep(0f, 1f, (p.y - 1.7f) / 0.16f));
		}

		private static float HairCut(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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)
			if (p.z < 0.245f || p.y < 1.47f || p.y > 2.25f)
			{
				return 0f;
			}
			float num = (2.25f - p.y) / 0.78f;
			float num2 = 0.3f + 0.075f * Mathf.Sin(num * (float)Math.PI * 0.8f);
			float num3 = 0.038f * Mathf.Sin(num * (float)Math.PI * 7f);
			float num4 = Mathf.Min(Mathf.Abs(Mathf.Abs(p.x) - (num2 + num3)), Mathf.Abs(Mathf.Abs(p.x) - (num2 - num3)));
			return Mathf.Clamp01(1f - num4 / 0.015f) * Mathf.Clamp01(num * 12f) * Mathf.Clamp01((1f - num) * 12f);
		}

		private static float Cross(Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0028: 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)
			return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
		}

		private static double Quality(Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0051: 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)
			double num = (double)b.x - (double)a.x;
			double num2 = (double)b.y - (double)a.y;
			double num3 = (double)c.x - (double)a.x;
			double num4 = (double)c.y - (double)a.y;
			double num5 = (double)c.x - (double)b.x;
			double num6 = (double)c.y - (double)b.y;
			return Math.Abs(num * num4 - num2 * num3) / (num * num + num2 * num2 + num3 * num3 + num4 * num4 + num5 * num5 + num6 * num6);
		}

		private static List<int> Triangulate(List<Vector3> polygon)
		{
			//IL_0089: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: 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_00f8: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: 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_015f: 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)
			List<int> list = Enumerable.Range(0, polygon.Count).ToList();
			List<int[]> list2 = new List<int[]>();
			int num = 0;
			while (list.Count > 2 && num++ < 1000)
			{
				int num2 = -1;
				double num3 = -1.0;
				int[] item = null;
				for (int i = 0; i < list.Count; i++)
				{
					int num4 = list[(i + list.Count - 1) % list.Count];
					int num5 = list[i];
					int num6 = list[(i + 1) % list.Count];
					if (Cross(polygon[num4], polygon[num5], polygon[num6]) <= 1E-07f)
					{
						continue;
					}
					bool flag = false;
					foreach (int item2 in list)
					{
						if (item2 != num4 && item2 != num5 && item2 != num6)
						{
							Vector3 c = polygon[item2];
							if (Cross(polygon[num4], polygon[num5], c) >= 0f && Cross(polygon[num5], polygon[num6], c) >= 0f && Cross(polygon[num6], polygon[num4], c) >= 0f)
							{
								flag = true;
								break;
							}
						}
					}
					if (!flag)
					{
						double num7 = Quality(polygon[num4], polygon[num5], polygon[num6]);
						if (num7 > num3)
						{
							num3 = num7;
							num2 = i;
							item = new int[3] { num4, num5, num6 };
						}
					}
				}
				if (num2 < 0)
				{
					throw new InvalidOperationException("SIF facial boundary could not be triangulated safely");
				}
				list2.Add(item);
				list.RemoveAt(num2);
			}
			int num8 = 0;
			for (int j = 0; j < 1000; j++)
			{
				Dictionary<ulong, List<int>> dictionary = new Dictionary<ulong, List<int>>();
				for (int k = 0; k < list2.Count; k++)
				{
					for (int l = 0; l < 3; l++)
					{
						uint val = (uint)list2[k][l];
						uint val2 = (uint)list2[k][(l + 1) % 3];
						ulong key = ((ulong)Math.Min(val, val2) << 32) | Math.Max(val, val2);
						if (!dictionary.TryGetValue(key, out var value))
						{
							value = (dictionary[key] = new List<int>());
						}
						value.Add(k);
					}
				}
				bool flag2 = false;
				foreach (KeyValuePair<ulong, List<int>> item3 in dictionary)
				{
					if (item3.Value.Count != 2)
					{
						continue;
					}
					int a = (int)(item3.Key >> 32);
					int b = (int)(item3.Key & 0xFFFFFFFFu);
					int index = item3.Value[0];
					int index2 = item3.Value[1];
					int num9 = list2[index].First((int x) => x != a && x != b);
					int num10 = list2[index2].First((int x) => x != a && x != b);
					if (!(Cross(polygon[num9], polygon[num10], polygon[a]) * Cross(polygon[num9], polygon[num10], polygon[b]) >= 0f))
					{
						double num11 = Math.Min(Quality(polygon[a], polygon[b], polygon[num9]), Quality(polygon[a], polygon[b], polygon[num10]));
						if (!(Math.Min(Quality(polygon[num9], polygon[num10], polygon[a]), Quality(polygon[num9], polygon[num10], polygon[b])) <= num11 + 1E-07))
						{
							list2[index] = ((!(Cross(polygon[num9], polygon[num10], polygon[a]) > 0f)) ? new int[3] { num9, a, num10 } : new int[3] { num9, num10, a });
							list2[index2] = ((!(Cross(polygon[num10], polygon[num9], polygon[b]) > 0f)) ? new int[3] { num10, b, num9 } : new int[3] { num10, num9, b });
							num8++;
							flag2 = true;
							break;
						}
					}
				}
				if (!flag2)
				{
					break;
				}
			}
			Debug.Log((object)("[SIF Green house] Carving triangulation quality min=" + list2.Min((int[] t) => Quality(polygon[t[0]], polygon[t[1]], polygon[t[2]])) + ", improving flips=" + num8));
			return list2.SelectMany((int[] t) => t).ToList();
		}

		private static Material Wood(Material source, Color tint, string name, SifSceneResources resources)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0027: 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)
			Material val = resources.Own<Material>(new Material(source));
			((Object)val).name = name;
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", tint);
			}
			if (val.HasProperty("_EmissionMap"))
			{
				val.SetTexture("_EmissionMap", (Texture)null);
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", Color.black);
			}
			val.DisableKeyword("_EMISSION");
			return val;
		}

		internal static void Build(GameObject go, PrivateArea area, SifSceneResources resources)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_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_0130: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_016e: 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_01a5: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_0767: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_0786: Unknown result type (might be due to invalid IL or missing references)
			//IL_078d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0794: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_0825: Unknown result type (might be due to invalid IL or missing references)
			//IL_082a: Unknown result type (might be due to invalid IL or missing references)
			//IL_082f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0833: Unknown result type (might be due to invalid IL or missing references)
			//IL_083f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0841: Unknown result type (might be due to invalid IL or missing references)
			//IL_0850: Unknown result type (might be due to invalid IL or missing references)
			//IL_0855: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_089b: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0919: Unknown result type (might be due to invalid IL or missing references)
			//IL_091e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0922: Unknown result type (might be due to invalid IL or missing references)
			//IL_0934: Unknown result type (might be due to invalid IL or missing references)
			//IL_0983: Unknown result type (might be due to invalid IL or missing references)
			//IL_099e: Unknown result type (might be due to invalid IL or missing references)
			//IL_09bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0953: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a80: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a99: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ace: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aeb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0afa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b31: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b67: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b71: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b80: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c46: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e34: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e49: Expected O, but got Unknown
			//IL_0eec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f1e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f40: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f62: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f9b: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer model = area.m_model;
			if (!Object.op_Implicit((Object)(object)model))
			{
				return;
			}
			MeshFilter component = ((Component)model).GetComponent<MeshFilter>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh) || ((Renderer)model).sharedMaterials.Length < 2)
			{
				return;
			}
			Mesh sharedMesh = component.sharedMesh;
			Vector3[] v = sharedMesh.vertices;
			Vector2[] uv = sharedMesh.uv;
			Vector3[] normals = sharedMesh.normals;
			if (v.Length != uv.Length || normals.Length != v.Length)
			{
				return;
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Dictionary<string, Vector3Int[]> dictionary2 = new Dictionary<string, Vector3Int[]>();
			Dictionary<Vector3Int, Vector3> dictionary3 = new Dictionary<Vector3Int, Vector3>();
			int num = 0;
			for (int i = 0; i < sharedMesh.subMeshCount; i++)
			{
				int[] triangles = sharedMesh.GetTriangles(i);
				for (int j = 0; j < triangles.Length; j += 3)
				{
					bool flag = ReplaceTriangle(v, uv, triangles[j], triangles[j + 1], triangles[j + 2], i);
					if (flag)
					{
						num++;
					}
					for (int k = 0; k < 3; k++)
					{
						Vector3Int val = Key(v[triangles[j + k]]);
						Vector3Int val2 = Key(v[triangles[j + (k + 1) % 3]]);
						dictionary3[val] = v[triangles[j + k]];
						dictionary3[val2] = v[triangles[j + (k + 1) % 3]];
						string key = Edge(val, val2);
						dictionary.TryGetValue(key, out var value);
						dictionary[key] = value | (flag ? 1 : 2);
						dictionary2[key] = (Vector3Int[])(object)new Vector3Int[2] { val, val2 };
					}
				}
			}
			if (num != 312)
			{
				Debug.LogWarning((object)"[SIF Green house] Native full-face layout changed; preserving vanilla artwork.");
				return;
			}
			Dictionary<Vector3Int, List<Vector3Int>> dictionary4 = new Dictionary<Vector3Int, List<Vector3Int>>();
			foreach (KeyValuePair<string, int> item in dictionary)
			{
				if (item.Value != 3)
				{
					continue;
				}
				Vector3Int[] array = dictionary2[item.Key];
				Vector3Int[] array2 = array;
				foreach (Vector3Int key2 in array2)
				{
					if (!dictionary4.ContainsKey(key2))
					{
						dictionary4[key2] = new List<Vector3Int>();
					}
				}
				dictionary4[array[0]].Add(array[1]);
				dictionary4[array[1]].Add(array[0]);
			}
			if (dictionary4.Count != 56 || dictionary4.Any((KeyValuePair<Vector3Int, List<Vector3Int>> p) => p.Value.Count != 2))
			{
				Debug.LogWarning((object)"[SIF Green house] Facial boundary invalid; preserving vanilla artwork.");
				return;
			}
			List<Vector3> ordered = new List<Vector3>();
			Vector3Int val3 = dictionary4.Keys.First();
			Vector3Int val4 = val3;
			Vector3Int previous = new Vector3Int(int.MinValue, 0, 0);
			do
			{
				ordered.Add(Chest(dictionary3[val4]));
				Vector3Int val5 = dictionary4[val4].First((Vector3Int p) => p != previous);
				previous = val4;
				val4 = val5;
				if (ordered.Count > 56)
				{
					return;
				}
			}
			while (val4 != val3);
			float num2 = 0f;
			for (int num3 = 0; num3 < ordered.Count; num3++)
			{
				Vector3 val6 = ordered[num3];
				Vector3 val7 = ordered[(num3 + 1) % ordered.Count];
				num2 += val6.x * val7.y - val7.x * val6.y;
			}
			if (num2 < 0f)
			{
				ordered.Reverse();
			}
			List<int> list;
			try
			{
				list = Triangulate(ordered);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[SIF Green house] " + ex.Message));
				return;
			}
			Surface output = new Surface(sharedMesh.subMeshCount + 4);
			int goldIndex = sharedMesh.subMeshCount;
			int faceIndex = goldIndex + 1;
			int darkIndex = goldIndex + 2;
			int robeIndex = goldIndex + 3;
			for (int sub = 0; sub < sharedMesh.subMeshCount; sub++)
			{
				int[] triangles2 = sharedMesh.GetTriangles(sub);
				for (int num4 = 0; num4 < triangles2.Length; num4 += 3)
				{
					int ia = triangles2[num4];
					int ib = triangles2[num4 + 1];
					int ic = triangles2[num4 + 2];
					if (ReplaceTriangle(v, uv, ia, ib, ic, sub))
					{
						continue;
					}
					bool hood = Hood(uv[ia]) && Hood(uv[ib]) && Hood(uv[ic]);
					bool seam = BeardSeam(uv[ia]) && BeardSeam(uv[ib]) && BeardSeam(uv[ic]);
					int divisions = ((!hood) ? 1 : 8);
					Func<Vector3, Vector3> position = delegate(Vector3 w)
					{
						//IL_0016: Unknown result type (might be due to invalid IL or missing references)
						//IL_001b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0020: Unknown result type (might be due to invalid IL or missing references)
						//IL_0026: 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_0046: 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_0051: Unknown result type (might be due to invalid IL or missing references)
						//IL_0056: Unknown result type (might be due to invalid IL or missing references)
						//IL_0071: Unknown result type (might be due to invalid IL or missing references)
						//IL_0076: Unknown result type (might be due to invalid IL or missing references)
						//IL_007b: Unknown result type (might be due to invalid IL or missing references)
						//IL_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_008b: Unknown result type (might be due to invalid IL or missing references)
						//IL_015b: 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_00ae: 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_00b9: 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)
						//IL_00df: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
						//IL_00ff: 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_010a: 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_0114: Unknown result type (might be due to invalid IL or missing references)
						//IL_0117: Unknown result type (might be due to invalid IL or missing references)
						//IL_011c: Unknown result type (might be due to invalid IL or missing references)
						//IL_0128: 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_0150: 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)
						Vector3 val23 = Chest(v[ia]) * w.x + Chest(v[ib]) * w.y + Chest(v[ic]) * w.z;
						if (hood)
						{
							Vector3 val24 = val23;
							Vector3 val25 = normals[ia] * w.x + normals[ib] * w.y + normals[ic] * w.z;
							val23 = val24 - ((Vector3)(ref val25)).normalized * (HairCut(val23) * 0.014f * Mathf.Clamp01(Mathf.Min(w.x, Mathf.Min(w.y, w.z)) * 24f));
						}
						return val23;
					};
					Action<Vector3, Vector3, Vector3> emit = delegate(Vector3 arg, Vector3 arg2, Vector3 arg3)
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						//IL_0013: Unknown result type (might be due to invalid IL or missing references)
						//IL_0014: Unknown result type (might be due to invalid IL or missing references)
						//IL_0019: Unknown result type (might be due to invalid IL or missing references)
						//IL_0020: 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_00ed: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
						//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
						//IL_0100: Unknown result type (might be due to invalid IL or missing references)
						//IL_0117: Unknown result type (might be due to invalid IL or missing references)
						//IL_0118: 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_0110: Unknown result type (might be due to invalid IL or missing references)
						//IL_0089: Unknown result type (might be due to invalid IL or missing references)
						//IL_008a: Unknown result type (might be due to invalid IL or missing references)
						//IL_008b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0090: 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_009b: 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_0130: Unknown result type (might be due to invalid IL or missing references)
						//IL_0127: Unknown result type (might be due to invalid IL or missing references)
						//IL_0128: Unknown result type (might be due to invalid IL or missing references)
						//IL_0147: Unknown result type (might be due to invalid IL or missing references)
						//IL_0148: Unknown result type (might be due to invalid IL or missing references)
						//IL_013f: 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)
						Vector3 val23 = position(arg);
						Vector3 val24 = position(arg2);
						Vector3 val25 = position(arg3);
						Func<Vector3, Vector3> func = delegate(Vector3 w)
						{
							//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_0021: Unknown result type (might be due to invalid IL or missing references)
							//IL_003c: Unknown result type (might be due to invalid IL or missing references)
							//IL_0041: Unknown result type (might be due to invalid IL or missing references)
							//IL_0047: Unknown result type (might be due to invalid IL or missing references)
							//IL_004c: Unknown result type (might be due to invalid IL or missing references)
							//IL_0067: Unknown result type (might be due to invalid IL or missing references)
							//IL_006c: Unknown result type (might be due to invalid IL or missing references)
							//IL_0072: Unknown result type (might be due to invalid IL or missing references)
							//IL_0077: Unknown result type (might be due to invalid IL or missing references)
							//IL_007c: Unknown result type (might be due to invalid IL or missing references)
							//IL_007f: Unknown result type (might be due to invalid IL or missing references)
							Vector3 val26 = normals[ia] * w.x + normals[ib] * w.y + normals[ic] * w.z;
							return ((Vector3)(ref val26)).normalized;
						};
						Func<Vector3, Vector2> func2 = (Vector3 w) => uv[ia] * w.x + uv[ib] * w.y + uv[ic] * w.z;
						int sub2 = (seam ? robeIndex : ((hood && sub != 0 && HairCut((val23 + val24 + val25) / 3f) > 0.4f) ? goldIndex : sub));
						output.Add(val23, val24, val25, func(arg), func(arg2), func(arg3), seam ? WoodUV(val23) : func2(arg), seam ? WoodUV(val24) : func2(arg2), seam ? WoodUV(val25) : func2(arg3), sub2, hood || seam);
					};
					Grid(divisions, emit);
				}
			}
			Func<Vector3, Vector3> sculpt = delegate(Vector3 p)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: 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_0058: 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_0065: 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_0077: 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_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: 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)
				float num23 = float.MaxValue;
				Vector2 val25 = default(Vector2);
				Vector2 val26 = default(Vector2);
				for (int m = 0; m < ordered.Count; m++)
				{
					Vector3 val23 = ordered[m];
					Vector3 val24 = ordered[(m + 1) % ordered.Count];
					((Vector2)(ref val25))..ctor(val24.x - val23.x, val24.y - val23.y);
					((Vector2)(ref val26))..ctor(p.x - val23.x, p.y - val23.y);
					float num24 = Mathf.Clamp01(Vector2.Dot(val26, val25) / ((Vector2)(ref val25)).sqrMagnitude);
					float num25 = num23;
					Vector2 val27 = val26 - val25 * num24;
					num23 = Mathf.Min(num25, ((Vector2)(ref val27)).magnitude);
				}
				p.z = Mathf.Lerp(p.z, VisageDepth(p), Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num23 / 0.045f)));
				return p;
			};
			int count = output.v.Count;
			Func<int, int, float, Vector3> edgePoint = delegate(int num24, int num25, float t)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				int num23 = Mathf.RoundToInt(t * 24f);
				if (num24 > num25)
				{
					int num26 = num24;
					num24 = num25;
					num25 = num26;
					num23 = 24 - num23;
				}
				return (Vector3)(num23 switch
				{
					0 => ordered[num24], 
					24 => ordered[num25], 
					_ => ordered[num24] + (ordered[num25] - ordered[num24]) * ((float)num23 / 24f), 
				});
			};
			for (int num5 = 0; num5 < list.Count; num5 += 3)
			{
				int fa = list[num5];
				int fb = list[num5 + 1];
				int fc = list[num5 + 2];
				Vector3 a = ordered[fa];
				Vector3 b = ordered[fb];
				Vector3 c = ordered[fc];
				Mathf.Max(Vector3.Distance(a, b), Mathf.Max(Vector3.Distance(b, c), Vector3.Distance(c, a)));
				Func<Vector3, Vector3> sample = (Vector3 w) => sculpt((w.x == 0f) ? edgePoint(fb, fc, w.z) : ((w.y == 0f) ? edgePoint(fa, fc, w.z) : ((w.z == 0f) ? edgePoint(fa, fb, w.y) : (a * w.x + b * w.y + c * w.z))));
				Grid(24, delegate(Vector3 wa, Vector3 wb, Vector3 wc)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0013: Unknown result type (might be due to invali