Decompiled source of TogetherPlus v1.2.0

TogetherPlus.dll

Decompiled 13 hours 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.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cinemachine;
using HarmonyLib;
using Newtonsoft.Json;
using PurrLobby;
using PurrNet;
using PurrNet.Packing;
using PurrNet.Transports;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace TogetherPlus;

internal sealed class AmbienceFeature : Feature
{
	private sealed class Layer
	{
		public AudioSource Src;

		public float Cur;

		public float Target;

		public Func<AudioClip> Make;
	}

	public ConfigEntry<float> Master;

	public ConfigEntry<float> BirdsVol;

	public ConfigEntry<float> CricketsVol;

	public ConfigEntry<float> WavesVol;

	public ConfigEntry<float> WindVol;

	public ConfigEntry<float> MusicVol;

	public ConfigEntry<bool> Birds;

	public ConfigEntry<bool> Crickets;

	public ConfigEntry<bool> Waves;

	public ConfigEntry<bool> Wind;

	public ConfigEntry<bool> Music;

	private readonly Dictionary<string, Layer> _layers = new Dictionary<string, Layer>();

	private GameObject _root;

	private float _nextScan;

	private float _beach;

	private bool _indoor;

	public override string Id => "Ambience";

	public override string Title => "Ambience";

	public override string Description => "Birds by day, crickets at night, waves at the beach, wind and soft background music.";

	protected override void BindSettings(ConfigFile cfg)
	{
		Master = BindRange(cfg, "MasterVolume", 0.15f, 0f, 1f, "Overall volume of all ambience sounds.");
		Birds = Bind(cfg, "Birds", def: true, "Bird song in the daytime (not in rain or deep winter).");
		BirdsVol = BindRange(cfg, "BirdsVolume", 0.5f, 0f, 1f, "Volume of the birds.");
		Crickets = Bind(cfg, "Crickets", def: true, "Crickets at dusk and at night (not in rain or winter).");
		CricketsVol = BindRange(cfg, "CricketsVolume", 0.45f, 0f, 1f, "Volume of the crickets.");
		Waves = Bind(cfg, "Waves", def: true, "Waves when you are on or near the beach.");
		WavesVol = BindRange(cfg, "WavesVolume", 0.6f, 0f, 1f, "Volume of the waves.");
		Wind = Bind(cfg, "Wind", def: true, "Wind in autumn and winter.");
		WindVol = BindRange(cfg, "WindVolume", 0.4f, 0f, 1f, "Volume of the wind.");
		Music = Bind(cfg, "Music", def: false, "Soft background music (a slow pad). Off by default.");
		MusicVol = BindRange(cfg, "MusicVolume", 0.12f, 0f, 1f, "Volume of the background music.");
	}

	public override void OnDisabled()
	{
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
		_root = null;
		_layers.Clear();
	}

	private void Ensure()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		if (!((Object)(object)_root != (Object)null))
		{
			_root = new GameObject("TP_Ambience");
			Object.DontDestroyOnLoad((Object)(object)_root);
			_layers.Clear();
			Add("birds", Synth.Birds);
			Add("crickets", Synth.Crickets);
			Add("waves", Synth.Waves);
			Add("wind", Synth.Wind);
			Add("music", Synth.Pad);
		}
	}

	private void Add(string name, Func<AudioClip> make)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(_root.transform, false);
		AudioSource val2 = val.AddComponent<AudioSource>();
		val2.loop = true;
		val2.spatialBlend = 0f;
		val2.volume = 0f;
		val2.playOnAwake = false;
		_layers[name] = new Layer
		{
			Src = val2,
			Make = make
		};
	}

	private static bool Covered(Vector3 p)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0015: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit[] array = Physics.RaycastAll(p + Vector3.up * 0.3f, Vector3.up, 12f, -1, (QueryTriggerInteraction)1);
		RaycastHit[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val = array2[i];
			if ((Object)(object)((RaycastHit)(ref val)).collider != (Object)null && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerController>() == (Object)null)
			{
				return true;
			}
		}
		return false;
	}

	private static bool IsBeach(Collider c)
	{
		if ((Object)(object)c == (Object)null)
		{
			return false;
		}
		string text = "";
		try
		{
			text = ((Component)c).tag;
		}
		catch
		{
		}
		string text2 = (((Object)c).name ?? "").ToLowerInvariant();
		return text == "Beach" || text == "Sand" || text2.Contains("beach") || text2.Contains("sand");
	}

	private void Scan(Transform me)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		_indoor = Covered(me.position);
		int num = 0;
		int num2 = 0;
		RaycastHit val2 = default(RaycastHit);
		for (int i = 0; i < 8; i++)
		{
			float num3 = (float)i * (float)Math.PI / 4f;
			float num4 = ((i % 2 != 0) ? 12f : 6f);
			Vector3 val = me.position + new Vector3(Mathf.Cos(num3) * num4, 3f, Mathf.Sin(num3) * num4);
			num2++;
			if (Physics.Raycast(val, Vector3.down, ref val2, 12f, -1, (QueryTriggerInteraction)1) && IsBeach(((RaycastHit)(ref val2)).collider))
			{
				num++;
			}
		}
		RaycastHit val3 = default(RaycastHit);
		bool flag = Physics.Raycast(me.position + Vector3.up * 0.5f, Vector3.down, ref val3, 3f, -1, (QueryTriggerInteraction)1) && IsBeach(((RaycastHit)(ref val3)).collider);
		_beach = Mathf.Clamp01((float)num / (float)num2 * 1.4f + ((!flag) ? 0f : 0.5f));
	}

	public override void Tick()
	{
		Transform val = Game.SelfTransform();
		if ((Object)(object)val == (Object)null)
		{
			if (!((Object)(object)_root != (Object)null))
			{
				return;
			}
			foreach (Layer value2 in _layers.Values)
			{
				value2.Target = 0f;
			}
		}
		Ensure();
		string text = "off";
		string text2 = "off";
		string text3 = "off";
		bool flag = false;
		SeasonFeature seasonFeature = Plugin.Get<SeasonFeature>();
		if (seasonFeature != null && seasonFeature.Enabled.Value)
		{
			text = seasonFeature.CurrentName;
			text2 = seasonFeature.TimeName;
			text3 = seasonFeature.WeatherName;
			flag = true;
		}
		int hour = DateTime.Now.Hour;
		bool flag2 = ((flag && text2 != "off") ? (text2 == "night") : (hour >= 21 || hour < 5));
		bool flag3 = ((flag && text2 != "off") ? (text2 == "evening") : (hour >= 18 && hour < 21));
		bool flag4 = !flag2 && !flag3;
		if (text == "off")
		{
			int month = DateTime.Now.Month;
			text = ((month >= 3 && month <= 5) ? "spring" : ((month >= 6 && month <= 8) ? "summer" : ((month < 9 || month > 11) ? "winter" : "autumn")));
		}
		bool flag5 = text3 == "rain";
		if ((Object)(object)val != (Object)null && Time.unscaledTime > _nextScan)
		{
			_nextScan = Time.unscaledTime + 1f;
			Scan(val);
		}
		float num = ((!_indoor) ? 1f : 0.35f);
		float value = Master.Value;
		float num2 = ((!flag4 || flag5 || !(text != "winter")) ? 0f : ((!(text == "spring")) ? 0.75f : 1f));
		float num3 = (((!flag2 && !flag3) || flag5 || !(text != "winter")) ? 0f : ((!(text == "summer")) ? 0.6f : 1f));
		float num4 = ((text == "autumn") ? 0.5f : ((!(text == "winter")) ? 0.15f : 0.55f)) * ((!(text3 == "rain")) ? 1f : 1.4f);
		Set("birds", (!Birds.Value) ? 0f : (num2 * BirdsVol.Value * value * num));
		Set("crickets", (!Crickets.Value) ? 0f : (num3 * CricketsVol.Value * value * num));
		Set("waves", (!Waves.Value) ? 0f : (_beach * WavesVol.Value * value * ((!_indoor) ? 1f : 0.4f)));
		Set("wind", (!Wind.Value) ? 0f : (Mathf.Min(1f, num4) * WindVol.Value * value * num));
		Set("music", (!Music.Value) ? 0f : (MusicVol.Value * value));
		if ((Object)(object)val == (Object)null)
		{
			foreach (Layer value3 in _layers.Values)
			{
				value3.Target = 0f;
			}
		}
		foreach (Layer value4 in _layers.Values)
		{
			value4.Cur = Mathf.MoveTowards(value4.Cur, value4.Target, Time.unscaledDeltaTime * 0.35f);
			if (value4.Cur > 0.002f)
			{
				if ((Object)(object)value4.Src.clip == (Object)null)
				{
					value4.Src.clip = value4.Make();
				}
				if (!value4.Src.isPlaying)
				{
					value4.Src.time = 0f;
					value4.Src.Play();
				}
				value4.Src.volume = value4.Cur;
			}
			else if (value4.Src.isPlaying)
			{
				value4.Src.Pause();
			}
		}
	}

	private void Set(string name, float v)
	{
		if (_layers.TryGetValue(name, out var value))
		{
			value.Target = Mathf.Clamp01(v);
		}
	}
}
internal static class Art
{
	private static readonly Dictionary<string, Material> Cache = new Dictionary<string, Material>();

	private static readonly FieldInfo F_Id = typeof(FocusAreaController).GetField("ID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static readonly FieldInfo F_Settings = typeof(FocusAreaController).GetField("_focusAreaSettings", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo F_Point = typeof(FocusAreaController).GetField("_playerPoint", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo F_Types = typeof(FocusAreaSettings).GetField("_focusTypes", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo F_Lock = typeof(FocusAreaController).GetField("_isLockedPos", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo F_Layer = typeof(FocusAreaController).GetField("_isChangeLayerRoot", BindingFlags.Instance | BindingFlags.NonPublic);

	private static FocusAreaController _tplSettings;

	private static FocusAreaController _tplId;

	public static float BenchSeatY = -1f;

	public static int SeatLayer = 0;

	private static float _nextTpl;

	public static Material OutlineMat(Color c)
	{
		//IL_0005: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		string key = "O" + c;
		if (Cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		Material val = Gfx.Lit(c, 0f);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val);
		((Object)val2).hideFlags = (HideFlags)61;
		value = val2;
		if (value.HasProperty("_Cull"))
		{
			value.SetFloat("_Cull", 1f);
		}
		if (value.HasProperty("_SpecColor"))
		{
			value.SetColor("_SpecColor", Color.black);
		}
		Cache[key] = value;
		return value;
	}

	public static Mesh GrowMesh(Mesh src, float width)
	{
		//IL_0043: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		Vector3[] vertices = src.vertices;
		Vector3[] normals = src.normals;
		Dictionary<long, Vector3> dictionary = new Dictionary<long, Vector3>();
		Func<Vector3, long> func = (Vector3 v) => ((long)Mathf.RoundToInt(v.x * 400f) * 73856093L) ^ ((long)Mathf.RoundToInt(v.y * 400f) * 19349663L) ^ ((long)Mathf.RoundToInt(v.z * 400f) * 83492791L);
		for (int num = 0; num < vertices.Length; num++)
		{
			long key = func(vertices[num]);
			dictionary.TryGetValue(key, out var value);
			dictionary[key] = value + normals[num];
		}
		Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length];
		for (int num2 = 0; num2 < vertices.Length; num2++)
		{
			ref Vector3 reference = ref array[num2];
			Vector3 val = vertices[num2];
			Vector3 val2 = dictionary[func(vertices[num2])];
			reference = val + ((Vector3)(ref val2)).normalized * width;
		}
		Mesh val3 = new Mesh();
		((Object)val3).name = ((Object)src).name + "_outline";
		val3.indexFormat = src.indexFormat;
		Mesh val4 = val3;
		val4.vertices = array;
		val4.uv = src.uv;
		List<int> list = new List<int>();
		for (int num3 = 0; num3 < src.subMeshCount; num3++)
		{
			list.AddRange(src.GetTriangles(num3));
		}
		val4.SetTriangles(list, 0);
		val4.RecalculateBounds();
		return val4;
	}

