Decompiled source of MeditateReminder v1.0.2

MeditateReminder.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MeditateReminder")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MeditateReminder")]
[assembly: AssemblyTitle("MeditateReminder")]
[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 MeditateReminder
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Birbski.MeditateReminder", "MeditateReminder", "1.0.2")]
	public class MeditateReminder : BaseUnityPlugin
	{
		public const string PluginGUID = "Birbski.MeditateReminder";

		public const string PluginAuthor = "Birbski";

		public const string PluginName = "MeditateReminder";

		public const string PluginVersion = "1.0.2";

		private const float placementMin = 0.01f;

		private const float placementMax = 1f;

		private const int fontSizeMin = 8;

		private const int fontSizeMax = 96;

		private const float timerMin = 1f;

		private const float timerMax = 5f;

		private TextMeshProUGUI reminderText;

		private GameObject goReminder;

		private BodyIndex seekerBodyIndex;

		private float prevCd = 0f;

		public static ConfigEntry<bool> useChat { get; set; }

		public static ConfigEntry<float> xPlacement { get; set; }

		public static ConfigEntry<float> yPlacement { get; set; }

		public static ConfigEntry<int> fontSize { get; set; }

		public static ConfigEntry<Color> fontColor { get; set; }

		public static ConfigEntry<float> revealTime { get; set; }

		public void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_0178: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_01c7: Expected O, but got Unknown
			//IL_01cc: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_0202: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_020d: 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_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			//IL_0229: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_027d: Expected O, but got Unknown
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			seekerBodyIndex = BodyCatalog.FindBodyIndex("SeekerBody");
			useChat = ((BaseUnityPlugin)this).Config.Bind<bool>("-", "SendInChat", false, "Show reminder in chat rather than on screen");
			xPlacement = ((BaseUnityPlugin)this).Config.Bind<float>("-", "XPlacement", 0.4f, "Placement of reminder text on X Axis (0 - 1.0)");
			yPlacement = ((BaseUnityPlugin)this).Config.Bind<float>("-", "YPlacement", 0.4f, "Placement of reminder text on Y Axis (0 - 1.0)");
			fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("-", "FontSize", 28, "Size of reminder text");
			fontColor = ((BaseUnityPlugin)this).Config.Bind<Color>("-", "FontColor", Color.cyan, "Color of reminder text");
			revealTime = ((BaseUnityPlugin)this).Config.Bind<float>("-", "RevealTime", 3f, "How many seconds the reminder text is on screen");
			Sprite val = LoadSprite();
			if ((Object)(object)val != (Object)null)
			{
				ModSettingsManager.SetModIcon(val);
			}
			ModSettingsManager.SetModDescription("Looking at the bottom right is hard. Easy reminder for Seeker's Meditate ability.");
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(useChat));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(xPlacement, (SliderConfig)new StepSliderConfig
			{
				min = 0.01f,
				max = 1f,
				increment = 0.01f,
				FormatString = "{0:0.0}",
				checkIfDisabled = new IsDisabledDelegate(CheckToEnableOptions)
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(yPlacement, (SliderConfig)new StepSliderConfig
			{
				min = 0.01f,
				max = 1f,
				increment = 0.01f,
				FormatString = "{0:0.0}",
				checkIfDisabled = new IsDisabledDelegate(CheckToEnableOptions)
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(fontSize, new IntSliderConfig
			{
				min = 8,
				max = 96,
				checkIfDisabled = new IsDisabledDelegate(CheckToEnableOptions)
			}));
			ModSettingsManager.AddOption((BaseOption)new ColorOption(fontColor, new ColorOptionConfig
			{
				checkIfDisabled = new IsDisabledDelegate(CheckToEnableOptions)
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(revealTime, (SliderConfig)new StepSliderConfig
			{
				min = 1f,
				max = 5f,
				increment = 1f,
				FormatString = "{0:0}",
				checkIfDisabled = new IsDisabledDelegate(CheckToEnableOptions)
			}));
			CharacterBody.FixedUpdate += new hook_FixedUpdate(CharacterBody_FixedUpdate);
			CharacterBody.OnDestroy += new hook_OnDestroy(CharacterBody_OnDestroy);
			HUD.Awake += new hook_Awake(HUD_Awake);
		}

		private void OnDestroy()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			CharacterBody.FixedUpdate -= new hook_FixedUpdate(CharacterBody_FixedUpdate);
			CharacterBody.OnDestroy -= new hook_OnDestroy(CharacterBody_OnDestroy);
			HUD.Awake -= new hook_Awake(HUD_Awake);
		}

		private void CharacterBody_OnDestroy(orig_OnDestroy orig, CharacterBody self)
		{
			prevCd = 0f;
			orig.Invoke(self);
		}

		private bool CheckToEnableOptions()
		{
			return useChat.Value;
		}

		private void CharacterBody_FixedUpdate(orig_FixedUpdate orig, CharacterBody self)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if ((int)seekerBodyIndex == -1)
			{
				seekerBodyIndex = BodyCatalog.FindBodyIndex("SeekerBody");
			}
			if (self.bodyIndex != seekerBodyIndex || (Object)(object)self.master == (Object)null || !self.master.hasEffectiveAuthority)
			{
				return;
			}
			SkillLocator skillLocator = self.skillLocator;
			if ((Object)(object)skillLocator == (Object)null)
			{
				return;
			}
			GenericSkill special = skillLocator.special;
			if ((Object)(object)special == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)((Component)self).gameObject).GetInstanceID();
			float cooldownRemaining = special.cooldownRemaining;
			if (prevCd > 0f && cooldownRemaining <= 0f)
			{
				int buffCount = self.GetBuffCount(Buffs.ChakraBuff);
				if (buffCount < 7)
				{
					SendMessage();
				}
			}
			prevCd = cooldownRemaining;
		}

		private void HUD_Awake(orig_Awake orig, HUD self)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			goReminder = new GameObject("MeditateReminderText");
			goReminder.transform.SetParent(self.mainUIPanel.transform);
			reminderText = goReminder.AddComponent<TextMeshProUGUI>();
			((TMP_Text)reminderText).fontSize = fontSize.Value;
			((Graphic)reminderText).color = fontColor.Value;
			((TMP_Text)reminderText).text = "Refresh meditate!";
			RectTransform rectTransform = ((TMP_Text)reminderText).rectTransform;
			rectTransform.anchorMin = new Vector2(xPlacement.Value, yPlacement.Value);
			rectTransform.anchorMax = new Vector2(xPlacement.Value, yPlacement.Value);
			rectTransform.anchoredPosition = Vector2.zero;
			goReminder.SetActive(false);
		}

		private void SendMessage()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (useChat.Value)
			{
				Chat.AddMessage("<color=yellow>Refresh meditate!</color>");
			}
			else if (Object.op_Implicit((Object)(object)goReminder))
			{
				CheckLimits();
				((TMP_Text)reminderText).fontSize = fontSize.Value;
				((Graphic)reminderText).color = fontColor.Value;
				RectTransform rectTransform = ((TMP_Text)reminderText).rectTransform;
				rectTransform.anchorMin = new Vector2(xPlacement.Value, yPlacement.Value);
				rectTransform.anchorMax = new Vector2(xPlacement.Value, yPlacement.Value);
				rectTransform.anchoredPosition = Vector2.zero;
				((MonoBehaviour)this).StartCoroutine(ShowMessage());
			}
			IEnumerator ShowMessage()
			{
				goReminder.SetActive(true);
				yield return (object)new WaitForSeconds(revealTime.Value);
				goReminder.SetActive(false);
			}
		}

		private void CheckLimits()
		{
			if (xPlacement.Value < 0.01f)
			{
				xPlacement.Value = 0.01f;
			}
			if (xPlacement.Value > 1f)
			{
				xPlacement.Value = 1f;
			}
			if (yPlacement.Value < 0.01f)
			{
				yPlacement.Value = 0.01f;
			}
			if (yPlacement.Value > 1f)
			{
				yPlacement.Value = 1f;
			}
			if (((TMP_Text)reminderText).fontSize < 8f)
			{
				((TMP_Text)reminderText).fontSize = 8f;
			}
			if (((TMP_Text)reminderText).fontSize > 96f)
			{
				((TMP_Text)reminderText).fontSize = 96f;
			}
			if (revealTime.Value < 1f)
			{
				revealTime.Value = 1f;
			}
			if (revealTime.Value > 5f)
			{
				revealTime.Value = 5f;
			}
		}

		private Sprite LoadSprite()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_008a: 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)
			string path = Paths.PluginPath + "\\Birbski-MeditateReminder\\icon.png";
			if (!File.Exists(path))
			{
				Log.Error("Logo File does not exist");
				return null;
			}
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(256, 256, (TextureFormat)5, false);
			if (!ImageConversion.LoadImage(val, array))
			{
				Log.Error("Texture load error");
				return null;
			}
			((Texture)val).filterMode = (FilterMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
		}
	}
}