Decompiled source of StashBoard v1.0.0

StashBoard.dll

Decompiled 7 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Sodalite;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace StashBoard;

internal static class AmmoStacks
{
	private static readonly Dictionary<int, float> Diameters;

	public const int MaxPerSlot = 999;

	private static readonly Dictionary<string, int> Table;

	private static readonly Dictionary<int, int> Measured;

	private static readonly Regex Dims;

	static AmmoStacks()
	{
		Diameters = new Dictionary<int, float>();
		Table = new Dictionary<string, int>();
		Measured = new Dictionary<int, int>();
		Dims = new Regex("(\\d+(?:[.,]\\d+)?)\\s*[xX\\u00D7]\\s*(\\d+(?:[.,]\\d+)?)");
		Set(500, "a177Pellet");
		Set(250, "a22Short");
		Set(200, "a22_LR", "a22Long");
		Set(150, "a22WinchesterMagnum", "a25_ACP", "a32ACP", "a32Rimfire", "a41_Short", "a545x18mm", "a5mmBergmann", "a7x20mmNambu", "mf_5mmRivet");
		Set(120, "a380_ACP", "a765x20mmLongue", "a38Rimfire", "a41Volcanic");
		Set(100, "a38ACP", "a9_19_Parabellum", "a9_18_Makarov", "a9x21mmGyurza", "a9mmSteyr", "a9mmBelgian", "a762_25_Tokarev", "a763x25mmMauser", "a765x25mmBorchardt", "a45_ACP", "a455WebleyAuto", "a40_SW", "a10mmAuto", "a357Sig", "a46x30mm", "a57x28mm", "a65CBJ", "a7_5FK", "a8x22mmNambu", "a8mmRoth", "a8mmBergmann", "a44Rimfire", "mf_11mmMannChevski", "mf_10_1mmShhhh");
		Set(60, "a38Special", "a357_Magnum", "a762x38mmR", "a455Webley", "a44_40Winchester", "a38Tround");
		Set(50, "a44_Magnum", "a45_Colt", "a50ActionExpress", "a50_Remington_BP");
		Set(40, "a454Casull");
		Set(30, "a500SW");
		Set(80, "a545_39_Soviet", "a556_45_Nato", "a58x42mm", "a22_250", "a17Hornet", "a22Hornet", "a30Carbine", "a47x33mm");
		Set(70, "a762_39_Soviet", "a792x33mmKurz", "a9x39mm", "a300Blackout", "a762x42mm", "a762x36mm");
		Set(60, "a280British");
		Set(50, "a308_Winchester", "a762_51_Nato", "a243Winchester", "a35Remington");
		Set(40, "a762_54_Mosin", "a3006_Springfield", "a792x57mmMauser", "a303British", "a75x54mmFrench", "a7_5Swiss", "a6_5Swedish", "a65x52mmCarcano", "a7_7x58mmAriska", "a8mmLebel");
		Set(30, "a577_450_MH", "a45_70_Govt");
		Set(20, "a45_110Sharps");
		Set(30, "a300_Winchester_Magnum", "a338Lapua");
		Set(20, "a408Cheytac");
		Set(15, "a50_BMG", "a127_108_AntiMaterial");
		Set(10, "a145_114_AntiMaterial", "acal55boys", "a13_2mmTuF");
		Set(25, "a12g_Shotgun", "a12GaugeBelted", "mf_13Gauge");
		Set(30, "a12gaugeShort", "a16Gauge");
		Set(35, "a20g_Shotgun");
		Set(40, "a410");
		Set(20, "a10gauge");
		Set(15, "a8g_Shotgun", "a23x75mmR", "mf_7GaugeStout");
		Set(5, "a3gauge", "a27x90mm", "a35x32mm", "a40_46_Grenade", "a40x53mmGrenade", "a37mmGrenade", "a40mmCaseless");
		Set(1, "aSturmPistole", "aRPG7Rocket", "aM1A1Rocket", "aPanzerSchreckRocket", "aM72Rocket", "aPanzerFaust3", "a84mmCG", "a67mmGrocket", "aPiatBomb", "aRemoteMissile", "a60mmMortar", "a106_25mmR", "a20x82mm", "aCannon367Inch", "mf_rocket", "mf_42mmNade", "mf_StickyShell", "mf_50mmFlare", "mf_2Gauge", "aGrappleBolt", "aPlungerShell", "aRailPotate", "a50mmPotato", "aFlameThrowerFuel", "aDarkMatterLemon");
	}

	public static float DiameterMm(FVRFireArmRound r)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected I4, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: 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)
		//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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)r == (Object)null)
		{
			return 0f;
		}
		int key = (int)r.RoundType;
		if (Diameters.TryGetValue(key, out var value))
		{
			return value;
		}
		value = 0f;
		try
		{
			HashSet<Transform> hashSet = new HashSet<Transform>();
			if (r.ProxyRounds != null)
			{
				foreach (ProxyRound proxyRound in r.ProxyRounds)
				{
					if (proxyRound != null && (Object)(object)proxyRound.GO != (Object)null)
					{
						hashSet.Add(proxyRound.GO.transform);
					}
				}
			}
			Transform transform = ((Component)r).transform;
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(Vector3.zero, Vector3.zero);
			bool flag = false;
			MeshFilter[] componentsInChildren = ((Component)r).GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val2 in componentsInChildren)
			{
				if ((Object)(object)val2.sharedMesh == (Object)null)
				{
					continue;
				}
				bool flag2 = false;
				Transform val3 = ((Component)val2).transform;
				while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)transform)
				{
					if (hashSet.Contains(val3))
					{
						flag2 = true;
						break;
					}
					val3 = val3.parent;
				}
				if (flag2)
				{
					continue;
				}
				Bounds bounds = val2.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					Vector3 val5 = transform.InverseTransformPoint(((Component)val2).transform.TransformPoint(val4));
					if (!flag)
					{
						((Bounds)(ref val))..ctor(val5, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val)).Encapsulate(val5);
					}
				}
			}
			if (flag)
			{
				float[] array = new float[3]
				{
					((Bounds)(ref val)).size.x,
					((Bounds)(ref val)).size.y,
					((Bounds)(ref val)).size.z
				};
				Array.Sort(array);
				value = array[1] * 1000f;
			}
		}
		catch (Exception)
		{
			value = 0f;
		}
		if (value > 0f)
		{
			Diameters[key] = value;
		}
		return value;
	}

	private static void Set(int n, params string[] names)
	{
		foreach (string key in names)
		{
			Table[key] = n;
		}
	}

	public static int For(FVRFireArmRound r, float realScale, string caliberName)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected I4, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)r == (Object)null)
		{
			return 1;
		}
		if (Table.TryGetValue(((object)Unsafe.As<FireArmRoundType, FireArmRoundType>(ref r.RoundType)/*cast due to .constrained prefix*/).ToString(), out var value))
		{
			return value;
		}
		int key = (int)r.RoundType;
		if (Measured.TryGetValue(key, out value))
		{
			return value;
		}
		string text;
		if (FromName(caliberName, out value))
		{
			text = "from its caliber (" + caliberName + ")";
		}
		else
		{
			value = FromSize(r, realScale);
			text = "from its size";
		}
		Measured[key] = value;
		StashBoardPlugin.Detail(string.Concat("Ammo: ", r.RoundType, " (", caliberName, ") is not in the EFT list; ", value, " per slot ", text, "."));
		return value;
	}

	private static bool FromName(string name, out int n)
	{
		n = 0;
		if (string.IsNullOrEmpty(name))
		{
			return false;
		}
		Match match = Dims.Match(name);
		if (!match.Success)
		{
			return false;
		}
		if (!float.TryParse(match.Groups[1].Value.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
		{
			return false;
		}
		if (!float.TryParse(match.Groups[2].Value.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
		{
			return false;
		}
		if (result < 20f)
		{
			return false;
		}
		if (result >= 30f)
		{
			n = ((!(result <= 45f) || !(result2 <= 60f)) ? 1 : 5);
		}
		else
		{
			n = ((!(result2 >= 80f)) ? 10 : 5);
		}
		return true;
	}

	private static int FromSize(FVRFireArmRound r, float realScale)
	{
		//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_008c: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_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_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: 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)
		try
		{
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(Vector3.zero, Vector3.zero);
			bool flag = false;
			HashSet<Transform> hashSet = new HashSet<Transform>();
			if (r.ProxyRounds != null)
			{
				foreach (ProxyRound proxyRound in r.ProxyRounds)
				{
					if (proxyRound != null && (Object)(object)proxyRound.GO != (Object)null)
					{
						hashSet.Add(proxyRound.GO.transform);
					}
				}
			}
			Matrix4x4 val2 = Matrix4x4.TRS(((Component)r).transform.position, ((Component)r).transform.rotation, Vector3.one);
			Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse;
			MeshFilter[] componentsInChildren = ((Component)r).GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val3 in componentsInChildren)
			{
				if ((Object)(object)val3.sharedMesh == (Object)null)
				{
					continue;
				}
				bool flag2 = false;
				Transform val4 = ((Component)val3).transform;
				while ((Object)(object)val4 != (Object)null && (Object)(object)val4 != (Object)(object)((Component)r).transform)
				{
					if (hashSet.Contains(val4))
					{
						flag2 = true;
						break;
					}
					val4 = val4.parent;
				}
				if (flag2)
				{
					continue;
				}
				Bounds bounds = val3.sharedMesh.bounds;
				Matrix4x4 val5 = inverse * ((Component)val3).transform.localToWorldMatrix;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val6 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					Vector3 val7 = ((Matrix4x4)(ref val5)).MultiplyPoint3x4(val6);
					if (!flag)
					{
						((Bounds)(ref val))..ctor(val7, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val)).Encapsulate(val7);
					}
				}
			}
			if (!flag)
			{
				return 1;
			}
			float[] array = new float[3]
			{
				((Bounds)(ref val)).size.x,
				((Bounds)(ref val)).size.y,
				((Bounds)(ref val)).size.z
			};
			Array.Sort(array);
			float num = ((!(realScale > 0.0001f)) ? 1000f : (1000f / realScale));
			float num2 = array[2] * num;
			float num3 = array[1] * num;
			if (num2 > 150f || num3 > 30f)
			{
				return 1;
			}
			float num4 = num2 * num3 * num3;
			if (num4 < 2600f)
			{
				return Mathf.Clamp(Mathf.RoundToInt(300000f / Mathf.Max(num4, 1f) / 5f) * 5, 100, 999);
			}
			if (num4 < 4500f)
			{
				return 100;
			}
			if (num4 < 6500f)
			{
				return 80;
			}
			if (num4 < 9000f)
			{
				return 70;
			}
			if (num4 < 12000f)
			{
				return 50;
			}
			if (num4 < 18000f)
			{
				return 40;
			}
			if (num4 < 26000f)
			{
				return 30;
			}
			if (num4 < 40000f)
			{
				return 25;
			}
			if (num4 < 70000f)
			{
				return 15;
			}
			return 1;
		}
		catch (Exception)
		{
			return 1;
		}
	}
}
public class Board : MonoBehaviour
{
	private class PendingOpen
	{
		public Vector3 Pos;

