Decompiled source of Graphlib v1.0.0

Graphlib.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Graphlib.Config;
using Graphlib.Grapher;
using Graphlib.UI;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Graphlib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Graphlib")]
[assembly: AssemblyTitle("Graphlib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace Graphlib
{
	public class StatGraph : MonoBehaviour
	{
		public struct DataSource
		{
			public string Label;

			public Func<float> ValueProvider;

			public Color? Color;
		}

		private static readonly List<Color> PlotLineColors = new List<Color>
		{
			new Color(0.12f, 0.47f, 0.71f),
			new Color(1f, 0.5f, 0.05f),
			new Color(0.17f, 0.63f, 0.17f),
			new Color(0.84f, 0.15f, 0.16f),
			new Color(0.58f, 0.4f, 0.74f),
			new Color(0.55f, 0.34f, 0.29f)
		};

		private RectTransform? _rt;

		private bool _dirty;

		private DataSource[] _dataSources = Array.Empty<DataSource>();

		private readonly List<TextMeshProUGUI?> _labelTexts = new List<TextMeshProUGUI>();

		private readonly List<TextMeshProUGUI?> _valueTexts = new List<TextMeshProUGUI>();

		private TextMeshProUGUI? _graphMaxText;

		private TextMeshProUGUI? _graphMinText;

		private TextMeshProUGUI? _graphTimeText;

		private Plotter? _plot;

		private Color32 _textColor = new Color32((byte)227, (byte)227, (byte)227, (byte)227);

		private const float BlockHeight = 12f;

		private const float ElementSpacing = 4f;

		private float _sampleRate = 2f;

		private float _sampleInterval = 0.5f;

		private float _timeSinceLastSample;

		public RectTransform RT
		{
			get
			{
				if ((Object)(object)_rt == (Object)null)
				{
					_rt = ((Component)this).GetComponent<RectTransform>();
				}
				return _rt;
			}
		}

		public Plotter Plot => _plot ?? throw new NullReferenceException("StatGraph[" + ((Object)this).name + "] No plotter assigned.");

		public Vector2 Size => RT.sizeDelta;

		public Vector2 PlotSize
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return Plot.PlotSize;
			}
			set
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				Plot.PlotSize = value;
			}
		}

		public Color32 TextColor
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _textColor;
			}
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				_textColor = value;
				_dirty = true;
			}
		}

		public string Unit { get; set; }

		public uint Precision { get; set; } = 1u;


		public bool AbbreviateWithSIUnit { get; set; }

		public float SampleRate
		{
			get
			{
				return _sampleRate;
			}
			set
			{
				_sampleRate = value;
				_sampleInterval = 1f / _sampleRate;
			}
		}

		private float DesiredClearance => (float)_dataSources.Length * 16f;

		public StatGraph(IntPtr ptr)
			: base(ptr)
		{
			//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)
			Unit = "";
		}

		public static StatGraph Create(Transform parent, Vector2 graphSize, StatGraphConfig config)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Create(parent, config.Sources, config.Unit, graphSize, config.PlotMin, config.PlotMax, config.PlotAutoScale, config.PlotAutoScaleIncrement, config.ObjectName, config.AbbreviateWithSIPrefix, config.SampleRate, config.Precision);
		}

		public static StatGraph Create(Transform parent, DataSource[] sources, string unit, Vector2 plotSize, float min = 0f, float max = 1f, bool autoScale = true, float autoScaleInc = -1f, string objName = "", bool abbrValWithSI = false, float sampleRate = 2f, uint precision = 0u)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject((objName == "") ? ("StatGraph." + sources.Select((DataSource s) => s.Label).Aggregate((string str0, string str1) => str0 + "_" + str1)) : objName);
			RectTransform val2 = val.AddComponent<RectTransform>();
			((Transform)val2).SetParent(parent, false);
			StatGraph statGraph = val.AddComponent<StatGraph>();
			statGraph._rt = val2;
			statGraph._dataSources = sources;
			statGraph.Unit = unit;
			statGraph.AbbreviateWithSIUnit = abbrValWithSI;
			statGraph.SampleRate = sampleRate;
			statGraph.Precision = precision;
			Plotter plotter = ((Component)statGraph).gameObject.AddComponent<Plotter>();
			plotter.PlotSize = plotSize;
			plotter.AutoScale = autoScale;
			plotter.MinY = min;
			plotter.MaxY = max;
			plotter.AutoScaleIncrement = autoScaleInc;
			plotter.AfterPopulateMesh += statGraph.DrawLegendIdentifiers;
			plotter.AfterPopulateMesh += statGraph.DrawMaxTick;
			statGraph._plot = plotter;
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(1f, 0f);
			val2.anchoredPosition3D = Vector3.zero;
			statGraph.Recreate();
			if (TMPUtil.CreateTMPUGUI("GraphMax", (Transform?)(object)statGraph.RT, out TextMeshProUGUI tp))
			{
				statGraph._graphMaxText = tp;
			}
			if (TMPUtil.CreateTMPUGUI("GraphMin", (Transform?)(object)statGraph.RT, out TextMeshProUGUI tp2))
			{
				statGraph._graphMinText = tp2;
			}
			if (TMPUtil.CreateTMPUGUI("Time", (Transform?)(object)statGraph.RT, out TextMeshProUGUI tp3))
			{
				statGraph._graphTimeText = tp3;
			}
			statGraph.Reconfigure();
			return statGraph;
		}

		public void UpdateSources(DataSource[] sources)
		{
			if (sources.Length != _dataSources.Length)
			{
				_dataSources = sources;
				Recreate();
				Reconfigure();
			}
			else
			{
				_dataSources = sources;
				Reconfigure();
			}
		}

		private void Update()
		{
			if ((Object)(object)_plot == (Object)null)
			{
				Logger.Error("StatGraph[" + ((Object)this).name + "] No plotter assigned. Disabling graph.");
				((Component)this).gameObject.SetActive(false);
				return;
			}
			_timeSinceLastSample += Time.deltaTime;
			if (_timeSinceLastSample >= _sampleInterval)
			{
				for (int i = 0; i < _dataSources.Length; i++)
				{
					float value = _dataSources[i].ValueProvider();
					_plot.PushSample(value, i);
					if ((Object)(object)_valueTexts[i] != (Object)null)
					{
						string text = (AbbreviateWithSIUnit ? Util.Value2SIAbbrStr(value) : value.ToString($"F{Precision}"));
						((TMP_Text)_valueTexts[i]).text = text + Unit;
					}
				}
				_timeSinceLastSample = 0f;
			}
			TextMeshProUGUI? graphMinText = _graphMinText;
			if (graphMinText != null)
			{
				((TMP_Text)graphMinText).SetText(AbbreviateWithSIUnit ? Util.Value2SIAbbrStr(_plot.MinY) : _plot.MinY.ToString($"F{Precision}"), true);
			}
			TextMeshProUGUI? graphMaxText = _graphMaxText;
			if (graphMaxText != null)
			{
				((TMP_Text)graphMaxText).SetText(AbbreviateWithSIUnit ? Util.Value2SIAbbrStr(_plot.DisplayMaxY) : _plot.DisplayMaxY.ToString($"F{Precision}"), true);
			}
			TextMeshProUGUI? graphTimeText = _graphTimeText;
			if (graphTimeText != null)
			{
				((TMP_Text)graphTimeText).SetText($"{(float)_plot.Capacity * _sampleInterval:F0}s", true);
			}
			if (_dirty)
			{
				Reconfigure();
			}
		}

		private void Recreate()
		{
			foreach (TextMeshProUGUI labelText in _labelTexts)
			{
				if ((Object)(object)labelText != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)labelText).gameObject);
				}
			}
			foreach (TextMeshProUGUI valueText in _valueTexts)
			{
				if ((Object)(object)valueText != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)valueText).gameObject);
				}
			}
			_labelTexts.Clear();
			_valueTexts.Clear();
			for (int i = 0; i < _dataSources.Length; i++)
			{
				if (TMPUtil.CreateTMPUGUI($"Label.C{i}", (Transform?)(object)RT, out TextMeshProUGUI tp))
				{
					((TMP_Text)tp).text = _dataSources[i].Label;
					_labelTexts.Add(tp);
				}
				if (TMPUtil.CreateTMPUGUI($"Value.C{i}", (Transform?)(object)RT, out TextMeshProUGUI tp2))
				{
					_valueTexts.Add(tp2);
				}
			}
		}

		private void Reconfigure()
		{
			//IL_008b: 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_0090: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: 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_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0605: Unknown result type (might be due to invalid IL or missing references)
			//IL_0616: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_0682: Unknown result type (might be due to invalid IL or missing references)
			//IL_0691: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_plot == (Object)null)
			{
				Logger.Error("StatGraph[" + ((Object)this).name + "] No plotter assigned.");
				return;
			}
			_plot.SetClearance(DesiredClearance);
			_plot.AllocateChannels(_dataSources.Length);
			for (int i = 0; i < _dataSources.Length; i++)
			{
				Color c = (Color)(((??)_dataSources[i].Color) ?? PlotLineColors[i % PlotLineColors.Count]);
				_plot.SetColor(Plotter.PlotComponent.Line, c, i);
			}
			string fmt = "StatGraph[" + ((Object)this).name + "]->{0} UI reconfigure failed, is null.";
			Vector2 val2 = default(Vector2);
			Vector2 v = default(Vector2);
			Vector2 val4 = default(Vector2);
			Vector2 v2 = default(Vector2);
			for (int j = 0; j < _dataSources.Length; j++)
			{
				TextMeshProUGUI val = _labelTexts[j];
				if ((Object)(object)val != (Object)null)
				{
					((TMP_Text)val).SetText(_dataSources[j].Label, true);
					((Vector2)(ref val2))..ctor(0f, 1f);
					((TMP_Text)val).alignment = (TextAlignmentOptions)513;
					((Graphic)val).color = Color.white;
					((TMP_Text)val).faceColor = TextColor;
					((TMP_Text)val).autoSizeTextContainer = false;
					((TMP_Text)val).enableAutoSizing = true;
					((TMP_Text)val).fontSizeMax = 20f;
					((TMP_Text)val).fontSizeMin = 16f;
					RectTransform rectTransform = ((TMP_Text)val).rectTransform;
					rectTransform.anchorMax = val2;
					rectTransform.anchorMin = val2;
					rectTransform.pivot = new Vector2(0f, 0.5f);
					rectTransform.sizeDelta = new Vector2(_plot.Size.x - 12f - 4f, 12f);
					((Vector2)(ref v))..ctor(16f, 0f - ((float)j * 16f + 4f + 6f));
					rectTransform.anchoredPosition3D = v.Extend();
				}
				else
				{
					Logger.Warn(fmt, $"C{j}:Label");
				}
				TextMeshProUGUI val3 = _valueTexts[j];
				if ((Object)(object)val3 != (Object)null)
				{
					((Vector2)(ref val4))..ctor(1f, 1f);
					((TMP_Text)val3).alignment = (TextAlignmentOptions)516;
					((Graphic)val3).color = Color.white;
					((TMP_Text)val3).faceColor = TextColor;
					((TMP_Text)val3).autoSizeTextContainer = false;
					((TMP_Text)val3).enableAutoSizing = true;
					((TMP_Text)val3).fontSizeMax = 20f;
					((TMP_Text)val3).fontSizeMin = 16f;
					RectTransform rectTransform2 = ((TMP_Text)val3).rectTransform;
					rectTransform2.anchorMax = val4;
					rectTransform2.anchorMin = val4;
					rectTransform2.pivot = new Vector2(1f, 0.5f);
					rectTransform2.sizeDelta = new Vector2(_plot.Size.x, 12f);
					((Vector2)(ref v2))..ctor(-4f, 0f - ((float)j * 16f + 4f + 6f));
					rectTransform2.anchoredPosition3D = v2.Extend();
				}
				else
				{
					Logger.Warn(fmt, $"C{j}:Value");
				}
			}
			if ((Object)(object)_graphTimeText != (Object)null)
			{
				Vector2 val5 = default(Vector2);
				((Vector2)(ref val5))..ctor(0f, 0f);
				((TMP_Text)_graphTimeText).alignment = (TextAlignmentOptions)1025;
				((Graphic)_graphTimeText).color = Color.white;
				((TMP_Text)_graphTimeText).faceColor = TextColor;
				((TMP_Text)_graphTimeText).autoSizeTextContainer = false;
				((TMP_Text)_graphTimeText).enableAutoSizing = true;
				((TMP_Text)_graphTimeText).fontSizeMax = 20f;
				((TMP_Text)_graphTimeText).fontSizeMin = 16f;
				RectTransform rectTransform3 = ((TMP_Text)_graphTimeText).rectTransform;
				rectTransform3.anchorMax = val5;
				rectTransform3.anchorMin = val5;
				rectTransform3.pivot = val5;
				rectTransform3.sizeDelta = new Vector2(_plot.Size.x, 12f);
				Vector2 val6 = new Vector2(0.5f, 0.5f) - val5;
				Vector2 v3 = ((Vector2)(ref val6)).normalized * 4f;
				rectTransform3.anchoredPosition3D = v3.Extend();
			}
			else
			{
				Logger.Warn(fmt, "GraphTime");
			}
			if ((Object)(object)_graphMaxText != (Object)null)
			{
				Vector2 val7 = default(Vector2);
				((Vector2)(ref val7))..ctor(0f, 1f);
				Vector2 pivot = default(Vector2);
				((Vector2)(ref pivot))..ctor(1f, 1f);
				((TMP_Text)_graphMaxText).alignment = (TextAlignmentOptions)516;
				((Graphic)_graphMaxText).color = Color.white;
				((TMP_Text)_graphMaxText).faceColor = TextColor;
				((TMP_Text)_graphMaxText).autoSizeTextContainer = false;
				((TMP_Text)_graphMaxText).enableAutoSizing = true;
				((TMP_Text)_graphMaxText).fontSizeMax = 20f;
				((TMP_Text)_graphMaxText).fontSizeMin = 16f;
				RectTransform rectTransform4 = ((TMP_Text)_graphMaxText).rectTransform;
				rectTransform4.anchorMax = val7;
				rectTransform4.anchorMin = val7;
				rectTransform4.pivot = pivot;
				rectTransform4.sizeDelta = new Vector2(_plot.Size.x, 12f);
				Vector2 v4 = default(Vector2);
				((Vector2)(ref v4))..ctor(-4f, 0f - (DesiredClearance - 6f));
				rectTransform4.anchoredPosition3D = v4.Extend();
			}
			else
			{
				Logger.Warn(fmt, "GraphMax");
			}
			if ((Object)(object)_graphMinText != (Object)null)
			{
				Vector2 val8 = default(Vector2);
				((Vector2)(ref val8))..ctor(0f, 0f);
				Vector2 pivot2 = default(Vector2);
				((Vector2)(ref pivot2))..ctor(1f, 0f);
				((TMP_Text)_graphMinText).alignment = (TextAlignmentOptions)1028;
				((Graphic)_graphMinText).color = Color.white;
				((TMP_Text)_graphMinText).faceColor = TextColor;
				((TMP_Text)_graphMinText).autoSizeTextContainer = false;
				((TMP_Text)_graphMinText).enableAutoSizing = true;
				((TMP_Text)_graphMinText).fontSizeMax = 20f;
				((TMP_Text)_graphMinText).fontSizeMin = 16f;
				RectTransform rectTransform5 = ((TMP_Text)_graphMinText).rectTransform;
				rectTransform5.anchorMax = val8;
				rectTransform5.anchorMin = val8;
				rectTransform5.pivot = pivot2;
				rectTransform5.sizeDelta = new Vector2(_plot.Size.x, 12f);
				Vector2 v5 = default(Vector2);
				((Vector2)(ref v5))..ctor(-4f, 0f);
				rectTransform5.anchoredPosition3D = v5.Extend();
			}
			else
			{
				Logger.Warn(fmt, "GraphMin");
			}
			_dirty = false;
		}

		private void DrawLegendIdentifiers(Graphic graphic, VertexHelper vh)
		{
			//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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Rect pixelAdjustedRect = graphic.GetPixelAdjustedRect();
			Vector2 val = default(Vector2);
			Rect r = default(Rect);
			for (int i = 0; i < _dataSources.Length; i++)
			{
				Color c = (Color)(((??)_dataSources[i].Color) ?? PlotLineColors[i % PlotLineColors.Count]);
				float num = Mathf.Floor(6f);
				float num2 = (12f - num) / 2f;
				((Vector2)(ref val))..ctor(((Rect)(ref pixelAdjustedRect)).xMin + 4f + num2, ((Rect)(ref pixelAdjustedRect)).yMax - (float)(i + 1) * 16f + num2);
				((Rect)(ref r))..ctor(val, new Vector2(num, num));
				VhUtil.AddRect(vh, r, c);
			}
		}

		private void DrawMaxTick(Graphic graphic, VertexHelper vh)
		{
			//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_002e: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			Rect pixelAdjustedRect = graphic.GetPixelAdjustedRect();
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref pixelAdjustedRect)).xMin, ((Rect)(ref pixelAdjustedRect)).yMax - DesiredClearance, 4f, 1f);
			VhUtil.AddRect(vh, r, (Color)(((??)_plot?.BorderColor) ?? new Color(1f, 1f, 1f, 0.35f)));
		}
	}
	public struct StatGraphConfig
	{
		public StatGraph.DataSource[] Sources;

		public string Unit;

		public float PlotMin;

		public float PlotMax;

		public bool PlotAutoScale;

		public float PlotAutoScaleIncrement;

		public string ObjectName;

		public uint Precision;

		public float SampleRate;

		public bool AbbreviateWithSIPrefix;

		public StatGraphConfig()
		{
			Sources = new StatGraph.DataSource[0];
			Unit = "";
			PlotMin = 0f;
			PlotMax = 1f;
			PlotAutoScale = true;
			PlotAutoScaleIncrement = -1f;
			ObjectName = "";
			Precision = 0u;
			SampleRate = 2f;
			AbbreviateWithSIPrefix = false;
		}
	}
	internal static class Logger
	{
		private static ManualLogSource _mLogSource;

		public static bool Ready => _mLogSource != null;

		public static void Setup()
		{
			_mLogSource = Logger.CreateLogSource("io.takina.gtfo.Graphlib");
		}

		public static void SetupFromInit(ManualLogSource logSource)
		{
			_mLogSource = logSource;
		}

		private static string Format(object data)
		{
			return data.ToString();
		}

		public static void Debug(object msg)
		{
			if (ConfigMgr.Debug)
			{
				_mLogSource.LogInfo((object)(" [DEBUG] " + Format(msg)));
			}
		}

		public static void Debug(string fmt, params object[] args)
		{
			if (ConfigMgr.Debug)
			{
				_mLogSource.LogInfo((object)("[DEBUG] " + Format(string.Format(fmt, args))));
			}
			else
			{
				_mLogSource.LogDebug((object)Format(string.Format(fmt, args)));
			}
		}

		public static void Info(object msg)
		{
			_mLogSource.LogInfo((object)Format(msg));
		}

		public static void Info(string fmt, params object[] args)
		{
			_mLogSource.LogInfo((object)Format(string.Format(fmt, args)));
		}

		public static void Warn(object msg)
		{
			_mLogSource.LogWarning((object)Format(msg));
		}

		public static void Warn(string fmt, params object[] args)
		{
			_mLogSource.LogWarning((object)Format(string.Format(fmt, args)));
		}

		public static void Error(object msg)
		{
			_mLogSource.LogError((object)Format(msg));
		}

		public static void Error(string fmt, params object[] args)
		{
			_mLogSource.LogError((object)Format(string.Format(fmt, args)));
		}

		public static void Fatal(object msg)
		{
			_mLogSource.LogFatal((object)Format(msg));
		}

		public static void Fatal(string fmt, params object[] args)
		{
			_mLogSource.LogFatal((object)Format(string.Format(fmt, args)));
		}
	}
	[BepInPlugin("io.takina.gtfo.Graphlib", "Graphlib", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public const string NAME = "Graphlib";

		public const string GUID = "io.takina.gtfo.Graphlib";

		public const string VERSION = "1.0.0";

		public override void Load()
		{
			Logger.Setup();
			Logger.Info("Graphlib [io.takina.gtfo.Graphlib @ 1.0.0]");
			ConfigMgr.Init();
			ClassInjector.RegisterTypeInIl2Cpp<Plotter>();
			ClassInjector.RegisterTypeInIl2Cpp<StatGraph>();
		}
	}
	public static class Util
	{
		private static readonly string[] _siAbbrs = new string[7] { "", "K", "M", "G", "T", "P", "E" };

		public static Vector3 Extend(this Vector2 v, float z = 0f)
		{
			//IL_0000: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, v.y, z);
		}

		public static int TrueMod(int n, int m)
		{
			return (n % m + m) % m;
		}

		public static string Value2SIAbbrStr(float value, bool includeOneDecimalWhenValueLessThan10 = true)
		{
			bool flag = value < 1000f;
			int num = 0;
			while (value >= 1000f && num < _siAbbrs.Length - 1)
			{
				value /= 1000f;
				num++;
			}
			string text = ((!flag && includeOneDecimalWhenValueLessThan10 && value < 10f) ? "0.0" : "0");
			return value.ToString(text) + _siAbbrs[num];
		}
	}
}
namespace Graphlib.UI
{
	public static class TMPUtil
	{
		public static bool CreateTMP(string name, Transform? parent, [NotNullWhen(true)] out TextMeshPro? tp)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			WatermarkGuiLayer watermarkLayer = GuiManager.WatermarkLayer;
			object obj;
			if (watermarkLayer == null)
			{
				obj = null;
			}
			else
			{
				PUI_Watermark watermark = watermarkLayer.m_watermark;
				obj = ((watermark != null) ? watermark.m_fpsText : null);
			}
			TextMeshPro val = (TextMeshPro)obj;
			if ((Object)(object)parent == (Object)null || (Object)(object)val == (Object)null)
			{
				tp = null;
				return false;
			}
			tp = Object.Instantiate<TextMeshPro>(val, parent, false);
			((Object)tp).name = name;
			((TMP_Text)tp).rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			((TMP_Text)tp).rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			((TMP_Text)tp).rectTransform.pivot = new Vector2(1f, 0f);
			((TMP_Text)tp).rectTransform.anchoredPosition3D = new Vector3(0f, 2f, 0f);
			((Transform)((TMP_Text)tp).rectTransform).localRotation = Quaternion.Euler(0f, 0f, 0f);
			((TMP_Text)tp).enableAutoSizing = false;
			((TMP_Text)tp).overflowMode = (TextOverflowModes)0;
			((TMP_Text)tp).alignment = (TextAlignmentOptions)513;
			((TMP_Text)tp).fontSize = 16f;
			return true;
		}

