Decompiled source of Runic Inscriptions v1.0.0

RunicInscriptions.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("RunicInscriptions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RunicInscriptions")]
[assembly: AssemblyTitle("RunicInscriptions")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RunicInscriptions;

internal static class GameInput
{
	public enum Mode
	{
		Free,
		Editing,
		Placing
	}

	private static readonly HashSet<string> PlacingAllowed = new HashSet<string> { "Sprint", "DodgeButtonDown", "DodgeButton", "StealthButton", "AutoRun" };

	private static readonly HashSet<string> MouseNavigation = new HashSet<string> { "IsKeyboardOrGamepadNavigation", "IsLastActionGamepad" };

	private static Panel panel;

	private static Panel previous;

	private static Character owner;

	public static Mode Current { get; private set; } = Mode.Free;

	public static bool Blocked => Current != Mode.Free;

	public static void Set(Mode mode, Character c)
	{
		if (mode != Current)
		{
			Current = mode;
			if (mode == Mode.Editing)
			{
				ShowPanel(c);
			}
			else
			{
				HidePanel();
			}
		}
	}

	private static void ShowPanel(Character c)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		if (!((Object)(object)c == (Object)null) && !((Object)(object)c.CharacterUI == (Object)null) && !((Object)(object)owner != (Object)null))
		{
			owner = c;
			if ((Object)(object)panel == (Object)null)
			{
				GameObject val = new GameObject("RunicInscriptions_MenuLock");
				Object.DontDestroyOnLoad((Object)val);
				panel = val.AddComponent<Panel>();
			}
			previous = c.CharacterUI.PendingDemoCharSelectionScreen;
			c.CharacterUI.PendingDemoCharSelectionScreen = panel;
			((UIElement)panel).Show();
		}
	}

	private static void HidePanel()
	{
		if ((Object)(object)panel != (Object)null)
		{
			((UIElement)panel).Hide();
		}
		if ((Object)(object)owner != (Object)null && (Object)(object)owner.CharacterUI != (Object)null && (Object)(object)owner.CharacterUI.PendingDemoCharSelectionScreen == (Object)(object)panel)
		{
			owner.CharacterUI.PendingDemoCharSelectionScreen = previous;
		}
		owner = null;
		previous = null;
	}

	public static void Patch(Harmony h)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		HarmonyMethod val = new HarmonyMethod(typeof(GameInput), "Query", (Type[])null);
		int num = 0;
		MethodInfo[] methods = typeof(ControlsInput).GetMethods(BindingFlags.Static | BindingFlags.Public);
		foreach (MethodInfo methodInfo in methods)
		{
			if (!(methodInfo.ReturnType != typeof(bool)) && !methodInfo.IsGenericMethod)
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (((parameters.Length == 1 && parameters[0].ParameterType == typeof(int)) || (parameters.Length == 0 && methodInfo.Name == "MenuCancelSystem")) && ((!methodInfo.Name.StartsWith("Does") && !methodInfo.Name.StartsWith("Is") && !(methodInfo.Name == "CheckEnoughControllers")) || MouseNavigation.Contains(methodInfo.Name)))
				{
					h.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
		}
		Plugin.Log.LogDebug((object)$"{num} ControlsInput queries watched while the mod is in use");
	}

	private static bool Query(MethodBase __originalMethod, ref bool __result)
	{
		if (Current == Mode.Free)
		{
			return true;
		}
		if (Current == Mode.Placing && PlacingAllowed.Contains(__originalMethod.Name))
		{
			return true;
		}
		__result = false;
		return false;
	}
}
public enum Align
{
	Left,
	Center,
	Right
}
[Serializable]
public class RuneStyle
{
	public float Size = 0.35f;

	public float Spacing = 0.18f;

	public float LineSpacing = 0.35f;

	public Align Align = Align.Center;

	public bool Vertical;

	public float Thickness = 0.5f;

	public Color Color = new Color(0.82f, 0.2f, 1f);

	public float Brightness = 4.3f;

	public float Paint = 0.6f;

	public bool Pulse;

	public float PulseSpeed = 1f;

	public bool Light;

	public float LightRange = 3f;

	public float LightIntensity = 1f;

	public bool Conform = true;

	public float Offset = 0.012f;

	public bool DoubleSided;

	public RuneStyle Clone()
	{
		return (RuneStyle)MemberwiseClone();
	}
}
[Serializable]
public class Inscription
{
	public string Id;

	public string Scene;

	public string Text;

	public Vector3 Position;

	public Quaternion Rotation = Quaternion.identity;

	public bool OnSurface = true;

	public RuneStyle Style = new RuneStyle();

	public long Created;
}
[Serializable]
internal class InscriptionFile
{
	public int Version = 1;

	public string Character;

	public List<Inscription> Inscriptions = new List<Inscription>();
}
internal static class Presets
{
	public sealed class Preset
	{
		public string Name;

		public Color Color;

		public float Brightness;

		public float Paint;
	}

	public static readonly Preset[] All = new Preset[8]
	{
		new Preset
		{
			Name = "Arcane",
			Color = new Color(0.82f, 0.2f, 1f),
			Brightness = 4.3f,
			Paint = 0.6f
		},
		new Preset
		{
			Name = "Fire",
			Color = new Color(1f, 0.42f, 0.08f),
			Brightness = 4f,
			Paint = 0.5f
		},
		new Preset
		{
			Name = "Frost",
			Color = new Color(0.35f, 0.8f, 1f),
			Brightness = 3.5f,
			Paint = 0.6f
		},
		new Preset
		{
			Name = "Light",
			Color = new Color(1f, 0.85f, 0.45f),
			Brightness = 3f,
			Paint = 0.7f
		},
		new Preset
		{
			Name = "Decay",
			Color = new Color(0.45f, 1f, 0.3f),
			Brightness = 3f,
			Paint = 0.5f
		},
		new Preset
		{
			Name = "Blood",
			Color = new Color(0.6f, 0.02f, 0.02f),
			Brightness = 0f,
			Paint = 0.9f
		},
		new Preset
		{
			Name = "Chalk",
			Color = new Color(0.9f, 0.88f, 0.82f),
			Brightness = 0f,
			Paint = 1f
		},
		new Preset
		{
			Name = "Carved",
			Color = new Color(0.12f, 0.1f, 0.09f),
			Brightness = 0f,
			Paint = 1f
		}
	};
}
internal static class InscriptionBuilder
{
	internal struct Quad
	{
		public Glyph Glyph;

		public Vector2 Min;

		public Vector2 Max;
	}

	public const string RootName = "RunicInscription_";

	private const string MainShader = "Custom/Main Set/Main Standard";

	private const int ConformCells = 4;

	private static Material template;

	private static Texture2D flatNormal;

	private static Texture2D white;

