Decompiled source of Mission Timer v1.0.0

MissionTimer.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BrigadeModMenu;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using MissionTimer;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MissionTimerMod), "Mission Timer", "1.0.0", "Mission Timer", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: MelonOptionalDependencies(new string[] { "BrigadeModMenu" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MissionTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MissionTimer")]
[assembly: AssemblyTitle("MissionTimer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BrigadeModMenu
{
	public static class ModMenuCompat
	{
		public static Page Entry(this Page page, MelonPreferences_Entry entry, Func<string> label = null)
		{
			if (entry != null)
			{
				return page.Entry(entry.Raw, label ?? ((Func<string>)(() => entry.DisplayName)));
			}
			return page;
		}

		public static Page Category(this Page page, MelonPreferences_Category category)
		{
			if (category == null)
			{
				return page;
			}
			Menu.HideCategory(category.Identifier);
			foreach (MelonPreferences_Entry e in category.Entries)
			{
				if (e != null && !e.IsHidden)
				{
					page.Entry(e.Raw, (Func<string>)(() => e.DisplayName));
				}
			}
			return page;
		}
	}
}
namespace MissionTimer
{
	internal static class MenuPage
	{
		private const string BaseSizeKey = "MissionTimer.BaseSize";

		private const string MarkersKey = "MissionTimer.ObjectiveLines";

		private static readonly List<GameObject> _lines = new List<GameObject>();

		private static TMP_Text _preview;

		private static Image _icon;

		private static RectTransform _area;

		private static readonly HudElement Element = new HudElement
		{
			Name = "Mission Timer",
			Build = delegate(RectTransform parent)
			{
				_preview = null;
				float[] array = HudEditor.Measured("MissionTimer.BaseSize");
				RectTransform val = HudEditor.Recorded("RunProgress_Panel/Progress_Slider");
				if (array == null || (Object)(object)val == (Object)null)
				{
					return (RectTransform)null;
				}
				_area = parent;
				RectTransform obj = HudEditor.Recorded("RunProgress_Panel");
				TMP_Text val2 = ((obj != null) ? ((Component)obj).GetComponentInChildren<TMP_Text>(true) : null);
				GameObject go = (((Object)(object)val2 != (Object)null) ? Object.Instantiate<GameObject>(((Component)val2).gameObject, (Transform)(object)val, false) : NewText((Transform)(object)val));
				MissionTimerMod.CurrentBaseSize = array[0];
				_preview = MissionTimerMod.StyleLabel(go);
				_preview.text = "12:34";
				Sprite val3 = HudEditor.Sprite("ui_stat_icon_time");
				_icon = (((Object)(object)val3 != (Object)null) ? MissionTimerMod.AddIcon(_preview, val3) : null);
				BuildLines(val);
				return _preview.rectTransform;
			},
			Place = delegate
			{
				if ((Object)(object)_preview == (Object)null)
				{
					return;
				}
				MissionTimerMod.ApplySizeTo(_preview);
				MissionTimerMod.PlaceIcon(_preview, _icon);
				MissionTimerMod.PlaceLabel(_preview, (Transform)(object)_area);
				foreach (GameObject line in _lines)
				{
					if ((Object)(object)line != (Object)null && line.activeSelf != MissionTimerMod.ShowMarkers.Value)
					{
						line.SetActive(MissionTimerMod.ShowMarkers.Value);
					}
				}
			},
			Live = MissionTimerMod.LiveLabel,
			GetOffset = () => new Vector2(MissionTimerMod.OffsetX.Value, MissionTimerMod.OffsetY.Value),
			SetOffset = delegate(Vector2 v)
			{
				//IL_0005: 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)
				MissionTimerMod.OffsetX.Value = Mathf.Clamp(v.x, -2500f, 2500f);
				MissionTimerMod.OffsetY.Value = Mathf.Clamp(v.y, -1900f, 200f);
			},
			GetSize = () => MissionTimerMod.Size.Value,
			SetSize = delegate(float s)
			{
				MissionTimerMod.Size.Value = s;
			},
			Reset = delegate
			{
				MissionTimerMod.OffsetX.Value = 0f;
				MissionTimerMod.OffsetY.Value = 0f;
				MissionTimerMod.Size.Value = 1f;
			}
		};

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			HudEditor.RecordSprites(new string[1] { "ui_stat_icon_time" });
			HudEditor.Register(Element);
			Menu.AddPage("MissionTimer", "Mission Timer").Entry(MissionTimerMod.Enabled, () => "Show Mission Time").Entry(MissionTimerMod.ShowMarkers, () => "Show Objective Lines")
				.Buttons((MenuButton[])(object)new MenuButton[1]
				{
					new MenuButton("Edit Position & Size", (Action)delegate
					{
						HudEditor.Open(Element);
					}, false)
				})
				.Entry(MissionTimerMod.FollowPanels, () => "Move Below Objective Windows")
				.Note((Func<string>)(() => "With the setting above on, the time moves down below an objective's window only when the window would cover it, wherever you've put it."))
				.Entry(MissionTimerMod.Size, () => "Text Size")
				.Entry(MissionTimerMod.OffsetX, () => "Move Left / Right")
				.Entry(MissionTimerMod.OffsetY, () => "Move Up / Down");
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void SaveMarkers(float[] progress)
		{
			HudEditor.Measure("MissionTimer.ObjectiveLines", progress);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void SaveBaseSize(float size)
		{
			HudEditor.Measure("MissionTimer.BaseSize", new float[1] { size });
		}

		private static void BuildLines(RectTransform bar)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			_lines.Clear();
			float[] array = HudEditor.Measured("MissionTimer.ObjectiveLines");
			Transform obj = ((Transform)bar).Find("Fill Area");
			RectTransform val = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
			if (array != null && !((Object)(object)val == (Object)null))
			{
				Transform obj2 = ((Transform)val).Find("Fill");
				Image val2 = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
				Color color = (Color)(((Object)(object)val2 != (Object)null) ? ((Graphic)val2).color : new Color(1f, 1f, 0.95f, 1f));
				Rect rect = val.rect;
				float barHeight = Mathf.Max(((Rect)(ref rect)).height, 10f);
				for (int i = 0; i < array.Length; i++)
				{
					_lines.Add(ObjectiveMarkers.CreateLine(val, array[i], color, barHeight, i));
				}
			}
		}

		private static GameObject NewText(Transform parent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			GameObject val = new GameObject("Text");
			val.transform.SetParent(parent, false);
			val.AddComponent<TextMeshProUGUI>();
			return val;
		}
	}
	public class MissionTimerMod : MelonMod
	{
		private struct Area
		{
			public bool Any;

			public float MinX;

			public float MaxX;

			public float MinY;

			public float MaxY;

			public void Add(Vector3 p)
			{
				//IL_0041: 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_006f: 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_0011: 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)
				if (!Any)
				{
					Any = true;
					MinX = (MaxX = p.x);
					MinY = (MaxY = p.y);
				}
				else
				{
					MinX = Mathf.Min(MinX, p.x);
					MaxX = Mathf.Max(MaxX, p.x);
					MinY = Mathf.Min(MinY, p.y);
					MaxY = Mathf.Max(MaxY, p.y);
				}
			}
		}

		private const string LabelName = "MissionTimer_Label";

		internal static MelonLogger.Instance Log;

		internal static MelonPreferences_Entry<bool> Enabled;

		internal static MelonPreferences_Entry<float> Size;

		internal static MelonPreferences_Entry<float> OffsetX;

		internal static MelonPreferences_Entry<float> OffsetY;

		internal static MelonPreferences_Entry<bool> ShowMarkers;

		internal static MelonPreferences_Entry<bool> FollowPanels;

		private static bool _hasMenu;

		private static float _editingUntil;

		private static TMP_Text _label;

		private static RunProgressBarUI _bar;

		private static int _shownSeconds = -1;

		private static bool _detached;

		private const float ObjectiveGap = 14f;

		private static Vector3 _home;

		private static ObjectiveDetailPanel[] _panels;

		private const string IconName = "MissionTimer_Icon";

		private static Image _icon;

		private static float _nextIconTry;

		private static float _baseSize = 32f;

		internal static bool HasMenu => _hasMenu;

		private static bool Editing => Time.unscaledTime < _editingUntil;

		internal static float CurrentBaseSize
		{
			get
			{
				return _baseSize;
			}
			set
			{
				_baseSize = value;
			}
		}

		internal static RectTransform LiveLabel()
		{
			if ((Object)(object)_label == (Object)null || ((Il2CppObjectBase)_label).WasCollected)
			{
				return null;
			}
			_editingUntil = Time.unscaledTime + 0.3f;
			if (!((Component)_label).gameObject.activeSelf)
			{
				((Component)_label).gameObject.SetActive(true);
			}
			return _label.rectTransform;
		}

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			MelonPreferences_Category melonPreferences_Category = MelonPreferences.CreateCategory("MissionTimer", "Mission Timer");
			Enabled = melonPreferences_Category.CreateEntry("Enabled", default_value: true, "Show Mission Time", "Show the total mission time under the mission bar");
			Size = melonPreferences_Category.CreateEntry("TextSize", 1f, "Text Size", "Size of the mission time text", is_hidden: false, dont_save_default: false, new ValueRange<float>(0.5f, 2f));
			ShowMarkers = melonPreferences_Category.CreateEntry("ObjectiveMarkers", default_value: true, "Show Objective Lines", "Show glowing lines on the mission bar where objectives start");
			FollowPanels = melonPreferences_Category.CreateEntry("FollowObjectivePanels", default_value: true, "Move Below Objective Windows", "If an objective's window at the top of the screen would cover the time, move the time down just below it");
			OffsetX = melonPreferences_Category.CreateEntry("OffsetX", 0f, "Move Left / Right", "Move the time left (negative) or right (positive) of its usual spot", is_hidden: false, dont_save_default: false, new ValueRange<float>(-2500f, 2500f));
			OffsetY = melonPreferences_Category.CreateEntry("OffsetY", 0f, "Move Up / Down", "Move the time down (negative) or up (positive) from its usual spot", is_hidden: false, dont_save_default: false, new ValueRange<float>(-1900f, 200f));
			melonPreferences_Category.SaveToFile(printmsg: false);
			Enabled.OnEntryValueChanged.Subscribe(delegate(bool _, bool on)
			{
				if ((Object)(object)_label != (Object)null)
				{
					((Component)_label).gameObject.SetActive(on);
				}
			});
			Size.OnEntryValueChanged.Subscribe(delegate
			{
				ApplySize();
			});
			if (Array.Exists(AppDomain.CurrentDomain.GetAssemblies(), (Assembly a) => a.GetName().Name == "BrigadeModMenu"))
			{
				_hasMenu = true;
				try
				{
					RegisterMenu();
				}
				catch (Exception ex)
				{
					Log.Warning("Mod Menu page: " + ex.Message);
				}
			}
			if (Patch("Start", "BarStartPostfix"))
			{
				Log.Msg("ready — mission time and objective markers on the mission bar");
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterMenu()
		{
			MenuPage.Register();
		}

		private static Vector3 OffsetWorld()
		{
			//IL_0048: 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)
			Canvas val = (((Object)(object)_label != (Object)null && (Object)(object)((Graphic)_label).canvas != (Object)null) ? ((Graphic)_label).canvas.rootCanvas : null);
			float num = (((Object)(object)val != (Object)null) ? ((Component)val).transform.lossyScale.x : 1f);
			return new Vector3(OffsetX.Value * num, OffsetY.Value * num, 0f);
		}

		private bool Patch(string method, string postfix)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(RunProgressBarUI), method, (Type[])null, (Type[])null) ?? throw new MissingMethodException("RunProgressBarUI." + method + " not found");
				base.HarmonyInstance.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(MissionTimerMod), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				return true;
			}
			catch (Exception ex)
			{
				Log.Error("failed to hook RunProgressBarUI." + method + ": " + ex.Message);
				return false;
			}
		}

		private static void BarStartPostfix(RunProgressBarUI __instance)
		{
			try
			{
				RunProgressBarUI val = ((__instance != null) ? ((Il2CppObjectBase)__instance).TryCast<RunProgressBarUI>() : null);
				if (!((Object)(object)val == (Object)null))
				{
					_bar = val;
					_shownSeconds = -1;
					ObjectiveMarkers.Reset(val);
					if ((Object)(object)_label != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)_label).gameObject);
					}
					_label = null;
					_detached = false;
					_panels = null;
					_label = CreateLabel(val);
					Tick();
				}
			}
			catch (Exception value)
			{
				Log.Warning($"mission time label: {value}");
			}
		}

		public override void OnUpdate()
		{
			if ((Object)(object)_bar == (Object)null)
			{
				if ((Object)(object)_label != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_label).gameObject);
					_label = null;
				}
				return;
			}
			try
			{
				ObjectiveMarkers.Tick();
			}
			catch (Exception ex)
			{
				Log.Warning("objective markers: " + ex.Message);
				_bar = null;
				return;
			}
			if ((Object)(object)_label == (Object)null)
			{
				return;
			}
			if (!Enabled.Value && !Editing && ((Component)_label).gameObject.activeSelf)
			{
				((Component)_label).gameObject.SetActive(false);
			}
			try
			{
				Tick();
			}
			catch
			{
				_label = null;
			}
		}

		private static void Tick()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_label == (Object)null || (Object)(object)_bar == (Object)null || (!Enabled.Value && !Editing))
			{
				return;
			}
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (!_detached)
			{
				PlaceLabel(_label, ((Object)(object)((Graphic)_label).canvas != (Object)null) ? ((Component)((Graphic)_label).canvas.rootCanvas).transform : null);
			}
			if (!_detached && instance.runHasStarted && instance.GetCurrentRunTimeInSeconds() > 3f && ((Component)_label).gameObject.activeInHierarchy)
			{
				Canvas val = (((Object)(object)((Graphic)_label).canvas != (Object)null) ? ((Graphic)_label).canvas.rootCanvas : null);
				if ((Object)(object)val != (Object)null)
				{
					_home = _label.transform.position - OffsetWorld();
					_label.transform.SetParent(((Component)val).transform, true);
					_detached = true;
				}
			}
			if (_detached)
			{
				FollowObjective();
			}
			if ((Object)(object)_icon == (Object)null && Time.unscaledTime >= _nextIconTry)
			{
				_nextIconTry = Time.unscaledTime + 2f;
				CreateIcon(_label, quiet: true);
				if ((Object)(object)_icon != (Object)null)
				{
					_shownSeconds = -1;
				}
			}
			int num = Mathf.FloorToInt(Mathf.Max(0f, instance.GetCurrentRunTimeInSeconds()));
			if (num != _shownSeconds)
			{
				_shownSeconds = num;
				TimeSpan timeSpan = TimeSpan.FromSeconds(num);
				_label.text = ((timeSpan.TotalHours >= 1.0) ? $"{(int)timeSpan.TotalHours}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}" : $"{timeSpan.Minutes:00}:{timeSpan.Seconds:00}");
				PlaceIcon(_label, _icon);
			}
		}

		internal static void PlaceLabel(TMP_Text label, Transform hud)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = label.transform.parent;
			float num = (((Object)(object)parent != (Object)null && (Object)(object)hud != (Object)null && hud.lossyScale.x > 0f) ? (parent.lossyScale.x / hud.lossyScale.x) : 1f);
			label.rectTransform.anchoredPosition = new Vector2(OffsetX.Value, OffsetY.Value) / Mathf.Max(0.01f, num) + new Vector2(0f, -16f);
		}

		private static void FollowObjective()
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = _home + OffsetWorld();
			_label.transform.position = val;
			if (!FollowPanels.Value)
			{
				return;
			}
			if (_panels == null)
			{
				_panels = FindPanels();
			}
			Area area = default(Area);
			ObjectiveDetailPanel[] panels = _panels;
			foreach (ObjectiveDetailPanel val2 in panels)
			{
				if ((Object)(object)val2 == (Object)null || !((Component)val2).gameObject.activeInHierarchy)
				{
					continue;
				}
				foreach (TMP_Text componentsInChild in ((Component)val2).GetComponentsInChildren<TMP_Text>(false))
				{
					AddLetters(componentsInChild, ref area);
				}
				foreach (Image componentsInChild2 in ((Component)val2).GetComponentsInChildren<Image>(false))
				{
					AddImage(componentsInChild2, ref area);
				}
			}
			if (!area.Any)
			{
				return;
			}
			Area area2 = TimerArea();
			if (!area2.Any)
			{
				return;
			}
			bool num = area2.MinX < area.MaxX && area2.MaxX > area.MinX;
			bool flag = area2.MinY < area.MaxY && area2.MaxY > area.MinY - 14f * _label.transform.lossyScale.y;
			if (num && flag)
			{
				float num2 = 14f * _label.transform.lossyScale.y;
				float num3 = area2.MaxY - (area.MinY - num2);
				if (num3 > 0f)
				{
					_label.transform.position = val - new Vector3(0f, num3, 0f);
				}
			}
		}

		private static Area TimerArea()
		{
			Area area = default(Area);
			_label.ForceMeshUpdate(false, false);
			AddLetters(_label, ref area);
			if ((Object)(object)_icon != (Object)null)
			{
				AddImage(_icon, ref area);
			}
			return area;
		}

		private static void AddImage(Image image, ref Area area)
		{
			//IL_0020: 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_003f: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)image == (Object)null || !((Behaviour)image).isActiveAndEnabled || (Object)(object)image.sprite == (Object)null || ((Graphic)image).color.a <= 0.01f)
			{
				return;
			}
			RectTransform rectTransform = ((Graphic)image).rectTransform;
			Rect rect = rectTransform.rect;
			if (((Rect)(ref rect)).width < 1f)
			{
				return;
			}
			rect = rectTransform.rect;
			if (!(((Rect)(ref rect)).height < 1f))
			{
				Il2CppStructArray<Vector3> val = new Il2CppStructArray<Vector3>(4L);
				rectTransform.GetWorldCorners(val);
				for (int i = 0; i < 4; i++)
				{
					area.Add(((Il2CppArrayBase<Vector3>)(object)val)[i]);
				}
			}
		}

		private static void AddLetters(TMP_Text text, ref Area area)
		{
			//IL_001f: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)text == (Object)null || !((Behaviour)text).isActiveAndEnabled || string.IsNullOrEmpty(text.text) || ((Graphic)text).color.a <= 0.01f)
			{
				return;
			}
			TMP_TextInfo textInfo = text.textInfo;
			if (textInfo == null || textInfo.characterCount == 0)
			{
				return;
			}
			Il2CppReferenceArray<TMP_CharacterInfo> characterInfo = textInfo.characterInfo;
			for (int i = 0; i < textInfo.characterCount && i < ((Il2CppArrayBase<TMP_CharacterInfo>)(object)characterInfo).Length; i++)
			{
				TMP_CharacterInfo val = ((Il2CppArrayBase<TMP_CharacterInfo>)(object)characterInfo)[i];
				if (val.isVisible)
				{
					area.Add(text.transform.TransformPoint(new Vector3(val.bottomLeft.x, Mathf.Min(val.bottomLeft.y, val.descender), 0f)));
					area.Add(text.transform.TransformPoint(new Vector3(val.topRight.x, Mathf.Max(val.topRight.y, val.ascender), 0f)));
				}
			}
		}

		private static ObjectiveDetailPanel[] FindPanels()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			List<ObjectiveDetailPanel> list = new List<ObjectiveDetailPanel>();
			foreach (ObjectiveDetailPanel item in Resources.FindObjectsOfTypeAll<ObjectiveDetailPanel>())
			{
				if ((Object)(object)item != (Object)null)
				{
					Scene scene = ((Component)item).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						list.Add(item);
					}
				}
			}
			return list.ToArray();
		}

		private static void CreateIcon(TMP_Text text, bool quiet = false)
		{
			_icon = null;
			Sprite val = MissionTimerMod.FindAsset<Sprite>("ui_stat_icon_time");
			if ((Object)(object)val == (Object)null)
			{
				if (!quiet)
				{
					Log.Msg("timer icon not loaded yet; will add it when it is");
				}
			}
			else
			{
				_icon = AddIcon(text, val);
			}
		}

		internal static Image AddIcon(TMP_Text text, Sprite sprite)
		{
			//IL_002a: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			Transform val = text.transform.Find("MissionTimer_Icon");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			RectTransform obj = new GameObject("MissionTimer_Icon").AddComponent<RectTransform>();
			((Transform)obj).SetParent(text.transform, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			obj.anchorMax = val2;
			obj.anchorMin = val2;
			obj.pivot = new Vector2(1f, 0.5f);
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = sprite;
			obj2.preserveAspect = true;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		internal static void PlaceIcon(TMP_Text label, Image icon)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)icon == (Object)null) && !((Object)(object)label == (Object)null))
			{
				label.ForceMeshUpdate(false, false);
				Bounds textBounds = label.textBounds;
				float num = label.fontSize * 0.85f;
				RectTransform rectTransform = ((Graphic)icon).rectTransform;
				rectTransform.sizeDelta = new Vector2(num, num);
				((Transform)rectTransform).localPosition = new Vector3(((Bounds)(ref textBounds)).min.x - num * 0.2f, ((Bounds)(ref textBounds)).center.y, 0f);
			}
		}

		internal static T FindAsset<T>(string name) where T : Object
		{
			foreach (T item in Resources.FindObjectsOfTypeAll<T>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == name)
				{
					return item;
				}
			}
			return default(T);
		}

		private static TMP_Text CreateLabel(RunProgressBarUI bar)
		{
			Transform val = (((Object)(object)bar.progressBar != (Object)null) ? ((Component)bar.progressBar).transform : ((Component)bar).transform);
			Transform val2 = val.Find("MissionTimer_Label");
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val2).gameObject);
			}
			TMP_Text val3 = FindTemplate(bar);
			if ((Object)(object)val3 == (Object)null)
			{
				Log.Warning("no font to copy for the mission time");
				return null;
			}
			_baseSize = 2f * ((val3.fontSize > 1f) ? Mathf.Clamp(val3.fontSize, 20f, 48f) : 32f);
			if (_hasMenu)
			{
				MenuPage.SaveBaseSize(_baseSize);
			}
			TMP_Text obj = StyleLabel(Object.Instantiate<GameObject>(((Component)val3).gameObject, val, false));
			CreateIcon(obj);
			((Component)obj).gameObject.SetActive(Enabled.Value);
			return obj;
		}

		internal static TMP_Text StyleLabel(GameObject go)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			((Object)go).name = "MissionTimer_Label";
			go.SetActive(true);
			foreach (MonoBehaviour component2 in go.GetComponents<MonoBehaviour>())
			{
				if ((Object)(object)component2 != (Object)null && (Object)(object)((Il2CppObjectBase)component2).TryCast<TMP_Text>() == (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component2);
				}
			}
			for (int num = go.transform.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)go.transform.GetChild(num)).gameObject);
			}
			TMP_Text component = go.GetComponent<TMP_Text>();
			component.text = "00:00";
			component.alignment = (TextAlignmentOptions)258;
			component.textWrappingMode = (TextWrappingModes)0;
			component.overflowMode = (TextOverflowModes)0;
			component.enableAutoSizing = false;
			((Graphic)component).raycastTarget = false;
			component.fontStyle = (FontStyles)(component.fontStyle & -3);
			TMP_FontAsset val = MissionTimerMod.FindAsset<TMP_FontAsset>("TitilliumWeb-Bold SDF");
			if ((Object)(object)val != (Object)null)
			{
				component.font = val;
				component.fontSharedMaterial = ((TMP_Asset)val).material;
			}
			else
			{
				Log.Warning("bold HUD font not found; using the copied HUD font");
			}
			((Graphic)component).color = Color.white;
			component.outlineWidth = Mathf.Max(component.outlineWidth, 0.2f);
			component.outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)200);
			RectTransform rectTransform = component.rectTransform;
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).localRotation = Quaternion.identity;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.sizeDelta = new Vector2(400f, 60f);
			rectTransform.anchoredPosition = new Vector2(0f, -16f);
			ApplySizeTo(component);
			rectTransform.sizeDelta = new Vector2(600f, _baseSize * 2f);
			return component;
		}

		private static void ApplySize()
		{
			if ((Object)(object)_label != (Object)null)
			{
				ApplySizeTo(_label);
				PlaceIcon(_label, _icon);
			}
		}

		internal static void ApplySizeTo(TMP_Text text)
		{
			text.fontSize = _baseSize * Size.Value;
		}

		internal static TMP_Text FindTemplate(RunProgressBarUI bar)
		{
			TMP_Text componentInChildren = ((Component)bar).GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				return componentInChildren;
			}
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.waveInfoText != (Object)null)
			{
				return instance.waveInfoText;
			}
			Canvas componentInParent = ((Component)bar).GetComponentInParent<Canvas>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return null;
			}
			return ((Component)componentInParent).GetComponentInChildren<TMP_Text>(true);
		}
	}
	internal static class ObjectiveMarkers
	{
		private sealed class Marker
		{
			public float Progress;

			public GameObject Line;
		}

		private const string Prefix = "MissionTimer_ObjectiveLine";

		private static readonly int[] DefaultObjectiveWaves = new int[4] { 3, 7, 11, 15 };

		private static readonly List<Marker> Markers = new List<Marker>();

		private static RunProgressBarUI _bar;

		private static Sprite _glow;

		internal static void Reset(RunProgressBarUI bar)
		{
			Clear();
			_bar = bar;
		}

		internal static void Tick()
		{
			if ((Object)(object)_bar == (Object)null)
			{
				return;
			}
			if (Markers.Count == 0)
			{
				TryBuild();
			}
			if (Markers.Count == 0)
			{
				return;
			}
			Slider progressBar = _bar.progressBar;
			float num = (((Object)(object)progressBar != (Object)null) ? progressBar.normalizedValue : 0f);
			foreach (Marker marker in Markers)
			{
				if (!((Object)(object)marker.Line == (Object)null))
				{
					bool flag = MissionTimerMod.ShowMarkers.Value && num < marker.Progress - 0.0005f;
					if (marker.Line.activeSelf != flag)
					{
						marker.Line.SetActive(flag);
					}
				}
			}
		}

		private static void TryBuild()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				RunConfiguration configuration = instance.Configuration;
				obj = ((configuration != null) ? configuration.Waves : null);
			}
			List<WaveConfiguration> val = (List<WaveConfiguration>)obj;
			Slider progressBar = _bar.progressBar;
			object obj2;
			if (!((Object)(object)progressBar != (Object)null) || !((Object)(object)progressBar.fillRect != (Object)null))
			{
				obj2 = null;
			}
			else
			{
				Transform parent = ((Transform)progressBar.fillRect).parent;
				obj2 = ((parent != null) ? ((Il2CppObjectBase)parent).TryCast<RectTransform>() : null);
			}
			RectTransform val2 = (RectTransform)obj2;
			if ((Object)(object)instance == (Object)null || val == null || val.Count == 0 || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			int count = val.Count;
			List<int> list = new List<int>();
			try
			{
				ObjectiveDeterminer objectiveDeterminer = instance.objectiveDeterminer;
				List<int> val3 = ((objectiveDeterminer != null) ? objectiveDeterminer.waveNumbersForObjectives : null);
				int num = 0;
				while (val3 != null && num < val3.Count)
				{
					list.Add(val3[num]);
					num++;
				}
			}
			catch
			{
			}
			if (list.Count == 0)
			{
				list.AddRange(DefaultObjectiveWaves);
			}
			Image component = ((Component)progressBar.fillRect).GetComponent<Image>();
			Color color = (Color)(((Object)(object)component != (Object)null) ? ((Graphic)component).color : new Color(1f, 1f, 0.95f, 1f));
			Rect rect = val2.rect;
			float barHeight = Mathf.Max(((Rect)(ref rect)).height, 10f);
			foreach (int item in list)
			{
				if (item >= 1 && item < count)
				{
					float progress = (float)(item - 1) / (float)count;
					Markers.Add(new Marker
					{
						Progress = progress,
						Line = CreateLine(val2, progress, color, barHeight, Markers.Count)
					});
				}
			}
			MissionTimerMod.Log.Msg($"objective lines at waves {string.Join(", ", list)} of {count}");
			if (MissionTimerMod.HasMenu)
			{
				MenuPage.SaveMarkers(Markers.ConvertAll((Marker m) => m.Progress).ToArray());
			}
		}

		internal static GameObject CreateLine(RectTransform fillArea, float progress, Color color, float barHeight, int index)
		{
			//IL_0011: 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_0039: 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_0055: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = new GameObject("MissionTimer_ObjectiveLine" + index).AddComponent<RectTransform>();
			((Transform)val).SetParent((Transform)(object)fillArea, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(progress, 0.5f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0.5f, 0.5f);
			val.anchoredPosition = Vector2.zero;
			float num = barHeight * 2.2f;
			val.sizeDelta = new Vector2(4f, num);
			((Graphic)NewImage("Glow", val, GlowSprite(), new Color(color.r, color.g, color.b, 0.55f))).rectTransform.sizeDelta = new Vector2(26f, num * 1.15f);
			((Graphic)NewImage("Core", val, null, new Color(color.r, color.g, color.b, 1f))).rectTransform.sizeDelta = new Vector2(4f, num);
			return ((Component)val).gameObject;
		}

		private static Image NewImage(string name, RectTransform parent, Sprite sprite, Color color)
		{
			//IL_0001: 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_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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = new GameObject(name).AddComponent<RectTransform>();
			((Transform)obj).SetParent((Transform)(object)parent, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			obj.pivot = val;
			Vector2 anchorMin = (obj.anchorMax = val);
			obj.anchorMin = anchorMin;
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = sprite;
			((Graphic)obj2).color = color;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static Sprite GlowSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0035: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_glow != (Object)null)
			{
				return _glow;
			}
			Texture2D val = new Texture2D(32, 64, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[2048];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = ((float)j + 0.5f) / 32f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
					float num3 = Mathf.Exp((0f - num) * num * 6f);
					float num4 = Mathf.Clamp01(1.3f - Mathf.Abs(num2) * 1.3f);
					byte b = (byte)(255f * Mathf.Clamp01(num3 * num4));
					array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, b);
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply();
			_glow = Sprite.Create(val, new Rect(0f, 0f, 32f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)_glow).hideFlags = (HideFlags)61;
			return _glow;
		}

		private static void Clear()
		{
			foreach (Marker marker in Markers)
			{
				if ((Object)(object)marker.Line != (Object)null)
				{
					Object.Destroy((Object)(object)marker.Line);
				}
			}
			Markers.Clear();
		}
	}
}
namespace MissionTimer.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.MissionTimer", "Mission Timer", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.MissionTimer";

		public override void Load()
		{
			MelonCompat.Start<MissionTimerMod, Runner>((BasePlugin)(object)this, "SpellBrigade.MissionTimer");
		}
	}
	public class Runner : MonoBehaviour
	{
		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			MelonCompat.Update();
		}
	}
}
namespace MelonLoader
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonInfoAttribute : Attribute
	{
		public MelonInfoAttribute(Type type, string name, string version, string author, string downloadLink = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public sealed class MelonGameAttribute : Attribute
	{
		public MelonGameAttribute(string developer = null, string name = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonOptionalDependenciesAttribute : Attribute
	{
		public MelonOptionalDependenciesAttribute(params string[] names)
		{
		}
	}
	public abstract class MelonBase
	{
		public MelonLogger.Instance LoggerInstance { get; internal set; }

		public Harmony HarmonyInstance { get; internal set; }

		public static object FindMelon(string name, string author)
		{
			try
			{
				foreach (PluginInfo value in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Values)
				{
					if (((value != null) ? value.Metadata : null) != null && string.Equals(value.Metadata.Name, name, StringComparison.OrdinalIgnoreCase) && value.Instance != null)
					{
						return value;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	public abstract class MelonMod : MelonBase
	{
		public virtual void OnInitializeMelon()
		{
		}

		public virtual void OnLateInitializeMelon()
		{
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnLateUpdate()
		{
		}

		public virtual void OnFixedUpdate()
		{
		}

		public virtual void OnGUI()
		{
		}

		public virtual void OnApplicationQuit()
		{
		}

		public virtual void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
		}
	}
	public static class MelonLogger
	{
		public sealed class Instance
		{
			private readonly ManualLogSource _log;

			public Instance(ManualLogSource log)
			{
				_log = log;
			}

			public void Msg(string text)
			{
				_log.LogInfo((object)text);
			}

			public void Msg(object value)
			{
				_log.LogInfo(value);
			}

			public void Msg(string format, params object[] args)
			{
				_log.LogInfo((object)string.Format(format, args));
			}

			public void Warning(string text)
			{
				_log.LogWarning((object)text);
			}

			public void Warning(object value)
			{
				_log.LogWarning(value);
			}

			public void Error(string text)
			{
				_log.LogError((object)text);
			}

			public void Error(object value)
			{
				_log.LogError(value);
			}

			public void Error(string text, Exception e)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e);
				}
				log.LogError(val);
			}
		}
	}
	public static class MelonCompat
	{
		internal static ConfigFile Config;

		private static MelonMod _mod;

		private static bool _lateInit;

		public static void Start<TMod, TRunner>(BasePlugin plugin, string harmonyId) where TMod : MelonMod, new() where TRunner : MonoBehaviour
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Config = plugin.Config;
			_mod = new TMod
			{
				LoggerInstance = new MelonLogger.Instance(plugin.Log),
				HarmonyInstance = new Harmony(harmonyId)
			};
			try
			{
				_mod.HarmonyInstance.PatchAll(typeof(TMod).Assembly);
			}
			catch (Exception ex)
			{
				ManualLogSource log = plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patches: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_mod.OnInitializeMelon();
			HookScenes();
			ClassInjector.RegisterTypeInIl2Cpp<TRunner>();
			plugin.AddComponent<TRunner>();
		}

		private static void HookScenes()
		{
			SceneManager.sceneLoaded += DelegateSupport.ConvertDelegate<UnityAction<Scene, LoadSceneMode>>((Delegate)new Action<Scene, LoadSceneMode>(OnSceneLoaded));
			SceneManager.sceneUnloaded += DelegateSupport.ConvertDelegate<UnityAction<Scene>>((Delegate)new Action<Scene>(OnSceneUnloaded));
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasLoaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
			Guard(delegate
			{
				_mod.OnSceneWasInitialized(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		private static void OnSceneUnloaded(Scene scene)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasUnloaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		public static void Update()
		{
			if (_mod != null)
			{
				if (!_lateInit)
				{
					_lateInit = true;
					Guard(_mod.OnLateInitializeMelon);
				}
				_mod.OnUpdate();
			}
		}

		public static void LateUpdate()
		{
			_mod?.OnLateUpdate();
		}

		public static void FixedUpdate()
		{
			_mod?.OnFixedUpdate();
		}

		public static void OnGUI()
		{
			_mod?.OnGUI();
		}

		public static void Quit()
		{
			_mod?.OnApplicationQuit();
		}

		private static void Guard(Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				_mod.LoggerInstance.Error(ex.ToString());
			}
		}
	}
	public static class MelonPreferences
	{
		private static readonly Dictionary<string, MelonPreferences_Category> Categories = new Dictionary<string, MelonPreferences_Category>();

		public static MelonPreferences_Category CreateCategory(string identifier, string displayName = null, bool is_hidden = false, bool is_inlined = false)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				value = (Categories[identifier] = new MelonPreferences_Category(identifier, displayName ?? identifier)
				{
					IsHidden = is_hidden
				});
			}
			return value;
		}

		public static MelonPreferences_Category GetCategory(string identifier)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Save()
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}
	}
	public sealed class MelonPreferences_Category
	{
		public readonly List<MelonPreferences_Entry> Entries = new List<MelonPreferences_Entry>();

		public string Identifier { get; }

		public string DisplayName { get; }

		public bool IsHidden { get; internal set; }

		internal MelonPreferences_Category(string identifier, string displayName)
		{
			Identifier = identifier;
			DisplayName = displayName;
		}

		public MelonPreferences_Entry<T> CreateEntry<T>(string identifier, T default_value, string display_name = null, string description = null, bool is_hidden = false, bool dont_save_default = false, ValueValidator validator = null, string oldIdentifier = null)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				DispName = (display_name ?? identifier),
				Browsable = (!is_hidden && !IsHidden),
				Order = -Entries.Count,
				Category = DisplayName
			};
			AcceptableValueBase val = validator?.ToAcceptable(typeof(T));
			ConfigEntry<T> cfg = MelonCompat.Config.Bind<T>(Identifier, identifier, default_value, new ConfigDescription(description ?? "", val, new object[1] { configurationManagerAttributes }));
			MelonPreferences_Entry<T> melonPreferences_Entry = new MelonPreferences_Entry<T>(this, cfg, identifier, display_name ?? identifier, description, is_hidden);
			Entries.Add(melonPreferences_Entry);
			return melonPreferences_Entry;
		}

		public MelonPreferences_Entry GetEntry(string identifier)
		{
			return Entries.Find((MelonPreferences_Entry e) => e.Identifier == identifier);
		}

		public MelonPreferences_Entry<T> GetEntry<T>(string identifier)
		{
			return GetEntry(identifier) as MelonPreferences_Entry<T>;
		}

		public bool HasEntry(string identifier)
		{
			return GetEntry(identifier) != null;
		}

		public void SaveToFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}

		public void LoadFromFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Reload();
			}
		}
	}
	public abstract class MelonPreferences_Entry
	{
		public readonly MelonEvent<object, object> OnEntryValueChangedUntyped = new MelonEvent<object, object>();

		public MelonPreferences_Category Category { get; protected set; }

		public string Identifier { get; protected set; }

		public string DisplayName { get; protected set; }

		public string Description { get; protected set; }

		public bool IsHidden { get; protected set; }

		public abstract ConfigEntryBase Raw { get; }

		public abstract object BoxedValue { get; set; }

		public abstract void ResetToDefault();
	}
	public sealed class MelonPreferences_Entry<T> : MelonPreferences_Entry
	{
		private readonly ConfigEntry<T> _cfg;

		private T _last;

		public readonly MelonEvent<T, T> OnEntryValueChanged = new MelonEvent<T, T>();

		public readonly MelonEvent<T, T> OnValueChanged;

		public T Value
		{
			get
			{
				return _cfg.Value;
			}
			set
			{
				_cfg.Value = value;
			}
		}

		public T DefaultValue => (T)((ConfigEntryBase)_cfg).DefaultValue;

		public override ConfigEntryBase Raw => (ConfigEntryBase)(object)_cfg;

		public override object BoxedValue
		{
			get
			{
				return ((ConfigEntryBase)_cfg).BoxedValue;
			}
			set
			{
				((ConfigEntryBase)_cfg).BoxedValue = value;
			}
		}

		internal MelonPreferences_Entry(MelonPreferences_Category category, ConfigEntry<T> cfg, string identifier, string displayName, string description, bool hidden)
		{
			base.Category = category;
			_cfg = cfg;
			base.Identifier = identifier;
			base.DisplayName = displayName;
			base.Description = description;
			base.IsHidden = hidden;
			OnValueChanged = OnEntryValueChanged;
			_last = cfg.Value;
			cfg.SettingChanged += OnSettingChanged;
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			T last = _last;
			_last = _cfg.Value;
			if (!EqualityComparer<T>.Default.Equals(last, _last))
			{
				OnEntryValueChanged.Invoke(last, _last);
				OnEntryValueChangedUntyped.Invoke(last, _last);
			}
		}

		public override void ResetToDefault()
		{
			_cfg.Value = DefaultValue;
		}
	}
	public sealed class MelonEvent<T1, T2>
	{
		private readonly List<Action<T1, T2>> _handlers = new List<Action<T1, T2>>();

		public void Subscribe(Action<T1, T2> handler, int priority = 0, bool unsubscribeOnFirstInvocation = false)
		{
			_handlers.Add(handler);
		}

		public void Unsubscribe(Action<T1, T2> handler)
		{
			_handlers.Remove(handler);
		}

		internal void Invoke(T1 a, T2 b)
		{
			Action<T1, T2>[] array = _handlers.ToArray();
			foreach (Action<T1, T2> action in array)
			{
				try
				{
					action(a, b);
				}
				catch (Exception ex)
				{
					Debug.LogError(Object.op_Implicit(ex.ToString()));
				}
			}
		}
	}
	public sealed class ConfigurationManagerAttributes
	{
		public string DispName;

		public bool? Browsable;

		public int? Order;

		public string Category;
	}
}
namespace MelonLoader.Preferences
{
	public abstract class ValueValidator
	{
		public abstract AcceptableValueBase ToAcceptable(Type type);
	}
	public sealed class ValueRange<T> : ValueValidator where T : IComparable
	{
		public T MinValue { get; }

		public T MaxValue { get; }

		public ValueRange(T min, T max)
		{
			MinValue = min;
			MaxValue = max;
		}

		public override AcceptableValueBase ToAcceptable(Type type)
		{
			if (!(type == typeof(T)))
			{
				return null;
			}
			return (AcceptableValueBase)(object)new AcceptableValueRange<T>(MinValue, MaxValue);
		}
	}
}
namespace Il2CppTMPro
{
	internal static class NamespaceStandIn
	{
	}
}
namespace Il2Cpp
{
	internal static class NamespaceStandIn
	{
	}
}