Decompiled source of Ward Cores v1.2.0

WardCores.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConditionalConfigSync;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.TextCore;
using WardCores.Core;
using WardCores.Effects;
using WardCores.Net;
using WardCores.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("WardCores")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("WardCores")]
[assembly: AssemblyTitle("WardCores")]
[assembly: AssemblyVersion("1.2.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WardCores
{
	internal sealed class ConfigurationManagerAttributes
	{
		public Action<ConfigEntryBase> CustomDrawer;

		public int? Order;

		public string Category;

		public string DispName;
	}
	internal static class CoreListDrawer
	{
		private sealed class Row
		{
			internal string Prefab;

			internal string Max;
		}

		private const int NoRow = -1;

		private const float PrefabMinWidth = 150f;

		private const float MaxFieldWidth = 60f;

		private const float RemoveButtonWidth = 24f;

		private const float NoteIndent = 16f;

		private const string ListedTwice = "listed twice";

		private const string NotFound = "not found in the game";

		private static readonly Color ProblemColor = new Color(1f, 0.5f, 0.5f);

		private static readonly Color UnknownColor = new Color(0.5f, 0.85f, 1f);

		private static readonly List<Row> Draft = new List<Row>();

		private static string _source;

		private static string _loadedText;

		private static int _openRow = -1;

		private static int _nextOpenRow = -1;

		internal static void Draw(ConfigEntryBase entry)
		{
			string text = (entry.BoxedValue as string) ?? "";
			if (text != _source)
			{
				Load(text);
			}
			int num = 0;
			int num2 = -1;
			bool canLookUp = Items.CanLookUp;
			HashSet<string> listed = Listed();
			_nextOpenRow = _openRow;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < Draft.Count; i++)
			{
				Row row = Draft[i];
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (!canLookUp)
				{
					row.Prefab = GUILayout.TextField(row.Prefab, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.MinWidth(150f),
						GUILayout.ExpandWidth(true)
					});
				}
				else if (ItemPicker.Button(row.Prefab.Trim(), i == _openRow, 150f))
				{
					_nextOpenRow = ((i == _openRow) ? (-1) : i);
				}
				row.Max = GUILayout.TextField(row.Max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				if (GUILayout.Button("x", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
				{
					num2 = i;
				}
				GUILayout.EndHorizontal();
				if (canLookUp && i == _openRow)
				{
					string text2 = ItemPicker.Panel(row.Prefab.Trim(), listed, 16f);
					if (text2 != null)
					{
						row.Prefab = text2;
						_nextOpenRow = -1;
					}
				}
				string text3 = Problem(i);
				if (text3 != null)
				{
					num++;
				}
				Note(text3, row.Prefab.Trim());
			}
			if (num2 != -1)
			{
				Draft.RemoveAt(num2);
				_openRow = AfterRemoval(_openRow, num2);
				_nextOpenRow = AfterRemoval(_nextOpenRow, num2);
			}
			Buttons(entry, text, num);
			GUILayout.EndVertical();
			if (_nextOpenRow != _openRow)
			{
				_openRow = _nextOpenRow;
				if (_openRow != -1)
				{
					ItemPicker.Opened();
				}
			}
		}

		private static int AfterRemoval(int row, int removed)
		{
			if (row != removed)
			{
				if (row <= removed)
				{
					return row;
				}
				return row - 1;
			}
			return -1;
		}

		private static HashSet<string> Listed()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			foreach (Row item in Draft)
			{
				hashSet.Add(item.Prefab.Trim());
			}
			return hashSet;
		}

		private static void Buttons(ConfigEntryBase entry, string value, int problems)
		{
			bool flag = DraftText() != _loadedText;
			bool enabled = GUI.enabled;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("+ Add core", Array.Empty<GUILayoutOption>()))
			{
				Draft.Add(new Row
				{
					Prefab = "",
					Max = ""
				});
				_nextOpenRow = Draft.Count - 1;
			}
			GUI.enabled = enabled && flag && problems == 0;
			if (GUILayout.Button("Apply", Array.Empty<GUILayoutOption>()))
			{
				entry.BoxedValue = CoreTable.Join(Entries());
				Load((entry.BoxedValue as string) ?? "");
			}
			GUI.enabled = enabled && flag;
			if (GUILayout.Button("Revert", Array.Empty<GUILayoutOption>()))
			{
				Load(value);
			}
			GUI.enabled = enabled;
			GUILayout.EndHorizontal();
		}

		private static void Load(string value)
		{
			Draft.Clear();
			foreach (CorePart item in CoreTable.Split(value))
			{
				Draft.Add(new Row
				{
					Prefab = item.Prefab,
					Max = (item.Number ?? "")
				});
			}
			_source = value;
			_loadedText = DraftText();
			_openRow = -1;
			_nextOpenRow = -1;
		}

		private static string Problem(int index)
		{
			Row row = Draft[index];
			string text = row.Prefab.Trim();
			float max;
			string text2 = CoreTable.Check(text, row.Max.Trim(), out max);
			if (text2 != null)
			{
				return text2;
			}
			for (int i = 0; i < index; i++)
			{
				if (Draft[i].Prefab.Trim() == text)
				{
					return "listed twice";
				}
			}
			return null;
		}

		private static void Note(string problem, string prefab)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Color contentColor = GUI.contentColor;
			string text = "";
			if (problem != null)
			{
				GUI.contentColor = ProblemColor;
				text = problem;
			}
			else if (Items.CanLookUp && !Items.IsKnown(prefab))
			{
				GUI.contentColor = UnknownColor;
				text = "not found in the game";
			}
			else if (Items.CanLookUp)
			{
				text = prefab;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Space(16f);
			GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUI.contentColor = contentColor;
		}

		private static IEnumerable<CoreEntry> Entries()
		{
			foreach (Row item in Draft)
			{
				CoreTable.Check(item.Prefab.Trim(), item.Max.Trim(), out var max);
				yield return new CoreEntry(item.Prefab.Trim(), max);
			}
		}

		private static string DraftText()
		{
			List<string> list = new List<string>();
			foreach (Row item in Draft)
			{
				list.Add(item.Prefab.Trim() + ":" + item.Max.Trim());
			}
			return string.Join(", ", list);
		}
	}
	internal static class ItemIcons
	{
		private const string Prefix = "wardcores.";

		private const string SpriteShader = "TextMeshPro/Sprite";

		private const string AssetVersion = "1.1.0";

		private const uint NoUnicode = 65534u;

		private static readonly Dictionary<string, TMP_SpriteAsset> Assets = new Dictionary<string, TMP_SpriteAsset>();

		private static FieldInfo _version;

		private static Shader _shader;

		private static bool _off;

		internal static void Register()
		{
			_version = typeof(TMP_Asset).GetField("m_Version", BindingFlags.Instance | BindingFlags.NonPublic);
			if (_version == null || _version.FieldType != typeof(string))
			{
				TurnOff("TMP_Asset.m_Version");
			}
			else
			{
				TMP_Text.OnSpriteAssetRequest += Request;
			}
		}

		private static bool HasShader()
		{
			if ((Object)(object)_shader == (Object)null && !_off)
			{
				_shader = Shader.Find("TextMeshPro/Sprite");
				if ((Object)(object)_shader == (Object)null)
				{
					TurnOff("the shader 'TextMeshPro/Sprite'");
				}
			}
			return (Object)(object)_shader != (Object)null;
		}

		private static void TurnOff(string missing)
		{
			_off = true;
			Plugin.Log.LogWarning((object)("TextMeshPro lacks " + missing + "; the hover shows cores without their icon"));
		}

		internal static string Tag(string prefab)
		{
			if (!((Object)(object)Asset(prefab) != (Object)null))
			{
				return "";
			}
			return "<sprite=\"wardcores." + prefab + "\" index=0> ";
		}

		private static TMP_SpriteAsset Request(int hashCode, string name)
		{
			if (name == null || !name.StartsWith("wardcores.", StringComparison.Ordinal))
			{
				return null;
			}
			return Asset(name.Substring("wardcores.".Length));
		}

		private static TMP_SpriteAsset Asset(string prefab)
		{
			if (_off || string.IsNullOrEmpty(prefab))
			{
				return null;
			}
			if (Assets.TryGetValue(prefab, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Sprite icon = Items.Icon(prefab);
			if (!Items.HasIconRect(icon) || !HasShader())
			{
				return null;
			}
			value = Build(prefab, icon);
			Assets[prefab] = value;
			return value;
		}

		private static TMP_SpriteAsset Build(string prefab, Sprite icon)
		{
			//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)
			//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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			Rect textureRect = icon.textureRect;
			TMP_SpriteAsset val = ScriptableObject.CreateInstance<TMP_SpriteAsset>();
			((Object)val).name = "wardcores." + prefab;
			((Object)val).hideFlags = (HideFlags)61;
			_version.SetValue(val, "1.1.0");
			val.spriteSheet = (Texture)(object)icon.texture;
			((TMP_Asset)val).material = new Material(_shader)
			{
				hideFlags = (HideFlags)61,
				mainTexture = (Texture)(object)icon.texture
			};
			TMP_SpriteGlyph val2 = new TMP_SpriteGlyph(0u, new GlyphMetrics(((Rect)(ref textureRect)).width, ((Rect)(ref textureRect)).height, 0f, ((Rect)(ref textureRect)).height, ((Rect)(ref textureRect)).width), new GlyphRect((int)((Rect)(ref textureRect)).x, (int)((Rect)(ref textureRect)).y, (int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height), 1f, 0, icon);
			val.spriteGlyphTable.Add(val2);
			val.spriteCharacterTable.Add(new TMP_SpriteCharacter(65534u, val, val2)
			{
				name = prefab
			});
			val.UpdateLookupTables();
			return val;
		}
	}
	internal static class ItemPicker
	{
		private sealed class Item
		{
			internal string Prefab;

			internal string Name;

			internal Sprite Icon;
		}

		private const float EntryHeight = 26f;

		private const int VisibleEntries = 8;

		private const float IconMargin = 3f;

		private const string SearchControl = "WardCores_ItemSearch";

		private const string Listed = "listed";

		private const string NoItem = "Pick an item";

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

		private static ObjectDB _catalogDb;

		private static int _catalogCount;

		private static string _catalogLanguage;

		private static string _search = "";

		private static Vector2 _scroll;

		private static bool _focus;

		private static GUIStyle _skinButton;

		private static GUIStyle _iconButton;

		internal static void Opened()
		{
			//IL_000a: 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)
			_search = "";
			_scroll = Vector2.zero;
			_focus = true;
		}

		internal static bool Button(string prefab, bool open, float minWidth)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_004e: 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_0054: 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)
			GUIContent val = new GUIContent(((prefab.Length > 0) ? Items.DisplayName(prefab) : "Pick an item") + (open ? "  ▴" : "  ▾"));
			Rect rect = GUILayoutUtility.GetRect(val, IconButton(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(minWidth),
				GUILayout.ExpandWidth(true)
			});
			bool result = GUI.Button(rect, val, IconButton());
			DrawIcon(Items.Icon(prefab), rect);
			return result;
		}

		internal static string Panel(string current, HashSet<string> listed, float indent)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			string text = _search.Trim();
			string result = null;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Space(indent);
			GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUI.SetNextControlName("WardCores_ItemSearch");
			_search = GUILayout.TextField(_search, Array.Empty<GUILayoutOption>());
			if (_focus && (int)Event.current.type == 7)
			{
				GUI.FocusControl("WardCores_ItemSearch");
				_focus = false;
			}
			_scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(208f) });
			bool flag = false;
			foreach (Item item in Offered())
			{
				if (Matches(item, text))
				{
					flag |= item.Prefab == text;
					bool flag2 = item.Prefab != current && listed.Contains(item.Prefab);
					bool enabled = GUI.enabled;
					GUI.enabled = enabled && !flag2;
					if (Entry(item, flag2))
					{
						result = item.Prefab;
					}
					GUI.enabled = enabled;
				}
			}
			if (text.Length > 0 && !flag && GUILayout.Button("Use '" + text + "'", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				result = text;
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			return result;
		}

		private static bool Entry(Item item, bool taken)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004d: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			GUIContent val = new GUIContent(item.Name + "   " + item.Prefab + (taken ? "   (listed)" : ""));
			Rect rect = GUILayoutUtility.GetRect(val, IconButton(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(26f),
				GUILayout.ExpandWidth(true)
			});
			bool result = GUI.Button(rect, val, IconButton());
			DrawIcon(item.Icon, rect);
			return result;
		}

		private static bool Matches(Item item, string typed)
		{
			if (typed.Length != 0 && item.Name.IndexOf(typed, StringComparison.OrdinalIgnoreCase) < 0)
			{
				return item.Prefab.IndexOf(typed, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private static List<Item> Offered()
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Invalid comparison between Unknown and I4
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Invalid comparison between Unknown and I4
			ObjectDB instance = ObjectDB.instance;
			string text = ((Localization.instance != null) ? Localization.instance.GetSelectedLanguage() : "");
			int num = (((Object)(object)instance != (Object)null) ? instance.m_items.Count : 0);
			if ((Object)(object)instance == (Object)(object)_catalogDb && num == _catalogCount && text == _catalogLanguage)
			{
				return Catalog;
			}
			_catalogDb = instance;
			_catalogCount = num;
			_catalogLanguage = text;
			Catalog.Clear();
			if ((Object)(object)instance == (Object)null)
			{
				return Catalog;
			}
			foreach (GameObject item in instance.m_items)
			{
				ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null);
				if (!((Object)(object)val == (Object)null))
				{
					SharedData shared = val.m_itemData.m_shared;
					if ((int)shared.m_itemType == 1 || (int)shared.m_itemType == 16)
					{
						string prefabName = Utils.GetPrefabName(item);
						Catalog.Add(new Item
						{
							Prefab = prefabName,
							Name = Items.DisplayName(prefabName),
							Icon = Items.Icon(prefabName)
						});
					}
				}
			}
			Catalog.Sort((Item a, Item b) => string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase));
			return Catalog;
		}

		private static void DrawIcon(Sprite icon, Rect rect)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0054: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7 && Items.HasIconRect(icon))
			{
				float num = Mathf.Min(((Rect)(ref rect)).height, 26f) - 6f;
				Rect val = new Rect(((Rect)(ref rect)).x + 3f, ((Rect)(ref rect)).y + (((Rect)(ref rect)).height - num) / 2f, num, num);
				Texture2D texture = icon.texture;
				Rect textureRect = icon.textureRect;
				GUI.DrawTextureWithTexCoords(val, (Texture)(object)texture, new Rect(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height));
			}
		}

		private static GUIStyle IconButton()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_006e: Expected O, but got Unknown
			if (_iconButton == null || _skinButton != GUI.skin.button)
			{
				_skinButton = GUI.skin.button;
				RectOffset padding = _skinButton.padding;
				_iconButton = new GUIStyle(_skinButton)
				{
					alignment = (TextAnchor)3,
					padding = new RectOffset(padding.left + 26, padding.right, padding.top, padding.bottom)
				};
			}
			return _iconButton;
		}
	}
	internal static class Lang
	{
		internal static string NotConfigured => Status("#FF6E6E", T("Not configured - no shield", "Nicht eingetragen - kein Schild"));

		internal static string InstallHint => Localization.instance.Localize("[<color=yellow><b>$KEY_HotbarUse</b></color>] $piece_useitem");

		internal static string NoAccess => T("No access to this ward", "Kein Zugriff");

		internal static string Chilled => T("Chilled", "Unterkühlt");

		internal static string Core(string core)
		{
			return T("Core: ", "Kern: ") + core;
		}

		internal static string Charge(float energy, float max)
		{
			return T("Charge: ", "Ladung: ") + Palette.Paint("#5AB4FF", Whole(energy) + " / " + Whole(max) + " - " + Percent(energy, max) + "%");
		}

		internal static string Ready(float holds)
		{
			return Status((holds >= 1f) ? "#7CDB7C" : "#FFA64D", T("Ready", "Bereit") + Protection(holds));
		}

		internal static string Charging(double seconds, float holds)
		{
			string text = Whole((float)Math.Ceiling(seconds)) + "s";
			return Status("#FF6E6E", T("Charging - " + text + " until ready", "Lädt - bereit in " + text) + Protection(holds));
		}

		internal static string NeedsFuel(string fuel, float holds)
		{
			return Status("#FF6E6E", T("Charging - needs " + fuel, "Lädt - braucht " + fuel) + Protection(holds));
		}

		internal static string NotCharging(float holds)
		{
			return Status("#FF6E6E", T("Not charging", "Lädt nicht") + Protection(holds));
		}

		internal static string Fuel(string fuel, int items, int capacity, double seconds)
		{
			return fuel + ": " + items + " / " + capacity + ((items > 0) ? (" - " + Duration(seconds)) : "");
		}

		internal static string FeedHint(string fuel)
		{
			string text = ((ZInput.IsNonClassicFunctionality() && ZInput.IsGamepadActive()) ? "$KEY_AltKeys + $KEY_Use" : "$KEY_AltPlace + $KEY_Use");
			return Localization.instance.Localize("[<color=yellow><b>" + text + "</b></color>] ") + T("Add " + fuel, fuel + " hinzufügen");
		}

		internal static string Adding(string fuelToken)
		{
			return Localization.instance.Localize("$msg_fireadding", new string[1] { fuelToken });
		}

		internal static string CantAddMore(string fuelToken)
		{
			return Localization.instance.Localize("$msg_cantaddmore", new string[1] { fuelToken });
		}

		internal static string OutOf(string fuelToken)
		{
			return "$msg_outof " + fuelToken;
		}

		internal static string WardFuel(double seconds, float percentPerSecond)
		{
			return T(WardName() + " Fuel", WardName() + "-Brennstoff") + ": <color=orange>" + Duration(seconds) + "</color> " + T("at", "mit") + " +" + percentPerSecond.ToString("0.##", CultureInfo.InvariantCulture) + " %/s";
		}

		internal static string WardPower(float max)
		{
			return T(WardName() + " Power", WardName() + "-Energie") + ": <color=orange>" + Whole(max) + "</color>";
		}

		private static string WardName()
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("guard_stone") : null);
			Piece val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Piece>() : null);
			if (!((Object)(object)val2 != (Object)null) || Localization.instance == null)
			{
				return "Ward";
			}
			return Localization.instance.Localize(val2.m_name);
		}

		internal static string AlreadyInstalled(string core)
		{
			return core + T(" is already installed", " ist bereits eingesetzt");
		}

		internal static string Installed(string core)
		{
			return core + T(" installed — charging", " eingesetzt — lädt auf");
		}

		private static string T(string en, string de)
		{
			if (Localization.instance == null || !(Localization.instance.GetSelectedLanguage() == "German"))
			{
				return en;
			}
			return de;
		}

		private static string Status(string color, string text)
		{
			return "Status: " + Palette.Paint(color, text);
		}

		private static string Protection(float holds)
		{
			return " - " + T("Protection ", "Schutz ") + Whole((float)Math.Floor((double)holds * 100.0)) + "%";
		}

		private static string Whole(float value)
		{
			return value.ToString("0", CultureInfo.InvariantCulture);
		}

		private static string Duration(double seconds)
		{
			long num = (long)Math.Ceiling(Math.Max(0.0, seconds));
			if (num < 60)
			{
				return num + "s";
			}
			if (num < 3600)
			{
				return num / 60 + "m " + num % 60 + "s";
			}
			return num / 3600 + "h " + num % 3600 / 60 + "m";
		}

		private static string Percent(float energy, float max)
		{
			if (!(max > 0f))
			{
				return "0";
			}
			return Whole((float)Math.Floor((double)energy * 100.0 / (double)max));
		}
	}
	internal static class Palette
	{
		internal const string Energy = "#5AB4FF";

		internal const string Full = "#7CDB7C";

		internal const string Bleeding = "#FFA64D";

		internal const string Off = "#FF6E6E";

		internal static string Tag(string color)
		{
			return "<color=" + color + ">";
		}

		internal static string Paint(string color, string text)
		{
			return Tag(color) + text + "</color>";
		}
	}
	[BepInPlugin("valheim.wardcores", "Ward Cores", "1.2.0")]
	[BepInDependency("_shudnal.ConditionalConfigSync", "1.0.10")]
	[BepInProcess("valheim.exe")]
	[BepInProcess("valheim_server.exe")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "valheim.wardcores";

		public const string Name = "Ward Cores";

		public const string Version = "1.2.0";

		private const string SyncGuid = "_shudnal.ConditionalConfigSync";

		private const string SyncMinimumVersion = "1.0.10";

		internal static ManualLogSource Log;

		private static bool _ready;

		internal static string Stamp()
		{
			return "[frame " + Time.frameCount + ", " + Time.time.ToString("0.000", CultureInfo.InvariantCulture) + " s] ";
		}

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Settings.Bind(((BaseUnityPlugin)this).Config);
			List<string> list = WardAccess.Resolve();
			if (list.Count > 0)
			{
				foreach (string item in list)
				{
					Log.LogError((object)("Not found in this Valheim version: " + item));
				}
				Log.LogError((object)"Ward Cores stays off, nothing is patched.");
				return;
			}
			Harmony val = new Harmony("valheim.wardcores");
			try
			{
				WardPatches.Apply(val);
				DamagePatch.Apply(val);
				TooltipPatch.Apply(val);
				NumbersPatch.Apply(val);
			}
			catch (Exception ex)
			{
				val.UnpatchSelf();
				Log.LogError((object)("Ward Cores stays off, patching failed: " + ex));
				return;
			}
			ItemIcons.Register();
			_ready = true;
			Log.LogInfo((object)"Ward Cores 1.2.0 ready");
		}

		private void Update()
		{
			if (_ready)
			{
				FrostAura.Update(Time.deltaTime);
				NumbersPatch.FlushPayments(Time.deltaTime);
			}
		}

		private void LateUpdate()
		{
			DamagePatch.FlushSplashes();
		}
	}
	internal static class Settings
	{
		private const string CoresSection = "Cores";

		private const string EnergySection = "Energy";

		private const string FuelSection = "Fuel";

		private const string ThunderSection = "Thunder";

		private const string FireSection = "Fire";

		private const string FrostSection = "Frost";

		private const string LiquidFrostHeading = "Frost · Liquid Frost";

		private const string LegacyThunderstoneSection = "Thunderstone";

		internal static ConfigEntry<string> CoreList;

		internal static ConfigEntry<string> BuiltIn;

		internal static ConfigEntry<float> RechargePercentPerSecond;

		internal static ConfigEntry<float> RechargeCooldownSeconds;

		internal static ConfigEntry<float> CooldownRechargeFactor;

		internal static ConfigEntry<float> ReactivateAtPercent;

		internal static ConfigEntry<float> BleedBelowPercent;

		internal static ConfigEntry<float> BleedMaxPercent;

		internal static ConfigEntry<float> DamageToEnergyFactor;

		internal static ConfigEntry<float> ToolDamageFactor;

		internal static ConfigEntry<string> FuelItem;

		internal static ConfigEntry<float> FuelRechargePercentPerSecond;

		internal static ConfigEntry<float> FuelSecondsPerItem;

		internal static ConfigEntry<int> FuelCapacity;

		internal static ConfigEntry<bool> ThunderstoneEnabled;

		internal static ConfigEntry<float> RetaliationDamageFactor;

		internal static ConfigEntry<bool> FullRetaliation;

		internal static ConfigEntry<bool> StaggerAttackers;

		internal static ConfigEntry<bool> MoltenEnabled;

		internal static ConfigEntry<float> MoltenRetaliationDamageFactor;

		internal static ConfigEntry<bool> MoltenFullRetaliation;

		internal static ConfigEntry<float> MoltenBurnSeconds;

		internal static ConfigEntry<int> MoltenMaxStacks;

		internal static ConfigEntry<bool> FrostcoreEnabled;

		internal static ConfigEntry<float> FrostSlowPercent;

		internal static ConfigEntry<float> FrostSlowStepPercent;

		internal static ConfigEntry<bool> LiquidFrostEnabled;

		internal static ConfigEntry<float> LiquidFrostDamagePercent;

		internal static ConfigEntry<float> LiquidFrostEnergyPerDamage;

		internal static ConfigEntry<bool> LogAbsorb;

		private static ConfigSync _sync;

		private static ConfigFile _config;

		private static int _order;

		private const float NotInFile = -1f;

		internal static CoreTable Cores { get; private set; } = CoreTable.Parse("");

		internal static string Fuel => FuelItem.Value.Trim();

		internal static bool FuelEnabled => Fuel.Length > 0;

		internal static RechargeRule Recharge => new RechargeRule(RechargePercentPerSecond.Value, FuelEnabled ? FuelRechargePercentPerSecond.Value : 0f, CooldownRechargeFactor.Value);

		internal static float FuelCapacitySeconds => (float)FuelCapacity.Value * FuelSecondsPerItem.Value;

		internal static void Bind(ConfigFile config)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			_config = config;
			_sync = new ConfigSync("valheim.wardcores")
			{
				DisplayName = "Ward Cores",
				CurrentVersion = "1.2.0",
				MinimumRequiredVersion = "1.2.0",
				ModRequired = true
			};
			CoreList = Server("Cores", "List", "SurtlingCore:600, Upgrader0Armor:800, Upgrader1Armor:1000, Thunderstone:1000, Upgrader2Armor:1200, FrostCore:1400, DragonTear:1600, Upgrader3Armor:1800, YagluthDrop:2000, Upgrader4Armor:2200, Wisp:2400, BlackCore:2600, Upgrader5Armor:2800, MoltenCore:3000, FaderEmber:3200, Upgrader6Armor:3400, FrozenFuel:3600, OrbFrostFire:3800, OrbThunderBlood:3800, Upgrader7Armor:4000", "Prefab:MaxEnergy, comma separated, e.g. DragonTear:1600. Names are case-sensitive, decimals use a dot; broken entries are skipped with a warning in the log. A ward whose core is removed from the list has no shield until a listed core is installed. Items from other mods work by their prefab name.", null, null, null, CoreListDrawer.Draw);
			BuiltIn = Server("Cores", "BuiltIn", "SurtlingCore", "Core every ward carries until another is installed. It must also be in List, or those wards have no shield. Never returned by a swap: it comes back through the ward's recipe.");
			RechargePercentPerSecond = Server("Energy", "RechargePercentPerSecond", 1f, "Percent of max energy a ward regains per second of world time, also while nobody is near and while players sleep. A change applies at once, also to recharge already under way. 0 = wards recharge only while fuel burns.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			RechargeCooldownSeconds = Server("Energy", "RechargeCooldownSeconds", 5f, "After absorbing a hit, a ward recharges only at CooldownRechargeFactor of its rate for this long; every further hit restarts it. 0 = no cooldown.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f));
			CooldownRechargeFactor = Server("Energy", "CooldownRechargeFactor", 0.25f, "Share of the normal recharge rate a ward keeps during the cooldown after a hit: 0 = it pauses, 0.5 = half speed, 1 = no slowdown.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f));
			ReactivateAtPercent = Server("Energy", "ReactivateAtPercent", 30f, "A drained ward switches back on at this percent of max energy. The same point decides when the hover says Ready, and when a ward switched on with E below it comes on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f));
			BleedBelowPercent = Server("Energy", "BleedBelowPercent", 30f, "Below this charge a ward lets part of its share of a hit through: none at this value, more the emptier it is. Wards at or above it take over what bleeds through. What no ward takes over reaches the piece. 0 turns bleeding off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			BleedMaxPercent = Server("Energy", "BleedMaxPercent", 50f, "The most of its share a weakened ward lets through, reached when it is empty (the bleed grows linearly up to it), so it still pays something for every hit and runs dry instead of fading forever. 0 = no bleed, 100 = no cap (a ward then never quite runs dry).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			DamageToEnergyFactor = Server("Energy", "DamageToEnergyFactor", 1f, "Energy a ward pays per point of damage it absorbs, counted on the reshaped hit (resistances apply, weaknesses don't, chop and pickaxe scaled by ToolDamageFactor). 1 = 1:1, 0.5 = half, 2 = double.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 100f));
			ToolDamageFactor = Server("Energy", "ToolDamageFactor", 1f, "Share of chop and pickaxe damage that counts in a hit on a protected piece: its wards pay for it, and only what bleeds through reaches the piece. 0 = none, 1 = full. Weaknesses never apply while protected.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f));
			FuelItem = Server("Fuel", "FuelItem", "Sap", "Item fed to wards with Shift+E to speed up their recharge (prefab ID). Empty turns feeding off.");
			FuelRechargePercentPerSecond = Server("Fuel", "FuelRechargePercentPerSecond", 1f, "Percent of max energy per second a ward recharges on top of RechargePercentPerSecond while fuel burns. The cooldown after a hit slows it like the rest of the rate.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			FuelSecondsPerItem = Server("Fuel", "FuelSecondsPerItem", 60f, "Seconds of recharging one fuel item lasts; it burns only while the ward recharges.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3600f));
			FuelCapacity = Server("Fuel", "FuelCapacity", 50, "Fuel items a ward can hold.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000));
			ThunderstoneEnabled = Server("Thunder", "ThunderstoneEnabled", value: true, "Whether wards running the Thunder Stone strike back with lightning. Whether it is a core at all, and its max energy, come from [Cores] List. Off: it works like any other core.");
			RetaliationDamageFactor = Server("Thunder", "RetaliationDamageFactor", 0.5f, "Share of the absorbed damage the lightning strike returns to the attacker, once per attack (FullRetaliation sets which wards' absorption counts): 0 = stagger only, 1 = all of it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f));
			FullRetaliation = Server("Thunder", "FullRetaliation", value: true, FullRetaliationText("strike", "Thunder Stone"));
			StaggerAttackers = Server("Thunder", "StaggerAttackers", value: true, "Whether the strike staggers the attacker. Creatures the game never staggers, like bosses, stay unstaggered.");
			MoltenEnabled = Server("Fire", "MoltenCoreEnabled", value: true, "Whether wards running the Molten Core burn every attacker they absorb. Whether it is a core at all, and its max energy, come from [Cores] List. Off: it works like any other core.");
			MoltenRetaliationDamageFactor = Server("Fire", "RetaliationDamageFactor", 0.5f, "Share of the absorbed damage that comes back as fire, once per attack, burning over a few seconds (FullRetaliation sets which wards' absorption counts): 0 = none, 1 = all of it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f));
			MoltenFullRetaliation = Server("Fire", "FullRetaliation", value: true, FullRetaliationText("burn", "Molten Core"));
			MoltenBurnSeconds = Server("Fire", "BurnSeconds", 8f, "How long each attack's burn lasts. Every attack adds its own stack, burning its fire evenly over this time, and the stacks burn side by side. Water makes them run out six times as fast.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f));
			MoltenMaxStacks = Server("Fire", "MaxStacks", 0, "The most burn stacks one attacker carries at once; an attack beyond it replaces the oldest stack. 0 = no limit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100));
			FrostcoreEnabled = Server("Frost", "FrostcoreEnabled", value: true, "Whether wards running the Frostcore chill hostile creatures, and players without access who have PvP on, inside their radius. Whether it is a core at all, and its max energy, come from [Cores] List. Off: it works like any other core.");
			FrostSlowPercent = Server("Frost", "SlowPercent", 60f, "The most a chill slows its target, in percent, before frost resistance. Frostcore and Liquid Frost alike.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			FrostSlowStepPercent = Server("Frost", "SlowStepPercent", 5f, "How much the chill grows each second inside the radius, and thaws each second outside, in percent, before frost resistance. Frostcore and Liquid Frost alike.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f));
			LiquidFrostEnabled = Server("Frost", "LiquidFrostEnabled", value: true, "Whether wards running the Liquid Frost chill like a Frostcore and also freeze their targets with frost damage each second, paid from their energy. Whether it is a core at all, and its max energy, come from [Cores] List. Off: it works like any other core.", null, "Frost · Liquid Frost");
			LiquidFrostDamagePercent = Server("Frost", "LiquidFrostDamagePercent", 1f, "Frost damage each second to a target inside a Liquid Frost ward, in percent of its max health, before frost resistance and armour.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), "Frost · Liquid Frost", "DamagePercent");
			LiquidFrostEnergyPerDamage = Server("Frost", "LiquidFrostEnergyPerDamage", 0.5f, "Energy the Liquid Frost wards pay per point of frost damage actually dealt, split evenly between them. It does not start the recharge cooldown.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), "Frost · Liquid Frost", "EnergyPerDamage");
			LogAbsorb = Entry("Debug", "LogAbsorb", value: false, "Log every absorbed hit (piece, vanilla and reshaped damage, wards, shares, what reaches the piece), every splash charge, every Thunder Stone strike, every Molten Core burn, every chill step, every Liquid Frost freeze and every feed, with frame and time.");
			MoveLegacyThunderstone();
			CoreList.SettingChanged += delegate
			{
				Rebuild();
			};
			Rebuild();
		}

		private static ConfigEntry<T> Server<T>(string section, string key, T value, string description, AcceptableValueBase range = null, string heading = null, string displayName = null, Action<ConfigEntryBase> drawer = null)
		{
			ConfigEntry<T> val = Entry(section, key, value, description, range, heading, displayName, drawer);
			((ConditionalConfigSync)_sync).AddConfigEntry<T>(val, (ConfigSyncMode)0);
			return val;
		}

		private static ConfigEntry<T> Entry<T>(string section, string key, T value, string description, AcceptableValueBase range = null, string heading = null, string displayName = null, Action<ConfigEntryBase> drawer = null)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				Order = _order--,
				Category = heading,
				DispName = displayName,
				CustomDrawer = drawer
			};
			return _config.Bind<T>(section, key, value, new ConfigDescription(description, range, new object[1] { configurationManagerAttributes }));
		}

		private static string FullRetaliationText(string payback, string core)
		{
			return "Whether the " + payback + " also counts the normal wards covering the hit, its share of them beside other striking cores, so sharing the hit doesn't weaken it. Off: only the " + core + " wards' own part counts. Damage that bleeds through to the piece never counts.";
		}

		internal static bool TryGetMax(string prefab, out float max)
		{
			return Cores.TryGetMax(string.IsNullOrEmpty(prefab) ? BuiltIn.Value : prefab, out max);
		}

		private static void MoveLegacyThunderstone()
		{
			if (File.Exists(_config.ConfigFilePath) && File.ReadAllText(_config.ConfigFilePath).Contains("[Thunderstone]"))
			{
				Move<bool>("Enabled", ThunderstoneEnabled);
				Move<float>("RetaliationDamageFactor", RetaliationDamageFactor);
				Move<bool>("FullRetaliation", FullRetaliation);
				Move<bool>("StaggerAttackers", StaggerAttackers);
				ConfigEntry<float> val = _config.Bind<float>("Thunderstone", "MaxEnergy", -1f, "");
				float value = val.Value;
				_config.Remove(((ConfigEntryBase)val).Definition);
				if (value > 0f && ThunderstoneEnabled.Value)
				{
					CoreList.Value = CoreTable.Append(CoreList.Value, "Thunderstone", value);
					Plugin.Log.LogInfo((object)("[Thunderstone] MaxEnergy " + value.ToString(CultureInfo.InvariantCulture) + " moved into [Cores] List"));
				}
				_config.Save();
				Plugin.Log.LogInfo((object)"[Thunderstone] settings moved into [Thunder]");
			}
		}

		private static void Move<T>(string key, ConfigEntry<T> target)
		{
			ConfigEntry<T> val = _config.Bind<T>("Thunderstone", key, target.Value, "");
			target.Value = val.Value;
			_config.Remove(((ConfigEntryBase)val).Definition);
		}

		private static void Rebuild()
		{
			Cores = CoreTable.Parse(CoreList.Value);
			foreach (string problem in Cores.Problems)
			{
				Plugin.Log.LogWarning((object)("[Cores] List: " + problem + " — skipped"));
			}
			Plugin.Log.LogInfo((object)(Cores.Entries.Count + " cores configured"));
		}
	}
}
namespace WardCores.Patches
{
	internal static class DamagePatch
	{
		private static readonly List<PrivateArea> Paying = new List<PrivateArea>();

		private static readonly List<float> Available = new List<float>();

		private static readonly List<float> Charge = new List<float>();

		private static readonly List<StrikeKind> Payback = new List<StrikeKind>();

		private static readonly float[] Returned = new float[3];

		private static readonly bool[] Strikes = new bool[3];

		private static readonly bool[] Full = new bool[3];

		private static readonly SplashBatch<ZDOID, PrivateArea> Batch = new SplashBatch<ZDOID, PrivateArea>();

		private static readonly List<SplashBatch<ZDOID, PrivateArea>.Splash> Closed = new List<SplashBatch<ZDOID, PrivateArea>.Splash>();

		private static ZDOID _ownerlessArea = ZDOID.None;

		internal static void Apply(Harmony harmony)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_003b: 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_005d: Expected O, but got Unknown
			//IL_005d: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			harmony.Patch((MethodBase)WardAccess.ApplyDamage, new HarmonyMethod(typeof(DamagePatch), "ApplyDamagePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaEffectHit, new HarmonyMethod(typeof(DamagePatch), "AreaEffectHitPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(DamagePatch), "AreaEffectHitFinalizer", (Type[])null), (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.PieceDamage, new HarmonyMethod(typeof(DamagePatch), "PieceDamagePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void AreaEffectHitPrefix(Aoe __instance, Character ___m_owner, ZNetView ___m_nview)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			_ownerlessArea = (((Object)(object)___m_owner == (Object)null && (Object)(object)___m_nview != (Object)null && ___m_nview.IsValid() && (Object)(object)((Component)___m_nview).gameObject == (Object)(object)((Component)__instance).gameObject) ? ___m_nview.GetZDO().m_uid : ZDOID.None);
		}

		private static void AreaEffectHitFinalizer()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			_ownerlessArea = ZDOID.None;
		}

		private static void PieceDamagePrefix(HitData hit)
		{
			//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)
			if (!((ZDOID)(ref _ownerlessArea)).IsNone() && hit != null && ((ZDOID)(ref hit.m_attacker)).IsNone())
			{
				hit.m_attacker = _ownerlessArea;
			}
		}

		private static bool ApplyDamagePrefix(WearNTear __instance, ref float damage, HitData hitData, ref bool __result)
		{
			//IL_001d: 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)
			if (hitData == null || damage <= 0f || !Protects(__instance, hitData))
			{
				return true;
			}
			float vanilla = damage;
			damage = Reshape(hitData, __instance.m_damages, damage);
			if (damage <= 0.001f)
			{
				NumbersPatch.ShowPiece(hitData, 0f);
				__result = true;
				return false;
			}
			float value = Settings.DamageToEnergyFactor.Value;
			float[] array = new float[Paying.Count];
			float num = WardMath.SplitWithBleed(damage * value, Available, Charge, Settings.BleedBelowPercent.Value, Settings.BleedMaxPercent.Value, array) / value;
			bool flag = !((ZDOID)(ref hitData.m_attacker)).IsNone();
			if (flag)
			{
				Full[1] = Settings.FullRetaliation.Value;
				Full[2] = Settings.MoltenFullRetaliation.Value;
				Retaliation.Returned(array, Payback, Full, Returned, Strikes);
				Batch.Add(hitData.m_attacker, Time.frameCount, Paying, array, Returned, Strikes);
			}
			for (int i = 0; i < Paying.Count; i++)
			{
				if (array[i] > 0f)
				{
					if (!flag)
					{
						Drain(Paying[i], array[i]);
					}
					WardAccess.Flash(Paying[i]);
				}
			}
			NumbersPatch.ShowPiece(hitData, num);
			if (Settings.LogAbsorb.Value)
			{
				Plugin.Log.LogInfo((object)Describe(__instance, vanilla, damage, num, array, flag));
			}
			if (num <= 0.001f)
			{
				__result = true;
				return false;
			}
			damage = num;
			return true;
		}

		internal static bool Protects(WearNTear piece, HitData hit)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			Paying.Clear();
			Available.Clear();
			Charge.Clear();
			Payback.Clear();
			Vector3 position = ((Component)piece).transform.position;
			Character attacker = hit.GetAttacker();
			Player val = (Player)(object)((attacker is Player) ? attacker : null);
			long num = (((Object)(object)val != (Object)null) ? val.GetPlayerID() : 0);
			long now = WardStore.Now();
			foreach (PrivateArea allArea in WardAccess.AllAreas)
			{
				if ((Object)(object)allArea == (Object)null || !WardStore.IsPlayerWard(allArea) || !WardAccess.IsEnabled(allArea) || !WardAccess.IsInside(allArea, position))
				{
					continue;
				}
				ZDO val2 = WardStore.Zdo(allArea);
				if (val2 == null)
				{
					continue;
				}
				if (num != 0L && WardStore.HasAccess(allArea, num))
				{
					Paying.Clear();
					return false;
				}
				if (!WardStore.IsDepleted(val2) && WardStore.TryGetMax(val2, out var max))
				{
					float num2 = WardStore.Energy(val2, max, now) - WardRpc.PendingFor(val2.m_uid);
					if (num2 > 0.001f)
					{
						Paying.Add(allArea);
						Available.Add(num2);
						Charge.Add(WardStore.ChargePercent(num2, max));
						Payback.Add(WardStore.PaybackOf(allArea));
					}
				}
			}
			return Paying.Count > 0;
		}

		private static float Reshape(HitData hit, DamageModifiers modifiers, float damage)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_0107: 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_0126: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			float value = Settings.ToolDamageFactor.Value;
			damage += Adjust(ref hit.m_damage.m_blunt, modifiers.m_blunt, 1f);
			damage += Adjust(ref hit.m_damage.m_slash, modifiers.m_slash, 1f);
			damage += Adjust(ref hit.m_damage.m_pierce, modifiers.m_pierce, 1f);
			damage += Adjust(ref hit.m_damage.m_chop, modifiers.m_chop, value);
			damage += Adjust(ref hit.m_damage.m_pickaxe, modifiers.m_pickaxe, value);
			damage += Adjust(ref hit.m_damage.m_fire, modifiers.m_fire, 1f);
			damage += Adjust(ref hit.m_damage.m_frost, modifiers.m_frost, 1f);
			damage += Adjust(ref hit.m_damage.m_lightning, modifiers.m_lightning, 1f);
			damage += Adjust(ref hit.m_damage.m_poison, modifiers.m_poison, 1f);
			damage += Adjust(ref hit.m_damage.m_spirit, modifiers.m_spirit, 1f);
			damage += Adjust(ref hit.m_damage.m_nonPlayer, modifiers.m_nonPlayer, 1f);
			return Mathf.Max(0f, damage);
		}

		private static float Adjust(ref float dealt, DamageModifier modifier, float scale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			float num = WardMath.Unweakened(dealt, WeaknessFactor(modifier)) * scale;
			float result = num - dealt;
			dealt = num;
			return result;
		}

		private static float WeaknessFactor(DamageModifier modifier)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(1f, Modifiers.Multiplier(modifier));
		}

		internal static void FlushSplashes()
		{
			//IL_00a8: 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)
			if (Batch.Open == 0)
			{
				return;
			}
			Batch.TakeClosed(Time.frameCount, Closed);
			foreach (SplashBatch<ZDOID, PrivateArea>.Splash item in Closed)
			{
				foreach (KeyValuePair<PrivateArea, float> item2 in item.Charges())
				{
					if ((Object)(object)item2.Key != (Object)null && item2.Value > 0f)
					{
						Drain(item2.Key, item2.Value);
					}
				}
				float value = Settings.DamageToEnergyFactor.Value;
				if (item.StrikesBack(StrikeKind.Lightning))
				{
					WardStrike.Strike(item.Attacker, Retaliation.StrikeDamage(item.Returned(StrikeKind.Lightning), value, Settings.RetaliationDamageFactor.Value));
				}
				if (item.StrikesBack(StrikeKind.Fire))
				{
					WardStrike.Burn(item.Attacker, Retaliation.StrikeDamage(item.Returned(StrikeKind.Fire), value, Settings.MoltenRetaliationDamageFactor.Value));
				}
				if (Settings.LogAbsorb.Value)
				{
					Plugin.Log.LogInfo((object)(Plugin.Stamp() + "Splash of " + item.Hits + " hit(s): charged " + Number(item.Sum / (float)item.Hits) + " (" + Number(item.Sum) + " ÷ " + item.Hits + ")"));
				}
			}
		}

		private static void Drain(PrivateArea ward, float amount)
		{
			WardRpc.SendDrain(ward, amount);
			NumbersPatch.ShowDrain(ward, amount);
		}

		private static string Describe(WearNTear piece, float vanilla, float damage, float left, float[] shares, bool splash)
		{
			StringBuilder stringBuilder = new StringBuilder(Plugin.Stamp());
			stringBuilder.Append("Absorbed ").Append(Number(damage - left)).Append(" of ")
				.Append(Number(damage));
			if (Mathf.Abs(vanilla - damage) > 0.001f)
			{
				stringBuilder.Append(" (vanilla ").Append(Number(vanilla)).Append(')');
			}
			stringBuilder.Append(" on ").Append(Utils.GetPrefabName(((Component)piece).gameObject)).Append(", wards:");
			for (int i = 0; i < Paying.Count; i++)
			{
				stringBuilder.Append(' ').Append(Utils.GetPrefabName(((Component)Paying[i]).gameObject)).Append('@')
					.Append(Number(Available[i]))
					.Append(" (")
					.Append(Number(Charge[i]))
					.Append("%) ")
					.Append(splash ? "share " : "pays ")
					.Append(Number(shares[i]));
			}
			return stringBuilder.Append(", reaches piece: ").Append(Number(left)).ToString();
		}

		private static string Number(float value)
		{
			return value.ToString("0.#", CultureInfo.InvariantCulture);
		}
	}
	internal static class NumbersPatch
	{
		private static readonly string DrainTag = Palette.Tag("#5AB4FF");

		private const string EnergySymbol = "⚡";

		private const float PaymentSeconds = 1f;

		private static HitData _protectedHit;

		private static readonly Dictionary<PrivateArea, float> Payments = new Dictionary<PrivateArea, float>();

		private static float _paymentTimer;

		internal static void Apply(Harmony harmony)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0038: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			harmony.Patch((MethodBase)WardAccess.RpcDamage, new HarmonyMethod(typeof(NumbersPatch), "RpcDamagePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(NumbersPatch), "RpcDamageFinalizer", (Type[])null), (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.DamageNumber, new HarmonyMethod(typeof(NumbersPatch), "DamageNumberPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AddWorldText, (HarmonyMethod)null, new HarmonyMethod(typeof(NumbersPatch), "AddWorldTextPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		internal static void ShowPiece(HitData hit, float reaches)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)DamageText.instance == (Object)null))
			{
				bool flag = reaches <= 0.001f;
				DamageText.instance.ShowText((TextType)(flag ? 3 : 0), hit.m_point, flag ? 0f : reaches, false);
			}
		}

		internal static void ShowDrain(PrivateArea ward, float amount)
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)DamageText.instance == (Object)null) && !((Object)(object)ward == (Object)null))
			{
				Vector3 val = ((Component)ward).transform.position + Vector3.up * Mathf.Max(1.5f, ward.m_hoverOffset);
				string text = amount.ToString("0.#", CultureInfo.InvariantCulture);
				DamageText.instance.ShowText((TextType)7, val, Palette.Paint("#5AB4FF", "⚡" + text), false);
			}
		}

		internal static void AddPayment(PrivateArea ward, float amount)
		{
			Payments.TryGetValue(ward, out var value);
			Payments[ward] = value + amount;
		}

		internal static void FlushPayments(float dt)
		{
			_paymentTimer += dt;
			if (_paymentTimer < 1f)
			{
				return;
			}
			_paymentTimer = 0f;
			foreach (KeyValuePair<PrivateArea, float> payment in Payments)
			{
				ShowDrain(payment.Key, payment.Value);
			}
			Payments.Clear();
		}

		private static void AddWorldTextPostfix(DamageText __instance)
		{
			Transform transform = ((Component)__instance).transform;
			if (transform.childCount != 0)
			{
				TMP_Text component = ((Component)transform.GetChild(transform.childCount - 1)).GetComponent<TMP_Text>();
				string text = (((Object)(object)component != (Object)null) ? component.text : null);
				if (text != null && text.StartsWith(DrainTag, StringComparison.Ordinal))
				{
					component.richText = true;
				}
			}
		}

		private static void RpcDamagePrefix(WearNTear __instance, HitData hit)
		{
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			_protectedHit = ((hit != null && (Object)(object)component != (Object)null && component.IsValid() && component.IsOwner() && DamagePatch.Protects(__instance, hit)) ? hit : null);
		}

		private static void RpcDamageFinalizer()
		{
			_protectedHit = null;
		}

		private static bool DamageNumberPrefix(Vector3 pos, float dmg)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (_protectedHit != null && !(dmg <= 0f))
			{
				return pos != _protectedHit.m_point;
			}
			return true;
		}
	}
	internal static class TooltipPatch
	{
		internal static void Apply(Harmony harmony)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			harmony.Patch((MethodBase)WardAccess.ItemTooltip, (HarmonyMethod)null, new HarmonyMethod(typeof(TooltipPatch), "TooltipPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void TooltipPostfix(ItemData item, bool appending, ref string __result)
		{
			if (!appending && item != null)
			{
				string text = Items.PrefabOf(item);
				if (text != null && Settings.Cores.TryGetMax(text, out var max))
				{
					__result = __result + "\n\n" + Lang.WardPower(max);
				}
				if (text != null && Settings.FuelEnabled && text == Settings.Fuel)
				{
					__result = __result + "\n\n" + Lang.WardFuel(Settings.FuelSecondsPerItem.Value, Settings.FuelRechargePercentPerSecond.Value);
				}
			}
		}
	}
	internal static class WardPatches
	{
		private const float FeedRepeatSeconds = 0.2f;

		private static float _lastFeed;

		internal static void Apply(Harmony harmony)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			harmony.Patch((MethodBase)WardAccess.AreaAwake, (HarmonyMethod)null, new HarmonyMethod(typeof(WardPatches), "AwakePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaUpdateStatus, (HarmonyMethod)null, new HarmonyMethod(typeof(WardPatches), "UpdateStatusPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaGetHoverText, (HarmonyMethod)null, new HarmonyMethod(typeof(WardPatches), "GetHoverTextPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaUseItem, new HarmonyMethod(typeof(WardPatches), "UseItemPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaInteract, new HarmonyMethod(typeof(WardPatches), "InteractPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaToggleEnabled, new HarmonyMethod(typeof(WardPatches), "ToggleEnabledPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.AreaTogglePermitted, new HarmonyMethod(typeof(WardPatches), "TogglePermittedPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)WardAccess.ObjectDbAwake, (HarmonyMethod)null, new HarmonyMethod(typeof(WardPatches), "ObjectDbAwakePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void AwakePostfix(PrivateArea __instance)
		{
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if (!WardStore.IsPlayerWard(__instance) || (Object)(object)component == (Object)null || !component.IsValid())
			{
				return;
			}
			WardRpc.Register(__instance, component);
			WearNTear component2 = ((Component)__instance).GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_onDestroyed = (Action)Delegate.Combine(component2.m_onDestroyed, (Action)delegate
				{
					DropContents(__instance);
				});
			}
			WardStore.Settle(__instance);
		}

		private static void UpdateStatusPostfix(PrivateArea __instance)
		{
			if (WardStore.IsPlayerWard(__instance))
			{
				WardStore.Settle(__instance);
			}
		}

		private static void GetHoverTextPostfix(PrivateArea __instance, ref string __result)
		{
			if (string.IsNullOrEmpty(__result) || !WardStore.IsPlayerWard(__instance))
			{
				return;
			}
			ZDO val = WardStore.Zdo(__instance);
			if (val == null)
			{
				return;
			}
			long now = WardStore.Now();
			string text = (Settings.FuelEnabled ? Items.DisplayName(Settings.Fuel) : null);
			string prefab = WardStore.CorePrefab(val);
			__result = __result + "\n" + Lang.Core(ItemIcons.Tag(prefab) + Items.DisplayName(prefab));
			float max;
			bool flag = WardStore.TryGetMax(val, out max);
			float energy = (flag ? WardStore.Energy(val, max, now) : 0f);
			if (flag)
			{
				__result = __result + "\n" + Lang.Charge(energy, max);
			}
			if (text != null)
			{
				float num = WardStore.FuelSeconds(val, now);
				__result = __result + "\n" + Lang.Fuel(text, WardStore.FuelItems(num, countBurning: true), Settings.FuelCapacity.Value, num);
			}
			__result = __result + "\n" + (flag ? Status(__instance, val, energy, max, now, text) : Lang.NotConfigured);
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && WardStore.HasAccess(__instance, localPlayer.GetPlayerID()))
			{
				__result = __result + "\n" + Lang.InstallHint;
				if (text != null)
				{
					__result = __result + "\n" + Lang.FeedHint(text);
				}
			}
		}

		private static string Status(PrivateArea area, ZDO zdo, float energy, float max, long now, string fuel)
		{
			float holds = WardStore.Holds(energy, max);
			if (WardStore.IsReady(area, energy, max))
			{
				return Lang.Ready(holds);
			}
			double num = WardStore.SecondsUntilReady(zdo, max, now);
			if (!double.IsInfinity(num))
			{
				return Lang.Charging(num, holds);
			}
			if (fuel == null)
			{
				return Lang.NotCharging(holds);
			}
			return Lang.NeedsFuel(fuel, holds);
		}

		private static bool UseItemPrefix(PrivateArea __instance, Humanoid user, ItemData item, ref bool __result)
		{
			string text = Items.PrefabOf(item);
			ZDO val = WardStore.Zdo(__instance);
			if (!WardStore.IsPlayerWard(__instance) || val == null || text == null || !Settings.Cores.TryGetMax(text, out var _))
			{
				return true;
			}
			__result = true;
			Player val2 = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			string core = Items.DisplayName(text);
			if (!WardStore.HasAccess(__instance, val2.GetPlayerID()))
			{
				((Character)user).Message((MessageType)2, Lang.NoAccess, 0, (Sprite)null, false);
				return false;
			}
			if (WardStore.CorePrefab(val) == text)
			{
				((Character)user).Message((MessageType)2, Lang.AlreadyInstalled(core), 0, (Sprite)null, false);
				return false;
			}
			string text2 = WardStore.InstalledItem(val);
			if (!user.GetInventory().RemoveOneItem(item))
			{
				return false;
			}
			if (text2.Length > 0)
			{
				Items.Give(user, text2);
			}
			WardRpc.SendInstall(__instance, text);
			((Character)user).Message((MessageType)2, Lang.Installed(core), 0, (Sprite)null, false);
			return false;
		}

		private static bool InteractPrefix(PrivateArea __instance, Humanoid human, bool hold, bool alt, ref bool __result)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			string text = ((alt && Settings.FuelEnabled && WardStore.IsPlayerWard(__instance)) ? Items.SharedName(Settings.Fuel) : null);
			if (text == null)
			{
				return true;
			}
			__result = false;
			Player val = (Player)(object)((human is Player) ? human : null);
			ZDO val2 = WardStore.Zdo(__instance);
			if ((Object)(object)val == (Object)null || val2 == null || (hold && Time.time - _lastFeed < 0.2f))
			{
				return false;
			}
			if (!WardStore.HasAccess(__instance, val.GetPlayerID()))
			{
				if (!hold)
				{
					((Character)human).Message((MessageType)2, Lang.NoAccess, 0, (Sprite)null, false);
				}
				return false;
			}
			Inventory inventory = human.GetInventory();
			if (!inventory.HaveItem(text, true))
			{
				((Character)human).Message((MessageType)2, Lang.OutOf(text), 0, (Sprite)null, false);
				return false;
			}
			if (WardStore.FuelItems(WardStore.FuelSeconds(val2, WardStore.Now()) + WardRpc.PendingFuelFor(val2.m_uid), countBurning: true) >= Settings.FuelCapacity.Value)
			{
				((Character)human).Message((MessageType)2, Lang.CantAddMore(text), 0, (Sprite)null, false);
				return false;
			}
			inventory.RemoveItem(text, 1, -1, true);
			WardRpc.SendFeed(__instance, 1);
			((Character)human).Message((MessageType)2, Lang.Adding(text), 0, (Sprite)null, false);
			_lastFeed = Time.time;
			__result = true;
			return false;
		}

		private static bool ToggleEnabledPrefix(PrivateArea __instance, long playerID)
		{
			Piece component = ((Component)__instance).GetComponent<Piece>();
			if (!WardStore.IsPlayerWard(__instance) || (Object)(object)component == (Object)null || component.GetCreator() != playerID)
			{
				return true;
			}
			return WardStore.ToggleRequested(__instance);
		}

		private static bool TogglePermittedPrefix(PrivateArea __instance)
		{
			ZDO val = WardStore.Zdo(__instance);
			if (WardStore.IsPlayerWard(__instance) && val != null)
			{
				return !WardStore.IsDepleted(val);
			}
			return true;
		}

		private static void DropContents(PrivateArea area)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_003c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)area).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner())
			{
				ZDO zDO = component.GetZDO();
				Vector3 position = ((Component)area).transform.position + Vector3.up;
				string text = WardStore.InstalledItem(zDO);
				if (text.Length > 0)
				{
					Items.DropAt(text, position);
				}
				int num = WardStore.FuelItems(WardStore.FuelSeconds(zDO, WardStore.Now()), countBurning: false);
				if (Settings.FuelEnabled && num > 0)
				{
					Items.DropAt(Settings.Fuel, position, num);
				}
			}
		}

		private static void ObjectDbAwakePostfix(ObjectDB __instance)
		{
			EffectRegistry.Register(__instance);
			if (__instance.m_items == null || __instance.m_items.Count == 0)
			{
				return;
			}
			foreach (CoreEntry entry in Settings.Cores.Entries)
			{
				if ((Object)(object)__instance.GetItemPrefab(entry.Prefab) == (Object)null)
				{
					Plugin.Log.LogWarning((object)("[Cores] List: the game has no item '" + entry.Prefab + "', nobody can install it"));
				}
			}
			if (!Settings.TryGetMax("", out var _))
			{
				Plugin.Log.LogWarning((object)("[Cores] BuiltIn '" + Settings.BuiltIn.Value + "' is not in the list: wards without an installed core have no shield"));
			}
			if (Settings.FuelEnabled && (Object)(object)__instance.GetItemPrefab(Settings.Fuel) == (Object)null)
			{
				Plugin.Log.LogWarning((object)("[Fuel] FuelItem: the game has no item '" + Settings.Fuel + "', nobody can feed wards"));
			}
		}
	}
}
namespace WardCores.Net
{
	internal static class WardRpc
	{
		private sealed class Ledger
		{
			private readonly Dictionary<ZDOID, List<KeyValuePair<float, float>>> _sent = new Dictionary<ZDOID, List<KeyValuePair<float, float>>>();

