Decompiled source of Numbers Guy v0.1.0

NumbersGuy.dll

Decompiled 35 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using I2.Loc;
using Microsoft.CodeAnalysis;
using NumbersGuy.Capture;
using NumbersGuy.Diagnostics;
using NumbersGuy.Display;
using NumbersGuy.Formula;
using NumbersGuy.Localization;
using NumbersGuy.Scoreboard;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.Items;
using PerfectRandom.Sulfur.Core.Stats;
using PerfectRandom.Sulfur.Core.Units;
using PerfectRandom.Sulfur.Core.Weapons;
using TMPro;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Numbers Guy")]
[assembly: AssemblyProduct("Numbers Guy")]
[assembly: AssemblyCompany("Ryuka")]
[assembly: ComVisible(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 NumbersGuy
{
	public static class NumbersGuyIntegration
	{
		private const float MaxHitBonus = 10f;

		private static Func<bool> _isResolvingRemoteHit;

		private static Func<float> _currentHitBonus;

		internal static bool IsResolvingRemoteHit
		{
			get
			{
				Func<bool> isResolvingRemoteHit = _isResolvingRemoteHit;
				if (isResolvingRemoteHit == null)
				{
					return false;
				}
				try
				{
					return isResolvingRemoteHit();
				}
				catch (Exception ex)
				{
					if ((object)_isResolvingRemoteHit == isResolvingRemoteHit)
					{
						_isResolvingRemoteHit = null;
						Plugin.Log.LogError((object)("Telling other players' hits apart is off for this session: the check failed. " + ex));
					}
					return false;
				}
			}
		}

		internal static float CurrentHitBonus
		{
			get
			{
				Func<float> currentHitBonus = _currentHitBonus;
				if (currentHitBonus == null)
				{
					return 1f;
				}
				try
				{
					return SanitizeBonus(currentHitBonus());
				}
				catch (Exception ex)
				{
					if ((object)_currentHitBonus == currentHitBonus)
					{
						_currentHitBonus = null;
						Plugin.Log.LogError((object)("Hit bonuses are off for this session: reading one failed. " + ex));
					}
					return 1f;
				}
			}
		}

		public static void SetRemoteHitScope(Func<bool> isResolvingRemoteHit)
		{
			_isResolvingRemoteHit = isResolvingRemoteHit;
		}

		public static void SetHitBonusScope(Func<float> currentHitBonus)
		{
			_currentHitBonus = currentHitBonus;
		}

		internal static float SanitizeBonus(float bonus)
		{
			if (float.IsNaN(bonus) || float.IsInfinity(bonus) || bonus <= 1.0001f || bonus > 10f)
			{
				return 1f;
			}
			return bonus;
		}

		internal static void Reset()
		{
			_isResolvingRemoteHit = null;
			_currentHitBonus = null;
		}
	}
	[BepInPlugin("ryuka.sulfur.numbers_guy", "Numbers Guy", "0.1.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "ryuka.sulfur.numbers_guy";

		public const string PluginName = "Numbers Guy";

		public const string PluginVersion = "0.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> FormulaEnabled;

		internal static ConfigEntry<TargetScope> FormulaTargets;

		internal static ConfigEntry<bool> ReduceFormulaAnimation;

		internal static ConfigEntry<float> FormulaHoldTime;

		internal static ConfigEntry<bool> FormulaShowDamageOverTime;

		internal static ConfigEntry<float> FormulaScale;

		internal static ConfigEntry<ScoreboardStyle> ScoreboardStyleSetting;

		internal static ConfigEntry<TargetScope> ScoreboardTargets;

		internal static ConfigEntry<Key> ScoreboardResetKey;

		internal static ConfigEntry<bool> DebugLog;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			FormulaEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Formula", "Enabled", true, "Show the math behind each hit at the top of the screen.");
			FormulaTargets = ((BaseUnityPlugin)this).Config.Bind<TargetScope>("Formula", "Targets", TargetScope.DummiesOnly, "Which hits get a formula. DummiesOnly is just the target dummies. DummiesAndEnemies adds every enemy you hit.");
			ReduceFormulaAnimation = ((BaseUnityPlugin)this).Config.Bind<bool>("Formula", "ReduceAnimation", false, "Turn off the pop-in, shake and sliding numbers. The formula just fades in and out.");
			FormulaHoldTime = ((BaseUnityPlugin)this).Config.Bind<float>("Formula", "HoldTime", 2.5f, new ConfigDescription("Seconds the formula stays up after your last hit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 6f), Array.Empty<object>()));
			FormulaShowDamageOverTime = ((BaseUnityPlugin)this).Config.Bind<bool>("Formula", "ShowDamageOverTime", false, "Also show ticks from burning, poison and other effects. Each tick replaces the weapon formula on screen.");
			FormulaScale = ((BaseUnityPlugin)this).Config.Bind<float>("Formula", "Scale", 1f, new ConfigDescription("How big the formula is. 1 is the normal size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), Array.Empty<object>()));
			ScoreboardStyleSetting = ((BaseUnityPlugin)this).Config.Bind<ScoreboardStyle>("Scoreboard", "Style", ScoreboardStyle.Side, "Side is a card on the right of the screen. Line puts two short lines under the crosshair. Off hides it.");
			ScoreboardTargets = ((BaseUnityPlugin)this).Config.Bind<TargetScope>("Scoreboard", "Targets", TargetScope.DummiesOnly, "Which hits count on the scoreboard. With enemies included, every enemy you hit adds to the same card.");
			ScoreboardResetKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Scoreboard", "ResetKey", (Key)71, "Clears the scoreboard. Counting starts again on your next hit. The card keeps its numbers until you press it, and its clock stops after 5 seconds without a hit.");
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLog", false, "Write hit details to the log. Doesn't change what you see.");
			_harmony = new Harmony("ryuka.sulfur.numbers_guy");
			if (HitCapture.Apply(_harmony))
			{
				HitProbeLog.Attach();
				HudRoot.Create(HudRoot.DirectoryOf(((BaseUnityPlugin)this).Info.Location));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Numbers Guy 0.1.0 loaded.");
		}

		private void OnDestroy()
		{
			HudRoot.DestroyInstance();
			HitProbeLog.Detach();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			HitCapture.Reset();
			NumbersGuyIntegration.Reset();
		}
	}
	public enum TargetScope
	{
		DummiesOnly = 1,
		DummiesAndEnemies
	}
	public enum ScoreboardStyle
	{
		Off,
		Side,
		Line
	}
}
namespace NumbersGuy.Scoreboard
{
	internal sealed class RedrawGate
	{
		private bool _valid;

		private ScoreSession _session;

		private int _version;

		private bool _paused;

		private string _resetKey;

		private string _weaponName;

		private string _language;

		public bool Changed(ScoreSession s, bool paused, string resetKey)
		{
			string gameCode = LangText.GameCode;
			if (_valid && s == _session && s.Version == _version && paused == _paused && resetKey == _resetKey && s.Weapon.Name == _weaponName && gameCode == _language)
			{
				return false;
			}
			_valid = true;
			_session = s;
			_version = s.Version;
			_paused = paused;
			_resetKey = resetKey;
			_weaponName = s.Weapon.Name;
			_language = gameCode;
			return true;
		}

		public void Invalidate()
		{
			_valid = false;
			_session = null;
		}
	}
	internal sealed class ScoreboardTracker
	{
		private struct Fired
		{
			public int WeaponId;

			public float Time;
		}

		private const float RecentSeconds = 2f;

		private readonly List<Fired> _recentShots = new List<Fired>();

		private readonly List<Fired> _recentProjectiles = new List<Fired>();

		private Weapon _weapon;

		public ScoreSession Current { get; private set; }

		public void OnShot(ShotRecord shot)
		{
			if (!((Object)(object)shot.Weapon == (Object)null))
			{
				int instanceID = ((Object)shot.Weapon).GetInstanceID();
				if (Counting(instanceID, shot.Time))
				{
					Current.AddShot();
				}
				else
				{
					Remember(_recentShots, instanceID, shot.Time);
				}
			}
		}

		public void OnProjectile(ShotRecord shot)
		{
			if (!((Object)(object)shot.Weapon == (Object)null))
			{
				int instanceID = ((Object)shot.Weapon).GetInstanceID();
				if (Counting(instanceID, shot.Time))
				{
					Current.AddProjectile();
				}
				else
				{
					Remember(_recentProjectiles, instanceID, shot.Time);
				}
			}
		}

		public void OnOutcome(ShotOutcome outcome, float now, bool includeEnemies)
		{
			if (outcome.Periodic || (Object)(object)outcome.Weapon == (Object)null)
			{
				return;
			}
			List<CountedHit> list = null;
			bool flag = false;
			for (int i = 0; i < outcome.Targets.Count; i++)
			{
				TargetHits targetHits = outcome.Targets[i];
				if (targetHits.IsDummy || includeEnemies)
				{
					if (list == null)
					{
						list = new List<CountedHit>();
					}
					list.AddRange(targetHits.Hits);
					if (!targetHits.IsDummy)
					{
						flag = true;
					}
				}
			}
			if (list != null)
			{
				int instanceID = ((Object)outcome.Weapon).GetInstanceID();
				if (Current == null || Current.Weapon.Id != instanceID)
				{
					Start(outcome.Weapon, instanceID, now);
				}
				else if (Current.IsPaused(now))
				{
					Resume(instanceID, now);
				}
				if (flag)
				{
					Current.HitEnemies = true;
				}
				for (int j = 0; j < list.Count; j++)
				{
					Current.AddHit(now, list[j].Role == HitRole.Main, list[j].Terms, list[j].CritChance);
				}
			}
		}

		public void Tick(float now)
		{
			Prune(_recentShots, now);
			Prune(_recentProjectiles, now);
		}

		public void Reset()
		{
			Current = null;
			_weapon = null;
			_recentShots.Clear();
			_recentProjectiles.Clear();
		}

		private bool Counting(int weaponId, float time)
		{
			if (Current != null && Current.Weapon.Id == weaponId)
			{
				return !Current.IsPaused(time);
			}
			return false;
		}

		private void Start(Weapon weapon, int id, float now)
		{
			WeaponInfo weaponInfo = new WeaponInfo
			{
				Id = id,
				Name = WeaponName(weapon),
				Melee = weapon.IsMelee,
				Cooldown = weapon.cooldown
			};
			if ((Object)(object)weapon.weaponDefinition != (Object)null)
			{
				weaponInfo.MagazineSize = weapon.weaponDefinition.iAmmoMax;
				weaponInfo.ReloadTime = weapon.weaponDefinition.fReloadTime;
				weaponInfo.AmmoPerShot = AmmoPerShot(weapon);
			}
			Current = new ScoreSession(weaponInfo, now, TimesOf(_recentShots, id), TimesOf(_recentProjectiles, id));
			_weapon = weapon;
			Forget(id);
		}

		public void RefreshWeaponName()
		{
			if (Current != null && !((Object)(object)_weapon == (Object)null))
			{
				Current.Weapon.Name = WeaponName(_weapon);
			}
		}

		private static int AmmoPerShot(Weapon weapon)
		{
			try
			{
				if (((Holdable)weapon).ItemStats != null && ((Holdable)weapon).ItemStats.GetAttribute((ItemAttributes)113) > 0f)
				{
					return 1;
				}
				return Math.Max(1, weapon.weaponDefinition.iMaxAmmoPerShot);
			}
			catch (Exception)
			{
				return 1;
			}
		}

		private void Resume(int id, float now)
		{
			Current.Resume(now, TimesOf(_recentShots, id), TimesOf(_recentProjectiles, id));
			Forget(id);
		}

		private void Forget(int id)
		{
			_recentShots.RemoveAll((Fired f) => f.WeaponId == id);
			_recentProjectiles.RemoveAll((Fired f) => f.WeaponId == id);
		}

		private static string WeaponName(Weapon weapon)
		{
			try
			{
				if ((Object)(object)weapon.weaponDefinition != (Object)null)
				{
					return ((ItemDefinition)weapon.weaponDefinition).LocalizedDisplayName;
				}
			}
			catch (Exception)
			{
			}
			return ((Object)weapon).name;
		}

		private static void Remember(List<Fired> list, int id, float time)
		{
			list.Add(new Fired
			{
				WeaponId = id,
				Time = time
			});
		}

		private static void Prune(List<Fired> list, float now)
		{
			int i;
			for (i = 0; i < list.Count && now - list[i].Time > 2f; i++)
			{
			}
			if (i > 0)
			{
				list.RemoveRange(0, i);
			}
		}

		private static List<float> TimesOf(List<Fired> list, int id)
		{
			List<float> list2 = new List<float>();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].WeaponId == id)
				{
					list2.Add(list[i].Time);
				}
			}
			return list2;
		}
	}
	internal sealed class ScoreboardView
	{
		private sealed class Row
		{
			public TextMeshProUGUI Left;

			public TextMeshProUGUI Right;
		}

		private const float Scale = 1.1829134f;

		private const float Width = 295.72836f;

		private const float Right = 21.292442f;

		private const float Top = 295.72836f;

		private const float Border = 2f;

		private const float HeaderHeight = 30.755749f;

		private const float PadX = 10.646221f;

		private const float PadTop = 5.914567f;

		private const float PadBottom = 8.280394f;

		private const float FontSize = 14.194962f;

		private const float LineHeight = 22.002188f;

		private const float SmallFontSize = 13.012048f;

		private const float HeaderFontSize = 15.377874f;

		private const float BigFontSize = 35.487404f;

		private const float BigHeight = 37.261772f;

		private const float BarHeight = 10.646221f;

		private const float RowGap = 9.463307f;

		private static readonly Color Orange = UiKit.Hex(16560193);

		private static readonly Color Ink = UiKit.Hex(2301472);

		private static readonly Color BodyColor = new Color(0.18039216f, 0.24313726f, 22f / 85f, 0.93f);

		private static readonly Color TextColor = UiKit.Hex(15001311);

		private static readonly Color[] PartColors = (Color[])(object)new Color[6]
		{
			UiKit.Hex(14406595),
			UiKit.Hex(15816762),
			UiKit.Hex(16560193),
			UiKit.Hex(11385194),
			UiKit.Hex(6984098),
			UiKit.Hex(9215134)
		};

		private readonly RectTransform _card;

		private readonly RedrawGate _gate = new RedrawGate();

		private readonly TextMeshProUGUI _headerLeft;

		private readonly TextMeshProUGUI _headerRight;

		private readonly float _headerWidth;

		private readonly TextMeshProUGUI _big;

		private readonly TextMeshProUGUI _bigNote;

		private readonly RectTransform _bar;

		private readonly Image[] _barParts = (Image[])(object)new Image[6];

		private readonly Image[] _legendSquares = (Image[])(object)new Image[6];

		private readonly TextMeshProUGUI[] _legendTexts = (TextMeshProUGUI[])(object)new TextMeshProUGUI[6];

		private readonly List<Row> _rows = new List<Row>();

		private TMP_FontAsset _semibold;

		private TMP_FontAsset _bold;

		private TMP_FontAsset _numbers;

		private int _rowCount;

		private float _y;

		public ScoreboardView(RectTransform canvas, TMP_FontAsset bold, TMP_FontAsset semibold)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			_semibold = semibold;
			_bold = bold;
			GameObject val = new GameObject("Scoreboard", new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasGroup)
			});
			_card = (RectTransform)val.transform;
			((Transform)_card).SetParent((Transform)(object)canvas, false);
			_card.anchorMin = new Vector2(1f, 1f);
			_card.anchorMax = new Vector2(1f, 1f);
			_card.pivot = new Vector2(1f, 1f);
			_card.anchoredPosition = new Vector2(-21.292442f, -295.72836f);
			CanvasGroup component = val.GetComponent<CanvasGroup>();
			component.interactable = false;
			component.blocksRaycasts = false;
			Stretch(((Graphic)UiKit.Image("Frame", (Transform)(object)_card, Orange, UiKit.Rounded(12))).rectTransform, 0f, 0f, 0f, 0f);
			Stretch(((Graphic)UiKit.Image("Body", (Transform)(object)_card, BodyColor, UiKit.Rounded(10, roundTop: false))).rectTransform, 2f, 30.755749f, 2f, 2f);
			float num = 270.4359f;
			_headerLeft = UiKit.Text("Title", (Transform)(object)_card, bold, 15.377874f, Ink, (TextAlignmentOptions)4097);
			_headerRight = UiKit.Text("State", (Transform)(object)_card, bold, 13.012048f, Ink, (TextAlignmentOptions)4100);
			UiKit.Place(((TMP_Text)_headerLeft).rectTransform, 12.646221f, 0f, num, 30.755749f);
			UiKit.Place(((TMP_Text)_headerRight).rectTransform, 12.646221f, 0f, num, 30.755749f);
			((TMP_Text)_headerLeft).overflowMode = (TextOverflowModes)3;
			_headerWidth = num;
			_big = UiKit.Text("Dps", (Transform)(object)_card, bold, 35.487404f, Orange, (TextAlignmentOptions)1025);
			_bigNote = UiKit.Text("DpsNote", (Transform)(object)_card, semibold, 14.194962f, TextColor, (TextAlignmentOptions)1028);
			Image val2 = UiKit.Image("Parts", (Transform)(object)_card, Color.white, UiKit.Rounded(4));
			((Component)val2).gameObject.AddComponent<Mask>().showMaskGraphic = false;
			_bar = ((Graphic)val2).rectTransform;
			for (int i = 0; i < _barParts.Length; i++)
			{
				_barParts[i] = UiKit.Image("Part" + i, (Transform)(object)_bar, PartColors[i]);
				_legendSquares[i] = UiKit.Image("Key" + i, (Transform)(object)_card, PartColors[i], UiKit.Rounded(2));
				_legendTexts[i] = UiKit.Text("KeyText" + i, (Transform)(object)_card, semibold, 13.012048f, TextColor, (TextAlignmentOptions)4097);
			}
			val.SetActive(false);
		}

		public void SetFonts(TMP_FontAsset bold, TMP_FontAsset semibold)
		{
			_gate.Invalidate();
			_semibold = semibold;
			_bold = bold;
			((TMP_Text)_headerLeft).font = bold;
			((TMP_Text)_headerRight).font = bold;
			((TMP_Text)_big).font = bold;
			((TMP_Text)_bigNote).font = semibold;
			for (int i = 0; i < _legendTexts.Length; i++)
			{
				((TMP_Text)_legendTexts[i]).font = semibold;
			}
			for (int j = 0; j < _rows.Count; j++)
			{
				((TMP_Text)_rows[j].Left).font = semibold;
				((TMP_Text)_rows[j].Right).font = semibold;
			}
		}

		public void SetNumberFont(TMP_FontAsset numbers)
		{
			_gate.Invalidate();
			_numbers = numbers;
		}

		private void FitTitle()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0f, _headerWidth - ((TMP_Text)_headerRight).preferredWidth - 10.646221f);
			RectTransform rectTransform = ((TMP_Text)_headerLeft).rectTransform;
			if (Mathf.Abs(rectTransform.sizeDelta.x - num) > 0.5f)
			{
				rectTransform.sizeDelta = new Vector2(num, rectTransform.sizeDelta.y);
			}
		}

		public void Hide()
		{
			_gate.Invalidate();
			if (((Component)_card).gameObject.activeSelf)
			{
				((Component)_card).gameObject.SetActive(false);
			}
		}

		public void Show(ScoreSession s, bool paused, string resetKey)
		{
			if (_gate.Changed(s, paused, resetKey))
			{
				Begin();
				string text = (s.HitEnemies ? ScoreText.L("score.headerFight", "Fight · {0}") : ScoreText.L("score.headerRange", "Range · {0}"));
				UiKit.Set(_headerLeft, text.Replace("{0}", s.Weapon.Name));
				UiKit.Set(_headerRight, paused ? ScoreText.L("score.paused", "Paused") : ScoreText.L("score.recording", "● Recording"));
				FitTitle();
				BigRow(s.HasRate ? ScoreText.Dps(s.Dps) : "—", ScoreText.DimText(ScoreText.L("score.measured", "DPS (measured)")));
				if (!s.Weapon.Melee && s.PaperBurstDps > 0f)
				{
					float paperSustainedDps = s.PaperSustainedDps;
					string text2 = ((paperSustainedDps > 0f) ? ScoreText.L("score.paperLine", "On paper: sustained {0} · burst {1}").Replace("{0}", ScoreText.Dps(paperSustainedDps)).Replace("{1}", ScoreText.Dps(s.PaperBurstDps)) : ScoreText.L("score.paperBurst", "On paper: burst {0}").Replace("{0}", ScoreText.Dps(s.PaperBurstDps)));
					AddRow(ScoreText.DimText(text2), "");
				}
				_y += 4.7316537f;
				AddRow(ScoreText.L("score.time", "Time"), ScoreText.Seconds(s.Duration));
				AddRow(ScoreText.L("score.damage", "Total damage"), ScoreText.Amount(s.TotalDamage));
				HitRow(s);
				CritRow(s);
				PartsBar(s);
				if (!string.IsNullOrEmpty(resetKey))
				{
					_y += 4.7316537f;
					AddRow(ScoreText.DimText(ScoreText.L("score.resetHint", "Press {0} to clear").Replace("{0}", resetKey)), "");
				}
				End();
			}
		}

		private void HitRow(ScoreSession s)
		{
			if (!s.Weapon.Melee && s.Projectiles > 0)
			{
				string text = ScoreText.L("score.hitsOf", "{0} / {1} shots").Replace("{0}", s.MainHits.ToString(CultureInfo.InvariantCulture)).Replace("{1}", s.Projectiles.ToString(CultureInfo.InvariantCulture));
				AddRow(ScoreText.L("score.hits", "Hits"), text + "\u3000" + ScoreText.Percent(s.HitRate));
			}
			else
			{
				AddRow(ScoreText.L("score.hits", "Hits"), s.MainHits.ToString(CultureInfo.InvariantCulture));
			}
		}

		private void CritRow(ScoreSession s)
		{
			if (!s.Weapon.Melee)
			{
				AddRow(ScoreText.L("score.crits", "Crits"), s.Crits + " / " + s.MainHits + "\u3000" + ScoreText.DimText(ScoreText.L("score.critChance", "chance {0}").Replace("{0}", ScoreText.Percent(s.AverageCritChance))));
			}
		}

		private void PartsBar(ScoreSession s)
		{
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < 6; i++)
			{
				num += s.PartCount((PartGroup)i);
			}
			bool flag = num > 0;
			if (((Component)_bar).gameObject.activeSelf != flag)
			{
				((Component)_bar).gameObject.SetActive(flag);
			}
			for (int j = 0; j < 6; j++)
			{
				bool flag2 = flag && s.PartCount((PartGroup)j) > 0;
				if (((Component)_legendSquares[j]).gameObject.activeSelf != flag2)
				{
					((Component)_legendSquares[j]).gameObject.SetActive(flag2);
				}
				if (((Component)_legendTexts[j]).gameObject.activeSelf != flag2)
				{
					((Component)_legendTexts[j]).gameObject.SetActive(flag2);
				}
			}
			if (!flag)
			{
				return;
			}
			float num2 = 270.4359f;
			_y += 4.7316537f;
			UiKit.Place(_bar, 12.646221f, _y, num2, 10.646221f);
			float num3 = 0f;
			for (int k = 0; k < 6; k++)
			{
				float num4 = num2 * (float)s.PartCount((PartGroup)k) / (float)num;
				UiKit.Place(((Graphic)_barParts[k]).rectTransform, num3, 0f, num4, 10.646221f);
				num3 += num4;
			}
			_y += 13.012048f;
			float num5 = 12.646221f;
			float num6 = num5;
			float num7 = 20.168673f;
			float num8 = 9.463307f;
			for (int l = 0; l < 6; l++)
			{
				int num9 = s.PartCount((PartGroup)l);
				if (num9 != 0)
				{
					TextMeshProUGUI obj = _legendTexts[l];
					UiKit.Set(obj, ScoreText.PartName((PartGroup)l) + " " + ScoreText.Percent((float)num9 / (float)num));
					float x = ((TMP_Text)obj).GetPreferredValues(((TMP_Text)obj).text).x;
					float num10 = num8 + 3.5487404f + x;
					if (num6 > num5 && num6 + num10 > num5 + num2)
					{
						num6 = num5;
						_y += num7;
					}
					UiKit.Place(((Graphic)_legendSquares[l]).rectTransform, num6, _y + (num7 - num8) / 2f, num8, num8);
					UiKit.Place(((TMP_Text)obj).rectTransform, num6 + num8 + 3.5487404f, _y, x + 2f, num7);
					num6 += num10 + 10.646221f;
				}
			}
			_y += num7;
		}

		private void Begin()
		{
			if (!((Component)_card).gameObject.activeSelf)
			{
				((Component)_card).gameObject.SetActive(true);
			}
			_rowCount = 0;
			_y = 36.670315f;
		}

		private void End()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			for (int i = _rowCount; i < _rows.Count; i++)
			{
				if (((Component)_rows[i].Left).gameObject.activeSelf)
				{
					((Component)_rows[i].Left).gameObject.SetActive(false);
				}
				if (((Component)_rows[i].Right).gameObject.activeSelf)
				{
					((Component)_rows[i].Right).gameObject.SetActive(false);
				}
			}
			_card.sizeDelta = new Vector2(295.72836f, _y + 8.280394f + 2f);
		}

		private void BigRow(string value, string note)
		{
			float width = 270.4359f;
			TMP_FontAsset val = (((Object)(object)_numbers != (Object)null && UiKit.Covers(_numbers, value)) ? _numbers : _bold);
			if ((Object)(object)((TMP_Text)_big).font != (Object)(object)val)
			{
				((TMP_Text)_big).font = val;
			}
			UiKit.Set(_big, value);
			UiKit.Set(_bigNote, note);
			UiKit.Place(((TMP_Text)_big).rectTransform, 12.646221f, _y, width, 37.261772f);
			UiKit.Place(((TMP_Text)_bigNote).rectTransform, 12.646221f, _y, width, 33.71303f);
			_y += 37.261772f;
		}

		private void AddRow(string left, string right)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			if (_rowCount == _rows.Count)
			{
				_rows.Add(new Row
				{
					Left = ShrinkToFit(UiKit.Text("RowLeft", (Transform)(object)_card, _semibold, 14.194962f, TextColor, (TextAlignmentOptions)4097)),
					Right = UiKit.Text("RowRight", (Transform)(object)_card, _semibold, 14.194962f, TextColor, (TextAlignmentOptions)4100)
				});
			}
			Row row = _rows[_rowCount++];
			if (!((Component)row.Left).gameObject.activeSelf)
			{
				((Component)row.Left).gameObject.SetActive(true);
			}
			if (!((Component)row.Right).gameObject.activeSelf)
			{
				((Component)row.Right).gameObject.SetActive(true);
			}
			UiKit.Set(row.Left, left);
			UiKit.Set(row.Right, right);
			float num = 270.4359f;
			float num2 = (string.IsNullOrEmpty(right) ? 0f : (((TMP_Text)row.Right).GetPreferredValues(((TMP_Text)row.Right).text).x + 9.463307f));
			UiKit.Place(((TMP_Text)row.Left).rectTransform, 12.646221f, _y, Mathf.Max(num - num2, num * 0.3f), 22.002188f);
			UiKit.Place(((TMP_Text)row.Right).rectTransform, 12.646221f, _y, num, 22.002188f);
			_y += 22.002188f;
		}

		private static TextMeshProUGUI ShrinkToFit(TextMeshProUGUI text)
		{
			((TMP_Text)text).enableAutoSizing = true;
			((TMP_Text)text).fontSizeMax = 14.194962f;
			((TMP_Text)text).fontSizeMin = 9.936473f;
			return text;
		}

		private static void Stretch(RectTransform rect, float left, float top, float right, float bottom)
		{
			//IL_0001: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.pivot = new Vector2(0.5f, 0.5f);
			rect.offsetMin = new Vector2(left, bottom);
			rect.offsetMax = new Vector2(0f - right, 0f - top);
		}
	}
	internal sealed class ScoreLineView
	{
		private sealed class Pill
		{
			public Image Back;

			public TextMeshProUGUI Text;

			public float PadX;

			public float Height;

			public TMP_FontAsset SeparatorFont;

			public string Separator;
		}

		private const float Scale = 1.1829134f;

		private const float Below = 108.23658f;

		private const float Gap = 4.7316537f;

		private const float DotGap = 1.15f;

		private static readonly Color PillColor = new Color(7f / 51f, 0.11764706f, 0.1254902f, 0.72f);

		private static readonly Color TextColor = UiKit.Hex(15001311);

		private static readonly Color DimColor = UiKit.Hex(9215134);

		private readonly RectTransform _root;

		private readonly RedrawGate _gate = new RedrawGate();

		private readonly Pill _top;

		private readonly Pill _bottom;

		public ScoreLineView(RectTransform canvas, TMP_FontAsset bold, TMP_FontAsset semibold)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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)
			_root = UiKit.Rect("Scoreboard Line", (Transform)(object)canvas);
			_root.anchorMin = new Vector2(0.5f, 0.5f);
			_root.anchorMax = new Vector2(0.5f, 0.5f);
			_root.pivot = new Vector2(0.5f, 1f);
			_root.anchoredPosition = new Vector2(0f, -108.23658f);
			_root.sizeDelta = Vector2.zero;
			_top = MakePill("Top", 15.377874f, 14.194962f, 3.5487404f, TextColor);
			_bottom = MakePill("Bottom", 13.012048f, 11.829134f, 1.1829134f, DimColor);
			SetFonts(bold, semibold);
			((Component)_root).gameObject.SetActive(false);
		}

		public void SetFonts(TMP_FontAsset bold, TMP_FontAsset semibold)
		{
			_gate.Invalidate();
			bool flag = (Object)(object)bold != (Object)null && (Object)(object)bold == (Object)(object)semibold;
			Pill[] array = new Pill[2] { _top, _bottom };
			for (int i = 0; i < array.Length; i++)
			{
				TextMeshProUGUI text = array[i].Text;
				if ((Object)(object)bold != (Object)null)
				{
					((TMP_Text)text).font = bold;
				}
				((TMP_Text)text).fontStyle = (FontStyles)(flag ? 1 : 0);
				((TMP_Text)text).characterSpacing = (flag ? (0f - bold.boldSpacing) : 0f);
			}
		}

		public void Hide()
		{
			_gate.Invalidate();
			if (((Component)_root).gameObject.activeSelf)
			{
				((Component)_root).gameObject.SetActive(false);
			}
		}

		public void Show(ScoreSession s, bool paused, string resetKey)
		{
			if (!_gate.Changed(s, paused, resetKey))
			{
				return;
			}
			if (!((Component)_root).gameObject.activeSelf)
			{
				((Component)_root).gameObject.SetActive(true);
			}
			string text = Separator(_top);
			string text2 = ScoreText.Tint("#f2b75e", s.HasRate ? ScoreText.Dps(s.Dps) : "—") + " DPS" + text + ScoreText.Amount(s.TotalDamage) + text + ScoreText.Seconds(s.Duration) + text + ScoreText.L("score.hits", "Hits") + " " + ((!s.Weapon.Melee && s.Projectiles > 0) ? ScoreText.Percent(s.HitRate) : s.MainHits.ToString(CultureInfo.InvariantCulture));
			if (paused)
			{
				text2 = text2 + text + ScoreText.DimText(ScoreText.L("score.paused", "Paused"));
			}
			text = Separator(_bottom);
			string text3 = Parts(s);
			if (!s.Weapon.Melee)
			{
				text3 = Join(text3, ScoreText.L("score.crits", "Crits") + " " + s.Crits + " / " + s.MainHits, text);
			}
			if (paused && !string.IsNullOrEmpty(resetKey))
			{
				text3 = Join(text3, ScoreText.L("score.resetHint", "Press {0} to clear").Replace("{0}", resetKey), text);
			}
			float num = Layout(_top, text2, 0f);
			if (string.IsNullOrEmpty(text3))
			{
				if (((Component)_bottom.Back).gameObject.activeSelf)
				{
					((Component)_bottom.Back).gameObject.SetActive(false);
				}
				return;
			}
			if (!((Component)_bottom.Back).gameObject.activeSelf)
			{
				((Component)_bottom.Back).gameObject.SetActive(true);
			}
			Layout(_bottom, text3, num + 4.7316537f);
		}

		private static string Parts(ScoreSession s)
		{
			int num = 0;
			for (int i = 0; i < 6; i++)
			{
				num += s.PartCount((PartGroup)i);
			}
			if (num == 0)
			{
				return "";
			}
			string text = "";
			for (int j = 0; j < 6; j++)
			{
				int num2 = s.PartCount((PartGroup)j);
				if (num2 != 0)
				{
					text = Join(text, ScoreText.PartName((PartGroup)j) + " " + ScoreText.Percent((float)num2 / (float)num), "\u3000");
				}
			}
			return text;
		}

		private static string Separator(Pill pill)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			TMP_FontAsset font = ((TMP_Text)pill.Text).font;
			if (pill.Separator != null && (Object)(object)pill.SeparatorFont == (Object)(object)font)
			{
				return pill.Separator;
			}
			bool covered;
			float num = ((TMP_Text)pill.Text).GetPreferredValues(UiKit.Fit(font, "·", out covered)).x / ((TMP_Text)pill.Text).fontSize;
			string text = "<space=" + Mathf.Max(0.2f, 1.15f - num / 2f).ToString("0.00", CultureInfo.InvariantCulture) + "em>";
			pill.Separator = text + "·" + text;
			pill.SeparatorFont = font;
			return pill.Separator;
		}

		private static string Join(string a, string b, string separator)
		{
			if (!string.IsNullOrEmpty(a))
			{
				return a + separator + b;
			}
			return b;
		}

		private static float Layout(Pill pill, string text, float y)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			UiKit.Set(pill.Text, text);
			float num = ((TMP_Text)pill.Text).GetPreferredValues(((TMP_Text)pill.Text).text).x + 2f * pill.PadX;
			RectTransform rectTransform = ((Graphic)pill.Back).rectTransform;
			rectTransform.anchoredPosition = new Vector2(0f, 0f - y);
			rectTransform.sizeDelta = new Vector2(Mathf.Ceil(num), pill.Height);
			return y + pill.Height;
		}

		private Pill MakePill(string name, float fontSize, float padX, float padY, Color color)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Round(fontSize * 1.3f + 2f * padY);
			Image val = UiKit.Image(name, (Transform)(object)_root, PillColor, UiKit.Rounded(Mathf.FloorToInt(num / 2f)));
			RectTransform rectTransform = ((Graphic)val).rectTransform;
			rectTransform.anchorMin = new Vector2(0.5f, 1f);
			rectTransform.anchorMax = new Vector2(0.5f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			TextMeshProUGUI val2 = UiKit.Text("Text", (Transform)(object)rectTransform, null, fontSize, color, (TextAlignmentOptions)4098);
			RectTransform rectTransform2 = ((TMP_Text)val2).rectTransform;
			rectTransform2.anchorMin = Vector2.zero;
			rectTransform2.anchorMax = Vector2.one;
			rectTransform2.pivot = new Vector2(0.5f, 0.5f);
			rectTransform2.offsetMin = Vector2.zero;
			rectTransform2.offsetMax = Vector2.zero;
			return new Pill
			{
				Back = val,
				Text = val2,
				PadX = padX,
				Height = num
			};
		}
	}
	internal sealed class WeaponInfo
	{
		public int Id;

		public string Name = "";

		public bool Melee;

		public float Cooldown;

		public int MagazineSize;

		public int AmmoPerShot = 1;

		public float ReloadTime;
	}
	internal enum PartGroup
	{
		Eye,
		Head,
		Chest,
		Body,
		Limbs,
		Other
	}
	internal sealed class ScoreSession
	{
		public const float PauseAfterSeconds = 5f;

		public const float LeadInSeconds = 1.5f;

		public const int PartGroupCount = 6;

		public readonly WeaponInfo Weapon;

		private bool _hitEnemies;

		private float _pausedStretches;

		private float _mainIncomingSum;

		private float _critChanceSum;

		private readonly int[] _partCounts = new int[6];

		public float StartTime { get; private set; }

		public float LastHitTime { get; private set; }

		public int Shots { get; private set; }

		public int Projectiles { get; private set; }

		public int MainHits { get; private set; }

		public int Crits { get; private set; }

		public float TotalDamage { get; private set; }

		public bool HitEnemies
		{
			get
			{
				return _hitEnemies;
			}
			set
			{
				if (_hitEnemies != value)
				{
					_hitEnemies = value;
					Version++;
				}
			}
		}

		public int Version { get; private set; }

		public float Duration => _pausedStretches + Math.Max(0f, LastHitTime - StartTime);

		public bool HasRate
		{
			get
			{
				if (Duration >= 0.25f)
				{
					if (!Weapon.Melee)
					{
						return Shots >= 2;
					}
					return MainHits >= 2;
				}
				return false;
			}
		}

		public float Dps
		{
			get
			{
				if (!HasRate)
				{
					return 0f;
				}
				return TotalDamage / Duration;
			}
		}

		public float ProjectilesPerShot
		{
			get
			{
				if (Shots <= 0 || Projectiles <= 0)
				{
					return 1f;
				}
				return (float)Projectiles / (float)Shots;
			}
		}

		public float PaperDamagePerShot
		{
			get
			{
				if (MainHits <= 0)
				{
					return 0f;
				}
				return _mainIncomingSum / (float)MainHits * ProjectilesPerShot;
			}
		}

		public float PaperBurstDps
		{
			get
			{
				if (!(Weapon.Cooldown > 0f))
				{
					return 0f;
				}
				return PaperDamagePerShot / Weapon.Cooldown;
			}
		}

		public float PaperSustainedDps
		{
			get
			{
				if (Weapon.Cooldown <= 0f || Weapon.MagazineSize <= 0 || Weapon.ReloadTime <= 0f)
				{
					return 0f;
				}
				int num = Math.Max(1, Weapon.AmmoPerShot);
				int num2 = (Weapon.MagazineSize + num - 1) / num;
				float num3 = (float)num2 * Weapon.Cooldown + Weapon.ReloadTime;
				return PaperDamagePerShot * (float)num2 / num3;
			}
		}

		public float AverageCritChance
		{
			get
			{
				if (MainHits <= 0)
				{
					return 0f;
				}
				return _critChanceSum / (float)MainHits;
			}
		}

		public float HitRate
		{
			get
			{
				if (Projectiles <= 0)
				{
					return 0f;
				}
				return Math.Min(1f, (float)MainHits / (float)Projectiles);
			}
		}

		public ScoreSession(WeaponInfo weapon, float firstHitTime, IList<float> recentShots, IList<float> recentProjectiles)
		{
			Weapon = weapon;
			LastHitTime = firstHitTime;
			BeginStretch(firstHitTime, recentShots, recentProjectiles);
		}

		public bool IsPaused(float now)
		{
			return now - LastHitTime >= 5f;
		}

		public void Resume(float hitTime, IList<float> recentShots, IList<float> recentProjectiles)
		{
			_pausedStretches += Math.Max(0f, LastHitTime - StartTime);
			LastHitTime = hitTime;
			Version++;
			BeginStretch(hitTime, recentShots, recentProjectiles);
		}

		private void BeginStretch(float hitTime, IList<float> recentShots, IList<float> recentProjectiles)
		{
			StartTime = hitTime;
			if (recentShots != null)
			{
				for (int i = 0; i < recentShots.Count; i++)
				{
					if (!(recentShots[i] < hitTime - 1.5f) && !(recentShots[i] > hitTime))
					{
						Shots++;
						if (recentShots[i] < StartTime)
						{
							StartTime = recentShots[i];
						}
					}
				}
			}
			if (recentProjectiles == null)
			{
				return;
			}
			for (int j = 0; j < recentProjectiles.Count; j++)
			{
				if (recentProjectiles[j] >= hitTime - 1.5f && recentProjectiles[j] <= hitTime)
				{
					Projectiles++;
				}
			}
		}

		public void AddShot()
		{
			Shots++;
			Version++;
		}

		public void AddProjectile()
		{
			Projectiles++;
			Version++;
		}

		public void AddHit(float time, bool main, HitTerms terms, float critChance)
		{
			TotalDamage += terms.Final;
			if (time > LastHitTime)
			{
				LastHitTime = time;
			}
			Version++;
			if (main)
			{
				MainHits++;
				if (terms.Crit)
				{
					Crits++;
				}
				_critChanceSum += critChance;
				_mainIncomingSum += terms.Incoming;
				_partCounts[(int)GroupOf(terms.Part)]++;
			}
		}

		public int PartCount(PartGroup group)
		{
			return _partCounts[(int)group];
		}

		public static PartGroup GroupOf(BodyPart part)
		{
			switch (part)
			{
			case BodyPart.Eye:
				return PartGroup.Eye;
			case BodyPart.Head:
				return PartGroup.Head;
			case BodyPart.Thorax:
				return PartGroup.Chest;
			case BodyPart.Body:
			case BodyPart.Groin:
				return PartGroup.Body;
			case BodyPart.Arm:
			case BodyPart.Leg:
				return PartGroup.Limbs;
			default:
				return PartGroup.Other;
			}
		}
	}
	internal static class ScoreText
	{
		public const string Dim = "#8c9c9e";

		public const string Gold = "#f2b75e";

		public static string PartName(PartGroup group)
		{
			return group switch
			{
				PartGroup.Eye => L("partGroup.Eye", "eye"), 
				PartGroup.Head => L("partGroup.Head", "head"), 
				PartGroup.Chest => L("partGroup.Chest", "chest"), 
				PartGroup.Body => L("partGroup.Body", "body"), 
				PartGroup.Limbs => L("partGroup.Limbs", "limbs"), 
				_ => L("partGroup.Other", "other"), 
			};
		}

		public static string DimText(string text)
		{
			return Tint("#8c9c9e", text);
		}

		public static string Tint(string hex, string text)
		{
			if (!string.IsNullOrEmpty(text))
			{
				return "<color=" + hex + ">" + text + "</color>";
			}
			return "";
		}

		public static string Dps(float v)
		{
			return Amount(v);
		}

		public static string Amount(float v)
		{
			if (!(v >= 100f))
			{
				return v.ToString("0.#", CultureInfo.InvariantCulture);
			}
			return Mathf.Round(v).ToString("#,0", CultureInfo.InvariantCulture);
		}

		public static string Seconds(float v)
		{
			return L("score.seconds", "{0} s").Replace("{0}", v.ToString("0.0", CultureInfo.InvariantCulture));
		}

		public static string Percent(float fraction)
		{
			return Mathf.RoundToInt(fraction * 100f).ToString(CultureInfo.InvariantCulture) + "%";
		}

		public static string L(string key, string english)
		{
			return LangText.Get(key, english);
		}
	}
}
namespace NumbersGuy.Localization
{
	internal static class GameLanguage
	{
		public const string FallbackCode = "en";

