Decompiled source of GroupBoard v1.1.1

plugins/GroupBoard.dll

Decompiled a month 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.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: AssemblyVersion("0.0.0.0")]
namespace GroupBoard;

internal static class FileLog
{
	private static DiskLogListener s_disk;

	private static bool s_looked;

	internal static void Info(ManualLogSource src, string msg)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		try
		{
			if (!s_looked)
			{
				s_looked = true;
				foreach (ILogListener listener in Logger.Listeners)
				{
					DiskLogListener val = (DiskLogListener)(object)((listener is DiskLogListener) ? listener : null);
					if (val != null)
					{
						s_disk = val;
						break;
					}
				}
			}
			if (s_disk != null)
			{
				s_disk.LogEvent((object)src, new LogEventArgs((object)msg, (LogLevel)16, (ILogSource)(object)src));
				return;
			}
		}
		catch (Exception)
		{
		}
		try
		{
			if (src != null)
			{
				src.LogDebug((object)msg);
			}
		}
		catch (Exception)
		{
		}
	}
}
[BepInPlugin("anwo.GroupBoard", "GroupBoard", "1.1.1")]
[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;
	}

	private sealed class Sent
	{
		public Sign Sign;

		public BoardOps.Op Op;

		public float Due;

		public int Tries;

		public float SentAt;
	}

	public const string Guid = "anwo.GroupBoard";

	public const string Name = "GroupBoard";

	public const string Version = "1.1.1";

	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 static ConfigEntry<bool> TodoSigns;

	internal const string PiecePrefab = "anwo_groupboard";

	private static GameObject s_boardPrefab;

	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 int _shownSize = -1;

	private float _shownText = -1f;

	private float _shownUntil;

	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");

	private readonly Dictionary<string, Sent> _sent = new Dictionary<string, Sent>();

	private const float AnswerWait = 4f;

	private const int MaxTries = 3;

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

	private void Awake()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Expected O, but got Unknown
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Expected O, but got Unknown
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected O, but got Unknown
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Expected O, but got Unknown
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Expected O, but got Unknown
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		MaxTasks = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Host", "Max tasks", 50, new ConfigDescription(Host("The most tasks one board can hold."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)MaxTasks, "1 - Board", "Max tasks");
		MaxLength = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Host", "Max task length", 120, new ConfigDescription(Host("Longest task text, in characters."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 300), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)MaxLength, "1 - Board", "Max task length");
		BoardRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Host", "Group board recipe", "Wood:6,Coal:1", new ConfigDescription(Host("Cost of the buildable Group board, as Item:Amount pairs separated by commas."), (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)BoardRecipe, "1 - Board", "Group board recipe");
		TodoSigns = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Host", "Todo signs", true, new ConfigDescription(Host("A normal sign whose text starts with Todo works as a board too. Off: signs are just signs; only the Group board is a board."), (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		CloseDistance = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Window", "Close distance", 8f, new ConfigDescription(Mine("The board window closes when you walk further than this from the board, in metres."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 50f), Array.Empty<object>()));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)CloseDistance, "1 - Board", "Close distance");
		Scale = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Window", "Scale", 1f, new ConfigDescription(Mine("Size of the board window."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 2.5f), Array.Empty<object>()));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)Scale, "2 - Look", "Scale");
		HoverTasks = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Look", "Tasks shown on hover", 3, new ConfigDescription(Mine("How many open tasks to show when you look at the board."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)HoverTasks, "1 - Board", "Tasks shown on hover");
		TextSize = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Look", "Board text size", 1.3f, new ConfigDescription(Mine("Text size on a Group board with a long list, until someone changes it with the board's Text size slider (1.3 = 130% on the slider). After that, everyone sees the size set on the board. A short list grows to fill the board."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.7f, 2f), Array.Empty<object>()));
		Carry(((BaseUnityPlugin)this).Config, (ConfigEntryBase)(object)TextSize, "2 - Look", "Board text size");
		BoardRecipe.SettingChanged += delegate
		{
			ApplyRecipe();
		};
		SynchronizationManager.OnConfigurationSynchronized += delegate
		{
			ApplyRecipe();
		};
		PieceManager.OnPiecesRegistered += ApplyRecipe;
		((BaseUnityPlugin)this).Config.Save();
		_harmony = new Harmony("anwo.GroupBoard");
		_harmony.PatchAll(typeof(Patches));
		PrefabManager.OnVanillaPrefabsAvailable += AddBoardPiece;
		FileLog.Info(((BaseUnityPlugin)this).Logger, "GroupBoard 1.1.1 loaded.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GroupBoard 1.1.1 loaded (details in LogOutput.log).");
	}

	private static string Host(string text)
	{
		if (!text.EndsWith("Set by the host."))
		{
			return text + " Set by the host.";
		}
		return text;
	}

	private static string Mine(string text)
	{
		if (!text.EndsWith("Each player's own setting."))
		{
			return text + " Each player's own setting.";
		}
		return text;
	}

	private static void Carry(ConfigFile cfg, ConfigEntryBase to, string oldSection, string oldKey)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		if (!(typeof(ConfigFile).GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(cfg) is Dictionary<ConfigDefinition, string> dictionary))
		{
			return;
		}
		ConfigDefinition key = new ConfigDefinition(oldSection, oldKey);
		if (dictionary.TryGetValue(key, out var value))
		{
			try
			{
				to.SetSerializedValue(value);
			}
			catch
			{
			}
			dictionary.Remove(key);
			cfg.Save();
		}
	}

	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_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: 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;
			}
			WearNTear component2 = val.GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_supports = false;
			}
			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));
			s_boardPrefab = val;
			FileLog.Info(((BaseUnityPlugin)this).Logger, "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 void ApplyRecipe()
	{
		//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_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		try
		{
			if ((Object)(object)s_boardPrefab == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			Piece component = s_boardPrefab.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			List<Requirement> list = new List<Requirement>();
			RequirementConfig[] array = ParseRecipe(BoardRecipe.Value);
			foreach (RequirementConfig val in array)
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(val.Item);
				ItemDrop val2 = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Log.LogWarning((object)("Group board recipe: there is no item called '" + val.Item + "', so it is left out."));
					continue;
				}
				list.Add(new Requirement
				{
					m_resItem = val2,
					m_amount = val.Amount,
					m_recover = true
				});
			}
			if (list.Count != 0)
			{
				component.m_resources = list.ToArray();
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Updating the Group board recipe failed: " + ex.Message));
		}
	}

	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 || (TodoSigns != null && !TodoSigns.Value))
		{
			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;
	}

	internal 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))));
	}

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

	private bool Send(BoardOps.Op op)
	{
		//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;
			}
			op.OpId = Guid8();
			Sent sent = new Sent
			{
				Sign = _sign,
				Op = op,
				Tries = 1,
				Due = Time.time + 4f,
				SentAt = Time.time
			};
			_sent[op.OpId] = sent;
			Transmit(sent, takeOver: false);
			if (op.IsListChange)
			{
				if (val.IsOwner())
				{
					Reread();
				}
				else
				{
					List<TaskItem> list = Parse(Serialize(_tasks));
					if (BoardOps.ApplyTo(list, op) == BoardOps.Result.Done)
					{
						_tasks = list;
					}
				}
			}
			return true;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Board change failed: " + ex.Message));
			return false;
		}
	}

	private static void Transmit(Sent s, bool takeOver)
	{
		ZNetView val = NView(s.Sign);
		if (takeOver || !val.HasOwner())
		{
			val.ClaimOwnership();
		}
		val.InvokeRPC("anwo_todo_op", new object[1] { s.Op.ToPackage() });
	}

	internal void OnResult(Sign sign, long from, string opId, BoardOps.Result result)
	{
		if (!_sent.TryGetValue(opId ?? "", out var value))
		{
			return;
		}
		switch (result)
		{
		case BoardOps.Result.Done:
		case BoardOps.Result.NoChange:
		{
			_sent.Remove(opId);
			if (result == BoardOps.Result.NoChange)
			{
				Forget(value);
			}
			long num = 0L;
			try
			{
				num = ZNet.GetUID();
			}
			catch
			{
			}
			if (from != num)
			{
				BoardOps.LogAnswered($"Board change {value.Op} was made by the board's owner, another player's game (peer {from}): {result}, " + $"{Time.time - value.SentAt:0.0} s after it was sent (try {value.Tries}).");
			}
			return;
		}
		case BoardOps.Result.NotOwner:
			value.Due = Mathf.Min(value.Due, Time.time + 1f);
			BoardOps.LogProblem($"Board change {value.Op} reached a game that doesn't own the board any more (peer {from}); sending it again shortly.");
			return;
		}
		_sent.Remove(opId);
		Forget(value);
		BoardOps.LogProblem($"Board change {value.Op} was not made by the board's owner (peer {from}): {result}.");
		if (result == BoardOps.Result.Full)
		{
			ShowFull();
			if (value.Op.Kind == BoardOps.Kind.Add && (Object)(object)sign == (Object)(object)_sign && string.IsNullOrEmpty(_input))
			{
				_input = value.Op.Text;
			}
		}
	}

	private void Forget(Sent s)
	{
		if (!((Object)(object)s.Sign != (Object)(object)_sign))
		{
			if (s.Op.IsListChange)
			{
				_raw = null;
				_nextRefresh = 0f;
			}
			else
			{
				_shownSize = -1;
				_shownText = -1f;
			}
		}
	}

	private void CheckSent()
	{
		if (_sent.Count == 0)
		{
			return;
		}
		float time = Time.time;
		foreach (Sent item in _sent.Values.ToList())
		{
			if (time < item.Due)
			{
				continue;
			}
			ZNetView val = (((Object)(object)item.Sign != (Object)null) ? NView(item.Sign) : null);
			if ((Object)(object)val == (Object)null || !val.IsValid())
			{
				_sent.Remove(item.Op.OpId);
				BoardOps.LogProblem($"Board change {item.Op} dropped: the board is gone from this game (out of range or removed).");
				continue;
			}
			if (item.Tries >= 3)
			{
				_sent.Remove(item.Op.OpId);
				Forget(item);
				BoardOps.LogProblem($"Board change {item.Op} gave up after {3} tries (owner peer {val.GetZDO().GetOwner()}).");
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "The board didn't take your change. Try again.", 0, (Sprite)null, false);
				}
				continue;
			}
			item.Tries++;
			item.Due = time + 4f;
			bool flag = item.Tries == 3;
			BoardOps.LogProblem($"Board change {item.Op}: no answer from the board's owner (peer {val.GetZDO().GetOwner()}); sending it again " + string.Format("(try {0} of {1}{2}).", item.Tries, 3, flag ? ", this game takes the board over" : ""));
			Transmit(item, flag);
			if ((Object)(object)item.Sign == (Object)(object)_sign)
			{
				_nextRefresh = 0f;
			}
		}
	}

	private void Reread()
	{
		if (!((Object)(object)_sign == (Object)null))
		{
			string text = ReadRaw(_sign);
			if (text != _raw)
			{
				_raw = text;
				_tasks = Parse(text);
			}
		}
	}

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

	private static void ShowFull()
	{
		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);
		}
	}

	private void AddTask()
	{
		string text = Clean(_input).Trim();
		if (text.Length == 0)
		{
			return;
		}
		if (text.Length > MaxLength.Value)
		{
			text = text.Substring(0, MaxLength.Value);
		}
		_focusInput = true;
		if (_tasks.Count >= MaxTasks.Value)
		{
			ShowFull();
			return;
		}
		string input = _input;
		_input = "";
		if (!Send(new BoardOps.Op
		{
			Kind = BoardOps.Kind.Add,
			TaskId = Guid8(),
			Text = text,
			Who = Me()
		}))
		{
			_input = input;
		}
	}

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

	private void MoveTask(string id, int dir)
	{
		int num = _tasks.FindIndex((TaskItem t) => t.Id == id);
		if (num >= 0)
		{
			bool done = _tasks[num].Done;
			int num2;
			for (num2 = num + dir; num2 >= 0 && num2 < _tasks.Count && _tasks[num2].Done != done; num2 += dir)
			{
			}
			if (num2 >= 0 && num2 < _tasks.Count)
			{
				Send(new BoardOps.Op
				{
					Kind = BoardOps.Kind.Move,
					TaskId = id,
					Other = _tasks[num2].Id,
					Flag = (dir > 0)
				});
			}
		}
	}

	private void SaveEdit()
	{
		string editId = _editId;
		string text = Clean(_editText).Trim();
		if (text.Length > MaxLength.Value)
		{
			text = text.Substring(0, MaxLength.Value);
		}
		_editId = null;
		if (editId != null && text.Length != 0)
		{
			Send(new BoardOps.Op
			{
				Kind = BoardOps.Kind.Edit,
				TaskId = editId,
				Text = text
			});
		}
	}

	private void SetSize(int size)
	{
		if (!((Object)(object)_sign == (Object)null) && IsBoardPiece(_sign))
		{
			size = Mathf.Clamp(size, 0, BoardPiece.Scales.Length - 1);
			if (Send(new BoardOps.Op
			{
				Kind = BoardOps.Kind.Size,
				Number = size
			}))
			{
				_shownSize = size;
				_shownUntil = Time.time + 12f + 1f;
			}
		}
	}

	private void SetTextSize(float scale)
	{
		if (!((Object)(object)_sign == (Object)null) && IsBoardPiece(_sign))
		{
			scale = Mathf.Clamp(scale, 0.7f, 2f);
			if (Send(new BoardOps.Op
			{
				Kind = BoardOps.Kind.TextSize,
				Number = scale
			}))
			{
				_shownText = scale;
				_shownUntil = Time.time + 12f + 1f;
			}
		}
	}

	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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			CheckSent();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Sending board changes again failed: " + ex.Message));
		}
		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 ex2)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Update failed: " + ex2.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_0063: 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_0074: 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_0094: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00da: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		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 num = FitScale(Scale.Value, _window);
			GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num, num, 1f));
			GUISkin skin = GUI.skin;
			GUI.skin = PanelSkin.Get();
			_window = KeepOnScreen(_window, num);
			_window = GUILayout.Window(7014957, _window, new WindowFunction(DrawWindow), title ?? "To-do", GUI.skin.window, Array.Empty<GUILayoutOption>());
			_window = KeepOnScreen(_window, num);
			GUI.skin = skin;
			GUI.matrix = matrix;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("OnGUI failed: " + ex.Message));
		}
	}

	private static float FitScale(float scale, Rect window)
	{
		float num = scale;
		if (((Rect)(ref window)).width > 1f)
		{
			num = Mathf.Min(num, (float)Screen.width / ((Rect)(ref window)).width);
		}
		if (((Rect)(ref window)).height > 1f)
		{
			num = Mathf.Min(num, (float)Screen.height / ((Rect)(ref window)).height);
		}
		return Mathf.Max(0.3f, num);
	}

	private static Rect KeepOnScreen(Rect window, float scale)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		float num = (float)Screen.width / scale;
		float num2 = (float)Screen.height / scale;
		((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f, Mathf.Max(0f, num - ((Rect)(ref window)).width));
		((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, Mathf.Max(0f, num2 - ((Rect)(ref window)).height));
		return window;
	}

	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_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Invalid comparison between Unknown and I4
		//IL_0565: Unknown result type (might be due to invalid IL or missing references)
		//IL_056c: Invalid comparison between Unknown and I4
		//IL_0570: Unknown result type (might be due to invalid IL or missing references)
		//IL_057a: 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 id = taskItem.Id;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool flag2 = GUILayout.Toggle(taskItem.Done, "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) });
			if (flag2 != taskItem.Done)
			{
				Send(new BoardOps.Op
				{
					Kind = BoardOps.Kind.Tick,
					TaskId = id,
					Flag = flag2,
					Who = Me()
				});
			}
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			if (editId == id)
			{
				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(id, -1);
			}
			GUI.enabled = enabled2;
			if (GUILayout.Button("▼", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				MoveTask(id, 1);
			}
			GUI.enabled = true;
			if (editId != id && GUILayout.Button("Edit", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(56f) }))
			{
				_editId = id;
				_editText = taskItem.Text;
				_focusEdit = true;
			}
			if (GUILayout.Button("✕", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				if (_editId == id)
				{
					_editId = null;
				}
				Send(new BoardOps.Op
				{
					Kind = BoardOps.Kind.Delete,
					TaskId = id
				});
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndScrollView();
		GUILayout.Space(4f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		Event current2 = Event.current;
		bool flag3 = (int)current2.type == 4 && ((int)current2.keyCode == 13 || (int)current2.keyCode == 271) && GUI.GetNameOfFocusedControl() == "anwo_task_input";
		if (flag3)
		{
			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) }) || flag3)
		{
			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
			{
			}
			if (_shownSize >= 0)
			{
				if (num3 == _shownSize || Time.time > _shownUntil)
				{
					_shownSize = -1;
				}
				else
				{
					num3 = _shownSize;
				}
			}
			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
			{
			}
			if (_shownText > 0f)
			{
				if (Mathf.Abs(num5 - _shownText) < 0.001f || Time.time > _shownUntil)
				{
					_shownText = -1f;
				}
				else
				{
					num5 = _shownText;
				}
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Text size", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			bool changed = GUI.changed;
			GUI.changed = false;
			float num6 = GUILayout.HorizontalSlider(num5, 0.7f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
			bool flag4 = GUI.changed && Mathf.Abs(num6 - num5) > 0.0001f;
			GUI.changed = changed || GUI.changed;
			float num7 = (flag4 ? (Mathf.Round(num6 * 10f) / 10f) : num5);
			GUILayout.Label(Mathf.RoundToInt(num7 * 100f) + "%", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) });
			if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				num7 = Mathf.Ceil(num5 * 10f - 0.001f) / 10f - 0.1f;
				flag4 = true;
			}
			if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(32f) }))
			{
				num7 = Mathf.Floor(num5 * 10f + 0.001f) / 10f + 0.1f;
				flag4 = true;
			}
			num7 = Mathf.Clamp(Mathf.Round(num7 * 10f) / 10f, 0.7f, 2f);
			if (flag4 && Mathf.Abs(num7 - num5) > 0.001f)
			{
				SetTextSize(num7);
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Clear done", Array.Empty<GUILayoutOption>()))
		{
			Send(new BoardOps.Op
			{
				Kind = BoardOps.Kind.ClearDone
			});
		}
		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();
	}
}
internal static class BoardOps
{
	internal enum Kind
	{
		Add = 1,
		Edit,
		Tick,
		Delete,
		Move,
		ClearDone,
		Size,
		TextSize
	}