		public static bool CreateTMPUGUI(string name, Transform? parent, [NotNullWhen(true)] out TextMeshProUGUI? tp)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0052: 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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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)
			WatermarkGuiLayer watermarkLayer = GuiManager.WatermarkLayer;
			object obj;
			if (watermarkLayer == null)
			{
				obj = null;
			}
			else
			{
				PUI_Watermark watermark = watermarkLayer.m_watermark;
				obj = ((watermark != null) ? watermark.m_fpsText : null);
			}
			TextMeshPro val = (TextMeshPro)obj;
			GameObject val2 = new GameObject();
			val2.transform.SetParent(parent, false);
			tp = val2.AddComponent<TextMeshProUGUI>();
			((Object)tp).name = name;
			((TMP_Text)tp).rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			((TMP_Text)tp).rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			((TMP_Text)tp).rectTransform.pivot = new Vector2(1f, 0f);
			((TMP_Text)tp).rectTransform.anchoredPosition3D = new Vector3(0f, 2f, 0f);
			((Transform)((TMP_Text)tp).rectTransform).localRotation = Quaternion.Euler(0f, 0f, 0f);
			((TMP_Text)tp).enableAutoSizing = false;
			((TMP_Text)tp).overflowMode = (TextOverflowModes)0;
			((TMP_Text)tp).alignment = (TextAlignmentOptions)513;
			((TMP_Text)tp).fontSize = 16f;
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)tp).font = ((TMP_Text)val).font;
				((TMP_Text)tp).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
			}
			return true;
		}
	}
	public static class VhUtil
	{
		public static void AddRect(VertexHelper vh, Rect r, Color c)
		{
			//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_0010: 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_002a: 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_0034: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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)
			int currentVertCount = vh.currentVertCount;
			UIVertex simpleVert = UIVertex.simpleVert;
			simpleVert.color = Color32.op_Implicit(c);
			simpleVert.position = Vector2.op_Implicit(new Vector2(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin));
			vh.AddVert(simpleVert);
			simpleVert.position = Vector2.op_Implicit(new Vector2(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMax));
			vh.AddVert(simpleVert);
			simpleVert.position = Vector2.op_Implicit(new Vector2(((Rect)(ref r)).xMax, ((Rect)(ref r)).yMax));
			vh.AddVert(simpleVert);
			simpleVert.position = Vector2.op_Implicit(new Vector2(((Rect)(ref r)).xMax, ((Rect)(ref r)).yMin));
			vh.AddVert(simpleVert);
			vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
			vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
		}

		public static void AddBorder(VertexHelper vh, Rect r, float thickness, Color c)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0073: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			AddRect(vh, Rect.MinMaxRect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMax - thickness, ((Rect)(ref r)).xMax, ((Rect)(ref r)).yMax), c);
			AddRect(vh, Rect.MinMaxRect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin, ((Rect)(ref r)).xMax, ((Rect)(ref r)).yMin + thickness), c);
			AddRect(vh, Rect.MinMaxRect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin, ((Rect)(ref r)).xMin + thickness, ((Rect)(ref r)).yMax), c);
			AddRect(vh, Rect.MinMaxRect(((Rect)(ref r)).xMax - thickness, ((Rect)(ref r)).yMin, ((Rect)(ref r)).xMax, ((Rect)(ref r)).yMax), c);
		}

		public static void AddThickSegment(VertexHelper vh, Vector2 a, Vector2 b, float halfThickness, Color c)
		{
			//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_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_0019: 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_0021: 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_002e: 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_0039: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0042: 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_0049: 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_004c: 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_0052: 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_0055: 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_005b: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0088: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_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)
			Vector2 val = b - a;
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (!(magnitude < 0.0001f))
			{
				val /= magnitude;
				Vector2 val2 = new Vector2(0f - val.y, val.x) * halfThickness;
				Vector2 val3 = a - val2;
				Vector2 val4 = a + val2;
				Vector2 val5 = b + val2;
				Vector2 val6 = b - val2;
				int currentVertCount = vh.currentVertCount;
				UIVertex simpleVert = UIVertex.simpleVert;
				simpleVert.color = Color32.op_Implicit(c);
				simpleVert.position = Vector2.op_Implicit(val3);
				vh.AddVert(simpleVert);
				simpleVert.position = Vector2.op_Implicit(val4);
				vh.AddVert(simpleVert);
				simpleVert.position = Vector2.op_Implicit(val5);
				vh.AddVert(simpleVert);
				simpleVert.position = Vector2.op_Implicit(val6);
				vh.AddVert(simpleVert);
				vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
				vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
			}
		}
	}
}
namespace Graphlib.Grapher
{
	public sealed class Plotter : Graphic
	{
		[Flags]
		public enum PlotComponent
		{
			None = 0,
			Line = 1,
			Fill = 2,
			Background = 4,
			Border = 8,
			PerChannel = 3,
			Standard = 0xD,
			StandardFill = 0xF,
			StandardNoBg = 9
		}

