Decompiled source of Stamina Display v1.0.1

WKStaminaDisplay.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using WKStaminaDisplay.MonoBehaviours;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WKStaminaDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WKStaminaDisplay")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("75012409-a45a-429e-91fc-9f5d10da9cac")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace WKStaminaDisplay
{
	[BepInPlugin("com.overmet15.WKStaminaDisplay", "WKStaminaDisplay", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string guid = "com.overmet15.WKStaminaDisplay";

		private const string pluginName = "WKStaminaDisplay";

		public const string versionString = "1.0.1";

		public static ConfigEntry<int> staminaDistanceFromCenter;

		public static ConfigEntry<bool> staminaSliderTransitionEnabled;

		public static ConfigEntry<float> staminaTransitionSpeed;

		public static ConfigEntry<Color> staminaBackgroundColor;

		public static ConfigEntry<Color> staminaFillColor;

		public static UnityEvent onConfigChange = new UnityEvent();

		private void Awake()
		{
			//IL_0081: 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)
			staminaDistanceFromCenter = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Stamina Slider Distance From Center", 150, (ConfigDescription)null);
			staminaSliderTransitionEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Stamina Slider Transiotion Enabled", true, (ConfigDescription)null);
			staminaTransitionSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Stamina Slider Transition Speed", 0.25f, (ConfigDescription)null);
			staminaBackgroundColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Stamina Slider BG color", new Color(1f, 1f, 1f, 0.025f), (ConfigDescription)null);
			staminaFillColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Stamina Slider Fill color", new Color(1f, 1f, 1f, 0.05f), (ConfigDescription)null);
			((ConfigEntryBase)staminaDistanceFromCenter).ConfigFile.SettingChanged += OnConfigChanged;
			SceneManager.sceneLoaded += OnSceneLoaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"WKStaminaDisplay v1.0.1 is loaded.");
		}

		private void OnConfigChanged(object sender, EventArgs e)
		{
			SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
			if (val != null)
			{
				onConfigChange.Invoke();
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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: Expected O, but got Unknown
			//IL_016a: 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)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.FindGameObjectWithTag("Player");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ENT_Player component = val.GetComponent<ENT_Player>();
			GameObject val2 = GameObject.Find("GameManager/Canvas/Game UI");
			if ((Object)(object)val2 != (Object)null)
			{
				Transform transform = val2.transform;
				bool flag = true;
				Hand[] hands = component.hands;
				foreach (Hand hand in hands)
				{
					GameObject val3 = null;
					try
					{
						val3 = new GameObject("Hand Slider", new Type[1] { typeof(RectTransform) });
						val3.transform.SetParent(transform, false);
						RectTransform component2 = val3.GetComponent<RectTransform>();
						component2.sizeDelta = new Vector2(20f, 75f);
						component2.pivot = new Vector2(0.5f, 0.5f);
						component2.anchoredPosition = new Vector2((float)(flag ? (-staminaDistanceFromCenter.Value) : staminaDistanceFromCenter.Value), 0f);
						Image val4 = val3.AddComponent<Image>();
						((Graphic)val4).color = staminaBackgroundColor.Value;
						GameObject val5 = new GameObject("Hand Slider Fill Parent", new Type[1] { typeof(RectTransform) });
						val5.transform.SetParent(val3.transform, false);
						RectTransform component3 = val5.GetComponent<RectTransform>();
						component3.anchorMin = Vector2.zero;
						component3.anchorMax = Vector2.one;
						component3.offsetMin = Vector2.zero;
						component3.offsetMax = Vector2.zero;
						GameObject val6 = new GameObject("Hand Slider Fill", new Type[1] { typeof(RectTransform) });
						val6.transform.SetParent(val5.transform, false);
						RectTransform component4 = val6.GetComponent<RectTransform>();
						component4.anchorMin = Vector2.zero;
						component4.anchorMax = Vector2.one;
						component4.offsetMin = new Vector2(2.5f, 2.5f);
						component4.offsetMax = new Vector2(-2.5f, -2.5f);
						Image val7 = val6.AddComponent<Image>();
						((Graphic)val7).color = staminaFillColor.Value;
						Slider val8 = val3.AddComponent<Slider>();
						val8.direction = (Direction)2;
						val8.fillRect = component4;
						val3.AddComponent<StaminaSlider>().Setup(hand, val8, flag);
						flag = false;
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)("Exception on creating slider, destroying the slider if not null..\n Exception: " + ex.Message));
						if ((Object)(object)val3 != (Object)null)
						{
							Object.Destroy((Object)(object)val3);
						}
					}
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Canvas not found. Returning.");
			}
		}
	}
}
namespace WKStaminaDisplay.MonoBehaviours
{
	public class StaminaSlider : MonoBehaviour
	{
		private Hand hand;

