Decompiled source of BluePrinceNotes v1.0.0

Mods/BluePrinceNotes.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using BluePrinceNotes;
using BluePrinceNotes.Features;
using BluePrinceNotes.Game;
using BluePrinceNotes.Notes;
using BluePrinceNotes.UI;
using BluePrinceNotes.Util;
using HarmonyLib;
using Il2Cpp;
using Il2CppBluePrince.UI;
using Il2CppHutongGames.PlayMaker;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSummertimeMadness;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Blue Prince Notes", "1.0.0", "Lucas Pospor", null)]
[assembly: MelonGame("Dogubomb", "BLUE PRINCE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Lucas Pospor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Blue Prince Notes: an in-game notepad for Blue Prince (MelonLoader)")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BluePrinceNotes")]
[assembly: AssemblyTitle("BluePrinceNotes")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BluePrinceNotes
{
	public class Core : MelonMod
	{
		internal static Instance Log;

		internal static MelonPreferences_Category Prefs;

		private readonly List<Feature> _features = new List<Feature>();

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			Prefs = MelonPreferences.CreateCategory("BluePrinceNotes");
			_features.Add(new NotepadFeature());
			foreach (Feature feature in _features)
			{
				feature.Init();
			}
			Log.Msg($"Loaded {_features.Count} feature(s)");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			FsmHooks.OnSceneLoaded();
			foreach (Feature f in _features)
			{
				Run(f, delegate
				{
					f.OnSceneLoaded(sceneName);
				});
			}
		}

		public override void OnUpdate()
		{
			FsmHooks.Tick(((MelonBase)this).HarmonyInstance);
			foreach (Feature feature in _features)
			{
				feature.PollEnabled();
				if (feature.Enabled)
				{
					Run(feature, feature.OnUpdate);
				}
			}
		}

		public override void OnApplicationQuit()
		{
			foreach (Feature feature in _features)
			{
				Run(feature, feature.OnQuit);
			}
		}

		public override void OnLateUpdate()
		{
			foreach (Feature feature in _features)
			{
				if (feature.Enabled)
				{
					Run(feature, feature.OnLateUpdate);
				}
			}
		}

		internal static void Run(Feature f, Action a)
		{
			try
			{
				a();
			}
			catch (Exception value)
			{
				f.Errors++;
				if (f.Errors <= 3)
				{
					Log.Error($"[{f.Name}] {value}");
				}
				if (f.Errors == 3)
				{
					Log.Error("[" + f.Name + "] further errors suppressed");
				}
			}
		}
	}
}
namespace BluePrinceNotes.Util
{
	internal static class FsmHooks
	{
		private const float InstallDelay = 5f;

		private static float _installAt = -1f;

		public static bool Installed { get; private set; }

		public static event Action<FsmState> BeforeEnter;

		public static event Action<FsmState> AfterEnter;

		public static event Action<Harmony> InstallPatches;

		internal static void RaiseBefore(FsmState s)
		{
			Raise(FsmHooks.BeforeEnter, s);
		}

		internal static void RaiseAfter(FsmState s)
		{
			Raise(FsmHooks.AfterEnter, s);
		}

		private static void Raise(Action<FsmState> ev, FsmState s)
		{
			if (ev == null || s == null)
			{
				return;
			}
			Delegate[] invocationList = ev.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<FsmState> action = (Action<FsmState>)invocationList[i];
				try
				{
					action(s);
				}
				catch (Exception value)
				{
					Core.Log.Error($"FSM hook {action.Method.DeclaringType?.Name}: {value}");
				}
			}
		}

		internal static void OnSceneLoaded()
		{
			if (!Installed && _installAt < 0f)
			{
				_installAt = Time.realtimeSinceStartup + 5f;
			}
		}

		internal static void Tick(Harmony harmony)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0087: Expected O, but got Unknown
			if (Installed || _installAt < 0f || Time.realtimeSinceStartup < _installAt)
			{
				return;
			}
			Installed = true;
			if (FsmHooks.BeforeEnter == null && FsmHooks.AfterEnter == null && FsmHooks.InstallPatches == null)
			{
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(typeof(Fsm), "EnterState", (Type[])null, (Type[])null);
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(FsmHooks), "EnterStatePrefix", (Type[])null), new HarmonyMethod(typeof(FsmHooks), "EnterStatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Core.Log.Msg("FSM hooks installed");
			if (FsmHooks.InstallPatches == null)
			{
				return;
			}
			Delegate[] invocationList = FsmHooks.InstallPatches.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<Harmony> action = (Action<Harmony>)invocationList[i];
				try
				{
					action(harmony);
				}
				catch (Exception value)
				{
					Core.Log.Error($"Patch install {action.Method.DeclaringType?.Name}: {value}");
				}
			}
		}

		private static void EnterStatePrefix(FsmState state)
		{
			RaiseBefore(state);
		}

		private static void EnterStatePostfix(FsmState state)
		{
			RaiseAfter(state);
		}

		public static string PathOf(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return "";
			}
			string text = ((Object)go).name;
			Transform parent = go.transform.parent;
			while ((Object)(object)parent != (Object)null)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}
	}
	internal static class FsmUtil
	{
		public static PlayMakerFSM Get(GameObject go, string fsmName = "FSM")
		{
			if ((Object)(object)go == (Object)null)
			{
				return null;
			}
			foreach (PlayMakerFSM component in go.GetComponents<PlayMakerFSM>())
			{
				if (component.FsmName == fsmName)
				{
					return component;
				}
			}
			return null;
		}

		public static PlayMakerFSM Find(string goName, string fsmName = "FSM")
		{
			return Get(GameObject.Find(goName), fsmName);
		}

		public static FsmInt Int(PlayMakerFSM fsm, string name)
		{
			if (fsm == null)
			{
				return null;
			}
			return fsm.FsmVariables.GetFsmInt(name);
		}

		public static FsmFloat Float(PlayMakerFSM fsm, string name)
		{
			if (fsm == null)
			{
				return null;
			}
			return fsm.FsmVariables.GetFsmFloat(name);
		}

		public static FsmBool Bool(PlayMakerFSM fsm, string name)
		{
			if (fsm == null)
			{
				return null;
			}
			return fsm.FsmVariables.GetFsmBool(name);
		}

		public static FsmString String(PlayMakerFSM fsm, string name)
		{
			if (fsm == null)
			{
				return null;
			}
			return fsm.FsmVariables.GetFsmString(name);
		}
	}
	internal readonly struct Hotkey
	{
		private readonly KeyCode _key;

		private readonly bool _shift;

		private readonly bool _ctrl;

		private readonly bool _alt;

		public KeyCode Key => _key;

		public Hotkey(KeyCode key, bool shift = false, bool ctrl = false, bool alt = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			_key = key;
			_shift = shift;
			_ctrl = ctrl;
			_alt = alt;
		}

		public static Hotkey Parse(string text, Hotkey fallback, string feature)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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)
			bool shift = false;
			bool ctrl = false;
			bool alt = false;
			KeyCode result = (KeyCode)0;
			string[] array = (text ?? "").Split('+', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
			foreach (string text2 in array)
			{
				switch (text2.ToLowerInvariant())
				{
				case "shift":
					shift = true;
					continue;
				case "ctrl":
				case "control":
					ctrl = true;
					continue;
				case "alt":
					alt = true;
					continue;
				}
				if (!Enum.TryParse<KeyCode>(text2, ignoreCase: true, out result))
				{
					result = (KeyCode)0;
				}
			}
			if ((int)result == 0)
			{
				Core.Log.Warning($"[{feature}] can't parse hotkey '{text}', using the default");
				return fallback;
			}
			return new Hotkey(result, shift, ctrl, alt);
		}

		public bool Down()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_key == 0 || !Input.GetKeyDown(_key))
			{
				return false;
			}
			if (_shift && !Input.GetKey((KeyCode)304) && !Input.GetKey((KeyCode)303))
			{
				return false;
			}
			if (_ctrl && !Input.GetKey((KeyCode)306) && !Input.GetKey((KeyCode)305))
			{
				return false;
			}
			if (_alt && !Input.GetKey((KeyCode)308) && !Input.GetKey((KeyCode)307))
			{
				return false;
			}
			return true;
		}

		public bool Held()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((int)_key != 0)
			{
				return Input.GetKey(_key);
			}
			return false;
		}
	}
}
namespace BluePrinceNotes.UI
{
	internal sealed class Notebook
	{
		private enum Mode
		{
			List,
			Editor
		}

		private sealed class KeyRepeat
		{
			private KeyCode _held;

			private float _next;

			public void Reset()
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				_held = (KeyCode)0;
			}

