Decompiled source of IsometricView v0.2.0

BepInEx/plugins/IsometricView/IsometricView.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("IsometricView")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+627c93de35fe4ea8fc7db780adf6d890daf2a24a")]
[assembly: AssemblyProduct("IsometricView")]
[assembly: AssemblyTitle("IsometricView")]
[assembly: AssemblyVersion("0.2.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace IsometricView
{
	internal static class BallisticAim
	{
		internal static bool Solve(Vector3 delta, float speed, float gravity, float drag, float dt, out Vector3 direction)
		{
			direction = ((delta.LengthSquared() > 1E-06f) ? Vector3.Normalize(delta) : Vector3.UnitZ);
			float num = (float)Math.Sqrt(delta.X * delta.X + delta.Z * delta.Z);
			if (num < 0.01f || speed < 0.1f)
			{
				return false;
			}
			float num2 = 0f;
			float num3 = 0f;
			bool flag = false;
			for (int i = 0; i <= 32; i++)
			{
				float num4 = -1.45f + (float)i * 0.090625f;
				if (!Height(num, delta.Y, num4, speed, gravity, drag, dt, out var height))
				{
					flag = false;
					continue;
				}
				float num5 = height - delta.Y;
				if (flag && num3 <= 0f && num5 >= 0f)
				{
					float num6 = num2;
					float num7 = num4;
					for (int j = 0; j < 18; j++)
					{
						float num8 = (num6 + num7) * 0.5f;
						if (!Height(num, delta.Y, num8, speed, gravity, drag, dt, out height))
						{
							return false;
						}
						if (height < delta.Y)
						{
							num6 = num8;
						}
						else
						{
							num7 = num8;
						}
					}
					float num9 = (num6 + num7) * 0.5f;
					direction = new Vector3(delta.X / num * (float)Math.Cos(num9), (float)Math.Sin(num9), delta.Z / num * (float)Math.Cos(num9));
					return true;
				}
				flag = true;
				num2 = num4;
				num3 = num5;
			}
			return false;
		}

		private static bool Height(float range, float targetHeight, float angle, float speed, float gravity, float drag, float dt, out float height)
		{
			dt = Math.Max(0.005f, dt);
			Vector3 position = Vector3.Zero;
			Vector3 velocity = new Vector3((float)Math.Cos(angle) * speed, (float)Math.Sin(angle) * speed, 0f);
			for (int i = 0; (float)i < Math.Min(6000f, 30f / dt); i++)
			{
				Vector3 vector = position;
				CameraMath.StepProjectile(ref position, ref velocity, gravity, drag, dt);
				if (position.X >= range)
				{
					height = vector.Y + (position.Y - vector.Y) * (range - vector.X) / (position.X - vector.X);
					return true;
				}
				if (velocity.Y < 0f && position.Y < targetHeight)
				{
					height = position.Y;
					return true;
				}
				if (velocity.X <= 0.001f)
				{
					break;
				}
			}
			height = 0f;
			return false;
		}
	}
	internal readonly struct BuildingPart
	{
		internal readonly Vector3 Min;

		internal readonly Vector3 Max;

		internal BuildingPart(Vector3 min, Vector3 max)
		{
			Min = min;
			Max = max;
		}

		internal bool Touches(BuildingPart other, float gap)
		{
			return Min.X <= other.Max.X + gap && Max.X + gap >= other.Min.X && Min.Y <= other.Max.Y + gap && Max.Y + gap >= other.Min.Y && Min.Z <= other.Max.Z + gap && Max.Z + gap >= other.Min.Z;
		}
	}
	internal static class BuildingLayout
	{
		internal static HashSet<int> Connected(IList<BuildingPart> parts, int seed)
		{
			HashSet<int> hashSet = new HashSet<int>();
			if (seed < 0 || seed >= parts.Count)
			{
				return hashSet;
			}
			Dictionary<(int, int, int), List<int>> dictionary = new Dictionary<(int, int, int), List<int>>();
			List<int> list = new List<int>();
			for (int i = 0; i < parts.Count; i++)
			{
				BuildingPart buildingPart = parts[i];
				int num = Bin(buildingPart.Min.X - 0.2f);
				int num2 = Bin(buildingPart.Min.Y - 0.2f);
				int num3 = Bin(buildingPart.Min.Z - 0.2f);
				int num4 = Bin(buildingPart.Max.X + 0.2f);
				int num5 = Bin(buildingPart.Max.Y + 0.2f);
				int num6 = Bin(buildingPart.Max.Z + 0.2f);
				if ((long)(num4 - num + 1) * (long)(num5 - num2 + 1) * (num6 - num3 + 1) > 4096)
				{
					list.Add(i);
					continue;
				}
				for (int j = num; j <= num4; j++)
				{
					for (int k = num2; k <= num5; k++)
					{
						for (int l = num3; l <= num6; l++)
						{
							(int, int, int) key = (j, k, l);
							if (!dictionary.TryGetValue(key, out var value))
							{
								value = (dictionary[key] = new List<int>());
							}
							value.Add(i);
						}
					}
				}
			}
			Queue<int> queue = new Queue<int>();
			hashSet.Add(seed);
			queue.Enqueue(seed);
			while (queue.Count > 0)
			{
				int index = queue.Dequeue();
				BuildingPart buildingPart2 = parts[index];
				SortedSet<int> sortedSet = new SortedSet<int>(list);
				int num7 = Bin(buildingPart2.Min.X - 0.2f);
				int num8 = Bin(buildingPart2.Min.Y - 0.2f);
				int num9 = Bin(buildingPart2.Min.Z - 0.2f);
				int num10 = Bin(buildingPart2.Max.X + 0.2f);
				int num11 = Bin(buildingPart2.Max.Y + 0.2f);
				int num12 = Bin(buildingPart2.Max.Z + 0.2f);
				if ((long)(num10 - num7 + 1) * (long)(num11 - num8 + 1) * (num12 - num9 + 1) > 4096)
				{
					for (int m = 0; m < parts.Count; m++)
					{
						sortedSet.Add(m);
					}
				}
				else
				{
					for (int n = num7; n <= num10; n++)
					{
						for (int num13 = num8; num13 <= num11; num13++)
						{
							for (int num14 = num9; num14 <= num12; num14++)
							{
								if (!dictionary.TryGetValue((n, num13, num14), out var value2))
								{
									continue;
								}
								foreach (int item in value2)
								{
									sortedSet.Add(item);
								}
							}
						}
					}
				}
				foreach (int item2 in sortedSet)
				{
					if (!hashSet.Contains(item2) && buildingPart2.Touches(parts[item2], 0.35f))
					{
						hashSet.Add(item2);
						queue.Enqueue(item2);
					}
				}
			}
			return hashSet;
		}

		private static int Bin(float value)
		{
			return (int)Math.Floor(value / 2f);
		}

		internal static bool FrontSupport(Vector2 point, Vector2 anchor, Vector2 camera, IList<RoomWall> boundaries)
		{
			float num = float.PositiveInfinity;
			bool flag = false;
			foreach (RoomWall boundary in boundaries)
			{
				Vector2 value = point - boundary.Center;
				Vector2 value2 = new Vector2(0f - boundary.Normal.Y, boundary.Normal.X);
				float num2 = Vector2.Dot(value, boundary.Normal);
				float num3 = Math.Max(0f, Math.Abs(Vector2.Dot(value, value2)) - boundary.HalfWidth);
				float num4 = num2 * num2 + num3 * num3;
				bool flag2 = CutawayMath.Front(boundary.Normal, boundary.Center, anchor, camera, previous: false);
				if (num4 < num - 0.001f)
				{
					num = num4;
					flag = flag2;
				}
				else if (Math.Abs(num4 - num) <= 0.001f)
				{
					flag = flag || flag2;
				}
			}
			return float.IsPositiveInfinity(num) ? CutawayMath.FrontFrame(point, anchor, camera, previous: false) : flag;
		}

		internal static List<SectionRun> FrontSections(Vector2 min, Vector2 max, Vector2 anchor, Vector2 camera, IList<RoomWall> boundaries)
		{
			bool x = max.X - min.X >= max.Y - min.Y;
			float num = (x ? min.X : min.Y);
			float num2 = (x ? max.X : max.Y);
			Vector2 center = (min + max) / 2f;
			List<SectionRun> list = new List<SectionRun>();
			bool flag = Side(num);
			float num3 = num;
			float num4 = num;
			int num5 = Math.Max(1, Math.Min(256, (int)Math.Ceiling((num2 - num) / 0.125f)));
			for (int i = 1; i <= num5; i++)
			{
				float num6 = num + (num2 - num) * (float)i / (float)num5;
				bool flag2 = Side(num6);
				if (flag2 != flag)
				{
					float num7 = num4;
					float num8 = num6;
					for (int j = 0; j < 20; j++)
					{
						float num9 = (num7 + num8) / 2f;
						if (Side(num9) == flag)
						{
							num7 = num9;
						}
						else
						{
							num8 = num9;
						}
					}
					float num10 = (num7 + num8) / 2f;
					if (num10 - num3 > 0.0001f)
					{
						list.Add(new SectionRun(num3, num10, flag, x));
					}
					num3 = num10;
					flag = flag2;
				}
				num4 = num6;
			}
			if (num2 - num3 > 0.0001f)
			{
				list.Add(new SectionRun(num3, num2, flag, x));
			}
			if (list.Count == 0)
			{
				list.Add(new SectionRun(num, num2, flag, x));
			}
			return list;
			bool Side(float at)
			{
				return FrontSupport(x ? new Vector2(at, center.Y) : new Vector2(center.X, at), anchor, camera, boundaries);
			}
		}

		internal static List<SectionRun> CameraSections(Vector2 min, Vector2 max, Vector2 player, Vector2 camera)
		{
			bool x = max.X - min.X >= max.Y - min.Y;
			float num = (x ? min.X : min.Y);
			float num2 = (x ? max.X : max.Y);
			Vector2 center = (min + max) / 2f;
			Vector2 vector = Vector2.Normalize(camera - player);
			float num3 = (x ? vector.X : vector.Y);
			float num4 = (x ? vector.Y : vector.X);
			List<SectionRun> list = new List<SectionRun>();
			if (Math.Abs(num3) > 0.0001f)
			{
				float num5 = (x ? player.X : player.Y) - ((x ? (center.Y - player.Y) : (center.X - player.X)) * num4 + 0.15f) / num3;
				if (num5 > num + 0.0001f && num5 < num2 - 0.0001f)
				{
					list.Add(new SectionRun(num, num5, Side((num + num5) / 2f), x));
					list.Add(new SectionRun(num5, num2, Side((num2 + num5) / 2f), x));
					return list;
				}
			}
			list.Add(new SectionRun(num, num2, Side((num + num2) / 2f), x));
			return list;
			bool Side(float at)
			{
				return CutawayMath.CameraSide(x ? new Vector2(at, center.Y) : new Vector2(center.X, at), player, camera);
			}
		}

		internal static List<RoomWall> SupportPlanes(Vector2 min, Vector2 max, IList<RoomWall> walls)
		{
			List<RoomWall> list = new List<RoomWall>();
			Vector2 vector = (min + max) / 2f;
			bool flag = max.X - min.X >= max.Y - min.Y;
			for (int i = 0; i < 5; i++)
			{
				float num = (float)i / 4f;
				Vector2 point = (flag ? new Vector2(min.X + (max.X - min.X) * num, vector.Y) : new Vector2(vector.X, min.Y + (max.Y - min.Y) * num));
				float num2 = float.PositiveInfinity;
				foreach (RoomWall wall in walls)
				{
					num2 = Math.Min(num2, ViewOcclusion.DistanceSquared(wall, point));
				}
				foreach (RoomWall wall2 in walls)
				{
					if (ViewOcclusion.DistanceSquared(wall2, point) <= num2 + 0.001f && !list.Contains(wall2))
					{
						list.Add(wall2);
					}
				}
			}
			return list;
		}

		internal static List<SectionRun> ViewSections(Vector2 min, Vector2 max, Vector2 player, Vector2 camera, IList<RoomWall> walls)
		{
			bool x = max.X - min.X >= max.Y - min.Y;
			float num = (x ? min.X : min.Y);
			float num2 = (x ? max.X : max.Y);
			Vector2 center = (min + max) / 2f;
			List<SectionRun> list = new List<SectionRun>();
			bool flag = Side(num);
			float num3 = num;
			float num4 = num;
			int num5 = Math.Max(1, Math.Min(128, (int)Math.Ceiling((num2 - num) / 0.125f)));
			for (int i = 1; i <= num5; i++)
			{
				float num6 = num + (num2 - num) * (float)i / (float)num5;
				bool flag2 = Side(num6);
				if (flag2 != flag)
				{
					float num7 = num4;
					float num8 = num6;
					for (int j = 0; j < 18; j++)
					{
						float num9 = (num7 + num8) / 2f;
						if (Side(num9) == flag)
						{
							num7 = num9;
						}
						else
						{
							num8 = num9;
						}
					}
					float num10 = (num7 + num8) / 2f;
					if (num10 - num3 > 0.0001f)
					{
						list.Add(new SectionRun(num3, num10, flag, x));
					}
					num3 = num10;
					flag = flag2;
				}
				num4 = num6;
			}
			if (num2 - num3 > 0.0001f)
			{
				list.Add(new SectionRun(num3, num2, flag, x));
			}
			if (list.Count == 0)
			{
				list.Add(new SectionRun(num, num2, flag, x));
			}
			return list;
			bool Side(float at)
			{
				Vector2 point = (x ? new Vector2(at, center.Y) : new Vector2(center.X, at));
				float num11 = float.PositiveInfinity;
				bool flag3 = false;
				foreach (RoomWall wall in walls)
				{
					float num12 = ViewOcclusion.DistanceSquared(wall, point);
					bool flag4 = ViewOcclusion.WallBetween(wall, player, camera);
					if (num12 < num11 - 0.001f)
					{
						num11 = num12;
						flag3 = flag4;
					}
					else if (Math.Abs(num12 - num11) <= 0.001f)
					{
						flag3 = flag3 || flag4;
					}
				}
				return float.IsPositiveInfinity(num11) ? CutawayMath.CameraSide(point, player, camera) : flag3;
			}
		}
	}
	internal readonly struct SectionRun
	{
		internal readonly float From;

		internal readonly float To;

		internal readonly bool Front;

		internal readonly bool AlongX;

		internal SectionRun(float from, float to, bool front, bool alongX)
		{
			From = from;
			To = to;
			Front = front;
			AlongX = alongX;
		}
	}
	internal static class CameraMath
	{
		internal const float IsometricPitch = 35.26439f;

		internal static float NormalizeYaw(float yaw)
		{
			return (yaw % 360f + 360f) % 360f;
		}

		internal static float SnapDiagonalYaw(float yaw)
		{
			return (float)Math.Floor(NormalizeYaw(yaw) / 90f) * 90f + 45f;
		}

		internal static float TurnDiagonal(float yaw, int direction)
		{
			return NormalizeYaw(SnapDiagonalYaw(yaw) + (float)(Math.Sign(direction) * 90));
		}

		internal static int ArrowTurn(bool left, bool right)
		{
			return (left != right) ? (left ? 1 : (-1)) : 0;
		}

		internal static float SimulatedDistance(float framingDistance, float nativeFov, float simulatedFov)
		{
			return framingDistance * (float)(Math.Tan((double)nativeFov * Math.PI / 360.0) / Math.Tan((double)simulatedFov * Math.PI / 360.0));
		}

		internal static (float Distance, float Fov) InteriorProjection(float framingDistance, float nativeFov, float simulatedFov)
		{
			float num = SimulatedDistance(framingDistance, nativeFov, simulatedFov);
			if (num <= 30f)
			{
				return (Distance: num, Fov: simulatedFov);
			}
			double num2 = (double)framingDistance * Math.Tan((double)nativeFov * Math.PI / 360.0);
			return (Distance: 30f, Fov: (float)(Math.Atan(num2 / 30.0) * 360.0 / Math.PI));
		}

		internal static float Zoom(float distance, float wheel, float sensitivity)
		{
			return Math.Max(3f, Math.Min(30f, distance - Math.Max(-1f, Math.Min(1f, wheel)) * sensitivity));
		}

		internal static void StepProjectile(ref Vector3 position, ref Vector3 velocity, float gravity, float drag, float dt)
		{
			velocity -= Vector3.UnitY * gravity * dt;
			float num = velocity.Length();
			if (num > 0f)
			{
				velocity -= velocity / num * (num * num * drag * dt);
			}
			position += velocity * dt;
		}
	}
	internal sealed class CameraTurn
	{
		private readonly Queue<int> turns = new Queue<int>();

		private float start;

		private float target;

		private float elapsed;

		private bool moving;

		internal float Value { get; private set; }

		internal void Reset(float yaw)
		{
			Value = (start = (target = yaw));
			elapsed = 0f;
			moving = false;
			turns.Clear();
		}

		internal void Turn(int sign)
		{
			if (sign != 0)
			{
				if (moving)
				{
					turns.Enqueue(Math.Sign(sign));
				}
				else
				{
					Start(Math.Sign(sign));
				}
			}
		}

		private void Start(int direction)
		{
			start = Value;
			target = start + (float)(direction * 90);
			elapsed = 0f;
			moving = true;
		}

		internal float Advance(float dt, float duration)
		{
			duration = Math.Max(0.01f, duration);
			dt = Math.Max(0f, dt);
			while (moving && dt > 0f)
			{
				float num = Math.Min(dt, duration - elapsed);
				dt -= num;
				elapsed += num;
				float num2 = Math.Min(1f, elapsed / duration);
				Value = start + (target - start) * num2 * num2 * (3f - 2f * num2);
				if (elapsed < duration)
				{
					break;
				}
				Value = target;
				moving = false;
				if (turns.Count > 0)
				{
					Start(turns.Dequeue());
				}
			}
			return CameraMath.NormalizeYaw(Value);
		}
	}
	internal static class ControlMath
	{
		internal static Vector3 Horizontal(Vector3 value, Vector3 fallback)
		{
			value.Y = 0f;
			return (value.LengthSquared() > 1E-06f) ? Vector3.Normalize(value) : fallback;
		}

		internal static Vector3 Movement(Vector3 input, Vector3 cameraForward)
		{
			input.Y = 0f;
			if (input.LengthSquared() > 1f)
			{
				input = Vector3.Normalize(input);
			}
			Vector3 vector = Horizontal(cameraForward, Vector3.UnitZ);
			Vector3 vector2 = Vector3.Cross(Vector3.UnitY, vector);
			return vector * input.Z + vector2 * input.X;
		}

		internal static Vector3 Rebase(Vector3 world, Vector3 lookForward)
		{
			Vector3 vector = Horizontal(lookForward, Vector3.UnitZ);
			return new Vector3(Vector3.Dot(world, Vector3.Cross(Vector3.UnitY, vector)), 0f, Vector3.Dot(world, vector));
		}

		internal static float FollowWeight(float responsiveness, float dt)
		{
			return 1f - (float)Math.Exp((0f - Math.Max(0f, responsiveness)) * Math.Max(0f, dt));
		}

		internal static Vector3 AimDirection(Vector3 spawn, Vector3 point, Vector3 fallback)
		{
			Vector3 value = point - spawn;
			return (value.LengthSquared() > 1E-06f) ? Vector3.Normalize(value) : Vector3.Normalize(fallback);
		}

		internal static bool PlanePoint(Vector3 origin, Vector3 direction, float height, out Vector3 point)
		{
			point = default(Vector3);
			if (Math.Abs(direction.Y) < 1E-05f)
			{
				return false;
			}
			float num = (height - origin.Y) / direction.Y;
			if (num < 0f || float.IsNaN(num) || float.IsInfinity(num))
			{
				return false;
			}
			point = origin + direction * num;
			return true;
		}
	}
	internal sealed class DragState
	{
		private bool waitingForRelease;

		internal float Step(bool allowed, bool held, float delta, float sensitivity, bool invert)
		{
			if (!allowed)
			{
				waitingForRelease = held;
				return 0f;
			}
			if (!held)
			{
				waitingForRelease = false;
				return 0f;
			}
			return waitingForRelease ? 0f : (delta * sensitivity * (float)((!invert) ? 1 : (-1)));
		}

		internal void Reset()
		{
			waitingForRelease = true;
		}
	}
	internal sealed class BowReleaseGate
	{
		private bool requireRelease;

		internal bool Step(bool allowed, bool held)
		{
			if (!allowed)
			{
				requireRelease = true;
			}
			bool result = !allowed || requireRelease;
			if (allowed && !held)
			{
				requireRelease = false;
			}
			return result;
		}
	}
	internal enum BuildingKind
	{
		Other,
		Wall,
		Floor,
		Roof,
		Stair,
		Frame
	}
	internal static class CutawayMath
	{
		internal static BuildingKind Kind(string name, bool door = false, bool furniture = false, bool construction = false)
		{
			if (furniture)
			{
				return BuildingKind.Other;
			}
			name = (name ?? "").ToLowerInvariant();
			if (name.Contains("portal") || name.Contains("teleport"))
			{
				return BuildingKind.Other;
			}
			if (name.Contains("stair") || name.Contains("step") || name.Contains("ladder") || name.Contains("ramp"))
			{
				return BuildingKind.Stair;
			}
			if (door || name.Contains("wall") || name.Contains("gate") || name.Contains("window") || name.Contains("arch") || name.Contains("door"))
			{
				return BuildingKind.Wall;
			}
			if (name.Contains("beam") || name.Contains("pole") || name.Contains("pillar") || name.Contains("column"))
			{
				return BuildingKind.Frame;
			}
			if (name.Contains("roof") || name.Contains("shingle"))
			{
				return BuildingKind.Roof;
			}
			if (name.Contains("floor") || name.Contains("ceiling"))
			{
				return BuildingKind.Floor;
			}
			return construction ? BuildingKind.Frame : BuildingKind.Other;
		}

		internal static RoomOpening Opening(string name, bool door)
		{
			name = (name ?? "").ToLowerInvariant();
			if (door || name.Contains("door") || name.Contains("gate") || name.Contains("arch"))
			{
				return RoomOpening.Passage;
			}
			return name.Contains("window") ? RoomOpening.Window : RoomOpening.Solid;
		}

		internal static bool WallOnFloor(float min, float max, float origin, float floor, RoomOpening opening)
		{
			if (max <= floor + 0.3f)
			{
				return false;
			}
			if (min < floor + 1.15f && max > floor + 0.65f)
			{
				return true;
			}
			if (opening == RoomOpening.Passage)
			{
				return Math.Abs(origin - floor) < 0.6f && min < floor + 3f;
			}
			return opening == RoomOpening.Window && min < floor + 1.8f && origin < floor + 1.8f && max > floor + 0.65f;
		}

		internal static bool Structural(BuildingKind kind)
		{
			return kind == BuildingKind.Wall || kind == BuildingKind.Frame || kind == BuildingKind.Floor || kind == BuildingKind.Roof || kind == BuildingKind.Stair;
		}

		internal static bool CameraSide(Vector2 point, Vector2 player, Vector2 camera, float margin = 0.15f)
		{
			Vector2 value = camera - player;
			return value.LengthSquared() > 0.0001f && Vector2.Dot(point - player, Vector2.Normalize(value)) >= 0f - margin;
		}

		internal static bool FrontFrame(Vector2 center, Vector2 inside, Vector2 cameraDirection, bool previous)
		{
			Vector2 normal = center - inside;
			return normal.LengthSquared() < 0.0625f || Front(normal, center, inside, cameraDirection, previous);
		}

		internal static bool Front(Vector2 normal, Vector2 wall, Vector2 inside, Vector2 cameraDirection, bool previous)
		{
			if (Vector2.Dot(normal, wall - inside) < 0f)
			{
				normal = -normal;
			}
			float num = Vector2.Dot(Vector2.Normalize(normal), Vector2.Normalize(cameraDirection));
			return num > 0.04f || (num >= -0.04f && previous);
		}

		internal static float Coverage(float radiusFraction, float feather, float minimumVisibility)
		{
			float num = 1f - Math.Clamp(feather, 0.05f, 1f);
			float num2 = Math.Clamp((radiusFraction - num) / Math.Max(0.01f, 1f - num), 0f, 1f);
			return (1f - minimumVisibility) * (1f - num2 * num2 * (3f - 2f * num2));
		}

		internal static float Threshold(int x, int y)
		{
			int num = 0;
			for (int i = 0; i < 3; i++)
			{
				int num2 = (x >> i) & 1;
				int num3 = (y >> i) & 1;
				num = num * 4 + ((num2 ^ num3) * 2 + num3);
			}
			return ((float)num + 0.5f) / 64f;
		}
	}
	internal sealed class FloorTracker
	{
		private float candidate;

		private float stableTime;

		private bool initialized;

		internal float Floor { get; private set; }

		internal float Reveal { get; private set; }

		internal bool OnStairs { get; private set; }

		internal void Reset()
		{
			initialized = false;
			OnStairs = false;
			stableTime = 0f;
		}

		internal void Update(bool grounded, bool stair, float supportY, float dt)
		{
			if (!initialized)
			{
				float floor = (Reveal = (candidate = supportY));
				Floor = floor;
				initialized = true;
			}
			if (!grounded)
			{
				return;
			}
			OnStairs = stair;
			if (stair)
			{
				stableTime = 0f;
			}
			else
			{
				if (Math.Abs(supportY - candidate) > 0.15f)
				{
					candidate = supportY;
					stableTime = 0f;
				}
				stableTime += Math.Max(0f, dt);
				if (stableTime >= 0.2f)
				{
					Floor = candidate;
				}
			}
			Reveal = Floor;
		}
	}
	internal enum DungeonFace
	{
		Keep,
		CutWall,
		HideRoof
	}
	internal readonly struct DungeonSlice : IEquatable<DungeonSlice>
	{
		internal readonly Vector2 Interior;

		internal readonly Vector2 TowardCamera;

		internal readonly float Floor;

		internal readonly bool HideRoof;

		internal DungeonSlice(Vector2 interior, Vector2 towardCamera, float floor, bool hideRoof)
		{
			Interior = interior;
			TowardCamera = towardCamera;
			Floor = floor;
			HideRoof = hideRoof;
		}

		public bool Equals(DungeonSlice other)
		{
			return Interior == other.Interior && TowardCamera == other.TowardCamera && Floor == other.Floor && HideRoof == other.HideRoof;
		}

		public override bool Equals(object obj)
		{
			return obj is DungeonSlice other && Equals(other);
		}

		public override int GetHashCode()
		{
			return HashCode.Combine(Interior, TowardCamera, Floor, HideRoof);
		}

		internal DungeonFace Face(Vector3 a, Vector3 b, Vector3 c, float cutHeight)
		{
			if (Math.Max(a.Y, Math.Max(b.Y, c.Y)) <= cutHeight)
			{
				return DungeonFace.Keep;
			}
			Vector3 vector = Vector3.Cross(b - a, c - a);
			float num = vector.Length();
			if (num < 1E-05f)
			{
				return DungeonFace.Keep;
			}
			float num2 = Math.Abs(vector.Y) / num;
			if (num2 > 0.65f)
			{
				return (HideRoof && Math.Min(a.Y, Math.Min(b.Y, c.Y)) >= Floor + 1.8f) ? DungeonFace.HideRoof : DungeonFace.Keep;
			}
			Vector2 vector2 = new Vector2((a.X + b.X + c.X) / 3f, (a.Z + b.Z + c.Z) / 3f);
			return (Vector2.Dot(vector2 - Interior, TowardCamera) >= -0.15f && CutawayMath.Front(new Vector2(vector.X, vector.Z), vector2, Interior, TowardCamera, previous: false)) ? DungeonFace.CutWall : DungeonFace.Keep;
		}
	}
	internal static class HoverHintText
	{
		internal static string RemapUse(string text, string nativeUse, string primary)
		{
			text = (text ?? string.Empty).Replace("$KEY_Use", primary);
			if (string.IsNullOrEmpty(nativeUse) || nativeUse == primary)
			{
				return text;
			}
			return Regex.Replace(text, "\\[[^\\]\\r\\n]*\\]", (Match bracket) => Regex.Replace(bracket.Value, "<[^>]*>|[^<]+", (Match part) => part.Value.StartsWith("<", StringComparison.Ordinal) ? part.Value : Regex.Replace(part.Value, "(?<![\\p{L}\\p{N}_])" + Regex.Escape(nativeUse) + "(?![\\p{L}\\p{N}_])", (Match _) => primary)));
		}

		internal static string Combine(string primary, string secondary)
		{
			return string.IsNullOrWhiteSpace(secondary) ? primary : (string.IsNullOrWhiteSpace(primary) ? secondary : (primary.TrimEnd() + "\n" + secondary.TrimStart()));
		}
	}
	internal static class InteractionMath
	{
		internal static bool FaceCursor(float movementSquared, bool attacking)
		{
			return movementSquared < 0.0001f || attacking;
		}

		internal static bool PrecisionEnabled(bool mode, bool local, bool ranged)
		{
			return mode && local && ranged;
		}

		internal static float FadeProgress(float current, bool obstructing, float dt, float duration)
		{
			float num = Math.Max(0f, dt) / Math.Max(0.01f, duration);
			return obstructing ? Math.Min(1f, current + num) : Math.Max(0f, current - num);
		}

		internal static float Opacity(float progress, float minimum)
		{
			float num = Math.Max(0f, Math.Min(1f, progress));
			return 1f - (1f - minimum) * num * num * (3f - 2f * num);
		}

		internal static Vector3 NearRayOrigin(Vector3 origin, Vector3 direction, Vector3 focus)
		{
			return origin + direction * Math.Max(0f, Vector3.Dot(focus - origin, direction) - 20f);
		}
	}
	internal static class OcclusionRules
	{
		internal const float NearbyCharacterDistance = 12f;

		internal const float NearCameraRadius = 1.1f;

		internal const float NearOpacity = 0.3f;

		internal const float HaloOpacity = 0.82f;

		internal const int MaximumHalos = 6;

		internal static bool Eligible(float viewportX, float viewportY, float depth, float distanceToPlayer)
		{
			return depth > 0f && distanceToPlayer <= 12f && Math.Abs(viewportX - 0.5f) <= 0.24f && Math.Abs(viewportY - 0.5f) <= 0.28f;
		}

		internal static float Radius(float depth, float verticalFovDegrees)
		{
			float val = 1.3f / (2f * Math.Max(0.1f, depth) * (float)Math.Tan((double)verticalFovDegrees * Math.PI / 360.0));
			return Math.Max(0.035f, Math.Min(0.095f, val));
		}

		internal static float HaloAlpha(float radiusFraction)
		{
			return (radiusFraction <= 0.55f) ? 0.82f : (0.82f * Math.Max(0f, Math.Min(1f, (1f - radiusFraction) / 0.45f)));
		}
	}
	internal static class PatchCompatibility
	{
		internal static bool IsKnownCompatible(string targetType, string targetMethod, string owner, string patchKind, string patchType, string patchMethod, string assemblyVersion)
		{
			return (targetType == "GameCamera" && targetMethod == "UpdateCamera" && owner == "dellarion.valheim.vanillabuildswap" && patchKind == "transpiler" && patchType == "VanillaBuildSwap.UpgradeController" && patchMethod == "CameraInput" && (assemblyVersion == "0.1.3.0" || assemblyVersion == "0.1.4.0")) || (targetType == "GameCamera" && targetMethod == "UpdateMouseCapture" && owner == "_shudnal.ConfigurationManager" && patchKind == "prefix" && patchType == "ConfigurationManager.ConfigurationManager+NativeCursor_WindowOverride" && patchMethod == "Prefix" && assemblyVersion == "1.1.27.0");
		}
	}
	internal static class RemotePlayerVisibility
	{
		internal static float Opacity(float distance, bool publicPosition, float fullDistance = 10f, float hiddenDistance = 30f)
		{
			if (publicPosition || distance <= fullDistance)
			{
				return 1f;
			}
			if (distance >= hiddenDistance || hiddenDistance <= fullDistance)
			{
				return 0f;
			}
			float num = Math.Clamp((distance - fullDistance) / (hiddenDistance - fullDistance), 0f, 1f);
			float num2 = num * num * (3f - 2f * num);
			return 1f - num2;
		}
	}
	internal static class RevealMath
	{
		internal static Vector4 Crop(Vector2 center, Vector2 radius, int width, int height)
		{
			int num = Math.Min(width, Math.Max(64, (int)Math.Ceiling(radius.X * 2f * (float)width / 64f) * 64));
			int num2 = Math.Min(height, Math.Max(64, (int)Math.Ceiling(radius.Y * 2f * (float)height / 64f) * 64));
			int num3 = Math.Clamp((int)Math.Floor(center.X * (float)width - (float)num / 2f), 0, width - num);
			int num4 = Math.Clamp((int)Math.Floor(center.Y * (float)height - (float)num2 / 2f), 0, height - num2);
			return new Vector4((float)num3 / (float)width, (float)num4 / (float)height, (float)num / (float)width, (float)num2 / (float)height);
		}

		internal static float Weight(Vector2 point, Vector2 center, Vector2 radius, float feather, float progress, float visibility)
		{
			if (radius.X <= 0f || radius.Y <= 0f)
			{
				return 0f;
			}
			return CutawayMath.Coverage(((point - center) / radius).Length(), feather, visibility) * (1f - InteractionMath.Opacity(progress, 0f));
		}
	}
	internal enum RoomOpening
	{
		Solid,
		Passage,
		Window
	}
	internal readonly struct RoomCover
	{
		internal readonly Vector2 Min;

		internal readonly Vector2 Max;

		internal RoomCover(Vector2 min, Vector2 max)
		{
			Min = min;
			Max = max;
		}

		internal bool Contains(Vector2 point)
		{
			return point.X >= Min.X && point.X <= Max.X && point.Y >= Min.Y && point.Y <= Max.Y;
		}
	}
	internal readonly struct RoomWall
	{
		internal readonly Vector2 Center;

		internal readonly Vector2 Normal;

		internal readonly float HalfWidth;

		internal readonly float HalfDepth;

		internal readonly RoomOpening Opening;

		internal RoomWall(Vector2 center, Vector2 normal, float halfWidth, RoomOpening opening = RoomOpening.Solid, float halfDepth = 0.05f)
		{
			Center = center;
			Normal = Vector2.Normalize(normal);
			HalfWidth = halfWidth;
			Opening = opening;
			HalfDepth = halfDepth;
		}

		internal bool Crosses(Vector2 a, Vector2 b)
		{
			float num = Vector2.Dot(a - Center, Normal);
			float num2 = Vector2.Dot(b - Center, Normal);
			if ((num > 0f && num2 > 0f) || (num < 0f && num2 < 0f) || Math.Abs(num - num2) < 1E-05f)
			{
				return false;
			}
			Vector2 vector = a + (b - a) * (num / (num - num2));
			return Math.Abs(Vector2.Dot(vector - Center, new Vector2(0f - Normal.Y, Normal.X))) <= HalfWidth + 0.08f;
		}
	}
	internal sealed class RoomLayout
	{
		internal const float Cell = 0.5f;

		private readonly HashSet<(int X, int Y)> cells = new HashSet<(int, int)>();

		private readonly Queue<(int X, int Y)> queue = new Queue<(int, int)>();

		private static readonly (int X, int Y)[] Steps = new(int, int)[4]
		{
			(1, 0),
			(0, 1),
			(-1, 0),
			(0, -1)
		};

		private Vector2 origin;

		private int seedX;

		private int seedY;

		internal Vector2 Center { get; private set; }

		internal bool Enclosed { get; private set; }

		internal bool RoofBounded { get; private set; }

		internal void Resolve(Vector2 player, float radius, IList<RoomWall> walls, IList<RoomCover> covers = null)
		{
			seedX = (int)Math.Floor(player.X / 0.5f);
			seedY = (int)Math.Floor(player.Y / 0.5f);
			origin = new Vector2(((float)seedX + 0.5f) * 0.5f, ((float)seedY + 0.5f) * 0.5f);
			List<RoomWall> list = SealOpenings(walls);
			RoofBounded = false;
			Enclosed = list.Count >= 3 && Flood(radius, list, null);
			if (!Enclosed && Covered(player, covers))
			{
				RoofBounded = true;
				Enclosed = Flood(radius, list, covers);
			}
			if (!Enclosed)
			{
				cells.Clear();
				Center = origin;
				return;
			}
			long num = 0L;
			long num2 = 0L;
			foreach (var cell in cells)
			{
				num += seedX + cell.X;
				num2 += seedY + cell.Y;
			}
			Center = new Vector2((float)(((double)num / (double)cells.Count + 0.5) * 0.5), (float)(((double)num2 / (double)cells.Count + 0.5) * 0.5));
		}

		private bool Flood(float radius, IList<RoomWall> walls, IList<RoomCover> covers)
		{
			cells.Clear();
			queue.Clear();
			int num = Math.Max(2, (int)Math.Floor(radius / 0.5f));
			cells.Add((0, 0));
			queue.Enqueue((0, 0));
			while (queue.Count > 0)
			{
				(int, int) tuple = queue.Dequeue();
				(int, int)[] steps = Steps;
				for (int i = 0; i < steps.Length; i++)
				{
					(int, int) tuple2 = steps[i];
					(int, int) item = (tuple.Item1 + tuple2.Item1, tuple.Item2 + tuple2.Item2);
					if (cells.Contains(item))
					{
						continue;
					}
					Vector2 a = origin + new Vector2(tuple.Item1, tuple.Item2) * 0.5f;
					Vector2 vector = origin + new Vector2(item.Item1, item.Item2) * 0.5f;
					if (covers != null && !Covered(vector, covers))
					{
						continue;
					}
					bool flag = false;
					foreach (RoomWall wall in walls)
					{
						if (wall.Crosses(a, vector))
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						if (Math.Abs(item.Item1) >= num || Math.Abs(item.Item2) >= num)
						{
							queue.Clear();
							return false;
						}
						cells.Add(item);
						queue.Enqueue(item);
					}
				}
			}
			return true;
		}

		internal static List<RoomWall> SealOpenings(IList<RoomWall> walls)
		{
			List<RoomWall> list = new List<RoomWall>(walls);
			for (int i = 0; i < walls.Count; i++)
			{
				for (int j = i + 1; j < walls.Count; j++)
				{
					RoomWall roomWall = walls[i];
					RoomWall roomWall2 = walls[j];
					if (!(Math.Abs(Vector2.Dot(roomWall.Normal, roomWall2.Normal)) < 0.995f) && !(Math.Abs(Vector2.Dot(roomWall2.Center - roomWall.Center, roomWall.Normal)) > 0.15f))
					{
						Vector2 vector = new Vector2(0f - roomWall.Normal.Y, roomWall.Normal.X);
						float value = Vector2.Dot(roomWall2.Center - roomWall.Center, vector);
						float num = Math.Abs(value) - roomWall.HalfWidth - roomWall2.HalfWidth;
						if (!(num <= 0.15f) && !(num > 2.1f))
						{
							float num2 = Math.Sign(value);
							list.Add(new RoomWall(roomWall.Center + vector * num2 * (roomWall.HalfWidth + num / 2f), roomWall.Normal, num / 2f, RoomOpening.Passage));
						}
					}
				}
			}
			return list;
		}

		private static bool Covered(Vector2 point, IList<RoomCover> covers)
		{
			if (covers != null)
			{
				foreach (RoomCover cover in covers)
				{
					if (cover.Contains(point))
					{
						return true;
					}
				}
			}
			return false;
		}

		internal bool Contains(Vector2 point)
		{
			if (!Enclosed)
			{
				return false;
			}
			return cells.Contains(((int)Math.Floor(point.X / 0.5f) - seedX, (int)Math.Floor(point.Y / 0.5f) - seedY));
		}

		internal bool Near(Vector2 point, float halfWidth)
		{
			if (Contains(point))
			{
				return true;
			}
			(int, int)[] steps = Steps;
			for (int i = 0; i < steps.Length; i++)
			{
				(int, int) tuple = steps[i];
				if (Contains(point + new Vector2(tuple.Item1, tuple.Item2) * Math.Max(0.5f, halfWidth)))
				{
					return true;
				}
			}
			return false;
		}

		internal bool Intersects(Vector2 min, Vector2 max)
		{
			foreach (var cell in cells)
			{
				Vector2 vector = origin + new Vector2(cell.X, cell.Y) * 0.5f;
				if (vector.X + 0.25f >= min.X && vector.X - 0.25f <= max.X && vector.Y + 0.25f >= min.Y && vector.Y - 0.25f <= max.Y)
				{
					return Enclosed;
				}
			}
			return false;
		}
	}
	internal enum RoomDeparture
	{
		Keep,
		Boundary,
		Floor
	}
	internal sealed class RoomResidence
	{
		private float outside;

		internal float Floor { get; private set; }

		internal Vector2 Anchor { get; private set; }

		internal void Commit(float floor, Vector2 anchor)
		{
			Floor = floor;
			Anchor = anchor;
			outside = 0f;
		}

		internal RoomDeparture Check(bool contains, bool grounded, bool stairs, float floor, float dt)
		{
			if (!grounded || stairs)
			{
				outside = 0f;
				return RoomDeparture.Keep;
			}
			if (Math.Abs(floor - Floor) > 0.65f)
			{
				return RoomDeparture.Floor;
			}
			outside = (contains ? 0f : (outside + Math.Max(0f, dt)));
			return (outside >= 0.35f) ? RoomDeparture.Boundary : RoomDeparture.Keep;
		}
	}
	internal static class ScreenSpaceMath
	{
		internal static Vector2 Viewport(Vector2 pointer, float displayWidth, float displayHeight)
		{
			return new Vector2(pointer.X / Math.Max(1f, displayWidth), pointer.Y / Math.Max(1f, displayHeight));
		}

		internal static bool InViewport(Vector3 point)
		{
			return point.Z > 0f && point.X >= 0f && point.X <= 1f && point.Y >= 0f && point.Y <= 1f;
		}

		internal static bool InReach(float squaredDistance)
		{
			return squaredDistance <= 9f;
		}

		internal static Vector2 StealthOffsets(float nameTop, float gap, float barHeight, float iconHeight)
		{
			return new Vector2(nameTop + gap + barHeight / 2f, nameTop + gap * 2f + barHeight + iconHeight / 2f);
		}

		internal static float Halo(Vector2 point, Vector2 center, float aspect, float radius)
		{
			Vector2 vector = point - center;
			vector.X *= aspect;
			float num = Math.Clamp((vector.Length() / radius - 0.55f) / 0.45f, 0f, 1f);
			return num * num * (3f - 2f * num);
		}
	}
	internal readonly struct SectionEdge
	{
		internal readonly Vector3 A;

		internal readonly Vector3 B;

		internal readonly int Material;

		internal SectionEdge(Vector3 a, Vector3 b, int material)
		{
			A = a;
			B = b;
			Material = material;
		}
	}
	internal readonly struct SectionVertex
	{
		internal readonly Vector3 Position;

		internal readonly Vector2 Uv;

		internal readonly int Edge;

		internal readonly float Along;

		internal SectionVertex(Vector3 position, Vector2 uv, int edge, float along)
		{
			Position = position;
			Uv = uv;
			Edge = edge;
			Along = along;
		}
	}
	internal sealed class SectionSurface
	{
		internal readonly List<SectionVertex> Vertices = new List<SectionVertex>();

		internal readonly List<int> Materials = new List<int>();
	}
	internal static class SectionCap
	{
		internal const float Epsilon = 0.0001f;

		internal static SectionSurface Build(IList<SectionEdge> source, Vector3 normal, bool convexOpen = false)
		{
			SectionSurface sectionSurface = new SectionSurface();
			if (source.Count == 0)
			{
				return sectionSurface;
			}
			normal = Vector3.Normalize(normal);
			Vector3 vector = Vector3.Normalize(Vector3.Cross((Math.Abs(normal.Y) < 0.9f) ? Vector3.UnitY : Vector3.UnitZ, normal));
			Vector3 vector2 = Vector3.Cross(normal, vector);
			float num = 0.0001f;
			foreach (SectionEdge item in source)
			{
				num = Math.Max(num, Math.Max(MaxAbs(item.A), MaxAbs(item.B)) * 5E-07f);
			}
			List<Vector3> list = new List<Vector3>();
			List<(int, int, int)> list2 = new List<(int, int, int)>();
			Dictionary<(long, long, long), List<int>> buckets = new Dictionary<(long, long, long), List<int>>();
			Dictionary<(int, int), int> dictionary = new Dictionary<(int, int), int>();
			for (int i = 0; i < source.Count; i++)
			{
				int num2 = Weld(source[i].A, list, buckets, num);
				int num3 = Weld(source[i].B, list, buckets, num);
				if (num2 != num3)
				{
					(int, int) key = (Math.Min(num2, num3), Math.Max(num2, num3));
					if (dictionary.TryGetValue(key, out var value))
					{
						list2[value] = (-1, -1, -1);
						dictionary.Remove(key);
					}
					else
					{
						dictionary.Add(key, list2.Count);
						list2.Add((num2, num3, i));
					}
				}
			}
			list2.RemoveAll(((int A, int B, int Source) edge) => edge.Source < 0);
			int[] array = new int[list.Count];
			foreach (var item2 in list2)
			{
				array[item2.Item1]++;
				array[item2.Item2]++;
			}
			int[] array2 = array;
			foreach (int num5 in array2)
			{
				if ((num5 & 1) != 0)
				{
					if (convexOpen)
					{
						return Convex(source, normal, vector, vector2);
					}
					throw new InvalidOperationException("The section contour is open; retaining the original solid.");
				}
			}
			List<float> list3 = new List<float>();
			foreach (Vector3 item3 in list)
			{
				list3.Add(Vector3.Dot(item3, vector2));
			}
			list3.Sort();
			List<float> list4 = new List<float>();
			foreach (float item4 in list3)
			{
				if (list4.Count == 0 || item4 - list4[list4.Count - 1] > 0.0001f)
				{
					list4.Add(item4);
				}
			}
			List<(float, int)> list5 = new List<(float, int)>();
			for (int num6 = 1; num6 < list4.Count; num6++)
			{
				float num7 = list4[num6 - 1];
				float num8 = list4[num6];
				float num9 = (num7 + num8) * 0.5f;
				list5.Clear();
				for (int num10 = 0; num10 < list2.Count; num10++)
				{
					(int, int, int) tuple = list2[num10];
					float num11 = Vector3.Dot(list[tuple.Item1], vector2);
					float num12 = Vector3.Dot(list[tuple.Item2], vector2);
					if (!(num9 <= Math.Min(num11, num12)) && !(num9 >= Math.Max(num11, num12)))
					{
						Vector3 vector3 = Vector3.Lerp(list[tuple.Item1], list[tuple.Item2], (num9 - num11) / (num12 - num11));
						list5.Add((Vector3.Dot(vector3, vector), num10));
					}
				}
				list5.Sort(delegate((float X, int Edge) tuple4, (float X, int Edge) tuple5)
				{
					int num14 = tuple4.X.CompareTo(tuple5.X);
					return (num14 != 0) ? num14 : tuple4.Edge.CompareTo(tuple5.Edge);
				});
				if ((list5.Count & 1) != 0)
				{
					throw new InvalidOperationException("The section has an unmatched boundary.");
				}
				for (int num13 = 0; num13 < list5.Count; num13 += 2)
				{
					if (!(list5[num13 + 1].Item1 - list5[num13].Item1 <= 0.0001f))
					{
						(int, int, int) tuple2 = list2[list5[num13].Item2];
						(int, int, int) tuple3 = list2[list5[num13 + 1].Item2];
						SectionVertex a = At(source, tuple2.Item3, num7, vector, vector2);
						SectionVertex b = At(source, tuple3.Item3, num7, vector, vector2);
						SectionVertex sectionVertex = At(source, tuple3.Item3, num8, vector, vector2);
						SectionVertex c = At(source, tuple2.Item3, num8, vector, vector2);
						Add(sectionSurface, a, b, sectionVertex, source[tuple2.Item3].Material, normal);
						Add(sectionSurface, a, sectionVertex, c, source[tuple2.Item3].Material, normal);
					}
				}
			}
			return sectionSurface;
		}

		private static SectionSurface Convex(IList<SectionEdge> source, Vector3 normal, Vector3 u, Vector3 v)
		{
			List<SectionVertex> list = new List<SectionVertex>();
			for (int i = 0; i < source.Count; i++)
			{
				int[] array = new int[2] { 0, 1 };
				foreach (int num in array)
				{
					Vector3 vector = ((num == 0) ? source[i].A : source[i].B);
					list.Add(new SectionVertex(vector, new Vector2(Vector3.Dot(vector, u), Vector3.Dot(vector, v)), i, num));
				}
			}
			list.Sort(delegate(SectionVertex a, SectionVertex b)
			{
				int num4 = a.Uv.X.CompareTo(b.Uv.X);
				return (num4 != 0) ? num4 : a.Uv.Y.CompareTo(b.Uv.Y);
			});
			List<SectionVertex> list2 = new List<SectionVertex>();
			foreach (SectionVertex item in list)
			{
				if (list2.Count == 0 || Vector2.DistanceSquared(item.Uv, list2[list2.Count - 1].Uv) > 9.999999E-09f)
				{
					list2.Add(item);
				}
			}
			List<SectionVertex> list3 = new List<SectionVertex>();
			foreach (SectionVertex item2 in list2)
			{
				while (list3.Count >= 2 && Cross(list3[list3.Count - 2], list3[list3.Count - 1], item2) <= 0f)
				{
					list3.RemoveAt(list3.Count - 1);
				}
				list3.Add(item2);
			}
			int count = list3.Count;
			for (int num2 = list2.Count - 2; num2 >= 0; num2--)
			{
				SectionVertex sectionVertex = list2[num2];
				while (list3.Count > count && Cross(list3[list3.Count - 2], list3[list3.Count - 1], sectionVertex) <= 0f)
				{
					list3.RemoveAt(list3.Count - 1);
				}
				list3.Add(sectionVertex);
			}
			if (list3.Count > 1)
			{
				list3.RemoveAt(list3.Count - 1);
			}
			SectionSurface sectionSurface = new SectionSurface();
			for (int num3 = 1; num3 < list3.Count - 1; num3++)
			{
				Add(sectionSurface, list3[0], list3[num3], list3[num3 + 1], source[list3[0].Edge].Material, normal);
			}
			return sectionSurface;
			static float Cross(SectionVertex a, SectionVertex b, SectionVertex c)
			{
				return (b.Uv.X - a.Uv.X) * (c.Uv.Y - a.Uv.Y) - (b.Uv.Y - a.Uv.Y) * (c.Uv.X - a.Uv.X);
			}
		}

		private static float MaxAbs(Vector3 p)
		{
			return Math.Max(Math.Abs(p.X), Math.Max(Math.Abs(p.Y), Math.Abs(p.Z)));
		}

		private static int Weld(Vector3 point, List<Vector3> points, Dictionary<(long, long, long), List<int>> buckets, float epsilon)
		{
			long num = (long)Math.Floor(point.X / epsilon);
			long num2 = (long)Math.Floor(point.Y / epsilon);
			long num3 = (long)Math.Floor(point.Z / epsilon);
			int num4 = int.MaxValue;
			for (int i = -1; i <= 1; i++)
			{
				for (int j = -1; j <= 1; j++)
				{
					for (int k = -1; k <= 1; k++)
					{
						if (!buckets.TryGetValue((num + i, num2 + j, num3 + k), out var value))
						{
							continue;
						}
						foreach (int item in value)
						{
							if (item < num4 && Vector3.DistanceSquared(point, points[item]) <= epsilon * epsilon)
							{
								num4 = item;
							}
						}
					}
				}
			}
			if (num4 != int.MaxValue)
			{
				return num4;
			}
			int count = points.Count;
			points.Add(point);
			if (!buckets.TryGetValue((num, num2, num3), out var value2))
			{
				value2 = (buckets[(num, num2, num3)] = new List<int>());
			}
			value2.Add(count);
			return count;
		}

		private static SectionVertex At(IList<SectionEdge> edges, int index, float y, Vector3 u, Vector3 v)
		{
			SectionEdge sectionEdge = edges[index];
			float num = Vector3.Dot(sectionEdge.A, v);
			float num2 = Vector3.Dot(sectionEdge.B, v);
			float num3 = Math.Clamp((y - num) / (num2 - num), 0f, 1f);
			Vector3 vector = Vector3.Lerp(sectionEdge.A, sectionEdge.B, num3);
			return new SectionVertex(vector, new Vector2(Vector3.Dot(vector, u), Vector3.Dot(vector, v)), index, num3);
		}

		private static void Add(SectionSurface surface, SectionVertex a, SectionVertex b, SectionVertex c, int material, Vector3 normal)
		{
			float num = Vector3.Dot(Vector3.Cross(b.Position - a.Position, c.Position - a.Position), normal);
			if (!(Math.Abs(num) <= 9.999999E-09f))
			{
				surface.Vertices.Add(a);
				surface.Vertices.Add((num > 0f) ? b : c);
				surface.Vertices.Add((num > 0f) ? c : b);
				surface.Materials.Add(material);
			}
		}
	}
	internal sealed class StateLease<T, TState>
	{
		private readonly Func<T, bool> exists;

		private readonly Func<T, TState> read;

		private readonly Action<T, TState> apply;

		private readonly Action<T, TState> restore;

		private readonly List<(T item, TState state)> saved = new List<(T, TState)>();

		private readonly HashSet<T> seen = new HashSet<T>();

		internal StateLease(Func<T, bool> exists, Func<T, TState> read, Action<T, TState> apply, Action<T, TState> restore)
		{
			this.exists = exists;
			this.read = read;
			this.apply = apply;
			this.restore = restore;
		}

		internal void Begin(IEnumerable<T> items)
		{
			End();
			try
			{
				foreach (T item in items)
				{
					if (exists(item) && seen.Add(item))
					{
						TState val = read(item);
						saved.Add((item, val));
						apply(item, val);
					}
				}
			}
			catch
			{
				End();
				throw;
			}
		}

		internal void End()
		{
			Exception ex = null;
			try
			{
				for (int num = saved.Count - 1; num >= 0; num--)
				{
					try
					{
						if (exists(saved[num].item))
						{
							restore(saved[num].item, saved[num].state);
						}
					}
					catch (Exception ex2)
					{
						ex = ex ?? ex2;
					}
				}
			}
			finally
			{
				saved.Clear();
				seen.Clear();
			}
			if (ex != null)
			{
				throw new InvalidOperationException("A render state could not be restored.", ex);
			}
		}
	}
	internal readonly struct StoreyFloor
	{
		internal readonly Vector2 Min;

		internal readonly Vector2 Max;

		internal readonly float Bottom;

		internal readonly float Top;

		internal readonly bool Hidden;

		internal StoreyFloor(Vector2 min, Vector2 max, float bottom, float top, bool hidden)
		{
			Min = min;
			Max = max;
			Bottom = bottom;
			Top = top;
			Hidden = hidden;
		}
	}
	internal static class StoreyVisibility
	{
		internal static bool Hidden(Vector3 origin, float lowestSolidPoint, float playerFloor, IList<StoreyFloor> floors)
		{
			float num = Math.Min(origin.Y, lowestSolidPoint);
			float num2 = float.NegativeInfinity;
			bool flag = false;
			foreach (StoreyFloor floor in floors)
			{
				if (!(origin.X < floor.Min.X - 0.05f) && !(origin.X > floor.Max.X + 0.05f) && !(origin.Z < floor.Min.Y - 0.05f) && !(origin.Z > floor.Max.Y + 0.05f) && !(num < floor.Bottom - 0.05f) && !(num < floor.Top - 0.35f))
				{
					bool flag2 = floor.Hidden && floor.Bottom > playerFloor + 0.8f;
					if (floor.Top > num2 + 0.001f)
					{
						num2 = floor.Top;
						flag = flag2;
					}
					else if (Math.Abs(floor.Top - num2) <= 0.001f)
					{
						flag = flag && flag2;
					}
				}
			}
			return flag;
		}
	}
	internal sealed class TargetSelection<T> where T : class
	{
		internal T Target { get; private set; }

		internal void Click(T candidate)
		{
			if (candidate != null)
			{
				Target = candidate;
			}
		}

		internal void Validate(Func<T, bool> valid)
		{
			if (Target != null && !valid(Target))
			{
				Clear();
			}
		}

		internal void Clear()
		{
			Target = null;
		}
	}
	internal static class TemporaryVisibility
	{
		internal static void Render<T>(IEnumerable<T> objects, Func<T, bool> exists, Func<T, bool> read, Action<T, bool> write, Action render)
		{
			Dictionary<T, bool> dictionary = new Dictionary<T, bool>();
			try
			{
				foreach (T @object in objects)
				{
					if (exists(@object) && !dictionary.ContainsKey(@object))
					{
						dictionary.Add(@object, read(@object));
						write(@object, arg2: true);
					}
				}
				render();
			}
			finally
			{
				foreach (KeyValuePair<T, bool> item in dictionary)
				{
					if (exists(item.Key))
					{
						write(item.Key, item.Value);
					}
				}
			}
		}
	}
	internal readonly struct ClipPoint
	{
		internal readonly Vector3 Position;

		internal readonly Vector3 Weights;

		internal readonly bool OnPlane;

		internal ClipPoint(Vector3 position, Vector3 weights, bool onPlane = false)
		{
			Position = position;
			Weights = weights;
			OnPlane = onPlane;
		}
	}
	internal static class TriangleClip
	{
		internal static void Below(Vector3 a, Vector3 b, Vector3 c, Vector4 plane, bool below, List<ClipPoint> result)
		{
			result.Clear();
			ClipPoint[] array = new ClipPoint[3]
			{
				new ClipPoint(a, Vector3.UnitX),
				new ClipPoint(b, Vector3.UnitY),
				new ClipPoint(c, Vector3.UnitZ)
			};
			for (int i = 0; i < 3; i++)
			{
				ClipPoint clipPoint = array[i];
				ClipPoint clipPoint2 = array[(i + 1) % 3];
				float num = Distance(clipPoint.Position, plane);
				float num2 = Distance(clipPoint2.Position, plane);
				bool flag = (below ? (num <= 0f) : (num >= 0f));
				bool flag2 = (below ? (num2 <= 0f) : (num2 >= 0f));
				if (flag)
				{
					result.Add(new ClipPoint(clipPoint.Position, clipPoint.Weights, Math.Abs(num) <= 0.0001f));
				}
				if (flag != flag2)
				{
					float amount = num / (num - num2);
					result.Add(new ClipPoint(Vector3.Lerp(clipPoint.Position, clipPoint2.Position, amount), Vector3.Lerp(clipPoint.Weights, clipPoint2.Weights, amount), onPlane: true));
				}
			}
		}

		private static float Distance(Vector3 p, Vector4 plane)
		{
			return (float)((double)p.X * (double)plane.X + (double)p.Y * (double)plane.Y + (double)p.Z * (double)plane.Z + (double)plane.W);
		}
	}
	internal static class ViewOcclusion
	{
		internal static bool WallBetween(RoomWall wall, Vector2 player, Vector2 camera)
		{
			float num = Vector2.Dot(player - wall.Center, wall.Normal);
			float num2 = Vector2.Dot(camera - wall.Center, wall.Normal);
			float num3 = Math.Max(0.02f, wall.HalfDepth) + 0.04f;
			return Math.Abs(num) > num3 && num * num2 < 0f;
		}

		internal static float DistanceSquared(RoomWall wall, Vector2 point)
		{
			Vector2 value = point - wall.Center;
			Vector2 value2 = new Vector2(0f - wall.Normal.Y, wall.Normal.X);
			float num = Vector2.Dot(value, wall.Normal);
			float num2 = Math.Max(0f, Math.Abs(Vector2.Dot(value, value2)) - wall.HalfWidth);
			return num * num + num2 * num2;
		}

		internal static bool NearSegment(Vector3 point, Vector3 player, Vector3 camera, float margin)
		{
			Vector3 vector = camera - player;
			float num = vector.LengthSquared();
			float num2 = ((num > 0.0001f) ? Math.Clamp(Vector3.Dot(point - player, vector) / num, 0f, 1f) : 0f);
			return Vector3.DistanceSquared(point, player + vector * num2) <= margin * margin;
		}

		internal static bool CameraCanopy(Vector4 rectangle, float nearest, float playerDepth, float distanceFromPlayer, bool containsCamera)
		{
			if (nearest >= playerDepth - 0.25f || distanceFromPlayer < 6f)
			{
				return false;
			}
			float num = Math.Max(0f, Math.Min(0.95f, rectangle.Z) - Math.Max(0.05f, rectangle.X));
			float num2 = Math.Max(0f, Math.Min(0.95f, rectangle.W) - Math.Max(0.05f, rectangle.Y));
			return num * num2 >= 0.15f && (containsCamera || nearest < playerDepth * 0.8f);
		}
	}
	internal enum PartView
	{
		Native,
		Protected,
		Hidden,
		Cut
	}
	internal readonly struct PartVisibility : IEquatable<PartVisibility>
	{
		internal readonly PartView View;

		internal readonly float Height;

		internal readonly SectionRun[] Sections;

		internal PartVisibility(PartView view, float height = 0f, IList<SectionRun> sections = null)
		{
			View = view;
			Height = height;
			Sections = null;
			if (sections != null)
			{
				Sections = new SectionRun[sections.Count];
				for (int i = 0; i < sections.Count; i++)
				{
					Sections[i] = sections[i];
				}
			}
		}

		public bool Equals(PartVisibility other)
		{
			if (View == other.View && Height == other.Height)
			{
				SectionRun[] sections = Sections;
				int num = ((sections != null) ? sections.Length : 0);
				SectionRun[] sections2 = other.Sections;
				if (num == ((sections2 != null) ? sections2.Length : 0))
				{
					if (Sections != null)
					{
						for (int i = 0; i < Sections.Length; i++)
						{
							SectionRun sectionRun = Sections[i];
							SectionRun sectionRun2 = other.Sections[i];
							if (sectionRun.From != sectionRun2.From || sectionRun.To != sectionRun2.To || sectionRun.Front != sectionRun2.Front || sectionRun.AlongX != sectionRun2.AlongX)
							{
								return false;
							}
						}
					}
					return true;
				}
			}
			return false;
		}

		public override bool Equals(object value)
		{
			return value is PartVisibility other && Equals(other);
		}

		public override int GetHashCode()
		{
			return ((int)View * 397) ^ Height.GetHashCode();
		}
	}
	internal sealed class VisibilityOverlay<TKey, TState>
	{
		private readonly Dictionary<TKey, TState> baseline = new Dictionary<TKey, TState>();

		private readonly Dictionary<TKey, TState> overrides = new Dictionary<TKey, TState>();

		private readonly Dictionary<TKey, TState> current = new Dictionary<TKey, TState>();

		private readonly HashSet<TKey> affected = new HashSet<TKey>();

		private readonly List<TKey> changed = new List<TKey>();

		private readonly IEqualityComparer<TState> comparer;

		internal IReadOnlyDictionary<TKey, TState> Current => current;

		internal VisibilityOverlay(IEqualityComparer<TState> comparer = null)
		{
			this.comparer = comparer ?? EqualityComparer<TState>.Default;
		}

		internal bool TryOverride(TKey key, out TState value)
		{
			return overrides.TryGetValue(key, out value);
		}

		internal bool TryBaseline(TKey key, out TState value)
		{
			return baseline.TryGetValue(key, out value);
		}

		internal void Reset(IEnumerable<KeyValuePair<TKey, TState>> values)
		{
			Clear();
			foreach (KeyValuePair<TKey, TState> value in values)
			{
				baseline.Add(value.Key, value.Value);
				current.Add(value.Key, value.Value);
			}
		}

		internal IReadOnlyList<TKey> Replace(IReadOnlyDictionary<TKey, TState> next)
		{
			affected.Clear();
			changed.Clear();
			foreach (TKey key in overrides.Keys)
			{
				affected.Add(key);
			}
			foreach (TKey key2 in next.Keys)
			{
				affected.Add(key2);
			}
			foreach (TKey item in affected)
			{
				TState value;
				bool flag = current.TryGetValue(item, out value);
				TState value2;
				bool flag2 = next.TryGetValue(item, out value2) || baseline.TryGetValue(item, out value2);
				if (flag != flag2 || (flag && !comparer.Equals(value, value2)))
				{
					if (flag2)
					{
						current[item] = value2;
					}
					else
					{
						current.Remove(item);
					}
					changed.Add(item);
				}
			}
			overrides.Clear();
			foreach (KeyValuePair<TKey, TState> item2 in next)
			{
				overrides.Add(item2.Key, item2.Value);
			}
			return changed;
		}

		internal void Clear()
		{
			baseline.Clear();
			overrides.Clear();
			current.Clear();
			affected.Clear();
			changed.Clear();
		}
	}
	internal static class VisualRules
	{
		internal static bool Bush(string prefab, bool tree, bool character)
		{
			return !tree && !character && (Contains(prefab, "bush") || Contains(prefab, "shrub"));
		}

		internal static bool Natural(string prefab, bool tree)
		{
			return tree || Contains(prefab, "bush") || Contains(prefab, "shrub") || Contains(prefab, "rock") || Contains(prefab, "boulder");
		}

		private static bool Contains(string value, string part)
		{
			return value != null && value.IndexOf(part, StringComparison.OrdinalIgnoreCase) >= 0;
		}

		internal static bool Backdrop(float width, float height, float screenWidth, float screenHeight)
		{
			return width >= screenWidth * 0.85f && height >= screenHeight * 0.85f;
		}

		internal static bool Foreground(bool hidden, bool natural, bool character, float depthFromPlayer)
		{
			return !character && (hidden || (natural && depthFromPlayer < -1f));
		}

		internal static bool CoversPlayer(float minX, float minY, float maxX, float maxY, float nearestDepth, float playerDepth, float x, float y, float radiusX, float radiusY)
		{
			if (nearestDepth >= playerDepth - 0.25f || radiusX <= 0f || radiusY <= 0f)
			{
				return false;
			}
			float num = Math.Max(minX - x, Math.Max(0f, x - maxX)) / radiusX;
			float num2 = Math.Max(minY - y, Math.Max(0f, y - maxY)) / radiusY;
			return num * num + num2 * num2 <= 1f;
		}
	}
	internal sealed class WorldClickState
	{
		private int lastPress = -1;

		private bool pressLatched;

		private float expires;

		internal bool Consumed { get; private set; }

		internal bool Pending { get; private set; }

		internal bool Begin(bool held, bool down, int frame)
		{
			if (!held && !down)
			{
				Consumed = false;
				pressLatched = false;
				return false;
			}
			if (!down || pressLatched || lastPress == frame)
			{
				return false;
			}
			pressLatched = true;
			lastPress = frame;
			return true;
		}

		internal void Consume()
		{
			Consumed = true;
		}

		internal void Defer(float now)
		{
			Pending = true;
			expires = now + 1f;
		}

		internal bool Complete(float now, bool allowed, bool inventoryVisible, bool reopened)
		{
			if (!Pending)
			{
				return false;
			}
			if (!allowed || reopened || now >= expires)
			{
				Pending = false;
				return false;
			}
			if (inventoryVisible)
			{
				return false;
			}
			Pending = false;
			return true;
		}

		internal void Reset()
		{
			Consumed = false;
			Pending = false;
			pressLatched = false;
			lastPress = -1;
		}
	}
	internal sealed class BowTrajectoryPreview
	{
		private const int Capacity = 512;

		private const float LineWidth = 0.035f;

		private static readonly int HitMask = LayerMask.GetMask(new string[11]
		{
			"Default", "static_solid", "Default_small", "piece", "terrain", "character", "character_net", "character_ghost", "hitbox", "vehicle",
			"viewblock"
		});

		private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[64];

		private readonly Vector3[] points = (Vector3[])(object)new Vector3[512];

		private LineRenderer line;

		private Material material;

		private Player lastPlayer;

		private ItemData lastWeapon;

		private Transform origin;

		internal void Update(Camera camera, Player player)
		{
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
			if (!((Character)player).IsDrawingBow() || currentWeapon?.m_shared?.m_attack == null || !currentWeapon.m_shared.m_attack.m_bowDraw)
			{
				Hide();
				return;
			}
			Attack attack = currentWeapon.m_shared.m_attack;
			ItemData ammoItem = ((Humanoid)player).GetAmmoItem();
			ProjectileAim.Parameters(player, attack, ammoItem, ((Humanoid)player).GetAttackDrawPercentage(), out var projectile, out var speed);
			if (!Object.op_Implicit((Object)(object)projectile))
			{
				Hide();
				return;
			}
			if ((Object)(object)lastPlayer != (Object)(object)player || lastWeapon != currentWeapon || !Object.op_Implicit((Object)(object)origin))
			{
				lastPlayer = player;
				lastWeapon = currentWeapon;
				origin = ((!string.IsNullOrEmpty(attack.m_attackOriginJoint) && Object.op_Implicit((Object)(object)((Character)player).GetVisual())) ? Utils.FindChild(((Character)player).GetVisual().transform, attack.m_attackOriginJoint, (IterativeSearchType)0) : ((Component)player).transform);
			}
			if (!Object.op_Implicit((Object)(object)origin))
			{
				Hide();
				return;
			}
			Transform transform = ((Component)player).transform;
			Vector3 val = origin.position + transform.up * attack.m_attackHeight + transform.forward * attack.m_attackRange + transform.right * attack.m_attackOffset;
			Vector3 val2 = ProjectileAim.Direction(camera, player, val, projectile, speed);
			Vector3 position = CameraRelativeMovement.ToNumerics(val);
			Vector3 velocity = CameraRelativeMovement.ToNumerics(val2 * speed);
			points[0] = val;
			int num = 1;
			float dt = Mathf.Max(0.001f, Time.fixedDeltaTime);
			for (int i = 1; i < 512; i++)
			{
				Vector3 val3 = CameraRelativeMovement.ToUnity(position);
				CameraMath.StepProjectile(ref position, ref velocity, projectile.m_gravity, projectile.m_drag, dt);
				Vector3 val4 = CameraRelativeMovement.ToUnity(position);
				if (Trace(val3, val4, projectile.m_rayRadius, player, out var point))
				{
					points[num++] = point;
					break;
				}
				points[num++] = val4;
			}
			if (EnsureLine())
			{
				Image val5 = (Object.op_Implicit((Object)(object)Hud.instance) ? Hud.instance.m_crosshairBow : null);
				Color val6 = (Object.op_Implicit((Object)(object)val5) ? ((Graphic)val5).color : Color.white);
				line.startColor = val6;
				line.endColor = val6;
				line.positionCount = num;
				for (int j = 0; j < num; j++)
				{
					line.SetPosition(j, points[j]);
				}
				((Renderer)line).enabled = true;
			}
		}

		private bool Trace(Vector3 from, Vector3 to, float radius, Player player, out Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			int num = ((radius > 0f) ? Physics.SphereCastNonAlloc(from, radius, ((Vector3)(ref val)).normalized, hits, ((Vector3)(ref val)).magnitude, HitMask, (QueryTriggerInteraction)1) : Physics.RaycastNonAlloc(from, ((Vector3)(ref val)).normalized, hits, ((Vector3)(ref val)).magnitude, HitMask, (QueryTriggerInteraction)1));
			float num2 = float.PositiveInfinity;
			point = to;
			for (int i = 0; i < num; i++)
			{
				RaycastHit val2 = hits[i];
				if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider) && !((Object)(object)((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Character>() == (Object)(object)player) && !(((RaycastHit)(ref val2)).distance >= num2))
				{
					num2 = ((RaycastHit)(ref val2)).distance;
					point = ((RaycastHit)(ref val2)).point;
				}
			}
			return num2 < float.PositiveInfinity;
		}

		private bool EnsureLine()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)line))
			{
				return true;
			}
			Shader val = Shader.Find("Sprites/Default");
			if (!Object.op_Implicit((Object)(object)val) || !val.isSupported)
			{
				return false;
			}
			material = new Material(val)
			{
				hideFlags = (HideFlags)61
			};
			GameObject val2 = new GameObject("IsometricView trajectory")
			{
				hideFlags = (HideFlags)61
			};
			line = val2.AddComponent<LineRenderer>();
			((Renderer)line).sharedMaterial = material;
			line.useWorldSpace = true;
			line.startWidth = 0.035f;
			line.endWidth = 0.035f;
			((Renderer)line).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)line).receiveShadows = false;
			((Renderer)line).enabled = false;
			return true;
		}

		internal void Hide()
		{
			if (Object.op_Implicit((Object)(object)line))
			{
				((Renderer)line).enabled = false;
			}
		}

		internal void Dispose()
		{
			if (Object.op_Implicit((Object)(object)line))
			{
				Object.Destroy((Object)(object)((Component)line).gameObject);
			}
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
			line = null;
			material = null;
			lastPlayer = null;
			lastWeapon = null;
			origin = null;
		}
	}
	internal static class CameraRelativeMovement
	{
		internal static Vector3 ToNumerics(Vector3 value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(value.x, value.y, value.z);
		}

		internal static Vector3 ToUnity(Vector3 value)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(value.X, value.Y, value.Z);
		}

		internal static Vector3 Rebase(Vector3 input, Vector3 forward, Vector3 look)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			return ToUnity(ControlMath.Rebase(ControlMath.Movement(ToNumerics(input), ToNumerics(forward)), ToNumerics(look)));
		}
	}
	internal sealed class CenterCrosshairVisibility
	{
		private Graphic image;

		private bool originalEnabled;

		internal void Hide(Graphic nativeImage)
		{
			if ((Object)(object)image != (Object)(object)nativeImage)
			{
				Restore();
				image = nativeImage;
				if (Object.op_Implicit((Object)(object)image))
				{
					originalEnabled = ((Behaviour)image).enabled;
				}
			}
			if (Object.op_Implicit((Object)(object)image))
			{
				((Behaviour)image).enabled = false;
			}
		}

		internal void Restore()
		{
			if (Object.op_Implicit((Object)(object)image))
			{
				((Behaviour)image).enabled = originalEnabled;
			}
			image = null;
		}
	}
	internal static class ChestFilterTooltip
	{
		internal const string PluginId = "dellarion.valheim.vanillachestitemcategory";

		private static Action<Hud, Player> track;

		private static Action flush;

		internal static void Install(Harmony harmony)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("dellarion.valheim.vanillachestitemcategory", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
			{
				return;
			}
			try
			{
				Type type = ((object)value.Instance).GetType().Assembly.GetType("VanillaChestItemCategory.HudHoverFilterIcon");
				if (!(type == null))
				{
					MethodInfo methodInfo = AccessTools.Method(type, "Track", new Type[2]
					{
						typeof(Hud),
						typeof(Player)
					}, (Type[])null);
					MethodInfo methodInfo2 = AccessTools.Method(type, "Flush", Type.EmptyTypes, (Type[])null);
					if (!(methodInfo == null) && !(methodInfo2 == null))
					{
						harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ChestFilterTooltip), "UseCursorTooltip", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
						track = (Action<Hud, Player>)methodInfo.CreateDelegate(typeof(Action<Hud, Player>));
						flush = (Action)methodInfo2.CreateDelegate(typeof(Action));
					}
				}
			}
			catch (Exception error)
			{
				Report(error);
			}
		}

		private static IEnumerable<CodeInstruction> UseCursorTooltip(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo objB = AccessTools.Field(typeof(Hud), "m_hoverName");
			MethodInfo methodInfo = AccessTools.Method(typeof(Humanoid), "GetHoverObject", (Type[])null, (Type[])null);
			int num = 0;
			int num2 = 0;
			foreach (CodeInstruction item in list)
			{
				if (item.opcode == OpCodes.Ldfld && object.Equals(item.operand, objB))
				{
					item.opcode = OpCodes.Call;
					item.operand = AccessTools.Method(typeof(ChestFilterTooltip), "Label", (Type[])null, (Type[])null);
					num++;
				}
				else if ((item.opcode == OpCodes.Callvirt || item.opcode == OpCodes.Call) && item.operand is MethodInfo methodInfo2 && methodInfo2.GetBaseDefinition() == methodInfo.GetBaseDefinition())
				{
					item.opcode = OpCodes.Call;
					item.operand = AccessTools.Method(typeof(ChestFilterTooltip), "Target", (Type[])null, (Type[])null);
					num2++;
				}
			}
			if (num != 1 || num2 != 1)
			{
				throw new InvalidOperationException("Unrecognized ChestItemFilter tooltip layout.");
			}
			return list;
		}

		private static TextMeshProUGUI Label(Hud hud)
		{
			CursorInteractionController cursorInteractionController = Plugin.Instance?.Interactions;
			return Object.op_Implicit((Object)(object)cursorInteractionController?.DisplayedLabel) ? cursorInteractionController.DisplayedLabel : hud.m_hoverName;
		}

		private static GameObject Target(Humanoid player)
		{
			CursorInteractionController cursorInteractionController = Plugin.Instance?.Interactions;
			return Object.op_Implicit((Object)(object)cursorInteractionController?.DisplayedLabel) ? cursorInteractionController.DisplayedTarget : player.GetHoverObject();
		}

		internal static void Refresh(TMP_Text label)
		{
			if (track == null)
			{
				return;
			}
			try
			{
				track(Hud.instance, Player.m_localPlayer);
				label.ForceMeshUpdate(false, false);
				flush();
			}
			catch (Exception error)
			{
				Report(error);
			}
		}

		private static void Report(Exception error)
		{
			track = null;
			Plugin.Instance?.Warn("Chest filter cursor icon unavailable: " + error.Message);
		}
	}
	internal static class CombatTextRange
	{
		internal static void Install(Harmony harmony)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(DamageText), "RPC_DamageText", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(CombatTextRange), "Rewrite", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static IEnumerable<CodeInstruction> Rewrite(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo position = AccessTools.PropertyGetter(typeof(Transform), "position");
			MethodInfo origin = AccessTools.Method(typeof(CombatTextRange), "Origin", (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, position))
				{
					instruction.opcode = OpCodes.Call;
					instruction.operand = origin;
				}
				yield return instruction;
			}
		}

		private static Vector3 Origin(Transform camera)
		{
			//IL_0028: 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_0035: 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)
			Player localPlayer = Player.m_localPlayer;
			Plugin instance = Plugin.Instance;
			return (instance != null && instance.CameraController.Active && Object.op_Implicit((Object)(object)localPlayer)) ? ((Component)localPlayer).transform.position : camera.position;
		}
	}
	internal sealed class CursorDrawIndicator
	{
		private RectTransform rect;

		private Vector3 originalPosition;

		private Vector2 originalPivot;

		private Quaternion originalRotation;

		internal void Update(Image image)
		{
			//IL_009c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)image) || !((Component)image).gameObject.activeInHierarchy)
			{
				Restore();
				return;
			}
			if ((Object)(object)rect != (Object)(object)((Graphic)image).rectTransform)
			{
				Restore();
				rect = ((Graphic)image).rectTransform;
				originalPosition = ((Transform)rect).localPosition;
				originalPivot = rect.pivot;
				originalRotation = ((Transform)rect).localRotation;
			}
			rect.pivot = new Vector2(0.5f, 0.5f);
			((Transform)rect).localRotation = Quaternion.identity;
			Transform parent = ((Transform)rect).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			Canvas componentInParent = ((Component)image).GetComponentInParent<Canvas>();
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)componentInParent))
			{
				Camera val2 = (((int)componentInParent.renderMode == 0) ? null : componentInParent.worldCamera);
				Vector3 position = default(Vector3);
				if (RectTransformUtility.ScreenPointToWorldPointInRectangle(val, Vector2.op_Implicit(ZInput.pointerPosition), val2, ref position))
				{
					((Transform)rect).position = position;
				}
			}
		}

		internal void Restore()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)rect))
			{
				rect.pivot = originalPivot;
				((Transform)rect).localRotation = originalRotation;
				((Transform)rect).localPosition = originalPosition;
			}
			rect = null;
		}
	}
	internal sealed class CursorFacingController
	{
		private static readonly FieldRef<Player, float> Pitch = AccessTools.FieldRefAccess<Player, float>("m_lookPitch");

		private Player player;

		private float originalPitch;

		private static readonly FieldRef<Character, Vector3> MoveDirection = AccessTools.FieldRefAccess<Character, Vector3>("m_moveDir");

		internal bool ShouldFace(Player local)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			bool attacking = ZInput.GetMouseButton(0) || ZInput.GetMouseButton(2);
			Vector3 val = MoveDirection.Invoke((Character)(object)local);
			return InteractionMath.FaceCursor(((Vector3)(ref val)).sqrMagnitude, attacking);
		}

		internal void ApplyMovement(Player local, Vector3 direction)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player != (Object)(object)local)
			{
				Restore();
				player = local;
				originalPitch = Pitch.Invoke(local);
			}
			if (((Vector3)(ref direction)).sqrMagnitude > 0.0001f)
			{
				((Character)local).SetLookDir(((Vector3)(ref direction)).normalized, 0f);
			}
			Pitch.Invoke(local) = 0f;
		}

		internal void Apply(Player local, Camera camera)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player != (Object)(object)local)
			{
				Restore();
				player = local;
				originalPitch = Pitch.Invoke(local);
			}
			Ray val = ScreenCoordinates.PointerRay(camera);
			Plane val2 = default(Plane);
			((Plane)(ref val2))..ctor(Vector3.up, ((Character)local).GetCenterPoint());
			float num = default(float);
			Vector3 val3 = (((Plane)(ref val2)).Raycast(val, ref num) ? ((Ray)(ref val)).GetPoint(num) : (((Character)local).GetCenterPoint() + ((Component)camera).transform.forward));
			Vector3 val4 = val3 - ((Character)local).GetCenterPoint();
			val4.y = 0f;
			if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f)
			{
				((Character)local).SetLookDir(((Vector3)(ref val4)).normalized, 0f);
			}
			Pitch.Invoke(local) = 0f;
		}

		internal void Restore()
		{
			if (Object.op_Implicit((Object)(object)player))
			{
				Pitch.Invoke(player) = originalPitch;
			}
			player = null;
		}
	}
	internal sealed class CursorInteractionController
	{
		private static readonly FieldRef<Player, int> Mask = AccessTools.FieldRefAccess<Player, int>("m_interactMask");

		private static readonly MethodInfo NativeInteract = AccessTools.Method(typeof(Player), "Interact", (Type[])null, (Type[])null);

		private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[128];

		private GameObject hovering;

		private Hoverable hoverable;

		private Interactable interactable;

		private Collider hitCollider;

		private readonly WorldClickState clicks = new WorldClickState();

		private readonly UiPointerHitTest ui = new UiPointerHitTest();

		private static readonly FieldRef<InventoryGui, Animator> InventoryAnimator = AccessTools.FieldRefAccess<InventoryGui, Animator>("m_animator");

		private static readonly FieldRef<InventoryGui, int> InventoryHiddenFrames = AccessTools.FieldRefAccess<InventoryGui, int>("m_hiddenFrames");

		private GameObject pendingTarget;

		private Collider pendingCollider;

		private bool pendingAlternate;

		private bool invokingNative;

		private Player seatingPlayer;

		private float seatingTransitionUntil;

		private Canvas canvas;

		private TextMeshProUGUI tooltip;

		private TMP_Text template;

		private string measuredText;

		private float measuredWidth;

		private float measuredHeight;

		internal TextMeshProUGUI DisplayedLabel => (Object.op_Implicit((Object)(object)tooltip) && ((Behaviour)tooltip).isActiveAndEnabled) ? tooltip : null;

		internal GameObject DisplayedTarget { get; private set; }

		internal static bool InventoryPanelVisible()
		{
			return Object.op_Implicit((Object)(object)InventoryGui.instance) && InventoryHiddenFrames.Invoke(InventoryGui.instance) <= 1;
		}

		internal void Update(Plugin plugin)
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: 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_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			if (!plugin.CameraController.Active || !plugin.Guard.IsWorldPointerAllowed() || ((Character)Player.m_localPlayer).InPlaceMode())
			{
				ClearVisuals();
				return;
			}
			Query(plugin, Player.m_localPlayer);
			if (!Object.op_Implicit((Object)(object)hovering) || hoverable == null || Hud.IsUserHidden())
			{
				ClearVisuals();
				return;
			}
			EnsureTooltip();
			if (Object.op_Implicit((Object)(object)tooltip))
			{
				PresentationTokens current = PresentationTokens.Current;
				((TMP_Text)tooltip).text = (CanReserveClick() ? CursorNativeActions.HoverText(hovering, hoverable) : hoverable.GetHoverText());
				((Graphic)tooltip).color = (InRange(Player.m_localPlayer) ? ((Graphic)template).color : current.hoverColor);
				RectTransform val = (RectTransform)((Component)canvas).transform;
				Vector2 pointerViewport = ScreenCoordinates.PointerViewport;
				Rect rect = val.rect;
				float num = ((Rect)(ref rect)).width - current.tooltipOffset * 2f;
				float tooltipWidth = current.tooltipWidth;
				rect = template.rectTransform.rect;
				float num2 = Mathf.Min(num, Mathf.Max(tooltipWidth, ((Rect)(ref rect)).width));
				float num3 = Mathf.Max(0.001f, ((Transform)((TMP_Text)tooltip).rectTransform).localScale.x);
				float num4 = Mathf.Max(0.001f, ((Transform)((TMP_Text)tooltip).rectTransform).localScale.y);
				float num5 = num2 / num3;
				bool flag = measuredText != ((TMP_Text)tooltip).text || measuredWidth != num5;
				bool flag2 = (Object)(object)DisplayedTarget != (Object)(object)hovering || !((Component)tooltip).gameObject.activeSelf;
				if (flag)
				{
					measuredText = ((TMP_Text)tooltip).text;
					measuredWidth = num5;
					measuredHeight = ((TMP_Text)tooltip).GetPreferredValues(((TMP_Text)tooltip).text, num5, float.PositiveInfinity).y;
				}
				float num6 = measuredHeight * num4;
				((TMP_Text)tooltip).rectTransform.sizeDelta = new Vector2(num5, measuredHeight);
				RectTransform rectTransform = ((TMP_Text)tooltip).rectTransform;
				Vector2 anchorMin = (((TMP_Text)tooltip).rectTransform.anchorMax = pointerViewport);
				rectTransform.anchorMin = anchorMin;
				rect = val.rect;
				float width = ((Rect)(ref rect)).width;
				rect = val.rect;
				float height = ((Rect)(ref rect)).height;
				((TMP_Text)tooltip).rectTransform.anchoredPosition = new Vector2(Mathf.Clamp(current.tooltipOffset, (0f - width) * pointerViewport.x + current.tooltipOffset, width * (1f - pointerViewport.x) - num2 - current.tooltipOffset), Mathf.Clamp(0f - current.tooltipOffset, num6 - height * pointerViewport.y + current.tooltipOffset, height * (1f - pointerViewport.y) - current.tooltipOffset));
				((Component)tooltip).gameObject.SetActive(true);
				DisplayedTarget = hovering;
				if (flag2 || flag)
				{
					ChestFilterTooltip.Refresh((TMP_Text)(object)tooltip);
				}
				bool flag3 = VisualRules.Bush(((Object)hovering).name, Object.op_Implicit((Object)(object)hovering.GetComponentInParent<TreeBase>()), Object.op_Implicit((Object)(object)hovering.GetComponentInParent<Character>()));
				plugin.CameraController.SetHoveredBush((flag3 && InRange(Player.m_localPlayer)) ? hovering.transform : null);
			}
		}

		internal void Tick(Plugin plugin)
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e5: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!plugin.CameraController.Active || !plugin.Guard.IsWorldPointerContext())
			{
				clicks.Reset();
				pendingTarget = null;
				pendingCollider = null;
				return;
			}
			bool reopened = clicks.Pending && Object.op_Implicit((Object)(object)InventoryGui.instance) && InventoryAnimator.Invoke(InventoryGui.instance).GetBool("visible");
			if (clicks.Complete(Time.unscaledTime, !plugin.Guard.IsModalUiOpen(), !plugin.Guard.IsWorldPointerAllowed(), reopened) && Object.op_Implicit((Object)(object)pendingTarget) && Object.op_Implicit((Object)(object)pendingCollider))
			{
				Vector3 val = pendingCollider.ClosestPoint(((Character)localPlayer).GetCenterPoint()) - ((Character)localPlayer).GetCenterPoint();
				if (ScreenSpaceMath.InReach(((Vector3)(ref val)).sqrMagnitude) && plugin.Guard.IsWorldPointerAllowed())
				{
					InvokeNative(localPlayer, pendingTarget, pendingAlternate);
				}
			}
			if (!clicks.Pending)
			{
				pendingTarget = null;
				pendingCollider = null;
			}
			ConsumeClick(plugin, localPlayer);
		}

		internal bool ConsumeClick(Plugin plugin, Player player)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (!clicks.Begin(ZInput.GetMouseButton(0), ZInput.GetMouseButtonDown(0), Time.frameCount))
			{
				return clicks.Consumed;
			}
			if (plugin.Guard.IsInventoryWorldClickAllowed())
			{
				if (ui.OverInterface(Vector2.op_Implicit(ZInput.pointerPosition)))
				{
					return clicks.Consumed;
				}
				clicks.Consume();
				Query(plugin, player);
				pendingTarget = ((Object.op_Implicit((Object)(object)hovering) && CanReserveClick() && InRange(player)) ? hovering : null);
				pendingCollider = (Object.op_Implicit((Object)(object)pendingTarget) ? hitCollider : null);
				pendingAlternate = CursorNativeActions.Alternate && (!Object.op_Implicit((Object)(object)pendingTarget) || !Object.op_Implicit((Object)(object)pendingTarget.GetComponentInParent<Smelter>()));
				InventoryGui.instance.Hide();
				if (Object.op_Implicit((Object)(object)pendingTarget))
				{
					clicks.Defer(Time.unscaledTime);
				}
				return true;
			}
			if (!plugin.Guard.IsWorldPointerAllowed() || ((Character)player).InPlaceMode())
			{
				return clicks.Consumed;
			}
			ItemDrop val = plugin.CombatHud.ItemAtLabel();
			if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled && !val.IsPiece() && !plugin.CameraController.IsHiddenContent(((Component)val).gameObject))
			{
				clicks.Consume();
				if (GroundItemLabels.InReach(val, player))
				{
					InvokeNative(player, ((Component)val).gameObject, alternate: false);
				}
				return true;
			}
			Query(plugin, player);
			if (Object.op_Implicit((Object)(object)hovering) && CanReserveClick())
			{
				clicks.Consume();
				if (InRange(player))
				{
					InvokeNative(player, hovering, CursorNativeActions.Alternate && !Object.op_Implicit((Object)(object)hovering.GetComponentInParent<Smelter>()));
				}
			}
			return clicks.Consumed;
		}

		private bool CanReserveClick()
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Invalid comparison between Unknown and I4
			if (hoverable == null || !Object.op_Implicit((Object)(object)hovering))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)hovering.GetComponentInParent<ArcheryTarget>()))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)hovering.GetComponentInParent<TreeBase>()) || Object.op_Implicit((Object)(object)hovering.GetComponentInParent<TreeLog>()))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)hovering.GetComponentInParent<MineRock>()) || Object.op_Implicit((Object)(object)hovering.GetComponentInParent<MineRock5>()))
			{
				return false;
			}
			Pickable componentInParent = hovering.GetComponentInParent<Pickable>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				return interactable != null && componentInParent.CanBePicked();
			}
			Piece componentInParent2 = hovering.GetComponentInParent<Piece>();
			string prefab = (Object.op_Implicit((Object)(object)componentInParent2) ? ((Object)((Component)componentInParent2).gameObject).name : ((Object)hovering).name);
			if (!Object.op_Implicit((Object)(object)componentInParent2) && VisualRules.Natural(prefab, tree: false))
			{
				return false;
			}
			bool flag = Object.op_Implicit((Object)(object)componentInParent2) && ((int)componentInParent2.m_category == 4 || componentInParent2.m_comfort > 0 || Object.op_Implicit((Object)(object)hovering.GetComponentInParent<Chair>()) || Object.op_Implicit((Object)(object)hovering.GetComponentInParent<Bed>()));
			return interactable != null || flag;
		}

		private void InvokeNative(Player player, GameObject target, bool alternate)
		{
			Pickable val = (Object.op_Implicit((Object)(object)target) ? target.GetComponentInParent<Pickable>() : null);
			if (Object.op_Implicit((Object)(object)val) && !val.CanBePicked())
			{
				return;
			}
			bool flag = Object.op_Implicit((Object)(object)target) && (Object.op_Implicit((Object)(object)target.GetComponentInParent<Chair>()) || Object.op_Implicit((Object)(object)target.GetComponentInParent<Bed>()));
			invokingNative = true;
			try
			{
				NativeInteract.Invoke(player, new object[3] { target, false, alternate });
				if (flag || ((Character)player).IsAttached() || ((Character)player).IsSitting())
				{
					seatingPlayer = player;
					seatingTransitionUntil = Time.unscaledTime + 0.75f;
				}
			}
			finally
			{
				invokingNative = false;
			}
		}

		internal bool BlockSeatingAttack(Player player)
		{
			if (!Object.op_Implicit((Object)(object)seatingPlayer) || (Object)(object)seatingPlayer != (Object)(object)player)
			{
				return false;
			}
			bool flag = Time.unscaledTime < seatingTransitionUntil;
			if (!flag && !((Character)player).IsAttached() && !((Character)player).IsSitting())
			{
				seatingPlayer = null;
				return false;
			}
			return flag || ((Character)player).IsAttached() || ((Character)player).IsSitting();
		}

		internal bool SeatingTransitionPending(Player player)
		{
			return (Object)(object)seatingPlayer == (Object)(object)player && Time.unscaledTime < seatingTransitionUntil;
		}

		internal bool AllowNativeInteraction(Plugin plugin, Player player)
		{
			if (invokingNative)
			{
				return true;
			}
			if (!plugin.Guard.IsWorldPointerContext())
			{
				return true;
			}
			ConsumeClick(plugin, player);
			return !clicks.Consumed;
		}

		private bool InRange(Player player)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			int result;
			if (Object.op_Implicit((Object)(object)hovering) && Object.op_Implicit((Object)(object)hitCollider) && hoverable != null)
			{
				Vector3 val = hitCollider.ClosestPoint(((Character)player).GetCenterPoint()) - ((Character)player).GetCenterPoint();
				result = (ScreenSpaceMath.InReach(((Vector3)(ref val)).sqrMagnitude) ? 1 : 0);
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}

		private void Query(Plugin plugin, Player player)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			hovering = null;
			hoverable = null;
			interactable = null;
			Ray val = ScreenCoordinates.PointerRay(plugin.CameraController.Camera);
			((Ray)(ref val)).origin = CameraRelativeMovement.ToUnity(InteractionMath.NearRayOrigin(CameraRelativeMovement.ToNumerics(((Ray)(ref val)).origin), CameraRelativeMovement.ToNumerics(((Ray)(ref val)).direction), CameraRelativeMovement.ToNumerics(((Character)player).m_eye.position)));
			int num = Physics.RaycastNonAlloc(val, hits, 1000f, Mask.Invoke(player), (QueryTriggerInteraction)2);
			RaycastHit[] array = hits;
			if (num == hits.Length)
			{
				array = Physics.RaycastAll(val, 1000f, Mask.Invoke(player), (QueryTriggerInteraction)2);
				num = array.Length;
			}
			float num2 = float.PositiveInfinity;
			int num3 = int.MaxValue;
			GameObject val2 = NativeCursorRays.Ghost.Invoke(player);
			for (int i = 0; i < num; i++)
			{
				RaycastHit hit = array[i];
				if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).collider) || (Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<Character>() == (Object)(object)player || (Object.op_Implicit((Object)(object)val2) && ((Component)((RaycastHit)(ref hit)).collider).transform.IsChildOf(val2.transform)) || plugin.CameraController.IsHiddenContent(((Component)((RaycastHit)(ref hit)).collider).gameObject))
				{
					continue;
				}
				Hoverable val3 = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<Hoverable>();
				Interactable val4 = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<Interactable>();
				Switch val5 = CursorNativeActions.Port(((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<Smelter>(), CursorNativeActions.Alternate);
				if (Object.op_Implicit((Ob