	internal enum Result
	{
		Done,
		NoChange,
		NotFound,
		Full,
		NotOwner,
		NotBoard,
		Failed
	}

	internal sealed class Op
	{
		public string OpId = "";

		public Kind Kind;

		public string TaskId = "";

		public string Other = "";

		public string Text = "";

		public string Who = "";

		public bool Flag;

		public float Number;

		internal bool IsListChange
		{
			get
			{
				if (Kind != Kind.Size)
				{
					return Kind != Kind.TextSize;
				}
				return false;
			}
		}

		internal ZPackage ToPackage()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write(OpId ?? "");
			val.Write((int)Kind);
			val.Write(TaskId ?? "");
			val.Write(Other ?? "");
			val.Write(Text ?? "");
			val.Write(Who ?? "");
			val.Write(Flag);
			val.Write(Number);
			return val;
		}

		internal static Op Read(ZPackage pkg)
		{
			int num = pkg.ReadInt();
			Op op = new Op
			{
				OpId = pkg.ReadString()
			};
			if (num != 1)
			{
				return op;
			}
			op.Kind = (Kind)pkg.ReadInt();
			op.TaskId = Id(pkg.ReadString());
			op.Other = Id(pkg.ReadString());
			string text = GroupBoardPlugin.Clean(pkg.ReadString()).Trim();
			int num2 = ((GroupBoardPlugin.MaxLength != null) ? GroupBoardPlugin.MaxLength.Value : 120);
			op.Text = ((text.Length > num2) ? text.Substring(0, num2) : text);
			op.Who = GroupBoardPlugin.Clean(pkg.ReadString()).Trim();
			op.Flag = pkg.ReadBool();
			op.Number = pkg.ReadSingle();
			return op;
		}

