Decompiled source of Hoop Heat v1.0.0

Mods/WoodStudios.HoopHeat.dll

Decompiled 20 minutes 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 Hoops;
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 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.Rendering;
using S1API.Shops;
using Schedule2;
using Schedule2.Game;
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_HP.FybCommon;
using WS_HP.WoodKit;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(HoopCore), "Hoop Heat Arcade Basketball", "1.0.0", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })]
[assembly: AssemblyTitle("WoodStudios.HoopHeat")]
[assembly: AssemblyProduct("WoodStudios.HoopHeat")]
[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 Hoops
{
	public sealed class HoopCore : MelonMod
	{
		internal const string MachineId = "hp_machine";

		private static MelonPreferences_Category _cat;

		private static MelonPreferences_Entry<int> _high;

		private static MelonPreferences_Entry<int> _tickets;

		private static MelonPreferences_Entry<float> _price;

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

		private static float _warnedAt = -100f;

		internal static GameObject Load(string file)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(file.Replace(".glb", ""));
			((Object)GltfLoader.LoadEmbedded(file, 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) && Fixed.Add(((Object)item).GetInstanceID()))
					{
						Color color = item.color;
						Color val2 = (item.color = ((Color)(ref color)).gamma);
						if (item.HasProperty("_BaseColor"))
						{
							item.SetColor("_BaseColor", val2);
						}
					}
				}
			}
			return val;
		}

		public override void OnInitializeMelon()
		{
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Host.Init((MelonMod)(object)this, "HoopHeat", "Hoop Heat Arcade Basketball", "hp_", null, Loaded, Unloaded);
				_cat = MelonPreferences.GetCategory("HoopHeat") ?? MelonPreferences.CreateCategory("HoopHeat", "Hoop Heat Arcade Basketball");
				_price = _cat.CreateEntry<float>("PriceMultiplier", 1f, "Price multiplier", "Multiplies the machine's price (1 = $1,500, 0 = free). Applies after a game restart.", false, false, (ValueValidator)null, (string)null);
				_high = _cat.CreateEntry<int>("HighScore", 0, "High score", "", true, false, (ValueValidator)null, (string)null);
				_tickets = _cat.CreateEntry<int>("Tickets", 0, "Tickets", "", true, false, (ValueValidator)null, (string)null);
				Kit.PriceMultiplier = () => Mathf.Max(0f, _price?.Value ?? 1f);
				HoopGame.Loader = Load;
				FortifyApi.SetNotifyIcon("hp_machine");
				Catalog.Add(new ItemSpec
				{
					Id = "hp_machine",
					Name = "Hoop Heat Arcade Basketball",
					Price = 1500f,
					Kind = PlaceKind.Ground,
					StackLimit = 1,
					RotateStep = 15f,
					IconColor = new Color(0.05f, 0.12f, 0.35f),
					BuildModel = delegate
					{
						GameObject obj = Load("AB_Machine.glb");
						HoopGame.AddColliders(obj);
						return obj;
					},
					Description = "A full-size stand-up arcade basketball machine for your place. 60 seconds, as many baskets as you can: click when the power meter hits the orange. 2 points a basket, 3 in the last 10 seconds. Tickets and a high score on the board."
				});
				Kit.Use["hp_machine"] = Use;
				Kit.Busy = () => HoopGame.Playing;
				Host.WhereToBuyNote = "Hoop Heat: the machine is at Dan's Hardware and Handy Hank's Hardware.";
				Host.Ok = true;
				((MelonBase)this).LoggerInstance.Msg("Hoop Heat loaded. The machine is at the hardware stores.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Hoop Heat couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer.");
			}
		}

		private static void Loaded()
		{
			HoopGame.High = _high.Value;
			HoopGame.TotalTickets = _tickets.Value;
		}

		private static void Unloaded()
		{
			HoopGame.Stop();
		}

		private static bool Use(Placement.Placed p, RaycastHit hit, out string hint)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			hint = null;
			Player local = Player.Local;
			if ((Object)(object)p?.Go == (Object)null || (Object)(object)local == (Object)null || HoopGame.Playing)
			{
				return false;
			}
			Vector3 val = p.Go.transform.InverseTransformPoint(((Component)local).transform.position);
			if (val.z > 0.4f || val.z < -2.2f || Mathf.Abs(val.x) > 1.2f)
			{
				hint = "Hoop Heat - stand at the front to play";
				return true;
			}
			KeyCode useKey = FortifyApi.UseKey;
			hint = $"[{useKey}] Play Hoop Heat    High score {_high.Value}    Tickets {_tickets.Value}";
			if (FortifyApi.KeyDown(useKey))
			{
				HoopGame.EndNote = "";
				HoopGame.Start(p.Go.transform, "HOOP HEAT", delegate
				{
					_high.Value = HoopGame.High;
					_tickets.Value = HoopGame.TotalTickets;
					HoopGame.EndNote = $"Total tickets {HoopGame.TotalTickets}";
					try
					{
						_cat.SaveToFile(false);
					}
					catch
					{
					}
				});
			}
			return true;
		}

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

		public override void OnFixedUpdate()
		{
			if (!Host.Ok)
			{
				return;
			}
			try
			{
				HoopGame.FixedUpdate();
			}
			catch
			{
			}
		}

		public override void OnGUI()
		{
			Host.DrawHint();
			if (!Host.Ok || !FortifyApi.InGame)
			{
				return;
			}
			try
			{
				HoopGame.Draw();
			}
			catch
			{
			}
		}
	}
	internal static class HoopGame
	{
		private enum St
		{
			Off,
			Countdown,
			Playing,
			Over
		}

		private sealed class Ball
		{
			public GameObject Go;

			public Rigidbody Rb;

			public bool Held;

			public bool Flying;

			public bool Scored;

			public float LastY;

			public float ShotAt;

			public float StuckSince = -1f;

			public Vector3 LastV;
		}

		public static readonly Vector3 Rim = new Vector3(0f, 2.08f, 2.6f);

		public const float RimR = 0.21f;

		public const float BallR = 0.09f;

		public static readonly Vector3 Stand = new Vector3(0f, 0f, -0.45f);

		private static readonly Vector3 TraySpot = new Vector3(0f, 1f, 0.36f);

		public static Func<string, GameObject> Loader;

		public static int High;

		public static int TotalTickets;

		private static St _st;

		private static Transform _m;

		private static float _t0;

		private static float _overAt;

		private static float _heldAt;

		private static float _popAt = -10f;

		private static float _lastShot;

		private static int _score;

		private static int _baskets;

		private static int _shots;

		private static int _lastPoints;

		private static string _pop = "";

		private static Action<int, int> _onEnd;

		private static string _title = "HOOP HEAT";

		private static readonly List<Ball> Balls = new List<Ball>();

		private static Ball _held;

		private static PhysicMaterial _bouncy;

		public const float GameSeconds = 60f;

		public const float HeatSeconds = 10f;

		private static int _lastBeep;

		private static int _endTickets;

		private static bool _endBest;

		public static string EndNote = "";

		public static bool Playing => _st != St.Off;

		public static float Meter => Mathf.PingPong((Time.time - _heldAt) * 1.8f, 1f);

		public static void AddColliders(GameObject go)
		{
			//IL_001c: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: 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_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			Box("Base", new Vector3(0f, 0.41f, 1.45f), new Vector3(1.24f, 0.82f, 2.9f), Vector3.zero);
			Box("Ramp", new Vector3(0f, 0.99f, 1.65f), new Vector3(1.12f, 0.04f, 2.55f), new Vector3(-7f, 0f, 0f));
			Box("Tray", new Vector3(0f, 0.86f, 0.34f), new Vector3(1f, 0.08f, 0.32f), Vector3.zero);
			Box("TrayLip", new Vector3(0f, 0.92f, 0.17f), new Vector3(1.04f, 0.16f, 0.04f), Vector3.zero);
			Box("Panel", new Vector3(0f, 0.85f, 0.08f), new Vector3(1.24f, 0.12f, 0.2f), Vector3.zero);
			Box("NetL", new Vector3(-0.6f, 1.85f, 1.6f), new Vector3(0.04f, 2.1f, 2.6f), Vector3.zero);
			Box("NetR", new Vector3(0.6f, 1.85f, 1.6f), new Vector3(0.04f, 2.1f, 2.6f), Vector3.zero);
			Box("Back", new Vector3(0f, 1.42f, 2.95f), new Vector3(1.24f, 1.2f, 0.06f), Vector3.zero);
			Box("Board", new Vector3(0f, 2.32f, 2.88f), new Vector3(1.05f, 0.72f, 0.04f), Vector3.zero);
			Box("Score", new Vector3(0f, 3.1f, 2.92f), new Vector3(1.3f, 0.7f, 0.2f), Vector3.zero);
			Box("Roof", new Vector3(0f, 3.3f, 1.6f), new Vector3(1.24f, 0.05f, 2.6f), Vector3.zero);
			Box("Bracket", new Vector3(0f, 2.07f, 2.74f), new Vector3(0.12f, 0.03f, 0.27f), Vector3.zero);
			for (int i = 0; i < 16; i++)
			{
				float num = (float)i / 16f * (float)Math.PI * 2f;
				Vector3 c = Rim + new Vector3(Mathf.Cos(num) * 0.21f, 0f, Mathf.Sin(num) * 0.21f);
				Box("Rim" + i, c, new Vector3(0.024f, 0.024f, 0.09f), new Vector3(0f, (0f - num) * 57.29578f, 0f));
			}
			Digits.Build(go);
			void Box(string n, Vector3 localPosition, Vector3 s, Vector3 euler)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("hp_" + n);
				val.transform.SetParent(go.transform, false);
				val.transform.localPosition = localPosition;
				val.transform.localRotation = Quaternion.Euler(euler);
				val.AddComponent<BoxCollider>().size = s;
			}
		}

		public static void Start(Transform machine, string title, Action<int, int> onEnd)
		{
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (Playing || (Object)(object)machine == (Object)null)
			{
				return;
			}
			_m = machine;
			_title = title;
			_onEnd = onEnd;
			_score = (_baskets = (_shots = 0));
			_st = St.Countdown;
			_t0 = Time.time;
			_pop = "";
			Player local = Player.Local;
			try
			{
				PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
				Vector3 val = _m.TransformPoint(Stand);
				Quaternion val2 = Quaternion.LookRotation(_m.forward, Vector3.up);
				if (instance != null)
				{
					instance.Teleport(val, val2, true);
				}
				if ((Object)(object)instance != (Object)null)
				{
					instance.CanMove = false;
				}
				if ((Object)(object)local != (Object)null)
				{
					((Component)local).transform.rotation = val2;
				}
				PlayerCamera instance2 = PlayerSingleton<PlayerCamera>.Instance;
				if (instance2 != null)
				{
					instance2.LookAt(_m.TransformPoint(Rim + new Vector3(0f, -0.25f, 0f)), 0.25f);
				}
				PlayerInventory instance3 = PlayerSingleton<PlayerInventory>.Instance;
				if (instance3 != null)
				{
					instance3.SetEquippingEnabled(false);
				}
			}
			catch
			{
			}
			MakeBalls();
			Digits.Show(((Component)_m).gameObject, "Score", 0);
			Digits.Show(((Component)_m).gameObject, "Time", 60);
			Digits.Show(((Component)_m).gameObject, "High", High);
			HoopSound.Play(HoopSound.Beep, _m.TransformPoint(Rim), 0.3f);
		}

		public static void Stop()
		{
			if (_st == St.Off)
			{
				return;
			}
			_st = St.Off;
			foreach (Ball ball in Balls)
			{
				if ((Object)(object)ball.Go != (Object)null)
				{
					Object.Destroy((Object)(object)ball.Go);
				}
			}
			Balls.Clear();
			_held = null;
			try
			{
				PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.CanMove = true;
				}
				PlayerInventory instance2 = PlayerSingleton<PlayerInventory>.Instance;
				if (instance2 != null)
				{
					instance2.SetEquippingEnabled(true);
				}
			}
			catch
			{
			}
		}

		private static void MakeBalls()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0044: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (_bouncy == null)
			{
				_bouncy = new PhysicMaterial
				{
					name = "hp_ball",
					bounciness = 0.62f,
					dynamicFriction = 0.45f,
					staticFriction = 0.5f,
					bounceCombine = (PhysicMaterialCombine)0
				};
			}
			Color val2 = default(Color);
			for (int i = 0; i < 4; i++)
			{
				GameObject val = Loader("AB_Ball.glb");
				((Object)val).name = "hp_Ball";
				foreach (Renderer componentsInChild in val.GetComponentsInChildren<Renderer>(true))
				{
					componentsInChild.shadowCastingMode = (ShadowCastingMode)1;
					foreach (Material item in (Il2CppArrayBase<Material>)(object)componentsInChild.sharedMaterials)
					{
						if ((Object)(object)item != (Object)null && item.color.r > 0.5f && item.color.g > 0.3f)
						{
							((Color)(ref val2))..ctor(0.78f, 0.27f, 0.05f);
							item.color = val2;
							if (item.HasProperty("_BaseColor"))
							{
								item.SetColor("_BaseColor", val2);
							}
						}
					}
				}
				SphereCollider obj = val.AddComponent<SphereCollider>();
				obj.radius = 0.09f;
				((Collider)obj).material = _bouncy;
				Rigidbody val3 = val.AddComponent<Rigidbody>();
				val3.mass = 0.6f;
				val3.drag = 0.02f;
				val3.angularDrag = 0.3f;
				val3.interpolation = (RigidbodyInterpolation)1;
				val3.collisionDetectionMode = (CollisionDetectionMode)2;
				val.transform.position = _m.TransformPoint(TraySpot + new Vector3(-0.3f + (float)i * 0.2f, 0.05f, 0f));
				Balls.Add(new Ball
				{
					Go = val,
					Rb = val3
				});
			}
		}

		public static void Update()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (_st == St.Off)
			{
				return;
			}
			if ((Object)(object)_m == (Object)null)
			{
				Stop();
				return;
			}
			try
			{
				PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
				if ((Object)(object)instance != (Object)null && instance.CanMove)
				{
					instance.CanMove = false;
				}
			}
			catch
			{
			}
			float time = Time.time;
			switch (_st)
			{
			case St.Countdown:
			{
				float num = 3f - (time - _t0);
				int num2 = Mathf.CeilToInt(num);
				if (num2 != _lastBeep && num2 > 0)
				{
					_lastBeep = num2;
					HoopSound.Play(HoopSound.Beep, Cam().position, 0.25f);
				}
				if (num <= 0f)
				{
					_st = St.Playing;
					_t0 = time;
					HoopSound.Play(HoopSound.Go, Cam().position, 0.3f);
				}
				HoldNext();
				break;
			}
			case St.Playing:
			{
				float num3 = 60f - (time - _t0);
				Digits.Show(((Component)_m).gameObject, "Time", Mathf.Max(0, Mathf.CeilToInt(num3)));
				HoldNext();
				if (!Cursor.visible && Keys.MouseDown(0) && _held != null && time - _lastShot > 0.25f)
				{
					Shoot();
				}
				if (num3 <= 0f)
				{
					End();
				}
				break;
			}
			case St.Over:
				if (time - _overAt > 4f)
				{
					Stop();
				}
				break;
			}
			if (_st != St.Off && FortifyApi.KeyDown((KeyCode)120) && _st != St.Over)
			{
				End();
			}
			PoseHeld();
		}

		public static void FixedUpdate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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)
			//IL_0187: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: 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_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			if (_st == St.Off || (Object)(object)_m == (Object)null)
			{
				return;
			}
			_m.TransformPoint(Rim);
			Vector2 val3 = default(Vector2);
			Vector2 val5 = default(Vector2);
			foreach (Ball ball in Balls)
			{
				if ((Object)(object)ball.Go == (Object)null || ball.Held)
				{
					continue;
				}
				Vector3 position = ball.Go.transform.position;
				Vector3 velocity = ball.Rb.velocity;
				Vector3 val = velocity - ball.LastV;
				if (((Vector3)(ref val)).magnitude > 2.2f)
				{
					Vector3 val2 = _m.InverseTransformPoint(position);
					((Vector2)(ref val3))..ctor(val2.x - Rim.x, val2.z - Rim.z);
					if (Mathf.Abs(val2.y - Rim.y) < 0.15f && Mathf.Abs(((Vector2)(ref val3)).magnitude - 0.21f) < 0.14f)
					{
						HoopSound.Play(HoopSound.Clank, position, 0.35f);
					}
					else if (val2.z > 2.75f && val2.y > 1.9f)
					{
						HoopSound.Play(HoopSound.Board, position, 0.4f);
					}
					else
					{
						AudioClip bounce = HoopSound.Bounce;
						val = velocity - ball.LastV;
						HoopSound.Play(bounce, position, Mathf.Clamp01(((Vector3)(ref val)).magnitude / 8f) * 0.25f);
					}
				}
				ball.LastV = velocity;
				Vector3 val4 = _m.InverseTransformPoint(position);
				if (ball.Flying && !ball.Scored && ball.LastY > Rim.y && val4.y <= Rim.y && velocity.y < 0f)
				{
					((Vector2)(ref val5))..ctor(val4.x - Rim.x, val4.z - Rim.z);
					if (((Vector2)(ref val5)).magnitude < 0.1785f)
					{
						ball.Scored = true;
						Score(position);
					}
				}
				ball.LastY = val4.y;
				if (ball.Flying && val4.z < 0.75f && val4.y < 1.25f && Time.time - ball.ShotAt > 0.6f)
				{
					ball.Flying = false;
				}
				bool flag = Mathf.Abs(val4.x) > 0.8f || val4.z < -0.6f || val4.z > 3.2f || val4.y < 0.3f || val4.y > 4f;
				bool flag2 = ((Vector3)(ref velocity)).sqrMagnitude < 0.05f && val4.z > 0.75f;
				if (flag || flag2)
				{
					if (ball.StuckSince < 0f)
					{
						ball.StuckSince = Time.time;
					}
					if (flag || Time.time - ball.StuckSince > 1.2f)
					{
						ball.Rb.velocity = Vector3.zero;
						ball.Go.transform.position = _m.TransformPoint(TraySpot + new Vector3(Random.Range(-0.3f, 0.3f), 0.1f, 0f));
						ball.Flying = false;
						ball.StuckSince = -1f;
					}
				}
				else
				{
					ball.StuckSince = -1f;
				}
			}
		}

		private static Transform Cam()
		{
			Camera main = Camera.main;
			if (!((Object)(object)main != (Object)null))
			{
				return _m;
			}
			return ((Component)main).transform;
		}

		private static void HoldNext()
		{
			//IL_0053: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (_held != null)
			{
				return;
			}
			Ball ball = null;
			float num = 9f;
			foreach (Ball ball2 in Balls)
			{
				if ((Object)(object)ball2.Go == (Object)null || ball2.Held || ball2.Flying)
				{
					continue;
				}
				Vector3 val = _m.InverseTransformPoint(ball2.Go.transform.position);
				if (val.z < 0.75f && val.y < 1.4f)
				{
					float num2 = Mathf.Abs(val.x);
					if (num2 < num)
					{
						num = num2;
						ball = ball2;
					}
				}
			}
			if (ball != null)
			{
				_held = ball;
				ball.Held = true;
				ball.Scored = false;
				ball.Rb.isKinematic = true;
				_heldAt = Time.time;
			}
		}

		private static Vector3 HandPos()
		{
			//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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Cam();
			return val.position + val.forward * 0.42f - val.up * 0.2f + val.right * 0.12f;
		}

		private static void PoseHeld()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_held?.Go == (Object)null))
			{
				float num = Mathf.Clamp01((Time.time - _heldAt) / 0.15f);
				_held.Go.transform.position = Vector3.Lerp(_held.Go.transform.position, HandPos(), num);
			}
		}

		private static void Shoot()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			Ball held = _held;
			_held = null;
			_lastShot = Time.time;
			_shots++;
			Vector3 val = HandPos();
			Vector3 val2 = _m.TransformPoint(Rim + new Vector3(0f, 0f, 0.02f)) - val;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
			Vector3 forward = Cam().forward;
			forward.y = 0f;
			Vector3 val4 = Vector3.Slerp(((Vector3)(ref val3)).normalized, ((Vector3)(ref forward)).normalized, 0.22f);
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			float y = val2.y;
			float num = 0.9075712f;
			float num2 = 2f * Mathf.Cos(num) * Mathf.Cos(num) * (magnitude * Mathf.Tan(num) - y);
			float num3 = ((num2 > 0.01f) ? Mathf.Sqrt(9.81f * magnitude * magnitude / num2) : 6f);
			float meter = Meter;
			float num4 = num3 * (0.87f + 0.26f * meter);
			Vector3 val5 = normalized * (num4 * Mathf.Cos(num)) + Vector3.up * (num4 * Mathf.Sin(num));
			held.Held = false;
			held.Flying = true;
			held.Scored = false;
			held.ShotAt = Time.time;
			held.Rb.isKinematic = false;
			held.Go.transform.position = val;
			held.Rb.velocity = val5;
			held.Rb.angularVelocity = Vector3.Cross(Vector3.up, normalized) * -8f;
			held.LastY = _m.InverseTransformPoint(val).y;
			held.LastV = val5;
			HoopSound.Play(HoopSound.Toss, val, 0.18f);
		}

		private static void Score(Vector3 at)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			bool num = Time.time - _t0 > 50f;
			int num2 = (num ? 3 : 2);
			_score += num2;
			_baskets++;
			_lastPoints = num2;
			_pop = (num ? "+3  HEAT!" : "+2");
			_popAt = Time.time;
			Digits.Show(((Component)_m).gameObject, "Score", _score);
			HoopSound.Play(HoopSound.Swish, at, 0.4f);
		}

		private static void End()
		{
			//IL_0020: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			_st = St.Over;
			_overAt = Time.time;
			_held = null;
			HoopSound.Play(HoopSound.Buzzer, Cam().position, 0.3f);
			int num = Mathf.Max(1, _score / 2);
			bool num2 = _score > High;
			if (num2)
			{
				High = _score;
				Digits.Show(((Component)_m).gameObject, "High", High);
			}
			TotalTickets += num;
			_endTickets = num;
			_endBest = num2;
			HoopSound.Play(HoopSound.Tickets, _m.TransformPoint(new Vector3(0.45f, 0.7f, -0.02f)), 0.25f);
			try
			{
				_onEnd?.Invoke(_score, num);
			}
			catch
			{
			}
		}

		public static string State()
		{
			return $"st={_st} score={_score} baskets={_baskets}/{_shots} high={High} tickets={TotalTickets} held={_held != null} meter={Meter:0.00}";
		}

		public static string DevShot(float meter)
		{
			if (_held == null)
			{
				return "no ball in hand";
			}
			_heldAt = Time.time - meter / 1.8f;
			Shoot();
			return "shot at " + meter;
		}

		public static void Draw()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0628: Unknown result type (might be due to invalid IL or missing references)
			//IL_0641: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0673: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0709: Unknown result type (might be due to invalid IL or missing references)
			//IL_0735: Unknown result type (might be due to invalid IL or missing references)
			//IL_0766: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0911: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0871: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_089c: Unknown result type (might be due to invalid IL or missing references)
			if (_st == St.Off || Cursor.visible)
			{
				return;
			}
			float num = Screen.width;
			float num2 = Screen.height;
			float num3 = num2 / 1080f;
			Color c = default(Color);
			((Color)(ref c))..ctor(0.03f, 0.06f, 0.13f, 0.74f);
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.55f, 0.1f);
			float time = Time.time;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(num / 2f - 310f * num3, 18f * num3, 620f * num3, 58f * num3);
			WS_HP.FybCommon.Ui.Fill(r, c);
			WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 2f * num3, ((Rect)(ref r)).width, 2f * num3), val);
			WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r)).x + 18f * num3, ((Rect)(ref r)).y, 240f * num3, ((Rect)(ref r)).height), _title, Mathf.RoundToInt(20f * num3), val, (TextAnchor)3, bold: true, wrap: false);
			float num4 = ((_st == St.Playing) ? Mathf.Max(0f, 60f - (time - _t0)) : ((_st == St.Countdown) ? 60f : 0f));
			bool flag = _st == St.Playing && num4 <= 10f;
			WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 18f * num3, ((Rect)(ref r)).height), $"SCORE {_score}    TIME {Mathf.CeilToInt(num4)}", Mathf.RoundToInt(18f * num3), (Color)(flag ? new Color(1f, 0.45f, 0.3f) : Color.white), (TextAnchor)5, bold: true, wrap: false);
			if (_st == St.Countdown)
			{
				int num5 = Mathf.CeilToInt(3f - (time - _t0));
				Shadow(new Rect(0f, num2 * 0.3f, num, 140f * num3), (num5 > 0) ? num5.ToString() : "GO!", Mathf.RoundToInt(110f * num3), Color.white);
				Shadow(new Rect(0f, num2 * 0.3f + 130f * num3, num, 40f * num3), "Click when the meter hits the orange", Mathf.RoundToInt(22f * num3), new Color(1f, 1f, 1f, 0.9f));
			}
			if (flag && _st == St.Playing)
			{
				float num6 = 0.6f + 0.4f * Mathf.Sin(time * 8f);
				Shadow(new Rect(0f, 90f * num3, num, 40f * num3), "HEAT TIME - 3 POINTS A BASKET", Mathf.RoundToInt(22f * num3), new Color(1f, 0.45f, 0.2f, num6));
			}
			float num7 = time - _popAt;
			if (num7 < 0.9f && _pop.Length > 0)
			{
				float num8 = 1f - num7 / 0.9f;
				Shadow(new Rect(0f, num2 * 0.36f - num7 * 60f * num3, num, 90f * num3), _pop, Mathf.RoundToInt((70f + 20f * num8) * num3), new Color(1f, (_lastPoints == 3) ? 0.55f : 0.85f, 0.2f, num8));
			}
			if (_st == St.Playing && _held != null)
			{
				float num9 = 420f * num3;
				float num10 = 16f * num3;
				Rect r2 = default(Rect);
				((Rect)(ref r2))..ctor(num / 2f - num9 / 2f, num2 - 190f * num3, num9, num10);
				WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r2)).x - 4f * num3, ((Rect)(ref r2)).y - 4f * num3, ((Rect)(ref r2)).width + 8f * num3, ((Rect)(ref r2)).height + 8f * num3), c);
				WS_HP.FybCommon.Ui.Fill(r2, new Color(1f, 1f, 1f, 0.16f));
				WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r2)).x + num9 * 0.36f, ((Rect)(ref r2)).y, num9 * 0.28f, num10), new Color(0.4f, 0.9f, 0.55f, 0.55f));
				WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r2)).x + num9 * 0.45f, ((Rect)(ref r2)).y, num9 * 0.1f, num10), val);
				WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r2)).x + Meter * num9 - 2.5f * num3, ((Rect)(ref r2)).y - 8f * num3, 5f * num3, num10 + 16f * num3), Color.white);
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r2)).x - 90f * num3, ((Rect)(ref r2)).y - 6f * num3, 80f * num3, 28f * num3), "SHORT", Mathf.RoundToInt(12f * num3), new Color(1f, 1f, 1f, 0.7f), (TextAnchor)5, bold: true, wrap: false);
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r2)).xMax + 10f * num3, ((Rect)(ref r2)).y - 6f * num3, 80f * num3, 28f * num3), "LONG", Mathf.RoundToInt(12f * num3), new Color(1f, 1f, 1f, 0.7f), (TextAnchor)3, bold: true, wrap: false);
			}
			if (_st == St.Over)
			{
				float num11 = Mathf.Clamp01((time - _overAt) * 3f);
				Rect r3 = default(Rect);
				((Rect)(ref r3))..ctor(num / 2f - 300f * num3, num2 * 0.26f, 600f * num3, 250f * num3);
				WS_HP.FybCommon.Ui.Fill(r3, new Color(0.03f, 0.06f, 0.13f, 0.85f * num11));
				WS_HP.FybCommon.Ui.Fill(new Rect(((Rect)(ref r3)).x, ((Rect)(ref r3)).y, ((Rect)(ref r3)).width, 4f * num3), new Color(val.r, val.g, val.b, num11));
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r3)).x, ((Rect)(ref r3)).y + 18f * num3, ((Rect)(ref r3)).width, 30f * num3), "FINAL SCORE", Mathf.RoundToInt(18f * num3), new Color(1f, 0.6f, 0.15f, num11), (TextAnchor)4);
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r3)).x, ((Rect)(ref r3)).y + 50f * num3, ((Rect)(ref r3)).width, 90f * num3), _score.ToString(), Mathf.RoundToInt(80f * num3), new Color(1f, 1f, 1f, num11), (TextAnchor)4);
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r3)).x, ((Rect)(ref r3)).y + 140f * num3, ((Rect)(ref r3)).width, 30f * num3), $"{_baskets} of {_shots} shots    {_endTickets} tickets", Mathf.RoundToInt(20f * num3), new Color(1f, 1f, 1f, 0.9f * num11), (TextAnchor)4, bold: false);
				string text = (_endBest ? "NEW HIGH SCORE!" : $"High score {High}");
				if (EndNote.Length > 0)
				{
					text = text + "    " + EndNote;
				}
				WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r3)).x, ((Rect)(ref r3)).y + 180f * num3, ((Rect)(ref r3)).width, 40f * num3), text, Mathf.RoundToInt(22f * num3), _endBest ? new Color(1f, 0.8f, 0.25f, num11) : new Color(0.75f, 0.8f, 0.9f, num11), (TextAnchor)4);
			}
			if (_st == St.Playing)
			{
				WS_HP.FybCommon.Ui.Text(new Rect(28f * num3, num2 - 128f * num3, 400f * num3, 28f * num3), "[Click] Shoot    [X] Stop", Mathf.RoundToInt(16f * num3), new Color(1f, 1f, 1f, 0.85f), (TextAnchor)3, bold: true, wrap: false);
			}
		}

		private static void Shadow(Rect r, string t, int size, Color c)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			WS_HP.FybCommon.Ui.Text(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 3f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), t, size, new Color(0f, 0f, 0f, c.a * 0.55f), (TextAnchor)4, bold: true, wrap: false);
			WS_HP.FybCommon.Ui.Text(r, t, size, c, (TextAnchor)4, bold: true, wrap: false);
		}
	}
	internal static class Digits
	{
		private static Material _on;

		private static Material _off;

		private static readonly int[] Masks = new int[10] { 63, 6, 91, 79, 102, 109, 125, 7, 127, 111 };

		private static readonly (string name, Vector3 at, Color c)[] Displays = new(string, Vector3, Color)[3]
		{
			("Score", new Vector3(-0.38f, 2.94f, 2.828f), new Color(1f, 0.55f, 0.1f)),
			("Time", new Vector3(0f, 2.94f, 2.828f), new Color(0.3f, 0.75f, 1f)),
			("High", new Vector3(0.38f, 2.94f, 2.828f), new Color(1f, 0.25f, 0.2f))
		};

		public static void Build(GameObject go)
		{
			//IL_001b: 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_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			if (_off == null)
			{
				_off = FortifyApi.Mat("hp_seg_off", new Color(0.06f, 0.03f, 0.03f));
			}
			(string, Vector3, Color)[] displays = Displays;
			Vector3 zero = default(Vector3);
			Vector3 localScale = default(Vector3);
			for (int i = 0; i < displays.Length; i++)
			{
				(string, Vector3, Color) tuple = displays[i];
				string item = tuple.Item1;
				Vector3 item2 = tuple.Item2;
				Color item3 = tuple.Item3;
				Material sharedMaterial = FortifyApi.Emissive("hp_seg_" + item, item3, item3 * 3f);
				GameObject val = new GameObject("hp_Disp_" + item);
				val.transform.SetParent(go.transform, false);
				val.transform.localPosition = item2;
				for (int j = 0; j < 3; j++)
				{
					GameObject val2 = new GameObject("Digit" + j);
					val2.transform.SetParent(val.transform, false);
					val2.transform.localPosition = new Vector3((float)(j - 1) * 0.085f, 0f, 0f);
					for (int k = 0; k < 7; k++)
					{
						GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
						Object.Destroy((Object)(object)val3.GetComponent<Collider>());
						((Object)val3).name = "Seg" + k;
						val3.transform.SetParent(val2.transform, false);
						float num = 0.05f;
						float num2 = 0.055f;
						float num3 = 0.011f;
						switch (k)
						{
						case 0:
							((Vector3)(ref zero))..ctor(0f, num2, 0f);
							((Vector3)(ref localScale))..ctor(num, num3, 0.005f);
							break;
						case 1:
							((Vector3)(ref zero))..ctor(num / 2f, num2 / 2f, 0f);
							((Vector3)(ref localScale))..ctor(num3, num2, 0.005f);
							break;
						case 2:
							((Vector3)(ref zero))..ctor(num / 2f, (0f - num2) / 2f, 0f);
							((Vector3)(ref localScale))..ctor(num3, num2, 0.005f);
							break;
						case 3:
							((Vector3)(ref zero))..ctor(0f, 0f - num2, 0f);
							((Vector3)(ref localScale))..ctor(num, num3, 0.005f);
							break;
						case 4:
							((Vector3)(ref zero))..ctor((0f - num) / 2f, (0f - num2) / 2f, 0f);
							((Vector3)(ref localScale))..ctor(num3, num2, 0.005f);
							break;
						case 5:
							((Vector3)(ref zero))..ctor((0f - num) / 2f, num2 / 2f, 0f);
							((Vector3)(ref localScale))..ctor(num3, num2, 0.005f);
							break;
						default:
							zero = Vector3.zero;
							((Vector3)(ref localScale))..ctor(num, num3, 0.005f);
							break;
						}
						val3.transform.localPosition = zero;
						val3.transform.localScale = localScale;
						Renderer component = val3.GetComponent<Renderer>();
						component.sharedMaterial = _off;
						component.shadowCastingMode = (ShadowCastingMode)0;
					}
					val2.SetActive(true);
				}
				((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = sharedMaterial;
			}
		}

		public static void Show(GameObject go, string display, int value)
		{
			Transform val = go.transform.Find("hp_Disp_" + display);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			Material val2 = ((component != null) ? ((Renderer)component).sharedMaterial : null);
			value = Mathf.Clamp(value, 0, 999);
			for (int i = 0; i < 3; i++)
			{
				Transform val3 = val.Find("Digit" + i);
				int num = 2 - i;
				int num2 = num switch
				{
					1 => 10, 
					2 => 100, 
					_ => 1, 
				};
				int num3 = ((num <= 0 || value >= num2) ? Masks[value / num2 % 10] : 0);
				for (int j = 0; j < 7; j++)
				{
					Transform val4 = ((val3 != null) ? val3.Find("Seg" + j) : null);
					if ((Object)(object)val4 != (Object)null)
					{
						((Component)val4).GetComponent<Renderer>().sharedMaterial = (((num3 & (1 << j)) != 0) ? val2 : _off);
					}
				}
			}
		}
	}
	internal static class HoopSound
	{
		private sealed class S
		{
			public float L;

			public float Low(float x, float k)
			{
				return L += (x - L) * k;
			}
		}

		private const float Tau = (float)Math.PI * 2f;

		private static AudioClip _swish;

		private static AudioClip _clank;

		private static AudioClip _board;

		private static AudioClip _bounce;

		private static AudioClip _toss;

		private static AudioClip _beep;

		private static AudioClip _go;

		private static AudioClip _buzzer;

		private static AudioClip _tickets;

		public static AudioClip Swish => _swish ?? (_swish = Make("hp_swish", 0.4f, (float t, Random r, S s) => s.Low(N(r), 0.45f) * Mathf.Sin(Mathf.Clamp01(t / 0.4f) * (float)Math.PI) * 0.8f));

		public static AudioClip Clank => _clank ?? (_clank = Make("hp_clank", 0.5f, (float t, Random r, S s) => (Mathf.Sin((float)Math.PI * 1480f * t) * 0.4f + Mathf.Sin((float)Math.PI * 3240f * t) * 0.25f) * Mathf.Exp((0f - t) * 9f) + N(r) * Mathf.Exp((0f - t) * 90f) * 0.3f));

		public static AudioClip Board => _board ?? (_board = Make("hp_board", 0.3f, (float t, Random r, S s) => s.Low(N(r), 0.2f) * Mathf.Exp((0f - t) * 22f) * 1.4f + Mathf.Sin((float)Math.PI * 320f * t) * Mathf.Exp((0f - t) * 18f) * 0.3f));

		public static AudioClip Bounce => _bounce ?? (_bounce = Make("hp_bounce", 0.2f, (float t, Random r, S s) => Mathf.Sin((float)Math.PI * 2f * (120f - 200f * t) * t) * Mathf.Exp((0f - t) * 25f) * 0.8f));

		public static AudioClip Toss => _toss ?? (_toss = Make("hp_toss", 0.15f, (float t, Random r, S s) => s.Low(N(r), 0.15f) * Mathf.Sin(t / 0.15f * (float)Math.PI) * 0.7f));

		public static AudioClip Beep => _beep ?? (_beep = Make("hp_beep", 0.14f, (float t, Random r, S s) => Mathf.Sin((float)Math.PI * 1760f * t) * 0.4f * Mathf.Clamp01((0.14f - t) * 30f)));

		public static AudioClip Go => _go ?? (_go = Make("hp_go", 0.35f, (float t, Random r, S s) => Mathf.Sin((float)Math.PI * 2640f * t) * 0.4f * Mathf.Clamp01((0.35f - t) * 15f)));

		public static AudioClip Buzzer => _buzzer ?? (_buzzer = Make("hp_buzzer", 0.9f, (float t, Random r, S s) => (Mathf.Sign(Mathf.Sin((float)Math.PI * 392f * t)) * 0.25f + Mathf.Sin((float)Math.PI * 784f * t) * 0.1f) * Mathf.Clamp01((0.9f - t) * 8f)));

		public static AudioClip Tickets => _tickets ?? (_tickets = Make("hp_tickets", 1.2f, (float t, Random r, S s) => N(r) * Mathf.Exp((0f - t * 40f % 1f) * 30f) * 0.5f));

		private static float N(Random r)
		{
			return (float)(r.NextDouble() * 2.0 - 1.0);
		}

		private static AudioClip Make(string name, float seconds, Func<float, Random, S, float> f)
		{
			try
			{
				int num = 22050;
				int num2 = Mathf.CeilToInt(seconds * (float)num);
				Random arg = new Random(name.GetHashCode());
				S arg2 = new S();
				Il2CppStructArray<float> val = new Il2CppStructArray<float>((long)num2);
				for (int i = 0; i < num2; i++)
				{
					((Il2CppArrayBase<float>)(object)val)[i] = Mathf.Clamp(f((float)i / (float)num, arg, arg2), -1f, 1f);
				}
				AudioClip obj = Sfx.Create(name, num2, 1, num, stream: false);
				Sfx.SetData(obj, val, 0);
				((Object)obj).hideFlags = (HideFlags)32;
				return obj;
			}
			catch
			{
				return null;
			}
		}

		public static void Play(AudioClip c, Vector3 at, float volume)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)c == (Object)null)
			{
				return;
			}
			try
			{
				AudioSource.PlayClipAtPoint(c, at, volume);
			}
			catch
			{
			}
		}
	}
}
namespace WS_HP.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.Relat