		private struct ChannelStyle
		{
			public bool DrawLine;

			public float LineThickness;

			public Color LineColor;

			public bool DrawFill;

			public float FillChunkWidth;

			public Color FillColor;

			public ChannelStyle()
			{
				//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_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				DrawLine = true;
				LineThickness = 2f;
				LineColor = new Color(0.85f, 0.85f, 0.85f, 1f);
				DrawFill = false;
				FillChunkWidth = 3f;
				FillColor = new Color(1f, 1f, 1f, 0.25f);
			}
		}

		private Vector2 _plotSize = new Vector2(200f, 100f);

		private float _minY;

		private float _maxY = 1f;

		private bool _autoScale;

		private float _autoscaleInc = -1f;

		private float _autoScaleLerp = 0.35f;

		private bool _useLogScale;

		private int _lineResolution = 1;

		private float _clearance;

		private bool _dirty;

		private ChannelStyle[] _styles = new ChannelStyle[0];

		private int _capacity = 120;

		private float _dispMax;

		private int _channelCount = 1;

		private float[,] _samples = new float[0, 0];

		private int[] _heads = new int[0];

		private int[] _counts = new int[0];

		private float[] _maxObserved = new float[0];

		public int Capacity => _capacity;

		public Vector2 Size => ((Graphic)this).rectTransform.sizeDelta;

