Decompiled source of BuminCombatFeel v1.0.1

plugins/BuminCombatFeel.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BuminCombatFeel;

internal static class CameraFeel
{
	private static int _frame = -1;

	private static float _trauma;

	private static float _punchTarget;

	private static float _punch;

	private static Vector3 _dirKickTarget;

	private static Vector3 _dirKick;

	private static FieldInfo _fpActive;

	private static bool _fpLooked;

	internal static void Apply(Harmony harmony)
	{
		Plugin.PatchMethod(harmony, typeof(GameCamera), "UpdateCamera", typeof(CameraFeel), null, "AfterUpdate", 200);
	}

	internal static void AddImpact(float trauma, float punch)
	{
		float value = Plugin.ImpactStrength.Value;
		if (Plugin.Enabled.Value && !(value <= 0f))
		{
			_trauma = Mathf.Clamp01(_trauma + trauma * value);
			_punchTarget = Mathf.Min(_punchTarget + punch * value, 10f);
		}
	}

	internal static void AddDirectionalKick(Vector3 direction, float degrees, bool recoil)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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_00e9: 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)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		GameCamera instance = GameCamera.instance;
		float value = Plugin.ImpactStrength.Value;
		if (Plugin.Enabled.Value && !((Object)(object)instance == (Object)null) && !(degrees <= 0f) && !(value <= 0f) && !(((Vector3)(ref direction)).sqrMagnitude < 0.0001f))
		{
			Vector3 val = Quaternion.Inverse(((Component)instance).transform.rotation) * ((Vector3)(ref direction)).normalized;
			float num = Mathf.Clamp(val.x, -1f, 1f);
			float num2 = Mathf.Clamp(val.y, -1f, 1f);
			Vector3 val2 = (recoil ? new Vector3(-0.7f + 0.3f * num2, -0.6f * num, 0.6f * num) : new Vector3(0.6f - 0.4f * num2, 0.7f * num, -0.6f * num));
			_dirKickTarget = Vector3.ClampMagnitude(_dirKickTarget + val2 * (degrees * value), 4f);
		}
	}

	private static bool FirstPerson()
	{
		if (!_fpLooked)
		{
			_fpLooked = true;
			Type type = AccessTools.TypeByName("BuminCamera.FpsCamera");
			_fpActive = ((type != null) ? AccessTools.Field(type, "Active") : null);
		}
		if (_fpActive == null)
		{
			return false;
		}
		object value = _fpActive.GetValue(null);
		if (value is bool)
		{
			return (bool)value;
		}
		return false;
	}

	private static float Noise(int lane, float time)
	{
		return Mathf.PerlinNoise((float)lane * 17.31f + 0.5f, time) * 2f - 1f;
	}

	private static void Step(float step)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		_trauma = Mathf.Max(0f, _trauma - step * 1.8f);
		_punchTarget = Mathf.Lerp(_punchTarget, 0f, 1f - Mathf.Exp(-10f * step));
		_punch = Mathf.Lerp(_punch, _punchTarget, 1f - Mathf.Exp(-40f * step));
		_dirKickTarget = Vector3.Lerp(_dirKickTarget, Vector3.zero, 1f - Mathf.Exp(-10f * step));
		_dirKick = Vector3.Lerp(_dirKick, _dirKickTarget, 1f - Mathf.Exp(-30f * step));
	}

	private static void AfterUpdate(GameCamera __instance, float dt, Camera ___m_camera, Camera ___m_skyCamera, bool ___m_freeFly, bool ___m_cameraShakeEnabled)
	{
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		float step = ((Time.frameCount != _frame) ? Mathf.Max(0f, dt) : 0f);
		_frame = Time.frameCount;
		Step(step);
		if (!Plugin.Enabled.Value || ___m_freeFly || (Object)(object)___m_camera == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || (!(_trauma > 0.001f) && !(_punch > 0.01f) && !(((Vector3)(ref _dirKick)).sqrMagnitude > 1E-06f)))
		{
			return;
		}
		float num = (FirstPerson() ? Plugin.FirstPersonShare.Value : 1f);
		if (num <= 0f)
		{
			return;
		}
		bool flag = !Plugin.FollowGameShake.Value || ___m_cameraShakeEnabled;
		Transform transform = ((Component)__instance).transform;
		if (flag)
		{
			Quaternion val = transform.rotation;
			Vector3 val2 = transform.position;
			if (((Vector3)(ref _dirKick)).sqrMagnitude > 1E-06f)
			{
				Vector3 val3 = _dirKick * num;
				val *= Quaternion.Euler(val3.x, val3.y, val3.z);
			}
			if (_trauma > 0.001f)
			{
				float num2 = _trauma * _trauma * num;
				float time = Time.unscaledTime * 22f;
				val *= Quaternion.Euler(3f * num2 * Noise(0, time), 3f * num2 * Noise(1, time), 2f * num2 * Noise(2, time));
				val2 += val * new Vector3(Noise(3, time), Noise(4, time), 0f) * (0.05f * num2);
			}
			transform.rotation = val;
			transform.position = val2;
		}
		if (_punch > 0.01f)
		{
			float fieldOfView = (___m_camera.fieldOfView = Mathf.Clamp(___m_camera.fieldOfView - _punch * num, 10f, 150f));
			if ((Object)(object)___m_skyCamera != (Object)null)
			{
				___m_skyCamera.fieldOfView = fieldOfView;
			}
		}
	}
}
internal static class Combo
{
	private const float FadeOut = 0.45f;

	private static int _count;

	private static float _damage;

	private static float _last = -100f;

	private static float _bump;

	private static int _frame = -1;

	private static GameObject _root;

	private static RectTransform _rect;

	private static TextMeshProUGUI _countText;

	private static TextMeshProUGUI _totalText;

	private static RectTransform _totalRect;

	private static TMP_FontAsset _font;

	private static Material _material;

	private static int _shownCount = -1;

	private static int _shownDamage = -1;

	internal static void AddHit(float damage)
	{
		if (Plugin.Enabled.Value && Plugin.ComboOn.Value)
		{
			if (Time.time - _last > Plugin.ComboWindow.Value)
			{
				_count = 0;
				_damage = 0f;
			}
			_count++;
			_damage += Mathf.Max(0f, damage);
			_last = Time.time;
			_bump = 1f;
		}
	}

	internal static void AddDamage(float damage)
	{
		if (Time.time - _last <= Plugin.ComboWindow.Value + 0.5f)
		{
			_damage += Mathf.Max(0f, damage);
		}
	}

