Decompiled source of Ruler v1.6.0

Ruler.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Ruler;
using Service;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Visualization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Ruler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5200cf1b2a2146c80e1186082ce886e867ff00c2")]
[assembly: AssemblyProduct("Ruler")]
[assembly: AssemblyTitle("Ruler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Visualization
{
	public class Draw : Component
	{
		public const string TriggerLayer = "character_trigger";

		private static Shader? lineShader;

		private static Dictionary<string, Color> colors = new Dictionary<string, Color>();

		private static Dictionary<string, int> lineWidths = new Dictionary<string, int>();

		private static Shader LineShader => lineShader ?? (lineShader = ((IEnumerable<Shader>)Resources.FindObjectsOfTypeAll<Shader>()).FirstOrDefault((Func<Shader, bool>)((Shader shader) => ((Object)shader).name == "Particles/Standard Unlit2")) ?? throw new Exception("Shader not found."));

		private static int GetSegments(float angle)
		{
			return (int)Math.Floor(32f * angle / 360f);
		}

		private static Vector3 GetArcSegmentX(float angle, float radius)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(0f, Mathf.Sin((float)Math.PI / 180f * angle) * radius, Mathf.Cos((float)Math.PI / 180f * angle) * radius);
		}

		private static Vector3 GetArcSegmentY(float angle, float radius)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(Mathf.Sin((float)Math.PI / 180f * angle) * radius, 0f, Mathf.Cos((float)Math.PI / 180f * angle) * radius);
		}

		private static Vector3 GetArcSegmentZ(float angle, float radius)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(Mathf.Sin((float)Math.PI / 180f * angle) * radius, Mathf.Cos((float)Math.PI / 180f * angle) * radius, 0f);
		}

		private static Vector3[] GetArcSegmentsX(Vector3 position, float angle, float radius)
		{
			//IL_001f: 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_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)
			float num = (0f - angle) / 2f;
			int segments = GetSegments(angle);
			Vector3[] array = (Vector3[])(object)new Vector3[segments + 1];
			for (int i = 0; i <= segments; i++)
			{
				array[i] = position + GetArcSegmentX(num, radius);
				num += angle / (float)segments;
			}
			return array;
		}

		private static Vector3[] GetArcSegmentsY(Vector3 position, float angle, float radius)
		{
			//IL_001f: 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_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)
			float num = (0f - angle) / 2f;
			int segments = GetSegments(angle);
			Vector3[] array = (Vector3[])(object)new Vector3[segments + 1];
			for (int i = 0; i <= segments; i++)
			{
				array[i] = position + GetArcSegmentY(num, radius);
				num += angle / (float)segments;
			}
			return array;
		}

		private static Vector3[] GetArcSegmentsZ(Vector3 position, float angle, float radius)
		{
			//IL_001f: 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_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)
			float num = (0f - angle) / 2f;
			int segments = GetSegments(angle);
			Vector3[] array = (Vector3[])(object)new Vector3[segments + 1];
			for (int i = 0; i <= segments; i++)
			{
				array[i] = position + GetArcSegmentZ(num, radius);
				num += angle / (float)segments;
			}
			return array;
		}

		private static void UpdateArcX(LineRenderer renderer, Vector3 position, float radius, float angle, float width)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] arcSegmentsX = GetArcSegmentsX(position, angle, radius - width / 2f);
			renderer.positionCount = arcSegmentsX.Length;
			renderer.SetPositions(arcSegmentsX);
		}

		public static void DrawArcX(GameObject obj, Vector3 position, float radius, float angle)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			UpdateArcX(CreateRenderer(obj), position, radius, angle, GetLineWidth(((Object)obj).name));
		}

		private static void UpdateArcY(LineRenderer renderer, Vector3 position, float radius, float angle, float width)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] arcSegmentsY = GetArcSegmentsY(position, angle, radius - width / 2f);
			renderer.positionCount = arcSegmentsY.Length;
			renderer.SetPositions(arcSegmentsY);
		}

		public static void DrawArcY(GameObject obj, Vector3 position, float radius, float angle)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			UpdateArcY(CreateRenderer(obj), position, radius, angle, GetLineWidth(((Object)obj).name));
		}

		private static void UpdateArcZ(LineRenderer renderer, Vector3 position, float radius, float angle, float width)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] arcSegmentsZ = GetArcSegmentsZ(position, angle, radius - width / 2f);
			renderer.positionCount = arcSegmentsZ.Length;
			renderer.SetPositions(arcSegmentsZ);
		}

		public static void DrawArcZ(GameObject obj, Vector3 position, float radius, float angle)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			UpdateArcZ(CreateRenderer(obj), position, radius, angle, GetLineWidth(((Object)obj).name));
		}

		public static GameObject DrawCircleY(string tag, GameObject parent, float radius)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = CreateObject(parent, tag);
			DrawArcY(CreateObject(obj, tag), Vector3.zero, radius, 360f);
			AddMeshCollider(obj);
			return obj;
		}

		public static GameObject DrawArc(string tag, MonoBehaviour parent, Vector3 position, float radius, float angle)
		{
			//IL_0015: 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)
			GameObject obj = CreateObject(((Component)parent).gameObject, tag);
			DrawArcY(CreateObject(obj, tag), position, radius, angle);
			DrawArcX(CreateObject(obj, tag), position, radius, angle);
			AddMeshCollider(obj);
			return obj;
		}

		private static GameObject CreateObject(GameObject parent, string tag, bool fixRotation = false)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject();
			val.layer = LayerMask.NameToLayer("character_trigger");
			val.transform.parent = parent.transform;
			val.transform.localPosition = Vector3.zero;
			if (!fixRotation)
			{
				val.transform.localRotation = Quaternion.identity;
			}
			if (tag != "")
			{
				((Object)val).name = tag;
				val.AddComponent<Visualization>().Tag = tag;
			}
			return val;
		}

		private static GameObject CreateLineRotater(GameObject parent, Vector3 start, Vector3 end)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_005b: Expected O, but got Unknown
			GameObject val = new GameObject
			{
				name = ((Object)parent).name,
				layer = LayerMask.NameToLayer("character_trigger")
			};
			val.transform.parent = parent.transform;
			val.transform.localPosition = start;
			val.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, end - start);
			return val;
		}

		private static LineRenderer CreateRenderer(GameObject obj)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			LineRenderer obj2 = obj.AddComponent<LineRenderer>();
			obj2.useWorldSpace = false;
			Material val = new Material(LineShader);
			val.SetColor("_Color", GetColor(((Object)obj).name));
			val.SetFloat("_BlendOp", 1f);
			Texture2D val2 = new Texture2D(1, 1);
			val2.SetPixel(0, 0, Color.gray);
			val.SetTexture("_MainTex", (Texture)(object)val2);
			((Renderer)obj2).material = val;
			((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
			obj2.widthMultiplier = GetLineWidth(((Object)obj).name);
			return obj2;
		}

		private static void ChangeColor(GameObject obj)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Color color = GetColor(((Object)obj).name);
			LineRenderer component = obj.GetComponent<LineRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((Renderer)component).material.SetColor("_Color", color);
			}
		}

		private static void ChangeLineWidth(GameObject obj)
		{
			float lineWidth = GetLineWidth(((Object)obj).name);
			LineRenderer component = obj.GetComponent<LineRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.widthMultiplier = lineWidth;
			}
		}

		public static void AddMeshCollider(GameObject obj)
		{
			GameObject obj2 = obj;
			Array.ForEach(obj2.GetComponentsInChildren<LineRenderer>(), delegate(LineRenderer renderer)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Expected O, but got Unknown
				MeshCollider obj3 = obj2.AddComponent<MeshCollider>();
				obj3.convex = true;
				((Collider)obj3).isTrigger = true;
				Mesh val = new Mesh();
				renderer.BakeMesh(val, false);
				obj3.sharedMesh = val;
			});
		}

		public static void AddText(GameObject obj, string title, string text)
		{
			StaticText staticText = obj.AddComponent<StaticText>();
			staticText.text = text;
			staticText.title = title;
		}

		public static LineRenderer[] GetRenderers(MonoBehaviour obj, string tag)
		{
			string tag2 = tag;
			return ((Component)obj).GetComponentsInChildren<LineRenderer>(true).Where(delegate(LineRenderer renderer)
			{
				Visualization component = ((Component)renderer).GetComponent<Visualization>();
				return (Object)(object)component != (Object)null && component.Tag == tag2;
			}).ToArray();
		}

		public static Color GetColor(string tag)
		{
			//IL_0019: 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)
			if (!colors.ContainsKey(tag))
			{
				return Color.white;
			}
			return colors[tag];
		}

		public static void SetColor(string tag, Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			colors[tag] = color;
			Visualization[] visualizations = Utils.GetVisualizations();
			foreach (Visualization visualization in visualizations)
			{
				if (visualization.Tag == tag)
				{
					ChangeColor(((Component)visualization).gameObject);
				}
			}
		}

		public static float GetLineWidth(string tag)
		{
			return (float)Math.Max(1, lineWidths.ContainsKey(tag) ? lineWidths[tag] : 0) / 100f;
		}

		public static void SetLineWidth(string tag, int width)
		{
			lineWidths[tag] = width;
			Visualization[] visualizations = Utils.GetVisualizations();
			foreach (Visualization visualization in visualizations)
			{
				if (visualization.Tag == tag)
				{
					ChangeLineWidth(((Component)visualization).gameObject);
				}
			}
		}

		private static void AddBoxCollider(GameObject obj)
		{
			GameObject obj2 = obj;
			Array.ForEach(obj2.GetComponentsInChildren<LineRenderer>(), delegate(LineRenderer renderer)
			{
				//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_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_0031: 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_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: 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_004d: 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_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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: 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)
				Vector3 position = renderer.GetPosition(0);
				Vector3 position2 = renderer.GetPosition(renderer.positionCount - 1);
				float widthMultiplier = renderer.widthMultiplier;
				BoxCollider obj3 = obj2.AddComponent<BoxCollider>();
				((Collider)obj3).isTrigger = true;
				obj3.center = position + (position2 - position) / 2f;
				Vector3 val = position2 - position;
				val.x = Math.Abs(val.x);
				val.y = Math.Abs(val.y);
				val.z = Math.Abs(val.z);
				obj3.size = val + 2f * new Vector3(widthMultiplier, widthMultiplier, widthMultiplier);
			});
		}

		private static void AddBoxCollider(GameObject obj, Vector3 center, Vector3 size)
		{
			//IL_000e: 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)
			BoxCollider obj2 = obj.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.center = center;
			obj2.size = size;
		}

		private static GameObject DrawLineSub(GameObject obj, Vector3 start, Vector3 end)
		{
			//IL_0008: 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)
			LineRenderer obj2 = CreateRenderer(obj);
			obj2.SetPosition(0, start);
			obj2.SetPosition(1, end);
			return obj;
		}

		public static GameObject DrawLineWithFixedRotation(string tag, GameObject parent, Vector3 start, Vector3 end)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001b: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			GameObject obj = CreateLineRotater(CreateObject(parent.gameObject, tag, fixRotation: true), start, end);
			Vector3 forward = Vector3.forward;
			Vector3 val = end - start;
			GameObject obj2 = DrawLineSub(end: forward * ((Vector3)(ref val)).magnitude, obj: obj, start: Vector3.zero);
			AddBoxCollider(obj2);
			return obj2;
		}

		public static void AddSphereCollider(GameObject obj, float radius)
		{
			GameObject obj2 = obj;
			Array.ForEach(obj2.GetComponentsInChildren<LineRenderer>(), delegate
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				SphereCollider obj3 = obj2.AddComponent<SphereCollider>();
				((Collider)obj3).isTrigger = true;
				obj3.center = Vector3.zero;
				obj3.radius = radius;
			});
		}

		public static void UpdateSphereCollider(MonoBehaviour obj, float radius)
		{
			Array.ForEach(((Component)obj).GetComponentsInChildren<SphereCollider>(), delegate(SphereCollider collider)
			{
				collider.radius = radius;
			});
		}

		public static void UpdateSphere(MonoBehaviour parent, float radius)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			LineRenderer[] componentsInChildren = ((Component)parent).GetComponentsInChildren<LineRenderer>();
			if (componentsInChildren.Length == 3)
			{
				float widthMultiplier = componentsInChildren[0].widthMultiplier;
				UpdateArcX(componentsInChildren[0], Vector3.zero, radius, 360f, widthMultiplier);
				UpdateArcY(componentsInChildren[1], Vector3.zero, radius, 360f, widthMultiplier);
				UpdateArcZ(componentsInChildren[2], Vector3.zero, radius, 360f, widthMultiplier);
				UpdateSphereCollider(parent, radius - widthMultiplier / 2f);
			}
		}

		public static GameObject DrawSphere(string tag, MonoBehaviour parent, float radius)
		{
			return DrawSphere(tag, ((Component)parent).gameObject, radius);
		}

		public static GameObject DrawSphere(string tag, GameObject parent, float radius)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			GameObject obj = CreateObject(parent, tag);
			DrawArcX(CreateObject(obj, tag), Vector3.zero, radius, 360f);
			float lineWidth = GetLineWidth(tag);
			AddSphereCollider(obj, radius - lineWidth / 2f);
			DrawArcY(CreateObject(obj, tag), Vector3.zero, radius, 360f);
			DrawArcZ(CreateObject(obj, tag), Vector3.zero, radius, 360f);
			return obj;
		}
	}
	public class Utils
	{
		public static Visualization[] GetVisualizations()
		{
			return Resources.FindObjectsOfTypeAll<Visualization>();
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateHover")]
	public class Player_AddHoverForVisuals
	{
		private static void Postfix(ref GameObject ___m_hovering, ref GameObject ___m_hoveringCreature)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (Object.op_Implicit((Object)(object)___m_hovering) || Object.op_Implicit((Object)(object)___m_hoveringCreature) || !global::Ruler.Ruler.Enabled)
			{
				return;
			}
			float num = 100f;
			int mask = LayerMask.GetMask(new string[1] { "character_trigger" });
			RaycastHit[] array = Physics.RaycastAll(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, num, mask);
			RaycastHit[] array2 = Physics.RaycastAll(((Component)GameCamera.instance).transform.position + ((Component)GameCamera.instance).transform.forward * num, -((Component)GameCamera.instance).transform.forward, num, mask);
			RaycastHit[] array3 = CollectionExtensions.AddRangeToArray<RaycastHit>(array, array2);
			Array.Sort(array3, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
			RaycastHit[] array4 = array3;
			for (int i = 0; i < array4.Length; i++)
			{
				RaycastHit val = array4[i];
				if ((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponent<Visualization>() != (Object)null)
				{
					___m_hovering = ((Component)((RaycastHit)(ref val)).collider).gameObject;
					break;
				}
			}
		}
	}
	public class StaticText : MonoBehaviour, Hoverable
	{
		public string title = "";

		public string text = "";

		public string GetHoverText()
		{
			return Format.String(title) + "\n" + text;
		}

		public string GetHoverName()
		{
			return title;
		}
	}
	public class Visualization : MonoBehaviour
	{
		public string Tag = "";
	}
}
namespace Service
{
	public class Format
	{
		public const string FORMAT = "0.##";

		public static string GetValidColor(bool valid)
		{
			if (!valid)
			{
				return "grey";
			}
			return "yellow";
		}

		public static string String(string value, string color = "yellow")
		{
			return "<color=" + color + ">" + value + "</color>";
		}

		public static string String(string value, bool valid)
		{
			return "<color=" + GetValidColor(valid) + ">" + value + "</color>";
		}

		public static string Float(double value, string format = "0.##", string color = "yellow")
		{
			return String(value.ToString(format, CultureInfo.InvariantCulture), color);
		}

		public static string Meters(double value, string color = "yellow")
		{
			return String(value.ToString("0.##", CultureInfo.InvariantCulture) + " meters", color);
		}

		public static string Coordinates(Vector3 coordinates, string format = "F0", string color = "yellow")
		{
			string color2 = color;
			return JoinRow(from value in ((Vector3)(ref coordinates)).ToString(format).Replace("(", "").Replace(")", "")
					.Split(new char[1] { ',' })
				select String(value.Trim(), color2));
		}

		public static string JoinLines(IEnumerable<string> lines)
		{
			return string.Join("\n", lines.Where((string line) => line != ""));
		}

		public static string JoinRow(IEnumerable<string> lines)
		{
			return string.Join(", ", lines.Where((string line) => line != ""));
		}
	}
	[HarmonyPatch(typeof(MessageHud), "Update")]
	public class MessageHud_UpdateMessage : MonoBehaviour
	{
		public static Func<List<string>> GetMessage = () => new List<string> { "Default message. Overwrite this with own function." };

		private static void Postfix(MessageHud __instance)
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || Hud.IsUserHidden())
			{
				return;
			}
			string text = __instance.m_messageText.text;
			List<string> list = GetMessage();
			if (list.Count != 0)
			{
				while (text.StartsWith(" \n"))
				{
					text = text.Substring(2);
				}
				int num = ((text != "") ? text.Split(new char[1] { '\n' }).Length : 0) + list.Count - 2;
				for (int i = 0; i < num; i++)
				{
					list.Insert(0, " ");
				}
				if (text != "")
				{
					list.Insert(0, " ");
					list.Insert(0, " ");
					list.Add(" ");
					list.Add(text);
				}
				__instance.m_messageText.text = Format.JoinLines(list);
				((Graphic)__instance.m_messageText).CrossFadeAlpha(1f, 0f, true);
				((Graphic)__instance.m_messageIcon).canvasRenderer.SetAlpha(0f);
				((Graphic)__instance.m_messageIcon).CrossFadeAlpha(0f, 0f, true);
			}
		}
	}
	[HarmonyPatch(typeof(MessageHud), "UpdateMessage")]
	public class MessageHud_GetBaseMessage : MonoBehaviour
	{
		private static string BaseMessage = "";

		private static void Prefix(out string __state)
		{
			__state = MessageHud.instance.m_messageText.text;
		}

		private static void Postfix(MessageHud __instance, float ___m_msgQueueTimer, string __state)
		{
			if (__instance.m_messageText.text != __state)
			{
				BaseMessage = __instance.m_messageText.text;
			}
			if (___m_msgQueueTimer >= 4f)
			{
				BaseMessage = "";
			}
			__instance.m_messageText.text = BaseMessage;
		}
	}
}
namespace Ruler
{
	[BepInPlugin("ruler", "Ruler", "1.6")]
	public class Ruler : BaseUnityPlugin
	{
		private const string GUID = "ruler";