		private static string Id(string s)
		{
			s = GroupBoardPlugin.Clean(s).Trim();
			if (s.Length <= 16)
			{
				return s;
			}
			return s.Substring(0, 16);
		}

		public override string ToString()
		{
			return "'" + Kind.ToString().ToLowerInvariant() + (string.IsNullOrEmpty(TaskId) ? "" : (" " + TaskId)) + "'";
		}
	}

	internal const string RpcOp = "anwo_todo_op";

	internal const string RpcResult = "anwo_todo_result";

	private const int Format = 1;

	private static int s_appliedLogs;

	private static int s_problemLogs;

	private static int s_answeredLogs;

	internal static void LogApplied(string text)
	{
		if (s_appliedLogs < 10)
		{
			s_appliedLogs++;
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogInfo((object)(text + ((s_appliedLogs == 10) ? " (no more of these this session)" : "")));
			}
		}
	}

	internal static void LogAnswered(string text)
	{
		if (s_answeredLogs < 10)
		{
			s_answeredLogs++;
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogInfo((object)(text + ((s_answeredLogs == 10) ? " (no more of these this session)" : "")));
			}
		}
	}

	internal static void LogProblem(string text)
	{
		if (s_problemLogs < 20)
		{
			s_problemLogs++;
			ManualLogSource log = GroupBoardPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)(text + ((s_problemLogs == 20) ? " (no more of these this session)" : "")));
			}
		}
	}

	internal static void Register(Sign sign)
	{
		ZNetView val = GroupBoardPlugin.NView(sign);
		if (!((Object)(object)val == (Object)null) && val.GetZDO() != null)
		{
			val.Register<ZPackage>("anwo_todo_op", (Action<long, ZPackage>)delegate(long sender, ZPackage pkg)
			{
				OnOp(sign, sender, pkg);
			});
			val.Register<string, int>("anwo_todo_result", (Action<long, string, int>)delegate(long sender, string opId, int result)
			{
				GroupBoardPlugin.Instance?.OnResult(sign, sender, opId, (Result)result);
			});
		}
	}

	private static void OnOp(Sign sign, long sender, ZPackage pkg)
	{
		ZNetView val = GroupBoardPlugin.NView(sign);
		if ((Object)(object)val == (Object)null || !val.IsValid())
		{
			return;
		}
		Op op = null;
		int count = -1;
		Result result;
		try
		{
			op = Op.Read(pkg);
			result = ((!val.IsOwner()) ? Result.NotOwner : ApplyOnOwner(sign, val.GetZDO(), op, out count));
		}
		catch (Exception ex)
		{
			result = Result.Failed;
			LogProblem("Making a board change failed: " + ex.Message);
		}
		if (op == null)
		{
			return;
		}
		string text = string.Format("Board change {0} from peer {1}{2}: {3}", op, sender, (op.Who.Length > 0) ? (" (" + op.Who + ")") : "", result) + ((count >= 0) ? $", {count} tasks on the board." : ".");
		if (result == Result.Done || result == Result.NoChange)
		{
			LogApplied(text);
		}
		else
		{
			LogProblem(text + ((result == Result.NotFound) ? " The task is gone (someone else removed it first)." : ""));
		}
		try
		{
			val.InvokeRPC(sender, "anwo_todo_result", new object[2]
			{
				op.OpId,
				(int)result
			});
		}
		catch (Exception ex2)
		{
			LogProblem("Answering a board change failed: " + ex2.Message);
		}
	}

	private static Result ApplyOnOwner(Sign sign, ZDO zdo, Op op, out int count)
	{
		count = -1;
		if (op.Kind == Kind.Size || op.Kind == Kind.TextSize)
		{
			if (!GroupBoardPlugin.IsBoardPiece(sign))
			{
				return Result.NotBoard;
			}
			if (op.Kind == Kind.Size)
			{
				int num = Mathf.Clamp(Mathf.RoundToInt(op.Number), 0, BoardPiece.Scales.Length - 1);
				if (zdo.GetInt("anwo_board_size", -1) == num)
				{
					return Result.NoChange;
				}
				zdo.Set("anwo_board_size", num);
				return Result.Done;
			}
			if (float.IsNaN(op.Number) || float.IsInfinity(op.Number))
			{
				return Result.Failed;
			}
			float num2 = Mathf.Clamp(op.Number, 0.7f, 2f);
			if (Mathf.Abs(zdo.GetFloat("anwo_board_text", -1f) - num2) < 0.0001f)
			{
				return Result.NoChange;
			}
			zdo.Set("anwo_board_text", num2);
			return Result.Done;
		}
		string text = zdo.GetString("anwo_todo", "") ?? "";
		List<GroupBoardPlugin.TaskItem> list = GroupBoardPlugin.Parse(text);
		Result result = ApplyTo(list, op);
		count = list.Count;
		if (result != Result.Done)
		{
			return result;
		}
		string text2 = GroupBoardPlugin.Serialize(list);
		if (text2 == text)
		{
			return Result.NoChange;
		}
		zdo.Set("anwo_todo", text2);
		return Result.Done;
	}

	internal static Result ApplyTo(List<GroupBoardPlugin.TaskItem> list, Op op)
	{
		GroupBoardPlugin.TaskItem taskItem = ((op.TaskId.Length > 0) ? list.FirstOrDefault((GroupBoardPlugin.TaskItem t) => t.Id == op.TaskId) : null);
		switch (op.Kind)
		{
		case Kind.Add:
			if (op.TaskId.Length == 0 || op.Text.Length == 0)
			{
				return Result.Failed;
			}
			if (taskItem != null)
			{
				return Result.NoChange;
			}
			if (list.Count >= GroupBoardPlugin.MaxTasks.Value)
			{
				return Result.Full;
			}
			list.Add(new GroupBoardPlugin.TaskItem
			{
				Id = op.TaskId,
				Done = false,
				Author = op.Who,
				DoneBy = "",
				Text = op.Text
			});
			return Result.Done;
		case Kind.Edit:
			if (taskItem == null)
			{
				return Result.NotFound;
			}
			if (op.Text.Length == 0)
			{
				return Result.Failed;
			}
			taskItem.Text = op.Text;
			return Result.Done;
		case Kind.Tick:
			if (taskItem == null)
			{
				return Result.NotFound;
			}
			taskItem.Done = op.Flag;
			taskItem.DoneBy = (op.Flag ? op.Who : "");
			return Result.Done;
		case Kind.Delete:
			if (taskItem == null)
			{
				return Result.NotFound;
			}
			list.RemoveAll((GroupBoardPlugin.TaskItem t) => t.Id == op.TaskId);
			return Result.Done;
		case Kind.Move:
		{
			if (taskItem == null || op.Other == op.TaskId || !list.Any((GroupBoardPlugin.TaskItem t) => t.Id == op.Other))
			{
				return Result.NotFound;
			}
			list.Remove(taskItem);
			int num = list.FindIndex((GroupBoardPlugin.TaskItem t) => t.Id == op.Other);
			list.Insert(op.Flag ? (num + 1) : num, taskItem);
			return Result.Done;
		}
		case Kind.ClearDone:
			if (list.RemoveAll((GroupBoardPlugin.TaskItem t) => t.Done) <= 0)
			{
				return Result.NoChange;
			}
			return Result.Done;
		default:
			return Result.Failed;
		}
	}
}
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 string _face;

	private static int s_faceLogs;

	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;
			}
			string text = ((TMP_Text)_sign.m_textWidget).text;
			if (!force && _face != null && text != _face)
			{
				force = true;
				if (s_faceLogs < 3)
				{
					s_faceLogs++;
					string text2 = text ?? "";
					ManualLogSource log = GroupBoardPlugin.Log;
					if (log != null)
					{
						log.LogInfo((object)("Board face: the game put \"" + ((text2.Length > 40) ? (text2.Substring(0, 40) + "...") : text2) + "\" on it after the list (its check of who named the board finished late); showing the list again."));
					}
				}
			}
			if (force || zDO.DataRevision != _revision)
			{
				_revision = zDO.DataRevision;
				ApplyText();
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log2 = GroupBoardPlugin.Log;
			if (log2 != null)
			{
				log2.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;
		_face = ((((TMP_Text)textWidget).text == text) ? text : null);
	}

	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), "Awake")]
	private static void AwakePostfix(Sign __instance)
	{
		try
		{
			BoardOps.Register(__instance);
		}
		catch (Exception ex)
		{
			BoardOps.LogProblem("A sign could not take board changes: " + ex.Message);
		}
	}

	[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)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (GroupBoardPlugin.IsBoard(__instance, out var title))
			{
				string text = Regex.Replace(__instance.GetText() ?? "", "<[^>]*>", "");
				string text2 = "\n[<color=yellow><b>$KEY_Use</b></color>] Open board";
				if (PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
				{
					text2 = text2 + "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] " + (GroupBoardPlugin.IsBoardPiece(__instance) ? "Rename board" : "Edit sign");
				}
				string text3 = Localization.instance.Localize(text2);
				__result = "\"" + text + "\"" + GroupBoardPlugin.HoverInfo(__instance, title) + text3;
			}
		}
		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;
	}
}