	public static List<Quad> Layout(string text, RuneStyle s, out Vector2 size)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		List<Quad> list = new List<Quad>();
		string[] array = (text ?? "").Split(new char[1] { '\n' });
		size = Vector2.zero;
		if (!s.Vertical)
		{
			float num = 1f + s.LineSpacing;
			float[] array2 = array.Select((string l) => LineWidth(l, s.Spacing)).ToArray();
			float num2 = ((array2.Length == 0) ? 0f : array2.Max());
			float num3 = (float)array.Length * 1f + (float)(array.Length - 1) * s.LineSpacing;
			size = new Vector2(num2, num3);
			for (int num4 = 0; num4 < array.Length; num4++)
			{
				float num5 = num3 / 2f - 0.5f - (float)num4 * num;
				float num6 = ((s.Align == Align.Left) ? ((0f - num2) / 2f) : ((s.Align == Align.Right) ? (num2 / 2f - array2[num4]) : ((0f - array2[num4]) / 2f)));
				bool flag = true;
				string text2 = array[num4];
				foreach (char c in text2)
				{
					if (!flag)
					{
						num6 += s.Spacing;
					}
					flag = false;
					if (!RuneGlyphs.TryGet(c, out var g))
					{
						num6 += 0.6f;
						continue;
					}
					float num8 = num6 - (g.Width - g.Ink) / 2f;
					float num9 = num5 - g.Top;
					list.Add(new Quad
					{
						Glyph = g,
						Min = new Vector2(num8, num9 - g.Height),
						Max = new Vector2(num8 + g.Width, num9)
					});
					num6 += g.Ink;
				}
			}
		}
		else
		{
			float num10 = 1.15f + s.LineSpacing;
			float[] array3 = array.Select((string l) => ColumnHeight(l, s.Spacing)).ToArray();
			float num11 = ((array3.Length == 0) ? 0f : array3.Max());
			float num12 = (float)array.Length * 1.15f + (float)(array.Length - 1) * s.LineSpacing;
			size = new Vector2(num12, num11);
			for (int num13 = 0; num13 < array.Length; num13++)
			{
				float num14 = (0f - num12) / 2f + 0.575f + (float)num13 * num10;
				float num15 = ((s.Align == Align.Left) ? (num11 / 2f) : ((s.Align == Align.Right) ? ((0f - num11) / 2f + array3[num13]) : (array3[num13] / 2f)));
				bool flag2 = true;
				string text2 = array[num13];
				foreach (char c2 in text2)
				{
					if (!flag2)
					{
						num15 -= s.Spacing;
					}
					flag2 = false;
					if (!RuneGlyphs.TryGet(c2, out var g2))
					{
						num15 -= 0.6f;
						continue;
					}
					float num16 = num15 - 0.5f - g2.Top;
					list.Add(new Quad
					{
						Glyph = g2,
						Min = new Vector2(num14 - g2.Width / 2f, num16 - g2.Height),
						Max = new Vector2(num14 + g2.Width / 2f, num16)
					});
					num15 -= 1f;
				}
			}
		}
		return list;
	}

	private static float LineWidth(string line, float spacing)
	{
		float num = 0f;
		for (int i = 0; i < line.Length; i++)
		{
			if (i > 0)
			{
				num += spacing;
			}
			num += (RuneGlyphs.TryGet(line[i], out var g) ? g.Ink : 0.6f);
		}
		return num;
	}

	private static float ColumnHeight(string line, float spacing)
	{
		float num = 0f;
		for (int i = 0; i < line.Length; i++)
		{
			if (i > 0)
			{
				num += spacing;
			}
			num += (RuneGlyphs.TryGet(line[i], out var _) ? 1f : 0.6f);
		}
		return num;
	}

	public static Mesh BuildMesh(Inscription ins, Transform frame, out Vector2 sizeMetres, Mesh reuse = null)
	{
		//IL_0016: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		RuneStyle style = ins.Style;
		Vector2 size;
		List<Quad> list = Layout(ins.Text, style, out size);
		sizeMetres = size * style.Size;
		bool flag = ins.OnSurface && style.Conform;
		int num = ((!flag) ? 1 : 4);
		List<Vector3> list2 = new List<Vector3>();
		List<Vector2> list3 = new List<Vector2>();
		List<int> list4 = new List<int>();
		Vector3 forward = frame.forward;
		foreach (Quad item in list)
		{
			int count = list2.Count;
			for (int i = 0; i <= num; i++)
			{
				for (int j = 0; j <= num; j++)
				{
					float num2 = (float)j / (float)num;
					float num3 = (float)i / (float)num;
					Vector3 val = new Vector3(Mathf.Lerp(item.Min.x, item.Max.x, num2), Mathf.Lerp(item.Min.y, item.Max.y, num3), 0f) * style.Size;
					if (flag)
					{
						val = Project(frame, val, style.Offset, forward, style.Size);
					}
					else if (ins.OnSurface)
					{
						val.z = 0f - style.Offset;
					}
					list2.Add(val);
					list3.Add(new Vector2(Mathf.Lerp(item.Glyph.UvMin.x, item.Glyph.UvMax.x, num2), Mathf.Lerp(item.Glyph.UvMin.y, item.Glyph.UvMax.y, num3)));
				}
			}
			for (int k = 0; k < num; k++)
			{
				for (int l = 0; l < num; l++)
				{
					int num4 = count + k * (num + 1) + l;
					int num5 = num4 + 1;
					int num6 = num4 + num + 1;
					int num7 = num6 + 1;
					list4.AddRange(new int[6] { num4, num6, num7, num4, num7, num5 });
				}
			}
		}
		Mesh val2 = (Mesh)(((Object)(object)reuse != (Object)null) ? ((object)reuse) : ((object)new Mesh
		{
			name = "mdl_runicInscription"
		}));
		val2.Clear();
		if (list2.Count > 65000)
		{
			val2.indexFormat = (IndexFormat)1;
		}
		val2.SetVertices(list2);
		val2.SetUVs(0, list3);
		val2.SetTriangles(list4, 0);
		val2.RecalculateNormals();
		if (flag)
		{
			val2.SetNormals(Enumerable.Repeat<Vector3>(new Vector3(0f, 0f, -1f), list2.Count).ToList());
		}
		val2.RecalculateTangents();
		val2.RecalculateBounds();
		return val2;
	}

	private static Vector3 Project(Transform frame, Vector3 local, float offset, Vector3 fwd, float size)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0026: 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_005f: 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_0044: 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)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0.5f, size * 2f);
		if (Surface.Cast(new Ray(frame.TransformPoint(local) - fwd * num, fwd), num * 2f, out var best))
		{
			return frame.InverseTransformPoint(((RaycastHit)(ref best)).point - fwd * offset);
		}
		local.z = 0f - offset;
		return local;
	}

	public static Material BuildMaterial(RuneStyle s)
	{
		Material obj = MakeBase();
		Apply(obj, s, 1f);
		return obj;
	}

	public static void Apply(Material m, RuneStyle s, float glowFactor)
	{
		//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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_004e: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		Color color = s.Color;
		Color val = Color.Lerp(new Color(0.06f, 0.05f, 0.05f), color, Mathf.Clamp01(s.Paint));
		val.a = 1f;
		m.SetColor("_Color", val);
		Color val2 = color * (s.Brightness * glowFactor);
		val2.a = 1f;
		m.SetColor("_EmissionColor", val2);
		if (s.Brightness > 0f)
		{
			m.EnableKeyword("_EMISSION");
		}
		else
		{
			m.DisableKeyword("_EMISSION");
		}
		m.SetFloat("_Cutoff", Mathf.Lerp(0.8f, 0.2f, Mathf.Clamp01(s.Thickness)));
		m.SetFloat("_Cull", s.DoubleSided ? 0f : 2f);
	}

	private static Material MakeBase()
	{
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Expected O, but got Unknown
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		Material val = Template();
		Material val2;
		if ((Object)(object)val != (Object)null)
		{
			val2 = new Material(val)
			{
				name = "mat_runicInscription"
			};
			val2.shaderKeywords = new string[5] { "_ALPHATEST_ON", "_CUTOFF", "_EMISSION", "_EMISSION_TEXTURED", "_WETNESS_NONE" };
			val2.renderQueue = 2450;
			val2.SetTexture("_MainTex", (Texture)(object)RuneGlyphs.Atlas);
			val2.SetTexture("_EmissionTex", (Texture)(object)RuneGlyphs.Atlas);
			val2.SetTexture("_NormTex", (Texture)(object)FlatNormal());
			val2.SetTexture("_DetNormTex", (Texture)(object)FlatNormal());
			val2.SetTexture("_GenTex", (Texture)(object)White());
			string[] array = new string[5] { "_DetTex", "_DetMaskTex", "_SpecColorTex", "_ParallaxMap", "_OcclusionMap" };
			foreach (string text in array)
			{
				if (val2.HasProperty(text))
				{
					val2.SetTexture(text, (Texture)null);
				}
			}
			val2.SetColor("_SpecColor", new Color(0.25f, 0.25f, 0.25f, 1f));
			(string, float)[] array2 = new(string, float)[24]
			{
				("_Mode", 1f),
				("_POM", 0f),
				("_DoubleFaced", 0f),
				("_ZWrite", 1f),
				("_SrcBlend", 1f),
				("_DstBlend", 0f),
				("_Glossiness", 0.4f),
				("_GlossMin", 0f),
				("_GlossMax", 1f),
				("_SmoothMin", 0f),
				("_SmoothMax", 1f),
				("_SpecBoost", 0f),
				("_Metallic", 0f),
				("_ReflectionRemoval", 0.9f),
				("_OcclusionStrength", 0f),
				("_EmitPulse", 0f),
				("_PulsateEmission", 0f),
				("_EmitScroll", 0f),
				("_Wetness", 0f),
				("_Snow", 0f),
				("_EmitGIBoost", 1f),
				("_BumpScale", 0f),
				("_NormStr", 0f),
				("_DetNormStr", 0f)
			};
			for (int i = 0; i < array2.Length; i++)
			{
				var (text2, num) = array2[i];
				if (val2.HasProperty(text2))
				{
					val2.SetFloat(text2, num);
				}
			}
		}
		else
		{
			val2 = new Material(Shader.Find("Standard"))
			{
				name = "mat_runicInscription_std"
			};
			val2.SetFloat("_Mode", 1f);
			val2.EnableKeyword("_ALPHATEST_ON");
			val2.SetTexture("_MainTex", (Texture)(object)RuneGlyphs.Atlas);
			val2.SetTexture("_EmissionMap", (Texture)(object)RuneGlyphs.Atlas);
			val2.renderQueue = 2450;
		}
		return val2;
	}

	private static Material Template()
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		if ((Object)(object)template != (Object)null)
		{
			return template;
		}
		List<Material> list = (from m in Resources.FindObjectsOfTypeAll<Material>()
			where (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && ((Object)m.shader).name == "Custom/Main Set/Main Standard"
			select m).ToList();
		template = ((IEnumerable<Material>)list).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name == "mat_env_atlasRunesA")) ?? ((IEnumerable<Material>)list).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name.StartsWith("mat_env_atlasStoneWood"))) ?? UnityEngineExtensions.FirstOrDefault<Material>((IList<Material>)list);
		if ((Object)(object)template != (Object)null)
		{
			template = new Material(template)
			{
				name = "mat_runicInscription_template"
			};
			Plugin.Log.LogMessage((object)"material template from the game's 'Custom/Main Set/Main Standard'");
		}
		else
		{
			Plugin.Log.LogWarning((object)"no material on 'Custom/Main Set/Main Standard' loaded: Unity's Standard shader instead");
		}
		return template;
	}

	private static Texture2D FlatNormal()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)flatNormal != (Object)null))
		{
			return flatNormal = Solid(new Color(0.5f, 0.5f, 1f, 0.5f), linear: true);
		}
		return flatNormal;
	}

	private static Texture2D White()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)white != (Object)null))
		{
			return white = Solid(Color.white, linear: false);
		}
		return white;
	}

	private static Texture2D Solid(Color c, bool linear)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false, linear);
		val.SetPixels(Enumerable.Repeat<Color>(c, 16).ToArray());
		val.Apply();
		return val;
	}

	public static InscriptionView Create(Inscription ins, bool ghost = false)
	{
		//IL_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("RunicInscription_" + (ghost ? "Ghost" : ins.Id));
		val.transform.SetPositionAndRotation(ins.Position, ins.Rotation);
		InscriptionView inscriptionView = val.AddComponent<InscriptionView>();
		inscriptionView.Init(ins, ghost);
		return inscriptionView;
	}
}
internal static class Surface
{
	public static int Mask
	{
		get
		{
			int num = Global.FullEnvironmentMask;
			if (num == 0)
			{
				num = -1;
			}
			return num & ~Global.CharactersMask;
		}
	}

	public static bool Cast(Ray ray, float distance, out RaycastHit best)
	{
		//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_0021: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		best = default(RaycastHit);
		float num = float.MaxValue;
		RaycastHit[] array = Physics.RaycastAll(ray, distance, Mask, (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			RaycastHit val = array[i];
			if (!(((RaycastHit)(ref val)).distance >= num) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>() != (Object)null))
			{
				best = val;
				num = ((RaycastHit)(ref val)).distance;
			}
		}
		return num < float.MaxValue;
	}
}
internal static class InscriptionStore
{
	private static InscriptionFile file;

