Decompiled source of WhaleCellSkins v1.0.15

BepInEx/plugins/Local-WhaleCellSkins/WhaleCellSkins.dll

Decompiled a week ago
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("WhaleCellProbe")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WhaleCellSkins")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.15.0")]
[assembly: AssemblyInformationalVersion("1.0.15")]
[assembly: AssemblyProduct("WhaleCellSkins")]
[assembly: AssemblyTitle("WhaleCellSkins")]
[assembly: AssemblyVersion("1.0.15.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace WhaleCellSkins
{
	internal static class Assets
	{
		private sealed record Part(Mesh Mesh, Material Material);

		private sealed record Glow(Material Material, float Gain);

		private static readonly Part[][] Cache = new Part[2][];

		private static readonly List<Glow> Glows = new List<Glow>();

		internal static bool Emitting { get; private set; } = true;

		internal static void SetEmission(bool enabled)
		{
			Emitting = enabled;
			Glows.RemoveAll((Glow g) => (Object)(object)g.Material == (Object)null);
			foreach (Glow glow in Glows)
			{
				Apply(glow);
			}
			Plugin.LogSource.LogInfo((object)("Skin emission=" + enabled));
		}

		internal static void Track(Material material, float gain)
		{
			Glow glow = new Glow(material, gain);
			Glows.Add(glow);
			Apply(glow);
		}

		internal static void Release(Material material)
		{
			Glows.RemoveAll((Glow g) => g.Material == material);
		}

		internal static bool GainOf(Material material, out float gain)
		{
			foreach (Glow glow in Glows)
			{
				if ((Object)(object)glow.Material == (Object)(object)material)
				{
					gain = glow.Gain;
					return true;
				}
			}
			gain = 0f;
			return false;
		}

		private static void Apply(Glow g)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Material material = g.Material;
			if (!((Object)(object)material == (Object)null))
			{
				Color val = Color.white * (Emitting ? g.Gain : 0f);
				material.SetColor("_EmissionColor", val);
				if (material.HasProperty("_EmissiveColor"))
				{
					material.SetColor("_EmissiveColor", val);
				}
			}
		}

		internal static GameObject Create(bool whale)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			bool num = !whale;
			Part[][] cache = Cache;
			int num2 = (num ? 1 : 0);
			Part[] array = cache[num2] ?? (cache[num2] = Load(whale ? "whale" : "gpu"));
			GameObject val = new GameObject(whale ? "WCS.Whale" : "WCS.GPU");
			try
			{
				for (int i = 0; i < array.Length; i++)
				{
					GameObject val2 = new GameObject("WCS.part." + i);
					val2.transform.SetParent(val.transform, false);
					val2.AddComponent<MeshFilter>().sharedMesh = array[i].Mesh;
					((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = array[i].Material;
				}
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		private static int Count(int n, int lo, int hi)
		{
			if (n < lo || n > hi)
			{
				throw new InvalidDataException("WCM count outside limits: " + n);
			}
			return n;
		}

		private static Part[] Load(string name)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Expected O, but got Unknown
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Expected O, but got Unknown
			string text = Path.Combine(Plugin.Root, name + ".wcm");
			if (new FileInfo(text).Length > 268435456)
			{
				throw new InvalidDataException("WCM too large");
			}
			BinaryReader r = new BinaryReader(new MemoryStream(File.ReadAllBytes(text), writable: false));
			List<Object> owned;
			Dictionary<string, Texture2D> textures;
			try
			{
				if (r.ReadUInt32() != 827147095)
				{
					throw new InvalidDataException("WCM1 header");
				}
				owned = new List<Object>();
				List<Glow> list = new List<Glow>();
				textures = new Dictionary<string, Texture2D>();
				try
				{
					Shader val = Shader.Find("Standard");
					if ((Object)(object)val == (Object)null || !val.isSupported)
					{
						throw new NotSupportedException("Standard shader unavailable");
					}
					Material[] array = (Material[])(object)new Material[Count(r.ReadInt32(), 1, 1024)];
					Color color = default(Color);
					for (int i = 0; i < array.Length; i++)
					{
						Texture2D val2 = Texture();
						((Color)(ref color))..ctor(F(), F(), F(), F());
						float num = F();
						Texture2D val3 = Texture();
						int num2 = Count(r.ReadInt32(), 0, 2);
						Material val4 = new Material(val);
						owned.Add((Object)(object)val4);
						array[i] = val4;
						((Object)val4).name = $"WCS.{name}.{i}";
						val4.mainTexture = (Texture)(object)val2;
						val4.color = color;
						val4.SetFloat("_Glossiness", 0.18f);
						val4.SetFloat("_Metallic", 0f);
						if (num2 == 1)
						{
							val4.SetFloat("_Mode", 1f);
							val4.SetFloat("_Cutoff", 0.45f);
							val4.EnableKeyword("_ALPHATEST_ON");
							val4.SetOverrideTag("RenderType", "TransparentCutout");
							val4.renderQueue = 2450;
						}
						if (num2 == 2)
						{
							val4.SetFloat("_Mode", 2f);
							val4.SetInt("_SrcBlend", 5);
							val4.SetInt("_DstBlend", 10);
							val4.SetInt("_ZWrite", 0);
							val4.EnableKeyword("_ALPHABLEND_ON");
							val4.SetOverrideTag("RenderType", "Transparent");
							val4.renderQueue = 3000;
						}
						if (num > 0f)
						{
							val4.EnableKeyword("_EMISSION");
							val4.SetTexture("_EmissionMap", (Texture)(object)(val3 ?? val2));
							val4.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
							Glow glow = new Glow(val4, num);
							Apply(glow);
							list.Add(glow);
						}
						if (name == "whale" && i <= 2)
						{
							val4.SetTexture("_EmissionMap", (Texture)(object)val2);
							val4.SetColor("_EmissionColor", Color.black);
							val4.EnableKeyword("_EMISSION");
							val4.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
						}
					}
					Part[] array2 = new Part[Count(r.ReadInt32(), 1, 2048)];
					for (int j = 0; j < array2.Length; j++)
					{
						Material material = array[Count(r.ReadInt32(), 0, array.Length - 1)];
						int num3 = Count(r.ReadInt32(), 3, 2000000);
						if ((long)num3 * 32L > r.BaseStream.Length - r.BaseStream.Position)
						{
							throw new EndOfStreamException();
						}
						Vector3[] array3 = (Vector3[])(object)new Vector3[num3];
						Vector3[] array4 = (Vector3[])(object)new Vector3[num3];
						Vector2[] array5 = (Vector2[])(object)new Vector2[num3];
						for (int k = 0; k < num3; k++)
						{
							array3[k] = new Vector3(F(), F(), F());
							array4[k] = new Vector3(F(), F(), F());
							array5[k] = new Vector2(F(), F());
						}
						int num4 = Count(r.ReadInt32(), 3, 6000000);
						if (num4 % 3 != 0 || (long)num4 * 4L > r.BaseStream.Length - r.BaseStream.Position)
						{
							throw new InvalidDataException("Triangle list");
						}
						int[] array6 = new int[num4];
						for (int l = 0; l < num4; l++)
						{
							array6[l] = Count(r.ReadInt32(), 0, num3 - 1);
						}
						Mesh val5 = new Mesh();
						owned.Add((Object)(object)val5);
						((Object)val5).name = $"WCS.{name}.{j}";
						if (num3 > 65535)
						{
							val5.indexFormat = (IndexFormat)1;
						}
						val5.vertices = Il2CppStructArray<Vector3>.op_Implicit(array3);
						val5.normals = Il2CppStructArray<Vector3>.op_Implicit(array4);
						val5.uv = Il2CppStructArray<Vector2>.op_Implicit(array5);
						val5.triangles = Il2CppStructArray<int>.op_Implicit(array6);
						val5.RecalculateBounds();
						array2[j] = new Part(val5, material);
					}
					if (r.BaseStream.Position != r.BaseStream.Length || list.Count == 0)
					{
						throw new InvalidDataException("Trailing data or no glow");
					}
					foreach (Object item in owned)
					{
						item.hideFlags = (HideFlags)32;
					}
					Glows.AddRange(list);
					ManualLogSource logSource = Plugin.LogSource;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(54, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Loaded ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(name);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(array2.Length);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" parts, ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(textures.Count);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" unique textures, ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(list.Count);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" emissive materials");
					}
					logSource.LogInfo(val6);
					return array2;
				}
				catch
				{
					foreach (Object item2 in owned)
					{
						Object.Destroy(item2);
					}
					throw;
				}
			}
			finally
			{
				if (r != null)
				{
					((IDisposable)r).Dispose();
				}
			}
			float F()
			{
				float num5 = r.ReadSingle();
				if (!float.IsFinite(num5))
				{
					throw new InvalidDataException("Nonfinite WCM float");
				}
				return num5;
			}
			Texture2D Texture()
			{
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Expected O, but got Unknown
				int num5 = Count(r.ReadInt32(), 0, 67108864);
				if (num5 == 0)
				{
					return null;
				}
				byte[] bytes = r.ReadBytes(num5);
				if (bytes.Length != num5 || num5 < 24 || bytes[0] != 137 || bytes[1] != 80)
				{
					throw new InvalidDataException("Truncated PNG");
				}
				if ((long)Dim(16) * (long)Dim(20) > 33554432)
				{
					throw new InvalidDataException("PNG dimensions");
				}
				string text2 = Convert.ToHexString(SHA256.HashData(bytes));
				if (textures.TryGetValue(text2, out var value))
				{
					return value;
				}
				Texture2D val7 = new Texture2D(2, 2, (TextureFormat)4, true);
				owned.Add((Object)(object)val7);
				if (!ImageConversion.LoadImage(val7, Il2CppStructArray<byte>.op_Implicit(bytes), name != "gpu"))
				{
					throw new InvalidDataException("Unity rejected PNG");
				}
				((Object)val7).name = name + "." + text2.Substring(0, 8);
				((Texture)val7).filterMode = (FilterMode)2;
				((Texture)val7).anisoLevel = 2;
				return textures[text2] = val7;
				int Dim(int start)
				{
					return Count(BinaryPrimitives.ReadInt32BigEndian(bytes.AsSpan(start, 4)), 1, 8192);
				}
			}
		}
	}
	public sealed class BatchVisual : MonoBehaviour
	{
		private MeshRenderer original;

		private MeshRenderer visual;

		private Material[] fp;

		private bool savedOff;

		private bool armed;

		private bool worldPickup;

		private MaterialPropertyBlock fpBlock;

		private Camera compareCam;

		private float sampleAt;

		private bool stockShown;

		public BatchVisual(IntPtr p)
			: base(p)
		{
		}

		internal void ArmComparison(Camera cam)
		{
			if (fp != null)
			{
				compareCam = cam;
				sampleAt = Time.unscaledTime + 1f;
			}
		}

		internal void SetReference(bool on)
		{
			if (armed && fp != null && !((Object)(object)original == (Object)null) && !((Object)(object)visual == (Object)null) && on != stockShown)
			{
				stockShown = on;
				((Renderer)original).forceRenderingOff = !on || savedOff;
				Follow();
			}
		}

		[HideFromIl2Cpp]
		private static string MatrixText(Matrix4x4 m)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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)
			return FormattableString.Invariant($"{m.m00:G7},{m.m01:G7},{m.m02:G7},{m.m03:G7};{m.m10:G7},{m.m11:G7},{m.m12:G7},{m.m13:G7};{m.m20:G7},{m.m21:G7},{m.m22:G7},{m.m23:G7};{m.m30:G7},{m.m31:G7},{m.m32:G7},{m.m33:G7}");
		}

		private void OnDisable()
		{
			SetReference(on: false);
			compareCam = null;
		}

		internal static void Attach(Transform body, MeshRenderer source, Fit.Product p, bool worldPickup)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			Transform val = body.Find("WCS.BatchVisual");
			GameObject val2 = null;
			bool flag = (Object)(object)val == (Object)null;
			try
			{
				Transform val3 = val;
				if (flag)
				{
					val2 = new GameObject("WCS.BatchVisual");
					val2.SetActive(false);
					val3 = val2.transform;
					val3.SetParent(body, false);
					val2.AddComponent<MeshFilter>();
					val2.AddComponent<MeshRenderer>();
					val2.AddComponent<BatchVisual>();
				}
				BatchVisual component = ((Component)val3).GetComponent<BatchVisual>();
				if ((Object)(object)component == (Object)null)
				{
					throw new Exception("Foreign child shares WCS name");
				}
				MeshFilter component2 = ((Component)val3).GetComponent<MeshFilter>();
				MeshRenderer component3 = ((Component)val3).GetComponent<MeshRenderer>();
				if ((Object)(object)component2.sharedMesh != (Object)(object)p.Mesh)
				{
					((Renderer)component3).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(component.Materials(body, source, p.Materials));
					component2.sharedMesh = p.Mesh;
				}
				if ((Object)(object)component2.sharedMesh != (Object)(object)p.Mesh || ((Il2CppArrayBase<Material>)(object)((Renderer)component3).sharedMaterials).Length != p.Materials.Length)
				{
					throw new Exception("Batch child incomplete");
				}
				if (flag)
				{
					component.original = source;
					component.visual = component3;
					component.savedOff = ((Renderer)source).forceRenderingOff;
					component.worldPickup = worldPickup;
					((Renderer)component3).shadowCastingMode = ((Renderer)source).shadowCastingMode;
					((Renderer)component3).receiveShadows = ((Renderer)source).receiveShadows;
					component.armed = true;
					component.Follow();
					val2.SetActive(true);
					((Renderer)source).forceRenderingOff = true;
				}
				else
				{
					component.Follow();
				}
				if (component.fp != null)
				{
					component.SyncBoundProjection(((Renderer)source).sharedMaterial.IsKeywordEnabled("ENABLE_FPS_RENDERING"), receipt: false);
				}
			}
			catch
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				throw;
			}
		}

		internal void SyncBoundProjection(bool enabledFP, bool receipt)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			if (!armed || fp == null || (Object)(object)visual == (Object)null || (Object)(object)original == (Object)null)
			{
				return;
			}
			Material[] array = Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)((Renderer)visual).sharedMaterials);
			Material sharedMaterial = ((Renderer)original).sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null || array.Length != fp.Length || array.Length == 0)
			{
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				Material val = array[i];
				if ((Object)(object)val == (Object)null || (Object)(object)fp[i] == (Object)null || ((Object)(object)val != (Object)(object)fp[i] && ((Object)(object)val.shader != (Object)(object)fp[i].shader || !((Object)val).name.StartsWith(((Object)fp[i]).name, StringComparison.Ordinal))))
				{
					return;
				}
			}
			int num = FpChildMaterial.SyncProjection(sharedMaterial, array, enabledFP);
			if (fpBlock == null)
			{
				fpBlock = new MaterialPropertyBlock();
			}
			((Renderer)original).GetPropertyBlock(fpBlock);
			((Renderer)visual).SetPropertyBlock(fpBlock);
			if (receipt)
			{
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(46, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("WCS_FP_SWITCH enabled=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(enabledFP);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" activeSlots=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(array.Length);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" corrected=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
				}
				logSource.LogInfo(val2);
			}
		}

		private void LateUpdate()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (!armed || (Object)(object)original == (Object)null || (Object)(object)visual == (Object)null)
			{
				return;
			}
			if ((Object)(object)compareCam != (Object)null)
			{
				bool flag = Input.GetKey((KeyCode)305) && Input.GetKey((KeyCode)290);
				bool num = flag != stockShown;
				SetReference(flag);
				if (num || (sampleAt >= 0f && Time.unscaledTime >= sampleAt))
				{
					sampleAt = -1f;
					Matrix4x4 m = compareCam.worldToCameraMatrix * ((Component)original).transform.localToWorldMatrix;
					ManualLogSource logSource = Plugin.LogSource;
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(63, 6, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("WCS_FP_AB stock=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(stockShown);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" itemCamera=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)compareCam).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" fov=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(compareCam.fieldOfView, "F2");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" aspect=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(compareCam.aspect, "F4");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" bodyView=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(MatrixText(m));
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" projection=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(MatrixText(compareCam.projectionMatrix));
					}
					logSource.LogInfo(val);
				}
			}
			Follow();
		}

		private void Follow()
		{
			if (worldPickup && !((Renderer)original).forceRenderingOff)
			{
				savedOff = false;
				((Renderer)original).forceRenderingOff = true;
			}
			bool flag = ((Renderer)original).enabled && !savedOff && !stockShown;
			if (((Renderer)visual).enabled != flag)
			{
				((Renderer)visual).enabled = flag;
			}
			if (worldPickup && flag && ((Renderer)visual).forceRenderingOff)
			{
				((Renderer)visual).forceRenderingOff = false;
			}
			int layer = ((Component)original).gameObject.layer;
			if (((Component)this).gameObject.layer != layer)
			{
				((Component)this).gameObject.layer = layer;
			}
		}

		[HideFromIl2Cpp]
		private Material[] Materials(Transform body, MeshRenderer source, Material[] skin)
		{
			Release();
			if (!FpChildMaterial.Applies(body, source))
			{
				return skin;
			}
			string note;
			Material[] array = FpChildMaterial.Build(source, skin, out note);
			if (note != null)
			{
				Plugin.LogSource.LogInfo((object)("WCS FP material " + note));
			}
			if (array == null)
			{
				return skin;
			}
			fp = array;
			return array;
		}

		private void Release()
		{
			if (fp == null)
			{
				return;
			}
			Material[] array = fp;
			fp = null;
			Material[] array2 = array;
			foreach (Material val in array2)
			{
				if ((Object)(object)val != (Object)null)
				{
					Assets.Release(val);
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private void OnDestroy()
		{
			Release();
			if (armed && (Object)(object)original != (Object)null)
			{
				((Renderer)original).forceRenderingOff = savedOff;
			}
		}
	}
	internal static class DecayShadowGuard
	{
		private static int skipped;

		private static float nextLog;

		internal static bool Installed { get; private set; }

		internal static int Skipped => skipped;

		internal static void Install(Harmony harmony)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(ShadowEnemyRenderer), "ShouldRender");
			if (methodInfo == null)
			{
				throw new MissingMethodException("ShadowEnemyRenderer.get_ShouldRender");
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(DecayShadowGuard), "Before", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Plugin.LogSource.LogInfo((object)"Render guard: ShadowEnemyRenderer.ShouldRender (renderer-less decay copy only)");
			Installed = true;
		}

		private static bool Before(ShadowEnemyRenderer __instance, ref bool __result)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.Renderer != (Object)null)
			{
				return true;
			}
			GameObject gameObject = ((Component)__instance).gameObject;
			if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy || !((Object)gameObject).name.EndsWith("_DecayRenderer", StringComparison.Ordinal))
			{
				return true;
			}
			__result = false;
			skipped++;
			if (Time.unscaledTime >= nextLog)
			{
				nextLog = Time.unscaledTime + 5f;
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(54, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("WCS_DECAY_SHADOW_SKIP go=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)gameObject).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" renderer=none skippedChecks=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(skipped);
				}
				logSource.LogInfo(val);
			}
			return false;
		}
	}
	internal static class Fit
	{
		internal enum Pose
		{
			Housing,
			Carried,
			Ground,
			FirstPerson
		}

		internal sealed record Product(Mesh Mesh, Material[] Materials, Bounds Original, float Scale, float Lift, GripSurface.Stats Surface, float Shift, string Stamp);

		private static readonly Product[] cache = new Product[4];

		internal const float DefaultGripLiftCm = 5.888967f;

		internal static float AppliedGripLiftCm
		{
			get
			{
				Product product = cache[3];
				if ((object)product == null)
				{
					if (Grip.Mode != Grip.Align.Lift)
					{
						return 5.888967f;
					}
					return Grip.ClampLift(Grip.RequestedLiftCm);
				}
				return product.Lift;
			}
		}

		internal static float AppliedGripExtraCm => AppliedGripLiftCm - 5.888967f;

		internal static Grip.Align GripMode => Grip.Mode;

		internal static Product Owned(Mesh mesh)
		{
			Product[] array = cache;
			foreach (Product product in array)
			{
				if (product != null && (Object)(object)product.Mesh == (Object)(object)mesh)
				{
					return product;
				}
			}
			return null;
		}

		internal static void Require(bool good, string reason)
		{
			if (!good)
			{
				throw new InvalidOperationException(reason);
			}
		}

		internal static void ConfigureGrip(float liftCentimeters)
		{
			Set(Grip.Align.Lift, 0f, liftCentimeters);
		}

		internal static void ConfigureGrip(Grip.Align align, float extraCentimeters)
		{
			Set(align, extraCentimeters, Grip.RequestedLiftCm);
		}

		internal static void ConfigureGrip(Grip.Align align, float extraCentimeters, float liftCentimeters)
		{
			Set(align, extraCentimeters, liftCentimeters);
		}

		private static void Set(Grip.Align align, float extraCentimeters, float liftCentimeters)
		{
			if (cache[3] != null)
			{
				throw new InvalidOperationException("Grip is set only at startup");
			}
			Grip.Configure(align, extraCentimeters, liftCentimeters);
		}

		private static bool Finite(Vector3 v)
		{
			//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)
			if (float.IsFinite(v.x) && float.IsFinite(v.y))
			{
				return float.IsFinite(v.z);
			}
			return false;
		}

		internal static bool Near(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = a - b;
			return ((Vector3)(ref val)).sqrMagnitude < 1E-08f;
		}

		internal static string V(Vector3 v)
		{
			//IL_000d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			return FormattableString.Invariant($"({v.x:F6},{v.y:F6},{v.z:F6})");
		}

		internal static string Describe(Bounds b)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			return $"sizeXYZ={V(((Bounds)(ref b)).size)} center={V(((Bounds)(ref b)).center)} min={V(((Bounds)(ref b)).min)} max={V(((Bounds)(ref b)).max)}";
		}

		internal static Matrix4x4 Relative(Transform ancestor, Transform child)
		{
			//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_001a: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.identity;
			while ((Object)(object)child != (Object)(object)ancestor)
			{
				Require((Object)(object)child != (Object)null, "measurement frame is not an ancestor");
				val = Matrix4x4.TRS(child.localPosition, child.localRotation, child.localScale) * val;
				child = child.parent;
			}
			return val;
		}

		internal static Bounds Box(Matrix4x4 m, Bounds b)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004c: 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_0060: 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_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_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_0078: 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)
			Vector3 center = ((Bounds)(ref b)).center;
			Vector3 extents = ((Bounds)(ref b)).extents;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(((Matrix4x4)(ref m)).MultiplyPoint3x4(center), Vector3.zero);
			for (int i = 0; i < 8; i++)
			{
				Vector3 val = ((Matrix4x4)(ref m)).MultiplyPoint3x4(center + new Vector3(((i & 1) == 0) ? (0f - extents.x) : extents.x, ((i & 2) == 0) ? (0f - extents.y) : extents.y, ((i & 4) == 0) ? (0f - extents.z) : extents.z));
				Require(Finite(val), "non-finite mesh bound");
				((Bounds)(ref result)).Encapsulate(val);
			}
			return result;
		}

		internal static Product Prepare(Bounds stock, Pose pose)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: 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_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Expected O, but got Unknown
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Expected O, but got Unknown
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			Product product = cache[(int)pose];
			if (product != null && (Object)(object)product.Mesh != (Object)null)
			{
				Bounds original = product.Original;
				int good;
				if (Near(((Bounds)(ref original)).center, ((Bounds)(ref stock)).center))
				{
					original = product.Original;
					good = (Near(((Bounds)(ref original)).size, ((Bounds)(ref stock)).size) ? 1 : 0);
				}
				else
				{
					good = 0;
				}
				Require((byte)good != 0, "stock bound changed");
				if (pose != Pose.FirstPerson || product.Stamp == Grip.Stamp)
				{
					return product;
				}
				cache[(int)pose] = null;
			}
			bool flag = pose == Pose.Housing;
			GameObject val = null;
			Mesh val2 = null;
			try
			{
				val = Assets.Create(flag);
				Require((Object)(object)val != (Object)null && (Object)(object)val.transform.parent == (Object)null, "no independent art root");
				val.SetActive(false);
				Il2CppArrayBase<MeshFilter> componentsInChildren = val.GetComponentsInChildren<MeshFilter>(true);
				Require(componentsInChildren.Length > 0, "empty art");
				Quaternion val3 = Quaternion.Euler(flag ? 90f : (-90f), 0f, 0f);
				Matrix4x4 val4 = Matrix4x4.TRS(Vector3.zero, val3, Vector3.one);
				CombineInstance[] array = (CombineInstance[])(object)new CombineInstance[componentsInChildren.Length];
				Material[] array2 = (Material[])(object)new Material[componentsInChildren.Length];
				Matrix4x4[] array3 = (Matrix4x4[])(object)new Matrix4x4[componentsInChildren.Length];
				Mesh[] array4 = (Mesh[])(object)new Mesh[componentsInChildren.Length];
				Bounds val5 = default(Bounds);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					MeshFilter val6 = componentsInChildren[i];
					MeshRenderer component = ((Component)val6).GetComponent<MeshRenderer>();
					Mesh sharedMesh = val6.sharedMesh;
					Require((Object)(object)sharedMesh != (Object)null && sharedMesh.isReadable && sharedMesh.subMeshCount == 1 && sharedMesh.vertexCount >= 3 && (Object)(object)component != (Object)null && ((Renderer)component).enabled && (Object)(object)((Renderer)component).sharedMaterial != (Object)null, "missing/unreadable art part");
					array2[i] = ((Renderer)component).sharedMaterial;
					array3[i] = val4 * Relative(val.transform, ((Component)val6).transform);
					array4[i] = sharedMesh;
					Bounds val7 = Box(array3[i], sharedMesh.bounds);
					if (i == 0)
					{
						val5 = val7;
					}
					else
					{
						((Bounds)(ref val5)).Encapsulate(val7);
					}
					int num = i;
					CombineInstance val8 = default(CombineInstance);
					((CombineInstance)(ref val8)).mesh = sharedMesh;
					((CombineInstance)(ref val8)).subMeshIndex = 0;
					array[num] = val8;
				}
				float num2 = (flag ? ((Bounds)(ref stock)).size.z : ((Bounds)(ref stock)).size.x);
				float num3 = num2 / (flag ? ((Bounds)(ref val5)).size.z : ((Bounds)(ref val5)).size.x);
				Require(float.IsFinite(num3) && num3 > 0f && num2 > 0f, "degenerate target/art");
				Vector3 val9 = ((Bounds)(ref stock)).center - ((Bounds)(ref val5)).center * num3;
				if (flag)
				{
					val9.z = ((Bounds)(ref stock)).min.z - ((Bounds)(ref val5)).min.z * num3;
					val9.y = Math.Max(((Bounds)(ref stock)).center.y, ((Bounds)(ref stock)).min.y + 0.145f - ((Bounds)(ref val5)).min.y * num3);
				}
				else if (pose == Pose.Ground)
				{
					val9.y = ((Bounds)(ref stock)).min.y - ((Bounds)(ref val5)).min.y * num3;
				}
				GripSurface.Stats art = default(GripSurface.Stats);
				Grip.Solution solution = default(Grip.Solution);
				if (pose == Pose.FirstPerson)
				{
					Grip.RequireStock(stock);
					art = GripSurface.Measure(array4, array3);
					solution = Grip.Solve(stock, in art, num3);
					val9.y = solution.Shift;
					ManualLogSource logSource = Plugin.LogSource;
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val10 = new BepInExInfoLogInterpolatedStringHandler(16, 3, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("WCS GRIP ");
						((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(Grip.Describe);
						((BepInExLogInterpolatedStringHandler)val10).AppendLiteral(" art[");
						((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(art.Describe);
						((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("] ");
						((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(solution.Describe);
					}
					logSource.LogInfo(val10);
				}
				Matrix4x4 val11 = Matrix4x4.TRS(val9, Quaternion.identity, Vector3.one * num3);
				for (int j = 0; j < array.Length; j++)
				{
					((CombineInstance)(ref array[j])).transform = val11 * array3[j];
				}
				val2 = new Mesh
				{
					name = "WCS.fitted." + pose,
					indexFormat = (IndexFormat)1
				};
				Il2CppStructArray<CombineInstance> val12 = Il2CppStructArray<CombineInstance>.op_Implicit(array);
				val2.CombineMeshes(val12, false, true, false);
				val2.RecalculateBounds();
				Require(val2.vertexCount >= 3 && val2.subMeshCount == array2.Length, "incomplete mesh combination");
				for (int k = 0; k < array2.Length; k++)
				{
					Require(val2.GetIndexCount(k) != 0, "empty fitted submesh");
				}
				Validate(stock, val2.bounds, pose);
				((Object)val2).hideFlags = (HideFlags)32;
				bool flag3 = pose == Pose.FirstPerson;
				Product product2 = new Product(val2, array2, stock, num3, flag3 ? solution.UnderCm : 0f, art, val9.y, flag3 ? Grip.Stamp : null);
				cache[(int)pose] = product2;
				val2 = null;
				return product2;
			}
			finally
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		internal static float Validate(Bounds original, Bounds actual, Pose pose)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_00ec: 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_01a0: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			Vector3 size = ((Bounds)(ref actual)).size;
			Require(Finite(((Bounds)(ref actual)).center) && Finite(size) && size.x > 0f && size.y > 0f && size.z > 0f, "invalid assembled geometry");
			bool num = pose == Pose.Housing;
			float num2 = Math.Abs((num ? (size.z / ((Bounds)(ref original)).size.z) : (size.x / ((Bounds)(ref original)).size.x)) - 1f);
			Require(float.IsFinite(num2) && num2 <= 0.05f, "principal dimension outside 5% tolerance");
			Require(Math.Abs(((Bounds)(ref actual)).center.x - ((Bounds)(ref original)).center.x) < 0.0002f, "X center misaligned");
			if (num)
			{
				Require(Math.Abs(((Bounds)(ref actual)).min.z - ((Bounds)(ref original)).min.z) < 0.0002f && ((Bounds)(ref actual)).min.y >= ((Bounds)(ref original)).min.y + 0.145f - 0.0002f, "housing floor or front clearance failed");
				return num2;
			}
			Require(Math.Abs(((Bounds)(ref actual)).center.z - ((Bounds)(ref original)).center.z) < 0.0002f, "cell axis misaligned");
			float num3;
			switch (pose)
			{
			case Pose.FirstPerson:
				Require(((Bounds)(ref actual)).min.y >= Math.Max(-0.14354299f, -0.042305492f) - 0.0002f, "first-person art sinks below a measured grip anchor");
				Require(((Bounds)(ref actual)).max.y <= ((Bounds)(ref original)).max.y + 0.025f + 0.0002f, "first-person art protrudes above the authored crown");
				return num2;
			default:
				num3 = Math.Abs(((Bounds)(ref actual)).center.y - ((Bounds)(ref original)).center.y);
				break;
			case Pose.Ground:
				num3 = Math.Abs(((Bounds)(ref actual)).min.y - ((Bounds)(ref original)).min.y);
				break;
			}
			Require(num3 < 0.0002f, "cell anchor misaligned");
			return num2;
		}
	}
	internal static class FpChildMaterial
	{
		internal const string Supports = "_SupportsFPSRendering";

		internal const string Enable = "_EnableFPSRendering";

		internal const string Keyword = "ENABLE_FPS_RENDERING";

		private static readonly Dictionary<int, Texture2D> Tints = new Dictionary<int, Texture2D>();

		private static Texture2D matteSurface;

		private static readonly Dictionary<int, Texture2D> prints = new Dictionary<int, Texture2D>();

		internal static Texture2D MatteSurface => matteSurface ?? (matteSurface = Pixel(new Color32((byte)0, (byte)0, (byte)0, (byte)0), "WCS.fp.matte"));

		private static string Bare(string name)
		{
			if (!name.EndsWith("(Clone)", StringComparison.Ordinal))
			{
				return name;
			}
			return name.Substring(0, name.Length - 7).TrimEnd();
		}

		internal static bool Applies(Transform body, MeshRenderer source)
		{
			Transform val = (((Object)(object)body != (Object)null) ? body.parent : null);
			Transform val2 = (((Object)(object)val != (Object)null) ? val.parent : null);
			if ((Object)(object)val2 == (Object)null || (Object)(object)source == (Object)null)
			{
				return false;
			}
			if (Bare(((Object)body).name) != "g_Generator_Cell" || Bare(((Object)val).name) != "Generator_Cell" || Bare(((Object)val2).name) != "Generator_Cell_FirstPerson")
			{
				return false;
			}
			Material sharedMaterial = ((Renderer)source).sharedMaterial;
			if ((Object)(object)sharedMaterial != (Object)null)
			{
				return sharedMaterial.HasProperty("_SupportsFPSRendering");
			}
			return false;
		}

		internal static Material[] Build(MeshRenderer source, Material[] skin, out string note)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			note = null;
			if ((Object)(object)source == (Object)null || skin == null || skin.Length == 0)
			{
				return null;
			}
			Material sharedMaterial = ((Renderer)source).sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null || !sharedMaterial.HasProperty("_SupportsFPSRendering"))
			{
				return null;
			}
			Material[] array = (Material[])(object)new Material[skin.Length];
			try
			{
				int num = 0;
				for (int i = 0; i < skin.Length; i++)
				{
					array[i] = new Material(sharedMaterial);
					if (Configure(array[i], skin[i], i))
					{
						num++;
					}
				}
				note = Describe(sharedMaterial, array[0], num, array.Length);
				return array;
			}
			catch (Exception ex)
			{
				Material[] array2 = array;
				foreach (Material val in array2)
				{
					if ((Object)(object)val != (Object)null)
					{
						Assets.Release(val);
						Object.Destroy((Object)(object)val);
					}
				}
				note = "fp material kept original: " + ex.Message;
				return null;
			}
		}

		internal static Texture AlbedoFor(Material skin)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00e2: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			Texture val = (skin.HasProperty("_MainTex") ? skin.GetTexture("_MainTex") : skin.mainTexture);
			if ((Object)(object)val == (Object)null)
			{
				Color color = skin.color;
				return (Texture)(object)TintOf(new Color(color.r * 0.3f, color.g * 0.3f, color.b * 0.3f, color.a));
			}
			Texture2D val2 = ((Il2CppObjectBase)val).Cast<Texture2D>();
			int instanceID = ((Object)val2).GetInstanceID();
			if (prints.TryGetValue(instanceID, out var value) && (Object)(object)value != (Object)null)
			{
				return (Texture)(object)value;
			}
			Color32[] array = Il2CppArrayBase<Color32>.op_Implicit((Il2CppArrayBase<Color32>)(object)val2.GetPixels32());
			for (int i = 0; i < array.Length; i++)
			{
				Color32 val3 = array[i];
				array[i] = new Color32((byte)((val3.r * 145 + 127) / 255), (byte)((val3.g * 145 + 127) / 255), (byte)((val3.b * 145 + 127) / 255), val3.a);
			}
			value = new Texture2D(((Texture)val2).width, ((Texture)val2).height, (TextureFormat)4, true)
			{
				name = "WCS.fp.print." + ((Object)val2).name,
				wrapMode = ((Texture)val2).wrapMode,
				filterMode = ((Texture)val2).filterMode,
				anisoLevel = ((Texture)val2).anisoLevel
			};
			try
			{
				value.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
				value.Apply(true, true);
				val2.Apply(false, true);
				((Object)value).hideFlags = (HideFlags)32;
				return (Texture)(object)(prints[instanceID] = value);
			}
			catch
			{
				Object.Destroy((Object)(object)value);
				throw;
			}
		}

		internal static float FpGain(float gain)
		{
			return Math.Min(0.6f, gain * 0.3f);
		}

		internal static Texture EmissionFor(Material skin)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Texture val = (skin.HasProperty("_EmissionMap") ? skin.GetTexture("_EmissionMap") : null);
			if (!((Object)(object)val != (Object)null))
			{
				if (!((Object)(object)skin.mainTexture != (Object)null))
				{
					return (Texture)(object)TintOf(skin.color);
				}
				return skin.mainTexture;
			}
			return val;
		}

		internal static Texture2D TintOf(Color color)
		{
			//IL_0002: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004f: 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)
			Color32 val = default(Color32);
			((Color32)(ref val))..ctor(B(color.r), B(color.g), B(color.b), B(color.a));
			int key = (val.r << 24) | (val.g << 16) | (val.b << 8) | val.a;
			if (Tints.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture2D val2 = Pixel(val, "WCS.fp.tint." + key.ToString("X8"));
			Tints[key] = val2;
			return val2;
		}

		private static byte B(float v)
		{
			return (byte)Mathf.RoundToInt(Mathf.Clamp01(v) * 255f);
		}

		private static Texture2D Pixel(Color32 c, string name)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0029: 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)
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false, true);
			((Object)val).name = name;
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit((Color32[])(object)new Color32[1] { c }));
			val.Apply(false, false);
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static bool Configure(Material m, Material skin, int index)
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			((Object)m).name = "WCS.fp." + index + "." + ((Object)skin).name;
			Texture obj = (skin.HasProperty("_MainTex") ? skin.GetTexture("_MainTex") : skin.mainTexture);
			if (m.HasProperty("_MainTex"))
			{
				m.SetTexture("_MainTex", AlbedoFor(skin));
			}
			if (m.HasProperty("_BumpMap"))
			{
				m.SetTexture("_BumpMap", (Texture)null);
			}
			m.DisableKeyword("_NORMALMAP");
			if (m.HasProperty("_MetallicGlossMap"))
			{
				m.SetTexture("_MetallicGlossMap", (Texture)(object)MatteSurface);
			}
			m.EnableKeyword("_METALLICGLOSSMAP");
			if (Assets.GainOf(skin, out var gain) && gain > 0f)
			{
				if (m.HasProperty("_EmissiveMap"))
				{
					m.SetTexture("_EmissiveMap", EmissionFor(skin));
				}
				if (m.HasProperty("_EnableEmissive"))
				{
					m.SetFloat("_EnableEmissive", 1f);
				}
				m.EnableKeyword("ENABLE_EMISSIVE");
				Assets.Track(m, FpGain(gain));
			}
			else
			{
				if (m.HasProperty("_EmissiveMap"))
				{
					m.SetTexture("_EmissiveMap", (Texture)null);
				}
				if (m.HasProperty("_EmissiveColor"))
				{
					m.SetColor("_EmissiveColor", Color.black);
				}
				if (m.HasProperty("_EnableEmissive"))
				{
					m.SetFloat("_EnableEmissive", 0f);
				}
				m.DisableKeyword("ENABLE_EMISSIVE");
			}
			return (Object)(object)obj == (Object)null;
		}

		internal static int SyncProjection(Material template, Material[] bound, bool enabled)
		{
			float num = template.GetFloat("_EnableFPSRendering");
			int num2 = 0;
			foreach (Material val in bound)
			{
				if (val.GetFloat("_EnableFPSRendering") != num)
				{
					val.SetFloat("_EnableFPSRendering", num);
				}
				if (val.IsKeywordEnabled("ENABLE_FPS_RENDERING") != enabled)
				{
					if (enabled)
					{
						val.EnableKeyword("ENABLE_FPS_RENDERING");
					}
					else
					{
						val.DisableKeyword("ENABLE_FPS_RENDERING");
					}
					num2++;
				}
			}
			return num2;
		}

		private static string Describe(Material template, Material clone, int tinted, int slots)
		{
			Texture val = (clone.HasProperty("_MainTex") ? clone.GetTexture("_MainTex") : null);
			Texture val2 = (clone.HasProperty("_MetallicGlossMap") ? clone.GetTexture("_MetallicGlossMap") : null);
			return "shader=" + (((Object)(object)clone.shader != (Object)null) ? ((Object)clone.shader).name : "?") + " template=" + (((Object)(object)template.shader != (Object)null) ? ((Object)template.shader).name : "?") + " supports=" + f(clone, "_SupportsFPSRendering") + " enable=" + f(clone, "_EnableFPSRendering") + " keyword=" + clone.IsKeywordEnabled("ENABLE_FPS_RENDERING") + " emissive=" + clone.IsKeywordEnabled("ENABLE_EMISSIVE") + " mainTex=" + (((Object)(object)val != (Object)null) ? ((Object)val).name : "none") + " tinted=" + tinted + "/" + slots + " surface=" + (((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "none") + " shading=" + f(clone, "_ShadingType");
			static string f(Material m, string p)
			{
				if (!m.HasProperty(p))
				{
					return "-";
				}
				return FormattableString.Invariant($"{m.GetFloat(p):F0}");
			}
		}
	}
	public sealed class GeneratorPlates : MonoBehaviour
	{
		private MeshRenderer slot;

		private MeshRenderer lid;

		private MeshRenderer display;

		private bool slotWasOff;

		private bool lidWasOff;

		private bool displayWasOff;

		private bool showingPower;

		private MaterialPropertyBlock block;

		private MeshFilter[] shadowFilters;

		private Mesh[] originalShadowMeshes;

		public GeneratorPlates(IntPtr p)
			: base(p)
		{
		}

		internal static void Apply(Transform model, GameObject slotObject, GameObject lidObject, MeshRenderer skin, bool powered)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			GeneratorPlates generatorPlates = ((Component)model).GetComponent<GeneratorPlates>();
			if ((Object)(object)generatorPlates == (Object)null || (Object)(object)generatorPlates.display == (Object)null)
			{
				MeshRenderer val = Plate(slotObject, "g_slot", 114);
				MeshRenderer val2 = Plate(lidObject, "g_lid", 20);
				MeshRenderer val3 = Plate(((Component)model.Find("display_powerindicator")).gameObject, "display_powerindicator", 8);
				if (generatorPlates == null)
				{
					generatorPlates = ((Component)model).gameObject.AddComponent<GeneratorPlates>();
				}
				generatorPlates.slot = val;
				generatorPlates.lid = val2;
				generatorPlates.slotWasOff = ((Renderer)val).forceRenderingOff;
				generatorPlates.lidWasOff = ((Renderer)val2).forceRenderingOff;
				generatorPlates.displayWasOff = ((Renderer)val3).forceRenderingOff;
				generatorPlates.display = val3;
			}
			try
			{
				generatorPlates.SetPower(skin, powered);
				generatorPlates.showingPower = true;
			}
			catch
			{
				generatorPlates.showingPower = false;
				((Renderer)generatorPlates.display).forceRenderingOff = generatorPlates.displayWasOff;
				throw;
			}
			if (generatorPlates.shadowFilters == null)
			{
				generatorPlates.RemoveStockShadows(model);
			}
			generatorPlates.LateUpdate();
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(60, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("WCS_GEN_POWER generator=");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(((Object)model).GetInstanceID());
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" powered=");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<bool>(powered);
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" emission=");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<bool>(powered && Assets.Emitting);
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" indicatorHidden=");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<bool>(((Renderer)generatorPlates.display).forceRenderingOff);
			}
			logSource.LogInfo(val4);
		}

		private void SetPower(MeshRenderer skin, bool powered)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)skin).sharedMaterials;
			int num = 0;
			if (block == null)
			{
				block = new MaterialPropertyBlock();
			}
			for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; i++)
			{
				Material val = ((Il2CppArrayBase<Material>)(object)sharedMaterials)[i];
				if (val.IsKeywordEnabled("_EMISSION"))
				{
					((Renderer)skin).GetPropertyBlock(block, i);
					float num2 = ((((Object)val).name == "WCS.whale.0") ? 0.35f : 1f);
					block.SetColor("_EmissionColor", (Color)((powered && Assets.Emitting) ? new Color(0.32f * num2, 0.9f * num2, 1.55f * num2, 1f) : Color.black));
					block.SetColor("_Color", (powered && !Assets.Emitting) ? (val.color * new Color(0.32f, 0.93f, 1f, 1f)) : val.color);
					((Renderer)skin).SetPropertyBlock(block, i);
					num++;
				}
			}
			Fit.Require(num > 0, "no emissive whale slots; leaving stock display alone");
		}

		private void RemoveStockShadows(Transform model)
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Invalid comparison between Unknown and I4
			shadowFilters = (MeshFilter[])(object)new MeshFilter[3];
			originalShadowMeshes = (Mesh[])(object)new Mesh[3];
			int num = 0;
			for (int i = 0; i < 3; i++)
			{
				Transform val = model.Find("Generator_Slot_shadow_1" + ((i == 0) ? "" : $" ({i})"));
				if (!((Object)(object)val == (Object)null) && val.childCount == 0 && !((Object)(object)((Component)val).GetComponent<Collider>() != (Object)null))
				{
					MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
					MeshFilter component2 = ((Component)val).GetComponent<MeshFilter>();
					Mesh val2 = ((component2 != null) ? component2.sharedMesh : null);
					if (!((Object)(object)component == (Object)null) && (int)((Renderer)component).shadowCastingMode == 3 && !((Object)(object)val2 == (Object)null) && !(((Object)val2).name != "Cube") && val2.vertexCount == 24)
					{
						shadowFilters[i] = component2;
						originalShadowMeshes[i] = val2;
						component2.sharedMesh = null;
						num++;
					}
				}
			}
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("WCS_GEN_SHADOW generator=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((Object)model).GetInstanceID());
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" detached=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("/3");
			}
			logSource.LogInfo(val3);
		}

		private static MeshRenderer Plate(GameObject node, string name, int vertices)
		{
			MeshRenderer component = node.GetComponent<MeshRenderer>();
			MeshFilter component2 = node.GetComponent<MeshFilter>();
			Mesh val = ((component2 != null) ? component2.sharedMesh : null);
			if (((Object)node).name != name || (Object)(object)component == (Object)null || (Object)(object)val == (Object)null || ((Object)val).name != name || val.vertexCount != vertices)
			{
				throw new InvalidOperationException("Unexpected generator visual: " + name);
			}
			return component;
		}

		private void LateUpdate()
		{
			Hide(slot);
			Hide(lid);
			if (showingPower)
			{
				Hide(display);
			}
		}

		private static void Hide(MeshRenderer r)
		{
			if ((Object)(object)r != (Object)null && !((Renderer)r).forceRenderingOff)
			{
				((Renderer)r).forceRenderingOff = true;
			}
		}

		private void OnDestroy()
		{
			if (shadowFilters != null)
			{
				for (int i = 0; i < shadowFilters.Length; i++)
				{
					MeshFilter val = shadowFilters[i];
					if ((Object)(object)val != (Object)null && (Object)(object)val.sharedMesh == (Object)null && (Object)(object)originalShadowMeshes[i] != (Object)null)
					{
						val.sharedMesh = originalShadowMeshes[i];
					}
				}
			}
			if ((Object)(object)slot != (Object)null)
			{
				((Renderer)slot).forceRenderingOff = slotWasOff;
			}
			if ((Object)(object)lid != (Object)null)
			{
				((Renderer)lid).forceRenderingOff = lidWasOff;
			}
			if ((Object)(object)display != (Object)null)
			{
				((Renderer)display).forceRenderingOff = displayWasOff;
			}
		}
	}
	internal static class Grip
	{
		internal enum Align
		{
			TopSurface,
			Centroid,
			Lift
		}

		internal readonly struct Solution
		{
			internal readonly float Shift;

			internal readonly float UnderCm;

			internal readonly float TopCm;

			internal readonly float AboveCrownCm;

			internal readonly float LeftClearCm;

			internal readonly float RightClearCm;

			internal readonly bool Pinned;

			internal string Describe => FormattableString.Invariant($"shift={Shift:F7} underCm={UnderCm:F4} topCm={TopCm:F4} aboveCrownCm={AboveCrownCm:F4} leftClearCm={LeftClearCm:F4} rightClearCm={RightClearCm:F4} pinned={Pinned}");

			internal Solution(float shift, float underCm, float topCm, float aboveCrownCm, float leftClearCm, float rightClearCm, bool pinned)
			{
				Shift = shift;
				UnderCm = underCm;
				TopCm = topCm;
				AboveCrownCm = aboveCrownCm;
				LeftClearCm = leftClearCm;
				RightClearCm = rightClearCm;
				Pinned = pinned;
			}
		}

		internal const float PrefabScale = 0.8f;

		internal const float CmPerMesh = 80f;

		internal const float StockBottomMeshY = -0.10027259f;

		internal const float StockCrownMeshY = 0.130257f;

		internal const float StockHeightMeshY = 0.23052958f;

		internal const float StockUpMeanMeshY = 0.058666844f;

		internal const float StockUpMedianMeshY = 0.085175686f;

		internal const float StockUpP90MeshY = 0.12167752f;

		internal const float StockSurfaceCentroidMeshY = 0.026834678f;

		internal const float PrefabToMeshY = 0.08021809f;

		internal const float LeftHandPrefabY = -0.0346163f;

		internal const float RightHandPrefabY = 0.0463737f;

		internal const float LeftHandAnchorMeshY = -0.14354299f;

		internal const float RightHandAnchorMeshY = -0.042305492f;

		internal const float LeftHandMeshX = 0.084919f;

		internal const float LeftHandMeshZ = 0.077723f;

		internal const float RightHandMeshX = 0.600306f;

		internal const float RightHandMeshZ = 0.086408f;

		internal const float AuthoredPalmClearanceMeshY = 0.0432704f;

		internal const float MaxPalmLiftCm = 12.8f;

		internal const float MinExtraCm = -3f;

		internal const float MaxExtraCm = 6f;

		internal const float MaxAboveCrownCm = 2f;

		internal const float MinLiftCm = -3f;

		internal const float MaxLiftCm = 25f;

		internal const float Shipped103LiftCm = 9.596041f;

		internal const float Shipped102LiftCm = 7.596041f;

		internal const float DefaultLiftCm = 5.888967f;

		private static Align mode = Align.TopSurface;

		private static float extraCm;

		private static float liftCm = 5.888967f;

		internal static float MaxPalmLiftMesh => 0.16f;

		internal static Align Mode => mode;

		internal static float ExtraCm => extraCm;

		internal static float RequestedLiftCm => liftCm;

		internal static string Stamp => FormattableString.Invariant($"{mode}|{extraCm:F4}|{liftCm:F6}");

		internal static string Describe => FormattableString.Invariant($"gripMode={mode} extraCm={extraCm:F3} liftCm={liftCm:F4} defaultLiftCm={5.888967f:F4} stockTargetMeshY={TargetMeshY(mode):F6} stockUpMedianMeshY={0.085175686f:F6} stockCentroidMeshY={0.026834678f:F6} crownMeshY={0.130257f:F6}");

		internal static float ClampExtra(float extra)
		{
			if (float.IsFinite(extra))
			{
				if (!(extra < -3f))
				{
					if (!(extra > 6f))
					{
						return extra;
					}
					return 6f;
				}
				return -3f;
			}
			return 0f;
		}

		internal static float ClampLift(float lift)
		{
			if (float.IsFinite(lift))
			{
				if (!(lift < -3f))
				{
					if (!(lift > 25f))
					{
						return lift;
					}
					return 25f;
				}
				return -3f;
			}
			return 5.888967f;
		}

		internal static void Configure(Align align, float extra)
		{
			Configure(align, extra, liftCm);
		}

		internal static void Configure(Align align, float extra, float liftCentimeters)
		{
			if (!Enum.IsDefined(typeof(Align), align))
			{
				throw new ArgumentOutOfRangeException("align");
			}
			mode = align;
			extraCm = ClampExtra(extra);
			liftCm = ClampLift(liftCentimeters);
		}

		internal static void Configure(float liftCentimeters)
		{
			mode = Align.Lift;
			extraCm = 0f;
			liftCm = ClampLift(liftCentimeters);
		}

		internal static void RequireStock(Bounds stock)
		{
			//IL_0002: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			Fit.Require(Math.Abs(((Bounds)(ref stock)).min.y - -0.10027259f) <= 0.0001f && Math.Abs(((Bounds)(ref stock)).size.y - 0.23052958f) <= 0.0001f && Math.Abs(((Bounds)(ref stock)).min.x - -0.46431506f) <= 0.0001f, "stock cell bound is not the measured g_Generator_Cell body; grip calibration is stale");
		}

		internal static float ToPrefab(float meshY)
		{
			return meshY * 0.8f + 0.08021809f;
		}

		internal static float ToMesh(float prefabY)
		{
			return (prefabY - 0.08021809f) / 0.8f;
		}

		internal static float PalmTargetMeshY(float palmMeshY)
		{
			return palmMeshY + 0.0432704f;
		}

		internal static float TargetMeshY(Align align)
		{
			return align switch
			{
				Align.TopSurface => 0.085175686f, 
				Align.Centroid => 0.026834678f, 
				_ => -0.10027259f, 
			};
		}

		internal static float ArtMeshY(Align align, in GripSurface.Stats art)
		{
			return align switch
			{
				Align.TopSurface => art.UpMedianY, 
				Align.Centroid => art.CentroidY, 
				_ => art.MinY, 
			};
		}

		internal static Solution Solve(Bounds stock, in GripSurface.Stats art, float scale, Align align, float extraCm, float liftCm)
		{
			//IL_004d: 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_00f5: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			Fit.Require(art.Measured && float.IsFinite(scale) && scale > 0f, "grip solve without a measured art piece");
			float num = TargetMeshY(align) + ClampExtra(extraCm) / 80f;
			float num2 = ((align == Align.Lift) ? (((Bounds)(ref stock)).min.y - scale * art.MinY + ClampLift(liftCm) / 80f) : (num - scale * ArtMeshY(align, in art)));
			float num3 = Math.Max(-0.14354299f, -0.042305492f) - scale * art.MinY;
			float num4 = ((Bounds)(ref stock)).max.y + 0.025f - scale * art.MaxY;
			float num5 = (float.IsFinite(num2) ? num2 : num3);
			if (num3 > num4)
			{
				num5 = (num3 + num4) * 0.5f;
			}
			else if (num5 < num3)
			{
				num5 = num3;
			}
			else if (num5 > num4)
			{
				num5 = num4;
			}
			float num6 = num5 + scale * art.MinY;
			float num7 = num5 + scale * art.MaxY;
			return new Solution(num5, (num6 - ((Bounds)(ref stock)).min.y) * 80f, (num7 - ((Bounds)(ref stock)).min.y) * 80f, (num7 - ((Bounds)(ref stock)).max.y) * 80f, (num6 - -0.14354299f) * 80f, (num6 - -0.042305492f) * 80f, num5 != num2);
		}

		internal static Solution Solve(Bounds stock, in GripSurface.Stats art, float scale)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Solve(stock, in art, scale, mode, extraCm, liftCm);
		}
	}
	internal static class GripSurface
	{
		internal readonly struct Stats
		{
			internal readonly float MinY;

			internal readonly float MaxY;

			internal readonly float Area;

			internal readonly float UpArea;

			internal readonly float UpMeanY;

			internal readonly float UpMedianY;

			internal readonly float UpP90Y;

			internal readonly float CentroidY;

			internal bool Measured
			{
				get
				{
					if (float.IsFinite(MinY) && float.IsFinite(MaxY) && Area > 0f)
					{
						return UpArea > 0f;
					}
					return false;
				}
			}

			internal string Describe => FormattableString.Invariant($"minY={MinY:F6} maxY={MaxY:F6} area={Area:F5} upArea={UpArea:F5} upMean={UpMeanY:F6} upMedian={UpMedianY:F6} upP90={UpP90Y:F6} centroidY={CentroidY:F6}");

			internal Stats(float minY, float maxY, float area, float upArea, float upMeanY, float upMedianY, float upP90Y, float centroidY)
			{
				MinY = minY;
				MaxY = maxY;
				Area = area;
				UpArea = upArea;
				UpMeanY = upMeanY;
				UpMedianY = upMedianY;
				UpP90Y = upP90Y;
				CentroidY = centroidY;
			}
		}

		private const int MaxTriangles = 2000000;

		internal static Stats Measure(Mesh mesh, Matrix4x4 toMesh)
		{
			//IL_0012: 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)
			return Measure((Mesh[])(object)new Mesh[1] { mesh }, (Matrix4x4[])(object)new Matrix4x4[1] { toMesh });
		}

		internal static Stats Measure(Mesh[] meshes, Matrix4x4[] toMesh)
		{
			//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_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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			Fit.Require(meshes != null && toMesh != null && meshes.Length == toMesh.Length && meshes.Length != 0, "grip measurement needs one matrix per mesh");
			float num = float.PositiveInfinity;
			float num2 = float.NegativeInfinity;
			double num3 = 0.0;
			double num4 = 0.0;
			double num5 = 0.0;
			double num6 = 0.0;
			List<float> list = new List<float>();
			List<float> list2 = new List<float>();
			int num7 = 0;
			for (int i = 0; i < meshes.Length; i++)
			{
				Mesh val = meshes[i];
				Fit.Require((Object)(object)val != (Object)null && val.isReadable && val.subMeshCount >= 1 && val.vertexCount >= 3, "grip measurement needs readable triangles");
				Vector3[] array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)val.vertices);
				int[] array2 = Il2CppArrayBase<int>.op_Implicit((Il2CppArrayBase<int>)(object)val.triangles);
				Fit.Require(array2.Length % 3 == 0, "grip measurement triangle list");
				num7 += array2.Length / 3;
				Fit.Require(num7 <= 2000000, "grip measurement triangle count");
				Matrix4x4 val2 = toMesh[i];
				for (int j = 0; j < array2.Length; j += 3)
				{
					Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(array[array2[j]]);
					Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(array[array2[j + 1]]);
					Vector3 val5 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(array[array2[j + 2]]);
					Fit.Require(float.IsFinite(val3.y) && float.IsFinite(val4.y) && float.IsFinite(val5.y), "non-finite art vertex");
					num = Math.Min(num, Math.Min(val3.y, Math.Min(val4.y, val5.y)));
					num2 = Math.Max(num2, Math.Max(val3.y, Math.Max(val4.y, val5.y)));
					Vector3 val6 = Vector3.Cross(val4 - val3, val5 - val3);
					float magnitude = ((Vector3)(ref val6)).magnitude;
					if (magnitude > 1E-12f)
					{
						double num8 = (double)magnitude * 0.5;
						Vector3 val7 = (val3 + val4 + val5) / 3f;
						num3 += num8;
						num5 += num8 * (double)val7.y;
						float num9 = (float)(num8 * (double)Math.Max(val6.y / magnitude, 0f));
						if (num9 > 0f)
						{
							num4 += (double)num9;
							num6 += (double)(num9 * val7.y);
							list.Add(val7.y);
							list2.Add(num9);
						}
					}
				}
			}
			Fit.Require(double.IsFinite(num3) && double.IsFinite(num4) && num3 > 0.0 && num4 > 0.0 && list.Count > 0, "art has no upper surface");
			float[] array3 = list.ToArray();
			float[] array4 = list2.ToArray();
			Array.Sort(array3, array4);
			double num10 = 0.0;
			float[] array5 = array4;
			foreach (float num11 in array5)
			{
				num10 += (double)num11;
			}
			Fit.Require(num3 > 0.0 && num4 > 0.0 && list.Count > 0 && num10 > 0.0, "art has no upward-facing skin");
			Fit.Require(Math.Abs(num10 - num4) <= num4 * 1E-06 + 1E-12, "grip weight sum drifted");
			return new Stats(num, num2, (float)num3, (float)num4, (float)(num6 / num4), Quantile(array3, array4, num10, 0.5), Quantile(array3, array4, num10, 0.9), (float)(num5 / num3));
		}

		private static float Quantile(float[] sorted, float[] mass, double total, double q)
		{
			double num = 0.0;
			for (int i = 0; i < sorted.Length; i++)
			{
				num += (double)mass[i];
				if (num >= total * q)
				{
					return sorted[i];
				}
			}
			return sorted[^1];
		}
	}
	internal static class PalmSeat
	{
		internal static bool Enabled;

		private const float Scale = 0.72f;

		internal static void Bind(Transform body, Transform graphics, Item item, string phase)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			Transform val = body.Find("WCS.BatchVisual");
			Fit.Require((Object)(object)val != (Object)null && (Object)(object)((Component)val).GetComponent<BatchVisual>() != (Object)null, "FP private renderer missing");
			Transform val2 = graphics.Find("Generator_Cell_GripAlign/LeftHand");
			Fit.Require((Object)(object)val2 != (Object)null, "FP authored left grip missing");
			Matrix4x4 val3 = Fit.Relative(graphics, body);
			val3 = ((Matrix4x4)(ref val3)).inverse * Fit.Relative(graphics, val2);
			Fit.Require(Fit.Near(((Matrix4x4)(ref val3)).MultiplyPoint3x4(Vector3.zero), new Vector3(0.084919f, -0.14354299f, 0.077723f)), "FP grip geometry changed");
			Mesh sharedMesh = ((Component)val).GetComponent<MeshFilter>().sharedMesh;
			Bounds bounds = sharedMesh.bounds;
			Fit.Product product = Fit.Owned(sharedMesh) ?? throw new InvalidOperationException("Not our FP mesh");
			Bounds original = product.Original;
			Vector3 val4 = ((Bounds)(ref original)).center - ((Bounds)(ref bounds)).center * 0.72f;
			val4.x -= (((Bounds)(ref original)).size.x - ((Bounds)(ref bounds)).size.x * 0.72f) * 0.25f;
			float num = 0.72f * (product.Shift + product.Surface.UpMedianY * product.Scale);
			bool flag = Enabled && Grip.Mode == Grip.Align.TopSurface;
			val4.y = (flag ? (0.12167752f + Grip.ExtraCm / 80f - num) : (product.Shift * 0.27999997f));
			val.localScale = 0.72f * Vector3.one;
			val.localRotation = Quaternion.identity;
			val.localPosition = val4;
			ManualLogSource logSource = Plugin.LogSource;
			bool flag2 = default(bool);
			BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(74, 4, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("WCS_FP_GRIP phase=");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(phase);
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" mode=native-lid scale=");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(0.72f, "F2");
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" artOnly=True topMeshY=");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(num + val4.y, "F5");
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" stockP90=");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(0.12167752f, "F5");
			}
			logSource.LogInfo(val5);
		}

		internal static float Underside(Mesh mesh, float x, float z)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_008b: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)mesh.vertices);
			int[] array2 = Il2CppArrayBase<int>.op_Implicit((Il2CppArrayBase<int>)(object)mesh.triangles);
			float num = float.PositiveInfinity;
			for (int i = 0; i < array2.Length; i += 3)
			{
				Vector3 val = array[array2[i]];
				Vector3 val2 = array[array2[i + 1]] - val;
				Vector3 val3 = array[array2[i + 2]] - val;
				float num2 = val2.x * val3.z - val2.z * val3.x;
				if (!(Math.Abs(num2) < 1E-10f))
				{
					float num3 = x - val.x;
					float num4 = z - val.z;
					float num5 = (num3 * val3.z - num4 * val3.x) / num2;
					float num6 = (val2.x * num4 - val2.z * num3) / num2;
					if (num5 >= 0f && num6 >= 0f && num5 + num6 <= 1f)
					{
						num = Math.Min(num, val.y + num5 * val2.y + num6 * val3.y);
					}
				}
			}
			return num;
		}
	}
	[BepInPlugin("local.WhaleCellSkins", "Whale + Cell Skins", "1.0.15")]
	public sealed class Plugin : BasePlugin
	{
		internal static ManualLogSource LogSource;

		internal static string Root;

		internal static RenderFaultWatch Watcher;

		public override void Load()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			LogSource = ((BasePlugin)this).Log;
			Root = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
			ConfigEntry<bool> obj = ((BasePlugin)this).Config.Bind<bool>("Visuals", "EnableEmission", true, "已供电鲸鱼娘和优香 3080 的局部自发光。关闭后电桩仅以颜色表示供电。修改后重启生效。");
			ConfigEntry<Grip.Align> obj2 = ((BasePlugin)this).Config.Bind<Grip.Align>("FirstPerson", "Align", Grip.Align.TopSurface, "TopSurface:对齐主要顶面;Centroid:对齐表面几何重心高度;Lift:使用旧版手动高度。");
			ConfigEntry<float> val = ((BasePlugin)this).Config.Bind<float>("FirstPerson", "GripExtraCm", 0f, "顶面或重心对齐后微调的厘米数。");
			ConfigEntry<float> val2 = ((BasePlugin)this).Config.Bind<float>("FirstPerson", "GripLiftCm", 5.888967f, "仅在 Align=Lift 时使用的手动底面高度(厘米)。");
			PalmSeat.Enabled = ((BasePlugin)this).Config.Bind<bool>("FirstPerson", "FollowPalm", true, "TopSurface 模式下将显卡主顶盖对齐原版电池较高的可见表面,不移动双手。false 保留基础高度。").Value;
			Fit.ConfigureGrip(obj2.Value, val.Value, val2.Value);
			((BasePlugin)this).Log.LogInfo((object)("WCS " + Grip.Describe));
			Assets.SetEmission(obj.Value);
			ClassInjector.RegisterTypeInIl2Cpp<BatchVisual>();
			ClassInjector.RegisterTypeInIl2Cpp<GeneratorPlates>();
			Harmony val3 = new Harmony("local.WhaleCellSkins");
			Targets.Install(val3);
			if (((BasePlugin)this).Config.Bind<bool>("Compatibility", "GuardDecayShadow", true, "跳过缺少渲染器的活跃尸体衰减副本,避免打断场景绘制。").Value)
			{
				try
				{
					DecayShadowGuard.Install(val3);
				}
				catch (Exception ex)
				{
					((BasePlugin)this).Log.LogWarning((object)("Decay shadow guard unavailable: " + ex.Message));
				}
			}
			if (((BasePlugin)this).Config.Bind<bool>("Diagnostics", "WatchRenderFaults", true, "仅在指定的相机空引用异常后检查阴影绘制列表;只移除空项,其他原因仅记录。").Value)
			{
				try
				{
					Watcher = ((BasePlugin)this).AddComponent<RenderFaultWatch>();
				}
				catch (Exception ex2)
				{
					((BasePlugin)this).Log.LogWarning((object)("Render fault watcher unavailable: " + ex2.Message));
				}
			}
			((BasePlugin)this).Log.LogInfo((object)"Ready; skin emission is controlled by [Visuals] EnableEmission in local.WhaleCellSkins.cfg.");
		}
	}
	public sealed class RenderFaultWatch : MonoBehaviour
	{
		private LogCallback listener;

		private bool pending;

		private float next;

		private string cameraAtFault;

		private Camera cameraRef;

		private int burst;

		private int countAtFault = -2;

		private float burstStart;

		private float lastFault;

		public RenderFaultWatch(IntPtr ptr)
			: base(ptr)
		{
		}

		private void OnEnable()
		{
			if (listener == null)
			{
				listener = LogCallback.op_Implicit((Action<string, string, LogType>)Observe);
				Application.logMessageReceived += listener;
			}
		}

		private void OnDisable()
		{
			if (listener != null)
			{
				Application.logMessageReceived -= listener;
			}
			listener = null;
			pending = false;
			burst = 0;
		}

		internal static bool Matches(string message, string trace, LogType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if (((int)type == 4 || (int)type == 0) && message != null && message.Contains("NullReferenceException", StringComparison.Ordinal) && trace != null && trace.Contains("RenderPipe.GatherCommands", StringComparison.Ordinal))
			{
				return trace.Contains("RenderPipe.OnCameraPreCull", StringComparison.Ordinal);
			}
			return false;
		}

		private void Observe(string message, string trace, LogType type)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!Matches(message, trace, type))
			{
				return;
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (burst == 0)
			{
				burstStart = realtimeSinceStartup;
				countAtFault = Count();
			}
			burst++;
			lastFault = realtimeSinceStartup;
			if (pending || realtimeSinceStartup < next)
			{
				return;
			}
			pending = true;
			try
			{
				Camera val = (cameraRef = Camera.current);
				cameraAtFault = (((Object)(object)val == (Object)null) ? "unavailable" : (((Object)val).name + "/" + ((object)val.actualRenderingPath/*cast due to .constrained prefix*/).ToString()));
			}
			catch
			{
				cameraRef = null;
				cameraAtFault = "unavailable";
			}
		}

		private void Update()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			if (pending)
			{
				pending = false;
				next = Time.realtimeSinceStartup + 5f;
				Report();
			}
			else if (burst > 0 && Time.realtimeSinceStartup - lastFault > 1f)
			{
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(59, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("WCS_RENDER_BURST faults=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(burst);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" seconds=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(lastFault - burstStart, "0.00");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" countAtStart=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(countAtFault);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" action=none");
				}
				logSource.LogWarning(val);
				burst = 0;
			}
		}

		private void Report()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			try
			{
				int count;
				int num = PruneNulls(out count);
				Plugin.LogSource.LogWarning((object)($"WCS_RENDER_FAULT camera={cameraAtFault} faults={burst} countAtFault={countAtFault} shadowEntries={count} deadRemoved={num} action=" + ((num > 0) ? "removed-empty-entries" : "diagnostic-only") + " " + FaultCameraData() + " " + Snapshot()));
			}
			catch (Exception ex)
			{
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(75, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("WCS_RENDER_FAULT camera=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(cameraAtFault);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" faults=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(burst);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" countAtFault=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(countAtFault);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" unable to inspect registry: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.GetType().Name);
				}
				logSource.LogWarning(val);
			}
		}

		private string FaultCameraData()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder("faultCameraData=");
			try
			{
				Dictionary<Camera, CameraData> s_cameraData = RenderPipe.s_cameraData;
				if (s_cameraData == null || (Object)(object)cameraRef == (Object)null)
				{
					return stringBuilder.Append("none").ToString();
				}
				if (!s_cameraData.ContainsKey(cameraRef))
				{
					return stringBuilder.Append("absent").ToSt