	internal static void Layout()
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.time - _last;
		float value = Plugin.ComboWindow.Value;
		if (!Plugin.Enabled.Value || !Plugin.ComboOn.Value || _count < Plugin.ComboMin.Value || !(num <= value + 0.45f) || Hud.IsUserHidden() || (Plugin.HideInMenus.Value && Plugin.InMenu()) || !((Object)(object)Player.m_localPlayer != (Object)null))
		{
			if ((Object)(object)_root != (Object)null && ((Transform)_rect).localScale.x != 0f)
			{
				((Transform)_rect).localScale = Vector3.zero;
			}
		}
		else if (Ensure())
		{
			float num2 = Mathf.Max(0.3f, (float)Screen.height / 1080f);
			TMP_FontAsset val = NumberFonts.Get(Plugin.Font.Value);
			if ((Object)(object)val != (Object)(object)_font)
			{
				_font = val;
				_material = NumberFonts.Material(val, Plugin.OutlineWidth.Value, Plugin.ColorOutline.Value, Plugin.Effect.Value, Plugin.ColorEffect.Value);
				Apply(_countText);
				Apply(_totalText);
			}
			else if ((Object)(object)((TMP_Text)_countText).font != (Object)(object)_font)
			{
				Apply(_countText);
				Apply(_totalText);
			}
			if (Time.frameCount != _frame)
			{
				_frame = Time.frameCount;
				_bump = Mathf.Max(0f, _bump - Time.unscaledDeltaTime / 0.18f);
			}
			float num3 = ((num <= value) ? 1f : (1f - (num - value) / 0.45f));
			if (_count != _shownCount)
			{
				_shownCount = _count;
				((TMP_Text)_countText).text = _count + "<size=55%> " + Plugin.ComboLabel.Value + "</size>";
			}
			int num4 = Mathf.RoundToInt(_damage);
			bool flag = Plugin.ComboTotal.Value && _damage > 0.5f;
			if (flag && num4 != _shownDamage)
			{
				_shownDamage = num4;
				((TMP_Text)_totalText).text = Numbers.Format(_damage);
			}
			else if (!flag && _shownDamage != -1)
			{
				_shownDamage = -1;
				((TMP_Text)_totalText).text = string.Empty;
			}
			float num5 = Plugin.ComboSize.Value * num2;
			((TMP_Text)_countText).fontSize = num5;
			((TMP_Text)_totalText).fontSize = num5 * 0.55f;
			_totalRect.anchoredPosition = new Vector2(0f, (0f - num5) * 0.85f);
			Color value2 = Plugin.ComboColor.Value;
			value2.a *= num3;
			((Graphic)_countText).color = value2;
			Color value3 = Plugin.ComboTotalColor.Value;
			value3.a *= num3;
			((Graphic)_totalText).color = value3;
			((Transform)_rect).position = new Vector3(Plugin.ComboX.Value * (float)Screen.width, Plugin.ComboY.Value * (float)Screen.height, 0f);
			float num6 = 1f + 0.35f * _bump * _bump;
			((Transform)_rect).localScale = Vector3.one * num6;
			((Transform)_rect).localRotation = Quaternion.Euler(0f, 0f, -4f * _bump);
		}
	}

	private static void Apply(TextMeshProUGUI text)
	{
		if ((Object)(object)_font == (Object)null)
		{
			return;
		}
		FontGuard.Enter();
		try
		{
			((TMP_Text)text).font = _font;
			if ((Object)(object)_material != (Object)null)
			{
				((TMP_Text)text).fontSharedMaterial = _material;
			}
		}
		finally
		{
			FontGuard.Exit();
		}
		((TMP_Text)text).fontStyle = (FontStyles)(Plugin.Bold.Value ? 3 : 2);
	}

	internal static void MarkDirty()
	{
		_font = null;
		_shownCount = -1;
		_shownDamage = -1;
	}

	private static bool Ensure()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_root != (Object)null)
		{
			return true;
		}
		Transform root = NumberView.Root;
		if ((Object)(object)root == (Object)null)
		{
			return false;
		}
		FontGuard.Enter();
		try
		{
			_root = new GameObject("Combo", new Type[1] { typeof(RectTransform) });
			_root.transform.SetParent(root, false);
			_rect = (RectTransform)_root.transform;
			_rect.sizeDelta = new Vector2(500f, 120f);
			_countText = _root.AddComponent<TextMeshProUGUI>();
			Setup(_countText);
			GameObject val = new GameObject("Total", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(_root.transform, false);
			_totalRect = (RectTransform)val.transform;
			_totalRect.sizeDelta = new Vector2(500f, 80f);
			_totalText = val.AddComponent<TextMeshProUGUI>();
			Setup(_totalText);
		}
		finally
		{
			FontGuard.Exit();
		}
		_font = null;
		_shownCount = -1;
		_shownDamage = -1;
		return true;
	}

	private static void Setup(TextMeshProUGUI text)
	{
		((Graphic)text).raycastTarget = false;
		((TMP_Text)text).richText = true;
		((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
		((TMP_Text)text).overflowMode = (TextOverflowModes)0;
		((TMP_Text)text).alignment = (TextAlignmentOptions)514;
		((TMP_Text)text).text = string.Empty;
	}
}
internal static class HitFlash
{
	private sealed class Part
	{
		public Renderer Renderer;

		public bool HadBlock;

		public bool HasEmission;

		public bool BlockEmission;

		public Color Emission;

		public bool HasValue;

		public bool BlockValue;

		public float Value;
	}

	private sealed class Flash
	{
		public readonly List<Part> Parts = new List<Part>();

		public float Age;

		public float Time;

		public Color Color;

		public float Strength;

		public bool Brighten;

		public Material Overlay;
	}

	private const int MaxRenderers = 16;

	private const float ValueBoost = 0.35f;

	private const float EmissionBoost = 1.6f;

	private const float OverlayAlpha = 0.55f;

	private static readonly string[] OverlayShaders = new string[5] { "Hidden/Internal-Colored", "Legacy Shaders/Particles/Additive", "Particles/Additive", "Mobile/Particles/Additive", "Sprites/Default" };

	private static readonly Dictionary<Character, Flash> Flashes = new Dictionary<Character, Flash>();

	private static readonly List<Character> Ended = new List<Character>();

	private static readonly Stack<Material> OverlayPool = new Stack<Material>();

	private static readonly List<Renderer> Found = new List<Renderer>();

	private static MaterialPropertyBlock _block;

	private static int _emissionId;

	private static int _valueId;

	private static int _colorId;

	private static int _tintId;

	private static Shader _overlayShader;

	private static string _overlayName;

	private static bool _shaderLooked;

	private static bool _logged;

	private static bool _failed;

	internal static void Trigger(Character target, Color color, float strength)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		if (_failed || !Plugin.Enabled.Value || !Plugin.FlashOn.Value || (Object)(object)target == (Object)null || (Object)(object)target == (Object)(object)Player.m_localPlayer || (target.IsPlayer() && !Plugin.FlashPlayers.Value))
		{
			return;
		}
		try
		{
			Begin(target, color, Mathf.Clamp(strength, 0.2f, 2f));
		}
		catch (Exception ex)
		{
			_failed = true;
			Plugin.Log.LogWarning((object)("Hit flash is off: " + ex));
			ReleaseAll();
		}
	}

	private static void Setup()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		if (_block == null)
		{
			_block = new MaterialPropertyBlock();
			_emissionId = Shader.PropertyToID("_EmissionColor");
			_valueId = Shader.PropertyToID("_Value");
			_colorId = Shader.PropertyToID("_Color");
			_tintId = Shader.PropertyToID("_TintColor");
		}
	}

	private static void Begin(Character target, Color color, float strength)
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		Setup();
		float num = Plugin.FlashTime.Value * (0.8f + 0.25f * strength);
		if (Flashes.TryGetValue(target, out var value))
		{
			value.Age = 0f;
			value.Time = Mathf.Max(num, value.Time - value.Age);
			value.Color = color;
			value.Strength = Mathf.Max(strength, value.Strength * 0.5f);
			return;
		}
		FlashStyle value2 = Plugin.FlashKind.Value;
		Flash flash = new Flash();
		flash.Time = num;
		flash.Color = color;
		flash.Strength = strength;
		flash.Brighten = value2 != FlashStyle.Overlay;
		value = flash;
		bool flag = value2 != FlashStyle.Brighten && (Object)(object)OverlayShader() != (Object)null;
		Found.Clear();
		((Component)target).GetComponentsInChildren<Renderer>(false, Found);
		int num2 = 0;
		foreach (Renderer item in Found)
		{
			if (value.Parts.Count >= 16)
			{
				break;
			}
			if ((Object)(object)item == (Object)null || !item.enabled || (!(item is SkinnedMeshRenderer) && !(item is MeshRenderer)))
			{
				continue;
			}
			Material sharedMaterial = item.sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null)
			{
				continue;
			}
			Part part = new Part();
			part.Renderer = item;
			Part part2 = part;
			if (value.Brighten)
			{
				part2.HadBlock = item.HasPropertyBlock();
				item.GetPropertyBlock(_block);
				part2.HasEmission = sharedMaterial.HasProperty(_emissionId);
				if (part2.HasEmission)
				{
					part2.BlockEmission = part2.HadBlock && _block.HasProperty(_emissionId);
					part2.Emission = (part2.BlockEmission ? _block.GetColor(_emissionId) : sharedMaterial.GetColor(_emissionId));
				}
				part2.HasValue = sharedMaterial.HasProperty(_valueId);
				if (part2.HasValue)
				{
					part2.BlockValue = part2.HadBlock && _block.HasProperty(_valueId);
					part2.Value = (part2.BlockValue ? _block.GetFloat(_valueId) : sharedMaterial.GetFloat(_valueId));
				}
				if (part2.HasEmission || part2.HasValue)
				{
					num2++;
				}
			}
			value.Parts.Add(part2);
		}
		Found.Clear();
		if (value.Parts.Count == 0)
		{
			return;
		}
		if (flag)
		{
			value.Overlay = TakeOverlay();
			foreach (Part part3 in value.Parts)
			{
				AddOverlay(part3.Renderer, value.Overlay);
			}
		}
		Flashes[target] = value;
		if (!_logged)
		{
			_logged = true;
			Plugin.Log.LogInfo((object)string.Concat("Hit flash: ", value2, ". Brighten found a glow or brightness value on ", num2, " of ", value.Parts.Count, " renderers of ", ((Object)target).name, "; overlay shader: ", _overlayName ?? "none", "."));
		}
		Apply(value, value.Strength * Plugin.FlashStrength.Value);
	}

	private static Shader OverlayShader()
	{
		if (_shaderLooked)
		{
			return _overlayShader;
		}
		_shaderLooked = true;
		string[] overlayShaders = OverlayShaders;
		foreach (string text in overlayShaders)
		{
			Shader val = Shader.Find(text);
			if ((Object)(object)val != (Object)null && val.isSupported)
			{
				_overlayShader = val;
				_overlayName = text;
				break;
			}
		}
		if ((Object)(object)_overlayShader == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Hit flash: no overlay shader found in this game; only Brighten is used.");
		}
		return _overlayShader;
	}

	private static Material TakeOverlay()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		while (OverlayPool.Count > 0)
		{
			Material val = OverlayPool.Pop();
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		Material val2 = new Material(_overlayShader);
		((Object)val2).name = "BuminCombatFeel hit flash";
		((Object)val2).hideFlags = (HideFlags)52;
		val2.renderQueue = 3001;
		SetInt(val2, "_SrcBlend", 5);
		SetInt(val2, "_DstBlend", 1);
		SetInt(val2, "_ZWrite", 0);
		SetInt(val2, "_ZTest", 4);
		SetInt(val2, "_Cull", 2);
		return val2;
	}

	private static void SetInt(Material material, string name, int value)
	{
		if (material.HasProperty(name))
		{
			material.SetInt(name, value);
		}
	}

	private static void AddOverlay(Renderer renderer, Material overlay)
	{
		Material[] sharedMaterials = renderer.sharedMaterials;
		Material[] array = (Material[])(object)new Material[sharedMaterials.Length + 1];
		Array.Copy(sharedMaterials, array, sharedMaterials.Length);
		array[sharedMaterials.Length] = overlay;
		renderer.sharedMaterials = array;
	}

	private static void RemoveOverlay(Renderer renderer, Material overlay)
	{
		Material[] sharedMaterials = renderer.sharedMaterials;
		int num = 0;
		Material[] array = sharedMaterials;
		foreach (Material val in array)
		{
			if ((Object)(object)val != (Object)(object)overlay)
			{
				num++;
			}
		}
		if (num == sharedMaterials.Length)
		{
			return;
		}
		Material[] array2 = (Material[])(object)new Material[num];
		int num2 = 0;
		Material[] array3 = sharedMaterials;
		foreach (Material val2 in array3)
		{
			if ((Object)(object)val2 != (Object)(object)overlay)
			{
				array2[num2++] = val2;
			}
		}
		renderer.sharedMaterials = array2;
	}

	internal static void LateTick(float dt)
	{
		if (Flashes.Count == 0)
		{
			return;
		}
		try
		{
			Ended.Clear();
			bool flag = Plugin.Enabled.Value && Plugin.FlashOn.Value;
			foreach (KeyValuePair<Character, Flash> flash in Flashes)
			{
				Flash value = flash.Value;
				value.Age += dt;
				if ((Object)(object)flash.Key == (Object)null || !flag || value.Age >= value.Time)
				{
					Ended.Add(flash.Key);
					continue;
				}
				float num = 1f - value.Age / value.Time;
				Apply(value, num * num * value.Strength * Plugin.FlashStrength.Value);
			}
			foreach (Character item in Ended)
			{
				if (Flashes.TryGetValue(item, out var value2))
				{
					End(value2);
					Flashes.Remove(item);
				}
			}
			Ended.Clear();
		}
		catch (Exception ex)
		{
			_failed = true;
			Plugin.Log.LogWarning((object)("Hit flash is off: " + ex));
			ReleaseAll();
		}
	}

	private static void Apply(Flash flash, float k)
	{
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		foreach (Part part in flash.Parts)
		{
			Renderer renderer = part.Renderer;
			if (!((Object)(object)renderer == (Object)null) && flash.Brighten && (part.HasEmission || part.HasValue))
			{
				renderer.GetPropertyBlock(_block);
				if (part.HasEmission)
				{
					_block.SetColor(_emissionId, part.Emission + flash.Color * (k * 1.6f));
				}
				if (part.HasValue)
				{
					_block.SetFloat(_valueId, part.Value + 0.35f * k);
				}
				renderer.SetPropertyBlock(_block);
			}
		}
		if ((Object)(object)flash.Overlay != (Object)null)
		{
			Color color = flash.Color;
			color.a = Mathf.Clamp01(0.55f * k);
			if (flash.Overlay.HasProperty(_tintId))
			{
				flash.Overlay.SetColor(_tintId, new Color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, color.a));
			}
			else if (flash.Overlay.HasProperty(_colorId))
			{
				flash.Overlay.SetColor(_colorId, color);
			}
		}
	}

	private static void End(Flash flash)
	{
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		foreach (Part part in flash.Parts)
		{
			Renderer renderer = part.Renderer;
			if ((Object)(object)renderer == (Object)null)
			{
				continue;
			}
			if ((Object)(object)flash.Overlay != (Object)null)
			{
				RemoveOverlay(renderer, flash.Overlay);
			}
			if (!flash.Brighten || (!part.HasEmission && !part.HasValue))
			{
				continue;
			}
			if (!part.HadBlock)
			{
				renderer.SetPropertyBlock((MaterialPropertyBlock)null);
				continue;
			}
			renderer.GetPropertyBlock(_block);
			Material sharedMaterial = renderer.sharedMaterial;
			if (part.HasEmission)
			{
				_block.SetColor(_emissionId, (part.BlockEmission || (Object)(object)sharedMaterial == (Object)null) ? part.Emission : sharedMaterial.GetColor(_emissionId));
			}
			if (part.HasValue)
			{
				_block.SetFloat(_valueId, (part.BlockValue || (Object)(object)sharedMaterial == (Object)null) ? part.Value : sharedMaterial.GetFloat(_valueId));
			}
			renderer.SetPropertyBlock(_block);
		}
		if ((Object)(object)flash.Overlay != (Object)null)
		{
			OverlayPool.Push(flash.Overlay);
			flash.Overlay = null;
		}
	}

	internal static void ReleaseAll()
	{
		foreach (KeyValuePair<Character, Flash> flash in Flashes)
		{
			try
			{
				End(flash.Value);
			}
			catch (Exception)
			{
			}
		}
		Flashes.Clear();
	}
}
internal static class Impact
{
	private sealed class Watch
	{
		public Character Target;