		private static readonly string[] ShippedCodes = new string[15]
		{
			"en", "sv", "fr", "it", "de", "es", "pt", "ru", "pl", "ja",
			"ko", "zh-CN", "tr", "zh-TW", "ar"
		};

		public static string CurrentCode()
		{
			try
			{
				string currentLanguageCode = LocalizationManager.CurrentLanguageCode;
				if (string.IsNullOrEmpty(currentLanguageCode))
				{
					return null;
				}
				return (currentLanguageCode == "zh") ? "zh-TW" : currentLanguageCode;
			}
			catch (Exception)
			{
				return null;
			}
		}

		public static T FontIn<T>(string term, string languageName) where T : Object
		{
			try
			{
				string translation = LocalizationManager.GetTranslation(term, false, 0, true, false, (GameObject)null, languageName, true);
				if (string.IsNullOrEmpty(translation) || translation.StartsWith("<!-"))
				{
					return default(T);
				}
				T translatedObject = LocalizationManager.GetTranslatedObject<T>(translation, (Localize)null);
				if ((Object)(object)translatedObject != (Object)null)
				{
					return translatedObject;
				}
				T[] array = Resources.FindObjectsOfTypeAll<T>();
				for (int i = 0; i < array.Length; i++)
				{
					if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == translation)
					{
						return array[i];
					}
				}
				return default(T);
			}
			catch (Exception)
			{
				return default(T);
			}
		}