			internal void Add(ZDOID id, float amount)
			{
				//IL_0006: 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)
				if (!_sent.TryGetValue(id, out var value))
				{
					value = new List<KeyValuePair<float, float>>();
					_sent.Add(id, value);
				}
				value.Add(new KeyValuePair<float, float>(Time.time, amount));
			}

			internal float Sum(ZDOID id)
			{
				//IL_000c: 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)
				if (!_sent.TryGetValue(id, out var value))
				{
					return 0f;
				}
				float cutoff = Time.time - 1f;
				value.RemoveAll((KeyValuePair<float, float> entry) => entry.Key < cutoff);
				if (value.Count == 0)
				{
					_sent.Remove(id);
					return 0f;
				}
				float num = 0f;
				foreach (KeyValuePair<float, float> item in value)
				{
					num += item.Value;
				}
				return num;
			}
		}

		private const string DrainRpc = "wardcore_Drain";

		private const string PayRpc = "wardcore_Pay";

		private const string InstallRpc = "wardcore_Install";

		private const string FeedRpc = "wardcore_Feed";

		private const float PendingSeconds = 1f;

		private static readonly Ledger Drains = new Ledger();

		private static readonly Ledger Feeds = new Ledger();

		internal static void Register(PrivateArea area, ZNetView nview)
		{
			nview.Register<float>("wardcore_Drain", (Action<long, float>)delegate(long sender, float amount)
			{
				WardStore.Drain(area, amount);
			});
			nview.Register<float>("wardcore_Pay", (Action<long, float>)delegate(long sender, float amount)
			{
				Pay(area, amount);
			});
			nview.Register<string>("wardcore_Install", (Action<long, string>)delegate(long sender, string prefab)
			{
				WardStore.Install(area, prefab);
			});
			nview.Register<int>("wardcore_Feed", (Action<long, int>)delegate(long sender, int count)
			{
				WardStore.Feed(area, count);
			});
		}