	private static string fileCharacter;

	private static readonly List<InscriptionView> views = new List<InscriptionView>();

	public static IReadOnlyList<InscriptionView> Views => views;

	public static string Folder => Path.Combine(Paths.ConfigPath, "RunicInscriptions");

	public static string CharacterUid
	{
		get
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Character val = Plugin.LocalCharacter();
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return ((object)val.UID/*cast due to .constrained prefix*/).ToString();
		}
	}

	public static IEnumerable<Inscription> AllOwn
	{
		get
		{
			IEnumerable<Inscription> enumerable = File()?.Inscriptions;
			return enumerable ?? Array.Empty<Inscription>();
		}
	}

	internal static string CurrentPath
	{
		get
		{
			if (CharacterUid != null)
			{
				return PathFor(CharacterUid);
			}
			return null;
		}
	}

	public static int Total => File()?.Inscriptions.Count ?? 0;

	private static string PathFor(string uid)
	{
		return Path.Combine(Folder, uid + ".txt");
	}

	private static InscriptionFile File()
	{
		string characterUid = CharacterUid;
		if (characterUid == null)
		{
			return null;
		}
		if (file != null && fileCharacter == characterUid)
		{
			return file;
		}
		fileCharacter = characterUid;
		file = null;
		string text = PathFor(characterUid);
		try
		{
			if (System.IO.File.Exists(text))
			{
				file = new InscriptionFile
				{
					Inscriptions = TextFormat.Read(System.IO.File.ReadAllText(text))
				};
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("cannot read " + text + ": " + ex.Message));
			try
			{
				System.IO.File.Copy(text, text + ".bad", overwrite: true);
			}
			catch
			{
			}
		}
		if (file == null)
		{
			file = new InscriptionFile();
		}
		file.Character = characterUid;
		if (file.Inscriptions == null)
		{
			file.Inscriptions = new List<Inscription>();
		}
		foreach (Inscription inscription in file.Inscriptions)
		{
			if (inscription.Style == null)
			{
				inscription.Style = new RuneStyle();
			}
		}
		return file;
	}

	public static void Save()
	{
		if (file == null || fileCharacter == null)
		{
			return;
		}
		try
		{
			Directory.CreateDirectory(Folder);
			string text = PathFor(fileCharacter);
			string text2 = text + ".tmp";
			System.IO.File.WriteAllText(text2, TextFormat.Write(file.Inscriptions));
			if (System.IO.File.Exists(text))
			{
				System.IO.File.Delete(text);
			}
			System.IO.File.Move(text2, text);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("cannot save the inscriptions: " + ex.Message));
		}
	}

	public static void ShowLevel()
	{
		Clear();
		InscriptionFile inscriptionFile = File();
		if (inscriptionFile == null)
		{
			return;
		}
		string scene = SceneManagerHelper.ActiveSceneName;
		Packs.ShowLevel(scene);
		foreach (Inscription item in inscriptionFile.Inscriptions.Where((Inscription i) => i.Scene == scene))
		{
			try
			{
				views.Add(InscriptionBuilder.Create(item));
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"inscription '{item.Text}' ({item.Id}): {arg}");
			}
		}
		if (views.Count > 0)
		{
			Plugin.Log.LogMessage((object)$"{views.Count} inscription(s) in {scene}");
		}
	}

	public static void Clear()
	{
		foreach (InscriptionView view in views)
		{
			if ((Object)(object)view != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)view).gameObject);
			}
		}
		views.Clear();
		Packs.Clear();
	}

	public static InscriptionView Add(Inscription ins)
	{
		InscriptionFile inscriptionFile = File();
		if (inscriptionFile == null)
		{
			return null;
		}
		ins.Id = Guid.NewGuid().ToString("N").Substring(0, 12);
		ins.Scene = SceneManagerHelper.ActiveSceneName;
		ins.Created = DateTime.UtcNow.Ticks;
		inscriptionFile.Inscriptions.Add(ins);
		InscriptionView inscriptionView = InscriptionBuilder.Create(ins);
		views.Add(inscriptionView);
		Save();
		return inscriptionView;
	}

	public static void Remove(InscriptionView v)
	{
		if (!((Object)(object)v == (Object)null))
		{
			File()?.Inscriptions.Remove(v.Data);
			views.Remove(v);
			Object.Destroy((Object)(object)((Component)v).gameObject);
			Save();
		}
	}

	internal static void ForgetCache()
	{
		file = null;
		fileCharacter = null;
	}

	public static InscriptionView Last()
	{
		return (from v in views
			where (Object)(object)v != (Object)null
			orderby v.Data.Created descending
			select v).FirstOrDefault();
	}
}
internal class InscriptionView : MonoBehaviour
{
	private Mesh mesh;

	private Material mat;

	private MeshRenderer rend;

	private Light glow;

	private float bornAt = -100f;

	private bool selected;

	private const float FadeIn = 1.2f;

	public Inscription Data { get; private set; }

	public bool Ghost { get; private set; }

	public Vector2 Size { get; private set; }

	public void Init(Inscription ins, bool ghost)
	{
		Data = ins;
		Ghost = ghost;
		((Component)this).gameObject.AddComponent<MeshFilter>();
		rend = ((Component)this).gameObject.AddComponent<MeshRenderer>();
		((Renderer)rend).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)rend).receiveShadows = true;
		Rebuild();
	}

	public void Kindle()
	{
		bornAt = Time.time;
	}

	public void SetSelected(bool on)
	{
		selected = on;
	}

	public void Rebuild()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.SetPositionAndRotation(Data.Position, Data.Rotation);
		mesh = InscriptionBuilder.BuildMesh(Data, ((Component)this).transform, out var sizeMetres, mesh);
		Size = sizeMetres;
		((Component)this).GetComponent<MeshFilter>().sharedMesh = mesh;
		if ((Object)(object)mat == (Object)null)
		{
			mat = InscriptionBuilder.BuildMaterial(Data.Style);
			((Renderer)rend).sharedMaterial = mat;
		}
		UpdateLight();
		Refresh();
	}

	public void MoveTo(Vector3 pos, Quaternion rot)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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)
		Data.Position = pos;
		Data.Rotation = rot;
		if (Data.OnSurface && Data.Style.Conform)
		{
			Rebuild();
		}
		else
		{
			((Component)this).transform.SetPositionAndRotation(pos, rot);
		}
	}

	private void UpdateLight()
	{
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		RuneStyle style = Data.Style;
		if (!style.Light || !(style.Brightness > 0f) || Ghost)
		{
			if ((Object)(object)glow != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)glow).gameObject);
			}
			glow = null;
			return;
		}
		if ((Object)(object)glow == (Object)null)
		{
			GameObject val = new GameObject("Light");
			val.transform.SetParent(((Component)this).transform, false);
			glow = val.AddComponent<Light>();
			glow.type = (LightType)2;
			glow.shadows = (LightShadows)0;
			glow.renderMode = (LightRenderMode)0;
		}
		Transform transform = ((Component)glow).transform;
		Vector2 size = Size;
		transform.localPosition = new Vector3(0f, 0f, 0f - Mathf.Clamp(((Vector2)(ref size)).magnitude * 0.25f, 0.15f, 1f));
		glow.color = style.Color;
		glow.range = style.LightRange;
		glow.intensity = style.LightIntensity * Mathf.Min(style.Brightness, 6f) / 4f;
	}

	private void Refresh(float factor = 1f)
	{
		InscriptionBuilder.Apply(mat, Data.Style, factor);
		if ((Object)(object)glow != (Object)null)
		{
			glow.intensity = Data.Style.LightIntensity * Mathf.Min(Data.Style.Brightness, 6f) / 4f * factor;
		}
	}

	private void Update()
	{
		RuneStyle style = Data.Style;
		float num = 1f;
		float num2 = Time.time - bornAt;
		if (num2 < 1.2f)
		{
			num = Mathf.SmoothStep(0f, 1f, num2 / 1.2f);
		}
		if (style.Pulse)
		{
			num *= 0.55f + 0.45f * (0.5f + 0.5f * Mathf.Sin(Time.time * (float)Math.PI * 2f * style.PulseSpeed * 0.5f));
		}
		if (Ghost)
		{
			num *= 0.5f + 0.5f * Mathf.PingPong(Time.unscaledTime * 1.5f, 1f);
		}
		if (selected)
		{
			num *= 1.4f + 0.6f * Mathf.Sin(Time.unscaledTime * 8f);
		}
		if (Ghost || selected || style.Pulse || num2 < 1.3000001f)
		{
			Refresh(num);
		}
	}

	public bool Hit(Ray ray, out float distance)
	{
		//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_001f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		distance = 0f;
		Plane val = default(Plane);
		((Plane)(ref val))..ctor(-((Component)this).transform.forward, ((Component)this).transform.position);
		if (!((Plane)(ref val)).Raycast(ray, ref distance))
		{
			if (!Data.Style.DoubleSided && Data.OnSurface)
			{
				return false;
			}
			((Plane)(ref val))..ctor(((Component)this).transform.forward, ((Component)this).transform.position);
			if (!((Plane)(ref val)).Raycast(ray, ref distance))
			{
				return false;
			}
		}
		Vector3 val2 = ((Component)this).transform.InverseTransformPoint(((Ray)(ref ray)).GetPoint(distance));
		float num = Data.Style.Size * 0.3f;
		if (Mathf.Abs(val2.x) <= Size.x / 2f + num)
		{
			return Mathf.Abs(val2.y) <= Size.y / 2f + num;
		}
		return false;
	}

	private void OnDestroy()
	{
		if ((Object)(object)mesh != (Object)null)
		{
			Object.Destroy((Object)(object)mesh);
		}
		if ((Object)(object)mat != (Object)null)
		{
			Object.Destroy((Object)(object)mat);
		}
	}
}
public static class RunicInscriptionsAPI
{
	public const string Extension = ".runes";

