Decompiled source of ItemEnhancements v1.0.2

plugins/Valheim.ItemEnhancements/Valheim.ItemEnhancements.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Valheim.ItemEnhancements.Configuration;
using Valheim.ItemEnhancements.Core;
using Valheim.ItemEnhancements.UI;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Valheim.ItemEnhancements")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+02201869cbb3e1356f4b1931d01a778af3c07532")]
[assembly: AssemblyProduct("Valheim.ItemEnhancements")]
[assembly: AssemblyTitle("Valheim.ItemEnhancements")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Valheim.ItemEnhancements
{
	[BepInPlugin("ckforgame.ItemEnhancements", "ItemEnhancements", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "ckforgame.ItemEnhancements";

		public const string ModName = "ItemEnhancements";

		public const string ModVersion = "1.0.2";

		private Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Paths.ConfigPath, "com.customs.valheim.itemenhancements.cfg");
			string text2 = Path.Combine(Paths.ConfigPath, "ckforgame.ItemEnhancements.cfg");
			if (File.Exists(text) && !File.Exists(text2))
			{
				try
				{
					File.Copy(text, text2);
					Log.LogInfo((object)("Migrated old configuration from '" + text + "' to '" + text2 + "'."));
					((BaseUnityPlugin)this).Config.Reload();
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Failed to migrate old configuration: " + ex.Message));
				}
			}
			ModConfig.Initialize(((BaseUnityPlugin)this).Config);
			GameObject val = new GameObject("Valheim_ItemEnhancement_GUI");
			val.AddComponent<EnhancementGui>();
			Object.DontDestroyOnLoad((Object)val);
			_harmony = new Harmony("ckforgame.ItemEnhancements");
			try
			{
				_harmony.PatchAll();
				Log.LogInfo((object)"[ItemEnhancements] Successfully loaded and patched all methods!");
			}
			catch (Exception arg)
			{
				Log.LogError((object)string.Format("[{0}] Harmony Patching failed: {1}", "ItemEnhancements", arg));
			}
		}

		private void Update()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !TextInput.IsVisible() && Input.GetKeyDown(ModConfig.ToggleGuiKey.Value))
			{
				EnhancementGui.Toggle();
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace Valheim.ItemEnhancements.UI
{
	public class EnhancementGui : MonoBehaviour
	{
		private static readonly Func<List<CraftingStation>> s_getAllStations = CreateStaticFieldGetter<List<CraftingStation>>(typeof(CraftingStation), "m_allStations");

		private static readonly FieldRef<GameCamera, bool> s_mouseCaptureRef = AccessTools.FieldRefAccess<GameCamera, bool>("m_mouseCapture");

		private Rect _windowRect = new Rect((float)Screen.width / 2f - 340f, (float)Screen.height / 2f - 335f, 680f, 670f);

		private ItemData _selectedItem;

		private Vector2 _scrollPosition = Vector2.zero;

		private readonly List<ItemData> _cachedEnhanceableItems = new List<ItemData>();

		private bool _isEnhanceablesDirty = true;

		private float _stationCheckTimer;

		private int _pickerCategory;

		private bool _isForging;

		private float _forgeTimer;

		private const float ForgeDuration = 0.75f;

		private string _lastResultMessage = "";

		private string _lastResultColor = "#ffffff";

		private GUIStyle _windowStyle;

		private GUIStyle _headerStyle;

		private GUIStyle _subHeaderStyle;

		private GUIStyle _statLabelStyle;

		private GUIStyle _statValueCurrentStyle;

		private GUIStyle _statValueNextStyle;

		private GUIStyle _statArrowStyle;

		private GUIStyle _boxSectionStyle;

		private GUIStyle _actionButtonStyle;

		private GUIStyle _itemButtonStyle;

		private GUIStyle _rateNumberStyle;

		private GUIStyle _statusBoxStyle;

		private GUIStyle _statusTextStyle;

		private GUIStyle _meterTextStyle;

		private GUIStyle _tabButtonStyle;

		private GUIStyle _tabButtonActiveStyle;

		private Texture2D _texWindowBg;

		private Texture2D _texBoxBg;

		private Texture2D _texButtonNormal;

		private Texture2D _texButtonHover;

		private Texture2D _texButtonActive;

		private Texture2D _texButtonDisabled;

		private Texture2D _texScrollbarTrack;

		private Texture2D _texScrollbarThumb;

		private Texture2D _texScrollbarThumbHover;

		private Texture2D _texStatusBg;

		private Texture2D _texMeterBg;

		private Texture2D _texWhite;

		private Texture2D _texTabNormal;

		private Texture2D _texTabActive;

		public static EnhancementGui Instance { get; private set; }

		public static bool IsOpen { get; set; } = false;

		public static bool IsMouseOverWindow
		{
			get
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				if (!IsOpen || (Object)(object)Instance == (Object)null)
				{
					return false;
				}
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y);
				return ((Rect)(ref Instance._windowRect)).Contains(val);
			}
		}

		private static Func<T> CreateStaticFieldGetter<T>(Type type, string fieldName)
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(type, fieldName);
				if (fieldInfo == null)
				{
					return () => default(T);
				}
				return Expression.Lambda<Func<T>>(Expression.Field(null, fieldInfo), Array.Empty<ParameterExpression>()).Compile();
			}
			catch
			{
				return () => default(T);
			}
		}

		private void Awake()
		{
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			CreateTextures();
		}

		private void UpdateWindowDimensions()
		{
			float num = Mathf.Min((float)Screen.height - 40f, 760f);
			float height = Mathf.Clamp(670f, 400f, num);
			float width = Mathf.Min((float)Screen.width - 40f, 680f);
			((Rect)(ref _windowRect)).width = width;
			((Rect)(ref _windowRect)).height = height;
			float num2 = Mathf.Max(10f, (float)Screen.width - ((Rect)(ref _windowRect)).width - 10f);
			float num3 = Mathf.Max(10f, (float)Screen.height - ((Rect)(ref _windowRect)).height - 10f);
			((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 10f, num2);
			((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 10f, num3);
		}

		private void OnDisable()
		{
			if (IsOpen)
			{
				Close();
			}
		}

		public static bool IsNearCraftingStation()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			if (!ModConfig.RequireCraftingStation.Value)
			{
				return true;
			}
			if ((Object)(object)Player.m_localPlayer.GetCurrentCraftingStation() != (Object)null)
			{
				return true;
			}
			List<CraftingStation> list = s_getAllStations?.Invoke();
			if (list != null)
			{
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				float value = ModConfig.CraftingStationRange.Value;
				float num = value * value;
				for (int i = 0; i < list.Count; i++)
				{
					CraftingStation val = list[i];
					if ((Object)(object)val != (Object)null)
					{
						Vector3 val2 = ((Component)val).transform.position - position;
						if (((Vector3)(ref val2)).sqrMagnitude <= num)
						{
							return true;
						}
					}
				}
			}
			return false;
		}

		public static void Toggle()
		{
			if (IsOpen)
			{
				Close();
			}
			else
			{
				Open();
			}
		}

		public static void Open()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			if (ModConfig.RequireCraftingStation.Value && !IsNearCraftingStation())
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, "<color=#f59e0b>Must be near a crafting station or forge to enhance items!</color>", 0, (Sprite)null, false);
				return;
			}
			IsOpen = true;
			if ((Object)(object)Instance != (Object)null)
			{
				Instance._lastResultMessage = "";
				Instance._isEnhanceablesDirty = true;
				Instance._scrollPosition = Vector2.zero;
				Instance.UpdateWindowDimensions();
				if (Instance._selectedItem == null)
				{
					EnhancementGui instance = Instance;
					Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
					instance._selectedItem = ((inventory == null) ? null : inventory.GetEquippedItems()?.Find(EnhancementManager.IsEnhanceable));
				}
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			ZCursor.LockState = (CursorLockMode)0;
			ZCursor.Show();
			if ((Object)(object)InventoryGui.instance != (Object)null)
			{
				AccessTools.Method(typeof(InventoryGui), "SetupDragItem", new Type[3]
				{
					typeof(ItemData),
					typeof(Inventory),
					typeof(int)
				}, (Type[])null)?.Invoke(InventoryGui.instance, new object[3] { null, null, 0 });
			}
		}

		public static void Close(bool forceLockCursorIfNoMenu = false)
		{
			IsOpen = false;
			if ((Object)(object)Instance != (Object)null)
			{
				Instance._isForging = false;
				Instance._forgeTimer = 0f;
			}
			if ((Object)(object)GameCamera.instance != (Object)null && s_mouseCaptureRef != null)
			{
				s_mouseCaptureRef.Invoke(GameCamera.instance) = true;
			}
			bool flag = false;
			if (!forceLockCursorIfNoMenu)
			{
				flag = ((Object)(object)InventoryGui.instance != (Object)null && InventoryGui.IsVisible()) || ((Object)(object)StoreGui.instance != (Object)null && StoreGui.IsVisible());
			}
			if ((Object)(object)Menu.instance != (Object)null && (Menu.IsVisible() || Menu.IsActive()))
			{
				flag = true;
			}
			if (TextInput.IsVisible())
			{
				flag = true;
			}
			if (!flag)
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
				ZCursor.LockState = (CursorLockMode)1;
				ZCursor.Hide();
			}
		}

		public static void SetSelectedItem(ItemData item)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance != (Object)null && Instance._selectedItem != item)
			{
				Instance._selectedItem = item;
				Instance._lastResultMessage = "";
				Instance._isEnhanceablesDirty = true;
				Instance._scrollPosition = Vector2.zero;
			}
		}

		private bool CanEnhanceSelectedItem()
		{
			if (_selectedItem == null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			if (ModConfig.RequireCraftingStation.Value && !IsNearCraftingStation())
			{
				return false;
			}
			int enhancementLevel = EnhancementManager.GetEnhancementLevel(_selectedItem);
			if (enhancementLevel >= 20)
			{
				return false;
			}
			int targetLevel = enhancementLevel + 1;
			return EnhancementManager.CanAfford(Player.m_localPlayer, targetLevel);
		}

		private void Update()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen)
			{
				return;
			}
			if ((int)Cursor.lockState != 0 || !Cursor.visible)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			if ((int)ZCursor.LockState != 0)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
			if (_isForging)
			{
				_forgeTimer -= Time.deltaTime;
				if (_forgeTimer <= 0f)
				{
					_isForging = false;
					ExecuteEnhancement();
				}
			}
			if (!_isForging && _selectedItem != null && CanEnhanceSelectedItem() && (Input.GetKeyDown((KeyCode)32) || Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271)))
			{
				StartForging();
			}
			_stationCheckTimer -= Time.deltaTime;
			if (_stationCheckTimer <= 0f)
			{
				_stationCheckTimer = 0.25f;
				if (ModConfig.RequireCraftingStation.Value && (Object)(object)Player.m_localPlayer != (Object)null && !IsNearCraftingStation())
				{
					Close();
				}
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				Close();
			}
		}

		private void OnGUI()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//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)
			if (IsOpen && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				InitStyles();
				UpdateWindowDimensions();
				_windowRect = GUI.Window(987654, _windowRect, new WindowFunction(DrawWindowContent), "", _windowStyle);
			}
		}

		private void DrawWindowContent(int windowID)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Invalid comparison between Unknown and I4
			if ((int)Event.current.type == 6)
			{
				_scrollPosition.y += Event.current.delta.y * 35f;
				if (_scrollPosition.y < 0f)
				{
					_scrollPosition.y = 0f;
				}
				Event.current.Use();
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("✦  MMORPG ITEM ENHANCEMENT  ✦", _headerStyle, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("✕", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(32f),
				GUILayout.Height(26f)
			}))
			{
				Close();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			DrawItemSelectionArea();
			GUILayout.Space(6f);
			if (_selectedItem != null && EnhancementManager.IsEnhanceable(_selectedItem))
			{
				_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, false, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.ExpandWidth(true),
					GUILayout.ExpandHeight(true)
				});
				DrawStatsComparison();
				GUILayout.Space(8f);
				DrawRulesAndCostSection();
				GUILayout.EndScrollView();
				GUILayout.Space(8f);
				DrawActionButtonSection();
			}
			else
			{
				DrawEquipmentPickerList();
			}
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width - 45f, 35f));
			if (Event.current.isMouse && ((int)Event.current.type == 0 || (int)Event.current.type == 1))
			{
				Event.current.Use();
			}
		}

		private void DrawItemSelectionArea()
		{
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(_boxSectionStyle, Array.Empty<GUILayoutOption>());
			if (_selectedItem != null)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(_selectedItem);
				string tierHex = EnhancementManager.GetTierHex(enhancementLevel);
				string tierRankName = EnhancementManager.GetTierRankName(enhancementLevel);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				string text = ((Localization.instance != null) ? Localization.instance.Localize(_selectedItem.m_shared.m_name) : _selectedItem.m_shared.m_name);
				string text2 = (_selectedItem.m_equipped ? " <color=#38bdf8>[Equipped]</color>" : "");
				GUILayout.Label($"<b>Target:</b> <color={tierHex}><b>{text} +{enhancementLevel}</b></color> <color=#94a3b8>({tierRankName})</color>{text2}", _subHeaderStyle, Array.Empty<GUILayoutOption>());
				GUILayout.FlexibleSpace();
				if (GUILayout.Button("Change Item", _itemButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(130f),
					GUILayout.Height(26f)
				}))
				{
					_selectedItem = null;
					_lastResultMessage = "";
					_scrollPosition = Vector2.zero;
				}
				GUILayout.EndHorizontal();
			}
			else
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("<color=#ffd700>Select an item to enhance from the list below or click an item in your inventory.</color>", _subHeaderStyle, Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
		}

		private void DrawStatsComparison()
		{
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Invalid comparison between Unknown and I4
			int enhancementLevel = EnhancementManager.GetEnhancementLevel(_selectedItem);
			int num = enhancementLevel + 1;
			bool flag = enhancementLevel >= 20;
			GUILayout.BeginVertical(_boxSectionStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label("<b>Stat Progression:</b>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(4f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Current: <color={EnhancementManager.GetTierHex(enhancementLevel)}><b>+{enhancementLevel}</b></color>", _statValueCurrentStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(225f) });
			GUILayout.Label("➔", _statArrowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(25f) });
			if (!flag)
			{
				GUILayout.Label($"Next: <color={EnhancementManager.GetTierHex(num)}><b>+{num}</b></color>", _statValueNextStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			}
			else
			{
				GUILayout.Label("<color=#ffd700><b>★ MAX LEVEL ★</b></color>", _statValueNextStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			if (IsWeapon(_selectedItem))
			{
				float cumulativeAbilityValue = YamlConfigManager.GetCumulativeAbilityValue("WeaponDamage", enhancementLevel);
				float cumulativeAbilityValue2 = YamlConfigManager.GetCumulativeAbilityValue("WeaponDamage", num);
				float num2 = cumulativeAbilityValue2 - cumulativeAbilityValue;
				string arg = ((cumulativeAbilityValue <= 0f && cumulativeAbilityValue2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num2:F0}%)</color>");
				DrawStatRow("All Damage:", $"+{cumulativeAbilityValue:F0}%", flag ? "-" : $"+{cumulativeAbilityValue2:F0}% {arg}");
				float num3 = StatCalculator.GetAttackStaminaReduction(enhancementLevel) * 100f;
				float num4 = StatCalculator.GetAttackStaminaReduction(num) * 100f;
				float num5 = num4 - num3;
				string arg2 = ((num3 <= 0f && num4 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(-{num5:F0}%)</color>");
				DrawStatRow("Attack Stamina Cost:", $"-{num3:F0}%", flag ? "-" : $"-{num4:F0}% {arg2}");
				float num6 = StatCalculator.GetAttackEitrReduction(enhancementLevel) * 100f;
				float num7 = StatCalculator.GetAttackEitrReduction(num) * 100f;
				if (num6 > 0f || num7 > 0f || (_selectedItem.m_shared.m_attack != null && _selectedItem.m_shared.m_attack.m_attackEitr > 0f))
				{
					float num8 = num7 - num6;
					string arg3 = ((num6 <= 0f && num7 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(-{num8:F0}%)</color>");
					DrawStatRow("Attack Eitr Cost:", $"-{num6:F0}%", flag ? "-" : $"-{num7:F0}% {arg3}");
				}
				float backstabBonus = StatCalculator.GetBackstabBonus(enhancementLevel);
				float backstabBonus2 = StatCalculator.GetBackstabBonus(num);
				if (backstabBonus > 0f || backstabBonus2 > 0f || _selectedItem.m_shared.m_backstabBonus > 1f)
				{
					float num9 = backstabBonus2 - backstabBonus;
					string arg4 = ((backstabBonus <= 0f && backstabBonus2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num9:F2}x)</color>");
					DrawStatRow("Backstab Multiplier:", $"+{backstabBonus:F2}x", flag ? "-" : $"+{backstabBonus2:F2}x {arg4}");
				}
			}
			if (IsArmor(_selectedItem))
			{
				float armor = _selectedItem.GetArmor();
				float armorBonus = StatCalculator.GetArmorBonus(_selectedItem, num, _selectedItem.m_shared.m_armor);
				float armorBonus2 = StatCalculator.GetArmorBonus(_selectedItem, enhancementLevel, _selectedItem.m_shared.m_armor);
				float num10 = armorBonus - armorBonus2;
				string arg5 = ((armorBonus2 <= 0f && armorBonus > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num10:F1})</color>");
				DrawStatRow("Armor:", $"{armor:F1}", flag ? "-" : $"{armor + num10:F1} {arg5}");
				float num11 = StatCalculator.GetMovementModifierDelta(_selectedItem, enhancementLevel) * 100f;
				float num12 = StatCalculator.GetMovementModifierDelta(_selectedItem, num) * 100f;
				float num13 = num12 - num11;
				string arg6 = ((num11 <= 0f && num12 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(+{num13:F1}%)</color>");
				DrawStatRow("Movement Speed Bonus:", $"+{num11:F1}%", flag ? "-" : $"+{num12:F1}% {arg6}");
				float num14 = StatCalculator.GetEitrRegenBonus(enhancementLevel) * 100f;
				float num15 = StatCalculator.GetEitrRegenBonus(num) * 100f;
				if (num14 > 0f || num15 > 0f || _selectedItem.m_shared.m_eitrRegenModifier > 0f)
				{
					float num16 = num15 - num14;
					string arg7 = ((num14 <= 0f && num15 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(+{num16:F0}%)</color>");
					DrawStatRow("Eitr Regeneration:", $"+{num14:F0}%", flag ? "-" : $"+{num15:F0}% {arg7}");
				}
			}
			if ((int)_selectedItem.m_shared.m_itemType == 5)
			{
				float blockPower = _selectedItem.GetBlockPower(((Character)Player.m_localPlayer).GetSkillFactor((SkillType)6));
				float blockPowerBonus = StatCalculator.GetBlockPowerBonus(_selectedItem, enhancementLevel, _selectedItem.m_shared.m_blockPower);
				float blockPowerBonus2 = StatCalculator.GetBlockPowerBonus(_selectedItem, num, _selectedItem.m_shared.m_blockPower);
				float num17 = blockPowerBonus2 - blockPowerBonus;
				string arg8 = ((blockPowerBonus <= 0f && blockPowerBonus2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num17:F1})</color>");
				DrawStatRow("Block Power:", $"{blockPower:F1}", flag ? "-" : $"{blockPower + num17:F1} {arg8}");
				float num18 = StatCalculator.GetBlockStaminaReduction(enhancementLevel) * 100f;
				float num19 = StatCalculator.GetBlockStaminaReduction(num) * 100f;
				float num20 = num19 - num18;
				string arg9 = ((num18 <= 0f && num19 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(-{num20:F1}%)</color>");
				DrawStatRow("Block Stamina Cost:", $"-{num18:F0}%", flag ? "-" : $"-{num19:F0}% {arg9}");
				float timedBlockBonus = StatCalculator.GetTimedBlockBonus(enhancementLevel);
				float timedBlockBonus2 = StatCalculator.GetTimedBlockBonus(num);
				if (timedBlockBonus > 0f || timedBlockBonus2 > 0f)
				{
					float num21 = timedBlockBonus2 - timedBlockBonus;
					string arg10 = ((timedBlockBonus <= 0f && timedBlockBonus2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num21:F2}x)</color>");
					DrawStatRow("Parry Bonus:", $"+{timedBlockBonus:F2}x", flag ? "-" : $"+{timedBlockBonus2:F2}x {arg10}");
				}
			}
			if (StatCalculator.IsAccessory(_selectedItem))
			{
				float carryWeightBonus = StatCalculator.GetCarryWeightBonus(_selectedItem, enhancementLevel);
				float carryWeightBonus2 = StatCalculator.GetCarryWeightBonus(_selectedItem, num);
				if (carryWeightBonus > 0f || carryWeightBonus2 > 0f)
				{
					float num22 = carryWeightBonus2 - carryWeightBonus;
					string arg11 = ((carryWeightBonus <= 0f && carryWeightBonus2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num22:F0})</color>");
					DrawStatRow("Max Carry Weight:", $"+{carryWeightBonus:F0}", flag ? "-" : $"+{carryWeightBonus2:F0} {arg11}");
				}
				float armorBonus3 = StatCalculator.GetArmorBonus(_selectedItem, enhancementLevel, _selectedItem.m_shared.m_armor);
				float armorBonus4 = StatCalculator.GetArmorBonus(_selectedItem, num, _selectedItem.m_shared.m_armor);
				if (armorBonus3 > 0f || armorBonus4 > 0f)
				{
					float num23 = armorBonus4 - armorBonus3;
					string arg12 = ((armorBonus3 <= 0f && armorBonus4 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num23:F1})</color>");
					DrawStatRow("Armor Bonus:", $"+{armorBonus3:F1}", flag ? "-" : $"+{armorBonus4:F1} {arg12}");
				}
				float num24 = StatCalculator.GetEitrRegenBonus(enhancementLevel) * 100f;
				float num25 = StatCalculator.GetEitrRegenBonus(num) * 100f;
				if (num24 > 0f || num25 > 0f)
				{
					float num26 = num25 - num24;
					string arg13 = ((num24 <= 0f && num25 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(+{num26:F0}%)</color>");
					DrawStatRow("Eitr Regeneration:", $"+{num24:F0}%", flag ? "-" : $"+{num25:F0}% {arg13}");
				}
			}
			float maxDurability = _selectedItem.GetMaxDurability();
			float durabilityBonus = StatCalculator.GetDurabilityBonus(_selectedItem, enhancementLevel, _selectedItem.m_shared.m_maxDurability);
			float durabilityBonus2 = StatCalculator.GetDurabilityBonus(_selectedItem, num, _selectedItem.m_shared.m_maxDurability);
			float num27 = durabilityBonus2 - durabilityBonus;
			string arg14 = ((durabilityBonus <= 0f && durabilityBonus2 > 0f) ? "<color=#4ade80>(Unlocked!)</color>" : $"<color=#4ade80>(+{num27:F0})</color>");
			DrawStatRow("Max Durability:", $"{maxDurability:F0}", flag ? "-" : $"{maxDurability + num27:F0} {arg14}");
			float num28 = (1f - StatCalculator.GetWeightMultiplier(enhancementLevel)) * 100f;
			float num29 = (1f - StatCalculator.GetWeightMultiplier(num)) * 100f;
			if (num28 > 0f || num29 > 0f)
			{
				float num30 = num29 - num28;
				string arg15 = ((num28 <= 0f && num29 > 0f) ? "<color=#38bdf8>(Unlocked!)</color>" : $"<color=#38bdf8>(-{num30:F0}%)</color>");
				DrawStatRow("Weight Reduction:", $"-{num28:F0}%", flag ? "-" : $"-{num29:F0}% {arg15}");
			}
			if (StatCalculator.IsCheatEnabled)
			{
				float cheatItemMaxHealth = StatCalculator.GetCheatItemMaxHealth(_selectedItem, enhancementLevel);
				float cheatItemMaxHealth2 = StatCalculator.GetCheatItemMaxHealth(_selectedItem, num);
				if (cheatItemMaxHealth > 0f || cheatItemMaxHealth2 > 0f)
				{
					float num31 = cheatItemMaxHealth2 - cheatItemMaxHealth;
					string arg16 = ((cheatItemMaxHealth <= 0f && cheatItemMaxHealth2 > 0f) ? "<color=#fb7185>(Unlocked!)</color>" : $"<color=#fb7185>(+{num31:F0})</color>");
					DrawStatRow("<color=#fb7185>★ [Cheat] Max HP:</color>", $"+{cheatItemMaxHealth:F0}", flag ? "-" : $"+{cheatItemMaxHealth2:F0} {arg16}");
				}
				float cheatItemMaxStamina = StatCalculator.GetCheatItemMaxStamina(_selectedItem, enhancementLevel);
				float cheatItemMaxStamina2 = StatCalculator.GetCheatItemMaxStamina(_selectedItem, num);
				if (cheatItemMaxStamina > 0f || cheatItemMaxStamina2 > 0f)
				{
					float num32 = cheatItemMaxStamina2 - cheatItemMaxStamina;
					string arg17 = ((cheatItemMaxStamina <= 0f && cheatItemMaxStamina2 > 0f) ? "<color=#fb7185>(Unlocked!)</color>" : $"<color=#fb7185>(+{num32:F0})</color>");
					DrawStatRow("<color=#fb7185>★ [Cheat] Max Stamina:</color>", $"+{cheatItemMaxStamina:F0}", flag ? "-" : $"+{cheatItemMaxStamina2:F0} {arg17}");
				}
				float cheatItemMaxEitr = StatCalculator.GetCheatItemMaxEitr(_selectedItem, enhancementLevel);
				float cheatItemMaxEitr2 = StatCalculator.GetCheatItemMaxEitr(_selectedItem, num);
				if (cheatItemMaxEitr > 0f || cheatItemMaxEitr2 > 0f)
				{
					float num33 = cheatItemMaxEitr2 - cheatItemMaxEitr;
					string arg18 = ((cheatItemMaxEitr <= 0f && cheatItemMaxEitr2 > 0f) ? "<color=#fb7185>(Unlocked!)</color>" : $"<color=#fb7185>(+{num33:F0})</color>");
					DrawStatRow("<color=#fb7185>★ [Cheat] Max Eitr:</color>", $"+{cheatItemMaxEitr:F0}", flag ? "-" : $"+{cheatItemMaxEitr2:F0} {arg18}");
				}
				float num34 = StatCalculator.GetCheatItemHealthRegen(_selectedItem, enhancementLevel) * 100f;
				float num35 = StatCalculator.GetCheatItemHealthRegen(_selectedItem, num) * 100f;
				if (num34 > 0f || num35 > 0f)
				{
					float num36 = num35 - num34;
					string arg19 = ((num34 <= 0f && num35 > 0f) ? "<color=#fb7185>(Unlocked!)</color>" : $"<color=#fb7185>(+{num36:F0}%)</color>");
					DrawStatRow("<color=#fb7185>★ [Cheat] HP Regen:</color>", $"+{num34:F0}%", flag ? "-" : $"+{num35:F0}% {arg19}");
				}
				float num37 = StatCalculator.GetCheatItemStaminaRegen(_selectedItem, enhancementLevel) * 100f;
				float num38 = StatCalculator.GetCheatItemStaminaRegen(_selectedItem, num) * 100f;
				if (num37 > 0f || num38 > 0f)
				{
					float num39 = num38 - num37;
					string arg20 = ((num37 <= 0f && num38 > 0f) ? "<color=#fb7185>(Unlocked!)</color>" : $"<color=#fb7185>(+{num39:F0}%)</color>");
					DrawStatRow("<color=#fb7185>★ [Cheat] Stamina Regen:</color>", $"+{num37:F0}%", flag ? "-" : $"+{num38:F0}% {arg20}");
				}
			}
			GUILayout.EndVertical();
		}

		private void DrawStatRow(string label, string currentVal, string nextVal)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, _statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(225f) });
			GUILayout.Label(currentVal, _statValueCurrentStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
			GUILayout.Label("➔", _statArrowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(25f) });
			GUILayout.Label(nextVal, _statValueNextStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			GUILayout.EndHorizontal();
		}

		private void DrawRulesAndCostSection()
		{
			//IL_0097: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			int enhancementLevel = EnhancementManager.GetEnhancementLevel(_selectedItem);
			int num = enhancementLevel + 1;
			bool num2 = enhancementLevel >= 20;
			GUILayout.BeginVertical(_boxSectionStyle, Array.Empty<GUILayoutOption>());
			if (num2)
			{
				GUILayout.Label("<color=#ffd700><b>★ This item has reached maximum enhancement level (+20 MAX) ★</b></color>", _headerStyle, Array.Empty<GUILayoutOption>());
				GUILayout.EndVertical();
				return;
			}
			float successRate = ModConfig.GetSuccessRate(num);
			Color fillColor = ((successRate >= 70f) ? new Color(0.29f, 0.87f, 0.5f) : ((successRate >= 40f) ? new Color(0.96f, 0.62f, 0.04f) : new Color(0.94f, 0.27f, 0.27f)));
			string arg = ((successRate >= 70f) ? "#4ade80" : ((successRate >= 40f) ? "#f59e0b" : "#ef4444"));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(270f) });
			GUILayout.Label("<b>Success Probability:</b>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(2f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"<color={arg}><b>{successRate:F0}%</b></color>", _rateNumberStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(75f) });
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			DrawProgressBar(successRate / 100f, fillColor, "", 12f);
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUILayout.Space(12f);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label("<b>Failure Penalty:</b>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(2f);
			if (enhancementLevel < ModConfig.SafeLevel.Value)
			{
				GUILayout.Label("<color=#4ade80><b>\ud83d\udee1 100% Protected (Safe Level)</b></color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label("<color=#94a3b8>Level will not decrease. Item cannot break.</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			else if (ModConfig.BreakOnFail.Value)
			{
				GUILayout.Label("<color=#ef4444><b>⚠ High Risk: Downgrade or Destroy</b></color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label($"<color=#f87171>Break Chance: {ModConfig.BreakChanceAboveSafeLevel.Value:F0}%  •  Otherwise: -1 Level</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			else if (ModConfig.DowngradeOnFail.Value)
			{
				GUILayout.Label("<color=#f59e0b><b>⚠ Moderate Risk: Downgrade on Fail</b></color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label($"<color=#fbbf24>Level will decrease: +{enhancementLevel} ➔ +{enhancementLevel - 1}</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label("<color=#4ade80><b>✔ Safe - Level remains unchanged</b></color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.Space(8f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(_boxSectionStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (ModConfig.RequireScrolls.Value)
			{
				int requiredScrollTier = EnhancementManager.GetRequiredScrollTier(num);
				string scrollDisplayName = ScrollItemManager.GetScrollDisplayName(requiredScrollTier);
				int value = ModConfig.ScrollsRequiredPerAttempt.Value;
				int playerScrollCount = EnhancementManager.GetPlayerScrollCount(Player.m_localPlayer, requiredScrollTier);
				bool flag = playerScrollCount >= value;
				string text = (flag ? "#4ade80" : "#ef4444");
				string tierHex = EnhancementManager.GetTierHex(num);
				GUILayout.Label("<b>Required Scroll:</b> <color=" + tierHex + ">" + scrollDisplayName + "</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				string text2 = (flag ? "<color=#4ade80>✔ Ready</color>" : $"<color=#ef4444>(Need {value - playerScrollCount} more)</color>");
				GUILayout.Label($"<b>Inventory:</b> <color={text}><b>{playerScrollCount}</b> / {value}</color>  {text2}", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label("<b>Required Scroll:</b> <color=#4ade80>None (Free)</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUILayout.Space(6f);
			GUILayout.BeginVertical(_boxSectionStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (ModConfig.RequireCoins.Value)
			{
				int coinCost = ModConfig.GetCoinCost(num);
				int playerCoins = EnhancementManager.GetPlayerCoins(Player.m_localPlayer);
				bool num3 = playerCoins >= coinCost;
				string text3 = (num3 ? "#ffd700" : "#ef4444");
				string text4 = (num3 ? "<color=#4ade80>✔ Ready</color>" : $"<color=#ef4444>(Need {coinCost - playerCoins} more)</color>");
				GUILayout.Label($"<b>Enhancement Fee:</b> <color={text3}>{coinCost} Coins</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label($"<b>Inventory:</b> <color={text3}><b>{playerCoins}</b> / {coinCost}</color>  {text4}", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label("<b>Enhancement Fee:</b> <color=#4ade80>Free (No coins)</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label("<b>Status:</b> <color=#4ade80>✔ Ready</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		private void DrawActionButtonSection()
		{
			int enhancementLevel = EnhancementManager.GetEnhancementLevel(_selectedItem);
			int num = enhancementLevel + 1;
			bool isMax = enhancementLevel >= 20;
			int requiredScrollTier = EnhancementManager.GetRequiredScrollTier(num);
			int value = ModConfig.ScrollsRequiredPerAttempt.Value;
			int playerScrollCount = EnhancementManager.GetPlayerScrollCount(Player.m_localPlayer, requiredScrollTier);
			bool hasScrolls = !ModConfig.RequireScrolls.Value || playerScrollCount >= value;
			int coinCost = ModConfig.GetCoinCost(num);
			int playerCoins = EnhancementManager.GetPlayerCoins(Player.m_localPlayer);
			bool hasCoins = !ModConfig.RequireCoins.Value || playerCoins >= coinCost;
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(98f) });
			DrawStatusCard(enhancementLevel, num, isMax, hasScrolls, requiredScrollTier, playerScrollCount, value, hasCoins, coinCost, playerCoins);
			GUILayout.Space(6f);
			DrawEnhanceButton(num, isMax, hasScrolls, requiredScrollTier, playerScrollCount, value, hasCoins, coinCost, playerCoins);
			GUILayout.EndVertical();
		}

		private void DrawStatusCard(int currentLvl, int nextLvl, bool isMax, bool hasScrolls, int scrollTier, int playerScrolls, int neededScrolls, bool hasCoins, int cost, int playerCoins)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(_statusBoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) });
			if (_isForging)
			{
				float num = Mathf.Clamp01(1f - _forgeTimer / 0.75f);
				int num2 = Mathf.RoundToInt(num * 100f);
				GUILayout.Label($"<color=#ffd700><b>\ud83d\udd28  Forging on Anvil... ({num2}%)  \ud83d\udd28</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(2f);
				DrawProgressBar(num, new Color(1f, 0.85f, 0.25f, 0.9f), "", 6f);
			}
			else if (!string.IsNullOrEmpty(_lastResultMessage))
			{
				GUILayout.Label("<color=" + _lastResultColor + "><b>" + _lastResultMessage + "</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
			}
			else if (isMax)
			{
				GUILayout.Label("<color=#ffd700><b>★ Item has reached maximum enhancement level (+20 DIVINE) ★</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
			}
			else if (!hasScrolls)
			{
				int num3 = neededScrolls - playerScrolls;
				string scrollDisplayName = ScrollItemManager.GetScrollDisplayName(scrollTier);
				GUILayout.Label($"<color=#f87171><b>❌ Missing Materials: Need {num3} more {scrollDisplayName}</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
			}
			else if (!hasCoins)
			{
				int num4 = cost - playerCoins;
				GUILayout.Label($"<color=#fbbf24><b>❌ Insufficient Coins: Need {num4} more coins</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label($"<color=#38bdf8><b>⚡ Ready to enhance to +{nextLvl}  •  Click below or press [Space / Enter]</b></color>", _statusTextStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
		}

		private void DrawEnhanceButton(int nextLvl, bool isMax, bool hasScrolls, int scrollTier, int playerScrolls, int neededScrolls, bool hasCoins, int cost, int playerCoins)
		{
			if (_isForging)
			{
				GUI.enabled = false;
				int num = Mathf.RoundToInt(Mathf.Clamp01(1f - _forgeTimer / 0.75f) * 100f);
				GUILayout.Button($"\ud83d\udd28  FORGING... ({num}%)  \ud83d\udd28", _actionButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f) });
				GUI.enabled = true;
			}
			else if (isMax)
			{
				GUI.enabled = false;
				GUILayout.Button("★  MAX LEVEL REACHED (+20)  ★", _actionButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f) });
				GUI.enabled = true;
			}
			else if (!hasScrolls)
			{
				GUI.enabled = false;
				string scrollDisplayName = ScrollItemManager.GetScrollDisplayName(scrollTier);
				GUILayout.Button($"❌  Requires [{scrollDisplayName}] ({playerScrolls}/{neededScrolls})  ❌", _actionButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f) });
				GUI.enabled = true;
			}
			else if (!hasCoins)
			{
				GUI.enabled = false;
				GUILayout.Button($"❌  Insufficient Coins (Requires {cost}, Have {playerCoins})  ❌", _actionButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f) });
				GUI.enabled = true;
			}
			else if (GUILayout.Button($"⚡  ENHANCE TO +{nextLvl}  ⚡", _actionButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f) }))
			{
				StartForging();
			}
		}

		private void DrawProgressBar(float progress, Color fillColor, string overlayText = "", float height = 14f)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = GUILayoutUtility.GetRect(0f, ((Rect)(ref _windowRect)).width, height, height, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if ((Object)(object)_texMeterBg != (Object)null)
			{
				GUI.DrawTexture(rect, (Texture)(object)_texMeterBg);
			}
			float num = Mathf.Clamp01(progress);
			if (num > 0.001f && (Object)(object)_texWhite != (Object)null)
			{
				Rect val = new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, (((Rect)(ref rect)).width - 2f) * num, ((Rect)(ref rect)).height - 2f);
				Color color = GUI.color;
				GUI.color = fillColor;
				GUI.DrawTexture(val, (Texture)(object)_texWhite);
				GUI.color = color;
			}
			if (!string.IsNullOrEmpty(overlayText) && _meterTextStyle != null)
			{
				GUI.Label(rect, overlayText, _meterTextStyle);
			}
		}

		private void StartForging()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (_selectedItem == null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			object obj;
			if (!((Object)(object)InventoryGui.instance != (Object)null) || !InventoryGui.instance.IsContainerOpen())
			{
				obj = null;
			}
			else
			{
				InventoryGrid containerGrid = InventoryGui.instance.ContainerGrid;
				obj = ((containerGrid != null) ? containerGrid.GetInventory() : null);
			}
			Inventory val = (Inventory)obj;
			if ((inventory == null || !inventory.ContainsItem(_selectedItem)) && (val == null || !val.ContainsItem(_selectedItem)))
			{
				_selectedItem = null;
				_lastResultColor = "#ef4444";
				_lastResultMessage = "Item not found in inventory!";
				return;
			}
			_isForging = true;
			_forgeTimer = 0.75f;
			if ((Object)(object)InventoryGui.instance != (Object)null && InventoryGui.instance.m_craftItemEffects != null)
			{
				InventoryGui.instance.m_craftItemEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
		}

		private void ExecuteEnhancement()
		{
			//IL_01b5: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			if (_selectedItem == null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			object obj;
			if (!((Object)(object)InventoryGui.instance != (Object)null) || !InventoryGui.instance.IsContainerOpen())
			{
				obj = null;
			}
			else
			{
				InventoryGrid containerGrid = InventoryGui.instance.ContainerGrid;
				obj = ((containerGrid != null) ? containerGrid.GetInventory() : null);
			}
			Inventory val = (Inventory)obj;
			if ((inventory == null || !inventory.ContainsItem(_selectedItem)) && (val == null || !val.ContainsItem(_selectedItem)))
			{
				_selectedItem = null;
				_lastResultColor = "#ef4444";
				_lastResultMessage = "Item not found in inventory!";
				return;
			}
			string text = ((Localization.instance != null) ? Localization.instance.Localize(_selectedItem.m_shared.m_name) : _selectedItem.m_shared.m_name);
			int newLevel;
			switch (EnhancementManager.TryEnhance(Player.m_localPlayer, _selectedItem, out newLevel))
			{
			case EnhanceResult.Success:
				if (InventoryGui.instance?.m_craftItemDoneEffects != null)
				{
					InventoryGui.instance.m_craftItemDoneEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
				_lastResultColor = "#ffd700";
				_lastResultMessage = $"★ Enhancement Successful! {text} is now +{newLevel} ★";
				((Character)Player.m_localPlayer).Message((MessageType)2, $"<color=#ffd700>★ Enhancement Successful! {text} (+{newLevel}) ★</color>", 0, (Sprite)null, false);
				break;
			case EnhanceResult.FailedSafe:
			{
				CraftingStation currentCraftingStation2 = Player.m_localPlayer.GetCurrentCraftingStation();
				if (currentCraftingStation2 != null)
				{
					EffectList repairItemDoneEffects2 = currentCraftingStation2.m_repairItemDoneEffects;
					if (repairItemDoneEffects2 != null)
					{
						repairItemDoneEffects2.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
					}
				}
				_lastResultColor = "#94a3b8";
				_lastResultMessage = $"\ud83d\udee1 Safe Attempt: Level remained unchanged (+{newLevel})";
				((Character)Player.m_localPlayer).Message((MessageType)2, $"<color=#94a3b8>\ud83d\udee1 Safe: Level Remained (+{newLevel})</color>", 0, (Sprite)null, false);
				break;
			}
			case EnhanceResult.FailedDowngraded:
			{
				CraftingStation currentCraftingStation3 = Player.m_localPlayer.GetCurrentCraftingStation();
				if (currentCraftingStation3 != null)
				{
					EffectList repairItemDoneEffects3 = currentCraftingStation3.m_repairItemDoneEffects;
					if (repairItemDoneEffects3 != null)
					{
						repairItemDoneEffects3.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
					}
				}
				_lastResultColor = "#f59e0b";
				_lastResultMessage = $"⚠ Enhancement Failed! Item downgraded to +{newLevel}";
				((Character)Player.m_localPlayer).Message((MessageType)2, $"<color=#f59e0b>⚠ Enhancement Failed! Downgraded to +{newLevel}</color>", 0, (Sprite)null, false);
				break;
			}
			case EnhanceResult.FailedBroken:
			{
				CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
				if (currentCraftingStation != null)
				{
					EffectList repairItemDoneEffects = currentCraftingStation.m_repairItemDoneEffects;
					if (repairItemDoneEffects != null)
					{
						repairItemDoneEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
					}
				}
				_lastResultColor = "#ef4444";
				_lastResultMessage = "☠ Enhancement Failed! " + text + " was destroyed! ☠";
				((Character)Player.m_localPlayer).Message((MessageType)2, "<color=#ef4444>☠ Enhancement Failed! " + text + " destroyed! ☠</color>", 0, (Sprite)null, false);
				_selectedItem = null;
				break;
			}
			case EnhanceResult.CannotAfford:
				_lastResultColor = "#ef4444";
				_lastResultMessage = "Insufficient enhancement materials or coins!";
				break;
			}
			_isEnhanceablesDirty = true;
			if ((Object)(object)InventoryGui.instance != (Object)null)
			{
				AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", (Type[])null, (Type[])null)?.Invoke(InventoryGui.instance, new object[1] { false });
			}
		}

		private void RefreshEnhanceablesList()
		{
			_cachedEnhanceableItems.Clear();
			if ((Object)(object)Player.m_localPlayer != (Object)null && ((Humanoid)Player.m_localPlayer).GetInventory() != null)
			{
				List<ItemData> allItems = ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems();
				if (allItems != null)
				{
					for (int i = 0; i < allItems.Count; i++)
					{
						ItemData val = allItems[i];
						if (val != null && EnhancementManager.IsEnhanceable(val))
						{
							_cachedEnhanceableItems.Add(val);
						}
					}
					_cachedEnhanceableItems.Sort(delegate(ItemData a, ItemData b)
					{
						if (a.m_equipped != b.m_equipped)
						{
							return b.m_equipped.CompareTo(a.m_equipped);
						}
						int enhancementLevel = EnhancementManager.GetEnhancementLevel(a);
						int enhancementLevel2 = EnhancementManager.GetEnhancementLevel(b);
						if (enhancementLevel != enhancementLevel2)
						{
							return enhancementLevel2.CompareTo(enhancementLevel);
						}
						string strA = ((Localization.instance != null) ? Localization.instance.Localize(a.m_shared.m_name) : a.m_shared.m_name);
						string strB = ((Localization.instance != null) ? Localization.instance.Localize(b.m_shared.m_name) : b.m_shared.m_name);
						return string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase);
					});
				}
			}
			_isEnhanceablesDirty = false;
		}

		private bool MatchesCategory(ItemData item, int category)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			if (item?.m_shared == null)
			{
				return false;
			}
			return category switch
			{
				1 => IsWeapon(item), 
				2 => IsArmor(item), 
				3 => (int)item.m_shared.m_itemType == 5, 
				4 => StatCalculator.IsAccessory(item), 
				_ => true, 
			};
		}

		private void DrawEquipmentPickerList()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(_boxSectionStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			if (_isEnhanceablesDirty)
			{
				RefreshEnhanceablesList();
			}
			int count = _cachedEnhanceableItems.Count;
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			for (int i = 0; i < _cachedEnhanceableItems.Count; i++)
			{
				ItemData val = _cachedEnhanceableItems[i];
				if (IsWeapon(val))
				{
					num++;
				}
				else if (IsArmor(val))
				{
					num2++;
				}
				else if ((int)val.m_shared.m_itemType == 5)
				{
					num3++;
				}
				else if (StatCalculator.IsAccessory(val))
				{
					num4++;
				}
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button($"All ({count})", (_pickerCategory == 0) ? _tabButtonActiveStyle : _tabButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				_pickerCategory = 0;
				_scrollPosition = Vector2.zero;
			}
			if (GUILayout.Button($"⚔ Weapons ({num})", (_pickerCategory == 1) ? _tabButtonActiveStyle : _tabButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				_pickerCategory = 1;
				_scrollPosition = Vector2.zero;
			}
			if (GUILayout.Button($"\ud83d\udee1 Armor ({num2})", (_pickerCategory == 2) ? _tabButtonActiveStyle : _tabButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				_pickerCategory = 2;
				_scrollPosition = Vector2.zero;
			}
			if (GUILayout.Button($"\ud83d\udd30 Shields ({num3})", (_pickerCategory == 3) ? _tabButtonActiveStyle : _tabButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				_pickerCategory = 3;
				_scrollPosition = Vector2.zero;
			}
			if (GUILayout.Button($"\ud83d\udc8d Accessories ({num4})", (_pickerCategory == 4) ? _tabButtonActiveStyle : _tabButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				_pickerCategory = 4;
				_scrollPosition = Vector2.zero;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			List<ItemData> list = new List<ItemData>();
			for (int j = 0; j < _cachedEnhanceableItems.Count; j++)
			{
				ItemData item = _cachedEnhanceableItems[j];
				if (MatchesCategory(item, _pickerCategory))
				{
					list.Add(item);
				}
			}
			if (list.Count == 0)
			{
				GUILayout.Space(20f);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.FlexibleSpace();
				GUILayout.Label("<color=#94a3b8>No equipment found matching this category in your inventory.</color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
				GUILayout.FlexibleSpace();
			}
			else
			{
				_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, false, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.ExpandWidth(true),
					GUILayout.ExpandHeight(true)
				});
				for (int k = 0; k < list.Count; k++)
				{
					ItemData val2 = list[k];
					if (val2 != null)
					{
						int enhancementLevel = EnhancementManager.GetEnhancementLevel(val2);
						string tierHex = EnhancementManager.GetTierHex(enhancementLevel);
						string tierRankName = EnhancementManager.GetTierRankName(enhancementLevel);
						string text = ((Localization.instance != null) ? Localization.instance.Localize(val2.m_shared.m_name) : val2.m_shared.m_name);
						GUILayout.BeginHorizontal(_boxSectionStyle, Array.Empty<GUILayoutOption>());
						string text2 = (val2.m_equipped ? " <color=#38bdf8><b>[Equipped]</b></color>" : "");
						GUILayout.Label($"<b>{text}</b> <color={tierHex}>+{enhancementLevel}</color> <color=#94a3b8>({tierRankName})</color>{text2}", _statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(460f) });
						if (GUILayout.Button("⚡ Select", _itemButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.Width(130f),
							GUILayout.Height(24f)
						}))
						{
							_selectedItem = val2;
							_lastResultMessage = "";
							_isEnhanceablesDirty = true;
							_scrollPosition = Vector2.zero;
						}
						GUILayout.EndHorizontal();
						GUILayout.Space(2f);
					}
				}
				GUILayout.EndScrollView();
			}
			GUILayout.Space(4f);
			GUILayout.Label("<color=#64748b>\ud83d\udca1 <i>Tip: You can also left-click or right-click any equipment in your inventory to select it directly.</i></color>", _statLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
		}

		private bool IsWeapon(ItemData item)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			if (item?.m_shared == null)
			{
				return false;
			}
			if ((int)item.m_shared.m_itemType != 3 && (int)item.m_shared.m_itemType != 14 && (int)item.m_shared.m_itemType != 22)
			{
				return (int)item.m_shared.m_itemType == 4;
			}
			return true;
		}

		private bool IsArmor(ItemData item)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			if (item?.m_shared == null)
			{
				return false;
			}
			if ((int)item.m_shared.m_itemType != 6 && (int)item.m_shared.m_itemType != 7 && (int)item.m_shared.m_itemType != 11)
			{
				return (int)item.m_shared.m_itemType == 17;
			}
			return true;
		}

		private void InitStyles()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Expected O, but got Unknown
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Expected O, but got Unknown
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Expected O, but got Unknown
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Expected O, but got Unknown
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Expected O, but got Unknown
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Expected O, but got Unknown
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Expected O, but got Unknown
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Expected O, but got Unknown
			//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			if (_windowStyle == null)
			{
				_windowStyle = new GUIStyle(GUI.skin.window);
				_windowStyle.normal.background = _texWindowBg;
				_windowStyle.padding = new RectOffset(16, 16, 14, 16);
				_headerStyle = new GUIStyle(GUI.skin.label);
				_headerStyle.fontSize = 17;
				_headerStyle.fontStyle = (FontStyle)1;
				_headerStyle.alignment = (TextAnchor)4;
				_headerStyle.normal.textColor = new Color(1f, 0.85f, 0.2f);
				_subHeaderStyle = new GUIStyle(GUI.skin.label);
				_subHeaderStyle.fontSize = 14;
				_subHeaderStyle.normal.textColor = Color.white;
				_statLabelStyle = new GUIStyle(GUI.skin.label);
				_statLabelStyle.fontSize = 13;
				_statLabelStyle.normal.textColor = new Color(0.85f, 0.88f, 0.92f);
				_statValueCurrentStyle = new GUIStyle(GUI.skin.label);
				_statValueCurrentStyle.fontSize = 13;
				_statValueCurrentStyle.normal.textColor = new Color(0.7f, 0.75f, 0.8f);
				_statValueNextStyle = new GUIStyle(GUI.skin.label);
				_statValueNextStyle.fontSize = 13;
				_statValueNextStyle.fontStyle = (FontStyle)1;
				_statValueNextStyle.normal.textColor = new Color(0.3f, 0.9f, 0.5f);
				_statArrowStyle = new GUIStyle(GUI.skin.label);
				_statArrowStyle.fontSize = 13;
				_statArrowStyle.alignment = (TextAnchor)4;
				_statArrowStyle.normal.textColor = new Color(0.6f, 0.65f, 0.7f);
				_boxSectionStyle = new GUIStyle(GUI.skin.box);
				_boxSectionStyle.normal.background = _texBoxBg;
				_boxSectionStyle.padding = new RectOffset(12, 12, 10, 10);
				_actionButtonStyle = new GUIStyle(GUI.skin.button);
				_actionButtonStyle.normal.background = _texButtonNormal;
				_actionButtonStyle.hover.background = _texButtonHover;
				_actionButtonStyle.active.background = _texButtonActive;
				_actionButtonStyle.fontSize = 16;
				_actionButtonStyle.fontStyle = (FontStyle)1;
				_actionButtonStyle.normal.textColor = new Color(1f, 0.9f, 0.3f);
				_actionButtonStyle.hover.textColor = Color.white;
				_itemButtonStyle = new GUIStyle(GUI.skin.button);
				_itemButtonStyle.fontSize = 12;
				_rateNumberStyle = new GUIStyle(GUI.skin.label);
				_rateNumberStyle.fontSize = 28;
				_rateNumberStyle.fontStyle = (FontStyle)1;
				_rateNumberStyle.alignment = (TextAnchor)3;
				_statusBoxStyle = new GUIStyle(GUI.skin.box);
				_statusBoxStyle.normal.background = _texStatusBg;
				_statusBoxStyle.padding = new RectOffset(10, 10, 8, 8);
				_statusBoxStyle.alignment = (TextAnchor)4;
				_statusTextStyle = new GUIStyle(GUI.skin.label);
				_statusTextStyle.fontSize = 13;
				_statusTextStyle.fontStyle = (FontStyle)1;
				_statusTextStyle.alignment = (TextAnchor)4;
				_statusTextStyle.normal.textColor = Color.white;
				_statusTextStyle.wordWrap = false;
				_statusTextStyle.clipping = (TextClipping)1;
				_meterTextStyle = new GUIStyle(GUI.skin.label);
				_meterTextStyle.fontSize = 10;
				_meterTextStyle.fontStyle = (FontStyle)1;
				_meterTextStyle.alignment = (TextAnchor)4;
				_meterTextStyle.normal.textColor = Color.white;
				_tabButtonStyle = new GUIStyle(GUI.skin.button);
				_tabButtonStyle.normal.background = _texTabNormal;
				_tabButtonStyle.fontSize = 12;
				_tabButtonStyle.normal.textColor = new Color(0.6f, 0.64f, 0.72f);
				_tabButtonStyle.hover.textColor = new Color(0.9f, 0.92f, 0.96f);
				_tabButtonActiveStyle = new GUIStyle(GUI.skin.button);
				_tabButtonActiveStyle.normal.background = _texTabActive;
				_tabButtonActiveStyle.fontStyle = (FontStyle)1;
				_tabButtonActiveStyle.fontSize = 12;
				_tabButtonActiveStyle.normal.textColor = new Color(1f, 0.95f, 0.4f);
				_tabButtonActiveStyle.hover.textColor = new Color(1f, 1f, 0.7f);
				_itemButtonStyle = new GUIStyle(GUI.skin.button);
				_itemButtonStyle.normal.background = _texButtonNormal;
				_itemButtonStyle.hover.background = _texButtonHover;
				_itemButtonStyle.active.background = _texButtonActive;
				_itemButtonStyle.fontSize = 12;
				_itemButtonStyle.fontStyle = (FontStyle)1;
				_itemButtonStyle.normal.textColor = new Color(1f, 0.9f, 0.35f);
				_itemButtonStyle.hover.textColor = Color.white;
				if (GUI.skin.verticalScrollbar != null)
				{
					GUI.skin.verticalScrollbar.normal.background = _texScrollbarTrack;
					GUI.skin.verticalScrollbar.fixedWidth = 12f;
				}
				if (GUI.skin.verticalScrollbarThumb != null)
				{
					GUI.skin.verticalScrollbarThumb.normal.background = _texScrollbarThumb;
					GUI.skin.verticalScrollbarThumb.hover.background = _texScrollbarThumbHover;
					GUI.skin.verticalScrollbarThumb.active.background = _texScrollbarThumbHover;
					GUI.skin.verticalScrollbarThumb.fixedWidth = 12f;
				}
			}
		}

		private void CreateTextures()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			_texWindowBg = MakeBorderedTexture(16, 16, new Color(0.1f, 0.11f, 0.14f, 0.96f), new Color(0.7f, 0.55f, 0.2f, 1f));
			_texBoxBg = MakeBorderedTexture(16, 16, new Color(0.15f, 0.17f, 0.22f, 0.9f), new Color(0.28f, 0.32f, 0.4f, 0.8f));
			_texButtonNormal = MakeBorderedTexture(16, 16, new Color(0.25f, 0.18f, 0.08f, 1f), new Color(0.85f, 0.65f, 0.15f, 1f));
			_texButtonHover = MakeBorderedTexture(16, 16, new Color(0.4f, 0.28f, 0.1f, 1f), new Color(1f, 0.85f, 0.3f, 1f));
			_texButtonActive = MakeBorderedTexture(16, 16, new Color(0.55f, 0.38f, 0.12f, 1f), new Color(1f, 0.95f, 0.5f, 1f));
			_texButtonDisabled = MakeBorderedTexture(16, 16, new Color(0.18f, 0.18f, 0.2f, 0.8f), new Color(0.3f, 0.3f, 0.35f, 0.6f));
			_texScrollbarTrack = MakeBorderedTexture(12, 12, new Color(0.08f, 0.09f, 0.12f, 0.9f), new Color(0.22f, 0.24f, 0.3f, 0.7f));
			_texScrollbarThumb = MakeBorderedTexture(12, 12, new Color(0.55f, 0.4f, 0.12f, 0.95f), new Color(0.85f, 0.65f, 0.2f, 1f));
			_texScrollbarThumbHover = MakeBorderedTexture(12, 12, new Color(0.75f, 0.55f, 0.18f, 1f), new Color(1f, 0.85f, 0.35f, 1f));
			_texStatusBg = MakeBorderedTexture(16, 16, new Color(0.12f, 0.14f, 0.19f, 0.95f), new Color(0.35f, 0.4f, 0.5f, 0.9f));
			_texMeterBg = MakeBorderedTexture(12, 12, new Color(0.08f, 0.09f, 0.12f, 0.95f), new Color(0.25f, 0.28f, 0.35f, 0.8f));
			_texWhite = MakeSolidTexture(2, 2, Color.white);
			_texTabNormal = MakeBorderedTexture(12, 12, new Color(0.11f, 0.12f, 0.15f, 0.88f), new Color(0.22f, 0.24f, 0.3f, 0.6f));
			_texTabActive = MakeBorderedTexture(12, 12, new Color(0.35f, 0.24f, 0.08f, 0.98f), new Color(0.95f, 0.75f, 0.2f, 1f));
		}

		private Texture2D MakeSolidTexture(int width, int height, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//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)
			Texture2D val = new Texture2D(width, height);
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private Texture2D MakeBorderedTexture(int width, int height, Color background, Color border)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height);
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					if (j == 0 || i == 0 || j == width - 1 || i == height - 1)
					{
						array[i * width + j] = border;
					}
					else
					{
						array[i * width + j] = background;
					}
				}
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}
	}
}
namespace Valheim.ItemEnhancements.Patches
{
	public static class CharacterDropPatches
	{
		[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
		public static class CharacterDrop_GenerateDropList_Patch
		{
			public static void Postfix(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result)
			{
				if (!((Object)(object)__instance == (Object)null) && __result != null)
				{
					Character component = ((Component)__instance).GetComponent<Character>();
					if (!((Object)(object)component == (Object)null))
					{
						ScrollDropManager.TryAddScrollDrop(__instance, component, __result);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CharacterDrop), "DropItems")]
		public static class CharacterDrop_DropItems_Patch
		{
			public static void Prefix(List<KeyValuePair<GameObject, int>> drops)
			{
				if (drops == null)
				{
					return;
				}
				for (int i = 0; i < drops.Count; i++)
				{
					GameObject key = drops[i].Key;
					if ((Object)(object)key != (Object)null && !key.activeSelf)
					{
						key.SetActive(true);
					}
				}
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		public static class ObjectDB_Awake_Patch
		{
			public static void Postfix(ObjectDB __instance)
			{
				ScrollItemManager.InitCustomItems(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		public static class ObjectDB_CopyOtherDB_Patch
		{
			public static void Postfix(ObjectDB __instance)
			{
				ScrollItemManager.InitCustomItems(__instance);
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		public static class ZNetScene_Awake_Patch
		{
			public static void Postfix(ZNetScene __instance)
			{
				ScrollItemManager.RegisterZNetScenePrefabs(__instance);
				ScrollItemManager.CleanupOrphanScrolls();
			}
		}

		[HarmonyPatch(typeof(ZNetView), "Awake")]
		public static class ZNetView_Awake_PrefabGuard_Patch
		{
			public static bool Prefix(ZNetView __instance)
			{
				if (ScrollItemManager.IsCloningCustomPrefab)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemDrop), "Awake")]
		public static class ItemDrop_Awake_PrefabGuard_Patch
		{
			public static bool Prefix(ItemDrop __instance)
			{
				if (ScrollItemManager.IsCloningCustomPrefab)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Floating), "Awake")]
		public static class Floating_Awake_PrefabGuard_Patch
		{
			public static bool Prefix(Floating __instance)
			{
				if (ScrollItemManager.IsCloningCustomPrefab)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Floating), "CustomFixedUpdate")]
		public static class Floating_CustomFixedUpdate_Patch
		{
			private static readonly FieldRef<Floating, ZNetView> _nviewRef = AccessTools.FieldRefAccess<Floating, ZNetView>("m_nview");

			public static bool Prefix(Floating __instance)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return false;
				}
				try
				{
					ZNetView val = ((_nviewRef != null) ? _nviewRef.Invoke(__instance) : ((Component)__instance).GetComponent<ZNetView>());
					if ((Object)(object)val == (Object)null || !val.IsValid())
					{
						return false;
					}
				}
				catch
				{
					return false;
				}
				return true;
			}

			public static Exception Finalizer(Exception __exception)
			{
				if (__exception is NullReferenceException)
				{
					return null;
				}
				return __exception;
			}
		}

		[HarmonyPatch(typeof(Player), "AutoPickup")]
		public static class Player_AutoPickup_Patch
		{
			public static Exception Finalizer(Exception __exception)
			{
				if (__exception is NullReferenceException)
				{
					return null;
				}
				return __exception;
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "RemoveObjects")]
		public static class ZNetScene_RemoveObjects_Patch
		{
			public static Exception Finalizer(Exception __exception)
			{
				if (__exception is NullReferenceException)
				{
					return null;
				}
				return __exception;
			}
		}
	}
	public static class GameCameraPatches
	{
		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		public static class UpdateMouseCapture_Patch
		{
			public static bool Prefix(ref bool ___m_mouseCapture)
			{
				if (EnhancementGui.IsOpen)
				{
					ZCursor.LockState = (CursorLockMode)0;
					ZCursor.Show();
					return false;
				}
				if (!___m_mouseCapture)
				{
					___m_mouseCapture = true;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
		public static class GetMouseScrollWheel_Patch
		{
			public static bool Prefix(ref float __result)
			{
				if (EnhancementGui.IsOpen)
				{
					__result = 0f;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
		public static class UpdateCamera_Patch
		{
			public static bool Prefix()
			{
				if (EnhancementGui.IsOpen)
				{
					return false;
				}
				return true;
			}
		}
	}
	public static class InventoryGridPatches
	{
		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui", new Type[]
		{
			typeof(Player),
			typeof(ItemData)
		})]
		public static class UpdateGui_Patch
		{
			private static readonly string[] s_badgeStrings;

			static UpdateGui_Patch()
			{
				s_badgeStrings = new string[21];
				for (int i = 1; i <= 20; i++)
				{
					string tierHex = EnhancementManager.GetTierHex(i);
					s_badgeStrings[i] = $"<color={tierHex}><b>+{i}</b></color>";
				}
			}

			private static string GetBadgeString(int level)
			{
				if (level >= 1 && level <= 20)
				{
					return s_badgeStrings[level];
				}
				string tierHex = EnhancementManager.GetTierHex(level);
				return $"<color={tierHex}><b>+{level}</b></color>";
			}

			public static void Postfix(InventoryGrid __instance, List<InventoryElement> ___m_elements, int ___m_width, int ___m_height)
			{
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				if (!ModConfig.ShowInventoryBadges.Value || ___m_elements == null)
				{
					return;
				}
				Inventory inventory = __instance.GetInventory();
				if (inventory == null)
				{
					return;
				}
				List<ItemData> allItems = inventory.GetAllItems();
				if (allItems == null)
				{
					return;
				}
				for (int i = 0; i < allItems.Count; i++)
				{
					ItemData val = allItems[i];
					if (val == null)
					{
						continue;
					}
					int enhancementLevel = EnhancementManager.GetEnhancementLevel(val);
					if (enhancementLevel <= 0)
					{
						continue;
					}
					int num = val.m_gridPos.y * ___m_width + val.m_gridPos.x;
					if (num < 0 || num >= ___m_elements.Count)
					{
						continue;
					}
					InventoryElement val2 = ___m_elements[num];
					if ((Object)(object)val2?.m_quality != (Object)null)
					{
						if ((int)val2.m_quality.textWrappingMode != 0)
						{
							val2.m_quality.textWrappingMode = (TextWrappingModes)0;
							val2.m_quality.overflowMode = (TextOverflowModes)0;
						}
						RectTransform rectTransform = val2.m_quality.rectTransform;
						if ((Object)(object)rectTransform != (Object)null && rectTransform.sizeDelta.x < 45f)
						{
							rectTransform.sizeDelta = new Vector2(45f, rectTransform.sizeDelta.y);
						}
						string badgeString = GetBadgeString(enhancementLevel);
						if (val2.m_quality.text != badgeString)
						{
							val2.m_quality.text = badgeString;
						}
						if (!((Component)val2.m_quality).gameObject.activeSelf)
						{
							((Component)val2.m_quality).gameObject.SetActive(true);
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "OnLeftDown")]
		public static class OnLeftDown_Patch
		{
			public static bool Prefix(InventoryGrid __instance, UIInputHandler clickHandler)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: 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)
				if (EnhancementGui.IsOpen && (Object)(object)clickHandler != (Object)null)
				{
					Vector2i gridPos = GetGridPos(__instance, clickHandler);
					if (gridPos.x >= 0 && gridPos.y >= 0)
					{
						Inventory inventory = __instance.GetInventory();
						ItemData val = ((inventory != null) ? inventory.GetItemAt(gridPos.x, gridPos.y) : null);
						if (val != null)
						{
							if (EnhancementManager.IsEnhanceable(val))
							{
								EnhancementGui.SetSelectedItem(val);
							}
							else
							{
								string text = ((Localization.instance != null) ? Localization.instance.Localize(val.m_shared.m_name) : val.m_shared.m_name);
								Player localPlayer = Player.m_localPlayer;
								if (localPlayer != null)
								{
									((Character)localPlayer).Message((MessageType)2, "<color=#f59e0b>" + text + " cannot be enhanced!</color>", 0, (Sprite)null, false);
								}
							}
						}
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "OnLeftClick")]
		public static class OnLeftClick_Patch
		{
			public static bool Prefix()
			{
				if (EnhancementGui.IsOpen)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "OnRightDown")]
		public static class OnRightDown_Patch
		{
			public static bool Prefix(InventoryGrid __instance, UIInputHandler element)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: 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)
				if (EnhancementGui.IsOpen && (Object)(object)element != (Object)null)
				{
					Vector2i gridPos = GetGridPos(__instance, element);
					if (gridPos.x >= 0 && gridPos.y >= 0)
					{
						Inventory inventory = __instance.GetInventory();
						ItemData val = ((inventory != null) ? inventory.GetItemAt(gridPos.x, gridPos.y) : null);
						if (val != null)
						{
							if (EnhancementManager.IsEnhanceable(val))
							{
								EnhancementGui.SetSelectedItem(val);
							}
							else
							{
								string text = ((Localization.instance != null) ? Localization.instance.Localize(val.m_shared.m_name) : val.m_shared.m_name);
								Player localPlayer = Player.m_localPlayer;
								if (localPlayer != null)
								{
									((Character)localPlayer).Message((MessageType)2, "<color=#f59e0b>" + text + " cannot be enhanced!</color>", 0, (Sprite)null, false);
								}
							}
						}
					}
					return false;
				}
				return true;
			}
		}

		private static readonly MethodInfo s_getButtonPos = AccessTools.Method(typeof(InventoryGrid), "GetButtonPos", new Type[1] { typeof(GameObject) }, (Type[])null);

		private static Vector2i GetGridPos(InventoryGrid grid, UIInputHandler handler)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)handler == (Object)null)
			{
				return new Vector2i(-1, -1);
			}
			InventoryElement componentInParent = ((Component)handler).GetComponentInParent<InventoryElement>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.Position;
			}
			if (s_getButtonPos != null && (Object)(object)grid != (Object)null)
			{
				return (Vector2i)s_getButtonPos.Invoke(grid, new object[1] { ((Component)handler).gameObject });
			}
			return new Vector2i(-1, -1);
		}
	}
	public static class InventoryGuiPatches
	{
		[HarmonyPatch(typeof(InventoryGui), "Awake")]
		public static class Awake_Patch
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static UnityAction <>9__0_0;

				internal void <Postfix>b__0_0()
				{
					EnhancementGui.Toggle();
				}
			}

			public static void Postfix(InventoryGui __instance)
			{
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Expected O, but got Unknown
				//IL_0161: 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_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_020b: Expected O, but got Unknown
				//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_0231: Expected O, but got Unknown
				//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f6: Expected O, but got Unknown
				//IL_0315: Unknown result type (might be due to invalid IL or missing references)
				//IL_0320: Unknown result type (might be due to invalid IL or missing references)
				//IL_032b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0335: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance?.m_repairButton == (Object)null || (Object)(object)((Component)__instance.m_repairButton).transform.parent == (Object)null)
				{
					return;
				}
				try
				{
					if ((Object)(object)_enhanceButtonObj != (Object)null)
					{
						return;
					}
					_enhanceButtonObj = Object.Instantiate<GameObject>(((Component)__instance.m_repairButton).gameObject, ((Component)__instance.m_repairButton).transform.parent);
					((Object)_enhanceButtonObj).name = "EnhanceButton";
					Mask component = ((Component)((Component)__instance.m_repairButton).transform.parent).GetComponent<Mask>();
					if ((Object)(object)component != (Object)null)
					{
						((Behaviour)component).enabled = false;
					}
					RectMask2D component2 = ((Component)((Component)__instance.m_repairButton).transform.parent).GetComponent<RectMask2D>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Behaviour)component2).enabled = false;
					}
					RectTransform component3 = ((Component)__instance.m_repairButton).GetComponent<RectTransform>();
					RectTransform component4 = _enhanceButtonObj.GetComponent<RectTransform>();
					if ((Object)(object)component4 != (Object)null && (Object)(object)component3 != (Object)null)
					{
						component4.anchorMin = component3.anchorMin;
						component4.anchorMax = component3.anchorMax;
						component4.pivot = component3.pivot;
						component4.sizeDelta = component3.sizeDelta;
						((Transform)component4).localScale = ((Transform)component3).localScale;
						Rect rect = component3.rect;
						float num;
						if (!(((Rect)(ref rect)).height > 0f))
						{
							num = 44f;
						}
						else
						{
							rect = component3.rect;
							num = ((Rect)(ref rect)).height;
						}
						float num2 = num + 6f;
						component4.anchoredPosition = new Vector2(component3.anchoredPosition.x, component3.anchoredPosition.y - num2);
					}
					foreach (Transform item in _enhanceButtonObj.transform)
					{
						Transform val = item;
						if (((Object)val).name.ToLower().Contains("glow"))
						{
							((Component)val).gameObject.SetActive(false);
						}
					}
					Button component5 = _enhanceButtonObj.GetComponent<Button>();
					if ((Object)(object)component5 != (Object)null)
					{
						component5.onClick = new ButtonClickedEvent();
						ButtonClickedEvent onClick = component5.onClick;
						object obj = <>c.<>9__0_0;
						if (obj == null)
						{
							UnityAction val2 = delegate
							{
								EnhancementGui.Toggle();
							};
							<>c.<>9__0_0 = val2;
							obj = (object)val2;
						}
						((UnityEvent)onClick).AddListener((UnityAction)obj);
						((Selectable)component5).interactable = true;
					}
					UITooltip val3 = _enhanceButtonObj.GetComponent<UITooltip>();
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = _enhanceButtonObj.AddComponent<UITooltip>();
					}
					val3.m_text = "Open Item Enhancement Window";
					val3.m_topic = "⚡ Enhance Item";
					Image[] componentsInChildren = _enhanceButtonObj.GetComponentsInChildren<Image>(true);
					foreach (Image val4 in componentsInChildren)
					{
						if ((Object)(object)((Component)val4).gameObject != (Object)(object)_enhanceButtonObj && !((Object)val4).name.ToLower().Contains("glow"))
						{
							((Graphic)val4).color = new Color(1f, 0.85f, 0.25f, 1f);
						}
					}
					GameObject val5 = new GameObject("EnhanceIconBadge");
					val5.transform.SetParent(_enhanceButtonObj.transform, false);
					RectTransform obj2 = val5.AddComponent<RectTransform>();
					obj2.anchorMin = Vector2.zero;
					obj2.anchorMax = Vector2.one;
					obj2.offsetMin = Vector2.zero;
					obj2.offsetMax = Vector2.zero;
					if ((Object)(object)__instance.m_craftingStationName != (Object)null)
					{
						TextMeshProUGUI obj3 = val5.AddComponent<TextMeshProUGUI>();
						((TMP_Text)obj3).font = __instance.m_craftingStationName.font;
						((TMP_Text)obj3).text = "<color=#ffd700><b>⚡</b></color>";
						((TMP_Text)obj3).fontSize = 24f;
						((TMP_Text)obj3).alignment = (TextAlignmentOptions)514;
						((Graphic)obj3).raycastTarget = false;
					}
					else
					{
						Text obj4 = val5.AddComponent<Text>();
						obj4.text = "⚡";
						obj4.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
						obj4.fontSize = 20;
						obj4.alignment = (TextAnchor)4;
						((Graphic)obj4).color = new Color(1f, 0.85f, 0.25f, 1f);
						((Graphic)obj4).raycastTarget = false;
					}
					_enhanceButtonObj.SetActive(true);
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[Valheim.ItemEnhancements] Could not create EnhanceButton: " + ex.Message));
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "UpdateRepair")]
		public static class UpdateRepair_Patch
		{
			public static void Postfix(InventoryGui __instance)
			{
				if (!((Object)(object)_enhanceButtonObj == (Object)null))
				{
					Button component = _enhanceButtonObj.GetComponent<Button>();
					if ((Object)(object)component != (Object)null)
					{
						((Selectable)component).interactable = true;
					}
					bool active = (Object)(object)__instance.m_repairButton != (Object)null && ((Component)__instance.m_repairButton).gameObject.activeInHierarchy;
					_enhanceButtonObj.SetActive(active);
					UITooltip component2 = _enhanceButtonObj.GetComponent<UITooltip>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.m_text = (EnhancementGui.IsOpen ? "Close Item Enhancement Window [F8]" : "Open Item Enhancement Window [F8]");
					}
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Hide")]
		public static class Hide_Patch
		{
			public static void Postfix()
			{
				EnhancementGui.Close(forceLockCursorIfNoMenu: true);
			}
		}

		private static GameObject _enhanceButtonObj;
	}
	public static class ItemDataPatches
	{
		[HarmonyPatch(typeof(ItemData), "GetDamage", new Type[]
		{
			typeof(int),
			typeof(float)
		})]
		public static class GetDamage_Patch
		{
			public static void Postfix(ItemData __instance, ref DamageTypes __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					StatCalculator.ApplyDamageBonus(__instance, enhancementLevel, ref __result);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetArmor", new Type[]
		{
			typeof(int),
			typeof(float)
		})]
		public static class GetArmor_Patch
		{
			public static void Postfix(ItemData __instance, ref float __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					__result += StatCalculator.GetArmorBonus(__instance, enhancementLevel, __result);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetBlockPower", new Type[]
		{
			typeof(int),
			typeof(float)
		})]
		public static class GetBlockPower_Patch
		{
			public static void Postfix(ItemData __instance, ref float __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					__result += StatCalculator.GetBlockPowerBonus(__instance, enhancementLevel, __result);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetDeflectionForce", new Type[] { typeof(int) })]
		public static class GetDeflectionForce_Patch
		{
			public static void Postfix(ItemData __instance, ref float __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					__result += StatCalculator.GetDeflectionBonus(__instance, enhancementLevel, __result);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetMaxDurability", new Type[] { typeof(int) })]
		public static class GetMaxDurability_Patch
		{
			public static void Postfix(ItemData __instance, ref float __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					__result += StatCalculator.GetDurabilityBonus(__instance, enhancementLevel, __result);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetWeight")]
		public static class GetWeight_Patch
		{
			public static void Postfix(ItemData __instance, ref float __result)
			{
				int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance);
				if (enhancementLevel > 0)
				{
					__result *= StatCalculator.GetWeightMultiplier(enhancementLevel);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float),
			typeof(int),
			typeof(bool)
		})]
		public static class GetTooltip_Patch
		{
			public static void Postfix(ItemData item, ref string __result)
			{
				if (item != null)
				{
					int enhancementLevel = EnhancementManager.GetEnhancementLevel(item);
					if (enhancementLevel > 0)
					{
						__result += EnhancementManager.BuildEnhancementTooltip(item, enhancementLevel);
					}
				}
			}
		}

		[HarmonyPatch(typeof(ItemDrop), "GetHoverText")]
		public static class ItemDropHoverText_Patch
		{
			public static void Postfix(ItemDrop __instance, ref string __result)
			{
				if (__instance?.m_itemData != null && !string.IsNullOrEmpty(__result))
				{
					int enhancementLevel = EnhancementManager.GetEnhancementLevel(__instance.m_itemData);
					if (enhancementLevel > 0)
					{
						string tierHex = EnhancementManager.GetTierHex(enhancementLevel);
						__result = $"{__result} <color={tierHex}>+{enhancementLevel}</color>";
					}
				}
			}
		}
	}
	public static class PlayerPatches
	{
		[HarmonyPatch(typeof(Player), "GetEquipmentMovementModifier")]
		public static class GetEquipmentMovementModifier_Patch
		{
			public static void Postfix(Player __instance, ref float __result)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PlayerBonusCache.EnsureFresh(__instance);
					__result += PlayerBonusCache.MovementBonus;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "GetEquipmentDodgeStaminaModifier")]
		public static class GetEquipmentDodgeStaminaModifier_Patch
		{
			public static void Postfix(Player __instance, ref float __result)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PlayerBonusCache.EnsureFresh(__instance);
					__result -= PlayerBonusCache.DodgeStaminaReduction;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "GetEquipmentRunStaminaModifier")]
		public static class GetEquipmentRunStaminaModifier_Patch
		{
			public static void Postfix(Player __instance, ref float __result)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PlayerBonusCache.EnsureFresh(__instance);
					__result -= PlayerBonusCache.RunStaminaReduction;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "GetEquipmentJumpStaminaModifier")]
		public static class GetEquipmentJumpStaminaModifier_Patch
		{
			public static void Postfix(Player __instance, ref float __result)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PlayerBonusCache.EnsureFresh(__instance);
					__result -= PlayerBonusCache.JumpStaminaReduction;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "GetEquipmentBlockStaminaModifier")]
		public static class GetEquipmentBlockStaminaModifier_Patch
		{
			public static void Postfix(Player __instance, ref float __result)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PlayerBonusCache.EnsureFresh(__instance);
					__result -= PlayerBonusCache.BlockStaminaReduction;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "GetEquipmentEitrRegenModifier")]
		public static class GetEquipmentEitrRegenModifier_Patch

plugins/Valheim.ItemEnhancements/YamlDotNet.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.CodeAnalysis;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("13.7.1.0")]
[assembly: AssemblyInformationalVersion("13.7.1")]
[assembly: AssemblyTitle("YamlDotNet")]
[assembly: AssemblyDescription("The YamlDotNet library.")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("YamlDotNet")]
[assembly: AssemblyCopyright("Copyright (c) Antoine Aubry and contributors 2008 - 2019")]
[assembly: AssemblyTrademark("")]
[assembly: CLSCompliant(true)]
[assembly: InternalsVisibleTo("YamlDotNet.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010065e52a453dde5c5b4be5bbe2205755727fce80244b79b894faf8793d80f7db9a96d360b51c220782db32aacee4cb5b8a91bee33aeec700e1f21895c4baadef501eeeac609220d1651603b378173811ee5bb6a002df973d38821bd2fef820c00c174a69faec326a1983b570f07ec66147026b9c8753465de3a8d0c44b613b02af")]
[assembly: TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName = ".NET Framework 4.7")]
[assembly: AssemblyVersion("13.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace YamlDotNet
{
	internal sealed class CultureInfoAdapter : CultureInfo
	{
		private readonly IFormatProvider provider;

		public CultureInfoAdapter(CultureInfo baseCulture, IFormatProvider provider)
			: base(baseCulture.LCID)
		{
			this.provider = provider;
		}

		public override object? GetFormat(Type? formatType)
		{
			return provider.GetFormat(formatType);
		}
	}
	internal static class ReflectionExtensions
	{
		private static readonly FieldInfo? RemoteStackTraceField = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic);

		public static Type? BaseType(this Type type)
		{
			return type.BaseType;
		}

		public static bool IsValueType(this Type type)
		{
			return type.IsValueType;
		}

		public static bool IsGenericType(this Type type)
		{
			return type.IsGenericType;
		}

		public static bool IsGenericTypeDefinition(this Type type)
		{
			return type.IsGenericTypeDefinition;
		}

		public static bool IsInterface(this Type type)
		{
			return type.IsInterface;
		}

		public static bool IsEnum(this Type type)
		{
			return type.IsEnum;
		}

		public static bool IsDbNull(this object value)
		{
			return value is DBNull;
		}

		public static bool HasDefaultConstructor(this Type type, bool allowPrivateConstructors)
		{
			BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;
			if (allowPrivateConstructors)
			{
				bindingFlags |= BindingFlags.NonPublic;
			}
			if (!type.IsValueType)
			{
				return type.GetConstructor(bindingFlags, null, Type.EmptyTypes, null) != null;
			}
			return true;
		}

		public static TypeCode GetTypeCode(this Type type)
		{
			return Type.GetTypeCode(type);
		}

		public static PropertyInfo? GetPublicProperty(this Type type, string name)
		{
			return type.GetProperty(name);
		}

		public static FieldInfo? GetPublicStaticField(this Type type, string name)
		{
			return type.GetField(name, BindingFlags.Static | BindingFlags.Public);
		}

		public static IEnumerable<PropertyInfo> GetProperties(this Type type, bool includeNonPublic)
		{
			BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;
			if (includeNonPublic)
			{
				bindingFlags |= BindingFlags.NonPublic;
			}
			if (!type.IsInterface)
			{
				return type.GetProperties(bindingFlags);
			}
			return new Type[1] { type }.Concat(type.GetInterfaces()).SelectMany((Type i) => i.GetProperties(bindingFlags));
		}

		public static IEnumerable<PropertyInfo> GetPublicProperties(this Type type)
		{
			return type.GetProperties(includeNonPublic: false);
		}

		public static IEnumerable<FieldInfo> GetPublicFields(this Type type)
		{
			return type.GetFields(BindingFlags.Instance | BindingFlags.Public);
		}

		public static IEnumerable<MethodInfo> GetPublicStaticMethods(this Type type)
		{
			return type.GetMethods(BindingFlags.Static | BindingFlags.Public);
		}

		public static MethodInfo GetPrivateStaticMethod(this Type type, string name)
		{
			return type.GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic) ?? throw new MissingMethodException("Expected to find a method named '" + name + "' in '" + type.FullName + "'.");
		}

		public static MethodInfo? GetPublicStaticMethod(this Type type, string name, params Type[] parameterTypes)
		{
			return type.GetMethod(name, BindingFlags.Static | BindingFlags.Public, null, parameterTypes, null);
		}

		public static MethodInfo? GetPublicInstanceMethod(this Type type, string name)
		{
			return type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public);
		}

		public static Exception Unwrap(this TargetInvocationException ex)
		{
			Exception innerException = ex.InnerException;
			if (innerException == null)
			{
				return ex;
			}
			if (RemoteStackTraceField != null)
			{
				RemoteStackTraceField.SetValue(innerException, innerException.StackTrace + "\r\n");
			}
			return innerException;
		}

		public static bool IsInstanceOf(this Type type, object o)
		{
			return type.IsInstanceOfType(o);
		}

		public static Attribute[] GetAllCustomAttributes<TAttribute>(this PropertyInfo property)
		{
			return Attribute.GetCustomAttributes(property, typeof(TAttribute), inherit: true);
		}
	}
	internal static class PropertyInfoExtensions
	{
		public static object? ReadValue(this PropertyInfo property, object target)
		{
			return property.GetValue(target, null);
		}
	}
	internal static class StandardRegexOptions
	{
		public const RegexOptions Compiled = RegexOptions.Compiled;
	}
}
namespace YamlDotNet.Serialization
{
	public abstract class BuilderSkeleton<TBuilder> where TBuilder : BuilderSkeleton<TBuilder>
	{
		internal INamingConvention namingConvention = NullNamingConvention.Instance;

		internal ITypeResolver typeResolver;

		internal readonly YamlAttributeOverrides overrides;

		internal readonly LazyComponentRegistrationList<Nothing, IYamlTypeConverter> typeConverterFactories;

		internal readonly LazyComponentRegistrationList<ITypeInspector, ITypeInspector> typeInspectorFactories;

		internal bool ignoreFields;

		internal bool includeNonPublicProperties;

		internal Settings settings;

		internal YamlFormatter yamlFormatter = YamlFormatter.Default;

		protected abstract TBuilder Self { get; }

		internal BuilderSkeleton(ITypeResolver typeResolver)
		{
			overrides = new YamlAttributeOverrides();
			typeConverterFactories = new LazyComponentRegistrationList<Nothing, IYamlTypeConverter>
			{
				{
					typeof(YamlDotNet.Serialization.Converters.GuidConverter),
					(Nothing _) => new YamlDotNet.Serialization.Converters.GuidConverter(jsonCompatible: false)
				},
				{
					typeof(SystemTypeConverter),
					(Nothing _) => new SystemTypeConverter()
				}
			};
			typeInspectorFactories = new LazyComponentRegistrationList<ITypeInspector, ITypeInspector>();
			this.typeResolver = typeResolver ?? throw new ArgumentNullException("typeResolver");
			settings = new Settings();
		}

		public TBuilder IgnoreFields()
		{
			ignoreFields = true;
			return Self;
		}

		public TBuilder IncludeNonPublicProperties()
		{
			includeNonPublicProperties = true;
			return Self;
		}

		public TBuilder EnablePrivateConstructors()
		{
			settings.AllowPrivateConstructors = true;
			return Self;
		}

		public TBuilder WithNamingConvention(INamingConvention namingConvention)
		{
			this.namingConvention = namingConvention ?? throw new ArgumentNullException("namingConvention");
			return Self;
		}

		public TBuilder WithTypeResolver(ITypeResolver typeResolver)
		{
			this.typeResolver = typeResolver ?? throw new ArgumentNullException("typeResolver");
			return Self;
		}

		public abstract TBuilder WithTagMapping(TagName tag, Type type);

		public TBuilder WithAttributeOverride<TClass>(Expression<Func<TClass, object>> propertyAccessor, Attribute attribute)
		{
			overrides.Add(propertyAccessor, attribute);
			return Self;
		}

		public TBuilder WithAttributeOverride(Type type, string member, Attribute attribute)
		{
			overrides.Add(type, member, attribute);
			return Self;
		}

		public TBuilder WithTypeConverter(IYamlTypeConverter typeConverter)
		{
			return WithTypeConverter(typeConverter, delegate(IRegistrationLocationSelectionSyntax<IYamlTypeConverter> w)
			{
				w.OnTop();
			});
		}

		public TBuilder WithTypeConverter(IYamlTypeConverter typeConverter, Action<IRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where)
		{
			if (typeConverter == null)
			{
				throw new ArgumentNullException("typeConverter");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeConverterFactories.CreateRegistrationLocationSelector(typeConverter.GetType(), (Nothing _) => typeConverter));
			return Self;
		}

		public TBuilder WithTypeConverter<TYamlTypeConverter>(WrapperFactory<IYamlTypeConverter, IYamlTypeConverter> typeConverterFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where) where TYamlTypeConverter : IYamlTypeConverter
		{
			if (typeConverterFactory == null)
			{
				throw new ArgumentNullException("typeConverterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeConverterFactories.CreateTrackingRegistrationLocationSelector(typeof(TYamlTypeConverter), (IYamlTypeConverter wrapped, Nothing _) => typeConverterFactory(wrapped)));
			return Self;
		}

		public TBuilder WithoutTypeConverter<TYamlTypeConverter>() where TYamlTypeConverter : IYamlTypeConverter
		{
			return WithoutTypeConverter(typeof(TYamlTypeConverter));
		}

		public TBuilder WithoutTypeConverter(Type converterType)
		{
			if (converterType == null)
			{
				throw new ArgumentNullException("converterType");
			}
			typeConverterFactories.Remove(converterType);
			return Self;
		}

		public TBuilder WithTypeInspector<TTypeInspector>(Func<ITypeInspector, TTypeInspector> typeInspectorFactory) where TTypeInspector : ITypeInspector
		{
			return WithTypeInspector(typeInspectorFactory, delegate(IRegistrationLocationSelectionSyntax<ITypeInspector> w)
			{
				w.OnTop();
			});
		}

		public TBuilder WithTypeInspector<TTypeInspector>(Func<ITypeInspector, TTypeInspector> typeInspectorFactory, Action<IRegistrationLocationSelectionSyntax<ITypeInspector>> where) where TTypeInspector : ITypeInspector
		{
			if (typeInspectorFactory == null)
			{
				throw new ArgumentNullException("typeInspectorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeInspectorFactories.CreateRegistrationLocationSelector(typeof(TTypeInspector), (ITypeInspector inner) => typeInspectorFactory(inner)));
			return Self;
		}

		public TBuilder WithTypeInspector<TTypeInspector>(WrapperFactory<ITypeInspector, ITypeInspector, TTypeInspector> typeInspectorFactory, Action<ITrackingRegistrationLocationSelectionSyntax<ITypeInspector>> where) where TTypeInspector : ITypeInspector
		{
			if (typeInspectorFactory == null)
			{
				throw new ArgumentNullException("typeInspectorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeInspectorFactories.CreateTrackingRegistrationLocationSelector(typeof(TTypeInspector), (ITypeInspector wrapped, ITypeInspector inner) => typeInspectorFactory(wrapped, inner)));
			return Self;
		}

		public TBuilder WithoutTypeInspector<TTypeInspector>() where TTypeInspector : ITypeInspector
		{
			return WithoutTypeInspector(typeof(TTypeInspector));
		}

		public TBuilder WithoutTypeInspector(Type inspectorType)
		{
			if (inspectorType == null)
			{
				throw new ArgumentNullException("inspectorType");
			}
			typeInspectorFactories.Remove(inspectorType);
			return Self;
		}

		public TBuilder WithYamlFormatter(YamlFormatter formatter)
		{
			yamlFormatter = formatter ?? throw new ArgumentNullException("formatter");
			return Self;
		}

		protected IEnumerable<IYamlTypeConverter> BuildTypeConverters()
		{
			return typeConverterFactories.BuildComponentList();
		}
	}
	public delegate TComponent WrapperFactory<TComponentBase, TComponent>(TComponentBase wrapped) where TComponent : TComponentBase;
	public delegate TComponent WrapperFactory<TArgument, TComponentBase, TComponent>(TComponentBase wrapped, TArgument argument) where TComponent : TComponentBase;
	[Flags]
	public enum DefaultValuesHandling
	{
		Preserve = 0,
		OmitNull = 1,
		OmitDefaults = 2,
		OmitEmptyCollections = 4
	}
	public sealed class Deserializer : IDeserializer
	{
		private readonly IValueDeserializer valueDeserializer;

		public Deserializer()
			: this(new DeserializerBuilder().BuildValueDeserializer())
		{
		}

		private Deserializer(IValueDeserializer valueDeserializer)
		{
			this.valueDeserializer = valueDeserializer ?? throw new ArgumentNullException("valueDeserializer");
		}

		public static Deserializer FromValueDeserializer(IValueDeserializer valueDeserializer)
		{
			return new Deserializer(valueDeserializer);
		}

		public T Deserialize<T>(string input)
		{
			using StringReader input2 = new StringReader(input);
			return Deserialize<T>(input2);
		}

		public T Deserialize<T>(TextReader input)
		{
			return Deserialize<T>(new Parser(input));
		}

		public T Deserialize<T>(IParser parser)
		{
			return (T)Deserialize(parser, typeof(T));
		}

		public object? Deserialize(string input)
		{
			return Deserialize(input, typeof(object));
		}

		public object? Deserialize(TextReader input)
		{
			return Deserialize(input, typeof(object));
		}

		public object? Deserialize(IParser parser)
		{
			return Deserialize(parser, typeof(object));
		}

		public object? Deserialize(string input, Type type)
		{
			using StringReader input2 = new StringReader(input);
			return Deserialize(input2, type);
		}

		public object? Deserialize(TextReader input, Type type)
		{
			return Deserialize(new Parser(input), type);
		}

		public object? Deserialize(IParser parser, Type type)
		{
			if (parser == null)
			{
				throw new ArgumentNullException("parser");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			YamlDotNet.Core.Events.StreamStart @event;
			bool flag = parser.TryConsume<YamlDotNet.Core.Events.StreamStart>(out @event);
			YamlDotNet.Core.Events.DocumentStart event2;
			bool flag2 = parser.TryConsume<YamlDotNet.Core.Events.DocumentStart>(out event2);
			object result = null;
			if (!parser.Accept<YamlDotNet.Core.Events.DocumentEnd>(out var _) && !parser.Accept<YamlDotNet.Core.Events.StreamEnd>(out var _))
			{
				using SerializerState serializerState = new SerializerState();
				result = valueDeserializer.DeserializeValue(parser, type, serializerState, valueDeserializer);
				serializerState.OnDeserialization();
			}
			if (flag2)
			{
				parser.Consume<YamlDotNet.Core.Events.DocumentEnd>();
			}
			if (flag)
			{
				parser.Consume<YamlDotNet.Core.Events.StreamEnd>();
			}
			return result;
		}
	}
	public sealed class DeserializerBuilder : BuilderSkeleton<DeserializerBuilder>
	{
		private Lazy<IObjectFactory> objectFactory;

		private readonly LazyComponentRegistrationList<Nothing, INodeDeserializer> nodeDeserializerFactories;

		private readonly LazyComponentRegistrationList<Nothing, INodeTypeResolver> nodeTypeResolverFactories;

		private readonly Dictionary<TagName, Type> tagMappings;

		private readonly Dictionary<Type, Type> typeMappings;

		private readonly ITypeConverter typeConverter;

		private bool ignoreUnmatched;

		private bool duplicateKeyChecking;

		private bool attemptUnknownTypeDeserialization;

		protected override DeserializerBuilder Self => this;

		public DeserializerBuilder()
			: base((ITypeResolver)new StaticTypeResolver())
		{
			typeMappings = new Dictionary<Type, Type>();
			objectFactory = new Lazy<IObjectFactory>(() => new DefaultObjectFactory(typeMappings, settings), isThreadSafe: true);
			tagMappings = new Dictionary<TagName, Type>
			{
				{
					FailsafeSchema.Tags.Map,
					typeof(Dictionary<object, object>)
				},
				{
					FailsafeSchema.Tags.Str,
					typeof(string)
				},
				{
					JsonSchema.Tags.Bool,
					typeof(bool)
				},
				{
					JsonSchema.Tags.Float,
					typeof(double)
				},
				{
					JsonSchema.Tags.Int,
					typeof(int)
				},
				{
					DefaultSchema.Tags.Timestamp,
					typeof(DateTime)
				}
			};
			typeInspectorFactories.Add(typeof(CachedTypeInspector), (ITypeInspector inner) => new CachedTypeInspector(inner));
			typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), (ITypeInspector inner) => (!(namingConvention is NullNamingConvention)) ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
			typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), (ITypeInspector inner) => new YamlAttributesTypeInspector(inner));
			typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), (ITypeInspector inner) => (overrides == null) ? inner : new YamlAttributeOverridesInspector(inner, overrides.Clone()));
			typeInspectorFactories.Add(typeof(ReadableAndWritablePropertiesTypeInspector), (ITypeInspector inner) => new ReadableAndWritablePropertiesTypeInspector(inner));
			nodeDeserializerFactories = new LazyComponentRegistrationList<Nothing, INodeDeserializer>
			{
				{
					typeof(YamlConvertibleNodeDeserializer),
					(Nothing _) => new YamlConvertibleNodeDeserializer(objectFactory.Value)
				},
				{
					typeof(YamlSerializableNodeDeserializer),
					(Nothing _) => new YamlSerializableNodeDeserializer(objectFactory.Value)
				},
				{
					typeof(TypeConverterNodeDeserializer),
					(Nothing _) => new TypeConverterNodeDeserializer(BuildTypeConverters())
				},
				{
					typeof(NullNodeDeserializer),
					(Nothing _) => new NullNodeDeserializer()
				},
				{
					typeof(ScalarNodeDeserializer),
					(Nothing _) => new ScalarNodeDeserializer(attemptUnknownTypeDeserialization, typeConverter, yamlFormatter)
				},
				{
					typeof(ArrayNodeDeserializer),
					(Nothing _) => new ArrayNodeDeserializer()
				},
				{
					typeof(DictionaryNodeDeserializer),
					(Nothing _) => new DictionaryNodeDeserializer(objectFactory.Value, duplicateKeyChecking)
				},
				{
					typeof(CollectionNodeDeserializer),
					(Nothing _) => new CollectionNodeDeserializer(objectFactory.Value)
				},
				{
					typeof(EnumerableNodeDeserializer),
					(Nothing _) => new EnumerableNodeDeserializer()
				},
				{
					typeof(ObjectNodeDeserializer),
					(Nothing _) => new ObjectNodeDeserializer(objectFactory.Value, BuildTypeInspector(), ignoreUnmatched, duplicateKeyChecking, typeConverter)
				}
			};
			nodeTypeResolverFactories = new LazyComponentRegistrationList<Nothing, INodeTypeResolver>
			{
				{
					typeof(MappingNodeTypeResolver),
					(Nothing _) => new MappingNodeTypeResolver(typeMappings)
				},
				{
					typeof(YamlConvertibleTypeResolver),
					(Nothing _) => new YamlConvertibleTypeResolver()
				},
				{
					typeof(YamlSerializableTypeResolver),
					(Nothing _) => new YamlSerializableTypeResolver()
				},
				{
					typeof(TagNodeTypeResolver),
					(Nothing _) => new TagNodeTypeResolver(tagMappings)
				},
				{
					typeof(PreventUnknownTagsNodeTypeResolver),
					(Nothing _) => new PreventUnknownTagsNodeTypeResolver()
				},
				{
					typeof(DefaultContainersNodeTypeResolver),
					(Nothing _) => new DefaultContainersNodeTypeResolver()
				}
			};
			typeConverter = new ReflectionTypeConverter();
		}

		internal ITypeInspector BuildTypeInspector()
		{
			ITypeInspector typeInspector = new WritablePropertiesTypeInspector(typeResolver, includeNonPublicProperties);
			if (!ignoreFields)
			{
				typeInspector = new CompositeTypeInspector(new ReadableFieldsTypeInspector(typeResolver), typeInspector);
			}
			return typeInspectorFactories.BuildComponentChain(typeInspector);
		}

		public DeserializerBuilder WithAttemptingUnquotedStringTypeDeserialization()
		{
			attemptUnknownTypeDeserialization = true;
			return this;
		}

		public DeserializerBuilder WithObjectFactory(IObjectFactory objectFactory)
		{
			if (objectFactory == null)
			{
				throw new ArgumentNullException("objectFactory");
			}
			this.objectFactory = new Lazy<IObjectFactory>(() => objectFactory, isThreadSafe: true);
			return this;
		}

		public DeserializerBuilder WithObjectFactory(Func<Type, object> objectFactory)
		{
			if (objectFactory == null)
			{
				throw new ArgumentNullException("objectFactory");
			}
			return WithObjectFactory(new LambdaObjectFactory(objectFactory));
		}

		public DeserializerBuilder WithNodeDeserializer(INodeDeserializer nodeDeserializer)
		{
			return WithNodeDeserializer(nodeDeserializer, delegate(IRegistrationLocationSelectionSyntax<INodeDeserializer> w)
			{
				w.OnTop();
			});
		}

		public DeserializerBuilder WithNodeDeserializer(INodeDeserializer nodeDeserializer, Action<IRegistrationLocationSelectionSyntax<INodeDeserializer>> where)
		{
			if (nodeDeserializer == null)
			{
				throw new ArgumentNullException("nodeDeserializer");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeDeserializerFactories.CreateRegistrationLocationSelector(nodeDeserializer.GetType(), (Nothing _) => nodeDeserializer));
			return this;
		}

		public DeserializerBuilder WithNodeDeserializer<TNodeDeserializer>(WrapperFactory<INodeDeserializer, TNodeDeserializer> nodeDeserializerFactory, Action<ITrackingRegistrationLocationSelectionSyntax<INodeDeserializer>> where) where TNodeDeserializer : INodeDeserializer
		{
			if (nodeDeserializerFactory == null)
			{
				throw new ArgumentNullException("nodeDeserializerFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeDeserializerFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeDeserializer), (INodeDeserializer wrapped, Nothing _) => nodeDeserializerFactory(wrapped)));
			return this;
		}

		public DeserializerBuilder WithoutNodeDeserializer<TNodeDeserializer>() where TNodeDeserializer : INodeDeserializer
		{
			return WithoutNodeDeserializer(typeof(TNodeDeserializer));
		}

		public DeserializerBuilder WithoutNodeDeserializer(Type nodeDeserializerType)
		{
			if (nodeDeserializerType == null)
			{
				throw new ArgumentNullException("nodeDeserializerType");
			}
			nodeDeserializerFactories.Remove(nodeDeserializerType);
			return this;
		}

		public DeserializerBuilder WithTypeDiscriminatingNodeDeserializer(Action<ITypeDiscriminatingNodeDeserializerOptions> configureTypeDiscriminatingNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
		{
			TypeDiscriminatingNodeDeserializerOptions typeDiscriminatingNodeDeserializerOptions = new TypeDiscriminatingNodeDeserializerOptions();
			configureTypeDiscriminatingNodeDeserializerOptions(typeDiscriminatingNodeDeserializerOptions);
			TypeDiscriminatingNodeDeserializer nodeDeserializer = new TypeDiscriminatingNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), typeDiscriminatingNodeDeserializerOptions.discriminators, maxDepth, maxLength);
			return WithNodeDeserializer(nodeDeserializer, delegate(IRegistrationLocationSelectionSyntax<INodeDeserializer> s)
			{
				s.Before<DictionaryNodeDeserializer>();
			});
		}

		public DeserializerBuilder WithNodeTypeResolver(INodeTypeResolver nodeTypeResolver)
		{
			return WithNodeTypeResolver(nodeTypeResolver, delegate(IRegistrationLocationSelectionSyntax<INodeTypeResolver> w)
			{
				w.OnTop();
			});
		}

		public DeserializerBuilder WithNodeTypeResolver(INodeTypeResolver nodeTypeResolver, Action<IRegistrationLocationSelectionSyntax<INodeTypeResolver>> where)
		{
			if (nodeTypeResolver == null)
			{
				throw new ArgumentNullException("nodeTypeResolver");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeTypeResolverFactories.CreateRegistrationLocationSelector(nodeTypeResolver.GetType(), (Nothing _) => nodeTypeResolver));
			return this;
		}

		public DeserializerBuilder WithNodeTypeResolver<TNodeTypeResolver>(WrapperFactory<INodeTypeResolver, TNodeTypeResolver> nodeTypeResolverFactory, Action<ITrackingRegistrationLocationSelectionSyntax<INodeTypeResolver>> where) where TNodeTypeResolver : INodeTypeResolver
		{
			if (nodeTypeResolverFactory == null)
			{
				throw new ArgumentNullException("nodeTypeResolverFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeTypeResolverFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeTypeResolver), (INodeTypeResolver wrapped, Nothing _) => nodeTypeResolverFactory(wrapped)));
			return this;
		}

		public DeserializerBuilder WithoutNodeTypeResolver<TNodeTypeResolver>() where TNodeTypeResolver : INodeTypeResolver
		{
			return WithoutNodeTypeResolver(typeof(TNodeTypeResolver));
		}

		public DeserializerBuilder WithoutNodeTypeResolver(Type nodeTypeResolverType)
		{
			if (nodeTypeResolverType == null)
			{
				throw new ArgumentNullException("nodeTypeResolverType");
			}
			nodeTypeResolverFactories.Remove(nodeTypeResolverType);
			return this;
		}

		public override DeserializerBuilder WithTagMapping(TagName tag, Type type)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (tagMappings.TryGetValue(tag, out Type value))
			{
				throw new ArgumentException($"Type already has a registered type '{value.FullName}' for tag '{tag}'", "tag");
			}
			tagMappings.Add(tag, type);
			return this;
		}

		public DeserializerBuilder WithTypeMapping<TInterface, TConcrete>() where TConcrete : TInterface
		{
			Type typeFromHandle = typeof(TInterface);
			Type typeFromHandle2 = typeof(TConcrete);
			if (!typeFromHandle.IsAssignableFrom(typeFromHandle2))
			{
				throw new InvalidOperationException("The type '" + typeFromHandle2.Name + "' does not implement interface '" + typeFromHandle.Name + "'.");
			}
			if (typeMappings.ContainsKey(typeFromHandle))
			{
				typeMappings[typeFromHandle] = typeFromHandle2;
			}
			else
			{
				typeMappings.Add(typeFromHandle, typeFromHandle2);
			}
			return this;
		}

		public DeserializerBuilder WithoutTagMapping(TagName tag)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (!tagMappings.Remove(tag))
			{
				throw new KeyNotFoundException($"Tag '{tag}' is not registered");
			}
			return this;
		}

		public DeserializerBuilder IgnoreUnmatchedProperties()
		{
			ignoreUnmatched = true;
			return this;
		}

		public DeserializerBuilder WithDuplicateKeyChecking()
		{
			duplicateKeyChecking = true;
			return this;
		}

		public IDeserializer Build()
		{
			return Deserializer.FromValueDeserializer(BuildValueDeserializer());
		}

		public IValueDeserializer BuildValueDeserializer()
		{
			return new AliasValueDeserializer(new NodeValueDeserializer(nodeDeserializerFactories.BuildComponentList(), nodeTypeResolverFactories.BuildComponentList(), typeConverter));
		}
	}
	public sealed class EmissionPhaseObjectGraphVisitorArgs
	{
		private readonly IEnumerable<IObjectGraphVisitor<Nothing>> preProcessingPhaseVisitors;

		public IObjectGraphVisitor<IEmitter> InnerVisitor { get; private set; }

		public IEventEmitter EventEmitter { get; private set; }

		public ObjectSerializer NestedObjectSerializer { get; private set; }

		public IEnumerable<IYamlTypeConverter> TypeConverters { get; private set; }

		public EmissionPhaseObjectGraphVisitorArgs(IObjectGraphVisitor<IEmitter> innerVisitor, IEventEmitter eventEmitter, IEnumerable<IObjectGraphVisitor<Nothing>> preProcessingPhaseVisitors, IEnumerable<IYamlTypeConverter> typeConverters, ObjectSerializer nestedObjectSerializer)
		{
			InnerVisitor = innerVisitor ?? throw new ArgumentNullException("innerVisitor");
			EventEmitter = eventEmitter ?? throw new ArgumentNullException("eventEmitter");
			this.preProcessingPhaseVisitors = preProcessingPhaseVisitors ?? throw new ArgumentNullException("preProcessingPhaseVisitors");
			TypeConverters = typeConverters ?? throw new ArgumentNullException("typeConverters");
			NestedObjectSerializer = nestedObjectSerializer ?? throw new ArgumentNullException("nestedObjectSerializer");
		}

		public T GetPreProcessingPhaseObjectGraphVisitor<T>() where T : IObjectGraphVisitor<Nothing>
		{
			return preProcessingPhaseVisitors.OfType<T>().Single();
		}
	}
	public abstract class EventInfo
	{
		public IObjectDescriptor Source { get; }

		protected EventInfo(IObjectDescriptor source)
		{
			Source = source ?? throw new ArgumentNullException("source");
		}
	}
	public class AliasEventInfo : EventInfo
	{
		public AnchorName Alias { get; }

		public bool NeedsExpansion { get; set; }

		public AliasEventInfo(IObjectDescriptor source, AnchorName alias)
			: base(source)
		{
			if (alias.IsEmpty)
			{
				throw new ArgumentNullException("alias");
			}
			Alias = alias;
		}
	}
	public class ObjectEventInfo : EventInfo
	{
		public AnchorName Anchor { get; set; }

		public TagName Tag { get; set; }

		protected ObjectEventInfo(IObjectDescriptor source)
			: base(source)
		{
		}
	}
	public sealed class ScalarEventInfo : ObjectEventInfo
	{
		public string RenderedValue { get; set; }

		public ScalarStyle Style { get; set; }

		public bool IsPlainImplicit { get; set; }

		public bool IsQuotedImplicit { get; set; }

		public ScalarEventInfo(IObjectDescriptor source)
			: base(source)
		{
			Style = source.ScalarStyle;
			RenderedValue = string.Empty;
		}
	}
	public sealed class MappingStartEventInfo : ObjectEventInfo
	{
		public bool IsImplicit { get; set; }

		public MappingStyle Style { get; set; }

		public MappingStartEventInfo(IObjectDescriptor source)
			: base(source)
		{
		}
	}
	public sealed class MappingEndEventInfo : EventInfo
	{
		public MappingEndEventInfo(IObjectDescriptor source)
			: base(source)
		{
		}
	}
	public sealed class SequenceStartEventInfo : ObjectEventInfo
	{
		public bool IsImplicit { get; set; }

		public SequenceStyle Style { get; set; }

		public SequenceStartEventInfo(IObjectDescriptor source)
			: base(source)
		{
		}
	}
	public sealed class SequenceEndEventInfo : EventInfo
	{
		public SequenceEndEventInfo(IObjectDescriptor source)
			: base(source)
		{
		}
	}
	public interface IAliasProvider
	{
		AnchorName GetAlias(object target);
	}
	public interface IDeserializer
	{
		T Deserialize<T>(string input);

		T Deserialize<T>(TextReader input);

		T Deserialize<T>(IParser parser);

		object? Deserialize(string input);

		object? Deserialize(TextReader input);

		object? Deserialize(IParser parser);

		object? Deserialize(string input, Type type);

		object? Deserialize(TextReader input, Type type);

		object? Deserialize(IParser parser, Type type);
	}
	public interface IEventEmitter
	{
		void Emit(AliasEventInfo eventInfo, IEmitter emitter);

		void Emit(ScalarEventInfo eventInfo, IEmitter emitter);

		void Emit(MappingStartEventInfo eventInfo, IEmitter emitter);

		void Emit(MappingEndEventInfo eventInfo, IEmitter emitter);

		void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter);

		void Emit(SequenceEndEventInfo eventInfo, IEmitter emitter);
	}
	public interface INamingConvention
	{
		string Apply(string value);
	}
	public interface INodeDeserializer
	{
		bool Deserialize(IParser reader, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value);
	}
	public interface INodeTypeResolver
	{
		bool Resolve(NodeEvent? nodeEvent, ref Type currentType);
	}
	public interface IObjectAccessor
	{
		void Set(string name, object target, object value);

		object? Read(string name, object target);
	}
	public interface IObjectDescriptor
	{
		object? Value { get; }

		Type Type { get; }

		Type StaticType { get; }

		ScalarStyle ScalarStyle { get; }
	}
	public static class ObjectDescriptorExtensions
	{
		public static object NonNullValue(this IObjectDescriptor objectDescriptor)
		{
			return objectDescriptor.Value ?? throw new InvalidOperationException("Attempted to use a IObjectDescriptor of type '" + objectDescriptor.Type.FullName + "' whose Value is null at a point whete it is invalid to do so. This may indicate a bug in YamlDotNet.");
		}
	}
	public interface IObjectFactory
	{
		object Create(Type type);

		object? CreatePrimitive(Type type);

		bool GetDictionary(IObjectDescriptor descriptor, out IDictionary? dictionary, out Type[]? genericArguments);

		Type GetValueType(Type type);

		void ExecuteOnDeserializing(object value);

		void ExecuteOnDeserialized(object value);

		void ExecuteOnSerializing(object value);

		void ExecuteOnSerialized(object value);
	}
	public interface IObjectGraphTraversalStrategy
	{
		void Traverse<TContext>(IObjectDescriptor graph, IObjectGraphVisitor<TContext> visitor, TContext context);
	}
	public interface IObjectGraphVisitor<TContext>
	{
		bool Enter(IObjectDescriptor value, TContext context);

		bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, TContext context);

		bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, TContext context);

		void VisitScalar(IObjectDescriptor scalar, TContext context);

		void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, TContext context);

		void VisitMappingEnd(IObjectDescriptor mapping, TContext context);

		void VisitSequenceStart(IObjectDescriptor sequence, Type elementType, TContext context);

		void VisitSequenceEnd(IObjectDescriptor sequence, TContext context);
	}
	public interface IPropertyDescriptor
	{
		string Name { get; }

		bool CanWrite { get; }

		Type Type { get; }

		Type? TypeOverride { get; set; }

		int Order { get; set; }

		ScalarStyle ScalarStyle { get; set; }

		T? GetCustomAttribute<T>() where T : Attribute;

		IObjectDescriptor Read(object target);

		void Write(object target, object? value);
	}
	public interface IRegistrationLocationSelectionSyntax<TBaseRegistrationType>
	{
		void InsteadOf<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;

		void Before<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;

		void After<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;

		void OnTop();

		void OnBottom();
	}
	public interface ITrackingRegistrationLocationSelectionSyntax<TBaseRegistrationType>
	{
		void InsteadOf<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;
	}
	public interface ISerializer
	{
		string Serialize(object? graph);

		string Serialize(object? graph, Type type);

		void Serialize(TextWriter writer, object? graph);

		void Serialize(TextWriter writer, object? graph, Type type);

		void Serialize(IEmitter emitter, object? graph);

		void Serialize(IEmitter emitter, object? graph, Type type);
	}
	public interface ITypeInspector
	{
		IEnumerable<IPropertyDescriptor> GetProperties(Type type, object? container);

		IPropertyDescriptor GetProperty(Type type, object? container, string name, [MaybeNullWhen(true)] bool ignoreUnmatched);
	}
	public interface ITypeResolver
	{
		Type Resolve(Type staticType, object? actualValue);
	}
	public interface IValueDeserializer
	{
		object? DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer);
	}
	public interface IValuePromise
	{
		event Action<object?> ValueAvailable;
	}
	public interface IValueSerializer
	{
		void SerializeValue(IEmitter emitter, object? value, Type? type);
	}
	public interface IYamlConvertible
	{
		void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer);

		void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer);
	}
	public delegate object? ObjectDeserializer(Type type);
	public delegate void ObjectSerializer(object? value, Type? type = null);
	[Obsolete("Please use IYamlConvertible instead")]
	public interface IYamlSerializable
	{
		void ReadYaml(IParser parser);

		void WriteYaml(IEmitter emitter);
	}
	public interface IYamlTypeConverter
	{
		bool Accepts(Type type);

		object? ReadYaml(IParser parser, Type type);

		void WriteYaml(IEmitter emitter, object? value, Type type);
	}
	internal sealed class LazyComponentRegistrationList<TArgument, TComponent> : IEnumerable<Func<TArgument, TComponent>>, IEnumerable
	{
		public sealed class LazyComponentRegistration
		{
			public readonly Type ComponentType;

			public readonly Func<TArgument, TComponent> Factory;

			public LazyComponentRegistration(Type componentType, Func<TArgument, TComponent> factory)
			{
				ComponentType = componentType;
				Factory = factory;
			}
		}

		public sealed class TrackingLazyComponentRegistration
		{
			public readonly Type ComponentType;

			public readonly Func<TComponent, TArgument, TComponent> Factory;

			public TrackingLazyComponentRegistration(Type componentType, Func<TComponent, TArgument, TComponent> factory)
			{
				ComponentType = componentType;
				Factory = factory;
			}
		}

		private class RegistrationLocationSelector : IRegistrationLocationSelectionSyntax<TComponent>
		{
			private readonly LazyComponentRegistrationList<TArgument, TComponent> registrations;

			private readonly LazyComponentRegistration newRegistration;

			public RegistrationLocationSelector(LazyComponentRegistrationList<TArgument, TComponent> registrations, LazyComponentRegistration newRegistration)
			{
				this.registrations = registrations;
				this.newRegistration = newRegistration;
			}

			void IRegistrationLocationSelectionSyntax<TComponent>.InsteadOf<TRegistrationType>()
			{
				if (newRegistration.ComponentType != typeof(TRegistrationType))
				{
					registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				}
				int index = registrations.EnsureRegistrationExists<TRegistrationType>();
				registrations.entries[index] = newRegistration;
			}

			void IRegistrationLocationSelectionSyntax<TComponent>.After<TRegistrationType>()
			{
				registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				int num = registrations.EnsureRegistrationExists<TRegistrationType>();
				registrations.entries.Insert(num + 1, newRegistration);
			}

			void IRegistrationLocationSelectionSyntax<TComponent>.Before<TRegistrationType>()
			{
				registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				int index = registrations.EnsureRegistrationExists<TRegistrationType>();
				registrations.entries.Insert(index, newRegistration);
			}

			void IRegistrationLocationSelectionSyntax<TComponent>.OnBottom()
			{
				registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				registrations.entries.Add(newRegistration);
			}

			void IRegistrationLocationSelectionSyntax<TComponent>.OnTop()
			{
				registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				registrations.entries.Insert(0, newRegistration);
			}
		}

		private class TrackingRegistrationLocationSelector : ITrackingRegistrationLocationSelectionSyntax<TComponent>
		{
			private readonly LazyComponentRegistrationList<TArgument, TComponent> registrations;

			private readonly TrackingLazyComponentRegistration newRegistration;

			public TrackingRegistrationLocationSelector(LazyComponentRegistrationList<TArgument, TComponent> registrations, TrackingLazyComponentRegistration newRegistration)
			{
				this.registrations = registrations;
				this.newRegistration = newRegistration;
			}

			void ITrackingRegistrationLocationSelectionSyntax<TComponent>.InsteadOf<TRegistrationType>()
			{
				if (newRegistration.ComponentType != typeof(TRegistrationType))
				{
					registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
				}
				int index = registrations.EnsureRegistrationExists<TRegistrationType>();
				Func<TArgument, TComponent> innerComponentFactory = registrations.entries[index].Factory;
				registrations.entries[index] = new LazyComponentRegistration(newRegistration.ComponentType, (TArgument arg) => newRegistration.Factory(innerComponentFactory(arg), arg));
			}
		}

		private readonly List<LazyComponentRegistration> entries = new List<LazyComponentRegistration>();

		public int Count => entries.Count;

		public IEnumerable<Func<TArgument, TComponent>> InReverseOrder
		{
			get
			{
				int i = entries.Count - 1;
				while (i >= 0)
				{
					yield return entries[i].Factory;
					int num = i - 1;
					i = num;
				}
			}
		}

		public LazyComponentRegistrationList<TArgument, TComponent> Clone()
		{
			LazyComponentRegistrationList<TArgument, TComponent> lazyComponentRegistrationList = new LazyComponentRegistrationList<TArgument, TComponent>();
			foreach (LazyComponentRegistration entry in entries)
			{
				lazyComponentRegistrationList.entries.Add(entry);
			}
			return lazyComponentRegistrationList;
		}

		public void Clear()
		{
			entries.Clear();
		}

		public void Add(Type componentType, Func<TArgument, TComponent> factory)
		{
			entries.Add(new LazyComponentRegistration(componentType, factory));
		}

		public void Remove(Type componentType)
		{
			for (int i = 0; i < entries.Count; i++)
			{
				if (entries[i].ComponentType == componentType)
				{
					entries.RemoveAt(i);
					return;
				}
			}
			throw new KeyNotFoundException("A component registration of type '" + componentType.FullName + "' was not found.");
		}

		public IRegistrationLocationSelectionSyntax<TComponent> CreateRegistrationLocationSelector(Type componentType, Func<TArgument, TComponent> factory)
		{
			return new RegistrationLocationSelector(this, new LazyComponentRegistration(componentType, factory));
		}

		public ITrackingRegistrationLocationSelectionSyntax<TComponent> CreateTrackingRegistrationLocationSelector(Type componentType, Func<TComponent, TArgument, TComponent> factory)
		{
			return new TrackingRegistrationLocationSelector(this, new TrackingLazyComponentRegistration(componentType, factory));
		}

		public IEnumerator<Func<TArgument, TComponent>> GetEnumerator()
		{
			return entries.Select((LazyComponentRegistration e) => e.Factory).GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		private int IndexOfRegistration(Type registrationType)
		{
			for (int i = 0; i < entries.Count; i++)
			{
				if (registrationType == entries[i].ComponentType)
				{
					return i;
				}
			}
			return -1;
		}

		private void EnsureNoDuplicateRegistrationType(Type componentType)
		{
			if (IndexOfRegistration(componentType) != -1)
			{
				throw new InvalidOperationException("A component of type '" + componentType.FullName + "' has already been registered.");
			}
		}

		private int EnsureRegistrationExists<TRegistrationType>()
		{
			int num = IndexOfRegistration(typeof(TRegistrationType));
			if (num == -1)
			{
				throw new InvalidOperationException("A component of type '" + typeof(TRegistrationType).FullName + "' has not been registered.");
			}
			return num;
		}
	}
	internal static class LazyComponentRegistrationListExtensions
	{
		public static TComponent BuildComponentChain<TComponent>(this LazyComponentRegistrationList<TComponent, TComponent> registrations, TComponent innerComponent)
		{
			return registrations.InReverseOrder.Aggregate(innerComponent, (TComponent inner, Func<TComponent, TComponent> factory) => factory(inner));
		}

		public static TComponent BuildComponentChain<TArgument, TComponent>(this LazyComponentRegistrationList<TArgument, TComponent> registrations, TComponent innerComponent, Func<TComponent, TArgument> argumentBuilder)
		{
			return registrations.InReverseOrder.Aggregate(innerComponent, (TComponent inner, Func<TArgument, TComponent> factory) => factory(argumentBuilder(inner)));
		}

		public static List<TComponent> BuildComponentList<TComponent>(this LazyComponentRegistrationList<Nothing, TComponent> registrations)
		{
			return registrations.Select((Func<Nothing, TComponent> factory) => factory(default(Nothing))).ToList();
		}

		public static List<TComponent> BuildComponentList<TArgument, TComponent>(this LazyComponentRegistrationList<TArgument, TComponent> registrations, TArgument argument)
		{
			return registrations.Select((Func<TArgument, TComponent> factory) => factory(argument)).ToList();
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct Nothing
	{
	}
	public sealed class ObjectDescriptor : IObjectDescriptor
	{
		public object? Value { get; private set; }

		public Type Type { get; private set; }

		public Type StaticType { get; private set; }

		public ScalarStyle ScalarStyle { get; private set; }

		public ObjectDescriptor(object? value, Type type, Type staticType)
			: this(value, type, staticType, ScalarStyle.Any)
		{
		}

		public ObjectDescriptor(object? value, Type type, Type staticType, ScalarStyle scalarStyle)
		{
			Value = value;
			Type = type ?? throw new ArgumentNullException("type");
			StaticType = staticType ?? throw new ArgumentNullException("staticType");
			ScalarStyle = scalarStyle;
		}
	}
	public delegate IObjectGraphTraversalStrategy ObjectGraphTraversalStrategyFactory(ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable<IYamlTypeConverter> typeConverters, int maximumRecursion);
	public sealed class PropertyDescriptor : IPropertyDescriptor
	{
		private readonly IPropertyDescriptor baseDescriptor;

		public string Name { get; set; }

		public Type Type => baseDescriptor.Type;

		public Type? TypeOverride
		{
			get
			{
				return baseDescriptor.TypeOverride;
			}
			set
			{
				baseDescriptor.TypeOverride = value;
			}
		}

		public int Order { get; set; }

		public ScalarStyle ScalarStyle
		{
			get
			{
				return baseDescriptor.ScalarStyle;
			}
			set
			{
				baseDescriptor.ScalarStyle = value;
			}
		}

		public bool CanWrite => baseDescriptor.CanWrite;

		public PropertyDescriptor(IPropertyDescriptor baseDescriptor)
		{
			this.baseDescriptor = baseDescriptor;
			Name = baseDescriptor.Name;
		}

		public void Write(object target, object? value)
		{
			baseDescriptor.Write(target, value);
		}

		public T? GetCustomAttribute<T>() where T : Attribute
		{
			return baseDescriptor.GetCustomAttribute<T>();
		}

		public IObjectDescriptor Read(object target)
		{
			return baseDescriptor.Read(target);
		}
	}
	public sealed class Serializer : ISerializer
	{
		private readonly IValueSerializer valueSerializer;

		private readonly EmitterSettings emitterSettings;

		public Serializer()
			: this(new SerializerBuilder().BuildValueSerializer(), EmitterSettings.Default)
		{
		}

		private Serializer(IValueSerializer valueSerializer, EmitterSettings emitterSettings)
		{
			this.valueSerializer = valueSerializer ?? throw new ArgumentNullException("valueSerializer");
			this.emitterSettings = emitterSettings ?? throw new ArgumentNullException("emitterSettings");
		}

		public static Serializer FromValueSerializer(IValueSerializer valueSerializer, EmitterSettings emitterSettings)
		{
			return new Serializer(valueSerializer, emitterSettings);
		}

		public string Serialize(object? graph)
		{
			using StringWriter stringWriter = new StringWriter();
			Serialize(stringWriter, graph);
			return stringWriter.ToString();
		}

		public string Serialize(object? graph, Type type)
		{
			using StringWriter stringWriter = new StringWriter();
			Serialize(stringWriter, graph, type);
			return stringWriter.ToString();
		}

		public void Serialize(TextWriter writer, object? graph)
		{
			Serialize(new Emitter(writer, emitterSettings), graph);
		}

		public void Serialize(TextWriter writer, object? graph, Type type)
		{
			Serialize(new Emitter(writer, emitterSettings), graph, type);
		}

		public void Serialize(IEmitter emitter, object? graph)
		{
			if (emitter == null)
			{
				throw new ArgumentNullException("emitter");
			}
			EmitDocument(emitter, graph, null);
		}

		public void Serialize(IEmitter emitter, object? graph, Type type)
		{
			if (emitter == null)
			{
				throw new ArgumentNullException("emitter");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			EmitDocument(emitter, graph, type);
		}

		private void EmitDocument(IEmitter emitter, object? graph, Type? type)
		{
			emitter.Emit(new YamlDotNet.Core.Events.StreamStart());
			emitter.Emit(new YamlDotNet.Core.Events.DocumentStart());
			valueSerializer.SerializeValue(emitter, graph, type);
			emitter.Emit(new YamlDotNet.Core.Events.DocumentEnd(isImplicit: true));
			emitter.Emit(new YamlDotNet.Core.Events.StreamEnd());
		}
	}
	public sealed class SerializerBuilder : BuilderSkeleton<SerializerBuilder>
	{
		private class ValueSerializer : IValueSerializer
		{
			private readonly IObjectGraphTraversalStrategy traversalStrategy;

			private readonly IEventEmitter eventEmitter;

			private readonly IEnumerable<IYamlTypeConverter> typeConverters;

			private readonly LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories;

			private readonly LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories;

			public ValueSerializer(IObjectGraphTraversalStrategy traversalStrategy, IEventEmitter eventEmitter, IEnumerable<IYamlTypeConverter> typeConverters, LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories, LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories)
			{
				this.traversalStrategy = traversalStrategy;
				this.eventEmitter = eventEmitter;
				this.typeConverters = typeConverters;
				this.preProcessingPhaseObjectGraphVisitorFactories = preProcessingPhaseObjectGraphVisitorFactories;
				this.emissionPhaseObjectGraphVisitorFactories = emissionPhaseObjectGraphVisitorFactories;
			}

			public void SerializeValue(IEmitter emitter, object? value, Type? type)
			{
				Type type2 = type ?? ((value != null) ? value.GetType() : typeof(object));
				Type staticType = type ?? typeof(object);
				ObjectDescriptor graph = new ObjectDescriptor(value, type2, staticType);
				List<IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitors = preProcessingPhaseObjectGraphVisitorFactories.BuildComponentList(typeConverters);
				foreach (IObjectGraphVisitor<Nothing> item in preProcessingPhaseObjectGraphVisitors)
				{
					traversalStrategy.Traverse(graph, item, default(Nothing));
				}
				IObjectGraphVisitor<IEmitter> visitor = emissionPhaseObjectGraphVisitorFactories.BuildComponentChain<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>>(new EmittingObjectGraphVisitor(eventEmitter), (IObjectGraphVisitor<IEmitter> inner) => new EmissionPhaseObjectGraphVisitorArgs(inner, eventEmitter, preProcessingPhaseObjectGraphVisitors, typeConverters, NestedObjectSerializer));
				traversalStrategy.Traverse(graph, visitor, emitter);
				void NestedObjectSerializer(object? v, Type? t)
				{
					SerializeValue(emitter, v, t);
				}
			}
		}

		private ObjectGraphTraversalStrategyFactory objectGraphTraversalStrategyFactory;

		private readonly LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories;

		private readonly LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories;

		private readonly LazyComponentRegistrationList<IEventEmitter, IEventEmitter> eventEmitterFactories;

		private readonly IDictionary<Type, TagName> tagMappings = new Dictionary<Type, TagName>();

		private readonly IObjectFactory objectFactory;

		private int maximumRecursion = 50;

		private EmitterSettings emitterSettings = EmitterSettings.Default;

		private DefaultValuesHandling defaultValuesHandlingConfiguration;

		private ScalarStyle defaultScalarStyle;

		private bool quoteNecessaryStrings;

		private bool quoteYaml1_1Strings;

		protected override SerializerBuilder Self => this;

		public SerializerBuilder()
			: base((ITypeResolver)new DynamicTypeResolver())
		{
			typeInspectorFactories.Add(typeof(CachedTypeInspector), (ITypeInspector inner) => new CachedTypeInspector(inner));
			typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), (ITypeInspector inner) => (!(namingConvention is NullNamingConvention)) ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
			typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), (ITypeInspector inner) => new YamlAttributesTypeInspector(inner));
			typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), (ITypeInspector inner) => (overrides == null) ? inner : new YamlAttributeOverridesInspector(inner, overrides.Clone()));
			preProcessingPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> { 
			{
				typeof(AnchorAssigner),
				(IEnumerable<IYamlTypeConverter> typeConverters) => new AnchorAssigner(typeConverters)
			} };
			emissionPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>>
			{
				{
					typeof(CustomSerializationObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new CustomSerializationObjectGraphVisitor(args.InnerVisitor, args.TypeConverters, args.NestedObjectSerializer)
				},
				{
					typeof(AnchorAssigningObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, args.GetPreProcessingPhaseObjectGraphVisitor<AnchorAssigner>())
				},
				{
					typeof(DefaultValuesObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new DefaultValuesObjectGraphVisitor(defaultValuesHandlingConfiguration, args.InnerVisitor, new DefaultObjectFactory())
				},
				{
					typeof(CommentsObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new CommentsObjectGraphVisitor(args.InnerVisitor)
				}
			};
			eventEmitterFactories = new LazyComponentRegistrationList<IEventEmitter, IEventEmitter> { 
			{
				typeof(TypeAssigningEventEmitter),
				(IEventEmitter inner) => new TypeAssigningEventEmitter(inner, requireTagWhenStaticAndActualTypesAreDifferent: false, tagMappings, quoteNecessaryStrings, quoteYaml1_1Strings, defaultScalarStyle, yamlFormatter)
			} };
			objectFactory = new DefaultObjectFactory();
			objectGraphTraversalStrategyFactory = (ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable<IYamlTypeConverter> typeConverters, int maximumRecursion) => new FullObjectGraphTraversalStrategy(typeInspector, typeResolver, maximumRecursion, namingConvention, objectFactory);
		}

		public SerializerBuilder WithQuotingNecessaryStrings(bool quoteYaml1_1Strings = false)
		{
			quoteNecessaryStrings = true;
			this.quoteYaml1_1Strings = quoteYaml1_1Strings;
			return this;
		}

		public SerializerBuilder WithDefaultScalarStyle(ScalarStyle style)
		{
			defaultScalarStyle = style;
			return this;
		}

		public SerializerBuilder WithMaximumRecursion(int maximumRecursion)
		{
			if (maximumRecursion <= 0)
			{
				throw new ArgumentOutOfRangeException("maximumRecursion", $"The maximum recursion specified ({maximumRecursion}) is invalid. It should be a positive integer.");
			}
			this.maximumRecursion = maximumRecursion;
			return this;
		}

		public SerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory) where TEventEmitter : IEventEmitter
		{
			return WithEventEmitter(eventEmitterFactory, delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> w)
			{
				w.OnTop();
			});
		}

		public SerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory, Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where) where TEventEmitter : IEventEmitter
		{
			if (eventEmitterFactory == null)
			{
				throw new ArgumentNullException("eventEmitterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), (IEventEmitter inner) => eventEmitterFactory(inner)));
			return Self;
		}

		public SerializerBuilder WithEventEmitter<TEventEmitter>(WrapperFactory<IEventEmitter, IEventEmitter, TEventEmitter> eventEmitterFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IEventEmitter>> where) where TEventEmitter : IEventEmitter
		{
			if (eventEmitterFactory == null)
			{
				throw new ArgumentNullException("eventEmitterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(eventEmitterFactories.CreateTrackingRegistrationLocationSelector(typeof(TEventEmitter), (IEventEmitter wrapped, IEventEmitter inner) => eventEmitterFactory(wrapped, inner)));
			return Self;
		}

		public SerializerBuilder WithoutEventEmitter<TEventEmitter>() where TEventEmitter : IEventEmitter
		{
			return WithoutEventEmitter(typeof(TEventEmitter));
		}

		public SerializerBuilder WithoutEventEmitter(Type eventEmitterType)
		{
			if (eventEmitterType == null)
			{
				throw new ArgumentNullException("eventEmitterType");
			}
			eventEmitterFactories.Remove(eventEmitterType);
			return this;
		}

		public override SerializerBuilder WithTagMapping(TagName tag, Type type)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (tagMappings.TryGetValue(type, out var value))
			{
				throw new ArgumentException($"Type already has a registered tag '{value}' for type '{type.FullName}'", "type");
			}
			tagMappings.Add(type, tag);
			return this;
		}

		public SerializerBuilder WithoutTagMapping(Type type)
		{
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (!tagMappings.Remove(type))
			{
				throw new KeyNotFoundException("Tag for type '" + type.FullName + "' is not registered");
			}
			return this;
		}

		public SerializerBuilder EnsureRoundtrip()
		{
			objectGraphTraversalStrategyFactory = (ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable<IYamlTypeConverter> typeConverters, int maximumRecursion) => new RoundtripObjectGraphTraversalStrategy(typeConverters, typeInspector, typeResolver, maximumRecursion, namingConvention, settings, objectFactory);
			WithEventEmitter((IEventEmitter inner) => new TypeAssigningEventEmitter(inner, requireTagWhenStaticAndActualTypesAreDifferent: true, tagMappings, quoteNecessaryStrings, quoteYaml1_1Strings, defaultScalarStyle, yamlFormatter), delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> loc)
			{
				loc.InsteadOf<TypeAssigningEventEmitter>();
			});
			return WithTypeInspector((ITypeInspector inner) => new ReadableAndWritablePropertiesTypeInspector(inner), delegate(IRegistrationLocationSelectionSyntax<ITypeInspector> loc)
			{
				loc.OnBottom();
			});
		}

		public SerializerBuilder DisableAliases()
		{
			preProcessingPhaseObjectGraphVisitorFactories.Remove(typeof(AnchorAssigner));
			emissionPhaseObjectGraphVisitorFactories.Remove(typeof(AnchorAssigningObjectGraphVisitor));
			return this;
		}

		[Obsolete("The default behavior is now to always emit default values, thefore calling this method has no effect. This behavior is now controlled by ConfigureDefaultValuesHandling.", true)]
		public SerializerBuilder EmitDefaults()
		{
			return ConfigureDefaultValuesHandling(DefaultValuesHandling.Preserve);
		}

		public SerializerBuilder ConfigureDefaultValuesHandling(DefaultValuesHandling configuration)
		{
			defaultValuesHandlingConfiguration = configuration;
			return this;
		}

		public SerializerBuilder JsonCompatible()
		{
			emitterSettings = emitterSettings.WithMaxSimpleKeyLength(int.MaxValue).WithoutAnchorName();
			return WithTypeConverter(new YamlDotNet.Serialization.Converters.GuidConverter(jsonCompatible: true), delegate(IRegistrationLocationSelectionSyntax<IYamlTypeConverter> w)
			{
				w.InsteadOf<YamlDotNet.Serialization.Converters.GuidConverter>();
			}).WithTypeConverter(new YamlDotNet.Serialization.Converters.DateTimeConverter(DateTimeKind.Utc, null, true)).WithEventEmitter((IEventEmitter inner) => new JsonEventEmitter(inner, yamlFormatter), delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> loc)
			{
				loc.InsteadOf<TypeAssigningEventEmitter>();
			});
		}

		public SerializerBuilder WithNewLine(string newLine)
		{
			emitterSettings = emitterSettings.WithNewLine(newLine);
			return this;
		}

		public SerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(TObjectGraphVisitor objectGraphVisitor) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			return WithPreProcessingPhaseObjectGraphVisitor(objectGraphVisitor, delegate(IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>> w)
			{
				w.OnTop();
			});
		}

		public SerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(TObjectGraphVisitor objectGraphVisitor, Action<IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			if (objectGraphVisitor == null)
			{
				throw new ArgumentNullException("objectGraphVisitor");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(preProcessingPhaseObjectGraphVisitorFactories.CreateRegistrationLocationSelector(typeof(TObjectGraphVisitor), (IEnumerable<IYamlTypeConverter> _) => objectGraphVisitor));
			return this;
		}

		public SerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(WrapperFactory<IObjectGraphVisitor<Nothing>, TObjectGraphVisitor> objectGraphVisitorFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			if (objectGraphVisitorFactory == null)
			{
				throw new ArgumentNullException("objectGraphVisitorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(preProcessingPhaseObjectGraphVisitorFactories.CreateTrackingRegistrationLocationSelector(typeof(TObjectGraphVisitor), (IObjectGraphVisitor<Nothing> wrapped, IEnumerable<IYamlTypeConverter> _) => objectGraphVisitorFactory(wrapped)));
			return this;
		}

		public SerializerBuilder WithoutPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>() where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			return WithoutPreProcessingPhaseObjectGraphVisitor(typeof(TObjectGraphVisitor));
		}

		public SerializerBuilder WithoutPreProcessingPhaseObjectGraphVisitor(Type objectGraphVisitorType)
		{
			if (objectGraphVisitorType == null)
			{
				throw new ArgumentNullException("objectGraphVisitorType");
			}
			preProcessingPhaseObjectGraphVisitorFactories.Remove(objectGraphVisitorType);
			return this;
		}

		public SerializerBuilder WithObjectGraphTraversalStrategyFactory(ObjectGraphTraversalStrategyFactory objectGraphTraversalStrategyFactory)
		{
			this.objectGraphTraversalStrategyFactory = objectGraphTraversalStrategyFactory;
			return this;
		}

		public SerializerBuilder WithEmissionPhaseObjectGraphVisitor<TObjectGraphVisitor>(Func<EmissionPhaseObjectGraphVisitorArgs, TObjectGraphVisitor> objectGraphVisitorFactory) where TObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
		{
			return WithEmissionPhaseObjectGraphVisitor(objectGraphVisitorFactory, delegate(IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<IEmitter>> w)
			{
				w.OnTop();
			});
		}

		public SerializerBuilder WithEmissionPhaseObjectGraphVisitor<TObjectGraphVisitor>(Func<EmissionPhaseObjectGraphVisitorArgs, TObjectGraphVisitor> objectGraphVisitorFactory, Action<IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<IEmitter>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
		{
			if (objectGraphVisitorFactory == null)
			{
				throw new ArgumentNullException("objectGraphVisitorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(emissionPhaseObjectGraphVisitorFactories.CreateRegistrationLocationSelector(typeof(TObjectGraphVisitor), (EmissionPhaseObjectGraphVisitorArgs args) => objectGraphVisitorFactory(args)));
			return this;
		}

		public SerializerBuilder WithEmissionPhaseObjectGraphVisitor<TObjectGraphVisitor>(WrapperFactory<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>, TObjectGraphVisitor> objectGraphVisitorFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IObjectGraphVisitor<IEmitter>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
		{
			if (objectGraphVisitorFactory == null)
			{
				throw new ArgumentNullException("objectGraphVisitorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(emissionPhaseObjectGraphVisitorFactories.CreateTrackingRegistrationLocationSelector(typeof(TObjectGraphVisitor), (IObjectGraphVisitor<IEmitter> wrapped, EmissionPhaseObjectGraphVisitorArgs args) => objectGraphVisitorFactory(wrapped, args)));
			return this;
		}

		public SerializerBuilder WithoutEmissionPhaseObjectGraphVisitor<TObjectGraphVisitor>() where TObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
		{
			return WithoutEmissionPhaseObjectGraphVisitor(typeof(TObjectGraphVisitor));
		}

		public SerializerBuilder WithoutEmissionPhaseObjectGraphVisitor(Type objectGraphVisitorType)
		{
			if (objectGraphVisitorType == null)
			{
				throw new ArgumentNullException("objectGraphVisitorType");
			}
			emissionPhaseObjectGraphVisitorFactories.Remove(objectGraphVisitorType);
			return this;
		}

		public SerializerBuilder WithIndentedSequences()
		{
			emitterSettings = emitterSettings.WithIndentedSequences();
			return this;
		}

		public ISerializer Build()
		{
			return Serializer.FromValueSerializer(BuildValueSerializer(), emitterSettings);
		}

		public IValueSerializer BuildValueSerializer()
		{
			IEnumerable<IYamlTypeConverter> typeConverters = BuildTypeConverters();
			ITypeInspector typeInspector = BuildTypeInspector();
			IObjectGraphTraversalStrategy traversalStrategy = objectGraphTraversalStrategyFactory(typeInspector, typeResolver, typeConverters, maximumRecursion);
			IEventEmitter eventEmitter = eventEmitterFactories.BuildComponentChain(new WriterEventEmitter());
			return new ValueSerializer(traversalStrategy, eventEmitter, typeConverters, preProcessingPhaseObjectGraphVisitorFactories.Clone(), emissionPhaseObjectGraphVisitorFactories.Clone());
		}

		internal ITypeInspector BuildTypeInspector()
		{
			ITypeInspector typeInspector = new ReadablePropertiesTypeInspector(typeResolver, includeNonPublicProperties);
			if (!ignoreFields)
			{
				typeInspector = new CompositeTypeInspector(new ReadableFieldsTypeInspector(typeResolver), typeInspector);
			}
			return typeInspectorFactories.BuildComponentChain(typeInspector);
		}
	}
	public class Settings
	{
		public bool AllowPrivateConstructors { get; set; }
	}
	public abstract class StaticBuilderSkeleton<TBuilder> where TBuilder : StaticBuilderSkeleton<TBuilder>
	{
		internal INamingConvention namingConvention = NullNamingConvention.Instance;

		internal ITypeResolver typeResolver;

		internal readonly LazyComponentRegistrationList<Nothing, IYamlTypeConverter> typeConverterFactories;

		internal readonly LazyComponentRegistrationList<ITypeInspector, ITypeInspector> typeInspectorFactories;

		internal bool includeNonPublicProperties;

		internal Settings settings;

		internal YamlFormatter yamlFormatter = YamlFormatter.Default;

		protected abstract TBuilder Self { get; }

		internal StaticBuilderSkeleton(ITypeResolver typeResolver)
		{
			typeConverterFactories = new LazyComponentRegistrationList<Nothing, IYamlTypeConverter> { 
			{
				typeof(YamlDotNet.Serialization.Converters.GuidConverter),
				(Nothing _) => new YamlDotNet.Serialization.Converters.GuidConverter(jsonCompatible: false)
			} };
			typeInspectorFactories = new LazyComponentRegistrationList<ITypeInspector, ITypeInspector>();
			this.typeResolver = typeResolver ?? throw new ArgumentNullException("typeResolver");
			settings = new Settings();
		}

		public TBuilder WithNamingConvention(INamingConvention namingConvention)
		{
			this.namingConvention = namingConvention ?? throw new ArgumentNullException("namingConvention");
			return Self;
		}

		public TBuilder WithTypeResolver(ITypeResolver typeResolver)
		{
			this.typeResolver = typeResolver ?? throw new ArgumentNullException("typeResolver");
			return Self;
		}

		public abstract TBuilder WithTagMapping(TagName tag, Type type);

		public TBuilder WithTypeConverter(IYamlTypeConverter typeConverter)
		{
			return WithTypeConverter(typeConverter, delegate(IRegistrationLocationSelectionSyntax<IYamlTypeConverter> w)
			{
				w.OnTop();
			});
		}

		public TBuilder WithTypeConverter(IYamlTypeConverter typeConverter, Action<IRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where)
		{
			if (typeConverter == null)
			{
				throw new ArgumentNullException("typeConverter");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeConverterFactories.CreateRegistrationLocationSelector(typeConverter.GetType(), (Nothing _) => typeConverter));
			return Self;
		}

		public TBuilder WithTypeConverter<TYamlTypeConverter>(WrapperFactory<IYamlTypeConverter, IYamlTypeConverter> typeConverterFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where) where TYamlTypeConverter : IYamlTypeConverter
		{
			if (typeConverterFactory == null)
			{
				throw new ArgumentNullException("typeConverterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeConverterFactories.CreateTrackingRegistrationLocationSelector(typeof(TYamlTypeConverter), (IYamlTypeConverter wrapped, Nothing _) => typeConverterFactory(wrapped)));
			return Self;
		}

		public TBuilder WithoutTypeConverter<TYamlTypeConverter>() where TYamlTypeConverter : IYamlTypeConverter
		{
			return WithoutTypeConverter(typeof(TYamlTypeConverter));
		}

		public TBuilder WithoutTypeConverter(Type converterType)
		{
			if (converterType == null)
			{
				throw new ArgumentNullException("converterType");
			}
			typeConverterFactories.Remove(converterType);
			return Self;
		}

		public TBuilder WithTypeInspector<TTypeInspector>(Func<ITypeInspector, TTypeInspector> typeInspectorFactory) where TTypeInspector : ITypeInspector
		{
			return WithTypeInspector(typeInspectorFactory, delegate(IRegistrationLocationSelectionSyntax<ITypeInspector> w)
			{
				w.OnTop();
			});
		}

		public TBuilder WithTypeInspector<TTypeInspector>(Func<ITypeInspector, TTypeInspector> typeInspectorFactory, Action<IRegistrationLocationSelectionSyntax<ITypeInspector>> where) where TTypeInspector : ITypeInspector
		{
			if (typeInspectorFactory == null)
			{
				throw new ArgumentNullException("typeInspectorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeInspectorFactories.CreateRegistrationLocationSelector(typeof(TTypeInspector), (ITypeInspector inner) => typeInspectorFactory(inner)));
			return Self;
		}

		public TBuilder WithTypeInspector<TTypeInspector>(WrapperFactory<ITypeInspector, ITypeInspector, TTypeInspector> typeInspectorFactory, Action<ITrackingRegistrationLocationSelectionSyntax<ITypeInspector>> where) where TTypeInspector : ITypeInspector
		{
			if (typeInspectorFactory == null)
			{
				throw new ArgumentNullException("typeInspectorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(typeInspectorFactories.CreateTrackingRegistrationLocationSelector(typeof(TTypeInspector), (ITypeInspector wrapped, ITypeInspector inner) => typeInspectorFactory(wrapped, inner)));
			return Self;
		}

		public TBuilder WithoutTypeInspector<TTypeInspector>() where TTypeInspector : ITypeInspector
		{
			return WithoutTypeInspector(typeof(TTypeInspector));
		}

		public TBuilder WithoutTypeInspector(Type inspectorType)
		{
			if (inspectorType == null)
			{
				throw new ArgumentNullException("inspectorType");
			}
			typeInspectorFactories.Remove(inspectorType);
			return Self;
		}

		public TBuilder WithYamlFormatter(YamlFormatter formatter)
		{
			yamlFormatter = formatter ?? throw new ArgumentNullException("formatter");
			return Self;
		}

		protected IEnumerable<IYamlTypeConverter> BuildTypeConverters()
		{
			return typeConverterFactories.BuildComponentList();
		}
	}
	public abstract class StaticContext
	{
		public virtual bool IsKnownType(Type type)
		{
			throw new NotImplementedException();
		}

		public virtual ITypeResolver GetTypeResolver()
		{
			throw new NotImplementedException();
		}

		public virtual StaticObjectFactory GetFactory()
		{
			throw new NotImplementedException();
		}

		public virtual ITypeInspector GetTypeInspector()
		{
			throw new NotImplementedException();
		}
	}
	public sealed class StaticDeserializerBuilder : StaticBuilderSkeleton<StaticDeserializerBuilder>
	{
		private readonly StaticContext context;

		private readonly StaticObjectFactory factory;

		private readonly LazyComponentRegistrationList<Nothing, INodeDeserializer> nodeDeserializerFactories;

		private readonly LazyComponentRegistrationList<Nothing, INodeTypeResolver> nodeTypeResolverFactories;

		private readonly Dictionary<TagName, Type> tagMappings;

		private readonly ITypeConverter typeConverter;

		private readonly Dictionary<Type, Type> typeMappings;

		private bool ignoreUnmatched;

		private bool duplicateKeyChecking;

		private bool attemptUnknownTypeDeserialization;

		protected override StaticDeserializerBuilder Self => this;

		public StaticDeserializerBuilder(StaticContext context)
			: base(context.GetTypeResolver())
		{
			this.context = context;
			factory = context.GetFactory();
			typeMappings = new Dictionary<Type, Type>();
			tagMappings = new Dictionary<TagName, Type>
			{
				{
					FailsafeSchema.Tags.Map,
					typeof(Dictionary<object, object>)
				},
				{
					FailsafeSchema.Tags.Str,
					typeof(string)
				},
				{
					JsonSchema.Tags.Bool,
					typeof(bool)
				},
				{
					JsonSchema.Tags.Float,
					typeof(double)
				},
				{
					JsonSchema.Tags.Int,
					typeof(int)
				},
				{
					DefaultSchema.Tags.Timestamp,
					typeof(DateTime)
				}
			};
			typeInspectorFactories.Add(typeof(CachedTypeInspector), (ITypeInspector inner) => new CachedTypeInspector(inner));
			typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), (ITypeInspector inner) => (!(namingConvention is NullNamingConvention)) ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
			typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), (ITypeInspector inner) => new YamlAttributesTypeInspector(inner));
			nodeDeserializerFactories = new LazyComponentRegistrationList<Nothing, INodeDeserializer>
			{
				{
					typeof(YamlConvertibleNodeDeserializer),
					(Nothing _) => new YamlConvertibleNodeDeserializer(factory)
				},
				{
					typeof(YamlSerializableNodeDeserializer),
					(Nothing _) => new YamlSerializableNodeDeserializer(factory)
				},
				{
					typeof(TypeConverterNodeDeserializer),
					(Nothing _) => new TypeConverterNodeDeserializer(BuildTypeConverters())
				},
				{
					typeof(NullNodeDeserializer),
					(Nothing _) => new NullNodeDeserializer()
				},
				{
					typeof(ScalarNodeDeserializer),
					(Nothing _) => new ScalarNodeDeserializer(attemptUnknownTypeDeserialization, typeConverter, yamlFormatter)
				},
				{
					typeof(StaticArrayNodeDeserializer),
					(Nothing _) => new StaticArrayNodeDeserializer(factory)
				},
				{
					typeof(StaticDictionaryNodeDeserializer),
					(Nothing _) => new StaticDictionaryNodeDeserializer(factory, duplicateKeyChecking)
				},
				{
					typeof(StaticCollectionNodeDeserializer),
					(Nothing _) => new StaticCollectionNodeDeserializer(factory)
				},
				{
					typeof(ObjectNodeDeserializer),
					(Nothing _) => new ObjectNodeDeserializer(factory, BuildTypeInspector(), ignoreUnmatched, duplicateKeyChecking, typeConverter)
				}
			};
			nodeTypeResolverFactories = new LazyComponentRegistrationList<Nothing, INodeTypeResolver>
			{
				{
					typeof(MappingNodeTypeResolver),
					(Nothing _) => new MappingNodeTypeResolver(typeMappings)
				},
				{
					typeof(YamlConvertibleTypeResolver),
					(Nothing _) => new YamlConvertibleTypeResolver()
				},
				{
					typeof(YamlSerializableTypeResolver),
					(Nothing _) => new YamlSerializableTypeResolver()
				},
				{
					typeof(TagNodeTypeResolver),
					(Nothing _) => new TagNodeTypeResolver(tagMappings)
				},
				{
					typeof(PreventUnknownTagsNodeTypeResolver),
					(Nothing _) => new PreventUnknownTagsNodeTypeResolver()
				},
				{
					typeof(DefaultContainersNodeTypeResolver),
					(Nothing _) => new DefaultContainersNodeTypeResolver()
				}
			};
			typeConverter = new NullTypeConverter();
		}

		internal ITypeInspector BuildTypeInspector()
		{
			ITypeInspector typeInspector = context.GetTypeInspector();
			return typeInspectorFactories.BuildComponentChain(typeInspector);
		}

		public StaticDeserializerBuilder WithAttemptingUnquotedStringTypeDeserialization()
		{
			attemptUnknownTypeDeserialization = true;
			return this;
		}

		public StaticDeserializerBuilder WithNodeDeserializer(INodeDeserializer nodeDeserializer)
		{
			return WithNodeDeserializer(nodeDeserializer, delegate(IRegistrationLocationSelectionSyntax<INodeDeserializer> w)
			{
				w.OnTop();
			});
		}

		public StaticDeserializerBuilder WithNodeDeserializer(INodeDeserializer nodeDeserializer, Action<IRegistrationLocationSelectionSyntax<INodeDeserializer>> where)
		{
			if (nodeDeserializer == null)
			{
				throw new ArgumentNullException("nodeDeserializer");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeDeserializerFactories.CreateRegistrationLocationSelector(nodeDeserializer.GetType(), (Nothing _) => nodeDeserializer));
			return this;
		}

		public StaticDeserializerBuilder WithNodeDeserializer<TNodeDeserializer>(WrapperFactory<INodeDeserializer, TNodeDeserializer> nodeDeserializerFactory, Action<ITrackingRegistrationLocationSelectionSyntax<INodeDeserializer>> where) where TNodeDeserializer : INodeDeserializer
		{
			if (nodeDeserializerFactory == null)
			{
				throw new ArgumentNullException("nodeDeserializerFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeDeserializerFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeDeserializer), (INodeDeserializer wrapped, Nothing _) => nodeDeserializerFactory(wrapped)));
			return this;
		}

		public StaticDeserializerBuilder WithoutNodeDeserializer<TNodeDeserializer>() where TNodeDeserializer : INodeDeserializer
		{
			return WithoutNodeDeserializer(typeof(TNodeDeserializer));
		}

		public StaticDeserializerBuilder WithoutNodeDeserializer(Type nodeDeserializerType)
		{
			if (nodeDeserializerType == null)
			{
				throw new ArgumentNullException("nodeDeserializerType");
			}
			nodeDeserializerFactories.Remove(nodeDeserializerType);
			return this;
		}

		public StaticDeserializerBuilder WithTypeDiscriminatingNodeDeserializer(Action<ITypeDiscriminatingNodeDeserializerOptions> configureTypeDiscriminatingNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
		{
			TypeDiscriminatingNodeDeserializerOptions typeDiscriminatingNodeDeserializerOptions = new TypeDiscriminatingNodeDeserializerOptions();
			configureTypeDiscriminatingNodeDeserializerOptions(typeDiscriminatingNodeDeserializerOptions);
			TypeDiscriminatingNodeDeserializer nodeDeserializer = new TypeDiscriminatingNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), typeDiscriminatingNodeDeserializerOptions.discriminators, maxDepth, maxLength);
			return WithNodeDeserializer(nodeDeserializer, delegate(IRegistrationLocationSelectionSyntax<INodeDeserializer> s)
			{
				s.Before<DictionaryNodeDeserializer>();
			});
		}

		public StaticDeserializerBuilder WithNodeTypeResolver(INodeTypeResolver nodeTypeResolver)
		{
			return WithNodeTypeResolver(nodeTypeResolver, delegate(IRegistrationLocationSelectionSyntax<INodeTypeResolver> w)
			{
				w.OnTop();
			});
		}

		public StaticDeserializerBuilder WithNodeTypeResolver(INodeTypeResolver nodeTypeResolver, Action<IRegistrationLocationSelectionSyntax<INodeTypeResolver>> where)
		{
			if (nodeTypeResolver == null)
			{
				throw new ArgumentNullException("nodeTypeResolver");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeTypeResolverFactories.CreateRegistrationLocationSelector(nodeTypeResolver.GetType(), (Nothing _) => nodeTypeResolver));
			return this;
		}

		public StaticDeserializerBuilder WithNodeTypeResolver<TNodeTypeResolver>(WrapperFactory<INodeTypeResolver, TNodeTypeResolver> nodeTypeResolverFactory, Action<ITrackingRegistrationLocationSelectionSyntax<INodeTypeResolver>> where) where TNodeTypeResolver : INodeTypeResolver
		{
			if (nodeTypeResolverFactory == null)
			{
				throw new ArgumentNullException("nodeTypeResolverFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(nodeTypeResolverFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeTypeResolver), (INodeTypeResolver wrapped, Nothing _) => nodeTypeResolverFactory(wrapped)));
			return this;
		}

		public StaticDeserializerBuilder WithoutNodeTypeResolver<TNodeTypeResolver>() where TNodeTypeResolver : INodeTypeResolver
		{
			return WithoutNodeTypeResolver(typeof(TNodeTypeResolver));
		}

		public StaticDeserializerBuilder WithoutNodeTypeResolver(Type nodeTypeResolverType)
		{
			if (nodeTypeResolverType == null)
			{
				throw new ArgumentNullException("nodeTypeResolverType");
			}
			nodeTypeResolverFactories.Remove(nodeTypeResolverType);
			return this;
		}

		public override StaticDeserializerBuilder WithTagMapping(TagName tag, Type type)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (tagMappings.TryGetValue(tag, out Type value))
			{
				throw new ArgumentException($"Type already has a registered type '{value.FullName}' for tag '{tag}'", "tag");
			}
			tagMappings.Add(tag, type);
			return this;
		}

		public StaticDeserializerBuilder WithTypeMapping<TInterface, TConcrete>() where TConcrete : TInterface
		{
			Type typeFromHandle = typeof(TInterface);
			Type typeFromHandle2 = typeof(TConcrete);
			if (!typeFromHandle.IsAssignableFrom(typeFromHandle2))
			{
				throw new InvalidOperationException("The type '" + typeFromHandle2.Name + "' does not implement interface '" + typeFromHandle.Name + "'.");
			}
			if (typeMappings.ContainsKey(typeFromHandle))
			{
				typeMappings[typeFromHandle] = typeFromHandle2;
			}
			else
			{
				typeMappings.Add(typeFromHandle, typeFromHandle2);
			}
			return this;
		}

		public StaticDeserializerBuilder WithoutTagMapping(TagName tag)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (!tagMappings.Remove(tag))
			{
				throw new KeyNotFoundException($"Tag '{tag}' is not registered");
			}
			return this;
		}

		public StaticDeserializerBuilder IgnoreUnmatchedProperties()
		{
			ignoreUnmatched = true;
			return this;
		}

		public StaticDeserializerBuilder WithDuplicateKeyChecking()
		{
			duplicateKeyChecking = true;
			return this;
		}

		public IDeserializer Build()
		{
			return Deserializer.FromValueDeserializer(BuildValueDeserializer());
		}

		public IValueDeserializer BuildValueDeserializer()
		{
			return new AliasValueDeserializer(new NodeValueDeserializer(nodeDeserializerFactories.BuildComponentList(), nodeTypeResolverFactories.BuildComponentList(), typeConverter));
		}
	}
	public sealed class StaticSerializerBuilder : StaticBuilderSkeleton<StaticSerializerBuilder>
	{
		private class ValueSerializer : IValueSerializer
		{
			private readonly IObjectGraphTraversalStrategy traversalStrategy;

			private readonly IEventEmitter eventEmitter;

			private readonly IEnumerable<IYamlTypeConverter> typeConverters;

			private readonly LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories;

			private readonly LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories;

			public ValueSerializer(IObjectGraphTraversalStrategy traversalStrategy, IEventEmitter eventEmitter, IEnumerable<IYamlTypeConverter> typeConverters, LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories, LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories)
			{
				this.traversalStrategy = traversalStrategy;
				this.eventEmitter = eventEmitter;
				this.typeConverters = typeConverters;
				this.preProcessingPhaseObjectGraphVisitorFactories = preProcessingPhaseObjectGraphVisitorFactories;
				this.emissionPhaseObjectGraphVisitorFactories = emissionPhaseObjectGraphVisitorFactories;
			}

			public void SerializeValue(IEmitter emitter, object? value, Type? type)
			{
				Type type2 = type ?? ((value != null) ? value.GetType() : typeof(object));
				Type staticType = type ?? typeof(object);
				ObjectDescriptor graph = new ObjectDescriptor(value, type2, staticType);
				List<IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitors = preProcessingPhaseObjectGraphVisitorFactories.BuildComponentList(typeConverters);
				foreach (IObjectGraphVisitor<Nothing> item in preProcessingPhaseObjectGraphVisitors)
				{
					traversalStrategy.Traverse(graph, item, default(Nothing));
				}
				IObjectGraphVisitor<IEmitter> visitor = emissionPhaseObjectGraphVisitorFactories.BuildComponentChain<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>>(new EmittingObjectGraphVisitor(eventEmitter), (IObjectGraphVisitor<IEmitter> inner) => new EmissionPhaseObjectGraphVisitorArgs(inner, eventEmitter, preProcessingPhaseObjectGraphVisitors, typeConverters, NestedObjectSerializer));
				traversalStrategy.Traverse(graph, visitor, emitter);
				void NestedObjectSerializer(object? v, Type? t)
				{
					SerializeValue(emitter, v, t);
				}
			}
		}

		private readonly StaticContext context;

		private readonly StaticObjectFactory factory;

		private ObjectGraphTraversalStrategyFactory objectGraphTraversalStrategyFactory;

		private readonly LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> preProcessingPhaseObjectGraphVisitorFactories;

		private readonly LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>> emissionPhaseObjectGraphVisitorFactories;

		private readonly LazyComponentRegistrationList<IEventEmitter, IEventEmitter> eventEmitterFactories;

		private readonly IDictionary<Type, TagName> tagMappings = new Dictionary<Type, TagName>();

		private int maximumRecursion = 50;

		private EmitterSettings emitterSettings = EmitterSettings.Default;

		private DefaultValuesHandling defaultValuesHandlingConfiguration;

		private bool quoteNecessaryStrings;

		private bool quoteYaml1_1Strings;

		private ScalarStyle defaultScalarStyle;

		protected override StaticSerializerBuilder Self => this;

		public StaticSerializerBuilder(StaticContext context)
			: base((ITypeResolver)new DynamicTypeResolver())
		{
			this.context = context;
			factory = context.GetFactory();
			typeInspectorFactories.Add(typeof(CachedTypeInspector), (ITypeInspector inner) => new CachedTypeInspector(inner));
			typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), (ITypeInspector inner) => (!(namingConvention is NullNamingConvention)) ? new NamingConventionTypeInspector(inner, namingConvention) : inner);
			typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), (ITypeInspector inner) => new YamlAttributesTypeInspector(inner));
			preProcessingPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList<IEnumerable<IYamlTypeConverter>, IObjectGraphVisitor<Nothing>> { 
			{
				typeof(AnchorAssigner),
				(IEnumerable<IYamlTypeConverter> typeConverters) => new AnchorAssigner(typeConverters)
			} };
			emissionPhaseObjectGraphVisitorFactories = new LazyComponentRegistrationList<EmissionPhaseObjectGraphVisitorArgs, IObjectGraphVisitor<IEmitter>>
			{
				{
					typeof(CustomSerializationObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new CustomSerializationObjectGraphVisitor(args.InnerVisitor, args.TypeConverters, args.NestedObjectSerializer)
				},
				{
					typeof(AnchorAssigningObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, args.GetPreProcessingPhaseObjectGraphVisitor<AnchorAssigner>())
				},
				{
					typeof(DefaultValuesObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new DefaultValuesObjectGraphVisitor(defaultValuesHandlingConfiguration, args.InnerVisitor, factory)
				},
				{
					typeof(CommentsObjectGraphVisitor),
					(EmissionPhaseObjectGraphVisitorArgs args) => new CommentsObjectGraphVisitor(args.InnerVisitor)
				}
			};
			eventEmitterFactories = new LazyComponentRegistrationList<IEventEmitter, IEventEmitter> { 
			{
				typeof(TypeAssigningEventEmitter),
				(IEventEmitter inner) => new TypeAssigningEventEmitter(inner, requireTagWhenStaticAndActualTypesAreDifferent: false, tagMappings, quoteNecessaryStrings, quoteYaml1_1Strings, defaultScalarStyle, yamlFormatter)
			} };
			objectGraphTraversalStrategyFactory = (ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable<IYamlTypeConverter> typeConverters, int maximumRecursion) => new FullObjectGraphTraversalStrategy(typeInspector, typeResolver, maximumRecursion, namingConvention, factory);
		}

		public StaticSerializerBuilder WithQuotingNecessaryStrings(bool quoteYaml1_1Strings = false)
		{
			quoteNecessaryStrings = true;
			this.quoteYaml1_1Strings = quoteYaml1_1Strings;
			return this;
		}

		public StaticSerializerBuilder WithQuotingNecessaryStrings()
		{
			quoteNecessaryStrings = true;
			return this;
		}

		public StaticSerializerBuilder WithDefaultScalarStyle(ScalarStyle style)
		{
			defaultScalarStyle = style;
			return this;
		}

		public StaticSerializerBuilder WithMaximumRecursion(int maximumRecursion)
		{
			if (maximumRecursion <= 0)
			{
				throw new ArgumentOutOfRangeException("maximumRecursion", $"The maximum recursion specified ({maximumRecursion}) is invalid. It should be a positive integer.");
			}
			this.maximumRecursion = maximumRecursion;
			return this;
		}

		public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory) where TEventEmitter : IEventEmitter
		{
			return WithEventEmitter(eventEmitterFactory, delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> w)
			{
				w.OnTop();
			});
		}

		public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory, Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where) where TEventEmitter : IEventEmitter
		{
			if (eventEmitterFactory == null)
			{
				throw new ArgumentNullException("eventEmitterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), (IEventEmitter inner) => eventEmitterFactory(inner)));
			return Self;
		}

		public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(WrapperFactory<IEventEmitter, IEventEmitter, TEventEmitter> eventEmitterFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IEventEmitter>> where) where TEventEmitter : IEventEmitter
		{
			if (eventEmitterFactory == null)
			{
				throw new ArgumentNullException("eventEmitterFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(eventEmitterFactories.CreateTrackingRegistrationLocationSelector(typeof(TEventEmitter), (IEventEmitter wrapped, IEventEmitter inner) => eventEmitterFactory(wrapped, inner)));
			return Self;
		}

		public StaticSerializerBuilder WithoutEventEmitter<TEventEmitter>() where TEventEmitter : IEventEmitter
		{
			return WithoutEventEmitter(typeof(TEventEmitter));
		}

		public StaticSerializerBuilder WithoutEventEmitter(Type eventEmitterType)
		{
			if (eventEmitterType == null)
			{
				throw new ArgumentNullException("eventEmitterType");
			}
			eventEmitterFactories.Remove(eventEmitterType);
			return this;
		}

		public override StaticSerializerBuilder WithTagMapping(TagName tag, Type type)
		{
			if (tag.IsEmpty)
			{
				throw new ArgumentException("Non-specific tags cannot be maped");
			}
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (tagMappings.TryGetValue(type, out var value))
			{
				throw new ArgumentException($"Type already has a registered tag '{value}' for type '{type.FullName}'", "type");
			}
			tagMappings.Add(type, tag);
			return this;
		}

		public StaticSerializerBuilder WithoutTagMapping(Type type)
		{
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			if (!tagMappings.Remove(type))
			{
				throw new KeyNotFoundException("Tag for type '" + type.FullName + "' is not registered");
			}
			return this;
		}

		public StaticSerializerBuilder EnsureRoundtrip()
		{
			objectGraphTraversalStrategyFactory = (ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable<IYamlTypeConverter> typeConverters, int maximumRecursion) => new RoundtripObjectGraphTraversalStrategy(typeConverters, typeInspector, typeResolver, maximumRecursion, namingConvention, settings, factory);
			WithEventEmitter((IEventEmitter inner) => new TypeAssigningEventEmitter(inner, requireTagWhenStaticAndActualTypesAreDifferent: true, tagMappings, quoteNecessaryStrings), delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> loc)
			{
				loc.InsteadOf<TypeAssigningEventEmitter>();
			});
			return WithTypeInspector((ITypeInspector inner) => new ReadableAndWritablePropertiesTypeInspector(inner), delegate(IRegistrationLocationSelectionSyntax<ITypeInspector> loc)
			{
				loc.OnBottom();
			});
		}

		public StaticSerializerBuilder DisableAliases()
		{
			preProcessingPhaseObjectGraphVisitorFactories.Remove(typeof(AnchorAssigner));
			emissionPhaseObjectGraphVisitorFactories.Remove(typeof(AnchorAssigningObjectGraphVisitor));
			return this;
		}

		[Obsolete("The default behavior is now to always emit default values, thefore calling this method has no effect. This behavior is now controlled by ConfigureDefaultValuesHandling.", true)]
		public StaticSerializerBuilder EmitDefaults()
		{
			return ConfigureDefaultValuesHandling(DefaultValuesHandling.Preserve);
		}

		public StaticSerializerBuilder ConfigureDefaultValuesHandling(DefaultValuesHandling configuration)
		{
			defaultValuesHandlingConfiguration = configuration;
			return this;
		}

		public StaticSerializerBuilder JsonCompatible()
		{
			emitterSettings = emitterSettings.WithMaxSimpleKeyLength(int.MaxValue).WithoutAnchorName();
			return WithTypeConverter(new YamlDotNet.Serialization.Converters.GuidConverter(jsonCompatible: true), delegate(IRegistrationLocationSelectionSyntax<IYamlTypeConverter> w)
			{
				w.InsteadOf<YamlDotNet.Serialization.Converters.GuidConverter>();
			}).WithTypeConverter(new YamlDotNet.Serialization.Converters.DateTimeConverter(DateTimeKind.Utc, null, true)).WithEventEmitter((IEventEmitter inner) => new JsonEventEmitter(inner, yamlFormatter), delegate(IRegistrationLocationSelectionSyntax<IEventEmitter> loc)
			{
				loc.InsteadOf<TypeAssigningEventEmitter>();
			});
		}

		public StaticSerializerBuilder WithNewLine(string newLine)
		{
			emitterSettings = emitterSettings.WithNewLine(newLine);
			return this;
		}

		public StaticSerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(TObjectGraphVisitor objectGraphVisitor) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			return WithPreProcessingPhaseObjectGraphVisitor(objectGraphVisitor, delegate(IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>> w)
			{
				w.OnTop();
			});
		}

		public StaticSerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(TObjectGraphVisitor objectGraphVisitor, Action<IRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			if (objectGraphVisitor == null)
			{
				throw new ArgumentNullException("objectGraphVisitor");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(preProcessingPhaseObjectGraphVisitorFactories.CreateRegistrationLocationSelector(typeof(TObjectGraphVisitor), (IEnumerable<IYamlTypeConverter> _) => objectGraphVisitor));
			return this;
		}

		public StaticSerializerBuilder WithPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>(WrapperFactory<IObjectGraphVisitor<Nothing>, TObjectGraphVisitor> objectGraphVisitorFactory, Action<ITrackingRegistrationLocationSelectionSyntax<IObjectGraphVisitor<Nothing>>> where) where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			if (objectGraphVisitorFactory == null)
			{
				throw new ArgumentNullException("objectGraphVisitorFactory");
			}
			if (where == null)
			{
				throw new ArgumentNullException("where");
			}
			where(preProcessingPhaseObjectGraphVisitorFactories.CreateTrackingRegistrationLocationSelector(typeof(TObjectGraphVisitor), (IObjectGraphVisitor<Nothing> wrapped, IEnumerable<IYamlTypeConverter> _) => objectGraphVisitorFactory(wrapped)));
			return this;
		}

		public StaticSerializerBuilder WithoutPreProcessingPhaseObjectGraphVisitor<TObjectGraphVisitor>() where TObjectGraphVisitor : IObjectGraphVisitor<Nothing>
		{
			return WithoutPreProcessingPhaseObjectGraphVisitor(typeof(TObjectGraphVisitor));
		}

		public StaticSerializerBuilder WithoutPreProcessingPhaseObjectGraphVisitor(Type objectGraphVisitorType)
		{
			if (objectGraphVisitorType == null)
			{
				throw new ArgumentNullException("objectGraphVisitorType");
			}
			preProcessingPhaseObjectGraphVisitorFactories.Remove(objectGraphVisitorType);
			return this;
		}

		public StaticSerializerBuilder WithObjectGraphTraversalStrategyFactory(ObjectGraphTraversalStrategyFactory objectGraphTraversalStrategyFactory)
		{
			this.objectGraphTraversalStrategyFactory = objectGraphTraversalStrategyFactory;
			return this;
		}

		public StaticSerializerBuilder WithEmissionPhaseObjectGraphVisitor<TObjectGraphVisitor>(Func<EmissionPhaseObjectGraphVisitorArgs, TObjectGraphVisitor> objectGraphVisitorFactory) where TObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
		{
			return WithEmissionPhaseObjectGraphVisitor(objectGraphVisitorFactory, delegate(IRegistrationLocationSelectionSyntax<I