Decompiled source of ExperienceBar Mono v1.0.1

Mods/ExperienceBar_Mono.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using ExperienceBar;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ScheduleOne.DevUtilities;
using ScheduleOne.Levelling;
using ScheduleOne.UI;
using ScheduleOne.UI.Phone;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "ExperienceBar", "1.0.1", "j0ckinjz", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyMetadata("NexusModID", "1002")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ExperienceBar_Mono")]
[assembly: AssemblyConfiguration("MONO")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExperienceBar_Mono")]
[assembly: AssemblyTitle("ExperienceBar_Mono")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExperienceBar
{
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <Init>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Core <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Init>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)Singleton<HUD>.Instance == (Object)null || (Object)(object)NetworkSingleton<LevelManager>.Instance == (Object)null || (Object)(object)Singleton<HUD>.Instance.canvasRect == (Object)null)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				<>4__this.xpBar = new XPBar();
				<>4__this.xpBar.Init((Transform)(object)Singleton<HUD>.Instance.canvasRect);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private XPBar xpBar;

		private float lastXP = -1f;

		private float lastMaxXP = -1f;

		public override void OnInitializeMelon()
		{
			Prefs.Init();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				Log.Msg("Mod Initialized. Version " + ((MelonBase)this).Info.Version);
				MelonCoroutines.Start(Init());
			}
		}

		[IteratorStateMachine(typeof(<Init>d__5))]
		private IEnumerator Init()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Init>d__5(0)
			{
				<>4__this = this
			};
		}

		public override void OnUpdate()
		{
			Phone instance = PlayerSingleton<Phone>.Instance;
			bool phoneOpen = instance != null && instance.IsOpen;
			if (xpBar == null)
			{
				return;
			}
			LevelManager instance2 = NetworkSingleton<LevelManager>.Instance;
			if (instance2 != null)
			{
				float num = instance2.XP;
				float xPToNextTier = instance2.XPToNextTier;
				if (num != lastXP || xPToNextTier != lastMaxXP)
				{
					lastXP = num;
					lastMaxXP = xPToNextTier;
					xpBar.UpdateXP(num, xPToNextTier);
				}
				xpBar.Update(phoneOpen);
			}
		}
	}
	internal static class Log
	{
		public static void Msg(string msg)
		{
			Melon<Core>.Logger.Msg(msg);
		}

		public static void Warn(string warn)
		{
			Melon<Core>.Logger.Warning(warn);
		}

		public static void Error(string error)
		{
			Melon<Core>.Logger.Error(error);
		}
	}
	public static class Prefs
	{
		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<bool> FadeBar;

		public static MelonPreferences_Entry<bool> FadeRank;

		public static void Init()
		{
			Category = MelonPreferences.CreateCategory("ExperienceBar_ExperienceBar", "Experience Bar");
			FadeBar = Category.CreateEntry<bool>("FadeBar", true, "Fade XP Bar", "Fade out the XP bar after inactivity", false, false, (ValueValidator)null, (string)null);
			FadeRank = Category.CreateEntry<bool>("FadeRank", true, "Fade Rank / XP Text", "Fade out the rank text after inactivity", false, false, (ValueValidator)null, (string)null);
		}
	}
	public class XPBar
	{
		private GameObject _barGO;

		private Slider _slider;

		private Image _fillImage;

		private TextMeshProUGUI _xpText;

		private TextMeshProUGUI _rankText;

		private CanvasGroup _textGroup;

		private string _lastRankDisplay = "";

		private float _lastXPUpdateTime;

		private float _currentFill = 0f;

		private const float FadeDelay = 3f;

		private const float FadeSpeed = 2f;

		private const float LerpSpeed = 5f;

		private const float BarHeight = 2f;

		private const float BarOffsetY = 8f;

		private const float LabelX = 5f;

		private const float RankY = 38f;

		private const float XPY = 20f;

		private const float LabelWidth = 400f;

		private const float LabelHeight = 20f;

		private const int FontSize = 16;

		private bool _lastPhoneOpen = false;

		private float _pauseStartTime = 0f;

		private float _pauseAccumulated = 0f;

		public void Init(Transform hudCanvas)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0058: 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_0084: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			_barGO = new GameObject("ExperienceBar");
			_barGO.transform.SetParent(hudCanvas, false);
			_barGO.AddComponent<RectTransform>();
			_slider = _barGO.AddComponent<Slider>();
			RectTransform component = _barGO.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 0f);
			component.anchoredPosition = new Vector2(0f, 8f);
			component.sizeDelta = new Vector2(0f, 2f);
			_slider.minValue = 0f;
			_slider.maxValue = 1f;
			_slider.value = 0f;
			GameObject val = new GameObject("Fill");
			val.transform.SetParent(_barGO.transform, false);
			val.AddComponent<RectTransform>();
			_fillImage = val.AddComponent<Image>();
			((Graphic)_fillImage).color = Color.green;
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			_slider.fillRect = component2;
			GameObject val2 = new GameObject("TextGroup");
			val2.transform.SetParent(_barGO.transform, false);
			_textGroup = val2.AddComponent<CanvasGroup>();
			RectTransform val3 = val2.AddComponent<RectTransform>();
			val3.anchorMin = new Vector2(0f, 1f);
			val3.anchorMax = new Vector2(0f, 1f);
			val3.pivot = new Vector2(0f, 1f);
			val3.anchoredPosition = new Vector2(0f, 0f);
			val3.sizeDelta = new Vector2(0f, 0f);
			GameObject val4 = new GameObject("RankText");
			val4.transform.SetParent(val2.transform, false);
			RectTransform val5 = val4.AddComponent<RectTransform>();
			val5.anchorMin = new Vector2(0f, 1f);
			val5.anchorMax = new Vector2(0f, 1f);
			val5.pivot = new Vector2(0f, 1f);
			val5.anchoredPosition = new Vector2(5f, 38f);
			val5.sizeDelta = new Vector2(400f, 20f);
			_rankText = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_rankText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)_rankText).fontSize = 16f;
			ApplyTextShadow(_rankText);
			GameObject val6 = new GameObject("XPText");
			val6.transform.SetParent(val2.transform, false);
			RectTransform val7 = val6.AddComponent<RectTransform>();
			val7.anchorMin = new Vector2(0f, 1f);
			val7.anchorMax = new Vector2(0f, 1f);
			val7.pivot = new Vector2(0f, 1f);
			val7.anchoredPosition = new Vector2(5f, 20f);
			val7.sizeDelta = new Vector2(400f, 20f);
			_xpText = val6.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_xpText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)_xpText).fontSize = 16f;
			ApplyTextShadow(_xpText);
		}

		public void Update(bool phoneOpen)
		{
			//IL_0141: 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_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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (phoneOpen)
			{
				if (!_lastPhoneOpen)
				{
					_pauseStartTime = Time.time;
				}
				_lastPhoneOpen = true;
				if ((Object)(object)_fillImage != (Object)null && Prefs.FadeBar.Value)
				{
					Color color = ((Graphic)_fillImage).color;
					color.a = 1f;
					((Graphic)_fillImage).color = color;
				}
				if ((Object)(object)_textGroup != (Object)null && Prefs.FadeRank.Value)
				{
					_textGroup.alpha = 1f;
				}
				return;
			}
			if (_lastPhoneOpen)
			{
				_pauseAccumulated += Time.time - _pauseStartTime;
				_lastPhoneOpen = false;
			}
			float num = Time.time - _lastXPUpdateTime - _pauseAccumulated;
			_slider.value = Mathf.Lerp(_slider.value, _currentFill, Time.deltaTime * 5f);
			if (Prefs.FadeBar.Value && (Object)(object)_fillImage != (Object)null)
			{
				Color color2 = ((Graphic)_fillImage).color;
				float num2 = ((num > 3f) ? 0f : 1f);
				color2.a = Mathf.Lerp(color2.a, num2, Time.deltaTime * 2f);
				((Graphic)_fillImage).color = color2;
			}
			if (Prefs.FadeRank.Value && (Object)(object)_textGroup != (Object)null)
			{
				float num3 = ((num > 3f) ? 0f : 1f);
				_textGroup.alpha = Mathf.Lerp(_textGroup.alpha, num3, Time.deltaTime * 2f);
			}
		}

		public void UpdateXP(float xp, float maxXP)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			_currentFill = ((maxXP > 0f) ? (xp / maxXP) : 0f);
			((TMP_Text)_xpText).text = $"{xp} / {maxXP} XP";
			_lastXPUpdateTime = Time.time;
			if ((Object)(object)_rankText != (Object)null && (Object)(object)NetworkSingleton<LevelManager>.Instance != (Object)null)
			{
				ERank rank = NetworkSingleton<LevelManager>.Instance.Rank;
				int tier = NetworkSingleton<LevelManager>.Instance.Tier;
				string text = $"{rank} ({tier})";
				if (text != _lastRankDisplay)
				{
					_lastRankDisplay = text;
					((TMP_Text)_rankText).text = text;
				}
			}
			if ((Object)(object)_fillImage != (Object)null)
			{
				Color color = ((Graphic)_fillImage).color;
				color.a = 1f;
				((Graphic)_fillImage).color = color;
			}
			if ((Object)(object)_textGroup != (Object)null)
			{
				_textGroup.alpha = 1f;
			}
		}

		public void Show()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			_lastXPUpdateTime = Time.time;
			if ((Object)(object)_fillImage != (Object)null)
			{
				Color color = ((Graphic)_fillImage).color;
				color.a = 1f;
				((Graphic)_fillImage).color = color;
			}
			if ((Object)(object)_textGroup != (Object)null)
			{
				_textGroup.alpha = 1f;
			}
		}

		private void ApplyTextShadow(TextMeshProUGUI text)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Material fontSharedMaterial = ((TMP_Text)text).fontSharedMaterial;
			fontSharedMaterial.EnableKeyword("UNDERLAY_ON");
			fontSharedMaterial.SetFloat(ShaderUtilities.ID_UnderlaySoftness, 0.2f);
			fontSharedMaterial.SetFloat(ShaderUtilities.ID_UnderlayDilate, 1f);
			fontSharedMaterial.SetColor(ShaderUtilities.ID_UnderlayColor, Color.black);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}