	public static IDictionary<string, int> LoadedPacks => Packs.Loaded.ToDictionary((KeyValuePair<string, List<Inscription>> p) => p.Key, (KeyValuePair<string, List<Inscription>> p) => p.Value.Count);

	public static int AddPack(string packId, string text)
	{
		return Packs.Add(packId, text);
	}

	public static int AddPackFile(string path)
	{
		return Packs.Add(Path.GetFullPath(path), File.ReadAllText(path, Encoding.UTF8));
	}

	public static int AddPackResource(Assembly assembly, string resourceName)
	{
		using Stream stream = assembly.GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			throw new FileNotFoundException("no resource '" + resourceName + "' in " + assembly.GetName().Name);
		}
		using StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
		return Packs.Add(assembly.GetName().Name + "/" + resourceName, streamReader.ReadToEnd());
	}

	public static string ExportCharacter()
	{
		return Packs.Export();
	}
}
internal static class Packs
{
	internal static readonly Dictionary<string, List<Inscription>> Loaded = new Dictionary<string, List<Inscription>>();

	private static readonly List<string> order = new List<string>();

	private static readonly List<InscriptionView> views = new List<InscriptionView>();

	private static string shownScene;

	public static IReadOnlyList<InscriptionView> Views => views;

	public static string ExportFolder => Path.Combine(InscriptionStore.Folder, "Exports");

	public static int Add(string packId, string text)
	{
		if (string.IsNullOrEmpty(packId))
		{
			throw new ArgumentException("packId");
		}
		if (Loaded.ContainsKey(packId))
		{
			return 0;
		}
		List<Inscription> list = TextFormat.Read(text ?? "");
		foreach (Inscription item in list)
		{
			if (item.Style == null)
			{
				item.Style = new RuneStyle();
			}
			if (string.IsNullOrEmpty(item.Id))
			{
				item.Id = packId + "#" + list.IndexOf(item);
			}
		}
		list.RemoveAll((Inscription i) => string.IsNullOrEmpty(i.Scene) || string.IsNullOrEmpty(i.Text));
		Loaded[packId] = list;
		order.Add(packId);
		Plugin.Log.LogMessage((object)$"pack {packId}: {list.Count} inscription(s) in {list.Select((Inscription i) => i.Scene).Distinct().Count()} place(s)");
		if (shownScene != null && list.Any((Inscription i) => i.Scene == shownScene))
		{
			ShowLevel(shownScene);
		}
		return list.Count;
	}

	public static void ScanPlugins()
	{
		IEnumerable<string> enumerable;
		try
		{
			enumerable = Directory.GetFiles(Paths.PluginPath, "*.runes", SearchOption.AllDirectories).OrderBy<string, string>((string f) => f, StringComparer.OrdinalIgnoreCase);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("cannot look for packs in " + Paths.PluginPath + ": " + ex.Message));
			return;
		}
		foreach (string item in enumerable)
		{
			try
			{
				RunicInscriptionsAPI.AddPackFile(item);
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogError((object)("pack " + item + ": " + ex2.Message));
			}
		}
	}

	public static void ShowLevel(string scene)
	{
		Clear();
		shownScene = scene;
		if (scene == null || !Plugin.ShowPacks.Value)
		{
			return;
		}
		HashSet<string> hashSet = new HashSet<string>(InscriptionStore.AllOwn.Select((Inscription i) => i.Id));
		HashSet<string> hashSet2 = new HashSet<string>();
		foreach (string item in order)
		{
			foreach (Inscription item2 in Loaded[item])
			{
				if (!(item2.Scene != scene) && !hashSet.Contains(item2.Id) && hashSet2.Add(item2.Id))
				{
					try
					{
						views.Add(InscriptionBuilder.Create(item2));
					}
					catch (Exception ex)
					{
						Plugin.Log.LogError((object)$"pack {item}, inscription '{item2.Text}' ({item2.Id}): {ex}");
					}
				}
			}
		}
		if (views.Count > 0)
		{
			Plugin.Log.LogMessage((object)$"{views.Count} inscription(s) from mods in {scene}");
		}
	}

	public static void Clear()
	{
		foreach (InscriptionView view in views)
		{
			if ((Object)(object)view != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)view).gameObject);
			}
		}
		views.Clear();
		shownScene = null;
	}

	public static void Refresh()
	{
		if ((Object)(object)Plugin.LocalCharacter() != (Object)null && (Object)(object)NetworkLevelLoader.Instance != (Object)null && NetworkLevelLoader.Instance.IsOverallLoadingDone)
		{
			ShowLevel(SceneManagerHelper.ActiveSceneName);
		}
	}

	public static string Export()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		Character val = Plugin.LocalCharacter();
		List<Inscription> list = InscriptionStore.AllOwn.ToList();
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Directory.CreateDirectory(ExportFolder);
		string arg = new string((val.Name ?? "character").Select((char ch) => (!UnityEngineExtensions.Contains<char>(Path.GetInvalidFileNameChars(), ch) && ch != ' ') ? ch : '_').ToArray());
		string text = Path.Combine(ExportFolder, string.Format("{0}_{1:yyyyMMdd-HHmmss}{2}", arg, DateTime.Now, ".runes"));
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append("# Exported from the character \"").Append(val.Name).Append("\" (")
			.Append(UID.op_Implicit(val.UID))
			.Append(") on ")
			.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm"))
			.Append('\n');
		stringBuilder.Append("# ").Append(list.Count).Append(" inscription(s):");
		foreach (IGrouping<string, Inscription> item in from i in list
			group i by i.Scene into g
			orderby g.Key
			select g)
		{
			stringBuilder.Append(' ').Append(item.Key).Append(" (")
				.Append(item.Count())
				.Append(')');
		}
		stringBuilder.Append('\n');
		stringBuilder.Append("# Put this file in your mod's folder (BepInEx\\plugins\\<your mod>\\...): Runic Inscriptions loads every *.runes file.\n");
		stringBuilder.Append(TextFormat.Write(list));
		File.WriteAllText(text, stringBuilder.ToString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
		Plugin.Log.LogMessage((object)$"exported {list.Count} inscription(s) to {text}");
		return text;
	}
}
[BepInPlugin("tchernobill.runicinscriptions", "Runic Inscriptions", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "tchernobill.runicinscriptions";

	public const string NAME = "Runic Inscriptions";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	internal static Plugin Instance;

	internal static ConfigEntry<KeyCode> ToggleKey;

	internal static ConfigEntry<float> UiScale;

	internal static ConfigEntry<float> MaxDistance;

	internal static ConfigEntry<bool> Gesture;

	internal static ConfigEntry<KeyCode> PlaceKey;

	internal static ConfigEntry<bool> EditAfterCarving;

	internal static ConfigEntry<float> CrosshairHeight;

	internal static ConfigEntry<bool> ShowPacks;

	internal static Character LocalCharacter()
	{
		try
		{
			CharacterManager instance = CharacterManager.Instance;
			return (instance != null) ? instance.GetFirstLocalCharacter() : null;
		}
		catch (NullReferenceException)
		{
			return null;
		}
	}

	private void Awake()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Expected O, but got Unknown
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Expected O, but got Unknown
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Instance = this;
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Window Key", (KeyCode)287, "Opens and closes the carving window.");
		PlaceKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Place Key", (KeyCode)9, "Switches between the window (editing the text and its look, free cursor) and placing it in the world (crosshair, the character moves).");
		EditAfterCarving = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Back To The Window After Carving", false, "After carving, go back to the window instead of staying in placing mode (to carve several in a row).");
		CrosshairHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Crosshair Height", 0.66f, new ConfigDescription("Height of the aim point on the screen while placing (0.5 = centre, 1 = top): above the character, so it does not hide what it aims at.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 0.85f), Array.Empty<object>()));
		UiScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Window Scale", 1f, new ConfigDescription("Size of the window (1 = sized for 1080p, follows the screen height).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2.5f), Array.Empty<object>()));
		MaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Reach", 30f, new ConfigDescription("How far (m) from the camera runes can be carved.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 200f), Array.Empty<object>()));
		Gesture = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Gesture", true, "The character turns to the runes and makes a short casting gesture when carving them (out of combat).");
		ShowPacks = ((BaseUnityPlugin)this).Config.Bind<bool>("Mods", "Show Inscriptions From Mods", true, "Shows the inscriptions other mods bring (*.runes files): pre-written runes, the same for every character, not editable.");
		ShowPacks.SettingChanged += delegate
		{
			Packs.Refresh();
		};
		GameInput.Patch(new Harmony("tchernobill.runicinscriptions"));
		GameObject val = new GameObject("RunicInscriptions");
		Object.DontDestroyOnLoad((Object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<RuneWindow>();
		Packs.ScanPlugins();
		TestHarness.StartIfRequested(val);
		Log.LogMessage((object)string.Format("{0} {1} ready ({2} opens the window)", "Runic Inscriptions", "1.0.0", ToggleKey.Value));
	}
}
internal readonly struct Glyph
{
	public readonly char Char;

	public readonly Vector2 UvMin;

	public readonly Vector2 UvMax;

	public readonly float Width;

	public readonly float Height;

	public readonly float Top;

	public readonly float Ink;

	public Glyph(char c, float u0, float v0, float u1, float v1, float w, float h, float top, float ink)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		Char = c;
		UvMin = new Vector2(u0, v0);
		UvMax = new Vector2(u1, v1);
		Width = w;
		Height = h;
		Top = top;
		Ink = ink;
	}
}
internal static class RuneGlyphs
{
	public const float SpaceAdvance = 0.6f;

	private static Dictionary<char, Glyph> byChar;

	private static Texture2D atlas;

