Decompiled source of Yuletide v0.8.4

Yuletide.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering;
using Yuletide.Creatures;
using Yuletide.Events;
using Yuletide.Items;
using Yuletide.Items.Armor;
using Yuletide.Items.Food;
using Yuletide.Items.Weapons;
using Yuletide.Pieces;
using Yuletide.Util;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[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 Yuletide
{
	internal static class NewTranslations
	{
		public static void Register()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "enemy_yule_grinch", "Mountain Grump" },
				{ "item_yule_trophy_grinch", "Mountain Grump trophy" },
				{ "item_yule_trophy_grinch_desc", "A sour green face with a sneer that even death couldn't wipe off. Santa pays well for it." },
				{ "msg_yule_grinch_cheer", "The Mountain Grump stole your holiday cheer!" },
				{ "msg_yule_grinch_stole", "The Mountain Grump snatched your" },
				{ "piece_yule_grinchhoard", "Mountain Grump's hoard" },
				{ "enemy_yule_embergingerbreadman", "Ember Gingerbread Man" },
				{ "enemy_yule_embergingerbreadbrute", "Ember Gingerbread Brute" },
				{ "event_yuleemberuprising_start", "The air smells of burnt sugar... the Ember Gingerbread are rising!" },
				{ "event_yuleemberuprising_end", "The ember uprising has burnt itself out." },
				{ "enemy_yule_krampus", "Krampus" },
				{ "enemy_yule_krampusdemon", "Krampus demon" },
				{ "enemy_yule_giftgoblin", "Gift-goblin" },
				{ "enemy_yule_jackfrost", "Jack Frost" },
				{ "enemy_yule_mouseking", "Mouse King" },
				{ "enemy_yule_nutcracker", "Nutcracker soldier" },
				{ "enemy_yule_mousesoldier", "Mouse soldier" },
				{ "item_yule_trophy_krampus", "Krampus horns" },
				{ "item_yule_trophy_krampus_desc", "Long black horns, still warm. Santa will pay handsomely for proof." },
				{ "item_yule_trophy_jackfrost", "Jack Frost's crown" },
				{ "item_yule_trophy_jackfrost_desc", "A spiky crown of ice that never melts. It hums faintly in a blizzard." },
				{ "item_yule_trophy_mouseking", "Mouse King trophy" },
				{ "item_yule_trophy_mouseking_desc", "The Mouse King's whiskered head, still wearing its jewelled crown and ermine collar." },
				{ "msg_yule_giftgoblin_stole", "A Gift-goblin grabbed your" },
				{ "piece_yule_krampusaltar", "Krampus altar" },
				{ "piece_yule_krampusaltar_desc", "Black stone bound in chain, with bowls of Krampus coal. Offer a naughty list to call Krampus. Bring friends." },
				{ "piece_yule_krampusaltar_use", "Offer the naughty list" },
				{ "msg_yule_krampus_summoned", "Chains rattle in the dark... Krampus is coming!" },
				{ "event_yulekrampusnight_start", "The fog thickens and chains rattle... it's Krampus Night!" },
				{ "event_yulekrampusnight_end", "The demons slink back into the dark." },
				{ "event_yulemouseking_start", "Squeaking from every corner... the Mouse King's army is coming! The nutcracker soldiers march to defend you." },
				{ "event_yulemouseking_end", "The Mouse King's army has scattered." },
				{ "item_yule_reindeerharness", "Reindeer harness" },
				{ "item_yule_reindeerharness_desc", "A red woven halter with a brass bell. Use it next to a wild reindeer to tame it on the spot." },
				{ "item_yule_sleighbell", "Sleigh bell" },
				{ "item_yule_sleighbell_desc", "Ring it and every tamed reindeer within earshot comes trotting to follow you." },
				{ "item_yule_naughtylist", "Naughty list" },
				{ "item_yule_naughtylist_desc", "A long scroll of names, many struck through in red. Offered at the Krampus altar, it calls him. Creatures of the Deep North, and now and then of the Ashlands, carry one." },
				{ "item_yuleshears", "Wool shears" },
				{ "item_yuleshears_desc", "Spring-bowed iron shears. Use them on a Golden Goat to shear its wool without harming it, once a day." },
				{ "msg_yule_harness_none", "There's no wild reindeer close enough." },
				{ "msg_yule_harness_tamed", "The reindeer accepts the harness." },
				{ "piece_yule_sledwood", "Mountain sled" },
				{ "piece_yule_sledwood_desc", "Frost-bitten timber, warm furs and a snarling carved prow. One seat and a sturdy chest. Pull it yourself, or hitch a tamed reindeer at its front and ride. Glides over snow." },
				{ "piece_yule_sledreinforced", "Mistlands sleigh" },
				{ "piece_yule_sledreinforced_desc", "Dark wood curled like a swan's neck and inlaid with glowing crystal. Seats two on green cushions, with a rune chest behind. Carries more, and its load drags less." },
				{ "piece_yule_sledroyal", "Santa's sleigh" },
				{ "piece_yule_sledroyal_desc", "Red lacquer, gilded runners, candy canes and garlands. Seats three, takes two reindeer, and its gift chest is the roomiest of all. The lightest to pull." },
				{ "msg_yule_sled_hitched", "Your reindeer takes the shafts." },
				{ "msg_yule_sled_ride", "W/S to go and stop, A/D to steer, Jump to get off" },
				{ "piece_yule_sled_storage", "Sled storage" },
				{ "piece_yule_sled_ride", "Ride" },
				{ "piece_yule_sled_sit", "Sit" },
				{ "piece_yule_sled_hitch", "Hitch reindeer" },
				{ "piece_yule_sled_unhitch", "Unhitch reindeer" },
				{ "piece_yule_sled_right", "Right sled" },
				{ "piece_yule_sled_tipped", "tipped over" },
				{ "msg_yule_sled_noreindeer", "No tamed reindeer nearby." },
				{ "msg_yule_sled_full", "Every harness on this sled is taken." },
				{ "msg_yule_sled_unhitched", "The reindeer step out of the harness." },
				{ "msg_yule_sled_usehitch", "Unhitch the reindeer at the front of the sled first." },
				{ "msg_yule_sled_tipped", "The sled tips and you jump clear!" },
				{ "msg_yule_sled_slipped", "The sled snagged and the reindeer slipped the harness." },
				{ "msg_yule_sled_handpulled", "Let go of the sled before you hitch a reindeer." },
				{ "msg_yule_sled_stuck", "The sled is caught, the reindeer waits for it." },
				{ "msg_yule_bell_called", "Reindeer coming:" },
				{ "msg_yule_bell_none", "No tamed reindeer heard the bell." },
				{ "msg_yule_goat_sheared", "You shear the goat: +2 golden wool." },
				{ "msg_yule_goat_shorn", "This goat was shorn today already." },
				{ "item_yule_goldenticket", "Golden ticket" },
				{ "item_yule_goldenticket_desc", "A shining ticket found folded inside a present. Use it for three presents' worth of your best finds and a purse of coins, or sell it to Santa." },
				{ "msg_yule_goldenticket_found", "There's a golden ticket inside!" },
				{ "msg_yule_goldenticket_redeemed", "Golden ticket:" },
				{ "piece_yule_wreath", "Holly wreath" },
				{ "piece_yule_wreath_desc", "A ring of fresh fir with pinecones, holly, little bells and a velvet bow. Hang it on a wall." },
				{ "piece_yule_stocking", "Christmas stocking (valknut)" },
				{ "piece_yule_stocking_desc", "A red wool stocking stitched with a valknut. It holds two things. Hang it up and Santa leaves a treat in it each morning." },
				{ "piece_yule_stocking_stag", "Christmas stocking (stag)" },
				{ "piece_yule_stocking_stag_desc", "A sea-green wool stocking with a stag in a knotwork ring. It holds two things. Hang it up and Santa leaves a treat in it each morning." },
				{ "piece_yule_stocking_snowflake", "Christmas stocking (snowflake)" },
				{ "piece_yule_stocking_snowflake_desc", "A green wool stocking with a white snowflake and a fur cuff. It holds two things. Hang it up and Santa leaves a treat in it each morning." },
				{ "piece_yule_stocking_tree", "Christmas stocking (world tree)" },
				{ "piece_yule_stocking_tree_desc", "A green wool stocking stitched with Yggdrasil. It holds two things. Hang it up and Santa leaves a treat in it each morning." },
				{ "piece_yule_nutcracker", "Nutcracker guard" },
				{ "piece_yule_nutcracker_desc", "A painted wooden nutcracker in a red coat and tall black hat, his sword drawn. He guards the door all winter." },
				{ "piece_yule_nutcracker_viking", "Viking nutcracker" },
				{ "piece_yule_nutcracker_viking_desc", "A carved nutcracker jarl in an antlered helm, spear and banner in hand, on a rune-cut plinth with two lanterns burning at his feet." },
				{ "piece_yule_mistletoe", "Mistletoe" },
				{ "piece_yule_mistletoe_desc", "A sprig of white-berried mistletoe on a short string. Hang it from a beam or ceiling; it sways in the wind and when anyone brushes past." },
				{ "piece_yule_snowman", "Snowman" },
				{ "piece_yule_snowman_desc", "Three balls of packed snow in a horned helm, with a fur scarf, twig arms, a round shield and a hammer charm on his rope belt. He never melts indoors." },
				{ "piece_yule_advent", "Advent calendar" },
				{ "piece_yule_advent_desc", "Twenty-four little doors. Open one each day for a treat; the last one is the best." },
				{ "msg_yule_advent_open", "Open door" },
				{ "msg_yule_advent_tomorrow", "Today's door is open. Come back tomorrow." },
				{ "piece_yule_tree", "Christmas tree" },
				{ "piece_yule_tree_desc", "A tall fir in a ring of stones, hung with crystal lights that twinkle through the night, under a carved horned topper. Comfort +2." },
				{ "piece_yule_garland", "Fir garland" },
				{ "piece_yule_garland_desc", "Four metres of fir in two swags, with bows, baubles, bells and candy canes." },
				{ "piece_yule_giftchest", "Gift-box chest" },
				{ "piece_yule_giftchest_desc", "A wrapped present the size of a chest. Lift the lid: it holds 12 stacks." },
				{ "piece_yule_giftchestlarge", "Large gift-box chest" },
				{ "piece_yule_giftchestlarge_desc", "An enormous wrapped present with a gold bow. It holds 24 stacks." },
				{ "piece_yule_yuleloghearth", "Great log hearth" },
				{ "piece_yule_yuleloghearth_desc", "A fieldstone hearth round a great birch log carved with runes. Burns wood, and you can cook over it. Comfort +2." },
				{ "piece_yule_lanternpost", "Holly lamp post" },
				{ "piece_yule_lanternpost_desc", "A timber lamp post on a stone footing, its holly-wreathed lantern hung on a chain from the arm. It never needs fuel." },
				{ "piece_yule_lanternhang", "Hanging holly lantern" },
				{ "piece_yule_lanternhang_desc", "A holly-wreathed lantern on a short iron chain. Hang it from a beam or ceiling; it never needs fuel and sways in the wind." },
				{ "piece_yule_paintcantrap", "Paint can trap" },
				{ "piece_yule_paintcantrap_desc", "A heavy can of paint hung from a gallows. When something nasty walks underneath, it swings down: BONK. The paint slows them like tar." },
				{ "piece_yule_auroralights", "Aurora lights" },
				{ "piece_yule_auroralights_desc", "A string of frosted glass lights that drift through the colours of the northern lights." }
			});
		}
	}
	internal class SelfTest : MonoBehaviour
	{
		private string _character = "";

		private string _world = "";

		private string _mode = "";

		private string[] _lines = new string[0];

		private static string Dir => Path.Combine(Paths.BepInExRootPath, "yuletide_selftest");

		private static string Marker => Path.Combine(Paths.ConfigPath, "yuletide_selftest.txt");

		public static void Install(GameObject host)
		{
			if (File.Exists(Marker))
			{
				host.AddComponent<SelfTest>();
			}
		}

		private static void Log(string what, bool ok, string detail)
		{
			Logger.LogInfo((object)("YULE TEST " + (ok ? "PASS" : "FAIL") + " " + what + ": " + detail));
		}

		private void Start()
		{
			string[] array = (_lines = File.ReadAllLines(Marker));
			if (array.Length != 0)
			{
				_character = array[0].Trim();
			}
			if (array.Length > 1)
			{
				_world = array[1].Trim();
			}
			if (array.Length > 2)
			{
				_mode = array[2].Trim().ToLowerInvariant();
			}
			if (_mode.StartsWith("armor "))
			{
				SelfTestArmor.Only = _mode.Substring(6).Split(new char[2] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
				_mode = "armor";
			}
			Directory.CreateDirectory(Dir);
			((MonoBehaviour)this).StartCoroutine(Run());
		}

		private IEnumerator Run()
		{
			Traverse fejd = Traverse.Create(typeof(FejdStartup)).Field("m_instance");
			float t0 = Time.realtimeSinceStartup;
			while ((Object)(object)fejd.GetValue<FejdStartup>() == (Object)null || Traverse.Create((object)fejd.GetValue<FejdStartup>()).Field("m_profiles").GetValue<List<PlayerProfile>>() == null)
			{
				if (Time.realtimeSinceStartup - t0 > 180f)
				{
					Logger.LogError((object)"YULE TEST: main menu never came up");
					Application.Quit();
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(1f);
			}
			yield return (object)new WaitForSecondsRealtime(4f);
			FejdStartup value = fejd.GetValue<FejdStartup>();
			Traverse tf = Traverse.Create((object)value);
			List<PlayerProfile> value2 = tf.Field("m_profiles").GetValue<List<PlayerProfile>>();
			int num = Math.Max(0, value2.FindIndex((PlayerProfile val2) => val2.GetName().IndexOf(_character, StringComparison.OrdinalIgnoreCase) >= 0 && _character.Length > 0));
			tf.Field("m_profileIndex").SetValue((object)num);
			Logger.LogInfo((object)("YULE TEST: character '" + value2[num].GetName() + "'"));
			tf.Method("OnCharacterStart", Array.Empty<object>()).GetValue();
			yield return (object)new WaitForSecondsRealtime(2f);
			List<World> worldList = SaveSystem.GetWorldList();
			World val = ((IEnumerable<World>)worldList).FirstOrDefault((Func<World, bool>)((World x) => x.m_name.Equals(_world, StringComparison.OrdinalIgnoreCase))) ?? worldList.FirstOrDefault();
			if (val == null)
			{
				Logger.LogError((object)"YULE TEST: no world");
				Application.Quit();
				yield break;
			}
			Logger.LogInfo((object)("YULE TEST: world '" + val.m_name + "'"));
			tf.Field("m_world").SetValue((object)val);
			tf.Method("OnWorldStart", Array.Empty<object>()).GetValue();
			t0 = Time.realtimeSinceStartup;
			while ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsTeleporting() || (Object)(object)ZNetScene.instance == (Object)null)
			{
				if (Time.realtimeSinceStartup - t0 > 240f)
				{
					Logger.LogError((object)"YULE TEST: never got into the world");
					Application.Quit();
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(1f);
			}
			yield return (object)new WaitForSeconds(8f);
			Player p = Player.m_localPlayer;
			p.SetGodMode(true);
			Traverse.Create((object)p).Field("m_noPlacementCost").SetValue((object)true);
			Logger.LogInfo((object)("YULE TEST: in game at " + ((object)((Component)p).transform.position/*cast due to .constrained prefix*/).ToString()));
			((Humanoid)p).UnequipAllItems();
			((Humanoid)p).GetInventory().RemoveAll();
			if (_mode == "armor")
			{
				yield return Guard(SelfTestArmor.Run(p), "armor");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode == "drops")
			{
				yield return Guard(SelfTestDrops.Run(p), "drops");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode == "status")
			{
				yield return Guard(SelfTestStatus.Run(p), "status");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode == "sleds")
			{
				yield return Guard(SelfTestSleds.Run(p), "sleds");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode == "decor")
			{
				yield return Guard(SelfTestDecor.Run(p), "decor");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode.StartsWith("showcase"))
			{
				SelfTestShowcase.Parts = ((_lines.Length > 3) ? _lines[3].Trim().ToLowerInvariant() : "");
				yield return Guard(SelfTestShowcase.Run(p), "showcase");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			if (_mode == "weapons")
			{
				yield return Guard(SelfTestWeapons.Run(p), "weapons");
				Logger.LogInfo((object)"YULE TEST: done");
				yield return (object)new WaitForSeconds(1f);
				Application.Quit();
				yield break;
			}
			yield return Guard(TestFood(p), "food");
			yield return Guard(TestPresents(p), "presents");
			yield return Guard(TestTurkey(p), "turkey");
			yield return Guard(TestSleds(p), "sleds");
			yield return Guard(TestMobs(p), "mobs");
			yield return Guard(TestGoat(p), "goat");
			yield return Guard(SelfTestStatus.Run(p), "status");
			yield return Guard(SelfTestWeapons.Run(p), "weapons");
			Logger.LogInfo((object)"YULE TEST: done");
			yield return (object)new WaitForSeconds(1f);
			Application.Quit();
		}

		private IEnumerator Guard(IEnumerator inner, string what)
		{
			while (true)
			{
				object current;
				try
				{
					if (!inner.MoveNext())
					{
						break;
					}
					current = inner.Current;
				}
				catch (Exception ex)
				{
					Log(what, ok: false, "exception " + ex);
					break;
				}
				yield return current;
			}
		}

		private static ItemData Give(Player p, string prefab, int n = 1)
		{
			GameObject go = ObjectDB.instance.GetItemPrefab(prefab);
			if ((Object)(object)go == (Object)null)
			{
				return null;
			}
			if (!((Humanoid)p).GetInventory().AddItem(go, n))
			{
				return null;
			}
			return ((IEnumerable<ItemData>)((Humanoid)p).GetInventory().GetAllItems()).LastOrDefault((Func<ItemData, bool>)((ItemData i) => (Object)(object)i.m_dropPrefab == (Object)(object)go));
		}

		private IEnumerator TestFood(Player p)
		{
			List<ItemDrop> list = (from g in ObjectDB.instance.m_items
				select g.GetComponent<ItemDrop>() into val
				where (Object)(object)val != (Object)null && ((Object)val).name.StartsWith("Yule") && (int)val.m_itemData.m_shared.m_itemType == 2
				select val).ToList();
			Log("food", list.Count > 0, list.Count + " Yuletide consumables found");
			foreach (ItemDrop d in list)
			{
				Traverse.Create((object)p).Field("m_foods").GetValue<List<Food>>()
					.Clear();
				((Character)p).GetSEMan().RemoveAllStatusEffects(false);
				ItemData item = Give(p, ((Object)d).name);
				if (item == null)
				{
					Log("food " + ((Object)d).name, ok: false, "could not add to inventory");
					continue;
				}
				int before = ((Humanoid)p).GetInventory().CountItems(item.m_shared.m_name, -1, true);
				((Humanoid)p).UseItem(((Humanoid)p).GetInventory(), item, true);
				yield return (object)new WaitForSeconds(0.3f);
				int num = ((Humanoid)p).GetInventory().CountItems(item.m_shared.m_name, -1, true);
				bool flag = p.GetFoods().Any((Food f) => f.m_name == ((Object)d).name || f.m_item?.m_shared.m_name == item.m_shared.m_name);
				bool flag2 = (Object)(object)item.m_shared.m_consumeStatusEffect != (Object)null && ((Character)p).GetSEMan().HaveStatusEffect(item.m_shared.m_consumeStatusEffect.NameHash());
				bool flag3 = item.m_shared.m_food > 0f || item.m_shared.m_foodStamina > 0f || item.m_shared.m_foodEitr > 0f;
				Log("food " + ((Object)d).name, num < before && (!flag3 || flag), $"used {before}->{num}, in food slots {flag}, effect {flag2}, hp {item.m_shared.m_food} st {item.m_shared.m_foodStamina} eitr {item.m_shared.m_foodEitr}");
				((Humanoid)p).GetInventory().RemoveItem(item.m_shared.m_name, 99, -1, true);
			}
		}

		private IEnumerator TestPresents(Player p)
		{
			for (int k = 0; k < 3; k++)
			{
				ItemData present = Give(p, "YulePresent");
				if (present == null)
				{
					Log("present", ok: false, "no YulePresent item");
					break;
				}
				List<string> before = (from i in ((Humanoid)p).GetInventory().GetAllItems()
					select i.m_shared.m_name + "x" + i.m_stack).ToList();
				((Humanoid)p).UseItem(((Humanoid)p).GetInventory(), present, true);
				yield return (object)new WaitForSeconds(0.5f);
				List<string> list = (from i in ((Humanoid)p).GetInventory().GetAllItems()
					select i.m_shared.m_name + "x" + i.m_stack).ToList().Except(before).ToList();
				bool flag = ((Humanoid)p).GetInventory().CountItems(present.m_shared.m_name, -1, true) == 0;
				Log("present " + (k + 1), flag && list.Count > 0, "gained " + string.Join(", ", list));
				foreach (ItemData item in ((Humanoid)p).GetInventory().GetAllItems().ToList())
				{
					if (!before.Contains(item.m_shared.m_name + "x" + item.m_stack))
					{
						((Humanoid)p).GetInventory().RemoveItem(item);
					}
				}
			}
		}

		private IEnumerator TestTurkey(Player p)
		{
			ItemData club = Give(p, "YuleTurkeyLegClub");
			if (club == null)
			{
				Log("turkey", ok: false, "no club item");
				yield break;
			}
			((Humanoid)p).EquipItem(club, true);
			yield return (object)new WaitForSeconds(0.5f);
			((Character)p).SetHealth(((Character)p).GetMaxHealth() * 0.5f);
			float hp = ((Character)p).GetHealth();
			bool ok = TurkeyLegClub.TryEat(p, club);
			yield return (object)new WaitForSeconds(0.5f);
			bool flag = ((Humanoid)p).GetInventory().CountItems("$item_yule_turkeybone", -1, true) > 0;
			bool flag2 = ((Humanoid)p).GetInventory().CountItems("$item_yule_turkeyleg", -1, true) == 0;
			Log("turkey leg club eaten", ok && flag && flag2 && ((Character)p).GetHealth() > hp, $"ate {ok}, hp {hp:0}->{((Character)p).GetHealth():0}, bone {flag}, club gone {flag2}");
			((Humanoid)p).GetInventory().RemoveItem("$item_yule_turkeybone", 9, -1, true);
		}

		private Vector3 Ahead(Player p, float d)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)p).transform.position + ((Component)p).transform.forward * d;
			float y = default(float);
			if (ZoneSystem.instance.GetGroundHeight(val, ref y))
			{
				val.y = y;
			}
			return val;
		}

		private IEnumerator Shot(string name, GameObject target = null)
		{
			yield return (object)new WaitForEndOfFrame();
			if ((Object)(object)target == (Object)null)
			{
				yield break;
			}
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(target.transform.position, Vector3.one * 0.5f);
			Renderer[] componentsInChildren = target.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				if (val2.enabled && !(val2 is ParticleSystemRenderer))
				{
					((Bounds)(ref val)).Encapsulate(val2.bounds);
				}
			}
			float num = Mathf.Max(new float[3]
			{
				((Bounds)(ref val)).size.x,
				((Bounds)(ref val)).size.y,
				((Bounds)(ref val)).size.z
			});
			GameObject val3 = new GameObject("YuleTestCam");
			Camera val4 = val3.AddComponent<Camera>();
			val4.fieldOfView = 35f;
			val4.nearClipPlane = 0.05f;
			val4.farClipPlane = 500f;
			RenderTexture val5 = (val4.targetTexture = new RenderTexture(960, 720, 24));
			Texture2D val7 = new Texture2D(1920, 720, (TextureFormat)3, false);
			Vector3 forward = target.transform.forward;
			Vector3[] array = new Vector3[2];
			Vector3 val8 = forward + target.transform.right * 0.6f + Vector3.up * 0.35f;
			array[0] = ((Vector3)(ref val8)).normalized;
			val8 = target.transform.right + Vector3.up * 0.15f;
			array[1] = ((Vector3)(ref val8)).normalized;
			Vector3[] array2 = (Vector3[])(object)array;
			for (int j = 0; j < 2; j++)
			{
				((Component)val4).transform.position = ((Bounds)(ref val)).center + array2[j] * (num * 1.9f + 1f);
				((Component)val4).transform.LookAt(((Bounds)(ref val)).center);
				val4.Render();
				RenderTexture.active = val5;
				val7.ReadPixels(new Rect(0f, 0f, 960f, 720f), j * 960, 0);
				RenderTexture.active = null;
			}
			val7.Apply();
			if (Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("EncodeToPNG", new Type[1] { typeof(Texture2D) })?.Invoke(null, new object[1] { val7 }) is byte[] bytes)
			{
				File.WriteAllBytes(Path.Combine(Dir, name + ".png"), bytes);
			}
			val4.targetTexture = null;
			Object.Destroy((Object)(object)val5);
			Object.Destroy((Object)(object)val7);
			Object.Destroy((Object)(object)val3);
			yield return null;
		}

		private IEnumerator TestSleds(Player p)
		{
			string[] array = new string[3] { "YuleSledWood", "YuleSledReinforced", "YuleSledRoyal" };
			float num = default(float);
			foreach (string name in array)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab(name);
				if ((Object)(object)prefab == (Object)null)
				{
					Log("sled " + name, ok: false, "prefab missing");
					continue;
				}
				Vector3 val = Ahead(p, 5f) + Vector3.up * 0.3f;
				GameObject s = Object.Instantiate<GameObject>(prefab, val, Quaternion.LookRotation(((Component)p).transform.forward));
				yield return (object)new WaitForSeconds(4f);
				WearNTear wnt = s.GetComponent<WearNTear>();
				float hp0 = (((Object)(object)wnt != (Object)null) ? wnt.GetHealthPercentage() : 1f);
				ZoneSystem.instance.GetGroundHeight(s.transform.position, ref num);
				float sink = num - s.transform.position.y;
				Vector3 p2 = s.transform.position;
				float tilt = Vector3.Angle(s.transform.up, Vector3.up);
				yield return Shot("sled_" + name, s);
				Rigidbody rb = (from x in s.GetComponentsInChildren<Rigidbody>()
					orderby x.mass descending
					select x).FirstOrDefault();
				Logger.LogInfo((object)("YULE TEST: " + name + " body " + (Object.op_Implicit((Object)(object)rb) ? (((Object)rb).name + " mass " + rb.mass + " kinematic " + rb.isKinematic + " sleeping " + rb.IsSleeping()) : "none")));
				if ((Object)(object)rb != (Object)null)
				{
					rb.WakeUp();
				}
				for (float tt = 0f; tt < 0.5f; tt += Time.fixedDeltaTime)
				{
					if ((Object)(object)rb != (Object)null)
					{
						rb.WakeUp();
						rb.AddForce(s.transform.forward * 0.25f, (ForceMode)2);
					}
					yield return (object)new WaitForFixedUpdate();
				}
				yield return (object)new WaitForSeconds(1f);
				float num2 = Vector3.Distance(p2, s.transform.position);
				float num3 = (((Object)(object)wnt != (Object)null) ? wnt.GetHealthPercentage() : 1f);
				Container componentInChildren = s.GetComponentInChildren<Container>();
				Log("sled " + name, sink < 0.25f && tilt < 25f && num2 > 1f && num3 >= hp0 - 0.01f, string.Format("below ground {0:0.00} m, tilt {1:0}°, towed {2:0.0} m, health {3:P0}->{4:P0}, storage {5}", sink, tilt, num2, hp0, num3, ((Object)(object)componentInChildren != (Object)null) ? (componentInChildren.m_width + "x" + componentInChildren.m_height) : "none"));
				ZNetScene.instance.Destroy(s);
				yield return (object)new WaitForSeconds(0.5f);
			}
		}

		private IEnumerator TestMobs(Player p)
		{
			List<string> list = (from g in ZNetScene.instance.m_prefabs
				where (Object)(object)g != (Object)null && ((Object)g).name.StartsWith("Yule") && (Object)(object)g.GetComponent<Character>() != (Object)null
				select ((Object)g).name).ToList();
			Log("mobs", list.Count > 0, list.Count + " Yuletide creatures: " + string.Join(", ", list));
			float num = default(float);
			foreach (string name in list)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab(name);
				Vector3 val = Ahead(p, 7f) + Vector3.up * 0.5f;
				GameObject m = Object.Instantiate<GameObject>(prefab, val, Quaternion.LookRotation(-((Component)p).transform.forward));
				Character ch = m.GetComponent<Character>();
				yield return (object)new WaitForSeconds(3f);
				if ((Object)(object)m == (Object)null || (Object)(object)ch == (Object)null)
				{
					Log("mob " + name, ok: false, "gone after spawn");
					continue;
				}
				ZoneSystem.instance.GetGroundHeight(m.transform.position, ref num);
				float below = num - m.transform.position.y;
				Animator componentInChildren = m.GetComponentInChildren<Animator>();
				bool animOk = (Object)(object)componentInChildren != (Object)null && ((Behaviour)componentInChildren).enabled && (Object)(object)componentInChildren.runtimeAnimatorController != (Object)null;
				string text = Localization.instance.Localize(ch.GetHoverName());
				bool ok = !string.IsNullOrEmpty(text) && text.IndexOf("Yule", StringComparison.OrdinalIgnoreCase) < 0 && !text.Contains("$") && !text.Contains("[");
				Log("name " + name, ok, "m_name '" + ch.m_name + "', shown '" + text + "'");
				Type.GetType("UnityEngine.ScreenCapture, UnityEngine.ScreenCaptureModule")?.GetMethod("CaptureScreenshot", new Type[1] { typeof(string) })?.Invoke(null, new object[1] { Path.Combine(Dir, "plate_" + name + ".png") });
				yield return (object)new WaitForSeconds(0.3f);
				yield return Shot("mob_" + name, m);
				Log("mob " + name, !ch.IsDead() && below < 0.3f && animOk, $"alive {!ch.IsDead()}, below ground {below:0.00} m, animator {animOk}, hp {ch.GetHealth():0}/{ch.GetMaxHealth():0}");
				ZNetScene.instance.Destroy(m);
				yield return (object)new WaitForSeconds(0.5f);
			}
		}

		private IEnumerator TestGoat(Player p)
		{
			GameObject prefab = ZNetScene.instance.GetPrefab("YuleGoat");
			if ((Object)(object)prefab == (Object)null)
			{
				Log("goat", ok: false, "prefab missing");
				yield break;
			}
			GameObject g = Object.Instantiate<GameObject>(prefab, Ahead(p, 6f) + Vector3.up * 0.5f, Quaternion.LookRotation(-((Component)p).transform.forward));
			Character goat = g.GetComponent<Character>();
			MonsterAI ai = g.GetComponent<MonsterAI>();
			yield return (object)new WaitForSeconds(5f);
			bool flag = BaseAI.IsEnemy(goat, (Character)(object)p);
			Character val = (((Object)(object)ai != (Object)null) ? ((BaseAI)ai).GetTargetCreature() : null);
			Log("goat calm", !flag && (Object)(object)val != (Object)(object)p, string.Format("name '{0}', enemy {1}, target {2}, distance {3:0.0} m", goat.m_name, flag, Object.op_Implicit((Object)(object)val) ? ((Object)val).name : "none", Vector3.Distance(g.transform.position, ((Component)p).transform.position)));
			HitData val2 = new HitData();
			val2.m_damage.m_blunt = 1f;
			val2.m_point = goat.GetCenterPoint();
			Vector3 val3 = g.transform.position - ((Component)p).transform.position;
			val2.m_dir = ((Vector3)(ref val3)).normalized;
			val2.SetAttacker((Character)(object)p);
			goat.Damage(val2);
			yield return (object)new WaitForSeconds(4f);
			bool flag2 = BaseAI.IsEnemy(goat, (Character)(object)p);
			Character val4 = (((Object)(object)ai != (Object)null) ? ((BaseAI)ai).GetTargetCreature() : null);
			Log("goat provoked", flag2 && (Object)(object)val4 == (Object)(object)p, string.Format("enemy {0}, target {1}, hp {2:0}/{3:0}", flag2, Object.op_Implicit((Object)(object)val4) ? ((Object)val4).name : "none", goat.GetHealth(), goat.GetMaxHealth()));
			ZNetScene.instance.Destroy(g);
			yield return (object)new WaitForSeconds(0.5f);
		}
	}
	internal static class SelfTestArmor
	{
		[HarmonyPatch(typeof(Player), "SetControls")]
		private static class ControlsPatch
		{
			private static void Prefix(Player __instance, ref Vector3 movedir, ref bool run, ref bool autoRun, ref bool jump, ref bool attack, ref bool crouch)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				if (_drive && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					movedir = _move;
					run = _run;
					autoRun = false;
					jump = _jump;
					attack = false;
					crouch = false;
				}
			}
		}

		private static bool _drive;

		private static bool _run;

		private static bool _jump;

		private static Vector3 _move;

		private const float CrouchHips = 0.65f;

		private static bool _testing;

		private static readonly Vector3 Front = new Vector3(0f, 0.06f, 1f);

		private static readonly Vector3 Back = new Vector3(0f, 0.06f, -1f);

		private static readonly Vector3 Side = new Vector3(1f, 0.05f, 0.02f);

		private static readonly Vector3 Quarter = new Vector3(0.6f, 0.12f, 1f);

		private static readonly Vector3 FrontLow = new Vector3(0f, -0.6f, 1f);

		private static readonly Vector3 BackLow = new Vector3(0f, -0.6f, -1f);

		private static readonly Vector3 Below = new Vector3(0f, -1f, 0.12f);

		public static string[] Only;

		private static readonly string[] Groups = new string[3] { "fit", "chains", "cloth" };

		private static bool _gFit = true;

		private static bool _gChains = true;

		private static bool _gCloth = true;

		private static readonly string[] SetNames = new string[9] { "elf", "winterelf", "santa", "embersanta", "krampus", "krampusx", "wool", "frost", "aurora" };

		private static readonly string[][] SetItems = new string[9][]
		{
			new string[3] { "YuleElfHat", "YuleElfTunic", "YuleElfLeggings" },
			new string[3] { "YuleWinterElfHat", "YuleWinterElfTunic", "YuleWinterElfLeggings" },
			new string[4] { "YuleSantaHat", "YuleSantaCoat", "YuleSantaTrousers", "YuleSantaBelt" },
			new string[3] { "YuleEmberSantaHat", "YuleEmberSantaCoat", "YuleEmberSantaTrousers" },
			new string[3] { "YuleKrampusHelm", "YuleKrampusChest", "YuleKrampusLegs" },
			new string[3] { "YuleKrampusXHelm", "YuleKrampusXChest", "YuleKrampusXLegs" },
			new string[3] { "YuleWoolHood", "YuleWoolTunic", "YuleWoolTrousers" },
			new string[3] { "YuleFrostHood", "YuleFrostCoat", "YuleFrostTrousers" },
			new string[3] { "YuleAuroraHood", "YuleAuroraCoat", "YuleAuroraTrousers" }
		};

		private static int _skipped0;

		private static int _unity0;

		private static Vector3 _home;

		private const int EW = 400;

		private const float ESpan = 0.2f;

		private const float EClip = 0.15f;

		private static Texture2D _endsTex;

		private static readonly string[] LoopNames = new string[4] { "left upper", "left lower", "right upper", "right lower" };

		private static readonly List<Renderer> _hidden = new List<Renderer>();

		private static string Dir => Path.Combine(Paths.BepInExRootPath, "yuletide_selftest");

		private static bool Short
		{
			get
			{
				if (Only != null)
				{
					return Only.Length != 0;
				}
				return false;
			}
		}

		private static void Log(string what, bool ok, string detail)
		{
			Logger.LogInfo((object)("YULE TEST " + (ok ? "PASS" : "FAIL") + " " + what + ": " + detail));
		}

		private static ItemData Give(Player p, string prefab)
		{
			GameObject go = ObjectDB.instance.GetItemPrefab(prefab);
			if ((Object)(object)go == (Object)null)
			{
				return null;
			}
			if (!((Humanoid)p).GetInventory().AddItem(go, 1))
			{
				return null;
			}
			return ((IEnumerable<ItemData>)((Humanoid)p).GetInventory().GetAllItems()).LastOrDefault((Func<ItemData, bool>)((ItemData i) => (Object)(object)i.m_dropPrefab == (Object)(object)go));
		}

		private static Transform Bone(Player p, string name)
		{
			Transform[] componentsInChildren = ((Component)p).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private static void Crouch(Player p, bool on)
		{
			Traverse.Create((object)p).Method("SetCrouch", new object[1] { on }).GetValue();
		}

		private static IEnumerator HoldCrouch(Player p, string what)
		{
			Transform hips = Bone(p, "Hips");
			((Character)p).AddStamina(((Character)p).GetMaxStamina());
			Crouch(p, on: true);
			float t = 0f;
			float still = 0f;
			float last = (((Object)(object)hips != (Object)null) ? (hips.position.y - ((Component)p).transform.position.y) : 0f);
			float y0 = last;
			float tOrder = 0f;
			int again = 0;
			while (t < 9f && still < 0.5f)
			{
				yield return null;
				float deltaTime = Time.deltaTime;
				t += deltaTime;
				tOrder += deltaTime;
				float num = (((Object)(object)hips != (Object)null) ? (hips.position.y - ((Component)p).transform.position.y) : 0f);
				bool flag = (Object)(object)hips == (Object)null || num < 0.65f;
				still = ((((Character)p).IsCrouching() && flag && Flat(((Character)p).GetVelocity()) < 0.1f && Mathf.Abs(num - last) < 0.0015f) ? (still + deltaTime) : 0f);
				last = num;
				if (tOrder > 1.5f && again < 4 && (!((Character)p).IsCrouching() || !flag))
				{
					again++;
					tOrder = 0f;
					((Character)p).AddStamina(((Character)p).GetMaxStamina());
					if (((Character)p).IsCrouching())
					{
						Crouch(p, on: false);
						yield return (object)new WaitForSeconds(0.35f);
						t += 0.35f;
					}
					Crouch(p, on: true);
				}
			}
			Animator componentInChildren = ((Component)p).GetComponentInChildren<Animator>();
			bool flag2 = (Object)(object)hips == (Object)null || last < 0.65f;
			Log("crouch held " + what, still >= 0.5f && ((Character)p).IsCrouching() && flag2, string.Format("after {0:0.0} s: crouching {1}, hips {2:0.00} -> {3:0.00} m above the feet (must be under {4:0.00}), at rest {5:0.0} s, ordered again {6} times, stamina {7:0}, animator culling {8}", t, ((Character)p).IsCrouching(), y0, last, 0.65f, still, again, p.GetStamina(), ((Object)(object)componentInChildren != (Object)null) ? ((object)componentInChildren.cullingMode/*cast due to .constrained prefix*/).ToString() : "none"));
			yield return (object)new WaitForSeconds(0.4f);
		}

		private static IEnumerator KeepStamina(Player p)
		{
			while (_testing && (Object)(object)p != (Object)null)
			{
				if (p.GetStamina() < ((Character)p).GetMaxStamina() * 0.6f)
				{
					((Character)p).AddStamina(((Character)p).GetMaxStamina());
				}
				yield return null;
			}
		}

		public static IEnumerator Run(Player p)
		{
			if ((Object)(object)EnvMan.instance != (Object)null)
			{
				EnvMan.instance.m_debugTimeOfDay = true;
				EnvMan.instance.m_debugTime = 0.5f;
			}
			p.SetGhostMode(true);
			int num = 0;
			foreach (Character item in Character.GetAllCharacters().ToList())
			{
				if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)p) && !item.IsPlayer() && !(Vector3.Distance(((Component)item).transform.position, ((Component)p).transform.position) > 80f))
				{
					ZNetView component = ((Component)item).GetComponent<ZNetView>();
					if ((Object)(object)component != (Object)null && component.IsValid())
					{
						component.ClaimOwnership();
						component.Destroy();
						num++;
					}
				}
			}
			Logger.LogInfo((object)$"YULE TEST: {num} creatures near the character removed");
			yield return (object)new WaitForSeconds(2f);
			if (Only != null)
			{
				string[] array = Only.Where((string o) => Array.IndexOf(Groups, o) < 0).ToArray();
				string[] array2 = Only.Where((string o) => Array.IndexOf(Groups, o) >= 0).ToArray();
				if (array2.Length != 0)
				{
					_gFit = array2.Contains("fit");
					_gChains = array2.Contains("chains");
					_gCloth = array2.Contains("cloth");
				}
				if (array.Length == 0 && array2.Length != 0)
				{
					array = SetNames;
				}
				Only = array;
				Logger.LogInfo((object)string.Format("YULE TEST: short armor run: sets {0}; groups fit {1}, chains {2}, cloth {3}", string.Join(",", array), _gFit, _gChains, _gCloth));
			}
			int model0 = p.GetPlayerModel();
			string hair0 = ((Humanoid)p).GetHair();
			Vector3 home = ((Component)p).transform.position;
			Vector3 fwd0 = ((Component)p).transform.forward;
			fwd0.y = 0f;
			((Vector3)(ref fwd0)).Normalize();
			_home = home;
			_testing = true;
			((MonoBehaviour)p).StartCoroutine(KeepStamina(p));
			int seg = 0;
			for (int sex = 0; sex < 2; sex++)
			{
				string sx = ((sex == 0) ? "male" : "female");
				p.SetPlayerModel(sex);
				yield return (object)new WaitForSeconds(2f);
				for (int si = 0; si < SetNames.Length; si++)
				{
					string set = SetNames[si];
					if (Only != null && Only.Length != 0 && Array.IndexOf(Only, set) < 0)
					{
						continue;
					}
					yield return Wear(p, SetItems[si]);
					VisEquipment component2 = ((Component)p).GetComponent<VisEquipment>();
					SkinnedMeshRenderer val = (((Object)(object)component2 != (Object)null) ? component2.m_bodyModel : null);
					if ((Object)(object)val != (Object)null && (Object)(object)val.sharedMesh != (Object)null)
					{
						Log("armor " + set + " " + sx, ok: true, $"body mesh {((Object)val.sharedMesh).name}, {val.sharedMesh.triangles.Length / 3} triangles drawn, model {p.GetPlayerModel()}");
					}
					string tag = set + "_" + sx;
					yield return Shot(p, tag + "_stand", "Hips", 0f, 2.2f, (Vector3[])(object)new Vector3[2] { Front, Back });
					yield return Third(p, "tp_" + tag + "_stand");
					if (set == "krampus" || set == "krampusx")
					{
						ChainRope[] componentsInChildren = ((Component)p).GetComponentsInChildren<ChainRope>(true);
						foreach (ChainRope chainRope in componentsInChildren)
						{
							Log("chain equip " + tag, ok: true, chainRope.Diag());
						}
					}
					Vector3 dir = ((seg++ % 2 == 0) ? fwd0 : (-fwd0));
					if (_gFit)
					{
						yield return HoldCrouch(p, tag);
						yield return Shot(p, tag + "_crouch", "Hips", 0f, 1.15f, (Vector3[])(object)new Vector3[4] { FrontLow, Back, BackLow, Below });
						yield return Stride(p, tag + "_sneak", dir, run: false, "Hips", 0f, 1.15f, (Vector3[])(object)new Vector3[4] { FrontLow, BackLow, Below, Side });
						_move = -dir;
						_run = false;
						_drive = true;
						yield return (object)new WaitForSeconds(1.4f);
						yield return Third(p, "tp_" + tag + "_sneak");
						_drive = false;
						_move = Vector3.zero;
						Crouch(p, on: false);
						yield return (object)new WaitForSeconds(1.2f);
						yield return Stride(p, tag + "_run", -dir, run: true, "Hips", 0.15f, 2.1f, (Vector3[])(object)new Vector3[4] { Front, Back, Side, Quarter });
						_move = dir;
						_run = true;
						_drive = true;
						yield return (object)new WaitForSeconds(1.4f);
						yield return Third(p, "tp_" + tag + "_run");
						_drive = false;
						_move = Vector3.zero;
						_run = false;
						yield return (object)new WaitForSeconds(0.8f);
					}
					if ((set == "krampus" || set == "krampusx") && _gChains)
					{
						Vector3[] cv = (Vector3[])(object)new Vector3[4] { Front, Side, Back, Quarter };
						ChainRope[] componentsInChildren = ((Component)p).GetComponentsInChildren<ChainRope>(true);
						foreach (ChainRope chainRope2 in componentsInChildren)
						{
							Log("chain stand " + tag, ok: true, chainRope2.Diag());
						}
						yield return Moving(p, "chain_" + tag + "_walk", dir, run: false, 1.6f, "Hips", 0.2f, 1.5f, cv);
						yield return Moving(p, "chain_" + tag + "_run", -dir, run: true, 1.6f, "Hips", 0.2f, 1.5f, cv);
						yield return (object)new WaitForSeconds(2.2f);
						componentsInChildren = ((Component)p).GetComponentsInChildren<ChainRope>(true);
						foreach (ChainRope chainRope3 in componentsInChildren)
						{
							Log("chain stand3 " + tag, ok: true, chainRope3.Diag());
						}
						yield return ChainEnds(p, tag, 0, "standing");
						yield return HoldCrouch(p, "chain " + tag);
						yield return (object)new WaitForEndOfFrame();
						componentsInChildren = ((Component)p).GetComponentsInChildren<ChainRope>(true);
						foreach (ChainRope chainRope4 in componentsInChildren)
						{
							Log("chain crouch " + tag, ok: true, chainRope4.Diag());
						}
						yield return Shot(p, "chain_" + tag + "_crouch", "Hips", 0.2f, 1.5f, cv);
						yield return ChainEnds(p, tag, 1, "crouching");
						Crouch(p, on: false);
						yield return (object)new WaitForSeconds(1.5f);
						((Character)p).StartAttack((Character)null, false);
						yield return (object)new WaitForSeconds(0.28f);
						yield return Shot(p, "chain_" + tag + "_attack", "Hips", 0.2f, 1.5f, cv);
						yield return (object)new WaitForSeconds(1.5f);
						if ((Object)(object)EnvMan.instance != (Object)null && !Short)
						{
							EnvMan.instance.m_debugTime = 0f;
							yield return (object)new WaitForSeconds(2.5f);
							yield return Third(p, "tp_" + tag + "_night");
							EnvMan.instance.m_debugTime = 0.5f;
							Traverse.Create((object)EnvMan.instance).Field("m_debugEnv").SetValue((object)"Rain");
							yield return (object)new WaitForSeconds(6f);
							yield return Third(p, "tp_" + tag + "_rain");
							Traverse.Create((object)EnvMan.instance).Field("m_debugEnv").SetValue((object)"");
							yield return (object)new WaitForSeconds(4f);
						}
					}
					Vector3 turn;
					if (_gCloth)
					{
						string seq = ((set == "krampus" || set == "krampusx") ? "chainseq" : "clothseq");
						MagicaCloth[] componentsInChildren2 = ((Component)p).GetComponentsInChildren<MagicaCloth>(true);
						int own = 0;
						int num3 = 0;
						string text = "";
						MagicaCloth[] array3 = componentsInChildren2;
						foreach (MagicaCloth val2 in array3)
						{
							if (!((Object)(object)val2 == (Object)null) && ((Object)val2).name.StartsWith("YuleCloth"))
							{
								own++;
								if (val2.IsValid())
								{
									num3++;
								}
								text = text + ((text.Length > 0) ? ", " : "") + (((Object)(object)((Component)val2).transform.parent != (Object)null) ? ((Object)((Component)val2).transform.parent).name : ((Object)val2).name);
							}
						}
						Log("cloth " + tag, own == 0 || num3 == own, $"{own} cloth parts of ours, {num3} running ({text}); cloth components on the character in all: {componentsInChildren2.Length}");
						int skipped = ClothWriteGuard.Skipped;
						int unityErrors = ClothWriteGuard.UnityErrors;
						Log("cloth writes " + tag, skipped == _skipped0 && unityErrors == _unity0, $"since the last set: {skipped - _skipped0} cloth writes skipped by the guard, {unityErrors - _unity0} refused by Unity (in all {skipped} and {unityErrors})");
						_skipped0 = skipped;
						_unity0 = unityErrors;
						turn = Vector3.Cross(Vector3.up, dir);
						yield return FrameTime(p, tag + " cloth " + ((own > 0) ? "on" : "none"), dir);
						if (sex == 0 && own > 0 && !Short)
						{
							YuleCloth.Enabled = false;
							yield return Wear(p, SetItems[si]);
							yield return FrameTime(p, tag + " cloth off", -dir);
							YuleCloth.Enabled = true;
							yield return Wear(p, SetItems[si]);
						}
						_move = dir;
						_run = true;
						_drive = true;
						yield return (object)new WaitForSeconds(0.2f);
						yield return Sequence(p, seq + "_" + tag + "_1_run");
						_move = turn;
						yield return Sequence(p, seq + "_" + tag + "_2_turn");
						_move = Vector3.zero;
						_run = false;
						yield return Sequence(p, seq + "_" + tag + "_3_stop");
						((Character)p).AddStamina(((Character)p).GetMaxStamina());
						yield return (object)new WaitForSeconds(0.3f);
						_jump = true;
						bool flag = false;
						for (int f = 0; f < 30; f++)
						{
							if (flag)
							{
								break;
							}
							yield return null;
							flag = !((Character)p).IsOnGround();
						}
						_jump = false;
						Log("jump " + tag, flag, flag ? "left the ground" : "never left the ground in 30 frames");
						yield return Sequence(p, seq + "_" + tag + "_4_jump");
						_drive = false;
						yield return (object)new WaitForSeconds(0.6f);
						Crouch(p, on: true);
						yield return Sequence(p, seq + "_" + tag + "_5_crouch");
						Crouch(p, on: false);
						((Character)p).AddStamina(((Character)p).GetMaxStamina());
						yield return (object)new WaitForSeconds(1f);
					}
					if (set == "krampus" || set == "krampusx")
					{
						yield return (object)new WaitForSeconds(0.5f);
						yield return Shot(p, "armpit_" + tag, "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[4]
						{
							Side,
							Quarter,
							new Vector3(0.6f, 0.12f, -1f),
							new Vector3(1f, -0.5f, 0.3f)
						});
						((Character)p).StartAttack((Character)null, false);
						yield return (object)new WaitForSeconds(0.28f);
						yield return Shot(p, "armpit_" + tag + "_attack", "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[4]
						{
							Side,
							Quarter,
							new Vector3(0.6f, 0.12f, -1f),
							new Vector3(1f, -0.5f, 0.3f)
						});
						yield return (object)new WaitForSeconds(1.5f);
					}
					switch (set)
					{
					case "wool":
					case "frost":
					case "aurora":
					{
						for (int own = 0; own < 2; own++)
						{
							((Character)p).AddStamina(((Character)p).GetMaxStamina());
							if (own == 1)
							{
								_move = dir;
								_run = true;
								_drive = true;
								yield return (object)new WaitForSeconds(0.7f);
							}
							else
							{
								_move = Vector3.zero;
								_run = false;
								_drive = true;
								yield return (object)new WaitForSeconds(0.3f);
							}
							_jump = true;
							bool flag2 = false;
							for (int f = 0; f < 30; f++)
							{
								if (flag2)
								{
									break;
								}
								yield return null;
								flag2 = !((Character)p).IsOnGround();
							}
							_jump = false;
							yield return JumpClose(p, "skirtjump_" + tag + "_" + ((own == 0) ? "stand" : "run"));
							_drive = false;
							_move = Vector3.zero;
							_run = false;
							yield return (object)new WaitForSeconds(1f);
						}
						yield return HoldCrouch(p, "skirtsneak " + tag);
						if (Vector3.Distance(((Component)p).transform.position, _home) > 6f)
						{
							((Component)p).transform.position = _home;
							yield return (object)new WaitForSeconds(0.8f);
							yield return HoldCrouch(p, "skirtsneak " + tag + " (back home)");
						}
						_move = dir;
						_run = false;
						_drive = true;
						yield return (object)new WaitForSeconds(1.2f);
						if (Flat(((Character)p).GetVelocity()) < 0.3f)
						{
							_move = -dir;
							yield return (object)new WaitForSeconds(1.2f);
						}
						Log("skirtsneak " + tag, ((Character)p).IsCrouching() && Flat(((Character)p).GetVelocity()) > 0.3f, $"crouching {((Character)p).IsCrouching()}, speed {Flat(((Character)p).GetVelocity()):0.0} m/s");
						yield return JumpClose(p, "skirtsneak_" + tag, "Hips", 0.6f, 0.15f);
						_drive = false;
						_move = Vector3.zero;
						Crouch(p, on: false);
						yield return (object)new WaitForSeconds(1.2f);
						break;
					}
					}
					if (set == "embersanta")
					{
						yield return (object)new WaitForSeconds(0.5f);
						Vector3[] cv = (Vector3[])(object)new Vector3[4]
						{
							Front,
							new Vector3(0f, -1f, 0.3f),
							new Vector3(0.5f, -0.8f, 0.5f),
							new Vector3(-0.5f, -0.8f, 0.5f)
						};
						yield return Shot(p, "cuff_" + tag + "_left", "LeftHand", 0.05f, 0.4f, cv);
						yield return Shot(p, "cuff_" + tag + "_right", "RightHand", 0.05f, 0.4f, cv);
						((Character)p).AddStamina(((Character)p).GetMaxStamina());
						_move = Vector3.zero;
						_run = false;
						_drive = true;
						yield return (object)new WaitForSeconds(0.3f);
						_jump = true;
						bool flag3 = false;
						for (int own = 0; own < 30; own++)
						{
							if (flag3)
							{
								break;
							}
							yield return null;
							flag3 = !((Character)p).IsOnGround();
						}
						_jump = false;
						yield return JumpClose(p, "liner_" + tag + "_jump", "Spine2", 0.5f);
						_drive = false;
						yield return (object)new WaitForSeconds(1f);
					}
					turn = new Vector3(0f, -0.5f, 1f);
					Vector3 below = new Vector3(0f, -1f, 0.15f);
					Vector3 backQ = new Vector3(-0.6f, 0.12f, -1f);
					Vector3 backLow = new Vector3(0f, -0.45f, -1f);
					bool santa = set == "santa" || set == "embersanta";
					bool elf = set == "elf" || set == "winterelf";
					bool kr = set == "krampus" || set == "krampusx";
					bool wl = set == "wool" || set == "frost" || set == "aurora";
					if (santa || elf || kr || wl)
					{
						yield return (object)new WaitForSeconds(0.5f);
						if (santa)
						{
							yield return Shot(p, "r22_collar_" + tag, "Neck", 0f, 0.45f, (Vector3[])(object)new Vector3[3] { Front, Quarter, Side });
							yield return Shot(p, "r22_wrists_" + tag, "LeftHand", 0f, 0.35f, (Vector3[])(object)new Vector3[3] { Front, Side, Back });
							yield return Shot(p, "r22_wrists_" + tag + "_r", "RightHand", 0f, 0.35f, (Vector3[])(object)new Vector3[3] { Front, Side, Back });
						}
						if (elf)
						{
							yield return Shot(p, "r22_neck_" + tag, "Neck", 0f, 0.45f, (Vector3[])(object)new Vector3[3] { Front, Quarter, Side });
							yield return Shot(p, "r22_strap_" + tag, "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[3] { Back, backQ, Side });
							yield return Shot(p, "r22_shoes_" + tag, "Hips", -0.85f, 0.5f, (Vector3[])(object)new Vector3[4] { Front, Quarter, Side, below });
						}
						if (kr)
						{
							yield return Shot(p, "r22_skull_" + tag, "Head", 0.08f, 0.4f, (Vector3[])(object)new Vector3[3] { Front, Quarter, Side });
							yield return Shot(p, "r22_midback_" + tag, "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[2] { Back, backQ });
						}
						if (wl)
						{
							yield return Shot(p, "r22_waist_" + tag, "Hips", 0.15f, 0.6f, (Vector3[])(object)new Vector3[3] { Back, backQ, Side });
							yield return Shot(p, "r22_soles_" + tag, "Hips", -0.85f, 0.5f, (Vector3[])(object)new Vector3[3] { below, turn, Side });
						}
						yield return HoldCrouch(p, "r22 " + tag);
						if (santa)
						{
							yield return Shot(p, "r22_crouch_" + tag, "Hips", 0.15f, 0.8f, (Vector3[])(object)new Vector3[4] { Front, Quarter, backLow, Back });
						}
						if (elf)
						{
							yield return Shot(p, "r22_crouch_" + tag, "Hips", 0.2f, 0.7f, (Vector3[])(object)new Vector3[4] { Front, Quarter, backQ, Side });
						}
						if (kr)
						{
							yield return Shot(p, "r22_crouch_" + tag, "Hips", 0.05f, 0.8f, (Vector3[])(object)new Vector3[4] { Front, turn, backQ, Back });
						}
						if (kr)
						{
							yield return Shot(p, "r24_midback_" + tag + "_crouch", "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[2] { Back, backQ });
							yield return Stride(p, "r24_midback_" + tag + "_sneak", dir, run: false, "Spine1", 0f, 0.6f, (Vector3[])(object)new Vector3[2] { Back, backQ });
							_drive = false;
							_move = Vector3.zero;
						}
						if (wl)
						{
							yield return Shot(p, "r22_crouch_" + tag, "Hips", 0.1f, 0.7f, (Vector3[])(object)new Vector3[4]
							{
								Back,
								backQ,
								Side,
								new Vector3(-1f, 0.05f, 0.02f)
							});
						}
						Crouch(p, on: false);
						yield return (object)new WaitForSeconds(1f);
					}
					if (set == "elf" || set == "winterelf")
					{
						string[] array4 = new string[2] { "Hair3", "Hair18" };
						foreach (string seq in array4)
						{
							((Humanoid)p).SetHair(seq);
							yield return (object)new WaitForSeconds(1.5f);
							yield return Shot(p, "hat_" + tag + "_" + seq, "Head", 0.1f, 0.72f, (Vector3[])(object)new Vector3[3] { Front, Side, Back });
						}
						((Humanoid)p).SetHair(hair0);
						yield return (object)new WaitForSeconds(0.5f);
					}
					if (Vector3.Distance(((Component)p).transform.position, home) > 12f)
					{
						((Component)p).transform.position = home;
						yield return (object)new WaitForSeconds(1f);
					}
				}
			}
			_drive = false;
			_jump = false;
			_testing = false;
			if ((Object)(object)EnvMan.instance != (Object)null)
			{
				Traverse.Create((object)EnvMan.instance).Field("m_debugEnv").SetValue((object)"");
			}
			if (!Short)
			{
				yield return StandTrial(p);
			}
			((Humanoid)p).UnequipAllItems();
			((Humanoid)p).GetInventory().RemoveAll();
			p.SetPlayerModel(model0);
			((Humanoid)p).SetHair(hair0);
			yield return (object)new WaitForSeconds(1f);
		}

		private static IEnumerator StandTrial(Player p)
		{
			int made = 0;
			int found = 0;
			List<MagicaCloth> parts = new List<MagicaCloth>();
			int sk0 = ClothWriteGuard.Skipped;
			int ue0 = ClothWriteGuard.UnityErrors;
			YuleCloth.Stands = true;
			VisEquipment[] array = Object.FindObjectsOfType<VisEquipment>();
			foreach (VisEquipment val in array)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<Player>() != (Object)null || Vector3.Distance(((Component)val).transform.position, ((Component)p).transform.position) > 80f)
				{
					continue;
				}
				SkinnedMeshRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && YuleCloth.HasRule(val2.sharedMesh))
					{
						found++;
						bool flag = false;
						try
						{
							flag = YuleCloth.Setup(val2, val);
						}
						catch (Exception ex)
						{
							Logger.LogWarning((object)("YULE TEST: stand cloth: " + ex.Message));
						}
						if (flag)
						{
							made++;
							parts.AddRange(((Component)val2).GetComponentsInChildren<MagicaCloth>(true));
						}
					}
				}
			}
			YuleCloth.Stands = false;
			if (found == 0)
			{
				Logger.LogInfo((object)"YULE TEST: stand cloth trial: no stand near the character wears a piece with cloth");
				yield break;
			}
			yield return (object)new WaitForSeconds(4f);
			int num = 0;
			foreach (MagicaCloth item in parts)
			{
				if ((Object)(object)item != (Object)null && item.IsValid())
				{
					num++;
				}
			}
			int num2 = ClothWriteGuard.Skipped - sk0;
			int num3 = ClothWriteGuard.UnityErrors - ue0;
			Log("stand cloth trial", made > 0 && num == parts.Count && num2 == 0 && num3 == 0, $"{found} pieces on stands, {made} set up, {num} of {parts.Count} cloths running after 4 s, {num2} writes skipped by the guard, {num3} refused by Unity");
		}

		private static IEnumerator FrameTime(Player p, string what, Vector3 dir)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			((Character)p).AddStamina(((Character)p).GetMaxStamina());
			_move = dir;
			_run = true;
			_drive = true;
			yield return (object)new WaitForSeconds(0.5f);
			float sum = 0f;
			float worst = 0f;
			int n = 0;
			float end = Time.realtimeSinceStartup + 2.5f;
			while (Time.realtimeSinceStartup < end)
			{
				yield return null;
				float unscaledDeltaTime = Time.unscaledDeltaTime;
				sum += unscaledDeltaTime;
				n++;
				if (unscaledDeltaTime > worst)
				{
					worst = unscaledDeltaTime;
				}
			}
			_drive = false;
			_move = Vector3.zero;
			_run = false;
			Logger.LogInfo((object)$"YULE TEST: frame time {what}: average {((n > 0) ? (sum / (float)n * 1000f) : 0f):0.00} ms, worst {worst * 1000f:0.0} ms over {n} frames");
			yield return (object)new WaitForSeconds(0.6f);
		}

		private static IEnumerator Wear(Player p, string[] items)
		{
			((Humanoid)p).UnequipAllItems();
			((Humanoid)p).GetInventory().RemoveAll();
			yield return (object)new WaitForSeconds(0.5f);
			foreach (string text in items)
			{
				ItemData val = Give(p, text);
				if (val == null)
				{
					Log("armor " + text, ok: false, "no such item");
				}
				else
				{
					((Humanoid)p).EquipItem(val, true);
				}
			}
			yield return (object)new WaitForSeconds(2.5f);
			foreach (ItemData item in ((Humanoid)p).GetInventory().GetAllItems().ToList())
			{
				if (!((Humanoid)p).IsItemEquiped(item))
				{
					((Humanoid)p).EquipItem(item, true);
					Logger.LogInfo((object)("YULE TEST: equipped again " + item.m_shared.m_name));
				}
			}
			yield return (object)new WaitForSeconds(1.5f);
		}

		private static float Flat(Vector3 v)
		{
			v.y = 0f;
			return ((Vector3)(ref v)).magnitude;
		}

		private static float FootGap(Player p, Transform l, Transform r)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)l == (Object)null) && !((Object)(object)r == (Object)null))
			{
				return Vector3.Dot(r.position - l.position, ((Component)p).transform.forward);
			}
			return 0f;
		}

		private static IEnumerator Stride(Player p, string name, Vector3 dir, bool run, string bone, float up, float height, Vector3[] views)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Transform lf = Bone(p, "LeftFoot");
			Transform rf = Bone(p, "RightFoot");
			bool wasDown = ((Character)p).IsCrouching();
			if (Vector3.Distance(((Component)p).transform.position, _home) > 3f)
			{
				((Component)p).transform.position = _home;
				yield return (object)new WaitForSeconds(0.8f);
				if (wasDown && !run)
				{
					yield return HoldCrouch(p, name + " (back home)");
				}
			}
			((Character)p).AddStamina(((Character)p).GetMaxStamina());
			float max = float.MinValue;
			float min = float.MaxValue;
			float top = 0f;
			int tries;
			for (tries = 0; tries < 3; tries++)
			{
				if (!run && wasDown && !((Character)p).IsCrouching())
				{
					Crouch(p, on: true);
				}
				_move = dir;
				_run = run;
				_drive = true;
				yield return (object)new WaitForSeconds(1.3f);
				max = float.MinValue;
				min = float.MaxValue;
				top = 0f;
				for (float t = 0f; t < 1.6f; t += Time.deltaTime)
				{
					float num = Flat(((Character)p).GetVelocity());
					top = Mathf.Max(top, num);
					if (num > 0.5f)
					{
						float num2 = FootGap(p, lf, rf);
						if (num2 > max)
						{
							max = num2;
						}
						if (num2 < min)
						{
							min = num2;
						}
					}
					yield return null;
				}
				if (top > 0.5f && max - min > 0.2f)
				{
					break;
				}
				Logger.LogInfo((object)$"YULE TEST: {name}: did not move along {dir:F1} (top {top:0.0} m/s), try {tries + 1}");
				if (tries == 1)
				{
					_drive = false;
					((Component)p).transform.position = _home;
					yield return (object)new WaitForSeconds(0.8f);
				}
				dir = -dir;
			}
			if (max < min)
			{
				max = 0f;
				min = 0f;
			}
			if (run)
			{
				((Character)p).AddStamina(((Character)p).GetMaxStamina());
				dir = -dir;
				_move = dir;
				yield return (object)new WaitForSeconds(1f);
			}
			bool a = false;
			bool b = false;
			float ga = 0f;
			float gb = 0f;
			float sa = 0f;
			float sb = 0f;
			float slow = 0f;
			int turns = 0;
			bool valid = top > 0.5f && max - min > 0.2f;
			float moved = 0f;
			float lmax = float.MinValue;
			float lmin = float.MaxValue;
			float ltop = 0f;
			for (float t = 0f; t < 9f; t += Time.deltaTime)
			{
				if (a && b)
				{
					break;
				}
				float num3 = FootGap(p, lf, rf);
				float num4 = Flat(((Character)p).GetVelocity());
				bool flag = ((!valid) ? (num4 > 0.5f) : (num4 > 0.6f * top && num4 > 0.5f));
				if (!valid && flag)
				{
					slow = 0f;
					moved += Time.deltaTime;
					ltop = Mathf.Max(ltop, num4);
					if (num3 > lmax)
					{
						lmax = num3;
					}
					if (num3 < lmin)
					{
						lmin = num3;
					}
					if (moved > 1.3f && lmax - lmin > 0.2f)
					{
						max = lmax;
						min = lmin;
						top = ltop;
						valid = true;
					}
					yield return null;
				}
				else if (!flag)
				{
					slow += Time.deltaTime;
					if (slow > 0.5f && turns < 3)
					{
						turns++;
						slow = 0f;
						dir = -dir;
						_move = dir;
						((Character)p).AddStamina(((Character)p).GetMaxStamina());
						yield return (object)new WaitForSeconds(1f);
						t += 1f;
					}
					yield return null;
				}
				else
				{
					slow = 0f;
					if (!a && num3 >= max - 0.08f * (max - min))
					{
						a = true;
						ga = num3;
						sa = num4;
						yield return Shot(p, name + "_a", bone, up, height, views);
					}
					else if (!b && num3 <= min + 0.08f * (max - min))
					{
						b = true;
						gb = num3;
						sb = num4;
						yield return Shot(p, name + "_b", bone, up, height, views);
					}
					else
					{
						yield return null;
					}
				}
			}
			bool late = !a || !b;
			if (!a)
			{
				yield return Shot(p, name + "_a", bone, up, height, views);
			}
			if (!b)
			{
				yield return Shot(p, name + "_b", bone, up, height, views);
			}
			_drive = false;
			_move = Vector3.zero;
			_run = false;
			Log("armor stride " + name, !late && max - min > 0.2f, $"feet {min:0.00}..{max:0.00} m apart along the facing, shot at {ga:0.00} and {gb:0.00} at {sa:0.0} and {sb:0.0} m/s (top {top:0.0}), turned back {turns} times, measured again {tries} times, crouching {((Character)p).IsCrouching()}");
			yield return (object)new WaitForSeconds(0.6f);
		}

		private static IEnumerator Moving(Player p, string name, Vector3 dir, bool run, float after, string bone, float up, float height, Vector3[] views)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			_move = dir;
			_run = run;
			_drive = true;
			yield return (object)new WaitForSeconds(after);
			yield return Shot(p, name, bone, up, height, views);
			_drive = false;
			_move = Vector3.zero;
			_run = false;
			yield return (object)new WaitForSeconds(0.6f);
		}

		private static IEnumerator Shot(Player p, string name, string bone, float up, float height, Vector3[] views)
		{
			yield return (object)new WaitForEndOfFrame();
			GameObject val = new GameObject("YuleTestCam");
			Camera val2 = val.AddComponent<Camera>();
			val2.orthographic = true;
			val2.orthographicSize = height / 2f;
			val2.nearClipPlane = 0.05f;
			val2.farClipPlane = 50f;
			val2.clearFlags = (CameraClearFlags)2;
			val2.backgroundColor = new Color(0.55f, 0.6f, 0.68f);
			RenderTexture val3 = (val2.targetTexture = new RenderTexture(640, 640, 24));
			Texture2D val5 = new Texture2D(640 * views.Length, 640, (TextureFormat)3, false);
			int num = 0;
			Renderer[] componentsInChildren = ((Component)p).GetComponentsInChildren<Renderer>();
			foreach (Renderer val6 in componentsInChildren)
			{
				num |= 1 << ((Component)val6).gameObject.layer;
			}
			if (num != 0)
			{
				val2.cullingMask = num;
			}
			Transform transform = ((Component)p).transform;
			Transform val7 = Bone(p, bone);
			Vector3 val8 = (((Object)(object)val7 != (Object)null) ? val7.position : (transform.position + Vector3.up)) + Vector3.up * up;
			HideOthers(p, num, val8);
			for (int j = 0; j < views.Length; j++)
			{
				Vector3 val9 = transform.right * views[j].x + Vector3.up * views[j].y + transform.forward * views[j].z;
				Vector3 normalized = ((Vector3)(ref val9)).normalized;
				((Component)val2).transform.position = val8 + normalized * 4f;
				((Component)val2).transform.rotation = Quaternion.LookRotation(-normalized, (Mathf.Abs(normalized.y) > 0.9f) ? transform.forward : Vector3.up);
				val2.Render();
				RenderTexture.active = val3;
				val5.ReadPixels(new Rect(0f, 0f, 640f, 640f), j * 640, 0);
				RenderTexture.active = null;
			}
			ShowOthers();
			Save(val5, name);
			val2.targetTexture = null;
			Object.Destroy((Object)(object)val3);
			Object.Destroy((Object)(object)val5);
			Object.Destroy((Object)(object)val);
			yield return null;
		}

		private static float PointTri(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = b - a;
			Vector3 val2 = c - a;
			Vector3 val3 = p - a;
			float num = Vector3.Dot(val, val3);
			float num2 = Vector3.Dot(val2, val3);
			if (num <= 0f && num2 <= 0f)
			{
				return ((Vector3)(ref val3)).magnitude;
			}
			Vector3 val4 = p - b;
			float num3 = Vector3.Dot(val, val4);
			float num4 = Vector3.Dot(val2, val4);
			if (num3 >= 0f && num4 <= num3)
			{
				return ((Vector3)(ref val4)).magnitude;
			}
			float num5 = num * num4 - num3 * num2;
			Vector3 val5;
			if (num5 <= 0f && num >= 0f && num3 <= 0f)
			{
				val5 = p - (a + val * (num / (num - num3)));
				return ((Vector3)(ref val5)).magnitude;
			}
			Vector3 val6 = p - c;
			float num6 = Vector3.Dot(val, val6);
			float num7 = Vector3.Dot(val2, val6);
			if (num7 >= 0f && num6 <= num7)
			{
				return ((Vector3)(ref val6)).magnitude;
			}
			float num8 = num6 * num2 - num * num7;
			if (num8 <= 0f && num2 >= 0f && num7 <= 0f)
			{
				val5 = p - (a + val2 * (num2 / (num2 - num7)));
				return ((Vector3)(ref val5)).magnitude;
			}
			float num9 = num3 * num7 - num6 * num4;
			if (num9 <= 0f && num4 - num3 >= 0f && num6 - num7 >= 0f)
			{
				val5 = p - (b + (c - b) * ((num4 - num3) / (num4 - num3 + (num6 - num7))));
				return ((Vector3)(ref val5)).magnitude;
			}
			float num10 = 1f / (num9 + num8 + num5);
			val5 = p - (a + val * (num8 * num10) + val2 * (num5 * num10));
			return ((Vector3)(ref val5)).magnitude;
		}

		private static float[] ToOutfit(Player p, Vector3[] pts, out int tris)
		{
			//IL_00a9: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: 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_027c: 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_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: 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_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[pts.Length];
			tris = 0;
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = float.MaxValue;
			}
			SkinnedMeshRenderer[] componentsInChildren = ((Component)p).GetComponentsInChildren<SkinnedMeshRenderer>();
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				if (!ChainRope.Wears(val) || !val.sharedMesh.isReadable)
				{
					continue;
				}
				Mesh sharedMesh = val.sharedMesh;
				Transform[] bones = val.bones;
				Matrix4x4[] bindposes = sharedMesh.bindposes;
				int num = Mathf.Min(bones.Length, bindposes.Length);
				Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[num];
				bool[] array3 = new bool[num];
				for (int k = 0; k < num; k++)
				{
					if (!((Object)(object)bones[k] == (Object)null))
					{
						array2[k] = bones[k].localToWorldMatrix * bindposes[k];
						string name = ((Object)bones[k]).name;
						array3[k] = name.StartsWith("YuleLink") || name.StartsWith("YuleRope") || name.StartsWith("YuleChain");
					}
				}
				Vector3[] vertices = sharedMesh.vertices;
				BoneWeight[] boneWeights = sharedMesh.boneWeights;
				int[] triangles = sharedMesh.triangles;
				if (boneWeights.Length != vertices.Length)
				{
					continue;
				}
				Vector3[] array4 = (Vector3[])(object)new Vector3[vertices.Length];
				bool[] array5 = new bool[vertices.Length];
				for (int l = 0; l < vertices.Length; l++)
				{
					BoneWeight val2 = boneWeights[l];
					Vector3 val3 = Vector3.zero;
					if (((BoneWeight)(ref val2)).boneIndex0 >= num || ((BoneWeight)(ref val2)).boneIndex1 >= num || ((BoneWeight)(ref val2)).boneIndex2 >= num || ((BoneWeight)(ref val2)).boneIndex3 >= num)
					{
						array5[l] = true;
						continue;
					}
					if (((BoneWeight)(ref val2)).weight0 > 0f)
					{
						val3 += ((Matrix4x4)(ref array2[((BoneWeight)(ref val2)).boneIndex0])).MultiplyPoint3x4(vertices[l]) * ((BoneWeight)(ref val2)).weight0;
						ref bool reference = ref array5[l];
						reference |= array3[((BoneWeight)(ref val2)).boneIndex0];
					}
					if (((BoneWeight)(ref val2)).weight1 > 0f)
					{
						val3 += ((Matrix4x4)(ref array2[((BoneWeight)(ref val2)).boneIndex1])).MultiplyPoint3x4(vertices[l]) * ((BoneWeight)(ref val2)).weight1;
						ref bool reference2 = ref array5[l];
						reference2 |= array3[((BoneWeight)(ref val2)).boneIndex1];
					}
					if (((BoneWeight)(ref val2)).weight2 > 0f)
					{
						val3 += ((Matrix4x4)(ref array2[((BoneWeight)(ref val2)).boneIndex2])).MultiplyPoint3x4(vertices[l]) * ((BoneWeight)(ref val2)).weight2;
						ref bool reference3 = ref array5[l];
						reference3 |= array3[((BoneWeight)(ref val2)).boneIndex2];
					}
					if (((BoneWeight)(ref val2)).weight3 > 0f)
					{
						val3 += ((Matrix4x4)(ref array2[((BoneWeight)(ref val2)).boneIndex3])).MultiplyPoint3x4(vertices[l]) * ((BoneWeight)(ref val2)).weight3;
						ref bool reference4 = ref array5[l];
						reference4 |= array3[((BoneWeight)(ref val2)).boneIndex3];
					}
					array4[l] = val3;
				}
				for (int m = 0; m + 2 < triangles.Length; m += 3)
				{
					int num2 = triangles[m];
					int num3 = triangles[m + 1];
					int num4 = triangles[m + 2];
					if (array5[num2] || array5[num3] || array5[num4])
					{
						continue;
					}
					tris++;
					for (int n = 0; n < pts.Length; n++)
					{
						Vector3 val4 = array4[num2] - pts[n];
						if (!(((Vector3)(ref val4)).sqrMagnitude > 0.040000003f))
						{
							float num5 = PointTri(pts[n], array4[num2], array4[num3], array4[num4]);
							if (num5 < array[n])
							{
								array[n] = num5;
							}
						}
					}
				}
			}
			return array;
		}

		private static IEnumerator ChainEnds(Player p, string tag, int row, string pose)
		{
			yield return (object)new WaitForEndOfFrame();
			ChainRope[] array = new ChainRope[4];
			ChainRope[] componentsInChildren = ((Component)p).GetComponentsInChildren<ChainRope>(true);
			foreach (ChainRope chainRope in componentsInChildren)
			{
				if ((Object)(object)chainRope != (Object)null && chainRope.Running && chainRope.Loop >= 0 && chainRope.Loop < 4)
				{
					array[chainRope.Loop] = chainRope;
				}
			}
			Vector3[] array2 = (Vector3[])(object)new Vector3[8];
			bool[] array3 = new bool[8];
			int num = 0;
			float num2 = 1f;
			for (int j = 0; j < 4; j++)
			{
				for (int k = 0; k < 2; k++)
				{
					if ((Object)(object)array[j] != (Object)null)
					{
						array2[j * 2 + k] = array[j].EndAnchor(k);
						array3[j * 2 + k] = true;
						num2 = array[j].Unit;
						num++;
					}
				}
			}
			if (num == 0)
			{
				Log("chain ends " + tag + " " + pose, ok: false, "no hip loop is running");
				yield break;
			}
			string text = "";
			float num3 = 0f;
			int num4 = 0;
			float[] array4;
			int tris;
			try
			{
				array4 = ToOutfit(p, array2, out tris);
			}
			catch (Exception ex)
			{
				Log("chain ends " + tag + " " + pose, ok: false, "could not measure: " + ex.Message);
				array4 = null;
				tris = 0;
			}
			Vector3 val;
			if (array4 != null)
			{
				for (int l = 0; l < 8; l++)
				{
					if (!array3[l])
					{
						text = text + " | " + LoopNames[l / 2] + " " + ((l % 2 == 0) ? "front" : "back") + ": no loop";
						continue;
					}
					float num5 = array4[l] / num2 * 1000f;
					val = array[l / 2].EndNode(l % 2) - array2[l];
					float num6 = ((Vector3)(ref val)).magnitude / num2 * 1000f;
					float num7 = ((l == 1 || l == 5) ? 14f : 10f);
					if (num5 >= num7 || num6 >= 10f)
					{
						num4++;
					}
					num3 = Mathf.Max(num3, Mathf.Max(num5, num6));
					text += string.Format(" | {0} {1}: anchor {2:0.0} mm from the outfit, end link {3:0.0} mm from the anchor", LoopNames[l / 2], (l % 2 == 0) ? "front" : "back", num5, num6);
				}
				Log("chain ends " + tag + " " + pose, num == 8 && num4 == 0, $"{num} of 8 ends, {num4} over their limit (10 mm, upper back ends 14 mm), worst {num3:0.0} mm, against {tris} outfit triangles{text}");
			}
			if ((Object)(object)_endsTex == (Object)null)
			{
				_endsTex = new Texture2D(3200, 1600, (TextureFormat)3, false);
				Color32[] array5 = (Color32[])(object)new Color32[5120000];
				for (int m = 0; m < array5.Length; m++)
				{
					array5[m] = new Color32((byte)40, (byte)40, (byte)40, byte.MaxValue);
				}
				_endsTex.SetPixels32(array5);
			}
			RenderTexture rt;
			Camera val2 = TestCam(ortho: true, 0.1f, 400, 400, out rt);
			int num8 = PlayerMask(p);
			if (num8 != 0)
			{
				val2.cullingMask = num8;
			}
			val2.nearClipPlane = 2f - 0.15f * num2;
			val2.farClipPlane = 4f;
			Transform transform = ((Component)p).transform;
			Transform val3 = Bone(p, "Hips");
			HideOthers(p, num8, transform.position + Vector3.up);
			for (int n = 0; n < 8; n++)
			{
				if (!array3[n])
				{
					continue;
				}
				Vector3 val4 = array2[n];
				float num9 = (((Object)(object)val3 != (Object)null && Vector3.Dot(val4 - val3.position, transform.right) < 0f) ? (-1f) : 1f);
				float num10 = ((n % 2 == 0) ? 1f : (-1f));
				for (int num11 = 0; num11 < 2; num11++)
				{
					Vector3 val5 = ((num11 == 0) ? new Vector3(0f, 0.12f, num10) : new Vector3(num9, 0.2f, num10 * 0.55f));
					bool flag = row == 1 && num11 == 0 && (n == 2 || n == 6);
					if (flag)
					{
						((Vector3)(ref val5))..ctor(num9, 0.35f, -0.15f);
					}
					val2.nearClipPlane = 2f - (flag ? 0.09f : 0.15f) * num2;
					val = transform.right * val5.x + Vector3.up * val5.y + transform.forward * val5.z;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					((Component)val2).transform.position = val4 + normalized * 2f;
					((Component)val2).transform.rotation = Quaternion.LookRotation(-normalized, Vector3.up);
					val2.Render();
					RenderTexture.active = rt;
					_endsTex.ReadPixels(new Rect(0f, 0f, 400f, 400f), n * 400, (3 - (row * 2 + num11)) * 400);
					RenderTexture.active = null;
				}
			}
			ShowOthers();
			val2.targetTexture = null;
			Object.Destroy((Object)(object)rt);
			Object.Destroy((Object)(object)((Component)val2).gameObject);
			if (row == 1)
			{
				_endsTex.Apply();
				byte[] array6 = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("EncodeToJPG", new Type[2]
				{
					typeof(Texture2D),
					typeof(int)
				})?.Invoke(null, new object[2] { _endsTex, 90 }) as byte[];
				if (array6 != null)
				{
					File.WriteAllBytes(Path.Combine(Dir, "chains_ends_" + tag + ".jpg"), array6);
				}
				Logger.LogInfo((object)$"YULE TEST: picture chains_ends_{tag}.jpg {((Texture)_endsTex).width}x{((Texture)_endsTex).height}, {((array6 != null) ? (array6.Length / 1024) : 0)} KB");
				Object.Destroy((Object)(object)_endsTex);
				_endsTex = null;
			}
			yield return null;
		}

		private static void Save(Texture2D tex, string name)
		{
			tex.Apply();
			if (Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("EncodeToPNG", new Type[1] { typeof(Texture2D) })?.Invoke(null, new object[1] { tex }) is byte[] bytes)
			{
				File.WriteAllBytes(Path.Combine(Dir, "armor_" + name + ".png"), bytes);
			}
		}

		private static void HideOthers(Player p, int mask, Vector3 centre)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			_hidden.Clear();
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			foreach (Renderer val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.enabled && !val.forceRenderingOff && (mask & (1 << ((Component)val).gameObject.layer)) != 0 && !((Component)val).transform.IsChildOf(((Component)p).transform))
				{
					Bounds bounds = val.bounds;
					Vector3 val2 = ((Bounds)(ref bounds)).ClosestPoint(centre) - centre;
					if (!(((Vector3)(ref val2)).sqrMagnitude > 3600f))
					{
						val.forceRenderingOff = true;
						_hidden.Add(val);
					}
				}
			}
		}

		private static void ShowOthers()
		{
			foreach (Renderer item in _hidden)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.forceRenderingOff = false;
				}
			}
			_hidden.Clear();
		}

		private static Camera TestCam(bool ortho, float size, int w, int h, out RenderTexture rt)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			Camera val = new GameObject("YuleTestCam").AddComponent<Camera>();
			val.orthographic = ortho;
			if (ortho)
			{
				val.orthographicSize = size;
			}
			else
			{
				val.fieldOfView = size;
			}
			val.nearClipPlane = 0.05f;
			val.farClipPlane = 50f;
			val.clearFlags = (CameraClearFlags)2;
			val.backgroundColor = new Color(0.55f, 0.6f, 0.68f);
			rt = new RenderTexture(w, h, 24);
			val.targetTexture = rt;
			return val;
		}

		private static int PlayerMask(Player p)
		{
			int num = 0;
			Renderer[] componentsInChildren = ((Component)p).GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				num |= 1 << ((Component)val).gameObject.layer;
			}
			return num;
		}

		private static IEnumerator Third(Player p, string name)
		{
			yield return (object)new WaitForEndOfFrame();
			RenderTexture rt;
			Camera val = TestCam(ortho: false, 65f, 800, 800, out rt);
			Texture2D val2 = new Texture2D(2400, 800, (TextureFormat)3, false);
			int num = PlayerMask(p);
			if (num != 0)
			{
				val.cullingMask = num;
			}
			Transform transform = ((Component)p).transform;
			Transform val3 = Bone(p, "Head");
			Vector3 val4 = (((Object)(object)val3 != (Object)null) ? val3.position : (transform.position + Vector3.up * 1.6f));
			Vector3 val5 = val4 - Vector3.up * 0.45f;
			Vector3[] array = (Vector3[])(object)new Vector3[3]
			{
				new Vector3(0f, 0.36f, -1f),
				new Vector3(0.7f, 0.25f, 1f),
				new Vector3(1f, 0.2f, 0.05f)
			};
			HideOthers(p, num, val4);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val6 = transform.right * array[i].x + Vector3.up * array[i].y + transform.forward * array[i].z;
				Vector3 normalized = ((Vector3)(ref val6)).normalized;
				((Component)val).transform.position = val4 + normalized * 4f;
				((Component)val).transform.rotation = Quaternion.LookRotation(val5 - ((Component)val).transform.position, Vector3.up);
				val.Render();
				RenderTexture.active = rt;
				val2.ReadPixels(new Rect(0f, 0f, 800f, 800f), i * 800, 0);
				RenderTexture.active = null;
			}
			ShowOthers();
			Save(val2, name);
			val.targetTexture = null;
			Object.Destroy((Object)(object)rt);
			Object.Destroy((Object)(object)val2);
			Object.Destroy((Object)(object)((Component)val).gameObject);
			yield return null;
		}

		private static IEnumerator JumpClose(Player p, string name, string bone = "Hips", float size = 0.6f, float gap = 0.07f)
		{
			RenderTexture rt;
			Camera cam = TestCam(ortho: true, size, 400, 400, out rt);
			Texture2D tex = new Texture2D(3200, 800, (TextureFormat)3, false);
			int mask = PlayerMask(p);
			if (mask != 0)
			{
				cam.cullingMask = mask;
			}
			Transform t = ((Component)p).transform;
			Transform b = Bone(p, bone);
			for (int i = 0; i < 8; i++)
			{
				yield return (object)new WaitForEndOfFrame();
				Vector3 val = (((Object)(object)b != (Object)null) ? b.position : (t.position + Vector3.up)) - Vector3.up * 0.1f;
				HideOthers(p, mask, val);
				for (int j = 0; j < 2; j++)
				{
					Vector3 val2;
					Vector3 normalized;
					if (j != 0)
					{
						val2 = t.right * 0.6f + Vector3.up * 0.12f + t.forward;
						normalized = ((Vector3)(ref val2)).normalized;
					}
					else
					{
						val2 = Vector3.up * 0.06f + t.forward;
						normalized = ((Vector3)(ref val2)).normalized;
					}
					Vector3 val3 = normalized;
					((Component)cam).transform.position = val + val3 * 4f;
					((Component)cam).transform.rotation = Quaternion.LookRotation(-val3, Vector3.up);
					cam.Render();
					RenderTexture.active = rt;
					tex.ReadPixels(new Rect(0f, 0f, 400f, 400f), i * 400, (1 - j) * 400);
					RenderTexture.active = null;
				}
				ShowOthers();
				yield return (object)new WaitForSeconds(gap);
			}
			Save(tex, name);
			cam.targetTexture = null;
			Object.Destroy((Object)(object)rt);
			Object.Destroy((Object)(object)tex);
			Object.Destroy((Object)(object)((Component)cam).gameObject);
			yield return null;
		}

		private static IEnumerator Sequence(Player p, string name)
		{
			RenderTexture rt;
			Camera cam = TestCam(ortho: true, 0.75f, 400, 400, out rt);
			Texture2D tex = new Texture2D(3200, 400, (TextureFormat)3, false);
			int mask = PlayerMask(p);
			if (mask != 0)
			{
				cam.cullingMask = mask;
			}
			Transform t = ((Component)p).transform;
			Transform hips = Bone(p, "Hips");
			for (int i = 0; i < 8; i++)
			{
				yield return (object)new WaitForEndOfFrame();
				Vector3 val = (((Object)(object)hips != (Object)null) ? hips.position : (t.position + Vector3.up)) + Vector3.up * 0.05f;
				Vector3 val2 = t.right * 0.8f + Vector3.up * 0.15f + t.forward * 1f;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				HideOthers(p, mask, val);
				((Component)cam).transform.position = val + normalized * 4f;
				((Component)cam).transform.rotation = Quaternion.LookRotation(-normalized, Vector3.up);
				cam.Render();
				RenderTexture.active = rt;
				tex.ReadPixels(new Rect(0f, 0f, 400f, 400f), i * 400, 0);
				RenderTexture.active = null;
				ShowOthers();
				yield return (object)new WaitForSeconds(0.1f);
			}
			Save(tex, name);
			cam.targetTexture = null;
			Object.Destroy((Object)(object)rt);
			Object.Destroy((Object)(object)tex);
			Object.Destroy((Object)(object)((Component)cam).gameObject);
			yield return null;
		}
	}
	internal static class SelfTestDecor
	{
		[HarmonyPatch(typeof(Player), "SetControls")]
		private static class ControlsPatch
		{
			private static void Prefix(Player __instance, ref Vector3 movedir, ref bool run, ref bool autoRun, ref bool jump, ref bool attack, ref bool crouch)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				if (_drive && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					movedir = _move;
					run = _run;
					autoRun = false;
					jump = false;
					attack = false;
					crouch = false;
				}
			}
		}

		private static readonly string[] Ground = new string[5] { "YuleSnowman", "YuleTree", "YuleNutcracker", "YuleNutcrackerViking", "YuleLanternPost" };

		private static readonly string[] Feet = new string[3] { "YuleSnowman", "YuleNutcracker", "YuleNutcrackerViking" };

		private static readonly string[] Walls = new string[5] { "YuleStocking", "YuleStockingStag", "YuleStockingSnowflake", "YuleStockingTree", "YuleWreath" };

		private const string Mistletoe = "YuleMistletoe";

		private static readonly string[] Hanging = new string[2] { "YuleMistletoe", "YuleLanternHang" };

		private static bool _drive;

		private static bool _run;

		private static Vector3 _move;

		private static Camera _cam;

		private static RenderTexture _rt;

		private const int Tile = 600;

		private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");

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

		private static readonly int BuildMask = LayerMask.GetMask(new string[6] { "piece", "piece_nonsolid", "static_solid", "Default_small", "Default", "vehicle" });

		private static string Dir => Path.Combine(Path.Combine(Paths.BepInExRootPath, "yuletide_selftest"), "decor");

		private static void Log(string what, bool ok, string detail)
		{
			Logger.LogInfo((object)("YULE TEST " + (ok ? "PASS" : "FAIL") + " " + what + ": " + detail));
		}

		private static void Info(string what)
		{
			Logger.LogInfo((object)("YULE DECOR " + what));
		}

		private static string V(Vector3 v)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return $"({v.x:0.00},{v.y:0.00},{v.z:0.00})";
		}

		private static string Key(string prefab)
		{
			if (!prefab.StartsWith("Yule"))
			{
				return prefab;
			}
			return prefab.Substring(4);
		}

		public static IEnumerator Run(Player p)
		{
			Directory.CreateDirectory(Dir);
			p.SetGhostMode(true);
			int num = 0;
			foreach (Character item in Character.GetAllCharacters().ToList())
			{
				if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)p) && !item.IsPlayer() && !(Vector3.Distance(((Component)item).transform.position, ((Component)p).transform.position) > 80f))
				{
					ZNetView component = ((Component)item).GetComponent<ZNetView>();
					if ((Object)(object)component != (Object)null && component.IsValid())
					{
						component.ClaimOwnership();
						component.Destroy();
						num++;
					}
				}
			}
			Info($"{num} creatures near the character removed");
			if ((Object)(object)EnvMan.instance != (Object)null)
			{
				EnvMan.instance.SetForceEnvironment("Clear");
				EnvMan.instance.SetDebugWind(0f, 0f);
			}
			SetTime(0.5f);
			yield return (object)new WaitForSeconds(3f);
			Vector3 position = ((Component)p).transform.position;
			Vector3 forward = ((Component)p).transform.forward;
			forward.y = 0f;
			((Vector3)(ref forward)).Normalize();
			Vector3 sfwd;
			Vector3 spot = FindSpot(position, forward, out sfwd);
			Vector3 right = Vector3.Cross(Vector3.up, sfwd);
			Info("home " + V(position) + ", test spot " + V(spot) + ", facing " + V(sfwd));
			AuditHammer();
			yield return IconSheet();
			string[] ground = Ground;
			foreach (string name in ground)
			{
				GameObject piece = Spawn(name, AtGround(spot), Quaternion.LookRotation(-sfwd));
				yield return Check(p, name, piece, -sfwd);
				if (Feet.Contains(name) && (Object)(object)piece != (Object)null)
				{
					yield return OnGround(p, name, piece, -sfwd);
				}
				if (name == "YuleTree" && (Object)(object)piece != (Object)null)
				{
					yield return Twinkle(p, piece, -sfwd);
				}
				if (name == "YuleNutcrackerViking" && (Object)(object)piece != (Object)null)
				{
					yield return Lanterns(p, piece, -sfwd);
				}
				if (name == "YuleLanternPost" && (Object)(object)piece != (Object)null)
				{
					yield return LanternSwing(name, piece);
				}
				Clear();
				yield return (object)new WaitForSeconds(0.5f);
			}
			ground = Walls;
			foreach (string name in ground)
			{
				GameObject piece = Scaffold("woodwall", spot, Quaternion.LookRotation(-sfwd));
				yield return (object)new WaitForSeconds(0.5f);
				GameObject val = null;
				Vector3 val2 = -sfwd;
				if ((Object)(object)piece != (Object)null && HitOn(piece, spot + Vector3.up * 1.2f - sfwd * 2.5f, sfwd, 4f, out var hit))
				{
					val2 = ((RaycastHit)(ref hit)).normal;
					val2.y = 0f;
					((Vector3)(ref val2)).Normalize();
					val = OnWall(name, ((RaycastHit)(ref hit)).point, val2);
				}
				else
				{
					Log("decor " + name, ok: false, "no wall to hang it on");
				}
				if ((Object)(object)val != (Object)null)
				{
					yield return Check(p, name, val, val2);
				}
				Clear();
				yield return (object)new WaitForSeconds(0.5f);
			}
			ground = Hanging;
			foreach (string name in ground)
			{
				GameObject piece = Beam(spot, sfwd, right);
				yield return (object)new WaitForSeconds(0.5f);
				GameObject piece2 = null;
				if ((Object)(object)piece != (Object)null && HitOn(piece, spot + Vector3.up * 0.4f, Vector3.up, 4f, out var hit2))
				{
					piece2 = Spawn(name, ((RaycastHit)(ref hit2)).point, Quaternion.LookRotation(-sfwd));
					Info($"{name}: hung at {V(((RaycastHit)(ref hit2)).point)} ({((RaycastHit)(ref hit2)).point.y - GroundY(((RaycastHit)(ref hit2)).point):0.00} m above the ground)");
				}
				else
				{
					Log("decor " + name, ok: false, "no beam to hang it under");
				}
				if ((Object)(object)piece2 != (Object)null)
				{
					yield return Check(p, name, piece2, -sfwd);
					if (name == "YuleMistletoe")
					{
						yield return Sway(p, piece2, sfwd, right);
					}
					else
					{
						yield return LanternSwing(name, piece2);
					}
				}
				Clear();
				yield return (object)new WaitForSeconds(0.5f);
			}
			if ((Object)(object)EnvMan.instance != (Object)null)
			{
				EnvMan.instance.SetForceEnvironment("");
				EnvMan.instance.ResetDebugWind();
				EnvMan.instance.m_debugTimeOfDay = false;
			}
			p.SetGhostMode(false);
			if ((Object)(object)_cam != (Object)null)
			{
				_cam.targetTexture = null;
				Object.Destroy((Object)(object)_rt);
				Object.Destr