	public static GameObject Obj(string name, Transform parent, Vector3 pos, Quaternion rot, Mesh mesh, Color outline, float width, params Material[] mats)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		GameObject val = Gfx.Obj(name, parent, pos, rot, mesh, mats);
		Material val2 = OutlineMat(outline);
		if ((Object)(object)val2 != (Object)null && width > 0f)
		{
			GameObject val3 = new GameObject(name + "_Outline");
			val3.layer = 2;
			val3.transform.SetParent(val.transform, false);
			val3.AddComponent<MeshFilter>().sharedMesh = GrowMesh(mesh, width);
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			((Renderer)val4).sharedMaterial = val2;
			((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val4).receiveShadows = false;
		}
		return val;
	}

	public static void AddOutline(GameObject g, Mesh grown, Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Material val = OutlineMat(c);
		if (!((Object)(object)val == (Object)null) && !((Object)(object)grown == (Object)null))
		{
			GameObject val2 = new GameObject("Outline");
			val2.layer = g.layer;
			val2.transform.SetParent(g.transform, false);
			val2.AddComponent<MeshFilter>().sharedMesh = grown;
			MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
			((Renderer)val3).sharedMaterial = val;
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
		}
	}

	public static void FindTemplatesPublic()
	{
		FindTemplates();
	}

	private static void FindTemplates()
	{
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		if (((Object)(object)_tplSettings != (Object)null && (Object)(object)_tplId != (Object)null) || Time.unscaledTime < _nextTpl)
		{
			return;
		}
		_nextTpl = Time.unscaledTime + 5f;
		int num = -1;
		FocusAreaController val = null;
		FocusAreaController val2 = null;
		FocusAreaController[] array = Object.FindObjectsOfType<FocusAreaController>();
		foreach (FocusAreaController val3 in array)
		{
			if ((Object)(object)val3 == (Object)null || (Object)(object)((Component)val3).GetComponent<TpFocusMarker>() != (Object)null)
			{
				continue;
			}
			bool flag = false;
			bool flag2 = false;
			try
			{
				flag = val3.IsYogaOrIsland;
				flag2 = val3.IsClassroom;
			}
			catch
			{
			}
			if (flag && (Object)(object)val2 == (Object)null)
			{
				val2 = val3;
			}
			if (!flag2 && !flag)
			{
				int num2 = 0;
				try
				{
					FocusAreaSettings val4 = (FocusAreaSettings)((!(F_Settings != null)) ? null : /*isinst with value type is only supported in some contexts*/);
					num2 = ((!((Object)(object)val4 != (Object)null) || !(F_Types != null)) ? null : (F_Types.GetValue(val4) as IList))?.Count ?? 0;
				}
				catch
				{
				}
				bool flag3 = false;
				try
				{
					string text = ((!((Object)(object)((Component)val3).transform.parent != (Object)null)) ? "" : ((Object)((Component)val3).transform.parent).name.ToLowerInvariant());
					flag3 = text.Contains("bench") || ((Object)val3).name.ToLowerInvariant().Contains("bench");
				}
				catch
				{
				}
				if (flag3)
				{
					num2 += 100;
				}
				if (num2 > num)
				{
					num = num2;
					val = val3;
				}
			}
		}
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = val;
		}
		_tplSettings = val;
		_tplId = val2;
		if ((Object)(object)val != (Object)null)
		{
			SeatLayer = ((Component)val).gameObject.layer;
		}
		try
		{
			Transform val5 = (Transform)((!((Object)(object)val != (Object)null) || !(F_Point != null)) ? null : /*isinst with value type is only supported in some contexts*/);
			Transform val6 = ((!((Object)(object)val != (Object)null)) ? null : ((!((Object)(object)((Component)val).transform.parent != (Object)null)) ? ((Component)val).transform : ((Component)val).transform.parent));
			if ((Object)(object)val5 != (Object)null && (Object)(object)val6 != (Object)null)
			{
				float num3 = float.MaxValue;
				Renderer[] componentsInChildren = ((Component)val6).GetComponentsInChildren<Renderer>();
				foreach (Renderer val7 in componentsInChildren)
				{
					if ((Object)(object)val7 != (Object)null && val7.enabled)
					{
						float num4 = num3;
						Bounds bounds = val7.bounds;
						num3 = Mathf.Min(num4, ((Bounds)(ref bounds)).min.y);
					}
				}
				if (num3 < float.MaxValue)
				{
					BenchSeatY = val5.position.y - num3;
					Plugin.Log.LogInfo((object)("Focus seat: bench sit point is " + BenchSeatY.ToString("0.00") + " m above the bench base."));
				}
			}
		}
		catch
		{
		}
		Plugin.Log.LogInfo((object)("Focus seat templates: settings=" + ((!((Object)(object)val != (Object)null)) ? "none" : (((!((Object)(object)((Component)val).transform.parent != (Object)null)) ? "" : (((Object)((Component)val).transform.parent).name + "/")) + ((Object)val).name + " (score " + num + ")")) + ", id from=" + ((!((Object)(object)val2 != (Object)null)) ? "none" : ((Object)val2).name)));
	}

	public static bool AddFocusSeat(Transform parent, Vector3 localPos, Quaternion localRot, Vector3 triggerSize, Vector3 triggerCenter)
	{
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_013f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			FindTemplates();
			if ((Object)(object)_tplSettings == (Object)null || (Object)(object)_tplId == (Object)null || F_Id == null || F_Settings == null || F_Point == null)
			{
				Plugin.Log.LogWarning((object)("Focus seat: no template (settings=" + ((Object)(object)_tplSettings != (Object)null) + ", id=" + ((Object)(object)_tplId != (Object)null) + ", fields=" + (F_Id != null && F_Settings != null && F_Point != null) + ")."));
				return false;
			}
			GameObject val = new GameObject("TP_FocusSeat");
			val.layer = SeatLayer;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			val.transform.localRotation = localRot;
			BoxCollider val2 = val.AddComponent<BoxCollider>();
			((Collider)val2).isTrigger = true;
			val2.center = triggerCenter;
			val2.size = triggerSize;
			val.AddComponent<TpFocusMarker>();
			FocusAreaController obj = val.AddComponent<FocusAreaController>();
			F_Id.SetValue(obj, F_Id.GetValue(_tplId));
			F_Settings.SetValue(obj, F_Settings.GetValue(_tplSettings));
			F_Point.SetValue(obj, val.transform);
			if (F_Lock != null)
			{
				F_Lock.SetValue(obj, true);
			}
			if (F_Layer != null && (Object)(object)_tplSettings != (Object)null)
			{
				F_Layer.SetValue(obj, F_Layer.GetValue(_tplSettings));
			}
			Plugin.Log.LogInfo((object)("Focus seat placed: layer " + SeatLayer + ", id " + F_Id.GetValue(obj)));
			return true;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Focus seat failed: " + ex.Message));
			return false;
		}
	}
}
internal sealed class TpFocusMarker : MonoBehaviour
{
}
internal sealed class FlameWobble : MonoBehaviour
{
	public float Speed = 1f;

	public float Amount = 0.1f;

	public float Phase;

	public float Sway = 5f;

	private Vector3 _s;

	private void Awake()
	{
		//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)
		_s = ((Component)this).transform.localScale;
		Phase += Random.value * 20f;
	}

	private void Update()
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.time * Speed + Phase;
		float num2 = Mathf.PerlinNoise(num * 1.3f, Phase) * 0.6f + Mathf.PerlinNoise(num * 3.1f, Phase + 4f) * 0.4f;
		((Component)this).transform.localScale = new Vector3(_s.x * (1f + (num2 - 0.5f) * Amount), _s.y * (1f + (num2 - 0.5f) * Amount * 2.4f), _s.z * (1f + (num2 - 0.5f) * Amount));
		((Component)this).transform.localRotation = Quaternion.Euler(Mathf.Sin(num * 2.1f) * Sway, 0f, Mathf.Sin(num * 1.7f + 1f) * Sway) * Quaternion.Euler(0f, 0f, 0f);
	}
}
internal sealed class JarFireflies : MonoBehaviour
{
	public Vector3 Center = new Vector3(0f, 0.15f, 0f);

	public Vector3 Radius = new Vector3(0.09f, 0.1f, 0.09f);

	private Transform[] _f;

	private Renderer[] _r;

	private float[] _p;

	public void Init(Transform[] flies)
	{
		_f = flies;
		_r = (Renderer[])(object)new Renderer[flies.Length];
		_p = new float[flies.Length * 7];
		for (int i = 0; i < flies.Length; i++)
		{
			_r[i] = ((Component)flies[i]).GetComponent<Renderer>();
			for (int j = 0; j < 7; j++)
			{
				_p[i * 7 + j] = Random.Range(0f, 6.28f);
			}
		}
	}