		public Quaternion Rot;

		public string GroupName;

		public int Group = -1;

		public int Page = -1;

		public bool Locked;

		public float Since;

		public VaultFile File;

		public VaultObject Marker;
	}

	private class Displayed
	{
		public StashEntry Entry;

		public FVRPhysicalObject Obj;

		public Vector3 OrigScale;

		public float FrontZ = -0.006f;

		public List<FVRPhysicalObject> HiddenContents;

		public bool Lossy;

		public List<BoardPointable> Pointables = new List<BoardPointable>();

		public bool FitChecked;

		public bool PartsDone;

		public GameObject CardHit;
	}

	private class SpawnRequest
	{
		public StashEntry Entry;

		public int Token;

		public bool Done;

		public bool Abandoned;

		public bool Lossy;

		public List<string> Missing = new List<string>();

		public SpawnerIdShim.Token Shim;

		public List<FVRPhysicalObject> Objs;

		public GameObject Anchor;
	}

	private class GhostMesh
	{
		public Mesh Mesh;

		public Vector3 Pos;

		public Quaternion Rot;

		public Vector3 Scale;

		public Material[] Materials;
	}

	private class HandState
	{
		public FVRPhysicalObject LastHeld;

		public BoardButton HoverButton;

		public int HoverFrame = -10;

		public StashEntry SlotEntry;

		public int SlotFrame = -10;

		public int PlaceKind = -1;

		public int PlaceX;

		public int PlaceY;

		public int PlaceW;

		public int PlaceH;

		public StashEntry PlaceStack;

		public FVRPhysicalObject GhostFor;

		public Bounds GhostBounds;

		public Bounds SizeBounds;

		public int BaseW;

		public int BaseH;

		public string StorableReason;

		public GameObject GhostRoot;

		public GameObject GhostRect;

		public Mesh GhostRectMesh;

		public int RectW = -1;

		public int RectH = -1;

		public bool RectValid;

		public GameObject GhostMeshRoot;

		public List<MeshRenderer> GhostMeshRenderers = new List<MeshRenderer>();

		public List<Material> GhostMaterials = new List<Material>();

		public string SizeSource;

		public float LongCm;

		public float ShortCm;

		public float DepthM;

		public string HeadTitle;

		public string HeadSub;

		public bool OverBin;

		public StashEntry MergeTarget;

		public bool Visible;

		public bool Valid;

		public int X;

		public int Y;

		public int W;

		public int H;

		public Quaternion LocalRot;

		public LineRenderer Laser;

		public GameObject LaserDot;
	}

	public class BoardButton
	{
		public string Name;

		public Vector3 LocalPos;

		public Vector2 Size;

		public MeshRenderer Renderer;

		public Action OnPress;

		public bool IsHandle;

		public Transform Root;

		public string Hint;

		public Vector3 Extent;

		public Material LockedMat;

		public HandleMode Mode;

		public bool Hover;

		public bool Lit;

		public int Layer;

		public Material Normal;

		public Material HoverMat;

		public Material LitMat;

		public TextMesh Label;

		public int LastPressFrame = -1;

		public float Pad;
	}

	private enum ModalKind
	{
		None,
		Confirm,
		Options
	}

	public enum HandleMode
	{
		MoveY,
		MoveX,
		Yaw,
		Pitch,
		TableHeight,
		TableSlide
	}

	private enum SlotState
	{
		Loading,
		Loaded,
		Error,
		MissingParts,
		NotShown
	}

	private class SlotText
	{
		public GameObject Go;

		public TextMesh Main;

		public TextMesh Shadow;

		public string Full;

		public float MaxW;

		public int FitPass;

		public int FitFrame;

		public void SetText(string t)
		{
			Main.text = t;
			if ((Object)(object)Shadow != (Object)null)
			{
				Shadow.text = t;
			}
		}
	}

	private class Slot
	{
		public GameObject Fill;

		public Mesh Mesh;

		public List<SlotText> Texts = new List<SlotText>();

		public SlotState State;

		public float W;

		public float H;

		public float CaliberMax;

		public float Pad;

		public float TextZ = -0.0025f;
	}

	private class Remainder
	{
		public StashPage Page;

		public StashEntry From;

		public List<string> Rounds;
	}

	public static Board Current;

	public const string SaveMarkerId = "StashBoard.Board";

	private static PendingOpen _pendingOpen;

	private static VaultFile _lastMarkerFile;

	private static int _lastMarkerFrame = -10;

	private const int QScreenFx = 3000;

	private const int QCells = 3001;

	private const int QCards = 3002;

	private const int QFootprint = 3003;

	private const int QButton = 3004;

	private const int QTextShadow = 3005;

	private const int QText = 3006;

	private const int QGhost = 3010;

	private const int QOverlay = 3090;

	private const int QDialog = 3091;

	private const int QDialogInset = 3092;

	private const int QDialogButton = 3093;

	private const int QDialogText = 3094;

	private const int QTooltip = 3100;

	private const int QTooltipText = 3101;

	private const int QLaser = 3110;

	private int _cols;

	private int _rows;

	private float _cs;

	private float _bw;

	private float _bh;

	private float _fit;

	private float _edge;

	private float _ui;

	private float _gu;

	private int _pageIndex;

	private int _groupIndex;

	private float _scale = 1f;

	private Vector3 _openPos;

	private Quaternion _openRot = Quaternion.identity;

	private int _loadToken;

	private bool _loading;

	private bool _closing;

	private readonly Dictionary<string, Displayed> _displayed = new Dictionary<string, Displayed>();

	private readonly Dictionary<FVRPhysicalObject, Displayed> _displayedByObj = new Dictionary<FVRPhysicalObject, Displayed>();

	private readonly Dictionary<string, Slot> _slots = new Dictionary<string, Slot>();

	private readonly Dictionary<string, List<string>> _missingParts = new Dictionary<string, List<string>>();

	private readonly HashSet<string> _errorEntries = new HashSet<string>();

	private readonly HashSet<string> _lossyEntries = new HashSet<string>();

	private readonly List<SpawnerIdShim.Token> _pendingShims = new List<SpawnerIdShim.Token>();

	private readonly HandState[] _hands = new HandState[2]
	{
		new HandState(),
		new HandState()
	};

	private readonly List<BoardButton> _buttons = new List<BoardButton>();

	private readonly List<BoardButton> _handles = new List<BoardButton>();

	private TextMesh _pageText;

	private string _idleSub;

	private int _idleSubPage = -1;

	private int _idleSubCount = -1;

	private GameObject _pageBarRoot;

	private readonly List<BoardButton> _pageBarButtons = new List<BoardButton>();

	private TextMesh _infoText;

	private TextMesh _headTitle;

	private TextMesh _headSub;

	private Font _font;

	private Material _textMat;

	private Material _textShadowMat;

	private Material _tooltipTextMat;

	private readonly List<Renderer> _textRenderers = new List<Renderer>();

	private bool _textHidden;

	private int _pointLayer = -1;

	private Texture2D _dotTexture;

	private GameObject _tooltipRoot;

	private GameObject _tooltipBack;

	private TextMesh _tooltipText;

	private StashEntry _tooltipEntry;

	private Vector3 _tooltipLocal;

	private int _tooltipFrame = -10;

	private int _dragHand = -1;

	private bool _dragRemote;

	private BoardButton _dragButton;

	private Vector3 _dragStartPos;

	private Vector3 _dragStartHand;

	private Vector3 _dragStartHit;

	private Vector3 _dragRight;

	private Vector3 _dragUp;

	private Quaternion _dragStartRot;

	private Quaternion _dragStartHandRot;

	private Plane _dragPlane;

	private readonly List<BoardButton> _rightHandle = new List<BoardButton>();

	private float _trayGridR;

	private float _trayPanelR;

	private float _trayL;

	private float _trayTop;

	private float _trayBot;

	private float _headMidY;

	private float _headH;

	private GameObject _panelRoot;

	private bool _panelOpen = true;

	private BoardButton _panelButton;

	private Material _matIcon;

	private Material _matHandleKnob;

	private Material _matHandleKnobHover;

	private Material _matGear;

	private Material _matTrashOutline;

	private GameObject _trashHover;

	private Mesh _trashHoverMesh;

	private int _trashHoverW = -1;

	private int _trashHoverH = -1;

	private bool _trashHoverRed;

	private int _optTab;

	private int _setTab;

	private bool _optDdOpen;

	private int _optDdPage;

	private int _setSel;

	private int _sizeSel = -1;

	private int _optScale;

	private int _setPage;

	private int _cardHitLayer = -2;

	private float _modalScale = 1f;

	private BoardButton _resetButton;

	private BoardButton _hintButton;

	private BoardButton _lockButton;

	private bool _controlsLocked;

	private MeshFilter _lockIcon;

	private Mesh _lockClosed;

	private Mesh _lockOpen;

	private Material _matHandleLocked;

	private Material _matTableKnobLocked;

	private float _tableOffset;

	private BoardButton _tableSlide;

	private Vector3 _dragTableStartPos;

	private TextMesh _optTblFwd;

	private Mesh _resetIconDlg;

	private float _barSeg = 0.1f;

	private Material _matDlgIcon;

	private Material _matDlgInset;

	private Material _matDlgButtonLit;

	private Material _matButtonLit;

	private Material _matScreenFx;

	private Material _matBolt;

	private readonly Dictionary<long, Mesh> _buttonMeshes = new Dictionary<long, Mesh>();

	private MeshFilter _panelIcon;

	private Mesh _arrowLeft;

	private Mesh _arrowRight;

	private GameObject _boltsGridRight;

	private Vector3 _dragPivot;

	private string _tooltipMeshId;

	private GameObject _table;

	private BoardButton _tableKnob;

	private BoardButton _tableKnob2;

	private float _tableDrop;

	private float _tableW;

	private float _tableD;

	private int _tableLayer = -1;

	private float _dragTableStartDrop;

	private float _dragTableStartY;

	private Plane _dragTablePlane;

	private Material _matTableTop;

	private Material _matTableKnob;

	private Material _matTableKnobHover;

	private Material _matTableIcon;

	private TextMesh _optTblLen;

	private TextMesh _optTblDepth;

	private TextMesh _optTblDrop;

	private const float TableThick = 0.03f;

	private const float TableKnobSize = 0.14f;

	private const float TableDropMin = -2f;

	private const float TableDropMax = 2f;

	private const float TableOffsetMin = -1.5f;

	private const float TableOffsetMax = 2f;

	private Mesh _triUp;