		public float Time;

		public bool Melee;

		public bool Staggered;

		public Color Flash;
	}

	private sealed class Freeze
	{
		public Animator Animator;

		public float Left;

		public float Speed;
	}

	private const float OneHanded = 0.38f;

	private const float TwoHanded = 0.5f;

	private const float Unarmed = 0.3f;

	private const float Secondary = 1.25f;

	private const float Block = 0.35f;

	private const float Parry = 0.55f;

	private const float GuardBroken = 0.6f;

	private const float PerfectBlockWindow = 0.25f;

	private const float VanillaFreeze = 0.15f;

	private const float HeavyPower = 0.65f;

	private const float WatchTime = 0.6f;

	private const float FrozenSpeed = 0.05f;

	private const float MaxFreeze = 0.3f;

	private const float MineTime = 1.5f;

	private static FieldInfo _secondary;

	private static FieldInfo _animEvent;

	private static FieldInfo _animator;

	private static MethodInfo _freezeFrame;

	private static int _hitFrame = -1;

	private static float _hitPower;

	private static bool _hitCrit;

	private static Vector3 _hitPoint;

	private static readonly List<Watch> Watches = new List<Watch>();

	private static readonly Dictionary<Character, Freeze> Freezes = new Dictionary<Character, Freeze>();

	private static readonly List<Character> Done = new List<Character>();

	private static readonly Dictionary<Character, float> Mine = new Dictionary<Character, float>();

	private static readonly Dictionary<Character, float> CritShown = new Dictionary<Character, float>();

	private static readonly List<Character> Stale = new List<Character>();

	internal static void Apply(Harmony harmony)
	{
		_secondary = AccessTools.Field(typeof(Humanoid), "m_currentAttackIsSecondary");
		_animEvent = AccessTools.Field(typeof(Character), "m_animEvent");
		_animator = AccessTools.Field(typeof(Character), "m_animator");
		_freezeFrame = AccessTools.Method(typeof(CharacterAnimEvent), "FreezeFrame", (Type[])null, (Type[])null);
		Plugin.PatchMethod(harmony, typeof(Character), "Damage", typeof(Impact), "BeforeDamage", null, 400);
		Plugin.PatchMethod(harmony, typeof(Character), "FreezeFrame", typeof(Impact), null, "OnHitLanded", 400);
		Plugin.PatchMethod(harmony, typeof(Humanoid), "BlockAttack", typeof(Impact), "BeforeBlock", "AfterBlock", 400);
	}

	internal static bool HitByMe(Character character)
	{
		if ((Object)(object)character != (Object)null && Mine.TryGetValue(character, out var value))
		{
			return Time.time - value <= 1.5f;
		}
		return false;
	}

	private static void BeforeDamage(Character __instance, HitData hit)
	{
		//IL_0037: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: 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_0234: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Plugin.Enabled.Value || (Object)(object)localPlayer == (Object)null || hit == null || (Object)(object)__instance == (Object)null || (Object)(object)__instance == (Object)(object)localPlayer || !((ZDOID)(ref hit.m_attacker)).Equals(((Character)localPlayer).GetZDOID()) || __instance.IsDead() || __instance.GetHealth() <= 0f)
		{
			return;
		}
		float num = Mathf.Clamp01(Mathf.Sqrt(hit.GetTotalDamage() / Mathf.Max(__instance.GetMaxHealth(), 40f)) * 1.25f);
		BaseAI baseAI = __instance.GetBaseAI();
		bool flag = hit.m_backstabBonus > 1f && (Object)(object)baseAI != (Object)null && !baseAI.IsAlerted();
		bool flag2 = !hit.m_ranged;
		Mine[__instance] = Time.time;
		Combo.AddHit(Plugin.NumbersOn.Value ? 0f : hit.GetTotalDamage());
		if (flag2)
		{
			if (_hitFrame != Time.frameCount)
			{
				_hitFrame = Time.frameCount;
				_hitPower = 0f;
				_hitCrit = false;
			}
			if (num >= _hitPower)
			{
				_hitPower = num;
				_hitPoint = hit.m_point;
			}
			_hitCrit |= flag;
		}
		else if (Plugin.RangedShake.Value > 0f)
		{
			CameraFeel.AddImpact(0.16f * Plugin.RangedShake.Value * (0.6f + 0.6f * num), 0.3f * Plugin.MeleePunch.Value * Plugin.RangedShake.Value);
		}
		if (Plugin.HitStop.Value)
		{
			float num2 = Plugin.HitStopTarget.Value * (0.6f + 0.8f * num) * (flag ? 1.5f : 1f) * (flag2 ? 1f : 0.6f);
			if (flag)
			{
				num2 += Plugin.HitStopCrit.Value;
			}
			FreezeCharacter(__instance, num2);
		}
		Color val = (flag ? Plugin.FlashCritColor.Value : FlashColorOf(hit));
		if (flag2 || Plugin.FlashRanged.Value)
		{
			HitFlash.Trigger(__instance, val, (0.7f + 0.5f * num) * (flag ? 1.3f : 1f));
		}
		AddWatch(__instance, flag2, val);
	}