	private void Update()
	{
		//IL_00c7: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		if (_f == null)
		{
			return;
		}
		float time = Time.time;
		Vector3 val = default(Vector3);
		for (int i = 0; i < _f.Length; i++)
		{
			if (!((Object)(object)_f[i] == (Object)null))
			{
				int num = i * 7;
				((Vector3)(ref val))..ctor(Mathf.Sin(time * (0.5f + 0.07f * (float)i) + _p[num]) * Radius.x, Mathf.Sin(time * (0.43f + 0.05f * (float)i) + _p[num + 1]) * Radius.y, Mathf.Sin(time * (0.37f + 0.06f * (float)i) + _p[num + 2]) * Radius.z);
				_f[i].localPosition = Center + val;
				float num2 = 0.25f + 0.75f * Mathf.Pow(0.5f + 0.5f * Mathf.Sin(time * (0.9f + 0.13f * (float)i) + _p[num + 3]), 2f);
				GlowBillboard component = ((Component)_f[i]).GetComponent<GlowBillboard>();
				if ((Object)(object)component != (Object)null)
				{
					component.Base = new Color(0.85f, 1f, 0.45f, 0.9f * num2);
				}
				if ((Object)(object)_r[i] != (Object)null)
				{
					_r[i].material.color = new Color(0.85f, 1f, 0.45f, 0.9f * num2);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerFocusController), "Update")]
internal static class FocusListCleanPatch
{
	private static void Prefix(PlayerFocusController __instance)
	{
		try
		{
			if (__instance.FocusAreaControllers != null)
			{
				__instance.FocusAreaControllers.RemoveAll((FocusAreaController x) => (Object)(object)x == (Object)null);
			}
		}
		catch
		{
		}
	}
}
internal static class Dsp
{
	public sealed class Rnd
	{
		private uint _s;

		public Rnd(int seed)
		{
			_s = (uint)(seed * 2654435761u + 12345);
			if (_s == 0)
			{
				_s = 1u;
			}
		}

		public float Next()
		{
			_s ^= _s << 13;
			_s ^= _s >> 17;
			_s ^= _s << 5;
			return (float)(_s & 0xFFFFFF) / 16777216f;
		}

		public float Signed()
		{
			return Next() * 2f - 1f;
		}

		public float Range(float a, float b)
		{
			return a + (b - a) * Next();
		}

		public int Int(int a, int b)
		{
			return a + (int)(Next() * (float)(b - a));
		}
	}

	public sealed class Biquad
	{
		private float b0;

		private float b1;

		private float b2;

		private float a1;

		private float a2;

		private float x1;

		private float x2;

		private float y1;

		private float y2;

		public static Biquad Low(float f, float q, int rate)
		{
			Biquad biquad = new Biquad();
			biquad.Set(0, f, q, rate);
			return biquad;
		}

		public static Biquad High(float f, float q, int rate)
		{
			Biquad biquad = new Biquad();
			biquad.Set(1, f, q, rate);
			return biquad;
		}

		public static Biquad Band(float f, float q, int rate)
		{
			Biquad biquad = new Biquad();
			biquad.Set(2, f, q, rate);
			return biquad;
		}

		public static Biquad Peak(float f, float q, float gainDb, int rate)
		{
			Biquad biquad = new Biquad();
			biquad.Set(3, f, q, rate, gainDb);
			return biquad;
		}

		public void Set(int type, float f, float q, int rate, float gainDb = 0f)
		{
			f = Mathf.Clamp(f, 20f, (float)rate * 0.45f);
			float num = (float)Math.PI * 2f * f / (float)rate;
			float num2 = Mathf.Cos(num);
			float num3 = Mathf.Sin(num);
			float num4 = num3 / (2f * Mathf.Max(0.05f, q));
			float num5 = Mathf.Pow(10f, gainDb / 40f);
			float num6;
			switch (type)
			{
			case 0:
				b0 = (1f - num2) / 2f;
				b1 = 1f - num2;
				b2 = (1f - num2) / 2f;
				num6 = 1f + num4;
				a1 = -2f * num2;
				a2 = 1f - num4;
				break;
			case 1:
				b0 = (1f + num2) / 2f;
				b1 = 0f - (1f + num2);
				b2 = (1f + num2) / 2f;
				num6 = 1f + num4;
				a1 = -2f * num2;
				a2 = 1f - num4;
				break;
			case 2:
				b0 = num4;
				b1 = 0f;
				b2 = 0f - num4;
				num6 = 1f + num4;
				a1 = -2f * num2;
				a2 = 1f - num4;
				break;
			default:
				b0 = 1f + num4 * num5;
				b1 = -2f * num2;
				b2 = 1f - num4 * num5;
				num6 = 1f + num4 / num5;
				a1 = -2f * num2;
				a2 = 1f - num4 / num5;
				break;
			}
			b0 /= num6;
			b1 /= num6;
			b2 /= num6;
			a1 /= num6;
			a2 /= num6;
		}

		public float Process(float x)
		{
			float result = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
			x2 = x1;
			x1 = x;
			y2 = y1;
			y1 = result;
			return result;
		}
	}

	public sealed class Drift
	{
		private readonly Rnd _r;

		private float _a;

		private float _b;

		private float _t;

		private float _len;

		public Drift(int seed, float seconds, int rate)
		{
			_r = new Rnd(seed);
			_len = seconds * (float)rate;
			_a = _r.Signed();
			_b = _r.Signed();
		}

		public float Next()
		{
			_t += 1f;
			if (_t >= _len)
			{
				_t = 0f;
				_a = _b;
				_b = _r.Signed();
			}
			float num = _t / _len;
			num = num * num * (3f - 2f * num);
			return Mathf.Lerp(_a, _b, num);
		}
	}

	public const int Rate = 32000;

	public static void Reverb(float[] buf, float mix, float size, int rate)
	{
		int[] array = new int[4] { 1116, 1188, 1277, 1356 };
		int[] array2 = new int[2] { 225, 556 };
		float num = (float)rate / 44100f * size;
		float[] array3 = new float[buf.Length];
		int[] array4 = array;
		foreach (int num2 in array4)
		{
			int num3 = Mathf.Max(8, (int)((float)num2 * num));
			float[] array5 = new float[num3];
			int num4 = 0;
			float num5 = 0f;
			for (int j = 0; j < buf.Length; j++)
			{
				float num6 = array5[num4];
				num5 += (num6 - num5) * 0.35f;
				array5[num4] = buf[j] + num5 * 0.8f;
				num4 = (num4 + 1) % num3;
				array3[j] += num6 * 0.25f;
			}
		}
		int[] array6 = array2;
		foreach (int num7 in array6)
		{
			int num8 = Mathf.Max(4, (int)((float)num7 * num));
			float[] array7 = new float[num8];
			int num9 = 0;
			for (int l = 0; l < buf.Length; l++)
			{
				float num10 = array7[num9];
				float num11 = (array7[num9] = array3[l] + num10 * 0.5f);
				num9 = (num9 + 1) % num8;
				array3[l] = num10 - num11 * 0.5f;
			}
		}
		for (int m = 0; m < buf.Length; m++)
		{
			buf[m] = buf[m] * (1f - mix * 0.4f) + array3[m] * mix;
		}
	}

	public static float[] Loop(float[] raw, float fadeSeconds, int rate)
	{
		int num = (int)(fadeSeconds * (float)rate);
		int num2 = raw.Length - num;
		float[] array = new float[num2];
		Array.Copy(raw, array, num2);
		for (int i = 0; i < num; i++)
		{
			float num3 = (float)i / (float)num;
			array[i] = array[i] * num3 + raw[num2 + i] * (1f - num3);
		}
		return array;
	}

	public static AudioClip Clip(string name, float[] buf, float peak, int rate)
	{
		float num = 0.0001f;
		for (int i = 0; i < buf.Length; i++)
		{
			num = Mathf.Max(num, Mathf.Abs(buf[i]));
		}
		float num2 = peak / num;
		for (int j = 0; j < buf.Length; j++)
		{
			buf[j] *= num2;
		}
		AudioClip val = AudioClip.Create(name, buf.Length, 1, rate, false);
		val.SetData(buf, 0);
		return val;
	}
}
internal static class Synth
{
	private const int R = 32000;

	private static float Hz(int semitonesFromA2)
	{
		return 110f * Mathf.Pow(2f, (float)semitonesFromA2 / 12f);
	}

	private static void Pluck(float[] buf, int start, float freq, float amp, float seconds, int rate, int seed, bool wrap)
	{
		Dsp.Rnd rnd = new Dsp.Rnd(seed);
		int num = buf.Length;
		int num2 = Mathf.Max(4, Mathf.RoundToInt((float)rate / freq));
		int num3 = (int)(seconds * (float)rate);
		float[] array = new float[num2];
		Dsp.Biquad biquad = Dsp.Biquad.Low(rnd.Range(2200f, 3600f), 0.7f, rate);
		for (int i = 0; i < num2; i++)
		{
			array[i] = biquad.Process(rnd.Signed());
		}
		float num4 = 0.9965f - 0.004f * Mathf.Clamp01(freq / 700f);
		float num5 = 0f;
		int num6 = 0;
		for (int j = 0; j < num3; j++)
		{
			int num7 = (num6 + 1) % num2;
			float num8 = array[num6];
			float num9 = 0.5f * (array[num6] + array[num7]);
			array[num6] = num9 * num4;
			num6 = num7;
			float num10 = num5 + (num8 - num5) * 0.6f;
			num5 = num10;
			float num11 = Mathf.Min(1f, (float)j / 24f) * Mathf.Exp((float)(-j) / ((float)rate * seconds * 0.5f));
			int num12 = start + j;
			if (num12 >= num)
			{
				if (!wrap)
				{
					break;
				}
				num12 %= num;
			}
			buf[num12] += num10 * amp * num11;
		}
	}

	private static void Body(float[] buf, int rate)
	{
		Dsp.Biquad biquad = Dsp.Biquad.Peak(105f, 1.4f, 6f, rate);
		Dsp.Biquad biquad2 = Dsp.Biquad.Peak(210f, 1.8f, 4f, rate);
		Dsp.Biquad biquad3 = Dsp.Biquad.Low(5200f, 0.6f, rate);
		for (int i = 0; i < buf.Length; i++)
		{
			buf[i] = biquad3.Process(biquad2.Process(biquad.Process(buf[i])));
		}
	}

	public static AudioClip Guitar()
	{
		Dsp.Rnd rnd = new Dsp.Rnd(41);
		float num = 0.52f;
		int num2 = 8;
		int num3 = 8;
		int num4 = (int)((float)(num2 * num3) * num * 22050f * 0.5f) + 66150;
		float[] array = new float[num4];
		int[][] array2 = new int[4][]
		{
			new int[5] { 0, 7, 12, 15, 19 },
			new int[5] { -4, 3, 8, 12, 15 },
			new int[5] { -9, -2, 3, 7, 10 },
			new int[5] { -7, 0, 5, 9, 12 }
		};
		int[] array3 = new int[8] { 0, 3, 2, 4, 1, 3, 2, 4 };
		float num5 = 0f;
		for (int i = 0; i < num2; i++)
		{
			int[] array4 = array2[i / 2 % array2.Length];
			for (int j = 0; j < num3; j++)
			{
				float num6 = num5 + rnd.Range(-0.012f, 0.012f);
				int semitonesFromA = array4[array3[j]];
				float amp = ((j == 0) ? 0.6f : ((j % 2 != 0) ? 0.34f : 0.42f)) * rnd.Range(0.85f, 1.1f);
				Pluck(array, Mathf.Max(0, (int)(num6 * 22050f)), Hz(semitonesFromA), amp, 2.6f, 22050, i * 17 + j * 5 + 1, wrap: true);
				if (j == 0)
				{
					Pluck(array, Mathf.Max(0, (int)(num6 * 22050f)), Hz(array4[0] - 12), 0.5f, 3.4f, 22050, i * 7 + 3, wrap: true);
				}
				num5 += num * 0.5f;
			}
		}
		Body(array, 22050);
		Dsp.Reverb(array, 0.28f, 1f, 22050);
		int num7 = (int)((float)(num2 * num3) * num * 0.5f * 22050f);
		float[] array5 = new float[num7];
		Array.Copy(array, array5, num7);
		for (int k = 0; k < num4 - num7 && k < num7; k++)
		{
			array5[k] += array[num7 + k];
		}
		return Dsp.Clip("TP_Guitar", array5, 0.8f, 22050);
	}

	public static AudioClip Campfire()
	{
		Dsp.Rnd rnd = new Dsp.Rnd(77);
		int num = 705600;
		int num2 = num + 88200;
		float[] array = new float[num2];
		int[][] array2 = new int[4][]
		{
			new int[3] { 0, 7, 15 },
			new int[3] { -4, 3, 12 },
			new int[3] { 3, 10, 15 },
			new int[3] { -2, 5, 14 }
		};
		for (int i = 0; i < 4; i++)
		{
			int[] array3 = array2[i];
			foreach (int num3 in array3)
			{
				for (int k = 0; k < 2; k++)
				{
					float num4 = Hz(num3 + 12) * (1f + ((float)k - 0.5f) * 0.004f);
					float num5 = rnd.Next() * 6.28f;
					int num6 = (int)((float)(i * 2) * 4f * 22050f);
					int num7 = 220500;
					for (int l = 0; l < num7; l++)
					{
						float num8 = (float)l / 22050f;
						float num9 = Mathf.SmoothStep(0f, 1f, num8 / 1.6f) * Mathf.SmoothStep(0f, 1f, ((float)num7 / 22050f - num8) / 2f);
						float num10 = num5 + (float)Math.PI * 2f * num4 * num8;
						array[(num6 + l) % num2] += (Mathf.Sin(num10) + 0.18f * Mathf.Sin(2f * num10)) * num9 * 0.045f;
					}
				}
			}
		}
		int[] array4 = new int[7] { 12, 15, 17, 19, 22, 24, 27 };
		int num11 = 3;
		for (float num12 = 0f; num12 < 31.5f; num12 += ((!(rnd.Next() < 0.35f)) ? ((!(rnd.Next() < 0.6f)) ? 2f : 1.5f) : 1f))
		{
			float num13 = rnd.Next();
			if (num13 > 0.18f)
			{
				float num14 = Hz(array4[num11]);
				int num15 = (int)(num12 * 22050f);
				float num16 = 0.5f + 0.25f * rnd.Next();
				for (int m = 0; m < 66150; m++)
				{
					float num17 = (float)m / 22050f;
					float num18 = (1f - Mathf.Exp((0f - num17) * 400f)) * Mathf.Exp((0f - num17) * 2.4f);
					float num19 = Mathf.Sin((float)Math.PI * 2f * num14 * 5.4f * num17) * Mathf.Exp((0f - num17) * 16f) * 0.22f;
					float num20 = (Mathf.Sin((float)Math.PI * 2f * num14 * num17) + 0.12f * Mathf.Sin((float)Math.PI * 4f * num14 * num17) + num19) * num18 * num16 * 0.11f;
					array[(num15 + m) % num2] += num20;
				}
			}
			float num21 = rnd.Next();
			num11 = Mathf.Clamp(num11 + ((!(num21 < 0.3f)) ? ((!(num21 < 0.5f)) ? ((num21 < 0.85f) ? 1 : 2) : 0) : (-1)) * ((rnd.Next() < 0.5f) ? 1 : (-1)), 0, array4.Length - 1);
		}
		Dsp.Biquad biquad = Dsp.Biquad.Low(3200f, 0.6f, 22050);
		for (int n = 0; n < num2; n++)
		{
			array[n] = biquad.Process(array[n]);
		}
		Dsp.Reverb(array, 0.42f, 1.5f, 22050);
		float[] array5 = new float[num];
		Array.Copy(array, array5, num);
		for (int num22 = 0; num22 < num2 - num && num22 < num; num22++)
		{
			array5[num22] += array[num + num22];
		}
		return Dsp.Clip("TP_Campfire", array5, 0.75f, 22050);
	}

	public static AudioClip Pad()
	{
		int num = 793800;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(5);
		int[][] array2 = new int[4][]
		{
			new int[4] { 0, 7, 15, 19 },
			new int[4] { -4, 3, 8, 12 },
			new int[4] { -9, -2, 3, 7 },
			new int[4] { -7, 0, 5, 9 }
		};
		for (int i = 0; i < 4; i++)
		{
			int num2 = i * 9 * 22050;
			int[] array3 = array2[i];
			foreach (int num3 in array3)
			{
				for (int k = 0; k < 3; k++)
				{
					float num4 = Hz(num3 + 12) * (1f + (float)(k - 1) * 0.0035f);
					float num5 = rnd.Next() * 6.28f;
					for (int l = 0; l < 286650; l++)
					{
						float num6 = (float)l / 22050f;
						float num7 = Mathf.SmoothStep(0f, 1f, num6 / 4f) * Mathf.SmoothStep(0f, 1f, (13f - num6) / 4.5f);
						float num8 = num5 + (float)Math.PI * 2f * num4 * num6;
						array[(num2 + l) % num] += (Mathf.Sin(num8) + 0.35f * Mathf.Sin(2f * num8) + 0.12f * Mathf.Sin(3f * num8)) * num7 * 0.05f;
					}
				}
			}
		}
		Dsp.Biquad biquad = Dsp.Biquad.Low(1800f, 0.5f, 22050);
		for (int m = 0; m < num; m++)
		{
			array[m] = biquad.Process(array[m]);
		}
		Dsp.Reverb(array, 0.4f, 1.6f, 22050);
		return Dsp.Clip("TP_Pad", array, 0.65f, 22050);
	}

	public static AudioClip Wind()
	{
		int num = 544000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(3);
		Dsp.Biquad biquad = Dsp.Biquad.Band(400f, 0.7f, 32000);
		Dsp.Biquad biquad2 = Dsp.Biquad.Low(900f, 0.6f, 32000);
		Dsp.Biquad biquad3 = Dsp.Biquad.Band(720f, 9f, 32000);
		Dsp.Drift drift = new Dsp.Drift(1, 2.6f, 32000);
		Dsp.Drift drift2 = new Dsp.Drift(2, 4.1f, 32000);
		Dsp.Drift drift3 = new Dsp.Drift(3, 6f, 32000);
		for (int i = 0; i < num; i++)
		{
			float num2 = Mathf.Clamp01(0.5f + 0.5f * drift.Next() * 0.8f + 0.25f * drift2.Next());
			float f = 260f + 480f * num2;
			if ((i & 0x3F) == 0)
			{
				biquad.Set(2, f, 0.6f, 32000);
				biquad3.Set(2, 640f + 220f * drift3.Next(), 10f, 32000);
			}
			float x = rnd.Signed();
			float num3 = biquad.Process(x) * (0.25f + num2 * 1.1f) + biquad2.Process(x) * 0.25f + biquad3.Process(x) * 0.05f * num2 * num2;
			array[i] = num3;
		}
		return Dsp.Clip("TP_Wind", Dsp.Loop(array, 1.2f, 32000), 0.6f, 32000);
	}

	public static AudioClip Waves()
	{
		int num = 832000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(5);
		float[] array2 = new float[num];
		for (float num2 = 1.5f; num2 < 25f; num2 += rnd.Range(6.5f, 9.5f))
		{
			float num3 = rnd.Range(2.6f, 4.2f);
			float num4 = rnd.Range(4f, 6.5f);
			float num5 = rnd.Range(0.55f, 1f);
			for (int i = 0; (float)i < (num3 + num4) * 32000f; i++)
			{
				int num6 = (int)(num2 * 32000f) + i;
				if (num6 >= num)
				{
					break;
				}
				float num7 = (float)i / 32000f;
				float num8 = ((!(num7 < num3)) ? (Mathf.Exp((0f - (num7 - num3)) * 0.9f) * 1f) : Mathf.Pow(num7 / num3, 2.2f));
				array2[num6] = Mathf.Max(array2[num6], num8 * num5);
			}
		}
		Dsp.Biquad biquad = Dsp.Biquad.Low(500f, 0.7f, 32000);
		Dsp.Biquad biquad2 = Dsp.Biquad.Band(1400f, 0.5f, 32000);
		Dsp.Biquad biquad3 = Dsp.Biquad.High(3000f, 0.7f, 32000);
		float[] array3 = new float[num];
		float num9 = 0f;
		for (int j = 0; j < num; j++)
		{
			num9 = (array3[j] = num9 + (array2[j] - num9) * 0.0006f);
		}
		for (int k = 0; k < num; k++)
		{
			float num10 = array3[k];
			float x = rnd.Signed();
			float num11 = Mathf.Pow(num10, 1.7f);
			array[k] = biquad.Process(x) * (0.15f + num10 * 1.2f) + biquad2.Process(x) * num10 * 0.5f + biquad3.Process(x) * num11 * 0.45f;
		}
		return Dsp.Clip("TP_Waves", Dsp.Loop(array, 2f, 32000), 0.6f, 32000);
	}

	public static AudioClip Crickets()
	{
		int num = 352000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(9);
		for (int i = 0; i < 6; i++)
		{
			float num2 = rnd.Range(4300f, 5200f);
			float num3 = rnd.Range(1.6f, 3.1f);
			float num4 = rnd.Range(3f, 5f);
			float num5 = rnd.Range(0f, 1f);
			float num6 = rnd.Range(0.05f, 0.11f);
			float num7 = rnd.Range(26f, 34f);
			float num8 = 0f;
			float num9 = 0f;
			Dsp.Drift drift = new Dsp.Drift(40 + i, 3f, 32000);
			for (int j = 0; j < num; j++)
			{
				float num10 = (float)j / 32000f;
				float num11 = Mathf.Repeat(num10 * num3 + num5, 1f);
				float num12 = num4 / num7 * num3;
				if (!(num11 > num12))
				{
					float num13 = num11 / num3;
					float num14 = Mathf.Pow(Mathf.Max(0f, Mathf.Sin((float)Math.PI * Mathf.Repeat(num13 * num7, 1f))), 1.5f);
					float num15 = Mathf.Sin((float)Math.PI * Mathf.Clamp01(num11 / num12)) * 0.5f + 0.5f;
					num8 += (float)Math.PI * 2f * num2 * (1f + 0.01f * drift.Next()) / 32000f;
					num9 += (float)Math.PI * 2f * num2 * 2.02f / 32000f;
					array[j] += (Mathf.Sin(num8) + 0.18f * Mathf.Sin(num9)) * num14 * num15 * num6;
				}
			}
		}
		Dsp.Biquad biquad = Dsp.Biquad.High(2500f, 0.7f, 32000);
		for (int k = 0; k < num; k++)
		{
			array[k] = biquad.Process(array[k]);
		}
		Dsp.Reverb(array, 0.12f, 1f, 32000);
		return Dsp.Clip("TP_Crickets", Dsp.Loop(array, 1f, 32000), 0.5f, 32000);
	}

	private static void Tweet(float[] buf, int start, float f0, float f1, float seconds, float amp, float vibrato, int rate)
	{
		int num = (int)(seconds * (float)rate);
		float num2 = 0f;
		float num3 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num4 = (float)i / (float)num;
			float num5 = Mathf.Lerp(f0, f1, num4 * num4 * (3f - 2f * num4)) * (1f + vibrato * Mathf.Sin(num4 * 70f));
			num2 += (float)Math.PI * 2f * num5 / (float)rate;
			num3 += (float)Math.PI * 2f * num5 * 2f / (float)rate;
			float num6 = Mathf.Sin((float)Math.PI * Mathf.Pow(num4, 0.7f));
			num6 *= num6;
			int num7 = start + i;
			if (num7 >= buf.Length)
			{
				break;
			}
			buf[num7] += (Mathf.Sin(num2) + 0.22f * Mathf.Sin(num3)) * num6 * amp;
		}
	}

	public static AudioClip Birds()
	{
		int num = 704000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(11);
		for (float num2 = 0.6f; num2 < 19f; num2 += rnd.Range(1.6f, 4.2f))
		{
			int num3 = (int)(num2 * 32000f);
			int num4 = rnd.Int(0, 4);
			float num5 = rnd.Range(0.1f, 0.2f);
			float num6 = rnd.Range(0.8f, 1.25f);
			switch (num4)
			{
			case 0:
			{
				int j = 0;
				for (int num7 = rnd.Int(2, 5); j < num7; j++)
				{
					Tweet(array, num3 + (int)((float)j * 0.16f * 32000f), 3100f * num6, 4300f * num6, 0.09f, num5, 0.01f, 32000);
				}
				break;
			}
			case 1:
				Tweet(array, num3, 3600f * num6, 2500f * num6, 0.26f, num5, 0f, 32000);
				Tweet(array, num3 + 10880, 3300f * num6, 2200f * num6, 0.34f, num5 * 0.9f, 0f, 32000);
				break;
			case 2:
			{
				for (int i = 0; i < 9; i++)
				{
					Tweet(array, num3 + (int)((float)i * 0.075f * 32000f), rnd.Range(2400f, 4200f) * num6, rnd.Range(2400f, 4200f) * num6, 0.06f, num5 * 0.8f, 0.02f, 32000);
				}
				break;
			}
			default:
				Tweet(array, num3, 2300f * num6, 3900f * num6, 0.14f, num5, 0f, 32000);
				Tweet(array, num3 + 6400, 2600f * num6, 4300f * num6, 0.14f, num5, 0f, 32000);
				break;
			}
		}
		Dsp.Biquad biquad = Dsp.Biquad.Low(6500f, 0.6f, 32000);
		for (int k = 0; k < num; k++)
		{
			array[k] = biquad.Process(array[k]);
		}
		Dsp.Reverb(array, 0.3f, 1.4f, 32000);
		return Dsp.Clip("TP_Birds", array, 0.5f, 32000);
	}

	public static AudioClip Rain()
	{
		int num = 416000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(21);
		Dsp.Biquad biquad = Dsp.Biquad.High(220f, 0.6f, 32000);
		Dsp.Biquad biquad2 = Dsp.Biquad.Low(3600f, 0.5f, 32000);
		Dsp.Biquad biquad3 = Dsp.Biquad.Low(1200f, 0.6f, 32000);
		Dsp.Drift drift = new Dsp.Drift(9, 2.5f, 32000);
		for (int i = 0; i < num; i++)
		{
			float x = rnd.Signed();
			array[i] = biquad2.Process(biquad.Process(x)) * (0.42f + 0.08f * drift.Next()) + biquad3.Process(rnd.Signed()) * 0.18f;
		}
		Dsp.Biquad biquad4 = Dsp.Biquad.Low(2600f, 0.5f, 32000);
		for (int j = 0; j < 2640; j++)
		{
			int num2 = rnd.Int(0, num - 300);
			float num3 = rnd.Range(0.015f, 0.06f);
			int num4 = rnd.Int(30, 140);
			for (int k = 0; k < num4; k++)
			{
				array[num2 + k] += biquad4.Process(rnd.Signed()) * Mathf.Exp((float)(-k) / ((float)num4 * 0.3f)) * num3;
			}
		}
		return Dsp.Clip("TP_Rain", Dsp.Loop(array, 1f, 32000), 0.5f, 32000);
	}

	public static AudioClip Crackle()
	{
		int num = 160000;
		float[] array = new float[num];
		Dsp.Rnd rnd = new Dsp.Rnd(7);
		Dsp.Biquad biquad = Dsp.Biquad.Low(420f, 0.7f, 32000);
		Dsp.Drift drift = new Dsp.Drift(6, 0.8f, 32000);
		Dsp.Biquad biquad2 = Dsp.Biquad.Band(3200f, 0.6f, 32000);
		for (int i = 0; i < num; i++)
		{
			float x = rnd.Signed();
			array[i] = biquad.Process(x) * (0.42f + 0.18f * drift.Next()) + biquad2.Process(x) * 0.025f;
		}
		for (int j = 0; j < 60; j++)
		{
			int num2 = rnd.Int(0, num - 2500);
			float num3 = rnd.Range(0.1f, 0.55f) * ((!(rnd.Next() < 0.12f)) ? 1f : 1.8f);
			int num4 = rnd.Int(40, 900);
			float f = rnd.Range(900f, 3400f);
			Dsp.Biquad biquad3 = Dsp.Biquad.Band(f, rnd.Range(0.7f, 2.4f), 32000);
			for (int k = 0; k < num4; k++)
			{
				array[num2 + k] += biquad3.Process(rnd.Signed()) * Mathf.Exp((float)(-k) / ((float)num4 * 0.16f)) * num3;
			}
		}
		return Dsp.Clip("TP_Crackle", Dsp.Loop(array, 0.6f, 32000), 0.7f, 32000);
	}

	public static AudioClip Chime(string name, float[] freqs, float gap, float decay, float brightness)
	{
		int num = (int)(gap * 44100f);
		int num2 = (int)((float)(num * (freqs.Length - 1)) + decay * 1.6f * 44100f);
		float[] array = new float[num2];
		for (int i = 0; i < freqs.Length; i++)
		{
			int num3 = i * num;
			float num4 = freqs[i];
			float num5 = ((i != freqs.Length - 1) ? 0.8f : 1f);
			float[] array2 = new float[4] { 1f, 2.01f, 2.76f, 4.07f };
			float[] array3 = new float[4]
			{
				1f,
				0.38f * brightness,
				0.16f * brightness,
				0.07f * brightness
			};
			float[] array4 = new float[4] { 1f, 0.7f, 0.45f, 0.25f };
			for (int j = 0; j < 4; j++)
			{
				float num6 = (float)Math.PI * 2f * num4 * array2[j] / 44100f;
				for (int k = 0; num3 + k < num2; k++)
				{
					float num7 = (float)k / 44100f;
					float num8 = Mathf.Min(1f, (float)k / 90f) * Mathf.Exp((0f - num7) / (decay * array4[j] * 0.45f));
					if (num8 < 0.0005f)
					{
						break;
					}
					array[num3 + k] += Mathf.Sin(num6 * (float)k) * array3[j] * num8 * num5 * 0.3f;
				}
			}
		}
		Dsp.Reverb(array, 0.22f, 0.8f, 44100);
		return Dsp.Clip(name, array, 0.5f, 44100);
	}
}
internal static class BoardTools
{
	public enum Tool
	{
		Pen,
		Line,
		Box,
		Oval,
		Text
	}