		public static bool IsRightToLeft()
		{
			try
			{
				return LocalizationManager.IsRight2Left;
			}
			catch (Exception)
			{
				return false;
			}
		}

		public static string FixRightToLeft(string text)
		{
			string text2;
			try
			{
				text2 = LocalizationManager.FixRTL_IfNeeded(text, 0, false);
			}
			catch (Exception)
			{
				return text;
			}
			return RestorePlaceholders(text2);
		}

		internal static string RestorePlaceholders(string text)
		{
			if (string.IsNullOrEmpty(text) || text.IndexOf('}') < 0)
			{
				return text;
			}
			for (int i = 0; i <= 9; i++)
			{
				string text2 = i.ToString(CultureInfo.InvariantCulture);
				text = text.Replace("}" + text2 + "{", "{" + text2 + "}");
			}
			return text;
		}

		public static List<string> FallbackChain(string languageCode)
		{
			List<string> list = new List<string> { "en" };
			string text = Resolve(languageCode);
			if (text == "zh-TW")
			{
				list.Add("zh-CN");
			}
			if (!list.Contains(text))
			{
				list.Add(text);
			}
			return list;
		}

		private static string Resolve(string languageCode)
		{
			if (string.IsNullOrEmpty(languageCode))
			{
				return "en";
			}
			for (int i = 0; i < ShippedCodes.Length; i++)
			{
				if (string.Equals(ShippedCodes[i], languageCode, StringComparison.OrdinalIgnoreCase))
				{
					return ShippedCodes[i];
				}
			}
			string b = LanguageOf(languageCode);
			for (int j = 0; j < ShippedCodes.Length; j++)
			{
				if (string.Equals(LanguageOf(ShippedCodes[j]), b, StringComparison.OrdinalIgnoreCase))
				{
					return ShippedCodes[j];
				}
			}
			return "en";
		}

