Decompiled source of Lucky Scratchers v1.0.1

Mods/WoodStudios.LuckyScratchers.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using HarmonyLib;
using HoldTheFort;
using Il2CppFishNet;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.AvatarFramework.Animation;
using Il2CppScheduleOne.Building;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.Instancing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Relation;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.Tiles;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Shop;
using Il2CppScheduleOne.Weather;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Il2CppTMPro;
using LuckyScratchers;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Items;
using S1API.Items.Storable;
using S1API.Lifecycle;
using S1API.Money;
using S1API.Rendering;
using S1API.Shops;
using Schedule2;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;
using WS_LS.FybCommon;
using WS_LS.WoodKit;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ScratchCore), "Lucky Scratchers", "1.0.0", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })]
[assembly: AssemblyTitle("WoodStudios.LuckyScratchers")]
[assembly: AssemblyProduct("WoodStudios.LuckyScratchers")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Schedule2
{
	internal static class Res
	{
		private static readonly Assembly Asm = typeof(Res).Assembly;

		public static Stream Open(string name)
		{
			Stream manifestResourceStream = Asm.GetManifestResourceStream(name);
			if (manifestResourceStream == null)
			{
				return null;
			}
			int num = manifestResourceStream.ReadByte();
			int num2 = manifestResourceStream.ReadByte();
			manifestResourceStream.Position = 0L;
			if (num != 31 || num2 != 139)
			{
				return manifestResourceStream;
			}
			MemoryStream memoryStream = new MemoryStream();
			using (GZipStream gZipStream = new GZipStream(manifestResourceStream, CompressionMode.Decompress))
			{
				gZipStream.CopyTo(memoryStream);
			}
			memoryStream.Position = 0L;
			return memoryStream;
		}
	}
}
namespace Schedule2.Game
{
	internal static class Sfx
	{
		public static AudioClip Create(string name, int lengthSamples, int channels, int frequency, bool stream)
		{
			return AudioClip.Create(name, lengthSamples, channels, frequency, stream);
		}

		public static bool SetData(AudioClip clip, Il2CppStructArray<float> data, int offset)
		{
			if ((Object)(object)clip != (Object)null)
			{
				return clip.SetData(data, offset);
			}
			return false;
		}
	}
}
namespace LuckyScratchers
{
	public static class Dev
	{
		public static string State()
		{
			return $"tickets {Scratch.Tickets}, winners {Scratch.Winners}, paid ${Scratch.PaidOut}, open {Scratch.Open}";
		}

		public static string Shops()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (ShopInterface item in Object.FindObjectsOfType<ShopInterface>(true))
			{
				stringBuilder.Append(item.ShopName).Append(" | ");
			}
			return stringBuilder.ToString();
		}

		public static string Odds(int n)
		{
			return Scratch.Simulate(n);
		}
	}
	internal static class Scratch
	{
		private sealed class Spot
		{
			public int Amount;

			public Texture2D Coat;

			public int Left;

			public int Total;

			public bool Clear;

			public bool Dirty;
		}

		private static readonly (int amount, float chance)[] Prizes = new(int, float)[7]
		{
			(10000, 5E-05f),
			(1000, 0.0004f),
			(500, 0.00125f),
			(100, 0.01f),
			(50, 0.025f),
			(20, 0.0625f),
			(10, 0.125f)
		};

		private static readonly int[] Faces = new int[8] { 5, 10, 20, 50, 100, 500, 1000, 10000 };

		public static bool Open;

		private static Spot[] _spots;

		private static int _win;

		private static bool _paid;

		private static float _openedAt;

		private static int _heldFrame = -10;

		private static GameObject _view;

		private static Vector2 _lastMouse;

		private static bool _lastHeld;

		private static int _rubFrame = -1;

		private static Camera _cam;

		private static Texture2D _white;

		private static readonly Random Rng = new Random();

		private static float _applyAt;

		public static int Tickets;

		public static int Winners;

		public static int PaidOut;

		private const int CoatW = 96;

		private const int CoatH = 64;

		private static List<int> _amounts;

		public static GameObject Model()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ls_Ticket");
			((Object)GltfLoader.LoadEmbedded("LS_Ticket.glb", val.transform)).name = "Model";
			foreach (Renderer componentsInChild in val.GetComponentsInChildren<Renderer>(true))
			{
				foreach (Material item in (Il2CppArrayBase<Material>)(object)componentsInChild.sharedMaterials)
				{
					if ((Object)(object)item != (Object)null)
					{
						Color color = item.color;
						Color val2 = (item.color = ((Color)(ref color)).gamma);
						if (item.HasProperty("_BaseColor"))
						{
							item.SetColor("_BaseColor", val2);
						}
					}
				}
			}
			val.AddComponent<BoxCollider>().size = new Vector3(0.1f, 0.01f, 0.15f);
			return val;
		}

		public static bool Held(ItemSpec s, Camera cam, Player pl, out string hint)
		{
			_heldFrame = Time.frameCount;
			_cam = cam;
			hint = (Open ? null : "[Click] Scratch this Lucky Scratcher");
			return true;
		}

		public static void Update()
		{
			if (_heldFrame >= Time.frameCount - 1 && (Object)(object)_cam != (Object)null && !Open)
			{
				ShowView();
				bool flag = false;
				try
				{
					flag = GameInput.GetButtonDown((ButtonCode)0);
				}
				catch
				{
				}
				if (flag)
				{
					Start();
				}
			}
			else if ((Object)(object)_view != (Object)null && _view.activeSelf)
			{
				_view.SetActive(false);
			}
			if (Open && Time.unscaledTime > _openedAt + 0.3f && Keys.RawDown((KeyCode)27))
			{
				Finish();
			}
		}

		private static void ShowView()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_view == (Object)null || (Object)(object)_view.transform.parent != (Object)(object)((Component)_cam).transform)
			{
				if ((Object)(object)_view != (Object)null)
				{
					Object.Destroy((Object)(object)_view);
				}
				GameObject val = Catalog.Get("ls_ticket")?.Template;
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				_view = Object.Instantiate<GameObject>(val);
				foreach (Collider componentsInChild in _view.GetComponentsInChildren<Collider>(true))
				{
					Object.Destroy((Object)(object)componentsInChild);
				}
				((Object)_view).name = "LS_TicketView";
				_view.transform.SetParent(((Component)_cam).transform, false);
				_view.transform.localPosition = new Vector3(0.15f, -0.13f, 0.4f);
				_view.transform.localRotation = Quaternion.Euler(-60f, -12f, 0f);
				_view.transform.localScale = Vector3.one * 0.8f;
				foreach (Renderer componentsInChild2 in _view.GetComponentsInChildren<Renderer>(true))
				{
					componentsInChild2.shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			if (!_view.activeSelf)
			{
				_view.SetActive(true);
			}
		}

		private static void Start()
		{
			try
			{
				PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
				HotbarSlot val = ((instance != null) ? instance.equippedSlot : null);
				if (val == null || ((ItemSlot)val).ItemInstance == null || ((BaseItemInstance)((ItemSlot)val).ItemInstance).ID != "ls_ticket")
				{
					return;
				}
				((ItemSlot)val).ChangeQuantity(-1, false);
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lucky Scratchers: couldn't take the ticket (" + ex.Message + ").");
				}
				return;
			}
			Deal();
			MakeSpots();
			Tickets++;
			Open = true;
			_paid = false;
			_openedAt = Time.unscaledTime;
			if ((Object)(object)_view != (Object)null)
			{
				_view.SetActive(false);
			}
			FortifyApi.OpenMenu("ls_scratch");
		}

		private static void Deal()
		{
			_win = 0;
			double num = Rng.NextDouble();
			double num2 = 0.0;
			(int, float)[] prizes = Prizes;
			for (int i = 0; i < prizes.Length; i++)
			{
				(int, float) tuple = prizes[i];
				num2 += (double)tuple.Item2;
				if (num < num2)
				{
					(_win, _) = tuple;
					break;
				}
			}
			List<int> list = new List<int>();
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			if (_win > 0)
			{
				list.Add(_win);
				list.Add(_win);
				list.Add(_win);
				dictionary[_win] = 3;
			}
			while (list.Count < 6)
			{
				int num3 = Faces[Rng.Next(Faces.Length)];
				if (num3 < 1000 || !(Rng.NextDouble() < 0.6))
				{
					dictionary.TryGetValue(num3, out var value);
					if ((value < 2 || num3 == _win) && (num3 != _win || value < 3))
					{
						dictionary[num3] = value + 1;
						list.Add(num3);
					}
				}
			}
			for (int num4 = list.Count - 1; num4 > 0; num4--)
			{
				int num5 = Rng.Next(num4 + 1);
				List<int> list2 = list;
				int i = num4;
				List<int> list3 = list;
				int index = num5;
				int value2 = list[num5];
				int value3 = list[num4];
				list2[i] = value2;
				list3[index] = value3;
			}
			_amounts = list;
		}

		private static void MakeSpots()
		{
			if (_spots != null)
			{
				Spot[] spots = _spots;
				foreach (Spot spot in spots)
				{
					if ((Object)(object)spot.Coat != (Object)null)
					{
						Object.Destroy((Object)(object)spot.Coat);
					}
				}
			}
			_spots = new Spot[6];
			for (int j = 0; j < 6; j++)
			{
				_spots[j] = new Spot
				{
					Amount = _amounts[j],
					Coat = Coat(j),
					Total = 6144,
					Left = 6144
				};
			}
		}

		private static Texture2D Coat(int seed)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(96, 64, (TextureFormat)4, false);
			Random random = new Random(seed * 7919 + Environment.TickCount);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num = Mathf.PerlinNoise((float)j * 0.15f + (float)seed, (float)i * 0.15f) * 0.12f + (float)random.NextDouble() * 0.06f;
					float num2 = 0.68f + num;
					float num3 = ((Mathf.Repeat((float)(j + i) * 0.05f, 1f) < 0.5f) ? 0.03f : 0f);
					val.SetPixel(j, i, new Color(num2 + num3, num2 + 0.01f + num3, num2 + 0.03f + num3, 1f));
				}
			}
			val.Apply();
			((Texture)val).filterMode = (FilterMode)1;
			return val;
		}

		public static string Simulate(int n)
		{
			int num = 0;
			long num2 = 0L;
			for (int i = 0; i < n; i++)
			{
				Deal();
				if (_win > 0)
				{
					num++;
					num2 += _win;
				}
				int num3 = 0;
				Dictionary<int, int> dictionary = new Dictionary<int, int>();
				foreach (int amount in _amounts)
				{
					dictionary.TryGetValue(amount, out var value);
					dictionary[amount] = value + 1;
					if (value + 1 >= 3)
					{
						num3 = amount;
					}
				}
				if (num3 != _win)
				{
					return "layout mismatch: win " + _win + " shows " + num3;
				}
			}
			Open = false;
			return $"{n} tickets: {num} winners (1 in {((num > 0) ? ((float)n / (float)num) : 0f):0.00}), paid ${num2} of ${n * 10} ({(double)num2 * 100.0 / (double)(n * 10):0}%)";
		}

		public static void Close()
		{
			if (Open)
			{
				Finish();
			}
		}

		private static void Finish()
		{
			if (_spots != null)
			{
				Spot[] spots = _spots;
				for (int i = 0; i < spots.Length; i++)
				{
					spots[i].Clear = true;
				}
			}
			Pay();
			Open = false;
			FortifyApi.CloseMenu("ls_scratch");
		}

		private static void Pay()
		{
			if (_paid)
			{
				return;
			}
			_paid = true;
			if (_win <= 0)
			{
				return;
			}
			Winners++;
			PaidOut += _win;
			try
			{
				Money.ChangeCashBalance((float)_win, true, true);
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lucky Scratchers: couldn't pay out (" + ex.Message + ").");
				}
			}
			if (_win >= 1000)
			{
				FortifyApi.Notify("Lucky Scratchers", (_win >= 10000) ? "JACKPOT! $10,000 in cash!" : ("Big winner: $" + _win.ToString("N0") + "!"));
			}
		}

		private static Vector2 MousePos()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			try
			{
				val = Input.mousePosition;
			}
			catch
			{
				try
				{
					val = Vector2.op_Implicit(((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue());
				}
				catch
				{
				}
			}
			return new Vector2(val.x, (float)Screen.height - val.y);
		}

		private static bool MouseHeld()
		{
			try
			{
				return Input.GetMouseButton(0);
			}
			catch
			{
				try
				{
					return Mouse.current != null && Mouse.current.leftButton.isPressed;
				}
				catch
				{
					return false;
				}
			}
		}

		private static Texture2D White()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_white == (Object)null)
			{
				_white = new Texture2D(1, 1);
				_white.SetPixel(0, 0, Color.white);
				_white.Apply();
			}
			return _white;
		}

		private static void Box(Rect r, Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			WS_LS.WoodKit.Ui.Fill(r, c);
		}

		public static void Draw()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_068b: Unknown result type (might be due to invalid IL or missing references)
			if (!Open || _spots == null)
			{
				return;
			}
			float num = Mathf.Clamp((float)Screen.height / 1080f, 0.7f, 2f);
			float num2 = 460f * num;
			float num3 = 700f * num;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((float)Screen.width - num2) * 0.5f, ((float)Screen.height - num3) * 0.5f, num2, num3);
			Box(new Rect(((Rect)(ref r)).x - 6f * num, ((Rect)(ref r)).y - 6f * num, ((Rect)(ref r)).width + 12f * num, ((Rect)(ref r)).height + 12f * num), new Color(0.95f, 0.72f, 0.15f));
			Box(r, new Color(0.36f, 0.06f, 0.5f));
			Box(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 18f * num, ((Rect)(ref r)).width, 120f * num), new Color(0.27f, 0.03f, 0.4f));
			WS_LS.FybCommon.Ui.Text(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 22f * num, ((Rect)(ref r)).width, 70f * num), "LUCKY SCRATCHERS", Mathf.RoundToInt(42f * num), new Color(1f, 0.82f, 0.25f), (TextAnchor)4);
			WS_LS.FybCommon.Ui.Text(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 88f * num, ((Rect)(ref r)).width, 40f * num), "Match 3 amounts, win that amount!", Mathf.RoundToInt(20f * num), Color.white, (TextAnchor)4);
			Vector2 val = MousePos();
			bool flag = MouseHeld();
			float num4 = 180f * num;
			float num5 = 120f * num;
			float num6 = 30f * num;
			float num7 = 22f * num;
			float num8 = ((Rect)(ref r)).x + (((Rect)(ref r)).width - 2f * num4 - num6) * 0.5f;
			float num9 = ((Rect)(ref r)).y + 160f * num;
			int num10 = 0;
			Rect r2 = default(Rect);
			for (int i = 0; i < 6; i++)
			{
				Spot spot = _spots[i];
				((Rect)(ref r2))..ctor(num8 + (float)(i % 2) * (num4 + num6), num9 + (float)(i / 2) * (num5 + num7), num4, num5);
				Box(r2, new Color(0.97f, 0.95f, 0.88f));
				WS_LS.FybCommon.Ui.Text(r2, "$" + spot.Amount.ToString("N0"), Mathf.RoundToInt((float)((spot.Amount >= 10000) ? 34 : 40) * num), new Color(0.3f, 0.05f, 0.45f), (TextAnchor)4);
				if (!spot.Clear)
				{
					if (flag && Time.frameCount != _rubFrame)
					{
						Vector2 val2 = (_lastHeld ? _lastMouse : val);
						int num11 = Mathf.Clamp(Mathf.CeilToInt(Vector2.Distance(val2, val) / (5f * num)), 1, 200);
						for (int j = 0; j <= num11; j++)
						{
							Vector2 val3 = Vector2.Lerp(val2, val, (float)j / (float)num11);
							if (((Rect)(ref r2)).Contains(val3))
							{
								ScratchAt(spot, (val3.x - ((Rect)(ref r2)).x) / ((Rect)(ref r2)).width, (val3.y - ((Rect)(ref r2)).y) / ((Rect)(ref r2)).height);
							}
						}
					}
					if (spot.Dirty && Time.unscaledTime >= _applyAt)
					{
						spot.Coat.Apply();
						spot.Dirty = false;
					}
					if ((float)spot.Left < (float)spot.Total * 0.42f)
					{
						spot.Clear = true;
					}
					else
					{
						WS_LS.WoodKit.Ui.Image(r2, spot.Coat);
					}
				}
				if (spot.Clear)
				{
					num10++;
					if (_paid && _win > 0 && spot.Amount == _win)
					{
						Box(new Rect(((Rect)(ref r2)).x, ((Rect)(ref r2)).y, ((Rect)(ref r2)).width, 5f * num), new Color(0.1f, 0.75f, 0.2f));
						Box(new Rect(((Rect)(ref r2)).x, ((Rect)(ref r2)).yMax - 5f * num, ((Rect)(ref r2)).width, 5f * num), new Color(0.1f, 0.75f, 0.2f));
					}
				}
			}
			if (Time.unscaledTime >= _applyAt)
			{
				_applyAt = Time.unscaledTime + 0.03f;
			}
			if (num10 == 6)
			{
				Pay();
			}
			if (Time.frameCount != _rubFrame)
			{
				_rubFrame = Time.frameCount;
				_lastMouse = val;
				_lastHeld = flag;
			}
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 120f * num, ((Rect)(ref r)).width, 50f * num);
			if (num10 < 6)
			{
				WS_LS.FybCommon.Ui.Text(r3, "Hold the mouse button and rub the silver spots", Mathf.RoundToInt(18f * num), new Color(1f, 1f, 1f, 0.85f), (TextAnchor)4);
				if (WS_LS.FybCommon.Ui.Button(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.5f - 110f * num, ((Rect)(ref r)).yMax - 64f * num, 220f * num, 44f * num), "Scratch it all", enabled: true, selected: false, Mathf.RoundToInt(18f * num)))
				{
					Spot[] spots = _spots;
					for (int k = 0; k < spots.Length; k++)
					{
						spots[k].Clear = true;
					}
				}
			}
			else
			{
				string s = ((_win <= 0) ? "Not a winner. Better luck next time!" : ((_win >= 10000) ? "JACKPOT! YOU WIN $10,000!" : ("WINNER! YOU WIN $" + _win.ToString("N0") + "!")));
				WS_LS.FybCommon.Ui.Text(r3, s, Mathf.RoundToInt((float)((_win > 0) ? 26 : 20) * num), (Color)((_win > 0) ? new Color(0.45f, 1f, 0.45f) : Color.white), (TextAnchor)4);
				if (WS_LS.FybCommon.Ui.Button(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.5f - 90f * num, ((Rect)(ref r)).yMax - 64f * num, 180f * num, 44f * num), "Done", enabled: true, selected: false, Mathf.RoundToInt(18f * num)))
				{
					Finish();
				}
			}
		}

		private static void ScratchAt(Spot sp, float u, float v)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.RoundToInt(u * 96f);
			int num2 = Mathf.RoundToInt((1f - v) * 64f);
			for (int i = num2 - 9; i <= num2 + 9; i++)
			{
				if (i < 0 || i >= 64)
				{
					continue;
				}
				for (int j = num - 9; j <= num + 9; j++)
				{
					if (j >= 0 && j < 96 && (j - num) * (j - num) + (i - num2) * (i - num2) <= 81)
					{
						Color pixel = sp.Coat.GetPixel(j, i);
						if (pixel.a > 0f && !(Rng.NextDouble() < 0.18))
						{
							sp.Coat.SetPixel(j, i, new Color(pixel.r, pixel.g, pixel.b, 0f));
							sp.Left--;
							sp.Dirty = true;
						}
					}
				}
			}
		}
	}
	public sealed class ScratchCore : MelonMod
	{
		internal const string TicketId = "ls_ticket";

		private static MelonPreferences_Entry<float> _price;

		private static float _warnedAt = -100f;

		internal static readonly string[] GasMarts = new string[2] { "Gas-Mart (Central)", "Gas-Mart (West)" };

		public override void OnInitializeMelon()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Host.Init((MelonMod)(object)this, "LuckyScratchers", "Lucky Scratchers", "ls_", null, null, Scratch.Close);
				_price = (MelonPreferences.GetCategory("LuckyScratchers") ?? MelonPreferences.CreateCategory("LuckyScratchers", "Lucky Scratchers")).CreateEntry<float>("PriceMultiplier", 1f, "Price multiplier", "Multiplies the ticket price (1 = $10). Applies after a game restart.", false, false, (ValueValidator)null, (string)null);
				Kit.PriceMultiplier = () => _price?.Value ?? 1f;
				Kit.Stores = GasMarts;
				FortifyApi.SetNotifyIcon("ls_ticket");
				Catalog.Add(new ItemSpec
				{
					Id = "ls_ticket",
					Name = "Lucky Scratcher",
					Kind = PlaceKind.Ground,
					Price = 10f,
					RotateStep = 0f,
					StackLimit = 20,
					Stores = GasMarts,
					IconColor = new Color(0.45f, 0.1f, 0.6f),
					BuildModel = Scratch.Model,
					IconModel = delegate
					{
						//IL_0005: Unknown result type (might be due to invalid IL or missing references)
						//IL_000b: Expected O, but got Unknown
						//IL_0036: Unknown result type (might be due to invalid IL or missing references)
						GameObject val = new GameObject("ls_TicketIcon");
						GameObject obj = Scratch.Model();
						obj.transform.SetParent(val.transform, false);
						obj.transform.localRotation = Quaternion.Euler(-80f, 0f, -12f);
						return val;
					},
					Description = "A $10 scratch-off. Hold it and click to scratch: match 3 amounts and win that amount, up to a $10,000 jackpot. About 1 in 4 tickets wins something."
				});
				Kit.CustomPlace["ls_ticket"] = Scratch.Held;
				Host.WhereToBuyNote = "Lucky Scratchers are at the Gas-Marts: $10 a ticket, jackpot $10,000.";
				Host.Ok = true;
				((MelonBase)this).LoggerInstance.Msg("Lucky Scratchers loaded. Tickets are at the Gas-Marts.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Lucky Scratchers couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer.");
			}
		}

		public override void OnUpdate()
		{
			if (!Host.Update())
			{
				return;
			}
			try
			{
				Scratch.Update();
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime - _warnedAt > 30f)
				{
					_warnedAt = Time.unscaledTime;
					((MelonBase)this).LoggerInstance.Warning("Lucky Scratchers: " + ex.Message);
				}
			}
		}

		public override void OnGUI()
		{
			if (!Host.Ok || !FortifyApi.InGame)
			{
				return;
			}
			try
			{
				Scratch.Draw();
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime - _warnedAt > 30f)
				{
					_warnedAt = Time.unscaledTime;
					((MelonBase)this).LoggerInstance.Warning("Lucky Scratchers (drawing): " + ex.Message);
				}
			}
			if (!Scratch.Open)
			{
				Host.DrawHint();
			}
		}
	}
}
namespace WS_LS.WoodKit
{
	internal static class Catalog
	{
		public static readonly List<ItemSpec> Items = new List<ItemSpec>();