	private static readonly Glyph[] Table = new Glyph[37]
	{
		new Glyph('A', 0.01709f, 0.833594f, 0.10791f, 0.966406f, 1.1695f, 1.0678f, -0.5424f, 1.0339f),
		new Glyph('B', 0.151855f, 0.835938f, 0.223145f, 0.964063f, 0.9153f, 1.0339f, -0.5085f, 0.7797f),
		new Glyph('C', 0.272461f, 0.833594f, 0.352539f, 0.966406f, 1.0339f, 1.0678f, -0.5254f, 0.8983f),
		new Glyph('D', 0.392578f, 0.835938f, 0.481934f, 0.964063f, 1.1525f, 1.0339f, -0.5085f, 1.0169f),
		new Glyph('E', 0.524414f, 0.835938f, 0.600586f, 0.964063f, 0.9831f, 1.0339f, -0.5085f, 0.8475f),
		new Glyph('F', 0.651855f, 0.835938f, 0.723145f, 0.964063f, 0.9153f, 1.0339f, -0.5085f, 0.7797f),
		new Glyph('G', 0.768066f, 0.833594f, 0.856445f, 0.966406f, 1.1356f, 1.0678f, -0.5339f, 1f),
		new Glyph('H', 0.894531f, 0.835938f, 0.97998f, 0.964063f, 1.1017f, 1.0339f, -0.5169f, 0.9661f),
		new Glyph('I', 0.040039f, 0.635938f, 0.084961f, 0.764062f, 0.5763f, 1.0339f, -0.5169f, 0.4407f),
		new Glyph('J', 0.155273f, 0.635156f, 0.219727f, 49f / 64f, 0.8305f, 1.0508f, -0.5169f, 0.6949f),
		new Glyph('K', 0.271484f, 0.635938f, 0.353027f, 0.764062f, 1.0508f, 1.0339f, -0.5169f, 0.9153f),
		new Glyph('L', 0.399902f, 0.635938f, 0.475098f, 0.764062f, 0.9661f, 1.0339f, -0.5169f, 0.8305f),
		new Glyph('M', 0.507324f, 0.635938f, 0.617676f, 0.764062f, 1.4237f, 1.0339f, -0.5169f, 1.2881f),
		new Glyph('N', 0.642578f, 0.635156f, 0.731934f, 49f / 64f, 1.1525f, 1.0508f, -0.5085f, 1.0169f),
		new Glyph('O', 0.768066f, 0.635156f, 0.856445f, 49f / 64f, 1.1356f, 1.0508f, -0.5254f, 1f),
		new Glyph('P', 0.902344f, 0.635156f, 0.972168f, 49f / 64f, 0.8983f, 1.0508f, -0.5254f, 0.7627f),
		new Glyph('Q', 0.018066f, 0.432813f, 0.106445f, 0.567187f, 1.1356f, 1.0847f, -0.5424f, 1f),
		new Glyph('R', 0.147461f, 0.435937f, 0.227539f, 0.564063f, 1.0339f, 1.0339f, -0.5254f, 0.8983f),
		new Glyph('S', 0.28418f, 0.433594f, 0.34082f, 0.566406f, 0.7288f, 1.0678f, -0.5424f, 0.5932f),
		new Glyph('T', 0.394531f, 0.433594f, 0.47998f, 0.566406f, 1.1017f, 1.0678f, -0.5508f, 0.9661f),
		new Glyph('U', 0.518066f, 0.435156f, 0.606445f, 0.565625f, 1.1356f, 1.0508f, -0.5169f, 1f),
		new Glyph('V', 0.644531f, 0.435156f, 0.72998f, 0.565625f, 1.1017f, 1.0508f, -0.5169f, 0.9661f),
		new Glyph('W', 0.75f, 0.433594f, 0.875f, 0.566406f, 1.6102f, 1.0678f, -0.5169f, 1.4746f),
		new Glyph('X', 0.893066f, 0.435156f, 0.981445f, 0.565625f, 1.1356f, 1.0508f, -0.5169f, 1f),
		new Glyph('Y', 0.019531f, 0.235938f, 0.10498f, 0.364062f, 1.1017f, 1.0339f, -0.5169f, 0.9661f),
		new Glyph('Z', 0.147949f, 0.233594f, 0.227051f, 0.366406f, 1.0169f, 1.0678f, -0.5f, 0.8814f),
		new Glyph('1', 0.287598f, 0.235938f, 0.337402f, 0.364062f, 0.6441f, 1.0339f, -0.5f, 0.5085f),
		new Glyph('2', 0.405762f, 0.232812f, 15f / 32f, 0.367188f, 0.8136f, 1.0847f, -0.5169f, 0.678f),
		new Glyph('3', 0.533203f, 0.232812f, 0.591309f, 0.367188f, 0.7458f, 1.0847f, -0.5339f, 0.6102f),
		new Glyph('4', 0.655273f, 0.235156f, 0.719727f, 0.365625f, 0.8305f, 1.0508f, -0.5169f, 0.6949f),
		new Glyph('5', 0.77832f, 0.230469f, 0.84668f, 0.369531f, 0.8814f, 1.1186f, -0.5678f, 0.7458f),
		new Glyph('6', 0.908203f, 0.232812f, 0.966309f, 0.367188f, 0.7458f, 1.0847f, -0.5339f, 0.6102f),
		new Glyph('7', 0.032227f, 0.030469f, 0.092773f, 0.169531f, 0.7797f, 1.1186f, -0.5593f, 0.6441f),
		new Glyph('8', 0.142578f, 0.032813f, 0.231934f, 0.167188f, 1.1525f, 1.0847f, -0.5254f, 1.0169f),
		new Glyph('9', 0.282715f, 0.032813f, 0.341797f, 0.167188f, 0.7627f, 1.0847f, -0.5254f, 0.6271f),
		new Glyph('0', 0.392578f, 0.032813f, 0.481934f, 0.167188f, 1.1525f, 1.0847f, -0.5254f, 1.0169f),
		new Glyph('?', 0.532715f, 0.033594f, 0.591797f, 0.166406f, 0.7627f, 1.0678f, -0.5085f, 0.6271f)
	};

	public static IEnumerable<Glyph> All => Table;

	public static Texture2D Atlas
	{
		get
		{
			//IL_003f: 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_004f: 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_0062: Expected O, but got Unknown
			if ((Object)(object)atlas != (Object)null)
			{
				return atlas;
			}
			using (Stream stream = typeof(RuneGlyphs).Assembly.GetManifestResourceStream("RunicInscriptions.runes_atlas.png"))
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				atlas = new Texture2D(2, 2, (TextureFormat)4, true, false)
				{
					name = "tex_runicInscriptions_atlas",
					wrapMode = (TextureWrapMode)1,
					anisoLevel = 4
				};
				ImageConversion.LoadImage(atlas, memoryStream.ToArray(), false);
				((Texture)atlas).filterMode = (FilterMode)2;
			}
			return atlas;
		}
	}

	public static bool TryGet(char c, out Glyph g)
	{
		if (byChar == null)
		{
			byChar = new Dictionary<char, Glyph>();
			Glyph[] table = Table;
			for (int i = 0; i < table.Length; i++)
			{
				Glyph value = table[i];
				byChar[value.Char] = value;
			}
		}
		return byChar.TryGetValue(c, out g);
	}

	public static string Normalize(string text, out int dropped)
	{
		dropped = 0;
		if (string.IsNullOrEmpty(text))
		{
			return "";
		}
		StringBuilder stringBuilder = new StringBuilder(text.Length);
		string text2 = text.Normalize(NormalizationForm.FormD);
		foreach (char c in text2)
		{
			if (CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark)
			{
				continue;
			}
			char c2 = char.ToUpperInvariant(c);
			switch (c2)
			{
			case 'Œ':
				stringBuilder.Append("OE");
				break;
			case 'Æ':
				stringBuilder.Append("AE");
				break;
			case 'ß':
				stringBuilder.Append("SS");
				break;
			default:
			{
				if (!TryGet(c2, out var _))
				{
					switch (c2)
					{
					case '\t':
						stringBuilder.Append(' ');
						break;
					default:
						dropped++;
						break;
					case '\r':
						break;
					}
					break;
				}
				goto case '\n';
			}
			case '\n':
			case ' ':
				stringBuilder.Append(c2);
				break;
			}
		}
		return stringBuilder.ToString();
	}
}
internal class RuneWindow : MonoBehaviour
{
	public static RuneWindow Instance;

	internal string RawText = "OUTWARD";

	internal readonly Dictionary<string, Rect> Marks = new Dictionary<string, Rect>();

	internal RuneStyle Style = new RuneStyle();

	internal bool OnSurface = true;

	internal float Roll;

	internal float AirDistance = 3f;

	internal Ray? AimOverride;

	private InscriptionView ghost;

	private InscriptionView selected;

	private bool moving;

	private readonly Stack<InscriptionView> carved = new Stack<InscriptionView>();

	private string lastSignature;

	private float dirtyAt = -1f;

	internal Rect window = new Rect(30f, 80f, 470f, 760f);

	internal Vector2 scroll;

	private Vector2 listScroll;

	internal static bool Secret;

	private bool overWindow;

	private bool aimValid;

	private Vector3 aimPos;

	private Quaternion aimRot;

	private string status = "";

	private float statusUntil;

	private int dropped;

	private Character character;

	private string scene;

	private static readonly string[] AlignNames = new string[3] { "Left", "Center", "Right" };

	private static readonly string[] ModeNames = new string[2] { "On a surface", "In the air" };

	private static Texture2D dot;

	public bool Open { get; private set; }

	public bool Placing
	{
		get
		{
			if (Open)
			{
				return GameInput.Current == GameInput.Mode.Placing;
			}
			return false;
		}
	}

	internal static Vector2 AimViewport => new Vector2(0.5f, Plugin.CrosshairHeight.Value);

	private Camera Cam
	{
		get
		{
			Character obj = character;
			if (obj == null)
			{
				return null;
			}
			CharacterCamera characterCamera = obj.CharacterCamera;
			if (characterCamera == null)
			{
				return null;
			}
			return characterCamera.CameraScript;
		}
	}

	private float UiScale => Mathf.Clamp(Plugin.UiScale.Value * (float)Screen.height / 1080f, 0.5f, 3f);