		internal static void SendDrain(PrivateArea area, float amount)
		{
			SendTake(area, amount, "wardcore_Drain", WardStore.Drain);
		}

		internal static void SendPay(PrivateArea area, float amount)
		{
			SendTake(area, amount, "wardcore_Pay", Pay);
		}

		private static void Pay(PrivateArea area, float amount)
		{
			WardStore.Pay(area, amount);
			NumbersPatch.AddPayment(area, amount);
		}

		private static void SendTake(PrivateArea area, float amount, string rpc, Action<PrivateArea, float> take)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)area).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid())
			{
				if (component.IsOwner())
				{
					take(area, amount);
					return;
				}
				Drains.Add(component.GetZDO().m_uid, amount);
				component.InvokeRPC(rpc, new object[1] { amount });
			}
		}

		internal static void SendInstall(PrivateArea area, string prefab)
		{
			((Component)area).GetComponent<ZNetView>().InvokeRPC("wardcore_Install", new object[1] { prefab });
		}

		internal static void SendFeed(PrivateArea area, int count)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)area).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid())
			{
				if (component.IsOwner())
				{
					WardStore.Feed(area, count);
					return;
				}
				Feeds.Add(component.GetZDO().m_uid, (float)count * Settings.FuelSecondsPerItem.Value);
				component.InvokeRPC("wardcore_Feed", new object[1] { count });
			}
		}

		internal static float PendingFor(ZDOID id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Drains.Sum(id);
		}

		internal static float PendingFuelFor(ZDOID id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Feeds.Sum(id);
		}
	}
	internal static class WardStrike
	{
		private const string StrikeEffect = "fx_chainlightning_hit";

		private const float GuaranteedStagger = 100f;

		private static bool _effectMissingLogged;

		internal static void Strike(ZDOID attacker, float damage)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			Character val = Target(attacker);
			if (!((Object)(object)val == (Object)null))
			{
				bool flag = Settings.StaggerAttackers.Value && Staggerable(val);
				if (!(damage <= 0f) || flag)
				{
					HitData val2 = Hit(val);
					val2.m_staggerMultiplier = (flag ? 100f : 1f);
					val2.m_damage.m_lightning = damage;
					val.Damage(val2);
					PlayEffect(val2.m_point);
					Log("Strike", val, damage, "lightning");
				}
			}
		}

		internal static void Burn(ZDOID attacker, float fire)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Character val = ((fire > 0f) ? Target(attacker) : null);
			if (!((Object)(object)val == (Object)null))
			{
				val.GetSEMan().AddStatusEffect(MoltenBurn.Hash, true, 0, fire, (short)0);
				Log("Burn", val, fire, "fire");
			}
		}

		private static Character Target(ZDOID attacker)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (((ZDOID)(ref attacker)).IsNone() || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return null;
			}
			GameObject val = ZNetScene.instance.FindInstance(attacker);
			Character val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null);
			if (!((Object)(object)val2 != (Object)null) || val2.IsDead())
			{
				return null;
			}
			return val2;
		}

		private static HitData Hit(Character target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			return new HitData
			{
				m_point = target.GetCenterPoint(),
				m_dir = Vector3.down,
				m_hitType = (HitType)0
			};
		}

		private static void Log(string what, Character target, float damage, string type)
		{
			if (Settings.LogAbsorb.Value)
			{
				Plugin.Log.LogInfo((object)(Plugin.Stamp() + what + " " + Localization.instance.Localize(target.m_name) + " for " + damage.ToString("0.#", CultureInfo.InvariantCulture) + " " + type));
			}
		}

		private static bool Staggerable(Character target)
		{
			if (!target.IsPlayer())
			{
				return target.m_staggerDamageFactor > 0f;
			}
			return true;
		}

		private static void PlayEffect(Vector3 position)
		{
			//IL_001a: 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)
			GameObject prefab = ZNetScene.instance.GetPrefab("fx_chainlightning_hit");
			if ((Object)(object)prefab != (Object)null)
			{
				Object.Instantiate<GameObject>(prefab, position, Quaternion.identity);
			}
			else if (!_effectMissingLogged)
			{
				_effectMissingLogged = true;
				Plugin.Log.LogWarning((object)"[Thunder] The game has no effect 'fx_chainlightning_hit'; strikes land without it");
			}
		}
	}
}
namespace WardCores.Effects
{
	internal sealed class Chilled : StatusEffect
	{
		internal const string Name = "WardCores_Chilled";

