Decompiled source of BuffMeDaddy v1.1.0

plugins/BuffMeDaddy.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Jatify.AdminHammer;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Jatify.BuffMeDaddy
{
	internal static class Log
	{
		private static ManualLogSource _s;

		internal static void Bind(ManualLogSource s)
		{
			if (_s == null)
			{
				_s = s;
			}
		}

		internal static void Info(string m)
		{
			ManualLogSource s = _s;
			if (s != null)
			{
				s.LogInfo((object)m);
			}
		}

		internal static void Warn(string m)
		{
			ManualLogSource s = _s;
			if (s != null)
			{
				s.LogWarning((object)m);
			}
		}
	}
	[BepInPlugin("jatify.buffmedaddy", "BuffMeDaddy", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "jatify.buffmedaddy";

		internal static ConfigEntry<string> UnlimitedCfg;

		internal static ConfigEntry<string> ProfilesCfg;

		private float _next;

		private void Awake()
		{
			Log.Bind(((BaseUnityPlugin)this).Logger);
			AppDomain.CurrentDomain.AssemblyResolve += NewestAdminHammer;
			Setup();
		}

		private static Assembly NewestAdminHammer(object sender, ResolveEventArgs e)
		{
			if (new AssemblyName(e.Name).Name != "AdminHammer")
			{
				return null;
			}
			return (from a in AppDomain.CurrentDomain.GetAssemblies()
				where a.GetName().Name.StartsWith("AdminHammer-")
				orderby a.GetName().Name descending
				select a).FirstOrDefault();
		}

		private void OnDestroy()
		{
			AppDomain.CurrentDomain.AssemblyResolve -= NewestAdminHammer;
		}

		private void Setup()
		{
			//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_0058: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			UnlimitedCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Buffs", "Unlimited", "", "Status effects (prefab names, comma separated) whose time limit is removed. Set from the Buffs tab.");
			ProfilesCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Buffs", "Profiles", "", "Saved buff profiles (made from the Buffs tab): Name=effect:1,effect:0;... where 1 = no time limit.");
			AdminHammerApi.AddTab(new Tab
			{
				Name = "Buffs",
				Targets = true,
				Build = BuffTab.Build,
				Show = BuffTab.Show,
				Tick = BuffTab.Tick,
				Footer = BuffTab.Footer
			});
		}

		private void Update()
		{
			if (!(Time.unscaledTime < _next))
			{
				_next = Time.unscaledTime + 0.5f;
				Buffs.KeepUnlimited();
				Buffs.KeepOthers();
			}
		}
	}
	internal static class Buffs
	{
		internal sealed class Entry
		{
			public StatusEffect Se;

			public string Name;

			public string Category;

			public int Hash;
		}

		internal static readonly string[] Categories = new string[6] { "Meads", "Forsaken powers", "Food & rest", "Set & item effects", "Ailments", "Other" };

		private static readonly string[] AilmentWords = new string[16]
		{
			"wet", "burning", "poison", "frost", "lightning", "smoked", "tared", "encumbered", "cold", "freezing",
			"slimed", "spirit", "staggered", "hit", "puke", "fall"
		};

		private static List<Entry> _all;

		private static HashSet<string> _unl;

		internal static readonly Dictionary<ZDOID, HashSet<int>> Keep = new Dictionary<ZDOID, HashSet<int>>();

		private static readonly Dictionary<(ZDOID, int), float> _nextSend = new Dictionary<(ZDOID, int), float>();

		internal static List<Entry> All
		{
			get
			{
				if (_all != null && _all.Count > 0)
				{
					return _all;
				}
				_all = new List<Entry>();
				if ((Object)(object)ObjectDB.instance == (Object)null)
				{
					return _all;
				}
				foreach (StatusEffect statusEffect in ObjectDB.instance.m_StatusEffects)
				{
					if (!((Object)(object)statusEffect == (Object)null))
					{
						string text = (string.IsNullOrEmpty(statusEffect.m_name) ? "" : Localization.instance.Localize(statusEffect.m_name));
						string name = ((string.IsNullOrEmpty(text) || text.StartsWith("[")) ? Words(((Object)statusEffect).name) : text);
						_all.Add(new Entry
						{
							Se = statusEffect,
							Name = name,
							Hash = statusEffect.NameHash(),
							Category = Classify(statusEffect)
						});
					}
				}
				_all = _all.OrderBy((Entry e) => e.Name).ToList();
				return _all;
			}
		}

		private static HashSet<string> Unl => _unl ?? (_unl = new HashSet<string>(from s in Plugin.UnlimitedCfg.Value.Split(new char[1] { ',' })
			select s.Trim() into s
			where s.Length > 0
			select s));

		private static string Classify(StatusEffect se)
		{
			string n = ((Object)se).name.ToLowerInvariant();
			string text = (se.m_category ?? "").ToLowerInvariant();
			if (n.StartsWith("potion_") || text.Contains("potion") || text.Contains("mead"))
			{
				return "Meads";
			}
			if (n.StartsWith("gp_"))
			{
				return "Forsaken powers";
			}
			if (n.StartsWith("seteffect_") || n.Contains("equip") || (n.StartsWith("se_") && text.Contains("set")))
			{
				return "Set & item effects";
			}
			if (n.Contains("rested") || n.Contains("resting") || n.Contains("shelter") || n.Contains("campfire") || n.Contains("cozy") || n.Contains("food") || n.Contains("feast") || text.Contains("food"))
			{
				return "Food & rest";
			}
			if (AilmentWords.Any((string w) => n.Contains(w)))
			{
				return "Ailments";
			}
			return "Other";
		}

		private static string Words(string s)
		{
			return Regex.Replace(s.Replace('_', ' '), "(?<=[a-z])([A-Z])", " $1").Trim();
		}

		internal static bool IsUnlimited(Entry e)
		{
			return Unl.Contains(((Object)e.Se).name);
		}

		internal static void SetUnlimited(Entry e, bool on)
		{
			if (on)
			{
				Unl.Add(((Object)e.Se).name);
			}
			else
			{
				Unl.Remove(((Object)e.Se).name);
			}
			Plugin.UnlimitedCfg.Value = string.Join(",", Unl);
			StatusEffect val = Active(e);
			if (!on && (Object)(object)val != (Object)null)
			{
				val.m_ttl = ((e.Se.m_ttl > 0f) ? (val.GetDuration() + e.Se.m_ttl) : 0f);
			}
			KeepUnlimited();
		}

		internal static void KeepUnlimited()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || Unl.Count == 0)
			{
				return;
			}
			foreach (StatusEffect statusEffect in ((Character)localPlayer).GetSEMan().GetStatusEffects())
			{
				if ((Object)(object)statusEffect != (Object)null && statusEffect.m_ttl > 0f && Unl.Contains(((Object)statusEffect).name.Replace("(Clone)", "").Trim()))
				{
					statusEffect.m_ttl = 0f;
				}
			}
		}

		internal static List<PlayerInfo> Others()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			ZDOID me = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Character)Player.m_localPlayer).GetZDOID() : ZDOID.None);
			if (!((Object)(object)ZNet.instance == (Object)null))
			{
				return (from p in ZNet.instance.GetPlayerList()
					where !((ZDOID)(ref p.m_characterID)).IsNone() && p.m_characterID != me
					select p).ToList();
			}
			return new List<PlayerInfo>();
		}

		internal static void GiveTo(ZDOID who, Entry e)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				instance.InvokeRoutedRPC(((ZDOID)(ref who)).UserID, who, "RPC_AddStatusEffect", new object[5] { e.Hash, true, 0, 0f, -1 });
			}
		}

		internal static bool Kept(ZDOID who, Entry e)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Keep.TryGetValue(who, out var value))
			{
				return value.Contains(e.Hash);
			}
			return false;
		}

		internal static void SetKept(ZDOID who, Entry e, bool on)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!Keep.TryGetValue(who, out var value))
			{
				value = (Keep[who] = new HashSet<int>());
			}
			if (on)
			{
				value.Add(e.Hash);
				GiveTo(who, e);
			}
			else
			{
				value.Remove(e.Hash);
			}
			_nextSend[(who, e.Hash)] = Time.unscaledTime + Interval(e.Hash);
		}

		private static float Interval(int hash)
		{
			ObjectDB instance = ObjectDB.instance;
			StatusEffect val = ((instance != null) ? instance.GetStatusEffect(hash) : null);
			if (!((Object)(object)val == (Object)null) && !(val.m_ttl <= 0f))
			{
				return Mathf.Clamp(val.m_ttl * 0.5f, 2f, 60f);
			}
			return 60f;
		}

		internal static void KeepOthers()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (Keep.Count == 0 || (Object)(object)ZNet.instance == (Object)null)
			{
				return;
			}
			HashSet<ZDOID> hashSet = new HashSet<ZDOID>(from p in Others()
				select p.m_characterID);
			foreach (ZDOID item in Keep.Keys.ToList())
			{
				ZDOID current = item;
				if (!hashSet.Contains(current))
				{
					Keep.Remove(current);
					continue;
				}
				foreach (int item2 in Keep[current])
				{
					if (!_nextSend.TryGetValue((current, item2), out var value) || Time.unscaledTime >= value)
					{
						ZRoutedRpc instance = ZRoutedRpc.instance;
						if (instance != null)
						{
							instance.InvokeRoutedRPC(((ZDOID)(ref current)).UserID, current, "RPC_AddStatusEffect", new object[5] { item2, true, 0, 0f, -1 });
						}
						_nextSend[(current, item2)] = Time.unscaledTime + Interval(item2);
					}
				}
			}
		}

		internal static StatusEffect Active(Entry e)
		{
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer == null)
			{
				return null;
			}
			return ((Character)localPlayer).GetSEMan().GetStatusEffect(e.Hash);
		}

		internal static void Give(Entry e)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				((Character)localPlayer).GetSEMan().AddStatusEffect(e.Hash, true, 0, 0f, (short)(-1));
				KeepUnlimited();
				AdminHammerApi.Status(e.Name + ": on" + (IsUnlimited(e) ? ", no time limit" : ""));
			}
		}

		internal static void Remove(Entry e)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				((Character)localPlayer).GetSEMan().RemoveStatusEffect(e.Hash, false);
				AdminHammerApi.Status(e.Name + ": off");
			}
		}
	}
	internal static class BuffTab
	{
		private const float W = 1100f;

		private const float Body = 559f;

		private const float RailW = 232f;

		private const float InsW = 288f;

		private const float WorkW = 580f;

		private static RectTransform _area;

		private static RectTransform _rail;

		private static RectTransform _toolbar;

		private static RectTransform _grid;

		private static RectTransform _ins;

		private static TMP_InputField _search;

		private static string _cat = "Meads";

		private static string _query = "";

		private static Buffs.Entry _sel;

		private static bool _naming;

		private static float _refreshAt;

		private static string TargetName => AdminHammerApi.Target;

		private static bool Me => TargetName.Length == 0;

		private static ZDOID TargetId => (from p in Buffs.Others()
			where p.m_name == TargetName
			select p.m_characterID).DefaultIfEmpty(ZDOID.None).First();

		internal static void Build(RectTransform area)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			_area = area;
			Line(232f, 0f, 1f, 559f);
			_search = AdminHammerUi.Search((Transform)(object)area, "Search buffs", 12f, 14f, 208f, (Action<string>)delegate(string q)
			{
				_query = (q ?? "").Trim().ToLowerInvariant();
				PaintRail();
				PaintToolbar();
				PaintGrid();
			});
			_rail = AdminHammerUi.Scroll((Transform)(object)area, "Rail", 12f, 60f, 208f, 485f);
			_toolbar = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)area, "Toolbar"), 233f, 0f, 579f, 58f);
			Image obj = AdminHammerUi.Box((Transform)(object)area, "ToolbarLine", AdminHammerUi.LineSoft, AdminHammerUi.NoColor, 1);
			((Graphic)obj).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj).rectTransform, 233f, 58f, 579f, 1f);
			_grid = AdminHammerUi.Scroll((Transform)(object)area, "Grid", 233f, 59f, 579f, 499f);
			Line(812f, 0f, 1f, 559f);
			_ins = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)area, "Inspector"), 813f, 0f, 287f, 559f);
			AdminHammerApi.TargetChanged = (Action)Delegate.Combine(AdminHammerApi.TargetChanged, (Action)delegate
			{
				if ((Object)(object)_area != (Object)null && ((Component)_area).gameObject.activeInHierarchy)
				{
					Paint();
				}
			});
		}

		internal static void Show()
		{
			_sel = _sel ?? Buffs.All.FirstOrDefault((Buffs.Entry e) => e.Category == _cat);
			Paint();
		}

		internal static void Tick()
		{
			if (Time.unscaledTime > _refreshAt)
			{
				_refreshAt = Time.unscaledTime + 1f;
				PaintInspector();
			}
			if (Input.GetKeyDown((KeyCode)47) && (Object)(object)_search != (Object)null && !_search.isFocused && !_naming)
			{
				_search.ActivateInputField();
			}
		}

		internal static void Footer(RectTransform foot)
		{
			//IL_0007: 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)
			float num = 16f;
			float y = foot.sizeDelta.y;
			num = AdminHammerUi.Key((Transform)(object)foot, "Click", "select", num, y);
			num = AdminHammerUi.Key((Transform)(object)foot, "Right click", "turn on or off", num, y);
			TextMeshProUGUI val = AdminHammerUi.Text((Transform)(object)foot, "A profile gives all of its effects at once", "medium", 12.5f, AdminHammerUi.C("mute"), num, 0f, 300f, y, (TextAlignmentOptions)4097);
			num += AdminHammerUi.Width((TMP_Text)(object)val) + 18f;
			AdminHammerUi.Key((Transform)(object)foot, "/", "search", num, y);
		}

		private static void Paint()
		{
			PaintRail();
			PaintToolbar();
			PaintGrid();
			PaintInspector();
		}

		private static IEnumerable<Buffs.Entry> Visible()
		{
			if (_query.Length <= 0)
			{
				return Buffs.All.Where((Buffs.Entry e) => e.Category == _cat);
			}
			return Buffs.All.Where((Buffs.Entry e) => e.Name.ToLowerInvariant().Contains(_query) || ((Object)e.Se).name.ToLowerInvariant().Contains(_query));
		}

		private static void PaintRail()
		{
			//IL_0096: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_rail);
			float num = 208f;
			float num2 = 0f;
			AdminHammerUi.Section((Transform)(object)_rail, "Profiles", 2f, num2, num);
			num2 += 22f;
			foreach (Profiles.Profile item in Profiles.All)
			{
				Profiles.Profile prof = item;
				int num3 = item.Fx.Count(((string se, bool inf) f) => f.inf);
				Image obj = AdminHammerUi.Box((Transform)(object)_rail, "Profile", AdminHammerUi.C("raised"), AdminHammerUi.LineSoft, 8);
				AdminHammerUi.Place(((Graphic)obj).rectTransform, 0f, num2, num - 32f, 34f);
				((TMP_Text)AdminHammerUi.Text(((Component)obj).transform, item.Name, "medium", 13.5f, Color.white, 10f, 0f, num - 32f - 80f, 34f, (TextAlignmentOptions)4097)).overflowMode = (TextOverflowModes)1;
				AdminHammerUi.Text(((Component)obj).transform, string.Format("{0}{1}", item.Fx.Count, (num3 > 0) ? $" · {num3}∞" : ""), "mono", 11.5f, AdminHammerUi.C("mute"), num - 32f - 70f, 0f, 60f, 34f, (TextAlignmentOptions)4100);
				AdminHammerUi.On((Graphic)(object)obj, (Action)delegate
				{
					Apply(prof);
				}, (Action)null, (Action)null);
				Image obj2 = AdminHammerUi.Box((Transform)(object)_rail, "Delete", AdminHammerUi.NoColor, AdminHammerUi.NoColor, 8);
				AdminHammerUi.Place(((Graphic)obj2).rectTransform, num - 28f, num2, 28f, 34f);
				AdminHammerUi.Fill(((TMP_Text)AdminHammerUi.Text(((Component)obj2).transform, "×", "medium", 16f, AdminHammerUi.C("mute"), 0f, 0f, 28f, 34f, (TextAlignmentOptions)514)).rectTransform, 0f);
				AdminHammerUi.On((Graphic)(object)obj2, (Action)delegate
				{
					Profiles.Delete(prof);
					AdminHammerApi.Status("Deleted " + prof.Name);
					PaintRail();
				}, (Action)null, (Action)null);
				num2 += 38f;
			}
			if (_naming)
			{
				TMP_InputField name = AdminHammerUi.Search((Transform)(object)_rail, "Profile name", 0f, num2, num - 66f, (Action<string>)delegate
				{
				});
				name.characterLimit = 24;
				((UnityEvent<string>)(object)name.onSubmit).AddListener((UnityAction<string>)Save);
				name.ActivateInputField();
				AdminHammerUi.Primary((Transform)(object)_rail, "Save", num - 60f, num2, 60f, 34f, (Action)delegate
				{
					Save(name.text);
				}, true);
				num2 += 40f;
			}
			else
			{
				int num4 = (Me ? Buffs.All.Count((Buffs.Entry e) => (Object)(object)Buffs.Active(e) != (Object)null) : 0);
				Image val = AdminHammerUi.Box((Transform)(object)_rail, "SaveProfile", AdminHammerUi.NoColor, AdminHammerUi.C("line2"), 8);
				AdminHammerUi.Place(((Graphic)val).rectTransform, 0f, num2, num, 32f);
				AdminHammerUi.Fill(((TMP_Text)AdminHammerUi.Text(((Component)val).transform, (num4 > 0) ? $"Save current as profile ({num4})" : "Turn effects on to save a profile", "medium", 12.5f, (num4 > 0) ? AdminHammerUi.C("dim") : AdminHammerUi.C("mute"), 0f, 0f, num, 32f, (TextAlignmentOptions)514)).rectTransform, 0f);
				if (num4 > 0)
				{
					AdminHammerUi.On((Graphic)(object)val, (Action)delegate
					{
						_naming = true;
						PaintRail();
					}, (Action)null, (Action)null);
				}
				num2 += 38f;
			}
			Image obj3 = AdminHammerUi.Box((Transform)(object)_rail, "Sep", AdminHammerUi.LineSoft, AdminHammerUi.NoColor, 1);
			((Graphic)obj3).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj3).rectTransform, 0f, num2 + 4f, num, 1f);
			num2 += 14f;
			string[] categories = Buffs.Categories;
			foreach (string c in categories)
			{
				int num6 = Buffs.All.Count((Buffs.Entry e) => e.Category == c);
				if (num6 == 0)
				{
					continue;
				}
				string cc = c;
				AdminHammerUi.CatRow((Transform)(object)_rail, c, num6, _query.Length == 0 && c == _cat, num2, num, (Action)delegate
				{
					_cat = cc;
					_query = "";
					if ((Object)(object)_search != (Object)null)
					{
						_search.text = "";
					}
					_sel = Buffs.All.FirstOrDefault((Buffs.Entry e) => e.Category == cc);
					Paint();
				});
				num2 += 38f;
			}
			_rail.sizeDelta = new Vector2(0f, num2);
		}

		private static void Save(string name)
		{
			name = (name ?? "").Trim();
			if (name.Length != 0)
			{
				List<(string, bool)> list = (from e in Buffs.All
					where (Object)(object)Buffs.Active(e) != (Object)null
					select (name: ((Object)e.Se).name, Buffs.IsUnlimited(e))).ToList();
				Profiles.Save(name, list);
				_naming = false;
				AdminHammerApi.Status($"Saved {name}: {list.Count} effects");
				PaintRail();
			}
		}

		private static void Apply(Profiles.Profile p)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			List<(Buffs.Entry, bool)> list = (from f in p.Fx
				select (e: Buffs.All.FirstOrDefault((Buffs.Entry x) => ((Object)x.Se).name == f.se), inf: f.inf) into f
				where f.e != null
				select f).ToList();
			if (Me)
			{
				foreach (var (entry, flag) in list)
				{
					Buffs.SetUnlimited(entry, flag);
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer != null)
					{
						((Character)localPlayer).GetSEMan().AddStatusEffect(entry.Hash, true, 0, 0f, (short)(-1));
					}
					Buffs.KeepUnlimited();
				}
			}
			else
			{
				ZDOID targetId = TargetId;
				if (((ZDOID)(ref targetId)).IsNone())
				{
					AdminHammerApi.Status(TargetName + " is not online");
					return;
				}
				foreach (var (e, flag2) in list)
				{
					Buffs.GiveTo(targetId, e);
					if (flag2)
					{
						Buffs.SetKept(targetId, e, on: true);
					}
				}
			}
			AdminHammerApi.Status(Me ? $"{p.Name}: {list.Count} effects on" : $"Gave {p.Name} to {TargetName}: {list.Count} effects");
			Paint();
		}

		private static void PaintToolbar()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_toolbar);
			TextMeshProUGUI val = AdminHammerUi.Text((Transform)(object)_toolbar, (_query.Length > 0) ? "Results" : _cat, "bold", 15f, Color.white, 16f, 0f, 200f, 58f, (TextAlignmentOptions)4097);
			AdminHammerUi.Text((Transform)(object)_toolbar, Visible().Count().ToString(), "mono", 12f, AdminHammerUi.C("mute"), 16f + AdminHammerUi.Width((TMP_Text)(object)val) + 6f, 1f, 60f, 58f, (TextAlignmentOptions)4097);
			TextMeshProUGUI val2 = AdminHammerUi.Text((Transform)(object)_toolbar, Me ? "your effects" : ("effects for " + TargetName), "medium", 12f, AdminHammerUi.C("dim"), 0f, 0f, 260f, 58f, (TextAlignmentOptions)4100);
			AdminHammerUi.Place(((TMP_Text)val2).rectTransform, 303f, 0f, 260f, 58f);
			AdminHammerUi.Place(((TMP_Text)AdminHammerUi.Text((Transform)(object)_toolbar, "Showing", "medium", 12f, AdminHammerUi.C("mute"), 0f, 0f, 60f, 58f, (TextAlignmentOptions)4100)).rectTransform, 563f - AdminHammerUi.Width((TMP_Text)(object)val2) - 8f - 60f, 0f, 60f, 58f);
		}

		private static void PaintGrid()
		{
			//IL_0023: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_grid);
			List<Buffs.Entry> list = Visible().ToList();
			ZDOID who = (Me ? ZDOID.None : TargetId);
			float num = 177f;
			for (int i = 0; i < list.Count; i++)
			{
				Buffs.Entry e = list[i];
				RectTransform val = AdminHammerUi.Tile((Transform)(object)_grid, e.Se.m_icon, e.Name, e == _sel, 16f + (float)(i % 3) * (num + 8f), 14f + (float)(i / 3) * 68f, num, (Action)delegate
				{
					_sel = e;
					PaintGrid();
					PaintInspector();
				}, (Action)delegate
				{
					_sel = e;
					DoGive(e);
					Paint();
				}, (Action)delegate
				{
					_sel = e;
					if (Me && (Object)(object)Buffs.Active(e) != (Object)null)
					{
						DoRemove(e);
					}
					else
					{
						DoGive(e);
					}
					Paint();
				});
				if (Me && (Object)(object)Buffs.Active(e) != (Object)null)
				{
					AdminHammerUi.Tag(val, "ON", "on");
				}
				if (Me ? Buffs.IsUnlimited(e) : Buffs.Kept(who, e))
				{
					AdminHammerUi.Tag(val, "∞", "inf");
				}
			}
			_grid.sizeDelta = new Vector2(0f, 14f + (float)Mathf.CeilToInt((float)list.Count / 3f) * 68f + 10f);
		}

		private static void PaintInspector()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ins == (Object)null)
			{
				return;
			}
			AdminHammerUi.Clear((Transform)(object)_ins);
			float num = 18f;
			float num2 = 251f;
			if (_sel == null)
			{
				AdminHammerUi.Para((Transform)(object)_ins, "Pick an effect to give it or take it off.", 14f, AdminHammerUi.C("mute"), num, 18f, num2, 60f);
				return;
			}
			AdminHammerUi.IconBox((Transform)(object)_ins, _sel.Se.m_icon, _sel.Name, num, 18f, 56f, 12);
			TextMeshProUGUI obj = AdminHammerUi.Text((Transform)(object)_ins, _sel.Name, "bold", 18f, Color.white, num + 68f, 18f, num2 - 68f, 44f, (TextAlignmentOptions)257);
			((TMP_Text)obj).textWrappingMode = (TextWrappingModes)1;
			((TMP_Text)obj).maxVisibleLines = 2;
			((TMP_Text)obj).lineSpacing = -10f;
			AdminHammerUi.Text((Transform)(object)_ins, ((Object)_sel.Se).name, "mono", 12f, AdminHammerUi.C("mute"), num + 68f, 58f, num2 - 68f, 18f, (TextAlignmentOptions)4097);
			StatusEffect val = (Me ? Buffs.Active(_sel) : null);
			ZDOID who = (Me ? ZDOID.None : TargetId);
			string item = ((!Me) ? ("For " + TargetName) : (((Object)(object)val == (Object)null) ? "Off" : ((val.m_ttl <= 0f) ? "On, no time limit" : $"On, {Mathf.CeilToInt(val.GetRemaningTime())} s left")));
			float num3 = 92f + AdminHammerUi.Meta((Transform)(object)_ins, num, 92f, num2, new(string, string)[3]
			{
				("Category", _sel.Category),
				("Duration", (_sel.Se.m_ttl > 0f) ? $"{Mathf.RoundToInt(_sel.Se.m_ttl)} s" : "Set by the game"),
				("State", item)
			}) + 10f;
			bool flag = (Me ? Buffs.IsUnlimited(_sel) : Buffs.Kept(who, _sel));
			AdminHammerUi.Text((Transform)(object)_ins, Me ? "No time limit" : "Keep topping up while I'm online", "medium", 13f, AdminHammerUi.C("dim"), num, num3, num2 - 50f, 22f, (TextAlignmentOptions)4097);
			AdminHammerUi.Switch((Transform)(object)_ins, num + num2 - 38f, num3, flag, (Action<bool>)delegate(bool on)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				if (Me)
				{
					Buffs.SetUnlimited(_sel, on);
				}
				else
				{
					ZDOID targetId = TargetId;
					if (!((ZDOID)(ref targetId)).IsNone())
					{
						Buffs.SetKept(targetId, _sel, on);
					}
				}
				PaintGrid();
				PaintInspector();
			});
			num3 += 32f;
			AdminHammerUi.Para((Transform)(object)_ins, Me ? "Right click a tile to turn an effect on or off." : "Effects can't be taken off another player. Switching this off lets the effect run out.", 12.5f, AdminHammerUi.C("mute"), num, num3, num2, 40f);
			float num4 = 423f;
			AdminHammerUi.Primary((Transform)(object)_ins, "Give", num, num4, (num2 - 8f) / 2f, 42f, (Action)delegate
			{
				DoGive(_sel);
				Paint();
			}, true);
			AdminHammerUi.Secondary((Transform)(object)_ins, "Remove", num + (num2 - 8f) / 2f + 8f, num4 + 3f, (num2 - 8f) / 2f, 36f, (Action)delegate
			{
				DoRemove(_sel);
				Paint();
			}, !Me || (Object)(object)val != (Object)null);
			AdminHammerUi.Secondary((Transform)(object)_ins, "Remove all", num, num4 + 50f, num2, 36f, (Action)delegate
			{
				RemoveAll();
				Paint();
			}, true);
		}

		private static void DoGive(Buffs.Entry e)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (Me)
			{
				Buffs.Give(e);
				return;
			}
			ZDOID targetId = TargetId;
			if (((ZDOID)(ref targetId)).IsNone())
			{
				AdminHammerApi.Status(TargetName + " is not online");
				return;
			}
			Buffs.GiveTo(targetId, e);
			AdminHammerApi.Status("Gave " + e.Name + " to " + TargetName);
		}

		private static void DoRemove(Buffs.Entry e)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (Me)
			{
				Buffs.Remove(e);
				return;
			}
			ZDOID targetId = TargetId;
			if (!((ZDOID)(ref targetId)).IsNone())
			{
				Buffs.SetKept(targetId, e, on: false);
			}
			AdminHammerApi.Status("Stopped topping up " + e.Name + " on " + TargetName + "; it runs out normally");
		}

		private static void RemoveAll()
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!Me)
			{
				ZDOID targetId = TargetId;
				if (Buffs.Keep.TryGetValue(targetId, out var value))
				{
					value.Clear();
				}
				AdminHammerApi.Status("Stopped topping up everything on " + TargetName);
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			foreach (Buffs.Entry item in Buffs.All.Where((Buffs.Entry e) => (Object)(object)Buffs.Active(e) != (Object)null))
			{
				((Character)localPlayer).GetSEMan().RemoveStatusEffect(item.Hash, true);
			}
			AdminHammerApi.Status("Removed all effects");
		}

		private static void Line(float x, float y, float w, float h)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Image obj = AdminHammerUi.Box((Transform)(object)_area, "Line", AdminHammerUi.C("glassLine"), AdminHammerUi.NoColor, 1);
			((Graphic)obj).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj).rectTransform, x, y, w, h);
		}
	}
	internal static class Profiles
	{
		internal sealed class Profile
		{
			public string Name;

			public List<(string se, bool inf)> Fx = new List<(string, bool)>();
		}

		internal static List<Profile> All
		{
			get
			{
				List<Profile> list = new List<Profile>();
				string[] array = Plugin.ProfilesCfg.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string text in array)
				{
					int num = text.IndexOf('=');
					if (num <= 0)
					{
						continue;
					}
					Profile profile = new Profile
					{
						Name = text.Substring(0, num).Trim()
					};
					string[] array2 = text.Substring(num + 1).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
					for (int j = 0; j < array2.Length; j++)
					{
						string[] array3 = array2[j].Split(new char[1] { ':' });
						if (array3[0].Trim().Length > 0)
						{
							profile.Fx.Add((array3[0].Trim(), array3.Length > 1 && array3[1].Trim() == "1"));
						}
					}
					list.Add(profile);
				}
				return list;
			}
		}

		internal static void Save(string name, List<(string se, bool inf)> fx)
		{
			name = new string(name.Where((char c) => c != ';' && c != '=' && c != ',' && c != ':').ToArray()).Trim();
			if (name.Length != 0)
			{
				List<Profile> list = All.Where((Profile p) => !string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)).ToList();
				list.Add(new Profile
				{
					Name = name,
					Fx = fx
				});
				Write(list);
			}
		}

		internal static void Delete(Profile p)
		{
			Write(All.Where((Profile x) => x.Name != p.Name).ToList());
		}

		private static void Write(List<Profile> list)
		{
			Plugin.ProfilesCfg.Value = string.Join(";", list.Select((Profile p) => p.Name + "=" + string.Join(",", p.Fx.Select(((string se, bool inf) f) => f.se + ":" + (f.inf ? "1" : "0")))));
		}
	}
}