	private struct Cmd
	{
		public QuadPainterGPU Q;

		public Vector2 A;

		public Vector2 B;

		public int Col;

		public bool Erase;

		public bool Big;

		public bool Self;
	}

	public static Tool Cur = Tool.Pen;

	public static int WidthStep = 0;

	public static bool Fill;

	public static string Text = "";

	public static int TextStep = 1;

	public static bool TextFocus;

	public static Rect PanelA;

	public static Rect PanelB;

	public static Rect GripA;

	public static Rect GripB;

	public static bool PanelDrag;

	private static readonly int[] Widths = new int[4] { 2, 4, 6, 8 };

	private static readonly float[] TextUnits = new float[4] { 2.2f, 3f, 4.2f, 6f };

	private static readonly MethodInfo M_Fill = AccessTools.Method(typeof(QuadPainterGPU), "FillTheBlanks", (Type[])null, (Type[])null);

	private static readonly FieldInfo F_Prev = AccessTools.Field(typeof(QuadPainterGPU), "previousUV");

	private static readonly Queue<Cmd> Queue = new Queue<Cmd>();

	private static bool _loggedSize;

	private static int _announced = -2;

	private static float _announcedAt;

	private static float _hold;

	private static readonly Dictionary<string, KeyValuePair<int, int>> Remote = new Dictionary<string, KeyValuePair<int, int>>();