	private static Color FlashColorOf(HitData hit)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		Color value = Plugin.FlashColor.Value;
		if (!Plugin.FlashElement.Value)
		{
			return value;
		}
		DamageTypes damage = hit.m_damage;
		float num = damage.m_damage + damage.m_blunt + damage.m_slash + damage.m_pierce + damage.m_chop + damage.m_pickaxe;
		float best = 0f;
		int bestKind = -1;
		Pick(damage.m_fire, 1, ref best, ref bestKind);
		Pick(damage.m_frost, 2, ref best, ref bestKind);
		Pick(damage.m_lightning, 3, ref best, ref bestKind);
		Pick(damage.m_poison, 4, ref best, ref bestKind);
		Pick(damage.m_spirit, 5, ref best, ref bestKind);
		if (bestKind < 0 || best < num)
		{
			return value;
		}
		Color result = Numbers.ElementColor(bestKind);
		result.a = 1f;
		return result;
	}

	private static void Pick(float value, int kind, ref float best, ref int bestKind)
	{
		if (value > best)
		{
			best = value;
			bestKind = kind;
		}
	}

	private static void OnHitLanded(Character __instance)
	{
		//IL_0048: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Invalid comparison between Unknown and I4
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Invalid comparison between Unknown and I4
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		Player val = (Player)(object)((__instance is Player) ? __instance : null);
		if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || !Plugin.Enabled.Value)
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
		float num = 0.38f;
		if (currentWeapon != null && currentWeapon.m_shared != null)
		{
			ItemType itemType = currentWeapon.m_shared.m_itemType;
			if ((int)itemType == 14 || (int)itemType == 22)
			{
				num = 0.5f;
			}
			else if ((int)currentWeapon.m_shared.m_skillType == 11)
			{
				num = 0.3f;
			}
		}
		bool flag = IsSecondary((Humanoid)(object)val);
		if (flag)
		{
			num *= 1.25f;
		}
		bool flag2 = _hitFrame == Time.frameCount;
		float num2 = (flag2 ? _hitPower : 0.5f);
		bool flag3 = flag2 && _hitCrit;
		float num3 = (0.75f + 0.5f * num2) * (flag3 ? 1.25f : 1f);
		bool flag4 = flag2 && (num2 >= 0.65f || flag3 || flag);
		float punch = Plugin.MeleePunch.Value * num3 * (flag4 ? 1.4f : 1f);
		CameraFeel.AddImpact(num * Plugin.MeleeShake.Value * num3, punch);
		if (flag2 && Plugin.DirectionalKick.Value && (Object)(object)GameCamera.instance != (Object)null)
		{
			float degrees = Plugin.DirectionalKickStrength.Value * (0.6f + 0.6f * num2) * (flag4 ? 1.3f : 1f);
			CameraFeel.AddDirectionalKick(_hitPoint - ((Component)GameCamera.instance).transform.position, degrees, recoil: false);
		}
		if (flag4)
		{
			if (Plugin.HitStop.Value)
			{
				ExtendOwnFreeze(val, Plugin.HitStopHeavy.Value * (flag3 ? 1.3f : 1f));
			}
			if (Plugin.ScreenPulse.Value)
			{
				ScreenPulse.Add(0.6f + 0.4f * num2);
			}
			ScreenPulse.AddBlur(0.5f + 0.5f * num2);
		}
	}

	internal static void OnCriticalNumber(Character target)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.Enabled.Value && !((Object)(object)target == (Object)null) && HitByMe(target) && (!CritShown.TryGetValue(target, out var value) || !(Time.time - value < 0.2f)))
		{
			CritShown[target] = Time.time;
			HitFlash.Trigger(target, Plugin.FlashCritColor.Value, 1.3f);
			if (Plugin.HitStop.Value)
			{
				FreezeCharacter(target, Plugin.HitStopTarget.Value + Plugin.HitStopCrit.Value);
			}
			CameraFeel.AddImpact(0.12f, Plugin.MeleePunch.Value * 0.6f);
			if (Plugin.ScreenPulse.Value)
			{
				ScreenPulse.Add(0.45f);
			}
		}
	}

	private static void BeforeBlock(Humanoid __instance, float ___m_blockTimer, out float __state)
	{
		__state = ___m_blockTimer;
	}

	private static void AfterBlock(Humanoid __instance, HitData hit, bool __result, float __state)
	{
		//IL_00df: 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)
		if (!__result || (Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || !Plugin.Enabled.Value)
		{
			return;
		}
		float num;
		if (((Character)__instance).IsStaggering())
		{
			CameraFeel.AddImpact(0.6f * Plugin.BlockShake.Value, 0f);
			num = 1.4f;
		}
		else if (__state >= 0f && __state < 0.25f)
		{
			CameraFeel.AddImpact(0.55f * Plugin.ParryShake.Value, Plugin.MeleePunch.Value);
			num = 1f;
			if (Plugin.ScreenPulse.Value)
			{
				ScreenPulse.Add(0.5f);
			}
		}
		else
		{
			CameraFeel.AddImpact(0.35f * Plugin.BlockShake.Value, 0f);
			num = 0.7f;
		}
		if (hit != null && Plugin.DirectionalKick.Value && ((Vector3)(ref hit.m_dir)).sqrMagnitude > 0.0001f)
		{
			CameraFeel.AddDirectionalKick(-hit.m_dir, Plugin.DirectionalKickStrength.Value * num, recoil: true);
		}
	}

	private static bool IsSecondary(Humanoid character)
	{
		if (_secondary == null || (Object)(object)character == (Object)null)
		{
			return false;
		}
		object value = _secondary.GetValue(character);
		if (value is bool)
		{
			return (bool)value;
		}
		return false;
	}

	internal static void Update(float dt)
	{
		for (int num = Watches.Count - 1; num >= 0; num--)
		{
			Watch watch = Watches[num];
			watch.Time += dt;
			Character target = watch.Target;
			if ((Object)(object)target == (Object)null || target.IsDead() || target.GetHealth() <= 0f)
			{
				Watches.RemoveAt(num);
				OnKill(watch);
			}
			else
			{
				if (!watch.Staggered && target.IsStaggering())
				{
					watch.Staggered = true;
					OnStagger(target);
				}
				if (watch.Time > 0.6f)
				{
					Watches.RemoveAt(num);
				}
			}
		}
		if (Mine.Count > 32)
		{
			Stale.Clear();
			foreach (KeyValuePair<Character, float> item in Mine)
			{
				if ((Object)(object)item.Key == (Object)null || Time.time - item.Value > 1.5f)
				{
					Stale.Add(item.Key);
				}
			}
			foreach (Character item2 in Stale)
			{
				Mine.Remove(item2);
				CritShown.Remove(item2);
			}
		}
		if (Freezes.Count == 0)
		{
			return;
		}
		Done.Clear();
		foreach (KeyValuePair<Character, Freeze> freeze in Freezes)
		{
			Freeze value = freeze.Value;
			value.Left -= dt;
			if ((Object)(object)freeze.Key == (Object)null || (Object)(object)value.Animator == (Object)null)
			{
				Done.Add(freeze.Key);
			}
			else if (value.Left <= 0f)
			{
				value.Animator.speed = value.Speed;
				Done.Add(freeze.Key);
			}
			else
			{
				value.Animator.speed = 0.05f;
			}
		}
		foreach (Character item3 in Done)
		{
			Freezes.Remove(item3);
		}
	}

	internal static void ReleaseAll()
	{
		foreach (KeyValuePair<Character, Freeze> freeze in Freezes)
		{
			if ((Object)(object)freeze.Value.Animator != (Object)null)
			{
				freeze.Value.Animator.speed = freeze.Value.Speed;
			}
		}
		Freezes.Clear();
		Watches.Clear();
		Mine.Clear();
		CritShown.Clear();
	}

	private static void OnKill(Watch watch)
	{
		if (!Plugin.Enabled.Value || !Plugin.KillStagger.Value)
		{
			return;
		}
		float value = Plugin.KillStrength.Value;
		if (!(value <= 0f))
		{
			CameraFeel.AddImpact(0.35f * value, Plugin.MeleePunch.Value * 0.8f * value);
			if (Plugin.ScreenPulse.Value)
			{
				ScreenPulse.Add(0.8f * value);
			}
			ScreenPulse.AddBlur(0.8f * value);
			ScreenPulse.AddFade(value);
			Player localPlayer = Player.m_localPlayer;
			if (watch.Melee && watch.Time <= 0.12f && Plugin.HitStop.Value && (Object)(object)localPlayer != (Object)null)
			{
				ExtendOwnFreeze(localPlayer, Plugin.HitStopHeavy.Value * 1.5f * value);
			}
		}
	}

	private static void OnStagger(Character target)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Enabled.Value || !Plugin.KillStagger.Value)
		{
			return;
		}
		float value = Plugin.StaggerStrength.Value;
		if (!(value <= 0f))
		{
			CameraFeel.AddImpact(0.25f * value, Plugin.MeleePunch.Value * 0.6f * value);
			HitFlash.Trigger(target, Plugin.FlashColor.Value, 1.2f * value);
			if (Plugin.HitStop.Value)
			{
				FreezeCharacter(target, 0.08f * value);
			}
			if (Plugin.ScreenPulse.Value)
			{
				ScreenPulse.Add(0.5f * value);
			}
		}
	}

	private static void AddWatch(Character target, bool melee, Color flash)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		foreach (Watch watch in Watches)
		{
			if ((Object)(object)watch.Target == (Object)(object)target)
			{
				watch.Time = 0f;
				watch.Melee = melee;
				watch.Flash = flash;
				watch.Staggered |= target.IsStaggering();
				return;
			}
		}
		Watches.Add(new Watch
		{
			Target = target,
			Melee = melee,
			Staggered = target.IsStaggering(),
			Flash = flash
		});
	}

	private static void FreezeCharacter(Character character, float time)
	{
		if (time <= 0.001f || _animator == null || (Object)(object)character == (Object)null)
		{
			return;
		}
		time = Mathf.Min(time, 0.3f);
		if (Freezes.TryGetValue(character, out var value))
		{
			value.Left = Mathf.Max(value.Left, time);
			return;
		}
		object? value2 = _animator.GetValue(character);
		Animator val = (Animator)((value2 is Animator) ? value2 : null);
		if (!((Object)(object)val == (Object)null))
		{
			float speed = val.speed;
			Freezes[character] = new Freeze
			{
				Animator = val,
				Left = time,
				Speed = ((speed > 0.01f) ? speed : 1f)
			};
			val.speed = 0.05f;
		}
	}

	private static void ExtendOwnFreeze(Player player, float extra)
	{
		if (!(extra <= 0.001f) && !(_animEvent == null) && !(_freezeFrame == null))
		{
			object? value = _animEvent.GetValue(player);
			CharacterAnimEvent val = (CharacterAnimEvent)((value is CharacterAnimEvent) ? value : null);
			if ((Object)(object)val != (Object)null)
			{
				_freezeFrame.Invoke(val, new object[1] { Mathf.Min(0.15f + extra, 0.3f) });
			}
		}
	}
}
internal static class NumberFonts
{
	private sealed class Choice
	{
		public string Name;

		public string File;

		public string[] Game;
	}

	internal const string Same = "Same";

	internal const string GameDefault = "Valheim Default";

	private const string DefaultChoice = "Valheim Norse Bold";

	private static readonly string[,] WindowsFonts = new string[18, 2]
	{
		{ "Impact", "impact.ttf" },
		{ "Arial Black", "ariblk.ttf" },
		{ "Bahnschrift", "bahnschrift.ttf" },
		{ "Segoe UI Black", "seguibl.ttf" },
		{ "Segoe UI Bold", "segoeuib.ttf" },
		{ "Georgia Bold", "georgiab.ttf" },
		{ "Trebuchet Bold", "trebucbd.ttf" },
		{ "Verdana Bold", "verdanab.ttf" },
		{ "Times Bold", "timesbd.ttf" },
		{ "Comic Sans Bold", "comicbd.ttf" },
		{ "Cambria Bold", "cambriab.ttf" },
		{ "Consolas Bold", "consolab.ttf" },
		{ "Calibri Bold", "calibrib.ttf" },
		{ "Palatino Bold", "palab.ttf" },
		{ "Constantia Bold", "constanb.ttf" },
		{ "Tahoma Bold", "tahomabd.ttf" },
		{ "Franklin Gothic", "framd.ttf" },
		{ "Lucida Console", "lucon.ttf" }
	};

	private static List<Choice> _choices;

	private static readonly Dictionary<string, TMP_FontAsset> Built = new Dictionary<string, TMP_FontAsset>();

	private static readonly Dictionary<string, float> Missed = new Dictionary<string, float>();

	private static readonly Dictionary<string, Material> Materials = new Dictionary<string, Material>();

	private static readonly List<Font> Sources = new List<Font>();

	private static TMP_FontAsset _base;

	private static bool _listedGameFonts;

	internal static string[] Choices()
	{
		_choices = new List<Choice>();
		Add("Valheim Default", null, null);
		Add("Valheim Norse Bold", null, new string[3] { "norsebold", "norse-bold", "norse bold" });
		Add("Valheim Norse", null, new string[1] { "norse" });
		Add("Valheim Averia Serif", null, new string[1] { "averiaserif" });
		Add("Valheim Averia Sans", null, new string[3] { "averiasans", "averialibre", "averia" });
		try
		{
			string text = Path.Combine(Paths.PluginPath, Path.Combine("Bumin-BuminFixes", Path.Combine("fonts", "Caudex-Regular.ttf")));
			if (File.Exists(text))
			{
				Add("Caudex", text, null);
			}
			string path = Path.Combine(Path.GetDirectoryName(typeof(NumberFonts).Assembly.Location) ?? "", "fonts");
			if (Directory.Exists(path))
			{
				List<string> list = new List<string>(Directory.GetFiles(path, "*.ttf"));
				list.AddRange(Directory.GetFiles(path, "*.otf"));
				list.Sort(StringComparer.OrdinalIgnoreCase);
				foreach (string item in list)
				{
					Add(Path.GetFileNameWithoutExtension(item), item, null);
				}
			}
			string text2 = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
			if (string.IsNullOrEmpty(text2))
			{
				text2 = "C:\\Windows\\Fonts";
			}
			for (int i = 0; i < WindowsFonts.GetLength(0); i++)
			{
				string text3 = Path.Combine(text2, WindowsFonts[i, 1]);
				if (File.Exists(text3))
				{
					Add(WindowsFonts[i, 0], text3, null);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not look for fonts: " + ex.Message));
		}
		string[] array = new string[_choices.Count];
		for (int j = 0; j < array.Length; j++)
		{
			array[j] = _choices[j].Name;
		}
		return array;
	}

	private static void Add(string name, string file, string[] game)
	{
		foreach (Choice choice in _choices)
		{
			if (string.Equals(choice.Name, name, StringComparison.OrdinalIgnoreCase))
			{
				return;
			}
		}
		_choices.Add(new Choice
		{
			Name = name,
			File = file,
			Game = game
		});
	}

	internal static string Default(string[] fonts)
	{
		if (Array.IndexOf(fonts, "Valheim Norse Bold") < 0)
		{
			return fonts[0];
		}
		return "Valheim Norse Bold";
	}

	internal static void MarkDirty()
	{
		Missed.Clear();
	}

	internal static TMP_FontAsset Base()
	{
		if ((Object)(object)_base != (Object)null)
		{
			return _base;
		}
		DamageText instance = DamageText.instance;
		if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_worldTextBase != (Object)null)
		{
			TMP_Text component = instance.m_worldTextBase.GetComponent<TMP_Text>();
			if ((Object)(object)component != (Object)null)
			{
				_base = component.font;
			}
		}
		if ((Object)(object)_base == (Object)null && (Object)(object)EnemyHud.instance != (Object)null && (Object)(object)EnemyHud.instance.m_baseHud != (Object)null)
		{
			TextMeshProUGUI componentInChildren = EnemyHud.instance.m_baseHud.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				_base = ((TMP_Text)componentInChildren).font;
			}
		}
		if ((Object)(object)_base == (Object)null)
		{
			_base = TMP_Settings.defaultFontAsset;
		}
		return _base;
	}