		private RectTransform rectTransform;

		private Slider slider;

		private CanvasGroup canvasGroup;

		private bool hidden;

		private bool isLeft;

		private void Start()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			canvasGroup = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			hidden = true;
			canvasGroup.alpha = 0f;
			rectTransform = ((Component)this).GetComponent<RectTransform>();
			Plugin.onConfigChange.AddListener(new UnityAction(OnConfigChange));
			if (!Plugin.staminaSliderTransitionEnabled.Value)
			{
				ForceInPlace();
			}
			else
			{
				rectTransform.anchoredPosition = Vector2.zero;
			}
		}

		public void Update()
		{
			if (hand == null || (Object)(object)slider == (Object)null)
			{
				return;
			}
			slider.maxValue = hand.GetPlayer().GetCurrentGripStrengthTimer();
			slider.value = hand.gripStrength;
			if (Plugin.staminaSliderTransitionEnabled.Value)
			{
				if (hidden && hand.gripStrength < slider.maxValue)
				{
					Toggle();
				}
				else if (!hidden && hand.gripStrength >= slider.maxValue)
				{
					Toggle();
				}
			}
		}

		public void Setup(Hand hand, Slider slider, bool isLeft)
		{
			this.hand = hand;
			this.slider = slider;
			this.isLeft = isLeft;
			slider.maxValue = hand.gripStrength;
		}

		private void Toggle()
		{
			hidden = !hidden;
			int num = Plugin.staminaDistanceFromCenter.Value;
			if (isLeft)
			{
				num *= -1;
			}
			if (hidden)
			{
				TweenSettingsExtensions.SetEase<TweenerCore<float, float, FloatOptions>>(DOTweenModuleUI.DOFade(canvasGroup, 0f, 0.25f), (Ease)12);
				TweenSettingsExtensions.SetEase<TweenerCore<Vector2, Vector2, VectorOptions>>(DOTweenModuleUI.DOAnchorPosX(rectTransform, (float)(num + ((num < 0) ? 75 : (-75))), Plugin.staminaTransitionSpeed.Value, false), (Ease)12);
			}
			else
			{
				TweenSettingsExtensions.SetEase<TweenerCore<float, float, FloatOptions>>(DOTweenModuleUI.DOFade(canvasGroup, 1f, 0.25f), (Ease)12);
				TweenSettingsExtensions.SetEase<TweenerCore<Vector2, Vector2, VectorOptions>>(DOTweenModuleUI.DOAnchorPosX(rectTransform, (float)num, Plugin.staminaTransitionSpeed.Value, false), (Ease)12);
			}
		}

		private void OnConfigChange()
		{
			//IL_0043: 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)
			if (!Plugin.staminaSliderTransitionEnabled.Value)
			{
				ForceInPlace();
			}
			else if (!hidden)
			{
				hidden = true;
				Toggle();
			}
			((Graphic)((Component)this).GetComponent<Image>()).color = Plugin.staminaBackgroundColor.Value;
			((Graphic)((Component)((Component)this).transform.GetChild(0).GetChild(0)).GetComponent<Image>()).color = Plugin.staminaFillColor.Value;
		}

		private void ForceInPlace()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			int num = Plugin.staminaDistanceFromCenter.Value;
			if (isLeft)
			{
				num *= -1;
			}
			canvasGroup.alpha = 1f;
			Vector2 anchoredPosition = rectTransform.anchoredPosition;
			((Vector2)(ref anchoredPosition)).Set((float)num, 0f);
		}

		private void OnDestroy()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Plugin.onConfigChange.RemoveListener(new UnityAction(OnConfigChange));
		}
	}
}