		public Vector2 PlotSize
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _plotSize;
			}
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				_plotSize = value;
				((Graphic)this).rectTransform.sizeDelta = new Vector2(_plotSize.x, _plotSize.y + _clearance);
				MarkDirty();
			}
		}

		public float Clearance => _clearance;

		public float MinY
		{
			get
			{
				return _minY;
			}
			set
			{
				_minY = value;
				MarkDirty();
			}
		}

		public float MaxY
		{
			get
			{
				return _maxY;
			}
			set
			{
				_maxY = value;
				_dispMax = value;
				MarkDirty();
			}
		}

		public float DisplayMaxY => _dispMax;

		public bool LogScale
		{
			get
			{
				return _useLogScale;
			}
			set
			{
				_useLogScale = value;
				MarkDirty();
			}
		}

		public bool AutoScale
		{
			get
			{
				return _autoScale;
			}
			set
			{
				_autoScale = value;
				MarkDirty();
			}
		}

		public float AutoScaleIncrement
		{
			get
			{
				return _autoscaleInc;
			}
			set
			{
				_autoscaleInc = value;
				MarkDirty();
			}
		}

		public float AutoScaleLerpFactor
		{
			get
			{
				return _autoScaleLerp;
			}
			set
			{
				_autoScaleLerp = Mathf.Clamp01(value);
				MarkDirty();
			}
		}

		public bool DrawBackground { get; set; } = true;


		public Color BgColor { get; private set; } = new Color(0f, 0f, 0f, 0.35f);


		public bool DrawBorder { get; set; } = true;


		public float BorderThickness { get; set; } = 1f;


		public Color BorderColor { get; private set; } = new Color(1f, 1f, 1f, 0.35f);


		public event Action<Graphic, VertexHelper>? AfterPopulateMesh;

		public override void Awake()
		{
			EnsureBuffer();
			_dispMax = _maxY;
		}

		public void AllocateChannels(int channelCount)
		{
			_channelCount = Mathf.Max(1, channelCount);
			EnsureBuffer();
		}

		public void SetCapacity(int cap)
		{
			_capacity = Mathf.Max(8, cap);
			EnsureBuffer();
			MarkDirty();
		}

		public void SetStyle(PlotComponent style, int channel = 0, bool affectBackgroundAndBorder = false)
		{
			_styles[channel].DrawLine = style.HasFlag(PlotComponent.Line);
			_styles[channel].DrawFill = style.HasFlag(PlotComponent.Fill);
			if (affectBackgroundAndBorder)
			{
				DrawBackground = style.HasFlag(PlotComponent.Background);
				DrawBorder = style.HasFlag(PlotComponent.Border);
			}
			MarkDirty();
		}

		public void SetColor(PlotComponent comp, Color c, int channel = 0)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_005e: 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)
			if (comp.HasFlag(PlotComponent.Line))
			{
				_styles[channel].LineColor = c;
			}
			if (comp.HasFlag(PlotComponent.Fill))
			{
				_styles[channel].FillColor = c;
			}
			if (comp.HasFlag(PlotComponent.Background))
			{
				BgColor = c;
			}
			if (comp.HasFlag(PlotComponent.Border))
			{
				BorderColor = c;
			}
			MarkDirty();
		}

		public void SetThickness(PlotComponent comp, float thickness, int channel = 0, bool affectBackgroundAndBorder = false)
		{
			if (comp.HasFlag(PlotComponent.Line))
			{
				_styles[channel].LineThickness = Mathf.Max(1f, thickness);
			}
			if (comp.HasFlag(PlotComponent.Fill))
			{
				_styles[channel].FillChunkWidth = Mathf.Max(0f, thickness);
			}
			if (affectBackgroundAndBorder && comp.HasFlag(PlotComponent.Border))
			{
				BorderThickness = Mathf.Max(0f, thickness);
			}
			MarkDirty();
		}

		public void SetClearance(float clearance)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			_clearance = clearance;
			((Graphic)this).rectTransform.sizeDelta = new Vector2(_plotSize.x, _plotSize.y + _clearance);
			MarkDirty();
		}

		public void PushSample(float value, int channel = 0)
		{
			EnsureBuffer();
			_heads[channel] = (_heads[channel] + 1) % _capacity;
			_samples[channel, _heads[channel]] = value;
			if (_counts[channel] < _capacity)
			{
				_counts[channel]++;
			}
			if (_autoScale)
			{
				float num = _minY + 0.0001f;
				for (int i = 0; i < _counts[channel]; i++)
				{
					float sampleReverse = GetSampleReverse(i, channel);
					if (sampleReverse > num)
					{
						num = sampleReverse;
					}
				}
				_maxObserved[channel] = Mathf.Max(num, _minY + 0.0001f);
				float num2 = _minY + 0.0001f;
				for (int j = 0; j < _channelCount; j++)
				{
					if (_maxObserved[j] > num2)
					{
						num2 = _maxObserved[j];
					}
				}
				float num3 = num2;
				if (_autoscaleInc > 0f)
				{
					num3 = Mathf.Ceil((num2 - _minY) / _autoscaleInc) * _autoscaleInc + _minY;
				}
				_dispMax = Mathf.Lerp(_dispMax, num3, _autoScaleLerp);
				_dispMax = Mathf.Max(Mathf.Max(_dispMax, _minY + 0.0001f), _maxY);
			}
			MarkDirty();
		}

		public void Clear()
		{
			Array.Clear(_samples);
			for (int i = 0; i < _channelCount; i++)
			{
				_heads[i] = _capacity - 1;
				_counts[i] = 0;
				_maxObserved[i] = _minY;
			}
			MarkDirty();
		}

		private void EnsureBuffer()
		{
			if (_styles.Length != _channelCount || _samples.Length != _capacity * _channelCount)
			{
				_styles = new ChannelStyle[_channelCount];
				for (int i = 0; i < _styles.Length; i++)
				{
					_styles[i] = new ChannelStyle();
				}
				_samples = new float[_channelCount, _capacity];
				_heads = new int[_channelCount];
				Array.Fill(_heads, _capacity - 1);
				_counts = new int[_channelCount];
				_maxObserved = new float[_channelCount];
				_dirty = true;
			}
		}

		private void MarkDirty()
		{
			if (!_dirty)
			{
				_dirty = true;
				((Graphic)this).SetVerticesDirty();
			}
		}

		private float GetSample(int i, int channel = 0)
		{
			int n = _heads[channel] + 1 + i;
			n = Util.TrueMod(n, _capacity);
			if (!_useLogScale)
			{
				return _samples[channel, n];
			}
			return Mathf.Log(_samples[channel, n]);
		}

		private float GetSampleReverse(int i, int channel = 0)
		{
			int n = _heads[channel] - i;
			n = Util.TrueMod(n, _capacity);
			if (!_useLogScale)
			{
				return _samples[channel, n];
			}
			return Mathf.Log(_samples[channel, n]);
		}

		public override void OnPopulateMesh(VertexHelper vh)
		{
			//IL_000e: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			vh.Clear();
			_dirty = false;
			Rect pixelAdjustedRect = ((Graphic)this).GetPixelAdjustedRect();
			if (((Rect)(ref pixelAdjustedRect)).width <= 1f || ((Rect)(ref pixelAdjustedRect)).height <= 1f)
			{
				return;
			}
			if (DrawBackground)
			{
				VhUtil.AddRect(vh, pixelAdjustedRect, BgColor);
			}
			Vector2 val2 = default(Vector2);
			for (int i = 0; i < _channelCount; i++)
			{
				ChannelStyle channelStyle = _styles[i];
				if (_counts[i] <= 1)
				{
					continue;
				}
				float num = (_autoScale ? _dispMax : _maxY);
				num = Mathf.Max(num, _minY + 0.0001f);
				float xMin = ((Rect)(ref pixelAdjustedRect)).xMin;
				float xMax = ((Rect)(ref pixelAdjustedRect)).xMax;
				float yMin = ((Rect)(ref pixelAdjustedRect)).yMin;
				float num2 = ((Rect)(ref pixelAdjustedRect)).yMax - _clearance;
				int capacity = _capacity;
				float num3 = (xMax - xMin) / (float)(capacity - 1);
				float num4 = 1f / (num - _minY);
				if (channelStyle.DrawFill)
				{
					float num5 = Mathf.Min(channelStyle.FillChunkWidth * 0.5f, num3 * 0.5f);
					for (int j = 0; j < capacity; j++)
					{
						float num6 = Mathf.Clamp01((GetSample(j, i) - _minY) * num4);
						float num7 = xMin + num3 * (float)j;
						float num8 = Mathf.Lerp(yMin, num2, num6);
						Rect r = Rect.MinMaxRect(num7 - num5, yMin, num7 + num5, num8);
						VhUtil.AddRect(vh, r, channelStyle.FillColor);
					}
				}
				if (!channelStyle.DrawLine)
				{
					continue;
				}
				float halfThickness = channelStyle.LineThickness * 0.5f;
				Vector2 val = default(Vector2);
				for (int k = 0; k < capacity; k++)
				{
					float num9 = Mathf.Clamp01((GetSample(k, i) - _minY) * num4);
					float num10 = xMin + num3 * (float)k;
					float num11 = Mathf.Lerp(yMin, num2, num9);
					((Vector2)(ref val2))..ctor(num10, num11);
					if (k > 0)
					{
						for (int l = 1; l <= _lineResolution; l++)
						{
							float num12 = (float)l / (float)_lineResolution;
							Vector2 b = Vector2.Lerp(val, val2, num12);
							Vector2 a = Vector2.Lerp(val, val2, (float)(l - 1) / (float)_lineResolution);
							VhUtil.AddThickSegment(vh, a, b, halfThickness, channelStyle.LineColor);
						}
					}
					val = val2;
				}
			}
			if (DrawBorder && BorderThickness > 0f)
			{
				VhUtil.AddBorder(vh, pixelAdjustedRect, BorderThickness, BorderColor);
			}
			this.AfterPopulateMesh?.Invoke((Graphic)(object)this, vh);
		}
	}
}
namespace Graphlib.Config
{
	public enum ConfigEntryRule
	{
		Min,
		Max
	}
	public class ConfigEntryExtended<T>
	{
		private Dictionary<ConfigEntryRule, T> _rules = new Dictionary<ConfigEntryRule, T>();