		internal static readonly int Hash = StringExtensionMethods.GetStableHashCode("WardCores_Chilled");

		private const float StepSeconds = 1f;

		private static readonly List<PrivateArea> Freezing = new List<PrivateArea>();

		private float _level;

		private float _resistance;

		private float _timer;

		private bool _inside;

		private EffectSize _look;

		public override void Setup(Character character)
		{
			//IL_0015: 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)
			_look = new EffectSize();
			((StatusEffect)this).Setup(character);
			_resistance = Modifiers.Multiplier(character.GetDamageModifiers((WeakSpot)null).m_frost);
			_level = 0f;
			_timer = 0f;
			Step();
		}

		public override void UpdateStatusEffect(float dt)
		{
			((StatusEffect)this).UpdateStatusEffect(dt);
			_timer += dt;
			if (!(_timer < 1f))
			{
				_timer -= 1f;
				Step();
			}
		}

		public override bool IsDone()
		{
			if (_level <= 0f)
			{
				if (_inside)
				{
					return _resistance <= 0f;
				}
				return true;
			}
			return false;
		}

		public override void ModifySpeed(float baseSpeed, ref float speed, Character character, Vector3 dir)
		{
			speed = Mathf.Max(0f, speed - baseSpeed * _level / 100f);
		}

		private void Step()
		{
			_inside = FrostAura.Chills(base.m_character);
			float num = Frostcore.NextLevel(_level, _inside, Settings.FrostSlowStepPercent.Value, Settings.FrostSlowPercent.Value, _resistance);
			if (Settings.LogAbsorb.Value && !Mathf.Approximately(num, _level))
			{
				Plugin.Log.LogInfo((object)(Plugin.Stamp() + "Chill " + Localization.instance.Localize(base.m_character.m_name) + " to " + num.ToString("0.#", CultureInfo.InvariantCulture) + " %"));
			}
			_level = num;
			_look.Apply(base.m_startEffectInstances, Frostcore.LookScale(_level, Settings.FrostSlowPercent.Value));
			if (_inside)
			{
				Freeze();
			}
		}