		private const string NAME = "Ruler";

		private const string VERSION = "1.6";

		public static string Tag = "ruler.Ruler";

		private static GameObject? ruler = null;

		private static Vector3 Position;

		private static float Radius;

		public static bool Enabled => Object.op_Implicit((Object)(object)ruler);

		public void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Settings.Init(((BaseUnityPlugin)this).Config);
			new Harmony("ruler").PatchAll();
			MessageHud_UpdateMessage.GetMessage = GetMessage;
		}

		public static void Remove()
		{
			if (Object.op_Implicit((Object)(object)ruler))
			{
				Object.Destroy((Object)(object)ruler);
			}
			ruler = null;
		}

		public static void Refresh()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Draw(Position, Radius);
		}

		public static void Draw(Vector3 position, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0023: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Radius = radius;
			if (Object.op_Implicit((Object)(object)ruler))
			{
				Remove();
			}
			GameObject val = new GameObject();
			val.layer = LayerMask.NameToLayer("character_trigger");
			val.transform.position = position;
			ruler = val;
			if (Settings.configDraw3d.Value)
			{
				Visualization.Draw.AddText(Visualization.Draw.DrawSphere(Tag, val, radius), Format.Coordinates(position), "Ruler");
			}
			else
			{
				Visualization.Draw.AddText(Visualization.Draw.DrawCircleY(Tag, val, radius), Format.Coordinates(position), "Ruler");
			}
			if (Settings.configDrawAxis.Value)
			{
				Visualization.Draw.AddText(Visualization.Draw.DrawLineWithFixedRotation(Tag, val, -Vector3.forward * radius, Vector3.forward * radius), Format.Coordinates(position), "Ruler");
				Visualization.Draw.AddText(Visualization.Draw.DrawLineWithFixedRotation(Tag, val, -Vector3.right * radius, Vector3.right * radius), Format.Coordinates(position), "Ruler");
				if (Settings.configDraw3d.Value)
				{
					Visualization.Draw.AddText(Visualization.Draw.DrawLineWithFixedRotation(Tag, val, -Vector3.up * radius, Vector3.up * radius), Format.Coordinates(position), "Ruler");
				}
			}
		}

		public static void Toggle(Vector3 position, float radius)
		{
			//IL_002f: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ruler != (Object)null && Vector3.Distance(ruler.transform.position, position) < 0.1f)
			{
				Remove();
			}
			else
			{
				Draw(position, radius);
			}
		}

		private static string GetText(Vector3 position)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0029: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ruler == (Object)null)
			{
				return "";
			}
			Vector3 coordinates = position - ruler.transform.position;
			float num = Utils.DistanceXZ(position, ruler.transform.position);
			return "Ruler distance (" + Format.Coordinates(coordinates) + "): " + Format.Float(((Vector3)(ref coordinates)).magnitude) + " m, XZ: " + Format.Float(num) + " m";
		}

		public static List<string> GetMessage()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			if ((Object)(object)ruler == (Object)null || !Settings.configShowText.Value)
			{
				return list;
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			list.Add(GetText(position));
			return list;
		}
	}
	public class Settings
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static EventHandler <>9__5_0;

			public static EventHandler <>9__5_1;

			public static ConsoleEvent <>9__9_0;

			internal void <Init>b__5_0(object s, EventArgs e)
			{
				Ruler.Refresh();
			}

			internal void <Init>b__5_1(object s, EventArgs e)
			{
				Ruler.Refresh();
			}

			internal void <InitCommands>b__9_0(ConsoleEventArgs args)
			{
				//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_00c4: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return;
				}
				float result = 0.1f;
				if (args.Length > 1)
				{
					float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result);
				}
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				if (args.Length > 2)
				{
					string[] array = args[2].Split(new char[1] { ',' });
					if (array.Length != 0)
					{
						float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out position.x);
					}
					if (array.Length > 1)
					{
						float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out position.z);
					}
					if (array.Length > 2)
					{
						float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out position.y);
					}
				}
				Ruler.Toggle(position, result);
			}
		}

		public static ConfigEntry<string> configColor;

		public static ConfigEntry<int> configLineWidth;

		public static ConfigEntry<bool> configDrawAxis;

		public static ConfigEntry<bool> configDraw3d;

		public static ConfigEntry<bool> configShowText;

		public static void Init(ConfigFile config)
		{
			string text = "Ruler";
			configLineWidth = config.Bind<int>(text, "Line width", 10, "");
			OnWidthChanged(configLineWidth, Ruler.Tag);
			configColor = config.Bind<string>(text, "Color", "red", "");
			OnColorChanged(configColor, Ruler.Tag);
			configDrawAxis = config.Bind<bool>(text, "Draw axis", true, "Draws axis inside the ruler.");
			configDrawAxis.SettingChanged += delegate
			{
				Ruler.Refresh();
			};
			configDraw3d = config.Bind<bool>(text, "Draw 3d", true, "Draws sphere instead of a circle.");
			configDraw3d.SettingChanged += delegate
			{
				Ruler.Refresh();
			};
			configShowText = config.Bind<bool>(text, "Show text", true, "Shows distance on the HUD.");
			InitCommands();
		}

		private static Color ParseColor(string color)
		{
			//IL_000c: 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)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString(color, ref result))
			{
				return result;
			}
			return Color.white;
		}

		private static void OnWidthChanged(ConfigEntry<int> entry, string tag)
		{
			string tag2 = tag;
			ConfigEntry<int> entry2 = entry;
			entry2.SettingChanged += delegate
			{
				Draw.SetLineWidth(tag2, entry2.Value);
			};
			Draw.SetLineWidth(tag2, entry2.Value);
		}

		private static void OnColorChanged(ConfigEntry<string> entry, string tag)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			string tag2 = tag;
			ConfigEntry<string> entry2 = entry;
			entry2.SettingChanged += delegate
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Draw.SetColor(tag2, ParseColor(entry2.Value));
			};
			Draw.SetColor(tag2, ParseColor(entry2.Value));
		}

		private static void InitCommands()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			object obj = <>c.<>9__9_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					//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_00c4: Unknown result type (might be due to invalid IL or missing references)
					if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
					{
						float result = 0.1f;
						if (args.Length > 1)
						{
							float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result);
						}
						Vector3 position = ((Component)Player.m_localPlayer).transform.position;
						if (args.Length > 2)
						{
							string[] array = args[2].Split(new char[1] { ',' });
							if (array.Length != 0)
							{
								float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out position.x);
							}
							if (array.Length > 1)
							{
								float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out position.z);
							}
							if (array.Length > 2)
							{
								float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out position.y);
							}
						}
						Ruler.Toggle(position, result);
					}
				};
				<>c.<>9__9_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("ruler", "[radius] [x,z,y=player pos] - Toggles or sets the ruler.", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
}