		private static readonly Dictionary<string, ItemSpec> ById = new Dictionary<string, ItemSpec>(StringComparer.OrdinalIgnoreCase);

		public static void Add(ItemSpec s)
		{
			Items.Add(s);
			ById[s.Id] = s;
		}

		public static ItemSpec Get(string id)
		{
			if (string.IsNullOrEmpty(id) || !ById.TryGetValue(id, out var value))
			{
				return null;
			}
			return value;
		}

		public static void BuildTemplates()
		{
			foreach (ItemSpec item in Items)
			{
				if ((Object)(object)item.Template != (Object)null || item.BuildModel == null)
				{
					continue;
				}
				try
				{
					item.Template = item.BuildModel();
					if ((Object)(object)item.Template != (Object)null && (Object)(object)item.Template.transform.parent == (Object)null)
					{
						item.Template.transform.SetParent(Models.Root, false);
					}
				}
				catch (Exception ex)
				{
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Error("Couldn't build the " + item.Name + " model: " + ex.Message);
					}
				}
			}
		}
	}
	internal static class CoopMirror
	{
		private sealed class Shown
		{
			public string Payload;

			public readonly List<GameObject> Gos = new List<GameObject>();
		}

		private const int Chunk = 3500;

		private const int MaxChunks = 24;

		private static readonly Dictionary<ulong, Shown> Views = new Dictionary<ulong, Shown>();

		private static string _published;

		private static int _publishedChunks;

		private static float _nextBuild;

		private static float _nextView;

		private static string Key => "wk_" + (Kit.Prefix ?? "x");

		private static bool InLobby(out CSteamID lobby, out int members)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			lobby = default(CSteamID);
			members = 0;
			try
			{
				Lobby instance = Singleton<Lobby>.Instance;
				if ((Object)(object)instance == (Object)null || !instance.IsInLobby || instance.LobbyID == 0L)
				{
					return false;
				}
				lobby = new CSteamID
				{
					m_SteamID = instance.LobbyID
				};
				members = SteamMatchmaking.GetNumLobbyMembers(lobby);
				return members > 1;
			}
			catch
			{
				return false;
			}
		}

		public static void Update()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!InLobby(out var lobby, out var members))
			{
				if (Views.Count > 0)
				{
					Clear();
				}
				_published = null;
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= _nextBuild)
			{
				_nextBuild = unscaledTime + 1.5f;
				string text = Build();
				if (text != _published)
				{
					Publish(lobby, text);
				}
			}
			if (unscaledTime >= _nextView)
			{
				_nextView = unscaledTime + 1f;
				Refresh(lobby, members);
			}
		}

		public static void Reset()
		{
			Clear();
			_published = null;
			_publishedChunks = 0;
			_nextBuild = (_nextView = 0f);
		}

		private static string Build()
		{
			//IL_0075: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Placement.Placed item in Placement.All)
			{
				try
				{
					if (item != null && !((Object)(object)item.Go == (Object)null) && item.Spec != null && !item.OnShip && !((Object)(object)item.Spec.Template == (Object)null) && item.Go.activeInHierarchy)
					{
						Transform transform = item.Go.transform;
						Vector3 position = transform.position;
						Quaternion rotation = transform.rotation;
						Vector3 lossyScale = transform.lossyScale;
						if (stringBuilder.Length > 0)
						{
							stringBuilder.Append('~');
						}
						stringBuilder.Append(item.Spec.Id).Append(';');
						Num(stringBuilder, position.x);
						stringBuilder.Append(',');
						Num(stringBuilder, position.y);
						stringBuilder.Append(',');
						Num(stringBuilder, position.z);
						stringBuilder.Append(';');
						Num(stringBuilder, rotation.x, 4);
						stringBuilder.Append(',');
						Num(stringBuilder, rotation.y, 4);
						stringBuilder.Append(',');
						Num(stringBuilder, rotation.z, 4);
						stringBuilder.Append(',');
						Num(stringBuilder, rotation.w, 4);
						stringBuilder.Append(';');
						Num(stringBuilder, lossyScale.x, 3);
						stringBuilder.Append(',');
						Num(stringBuilder, lossyScale.y, 3);
						stringBuilder.Append(',');
						Num(stringBuilder, lossyScale.z, 3);
					}
				}
				catch
				{
				}
			}
			return stringBuilder.ToString();
		}

		private static void Publish(CSteamID lobby, string payload)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = ((payload.Length != 0) ? Math.Min(24, (payload.Length + 3500 - 1) / 3500) : 0);
				for (int i = 0; i < num; i++)
				{
					SteamMatchmaking.SetLobbyMemberData(lobby, Key + "_" + i, payload.Substring(i * 3500, Math.Min(3500, payload.Length - i * 3500)));
				}
				for (int j = num; j < _publishedChunks; j++)
				{
					SteamMatchmaking.SetLobbyMemberData(lobby, Key + "_" + j, "");
				}
				SteamMatchmaking.SetLobbyMemberData(lobby, Key + "_n", num.ToString(CultureInfo.InvariantCulture) + "|" + payload.Length.ToString(CultureInfo.InvariantCulture));
				_publishedChunks = num;
				_published = payload;
			}
			catch
			{
			}
		}

		private static void Refresh(CSteamID lobby, int members)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			ulong num = 0uL;
			try
			{
				num = SteamUser.GetSteamID().m_SteamID;
			}
			catch
			{
			}
			HashSet<ulong> hashSet = new HashSet<ulong>();
			for (int i = 0; i < members; i++)
			{
				CSteamID lobbyMemberByIndex;
				try
				{
					lobbyMemberByIndex = SteamMatchmaking.GetLobbyMemberByIndex(lobby, i);
				}
				catch
				{
					continue;
				}
				if (lobbyMemberByIndex.m_SteamID == num || lobbyMemberByIndex.m_SteamID == 0L)
				{
					continue;
				}
				hashSet.Add(lobbyMemberByIndex.m_SteamID);
				string lobbyMemberData = SteamMatchmaking.GetLobbyMemberData(lobby, lobbyMemberByIndex, Key + "_n");
				if (string.IsNullOrEmpty(lobbyMemberData))
				{
					continue;
				}
				string[] array = lobbyMemberData.Split('|');
				if (array.Length < 2 || !int.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || !int.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) || result < 0 || result > 24)
				{
					continue;
				}
				StringBuilder stringBuilder = new StringBuilder();
				for (int j = 0; j < result; j++)
				{
					stringBuilder.Append(SteamMatchmaking.GetLobbyMemberData(lobby, lobbyMemberByIndex, Key + "_" + j) ?? "");
				}
				string text = stringBuilder.ToString();
				if (text.Length == result2 && (!Views.TryGetValue(lobbyMemberByIndex.m_SteamID, out var value) || !(value.Payload == text)))
				{
					if (value != null)
					{
						Destroy(value);
					}
					value = new Shown
					{
						Payload = text
					};
					Views[lobbyMemberByIndex.m_SteamID] = value;
					Spawn(value, text);
				}
			}
			List<ulong> list = new List<ulong>();
			foreach (KeyValuePair<ulong, Shown> view in Views)
			{
				if (!hashSet.Contains(view.Key))
				{
					list.Add(view.Key);
				}
			}
			foreach (ulong item in list)
			{
				Destroy(Views[item]);
				Views.Remove(item);
			}
		}

		private static void Spawn(Shown shown, string payload)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(payload))
			{
				return;
			}
			string[] array = payload.Split('~');
			foreach (string text in array)
			{
				try
				{
					string[] array2 = text.Split(';');
					if (array2.Length < 4)
					{
						continue;
					}
					ItemSpec itemSpec = Catalog.Get(array2[0]);
					if (itemSpec != null && !((Object)(object)itemSpec.Template == (Object)null))
					{
						GameObject val = Object.Instantiate<GameObject>(itemSpec.Template);
						((Object)val).name = Kit.Prefix + "Mirror_" + itemSpec.Id;
						val.transform.SetParent((Transform)null, false);
						val.transform.SetPositionAndRotation(Vec(array2[1]), Rot(array2[2]));
						Vector3 val2 = Vec(array2[3]);
						if (val2.x > 0.001f && val2.y > 0.001f && val2.z > 0.001f)
						{
							val.transform.localScale = val2;
						}
						val.SetActive(true);
						shown.Gos.Add(val);
					}
				}
				catch
				{
				}
			}
		}

		internal static bool IsMirror(GameObject go)
		{
			Transform val = (((Object)(object)go != (Object)null) ? go.transform : null);
			while ((Object)(object)val != (Object)null)
			{
				if ((((Object)val).name ?? "").Contains("Mirror_"))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private static void Num(StringBuilder sb, float v, int dp = 2)
		{
			sb.Append(Math.Round(v, dp).ToString(CultureInfo.InvariantCulture));
		}

		private static Vector3 Vec(string s)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			string[] a = s.Split(',');
			return new Vector3(P(a, 0), P(a, 1), P(a, 2));
		}

		private static Quaternion Rot(string s)
		{
			//IL_002d: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			string[] a = s.Split(',');
			Quaternion val = default(Quaternion);
			((Quaternion)(ref val))..ctor(P(a, 0), P(a, 1), P(a, 2), P(a, 3));
			float num = Mathf.Sqrt(val.x * val.x + val.y * val.y + val.z * val.z + val.w * val.w);
			if (!(num > 0.0001f))
			{
				return Quaternion.identity;
			}
			return new Quaternion(val.x / num, val.y / num, val.z / num, val.w / num);
		}

		private static float P(string[] a, int i)
		{
			if (i >= a.Length || !float.TryParse(a[i], NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				return 0f;
			}
			return result;
		}

		private static void Destroy(Shown s)
		{
			foreach (GameObject go in s.Gos)
			{
				try
				{
					if ((Object)(object)go != (Object)null)
					{
						Object.Destroy((Object)(object)go);
					}
				}
				catch
				{
				}
			}
			s.Gos.Clear();
		}

		private static void Clear()
		{
			foreach (KeyValuePair<ulong, Shown> view in Views)
			{
				Destroy(view.Value);
			}
			Views.Clear();
		}
	}
	internal static class Core
	{
		internal const string PickupLabel = "Hold Right Click";

		public static Instance Log => Kit.Log;

		public static KeyCode ViewKey => FortifyApi.UseKey;

		public static KeyCode RotateKey => Kit.RotateKey;
	}
	internal static class GltfLoader
	{
		public static GameObject LoadEmbedded(string fileName, Transform parent)
		{
			using Stream stream = Res.Open(Kit.ModelResourcePrefix + fileName);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded model missing: " + fileName);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return Load(memoryStream.ToArray(), Path.GetFileNameWithoutExtension(fileName), parent);
		}

		public static GameObject Load(byte[] glb, string name, Transform parent)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (glb.Length < 20 || BitConverter.ToUInt32(glb, 0) != 1179937895)
			{
				throw new InvalidDataException("Not a GLB file");
			}
			int num = (int)BitConverter.ToUInt32(glb, 12);
			string json = Encoding.UTF8.GetString(glb, 20, num);
			int bin = 20 + num + 8;
			using JsonDocument jsonDocument = JsonDocument.Parse(json);
			JsonElement rootElement = jsonDocument.RootElement;
			Material[] materials = BuildMaterials(rootElement);
			Dictionary<int, (Mesh, Material[])> meshCache = new Dictionary<int, (Mesh, Material[])>();
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			JsonElement property = rootElement.GetProperty("nodes");
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < property.GetArrayLength(); i++)
			{
				if (!property[i].TryGetProperty("children", out var value))
				{
					continue;
				}
				foreach (JsonElement item in value.EnumerateArray())
				{
					hashSet.Add(item.GetInt32());
				}
			}
			for (int j = 0; j < property.GetArrayLength(); j++)
			{
				if (!hashSet.Contains(j))
				{
					BuildNode(rootElement, property, j, val.transform, glb, bin, materials, meshCache);
				}
			}
			return val;
		}

		private static void BuildNode(JsonElement root, JsonElement nodes, int index, Transform parent, byte[] glb, int bin, Material[] materials, Dictionary<int, (Mesh, Material[])> meshCache)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			JsonElement jsonElement = nodes[index];
			JsonElement value;
			GameObject val = new GameObject(jsonElement.TryGetProperty("name", out value) ? value.GetString() : ("node" + index));
			Transform transform = val.transform;
			transform.SetParent(parent, false);
			if (jsonElement.TryGetProperty("translation", out var value2))
			{
				transform.localPosition = new Vector3(value2[0].GetSingle(), value2[1].GetSingle(), 0f - value2[2].GetSingle());
			}
			if (jsonElement.TryGetProperty("rotation", out var value3))
			{
				transform.localRotation = new Quaternion(0f - value3[0].GetSingle(), 0f - value3[1].GetSingle(), value3[2].GetSingle(), value3[3].GetSingle());
			}
			if (jsonElement.TryGetProperty("scale", out var value4))
			{
				transform.localScale = new Vector3(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle());
			}
			if (jsonElement.TryGetProperty("mesh", out var value5))
			{
				int @int = value5.GetInt32();
				if (!meshCache.TryGetValue(@int, out var value6))
				{
					(Mesh, Material[]) tuple = (meshCache[@int] = BuildMesh(root, @int, glb, bin, materials));
					value6 = tuple;
				}
				val.AddComponent<MeshFilter>().sharedMesh = value6.Item1;
				MeshRenderer val2 = val.AddComponent<MeshRenderer>();
				Il2CppReferenceArray<Material> val3 = new Il2CppReferenceArray<Material>((long)value6.Item2.Length);
				for (int i = 0; i < value6.Item2.Length; i++)
				{
					((Il2CppArrayBase<Material>)(object)val3)[i] = value6.Item2[i];
				}
				((Renderer)val2).sharedMaterials = val3;
			}
			if (!jsonElement.TryGetProperty("children", out var value7))
			{
				return;
			}
			foreach (JsonElement item in value7.EnumerateArray())
			{
				BuildNode(root, nodes, item.GetInt32(), transform, glb, bin, materials, meshCache);
			}
		}

		private static (Mesh, Material[]) BuildMesh(JsonElement root, int meshIndex, byte[] glb, int bin, Material[] materials)
		{
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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)
			JsonElement property = root.GetProperty("meshes")[meshIndex].GetProperty("primitives");
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int[]> list4 = new List<int[]>();
			List<Material> list5 = new List<Material>();
			foreach (JsonElement item in property.EnumerateArray())
			{
				JsonElement property2 = item.GetProperty("attributes");
				int count = list.Count;
				int count2;
				float[] array = ReadFloats(root, property2.GetProperty("POSITION").GetInt32(), glb, bin, out count2);
				for (int i = 0; i < count2; i++)
				{
					list.Add(new Vector3(array[i * 3], array[i * 3 + 1], 0f - array[i * 3 + 2]));
				}
				int count3;
				if (property2.TryGetProperty("NORMAL", out var value))
				{
					float[] array2 = ReadFloats(root, value.GetInt32(), glb, bin, out count3);
					for (int j = 0; j < count2; j++)
					{
						list2.Add(new Vector3(array2[j * 3], array2[j * 3 + 1], 0f - array2[j * 3 + 2]));
					}
				}
				else
				{
					for (int k = 0; k < count2; k++)
					{
						list2.Add(Vector3.up);
					}
				}
				if (property2.TryGetProperty("TEXCOORD_0", out var value2))
				{
					float[] array3 = ReadFloats(root, value2.GetInt32(), glb, bin, out count3);
					for (int l = 0; l < count2; l++)
					{
						list3.Add(new Vector2(array3[l * 2], 1f - array3[l * 2 + 1]));
					}
				}
				else
				{
					for (int m = 0; m < count2; m++)
					{
						list3.Add(Vector2.zero);
					}
				}
				int[] array4;
				if (item.TryGetProperty("indices", out var value3))
				{
					array4 = ReadIndices(root, value3.GetInt32(), glb, bin);
				}
				else
				{
					array4 = new int[count2];
					for (int n = 0; n < count2; n++)
					{
						array4[n] = n;
					}
				}
				for (int num = 0; num + 2 < array4.Length; num += 3)
				{
					int num2 = array4[num] + count;
					int num3 = array4[num + 1] + count;
					int num4 = array4[num + 2] + count;
					array4[num] = num2;
					array4[num + 1] = num4;
					array4[num + 2] = num3;
				}
				list4.Add(array4);
				JsonElement value4;
				int num5 = (item.TryGetProperty("material", out value4) ? value4.GetInt32() : (-1));
				list5.Add((num5 >= 0 && num5 < materials.Length) ? materials[num5] : Models.Mat("gltf_default", Color.gray));
			}
			Mesh val = new Mesh
			{
				name = "HTF_" + meshIndex
			};
			if (list.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = new Il2CppStructArray<Vector3>(list.ToArray());
			val.normals = new Il2CppStructArray<Vector3>(list2.ToArray());
			val.uv = new Il2CppStructArray<Vector2>(list3.ToArray());
			val.subMeshCount = list4.Count;
			for (int num6 = 0; num6 < list4.Count; num6++)
			{
				val.SetTriangles(new Il2CppStructArray<int>(list4[num6]), num6);
			}
			val.RecalculateBounds();
			((Object)val).hideFlags = (HideFlags)32;
			return (val, list5.ToArray());
		}

		private static Material[] BuildMaterials(JsonElement root)
		{
			//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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			if (!root.TryGetProperty("materials", out var value))
			{
				return Array.Empty<Material>();
			}
			Material[] array = (Material[])(object)new Material[value.GetArrayLength()];
			for (int i = 0; i < array.Length; i++)
			{
				JsonElement jsonElement = value[i];
				JsonElement value2;
				string text = (jsonElement.TryGetProperty("name", out value2) ? value2.GetString() : ("mat" + i));
				Color white = Color.white;
				float metallic = 1f;
				float num = 1f;
				if (jsonElement.TryGetProperty("pbrMetallicRoughness", out var value3))
				{
					if (value3.TryGetProperty("baseColorFactor", out var value4))
					{
						((Color)(ref white))..ctor(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle(), value4[3].GetSingle());
					}
					if (value3.TryGetProperty("metallicFactor", out var value5))
					{
						metallic = value5.GetSingle();
					}
					if (value3.TryGetProperty("roughnessFactor", out var value6))
					{
						num = value6.GetSingle();
					}
				}
				Color? emission = null;
				if (jsonElement.TryGetProperty("emissiveFactor", out var value7))
				{
					float num2 = 1f;
					if (jsonElement.TryGetProperty("extensions", out var value8) && value8.TryGetProperty("KHR_materials_emissive_strength", out var value9) && value9.TryGetProperty("emissiveStrength", out var value10))
					{
						num2 = value10.GetSingle();
					}
					Color value11 = new Color(value7[0].GetSingle(), value7[1].GetSingle(), value7[2].GetSingle()) * Mathf.Min(num2, 8f) * 0.5f;
					if (((Color)(ref value11)).maxColorComponent > 0.001f)
					{
						emission = value11;
					}
				}
				array[i] = Models.Mat("glb_" + text, white, metallic, 1f - num, emission);
			}
			return array;
		}

		private static float[] ReadFloats(JsonElement root, int accessor, byte[] glb, int bin, out int count)
		{
			JsonElement jsonElement = root.GetProperty("accessors")[accessor];
			count = jsonElement.GetProperty("count").GetInt32();
			int num = Components(jsonElement.GetProperty("type").GetString());
			JsonElement jsonElement2 = root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()];
			JsonElement value;
			JsonElement value2;
			int num2 = bin + (jsonElement2.TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0);
			JsonElement value3;
			int num3 = (jsonElement2.TryGetProperty("byteStride", out value3) ? value3.GetInt32() : (num * 4));
			float[] array = new float[count * num];
			for (int i = 0; i < count; i++)
			{
				for (int j = 0; j < num; j++)
				{
					array[i * num + j] = BitConverter.ToSingle(glb, num2 + i * num3 + j * 4);
				}
			}
			return array;
		}

		private static int[] ReadIndices(JsonElement root, int accessor, byte[] glb, int bin)
		{
			JsonElement jsonElement = root.GetProperty("accessors")[accessor];
			int @int = jsonElement.GetProperty("count").GetInt32();
			int int2 = jsonElement.GetProperty("componentType").GetInt32();
			JsonElement value;
			JsonElement value2;
			int num = bin + (root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()].TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0);
			int[] array = new int[@int];
			for (int i = 0; i < @int; i++)
			{
				int[] array2 = array;
				int num2 = i;
				int[] array3 = array2;
				int num3 = num2;
				array3[num3] = int2 switch
				{
					5121 => glb[num + i], 
					5123 => BitConverter.ToUInt16(glb, num + i * 2), 
					_ => (int)BitConverter.ToUInt32(glb, num + i * 4), 
				};
			}
			return array;
		}

		private static int Components(string type)
		{
			return type switch
			{
				"SCALAR" => 1, 
				"VEC2" => 2, 
				"VEC3" => 3, 
				"VEC4" => 4, 
				_ => 1, 
			};
		}
	}
	internal static class Host
	{
		public static bool Ok;

		public static string LinkedInGameNote = "Fortify Your Base already sells these at the hardware stores.";

		private static bool _linkedTold;

		private static bool _whereTold;

		public static string WhereToBuyNote;

		private static string _linkedNote;

		private static Action _onLoaded;

		private static Action _onUnloaded;

		private static string _folder;

		public static void Init(MelonMod mod, string folder, string title, string prefix, string linkedNote = null, Action onLoaded = null, Action onUnloaded = null)
		{
			_folder = folder;
			Kit.Log = ((MelonBase)mod).LoggerInstance;
			Kit.Prefix = prefix;
			Kit.Title = title;
			Kit.ModelResourcePrefix = ((object)mod).GetType().Namespace + ".models.";
			FortifyApi.Init(mod, folder, title);
			_linkedNote = linkedNote;
			_onLoaded = onLoaded;
			_onUnloaded = onUnloaded;
			FortifyApi.AfterLoad += Loaded;
			FortifyApi.BeforeSave += Placement.Save;
			FortifyApi.Unloaded += Unloaded;
		}

		private static void Loaded()
		{
			Registration.ResetForNewScene();
			Placement.Load();
			try
			{
				_onLoaded?.Invoke();
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Loading: " + ex.Message);
				}
			}
			MelonCoroutines.Start(Registration.RenderIcons());
		}

		private static void Unloaded()
		{
			try
			{
				_onUnloaded?.Invoke();
			}
			catch
			{
			}
			Placement.Reset();
			CoopMirror.Reset();
		}

		public static bool Update()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if (!Ok)
			{
				return false;
			}
			try
			{
				Registration.TryRegister();
			}
			catch
			{
			}
			if (!FortifyApi.InGame)
			{
				return false;
			}
			FortifyApi.Frame();
			try
			{
				StuckInput.Update();
			}
			catch
			{
			}
			if (FortifyApi.Linked && _linkedNote != null)
			{
				if (!_linkedTold)
				{
					_linkedTold = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Msg(_linkedNote);
					}
					TellLinkedOnce();
				}
				Registration.TryAddToShops(onlyWithFyb: true);
			}
			else
			{
				Registration.TryAddToShops();
			}
			if (!_whereTold && WhereToBuyNote != null && FortifyApi.DataReady)
			{
				_whereTold = true;
				if (!FortifyApi.Linked || _linkedNote == null)
				{
					TellWhereOnce();
				}
			}
			try
			{
				Placement.Update();
				try
				{
					CoopMirror.Update();
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				if (Time.frameCount % 600 == 0)
				{
					Instance log2 = Kit.Log;
					if (log2 != null)
					{
						log2.Warning("Placement: " + ex.Message);
					}
				}
			}
			if (FortifyApi.DevKeys && FortifyApi.KeyHeld((KeyCode)308) && FortifyApi.KeyDown(Kit.DevGiveKey))
			{
				Placement.DevGive();
			}
			return true;
		}

		private static void TellLinkedOnce()
		{
			try
			{
				MelonPreferences_Category val = MelonPreferences.GetCategory(_folder) ?? MelonPreferences.CreateCategory(_folder, Kit.Title);
				MelonPreferences_Entry<bool> val2 = val.GetEntry<bool>("LinkedNoticeShown") ?? val.CreateEntry<bool>("LinkedNoticeShown", false, "Linked notice shown", "Set once the in-game note about Fortify Your Base has been shown.", true, false, (ValueValidator)null, (string)null);
				if (!val2.Value)
				{
					val2.Value = true;
					FortifyApi.Notify(Kit.Title, LinkedInGameNote);
					MelonPreferences.Save();
				}
			}
			catch
			{
			}
		}

		private static void TellWhereOnce()
		{
			try
			{
				MelonPreferences_Category val = MelonPreferences.GetCategory(_folder) ?? MelonPreferences.CreateCategory(_folder, Kit.Title);
				MelonPreferences_Entry<bool> val2 = val.GetEntry<bool>("WhereNoticeShown") ?? val.CreateEntry<bool>("WhereNoticeShown", false, "Where-to-buy notice shown", "Set once the in-game note about where the items are sold has been shown.", true, false, (ValueValidator)null, (string)null);
				if (!val2.Value)
				{
					val2.Value = true;
					FortifyApi.Notify(Kit.Title, WhereToBuyNote);
					MelonPreferences.Save();
				}
			}
			catch
			{
			}
		}

		public static void DrawHint()
		{
			if (!Ok || !FortifyApi.InGame)
			{
				return;
			}
			try
			{
				FortifyApi.Hint(Placement.Hint);
				PickupHold.Draw();
			}
			catch
			{
			}
		}
	}
	internal static class InputUtil
	{
		private static bool _legacyBroken;

		public static bool Suppressed;

		public static KeyCode Parse(string name, KeyCode fallback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrWhiteSpace(name) && Enum.TryParse<KeyCode>(name.Trim(), ignoreCase: true, out KeyCode result))
			{
				return result;
			}
			return fallback;
		}

		public static bool Down(KeyCode key)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!Suppressed && !TextBoxElsewhere())
			{
				return RawDown(key);
			}
			return false;
		}

		public static bool Held(KeyCode key)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!Suppressed && !TextBoxElsewhere())
			{
				return RawHeld(key);
			}
			return false;
		}

		private static bool TextBoxElsewhere()
		{
			try
			{
				return AppDomain.CurrentDomain.GetData("WoodStudios.TextBoxFrame") is int num && Time.frameCount - num <= 2;
			}
			catch
			{
				return false;
			}
		}

		public static bool RawDown(KeyCode key)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetKeyDown(key);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			KeyControl obj2 = Control(key);
			if (obj2 == null)
			{
				return false;
			}
			return ((ButtonControl)obj2).wasPressedThisFrame;
		}

		public static bool RawHeld(KeyCode key)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetKey(key);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			KeyControl obj2 = Control(key);
			if (obj2 == null)
			{
				return false;
			}
			return ((ButtonControl)obj2).isPressed;
		}

		public static bool MouseDown(int button)
		{
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetMouseButtonDown(button);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			try
			{
				Mouse current = Mouse.current;
				if (current == null)
				{
					return false;
				}
				return (button == 0) ? current.leftButton.wasPressedThisFrame : current.rightButton.wasPressedThisFrame;
			}
			catch
			{
				return false;
			}
		}

		public static bool MouseHeld(int button)
		{
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetMouseButton(button);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			try
			{
				Mouse current = Mouse.current;
				if (current == null)
				{
					return false;
				}
				return (button == 0) ? current.leftButton.isPressed : current.rightButton.isPressed;
			}
			catch
			{
				return false;
			}
		}

		private unsafe static KeyControl Control(KeyCode key)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return null;
				}
				string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
				if (text.StartsWith("Alpha"))
				{
					text = "Digit" + text.Substring(5);
				}
				else if (text == "Return")
				{
					text = "Enter";
				}
				else if (text == "KeypadEnter")
				{
					text = "NumpadEnter";
				}
				else if (text.StartsWith("Keypad"))
				{
					text = "Numpad" + text.Substring(6);
				}
				if (!Enum.TryParse<Key>(text, ignoreCase: true, out Key result))
				{
					return null;
				}
				return current[result];
			}
			catch
			{
				return null;
			}
		}
	}
	internal sealed class ItemSpec
	{
		public string Id;

		public string Name;

		public string Description;

		public float Price;

		public PlaceKind Kind;

		public int StackLimit = 10;

		public float RotateStep = 90f;

		public Color IconColor = Color.gray;

		public Func<GameObject> BuildModel;

		public Func<GameObject> IconModel;

		public string[] Stores;

		public bool NotSold;

		public bool SoldWithFyb;

		public float FitLift;

		public Bounds? FitBounds;

		public GameObject Template;
	}
	internal static class Kit
	{
		public delegate bool UseHandler(Placement.Placed p, RaycastHit hit, out string hint);

		public delegate bool Placer(ItemSpec spec, Camera cam, Player player, out string hint);

		public static string Prefix = "wk_";

		public static string ModelResourcePrefix = "WoodKit.models.";

		public static string Title = "Wood Studios";

		public static string SaveKey = "Items";

		public static Instance Log;

		public static string[] Stores = new string[2] { "Dan's Hardware", "Handy Hank's Hardware" };

		public static Func<float> PriceMultiplier = () => 1f;

		public static KeyCode RotateKey = (KeyCode)114;

		public static KeyCode DevGiveKey = (KeyCode)117;

		public static readonly Dictionary<string, UseHandler> Use = new Dictionary<string, UseHandler>(StringComparer.OrdinalIgnoreCase);

		public static readonly Dictionary<string, Placer> CustomPlace = new Dictionary<string, Placer>(StringComparer.OrdinalIgnoreCase);

		public static Func<bool> Busy = () => false;

		public static Func<Placement.Placed, bool> CanPickUp;

		public static event Action<Placement.Placed> Created;

		public static event Action<Placement.Placed> Removed;

		internal static void RaiseCreated(Placement.Placed p)
		{
			try
			{
				Kit.Created?.Invoke(p);
			}
			catch (Exception ex)
			{
				Instance log = Log;
				if (log != null)
				{
					log.Warning(p?.Spec?.Name + ": " + ex.Message);
				}
			}
		}

		internal static void RaiseRemoved(Placement.Placed p)
		{
			try
			{
				Kit.Removed?.Invoke(p);
			}
			catch (Exception ex)
			{
				Instance log = Log;
				if (log != null)
				{
					log.Warning(p?.Spec?.Name + ": " + ex.Message);
				}
			}
		}
	}
	internal static class Locals
	{
		private const int Nearest = 2;

		private static float _next;

		private static float _localsAt = -100f;

		private static readonly List<NPC> _locals = new List<NPC>();

		private static readonly HashSet<IntPtr> _localSet = new HashSet<IntPtr>();

		private static readonly HashSet<IntPtr> _reported = new HashSet<IntPtr>();

		private static bool _warned;

		public static void Reset()
		{
			_locals.Clear();
			_localSet.Clear();
			_reported.Clear();
			_localsAt = -100f;
			_next = 0f;
		}

		public static void Keep(IList<NPC> ours, string title)
		{
			if (ours == null || ours.Count == 0 || Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 5f;
			try
			{
				if (_locals.Count == 0 || (Object)(object)_locals[0] == (Object)null || Time.unscaledTime - _localsAt > 60f)
				{
					FindLocals();
				}
				if (_locals.Count == 0)
				{
					return;
				}
				foreach (NPC our in ours)
				{
					if ((Object)(object)our != (Object)null)
					{
						Link(our, title);
					}
				}
			}
			catch (Exception ex)
			{
				if (!_warned)
				{
					_warned = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning(title + ": linking customers to the locals (" + ex.Message + ").");
					}
				}
			}
		}

		private static void FindLocals()
		{
			_localsAt = Time.unscaledTime;
			_locals.Clear();
			_localSet.Clear();
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			Assembly assembly = typeof(NPC).Assembly;
			foreach (NPC item in NPC.All)
			{
				try
				{
					if (item != null && ((object)item).GetType().Assembly != assembly && (Object)(object)item.gameObject != (Object)null)
					{
						hashSet.Add(((Il2CppObjectBase)item.gameObject).Pointer);
					}
				}
				catch
				{
				}
			}
			List<NPC> nPCRegistry = NPCManager.NPCRegistry;
			int num = 0;
			while (nPCRegistry != null && num < nPCRegistry.Count)
			{
				NPC val = nPCRegistry[num];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null) && !hashSet.Contains(((Il2CppObjectBase)((Component)val).gameObject).Pointer) && val.RelationData != null && !((Object)(object)((Component)val).GetComponent<Customer>() == (Object)null))
				{
					_locals.Add(val);
					_localSet.Add(((Il2CppObjectBase)val).Pointer);
				}
				num++;
			}
		}

		private static bool Has(List<NPC> list, NPC n)
		{
			for (int i = 0; i < list.Count; i++)
			{
				NPC val = list[i];
				if ((Object)(object)val != (Object)null && ((Il2CppObjectBase)val).Pointer == ((Il2CppObjectBase)n).Pointer)
				{
					return true;
				}
			}
			return false;
		}

		private static void Join(NPC me, NPC local)
		{
			List<NPC> connections = me.RelationData.Connections;
			if (!Has(connections, local))
			{
				connections.Add(local);
			}
			NPCRelationData relationData = local.RelationData;
			List<NPC> val = ((relationData != null) ? relationData.Connections : null);
			if (val != null && !Has(val, me))
			{
				val.Add(me);
			}
		}

		private static void Link(NPC me, string title)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			NPCRelationData relationData = me.RelationData;
			List<NPC> val = ((relationData != null) ? relationData.Connections : null);
			if (val == null)
			{
				return;
			}
			int num = 0;
			bool flag = false;
			for (int i = 0; i < val.Count; i++)
			{
				NPC val2 = val[i];
				if (!((Object)(object)val2 == (Object)null) && _localSet.Contains(((Il2CppObjectBase)val2).Pointer))
				{
					num++;
					if (val2.RelationData != null && val2.RelationData.Unlocked)
					{
						flag = true;
					}
				}
			}
			if (num >= 2 && (flag || relationData.Unlocked))
			{
				return;
			}
			Vector3 at = ((Component)me).transform.position;
			EMapRegion region = me.Region;
			List<NPC> list = new List<NPC>();
			foreach (NPC local in _locals)
			{
				if ((Object)(object)local != (Object)null && local.Region == region)
				{
					list.Add(local);
				}
			}
			if (list.Count == 0)
			{
				list.AddRange(_locals);
			}
			list.Sort(delegate(NPC a, NPC b)
			{
				//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)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val3 = ((Component)a).transform.position - at;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				val3 = ((Component)b).transform.position - at;
				return sqrMagnitude.CompareTo(((Vector3)(ref val3)).sqrMagnitude);
			});
			List<string> list2 = new List<string>();
			foreach (NPC item in list)
			{
				if (num >= 2)
				{
					break;
				}
				if (!Has(val, item))
				{
					Join(me, item);
					num++;
					if (item.RelationData.Unlocked)
					{
						flag = true;
					}
					list2.Add(item.FirstName);
				}
			}
			if (!flag && !relationData.Unlocked)
			{
				foreach (NPC item2 in list)
				{
					if (item2.RelationData.Unlocked && !Has(val, item2))
					{
						Join(me, item2);
						list2.Add(item2.FirstName + " (you know them)");
						break;
					}
				}
			}
			if (list2.Count <= 0 || !FortifyApi.DevKeys)
			{
				return;
			}
			string value = "";
			if (!_reported.Contains(((Il2CppObjectBase)me).Pointer))
			{
				_reported.Add(((Il2CppObjectBase)me).Pointer);
				try
				{
					Customer component = ((Component)me).GetComponent<Customer>();
					string text = null;
					bool flag2 = (Object)(object)component != (Object)null && component.SampleOptionValid(ref text);
					value = (relationData.Unlocked ? " Already a customer." : (flag2 ? " A sample can be offered now." : (" No sample yet: " + text + ".")));
				}
				catch (Exception ex)
				{
					value = " (sample check: " + ex.Message + ")";
				}
			}
			Instance log = Kit.Log;
			if (log != null)
			{
				log.Msg($"{title}: {me.FirstName} knows {string.Join(", ", list2)}.{value}");
			}
		}
	}
	internal static class Models
	{
		private static GameObject _root;

		private static readonly Dictionary<string, Material> Mats = new Dictionary<string, Material>();

		private static Shader _litShader;

		public const float WallHeight = 2.4f;

		public const float WallThick = 0.25f;

		public static Transform Root
		{
			get
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				if ((Object)(object)_root == (Object)null)
				{
					_root = new GameObject(Kit.Prefix + "Templates");
					_root.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)_root);
				}
				return _root.transform;
			}
		}

		internal static Material Concrete => Mat("concrete", new Color(0.58f, 0.58f, 0.56f), 0f, 0.12f);

		internal static Material Mortar => Mat("mortar", new Color(0.42f, 0.42f, 0.41f), 0f, 0.05f);

		internal static Material SteelDark => Mat("steel_dark", new Color(0.2f, 0.21f, 0.23f), 0.8f, 0.45f);

		internal static Material SteelLight => Mat("steel_light", new Color(0.55f, 0.57f, 0.6f), 0.85f, 0.55f);

		internal static Material Housing => Mat("housing", new Color(0.86f, 0.86f, 0.84f), 0.1f, 0.5f);

		internal static Material BlackPlastic => Mat("black", new Color(0.05f, 0.05f, 0.06f), 0.2f, 0.6f);

		internal static Material LedRed => Mat("led_red", new Color(1f, 0.1f, 0.1f), 0f, 0.8f, (Color?)new Color(4f, 0.2f, 0.2f));

		internal static Material LensWarm => Mat("lens_warm", new Color(1f, 0.96f, 0.85f), 0f, 0.9f, (Color?)new Color(3f, 2.8f, 2.3f));

		internal static Material Chain => Mat("chain", new Color(0.52f, 0.54f, 0.57f), 0.7f, 0.4f);

		internal static Material Burlap => Mat("burlap", new Color(0.62f, 0.55f, 0.4f), 0f, 0.05f);

		internal static Material Hazard => Mat("hazard", new Color(0.95f, 0.75f, 0.1f));

		internal static Shader Lit()
		{
			return LitShader();
		}

		public static Sprite FallbackIcon(Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					bool flag = i > 6 && i < 57 && j > 6 && j < 57;
					bool flag2 = flag && (i < 11 || i > 52 || j < 11 || j > 52);
					val.SetPixel(i, j, (!flag) ? val2 : (flag2 ? (color * 0.55f) : color));
				}
			}
			val.Apply();
			((Object)val).hideFlags = (HideFlags)32;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		private static Shader LitShader()
		{
			if ((Object)(object)_litShader != (Object)null)
			{
				return _litShader;
			}
			_litShader = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)_litShader == (Object)null)
			{
				_litShader = Shader.Find("Universal Render Pipeline/Simple Lit");
			}
			if ((Object)(object)_litShader == (Object)null)
			{
				foreach (Material item in Resources.FindObjectsOfTypeAll<Material>())
				{
					if ((Object)(object)item != (Object)null && (Object)(object)item.shader != (Object)null && ((Object)item.shader).name.Contains("Lit"))
					{
						_litShader = item.shader;
						break;
					}
				}
			}
			if ((Object)(object)_litShader == (Object)null)
			{
				_litShader = Shader.Find("Standard");
			}
			return _litShader;
		}

		public static Material Mat(string key, Color color, float metallic = 0f, float smoothness = 0.3f, Color? emission = null)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (Mats.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Material val = new Material(LitShader());
			((Object)val).name = Kit.Prefix + key;
			val.color = color;
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", color);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metallic);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", smoothness);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", smoothness);
			}
			if (emission.HasValue)
			{
				val.EnableKeyword("_EMISSION");
				if (val.HasProperty("_EmissionColor"))
				{
					val.SetColor("_EmissionColor", emission.Value);
				}
				val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			((Object)val).hideFlags = (HideFlags)32;
			Mats[key] = val;
			return val;
		}

		internal static GameObject NewRoot(string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(Root, false);
			return val;
		}

		internal static GameObject Prim(PrimitiveType type, Transform parent, Vector3 pos, Vector3 scale, Material mat, Vector3? euler = null, bool keepCollider = false)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive(type);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = pos;
			val.transform.localRotation = (euler.HasValue ? Quaternion.Euler(euler.Value) : Quaternion.identity);
			val.transform.localScale = scale;
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).sharedMaterial = mat;
			}
			if (!keepCollider)
			{
				Collider component2 = val.GetComponent<Collider>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component2);
				}
			}
			return val;
		}

		internal static GameObject Box(Transform p, Vector3 pos, Vector3 size, Material m, Vector3? euler = null)
		{
			//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)
			return Prim((PrimitiveType)3, p, pos, size, m, euler);
		}

		internal static GameObject Rod(Transform p, Vector3 pos, float radius, float height, Material m, Vector3? euler = null)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return Prim((PrimitiveType)2, p, pos, new Vector3(radius * 2f, height * 0.5f, radius * 2f), m, euler);
		}

		internal static void AddBoxCollider(GameObject go, Vector3 center, Vector3 size)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			BoxCollider obj = go.AddComponent<BoxCollider>();
			obj.center = center;
			obj.size = size;
		}

		internal static void NavBlock(GameObject go, Vector3 center, Vector3 size)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			AddNavObstacle(go, center, size);
		}

		private static void AddNavObstacle(GameObject go, Vector3 center, Vector3 size)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				NavMeshObstacle obj = go.AddComponent<NavMeshObstacle>();
				obj.shape = (NavMeshObstacleShape)1;
				obj.center = center;
				obj.size = size;
				obj.carving = true;
			}
			catch
			{
			}
		}

		public static void Combine(Transform root)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<int, List<MeshFilter>> dictionary = new Dictionary<int, List<MeshFilter>>();
			Dictionary<int, Material> dictionary2 = new Dictionary<int, Material>();
			foreach (MeshFilter componentsInChild in ((Component)root).GetComponentsInChildren<MeshFilter>(true))
			{
				if ((Object)(object)((Component)componentsInChild).transform == (Object)(object)root || (Object)(object)componentsInChild.sharedMesh == (Object)null)
				{
					continue;
				}
				if (!componentsInChild.sharedMesh.isReadable)
				{
					return;
				}
				MeshRenderer component = ((Component)componentsInChild).GetComponent<MeshRenderer>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)((Renderer)component).sharedMaterial == (Object)null))
				{
					int instanceID = ((Object)((Renderer)component).sharedMaterial).GetInstanceID();
					if (!dictionary.TryGetValue(instanceID, out var value))
					{
						List<MeshFilter> list = (dictionary[instanceID] = new List<MeshFilter>());
						value = list;
						dictionary2[instanceID] = ((Renderer)component).sharedMaterial;
					}
					value.Add(componentsInChild);
				}
			}
			Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
			foreach (KeyValuePair<int, List<MeshFilter>> item in dictionary)
			{
				if (item.Value.Count < 2)
				{
					continue;
				}
				Il2CppStructArray<CombineInstance> val = new Il2CppStructArray<CombineInstance>((long)item.Value.Count);
				for (int i = 0; i < item.Value.Count; i++)
				{
					int num = i;
					CombineInstance val2 = default(CombineInstance);
					((CombineInstance)(ref val2)).mesh = item.Value[i].sharedMesh;
					((CombineInstance)(ref val2)).transform = worldToLocalMatrix * ((Component)item.Value[i]).transform.localToWorldMatrix;
					((Il2CppArrayBase<CombineInstance>)(object)val)[num] = val2;
				}
				Mesh val3 = new Mesh
				{
					name = "HTF_Combined"
				};
				val3.indexFormat = (IndexFormat)1;
				val3.CombineMeshes(val, true, true);
				val3.RecalculateBounds();
				((Object)val3).hideFlags = (HideFlags)32;
				GameObject val4 = new GameObject("Combined_" + ((Object)dictionary2[item.Key]).name);
				val4.transform.SetParent(root, false);
				val4.AddComponent<MeshFilter>().sharedMesh = val3;
				((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = dictionary2[item.Key];
				foreach (MeshFilter item2 in item.Value)
				{
					Object.DestroyImmediate((Object)(object)((Component)item2).gameObject);
				}
			}
		}

		internal static void MeshColliders(GameObject root, params string[] prefixes)
		{
			foreach (MeshFilter componentsInChild in root.GetComponentsInChildren<MeshFilter>(true))
			{
				foreach (string value in prefixes)
				{
					if (((Object)componentsInChild).name.StartsWith(value, StringComparison.Ordinal))
					{
						((Component)componentsInChild).gameObject.AddComponent<MeshCollider>().sharedMesh = componentsInChild.sharedMesh;
						break;
					}
				}
			}
		}

		internal static Light AddPointLight(Transform parent, string name, Vector3 local, float range, float intensity, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = local;
			Light obj = val.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.range = range;
			obj.intensity = intensity;
			obj.color = color;
			obj.shadows = (LightShadows)0;
			return obj;
		}

		internal static AudioSource AddAudio(Transform parent, string name, Vector3 local, AudioClip clip, bool loop, bool playOnAwake, float volume, float maxDistance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = local;
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.clip = clip;
			obj.loop = loop;
			obj.playOnAwake = playOnAwake;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 1.5f;
			obj.maxDistance = maxDistance;
			obj.volume = volume;
			return obj;
		}
	}
	internal static class PickupHold
	{
		private const float Seconds = 0.6f;

		private static float _start = -1f;

		private static int _target;

		private static int _lastFrame = -10;

		public static float Progress { get; private set; }

		public static bool Showing
		{
			get
			{
				if (Progress > 0f)
				{
					return Time.frameCount - _lastFrame <= 2;
				}
				return false;
			}
		}

		public static bool Held(GameObject target)
		{
			int num = (((Object)(object)target != (Object)null) ? ((Object)target).GetInstanceID() : 0);
			int frameCount = Time.frameCount;
			bool flag = frameCount - _lastFrame > 2;
			_lastFrame = frameCount;
			if (num == 0 || !MouseHeld() || HoldingWeapon())
			{
				_start = -1f;
				Progress = 0f;
				_target = num;
				return false;
			}
			if (_start < 0f || num != _target || flag)
			{
				_target = num;
				Progress = 0f;
				if (!Keys.MouseDown(1))
				{
					_start = -1f;
					return false;
				}
				_start = Time.unscaledTime;
			}
			Progress = Mathf.Clamp01((Time.unscaledTime - _start) / 0.6f);
			if (Progress < 1f)
			{
				return false;
			}
			_start = -1f;
			Progress = 0f;
			return true;
		}

		private static bool MouseHeld()
		{
			try
			{
				return Input.GetMouseButton(1);
			}
			catch
			{
				try
				{
					Mouse current = Mouse.current;
					return current != null && current.rightButton.isPressed;
				}
				catch
				{
					return false;
				}
			}
		}

		private static bool HoldingWeapon()
		{
			try
			{
				PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
				Equippable val = ((instance != null) ? instance.Equippable : null);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				return (Object)(object)((Il2CppObjectBase)val).TryCast<Equippable_RangedWeapon>() != (Object)null || (Object)(object)((Il2CppObjectBase)val).TryCast<Equippable_MeleeWeapon>() != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		public static void Draw()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (Showing)
			{
				float num = 220f;
				float num2 = (float)Screen.width * 0.5f - num * 0.5f;
				float num3 = (float)Screen.height * 0.68f + 40f;
				FortifyApi.UiFill(new Rect(num2, num3, num, 8f), new Color(0f, 0f, 0f, 0.6f));
				FortifyApi.UiFill(new Rect(num2, num3, num * Progress, 8f), new Color(1f, 1f, 1f, 0.9f));
			}
		}
	}
	internal sealed class PlacedRecord
	{
		public string Id { get; set; }

		public float[] Pos { get; set; }

		public float[] Rot { get; set; }

		public bool Active { get; set; } = true;

		public int Channel { get; set; }

		public string Text { get; set; }

		public float[] Extra { get; set; }
	}
	internal enum PlaceKind
	{
		Ground,
		Wall
	}
	internal static class Placement
	{
		internal sealed class Placed
		{
			public GameObject Go;

			public ItemSpec Spec;

			public PlacedRecord Rec;

			public bool Active = true;

			public int Channel;

			public string Text;

			public string Label;

			public Camera Feed;

			public bool OnShip;

			public Vector3[] Extra;

			public object State;
		}

		private const float PlaceReach = 8f;

		private const float UseReach = 3.5f;

		private const float Tile = 0.25f;

		private static readonly List<Placed> Items = new List<Placed>();

		internal static int Version;

		private static GameObject _ghost;

		private static string _ghostId;

		private static Bounds _ghostLocalBounds;

		private static float _ghostLift;

		private static Bounds? _ghostFit;

		private static float _blockedLogAt = -100f;

		internal static string LastBlocker;

		private static bool _ghostShowingValid;

		private static int _rotIndex;

		private static float _turn;

		private const float FineTurn = 15f;

		private static string _hint;

		private static readonly HashSet<int> Ignored = new HashSet<int>();

		private static float _ignoredRefreshAt;

		internal static List<Placed> All => Items;

		public static string Hint => _hint;

		internal static int Count(string id)
		{
			int num = 0;
			foreach (Placed item in Items)
			{
				if ((Object)(object)item.Go != (Object)null && string.Equals(item.Spec.Id, id, StringComparison.OrdinalIgnoreCase))
				{
					num++;
				}
			}
			return num;
		}

		public static void Load()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Reset();
			List<PlacedRecord> list = null;
			try
			{
				string data = FortifyApi.GetData(Kit.SaveKey);
				if (!string.IsNullOrEmpty(data))
				{
					list = JsonSerializer.Deserialize<List<PlacedRecord>>(data);
				}
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Couldn't read the saved items (" + ex.Message + ").");
				}
			}
			if (list == null)
			{
				return;
			}
			int num = 0;
			foreach (PlacedRecord item in list)
			{
				ItemSpec itemSpec = Catalog.Get(item?.Id);
				if (itemSpec != null && !((Object)(object)itemSpec.Template == (Object)null) && item.Pos != null && item.Rot != null)
				{
					Placed placed = Create(itemSpec, V(item.Pos), Q(item.Rot), item);
					Items.Add(placed);
					num++;
					Kit.RaiseCreated(placed);
				}
			}
			Version++;
			if (num > 0)
			{
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Msg($"Put back {num} placed item(s).");
				}
			}
		}

		public static void Save()
		{
			try
			{
				List<PlacedRecord> list = new List<PlacedRecord>();
				foreach (Placed item in Items)
				{
					if (!((Object)(object)item.Go == (Object)null))
					{
						UpdateRecord(item);
						list.Add(item.Rec);
					}
				}
				FortifyApi.SetData(Kit.SaveKey, JsonSerializer.Serialize(list));
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Couldn't save the placed items: " + ex.Message);
				}
			}
		}

		public static void Reset()
		{
			foreach (Placed item in Items)
			{
				Kit.RaiseRemoved(item);
				if ((Object)(object)item.Go != (Object)null)
				{
					Object.Destroy((Object)(object)item.Go);
				}
			}
			Items.Clear();
			Version++;
			DestroyGhost();
			_hint = null;
		}

		internal static void UpdateRecord(Placed p)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = p.Go.transform;
			if (p.Rec == null)
			{
				p.Rec = new PlacedRecord
				{
					Id = p.Spec.Id
				};
			}
			p.Rec.Pos = F(transform.position);
			p.Rec.Rot = F(transform.rotation);
			p.Rec.Active = p.Active;
			p.Rec.Channel = p.Channel;
			p.Rec.Text = p.Text;
			if (p.Extra != null)
			{
				float[] array = new float[p.Extra.Length * 3];
				for (int i = 0; i < p.Extra.Length; i++)
				{
					array[i * 3] = p.Extra[i].x;
					array[i * 3 + 1] = p.Extra[i].y;
					array[i * 3 + 2] = p.Extra[i].z;
				}
				p.Rec.Extra = array;
			}
		}

		public static void Update()
		{
			_hint = null;
			Player local = Player.Local;
			Camera camera = GetCamera();
			if ((Object)(object)local == (Object)null || (Object)(object)camera == (Object)null || UiBusy(local))
			{
				HideGhost();
				return;
			}
			ItemSpec itemSpec = Catalog.Get(EquippedId());
			if (itemSpec != null)
			{
				if (Kit.CustomPlace.TryGetValue(itemSpec.Id, out var value))
				{
					HideGhost();
					value(itemSpec, camera, local, out _hint);
				}
				else
				{
					UpdatePlacing(itemSpec, camera, local);
				}
			}
			else
			{
				HideGhost();
				UpdateLooking(camera, local);
			}
		}

		private static void UpdatePlacing(ItemSpec spec, Camera cam, Player player)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: 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_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: 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_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or