		private void Freeze()
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			FrostAura.Freezing(base.m_character, Freezing);
			if (Freezing.Count == 0)
			{
				return;
			}
			HitData val = new HitData
			{
				m_point = base.m_character.GetCenterPoint(),
				m_hitType = (HitType)6
			};
			val.m_damage.m_frost = LiquidFrost.Damage(base.m_character.GetMaxHealth(), Settings.LiquidFrostDamagePercent.Value);
			Mitigation.Apply(base.m_character, val);
			if (val.m_damage.m_frost <= 0f)
			{
				return;
			}
			float health = base.m_character.GetHealth();
			base.m_character.ApplyDamage(val, true, false, (DamageModifier)0);
			float num = health - Mathf.Max(0f, base.m_character.GetHealth());
			if (num <= 0f)
			{
				return;
			}
			float amount = LiquidFrost.CostPerWard(num, Settings.LiquidFrostEnergyPerDamage.Value, Freezing.Count);
			foreach (PrivateArea item in Freezing)
			{
				WardRpc.SendPay(item, amount);
			}
			if (Settings.LogAbsorb.Value)
			{
				Plugin.Log.LogInfo((object)(Plugin.Stamp() + "Freeze " + Localization.instance.Localize(base.m_character.m_name) + " for " + num.ToString("0.##", CultureInfo.InvariantCulture) + " frost, " + Freezing.Count + " ward(s) pay " + amount.ToString("0.##", CultureInfo.InvariantCulture) + " each"));
			}
		}
	}
	internal static class EffectRegistry
	{
		internal static void Register(ObjectDB db)
		{
			if (db.m_StatusEffects == null)
			{
				return;
			}
			Chilled chilled = Add<Chilled>(db, "WardCores_Chilled", SEMan.s_statusEffectFrost);
			if ((Object)(object)chilled != (Object)null)
			{
				((StatusEffect)chilled).m_name = Lang.Chilled;
			}
			MoltenBurn moltenBurn = Add<MoltenBurn>(db, "WardCores_Burn", SEMan.s_statusEffectBurning);
			if ((Object)(object)moltenBurn != (Object)null)
			{
				StatusEffect statusEffect = db.GetStatusEffect(SEMan.s_statusEffectBurning);
				SE_Burning val = (SE_Burning)(object)((statusEffect is SE_Burning) ? statusEffect : null);
				if (val != null)
				{
					((StatusEffect)moltenBurn).m_name = ((StatusEffect)val).m_name;
					moltenBurn.TickEffect = val.m_tickEffect;
				}
			}
		}

		private static T Add<T>(ObjectDB db, string name, int lookAlike) where T : StatusEffect
		{
			if ((Object)(object)db.GetStatusEffect(StringExtensionMethods.GetStableHashCode(name)) != (Object)null)
			{
				return default(T);
			}
			T val = ScriptableObject.CreateInstance<T>();
			((Object)(object)val).name = name;
			StatusEffect statusEffect = db.GetStatusEffect(lookAlike);
			if ((Object)(object)statusEffect != (Object)null)
			{
				((StatusEffect)val).m_icon = statusEffect.m_icon;
				((StatusEffect)val).m_startEffects = statusEffect.m_startEffects;
			}
			db.m_StatusEffects.Add((StatusEffect)(object)val);
			return val;
		}
	}
	internal sealed class EffectSize
	{
		private Vector3[] _gameSizes;

		private float _shown = -1f;

		internal void Apply(GameObject[] effects, float factor)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (effects == null || Mathf.Approximately(factor, _shown))
			{
				return;
			}
			if (_gameSizes == null || _gameSizes.Length != effects.Length)
			{
				_gameSizes = (Vector3[])(object)new Vector3[effects.Length];
				for (int i = 0; i < effects.Length; i++)
				{
					_gameSizes[i] = (((Object)(object)effects[i] != (Object)null) ? effects[i].transform.localScale : Vector3.one);
				}
			}
			for (int j = 0; j < effects.Length; j++)
			{
				if ((Object)(object)effects[j] != (Object)null)
				{
					effects[j].transform.localScale = _gameSizes[j] * factor;
				}
			}
			_shown = factor;
		}
	}
	internal static class FrostAura
	{
		private const float CheckSeconds = 1f;

		private static float _timer;

		internal static void Update(float dt)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			_timer += dt;
			if (_timer < 1f || (!Settings.FrostcoreEnabled.Value && !Settings.LiquidFrostEnabled.Value))
			{
				return;
			}
			_timer = 0f;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!((Object)(object)allCharacter == (Object)null) && allCharacter.IsOwner() && !allCharacter.IsDead() && !allCharacter.GetSEMan().HaveStatusEffect(Chilled.Hash) && Modifiers.Multiplier(allCharacter.GetDamageModifiers((WeakSpot)null).m_frost) > 0f && Chills(allCharacter))
				{
					allCharacter.GetSEMan().AddStatusEffect(Chilled.Hash, false, 0, 0f, (short)(-1));
				}
			}
		}

		internal static bool Chills(Character character)
		{
			return Covering(character, IsChilling, null);
		}

		internal static void Freezing(Character character, List<PrivateArea> wards)
		{
			wards.Clear();
			Covering(character, IsFreezing, wards);
		}

		private static bool Covering(Character character, Func<PrivateArea, bool> filter, List<PrivateArea> wards)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || character.IsBoss())
			{
				return false;
			}
			Player val = (Player)(object)((character is Player) ? character : null);
			if (((Object)(object)val != (Object)null) ? (!((Character)val).IsPVPEnabled()) : (!IsHostile(character)))
			{
				return false;
			}
			Vector3 position = ((Component)character).transform.position;
			bool result = false;
			foreach (PrivateArea allArea in WardAccess.AllAreas)
			{
				if (!((Object)(object)allArea == (Object)null) && filter(allArea) && WardAccess.IsInside(allArea, position) && (!((Object)(object)val != (Object)null) || !WardStore.HasAccess(allArea, val.GetPlayerID())))
				{
					if (wards == null)
					{
						return true;
					}
					wards.Add(allArea);
					result = true;
				}
			}
			return result;
		}

		private static bool IsHostile(Character creature)
		{
			if (creature.IsTamed() || !(creature.GetBaseAI() is MonsterAI))
			{
				return false;
			}
			Player val = Player.m_localPlayer;
			if ((Object)(object)val == (Object)null)
			{
				List<Player> allPlayers = Player.GetAllPlayers();
				val = ((allPlayers.Count > 0) ? allPlayers[0] : null);
			}
			if ((Object)(object)val != (Object)null)
			{
				return BaseAI.IsEnemy(creature, (Character)(object)val);
			}
			return false;
		}

		private static bool IsChilling(PrivateArea area)
		{
			string text = ActiveCore(area);
			if (!(text == "FrostCore") || !Settings.FrostcoreEnabled.Value)
			{
				return FreezesWith(text);
			}
			return true;
		}

		private static bool IsFreezing(PrivateArea area)
		{
			return FreezesWith(ActiveCore(area));
		}

		private static bool FreezesWith(string core)
		{
			if (core == "FrozenFuel")
			{
				return Settings.LiquidFrostEnabled.Value;
			}
			return false;
		}

		private static string ActiveCore(PrivateArea area)
		{
			ZDO val = WardStore.Zdo(area);
			if (val == null || !WardStore.IsPlayerWard(area) || !WardAccess.IsEnabled(area) || WardStore.IsDepleted(val) || !WardStore.TryGetMax(val, out var _))
			{
				return null;
			}
			return WardStore.CorePrefab(val);
		}
	}
	internal static class Mitigation
	{
		internal static void Apply(Character target, HitData hit)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			DamageModifier val = default(DamageModifier);
			hit.ApplyResistance(target.GetDamageModifiers((WeakSpot)null), ref val);
			if (target.IsPlayer())
			{
				hit.ApplyArmor(target.GetBodyArmor());
			}
			else if (Game.m_worldLevel > 0 && (Object)(object)Game.instance != (Object)null)
			{
				hit.ApplyArmor((float)(Game.m_worldLevel * Game.instance.m_worldLevelEnemyBaseAC));
			}
		}
	}
	internal sealed class MoltenBurn : StatusEffect
	{
		internal const string Name = "WardCores_Burn";

		internal static readonly int Hash = StringExtensionMethods.GetStableHashCode("WardCores_Burn");

		private const float TickSeconds = 1f;

		internal EffectList TickEffect;

		private BurnStacks _stacks;

		private float _timer;

		private EffectSize _flames;

		public override void Setup(Character character)
		{
			_stacks = new BurnStacks();
			_flames = new EffectSize();
			((StatusEffect)this).Setup(character);
			_timer = 0f;
		}

		public unsafe override void SetLevel(int itemLevel, float skillLevel)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			((StatusEffect)this).SetLevel(itemLevel, skillLevel);
			float num = Resisted(skillLevel);
			_stacks.Add(num, Settings.MoltenBurnSeconds.Value, Settings.MoltenMaxStacks.Value);
			SizeFlames();
			string[] obj = new string[10]
			{
				Number(skillLevel),
				" fire → ",
				Number(num),
				" after resistance and armour (fire ",
				null,
				null,
				null,
				null,
				null,
				null
			};
			DamageModifiers damageModifiers = base.m_character.GetDamageModifiers((WeakSpot)null);
			obj[4] = ((object)(*(DamageModifier*)(&damageModifiers.m_fire))/*cast due to .constrained prefix*/).ToString();
			obj[5] = ", world level ";
			obj[6] = Game.m_worldLevel.ToString();
			obj[7] = "), ";
			obj[8] = _stacks.Count.ToString();
			obj[9] = " stack(s)";
			Log("stack on", string.Concat(obj));
		}

		private float Resisted(float fire)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			HitData val = new HitData();
			val.m_damage.m_fire = fire;
			Mitigation.Apply(base.m_character, val);
			return val.m_damage.m_fire;
		}

		private void SizeFlames()
		{
			_flames.Apply(base.m_startEffectInstances, MoltenCore.FlameScale(_stacks.Count));
		}

		public override void UpdateStatusEffect(float dt)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_009c: 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_00a4: Expected O, but got Unknown
			//IL_00e3: 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_0101: 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)
			((StatusEffect)this).UpdateStatusEffect(dt);
			_timer += dt;
			if (_timer < 1f)
			{
				return;
			}
			_timer -= 1f;
			bool flag = base.m_character.GetSEMan().HaveStatusEffect(SEMan.s_statusEffectWet);
			int count = _stacks.Count;
			float num = _stacks.Tick(1f, flag ? 6f : 1f);
			SizeFlames();
			if (!(num <= 0f))
			{
				HitData val = new HitData
				{
					m_point = base.m_character.GetCenterPoint(),
					m_hitType = (HitType)5
				};
				val.m_damage.m_fire = num;
				float health = base.m_character.GetHealth();
				base.m_character.ApplyDamage(val, true, false, (DamageModifier)0);
				EffectList tickEffect = TickEffect;
				if (tickEffect != null)
				{
					tickEffect.Create(((Component)base.m_character).transform.position, ((Component)base.m_character).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				}
				Log("tick on", Number(num) + " fire from " + count + " stack(s), health " + Number(health) + " → " + Number(base.m_character.GetHealth()));
			}
		}

		public override bool IsDone()
		{
			if (_stacks != null)
			{
				return _stacks.Count == 0;
			}
			return true;
		}

		private void Log(string what, string text)
		{
			if (Settings.LogAbsorb.Value)
			{
				Plugin.Log.LogInfo((object)(Plugin.Stamp() + "Burn " + what + " " + Localization.instance.Localize(base.m_character.m_name) + ": " + text));
			}
		}

		private static string Number(float value)
		{
			return value.ToString("0.##", CultureInfo.InvariantCulture);
		}
	}
}
namespace WardCores.Core
{
	internal sealed class BurnStacks
	{
		private sealed class Stack
		{
			internal float PerSecond;

