Decompiled source of BuffCountdown v0.7.1

plugins/BuffCountdown.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BuffCountdown
{
	[BepInPlugin("Squirtle18.BuffCountdown", "BuffCountdown", "0.7.1")]
	public class BuffCountdownPlugin : BaseUnityPlugin
	{
		public static BuffCountdownPlugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public ConfigEntry<bool> Enabled { get; private set; }

		public ConfigEntry<int> OffsetX { get; private set; }

		public ConfigEntry<int> OffsetY { get; private set; }

		public ConfigEntry<float> PanelScale { get; private set; }

		public ConfigEntry<int> Alignment { get; private set; }

		public ConfigEntry<float> FontSize { get; private set; }

		public ConfigEntry<Color> TextColor { get; private set; }

		public ConfigEntry<bool> ShowBackground { get; private set; }

		public ConfigEntry<float> BackgroundAlpha { get; private set; }

		public ConfigEntry<bool> ShowProgress { get; private set; }

		public ConfigEntry<bool> UseChinese { get; private set; }

		public ConfigEntry<float> Precision { get; private set; }

		public ConfigEntry<bool> AutoScanInterval { get; private set; }

		public ConfigEntry<float> ManualScanInterval { get; private set; }

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Expected O, but got Unknown
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				MushroomEffectHook.TryPatch(new Harmony("Squirtle18.BuffCountdown"));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[BuffCountdown] Harmony patch failed: " + ex.Message));
			}
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "Enabled", true, "Show buff countdown HUD\n显示效果倒计时 HUD");
			OffsetX = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "OffsetX", 0, new ConfigDescription("Screen horizontal offset in pixels\n屏幕水平偏移(像素)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-5000, 5000), Array.Empty<object>()));
			OffsetY = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "OffsetY", 0, new ConfigDescription("Screen vertical offset in pixels\n屏幕垂直偏移(像素)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-5000, 5000), Array.Empty<object>()));
			PanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "PanelScale", 1f, new ConfigDescription("Overall HUD scale\nHUD 整体缩放", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.4f, 3f), Array.Empty<object>()));
			Alignment = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "Alignment", 0, new ConfigDescription("0=Right of stamina bar (default), 1=Left, 2=Center, 3=Right\n对齐方式:0=紧靠体力条右侧(默认) 1=屏幕左 2=屏幕中 3=屏幕右", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
			FontSize = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "FontSize", 18f, new ConfigDescription("Font size (px)\n字体大小", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 48f), Array.Empty<object>()));
			TextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Display", "TextColor", new Color(1f, 0.3f, 0.3f), "Seconds text color (Color)\n秒数文字颜色(Color 格式:R,G,B,A 均 0~1,默认红色)");
			ShowBackground = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowBackground", true, "Show translucent background panel\n显示半透明背景板");
			BackgroundAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "BackgroundAlpha", 0.35f, new ConfigDescription("Background alpha (0~1)\n背景不透明度", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ShowProgress = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowProgress", true, "Show thin progress bar per buff\n每个 buff 显示细进度条");
			UseChinese = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "UseChinese", true, "Use Chinese labels\n使用中文标签");
			Precision = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "Precision", 0.1f, new ConfigDescription("Time precision in seconds (0.01 = 0.01s, 0.1 = 0.1s, 1 = 1s). Default 0.1s; min 0.01s.\n时间精度(秒):0.01=0.01s,0.1=0.1s,1=1s。默认 0.1s,最小 0.01s。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()));
			AutoScanInterval = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "AutoScanInterval", true, "Auto-tune scan interval to match Precision (recommended for performance)\n自动按精度调节扫描频率(推荐,兼顾性能与精确度)");
			ManualScanInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Performance", "ManualScanInterval", 0.1f, new ConfigDescription("Manual scan interval in seconds when AutoScanInterval=false. Higher = fewer allocations.\n关闭自动时手动的扫描间隔(秒),越大越省性能。\n典型值:0.01 = 精确到帧,0.1 = 平衡,1.0 = 极省", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 5f), Array.Empty<object>()));
			Log.LogInfo((object)"[BuffCountdown] loaded v0.7.1");
		}

		private void Update()
		{
			try
			{
				if (Enabled.Value)
				{
					BuffTimerReader.Refresh(AutoScanInterval.Value ? Precision.Value : ManualScanInterval.Value);
				}
			}
			catch (Exception ex)
			{
				Log.LogDebug((object)("Update error: " + ex.Message));
			}
		}

		private void OnGUI()
		{
			CountdownOverlay.Instance.Draw();
		}
	}
	public static class BuffLocalizer
	{
		public static string BuffName(AfflictionType type)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			bool flag = (Object)(object)BuffCountdownPlugin.Instance != (Object)null && BuffCountdownPlugin.Instance.UseChinese.Value;
			if ((int)type <= 2)
			{
				if ((int)type == 1)
				{
					if (!flag)
					{
						return "Infinite Stamina";
					}
					return "无限体力";
				}
				if ((int)type == 2)
				{
					if (!flag)
					{
						return "Speed Boost";
					}
					return "加速";
				}
			}
			else
			{
				if ((int)type == 16)
				{
					if (!flag)
					{
						return "Invincible";
					}
					return "无敌";
				}
				if ((int)type == 17)
				{
					if (!flag)
					{
						return "Low Gravity";
					}
					return "低重力";
				}
			}
			return null;
		}

		public static ColorStyle BuffStyle(AfflictionType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			if ((int)type <= 2)
			{
				if ((int)type == 1)
				{
					return new ColorStyle(0.45f, 0.9f, 0.55f);
				}
				if ((int)type == 2)
				{
					return new ColorStyle(1f, 0.6f, 0.3f);
				}
			}
			else
			{
				if ((int)type == 16)
				{
					return new ColorStyle(1f, 0.85f, 0.35f);
				}
				if ((int)type == 17)
				{
					return new ColorStyle(0.55f, 0.65f, 1f);
				}
			}
			return new ColorStyle(0.85f, 0.85f, 0.85f);
		}

		public static string DelayedLabel()
		{
			if (!((Object)(object)BuffCountdownPlugin.Instance != (Object)null) || !BuffCountdownPlugin.Instance.UseChinese.Value)
			{
				return "Delayed";
			}
			return "延迟生效";
		}

		public static AfflictionType? DelayedMushroomEffectType(int effect)
		{
			return effect switch
			{
				0 => (AfflictionType)1, 
				1 => (AfflictionType)2, 
				2 => (AfflictionType)17, 
				_ => null, 
			};
		}
	}
	public struct BuffTimerInfo
	{
		public string Name;

		public float SumSeconds;

		public float TotalSeconds;

		public bool IsPendingDelay;

		public ColorStyle Style;
	}
	public struct ColorStyle
	{
		public float R;

		public float G;

		public float B;

		public ColorStyle(float r, float g, float b)
		{
			R = r;
			G = g;
			B = b;
		}
	}
	public sealed class ScanSnapshot
	{
		public readonly List<BuffTimerInfo> Entries = new List<BuffTimerInfo>(8);

		public float TimeAtScan;

		public bool Valid;
	}
	public static class BuffTimerReader
	{
		public static readonly ScanSnapshot Snapshot = new ScanSnapshot();

		private static float _nextScanTime = -1f;

		private static FieldInfo _bonusTimeField;

		public static void Refresh(float intervalSeconds)
		{
			float num = ((intervalSeconds <= 0.015f) ? 0.01f : ((intervalSeconds <= 0.15f) ? 0.1f : ((intervalSeconds <= 0.5f) ? 0.5f : 1f)));
			if (num < 0.01f)
			{
				num = 0.01f;
			}
			float time = Time.time;
			if (!(time < _nextScanTime))
			{
				_nextScanTime = time + num;
				if (_bonusTimeField == null)
				{
					_bonusTimeField = typeof(Affliction).GetField("bonusTime", BindingFlags.Instance | BindingFlags.NonPublic);
				}
				ScanAndStore();
			}
		}

		private static void ScanAndStore()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			Snapshot.Entries.Clear();
			Snapshot.TimeAtScan = Time.time;
			Snapshot.Valid = false;
			Character localCharacter;
			try
			{
				localCharacter = Character.localCharacter;
			}
			catch
			{
				return;
			}
			if ((Object)(object)localCharacter == (Object)null)
			{
				return;
			}
			CharacterAfflictions val;
			try
			{
				val = localCharacter.refs?.afflictions;
			}
			catch
			{
				return;
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			List<Affliction> afflictionList;
			try
			{
				afflictionList = val.afflictionList;
			}
			catch
			{
				return;
			}
			if (afflictionList == null)
			{
				return;
			}
			HashSet<AfflictionType> hashSet = new HashSet<AfflictionType>();
			for (int i = 0; i < afflictionList.Count; i++)
			{
				Affliction val2 = afflictionList[i];
				if (val2 == null)
				{
					continue;
				}
				AfflictionType afflictionType;
				try
				{
					afflictionType = val2.GetAfflictionType();
				}
				catch
				{
					continue;
				}
				hashSet.Add(afflictionType);
				string text = BuffLocalizer.BuffName(afflictionType);
				if (text == null)
				{
					continue;
				}
				float totalTime = val2.totalTime;
				if (!(totalTime <= 0f))
				{
					float num = val2.timeElapsed;
					if (num < 0f)
					{
						num = 0f;
					}
					float num2 = totalTime - num;
					if (num2 < 0f)
					{
						num2 = 0f;
					}
					float num3 = num2 + ReadBonusTime(val2);
					if (!(num3 <= 0.0005f))
					{
						Snapshot.Entries.Add(new BuffTimerInfo
						{
							Name = text,
							SumSeconds = num3,
							TotalSeconds = totalTime,
							IsPendingDelay = false,
							Style = BuffLocalizer.BuffStyle(afflictionType)
						});
					}
				}
			}
			PendingDelayTracker.Collect(Snapshot.Entries, hashSet);
			Snapshot.Valid = true;
		}

		private static float ReadBonusTime(Affliction a)
		{
			if (_bonusTimeField == null)
			{
				return 0f;
			}
			try
			{
				if (_bonusTimeField.GetValue(a) is float num && num > 0f)
				{
					return num;
				}
			}
			catch
			{
			}
			return 0f;
		}

		public static float GetDisplayRemain(BuffTimerInfo info)
		{
			float num = Time.time - Snapshot.TimeAtScan;
			if (num < 0f)
			{
				num = 0f;
			}
			float num2 = info.SumSeconds - num;
			if (!(num2 < 0f))
			{
				return num2;
			}
			return 0f;
		}

		public static float GetDisplayRatio(BuffTimerInfo info)
		{
			float num = (info.IsPendingDelay ? 3f : info.TotalSeconds);
			if (num <= 0f)
			{
				return 0f;
			}
			return Mathf.Clamp01(GetDisplayRemain(info) / num);
		}
	}
	public class CountdownOverlay
	{
		public static readonly CountdownOverlay Instance = new CountdownOverlay();

		private GUIStyle _leftStyle;

		private GUIStyle _rightStyle;

		private Texture2D _whiteTex;

		private static readonly RectOffset Zero = new RectOffset(0, 0, 0, 0);

		private void EnsureAssets()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			if ((Object)(object)_whiteTex == (Object)null)
			{
				_whiteTex = new Texture2D(1, 1);
				_whiteTex.SetPixel(0, 0, Color.white);
				_whiteTex.Apply();
				((Object)_whiteTex).hideFlags = (HideFlags)61;
			}
			if (_leftStyle == null)
			{
				_leftStyle = new GUIStyle();
				_leftStyle.alignment = (TextAnchor)3;
				_leftStyle.normal.textColor = Color.white;
				_leftStyle.normal.background = null;
				_leftStyle.padding = Zero;
				_leftStyle.margin = Zero;
				_leftStyle.border = Zero;
				_leftStyle.clipping = (TextClipping)1;
			}
			if (_rightStyle == null)
			{
				_rightStyle = new GUIStyle(_leftStyle);
				_rightStyle.alignment = (TextAnchor)5;
			}
		}

		public void Draw()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if (Event.current == null || (int)Event.current.type != 7 || (Object)(object)BuffCountdownPlugin.Instance == (Object)null || !BuffCountdownPlugin.Instance.Enabled.Value)
			{
				return;
			}
			ScanSnapshot snapshot = BuffTimerReader.Snapshot;
			if (snapshot == null || !snapshot.Valid || snapshot.Entries.Count == 0)
			{
				return;
			}
			try
			{
				EnsureAssets();
				RenderHud();
			}
			catch (Exception ex)
			{
				BuffCountdownPlugin.Log.LogDebug((object)("Draw render error: " + ex.Message));
			}
		}

		private void RenderHud()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			BuffCountdownPlugin instance = BuffCountdownPlugin.Instance;
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.skin.font = null;
			EnsureAssets();
			float num = Mathf.Max(0.3f, instance.PanelScale.Value);
			int value = instance.Alignment.Value;
			int value2 = instance.OffsetX.Value;
			int value3 = instance.OffsetY.Value;
			float num2 = Mathf.Max(6f, instance.FontSize.Value) * num;
			int fontSize = Mathf.RoundToInt(num2);
			_leftStyle.fontSize = fontSize;
			_rightStyle.fontSize = fontSize;
			ScanSnapshot snapshot = BuffTimerReader.Snapshot;
			int count = snapshot.Entries.Count;
			float num3 = 18f * num;
			float num4 = 2f * num;
			bool value4 = instance.ShowProgress.Value;
			float num5 = (value4 ? (num4 + 2f * num) : 0f);
			float num6 = 4f * num;
			float num7 = 8f * num;
			float num8 = 8f * num;
			float num9 = 6f * num;
			float num10 = 6f * num;
			float num11 = 10f * num;
			float num12 = num3 + num5;
			bool value5 = instance.ShowBackground.Value;
			string fmt = "0." + new string('0', Mathf.Max(1, PrecisionToDecimals(instance.Precision.Value)));
			string delayedLabel = BuffLocalizer.DelayedLabel();
			Color value6 = instance.TextColor.Value;
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.78f, 0.35f);
			float num13 = 0f;
			float num14 = 0f;
			for (int i = 0; i < count; i++)
			{
				BuffTimerInfo info = snapshot.Entries[i];
				float num15 = MeasureTextWidth(info.Name, num2);
				float num16 = MeasureTextWidth(BuildTimeText(info, fmt, delayedLabel), num2);
				if (num15 > num13)
				{
					num13 = num15;
				}
				if (num16 > num14)
				{
					num14 = num16;
				}
			}
			float num17 = num13 + num11 + num14;
			float num18 = num17 + num7 + num8;
			if (value5)
			{
				num18 += num9 * 2f;
			}
			float num19 = (float)count * num12 + (float)Mathf.Max(0, count - 1) * num6;
			if (value5)
			{
				num19 += num10 * 2f;
			}
			float num20;
			float num21;
			if (value == 0 && StaminaBarAnchor.TryGet(out var guiRightX, out var guiCenterY))
			{
				num20 = guiRightX + 8f + (float)value2;
				num21 = guiCenterY - num19 * 0.5f + (float)value3;
			}
			else
			{
				num20 = ((value == 0) ? 1 : value) switch
				{
					1 => 16f + (float)value2, 
					3 => (float)Screen.width - 16f - num18 + (float)value2, 
					_ => Mathf.Round(((float)Screen.width - num18) / 2f) + (float)value2, 
				};
				num21 = (float)Screen.height - num19 - 16f + (float)value3;
			}
			if (num20 + num18 > (float)Screen.width)
			{
				num20 = (float)Screen.width - num18;
			}
			if (num20 < 0f)
			{
				num20 = 0f;
			}
			if (num21 + num19 > (float)Screen.height)
			{
				num21 = (float)Screen.height - num19;
			}
			if (num21 < 0f)
			{
				num21 = 0f;
			}
			float num22 = num20 + num7;
			float num23 = num21 + (value5 ? num10 : 0f);
			if (value5)
			{
				GUI.color = new Color(0f, 0f, 0f, Mathf.Clamp01(instance.BackgroundAlpha.Value));
				GUI.DrawTexture(new Rect(num20, num21, num18, num19), (Texture)(object)_whiteTex, (ScaleMode)0);
				GUI.color = Color.white;
			}
			for (int j = 0; j < count; j++)
			{
				BuffTimerInfo info2 = snapshot.Entries[j];
				float num24 = num23 + (float)j * (num12 + num6);
				string text = BuildTimeText(info2, fmt, delayedLabel);
				Color textColor = (info2.IsPendingDelay ? val : value6);
				_leftStyle.normal.textColor = new Color(info2.Style.R, info2.Style.G, info2.Style.B, 1f);
				DrawShadedLabel(new Rect(num22, num24, num17, num3), info2.Name, _leftStyle, num);
				_rightStyle.normal.textColor = textColor;
				DrawShadedLabel(new Rect(num22, num24, num17, num3), text, _rightStyle, num);
				if (value4)
				{
					float displayRatio = BuffTimerReader.GetDisplayRatio(info2);
					float num25 = num24 + num3 + 1f * num;
					GUI.color = new Color(0f, 0f, 0f, 0.55f);
					GUI.DrawTexture(new Rect(num22, num25, num17, num4), (Texture)(object)_whiteTex, (ScaleMode)0);
					GUI.color = new Color(info2.Style.R, info2.Style.G, info2.Style.B, 0.95f);
					GUI.DrawTexture(new Rect(num22, num25, num17 * displayRatio, num4), (Texture)(object)_whiteTex, (ScaleMode)0);
					GUI.color = Color.white;
				}
			}
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.skin.font = null;
		}

		private string BuildTimeText(BuffTimerInfo info, string fmt, string delayedLabel)
		{
			float displayRemain = BuffTimerReader.GetDisplayRemain(info);
			if (!info.IsPendingDelay)
			{
				return displayRemain.ToString(fmt) + "s";
			}
			return delayedLabel + " " + displayRemain.ToString(fmt) + "s";
		}

		private float MeasureTextWidth(string text, float fontSize)
		{
			if (string.IsNullOrEmpty(text))
			{
				return 0f;
			}
			float num = 0f;
			for (int i = 0; i < text.Length; i++)
			{
				num += ((text[i] > '\u007f') ? fontSize : (fontSize * 0.55f));
			}
			return num;
		}

		private void DrawShadedLabel(Rect rect, string text, GUIStyle style, float scale)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(((Rect)(ref rect)).x + 1f * scale, ((Rect)(ref rect)).y + 1f * scale, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), text, style);
			GUI.Label(rect, text, style);
		}

		private int PrecisionToDecimals(float p)
		{
			if (p < 0.015f)
			{
				return 2;
			}
			if (p < 0.15f)
			{
				return 1;
			}
			return 0;
		}
	}
	internal static class MushroomEffectHook
	{
		public static void TryPatch(Harmony harmony)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Action_RandomMushroomEffect), "RunAction", (Type[])null, (Type[])null);
				if (!(methodInfo == null))
				{
					MethodInfo methodInfo2 = AccessTools.Method(typeof(MushroomEffectHook), "Postfix", (Type[])null, (Type[])null);
					if (!(methodInfo2 == null))
					{
						harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
				}
			}
			catch
			{
			}
		}

		private static void Postfix(Action_RandomMushroomEffect __instance)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				int effect;
				if (__instance.useDebugEffect)
				{
					effect = __instance.debugEffect;
				}
				else
				{
					MushroomManager instance = MushroomManager.instance;
					if ((Object)(object)instance == (Object)null || instance.mushroomEffects == null || instance.mushroomEffects.Length == 0)
					{
						return;
					}
					int num = __instance.mushroomTypeIndex % instance.mushroomEffects.Length;
					if (num < 0)
					{
						num += instance.mushroomEffects.Length;
					}
					effect = instance.mushroomEffects[num];
				}
				AfflictionType? val = BuffLocalizer.DelayedMushroomEffectType(effect);
				if (val.HasValue)
				{
					PendingDelayTracker.Add(val.Value);
				}
			}
			catch
			{
			}
		}
	}
	public static class PendingDelayTracker
	{
		private struct Pending
		{
			public float StartTime;

			public AfflictionType Type;
		}

		public const float DelaySeconds = 3f;

		private static readonly List<Pending> Items = new List<Pending>(4);

		public static void Add(AfflictionType type)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Items.Add(new Pending
			{
				StartTime = Time.time,
				Type = type
			});
		}

		public static void Clear()
		{
			Items.Clear();
		}

		public static void Collect(List<BuffTimerInfo> output, HashSet<AfflictionType> presentTypes)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			for (int num = Items.Count - 1; num >= 0; num--)
			{
				float num2 = 3f - (time - Items[num].StartTime);
				if (num2 <= 0f || presentTypes.Contains(Items[num].Type))
				{
					Items.RemoveAt(num);
				}
				else
				{
					string text = BuffLocalizer.BuffName(Items[num].Type);
					if (text == null)
					{
						Items.RemoveAt(num);
					}
					else
					{
						output.Add(new BuffTimerInfo
						{
							Name = text,
							SumSeconds = num2,
							TotalSeconds = 3f,
							IsPendingDelay = true,
							Style = BuffLocalizer.BuffStyle(Items[num].Type)
						});
					}
				}
			}
		}
	}
	public static class StaminaBarAnchor
	{
		private static StaminaBar _cached;

		private static float _nextSearchTime = -1f;

		public static bool TryGet(out float guiRightX, out float guiCenterY)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			guiRightX = 0f;
			guiCenterY = 0f;
			StaminaBar val = Resolve();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			RectTransform val2 = (RectTransform)(((Object)(object)val.fullBar != (Object)null) ? val.fullBar : (((Object)(object)val.staminaBar != (Object)null) ? ((object)val.staminaBar) : ((object)/*isinst with value type is only supported in some contexts*/)));
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			try
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				val2.GetWorldCorners(array);
				Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>();
				Camera val3 = null;
				if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0)
				{
					val3 = componentInParent.worldCamera;
				}
				Vector2 val4 = RectTransformUtility.WorldToScreenPoint(val3, array[0]);
				Vector2 val5 = RectTransformUtility.WorldToScreenPoint(val3, array[2]);
				guiRightX = Mathf.Max(val4.x, val5.x);
				float num = (val4.y + val5.y) * 0.5f;
				guiCenterY = (float)Screen.height - num;
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static StaminaBar Resolve()
		{
			if ((Object)(object)_cached != (Object)null)
			{
				return _cached;
			}
			float time = Time.time;
			if (time < _nextSearchTime)
			{
				return null;
			}
			_nextSearchTime = time + 1f;
			try
			{
				_cached = Object.FindAnyObjectByType<StaminaBar>();
			}
			catch
			{
				_cached = null;
			}
			return _cached;
		}
	}
}