Decompiled source of ItemStats v0.2.0

plugins/com.github.boxofbiscuits97.ItemStats.dll

Decompiled 2 weeks 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 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.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("com.github.boxofbiscuits97.ItemStats")]
[assembly: AssemblyTitle("ItemStats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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.2.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.2.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 int index = 0;

		public static string precentSign = "%";

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InventoryItemUI), "SetItem")]
		private static void SetItemPatch(InventoryItemUI __instance)
		{
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			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 _, "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 objectIcon7, out TextMeshProUGUI objectTMP7, "GAME/GUIManager/Canvas_HUD/BarGroup/ExtraStaminaBar/Icon", "infiniteStaminaStat");
			AddNewStat(out GameObject objectIcon8, out TextMeshProUGUI objectTMP8, "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))
			{
				int incriment = 1;
				float num = component.poisonPerSecond * component.inflictionTime * 100f;
				if (((TMP_Text)objectTMP8).text != "0")
				{
					num += float.Parse(((TMP_Text)objectTMP8).text.Replace(precentSign, ""));
					incriment = 0;
				}
				string text = "+" + Mathf.Round(num) + precentSign;
				((TMP_Text)objectTMP8).text = text;
				UpdateStats(ref objectIcon8, 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_ApplyInfiniteStamina component4 = ((Component)currentItem).gameObject.GetComponent<Action_ApplyInfiniteStamina>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				Image component5 = objectIcon7.GetComponent<Image>();
				rainbowHue += Time.deltaTime * 0.1f;
				if (rainbowHue > 1f)
				{
					rainbowHue -= 1f;
				}
				Color color = (((Graphic)component5).color = Color.HSVToRGB(rainbowHue, 1f, 1f));
				((Graphic)objectTMP7).color = color;
				string text4 = "+" + component4.drowsyAmount * 100f + precentSign;
				((TMP_Text)objectTMP4).text = text4;
				UpdateStats(ref objectIcon4, ref index);
				string text5 = component4.buffTime + "sec";
				((TMP_Text)objectTMP7).text = text5;
				UpdateStats(ref objectIcon7, 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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)
			{
				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)
		{
		}
	}
}