Decompiled source of Better Cooldown Formatting v4.0.0

BetterCooldownFormatting.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using On;
using Partiality.Modloader;
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: AssemblyVersion("0.0.0.0")]
public class MyPartialityMod : PartialityMod
{
	public MyPartialityMod()
	{
		base.ModID = "BetterCooldownFormatting";
		base.Version = "3";
		base.author = "Stian";
	}

	public override void OnEnable()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		((PartialityMod)this).OnEnable();
		ItemDetailsDisplay.RefreshDetail += new hook_RefreshDetail(ItemDetailsDisplay_RefreshDetail);
		StatusEffectDetailDisplay.RefreshDisplay += new hook_RefreshDisplay(StatusEffectDetailDisplay_RefreshDisplay);
	}

	public bool ItemDetailsDisplay_RefreshDetail(orig_RefreshDetail orig, ItemDetailsDisplay self, int _rowIndex, DisplayedInfos _infoType)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		bool result = orig.Invoke(self, _rowIndex, _infoType);
		if ((int)_infoType == 24)
		{
			FieldInfo field = ((object)self).GetType().GetField("cachedSkill", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			Skill val = (Skill)field.GetValue(self);
			if (Object.op_Implicit((Object)(object)val))
			{
				MethodInfo method = ((object)self).GetType().GetMethod("GetRow", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				ItemDetailRowDisplay val2 = (ItemDetailRowDisplay)method.Invoke(self, new object[1] { _rowIndex });
				string text = FormatDuration(val.Cooldown, showZero: false);
				val2.SetInfo(LocalizationManager.Instance.GetLoc("ItemStat_Cooldown"), text);
			}
		}
		return result;
	}

	public void StatusEffectDetailDisplay_RefreshDisplay(orig_RefreshDisplay orig, StatusEffectDetailDisplay self)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		orig.Invoke(self);
		FieldInfo field = ((object)self).GetType().GetField("m_lblTimer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Text val = (Text)field.GetValue(self);
		if (Object.op_Implicit((Object)(object)val) && val.text != string.Empty)
		{
			string value = val.text.Substring(0, val.text.Length - 5);
			float seconds = Convert.ToSingle(value);
			string text = FormatDuration(seconds, showZero: true);
			val.text = text;
		}
	}

	private string FormatDuration(float seconds, bool showZero)
	{
		string text = "";
		int minutes = TimeSpan.FromSeconds(seconds).Minutes;
		float num = seconds - (float)(minutes * 60);
		if (minutes > 0)
		{
			text = text + minutes + " min";
		}
		if (showZero || num > 0f)
		{
			if (minutes > 0)
			{
				text += " ";
			}
			text = text + num + " sec";
		}
		return text;
	}
}