Decompiled source of PeakClasses v1.0.7

BepInEx/plugins/PeakClasses/PeakClasses.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreCustomizations;
using MoreCustomizations.Data;
using PEAKLib.Core;
using PEAKLib.Items;
using Peak;
using Peak.Afflictions;
using Photon.Pun;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Zorro.Core;

[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 WizardFit
{
	[BepInPlugin("satyan.peak.peakclasses", "PeakClasses", "1.0.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class WizardFitPlugin : BaseUnityPlugin
	{
		public const string GUID = "satyan.peak.peakclasses";

		public const string NAME = "PeakClasses";

		public const string VERSION = "1.0.7";

		internal static ManualLogSource Log;

		internal static WizardFitPlugin Instance;

		internal static ConfigEntry<string> Language;

		internal static ConfigEntry<bool> DebugGrip;

		internal static ConfigEntry<bool> IconAutoDiagonal;

		internal static ConfigEntry<bool> DumpIcons;

		internal static ConfigEntry<float> IconDiagonalAngle;

		internal static ConfigEntry<float> IconDiagonalCutoff;

		internal static ConfigEntry<float> IconOutline;

		internal static ConfigEntry<float> IconAmbient;

		internal static ConfigEntry<float> IconLight;

		internal static ConfigEntry<string> IconOutlineColor;

		internal static ConfigEntry<bool> EnableRobe;

		internal static ConfigEntry<bool> EnableHat;

		internal static ConfigEntry<bool> EnableBeard;

		internal static ConfigEntry<float> HatScale;

		internal static ConfigEntry<float> HatPosX;

		internal static ConfigEntry<float> HatPosY;

		internal static ConfigEntry<float> HatPosZ;

		internal static ConfigEntry<float> HatRotX;

		internal static ConfigEntry<float> HatRotY;

		internal static ConfigEntry<float> HatRotZ;

		internal static ConfigEntry<string> RobeBaseMesh;

		internal static CustomFit_V1 RobeData;

		internal static CustomFit_V1 TunicData;

		internal static CustomHat_V1 HatData;

		internal static CustomHat_V1 TiaraData;

		internal static CustomAccessory_V1 BeardData;

		internal static CustomAccessory_V1 HairData;

		internal static readonly List<CustomFit_V1> AllFits = new List<CustomFit_V1>();

		private static GameObject _hatPrefabRoot;

		private static GameObject _tiaraPrefabRoot;

		internal static ConfigEntry<bool> EnableElfSet;

		internal static ConfigEntry<bool> EnableMedicSet;

		internal static ConfigEntry<bool> EnableWindSet;

		internal static ConfigEntry<bool> EnableSapperSet;

		internal static CustomFit_V1 VestData;

		internal static CustomHat_V1 HelmetData;

		internal static CustomAccessory_V1 SafetyGogglesData;

		private static GameObject _helmetPrefabRoot;

		internal static CustomFit_V1 WindRobeData;

		internal static CustomHat_V1 WindHatData;

		internal static CustomAccessory_V1 WindHairData;

		private static GameObject _windHatPrefabRoot;

		internal static CustomFit_V1 JacketData;

		internal static CustomHat_V1 BeanieData;

		internal static CustomAccessory_V1 GogglesData;

		private static GameObject _beaniePrefabRoot;

		internal static ConfigEntry<float> TiaraRotY;

		private const float BEANIE_EDGE = 0.27f;

		private static string AssetDir => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "assets");

		internal static string T(string en, string pt, string custom = null)
		{
			if (!string.IsNullOrWhiteSpace(custom))
			{
				return custom;
			}
			if (!((Language != null) ? (Language.Value ?? "en").Trim().ToLowerInvariant() : "en").StartsWith("pt"))
			{
				return en;
			}
			return pt;
		}

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				BindConfig();
				WizardStaff.BindConfig(((BaseUnityPlugin)this).Config);
				ElfBow.BindConfig(((BaseUnityPlugin)this).Config);
				StartingKit.BindConfig(((BaseUnityPlugin)this).Config);
				Charges.BindConfig(((BaseUnityPlugin)this).Config);
				MedicHook.BindConfig(((BaseUnityPlugin)this).Config);
				WindStaff.BindConfig(((BaseUnityPlugin)this).Config);
				SapperTool.BindConfig(((BaseUnityPlugin)this).Config);
				TestKeys.BindConfig(((BaseUnityPlugin)this).Config);
				CreateContent();
				RegisterWithMoreCustomizations();
				ApplyPatches();
				((Component)this).gameObject.AddComponent<TestKeys>();
				Log.LogInfo((object)"PeakClasses 1.0.7 loaded (built 2026-09-15 19:43:27 UTC).");
				LogSettings();
			}
			catch (Exception arg)
			{
				Log.LogError((object)string.Format("{0} failed to initialize and will stay disabled: {1}", "PeakClasses", arg));
			}
		}

		private void LogSettings()
		{
			try
			{
				Log.LogInfo((object)("Settings in effect: " + $"AuraRadiusMultiplier={WizardStaff.AuraRadiusMultiplier.Value}, " + $"AuraGlareMultiplier={WizardStaff.AuraVisualMultiplier.Value}, " + $"ShowAuraDome={WizardStaff.ShowDome.Value}, " + $"AuraDomeOpacity={WizardStaff.DomeOpacity.Value}, " + $"AuraDomeBorderBrightness={WizardStaff.DomeBorderBoost.Value}, " + $"AuraDomeEdgeSharpness={WizardStaff.DomeEdgeSharpness.Value}, " + $"GustStrength={WindStaff.GustForce.Value}, " + $"Language={Language.Value}, DumpIcons={DumpIcons.Value}"));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not print the settings: " + ex.Message));
			}
		}

		private void ApplyPatches()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("satyan.peak.peakclasses");
			int num = 0;
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0)
				{
					try
					{
						val.PatchAll(type);
						num++;
					}
					catch (Exception ex)
					{
						Log.LogError((object)("Patch '" + type.Name + "' could not be applied: " + ex.Message));
					}
				}
			}
			Log.LogInfo((object)$"Applied {num} patch classes.");
		}

		private void BindConfig()
		{
			DebugGrip = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugGrip", false, "Log where a held class item and the hand actually are, for tuning the grip.");
			IconAutoDiagonal = ((BaseUnityPlugin)this).Config.Bind<bool>("Icons", "LayDiagonally", true, "Turn each item so its longest side lies diagonally across its icon, the way the game's own icons read. Off keeps whatever rotation the item is given.");
			IconDiagonalAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "DiagonalAngle", 35f, "The angle that diagonal sits at, in degrees. Positive points up to the right.");
			IconDiagonalCutoff = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "DiagonalCutoff", 0.85f, "How stubby an item may be and still be laid diagonally. 1 lays everything, 0.5 only clearly long items.");
			IconOutline = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "OutlineWidth", 0.018f, "Thickness of the dark line around the icon, as a share of its width. 0 for none. Every vanilla icon has one.");
			IconOutlineColor = ((BaseUnityPlugin)this).Config.Bind<string>("Icons", "OutlineColor", "1A1410", "Colour of that line (RRGGBB).");
			IconAmbient = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "Ambient", 0.85f, "Ambient light while the icon is rendered. The game's own item materials need it — without it they come out nearly black.");
			IconLight = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "LightStrength", 1f, "Multiplier on the two lights that shape the item.");
			DumpIcons = ((BaseUnityPlugin)this).Config.Bind<bool>("Icons", "DumpIcons", false, "Also write every rendered icon, and a few of the game's own for comparison, as PNGs into an icon-dump folder next to the plugin.");
			Language = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "en", "Language of the item names and prompts shown in game: en or pt.");
			EnableRobe = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableRobe", true, "Add the wizard robe (fit).");
			EnableHat = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableHat", true, "Add the pointed wizard hat.");
			EnableBeard = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableBeard", true, "Add the white beard accessory.");
			EnableElfSet = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableElfSet", true, "Add the elf ranger set (hair, tunic, leaf tiara).");
			EnableMedicSet = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMedicSet", true, "Add the medic set (goggles, jacket, beanie).");
			EnableWindSet = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableWindSet", true, "Add the wind mage set (silver fringe, blue robe, feathered hat).");
			EnableSapperSet = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableSapperSet", true, "Add the sapper set (safety goggles, orange vest, hard hat).");
			TiaraRotY = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "TiaraRotY", 0f, "Spin the tiara+hair around the head (degrees) if the hair ends up over the face.");
			RobeBaseMesh = ((BaseUnityPlugin)this).Config.Bind<string>("Robe", "BaseMeshName", "Seagull", "Name fragment of the vanilla fit whose mesh the robe reuses (texture-only reskin). Empty = first fit.");
			HatScale = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "Scale", 1f, "Uniform scale of the hat.");
			HatPosX = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "PosX", 0f, "Position offset (Blender-style: X right, Y forward, Z up).");
			HatPosY = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "PosY", 0f, "Position offset Y (forward).");
			HatPosZ = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "PosZ", 0f, "Position offset Z (up).");
			HatRotX = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "RotX", 0f, "Rotation offset in degrees.");
			HatRotY = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "RotY", 0f, "Rotation offset in degrees.");
			HatRotZ = ((BaseUnityPlugin)this).Config.Bind<float>("Hat", "RotZ", 0f, "Rotation offset in degrees.");
		}

		private void CreateContent()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			if (EnableBeard.Value)
			{
				BeardData = MakeAccessory("wizard_beard", "wizard_beard.png");
			}
			if (EnableRobe.Value)
			{
				RobeData = MakeFit("wizard_robe", "icon_robe.png", "wizard_robe.png", "wizard_shoes.png");
			}
			if (EnableHat.Value)
			{
				HatData = MakeHat("wizard_hat", "icon_hat.png", "wizard_hat.png", _hatPrefabRoot = BuildHatPrefab(feather: false), new Vector3(HatPosX.Value, HatPosY.Value, HatPosZ.Value), new Vector3(HatRotX.Value, HatRotY.Value, HatRotZ.Value));
			}
			if (EnableElfSet.Value)
			{
				HairData = MakeAccessory("elf_hair", "elf_hair.png");
				TunicData = MakeFit("elf_tunic", "icon_tunic.png", "elf_tunic.png", "elf_boots.png");
				TiaraData = MakeHat("elf_tiara", "icon_tiara.png", "elf_tiara.png", _tiaraPrefabRoot = BuildTiaraPrefab(), Vector3.zero, new Vector3(0f, TiaraRotY.Value, 0f));
			}
			if (EnableMedicSet.Value)
			{
				GogglesData = MakeAccessory("medic_goggles", "medic_goggles.png");
				JacketData = MakeFit("medic_jacket", "icon_jacket.png", "medic_jacket.png", "medic_boots.png");
				BeanieData = MakeHat("medic_beanie", "icon_beanie.png", "medic_beanie.png", _beaniePrefabRoot = BuildBeaniePrefab(), Vector3.zero, Vector3.zero);
			}
			if (EnableWindSet.Value)
			{
				WindHairData = MakeAccessory("wind_hair", "wind_hair.png");
				WindRobeData = MakeFit("wind_robe", "icon_windrobe.png", "wind_robe.png", "wind_boots.png");
				WindHatData = MakeHat("wind_hat", "icon_windhat.png", "wind_hat.png", _windHatPrefabRoot = BuildHatPrefab(feather: true), new Vector3(HatPosX.Value, HatPosY.Value, HatPosZ.Value), new Vector3(HatRotX.Value, HatRotY.Value, HatRotZ.Value));
			}
			if (EnableSapperSet.Value)
			{
				SafetyGogglesData = MakeAccessory("sapper_goggles", "sapper_goggles.png");
				VestData = MakeFit("sapper_vest", "icon_vest.png", "sapper_vest.png", "sapper_boots.png");
				HelmetData = MakeHat("sapper_helmet", "icon_helmet.png", "sapper_helmet.png", _helmetPrefabRoot = BuildHelmetPrefab(), Vector3.zero, Vector3.zero);
			}
		}

		private static CustomAccessory_V1 MakeAccessory(string name, string texFile)
		{
			CustomAccessory_V1 obj = ScriptableObject.CreateInstance<CustomAccessory_V1>();
			((Object)obj).name = name;
			Set((Object)(object)obj, "Texture", LoadTexture(texFile));
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static CustomFit_V1 MakeFit(string name, string iconFile, string mainFile, string shoesFile)
		{
			CustomFit_V1 val = ScriptableObject.CreateInstance<CustomFit_V1>();
			((Object)val).name = name;
			Set((Object)(object)val, "Icon", LoadTexture(iconFile));
			Set((Object)(object)val, "FitMainTexture", LoadTexture(mainFile));
			Set((Object)(object)val, "FitShoeTexture", LoadTexture(shoesFile));
			Set((Object)(object)val, "IsSkirt", false);
			Set((Object)(object)val, "NoPants", false);
			Set((Object)(object)val, "DrawUnderEye", false);
			((Object)val).hideFlags = (HideFlags)61;
			AllFits.Add(val);
			return val;
		}

		private static CustomHat_V1 MakeHat(string name, string iconFile, string texFile, GameObject prefab, Vector3 pos, Vector3 rot)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			CustomHat_V1 obj = ScriptableObject.CreateInstance<CustomHat_V1>();
			((Object)obj).name = name;
			Set((Object)(object)obj, "Icon", LoadTexture(iconFile));
			Texture2D value = LoadTexture(texFile);
			Set((Object)(object)obj, "MainTexture", value);
			Set((Object)(object)obj, "SubTexture", value);
			Set((Object)(object)obj, "Prefab", prefab);
			Set((Object)(object)obj, "PositionOffset", pos);
			Set((Object)(object)obj, "EulerAngleOffset", rot);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		internal static void Set(Object target, string property, object value)
		{
			(AccessTools.Property(((object)target).GetType(), property) ?? throw new MissingMemberException(((object)target).GetType().Name + "." + property + " not found")).SetValue(target, value);
		}

		internal static Vector3 IconEuler(string section, float x, float y, float z)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return new Vector3(((BaseUnityPlugin)Instance).Config.Bind<float>(section, "IconRotX", x, "Model rotation used for the rendered inventory icon.").Value, ((BaseUnityPlugin)Instance).Config.Bind<float>(section, "IconRotY", y, "Model rotation used for the rendered inventory icon.").Value, ((BaseUnityPlugin)Instance).Config.Bind<float>(section, "IconRotZ", z, "Model rotation used for the rendered inventory icon.").Value);
			}
			catch
			{
				return new Vector3(x, y, z);
			}
		}

		internal static void VerifyItemId(object database, Dictionary<ushort, Item> lookup, string prefabName)
		{
			if (lookup == null || string.IsNullOrEmpty(prefabName))
			{
				return;
			}
			try
			{
				Item val = ((IEnumerable<Item>)lookup.Values).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && ((Object)((Component)i).gameObject).name == prefabName));
				if ((Object)(object)val == (Object)null)
				{
					val = ((IEnumerable<Item>)Resources.FindObjectsOfTypeAll<Item>()).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && ((Object)((Component)i).gameObject).name == prefabName));
					if ((Object)(object)val == (Object)null)
					{
						Log.LogWarning((object)(prefabName + ": not found to verify its id."));
						return;
					}
				}
				if (lookup.TryGetValue(val.itemID, out var value) && (Object)(object)value == (Object)(object)val)
				{
					Log.LogInfo((object)$"{prefabName}: id {val.itemID} checks out.");
					return;
				}
				string id = ModDefinition.GetOrCreate(((BaseUnityPlugin)Instance).Info.Metadata).Id;
				ushort num;
				using (MD5 mD = MD5.Create())
				{
					num = BitConverter.ToUInt16(mD.ComputeHash(Encoding.UTF8.GetBytes(id + ((Object)((Component)val).gameObject).name)), 0);
				}
				ushort num2 = num;
				while (lookup.ContainsKey(num))
				{
					num++;
					if (num == num2)
					{
						break;
					}
				}
				ushort itemID = val.itemID;
				val.itemID = num;
				lookup[num] = val;
				try
				{
					IList list = ((database != null) ? (AccessTools.Field(database.GetType(), "Objects")?.GetValue(database) as IList) : null);
					if (list != null && !list.Contains(val))
					{
						list.Add(val);
					}
				}
				catch
				{
				}
				Log.LogWarning((object)$"{prefabName}: was still answering to the vanilla id {itemID}; reassigned to {num}.");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"{prefabName}: could not verify the item id: {arg}");
			}
		}

		internal static Color ParseOutlineColor()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString("#" + (IconOutlineColor.Value ?? "").TrimStart('#'), ref result))
			{
				return result;
			}
			return new Color(0.1f, 0.08f, 0.06f);
		}

		internal static void PrepareClassItem(Item item)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (item.UIData != null)
				{
					item.UIData.hideFuel = false;
				}
				try
				{
					Log.LogInfo((object)$"{((Object)((Component)item).gameObject).name}: canBackpack={item.UIData?.canBackpack} canPocket={item.UIData?.canPocket} canDrop={item.UIData?.canDrop} tags={item.itemTags}");
				}
				catch
				{
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(LootData), "spawnLocations");
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(LootData), "excludeFromCustomRunSelection");
				int num = 0;
				LootData[] componentsInChildren = ((Component)item).GetComponentsInChildren<LootData>(true);
				foreach (LootData obj2 in componentsInChildren)
				{
					if (fieldInfo != null)
					{
						fieldInfo.SetValue(obj2, Enum.ToObject(fieldInfo.FieldType, 0));
					}
					if (fieldInfo2 != null && fieldInfo2.FieldType == typeof(bool))
					{
						fieldInfo2.SetValue(obj2, true);
					}
					num++;
				}
				Log.LogInfo((object)$"{((Object)((Component)item).gameObject).name}: kept out of the loot pools ({num} LootData), hideFuel={item.UIData?.hideFuel}.");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("PrepareClassItem: " + ex.Message));
			}
		}

		internal static Texture2D TryLoadTexture(string file)
		{
			try
			{
				return LoadTexture(file);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Texture '" + file + "' not loaded: " + ex.Message));
				return null;
			}
		}

		private static byte[] ReadAsset(string file)
		{
			try
			{
				string path = Path.Combine(AssetDir, file);
				if (File.Exists(path))
				{
					return File.ReadAllBytes(path);
				}
			}
			catch
			{
			}
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("assets/" + file);
			if (stream == null)
			{
				throw new FileNotFoundException("Asset '" + file + "' is neither on disk nor embedded");
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num <= 0)
				{
					break;
				}
			}
			return array;
		}

		private static Texture2D LoadTexture(string file)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, ReadAsset(file)))
			{
				throw new Exception("Could not decode '" + file + "'");
			}
			((Object)val).name = Path.GetFileNameWithoutExtension(file);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)1;
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private static GameObject BuildHatPrefab(bool feather)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: 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_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Expected O, but got Unknown
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Expected O, but got Unknown
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04be: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			float value = HatScale.Value;
			float num = 0.77825f;
			float num2 = 1.5848f;
			float num3 = 4.245f;
			float num4 = 2.9714997f;
			float num5 = 1.2735f;
			int num6 = 24;
			int num7 = 14;
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<int> list4 = new List<int>();
			List<int> list5 = new List<int>();
			Vector3 val = default(Vector3);
			Vector3 val2;
			for (int i = 0; i <= num7; i++)
			{
				float num8 = (float)i / (float)num7;
				float num9 = num2 * Mathf.Pow(1f - num8, 1.15f);
				float num10 = num5 * Mathf.Pow(num8, 3f);
				float num11 = num + num3 * Mathf.Sin(num8 * (float)Math.PI * 0.5f);
				for (int j = 0; j <= num6; j++)
				{
					float num12 = (float)j / (float)num6 * (float)Math.PI * 2f;
					((Vector3)(ref val))..ctor(Mathf.Cos(num12) * num9, num11, Mathf.Sin(num12) * num9 - num10);
					list.Add(val * value);
					list2.Add(new Vector2((float)j / (float)num6, num8));
					val2 = new Vector3(Mathf.Cos(num12), 0.35f, Mathf.Sin(num12));
					list3.Add(((Vector3)(ref val2)).normalized);
				}
			}
			for (int k = 0; k < num7; k++)
			{
				for (int l = 0; l < num6; l++)
				{
					int num13 = k * (num6 + 1) + l;
					int num14 = num13 + num6 + 1;
					list4.AddRange(new int[6]
					{
						num13,
						num14,
						num13 + 1,
						num13 + 1,
						num14,
						num14 + 1
					});
				}
			}
			int count = list.Count;
			float num15 = num - 0.028299998f;
			Vector3 val3 = default(Vector3);
			Vector3 val4 = default(Vector3);
			for (int m = 0; m < 2; m++)
			{
				for (int n = 0; n <= num6; n++)
				{
					float num16 = (float)n / (float)num6 * (float)Math.PI * 2f;
					float num17 = 1f + 0.04f * Mathf.Sin(num16 * 3f);
					((Vector3)(ref val3))..ctor(Mathf.Cos(num16) * num2 * 0.98f, num15, Mathf.Sin(num16) * num2 * 0.98f);
					((Vector3)(ref val4))..ctor(Mathf.Cos(num16) * num4 * num17, num15 - 0.1698f * (1f - Mathf.Cos(num16 * 2f) * 0.3f), Mathf.Sin(num16) * num4 * num17);
					list.Add(val3 * value);
					list.Add(val4 * value);
					list2.Add(new Vector2(0.5f + Mathf.Cos(num16) * 0.2f, 0.5f + Mathf.Sin(num16) * 0.2f));
					list2.Add(new Vector2(0.5f + Mathf.Cos(num16) * 0.45f, 0.5f + Mathf.Sin(num16) * 0.45f));
					Vector3 item = ((m == 0) ? Vector3.up : Vector3.down);
					list3.Add(item);
					list3.Add(item);
				}
			}
			for (int num18 = 0; num18 < 2; num18++)
			{
				int num19 = count + num18 * (num6 + 1) * 2;
				for (int num20 = 0; num20 < num6; num20++)
				{
					int num21 = num19 + num20 * 2;
					int num22 = num21 + 1;
					int num23 = num21 + 2;
					int num24 = num23 + 1;
					if (num18 == 0)
					{
						list5.AddRange(new int[6] { num21, num22, num23, num23, num22, num24 });
					}
					else
					{
						list5.AddRange(new int[6] { num21, num23, num22, num22, num23, num24 });
					}
				}
			}
			if (feather)
			{
				Vector3 val5 = new Vector3(num2 * 0.7f, num + 0.21225001f, (0f - num2) * 0.55f) * value;
				val2 = new Vector3(0.35f, 0.9f, -0.5f);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				float num25 = 3.113f * value;
				float num26 = 0.22639999f * value;
				val2 = Vector3.Cross(normalized, Vector3.forward);
				Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
				int[] array = new int[2] { 1, -1 };
				foreach (int num28 in array)
				{
					int count2 = list.Count;
					val2 = Vector3.Cross(normalized2, normalized);
					Vector3 item2 = ((Vector3)(ref val2)).normalized * (float)num28;
					list.Add(val5);
					list.Add(val5 + normalized * num25 * 0.5f + normalized2 * num26);
					list.Add(val5 + normalized * num25);
					list.Add(val5 + normalized * num25 * 0.5f - normalized2 * num26);
					for (int num29 = 0; num29 < 4; num29++)
					{
						list3.Add(item2);
						list2.Add(new Vector2(0.5f, 0.96f));
					}
					if (num28 == 1)
					{
						list5.AddRange(new int[6]
						{
							count2,
							count2 + 1,
							count2 + 2,
							count2,
							count2 + 2,
							count2 + 3
						});
					}
					else
					{
						list5.AddRange(new int[6]
						{
							count2,
							count2 + 2,
							count2 + 1,
							count2,
							count2 + 3,
							count2 + 2
						});
					}
				}
			}
			Mesh val6 = new Mesh
			{
				name = "WizardHatMesh"
			};
			val6.SetVertices(list);
			val6.SetUVs(0, list2);
			val6.SetNormals(list3);
			val6.subMeshCount = 2;
			val6.SetTriangles(list4, 0);
			val6.SetTriangles(list5, 1);
			val6.RecalculateBounds();
			((Object)val6).hideFlags = (HideFlags)61;
			_hatPrefabRoot = new GameObject("WizardHat_Prefab");
			_hatPrefabRoot.transform.position = new Vector3(0f, -5000f, 0f);
			Object.DontDestroyOnLoad((Object)(object)_hatPrefabRoot);
			_hatPrefabRoot.AddComponent<MeshFilter>().sharedMesh = val6;
			((Renderer)_hatPrefabRoot.AddComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[2];
			return _hatPrefabRoot;
		}

		private static GameObject BuildTiaraPrefab()
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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_029c: 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_029f: 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_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: 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_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: 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_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_069b: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_082c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0831: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Expected O, but got Unknown
			//IL_088b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08af: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b5: Expected O, but got Unknown
			//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d4: Expected O, but got Unknown
			//IL_06f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_074f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0751: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			//IL_075a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0766: Unknown result type (might be due to invalid IL or missing references)
			//IL_078a: Unknown result type (might be due to invalid IL or missing references)
			float num = 1.4432999f;
			float num2 = 0.5943f;
			float num3 = 0.063675f;
			int num4 = 48;
			int num5 = 8;
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<int> list4 = new List<int>();
			List<int> list5 = new List<int>();
			Vector3 val = default(Vector3);
			Vector3 val2 = default(Vector3);
			for (int i = 0; i <= num4; i++)
			{
				float num6 = (float)i / (float)num4 * (float)Math.PI * 2f;
				((Vector3)(ref val))..ctor(Mathf.Cos(num6) * num, num2 + Mathf.Sin(num6 * 2f) * 1.415f * 0.04f, Mathf.Sin(num6) * num);
				((Vector3)(ref val2))..ctor(Mathf.Cos(num6), 0f, Mathf.Sin(num6));
				for (int j = 0; j <= num5; j++)
				{
					float num7 = (float)j / (float)num5 * (float)Math.PI * 2f;
					Vector3 val3 = val2 * Mathf.Cos(num7) + Vector3.up * Mathf.Sin(num7);
					list.Add(val + val3 * num3);
					list3.Add(val3);
					list2.Add(new Vector2((float)i / (float)num4 * 4f, 0.625f + 0.1f * Mathf.Sin(num7)));
				}
			}
			for (int k = 0; k < num4; k++)
			{
				for (int l = 0; l < num5; l++)
				{
					int num8 = k * (num5 + 1) + l;
					int num9 = num8 + num5 + 1;
					list4.AddRange(new int[6]
					{
						num8,
						num9,
						num8 + 1,
						num8 + 1,
						num9,
						num9 + 1
					});
				}
			}
			int num10 = 14;
			Vector3 val5 = default(Vector3);
			Vector3 val6 = default(Vector3);
			for (int m = 0; m < num10; m++)
			{
				float num11 = (float)m / (float)num10 * (float)Math.PI * 2f;
				Vector3 val4 = new Vector3(Mathf.Cos(num11) * num, num2, Mathf.Sin(num11) * num);
				((Vector3)(ref val5))..ctor(Mathf.Cos(num11), 0f, Mathf.Sin(num11));
				((Vector3)(ref val6))..ctor(0f - Mathf.Sin(num11), 0f, Mathf.Cos(num11));
				float num12 = 1.415f * (0.28f + 0.1f * ((float)(m % 3) / 2f));
				float num13 = 0.1698f;
				Vector3 val7 = val4 + val5 * num12 * 0.55f + Vector3.up * num12 * 0.85f;
				Vector3 val8 = val4 - val6 * num13 + val5 * num3;
				Vector3 val9 = val4 + val6 * num13 + val5 * num3;
				Vector3 val10 = val4 + val5 * num12 * 0.35f + Vector3.up * num12 * 0.35f;
				int[] array = new int[2] { 1, -1 };
				foreach (int num14 in array)
				{
					int count = list.Count;
					Vector3 val11 = Vector3.Cross(val9 - val8, val7 - val8);
					Vector3 item = ((Vector3)(ref val11)).normalized * (float)num14;
					list.Add(val8);
					list.Add(val9);
					list.Add(val10 + val6 * num13 * 0.9f);
					list.Add(val10 - val6 * num13 * 0.9f);
					list.Add(val7);
					for (int num15 = 0; num15 < 5; num15++)
					{
						list3.Add(item);
					}
					list2.Add(new Vector2(0.3f, 0.78f));
					list2.Add(new Vector2(0.7f, 0.78f));
					list2.Add(new Vector2(0.8f, 0.9f));
					list2.Add(new Vector2(0.2f, 0.9f));
					list2.Add(new Vector2(0.5f, 0.99f));
					if (num14 == 1)
					{
						list5.AddRange(new int[9]
						{
							count,
							count + 1,
							count + 2,
							count,
							count + 2,
							count + 3,
							count + 3,
							count + 2,
							count + 4
						});
					}
					else
					{
						list5.AddRange(new int[9]
						{
							count,
							count + 2,
							count + 1,
							count,
							count + 3,
							count + 2,
							count + 3,
							count + 4,
							count + 2
						});
					}
				}
			}
			float num16 = 1.51405f;
			int num17 = 10;
			int num18 = 24;
			int count2 = list.Count;
			Vector3 val12 = default(Vector3);
			for (int num19 = 0; num19 <= num17; num19++)
			{
				float num20 = Mathf.Lerp((float)Math.PI / 2f, -0.47123894f, (float)num19 / (float)num17);
				for (int num21 = 0; num21 <= num18; num21++)
				{
					float num22 = Mathf.Lerp((float)Math.PI * -31f / 50f, (float)Math.PI * 31f / 50f, (float)num21 / (float)num18) + (float)Math.PI;
					((Vector3)(ref val12))..ctor(Mathf.Cos(num20) * Mathf.Sin(num22), Mathf.Sin(num20), Mathf.Cos(num20) * Mathf.Cos(num22));
					float num23 = num16 * (1f + 0.03f * Mathf.Sin(num22 * 9f));
					list.Add(val12 * num23);
					list3.Add(val12);
					list2.Add(new Vector2((float)num21 / (float)num18 * 3f, 0.05f + 0.4f * (1f - (float)num19 / (float)num17)));
				}
			}
			for (int num24 = 0; num24 < num17; num24++)
			{
				for (int num25 = 0; num25 < num18; num25++)
				{
					int num26 = count2 + num24 * (num18 + 1) + num25;
					int num27 = num26 + num18 + 1;
					list5.AddRange(new int[6]
					{
						num26,
						num26 + 1,
						num27,
						num26 + 1,
						num27 + 1,
						num27
					});
				}
			}
			int num28 = 9;
			Vector3 val16 = default(Vector3);
			for (int num29 = 0; num29 < num28; num29++)
			{
				float num30 = Mathf.Lerp((float)Math.PI * -11f / 20f, (float)Math.PI * 11f / 20f, (float)num29 / (float)(num28 - 1)) + (float)Math.PI;
				Vector3 val13 = new Vector3(Mathf.Sin(num30), -0.25f, Mathf.Cos(num30)) * num16;
				Vector3 val14 = val13 + new Vector3(Mathf.Sin(num30) * 0.15f, -1.8394998f, Mathf.Cos(num30) * 0.15f);
				int num31 = 6;
				int num32 = 4;
				int count3 = list.Count;
				for (int num33 = 0; num33 <= num32; num33++)
				{
					float num34 = (float)num33 / (float)num32;
					Vector3 val15 = Vector3.Lerp(val13, val14, num34);
					float num35 = 0.12735f * (1f - 0.7f * num34);
					for (int num36 = 0; num36 <= num31; num36++)
					{
						float num37 = (float)num36 / (float)num31 * (float)Math.PI * 2f;
						((Vector3)(ref val16))..ctor(Mathf.Cos(num37), 0f, Mathf.Sin(num37));
						list.Add(val15 + val16 * num35);
						list3.Add(val16);
						list2.Add(new Vector2((float)num36 / (float)num31, 0.05f + 0.4f * (1f - num34)));
					}
				}
				for (int num38 = 0; num38 < num32; num38++)
				{
					for (int num39 = 0; num39 < num31; num39++)
					{
						int num40 = count3 + num38 * (num31 + 1) + num39;
						int num41 = num40 + num31 + 1;
						list5.AddRange(new int[6]
						{
							num40,
							num41,
							num40 + 1,
							num40 + 1,
							num41,
							num41 + 1
						});
					}
				}
			}
			Mesh val17 = new Mesh
			{
				name = "ElfTiaraMesh"
			};
			val17.SetVertices(list);
			val17.SetUVs(0, list2);
			val17.SetNormals(list3);
			val17.subMeshCount = 2;
			val17.SetTriangles(list5, 0);
			val17.SetTriangles(list4, 1);
			val17.RecalculateBounds();
			((Object)val17).hideFlags = (HideFlags)61;
			GameObject val18 = new GameObject("ElfTiara_Prefab");
			val18.transform.position = new Vector3(0f, -5000f, 0f);
			Object.DontDestroyOnLoad((Object)val18);
			val18.AddComponent<MeshFilter>().sharedMesh = val17;
			((Renderer)val18.AddComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[2];
			return val18;
		}

		private static GameObject BuildBeaniePrefab()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: 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_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Expected O, but got Unknown
			//IL_0394: 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_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Expected O, but got Unknown
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Expected O, but got Unknown
			float num = 1.5282f;
			int num2 = 10;
			int num3 = 28;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			List<int> list5 = new List<int>();
			Vector3 val = default(Vector3);
			for (int i = 0; i <= num2; i++)
			{
				float num4 = (float)i / (float)num2;
				float num5 = Mathf.Lerp((float)Math.PI / 2f, (float)Math.PI * 27f / 100f, num4);
				for (int j = 0; j <= num3; j++)
				{
					float num6 = (float)j / (float)num3 * (float)Math.PI * 2f;
					((Vector3)(ref val))..ctor(Mathf.Cos(num5) * Mathf.Sin(num6), Mathf.Sin(num5), Mathf.Cos(num5) * Mathf.Cos(num6));
					float num7 = num * (1f + 0.12f * num4 * num4);
					Vector3 item = val * num7;
					item.y += 0.2547f * (1f - num4);
					list.Add(item);
					list2.Add(val);
					list3.Add(new Vector2((float)j / (float)num3 * 3f, 0.3f + 0.7f * (1f - num4)));
				}
			}
			for (int k = 0; k < num2; k++)
			{
				for (int l = 0; l < num3; l++)
				{
					int num8 = k * (num3 + 1) + l;
					int num9 = num8 + num3 + 1;
					list4.AddRange(new int[6]
					{
						num8,
						num8 + 1,
						num9,
						num8 + 1,
						num9 + 1,
						num9
					});
				}
			}
			float num10 = num * Mathf.Sin((float)Math.PI * 27f / 100f);
			float num11 = num * Mathf.Cos((float)Math.PI * 27f / 100f) * 1.12f;
			float num12 = 0.15564999f;
			int count = list.Count;
			int num13 = 8;
			Vector3 val2 = default(Vector3);
			Vector3 val3 = default(Vector3);
			for (int m = 0; m <= num3; m++)
			{
				float num14 = (float)m / (float)num3 * (float)Math.PI * 2f;
				((Vector3)(ref val2))..ctor(Mathf.Sin(num14) * num11, num10, Mathf.Cos(num14) * num11);
				((Vector3)(ref val3))..ctor(Mathf.Sin(num14), 0f, Mathf.Cos(num14));
				for (int n = 0; n <= num13; n++)
				{
					float num15 = (float)n / (float)num13 * (float)Math.PI * 2f;
					Vector3 val4 = val3 * Mathf.Cos(num15) + Vector3.up * Mathf.Sin(num15);
					list.Add(val2 + val4 * num12);
					list2.Add(val4);
					list3.Add(new Vector2((float)m / (float)num3 * 3f, 0.05f + 0.15f * (0.5f + 0.5f * Mathf.Sin(num15))));
				}
			}
			for (int num16 = 0; num16 < num3; num16++)
			{
				for (int num17 = 0; num17 < num13; num17++)
				{
					int num18 = count + num16 * (num13 + 1) + num17;
					int num19 = num18 + num13 + 1;
					list5.AddRange(new int[6]
					{
						num18,
						num19,
						num18 + 1,
						num18 + 1,
						num19,
						num19 + 1
					});
				}
			}
			Mesh val5 = new Mesh
			{
				name = "MedicBeanieMesh"
			};
			val5.SetVertices(list);
			val5.SetUVs(0, list3);
			val5.SetNormals(list2);
			val5.subMeshCount = 2;
			val5.SetTriangles(list4, 0);
			val5.SetTriangles(list5, 1);
			val5.RecalculateBounds();
			((Object)val5).hideFlags = (HideFlags)61;
			GameObject val6 = new GameObject("MedicBeanie_Prefab");
			val6.transform.position = new Vector3(0f, -5000f, 0f);
			Object.DontDestroyOnLoad((Object)val6);
			val6.AddComponent<MeshFilter>().sharedMesh = val5;
			((Renderer)val6.AddComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[2];
			return val6;
		}

		private static GameObject BuildHelmetPrefab()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: 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_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05df: Expected O, but got Unknown
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Expected O, but got Unknown
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_0662: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Expected O, but got Unknown
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			float num = 1.5565f;
			int num2 = 10;
			int num3 = 28;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			List<int> list5 = new List<int>();
			Vector3 val = default(Vector3);
			for (int i = 0; i <= num2; i++)
			{
				float num4 = (float)i / (float)num2;
				float num5 = Mathf.Lerp((float)Math.PI / 2f, (float)Math.PI * 3f / 25f, num4);
				for (int j = 0; j <= num3; j++)
				{
					float num6 = (float)j / (float)num3 * (float)Math.PI * 2f;
					((Vector3)(ref val))..ctor(Mathf.Cos(num5) * Mathf.Sin(num6), Mathf.Sin(num5), Mathf.Cos(num5) * Mathf.Cos(num6));
					Vector3 item = val * num;
					item.y += 0.0849f;
					list.Add(item);
					list2.Add(val);
					list3.Add(new Vector2((float)j / (float)num3 * 2f, 0.3f + 0.65f * (1f - num4)));
				}
			}
			for (int k = 0; k < num2; k++)
			{
				for (int l = 0; l < num3; l++)
				{
					int num7 = k * (num3 + 1) + l;
					int num8 = num7 + num3 + 1;
					list4.AddRange(new int[6]
					{
						num7,
						num7 + 1,
						num8,
						num7 + 1,
						num8 + 1,
						num8
					});
				}
			}
			float num9 = num * Mathf.Sin((float)Math.PI * 3f / 25f) + 0.0849f;
			float num10 = num * Mathf.Cos((float)Math.PI * 3f / 25f);
			int count = list.Count;
			for (int m = 0; m < 2; m++)
			{
				for (int n = 0; n <= num3; n++)
				{
					float num11 = (float)n / (float)num3 * (float)Math.PI * 2f;
					float num12 = num10 * (1.14f + 0.16f * Mathf.Max(0f, Mathf.Cos(num11)));
					Vector3 item2 = ((m == 0) ? Vector3.up : Vector3.down);
					list.Add(new Vector3(Mathf.Sin(num11) * num10, num9, Mathf.Cos(num11) * num10));
					list2.Add(item2);
					list3.Add(new Vector2((float)n / (float)num3 * 2f, 0.1f));
					list.Add(new Vector3(Mathf.Sin(num11) * num12, num9 - 0.04245f, Mathf.Cos(num11) * num12));
					list2.Add(item2);
					list3.Add(new Vector2((float)n / (float)num3 * 2f, 0.2f));
				}
			}
			for (int num13 = 0; num13 < 2; num13++)
			{
				int num14 = count + num13 * (num3 + 1) * 2;
				for (int num15 = 0; num15 < num3; num15++)
				{
					int num16 = num14 + num15 * 2;
					int num17 = num16 + 1;
					int num18 = num16 + 2;
					int num19 = num18 + 1;
					if (num13 == 0)
					{
						list5.AddRange(new int[6] { num16, num17, num18, num18, num17, num19 });
					}
					else
					{
						list5.AddRange(new int[6] { num16, num18, num17, num17, num18, num19 });
					}
				}
			}
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(0f, 0.77825f, num * 0.9f);
			float num20 = 0.22639999f;
			float num21 = 0.1698f;
			float num22 = 0.1415f;
			Vector3[] array = (Vector3[])(object)new Vector3[8]
			{
				val2 + new Vector3(0f - num20, 0f - num21, 0f),
				val2 + new Vector3(num20, 0f - num21, 0f),
				val2 + new Vector3(num20, num21, 0f),
				val2 + new Vector3(0f - num20, num21, 0f),
				val2 + new Vector3(0f - num20, 0f - num21, num22),
				val2 + new Vector3(num20, 0f - num21, num22),
				val2 + new Vector3(num20, num21, num22),
				val2 + new Vector3(0f - num20, num21, num22)
			};
			int[][] array2 = new int[6][]
			{
				new int[4] { 4, 5, 6, 7 },
				new int[4] { 1, 0, 3, 2 },
				new int[4] { 0, 1, 5, 4 },
				new int[4] { 2, 3, 7, 6 },
				new int[4] { 3, 0, 4, 7 },
				new int[4] { 1, 2, 6, 5 }
			};
			foreach (int[] array3 in array2)
			{
				int count2 = list.Count;
				Vector3 val3 = Vector3.Cross(array[array3[1]] - array[array3[0]], array[array3[2]] - array[array3[0]]);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				int[] array4 = array3;
				foreach (int num25 in array4)
				{
					list.Add(array[num25]);
					list2.Add(normalized);
					list3.Add(new Vector2(0.5f, 0.1f));
				}
				list5.AddRange(new int[6]
				{
					count2,
					count2 + 1,
					count2 + 2,
					count2,
					count2 + 2,
					count2 + 3
				});
			}
			Mesh val4 = new Mesh
			{
				name = "SapperHelmetMesh"
			};
			val4.SetVertices(list);
			val4.SetUVs(0, list3);
			val4.SetNormals(list2);
			val4.subMeshCount = 2;
			val4.SetTriangles(list4, 0);
			val4.SetTriangles(list5, 1);
			val4.RecalculateBounds();
			((Object)val4).hideFlags = (HideFlags)61;
			GameObject val5 = new GameObject("SapperHelmet_Prefab");
			val5.transform.position = new Vector3(0f, -5000f, 0f);
			Object.DontDestroyOnLoad((Object)val5);
			val5.AddComponent<MeshFilter>().sharedMesh = val4;
			((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[2];
			return val5;
		}

		internal static void DropFits()
		{
			AllFits.Clear();
			RobeData = null;
			TunicData = null;
			RegisterWithMoreCustomizations(removeOnly: true);
		}

		private static void RegisterWithMoreCustomizations(bool removeOnly = false)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			PropertyInfo propertyInfo = AccessTools.Property(typeof(MoreCustomizationsPlugin), "AllCustomizationsData");
			IReadOnlyDictionary<Type, IReadOnlyList<CustomizationData>> readOnlyDictionary = propertyInfo.GetValue(null) as IReadOnlyDictionary<Type, IReadOnlyList<CustomizationData>>;
			Dictionary<Type, List<CustomizationData>> merged = new Dictionary<Type, List<CustomizationData>>();
			if (readOnlyDictionary != null)
			{
				foreach (KeyValuePair<Type, IReadOnlyList<CustomizationData>> item in readOnlyDictionary)
				{
					merged[item.Key] = item.Value.Where(delegate(CustomizationData d)
					{
						if ((Object)(object)d != (Object)null)
						{
							CustomFit_V1 val = (CustomFit_V1)(object)((d is CustomFit_V1) ? d : null);
							if (val != null)
							{
								return AllFits.Contains(val);
							}
							return true;
						}
						return false;
					}).ToList();
				}
			}
			if (removeOnly)
			{
				propertyInfo.SetValue(null, ((IEnumerable<KeyValuePair<Type, List<CustomizationData>>>)merged).ToDictionary((Func<KeyValuePair<Type, List<CustomizationData>>, Type>)((KeyValuePair<Type, List<CustomizationData>> k) => k.Key), (Func<KeyValuePair<Type, List<CustomizationData>>, IReadOnlyList<CustomizationData>>)((KeyValuePair<Type, List<CustomizationData>> v) => v.Value)));
				return;
			}
			Add((Type)10, (CustomizationData)(object)BeardData);
			Add((Type)40, (CustomizationData)(object)RobeData);
			Add((Type)50, (CustomizationData)(object)HatData);
			Add((Type)10, (CustomizationData)(object)HairData);
			Add((Type)40, (CustomizationData)(object)TunicData);
			Add((Type)50, (CustomizationData)(object)TiaraData);
			Add((Type)10, (CustomizationData)(object)GogglesData);
			Add((Type)40, (CustomizationData)(object)JacketData);
			Add((Type)50, (CustomizationData)(object)BeanieData);
			Add((Type)10, (CustomizationData)(object)WindHairData);
			Add((Type)40, (CustomizationData)(object)WindRobeData);
			Add((Type)50, (CustomizationData)(object)WindHatData);
			Add((Type)10, (CustomizationData)(object)SafetyGogglesData);
			Add((Type)40, (CustomizationData)(object)VestData);
			Add((Type)50, (CustomizationData)(object)HelmetData);
			Dictionary<Type, IReadOnlyList<CustomizationData>> value = ((IEnumerable<KeyValuePair<Type, List<CustomizationData>>>)merged).ToDictionary((Func<KeyValuePair<Type, List<CustomizationData>>, Type>)((KeyValuePair<Type, List<CustomizationData>> k) => k.Key), (Func<KeyValuePair<Type, List<CustomizationData>>, IReadOnlyList<CustomizationData>>)((KeyValuePair<Type, List<CustomizationData>> v) => v.Value));
			propertyInfo.SetValue(null, value);
			void Add(Type t, CustomizationData d)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)d == (Object)null))
				{
					if (!merged.TryGetValue(t, out var value2))
					{
						value2 = (merged[t] = new List<CustomizationData>());
					}
					value2.Add(d);
					Log.LogInfo((object)$"Queued '{((Object)d).name}' as {t}.");
				}
			}
		}
	}
	[HarmonyPatch(typeof(PassportManager), "Awake")]
	internal static class PassportPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static void Prefix(PassportManager __instance)
		{
			try
			{
				if (WizardFitPlugin.AllFits.Count == 0 || WizardFitPlugin.AllFits.All((CustomFit_V1 f) => (Object)(object)f.FitMesh != (Object)null))
				{
					return;
				}
				Customization component = ((Component)__instance).GetComponent<Customization>();
				if ((Object)(object)component == (Object)null || component.fits == null || component.fits.Length == 0)
				{
					WizardFitPlugin.Log.LogWarning((object)"No vanilla fits found; custom fits skipped.");
					WizardFitPlugin.DropFits();
					return;
				}
				string text = WizardFitPlugin.RobeBaseMesh.Value ?? "";
				CustomizationOption val = null;
				CustomizationOption[] fits = component.fits;
				foreach (CustomizationOption val2 in fits)
				{
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.fitMesh == (Object)null))
					{
						if ((Object)(object)val == (Object)null)
						{
							val = val2;
						}
						if (text.Length > 0 && (((Object)val2).name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)val2.fitMesh).name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0))
						{
							val = val2;
							break;
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					WizardFitPlugin.Log.LogWarning((object)"No fit with a mesh found; custom fits skipped.");
					WizardFitPlugin.DropFits();
					return;
				}
				foreach (CustomFit_V1 allFit in WizardFitPlugin.AllFits)
				{
					if (!((Object)(object)allFit.FitMesh != (Object)null))
					{
						WizardFitPlugin.Set((Object)(object)allFit, "FitMesh", val.fitMesh);
						WizardFitPlugin.Set((Object)(object)allFit, "IsSkirt", val.isSkirt);
						WizardFitPlugin.Set((Object)(object)allFit, "NoPants", val.noPants);
					}
				}
				WizardFitPlugin.Log.LogInfo((object)("Custom fits reuse mesh of vanilla fit '" + ((Object)val).name + "' ('" + ((Object)val.fitMesh).name + "')."));
			}
			catch (Exception arg)
			{
				WizardFitPlugin.Log.LogError((object)$"PassportPatch failed: {arg}");
			}
		}
	}
	internal static class WizardStaff
	{
		internal const string ITEM_NAME = "WizardStaff";

		internal static ConfigEntry<bool> Enable;

		internal static ConfigEntry<bool> GiveAtRunStart;

		internal static ConfigEntry<bool> DumpHierarchy;

		internal static ConfigEntry<string> DisplayName;

		internal static ConfigEntry<string> BaseItemName;

		internal static ConfigEntry<float> Length;

		internal static ConfigEntry<float> Radius;

		internal static ConfigEntry<float> Scale;

		internal static ConfigEntry<float> MeshPosX;

		internal static ConfigEntry<float> MeshPosY;

		internal static ConfigEntry<float> MeshPosZ;

		internal static ConfigEntry<float> MeshRotX;

		internal static ConfigEntry<float> MeshRotY;

		internal static ConfigEntry<float> MeshRotZ;

		internal static ConfigEntry<float> LightPosX;

		internal static ConfigEntry<float> LightPosY;

		internal static ConfigEntry<float> LightPosZ;

		internal static ConfigEntry<float> LightIntensity;

		internal static ConfigEntry<float> GlowStrength;

		internal static ConfigEntry<float> GlowSize;

		internal static ConfigEntry<string> LightColor;

		internal static ConfigEntry<bool> InfiniteFuel;

		internal static ConfigEntry<float> FuelRecharge;

		internal static ConfigEntry<float> VigorAmount;

		internal static ConfigEntry<float> VigorCooldown;

		internal static ConfigEntry<float> VigorFlashSeconds;

		internal static ConfigEntry<float> VigorFlashStrength;

		internal static ConfigEntry<float> AuraRadiusMultiplier;

		internal static ConfigEntry<float> AuraVisualMultiplier;

		internal static ConfigEntry<float> DomeOpacity;

		internal static ConfigEntry<float> DomeBorderBoost;

		internal static ConfigEntry<float> DomeEdgeSharpness;

		internal static ConfigEntry<bool> ShowDome;

		internal static ConfigEntry<string> DomeColor;

		internal static string PrefabName;

		private static GameObject _holder;

		private static bool _registered;

		internal static ConfigEntry<string> GripCopyFrom;

		internal static ConfigEntry<float> HandPosX;

		internal static ConfigEntry<float> HandPosY;

		internal static ConfigEntry<float> HandPosZ;

		internal static ConfigEntry<float> HandRotX;

		internal static ConfigEntry<float> HandRotY;

		internal static ConfigEntry<float> HandRotZ;

		private static float _auraRadius = 8f;

		internal static void BindConfig(ConfigFile cfg)
		{
			Enable = cfg.Bind<bool>("Staff", "Enable", true, "Add the wizard staff item (needs PEAKLib Items).");
			GiveAtRunStart = cfg.Bind<bool>("Staff", "GiveAtRunStart", true, "Spawn the staff in your hand when a run starts on the beach.");
			DumpHierarchy = cfg.Bind<bool>("Staff", "DumpHierarchy", true, "Log the base item's hierarchy once (for tuning).");
			DisplayName = cfg.Bind<string>("Staff", "DisplayNameV3", "", "Overrides the item name shown in game; empty uses the built-in name for the chosen Language.");
			BaseItemName = cfg.Bind<string>("Staff", "BaseItemPrefab", "Lantern_Faerie", "Vanilla item prefab to clone the behaviour from (Lantern_Faerie heals every status and dispels fog; Lantern = fog safe zone only).");
			Length = cfg.Bind<float>("Staff", "Length", 1.4f, "Staff length in meters.");
			Radius = cfg.Bind<float>("Staff", "Radius", 0.035f, "Staff radius in meters.");
			Scale = cfg.Bind<float>("Staff", "Scale", 1f, "Uniform scale multiplier applied to the staff mesh.");
			MeshPosX = cfg.Bind<float>("Staff", "MeshPosX", 0f, "Mesh offset inside the item (meters).");
			MeshPosY = cfg.Bind<float>("Staff", "MeshPosY", 0f, "Mesh offset inside the item (meters).");
			MeshPosZ = cfg.Bind<float>("Staff", "MeshPosZ", 0f, "Mesh offset inside the item (meters).");
			MeshRotX = cfg.Bind<float>("Staff", "MeshRotX", 0f, "Mesh rotation inside the item (degrees).");
			MeshRotY = cfg.Bind<float>("Staff", "MeshRotY", 0f, "Mesh rotation inside the item (degrees).");
			GripCopyFrom = cfg.Bind<string>("Staff", "GripCopyFromV2", "Amulet_SuperJump", "Vanilla item whose hand anchor the staff borrows. Empty keeps the cloned item's own.");
			HandPosX = cfg.Bind<float>("Staff", "HandPosXV2", 9999f, "Overrides the grip offset on this axis; 9999 keeps the value copied from GripCopyFromV2.");
			HandPosY = cfg.Bind<float>("Staff", "HandPosY", 0.03f, "Overrides the grip offset on this axis; 9999 keeps the value copied from GripCopyFromV2.");
			HandPosZ = cfg.Bind<float>("Staff", "HandPosZV2", 9999f, "Overrides the grip offset on this axis; 9999 keeps the value copied from GripCopyFromV2.");
			HandRotX = cfg.Bind<float>("Staff", "HandRotX", 9999f, "Overrides the grip rotation; 9999 keeps the copied one.");
			HandRotY = cfg.Bind<float>("Staff", "HandRotY", 0f, "Grip rotation in degrees.");
			HandRotZ = cfg.Bind<float>("Staff", "HandRotZ", 0f, "Grip rotation in degrees.");
			MeshRotZ = cfg.Bind<float>("Staff", "MeshRotZ", 0f, "Mesh rotation inside the item (degrees).");
			LightPosX = cfg.Bind<float>("Staff", "LightPosX", 0f, "Where the light/fire sits, relative to the item root (meters).");
			LightPosY = cfg.Bind<float>("Staff", "LightPosY", 0.75f, "Where the light/fire sits, relative to the item root (meters).");
			LightPosZ = cfg.Bind<float>("Staff", "LightPosZ", 0f, "Where the light/fire sits, relative to the item root (meters).");
			LightColor = cfg.Bind<string>("Staff", "LightColorV2", "6FC4FF", "Hex colour of the crystal, its lamp and its glow (RRGGBB). Keep it a real colour — anything close to white blooms into a white wash.");
			LightIntensity = cfg.Bind<float>("Staff", "LampIntensity", 0.55f, "Multiplier on the lamp's brightness, as a share of the lantern's own.");
			GlowStrength = cfg.Bind<float>("Staff", "CrystalGlowStrength", 0.45f, "Multiplier on the glow sprite around the crystal. This is the billboard that was washing the screen white; 1 is the lantern's own.");
			GlowSize = cfg.Bind<float>("Staff", "CrystalGlowSize", 0.3f, "How big that glow sprite is, as a share of the lantern's. The lantern's is sized for a lamp you hold low, not for a crystal at eye level.");
			InfiniteFuel = cfg.Bind<bool>("Staff", "InfiniteLight", false, "If true the light never runs out. If false it burns the base item's fuel (30 s for the Faerie lantern) and recharges while unlit.");
			FuelRecharge = cfg.Bind<float>("Staff", "FuelRechargeSecondsV2", 0f, "Seconds to recharge from empty to full while the light is off (0 = only at campfires).");
			VigorAmount = cfg.Bind<float>("Staff", "VigorAmountV2", 1f, "Extra stamina given by the secondary use (1 = a full extra bar, the game's cap).");
			VigorCooldown = cfg.Bind<float>("Staff", "VigorCooldownSeconds", 60f, "(unused since 0.7.0: vigor now has charges per biome)");
			VigorFlashSeconds = cfg.Bind<float>("Staff", "VigorFlashSeconds", 2.2f, "How long the flash of light lasts when the breath of vigor is used.");
			VigorFlashStrength = cfg.Bind<float>("Staff", "VigorFlashStrengthV2", 1f, "How bright the crystal goes during that flash. Only the crystal — the staff lamp is left alone.");
			AuraRadiusMultiplier = cfg.Bind<float>("Staff", "AuraRadiusMultiplier", 1.8f, "How much wider the lit staff reaches than the lantern it is built on — the healing field, the fog and the gloom protection all scale together. 1 = the lantern's own reach.");
			AuraVisualMultiplier = cfg.Bind<float>("Staff", "AuraGlareMultiplier", 1f, "How far the lit staff clears and brightens the fog around you — the white bubble, not the healing. 1 is exactly what the Faerie Lantern does; below 1 makes the glare smaller than the game ships it.");
			ShowDome = cfg.Bind<bool>("Staff", "ShowAuraDome", true, "While the staff is lit, raise the same misty dome the endless-stamina amulet uses, sized to the aura, so everyone can see who it covers.");
			DomeOpacity = cfg.Bind<float>("Staff", "AuraDomeOpacityV3", 0.35f, "How thick the dome's mist is, as a share of the game's own. This scales the shader's master opacity (_Alpha, 0.1 by default), which is the only thing that really controls it.");
			DomeBorderBoost = cfg.Bind<float>("Staff", "AuraDomeBorderBrightness", 0.25f, "Multiplier on the edge glow's brightness. The game ships it at 5.3, well past the point where bloom turns it white; below about 0.2 it stops blooming. 1 leaves it as the game set it.");
			DomeEdgeSharpness = cfg.Bind<float>("Staff", "AuraDomeEdgeSharpness", 8f, "Multiplier on the glow's falloff (_Power, 0.25 by default). Higher pulls the glow into a thin rim at the silhouette and leaves the middle of the dome clear; 1 keeps the game's broad spread.");
			DomeColor = cfg.Bind<string>("Staff", "AuraDomeTint", "", "Optional tint multiplied over the dome (RRGGBB). Empty — the default — leaves the game's own mist untouched, which is the only way its edge glow survives.");
		}

		internal static void TryRegister(ItemDatabase db)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			if (_registered || !Enable.Value)
			{
				return;
			}
			_registered = true;
			try
			{
				Item val = FindBaseItem(db);
				if ((Object)(object)val == (Object)null)
				{
					WizardFitPlugin.Log.LogWarning((object)("Staff: base item '" + BaseItemName.Value + "' not found in ItemDatabase; staff disabled."));
					return;
				}
				WizardFitPlugin.Log.LogInfo((object)$"Staff: cloning '{((Object)((Component)val).gameObject).name}' (id {val.itemID}, ui '{val.UIData?.itemName}').");
				_holder = new GameObject("WizardFit_ItemTemplates");
				_holder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_holder);
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, _holder.transform);
				((Object)val2).name = "WizardStaff";
				Item component = val2.GetComponent<Item>();
				if (DumpHierarchy.Value)
				{
					WizardFitPlugin.Log.LogInfo((object)("Staff: base hierarchy\n" + Describe(val2.transform)));
				}
				LogReferenceGrips(db);
				ApplyVisuals(component);
				CopyGripRotation(db, component, "Staff");
				PlaceGripFor(component, "Staff", HandPosX, HandPosY, HandPosZ, HandRotX, HandRotY, HandRotZ);
				AddBehaviours(component);
				component.UIData.itemName = WizardFitPlugin.T("Wizard's Staff", "Cajado do Mago", DisplayName.Value);
				component.UIData.hideFuel = InfiniteFuel.Value;
				component.UIData.hasSecondInteract = true;
				component.canUseOnFriend = true;
				component.mustUseOnFriend = false;
				component.UIData.hideSecondInteract = false;
				component.UIData.secondaryInteractPrompt = WizardFitPlugin.T("Breath of vigor", "Sopro de vigor");
				Texture2D val3 = WizardFitPlugin.TryLoadTexture("icon_staff.png");
				if ((Object)(object)val3 != (Object)null)
				{
					component.UIData.icon = val3;
					component.UIData.hasAltIcon = false;
					component.UIData.hasColorBlindIcon = false;
				}
				ModDefinition orCreate = ModDefinition.GetOrCreate(((BaseUnityPlugin)WizardFitPlugin.Instance).Info.Metadata);
				if (WizardFitPlugin.DebugGrip.Value)
				{
					((Component)component).gameObject.AddComponent<GripDebug>().label = "Staff";
				}
				WizardFitPlugin.PrepareClassItem(component);
				IconRenderer.Queue(component, WizardFitPlugin.IconEuler("Staff", 0f, 0f, -52f));
				new ItemContent(component).Register(orCreate);
				PrefabName = ((Object)val2).name;
				WizardFitPlugin.Log.LogInfo((object)$"Staff: registered as '{PrefabName}' (id {component.itemID}).");
			}
			catch (Exception arg)
			{
				WizardFitPlugin.Log.LogError((object)$"Staff: registration failed, staff disabled: {arg}");
				PrefabName = null;
			}
		}

		private static Item FindBaseItem(ItemDatabase db)
		{
			List<Item> source = db.itemLookup.Values.Where((Item i) => (Object)(object)i != (Object)null).ToList();
			WizardFitPlugin.Log.LogInfo((object)("Staff: vanilla items = " + string.Join(", ", from i in source
				select ((Object)((Component)i).gameObject).name into n
				orderby n
				select n)));
			string want = BaseItemName.Value;
			return ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => ((Object)((Component)i).gameObject).name == want)) ?? ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)((Component)i).GetComponentInChildren<Lantern>(true) != (Object)null && ((Object)((Component)i).gameObject).name.IndexOf(want, StringComparison.OrdinalIgnoreCase) >= 0));
		}

		private static void LogReferenceGrips(ItemDatabase db)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string[] array = new string[6] { "Torch", "Parasol", "Bugle", "Flag_Plantable_Checkpoint", "Lantern", "RitualDagger" };
				foreach (string name in array)
				{
					Item val = ((IEnumerable<Item>)db.itemLookup.Values).FirstOrDefault((Func<Item, bool>)((Item val4) => (Object)(object)val4 != (Object)null && ((Object)((Component)val4).gameObject).name == name));
					Transform val2 = (((Object)(object)val != (Object)null) ? val.transform.Find("Hand_R") : null);
					if ((Object)(object)val2 != (Object)null)
					{
						ManualLogSource log = WizardFitPlugin.Log;
						string[] obj = new string[6] { "Grip reference ", name, ": pos=", null, null, null };
						Vector3 val3 = val2.localPosition;
						obj[3] = ((Vector3)(ref val3)).ToString("F3");
						obj[4] = " rot=";
						val3 = val2.localEulerAngles;
						obj[5] = ((Vector3)(ref val3)).ToString("F1");
						log.LogInfo((object)string.Concat(obj));
					}
				}
			}
			catch (Exception ex)
			{
				WizardFitPlugin.Log.LogWarning((object)("Grip reference: " + ex.Message));
			}
		}

		internal static void CopyGripRotation(ItemDatabase db, Item item, string label)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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)
			try
			{
				string from = GripCopyFrom.Value;
				if (!string.IsNullOrWhiteSpace(from))
				{
					Item val = ((IEnumerable<Item>)db.itemLookup.Values).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && ((Object)((Component)i).gameObject).name == from));
					Transform val2 = (((Object)(object)val != (Object)null) ? val.transform.Find("Hand_R") : null);
					Transform val3 = item.transform.Find("Hand_R");
					if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
					{
						WizardFitPlugin.Log.LogWarning((object)(label + ": grip source '" + from + "' not found, keeping the clone's own grip."));
						return;
					}
					val3.localPosition = val2.localPosition;
					val3.localRotation = val2.localRotation;
					ManualLogSource log = WizardFitPlugin.Log;
					string[] obj = new string[8] { label, ": grip copied from '", from, "' (pos=", null, null, null, null };
					Vector3 val4 = val2.localPosition;
					obj[4] = ((Vector3)(ref val4)).ToString("F3");
					obj[5] = " rot=";
					val4 = val2.localEulerAngles;
					obj[6] = ((Vector3)(ref val4)).ToString("F1");
					obj[7] = ")";
					log.LogInfo((object)string.Concat(obj));
				}
			}
			catch (Exception ex)
			{
				WizardFitPlugin.Log.LogWarning((object)(label + ": grip not copied (" + ex.Message + ")."));
			}
		}

		internal static void PlaceGripFor(Item item, string label, ConfigEntry<float> px, ConfigEntry<float> py, ConfigEntry<float> pz, ConfigEntry<float> rx, ConfigEntry<float> ry, ConfigEntry<float> rz)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Transform val = item.transform.Find("Hand_R");
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 localPosition = val.localPosition;
					Vector3 localEulerAngles = val.localEulerAngles;
					if (px.Value < 900f)
					{
						localPosition.x = px.Value;
					}
					if (py.Value < 900f)
					{
						localPosition.y = py.Value;
					}
					if (pz.Value < 900f)
					{
						localPosition.z = pz.Value;
					}
					if (rx.Value < 900f)
					{
						((Vector3)(ref localEulerAngles))..ctor(rx.Value, ry.Value, rz.Value);
					}
					val.localPosition = localPosition;
					val.localRotation = Quaternion.Euler(localEulerAngles);
					ManualLogSource log = WizardFitPlugin.Log;
					string[] obj = new string[5] { label, ": grip final pos=", null, null, null };
					Vector3 val2 = val.localPosition;
					obj[2] = ((Vector3)(ref val2)).ToString("F3");
					obj[3] = " rot=";
					val2 = val.localEulerAngles;
					obj[4] = ((Vector3)(ref val2)).ToString("F1");
					log.LogInfo((object)string.Concat(obj));
				}
			}
			catch (Exception ex)
			{
				WizardFitPlugin.Log.LogWarning((object)(label + ": grip not adjusted (" + ex.Message + ")."));
			}
		}

		private static void ApplyVisuals(Item item)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_0200: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0574: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_067b: Unknown result type (might be due to invalid IL or missing references)
			Mesh sharedMesh = BuildStaffMesh();
			Texture2D val = WizardFitPlugin.TryLoadTexture("wizard_staff.png");
			Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if (!(val2 is ParticleSystemRenderer) && !((Object)val2).name.Contains("Hand"))
				{
					val2.enabled = false;
				}
			}
			Color val3 = ParseTint();
			Shader val4 = Shader.Find("W/Character");
			Material val5 = new Material(((Object)(object)val4 != (Object)null) ? val4 : Shader.Find("Standard"));
			if ((Object)(object)val != (Object)null && val5.HasProperty("_MainTex"))
			{
				val5.SetTexture("_MainTex", (Texture)(object)val);
			}
			if (val5.HasProperty("_UseSkinTone"))
			{
				val5.SetFloat("_UseSkinTone", 0f);
			}
			Shader val6 = Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Unlit/Color");
			Material val7;
			if ((Object)(object)val6 != (Object)null)
			{
				val7 = new Material(val6);
				if (val7.HasProperty("_BaseColor"))
				{
					val7.SetColor("_BaseColor", val3);
				}
				if (val7.HasProperty("_Color"))
				{
					val7.SetColor("_Color", val3);
				}
			}
			else
			{
				val7 = new Material(val5);
				if (val7.HasProperty("_MainTex"))
				{
					val7.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
				}
				if (val7.HasProperty("_Color"))
				{
					val7.SetColor("_Color", val3);
				}
			}
			WizardFitPlugin.Log.LogInfo((object)("Staff: wood shader '" + ((Object)val5.shader).name + "', crystal shader '" + ((Object)val7.shader).name + "'"));
			GameObject val8 = new GameObject("StaffMesh");
			val8.transform.SetParent(item.transform, false);
			val8.transform.localPosition = new Vector3(MeshPosX.Value, MeshPosY.Value, MeshPosZ.Value);
			val8.transform.localRotation = Quaternion.Euler(MeshRotX.Value, MeshRotY.Value, MeshRotZ.Value);
			val8.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
			MeshRenderer val9 = val8.AddComponent<MeshRenderer>();
			((Renderer)val9).sharedMaterials = (Material[])(object)new Material[2] { val5, val7 };
			item.mainRenderer = (Renderer)(object)val9;
			item.rightHandOnly = true;
			HandVisual[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<HandVisual>(true);
			foreach (HandVisual val10 in componentsInChildren2)
			{
				if (((Object)val10).name.Contains("_L"))
				{
					((Component)val10).gameObject.SetActive(false);
				}
			}
			Collider[] componentsInChildren3 = ((Component)item).GetComponentsInChildren<Collider>(true);
			foreach (Collider val11 in componentsInChildren3)
			{
				MeshCollider val12 = (MeshCollider)(object)((val11 is MeshCollider) ? val11 : null);
				if (val12 == null)
				{
					CapsuleCollider val13 = (CapsuleCollider)(object)((val11 is CapsuleCollider) ? val11 : null);
					if (val13 == null)
					{
						BoxCollider val14 = (BoxCollider)(object)((val11 is BoxCollider) ? val11 : null);
						if (val14 != null)
						{
							val14.center = Vector3.zero;
							val14.size = new Vector3(Radius.Value * 3f, Length.Value, Radius.Value * 3f);
						}
					}
					else
					{
						val13.center = Vector3.zero;
						val13.direction = 1;
						val13.radius = Radius.Value * 1.5f;
						val13.height = Length.Value;
					}
				}
				else
				{
					((Component)val12).transform.SetParent(item.transform, false);
					((Component)val12).transform.localPosition = val8.transform.localPosition;
					((Component)val12).transform.localRotation = val8.transform.localRotation;
					((Component)val12).transform.localScale = Vector3.one;
					val12.sharedMesh = sharedMesh;
					val12.convex = true;
				}
			}
			Color val15 = ParseTint();
			Vector3 localInRoot = default(Vector3);
			((Vector3)(ref localInRoot))..ctor(LightPosX.Value, LightPosY.Value, LightPosZ.Value);
			float num = Mathf.Max(0f, LightIntensity.Value);
			float num2 = Mathf.Max(0f, GlowStrength.Value);
			float num3 = Mathf.Max(0.01f, GlowSize.Value);
			Light[] componentsInChildren4 = ((Component)item).GetComponentsInChildren<Light>(true);
			foreach (Light val16 in componentsInChildren4)
			{
				SetLocal(((Component)val16).transform, item.transform, localInRoot);
				val16.color = val15;
				float intensity = val16.intensity;
				val16.intensity = intensity * num;
				WizardFitPlugin.Log.LogInfo((object)$"Staff: lamp intensity {intensity:F2}->{val16.intensity:F2}, range {val16.range:F1}m.");
			}
			ParticleSystem[] componentsInChildren5 = ((Component)item).GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val17 in componentsInChildren5)
			{
				string text = ((Object)val17).name.ToLowerInvariant();
				if (text.Contains("smoke") || text.Contains("fire") || text.Contains("flame"))
				{
					((Component)val17).gameObject.SetActive(false);
					continue;
				}
				SetLocal(((Component)val17).transform, item.transform, localInRoot);
				MainModule main = val17.main;
				((MainModule)(ref main)).startColor = new MinMaxGradient(val15 * num2);
				float startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier;
				((MainModule)(ref main)).startSizeMultiplier = startSizeMultiplier * num3;
				WizardFitPlugin.Log.LogInfo((object)$"Staff: glow '{((Object)val17).name}' size {startSizeMultiplier:F2}->{((MainModule)(ref main)).startSizeMultiplier:F2}, strength x{num2:F2}.");
				ColorOverLifetimeModule colorOverLifetime = val17.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = false;
				ColorBySpeedModule colorBySpeed = val17.colorBySpeed;
				((ColorBySpeedModule)(ref colorBySpeed)).enabled = false;
				ParticleSystemRenderer component = ((Component)val17).GetComponent<ParticleSystemRenderer>();
				if (!((Object)(object)component != (Object)null) || !((Object)(object)((Renderer)component).sharedMaterial != (Object)null))
				{
					continue;
				}
				Material val18 = Object.Instantiate<Material>(((Renderer)component).sharedMaterial);
				string[] array = new string[4] { "_Color", "_TintColor", "_BaseColor", "_EmissionColor" };
				foreach (string text2 in array)
				{
					if (val18.HasProperty(text2))
					{
						val18.SetColor(text2, val15 * num2);
					}
				}
				((Renderer)component).sharedMaterial = val18;
			}
		}

		private static void AddBehaviours(Item item)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			StaffGlow staffGlow = ((Component)item).gameObject.AddComponent<StaffGlow>();
			staffGlow.crystalRenderer = item.mainRenderer;
			WizardFitPlugin.Log.LogInfo((object)("Staff: glow bound to renderer '" + (((Object)(object)item.mainRenderer != (Object)null) ? ((Object)item.mainRenderer).name : "null") + "'"));
			staffGlow.litColor = ParseTint();
			((Component)item).gameObject.AddComponent<ClassRpc>();
			((Component)item).gameObject.AddComponent<ChargeStore>().secondaryMax = Charges.StaffVigor.Value;
			Action_StaffVigor action_StaffVigor = ((Component)item).gameObject.AddComponent<Action_StaffVigor>();
			action_StaffVigor.amount = VigorAmount.Value;
			action_StaffVigor.maxUses = Charges.StaffVigor.Value;
			Lantern componentInChildren = ((Component)item).GetComponentInChildren<Lantern>(true);
			FieldInfo fieldInfo = AccessTools.Field(typeof(Lantern), "startingFuel");
			if ((Object)(object)componentInChildren != (Object)null && fieldInfo != null)
			{
				float num = (float)fieldInfo.GetValue(componentInChildren);
				fieldInfo.SetValue(componentInChildren, num * (float)Mathf.Max(1, Charges.StaffAura.Value));
				AccessTools.Field(typeof(Lantern), "fuel")?.SetValue(componentInChildren, num * (float)Mathf.Max(1, Charges.StaffAura.Value));
				WizardFitPlugin.Log.LogInfo((object)$"Staff: aura tank = {Charges.StaffAura.Value} x {num:F0}s");
			}
			WidenAura(item);
			((Component)item).gameObject.AddComponent<AuraDome>().radius = _auraRadius;
		}

		private static void WidenAura(Item item)
		{
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0.1f, AuraRadiusMultiplier.Value);
			float num2 = Mathf.Max(0.05f, AuraVisualMultiplier.Value);
			List<string> list = new List<string>();
			GloomSafeZone[] componentsInChildren = ((Component)item).GetComponentsInChildren<GloomSafeZone>(true);
			foreach (GloomSafeZone obj in componentsInChildren)
			{
				(string, float)[] array = new(string, float)[2]
				{
					("statusProtectionRadius", num),
					("visualRadius", num2)
				};
				for (int j = 0; j < array.Length; j++)
				{
					(string, float) tuple = array[j];
					FieldInfo fieldInfo = AccessTools.Field(typeof(GloomSafeZone), tuple.Item1);
					if (!(fieldInfo == null) && !(fieldInfo.FieldType != typeof(float)))
					{
						float num3 = (float)fieldInfo.GetValue(obj);
						fieldInfo.SetValue(obj, num3 * tuple.Item2);
						list.Add($"{tuple.Item1} {num3:F1}->{num3 * tuple.Item2:F1}m");
					}
				}
			}
			StatusField[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<StatusField>(true);
			foreach (StatusField val in componentsInChildren2)
			{
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(StatusField), "radius");
				if (fieldInfo2 == null)
				{
					continue;
				}
				float num4 = (float)fieldInfo2.GetValue(val);
				fieldInfo2.SetValue(val, num4 * num);
				float num5 = 1f;
				try
				{
					FieldInfo fieldInfo3 = AccessTools.Field(typeof(StatusField), "respectScale");
					if (fieldInfo3 != null && (bool)fieldInfo3.GetValue(val))
					{
						num5 = ((Component)val).transform.lossyScale.x;
					}
				}
				catch
				{
				}
				_auraRadius = num4 * num * num5;
				list.Add($"{DescribeField(val)} {num4 * num5:F1}->{num4 * num * num5:F1}m");
			}
			DispelFogField[] componentsInChildren3 = ((Component)item).GetComponentsInChildren<DispelFogField>(true);
			foreach (DispelFogField obj3 in componentsInChildren3)
			{
				string[] array2 = new string[2] { "innerRadius", "outerRadius" };
				foreach (string text in array2)
				{
					FieldInfo fieldInfo4 = AccessTools.Field(typeof(DispelF