			public bool Fire(KeyCode k)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				if (!Application.isFocused)
				{
					_held = (KeyCode)0;
					return false;
				}
				float unscaledTime = Time.unscaledTime;
				if (Input.GetKeyDown(k))
				{
					_held = k;
					_next = unscaledTime + 0.4f;
					return true;
				}
				if (_held != k)
				{
					return false;
				}
				if (!Input.GetKey(k))
				{
					_held = (KeyCode)0;
					return false;
				}
				if (unscaledTime < _next)
				{
					return false;
				}
				_next = unscaledTime + 1f / 30f;
				return true;
			}
		}

		private const int MaxNoteLength = 10000;

		private const int MaxSearch = 60;

		private const float DeleteConfirmTime = 4f;

		private readonly NoteStore _store;

		private bool _loaded;

		private Mode _mode;

		private string _search = "";

		private readonly List<Note> _shown = new List<Note>();

		private readonly List<ListRow> _rows = new List<ListRow>();

		private bool _rowsStale = true;

		private int _selected;

		private Note _deleteArmed;

		private float _deleteArmedAt;

		private Note _editing;

		private bool _editingAdded;

		private readonly TextBuffer _buffer = new TextBuffer(10000);

		private float _goalX = float.NaN;

		private float _blinkFrom;

		private NoteContext _openContext = new NoteContext();

		private readonly KeyRepeat _repeat = new KeyRepeat();

		private const float DoubleClickTime = 0.35f;

		private const float AutoScrollStep = 0.06f;

		private float _wheelRest;

		private float _lastClickAt = -1f;

		private float _swallowClickUntil = -1f;

		private float _nextAutoScroll;

		private float _clicksFrom;

		private Vector2 _lastClickPos;

		private Vector2 _lastMouse;

		private bool _dragging;

		private bool _hoverNow;

		private bool _resetScroll;

		private static double Now => Time.unscaledTimeAsDouble;

		private bool ClickDown
		{
			get
			{
				if (Input.GetMouseButtonDown(0) && Application.isFocused)
				{
					return Time.unscaledTime >= _clicksFrom;
				}
				return false;
			}
		}

		private static bool Ctrl
		{
			get
			{
				if ((Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)) && !Input.GetKey((KeyCode)307))
				{
					return !Input.GetKey((KeyCode)313);
				}
				return false;
			}
		}

		private static bool Shift
		{
			get
			{
				if (!Input.GetKey((KeyCode)304))
				{
					return Input.GetKey((KeyCode)303);
				}
				return true;
			}
		}

		private List<Note> Shown
		{
			get
			{
				if (!_rowsStale)
				{
					return _shown;
				}
				_rowsStale = false;
				_shown.Clear();
				string text = TextFold.Fold(_search.Trim());
				foreach (Note note in _store.Notes)
				{
					if (text.Length <= 0 || TextFold.Fold(note.Text).Contains(text) || TextFold.Fold(note.Context?.Room).Contains(text))
					{
						_shown.Add(note);
					}
				}
				_shown.Sort((Note a, Note b) => b.Edited.CompareTo(a.Edited));
				_rows.Clear();
				foreach (Note item in _shown)
				{
					string text2 = item.Title;
					if (text2.Length == 0)
					{
						text2 = "(empty)";
					}
					bool flag = item == _deleteArmed;
					string meta = (flag ? "Press Delete again to delete this note" : GameContext.Describe(item.Context));
					_rows.Add(new ListRow(text2, meta, flag));
				}
				return _shown;
			}
		}

		private string SaveWarning
		{
			get
			{
				if (!_loaded || !_store.NotSaving)
				{
					return "";
				}
				return " · NOT SAVED (see the MelonLoader log)";
			}
		}

		public Notebook()
		{
			string directory = Path.Combine(MelonEnvironment.UserDataDirectory, "BluePrinceNotes");
			_store = new NoteStore(directory, delegate(string m)
			{
				Core.Log.Msg("[Notepad] " + m);
			}, delegate(string m)
			{
				Core.Log.Warning("[Notepad] " + m);
			});
		}

		public void Opened()
		{
			if (!_loaded)
			{
				_loaded = true;
				_store.Load();
			}
			try
			{
				_openContext = GameContext.Capture();
			}
			catch (Exception ex)
			{
				_openContext = new NoteContext();
				Core.Log.Warning("[Notepad] reading game context: " + ex.Message);
			}
			_mode = Mode.List;
			_search = "";
			_selected = 0;
			_deleteArmed = null;
			_rowsStale = true;
			_repeat.Reset();
			_wheelRest = 0f;
			_dragging = false;
			_lastClickAt = -1f;
			_swallowClickUntil = -1f;
			_nextAutoScroll = 0f;
		}

		public void Closed()
		{
			if (_mode == Mode.Editor)
			{
				LeaveEditor();
			}
			_deleteArmed = null;
			Flush();
		}

		public void Tick()
		{
			_store.Tick(Now);
		}

		public void Flush()
		{
			if (_loaded)
			{
				_store.Flush(Now);
			}
		}

		public void FocusLost()
		{
			_repeat.Reset();
			Flush();
		}

		public bool HandleInput(NotepadView view)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			bool keyDown = Input.GetKeyDown((KeyCode)27);
			if (ClickDown && !view.InsidePage(Vector2.op_Implicit(Input.mousePosition)))
			{
				return true;
			}
			if (_mode != Mode.List)
			{
				return EditorInput(view, keyDown);
			}
			return ListInput(view, keyDown);
		}

		public void FocusGained()
		{
			_clicksFrom = Time.unscaledTime + 0.3f;
		}

		private bool ListInput(NotepadView view, bool esc)
		{
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			if (esc)
			{
				if (_search.Length == 0)
				{
					return true;
				}
				SetSearch("");
				return false;
			}
			bool ctrl = Ctrl;
			if (ctrl && Input.GetKeyDown((KeyCode)110))
			{
				NewNote("");
				return false;
			}
			if (!ctrl)
			{
				string inputString = Input.inputString;
				if (!string.IsNullOrEmpty(inputString))
				{
					string text = _search;
					string text2 = inputString;
					for (int i = 0; i < text2.Length; i++)
					{
						char c = text2[i];
						if (c == '\b')
						{
							if (text.Length > 0)
							{
								text = text.Substring(0, text.Length - ((text.Length < 2 || !char.IsLowSurrogate(text[text.Length - 1])) ? 1 : 2));
							}
						}
						else if (c >= ' ' && c != '\u007f' && text.Length < 60)
						{
							text += c;
						}
					}
					if (text != _search)
					{
						SetSearch(text);
					}
				}
			}
			int count = Shown.Count;
			if (ClickDown)
			{
				int num = view.RowAt(Vector2.op_Implicit(Input.mousePosition));
				if (num >= 0 && num < count)
				{
					_selected = num;
					_swallowClickUntil = Time.unscaledTime + 0.35f;
					_lastClickPos = Vector2.op_Implicit(Input.mousePosition);
					OpenNote(Shown[num]);
					return false;
				}
			}
			int selected = _selected;
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			Vector2 val2 = val - _lastMouse;
			bool num2 = ((Vector2)(ref val2)).sqrMagnitude > 0.25f;
			_lastMouse = val;
			if ((num2 || _hoverNow) && view.PointerShown)
			{
				int num3 = view.RowAt(val);
				if (num3 >= 0 && num3 < count)
				{
					_selected = num3;
				}
			}
			_hoverNow = false;
			_wheelRest += Input.mouseScrollDelta.y;
			while (_wheelRest >= 1f)
			{
				_selected--;
				_wheelRest -= 1f;
			}
			while (_wheelRest <= -1f)
			{
				_selected++;
				_wheelRest += 1f;
			}
			if (_repeat.Fire((KeyCode)273))
			{
				_selected--;
			}
			if (_repeat.Fire((KeyCode)274))
			{
				_selected++;
			}
			if (_repeat.Fire((KeyCode)280))
			{
				_selected -= 8;
			}
			if (_repeat.Fire((KeyCode)281))
			{
				_selected += 8;
			}
			if (Input.GetKeyDown((KeyCode)278))
			{
				_selected = 0;
			}
			if (Input.GetKeyDown((KeyCode)279))
			{
				_selected = count - 1;
			}
			_selected = Mathf.Clamp(_selected, 0, Mathf.Max(0, count - 1));
			if (_selected != selected && _deleteArmed != null)
			{
				_deleteArmed = null;
				_rowsStale = true;
			}
			if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
			{
				if (count > 0)
				{
					OpenNote(Shown[_selected]);
				}
				else if (_search.Trim().Length > 0)
				{
					NewNote(_search.Trim());
				}
				return false;
			}
			if (Input.GetKeyDown((KeyCode)127) && count > 0)
			{
				Note note = Shown[_selected];
				if (_deleteArmed == note && Time.unscaledTime - _deleteArmedAt < 4f)
				{
					_store.Remove(note, Now);
					_deleteArmed = null;
					_rowsStale = true;
					Core.Log.Msg($"[Notepad] deleted a note ({_store.Notes.Count} left)");
				}
				else
				{
					_deleteArmed = note;
					_deleteArmedAt = Time.unscaledTime;
					_rowsStale = true;
				}
				return false;
			}
			if (_deleteArmed != null && Time.unscaledTime - _deleteArmedAt >= 4f)
			{
				_deleteArmed = null;
				_rowsStale = true;
			}
			return false;
		}

		private void SetSearch(string s)
		{
			_search = s;
			_selected = 0;
			_deleteArmed = null;
			_rowsStale = true;
		}

		private bool EditorInput(NotepadView view, bool esc)
		{
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			if (esc)
			{
				LeaveEditor();
				return false;
			}
			double now = Now;
			int version = _buffer.Version;
			int caret = _buffer.Caret;
			int anchor = _buffer.Anchor;
			bool ctrl = Ctrl;
			bool shift = Shift;
			bool flag = !string.IsNullOrEmpty(Input.compositionString);
			if (ctrl)
			{
				if (Input.GetKeyDown((KeyCode)97))
				{
					_buffer.SelectAll();
				}
				if (Input.GetKeyDown((KeyCode)99) && _buffer.HasSelection)
				{
					Copy(_buffer.SelectedText);
				}
				if (Input.GetKeyDown((KeyCode)120) && _buffer.HasSelection)
				{
					Copy(_buffer.SelectedText);
					_buffer.DeleteSelection(now);
				}
				if (Input.GetKeyDown((KeyCode)118))
				{
					Paste(now);
				}
				if (Input.GetKeyDown((KeyCode)122))
				{
					if (shift)
					{
						_buffer.Redo();
					}
					else
					{
						_buffer.Undo();
					}
				}
				if (Input.GetKeyDown((KeyCode)121))
				{
					_buffer.Redo();
				}
			}
			if (!flag)
			{
				bool flag2 = false;
				if (_repeat.Fire((KeyCode)276))
				{
					_buffer.Left(ctrl, shift);
				}
				if (_repeat.Fire((KeyCode)275))
				{
					_buffer.Right(ctrl, shift);
				}
				if (_repeat.Fire((KeyCode)273))
				{
					_buffer.MoveTo(view.Vertical(_buffer.Caret, -1, ref _goalX), shift);
					flag2 = true;
				}
				if (_repeat.Fire((KeyCode)274))
				{
					_buffer.MoveTo(view.Vertical(_buffer.Caret, 1, ref _goalX), shift);
					flag2 = true;
				}
				if (_repeat.Fire((KeyCode)280))
				{
					_buffer.MoveTo(view.Page(_buffer.Caret, -1, ref _goalX), shift);
					flag2 = true;
				}
				if (_repeat.Fire((KeyCode)281))
				{
					_buffer.MoveTo(view.Page(_buffer.Caret, 1, ref _goalX), shift);
					flag2 = true;
				}
				if (Input.GetKeyDown((KeyCode)278))
				{
					_buffer.MoveTo((!ctrl) ? view.Home(_buffer.Caret) : 0, shift);
				}
				if (Input.GetKeyDown((KeyCode)279))
				{
					_buffer.MoveTo(ctrl ? _buffer.Length : view.End(_buffer.Caret), shift);
				}
				if (_repeat.Fire((KeyCode)127))
				{
					_buffer.Delete(ctrl, now);
				}
				if (ctrl && _repeat.Fire((KeyCode)8))
				{
					_buffer.Backspace(word: true, now);
				}
				bool flag3 = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
				if (!ctrl && !flag3 && _repeat.Fire((KeyCode)9))
				{
					_buffer.Insert("    ", now);
				}
				if (!flag2 && (_buffer.Caret != caret || _buffer.Version != version))
				{
					_goalX = float.NaN;
				}
			}
			string inputString = Input.inputString;
			if (!string.IsNullOrEmpty(inputString))
			{
				int num = 0;
				for (int i = 0; i <= inputString.Length; i++)
				{
					char c = ((i < inputString.Length) ? inputString[i] : '\0');
					if (i == inputString.Length || c == '\b' || c == '\u007f' || c == '\t' || (ctrl && c != '\r' && c != '\n'))
					{
						if (i > num)
						{
							_buffer.Insert(inputString.Substring(num, i - num), now);
						}
						if (c == '\b' && !ctrl)
						{
							_buffer.Backspace(word: false, now);
						}
						num = i + 1;
					}
				}
				_goalX = float.NaN;
			}
			float y = Input.mouseScrollDelta.y;
			if (y != 0f)
			{
				view.ScrollLines((0f - y) * 3f);
			}
			if (!flag)
			{
				Vector2 val = Vector2.op_Implicit(Input.mousePosition);
				Vector2 val2;
				if (ClickDown && Time.unscaledTime < _swallowClickUntil)
				{
					val2 = val - _lastClickPos;
					if (((Vector2)(ref val2)).sqrMagnitude < 100f)
					{
						_swallowClickUntil = -1f;
						goto IL_05d9;
					}
				}
				if (ClickDown && view.InsideText(val))
				{
					int num2 = view.IndexAt(val);
					if (num2 >= 0)
					{
						if (Time.unscaledTime - _lastClickAt < 0.35f)
						{
							val2 = val - _lastClickPos;
							if (((Vector2)(ref val2)).sqrMagnitude < 100f)
							{
								int num3 = view.CharAt(val);
								_buffer.SelectWordAt((num3 >= 0) ? num3 : num2);
								_dragging = false;
								_lastClickAt = -1f;
								goto IL_0559;
							}
						}
						_buffer.MoveTo(num2, shift);
						_dragging = true;
						_lastClickAt = Time.unscaledTime;
						_lastClickPos = val;
						goto IL_0559;
					}
				}
				else if (_dragging && Input.GetMouseButton(0))
				{
					bool flag4 = Time.unscaledTime >= _nextAutoScroll;
					int num4 = view.IndexAt(val, flag4 ? 1 : 0);
					if (flag4)
					{
						_nextAutoScroll = Time.unscaledTime + 0.06f;
					}
					if (num4 >= 0 && num4 != _buffer.Caret)
					{
						_buffer.MoveTo(num4, extend: true);
						_goalX = float.NaN;
					}
				}
				goto IL_05d9;
			}
			goto IL_05e8;
			IL_0559:
			_goalX = float.NaN;
			goto IL_05d9;
			IL_05d9:
			if (!Input.GetMouseButton(0))
			{
				_dragging = false;
			}
			goto IL_05e8;
			IL_05e8:
			if (_buffer.Version != version)
			{
				_editing.Text = _buffer.Text;
				_editing.Edited = DateTime.UtcNow;
				if (!_editingAdded && !_editing.IsBlank)
				{
					_store.Add(_editing, now);
					_editingAdded = true;
				}
				else if (_editingAdded)
				{
					_store.Changed(now);
				}
				_rowsStale = true;
			}
			if (_buffer.Version != version || _buffer.Caret != caret || _buffer.Anchor != anchor)
			{
				_blinkFrom = Time.unscaledTime;
				view.FollowCaret();
			}
			return false;
		}

		private static void Copy(string s)
		{
			try
			{
				GUIUtility.systemCopyBuffer = s;
			}
			catch (Exception ex)
			{
				Core.Log.Warning("[Notepad] copy failed: " + ex.Message);
			}
		}

		private void Paste(double now)
		{
			string systemCopyBuffer;
			try
			{
				systemCopyBuffer = GUIUtility.systemCopyBuffer;
			}
			catch (Exception ex)
			{
				Core.Log.Warning("[Notepad] paste failed: " + ex.Message);
				return;
			}
			if (!string.IsNullOrEmpty(systemCopyBuffer))
			{
				_buffer.Insert(systemCopyBuffer, now, paste: true);
			}
		}

		private void NewNote(string text)
		{
			DateTime utcNow = DateTime.UtcNow;
			Note note = (_editing = new Note
			{
				Created = utcNow,
				Edited = utcNow,
				Text = text,
				Context = Copy(_openContext)
			});
			_editingAdded = false;
			if (!note.IsBlank)
			{
				_store.Add(note, Now);
				_editingAdded = true;
			}
			Edit(note);
		}

		private void OpenNote(Note note)
		{
			_editing = note;
			_editingAdded = true;
			Edit(note);
		}

		private void Edit(Note note)
		{
			if (TextBuffer.Clean(note.Text, int.MaxValue).Length > 10000)
			{
				Core.Log.Warning($"[Notepad] this note is longer than {10000} characters; editing it keeps the first {10000}");
			}
			_buffer.Reset(note.Text);
			_mode = Mode.Editor;
			_dragging = false;
			_goalX = float.NaN;
			_blinkFrom = Time.unscaledTime;
			_deleteArmed = null;
			_resetScroll = true;
		}

		private void LeaveEditor()
		{
			if (_editing != null)
			{
				if (_editing.IsBlank)
				{
					if (_editingAdded)
					{
						_store.Remove(_editing, Now);
					}
				}
				else
				{
					SetSearch("");
					_selected = Math.Max(0, Shown.IndexOf(_editing));
				}
			}
			_editing = null;
			_mode = Mode.List;
			_rowsStale = true;
			_hoverNow = true;
			Flush();
		}

		private static NoteContext Copy(NoteContext c)
		{
			return new NoteContext
			{
				Day = c.Day,
				Area = c.Area,
				Room = c.Room,
				Rank = c.Rank,
				Tile = c.Tile,
				SaveSlot = c.SaveSlot,
				Seed = c.Seed,
				DayStartClock = c.DayStartClock
			};
		}

		public void Render(NotepadView view, string closeKey)
		{
			if (_mode == Mode.List)
			{
				List<Note> shown = Shown;
				string header = ((_store.Notes.Count == 0) ? "Notes" : $"Notes ({_store.Notes.Count})") + SaveWarning;
				string hint = "Enter open · Ctrl+N new · Delete delete · type to search · Esc or " + closeKey + " close";
				string search = ((_search.Length > 0) ? ("Search: " + _search) : null);
				string empty = ((_search.Trim().Length > 0) ? "No notes match. Press Enter to start one with this text." : "No notes yet. Press Ctrl+N to start one.");
				view.ShowList(header, hint, search, _rows, (shown.Count > 0) ? _selected : (-1), empty);
				return;
			}
			if (_resetScroll)
			{
				_resetScroll = false;
				view.ResetScroll();
			}
			string text = GameContext.Describe(_editing?.Context);
			bool caretOn = (Time.unscaledTime - _blinkFrom) % 1f < 0.55f;
			string composing = "";
			try
			{
				composing = Input.compositionString ?? "";
			}
			catch
			{
			}
			view.ShowEditor(((text.Length > 0) ? text : "New note") + SaveWarning, "Esc back to the list · " + closeKey + " close", _buffer.Text, _buffer.Caret, _buffer.Anchor, caretOn, composing);
		}
	}
	internal static class NotebookPaper
	{
		internal struct Geometry
		{
			public int PageW;

			public int PageH;

			public int Border;

			public float S;

			public float MarginX;

			public float HeaderRuleY;

			public float FirstRuleY;

			public float RuleStep;

			public int RuleCount;

			public int Seed;
		}

		private readonly struct Vec3
		{
			public readonly float X;

			public readonly float Y;

			public readonly float Z;

			public Vec3(float x, float y, float z)
			{
				X = x;
				Y = y;
				Z = z;
			}

			public static Vec3 operator *(Vec3 a, float k)
			{
				return new Vec3(a.X * k, a.Y * k, a.Z * k);
			}

			public static Vec3 Lerp(Vec3 a, Vec3 b, float t)
			{
				return new Vec3(a.X + (b.X - a.X) * t, a.Y + (b.Y - a.Y) * t, a.Z + (b.Z - a.Z) * t);
			}
		}

		private static readonly Vec3 Paper = new Vec3(0.957f, 0.933f, 0.859f);

		private static readonly Vec3 PaperAged = new Vec3(0.925f, 0.875f, 0.76f);

		private static readonly Vec3 EdgeTone = new Vec3(0.835f, 0.77f, 0.64f);

		private static readonly Vec3 FibreDark = new Vec3(0.56f, 0.505f, 0.42f);

		private static readonly Vec3 FibreLight = new Vec3(1f, 0.995f, 0.965f);

		private static readonly Vec3 StainTone = new Vec3(0.64f, 0.5f, 0.31f);

		private static readonly Vec3 RuleBlue = new Vec3(0.42f, 0.58f, 0.8f);

		private const float RuleBlueA = 0.62f;

		private static readonly Vec3 MarginRed = new Vec3(0.86f, 0.33f, 0.36f);

		private const float MarginRedA = 0.78f;

		private static readonly Vec3 HeaderRed = new Vec3(0.64f, 0.11f, 0.15f);

		private const float HeaderRedA = 0.85f;

		private const float ShadowA = 0.55f;

		public static byte[] Build(in Geometry g, out int texW, out int texH)
		{
			int pageW = g.PageW;
			int pageH = g.PageH;
			int border = g.Border;
			float s = g.S;
			texW = pageW + 2 * border;
			texH = pageH + 2 * border;
			byte[] array = new byte[texW * texH * 4];
			Random random = new Random(g.Seed);
			float[] array2 = new float[pageW * pageH];
			int num = (int)((float)((long)pageW * (long)pageH) / (s * s * 2.2f));
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)random.NextDouble() * (float)pageW;
				float num3 = (float)random.NextDouble() * (float)pageH;
				float num4 = s * (0.25f + 0.85f * (float)random.NextDouble());
				float num5 = (float)(random.NextDouble() * Math.PI * 2.0);
				float num6 = ((float)random.NextDouble() - 0.5f) * 2.5f / num4;
				float num7 = ((random.NextDouble() < 0.72) ? (0.05f + 0.07f * (float)random.NextDouble()) : (0f - (0.05f + 0.06f * (float)random.NextDouble())));
				int num8 = (int)(num4 * 2f);
				for (int j = 0; j < num8; j++)
				{
					float num9 = (float)j / (float)num8;
					Splat(array2, pageW, pageH, num2, num3, num7 * MathF.Sin(num9 * (float)Math.PI));
					num5 += num6 * 0.5f;
					num2 += MathF.Cos(num5) * 0.5f;
					num3 += MathF.Sin(num5) * 0.5f;
				}
			}
			(float, float, float, float, float)[] array3 = new(float, float, float, float, float)[14]
			{
				((float)pageW - s * (1.2f + (float)random.NextDouble()), (float)pageH - s * (0.6f + (float)random.NextDouble()), s * 2.6f, 0.03f, 0.11f),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float)),
				default((float, float, float, float, float))
			};
			float num10 = (float)pageW * (0.15f + 0.6f * (float)random.NextDouble());
			float num11 = (float)pageH * (0.08f + 0.15f * (float)random.NextDouble());
			for (int k = 1; k < array3.Length; k++)
			{
				float x = (float)(random.NextDouble() * Math.PI * 2.0);
				float num12 = s * 2.2f * (float)Math.Sqrt(random.NextDouble());
				array3[k] = (num10 + MathF.Cos(x) * num12 * 1.8f, num11 + MathF.Sin(x) * num12 * 0.7f, s * (0.04f + 0.12f * (float)random.NextDouble()), 0.1f + 0.12f * (float)random.NextDouble(), 0f);
			}
			float thickness = MathF.Max(1f, 0.05f * s);
			float thickness2 = MathF.Max(1f, 0.055f * s);
			float thickness3 = MathF.Max(1f, 0.03f * s);
			float num13 = 0.13f * s;
			float thickness4 = MathF.Max(1f, 0.055f * s);
			float[] array4 = new float[pageH];
			float[] array5 = new float[pageH];
			for (int l = 0; l < pageH; l++)
			{
				float num14 = 0f;
				for (int m = 0; m < g.RuleCount; m++)
				{
					num14 = MathF.Max(num14, Cover(l, g.FirstRuleY + (float)m * g.RuleStep, thickness));
				}
				array4[l] = num14;
				array5[l] = MathF.Max(Cover(l, g.HeaderRuleY, thickness2), Cover(l, g.HeaderRuleY + num13, thickness3));
			}
			float[] array6 = new float[pageW];
			for (int n = 0; n < pageW; n++)
			{
				array6[n] = Cover(n, g.MarginX, thickness4);
			}
			float r = 0.22f * s;
			float num15 = 0.22f * s;
			float num16 = g.Seed % 997;
			float num17 = (float)pageW * 0.5f;
			float num18 = (float)pageH * 0.5f;
			int num19 = pageW / 4 + 2;
			int num20 = pageH / 4 + 2;
			float[] array7 = new float[num19 * num20];
			for (int num21 = 0; num21 < num20; num21++)
			{
				for (int num22 = 0; num22 < num19; num22++)
				{
					array7[num21 * num19 + num22] = Fbm((float)(num22 * 4) / (7f * s), (float)(num21 * 4) / (7f * s), 3, g.Seed + 11);
				}
			}
			for (int num23 = 0; num23 < texH; num23++)
			{
				int num24 = (texH - 1 - num23) * texW * 4;
				float num25 = (float)(num23 - border) + 0.5f;
				int num26 = num23 - border;
				bool flag = num26 >= 0 && num26 < pageH;
				float num27 = (flag ? array4[num26] : 0f);
				float num28 = (flag ? array5[num26] : 0f);
				for (int num29 = 0; num29 < texW; num29++)
				{
					float num30 = (float)(num29 - border) + 0.5f;
					int num31 = num29 - border;
					int num32 = num24 + num29 * 4;
					float num33 = RoundRect(num30 - num17, num25 - num18, num17, num18, r);
					float num34 = Clamp01(0.5f - num33);
					float num35 = 0f;
					if (num34 < 1f)
					{
						float num36 = RoundRect(num30 - num17, num25 - num18 - num15, num17 - 0.1f * s, num18, r);
						num35 = 0.55f * MathF.Pow(Clamp01(1f - (num36 + 0.15f * s) / ((float)border * 1.05f)), 2.2f);
						num35 = MathF.Max(num35, 0.35f * Clamp01(1f - MathF.Max(0f, num33) / (0.12f * s)));
						if (num34 <= 0f)
						{
							array[num32] = (array[num32 + 1] = (array[num32 + 2] = 0));
							array[num32 + 3] = ToByte(num35);
							continue;
						}
					}
					float num37 = Math.Clamp(num30, 0f, (float)pageW - 1f) / 4f;
					float num38 = Math.Clamp(num25, 0f, (float)pageH - 1f) / 4f;
					int num39 = (int)num37;
					int num40 = (int)num38;
					float t = num37 - (float)num39;
					float t2 = num38 - (float)num40;
					int num41 = num40 * num19 + num39;
					float v = Lerp(Lerp(array7[num41], array7[num41 + 1], t), Lerp(array7[num41 + num19], array7[num41 + num19 + 1], t), t2);
					float num42 = Fbm(num30 / (0.9f * s), num25 / (0.9f * s), 3, g.Seed + 23);
					float num43 = Hash(num29, num23, g.Seed + 37);
					Vec3 a = Vec3.Lerp(Paper, PaperAged, 0.55f * SmoothStep(0.35f, 0.8f, v));
					a *= 1f + 0.035f * (num42 - 0.5f) * 2f + 0.022f * (num43 - 0.5f) * 2f;
					float num44 = (num30 - num17) / num17;
					float num45 = (num25 - num18) / num18;
					a *= 1f - 0.035f * (num44 * num44 + num45 * num45);
					float num46 = MathF.Min(MathF.Min(num30, (float)pageW - num30), MathF.Min(num25, (float)pageH - num25));
					if (num46 < 1.4f * s)
					{
						float num47 = 0.6f + 0.8f * Noise(num30 / (1.5f * s), num25 / (1.5f * s), g.Seed + 41);
						a = Vec3.Lerp(a, EdgeTone, 0.55f * (1f - SmoothStep(0f, 0.9f * s * num47, num46)));
					}
					if (num30 < 8f * s)
					{
						a *= 1f - 0.07f * MathF.Exp((0f - num30) / (0.35f * s)) - 0.03f * MathF.Exp((0f - num30) / (1.6f * s));
					}
					for (int num48 = 0; num48 < array3.Length; num48++)
					{
						(float, float, float, float, float) tuple = array3[num48];
						float num49 = num30 - tuple.Item1;
						float num50 = num25 - tuple.Item2;
						float num51 = tuple.Item3 * 1.3f;
						if (!(num49 * num49 + num50 * num50 > num51 * num51))
						{
							float num52 = MathF.Sqrt(num49 * num49 + num50 * num50) / tuple.Item3;
							num52 += 0.12f * (Noise(num30 / (0.5f * s), num25 / (0.5f * s), g.Seed + 53 + num48) - 0.5f);
							float num53 = tuple.Item4 * (1f - SmoothStep(0.7f, 1f, num52));
							if (tuple.Item5 > 0f)
							{
								num53 += tuple.Item5 * MathF.Exp((0f - (num52 - 1f)) * (num52 - 1f) / 0.004f);
							}
							a = Vec3.Lerp(a, StainTone, num53);
						}
					}
					if (num31 >= 0 && num31 < pageW && flag)
					{
						float num54 = array2[num26 * pageW + num31];
						if (num54 > 0f)
						{
							a = Vec3.Lerp(a, FibreDark, MathF.Min(num54, 0.22f));
						}
						else if (num54 < 0f)
						{
							a = Vec3.Lerp(a, FibreLight, MathF.Min(0f - num54, 0.22f));
						}
					}
					if (num27 > 0f || num28 > 0f)
					{
						float num55 = 0.78f + 0.22f * Noise(num30 / (0.35f * s), num25 * 0.37f + num16, g.Seed + 61);
						if (num27 > 0f)
						{
							a = Vec3.Lerp(a, RuleBlue, 0.62f * num27 * num55);
						}
						if (num28 > 0f)
						{
							a = Vec3.Lerp(a, HeaderRed, 0.85f * num28 * num55);
						}
					}
					if (num31 >= 0 && num31 < pageW)
					{
						float num56 = array6[num31];
						if (num56 > 0f)
						{
							float num57 = 0.78f + 0.22f * Noise(num30 * 0.37f + num16, num25 / (0.35f * s), g.Seed + 67);
							a = Vec3.Lerp(a, MarginRed, 0.78f * num56 * num57);
						}
					}
					float num58 = num34 + num35 * (1f - num34);
					float num59 = num34 / MathF.Max(num58, 1E-05f);
					array[num32] = ToByte(a.X * num59);
					array[num32 + 1] = ToByte(a.Y * num59);
					array[num32 + 2] = ToByte(a.Z * num59);
					array[num32 + 3] = ToByte(num58);
				}
			}
			return array;
		}

		public static byte[] BuildHighlighter(int w, int h, int seed)
		{
			byte[] array = new byte[w * h * 4];
			Vec3 vec = new Vec3(1f, 0.86f, 0.3f);
			for (int i = 0; i < h; i++)
			{
				int num = (h - 1 - i) * w * 4;
				float num2 = ((float)i + 0.5f) / (float)h;
				for (int j = 0; j < w; j++)
				{
					float num3 = (float)j + 0.5f;
					float num4 = 0.1f + 0.06f * Noise(num3 / 9f, 0.5f, seed + 1);
					float num5 = 0.9f - 0.06f * Noise(num3 / 9f, 7.5f, seed + 2);
					float num6 = SmoothStep(num4 - 0.04f, num4 + 0.04f, num2) * (1f - SmoothStep(num5 - 0.04f, num5 + 0.04f, num2));
					float num7 = (num2 - 0.5f) * (float)h * 0.45f;
					float num8 = 0.06f * (float)h + num7;
					float num9 = (float)w - 0.06f * (float)h + num7;
					num6 *= SmoothStep(num8 - 1.5f, num8 + 1.5f, num3) * (1f - SmoothStep(num9 - 1.5f, num9 + 1.5f, num3));
					float num10 = 0.82f + 0.18f * Noise(num3 / 60f, num2 * 9f, seed + 3);
					float num11 = 1f + 0.18f * (MathF.Exp((0f - (num3 - num8)) / (0.4f * (float)h)) + MathF.Exp((0f - (num9 - num3)) / (0.4f * (float)h)));
					num6 = Clamp01(num6 * num10 * num11) * 0.7f;
					int num12 = num + j * 4;
					array[num12] = ToByte(vec.X);
					array[num12 + 1] = ToByte(vec.Y);
					array[num12 + 2] = ToByte(vec.Z);
					array[num12 + 3] = ToByte(num6);
				}
			}
			return array;
		}

		private static float Cover(float pixel, float centre, float thickness)
		{
			float num = MathF.Max(pixel, centre - thickness * 0.5f);
			return Clamp01(MathF.Min(pixel + 1f, centre + thickness * 0.5f) - num);
		}

		private static void Splat(float[] buf, int w, int h, float x, float y, float v)
		{
			int num = (int)MathF.Floor(x - 0.5f);
			int num2 = (int)MathF.Floor(y - 0.5f);
			float num3 = x - 0.5f - (float)num;
			float num4 = y - 0.5f - (float)num2;
			Add(buf, w, h, num, num2, v * (1f - num3) * (1f - num4));
			Add(buf, w, h, num + 1, num2, v * num3 * (1f - num4));
			Add(buf, w, h, num, num2 + 1, v * (1f - num3) * num4);
			Add(buf, w, h, num + 1, num2 + 1, v * num3 * num4);
		}

		private static void Add(float[] buf, int w, int h, int x, int y, float v)
		{
			if ((uint)x < (uint)w && (uint)y < (uint)h)
			{
				buf[y * w + x] += v;
			}
		}

		private static float RoundRect(float x, float y, float hw, float hh, float r)
		{
			float x2 = MathF.Abs(x) - (hw - r);
			float num = MathF.Abs(y) - (hh - r);
			float num2 = MathF.Max(x2, 0f);
			float num3 = MathF.Max(num, 0f);
			return MathF.Sqrt(num2 * num2 + num3 * num3) + MathF.Min(MathF.Max(x2, num), 0f) - r;
		}

		private static float Hash(int x, int y, int seed)
		{
			int num = x * 374761393 + y * 668265263 + seed * -2048144777;
			int num2 = (num ^ (num >>> 13)) * 1274126177;
			return (float)(uint)((num2 ^ (num2 >>> 16)) & 0xFFFFFF) / 16777215f;
		}

		private static float Noise(float x, float y, int seed)
		{
			float num = MathF.Floor(x);
			float num2 = MathF.Floor(y);
			int num3 = (int)num;
			int num4 = (int)num2;
			float num5 = x - num;
			float num6 = y - num2;
			float num7 = num5 * num5 * (3f - 2f * num5);
			float num8 = num6 * num6 * (3f - 2f * num6);
			float num9 = Hash(num3, num4, seed);
			float num10 = Hash(num3 + 1, num4, seed);
			float num11 = Hash(num3, num4 + 1, seed);
			float num12 = Hash(num3 + 1, num4 + 1, seed);
			return num9 + (num10 - num9) * num7 + (num11 - num9) * num8 + (num9 - num10 - num11 + num12) * num7 * num8;
		}

		private static float Fbm(float x, float y, int octaves, int seed)
		{
			float num = 0f;
			float num2 = 0.5f;
			float num3 = 0f;
			for (int i = 0; i < octaves; i++)
			{
				num += num2 * Noise(x, y, seed + i * 1013);
				num3 += num2;
				x *= 2.03f;
				y *= 2.03f;
				num2 *= 0.5f;
			}
			return num / num3;
		}

		private static float Lerp(float a, float b, float t)
		{
			return a + (b - a) * t;
		}

		private static float Clamp01(float v)
		{
			if (!(v < 0f))
			{
				if (!(v > 1f))
				{
					return v;
				}
				return 1f;
			}
			return 0f;
		}

		private static float SmoothStep(float a, float b, float v)
		{
			float num = Clamp01((v - a) / (b - a));
			return num * num * (3f - 2f * num);
		}

		private static byte ToByte(float v)
		{
			return (byte)(Clamp01(v) * 255f + 0.5f);
		}
	}
	internal readonly struct ListRow
	{
		public readonly string Title;

		public readonly string Meta;

		public readonly bool Deleting;

		public ListRow(string title, string meta, bool deleting = false)
		{
			Title = title;
			Meta = meta;
			Deleting = deleting;
		}
	}
	internal sealed class NotepadView
	{
		private sealed class Row
		{
			public TextMeshProUGUI Title;

			public TextMeshProUGUI Meta;
		}

		private const string RootName = "BluePrinceNotes Notepad";

		private const string FallbackFont = "TypeNeat SDF";

		private const int MaxRows = 20;

		private const int PaperSeed = 1912;

		private static readonly Color Ink = new Color(0.075f, 0.065f, 0.07f, 1f);

		private static readonly Color Red = new Color(0.396f, 0f, 0.06f, 1f);

		private static readonly Color CaretColor = new Color(0.7f, 0.08f, 0.12f, 1f);

		private static readonly Color Pencil = new Color(0.142f, 0.119f, 0.119f, 0.78f);

		private static readonly Color PaperFlat = new Color(0.957f, 0.933f, 0.859f, 1f);

		private static readonly Color DimColor = new Color(0f, 0f, 0f, 0.5f);

		private GameObject _root;

		private RectTransform _panel;

		private RectTransform _listArea;

		private RectTransform _viewport;

		private RectTransform _selLayer;

		private RawImage _paper;

		private RawImage _pointer;

		private TextMeshProUGUI _header;

		private TextMeshProUGUI _hint;

		private TextMeshProUGUI _search;

		private TextMeshProUGUI _empty;

		private TextMeshProUGUI _body;

		private TextMeshProUGUI _marker;

		private TextMeshProUGUI _probe;

		private Image _caret;

		private Image _rowMark;

		private Image _strike;

		private readonly List<Image> _selection = new List<Image>();

		private readonly List<Row> _rows = new List<Row>();

		private string _builtFor;

		private float _nextTry;

		private float _s;

		private float _A;

		private float _L;

		private float _em;

		private int _W;

		private int _H;

		private int _B;

		private int _n;

		private float _T;

		private float _M;

		private float _X0;

		private float _X1;

		private string _geomKey;

		private static Texture2D _paperTex;

		private static Texture2D _markTex;

		private static Sprite _markSprite;

		private static string _paperKey;

		private static Task<(byte[] px, int w, int h, string key)> _paperTask;

		private static string _paperTaskKey;

		private static bool _paperFailed;

		private int _listTop;

		private int _listFirst;

		private int _listFit;

		private int _listCount;

		private string _listMarkKey;

		private float _titleWidth;

		private string _layoutKey;

		private string _laidText = "";

		private int _n2;

		private int _lines;

		private float[] _origin = new float[256];

		private float[] _advance = new float[256];

		private int[] _lineOf = new int[256];

		private int[] _index = new int[256];

		private char[] _char = new char[256];

		private int[] _kAt = new int[257];

		private int[] _lFirst = new int[32];

		private int[] _lLast = new int[32];

		private float[] _lAsc = new float[32];

		private float[] _lDesc = new float[32];

		private float _left;

		private float _right;

		private float _lineH;

		private float _asc0;

		private float _desc0;

		private float _scroll;

		private float _bodyX;

		private bool _followCaret = true;

		private float _wheelRest;

		private static int _ciStride = -1;

		private static int _oOrigin;

		private static int _oAdvance;

		private static int _oLine;

		private static int _oIndex;

		private static int _oChar;

		private static bool _ciChecked;

		private Vector2 _mouseAtOpen;

		private bool _mouseMoved;

		private readonly Dictionary<IntPtr, string> _shown = new Dictionary<IntPtr, string>();

		public bool Visible
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return _root.activeSelf;
				}
				return false;
			}
		}

		private int LineCount
		{
			get
			{
				if (_n2 <= 0 || _char[_n2 - 1] != '\n')
				{
					return Math.Max(1, _lines);
				}
				return _lines + 1;
			}
		}

		public bool PointerShown => _mouseMoved;

		private float Baseline(int line)
		{
			return _T + _A + (float)line * _L;
		}

		public bool Begin(string fontName, float fontScale)
		{
			if ((Object)(object)_body == (Object)null || (Object)(object)_header == (Object)null || (Object)(object)((TMP_Text)_body).font == (Object)null || _builtFor != fontName)
			{
				Destroy();
				if (Time.unscaledTime < _nextTry)
				{
					return false;
				}
				_nextTry = Time.unscaledTime + 1f;
				if (!TryCreate(fontName))
				{
					return false;
				}
			}
			if (!_root.activeSelf)
			{
				_root.SetActive(true);
			}
			Layout(fontScale);
			UpdatePaper();
			return true;
		}

		public void Hide()
		{
			if ((Object)(object)_root != (Object)null && _root.activeSelf)
			{
				_root.SetActive(false);
			}
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_panel = (_listArea = (_viewport = (_selLayer = null)));
			_paper = (_pointer = null);
			_header = (_hint = (_search = (_empty = (_body = (_marker = (_probe = null))))));
			_caret = (_rowMark = (_strike = null));
			_selection.Clear();
			_rows.Clear();
			_builtFor = null;
			_geomKey = null;
			_layoutKey = null;
			_shown.Clear();
		}

		private static int Even(float v)
		{
			return Mathf.RoundToInt(v / 2f) * 2;
		}

		private void Layout(float fontScale)
		{
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			int width = Screen.width;
			int height = Screen.height;
			string text = $"{width}x{height}:{fontScale}:{((Object)((TMP_Text)_body).font).name}";
			if (text == _geomKey)
			{
				return;
			}
			_geomKey = text;
			float num = Mathf.Max(12f, (float)height * Mathf.Clamp(fontScale, 0.01f, 0.1f));
			FaceInfo faceInfo = ((TMP_Asset)((TMP_Text)_body).font).faceInfo;
			float num2 = Mathf.Max(1f, faceInfo.pointSize);
			_s = num;
			_A = faceInfo.ascentLine / num2 * num;
			_L = faceInfo.lineHeight / num2 * num;
			_em = Mathf.Max(1.2f, (faceInfo.ascentLine - faceInfo.descentLine) / num2) + 0.05f;
			MeasureLines();
			_W = Even(Mathf.Min((float)width - 40f, Mathf.Max(0.55f * (float)width, 24f * num)));
			_T = 2.3f * num;
			_n = Mathf.Max(4, Mathf.FloorToInt((0.72f * (float)height - _T - 1.5f * num) / _L + 0.001f));
			_H = Even(_T + (float)_n * _L + 1.5f * num);
			_B = Mathf.RoundToInt(0.75f * num);
			_M = 2.4f * num;
			_X0 = _M + 0.5f * num;
			_X1 = (float)_W - 0.9f * num;
			_panel.sizeDelta = new Vector2((float)_W, (float)_H);
			_panel.anchoredPosition = new Vector2(((width - _W) % 2 != 0) ? 0.5f : 0f, ((height - _H) % 2 != 0) ? 0.5f : 0f);
			RectTransform rectTransform = ((Graphic)_paper).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			((TMP_Text)_header).fontSize = 0.95f * num;
			PlaceText(_header, _X0, _X1, Baseline(-1) - 0.08f * num, 0.95f);
			((TMP_Text)_hint).fontSize = 0.6f * num;
			PlaceText(_hint, _X0, _X1, (float)_H - 0.55f * num, 0.6f);
			PlaceTL(_listArea, _X0, _T, _X1 - _X0, (float)_n * _L);
			PlaceTL(_viewport, _X0 - 0.3f * num, _T, _X1 - _X0 + 0.6f * num, (float)_n * _L);
			RectTransform rectTransform2 = ((TMP_Text)_body).rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rectTransform2.anchorMax = val;
			rectTransform2.anchorMin = val;
			rectTransform2.pivot = new Vector2(0.5f, 1f);
			rectTransform2.sizeDelta = new Vector2(_X1 - _X0, (float)_n * _L);
			_bodyX = 0.3f * num + (_X1 - _X0) / 2f;
			rectTransform2.anchoredPosition = new Vector2(_bodyX, _scroll);
			val = (_selLayer.anchorMin = (_selLayer.anchorMax = rectTransform2.anchorMin));
			_selLayer.pivot = rectTransform2.pivot;
			_selLayer.sizeDelta = rectTransform2.sizeDelta;
			_selLayer.anchoredPosition = rectTransform2.anchoredPosition;
			((TMP_Text)_body).fontSize = num;
			((TMP_Text)_search).fontSize = num;
			((TMP_Text)_empty).fontSize = 0.8f * num;
			((TMP_Text)_marker).fontSize = num;
			foreach (Row row in _rows)
			{
				((TMP_Text)row.Title).fontSize = num;
				((TMP_Text)row.Meta).fontSize = 0.6f * num;
			}
			((Graphic)_caret).rectTransform.sizeDelta = new Vector2(Mathf.Max(2f, 0.08f * num), 1.14f * num);
			((Graphic)_strike).rectTransform.sizeDelta = new Vector2(0f, Mathf.Max(2f, 0.07f * num));
			_rowMark.pixelsPerUnitMultiplier = 64f / (1.22f * num);
			foreach (Image item in _selection)
			{
				item.pixelsPerUnitMultiplier = 64f / (1.22f * num);
			}
			_layoutKey = null;
			_listMarkKey = null;
		}

		private void MeasureLines()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			try
			{
				((TMP_Text)_probe).fontSize = _s;
				((TMP_Text)_probe).rectTransform.sizeDelta = new Vector2(10f * _s, 4f * _L);
				((TMP_Text)_probe).text = "Ag\nAg";
				((TMP_Text)_probe).ForceMeshUpdate(false, false);
				TMP_TextInfo textInfo = ((TMP_Text)_probe).textInfo;
				if (textInfo.lineCount >= 2)
				{
					Il2CppStructArray<TMP_LineInfo> lineInfo = textInfo.lineInfo;
					float num = 0f - ((Il2CppArrayBase<TMP_LineInfo>)(object)lineInfo)[0].baseline;
					float num2 = ((Il2CppArrayBase<TMP_LineInfo>)(object)lineInfo)[0].baseline - ((Il2CppArrayBase<TMP_LineInfo>)(object)lineInfo)[1].baseline;
					if (num > 0f && Mathf.Abs(num - _A) > 0.5f)
					{
						_A = num;
					}
					if (num2 > 0f && Mathf.Abs(num2 - _L) > 0.5f)
					{
						_L = num2;
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("[Notepad] measuring the font: " + ex.Message);
			}
		}

		private static void PlaceTL(RectTransform rt, float x, float y, float w, float h)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0038: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.pivot = new Vector2(0f, 1f);
			rt.anchoredPosition = new Vector2(x, 0f - y);
			rt.sizeDelta = new Vector2(w, h);
		}

		private void PlaceText(TextMeshProUGUI t, float x0, float x1, float baseline, float size)
		{
			float y = baseline - size * _A;
			PlaceTL(((TMP_Text)t).rectTransform, x0, y, x1 - x0, size * _em * _s);
		}

		private void UpdatePaper()
		{
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			NotebookPaper.Geometry g = new NotebookPaper.Geometry
			{
				PageW = _W,
				PageH = _H,
				Border = _B,
				S = _s,
				MarginX = _M,
				HeaderRuleY = Baseline(-1) + 0.035f * _s,
				FirstRuleY = Baseline(0) + 0.035f * _s,
				RuleStep = _L,
				RuleCount = _n,
				Seed = 1912
			};
			string key = $"{g.PageW}x{g.PageH}:{g.Border}:{g.S}:{g.HeaderRuleY}:{g.FirstRuleY}:{g.RuleStep}:{g.RuleCount}";
			if (_paperTask != null && _paperTask.IsCompleted)
			{
				Task<(byte[], int, int, string)> paperTask = _paperTask;
				_paperTask = null;
				if (paperTask.IsFaulted)
				{
					if (!_paperFailed)
					{
						Core.Log.Warning("[Notepad] drawing the paper failed: " + paperTask.Exception?.GetBaseException().Message);
					}
					_paperFailed = true;
				}
				else if (paperTask.Result.Item4 == key)
				{
					Upload(paperTask.Result.Item1, paperTask.Result.Item2, paperTask.Result.Item3, key);
				}
			}
			if (_paperKey != key && _paperTask == null && !_paperFailed)
			{
				_paperTaskKey = key;
				_paperTask = Task.Run(() => (px: NotebookPaper.Build(in g, out var texW, out var texH), w: texW, h: texH, key: key));
			}
			bool flag = _paperKey == key && (Object)(object)_paperTex != (Object)null;
			if (flag && (Object)(object)_paper.texture == (Object)null)
			{
				_paper.texture = (Texture)(object)_paperTex;
			}
			if (!flag && (Object)(object)_paper.texture != (Object)null)
			{
				_paper.texture = null;
			}
			((Graphic)_paper).color = (flag ? Color.white : PaperFlat);
			float num = (flag ? ((float)_B) : 0f);
			RectTransform rectTransform = ((Graphic)_paper).rectTransform;
			if (rectTransform.offsetMax.x != num || rectTransform.offsetMax.y != num)
			{
				rectTransform.offsetMin = new Vector2(0f - num, 0f - num);
				rectTransform.offsetMax = new Vector2(num, num);
			}
		}

		private static void Upload(byte[] px, int w, int h, string key)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			try
			{
				Texture2D val = new Texture2D(w, h, (TextureFormat)4, false);
				val.LoadRawTextureData(Il2CppStructArray<byte>.op_Implicit(px));
				val.Apply(false, true);
				((Texture)val).filterMode = (FilterMode)1;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Object)val).hideFlags = (HideFlags)61;
				if ((Object)(object)_paperTex != (Object)null)
				{
					Object.Destroy((Object)(object)_paperTex);
				}
				_paperTex = val;
				_paperKey = key;
			}
			catch (Exception ex)
			{
				_paperFailed = true;
				Core.Log.Warning("[Notepad] uploading the paper failed: " + ex.Message);
			}
		}

		private static Sprite Highlighter()
		{
			//IL_001c: 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_003d: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0075: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			if ((Object)(object)_markSprite != (Object)null)
			{
				return _markSprite;
			}
			Texture2D val = new Texture2D(256, 64, (TextureFormat)4, false);
			val.LoadRawTextureData(Il2CppStructArray<byte>.op_Implicit(NotebookPaper.BuildHighlighter(256, 64, 1912)));
			val.Apply(false, true);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Object)val).hideFlags = (HideFlags)61;
			_markTex = val;
			_markSprite = Sprite.Create(val, new Rect(0f, 0f, 256f, 64f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(32f, 0f, 32f, 0f));
			((Object)_markSprite).hideFlags = (HideFlags)61;
			return _markSprite;
		}

		private Image MakeMark(GameObject parent, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			Image val2 = val.AddComponent<Image>();
			val2.sprite = Highlighter();
			val2.type = (Type)1;
			((Graphic)val2).color = Color.white;
			((Graphic)val2).raycastTarget = false;
			if (_s > 0f)
			{
				val2.pixelsPerUnitMultiplier = 64f / (1.22f * _s);
			}
			return val2;
		}

		public void ShowList(string header, string hint, string search, IReadOnlyList<ListRow> rows, int selected, string empty)
		{
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			((Component)_viewport).gameObject.SetActive(false);
			((Component)_listArea).gameObject.SetActive(true);
			Set(_header, header);
			Set(_hint, hint);
			bool flag = !string.IsNullOrEmpty(search);
			if (((Component)_search).gameObject.activeSelf != flag)
			{
				((Component)_search).gameObject.SetActive(flag);
			}
			int num = (flag ? 1 : 0);
			if (flag)
			{
				Set(_search, search);
				PlaceText(_search, 0f, _X1 - _X0, _A, 1f);
			}
			int num2 = Mathf.Clamp((_n - num) / 2, 1, 20);
			int num3 = rows?.Count ?? 0;
			_listFirst = num;
			_listFit = num2;
			_listCount = num3;
			if (selected >= 0 && selected < _listTop)
			{
				_listTop = selected;
			}
			if (selected >= _listTop + num2)
			{
				_listTop = selected - num2 + 1;
			}
			_listTop = Mathf.Clamp(_listTop, 0, Mathf.Max(0, num3 - num2));
			bool flag2 = false;
			bool flag3 = false;
			for (int i = 0; i < _rows.Count; i++)
			{
				Row row = _rows[i];
				int num4 = _listTop + i;
				bool flag4 = i < num2 && num4 < num3;
				if (((Component)row.Title).gameObject.activeSelf != flag4)
				{
					((Component)row.Title).gameObject.SetActive(flag4);
					((Component)row.Meta).gameObject.SetActive(flag4);
				}
				if (!flag4)
				{
					continue;
				}
				int num5 = num + 2 * i;
				float num6 = _A + (float)num5 * _L;
				PlaceText(row.Title, 0f, _X1 - _X0, num6, 1f);
				PlaceText(row.Meta, 0f, _X1 - _X0, num6 + 0.98f * _s, 0.6f);
				Set(row.Title, rows[num4].Title);
				Set(row.Meta, rows[num4].Meta);
				if (num4 == selected)
				{
					float num7 = TitleWidth(row.Title, rows[num4].Title, num4, selected);
					PlaceTL(((Graphic)_rowMark).rectTransform, -0.22f * _s, num6 - 0.92f * _s, num7 + 0.5f * _s, 1.22f * _s);
					flag2 = true;
					PlaceTextRight(_marker, _M - 0.28f * _s, _T + num6);
					if (rows[num4].Deleting)
					{
						PlaceTL(((Graphic)_strike).rectTransform, 0f, num6 - 0.3f * _s, num7, ((Graphic)_strike).rectTransform.sizeDelta.y);
						flag3 = true;
					}
				}
			}
			if (((Component)_rowMark).gameObject.activeSelf != flag2)
			{
				((Component)_rowMark).gameObject.SetActive(flag2);
			}
			if (((Component)_marker).gameObject.activeSelf != flag2)
			{
				((Component)_marker).gameObject.SetActive(flag2);
			}
			if (((Component)_strike).gameObject.activeSelf != flag3)
			{
				((Component)_strike).gameObject.SetActive(flag3);
			}
			if (((Component)_empty).gameObject.activeSelf != (num3 == 0))
			{
				((Component)_empty).gameObject.SetActive(num3 == 0);
			}
			if (num3 == 0)
			{
				Set(_empty, empty);
				float y = _A + (float)(_n / 2) * _L - 0.8f * _A;
				PlaceTL(((TMP_Text)_empty).rectTransform, 0f, y, _X1 - _X0, 2f * _L);
			}
		}

		private float TitleWidth(TextMeshProUGUI t, string text, int index, int selected)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			string text2 = $"{selected}:{text}:{_s}";
			if (text2 != _listMarkKey)
			{
				_listMarkKey = text2;
				_titleWidth = Mathf.Min(((TMP_Text)t).GetPreferredValues(text ?? "").x, _X1 - _X0);
			}
			return _titleWidth;
		}

		private void PlaceTextRight(TextMeshProUGUI t, float x, float baseline)
		{
			float y = baseline - _A;
			PlaceTL(((TMP_Text)t).rectTransform, x - 2f * _s, y, 2f * _s, _em * _s);
		}

		public void ShowEditor(string header, string hint, string text, int caret, int anchor, bool caretOn, string composing)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			((Component)_listArea).gameObject.SetActive(false);
			((Component)_viewport).gameObject.SetActive(true);
			if (((Component)_marker).gameObject.activeSelf)
			{
				((Component)_marker).gameObject.SetActive(false);
			}
			Set(_header, header);
			Set(_hint, hint);
			if (text == null)
			{
				text = "";
			}
			caret = Math.Clamp(caret, 0, text.Length);
			anchor = Math.Clamp(anchor, 0, text.Length);
			if (!string.IsNullOrEmpty(composing))
			{
				text = text.Substring(0, caret) + composing + text.Substring(caret);
				caret += composing.Length;
				anchor = caret;
			}
			Relayout(text);
			(float x, int line) tuple = Pos(caret);
			float item = tuple.x;
			int item2 = tuple.line;
			item = Mathf.Min(item, _right - ((Graphic)_caret).rectTransform.sizeDelta.x);
			float num = LineBase(item2);
			((Behaviour)_caret).enabled = caretOn;
			((Graphic)_caret).rectTransform.anchoredPosition = new Vector2(item - ((Graphic)_caret).rectTransform.sizeDelta.x / 2f, num - 0.22f * _s);
			DrawSelection(Math.Min(caret, anchor), Math.Max(caret, anchor));
			if (_followCaret)
			{
				(float asc, float desc) tuple2 = LineY(item2);
				float item3 = tuple2.asc;
				float item4 = tuple2.desc;
				float num2 = (float)_n * _L;
				if (item3 > 0f - _scroll)
				{
					_scroll = 0f - item3;
				}
				if (item4 < 0f - _scroll - num2)
				{
					_scroll = 0f - item4 - num2;
				}
			}
			ClampScroll();
		}

		public void FollowCaret()
		{
			_followCaret = true;
			_wheelRest = 0f;
		}

		public void ScrollLines(float lines)
		{
			if (!((Object)(object)_body == (Object)null) && !(_lineH <= 0f))
			{
				_wheelRest += lines;
				float num = (float)Math.Truncate(_wheelRest);
				_wheelRest -= num;
				_followCaret = false;
				if (num != 0f)
				{
					_scroll += num * _lineH;
					ClampScroll();
				}
			}
		}

		public void ResetScroll()
		{
			_scroll = 0f;
			_wheelRest = 0f;
			_followCaret = true;
		}

		private void ClampScroll()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)_n * _L;
			_scroll = Mathf.Clamp(_scroll, 0f, Mathf.Max(0f, ContentHeight() - num));
			if (_lineH > 0f)
			{
				_scroll = Mathf.Round(_scroll / _lineH) * _lineH;
			}
			((TMP_Text)_body).rectTransform.anchoredPosition = new Vector2(_bodyX, _scroll);
			_selLayer.anchoredPosition = new Vector2(_bodyX, _scroll);
		}

		private void Relayout(string text)
		{
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			string text2 = $"{text.Length}:{text.GetHashCode()}:{_geomKey}";
			if (text2 == _layoutKey)
			{
				return;
			}
			_layoutKey = text2;
			_laidText = text;
			RectTransform rectTransform = ((TMP_Text)_body).rectTransform;
			((TMP_Text)_body).text = text;
			((TMP_Text)_body).ForceMeshUpdate(false, false);
			TMP_TextInfo textInfo = ((TMP_Text)_body).textInfo;
			_n2 = Math.Max(0, textInfo.characterCount);
			_lines = Math.Max(0, textInfo.lineCount);
			Grow(ref _origin, _n2);
			Grow(ref _advance, _n2);
			Grow(ref _lineOf, _n2);
			Grow(ref _index, _n2);
			Grow(ref _char, _n2);
			Grow(ref _kAt, text.Length + 1);
			Grow(ref _lFirst, _lines);
			Grow(ref _lLast, _lines);
			Grow(ref _lAsc, _lines);
			Grow(ref _lDesc, _lines);
			Il2CppReferenceArray<TMP_CharacterInfo> characterInfo = textInfo.characterInfo;
			if (characterInfo == null)
			{
				_n2 = 0;
			}
			else if (_n2 > ((Il2CppArrayBase<TMP_CharacterInfo>)(object)characterInfo).Length)
			{
				_n2 = ((Il2CppArrayBase<TMP_CharacterInfo>)(object)characterInfo).Length;
			}
			if (!ReadDirect(characterInfo))
			{
				for (int i = 0; i < _n2; i++)
				{
					TMP_CharacterInfo val = ((Il2CppArrayBase<TMP_CharacterInfo>)(object)characterInfo)[i];
					_origin[i] = val.origin;
					_advance[i] = val.xAdvance;
					_lineOf[i] = val.lineNumber;
					_index[i] = val.index;
					_char[i] = val.character;
				}
			}
			Il2CppStructArray<TMP_LineInfo> lineInfo = textInfo.lineInfo;
			for (int j = 0; j < _lines; j++)
			{
				TMP_LineInfo val2 = ((Il2CppArrayBase<TMP_LineInfo>)(object)lineInfo)[j];
				_lFirst[j] = val2.firstCharacterIndex;
				_lLast[j] = val2.lastCharacterIndex;
				_lAsc[j] = val2.ascender;
				_lDesc[j] = val2.descender;
			}
			for (int k = 0; k <= text.Length; k++)
			{
				_kAt[k] = -1;
			}
			for (int l = 0; l < _n2; l++)
			{
				if (_index[l] >= 0 && _index[l] < text.Length)
				{
					_kAt[_index[l]] = l;
				}
			}
			Rect rect = rectTransform.rect;
			_left = ((Rect)(ref rect)).xMin;
			rect = rectTransform.rect;
			_right = ((Rect)(ref rect)).xMax;
			_asc0 = 0f;
			_desc0 = (0f - (_em - 0.05f)) * _s;
			_lineH = _L;
		}

		private bool ReadDirect(Il2CppReferenceArray<TMP_CharacterInfo> chars)
		{
			if (_n2 == 0 || chars == null || !DirectLayout())
			{
				return false;
			}
			IntPtr intPtr = ((Il2CppObjectBase)chars).Pointer + 4 * IntPtr.Size;
			for (int i = 0; i < _n2; i++)
			{
				IntPtr ptr = intPtr + i * _ciStride;
				_origin[i] = BitConverter.Int32BitsToSingle(Marshal.ReadInt32(ptr, _oOrigin));
				_advance[i] = BitConverter.Int32BitsToSingle(Marshal.ReadInt32(ptr, _oAdvance));
				_lineOf[i] = Marshal.ReadInt32(ptr, _oLine);
				_index[i] = Marshal.ReadInt32(ptr, _oIndex);
				_char[i] = (char)Marshal.ReadInt16(ptr, _oChar);
			}
			GC.KeepAlive(chars);
			if (_ciChecked)
			{
				return true;
			}
			_ciChecked = true;
			if (Same(((Il2CppArrayBase<TMP_CharacterInfo>)(object)chars)[0], 0) && Same(((Il2CppArrayBase<TMP_CharacterInfo>)(object)chars)[_n2 - 1], _n2 - 1))
			{
				return true;
			}
			_ciStride = 0;
			Core.Log.Warning("[Notepad] fast text layout reads didn't match, using the slow path");
			return false;
		}

		private bool Same(TMP_CharacterInfo c, int k)
		{
			if (c.origin == _origin[k] && c.xAdvance == _advance[k] && c.lineNumber == _lineOf[k] && c.index == _index[k])
			{
				return c.character == _char[k];
			}
			return false;
		}

		private static bool DirectLayout()
		{
			if (_ciStride >= 0)
			{
				return _ciStride > 0;
			}
			_ciStride = 0;
			try
			{
				IntPtr cls = Il2CppClassPointerStore<TMP_CharacterInfo>.NativeClassPtr;
				if (cls == IntPtr.Zero)
				{
					return false;
				}
				uint num = 0u;
				int stride = IL2CPP.il2cpp_class_value_size(cls, ref num);
				int header = 2 * IntPtr.Size;
				_oOrigin = Off("origin");
				_oAdvance = Off("xAdvance");
				_oLine = Off("lineNumber");
				_oIndex = Off("index");
				_oChar = Off("character");
				if (stride > 0 && Fits(_oOrigin, 4) && Fits(_oAdvance, 4) && Fits(_oLine, 4) && Fits(_oIndex, 4) && Fits(_oChar, 2))
				{
					_ciStride = stride;
				}
				bool Fits(int o, int size)
				{
					if (o >= 0)
					{
						return o <= stride - size;
					}
					return false;
				}
				int Off(string name)
				{
					IntPtr il2CppField = IL2CPP.GetIl2CppField(cls, name);
					if (!(il2CppField == IntPtr.Zero))
					{
						return (int)IL2CPP.il2cpp_field_get_offset(il2CppField) - header;
					}
					return -1;
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("[Notepad] fast text layout unavailable: " + ex.Message);
			}
			return _ciStride > 0;
		}

		private static void Grow<T>(ref T[] a, int n)
		{
			if (a.Length < n)
			{
				a = new T[Math.Max(n, a.Length * 2)];
			}
		}

		private int KAt(int i)
		{
			while (i < _laidText.Length)
			{
				if (_kAt[i] >= 0)
				{
					return _kAt[i];
				}
				i++;
			}
			return -1;
		}

		private (float x, int line) Pos(int i)
		{
			if (_n2 == 0)
			{
				return (x: _left, line: 0);
			}
			int num = ((i < _laidText.Length) ? KAt(i) : (-1));
			if (num >= 0)
			{
				return (x: _origin[num], line: _lineOf[num]);
			}
			int num2 = _n2 - 1;
			if (_char[num2] == '\n')
			{
				return (x: _left, line: _lineOf[num2] + 1);
			}
			return (x: _advance[num2], line: _lineOf[num2]);
		}

		private (float asc, float desc) LineY(int line)
		{
			if (_lines == 0)
			{
				return (asc: _asc0 - (float)line * _lineH, desc: _desc0 - (float)line * _lineH);
			}
			if (line < _lines)
			{
				return (asc: _lAsc[line], desc: _lDesc[line]);
			}
			float num = (float)(line - _lines + 1) * _lineH;
			return (asc: _lAsc[_lines - 1] - num, desc: _lDesc[_lines - 1] - num);
		}

		private float LineBase(int line)
		{
			return 0f - (_A + (float)line * _L);
		}

		private float ContentHeight()
		{
			return (float)LineCount * _lineH;
		}

		private void DrawSelection(int start, int end)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			if (end > start && _n2 > 0)
			{
				(float x, int line) tuple = Pos(start);
				float item = tuple.x;
				int item2 = tuple.line;
				(float x, int line) tuple2 = Pos(end);
				float item3 = tuple2.x;
				int item4 = tuple2.line;
				for (int i = item2; i <= item4 && i < _lines; i++)
				{
					float num2 = ((i == item2) ? item : _origin[_lFirst[i]]);
					float num3 = ((i == item4) ? item3 : (_advance[_lLast[i]] + _s * 0.3f));
					num3 = Mathf.Min(num3, _right + 0.25f * _s);
					if (!(num3 <= num2))
					{
						Image obj = SelectionImage(num++);
						((Graphic)obj).rectTransform.anchoredPosition = new Vector2(num2 - 0.08f * _s, LineBase(i) - 0.3f * _s);
						((Graphic)obj).rectTransform.sizeDelta = new Vector2(num3 - num2 + 0.16f * _s, 1.22f * _s);
					}
				}
			}
			for (int j = 0; j < _selection.Count; j++)
			{
				if (((Behaviour)_selection[j]).enabled != j < num)
				{
					((Behaviour)_selection[j]).enabled = j < num;
				}
			}
		}

		private Image SelectionImage(int i)
		{
			while (_selection.Count <= i)
			{
				Image val = MakeMark(((Component)_selLayer).gameObject, "Selection");
				Anchor(((Graphic)val).rectTransform);
				_selection.Add(val);
			}
			return _selection[i];
		}

		private static void Anchor(RectTransform rt)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.pivot = Vector2.zero;
		}

		public int Vertical(int caret, int dir, ref float goalX)
		{
			if (_n2 == 0)
			{
				return caret;
			}
			var (num, num2) = Pos(caret);
			if (float.IsNaN(goalX))
			{
				goalX = num;
			}
			int num3 = num2 + dir;
			if (num3 < 0)
			{
				return 0;
			}
			if (num3 >= LineCount)
			{
				return _laidText.Length;
			}
			return AtX(num3, goalX);
		}

		public int Page(int caret, int dir, ref float goalX)
		{
			int num = Mathf.Max(1, _n - 1);
			for (int i = 0; i < num; i++)
			{
				int num2 = Vertical(caret, dir, ref goalX);
				if (num2 == caret)
				{
					break;
				}
				caret = num2;
			}
			return caret;
		}

		public int Home(int caret)
		{
			int item = Pos(caret).line;
			if (_n2 == 0 || item >= _lines)
			{
				return caret;
			}
			return _index[_lFirst[item]];
		}

		public int End(int caret)
		{
			int item = Pos(caret).line;
			if (_n2 == 0 || item >= _lines)
			{
				return caret;
			}
			int num = LineEndIndex(item);
			if (Pos(num).line != item)
			{
				return _index[_lLast[item]];
			}
			return num;
		}

		private int LineEndIndex(int line)
		{
			int num = _lLast[line];
			char c = _char[num];
			if (c == '\n')
			{
				return _index[num];
			}
			if (line == _lines - 1)
			{
				return _laidText.Length;
			}
			if (!char.IsWhiteSpace(c))
			{
				return _index[num] + 1;
			}
			return _index[num];
		}

		private int AtX(int line, float x)
		{
			if (line >= _lines)
			{
				return _laidText.Length;
			}
			int num = _lFirst[line];
			int num2 = _lLast[line];
			int result = _index[num];
			float num3 = Mathf.Abs(_origin[num] - x);
			for (int i = num + 1; i <= num2 && _char[i - 1] != '\n'; i++)
			{
				float num4 = Mathf.Abs(_origin[i] - x);
				if (num4 < num3)
				{
					num3 = num4;
					result = _index[i];
				}
			}
			int num5 = LineEndIndex(line);
			(float x, int line) tuple = Pos(num5);
			var (num6, _) = tuple;
			if (tuple.line == line && Mathf.Abs(num6 - x) < num3)
			{
				result = num5;
			}
			return result;
		}

		public void ResetPointer()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			_mouseAtOpen = Vector2.op_Implicit(Input.mousePosition);
			_mouseMoved = false;
		}

		public void UpdatePointer()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			if ((Object)(object)_pointer == (Object)null)
			{
				return;
			}
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			if (!_mouseMoved)
			{
				Vector2 val2 = val - _mouseAtOpen;
				if (((Vector2)(ref val2)).sqrMagnitude > 4f)
				{
					_mouseMoved = true;
				}
			}
			Texture2D val3 = (_mouseMoved ? GamePointer.Texture : null);
			bool flag = (Object)(object)val3 != (Object)null;
			if (((Component)_pointer).gameObject.activeSelf != flag)
			{
				((Component)_pointer).gameObject.SetActive(flag);
			}
			if (flag)
			{
				if ((Object)(object)_pointer.texture == (Object)null)
				{
					_pointer.texture = (Texture)(object)val3;
				}
				float num = 0.09f * (float)Screen.height;
				RectTransform rectTransform = ((Graphic)_pointer).rectTransform;
				rectTransform.sizeDelta = new Vector2(num, num);
				rectTransform.anchoredPosition = val;
				((Transform)rectTransform).SetAsLastSibling();
			}
		}

		private bool PagePoint(Vector2 screen, out Vector2 p)
		{
			//IL_0001: 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_0029: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			p = default(Vector2);
			Vector2 val = default(Vector2);
			if ((Object)(object)_panel == (Object)null || !RectTransformUtility.ScreenPointToLocalPointInRectangle(_panel, screen, (Camera)null, ref val))
			{
				return false;
			}
			p = new Vector2(val.x + (float)_W / 2f, (float)_H / 2f - val.y);
			return true;
		}

		public bool InsidePage(Vector2 screen)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (PagePoint(screen, out var p) && p.x >= 0f && p.x <= (float)_W && p.y >= 0f)
			{
				return p.y <= (float)_H;
			}
			return false;
		}

		public bool InsideText(Vector2 screen)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (PagePoint(screen, out var p) && p.x >= _X0 - 0.5f * _s && p.x <= _X1 + 0.5f * _s && p.y >= _T - 0.3f * _s)
			{
				return p.y <= _T + (float)_n * _L;
			}
			return false;
		}

		public int RowAt(Vector2 screen)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0044: 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)
			if (!PagePoint(screen, out var p))
			{
				return -1;
			}
			if (p.x < _M - 1.5f * _s || p.x > _X1 || p.y < _T || p.y >= _T + (float)_n * _L)
			{
				return -1;
			}
			int num = Mathf.FloorToInt((p.y - _T) / _L) - _listFirst;
			if (num < 0)
			{
				return -1;
			}
			int num2 = num / 2;
			if (num2 >= _listFit)
			{
				return -1;
			}
			int num3 = _listTop + num2;
			if (num3 >= _listCount)
			{
				return -1;
			}
			return num3;
		}

		public int IndexAt(Vector2 screen, int beyond = 0)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!BodyLine(screen, beyond, out var line, out var x))
			{
				return -1;
			}
			if (_n2 != 0)
			{
				return AtX(line, x);
			}
			return 0;
		}

		public int CharAt(Vector2 screen)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!BodyLine(screen, 0, out var line, out var x))
			{
				return -1;
			}
			if (_n2 == 0)
			{
				return 0;
			}
			if (line >= _lines)
			{
				return _laidText.Length;
			}
			for (int i = _lFirst[line]; i <= _lLast[line]; i++)
			{
				if (_char[i] == '\n' || x < _advance[i])
				{
					return _index[i];
				}
			}
			return LineEndIndex(line);
		}

		private bool BodyLine(Vector2 screen, int beyond, out int line, out float x)
		{
			//IL_0024: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			line = 0;
			x = 0f;
			Vector2 val = default(Vector2);
			if ((Object)(object)_body == (Object)null || !RectTransformUtility.ScreenPointToLocalPointInRectangle(((TMP_Text)_body).rectTransform, screen, (Camera)null, ref val))
			{
				return false;
			}
			int num = Mathf.RoundToInt(_scroll / _L);
			line = Mathf.FloorToInt((0f - val.y) / _L);
			line = Mathf.Clamp(line, num - beyond, num + _n - 1 + beyond);
			line = Mathf.Clamp(line, 0, LineCount - 1);
			x = val.x;
			return true;
		}

		private void Set(TextMeshProUGUI t, string s)
		{
			if (s == null)
			{
				s = "";
			}
			IntPtr pointer = ((Il2CppObjectBase)t).Pointer;
			if (!_shown.TryGetValue(pointer, out var value) || !(value == s))
			{
				_shown[pointer] = s;
				((TMP_Text)t).text = s;
			}
		}

		private bool TryCreate(string fontName)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Expected O, but got Unknown
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Expected O, but got Unknown
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Expected O, but got Unknown
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Expected O, but got Unknown
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Expected O, but got Unknown
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			bool fallback;
			TMP_FontAsset val = FindFont(fontName, out fallback);
			if ((Object)(object)val == (Object)null)
			{
				Core.Log.Warning("[Notepad] no usable font found");
				return false;
			}
			if (fallback)
			{
				Core.Log.Warning($"[Notepad] font '{fontName}' not found, using '{((Object)val).name}'");
			}
			_root = new GameObject("BluePrinceNotes Notepad");
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 600;
			GameObject val2 = new GameObject("Dim");
			val2.transform.SetParent(_root.transform, false);
			Image obj2 = val2.AddComponent<Image>();
			((Graphic)obj2).color = DimColor;
			((Graphic)obj2).raycastTarget = false;
			RectTransform rectTransform = ((Graphic)obj2).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			Vector2 val3 = (rectTransform.offsetMin = (rectTransform.offsetMax = Vector2.zero));
			GameObject val5 = new GameObject("Panel");
			val5.transform.SetParent(_root.transform, false);
			_panel = val5.AddComponent<RectTransform>();
			RectTransform panel = _panel;
			RectTransform panel2 = _panel;
			RectTransform panel3 = _panel;
			Vector2 val6 = default(Vector2);
			((Vector2)(ref val6))..ctor(0.5f, 0.5f);
			panel3.pivot = val6;
			val3 = (panel.anchorMin = (panel2.anchorMax = val6));
			GameObject val9 = new GameObject("Paper");
			val9.transform.SetParent(val5.transform, false);
			_paper = val9.AddComponent<RawImage>();
			((Graphic)_paper).color = PaperFlat;
			((Graphic)_paper).raycastTarget = false;
			_probe = MakeText(val5, "Probe", val, Color.clear, (TextWrappingModes)0, (TextOverflowModes)0);
			RectTransform rectTransform2 = ((TMP_Text)_probe).rectTransform;
			RectTransform rectTransform3 = ((TMP_Text)_probe).rectTransform;
			((Vector2)(ref val3))..ctor(0f, 1f);
			rectTransform3.anchorMax = val3;
			rectTransform2.anchorMin = val3;
			((TMP_Text)_probe).rectTransform.pivot = new Vector2(0f, 1f);
			_header = MakeText(val5, "Header", val, Red, (TextWrappingModes)0, (TextOverflowModes)1);
			_hint = MakeText(val5, "Hint", val, Pencil, (TextWrappingModes)0, (TextOverflowModes)1);
			_marker = MakeText(val5, "Marker", val, Red, (TextWrappingModes)0, (TextOverflowModes)0);
			((TMP_Text)_marker).alignment = (TextAlignmentOptions)260;
			((TMP_Text)_marker).text = (val.HasCharacter('»', false, false) ? "»" : ">");
			((Component)_marker).gameObject.SetActive(false);
			GameObject val10 = new GameObject("List");
			val10.transform.SetParent(val5.transform, false);
			_listArea = val10.AddComponent<RectTransform>();
			_rowMark = MakeMark(val10, "Selected");
			((Component)_rowMark).gameObject.SetActive(false);
			_search = MakeText(val10, "Search", val, Ink, (TextWrappingModes)0, (TextOverflowModes)1);
			_empty = MakeText(val10, "Empty", val, Pencil, (TextWrappingModes)1, (TextOverflowModes)0);
			((TMP_Text)_empty).alignment = (TextAlignmentOptions)258;
			for (int i = 0; i < 20; i++)
			{
				Row row = new Row
				{
					Title = MakeText(val10, "Title", val, Ink, (TextWrappingModes)0, (TextOverflowModes)1),
					Meta = MakeText(val10, "Meta", val, Pencil, (TextWrappingModes)0, (TextOverflowModes)1)
				};
				((Component)row.Title).gameObject.SetActive(false);
				((Component)row.Meta).gameObject.SetActive(false);
				_rows.Add(row);
			}
			GameObject val11 = new GameObject("Strike");
			val11.transform.SetParent(val10.transform, false);
			_strike = val11.AddComponent<Image>();
			((Graphic)_strike).color = Red;
			((Graphic)_strike).raycastTarget = false;
			val11.SetActive(false);
			GameObject val12 = new GameObject("Viewport");
			val12.transform.SetParent(val5.transform, false);
			_viewport = val12.AddComponent<RectTransform>();
			val12.AddComponent<RectMask2D>();
			GameObject val13 = new GameObject("SelectionLayer");
			val13.transform.SetParent(val12.transform, false);
			_selLayer = val13.AddComponent<RectTransform>();
			_body = MakeText(val12, "Body", val, Ink, (TextWrappingModes)1, (TextOverflowModes)0);
			((TMP_Text)_body).lineSpacing = 0f;
			((TMP_Text)_body).paragraphSpacing = 0f;
			GameObject val14 = new GameObject("Caret");
			val14.transform.SetParent(((TMP_Text)_body).transform, false);
			_caret = val14.AddComponent<Image>();
			((Graphic)_caret).color = CaretColor;
			((Graphic)_caret).raycastTarget = false;
			Anchor(((Graphic)_caret).rectTransform);
			val12.SetActive(false);
			GameObject val15 = new GameObject("Pointer");
			val15.transform.SetParent(_root.transform, false);
			_pointer = val15.AddComponent<RawImage>();
			((Graphic)_pointer).raycastTarget = false;
			RectTransform rectTransform4 = ((Graphic)_pointer).rectTransform;
			val3 = (rectTransform4.anchorMin = (rectTransform4.anchorMax = Vector2.zero));
			rectTransform4.pivot = new Vector2(0.492f, 0.651f);
			val15.SetActive(false);
			_builtFor = fontName;
			_geomKey = null;
			Core.Log.Msg("[Notepad] using game font '" + ((Object)val).name + "'");
			return true;
		}

		private static TextMeshProUGUI MakeText(GameObject parent, string name, TMP_FontAsset font, Color color, TextWrappingModes wrap, TextOverflowModes overflow)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = font;
			((Graphic)obj).color = color;
			((TMP_Text)obj).richText = false;
			((TMP_Text)obj).parseCtrlCharacters = false;
			((TMP_Text)obj).textWrappingMode = wrap;
			((TMP_Text)obj).overflowMode = overflow;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)257;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		internal static TMP_FontAsset FindFont(string want, out bool fallback)
		{
			TMP_FontAsset val = null;
			TMP_FontAsset val2 = null;
			foreach (TMP_FontAsset item in Resources.FindObjectsOfTypeAll<TMP_FontAsset>())
			{
				if (!((Object)(object)item == (Object)null))
				{
					if ((Object)(object)val == (Object)null && ((Object)item).name.Equals(want, StringComparison.OrdinalIgnoreCase))
					{
						val = item;
					}
					if ((Object)(object)val2 == (Object)null && ((Object)item).name == "TypeNeat SDF")
					{
						val2 = item;
					}
				}
			}
			fallback = (Object)(object)val == (Object)null;
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			try
			{
				return TMP_Settings.defaultFontAsset;
			}
			catch
			{
				return null;
			}
		}
	}
	internal sealed class Toast
	{
		private const float ShowTime = 1.8f;

		private const float FadeTime = 0.4f;

		private static readonly Color Back = new Color(0.02f, 0.03f, 0.06f, 0.72f);

		private static readonly Color Text = new Color(1f, 0.97f, 0.88f, 1f);

		private GameObject _root;

		private RectTransform _strip;

		private Image _bg;

		private TextMeshProUGUI _text;

		private CanvasGroup _group;

		private float _until = -1f;

		public void Show(string message, string fontName)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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)
			if (Ensure(fontName))
			{
				float num = Mathf.Max(12f, (float)Screen.height * 0.026f);
				((TMP_Text)_text).fontSize = num;
				((TMP_Text)_text).text = message;
				Vector2 preferredValues = ((TMP_Text)_text).GetPreferredValues(message, (float)Screen.width * 0.8f, 0f);
				_strip.sizeDelta = new Vector2(preferredValues.x + 2f * num, preferredValues.y + 0.6f * num);
				_strip.anchoredPosition = new Vector2(0f, (float)Screen.height * 0.18f);
				_group.alpha = 1f;
				_root.SetActive(true);
				_until = Time.unscaledTime + 1.8f;
			}
		}

		public void Tick()
		{
			if (!((Object)(object)_root == (Object)null) && _root.activeSelf)
			{
				float num = _until - Time.unscaledTime;
				if (num <= 0f)
				{
					Hide();
				}
				else
				{
					_group.alpha = Mathf.Clamp01(num / 0.4f);
				}
			}
		}

		public void Hide()
		{
			if ((Object)(object)_root != (Object)null && _root.activeSelf)
			{
				_root.SetActive(false);
			}
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_text = null;
		}

		private bool Ensure(string fontName)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_0181: