Decompiled source of ItemStats v0.4.0

plugins/com.github.boxofbiscuits97.ItemStats.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 BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak.Afflictions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.boxofbiscuits97.ItemStats")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0+eface1d929d02e13d18d879fcbbf572423197c4d")]
[assembly: AssemblyProduct("com.github.boxofbiscuits97.ItemStats")]
[assembly: AssemblyTitle("ItemStats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ItemStats
{
	[BepInPlugin("com.github.boxofbiscuits97.ItemStats", "ItemStats", "0.4.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static ConfigEntry<bool>? showPercentageSign;

		public const string Id = "com.github.boxofbiscuits97.ItemStats";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "ItemStats";

		public static string Version => "0.4.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			showPercentageSign = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowPercentageSign", true, "Whether to show a percentage sign (%) after numeric values.");
			if (!showPercentageSign.Value)
			{
				ItemStats.precentSign = "";
			}
			Harmony.CreateAndPatchAll(typeof(ItemStats), (string)null);
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
	public static class ItemStats
	{
		private static InventoryItemUI instance = new InventoryItemUI();

		private static GameObject? templateStat;

		private static float rainbowHue = 0f;

		private static float colorLerp = -1f;

		private static int index = 0;

		public static string precentSign = "%";

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InventoryItemUI), "SetItem")]
		private static void SetItemPatch(InventoryItemUI __instance)
		{
			//IL_035a: 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_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Invalid comparison between Unknown and I4
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Invalid comparison between Unknown and I4
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Invalid comparison between Unknown and I4
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Expected O, but got Unknown
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Expected O, but got Unknown
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Expected O, but got Unknown
			instance = __instance;
			GameObject gameObject = ((Component)__instance.fuelBar.transform.parent).gameObject;
			if (__instance.isBackpack)
			{
				return;
			}
			Initialize(out GameObject hungerIcon, out GameObject _, out TextMeshProUGUI hungerTMP);
			index = 0;
			AddNewStat(out hungerIcon, out hungerTMP, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Hunger/Icon", "hungerStat", (STATUSTYPE)1);
			AddNewStat(out GameObject objectIcon, out TextMeshProUGUI objectTMP, "GAME/GUIManager/Canvas_HUD/BarGroup/ExtraStaminaBar/Icon", "extraStaminaStat");
			AddNewStat(out GameObject _, out TextMeshProUGUI objectTMP2, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Cold/Icon", "coldStat", (STATUSTYPE)2);
			AddNewStat(out GameObject _, out TextMeshProUGUI _, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Injury/Icon", "injuryStat", (STATUSTYPE)0);
			AddNewStat(out GameObject objectIcon4, out TextMeshProUGUI objectTMP4, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Sleepy/Icon", "sleepyStat", (STATUSTYPE)6);
			AddNewStat(out GameObject _, out TextMeshProUGUI _, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Heat/Icon", "heatStat", (STATUSTYPE)8);
			AddNewStat(out GameObject _, out TextMeshProUGUI _, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Curse/Icon", "curseStat", (STATUSTYPE)5);
			AddNewStat(out GameObject _, out TextMeshProUGUI _, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Spores/Icon", "sporesStat", (STATUSTYPE)10);
			AddNewStat(out GameObject objectIcon8, out TextMeshProUGUI objectTMP8, "GAME/GUIManager/Canvas_HUD/BarGroup/ExtraStaminaBar/Icon", "infiniteStaminaStat");
			AddNewStat(out GameObject objectIcon9, out TextMeshProUGUI objectTMP9, "GAME/GUIManager/Canvas_HUD/BarGroup/ExtraStaminaBar/Icon", "fasterBoiStat");
			AddNewStat(out GameObject objectIcon10, out TextMeshProUGUI objectTMP10, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/OutlineMask/Outline/Shield/ShieldIcon", "invincibilityStat");
			AddNewStat(out GameObject objectIcon11, out TextMeshProUGUI objectTMP11, "GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Poison/Icon", "poisonStat", (STATUSTYPE)3);
			Item currentItem = Character.localCharacter.data.currentItem;
			if ((Object)(object)currentItem == (Object)null || !((Behaviour)((Component)gameObject.transform.Find("Name")).GetComponent<TextMeshProUGUI>()).enabled)
			{
				return;
			}
			Action_InflictPoison component = ((Component)currentItem).gameObject.GetComponent<Action_InflictPoison>();
			if (Object.op_Implicit((Object)(object)component) && ((Behaviour)component).enabled)
			{
				int incriment = 1;
				float num = component.poisonPerSecond * component.inflictionTime * 100f;
				if (((TMP_Text)objectTMP11).text != "0")
				{
					num += float.Parse(((TMP_Text)objectTMP11).text.Replace(precentSign, ""));
					incriment = 0;
				}
				string text = "+" + Mathf.Round(num) + precentSign;
				((TMP_Text)objectTMP11).text = text;
				UpdateStats(ref objectIcon11, ref index, incriment);
			}
			Action_RestoreHunger component2 = ((Component)currentItem).gameObject.GetComponent<Action_RestoreHunger>();
			if (Object.op_Implicit((Object)(object)component2) && component2.restorationAmount != 0f)
			{
				float num2 = component2.restorationAmount * 100f;
				string text2 = "-" + Mathf.Round(num2) + precentSign;
				((TMP_Text)hungerTMP).text = text2;
				UpdateStats(ref hungerIcon, ref index);
			}
			Action_GiveExtraStamina component3 = ((Component)currentItem).gameObject.GetComponent<Action_GiveExtraStamina>();
			if (Object.op_Implicit((Object)(object)component3) && component3.amount != 0f)
			{
				string text3 = "+" + component3.amount * 100f + precentSign;
				((TMP_Text)objectTMP).text = text3;
				UpdateStats(ref objectIcon, ref index);
			}
			Action_ApplyAffliction[] components = ((Component)currentItem).gameObject.GetComponents<Action_ApplyAffliction>();
			Action_ApplyAffliction[] array = components;
			foreach (Action_ApplyAffliction val in array)
			{
				if (!((Behaviour)val).enabled)
				{
					continue;
				}
				AfflictionType afflictionType = val.affliction.GetAfflictionType();
				if ((int)afflictionType == 1)
				{
					Image component4 = objectIcon8.GetComponent<Image>();
					rainbowHue += Time.deltaTime * 0.1f;
					if (rainbowHue > 1f)
					{
						rainbowHue -= 1f;
					}
					Color color = (((Graphic)component4).color = Color.HSVToRGB(rainbowHue, 1f, 1f));
					((Graphic)objectTMP8).color = color;
					Affliction_InfiniteStamina val3 = (Affliction_InfiniteStamina)val.affliction;
					Affliction_AdjustDrowsyOverTime val4 = (Affliction_AdjustDrowsyOverTime)val3.drowsyAffliction;
					float num3 = val3.drowsyAffliction.totalTime * val4.statusPerSecond;
					string text4 = "+" + Mathf.Round(num3 * 100f) + precentSign;
					((TMP_Text)objectTMP4).text = text4;
					UpdateStats(ref objectIcon4, ref index);
					string text5 = val.affliction.totalTime + "sec";
					((TMP_Text)objectTMP8).text = text5;
					UpdateStats(ref objectIcon8, ref index);
				}
				if ((int)afflictionType == 2)
				{
					Image component5 = objectIcon9.GetComponent<Image>();
					colorLerp += Time.deltaTime * 2f;
					if (colorLerp > 1f)
					{
						colorLerp -= 2f;
					}
					Color color2 = (((Graphic)component5).color = Color.Lerp(((Graphic)objectTMP).color, ((Graphic)objectTMP2).color, Mathf.Abs(colorLerp)));
					((Graphic)objectTMP9).color = color2;
					Affliction_FasterBoi val6 = (Affliction_FasterBoi)val.affliction;
					string text6 = "+" + Mathf.Round(val6.drowsyOnEnd * 100f) + precentSign;
					((TMP_Text)objectTMP4).text = text6;
					UpdateStats(ref objectIcon4, ref index);
					string text7 = ((Affliction)val6).totalTime + "sec";
					((TMP_Text)objectTMP9).text = text7;
					UpdateStats(ref objectIcon9, ref index);
				}
				if ((int)afflictionType == 16)
				{
					string text8 = val.affliction.totalTime + "sec";
					((TMP_Text)objectTMP10).text = text8;
					UpdateStats(ref objectIcon10, ref index);
				}
			}
		}

		private static void Initialize(out GameObject hungerIcon, out GameObject hungerText, out TextMeshProUGUI hungerTMP)
		{
			//IL_006f: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("GAME/GUIManager/Canvas_HUD/BarGroup/Bar/LayoutGroup/Hunger/Icon");
			GameObject gameObject = ((Component)instance.fuelBar.transform.parent).gameObject;
			Transform val2 = gameObject.transform.Find("hungerStat");
			if ((Object)(object)val2 == (Object)null)
			{
				hungerIcon = Object.Instantiate<GameObject>(val, gameObject.transform);
				((Object)hungerIcon).name = "hungerStat";
				hungerIcon.transform.localPosition = new Vector3(55f, -20f, 0f);
				hungerIcon.transform.localScale = new Vector3(0.66f, 0.66f, 0.66f);
				Outline val3 = hungerIcon.AddComponent<Outline>();
				((Shadow)val3).effectDistance = new Vector2(1.5f, -1.5f);
			}
			else
			{
				hungerIcon = ((Component)val2).gameObject;
			}
			Transform val4 = hungerIcon.transform.Find("Text");
			if ((Object)(object)val4 == (Object)null)
			{
				GameObject gameObject2 = ((Component)gameObject.transform.Find("Name")).gameObject;
				hungerText = Object.Instantiate<GameObject>(gameObject2, hungerIcon.transform);
				((Object)hungerText).name = "Text";
				hungerText.transform.localPosition = new Vector3(-75f, -25f, 0f);
				hungerTMP = hungerText.GetComponent<TextMeshProUGUI>();
				((TMP_Text)hungerTMP).text = "-100%";
				((TMP_Text)hungerTMP).outlineWidth = 0.1f;
				((TMP_Text)hungerTMP).alignment = (TextAlignmentOptions)516;
				((Behaviour)hungerTMP).enabled = true;
				Image component = val.GetComponent<Image>();
				((Graphic)hungerTMP).color = ((Graphic)component).color;
			}
			else
			{
				hungerText = ((Component)val4).gameObject;
				hungerTMP = hungerText.GetComponent<TextMeshProUGUI>();
			}
			templateStat = hungerIcon;
		}

		private static void AddNewStat(out GameObject objectIcon, out TextMeshProUGUI objectTMP, string name, string iconName, STATUSTYPE? status = null)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)templateStat == (Object)null)
			{
				objectIcon = new GameObject();
				objectTMP = objectIcon.AddComponent<TextMeshProUGUI>();
				return;
			}
			Item currentItem = Character.localCharacter.data.currentItem;
			GameObject gameObject = ((Component)instance.fuelBar.transform.parent).gameObject;
			Transform val = gameObject.transform.Find(iconName);
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = GameObject.Find(name);
				objectIcon = Object.Instantiate<GameObject>(templateStat, gameObject.transform);
				((Object)objectIcon).name = iconName;
				Image component = objectIcon.GetComponent<Image>();
				Image component2 = val2.GetComponent<Image>();
				component.sprite = component2.sprite;
				((Graphic)component).color = ((Graphic)component2).color;
				objectTMP = ((Component)objectIcon.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
				((Graphic)objectTMP).color = ((Graphic)component2).color;
			}
			else
			{
				objectIcon = ((Component)val).gameObject;
			}
			objectTMP = ((Component)objectIcon.transform.GetChild(0)).GetComponent<TextMeshProUGUI>();
			((TMP_Text)objectTMP).text = "0";
			objectIcon.SetActive(false);
			if ((Object)(object)currentItem == (Object)null || !status.HasValue || !((Behaviour)((Component)gameObject.transform.Find("Name")).GetComponent<TextMeshProUGUI>()).enabled)
			{
				return;
			}
			Action_ModifyStatus[] components = ((Component)currentItem).gameObject.GetComponents<Action_ModifyStatus>();
			Action_ModifyStatus[] array = components;
			foreach (Action_ModifyStatus val3 in array)
			{
				if (!((Behaviour)val3).enabled)
				{
					continue;
				}
				float num = val3.changeAmount * 100f;
				if (num == 0f)
				{
					continue;
				}
				string text = Mathf.Round(num) + precentSign;
				if ((STATUSTYPE?)val3.statusType == status)
				{
					string text2 = "";
					if (num > 0f)
					{
						text2 = "+";
					}
					((TMP_Text)objectTMP).text = text2 + text;
					UpdateStats(ref objectIcon, ref index);
				}
			}
		}

		private static void UpdateStats(ref GameObject icon, ref int index, int incriment = 1)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			icon.SetActive(true);
			index += incriment;
			Vector3 localPosition = default(Vector3);
			if (!instance.isTemporarySlot)
			{
				((Vector3)(ref localPosition))..ctor(60f, 80f + (float)(20 * index), 0f);
			}
			else
			{
				((Vector3)(ref localPosition))..ctor(20f, 120f + (float)(20 * index), 0f);
			}
			icon.transform.localPosition = localPosition;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}