Decompiled source of New Descents v1.1.0

New Descents.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using CUCoreLib.ContentReload;
using CUCoreLib.Data;
using CUCoreLib.Helpers;
using CUCoreLib.Networking;
using CUCoreLib.Registries;
using CUCoreLib.Saving;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.Tilemaps;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+d2883d34b6931d49aa4c85a7cd7da4dac421bcf5")]
[assembly: AssemblyProduct("Template description")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace New_Descents
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "New Descents";

		public const string PLUGIN_NAME = "Template description";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace NewDescents
{
	internal static class AsepriteAnimation
	{
		private sealed class Layer
		{
			internal bool Visible;

			internal byte Opacity;
		}

		private sealed class Cel
		{
			internal int Layer;

			internal int X;

			internal int Y;

			internal byte Opacity;

			internal int LinkFrame = -1;

			internal int Width;

			internal int Height;

			internal Color32[] Pixels;
		}

		private sealed class Frame
		{
			internal int DurationMs;

			internal readonly List<Cel> Cels = new List<Cel>();
		}

		private sealed class Tag
		{
			internal string Name;

			internal int From;

			internal int To;
		}

		private const int HeaderSize = 128;

		private const ushort FileMagic = 42464;

		private const ushort FrameMagic = 61946;

		private const ushort ChunkPalette = 4;

		private const ushort ChunkLayer = 8196;

		private const ushort ChunkCel = 8197;

		private const ushort ChunkTag = 8216;

		internal static RegisteredSpriteAnimation Load(string id, string resource, string tag = null, float pixelsPerUnit = 8f)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(resource))
			{
				return null;
			}
			if (!TryReadEmbedded(resource, out var data))
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogError((object)("AsepriteAnimation: '" + resource + "' is not embedded in this mod."));
				}
				return null;
			}
			if (!TryDecode(data, resource, out var width, out var height, out var layers, out var frames, out var tags))
			{
				return null;
			}
			List<int> list = ResolveRange(tags, tag, frames.Count, resource);
			if (list == null || list.Count == 0)
			{
				return null;
			}
			Sprite[] array = (Sprite[])(object)new Sprite[list.Count];
			for (int i = 0; i < list.Count; i++)
			{
				Texture2D val = Bake(id + "_" + i, width, height, layers, frames[list[i]]);
				if ((Object)(object)val == (Object)null)
				{
					ManualLogSource logger2 = Plugin.Logger;
					if (logger2 != null)
					{
						logger2.LogError((object)$"AsepriteAnimation: frame {list[i]} of '{resource}' is empty.");
					}
					return null;
				}
				array[i] = Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), pixelsPerUnit, 0u, (SpriteMeshType)0);
				((Object)array[i]).name = id + "_" + i;
			}
			float num = FramesPerSecond(list, frames, resource);
			RegisteredSpriteAnimation obj = AssetLoader.RegisterFrameAnimation(id, (IEnumerable<Sprite>)array, num, true);
			Report(obj, id, list.Count, width, height, num);
			return obj;
		}

		private static void Report(RegisteredSpriteAnimation animation, string id, int frameCount, int width, int height, float framesPerSecond)
		{
			RegisteredSpriteAnimation cachedSpriteAnimation = AssetLoader.GetCachedSpriteAnimation(id);
			bool flag = cachedSpriteAnimation != null && cachedSpriteAnimation.Frames != null && cachedSpriteAnimation.Frames.Length != 0 && (Object)(object)cachedSpriteAnimation.Frames[0] != (Object)null;
			ManualLogSource logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogDebug((object)($"AsepriteAnimation: '{id}' baked {frameCount} frame(s) of {width}x{height} at " + $"{framesPerSecond:0.#} fps, cache reads back " + (flag ? $"{cachedSpriteAnimation.Frames.Length} frame(s)" : "NOTHING") + "."));
			}
			if (animation == null || !flag)
			{
				ManualLogSource logger2 = Plugin.Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)("AsepriteAnimation: '" + id + "' did not reach CUCoreLib's animation cache, so nothing will play it."));
				}
			}
		}

		private static float FramesPerSecond(IList<int> order, IList<Frame> frames, string resource)
		{
			int num = 0;
			foreach (int item in order)
			{
				num += Math.Max(1, frames[item].DurationMs);
			}
			if (order.Select((int index) => frames[index].DurationMs).Distinct().Count() > 1)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogWarning((object)("AsepriteAnimation: '" + resource + "' has uneven frame durations; playing the loop at their average."));
				}
			}
			return 1000f / ((float)num / (float)order.Count);
		}

		private static List<int> ResolveRange(IList<Tag> tags, string tag, int frameCount, string resource)
		{
			if (string.IsNullOrWhiteSpace(tag))
			{
				return Enumerable.Range(0, frameCount).ToList();
			}
			Tag tag2 = tags.FirstOrDefault((Tag t) => string.Equals(t.Name, tag, StringComparison.OrdinalIgnoreCase));
			if (tag2 == null)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogError((object)("AsepriteAnimation: '" + resource + "' has no tag '" + tag + "'."));
				}
				return null;
			}
			if (tag2.From < 0 || tag2.To < tag2.From || tag2.To >= frameCount)
			{
				ManualLogSource logger2 = Plugin.Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)("AsepriteAnimation: tag '" + tag + "' of '" + resource + "' covers frames " + $"{tag2.From}-{tag2.To} of {frameCount}."));
				}
				return null;
			}
			return Enumerable.Range(tag2.From, tag2.To - tag2.From + 1).ToList();
		}

		private static Texture2D Bake(string name, int width, int height, IList<Layer> layers, Frame frame)
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[width * height];
			foreach (Cel cel in frame.Cels)
			{
				if (cel.Layer < 0 || cel.Layer >= layers.Count)
				{
					continue;
				}
				Layer layer = layers[cel.Layer];
				if (!layer.Visible || cel.Pixels == null)
				{
					continue;
				}
				float num = (float)(int)cel.Opacity / 255f * ((float)(int)layer.Opacity / 255f);
				if (num <= 0f)
				{
					continue;
				}
				for (int i = 0; i < cel.Height; i++)
				{
					int num2 = cel.Y + i;
					if (num2 < 0 || num2 >= height)
					{
						continue;
					}
					for (int j = 0; j < cel.Width; j++)
					{
						int num3 = cel.X + j;
						if (num3 >= 0 && num3 < width)
						{
							BlendOver(ref array[num2 * width + num3], cel.Pixels[i * cel.Width + j], num);
						}
					}
				}
			}
			bool flag = false;
			for (int k = 0; k < array.Length; k++)
			{
				if (array[k].a != 0)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return null;
			}
			Color32[] array2 = (Color32[])(object)new Color32[width * height];
			for (int l = 0; l < height; l++)
			{
				Array.Copy(array, (height - 1 - l) * width, array2, l * width, width);
			}
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				name = name + " (aseprite)"
			};
			val.SetPixels32(array2);
			val.Apply(false);
			return val;
		}

		private static void BlendOver(ref Color32 destination, Color32 source, float stacking)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)(int)source.a / 255f * stacking;
			if (!(num <= 0f))
			{
				float num2 = (float)(int)destination.a / 255f;
				float num3 = 1f - num;
				float num4 = num + num2 * num3;
				if (num4 <= 0f)
				{
					destination = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
				}
				else
				{
					destination = new Color32((byte)Mathf.Clamp(((float)(int)source.r * num + (float)(int)destination.r * num2 * num3) / num4, 0f, 255f), (byte)Mathf.Clamp(((float)(int)source.g * num + (float)(int)destination.g * num2 * num3) / num4, 0f, 255f), (byte)Mathf.Clamp(((float)(int)source.b * num + (float)(int)destination.b * num2 * num3) / num4, 0f, 255f), (byte)Mathf.Clamp(num4 * 255f, 0f, 255f));
				}
			}
		}

		private static bool TryDecode(byte[] data, string resource, out int width, out int height, out List<Layer> layers, out List<Frame> frames, out List<Tag> tags)
		{
			width = (height = 0);
			layers = new List<Layer>();
			frames = new List<Frame>();
			tags = new List<Tag>();
			BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			try
			{
				binaryReader.ReadUInt32();
				if (binaryReader.ReadUInt16() != 42464)
				{
					ManualLogSource logger = Plugin.Logger;
					if (logger != null)
					{
						logger.LogError((object)((data.Length > 3 && data[0] == 80 && data[1] == 75) ? ("AsepriteAnimation: '" + resource + "' is a compressed Aseprite file. Save it with File > Save As with 'Compress' off.") : ("AsepriteAnimation: '" + resource + "' is not an Aseprite file.")));
					}
					return false;
				}
				ushort num = binaryReader.ReadUInt16();
				width = binaryReader.ReadUInt16();
				height = binaryReader.ReadUInt16();
				ushort num2 = binaryReader.ReadUInt16();
				if (num2 != 32 || width <= 0 || height <= 0 || num == 0)
				{
					ManualLogSource logger2 = Plugin.Logger;
					if (logger2 != null)
					{
						logger2.LogError((object)($"AsepriteAnimation: '{resource}' is {num2}-bit. Only RGB (32-bit) " + "files carry per-pixel colour and alpha; use Sprite > Convert to > RGB Color."));
					}
					return false;
				}
				long num3 = 128L;
				for (int i = 0; i < num; i++)
				{
					binaryReader.BaseStream.Position = num3;
					uint num4 = binaryReader.ReadUInt32();
					if (binaryReader.ReadUInt16() != 61946)
					{
						ManualLogSource logger3 = Plugin.Logger;
						if (logger3 != null)
						{
							logger3.LogError((object)$"AsepriteAnimation: frame {i} of '{resource}' has no frame header.");
						}
						return false;
					}
					ushort num5 = binaryReader.ReadUInt16();
					Frame frame = new Frame
					{
						DurationMs = binaryReader.ReadUInt16()
					};
					binaryReader.ReadUInt16();
					uint num6 = binaryReader.ReadUInt32();
					if (num5 == ushort.MaxValue)
					{
						num5 = (ushort)num6;
					}
					frames.Add(frame);
					long num7 = num3 + num4;
					num3 += 16;
					for (int j = 0; j < num5; j++)
					{
						uint num8 = binaryReader.ReadUInt32();
						ushort num9 = binaryReader.ReadUInt16();
						if (num8 < 6 || binaryReader.BaseStream.Position + num8 - 6 > num7)
						{
							ManualLogSource logger4 = Plugin.Logger;
							if (logger4 != null)
							{
								logger4.LogError((object)($"AsepriteAnimation: chunk {num9:X4} of frame {i} in " + "'" + resource + "' runs past its frame."));
							}
							return false;
						}
						byte[] body = binaryReader.ReadBytes((int)(num8 - 6));
						switch (num9)
						{
						case 8196:
							ReadLayer(body, layers);
							break;
						case 8197:
							ReadCel(body, i, resource, frame);
							break;
						case 8216:
							ReadTags(body, tags);
							break;
						}
						num3 += num8;
					}
					if (num3 != num7)
					{
						ManualLogSource logger5 = Plugin.Logger;
						if (logger5 != null)
						{
							logger5.LogError((object)($"AsepriteAnimation: frame {i} of '{resource}' holds " + $"{num5} chunk(s) that do not fill its {num4} bytes."));
						}
						return false;
					}
				}
				if (num3 != data.Length)
				{
					ManualLogSource logger6 = Plugin.Logger;
					if (logger6 != null)
					{
						logger6.LogError((object)($"AsepriteAnimation: '{resource}' has {data.Length - num3} byte(s) " + "after its last frame."));
					}
					return false;
				}
				ResolveLinks(frames, resource);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logger7 = Plugin.Logger;
				if (logger7 != null)
				{
					logger7.LogError((object)("AsepriteAnimation: '" + resource + "' could not be read: " + ex.Message));
				}
				return false;
			}
			finally
			{
				binaryReader.Dispose();
			}
		}

		private static void ReadLayer(byte[] body, List<Layer> layers)
		{
			layers.Add(new Layer
			{
				Visible = ((body[0] & 1) != 0),
				Opacity = ((body.Length > 12) ? body[12] : byte.MaxValue)
			});
		}

		private static void ReadTags(byte[] body, List<Tag> tags)
		{
			int num = body[0] | (body[1] << 8);
			int num2 = 10;
			for (int i = 0; i < num; i++)
			{
				if (num2 + 19 > body.Length)
				{
					break;
				}
				int num3 = body[num2 + 17] | (body[num2 + 18] << 8);
				if (num2 + 19 + num3 <= body.Length)
				{
					tags.Add(new Tag
					{
						From = (body[num2] | (body[num2 + 1] << 8)),
						To = (body[num2 + 2] | (body[num2 + 3] << 8)),
						Name = Encoding.UTF8.GetString(body, num2 + 19, num3)
					});
					num2 += 19 + num3;
					continue;
				}
				break;
			}
		}

		private static void ReadCel(byte[] body, int frameIndex, string resource, Frame frame)
		{
			if (body.Length < 9)
			{
				return;
			}
			Cel cel = new Cel
			{
				Layer = (body[0] | (body[1] << 8)),
				X = (short)(body[2] | (body[3] << 8)),
				Y = (short)(body[4] | (body[5] << 8)),
				Opacity = body[6]
			};
			frame.Cels.Add(cel);
			int num = body[7] | (body[8] << 8);
			switch (num)
			{
			case 1:
				if (body.Length >= 18)
				{
					cel.LinkFrame = body[16] | (body[17] << 8);
				}
				break;
			default:
			{
				ManualLogSource logger2 = Plugin.Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)($"AsepriteAnimation: cel {frameIndex} of '{resource}' is tilemap-" + "compressed, which this loader cannot read."));
				}
				break;
			}
			case 0:
			case 2:
			{
				if (body.Length < 20)
				{
					break;
				}
				cel.Width = body[16] | (body[17] << 8);
				cel.Height = body[18] | (body[19] << 8);
				if (cel.Width <= 0 || cel.Height <= 0 || cel.Width > 4096 || cel.Height > 4096)
				{
					break;
				}
				byte[] array = ((num == 2) ? Inflate(body, 22, body.Length - 22, resource, frameIndex) : Slice(body, 20, body.Length - 20));
				cel.Pixels = ReadPixels(array, cel.Width, cel.Height);
				if (cel.Pixels == null)
				{
					ManualLogSource logger = Plugin.Logger;
					if (logger != null)
					{
						logger.LogError((object)($"AsepriteAnimation: cel {frameIndex} of '{resource}' holds " + $"{((array != null) ? array.Length : 0)} byte(s), not the {cel.Width * cel.Height * 4} of a " + $"{cel.Width}x{cel.Height} RGBA image."));
					}
				}
				break;
			}
			}
		}

		private static Color32[] ReadPixels(byte[] stream, int width, int height)
		{
			if (stream == null)
			{
				return null;
			}
			int num = width * height;
			if (stream.Length == num * 4)
			{
				return ToPixels(stream, num);
			}
			byte[] array = new byte[num * 4];
			int num2 = 0;
			int num3 = 0;
			for (int i = 0; i < height; i++)
			{
				int num4;
				for (int j = 0; j < width; j += num4)
				{
					if (num3 + 2 > stream.Length)
					{
						return null;
					}
					num4 = stream[num3] | (stream[num3 + 1] << 8);
					num3 += 2;
					if (num4 > width - j || num3 + num4 * 4 > stream.Length)
					{
						return null;
					}
					Array.Copy(stream, num3, array, num2, num4 * 4);
					num3 += num4 * 4;
					num2 += num4 * 4;
				}
			}
			if (num3 != stream.Length)
			{
				return null;
			}
			return ToPixels(array, num);
		}

		private static void ResolveLinks(List<Frame> frames, string resource)
		{
			foreach (Frame frame in frames)
			{
				for (int i = 0; i < frame.Cels.Count; i++)
				{
					Cel cel = frame.Cels[i];
					if (cel.Pixels != null || cel.LinkFrame < 0)
					{
						continue;
					}
					int linkFrame = cel.LinkFrame;
					while (linkFrame >= 0 && linkFrame < frames.Count)
					{
						Cel cel2 = frames[linkFrame].Cels.FirstOrDefault((Cel c) => c.Layer == cel.Layer);
						if (cel2 == null)
						{
							break;
						}
						if (cel2.Pixels == null)
						{
							linkFrame = cel2.LinkFrame;
							continue;
						}
						cel.Width = cel2.Width;
						cel.Height = cel2.Height;
						cel.Pixels = cel2.Pixels;
						break;
					}
					if (cel.Pixels == null)
					{
						ManualLogSource logger = Plugin.Logger;
						if (logger != null)
						{
							logger.LogError((object)("AsepriteAnimation: a cel of '" + resource + "' links to frame " + $"{cel.LinkFrame}, which holds no pixels for that layer."));
						}
					}
				}
			}
		}

		private static Color32[] ToPixels(byte[] stream, int count)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = new Color32(stream[i * 4], stream[i * 4 + 1], stream[i * 4 + 2], stream[i * 4 + 3]);
			}
			return array;
		}

		private static byte[] Slice(byte[] body, int from, int length)
		{
			if (length <= 0 || from < 0 || from + length > body.Length)
			{
				return null;
			}
			byte[] array = new byte[length];
			Array.Copy(body, from, array, 0, length);
			return array;
		}

		private static byte[] Inflate(byte[] body, int from, int length, string resource, int frameIndex)
		{
			byte[] array = Slice(body, from, length);
			if (array == null)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogError((object)($"AsepriteAnimation: cel {frameIndex} of '{resource}' is not long " + "enough to hold a zlib stream."));
				}
				return null;
			}
			try
			{
				using MemoryStream stream = new MemoryStream(array, writable: false);
				using DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress);
				using MemoryStream memoryStream = new MemoryStream();
				deflateStream.CopyTo(memoryStream);
				return memoryStream.ToArray();
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = Plugin.Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)($"AsepriteAnimation: cel {frameIndex} of '{resource}' did not " + "inflate: " + ex.Message));
				}
				return null;
			}
		}

		private static bool TryReadEmbedded(string resource, out byte[] data)
		{
			data = null;
			Assembly assembly = typeof(AsepriteAnimation).Assembly;
			string normalized = resource.Trim().Replace('/', '.').Replace('\\', '.');
			string[] manifestResourceNames = assembly.GetManifestResourceNames();
			string text = manifestResourceNames.FirstOrDefault((string n) => string.Equals(n, normalized, StringComparison.OrdinalIgnoreCase)) ?? manifestResourceNames.FirstOrDefault((string n) => n.EndsWith("." + normalized, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				return false;
			}
			using (Stream stream = assembly.GetManifestResourceStream(text))
			{
				if (stream == null)
				{
					return false;
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				data = memoryStream.ToArray();
			}
			if (data != null)
			{
				return data.Length > 128;
			}
			return false;
		}
	}
	internal static class BodyEat
	{
		internal static readonly MethodInfo Method = (from m in AccessTools.GetDeclaredMethods(typeof(Body))
			where m.Name == "Eat" && !m.IsStatic
			orderby m.GetParameters().Length descending
			select m).FirstOrDefault();

		internal static void Invoke(Body body, float hungerAmount, float weightGain, int foodType)
		{
			if (!((Object)(object)body == (Object)null) && !(Method == null))
			{
				object[] parameters = ((Method.GetParameters().Length < 3) ? new object[2] { hungerAmount, weightGain } : new object[3] { hungerAmount, weightGain, foodType });
				Method.Invoke(body, parameters);
			}
		}
	}
	internal static class ConditionResets
	{
		internal const float LastStandKeep = 0.3f;

		internal const float LastStandDialKeep = 0.75f;

		internal static void OnHealed(Body body)
		{
			if (!((Object)(object)body == (Object)null))
			{
				ToxicPoisonStatus status = StatusExtensions.GetStatus<ToxicPoisonStatus>(body);
				status.Exposure = 0f;
				status.LastToxicWasteTouchTime = -1000f;
				VisceraeDigestionStatus status2 = StatusExtensions.GetStatus<VisceraeDigestionStatus>(body);
				status2.Exposure = 0f;
				status2.LastTouch = -1000f;
				StatusExtensions.GetStatus<VisceraeParasiteStatus>(body).Amount = 0f;
				StatusExtensions.GetStatus<VisceraeIchorBurnStatus>(body).Exposure = 0f;
				StatusExtensions.GetStatus<VisceraeAssimilationStatus>(body).Progress = 0f;
			}
		}

		internal static void OnLastStand()
		{
			Body val = CUCoreUtils.EventPlayer ?? (((Object)(object)PlayerCamera.main != (Object)null) ? PlayerCamera.main.body : null);
			if (!((Object)(object)val == (Object)null))
			{
				StatusExtensions.GetStatus<ToxicPoisonStatus>(val).Exposure *= 0.3f;
				StatusExtensions.GetStatus<VisceraeDigestionStatus>(val).Exposure *= 0.3f;
				StatusExtensions.GetStatus<VisceraeParasiteStatus>(val).Amount *= 0.3f;
				StatusExtensions.GetStatus<VisceraeIchorBurnStatus>(val).Exposure *= 0.3f;
				StatusExtensions.GetStatus<VisceraeAssimilationStatus>(val).Progress *= 0.75f;
			}
		}
	}
	internal static class DebugStartLayer
	{
		[HarmonyPatch]
		internal static class MenuLaunchPatch
		{
			private static bool consumed;

			[HarmonyPatch(typeof(PreRunScript), "Start")]
			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "net.cucorelib" })]
			private static void LaunchSelectedLayer(PreRunScript __instance)
			{
				if (!consumed)
				{
					consumed = true;
					if (SelectedLayer() > 0 && AutoLaunch())
					{
						Launch(__instance);
					}
				}
			}
		}

		[HarmonyPatch(typeof(PreRunScript), "StartRun")]
		internal static class ReplaceMenuStartPatch
		{
			[HarmonyPrefix]
			private static bool ReplaceStart(PreRunScript __instance)
			{
				if (SelectedLayer() <= 0 || !ReplaceMenuStart())
				{
					runStartedFromDebug = false;
					return true;
				}
				Launch(__instance);
				return false;
			}
		}

		[HarmonyPatch(typeof(SettingsMenu), "SelectTab", new Type[] { typeof(SettingCategory) })]
		internal static class PlayButtonPatch
		{
			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "net.cucorelib" })]
			private static void AddPlayButton(SettingsMenu __instance, SettingCategory category, List<GameObject> ___spawnedSettings)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: 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_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cf: Expected O, but got Unknown
				int num = (from s in Settings.GetAllSettings()
					where s.category == category
					select s).ToList().FindIndex((Setting s) => s.name == "newdescents.debug.startlayer");
				if (num < 0 || num >= ___spawnedSettings.Count)
				{
					return;
				}
				RectTransform component = ___spawnedSettings[num].GetComponent<RectTransform>();
				GameObject val = Utils.Create("Special/GameSettingInput", (Transform)(object)__instance.content);
				RectTransform component2 = val.GetComponent<RectTransform>();
				float y = component2.sizeDelta.y;
				foreach (GameObject ___spawnedSetting in ___spawnedSettings)
				{
					RectTransform component3 = ___spawnedSetting.GetComponent<RectTransform>();
					if (component3.anchoredPosition.y < component.anchoredPosition.y)
					{
						component3.anchoredPosition -= new Vector2(0f, y);
					}
				}
				component2.anchoredPosition = component.anchoredPosition - new Vector2(0f, (component.sizeDelta.y + y) * 0.5f);
				RectTransform content = __instance.content;
				content.sizeDelta += new Vector2(0f, y);
				((TMP_Text)((Component)val.transform.GetChild(0)).GetComponent<TextMeshProUGUI>()).text = "";
				Button component4 = ((Component)val.transform.GetChild(1)).GetComponent<Button>();
				((TMP_Text)((Component)component4).GetComponentInChildren<TextMeshProUGUI>()).text = "Play";
				((Selectable)component4).interactable = (Object)(object)PreRunScript.instance != (Object)null && !Object.op_Implicit((Object)(object)WorldGeneration.world);
				((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
				{
					if (!((Object)(object)PreRunScript.instance == (Object)null))
					{
						Launch(PreRunScript.instance);
						__instance.Close();
					}
				});
				___spawnedSettings.Add(val);
			}
		}

		[HarmonyPatch(typeof(Body), "Awake")]
		internal static class CharacterPatch
		{
			[HarmonyPrefix]
			private static void ApplyCharacter(Body __instance)
			{
				if (runStartedFromDebug && !SaveSystem.loadedRun)
				{
					__instance.charType = SelectedCharacter();
				}
			}
		}

		internal const string LayerId = "newdescents.debug.startlayer";

		internal const string AutoLaunchId = "newdescents.debug.autolaunch";

		internal const string ReplaceMenuStartId = "newdescents.debug.replacemenustart";

		internal const string CharacterId = "newdescents.debug.character";

		private const int OffChoice = 0;

		internal const int CharExperiment = 0;

		internal const int CharMilky = 1;

		internal const int CharDune = 2;

		private static bool runStartedFromDebug;

		private static readonly FieldInfo CharacterSelectedField = AccessTools.Field(typeof(PreRunScript), "characterSelected");

		private static WorldGeneration kitGivenFor;

		private static int kitItemCount;

		internal static void Register()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			ModOptionsRegistry.Register(ModOptionDefinition.Dropdown("newdescents.debug.startlayer", "Start layer <size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", "Starts your run off at a chosen layer, with weighted random equipment and stats.", "<size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", 0, (ModDropdownChoice[])(object)new ModDropdownChoice[15]
			{
				new ModDropdownChoice("off", "Off"),
				new ModDropdownChoice("layer1", "Gravel lands"),
				new ModDropdownChoice("layer2", "Deeper gravel lands"),
				new ModDropdownChoice("layer3", "Dried desert"),
				new ModDropdownChoice("layer4", "Wasteland"),
				new ModDropdownChoice("layer5", "Overgrown depths"),
				new ModDropdownChoice("toxic", "Toxic Caverns"),
				new ModDropdownChoice("viscerae", "Viscerae"),
				new ModDropdownChoice("layer6", "Frozen chasm"),
				new ModDropdownChoice("layer7", "Fungal pools"),
				new ModDropdownChoice("layer8", "Crystalline hollow"),
				new ModDropdownChoice("layer9", "Geothermal vents"),
				new ModDropdownChoice("layer10", "WHERE WE MUST REACH"),
				new ModDropdownChoice("layer11", "CRIMSON ASCENT"),
				new ModDropdownChoice("layer12", "Earth / A lab, somewhere…")
			}, (Action<int>)null));
			ModOptionsRegistry.Register(ModOptionDefinition.Bool("newdescents.debug.autolaunch", "Debug start <size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", "Skips the menu and launches straight into the chosen start layer when the game loads.", "<size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", false, (Action<bool>)null));
			ModOptionsRegistry.Register(ModOptionDefinition.Bool("newdescents.debug.replacemenustart", "Replace menu start <size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", "When enabled, starting a new run from the main menu uses the chosen start layer and character. Otherwise they only apply via the Play button below or auto-launch.", "<size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", false, (Action<bool>)null));
			ModOptionsRegistry.Register(ModOptionDefinition.Dropdown("newdescents.debug.character", "Character <size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", "Select which character to play as when starting at a chosen layer. Locked characters are not offered.", "<size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", 0, (ModDropdownChoice[])(object)new ModDropdownChoice[3]
			{
				new ModDropdownChoice("experiment", "Experiment"),
				new ModDropdownChoice("milky", "Milky"),
				new ModDropdownChoice("dune", "Dune")
			}, (Action<int>)null));
		}

		private static int SelectedLayer()
		{
			return Settings.Get<SettingDropdown>("newdescents.debug.startlayer")?.value ?? 0;
		}

		private static bool AutoLaunch()
		{
			return Settings.Get<SettingBool>("newdescents.debug.autolaunch")?.value ?? false;
		}

		private static bool ReplaceMenuStart()
		{
			return Settings.Get<SettingBool>("newdescents.debug.replacemenustart")?.value ?? false;
		}

		internal static int SelectedCharacter()
		{
			return Settings.Get<SettingDropdown>("newdescents.debug.character")?.value ?? 0;
		}

		private static void Launch(PreRunScript menu)
		{
			if (!((Object)(object)GlobalDark.main != (Object)null) || !GlobalDark.main.IsDarkening())
			{
				runStartedFromDebug = true;
				CharacterSelectedField?.SetValue(null, SelectedCharacter());
				SaveSystem.loadedRun = false;
				WorldGeneration.runSettings = menu.runSettings;
				((MonoBehaviour)menu).StartCoroutine(menu.WaitLoad());
			}
		}

		internal static void ApplyOnWorldAwake(WorldGeneration world)
		{
			int num = SelectedLayer();
			if (num > 0 && !SaveSystem.loadedRun && runStartedFromDebug && (!LayerRouting.Demo || num <= 7))
			{
				LayerRouting.Biome biome = num switch
				{
					7 => LayerRouting.Biome.Viscerae, 
					6 => LayerRouting.Biome.Toxic, 
					_ => LayerRouting.Biome.Vanilla, 
				};
				int num2 = ((num <= 5) ? (num - 1) : ((num <= 7) ? LayerRouting.CustomDepth(biome) : (num - 3)));
				if (num2 < world.amountOfLayers)
				{
					LayerRouting.DebugStart(world, num2, biome);
				}
			}
		}

		internal static void GiveStarterKit(WorldGeneration world)
		{
			if ((Object)(object)kitGivenFor == (Object)(object)world)
			{
				return;
			}
			int num = SelectedLayer();
			if (num <= 0 || SaveSystem.loadedRun || !runStartedFromDebug)
			{
				return;
			}
			kitGivenFor = world;
			Body body = PlayerCamera.main.body;
			int biomeDepth = world.biomeDepth;
			body.skills.AddExp(0, (float)biomeDepth * 210f);
			body.skills.AddExp(1, (float)biomeDepth * 220f);
			body.skills.AddExp(2, (float)biomeDepth * 150f);
			switch (Mathf.Min(num, 7))
			{
			case 2:
				Give(body, "foliagebag");
				Give(body, "slingbag");
				Give(body, "emergencylight");
				Give(body, "flimsyknife");
				GiveFilled(body, "canteen", "biochem", 150f);
				GiveCraftable(body, 5);
				break;
			case 3:
				Give(body, "foliagebag", 2);
				GiveRandom(body, "container", 2);
				Give(body, "makeshifthelmet");
				Give(body, "firestarter");
				Give(body, "makeshiftdiggingtool");
				Give(body, "machete");
				GiveFilled(body, "canteen", "biochem", 300f);
				GiveRandom(body, "water", 1);
				GiveDressings(body, 1);
				GiveRandom(body, "drug", 3);
				GiveRandom(body, "utility", 2);
				break;
			case 4:
				Give(body, "bigpack");
				GiveRandom(body, "container", 4, "bigpack");
				Give(body, "makeshifthelmet");
				Give(body, "pickaxe");
				Give(body, "machete");
				Give(body, "wrench");
				Give(body, "flashlight");
				GiveFilled(body, "saline", "biochem", 300f);
				GiveDressings(body, 1);
				GiveRandom(body, "drug", 4);
				GiveRandom(body, "utility", 4);
				GiveRandom(body, "water", 2);
				break;
			case 5:
				Give(body, "bigpack");
				Give(body, "materialpouch");
				Give(body, "belt");
				Give(body, "gravbag");
				GiveRandom(body, "container", 2);
				Give(body, "bikehelmet");
				GiveSomeOf(body, 1, "minilaserdrill", "plasmacutter");
				GiveSomeOf(body, 1, "flashlight", "lantern");
				GiveFilled(body, "saline", "biochem", 500f);
				Give(body, "smallbattery", Random.Range(2, 4));
				Give(body, "mediumbattery");
				GiveDressings(body, Random.Range(1, 3));
				GiveRandom(body, "utility", 5);
				GiveRandom(body, "water", 3);
				GiveRandom(body, "drug", 5);
				break;
			case 6:
				Give(body, "bigpack");
				Give(body, "materialpouch");
				Give(body, "legpouch");
				Give(body, "brokenbag");
				Give(body, "gravbag");
				GiveRandom(body, "container", 2);
				Give(body, "bikehelmet");
				GiveSomeOf(body, 1, "flashlight", "lantern");
				GiveSomeOf(body, 1, "titaniummachete", "titaniumpickaxe");
				Give(body, "titaniummultitool");
				Give(body, "smallbattery", Random.Range(3, 5));
				Give(body, "mediumbattery", Random.Range(1, 3));
				GiveDressings(body, Random.Range(2, 4));
				GiveRandom(body, "utility", 5);
				GiveRandom(body, "water", 3);
				GiveRandom(body, "drug", 5);
				GiveSomeOf(body, 1, "traumarig", "tacticalgloves", "tacticalboots", "traumarig");
				break;
			case 7:
				Give(body, "bigpack");
				Give(body, "materialpouch");
				Give(body, "legpouch");
				Give(body, "brokenbag");
				Give(body, "gravbag");
				GiveRandom(body, "container", 2);
				Give(body, "riothelmet");
				GiveSomeOf(body, 1, "flashlight", "lantern", "pulselantern");
				GiveSomeOf(body, 1, "titaniummachete", "titaniumpickaxe");
				Give(body, "titaniummultitool");
				Give(body, "smallbattery", Random.Range(3, 5));
				Give(body, "mediumbattery", Random.Range(1, 3));
				Give(body, "pulsecore");
				GiveDressings(body, 3);
				GiveRandom(body, "utility", 5);
				GiveRandom(body, "water", 3);
				GiveRandom(body, "drug", 5);
				GiveSomeOf(body, 2, "traumarig", "tacticalgloves", "tacticalboots", "traumarig");
				if (Random.value < 0.5f)
				{
					Give(body, "bioluminescentgel");
				}
				break;
			}
		}

		private static void Give(Body body, string id, int count = 1)
		{
			//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)
			if (Resolves(id))
			{
				for (int i = 0; i < count; i++)
				{
					Stow(body, Utils.Create(id, Vector2.op_Implicit(((Component)body).transform.position), 0f).GetComponent<Item>());
					kitItemCount++;
				}
			}
		}

		private static void GiveFilled(Body body, string id, string liquid, float ml)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (Resolves(id))
			{
				GameObject val = Utils.Create(id, Vector2.op_Implicit(((Component)body).transform.position), 0f);
				WaterContainerItem component = val.GetComponent<WaterContainerItem>();
				component.DrainAll();
				component.AddLiquid(liquid, ml);
				Stow(body, val.GetComponent<Item>());
				kitItemCount++;
			}
		}

		private static void Stow(Body body, Item item)
		{
			bool flag = item.Stats.wearable && (Object)(object)body.GetWearableBySlotID(item.Stats.wearSlotId) != (Object)null;
			if (item.Stats.wearable && !flag)
			{
				body.AutoPickUpItem(item);
			}
			else if ((Object)(object)item.container != (Object)null)
			{
				Hold(body, item);
			}
			else if ((!flag || (!TryLoad(body, item) && !Hold(body, item))) && (item.Stats.HasTag("noautopickup") || (!TryLoad(body, item) && !Hold(body, item))))
			{
				body.AutoPickUpItem(item);
			}
		}

		private static bool Hold(Body body, Item item)
		{
			for (int num = body.slots.Length - 1; num >= 0; num--)
			{
				if (!body.HoldingItem(num) && body.slots[num].canPickUp)
				{
					body.PickUpItem(item, num, true);
					return true;
				}
			}
			return false;
		}

		private static bool TryLoad(Body body, Item item)
		{
			foreach (Item surfaceInventoryItem in body.GetSurfaceInventoryItems())
			{
				if (!((Object)(object)surfaceInventoryItem.container == (Object)null) && surfaceInventoryItem.container.CanHoldItem(item))
				{
					surfaceInventoryItem.container.LoadItem(item);
					if ((Object)(object)((Component)item).transform.parent == (Object)(object)((Component)surfaceInventoryItem).transform)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void GiveRandom(Body body, string category, int count, params string[] except)
		{
			if (ItemLootPool.pool.TryGetValue(category, out var value))
			{
				GiveDistinct(body, value.Where((string id) => !except.Contains(id)), count);
			}
		}

		private static void GiveDressings(Body body, int count)
		{
			GiveDistinct(body, from kv in Item.GlobalItems
				where kv.Value.tags != null && kv.Value.tags.Split(new char[1] { ',' }).Contains("dressing")
				select kv.Key, count);
		}

		private static void GiveDistinct(Body body, IEnumerable<string> ids, int count)
		{
			foreach (string item in (from id in ids.Distinct()
				orderby Random.value
				where SlotFree(body, id)
				select id).Take(count))
			{
				Give(body, item);
			}
		}

		private static void GiveSomeOf(Body body, int count, params string[] ids)
		{
			for (int i = 0; i < count; i++)
			{
				string[] array = ids.Where((string id) => SlotFree(body, id)).ToArray();
				if (array.Length == 0)
				{
					break;
				}
				Give(body, Utils.PickRandom<string>(array));
			}
		}

		private static bool SlotFree(Body body, string id)
		{
			if (Item.GlobalItems.TryGetValue(id, out var value) && value.wearable)
			{
				return (Object)(object)body.GetWearableBySlotID(value.wearSlotId) == (Object)null;
			}
			return true;
		}

		private static void GiveCraftable(Body body, int count)
		{
			foreach (string item in (from id in (from r in Recipes.recipes
					where r.INT < 10 && !r.isRepair && r.result != null && !r.result.isLiquid && !string.IsNullOrEmpty(r.result.id)
					select r.result.id).Distinct()
				orderby Random.value
				where SlotFree(body, id)
				select id).Take(count))
			{
				Give(body, item);
			}
		}

		private static bool Resolves(string id)
		{
			ItemInfo val = default(ItemInfo);
			if ((Object)(object)Resources.Load<GameObject>(id) != (Object)null || ItemRegistry.TryGetItemInfo(id, ref val))
			{
				return true;
			}
			return false;
		}

		internal static void LogPatchStatus()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(PreRunScript), "Start", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				Harmony.GetPatchInfo((MethodBase)methodInfo);
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Body), "Awake", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				Harmony.GetPatchInfo((MethodBase)methodInfo2);
			}
		}
	}
	internal static class EffectsQuality
	{
		internal enum Level
		{
			High,
			Reduced,
			Low
		}

		internal const string SettingId = "newdescents.effectsquality";

		internal static Level Current;

		internal static void RegisterSetting()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			ModOptionsRegistry.Register(ModOptionDefinition.Dropdown("newdescents.effectsquality", "Effects quality <size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", "God rays, fog, floating motes and Old Machinery sparks. Lowering this may help GPU performance.", "<size=70%><color=#FFFFFF>(</color><color=#F7FAFC>N</color><color=#F0F5FA>e</color><color=#E8F0F7>w</color><color=#E1EBF5> </color><color=#D9E6F2>D</color><color=#D1E1EF>e</color><color=#CADDED>s</color><color=#C2D8EA>c</color><color=#BAD3E7>e</color><color=#B3CEE5>n</color><color=#ABC9E2>t</color><color=#A4C4E0>s</color><color=#9CBFDD>)</color></size>", 0, (ModDropdownChoice[])(object)new ModDropdownChoice[3]
			{
				new ModDropdownChoice("high", "High"),
				new ModDropdownChoice("reduced", "Reduced"),
				new ModDropdownChoice("low", "Low")
			}, (Action<int>)delegate(int choice)
			{
				Current = (Level)choice;
			}));
		}

		internal static T Pick<T>(T high, T reduced, T low)
		{
			if (Current != Level.High)
			{
				if (Current != Level.Reduced)
				{
					return low;
				}
				return reduced;
			}
			return high;
		}
	}
	internal static class LayerChoiceUI
	{
		private class Choice
		{
			internal readonly RectTransform[] arms = (RectTransform[])(object)new RectTransform[2];

			internal readonly RectTransform[] border = (RectTransform[])(object)new RectTransform[4];

			internal Button button;

			internal Image face;

			internal BannerShape cut;

			internal TMP_Text label;
		}

		private class BannerShape : BaseMeshEffect
		{
			internal bool Mirror;

			internal float Shear = 0.5f;

			public override void ModifyMesh(VertexHelper helper)
			{
				//IL_002e: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_0232: 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_0239: Unknown result type (might be due to invalid IL or missing references)
				//IL_023e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0243: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_0246: Unknown result type (might be due to invalid IL or missing references)
				//IL_0248: Unknown result type (might be due to invalid IL or missing references)
				//IL_024d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0258: Unknown result type (might be due to invalid IL or missing references)
				//IL_025a: Unknown result type (might be due to invalid IL or missing references)
				//IL_025f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0264: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_026b: Unknown result type (might be due to invalid IL or missing references)
				//IL_026c: 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_0273: Unknown result type (might be due to invalid IL or missing references)
				//IL_027e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0280: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028a: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0291: Unknown result type (might be due to invalid IL or missing references)
				//IL_0292: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_0299: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
				if (!((Behaviour)this).isActiveAndEnabled || (Object)(object)((BaseMeshEffect)this).graphic == (Object)null)
				{
					return;
				}
				Transform transform = ((Component)this).transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Rect rect = val.rect;
				if (!(((Rect)(ref rect)).width <= 0f) && !(((Rect)(ref rect)).height <= 0f))
				{
					Graphic graphic = ((BaseMeshEffect)this).graphic;
					Image val2 = (Image)(object)((graphic is Image) ? graphic : null);
					Texture2D val3 = (((Object)(object)val2 == (Object)null || (Object)(object)val2.overrideSprite == (Object)null) ? null : val2.overrideSprite.texture);
					Rect val4 = (Rect)(((Object)(object)val3 == (Object)null) ? new Rect(0f, 0f, 1f, 1f) : val2.overrideSprite.textureRect);
					float num = ((Rect)(ref rect)).width / ((Rect)(ref rect)).height;
					float num2 = ((Rect)(ref val4)).width / ((Rect)(ref val4)).height;
					if (num2 > num)
					{
						float num3 = ((Rect)(ref val4)).height * num;
						((Rect)(ref val4)).x = ((Rect)(ref val4)).x + (((Rect)(ref val4)).width - num3) * 0.5f;
						((Rect)(ref val4)).width = num3;
					}
					else if (num2 < num)
					{
						float num4 = ((Rect)(ref val4)).width / num;
						((Rect)(ref val4)).y = ((Rect)(ref val4)).y + (((Rect)(ref val4)).height - num4) * 0.5f;
						((Rect)(ref val4)).height = num4;
					}
					Rect uv = (Rect)(((Object)(object)val3 == (Object)null) ? val4 : new Rect(((Rect)(ref val4)).x / (float)((Texture)val3).width, ((Rect)(ref val4)).y / (float)((Texture)val3).height, ((Rect)(ref val4)).width / (float)((Texture)val3).width, ((Rect)(ref val4)).height / (float)((Texture)val3).height));
					float num5 = ((Rect)(ref rect)).width * Mathf.Clamp01(Shear);
					Vector2 val5 = default(Vector2);
					((Vector2)(ref val5))..ctor(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMin);
					Vector2 val6 = default(Vector2);
					((Vector2)(ref val6))..ctor(((Rect)(ref rect)).xMax, ((Rect)(ref rect)).yMin);
					Vector2 val7 = default(Vector2);
					((Vector2)(ref val7))..ctor(Mirror ? (((Rect)(ref rect)).xMin + num5) : ((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMax);
					Vector2 val8 = default(Vector2);
					((Vector2)(ref val8))..ctor(Mirror ? ((Rect)(ref rect)).xMax : (((Rect)(ref rect)).xMax - num5), ((Rect)(ref rect)).yMax);
					helper.Clear();
					helper.AddVert(Vector2.op_Implicit(val5), Color32.op_Implicit(Color.white), Vector4.op_Implicit(Uv(uv, rect, val5)));
					helper.AddVert(Vector2.op_Implicit(val7), Color32.op_Implicit(Color.white), Vector4.op_Implicit(Uv(uv, rect, val7)));
					helper.AddVert(Vector2.op_Implicit(val8), Color32.op_Implicit(Color.white), Vector4.op_Implicit(Uv(uv, rect, val8)));
					helper.AddVert(Vector2.op_Implicit(val6), Color32.op_Implicit(Color.white), Vector4.op_Implicit(Uv(uv, rect, val6)));
					helper.AddTriangle(0, 1, 2);
					helper.AddTriangle(2, 3, 0);
				}
			}

			private static Vector2 Uv(Rect uv, Rect rect, Vector2 point)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				return new Vector2(((Rect)(ref uv)).x + (point.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width * ((Rect)(ref uv)).width, ((Rect)(ref uv)).y + (point.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height * ((Rect)(ref uv)).height);
			}
		}

		private const string ChosenKey = "layerrouteselected";

		private const string ChosenText = "Chosen: {0}";

		private const string NameOpen = "<color=#1004FF>";

		private const string NameClose = "</color>";

		private const string RetroFontName = "Retro Gaming";

		private const string VanillaBannerFormat = "images.RouteArt.layer{0}.png";

		private const string ToxicBanner = "images.ToxicCaverns.savebanner.png";

		private const string VisceraeBanner = "images.Viscerae.savebanner.png";

		private const float DesignAspect = 2.367f;

		private const float CutRun = 1.5f;

		private const float CutMax = 0.85f;

		private const float ChevronShare = 0.42f;

		private const float StrokeShare = 0.07f;

		private const float InsetShare = 0.06f;

		private const float PadShare = 0.03f;

		private const float Diagonal = 0.70710677f;

		private const float BorderShare = 0.014f;

		private const float BorderMin = 2f;

		private const float BorderMax = 3f;

		private const float RowShare = 1.6f;

		private const float ScreenShare = 0.32f;

		private const float SizeScale = 1.15f;

		private const float GapUnits = 0.15f;

		private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

		private static readonly Dictionary<string, Sprite> banners = new Dictionary<string, Sprite>();

		private static readonly List<Button> actions = new List<Button>();

		private static WorldGeneration owner;

		private static GameObject savePanel;

		private static Button template;

		private static RectTransform root;

		private static RectTransform panelRect;

		private static RectTransform canvasRect;

		private static Choice first;

		private static Choice second;

		private static TMP_Text chosen;

		private static Sprite plate;

		private static Color ink = Color.white;

		private static float baseSize = 16f;

		private static TMP_FontAsset retro;

		private static bool retroReported;

		private static int displayedSlot = -1;

		private static int displayedOption = -1;

		private static bool panelWasOpen;

		internal static void RegisterLocale()
		{
			LocaleRegistry.Register("other", "layerrouteselected", "Chosen: {0}");
			LocaleRegistry.Register("other", "customlayertitle6", "Toxic Caverns");
			LocaleRegistry.Register("other", "customlayertitle7", "Viscerae");
		}

		internal static void Update(WorldGeneration world)
		{
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			if (LayerRouting.Demo)
			{
				return;
			}
			if ((Object)(object)world == (Object)null || (Object)(object)world.savePanel == (Object)null)
			{
				Clear();
				return;
			}
			if ((Object)(object)owner != (Object)(object)world || (Object)(object)savePanel != (Object)(object)world.savePanel)
			{
				Clear();
				owner = world;
				savePanel = world.savePanel;
				Button[] componentsInChildren = savePanel.GetComponentsInChildren<Button>(true);
				foreach (Button val in componentsInChildren)
				{
					bool flag = Calls(val, "ContinueRun");
					if (flag || Calls(val, "SaveAndExit"))
					{
						actions.Add(val);
						if ((Object)(object)template == (Object)null || flag)
						{
							template = val;
						}
					}
				}
			}
			if (!LayerRouting.IsAuthority)
			{
				Hide();
				return;
			}
			bool activeSelf = savePanel.activeSelf;
			if (activeSelf && !panelWasOpen)
			{
				LayerRouting.Prepare(world);
			}
			panelWasOpen = activeSelf;
			int num = (activeSelf ? LayerRouting.ForkSlot : (-1));
			if (num < 0)
			{
				Hide();
			}
			else if (!((Object)(object)root == (Object)null) || Create())
			{
				SetText(first.label, LayerRouting.OptionLabel(0));
				SetText(second.label, LayerRouting.OptionLabel(1));
				SetText(chosen, ChosenLine());
				if (num != displayedSlot || LayerRouting.SelectedOption != displayedOption)
				{
					displayedSlot = num;
					displayedOption = LayerRouting.SelectedOption;
					Dress(first, LayerRouting.OptionLocation(0), mirror: false);
					Dress(second, LayerRouting.OptionLocation(1), mirror: true);
					Paint(first, displayedOption == 0);
					Paint(second, displayedOption == 1);
					Bounds(canvasRect);
					Actions();
				}
				Layout();
				SetActive(((Component)root).gameObject, active: true);
			}
		}

		internal static void Clear()
		{
			if ((Object)(object)root != (Object)null)
			{
				((Component)root).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)root).gameObject);
			}
			owner = null;
			savePanel = null;
			template = null;
			root = (panelRect = (canvasRect = null));
			first = (second = null);
			chosen = null;
			actions.Clear();
			displayedSlot = -1;
			displayedOption = -1;
			panelWasOpen = false;
		}

		private static void Hide()
		{
			displayedSlot = -1;
			if ((Object)(object)root != (Object)null && ((Component)root).gameObject.activeSelf)
			{
				((Component)root).gameObject.SetActive(false);
			}
		}

		private static bool Calls(Button button, string method)
		{
			for (int i = 0; i < ((UnityEventBase)button.onClick).GetPersistentEventCount(); i++)
			{
				if (((UnityEventBase)button.onClick).GetPersistentMethodName(i) == method)
				{
					return true;
				}
			}
			return false;
		}

		private static string ChosenLine()
		{
			return LocaleRegistry.Get("layerrouteselected", "Chosen: {0}").Replace("{0}", "<color=#1004FF>" + LayerRouting.OptionLabel(LayerRouting.SelectedOption) + "</color>");
		}

		private static bool Create()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)template == (Object)null)
			{
				return false;
			}
			Transform transform = savePanel.transform;
			panelRect = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			Canvas componentInParent = savePanel.GetComponentInParent<Canvas>();
			TMP_Text val = (((Object)(object)componentInParent == (Object)null) ? null : (((Component)template).GetComponentInChildren<TMP_Text>(true) ?? ((Component)componentInParent).GetComponentInChildren<TMP_Text>(true)));
			if ((Object)(object)val == (Object)null || (Object)(object)panelRect == (Object)null || (Object)(object)componentInParent == (Object)null)
			{
				return false;
			}
			Transform transform2 = ((Component)componentInParent.rootCanvas).transform;
			canvasRect = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
			if ((Object)(object)canvasRect == (Object)null)
			{
				return false;
			}
			TMP_FontAsset font = RetroFont();
			baseSize = Mathf.Max(1f, val.fontSize) * 1.15f;
			ink = ((Graphic)val).color;
			Image component = ((Component)template).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				plate = component.sprite;
			}
			root = new GameObject("LayerChoiceUI", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Component)root).gameObject.SetActive(false);
			((Transform)root).SetParent((Transform)(object)canvasRect, false);
			root.anchorMin = Vector2.zero;
			root.anchorMax = Vector2.one;
			root.offsetMin = Vector2.zero;
			root.offsetMax = Vector2.zero;
			root.pivot = new Vector2(0.5f, 0.5f);
			((Transform)root).localScale = Vector3.one;
			first = Build(0, mirror: false, font, val);
			second = Build(1, mirror: true, font, val);
			chosen = Line("Chosen", (Transform)(object)root, font, val, centre: false);
			return true;
		}

		private static Choice Build(int option, bool mirror, TMP_FontAsset font, TMP_Text donor)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0150: Expected O, but got Unknown
			Choice choice = new Choice();
			Button val = Object.Instantiate<Button>(template, (Transform)(object)root, false);
			((Object)val).name = (mirror ? "OptionSecond" : "OptionFirst");
			choice.button = val;
			val.onClick = new ButtonClickedEvent();
			((UnityEvent)val.onClick).AddListener((UnityAction)delegate
			{
				Choose(option);
			});
			UILocalizer[] componentsInChildren = ((Component)val).GetComponentsInChildren<UILocalizer>(true);
			foreach (UILocalizer obj in componentsInChildren)
			{
				((Behaviour)obj).enabled = false;
				Object.Destroy((Object)(object)obj);
			}
			UITooltip[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<UITooltip>(true);
			foreach (UITooltip obj2 in componentsInChildren2)
			{
				((Behaviour)obj2).enabled = false;
				Object.Destroy((Object)(object)obj2);
			}
			Image[] componentsInChildren3 = ((Component)val).GetComponentsInChildren<Image>(true);
			foreach (Image val2 in componentsInChildren3)
			{
				if ((Object)(object)((Component)val2).transform != (Object)(object)((Component)val).transform)
				{
					((Behaviour)val2).enabled = false;
				}
			}
			ContentSizeFitter component = ((Component)val).GetComponent<ContentSizeFitter>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			Navigation navigation = ((Selectable)val).navigation;
			((Navigation)(ref navigation)).mode = (Mode)3;
			((Selectable)val).navigation = navigation;
			RectTransform val3 = (RectTransform)((Component)val).transform;
			((Transform)val3).localScale = Vector3.one;
			((Transform)val3).localRotation = Quaternion.identity;
			Anchor(val3);
			choice.face = ((Component)val).GetComponent<Image>();
			if ((Object)(object)choice.face != (Object)null)
			{
				choice.face.type = (Type)0;
				choice.cut = ((Component)choice.face).gameObject.AddComponent<BannerShape>();
				choice.cut.Mirror = mirror;
			}
			for (int num2 = 0; num2 < 4; num2++)
			{
				choice.border[num2] = Face("Border" + num2, ((Component)val).transform);
			}
			choice.label = Line("Label", ((Component)val).transform, font, donor, centre: true);
			choice.label.enableAutoSizing = true;
			for (int num3 = 0; num3 < 2; num3++)
			{
				choice.arms[num3] = Face("Chevron" + num3, ((Component)val).transform);
			}
			((Component)val).gameObject.SetActive(true);
			return choice;
		}

		private static RectTransform Face(string name, Transform slot)
		{
			//IL_0021: 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_004c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent(slot, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0.5f, 0.5f);
			Image component2 = ((Component)component).GetComponent<Image>();
			((Graphic)component2).color = Color.white;
			((Graphic)component2).raycastTarget = false;
			return component;
		}

		private static TMP_Text Line(string name, Transform slot, TMP_FontAsset font, TMP_Text donor, bool centre)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent(slot, false);
			if (centre)
			{
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0.5f, 0.5f);
				component.anchorMax = val;
				component.anchorMin = val;
				component.pivot = new Vector2(0.5f, 0.5f);
			}
			else
			{
				Anchor(component);
			}
			TextMeshProUGUI component2 = ((Component)component).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)component2).font = font;
			}
			((TMP_Text)component2).fontSize = baseSize;
			((TMP_Text)component2).fontStyle = (FontStyles)0;
			((Graphic)component2).color = ((Graphic)donor).color;
			((TMP_Text)component2).alignment = (TextAlignmentOptions)514;
			((TMP_Text)component2).enableWordWrapping = true;
			((TMP_Text)component2).enableAutoSizing = false;
			((Graphic)component2).raycastTarget = false;
			Shadow obj = ((Component)component).gameObject.AddComponent<Shadow>();
			obj.effectColor = new Color(0f, 0f, 0f, 0.8f);
			obj.effectDistance = new Vector2(Mathf.Max(1f, baseSize * 0.08f), 0f - Mathf.Max(1f, baseSize * 0.08f));
			return (TMP_Text)(object)component2;
		}

		private static TMP_FontAsset RetroFont()
		{
			if ((Object)(object)retro != (Object)null)
			{
				return retro;
			}
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name.StartsWith("Retro Gaming"))
				{
					retro = val;
					return retro;
				}
			}
			TMP_Text[] array2 = Resources.FindObjectsOfTypeAll<TMP_Text>();
			foreach (TMP_Text val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.font != (Object)null && ((Object)val2.font).name.StartsWith("Retro Gaming"))
				{
					retro = val2.font;
					return retro;
				}
			}
			if (!retroReported)
			{
				retroReported = true;
				Plugin.Logger.LogWarning((object)"No 'Retro Gaming' TMP font is loaded yet; the layer choice panel wears the HUD font until one is. Retried every time the panel builds.");
			}
			return null;
		}

		private static void Choose(int option)
		{
			if (!((Object)(object)root == (Object)null) && ((Component)root).gameObject.activeInHierarchy && LayerRouting.IsAuthority && displayedSlot >= 0 && LayerRouting.ForkSlot == displayedSlot)
			{
				LayerRouting.Choose(displayedSlot, option);
			}
		}

		private static void Dress(Choice choice, LayerRouting.Location? location, bool mirror)
		{
			Sprite val = ((!location.HasValue) ? null : Art(location.Value));
			if ((Object)(object)val == (Object)null)
			{
				val = plate;
			}
			if (!((Object)(object)choice.face == (Object)null))
			{
				if ((Object)(object)choice.face.sprite != (Object)(object)val)
				{
					choice.face.sprite = val;
				}
				choice.cut.Mirror = mirror;
				((Graphic)choice.face).SetVerticesDirty();
			}
		}

		private static Sprite Art(LayerRouting.Location location)
		{
			string text = ((location.Biome == LayerRouting.Biome.Vanilla) ? $"images.RouteArt.layer{location.Depth}.png" : ((location.Biome == LayerRouting.Biome.Toxic) ? "images.ToxicCaverns.savebanner.png" : "images.Viscerae.savebanner.png"));
			if (banners.TryGetValue(text, out var value))
			{
				return value;
			}
			Sprite val = AssetLoader.LoadUISprite(text, typeof(LayerChoiceUI).Assembly);
			banners[text] = val;
			_ = (Object)(object)val == (Object)null;
			return val;
		}

		private static void Paint(Choice choice, bool on)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0088: 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_00d8: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			float num = (on ? 1f : 0.55f);
			ColorBlock colors = ((Selectable)choice.button).colors;
			((ColorBlock)(ref colors)).normalColor = Plate(num);
			((ColorBlock)(ref colors)).highlightedColor = Plate(Mathf.Max(num, 0.85f));
			((ColorBlock)(ref colors)).pressedColor = Plate(Mathf.Min(num, 0.75f));
			((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).normalColor;
			((ColorBlock)(ref colors)).disabledColor = Plate(0.5f);
			((Selectable)choice.button).colors = colors;
			((Graphic)choice.label).color = Fade(ink, on ? 1f : 0.72f);
			RectTransform[] border = choice.border;
			foreach (RectTransform val in border)
			{
				Image val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<Image>());
				if ((Object)(object)val2 != (Object)null && ((Graphic)val2).color != ((ColorBlock)(ref colors)).normalColor)
				{
					((Graphic)val2).color = ((ColorBlock)(ref colors)).normalColor;
				}
			}
		}

		private static Color Plate(float value)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new Color(value, value, value, 1f);
		}

		private static Color Fade(Color color, float value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			return new Color(color.r * value, color.g * value, color.b * value, color.a);
		}

		private static void Layout()
		{
			//IL_0005: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//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_00a3: 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_00b3: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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)
			Rect screen = Bounds(canvasRect);
			Rect val = Bounds((RectTransform)((Component)template).transform);
			Rect row = Actions();
			float num = Mathf.Max(((Rect)(ref val)).width, ((Rect)(ref val)).height);
			float num2 = Mathf.Max(4f, num * 0.15f);
			float size = Mathf.Clamp(Mathf.Max(num * 0.22f, baseSize), 12f, 28f);
			Size(first.label, size);
			Size(second.label, size);
			Size(chosen, size);
			Seat(first, mirror: false, row, screen, num2, num);
			Seat(second, mirror: true, row, screen, num2, num);
			float num3 = Mathf.Min(((Rect)(ref screen)).width - num2 * 2f, Mathf.Max(((Rect)(ref row)).width, num * 5f));
			float num4 = Height(chosen, num3);
			float num5 = Mathf.Max(((Rect)(ref row)).yMin - num2 * 0.5f, ((Rect)(ref screen)).yMin + num4 + num2);
			Place(chosen.rectTransform, new Vector2(((Rect)(ref row)).center.x - num3 * 0.5f, num5), new Vector2(num3, num4));
		}

		private static void Seat(Choice choice, bool mirror, Rect row, Rect screen, float gap, float unit)
		{
			//IL_0039: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: 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_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: 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_0240: 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_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			float num = 2.367f;
			float num2 = (mirror ? (((Rect)(ref screen)).xMax - ((Rect)(ref row)).xMax - gap) : (((Rect)(ref row)).xMin - ((Rect)(ref screen)).xMin - gap));
			float num3 = Mathf.Min(((Rect)(ref screen)).yMax - ((Rect)(ref row)).center.y, ((Rect)(ref row)).center.y - ((Rect)(ref screen)).yMin) * 2f - gap;
			float num4 = Mathf.Min(Mathf.Min(((Rect)(ref row)).height * 1.6f, ((Rect)(ref screen)).height * 0.32f), Mathf.Min(num3, num2 / num));
			float num5 = num4 * num;
			if (num5 < unit * 1.1f)
			{
				SetActive(((Component)choice.button).gameObject, active: false);
				return;
			}
			float num6 = Mathf.Min(0.85f, 1.5f / num);
			float num7 = (mirror ? (((Rect)(ref row)).xMax + gap) : (((Rect)(ref row)).xMin - gap - num5));
			SetActive(((Component)choice.button).gameObject, active: true);
			Transform transform = ((Component)choice.button).transform;
			bool flag = Place((RectTransform)(object)((transform is RectTransform) ? transform : null), new Vector2(num7, ((Rect)(ref row)).center.y + num4 * 0.5f), new Vector2(num5, num4));
			if ((Object)(object)choice.cut != (Object)null && (flag || choice.cut.Shear != num6))
			{
				choice.cut.Shear = num6;
				((Graphic)choice.face).SetVerticesDirty();
			}
			float num8 = Mathf.Min(num4 * 0.42f, num5 * 0.22f);
			float num9 = num8 / 0.70710677f;
			float num10 = Mathf.Max(2f, num4 * 0.07f);
			float num11 = num5 * 0.06f;
			float num12 = (mirror ? (num5 * 0.5f - num11) : ((0f - num5) * 0.5f + num11));
			Vector2 val = default(Vector2);
			for (int i = 0; i < 2; i++)
			{
				float num13 = (mirror ? 135f : 45f) * ((i == 0) ? 1f : (-1f));
				RectTransform rect = choice.arms[i];
				((Vector2)(ref val))..ctor(Mathf.Cos(num13 * ((float)Math.PI / 180f)), Mathf.Sin(num13 * ((float)Math.PI / 180f)));
				Centre(rect, new Vector2(num12 + val.x * num9 * 0.5f, val.y * num9 * 0.5f), new Vector2(num9, num10));
				Spin(rect, num13);
			}
			float num14 = Mathf.Clamp(unit * 0.014f, 2f, 3f);
			float num15 = (mirror ? (-1f) : 1f);
			float num16 = num5 * num6;
			float num17 = num4 * 0.5f;
			float num18 = (0f - num15) * num5 * 0.5f;
			float num19 = num15 * num5 * 0.5f;
			float num20 = num19 - num15 * num16;
			Centre(choice.border[0], new Vector2(num18 - num15 * num14 * 0.5f, 0f), new Vector2(num14, num4 + 2f * num14));
			Centre(choice.border[1], new Vector2(0f, 0f - num17 - num14 * 0.5f), new Vector2(num5 + 2f * num14, num14));
			float num21 = num18 - num15 * num14;
			Centre(choice.border[2], new Vector2((num21 + num20) * 0.5f, num17 + num14 * 0.5f), new Vector2(Mathf.Abs(num20 - num21), num14));
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num20, num17);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(num19, 0f - num17);
			Vector2 val4 = val3 - val2;
			float magnitude = ((Vector2)(ref val4)).magnitude;
			Vector2 val5 = new Vector2(num15 * num4, num16) / Mathf.Max(1f, magnitude);
			Centre(choice.border[3], (val2 + val3) * 0.5f + val5 * num14 * 0.5f, new Vector2(magnitude + 2f * num14, num14));
			Spin(choice.border[3], Mathf.Atan2(val4.y, val4.x) * 57.29578f);
			float num22 = num5 * 0.03f;
			float num23 = (mirror ? (num5 * num6 * 0.5f) : (num11 + num8 + num22));
			float num24 = (mirror ? (num5 - num11 - num8 - num22) : (num5 * (1f - num6 * 0.5f)));
			Centre(choice.label.rectTransform, new Vector2((num23 + num24) * 0.5f - num5 * 0.5f, 0f), new Vector2(Mathf.Max(unit * 0.5f, num24 - num23), num4 * 0.7f));
		}

		private static void Size(TMP_Text text, float size)
		{
			if (text.enableAutoSizing)
			{
				if (text.fontSizeMax != size)
				{
					text.fontSizeMax = size;
					text.fontSizeMin = size * 0.5f;
				}
			}
			else if (text.fontSize != size)
			{
				text.fontSize = size;
			}
		}

		private static float Height(TMP_Text text, float width)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(text.fontSize * 1.5f, text.GetPreferredValues(text.text, width, 0f).y);
		}

		private static Rect Actions()
		{
			//IL_0005: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Rect result = Bounds(panelRect);
			bool flag = false;
			foreach (Button action in actions)
			{
				if (!((Object)(object)action == (Object)null) && ((Component)action).gameObject.activeInHierarchy)
				{
					Rect val = Bounds((RectTransform)((Component)action).transform);
					result = (flag ? Rect.MinMaxRect(Mathf.Min(((Rect)(ref result)).xMin, ((Rect)(ref val)).xMin), Mathf.Min(((Rect)(ref result)).yMin, ((Rect)(ref val)).yMin), Mathf.Max(((Rect)(ref result)).xMax, ((Rect)(ref val)).xMax), Mathf.Max(((Rect)(ref result)).yMax, ((Rect)(ref val)).yMax)) : val);
					flag = true;
				}
			}
			return result;
		}

		private static Rect Bounds(RectTransform rect)
		{
			//IL_0011: 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_001b: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			rect.GetWorldCorners(Corners);
			Vector2 val = Corner(Corners[0]);
			Vector2 val2 = val;
			for (int i = 1; i < Corners.Length; i++)
			{
				Vector2 val3 = Corner(Corners[i]);
				val = Vector2.Min(val, val3);
				val2 = Vector2.Max(val2, val3);
			}
			return Rect.MinMaxRect(val.x, val.y, val2.x, val2.y);
		}

		private static Vector2 Corner(Vector3 world)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(((Transform)root).InverseTransformPoint(world));
			Rect rect = root.rect;
			float num = ((Rect)(ref rect)).width * 0.5f;
			rect = root.rect;
			return val + new Vector2(num, ((Rect)(ref rect)).height * 0.5f);
		}

		private static void Anchor(RectTransform rect)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 anchorMin = (rect.anchorMax = Vector2.zero);
			rect.anchorMin = anchorMin;
			rect.pivot = new Vector2(0f, 1f);
		}

		private static bool Place(RectTransform rect, Vector2 position, Vector2 size)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			int num;
			if (!(rect.anchoredPosition != position))
			{
				num = ((rect.sizeDelta != size) ? 1 : 0);
				if (num == 0)
				{
					goto IL_002e;
				}
			}
			else
			{
				num = 1;
			}
			rect.anchoredPosition = position;
			rect.sizeDelta = size;
			goto IL_002e;
			IL_002e:
			return (byte)num != 0;
		}

		private static void Spin(RectTransform rect, float degrees)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (degrees < 0f)
			{
				degrees += 360f;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, 0f, degrees);
			if (((Transform)rect).localEulerAngles != val)
			{
				((Transform)rect).localEulerAngles = val;
			}
		}

		private static void Centre(RectTransform rect, Vector2 position, Vector2 size)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (rect.anchoredPosition != position)
			{
				rect.anchoredPosition = position;
			}
			if (rect.sizeDelta != size)
			{
				rect.sizeDelta = size;
			}
		}

		private static void SetText(TMP_Text label, string value)
		{
			if (label.text != value)
			{
				label.text = value;
			}
		}

		private static void SetActive(GameObject obj, bool active)
		{
			if (obj.activeSelf != active)
			{
				obj.SetActive(active);
			}
		}
	}
	internal static class LayerDialogue
	{
		private const string DustMaskId = "dustmask";

		private const string ToxicArrivalMaskKey = "toxicentermask";

		private const string ToxicArrivalMaskLine = "Good thing I have a dust mask for this.";

		private static readonly (string Key, string Line)[] ToxicArrival = new(string, string)[3]
		{
			("toxicenter1", "Wow, this is incredibly green."),
			("toxicenter2", "Are those toxic fumes in the air?"),
			("toxicenter3", "Urgh... ticks...")
		};

		private static readonly (string Key, string Line)[] ToxicDeparture = new(string, string)[5]
		{
			("toxicexit1", "I never want to see a cave tick again."),
			("toxicexit2", "My fur's all singed now..."),
			("toxicexit3", "My sense of smell is all fuzzy now"),
			("toxicexit4", "Finally free of this place..."),
			("toxicexit5", "What awaits me next?")
		};

		private static readonly (string Key, string Line)[] VisceraeArrival = new(string, string)[6]
		{
			("visceraeenter1", "This layer smells AWFUL."),
			("visceraeenter2", "Great, I'm now in some living thing."),
			("visceraeenter3", "Hopefully this place doesn't find me tasty..."),
			("visceraeenter4", "This place is innerving."),
			("visceraeenter5", "This blood looks unnatural..."),
			("visceraeenter6", "I want to throw up...")
		};

		private static readonly (string Key, string Line)[] VisceraeDeparture = new(string, string)[5]
		{
			("visceraeexit1", "Still unnerving."),
			("visceraeexit2", "My mind's still so fuzzy..."),
			("visceraeexit3", "Get me out of this place"),
			("visceraeexit4", "Need.. to.. leave."),
			("visceraeexit5", "Not today, living biome.")
		};

		private static bool promptSeen;

		private const float DepartureCooldownSeconds = 60f;

		private static float lastDepartureTime = float.NegativeInfinity;

		internal static void RegisterLocale()
		{
			LocaleRegistry.Register("other", "customlayertitle6", "Toxic Caverns");
			LocaleRegistry.Register("other", "customlayertitle7", "Viscerae");
			LocaleRegistry.Register("other", "toxicentermask", "Good thing I have a dust mask for this.");
			RegisterPool(ToxicArrival);
			RegisterPool(ToxicDeparture);
			RegisterPool(VisceraeArrival);
			RegisterPool(VisceraeDeparture);
		}

		private static void RegisterPool((string Key, string Line)[] pool)
		{
			for (int i = 0; i < pool.Length; i++)
			{
				(string, string) tuple = pool[i];
				LocaleRegistry.Register("other", tuple.Item1, tuple.Item2);
			}
		}

		internal static void OnLayerLoaded(WorldGeneration world)
		{
			promptSeen = false;
			lastDepartureTime = float.NegativeInfinity;
			Body val = (((Object)(object)PlayerCamera.main != (Object)null) ? PlayerCamera.main.body : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (ToxicCaverns.IsLayer(world))
			{
				if (HasDustMask(val))
				{
					Say(val, "toxicentermask", "Good thing I have a dust mask for this.");
				}
				else
				{
					Say(val, ToxicArrival);
				}
			}
			else if (Viscerae.IsLayer(world))
			{
				Say(val, VisceraeArrival);
			}
		}

		internal static void NoteBottomPrompt(WorldGeneration world)
		{
			if (!((Object)(object)world != (Object)null) || !((Object)(object)world.savePanel != (Object)null) || !world.savePanel.activeSelf)
			{
				promptSeen = false;
			}
			else
			{
				if (promptSeen)
				{
					return;
				}
				promptSeen = true;
				Body val = (((Object)(object)PlayerCamera.main != (Object)null) ? PlayerCamera.main.body : null);
				if (!((Object)(object)val == (Object)null) && !(Time.time - lastDepartureTime < 60f))
				{
					if (ToxicCaverns.IsLayer(world))
					{
						lastDepartureTime = Time.time;
						Say(val, ToxicDeparture);
					}
					else if (Viscerae.IsLayer(world) && !VisceraeAssimilation.AtMax(val))
					{
						lastDepartureTime = Time.time;
						Say(val, VisceraeDeparture);
					}
				}
			}
		}

		private static bool HasDustMask(Body body)
		{
			foreach (Item item in body.GetAllItemsThorough())
			{
				if ((Object)(object)item != (Object)null && item.id == "dustmask")
				{
					return true;
				}
			}
			return false;
		}

		private static void Say(Body body, (string Key, string Line)[] pool)
		{
			(string, string) tuple = pool[Random.Range(0, pool.Length)];
			Say(body, tuple.Item1, tuple.Item2);
		}

		private static void Say(Body body, string key, string line)
		{
			if (!((Object)(object)body.talker == (Object)null))
			{
				body.talker.Talk(LocaleRegistry.Get(key, line), (Limb)null, true, false);
			}
		}
	}
	internal static class LayerRoutePersistence
	{
		private sealed class Provider : ICustomSaveProvider
		{
			public int GetVersion()
			{
				return 1;
			}

			public JToken Capture()
			{
				return (JToken)(object)LayerRoutePersistence.Capture(descentSave);
			}

			public void Restore(JToken payload, int version, SaveRestoreContext context)
			{
				if (version == 1)
				{
					JObject val = (JObject)(object)((payload is JObject) ? payload : null);
					if (val != null)
					{
						LayerRoutePersistence.Restore(context.World, val);
						skipWorldRestore = (bool?)val["descent"] == true;
						restored = true;
						return;
					}
				}
				throw new InvalidOperationException("Unsupported New Descents route save version.");
			}
		}

		private static class SaveBiomePatch
		{
			[HarmonyTranspiler]
			internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> codes = instructions.ToList();
				FieldInfo field = AccessTools.Field(typeof(SaveInfo), "cheatedSave");
				if (field == null)
				{
					throw new InvalidOperationException("SaveInfo.cheatedSave is gone.");
				}
				int matches = 0;
				for (int i = 0; i < codes.Count; i++)
				{
					yield return codes[i];
					if (CodeInstructionExtensions.StoresField(codes[i], field))
					{
						int num = i - 2;
						while (num >= 0 && !CodeInstructionExtensions.IsLdloc(codes[num], (LocalBuilder)null))
						{
							num--;
						}
						if (num < 0)
						{
							throw new InvalidOperationException("SaveInfo serialization receiver changed.");
						}
						yield return new CodeInstruction(codes[num].opcode, codes[num].operand);
						yield return CodeInstruction.Call(typeof(LayerRoutePersistence), "SetSavedBiome", (Type[])null, (Type[])null);
						matches++;
					}
				}
				if (matches != 1)
				{
					throw new InvalidOperationException("SaveInfo serialization seam changed.");
				}
			}
		}

		private static class DescentSavePatch
		{
			[HarmonyPrefix]
			internal static bool Prefix(WorldGeneration __instance)
			{
				if (Viscerae.IsLayer(__instance) && VisceraeAssimilation.AtMax(__instance.body))
				{
					return false;
				}
				if (!LayerRouting.IsAuthority)
				{
					return true;
				}
				LayerRouting.Prepare(__instance);
				return true;
			}

			[HarmonyTranspiler]
			internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo save = AccessTools.Method(typeof(SaveSystem), "SaveGame", (Type[])null, (Type[])null);
				int matches = 0;
				foreach (CodeInstruction item in RouteAchievement(instructions))
				{
					if (CodeInstructionExtensions.Calls(item, save))
					{
						item.operand = AccessTools.Method(typeof(LayerRoutePersistence), "SaveDestination", (Type[])null, (Type[])null);
						matches++;
					}
					yield return item;
				}
				if (matches != 1)
				{
					throw new InvalidOperationException("SaveAndExit save seam changed.");
				}
			}
		}

		private static class ContinuePatch
		{
			[HarmonyPrefix]
			internal static bool Prefix(WorldGeneration __instance)
			{
				if (!LayerRouting.IsAuthority)
				{
					return true;
				}
				LayerRouting.Prepare(__instance);
				return true;
			}

			[HarmonyTranspiler]
			internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return RouteAchievement(instructions);
			}
		}

		private static class LoadPatch
		{
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			internal static void Prefix()
			{
				ResetLoad();
			}

			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "net.cucorelib" })]
			internal static void Postfix()
			{
				WorldGeneration world = WorldGeneration.world;
				if (!((Object)(object)world == (Object)null))
				{
					if (!restored)
					{
						LayerRouting.Observe(world);
					}
					ApplyPendingRemote(world);
				}
			}

			[HarmonyFinalizer]
			internal static void Finalizer()
			{
				skipWorldRestore = false;
			}
		}

		private const string Key = "newdescents.route";

		private static bool descentSave;

		private static bool skipWorldRestore;

		private static bool restored;

		private static JObject remote;

		internal static void Register(Harmony harmony)
		{
			//IL_00b7: Unknown result type