Decompiled source of ItemUseTime v1.0.1

plugins/com.github.jkqt.ItemUseTime.dll

Decompiled 2 months 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 Photon.Pun;
using TMPro;
using UnityEngine;

[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.jkqt.ItemUseTime")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+3740ce06319c0cf5f129e956d4b885d584e654f6")]
[assembly: AssemblyProduct("com.github.jkqt.ItemUseTime")]
[assembly: AssemblyTitle("ItemUseTime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 ItemUseTime
{
	[BepInPlugin("com.github.jkqt.ItemUseTime", "ItemUseTime", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private static class ItemUseTimeProgressUpdatePatch
		{
			[HarmonyPatch(typeof(UI_UseItemProgress), "Update")]
			[HarmonyPostfix]
			private static void ItemUseTimeProgressUpdate(UI_UseItemProgress __instance)
			{
				try
				{
					if ((Object)(object)guiManager == (Object)null)
					{
						InitItemUseTime();
					}
					else
					{
						updateitemUseTimeTextMesh(__instance);
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)(ex.Message + ex.StackTrace));
				}
			}
		}

		private static GUIManager guiManager;

		private static TextMeshProUGUI itemUseTimeTextMesh;

		private static ConfigEntry<float> configFontSize;

		private static ConfigEntry<float> configOutlineWidth;

		public const string Id = "com.github.jkqt.ItemUseTime";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "ItemUseTime";

		public static string Version => "1.0.1";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			configFontSize = ((BaseUnityPlugin)this).Config.Bind<float>("ItemUseTime", "Font Size", 20f, "Customize the Font Size for item progress circle text.");
			configOutlineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("ItemUseTime", "Outline Width", 0.08f, "Customize the Outline Width for item progress circle text.");
			Harmony.CreateAndPatchAll(typeof(ItemUseTimeProgressUpdatePatch), (string)null);
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private static void updateitemUseTimeTextMesh(UI_UseItemProgress useItemProgress)
		{
			Character observedCharacter = Character.observedCharacter;
			if ((Object)(object)observedCharacter != (Object)null)
			{
				if (((MonoBehaviourPun)observedCharacter).photonView.IsMine)
				{
					Item currentItem = observedCharacter.data.currentItem;
					Item val = default(Item);
					if (observedCharacter.refs.items.climbingSpikeCastProgress > 0f && ((Component)observedCharacter.refs.items.currentClimbingSpikeComponent).gameObject.TryGetComponent<Item>(ref val))
					{
						((TMP_Text)itemUseTimeTextMesh).text = ((1f - useItemProgress.fill.fillAmount) * val.totalSecondaryUsingTime).ToString("F1");
						((Component)itemUseTimeTextMesh).gameObject.SetActive(true);
					}
					else if ((Object)(object)currentItem != (Object)null && currentItem.shouldShowCastProgress)
					{
						RopeTier val2 = default(RopeTier);
						if (((Component)currentItem).gameObject.TryGetComponent<RopeTier>(ref val2))
						{
							((TMP_Text)itemUseTimeTextMesh).text = ((1f - useItemProgress.fill.fillAmount) * val2.castTime).ToString("F1");
						}
						else if (currentItem.isUsingSecondary)
						{
							((TMP_Text)itemUseTimeTextMesh).text = ((1f - useItemProgress.fill.fillAmount) * currentItem.totalSecondaryUsingTime).ToString("F1");
						}
						else
						{
							((TMP_Text)itemUseTimeTextMesh).text = ((1f - useItemProgress.fill.fillAmount) * currentItem.usingTimePrimary).ToString("F1");
						}
						((Component)itemUseTimeTextMesh).gameObject.SetActive(true);
					}
					else if (useItemProgress.constantUseInteractableExists && Interaction.instance.constantInteractableProgress > 0f)
					{
						((TMP_Text)itemUseTimeTextMesh).text = ((1f - useItemProgress.fill.fillAmount) * Interaction.instance.currentConstantInteractableTime).ToString("F1");
						((Component)itemUseTimeTextMesh).gameObject.SetActive(true);
					}
					else
					{
						((Component)itemUseTimeTextMesh).gameObject.SetActive(false);
					}
				}
				else
				{
					((Component)itemUseTimeTextMesh).gameObject.SetActive(false);
				}
			}
			else
			{
				((Component)itemUseTimeTextMesh).gameObject.SetActive(false);
			}
		}

		private static void InitItemUseTime()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("GAME/GUIManager");
			guiManager = val.GetComponent<GUIManager>();
			TMP_FontAsset font = ((TMP_Text)guiManager.heroDayText).font;
			GameObject gameObject = ((Component)val.transform.Find("Canvas_HUD/UseItem")).gameObject;
			GameObject val2 = new GameObject("ItemUseTime");
			val2.transform.SetParent(gameObject.transform);
			itemUseTimeTextMesh = val2.AddComponent<TextMeshProUGUI>();
			RectTransform component = val2.GetComponent<RectTransform>();
			((TMP_Text)itemUseTimeTextMesh).font = font;
			((TMP_Text)itemUseTimeTextMesh).fontSize = configFontSize.Value;
			component.offsetMin = new Vector2(0f, 0f);
			component.offsetMax = new Vector2(0f, 0f);
			((TMP_Text)itemUseTimeTextMesh).alignment = (TextAlignmentOptions)514;
			((TMP_Text)itemUseTimeTextMesh).verticalAlignment = (VerticalAlignmentOptions)8192;
			((TMP_Text)itemUseTimeTextMesh).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)itemUseTimeTextMesh).text = "";
			((TMP_Text)itemUseTimeTextMesh).outlineWidth = configOutlineWidth.Value;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}