		private ConfigEntry<T> _entry;

		public T Value
		{
			get
			{
				return _entry.Value;
			}
			set
			{
				_entry.Value = Enforce(value);
			}
		}

		public object BoxedValue
		{
			get
			{
				return ((ConfigEntryBase)_entry).BoxedValue;
			}
			set
			{
				((ConfigEntryBase)_entry).BoxedValue = Enforce((T)value);
			}
		}

		public ConfigEntryExtended(ConfigEntry<T> entry)
		{
			_entry = entry;
		}

		public bool AddRule(ConfigEntryRule rule, T ruleValue)
		{
			if (_rules.TryAdd(rule, ruleValue))
			{
				Enforce(rule);
				return true;
			}
			return false;
		}

		private void Enforce()
		{
			T val = Enforce(_entry.Value);
			if (val != null && !val.Equals(_entry.Value))
			{
				_entry.Value = val;
			}
		}

		private T Enforce(T val)
		{
			foreach (var (configEntryRule2, val3) in _rules)
			{
				switch (configEntryRule2)
				{
				case ConfigEntryRule.Min:
					if (Comparer<T>.Default.Compare(val, val3) < 0)
					{
						val = val3;
					}
					break;
				case ConfigEntryRule.Max:
					if (Comparer<T>.Default.Compare(val, val3) > 0)
					{
						val = val3;
					}
					break;
				}
			}
			return val;
		}