		private static string LanguageOf(string languageCode)
		{
			int num = languageCode.IndexOf('-');
			if (num <= 0)
			{
				return languageCode;
			}
			return languageCode.Substring(0, num);
		}
	}
	internal static class LangText
	{
		[DataContract]
		private sealed class LangEntry
		{
			[DataMember(Name = "key")]
			public string Key;

			[DataMember(Name = "value")]
			public string Value;
		}

		[DataContract]
		private sealed class LangFile
		{
			[DataMember(Name = "entries")]
			public LangEntry[] Entries;
		}

		private static readonly Dictionary<string, string> Strings = new Dictionary<string, string>(StringComparer.Ordinal);

		public static string GameCode { get; private set; }

		public static int LoadedCount => Strings.Count;

		public static IEnumerable<KeyValuePair<string, string>> Loaded => Strings;

		public static string LoadedFrom { get; private set; }

		public static string LastLoadNote { get; private set; }

		public static bool Reload(string pluginDirectory)
		{
			string text = GameLanguage.CurrentCode();
			if (text == null || text == GameCode)
			{
				return false;
			}
			Strings.Clear();
			LoadedFrom = null;
			LastLoadNote = null;
			List<string> list = GameLanguage.FallbackChain(text);
			for (int i = 0; i < list.Count; i++)
			{
				LoadFirstMatch(pluginDirectory, list[i], i == list.Count - 1);
			}
			GameCode = text;
			return true;
		}

		public static void Forget()
		{
			Strings.Clear();
			GameCode = null;
		}

		public static string Get(string key, string englishFallback)
		{
			if (!Strings.TryGetValue(key, out var value) || string.IsNullOrEmpty(value))
			{
				return englishFallback;
			}
			return value;
		}

		private static IEnumerable<string> CandidateDirectories(string pluginDirectory)
		{
			if (!string.IsNullOrEmpty(pluginDirectory))
			{
				yield return Path.Combine(pluginDirectory, "lang");
				yield return pluginDirectory;
				DirectoryInfo directoryInfo;
				try
				{
					directoryInfo = Directory.GetParent(pluginDirectory);
				}
				catch (Exception)
				{
					directoryInfo = null;
				}
				if (directoryInfo != null)
				{
					yield return Path.Combine(directoryInfo.FullName, "lang");
				}
			}
		}

		private static void LoadFirstMatch(string pluginDirectory, string code, bool requested)
		{
			foreach (string item in CandidateDirectories(pluginDirectory))
			{
				if (LoadInto(item, code))
				{
					if (requested)
					{
						LoadedFrom = item;
					}
					return;
				}
			}
			if (requested && LastLoadNote == null)
			{
				LastLoadNote = "no readable " + code + ".json near " + (pluginDirectory ?? "<unknown>");
			}
		}

		private static bool LoadInto(string directory, string code)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(directory, code + ".json");
			if (!File.Exists(text))
			{
				return false;
			}
			try
			{
				LangFile langFile;
				using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(text)))
				{
					langFile = ((XmlObjectSerializer)new DataContractJsonSerializer(typeof(LangFile))).ReadObject((Stream)memoryStream) as LangFile;
				}
				if (langFile == null || langFile.Entries == null)
				{
					LastLoadNote = "no entries in " + text;
					return false;
				}
				bool flag = GameLanguage.IsRightToLeft();
				int num = 0;
				for (int i = 0; i < langFile.Entries.Length; i++)
				{
					LangEntry langEntry = langFile.Entries[i];
					if (langEntry != null && !string.IsNullOrEmpty(langEntry.Key) && langEntry.Value != null)
					{
						Strings[langEntry.Key] = (flag ? GameLanguage.FixRightToLeft(langEntry.Value) : langEntry.Value);
						num++;
					}
				}
				return num > 0;
			}
			catch (Exception ex)
			{
				LastLoadNote = ex.GetType().Name + " reading " + text;
				return false;
			}
		}
	}
}
namespace NumbersGuy.Formula
{
	internal enum BodyPart
	{
		None,
		Head,
		Eye,
		Thorax,
		Body,
		Groin,
		Arm,
		Leg,
		Other
	}
	internal sealed class HitTerms
	{
		public int Sequence;

		public int ParentSequence;

		public string DamageType = "Normal";

		public BodyPart Part;

		public bool Periodic;

		public bool AddOn;

		public bool Nested;

		public float Incoming;

		public float Falloff = 1f;

		public float HitBonus = 1f;

		public bool Crit;

		public bool Oil;

		public float GhostBonus;

		public float PartFactor = 1f;

		public float HeadshotBonus = 1f;

		public float Mitigation = 1f;

		public float Final;

		public bool IsExplosion => DamageType == "Explosive";
	}
	internal enum TokenTone
	{
		Plain,
		Up,
		Down,
		Operator,
		Result
	}
	internal sealed class FormulaToken
	{
		public string Key;

		public string Text;

		public string Label;

		public TokenTone Tone;

		public override string ToString()
		{
			return Text;
		}
	}
	internal sealed class FormulaLine
	{
		public readonly List<FormulaToken> Tokens = new List<FormulaToken>();

		public bool HasCrit;

		public float Result;