			internal float SecondsLeft;
		}

		private readonly List<Stack> _stacks = new List<Stack>();

		internal int Count => _stacks.Count;

		internal void Add(float fire, float seconds, int maxStacks)
		{
			if (!(fire <= 0f) && !(seconds <= 0f))
			{
				while (maxStacks > 0 && _stacks.Count >= maxStacks)
				{
					_stacks.RemoveAt(0);
				}
				_stacks.Add(new Stack
				{
					PerSecond = fire / seconds,
					SecondsLeft = seconds
				});
			}
		}

		internal float Tick(float tickSeconds, float speed)
		{
			float num = 0f;
			for (int num2 = _stacks.Count - 1; num2 >= 0; num2--)
			{
				Stack stack = _stacks[num2];
				num += stack.PerSecond * Math.Min(tickSeconds, stack.SecondsLeft / speed);
				stack.SecondsLeft -= tickSeconds * speed;
				if (stack.SecondsLeft <= 0f)
				{
					_stacks.RemoveAt(num2);
				}
			}
			return num;
		}
	}
	internal sealed class CoreEntry
	{
		internal string Prefab { get; }

		internal float Max { get; }

		internal CoreEntry(string prefab, float max)
		{
			Prefab = prefab;
			Max = max;
		}
	}
	internal sealed class CorePart
	{
		internal string Text { get; }