	private static readonly Dictionary<char, string> Font = BuildFont();

	private static QuadPainterGPU _dragBoard;

	private static Vector2 _a;

	private static Vector2 _b;

	public static Vector2 DragScreenStart;

	private const float SnapStart = 6f;

	private const float SnapBand = 3f;

	private const float SnapBreak = 5f;

	private static bool _penDown;

	private static bool _penBroken;

	private static int _penMode;

	private static Vector2 _penStart;

	private static Vector2 _penLast;

	private static readonly List<Vector2> _penBuf = new List<Vector2>();

	public static int Width => Widths[Mathf.Clamp(WidthStep, 0, 3)];

	public static bool Dragging => (Object)(object)_dragBoard != (Object)null;

	private static Vector2 Cells(QuadPainterGPU q)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		return new Vector2((float)Mathf.Max(1, ((Vector2Int)(ref q.gridSize)).x), (float)Mathf.Max(1, ((Vector2Int)(ref q.gridSize)).y));
	}

	private static Vector2 Clamp(Vector2 v)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		return new Vector2(Mathf.Clamp(v.x, 0.002f, 0.998f), Mathf.Clamp(v.y, 0.002f, 0.998f));
	}

	public static Color PenColor(QuadPainterGPU q)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		DrawingManager mgr = BoardFeature.Mgr;
		try
		{
			if ((Object)(object)mgr != (Object)null && (Object)(object)q != (Object)null)
			{
				return mgr.GetColor(mgr.ChalkIndex, q.IsWhiteBoard);
			}
		}
		catch
		{
		}
		return Color.white;
	}

	public static int NearestBase(int col)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		int baseCount = BoardFeature.BaseCount;
		DrawingManager mgr = BoardFeature.Mgr;
		if (baseCount <= 0 || col < baseCount || (Object)(object)mgr == (Object)null || mgr.BrushColors == null)
		{
			return col;
		}
		int num = col - baseCount;
		if (num >= BoardFeature.Palette.Length)
		{
			return 0;
		}
		Color val = BoardFeature.Palette[num];
		int result = 0;
		float num2 = float.MaxValue;
		for (int i = 0; i < baseCount && i < mgr.BrushColors.Count; i++)
		{
			Color val2 = mgr.BrushColors[i];
			float num3 = (val.r - val2.r) * (val.r - val2.r) * 0.3f + (val.g - val2.g) * (val.g - val2.g) * 0.59f + (val.b - val2.b) * (val.b - val2.b) * 0.11f;
			if (num3 < num2)
			{
				num2 = num3;
				result = i;
			}
		}
		return result;
	}

	public static void OnRemoteColour(string sender, string[] p)
	{
		if (!string.IsNullOrEmpty(sender) && p.Length >= 3 && int.TryParse(p[1], out var result) && int.TryParse(p[2], out var result2))
		{
			if (result < 0)
			{
				Remote.Remove(sender);
			}
			else
			{
				Remote[sender] = new KeyValuePair<int, int>(result2, result);
			}
		}
	}

	public static int Incoming(int col, bool erase, RPCInfo info)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (erase || BoardFeature.BaseCount < 0)
		{
			return col;
		}
		string text = GtNet.SenderSteamId(info);
		if (text != null && Remote.TryGetValue(text, out var value) && value.Key == col && value.Value < BoardFeature.Palette.Length)
		{
			return BoardFeature.BaseCount + value.Value;
		}
		return col;
	}

	public static void Pump()
	{
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: 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_01c0: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: 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_0233: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		if (Time.unscaledTime < _hold)
		{
			return;
		}
		if (_announced >= 0 && Time.unscaledTime - _announcedAt > 20f)
		{
			_announcedAt = Time.unscaledTime;
			GtNet.Send("B|" + _announced + "|" + NearestBase(BoardFeature.BaseCount + _announced));
		}
		while (Queue.Count > 0 && num++ < 24)
		{
			Cmd cmd = Queue.Peek();
			if ((Object)(object)cmd.Q != (Object)null && !cmd.Erase && BoardFeature.BaseCount >= 0)
			{
				int num2 = ((cmd.Col < BoardFeature.BaseCount) ? (-1) : (cmd.Col - BoardFeature.BaseCount));
				if (num2 != _announced && (num2 >= 0 || _announced != -2))
				{
					_announced = num2;
					_announcedAt = Time.unscaledTime;
					GtNet.SendNow("B|" + num2 + "|" + ((num2 < 0) ? (-1) : NearestBase(cmd.Col)));
					_hold = Time.unscaledTime + 0.35f;
					break;
				}
			}
			Cmd cmd2 = Queue.Dequeue();
			if ((Object)(object)cmd2.Q == (Object)null)
			{
				continue;
			}
			try
			{
				Vector2 a = cmd2.A;
				Vector2 b = cmd2.B;
				if (a.x <= 0.0005f)
				{
					a.x = 0.0005f;
				}
				cmd2.Q.FillTheBlanksRPC(b, a, (!cmd2.Erase) ? NearestBase(cmd2.Col) : cmd2.Col, cmd2.Erase, cmd2.Big, default(RPCInfo));
				if (M_Fill != null)
				{
					M_Fill.Invoke(cmd2.Q, new object[6] { b, a, cmd2.Col, cmd2.Erase, cmd2.Big, cmd2.Self });
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Board stroke: " + ex.Message));
				Queue.Clear();
				break;
			}
		}
	}

	private static void Push(QuadPainterGPU q, Vector2 a, Vector2 b, int col, bool erase, bool big, bool self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0062: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Cells(q);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor((b.x - a.x) * val.x, (b.y - a.y) * val.y);
		float magnitude = ((Vector2)(ref val2)).magnitude;
		int num = Mathf.Max(1, Mathf.CeilToInt(magnitude / 20f));
		Vector2 a2 = a;
		for (int i = 1; i <= num; i++)
		{
			Vector2 val3 = Vector2.Lerp(a, b, (float)i / (float)num);
			Queue.Enqueue(new Cmd
			{
				Q = q,
				A = a2,
				B = val3,
				Col = col,
				Erase = erase,
				Big = big,
				Self = self
			});
			a2 = val3;
		}
	}

	private static List<Vector2> Offsets(QuadPainterGPU q, int width)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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)
		Vector2 val = Cells(q);
		List<Vector2> list = new List<Vector2>();
		int num = width / 2;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				if (num < 3 || (i != 0 && i != num - 1) || (j != 0 && j != num - 1))
				{
					float num2 = (float)(i * 2 - (num - 1)) / val.x;
					float num3 = (float)(j * 2 - (num - 1)) / val.y;
					list.Add(new Vector2(num2, num3));
				}
			}
		}
		if (list.Count == 0)
		{
			list.Add(Vector2.zero);
		}
		return list;
	}

	public static void Stroke(QuadPainterGPU q, Vector2 a, Vector2 b, int col, int width)
	{
		//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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		bool self = true;
		foreach (Vector2 item in Offsets(q, width))
		{
			Push(q, Clamp(a + item), Clamp(b + item), col, erase: false, big: false, self);
			self = false;
		}
	}

	public static void Wipe(List<QuadPainterGPU> boards, DrawingManager m)
	{
		//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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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)
		Queue.Clear();
		Vector2 val2 = default(Vector2);
		Vector2 val3 = default(Vector2);
		foreach (QuadPainterGPU board in boards)
		{
			if ((Object)(object)board == (Object)null)
			{
				continue;
			}
			Vector2 val = Cells(board);
			int num = Mathf.Max(1, m.BigEraser);
			float num2 = Mathf.Max(1f, (float)(num + 1) * 0.85f) / val.y;
			bool flag = false;
			float num3 = 0.002f;
			while (true)
			{
				float num4 = Mathf.Min(0.998f, num3);
				((Vector2)(ref val2))..ctor(0.002f, num4);
				((Vector2)(ref val3))..ctor(0.998f, num4);
				Push(board, (!flag) ? val2 : val3, (!flag) ? val3 : val2, 0, erase: true, big: true, self: false);
				flag = !flag;
				if (num3 >= 0.998f)
				{
					break;
				}
				num3 += num2;
			}
		}
	}

	public static List<Vector2> ShapePoints(Tool t, Vector2 a, Vector2 b)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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)
		//IL_00ec: 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_004c: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		List<Vector2> list = new List<Vector2>();
		switch (t)
		{
		case Tool.Line:
			list.Add(a);
			list.Add(b);
			return list;
		case Tool.Box:
			list.Add(new Vector2(a.x, a.y));
			list.Add(new Vector2(b.x, a.y));
			list.Add(new Vector2(b.x, b.y));
			list.Add(new Vector2(a.x, b.y));
			list.Add(new Vector2(a.x, a.y));
			return list;
		default:
		{
			Vector2 val = (a + b) * 0.5f;
			Vector2 val2 = new Vector2(Mathf.Abs(b.x - a.x), Mathf.Abs(b.y - a.y)) * 0.5f;
			int num = 56;
			for (int i = 0; i <= num; i++)
			{
				float num2 = (float)i / (float)num * (float)Math.PI * 2f;
				list.Add(new Vector2(val.x + Mathf.Cos(num2) * val2.x, val.y + Mathf.Sin(num2) * val2.y));
			}
			return list;
		}
		}
	}

	private static void CommitShape(QuadPainterGPU q, Tool t, Vector2 a, Vector2 b, int col)
	{
		//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_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		int width = Width;
		Vector2 val = Cells(q);
		if (Fill && t != Tool.Line)
		{
			float num = Mathf.Min(a.x, b.x);
			float num2 = Mathf.Max(a.x, b.x);
			float num3 = Mathf.Min(a.y, b.y);
			float num4 = Mathf.Max(a.y, b.y);
			float num5 = Mathf.Max(1f, (float)width * 0.9f) / val.y;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((num + num2) * 0.5f, (num3 + num4) * 0.5f);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor((num2 - num) * 0.5f, (num4 - num3) * 0.5f);
			for (float num6 = num3; num6 <= num4 + num5 * 0.5f; num6 += num5)
			{
				float num7 = Mathf.Min(num6, num4);
				if (t == Tool.Box)
				{
					Stroke(q, new Vector2(num, num7), new Vector2(num2, num7), col, width);
					continue;
				}
				float num8 = ((!(val3.y <= 0f)) ? ((num7 - val2.y) / val3.y) : 0f);
				float num9 = val3.x * Mathf.Sqrt(Mathf.Max(0f, 1f - num8 * num8));
				Stroke(q, new Vector2(val2.x - num9, num7), new Vector2(val2.x + num9, num7), col, width);
			}
		}
		List<Vector2> list = ShapePoints(t, a, b);
		for (int i = 1; i < list.Count; i++)
		{
			Stroke(q, list[i - 1], list[i], col, width);
		}
	}

	private static Dictionary<char, string> BuildFont()
	{
		Dictionary<char, string> dictionary = new Dictionary<char, string>();
		dictionary['A'] = "00 26 40/13 33";
		dictionary['B'] = "00 06 36 45 33 03/33 42 41 30 00";
		dictionary['C'] = "41 30 10 01 05 16 36 45";
		dictionary['D'] = "00 06 36 45 41 30 00";
		dictionary['E'] = "40 00 06 46/03 33";
		dictionary['F'] = "00 06 46/03 33";
		dictionary['G'] = "45 36 16 05 01 10 30 41 43 23";
		dictionary['H'] = "00 06/40 46/03 43";
		dictionary['I'] = "10 30/20 26/16 36";
		dictionary['J'] = "16 46/36 31 20 10 01";
		dictionary['K'] = "00 06/46 03 40";
		dictionary['L'] = "06 00 40";
		dictionary['M'] = "00 06 23 46 40";
		dictionary['N'] = "00 06 40 46";
		dictionary['O'] = "10 01 05 16 36 45 41 30 10";
		dictionary['P'] = "00 06 36 45 34 03";
		dictionary['Q'] = "10 01 05 16 36 45 41 30 10/23 40";
		dictionary['R'] = "00 06 36 45 34 03/23 40";
		dictionary['S'] = "45 36 16 05 04 13 33 42 41 30 10 01";
		dictionary['T'] = "06 46/20 26";
		dictionary['U'] = "06 01 10 30 41 46";
		dictionary['V'] = "06 20 46";
		dictionary['W'] = "06 10 23 30 46";
		dictionary['X'] = "00 46/06 40";
		dictionary['Y'] = "06 23 46/23 20";
		dictionary['Z'] = "06 46 00 40";
		dictionary['0'] = "10 01 05 16 36 45 41 30 10/05 41";
		dictionary['1'] = "05 26 20/00 40";
		dictionary['2'] = "05 16 36 45 44 00 40";
		dictionary['3'] = "05 16 36 45 44 33 13/33 42 41 30 10 01";
		dictionary['4'] = "36 03 43/36 30";
		dictionary['5'] = "46 06 03 33 42 41 30 10 01";
		dictionary['6'] = "45 36 16 05 01 10 30 41 42 33 03";
		dictionary['7'] = "06 46 20";
		dictionary['8'] = "13 04 05 16 36 45 44 33 13 02 01 10 30 41 42 33";
		dictionary['9'] = "01 10 30 41 45 36 16 05 04 13 43";
		dictionary['.'] = "00 10";
		dictionary[','] = "10 01";
		dictionary['!'] = "26 23/20 21";
		dictionary['?'] = "05 16 36 45 44 23 22/20 21";
		dictionary['-'] = "02 42";
		dictionary['+'] = "02 42/21 25";
		dictionary['='] = "03 43/01 41";
		dictionary[':'] = "24 25/20 21";
		dictionary['/'] = "00 46";
		dictionary['('] = "30 11 15 36";
		dictionary[')'] = "10 31 35 16";
		dictionary['\''] = "36 35";
		dictionary['"'] = "16 15/36 35";
		dictionary['<'] = "40 03 46";
		dictionary['>'] = "00 43 06";
		dictionary['_'] = "00 40";
		dictionary['#'] = "04 44/02 42/16 10/36 30";
		dictionary['*'] = "20 03 05 16 25 36 45 43 20";
		dictionary['Ä'] = dictionary['A'] + "/17 17/37 37";
		dictionary['Ö'] = dictionary['O'] + "/17 17/37 37";
		dictionary['Ü'] = dictionary['U'] + "/17 17/37 37";
		dictionary[' '] = "";
		return dictionary;
	}

	private static string Prepare(string t)
	{
		return (t ?? "").Replace("ß", "SS").ToUpperInvariant();
	}

	private static void CommitText(QuadPainterGPU q, Vector2 at, int col)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: 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_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		string text = Prepare(Text);
		if (text.Length == 0)
		{
			return;
		}
		Vector2 val = Cells(q);
		float num = TextUnits[Mathf.Clamp(TextStep, 0, 3)];
		float num2 = at.x * val.x;
		float num3 = at.y * val.y;
		int width = Width;
		string text2 = text;
		Vector2 val3 = default(Vector2);
		foreach (char key in text2)
		{
			if (Font.TryGetValue(key, out var value) && value.Length > 0)
			{
				string[] array = value.Split('/');
				foreach (string text3 in array)
				{
					string[] array2 = text3.Split(' ');
					Vector2? val2 = null;
					string[] array3 = array2;
					foreach (string text4 in array3)
					{
						if (text4.Length < 2)
						{
							continue;
						}
						((Vector2)(ref val3))..ctor((num2 + (float)(text4[0] - 48) * num) / val.x, (num3 + (float)(text4[1] - 48) * num) / val.y);
						if (val2.HasValue)
						{
							if (InBoard(val2.Value) && InBoard(val3))
							{
								Stroke(q, val2.Value, val3, col, width);
							}
						}
						else if (array2.Length == 1 && InBoard(val3))
						{
							Stroke(q, val3, val3, col, width);
						}
						val2 = val3;
					}
					if (array2.Length < 2 || !(array2[0] == array2[^1]) || array2.Length == 2)
					{
					}
				}
			}
			num2 += 5.8f * num;
		}
	}

	private static bool InBoard(Vector2 p)
	{
		return p.x > 0.003f && p.x < 0.997f && p.y > 0.003f && p.y < 0.997f;
	}

	public static bool OverPanel()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y);
		return PanelDrag || ((Rect)(ref PanelA)).Contains(val) || ((Rect)(ref PanelB)).Contains(val) || ((Rect)(ref GripA)).Contains(val) || ((Rect)(ref GripB)).Contains(val);
	}

	public static void Update(QuadPainterGPU q)
	{
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: 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_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//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_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: 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_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		if (!q.IsActive)
		{
			return;
		}
		DrawingManager mgr = BoardFeature.Mgr;
		if ((Object)(object)mgr == (Object)null)
		{
			return;
		}
		if (!_loggedSize)
		{
			_loggedSize = true;
			Plugin.Log.LogInfo((object)("Board grid: " + ((Vector2Int)(ref q.gridSize)).x + " x " + ((Vector2Int)(ref q.gridSize)).y + " cells, texture " + q.textureWidth + " x " + q.textureHeight + "."));
		}
		if (TextFocus)
		{
			return;
		}
		bool isEraser = mgr.IsEraser;
		if (!isEraser && !mgr.IsHaveChalk())
		{
			return;
		}
		bool mouseButton = Input.GetMouseButton(0);
		bool mouseButtonDown = Input.GetMouseButtonDown(0);
		bool mouseButtonUp = Input.GetMouseButtonUp(0);
		Tool tool = ((!isEraser) ? Cur : Tool.Pen);
		if (Input.GetMouseButtonDown(1) && (Object)(object)_dragBoard == (Object)(object)q)
		{
			_dragBoard = null;
		}
		bool flag = false;
		Vector2 val = default(Vector2);
		Vector2 val2 = val;
		if ((mouseButton || mouseButtonDown) && !OverPanel())
		{
			try
			{
				var (val3, _) = MonoSingleton<ClickManager>.I.GetMousePosRay();
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(val3, ref val4, float.PositiveInfinity, 1 << LayerMask.NameToLayer("Drawing")) && (Object)(object)((Component)((RaycastHit)(ref val4)).collider).gameObject == (Object)(object)((Component)q).gameObject)
				{
					flag = true;
					val2 = ((RaycastHit)(ref val4)).textureCoord;
				}
			}
			catch
			{
			}
		}
		switch (tool)
		{
		case Tool.Pen:
		{
			Vector2 val5 = (Vector2)F_Prev.GetValue(q);
			if (!isEraser)
			{
				PenStep(q, mgr, flag, val2, mouseButtonDown, mouseButtonUp);
				if (mouseButtonUp)
				{
					val5.x = -1f;
					F_Prev.SetValue(q, val5);
				}
				else if (flag)
				{
					F_Prev.SetValue(q, val2);
				}
				return;
			}
			if (flag)
			{
				int chalkIndex = mgr.ChalkIndex;
				Push(q, val2, (!(val5.x > 0f)) ? val2 : val5, chalkIndex, erase: true, mgr.IsBigEraser, self: false);
				F_Prev.SetValue(q, val2);
			}
			if (mouseButtonUp)
			{
				val5.x = -1f;
				F_Prev.SetValue(q, val5);
			}
			return;
		}
		case Tool.Text:
			if (mouseButtonDown && flag && Text.Length > 0)
			{
				CommitText(q, val2, mgr.ChalkIndex);
			}
			return;
		}
		if (mouseButtonDown && flag)
		{
			_dragBoard = q;
			_a = val2;
			_b = val2;
			DragScreenStart = Vector2.op_Implicit(Input.mousePosition);
			return;
		}
		if (!((Object)(object)_dragBoard == (Object)(object)q))
		{
			return;
		}
		if (flag)
		{
			_b = val2;
		}
		if (!mouseButtonUp)
		{
			return;
		}
		_dragBoard = null;
		if (tool == Tool.Line)
		{
			Vector2 val6 = Cells(q);
			float num = (_b.x - _a.x) * val6.x;
			float num2 = (_b.y - _a.y) * val6.y;
			if (Mathf.Abs(num2) <= 3f && Mathf.Abs(num) > Mathf.Abs(num2))
			{
				_b.y = _a.y;
			}
			else if (Mathf.Abs(num) <= 3f && Mathf.Abs(num2) > Mathf.Abs(num))
			{
				_b.x = _a.x;
			}
		}
		val = _b - _a;
		if (((Vector2)(ref val)).sqrMagnitude > 1E-07f || tool == Tool.Line)
		{
			CommitShape(q, tool, _a, _b, mgr.ChalkIndex);
		}
	}

	public static void Cancel()
	{
		_dragBoard = null;
		_penDown = false;
	}

	private static void PenStep(QuadPainterGPU q, DrawingManager m, bool hitMe, Vector2 uv, bool pressed, bool released)
	{
		//IL_0008: 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_002d: 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_002f: 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_0048: 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_007f: 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_0086: 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_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: 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_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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)
		int chalkIndex = m.ChalkIndex;
		Vector2 val = Cells(q);
		if (pressed && hitMe)
		{
			_penDown = true;
			_penBroken = false;
			_penMode = 0;
			_penStart = (_penLast = uv);
			_penBuf.Clear();
			_penBuf.Add(uv);
			Stroke(q, uv, uv, chalkIndex, Width);
			return;
		}
		if (!_penDown)
		{
			if (hitMe)
			{
				_penDown = true;
				_penBroken = true;
				_penMode = 0;
				_penLast = uv;
				Stroke(q, uv, uv, chalkIndex, Width);
			}
			return;
		}
		if (hitMe)
		{
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((uv.x - _penStart.x) * val.x, (uv.y - _penStart.y) * val.y);
			if (_penMode == 0 && !_penBroken)
			{
				_penBuf.Add(uv);
				if (Mathf.Max(Mathf.Abs(val2.x), Mathf.Abs(val2.y)) >= 6f)
				{
					if (Mathf.Abs(val2.y) <= 3f && Mathf.Abs(val2.x) > Mathf.Abs(val2.y))
					{
						_penMode = 1;
					}
					else if (Mathf.Abs(val2.x) <= 3f && Mathf.Abs(val2.y) > Mathf.Abs(val2.x))
					{
						_penMode = 2;
					}
					else
					{
						_penBroken = true;
					}
					if (_penMode != 0)
					{
						Vector2 val3 = Proj(uv);
						Stroke(q, _penStart, val3, chalkIndex, Width);
						_penLast = val3;
					}
					else
					{
						Flush(q, chalkIndex);
					}
				}
			}
			else if (_penMode != 0)
			{
				float num = ((_penMode != 1) ? Mathf.Abs(val2.x) : Mathf.Abs(val2.y));
				if (num > 5f)
				{
					_penMode = 0;
					_penBroken = true;
					Stroke(q, _penLast, uv, chalkIndex, Width);
					_penLast = uv;
				}
				else
				{
					Vector2 val4 = Proj(uv);
					Stroke(q, _penLast, val4, chalkIndex, Width);
					_penLast = val4;
				}
			}
			else
			{
				Stroke(q, _penLast, uv, chalkIndex, Width);
				_penLast = uv;
			}
		}
		if (released)
		{
			if (_penMode == 0 && !_penBroken)
			{
				Flush(q, chalkIndex);
			}
			_penDown = false;
			_penMode = 0;
			_penBuf.Clear();
		}
	}

	private static Vector2 Proj(Vector2 uv)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		return (_penMode != 1) ? new Vector2(_penStart.x, uv.y) : new Vector2(uv.x, _penStart.y);
	}

	private static void Flush(QuadPainterGPU q, int col)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_004d: 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)
		Vector2 val = _penStart;
		foreach (Vector2 item in _penBuf)
		{
			Stroke(q, val, item, col, Width);
			val = item;
		}
		_penLast = val;
		_penBuf.Clear();
	}

	public static Color DragColor(DrawingManager m)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		QuadPainterGPU dragBoard = _dragBoard;
		return (!((Object)(object)dragBoard != (Object)null)) ? Color.white : PenColor(dragBoard);
	}
}
[HarmonyPatch(typeof(QuadPainterGPU), "FillTheBlanksRPC_Original_2")]
internal static class BoardIncomingPatch
{
	private static void Prefix(ref int colIndex, bool isErase, RPCInfo rpcInfo)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			colIndex = BoardTools.Incoming(colIndex, isErase, rpcInfo);
		}
		catch
		{
		}
	}
}
[HarmonyPatch(typeof(QuadPainterGPU), "Update")]
internal static class BoardUpdatePatch
{
	private static bool Prefix(QuadPainterGPU __instance)
	{
		BoardFeature boardFeature = Plugin.Get<BoardFeature>();
		if (boardFeature == null || !boardFeature.Enabled.Value)
		{
			return true;
		}
		try
		{
			BoardTools.Update(__instance);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("BoardTools: " + ex.Message));
		}
		return false;
	}
}
[HarmonyPatch(typeof(DrawingManager), "Update")]
internal static class BoardTypingPatch
{
	private static bool Prefix()
	{
		return !BoardTools.TextFocus;
	}
}
internal sealed class BoardFeature : Feature
{
	public ConfigEntry<string> PaletteOffset;

