Decompiled source of Where Is My Queen v1.0.0

plugins/WhereIsMyQueen.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using WhereIsMyQueen.Core;
using WhereIsMyQueen.Dev;
using WhereIsMyQueen.Gameplay;
using WhereIsMyQueen.Visual;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WhereIsMyQueen
{
	public static class Cfg
	{
		public static ConfigEntry<int> ChanceOneIn;

		public static ConfigEntry<bool> ScaleWithHoney;

		public static ConfigEntry<float> SetQueenBonus;

		public static ConfigEntry<float> WaxPerFullHive;

		public static ConfigEntry<int> WildHiveWaxMin;

		public static ConfigEntry<int> WildHiveWaxMax;

		public static ConfigEntry<bool> CalmBees;

		public static readonly Dictionary<string, ConfigEntry<string>> Recipes = new Dictionary<string, ConfigEntry<string>>();

		public static ConfigEntry<bool> ShowMessage;

		public static void Bind(ConfigFile c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			ChanceOneIn = c.Bind<int>("1 - Queens", "ChanceOneIn", 30, new ConfigDescription("Harvesting a full beehive gives a young queen bee with a chance of 1 in this number: 30 means about one full hive in thirty. 1 gives a queen with every full hive, 0 turns queens off.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100000), new object[1] { val }));
			ScaleWithHoney = c.Bind<bool>("1 - Queens", "ScaleWithHoney", true, new ConfigDescription("A hive that is only partly full has a smaller chance in proportion to its honey: half full is half the chance. So harvesting often gives no more queens than harvesting full hives. Off: every harvest has the full chance, however little honey it gives.", (AcceptableValueBase)null, new object[1] { val }));
			SetQueenBonus = c.Bind<float>("1 - Queens", "BeekeeperSetBonus", 2f, new ConfigDescription("A harvester who wears the whole beekeeper set (hat, smock, trousers) finds a queen this many times as often: 2 turns 1 in 30 into 1 in 15. 1 gives no bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1] { val }));
			WaxPerFullHive = c.Bind<float>("2 - Beeswax", "WaxPerFullHive", 2f, new ConfigDescription("Beeswax a full beehive gives with its honey. A hive that is only partly full gives its share of it (half full: half), with the part below one as a chance. 0 turns the wax off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { val }));
			WildHiveWaxMin = c.Bind<int>("2 - Beeswax", "WildHiveWaxMin", 1, new ConfigDescription("Least beeswax a wild beehive drops when you knock it down, on top of its honey and queen.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), new object[1] { val }));
			WildHiveWaxMax = c.Bind<int>("2 - Beeswax", "WildHiveWaxMax", 2, new ConfigDescription("Most beeswax a wild beehive drops when you knock it down.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), new object[1] { val }));
			CalmBees = c.Bind<bool>("3 - Beekeeper", "CalmBees", true, new ConfigDescription("Bees do not sting a player who wears the whole beekeeper set: not at wild hives and not in the swarm of a swarm pot. Off: the set only resists poison.", (AcceptableValueBase)null, new object[1] { val }));
			BeeItem[] all = BeeTable.All;
			foreach (BeeItem beeItem in all)
			{
				if (beeItem.Kind != BeeKind.Material)
				{
					Recipes[beeItem.Key] = c.Bind<string>("4 - Recipes", beeItem.Key, beeItem.Recipe, new ConfigDescription("Cost of " + beeItem.Key + " as item:amount, comma separated. For armour, item:amount+perLevel adds that much for each upgrade. Station: " + (string.IsNullOrEmpty(beeItem.Station) ? "by hand" : beeItem.Station) + ".", (AcceptableValueBase)null, new object[1] { val }));
				}
			}
			ShowMessage = c.Bind<bool>("5 - Client", "ShowMessage", true, "Show a message in the middle of the screen when you find a queen in the comb.");
		}
	}
	public static class Lang
	{
		private static readonly (string key, string en, string de)[] Texts = new(string, string, string)[32]
		{
			("wimq_found_title", "A young queen crawls from the comb", "Eine junge Königin krabbelt aus der Wabe"),
			("wimq_found_line", "Enough for a new hive", "Genug für einen neuen Bienenstock"),
			("wimq_item_beeswax", "Beeswax", "Bienenwachs"),
			("wimq_item_beeswax_desc", "Wax cut from the comb to get at the honey. Beekeepers wax their cloth with it and make bright, slow-burning torches.", "Wachs, das beim Honigernten von der Wabe geschnitten wird. Imker wachsen damit ihr Leinen und machen helle, lange brennende Fackeln."),
			("wimq_item_beekeeperhat", "Beekeeper's hat", "Imkerhut"),
			("wimq_item_beekeeperhat_desc", "A wide straw hat with a black net veil down to the shoulders. The bees cannot reach your face, and you can still see through it.", "Ein breiter Strohhut mit schwarzem Netzschleier bis auf die Schultern. Die Bienen kommen nicht ans Gesicht, und man sieht trotzdem hindurch."),
			("wimq_item_beekeepersmock", "Beekeeper's smock", "Imkerkittel"),
			("wimq_item_beekeepersmock_desc", "Undyed linen, waxed and closed at the wrists. A queen's scent is rubbed into the cloth, and her bees know it.", "Ungefärbtes Leinen, gewachst und an den Handgelenken geschlossen. Der Duft einer Königin ist in den Stoff gerieben, und ihre Bienen kennen ihn."),
			("wimq_item_beekeepertrousers", "Beekeeper's trousers", "Imkerhose"),
			("wimq_item_beekeepertrousers_desc", "Waxed linen tucked into the boots, so no bee crawls up a leg.", "Gewachstes Leinen, in die Stiefel gesteckt, damit keine Biene am Bein hochkrabbelt."),
			("wimq_item_swarmpot", "Swarm pot", "Schwarmtopf"),
			("wimq_item_swarmpot_desc", "A sealed clay pot with a queen and her swarm inside. Where it breaks, the angry bees sting everything around for a while. They leave a beekeeper in the whole set alone.", "Ein versiegelter Tontopf mit einer Königin und ihrem Schwarm. Wo er zerbricht, stechen die wütenden Bienen eine Weile alles ringsum. Wer das ganze Imkerset trägt, bleibt verschont."),
			("wimq_item_honeyarrow", "Honey arrow", "Honigpfeil"),
			("wimq_item_honeyarrow_desc", "Flint arrows dipped in honey. What they hit stays sticky and moves slower for a few seconds.", "Feuersteinpfeile, in Honig getaucht. Was sie treffen, klebt und bewegt sich ein paar Sekunden langsamer."),
			("wimq_item_beeswaxtorch", "Beeswax torch", "Bienenwachsfackel"),
			("wimq_item_beeswaxtorch_desc", "Wrapped in waxed cloth instead of resin: it burns three times as long and lights further, with a warmer light.", "Mit gewachstem Tuch statt Harz umwickelt: Sie brennt dreimal so lange, leuchtet weiter und mit wärmerem Licht."),
			("wimq_item_honeycarrots", "Honey-glazed carrots", "Honigmöhren"),
			("wimq_item_honeycarrots_desc", "Carrots glazed in honey in the cauldron. Sweet, filling and good for stamina.", "Im Kessel in Honig glasierte Möhren. Süß, sättigend und gut für die Ausdauer."),
			("wimq_item_honeyvenison", "Honey-roast venison", "Hirschbraten mit Honig"),
			("wimq_item_honeyvenison_desc", "Roast deer under a glaze of honey and raspberries.", "Hirschbraten unter einer Glasur aus Honig und Himbeeren."),
			("wimq_item_honeyturnipmash", "Honey turnip mash", "Rübenmus mit Honig"),
			("wimq_item_honeyturnipmash_desc", "Turnips and carrots mashed with honey. Plain swamp food, made kind.", "Rüben und Möhren, mit Honig zu Mus gestampft. Einfaches Sumpfessen, freundlich gemacht."),
			("wimq_item_honeywolf", "Honey-glazed wolf", "Honigglasierter Wolf"),
			("wimq_item_honeywolf_desc", "Wolf meat and onion, slowly glazed in honey. It keeps you fed for a long time.", "Wolfsfleisch mit Zwiebel, langsam in Honig glasiert. Hält lange satt."),
			("wimq_item_honeycake", "Honey cake", "Honigkuchen"),
			("wimq_item_honeycake_desc", "Barley flour, cloudberries and honey, dense and sweet.", "Gerstenmehl, Moltebeeren und Honig, dicht und süß."),
			("wimq_item_royalhoney", "Royal honey", "Königinnenhonig"),
			("wimq_item_royalhoney_desc", "Honey stirred with royal jelly and sap: the food of queens, and it clears the mind for magic.", "Honig, mit Gelée royale und Saft verrührt: die Speise der Königinnen, und sie klärt den Geist für die Magie."),
			("wimq_se_beekeeper", "Beekeeper", "Imker"),
			("wimq_se_beekeeper_tt", "Bees do not sting you. You find young queens in the comb more often.", "Bienen stechen dich nicht. Du findest öfter junge Königinnen in der Wabe."),
			("wimq_se_honeyed", "Sticky with honey", "Honigverklebt"),
			("wimq_se_honeyed_tt", "Honey sticks to fur and boots.", "Honig klebt an Fell und Stiefeln.")
		};

		public static void Register()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
			(string, string, string)[] texts = Texts;
			for (int i = 0; i < texts.Length; i++)
			{
				(string, string, string) tuple = texts[i];
				string item = tuple.Item1;
				string item2 = tuple.Item2;
				string item3 = tuple.Item3;
				dictionary[item] = item2;
				dictionary2[item] = item3;
			}
			string text = "English";
			localization.AddTranslation(ref text, dictionary);
			text = "German";
			localization.AddTranslation(ref text, dictionary2);
		}

		public static string T(string token, params object[] args)
		{
			string text = ((Localization.instance != null) ? Localization.instance.Localize("$" + token) : token);
			if (args == null || args.Length == 0)
			{
				return text;
			}
			try
			{
				return string.Format(text, args);
			}
			catch (FormatException)
			{
				return text;
			}
		}
	}
	[BepInPlugin("zap.whereismyqueen", "Where Is My Queen?", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class WhereIsMyQueenPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "zap.whereismyqueen";

		public const string PluginName = "Where Is My Queen?";

		public const string PluginVersion = "1.0.0";

		private Harmony _harmony;

		public static WhereIsMyQueenPlugin Instance { get; private set; }

		public static string PluginDir { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static string AssetPath(string fileName)
		{
			return Path.Combine(PluginDir ?? "", "Assets", fileName);
		}

		private void Awake()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Cfg.Bind(((BaseUnityPlugin)this).Config);
			Lang.Register();
			BeeItems.Init();
			BeeItems.HookConfig();
			_harmony = new Harmony("zap.whereismyqueen");
			_harmony.PatchAll(typeof(WhereIsMyQueenPlugin).Assembly);
			SelfTest.TryStart(((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace WhereIsMyQueen.Visual
{
	internal static class BeekeeperLook
	{
		private static readonly int ChestTex = Shader.PropertyToID("_ChestTex");

		private static readonly int LegsTex = Shader.PropertyToID("_LegsTex");

		private static readonly int ChestBump = Shader.PropertyToID("_ChestBumpMap");

		private static readonly int LegsBump = Shader.PropertyToID("_LegsBumpMap");

		private static readonly Color LinenDark = new Color(0.46f, 0.42f, 0.34f);

		private static readonly Color LinenLight = new Color(0.76f, 0.71f, 0.59f);

		private static readonly Color CuffDark = new Color(0.3f, 0.2f, 0.08f);

		private static readonly Color CuffLight = new Color(0.72f, 0.52f, 0.22f);

		private static readonly Color BootDark = new Color(0.16f, 0.11f, 0.07f);

		private static readonly Color BootLight = new Color(0.5f, 0.36f, 0.22f);

		private const float Contrast = 0.3f;

		private static Color[] _skin;

		private static int _skinW;

		private static int _skinH;

		public static void Apply(BeeItem i, GameObject prefab, SharedData sh)
		{
			try
			{
				switch (i.Kind)
				{
				case BeeKind.Helmet:
					Hat(prefab);
					break;
				case BeeKind.Chest:
					Body(prefab, sh, ChestTex, "smock", Smock);
					_skin = null;
					break;
				case BeeKind.Legs:
					Body(prefab, sh, LegsTex, "trousers", Trousers);
					break;
				}
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogWarning((object)("Look of " + i.Prefab + ": " + ex.Message));
			}
		}

		private static void Hat(GameObject prefab)
		{
			//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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			Transform val = prefab.transform.Find("attach");
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("no attach child on " + ((Object)prefab).name);
			}
			int layer = ((Component)val).gameObject.layer;
			for (int num = val.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val.GetChild(num)).gameObject);
			}
			GameObject obj = HatModel.Build();
			obj.transform.SetParent(val, false);
			GameObject val2 = new GameObject("collider")
			{
				layer = layer
			};
			val2.transform.SetParent(val, false);
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			obj2.center = new Vector3(0f, 0.08f, -0.01f);
			obj2.size = new Vector3(0.66f, 0.26f, 0.66f);
			MeshKit.SetLayer(obj, layer);
		}

		private static void Body(GameObject prefab, SharedData sh, int texId, string key, Func<Color, float, float, Color> f)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			Material armorMaterial = sh.m_armorMaterial;
			if ((Object)(object)armorMaterial == (Object)null)
			{
				throw new Exception("no armour material on " + ((Object)prefab).name);
			}
			Texture texture = armorMaterial.GetTexture(texId);
			Texture2D val = Recolor.Map(texture, key, f);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Material val2 = new Material(armorMaterial)
			{
				name = "WIMQ_" + key
			};
			val2.SetTexture(texId, (Texture)(object)val);
			val2.SetTexture((texId == ChestTex) ? ChestBump : LegsBump, (Texture)null);
			sh.m_armorMaterial = val2;
			SkinnedMeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = ((Renderer)val3).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)sharedMaterials[j] != (Object)null && sharedMaterials[j].HasProperty(texId) && (Object)(object)sharedMaterials[j].GetTexture(texId) == (Object)(object)texture)
					{
						sharedMaterials[j] = val2;
					}
				}
				((Renderer)val3).sharedMaterials = sharedMaterials;
			}
			Recolor.TintAll(prefab, key + "_drop", (Color c) => Recolor.Ramp(c, LinenDark, LinenLight, 1.6f, 0.9f, 0.5f), (Renderer r) => r is MeshRenderer);
		}

		private static Color Skin(float u, float v)
		{
			//IL_0104: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			if (_skin == null)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("Player");
				object obj;
				if (prefab == null)
				{
					obj = null;
				}
				else
				{
					VisEquipment component = prefab.GetComponent<VisEquipment>();
					if (component == null)
					{
						obj = null;
					}
					else
					{
						SkinnedMeshRenderer bodyModel = component.m_bodyModel;
						obj = ((bodyModel != null) ? ((Renderer)bodyModel).sharedMaterial : null);
					}
				}
				Material val = (Material)obj;
				Texture2D val2 = Recolor.Read(((Object)(object)val != (Object)null) ? val.GetTexture("_MainTex") : null);
				if ((Object)(object)val2 == (Object)null)
				{
					_skin = (Color[])(object)new Color[0];
					return new Color(0.6f, 0.6f, 0.6f);
				}
				_skin = val2.GetPixels();
				_skinW = ((Texture)val2).width;
				_skinH = ((Texture)val2).height;
				Object.Destroy((Object)(object)val2);
			}
			if (_skin.Length == 0)
			{
				return new Color(0.6f, 0.6f, 0.6f);
			}
			int num = Mathf.Clamp((int)(u * (float)_skinW), 0, _skinW - 1);
			int num2 = Mathf.Clamp((int)(v * (float)_skinH), 0, _skinH - 1);
			return _skin[num2 * _skinW + num];
		}

		private static Color Smock(Color c, float u, float v)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0067: 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)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			float num = u * 256f;
			float num2 = (1f - v) * 256f;
			bool flag = num < 64f && num2 < 46f;
			bool flag2 = num >= 64f && num < 128f && num2 >= 58f && num2 < 110f;
			bool flag3 = c.a > 0.5f;
			if (!flag && !flag2 && !flag3)
			{
				return c;
			}
			Color c2 = (flag3 ? c : Skin(u, v));
			float gain = (flag3 ? 1.8f : 1.25f);
			Color result = ((flag2 && num2 >= 103f) ? Recolor.Ramp(c2, CuffDark, CuffLight, gain, 1f, 0.3f) : Recolor.Ramp(c2, LinenDark, LinenLight, gain, 0.9f, 0.3f));
			result.a = ((flag || flag2) ? 1f : c.a);
			return result;
		}

		private static Color Trousers(Color c, float u, float v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004b: 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_0074: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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)
			if (c.a <= 0.01f)
			{
				return c;
			}
			Color result = (((1f - v) * 256f >= 108f && u * 256f < 64f) ? Recolor.Ramp(c, BootDark, BootLight, 1.8f, 1f, 0.7f) : Recolor.Ramp(c, LinenDark, LinenLight, 1.8f, 0.9f, 0.3f));
			result.a = c.a;
			return result;
		}
	}
	internal static class HatModel
	{
		private static readonly Vector3 Centre = new Vector3(0f, 0f, -0.01f);

		private static Material _straw;

		private static Material _band;

		private static Material _veil;

		public static Material Straw
		{
			get
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Expected O, but got Unknown
				//IL_0146: 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_0156: 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_016a: Expected O, but got Unknown
				//IL_0107: 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)
				if ((Object)(object)_straw != (Object)null)
				{
					return _straw;
				}
				Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
				{
					name = "wimq_straw",
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)2,
					anisoLevel = 4
				};
				Random random = new Random(52);
				Color[] array = (Color[])(object)new Color[16384];
				for (int i = 0; i < 128; i++)
				{
					float num = (float)(i % 16) / 16f;
					float num2 = 0.72f + 0.28f * Mathf.Sin(num * (float)Math.PI);
					for (int j = 0; j < 128; j++)
					{
						float num3 = 0.9f + 0.1f * Mathf.Sin(((float)j + (float)((i / 16 % 2 == 0) ? i : (-i)) * 1.5f) * 0.39f);
						float num4 = 0.92f + 0.08f * (float)random.NextDouble();
						float num5 = num2 * num3 * num4;
						array[i * 128 + j] = new Color(0.86f * num5, 0.7f * num5, 0.4f * num5, 1f);
					}
				}
				val.SetPixels(array);
				val.Apply(true, true);
				_straw = new Material(Mats.Standard)
				{
					name = "wimq_straw",
					mainTexture = (Texture)(object)val,
					hideFlags = (HideFlags)32
				};
				Mats.Surface(_straw, 0f, 0.12f);
				return _straw;
			}
		}

		public static Material Band
		{
			get
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: 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_004f: Expected O, but got Unknown
				if ((Object)(object)_band != (Object)null)
				{
					return _band;
				}
				_band = new Material(Mats.Standard)
				{
					name = "wimq_hatband",
					color = new Color(0.62f, 0.38f, 0.1f),
					hideFlags = (HideFlags)32
				};
				Mats.Surface(_band, 0f, 0.2f);
				return _band;
			}
		}

		public static Material Veil
		{
			get
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: 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_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00f1: Expected O, but got Unknown
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: 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)
				if ((Object)(object)_veil != (Object)null)
				{
					return _veil;
				}
				Texture2D val = new Texture2D(32, 32, (TextureFormat)4, true)
				{
					name = "wimq_veilnet",
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)2,
					anisoLevel = 4
				};
				Color[] array = (Color[])(object)new Color[1024];
				for (int i = 0; i < 32; i++)
				{
					for (int j = 0; j < 32; j++)
					{
						bool flag = j % 8 < 2 || i % 8 < 2;
						array[i * 32 + j] = (flag ? new Color(0.07f, 0.07f, 0.06f, 0.95f) : new Color(0.05f, 0.05f, 0.05f, 0.3f));
					}
				}
				val.SetPixels(array);
				val.Apply(true, true);
				_veil = new Material(Mats.AlphaBlended)
				{
					name = "wimq_veil",
					mainTexture = (Texture)(object)val,
					hideFlags = (HideFlags)32
				};
				if (_veil.HasProperty("_TintColor"))
				{
					_veil.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f));
				}
				return _veil;
			}
		}

		public static GameObject Build()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_001b: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00c3: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("beekeeper_hat");
			List<Vector2> profile = new List<Vector2>
			{
				new Vector2(0.16f, 0.052f),
				new Vector2(0.25f, 0.043f),
				new Vector2(0.335f, 0.028f),
				new Vector2(0.345f, 0.034f),
				new Vector2(0.342f, 0.043f),
				new Vector2(0.25f, 0.056f),
				new Vector2(0.172f, 0.066f),
				new Vector2(0.166f, 0.075f),
				new Vector2(0.16f, 0.15f),
				new Vector2(0.15f, 0.205f),
				new Vector2(0.12f, 0.228f),
				new Vector2(0.065f, 0.238f),
				new Vector2(0f, 0.24f)
			};
			MeshKit.Part("hat", val.transform, MeshKit.Lathe("wimq_hat", profile, 32, Centre, twoSided: false, 6f, 6f), Straw);
			List<Vector2> profile2 = new List<Vector2>
			{
				new Vector2(0.171f, 0.068f),
				new Vector2(0.169f, 0.084f),
				new Vector2(0.166f, 0.1f)
			};
			MeshKit.Part("band", val.transform, MeshKit.Lathe("wimq_hatband", profile2, 32, Centre), Band);
			List<Vector2> profile3 = new List<Vector2>
			{
				new Vector2(0.3f, 0.04f),
				new Vector2(0.29f, -0.04f),
				new Vector2(0.268f, -0.15f),
				new Vector2(0.262f, -0.22f),
				new Vector2(0.282f, -0.28f)
			};
			MeshKit.Part("veil", val.transform, MeshKit.Lathe("wimq_veil", profile3, 32, Centre, twoSided: true, 10f, 10f), Veil);
			return val;
		}
	}
	internal static class Mats
	{
		private static Shader _standard;

		private static Shader _alpha;

		private static readonly int MetallicId = Shader.PropertyToID("_Metallic");

		private static readonly int GlossId = Shader.PropertyToID("_Glossiness");

		public static Shader Standard
		{
			get
			{
				if (!((Object)(object)_standard != (Object)null))
				{
					return _standard = From("Honey", (Renderer r) => !(r is ParticleSystemRenderer), "Standard") ?? Shader.Find("Standard");
				}
				return _standard;
			}
		}

		public static Shader AlphaBlended
		{
			get
			{
				if (!((Object)(object)_alpha != (Object)null))
				{
					return _alpha = From("QueenBee", (Renderer r) => r is ParticleSystemRenderer, "Alpha Blended") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended");
				}
				return _alpha;
			}
		}

		public static void Surface(Material m, float metallic, float gloss)
		{
			if (m.HasProperty(MetallicId))
			{
				m.SetFloat(MetallicId, metallic);
			}
			if (m.HasProperty(GlossId))
			{
				m.SetFloat(GlossId, gloss);
			}
		}

		private static Shader From(string prefab, Func<Renderer, bool> which, string nameContains)
		{
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(prefab);
			if ((Object)(object)prefab2 == (Object)null)
			{
				return null;
			}
			return (from m in prefab2.GetComponentsInChildren<Renderer>(true).Where(which).SelectMany((Renderer r) => r.sharedMaterials)
				where (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null
				select m.shader).FirstOrDefault((Func<Shader, bool>)((Shader s) => ((Object)s).name.Contains(nameContains)));
		}
	}
	internal static class MeshKit
	{
		public static Mesh Lathe(string name, IList<Vector2> profile, int segments, Vector3 offset, bool twoSided = false, float uRepeat = 1f, float vScale = 1f)
		{
			//IL_0043: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			int count = profile.Count;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			float[] array = new float[count];
			Vector2[] array2 = (Vector2[])(object)new Vector2[count];
			for (int i = 1; i < count; i++)
			{
				array[i] = array[i - 1] + Vector2.Distance(profile[i], profile[i - 1]);
			}
			for (int j = 0; j < count; j++)
			{
				Vector2 val = profile[Mathf.Max(0, j - 1)];
				Vector2 val2 = profile[Mathf.Min(count - 1, j + 1)] - val;
				Vector2 normalized = ((Vector2)(ref val2)).normalized;
				array2[j] = new Vector2(normalized.y, 0f - normalized.x);
			}
			for (int k = 0; k < ((!twoSided) ? 1 : 2); k++)
			{
				int count2 = list.Count;
				float num = ((k == 0) ? 1f : (-1f));
				for (int l = 0; l <= segments; l++)
				{
					float num2 = (float)l * (float)Math.PI * 2f / (float)segments;
					float num3 = Mathf.Cos(num2);
					float num4 = Mathf.Sin(num2);
					for (int m = 0; m < count; m++)
					{
						Vector2 val3 = profile[m];
						list.Add(offset + new Vector3(val3.x * num4, val3.y, val3.x * num3));
						Vector3 val4 = new Vector3(array2[m].x * num4, array2[m].y, array2[m].x * num3);
						list2.Add(((Vector3)(ref val4)).normalized * num);
						list3.Add(new Vector2((float)l / (float)segments * uRepeat, array[m] * vScale));
					}
				}
				for (int n = 0; n < segments; n++)
				{
					for (int num5 = 0; num5 < count - 1; num5++)
					{
						int num6 = count2 + n * count + num5;
						int num7 = num6 + count;
						int item = num6 + 1;
						int item2 = num7 + 1;
						if (k == 0)
						{
							list4.Add(num6);
							list4.Add(num7);
							list4.Add(item);
							list4.Add(num7);
							list4.Add(item2);
							list4.Add(item);
						}
						else
						{
							list4.Add(num6);
							list4.Add(item);
							list4.Add(num7);
							list4.Add(num7);
							list4.Add(item);
							list4.Add(item2);
						}
					}
				}
			}
			Mesh val5 = new Mesh
			{
				name = name
			};
			val5.SetVertices(list);
			val5.SetNormals(list2);
			val5.SetUVs(0, list3);
			val5.SetTriangles(list4, 0);
			val5.RecalculateBounds();
			val5.RecalculateTangents();
			return val5;
		}

		public static void SetLayer(GameObject go, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			go.layer = layer;
			foreach (Transform item in go.transform)
			{
				SetLayer(((Component)item).gameObject, layer);
			}
		}

		public static GameObject Part(string name, Transform parent, Mesh mesh, Material mat)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_002c: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = mat;
			return val;
		}
	}
	internal static class Recolor
	{
		private static readonly Dictionary<string, Texture2D> Cache = new Dictionary<string, Texture2D>();

		public static Action<string> Debug;

		public static Texture2D Read(Texture src)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_004d: 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_0066: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00bf: 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_00ff: Expected O, but got Unknown
			if ((Object)(object)src == (Object)null)
			{
				return null;
			}
			int width = src.width;
			int height = src.height;
			RenderTexture active = RenderTexture.active;
			RenderTexture val = new RenderTexture(width, height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			try
			{
				val.Create();
				CommandBuffer val2 = new CommandBuffer
				{
					name = "WIMQ_readback"
				};
				val2.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)(object)val));
				val2.SetViewport(new Rect(0f, 0f, (float)width, (float)height));
				val2.ClearRenderTarget(true, true, Color.clear);
				val2.Blit(src, RenderTargetIdentifier.op_Implicit((Texture)(object)val));
				Graphics.ExecuteCommandBuffer(val2);
				val2.Release();
				RenderTexture.active = val;
				Texture2D val3 = new Texture2D(width, height, (TextureFormat)4, false)
				{
					name = ((Object)src).name + "_read"
				};
				val3.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
				val3.Apply();
				Debug?.Invoke($"read {((Object)src).name} {width}x{height}");
				return val3;
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogWarning((object)("Could not read texture " + ((Object)src).name + ": " + ex.Message));
				return null;
			}
			finally
			{
				RenderTexture.active = active;
				val.Release();
				Object.Destroy((Object)(object)val);
			}
		}

		public static Texture2D Map(Texture src, string key, Func<Color, float, float, Color> f, bool mipmaps = true)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)src == (Object)null || f == null)
			{
				return null;
			}
			string key2 = key + "|" + ((Object)src).name;
			if (Cache.TryGetValue(key2, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture2D val = Read(src);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			int width = ((Texture)val).width;
			int height = ((Texture)val).height;
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < height; i++)
			{
				float arg = ((float)i + 0.5f) / (float)height;
				for (int j = 0; j < width; j++)
				{
					int num = i * width + j;
					pixels[num] = f(pixels[num], ((float)j + 0.5f) / (float)width, arg);
				}
			}
			Object.Destroy((Object)(object)val);
			value = new Texture2D(width, height, (TextureFormat)4, mipmaps)
			{
				name = "WIMQ_" + key + "_" + ((Object)src).name,
				wrapMode = src.wrapMode,
				filterMode = (FilterMode)2,
				anisoLevel = 4
			};
			value.SetPixels(pixels);
			value.Apply(mipmaps, true);
			Cache[key2] = value;
			return value;
		}

		public static Material Tint(Material src, string key, Func<Color, Color> f, bool resetColor = false)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_00ba: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)src == (Object)null)
			{
				return null;
			}
			Material val = new Material(src)
			{
				name = ((Object)src).name + "_" + key
			};
			Texture val2 = (src.HasProperty("_MainTex") ? src.GetTexture("_MainTex") : null);
			Texture2D val3 = (((Object)(object)val2 != (Object)null) ? Map(val2, key, (Color c, float u, float v) => f(c)) : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val.SetTexture("_MainTex", (Texture)(object)val3);
				if (resetColor && val.HasProperty("_Color"))
				{
					val.color = Color.white;
				}
			}
			else if (val.HasProperty("_Color"))
			{
				val.color = f(val.color);
			}
			return val;
		}

		public static void TintAll(GameObject root, string key, Func<Color, Color> f, Func<Renderer, bool> which = null, bool resetColor = false)
		{
			Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is ParticleSystemRenderer || (which != null && !which(val)))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!((Object)(object)sharedMaterials[j] == (Object)null))
					{
						if (!dictionary.TryGetValue(sharedMaterials[j], out var value))
						{
							value = (dictionary[sharedMaterials[j]] = Tint(sharedMaterials[j], key, f, resetColor));
						}
						sharedMaterials[j] = value;
					}
				}
				val.sharedMaterials = sharedMaterials;
			}
		}

		public static float Lum(Color c)
		{
			//IL_0005: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			return 0.299f * c.r + 0.587f * c.g + 0.114f * c.b;
		}

		public static Color Ramp(Color c, Color dark, Color light, float gain = 1f, float gamma = 1f, float contrast = 1f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(Mathf.Pow(Mathf.Clamp01(Lum(c) * gain), gamma));
			num = Mathf.Lerp(0.6f, num, contrast);
			Color result = Color.Lerp(dark, light, num);
			result.a = c.a;
			return result;
		}

		public static Color Glaze(Color c, Color glaze, float amount)
		{
			//IL_0000: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(Lum(c) * 1.15f);
			Color val = default(Color);
			((Color)(ref val))..ctor(glaze.r * num, glaze.g * num, glaze.b * num, c.a);
			Color result = Color.Lerp(c, val, amount);
			result.a = c.a;
			return result;
		}
	}
}
namespace WhereIsMyQueen.Gameplay
{
	public static class BeeGear
	{
		[HarmonyPatch(typeof(Aoe), "OnHit")]
		private static class CalmBees
		{
			private static bool Prefix(Aoe __instance, Collider collider, ref bool __result)
			{
				try
				{
					if (!Cfg.CalmBees.Value || (Object)(object)collider == (Object)null || !IsSwarm(__instance))
					{
						return true;
					}
					GameObject val = Projectile.FindHitObject(collider);
					Player val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Player>() : null);
					if ((Object)(object)val2 == (Object)null || !WearsSet(val2))
					{
						return true;
					}
					__instance.m_hitList.Add(val);
					__result = false;
					return false;
				}
				catch (Exception ex)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Calm bees: " + ex.Message));
					return true;
				}
			}
		}

		private static readonly int HatHash = StringExtensionMethods.GetStableHashCode("WIMQ_BeekeeperHat");

		private static readonly int SmockHash = StringExtensionMethods.GetStableHashCode("WIMQ_BeekeeperSmock");

		private static readonly int TrousersHash = StringExtensionMethods.GetStableHashCode("WIMQ_BeekeeperTrousers");

		private static readonly int WildHiveHash = StringExtensionMethods.GetStableHashCode("Beehive");

		private static readonly int BeeCloudHash = StringExtensionMethods.GetStableHashCode("bee_aoe");

		private static readonly int SwarmHash = StringExtensionMethods.GetStableHashCode("WIMQ_swarmpot_swarm");

		public static bool WearsSet(Player p)
		{
			if ((Object)(object)p == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Character)p).m_nview == (Object)null || !((Character)p).m_nview.IsValid() || ((Character)p).m_nview.IsOwner())
			{
				if (Is(((Humanoid)p).m_helmetItem, "WIMQ_BeekeeperHat") && Is(((Humanoid)p).m_chestItem, "WIMQ_BeekeeperSmock"))
				{
					return Is(((Humanoid)p).m_legItem, "WIMQ_BeekeeperTrousers");
				}
				return false;
			}
			ZDO zDO = ((Character)p).m_nview.GetZDO();
			if (zDO != null)
			{
				if (zDO.GetInt(ZDOVars.s_helmetItem, 0) == HatHash && zDO.GetInt(ZDOVars.s_chestItem, 0) == SmockHash)
				{
					return zDO.GetInt(ZDOVars.s_legItem, 0) == TrousersHash;
				}
				return false;
			}
			if (Is(((Humanoid)p).m_helmetItem, "WIMQ_BeekeeperHat") && Is(((Humanoid)p).m_chestItem, "WIMQ_BeekeeperSmock"))
			{
				return Is(((Humanoid)p).m_legItem, "WIMQ_BeekeeperTrousers");
			}
			return false;
		}

		private static bool Is(ItemData item, string prefab)
		{
			if ((Object)(object)item?.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == prefab;
			}
			return false;
		}

		public static Player PlayerOf(long peer)
		{
			if (peer == 0L)
			{
				return null;
			}
			foreach (Player allPlayer in Player.GetAllPlayers())
			{
				if ((Object)(object)allPlayer != (Object)null && (Object)(object)((Character)allPlayer).m_nview != (Object)null && ((Character)allPlayer).m_nview.IsValid() && ((Character)allPlayer).m_nview.GetZDO().GetOwner() == peer)
				{
					return allPlayer;
				}
			}
			return null;
		}

		public static double QueenBonus(long harvester)
		{
			if (!WearsSet(PlayerOf(harvester)))
			{
				return 1.0;
			}
			return Math.Max(1f, Cfg.SetQueenBonus.Value);
		}

		public static bool IsSwarm(Aoe aoe)
		{
			if ((Object)(object)aoe == (Object)null)
			{
				return false;
			}
			ZDO val = (((Object)(object)aoe.m_nview != (Object)null) ? aoe.m_nview.GetZDO() : null);
			if (val == null)
			{
				return ((Object)((Component)aoe).gameObject).name.StartsWith("bee_aoe", StringComparison.Ordinal);
			}
			int prefab = val.GetPrefab();
			if (prefab != WildHiveHash && prefab != BeeCloudHash)
			{
				return prefab == SwarmHash;
			}
			return true;
		}
	}
	public static class BeeItems
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class AddToObjectDB
		{
			[HarmonyPriority(0)]
			private static void Postfix()
			{
				Apply();
			}
		}

		private static readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		private static readonly List<Recipe> Ours = new List<Recipe>();

		public const float HoneyedSpeed = -0.3f;

		public const float HoneyedSeconds = 6f;

		public const float WaxTorchDurability = 60f;

		public const float WaxTorchRange = 15f;

		public const float WaxTorchIntensity = 2f;

		public const float HoneyArrowPierce = 24f;

		private static bool _pending;

		public static SE_Stats SetEffect { get; private set; }

		public static SE_Stats Honeyed { get; private set; }

		internal static void Init()
		{
			PrefabManager.OnVanillaPrefabsAvailable += AddAll;
		}

		public static GameObject Prefab(string name)
		{
			if (!Prefabs.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

		private static void AddAll()
		{
			try
			{
				AddStatusEffects();
				BeeItem[] all = BeeTable.All;
				for (int i = 0; i < all.Length; i++)
				{
					Add(all[i]);
				}
				WhereIsMyQueenPlugin.Log.LogInfo((object)$"Added {Prefabs.Count} beekeeper items.");
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogError((object)("Could not add the beekeeper items: " + ex));
			}
			finally
			{
				PrefabManager.OnVanillaPrefabsAvailable -= AddAll;
			}
		}

		private static void AddStatusEffects()
		{
			//IL_00cb: 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_00e0: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab("QueenBee");
			Sprite icon = ((prefab == null) ? null : prefab.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_icons?.FirstOrDefault());
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("Honey");
			Sprite icon2 = ((prefab2 == null) ? null : prefab2.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_icons?.FirstOrDefault());
			SetEffect = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)SetEffect).name = "SetEffect_WIMQ_Beekeeper";
			((StatusEffect)SetEffect).m_name = "$wimq_se_beekeeper";
			((StatusEffect)SetEffect).m_tooltip = "$wimq_se_beekeeper_tt";
			((StatusEffect)SetEffect).m_icon = icon;
			SetEffect.m_mods = new List<DamageModPair>
			{
				new DamageModPair
				{
					m_type = (DamageType)256,
					m_modifier = (DamageModifier)1
				}
			};
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)SetEffect, false));
			Honeyed = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)Honeyed).name = "WIMQ_Honeyed";
			((StatusEffect)Honeyed).m_name = "$wimq_se_honeyed";
			((StatusEffect)Honeyed).m_tooltip = "$wimq_se_honeyed_tt";
			((StatusEffect)Honeyed).m_icon = icon2;
			((StatusEffect)Honeyed).m_ttl = 6f;
			Honeyed.m_speedModifier = -0.3f;
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)Honeyed, false));
		}

		private static void Add(BeeItem i)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			CustomItem val = new CustomItem(i.Prefab, i.Base);
			if ((Object)(object)val.ItemPrefab == (Object)null)
			{
				WhereIsMyQueenPlugin.Log.LogError((object)("Cloning " + i.Base + " for " + i.Prefab + " failed."));
				return;
			}
			GameObject itemPrefab = val.ItemPrefab;
			SharedData shared = val.ItemDrop.m_itemData.m_shared;
			shared.m_name = "$" + i.Token;
			shared.m_description = "$" + i.Token + "_desc";
			Piece component = itemPrefab.GetComponent<Piece>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_name = shared.m_name;
			}
			bool flag = !GUIManager.IsHeadless();
			switch (i.Kind)
			{
			case BeeKind.Material:
				shared.m_weight = 0.2f;
				if (flag)
				{
					Recolor.TintAll(itemPrefab, "wax", (Color c) => Recolor.Ramp(c, new Color(0.5f, 0.33f, 0.09f), new Color(0.86f, 0.66f, 0.3f), 1.5f, 1f, 0.7f), null, resetColor: true);
				}
				break;
			case BeeKind.Helmet:
			case BeeKind.Chest:
			case BeeKind.Legs:
				Armour(i, shared);
				if (flag)
				{
					BeekeeperLook.Apply(i, itemPrefab, shared);
				}
				break;
			case BeeKind.Bomb:
				SwarmPot.Setup(itemPrefab, shared, flag);
				break;
			case BeeKind.Arrow:
				shared.m_damages.m_pierce = 24f;
				shared.m_attackStatusEffect = (StatusEffect)(object)Honeyed;
				shared.m_attackStatusEffectChance = 1f;
				if (flag)
				{
					Recolor.TintAll(itemPrefab, "honeyarrow", (Color c) => Recolor.Glaze(c, new Color(1f, 0.66f, 0.16f), 0.5f));
				}
				break;
			case BeeKind.Torch:
			{
				shared.m_maxDurability = 60f;
				Light[] componentsInChildren = itemPrefab.GetComponentsInChildren<Light>(true);
				foreach (Light obj in componentsInChildren)
				{
					obj.color = new Color(1f, 0.74f, 0.45f);
					obj.range = 15f;
					obj.intensity = 2f;
				}
				if (flag)
				{
					Recolor.TintAll(itemPrefab, "waxtorch", (Color c) => Recolor.Glaze(c, new Color(1f, 0.85f, 0.5f), 0.35f));
				}
				break;
			}
			case BeeKind.Food:
				shared.m_food = i.Health;
				shared.m_foodStamina = i.Stamina;
				shared.m_foodEitr = i.Eitr;
				shared.m_foodBurnTime = i.BurnTime;
				shared.m_foodRegen = i.Regen;
				if (flag)
				{
					Recolor.TintAll(itemPrefab, "food_" + i.Key, FoodGlaze(i));
				}
				break;
			}
			val.ItemDrop.m_itemData.m_durability = shared.m_maxDurability;
			if (flag)
			{
				Sprite val2 = RenderIcon(itemPrefab, i.Kind);
				if ((Object)(object)val2 != (Object)null)
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 };
				}
			}
			ItemManager.Instance.AddItem(val);
			Prefabs[i.Prefab] = itemPrefab;
		}

		private static void Armour(BeeItem i, SharedData sh)
		{
			sh.m_armor = i.Armor;
			sh.m_armorPerLevel = i.ArmorPerLevel;
			sh.m_weight = i.Weight;
			sh.m_maxDurability = i.Durability;
			sh.m_durabilityPerLevel = i.DurabilityPerLevel;
			sh.m_maxQuality = 4;
			sh.m_movementModifier = 0f;
			sh.m_damageModifiers = new List<DamageModPair>();
			sh.m_equipStatusEffect = null;
			sh.m_setName = "wimq_beekeeper";
			sh.m_setSize = BeeTable.SetPieces.Length;
			sh.m_setStatusEffect = (StatusEffect)(object)SetEffect;
		}

		private static Func<Color, Color> FoodGlaze(BeeItem i)
		{
			string key = i.Key;
			if (!(key == "RoyalHoney"))
			{
				if (key == "HoneyCake")
				{
					return (Color c) => Recolor.Glaze(c, new Color(1f, 0.72f, 0.3f), 0.45f);
				}
				return (Color c) => Recolor.Glaze(c, new Color(1f, 0.64f, 0.18f), 0.4f);
			}
			return (Color c) => Recolor.Glaze(c, new Color(1f, 0.86f, 0.5f), 0.55f);
		}

		private static Sprite RenderIcon(GameObject prefab, BeeKind kind)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_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_002c: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			try
			{
				Quaternion rotation = ((kind == BeeKind.Helmet) ? Quaternion.Euler(18f, 160f, 0f) : RenderManager.IsometricRotation);
				return RenderManager.Instance.Render(new RenderRequest(prefab)
				{
					Rotation = rotation,
					Width = 128,
					Height = 128,
					ParticleSimulationTime = -1f,
					UseCache = false
				});
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogWarning((object)("Icon for " + ((Object)prefab).name + " failed: " + ex.Message));
				return null;
			}
		}

		public static void Apply()
		{
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null || instance.m_items == null || instance.m_items.Count == 0)
			{
				return;
			}
			try
			{
				instance.m_recipes.RemoveAll((Recipe r) => (Object)(object)r != (Object)null && Ours.Contains(r));
				foreach (Recipe our in Ours)
				{
					Object.Destroy((Object)(object)our);
				}
				Ours.Clear();
				Requirement val = ((IEnumerable<Requirement>)((IEnumerable<Recipe>)instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => (Object)(object)r?.m_item != (Object)null && ((Object)r.m_item).name == "ArmorTrollLeatherChest"))?.m_resources).FirstOrDefault((Func<Requirement, bool>)((Requirement q) => q.m_upgraderResource));
				BeeItem[] all = BeeTable.All;
				foreach (BeeItem beeItem in all)
				{
					if (beeItem.Kind != BeeKind.Material)
					{
						ConfigEntry<string> value;
						string cost = (Cfg.Recipes.TryGetValue(beeItem.Key, out value) ? value.Value : beeItem.Recipe);
						bool flag = beeItem.Kind == BeeKind.Helmet || beeItem.Kind == BeeKind.Chest || beeItem.Kind == BeeKind.Legs;
						Make(instance, beeItem, cost, flag ? val : null);
					}
				}
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogError((object)("Could not set up the recipes: " + ex));
			}
		}

		private static void Make(ObjectDB db, BeeItem i, string cost, Requirement upgrader)
		{
			//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_00a6: 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)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_0106: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0147: Expected O, but got Unknown
			GameObject itemPrefab = db.GetItemPrefab(i.Prefab);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return;
			}
			List<Requirement> list = new List<Requirement>();
			foreach (Cost item in BeeTable.Parse(cost))
			{
				GameObject itemPrefab2 = db.GetItemPrefab(item.Item);
				if ((Object)(object)itemPrefab2 == (Object)null)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Recipe for " + i.Prefab + ": no item '" + item.Item + "'."));
				}
				else
				{
					list.Add(new Requirement
					{
						m_resItem = itemPrefab2.GetComponent<ItemDrop>(),
						m_amount = item.Amount,
						m_amountPerLevel = item.PerLevel,
						m_recover = true
					});
				}
			}
			if (list.Count != 0)
			{
				if ((Object)(object)upgrader?.m_resItem != (Object)null)
				{
					list.Add(new Requirement
					{
						m_resItem = upgrader.m_resItem,
						m_amount = upgrader.m_amount,
						m_amountPerLevel = upgrader.m_amountPerLevel,
						m_upgraderResource = true,
						m_recover = upgrader.m_recover
					});
				}
				KeyValuePair<string, int> keyValuePair = BeeTable.Station(i.Station);
				GameObject val = ((keyValuePair.Key.Length == 0) ? null : (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(keyValuePair.Key) : PrefabManager.Instance.GetPrefab(keyValuePair.Key)));
				Recipe val2 = ScriptableObject.CreateInstance<Recipe>();
				((Object)val2).name = "Recipe_" + i.Prefab;
				val2.m_item = itemPrefab.GetComponent<ItemDrop>();
				val2.m_amount = i.Amount;
				val2.m_enabled = true;
				val2.m_craftingStation = (((Object)(object)val != (Object)null) ? val.GetComponent<CraftingStation>() : null);
				val2.m_minStationLevel = keyValuePair.Value;
				val2.m_resources = list.ToArray();
				db.m_recipes.Add(val2);
				Ours.Add(val2);
			}
		}

		internal static void HookConfig()
		{
			foreach (ConfigEntry<string> value in Cfg.Recipes.Values)
			{
				value.SettingChanged += delegate
				{
					ApplySoon();
				};
			}
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				ApplySoon();
			};
		}

		private static void ApplySoon()
		{
			if ((Object)(object)WhereIsMyQueenPlugin.Instance == (Object)null)
			{
				Apply();
			}
			else if (!_pending)
			{
				_pending = true;
				((MonoBehaviour)WhereIsMyQueenPlugin.Instance).StartCoroutine(ApplyAtEndOfFrame());
			}
		}

		private static IEnumerator ApplyAtEndOfFrame()
		{
			yield return null;
			_pending = false;
			Apply();
		}
	}
	public static class Beeswax
	{
		[HarmonyPatch(typeof(DropOnDestroyed), "OnDestroyed")]
		private static class WildHiveWax
		{
			private static void Postfix(DropOnDestroyed __instance)
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!((Object)(object)__instance == (Object)null) && ((Object)((Component)__instance).gameObject).name.StartsWith("Beehive", StringComparison.Ordinal))
					{
						int n = BeeTable.WildWax(Cfg.WildHiveWaxMin.Value, Cfg.WildHiveWaxMax.Value, Next);
						Spawn(((Component)__instance).transform.position + Vector3.up * 0.6f, n);
					}
				}
				catch (Exception ex)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Wild hive wax: " + ex.Message));
				}
			}
		}

		public static int Spawned;

		public static Func<double> Next = () => Random.value;

		internal static void Drop(Beehive hive, int taken)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			int n = BeeTable.Wax(taken, hive.m_maxHoney, Cfg.WaxPerFullHive.Value, Next);
			Spawn((((Object)(object)hive.m_spawnPoint != (Object)null) ? hive.m_spawnPoint : ((Component)hive).transform).position + new Vector3(0f, 0.25f * (float)taken + 0.35f, 0f), n);
		}

		private static void Spawn(Vector3 pos, int n)
		{
			//IL_0069: 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_0078: 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_007b: 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_008c: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			if (n <= 0)
			{
				return;
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("WIMQ_Beeswax") : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			int num = (((Object)(object)Game.instance != (Object)null) ? Game.instance.ScaleDrops(val2.m_itemData, n) : n);
			if (num > 0)
			{
				Vector2 val3 = Random.insideUnitCircle * 0.3f;
				GameObject obj = Object.Instantiate<GameObject>(val, pos + new Vector3(val3.x, 0f, val3.y), Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
				ItemDrop component = obj.GetComponent<ItemDrop>();
				if (component != null)
				{
					component.SetStack(num);
				}
				ItemDrop.OnCreateNew(obj, false);
				Spawned += num;
			}
		}
	}
	public static class HiveQueen
	{
		[HarmonyPatch(typeof(Beehive), "RPC_Extract")]
		private static class RollOnExtract
		{
			private static void Prefix(Beehive __instance, out int __state)
			{
				__state = 0;
				try
				{
					__state = __instance.GetHoneyLevel();
				}
				catch (Exception ex)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Queen roll (before harvest): " + ex.Message));
				}
			}

			private static void Postfix(Beehive __instance, long caller, int __state)
			{
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (__state <= 0 || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner() || (Object)(object)__instance.m_honeyItem == (Object)null || ((Object)__instance.m_honeyItem).name != "Honey")
					{
						return;
					}
					int num = __state - __instance.GetHoneyLevel();
					if (num > 0)
					{
						Beeswax.Drop(__instance, num);
						if (QueenOdds.Roll(QueenOdds.Chance(num, __instance.m_maxHoney, Cfg.ChanceOneIn.Value, Cfg.ScaleWithHoney.Value, BeeGear.QueenBonus(caller)), Next) && Drop(__instance, num))
						{
							QueenNews.Send(caller, ((Component)__instance).transform.position);
						}
					}
				}
				catch (Exception ex)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Queen roll: " + ex.Message));
				}
			}
		}

		public const string QueenPrefab = "QueenBee";

		public const string HoneyPrefab = "Honey";

		public static int Spawned;

		public static Func<double> Next = () => Random.value;

		private static bool Drop(Beehive hive, int jars)
		{
			//IL_0069: 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_0078: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("QueenBee") : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				WhereIsMyQueenPlugin.Log.LogWarning((object)"Queen roll: no QueenBee item in ObjectDB");
				return false;
			}
			Transform obj = (((Object)(object)hive.m_spawnPoint != (Object)null) ? hive.m_spawnPoint : ((Component)hive).transform);
			Vector2 val3 = Random.insideUnitCircle * 0.3f;
			Vector3 val4 = obj.position + new Vector3(val3.x, 0.25f * (float)jars + 0.1f, val3.y);
			GameObject obj2 = Object.Instantiate<GameObject>(val, val4, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
			int num = ((!((Object)(object)Game.instance != (Object)null)) ? 1 : Game.instance.ScaleDrops(val2.m_itemData, 1));
			ItemDrop component = obj2.GetComponent<ItemDrop>();
			if (component != null)
			{
				component.SetStack(Mathf.Max(1, num));
			}
			Spawned += Mathf.Max(1, num);
			return true;
		}
	}
	public static class QueenNews
	{
		[HarmonyPatch(typeof(Game), "Start")]
		private static class RegisterOnGameStart
		{
			private static void Postfix()
			{
				try
				{
					Register();
				}
				catch (Exception ex)
				{
					WhereIsMyQueenPlugin.Log.LogWarning((object)("Could not register WIMQ_QueenFound: " + ex.Message));
				}
			}
		}

		public const string RpcName = "WIMQ_QueenFound";

		private static ZRoutedRpc _registeredOn;

		public static string LastShown;

		public static void Register()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null && instance != _registeredOn)
			{
				instance.Register<Vector3>("WIMQ_QueenFound", (Action<long, Vector3>)RPC_QueenFound);
				_registeredOn = instance;
			}
		}

		public static void Send(long harvester, Vector3 hivePos)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Register();
			if (ZRoutedRpc.instance != null && harvester != 0L)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(harvester, "WIMQ_QueenFound", new object[1] { hivePos });
			}
		}

		public static string Message()
		{
			return Lang.T("wimq_found_title") + "\n<size=80%>" + Lang.T("wimq_found_line") + "</size>";
		}

		private static void RPC_QueenFound(long sender, Vector3 hivePos)
		{
			try
			{
				if (!((Object)(object)Player.m_localPlayer == (Object)null) && !GUIManager.IsHeadless() && Cfg.ShowMessage.Value)
				{
					LastShown = Message();
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, LastShown, 0, (Sprite)null, false, true);
					}
				}
			}
			catch (Exception ex)
			{
				WhereIsMyQueenPlugin.Log.LogWarning((object)("Queen message: " + ex.Message));
			}
		}
	}
	public static class SwarmPot
	{
		public const string SwarmPrefab = "WIMQ_swarmpot_swarm";

		public const string ProjectilePrefab = "WIMQ_swarmpot_projectile";

		public const float Radius = 3.5f;

		public const float Seconds = 8f;

		public const float StingPierce = 4f;

		public const float StingPoison = 20f;

		private static readonly Color Clay = new Color(0.58f, 0.36f, 0.16f);

		private static readonly Color Dust = new Color(0.55f, 0.45f, 0.3f, 0.35f);

		internal static void Setup(GameObject item, SharedData sh, bool client)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("WIMQ_swarmpot_projectile", "oozebomb_projectile");
			GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("WIMQ_swarmpot_swarm", "oozebomb_explosion");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				throw new Exception("ooze bomb prefabs not found");
			}
			val.GetComponent<Projectile>().m_spawnOnHit = val2;
			sh.m_attack.m_attackProjectile = val;
			Aoe component = val2.GetComponent<Aoe>();
			component.m_radius = 3.5f;
			component.m_ttl = 8f;
			component.m_ttlMax = 0f;
			component.m_statusEffectIfBoss = "";
			component.m_statusEffectIfPlayer = "";
			component.m_damagePerLevel = default(DamageTypes);
			component.m_hitInterval = 1f;
			component.m_damage = new DamageTypes
			{
				m_pierce = 4f,
				m_poison = 20f
			};
			component.m_statusEffect = "";
			if (client)
			{
				Paint(item);
				Paint(val);
				Bees(val2);
			}
			PrefabManager.Instance.AddPrefab(val);
			PrefabManager.Instance.AddPrefab(val2);
		}

		private static void Paint(GameObject go)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Recolor.TintAll(go, "swarmpot", (Color c) => new Color(Clay.r, Clay.g, Clay.b, c.a), (Renderer r) => r is MeshRenderer);
			ParticleSystem[] componentsInChildren = go.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if (!((Object)(object)((Component)val).gameObject == (Object)(object)go))
				{
					if (((Object)((Component)val).gameObject).name == "trail")
					{
						MainModule main = val.main;
						((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Dust);
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
			}
		}

		private static void Bees(GameObject swarm)
		{
			//IL_00a3: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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)
			ParticleSystem[] componentsInChildren = swarm.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if ((Object)(object)((Component)val).gameObject != (Object)(object)swarm)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_beehive");
			GameObject val2 = ((!((Object)(object)prefab != (Object)null)) ? null : prefab.GetComponent<Beehive>()?.m_beeEffect);
			if (!((Object)(object)val2 == (Object)null))
			{
				GameObject val3 = Object.Instantiate<GameObject>(val2, swarm.transform, false);
				((Object)val3).name = "bees";
				val3.transform.localPosition = new Vector3(0f, 1f, 0f);
				val3.SetActive(true);
				componentsInChildren = val3.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem obj in componentsInChildren)
				{
					ShapeModule shape = obj.shape;
					((ShapeModule)(ref shape)).radius = 2.625f;
					EmissionModule emission = obj.emission;
					((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * 6f;
					MainModule main = obj.main;
					((MainModule)(ref main)).maxParticles = Mathf.Max(((MainModule)(ref main)).maxParticles, 400);
					((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * 2.5f;
				}
				AudioSource[] componentsInChildren2 = val3.GetComponentsInChildren<AudioSource>(true);
				foreach (AudioSource val4 in componentsInChildren2)
				{
					val4.volume = Mathf.Min(1f, val4.volume * 1.5f);
					val4.maxDistance = Mathf.Max(val4.maxDistance, 25f);
				}
			}
		}
	}
}
namespace WhereIsMyQueen.Dev
{
	public class SelfTest : MonoBehaviour
	{
		private string _out;

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

		private Vector3 _spawn;

		private int _pass;

		private int _fail;

		public static void TryStart(GameObject host)
		{
			string environmentVariable = Environment.GetEnvironmentVariable("QUEEN_SELFTEST");
			if (string.IsNullOrEmpty(environmentVariable))
			{
				return;
			}
			Application.runInBackground = true;
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			bool flag = false;
			for (int i = 0; i < commandLineArgs.Length - 1; i++)
			{
				if (commandLineArgs[i] == "-savedir" && !string.IsNullOrEmpty(commandLineArgs[i + 1]))
				{
					Directory.CreateDirectory(commandLineArgs[i + 1]);
					Utils.SetSaveDataPath(commandLineArgs[i + 1]);
					flag = true;
				}
			}
			if (!flag)
			{
				WhereIsMyQueenPlugin.Log.LogError((object)"Self test needs -savedir <scratch folder>; not starting it.");
			}
			else
			{
				host.AddComponent<SelfTest>()._out = environmentVariable;
			}
		}

		private static bool Flag(string name)
		{
			return (Environment.GetEnvironmentVariable("QUEEN_SELFTEST_" + name) ?? "") == "1";
		}

		private void Start()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			Directory.CreateDirectory(_out);
			Application.logMessageReceived += new LogCallback(OnLog);
			((MonoBehaviour)this).StartCoroutine(Run());
		}

		private void OnLog(string condition, string stackTrace, LogType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if ((int)type == 4 || (int)type == 0)
			{
				_report.Add($"[{type}] {condition}\n{stackTrace}");
			}
		}

		private IEnumerator Run()
		{
			float timeout = Time.realtimeSinceStartup + 600f;
			while (((Object)(object)FejdStartup.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null) && Time.realtimeSinceStartup < timeout)
			{
				yield return null;
			}
			yield return (object)new WaitForSecondsRealtime(4f);
			if (Flag("WORLD"))
			{
				yield return ((MonoBehaviour)this).StartCoroutine(Safe(EnterWorld()));
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					yield return ((MonoBehaviour)this).StartCoroutine(Safe(Research()));
					if (Flag("RESEARCH"))
					{
						yield return ((MonoBehaviour)this).StartCoroutine(Safe(DeepResearch()));
					}
					else if (Flag("RESEARCH2"))
					{
						yield return ((MonoBehaviour)this).StartCoroutine(Safe(DeepResearch2()));
					}
					else
					{
						if (!Flag("GEARONLY"))
						{
							yield return ((MonoBehaviour)this).StartCoroutine(Safe(Hives()));
						}
						yield return ((MonoBehaviour)this).StartCoroutine(Safe(Gear()));
					}
				}
			}
			_report.Add($"RESULT pass {_pass} fail {_fail}");
			Flush();
			Application.logMessageReceived -= new LogCallback(OnLog);
			yield return (object)new WaitForSecondsRealtime(0.5f);
			Application.Quit();
		}

		private IEnumerator Safe(IEnumerator inner)
		{
			while (true)
			{
				object current;
				try
				{
					if (!inner.MoveNext())
					{
						break;
					}
					current = inner.Current;
				}
				catch (Exception ex)
				{
					_report.Add("step failed: " + ex);
					_fail++;
					break;
				}
				yield return current;
			}
		}

		private void Flush()
		{
			File.WriteAllLines(Path.Combine(_out, "report.txt"), _report);
		}

		private IEnumerator Research()
		{
			ZNetScene instance = ZNetScene.instance;
			List<GameObject> list = (from p in instance.m_prefabs.Concat(instance.m_namedPrefabs.Values)
				where (Object)(object)p != (Object)null
				group p by ((Object)p).name into g
				select g.First() into p
				orderby ((Object)p).name
				select p).ToList();
			_report.Add("research: prefabs " + list.Count);
			foreach (GameObject item in list)
			{
				Beehive component = item.GetComponent<Beehive>();
				if (!((Object)(object)component == (Object)null))
				{
					Piece component2 = item.GetComponent<Piece>();
					string text = ((component2?.m_resources == null) ? "-" : string.Join(", ", component2.m_resources.Select(delegate(Requirement r)
					{
						ItemDrop resItem = r.m_resItem;
						return ((resItem != null) ? ((Object)resItem).name : null) + ":" + r.m_amount;
					})));
					List<string> report = _report;
					object[] obj = new object[7]
					{
						((Object)item).name,
						component.m_name,
						null,
						null,
						null,
						null,
						null
					};
					ItemDrop honeyItem = component.m_honeyItem;
					obj[2] = ((honeyItem != null) ? ((Object)honeyItem).name : null);
					obj[3] = component.m_maxHoney;
					obj[4] = component.m_secPerUnit;
					obj[5] = component.m_biome;
					obj[6] = component.m_maxCover;
					string text2 = string.Format("HIVE {0} '{1}' honey {2} max {3} secPerUnit {4} biome {5} maxCover {6} ", obj);
					object[] obj2 = new object[4]
					{
						component.m_effectOnlyInDaylight,
						((Object)(object)component.m_spawnPoint == (Object)null) ? "null" : ((object)component.m_spawnPoint.localPosition/*cast due to .constrained prefix*/).ToString(),
						text,
						null
					};
					object obj3;
					if (component2 == null)
					{
						obj3 = null;
					}
					else
					{
						CraftingStation craftingStation = component2.m_craftingStation;
						obj3 = ((craftingStation != null) ? ((Object)craftingStation).name : null);
					}
					obj2[3] = obj3;
					report.Add(text2 + string.Format("daylight {0} spawnPoint {1} cost {2} station {3}", obj2));
				}
			}
			GameObject queen = ObjectDB.instance.GetItemPrefab("QueenBee");
			GameObject obj4 = queen;
			SharedData val = ((obj4 == null) ? null : obj4.GetComponent<ItemDrop>()?.m_itemData?.m_shared);
			_report.Add($"QUEEN item {(Object)(object)queen != (Object)null} '{val?.m_name}' stack {val?.m_maxStackSize} weight {val?.m_weight} type {val?.m_itemType}");
			foreach (GameObject item2 in list)
			{
				List<string> list2 = new List<string>();
				DropOnDestroyed component3 = item2.GetComponent<DropOnDestroyed>();
				if (component3?.m_dropWhenDestroyed?.m_drops != null && component3.m_dropWhenDestroyed.m_drops.Any((DropData d) => (Object)(object)d.m_item == (Object)(object)queen))
				{
					list2.Add($"destroyed (chance {component3.m_dropWhenDestroyed.m_dropChance}, {component3.m_dropWhenDestroyed.m_dropMin}-{component3.m_dropWhenDestroyed.m_dropMax} of {component3.m_dropWhenDestroyed.m_drops.Count})");
				}
				CharacterDrop component4 = item2.GetComponent<CharacterDrop>();
				if (component4?.m_drops != null && component4.m_drops.Any((Drop d) => (Object)(object)d.m_prefab == (Object)(object)queen))
				{
					list2.Add("creature");
				}
				Pickable component5 = item2.GetComponent<Pickable>();
				if ((Object)(object)component5 != (Object)null && (Object)(object)component5.m_itemPrefab == (Object)(object)queen)
				{
					list2.Add("pickable");
				}
				if (list2.Count > 0)
				{
					_report.Add("QUEENDROP " + ((Object)item2).name + ": " + string.Join(" ", list2));
				}
			}
			Flush();
			yield break;
		}

		private unsafe IEnumerator EnterWorld()
		{
			FejdStartup instance = FejdStartup.instance;
			if ((Object)(object)instance == (Object)null)
			{
				_report.Add("world: no FejdStartup");
				yield break;
			}
			PlayerProfile val = new PlayerProfile("queentester", (FileSource)2);
			val.SetName("Beekeeper");
			val.m_firstSpawn = false;
			val.Save();
			Game.SetProfile("queentester", (FileSource)2);
			World val2 = new World("QueenTest", "HQ7GnTiegh")
			{
				m_fileSource = (FileSource)2
			};
			val2.SaveWorldFWLData(DateTime.Now);
			instance.m_world = val2;
			instance.m_startingWorld = true;
			ZNet.SetServer(true, false, false, val2.m_name, "", val2);
			ZNet.ResetServerHost();
			instance.TransitionToMainScene();
			_report.Add("world: loading " + val2.m_name + " seed " + val2.m_seedName);
			float timeout = Time.realtimeSinceStartup + 300f;
			while (((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null || ((Character)Player.m_localPlayer).IsTeleporting()) && Time.realtimeSinceStartup < timeout)
			{
				yield return null;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				_report.Add("world: player never spawned");
				yield break;
			}
			yield return (object)new WaitForSecondsRealtime(6f);
			_spawn = ((Component)Player.m_localPlayer).transform.position;
			List<string> report = _report;
			Vector3 spawn = _spawn;
			report.Add("world: spawned at " + ((object)(*(Vector3*)(&spawn))/*cast due to .constrained prefix*/).ToString());
		}

		private unsafe IEnumerator Gear()
		{
			Player p = Player.m_localPlayer;
			ObjectDB db = ObjectDB.instance;
			EnvMan.instance.m_debugTimeOfDay = true;
			EnvMan.instance.m_debugTime = 0.38f;
			Player.m_enableAutoPickup = false;
			p.SetGodMode(true);
			BeeItem[] all = BeeTable.All;
			foreach (BeeItem beeItem in all)
			{
				Give(p, beeItem.Prefab);
			}
			all = BeeTable.All;
			BeeItem i2;
			GameObject itemPrefab;
			string text;
			bool flag;
			bool flag2;
			string text2;
			int num;
			bool flag3;
			for (int i = 0; i < all.Length; flag3 = (byte)num != 0, Check((Object)(object)itemPrefab != (Object)null && flag && flag2 && !text.StartsWith("[") && !text.StartsWith("$") && flag3, $"{i2.Prefab} '{text}' icon {flag} net {flag2} recipe {text2}"), i++)
			{
				i2 = all[i];
				itemPrefab = db.GetItemPrefab(i2.Prefab);
				SharedData val = ((itemPrefab == null) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared);
				text = ((val != null) ? Localization.instance.Localize(val.m_name) : "-");
				flag = val?.m_icons != null && val.m_icons.Length != 0 && (Object)(object)val.m_icons[0] != (Object)null;
				flag2 = (Object)(object)ZNetScene.instance.GetPrefab(i2.Prefab) != (Object)null;
				Recipe r = ((IEnumerable<Recipe>)db.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe x) => (Object)(object)x?.m_item != (Object)null && ((Object)x.m_item).name == i2.Prefab));
				object obj;
				if (!((Object)(object)r == (Object)null))
				{
					CraftingStation craftingStation = r.m_craftingStation;
					obj = string.Format("{0}:{1} x{2} [", ((craftingStation != null) ? ((Object)craftingStation).name : null) ?? "hand", r.m_minStationLevel, r.m_amount) + string.Join(", ", r.m_resources.Select(delegate(Requirement q)
					{
						object[] array = new object[4];
						ItemDrop resItem = q.m_resItem;
						array[0] = ((resItem != null) ? ((Object)resItem).name : null);
						array[1] = q.m_amount;
						array[2] = q.m_amountPerLevel;
						array[3] = (q.m_upgraderResource ? "U" : "");
						return string.Format("{0}:{1}+{2}{3}", array);
					})) + "]";
				}
				else
				{
					obj = "none";
				}
				text2 = (string)obj;
				if (i2.Kind != BeeKind.Material)
				{
					if ((Object)(object)r != (Object)null)
					{
						CraftingStation craftingStation2 = r.m_craftingStation;
						if ((((craftingStation2 != null) ? ((Object)craftingStation2).name : null) ?? "") == BeeTable.Station(i2.Station).Key && r.m_minStationLevel == BeeTable.Station(i2.Station).Value && r.m_amount == i2.Amount)
						{
							num = (BeeTable.Parse(i2.Recipe).All((Cost c) => r.m_resources.Any((Requirement q) => (Object)(object)q.m_resItem != (Object)null && ((Object)q.m_resItem).name == c.Item && q.m_amount == c.Amount && q.m_amountPerLevel == c.PerLevel)) ? 1 : 0);
							continue;
						}
					}
					num = 0;
				}
				else
				{
					num = (((Object)(object)r == (Object)null) ? 1 : 0);
				}
			}
			string[] setPieces = BeeTable.SetPieces;
			foreach (string piece in setPieces)
			{
				Recipe val2 = ((IEnumerable<Recipe>)db.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe x) => (Object)(object)x?.m_item != (Object)null && ((Object)x.m_item).name == piece));
				Check((Object)(object)val2 != (Object)null && val2.m_resources.Any((Requirement q) => q.m_upgraderResource && (Object)(object)q.m_resItem != (Object)null && ((Object)q.m_resItem).name.StartsWith("Upgrader")), piece + " can be refined at the refinement forge like vanilla armour");
			}
			SelfTest selfTest = this;
			GameObject attackProjectile = db.GetItemPrefab("WIMQ_SwarmPot").GetComponent<ItemDrop>().m_itemData.m_shared.m_attack.m_attackProjectile;
			int ok;
			if (((attackProjectile != null) ? ((Object)attackProjectile).name : null) == "WIMQ_swarmpot_projectile")
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("WIMQ_swarmpot_projectile");
				object obj2;
				if (prefab == null)
				{
					obj2 = null;
				}
				else
				{
					Projectile component = prefab.GetComponent<Projectile>();
					if (component == null)
					{
						obj2 = null;
					}
					else
					{
						GameObject spawnOnHit = component.m_spawnOnHit;
						obj2 = ((spawnOnHit != null) ? ((Object)spawnOnHit).name : null);
					}
				}
				if ((string?)obj2 == "WIMQ_swarmpot_swarm")
				{
					ok = (((Object)(object)ZNetScene.instance.GetPrefab("WIMQ_swarmpot_swarm") != (Object)null) ? 1 : 0);
					goto IL_0550;
				}
			}
			ok = 0;
			goto IL_0550;
			IL_0550:
			selfTest.Check((byte)ok != 0, "swarm pot throws its projectile, which lets the swarm loose (both networked)");
			Vector3 spot = FlatSpot(_spawn) + new Vector3(30f, 0f, 0f);
			Stand(p, spot + new Vector3(0f, 0f, -6f));
			yield return (object)new WaitForSecondsRealtime(3f);
			Stand(p, spot + new Vector3(0f, 0f, -6f));
			ClearArea(spot, 25f);
			yield return (object)new WaitForSecondsRealtime(1f);
			Beehive hive = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("piece_beehive"), Ground(spot), Quaternion.identity).GetComponent<Beehive>();
			yield return null;
			Vector3 drop = (((Object)(object)hive.m_spawnPoint != (Object)null) ? hive.m_spawnPoint.position : ((Component)hive).transform.position);
			int oldOneIn = Cfg.ChanceOneIn.Value;
			Cfg.ChanceOneIn.Value = 0;
			ClearDrops(drop);
			SetHoney(hive, hive.m_maxHoney);
			hive.RPC_Extract(ZRoutedRpc.instance.m_id);
			Check(Count(drop, "WIMQ_Beeswax") == 2 && Count(drop, "Honey") == hive.m_maxHoney, string.Format("full hive: {0} beeswax (must be 2) with {1} honey", Count(drop, "WIMQ_Beeswax"), Count(drop, "Honey")));
			ClearDrops(drop);
			int waxBefore = Beeswax.Spawned;
			for (int k = 0; k < 400; k++)
			{
				SetHoney(hive, 1);
				hive.RPC_Extract(ZRoutedRpc.instance.m_id);
				if (k % 25 == 24)
				{
					ClearDrops(drop);
					yield return null;
				}
			}
			int num2 = Beeswax.Spawned - waxBefore;
			Check(num2 >= 150 && num2 <= 250, $"400 harvests of one honey: {num2} wax (expected 200, the same per jar as full hives)");
			ClearDrops(drop);
			GameObject prefab2 = ZNetScene.instance.GetPrefab("Beehive");
			Vector3 wildAt = Ground(spot + new Vector3(6f, 0f, 0f)) + Vector3.up * 1.5f;
			GameObject wild = (((Object)(object)prefab2 != (Object)null) ? Object.Instantiate<GameObject>(prefab2, wildAt, Quaternion.identity) : null);
			yield return null;
			waxBefore = Beeswax.Spawned;
			if (wild != null)
			{
				WearNTear component2 = wild.GetComponent<WearNTear>();
				if (component2 != null)
				{
					component2.Remove(false);
				}
			}
			yield return (object)new WaitForSecondsRealtime(0.5f);
			int num3 = Beeswax.Spawned - waxBefore;
			Check(num3 >= 1 && num3 <= 2 && Count(wildAt, "WIMQ_Beeswax") == num3, string.Format("wild hive knocked down: {0} beeswax (1..2) with its {1} honey, {2} queen", num3, Count(wildAt, "Honey"), Count(wildAt, "QueenBee")));
			ClearDrops(wildAt);
			List<ItemData> pieces = BeeTable.SetPieces.Select((string n) => Give(p, n)).ToList();
			float armourBefore = ((Character)p).GetBodyArmor();
			Check(!BeeGear.WearsSet(p), "before dressing: not a beekeeper");
			foreach (ItemData item in pieces)
			{
				if (item != null)
				{
					((Humanoid)p).EquipItem(item, false);
				}
			}
			yield return (object)new WaitForSecondsRealtime(0.5f);
			bool flag4 = ((Character)p).GetSEMan().HaveStatusEffect(((StatusEffect)BeeItems.SetEffect).NameHash());
			DamageModifiers damageModifiers = ((Character)p).GetDamageModifiers((WeakSpot)null);
			Check(BeeGear.WearsSet(p) && flag4, $"in hat, smock and trousers: wears the set {BeeGear.WearsSet(p)}, set effect '{Localization.instance.Localize(((StatusEffect)BeeItems.SetEffect).m_name)}' {flag4}");
			float num4 = ((IEnumerable<ItemData>)(object)new ItemData[4]
			{
				((Humanoid)p).m_helmetItem,
				((Humanoid)p).m_chestItem,
				((Humanoid)p).m_legItem,
				((Humanoid)p).m_shoulderItem
			}).Where((ItemData x) => x != null).Sum((ItemData x) => x.GetArmor());
			Check(Mathf.Approximately(num4, ((Character)p).GetBodyArmor()) && pieces.All((ItemData x) => x != null && Mathf.Approximately(x.GetArmor(), 4f)), $"set armour 3 x 4 at quality 1: body armour {((Character)p).GetBodyArmor()} (before {armourBefore})");
			Check((int)damageModifiers.m_poison == 1, "set gives poison resistance: " + ((object)(*(DamageModifier*)(&damageModifiers.m_poison))/*cast due to .constrained prefix*/).ToString());
			Check(Math.Abs(BeeGear.QueenBonus(ZRoutedRpc.instance.m_id) - (double)Cfg.SetQueenBonus.Value) < 1E-06, $"queen bonus for the harvester in the set: x{BeeGear.QueenBonus(ZRoutedRpc.instance.m_id)}");
			string text3 = Plain(Localization.instance.Localize(((StatusEffect)BeeItems.SetEffect).GetTooltipString()));
			Note("set tooltip: " + text3);
			Stand(p, ((Component)hive).transform.position + new Vector3(1.4f, 0f, -1.2f));
			((Component)p).transform.rotation = Quaternion.LookRotation(((Component)hive).transform.position - ((Component)p).transform.position);
			((Character)p).SetLookDir(((Component)p).transform.forward, 0f);
			p.m_lookPitch = 0f;
			((Character)p).UpdateEyeRotation();
			yield return (object)new WaitForSecondsRealtime(1.5f);
			Vector3 chest = ((Component)p).transform.position + Vector3.up * 1.15f;
			yield return ((MonoBehaviour)this).StartCoroutine(Safe(MainShot("10_beekeeper_front", Look(chest, ((Component)p).transform.eulerAngles.y + 20f, 2.6f, 0.35f), 40f)));
			yield return ((MonoBehaviour)this).StartCoroutine(Safe(MainShot("11_beekeeper_back", Look(chest, ((Component)p).transform.eulerAngles.y + 160f, 2.6f, 0.45f), 40f)));
			yield return ((MonoBehaviour)this).StartCoroutine(Safe(MainShot("12_beekeeper_face", Look(chest + Vector3.up * 0.5f, ((Component)p).transform.eulerAngles.y + 10f, 1.2f, 0.1f), 40f)));
			Cfg.ChanceOneIn.Value = 30;
			int qBefore = HiveQueen.Spawned;
			for (int k = 0; k < 900; k++)
			{
				SetHoney(hive, hive.m_maxHoney);
				hive.RPC_Extract(ZRoutedRpc.instance.m_id);
				if (k % 20 == 19)
				{
					ClearDrops(drop);
					yield return null;
				}
			}
			int num5 = HiveQueen.Spawned - qBefore;
			Check(num5 >= 36 && num5 <= 88, $"in the set, 900 full harvests at 1 in 30: {num5} queens (expected 60 with bonus x2, 30 without)");
			ClearDrops(drop);
			Cfg.ChanceOneIn.Value = oldOneIn;
			p.SetGodMode(false);
			((Character)p).SetHealth(((Character)p).GetMaxHealth());
			GameObject prefab3 = ZNetScene.instance.GetPrefab("WIMQ_swarmpot_swarm");
			GameObject sw = Object.Instantiate<GameObject>(prefab3, ((Component)p).transform.position, Quaternion.identity);
			float hp0 = ((Character)p).GetHealth();
			yield return (object)new WaitForSecondsRealtime(3.5f);
			Check(((Character)p).GetHealth() >= hp0 - 0.01f, $"in the set, the swarm does not sting: health {hp0:0.#} → {((Character)p).GetHealth():0.#}");
			((Humanoid)p).UnequipItem(pieces[1], false);
			yield return (object)new WaitForSecondsRealtime(3.5f);
			float health = ((Character)p).GetHealth();
			Check(health < hp0 - 1f, $"without the smock, the swarm stings: health {hp0:0.#} → {health:0.#}");
			p.SetGodMode(true);
			((Character)p).SetHealth(((Character)p).GetMaxHealth());
			((Humanoid)p).EquipItem(pieces[1], false);
			Remove((Component)(object)sw.GetComponent<ZNetView>());
			yield return (object)new WaitForSecondsRealtime(1f);
			Vector3 val3 = Ground(spot + new Vector3(-7f, 0f, 4f));
			Character troll = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("Troll"), val3, Quaternion.Euler(0f, 90f, 0f)).GetComponent<Character>();
			yield return null;
			BaseAI component3 = ((Component)troll).GetComponent<BaseAI>();
			if ((Object)(object)component3 != (Object)null)
			{
				((Behaviour)component3).enabled = false;
			}
			yield return (object)new WaitForSecondsRealtime(0.5f);
			float t0 = troll.GetHealth();
			GameObject obj3 = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("WIMQ_swarmpot_projectile"), ((Component)trol