	private Mesh _triDown;

	private Mesh _triUpDim;

	private Mesh _triDownDim;

	private readonly List<BoardButton> _bottomHandle = new List<BoardButton>();

	private readonly List<float> _bottomHandleOff = new List<float>();

	private bool _kbOpen;

	private string _kbText = string.Empty;

	private bool _kbShift = true;

	private TextMesh _kbField;

	private BoardButton _groupButton;

	private GameObject _dropdownRoot;

	private bool _dropdownOpen;

	private static readonly HashSet<string> _loggedNotStorable = new HashSet<string>();

	private readonly HashSet<string> _containerEntries = new HashSet<string>();

	private int _ddPage;

	private Mesh _ddUp;

	private Mesh _ddDown;

	private Mesh _ddUpDim;

	private Mesh _ddDownDim;

	private float _panelCx;

	private float _panelW;

	private Vector3 _binCenter;

	private Vector2 _binSize;

	private MeshRenderer _binRenderer;

	private Material _matBin;

	private Material _matBinHot;

	private bool _trashMode;

	private BoardButton _trashButton;

	private GameObject _trashFx;

	private Material _matVignette;

	private bool _tooltipTrash;

	private ModalKind _modal;

	private GameObject _modalRoot;

	private Material _matOverlay;

	private Material _matDialog;

	private Material _matDlgButton;

	private Material _matDlgButtonHover;

	private Material _matDlgDanger;

	private Material _dlgTextMat;

	private readonly HashSet<FVRPhysicalObject> _lockedByUs = new HashSet<FVRPhysicalObject>();

	private int _optCols;

	private int _optRows;

	private TextMesh _optColsText;

	private TextMesh _optRowsText;

	private TextMesh _optScaleText;

	private TextMesh _optMsg;

	private Material _matButtonDanger;

	private Mesh _cellMesh;

	private bool _cellsDirty;

	private Material _matCells;

	private Material _matCards;

	private Material _matFootprint;

	private Material _matTooltipVtx;

	private Material _matTray;

	private Material _matFrame;

	private Material _matScreen;

	private Material _matHandle;

	private Material _matHandleHover;

	private Material _matButton;

	private Material _matButtonHover;

	private Material _matLaser;

	private Material _matLaserOn;

	private Material _matLaserDot;

	private Mesh _tooltipMesh;

	private Palette _pal;

	private string _flashText;

	private float _flashUntil;

	private float _tooltipW = -1f;

	private float _tooltipH = -1f;

	private int _tooltipTextFrame;

	private FVRViveHand _retrieveHand;

	private StashEntry _retrieveEntry;

	private static Shader _ghostShader;

	private float _saveAt = -1f;

	private static readonly HashSet<string> _loggedSizes = new HashSet<string>();

	private static Quaternion[] _axisRots;

	private const int MaxGhostMeshes = 96;

	private const float LaserMaxDistance = 25f;

	public const float FarReach = 25f;

	private static FVRSceneSettings _reachScene;

	private static float _reachOrig = -1f;

	private const float LabelCharSize = 0.00124f;

	private const float CaliberCharSize = 0.00106f;

	public const int MaxCols = 50;

	public const int MaxRows = 35;

	public const int MinScale = 10;

	public const int MaxScale = 150;

	private const int DefaultTableDepthCm = 45;

	private const float DefaultTableDrop = 0.14f;

	private const float DefaultTableForward = 0.02f;

	private const float Fillet = 0.05f;

	private static readonly Color CapacityColor = new Color(0.4f, 0.66f, 1f, 1f);

	private const string CaliberFitRef = "5.56x45mm";

	private float _textUnit = -1f;

	private const string Cut = "…";

	private const float WellDepth = 0.2f;

	private const float HousingDepth = 0.22f;

	private const float FrameMidZ = -0.006f;

	private static readonly string[] FaceOrder = new string[6] { "+Z", "-Z", "+X", "-X", "+Y", "-Y" };

	private static readonly HashSet<string> _loggedNested = new HashSet<string>();

	private static MethodInfo _writeVault;

	private static bool _writeVaultLooked;

	private const float OptW = 0.96f;

	private const float OptH = 1f;

	private const float OptRowH = 0.075f;

	private const float OptBtnH = 0.065f;

	private const int SetRowsVisible = 7;

	private static readonly Color ShownSetColor = new Color(0.55f, 0.95f, 0.6f, 1f);

	private const float OptMinusX = -0.08f;

	private const float OptValX = 0.08f;

	private const float OptPlusX = 0.24f;

	private const float OptSepX = 0.33f;

	private const float OptResetX = 0.4f;

	private const int ShownRoundsMax = 5;

	private const int ShownBigRoundsMax = 3;

	private const float BigRoundMm = 24f;

	private static readonly string[] KeyRows = new string[4] { "1234567890", "QWERTYUIOP", "ASDFGHJKL-", "ZXCVBNM_.!" };

	private float _nextLoadedCheck;

	private static readonly Dictionary<string, string> PrettyCalibers = new Dictionary<string, string>
	{
		{ "a46x30mm", "4.6x30mm" },
		{ "a57x28mm", "5.7x28mm" },
		{ "a545x18mm", "5.45x18mm" },
		{ "a47x33mm", "4.7x33mm" },
		{ "a58x42mm", "5.8x42mm" },
		{ "a65x52mmCarcano", "6.5x52mm Carcano" },
		{ "a763x25mmMauser", "7.63x25mm Mauser" },
		{ "a765x25mmBorchardt", "7.65x25mm Borchardt" },
		{ "a765x20mmLongue", "7.65x20mm Longue" },
		{ "a792x57mmMauser", "7.92x57mm Mauser" },
		{ "a792x33mmKurz", "7.92x33mm Kurz" },
		{ "a75x54mmFrench", "7.5x54mm French" },
		{ "a762x38mmR", "7.62x38mmR" },
		{ "a762x42mm", "7.62x42mm" },
		{ "a762x36mm", "7.62x36mm" },
		{ "a7_7x58mmAriska", "7.7x58mm Arisaka" },
		{ "a7_5Swiss", "7.5 Swiss" },
		{ "a6_5Swedish", "6.5 Swedish" },
		{ "a7_5FK", "7.5 FK" },
		{ "a545_39_Soviet", "5.45x39mm" },
		{ "a556_45_Nato", "5.56x45mm" },
		{ "a762_39_Soviet", "7.62x39mm" },
		{ "a762_51_Nato", "7.62x51mm" },
		{ "a762_54_Mosin", "7.62x54mmR" },
		{ "a762_25_Tokarev", "7.62x25mm" },
		{ "a9_19_Parabellum", "9x19mm" },
		{ "a9_18_Makarov", "9x18mm" },
		{ "a127_108_AntiMaterial", "12.7x108mm" },
		{ "a145_114_AntiMaterial", "14.5x114mm" },
		{ "a50_BMG", ".50 BMG" },
		{ "a22_LR", ".22 LR" },
		{ "a22_250", ".22-250" },
		{ "a3006_Springfield", ".30-06" },
		{ "a308_Winchester", ".308 Win" },
		{ "a357_Magnum", ".357 Magnum" },
		{ "a40_SW", ".40 S&W" },
		{ "a44_Magnum", ".44 Magnum" },
		{ "a45_ACP", ".45 ACP" },
		{ "a45_Colt", ".45 Colt" },
		{ "a45_70_Govt", ".45-70" },
		{ "a380_ACP", ".380 ACP" },
		{ "a25_ACP", ".25 ACP" },
		{ "a32ACP", ".32 ACP" },
		{ "a65CBJ", "6.5x25mm CBJ" },
		{ "a10mmAuto", "10mm Auto" },
		{ "a357Sig", ".357 SIG" },
		{ "a9x21mmGyurza", "9x21mm" }
	};

	private readonly List<Remainder> _remainders = new List<Remainder>();

	private static FVRHapticBuzzProfile _hapLight;

	private static FVRHapticBuzzProfile _hapItem;

	private static FVRHapticBuzzProfile _hapGrab;

	private StashData Data => StashBoardPlugin.Store.Data;

	private StashGroup Group => Data.Groups[_groupIndex];

	private StashPage Page => Group.Pages[_pageIndex];

	private float CardRadius => _cs * 0.84f * 0.05f;

	private StashGroup OptSet => Data.Groups[Mathf.Clamp((_sizeSel >= 0) ? _sizeSel : _groupIndex, 0, Data.Groups.Count - 1)];