		public string Signature
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < Tokens.Count; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append('|');
					}
					stringBuilder.Append(Tokens[i].Key);
				}
				return stringBuilder.ToString();
			}
		}

		public string Text
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < Tokens.Count; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(' ');
					}
					stringBuilder.Append(Tokens[i].Text);
				}
				return stringBuilder.ToString();
			}
		}
	}
	internal delegate string TextLookup(string key, string englishFallback);
	internal static class FormulaBuilder
	{
		private struct Outer
		{
			public float Part;

			public BodyPart PartName;

			public float Headshot;

			public float Mitigation;

			public bool IsIdentity
			{
				get
				{
					if (Near(Part, 1f) && Near(Headshot, 1f))
					{
						return Near(Mitigation, 1f);
					}
					return false;
				}
			}

			public bool SameAs(Outer o)
			{
				if (Near(Part, o.Part) && Near(Headshot, o.Headshot))
				{
					return Near(Mitigation, o.Mitigation);
				}
				return false;
			}
		}

		private const float Epsilon = 0.0001f;

		public static FormulaLine Build(IList<HitTerms> hits, TextLookup text)
		{
			if (hits == null || hits.Count == 0)
			{
				throw new ArgumentException("no hits", "hits");
			}
			if (text == null)
			{
				text = (string k, string f) => f;
			}
			FormulaLine formulaLine = new FormulaLine();
			float num = 0f;
			for (int num2 = 0; num2 < hits.Count; num2++)
			{
				num += hits[num2].Final;
			}
			formulaLine.Result = num;
			List<HitTerms> list = new List<HitTerms>();
			List<HitTerms> list2 = new List<HitTerms>();
			for (int num3 = 0; num3 < hits.Count; num3++)
			{
				if (hits[num3].Nested || (hits[num3].ParentSequence != 0 && ContainsSequence(hits, hits[num3].ParentSequence)))
				{
					list2.Add(hits[num3]);
				}
				else
				{
					list.Add(hits[num3]);
				}
			}
			string text2 = ((list.Count > 0) ? list[0].DamageType : hits[0].DamageType);
			List<HitTerms> list3 = new List<HitTerms>();
			List<HitTerms> list4 = new List<HitTerms>();
			for (int num4 = 0; num4 < list.Count; num4++)
			{
				if (list[num4].DamageType == text2 && !list[num4].AddOn)
				{
					list3.Add(list[num4]);
				}
				else
				{
					list4.Add(list[num4]);
				}
			}
			if (list3.Count == 0)
			{
				OnlyResult(formulaLine, hits.Count, text);
				return formulaLine;
			}
			if (!((list3.Count == 1) ? BuildSingle(formulaLine, list3[0], list4, text) : BuildPellets(formulaLine, list3, list4, text)))
			{
				formulaLine.Tokens.Clear();
				OnlyResult(formulaLine, hits.Count, text);
				return formulaLine;
			}
			for (int num5 = 0; num5 < list2.Count; num5++)
			{
				if (ShowsAsDamage(list2[num5].Final))
				{
					Op(formulaLine, "+", "o-nest" + num5);
					Num(formulaLine, "nest" + num5, FormatDamage(list2[num5].Final), TypeName(list2[num5].DamageType, text), TokenTone.Plain);
				}
			}
			if (formulaLine.Tokens.Count == 1)
			{
				FormulaToken formulaToken = formulaLine.Tokens[0];
				formulaToken.Label = text("formula.noModifiers", "{0} · no modifiers").Replace("{0}", formulaToken.Label);
				return formulaLine;
			}
			Op(formulaLine, "=", "o-eq");
			Num(formulaLine, "result", FormatDamage(num), "", TokenTone.Result);
			return formulaLine;
		}

		private static bool BuildSingle(FormulaLine line, HitTerms main, List<HitTerms> addOns, TextLookup text)
		{
			List<HitTerms> list = new List<HitTerms>();
			for (int i = 0; i < addOns.Count; i++)
			{
				bool flag = addOns[i].Incoming > 0.0001f && addOns[i].Final <= 0.0001f;
				if (ShowsAsDamage(addOns[i].Final) || flag)
				{
					list.Add(addOns[i]);
				}
			}
			Outer outer = OuterOf(main);
			bool flag2 = true;
			for (int j = 0; j < list.Count; j++)
			{
				if (!OuterOf(list[j]).SameAs(outer))
				{
					flag2 = false;
				}
			}
			if (list.Count == 0 || flag2)
			{
				bool flag3 = (list.Count > 0 || HasAddition(main)) && !outer.IsIdentity;
				if (flag3)
				{
					Op(line, "(", "o-open");
				}
				Inner(line, main, "", BaseLabel(main, text), text);
				for (int k = 0; k < list.Count; k++)
				{
					Op(line, "+", "o-add" + k);
					Inner(line, list[k], "add" + k + ".", AddOnLabel(list[k].DamageType, text), text);
				}
				if (flag3)
				{
					Op(line, ")", "o-close");
				}
				OuterTokens(line, outer, "", text);
			}
			else
			{
				Part(line, main, outer, "", BaseLabel(main, text), text);
				for (int l = 0; l < list.Count; l++)
				{
					Op(line, "+", "o-add" + l);
					Part(line, list[l], OuterOf(list[l]), "add" + l + ".", AddOnLabel(list[l].DamageType, text), text);
				}
			}
			line.HasCrit = main.Crit;
			return true;
		}

		private static bool BuildPellets(FormulaLine line, List<HitTerms> mains, List<HitTerms> addOns, TextLookup text)
		{
			HitTerms hitTerms = mains[0];
			for (int i = 1; i < mains.Count; i++)
			{
				if (!Near(mains[i].Incoming, hitTerms.Incoming) || !Near(mains[i].HitBonus, hitTerms.HitBonus) || !Near(mains[i].Falloff, hitTerms.Falloff) || mains[i].Oil != hitTerms.Oil || !Near(mains[i].GhostBonus, hitTerms.GhostBonus) || !Near(mains[i].Mitigation, hitTerms.Mitigation))
				{
					return false;
				}
			}
			if (hitTerms.GhostBonus > 0.0001f)
			{
				for (int j = 0; j < mains.Count; j++)
				{
					if (mains[j].Crit)
					{
						return false;
					}
				}
			}
			List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
			Dictionary<string, List<HitTerms>> groups = new Dictionary<string, List<HitTerms>>();
			for (int k = 0; k < mains.Count; k++)
			{
				HitTerms hitTerms2 = mains[k];
				string key = hitTerms2.Part.ToString() + (hitTerms2.Crit ? "!" : "") + "@" + FormatFactor(hitTerms2.HeadshotBonus) + "/" + FormatFactor(hitTerms2.PartFactor);
				if (!groups.TryGetValue(key, out var value))
				{
					value = new List<HitTerms>();
					groups[key] = value;
					list.Add(new KeyValuePair<string, int>(key, k));
				}
				value.Add(hitTerms2);
			}
			list.Sort(delegate(KeyValuePair<string, int> a, KeyValuePair<string, int> b)
			{
				int num6 = groups[b.Key].Count.CompareTo(groups[a.Key].Count);
				return (num6 == 0) ? a.Value.CompareTo(b.Value) : num6;
			});
			bool num = hitTerms.GhostBonus > 0.0001f;
			if (num)
			{
				Op(line, "(", "o-gopen");
			}
			Num(line, "base", FormatDamage(hitTerms.Incoming), text("formula.perPellet", "per pellet"), TokenTone.Plain);
			BeforeDamageCall(line, hitTerms, "", text);
			if (hitTerms.Oil)
			{
				Op(line, "×", "o-oil");
				Num(line, "oil", "2", text("formula.oil", "oil"), TokenTone.Up);
			}
			if (num)
			{
				Op(line, "+", "o-ghost");
				Num(line, "ghost", FormatDamage(hitTerms.GhostBonus), text("formula.ghost", "ghost"), TokenTone.Up);
				Op(line, ")", "o-gclose");
			}
			Op(line, "× (", "o-popen");
			for (int num2 = 0; num2 < list.Count; num2++)
			{
				List<HitTerms> list2 = groups[list[num2].Key];
				HitTerms hitTerms3 = list2[0];
				float num3 = (hitTerms3.Crit ? 2f : 1f) * hitTerms3.PartFactor * hitTerms3.HeadshotBonus;
				if (num2 > 0)
				{
					Op(line, "+", "o-pg" + list[num2].Key);
				}
				string newValue = PartName(hitTerms3.Part, text);
				if (hitTerms3.Crit)
				{
					newValue = text("formula.critOf", "{0} crit").Replace("{0}", newValue);
				}
				string label = text("formula.pelletGroup", "{0} ({1})").Replace("{0}", newValue).Replace("{1}", list2.Count.ToString(CultureInfo.InvariantCulture));
				TokenTone tone = ((num3 > 1.0001f) ? TokenTone.Up : ((num3 < 0.9999f) ? TokenTone.Down : TokenTone.Plain));
				Num(line, "pg" + list[num2].Key, FormatFactor(num3) + "×" + list2.Count.ToString(CultureInfo.InvariantCulture), label, tone);
				if (hitTerms3.Crit)
				{
					line.HasCrit = true;
				}
			}
			Op(line, ")", "o-pclose");
			if (!Near(hitTerms.Mitigation, 1f))
			{
				Op(line, "×", "o-res");
				Num(line, "res", FormatFactor(hitTerms.Mitigation), ResistanceLabel(hitTerms.Mitigation, text), Tone(hitTerms.Mitigation));
			}
			List<string> list3 = new List<string>();
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			for (int num4 = 0; num4 < addOns.Count; num4++)
			{
				if (!dictionary.ContainsKey(addOns[num4].DamageType))
				{
					dictionary[addOns[num4].DamageType] = 0f;
					list3.Add(addOns[num4].DamageType);
				}
				dictionary[addOns[num4].DamageType] += addOns[num4].Final;
			}
			for (int num5 = 0; num5 < list3.Count; num5++)
			{
				if (ShowsAsDamage(dictionary[list3[num5]]))
				{
					Op(line, "+", "o-addsum" + list3[num5]);
					Num(line, "addsum" + list3[num5], FormatDamage(dictionary[list3[num5]]), AddOnLabel(list3[num5], text), TokenTone.Plain);
				}
			}
			return true;
		}

		private static void Part(FormulaLine line, HitTerms h, Outer outer, string prefix, string baseLabel, TextLookup text)
		{
			int num;
			if (HasAddition(h))
			{
				num = ((!outer.IsIdentity) ? 1 : 0);
				if (num != 0)
				{
					Op(line, "(", prefix + "o-open");
				}
			}
			else
			{
				num = 0;
			}
			Inner(line, h, prefix, baseLabel, text);
			if (num != 0)
			{
				Op(line, ")", prefix + "o-close");
			}
			OuterTokens(line, outer, prefix, text);
		}

		private static bool HasAddition(HitTerms h)
		{
			return h.GhostBonus > 0.0001f;
		}

		private static void Inner(FormulaLine line, HitTerms h, string prefix, string baseLabel, TextLookup text)
		{
			Num(line, prefix + "base", FormatDamage(h.Incoming), baseLabel, TokenTone.Plain);
			BeforeDamageCall(line, h, prefix, text);
			if (h.Crit)
			{
				Op(line, "×", prefix + "o-crit");
				Num(line, prefix + "crit", "2", text("formula.crit", "crit"), TokenTone.Up);
			}
			if (h.Oil)
			{
				Op(line, "×", prefix + "o-oil");
				Num(line, prefix + "oil", "2", text("formula.oil", "oil"), TokenTone.Up);
			}
			if (h.GhostBonus > 0.0001f)
			{
				Op(line, "+", prefix + "o-ghost");
				Num(line, prefix + "ghost", FormatDamage(h.GhostBonus), text("formula.ghost", "ghost"), TokenTone.Up);
			}
		}

		private static void BeforeDamageCall(FormulaLine line, HitTerms h, string prefix, TextLookup text)
		{
			if (!Near(h.Falloff, 1f))
			{
				Op(line, "×", prefix + "o-falloff");
				Num(line, prefix + "falloff", FormatFactor(h.Falloff), text("formula.falloff", "falloff"), TokenTone.Down);
			}
			if (!Near(h.HitBonus, 1f))
			{
				Op(line, "×", prefix + "o-bonus");
				Num(line, prefix + "bonus", FormatFactor(h.HitBonus), text("formula.teamMark", "team mark"), TokenTone.Up);
			}
		}

		private static void OuterTokens(FormulaLine line, Outer o, string prefix, TextLookup text)
		{
			if (!Near(o.Part, 1f))
			{
				Op(line, "×", prefix + "o-part");
				Num(line, prefix + "part", FormatFactor(o.Part), PartName(o.PartName, text), Tone(o.Part));
			}
			if (!Near(o.Headshot, 1f))
			{
				Op(line, "×", prefix + "o-hs");
				Num(line, prefix + "hs", FormatFactor(o.Headshot), text("formula.headshotBonus", "headshot bonus"), Tone(o.Headshot));
			}
			if (!Near(o.Mitigation, 1f))
			{
				Op(line, "×", prefix + "o-res");
				Num(line, prefix + "res", FormatFactor(o.Mitigation), ResistanceLabel(o.Mitigation, text), Tone(o.Mitigation));
			}
		}

		private static void OnlyResult(FormulaLine line, int hitCount, TextLookup text)
		{
			string label = text("formula.hits", "{0} hits").Replace("{0}", hitCount.ToString(CultureInfo.InvariantCulture));
			Num(line, "result", FormatDamage(line.Result), label, TokenTone.Result);
		}

		private static Outer OuterOf(HitTerms h)
		{
			return new Outer
			{
				Part = h.PartFactor,
				PartName = h.Part,
				Headshot = h.HeadshotBonus,
				Mitigation = h.Mitigation
			};
		}

		private static string BaseLabel(HitTerms h, TextLookup text)
		{
			if (h.ParentSequence != 0)
			{
				return TypeName(h.DamageType, text);
			}
			if (h.Periodic)
			{
				return text("formula.tick", "{0} tick").Replace("{0}", TypeName(h.DamageType, text));
			}
			if (h.IsExplosion)
			{
				return text("formula.explosion", "explosion");
			}
			return text("formula.weaponDamage", "weapon damage");
		}

		private static string ResistanceLabel(float mitigation, TextLookup text)
		{
			float num = (1f - mitigation) * 100f;
			decimal num2 = ToDecimal(Math.Abs(num));
			decimal num3 = Math.Round(num2, 0, MidpointRounding.AwayFromZero);
			string newValue = ((num3 == 0m && num2 != 0m) ? Math.Round(num2, 1, MidpointRounding.AwayFromZero) : num3).ToString("0.#", CultureInfo.InvariantCulture);
			if (!(num < 0f))
			{
				return text("formula.resistance", "resistance {0}%").Replace("{0}", newValue);
			}
			return text("formula.weakness", "weakness {0}%").Replace("{0}", newValue);
		}

		private static string PartName(BodyPart part, TextLookup text)
		{
			return part switch
			{
				BodyPart.Head => text("part.Head", "head"), 
				BodyPart.Eye => text("part.Eye", "eye"), 
				BodyPart.Thorax => text("part.Thorax", "chest"), 
				BodyPart.Body => text("part.Body", "body"), 
				BodyPart.Groin => text("part.Groin", "groin"), 
				BodyPart.Arm => text("part.Arm", "arm"), 
				BodyPart.Leg => text("part.Leg", "leg"), 
				_ => text("part.Other", "body part"), 
			};
		}

		private static string AddOnLabel(string damageType, TextLookup text)
		{
			return text("formula.addOn", "{0} add-on").Replace("{0}", TypeName(damageType, text));
		}

		internal static string TypeName(string damageType, TextLookup text)
		{
			return damageType switch
			{
				"Normal" => text("type.Normal", "damage"), 
				"Fire" => text("type.Fire", "fire"), 
				"Frost" => text("type.Frost", "frost"), 
				"Dark" => text("type.Dark", "dark"), 
				"Holy" => text("type.Holy", "holy"), 
				"Poison" => text("type.Poison", "poison"), 
				"Electric" => text("type.Electric", "shock"), 
				"Explosive" => text("type.Explosive", "explosion"), 
				"Bleed" => text("type.Bleed", "bleeding"), 
				null => "", 
				_ => damageType.ToLowerInvariant(), 
			};
		}

		private static TokenTone Tone(float factor)
		{
			if (!(factor > 1.0001f))
			{
				if (!(factor < 0.9999f))
				{
					return TokenTone.Plain;
				}
				return TokenTone.Down;
			}
			return TokenTone.Up;
		}

		private static void Num(FormulaLine line, string key, string value, string label, TokenTone tone)
		{
			line.Tokens.Add(new FormulaToken
			{
				Key = key,
				Text = value,
				Label = (label ?? ""),
				Tone = tone
			});
		}

		private static void Op(FormulaLine line, string symbol, string key)
		{
			line.Tokens.Add(new FormulaToken
			{
				Key = key,
				Text = symbol,
				Label = "",
				Tone = TokenTone.Operator
			});
		}

		private static bool ContainsSequence(IList<HitTerms> hits, int sequence)
		{
			for (int i = 0; i < hits.Count; i++)
			{
				if (hits[i].Sequence == sequence)
				{
					return true;
				}
			}
			return false;
		}

		private static bool Near(float a, float b)
		{
			return Math.Abs(a - b) <= 0.0001f;
		}

		internal static string FormatFactor(float v)
		{
			if (float.IsNaN(v) || float.IsInfinity(v) || Math.Abs(v) > 1E+09f)
			{
				return v.ToString(CultureInfo.InvariantCulture);
			}
			decimal num = ToDecimal(v);
			decimal num2 = Math.Round(num, 2, MidpointRounding.AwayFromZero);
			for (int i = 3; i <= 4; i++)
			{
				if (!(num2 == 0m) && !(num2 == 1m))
				{
					break;
				}
				if (!(num2 != num))
				{
					break;
				}
				num2 = Math.Round(num, i, MidpointRounding.AwayFromZero);
			}
			return num2.ToString("0.####", CultureInfo.InvariantCulture);
		}

		private static bool ShowsAsDamage(float v)
		{
			if (v > 0.0001f)
			{
				return FormatDamage(v) != "0";
			}
			return false;
		}

		internal static string FormatDamage(float v)
		{
			if (float.IsNaN(v) || float.IsInfinity(v) || Math.Abs(v) > 1E+15f)
			{
				return v.ToString(CultureInfo.InvariantCulture);
			}
			return Math.Round(ToDecimal(v), 1, MidpointRounding.AwayFromZero).ToString("0.#", CultureInfo.InvariantCulture);
		}

		private static decimal ToDecimal(float v)
		{
			return (decimal)v;
		}
	}
}
namespace NumbersGuy.Display
{
	internal sealed class CubicBezier
	{
		public static readonly CubicBezier Pop = new CubicBezier(0.2f, 1.5f, 0.4f, 1f);

