Decompiled source of BetterAmuletUI v1.0.0

BetterAmuletUI.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak;
using Peak.Afflictions;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("VACNET")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VACNET")]
[assembly: AssemblyTitle("VACNET")]
[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 PetrifyPreviewMod
{
	[BepInPlugin("com.gedisu.petrifypreview", "Petrify Preview", "1.0.0")]
	[BepInProcess("Peak.exe")]
	public class PetrifyPreviewPlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			new Harmony("com.gedisu.petrifypreview").PatchAll();
			GameObject val = new GameObject("PetrifyCrosshairOverlay");
			val.AddComponent<CrosshairOverlay>();
			Object.DontDestroyOnLoad((Object)(object)val);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Petrify Preview: Loaded!");
		}
	}
	public class CrosshairOverlay : MonoBehaviour
	{
		private GUIStyle style;

		private GameObject cachedReticle;

		private bool lastState = false;

		private void Awake()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			style = new GUIStyle();
			style.normal.textColor = new Color(0.8f, 0.2f, 0.2f, 0.7f);
			style.fontSize = 32;
			style.fontStyle = (FontStyle)1;
			style.alignment = (TextAnchor)4;
		}

		private void Update()
		{
			bool flag = PreviewCache.IsPreviewing && PreviewCache.IsTargetNonCloneable;
			if (flag == lastState)
			{
				return;
			}
			if ((Object)(object)cachedReticle == (Object)null)
			{
				cachedReticle = GameObject.Find("Reticle");
			}
			if ((Object)(object)cachedReticle != (Object)null)
			{
				Image component = cachedReticle.GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = !flag;
				}
				else
				{
					cachedReticle.SetActive(!flag);
				}
			}
			lastState = flag;
		}

		private void OnGUI()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (PreviewCache.IsPreviewing && PreviewCache.IsTargetNonCloneable)
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)Screen.width / 2f - 25f, (float)Screen.height / 2f - 25f, 50f, 50f);
				GUI.Label(val, "X", style);
			}
		}
	}
	public static class PreviewCache
	{
		private static Item _lastItem;

		private static float _nextUpdateTime;

		public static bool IsTargetNonCloneable;

		public static float CurrentPenalty;

		public static bool IsPreviewing;

		public static void RefreshIfNeeded(Character player)
		{
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Invalid comparison between Unknown and I4
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: 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)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			Item currentItem = player.data.currentItem;
			if (!((Object)(object)currentItem != (Object)(object)_lastItem) && !(Time.time >= _nextUpdateTime))
			{
				return;
			}
			_lastItem = currentItem;
			_nextUpdateTime = Time.time + 0.1f;
			CurrentPenalty = 0f;
			IsPreviewing = false;
			if (!((Object)(object)currentItem != (Object)null))
			{
				return;
			}
			Action_SuperJumpAmulet componentInChildren = ((Component)currentItem).GetComponentInChildren<Action_SuperJumpAmulet>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				float petrifyPerUse = componentInChildren.petrifyPerUse;
				CurrentPenalty = ((petrifyPerUse < 1f && petrifyPerUse > 0f) ? petrifyPerUse : (petrifyPerUse / 100f));
				IsPreviewing = true;
				return;
			}
			Action_HealingGem componentInChildren2 = ((Component)currentItem).GetComponentInChildren<Action_HealingGem>();
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				try
				{
					float num = ((componentInChildren2.healingAffliction != null && componentInChildren2.healingAffliction.maxHealing > 0f) ? componentInChildren2.healingAffliction.maxHealing : 0.6f);
					float num2 = ((componentInChildren2.healingToPetrifyRatio > 0f) ? componentInChildren2.healingToPetrifyRatio : 0.5f);
					float num3 = ((componentInChildren2.minPetrify > 0f) ? componentInChildren2.minPetrify : 0.1f);
					float num4 = ((componentInChildren2.maxPetrify > 0f) ? componentInChildren2.maxPetrify : 0.3f);
					float totalPotentialHeal = Affliction_HealAll.GetTotalPotentialHeal(player, num);
					CurrentPenalty = Mathf.Clamp(totalPotentialHeal * num2, num3, num4);
				}
				catch
				{
					CurrentPenalty = 0.1f;
				}
				IsPreviewing = true;
				return;
			}
			Action_CloneSelectedItem componentInChildren3 = ((Component)currentItem).GetComponentInChildren<Action_CloneSelectedItem>();
			if ((Object)(object)componentInChildren3 != (Object)null)
			{
				float num5 = 0f;
				IsTargetNonCloneable = false;
				try
				{
					if ((Object)(object)Interaction.instance != (Object)null)
					{
						IInteractible val = default(IInteractible);
						Interaction.instance.DoInteractableRaycasts(ref val, componentInChildren3.range, false);
						if (val != null && (Object)(object)((val is Item) ? val : null) != (Object)null)
						{
							Item val2 = (Item)(object)((val is Item) ? val : null);
							if (((Enum)val2.itemTags).HasFlag((Enum)(object)(ItemTags)512) || ((Enum)val2.itemTags).HasFlag((Enum)(object)(ItemTags)2048))
							{
								IsTargetNonCloneable = true;
							}
							else
							{
								num5 = (((Enum)val2.itemTags).HasFlag((Enum)(object)(ItemTags)1) ? componentInChildren3.petrifyMystical : componentInChildren3.petrify);
							}
						}
					}
				}
				catch
				{
					num5 = componentInChildren3.petrify;
				}
				CurrentPenalty = num5 / 100f;
				IsPreviewing = true;
			}
			else
			{
				Action_ModifyStatus componentInChildren4 = ((Component)currentItem).GetComponentInChildren<Action_ModifyStatus>();
				if ((Object)(object)componentInChildren4 != (Object)null && (int)componentInChildren4.statusType == 13 && componentInChildren4.changeAmount > 0f)
				{
					float changeAmount = componentInChildren4.changeAmount;
					CurrentPenalty = ((changeAmount <= 1f) ? changeAmount : (changeAmount / 100f));
					IsPreviewing = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BarAffliction), "ChangeAffliction")]
	public static class PreventOverridePatch
	{
		[HarmonyPrefix]
		public static bool Prefix(BarAffliction __instance)
		{
			if (!__instance.isPetrify)
			{
				return true;
			}
			PreviewCache.RefreshIfNeeded(Character.observedCharacter);
			if (PreviewCache.IsPreviewing)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(BarAffliction), "UpdateAffliction")]
	public static class PreviewAfflictionPatch
	{
		[HarmonyPrefix]
		public static void Prefix(BarAffliction __instance, StaminaBar bar)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.isPetrify)
			{
				return;
			}
			Character observedCharacter = Character.observedCharacter;
			if ((Object)(object)observedCharacter == (Object)null)
			{
				return;
			}
			PreviewCache.RefreshIfNeeded(observedCharacter);
			float num = (float)observedCharacter.data.petrifyAmount / 100f;
			float num2 = num + PreviewCache.CurrentPenalty;
			if (num2 > 0.01f)
			{
				float num3 = bar.fullBar.sizeDelta.x * num2;
				if (num3 < bar.minAfflictionWidth)
				{
					num3 = bar.minAfflictionWidth;
				}
				__instance.size = num3;
				if (!((Component)__instance).gameObject.activeSelf)
				{
					((Component)__instance).gameObject.SetActive(true);
				}
			}
			else if (num <= 0.01f && ((Component)__instance).gameObject.activeSelf)
			{
				((Component)__instance).gameObject.SetActive(false);
			}
		}

		[HarmonyPostfix]
		public static void Postfix(BarAffliction __instance)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.isPetrify)
			{
				return;
			}
			if (PreviewCache.IsPreviewing)
			{
				float a = 0.4f + Mathf.Abs(Mathf.Sin(Time.time * 6f)) * 0.6f;
				if ((Object)(object)__instance.icon != (Object)null)
				{
					Color color = ((Graphic)__instance.icon).color;
					color.a = a;
					((Graphic)__instance.icon).color = color;
				}
			}
			else if ((Object)(object)__instance.icon != (Object)null && ((Graphic)__instance.icon).color.a != 1f)
			{
				Color color2 = ((Graphic)__instance.icon).color;
				color2.a = 1f;
				((Graphic)__instance.icon).color = color2;
			}
		}
	}
}