		private void Enforce(ConfigEntryRule rule)
		{
			T value = _entry.Value;
			value = Enforce(value, rule);
			if (value != null && !value.Equals(_entry.Value))
			{
				_entry.Value = value;
			}
		}

		private T Enforce(T val, ConfigEntryRule rule)
		{
			if (!_rules.TryGetValue(rule, out var value))
			{
				return val;
			}
			switch (rule)
			{
			case ConfigEntryRule.Min:
				if (Comparer<T>.Default.Compare(val, value) < 0)
				{
					val = value;
				}
				break;
			case ConfigEntryRule.Max:
				if (Comparer<T>.Default.Compare(val, value) > 0)
				{
					val = value;
				}
				break;
			}
			return val;
		}

		public static implicit operator ConfigEntryExtended<T>(ConfigEntry<T> entry)
		{
			return new ConfigEntryExtended<T>(entry);
		}
	}
	internal static class ConfigMgr
	{
		private static readonly ConfigFile Conf;

		private static readonly FileSystemWatcher? ConfigWatcher;

		private static readonly ConfigEntryExtended<bool> DebugConf;

		public static bool Debug => DebugConf.Value;

		public static void Init()
		{
			Logger.Info($"debug={Debug}");
		}

		static ConfigMgr()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			string text = "Graphlib.cfg";
			string text2 = Path.Combine(Paths.ConfigPath, text);
			Logger.Info("cfgPath = " + text2);
			Conf = new ConfigFile(text2, true);
			ConfigWatcher = new FileSystemWatcher(Paths.ConfigPath, text)
			{
				NotifyFilter = NotifyFilters.LastWrite,
				EnableRaisingEvents = true
			};
			ConfigWatcher.Changed += async delegate
			{
				ConfigWatcher.EnableRaisingEvents = false;
				await Task.Delay(500);
				Logger.Debug("Reloading config...");
				Conf.Reload();
				await Task.Delay(250);
				ConfigWatcher.EnableRaisingEvents = true;
			};
			string sectionHeader = default(string);
			HeaderSp('Z', "Dev");
			DebugConf = Conf.Bind<bool>(sectionHeader, "Enable Debug Logs", false, "debug logging");
			void HeaderSp(char prefix, string header)
			{
				sectionHeader = $"({prefix}) {header}";
			}
		}
	}
}