Decompiled source of VargheimProfessions v0.9.21

plugins/VargheimProfessions.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VargheimProfessions
{
	public static class Api
	{
		public sealed class Perk
		{
			public int Level;

			public string Name;

			public string Text;

			public Perk(int level, string name, string text)
			{
				Level = level;
				Name = name;
				Text = text;
			}
		}

		public sealed class Ladder
		{
			public string Profession;

			public string Mod;

			public string Summary;

			public List<Perk> Perks = new List<Perk>();
		}

		private static readonly HashSet<string> s_oops = new HashSet<string>();

		private const int OopsMax = 512;

		internal static readonly Dictionary<string, Ladder> Ladders = new Dictionary<string, Ladder>(StringComparer.Ordinal);

		private static float s_nextPublish;

		private static MethodInfo s_groupPlayers;

		private static FieldInfo s_refName;

		private static bool s_groupsLooked;

		public static string[] Professions => (string[])Rules.All.Clone();

		public static bool Active => Plugin.IsActive;

		public static event Action Changed;

		public static void Oops(string where, Exception ex)
		{
			if (where == null)
			{
				where = "?";
			}
			string item = OopsKey(where, ex);
			lock (s_oops)
			{
				if (s_oops.Count >= 512 || !s_oops.Add(item))
				{
					return;
				}
			}
			Debug.LogWarning((object)("Vargheim: " + where + " stopped working (game update?): " + ((ex != null) ? (ex.GetType().Name + ": " + ex.Message) : "unknown") + " - this is logged once."));
		}

		internal static string OopsKey(string where, Exception ex)
		{
			if (ex == null)
			{
				return where + "|?";
			}
			return where + "|" + ex.GetType().FullName + "|" + OopsSite(ex);
		}

		private static string OopsSite(Exception ex)
		{
			try
			{
				StackTrace stackTrace = new StackTrace(ex, fNeedFileInfo: false);
				for (int i = 0; i < stackTrace.FrameCount; i++)
				{
					MethodBase method = stackTrace.GetFrame(i).GetMethod();
					if (!(method == null) && !(method.DeclaringType == null) && (method.DeclaringType.Namespace ?? "").StartsWith("Vargheim", StringComparison.Ordinal))
					{
						return method.DeclaringType.Name + "." + method.Name;
					}
				}
			}
			catch
			{
			}
			return "";
		}

		internal static void RaiseChanged()
		{
			Action changed = Api.Changed;
			if (changed == null)
			{
				return;
			}
			Delegate[] invocationList;
			try
			{
				invocationList = changed.GetInvocationList();
			}
			catch (Exception ex)
			{
				Plugin.Warn("Changed handler list: " + ex.Message);
				return;
			}
			for (int i = 0; i < invocationList.Length; i++)
			{
				if (invocationList[i] is Action action)
				{
					try
					{
						action();
					}
					catch (Exception ex2)
					{
						string text = ((action.Method != null && action.Method.DeclaringType != null) ? (action.Method.DeclaringType.FullName + "." + action.Method.Name) : "?");
						Oops("Api.Changed subscriber " + text, ex2);
					}
				}
			}
		}

		public static string Display(string prof)
		{
			return Rules.Display(prof);
		}

		public static int TierLevel(int tier)
		{
			return Plugin.TierLevelFromConfig(tier);
		}

		public static int BiomeTier(Biome b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			if ((int)b <= 16)
			{
				switch (b - 1)
				{
				default:
					if ((int)b != 8)
					{
						if ((int)b != 16)
						{
							break;
						}
						return 4;
					}
					return 1;
				case 0:
					return 0;
				case 1:
					return 2;
				case 3:
					return 3;
				case 2:
					break;
				}
			}
			else if ((int)b <= 64)
			{
				if ((int)b == 32)
				{
					return 6;
				}
				if ((int)b == 64)
				{
					return 7;
				}
			}
			else
			{
				if ((int)b == 256)
				{
					return 1;
				}
				if ((int)b == 512)
				{
					return 5;
				}
			}
			return 0;
		}

		public static bool Has(string prof)
		{
			return Plugin.HasProf(prof);
		}

		public static float Level(string prof)
		{
			return Plugin.LocalLevel(prof);
		}

		public static int PerkLevel(string prof)
		{
			if (Plugin.IsActive && !Plugin.HasProf(prof))
			{
				return 0;
			}
			return Mathf.FloorToInt(Plugin.LocalLevel(prof));
		}

		public static bool AdminBypass()
		{
			return Plugin.AdminBypass();
		}

		public static bool HasPerk(string prof, int level)
		{
			return PerkLevel(prof) >= level;
		}

		public static int PerkLevelOf(Player p, string prof)
		{
			if ((Object)(object)p == (Object)null)
			{
				return 0;
			}
			if ((Object)(object)p == (Object)(object)Player.m_localPlayer)
			{
				return PerkLevel(prof);
			}
			ZNetView component = ((Component)p).GetComponent<ZNetView>();
			ZDO val = (((Object)(object)component != (Object)null && component.IsValid()) ? component.GetZDO() : null);
			if (val == null)
			{
				return 0;
			}
			return val.GetInt("vp_lv_" + prof, 0);
		}

		internal static void Publish(Player p)
		{
			if ((Object)(object)p == (Object)null || Time.time < s_nextPublish)
			{
				return;
			}
			s_nextPublish = Time.time + 5f;
			ZNetView component = ((Component)p).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return;
			}
			ZDO zDO = component.GetZDO();
			string[] all = Rules.All;
			foreach (string text in all)
			{
				int num = PerkLevel(text);
				if (zDO.GetInt("vp_lv_" + text, -1) != num)
				{
					zDO.Set("vp_lv_" + text, num);
				}
			}
		}

		public static void RegisterLadder(string prof, string mod, string summary, params Perk[] perks)
		{
			if (Rules.Normalize(prof) == null)
			{
				Plugin.Warn(mod + " registered perks for unknown profession '" + prof + "'.");
				return;
			}
			Ladder ladder = new Ladder
			{
				Profession = Rules.Normalize(prof),
				Mod = mod,
				Summary = summary
			};
			ladder.Perks.AddRange(perks);
			ladder.Perks.Sort((Perk a, Perk b) => a.Level.CompareTo(b.Level));
			Ladders[ladder.Profession] = ladder;
		}

		public static void Message(string text)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
		}

		public static void Note(string text)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)1, text, 0, (Sprite)null, false);
			}
		}

		public static HashSet<string> GroupMemberNames()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			try
			{
				if (!s_groupsLooked)
				{
					s_groupsLooked = true;
					Type type = AccessTools.TypeByName("Groups.API");
					Type type2 = AccessTools.TypeByName("Groups.PlayerReference");
					s_groupPlayers = ((type != null) ? AccessTools.Method(type, "GroupPlayers", (Type[])null, (Type[])null) : null);
					s_refName = ((type2 != null) ? AccessTools.Field(type2, "name") : null);
				}
				if (s_groupPlayers == null || s_refName == null)
				{
					return hashSet;
				}
				if (s_groupPlayers.Invoke(null, null) is IEnumerable enumerable)
				{
					foreach (object item in enumerable)
					{
						string text = s_refName.GetValue(item) as string;
						if (!string.IsNullOrEmpty(text))
						{
							hashSet.Add(text);
						}
					}
				}
			}
			catch
			{
			}
			return hashSet;
		}

		public static bool InMyGroup(Player other)
		{
			if ((Object)(object)other != (Object)null && (Object)(object)other != (Object)(object)Player.m_localPlayer)
			{
				return GroupMemberNames().Contains(other.GetPlayerName());
			}
			return false;
		}

		public static List<Player> GroupMembersNear(Vector3 point, float range)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			List<Player> list = new List<Player>();
			Player.GetPlayersInRange(point, range, list);
			HashSet<string> names = GroupMemberNames();
			list.RemoveAll((Player p) => (Object)(object)p == (Object)null || (Object)(object)p == (Object)(object)Player.m_localPlayer || !names.Contains(p.GetPlayerName()));
			return list;
		}
	}
	internal static class Bait
	{
		[HarmonyPatch]
		internal static class BaitPatches
		{
			[HarmonyPatch(typeof(ZNetScene), "Awake")]
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void ZNetScene_Awake(ZNetScene __instance)
			{
				try
				{
					OnZNetScene(__instance);
				}
				catch (Exception ex)
				{
					Plugin.Warn("bait: " + ex.Message);
				}
			}
		}

		internal const string Meadows = "VargheimBaitMeadows";

		internal const string Forest = "VargheimBaitForest";

		private static ConfigEntry<bool> s_on;

		private static ConfigEntry<string> s_meadowsRecipe;

		private static ConfigEntry<string> s_forestRecipe;

		private static ConfigEntry<string> s_meadowsFish;

		private static ConfigEntry<string> s_forestFish;

		private static ConfigEntry<int> s_amount;

		private static readonly HashSet<string> s_done = new HashSet<string>(StringComparer.Ordinal);

		private static string s_applied;

		internal static void Bind(ConfigFile cfg)
		{
			cfg.SettingChanged += delegate(object s, SettingChangedEventArgs e)
			{
				if (e != null && e.ChangedSetting != null && e.ChangedSetting.Definition.Section == "Bait")
				{
					Refresh(ObjectDB.instance);
				}
			};
			cfg.ConfigReloaded += delegate
			{
				Refresh(ObjectDB.instance);
			};
			s_on = cfg.Bind<bool>("Bait", "Enabled", true, "Add Simple Bait (Meadows) and Forest Bait (Black Forest), craftable at a workbench. Synced to players by the config lock.");
			s_amount = cfg.Bind<int>("Bait", "Amount", 20, "Bait per craft.");
			s_meadowsRecipe = cfg.Bind<string>("Bait", "MeadowsRecipe", "NeckTail:5,Honey:4", "Simple Bait materials (prefab:count, ...).");
			s_forestRecipe = cfg.Bind<string>("Bait", "ForestRecipe", "GreydwarfEye:5,Thistle:4", "Forest Bait materials (prefab:count, ...).");
			s_meadowsFish = cfg.Bind<string>("Bait", "MeadowsFish", "Fish1", "Fish prefabs Simple Bait can hook (comma separated). Fish1 = Perch.");
			s_forestFish = cfg.Bind<string>("Bait", "ForestFish", "Fish2", "Fish prefabs Forest Bait can hook (comma separated). Fish2 = Pike.");
		}

		internal static void Register()
		{
			if (s_on.Value)
			{
				Content.AddItem("FishingBait", "VargheimBaitMeadows", "Simple Bait", "Neck tail rolled in honey. Only a perch is dumb enough to bite. Hooks the smallest Meadows fish.", delegate(SharedData s)
				{
					s.m_maxStackSize = 100;
				});
				Content.AddItem("FishingBait", "VargheimBaitForest", "Forest Bait", "A greydwarf eye wrapped in thistle. Hooks the smallest Black Forest fish.", delegate(SharedData s)
				{
					s.m_maxStackSize = 100;
				});
				Content.AddRecipe("VargheimBaitMeadows", "piece_workbench", 1, Math.Max(1, s_amount.Value), s_meadowsRecipe.Value, null, 0);
				Content.AddRecipe("VargheimBaitForest", "piece_workbench", 1, Math.Max(1, s_amount.Value), s_forestRecipe.Value, null, 0);
			}
		}

		internal static void Refresh(ObjectDB db)
		{
			if (s_on == null || (Object)(object)db == (Object)null || db.m_recipes == null)
			{
				return;
			}
			try
			{
				int amount = Math.Max(1, s_amount.Value);
				string text = s_on.Value + "|" + amount + "|" + s_meadowsRecipe.Value + "|" + s_forestRecipe.Value + "|" + ((Object)db).GetInstanceID();
				Content.UpdateRecipeSpec("VargheimBaitMeadows", amount, s_meadowsRecipe.Value);
				Content.UpdateRecipeSpec("VargheimBaitForest", amount, s_forestRecipe.Value);
				int num = 0;
				foreach (Recipe recipe in db.m_recipes)
				{
					if (!((Object)(object)recipe == (Object)null) && (!(((Object)recipe).name != "Recipe_VargheimBaitMeadows") || !(((Object)recipe).name != "Recipe_VargheimBaitForest")))
					{
						string text2 = ((((Object)recipe).name == "Recipe_VargheimBaitMeadows") ? s_meadowsRecipe.Value : s_forestRecipe.Value);
						recipe.m_enabled = s_on.Value;
						recipe.m_amount = amount;
						Requirement[] array = Content.Reqs(db, text2, recover: true);
						if (array.Length != 0)
						{
							recipe.m_resources = array;
						}
						num++;
					}
				}
				if (num > 0 && text != s_applied)
				{
					s_applied = text;
					Plugin.Note("bait: " + num + " recipes set to " + amount + " per craft" + (s_on.Value ? "" : " (switched off)") + ".");
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("bait refresh: " + ex.Message);
			}
		}

		internal static void OnZNetScene(ZNetScene zs)
		{
			if (s_on.Value && !((Object)(object)zs == (Object)null))
			{
				Hook(zs, "VargheimBaitMeadows", s_meadowsFish.Value);
				Hook(zs, "VargheimBaitForest", s_forestFish.Value);
			}
		}

		private static void Hook(ZNetScene zs, string bait, string fishList)
		{
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			GameObject prefab = zs.GetPrefab(bait);
			if ((Object)(object)prefab == (Object)null)
			{
				return;
			}
			ItemDrop component = prefab.GetComponent<ItemDrop>();
			string[] array = (fishList ?? string.Empty).Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length == 0 || s_done.Contains(bait + "|" + text))
				{
					continue;
				}
				GameObject prefab2 = zs.GetPrefab(text);
				Fish val = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<Fish>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Warn("bait: fish " + text + " not found.");
					s_done.Add(bait + "|" + text);
					continue;
				}
				if (val.m_baits == null)
				{
					val.m_baits = new List<BaitSetting>();
				}
				float num = 0.5f;
				bool flag = false;
				foreach (BaitSetting bait2 in val.m_baits)
				{
					if (bait2 != null && !((Object)(object)bait2.m_bait == (Object)null))
					{
						if (((Object)bait2.m_bait).name == "FishingBait")
						{
							num = bait2.m_chance;
						}
						if (((Object)bait2.m_bait).name == bait)
						{
							flag = true;
						}
					}
				}
				if (!flag)
				{
					val.m_baits.Add(new BaitSetting
					{
						m_bait = component,
						m_chance = num
					});
				}
				s_done.Add(bait + "|" + text);
				Plugin.Note("bait: " + bait + " hooks " + text + " at " + Mathf.RoundToInt(num * 100f) + "%.");
			}
		}
	}
	[BepInPlugin("digi.vargheim.professions", "VargheimProfessions", "0.9.21")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static class BenchSurface
		{
			private static Material Body(Transform child)
			{
				MeshRenderer val = (((Object)(object)child != (Object)null) ? ((Component)child).GetComponent<MeshRenderer>() : null);
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2.shader != (Object)null && ((Object)val2.shader).name == "Custom/Piece" && val2.renderQueue <= 2500 && val2.HasProperty("_MainTex"))
					{
						return val2;
					}
				}
				return null;
			}

			internal static Material FindBody(GameObject bench)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Invalid comparison between Unknown and I4
				if ((int)SystemInfo.graphicsDeviceType == 4)
				{
					return null;
				}
				return Body(bench.transform.Find("New/high")) ?? Body(bench.transform.Find("New/low"));
			}

			internal static Material Create(GameObject bench, Material wood, Texture2D atlas)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Expected O, but got Unknown
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				Material val;
				if ((Object)(object)wood != (Object)null)
				{
					val = new Material(wood);
				}
				else
				{
					Shader val2 = Shader.Find("Custom/Piece") ?? Shader.Find("Standard");
					if ((Object)(object)val2 == (Object)null)
					{
						Warn(((Object)bench).name + ": no lit bench shader available.");
						return null;
					}
					val = new Material(val2);
					Warn(((Object)bench).name + ": workbench body material unavailable; using " + ((Object)val2).name + ".");
				}
				((Object)val).name = ((Object)bench).name;
				val.SetTexture("_MainTex", (Texture)(object)atlas);
				val.SetTextureScale("_MainTex", Vector2.one);
				val.SetTextureOffset("_MainTex", Vector2.zero);
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", Color.white);
				}
				if (val.HasProperty("_BumpMap"))
				{
					val.SetTexture("_BumpMap", (Texture)null);
				}
				if (val.HasProperty("_BumpScale"))
				{
					val.SetFloat("_BumpScale", 0f);
				}
				val.DisableKeyword("_NORMALMAP");
				if (val.HasProperty("_ValueNoise"))
				{
					val.SetFloat("_ValueNoise", 0f);
				}
				if (val.HasProperty("_Cutoff"))
				{
					val.SetFloat("_Cutoff", 0f);
				}
				Note(((Object)bench).name + ": bench material " + ((Object)val.shader).name + " from " + (((Object)(object)wood != (Object)null) ? ((Object)wood).name : "shader defaults") + ", atlas " + ((Object)atlas).name + ".");
				return val;
			}
		}

		internal static class BuilderBench
		{
			internal const string Prefab = "VP_BuilderBench";

			internal const string StationName = "Builder's bench";

			private static ConfigEntry<bool> s_on;

			private static ConfigEntry<string> s_recipe;

			private static ConfigEntry<int> s_level;

			private static ConfigEntry<float> s_yaw;

			private static ConfigEntry<float> s_use;

			private static ConfigEntry<float> s_lod0;

			private static ConfigEntry<float> s_lod1;

			internal static bool Enabled
			{
				get
				{
					if (s_on != null)
					{
						return s_on.Value;
					}
					return false;
				}
			}

			internal static void Bind(ConfigFile cfg)
			{
				s_on = cfg.Bind<bool>("Builder Bench", "Enabled", true, "The Builder's bench: a station that crafts only our modded Builder items (the Builder hammers). Off = the Builder hammers are made at Builder Hammers > Station instead (workbench). Server and client (synced).");
				s_recipe = cfg.Bind<string>("Builder Bench", "Recipe", "Wood:10,Stone:4", "Materials to build the Builder's bench (provisional - Digi sets costs).");
				s_level = cfg.Bind<int>("Builder Bench", "BuildLevel", -1, "Building level to build the bench. -1 = the Meadows tier level (Tier Gates > TierLevels), so every Builder hammer can be crafted once the bench stands.");
				s_yaw = cfg.Bind<float>("Builder Bench", "ModelYaw", 0f, "Degrees to turn the bench art and colliders about the vertical axis (native-fixture tuning; 180 if the vise/work side faces the wrong way).");
				s_use = cfg.Bind<float>("Builder Bench", "UseDistance", 2f, "How far from the bench a player can use it (art contract: 2.0 m).");
				s_lod0 = cfg.Bind<float>("Builder Bench", "Lod0ScreenHeight", 0.25f, "Screen height below which the simpler distance mesh is shown (native-fixture tuning).");
				s_lod1 = cfg.Bind<float>("Builder Bench", "Lod1ScreenHeight", 0.02f, "Screen height below which the bench is not drawn at all.");
				if (s_on.Value)
				{
					int level = ((s_level.Value >= 0) ? s_level.Value : TierLevelFromConfig(0));
					Content.AddPiece("piece_workbench", "VP_BuilderBench", "Builder's bench", "A joiner's bench for the Builder. Builder's and biome builder's hammers are made here; nothing else. It does not count as a workbench.", "Hammer", s_recipe.Value, "Building", level, Setup);
				}
			}

			internal static string HammerStation(string configured)
			{
				if (configured == "VP_BuilderBench" && !Enabled)
				{
					return "piece_workbench";
				}
				return configured;
			}

			private static bool Under(Transform t, Component root)
			{
				if ((Object)(object)root != (Object)null)
				{
					return t.IsChildOf(root.transform);
				}
				return false;
			}

			private static bool Under(Transform t, GameObject root)
			{
				if ((Object)(object)root != (Object)null)
				{
					return t.IsChildOf(root.transform);
				}
				return false;
			}

			private static void Setup(GameObject go)
			{
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Expected O, but got Unknown
				//IL_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: 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_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_0252: Unknown result type (might be due to invalid IL or missing references)
				//IL_0258: Invalid comparison between Unknown and I4
				CraftingStation component = go.GetComponent<CraftingStation>();
				if ((Object)(object)component == (Object)null)
				{
					Warn("builder bench: base piece has no CraftingStation - left as a plain copy.");
					return;
				}
				component.m_name = "Builder's bench";
				component.m_showBasicRecipies = false;
				component.m_useDistance = Mathf.Max(0.5f, s_use.Value);
				Material wood = BenchSurface.FindBody(go);
				int num = 0;
				int num2 = 0;
				LODGroup[] componentsInChildren = go.GetComponentsInChildren<LODGroup>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
				MeshRenderer[] componentsInChildren2 = go.GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val in componentsInChildren2)
				{
					Transform transform = ((Component)val).transform;
					if (!Under(transform, component.m_areaMarker) && !Under(transform, component.m_inUseObject) && !Under(transform, component.m_haveFireObject))
					{
						MeshFilter component2 = ((Component)val).GetComponent<MeshFilter>();
						Object.DestroyImmediate((Object)(object)val);
						if ((Object)(object)component2 != (Object)null)
						{
							Object.DestroyImmediate((Object)(object)component2);
						}
						num++;
					}
				}
				Collider[] componentsInChildren3 = go.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren3)
				{
					if (!val2.isTrigger && !((Object)(object)val2 == (Object)(object)component.m_effectAreaCollider) && !Under(((Component)val2).transform, component.m_areaMarker))
					{
						Object.DestroyImmediate((Object)(object)val2);
						num2++;
					}
				}
				GameObject val3 = new GameObject("VP_BenchPivot");
				val3.layer = go.layer;
				val3.transform.SetParent(go.transform, false);
				val3.transform.localRotation = Quaternion.Euler(0f, s_yaw.Value, 0f);
				int layer = LayerMask.NameToLayer("piece");
				AddBox(val3.transform, layer, new Vector3(0f, 0.495f, 0f), new Vector3(2.8f, 0.99f, 0.96f));
				AddBox(val3.transform, layer, new Vector3(-1.52f, 0.78f, 0f), new Vector3(0.31f, 0.36f, 0.62f));
				AddBox(val3.transform, layer, new Vector3(0f, 1.26f, -0.4f), new Vector3(1.88f, 0.46f, 0.2f));
				bool flag = false;
				if ((int)SystemInfo.graphicsDeviceType != 4)
				{
					flag = Dress(go, val3.transform, wood);
				}
				Note("builder bench: station 'Builder's bench' ready (" + num + " workbench renderers, " + num2 + " colliders replaced; art " + (flag ? "loaded" : "not loaded") + "; yaw " + s_yaw.Value + ").");
			}

			private static void AddBox(Transform parent, int layer, Vector3 center, Vector3 size)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("VP_BenchCollider")
				{
					layer = ((layer >= 0) ? layer : ((Component)parent).gameObject.layer)
				};
				val.transform.SetParent(parent, false);
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = center;
				obj.size = size;
			}

			private static bool Dress(GameObject go, Transform pivot, Material wood)
			{
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Expected O, but got Unknown
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
				Mesh val = ToolArt.MeshOf("builder_bench.obj");
				Mesh val2 = ToolArt.MeshOf("builder_bench_lod1.obj");
				Texture2D val3 = ToolArt.TexOf("builder_bench.png", icon: false);
				if ((Object)(object)val == (Object)null || (Object)(object)val3 == (Object)null)
				{
					return false;
				}
				Material val4 = BenchSurface.Create(go, wood, val3);
				if ((Object)(object)val4 == (Object)null)
				{
					return false;
				}
				GameObject val5 = new GameObject("VP_BenchModel");
				val5.layer = go.layer;
				val5.transform.SetParent(pivot, false);
				Renderer val6 = AddMesh(val5.transform, "LOD0", val, val4);
				List<LOD> list = new List<LOD>();
				list.Add(new LOD(Mathf.Clamp01(s_lod0.Value), (Renderer[])(object)new Renderer[1] { val6 }));
				List<LOD> list2 = list;
				if ((Object)(object)val2 != (Object)null)
				{
					Renderer val7 = AddMesh(val5.transform, "LOD1", val2, val4);
					list2.Add(new LOD(Mathf.Clamp(s_lod1.Value, 0f, Mathf.Clamp01(s_lod0.Value)), (Renderer[])(object)new Renderer[1] { val7 }));
				}
				else
				{
					list2[0] = new LOD(Mathf.Clamp01(s_lod1.Value), (Renderer[])(object)new Renderer[1] { val6 });
				}
				LODGroup obj = val5.AddComponent<LODGroup>();
				obj.SetLODs(list2.ToArray());
				obj.RecalculateBounds();
				Texture2D val8 = ToolArt.TexOf("builder_bench_icon.png", icon: true);
				Piece component = go.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null && (Object)(object)val8 != (Object)null)
				{
					Sprite val9 = Sprite.Create(val8, new Rect(0f, 0f, (float)((Texture)val8).width, (float)((Texture)val8).height), new Vector2(0.5f, 0.5f), 100f);
					((Object)val9).name = "VP_BuilderBench_icon";
					component.m_icon = val9;
					CraftingStation component2 = go.GetComponent<CraftingStation>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.m_icon = val9;
					}
				}
				return true;
			}

			private static Renderer AddMesh(Transform parent, string name, 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_0017: 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)
				GameObject val = new GameObject(name)
				{
					layer = ((Component)parent).gameObject.layer
				};
				val.transform.SetParent(parent, false);
				val.AddComponent<MeshFilter>().sharedMesh = mesh;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = mat;
				return (Renderer)(object)obj;
			}
		}

		internal sealed class Gate
		{
			public string Prof;

			public int Level;

			public string Why;

			public string[] AnyOf;

			public int Tier = -1;

			public string Who
			{
				get
				{
					if (AnyOf != null)
					{
						return string.Join(" / ", Array.ConvertAll(AnyOf, Rules.Title));
					}
					return Rules.Title(Prof);
				}
			}

			public int TierIndex
			{
				get
				{
					if (Tier < 0)
					{
						return TierOfLevel(Level);
					}
					return Tier;
				}
			}
		}

		internal static class Hammers
		{
			[HarmonyPatch]
			internal static class HammerPatches
			{
				[HarmonyPatch(typeof(ZNetScene), "Awake")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void SceneAwake()
				{
					try
					{
						if ((Object)(object)ObjectDB.instance != (Object)null)
						{
							Apply(ObjectDB.instance);
						}
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/Hammers.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ObjectDB), "Awake")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbAwake(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/Hammers.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ZoneSystem), "Start")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void WorldStart()
				{
					try
					{
						if ((Object)(object)ObjectDB.instance != (Object)null)
						{
							Apply(ObjectDB.instance);
						}
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/Hammers.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbCopy(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/Hammers.cs", ex);
					}
				}
			}

			internal const string MasterPrefab = "VP_BuilderHammer";

			internal static readonly string[] BiomeKeys = new string[8] { "Meadows", "BlackForest", "Swamp", "Mountains", "Plains", "Mistlands", "Ashlands", "DeepNorth" };

			private static readonly string[] BiomeNames = new string[8] { "Meadows", "Black Forest", "Swamp", "Mountain", "Plains", "Mistlands", "Ashlands", "Deep North" };

			private static readonly string[] DefaultCosts = new string[8] { "Wood:3,Stone:2", "RoundLog:3,Bronze:1", "ElderBark:3,Iron:1", "FineWood:3,Silver:1", "FineWood:3,BlackMetal:1", "YggdrasilWood:3,BlackMarble:2", "Blackwood:3,FlametalNew:1", "Frostwood:3,Ice:1" };

			private static ConfigEntry<bool> s_on;

			private static ConfigEntry<bool> s_retire;

			private static ConfigEntry<int> s_masterLevel;

			private static ConfigEntry<string> s_masterCost;

			private static ConfigEntry<string> s_keep;

			private static ConfigEntry<string> s_extraTools;

			private static ConfigEntry<string> s_station;

			private static readonly ConfigEntry<string>[] s_cost = new ConfigEntry<string>[8];

			private static readonly PieceTable[] s_tables = (PieceTable[])(object)new PieceTable[9];

			private static GameObject s_holder;

			private static string s_logged;

			internal static string BiomePrefab(int tier)
			{
				return "VP_BuilderHammer_" + BiomeKeys[tier];
			}

			internal static void Bind(ConfigFile cfg)
			{
				s_on = cfg.Bind<bool>("Builder Hammers", "Enabled", true, "Modded build pieces gated to Building leave the vanilla Hammer for the Builder hammers (a master hammer with all of them, one per biome with that tier's). Server and client (synced).");
				s_masterLevel = cfg.Bind<int>("Builder Hammers", "MasterLevel", 10, "Building level to craft the Builder's hammer (the one that shows every Builder piece). The biome hammers need their tier level (Tier Gates > TierLevels).");
				s_masterCost = cfg.Bind<string>("Builder Hammers", "MasterRecipe", "Wood:5,Stone:5,Bronze:1", "Materials for the Builder's hammer (workbench).");
				for (int i = 0; i < 8; i++)
				{
					s_cost[i] = cfg.Bind<string>("Builder Hammers", BiomeKeys[i] + "Recipe", DefaultCosts[i], "Materials for the " + BiomeNames[i] + " builder's hammer (workbench).");
				}
				s_station = cfg.Bind<string>("Builder Hammers", "Station", "VP_BuilderBench", "Crafting station for the Builder hammers. Default: the Builder's bench (Builder Bench section; falls back to the workbench when the bench is off).");
				string station = BuilderBench.HammerStation(s_station.Value);
				s_keep = cfg.Bind<string>("Builder Hammers", "KeepOnHammer", "VRH_vd_*,VRH_village_boat_shed,ShipyardStation,ShipConstruction,piece_workbench", "Pieces that never move to the Builder hammers (prefab names, * at the end = starts with). Default: the Shipwright hammer's parts and the workbench.");
				s_extraTools = cfg.Bind<string>("Builder Hammers", "ExtraTools", "BFP_FineHammer", "Other mods' build tools whose Builder pieces are also put on the Builder hammers (',').");
				s_retire = cfg.Bind<bool>("Builder Hammers", "RetireExtraTools", true, "Switch off the recipes of ExtraTools (the Builder hammers carry their pieces). Hammers already made keep working.");
				if (!s_on.Value)
				{
					return;
				}
				Content.AddItem("Hammer", "VP_BuilderHammer", "Builder's hammer", "Every modded building piece in one hammer: the Builder's full catalogue, sorted Meadows to Deep North. Pieces still unlock with your Building level.", delegate(SharedData s)
				{
					OwnTable(s, 0);
				});
				Content.AddRecipe("VP_BuilderHammer", station, 1, 1, s_masterCost.Value, "Building", s_masterLevel.Value);
				for (int num = 0; num < 8; num++)
				{
					int tier = num;
					Content.AddItem("Hammer", BiomePrefab(tier), BiomeNames[tier] + " builder's hammer", "The vanilla pieces plus the Builder's " + BiomeNames[tier] + " pieces only, for a shorter build menu.", delegate(SharedData s)
					{
						OwnTable(s, tier + 1);
					});
					Content.AddRecipe(BiomePrefab(tier), station, 1, 1, s_cost[tier].Value, "Building", TierLevelFromConfig(tier));
				}
			}

			private static void OwnTable(SharedData s, int slot)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				if (s == null || (Object)(object)s.m_buildPieces == (Object)null)
				{
					return;
				}
				if ((Object)(object)s_tables[slot] == (Object)null)
				{
					if ((Object)(object)s_holder == (Object)null)
					{
						s_holder = new GameObject("VargheimProfessions_BuilderHammers");
						s_holder.SetActive(false);
						Object.DontDestroyOnLoad((Object)(object)s_holder);
					}
					GameObject val = Object.Instantiate<GameObject>(((Component)s.m_buildPieces).gameObject, s_holder.transform, false);
					((Object)val).name = "_BuilderPieceTable_" + ((slot == 0) ? "Master" : BiomeKeys[slot - 1]);
					s_tables[slot] = val.GetComponent<PieceTable>();
					s_tables[slot].m_pieces = new List<GameObject>();
				}
				s.m_buildPieces = s_tables[slot];
			}

			private static bool Matches(string name, string list)
			{
				string[] array = (list ?? "").Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length != 0 && (text.EndsWith("*", StringComparison.Ordinal) ? name.StartsWith(text.Substring(0, text.Length - 1), StringComparison.Ordinal) : (name == text)))
					{
						return true;
					}
				}
				return false;
			}

			private static PieceTable ToolTable(ObjectDB db, string item)
			{
				GameObject itemPrefab = db.GetItemPrefab(item);
				ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (!((Object)(object)val != (Object)null) || val.m_itemData == null || val.m_itemData.m_shared == null)
				{
					return null;
				}
				return val.m_itemData.m_shared.m_buildPieces;
			}

			internal static void Apply(ObjectDB db)
			{
				if (s_on == null || !s_on.Value || (Object)(object)db == (Object)null || db.m_items == null || (Object)(object)db.GetItemPrefab("Wood") == (Object)null || (Object)(object)s_tables[0] == (Object)null || s_vanillaItems == null || s_vanillaPieces == null || !GatesEnabled)
				{
					return;
				}
				PieceTable val = ToolTable(db, "Hammer");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				List<GameObject> list = new List<GameObject>(val.m_pieces);
				foreach (GameObject piece in s_tables[0].m_pieces)
				{
					if ((Object)(object)piece != (Object)null && !list.Contains(piece))
					{
						list.Add(piece);
					}
				}
				string[] array = (s_extraTools.Value ?? "").Split(',');
				foreach (string text in array)
				{
					PieceTable val2 = ((text.Trim().Length > 0) ? ToolTable(db, text.Trim()) : null);
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					foreach (GameObject piece2 in val2.m_pieces)
					{
						if ((Object)(object)piece2 != (Object)null && !list.Contains(piece2))
						{
							list.Add(piece2);
						}
					}
				}
				PieceTable[] array2 = s_tables;
				foreach (PieceTable val3 in array2)
				{
					if ((Object)(object)val3 != (Object)null)
					{
						val3.m_pieces.Clear();
					}
				}
				int num = 0;
				int[] array3 = new int[8];
				List<GameObject> list2 = new List<GameObject>();
				List<KeyValuePair<GameObject, int>> list3 = new List<KeyValuePair<GameObject, int>>();
				foreach (GameObject item in list)
				{
					Piece val4 = (((Object)(object)item != (Object)null) ? item.GetComponent<Piece>() : null);
					if ((Object)(object)val4 == (Object)null)
					{
						continue;
					}
					if (VanillaPiece(((Object)item).name))
					{
						if (val.m_pieces.Contains(item))
						{
							list2.Add(item);
						}
						continue;
					}
					if (((Object)item).name == "VP_BuilderBench" || Matches(((Object)item).name, s_keep.Value) || (Object)(object)item.GetComponent<Ship>() != (Object)null)
					{
						if (!val.m_pieces.Contains(item))
						{
							val.m_pieces.Add(item);
						}
						continue;
					}
					Gate gate = GateOf(val4);
					if (gate != null && !(gate.Prof != "Building"))
					{
						int value = Mathf.Clamp(gate.TierIndex, 0, 7);
						list3.Add(new KeyValuePair<GameObject, int>(item, value));
						if (val.m_pieces.Remove(item))
						{
							num++;
						}
					}
				}
				array2 = s_tables;
				foreach (PieceTable val5 in array2)
				{
					if ((Object)(object)val5 != (Object)null)
					{
						val5.m_pieces.AddRange(list2);
					}
				}
				foreach (KeyValuePair<GameObject, int> item2 in list3)
				{
					s_tables[0].m_pieces.Add(item2.Key);
					if ((Object)(object)s_tables[item2.Value + 1] != (Object)null)
					{
						s_tables[item2.Value + 1].m_pieces.Add(item2.Key);
					}
					array3[item2.Value]++;
				}
				int num2 = 0;
				if (s_retire.Value)
				{
					foreach (Recipe recipe in db.m_recipes)
					{
						if ((Object)(object)recipe != (Object)null && (Object)(object)recipe.m_item != (Object)null && recipe.m_enabled && Matches(((Object)((Component)recipe.m_item).gameObject).name, s_extraTools.Value))
						{
							recipe.m_enabled = false;
							num2++;
						}
					}
				}
				string text2 = list3.Count + " Builder pieces on the Builder hammers (" + num + " taken off the vanilla Hammer; per biome " + string.Join("/", Array.ConvertAll(array3, (int x) => x.ToString())) + "); vanilla Hammer keeps " + val.m_pieces.Count + "; " + num2 + " extra tool recipe(s) switched off.";
				if (text2 != s_logged)
				{
					s_logged = text2;
					Note("builder hammers: " + text2);
				}
			}
		}

		private sealed class Locked
		{
			public string Guid;

			public ConfigEntryBase Entry;

			public string Value;

			public bool Broken;
		}

		private sealed class Conn
		{
			public bool Hello;

			public string Host = string.Empty;

			public string Name = string.Empty;
		}

		internal static class Powers
		{
			internal sealed class Power
			{
				public string Key;

				public string Name;

				public string Text;

				public string DefaultProfs;

				public float DefaultAmount;

				public ConfigEntry<string> Profs;

				public ConfigEntry<float> Amount;

				public string[] List = new string[0];
			}

			[HarmonyPatch]
			internal static class PowerPatches
			{
				[HarmonyPatch(typeof(Player), "GetRunSpeedFactor")]
				[HarmonyPostfix]
				private static void Run(Player __instance, ref float __result)
				{
					float num = Bonus(__instance, Speed);
					if (num > 0f)
					{
						__result *= 1f + num;
					}
				}

				[HarmonyPatch(typeof(Player), "GetBodyArmor")]
				[HarmonyPostfix]
				private static void BodyArmor(Player __instance, ref float __result)
				{
					float num = Bonus(__instance, Armor);
					if (num > 0f)
					{
						__result *= 1f + num;
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyAttackStaminaUsage")]
				[HarmonyPostfix]
				private static void AttackStamina(SEMan __instance, ref float staminaUse)
				{
					float num = Bonus(Owner(__instance), Discipline);
					if (num > 0f)
					{
						staminaUse *= 1f - Mathf.Clamp01(num);
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyBlockStaminaUsage")]
				[HarmonyPostfix]
				private static void BlockStamina(SEMan __instance, ref float staminaUse)
				{
					float num = Bonus(Owner(__instance), Discipline);
					if (num > 0f)
					{
						staminaUse *= 1f - Mathf.Clamp01(num);
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyFallDamage")]
				[HarmonyPostfix]
				private static void Fall(SEMan __instance, ref float damage)
				{
					float num = Bonus(Owner(__instance), Footing);
					if (num > 0f)
					{
						damage *= 1f - Mathf.Clamp01(num);
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifySwimStaminaUsage")]
				[HarmonyPostfix]
				private static void SwimStamina(SEMan __instance, ref float staminaUse)
				{
					float num = Bonus(Owner(__instance), Water);
					if (num > 0f)
					{
						staminaUse *= 1f - Mathf.Clamp01(num * 2f);
					}
				}

				[HarmonyPatch(typeof(SEMan), "ApplyStatusEffectSpeedMods")]
				[HarmonyPostfix]
				private static void SwimSpeed(SEMan __instance, ref float speed)
				{
					Player val = Owner(__instance);
					if (!((Object)(object)val == (Object)null) && ((Character)val).IsSwimming())
					{
						float num = Bonus(val, Water);
						if (num > 0f)
						{
							speed *= 1f + num;
						}
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyEitrRegen")]
				[HarmonyPostfix]
				private static void EitrRegen(SEMan __instance, ref float eitrMultiplier)
				{
					float num = Bonus(Owner(__instance), Eitr);
					if (num > 0f)
					{
						eitrMultiplier *= 1f + num;
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyHealthRegen")]
				[HarmonyPostfix]
				private static void HealthRegen(SEMan __instance, ref float regenMultiplier)
				{
					float num = Bonus(Owner(__instance), Hardy);
					if (num > 0f)
					{
						regenMultiplier *= 1f + num;
					}
				}

				[HarmonyPatch(typeof(SEMan), "ModifyStaminaRegen")]
				[HarmonyPostfix]
				private static void StaminaRegen(SEMan __instance, ref float staminaMultiplier)
				{
					float num = Bonus(Owner(__instance), SeaLegs);
					if (num > 0f)
					{
						staminaMultiplier *= 1f + num;
					}
				}

				[HarmonyPatch(typeof(Player), "EatFood")]
				[HarmonyPostfix]
				private static void Eat(Player __instance, ItemData item, bool __result, List<Food> ___m_foods)
				{
					if (!__result || item == null || ___m_foods == null)
					{
						return;
					}
					float num = Bonus(__instance, Stomach);
					if (num <= 0f)
					{
						return;
					}
					foreach (Food ___m_food in ___m_foods)
					{
						if (___m_food != null && ___m_food.m_item != null && ___m_food.m_item.m_shared.m_name == item.m_shared.m_name)
						{
							___m_food.m_time = Mathf.Min(___m_food.m_time * (1f + num), item.m_shared.m_foodBurnTime * (1f + num));
						}
					}
				}
			}

			internal static readonly Power Speed = new Power
			{
				Key = "FleetFoot",
				Name = "Fleet foot",
				Text = "run speed",
				DefaultProfs = "Exploration",
				DefaultAmount = 0.1f
			};

			internal static readonly Power Armor = new Power
			{
				Key = "FittedArmor",
				Name = "Fitted armor",
				Text = "armor from what you wear",
				DefaultProfs = "Blacksmithing",
				DefaultAmount = 0.1f
			};

			internal static readonly Power Discipline = new Power
			{
				Key = "WeaponDiscipline",
				Name = "Weapon discipline",
				Text = "less stamina for attacks and blocks",
				DefaultProfs = "Weaponsmithing",
				DefaultAmount = 0.15f
			};

			internal static readonly Power Footing = new Power
			{
				Key = "SureFooted",
				Name = "Sure-footed",
				Text = "less fall damage",
				DefaultProfs = "Building",
				DefaultAmount = 0.5f
			};

			internal static readonly Power Stomach = new Power
			{
				Key = "IronStomach",
				Name = "Iron stomach",
				Text = "longer-lasting food",
				DefaultProfs = "Cooking",
				DefaultAmount = 0.1f
			};

			internal static readonly Power Water = new Power
			{
				Key = "Waterborn",
				Name = "Waterborn",
				Text = "swim speed (and 2x that less swim stamina)",
				DefaultProfs = "Fishing",
				DefaultAmount = 0.15f
			};

			internal static readonly Power Eitr = new Power
			{
				Key = "EitrWell",
				Name = "Eitr well",
				Text = "eitr regeneration",
				DefaultProfs = "Jewelcrafting",
				DefaultAmount = 0.15f
			};

			internal static readonly Power Hardy = new Power
			{
				Key = "Hardy",
				Name = "Hardy",
				Text = "health regeneration",
				DefaultProfs = "Ranching",
				DefaultAmount = 0.1f
			};

			internal static readonly Power SeaLegs = new Power
			{
				Key = "SeaLegs",
				Name = "Sea legs",
				Text = "stamina regeneration",
				DefaultProfs = "Sailing",
				DefaultAmount = 0.15f
			};

			internal static readonly Power[] All = new Power[9] { Speed, Armor, Discipline, Footing, Stomach, Water, Eitr, Hardy, SeaLegs };

			private static ConfigEntry<bool> s_on;

			private static ConfigEntry<int> s_start;

			private static ConfigEntry<int> s_full;

			private static ConfigEntry<float> s_extra;

			private static readonly FieldRef<SEMan, Character> s_owner = AccessTools.FieldRefAccess<SEMan, Character>("m_character");

			internal static void Bind(ConfigFile cfg)
			{
				s_on = cfg.Bind<bool>("Signature Powers", "Enabled", true, "One personal power per profession, each on its own stat. A player whose professions share a power gets the best one, never the sum. Server-locked.");
				s_start = cfg.Bind<int>("Signature Powers", "StartLevel", 0, "Profession level where a power starts (0%). Digi Nov 15: powers grow over the whole 1-100 range.");
				s_full = cfg.Bind<int>("Signature Powers", "FullLevel", 100, "Profession level where a power is at full strength.");
				s_extra = cfg.Bind<float>("Signature Powers", "ExtraShare", 0.1f, "When several of your professions give the same power, only the best is active; each further one adds just this share of it (0.10 = +10%).");
				Power[] all = All;
				foreach (Power power in all)
				{
					power.Profs = cfg.Bind<string>("Signature Powers", power.Key + "Professions", power.DefaultProfs, power.Name + ": professions that give it (',' - with several, the best one counts, they never add up). Profession names: " + string.Join(", ", Rules.All) + " (Jewelcrafting = Mystic Crafting).");
					power.Amount = cfg.Bind<float>("Signature Powers", power.Key, power.DefaultAmount, power.Name + " at full strength (0.10 = 10% " + power.Text + "). 0 = off.");
					power.List = Split(power.Profs.Value);
				}
				cfg.SettingChanged += delegate
				{
					Power[] all2 = All;
					foreach (Power obj in all2)
					{
						obj.List = Split(obj.Profs.Value);
					}
				};
			}

			private static string[] Split(string raw)
			{
				List<string> list = new List<string>();
				string[] array = (raw ?? "").Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					string text = Rules.Normalize(array[i].Trim());
					if (text != null && !list.Contains(text))
					{
						list.Add(text);
					}
				}
				return list.ToArray();
			}

			internal static float Strength(Player pl, Power p)
			{
				if ((Object)(object)pl == (Object)null || s_on == null || !s_on.Value || p.Amount == null || p.Amount.Value <= 0f || p.List.Length == 0)
				{
					return 0f;
				}
				int num = Mathf.Max(1, s_full.Value - s_start.Value);
				float num2 = 0f;
				int num3 = -1;
				string[] list = p.List;
				foreach (string prof in list)
				{
					float num4 = Mathf.Clamp01((float)(Api.PerkLevelOf(pl, prof) - s_start.Value) / (float)num);
					if (num4 > 0f)
					{
						num3++;
					}
					if (num4 > num2)
					{
						num2 = num4;
					}
				}
				return num2 * (1f + (float)Mathf.Max(0, num3) * Mathf.Max(0f, s_extra.Value));
			}

			internal static float Bonus(Player pl, Power p)
			{
				return Strength(pl, p) * ((p.Amount != null) ? p.Amount.Value : 0f);
			}

			private static Player Owner(SEMan se)
			{
				try
				{
					return (Player)((se != null) ? /*isinst with value type is only supported in some contexts*/: null);
				}
				catch
				{
					return null;
				}
			}

			internal static string Describe(Player pl)
			{
				List<string> list = new List<string>();
				Power[] all = All;
				foreach (Power power in all)
				{
					float num = Bonus(pl, power);
					if (num > 0f)
					{
						list.Add(power.Name + " +" + Mathf.RoundToInt(num * 100f) + "% " + power.Text);
					}
				}
				return string.Join("\n", list.ToArray());
			}

			internal static string Line(string prof, int level)
			{
				if (s_on == null || !s_on.Value)
				{
					return null;
				}
				List<string> list = new List<string>();
				int num = Mathf.Max(1, s_full.Value - s_start.Value);
				Power[] all = All;
				foreach (Power power in all)
				{
					if (Array.IndexOf(power.List, prof) >= 0 && !(power.Amount.Value <= 0f))
					{
						float num2 = Mathf.Clamp01((float)(level - s_start.Value) / (float)num);
						string text = ((power.List.Length > 1) ? (" (shared with " + string.Join(", ", Array.FindAll(power.List, (string x) => x != prof).Select(Rules.Display)) + ": only the best is active, each other one adds " + Mathf.RoundToInt(s_extra.Value * 100f) + "%)") : "");
						list.Add("<b>Signature power - " + power.Name + "</b>: +" + Mathf.RoundToInt(power.Amount.Value * 100f) + "% " + power.Text + " at level " + s_full.Value + ", growing from level " + s_start.Value + " (now +" + Mathf.RoundToInt(num2 * power.Amount.Value * 100f) + "%)" + text + ". Personal; the same power from another profession never adds up.");
					}
				}
				if (list.Count <= 0)
				{
					return null;
				}
				return string.Join("\n", list.ToArray());
			}
		}

		internal static class ProfessionBenches
		{
			internal sealed class Bench
			{
				public string Key;

				public string Prefab;

				public string Name;

				public string Art;

				public string Description;

				public string DefaultRecipe;

				public string[] Profs;

				public Vector3[] Boxes;

				public ConfigEntry<string> Recipe;

				public ConfigEntry<int> Level;

				public ConfigEntry<float> Yaw;

				public CraftingStation Station;

				public Gate Rule;

				public int Moved;
			}

			private sealed class Orig
			{
				public string StationName;

				public string StationPrefab;

				public int Level;
			}

			[HarmonyPatch]
			internal static class BenchPatches
			{
				[HarmonyPatch(typeof(ObjectDB), "Awake")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbAwake(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ProfessionBenches.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbCopy(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ProfessionBenches.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ZNetScene), "Awake")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void SceneAwake()
				{
					try
					{
						if ((Object)(object)ObjectDB.instance != (Object)null)
						{
							Apply(ObjectDB.instance);
						}
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ProfessionBenches.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ZoneSystem), "Start")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void WorldStart()
				{
					try
					{
						if ((Object)(object)ObjectDB.instance != (Object)null)
						{
							Apply(ObjectDB.instance);
						}
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ProfessionBenches.cs", ex);
					}
				}

				[HarmonyPatch(typeof(Recipe), "GetRequiredStationLevel")]
				[HarmonyPostfix]
				private static void StationLevel(Recipe __instance, ref int __result)
				{
					try
					{
						if (__result > 1 && OnBench(__instance))
						{
							__result = 1;
						}
					}
					catch
					{
					}
				}

				[HarmonyPatch(typeof(InventoryGui), "CanRepair")]
				[HarmonyPostfix]
				private static void CanRepair(ItemData item, ref bool __result)
				{
					try
					{
						if (__result || item == null || s_repair == null || !s_repair.Value || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ObjectDB.instance == (Object)null || !item.m_shared.m_canBeReparied)
						{
							return;
						}
						CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
						if (!((Object)(object)currentCraftingStation == (Object)null))
						{
							Recipe recipe = ObjectDB.instance.GetRecipe(item);
							if ((Object)(object)recipe != (Object)null && OnBench(recipe) && s_moved.TryGetValue(recipe, out var value) && currentCraftingStation.m_name == value.StationName && currentCraftingStation.GetLevel(true) >= value.Level)
							{
								__result = true;
							}
						}
					}
					catch
					{
					}
				}
			}

			internal static readonly Bench[] Benches = new Bench[5]
			{
				new Bench
				{
					Key = "Smith",
					Prefab = "VP_SmithBench",
					Name = "Smith's bench",
					Art = "smith_bench",
					Profs = new string[1] { "Blacksmithing" },
					Description = "An anvil bench for the Blacksmith. Modded armor is made, upgraded and repaired here. It does not count as a workbench or forge.",
					DefaultRecipe = "Wood:10,Stone:6",
					Boxes = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(0f, 0.495f, 0f),
						new Vector3(2.8f, 0.99f, 0.96f),
						new Vector3(-0.985f, 1.17f, -0.02f),
						new Vector3(1.03f, 0.36f, 0.44f),
						new Vector3(1.05f, 1.23f, -0.08f),
						new Vector3(0.46f, 0.46f, 0.4f),
						new Vector3(0.02f, 1.29f, -0.43f),
						new Vector3(1.4f, 0.6f, 0.12f)
					}
				},
				new Bench
				{
					Key = "Weaponsmith",
					Prefab = "VP_WeaponsmithBench",
					Name = "Weaponsmith's bench",
					Art = "weaponsmith_bench",
					Profs = new string[1] { "Weaponsmithing" },
					Description = "A grinding bench for the Weaponsmith. Modded weapons, shields and ammo are made, upgraded and repaired here (the Fletcher table keeps its own). It does not count as a workbench or forge.",
					DefaultRecipe = "Wood:10,Stone:4,Flint:4",
					Boxes = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(0f, 0.495f, 0f),
						new Vector3(2.8f, 0.99f, 0.96f),
						new Vector3(-1.02f, 1.25f, 0.04f),
						new Vector3(0.56f, 0.53f, 0.76f),
						new Vector3(1.11f, 1.15f, 0.12f),
						new Vector3(0.56f, 0.3f, 0.56f),
						new Vector3(0f, 1.33f, -0.38f),
						new Vector3(1.35f, 0.68f, 0.22f)
					}
				},
				new Bench
				{
					Key = "Cook",
					Prefab = "VP_CookTable",
					Name = "Cook's table",
					Art = "cook_table",
					Profs = new string[1] { "Cooking" },
					Description = "A butcher's table for the Cook. Modded dishes and brews are made here. It does not count as a cauldron or workbench.",
					DefaultRecipe = "Wood:10,Stone:4",
					Boxes = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(0f, 0.495f, 0f),
						new Vector3(2.8f, 0.99f, 0.96f),
						new Vector3(-0.99f, 1.16f, 0.04f),
						new Vector3(0.74f, 0.36f, 0.68f),
						new Vector3(1f, 1.14f, 0.06f),
						new Vector3(0.62f, 0.3f, 0.62f),
						new Vector3(0f, 1.29f, -0.4f),
						new Vector3(1.65f, 0.56f, 0.21f)
					}
				},
				new Bench
				{
					Key = "Supply",
					Prefab = "VP_SupplyBench",
					Name = "Supply bench",
					Art = "supply_bench",
					Profs = new string[5] { "Mining", "Lumberjacking", "Fishing", "Farming", "Exploration" },
					Description = "A packing bench shared by the Miner, Lumberjack, Angler, Farmer and Explorer. Their tier materials and modded supplies (bait) are made here. It does not count as a workbench.",
					DefaultRecipe = "Wood:10,Stone:4",
					Boxes = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(0f, 0.495f, 0f),
						new Vector3(2.8f, 0.99f, 0.96f),
						new Vector3(-0.91f, 1.3f, 0f),
						new Vector3(0.9f, 0.64f, 0.52f),
						new Vector3(0.98f, 1.14f, -0.04f),
						new Vector3(0.76f, 0.32f, 0.8f),
						new Vector3(0.02f, 1.23f, -0.43f),
						new Vector3(0.64f, 0.45f, 0.06f)
					}
				},
				new Bench
				{
					Key = "Tanner",
					Prefab = "VP_TannerRack",
					Name = "Tanner's rack",
					Art = "tanner_rack",
					Profs = new string[1] { "Ranching" },
					Description = "A hide frame for the Rancher. Tier leathers, fertilizer, saddles and horse armour are made here. It does not count as a workbench.",
					DefaultRecipe = "Wood:10,LeatherScraps:4,DeerHide:2",
					Boxes = (Vector3[])(object)new Vector3[8]
					{
						new Vector3(0f, 0.85f, -0.22f),
						new Vector3(2.4f, 1.7f, 0.2f),
						new Vector3(0f, 0.425f, 0.26f),
						new Vector3(2.5f, 0.85f, 0.4f),
						new Vector3(-1.12f, 0.07f, 0f),
						new Vector3(0.3f, 0.14f, 0.94f),
						new Vector3(1.12f, 0.07f, 0f),
						new Vector3(0.3f, 0.14f, 0.94f)
					}
				}
			};

			private static ConfigEntry<bool> s_on;

			private static ConfigEntry<bool> s_route;

			private static ConfigEntry<bool> s_repair;

			private static ConfigEntry<string> s_keep;

			private static ConfigEntry<float> s_use;

			private static ConfigEntry<float> s_lod0;

			private static ConfigEntry<float> s_lod1;

			private static readonly Dictionary<Recipe, Orig> s_moved = new Dictionary<Recipe, Orig>();

			private static readonly HashSet<string> s_stationNames = new HashSet<string>(StringComparer.Ordinal);

			private static string s_logged;

			internal static bool Enabled
			{
				get
				{
					if (s_on != null)
					{
						return s_on.Value;
					}
					return false;
				}
			}

			internal static void Bind(ConfigFile cfg)
			{
				s_on = cfg.Bind<bool>("Profession Benches", "Enabled", true, "The five profession benches (Smith's bench, Weaponsmith's bench, Cook's table, Supply bench, Tanner's rack). Off = no benches; modded recipes stay at the vanilla stations. Server and client (synced).");
				s_route = cfg.Bind<bool>("Profession Benches", "MoveRecipes", true, "Recipes of modded items gated to a bench's profession move from VANILLA stations (workbench, forge, cauldron, prep table ...) to that bench. Vanilla items and other mods' own stations are never touched.");
				s_keep = cfg.Bind<string>("Profession Benches", "KeepAtStation", "Bolt*_OdinShip", "Item prefabs whose recipe never moves to a bench (',', * at the end = starts with). Default: the ship ballista bolts the Shipwright pass pins to the Fletcher table / forge.");
				s_repair = cfg.Bind<bool>("Profession Benches", "RepairAtOldStation", true, "An item whose recipe moved to a bench can still be repaired at the station it used to be made at (repairing stays open to everyone).");
				s_use = cfg.Bind<float>("Profession Benches", "UseDistance", 2f, "How far from a bench a player can use it (art contracts: 2.0 m).");
				s_lod0 = cfg.Bind<float>("Profession Benches", "Lod0ScreenHeight", 0.25f, "Screen height below which the simpler distance mesh is shown (native-fixture tuning).");
				s_lod1 = cfg.Bind<float>("Profession Benches", "Lod1ScreenHeight", 0.02f, "Screen height below which a bench is not drawn at all.");
				Bench[] benches = Benches;
				foreach (Bench bench in benches)
				{
					string text = string.Join(" / ", Array.ConvertAll(bench.Profs, Rules.Title));
					bench.Recipe = cfg.Bind<string>("Profession Benches", bench.Key + "Recipe", bench.DefaultRecipe, "Materials to build the " + bench.Name + " (provisional - Digi sets costs).");
					bench.Level = cfg.Bind<int>("Profession Benches", bench.Key + "Level", -1, "Level of " + text + " needed to build AND use the " + bench.Name + ". -1 = the Meadows tier level (Tier Gates > TierLevels), so the first tier's items can be made once it stands.");
					bench.Yaw = cfg.Bind<float>("Profession Benches", bench.Key + "ModelYaw", 0f, "Degrees to turn the " + bench.Name + " art and colliders about the vertical axis (native-fixture tuning; 180 if the work side faces the wrong way).");
				}
				if (!s_on.Value)
				{
					return;
				}
				benches = Benches;
				foreach (Bench bench2 in benches)
				{
					Bench bench3 = bench2;
					int level = LevelOf(bench2);
					bench2.Rule = new Gate
					{
						Prof = bench2.Profs[0],
						Level = level,
						Why = "perk",
						AnyOf = ((bench2.Profs.Length > 1) ? bench2.Profs : null)
					};
					s_stationNames.Add(bench2.Name);
					Content.AddPiece("piece_workbench", bench2.Prefab, bench2.Name, bench2.Description, "Hammer", bench2.Recipe.Value, null, 0, delegate(GameObject go)
					{
						Setup(bench3, go);
					});
				}
				cfg.SettingChanged += delegate(object o, SettingChangedEventArgs e)
				{
					if (e != null && e.ChangedSetting != null && (e.ChangedSetting.Definition.Section == "Profession Benches" || e.ChangedSetting.Definition.Section == "Tier Gates"))
					{
						Bench[] benches2 = Benches;
						foreach (Bench bench4 in benches2)
						{
							if (bench4.Rule != null)
							{
								bench4.Rule.Level = LevelOf(bench4);
							}
						}
					}
				};
			}

			private static int LevelOf(Bench b)
			{
				if (b.Level.Value < 0)
				{
					return TierLevelFromConfig(0);
				}
				return b.Level.Value;
			}

			internal static Gate RuleFor(string prefab)
			{
				if (!Enabled || prefab == null)
				{
					return null;
				}
				Bench[] benches = Benches;
				foreach (Bench bench in benches)
				{
					if (bench.Rule != null && string.Equals(bench.Prefab, prefab, StringComparison.Ordinal))
					{
						return bench.Rule;
					}
				}
				return null;
			}

			private static Bench BenchFor(string prof)
			{
				Bench[] benches = Benches;
				foreach (Bench bench in benches)
				{
					if ((Object)(object)bench.Station != (Object)null && Array.IndexOf(bench.Profs, prof) >= 0)
					{
						return bench;
					}
				}
				return null;
			}

			private static bool Matches(string name, string list)
			{
				string[] array = (list ?? "").Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length != 0 && (text.EndsWith("*", StringComparison.Ordinal) ? name.StartsWith(text.Substring(0, text.Length - 1), StringComparison.Ordinal) : (name == text)))
					{
						return true;
					}
				}
				return false;
			}

			internal static void Apply(ObjectDB db)
			{
				if (!Enabled || s_route == null || !s_route.Value || (Object)(object)db == (Object)null || db.m_recipes == null || (Object)(object)db.GetItemPrefab("Wood") == (Object)null || s_vanillaItems == null || s_vanillaPieces == null || !GatesEnabled)
				{
					return;
				}
				Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.Ordinal);
				int num = 0;
				foreach (Recipe recipe in db.m_recipes)
				{
					if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null || (Object)(object)recipe.m_craftingStation == (Object)null)
					{
						continue;
					}
					string name = ((Object)((Component)recipe.m_item).gameObject).name;
					string name2 = ((Object)((Component)recipe.m_craftingStation).gameObject).name;
					if (s_vanillaItems.Contains(name) || !VanillaPiece(name2) || Matches(name, s_keep.Value))
					{
						continue;
					}
					Gate gate = GateOf(recipe);
					if (gate == null || gate.Prof == null)
					{
						continue;
					}
					Bench bench = BenchFor(gate.Prof);
					if (bench != null)
					{
						if (!s_moved.ContainsKey(recipe))
						{
							s_moved[recipe] = new Orig
							{
								StationName = recipe.m_craftingStation.m_name,
								StationPrefab = name2,
								Level = Math.Max(1, recipe.m_minStationLevel)
							};
						}
						recipe.m_craftingStation = bench.Station;
						recipe.m_minStationLevel = 1;
						num++;
						dictionary.TryGetValue(bench.Key + " <- " + name2, out var value);
						dictionary[bench.Key + " <- " + name2] = value + 1;
					}
				}
				Bench[] benches = Benches;
				for (int i = 0; i < benches.Length; i++)
				{
					benches[i].Moved = 0;
				}
				foreach (KeyValuePair<Recipe, Orig> item in s_moved)
				{
					if ((Object)(object)item.Key == (Object)null || (Object)(object)item.Key.m_craftingStation == (Object)null)
					{
						continue;
					}
					benches = Benches;
					foreach (Bench bench2 in benches)
					{
						if ((Object)(object)bench2.Station != (Object)null && (Object)(object)item.Key.m_craftingStation == (Object)(object)bench2.Station)
						{
							bench2.Moved++;
						}
					}
				}
				List<string> list = new List<string>();
				benches = Benches;
				foreach (Bench bench3 in benches)
				{
					list.Add(bench3.Name + " " + (((Object)(object)bench3.Station != (Object)null) ? bench3.Moved.ToString() : "(not built)"));
				}
				List<string> list2 = new List<string>();
				foreach (KeyValuePair<string, int> item2 in dictionary)
				{
					list2.Add(item2.Key + " " + item2.Value);
				}
				string text = string.Join(", ", list.ToArray()) + ((num > 0) ? ("; this pass moved " + num + " (" + string.Join(", ", list2.ToArray()) + ")") : "");
				if (text != s_logged)
				{
					s_logged = text;
					Note("profession benches: recipes on the benches: " + text + ".");
				}
			}

			private static bool Under(Transform t, Component root)
			{
				if ((Object)(object)root != (Object)null)
				{
					return t.IsChildOf(root.transform);
				}
				return false;
			}

			private static bool Under(Transform t, GameObject root)
			{
				if ((Object)(object)root != (Object)null)
				{
					return t.IsChildOf(root.transform);
				}
				return false;
			}

			private static void Setup(Bench b, GameObject go)
			{
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Expected O, but got Unknown
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: 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_01f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Invalid comparison between Unknown and I4
				CraftingStation component = go.GetComponent<CraftingStation>();
				if ((Object)(object)component == (Object)null)
				{
					Warn("profession bench " + b.Key + ": base piece has no CraftingStation - left as a plain copy.");
					return;
				}
				component.m_name = b.Name;
				component.m_showBasicRecipies = false;
				component.m_useDistance = Mathf.Max(0.5f, s_use.Value);
				b.Station = component;
				Material wood = BenchSurface.FindBody(go);
				int num = 0;
				int num2 = 0;
				LODGroup[] componentsInChildren = go.GetComponentsInChildren<LODGroup>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
				MeshRenderer[] componentsInChildren2 = go.GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val in componentsInChildren2)
				{
					Transform transform = ((Component)val).transform;
					if (!Under(transform, component.m_areaMarker) && !Under(transform, component.m_inUseObject) && !Under(transform, component.m_haveFireObject))
					{
						MeshFilter component2 = ((Component)val).GetComponent<MeshFilter>();
						Object.DestroyImmediate((Object)(object)val);
						if ((Object)(object)component2 != (Object)null)
						{
							Object.DestroyImmediate((Object)(object)component2);
						}
						num++;
					}
				}
				Collider[] componentsInChildren3 = go.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren3)
				{
					if (!val2.isTrigger && !((Object)(object)val2 == (Object)(object)component.m_effectAreaCollider) && !Under(((Component)val2).transform, component.m_areaMarker))
					{
						Object.DestroyImmediate((Object)(object)val2);
						num2++;
					}
				}
				GameObject val3 = new GameObject("VP_BenchPivot");
				val3.layer = go.layer;
				val3.transform.SetParent(go.transform, false);
				val3.transform.localRotation = Quaternion.Euler(0f, b.Yaw.Value, 0f);
				int layer = LayerMask.NameToLayer("piece");
				for (int j = 0; j + 1 < b.Boxes.Length; j += 2)
				{
					Vector3 val4 = b.Boxes[j];
					AddBox(val3.transform, layer, new Vector3(0f - val4.x, val4.y, val4.z), b.Boxes[j + 1]);
				}
				bool flag = false;
				if ((int)SystemInfo.graphicsDeviceType != 4)
				{
					flag = Dress(b, go, val3.transform, wood);
				}
				Note("profession bench: station '" + b.Name + "' ready for " + string.Join("/", b.Profs) + " " + ((b.Rule != null) ? b.Rule.Level : 0) + " (" + num + " workbench renderers, " + num2 + " colliders replaced; art " + (flag ? "loaded" : "not loaded") + "; yaw " + b.Yaw.Value + ").");
			}

			private static void AddBox(Transform parent, int layer, Vector3 center, Vector3 size)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("VP_BenchCollider")
				{
					layer = ((layer >= 0) ? layer : ((Component)parent).gameObject.layer)
				};
				val.transform.SetParent(parent, false);
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = center;
				obj.size = size;
			}

			private static bool Dress(Bench b, GameObject go, Transform pivot, Material wood)
			{
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Expected O, but got Unknown
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
				string text = "benches/" + b.Art + "/" + b.Art;
				Mesh val = ToolArt.MeshOf(text + ".obj");
				Mesh val2 = ToolArt.MeshOf(text + "_lod1.obj");
				Texture2D val3 = ToolArt.TexOf(text + ".png", icon: false);
				if ((Object)(object)val == (Object)null || (Object)(object)val3 == (Object)null)
				{
					return false;
				}
				Material val4 = BenchSurface.Create(go, wood, val3);
				if ((Object)(object)val4 == (Object)null)
				{
					return false;
				}
				GameObject val5 = new GameObject("VP_BenchModel");
				val5.layer = go.layer;
				val5.transform.SetParent(pivot, false);
				Renderer val6 = AddMesh(val5.transform, "LOD0", val, val4);
				List<LOD> list = new List<LOD>();
				list.Add(new LOD(Mathf.Clamp01(s_lod0.Value), (Renderer[])(object)new Renderer[1] { val6 }));
				List<LOD> list2 = list;
				if ((Object)(object)val2 != (Object)null)
				{
					Renderer val7 = AddMesh(val5.transform, "LOD1", val2, val4);
					list2.Add(new LOD(Mathf.Clamp(s_lod1.Value, 0f, Mathf.Clamp01(s_lod0.Value)), (Renderer[])(object)new Renderer[1] { val7 }));
				}
				else
				{
					list2[0] = new LOD(Mathf.Clamp01(s_lod1.Value), (Renderer[])(object)new Renderer[1] { val6 });
				}
				LODGroup obj = val5.AddComponent<LODGroup>();
				obj.SetLODs(list2.ToArray());
				obj.RecalculateBounds();
				Texture2D val8 = ToolArt.TexOf(text + "_icon.png", icon: true);
				Piece component = go.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null && (Object)(object)val8 != (Object)null)
				{
					Sprite val9 = Sprite.Create(val8, new Rect(0f, 0f, (float)((Texture)val8).width, (float)((Texture)val8).height), new Vector2(0.5f, 0.5f), 100f);
					((Object)val9).name = b.Prefab + "_icon";
					component.m_icon = val9;
					CraftingStation component2 = go.GetComponent<CraftingStation>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.m_icon = val9;
					}
				}
				return true;
			}

			private static Renderer AddMesh(Transform parent, string name, 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_0017: 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)
				GameObject val = new GameObject(name)
				{
					layer = ((Component)parent).gameObject.layer
				};
				val.transform.SetParent(parent, false);
				val.AddComponent<MeshFilter>().sharedMesh = mesh;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = mat;
				return (Renderer)(object)obj;
			}

			private static bool OnBench(Recipe r)
			{
				if ((Object)(object)r != (Object)null && (Object)(object)r.m_craftingStation != (Object)null)
				{
					return s_stationNames.Contains(r.m_craftingStation.m_name);
				}
				return false;
			}
		}

		internal sealed class RosterEntry
		{
			public string Name;

			public bool Online;

			public Dictionary<string, int> Levels = new Dictionary<string, int>(StringComparer.Ordinal);
		}

		internal static class ToolArt
		{
			private sealed class Entry
			{
				public string Id;

				public string Prefab;

				public string Obj;

				public string Albedo;

				public string Icon;
			}

			[HarmonyPatch]
			internal static class ToolArtPatches
			{
				[HarmonyPatch(typeof(ObjectDB), "Awake")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbAwake(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ToolArt.cs", ex);
					}
				}

				[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
				[HarmonyPostfix]
				[HarmonyPriority(0)]
				private static void DbCopy(ObjectDB __instance)
				{
					try
					{
						Apply(__instance);
					}
					catch (Exception ex)
					{
						Api.Oops("VargheimProfessions/ToolArt.cs", ex);
					}
				}
			}

			private static List<Entry> s_entries;

			private static readonly HashSet<int> s_done = new HashSet<int>();

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

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

			private static string Dir()
			{
				return Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? ".", "tools");
			}

			private static void Load()
			{
				if (s_entries != null)
				{
					return;
				}
				s_entries = new List<Entry>();
				string path = Path.Combine(Dir(), "tools.json");
				if (!File.Exists(path))
				{
					Note("tool art: no tools/tools.json - vanilla look kept.");
					return;
				}
				foreach (Match item in Regex.Matches(File.ReadAllText(path), "\\{[^{}]*\"id\"[^{}]*\\}"))
				{
					string value = item.Value;
					Entry entry = new Entry
					{
						Id = Str(value, "id"),
						Prefab = Str(value, "prefab"),
						Obj = Str(value, "obj"),
						Albedo = Str(value, "albedo"),
						Icon = Str(value, "icon")
					};
					if (!string.IsNullOrEmpty(entry.Prefab) && !string.IsNullOrEmpty(entry.Obj))
					{
						s_entries.Add(entry);
					}
				}
			}

			private static string Str(string block, string key)
			{
				Match match = Regex.Match(block, "\"" + key + "\"\\s*:\\s*(\"([^\"]*)\"|null)");
				if (!match.Success || !match.Groups[2].Success)
				{
					return null;
				}
				return match.Groups[2].Value;
			}

			internal static void Apply(ObjectDB db)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Invalid comparison between Unknown and I4
				if ((Object)(object)db == (Object)null || db.m_items == null || db.m_items.Count == 0 || (int)SystemInfo.graphicsDeviceType == 4)
				{
					return;
				}
				Load();
				int num = 0;
				foreach (Entry s_entry in s_entries)
				{
					GameObject itemPrefab = db.GetItemPrefab(s_entry.Prefab);
					if ((Object)(object)itemPrefab == (Object)null || s_done.Contains(((Object)itemPrefab).GetInstanceID()))
					{
						continue;
					}
					try
					{
						if (Dress(itemPrefab, s_entry))
						{
							num++;
							s_done.Add(((Object)itemPrefab).GetInstanceID());
						}
					}
					catch (Exception ex)
					{
						Warn("tool art " + s_entry.Id + ": " + ex.Message);
						s_done.Add(((Object)itemPrefab).GetInstanceID());
					}
				}
				if (num > 0)
				{
					Note("tool art: " + num + " tool(s) dressed (" + Dir() + ").");
				}
			}

			private static bool Dress(GameObject item, Entry e)
			{
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				Mesh val = MeshOf(e.Obj);
				Texture2D val2 = TexOf(e.Albedo, icon: false);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return false;
				}
				Transform val3 = item.transform.Find("attach");
				Material mat = null;
				if ((Object)(object)val3 != (Object)null)
				{
					mat = Fit(val3, null, val, val2, gripAtOrigin: true, ref mat);
				}
				Fit(item.transform, val3, val, val2, gripAtOrigin: false, ref mat);
				ItemDrop component = item.GetComponent<ItemDrop>();
				Texture2D val4 = TexOf(e.Icon, icon: true);
				if ((Object)(object)component != (Object)null && (Object)(object)val4 != (Object)null)
				{
					Sprite val5 = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f), 100f);
					((Object)val5).name = e.Id + "_icon";
					component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val5 };
				}
				return true;
			}

			private static Material Fit(Transform root, Transform skip, Mesh mesh, Texture2D tex, bool gripAtOrigin, ref Material mat)
			{
				//IL_009c: 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_014f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: 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_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0168: Unknown result type (might be due to invalid IL or missing references)
				//IL_016f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_0211: Unknown result type (might be due to invalid IL or missing references)
				//IL_0213: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_021a: 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_0221: Unknown result type (might be due to invalid IL or missing references)
				//IL_0224: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0282: Unknown result type (might be due to invalid IL or missing references)
				//IL_0283: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: Unknown result type (might be due to invalid IL or missing references)
				//IL_028e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0293: Unknown result type (might be due to invalid IL or missing references)
				//IL_0297: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_0279: Unknown result type (might be due to invalid IL or missing references)
				//IL_027e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0399: Unknown result type (might be due to invalid IL or missing references)
				//IL_039e: Unknown result type (might be due to invalid IL or missing references)
				//IL_03af: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_0322: Unknown result type (might be due to invalid IL or missing references)
				//IL_031a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0328: Expected O, but got Unknown
				//IL_038a: Unknown result type (might be due to invalid IL or missing references)
				List<MeshFilter> list = new List<MeshFilter>();
				MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null) && (!((Object)(object)skip != (Object)null) || !((Component)val).transform.IsChildOf(skip)) && !(((Object)((Component)val).gameObject).name == "VP_ToolArt"))
					{
						list.Add(val);
					}
				}
				if (list.Count == 0)
				{
					return mat;
				}
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(float.MaxValue, float.MaxValue, float.MaxValue);
				Vector3 val3 = -val2;
				Material val4 = null;
				foreach (MeshFilter item in list)
				{
					MeshRenderer component = ((Component)item).GetComponent<MeshRenderer>();
					if ((Object)(object)val4 == (Object)null && (Object)(object)component != (Object)null)
					{
						val4 = ((Renderer)component).sharedMaterial;
					}
					Vector3[] vertices = item.sharedMesh.vertices;
					foreach (Vector3 val5 in vertices)
					{
						Vector3 val6 = root.InverseTransformPoint(((Component)item).transform.TransformPoint(val5));
						val2 = Vector3.Min(val2, val6);
						val3 = Vector3.Max(val3, val6);
					}
				}
				Vector3 val7 = val3 - val2;
				int num = ((!(val7.x >= val7.y) || !(val7.x >= val7.z)) ? ((val7.y >= val7.z) ? 1 : 2) : 0);
				int num2 = -1;
				for (int j = 0; j < 3; j++)
				{
					if (j != num && (num2 < 0 || ((Vector3)(ref val7))[j] > ((Vector3)(ref val7))[num2]))
					{
						num2 = j;
					}
				}
				float num3 = ((((Vector3)(ref val3))[num] >= 0f - ((Vector3)(ref val2))[num]) ? 1f : (-1f));
				Vector3 zero = Vector3.zero;
				((Vector3)(ref zero))[num] = num3;
				Vector3 zero2 = Vector3.zero;
				((Vector3)(ref zero2))[num2] = 1f;
				Quaternion val8 = Quaternion.LookRotation(Vector3.Cross(zero2, zero), zero);
				Bounds bounds = mesh.bounds;
				float num4 = ((Vector3)(ref val7))[num] / Mathf.Max(0.01f, ((Bounds)(ref bounds)).size.y);
				bool flag = ((Vector3)(ref val2))[num] < 0f && ((Vector3)(ref val3))[num] > 0f;
				Vector3 localPosition = ((!(gripAtOrigin && flag)) ? ((val2 + val3) * 0.5f - val8 * (((Bounds)(ref bounds)).center * num4)) : Vector3.zero);
				foreach (MeshFilter item2 in list)
				{
					MeshRenderer component2 = ((Component)item2).GetComponent<MeshRenderer>();
					if ((Object)(object)component2 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component2);
					}
					Object.DestroyImmediate((Object)(object)item2);
				}
				if ((Object)(object)mat == (Object)null)
				{
					mat = (((Object)(object)val4 != (Object)null) ? new Material(val4) : new Material(Shader.Find("Standard")));
					((Object)mat).name = "VP_ToolArt_" + ((Object)tex).name;
					mat.mainTexture = (Texture)(object)tex;
					if (mat.HasProperty("_BumpMap"))
					{
						mat.SetTexture("_BumpMap", (Texture)null);
						mat.DisableKeyword("_NORMALMAP");
					}
					if (mat.HasProperty("_Color"))
					{
						mat.SetColor("_Color", Color.white);
					}
				}
				GameObject val9 = new GameObject("VP_ToolArt")
				{
					layer = ((Component)root).gameObject.layer
				};
				val9.transform.SetParent(root, false);
				val9.transform.localPosition = localPosition;
				val9.transform.localRotation = val8;
				val9.transform.localScale = Vector3.one * num4;
				val9.AddComponent<MeshFilter>().sharedMesh = mesh;
				((Renderer)val9.AddComponent<MeshRenderer>()).sharedMaterial = mat;
				return mat;
			}

			internal static Texture2D TexOf(string file, bool icon)
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				if (string.IsNullOrEmpty(file))
				{
					return null;
				}
				if (s_tex.TryGetValue(file, out var value))
				{
					return value;
				}
				string text = Path.Combine(Dir(), file);
				if (!File.Exists(text))
				{
					Warn("tool art: missing " + text);
					return null;
				}
				value = new Texture2D(2, 2, (TextureFormat)4, !icon);
				((Object)value).name = Path.GetFileNameWithoutExtension(file);
				ImageConversion.LoadImage(value, File.ReadAllBytes(text), false);
				((Texture)value).wrapMode = (TextureWrapMode)1;
				((Texture)value).filterMode = (FilterMode)1;
				value.Apply(!icon, true);
				s_tex[file] = value;
				return value;
			}

			internal static Mesh MeshOf(string file)
			{
				//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e0: Expected O, but got Unknown
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0210: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0246: Unknown result type (might be due to invalid IL or missing references)
				if (s_mesh.TryGetValue(file, out var value))
				{
					return value;
				}
				string text = Path.Combine(Dir(), file);
				if (!File.Exists(text))
				{
					Warn("tool art: missing " + text);
					return null;
				}
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<Vector3> list4 = new List<Vector3>();
				List<Vector3> list5 = new List<Vector3>();
				List<Vector2> list6 = new List<Vector2>();
				List<int> list7 = new List<int>();
				Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.Ordinal);
				CultureInfo invariantCulture = CultureInfo.InvariantCulture;
				string[] array = File.ReadAllLines(text);
				for (int i = 0; i < array.Length; i++)
				{
					string text2 = array[i].Trim();
					if (text2.StartsWith("v ", StringComparison.Ordinal))
					{
						string[] array2 = text2.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
						list.Add(new Vector3(0f - float.Parse(array2[1], invariantCulture), float.Parse(array2[2], invariantCulture), float.Parse(array2[3], invariantCulture)));
					}
					else if (text2.StartsWith("vt ", StringComparison.Ordinal))
					{
						string[] array3 = text2.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
						list3.Add(new Vector2(float.Parse(array3[1], invariantCulture), float.Parse(array3[2], invariantCulture)));
					}
					else if (text2.StartsWith("vn ", StringComparison.Ordinal))
					{
						string[] array4 = text2.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
						list2.Add(new Vector3(0f - float.Parse(array4[1], invariantCulture), float.Parse(array4[2], invariantCulture), float.Parse(array4[3], invariantCulture)));
					}
					else
					{
						if (!text2.StartsWith("f ", StringComparison.Ordinal))
						{
							continue;
						}
						string[] array5 = text2.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
						int[] array6 = new int[array5.Length - 1];
						for (int j = 1; j < array5.Length; j++)
						{
							if (!dictionary.TryGetValue(array5[j], out var value2))
							{
								string[] array7 = array5[j].Split('/');
								int index = Ix(array7[0], list.Count);
								list4.Add(list[index]);
								list6.Add((array7.Length > 1 && array7[1].Length > 0) ? list3[Ix(array7[1], list3.Count)] : Vector2.zero);
								list5.Add((array7.Length > 2 && array7[2].Length > 0) ? list2[Ix(array7[2], list2.Count)] : Vector3.up);
								value2 = list4.Count - 1;
								dictionary[array5[j]] = value2;
							}
							array6[j - 1] = value2;
						}
						for (int k = 1; k + 1 < array6.Length; k++)
						{
							list7.Add(array6[0]);
							list7.Add(array6[k + 1]);
							list7.Add(array6[k]);
						}
					}
				}
				value = new Mesh
				{
					name = Path.GetFileNameWithoutExtension(file)
				};
				if (list4.Count > 65000)
				{
					value.indexFormat = (IndexFormat)1;
				}
				value.SetVertices(list4);
				value.SetNormals(list5);
				value.SetUVs(0, list6);
				value.SetTriangles(list7, 0);
				value.RecalculateBounds();
				value.RecalculateTangents();
				s_mesh[file] = value;
				return value;
			}

			private static int Ix(string s, int count)
			{
				int num = int.Parse(s, CultureInfo.InvariantCulture);
				if (num <= 0)
				{
					return count + num;
				}
				return num - 1;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static EventHandler<SettingChangedEventArgs> <0>__OnSettingChanged;

			public static Action<ZRpc, string> <1>__Client_State;

			public static Action<ZRpc, string> <2>__Client_Msg;

			public static Action<ZRpc, string> <3>__Client_Roster;

			public static Action<ZRpc, string> <4>__Client_Lock;

			public static Action<ZRpc, string> <5>__Client_Portals;

			public static Action<ZRpc, string> <6>__Client_Version;

			public static ConsoleEvent <7>__Command;

			public static ConsoleOptionsFetcher <8>__OptionsFetcher;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Requirement[], int, string> <>9__63_1;

			public static Func<Gate, string> <>9__63_2;

			public static ConditionalWeakTable<ZRpc, Conn>.CreateValueCallback <>9__139_0;

			public static ConsoleEvent <>9__166_0;

			public static ConsoleEvent <>9__166_1;

			public static ConsoleEvent <>9__166_2;

			public static EventHandler<SettingChangedEventArgs> <>9__230_0;

			public static Converter<int, string> <>9__238_0;

			internal string <WriteCatalog>b__63_1(Requirement[] reqs, int mode)
			{
				List<string> list = new List<string>();
				if (reqs != null)
				{
					foreach (Requirement val in reqs)
					{
						if (val != null && (Object)(object)val.m_resItem != (Object)null)
						{
							list.Add(((Object)((Component)val.m_resItem).gameObject).name + ":" + ((mode == 0) ? val.m_amount : val.m_amountPerLevel));
						}
					}
				}
				return string.Join(",", list.ToArray());
			}

			internal string <WriteCatalog>b__63_2(Gate g)
			{
				if (g != null)
				{
					return g.Prof + "\t" + g.Level + "\t" + g.Why;
				}
				return "\t\t";
			}

			internal Conn <ConnOf>b__139_0(ZRpc r)
			{
				return new Conn
				{
					Host = HostOf(r)
				};
			}

			internal void <RegisterCommand>b__166_0(ConsoleEventArgs args)
			{
				ReloadCommand(args.Context);
			}

			internal void <RegisterCommand>b__166_1(ConsoleEventArgs args)
			{
				DumpCatalog(args.Context);
			}

			internal void <RegisterCommand>b__166_2(ConsoleEventArgs args)
			{
				DumpGates(args.Context);
			}

			internal void <BindWindow>b__230_0(object s, SettingChangedEventArgs e)
			{
				ResetGateCache();
			}

			internal string <DrawDetails>b__238_0(int x)
			{
				return x.ToString(CultureInfo.InvariantCulture);
			}
		}

		private static ConfigEntry<bool> s_gatesOn;

		private static ConfigEntry<string> s_tierLevels;

		private static ConfigEntry<string> s_gateOverrides;

		private static ConfigEntry<string> s_extraTiers;

		private static ConfigEntry<bool> s_openStations;

		private static ConfigEntry<string> s_openTools;

		private static ConfigEntry<string> s_cookTools;

		private static ConfigEntry<string> s_mysticStations;

		private static ConfigEntry<string> s_sailTools;

		private static ConfigEntry<string> s_sailStations;

		private static Dictionary<string, string> s_pieceTool;

		private static HashSet<string> s_vanillaItems;

		private static HashSet<string> s_vanillaPieces;

		private static ConfigEntry<bool> s_catalogOnBoot;

		private static HashSet<string> s_vanillaPrefabs;

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

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

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

		private static Dictionary<string, Gate> s_overrides;

		private static ConfigEntry<bool> s_shipGates;

		private static ConfigEntry<string> s_openShips;

		private static ConfigEntry<string> s_stationRules;

		private static List<KeyValuePair<Regex, Gate>> s_stations;

		private static int[] s_levels = new int[8] { 10, 25, 35, 45, 55, 65, 75, 85 };

		internal const int Tiers = 8;

		private const string DefaultTiers = "0:Wood,Stone,Flint,Resin,LeatherScraps,DeerHide,Feathers,BoneFragments,HardAntler,Honey,Raspberry,Mushroom,Dandelion,NeckTail,RawMeat,DeerMeat,QueenBee,TrophyEikthyr,TrophyDeer,TrophyBoar,TrophyNeck,Amber,Coins,BeltStrength,BoarJerky,CookedMeat,CookedDeerMeat|1:Copper,CopperOre,Tin,TinOre,Bronze,BronzeNails,TrollHide,FineWood,RoundLog,GreydwarfEye,SurtlingCore,AncientSeed,Coal,Blueberries,MushroomYellow,Carrot,CarrotSeeds,Thistle,TrophyTheElder,CryptKey,AmberPearl,Ruby,Bjorn hide,BjornHide,BjornPaw,TrophyGreydwarf,TrophyGreydwarfBrute,TrophyGreydwarfShaman,TrophyFrostTroll,TrophySkeleton|2:Iron,IronScrap,IronOre,IronNails,Chain,ElderBark,Guck,Ooze,Bloodbag,Root,WitheredBone,Entrails,SerpentScale,SerpentMeat,Turnip,TurnipSeeds,TurnipStew,Chitin,TrophyBonemass,Wishbone,Pukeberries,Sap_unused|3:Silver,SilverOre,SilverNecklace,WolfPelt,WolfFang,WolfClaw,WolfMeat,Obsidian,Crystal,FreezeGland,DragonTear,DragonEgg,JuteRed,Onion,OnionSeeds,TrophyDragonQueen,TrophyCultist,FenrisHair,FenrisClaw,RottenPelt|4:BlackMetal,BlackMetalScrap,Flax,LinenThread,Barley,BarleyFlour,LoxPelt,LoxMeat,Needle,Tar,GoblinTotem,Cloudberry,TrophyGoblinKing,YagluthDrop,BugMeat,BonemawSerpentTooth,BonemawSerpentScale|5:Eitr,Sap,BlackMarble,BlackCore,Carapace,Mandible,YggdrasilWood,Softtissue,ScaleHide,JuteBlue,Wisp,Bilebag,DvergrNeedle,DvergrKey,MushroomJotunPuffs,MushroomMagecap,RoyalJelly,TrophySeekerQueen,QueenDrop,GiantBloodSack,HareMeat,ChickenMeat,ChickenEgg,Copper_unused|