Decompiled source of WatchPillar v1.0.1

WatchPillar.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[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("WatchPillar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("WatchPillar")]
[assembly: AssemblyTitle("WatchPillar")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WatchPillar
{
	public class PillarArea : MonoBehaviour
	{
		private const float Step = 2.5f;

		private const float ShowTime = 0.5f;

		private const float SegmentScale = 1.6f;

		private const float ZoneSize = 64f;

		private static GameObject segmentPrefab;

		private static bool segmentSearched;

		private static int terrainMask;

		private readonly List<Transform> segments = new List<Transform>();

		private GameObject marker;

		private float hideTime;

		private float nextLayout;

		private Vector2s laidZone;

		private int laidRadius = -1;

		public void Show()
		{
			hideTime = Time.time + 0.5f;
			((Behaviour)this).enabled = true;
		}

		private void Update()
		{
			bool flag = Player.IsPlacementGhost(((Component)this).gameObject);
			if (!flag && Time.time >= hideTime)
			{
				if ((Object)(object)marker != (Object)null && marker.activeSelf)
				{
					marker.SetActive(false);
				}
				((Behaviour)this).enabled = false;
			}
			else
			{
				Layout(flag);
			}
		}

		private void Layout(bool ghost)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_008c: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = SegmentPrefab();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if ((Object)(object)marker == (Object)null)
			{
				marker = new GameObject("q8wp_area");
				marker.transform.SetParent(((Component)this).transform, false);
			}
			if (!marker.activeSelf)
			{
				marker.SetActive(true);
				nextLayout = 0f;
			}
			int num = Mathf.Clamp(WatchPillarPlugin.Radius.Value, 0, 2);
			Vector2s zone = ZoneSystem.GetZone(((Component)this).transform.position);
			if (zone == laidZone && num == laidRadius && Time.time < nextLayout)
			{
				return;
			}
			nextLayout = Time.time + (ghost ? 0.25f : 1f);
			laidZone = zone;
			laidRadius = num;
			float num2 = (float)(zone.x - num) * 64f - 32f;
			float num3 = (float)(zone.x + num) * 64f + 32f;
			float num4 = (float)(zone.y - num) * 64f - 32f;
			float num5 = (float)(zone.y + num) * 64f + 32f;
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(num2, 0f, num4),
				new Vector3(num3, 0f, num4),
				new Vector3(num3, 0f, num5),
				new Vector3(num2, 0f, num5)
			};
			float num6 = num3 - num2;
			int num7 = Mathf.CeilToInt(num6 / 2.5f);
			EnsureSegments(val, num7 * 4);
			int num8 = 0;
			for (int i = 0; i < 4; i++)
			{
				Vector3 val2 = array[i];
				Vector3 val3 = array[(i + 1) % 4] - val2;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Quaternion val4 = Quaternion.LookRotation(normalized, Vector3.up);
				for (int j = 0; j < num7; j++)
				{
					Vector3 val5 = val2 + normalized * (num6 * ((float)j + 0.5f) / (float)num7);
					val5.y = GroundHeight(val5) + 0.05f;
					Transform val6 = segments[num8++];
					val6.SetPositionAndRotation(val5, val4);
					if (!((Component)val6).gameObject.activeSelf)
					{
						((Component)val6).gameObject.SetActive(true);
					}
				}
			}
			for (int k = num8; k < segments.Count; k++)
			{
				((Component)segments[k]).gameObject.SetActive(false);
			}
		}

		private void EnsureSegments(GameObject prefab, int count)
		{
			//IL_0020: 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)
			while (segments.Count < count)
			{
				GameObject val = Object.Instantiate<GameObject>(prefab, marker.transform);
				val.transform.localScale = prefab.transform.localScale * 1.6f;
				segments.Add(val.transform);
			}
		}

		private static float GroundHeight(Vector3 p)
		{
			//IL_001f: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (terrainMask == 0)
			{
				terrainMask = LayerMask.GetMask(new string[1] { "terrain" });
			}
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(new Vector3(p.x, 3000f, p.z), Vector3.down, ref val, 6000f, terrainMask))
			{
				return ((RaycastHit)(ref val)).point.y;
			}
			if (WorldGenerator.instance == null)
			{
				return p.y;
			}
			return WorldGenerator.instance.GetHeight(p.x, p.z);
		}

		private static GameObject SegmentPrefab()
		{
			if (segmentSearched)
			{
				return segmentPrefab;
			}
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return null;
			}
			segmentSearched = true;
			GameObject prefab = ZNetScene.instance.GetPrefab("guard_stone");
			CircleProjector val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponentInChildren<CircleProjector>(true) : null);
			segmentPrefab = (((Object)(object)val != (Object)null) ? val.m_prefab : null);
			if ((Object)(object)segmentPrefab == (Object)null)
			{
				WatchPillarPlugin.Log.LogWarning((object)"The ward's area marker not found, the pillar will not show its border.");
			}
			return segmentPrefab;
		}
	}
	[HarmonyPatch(typeof(Fireplace), "GetHoverText")]
	internal static class FireplaceHoverPatch
	{
		private static void Postfix(Fireplace __instance, ref string __result)
		{
			if (__instance.m_name != "$piece_q8wp_pillar")
			{
				return;
			}
			PillarArea component = ((Component)__instance).GetComponent<PillarArea>();
			if ((Object)(object)component != (Object)null)
			{
				component.Show();
			}
			ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component2 == (Object)null || !component2.IsValid())
			{
				return;
			}
			ZDO zDO = component2.GetZDO();
			bool infiniteFuel = __instance.m_infiniteFuel;
			string text;
			if (ZoneKeeper.IsBurning(zDO, infiniteFuel))
			{
				int num = Mathf.Clamp(WatchPillarPlugin.Radius.Value, 0, 2) * 2 + 1;
				int num2 = num * 64;
				text = $"$q8wp_hover_area: {num}×{num} $q8wp_zones ({num2}×{num2} $q8wp_m)";
				if (!infiniteFuel)
				{
					float minutes = zDO.GetFloat(ZDOVars.s_fuel, 0f) * WatchPillarPlugin.MinutesPerFuel.Value;
					text = text + "\n$q8wp_hover_left ~" + FormatMinutes(minutes);
				}
			}
			else
			{
				text = "$q8wp_hover_idle";
			}
			string text2 = Localization.instance.Localize(text);
			if (string.IsNullOrEmpty(__result))
			{
				__result = Localization.instance.Localize(__instance.m_name) + "\n" + text2;
				return;
			}
			int num3 = __result.IndexOf('\n');
			__result = ((num3 < 0) ? (__result + "\n" + text2) : (__result.Substring(0, num3) + "\n" + text2 + __result.Substring(num3)));
		}

		private static string FormatMinutes(float minutes)
		{
			int num = Mathf.Max(1, Mathf.CeilToInt(minutes));
			int num2 = num / 60;
			int num3 = num % 60;
			if (num2 == 0)
			{
				return $"{num3} $q8wp_min";
			}
			if (num3 != 0)
			{
				return $"{num2} $q8wp_h {num3} $q8wp_min";
			}
			return $"{num2} $q8wp_h";
		}
	}
	internal static class PillarModel
	{
		internal sealed class Materials
		{
			public Material Stone;

			public Material RuneDark;

			public Material RuneLit;
		}

		private sealed class MeshBuilder
		{
			public readonly List<Vector3> Vertices = new List<Vector3>();

			public readonly List<Vector3> Normals = new List<Vector3>();

			public readonly List<Vector2> Uvs = new List<Vector2>();

			public readonly List<int> Triangles = new List<int>();

			public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 normal, Vector2 ua, Vector2 ub, Vector2 uc, Vector2 ud)
			{
				//IL_0012: 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_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: 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_008b: 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_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: 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)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				int count = Vertices.Count;
				Vertices.Add(a);
				Vertices.Add(b);
				Vertices.Add(c);
				Vertices.Add(d);
				Uvs.Add(ua);
				Uvs.Add(ub);
				Uvs.Add(uc);
				Uvs.Add(ud);
				for (int i = 0; i < 4; i++)
				{
					Normals.Add(normal);
				}
				if (Vector3.Dot(Vector3.Cross(b - a, c - a), normal) >= 0f)
				{
					Triangles.AddRange(new int[6]
					{
						count,
						count + 1,
						count + 2,
						count,
						count + 2,
						count + 3
					});
				}
				else
				{
					Triangles.AddRange(new int[6]
					{
						count,
						count + 2,
						count + 1,
						count,
						count + 3,
						count + 2
					});
				}
			}

			public Mesh ToMesh(string name)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				Mesh val = new Mesh
				{
					name = name
				};
				val.SetVertices(Vertices);
				val.SetNormals(Normals);
				val.SetUVs(0, Uvs);
				val.SetTriangles(Triangles, 0);
				val.RecalculateTangents();
				val.RecalculateBounds();
				return val;
			}
		}

		internal const string LitName = "_enabled";

		private const float TexelsPerMetre = 0.125f;

		private const float AtlasV0 = 0.012f;

		private static readonly float[] FaceU0 = new float[4] { 0.06f, 0.18f, 0.3f, 0.42f };

		private const float ShaftHalf = 0.25f;

		private const float ShaftBottom = 0.2f;

		private const float ShaftTop = 2f;

		private static readonly Vector3[] Blocks = (Vector3[])(object)new Vector3[5]
		{
			new Vector3(0.39f, 0f, 0.12f),
			new Vector3(0.32f, 0.12f, 0.2f),
			new Vector3(0.25f, 0.2f, 2f),
			new Vector3(0.31f, 2f, 2.08f),
			new Vector3(0.38f, 2.08f, 2.2f)
		};

		private const int RuneColumns = 3;

		private const int RuneRows = 7;

		private const float RuneWidth = 0.1f;

		private const float RuneHeight = 0.16f;

		private const float RuneColumnStep = 0.13f;

		private const float RuneRowStep = 0.21f;

		private const float RuneFirstRow = 0.55f;

		private const float StrokeWidth = 0.017f;

		private static readonly Vector2[][] Glyphs = new Vector2[22][]
		{
			G(0.2f, 0f, 0.2f, 1f, 0.2f, 0.55f, 0.8f, 0.82f, 0.2f, 0.8f, 0.75f, 1f),
			G(0.2f, 0f, 0.2f, 1f, 0.2f, 1f, 0.8f, 0.7f, 0.8f, 0.7f, 0.8f, 0f),
			G(0.25f, 0f, 0.25f, 1f, 0.25f, 0.72f, 0.75f, 0.5f, 0.75f, 0.5f, 0.25f, 0.28f),
			G(0.25f, 0f, 0.25f, 1f, 0.25f, 1f, 0.75f, 0.78f, 0.25f, 0.75f, 0.75f, 0.53f),
			G(0.25f, 0f, 0.25f, 1f, 0.25f, 1f, 0.75f, 0.78f, 0.75f, 0.78f, 0.25f, 0.55f, 0.25f, 0.55f, 0.75f, 0f),
			G(0.7f, 0.85f, 0.3f, 0.55f, 0.3f, 0.55f, 0.7f, 0.25f),
			G(0.15f, 0.1f, 0.85f, 0.9f, 0.85f, 0.1f, 0.15f, 0.9f),
			G(0.25f, 0f, 0.25f, 1f, 0.25f, 1f, 0.75f, 0.78f, 0.75f, 0.78f, 0.25f, 0.56f),
			G(0.2f, 0f, 0.2f, 1f, 0.8f, 0f, 0.8f, 1f, 0.2f, 0.65f, 0.8f, 0.35f),
			G(0.5f, 0f, 0.5f, 1f, 0.2f, 0.68f, 0.8f, 0.4f),
			G(0.5f, 0f, 0.5f, 1f),
			G(0.5f, 0f, 0.5f, 1f, 0.5f, 1f, 0.8f, 0.8f, 0.5f, 0f, 0.2f, 0.2f),
			G(0.5f, 0f, 0.5f, 1f, 0.5f, 0.55f, 0.15f, 0.95f, 0.5f, 0.55f, 0.85f, 0.95f),
			G(0.7f, 1f, 0.25f, 0.65f, 0.25f, 0.65f, 0.75f, 0.35f, 0.75f, 0.35f, 0.3f, 0f),
			G(0.5f, 0f, 0.5f, 1f, 0.5f, 1f, 0.15f, 0.7f, 0.5f, 1f, 0.85f, 0.7f),
			G(0.25f, 0f, 0.25f, 1f, 0.25f, 1f, 0.75f, 0.75f, 0.75f, 0.75f, 0.25f, 0.5f, 0.25f, 0.5f, 0.75f, 0.25f, 0.75f, 0.25f, 0.25f, 0f),
			G(0.15f, 0f, 0.15f, 1f, 0.15f, 1f, 0.5f, 0.7f, 0.5f, 0.7f, 0.85f, 1f, 0.85f, 1f, 0.85f, 0f),
			G(0.15f, 0f, 0.15f, 1f, 0.85f, 0f, 0.85f, 1f, 0.15f, 1f, 0.85f, 0.55f, 0.85f, 1f, 0.15f, 0.55f),
			G(0.3f, 0f, 0.3f, 1f, 0.3f, 1f, 0.75f, 0.7f),
			G(0.5f, 0.85f, 0.8f, 0.5f, 0.8f, 0.5f, 0.5f, 0.15f, 0.5f, 0.15f, 0.2f, 0.5f, 0.2f, 0.5f, 0.5f, 0.85f),
			G(0.15f, 0f, 0.15f, 1f, 0.15f, 1f, 0.85f, 0f, 0.85f, 0f, 0.85f, 1f, 0.85f, 1f, 0.15f, 0f),
			G(0.5f, 1f, 0.8f, 0.65f, 0.8f, 0.65f, 0.2f, 0f, 0.5f, 1f, 0.2f, 0.65f, 0.2f, 0.65f, 0.8f, 0f)
		};

		private static readonly Vector3[] FaceNormals = (Vector3[])(object)new Vector3[4]
		{
			Vector3.forward,
			Vector3.right,
			Vector3.back,
			Vector3.left
		};

		private static Vector2[] G(params float[] xy)
		{
			//IL_001d: 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)
			Vector2[] array = (Vector2[])(object)new Vector2[xy.Length / 2];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Vector2(xy[2 * i], xy[2 * i + 1]);
			}
			return array;
		}

		internal static Materials FindMaterials(GameObject stonePillar)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			Materials materials = new Materials();
			MeshRenderer[] componentsInChildren = stonePillar.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial != (Object)null && ((Object)((Renderer)val).sharedMaterial).name.StartsWith("stone_mat") && !((Object)((Renderer)val).sharedMaterial).name.Contains("worn"))
				{
					materials.Stone = ((Renderer)val).sharedMaterial;
					break;
				}
			}
			if ((Object)(object)materials.Stone == (Object)null)
			{
				MeshRenderer componentInChildren = stonePillar.GetComponentInChildren<MeshRenderer>(true);
				materials.Stone = (((Object)(object)componentInChildren != (Object)null) ? ((Renderer)componentInChildren).sharedMaterial : null);
			}
			if ((Object)(object)materials.Stone != (Object)null)
			{
				materials.RuneDark = new Material(materials.Stone)
				{
					name = "q8wp_rune_dark"
				};
				materials.RuneDark.color = new Color(0.16f, 0.16f, 0.17f, 1f);
			}
			GameObject prefab = Cache.GetPrefab<GameObject>("GreydwarfEye");
			if ((Object)(object)prefab != (Object)null)
			{
				componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Material sharedMaterial = ((Renderer)componentsInChildren[i]).sharedMaterial;
					if ((Object)(object)sharedMaterial != (Object)null && sharedMaterial.IsKeywordEnabled("_EMISSION") && sharedMaterial.HasProperty("_EmissionColor"))
					{
						materials.RuneLit = new Material(sharedMaterial)
						{
							name = "q8wp_rune_lit"
						};
						break;
					}
				}
			}
			if ((Object)(object)materials.RuneLit == (Object)null && (Object)(object)materials.Stone != (Object)null)
			{
				WatchPillarPlugin.Log.LogWarning((object)"Greydwarf eye glow not found, the runes will not glow.");
				materials.RuneLit = new Material(materials.Stone)
				{
					name = "q8wp_rune_lit",
					color = new Color(0.35f, 0.75f, 1f)
				};
			}
			return materials;
		}

		internal static GameObject Build(Transform root, Materials materials)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			int layer = ((Component)root).gameObject.layer;
			AddCollider(root, "collider_base", 0.39f, 0f, 0.2f, layer);
			AddCollider(root, "collider_shaft", 0.25f, 0.2f, 2f, layer);
			AddCollider(root, "collider_top", 0.38f, 2f, 2.2f, layer);
			GameObject val = new GameObject("model");
			val.layer = layer;
			val.transform.SetParent(root, false);
			GameObject val2 = new GameObject("_enabled");
			val2.layer = layer;
			val2.transform.SetParent(val.transform, false);
			val2.SetActive(false);
			if (materials == null || (Object)(object)materials.Stone == (Object)null)
			{
				return val;
			}
			AddMesh(val.transform, "stone", BuildStoneMesh(), materials.Stone, layer, shadows: true);
			AddMesh(val.transform, "runes", BuildRuneMesh(0.0015f), materials.RuneDark, layer, shadows: false);
			AddMesh(val2.transform, "runes_lit", BuildRuneMesh(0.003f), materials.RuneLit, layer, shadows: false);
			GameObject val3 = new GameObject("light")
			{
				layer = layer
			};
			val3.transform.SetParent(val2.transform, false);
			val3.transform.localPosition = new Vector3(0f, 1.3f, 0f);
			Light obj = val3.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = new Color(0.45f, 0.8f, 1f);
			obj.range = 5f;
			obj.intensity = 1.1f;
			obj.shadows = (LightShadows)0;
			return val;
		}

		private static void AddCollider(Transform root, string name, float half, float bottom, float top, int layer)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(root, false);
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.center = new Vector3(0f, (bottom + top) * 0.5f, 0f);
			obj.size = new Vector3(half * 2f, top - bottom, half * 2f);
		}

		private static void AddMesh(Transform parent, string name, Mesh mesh, Material material, int layer, bool shadows)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)(shadows ? 1 : 0);
		}

		private static Vector3 RightOf(Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.LookRotation(-normal) * Vector3.right;
		}

		private static Vector2 SideUv(Vector3 point, Vector3 normal, int face)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			float num = Vector3.Dot(point, RightOf(normal));
			return new Vector2(FaceU0[face] + (num + 0.4f) * 0.125f, 0.012f + point.y * 0.125f);
		}

		private static Vector2 FlatUv(Vector3 point)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(FaceU0[0] + (point.x + 0.4f) * 0.125f, 0.012f + (point.z + 0.4f) * 0.125f);
		}

		private static Mesh BuildStoneMesh()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_004f: 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)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0070: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_016a: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			Vector3[] blocks = Blocks;
			Vector3 val8 = default(Vector3);
			Vector3 val9 = default(Vector3);
			Vector3 val10 = default(Vector3);
			Vector3 val11 = default(Vector3);
			Vector3 val12 = default(Vector3);
			Vector3 val13 = default(Vector3);
			Vector3 val14 = default(Vector3);
			Vector3 val15 = default(Vector3);
			foreach (Vector3 val in blocks)
			{
				float x = val.x;
				float y = val.y;
				float z = val.z;
				for (int j = 0; j < 4; j++)
				{
					Vector3 val2 = FaceNormals[j];
					Vector3 val3 = RightOf(val2);
					Vector3 val4 = val2 * x - val3 * x + Vector3.up * y;
					Vector3 val5 = val2 * x + val3 * x + Vector3.up * y;
					Vector3 val6 = val2 * x + val3 * x + Vector3.up * z;
					Vector3 val7 = val2 * x - val3 * x + Vector3.up * z;
					meshBuilder.Quad(val4, val5, val6, val7, val2, SideUv(val4, val2, j), SideUv(val5, val2, j), SideUv(val6, val2, j), SideUv(val7, val2, j));
				}
				((Vector3)(ref val8))..ctor(0f - x, z, 0f - x);
				((Vector3)(ref val9))..ctor(x, z, 0f - x);
				((Vector3)(ref val10))..ctor(x, z, x);
				((Vector3)(ref val11))..ctor(0f - x, z, x);
				meshBuilder.Quad(val8, val9, val10, val11, Vector3.up, FlatUv(val8), FlatUv(val9), FlatUv(val10), FlatUv(val11));
				((Vector3)(ref val12))..ctor(0f - x, y, 0f - x);
				((Vector3)(ref val13))..ctor(x, y, 0f - x);
				((Vector3)(ref val14))..ctor(x, y, x);
				((Vector3)(ref val15))..ctor(0f - x, y, x);
				meshBuilder.Quad(val12, val13, val14, val15, Vector3.down, FlatUv(val12), FlatUv(val13), FlatUv(val14), FlatUv(val15));
			}
			return meshBuilder.ToMesh("q8wp_pillar_stone");
		}

		private static Mesh BuildRuneMesh(float offset)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			Vector2 p = default(Vector2);
			Vector2 p2 = default(Vector2);
			for (int i = 0; i < 4; i++)
			{
				Vector3 val = FaceNormals[i];
				Vector3 right = RightOf(val);
				Vector3 surface = val * (0.25f + offset);
				for (int j = 0; j < 7; j++)
				{
					for (int k = 0; k < 3; k++)
					{
						int num = (i * 7 + j * 5 + k * 3 + j * k) % Glyphs.Length;
						Vector2[] array = Glyphs[num];
						float num2 = ((float)k - 1f) * 0.13f;
						float num3 = 0.55f + (float)j * 0.21f;
						for (int l = 0; l + 1 < array.Length; l += 2)
						{
							((Vector2)(ref p))..ctor(num2 + (array[l].x - 0.5f) * 0.1f, num3 + (array[l].y - 0.5f) * 0.16f);
							((Vector2)(ref p2))..ctor(num2 + (array[l + 1].x - 0.5f) * 0.1f, num3 + (array[l + 1].y - 0.5f) * 0.16f);
							AddStroke(meshBuilder, surface, right, val, i, p, p2);
						}
					}
				}
			}
			return meshBuilder.ToMesh("q8wp_pillar_runes");
		}

		private static void AddStroke(MeshBuilder builder, Vector3 surface, Vector3 right, Vector3 normal, int face, Vector2 p0, Vector2 p1)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_003c: 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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_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)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0086: 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_008d: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = p1 - p0;
			if (!(((Vector2)(ref val)).sqrMagnitude < 1E-08f))
			{
				((Vector2)(ref val)).Normalize();
				Vector2 val2 = new Vector2(0f - val.y, val.x) * 0.0085f;
				Vector2 val3 = val * 0.0085f;
				Vector3 val4 = ToFace(surface, right, p0 - val3 - val2);
				Vector3 val5 = ToFace(surface, right, p0 - val3 + val2);
				Vector3 val6 = ToFace(surface, right, p1 + val3 + val2);
				Vector3 val7 = ToFace(surface, right, p1 + val3 - val2);
				builder.Quad(val4, val5, val6, val7, normal, SideUv(val4, normal, face), SideUv(val5, normal, face), SideUv(val6, normal, face), SideUv(val7, normal, face));
			}
		}

		private static Vector3 ToFace(Vector3 surface, Vector3 right, Vector2 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			return surface + right * point.x + Vector3.up * point.y;
		}
	}
	internal static class PillarPiece
	{
		public const string PrefabName = "Q8_WatchPillar";

		public const string NameToken = "$piece_q8wp_pillar";

		public const string DescriptionToken = "$piece_q8wp_pillar_desc";

		private const string BasePrefabName = "stone_pillar";

		internal static GameObject Prefab;

		internal static void Register()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Invalid comparison between Unknown and I4
			//IL_0223: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("Q8_WatchPillar", "stone_pillar");
			if ((Object)(object)val == (Object)null)
			{
				WatchPillarPlugin.Log.LogError((object)"Base prefab stone_pillar not found, the watch pillar is not added.");
				return;
			}
			Piece component = val.GetComponent<Piece>();
			WearNTear component2 = val.GetComponent<WearNTear>();
			if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
			{
				WatchPillarPlugin.Log.LogError((object)"Base prefab stone_pillar has no Piece or WearNTear, the watch pillar is not added.");
				return;
			}
			bool flag = (int)SystemInfo.graphicsDeviceType == 4;
			PillarModel.Materials materials = (flag ? null : PillarModel.FindMaterials(val));
			for (int num = val.transform.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val.transform.GetChild(num)).gameObject);
			}
			Collider[] components = val.GetComponents<Collider>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			LODGroup component3 = val.GetComponent<LODGroup>();
			if ((Object)(object)component3 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component3);
			}
			GameObject val2 = PillarModel.Build(val.transform, materials);
			GameObject gameObject = ((Component)val2.transform.Find("_enabled")).gameObject;
			component2.m_new = val2;
			component2.m_worn = val2;
			component2.m_broken = val2;
			component2.m_wet = null;
			component2.m_snow = null;
			component2.m_snowWorn = null;
			component2.m_snowBroken = null;
			component2.m_fragmentRoots = null;
			Fireplace val3 = val.AddComponent<Fireplace>();
			val3.m_name = "$piece_q8wp_pillar";
			val3.m_startFuel = 0f;
			val3.m_canTurnOff = false;
			val3.m_canRefill = true;
			val3.m_disableCoverCheck = true;
			val3.m_igniteInterval = 0f;
			val3.m_igniteChance = 0f;
			val3.m_firePrefab = null;
			val3.m_smokeSpawner = null;
			val3.m_fireworkItemList = (FireworkItem[])(object)new FireworkItem[0];
			val3.m_enabledObject = gameObject;
			GameObject prefab = Cache.GetPrefab<GameObject>("piece_brazierfloor01");
			Fireplace val4 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Fireplace>() : null);
			if ((Object)(object)val4 != (Object)null)
			{
				val3.m_fuelAddedEffects = val4.m_fuelAddedEffects;
			}
			ApplyFuelRules(val3, fromCache: true);
			val.AddComponent<PillarArea>();
			PieceConfig val5 = new PieceConfig
			{
				Name = "$piece_q8wp_pillar",
				Description = "$piece_q8wp_pillar_desc",
				PieceTable = PieceTables.Hammer,
				Category = PieceCategories.Misc,
				CraftingStation = CraftingStations.Workbench,
				Requirements = ParseRecipe(WatchPillarPlugin.Recipe.Value).ToArray()
			};
			if (!flag)
			{
				val5.Icon = RenderIcon(val2);
			}
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, true, val5)))
			{
				WatchPillarPlugin.Log.LogError((object)"Jotunn rejected the watch pillar piece.");
			}
			else
			{
				Prefab = val;
			}
		}

		private static Sprite RenderIcon(GameObject model)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0045: 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_0064: Expected O, but got Unknown
			GameObject val = null;
			try
			{
				val = Object.Instantiate<GameObject>(model);
				((Component)val.transform.Find("_enabled")).gameObject.SetActive(true);
				Sprite val2 = RenderManager.Instance.Render(new RenderRequest(val)
				{
					Width = 128,
					Height = 128,
					Rotation = Quaternion.Euler(0f, -35f, 0f)
				});
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			catch (Exception ex)
			{
				WatchPillarPlugin.Log.LogWarning((object)("Could not render the pillar icon: " + ex.Message));
			}
			finally
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val);
				}
			}
			GameObject prefab = Cache.GetPrefab<GameObject>("SurtlingCore");
			ItemDrop val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val3 != (Object)null) || val3.m_itemData.m_shared.m_icons.Length == 0)
			{
				return null;
			}
			return val3.m_itemData.m_shared.m_icons[0];
		}

		private static void ApplyFuelRules(Fireplace fire, bool fromCache)
		{
			fire.m_maxFuel = WatchPillarPlugin.MaxFuel.Value;
			fire.m_secPerFuel = Mathf.Max(1f, WatchPillarPlugin.MinutesPerFuel.Value * 60f);
			fire.m_infiniteFuel = WatchPillarPlugin.InfiniteFuel.Value;
			ItemDrop val = FindItem(WatchPillarPlugin.FuelItem.Value, fromCache);
			if ((Object)(object)val != (Object)null)
			{
				fire.m_fuelItem = val;
			}
			else if ((Object)(object)fire.m_fuelItem == (Object)null)
			{
				WatchPillarPlugin.Log.LogWarning((object)("Fuel item '" + WatchPillarPlugin.FuelItem.Value + "' not found, the pillar burns coal."));
				fire.m_fuelItem = FindItem("Coal", fromCache);
			}
		}

		internal static void ApplyFuelRulesEverywhere()
		{
			if ((Object)(object)Prefab == (Object)null)
			{
				return;
			}
			ApplyFuelRules(Prefab.GetComponent<Fireplace>(), fromCache: false);
			Fireplace[] array = Object.FindObjectsByType<Fireplace>((FindObjectsSortMode)0);
			foreach (Fireplace val in array)
			{
				if (val.m_name == "$piece_q8wp_pillar")
				{
					ApplyFuelRules(val, fromCache: false);
				}
			}
		}

		internal static void ApplyRecipe()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_009c: Expected O, but got Unknown
			if ((Object)(object)Prefab == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			List<Requirement> list = new List<Requirement>();
			foreach (RequirementConfig item in ParseRecipe(WatchPillarPlugin.Recipe.Value))
			{
				ItemDrop val = FindItem(item.Item, fromCache: false);
				if ((Object)(object)val == (Object)null)
				{
					WatchPillarPlugin.Log.LogWarning((object)("Recipe item '" + item.Item + "' not found, skipped."));
					continue;
				}
				list.Add(new Requirement
				{
					m_resItem = val,
					m_amount = item.Amount,
					m_recover = true
				});
			}
			if (list.Count > 0)
			{
				Prefab.GetComponent<Piece>().m_resources = list.ToArray();
			}
		}

		private static ItemDrop FindItem(string name, bool fromCache)
		{
			if (string.IsNullOrEmpty(name))
			{
				return null;
			}
			GameObject val = ((!fromCache && (Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(name) : Cache.GetPrefab<GameObject>(name));
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<ItemDrop>();
		}

		internal static List<RequirementConfig> ParseRecipe(string text)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			List<RequirementConfig> list = new List<RequirementConfig>();
			string[] array = (text ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text2 in array)
			{
				string[] array2 = text2.Split(new char[1] { ':' });
				if (array2.Length != 2 || array2[0].Trim().Length == 0 || !int.TryParse(array2[1].Trim(), out var result) || result < 1)
				{
					WatchPillarPlugin.Log.LogWarning((object)("Recipe entry '" + text2 + "' is ignored, expected Item:amount."));
				}
				else
				{
					list.Add(new RequirementConfig(array2[0].Trim(), result, 0, true));
				}
			}
			if (list.Count == 0)
			{
				list.Add(new RequirementConfig("Stone", 25, 0, true));
				list.Add(new RequirementConfig("Wood", 10, 0, true));
				list.Add(new RequirementConfig("SurtlingCore", 1, 0, true));
				list.Add(new RequirementConfig("GreydwarfEye", 5, 0, true));
			}
			return list;
		}
	}
	[BepInPlugin("qua8ion.valheim.watchpillar", "WatchPillar", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class WatchPillarPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "qua8ion.valheim.watchpillar";

		public const string PluginName = "WatchPillar";

		public const string PluginVersion = "1.0.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> Radius;

		internal static ConfigEntry<string> FuelItem;

		internal static ConfigEntry<float> MinutesPerFuel;

		internal static ConfigEntry<int> MaxFuel;

		internal static ConfigEntry<bool> InfiniteFuel;

		internal static ConfigEntry<bool> KeepWhenEmpty;

		internal static ConfigEntry<string> Recipe;

		private void Awake()
		{
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Radius = Rule("Rules", "Radius", 1, "How many zones around its own zone a burning pillar keeps alive. A zone is a 64 x 64 m square of the world grid. 0: only the zone the pillar stands in. 1: a 3 x 3 square of zones, 192 x 192 m. 2: 5 x 5, 320 x 320 m.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2));
			FuelItem = Rule("Rules", "FuelItem", "Coal", "Prefab name of the item the pillar burns.");
			MinutesPerFuel = Rule("Rules", "MinutesPerFuel", 10f, "Real-time minutes one fuel item keeps the pillar burning.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1440f));
			MaxFuel = Rule("Rules", "MaxFuel", 100, "How many fuel items the pillar holds.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000));
			InfiniteFuel = Rule("Rules", "InfiniteFuel", value: false, "The pillar burns without fuel for as long as it stands.");
			KeepWhenEmpty = Rule("Rules", "KeepWhenEmpty", value: false, "Also keep the land alive while nobody is on the server. The game stops world time then: nothing grows, no young are born, crops, kilns and fuel wait, only animals move and taming goes on (without burning coal). If false, pillars rest until someone joins, as the rest of the world does.");
			Recipe = Rule("Rules", "Recipe", "Stone:25,Wood:10,SurtlingCore:1,GreydwarfEye:5", "Workbench recipe as Item:amount pairs separated by commas (prefab names).");
			MinutesPerFuel.SettingChanged += delegate
			{
				PillarPiece.ApplyFuelRulesEverywhere();
			};
			MaxFuel.SettingChanged += delegate
			{
				PillarPiece.ApplyFuelRulesEverywhere();
			};
			InfiniteFuel.SettingChanged += delegate
			{
				PillarPiece.ApplyFuelRulesEverywhere();
			};
			FuelItem.SettingChanged += delegate
			{
				PillarPiece.ApplyFuelRulesEverywhere();
			};
			Recipe.SettingChanged += delegate
			{
				PillarPiece.ApplyRecipe();
			};
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				PillarPiece.ApplyFuelRulesEverywhere();
				PillarPiece.ApplyRecipe();
			};
			AddLocalization();
			PrefabManager.OnVanillaPrefabsAvailable += PillarPiece.Register;
			if (ZoneKeeper.Init())
			{
				new Harmony("qua8ion.valheim.watchpillar").PatchAll(Assembly.GetExecutingAssembly());
			}
		}

		private void Update()
		{
			ZoneKeeper.Update();
		}

		private ConfigEntry<T> Rule<T>(string section, string key, T value, string description, AcceptableValueBase range = null)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, range, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private static void AddLocalization()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "piece_q8wp_pillar", "Watch pillar" },
				{ "piece_q8wp_pillar_desc", "While coal burns inside, the land around it lives on with nobody near: animals grow, breed and get tamed, kilns and workshops keep working. Look at it to see the border of the land it holds." },
				{ "q8wp_hover_area", "Keeps the land around alive" },
				{ "q8wp_hover_left", "Lasts" },
				{ "q8wp_hover_idle", "Not burning: with nobody near, the land around sleeps" },
				{ "q8wp_zones", "zones" },
				{ "q8wp_m", "m" },
				{ "q8wp_h", "h" },
				{ "q8wp_min", "min" }
			});
			text = "Russian";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "piece_q8wp_pillar", "Колонна наблюдения" },
				{ "piece_q8wp_pillar_desc", "Пока в колонне горит уголь, земля вокруг живёт и без людей: звери растут, плодятся и приручаются, печи и мастерские работают. Наведи на неё взгляд — покажет границу земли, которую держит." },
				{ "q8wp_hover_area", "Держит землю вокруг живой" },
				{ "q8wp_hover_left", "Хватит на" },
				{ "q8wp_hover_idle", "Не горит: без людей земля вокруг спит" },
				{ "q8wp_zones", "зоны" },
				{ "q8wp_m", "м" },
				{ "q8wp_h", "ч" },
				{ "q8wp_min", "мин" }
			});
		}
	}
	public static class ZoneKeeper
	{
		public const int MaxRadius = 2;

		private const float ScanInterval = 10f;

		private const float ClaimInterval = 2f;

		private const float PokeInterval = 0.1f;

		private static readonly HashSet<Vector2s> forced = new HashSet<Vector2s>();

		private static readonly List<Vector2s> forcedList = new List<Vector2s>();

		private static readonly HashSet<Vector2s> nextForced = new HashSet<Vector2s>();

		private static readonly List<ZDO> scanList = new List<ZDO>();

		private static readonly List<ZDO> tempObjects = new List<ZDO>();

		private static readonly HashSet<SectorIndex> tempVisited = new HashSet<SectorIndex>();

		private static readonly SimulationDistance singleZone = new SimulationDistance(0, 0, false);

		private static Func<ZoneSystem, Vector2s, bool> pokeLocalZone;

		private static Action<ZDOMan, Vector2s, List<ZDO>, HashSet<SectorIndex>> findObjects;

		private static FieldRef<ZDOMan, List<ZDO>> tempNearObjects;

		private static FieldInfo zonesField;

		private static ZoneSystem zonesOwner;

		private static IDictionary zones;

		private static ZDOMan owner;

		private static bool scanning;

		private static int scanIndex;

		private static float nextScan;

		private static float nextClaim;

		private static float pokeTimer;

		private static int pokeCursor;

		private static int burning;

		private static bool wasResting;

		internal static bool InPass;

		internal static bool AddedInPass;

		public static int BurningPillars => burning;

		public static int ForcedZoneCount => forced.Count;

		public static bool IsForced(Vector2s zone)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return forced.Contains(zone);
		}

		internal static bool Init()
		{
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(ZoneSystem), "PokeLocalZone", new Type[1] { typeof(Vector2s) }, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(ZDOMan), "FindObjects", new Type[3]
				{
					typeof(Vector2s),
					typeof(List<ZDO>),
					typeof(HashSet<SectorIndex>)
				}, (Type[])null);
				zonesField = AccessTools.Field(typeof(ZoneSystem), "m_zones");
				if (methodInfo == null || methodInfo2 == null || AccessTools.Field(typeof(ZDOMan), "m_tempNearObjects") == null || zonesField == null || !typeof(IDictionary).IsAssignableFrom(zonesField.FieldType))
				{
					WatchPillarPlugin.Log.LogError((object)"The game has changed (PokeLocalZone, FindObjects, m_tempNearObjects or m_zones not found): pillars will burn but will not keep the land alive. The mod needs an update.");
					return false;
				}
				pokeLocalZone = AccessTools.MethodDelegate<Func<ZoneSystem, Vector2s, bool>>(methodInfo, (object)null, true);
				findObjects = AccessTools.MethodDelegate<Action<ZDOMan, Vector2s, List<ZDO>, HashSet<SectorIndex>>>(methodInfo2, (object)null, true);
				tempNearObjects = AccessTools.FieldRefAccess<ZDOMan, List<ZDO>>("m_tempNearObjects");
				return true;
			}
			catch (Exception ex)
			{
				WatchPillarPlugin.Log.LogError((object)("Could not hook into the game: " + ex));
				return false;
			}
		}

		internal static void Update()
		{
			ZDOMan instance = ZDOMan.instance;
			if (findObjects == null || instance == null || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				Reset(null);
				return;
			}
			if (instance != owner)
			{
				Reset(instance);
			}
			bool flag = !WatchPillarPlugin.KeepWhenEmpty.Value && ZNet.instance.GetNrOfPlayers() == 0;
			if (flag != wasResting)
			{
				wasResting = flag;
				if (flag && forced.Count > 0)
				{
					WatchPillarPlugin.Log.LogInfo((object)"Nobody on the server, world time stands still: pillars rest until someone joins");
				}
			}
			if (flag)
			{
				Reset(instance);
				return;
			}
			Scan(instance);
			if (forcedList.Count > 0 && Time.time >= nextClaim)
			{
				nextClaim = Time.time + 2f;
				Claim(instance);
			}
		}

		private static void Reset(ZDOMan zdoMan)
		{
			if (owner != zdoMan || forced.Count != 0 || scanning)
			{
				owner = zdoMan;
				forced.Clear();
				forcedList.Clear();
				scanList.Clear();
				scanning = false;
				scanIndex = 0;
				nextScan = 0f;
				burning = 0;
				InPass = false;
			}
		}

		private static void Scan(ZDOMan zdoMan)
		{
			if (!scanning)
			{
				if (Time.time < nextScan)
				{
					return;
				}
				scanning = true;
				scanIndex = 0;
				scanList.Clear();
			}
			if (zdoMan.GetAllZDOsWithPrefabIterative("Q8_WatchPillar", scanList, ref scanIndex))
			{
				scanning = false;
				nextScan = Time.time + 10f;
				Rebuild();
			}
		}

		private static void Rebuild()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(WatchPillarPlugin.Radius.Value, 0, 2);
			bool value = WatchPillarPlugin.InfiniteFuel.Value;
			nextForced.Clear();
			int num2 = 0;
			foreach (ZDO scan in scanList)
			{
				if (scan == null || !scan.IsValid() || !IsBurning(scan, value))
				{
					continue;
				}
				num2++;
				Vector2s zone = ZoneSystem.GetZone(scan.GetPosition());
				for (int i = -num; i <= num; i++)
				{
					for (int j = -num; j <= num; j++)
					{
						nextForced.Add(new Vector2s(zone.x + j, zone.y + i));
					}
				}
			}
			scanList.Clear();
			if (num2 != burning || !nextForced.SetEquals(forced))
			{
				WatchPillarPlugin.Log.LogInfo((object)$"Pillars burning: {num2}, zones kept alive: {nextForced.Count}");
			}
			burning = num2;
			if (!nextForced.SetEquals(forced))
			{
				forced.Clear();
				forced.UnionWith(nextForced);
				forcedList.Clear();
				forcedList.AddRange(forced);
				pokeCursor = 0;
			}
		}

		public static bool IsBurning(ZDO zdo, bool infinite)
		{
			if (zdo.GetInt(ZDOVars.s_state, 1) == 1)
			{
				if (!infinite)
				{
					return zdo.GetFloat(ZDOVars.s_fuel, 0f) > 0f;
				}
				return true;
			}
			return false;
		}

		internal static bool ZoneLoaded(Vector2s zone)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)instance != (Object)(object)zonesOwner)
			{
				zonesOwner = instance;
				zones = (IDictionary)zonesField.GetValue(instance);
			}
			if (zones != null)
			{
				return zones.Contains(zone);
			}
			return false;
		}

		private static void Claim(ZDOMan zdoMan)
		{
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			long sessionID = ZDOMan.GetSessionID();
			foreach (Vector2s forced in forcedList)
			{
				if (!ZoneLoaded(forced))
				{
					continue;
				}
				tempObjects.Clear();
				zdoMan.FindSectorObjects(forced, singleZone, tempObjects, (List<ZDO>)null);
				foreach (ZDO tempObject in tempObjects)
				{
					if (tempObject.Persistent)
					{
						long num = tempObject.GetOwner();
						if (num != sessionID && (num == 0L || !OwnerIsNear(tempObject, num)))
						{
							tempObject.SetOwner(sessionID);
						}
					}
				}
			}
			tempObjects.Clear();
		}

		private static bool OwnerIsNear(ZDO zdo, long zdoOwner)
		{
			//IL_0010: 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)
			ZNetPeer peer = ZNet.instance.GetPeer(zdoOwner);
			if (peer != null)
			{
				return ZNetScene.InActiveArea(zdo.GetPosition(), peer.GetRefPos());
			}
			return false;
		}

		internal static void ReclaimReleased(ZDOMan zdoMan)
		{
			//IL_005e: 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)
			if (forced.Count == 0 || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			long sessionID = ZDOMan.GetSessionID();
			foreach (ZDO item in tempNearObjects.Invoke(zdoMan))
			{
				if (item.Persistent && !item.HasOwner() && forced.Contains(item.GetSector()) && ZoneLoaded(item.GetSector()))
				{
					item.SetOwner(sessionID);
				}
			}
		}

		internal static void BeginPass()
		{
			InPass = forcedList.Count > 0 && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer();
			AddedInPass = false;
		}

		internal static void EndPass()
		{
			InPass = false;
		}

		internal static void AddForced(ZDOMan zdoMan, List<ZDO> objects, HashSet<SectorIndex> visited)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			foreach (Vector2s forced in forcedList)
			{
				if (ZoneLoaded(forced))
				{
					findObjects(zdoMan, forced, objects, visited);
				}
			}
			AddedInPass = true;
		}

		internal static void AddForcedFallback(List<ZDO> nearObjects)
		{
			//IL_0084: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			AddedInPass = true;
			ZDOMan instance = ZDOMan.instance;
			if (instance == null)
			{
				return;
			}
			tempVisited.Clear();
			if (nearObjects.Count == 0)
			{
				foreach (Vector2s forced in forcedList)
				{
					if (ZoneLoaded(forced))
					{
						findObjects(instance, forced, nearObjects, tempVisited);
					}
				}
				return;
			}
			tempObjects.Clear();
			foreach (Vector2s forced2 in forcedList)
			{
				if (ZoneLoaded(forced2))
				{
					findObjects(instance, forced2, tempObjects, tempVisited);
				}
			}
			HashSet<ZDO> hashSet = new HashSet<ZDO>(nearObjects);
			foreach (ZDO tempObject in tempObjects)
			{
				if (hashSet.Add(tempObject))
				{
					nearObjects.Add(tempObject);
				}
			}
			tempObjects.Clear();
		}

		internal static void PokeZones(ZoneSystem zoneSystem)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (forcedList.Count == 0 || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || (int)ZNet.GetConnectionStatus() != 2 || !zoneSystem.LocationsGenerated)
			{
				return;
			}
			pokeTimer += Time.deltaTime;
			if (pokeTimer < 0.1f)
			{
				return;
			}
			pokeTimer = 0f;
			int count = forcedList.Count;
			for (int i = 0; i < count; i++)
			{
				int num = (pokeCursor + i) % count;
				if (pokeLocalZone(zoneSystem, forcedList[num]))
				{
					pokeCursor = (num + 1) % count;
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "CreateDestroyObjects")]
	internal static class CreateDestroyObjectsPatch
	{
		[HarmonyPriority(800)]
		private static void Prefix()
		{
			ZoneKeeper.BeginPass();
		}

		private static Exception Finalizer(Exception __exception)
		{
			ZoneKeeper.EndPass();
			return __exception;
		}
	}
	[HarmonyPatch(typeof(ZDOMan), "FindSectorObjects")]
	internal static class FindSectorObjectsPatch
	{
		private static void Postfix(ZDOMan __instance, List<ZDO> sectorObjects, HashSet<SectorIndex> ___m_visitedSectorIndices)
		{
			if (ZoneKeeper.InPass)
			{
				ZoneKeeper.AddForced(__instance, sectorObjects, ___m_visitedSectorIndices);
			}
		}
	}
	[HarmonyPatch(typeof(ZDOMan), "FindDistantObjects")]
	internal static class FindDistantObjectsPatch
	{
		private static bool Prefix(Vector2s sector)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (ZoneKeeper.InPass)
			{
				return !ZoneKeeper.IsForced(sector);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "CreateObjects")]
	internal static class CreateObjectsPatch
	{
		private static void Prefix(List<ZDO> currentNearObjects)
		{
			if (ZoneKeeper.InPass && !ZoneKeeper.AddedInPass)
			{
				ZoneKeeper.AddForcedFallback(currentNearObjects);
			}
		}
	}
	[HarmonyPatch(typeof(ZDOMan), "ReleaseNearbyZDOS")]
	internal static class ReleaseNearbyZDOSPatch
	{
		private static void Postfix(ZDOMan __instance)
		{
			ZoneKeeper.ReclaimReleased(__instance);
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "Update")]
	internal static class ZoneSystemUpdatePatch
	{
		private static void Postfix(ZoneSystem __instance)
		{
			ZoneKeeper.PokeZones(__instance);
		}
	}
}