		public static readonly CubicBezier Punch = new CubicBezier(0.2f, 1.6f, 0.4f, 1f);

		public static readonly CubicBezier Slide = new CubicBezier(0.3f, 0.9f, 0.4f, 1f);

		public static readonly CubicBezier EaseOut = new CubicBezier(0f, 0f, 0.58f, 1f);

		public static readonly CubicBezier EaseIn = new CubicBezier(0.42f, 0f, 1f, 1f);

		public static readonly CubicBezier Linear = new CubicBezier(0f, 0f, 1f, 1f);

		private readonly float _x1;

		private readonly float _y1;

		private readonly float _x2;

		private readonly float _y2;

		public CubicBezier(float x1, float y1, float x2, float y2)
		{
			_x1 = x1;
			_y1 = y1;
			_x2 = x2;
			_y2 = y2;
		}

		public float Evaluate(float progress)
		{
			if (progress <= 0f)
			{
				return 0f;
			}
			if (progress >= 1f)
			{
				return 1f;
			}
			float t = SolveT(progress);
			return Sample(_y1, _y2, t);
		}

		private float SolveT(float x)
		{
			float num = x;
			for (int i = 0; i < 6; i++)
			{
				float num2 = Sample(_x1, _x2, num) - x;
				if (Math.Abs(num2) < 0.0001f)
				{
					return num;
				}
				float num3 = Slope(_x1, _x2, num);
				if (Math.Abs(num3) < 1E-05f)
				{
					break;
				}
				num -= num2 / num3;
			}
			float num4 = 0f;
			float num5 = 1f;
			num = x;
			for (int j = 0; j < 20; j++)
			{
				float num6 = Sample(_x1, _x2, num);
				if (Math.Abs(num6 - x) < 0.0001f)
				{
					break;
				}
				if (num6 < x)
				{
					num4 = num;
				}
				else
				{
					num5 = num;
				}
				num = (num4 + num5) * 0.5f;
			}
			return num;
		}

		private static float Sample(float p1, float p2, float t)
		{
			float num = 1f - t;
			return 3f * num * num * t * p1 + 3f * num * t * t * p2 + t * t * t;
		}

		private static float Slope(float p1, float p2, float t)
		{
			float num = 1f - t;
			return 3f * num * num * p1 + 6f * num * t * (p2 - p1) + 3f * t * t * (1f - p2);
		}
	}
	internal sealed class FormulaView
	{
		private struct Tween
		{
			public bool Active;

			public float Start;

			public float Duration;

			public CubicBezier Curve;

			public static Tween Begin(float now, float delay, float duration, CubicBezier curve)
			{
				return new Tween
				{
					Active = true,
					Start = now + delay,
					Duration = duration,
					Curve = curve
				};
			}

			public float Eased(float now)
			{
				if (!Active)
				{
					return 1f;
				}
				float progress = (now - Start) / Duration;
				return Curve.Evaluate(progress);
			}

			public bool Done(float now)
			{
				if (Active)
				{
					return now >= Start + Duration;
				}
				return true;
			}
		}

		private enum NumberMotion
		{
			None,
			PopIn,
			CritPopIn,
			SwapUp,
			Punch
		}

		private sealed class Token
		{
			public string Key;

			public TokenTone Tone;

			public RectTransform Root;

			public RectTransform NumberBox;

			public ShadowText Number;

			public ShadowText Label;

			public float X;

			public float Width;

			public float SlideFrom;

			public Tween Slide;

			public NumberMotion Motion;

			public Tween NumberTween;

			public Tween NumberFade;

			public float PunchFrom;

			public Tween LabelRise;

			public bool ResultPop;

			public Tween TokenTween;

			public bool Removing;
		}

		private const float MinGap = 0.125f;

		private const float Scale = 1.1829134f;

		private const float Top = 82.80394f;

		private const float Gap = 11.829134f;

		private const float NumberSize = 47.316536f;

		private const float ResultSize = 54.414017f;

		private const float BorrowedOperatorSize = 35.487404f;

		private const float NumberHeight = 49.682365f;

		private const float LabelSize = 16.560787f;

		private const float LabelTop = 52.04819f;

		private const float LabelHeight = 23.185104f;

		private static readonly Color TextColor = Hex(15001311);

		private static readonly Color LabelColor = Hex(13225926);

		private static readonly Color OperatorColor = Hex(12173496);

		private static readonly Color UpColor = Hex(15816762);

		private static readonly Color DownColor = Hex(9417666);

		private static readonly Color ResultColor = Hex(16560193);

		private readonly RectTransform _root;

		private const float MaxWidthShare = 0.94f;

		private float _lineWidth;

		private readonly CanvasGroup _group;

		private readonly Dictionary<string, Token> _tokens = new Dictionary<string, Token>();

		private readonly List<Token> _order = new List<Token>();

		private readonly List<Token> _removing = new List<Token>();

		private TMP_FontAsset _numberFont;

		private TMP_FontAsset _labelFont;

		private string _signature;

		private float _lastShow = float.NegativeInfinity;

		private FormulaLine _pending;

		private Tween _shake;

		private Tween _fadeIn;

		private Tween _fadeOut;

		private bool _fading;

		private static readonly float[] ShakeKeys = new float[5] { 0f, -3f, 3f, -2f, 0f };

		public bool IsShowing
		{
			get
			{
				if (_order.Count <= 0)
				{
					return _removing.Count > 0;
				}
				return true;
			}
		}