	internal static TMP_FontAsset Get(string name)
	{
		TMP_FontAsset val = Base();
		if ((Object)(object)val == (Object)null || string.IsNullOrEmpty(name) || name == "Valheim Default" || name == "Same")
		{
			return val;
		}
		if (Built.TryGetValue(name, out var value))
		{
			if (!((Object)(object)value != (Object)null))
			{
				return val;
			}
			return value;
		}
		if (Missed.TryGetValue(name, out var value2) && Time.realtimeSinceStartup - value2 < 10f)
		{
			return val;
		}
		Choice choice = null;
		if (_choices != null)
		{
			foreach (Choice choice2 in _choices)
			{
				if (choice2.Name == name)
				{
					choice = choice2;
					break;
				}
			}
		}
		if (choice == null)
		{
			Built[name] = null;
			return val;
		}
		if (choice.Game != null)
		{
			value = FindGame(choice.Game);
			if ((Object)(object)value == (Object)null)
			{
				Missed[name] = Time.realtimeSinceStartup;
				return val;
			}
			Built[name] = value;
			return value;
		}
		value = Build(choice, val);
		Built[name] = value;
		if (!((Object)(object)value != (Object)null))
		{
			return val;
		}
		return value;
	}

	private static string Plain(string name)
	{
		return (name ?? "").ToLowerInvariant().Replace(" ", "").Replace("_", "");
	}

	private static TMP_FontAsset FindGame(string[] keys)
	{
		TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (string name in keys)
		{
			string text = Plain(name);
			TMP_FontAsset val = null;
			TMP_FontAsset[] array2 = array;
			foreach (TMP_FontAsset val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)null) && !((Object)val2).name.StartsWith("BuminCombatFeel", StringComparison.Ordinal))
				{
					string text2 = Plain(((Object)val2).name);
					if (!text2.Contains("caudex") && text2.Contains(text) && (!(text == "norse") || !text2.Contains("bold")) && ((Object)(object)val == (Object)null || ((Object)val2).name.Length < ((Object)val).name.Length))
					{
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		if (!_listedGameFonts)
		{
			_listedGameFonts = true;
			List<string> list = new List<string>();
			TMP_FontAsset[] array3 = array;
			foreach (TMP_FontAsset val3 in array3)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					list.Add(((Object)val3).name);
				}
			}
			Plugin.Log.LogInfo((object)("A Valheim font was not found by name (yet). Loaded TextMeshPro fonts: " + string.Join(", ", list.ToArray())));
		}
		return null;
	}

	private static TMP_FontAsset Build(Choice choice, TMP_FontAsset fallback)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		try
		{
			Font val = new Font(choice.File);
			((Object)val).name = "BuminCombatFeel " + choice.Name;
			((Object)val).hideFlags = (HideFlags)32;
			Sources.Add(val);
			TMP_FontAsset val2 = TMP_FontAsset.CreateFontAsset(val, 90, 9, (GlyphRenderMode)4165, 1024, 1024, (AtlasPopulationMode)1, true);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)("TextMeshPro could not make a font from " + choice.File + "; the game's font is used."));
				return null;
			}
			((Object)val2).name = "BuminCombatFeel Glyphs " + choice.Name;
			((Object)val2).hideFlags = (HideFlags)32;
			if ((Object)(object)((TMP_Asset)val2).material != (Object)null && (Object)(object)((TMP_Asset)fallback).material != (Object)null && (Object)(object)((TMP_Asset)fallback).material.shader != (Object)null)
			{
				((TMP_Asset)val2).material.shader = ((TMP_Asset)fallback).material.shader;
			}
			val2.fallbackFontAssetTable = new List<TMP_FontAsset> { fallback };
			Plugin.Log.LogInfo((object)("Font ready: " + choice.Name + " (" + choice.File + ")."));
			return val2;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Font " + choice.Name + " failed (" + ex.GetType().Name + ": " + ex.Message + "); the game's font is used."));
			return null;
		}
	}

	internal static Material Material(TMP_FontAsset font, float outline, Color outlineColor, TextEffect effect, Color effectColor)
	{
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Expected O, but got Unknown
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)font == (Object)null || (Object)(object)((TMP_Asset)font).material == (Object)null)
		{
			return null;
		}
		float value = Plugin.ShadowOffset.Value;
		float value2 = Plugin.GlowSize.Value;
		string key = ((Object)font).GetInstanceID() + "|" + Mathf.RoundToInt(outline * 100f) + "|" + Key(outlineColor) + "|" + (int)effect + "|" + Key(effectColor) + "|" + Mathf.RoundToInt(value * 100f) + "|" + Mathf.RoundToInt(value2 * 100f);
		if (Materials.TryGetValue(key, out var value3) && (Object)(object)value3 != (Object)null)
		{
			return value3;
		}
		ShaderUtilities.GetShaderPropertyIDs();
		value3 = new Material(((TMP_Asset)font).material);
		((Object)value3).name = "BuminCombatFeel number";
		((Object)value3).hideFlags = (HideFlags)32;
		if (outline > 0.001f && value3.HasProperty(ShaderUtilities.ID_OutlineWidth))
		{
			value3.EnableKeyword("OUTLINE_ON");
			value3.SetFloat(ShaderUtilities.ID_OutlineWidth, outline);
			SetColor(value3, ShaderUtilities.ID_OutlineColor, outlineColor);
			SetFloat(value3, ShaderUtilities.ID_FaceDilate, outline * 0.4f);
		}
		else
		{
			value3.DisableKeyword("OUTLINE_ON");
			SetFloat(value3, ShaderUtilities.ID_OutlineWidth, 0f);
		}
		if (effect != TextEffect.None && value3.HasProperty(ShaderUtilities.ID_UnderlayColor))
		{
			value3.EnableKeyword("UNDERLAY_ON");
			value3.DisableKeyword("UNDERLAY_INNER");
			SetColor(value3, ShaderUtilities.ID_UnderlayColor, effectColor);
			if (effect == TextEffect.Shadow)
			{
				SetFloat(value3, ShaderUtilities.ID_UnderlayOffsetX, value * 0.5f);
				SetFloat(value3, ShaderUtilities.ID_UnderlayOffsetY, (0f - value) * 0.9f);
				SetFloat(value3, ShaderUtilities.ID_UnderlayDilate, Mathf.Max(0.1f, outline));
				SetFloat(value3, ShaderUtilities.ID_UnderlaySoftness, 0.35f);
			}
			else
			{
				SetFloat(value3, ShaderUtilities.ID_UnderlayOffsetX, 0f);
				SetFloat(value3, ShaderUtilities.ID_UnderlayOffsetY, 0f);
				SetFloat(value3, ShaderUtilities.ID_UnderlayDilate, value2 * 0.8f);
				SetFloat(value3, ShaderUtilities.ID_UnderlaySoftness, value2);
			}
		}
		else
		{
			value3.DisableKeyword("UNDERLAY_ON");
		}
		ShaderUtilities.UpdateShaderRatios(value3);
		Materials[key] = value3;
		return value3;
	}

	private static string Key(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Color32 val = Color32.op_Implicit(color);
		return val.r + "," + val.g + "," + val.b + "," + val.a;
	}

	private static void SetFloat(Material material, int id, float value)
	{
		if (material.HasProperty(id))
		{
			material.SetFloat(id, value);
		}
	}

	private static void SetColor(Material material, int id, Color value)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		if (material.HasProperty(id))
		{
			material.SetColor(id, value);
		}
	}
}
internal static class FontGuard
{
	private static FieldInfo _busy;

	private static bool _looked;

	internal static void Enter()
	{
		if (!_looked)
		{
			_looked = true;
			if (Chainloader.PluginInfos.ContainsKey("pathofbumin.fixes"))
			{
				Type type = AccessTools.TypeByName("PathOfBuminFixes.UiFonts");
				FieldInfo fieldInfo = ((type != null) ? AccessTools.Field(type, "_busy") : null);
				_busy = ((fieldInfo != null && fieldInfo.IsStatic && fieldInfo.FieldType == typeof(bool)) ? fieldInfo : null);
			}
		}
		if (_busy != null)
		{
			_busy.SetValue(null, true);
		}
	}

	internal static void Exit()
	{
		if (_busy != null)
		{
			_busy.SetValue(null, false);
		}
	}
}
internal static class NumberView
{
	private sealed class Item
	{
		public GameObject Root;

		public RectTransform Rect;

		public TextMeshProUGUI Main;

		public TextMeshProUGUI Sub;

		public RectTransform SubRect;

		public NumberSpec Spec;

		public float Born;

		public float Duration;

		public float PopStart;

		public Vector3 World;

		public Vector3 Offset;

		public bool Follows;

		public float Dir;

		public float Rand;

		public float Seed;

		public int Slot;

		public bool Placed;

		public float PushY;

		public Vector2 Screen;

		public float Height;

		public bool KillChecked;

		public TMP_FontAsset Font;

		public Material Material;

		public TMP_FontAsset SubFont;

		public Material SubMaterial;
	}

	private const float CritSlamTime = 0.09f;

	private const float KillWindow = 0.25f;

	private static GameObject _root;

	private static Canvas _canvas;

	private static readonly List<Item> Live = new List<Item>(64);

	private static readonly Stack<Item> Pool = new Stack<Item>(64);

	private static bool _dirty;

	private static bool _failed;

	internal static bool Failed => _failed;

	internal static Transform Root
	{
		get
		{
			if (!Ensure())
			{
				return null;
			}
			return _root.transform;
		}
	}

	internal static void MarkDirty()
	{
		_dirty = true;
	}

	internal static void Fail(Exception e)
	{
		if (!_failed)
		{
			_failed = true;
			Plugin.Log.LogError((object)("Damage numbers failed and are off until restart; the game's numbers are back: " + e));
			Shutdown();
		}
	}

	internal static void Shutdown()
	{
		Live.Clear();
		Pool.Clear();
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
		_root = null;
		_canvas = null;
	}