		internal string Prefab { get; }

		internal string Number { get; }

		internal CorePart(string text, string prefab, string number)
		{
			Text = text;
			Prefab = prefab;
			Number = number;
		}
	}
	internal sealed class CoreTable
	{
		internal const string DefaultList = "SurtlingCore:600, Upgrader0Armor:800, Upgrader1Armor:1000, Thunderstone:1000, Upgrader2Armor:1200, FrostCore:1400, DragonTear:1600, Upgrader3Armor:1800, YagluthDrop:2000, Upgrader4Armor:2200, Wisp:2400, BlackCore:2600, Upgrader5Armor:2800, MoltenCore:3000, FaderEmber:3200, Upgrader6Armor:3400, FrozenFuel:3600, OrbFrostFire:3800, OrbThunderBlood:3800, Upgrader7Armor:4000";

		private readonly List<CoreEntry> _entries = new List<CoreEntry>();

		private readonly Dictionary<string, CoreEntry> _byPrefab = new Dictionary<string, CoreEntry>(StringComparer.Ordinal);

		private readonly List<string> _problems = new List<string>();

		internal IReadOnlyList<CoreEntry> Entries => _entries;

		internal IReadOnlyList<string> Problems => _problems;

		internal static CoreTable Parse(string list)
		{
			CoreTable coreTable = new CoreTable();
			foreach (CorePart item in Split(list))
			{
				coreTable.Add(item);
			}
			return coreTable;
		}