		public FormulaView(RectTransform canvas)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Formula", new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasGroup)
			});
			_root = (RectTransform)val.transform;
			((Transform)_root).SetParent((Transform)(object)canvas, false);
			_root.anchorMin = new Vector2(0.5f, 1f);
			_root.anchorMax = new Vector2(0.5f, 1f);
			_root.pivot = new Vector2(0.5f, 1f);
			_root.sizeDelta = new Vector2(0f, 72.86747f);
			_root.anchoredPosition = new Vector2(0f, -82.80394f);
			_group = val.GetComponent<CanvasGroup>();
			_group.interactable = false;
			_group.blocksRaycasts = false;
		}

		public void SetFonts(TMP_FontAsset numbers, TMP_FontAsset labels)
		{
			if (!((Object)(object)numbers == (Object)(object)_numberFont) || !((Object)(object)labels == (Object)(object)_labelFont))
			{
				_numberFont = numbers;
				_labelFont = labels;
				Clear();
			}
		}

		public void Show(FormulaLine line, float now)
		{
			if (line != null && line.Tokens.Count != 0)
			{
				if (now - _lastShow < 0.125f)
				{
					_pending = line;
				}
				else
				{
					Apply(line, now);
				}
			}
		}

		public void Tick(float now, float holdTime, float scale)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Transform)_root).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val != (Object)null && _lineWidth > 0f)
			{
				Rect rect = val.rect;
				float num = ((Rect)(ref rect)).width * 0.94f;
				if (_lineWidth * scale > num)
				{
					scale = num / _lineWidth;
				}
			}
			((Transform)_root).localScale = new Vector3(scale, scale, 1f);
			if (_pending != null && now - _lastShow >= 0.125f)
			{
				FormulaLine pending = _pending;
				_pending = null;
				Apply(pending, now);
			}
			if (_order.Count > 0 && !_fading && now >= _lastShow + holdTime)
			{
				_fading = true;
				_fadeOut = Tween.Begin(now, 0f, 0.3f, CubicBezier.EaseIn);
			}
			if (_fading && _fadeOut.Done(now))
			{
				Clear();
			}
			else
			{
				Evaluate(now);
			}
		}

		public void Clear()
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _order.Count; i++)
			{
				Object.Destroy((Object)(object)((Component)_order[i].Root).gameObject);
			}
			for (int j = 0; j < _removing.Count; j++)
			{
				Object.Destroy((Object)(object)((Component)_removing[j].Root).gameObject);
			}
			_order.Clear();
			_removing.Clear();
			_tokens.Clear();
			_signature = null;
			_pending = null;
			_fading = false;
			_fadeOut = default(Tween);
			_fadeIn = default(Tween);
			_shake = default(Tween);
			_group.alpha = 1f;
			_root.anchoredPosition = new Vector2(0f, -82.80394f);
		}

		private void Apply(FormulaLine line, float now)
		{
			bool value = Plugin.ReduceFormulaAnimation.Value;
			bool flag = _order.Count == 0;
			string signature = line.Signature;
			_fading = false;
			_fadeOut = default(Tween);
			if (!flag && signature == _signature)
			{
				for (int i = 0; i < line.Tokens.Count; i++)
				{
					FormulaToken formulaToken = line.Tokens[i];
					Token token = _tokens[formulaToken.Key];
					if (token.Number.Text != formulaToken.Text)
					{
						token.Number.Text = formulaToken.Text;
						if (!value)
						{
							if (formulaToken.Tone == TokenTone.Result)
							{
								StartNumber(token, NumberMotion.Punch, Tween.Begin(now, 0f, 0.14f, CubicBezier.Punch), 1.18f);
							}
							else
							{
								StartNumber(token, NumberMotion.SwapUp, Tween.Begin(now, 0f, 0.11f, CubicBezier.EaseOut), 1f);
							}
						}
					}
					SetTone(token, formulaToken.Tone);
					token.Label.Text = formulaToken.Label;
				}
				Layout();
			}
			else
			{
				Dictionary<string, float> dictionary = new Dictionary<string, float>();
				for (int j = 0; j < _order.Count; j++)
				{
					dictionary[_order[j].Key] = _order[j].X;
				}
				HashSet<string> hashSet = new HashSet<string>();
				for (int k = 0; k < line.Tokens.Count; k++)
				{
					hashSet.Add(line.Tokens[k].Key);
				}
				for (int l = 0; l < _order.Count; l++)
				{
					Token token2 = _order[l];
					if (!hashSet.Contains(token2.Key))
					{
						_tokens.Remove(token2.Key);
						if (value)
						{
							Object.Destroy((Object)(object)((Component)token2.Root).gameObject);
							continue;
						}
						token2.Removing = true;
						token2.ResultPop = false;
						token2.TokenTween = Tween.Begin(now, 0f, 0.11f, CubicBezier.EaseIn);
						_removing.Add(token2);
					}
				}
				_order.Clear();
				for (int m = 0; m < line.Tokens.Count; m++)
				{
					FormulaToken formulaToken2 = line.Tokens[m];
					if (!_tokens.TryGetValue(formulaToken2.Key, out var value2))
					{
						value2 = Create(formulaToken2);
						_tokens[formulaToken2.Key] = value2;
					}
					else
					{
						value2.Number.Text = formulaToken2.Text;
						value2.Label.Text = formulaToken2.Label;
						SetTone(value2, formulaToken2.Tone);
					}
					_order.Add(value2);
				}
				Layout();
				int num = 0;
				for (int n = 0; n < _order.Count; n++)
				{
					Token token3 = _order[n];
					if (dictionary.TryGetValue(token3.Key, out var value3))
					{
						float num2 = value3 - token3.X;
						if (!value && Mathf.Abs(num2) > 0.5f)
						{
							token3.SlideFrom = num2;
							token3.Slide = Tween.Begin(now, 0f, 0.14f, CubicBezier.Slide);
						}
					}
					else
					{
						if (value)
						{
							continue;
						}
						float num3 = (flag ? ((float)num * 0.035f) : 0f);
						if (token3.Tone == TokenTone.Result)
						{
							token3.ResultPop = true;
							token3.TokenTween = Tween.Begin(now, num3 + 0.02f, 0.21f, CubicBezier.Pop);
						}
						else
						{
							Tween tween = Tween.Begin(now, num3, 0.18f, CubicBezier.Pop);
							if (IsCritFactor(token3.Key))
							{
								StartNumber(token3, NumberMotion.CritPopIn, Tween.Begin(now, num3, 0.22f, CubicBezier.Punch), 1.6f);
								token3.NumberFade = tween;
							}
							else
							{
								StartNumber(token3, NumberMotion.PopIn, tween, 1f);
							}
							token3.LabelRise = Tween.Begin(now, num3 + 0.06f, 0.16f, CubicBezier.EaseOut);
						}
						num++;
					}
				}
			}
			if (line.HasCrit && !value)
			{
				_shake = Tween.Begin(now, 0f, 0.13f, CubicBezier.Linear);
			}
			if (value && flag)
			{
				_fadeIn = Tween.Begin(now, 0f, 0.12f, CubicBezier.Linear);
			}
			_signature = signature;
			_lastShow = now;
		}

		private static bool IsCritFactor(string key)
		{
			if (!(key == "crit"))
			{
				return key.EndsWith(".crit");
			}
			return true;
		}

		private static void StartNumber(Token token, NumberMotion motion, Tween tween, float punchFrom)
		{
			token.Motion = motion;
			token.NumberTween = tween;
			token.PunchFrom = punchFrom;
		}

		private void Layout()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			for (int i = 0; i < _order.Count; i++)
			{
				Token token = _order[i];
				token.Width = Mathf.Max(token.Number.PreferredWidth, token.Label.PreferredWidth);
				token.Number.Rect.sizeDelta = new Vector2(token.Width + 8f, 49.682365f);
				token.Label.Rect.sizeDelta = new Vector2(token.Width + 8f, 23.185104f);
				num += token.Width;
			}
			float num2 = (0f - (_lineWidth = num + 11.829134f * (float)Mathf.Max(0, _order.Count - 1))) / 2f;
			for (int j = 0; j < _order.Count; j++)
			{
				Token token2 = _order[j];
				token2.X = num2 + token2.Width / 2f;
				num2 += token2.Width + 11.829134f;
			}
		}

		private Token Create(FormulaToken t)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)new GameObject("Token " + t.Key, new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent((Transform)(object)_root, false);
			val.anchorMin = new Vector2(0.5f, 1f);
			val.anchorMax = new Vector2(0.5f, 1f);
			val.pivot = new Vector2(0.5f, 1f);
			val.sizeDelta = new Vector2(10f, 72.86747f);
			RectTransform val2 = (RectTransform)new GameObject("Number", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val2).SetParent((Transform)(object)val, false);
			val2.anchorMin = new Vector2(0.5f, 1f);
			val2.anchorMax = new Vector2(0.5f, 1f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = Vector2.zero;
			val2.anchoredPosition = new Vector2(0f, -24.841183f);
			Token token = new Token();
			token.Key = t.Key;
			token.Root = val;
			token.NumberBox = val2;
			token.Number = new ShadowText((Transform)(object)val2, "Value", _numberFont, 47.316536f, (TextAlignmentOptions)514);
			token.Number.SetFonts(_numberFont, _labelFont);
			token.Number.Rect.anchorMin = new Vector2(0.5f, 0.5f);
			token.Number.Rect.anchorMax = new Vector2(0.5f, 0.5f);
			token.Number.Rect.pivot = new Vector2(0.5f, 0.5f);
			token.Label = new ShadowText((Transform)(object)val, "Label", _labelFont, 16.560787f, (TextAlignmentOptions)258);
			token.Label.Rect.anchorMin = new Vector2(0.5f, 1f);
			token.Label.Rect.anchorMax = new Vector2(0.5f, 1f);
			token.Label.Rect.pivot = new Vector2(0.5f, 1f);
			token.Label.Rect.anchoredPosition = new Vector2(0f, -52.04819f);
			token.Number.Text = t.Text;
			token.Label.Text = t.Label;
			SetTone(token, t.Tone);
			return token;
		}

		private static void SetTone(Token token, TokenTone tone)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			token.Tone = tone;
			switch (tone)
			{
			case TokenTone.Up:
				token.Number.Color = UpColor;
				break;
			case TokenTone.Down:
				token.Number.Color = DownColor;
				break;
			case TokenTone.Operator:
				token.Number.Color = OperatorColor;
				break;
			case TokenTone.Result:
				token.Number.Color = ResultColor;
				break;
			default:
				token.Number.Color = TextColor;
				break;
			}
			bool flag = tone == TokenTone.Operator && token.Number.UsesFallback;
			token.Number.SetFontSize((tone == TokenTone.Result) ? 54.414017f : (flag ? 35.487404f : 47.316536f));
			token.Number.SetStyle((FontStyles)(flag ? 1 : 0));
			token.Label.Color = ((tone == TokenTone.Result) ? ResultColor : LabelColor);
		}

		private void Evaluate(float now)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f;
			float num2 = 0f;
			float num3 = 0f;
			if (_fadeIn.Active)
			{
				num *= Mathf.Clamp01(_fadeIn.Eased(now));
				if (_fadeIn.Done(now))
				{
					_fadeIn = default(Tween);
				}
			}
			if (_shake.Active)
			{
				num2 = ShakeOffset(Mathf.Clamp01((now - _shake.Start) / _shake.Duration));
				if (_shake.Done(now))
				{
					_shake = default(Tween);
				}
			}
			if (_fading)
			{
				float num4 = Mathf.Clamp01(_fadeOut.Eased(now));
				num *= 1f - num4;
				if (!Plugin.ReduceFormulaAnimation.Value)
				{
					num3 = 8f * num4;
				}
			}
			_group.alpha = num;
			_root.anchoredPosition = new Vector2(num2, -82.80394f + num3);
			for (int i = 0; i < _order.Count; i++)
			{
				EvaluateToken(_order[i], now);
			}
			for (int num5 = _removing.Count - 1; num5 >= 0; num5--)
			{
				Token token = _removing[num5];
				if (token.TokenTween.Done(now))
				{
					Object.Destroy((Object)(object)((Component)token.Root).gameObject);
					_removing.RemoveAt(num5);
				}
				else
				{
					EvaluateToken(token, now);
				}
			}
		}

		private static float ShakeOffset(float p)
		{
			float[] shakeKeys = ShakeKeys;
			float num = p * (float)(shakeKeys.Length - 1);
			int num2 = Mathf.Min(shakeKeys.Length - 2, (int)num);
			return Mathf.Lerp(shakeKeys[num2], shakeKeys[num2 + 1], num - (float)num2);
		}

		private static void EvaluateToken(Token token, float now)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			float num = token.X;
			if (token.Slide.Active)
			{
				num += token.SlideFrom * (1f - token.Slide.Eased(now));
				if (token.Slide.Done(now))
				{
					token.Slide = default(Tween);
				}
			}
			float num2 = 1f;
			float num3 = 1f;
			if (token.Removing)
			{
				float num4 = Mathf.Clamp01(token.TokenTween.Eased(now));
				num3 = 1f - num4;
				num2 = Mathf.Lerp(1f, 0.7f, num4);
			}
			else if (token.ResultPop)
			{
				float num5 = token.TokenTween.Eased(now);
				num2 = Mathf.LerpUnclamped(1.45f, 1f, num5);
				num3 = Mathf.Clamp01(num5);
				if (token.TokenTween.Done(now))
				{
					token.ResultPop = false;
				}
			}
			token.Root.anchoredPosition = new Vector2(num, 0f);
			((Transform)token.Root).localScale = new Vector3(num2, num2, 1f);
			float num6 = 1f;
			float num7 = 0f;
			float num8 = 1f;
			switch (token.Motion)
			{
			case NumberMotion.PopIn:
			{
				float num10 = token.NumberTween.Eased(now);
				num6 = Mathf.LerpUnclamped(0.6f, 1f, num10);
				num7 = Mathf.LerpUnclamped(10f, 0f, num10);
				num8 = Mathf.Clamp01(num10);
				break;
			}
			case NumberMotion.CritPopIn:
				num6 = Mathf.LerpUnclamped(token.PunchFrom, 1f, token.NumberTween.Eased(now));
				num8 = Mathf.Clamp01(token.NumberFade.Eased(now));
				break;
			case NumberMotion.SwapUp:
			{
				float num9 = token.NumberTween.Eased(now);
				num7 = Mathf.LerpUnclamped(-14f, 0f, num9);
				num8 = Mathf.Clamp01(num9);
				break;
			}
			case NumberMotion.Punch:
				num6 = Mathf.LerpUnclamped(token.PunchFrom, 1f, token.NumberTween.Eased(now));
				break;
			}
			if (token.Motion != NumberMotion.None && token.NumberTween.Done(now) && (token.Motion != NumberMotion.CritPopIn || token.NumberFade.Done(now)))
			{
				token.Motion = NumberMotion.None;
			}
			token.NumberBox.anchoredPosition = new Vector2(0f, -24.841183f + num7);
			((Transform)token.NumberBox).localScale = new Vector3(num6, num6, 1f);
			token.Number.Alpha = num8 * num3;
			float num11 = 1f;
			float num12 = 0f;
			if (token.LabelRise.Active)
			{
				float num13 = token.LabelRise.Eased(now);
				num12 = Mathf.LerpUnclamped(-4f, 0f, num13);
				num11 = Mathf.Clamp01(num13);
				if (token.LabelRise.Done(now))
				{
					token.LabelRise = default(Tween);
				}
			}
			token.Label.Rect.anchoredPosition = new Vector2(0f, -52.04819f + num12);
			token.Label.Alpha = num11 * num3;
		}

		private static Color Hex(int rgb)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
		}
	}
	internal enum HitRole
	{
		Main,
		AddOn,
		Nested,
		Tick
	}
	internal sealed class CountedHit
	{
		public HitTerms Terms;

		public HitRole Role;

		public float CritChance;
	}
	internal sealed class TargetHits
	{
		public Unit Target;

		public bool IsDummy;

		public readonly List<CountedHit> Hits = new List<CountedHit>();

		public float Total;
	}
	internal sealed class ShotOutcome
	{
		public Weapon Weapon;

		public bool Periodic;

		public readonly List<TargetHits> Targets = new List<TargetHits>();
	}
	internal sealed class HitAssembler
	{
		private readonly List<HitRecord> _pending = new List<HitRecord>();

		public event Action<ShotOutcome> ShotResolved;

		public void Add(HitRecord hit)
		{
			_pending.Add(hit);
		}

		public void Clear()
		{
			_pending.Clear();
		}

		public void Flush()
		{
			if (_pending.Count == 0)
			{
				return;
			}
			try
			{
				List<ShotOutcome> list = Group(_pending);
				for (int i = 0; i < list.Count; i++)
				{
					this.ShotResolved?.Invoke(list[i]);
				}
			}
			finally
			{
				_pending.Clear();
			}
		}

		private static List<ShotOutcome> Group(List<HitRecord> hits)
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			for (int i = 0; i < hits.Count; i++)
			{
				dictionary[hits[i].Sequence] = i;
			}
			List<ShotOutcome> list = new List<ShotOutcome>();
			Dictionary<string, ShotOutcome> dictionary2 = new Dictionary<string, ShotOutcome>();
			for (int j = 0; j < hits.Count; j++)
			{
				HitRecord hitRecord = hits[j];
				HitRecord root = RootOf(hitRecord, hits, dictionary);
				string key = KeyOf(root);
				if (!dictionary2.TryGetValue(key, out var value))
				{
					value = (dictionary2[key] = new ShotOutcome
					{
						Weapon = root.Weapon,
						Periodic = root.Periodic
					});
					list.Add(value);
				}
				TargetHits targetHits = TargetOf(value, hitRecord);
				bool flag = root.Sequence != hitRecord.Sequence;
				HitTerms hitTerms = ToTerms(hitRecord);
				hitTerms.Nested = flag;
				targetHits.Hits.Add(new CountedHit
				{
					Terms = hitTerms,
					Role = (flag ? HitRole.Nested : (hitRecord.Periodic ? HitRole.Tick : HitRole.Main)),
					CritChance = hitRecord.CritChance
				});
				targetHits.Total += hitRecord.Final;
			}
			for (int k = 0; k < list.Count; k++)
			{
				for (int l = 0; l < list[k].Targets.Count; l++)
				{
					List<CountedHit> hits2 = list[k].Targets[l].Hits;
					string text = null;
					bool flag2 = false;
					for (int m = 0; m < hits2.Count; m++)
					{
						if (hits2[m].Role == HitRole.Main)
						{
							if (text == null)
							{
								text = hits2[m].Terms.DamageType;
								flag2 = hits2[m].CritChance > 0f;
							}
							else if (hits2[m].Terms.DamageType != text || (flag2 && hits2[m].CritChance <= 0f))
							{
								hits2[m].Role = HitRole.AddOn;
								hits2[m].Terms.AddOn = true;
							}
						}
					}
				}
			}
			return list;
		}

		private static HitRecord RootOf(HitRecord hit, List<HitRecord> hits, Dictionary<int, int> indexBySequence)
		{
			HitRecord result = hit;
			for (int i = 0; i < 32; i++)
			{
				if (result.ParentSequence == 0)
				{
					break;
				}
				if (!indexBySequence.TryGetValue(result.ParentSequence, out var value))
				{
					break;
				}
				result = hits[value];
			}
			return result;
		}

		private unsafe static string KeyOf(HitRecord root)
		{
			if (root.Periodic)
			{
				return "tick:" + InstanceId((Object)(object)root.Target) + ":" + ((object)(*(DamageTypes*)(&root.DamageType))/*cast due to .constrained prefix*/).ToString() + ":" + root.Sequence;
			}
			if ((Object)(object)root.Weapon != (Object)null)
			{
				return "weapon:" + ((Object)root.Weapon).GetInstanceID();
			}
			return "source:" + root.SourceInstanceId;
		}

		private static TargetHits TargetOf(ShotOutcome outcome, HitRecord hit)
		{
			for (int i = 0; i < outcome.Targets.Count; i++)
			{
				if ((Object)(object)outcome.Targets[i].Target == (Object)(object)hit.Target)
				{
					return outcome.Targets[i];
				}
			}
			TargetHits targetHits = new TargetHits
			{
				Target = hit.Target,
				IsDummy = hit.TargetIsDummy
			};
			outcome.Targets.Add(targetHits);
			return targetHits;
		}

		private static int InstanceId(Object o)
		{
			if (!(o == (Object)null))
			{
				return o.GetInstanceID();
			}
			return 0;
		}

		internal unsafe static HitTerms ToTerms(HitRecord h)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			float num = ((h.HeadshotBonus > 0f) ? h.HeadshotBonus : 1f);
			float num2 = ((h.HitBonus > 1f) ? h.HitBonus : 1f);
			bool flag = h.ExplosionDamage > 0f && h.Falloff > 0f;
			return new HitTerms
			{
				Sequence = h.Sequence,
				ParentSequence = h.ParentSequence,
				DamageType = ((object)(*(DamageTypes*)(&h.DamageType))/*cast due to .constrained prefix*/).ToString(),
				Part = MapPart(h.Part),
				Periodic = h.Periodic,
				Incoming = (flag ? h.ExplosionDamage : (h.Incoming / num2)),
				Falloff = (flag ? h.Falloff : 1f),
				HitBonus = (flag ? 1f : num2),
				Crit = h.IsCritical,
				Oil = h.OilDoubled,
				GhostBonus = h.GhostBonus,
				PartFactor = h.PartMultiplier / num,
				HeadshotBonus = num,
				Mitigation = h.Mitigation,
				Final = h.Final
			};
		}

		private static BodyPart MapPart(Parts part)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected I4, but got Unknown
			return (int)part switch
			{
				0 => BodyPart.None, 
				2 => BodyPart.Eye, 
				4 => BodyPart.Head, 
				3 => BodyPart.Thorax, 
				7 => BodyPart.Body, 
				8 => BodyPart.Groin, 
				5 => BodyPart.Arm, 
				6 => BodyPart.Leg, 
				_ => BodyPart.Other, 
			};
		}
	}
	internal sealed class HudRoot : MonoBehaviour
	{
		private const float RetrySeconds = 1f;

		private static HudRoot _instance;

		private readonly HitAssembler _assembler = new HitAssembler();

		private readonly ScoreboardTracker _tracker = new ScoreboardTracker();

		private Canvas _canvas;

		private RectTransform _canvasRect;

		private FormulaView _formula;

		private ScoreboardView _scoreboard;

		private ScoreLineView _scoreLine;

		private TMP_FontAsset _font;

		private TMP_FontAsset _semibold;

		private TMP_FontAsset _numbers;

		private string _pluginDirectory;

		private AsyncAssetLoading _languageSource;

		private bool _languageDirty = true;

		private float _nextLanguageAttempt;

		private bool _fontsLogged;

		private bool _numbersLatin;

		private int _numberAttempts;

		private int _overlayErrors;

		private float _nextOverlayErrorLog;

		private const int NumberAttemptLimit = 30;

		public static void Create(string pluginDirectory)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (!((Object)(object)_instance != (Object)null))
			{
				GameObject val = new GameObject("Numbers Guy");
				Object.DontDestroyOnLoad((Object)val);
				_instance = val.AddComponent<HudRoot>();
				_instance._pluginDirectory = pluginDirectory;
			}
		}

		public static void DestroyInstance()
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				Object.Destroy((Object)(object)((Component)_instance).gameObject);
				_instance = null;
			}
		}

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			GameObject val = new GameObject("Numbers Guy Canvas", new Type[2]
			{
				typeof(Canvas),
				typeof(CanvasScaler)
			});
			val.transform.SetParent(((Component)this).transform, false);
			_canvas = val.GetComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = -90;
			((Behaviour)_canvas).enabled = false;
			CanvasScaler component = val.GetComponent<CanvasScaler>();
			component.uiScaleMode = (ScaleMode)1;
			component.referenceResolution = new Vector2(1920f, 1080f);
			component.matchWidthOrHeight = 1f;
			_canvasRect = (RectTransform)val.transform;
			_assembler.ShotResolved += OnShotResolved;
			HitCapture.HitCommitted += OnHit;
			HitCapture.ShotFired += OnShot;
			HitCapture.ProjectileFired += OnProjectile;
		}

		private void OnDestroy()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			HitCapture.HitCommitted -= OnHit;
			HitCapture.ShotFired -= OnShot;
			HitCapture.ProjectileFired -= OnProjectile;
			_assembler.ShotResolved -= OnShotResolved;
			if ((Object)(object)_languageSource != (Object)null)
			{
				_languageSource.onLanguageChange = (OnLanguageChange)Delegate.Remove((Delegate?)(object)_languageSource.onLanguageChange, (Delegate?)new OnLanguageChange(OnLanguageChange));
			}
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void OnHit(HitRecord hit)
		{
			_assembler.Add(hit);
		}

		private void OnShot(ShotRecord shot)
		{
			_tracker.OnShot(shot);
		}

		private void OnProjectile(ShotRecord shot)
		{
			_tracker.OnProjectile(shot);
		}

		private void LateUpdate()
		{
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				((Behaviour)_canvas).enabled = false;
				_assembler.Clear();
				float unscaledTime = Time.unscaledTime;
				_overlayErrors++;
				if (unscaledTime >= _nextOverlayErrorLog)
				{
					_nextOverlayErrorLog = unscaledTime + 10f;
					Plugin.Log.LogError((object)("The overlay failed and was hidden for this frame" + ((_overlayErrors > 1) ? (" (" + _overlayErrors + " failures since the last report)") : "") + ": " + ex));
					_overlayErrors = 0;
				}
			}
		}

		private void Tick()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			FollowLanguage(unscaledTime);
			_assembler.Flush();
			_tracker.Tick(unscaledTime);
			bool flag = IsLiveView();
			if (flag && KeyInput.WasPressedThisFrame(Plugin.ScoreboardResetKey.Value))
			{
				_tracker.Reset();
				if (Plugin.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)"[scoreboard] cleared by the reset key");
				}
			}
			if (!((Object)(object)_font == (Object)null))
			{
				EnsureViews();
				_formula.Tick(unscaledTime, Plugin.FormulaHoldTime.Value, Plugin.FormulaScale.Value);
				if (!Plugin.FormulaEnabled.Value && _formula.IsShowing)
				{
					_formula.Clear();
				}
				if (flag)
				{
					UpdateScoreboard(unscaledTime);
				}
				LogFontsOnce();
				((Behaviour)_canvas).enabled = flag;
			}
		}

		private void OnShotResolved(ShotOutcome outcome)
		{
			float unscaledTime = Time.unscaledTime;
			_tracker.OnOutcome(outcome, unscaledTime, Plugin.ScoreboardTargets.Value == TargetScope.DummiesAndEnemies);
			if (_formula == null || !Plugin.FormulaEnabled.Value || (outcome.Periodic && !Plugin.FormulaShowDamageOverTime.Value))
			{
				return;
			}
			bool flag = Plugin.FormulaTargets.Value == TargetScope.DummiesAndEnemies;
			TargetHits targetHits = null;
			for (int i = 0; i < outcome.Targets.Count; i++)
			{

NumbersGuy.SulfurTogether.dll

Decompiled 35 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using Microsoft.CodeAnalysis;
using SULFURTogether.Api;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("NumbersGuy.SulfurTogether")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NumbersGuy.SulfurTogether")]
[assembly: AssemblyTitle("NumbersGuy.SulfurTogether")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 NumbersGuy.SulfurTogether
{
	internal sealed class CombatBridge : IDisposable
	{
		private const int SupportedApiVersion = 1;

		private const int TeamMarksApiVersion = 2;

		public readonly int ApiVersion;

		private CombatBridge(int apiVersion)
		{
			ApiVersion = apiVersion;
		}

		public static CombatBridge TryCreate()
		{
			int apiVersion = NetCombat.ApiVersion;
			if (apiVersion < 1)
			{
				return null;
			}
			CombatBridge combatBridge = new CombatBridge(apiVersion);
			NumbersGuyIntegration.SetRemoteHitScope((Func<bool>)combatBridge.IsResolvingRemoteHit);
			if (apiVersion >= 2)
			{
				NumbersGuyIntegration.SetHitBonusScope((Func<float>)combatBridge.LocalHostHitMultiplier);
			}
			return combatBridge;
		}

		public void Dispose()
		{
			NumbersGuyIntegration.SetRemoteHitScope((Func<bool>)null);
			NumbersGuyIntegration.SetHitBonusScope((Func<float>)null);
		}

		private bool IsResolvingRemoteHit()
		{
			return NetCombat.IsResolvingRemoteHit;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private float LocalHostHitMultiplier()
		{
			return NetCombat.LocalHostHitMultiplier;
		}
	}
	[BepInPlugin("ryuka.sulfur.numbers_guy_sulfur_together", "Numbers Guy - SULFUR Together Adapter", "0.1.0")]
	[BepInDependency("ryuka.sulfur.numbers_guy", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class SulfurTogetherAdapterPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "ryuka.sulfur.numbers_guy_sulfur_together";

		public const string PluginName = "Numbers Guy - SULFUR Together Adapter";

		private const string SulfurTogetherGuid = "com.ryuka.sulfur.together";

		private const string Unfiltered = "as host, other players' hits on enemies may show as yours.";

		private IDisposable _bridge;

		private void Awake()
		{
			if (!Chainloader.PluginInfos.ContainsKey("com.ryuka.sulfur.together"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"SULFUR Together is not installed; nothing to connect.");
				return;
			}
			try
			{
				_bridge = Attach(out var apiVersion);
				((BaseUnityPlugin)this).Logger.LogInfo((object)((_bridge != null) ? ("Connected to SULFUR Together's combat API " + apiVersion + ".") : "The installed SULFUR Together has an unknown combat API; as host, other players' hits on enemies may show as yours."));
			}
			catch (Exception ex) when (IsMissingApi(ex))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("The installed SULFUR Together has no combat API (it needs 1.7.0 or newer); as host, other players' hits on enemies may show as yours. (" + ex.GetType().Name + ": " + ex.Message + ")"));
			}
		}

		private void OnDestroy()
		{
			if (_bridge != null)
			{
				_bridge.Dispose();
				_bridge = null;
			}
		}

		private static bool IsMissingApi(Exception e)
		{
			if (!(e is TypeLoadException) && !(e is MissingMethodException) && !(e is MissingFieldException) && !(e is TypeInitializationException))
			{
				return e is BadImageFormatException;
			}
			return true;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static IDisposable Attach(out int apiVersion)
		{
			CombatBridge combatBridge = CombatBridge.TryCreate();
			apiVersion = combatBridge?.ApiVersion ?? 0;
			return combatBridge;
		}
	}
}