	private static bool Ensure()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		if (_failed)
		{
			return false;
		}
		if ((Object)(object)_root != (Object)null)
		{
			return true;
		}
		if ((Object)(object)NumberFonts.Base() == (Object)null)
		{
			return false;
		}
		_root = new GameObject("BuminCombatFeel Numbers");
		Object.DontDestroyOnLoad((Object)(object)_root);
		_canvas = _root.AddComponent<Canvas>();
		_canvas.renderMode = (RenderMode)0;
		_canvas.sortingOrder = 5;
		_canvas.pixelPerfect = false;
		return true;
	}

	internal static void Spawn(NumberSpec spec)
	{
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		if (spec == null || string.IsNullOrEmpty(spec.Text) || !Ensure())
		{
			return;
		}
		int value = Plugin.MaxNumbers.Value;
		while (Live.Count >= value && Live.Count > 0)
		{
			Release(Live[0]);
			Live.RemoveAt(0);
		}
		Item item = Acquire();
		float time = Time.time;
		item.Spec = spec;
		item.Born = time;
		item.PopStart = 0f;
		float num = ((spec.Crit || spec.Kill) ? Plugin.CritDuration.Value : 1f);
		if (spec.Role == NumberRole.Word || spec.Role == NumberRole.TooHard || spec.Role == NumberRole.Blocked)
		{
			num *= 0.9f;
		}
		item.Duration = Plugin.Duration.Value * num;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(Random.Range(-0.15f, 0.15f), 0f, Random.Range(-0.15f, 0.15f));
		item.World = spec.World + Vector3.up * Plugin.StartHeight.Value + val;
		item.Follows = (Object)(object)spec.Target != (Object)null;
		item.Offset = (item.Follows ? (item.World - ((Component)spec.Target).transform.position) : Vector3.zero);
		item.Dir = ((Random.value < 0.5f) ? (-1f) : 1f);
		item.Rand = Random.Range(0.5f, 1f);
		item.Seed = Random.Range(0f, 100f);
		item.Placed = false;
		item.PushY = 0f;
		item.KillChecked = spec.Role != NumberRole.Damage || spec.Kill;
		item.Slot = 0;
		if ((Object)(object)spec.Target != (Object)null)
		{
			foreach (Item item2 in Live)
			{
				if (item2.Spec != null && (Object)(object)item2.Spec.Target == (Object)(object)spec.Target && time - item2.Born < item2.Duration * 0.7f)
				{
					item.Slot++;
				}
			}
			item.Slot %= 6;
		}
		Style(item);
		FontGuard.Enter();
		try
		{
			item.Root.SetActive(true);
		}
		finally
		{
			FontGuard.Exit();
		}
		Live.Add(item);
	}

	private static float ScreenScale()
	{
		return Mathf.Max(0.3f, (float)Screen.height / 1080f);
	}

	private static bool Wordy(NumberRole role)
	{
		if (role != NumberRole.Word && role != NumberRole.TooHard && role != NumberRole.Blocked)
		{
			return role == NumberRole.Bonus;
		}
		return true;
	}

	private static void Style(Item item)
	{
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00cf: 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_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: 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_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		NumberSpec spec = item.Spec;
		string value = Plugin.Font.Value;
		if (spec.Crit && Plugin.CritFont.Value != "Same")
		{
			value = Plugin.CritFont.Value;
		}
		else if (Wordy(spec.Role) && Plugin.WordFont.Value != "Same")
		{
			value = Plugin.WordFont.Value;
		}
		TMP_FontAsset font = NumberFonts.Get(value);
		bool crit = spec.Crit;
		TextEffect textEffect = (crit ? Plugin.CritEffect.Value : Plugin.Effect.Value);
		float outline = (crit ? Plugin.CritOutlineWidth.Value : Plugin.OutlineWidth.Value);
		Color outlineColor = (crit ? Plugin.ColorCritOutline.Value : Plugin.ColorOutline.Value);
		Color effectColor = Plugin.ColorEffect.Value;
		if (crit && textEffect == TextEffect.Glow)
		{
			effectColor = Color.Lerp(spec.Bottom, new Color(1f, 0.35f, 0f), 0.35f);
			effectColor.a = 0.8f;
		}
		item.Font = font;
		item.Material = NumberFonts.Material(font, outline, outlineColor, textEffect, effectColor);
		float num = (item.Height = Plugin.Size.Value * spec.SizeShare);
		TextMeshProUGUI main = item.Main;
		ApplyFont(main, item.Font, item.Material);
		FontStyles val = (FontStyles)(Plugin.Bold.Value ? 1 : 0);
		if (crit && Plugin.CritItalic.Value)
		{
			val = (FontStyles)(val | 2);
		}
		((TMP_Text)main).fontStyle = val;
		((TMP_Text)main).characterSpacing = Plugin.Spacing.Value;
		((TMP_Text)main).fontSize = num * ScreenScale();
		((TMP_Text)main).text = spec.Text;
		if (!string.IsNullOrEmpty(spec.Sub))
		{
			item.SubFont = NumberFonts.Get(Plugin.Font.Value);
			item.SubMaterial = NumberFonts.Material(item.SubFont, Plugin.OutlineWidth.Value, Plugin.ColorOutline.Value, Plugin.Effect.Value, Plugin.ColorEffect.Value);
			ApplyFont(item.Sub, item.SubFont, item.SubMaterial);
			((TMP_Text)item.Sub).fontStyle = (FontStyles)(Plugin.Bold.Value ? 1 : 0);
			((TMP_Text)item.Sub).fontSize = Plugin.Size.Value * 0.5f * ScreenScale();
			((TMP_Text)item.Sub).text = spec.Sub;
			item.SubRect.anchoredPosition = new Vector2(0f, (0f - (num * 0.62f + Plugin.Size.Value * 0.3f)) * ScreenScale());
		}
		else
		{
			item.SubFont = null;
			item.SubMaterial = null;
			((TMP_Text)item.Sub).text = string.Empty;
		}
	}

	private static void ApplyFont(TextMeshProUGUI text, TMP_FontAsset font, Material material)
	{
		if ((Object)(object)font == (Object)null)
		{
			return;
		}
		FontGuard.Enter();
		try
		{
			if ((Object)(object)((TMP_Text)text).font != (Object)(object)font)
			{
				((TMP_Text)text).font = font;
			}
			if ((Object)(object)material != (Object)null && (Object)(object)((TMP_Text)text).fontSharedMaterial != (Object)(object)material)
			{
				((TMP_Text)text).fontSharedMaterial = material;
			}
		}
		finally
		{
			FontGuard.Exit();
		}
	}

	private static Item Acquire()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		while (Pool.Count > 0)
		{
			Item item = Pool.Pop();
			if ((Object)(object)item.Root != (Object)null)
			{
				return item;
			}
		}
		Item item2 = new Item();
		FontGuard.Enter();
		try
		{
			item2.Root = new GameObject("Number", new Type[1] { typeof(RectTransform) });
			item2.Root.SetActive(false);
			item2.Root.transform.SetParent(_root.transform, false);
			item2.Rect = (RectTransform)item2.Root.transform;
			item2.Rect.sizeDelta = new Vector2(800f, 200f);
			item2.Main = item2.Root.AddComponent<TextMeshProUGUI>();
			Setup(item2.Main);
			GameObject val = new GameObject("Parts", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(item2.Root.transform, false);
			item2.SubRect = (RectTransform)val.transform;
			item2.SubRect.sizeDelta = new Vector2(800f, 100f);
			item2.Sub = val.AddComponent<TextMeshProUGUI>();
			Setup(item2.Sub);
			return item2;
		}
		finally
		{
			FontGuard.Exit();
		}
	}

	private static void Setup(TextMeshProUGUI text)
	{
		((Graphic)text).raycastTarget = false;
		((TMP_Text)text).richText = true;
		((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
		((TMP_Text)text).overflowMode = (TextOverflowModes)0;
		((TMP_Text)text).alignment = (TextAlignmentOptions)514;
		((TMP_Text)text).text = string.Empty;
	}

	private static void Release(Item item)
	{
		item.Spec = null;
		if (!((Object)(object)item.Root == (Object)null))
		{
			FontGuard.Enter();
			try
			{
				item.Root.SetActive(false);
			}
			finally
			{
				FontGuard.Exit();
			}
			Pool.Push(item);
		}
	}

	private static float EaseOut(float t)
	{
		t = 1f - Mathf.Clamp01(t);
		return 1f - t * t * t;
	}

	private static float Smooth(float t)
	{
		t = Mathf.Clamp01(t);
		return t * t * (3f - 2f * t);
	}

	internal static void Layout()
	{
		if ((Object)(object)_root == (Object)null)
		{
			return;
		}
		if (!Plugin.Enabled.Value || !Plugin.NumbersOn.Value)
		{
			for (int num = Live.Count - 1; num >= 0; num--)
			{
				Release(Live[num]);
			}
			Live.Clear();
			return;
		}
		Camera mainCamera = Utils.GetMainCamera();
		bool flag = (Object)(object)mainCamera == (Object)null || Hud.IsUserHidden() || (Plugin.HideInMenus.Value && Plugin.InMenu());
		if (((Behaviour)_canvas).enabled == flag)
		{
			((Behaviour)_canvas).enabled = !flag;
		}
		if (_dirty)
		{
			_dirty = false;
			foreach (Item item2 in Live)
			{
				Style(item2);
			}
		}
		float time = Time.time;
		for (int num2 = Live.Count - 1; num2 >= 0; num2--)
		{
			Item item = Live[num2];
			if ((Object)(object)item.Root == (Object)null || item.Spec == null || time - item.Born >= item.Duration)
			{
				Release(item);
				Live.RemoveAt(num2);
			}
		}
		if (!flag && Live.Count != 0)
		{
			float scale = ScreenScale();
			float value = Plugin.MaxDistance.Value;
			for (int i = 0; i < Live.Count; i++)
			{
				Place(Live[i], mainCamera, time, scale, value, i);
			}
		}
	}

	private static void Place(Item item, Camera camera, float now, float scale, float maxDistance, int index)
	{
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_046f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		NumberSpec spec = item.Spec;
		float num = now - item.Born;
		float num2 = Mathf.Clamp01(num / item.Duration);
		Character target = spec.Target;
		if (item.Follows && Plugin.FollowTarget.Value && (Object)(object)target != (Object)null)
		{
			item.World = ((Component)target).transform.position + item.Offset;
		}
		if (!item.KillChecked)
		{
			if (num > 0.25f)
			{
				item.KillChecked = true;
			}
			else if ((Object)(object)target != (Object)null && !target.IsPlayer() && (target.IsDead() || target.GetHealth() <= 0.01f))
			{
				item.KillChecked = true;
				spec.Kill = true;
				Numbers.KillLook(spec);
				spec.Text = Numbers.Label(spec, spec.Value);
				item.PopStart = num;
				Style(item);
			}
		}
		if ((Object)(object)((TMP_Text)item.Main).font != (Object)(object)item.Font && (Object)(object)item.Font != (Object)null)
		{
			Style(item);
		}
		Vector3 val = Utils.WorldToScreenPointScaled(camera, item.World);
		if (val.z <= 0.05f || val.z > maxDistance + 5f)
		{
			Hide(item);
			return;
		}
		float num3 = Mathf.Lerp(1f, Plugin.FarSize.Value, Mathf.InverseLerp(4f, Mathf.Max(5f, maxDistance), val.z));
		Vector2 val2 = Motion(item, spec, num, num2);
		float num4 = num - item.PopStart;
		float num5 = 1f;
		float num6 = 0f;
		float num7 = 1f;
		CritMotion critMotion = (spec.Crit ? Plugin.CritMove.Value : CritMotion.SameAsNumbers);
		if (critMotion == CritMotion.Slam)
		{
			if (num4 < 0.09f)
			{
				float num8 = num4 / 0.09f;
				num5 = Mathf.Lerp(2.8f, 0.9f, num8 * num8);
				num7 = Mathf.Clamp01(num4 / 0.05f);
			}
			else
			{
				num5 = Mathf.Lerp(0.9f, 1f, Smooth((num4 - 0.09f) / 0.14f));
				float num9 = Plugin.CritShake.Value * (1f - Mathf.Clamp01((num4 - 0.09f) / 0.32f));
				if (num9 > 0.01f)
				{
					val2.x += Mathf.Sin(num4 * 95f + item.Seed) * num9;
					val2.y += Mathf.Cos(num4 * 81f + item.Seed * 1.3f) * num9 * 0.6f;
				}
			}
			num6 = Plugin.CritTilt.Value * item.Dir * (1f - Smooth(num4 / 0.3f));
		}
		else
		{
			float num10 = Plugin.Pop.Value * ((critMotion == CritMotion.Pop) ? 1.8f : 1f) * ((Plugin.Motion.Value == NumberMotion.Pop) ? 1.4f : 1f);
			if (spec.Kill)
			{
				num10 = Mathf.Max(num10, 1f);
			}
			if (num10 > 0.001f)
			{
				float num11 = 1f + 0.55f * num10;
				num5 = ((num4 < 0.07f) ? Mathf.Lerp(0.55f, num11, num4 / 0.07f) : Mathf.Lerp(num11, 1f, Smooth((num4 - 0.07f) / 0.15f)));
			}
			if (critMotion == CritMotion.Pop)
			{
				num6 = Plugin.CritTilt.Value * 0.5f * item.Dir * (1f - Smooth(num4 / 0.25f));
			}
			num7 = Mathf.Clamp01(num4 / 0.03f);
		}
		if (!item.Placed)
		{
			item.Placed = true;
			item.Screen = new Vector2(val.x, val.y);
			if (Plugin.AvoidOverlap.Value)
			{
				Separate(item, index, now, scale * num3);
			}
		}
		float value = Plugin.FadeShare.Value;
		float num12 = ((num2 < 1f - value) ? 1f : (1f - (num2 - (1f - value)) / value));
		num12 = Mathf.Clamp01(num12) * num7;
		RectTransform rect = item.Rect;
		((Transform)rect).position = new Vector3(val.x + val2.x * scale * num3, val.y + (val2.y + item.PushY) * scale * num3, 0f);
		((Transform)rect).localScale = Vector3.one * (num5 * num3);
		((Transform)rect).localRotation = ((Mathf.Abs(num6) > 0.01f) ? Quaternion.Euler(0f, 0f, num6) : Quaternion.identity);
		Paint(item, num12);
	}

	private static void Hide(Item item)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (((Transform)item.Rect).localScale.x != 0f)
		{
			((Transform)item.Rect).localScale = Vector3.zero;
		}
	}

	private static Vector2 Motion(Item item, NumberSpec spec, float age, float t)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		float value = Plugin.Rise.Value;
		float num = Plugin.Drift.Value * item.Rand * item.Dir;
		if (spec.Crit && Plugin.CritMove.Value != CritMotion.SameAsNumbers)
		{
			return new Vector2(num * 0.15f * t, value * 0.45f * EaseOut(t));
		}
		return (Vector2)(Plugin.Motion.Value switch
		{
			NumberMotion.Rise => new Vector2(0f, value * EaseOut(t)), 
			NumberMotion.Float => new Vector2(0f, value * 0.5f * t), 
			NumberMotion.Fountain => new Vector2(num * 1.8f * t, value * 1.4f * (2.6f * t - 2.6f * t * t)), 
			NumberMotion.Pop => new Vector2(0f, value * 0.25f * EaseOut(t)), 
			NumberMotion.Stack => new Vector2(0f, (float)item.Slot * item.Height * 1.05f + value * 0.35f * EaseOut(t)), 
			_ => new Vector2(num * t, value * (2.4f * t - 2f * t * t)), 
		});
	}

	private static void Separate(Item item, int index, float now, float scale)
	{
		float num = item.Height * 0.95f;
		float num2 = Mathf.Max(item.Height * 1.4f, item.Height * 0.55f * (float)item.Spec.Text.Length);
		for (int i = 0; i < 6; i++)
		{
			bool flag = false;
			for (int j = 0; j < Live.Count; j++)
			{
				Item item2 = Live[j];
				if (j != index && item2 != item && item2.Placed && item2.Spec != null && !(now - item2.Born > 0.35f))
				{
					float num3 = Mathf.Abs(item.Screen.x - item2.Screen.x) / scale;
					float num4 = Mathf.Abs(item.Screen.y + item.PushY * scale - (item2.Screen.y + item2.PushY * scale)) / scale;
					float num5 = Mathf.Max(item2.Height * 1.4f, item2.Height * 0.55f * (float)item2.Spec.Text.Length);
					if (num3 < (num2 + num5) * 0.5f && num4 < (num + item2.Height * 0.95f) * 0.5f)
					{
						item.PushY += (num + item2.Height * 0.95f) * 0.5f;
						flag = true;
					}
				}
			}
			if (!flag)
			{
				break;
			}
		}
	}

	private static void Paint(Item item, float alpha)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		NumberSpec spec = item.Spec;
		Color top = spec.Top;
		Color bottom = spec.Bottom;
		top.a *= alpha;
		bottom.a *= alpha;
		TextMeshProUGUI main = item.Main;
		if (spec.Crit || Plugin.Gradient.Value)
		{
			if (!((TMP_Text)main).enableVertexGradient)
			{
				((TMP_Text)main).enableVertexGradient = true;
			}
			((Graphic)main).color = new Color(1f, 1f, 1f, 1f);
			((TMP_Text)main).colorGradient = new VertexGradient(top, top, bottom, bottom);
		}
		else
		{
			if (((TMP_Text)main).enableVertexGradient)
			{
				((TMP_Text)main).enableVertexGradient = false;
			}
			((Graphic)main).color = top;
		}
		if ((Object)(object)item.SubFont != (Object)null)
		{
			((Graphic)item.Sub).color = new Color(1f, 1f, 1f, alpha);
			if ((Object)(object)((TMP_Text)item.Sub).font != (Object)(object)item.SubFont)
			{
				ApplyFont(item.Sub, item.SubFont, item.SubMaterial);
			}
		}
	}
}
internal enum NumberRole
{
	Damage,
	Taken,
	Heal,
	Blocked,
	Shield,
	Word,
	TooHard,
	Bonus
}
internal sealed class NumberSpec
{
	public NumberRole Role;