		internal static List<CorePart> Split(string list)
		{
			List<CorePart> list2 = new List<CorePart>();
			if (string.IsNullOrWhiteSpace(list))
			{
				return list2;
			}
			string[] array = list.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0)
				{
					int num = text.IndexOf(':');
					list2.Add((num < 0) ? new CorePart(text, text, null) : new CorePart(text, text.Substring(0, num).Trim(), text.Substring(num + 1).Trim()));
				}
			}
			return list2;
		}

		internal static string Check(string prefab, string number, out float max)
		{
			max = 0f;
			if (number == null)
			{
				return "expected Prefab:MaxEnergy";
			}
			if (string.IsNullOrEmpty(prefab) || HasWhitespace(prefab))
			{
				return "the prefab name is empty or contains spaces";
			}
			if (!float.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out max) || float.IsNaN(max) || float.IsInfinity(max) || max <= 0f)
			{
				max = 0f;
				return "max energy must be a number above 0";
			}
			return null;
		}

		internal static string Join(IEnumerable<CoreEntry> entries)
		{
			List<string> list = new List<string>();
			foreach (CoreEntry entry in entries)
			{
				list.Add(entry.Prefab + ":" + entry.Max.ToString(CultureInfo.InvariantCulture));
			}
			return string.Join(", ", list);
		}

		internal static string Append(string list, string prefab, float max)
		{
			foreach (CorePart item in Split(list))
			{
				if (item.Prefab == prefab)
				{
					return list;
				}
			}
			string text = (list ?? "").TrimEnd(Array.Empty<char>()).TrimEnd(new char[1] { ',' }).TrimEnd(Array.Empty<char>());
			string text2 = Join(new CoreEntry[1]
			{
				new CoreEntry(prefab, max)
			});
			if (text.Length != 0)
			{
				return text + ", " + text2;
			}
			return text2;
		}

		internal bool TryGetMax(string prefab, out float max)
		{
			if (prefab != null && _byPrefab.TryGetValue(prefab, out var value))
			{
				max = value.Max;
				return true;
			}
			max = 0f;
			return false;
		}

		private void Add(CorePart part)
		{
			float max;
			string text = Check(part.Prefab, part.Number, out max);
			if (text == null && _byPrefab.ContainsKey(part.Prefab))
			{
				text = part.Prefab + " is listed twice, the first entry is used";
			}
			if (text != null)
			{
				_problems.Add("'" + part.Text + "': " + text);
				return;
			}
			CoreEntry coreEntry = new CoreEntry(part.Prefab, max);
			_entries.Add(coreEntry);
			_byPrefab.Add(part.Prefab, coreEntry);
		}

		private static bool HasWhitespace(string text)
		{
			for (int i = 0; i < text.Length; i++)
			{
				if (char.IsWhiteSpace(text[i]))
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class Frostcore
	{
		internal const string Prefab = "FrostCore";

		internal const float DefaultSlowPercent = 60f;

		internal const float DefaultStepPercent = 5f;

		internal static float NextLevel(float level, bool inside, float stepPercent, float maxPercent, float resistance)
		{
			float num = stepPercent * resistance;
			if (!inside)
			{
				return Math.Max(level - num, 0f);
			}
			return Math.Min(level + num, Math.Min(maxPercent * resistance, 100f));
		}

		internal static float LookScale(float level, float maxPercent)
		{
			if (!(maxPercent > 0f))
			{
				return 0f;
			}
			return Math.Min(level / maxPercent, 1f);
		}
	}
	internal static class Items
	{
		internal static bool CanLookUp => (Object)(object)ObjectDB.instance != (Object)null;

		internal static string PrefabOf(ItemData item)
		{
			if (item == null)
			{
				return null;
			}
			GameObject val = item.m_dropPrefab;
			if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance