Decompiled source of VikingWards v0.1.1

VikingWards.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using VikingLib.Stats;
using VikingWards.Conduits;
using VikingWards.Configuration;
using VikingWards.Effects;
using VikingWards.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DigitalVikings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+cbc0a2ffede822f5d85ada4b85977cd9ce96e062")]
[assembly: AssemblyProduct("VikingWards")]
[assembly: AssemblyTitle("VikingWards")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VikingWards
{
	[BepInPlugin("com.digitalvikings.vikingwards", "VikingWards", "0.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.digitalvikings.vikingwards";

		public const string ModName = "VikingWards";

		public const string ModVersion = "0.1.1";

		private Harmony? _harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.digitalvikings.vikingwards");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"VikingWards v0.1.1 loaded successfully with 5 Divine Conduits.");
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace VikingWards.UI
{
	public sealed class WardSlateDialog : MonoBehaviour
	{
		private class RequirementCard
		{
			public GameObject Root;

			public Image Icon;

			public Text AmountText;

			public Text NameText;
		}

		private struct OfferingDisplayData
		{
			public string LocalizedName;

			public Sprite? Icon;

			public bool IsKnown;

			public int RequiredAmount;

			public int CurrentAmount;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Close;
		}

		private static WardSlateDialog? _instance;

		private static GameObject? _uiRoot;

		private PrivateArea? _targetWard;

		private Player? _player;

		private DeityType _selectedDeity = DeityType.Odin;

		private int _selectedSlotIndex;

		private float _openTime;

		private GameObject? _dialogPanel;

		private Text? _titleText;

		private Text? _statusText;

		private Text? _riteTitleText;

		private Text? _riteDescText;

		private GameObject? _reqContainer;

		private readonly List<RequirementCard> _reqCards = new List<RequirementCard>();

		private Button? _dedicateBtn;

		private Text? _dedicateBtnText;

		private Button? _consecrateBtn;

		private Text? _consecrateBtnText;

		private readonly List<Button> _godButtons = new List<Button>();

		private readonly List<Button> _slotButtons = new List<Button>();

		private readonly List<Text> _slotTexts = new List<Text>();

		public static bool IsOpen()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				return ((Component)_instance).gameObject.activeSelf;
			}
			return false;
		}

		public static void Open(PrivateArea ward, Player player)
		{
			if ((Object)(object)_instance == (Object)null)
			{
				CreateUI();
			}
			if ((Object)(object)_instance != (Object)null)
			{
				_instance._targetWard = ward;
				_instance._player = player;
				DeityType activeGod = WardConduitManager.GetActiveGod(ward);
				_instance._selectedDeity = ((activeGod == DeityType.None) ? DeityType.Odin : activeGod);
				_instance._selectedSlotIndex = 0;
				_instance.Show();
			}
		}

		public static void Close()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.Hide();
			}
		}

		private static void CreateUI()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			if ((Object)(object)GUIManager.CustomGUIFront != (Object)null)
			{
				val = GUIManager.CustomGUIFront.transform;
			}
			else if ((Object)(object)Menu.instance != (Object)null)
			{
				val = ((Component)Menu.instance).transform.parent;
			}
			if (!((Object)(object)val == (Object)null))
			{
				_uiRoot = new GameObject("VikingWards_UI", new Type[1] { typeof(RectTransform) });
				_uiRoot.transform.SetParent(val, false);
				RectTransform component = _uiRoot.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.sizeDelta = Vector2.zero;
				_instance = _uiRoot.AddComponent<WardSlateDialog>();
				_instance.BuildVisualHierarchy();
				_instance.Hide();
			}
		}

		private void BuildVisualHierarchy()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Expected O, but got Unknown
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Expected O, but got Unknown
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_062c: Expected O, but got Unknown
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_0739: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Expected O, but got Unknown
			//IL_0790: Unknown result type (might be due to invalid IL or missing references)
			//IL_0797: Expected O, but got Unknown
			//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_084b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0852: Expected O, but got Unknown
			//IL_087c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0912: Unknown result type (might be due to invalid IL or missing references)
			//IL_091c: Expected O, but got Unknown
			//IL_094e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0962: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ac: Expected O, but got Unknown
			//IL_09d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a29: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a30: Expected O, but got Unknown
			//IL_0a56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b34: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b45: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b59: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c86: Expected O, but got Unknown
			//IL_0cb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d1e: Expected O, but got Unknown
			//IL_0d3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da8: Expected O, but got Unknown
			//IL_0dda: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de1: Expected O, but got Unknown
			//IL_0e0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e24: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e72: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e79: Expected O, but got Unknown
			//IL_0e96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ed8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ef4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0efe: Expected O, but got Unknown
			//IL_0f30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f37: Expected O, but got Unknown
			//IL_0f64: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fc0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fc5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fd8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fe0: Unknown result type (might be due to invalid IL or missing references)
			//IL_1010: Unknown result type (might be due to invalid IL or missing references)
			//IL_1031: Unknown result type (might be due to invalid IL or missing references)
			//IL_1036: Unknown result type (might be due to invalid IL or missing references)
			//IL_103c: Expected O, but got Unknown
			Font font = GUIManager.Instance.AveriaSerifBold ?? Resources.GetBuiltinResource<Font>("Arial.ttf");
			GameObject val = new GameObject("Blocker", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.sizeDelta = Vector2.zero;
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.65f);
			ButtonClickedEvent onClick = val.GetComponent<Button>().onClick;
			object obj = <>O.<0>__Close;
			if (obj == null)
			{
				UnityAction val2 = Close;
				<>O.<0>__Close = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			_dialogPanel = new GameObject("SlatePanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_dialogPanel.transform.SetParent(((Component)this).transform, false);
			RectTransform component2 = _dialogPanel.GetComponent<RectTransform>();
			component2.sizeDelta = new Vector2(760f, 560f);
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			GUIManager.Instance.ApplyWoodpanelStyle(_dialogPanel.transform);
			GameObject val3 = new GameObject("Title", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val3.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchoredPosition = new Vector2(0f, 245f);
			component3.sizeDelta = new Vector2(700f, 35f);
			_titleText = val3.GetComponent<Text>();
			_titleText.font = font;
			_titleText.fontSize = 24;
			_titleText.alignment = (TextAnchor)4;
			((Graphic)_titleText).color = GUIManager.Instance.ValheimOrange;
			GameObject val4 = new GameObject("Status", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val4.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component4 = val4.GetComponent<RectTransform>();
			component4.anchoredPosition = new Vector2(0f, 212f);
			component4.sizeDelta = new Vector2(700f, 25f);
			_statusText = val4.GetComponent<Text>();
			_statusText.font = font;
			_statusText.fontSize = 13;
			_statusText.alignment = (TextAnchor)4;
			((Graphic)_statusText).color = GUIManager.Instance.ValheimBeige;
			float num = -260f;
			float num2 = 130f;
			DeityType[] array = new DeityType[5]
			{
				DeityType.Odin,
				DeityType.Thor,
				DeityType.Frey,
				DeityType.Tyr,
				DeityType.Freya
			};
			for (int i = 0; i < array.Length; i++)
			{
				DeityType d = array[i];
				GameObject val5 = new GameObject($"GodBtn_{d}", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val5.transform.SetParent(_dialogPanel.transform, false);
				RectTransform component5 = val5.GetComponent<RectTransform>();
				component5.anchoredPosition = new Vector2(num + (float)i * num2, 162f);
				component5.sizeDelta = new Vector2(115f, 36f);
				Button component6 = val5.GetComponent<Button>();
				GUIManager.Instance.ApplyButtonStyle(component6, 14);
				GameObject val6 = new GameObject("Label", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val6.transform.SetParent(val5.transform, false);
				val6.GetComponent<RectTransform>().sizeDelta = component5.sizeDelta;
				Text component7 = val6.GetComponent<Text>();
				component7.font = font;
				component7.fontSize = 15;
				component7.alignment = (TextAnchor)4;
				component7.text = d.ToString();
				((Graphic)component7).color = ModConfig.GetDeityColor(d);
				((UnityEvent)component6.onClick).AddListener((UnityAction)delegate
				{
					_selectedDeity = d;
					_selectedSlotIndex = 0;
					RefreshUI();
				});
				_godButtons.Add(component6);
			}
			float[] array2 = new float[5] { -250f, -125f, 0f, 125f, 250f };
			string[] array3 = new string[5] { "I", "II", "III", "IV", "V" };
			for (int num3 = 0; num3 < 4; num3++)
			{
				GameObject val7 = new GameObject($"TierArrow_{num3}", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val7.transform.SetParent(_dialogPanel.transform, false);
				RectTransform component8 = val7.GetComponent<RectTransform>();
				component8.anchoredPosition = new Vector2(-187.5f + (float)num3 * 125f, 78f);
				component8.sizeDelta = new Vector2(30f, 30f);
				Text component9 = val7.GetComponent<Text>();
				component9.font = font;
				component9.fontSize = 18;
				component9.alignment = (TextAnchor)4;
				component9.text = "➔";
				((Graphic)component9).color = new Color(0.7f, 0.62f, 0.45f, 0.65f);
			}
			for (int num4 = 0; num4 < 5; num4++)
			{
				int num5 = num4 + 1;
				GameObject val8 = new GameObject($"Slot_{num5}", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val8.transform.SetParent(_dialogPanel.transform, false);
				RectTransform component10 = val8.GetComponent<RectTransform>();
				component10.anchoredPosition = new Vector2(array2[num4], 78f);
				component10.sizeDelta = new Vector2(100f, 64f);
				Button component11 = val8.GetComponent<Button>();
				GUIManager.Instance.ApplyButtonStyle(component11, 13);
				GameObject val9 = new GameObject("RuneText", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val9.transform.SetParent(val8.transform, false);
				val9.GetComponent<RectTransform>().sizeDelta = component10.sizeDelta;
				Text component12 = val9.GetComponent<Text>();
				component12.font = font;
				component12.fontSize = 15;
				component12.alignment = (TextAnchor)4;
				component12.text = "Tier " + array3[num4];
				((Graphic)component12).color = Color.white;
				int localIndex = num4;
				((UnityEvent)component11.onClick).AddListener((UnityAction)delegate
				{
					_selectedSlotIndex = localIndex;
					RefreshUI();
				});
				_slotButtons.Add(component11);
				_slotTexts.Add(component12);
			}
			GameObject val10 = new GameObject("RiteTitle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val10.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component13 = val10.GetComponent<RectTransform>();
			component13.anchoredPosition = new Vector2(0f, 15f);
			component13.sizeDelta = new Vector2(700f, 28f);
			_riteTitleText = val10.GetComponent<Text>();
			_riteTitleText.font = font;
			_riteTitleText.fontSize = 17;
			_riteTitleText.alignment = (TextAnchor)4;
			((Graphic)_riteTitleText).color = GUIManager.Instance.ValheimYellow;
			GameObject val11 = new GameObject("RiteDesc", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val11.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component14 = val11.GetComponent<RectTransform>();
			component14.anchoredPosition = new Vector2(0f, -22f);
			component14.sizeDelta = new Vector2(700f, 48f);
			_riteDescText = val11.GetComponent<Text>();
			_riteDescText.font = font;
			_riteDescText.fontSize = 13;
			_riteDescText.alignment = (TextAnchor)4;
			_riteDescText.horizontalOverflow = (HorizontalWrapMode)0;
			_riteDescText.verticalOverflow = (VerticalWrapMode)0;
			((Graphic)_riteDescText).color = GUIManager.Instance.ValheimBeige;
			_reqContainer = new GameObject("ReqContainer", new Type[1] { typeof(RectTransform) });
			_reqContainer.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component15 = _reqContainer.GetComponent<RectTransform>();
			component15.anchoredPosition = new Vector2(0f, -95f);
			component15.sizeDelta = new Vector2(700f, 50f);
			for (int num6 = 0; num6 < 4; num6++)
			{
				GameObject val12 = new GameObject($"ReqCard_{num6}", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val12.transform.SetParent(_reqContainer.transform, false);
				val12.GetComponent<RectTransform>().sizeDelta = new Vector2(130f, 46f);
				((Graphic)val12.GetComponent<Image>()).color = new Color(0.12f, 0.12f, 0.12f, 0.75f);
				GameObject val13 = new GameObject("IconFrame", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val13.transform.SetParent(val12.transform, false);
				RectTransform component16 = val13.GetComponent<RectTransform>();
				component16.anchoredPosition = new Vector2(-42f, 0f);
				component16.sizeDelta = new Vector2(38f, 38f);
				((Graphic)val13.GetComponent<Image>()).color = new Color(0.18f, 0.18f, 0.18f, 1f);
				GameObject val14 = new GameObject("Icon", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val14.transform.SetParent(val13.transform, false);
				val14.GetComponent<RectTransform>().sizeDelta = new Vector2(34f, 34f);
				Image component17 = val14.GetComponent<Image>();
				GameObject val15 = new GameObject("Amount", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val15.transform.SetParent(val12.transform, false);
				RectTransform component18 = val15.GetComponent<RectTransform>();
				component18.anchoredPosition = new Vector2(18f, 8f);
				component18.sizeDelta = new Vector2(75f, 18f);
				Text component19 = val15.GetComponent<Text>();
				component19.font = font;
				component19.fontSize = 13;
				component19.alignment = (TextAnchor)3;
				GameObject val16 = new GameObject("Name", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val16.transform.SetParent(val12.transform, false);
				RectTransform component20 = val16.GetComponent<RectTransform>();
				component20.anchoredPosition = new Vector2(18f, -9f);
				component20.sizeDelta = new Vector2(75f, 16f);
				Text component21 = val16.GetComponent<Text>();
				component21.font = font;
				component21.fontSize = 11;
				component21.alignment = (TextAnchor)3;
				_reqCards.Add(new RequirementCard
				{
					Root = val12,
					Icon = component17,
					AmountText = component19,
					NameText = component21
				});
			}
			GameObject val17 = new GameObject("DedicateBtn", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val17.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component22 = val17.GetComponent<RectTransform>();
			component22.anchoredPosition = new Vector2(-135f, -188f);
			component22.sizeDelta = new Vector2(240f, 40f);
			_dedicateBtn = val17.GetComponent<Button>();
			GUIManager.Instance.ApplyButtonStyle(_dedicateBtn, 14);
			GameObject val18 = new GameObject("Label", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val18.transform.SetParent(val17.transform, false);
			val18.GetComponent<RectTransform>().sizeDelta = component22.sizeDelta;
			_dedicateBtnText = val18.GetComponent<Text>();
			_dedicateBtnText.font = font;
			_dedicateBtnText.fontSize = 14;
			_dedicateBtnText.alignment = (TextAnchor)4;
			((Graphic)_dedicateBtnText).color = GUIManager.Instance.ValheimYellow;
			((UnityEvent)_dedicateBtn.onClick).AddListener(new UnityAction(OnDedicateClicked));
			GameObject val19 = new GameObject("ConsecrateBtn", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val19.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component23 = val19.GetComponent<RectTransform>();
			component23.anchoredPosition = new Vector2(135f, -188f);
			component23.sizeDelta = new Vector2(240f, 40f);
			_consecrateBtn = val19.GetComponent<Button>();
			GUIManager.Instance.ApplyButtonStyle(_consecrateBtn, 14);
			GameObject val20 = new GameObject("Label", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val20.transform.SetParent(val19.transform, false);
			val20.GetComponent<RectTransform>().sizeDelta = component23.sizeDelta;
			_consecrateBtnText = val20.GetComponent<Text>();
			_consecrateBtnText.font = font;
			_consecrateBtnText.fontSize = 14;
			_consecrateBtnText.alignment = (TextAnchor)4;
			((Graphic)_consecrateBtnText).color = Color.white;
			((UnityEvent)_consecrateBtn.onClick).AddListener(new UnityAction(OnConsecrateClicked));
			GameObject val21 = new GameObject("CloseBtn", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val21.transform.SetParent(_dialogPanel.transform, false);
			RectTransform component24 = val21.GetComponent<RectTransform>();
			component24.anchoredPosition = new Vector2(345f, 245f);
			component24.sizeDelta = new Vector2(35f, 35f);
			Button component25 = val21.GetComponent<Button>();
			GUIManager.Instance.ApplyButtonStyle(component25, 14);
			GameObject val22 = new GameObject("Label", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val22.transform.SetParent(val21.transform, false);
			val22.GetComponent<RectTransform>().sizeDelta = component24.sizeDelta;
			Text component26 = val22.GetComponent<Text>();
			component26.font = font;
			component26.fontSize = 16;
			component26.alignment = (TextAnchor)4;
			component26.text = "X";
			((Graphic)component26).color = Color.white;
			ButtonClickedEvent onClick2 = component25.onClick;
			object obj2 = <>O.<0>__Close;
			if (obj2 == null)
			{
				UnityAction val23 = Close;
				<>O.<0>__Close = val23;
				obj2 = (object)val23;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj2);
		}

		private void Update()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen())
			{
				if ((Object)(object)_player == (Object)null || (Object)(object)_targetWard == (Object)null || ((Character)_player).IsDead())
				{
					Close();
				}
				else if (Vector3.Distance(((Component)_player).transform.position, ((Component)_targetWard).transform.position) > 4.5f)
				{
					Close();
				}
				else if (!(Time.time < _openTime + 0.25f) && (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)9) || ZInput.GetKeyDown((KeyCode)27, true) || ZInput.GetButtonDown("JoyButtonB")))
				{
					Close();
				}
			}
		}

		private void OnDedicateClicked()
		{
			if (!((Object)(object)_targetWard == (Object)null) && !((Object)(object)_player == (Object)null))
			{
				WardConduitManager.SetActiveGod(_targetWard, _selectedDeity);
				((Character)_player).Message((MessageType)2, $"Ward Dedicated to {_selectedDeity}!", 0, (Sprite)null, false);
				RefreshUI();
			}
		}

		private void OnConsecrateClicked()
		{
			if ((Object)(object)_targetWard == (Object)null || (Object)(object)_player == (Object)null)
			{
				return;
			}
			IReadOnlyList<WardRiteDefinition> forDeity = WardRiteRegistry.GetForDeity(_selectedDeity);
			if (_selectedSlotIndex >= forDeity.Count)
			{
				return;
			}
			WardRiteDefinition wardRiteDefinition = forDeity[_selectedSlotIndex];
			if (WardConduitManager.IsRiteUnlocked(_targetWard, wardRiteDefinition.Id))
			{
				return;
			}
			if (CanPlayerUnlockRite(_player, wardRiteDefinition, out List<OfferingDisplayData> _))
			{
				if (WardConduitManager.UnlockRite(_targetWard, _player, wardRiteDefinition))
				{
					RefreshUI();
				}
			}
			else
			{
				((Character)_player).Message((MessageType)2, "Missing required offerings in inventory!", 0, (Sprite)null, false);
			}
		}

		private bool CanPlayerUnlockRite(Player player, WardRiteDefinition rite, out List<OfferingDisplayData> offeringList)
		{
			offeringList = new List<OfferingDisplayData>();
			Inventory inventory = ((Humanoid)player).GetInventory();
			ObjectDB instance = ObjectDB.instance;
			bool result = true;
			foreach (OfferingCost cost in rite.Costs)
			{
				GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetItemPrefab(cost.ItemPrefab) : null);
				ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
				string text = (((Object)(object)val2 != (Object)null) ? val2.m_itemData.m_shared.m_name : cost.ItemPrefab);
				string localizedName = (((Object)(object)val2 != (Object)null) ? Localization.instance.Localize(text) : cost.ItemPrefab);
				Sprite icon = (((Object)(object)val2 != (Object)null) ? val2.m_itemData.GetIcon() : null);
				bool isKnown = player.IsKnownMaterial(text);
				int num = ((inventory != null && (Object)(object)val2 != (Object)null) ? inventory.CountItems(text, -1, true) : 0);
				if (num < cost.Amount)
				{
					result = false;
				}
				offeringList.Add(new OfferingDisplayData
				{
					LocalizedName = localizedName,
					Icon = icon,
					IsKnown = isKnown,
					RequiredAmount = cost.Amount,
					CurrentAmount = num
				});
			}
			return result;
		}

		private void Show()
		{
			((Component)this).gameObject.SetActive(true);
			_openTime = Time.time;
			GUIManager.BlockInput(true);
			RefreshUI();
		}

		private void Hide()
		{
			if (((Component)this).gameObject.activeSelf)
			{
				GUIManager.BlockInput(false);
				((Component)this).gameObject.SetActive(false);
			}
			_targetWard = null;
			_player = null;
		}

		private void OnDestroy()
		{
			if (IsOpen())
			{
				GUIManager.BlockInput(false);
			}
		}

		private void RefreshUI()
		{
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_targetWard == (Object)null || (Object)(object)_player == (Object)null)
			{
				return;
			}
			DeityType activeGod = WardConduitManager.GetActiveGod(_targetWard);
			int unlockedCountForDeity = WardConduitManager.GetUnlockedCountForDeity(_targetWard, _selectedDeity);
			float wardRadius = ModConfig.GetWardRadius(unlockedCountForDeity);
			_titleText.text = $"Runic Ward of {_selectedDeity}";
			string arg = ((activeGod == _selectedDeity) ? "<color=#55FF55>ACTIVE PATRON</color>" : "<color=#AAAAAA>INACTIVE</color>");
			_statusText.text = $"{arg}  |  Consecrated Runes: {unlockedCountForDeity}/5  |  Zone Radius: {wardRadius:F0}m";
			if (activeGod == _selectedDeity)
			{
				_dedicateBtnText.text = $"✓ Dedicated to {_selectedDeity}";
				((Selectable)_dedicateBtn).interactable = false;
			}
			else
			{
				_dedicateBtnText.text = $"Dedicate to {_selectedDeity}";
				((Selectable)_dedicateBtn).interactable = true;
			}
			string[] array = new string[5] { "I", "II", "III", "IV", "V" };
			IReadOnlyList<WardRiteDefinition> forDeity = WardRiteRegistry.GetForDeity(_selectedDeity);
			for (int i = 0; i < _slotButtons.Count; i++)
			{
				if (i < forDeity.Count)
				{
					WardRiteDefinition wardRiteDefinition = forDeity[i];
					bool flag = WardConduitManager.IsRiteUnlocked(_targetWard, wardRiteDefinition.Id);
					Image component = ((Component)_slotButtons[i]).GetComponent<Image>();
					Text val = _slotTexts[i];
					bool flag2 = i == _selectedSlotIndex;
					if (flag2)
					{
						((Graphic)component).color = new Color(1f, 1f, 1f, 1f);
					}
					else
					{
						((Graphic)component).color = (flag ? new Color(0.85f, 0.85f, 0.85f, 0.95f) : new Color(0.6f, 0.6f, 0.6f, 0.8f));
					}
					if (flag)
					{
						val.text = "Tier " + array[i] + "\n<size=11><color=#55FF55>✓ Consecrated</color></size>";
						((Graphic)val).color = (flag2 ? Color.white : ModConfig.GetDeityColor(_selectedDeity));
					}
					else
					{
						val.text = "Tier " + array[i];
						((Graphic)val).color = (Color)(flag2 ? GUIManager.Instance.ValheimYellow : new Color(0.6f, 0.6f, 0.6f));
					}
				}
			}
			if (_selectedSlotIndex < 0 || _selectedSlotIndex >= forDeity.Count)
			{
				return;
			}
			WardRiteDefinition wardRiteDefinition2 = forDeity[_selectedSlotIndex];
			bool flag3 = WardConduitManager.IsRiteUnlocked(_targetWard, wardRiteDefinition2.Id);
			List<OfferingDisplayData> offeringList;
			bool flag4 = CanPlayerUnlockRite(_player, wardRiteDefinition2, out offeringList);
			_riteTitleText.text = $"{wardRiteDefinition2.Name}  <color=#A0A0A0>(Tier {wardRiteDefinition2.Tier})</color>";
			_riteDescText.text = wardRiteDefinition2.Description;
			int count = offeringList.Count;
			float num = 140f;
			float num2 = (0f - (float)count * num) / 2f + num / 2f;
			for (int j = 0; j < _reqCards.Count; j++)
			{
				RequirementCard requirementCard = _reqCards[j];
				if (j < count)
				{
					requirementCard.Root.SetActive(true);
					requirementCard.Root.GetComponent<RectTransform>().anchoredPosition = new Vector2(num2 + (float)j * num, 0f);
					OfferingDisplayData offeringDisplayData = offeringList[j];
					if ((Object)(object)offeringDisplayData.Icon != (Object)null)
					{
						requirementCard.Icon.sprite = offeringDisplayData.Icon;
						((Behaviour)requirementCard.Icon).enabled = true;
						if (offeringDisplayData.IsKnown)
						{
							((Graphic)requirementCard.Icon).color = Color.white;
							requirementCard.NameText.text = offeringDisplayData.LocalizedName;
							((Graphic)requirementCard.NameText).color = GUIManager.Instance.ValheimBeige;
						}
						else
						{
							((Graphic)requirementCard.Icon).color = new Color(0.06f, 0.06f, 0.06f, 0.98f);
							requirementCard.NameText.text = "???";
							((Graphic)requirementCard.NameText).color = new Color(0.6f, 0.6f, 0.6f);
						}
					}
					else
					{
						((Behaviour)requirementCard.Icon).enabled = false;
						requirementCard.NameText.text = (offeringDisplayData.IsKnown ? offeringDisplayData.LocalizedName : "???");
					}
					string arg2 = ((offeringDisplayData.CurrentAmount >= offeringDisplayData.RequiredAmount) ? "#55FF55" : "#FF5555");
					requirementCard.AmountText.text = $"<color={arg2}>{offeringDisplayData.CurrentAmount}</color>/{offeringDisplayData.RequiredAmount}";
				}
				else
				{
					requirementCard.Root.SetActive(false);
				}
			}
			if (flag3)
			{
				_consecrateBtnText.text = "✓ Consecrated";
				((Selectable)_consecrateBtn).interactable = false;
			}
			else if (flag4)
			{
				_consecrateBtnText.text = "<color=#55FF55>Consecrate Offering</color>";
				((Selectable)_consecrateBtn).interactable = true;
			}
			else
			{
				_consecrateBtnText.text = "Missing Offerings";
				((Selectable)_consecrateBtn).interactable = false;
			}
		}
	}
}
namespace VikingWards.Patches
{
	[HarmonyPatch(typeof(Player))]
	public static class PlayerPlacementPatch
	{
		private static readonly FieldRef<Player, GameObject> _ghostRef = AccessTools.FieldRefAccess<Player, GameObject>("m_placementGhost");

		private static readonly FieldRef<Player, PlacementStatus> _statusRef = AccessTools.FieldRefAccess<Player, PlacementStatus>("m_placementStatus");

		[HarmonyPatch("UpdatePlacementGhost")]
		[HarmonyPostfix]
		public static void UpdatePlacementGhost_Postfix(Player __instance)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			GameObject val = _ghostRef.Invoke(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			PrivateArea component = val.GetComponent<PrivateArea>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			Vector3 position = val.transform.position;
			float wardRadius = ModConfig.GetWardRadius();
			if ((Object)(object)component.m_areaMarker != (Object)null)
			{
				((Component)component.m_areaMarker).gameObject.SetActive(true);
				component.m_areaMarker.m_radius = wardRadius;
			}
			bool flag = false;
			foreach (PrivateArea allArea in WardConduitManager.GetAllAreas())
			{
				if (!((Object)(object)allArea == (Object)null) && WardConduitManager.IsAreaEnabled(allArea))
				{
					float num = WardConduitManager.CalculateRadius(allArea);
					float num2 = wardRadius + num;
					float num3 = Vector3.Distance(position, ((Component)allArea).transform.position);
					if (num3 <= 200f)
					{
						allArea.ShowAreaMarker();
					}
					if (num3 < num2)
					{
						flag = true;
					}
				}
			}
			if (flag)
			{
				_statusRef.Invoke(__instance) = (PlacementStatus)4;
				Piece component2 = val.GetComponent<Piece>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.SetInvalidPlacementHeightlight(true);
				}
			}
		}

		[HarmonyPatch("TryPlacePiece")]
		[HarmonyPrefix]
		public static bool TryPlacePiece_Prefix(Player __instance, Piece piece, ref bool __result)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((Object)(object)piece == (Object)null || (Object)(object)((Component)piece).GetComponent<PrivateArea>() == (Object)null)
			{
				return true;
			}
			GameObject val = _ghostRef.Invoke(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			Vector3 position = val.transform.position;
			float wardRadius = ModConfig.GetWardRadius();
			foreach (PrivateArea allArea in WardConduitManager.GetAllAreas())
			{
				if (!((Object)(object)allArea == (Object)null) && WardConduitManager.IsAreaEnabled(allArea))
				{
					float num = WardConduitManager.CalculateRadius(allArea);
					float num2 = wardRadius + num;
					if (Vector3.Distance(position, ((Component)allArea).transform.position) < num2)
					{
						((Character)__instance).Message((MessageType)2, $"<color=red>Cannot place ward: Must be at least {num2:F0}m from other active wards!</color>", 0, (Sprite)null, false);
						__result = false;
						return false;
					}
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PrivateArea))]
	public static class PrivateAreaPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void Awake_Postfix(PrivateArea __instance)
		{
			WardConduitManager.SyncPieceResources(__instance);
			WardConduitManager.ApplyVisualAndRadius(__instance);
		}

		[HarmonyPatch("GetHoverText")]
		[HarmonyPostfix]
		public static void GetHoverText_Postfix(PrivateArea __instance, ref string __result)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				DeityType activeGod = WardConduitManager.GetActiveGod(__instance);
				int unlockedCountForDeity = WardConduitManager.GetUnlockedCountForDeity(__instance, activeGod);
				float num = WardConduitManager.CalculateRadius(__instance);
				StringBuilder stringBuilder = new StringBuilder(__result);
				stringBuilder.AppendLine();
				stringBuilder.AppendLine();
				if (activeGod == DeityType.None)
				{
					stringBuilder.AppendLine("<color=#A0A0A0>Divine Conduit: Unconsecrated</color>");
				}
				else
				{
					string text = ColorUtility.ToHtmlStringRGB(ModConfig.GetDeityColor(activeGod));
					stringBuilder.AppendLine($"<color=#{text}>Patron Deity: {activeGod} (Runes: {unlockedCountForDeity}/5 | Radius: {num:F0}m)</color>");
				}
				stringBuilder.Append(Localization.instance.Localize("[<color=yellow><b>Left Shift + $KEY_Use</b></color>] Commune with the Gods"));
				__result = stringBuilder.ToString();
			}
		}

		[HarmonyPatch("Interact")]
		[HarmonyPrefix]
		public static bool Interact_Prefix(PrivateArea __instance, Humanoid human, bool hold, bool alt, ref bool __result)
		{
			if (hold)
			{
				return true;
			}
			if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
			{
				Player val = (Player)(object)((human is Player) ? human : null);
				if (val != null)
				{
					WardSlateDialog.Open(__instance, val);
					__result = true;
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("SetEnabled")]
		[HarmonyPrefix]
		public static bool SetEnabled_Prefix(PrivateArea __instance, bool enabled)
		{
			if (enabled && WardConduitManager.CheckOverlapWithOtherActiveWards(__instance))
			{
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, "Cannot activate ward: Divine boundary overlaps another active ward!", 0, (Sprite)null, false);
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch("UpdateStatus")]
		[HarmonyPostfix]
		public static void UpdateStatus_Postfix(PrivateArea __instance)
		{
			WardConduitManager.ApplyVisualAndRadius(__instance);
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				WardStatSyncService.UpdatePlayerStats(Player.m_localPlayer);
			}
		}
	}
	[HarmonyPatch(typeof(WearNTear))]
	public static class WearNTearWardPatch
	{
		[HarmonyPatch("Damage")]
		[HarmonyPrefix]
		public static void Damage_Prefix(WearNTear __instance, ref HitData hit)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && hit != null && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Thor))
			{
				hit.ApplyArmor(35f);
			}
		}

		[HarmonyPatch("IsWet")]
		[HarmonyPostfix]
		public static void IsWet_Postfix(WearNTear __instance, ref bool __result)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (__result && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Thor, 3))
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Fireplace))]
	public static class FireplaceWardPatch
	{
		[HarmonyPatch("CheckWet")]
		[HarmonyPrefix]
		public static bool CheckWet_Prefix(Fireplace __instance)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			if (WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Thor, 3))
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EnvMan))]
	public static class EnvManWardPatch
	{
		[HarmonyPatch("CalculateCold")]
		[HarmonyPostfix]
		public static void CalculateCold_Postfix(ref bool __result)
		{
			if (__result && (Object)(object)Player.m_localPlayer != (Object)null && WardConduitManager.IsPlayerInsideActiveWard(Player.m_localPlayer, DeityType.Thor, 3))
			{
				__result = false;
			}
		}

		[HarmonyPatch("CalculateFreezing")]
		[HarmonyPostfix]
		public static void CalculateFreezing_Postfix(ref bool __result)
		{
			if (__result && (Object)(object)Player.m_localPlayer != (Object)null && WardConduitManager.IsPlayerInsideActiveWard(Player.m_localPlayer, DeityType.Thor, 3))
			{
				__result = false;
			}
		}

		[HarmonyPatch("CalculateWet")]
		[HarmonyPostfix]
		public static void CalculateWet_Postfix(ref bool __result)
		{
			if (__result && (Object)(object)Player.m_localPlayer != (Object)null && WardConduitManager.IsPlayerInsideActiveWard(Player.m_localPlayer, DeityType.Thor, 3))
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Character))]
	public static class CharacterWardPatch
	{
		[HarmonyPatch("Damage")]
		[HarmonyPrefix]
		public static void Damage_Prefix(Character __instance, HitData hit)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance == (Object)null) && hit != null && (int)hit.m_hitType == 3)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null && WardConduitManager.IsPlayerInsideActiveWard(val, DeityType.Odin, 3))
				{
					hit.m_damage.m_damage = 0f;
				}
			}
		}

		[HarmonyPatch("GetBodyArmor")]
		[HarmonyPostfix]
		public static void GetBodyArmor_Postfix(Character __instance, ref float __result)
		{
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val != null && WardConduitManager.IsPlayerInsideActiveWard(val, DeityType.Tyr, 2))
			{
				__result += 30f;
			}
		}
	}
	[HarmonyPatch(typeof(MonsterAI))]
	public static class MonsterAIWardPatch
	{
		[HarmonyPatch("UpdateAI")]
		[HarmonyPrefix]
		public static void UpdateAI_Prefix(MonsterAI __instance)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				Character component = ((Component)__instance).GetComponent<Character>();
				if (!((Object)(object)component == (Object)null) && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Tyr, 5) && !component.IsTamed())
				{
					component.m_speed = component.m_walkSpeed * 0.65f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BaseAI))]
	public static class BaseAIWardPatch
	{
		[HarmonyPatch("CanSeeTarget", new Type[] { typeof(Character) })]
		[HarmonyPostfix]
		public static void CanSeeTarget_Postfix(BaseAI __instance, Character target, ref bool __result)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!__result)
			{
				return;
			}
			Player val = (Player)(object)((target is Player) ? target : null);
			if (val != null && WardConduitManager.IsPlayerInsideActiveWard(val, DeityType.Odin, 2))
			{
				float num = Vector3.Distance(((Component)__instance).transform.position, ((Component)val).transform.position);
				float viewRange = __instance.m_viewRange;
				if (num > viewRange * 0.15f)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(RandEventSystem))]
	public static class RandEventWardPatch
	{
		[HarmonyPatch("GetValidEventPoints")]
		[HarmonyPostfix]
		public static void GetValidEventPoints_Postfix(RandomEvent ev, List<PlayerEventData> characters, ref List<Vector3> __result)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (__result == null || __result.Count == 0)
			{
				return;
			}
			List<Vector3> list = new List<Vector3>(__result.Count);
			foreach (Vector3 item in __result)
			{
				if (!WardConduitManager.IsPositionInsideActiveWard(item, DeityType.Odin, 4) || !(Random.value < 0.65f))
				{
					list.Add(item);
				}
			}
			__result = list;
		}
	}
	[HarmonyPatch(typeof(Plant))]
	public static class PlantWardPatch
	{
		[HarmonyPatch("TimeSincePlanted")]
		[HarmonyPostfix]
		public static void TimeSincePlanted_Postfix(Plant __instance, ref double __result)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Frey))
			{
				__result *= 1.35;
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	public static class PlayerFoodWardPatch
	{
		[HarmonyPatch("UpdateFood")]
		[HarmonyPrefix]
		public static void UpdateFood_Prefix(Player __instance, ref float dt, bool forceUpdate)
		{
			if (!forceUpdate && WardConduitManager.IsPlayerInsideActiveWard(__instance, DeityType.Frey, 2))
			{
				dt = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(CookingStation))]
	public static class CookingStationWardPatch
	{
		[HarmonyPatch("GetDeltaTime")]
		[HarmonyPostfix]
		public static void GetDeltaTime_Postfix(CookingStation __instance, ref float __result)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Frey, 3))
			{
				__result *= 1.6f;
			}
		}
	}
	[HarmonyPatch(typeof(Fermenter))]
	public static class FermenterWardPatch
	{
		[HarmonyPatch("GetFermentationTime")]
		[HarmonyPostfix]
		public static void GetFermentationTime_Postfix(Fermenter __instance, ref double __result)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Frey, 3))
			{
				__result *= 1.6;
			}
		}
	}
	[HarmonyPatch(typeof(Smelter))]
	public static class SmelterWardPatch
	{
		[HarmonyPatch("GetDeltaTime")]
		[HarmonyPostfix]
		public static void GetDeltaTime_Postfix(Smelter __instance, ref double __result)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.m_windmill == (Object)null) && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Frey, 4))
			{
				__result *= 2.0;
			}
		}
	}
	[HarmonyPatch(typeof(Skills))]
	public static class SkillsWardPatch
	{
		[HarmonyPatch("RaiseSkill")]
		[HarmonyPrefix]
		public static void RaiseSkill_Prefix(Skills __instance, SkillType skillType, ref float factor)
		{
			Player component = ((Component)__instance).GetComponent<Player>();
			if ((Object)(object)component != (Object)null && WardConduitManager.IsPlayerInsideActiveWard(component, DeityType.Odin, 5))
			{
				factor *= 1.5f;
			}
		}
	}
	[HarmonyPatch(typeof(Procreation))]
	public static class ProcreationWardPatch
	{
		[HarmonyPatch("IsDue")]
		[HarmonyPostfix]
		public static void IsDue_Postfix(Procreation __instance, ref bool __result)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (__result || !((Object)(object)__instance != (Object)null) || !WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Freya))
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				long num = component.GetZDO().GetLong(ZDOVars.s_pregnant, 0L);
				if (num > 0 && (ZNet.instance.GetTime() - new DateTime(num)).TotalSeconds > (double)(__instance.m_pregnancyDuration * 0.4f))
				{
					__result = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Tameable))]
	public static class TameableWardPatch
	{
		private static readonly Action<Tameable, float> s_decreaseRemainingTime = AccessTools.MethodDelegate<Action<Tameable, float>>(AccessTools.Method(typeof(Tameable), "DecreaseRemainingTime", (Type[])null, (Type[])null), (object)null, true);

		[HarmonyPatch("TamingUpdate")]
		[HarmonyPrefix]
		public static void TamingUpdate_Prefix(Tameable __instance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner() && WardConduitManager.IsPositionInsideActiveWard(((Component)__instance).transform.position, DeityType.Freya, 3) && __instance.IsHungry())
				{
					s_decreaseRemainingTime(__instance, 3f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(SE_Rested))]
	public static class SERestedWardPatch
	{
		[HarmonyPatch("CalculateComfortLevel", new Type[] { typeof(Player) })]
		[HarmonyPostfix]
		public static void CalculateComfortLevel_Postfix(Player player, ref int __result)
		{
			if ((Object)(object)player != (Object)null && WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Freya, 4))
			{
				__result += 3;
			}
		}
	}
}
namespace VikingWards.Effects
{
	public static class WardStatSyncService
	{
		public const string OwnerKey = "VikingWards";

		public static void UpdatePlayerStats(Player player)
		{
			if (!((Object)(object)player == (Object)null))
			{
				List<StatModifier> list = new List<StatModifier>();
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Thor, 2))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.RunSpeed, 0.3f, "Thor Charged Stride", (Func<Character, bool>)null, (object)"VikingWards"));
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.JogSpeed, 0.3f, "Thor Charged Stride", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Thor, 5))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.CraftingYield, 0.15f, "Thor Forge of Thrudvang", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Frey, 5))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.ForagingYield, 0.3f, "Frey Feast of Skirnir", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Tyr))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.DamagePhysical, 0.3f, "Tyr Vanguard Stance", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Tyr, 3))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.MeleeStaminaEfficiency, 0.35f, "Tyr Endurance", (Func<Character, bool>)null, (object)"VikingWards"));
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.RangedStaminaEfficiency, 0.35f, "Tyr Endurance", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Tyr, 4))
				{
					list.Add(StatModifier.Flat(CharacterStats.HealthOnKill, 15f, "Tyr Judgment", (Func<Character, bool>)null, (object)"VikingWards"));
					list.Add(StatModifier.Flat(CharacterStats.StaminaOnKill, 30f, "Tyr Judgment", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Freya, 2))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.HealthRegen, 0.6f, "Freya Sylvan Shelter", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				if (WardConduitManager.IsPlayerInsideActiveWard(player, DeityType.Freya, 5))
				{
					list.Add(StatModifier.Increased((StatToken)(object)CharacterStats.ToolStaminaEfficiency, 0.8f, "Freya Folkvangr", (Func<Character, bool>)null, (object)"VikingWards"));
				}
				CharacterStatManager.ReplaceModifiersByOwner((Character)(object)player, (object)"VikingWards", (IEnumerable<StatModifier>)list);
			}
		}
	}
}
namespace VikingWards.Configuration
{
	public class ConfigurationManagerAttributes
	{
		public bool? Browsable;

		public string? Category;

		public bool? DefaultValue;

		public bool? HideDefaultButton;

		public bool? HideSettingName;

		public string? Description;

		public int? Order;

		public bool? ReadOnly;

		public bool? IsAdvanced;

		public bool? IsAdminOnly;
	}
	public static class ModConfig
	{
		public static ConfigEntry<bool>? DynamicRadius;

		public static ConfigEntry<float>? WardRadius;

		public static float BaseRadius = 32f;

		public static void Init(ConfigFile config)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			DynamicRadius = config.Bind<bool>("General", "DynamicRadius", false, new ConfigDescription("If true, ward radius scales dynamically with the number of consecrated runes (32m to 68m). If false, the fixed WardRadius slider value is used.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 10
				}
			}));
			WardRadius = config.Bind<float>("General", "WardRadius", 45f, new ConfigDescription("Radius of the consecrated ward zone in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(32f, 68f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 9
				}
			}));
			WardRadius.SettingChanged += delegate
			{
				WardConduitManager.RefreshAllWards();
			};
			DynamicRadius.SettingChanged += delegate
			{
				WardConduitManager.RefreshAllWards();
			};
		}

		public static float GetWardRadius(int runeCount = 0)
		{
			if (DynamicRadius != null && DynamicRadius.Value)
			{
				return GetRadiusForRuneCount(runeCount);
			}
			return WardRadius?.Value ?? 45f;
		}

		public static float GetRadiusForRuneCount(int count)
		{
			if (count > 0)
			{
				return count switch
				{
					1 => 38f, 
					2 => 44f, 
					3 => 50f, 
					4 => 58f, 
					_ => 68f, 
				};
			}
			return 32f;
		}

		public static Color GetDeityColor(DeityType deity)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			return (Color)(deity switch
			{
				DeityType.Odin => new Color(0.35f, 0.65f, 1f, 1f), 
				DeityType.Thor => new Color(1f, 0.82f, 0.15f, 1f), 
				DeityType.Frey => new Color(0.3f, 0.88f, 0.45f, 1f), 
				DeityType.Tyr => new Color(0.95f, 0.25f, 0.25f, 1f), 
				DeityType.Freya => new Color(0.95f, 0.35f, 0.7f, 1f), 
				_ => Color.white, 
			});
		}
	}
}
namespace VikingWards.Conduits
{
	public enum DeityType
	{
		None,
		Odin,
		Thor,
		Frey,
		Tyr,
		Freya
	}
	public static class WardConduitManager
	{
		public const string ZDO_GodKey = "VL_Ward_God";

		public const string ZDO_UnlocksKey = "VL_Ward_Unlocks";

		private static readonly FieldRef<PrivateArea, ZNetView> s_nviewRef = AccessTools.FieldRefAccess<PrivateArea, ZNetView>("m_nview");

		private static readonly FieldRef<PrivateArea, Piece> s_pieceRef = AccessTools.FieldRefAccess<PrivateArea, Piece>("m_piece");

		private static readonly FieldInfo s_allAreasField = AccessTools.Field(typeof(PrivateArea), "m_allAreas");

		private static readonly Func<PrivateArea, long, bool> s_isPermittedRef = AccessTools.MethodDelegate<Func<PrivateArea, long, bool>>(AccessTools.Method(typeof(PrivateArea), "IsPermitted", (Type[])null, (Type[])null), (object)null, true);

		public static ZNetView? GetNetView(PrivateArea ward)
		{
			if ((Object)(object)ward == (Object)null)
			{
				return null;
			}
			return s_nviewRef.Invoke(ward) ?? ((Component)ward).GetComponent<ZNetView>();
		}

		public static Piece? GetPiece(PrivateArea ward)
		{
			if ((Object)(object)ward == (Object)null)
			{
				return null;
			}
			return s_pieceRef.Invoke(ward) ?? ((Component)ward).GetComponent<Piece>();
		}

		public static List<PrivateArea> GetAllAreas()
		{
			return ((List<PrivateArea>)(s_allAreasField?.GetValue(null))) ?? new List<PrivateArea>();
		}

		public static bool IsAreaEnabled(PrivateArea ward)
		{
			if ((Object)(object)ward == (Object)null)
			{
				return false;
			}
			ZNetView netView = GetNetView(ward);
			if ((Object)(object)netView != (Object)null && netView.IsValid())
			{
				return netView.GetZDO().GetBool(ZDOVars.s_enabled, ward.m_enabledByDefault);
			}
			return false;
		}

		public static bool IsPlayerPermitted(PrivateArea ward, long playerId)
		{
			if ((Object)(object)ward == (Object)null)
			{
				return false;
			}
			return s_isPermittedRef(ward, playerId);
		}

		public static DeityType GetActiveGod(PrivateArea ward)
		{
			ZNetView netView = GetNetView(ward);
			if ((Object)(object)netView == (Object)null || !netView.IsValid())
			{
				return DeityType.None;
			}
			if (Enum.TryParse<DeityType>(netView.GetZDO().GetString("VL_Ward_God", ""), ignoreCase: true, out var result))
			{
				return result;
			}
			return DeityType.None;
		}

		public static void SetActiveGod(PrivateArea ward, DeityType deity)
		{
			ZNetView netView = GetNetView(ward);
			if (!((Object)(object)netView == (Object)null) && netView.IsValid() && netView.IsOwner())
			{
				netView.GetZDO().Set("VL_Ward_God", deity.ToString());
				ApplyVisualAndRadius(ward);
			}
		}

		public static HashSet<string> GetUnlockedRites(PrivateArea ward)
		{
			HashSet<string> hashSet = new HashSet<string>();
			ZNetView netView = GetNetView(ward);
			if ((Object)(object)netView == (Object)null || !netView.IsValid())
			{
				return hashSet;
			}
			string text = netView.GetZDO().GetString("VL_Ward_Unlocks", "");
			if (string.IsNullOrEmpty(text))
			{
				return hashSet;
			}
			string[] array = text.Split(',', StringSplitOptions.RemoveEmptyEntries);
			foreach (string text2 in array)
			{
				hashSet.Add(text2.Trim());
			}
			return hashSet;
		}

		public static bool IsRiteUnlocked(PrivateArea ward, string riteId)
		{
			return GetUnlockedRites(ward).Contains(riteId);
		}

		public static bool UnlockRite(PrivateArea ward, Player player, WardRiteDefinition rite)
		{
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			ZNetView netView = GetNetView(ward);
			if ((Object)(object)netView == (Object)null || !netView.IsValid() || (Object)(object)player == (Object)null)
			{
				return false;
			}
			if (!netView.IsOwner())
			{
				netView.ClaimOwnership();
			}
			HashSet<string> unlockedRites = GetUnlockedRites(ward);
			if (unlockedRites.Contains(rite.Id))
			{
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return false;
			}
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			ItemDrop val = default(ItemDrop);
			foreach (OfferingCost cost in rite.Costs)
			{
				GameObject itemPrefab = instance.GetItemPrefab(cost.ItemPrefab);
				if ((Object)(object)itemPrefab == (Object)null || !itemPrefab.TryGetComponent<ItemDrop>(ref val))
				{
					return false;
				}
				string name = val.m_itemData.m_shared.m_name;
				if (inventory.CountItems(name, -1, true) < cost.Amount)
				{
					((Character)player).Message((MessageType)2, $"Missing required offering: {cost.Amount}x {Localization.instance.Localize(name)}", 0, (Sprite)null, false);
					return false;
				}
			}
			ItemDrop val2 = default(ItemDrop);
			foreach (OfferingCost cost2 in rite.Costs)
			{
				GameObject itemPrefab2 = instance.GetItemPrefab(cost2.ItemPrefab);
				if ((Object)(object)itemPrefab2 != (Object)null && itemPrefab2.TryGetComponent<ItemDrop>(ref val2))
				{
					inventory.RemoveItem(val2.m_itemData.m_shared.m_name, cost2.Amount, -1, true);
				}
			}
			unlockedRites.Add(rite.Id);
			string text = string.Join(",", unlockedRites);
			netView.GetZDO().Set("VL_Ward_Unlocks", text);
			SyncPieceResources(ward);
			ApplyVisualAndRadius(ward);
			EffectList addPermittedEffect = ward.m_addPermittedEffect;
			if (addPermittedEffect != null)
			{
				addPermittedEffect.Create(((Component)ward).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
			((Character)player).Message((MessageType)2, "Consecrated: " + rite.Name + " (" + rite.RuneGlyph + ")", 0, (Sprite)null, false);
			return true;
		}

		public static int GetUnlockedCountForDeity(PrivateArea ward, DeityType deity)
		{
			HashSet<string> unlockedRites = GetUnlockedRites(ward);
			int num = 0;
			foreach (WardRiteDefinition item in WardRiteRegistry.GetForDeity(deity))
			{
				if (unlockedRites.Contains(item.Id))
				{
					num++;
				}
			}
			return num;
		}

		public static int GetTotalUnlockedRunes(PrivateArea ward)
		{
			return GetUnlockedRites(ward).Count;
		}

		public static float CalculateRadius(PrivateArea ward)
		{
			if ((Object)(object)ward == (Object)null)
			{
				return ModConfig.GetWardRadius();
			}
			DeityType activeGod = GetActiveGod(ward);
			if (activeGod == DeityType.None)
			{
				return ModConfig.BaseRadius;
			}
			return ModConfig.GetWardRadius(GetUnlockedCountForDeity(ward, activeGod));
		}

		public static void RefreshAllWards()
		{
			foreach (PrivateArea allArea in GetAllAreas())
			{
				if ((Object)(object)allArea != (Object)null)
				{
					ApplyVisualAndRadius(allArea);
				}
			}
		}

		public static void SyncPieceResources(PrivateArea ward)
		{
			//IL_015b: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			if ((Object)(object)ward == (Object)null)
			{
				return;
			}
			Piece piece = GetPiece(ward);
			if ((Object)(object)piece == (Object)null)
			{
				return;
			}
			List<Requirement> list = new List<Requirement>();
			if (piece.m_resources != null)
			{
				Requirement[] resources = piece.m_resources;
				foreach (Requirement val in resources)
				{
					if ((Object)(object)val?.m_resItem != (Object)null)
					{
						list.Add(val);
					}
				}
			}
			HashSet<string> unlockedRites = GetUnlockedRites(ward);
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			foreach (string item in unlockedRites)
			{
				WardRiteDefinition byId = WardRiteRegistry.GetById(item);
				if (byId == null)
				{
					continue;
				}
				foreach (OfferingCost cost in byId.Costs)
				{
					if (!dictionary.TryGetValue(cost.ItemPrefab, out var value))
					{
						value = 0;
					}
					dictionary[cost.ItemPrefab] = value + cost.Amount;
				}
			}
			List<Requirement> list2 = new List<Requirement>(list);
			ItemDrop resItem = default(ItemDrop);
			foreach (KeyValuePair<string, int> item2 in dictionary)
			{
				GameObject itemPrefab = instance.GetItemPrefab(item2.Key);
				if ((Object)(object)itemPrefab != (Object)null && itemPrefab.TryGetComponent<ItemDrop>(ref resItem))
				{
					list2.Add(new Requirement
					{
						m_resItem = resItem,
						m_amount = item2.Value,
						m_recover = true
					});
				}
			}
			piece.m_resources = list2.ToArray();
		}

		public static void ApplyVisualAndRadius(PrivateArea ward)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: 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_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ward == (Object)null)
			{
				return;
			}
			float radius = (ward.m_radius = CalculateRadius(ward));
			if ((Object)(object)ward.m_areaMarker != (Object)null)
			{
				ward.m_areaMarker.m_radius = radius;
			}
			DeityType activeGod = GetActiveGod(ward);
			Color val = (Color)((activeGod != DeityType.None) ? ModConfig.GetDeityColor(activeGod) : new Color(0f, 0.65f, 1f));
			if ((Object)(object)ward.m_model != (Object)null)
			{
				Material[] materials = ((Renderer)ward.m_model).materials;
				foreach (Material val2 in materials)
				{
					if (!((Object)(object)val2 == (Object)null) && ((Object)val2).name.IndexOf("Glow", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						if (activeGod != DeityType.None)
						{
							val2.EnableKeyword("_EMISSION");
							val2.SetColor("_EmissionColor", val * 2f);
							val2.SetColor("_Color", val);
						}
						else
						{
							val2.EnableKeyword("_EMISSION");
							val2.SetColor("_EmissionColor", new Color(1.934f, 1.017f, 0.185f, 1f));
							val2.SetColor("_Color", Color.white);
						}
					}
				}
				((Renderer)ward.m_model).materials = materials;
			}
			Light[] componentsInChildren = ((Component)ward).GetComponentsInChildren<Light>(true);
			foreach (Light val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					val3.color = new Color(1f, 0.75f, 0.35f, 1f);
					val3.intensity = 2.5f;
					val3.range = 3f;
				}
			}
			ParticleSystem[] componentsInChildren2 = ((Component)ward).GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val4 in componentsInChildren2)
			{
				if (!((Object)(object)val4 == (Object)null))
				{
					string text = ((Object)((Component)val4).gameObject).name.ToLowerInvariant();
					if (text.Contains("glow") || text.Contains("pulse") || text.Contains("flare"))
					{
						EmissionModule emission = val4.emission;
						((EmissionModule)(ref emission)).enabled = false;
						val4.Stop(true, (ParticleSystemStopBehavior)0);
						((Component)val4).gameObject.SetActive(false);
					}
					else
					{
						MainModule main = val4.main;
						((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(1f, 0.5f, 0.1f, 1f));
					}
				}
			}
			if ((Object)(object)ward.m_areaMarker != (Object)null)
			{
				LineRenderer component = ((Component)ward.m_areaMarker).GetComponent<LineRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					Color endColor = (component.startColor = ((activeGod != DeityType.None) ? val : Color.white));
					component.endColor = endColor;
				}
			}
		}