	public string Text;

	public string Sub;

	public Color Top;

	public Color Bottom;

	public bool Crit;

	public bool Heavy;

	public bool Kill;

	public float SizeShare = 1f;

	public Vector3 World;

	public Character Target;

	public float Value;

	public int Kind = -1;
}
internal static class Numbers
{
	private struct Raw
	{
		public int Code;

		public Vector3 Pos;

		public string Text;

		public bool MySelf;
	}

	private struct Decoded
	{
		public NumberRole Role;

		public int Kind;

		public int Grade;

		public bool Crit;

		public float Value;

		public string Text;

		public bool Skip;
	}

	private const int PovBase = 100;

	private const int PovStride = 16;

	private const int PovKinds = 7;

	private const int GradeNormal = 0;

	private const int GradeResist = 2;

	private const int GradeImmune = 4;

	private const int GradeWeak = 5;

	private static readonly float[] GradeFade = new float[6] { 0f, 0.35f, 0.6f, 0.82f, 1f, 0f };

	private static readonly List<Raw> Queue = new List<Raw>(32);

	private static readonly List<int> Group = new List<int>(8);

	private static bool[] _used = new bool[32];

	private static readonly StringBuilder Builder = new StringBuilder();

	private static bool _failed;

	private static float _gameMaxDistance = -1f;

	private static CultureInfo _turkish;

	internal static bool Active
	{
		get
		{
			if (!_failed && Plugin.Enabled.Value && Plugin.NumbersOn.Value)
			{
				return !NumberView.Failed;
			}
			return false;
		}
	}