	public static void Toggle()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		if ((Object)(object)Current != (Object)null)
		{
			Current.CloseBoard();
			return;
		}
		if ((Object)(object)GM.CurrentPlayerBody == (Object)null || (Object)(object)GM.CurrentMovementManager == (Object)null)
		{
			StashBoardPlugin.Log.LogWarning((object)"No player body in this scene; cannot open the board.");
			return;
		}
		GameObject val = new GameObject("StashBoard");
		Board board = val.AddComponent<Board>();
		board.Open();
	}

	public void AddSaveMarker(VaultFile file)
	{
		//IL_00b3: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: 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_011a: 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_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Expected O, but got Unknown
		if (_closing || file.Objects == null)
		{
			return;
		}
		foreach (VaultObject @object in file.Objects)
		{
			if (@object != null && @object.Elements != null && @object.Elements.Count > 0 && @object.Elements[0] != null && @object.Elements[0].ObjectID == "StashBoard.Board")
			{
				return;
			}
		}
		Vector3 position = ((Component)this).transform.position;
		Quaternion rotation = ((Component)this).transform.rotation;
		CultureInfo inv = CultureInfo.InvariantCulture;
		VaultElement val = new VaultElement();
		val.Index = 0;
		val.ObjectID = "StashBoard.Board";
		val.Type = "StashBoard";
		val.PosOffset = position;
		val.OrientationForward = ((Component)this).transform.forward;
		val.OrientationUp = ((Component)this).transform.up;
		val.ObjectAttachedTo = -1;
		val.MountAttachedTo = -1;
		val.LoadedRoundsInChambers = new List<FireArmRoundClass>();
		val.LoadedRoundsInMag = new List<FireArmRoundClass>();
		val.GenericInts = new List<int>
		{
			_groupIndex,
			_pageIndex,
			_controlsLocked ? 1 : 0
		};
		val.GenericStrings = new List<string>
		{
			"StashBoard 1",
			Group.Name,
			string.Join(",", new float[7] { position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, rotation.w }.Select((float f) => f.ToString("R", inv)).ToArray())
		};
		val.GenericVector3s = new List<Vector3> { position };
		val.GenericRotations = new List<Quaternion> { rotation };
		VaultObject val2 = new VaultObject();
		val2.Index = file.Objects.Count;
		val2.IsContainedIn = -1;
		val2.QuickbeltSlotIndex = -1;
		val2.InSlotOfRootObjectIndex = -1;
		val2.InSlotOfElementIndex = -1;
		val2.Elements = new List<VaultElement> { val };
		file.Objects.Add(val2);
		StashBoardPlugin.Log.LogInfo((object)("Scene save: the board is saved with it (" + Group.Name + ", page " + (_pageIndex + 1) + ")."));
	}

	public static void ReadSaveMarker(VaultFile f, bool takeOut, bool clearScene)
	{
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Invalid comparison between Unknown and I4
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		if (f == null || f.Objects == null || (object.ReferenceEquals(f, _lastMarkerFile) && Time.frameCount - _lastMarkerFrame <= 1))
		{
			return;
		}
		int num = -1;
		for (int i = 0; i < f.Objects.Count; i++)
		{
			VaultObject val = f.Objects[i];
			if (val != null && val.Elements != null && val.Elements.Count > 0 && val.Elements[0] != null && val.Elements[0].ObjectID == "StashBoard.Board")
			{
				num = i;
				break;
			}
		}
		if (num < 0)
		{
			if (takeOut && clearScene && (int)f.Type == 3 && (Object)(object)Current != (Object)null && !Current._closing)
			{
				StashBoardPlugin.Log.LogInfo((object)"Scene load: this save was made with the board closed; closing it.");
				Current.CloseBoard();
			}
			return;
		}
		_lastMarkerFile = f;
		_lastMarkerFrame = Time.frameCount;
		VaultElement val2 = f.Objects[num].Elements[0];
		PendingOpen pendingOpen = new PendingOpen();
		pendingOpen.Pos = val2.PosOffset;
		pendingOpen.Since = Time.unscaledTime;
		PendingOpen pendingOpen2 = pendingOpen;
		if (((Vector3)(ref val2.OrientationForward)).sqrMagnitude > 1E-06f && ((Vector3)(ref val2.OrientationUp)).sqrMagnitude > 1E-06f)
		{
			pendingOpen2.Rot = Quaternion.LookRotation(val2.OrientationForward, val2.OrientationUp);
		}
		if (val2.GenericVector3s != null && val2.GenericVector3s.Count > 0)
		{
			pendingOpen2.Pos = val2.GenericVector3s[0];
		}
		if (val2.GenericRotations != null && val2.GenericRotations.Count > 0)
		{
			pendingOpen2.Rot = val2.GenericRotations[0];
		}
		else if (val2.GenericStrings != null && val2.GenericStrings.Count > 2)
		{
			string[] array = val2.GenericStrings[2].Split(new char[1] { ',' });
			float[] array2 = new float[7];
			bool flag = array.Length == 7;
			int num2 = 0;
			while (flag && num2 < 7)
			{
				flag = float.TryParse(array[num2], NumberStyles.Float, CultureInfo.InvariantCulture, out array2[num2]);
				num2++;
			}
			if (flag)
			{
				pendingOpen2.Pos = new Vector3(array2[0], array2[1], array2[2]);
				pendingOpen2.Rot = new Quaternion(array2[3], array2[4], array2[5], array2[6]);
			}
		}
		if (val2.GenericInts != null)
		{
			if (val2.GenericInts.Count > 0)
			{
				pendingOpen2.Group = val2.GenericInts[0];
			}
			if (val2.GenericInts.Count > 1)
			{
				pendingOpen2.Page = val2.GenericInts[1];
			}
			if (val2.GenericInts.Count > 2)
			{
				pendingOpen2.Locked = val2.GenericInts[2] != 0;
			}
		}
		if (val2.GenericStrings != null && val2.GenericStrings.Count > 1)
		{
			pendingOpen2.GroupName = val2.GenericStrings[1];
		}
		if (takeOut)
		{
			pendingOpen2.File = f;
			pendingOpen2.Marker = f.Objects[num];
			f.Objects.RemoveAt(num);
		}
		PutBackMarker(_pendingOpen);
		_pendingOpen = pendingOpen2;
		StashBoardPlugin.Log.LogInfo((object)"Scene load: the board was saved with this scene; it opens where it was once the scene's items are out.");
	}

	private static void PutBackMarker(PendingOpen p)
	{
		if (p != null && p.File != null && p.Marker != null && p.File.Objects != null)
		{
			if (!p.File.Objects.Contains(p.Marker))
			{
				p.File.Objects.Add(p.Marker);
			}
			p.File = null;
			p.Marker = null;
		}
	}

	public static void CancelPendingOpen()
	{
		PutBackMarker(_pendingOpen);
		_pendingOpen = null;
	}

	public static void ProcessPendingOpen()
	{
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		PendingOpen pendingOpen = _pendingOpen;
		if (pendingOpen == null)
		{
			return;
		}
		float num = Time.unscaledTime - pendingOpen.Since;
		if (num > 120f)
		{
			PutBackMarker(pendingOpen);
			_pendingOpen = null;
			StashBoardPlugin.Log.LogWarning((object)"Gave up opening the board from the save (the scene never got ready).");
		}
		else if (!(num < 0.5f) && !SteamVR_LoadLevel.loading && !GM.IsLoadingVaultFile && !((Object)(object)GM.CurrentPlayerBody == (Object)null) && !((Object)(object)GM.CurrentPlayerBody.Head == (Object)null) && !((Object)(object)GM.CurrentMovementManager == (Object)null))
		{
			PutBackMarker(pendingOpen);
			_pendingOpen = null;
			if ((Object)(object)Current != (Object)null)
			{
				Current.CloseBoard();
			}
			GameObject val = new GameObject("StashBoard");
			Board board = val.AddComponent<Board>();
			board.OpenAt(pendingOpen);
		}
	}

	private void OpenAt(PendingOpen p)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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)
		Current = this;
		StashBoardPlugin.ReloadSettings();
		Transform head = GM.CurrentPlayerBody.Head;
		Vector3 forward = head.forward;
		forward.y = 0f;
		if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
		{
			forward = Vector3.forward;
		}
		_openPos = head.position;
		_openRot = Quaternion.LookRotation(((Vector3)(ref forward)).normalized, Vector3.up);
		((Component)this).transform.position = p.Pos;
		((Component)this).transform.rotation = p.Rot;
		int num = -1;
		if (!string.IsNullOrEmpty(p.GroupName))
		{
			num = Data.Groups.FindIndex((StashGroup x) => x.Name == p.GroupName);
		}
		if (num < 0 && p.Group >= 0 && p.Group < Data.Groups.Count)
		{
			num = p.Group;
		}
		if (num < 0)
		{
			num = Data.CurrentGroup;
		}
		Data.CurrentGroup = num;
		_controlsLocked = p.Locked;
		Setup(num, p.Page);
		UpdateTablePose();
		StashBoardPlugin.Log.LogInfo((object)("Board opened from the save (" + Group.Name + ")."));
	}

	public static void SetDisplayedActive(bool active)
	{
		if ((Object)(object)Current == (Object)null)
		{
			return;
		}
		foreach (Displayed value in Current._displayed.Values)
		{
			if ((Object)(object)value.Obj == (Object)null)
			{
				continue;
			}
			if (!active)
			{
				value.HiddenContents = ContentsOf(value.Obj);
			}
			if (value.HiddenContents != null)
			{
				foreach (FVRPhysicalObject hiddenContent in value.HiddenContents)
				{
					if ((Object)(object)hiddenContent != (Object)null)
					{
						((Component)hiddenContent).gameObject.SetActive(active);
					}
				}
			}
			if (active)
			{
				value.HiddenContents = null;
			}
			((Component)value.Obj).gameObject.SetActive(active);
		}
	}

	private void Open()
	{
		//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_0049: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		Current = this;
		StashBoardPlugin.ReloadSettings();
		Transform head = GM.CurrentPlayerBody.Head;
		Vector3 forward = head.forward;
		forward.y = 0f;
		if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
		{
			forward = Vector3.forward;
		}
		((Vector3)(ref forward)).Normalize();
		_openPos = head.position;
		_openRot = Quaternion.LookRotation(forward, Vector3.up);
		float num = Mathf.Clamp(StashBoardPlugin.SpawnDistance.Value, 0.3f, 4f);
		((Component)this).transform.position = _openPos + _openRot * new Vector3(0f, StashBoardPlugin.SpawnHeightOffset.Value, num);
		((Component)this).transform.rotation = _openRot;
		Setup(Data.CurrentGroup, -1);
		float num2 = ((!_panelOpen) ? _trayGridR : _trayPanelR);
		Transform transform = ((Component)this).transform;
		transform.position -= ((Component)this).transform.TransformVector(new Vector3((_trayL + num2) / 2f, 0f, 0f));
		UpdateTablePose();
	}

	private void Setup(int group, int page)
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		Current = this;
		_groupIndex = Mathf.Clamp(group, 0, Data.Groups.Count - 1);
		_cols = SetCols(Group);
		_rows = SetRows(Group);
		_cs = Mathf.Clamp(StashBoardPlugin.CellSizeCm.Value, 1f, 50f) / 100f;
		_fit = Mathf.Clamp(StashBoardPlugin.FitMargin.Value, 0.5f, 1f);
		_edge = _cs * (1f - _fit);
		_bw = (float)_cols * _cs;
		_bh = (float)_rows * _cs;
		_scale = (float)SetScale(Group) / 100f;
		((Component)this).transform.localScale = Vector3.one * _scale;
		_gu = Mathf.Min(_cs, 0.14f) / 0.06f;
		_ui = _gu * Mathf.Min(1f, Mathf.Min((float)_cols / 12f, (float)_rows / 8f));
		_pal = Palette.Get(StashBoardPlugin.PaletteName.Value);
		ChoosePointLayer();
		ExtendPointerReach();
		BuildVisuals();
		LoadTableSettings();
		BuildTable();
		SetControlLock(_controlsLocked);
		_pageIndex = Mathf.Clamp((page < 0) ? Group.LastPage : page, 0, Group.Pages.Count - 1);
		ShowPage(_pageIndex);
	}

	private static int SetCols(StashGroup g)
	{
		return (g == null || g.Cols <= 0) ? Mathf.Clamp(StashBoardPlugin.Columns.Value, 1, 50) : Mathf.Clamp(g.Cols, 4, 50);
	}

	private static int SetRows(StashGroup g)
	{
		return (g == null || g.Rows <= 0) ? Mathf.Clamp(StashBoardPlugin.Rows.Value, 1, 35) : Mathf.Clamp(g.Rows, 3, 35);
	}

	private static int SetScale(StashGroup g)
	{
		return Mathf.Clamp((g == null || g.ScalePercent <= 0) ? StashBoardPlugin.BoardScalePercent.Value : g.ScalePercent, 10, 150);
	}

	private void Rebuild(bool reopenOptions)
	{
		Rebuild(reopenOptions, _groupIndex, _pageIndex);
	}

	private void Rebuild(bool reopenOptions, int g, int pg)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)this).transform.position;
		Quaternion rotation = ((Component)this).transform.rotation;
		Vector3 val = ((Component)this).transform.TransformPoint(BottomCenterLocal());
		Vector3 openPos = _openPos;
		Quaternion openRot = _openRot;
		int optTab = _optTab;
		int sizeSel = _sizeSel;
		int setSel = _setSel;
		int setPage = _setPage;
		int setTab = _setTab;
		bool controlsLocked = _controlsLocked;
		CloseBoard();
		StashBoardPlugin.ReloadSettings();
		GameObject val2 = new GameObject("StashBoard");
		val2.transform.position = position;
		val2.transform.rotation = rotation;
		Board board = val2.AddComponent<Board>();
		board._openPos = openPos;
		board._openRot = openRot;
		board._optTab = optTab;
		board._setTab = setTab;
		board._sizeSel = sizeSel;
		board._setSel = setSel;
		board._setPage = setPage;
		board._controlsLocked = controlsLocked;
		board.Setup(g, pg);
		Transform transform = ((Component)board).transform;
		transform.position += val - ((Component)board).transform.TransformPoint(board.BottomCenterLocal());
		board.UpdateTablePose();
		if (reopenOptions)
		{
			board.OpenOptions();
		}
	}

	public void CloseBoard()
	{
		if (!_closing)
		{
			_closing = true;
			SetItemsLocked(locked: false);
			HidePage();
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)Current == (Object)(object)this)
		{
			Current = null;
		}
		if ((Object)(object)Current == (Object)null)
		{
			RestorePointerReach();
		}
		_loadToken++;
		FlushSave();
		Font.textureRebuilt -= OnFontTextureRebuilt;
		HandState[] hands = _hands;
		foreach (HandState hs in hands)
		{
			DestroyGhost(hs);
		}
		if ((Object)(object)_table != (Object)null)
		{
			Object.Destroy((Object)(object)_table);
		}
		foreach (SpawnerIdShim.Token pendingShim in _pendingShims)
		{
			SpawnerIdShim.Revert(pendingShim);
		}
		_pendingShims.Clear();
	}

	private static void ExtendPointerReach()
	{
		try
		{
			FVRSceneSettings currentSceneSettings = GM.CurrentSceneSettings;
			if (!((Object)(object)currentSceneSettings == (Object)null))
			{
				if ((Object)(object)_reachScene != (Object)(object)currentSceneSettings)
				{
					_reachScene = currentSceneSettings;
					_reachOrig = currentSceneSettings.MaxPointingDistance;
				}
				if (currentSceneSettings.MaxPointingDistance < 25f)
				{
					StashBoardPlugin.Detail("Pointer reach " + _reachOrig.ToString("0.0") + " m -> " + 25f + " m while the board is open.");
					currentSceneSettings.MaxPointingDistance = 25f;
				}
			}
		}
		catch (Exception ex)
		{
			StashBoardPlugin.Log.LogWarning((object)("Could not extend the pointer's reach: " + ex.Message));
		}
	}

	private static void RestorePointerReach()
	{
		try
		{
			if ((Object)(object)_reachScene != (Object)null && _reachOrig >= 0f && (Object)(object)GM.CurrentSceneSettings == (Object)(object)_reachScene)
			{
				_reachScene.MaxPointingDistance = _reachOrig;
			}
		}
		catch (Exception)
		{
		}
		_reachScene = null;
		_reachOrig = -1f;
	}

	private void ChoosePointLayer()
	{
		_pointLayer = -1;
		if (!StashBoardPlugin.LaserPointer.Value || !StashBoardPlugin.UseGamePointer.Value)
		{
			return;
		}
		try
		{
			FVRMovementManager currentMovementManager = GM.CurrentMovementManager;
			if ((Object)(object)currentMovementManager == (Object)null || currentMovementManager.Hands == null || currentMovementManager.Hands.Length == 0 || (Object)(object)currentMovementManager.Hands[0] == (Object)null)
			{
				return;
			}
			int value = ((LayerMask)(ref currentMovementManager.Hands[0].PointingLayerMask)).value;
			int num = -1;
			int num2 = -1;
			List<string> list = new List<string>();
			for (int i = 0; i < 32; i++)
			{
				if ((value & (1 << i)) != 0)
				{
					string text = LayerMask.LayerToName(i) ?? string.Empty;
					list.Add(i + ":" + text);
					string text2 = text.ToLowerInvariant();
					int num3 = 1;
					if (i == 0 || text2 == "default")
					{
						num3 = 0;
					}
					if (text2.Contains("point"))
					{
						num3 += 4;
					}
					if (text2.Contains("ui"))
					{
						num3 += 3;
					}
					if (text2.Contains("interact"))
					{
						num3--;
					}
					if (num3 > num2)
					{
						num2 = num3;
						num = i;
					}
				}
			}
			StashBoardPlugin.Detail("Game pointer layers: " + string.Join(", ", list.ToArray()));
			_pointLayer = num;
			StashBoardPlugin.Detail((num < 0) ? "The game's pointer has no layers; using StashBoard's own laser." : ("Using the game's pointer on layer " + num + " (" + LayerMask.LayerToName(num) + ")"));
		}
		catch (Exception ex)
		{
			_pointLayer = -1;
			StashBoardPlugin.Log.LogWarning((object)("Could not set up the game's pointer, using own laser: " + ex.Message));
		}
	}

	private void AddPointable(GameObject go, BoardPointable.PointKind kind, object target)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		AddPointable(go, kind, target, new Vector3(1f, 1f, 0.02f / Mathf.Max(0.001f, go.transform.lossyScale.z)));
	}

	private void AddPointable(GameObject go, BoardPointable.PointKind kind, object target, Vector3 size)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if (_pointLayer >= 0)
		{
			go.layer = _pointLayer;
			BoxCollider val = go.AddComponent<BoxCollider>();
			((Collider)val).isTrigger = true;
			val.size = size;
			BoardPointable boardPointable = go.AddComponent<BoardPointable>();
			boardPointable.Owner = this;
			boardPointable.Kind = kind;
			boardPointable.Target = target;
			((FVRPointable)boardPointable).MaxPointingRange = 25f;
		}
	}

	private void BuildVisuals()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_0068: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0465: Unknown result type (might be due to invalid IL or missing references)
		//IL_046f: Expected O, but got Unknown
		//IL_06de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0702: Unknown result type (might be due to invalid IL or missing references)
		//IL_0714: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Expected O, but got Unknown
		//IL_074d: Unknown result type (might be due to invalid IL or missing references)
		//IL_077b: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0819: Unknown result type (might be due to invalid IL or missing references)
		//IL_082d: Unknown result type (might be due to invalid IL or missing references)
		//IL_085b: Unknown result type (might be due to invalid IL or missing references)
		//IL_086f: Unknown result type (might be due to invalid IL or missing references)
		//IL_089d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_093d: Unknown result type (might be due to invalid IL or missing references)
		//IL_094e: Unknown result type (might be due to invalid IL or missing references)
		//IL_09af: Unknown result type (might be due to invalid IL or missing references)
		//IL_09ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a02: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a6d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a72: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ad5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b1a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b50: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b84: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bd4: Expected O, but got Unknown
		//IL_0c29: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c4d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cdb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d6b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d97: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dc9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e1c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e56: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e5f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0eba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ec1: Expected O, but got Unknown
		//IL_0ef4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0f32: Unknown result type (might be due to invalid IL or missing references)
		//IL_0faf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fbf: Unknown result type (might be due to invalid IL or missing references)
		//IL_1026: Unknown result type (might be due to invalid IL or missing references)
		//IL_104b: Unknown result type (might be due to invalid IL or missing references)
		//IL_1087: Unknown result type (might be due to invalid IL or missing references)
		//IL_108c: Unknown result type (might be due to invalid IL or missing references)
		//IL_10c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_10cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_10d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_10de: Unknown result type (might be due to invalid IL or missing references)
		//IL_110f: Unknown result type (might be due to invalid IL or missing references)
		//IL_112a: Unknown result type (might be due to invalid IL or missing references)
		//IL_112f: Unknown result type (might be due to invalid IL or missing references)
		//IL_1154: Unknown result type (might be due to invalid IL or missing references)
		//IL_116d: Unknown result type (might be due to invalid IL or missing references)
		//IL_118a: Unknown result type (might be due to invalid IL or missing references)
		//IL_11a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_11aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_11ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_1207: Unknown result type (might be due to invalid IL or missing references)
		//IL_120c: Unknown result type (might be due to invalid IL or missing references)
		//IL_124f: Unknown result type (might be due to invalid IL or missing references)
		//IL_12a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_12b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_12e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_12ec: Expected O, but got Unknown
		//IL_1315: Unknown result type (might be due to invalid IL or missing references)
		//IL_1320: Unknown result type (might be due to invalid IL or missing references)
		//IL_132a: Expected O, but got Unknown
		//IL_137e: Unknown result type (might be due to invalid IL or missing references)
		//IL_1388: Expected O, but got Unknown
		//IL_13e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_1409: Unknown result type (might be due to invalid IL or missing references)
		//IL_1460: Unknown result type (might be due to invalid IL or missing references)
		//IL_1489: Unknown result type (might be due to invalid IL or missing references)
		//IL_14a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_14c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_14d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_14da: Expected O, but got Unknown
		//IL_14fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_156a: Unknown result type (might be due to invalid IL or missing references)
		//IL_156f: Unknown result type (might be due to invalid IL or missing references)
		//IL_15c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_15c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_1626: Unknown result type (might be due to invalid IL or missing references)
		//IL_164c: Unknown result type (might be due to invalid IL or missing references)
		//IL_1671: Unknown result type (might be due to invalid IL or missing references)
		//IL_1676: Unknown result type (might be due to invalid IL or missing references)
		//IL_16b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_16bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_16ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_1704: Unknown result type (might be due to invalid IL or missing references)
		//IL_1759: Unknown result type (might be due to invalid IL or missing references)
		//IL_179a: Unknown result type (might be due to invalid IL or missing references)
		//IL_17b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_1819: Unknown result type (might be due to invalid IL or missing references)
		//IL_1836: Unknown result type (might be due to invalid IL or missing references)
		//IL_1884: Unknown result type (might be due to invalid IL or missing references)
		//IL_18c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_18e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_191d: Unknown result type (might be due to invalid IL or missing references)
		//IL_194e: Unknown result type (might be due to invalid IL or missing references)
		//IL_1994: Unknown result type (might be due to invalid IL or missing references)
		//IL_1999: Unknown result type (might be due to invalid IL or missing references)
		//IL_19a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_19c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_19f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_19fc: Expected O, but got Unknown
		//IL_1a19: Unknown result type (might be due to invalid IL or missing references)
		//IL_1a23: Expected O, but got Unknown
		//IL_1a40: Unknown result type (might be due to invalid IL or missing references)
		//IL_1a4a: Expected O, but got Unknown
		//IL_1a91: Unknown result type (might be due to invalid IL or missing references)
		_matCells = MakeMat(Color.white, 3001);
		_matCards = MakeMat(Color.white, 3002);
		_matFootprint = MakeMat(Color.white, 3003);
		_matTooltipVtx = MakeMat(Color.white, 3100);
		_matTray = MakeSolidMat(_pal.Tray);
		_matFrame = MakeSolidMat(_pal.Frame);
		_matScreen = MakeSolidMat(_pal.Screen);
		_matHandle = MakeSolidMat(Color.Lerp(_pal.Frame, Color.black, 0.45f));
		_matHandleHover = MakeSolidMat(_pal.Accent);
		_matHandleKnob = MakeSolidMat(Color.Lerp(_pal.Frame, Color.white, 0.22f));
		_matHandleKnobHover = MakeSolidMat(Color.Lerp(_pal.Accent, Color.white, 0.15f));
		_matBolt = MakeSolidMat(_pal.Bolt);
		_matButton = MakeMat(Tint(_pal.Button), 3004);
		_matButtonHover = MakeMat(Tint(_pal.Accent * 0.66f), 3004);
		_matButtonLit = MakeMat(Tint(_pal.Accent * 0.56f), 3004);
		_matButtonDanger = MakeMat(Tint(new Color(0.6f, 0.12f, 0.1f)), 3004);
		_matGear = MakeMat(Tint(Color.Lerp(_pal.Button, Color.white, 0.16f)), 3004);
		_matScreenFx = MakeMat(Color.white, 3000);
		_matIcon = MakeMat(Color.white, 3005);
		_matLaser = MakeMat(new Color(0.6f, 0.8f, 1f, 0.35f), 3110);
		_matLaserOn = MakeMat(new Color(0.4f, 0.9f, 1f, 0.9f), 3110);
		_matLaserDot = MakeMat(new Color(0.6f, 0.95f, 1f, 1f), 3111);
		_matLaserDot.mainTexture = (Texture)(object)DotTexture();
		_matBin = MakeMat(Tint(new Color(0.28f, 0.07f, 0.06f)), 3004);
		_matBinHot = MakeMat(Tint(new Color(0.8f, 0.16f, 0.1f)), 3004);
		_matVignette = MakeMat(Color.white, 3003);
		_matTrashOutline = MakeMat(Color.white, 3003);
		_matOverlay = MakeMat(new Color(0f, 0f, 0f, 0.62f), 3090);
		_matDialog = MakeMat(Color.white, 3091);
		_matDlgButton = MakeMat(Tint(Color.Lerp(_pal.Button, Color.white, 0.07f)), 3093);
		_matDlgButtonHover = MakeMat(Tint(_pal.Accent * 0.66f), 3093);
		_matDlgButtonLit = MakeMat(Tint(_pal.Accent * 0.56f), 3093);
		_matDlgDanger = MakeMat(Tint(new Color(0.62f, 0.12f, 0.09f)), 3093);
		_matDlgIcon = MakeMat(Color.white, 3094);
		_matDlgInset = MakeMat(Color.white, 3092);
		_font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
		string text = string.Empty;
		for (int i = 32; i < 127; i++)
		{
			text += (char)i;
		}
		_font.RequestCharactersInTexture(text, 64);
		_font.RequestCharactersInTexture(text, 64, (FontStyle)1);
		_textMat = MakeTextMaterial(3006);
		_textShadowMat = MakeTextMaterial(3005);
		_tooltipTextMat = MakeTextMaterial(3101);
		_dlgTextMat = MakeTextMaterial(3094);
		Font.textureRebuilt += OnFontTextureRebuilt;
		float u = _ui;
		float num = _bw / 2f + 0.006f * u;
		float num2 = _bh / 2f + 0.006f * u;
		float num3 = (0f - _bh) / 2f - 0.006f * u;
		float num4 = Mathf.Max(num, 0.4f * u);
		float num5 = 0.012f * u;
		float fz = -0.006f;
		_headH = 0.075f * u;
		float num6 = num2 + num5 + 0.014f * u;
		float num7 = num6 + _headH;
		_headMidY = (num6 + num7) / 2f;
		_panelW = 0.56f * u;
		float num8 = num4 + num5 + 0.03f * u;
		_panelCx = num8 + _panelW / 2f;
		float num9 = Mathf.Min(num3, num2 - 0.44f * u);
		_trayTop = num7 + num5 + 0.02f * u;
		_trayBot = Mathf.Min(num3 - num5 - 0.02f * u, num9 - num5 - 0.02f * u);
		_trayL = 0f - num4 - 0.029f * u;
		_trayGridR = num4 + num5 + 0.02f * u;
		_trayPanelR = num8 + _panelW + num5 + 0.02f * u;
		float num10 = 0.009f * u;
		AddBolt(new Vector3(_trayL + num10, _trayTop - num10, 0f), null, 0);
		AddBolt(new Vector3(_trayL + num10, _trayBot + num10, 0f), null, 1);
		_boltsGridRight = new GameObject("BoltsGridRight");
		_boltsGridRight.transform.SetParent(((Component)this).transform, false);
		AddBolt(new Vector3(_trayGridR - num10, _trayTop - num10, 0f), _boltsGridRight.transform, 2);
		AddBolt(new Vector3(_trayGridR - num10, _trayBot + num10, 0f), _boltsGridRight.transform, 3);
		float num11 = 0.111f;
		float trayL = _trayL;
		float trayGridR = _trayGridR;
		float trayTop = _trayTop;
		float trayBot = _trayBot;
		MakeCube("TrayTop", new Vector3((trayL + trayGridR) / 2f, (num2 + trayTop) / 2f, num11), new Vector3(trayGridR - trayL, trayTop - num2, 0.22f), _matTray);
		MakeCube("TrayBottom", new Vector3((trayL + trayGridR) / 2f, (trayBot + num3) / 2f, num11), new Vector3(trayGridR - trayL, num3 - trayBot, 0.22f), _matTray);
		MakeCube("TrayLeft", new Vector3((trayL - num) / 2f, (num2 + num3) / 2f, num11), new Vector3(0f - num - trayL, num2 - num3, 0.22f), _matTray);
		MakeCube("TrayRight", new Vector3((num + trayGridR) / 2f, (num2 + num3) / 2f, num11), new Vector3(trayGridR - num, num2 - num3, 0.22f), _matTray);
		MakeCube("WellBack", new Vector3(0f, (num2 + num3) / 2f, 0.211f), new Vector3(num * 2f, num2 - num3, 0.019999996f), _matScreen);
		MakeFrame("Frame", 0f, num, num2, num3, num5, 0.014f, fz, null);
		GameObject val = MakeQuad("Screen", new Vector3(0f, (num2 + num3) / 2f, 0.0005f), new Vector2(num * 2f, num2 - num3), _matScreen);
		((Renderer)val.GetComponent<MeshRenderer>()).enabled = false;
		AddPointable(val, BoardPointable.PointKind.Surface, null);
		GameObject val2 = BuildScreenFx("ScreenFx", null, 0f - num, num3, num, num2, 0.045f * u, null);
		val2.transform.localPosition = new Vector3(0f, 0f, 0.2006f);
		MakeFrame("HeadFrame", 0f, num4, num7, num6, num5, 0.014f, fz, null);
		MakeQuad("HeadScreen", new Vector3(0f, _headMidY, 0.0005f), new Vector2(num4 * 2f, _headH), _matScreen);
		float ax0 = 0f - num4 + 0.01f * u;
		float ay0 = num6 + _headH * 0.18f;
		float ay1 = num7 - _headH * 0.18f;
		Color ac = _pal.Accent;
		BuildScreenFx("HeadFx", null, 0f - num4, num6, num4, num7, 0.016f * u, delegate(List<Vector3> v2, List<Color> c2, List<int> t2)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			AddQuad(v2, c2, t2, ax0, ay0, ax0 + 0.0035f * u, ay1, ac, ac, ac, ac);
		});
		float num12 = 0f - num4 + 0.024f * u;
		_headTitle = MakeText("HeadTitle", new Vector3(num12, num6 + _headH * 0.66f, -0.003f), 0.003f * u, (TextAnchor)3);
		_headTitle.fontStyle = (FontStyle)1;
		_headSub = MakeText("HeadSub", new Vector3(num12, num6 + _headH * 0.27f, -0.003f), 0.0022f * u, (TextAnchor)3);
		_headSub.color = new Color(0.8f, 0.84f, 0.9f, 1f);
		_infoText = MakeText("InfoText", new Vector3(num4 - 0.022f * u, num6 + _headH * 0.27f, -0.003f), 0.002f * u, (TextAnchor)5);
		_infoText.color = new Color(0.72f, 0.75f, 0.8f, 1f);
		_panelRoot = new GameObject("Panel");
		_panelRoot.transform.SetParent(((Component)this).transform, false);
		Transform transform = _panelRoot.transform;
		ToParent(MakeCube("TrayPanel", new Vector3((_trayGridR + _trayPanelR) / 2f, (_trayTop + _trayBot) / 2f, 0.111f), new Vector3(_trayPanelR - _trayGridR, _trayTop - _trayBot, 0.22f), _matTray), transform);
		float headH = _headH;
		float num13 = _panelW - headH - 0.012f * u;
		MakeFrame("SetFrame", _panelCx, _panelW / 2f, num7, num6, num5, 0.014f, fz, transform);
		_groupButton = AddButton(GroupLabel(), new Vector3(num8 + num13 / 2f, _headMidY, -0.002f), new Vector2(num13, _headH), ToggleDropdown, 0, transform);
		SetHitPad(_groupButton, num5 + 0.006f * u);
		_groupButton.Label.anchor = (TextAnchor)3;
		_groupButton.Label.characterSize = 0.003f * u;
		((Component)_groupButton.Label).transform.localPosition = new Vector3(num8 + 0.075f * u, _headMidY, -0.004f);
		MakeMeshObject("SetV", transform, new Vector3(num8 + 0.032f * u, _headMidY, -0.004f), ArrowMesh(0.024f * u, 0.016f * u, 2, new Color(0.92f, 0.93f, 0.9f, 1f)), _matIcon);
		ToParent(MakeQuad("SetSeparator", new Vector3(num8 + 0.058f * u, _headMidY, -0.0035f), new Vector2(0.003f * u, _headH * 0.62f), _matIcon), transform);
		BoardButton boardButton = AddButton(string.Empty, new Vector3(num8 + _panelW - headH / 2f, _headMidY, -0.002f), new Vector2(headH, headH), OpenOptionsFresh, 0, transform);
		boardButton.Hint = "OPTIONS|size, sets, table, ammo";
		SetHitPad(boardButton, num5 * 0.5f);
		boardButton.Normal = _matGear;
		((Renderer)boardButton.Renderer).sharedMaterial = _matGear;
		GameObject val3 = new GameObject("GearIcon");
		val3.transform.SetParent(transform, false);
		val3.transform.localPosition = new Vector3(num8 + _panelW - headH / 2f, _headMidY, -0.004f);
		val3.AddComponent<MeshFilter>().sharedMesh = GearMesh(headH * 0.36f, headH * 0.27f, headH * 0.11f, 8, new Color(0.88f, 0.89f, 0.91f, 1f));
		MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
		((Renderer)val4).sharedMaterial = _matIcon;
		((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val4).receiveShadows = false;
		MakeFrame("PanelFrame", _panelCx, _panelW / 2f, num2, num9, num5, 0.014f, fz, transform);
		GameObject go = MakeQuad("PanelScreen", new Vector3(_panelCx, (num2 + num9) / 2f, 0.0005f), new Vector2(_panelW, num2 - num9), _matScreen);
		ToParent(go, transform);
		AddPointable(go, BoardPointable.PointKind.Surface, null);
		BuildScreenFx("PanelFx", transform, num8, num9, num8 + _panelW, num2, 0.03f * u, null);
		AddBolt(new Vector3(_trayPanelR - num10, _trayTop - num10, 0f), transform, 4);
		AddBolt(new Vector3(_trayPanelR - num10, _trayBot + num10, 0f), transform, 5);
		float num14 = 0.17f * u;
		float num15 = 0.12f * u;
		float num16 = 0.045f * u;
		_binSize = new Vector2(num14, num15);
		_binCenter = new Vector3(num8 + 0.012f * u + num14 / 2f, num9 + 0.012f * u + num15 / 2f, -0.002f);
		GameObject val5 = MakeButtonBody("Bin", _binCenter, _binSize, _matBin);
		ToParent(val5, transform);
		_binRenderer = val5.GetComponent<MeshRenderer>();
		MakeMeshObject("BinIcon", transform, _binCenter + new Vector3(0f, 0.027f * u, -0.003f), TrashIconMesh(0.042f * u, new Color(1f, 0.88f, 0.85f, 0.95f), new Color(0.35f, 0.05f, 0.04f, 0.9f)), _matIcon);
		TextMesh val6 = MakeText("BinLabel", _binCenter + new Vector3(0f, -0.014f * u, -0.003f), 0.0026f * u, (TextAnchor)4);
		val6.text = "TRASH";
		val6.fontStyle = (FontStyle)1;
		ToParent(((Component)val6).gameObject, transform);
		TextMesh val7 = MakeText("BinHelp", _binCenter + new Vector3(0f, -0.04f * u, -0.003f), 0.0013f * u, (TextAnchor)4);
		val7.text = "drop here to delete";
		val7.alignment = (TextAlignment)1;
		val7.color = new Color(1f, 0.82f, 0.78f, 1f);
		ToParent(((Component)val7).gameObject, transform);
		_trashButton = AddButton("TRASH MODE", new Vector3(_binCenter.x, _binCenter.y + num15 / 2f + 0.012f * u + num16 / 2f, -0.002f), new Vector2(num14, num16), ToggleTrashMode, 0, transform);
		_trashButton.LitMat = _matButtonDanger;
		GameObject val8 = new GameObject("Cells");
		val8.transform.SetParent(((Component)this).transform, false);
		val8.transform.localPosition = new Vector3(0f, 0f, -0.0005f);
		_cellMesh = new Mesh();
		((Object)_cellMesh).name = "StashBoardCells";
		val8.AddComponent<MeshFilter>().sharedMesh = _cellMesh;
		MeshRenderer val9 = val8.AddComponent<MeshRenderer>();
		((Renderer)val9).sharedMaterial = _matCells;
		((Renderer)val9).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val9).receiveShadows = false;
		RebuildCells();
		_pageBarRoot = new GameObject("PageBar");
		_pageBarRoot.transform.SetParent(((Component)this).transform, false);
		Transform transform2 = _pageBarRoot.transform;
		_pageBarButtons.Clear();
		float num17 = 0.078f * u;
		float num18 = _trayTop + num17 / 2f;
		ToParent(MakeCube("PageBarTray", new Vector3(0f, num18, 0.111f), new Vector3(num4 * 2f + 0.05f * u, num17, 0.22f), _matTray), transform2);
		List<Vector3> v = new List<Vector3>();
		List<Color> c = new List<Color>();
		List<int> t = new List<int>();
		float w = num4 * 2f + 0.012f * u;
		float h = 0.062f * u;
		AddRoundRect(v, c, t, Vector2.zero, w, h, 0.012f * u, new Color(0f, 0f, 0f, 0.42f), new Color(0f, 0f, 0f, 0.22f), fill: true, 0.0018f * u, new Color(1f, 1f, 1f, 0.06f));
		Mesh val10 = new Mesh();
		ApplyMesh(val10, v, c, t);
		MakeMeshObject("ButtonChannel", transform2, new Vector3(0f, num18, -0.0005f), val10, _matScreenFx);
		Vector2 size = default(Vector2);
		((Vector2)(ref size))..ctor(0.11f * u, 0.045f * u);
		Vector2 size2 = default(Vector2);
		((Vector2)(ref size2))..ctor(0.07f * u, 0.045f * u);
		BoardButton boardButton2 = AddButton("+PAGE", new Vector3(0f - num4 + size.x / 2f, num18, -0.002f), size, AddPage, 0, transform2);
		boardButton2.Label.text = "<size=104>+</size>  PAGE";
		BoardButton boardButton3 = AddButton("-PAGE", new Vector3(0f - num4 + size.x * 1.5f + 0.008f * u, num18, -0.002f), size, DeletePage, 0, transform2);
		boardButton3.Label.text = "<size=104>−</size>  PAGE";
		Color color = default(Color);
		((Color)(ref color))..ctor(0.93f, 0.94f, 0.91f, 1f);
		_arrowLeft = ArrowMesh(0.024f * u, 0.019f * u, 3, color);
		_arrowRight = ArrowMesh(0.024f * u, 0.019f * u, 1, color);
		BoardButton boardButton4 = AddButton(string.Empty, new Vector3(-0.115f * u, num18, -0.002f), size2, delegate
		{
			ChangePage(-1);
		}, 0, transform2);
		AttachIcon(boardButton4, _arrowLeft);
		BoardButton boardButton5 = AddButton(string.Empty, new Vector3(0.115f * u, num18, -0.002f), size2, delegate
		{
			ChangePage(1);
		}, 0, transform2);
		AttachIcon(boardButton5, _arrowRight);
		BoardButton boardButton6 = AddButton("CLOSE", new Vector3(num4 - size.x / 2f, num18, -0.002f), size, CloseBoard, 0, transform2);
		_pageBarButtons.AddRange(new BoardButton[5] { boardButton2, boardButton3, boardButton4, boardButton5, boardButton6 });
		_pageText = MakeText("PageText", new Vector3(0f, num18, -0.003f), 0.003f * u, (TextAnchor)4);
		_pageText.fontStyle = (FontStyle)1;
		ToParent(((Component)_pageText).gameObject, transform2);
		_panelButton = AddButton(string.Empty, Vector3.zero, new Vector2(0.065f * u, 0.065f * u), TogglePanel);
		_panelIcon = AttachIcon(_panelButton, _arrowLeft);
		SetHitPad(_panelButton, 0.03f * u);
		_panelButton.Hint = "FOLD|side panel";
		_resetButton = AddButton(string.Empty, Vector3.zero, new Vector2(0.065f * u, 0.065f * u), ResetAngle);
		AttachIcon(_resetButton, ResetIconMesh(0.019f * u, 0.0045f * u, new Color(0.93f, 0.94f, 0.91f, 1f)));
		SetHitPad(_resetButton, 0.02f * u);
		_resetButton.Hint = "RESET TILT|stand upright";
		_lockButton = AddButton(string.Empty, Vector3.zero, new Vector2(0.065f * u, 0.065f * u), ToggleControlLock);
		_lockClosed = PadlockMesh(0.042f * u, closed: true, new Color(0.93f, 0.94f, 0.91f, 1f));
		_lockOpen = PadlockMesh(0.042f * u, closed: false, new Color(0.93f, 0.94f, 0.91f, 1f));
		_lockIcon = AttachIcon(_lockButton, _lockOpen);
		SetHitPad(_lockButton, 0.02f * u);
		_matHandleLocked = MakeSolidMat(Color.Lerp(_pal.Frame, Color.black, 0.65f));
		_matTableKnobLocked = MakeMat(new Color(0.5f, 0.5f, 0.5f, 0.1f), 3007);
		BuildHandles();
		BuildTrashEffects(num, num2, num3);
		_tooltipRoot = new GameObject("Tooltip");
		_tooltipRoot.transform.SetParent(((Component)this).transform, false);
		_tooltipBack = new GameObject("TooltipBack");
		_tooltipBack.transform.SetParent(_tooltipRoot.transform, false);
		_tooltipMesh = new Mesh();
		_tooltipBack.AddComponent<MeshFilter>().sharedMesh = _tooltipMesh;
		MeshRenderer val11 = _tooltipBack.AddComponent<MeshRenderer>();
		((Renderer)val11).sharedMaterial = _matTooltipVtx;
		((Renderer)val11).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val11).receiveShadows = false;
		_tooltipText = MakeText("TooltipText", Vector3.zero, 0.0024f * u, (TextAnchor)3);
		((Renderer)((Component)_tooltipText).GetComponent<MeshRenderer>()).sharedMaterial = _tooltipTextMat;
		((Component)_tooltipText).transform.SetParent(_tooltipRoot.transform, false);
		_tooltipRoot.SetActive(false);
		_panelOpen = StashBoardPlugin.PanelOpen.Value;
		ApplyPanelLayout();
	}

	private static void ToParent(GameObject go, Transform parent)
	{
		if ((Object)(object)go != (Object)null && (Object)(object)parent != (Object)null)
		{
			go.transform.SetParent(parent, true);
		}
	}

	private void BuildHandles()
	{
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: 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)
		float ui = _ui;
		float num = 0.03f * ui;
		float num2 = 0.05f * ui;
		float num3 = 0.008f * ui;
		float num4 = (_trayTop + _trayBot) / 2f;
		float num5 = Mathf.Min(Mathf.Max(_trayTop - _trayBot, 0.3f * ui) * 0.6f, 0.44f * ui);
		float num6 = _headMidY - 0.065f * ui * 2.5f - 0.014f * ui * 2f - 0.02f * ui;
		num5 = Mathf.Max(0.2f * ui, Mathf.Min(num5, 2f * (num6 - num4)));
		float num7 = Mathf.Max(0.05f * ui, (num5 - num2 - num3 * 2f) / 2f);
		float num8 = num2 / 2f + num3 + num7 / 2f;
		_barSeg = num7;
		for (int i = 0; i < 2; i++)
		{
			float num9 = ((i != 0) ? 0f : (_trayL - num / 2f - 0.006f * ui));
			List<BoardButton> list = ((i != 1) ? null : _rightHandle);
			AddHandlePart("HandleUp", new Vector3(num9, num4 + num8, 0.012f), new Vector3(num, num7, 0.03f), HandleMode.MoveY, 0, list, 0f);
			AddHandlePart("HandleTilt", new Vector3(num9, num4, 0.012f), new Vector3(num, num2, 0.03f), HandleMode.Pitch, 0, list, 0f);
			AddHandlePart("HandleDown", new Vector3(num9, num4 - num8, 0.012f), new Vector3(num, num7, 0.03f), HandleMode.MoveY, 2, list, 0f);
		}
		float num10 = Mathf.Min(Mathf.Max(_trayGridR - _trayL, 0.6f * ui) * 0.6f, 0.58f * ui);
		float num11 = Mathf.Max(0.05f * ui, (num10 - num2 - num3 * 2f) / 2f);
		float num12 = num2 / 2f + num3 + num11 / 2f;
		float num13 = _trayBot - num / 2f - 0.006f * ui;
		AddHandlePart("HandleLeft", new Vector3(0f - num12, num13, 0.012f), new Vector3(num11, num, 0.03f), HandleMode.MoveX, 3, _bottomHandle, 0f - num12);
		AddHandlePart("HandleTurn", new Vector3(0f, num13, 0.012f), new Vector3(num2, num, 0.03f), HandleMode.Yaw, 0, _bottomHandle, 0f);
		AddHandlePart("HandleRight", new Vector3(num12, num13, 0.012f), new Vector3(num11, num, 0.03f), HandleMode.MoveX, 1, _bottomHandle, num12);
	}

	private void AddHandlePart(string name, Vector3 pos, Vector3 size, HandleMode mode, int dir, List<BoardButton> group, float offX)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0499: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Expected O, but got Unknown
		//IL_02ed: 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_02f1: 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_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		float ui = _ui;
		bool flag = mode == HandleMode.Yaw || mode == HandleMode.Pitch;
		GameObject val = new GameObject(name);
		val.transform.SetParent(((Component)this).transform, false);
		val.transform.localPosition = pos;
		List<Vector3> v = new List<Vector3>();
		List<Color> c = new List<Color>();
		List<int> t = new List<int>();
		GameObject val2;
		Vector3 one;
		Mesh val4;
		if (flag)
		{
			val2 = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val2).name = name + "Knob";
			Collider component = val2.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localScale = size;
			one = Vector3.one;
			float num = Mathf.Min(size.x, size.y) * 0.25f;
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.1f, 0.11f, 0.1f, 0.92f);
			AddQuad(v, c, t, 0f - num, 0f - num, num, num, val3, val3, val3, val3);
			val4 = new Mesh();
			ApplyMesh(val4, v, c, t);
		}
		else
		{
			val2 = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val2).name = name + "Bar";
			Collider component2 = val2.GetComponent<Collider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localScale = size;
			one = Vector3.one;
			bool flag2 = size.y > size.x;
			float num2 = ((!flag2) ? size.x : size.y);
			float num3 = ((!flag2) ? size.y : size.x);
			AddArrow(v, c, t, Vector2.zero, num3 * 0.55f, num3 * 0.42f, dir, new Color(0.9f, 0.91f, 0.88f, 0.95f));
			float num4 = ((dir != 0 && dir != 1) ? (-1f) : 1f);
			Color val5 = default(Color);
			((Color)(ref val5))..ctor(0f, 0f, 0f, 0.45f);
			for (int i = 0; i < ((num2 > 0.08f * ui) ? 3 : 0); i++)
			{
				float num5 = num4 * (num2 / 2f - 0.012f * ui - (float)i * 0.008f * ui);
				float num6 = num3 * 0.3f;
				float num7 = 0.0022f * ui;
				if (flag2)
				{
					AddQuad(v, c, t, 0f - num6, num5 - num7 / 2f, num6, num5 + num7 / 2f, val5, val5, val5, val5);
				}
				else
				{
					AddQuad(v, c, t, num5 - num7 / 2f, 0f - num6, num5 + num7 / 2f, num6, val5, val5, val5, val5);
				}
			}
			val4 = new Mesh();
			ApplyMesh(val4, v, c, t);
		}
		MeshRenderer component3 = val2.GetComponent<MeshRenderer>();
		((Renderer)component3).sharedMaterial = ((!flag) ? _matHandle : _matHandleKnob);
		((Renderer)component3).shadowCastingMode = (ShadowCastingMode)0;
		MakeMeshObject(name + "Face", val.transform, new Vector3(0f, 0f, (0f - size.z) / 2f - 0.0015f), val4, _matIcon);
		BoardButton boardButton = new BoardButton();
		boardButton.Name = name;
		boardButton.LocalPos = new Vector3(pos.x, pos.y, -0.002f);
		boardButton.Size = new Vector2(size.x, size.y);
		boardButton.Renderer = component3;
		boardButton.IsHandle = true;
		boardButton.Mode = mode;
		boardButton.Root = val.transform;
		boardButton.Normal = ((!flag) ? _matHandle : _matHandleKnob);
		boardButton.HoverMat = ((!flag) ? _matHandleHover : _matHandleKnobHover);
		boardButton.LockedMat = _matHandleLocked;
		BoardButton boardButton2 = boardButton;
		_handles.Add(boardButton2);
		group?.Add(boardButton2);
		if (group == _bottomHandle)
		{
			_bottomHandleOff.Add(offX);
		}
		AddPointable(val2, BoardPointable.PointKind.Handle, boardButton2, one);
	}

	private Vector3 FlatForward()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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)
		Vector3 val = ((Component)this).transform.forward;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
		{
			val = ((Component)this).transform.up;
			val.y = 0f;
		}
		if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
		{
			val = Vector3.forward;
		}
		return ((Vector3)(ref val)).normalized;
	}

	private static float PointerPlaneY(FVRViveHand hand, Plane plane, float fallback)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0029: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((HandInput)(ref hand.Input)).OneEuroPointingPos, hand.Input.OneEuroPointRotation * Vector3.forward);
		float num = default(float);
		if (((Plane)(ref plane)).Raycast(val, ref num) && num > 0f && num < 12f)
		{
			return ((Ray)(ref val)).GetPoint(num).y;
		}
		return fallback;
	}

	private static Vector3 PointerPlanePoint(FVRViveHand hand, Plane plane, Vector3 fallback)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((HandInput)(ref hand.Input)).OneEuroPointingPos, hand.Input.OneEuroPointRotation * Vector3.forward);
		float num = default(float);
		if (((Plane)(ref plane)).Raycast(val, ref num) && num > 0f && num < 12f)
		{
			return ((Ray)(ref val)).GetPoint(num);
		}
		return fallback;
	}

	private bool TableEnabledSetting()
	{
		return TableEnabledSetting(Group);
	}

	private static bool TableEnabledSetting(StashGroup g)
	{
		return g.TableOn > 0 || (g.TableOn == 0 && StashBoardPlugin.TableEnabled.Value);
	}

	private float SetDrop(StashGroup g)
	{
		if (g == Group)
		{
			return _tableDrop;
		}
		return Mathf.Clamp((!g.TableHeightSet) ? StashBoardPlugin.TableDrop.Value : (0f - g.TableHeight), -2f, 2f);
	}

	private float SetForward(StashGroup g)
	{
		if (g == Group)
		{
			return _tableOffset;
		}
		return Mathf.Clamp((!g.TableForwardSet) ? StashBoardPlugin.TableOffset.Value : g.TableForward, -1.5f, 2f);
	}

	private void LoadTableSettings()
	{
		StashGroup stashGroup = Group;
		_tableDrop = Mathf.Clamp((!stashGroup.TableHeightSet) ? StashBoardPlugin.TableDrop.Value : (0f - stashGroup.TableHeight), -2f, 2f);
		_tableOffset = Mathf.Clamp((!stashGroup.TableForwardSet) ? StashBoardPlugin.TableOffset.Value : stashGroup.TableForward, -1.5f, 2f);
	}

	private void SaveTable()
	{
		StashGroup stashGroup = Group;
		stashGroup.TableHeightSet = true;
		stashGroup.TableHeight = 0f - _tableDrop;
		stashGroup.TableForwardSet = true;
		stashGroup.TableForward = _tableOffset;
		StashBoardPlugin.Store.Save();
	}

	private int TableLengthSetting()
	{
		return TableLengthSetting(Group);
	}

	private static int TableLengthSetting(StashGroup set)
	{
		int tableLengthCm = set.TableLengthCm;
		return (tableLengthCm > 0) ? tableLengthCm : ((tableLengthCm >= 0) ? Mathf.Max(0, StashBoardPlugin.TableLengthCm.Value) : 0);
	}

	private float TableWidth()
	{
		int num = TableLengthSetting();
		if (num > 0)
		{
			return (float)Mathf.Clamp(num, 20, 600) / 100f;
		}
		float num2 = ((!_panelOpen) ? _trayGridR : _trayPanelR);
		return (num2 - _trayL) * _scale + 0.06f;
	}

	private float TableDepth()
	{
		return TableDepth(Group);
	}

	private static float TableDepth(StashGroup g)
	{
		int num = ((g.TableDepthCm <= 0) ? StashBoardPlugin.TableDepthCm.Value : g.TableDepthCm);
		return (float)Mathf.Clamp(num, 15, 150) / 100f;
	}

	private int ChooseTableLayer()
	{
		int num = 0;
		try
		{
			FVRMovementManager currentMovementManager = GM.CurrentMovementManager;
			if ((Object)(object)currentMovementManager != (Object)null)
			{
				num = ((LayerMask)(ref currentMovementManager.LM_TeleCast)).value | ((LayerMask)(ref currentMovementManager.LM_PointSearch)).value;
			}
		}
		catch (Exception)
		{
		}
		List<int> list = new List<int>();
		list.Add(1);
		list.Add(2);
		List<int> list2 = list;
		for (int i = 8; i < 32; i++)
		{
			list2.Add(i);
		}
		foreach (int item in list2)
		{
			if ((num & (1 << item)) == 0 && item != _pointLayer && !Physics.GetIgnoreLayerCollision(0, item))
			{
				string text = (LayerMask.LayerToName(item) ?? string.Empty).ToLowerInvariant();
				if (!text.Contains("player") && !text.Contains("agent") && !text.Contains("interact") && !text.Contains("environment") && !text.Contains("hand") && !text.Contains("head") && !text.Contains("nocol") && !text.Contains("water") && !text.Contains("ui"))
				{
					StashBoardPlugin.Detail("Table on layer " + item + " (" + LayerMask.LayerToName(item) + "); player movement layers 0x" + num.ToString("X8") + ".");
					return item;
				}
			}