Decompiled source of ProtectSpawnerFarms v2.1.1

ProtectSpawnerFarms.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using JoksterCube.ProtectSpawnerFarms.Common;
using JoksterCube.ProtectSpawnerFarms.Common.Networking;
using JoksterCube.ProtectSpawnerFarms.Domain;
using JoksterCube.ProtectSpawnerFarms.Domain.Networking;
using JoksterCube.ProtectSpawnerFarms.Settings;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ProtectSpawnerFarms")]
[assembly: AssemblyDescription("Protect the spawners your farms are built around: no damage while you're near, raised health, a shield bubble, and a Compendium list shared with your friends.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("JoksterCube")]
[assembly: AssemblyProduct("ProtectSpawnerFarms")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("53b674a6-219f-461c-9ac8-ddeb4570dd1f")]
[assembly: AssemblyFileVersion("2.1.1")]
[assembly: InternalsVisibleTo("ProtectSpawnerFarms.Tests")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 JoksterCube.ProtectSpawnerFarms
{
	[BepInPlugin("JoksterCube.ProtectSpawnerFarms", "ProtectSpawnerFarms", "2.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static readonly ManualLogSource ModLogger = Logger.CreateLogSource("ProtectSpawnerFarms");

		internal static string ConnectionError = string.Empty;

		internal static readonly ConfigSync ServerConfigSync = new ConfigSync("JoksterCube.ProtectSpawnerFarms")
		{
			DisplayName = "ProtectSpawnerFarms",
			CurrentVersion = "2.1.1",
			MinimumRequiredVersion = "2.1.1",
			IsLocked = true
		};

		private readonly string _configFileFullPath = Path.Combine(Paths.ConfigPath, "JoksterCube.ProtectSpawnerFarms.cfg");

		private const float ConfigCheckInterval = 2f;

		private FileSystemWatcher? _configWatcher;

		private DateTime _lastConfigWrite;

		private long _lastConfigSize = -1L;

		private float _nextConfigCheck;

		private readonly Harmony _harmony = new Harmony("JoksterCube.ProtectSpawnerFarms");

		private void Awake()
		{
			PluginConfig.Build(((BaseUnityPlugin)this).Config, ServerConfigSync);
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			RememberConfigFile();
			SetupWatcher();
		}

		private void Update()
		{
			if (Time.unscaledTime >= _nextConfigCheck)
			{
				_nextConfigCheck = Time.unscaledTime + 2f;
				ReloadConfigIfChanged();
			}
			ServerGuard.Update();
			ProtectionSync.Update();
			SpawnerProtection.Update();
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
			_configWatcher?.Dispose();
			SessionState.Clear();
			ProtectedMarker.Dispose();
			SpawnerHighlight.Dispose();
		}

		private void SetupWatcher()
		{
			try
			{
				FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "*.cfg")
				{
					NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime)
				};
				fileSystemWatcher.Changed += OnConfigFolderChanged;
				fileSystemWatcher.Created += OnConfigFolderChanged;
				fileSystemWatcher.Renamed += OnConfigFolderChanged;
				fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
				_configWatcher = fileSystemWatcher;
				fileSystemWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				ModLogger.LogWarning((object)string.Format("Config file watcher unavailable, checking {0} every {1} s instead: {2}", "JoksterCube.ProtectSpawnerFarms.cfg", 2f, ex.Message));
			}
		}

		private void OnConfigFolderChanged(object sender, FileSystemEventArgs e)
		{
			ReloadConfigIfChanged();
		}

		private void RememberConfigFile()
		{
			try
			{
				FileInfo fileInfo = new FileInfo(_configFileFullPath);
				if (fileInfo.Exists)
				{
					_lastConfigWrite = fileInfo.LastWriteTimeUtc;
					_lastConfigSize = fileInfo.Length;
				}
			}
			catch (IOException)
			{
			}
		}

		private void ReloadConfigIfChanged()
		{
			FileInfo fileInfo;
			try
			{
				fileInfo = new FileInfo(_configFileFullPath);
				if (!fileInfo.Exists || (fileInfo.LastWriteTimeUtc == _lastConfigWrite && fileInfo.Length == _lastConfigSize))
				{
					return;
				}
			}
			catch (IOException)
			{
				return;
			}
			_lastConfigWrite = fileInfo.LastWriteTimeUtc;
			_lastConfigSize = fileInfo.Length;
			try
			{
				ModLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
				ModLogger.LogInfo((object)"JoksterCube.ProtectSpawnerFarms.cfg changed, settings reloaded.");
			}
			catch
			{
				_lastConfigWrite = default(DateTime);
				_lastConfigSize = -1L;
				ModLogger.LogError((object)"There was an issue loading your JoksterCube.ProtectSpawnerFarms.cfg");
				ModLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}
	}
}
namespace JoksterCube.ProtectSpawnerFarms.Settings
{
	internal sealed class ConfigInfo<T>
	{
		internal string Group { get; }

		internal string Name { get; }

		internal ConfigDescription Description { get; }

		internal T DefaultValue { get; }

		internal bool Synchronized { get; }

		internal bool IsAdvanced { get; set; }

		internal ConfigInfo(string group, string name, string description, T defaultValue, bool synchronized = true)
			: this(group, name, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), defaultValue, synchronized)
		{
		}//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown


		internal ConfigInfo(string group, string name, ConfigDescription description, T defaultValue, bool synchronized = true)
		{
			Group = group;
			Name = name;
			Description = description;
			DefaultValue = defaultValue;
			Synchronized = synchronized;
		}
	}
	internal static class ConfigOptions
	{
		private static ConfigFile? _configFile;

		private static ConfigSync? _configSync;

		private static readonly Dictionary<string, int> NextOrder = new Dictionary<string, int>();

		internal static void Initialize(ConfigFile config, ConfigSync configSync)
		{
			_configFile = config;
			_configSync = configSync;
		}

		internal static ConfigEntry<T> Config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true, bool advanced = false)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			int value2;
			int num = (NextOrder.TryGetValue(group, out value2) ? value2 : 1000);
			NextOrder[group] = num - 1;
			ConfigurationManagerAttributes element = new ConfigurationManagerAttributes
			{
				Order = num,
				IsAdvanced = (advanced ? new bool?(true) : ((bool?)null))
			};
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, (description.Tags ?? Array.Empty<object>()).Append(element).ToArray());
			ConfigEntry<T> val2 = (_configFile ?? throw new InvalidOperationException("ConfigOptions is not initialized.")).Bind<T>(group, name, value, val);
			(_configSync ?? throw new InvalidOperationException("ConfigOptions is not initialized.")).AddConfigEntry<T>(val2).SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		internal static ConfigEntry<T> Config<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return Config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		internal static ConfigEntry<T> Config<T>(ConfigInfo<T> configInfo)
		{
			return Config(configInfo.Group, configInfo.Name, configInfo.DefaultValue, configInfo.Description, configInfo.Synchronized, configInfo.IsAdvanced);
		}
	}
	internal sealed class ConfigurationManagerAttributes
	{
		public int? Order;

		public bool? IsAdvanced;

		public bool? ReadOnly;

		public bool? Browsable;

		public string? DispName;

		public string? Category;
	}
	internal static class Constants
	{
		internal static class Plugin
		{
			internal const string ModName = "ProtectSpawnerFarms";

			internal const string ModVersion = "2.1.1";

			internal const string Author = "JoksterCube";

			internal const string ModGUID = "JoksterCube.ProtectSpawnerFarms";

			internal const string Description = "Protect the spawners your farms are built around: no damage while you're near, raised health, a shield bubble, and a Compendium list shared with your friends.";

			internal const string Copyright = "Copyright ©  2026";

			internal const string Guid = "53b674a6-219f-461c-9ac8-ddeb4570dd1f";

			internal const string ConfigFileName = "JoksterCube.ProtectSpawnerFarms.cfg";

			internal const string VersionCheckRpc = "ProtectSpawnerFarms_VersionCheck";
		}

		internal static class Rpcs
		{
			internal const string RequestList = "ProtectSpawnerFarms_RequestList";

			internal const string SetProtected = "ProtectSpawnerFarms_SetProtected";

			internal const string Touch = "ProtectSpawnerFarms_Touch";

			internal const string ProtectedList = "ProtectSpawnerFarms_ProtectedList";

			internal const string Refused = "ProtectSpawnerFarms_Refused";
		}

		internal static class Messages
		{
			internal const string Protected = "{0} is now protected";

			internal const string Unprotected = "{0} is no longer protected";

			internal const string HighlightOn = "Highlighting the nearest spawner";

			internal const string HighlightOff = "Stopped highlighting spawners";

			internal const string RefusedAdminsOnly = "Only server admins can change spawner protection";

			internal const string RefusedProtectorOnly = "Only {0} or an admin can remove this protection";

			internal const string StatusName = "Protecting spawner";

			internal const string StatusTooltip = "A protected spawner is near. Damage to it is blocked while you stay close.";

			internal const string ServerStatusName = "Protected spawner nearby";

			internal const string ServerStatusTooltip = "The server keeps this spawner safe from all damage.";

			internal const string HighlightStatusName = "Highlighting spawner";

			internal const string HighlightStatusTooltip = "The nearest spawner is painted in a pulsing color you can see through walls.";

			internal const string HoverProtectedBy = "Protected by {0}";

			internal const string HoverProtected = "Protected";

			internal const string ProtectTooltipTopic = "Protect spawner";

			internal const string UnprotectTooltipTopic = "Unprotect spawner";

			internal const string ProtectTooltip = "{0}, {1} m away";

			internal const string UnprotectTooltip = "{0}, {1} m away";

			internal const string HighlightTooltipTopic = "Highlight nearest spawner";

			internal const string CompendiumTopic = "Protected spawners";

			internal const string CompendiumEmpty = "No protected spawners found yet. Open your inventory next to a spawner and click the shield.";

			internal const string CompendiumCount = "{0} protected, nearest first.";

			internal const string CompendiumDistance = "  -  {0} away";

			internal const string CompendiumProtectedBy = "Protected by {0} {1}";

			internal const string CompendiumLastGuarded = "Last guarded {0} by {1}";

			internal const string CompendiumNeverGuarded = "Not guarded yet";

			internal const string CompendiumLastBlocked = "Last blocked a hit {0}";

			internal const string CompendiumNeverBlocked = "No hits blocked yet";

			internal const string CompendiumShowOnMap = "Show on map ({0:0}, {1:0})";

			internal const string CompendiumUnknownPlayer = "someone";

			internal const string CompendiumUnknownTime = "at an unknown time";

			internal const string CompendiumSharedByServer = "Saved on the spawners themselves. The server lists every protected spawner in the world for everyone with the mod.";

			internal const string CompendiumSeenNearby = "Saved on the spawners themselves. The server doesn't have the mod, so this lists the protected spawners you have been near on this server.";

			internal const string CompendiumHosted = "Saved on the spawners in this world. Players who join with the mod see this list too.";

			internal const string CompendiumLocal = "Saved on the spawners in this world.";

			internal const string StopHighlightTooltipTopic = "Stop highlighting";

			internal const string HighlightTooltip = "{0}, {1} m away";

			internal const string StopHighlightTooltip = "{0}, {1} m away";
		}

		internal static class DebugMessages
		{
			internal const string ReadConfigCalled = "ReadConfigValues called";

			internal const string ErrorLoadingConfig = "There was an issue loading your JoksterCube.ProtectSpawnerFarms.cfg";

			internal const string RequestCheckConfig = "Please check your config entries for spelling and format!";
		}

		internal static class Groups
		{
			internal static class Protection
			{
				internal const string Group = "1 - Protection";

				internal static readonly ConfigInfo<float> BoostedHealth = new ConfigInfo<float>("1 - Protection", "Boosted Health", new ConfigDescription("Health a protected spawner is raised to, so players without the mod don't destroy it by accident. Set to 0 to keep normal health. Unprotecting a spawner puts its health back to normal.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000000f), Array.Empty<object>()), 100000f);

				internal static readonly ConfigInfo<float> ProtectionRange = new ConfigInfo<float>("1 - Protection", "Protection Range", new ConfigDescription("While you are within this many meters of a protected spawner, you get the Protecting spawner status. Protection itself doesn't depend on it: damage to a protected spawner is always blocked.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>()), 20f);

				internal static readonly ConfigInfo<ProtectionPermission> WhoCanChange = new ConfigInfo<ProtectionPermission>("1 - Protection", "Who Can Change Protection", "Who may protect and unprotect spawners. Anyone: every player with the mod. AdminsOnly: only server admins. ProtectorOrAdmin: anyone can protect, but only the player who protected a spawner (or an admin) can remove its protection. On a server with the mod the server decides; without it, each player's own setting applies to their own changes.", ProtectionPermission.Anyone);
			}

			internal static class Controls
			{
				internal const string Group = "2 - Controls";

				internal static readonly ConfigInfo<float> ActionDistance = new ConfigInfo<float>("2 - Controls", "Action Distance", new ConfigDescription("The spawner buttons show in the inventory screen when a spawner is within this many meters. They act on the closest one.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>()), 20f, synchronized: false);
			}

			internal static class Display
			{
				internal const string Group = "3 - Display";

				internal static readonly ConfigInfo<Toggle> ShowShieldBubble = new ConfigInfo<Toggle>("3 - Display", "Show Shield Bubble", "Show a shield bubble, like the Staff of Protection's, around protected spawners.", Toggle.On, synchronized: false);

				internal static readonly ConfigInfo<Color> ShieldBubbleColor = new ConfigInfo<Color>("3 - Display", "Shield Bubble Color", "Color of the shield bubble around protected spawners.", new Color(0.2f, 0.55f, 1f, 1f), synchronized: false);

				internal static readonly ConfigInfo<float> ShieldBubbleOpacity = new ConfigInfo<float>("3 - Display", "Shield Bubble Opacity", new ConfigDescription("How solid the shield bubble looks: 0 is invisible, 1 is fully solid.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()), 0.1f, synchronized: false);

				internal static readonly ConfigInfo<Color> HighlightColor = new ConfigInfo<Color>("3 - Display", "Highlight Color", "Color a highlighted spawner is painted in. It pulses and shows through walls.", new Color(1f, 0.75f, 0.2f, 1f), synchronized: false);

				internal static readonly ConfigInfo<Toggle> ShowProtectingStatus = new ConfigInfo<Toggle>("3 - Display", "Show Protecting Status", "Show the Protecting spawner status while you are near a protected spawner.", Toggle.On, synchronized: false);

				internal static readonly ConfigInfo<Toggle> ShowMessages = new ConfigInfo<Toggle>("3 - Display", "Show Messages", "Show a message when a spawner is protected, unprotected or highlighted.", Toggle.On, synchronized: false);
			}
		}
	}
	internal static class PluginConfig
	{
		internal static ConfigEntry<float> BoostedHealth;

		internal static ConfigEntry<float> ProtectionRange;

		internal static ConfigEntry<ProtectionPermission> WhoCanChange;

		internal static ConfigEntry<float> ActionDistance;

		internal static ConfigEntry<Toggle> ShowShieldBubble;

		internal static ConfigEntry<Color> ShieldBubbleColor;

		internal static ConfigEntry<float> ShieldBubbleOpacity;

		internal static ConfigEntry<Color> HighlightColor;

		internal static ConfigEntry<Toggle> ShowProtectingStatus;

		internal static ConfigEntry<Toggle> ShowMessages;

		internal static void Build(ConfigFile config, ConfigSync configSync)
		{
			ConfigOptions.Initialize(config, configSync);
			BoostedHealth = ConfigOptions.Config(Constants.Groups.Protection.BoostedHealth);
			ProtectionRange = ConfigOptions.Config(Constants.Groups.Protection.ProtectionRange);
			WhoCanChange = ConfigOptions.Config(Constants.Groups.Protection.WhoCanChange);
			ActionDistance = ConfigOptions.Config(Constants.Groups.Controls.ActionDistance);
			ShowShieldBubble = ConfigOptions.Config(Constants.Groups.Display.ShowShieldBubble);
			ShieldBubbleColor = ConfigOptions.Config(Constants.Groups.Display.ShieldBubbleColor);
			ShieldBubbleOpacity = ConfigOptions.Config(Constants.Groups.Display.ShieldBubbleOpacity);
			HighlightColor = ConfigOptions.Config(Constants.Groups.Display.HighlightColor);
			ShowProtectingStatus = ConfigOptions.Config(Constants.Groups.Display.ShowProtectingStatus);
			ShowMessages = ConfigOptions.Config(Constants.Groups.Display.ShowMessages);
		}
	}
}
namespace JoksterCube.ProtectSpawnerFarms.Patches
{
	internal static class CompendiumPatches
	{
		[HarmonyPatch(typeof(TextsDialog), "UpdateTextsList")]
		private static class AddPage
		{
			private static void Postfix(TextsDialog __instance)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				if (PatchGuard.IsDisabled("Compendium page"))
				{
					return;
				}
				try
				{
					int index = Math.Min(1, __instance.m_texts.Count);
					__instance.m_texts.Insert(index, new TextInfo(Compendium.Topic, Compendium.BuildText()));
				}
				catch (Exception exception)
				{
					PatchGuard.Fail("Compendium page", exception);
				}
			}
		}

		[HarmonyPatch(typeof(TextsDialog), "Update")]
		private static class MapButtons
		{
			private static void Postfix(TextsDialog __instance)
			{
				if (PatchGuard.IsDisabled("Compendium page"))
				{
					return;
				}
				try
				{
					Compendium.UpdateButtons(__instance);
				}
				catch (Exception exception)
				{
					PatchGuard.Fail("Compendium page", exception);
				}
			}
		}

		private const string Feature = "Compendium page";
	}
	internal static class EnforceServerConfigPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static class LockForAdmins
		{
			private static void Postfix(ConfigSync __instance, ref bool __result)
			{
				if (__instance == Plugin.ServerConfigSync && !__instance.IsSourceOfTruth)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(ConfigSync), "RPC_FromOtherClientConfigSync")]
		private static class IgnoreClientChanges
		{
			private static bool Prefix(ConfigSync __instance, long sender)
			{
				if (__instance != Plugin.ServerConfigSync || !Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
				{
					return true;
				}
				Plugin.ModLogger.LogWarning((object)string.Format("Ignored a settings change sent by a player ({0}). Change {1} on the server instead.", sender, "JoksterCube.ProtectSpawnerFarms.cfg"));
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(HoverText), "GetHoverText")]
	internal static class HoverTextPatch
	{
		private const string Feature = "Spawner hover text";

		private const string Color = "#8fd3ff";

		private static void Postfix(HoverText __instance, ref string __result)
		{
			if (PatchGuard.IsDisabled("Spawner hover text"))
			{
				return;
			}
			try
			{
				Destructible destructible = default(Destructible);
				if (((Component)__instance).TryGetComponent<Destructible>(ref destructible) && SpawnerRegistry.TryGet(destructible, out SpawnerRegistry.Spawner spawner) && SpawnerData.IsProtected(spawner.View.GetZDO()))
				{
					string text = SpawnerData.ProtectedBy(spawner.View.GetZDO());
					string text2 = (string.IsNullOrEmpty(text) ? "Protected" : $"Protected by {text}");
					__result = __result + "\n<color=#8fd3ff>" + text2 + "</color>";
				}
			}
			catch (Exception exception)
			{
				PatchGuard.Fail("Spawner hover text", exception);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	internal static class InventoryButtonsPatch
	{
		private const string Feature = "Inventory buttons";

		private static void Postfix(InventoryGui __instance)
		{
			if (PatchGuard.IsDisabled("Inventory buttons"))
			{
				return;
			}
			try
			{
				SpawnerButtons.Update(__instance);
			}
			catch (Exception exception)
			{
				PatchGuard.Fail("Inventory buttons", exception);
			}
		}
	}
	internal static class ServerGuardPatch
	{
		[HarmonyPatch(typeof(ZDOMan), "RPC_ZDOData")]
		private static class RestoreHealth
		{
			private static void Postfix()
			{
				ServerGuard.OnDataReceived();
			}
		}

		[HarmonyPatch(typeof(ZRoutedRpc), "RPC_RoutedRPC")]
		private static class RefuseDestroy
		{
			private static bool Prefix(ZRoutedRpc __instance, ZPackage pkg)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				if (!__instance.m_server)
				{
					return true;
				}
				int pos = pkg.GetPos();
				RoutedRPCData val = new RoutedRPCData();
				val.Deserialize(pkg);
				if (val.m_methodHash != ServerGuard.DestroyMethod)
				{
					pkg.SetPos(pos);
					return true;
				}
				if (ServerGuard.FilterDestroy(val))
				{
					if (val.m_targetPeerID == __instance.m_id || val.m_targetPeerID == 0L)
					{
						__instance.HandleRoutedRPC(val);
					}
					if (val.m_targetPeerID != __instance.m_id)
					{
						__instance.RouteRPC(val);
					}
				}
				return false;
			}
		}
	}
	internal static class SessionPatches
	{
		[HarmonyPatch(typeof(ZNet), "Awake")]
		private static class RegisterRpcs
		{
			private const string Feature = "Protection sync";

			private static void Postfix()
			{
				if (PatchGuard.IsDisabled("Protection sync") || ZRoutedRpc.instance == null)
				{
					return;
				}
				try
				{
					ProtectionSync.Register(ZRoutedRpc.instance);
				}
				catch (Exception exception)
				{
					PatchGuard.Fail("Protection sync", exception);
				}
			}
		}

		[HarmonyPatch(typeof(ZNet), "OnDestroy")]
		private static class ResetSession
		{
			private const string Feature = "Session reset";

			private static void Postfix()
			{
				if (PatchGuard.IsDisabled("Session reset"))
				{
					return;
				}
				try
				{
					SessionState.Clear();
				}
				catch (Exception exception)
				{
					PatchGuard.Fail("Session reset", exception);
				}
			}
		}
	}
	internal static class SpawnerPatches
	{
		[HarmonyPatch(typeof(Destructible), "Awake")]
		private static class RegisterSpawner
		{
			private static void Postfix(Destructible __instance)
			{
				if (PatchGuard.IsDisabled("Spawner damage protection"))
				{
					return;
				}
				try
				{
					SpawnerRegistry.TryAdd(__instance);
				}
				catch (Exception exception)
				{
					PatchGuard.Fail("Spawner damage protection", exception);
				}
			}
		}

		[HarmonyPatch(typeof(Destructible), "Damage")]
		private static class BlockOutgoingHit
		{
			private static bool Prefix(Destructible __instance, HitData hit)
			{
				return !Blocks(__instance, hit);
			}
		}

		[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
		private static class BlockIncomingHit
		{
			private static bool Prefix(Destructible __instance, HitData hit)
			{
				if (Object.op_Implicit((Object)(object)__instance.m_nview) && __instance.m_nview.IsOwner())
				{
					return !Blocks(__instance, hit);
				}
				return true;
			}
		}

		private const string Feature = "Spawner damage protection";

		private static bool Blocks(Destructible destructible, HitData hit)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (PatchGuard.IsDisabled("Spawner damage protection"))
			{
				return false;
			}
			try
			{
				if (!SpawnerProtection.TryBlockDamage(destructible))
				{
					return false;
				}
				if (Object.op_Implicit((Object)(object)DamageText.instance) && hit != null)
				{
					DamageText.instance.ShowText((TextType)3, hit.m_point, 0f, false);
				}
				return true;
			}
			catch (Exception exception)
			{
				PatchGuard.Fail("Spawner damage protection", exception);
				return false;
			}
		}
	}
}
namespace JoksterCube.ProtectSpawnerFarms.Domain
{
	internal static class ButtonIcons
	{
		internal static readonly Color Amber = new Color(1f, 0.5f, 0.12f);

		private static Sprite? _shield;

		private static Sprite? _eye;

		private static readonly float[] RayAngles = new float[5] { -60f, -30f, 0f, 30f, 60f };

		internal static Sprite Shield()
		{
			if (!Object.op_Implicit((Object)(object)_shield))
			{
				return _shield = ShieldPicture().ToSprite("ProtectSpawnerFarms_Shield");
			}
			return _shield;
		}

		internal static Sprite Eye()
		{
			if (!Object.op_Implicit((Object)(object)_eye))
			{
				return _eye = EyePicture().ToSprite("ProtectSpawnerFarms_Eye");
			}
			return _eye;
		}

		internal static Color[] RenderShield()
		{
			return ShieldPicture().Colors;
		}

		internal static Color[] RenderEye()
		{
			return EyePicture().Colors;
		}

		private static IconCanvas ShieldPicture()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			IconCanvas iconCanvas = new IconCanvas();
			IconPaint.Glow(iconCanvas, 32f, 32f, 31f, Amber, 0.45f);
			PaintShield(iconCanvas, 32f, 32f, 27f);
			return iconCanvas;
		}

		internal static void PaintShield(IconCanvas canvas, float cx, float cy, float radius)
		{
			float s = radius / 27f;
			float rimWidth = 3.5f * s;
			float face = radius - rimWidth;
			IconPaint.Shadow(canvas, (float x, float y) => IconPaint.Circle(x, y, cx, cy, radius), 0.6f);
			float left = cx - 28f * s;
			float top = cy - 24f * s;
			float board = 9f * s;
			canvas.Paint(delegate(float x, float y)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				float num = IconPaint.Circle(x, y, cx, cy, face);
				if (num > 0.5f)
				{
					return Color.clear;
				}
				int num2 = Mathf.FloorToInt((x - left) / board);
				float num3 = Mathf.Abs(x - left - ((float)num2 + 0.5f) * board) / (board / 2f);
				float num4 = ((num2 % 2 == 0) ? 1f : 0.88f);
				float num5 = Mathf.Lerp(1f, 0.62f, Mathf.Clamp01((y - top) / (48f * s))) * num4;
				num5 *= Mathf.Lerp(1f, 0.6f, Mathf.Pow(num3, 6f));
				num5 *= 0.8f + 0.2f * Mathf.Clamp01((0f - num) / (3f * s));
				return new Color(0.62f * num5, 0.38f * num5, 0.2f * num5, Mathf.Clamp01(0.5f - num));
			});
			canvas.Paint(delegate(float x, float y)
			{
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Abs(IconPaint.Circle(x, y, cx, cy, 0f) - (radius - rimWidth / 2f)) - rimWidth / 2f;
				float num2 = Mathf.Clamp01((cy - y) / radius * 0.5f + 0.5f);
				float num3 = Mathf.Clamp01((0f - num) / (1.5f * s));
				float num4 = Mathf.Lerp(0.3f, 0.68f, num2) * (0.7f + 0.3f * num3);
				return new Color(num4, num4 * 0.98f, num4 * 0.95f, Mathf.Clamp01(0.5f - num));
			});
			canvas.Paint(delegate(float x, float y)
			{
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Abs(IconPaint.Circle(x, y, cx, cy, face)) - 0.5f;
				return new Color(0.12f, 0.07f, 0.04f, Mathf.Clamp01(0.5f - num) * 0.7f);
			});
			PaintBoss(canvas, cx, cy, s);
		}

		private static void PaintBoss(IconCanvas canvas, float cx, float cy, float s)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			float r = 9f * s;
			IconPaint.GlowLine(canvas, (float x, float y) => Mathf.Abs(IconPaint.Circle(x, y, cx, cy, r + 2.2f * s)) - Mathf.Max(0.9f * s, 0.6f), new Color(1f, 0.45f, 0.1f), new Color(1f, 0.82f, 0.45f), Mathf.Max(4.5f * s, 2.5f), 0.8f);
			IconPaint.Shadow(canvas, (float x, float y) => IconPaint.Circle(x, y, cx, cy, r), 0.5f);
			canvas.Paint(delegate(float x, float y)
			{
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				float num = IconPaint.Circle(x, y, cx, cy, r);
				float num2 = (x - cx) / r;
				float num3 = (y - cy) / r;
				float num4 = Mathf.Clamp01(0.55f - 0.6f * (num2 * 0.6f + num3 * 0.8f) - 0.35f * (num2 * num2 + num3 * num3));
				float num5 = Mathf.Lerp(0.22f, 0.8f, num4);
				return new Color(num5, num5 * 0.97f, num5 * 0.93f, Mathf.Clamp01(0.5f - num));
			});
			canvas.Paint((float x, float y) => new Color(1f, 1f, 0.95f, Mathf.Clamp01(0.5f - IconPaint.Circle(x, y, cx - 3f * s, cy - 3.5f * s, Mathf.Max(1.8f * s, 0.8f))) * 0.7f));
		}

		private static IconCanvas EyePicture()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			IconCanvas iconCanvas = new IconCanvas();
			IconPaint.Glow(iconCanvas, 32f, 32f, 32f, Amber, 0.5f);
			IconPaint.GlowLine(iconCanvas, delegate(float x, float y)
			{
				float num = float.MaxValue;
				float[] rayAngles = RayAngles;
				for (int i = 0; i < rayAngles.Length; i++)
				{
					float num2 = rayAngles[i] * ((float)Math.PI / 180f);
					float num3 = Mathf.Sin(num2);
					float num4 = Mathf.Cos(num2);
					float num5 = 19f + 4f * Mathf.Abs(num3);
					float num6 = num5 + 7f;
					num = Mathf.Min(num, IconPaint.Capsule(x, y, 32f + num3 * num5, 32f - num4 * num5, 32f + num3 * num6, 32f - num4 * num6, 1.3f));
					num = Mathf.Min(num, IconPaint.Capsule(x, y, 32f + num3 * num5, 32f + num4 * num5, 32f + num3 * num6, 32f + num4 * num6, 1.3f));
				}
				return num;
			}, Amber, new Color(1f, 0.85f, 0.5f), 3.5f, 0.6f);
			PaintEye(iconCanvas, 32f, 32f, 1f);
			return iconCanvas;
		}

		internal static void PaintEye(IconCanvas canvas, float cx, float cy, float scale)
		{
			float lid = Mathf.Max(2f * scale, 1.2f);
			IconPaint.Shadow(canvas, (float x, float y) => EyeShape(x, y) - lid, 0.6f);
			canvas.Paint(delegate(float x, float y)
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				float num = EyeShape(x, y) - lid;
				return new Color(0.24f, 0.14f, 0.08f, Mathf.Clamp01(0.5f - num));
			});
			canvas.Paint(delegate(float x, float y)
			{
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				float num = EyeShape(x, y);
				float num2 = Mathf.Lerp(1f, 0.7f, Mathf.Clamp01(Mathf.Abs(x - cx) / (22f * scale))) * Mathf.Lerp(0.82f, 1f, Mathf.Clamp01((y - (cy - 10f * scale)) / (10f * scale)));
				return new Color(0.95f * num2, 0.9f * num2, 0.8f * num2, Mathf.Clamp01(0.5f - num));
			});
			float irisRadius = 10f * scale;
			canvas.Paint(delegate(float x, float y)
			{
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Max(IconPaint.Circle(x, y, cx, cy, irisRadius), EyeShape(x, y));
				float num2 = Mathf.Clamp01((0f - IconPaint.Circle(x, y, cx, cy, irisRadius)) / irisRadius);
				Color below = new Color(1f, Mathf.Lerp(0.45f, 0.82f, num2), Mathf.Lerp(0.08f, 0.35f, num2), Mathf.Clamp01(0.5f - num));
				float num3 = Mathf.Clamp01(0.5f - Mathf.Max(Mathf.Abs(IconPaint.Circle(x, y, cx, cy, irisRadius - 0.6f * scale)) - Mathf.Max(0.6f * scale, 0.4f), EyeShape(x, y)));
				return IconCanvas.Over(below, new Color(0.45f, 0.18f, 0.05f, num3 * 0.8f));
			});
			canvas.Paint((float x, float y) => new Color(0.08f, 0.04f, 0.02f, Mathf.Clamp01(0.5f - IconPaint.Circle(x, y, cx, cy, Mathf.Max(4.2f * scale, 1.6f)))));
			canvas.Paint((float x, float y) => new Color(1f, 1f, 0.95f, Mathf.Clamp01(0.5f - IconPaint.Circle(x, y, cx - 3.5f * scale, cy - 3.5f * scale, Mathf.Max(2f * scale, 0.9f))) * 0.9f));
			float EyeShape(float x, float y)
			{
				return Mathf.Max(IconPaint.Circle(x, y, cx, cy + 18f * scale, 30f * scale), IconPaint.Circle(x, y, cx, cy - 18f * scale, 30f * scale));
			}
		}
	}
	internal static class Compendium
	{
		private readonly struct MapTarget
		{
			internal Vector3 Position { get; }

			internal string Name { get; }

			internal string Label { get; }

			public MapTarget(Vector3 position, string name, string label)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				Position = position;
				Name = name;
				Label = label;
			}
		}

		private const string LinkPrefix = "psf:";

		private const string NameColor = "#ffd27f";

		private const string DateColor = "#9fd8ff";

		private const string FadedColor = "#a0a0a0";

		private const string PlaceColor = "#e8d9b0";

		private static readonly Vector2 ButtonPadding = new Vector2(28f, 10f);

		private static readonly Vector2 ButtonOffset = new Vector2(18f, -8f);

		private static readonly List<MapTarget> Targets = new List<MapTarget>();

		private static MapTarget? _pending;

		private static readonly List<GameObject> Buttons = new List<GameObject>();

		private static readonly List<(int Index, Vector2 Min, Vector2 Max)> Spots = new List<(int, Vector2, Vector2)>();

		internal static string Topic => "Protected spawners";

		internal static string BuildText()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			Targets.Clear();
			StringBuilder stringBuilder = new StringBuilder(1024);
			stringBuilder.Append("<color=#c8c8c8>").Append(SharingLine()).Append("</color>\n\n");
			Vector3? player = (Object.op_Implicit((Object)(object)Player.m_localPlayer) ? new Vector3?(((Component)Player.m_localPlayer).transform.position) : ((Vector3?)null));
			string prefabName;
			float x;
			float y;
			float z;
			List<(SpawnerRecord, string, Vector3)> list = (from record in ProtectedSpawners.All
				select (!SpawnerKey.TryParse(record.Key, out prefabName, out x, out y, out z)) ? default((SpawnerRecord, string, Vector3)) : (Record: record, Prefab: prefabName, Position: new Vector3(x, y, z)) into entry
				where entry.Record != null
				orderby (!player.HasValue) ? 0f : Vector3.Distance(player.Value, entry.Position)
				select entry).ToList();
			if (list.Count == 0)
			{
				stringBuilder.Append("No protected spawners found yet. Open your inventory next to a spawner and click the shield.");
				return stringBuilder.ToString();
			}
			stringBuilder.Append($"{list.Count} protected, nearest first.").Append("\n\n");
			foreach (var item4 in list)
			{
				SpawnerRecord item = item4.Item1;
				string item2 = item4.Item2;
				Vector3 item3 = item4.Item3;
				string text = SpawnerRegistry.NameOf(item2);
				stringBuilder.Append("<color=orange>").Append(text).Append("</color>");
				if (player.HasValue)
				{
					stringBuilder.Append(string.Format("  -  {0} away", Colored("#e8d9b0", Vector3.Distance(player.Value, item3).ToString("0") + " m")));
				}
				stringBuilder.Append('\n');
				stringBuilder.Append($"Protected by {Who(item.ProtectedBy)} {When(item.ProtectedAt)}").Append('\n');
				stringBuilder.Append((item.LastGuarded > 0) ? $"Last guarded {When(item.LastGuarded)} by {Who(item.GuardedBy)}" : "Not guarded yet").Append('\n');
				stringBuilder.Append((item.LastBlocked > 0) ? $"Last blocked a hit {When(item.LastBlocked)}" : "No hits blocked yet").Append('\n');
				string text2 = string.Format(CultureInfo.InvariantCulture, "Show on map ({0:0}, {1:0})", item3.x, item3.z);
				stringBuilder.Append("<size=120%><link=\"").Append("psf:").Append(Targets.Count)
					.Append("\"><alpha=#00>   ")
					.Append(text2)
					.Append("   </link><alpha=#FF></size>\n\n");
				Targets.Add(new MapTarget(item3, text, text2));
			}
			stringBuilder.Append("<alpha=#00>.<alpha=#FF>");
			return stringBuilder.ToString();
		}

		internal static void UpdateButtons(TextsDialog dialog)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text textArea = dialog.m_textArea;
			TMP_Text textAreaTopic = dialog.m_textAreaTopic;
			if (!Object.op_Implicit((Object)(object)textArea) || !Object.op_Implicit((Object)(object)textAreaTopic))
			{
				return;
			}
			if (textAreaTopic.text != Topic)
			{
				if (Buttons.Count > 0)
				{
					ClearButtons();
				}
				return;
			}
			TMP_TextInfo textInfo = textArea.textInfo;
			Spots.Clear();
			float num = 0f;
			int num2 = 0;
			while (textInfo != null && num2 < textInfo.linkCount)
			{
				TMP_LinkInfo link = textInfo.linkInfo[num2];
				string linkID = ((TMP_LinkInfo)(ref link)).GetLinkID();
				if (linkID != null && linkID.StartsWith("psf:", StringComparison.Ordinal) && int.TryParse(linkID.Substring("psf:".Length), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && result >= 0 && result < Targets.Count && TryGetBounds(textInfo, link, out var min, out var max))
				{
					Spots.Add((result, min, max));
					num = Math.Max(num, max.x - min.x);
				}
				num2++;
			}
			int num3 = 0;
			foreach (var (num4, val, val2) in Spots)
			{
				while (Buttons.Count <= num4)
				{
					GameObject val3 = CreateButton(textArea, Buttons.Count);
					if (!Object.op_Implicit((Object)(object)val3))
					{
						return;
					}
					Buttons.Add(val3);
				}
				Place(Buttons[num4], val, new Vector2(val.x + num, val2.y), Targets[num4].Label);
				num3 = Math.Max(num3, num4 + 1);
			}
			for (int i = 0; i < Buttons.Count; i++)
			{
				if (i >= num3 && Object.op_Implicit((Object)(object)Buttons[i]) && Buttons[i].activeSelf)
				{
					Buttons[i].SetActive(false);
				}
			}
		}

		private static bool TryGetBounds(TMP_TextInfo info, TMP_LinkInfo link, out Vector2 min, out Vector2 max)
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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)
			min = new Vector2(float.MaxValue, float.MaxValue);
			max = new Vector2(float.MinValue, float.MinValue);
			int num = Math.Min(link.linkTextfirstCharacterIndex + link.linkTextLength, info.characterCount);
			for (int i = Math.Max(0, link.linkTextfirstCharacterIndex); i < num; i++)
			{
				TMP_CharacterInfo val = info.characterInfo[i];
				min = Vector2.Min(min, new Vector2(val.origin, val.descender));
				max = Vector2.Max(max, new Vector2(val.xAdvance, val.ascender));
			}
			if (max.x > min.x)
			{
				return max.y > min.y;
			}
			return false;
		}

		private static void Place(GameObject button, Vector2 min, Vector2 max, string label)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: 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_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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0053: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text componentInChildren = button.GetComponentInChildren<TMP_Text>();
			if (Object.op_Implicit((Object)(object)componentInChildren) && componentInChildren.text != label)
			{
				componentInChildren.text = label;
			}
			RectTransform val = (RectTransform)button.transform;
			Vector2 val2 = max - min + ButtonPadding;
			Vector3 val3 = Vector2.op_Implicit((min + max) / 2f + ButtonOffset);
			if (val.sizeDelta != val2)
			{
				val.sizeDelta = val2;
			}
			if (((Transform)val).localPosition != val3)
			{
				((Transform)val).localPosition = val3;
			}
			if (!button.activeSelf)
			{
				button.SetActive(true);
			}
		}

		private static GameObject? CreateButton(TMP_Text area, int index)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00c0: 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_00c3: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			Button val = (Object.op_Implicit((Object)(object)InventoryGui.instance) ? InventoryGui.instance.m_craftButton : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, area.transform);
			((Object)val2).name = "ProtectSpawnerFarms_ShowOnMap";
			UIGamePad[] componentsInChildren = val2.GetComponentsInChildren<UIGamePad>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			UITooltip[] componentsInChildren2 = val2.GetComponentsInChildren<UITooltip>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
			RectTransform val3 = (RectTransform)val2.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0.5f);
			val3.pivot = val4;
			Vector2 anchorMin = (val3.anchorMax = val4);
			val3.anchorMin = anchorMin;
			((Transform)val3).localRotation = Quaternion.identity;
			((Transform)val3).localScale = Vector3.one;
			TMP_Text[] componentsInChildren3 = val2.GetComponentsInChildren<TMP_Text>(true);
			for (int j = 0; j < componentsInChildren3.Length; j++)
			{
				if (j > 0)
				{
					((Component)componentsInChildren3[j]).gameObject.SetActive(false);
					continue;
				}
				componentsInChildren3[0].enableAutoSizing = true;
				componentsInChildren3[0].fontSizeMin = 10f;
				componentsInChildren3[0].fontSizeMax = area.fontSize;
			}
			Button component = val2.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				ShowOnMap(index);
			});
			((Selectable)component).interactable = true;
			val2.SetActive(false);
			return val2;
		}

		private static void ClearButtons()
		{
			foreach (GameObject button in Buttons)
			{
				if (Object.op_Implicit((Object)(object)button))
				{
					Object.Destroy((Object)(object)button);
				}
			}
			Buttons.Clear();
		}

		private static void ShowOnMap(int index)
		{
			if (index >= 0 && index < Targets.Count)
			{
				_pending = Targets[index];
				if (Object.op_Implicit((Object)(object)InventoryGui.instance))
				{
					InventoryGui.instance.Hide();
				}
			}
		}

		internal static void Update()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (_pending.HasValue && !InventoryGui.IsVisible())
			{
				MapTarget value = _pending.Value;
				_pending = null;
				if (Object.op_Implicit((Object)(object)Minimap.instance) && Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					Minimap.instance.DiscoverLocation(value.Position, (PinType)3, value.Name, true);
				}
			}
		}

		internal static void ClearSession()
		{
			Targets.Clear();
			ClearButtons();
			_pending = null;
		}

		private static string SharingLine()
		{
			switch (ProtectedSpawners.Mode)
			{
			case ShareMode.Server:
				return "Saved on the spawners themselves. The server lists every protected spawner in the world for everyone with the mod.";
			case ShareMode.Players:
				return "Saved on the spawners themselves. The server doesn't have the mod, so this lists the protected spawners you have been near on this server.";
			case ShareMode.Host:
				if (Object.op_Implicit((Object)(object)ZNet.instance) && (ZNet.instance.IsDedicated() || ZNet.instance.GetPeers().Count > 0 || ZNet.m_openServer))
				{
					return "Saved on the spawners in this world. Players who join with the mod see this list too.";
				}
				break;
			}
			return "Saved on the spawners in this world.";
		}

		private static string Who(string name)
		{
			if (!string.IsNullOrEmpty(name))
			{
				return Colored("#ffd27f", name);
			}
			return Colored("#a0a0a0", "someone");
		}

		private static string When(long ticks)
		{
			if (ticks > 0)
			{
				return Colored("#9fd8ff", TimeAgo.Format(ticks, DateTime.UtcNow.Ticks));
			}
			return Colored("#a0a0a0", "at an unknown time");
		}

		private static string Colored(string color, string text)
		{
			return "<color=" + color + ">" + text + "</color>";
		}
	}
	internal static class CompendiumCache
	{
		private const string FolderName = "CompendiumCache";

		private static string? _file;

		internal static string? FileFor()
		{
			World world = ZNet.World;
			if (world == null || world.m_uid == 0L)
			{
				return null;
			}
			string path = SafeFileName($"{world.m_name}_{world.m_uid}") + ".txt";
			return Path.Combine(Paths.ConfigPath, "JoksterCube.ProtectSpawnerFarms", "CompendiumCache", path);
		}

		internal static List<SpawnerRecord> Load(string file)
		{
			_file = file;
			try
			{
				if (!File.Exists(file))
				{
					return new List<SpawnerRecord>();
				}
				List<SpawnerRecord> list = (from record in (from line in File.ReadAllLines(file)
						where !line.StartsWith("#", StringComparison.Ordinal)
						select line).Select(SpawnerRecords.Parse)
					where record?.IsProtected ?? false
					select record).ToList();
				Plugin.ModLogger.LogInfo((object)$"Remembered {list.Count} protected spawners on this server.");
				return list;
			}
			catch (Exception ex)
			{
				Plugin.ModLogger.LogError((object)("Could not read " + file + ": " + ex.Message));
				return new List<SpawnerRecord>();
			}
		}

		internal static void Save(IEnumerable<SpawnerRecord> records)
		{
			if (_file == null)
			{
				return;
			}
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(_file));
				string[] first = new string[2] { "# Protected spawners seen on this server, for the Compendium only. Protection itself is saved on the spawners.", "# key (prefab@x,y,z), protected, protected by, protector id, protected at, guarded by, last guarded, last blocked hit. Times are UTC ticks." };
				File.WriteAllLines(_file, first.Concat(records.OrderBy<SpawnerRecord, string>((SpawnerRecord record) => record.Key, StringComparer.Ordinal).Select(SpawnerRecords.Format)));
			}
			catch (Exception ex)
			{
				Plugin.ModLogger.LogError((object)("Could not save " + _file + ": " + ex.Message));
			}
		}

		internal static void ClearSession()
		{
			_file = null;
		}

		private static string SafeFileName(string name)
		{
			char[] invalid = Path.GetInvalidFileNameChars();
			return new string(name.Select((char c) => (!invalid.Contains(c)) ? c : '_').ToArray());
		}
	}
	internal static class HighlightingStatus
	{
		private static StatusEffect? _effect;

		internal static void Set(Player? player, bool active)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return;
			}
			SEMan sEMan = ((Character)player).GetSEMan();
			StatusEffect val = ProtectingStatus.Effect(ref _effect, "SE_ProtectSpawnerFarms_Highlighting", "Highlighting spawner", "The nearest spawner is painted in a pulsing color you can see through walls.", StatusIcons.Highlighting);
			bool flag = sEMan.HaveStatusEffect(val.NameHash());
			if (active != flag)
			{
				if (active)
				{
					sEMan.AddStatusEffect(val, false, 0, 0f, (short)(-1));
				}
				else
				{
					sEMan.RemoveStatusEffect(val.NameHash(), true);
				}
			}
		}
	}
	internal static class IconPaint
	{
		internal const int Size = 64;

		internal static void Glow(IconCanvas canvas, float cx, float cy, float radius, Color color, float strength)
		{
			//IL_0015: 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)
			canvas.Paint(delegate(float x, float y)
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
				return new Color(color.r, color.g, color.b, Mathf.Pow(Mathf.Clamp01(1f - num / radius), 2f) * strength);
			});
		}

		internal static void Shadow(IconCanvas canvas, Func<float, float, float> shape, float strength)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					array[i * 64 + j] = Mathf.Clamp01(0.5f - shape((float)j + 0.5f, (float)i + 0.5f));
				}
			}
			float[] array2 = IconCanvas.Blur(array, 2);
			for (int k = 64; k < array2.Length; k++)
			{
				canvas.Blend(k, new Color(0f, 0f, 0f, array2[k - 64] * strength));
			}
		}

		internal static void GlowLine(IconCanvas canvas, Func<float, float, float> line, Color glow, Color core, float width, float strength)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			canvas.Paint(delegate(float x, float y)
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				float num = line(x, y);
				float num2 = Mathf.Pow(Mathf.Clamp01(1f - Mathf.Max(num, 0f) / width), 2f) * strength;
				return IconCanvas.Over(new Color(glow.r, glow.g, glow.b, num2), new Color(core.r, core.g, core.b, Mathf.Clamp01(0.5f - num)));
			});
		}

		internal static void Fill(IconCanvas canvas, Func<float, float, float> shape, Func<float, float, float, Color> color)
		{
			canvas.Paint(delegate(float x, float y)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: 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_0016: Unknown result type (might be due to invalid IL or missing references)
				float num = shape(x, y);
				if (num > 0.5f)
				{
					return Color.clear;
				}
				Color result = color(x, y, 0f - num);
				result.a *= Mathf.Clamp01(0.5f - num);
				return result;
			});
		}

		internal static float Circle(float x, float y, float cx, float cy, float r)
		{
			return Mathf.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) - r;
		}

		internal static float Ellipse(float x, float y, float cx, float cy, float rx, float ry)
		{
			float num = (x - cx) / rx;
			float num2 = (y - cy) / ry;
			return (Mathf.Sqrt(num * num + num2 * num2) - 1f) * Mathf.Min(rx, ry);
		}

		internal static float Box(float x, float y, float left, float top, float right, float bottom)
		{
			return Mathf.Max(Mathf.Max(left - x, x - right), Mathf.Max(top - y, y - bottom));
		}

		internal static float Capsule(float x, float y, float ax, float ay, float bx, float by, float r)
		{
			float num = bx - ax;
			float num2 = by - ay;
			float num3 = num * num + num2 * num2;
			float num4 = ((num3 > 0f) ? Mathf.Clamp01(((x - ax) * num + (y - ay) * num2) / num3) : 0f);
			float num5 = ax + num4 * num - x;
			float num6 = ay + num4 * num2 - y;
			return Mathf.Sqrt(num5 * num5 + num6 * num6) - r;
		}
	}
	internal sealed class IconCanvas
	{
		private const int Size = 64;

		private readonly Color[] _pixels = (Color[])(object)new Color[4096];

		internal Color[] Colors => _pixels;

		internal void Blend(int index, Color color)
		{
			//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_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)
			_pixels[index] = Over(_pixels[index], color);
		}

		internal void Paint(Func<float, float, Color> shade)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					Blend(i * 64 + j, shade((float)j + 0.5f, (float)i + 0.5f));
				}
			}
		}

		internal static Color Over(Color below, Color above)
		{
			//IL_0000: 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_0011: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			float num = above.a + below.a * (1f - above.a);
			if (num <= 0f)
			{
				return Color.clear;
			}
			float num2 = below.a * (1f - above.a);
			return new Color((above.r * above.a + below.r * num2) / num, (above.g * above.a + below.g * num2) / num, (above.b * above.a + below.b * num2) / num, num);
		}

		internal static float[] Blur(float[] values, int radius)
		{
			float[] array = values;
			for (int i = 0; i < 2; i++)
			{
				float[] array2 = new float[array.Length];
				float[] array3 = new float[array.Length];
				for (int j = 0; j < 64; j++)
				{
					for (int k = 0; k < 64; k++)
					{
						float num = 0f;
						for (int l = -radius; l <= radius; l++)
						{
							num += array[j * 64 + Mathf.Clamp(k + l, 0, 63)];
						}
						array2[j * 64 + k] = num / (float)(2 * radius + 1);
					}
				}
				for (int m = 0; m < 64; m++)
				{
					for (int n = 0; n < 64; n++)
					{
						float num2 = 0f;
						for (int num3 = -radius; num3 <= radius; num3++)
						{
							num2 += array2[Mathf.Clamp(m + num3, 0, 63) * 64 + n];
						}
						array3[m * 64 + n] = num2 / (float)(2 * radius + 1);
					}
				}
				array = array3;
			}
			return array;
		}

		internal Sprite ToSprite(string name)
		{
			//IL_003a: 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_0046: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[_pixels.Length];
			for (int i = 0; i < 64; i++)
			{
				Array.Copy(_pixels, i * 64, array, (63 - i) * 64, 64);
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = name,
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			val.SetPixels(array);
			val.Apply(false, true);
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).name = name;
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}
	}
	internal static class ProtectedMarker
	{
		private const string NamePrefix = "ProtectSpawnerFarms_";

		private const string BubblePrefab = "vfx_StaffShield";

		private const string SphereName = "Sphere";

		private const float BubbleDiameter = 2.5f;

		private const float Padding = 0.5f;

		private const float MinRadius = 1.5f;

		private const float MaxRadius = 12f;

		private const float SpinDegreesPerSecond = 12f;

		private static bool _bubbleMissing;

		private static bool _shaderMissing;

		private static Shader? _shader;

		private static readonly Dictionary<(Color32 Color, int Opacity, Texture? Texture), Material> Materials = new Dictionary<(Color32, int, Texture), Material>();

		internal static void Update(SpawnerRegistry.Spawner spawner, bool isProtected)
		{
			//IL_0022: 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)
			bool flag = isProtected && PluginConfig.ShowShieldBubble.IsOn();
			if (Object.op_Implicit((Object)(object)spawner.Bubble) && (!flag || spawner.BubbleColor != PluginConfig.ShieldBubbleColor.Value || spawner.BubbleOpacity != PluginConfig.ShieldBubbleOpacity.Value))
			{
				Object.Destroy((Object)(object)spawner.Bubble);
				spawner.Bubble = null;
			}
			if (flag && !Object.op_Implicit((Object)(object)spawner.Bubble))
			{
				spawner.Bubble = CreateBubble(spawner);
			}
		}

		internal static bool IsModVisual(Transform transform, Transform spawner)
		{
			Transform val = transform;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)spawner)
			{
				if (((Object)val).name.StartsWith("ProtectSpawnerFarms_", StringComparison.Ordinal))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		internal static void Dispose()
		{
			foreach (SpawnerRegistry.Spawner item in SpawnerRegistry.All)
			{
				if (Object.op_Implicit((Object)(object)item.Bubble))
				{
					Object.Destroy((Object)(object)item.Bubble);
				}
			}
			foreach (Material value in Materials.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			Materials.Clear();
		}

		private static GameObject? CreateBubble(SpawnerRegistry.Spawner spawner)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			if (_bubbleMissing || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return null;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("vfx_StaffShield");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				_bubbleMissing = true;
				Plugin.ModLogger.LogWarning((object)"Staff of Protection bubble not found, protected spawners get no bubble.");
				return null;
			}
			Footprint(((Component)spawner.Destructible).gameObject, out var center, out var radius);
			ZNetView.m_forceDisableInit = true;
			GameObject val;
			try
			{
				val = Object.Instantiate<GameObject>(prefab, center, Quaternion.identity);
			}
			finally
			{
				ZNetView.m_forceDisableInit = false;
			}
			((Object)val).name = "ProtectSpawnerFarms_Bubble";
			val.transform.SetParent(((Component)spawner.Destructible).transform, true);
			float num = radius * 2f / 2.5f;
			Vector3 lossyScale = ((Component)spawner.Destructible).transform.lossyScale;
			val.transform.localScale = new Vector3(num / Mathf.Max(lossyScale.x, 0.01f), num / Mathf.Max(lossyScale.y, 0.01f), num / Mathf.Max(lossyScale.z, 0.01f));
			spawner.BubbleColor = PluginConfig.ShieldBubbleColor.Value;
			spawner.BubbleOpacity = PluginConfig.ShieldBubbleOpacity.Value;
			Restyle(val, spawner.BubbleColor, spawner.BubbleOpacity);
			return val;
		}

		private static void Restyle(GameObject bubble, Color color, float opacity)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = bubble.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!(((Object)val).name != "Sphere") && val is MeshRenderer)
				{
					Material val2 = CreateMaterial(val.sharedMaterial, color, opacity);
					if (Object.op_Implicit((Object)(object)val2))
					{
						val.sharedMaterial = val2;
					}
					((Component)val).gameObject.AddComponent<BubbleSpin>().DegreesPerSecond = 12f;
				}
			}
			Light[] componentsInChildren2 = bubble.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].color = color;
			}
		}

		private static Material? CreateMaterial(Material? original, Color color, float opacity)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (_shaderMissing)
			{
				return null;
			}
			if (_shader == null)
			{
				_shader = Shader.Find("UI/Default");
			}
			if (!Object.op_Implicit((Object)(object)_shader))
			{
				_shaderMissing = true;
				Plugin.ModLogger.LogWarning((object)"UI/Default shader not found, the shield bubble keeps the staff's look.");
				return null;
			}
			Texture val = ((Object.op_Implicit((Object)(object)original) && original.HasProperty("_MainTex")) ? original.mainTexture : null);
			(Color32, int, Texture) key = (Color32.op_Implicit(color), Mathf.RoundToInt(Mathf.Clamp01(opacity) * 255f), val);
			if (Materials.TryGetValue(key, out Material value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			Material val2 = new Material(_shader)
			{
				name = "ProtectSpawnerFarms_BubbleMaterial",
				hideFlags = (HideFlags)52
			};
			if (Object.op_Implicit((Object)(object)val))
			{
				val2.mainTexture = val;
			}
			color.a = Mathf.Clamp01(opacity);
			val2.color = color;
			val2.SetFloat("unity_GUIZTestMode", 4f);
			Materials[key] = val2;
			return val2;
		}

		private static void Footprint(GameObject spawner, out Vector3 center, out float radius)
		{
			//IL_000f: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			bool found = false;
			Bounds bounds = default(Bounds);
			Renderer[] componentsInChildren = spawner.GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				bool flag = ((val is MeshRenderer || val is SkinnedMeshRenderer) ? true : false);
				if (flag && !IsModVisual(((Component)val).transform, spawner.transform))
				{
					Add(val.bounds);
				}
			}
			Collider[] componentsInChildren2 = spawner.GetComponentsInChildren<Collider>();
			foreach (Collider val2 in componentsInChildren2)
			{
				if (!val2.isTrigger && !IsModVisual(((Component)val2).transform, spawner.transform))
				{
					Add(val2.bounds);
				}
			}
			center = (found ? ((Bounds)(ref bounds)).center : (spawner.transform.position + Vector3.up));
			float num = (found ? (Mathf.Max(new float[3]
			{
				((Bounds)(ref bounds)).extents.x,
				((Bounds)(ref bounds)).extents.y,
				((Bounds)(ref bounds)).extents.z
			}) + 0.5f) : 2f);
			radius = Mathf.Clamp(num, 1.5f, 12f);
			void Add(Bounds part)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				if (!found)
				{
					bounds = part;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(part);
				}
				found = true;
			}
		}
	}
	internal sealed class BubbleSpin : MonoBehaviour
	{
		internal float DegreesPerSecond;

		private void Update()
		{
			((Component)this).transform.Rotate(0f, DegreesPerSecond * Time.deltaTime, 0f, (Space)0);
		}
	}
	internal enum ShareMode
	{
		Alone,
		Host,
		Server,
		Players
	}
	internal static class ProtectedSpawners
	{
		private static readonly SpawnerRecords Records = new SpawnerRecords();

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

		private static readonly List<KeyValuePair<string, ZDOID>> Known = new List<KeyValuePair<string, ZDOID>>();

		private static bool _scanned;

		private static bool _cacheLoaded;

		private static bool _cacheDirty;

		private static bool _cacheOff;

		internal static int Revision { get; private set; }

		internal static bool ListReceived { get; private set; }

		internal static ShareMode Mode
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)ZNet.instance))
				{
					return ShareMode.Alone;
				}
				if (ZNet.instance.IsServer())
				{
					return ShareMode.Host;
				}
				if (!RpcHandlers.ServerHasMod)
				{
					return ShareMode.Players;
				}
				return ShareMode.Server;
			}
		}

		internal static IEnumerable<SpawnerRecord> All => Records.All;

		internal static IEnumerable<ZDOID> TrackedIds => Ids.Values;

		internal static long Now => DateTime.UtcNow.Ticks;

		internal static bool ServerProtects
		{
			get
			{
				if (Mode != ShareMode.Server)
				{
					return Mode == ShareMode.Host;
				}
				return true;
			}
		}

		internal static string LocalPlayerName
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)Game.instance) || Game.instance.GetPlayerProfile() == null)
				{
					return "?";
				}
				return Game.instance.GetPlayerProfile().GetName();
			}
		}

		internal static string LocalPlayerId
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)Game.instance) || Game.instance.GetPlayerProfile() == null)
				{
					return string.Empty;
				}
				return Game.instance.GetPlayerProfile().GetPlayerID().ToString(CultureInfo.InvariantCulture);
			}
		}

		internal static SpawnerRecord? Note(ZDO zdo, string key)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			SpawnerRecord spawnerRecord = SpawnerData.Read(zdo, key);
			if (spawnerRecord.IsProtected)
			{
				Ids[key] = zdo.m_uid;
			}
			else
			{
				Ids.Remove(key);
			}
			return Changed(spawnerRecord);
		}

		internal static List<SpawnerRecord> Refresh()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			List<SpawnerRecord> list = new List<SpawnerRecord>();
			if (ZDOMan.instance == null || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return list;
			}
			bool flag = Mode == ShareMode.Host;
			if (flag && !_scanned)
			{
				_scanned = true;
				Scan(list);
				return list;
			}
			Known.Clear();
			Known.AddRange(Ids);
			foreach (KeyValuePair<string, ZDOID> item in Known)
			{
				ZDO zDO = ZDOMan.instance.GetZDO(item.Value);
				if (zDO != null)
				{
					SpawnerRecord spawnerRecord = Note(zDO, item.Key);
					if (spawnerRecord != null)
					{
						list.Add(spawnerRecord);
					}
				}
				else if (flag)
				{
					Ids.Remove(item.Key);
					SpawnerRecord spawnerRecord2 = Changed(new SpawnerRecord(item.Key)
					{
						IsProtected = false
					});
					if (spawnerRecord2 != null)
					{
						list.Add(spawnerRecord2);
					}
				}
			}
			Known.Clear();
			if (!flag)
			{
				UpdateCache();
			}
			return list;
		}

		private static void UpdateCache()
		{
			if (_cacheOff)
			{
				return;
			}
			if (!_cacheLoaded)
			{
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return;
				}
				string text = CompendiumCache.FileFor();
				if (text == null)
				{
					return;
				}
				_cacheLoaded = true;
				foreach (SpawnerRecord item in CompendiumCache.Load(text))
				{
					if (!Records.TryGet(item.Key, out SpawnerRecord _))
					{
						Records.Set(item);
					}
				}
				Revision++;
			}
			SaveCache();
		}

		private static void SaveCache()
		{
			if (_cacheLoaded && _cacheDirty && !_cacheOff)
			{
				_cacheDirty = false;
				CompendiumCache.Save(Records.All);
			}
		}

		private static void Scan(List<SpawnerRecord> changes)
		{
			foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
			{
				if (!SpawnerData.IsProtected(value))
				{
					continue;
				}
				string text = SpawnerRegistry.KeyOf(value);
				if (text != null)
				{
					SpawnerRecord spawnerRecord = Note(value, text);
					if (spawnerRecord != null)
					{
						changes.Add(spawnerRecord);
					}
				}
			}
			Plugin.ModLogger.LogInfo((object)$"Found {Records.Count} protected spawners in this world.");
		}

		internal static void Receive(IEnumerable<SpawnerRecord> records, bool fullList)
		{
			_cacheOff = true;
			if (fullList)
			{
				Records.Clear();
			}
			foreach (SpawnerRecord record in records)
			{
				Records.Set(record);
			}
			if (fullList)
			{
				ListReceived = true;
			}
			Revision++;
		}

		private static SpawnerRecord? Changed(SpawnerRecord record)
		{
			if (!Records.Set(record))
			{
				return null;
			}
			Revision++;
			_cacheDirty = true;
			return record;
		}

		internal static void ClearSession()
		{
			SaveCache();
			CompendiumCache.ClearSession();
			_cacheLoaded = (_cacheDirty = (_cacheOff = false));
			Records.Clear();
			Ids.Clear();
			Known.Clear();
			_scanned = false;
			ListReceived = false;
			Revision++;
		}
	}
	internal static class ProtectingStatus
	{
		private static StatusEffect? _protecting;

		private static StatusEffect? _serverProtected;

		internal static void Set(Player? player, bool active, bool serverProtects)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return;
			}
			SEMan sEMan = ((Character)player).GetSEMan();
			StatusEffect val = (serverProtects ? Effect(ref _serverProtected, "SE_ProtectSpawnerFarms_ServerProtected", "Protected spawner nearby", "The server keeps this spawner safe from all damage.", StatusIcons.ServerProtected) : Effect(ref _protecting, "SE_ProtectSpawnerFarms_Protecting", "Protecting spawner", "A protected spawner is near. Damage to it is blocked while you stay close.", StatusIcons.Protecting));
			StatusEffect val2 = (serverProtects ? _protecting : _serverProtected);
			if (Object.op_Implicit((Object)(object)val2) && sEMan.HaveStatusEffect(val2.NameHash()))
			{
				sEMan.RemoveStatusEffect(val2.NameHash(), true);
			}
			bool flag = sEMan.HaveStatusEffect(val.NameHash());
			if (active != flag)
			{
				if (active)
				{
					sEMan.AddStatusEffect(val, false, 0, 0f, (short)(-1));
				}
				else
				{
					sEMan.RemoveStatusEffect(val.NameHash(), true);
				}
			}
		}

		internal static StatusEffect Effect(ref StatusEffect? effect, string name, string displayName, string tooltip, Func<Sprite> icon)
		{
			if (!Object.op_Implicit((Object)(object)effect))
			{
				effect = ScriptableObject.CreateInstance<StatusEffect>();
				((Object)effect).name = name;
				effect.m_name = displayName;
				effect.m_tooltip = tooltip;
				effect.m_ttl = 0f;
				((Object)effect).hideFlags = (HideFlags)61;
			}
			if (!Object.op_Implicit((Object)(object)effect.m_icon))
			{
				effect.m_icon = icon();
			}
			return effect;
		}
	}
	internal enum ProtectionPermission
	{
		Anyone,
		AdminsOnly,
		ProtectorOrAdmin
	}
	internal static class ProtectionPermissions
	{
		internal enum Verdict
		{
			Allowed,
			AdminsOnly,
			ProtectorOnly
		}

		internal static Verdict Check(ProtectionPermission permission, bool protect, string protectorId, string requesterId, bool isAdmin)
		{
			if (!isAdmin)
			{
				switch (permission)
				{
				case ProtectionPermission.Anyone:
					break;
				case ProtectionPermission.AdminsOnly:
					return Verdict.AdminsOnly;
				default:
					if (protect || string.IsNullOrEmpty(protectorId) || protectorId == requesterId)
					{
						return Verdict.Allowed;
					}
					return Verdict.ProtectorOnly;
				}
			}
			return Verdict.Allowed;
		}
	}
	internal static class ServerGuard
	{
		private const string Feature = "Server protection";

		private const float MinCheckInterval = 0.1f;

		private const float CheckInterval = 1f;

		internal static readonly int DestroyMethod = StringExtensionMethods.GetStableHashCode("DestroyZDO");

		private static readonly List<ZDOID> Kept = new List<ZDOID>();

		private static readonly List<ZDOID> Destroyed = new List<ZDOID>();

		private static float _lastCheck = -1f;

		private static bool Active
		{
			get
			{
				if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && ZDOMan.instance != null)
				{
					return Object.op_Implicit((Object)(object)ZNetScene.instance);
				}
				return false;
			}
		}

		internal static void Update()
		{
			if (Time.time - _lastCheck >= 1f)
			{
				Run();
			}
		}

		internal static void OnDataReceived()
		{
			if (Time.time - _lastCheck >= 0.1f)
			{
				Run();
			}
		}

		internal static void ClearSession()
		{
			_lastCheck = -1f;
		}

		internal static bool FilterDestroy(RoutedRPCData data)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			if (data.m_methodHash != DestroyMethod || !((ZDOID)(ref data.m_targetZDO)).IsNone() || PatchGuard.IsDisabled("Server protection") || !Active)
			{
				return true;
			}
			try
			{
				data.m_parameters.SetPos(0);
				ZPackage val = data.m_parameters.ReadPackage();
				data.m_parameters.SetPos(0);
				Kept.Clear();
				Destroyed.Clear();
				int num = val.ReadInt();
				for (int i = 0; i < num; i++)
				{
					ZDOID val2 = val.ReadZDOID();
					if (SpawnerData.IsProtected(ZDOMan.instance.GetZDO(val2)))
					{
						Kept.Add(val2);
					}
					else
					{
						Destroyed.Add(val2);
					}
				}
				if (Kept.Count == 0)
				{
					return true;
				}
				foreach (ZDOID item in Kept)
				{
					Restore(ZDOMan.instance.GetZDO(item));
				}
				Plugin.ModLogger.LogInfo((object)$"Refused to destroy {Kept.Count} protected spawner(s), from player {data.m_senderPeerID}.");
				if (Destroyed.Count == 0)
				{
					return false;
				}
				ZPackage val3 = new ZPackage();
				val3.Write(Destroyed.Count);
				foreach (ZDOID item2 in Destroyed)
				{
					val3.Write(item2);
				}
				ZPackage val4 = new ZPackage();
				val4.Write(val3);
				val4.SetPos(0);
				data.m_parameters = val4;
				return true;
			}
			catch (Exception exception)
			{
				PatchGuard.Fail("Server protection", exception);
				data.m_parameters.SetPos(0);
				return true;
			}
			finally
			{
				Kept.Clear();
				Destroyed.Clear();
			}
		}

		private static void Run()
		{
			if (PatchGuard.IsDisabled("Server protection") || !Active)
			{
				return;
			}
			_lastCheck = Time.time;
			try
			{
				Check();
			}
			catch (Exception exception)
			{
				PatchGuard.Fail("Server protection", exception);
			}
		}

		private static void Check()
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			foreach (ZDOID trackedId in ProtectedSpawners.TrackedIds)
			{
				ZDO zDO = ZDOMan.instance.GetZDO(trackedId);
				if (zDO != null && SpawnerData.IsProtected(zDO))
				{
					float num = TargetHealth(zDO);
					if (!(num <= 0f) && !(zDO.GetFloat(ZDOVars.s_health, SpawnerRegistry.DefaultHealth(zDO.GetPrefab())) >= num))
					{
						zDO.Set(ZDOVars.s_health, num);
						SpawnerData.Written(zDO);
					}
				}
			}
		}

		private static void Restore(ZDO zdo)
		{
			float num = TargetHealth(zdo);
			float num2 = zdo.GetFloat(ZDOVars.s_health, SpawnerRegistry.DefaultHealth(zdo.GetPrefab()));
			if (num > 0f && num2 < num)
			{
				zdo.Set(ZDOVars.s_health, num);
			}
			zdo.DataRevision += 100;
		}

		private static float TargetHealth(ZDO zdo)
		{
			return Mathf.Max(PluginConfig.BoostedHealth.Value, SpawnerRegistry.DefaultHealth(zdo.GetPrefab()));
		}
	}
	internal static class SessionState
	{
		internal static void Clear()
		{
			SpawnerHighlight.Stop();
			SpawnerRegistry.Clear();
			SpawnerButtons.ClearSession();
			Compendium.ClearSession();
			ServerGuard.ClearSession();
			SpawnerProtection.ClearSession();
			ProtectionSync.ClearSession();
			ProtectedSpawners.ClearSession();
			RpcHandlers.ResetServerVersionCheck();
		}
	}
	internal static class SpawnerButtons
	{
		private sealed class SpawnerButton(Image icon, GameObject cross, UITooltip? tooltip)
		{
			internal Image Icon { get; } = icon;

			internal GameObject Cross { get; } = cross;

			internal UITooltip? Tooltip { get; } = tooltip;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Func<Sprite> <0>__Shield;

			public static Func<Sprite> <1>__Eye;

			public static UnityAction <2>__OnProtect;

			public static UnityAction <3>__OnHighlight;
		}

		private const float ButtonSize = 52f;

		private const float ButtonGap = 8f;

		private const float Padding = 12f;

		private const float PanelGap = 2f;

		private const float IconPadding = 7f;

		private const float SlideSeconds = 0.18f;

		private const float CrossThickness = 4f;

		private const float CrossInset = 13f;

		private const string FlapSprite = "woodpanel_flik";

		private static readonly Color FallbackPanelTint = new Color(0.45f, 0.38f, 0.34f, 1f);

		private static readonly Color CrossColor = new Color(0.9f, 0.15f, 0.1f, 1f);

		private static readonly Color CrossEdge = new Color(0.1f, 0.05f, 0.03f, 0.85f);

		private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

		private static RectTransform? _root;

		private static RectTransform? _anchorPanel;

		private static SpawnerButton? _protect;

		private static SpawnerButton? _highlight;

		private static SpawnerRegistry.Spawner? _closest;

		private static float _shown;

		internal static void Update(InventoryGui gui)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			SpawnerRegistry.Spawner spawner = ((Object.op_Implicit((Object)(object)localPlayer) && InventoryGui.IsVisible()) ? SpawnerRegistry.Closest(((Component)localPlayer).transform.position, PluginConfig.ActionDistance.Value) : null);
			if (spawner != null)
			{
				_closest = spawner;
			}
			if (!Object.op_Implicit((Object)(object)_root))
			{
				if (spawner == null)
				{
					return;
				}
				Create(gui);
				if (!Object.op_Implicit((Object)(object)_root))
				{
					return;
				}
			}
			float num = ((spawner != null) ? 1f : 0f);
			_shown = Mathf.MoveTowards(_shown, num, Time.unscaledDeltaTime / 0.18f);
			bool flag = _shown > 0f;
			if (((Component)_root).gameObject.activeSelf != flag)
			{
				((Component)_root).gameObject.SetActive(flag);
			}
			if (flag)
			{
				Place();
				if (_closest != null && _closest.IsAlive)
				{
					string arg = Vector3.Distance(Object.op_Implicit((Object)(object)localPlayer) ? ((Component)localPlayer).transform.position : _closest.Position, _closest.Position).ToString("0");
					bool flag2 = SpawnerData.IsProtected(_closest.View.GetZDO());
					SetState(_protect, flag2, ButtonIcons.Shield, flag2 ? "Unprotect spawner" : "Protect spawner", string.Format(flag2 ? "{0}, {1} m away" : "{0}, {1} m away", _closest.Name, arg));
					bool isEnabled = SpawnerHighlight.IsEnabled;
					SetState(_highlight, isEnabled, ButtonIcons.Eye, isEnabled ? "Stop highlighting" : "Highlight nearest spawner", string.Format(isEnabled ? "{0}, {1} m away" : "{0}, {1} m away", _closest.Name, arg));
				}
			}
		}

		private static void SetState(SpawnerButton button, bool on, Func<Sprite> icon, string topic, string text)
		{
			if (!Object.op_Implicit((Object)(object)button.Icon.sprite))
			{
				button.Icon.sprite = icon();
			}
			if (button.Cross.activeSelf == on)
			{
				button.Cross.SetActive(!on);
			}
			if (Object.op_Implicit((Object)(object)button.Tooltip) && (!(button.Tooltip.m_topic == topic) || !(button.Tooltip.m_text == text)))
			{
				button.Tooltip.m_topic = topic;
				button.Tooltip.m_text = text;
			}
		}

		private static void Place()
		{
			//IL_0022: 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_0032: 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_004c: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0081: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_anchorPanel))
			{
				_anchorPanel.GetWorldCorners(Corners);
				Vector3 val = (Corners[0] + Corners[1]) / 2f;
				Vector3 val2 = ((Transform)_root).parent.InverseTransformPoint(val);
				float num = _shown * _shown * (3f - 2f * _shown);
				float x = val2.x;
				Rect rect = _root.rect;
				float num2 = x + ((Rect)(ref rect)).width;
				float num3 = val2.x - 2f;
				((Transform)_root).localPosition = new Vector3(Mathf.Lerp(num2, num3, num), val2.y, 0f);
			}
		}

		private static void OnProtect()
		{
			if (_closest != null && _closest.IsAlive)
			{
				SpawnerProtection.Toggle(_closest);
			}
		}

		private static void OnHighlight()
		{
			SpawnerHighlight.Toggle();
		}

		private static void Create(InventoryGui gui)
		{
			//IL_0030: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			_anchorPanel = PlayerPanel(gui);
			if (Object.op_Implicit((Object)(object)_anchorPanel))
			{
				GameObject val = new GameObject("ProtectSpawnerFarms_Buttons", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(((Transform)_anchorPanel).parent, false);
				val.transform.SetSiblingIndex(((Transform)_anchorPanel).GetSiblingIndex());
				_root = (RectTransform)val.transform;
				RectTransform? root = _root;
				RectTransform? root2 = _root;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 0.5f);
				root2.anchorMax = val2;
				root.anchorMin = val2;
				_root.pivot = new Vector2(1f, 0.5f);
				_root.sizeDelta = new Vector2(76f, 136f);
				((Transform)_root).localScale = Vector3.one;
				CreateBackground(gui, _root);
				float num = 30f;
				RectTransform? root3 = _root;
				object obj = <>O.<2>__OnProtect;
				if (obj == null)
				{
					UnityAction val3 = OnProtect;
					<>O.<2>__OnProtect = val3;
					obj = (object)val3;
				}
				_protect = CreateButton(gui, root3, "Protect", num, (UnityAction)obj);
				RectTransform? root4 = _root;
				float y = 0f - num;
				object obj2 = <>O.<3>__OnHighlight;
				if (obj2 == null)
				{
					UnityAction val4 = OnHighlight;
					<>O.<3>__OnHighlight = val4;
					obj2 = (object)val4;
				}
				_highlight = CreateButton(gui, root4, "Highlight", y, (UnityAction)obj2);
				_shown = 0f;
				val.SetActive(false);
			}
		}

		private static RectTransform? PlayerPanel(InventoryGui gui)
		{
			if (!Object.op_Implicit((Object)(object)gui.m_playerName))
			{
				return null;
			}
			Transform val = gui.m_playerName.transform;
			while (Object.op_Implicit((Object)(object)val.parent) && (Object)(object)val.parent != (Object)(object)gui.m_inventoryRoot)
			{
				val = val.parent;
			}
			if (!Object.op_Implicit((Object)(object)val.parent))
			{
				return null;
			}
			return (RectTransform?)(object)((val is RectTransform) ? val : null);
		}

		private static void CreateBackground(InventoryGui gui, RectTransform root)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Child((Transform)(object)root, "Background", 0f);
			((Transform)obj).localScale = new Vector3(-1f, 1f, 1f);
			Image val = ((Component)obj).gameObject.AddComponent<Image>();
			((Graphic)val).raycastTarget = true;
			Image val2 = null;
			if (Object.op_Implicit((Object)(object)gui.m_repairPanel))
			{
				Image[] componentsInChildren = ((Component)gui.m_repairPanel).GetComponentsInChildren<Image>(true);
				foreach (Image val3 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val3.sprite) && ((Object)val3.sprite).name.StartsWith("woodpanel_flik", StringComparison.Ordinal))
					{
						val2 = val3;
						break;
					}
				}
			}
			val.sprite = FindSprite("woodpanel_flik") ?? ((val2 != null) ? val2.sprite : null);
			val.type = (Type)((Object.op_Implicit((Object)(object)val.sprite) && val.sprite.border != Vector4.zero) ? 1 : 0);
			((Graphic)val).color = (Object.op_Implicit((Object)(object)val2) ? ((Graphic)val2).color : FallbackPanelTint);
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Graphic)val).material = ((Graphic)val2).material;
			}
		}

		private static Sprite? FindSprite(string name)
		{
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private static SpawnerButton CreateButton(InventoryGui gui, RectTransform panel, string name, float y, UnityAction onClick)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_01f3: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due