Decompiled source of Scroll Counter v1.0.0

ScrollCounter.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 ScrollCounter;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
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(ScrollCounterMod), "Scroll Counter", "1.0.0", "Scroll Counter", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: MelonOptionalDependencies(new string[] { "BrigadeModMenu" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ScrollCounter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScrollCounter")]
[assembly: AssemblyTitle("ScrollCounter")]
[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 ScrollCounter
{
	internal static class HostInfo
	{
		private const string Message = "ScrollCounter.Host";

		private const ChallengeId Quest1 = (ChallengeId)110;

		private const ChallengeId Quest2 = (ChallengeId)111;

		private const ChallengeId QuestRepeat = (ChallengeId)112;

		private static IntPtr _messaging;

		private static float _nextSend;

		private static float _nextFail;

		private static HandleNamedMessageDelegate _handler;

		internal static bool Known { get; private set; }

		internal static bool HostQuest1 { get; private set; }

		internal static bool HostQuest2 { get; private set; }

		internal static bool HostQuestRepeat { get; private set; }

		internal static int HostSpawned { get; private set; }

		internal static void Reset()
		{
			Known = false;
			HostSpawned = 0;
		}

		internal static void Tick()
		{
			if (Time.unscaledTime < _nextFail)
			{
				return;
			}
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				bool flag = (Object)(object)singleton != (Object)null && singleton.IsListening;
				if (!flag || singleton.IsServer)
				{
					ReadLocal();
					if (flag)
					{
						Share(singleton);
					}
				}
				else
				{
					Listen(singleton);
				}
			}
			catch (Exception ex)
			{
				ScrollCounterMod.Log.Warning("host info: " + ex.Message);
				_nextFail = Time.unscaledTime + 5f;
			}
		}

		private static void ReadLocal()
		{
			LocalPlayer instance = SingletonPersistent<LocalPlayer>.Instance;
			ChallengeManager val = ((instance != null) ? instance.GetChallengeManager() : null);
			if (val != null)
			{
				HostQuest1 = val.IsCompleted((ChallengeId)110);
				HostQuest2 = val.IsCompleted((ChallengeId)111);
				HostQuestRepeat = val.IsCompleted((ChallengeId)112);
				ArtifactManager instance2 = NetworkSingleton<ArtifactManager>.Instance;
				HostSpawned = (((Object)(object)instance2 != (Object)null) ? instance2.GetAmountOfSpawnedArtifacts() : 0);
				Known = true;
			}
		}

		private static void Share(NetworkManager nm)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextSend)
			{
				return;
			}
			_nextSend = Time.unscaledTime + 2f;
			CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
			if (customMessagingManager == null)
			{
				return;
			}
			Il2CppStructArray<byte> val = new Il2CppStructArray<byte>(4L);
			((Il2CppArrayBase<byte>)(object)val)[0] = (HostQuest1 ? ((byte)1) : ((byte)0));
			((Il2CppArrayBase<byte>)(object)val)[1] = (HostQuest2 ? ((byte)1) : ((byte)0));
			((Il2CppArrayBase<byte>)(object)val)[2] = (HostQuestRepeat ? ((byte)1) : ((byte)0));
			((Il2CppArrayBase<byte>)(object)val)[3] = (byte)Mathf.Clamp(HostSpawned, 0, 255);
			FastBufferWriter val2 = default(FastBufferWriter);
			((FastBufferWriter)(ref val2))..ctor(4, (Allocator)2, 4);
			try
			{
				((FastBufferWriter)(ref val2)).WriteBytesSafe(val, 4, 0);
				customMessagingManager.SendNamedMessageToAll("ScrollCounter.Host", val2, (NetworkDelivery)2);
			}
			finally
			{
				((FastBufferWriter)(ref val2)).Dispose();
			}
		}

		private static void Listen(NetworkManager nm)
		{
			CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
			if (customMessagingManager != null && !(((Il2CppObjectBase)customMessagingManager).Pointer == _messaging))
			{
				if (_handler == null)
				{
					_handler = DelegateSupport.ConvertDelegate<HandleNamedMessageDelegate>((Delegate)new Action<ulong, FastBufferReader>(OnMessage));
				}
				customMessagingManager.RegisterNamedMessageHandler("ScrollCounter.Host", _handler);
				_messaging = ((Il2CppObjectBase)customMessagingManager).Pointer;
				Known = false;
			}
		}

		private static void OnMessage(ulong sender, FastBufferReader reader)
		{
			try
			{
				if (((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position >= 4)
				{
					Il2CppStructArray<byte> val = new Il2CppStructArray<byte>(4L);
					((FastBufferReader)(ref reader)).ReadBytesSafe(ref val, 4, 0);
					HostQuest1 = ((Il2CppArrayBase<byte>)(object)val)[0] != 0;
					HostQuest2 = ((Il2CppArrayBase<byte>)(object)val)[1] != 0;
					HostQuestRepeat = ((Il2CppArrayBase<byte>)(object)val)[2] != 0;
					HostSpawned = ((Il2CppArrayBase<byte>)(object)val)[3];
					Known = true;
				}
			}
			catch (Exception ex)
			{
				ScrollCounterMod.Log.Warning("host info message: " + ex.Message);
			}
		}
	}
	internal static class MenuPage
	{
		private static readonly HudElement Element = new HudElement
		{
			Name = "Scroll Counter",
			Build = delegate(RectTransform parent)
			{
				Image icon;
				TMP_Text text;
				RectTransform result = ScrollCounterMod.BuildCounter((Transform)(object)parent, out icon, out text);
				text.text = "1-2";
				Sprite val = HudEditor.Sprite("ui_ping_artifact");
				if ((Object)(object)val != (Object)null)
				{
					icon.sprite = val;
					((Behaviour)icon).enabled = true;
				}
				return result;
			},
			Place = delegate(RectTransform root)
			{
				ScrollCounterMod.PlaceCounter(root);
			},
			Live = ScrollCounterMod.LiveCounter,
			GetOffset = () => new Vector2(ScrollCounterMod.OffsetX.Value, ScrollCounterMod.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)
				ScrollCounterMod.OffsetX.Value = Mathf.Clamp(v.x, -5000f, 0f);
				ScrollCounterMod.OffsetY.Value = Mathf.Clamp(v.y, 0f, 2000f);
			},
			GetSize = () => ScrollCounterMod.Size.Value,
			SetSize = delegate(float s)
			{
				ScrollCounterMod.Size.Value = s;
			},
			Reset = delegate
			{
				ScrollCounterMod.OffsetX.Value = 0f;
				ScrollCounterMod.OffsetY.Value = 0f;
				ScrollCounterMod.Size.Value = 1f;
			}
		};

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			HudEditor.RecordSprites(new string[1] { "ui_ping_artifact" });
			HudEditor.Register(Element);
			Menu.AddPage("ScrollCounter", "Scroll Counter").Entry(ScrollCounterMod.Enabled, () => "Show Scroll Counter").Entry(ScrollCounterMod.ShowExact, () => "Show Exact Count")
				.Entry(ScrollCounterMod.HideWhenNone, () => "Hide When None")
				.Buttons((MenuButton[])(object)new MenuButton[1]
				{
					new MenuButton("Edit Position & Size", (Action)delegate
					{
						HudEditor.Open(Element);
					}, false)
				})
				.Entry(ScrollCounterMod.Size, () => "Size")
				.Entry(ScrollCounterMod.OffsetX, () => "Move Left / Right")
				.Entry(ScrollCounterMod.OffsetY, () => "Move Up / Down");
		}
	}
	public class ScrollCounterMod : MelonMod
	{
		private sealed class ChestEvent
		{
			public RunEvent Event;

			public bool Repeating;

			public bool Fired;

			public int FiredCycle = -1;

			public bool WindowPassed;

			public bool NotAllowed;

			public float Min => Event.minStartTime;

			public float Max => Event.maxStartTime;

			public bool Random => Event.maxStartTime > Event.minStartTime;

			public string Label => $"{(Repeating ? "repeating" : "timed")} {Event.minStartTime}-{Event.maxStartTime}s";
		}

		internal static MelonLogger.Instance Log;

		internal static MelonPreferences_Entry<bool> Enabled;

		internal static MelonPreferences_Entry<bool> HideWhenNone;

		internal static MelonPreferences_Entry<bool> ShowExact;

		internal static MelonPreferences_Entry<float> Size;

		internal static MelonPreferences_Entry<float> OffsetX;

		internal static MelonPreferences_Entry<float> OffsetY;

		private const float CheckEvery = 0.25f;

		private RectTransform _root;

		private static ScrollCounterMod _instance;

		private static float _editingUntil;

		private TMP_Text _text;

		private Image _icon;

		private float _nextCheck;

		private float _nextSearch;

		private float _retryAt;

		private string _lastError;

		private IntPtr _runPtr;

		private int _cycle = -1;

		private readonly HashSet<IntPtr> _seenChests = new HashSet<IntPtr>();

		private readonly HashSet<IntPtr> _windowChests = new HashSet<IntPtr>();

		private List<ChestEvent> _events;

		private const float AboveBar = 130f;

		internal static RectTransform LiveCounter()
		{
			ScrollCounterMod instance = _instance;
			if (instance == null || !instance.EnsureUi())
			{
				return null;
			}
			_editingUntil = Time.unscaledTime + 0.3f;
			instance.Show(on: true);
			if (string.IsNullOrEmpty(instance._text.text))
			{
				instance._text.text = "0";
			}
			PlaceCounter(instance._root);
			return instance._root;
		}

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			_instance = this;
			MelonPreferences_Category melonPreferences_Category = MelonPreferences.CreateCategory("ScrollCounter", "Scroll Counter");
			Enabled = melonPreferences_Category.CreateEntry("Enabled", default_value: true, "Show Scroll Counter", "How many scrolls are waiting on the map (a range while a chest may be spawning)");
			ShowExact = melonPreferences_Category.CreateEntry("ShowExact", default_value: false, "Show Exact Count", "Show the exact number, going up the moment a chest spawns, instead of a range while a chest may spawn");
			HideWhenNone = melonPreferences_Category.CreateEntry("HideWhenNone", default_value: false, "Hide When None", "Hide the counter while there are no scrolls on the map and none can spawn");
			Size = melonPreferences_Category.CreateEntry("Size", 1f, "Size", "Size of the counter", is_hidden: false, dont_save_default: false, new ValueRange<float>(0.5f, 2f));
			OffsetX = melonPreferences_Category.CreateEntry("OffsetX", 0f, "Move Left / Right", "Move the counter left (negative) or right (positive) of the bottom-right corner", is_hidden: false, dont_save_default: false, new ValueRange<float>(-5000f, 0f));
			OffsetY = melonPreferences_Category.CreateEntry("OffsetUp", 0f, "Move Up / Down", "Move the counter up from just above the bottom bar", is_hidden: false, dont_save_default: false, new ValueRange<float>(0f, 2000f));
			if (Array.Exists(AppDomain.CurrentDomain.GetAssemblies(), (Assembly a) => a.GetName().Name == "BrigadeModMenu"))
			{
				try
				{
					RegisterMenu();
				}
				catch (Exception ex)
				{
					Log.Warning("Mod Menu page: " + ex.Message);
				}
			}
			Log.Msg("ready");
		}

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

		public override void OnUpdate()
		{
			if (Time.unscaledTime < _retryAt || Time.unscaledTime < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.unscaledTime + 0.25f;
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				string name = ex.GetType().Name;
				string? stackTrace = ex.StackTrace;
				string text = name + ((stackTrace != null) ? stackTrace.Split('\n')[0] : null);
				if (_lastError != text)
				{
					_lastError = text;
					Log.Error($"scroll counter: {ex}");
				}
				_retryAt = Time.unscaledTime + 3f;
				Show(on: false);
			}
		}

		private void Tick()
		{
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			if (!Enabled.Value || (Object)(object)instance == (Object)null || !instance.runHasStarted)
			{
				Show(on: false);
				if ((Object)(object)instance == (Object)null)
				{
					_runPtr = IntPtr.Zero;
				}
				return;
			}
			if (((Il2CppObjectBase)instance).Pointer != _runPtr)
			{
				_runPtr = ((Il2CppObjectBase)instance).Pointer;
				_cycle = -1;
				_seenChests.Clear();
				_windowChests.Clear();
				HostInfo.Reset();
				_events = null;
			}
			FindEvents();
			int currentCycle = instance.GetCurrentCycle();
			float currentCycleTimeInSeconds = instance.GetCurrentCycleTimeInSeconds();
			HostInfo.Tick();
			if (currentCycle != _cycle)
			{
				foreach (ChestEvent @event in _events)
				{
					if (@event.Repeating)
					{
						if (_cycle > 0 && RepeatCycle(_cycle) && !@event.Fired && @event.WindowPassed && !HostInfo.Known)
						{
							@event.NotAllowed = true;
						}
						@event.Fired = false;
						@event.WindowPassed = false;
					}
				}
				_cycle = currentCycle;
				_windowChests.Clear();
			}
			foreach (ChestEvent event2 in _events)
			{
				if (event2.Repeating && currentCycleTimeInSeconds > event2.Max + 1f)
				{
					event2.WindowPassed = true;
				}
			}
			int num = 0;
			int num2 = 0;
			bool flag = false;
			foreach (ChestEvent event3 in _events)
			{
				if (WindowOpen(event3, currentCycle, currentCycleTimeInSeconds))
				{
					flag = true;
				}
			}
			foreach (ArtifactChestWithPickup item in Object.FindObjectsOfType<ArtifactChestWithPickup>())
			{
				if (!((Object)(object)item == (Object)null) && ((Component)item).gameObject.activeInHierarchy && !item.hasBeenPickedUp)
				{
					num++;
					if (_seenChests.Add(((Il2CppObjectBase)item).Pointer))
					{
						OnNewChest(((Il2CppObjectBase)item).Pointer, currentCycle, currentCycleTimeInSeconds);
					}
					if (_windowChests.Contains(((Il2CppObjectBase)item).Pointer))
					{
						num2++;
					}
				}
			}
			if (!flag)
			{
				_windowChests.Clear();
			}
			string text;
			if (ShowExact.Value)
			{
				text = num.ToString();
			}
			else
			{
				int num3 = 0;
				foreach (ChestEvent event4 in _events)
				{
					if (WindowOpen(event4, currentCycle, currentCycleTimeInSeconds) && (event4.Fired || Eligible(event4)))
					{
						num3++;
					}
				}
				int num4 = num - num2;
				text = ((num3 > 0) ? $"{num4}-{num4 + num3}" : num.ToString());
			}
			if (HideWhenNone.Value && text == "0")
			{
				Show(on: false);
			}
			else if (EnsureUi())
			{
				Show(on: true);
				_text.text = text;
				Place();
			}
		}

		private static bool WindowOpen(ChestEvent e, int cycle, float t)
		{
			if (!e.Random || t < e.Min || t > e.Max + 1f)
			{
				return false;
			}
			if (e.Repeating)
			{
				return RepeatCycle(cycle);
			}
			if (e.Fired)
			{
				return e.FiredCycle == cycle;
			}
			return true;
		}

		private void OnNewChest(IntPtr chest, int cycle, float t)
		{
			bool flag = false;
			foreach (ChestEvent @event in _events)
			{
				if (WindowOpen(@event, cycle, t))
				{
					flag = true;
					if (!@event.Fired)
					{
						@event.Fired = true;
						@event.FiredCycle = cycle;
						_windowChests.Add(chest);
						return;
					}
				}
			}
			if (flag)
			{
				_windowChests.Add(chest);
				return;
			}
			foreach (ChestEvent event2 in _events)
			{
				if (!event2.Fired && !event2.Repeating && !event2.Random && !(t < event2.Min - 1f))
				{
					event2.Fired = true;
					event2.FiredCycle = cycle;
					break;
				}
			}
		}

		private static bool Eligible(ChestEvent e)
		{
			if (e.Repeating)
			{
				if (!HostInfo.Known)
				{
					return !e.NotAllowed;
				}
				return HostInfo.HostQuestRepeat;
			}
			if (!HostInfo.Known)
			{
				return true;
			}
			int hostSpawned = HostInfo.HostSpawned;
			if (hostSpawned != 0 && (hostSpawned != 1 || !HostInfo.HostQuest1))
			{
				if (hostSpawned == 2)
				{
					return HostInfo.HostQuest2;
				}
				return false;
			}
			return true;
		}

		private static bool RepeatCycle(int cycle)
		{
			if (cycle > 1)
			{
				return (cycle & (cycle - 1)) == 0;
			}
			return false;
		}

		private void FindEvents()
		{
			if (_events != null)
			{
				return;
			}
			List<ChestEvent> found = new List<ChestEvent>();
			HashSet<IntPtr> seen = new HashSet<IntPtr>();
			try
			{
				List<RunEvent> val = RunEventRepository.Get();
				int num = 0;
				while (val != null && num < val.Count)
				{
					Add(val[num]);
					num++;
				}
			}
			catch (Exception ex)
			{
				Log.Warning("run events: " + ex.Message);
			}
			foreach (ArtifactRunEvent item in Resources.FindObjectsOfTypeAll<ArtifactRunEvent>())
			{
				Add((RunEvent)(object)item);
			}
			foreach (RepeatingArtifactRunEvent item2 in Resources.FindObjectsOfTypeAll<RepeatingArtifactRunEvent>())
			{
				Add((RunEvent)(object)item2);
			}
			_events = found;
			Log.Msg("scroll chest events: " + ((found.Count == 0) ? "none found" : string.Join(", ", found.ConvertAll((ChestEvent e) => e.Label))));
			void Add(RunEvent ev)
			{
				if (!((Object)(object)ev == (Object)null) && seen.Add(((Il2CppObjectBase)ev).Pointer))
				{
					if ((Object)(object)((Il2CppObjectBase)ev).TryCast<RepeatingArtifactRunEvent>() != (Object)null)
					{
						found.Add(new ChestEvent
						{
							Event = ev,
							Repeating = true
						});
					}
					else if ((Object)(object)((Il2CppObjectBase)ev).TryCast<ArtifactRunEvent>() != (Object)null)
					{
						found.Add(new ChestEvent
						{
							Event = ev
						});
					}
				}
			}
		}

		private void Show(bool on)
		{
			if ((on || !(Time.unscaledTime < _editingUntil)) && (Object)(object)_root != (Object)null && !((Il2CppObjectBase)_root).WasCollected && ((Component)_root).gameObject.activeSelf != on)
			{
				((Component)_root).gameObject.SetActive(on);
			}
		}

		private bool EnsureUi()
		{
			if ((Object)(object)_root != (Object)null && !((Il2CppObjectBase)_root).WasCollected)
			{
				return true;
			}
			_root = null;
			if (Time.unscaledTime < _nextSearch)
			{
				return false;
			}
			_nextSearch = Time.unscaledTime + 1f;
			Canvas val = null;
			foreach (SpellSlotsDisplay item in Object.FindObjectsOfType<SpellSlotsDisplay>())
			{
				Canvas componentInParent = ((Component)item).GetComponentInParent<Canvas>();
				val = ((componentInParent != null) ? componentInParent.rootCanvas : null);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_root = BuildCounter(((Component)val).transform, out _icon, out _text);
			return true;
		}

		internal static RectTransform BuildCounter(Transform parent, out Image icon, out TMP_Text text)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = new GameObject("ScrollCounter").AddComponent<RectTransform>();
			((Transform)val).SetParent(parent, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(1f, 0f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(1f, 0f);
			val.sizeDelta = new Vector2(260f, 110f);
			RectTransform val3 = new GameObject("Icon").AddComponent<RectTransform>();
			((Transform)val3).SetParent((Transform)(object)val, false);
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(1f, 0.5f);
			val3.pivot = val4;
			val2 = (val3.anchorMin = (val3.anchorMax = val4));
			val3.sizeDelta = new Vector2(100f, 100f);
			val3.anchoredPosition = Vector2.zero;
			icon = ((Component)val3).gameObject.AddComponent<Image>();
			icon.sprite = FindSprite("ui_ping_artifact") ?? FindSprite("ui_reward_artifact_chest");
			icon.preserveAspect = true;
			((Graphic)icon).raycastTarget = false;
			((Behaviour)icon).enabled = (Object)(object)icon.sprite != (Object)null;
			RectTransform val7 = new GameObject("Count").AddComponent<RectTransform>();
			((Transform)val7).SetParent((Transform)(object)val, false);
			((Vector2)(ref val4))..ctor(1f, 0.5f);
			val7.pivot = val4;
			val2 = (val7.anchorMin = (val7.anchorMax = val4));
			val7.sizeDelta = new Vector2(220f, 100f);
			val7.anchoredPosition = new Vector2(-110f, 0f);
			text = (TMP_Text)(object)((Component)val7).gameObject.AddComponent<TextMeshProUGUI>();
			TMP_FontAsset val10 = FindFont("IrishGrover-Regular SDF") ?? FindFont("TitilliumWeb-Bold SDF");
			if ((Object)(object)val10 != (Object)null)
			{
				text.font = val10;
				text.fontSharedMaterial = ((TMP_Asset)val10).material;
			}
			text.fontSize = 72f;
			text.alignment = (TextAlignmentOptions)516;
			text.textWrappingMode = (TextWrappingModes)0;
			text.overflowMode = (TextOverflowModes)0;
			((Graphic)text).color = Color.white;
			text.outlineWidth = 0.2f;
			text.outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)200);
			((Graphic)text).raycastTarget = false;
			return val;
		}

		private void Place()
		{
			PlaceCounter(_root);
		}

		internal static void PlaceCounter(RectTransform root)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			float value = Size.Value;
			((Transform)root).localScale = new Vector3(value, value, 1f);
			root.anchoredPosition = new Vector2(-50f + OffsetX.Value, 130f + OffsetY.Value);
		}

		private static Sprite FindSprite(string name)
		{
			foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == name)
				{
					return item;
				}
			}
			return null;
		}

		private static TMP_FontAsset FindFont(string name)
		{
			foreach (TMP_FontAsset item in Resources.FindObjectsOfTypeAll<TMP_FontAsset>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == name)
				{
					return item;
				}
			}
			return null;
		}
	}
}
namespace ScrollCounter.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.ScrollCounter", "Scroll Counter", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.ScrollCounter";

		public override void Load()
		{
			MelonCompat.Start<ScrollCounterMod, Runner>((BasePlugin)(object)this, "SpellBrigade.ScrollCounter");
		}
	}
	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
	{
	}
}