	public ConfigEntry<string> ToolsOffset;

	private int _drag;

	private Vector2 _dragMouse;

	private Vector2 _dragFrom;

	private Vector2 _palOff;

	private Vector2 _toolOff;

	private bool _offLoaded;

	public static int BaseCount = -1;

	public static readonly Color[] Palette = Build();

	private int _pick = -1;

	private static readonly FieldInfo F_Parent = AccessTools.Field(typeof(DrawingManager), "_chalkParent");

	private static readonly FieldInfo F_Board = AccessTools.Field(typeof(DrawingManager), "_currentActiveBoard");

	private float _armed;

	private static readonly string[] ToolNames = new string[5] { "Pen", "Line", "Box", "Oval", "Text" };

	public override string Id => "Boards";

	public override string Title => "Board colours";

	public override string Description => "Palette with 48 extra colours and drawing tools for the boards. Players with the mod see the exact colour, players without it the closest chalk colour. Drag the small tab above a panel to move it.";

	public static int ExtraCount => Palette.Length;

	public static DrawingManager Mgr
	{
		get
		{
			try
			{
				return MonoSingleton<DrawingManager>.I;
			}
			catch
			{
				return null;
			}
		}
	}

	protected override void BindSettings(ConfigFile cfg)
	{
		PaletteOffset = Bind(cfg, "PalettePosition", "0,0", "Where you moved the colour palette (share of the screen, x,y). 0,0 = default. Drag the tab above the panel; right-click the tab resets it.");
		ToolsOffset = Bind(cfg, "ToolsPosition", "0,0", "Where you moved the tool bar (share of the screen, x,y). 0,0 = default.");
	}