	internal static void Apply(Harmony harmony)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		Plugin.PatchMethod(harmony, typeof(DamageText), "AddInworldText", typeof(Numbers), "BeforeText", null, 800);
		if (!Chainloader.PluginInfos.ContainsKey("DarthVladi.HPBarheim"))
		{
			return;
		}
		try
		{
			Type type = AccessTools.TypeByName("HPBarheim.Hud.DamageNumberManager");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Emit", (Type[])null, (Type[])null) : null);
			if (methodInfo == null)
			{
				Plugin.Log.LogWarning((object)"HP Barheim's damage number method was not found; its numbers may show next to these.");
				return;
			}
			HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(Numbers), "BeforeBarheimEmit", (Type[])null, (Type[])null));
			val.priority = 800;
			harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not hide HP Barheim's damage numbers: " + ex.Message));
		}
	}

	private static bool BeforeBarheimEmit()
	{
		if (Active)
		{
			return !Plugin.HideBarheim.Value;
		}
		return true;
	}

	private static bool BeforeText(TextType type, Vector3 pos, string text, bool mySelf)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected I4, but got Unknown
		//IL_0020: 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)
		if (!Active)
		{
			return true;
		}
		Queue.Add(new Raw
		{
			Code = (int)type,
			Pos = pos,
			Text = text,
			MySelf = mySelf
		});
		return false;
	}

	internal static void AddShield(Vector3 pos, float value)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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)
		if (Active && Plugin.ShowShield.Value && !(value < 0.05f))
		{
			Color value2 = Plugin.ColorShield.Value;
			NumberSpec numberSpec = new NumberSpec();
			numberSpec.Role = NumberRole.Shield;
			numberSpec.Text = Format(value);
			numberSpec.Top = value2;
			numberSpec.Bottom = Darker(value2);
			numberSpec.SizeShare = Plugin.TakenSize.Value;
			numberSpec.World = pos;
			numberSpec.Target = (Character)(object)Player.m_localPlayer;
			numberSpec.Value = value;
			NumberView.Spawn(numberSpec);
		}
	}

	internal static void Flush()
	{
		KeepGameDistance();
		if (Queue.Count == 0)
		{
			return;
		}
		if (!Active)
		{
			Queue.Clear();
			return;
		}
		try
		{
			Process();
		}
		catch (Exception ex)
		{
			_failed = true;
			Plugin.Log.LogError((object)("Damage numbers failed and are off until restart; the game's numbers are back: " + ex));
		}
		Queue.Clear();
	}

	private static void KeepGameDistance()
	{
		DamageText instance = DamageText.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			if (_gameMaxDistance < 0f)
			{
				_gameMaxDistance = instance.m_maxTextDistance;
			}
			instance.m_maxTextDistance = (Active ? Plugin.MaxDistance.Value : _gameMaxDistance);
		}
	}

	private static void Process()
	{
		int count = Queue.Count;
		if (_used.Length < count)
		{
			_used = new bool[count * 2];
		}
		for (int i = 0; i < count; i++)
		{
			_used[i] = false;
		}
		ElementParts value = Plugin.Parts.Value;
		for (int j = 0; j < count; j++)
		{
			if (_used[j])
			{
				continue;
			}
			_used[j] = true;
			Raw raw = Queue[j];
			Decoded d = Decode(raw);
			if (d.Skip)
			{
				continue;
			}
			if (d.Role != NumberRole.Damage && d.Role != NumberRole.Taken)
			{
				Other(raw, d);
				continue;
			}
			Group.Clear();
			Group.Add(j);
			if (value != ElementParts.Separate)
			{
				for (int k = j + 1; k < count; k++)
				{
					if (!_used[k] && SameHit(raw, Queue[k]) && Decode(Queue[k]).Role == d.Role)
					{
						Group.Add(k);
						_used[k] = true;
					}
				}
			}
			Damage(value);
		}
	}

	private static bool SameHit(Raw a, Raw b)
	{
		if (a.MySelf != b.MySelf)
		{
			return false;
		}
		float num = a.Pos.x - b.Pos.x;
		float num2 = a.Pos.z - b.Pos.z;
		float num3 = b.Pos.y - a.Pos.y;
		if (num * num + num2 * num2 < 0.0025f && num3 > -0.01f)
		{
			return num3 < 2.3f;
		}
		return false;
	}

	private static Decoded Decode(Raw raw)
	{
		Decoded result = new Decoded
		{
			Kind = 0,
			Grade = 0,
			Text = raw.Text
		};
		float value;
		bool flag = TryNumber(raw.Text, out value);
		result.Value = value;
		int code = raw.Code;
		if (code >= 100 && code < 212)
		{
			int num = (code - 100) % 16;
			result.Kind = (code - 100) / 16;
			result.Crit = (num & 8) != 0;
			result.Grade = Mathf.Clamp(num & 7, 0, GradeFade.Length - 1);
			result.Role = (raw.MySelf ? NumberRole.Taken : NumberRole.Damage);
			if (!flag)
			{
				result.Role = NumberRole.Word;
			}
		}
		else
		{
			switch (code)
			{
			case 0:
			case 1:
			case 2:
			case 3:
				result.Role = (raw.MySelf ? NumberRole.Taken : NumberRole.Damage);
				result.Grade = code switch
				{
					3 => 4, 
					2 => 5, 
					1 => 2, 
					_ => 0, 
				};
				if (!flag)
				{
					result.Role = NumberRole.Word;
				}
				break;
			case 4:
				result.Role = NumberRole.Heal;
				break;
			case 5:
				result.Role = NumberRole.TooHard;
				break;
			case 6:
				result.Role = NumberRole.Blocked;
				break;
			case 7:
				result.Role = ((!flag) ? NumberRole.Bonus : NumberRole.Damage);
				result.Crit = flag;
				break;
			default:
				result.Role = ((!flag) ? NumberRole.Word : (raw.MySelf ? NumberRole.Taken : NumberRole.Damage));
				break;
			}
		}
		switch (result.Role)
		{
		case NumberRole.Damage:
			result.Skip = !flag || (value < 0.05f && !Plugin.ShowZero.Value);
			break;
		case NumberRole.Taken:
			result.Skip = !Plugin.ShowTaken.Value || !flag || (value < 0.05f && !Plugin.ShowZero.Value);
			break;
		case NumberRole.Heal:
			result.Skip = !Plugin.ShowHeals.Value || !flag || value <= 0.05f;
			break;
		case NumberRole.Blocked:
			result.Skip = !Plugin.ShowBlocked.Value || !flag || value <= 0.05f;
			break;
		case NumberRole.Word:
		case NumberRole.Bonus:
			result.Skip = !Plugin.ShowWords.Value || string.IsNullOrEmpty(raw.Text);
			break;
		case NumberRole.TooHard:
			result.Skip = !Plugin.ShowTooHard.Value;
			break;
		}
		return result;
	}

	private static bool TryNumber(string text, out float value)
	{
		value = 0f;
		if (string.IsNullOrEmpty(text))
		{
			return false;
		}
		return float.TryParse(text.Trim().TrimStart(new char[1] { '+' }), NumberStyles.Float, CultureInfo.InvariantCulture, out value);
	}

	private static void Damage(ElementParts parts)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		Raw raw = Queue[Group[0]];
		bool mySelf = raw.MySelf;
		float num = 0f;
		bool flag = false;
		float num2 = -1f;
		int kind = 0;
		int grade = 0;
		Vector3 pos = raw.Pos;
		foreach (int item in Group)
		{
			Decoded decoded = Decode(Queue[item]);
			num += decoded.Value;
			flag |= decoded.Crit;
			if (decoded.Value > num2)
			{
				num2 = decoded.Value;
				kind = decoded.Kind;
				grade = decoded.Grade;
			}
			if (Queue[item].Pos.y < pos.y)
			{
				pos = Queue[item].Pos;
			}
		}
		NumberRole role = (mySelf ? NumberRole.Taken : NumberRole.Damage);
		Character target = (Character)(mySelf ? ((object)Player.m_localPlayer) : ((object)FindTarget(pos, notLocalPlayer: true)));
		NumberSpec numberSpec = new NumberSpec();
		numberSpec.Role = role;
		numberSpec.World = pos;
		numberSpec.Target = target;
		numberSpec.Value = num;
		numberSpec.Kind = kind;
		numberSpec.Crit = flag && !mySelf;
		NumberSpec numberSpec2 = numberSpec;
		if (mySelf)
		{
			numberSpec2.Bottom = Darker(numberSpec2.Top = ((num < 0.05f) ? Plugin.ColorResisted.Value : Plugin.ColorTaken.Value));
			numberSpec2.SizeShare = Plugin.TakenSize.Value;
			numberSpec2.Text = Format(num);
		}
		else
		{
			Paint(numberSpec2, kind, grade, num, target);
		}
		if (parts == ElementParts.TotalWithParts && Group.Count > 1)
		{
			Builder.Length = 0;
			foreach (int item2 in Group)
			{
				Decoded decoded2 = Decode(Queue[item2]);
				Color val = (mySelf ? Plugin.ColorTaken.Value : GradeColor(decoded2.Kind, decoded2.Grade));
				if (Builder.Length > 0)
				{
					Builder.Append("  ");
				}
				Builder.Append("<color=#").Append(ColorUtility.ToHtmlStringRGB(val)).Append('>')
					.Append(Format(decoded2.Value))
					.Append("</color>");
			}
			numberSpec2.Sub = Builder.ToString();
		}
		NumberView.Spawn(numberSpec2);
		AfterDamage(numberSpec2, num);
	}

	private static void AfterDamage(NumberSpec spec, float total)
	{
		if (spec.Role == NumberRole.Damage && !((Object)(object)spec.Target == (Object)null) && Impact.HitByMe(spec.Target))
		{
			Combo.AddDamage(total);
			if (spec.Crit)
			{
				Impact.OnCriticalNumber(spec.Target);
			}
		}
	}

	private static void Paint(NumberSpec spec, int kind, int grade, float value, Character target)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		Color val = (spec.Top = GradeColor(kind, grade));
		spec.Bottom = (Plugin.Gradient.Value ? Darker(val) : val);
		spec.SizeShare = ((grade == 5 && kind != 0) ? 1.12f : 1f);
		float num = (((Object)(object)target != (Object)null) ? target.GetMaxHealth() : 0f);
		spec.Heavy = !spec.Crit && Plugin.HeavyThreshold.Value > 0f && num > 0f && value / num >= Plugin.HeavyThreshold.Value;
		spec.Kill = (Object)(object)target != (Object)null && !target.IsPlayer() && (target.IsDead() || target.GetHealth() <= 0.01f);
		if (spec.Heavy)
		{
			if (kind == 0 && grade != 5)
			{
				spec.Top = Plugin.ColorHeavy.Value;
				spec.Bottom = Darker(spec.Top);
			}
			spec.SizeShare *= Plugin.HeavySize.Value;
		}
		if (spec.Crit)
		{
			CritLook(spec, kind);
			spec.SizeShare = Mathf.Max(spec.SizeShare, 1f) * Plugin.CritSize.Value;
		}
		if (spec.Kill)
		{
			KillLook(spec);
		}
		spec.Text = Label(spec, value);
	}

	internal static void CritLook(NumberSpec spec, int kind)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.CritElement.Value && kind > 0 && Plugin.ElementColors.Value)
		{
			Color val = ElementColor(kind);
			spec.Top = Color.Lerp(val, Color.white, 0.35f);
			spec.Bottom = Darker(val);
		}
		else
		{
			spec.Top = Plugin.CritTop.Value;
			spec.Bottom = Plugin.CritBottom.Value;
		}
	}

	internal static void KillLook(NumberSpec spec)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		if (!spec.Crit)
		{
			spec.Top = Plugin.ColorKill.Value;
			spec.Bottom = Darker(spec.Top);
		}
		spec.SizeShare = Mathf.Max(spec.SizeShare, Plugin.KillSize.Value);
	}

	internal static string Label(NumberSpec spec, float value)
	{
		string text = Format(value);
		if (spec.Crit)
		{
			text = Plugin.CritPrefix.Value + text + Plugin.CritSuffix.Value;
		}
		if (spec.Kill)
		{
			text += Plugin.KillSuffix.Value;
		}
		return text;
	}

	private static void Other(Raw raw, Decoded d)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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_0091: 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)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		NumberSpec numberSpec = new NumberSpec();
		numberSpec.Role = d.Role;
		numberSpec.World = raw.Pos;
		numberSpec.Value = d.Value;
		NumberSpec numberSpec2 = numberSpec;
		Color value;
		switch (d.Role)
		{
		case NumberRole.Heal:
			value = Plugin.ColorHeal.Value;
			numberSpec2.Text = "+" + Format(d.Value);
			numberSpec2.SizeShare = 0.9f;
			numberSpec2.Target = FindTarget(raw.Pos, notLocalPlayer: false);
			if ((Object)(object)numberSpec2.Target != (Object)null)
			{
				numberSpec2.World = numberSpec2.Target.GetTopPoint();
			}
			break;
		case NumberRole.Blocked:
			value = Plugin.ColorBlocked.Value;
			numberSpec2.Text = Localize("$msg_blocked") + ": " + Format(d.Value);
			numberSpec2.SizeShare = Plugin.WordSize.Value;
			numberSpec2.Target = FindTarget(raw.Pos, notLocalPlayer: false);
			break;
		case NumberRole.TooHard:
			value = Plugin.ColorTooHard.Value;
			numberSpec2.Text = Word(Localize("$msg_toohard"));
			numberSpec2.SizeShare = Plugin.WordSize.Value;
			break;
		case NumberRole.Bonus:
			value = Plugin.CritTop.Value;
			numberSpec2.Text = Word(Localize(raw.Text));
			numberSpec2.SizeShare = Plugin.WordSize.Value * 1.3f;
			numberSpec2.Target = FindTarget(raw.Pos, !raw.MySelf);
			break;
		default:
			value = Plugin.ColorWord.Value;
			numberSpec2.Text = Word(Localize(raw.Text));
			numberSpec2.SizeShare = Plugin.WordSize.Value;
			numberSpec2.Target = FindTarget(raw.Pos, !raw.MySelf);
			break;
		}
		numberSpec2.Top = value;
		numberSpec2.Bottom = (Plugin.Gradient.Value ? Darker(value) : value);
		NumberView.Spawn(numberSpec2);
	}

	private static string Localize(string text)
	{
		Localization instance = Localization.instance;
		if (instance == null)
		{
			return text;
		}
		return instance.Localize(text);
	}

	private static string Word(string text)
	{
		if (!Plugin.WordsUpper.Value || string.IsNullOrEmpty(text))
		{
			return text;
		}
		Localization instance = Localization.instance;
		if (instance != null && instance.GetSelectedLanguage() == "Turkish")
		{
			if (_turkish == null)
			{
				_turkish = new CultureInfo("tr-TR");
			}
			return text.ToUpper(_turkish);
		}
		return text.ToUpperInvariant();
	}

	internal static Color ElementColor(int kind)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		return (Color)(kind switch
		{
			1 => Plugin.ColorFire.Value, 
			2 => Plugin.ColorFrost.Value, 
			3 => Plugin.ColorLightning.