		public static bool CheckOverlapWithOtherActiveWards(PrivateArea candidateWard)
		{
			//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_0055: 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)
			if ((Object)(object)candidateWard == (Object)null)
			{
				return false;
			}
			float num = CalculateRadius(candidateWard);
			Vector3 position = ((Component)candidateWard).transform.position;
			foreach (PrivateArea allArea in GetAllAreas())
			{
				if (!((Object)(object)allArea == (Object)null) && !((Object)(object)allArea == (Object)(object)candidateWard) && IsAreaEnabled(allArea))
				{
					float num2 = CalculateRadius(allArea);
					if (Vector3.Distance(position, ((Component)allArea).transform.position) < num + num2)
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsPositionInsideActiveWard(Vector3 pos, DeityType deity, int minTier = 1)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (PrivateArea allArea in GetAllAreas())
			{
				if (!((Object)(object)allArea == (Object)null) && IsAreaEnabled(allArea) && GetActiveGod(allArea) == deity)
				{
					float num = CalculateRadius(allArea);
					if (Vector3.Distance(pos, ((Component)allArea).transform.position) <= num && GetUnlockedCountForDeity(allArea, deity) >= minTier)
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsPlayerInsideActiveWard(Player player, DeityType deity, int minTier = 1)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			Vector3 position = ((Component)player).transform.position;
			foreach (PrivateArea allArea in GetAllAreas())
			{
				if (!((Object)(object)allArea == (Object)null) && IsAreaEnabled(allArea) && GetActiveGod(allArea) == deity)
				{
					float num = CalculateRadius(allArea);
					if (Vector3.Distance(position, ((Component)allArea).transform.position) <= num && IsPlayerPermitted(allArea, player.GetPlayerID()) && GetUnlockedCountForDeity(allArea, deity) >= minTier)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	public sealed class OfferingCost
	{
		public string ItemPrefab { get; }

		public int Amount { get; }

		public OfferingCost(string itemPrefab, int amount)
		{
			ItemPrefab = itemPrefab;
			Amount = amount;
		}
	}
	public sealed class WardRiteDefinition
	{
		public string Id { get; }

		public DeityType Deity { get; }

		public int Tier { get; }

		public string Name { get; }

		public string RuneGlyph { get; }

		public string Description { get; }

		public IReadOnlyList<OfferingCost> Costs { get; }

		public WardRiteDefinition(string id, DeityType deity, int tier, string name, string runeGlyph, string description, params OfferingCost[] costs)
		{
			Id = id;
			Deity = deity;
			Tier = tier;
			Name = name;
			RuneGlyph = runeGlyph;
			Description = description;
			Costs = costs;
		}
	}
	public static class WardRiteRegistry
	{
		private static readonly Dictionary<string, WardRiteDefinition> _byId;

		private static readonly Dictionary<DeityType, List<WardRiteDefinition>> _byDeity;

		static WardRiteRegistry()
		{
			_byId = new Dictionary<string, WardRiteDefinition>();
			_byDeity = new Dictionary<DeityType, List<WardRiteDefinition>>();
			RegisterOdin();
			RegisterThor();
			RegisterFrey();
			RegisterTyr();
			RegisterFreya();
		}

		private static void Register(WardRiteDefinition def)
		{
			_byId[def.Id] = def;
			if (!_byDeity.TryGetValue(def.Deity, out List<WardRiteDefinition> value))
			{
				value = new List<WardRiteDefinition>();
				_byDeity[def.Deity] = value;
			}
			value.Add(def);
		}

		public static WardRiteDefinition? GetById(string id)
		{
			_byId.TryGetValue(id, out WardRiteDefinition value);
			return value;
		}

		public static IReadOnlyList<WardRiteDefinition> GetForDeity(DeityType deity)
		{
			if (_byDeity.TryGetValue(deity, out List<WardRiteDefinition> value))
			{
				return value;
			}
			return Array.Empty<WardRiteDefinition>();
		}

		private static void RegisterOdin()
		{
			Register(new WardRiteDefinition("odin_1_sanctuary", DeityType.Odin, 1, "Aegis of the Allfather", "ᚩ", "Enforces domestic sanctuary. Unauthorized players in PvP cannot build, deconstruct, or access containers and doors.", new OfferingCost("GreydwarfEye", 10), new OfferingCost("Feathers", 5), new OfferingCost("Ruby", 1)));
			Register(new WardRiteDefinition("odin_2_shroud", DeityType.Odin, 2, "Raven's Shroud", "ᚱ", "Reduces wild roaming creature detection range by 85% outside the perimeter.", new OfferingCost("Guck", 15), new OfferingCost("BoneFragments", 10), new OfferingCost("Feathers", 2)));
			Register(new WardRiteDefinition("odin_3_featherfall", DeityType.Odin, 3, "Rune of Unyielding Stone", "ᛋ", "Eliminates 100% of fall damage within the ward boundary.", new OfferingCost("Obsidian", 15), new OfferingCost("WolfFang", 5), new OfferingCost("DragonEgg", 1)));
			Register(new WardRiteDefinition("odin_4_silent_horizon", DeityType.Odin, 4, "Silent Horizon", "ᚼ", "Reduces the frequency of base raid rolls targeting this settlement by 65%.", new OfferingCost("GoblinTotem", 4), new OfferingCost("Needle", 10), new OfferingCost("Tar", 15)));
			Register(new WardRiteDefinition("odin_5_thought_memory", DeityType.Odin, 5, "Thought & Memory", "ᛗ", "Permitted players gain +50% increased skill XP gain on all actions performed inside the ward boundary.", new OfferingCost("Eitr", 10), new OfferingCost("BlackMarble", 10), new OfferingCost("DvergrNeedle", 3)));
		}

		private static void RegisterThor()
		{
			Register(new WardRiteDefinition("thor_1_armor", DeityType.Thor, 1, "Sparks of Bilskirnir", "ᚦ", "Structural pieces gain +35 flat piece armor against all damage types.", new OfferingCost("Copper", 10), new OfferingCost("Tin", 10), new OfferingCost("SurtlingCore", 5)));
			Register(new WardRiteDefinition("thor_2_stride", DeityType.Thor, 2, "Charged Stride", "ᛏ", "Permitted players gain +30% movement and sprint speed inside the barrier.", new OfferingCost("Iron", 15), new OfferingCost("SurtlingCore", 5), new OfferingCost("Ooze", 10)));
			Register(new WardRiteDefinition("thor_3_weather", DeityType.Thor, 3, "Stormcaller's Aegis", "ᛊ", "Immunity to adverse weather debuffs (Freezing, Cold, Wet) inside the sphere. Fires never extinguish from rain.", new OfferingCost("Silver", 15), new OfferingCost("FreezeGland", 5), new OfferingCost("Crystal", 1)));
			Register(new WardRiteDefinition("thor_4_craftspeed", DeityType.Thor, 4, "Craftsman's Spark", "ᛈ", "Crafting, building, and hammer repairs are accelerated by 60%.", new OfferingCost("BlackMetal", 20), new OfferingCost("LinenThread", 10), new OfferingCost("SurtlingCore", 10)));
			Register(new WardRiteDefinition("thor_5_rebate", DeityType.Thor, 5, "Forge of Thrudvang", "ᚹ", "Crafting weapons, armor, and base structures grants a 15% chance to duplicate/refund materials.", new OfferingCost("FlametalNew", 15), new OfferingCost("Softtissue", 10), new OfferingCost("WoodAsh", 5)));
		}

		private static void RegisterFrey()
		{
			Register(new WardRiteDefinition("frey_1_crops", DeityType.Frey, 1, "Sun of the Vanir", "ᚠ", "Crops, flora, and trees planted within the ward grow 35% faster.", new OfferingCost("CarrotSeeds", 10), new OfferingCost("AncientSeed", 10), new OfferingCost("Honey", 20)));
			Register(new WardRiteDefinition("frey_2_food_freeze", DeityType.Frey, 2, "Preserving Cellar", "ᛃ", "Active food buff decay timers are frozen on permitted players while resting or standing within the ward sphere.", new OfferingCost("TurnipSeeds", 10), new OfferingCost("Entrails", 15), new OfferingCost("Bloodbag", 10)));
			Register(new WardRiteDefinition("frey_3_cooking_speed", DeityType.Frey, 3, "Ever-Warm Hearth", "ᚲ", "Cauldrons, fermenters, and cooking ovens process foods, meads, and potions 60% faster.", new OfferingCost("Sausages", 10), new OfferingCost("OnionSeeds", 10), new OfferingCost("WolfMeat", 10)));
			Register(new WardRiteDefinition("frey_4_mill_speed", DeityType.Frey, 4, "Bountiful Grain", "ᛒ", "Windmills and grain processing operate at double speed (+100%).", new OfferingCost("Barley", 30), new OfferingCost("Cloudberry", 20), new OfferingCost("LoxMeat", 10)));
			Register(new WardRiteDefinition("frey_5_harvest_yield", DeityType.Frey, 5, "Feast of Skírnir", "ᛜ", "Gathering and harvesting plants and crops yields +30% bonus produce (handled via VikingLib ForagingYield).", new OfferingCost("MushroomMagecap", 20), new OfferingCost("MushroomJotunPuffs", 20), new OfferingCost("RoyalJelly", 5)));
		}

		private static void RegisterTyr()
		{
			Register(new WardRiteDefinition("tyr_1_damage", DeityType.Tyr, 1, "Vanguard Stance", "ᛏ", "Permitted defenders deal +30% increased damage against all targets while inside the ward boundary.", new OfferingCost("Bronze", 10), new OfferingCost("BoneFragments", 10), new OfferingCost("TrollHide", 5)));
			Register(new WardRiteDefinition("tyr_2_armor", DeityType.Tyr, 2, "Shieldwall Rite", "ᛉ", "Permitted defenders gain +30 flat body armor while inside the ward boundary.", new OfferingCost("Iron", 20), new OfferingCost("Chain", 10), new OfferingCost("Root", 5)));
			Register(new WardRiteDefinition("tyr_3_stamina", DeityType.Tyr, 3, "Unyielding Endurance", "ᚢ", "Weapon attack stamina efficiency is increased by +35% for all permitted players.", new OfferingCost("Silver", 15), new OfferingCost("WolfFang", 10), new OfferingCost("WolfClaw", 5)));
			Register(new WardRiteDefinition("tyr_4_kill_restore", DeityType.Tyr, 4, "Tyr's Judgment", "ᛞ", "Slaying an enemy inside the perimeter restores +15 Health and +30 Stamina to the killer.", new OfferingCost("BlackMetal", 20), new OfferingCost("Needle", 10), new OfferingCost("TrophyGoblinBrute", 1)));
			Register(new WardRiteDefinition("tyr_5_slow_field", DeityType.Tyr, 5, "Biting Fetters", "ᚾ", "Hostile creatures entering the ward boundary suffer a continuous 35% movement speed slow debuff.", new OfferingCost("Carapace", 15), new OfferingCost("Mandible", 10), new OfferingCost("Sinew", 5)));
		}

		private static void RegisterFreya()
		{
			Register(new WardRiteDefinition("freya_1_procreation", DeityType.Freya, 1, "Mother of Beasts", "ᛖ", "Tamed animals (boars, wolves, lox, asksvin) mate and procreate 60% faster within the ward.", new OfferingCost("Dandelion", 20), new OfferingCost("Raspberry", 20), new OfferingCost("TrophyDeer", 5)));
			Register(new WardRiteDefinition("freya_2_health_regen", DeityType.Freya, 2, "Sylvan Shelter", "ᛚ", "Permitted players gain +60% health regeneration rate inside the perimeter.", new OfferingCost("ElderBark", 20), new OfferingCost("Guck", 15), new OfferingCost("Thistle", 10)));
			Register(new WardRiteDefinition("freya_3_taming_speed", DeityType.Freya, 3, "Soothing Caress", "ᛈ", "Acclimating and taming wild beasts progresses twice as fast (+100%).", new OfferingCost("FreezeGland", 20), new OfferingCost("WolfPelt", 10), new OfferingCost("Cloudberry", 5)));
			Register(new WardRiteDefinition("freya_4_comfort", DeityType.Freya, 4, "Cat-Drawn Carriage", "ᛟ", "Base Comfort level is increased by +3 within the ward sphere (+3 min Rested duration).", new OfferingCost("Tar", 15), new OfferingCost("LoxPelt", 10), new OfferingCost("Flax", 15)));
			Register(new WardRiteDefinition("freya_5_tool_stamina", DeityType.Freya, 5, "Sanctuary of Fólkvangr", "ᛝ", "Tool stamina efficiency (hammer, hoe, cultivator, axes, pickaxes) is increased by +80% within the perimeter.", new OfferingCost("Softtissue", 15), new OfferingCost("Sap", 15), new OfferingCost("AsksvinHide", 5)));
		}
	}
}