	private static Vector2 ReadOff(ConfigEntry<string> e)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			string[] array = (e.Value ?? "").Split(',');
			if (array.Length == 2 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
			{
				return new Vector2(result * (float)Screen.width, result2 * (float)Screen.height);
			}
		}
		catch
		{
		}
		return Vector2.zero;
	}

	private static void SaveOff(ConfigEntry<string> e, Vector2 px)
	{
		CultureInfo invariantCulture = CultureInfo.InvariantCulture;
		e.Value = (px.x / (float)Mathf.Max(1, Screen.width)).ToString("0.####", invariantCulture) + "," + (px.y / (float)Mathf.Max(1, Screen.height)).ToString("0.####", invariantCulture);
	}

	private static Rect Shift(Rect r, Vector2 off)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: 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)
		((Rect)(ref r)).position = ((Rect)(ref r)).position + off;
		((Rect)(ref r)).x = Mathf.Clamp(((Rect)(ref r)).x, 4f - ((Rect)(ref r)).width * 0.75f, (float)Screen.width - ((Rect)(ref r)).width * 0.25f);
		((Rect)(ref r)).y = Mathf.Clamp(((Rect)(ref r)).y, 24f, (float)Screen.height - 24f);
		return r;
	}

	private void Grip(Rect panel, int which, float k, ref Vector2 off, ConfigEntry<string> store)
	{
		//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_004e: 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_0062: 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_0091: 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_00a9: 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_00d1: 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)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Invalid comparison between Unknown and I4
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Invalid comparison between Unknown and I4
		//IL_0111: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Invalid comparison between Unknown and I4
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Invalid comparison between Unknown and I4
		//IL_0144: 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_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_01fc: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		float num = 64f * k;
		float num2 = 18f * k;
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref panel)).x + (((Rect)(ref panel)).width - num) * 0.5f, ((Rect)(ref panel)).y - num2 + 3f * k, num, num2);
		if (which == 1)
		{
			BoardTools.GripA = val;
		}
		else
		{
			BoardTools.GripB = val;
		}
		bool flag = ((Rect)(ref val)).Contains(current.mousePosition) || _drag == which;
		GameSkin.Box(val, (!flag) ? GameSkin.Cream : GameSkin.Field, Mathf.RoundToInt(8f * k));
		GUI.Label(val, "•••", GameSkin.Text(Mathf.RoundToInt(12f * k), GameSkin.Line, bold: true, (TextAnchor)4));
		if (((Rect)(ref val)).Contains(current.mousePosition))
		{
			UiBlock.Hover = true;
		}
		if ((int)current.type == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
		{
			if (current.button == 1)
			{
				off = Vector2.zero;
				SaveOff(store, off);
				current.Use();
				return;
			}
			if (current.button == 0)
			{
				_drag = which;
				_dragMouse = current.mousePosition;
				_dragFrom = off;
				current.Use();
			}
		}
		if (_drag == which)
		{
			if ((int)current.type == 3 || (int)current.type == 7 || (int)current.type == 8)
			{
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y);
				off = _dragFrom + (val2 - _dragMouse);
			}
			if ((int)current.rawType == 1 || !Input.GetMouseButton(0))
			{
				_drag = 0;
				SaveOff(store, off);
			}
		}
		BoardTools.PanelDrag = _drag != 0;
	}

	private static Color[] Build()
	{
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		List<Color> list = new List<Color>();
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 12; j++)
			{
				list.Add(Color.HSVToRGB((float)j / 12f, i switch
				{
					0 => 0.35f, 
					1 => 0.85f, 
					_ => 0.9f, 
				}, i switch
				{
					0 => 1f, 
					1 => 0.95f, 
					_ => 0.45f, 
				}));
			}
		}
		string[] array = new string[12]
		{
			"FFFFFF", "E6E6E6", "BFBFBF", "8C8C8C", "595959", "262626", "F5DEB3", "D2A679", "A0693F", "6B4226",
			"FFC0CB", "7FFFD4"
		};
		string[] array2 = array;
		Color item = default(Color);
		foreach (string text in array2)
		{
			ColorUtility.TryParseHtmlString("#" + text, ref item);
			list.Add(item);
		}
		return list.ToArray();
	}

	public static void Extend(DrawingManager m)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)m == (Object)null || m.BrushColors == null)
		{
			return;
		}
		if (BaseCount < 0)
		{
			BaseCount = m.BrushColors.Count;
		}
		while (m.BrushColors.Count < BaseCount + Palette.Length)
		{
			m.BrushColors.Add(Palette[m.BrushColors.Count - BaseCount]);
		}
		if (m.WhiteBrushColors != null)
		{
			while (m.WhiteBrushColors.Count < BaseCount + Palette.Length)
			{
				Color val = Palette[m.WhiteBrushColors.Count - BaseCount];
				m.WhiteBrushColors.Add((Color)((!(((Color)(ref val)).grayscale > 0.92f)) ? val : new Color(0.78f, 0.78f, 0.78f)));
			}
		}
	}

	public override void Tick()
	{
		DrawingManager mgr = Mgr;
		if ((Object)(object)mgr != (Object)null)
		{
			Extend(mgr);
		}
		BoardTools.Pump();
	}

	private void ClearBoard(DrawingManager m)
	{
		QuadPainterGPU val = (QuadPainterGPU)((!(F_Board != null)) ? null : /*isinst with value type is only supported in some contexts*/);
		if ((Object)(object)val == (Object)null)
		{
			Game.Say("Step up to a board first.");
			return;
		}
		List<QuadPainterGPU> list = new List<QuadPainterGPU>();
		list.Add(val);
		List<QuadPainterGPU> list2 = list;
		try
		{
			if (val.isGrid && (Object)(object)((Component)val).transform.parent != (Object)null)
			{
				QuadPainterGPU[] componentsInChildren = ((Component)((Component)val).transform.parent).GetComponentsInChildren<QuadPainterGPU>();
				foreach (QuadPainterGPU val2 in componentsInChildren)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)val)
					{
						list2.Add(val2);
					}
				}
			}
		}
		catch
		{
		}
		BoardTools.Wipe(list2, m);
		Game.Say("Wiping the board...");
	}

	private bool ChalkRect(DrawingManager m, out Rect r)
	{
		//IL_0001: 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_0124: Unknown result type (might be due to invalid IL or missing references)
		r = default(Rect);
		try
		{
			Transform val = (Transform)((!(F_Parent != null)) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val == (Object)null || val.childCount < 6)
			{
				return false;
			}
			bool flag = false;
			float num = 1E+09f;
			float num2 = 1E+09f;
			float num3 = -1E+09f;
			float num4 = -1E+09f;
			for (int i = 0; i < val.childCount; i++)
			{
				Transform child = val.GetChild(i);
				RectTransform val2 = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeInHierarchy && GameSkin.ScreenRect(val2, out var rect))
				{
					flag = true;
					num = Mathf.Min(num, ((Rect)(ref rect)).xMin);
					num2 = Mathf.Min(num2, ((Rect)(ref rect)).yMin);
					num3 = Mathf.Max(num3, ((Rect)(ref rect)).xMax);
					num4 = Mathf.Max(num4, ((Rect)(ref rect)).yMax);
				}
			}
			if (!flag)
			{
				return false;
			}
			r = Rect.MinMaxRect(num, num2, num3, num4);
			return true;
		}
		catch
		{
			return false;
		}
	}

	public override void DrawHUD()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_05ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0645: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: 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_0669: 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_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: 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_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: 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_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0617: Unknown result type (might be due to invalid IL or missing references)
		//IL_060d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0689: Unknown result type (might be due to invalid IL or missing references)
		//IL_067f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Invalid comparison between Unknown and I4
		//IL_069f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0695: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: 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_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: 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_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0557: Unknown result type (might be due to invalid IL or missing references)
		//IL_0574: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (mig