Decompiled source of GroupBoard v1.0.3

plugins/GroupBoard.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GroupBoard")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GroupBoard")]
[assembly: AssemblyTitle("GroupBoard")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GroupBoard;

[BepInPlugin("anwo.GroupBoard", "GroupBoard", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class GroupBoardPlugin : BaseUnityPlugin
{
	internal sealed class TaskItem
	{
		public string Id;

		public bool Done;

		public string Author;

		public string DoneBy;

		public string Text;
	}

	public const string Guid = "anwo.GroupBoard";

	public const string Name = "GroupBoard";

	public const string Version = "1.0.3";

	internal const string ZdoKey = "anwo_todo";

	internal static GroupBoardPlugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<int> MaxTasks;

	internal static ConfigEntry<int> MaxLength;

	internal static ConfigEntry<int> HoverTasks;

	internal static ConfigEntry<float> Scale;

	internal static ConfigEntry<float> TextSize;

	internal static ConfigEntry<float> CloseDistance;

	internal static ConfigEntry<string> BoardRecipe;

	internal const string PiecePrefab = "anwo_groupboard";

	private Sign _sign;

	private List<TaskItem> _tasks = new List<TaskItem>();

	private string _raw = "";

	private float _nextRefresh;

	private string _input = "";

	private string _editId;

	private string _editText = "";

	private bool _focusInput;

	private bool _focusEdit;

	private int _openedFrame;

	private Vector2 _scroll;

	private Rect _window = new Rect(80f, 80f, 620f, 520f);

	private GUIStyle _done;

	private GUIStyle _open;

	private GUIStyle _small;

	private Harmony _harmony;

	private static readonly Regex BoardRx = new Regex("^\\s*to[\\s\\-]?do(?![a-z])\\s*[:\\-]?\\s*(.*)$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);

	private static readonly Regex Tags = new Regex("<[^>]*>", RegexOptions.Compiled);

	private static readonly FieldRef<Sign, ZNetView> SignNView = AccessTools.FieldRefAccess<Sign, ZNetView>("m_nview");

	internal static bool WindowOpen
	{
		get
		{
			if ((Object)(object)Instance != (Object)null)
			{
				return (Object)(object)Instance._sign != (Object)null;
			}
			return false;
		}
	}

	private void Awake()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		//IL_018a: 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_0197: Expected O, but got Unknown
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		MaxTasks = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Board", "Max tasks", 50, new ConfigDescription("The most tasks one board can hold.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), Array.Empty<object>()));
		MaxLength = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Board", "Max task length", 120, new ConfigDescription("Longest task text, in characters.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 300), Array.Empty<object>()));
		HoverTasks = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Board", "Tasks shown on hover", 3, new ConfigDescription("How many open tasks to show when you look at the board.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
		CloseDistance = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Board", "Close distance", 8f, new ConfigDescription("The board window closes when you walk further than this from the sign, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 50f), Array.Empty<object>()));
		Scale = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Look", "Scale", 1f, new ConfigDescription("Size of the board window.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 2.5f), Array.Empty<object>()));
		TextSize = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Look", "Board text size", 1.3f, new ConfigDescription("Text size on a Group board with a long list, until someone changes it with the board's Text size slider (1 = the size in version 1.0.0). A short list grows to fill the board.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.7f, 2f), Array.Empty<object>()));
		BoardRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Board", "Group board recipe", "Wood:6,Coal:1", new ConfigDescription("Cost of the buildable Group board, as Item:Amount pairs separated by commas. Needs a game restart.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		_harmony = new Harmony("anwo.GroupBoard");
		_harmony.PatchAll(typeof(Patches));
		PrefabManager.OnVanillaPrefabsAvailable += AddBoardPiece;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GroupBoard 1.0.3 loaded.");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private void AddBoardPiece()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_009f: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		try
		{
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("anwo_groupboard", "sign");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Cloning the vanilla sign failed; the Group board is not added.");
				return;
			}
			val.transform.localScale = Vector3.one * BoardPiece.Scales[1];
			Sign component = val.GetComponent<Sign>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_name = "Group board";
				component.m_defaultText = "To-do";
				component.m_characterLimit = 40;
			}
			val.AddComponent<BoardPiece>();
			PieceConfig val2 = new PieceConfig
			{
				Name = "Group board",
				Description = "A big board with your group's to-do list on it. E opens the list, Shift+E renames the board.",
				PieceTable = PieceTables.Hammer,
				Category = PieceCategories.Misc,
				CraftingStation = CraftingStations.Workbench,
				Icon = LoadIcon(),
				Requirements = ParseRecipe(BoardRecipe.Value)
			};
			PieceManager.Instance.AddPiece(new CustomPiece(val, false, val2));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Group board added to the hammer (Misc).");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Adding the Group board failed: " + ex));
		}
		finally
		{
			PrefabManager.OnVanillaPrefabsAvailable -= AddBoardPiece;
		}
	}

	private static RequirementConfig[] ParseRecipe(string recipe)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_00a3: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: 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_006d: Expected O, but got Unknown
		List<RequirementConfig> list = new List<RequirementConfig>();
		string[] array = (recipe ?? "").Split(',');
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = array[i].Split(':');
			if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0)
			{
				list.Add(new RequirementConfig
				{
					Item = array2[0].Trim(),
					Amount = result,
					Recover = true
				});
			}
		}
		if (list.Count == 0)
		{
			list.Add(new RequirementConfig
			{
				Item = "Wood",
				Amount = 6,
				Recover = true
			});
		}
		return list.ToArray();
	}

	private static Sprite LoadIcon()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_0076: 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)
		try
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GroupBoard.icon.png");
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num <= 0)
				{
					break;
				}
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Could not load the board icon: " + ex.Message));
			return null;
		}
	}

	internal static bool IsBoard(Sign sign, out string title)
	{
		title = null;
		if ((Object)(object)sign == (Object)null)
		{
			return false;
		}
		string text;
		try
		{
			text = sign.GetText();
		}
		catch
		{
			return false;
		}
		string text2 = Tags.Replace(text ?? "", "").Trim();
		Match match = BoardRx.Match(text2);
		if ((Object)(object)((Component)sign).GetComponent<BoardPiece>() != (Object)null)
		{
			title = (match.Success ? match.Groups[1].Value.Trim() : text2);
			if (title.Length == 0)
			{
				title = "To-do";
			}
			return true;
		}
		if (!match.Success)
		{
			return false;
		}
		title = match.Groups[1].Value.Trim();
		if (title.Length == 0)
		{
			title = "To-do";
		}
		return true;
	}

	internal static bool IsBoardPiece(Sign sign)
	{
		if ((Object)(object)sign != (Object)null)
		{
			return (Object)(object)((Component)sign).GetComponent<BoardPiece>() != (Object)null;
		}
		return false;
	}

	internal static ZNetView NView(Sign sign)
	{
		if (!((Object)(object)sign == (Object)null))
		{
			return SignNView.Invoke(sign);
		}
		return null;
	}

	internal static string ReadRaw(Sign sign)
	{
		ZNetView val = NView(sign);
		if ((Object)(object)val == (Object)null || !val.IsValid())
		{
			return "";
		}
		return val.GetZDO().GetString("anwo_todo", "") ?? "";
	}

	internal static List<TaskItem> Parse(string raw)
	{
		List<TaskItem> list = new List<TaskItem>();
		if (string.IsNullOrEmpty(raw))
		{
			return list;
		}
		string[] array = raw.Split('\n');
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = array[i].Split('\t');
			if (array2.Length >= 5)
			{
				list.Add(new TaskItem
				{
					Id = array2[0],
					Done = (array2[1] == "1"),
					Author = array2[2],
					DoneBy = array2[3],
					Text = array2[4]
				});
			}
		}
		return list;
	}

	private static string Serialize(List<TaskItem> list)
	{
		return string.Join("\n", list.Select((TaskItem t) => string.Join("\t", t.Id, t.Done ? "1" : "0", Clean(t.Author), Clean(t.DoneBy), Clean(t.Text))));
	}

	private static string Clean(string s)
	{
		return (s ?? "").Replace('\t', ' ').Replace('\n', ' ').Replace('\r', ' ');
	}

	private bool Apply(Action<List<TaskItem>> change)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)_sign == (Object)null)
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)_sign).transform.position, 0f, true, false))
			{
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "This board is inside a ward you don't have access to", 0, (Sprite)null, false);
				}
				return false;
			}
			ZNetView val = NView(_sign);
			if ((Object)(object)val == (Object)null || !val.IsValid())
			{
				return false;
			}
			List<TaskItem> list = Parse(val.GetZDO().GetString("anwo_todo", "") ?? "");
			change(list);
			val.ClaimOwnership();
			string text = Serialize(list);
			val.GetZDO().Set("anwo_todo", text);
			_raw = text;
			_tasks = list;
			return true;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Board change failed: " + ex.Message));
			return false;
		}
	}

	private static string Me()
	{
		try
		{
			return ((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetPlayerName() : "?";
		}
		catch
		{
			return "?";
		}
	}

	private void AddTask()
	{
		string text = Clean(_input).Trim();
		if (text.Length == 0)
		{
			return;
		}
		if (text.Length > MaxLength.Value)
		{
			text = text.Substring(0, MaxLength.Value);
		}
		bool full = false;
		Apply(delegate(List<TaskItem> list)
		{
			if (list.Count >= MaxTasks.Value)
			{
				full = true;
			}
			else
			{
				list.Add(new TaskItem
				{
					Id = Guid8(),
					Done = false,
					Author = Me(),
					DoneBy = "",
					Text = text
				});
			}
		});
		if (full)
		{
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, $"The board is full ({MaxTasks.Value} tasks). Clear finished ones first.", 0, (Sprite)null, false);
			}
		}
		else
		{
			_input = "";
		}
		_focusInput = true;
	}

	private static string Guid8()
	{
		return System.Guid.NewGuid().ToString("N").Substring(0, 8);
	}

	private void MoveTask(string id, int dir)
	{
		Apply(delegate(List<TaskItem> list)
		{
			int num = list.FindIndex((TaskItem t) => t.Id == id);
			if (num >= 0)
			{
				bool done = list[num].Done;
				int num2;
				for (num2 = num + dir; num2 >= 0 && num2 < list.Count && list[num2].Done != done; num2 += dir)
				{
				}
				if (num2 >= 0 && num2 < list.Count)
				{
					TaskItem value = list[num];
					list[num] = list[num2];
					list[num2] = value;
				}
			}
		});
	}

	private void SaveEdit()
	{
		string id = _editId;
		string text = Clean(_editText).Trim();
		if (text.Length > MaxLength.Value)
		{
			text = text.Substring(0, MaxLength.Value);
		}
		_editId = null;
		if (id == null || text.Length == 0)
		{
			return;
		}
		Apply(delegate(List<TaskItem> list)
		{
			TaskItem taskItem = list.FirstOrDefault((TaskItem t) => t.Id == id);
			if (taskItem != null)
			{
				taskItem.Text = text;
			}
		});
	}

	private void SetSize(int size)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((Object)(object)_sign == (Object)null) && IsBoardPiece(_sign) && PrivateArea.CheckAccess(((Component)_sign).transform.position, 0f, true, false))
			{
				ZNetView val = NView(_sign);
				if (!((Object)(object)val == (Object)null) && val.IsValid())
				{
					val.ClaimOwnership();
					val.GetZDO().Set("anwo_board_size", Mathf.Clamp(size, 0, BoardPiece.Scales.Length - 1));
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Board resize failed: " + ex.Message));
		}
	}

	private void SetTextSize(float scale)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((Object)(object)_sign == (Object)null) && IsBoardPiece(_sign) && PrivateArea.CheckAccess(((Component)_sign).transform.position, 0f, true, false))
			{
				ZNetView val = NView(_sign);
				if (!((Object)(object)val == (Object)null) && val.IsValid())
				{
					val.ClaimOwnership();
					val.GetZDO().Set("anwo_board_text", Mathf.Clamp(scale, 0.7f, 2f));
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Board text size failed: " + ex.Message));
		}
	}

	internal void Open(Sign sign)
	{
		_sign = sign;
		_raw = ReadRaw(sign);
		_tasks = Parse(_raw);
		_input = "";
		_focusInput = true;
		_openedFrame = Time.frameCount;
		_nextRefresh = Time.time + 0.5f;
	}

	private void Close()
	{
		_sign = null;
		_input = "";
		_editId = null;
	}

	private void Update()
	{
		//IL_003c: 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)
		if ((Object)(object)_sign == (Object)null)
		{
			return;
		}
		try
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || !IsBoard(_sign, out var _) || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)_sign).transform.position) > CloseDistance.Value)
			{
				Close();
			}
			else if (Time.time >= _nextRefresh)
			{
				_nextRefresh = Time.time + 0.5f;
				string text = ReadRaw(_sign);
				if (text != _raw)
				{
					_raw = text;
					_tasks = Parse(text);
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Update failed: " + ex.Message));
			Close();
		}
	}

	private void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		//IL_00bd: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_sign == (Object)null)
		{
			return;
		}
		try
		{
			Event current = Event.current;
			if ((int)current.type == 4 && (int)current.keyCode == 27)
			{
				current.Use();
				Close();
				return;
			}
			IsBoard(_sign, out var title);
			Matrix4x4 matrix = GUI.matrix;
			float value = Scale.Value;
			GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(value, value, 1f));
			GUISkin skin = GUI.skin;
			GUI.skin = PanelSkin.Get();
			_window = GUILayout.Window(7014957, _window, new WindowFunction(DrawWindow), title ?? "To-do", GUI.skin.window, Array.Empty<GUILayoutOption>());
			GUI.skin = skin;
			GUI.matrix = matrix;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("OnGUI failed: " + ex.Message));
		}
	}

	private void DrawWindow(int id)
	{
		GUISkin skin = GUI.skin;
		GUI.skin = PanelSkin.Get();
		try
		{
			DrawWindowContent();
		}
		finally
		{
			GUI.skin = skin;
		}
	}

	private void DrawWindowContent()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Invalid comparison between Unknown and I4
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Invalid comparison between Unknown and I4
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Invalid comparison between Unknown and I4
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0590: Invalid comparison between Unknown and I4
		//IL_0594: Unknown result type (might be due to invalid IL or missing references)
		//IL_059b: Invalid comparison between Unknown and I4
		//IL_059f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a9: Invalid comparison between Unknown and I4
		if (_done == null)
		{
			_open = new GUIStyle(GUI.skin.label)
			{
				wordWrap = true,
				richText = false
			};
			_done = new GUIStyle(_open);
			_done.normal.textColor = new Color(0.62f, 0.62f, 0.6f);
			_small = new GUIStyle(GUI.skin.label)
			{
				fontSize = Mathf.Max(11, GUI.skin.label.fontSize - 2),
				richText = false
			};
			_small.normal.textColor = new Color(0.78f, 0.76f, 0.72f);
		}
		int num = _tasks.Count((TaskItem t) => !t.Done);
		GUILayout.Label($"{num} open, {_tasks.Count - num} done. Everyone on the server sees the same list.", _small, Array.Empty<GUILayoutOption>());
		_scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(300f) });
		if (_tasks.Count == 0)
		{
			GUILayout.Label("No tasks yet. Type one below and press Enter.", _open, Array.Empty<GUILayoutOption>());
		}
		List<TaskItem> list = _tasks.Where((TaskItem t) => !t.Done).Concat(_tasks.Where((TaskItem t) => t.Done)).ToList();
		Event current = Event.current;
		string editId = _editId;
		bool flag = editId != null && (int)current.type == 4 && ((int)current.keyCode == 13 || (int)current.keyCode == 271) && GUI.GetNameOfFocusedControl() == "anwo_task_edit";
		if (flag)
		{
			current.Use();
		}
		for (int num2 = 0; num2 < list.Count; num2++)
		{
			TaskItem taskItem = list[num2];
			string tid = taskItem.Id;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool now = GUILayout.Toggle(taskItem.Done, "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) });
			if (now != taskItem.Done)
			{
				string me = Me();
				Apply(delegate(List<TaskItem> source)
				{
					TaskItem taskItem2 = source.FirstOrDefault((TaskItem i) => i.Id == tid);
					if (taskItem2 != null)
					{
						taskItem2.Done = now;
						taskItem2.DoneBy = (now ? me : "");
					}
				});
			}
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			if (editId == tid)
			{
				GUI.SetNextControlName("anwo_task_edit");
				_editText = GUILayout.TextField(_editText ?? "", MaxLength.Value, Array.Empty<GUILayoutOption>());
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Save", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) }) || flag)
				{
					SaveEdit();
				}
				if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) }))
				{
					_editId = null;
				}
				GUILayout.EndHorizontal();
			}
			else
			{
				GUILayout.Label(taskItem.Done ? ("✓ " + taskItem.Text) : taskItem.Text, taskItem.Done ? _done : _open, Array.Empty<GUILayoutOption>());
				GUILayout.Label((taskItem.Done && !string.IsNullOrEmpty(taskItem.DoneBy)) ? ("added by " + taskItem.Author + ", done by " + taskItem.DoneBy) : ("added by " + taskItem.Author), _small, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			bool enabled = num2 > 0 && list[num2 - 1].Done == taskItem.Done;
			bool enabled2 = num2 < list.Count - 1 && list[num2 + 1].Done == taskItem.Done;
			GUI.enabled = enabled;
			if (GUILayout.Button("▲", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				MoveTask(tid, -1);
			}
			GUI.enabled = enabled2;
			if (GUILayout.Button("▼", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				MoveTask(tid, 1);
			}
			GUI.enabled = true;
			if (editId != tid && GUILayout.Button("Edit", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(56f) }))
			{
				_editId = tid;
				_editText = taskItem.Text;
				_focusEdit = true;
			}
			if (GUILayout.Button("✕", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				if (_editId == tid)
				{
					_editId = null;
				}
				Apply(delegate(List<TaskItem> list2)
				{
					list2.RemoveAll((TaskItem i) => i.Id == tid);
				});
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndScrollView();
		GUILayout.Space(4f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		Event current2 = Event.current;
		bool flag2 = (int)current2.type == 4 && ((int)current2.keyCode == 13 || (int)current2.keyCode == 271) && GUI.GetNameOfFocusedControl() == "anwo_task_input";
		if (flag2)
		{
			current2.Use();
		}
		if (Time.frameCount <= _openedFrame + 1)
		{
			_input = "";
		}
		GUI.SetNextControlName("anwo_task_input");
		_input = GUILayout.TextField(_input ?? "", MaxLength.Value, Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Add", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) }) || flag2)
		{
			AddTask();
		}
		GUILayout.EndHorizontal();
		if (_focusEdit)
		{
			GUI.FocusControl("anwo_task_edit");
			_focusEdit = false;
			_focusInput = false;
		}
		else if (_focusInput)
		{
			GUI.FocusControl("anwo_task_input");
			_focusInput = false;
		}
		if (IsBoardPiece(_sign))
		{
			int num3 = 1;
			try
			{
				num3 = NView(_sign).GetZDO().GetInt("anwo_board_size", 1);
			}
			catch
			{
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Board size", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			for (int num4 = 0; num4 < BoardPiece.SizeNames.Length; num4++)
			{
				if (GUILayout.Toggle(num3 == num4, BoardPiece.SizeNames[num4], GUIStyle.op_Implicit("Button"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(86f) }) && num3 != num4)
				{
					SetSize(num4);
				}
			}
			GUILayout.EndHorizontal();
			float num5 = BoardPiece.DefaultText;
			try
			{
				num5 = BoardPiece.TextScale(NView(_sign).GetZDO());
			}
			catch
			{
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Text size", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			float num6 = GUILayout.HorizontalSlider(num5, 0.7f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
			num6 = Mathf.Round(num6 * 10f) / 10f;
			GUILayout.Label(Mathf.RoundToInt(num6 * 100f) + "%", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) });
			if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				num6 = num5 - 0.1f;
			}
			if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				num6 = num5 + 0.1f;
			}
			num6 = Mathf.Clamp(Mathf.Round(num6 * 10f) / 10f, 0.7f, 2f);
			if (Mathf.Abs(num6 - num5) > 0.01f)
			{
				SetTextSize(num6);
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Clear done", Array.Empty<GUILayoutOption>()))
		{
			Apply(delegate(List<TaskItem> list2)
			{
				list2.RemoveAll((TaskItem i) => i.Done);
			});
		}
		GUILayout.FlexibleSpace();
		GUILayout.Label("Esc closes", _small, Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(84f) }))
		{
			Close();
		}
		GUILayout.EndHorizontal();
		GUI.DragWindow();
	}

	internal static string HoverInfo(Sign sign, string title)
	{
		List<TaskItem> list = Parse(ReadRaw(sign));
		int num = list.Count((TaskItem t) => !t.Done);
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append($"\n<color=#e8c170>{title}</color>: {num} open, {list.Count - num} done");
		foreach (TaskItem item in list.Where((TaskItem t) => !t.Done).Take(HoverTasks.Value))
		{
			string text = ((item.Text.Length > 60) ? (item.Text.Substring(0, 57) + "…") : item.Text);
			stringBuilder.Append("\n• ").Append(text.Replace("<", "‹").Replace(">", "›"));
		}
		if (num > HoverTasks.Value)
		{
			stringBuilder.Append($"\n… and {num - HoverTasks.Value} more");
		}
		return stringBuilder.ToString();
	}
}
public class BoardPiece : MonoBehaviour
{
	internal const string KeySize = "anwo_board_size";

	internal const string KeyText = "anwo_board_text";

	internal const float MinText = 0.7f;

	internal const float MaxText = 2f;

	internal static readonly string[] SizeNames = new string[3] { "Small", "Medium", "Large" };

	internal static readonly float[] Scales = new float[3] { 1.6f, 2.3f, 3.1f };

	private static readonly int[] Lines = new int[3] { 5, 8, 11 };

	private Sign _sign;

	private ZNetView _nview;

	private uint _revision = uint.MaxValue;

	private int _size = -1;

	private float _text = -1f;

	private float _next;

	private bool _configured;

	private const float MaxGrow = 2.5f;

	private const int MaxTaskChars = 140;

	private static readonly FieldRef<Sign, bool> IsViewable = AccessTools.FieldRefAccess<Sign, bool>("m_isViewable");

	private static readonly Action<WearNTear> SetupColliders = MakeSetupColliders();

	internal static float DefaultText
	{
		get
		{
			float num = ((GroupBoardPlugin.TextSize != null) ? GroupBoardPlugin.TextSize.Value : 1.3f);
			if (!float.IsNaN(num))
			{
				return Mathf.Clamp(num, 0.7f, 2f);
			}
			return 1.3f;
		}
	}

	private float CurrentText
	{
		get
		{
			if (!(_text > 0f))
			{
				return DefaultText;
			}
			return _text;
		}
	}

	internal static float TextScale(ZDO zdo)
	{
		float defaultText = DefaultText;
		float num = ((zdo != null) ? zdo.GetFloat("anwo_board_text", defaultText) : defaultText);
		if (!float.IsNaN(num) && !float.IsInfinity(num))
		{
			return Mathf.Clamp(num, 0.7f, 2f);
		}
		return defaultText;
	}

	private void Awake()
	{
		_sign = ((Component)this).GetComponent<Sign>();
		_nview = ((Component)this).GetComponent<ZNetView>();
	}

	private void Start()
	{
		Refresh(force: true);
	}

	private void Update()
	{
		if (!(Time.time < _next))
		{
			_next = Time.time + 0.5f;
			Refresh(force: false);
		}
	}

	private void Refresh(bool force)
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)_sign == (Object)null || (Object)(object)_sign.m_textWidget == (Object)null)
			{
				return;
			}
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				if (force)
				{
					Show("<b>To-do</b>\n<size=75%>No tasks yet · press E</size>", 1);
				}
				return;
			}
			ZDO zDO = _nview.GetZDO();
			int num = Mathf.Clamp(zDO.GetInt("anwo_board_size", 1), 0, Scales.Length - 1);
			if (num != _size)
			{
				_size = num;
				((Component)this).transform.localScale = Vector3.one * Scales[num];
				WearNTear component = ((Component)this).GetComponent<WearNTear>();
				if ((Object)(object)component != (Object)null && SetupColliders != null)
				{
					SetupColliders(component);
				}
				force = true;
			}
			float num2 = TextScale(zDO);
			if (Mathf.Abs(num2 - _text) > 0.001f)
			{
				_text = num2;
				force = true;
			}
			if (force || zDO.DataRevision != _revision)
			{
				_revision = zDO.DataRevision;
				ApplyText();
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogDebug((object)("Board refresh failed: " + ex.Message));
			}
		}
	}

	internal void ApplyText()
	{
		if ((Object)(object)_sign == (Object)null || (Object)(object)_sign.m_textWidget == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid())
		{
			return;
		}
		if (!Viewable(_sign))
		{
			Show("<b>????????????</b>", (_size < 0) ? 1 : _size);
			return;
		}
		GroupBoardPlugin.IsBoard(_sign, out var title);
		List<GroupBoardPlugin.TaskItem> list = GroupBoardPlugin.Parse(GroupBoardPlugin.ReadRaw(_sign));
		int size = ((_size < 0) ? 1 : _size);
		List<GroupBoardPlugin.TaskItem> list2 = list.Where((GroupBoardPlugin.TaskItem t) => !t.Done).ToList();
		int num = list.Count - list2.Count;
		string text = "<b>" + Safe(title ?? "To-do") + "</b>";
		if (list2.Count == 0)
		{
			text = text + "\n<size=75%>" + ((list.Count == 0) ? "No tasks yet" : "All done!") + " · press E</size>";
		}
		string tail = ((num > 0) ? ("<size=75%>" + num + " done</size>") : null);
		List<string> tasks = list2.Select(delegate(GroupBoardPlugin.TaskItem t)
		{
			string text2 = t.Text ?? "";
			if (text2.Length > 140)
			{
				text2 = text2.Substring(0, 137) + "...";
			}
			return "- " + Safe(text2);
		}).ToList();
		Show(text, tasks, tail, size);
	}

	private void Show(string text, int size)
	{
		Show(text, new List<string>(), null, size);
	}

	private void Show(string head, List<string> tasks, string tail, int size)
	{
		//IL_0048: 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_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_0061: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI textWidget = _sign.m_textWidget;
		if (!_configured)
		{
			_configured = true;
			((TMP_Text)textWidget).richText = true;
			((TMP_Text)textWidget).enableAutoSizing = false;
			((TMP_Text)textWidget).alignment = (TextAlignmentOptions)257;
			((TMP_Text)textWidget).textWrappingMode = (TextWrappingModes)1;
			((TMP_Text)textWidget).overflowMode = (TextOverflowModes)1;
		}
		Rect rect = ((TMP_Text)textWidget).rectTransform.rect;
		Vector4 margin = ((TMP_Text)textWidget).margin;
		float num = Mathf.Abs(((Rect)(ref rect)).width) - margin.x - margin.z;
		float num2 = Mathf.Abs(((Rect)(ref rect)).height) - margin.y - margin.w;
		float num3 = Mathf.Abs(((Rect)(ref rect)).height) / (((float)Lines[Mathf.Clamp(size, 0, Lines.Length - 1)] + 2.2f) * 1.18f);
		float num4 = num3 * CurrentText;
		float num5 = num3 * Mathf.Max(2.5f, CurrentText);
		string text = Compose(head, tasks, tasks.Count, tail);
		float fontSize = num4;
		try
		{
			if (num > 0.01f && num2 > 0.01f)
			{
				if (!Fits((TMP_Text)(object)textWidget, text, num4, num, num2))
				{
					int num6 = 0;
					int num7 = tasks.Count - 1;
					while (num6 < num7)
					{
						int num8 = (num6 + num7 + 1) / 2;
						if (Fits((TMP_Text)(object)textWidget, Compose(head, tasks, num8, tail), num4, num, num2))
						{
							num6 = num8;
						}
						else
						{
							num7 = num8 - 1;
						}
					}
					text = Compose(head, tasks, num6, tail);
				}
				if (Fits((TMP_Text)(object)textWidget, text, num5, num, num2))
				{
					fontSize = num5;
				}
				else
				{
					float num9 = num4;
					float num10 = num5;
					for (int i = 0; i < 10; i++)
					{
						float num11 = (num9 + num10) * 0.5f;
						if (Fits((TMP_Text)(object)textWidget, text, num11, num, num2))
						{
							num9 = num11;
						}
						else
						{
							num10 = num11;
						}
					}
					fontSize = num9;
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogDebug((object)("Fitting the board text failed: " + ex.Message));
			}
			fontSize = num4;
		}
		((TMP_Text)textWidget).fontSize = fontSize;
		((TMP_Text)textWidget).text = text;
	}

	private static string Compose(string head, List<string> tasks, int shown, string tail)
	{
		StringBuilder stringBuilder = new StringBuilder(head);
		for (int i = 0; i < shown && i < tasks.Count; i++)
		{
			stringBuilder.Append('\n').Append(tasks[i]);
		}
		if (tasks.Count > shown)
		{
			stringBuilder.Append("\n<size=75%>+").Append(tasks.Count - shown).Append(" more · press E to see all</size>");
		}
		if (tail != null)
		{
			stringBuilder.Append('\n').Append(tail);
		}
		return stringBuilder.ToString();
	}

	private static bool Fits(TMP_Text widget, string text, float fontSize, float width, float height)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		widget.fontSize = fontSize;
		return widget.GetPreferredValues(text, width, 0f).y <= height;
	}

	private static string Safe(string s)
	{
		return (s ?? "").Replace("<", "‹").Replace(">", "›");
	}

	private static Action<WearNTear> MakeSetupColliders()
	{
		try
		{
			return AccessTools.MethodDelegate<Action<WearNTear>>(AccessTools.Method(typeof(WearNTear), "SetupColliders", (Type[])null, (Type[])null), (object)null, true);
		}
		catch
		{
			return null;
		}
	}

	internal static bool Viewable(Sign sign)
	{
		try
		{
			return IsViewable.Invoke(sign);
		}
		catch
		{
			return true;
		}
	}
}
internal static class Patches
{
	private static readonly FieldRef<Sign, string> CurrentText = AccessTools.FieldRefAccess<Sign, string>("m_currentText");

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Sign), "GetText")]
	private static void GetTextPostfix(Sign __instance, ref string __result)
	{
		try
		{
			if (!((Object)(object)((Component)__instance).GetComponent<BoardPiece>() == (Object)null))
			{
				__result = (BoardPiece.Viewable(__instance) ? (CurrentText.Invoke(__instance) ?? "") : "????????????");
			}
		}
		catch
		{
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Sign), "UpdateText")]
	private static void UpdateTextPostfix(Sign __instance)
	{
		try
		{
			BoardPiece component = ((Component)__instance).GetComponent<BoardPiece>();
			if ((Object)(object)component != (Object)null)
			{
				component.ApplyText();
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogDebug((object)("Board text failed: " + ex.Message));
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Sign), "Interact")]
	private static bool InteractPrefix(Sign __instance, bool hold, bool alt, ref bool __result)
	{
		try
		{
			if (hold || alt)
			{
				return true;
			}
			if (!GroupBoardPlugin.IsBoard(__instance, out var _))
			{
				return true;
			}
			GroupBoardPlugin.Instance?.Open(__instance);
			__result = true;
			return false;
		}
		catch (Exception ex)
		{
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogDebug((object)("Interact failed: " + ex.Message));
			}
			return true;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Sign), "GetHoverText")]
	private static void HoverPostfix(Sign __instance, ref string __result)
	{
		try
		{
			if (GroupBoardPlugin.IsBoard(__instance, out var title))
			{
				string text = Regex.Replace(__instance.GetText() ?? "", "<[^>]*>", "");
				string text2 = Localization.instance.Localize("\n[<color=yellow><b>$KEY_Use</b></color>] Open board\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Rename board");
				__result = "\"" + text + "\"" + GroupBoardPlugin.HoverInfo(__instance, title) + text2;
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogDebug((object)("Hover failed: " + ex.Message));
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	private static void TextInputVisible(ref bool __result)
	{
		if (!__result && GroupBoardPlugin.WindowOpen)
		{
			__result = true;
		}
	}
}
internal static class PanelSkin
{
	private static GUISkin s_skin;

	internal static GUISkin Get()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Expected O, but got Unknown
		//IL_016b: Expected O, but got Unknown
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: 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_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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Expected O, but got Unknown
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Expected O, but got Unknown
		//IL_0286: Expected O, but got Unknown
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Expected O, but got Unknown
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_skin != (Object)null)
		{
			return s_skin;
		}
		GUISkin val = Object.Instantiate<GUISkin>(GUI.skin);
		((Object)val).hideFlags = (HideFlags)61;
		Color color = default(Color);
		((Color)(ref color))..ctor(0.95f, 0.93f, 0.88f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.93f, 0.78f, 0.45f);
		Color frame = default(Color);
		((Color)(ref frame))..ctor(0.62f, 0.48f, 0.26f);
		val.window = new GUIStyle(val.window);
		SetAll(val.window, Tex(new Color(0.09f, 0.08f, 0.07f, 0.97f), frame), val2);
		val.window.border = new RectOffset(3, 3, 3, 3);
		val.window.padding = new RectOffset(14, 14, 38, 14);
		val.window.contentOffset = new Vector2(0f, -30f);
		val.window.fontSize = 20;
		val.window.fontStyle = (FontStyle)1;
		val.window.alignment = (TextAnchor)1;
		val.label = new GUIStyle(val.label)
		{
			fontSize = 16
		};
		SetText(val.label, color);
		val.button = new GUIStyle(val.button)
		{
			fontSize = 15,
			padding = new RectOffset(8, 8, 5, 5),
			border = new RectOffset(2, 2, 2, 2)
		};
		Texture2D background = Tex(new Color(0.22f, 0.19f, 0.15f, 1f), frame);
		SetAll(val.button, background, color);
		val.button.hover.background = Tex(new Color(0.32f, 0.27f, 0.2f, 1f), val2);
		val.button.active.background = Tex(new Color(0.15f, 0.13f, 0.1f, 1f), val2);
		Texture2D background2 = Tex(new Color(0.5f, 0.37f, 0.16f, 1f), val2);
		val.button.onNormal.background = background2;
		val.button.onHover.background = background2;
		val.button.onActive.background = background2;
		val.textField = new GUIStyle(val.textField)
		{
			fontSize = 16,
			padding = new RectOffset(6, 6, 5, 5),
			border = new RectOffset(2, 2, 2, 2)
		};
		SetAll(val.textField, Tex(new Color(0.03f, 0.03f, 0.03f, 1f), frame), Color.white);
		val.textField.focused.background = Tex(new Color(0.03f, 0.03f, 0.03f, 1f), val2);
		val.textField.onFocused.background = val.textField.focused.background;
		val.toggle = new GUIStyle(val.toggle)
		{
			fontSize = 15
		};
		SetText(val.toggle, color);
		s_skin = val;
		return val;
	}

	private static void SetText(GUIStyle style, Color color)
	{
		//IL_0006: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		style.normal.textColor = color;
		style.hover.textColor = color;
		style.active.textColor = color;
		style.focused.textColor = color;
		style.onNormal.textColor = color;
		style.onHover.textColor = color;
		style.onActive.textColor = color;
		style.onFocused.textColor = color;
	}

	private static void SetAll(GUIStyle style, Texture2D background, Color color)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		style.normal.background = background;
		style.hover.background = background;
		style.active.background = background;
		style.focused.background = background;
		style.onNormal.background = background;
		style.onHover.background = background;
		style.onActive.background = background;
		style.onFocused.background = background;
		SetText(style, color);
	}

	private static Texture2D Tex(Color fill, Color frame)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(8, 8, (TextureFormat)4, false);
		((Object)val).hideFlags = (HideFlags)61;
		((Texture)val).filterMode = (FilterMode)0;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Color[] array = (Color[])(object)new Color[64];
		for (int i = 0; i < 8; i++)
		{
			for (int j = 0; j < 8; j++)
			{
				array[i * 8 + j] = ((j < 2 || i < 2 || j >= 6 || i >= 6) ? frame : fill);
			}
		}
		val.SetPixels(array);
		val.Apply();
		return val;
	}
}