	private static Rect ToScreen(Rect r)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//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_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = GUIUtility.GUIToScreenPoint(((Rect)(ref r)).min);
		Vector2 val2 = GUIUtility.GUIToScreenPoint(((Rect)(ref r)).max);
		return Rect.MinMaxRect(val.x, val.y, val2.x, val2.y);
	}

	private void Mark(string name, Rect r)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_0014: 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)
		if ((int)Event.current.type == 7)
		{
			Marks[name] = ToScreen(r);
		}
	}

	private void Awake()
	{
		Instance = this;
	}

	private void Update()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Invalid comparison between Unknown and I4
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Invalid comparison between Unknown and I4
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		TrackLevel();
		bool flag = !Placing && TextFieldFocused();
		if (Input.GetKeyDown(Plugin.ToggleKey.Value) && (!flag || ((int)Plugin.ToggleKey.Value >= 282 && (int)Plugin.ToggleKey.Value <= 296)))
		{
			Toggle();
		}
		else
		{
			if (!Open)
			{
				return;
			}
			if ((Object)(object)character == (Object)null || (Object)(object)NetworkLevelLoader.Instance == (Object)null || !NetworkLevelLoader.Instance.IsOverallLoadingDone)
			{
				Close();
				return;
			}
			if (Input.GetKeyDown(Plugin.PlaceKey.Value))
			{
				if (Placing)
				{
					StartEditing();
				}
				else
				{
					StartPlacing();
				}
			}
			else if (Placing)
			{
				PlacingInput();
			}
			else if (Input.GetKeyDown((KeyCode)27))
			{
				if (flag)
				{
					GUIUtility.keyboardControl = 0;
				}
				else
				{
					Close();
				}
			}
			if (Input.GetKey((KeyCode)306) && Input.GetKeyDown((KeyCode)122) && !flag)
			{
				Undo();
			}
			Aim();
			Sync();
		}
	}

	private void LateUpdate()
	{
		if (Open && !Placing)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
	}

	public void StartEditing()
	{
		if (Open)
		{
			GameInput.Set(GameInput.Mode.Editing, character);
			if (moving)
			{
				moving = false;
			}
		}
	}

	public void StartPlacing()
	{
		if (Open)
		{
			GUIUtility.keyboardControl = 0;
			if ((Object)(object)selected != (Object)null && !moving)
			{
				Deselect();
			}
			GameInput.Set(GameInput.Mode.Placing, character);
			lastSignature = null;
		}
	}

	private void PlacingInput()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		if (character.CharacterUI.IsMenuFocused)
		{
			return;
		}
		Camera cam = Cam;
		if ((Object)(object)cam == (Object)null)
		{
			return;
		}
		Ray ray = CentreRay(cam);
		if (Input.GetMouseButtonDown(0))
		{
			CarveAtAim();
		}
		else if (Input.GetMouseButtonDown(1) || Input.GetKeyDown((KeyCode)27))
		{
			StartEditing();
		}
		else if (Input.GetMouseButtonDown(2))
		{
			InscriptionView inscriptionView = Pick(ray);
			if ((Object)(object)inscriptionView != (Object)null)
			{
				Select(inscriptionView);
				StartEditing();
			}
			else
			{
				Say("No inscription under the crosshair.");
			}
		}
		else if (Input.GetKeyDown((KeyCode)127))
		{
			InscriptionView inscriptionView2 = Pick(ray);
			if ((Object)(object)inscriptionView2 != (Object)null)
			{
				Delete(inscriptionView2);
			}
			else
			{
				Say("No inscription under the crosshair.");
			}
		}
		float y = Input.mouseScrollDelta.y;
		if (Mathf.Abs(y) > 0.01f)
		{
			Wheel(Mathf.Sign(y), Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303), Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305));
		}
	}

	internal InscriptionView CarveAtAim()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		if (!aimValid)
		{
			Say(OnSurface ? "No surface there (or too far)." : "Nowhere to carve.");
			return null;
		}
		bool num = moving && (Object)(object)selected != (Object)null;
		InscriptionView inscriptionView = CarveAt(aimPos, aimRot);
		if (num || ((Object)(object)inscriptionView != (Object)null && Plugin.EditAfterCarving.Value))
		{
			StartEditing();
		}
		return inscriptionView;
	}

	private static Ray CentreRay(Camera cam)
	{
		//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_001a: 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)
		return cam.ViewportPointToRay(new Vector3(AimViewport.x, AimViewport.y, 0f));
	}

	private void Wheel(float d, bool shift, bool control)
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		if (shift)
		{
			Style.Size = Mathf.Clamp(Style.Size * ((d > 0f) ? 1.1f : 0.9090909f), 0.05f, 5f);
			return;
		}
		if (control)
		{
			AirDistance = Mathf.Clamp(AirDistance + d * 0.25f, 0.5f, 20f);
			return;
		}
		Roll = Mathf.Repeat(Roll + d * 15f + 180f, 360f) - 180f;
		if ((Object)(object)selected != (Object)null && !moving)
		{
			Inscription data = selected.Data;
			data.Rotation *= Quaternion.Euler(0f, 0f, d * 15f);
			selected.Rebuild();
			dirtyAt = Time.unscaledTime;
		}
	}

	private void TrackLevel()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		NetworkLevelLoader instance = NetworkLevelLoader.Instance;
		Character val = Plugin.LocalCharacter();
		bool flag = (Object)(object)instance != (Object)null && instance.IsOverallLoadingDone && (Object)(object)val != (Object)null;
		string text = (flag ? (SceneManagerHelper.ActiveSceneName + "|" + UID.op_Implicit(val.UID)) : null);
		if (!(text == scene))
		{
			scene = text;
			if (Open)
			{
				Close();
			}
			if (flag)
			{
				character = val;
				InscriptionStore.ShowLevel();
			}
			else
			{
				character = null;
				InscriptionStore.Clear();
			}
		}
	}

	public void Toggle()
	{
		if (Open)
		{
			Close();
		}
		else
		{
			Show();
		}
	}

	public void Show()
	{
		if (!Open && !((Object)(object)character == (Object)null) && !((Object)(object)character.CharacterUI == (Object)null) && !character.CharacterUI.IsMenuFocused && !character.CharacterUI.IsDialogueInProgress)
		{
			Open = true;
			GameInput.Set(GameInput.Mode.Editing, character);
			lastSignature = null;
		}
	}

	public void Close()
	{
		if (Open)
		{
			Open = false;
			Deselect();
			if ((Object)(object)ghost != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)ghost).gameObject);
			}
			ghost = null;
			moving = false;
			GameInput.Set(GameInput.Mode.Free, character);
			GUIUtility.keyboardControl = 0;
		}
	}

	private static bool TextFieldFocused()
	{
		return GUIUtility.keyboardControl != 0;
	}

	private void Aim()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		Camera cam = Cam;
		aimValid = false;
		if (!((Object)(object)cam == (Object)null) && (!Placing || !character.CharacterUI.IsMenuFocused || AimOverride.HasValue))
		{
			Ray ray = (Ray)(((??)AimOverride) ?? CentreRay(cam));
			aimValid = Pose(ray, out aimPos, out aimRot);
		}
	}

	public bool Pose(Ray ray, out Vector3 pos, out Quaternion rot)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_0028: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		pos = Vector3.zero;
		rot = Quaternion.identity;
		Camera cam = Cam;
		Vector3 val = (((Object)(object)cam != (Object)null) ? ((Component)cam).transform.forward : ((Ray)(ref ray)).direction);
		if (OnSurface)
		{
			if (!Surface.Cast(ray, Plugin.MaxDistance.Value, out var best))
			{
				return false;
			}
			Vector3 normal = ((RaycastHit)(ref best)).normal;
			Vector3 val2 = ((!(Mathf.Abs(normal.y) < 0.7f)) ? Vector3.ProjectOnPlane(val, normal) : Vector3.ProjectOnPlane(Vector3.up, normal));
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				val2 = Vector3.ProjectOnPlane(Vector3.forward, normal);
			}
			rot = Quaternion.LookRotation(-normal, ((Vector3)(ref val2)).normalized) * Quaternion.Euler(0f, 0f, Roll);
			pos = ((RaycastHit)(ref best)).point;
			return true;
		}
		Vector3 val3 = Vector3.ProjectOnPlane(((Ray)(ref ray)).direction, Vector3.up);
		if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
		{
			val3 = Vector3.ProjectOnPlane(val, Vector3.up);
		}
		rot = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up) * Quaternion.Euler(0f, 0f, Roll);
		pos = ((Ray)(ref ray)).GetPoint(AirDistance);
		return true;
	}

	private void Sync()
	{
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		string text = RuneGlyphs.Normalize(RawText, out dropped);
		string text2 = text + "|" + OnSurface + "|" + TextFormat.Fields(Style);
		bool flag = text2 != lastSignature;
		lastSignature = text2;
		if ((Object)(object)selected != (Object)null && !moving)
		{
			if ((Object)(object)ghost != (Object)null)
			{
				((Component)ghost).gameObject.SetActive(false);
			}
			if (flag)
			{
				selected.Data.Text = text;
				selected.Data.OnSurface = OnSurface;
				selected.Data.Style = Style;
				selected.Rebuild();
				dirtyAt = Time.unscaledTime;
			}
			if (dirtyAt > 0f && Time.unscaledTime - dirtyAt > 1f)
			{
				InscriptionStore.Save();
				dirtyAt = -1f;
			}
			return;
		}
		if (!aimValid || text.Trim().Length <= 0)
		{
			if ((Object)(object)ghost != (Object)null)
			{
				((Component)ghost).gameObject.SetActive(false);
			}
			return;
		}
		if ((Object)(object)ghost == (Object)null)
		{
			ghost = InscriptionBuilder.Create(new Inscription
			{
				Text = text,
				Style = Style,
				OnSurface = OnSurface,
				Position = aimPos,
				Rotation = aimRot
			}, ghost: true);
			flag = false;
		}
		((Component)ghost).gameObject.SetActive(true);
		Inscription data = ghost.Data;
		Vector3 val = data.Position - aimPos;
		bool flag2 = ((Vector3)(ref val)).sqrMagnitude > 1E-06f || Quaternion.Angle(data.Rotation, aimRot) > 0.05f;
		if (flag)
		{
			data.Text = text;
			data.Style = Style;
			data.OnSurface = OnSurface;
			data.Position = aimPos;
			data.Rotation = aimRot;
			ghost.Rebuild();
		}
		else if (flag2)
		{
			ghost.MoveTo(aimPos, aimRot);
		}
	}

	public InscriptionView CarveAt(Vector3 pos, Quaternion rot)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		int num;
		string text = RuneGlyphs.Normalize(RawText, out num);
		if (moving && (Object)(object)selected != (Object)null)
		{
			selected.Data.Position = pos;
			selected.Data.Rotation = rot;
			selected.Data.OnSurface = OnSurface;
			selected.Rebuild();
			selected.Kindle();
			InscriptionStore.Save();
			moving = false;
			Gesture(pos);
			Say("Moved.");
			return selected;
		}
		if (text.Trim().Length == 0)
		{
			Say("Nothing to carve: type a text first.");
			return null;
		}
		InscriptionView inscriptionView = InscriptionStore.Add(new Inscription
		{
			Text = text,
			Position = pos,
			Rotation = rot,
			OnSurface = OnSurface,
			Style = Style.Clone()
		});
		if ((Object)(object)inscriptionView == (Object)null)
		{
			return null;
		}
		inscriptionView.Kindle();
		carved.Push(inscriptionView);
		Gesture(pos);
		Say("Carved" + Quoted(text) + ".");
		return inscriptionView;
	}

	private void Gesture(Vector3 at)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Gesture.Value || (Object)(object)character == (Object)null || character.InCombat || !character.InLocomotion || character.IsCasting)
		{
			return;
		}
		try
		{
			Vector3 val = Vector3.ProjectOnPlane(at - ((Component)character).transform.position, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
			{
				((Component)character).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
			}
			character.SpellCastAnim((SpellCastType)1, (SpellCastModifier)0, 0);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogDebug((object)("gesture: " + ex.Message));
		}
	}

	public void Undo()
	{
		while (carved.Count > 0 && (Object)(object)carved.Peek() == (Object)null)
		{
			carved.Pop();
		}
		if (carved.Count == 0)
		{
			Say("Nothing to undo.");
			return;
		}
		InscriptionView inscriptionView = carved.Pop();
		if ((Object)(object)inscriptionView == (Object)(object)selected)
		{
			Deselect();
		}
		Say("Erased" + Quoted(inscriptionView.Data.Text) + ".");
		InscriptionStore.Remove(inscriptionView);
	}

	public void Select(InscriptionView v)
	{
		if (!((Object)(object)v == (Object)(object)selected))
		{
			Deselect();
			if (!((Object)(object)v == (Object)null))
			{
				selected = v;
				v.SetSelected(on: true);
				RawText = v.Data.Text;
				Style = v.Data.Style;
				OnSurface = v.Data.OnSurface;
				lastSignature = null;
				moving = false;
			}
		}
	}

	public void Deselect()
	{
		if (!((Object)(object)selected == (Object)null))
		{
			selected.SetSelected(on: false);
			Style = Style.Clone();
			selected = null;
			moving = false;
			InscriptionStore.Save();
			dirtyAt = -1f;
			lastSignature = null;
		}
	}

	private void Delete(InscriptionView v)
	{
		if ((Object)(object)v == (Object)(object)selected)
		{
			selected.SetSelected(on: false);
			Style = Style.Clone();
			selected = null;
			moving = false;
		}
		Say("Erased" + Quoted(v.Data.Text) + ".");
		InscriptionStore.Remove(v);
	}

	private InscriptionView Pick(Ray ray)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		InscriptionView result = null;
		float num = Plugin.MaxDistance.Value;
		foreach (InscriptionView view in InscriptionStore.Views)
		{
			if ((Object)(object)view != (Object)null && view.Hit(ray, out var distance) && distance < num)
			{
				result = view;
				num = distance;
			}
		}
		return result;
	}

	public string ExportAll()
	{
		if ((Object)(object)selected != (Object)null)
		{
			Deselect();
		}
		string text = null;
		try
		{
			text = Packs.Export();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("export: " + ex));
		}
		Say((text == null) ? "Export failed (see the log)." : $"Exported {InscriptionStore.Total} inscription(s) to config\\RunicInscriptions\\Exports\\{Path.GetFileName(text)}");
		return text;
	}

	private void Say(string s)
	{
		status = s;
		statusUntil = Time.unscaledTime + 4f;
	}

	private static string Quoted(string s)
	{
		if (!Secret)
		{
			return " \"" + Short(s) + "\"";
		}
		return "";
	}

	private static string Short(string s)
	{
		s = s.Replace('\n', ' ');
		if (s.Length <= 24)
		{
			return s;
		}
		return s.Substring(0, 22) + "...";
	}

	private void OnGUI()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Invalid comparison between Unknown and I4
		//IL_001e: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Expected O, but got Unknown
		//IL_00ea: 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_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Invalid comparison between Unknown and I4
		if (!Open)
		{
			return;
		}
		Styles.Init();
		Event current = Event.current;
		if ((int)current.type == 4 && (current.keyCode == Plugin.PlaceKey.Value || ((int)Plugin.PlaceKey.Value == 9 && current.character == '\t')))
		{
			current.Use();
			return;
		}
		float uiScale = UiScale;
		if (Placing)
		{
			if (!character.CharacterUI.IsMenuFocused)
			{
				DrawCrosshair();
				DrawPlacingBanner(uiScale);
				DrawHint(uiScale);
			}
			return;
		}
		Matrix4x4 matrix = GUI.matrix;
		GUI.matrix = Matrix4x4.Scale(new Vector3(uiScale, uiScale, 1f));
		((Rect)(ref window)).height = Mathf.Min(((Rect)(ref window)).height, (float)Screen.height / uiScale - 20f);
		window = GUI.Window(1381322309, window, new WindowFunction(DrawWindow), "Runic Inscriptions", Styles.Window);
		((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f - ((Rect)(ref window)).width + 60f, (float)Screen.width / uiScale - 60f);
		((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, (float)Screen.height / uiScale - 30f);
		overWindow = ((Rect)(ref window)).Contains(current.mousePosition);
		if (!overWindow)
		{
			WorldEvents(current);
		}
		GUI.matrix = matrix;
		DrawHint(uiScale);
	}

	private void WorldEvents(Event e)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Invalid comparison between Unknown and I4
		//IL_007b: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		Camera cam = Cam;
		if ((Object)(object)cam == (Object)null)
		{
			return;
		}
		if ((int)e.type == 0 && e.button == 0)
		{
			GUIUtility.keyboardControl = 0;
			e.Use();
		}
		else if ((int)e.type == 0 && e.button == 1)
		{
			InscriptionView inscriptionView = Pick(cam.ScreenPointToRay(Input.mousePosition));
			if ((Object)(object)inscriptionView != (Object)null)
			{
				Select(inscriptionView);
			}
			else
			{
				Deselect();
			}
			e.Use();
		}
		else if ((int)e.type == 6)
		{
			Wheel(0f - Mathf.Sign(e.delta.y), e.shift, e.control);
			e.Use();
		}
	}

	private void DrawCrosshair()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)dot == (Object)null)
		{
			dot = Texture2D.whiteTexture;
		}
		float num = (float)Screen.width * AimViewport.x;
		float num2 = (float)Screen.height * (1f - AimViewport.y);
		float s = Mathf.Max(1f, (float)Screen.height / 1080f);
		Color c = (Color)(aimValid ? Color.Lerp(Style.Color, Color.white, 0.4f) : new Color(1f, 0.35f, 0.3f));
		float num3 = 9f * s;
		float num4 = 4f * s;
		float num5 = 2f * s;
		Bar(num - num4 - num3, num2 - num5 / 2f, num3, num5);
		Bar(num + num4, num2 - num5 / 2f, num3, num5);
		Bar(num - num5 / 2f, num2 - num4 - num3, num5, num3);
		Bar(num - num5 / 2f, num2 + num4, num5, num3);
		GUI.color = Color.white;
		void Bar(float x, float y, float w, float h)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			GUI.color = new Color(0f, 0f, 0f, 0.7f);
			GUI.DrawTexture(new Rect(x - s, y - s, w + 2f * s, h + 2f * s), (Texture)(object)dot);
			GUI.color = c;
			GUI.DrawTexture(new Rect(x, y, w, h), (Texture)(object)dot);
		}
	}

	private void DrawPlacingBanner(float k)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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)
		Matrix4x4 matrix = GUI.matrix;
		GUI.matrix = Matrix4x4.Scale(new Vector3(k, k, 1f));
		float num = 420f;
		float num2 = ((float)Screen.width / k - num) / 2f;
		string text = ((moving && (Object)(object)selected != (Object)null) ? ("Moving: " + Short(selected.Data.Text)) : "Carving");
		GUI.Label(new Rect(num2, 14f, num, 22f), text, Styles.Hint);
		DrawPreview(new Rect(num2, 38f, num, 56f));
		GUI.matrix = matrix;
	}

	private void DrawHint(float k)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		string text = ((object)Plugin.PlaceKey.Value/*cast due to .constrained prefix*/).ToString();
		string text2 = ((!Placing) ? (((Object)(object)selected != (Object)null) ? ("Editing the selected inscription live · Right click another to select it · " + text + ": carve a new one") : (text + ": place it in the world · Right click an inscription: edit it · Wheel: turn · Esc: close")) : ((moving && (Object)(object)selected != (Object)null) ? ("Left click: put it there · Wheel: turn · Right click / Esc / " + text + ": cancel") : ("Left click: carve · Wheel: turn · Shift+wheel: size · Ctrl+wheel: distance (air) · Middle click: edit that one · Del: erase it · Right click / Esc / " + text + ": back to the window · Ctrl+Z: undo")));
		if (Time.unscaledTime < statusUntil)
		{
			text2 = status + "    " + text2;
		}
		Vector2 val = Styles.Hint.CalcSize(new GUIContent(text2));
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(((float)Screen.width - val.x * k) / 2f, (float)Screen.height - (val.y + 40f) * k, val.x * k, val.y * k);
		Matrix4x4 matrix = GUI.matrix;
		GUI.matrix = Matrix4x4.TRS(new Vector3(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, 0f), Quaternion.identity, new Vector3(k, k, 1f));
		GUI.Label(new Rect(0f, 0f, val.x, val.y), text2, Styles.Hint);
		GUI.matrix = matrix;
	}

	private void DrawWindow(int id)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_0517: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0822: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(4f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button(((Object)(object)selected != (Object)null) ? $"Carve a new one ({Plugin.PlaceKey.Value})" : $"Place in the world ({Plugin.PlaceKey.Value})", Styles.Primary, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
		{
			StartPlacing();
		}
		Mark("button:place", GUILayoutUtility.GetLastRect());
		if (GUILayout.Button($"Close ({Plugin.ToggleKey.Value})", Styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(110f),
			GUILayout.Height(34f)
		}))
		{
			Close();
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(4f);
		scroll = GUILayout.BeginScrollView(scroll, false, false, Array.Empty<GUILayoutOption>());
		GUILayout.Label((!((Object)(object)selected != (Object)null)) ? "Text" : (moving ? "Moving the selected inscription" : "Selected inscription (live edit)"), Styles.Header, Array.Empty<GUILayoutOption>());
		GUI.SetNextControlName("runeText");
		RawText = GUILayout.TextArea(RawText ?? "", 400, Styles.Text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinHeight(48f) });
		Mark("textbox", GUILayoutUtility.GetLastRect());
		if (dropped > 0)
		{
			GUILayout.Label($"{dropped} character(s) without a rune are left out (the runes write A-Z, 0-9 and ?).", Styles.Small, Array.Empty<GUILayoutOption>());
		}
		DrawPreview(GUILayoutUtility.GetRect(430f, 64f));
		DrawKeyboard();
		GUILayout.Label("Look", Styles.Header, Array.Empty<GUILayoutOption>());
		Style.Size = Slider("Rune height", Style.Size, 0.05f, 3f, "0.00 m");
		Style.Spacing = Slider("Spacing", Style.Spacing, -0.2f, 1.5f, "0.00");
		Style.LineSpacing = Slider("Line spacing", Style.LineSpacing, -0.3f, 2f, "0.00");
		Style.Thickness = Slider("Stroke", Style.Thickness, 0f, 1f, "0.00");
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Align", Styles.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		Style.Align = (Align)GUILayout.Toolbar((int)Style.Align, AlignNames, Styles.Button, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		Style.Vertical = GUILayout.Toggle(Style.Vertical, " Vertical (columns, top to bottom)", Styles.Toggle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Colour and light", Styles.Header, Array.Empty<GUILayoutOption>());
		DrawPresets();
		Style.Color.r = Slider("Red", Style.Color.r, 0f, 1f, "0.00");
		Style.Color.g = Slider("Green", Style.Color.g, 0f, 1f, "0.00");
		Style.Color.b = Slider("Blue", Style.Color.b, 0f, 1f, "0.00");
		Style.Brightness = Slider("Glow", Style.Brightness, 0f, 12f, "0.0");
		Style.Paint = Slider("Paint", Style.Paint, 0f, 1f, "0.00");
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		Style.Pulse = GUILayout.Toggle(Style.Pulse, " Pulse", Styles.Toggle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		Mark("toggle:pulse", GUILayoutUtility.GetLastRect());
		if (Style.Pulse)
		{
			Style.PulseSpeed = GUILayout.HorizontalSlider(Style.PulseSpeed, 0.1f, 4f, Styles.Slider, Styles.Thumb, Array.Empty<GUILayoutOption>());
		}
		GUILayout.EndHorizontal();
		Style.Light = GUILayout.Toggle(Style.Light, " Cast light on the surroundings", Styles.Toggle, Array.Empty<GUILayoutOption>());
		Mark("toggle:light", GUILayoutUtility.GetLastRect());
		if (Style.Light)
		{
			Style.LightRange = Slider("Light range", Style.LightRange, 0.5f, 15f, "0.0 m");
			Style.LightIntensity = Slider("Light strength", Style.LightIntensity, 0f, 4f, "0.00");
		}
		GUILayout.Label("Placement", Styles.Header, Array.Empty<GUILayoutOption>());
		OnSurface = GUILayout.Toolbar((!OnSurface) ? 1 : 0, ModeNames, Styles.Button, Array.Empty<GUILayoutOption>()) == 0;
		if (OnSurface)
		{
			Style.Conform = GUILayout.Toggle(Style.Conform, " Follow the relief", Styles.Toggle, Array.Empty<GUILayoutOption>());
			Style.Offset = Slider("Off the surface", Style.Offset, 0.002f, 0.2f, "0.000 m");
		}
		else
		{
			AirDistance = Slider("Distance", AirDistance, 0.5f, 20f, "0.0 m");
		}
		Style.DoubleSided = GUILayout.Toggle(Style.DoubleSided, " Visible from behind (mirrored)", Styles.Toggle, Array.Empty<GUILayoutOption>());
		float num = Slider("Rotation", Roll, -180f, 180f, "0°");
		if (Mathf.Abs(num - Roll) > 0.01f)
		{
			Roll = num;
		}
		GUILayout.Label("Inscriptions here", Styles.Header, Array.Empty<GUILayoutOption>());
		if ((Object)(object)selected != (Object)null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Move", Styles.Button, Array.Empty<GUILayoutOption>()))
			{
				moving = true;
				StartPlacing();
			}
			if (GUILayout.Button("Delete", Styles.Button, Array.Empty<GUILayoutOption>()))
			{
				Delete(selected);
			}
			if (GUILayout.Button("Done", Styles.Button, Array.Empty<GUILayoutOption>()))
			{
				Deselect();
			}
			GUILayout.EndHorizontal();
		}
		DrawList();
		GUILayout.Label($"{InscriptionStore.Total} inscription(s) by this character in all places.", Styles.Small, Array.Empty<GUILayoutOption>());
		int num2 = Packs.Views.Count((InscriptionView v) => (Object)(object)v != (Object)null);
		if (num2 > 0)
		{
			GUILayout.Label($"{num2} more here from mods (pre-written, not editable).", Styles.Small, Array.Empty<GUILayoutOption>());
		}
		if (GUILayout.Button("Export all to a file (for a mod)", Styles.Button, Array.Empty<GUILayoutOption>()))
		{
			ExportAll();
		}
		GUILayout.EndScrollView();
		Mark("scrollview", GUILayoutUtility.GetLastRect());
		if (GUILayout.Button("Undo last (Ctrl+Z)", Styles.Button, Array.Empty<GUILayoutOption>()))
		{
			Undo();
		}
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 24f));
	}

	private float Slider(string label, float value, float min, float max, string fmt)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(label, Styles.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		value = GUILayout.HorizontalSlider(value, min, max, Styles.Slider, Styles.Thumb, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		Mark("slider:" + label, GUILayoutUtility.GetLastRect());
		GUILayout.Label(value.ToString(fmt), Styles.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(62f) });
		GUILayout.EndHorizontal();
		return value;
	}

	private void DrawPreview(Rect box)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: 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_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		GUI.Box(box, GUIContent.none, Styles.Well);
		int num;
		string text = RuneGlyphs.Normalize(RawText, out num);
		if (text.Trim().Length == 0)
		{
			return;
		}
		Vector2 size;
		List<InscriptionBuilder.Quad> list = InscriptionBuilder.Layout(text, Style, out size);
		if (list.Count == 0)
		{
			return;
		}
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref box)).x + 6f, ((Rect)(ref box)).y + 6f, ((Rect)(ref box)).width - 12f, ((Rect)(ref box)).height - 12f);
		float num2 = list.Min((InscriptionBuilder.Quad q) => q.Min.x);
		float num3 = list.Max((InscriptionBuilder.Quad q) => q.Max.x);
		float num4 = list.Min((InscriptionBuilder.Quad q) => q.Min.y);
		float num5 = list.Max((InscriptionBuilder.Quad q) => q.Max.y);
		float num6 = Mathf.Min(((Rect)(ref val)).width / (num3 - num2), ((Rect)(ref val)).height / (num5 - num4));
		float num7 = ((Rect)(ref val)).center.x - (num2 + num3) / 2f * num6;
		float num8 = ((Rect)(ref val)).center.y + (num4 + num5) / 2f * num6;
		GUI.color = Color.Lerp(Style.Color, Color.white, 0.35f);
		foreach (InscriptionBuilder.Quad item in list)
		{
			Rect val2 = new Rect(num7 + item.Min.x * num6, num8 - item.Max.y * num6, (item.Max.x - item.Min.x) * num6, (item.Max.y - item.Min.y) * num6);
			Glyph glyph = item.Glyph;
			GUI.DrawTextureWithTexCoords(val2, (Texture)(object)RuneGlyphs.Atlas, new Rect(glyph.UvMin.x, glyph.UvMin.y, glyph.UvMax.x - glyph.UvMin.x, glyph.UvMax.y - glyph.UvMin.y));
		}
		GUI.color = Color.white;
	}

	private void DrawKeyboard()
	{
		//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)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: 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_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		List<Glyph> list = RuneGlyphs.All.ToList();
		Color color = Color.Lerp(Style.Color, Color.white, 0.35f);
		color.a = 1f;
		for (int i = 0; i < list.Count; i += 10)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (Glyph item in list.Skip(i).Take(10))
			{
				Rect rect = GUILayoutUtility.GetRect(40f, 58f, Styles.Key, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(40f),
					GUILayout.Height(58f)
				});
				char c = item.Char;
				Mark("key:" + c, rect);
				if (GUI.Button(rect, GUIContent.none, Styles.Key))
				{
					c = item.Char;
					Type(c.ToString());
				}