Decompiled source of NoMapWayfinding v1.1.1

plugins/NoMapWayfinding.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NoMapWayfinding.Patches;
using NoMapWayfinding.Sync;
using UnityEngine;

[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("NoMapWayfinding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Hides the Valheim minimap; the world map is readable only at a cartography table, which auto-syncs exploration between players.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+0714c97815f944cc757501ca776e87d09a1582aa")]
[assembly: AssemblyProduct("NoMap Wayfinding")]
[assembly: AssemblyTitle("NoMapWayfinding")]
[assembly: AssemblyVersion("1.1.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 NoMapWayfinding
{
	internal class CompassHud : MonoBehaviour
	{
		private sealed class CachedColor
		{
			private readonly Color _fallback;

			private string _text;

			private Color _value;

			private bool _warned;

			public CachedColor(Color fallback)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				_fallback = fallback;
				_value = fallback;
			}

			public Color Get(string text)
			{
				//IL_000f: 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_0042: 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_0028: 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_0071: Unknown result type (might be due to invalid IL or missing references)
				if (text == _text)
				{
					return _value;
				}
				_text = text;
				Color value = default(Color);
				if (ColorUtility.TryParseHtmlString(text, ref value))
				{
					_value = value;
					_warned = false;
					return _value;
				}
				_value = _fallback;
				if (!_warned)
				{
					_warned = true;
					WayfindingPlugin.Log.LogWarning((object)("Could not read the compass colour \"" + text + "\". Expected something like #FFF7E0 or a colour name such as cyan. Using the default for now."));
				}
				return _value;
			}
		}

		private const float BaseHeight = 30f;

		private const int MinorStepDegrees = 15;

		private static readonly string[] Headings = new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" };

		private Texture2D _pixel;

		private readonly CachedColor _color = new CachedColor(new Color(1f, 0.97f, 0.88f));

		private readonly CachedColor _markerColor = new CachedColor(new Color(1f, 0.94f, 0.78f));

		private Texture _shoutTexture;

		private Rect _shoutCoords;

		private bool _shoutChecked;

		private ShoutMarkers.Marker _namedMarker;

		private string _biomeName = "";

		private float _biomeChangedAt = -99f;

		private GUIStyle _labelStyle;

		private Font _font;

		private bool _fontSearched;

		private void OnGUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			if ((int)Event.current.type == 7 && ShouldDraw())
			{
				EnsureResources();
				Draw(CurrentHeading());
				if (Settings.CompassShowBiome)
				{
					DrawBiome();
				}
				DrawShoutName();
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_pixel != (Object)null)
			{
				Object.Destroy((Object)(object)_pixel);
				_pixel = null;
			}
		}

		private static Color WithAlpha(Color color, float alpha)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new Color(color.r, color.g, color.b, alpha);
		}

		private static bool ShouldDraw()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (!Settings.Enabled || !Settings.CompassEnabled)
			{
				return false;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				return false;
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || (int)instance.m_mode == 2)
			{
				return false;
			}
			Hud instance2 = Hud.instance;
			if ((Object)(object)instance2 == (Object)null || instance2.m_userHidden || !instance2.IsVisible())
			{
				return false;
			}
			return (Object)(object)GameCamera.instance != (Object)null;
		}

		private static float CurrentHeading()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			GameCamera instance = GameCamera.instance;
			if ((Object)(object)instance != (Object)null)
			{
				return ((Component)instance).transform.eulerAngles.y;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer != (Object)null))
			{
				return 0f;
			}
			return ((Component)localPlayer).transform.eulerAngles.y;
		}

		private void EnsureResources()
		{
			//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_0025: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			if ((Object)(object)_pixel == (Object)null)
			{
				_pixel = new Texture2D(1, 1, (TextureFormat)5, false)
				{
					hideFlags = (HideFlags)61
				};
				_pixel.SetPixel(0, 0, Color.white);
				_pixel.Apply();
			}
			if (!_fontSearched)
			{
				_fontSearched = true;
				_font = FindGameFont();
			}
			if (_labelStyle == null)
			{
				_labelStyle = new GUIStyle
				{
					alignment = (TextAnchor)4,
					richText = false
				};
				if ((Object)(object)_font != (Object)null)
				{
					_labelStyle.font = _font;
				}
			}
		}

		private static Font FindGameFont()
		{
			Font result = null;
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (!((Object)(object)val == (Object)null) && !string.IsNullOrEmpty(((Object)val).name))
				{
					string text = ((Object)val).name.ToLowerInvariant();
					if (text.Contains("norsebold"))
					{
						return val;
					}
					if (text.Contains("norse") || text.Contains("averia"))
					{
						result = val;
					}
				}
			}
			return result;
		}

		private void Draw(float heading)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			float compassScale = Settings.CompassScale;
			float num = Settings.CompassWidth * compassScale;
			float num2 = 30f * compassScale;
			float num3 = num * 0.5f;
			float num4 = Settings.CompassPixelsPerDegree * compassScale;
			float compassOpacity = Settings.CompassOpacity;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(Mathf.Round(((float)Screen.width - num) * 0.5f), Mathf.Round(Settings.CompassTopOffset * compassScale), num, num2);
			Color color = GUI.color;
			_labelStyle.fontSize = Mathf.Max(9, Mathf.RoundToInt(15f * compassScale));
			GUI.BeginGroup(val);
			for (int i = 0; i < 360; i += 15)
			{
				float num5 = Mathf.DeltaAngle(heading, (float)i) * num4;
				float num6 = num3 + num5;
				if (num6 < -30f * compassScale || num6 > num + 30f * compassScale)
				{
					continue;
				}
				float num7 = Mathf.Abs(num5) / num3;
				float num8 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((1f - num7) * 2.2f));
				if (!(num8 <= 0.01f))
				{
					bool num9 = i % 45 == 0;
					float num10 = compassOpacity * num8;
					if (num9)
					{
						DrawLabel(Headings[i / 45], num6, num2, compassScale, num10);
					}
					else
					{
						DrawTick(num6, num2, compassScale, num10 * 0.55f);
					}
				}
			}
			GUI.EndGroup();
			GUI.color = WithAlpha(_markerColor.Get(Settings.CompassMarkerColor), compassOpacity);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x + num3 - 1f, ((Rect)(ref val)).y + ((Rect)(ref val)).height - 7f * compassScale, 2f, 7f * compassScale), (Texture)(object)_pixel);
			GUI.color = color;
			DrawShoutMarkers(heading, val, compassScale, num4);
		}

		private void DrawShoutMarkers(float heading, Rect strip, float scale, float pixelsPerDegree)
		{
			//IL_002c: 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_0079: 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_0083: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			_namedMarker = null;
			List<ShoutMarkers.Marker> list = ShoutMarkers.Active();
			if (list.Count == 0)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)localPlayer).transform.position;
			float num = ((Rect)(ref strip)).width * 0.5f;
			float num2 = 18f * scale;
			float num3 = Mathf.Max(0f, ((Rect)(ref strip)).y - num2 - 2f * scale);
			Rect val = new Rect(((Rect)(ref strip)).x, num3, ((Rect)(ref strip)).width, num2);
			Color color = GUI.color;
			ShoutMarkers.Marker marker = null;
			float num4 = float.MaxValue;
			GUI.BeginGroup(val);
			foreach (ShoutMarkers.Marker item in list)
			{
				Vector3 val2 = item.Position - position;
				float num5 = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
				float num6 = Mathf.DeltaAngle(heading, num5) * pixelsPerDegree;
				float num7 = num + num6;
				if (num7 < 0f - num2 || num7 > ((Rect)(ref strip)).width + num2)
				{
					continue;
				}
				float num8 = Settings.CompassOpacity * ShoutMarkers.Opacity(item);
				if (!(num8 <= 0.01f))
				{
					DrawShoutIcon(new Rect(num7 - num2 * 0.5f, 0f, num2, num2), num8);
					if (Mathf.Abs(num6) < num4)
					{
						marker = item;
						num4 = Mathf.Abs(num6);
					}
				}
			}
			GUI.EndGroup();
			if (marker != null && !string.IsNullOrEmpty(marker.Name) && num4 < ((Rect)(ref strip)).width * 0.25f)
			{
				_namedMarker = marker;
			}
			GUI.color = color;
		}

		private void DrawShoutName()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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)
			if (_namedMarker != null)
			{
				float compassScale = Settings.CompassScale;
				float num = Settings.CompassTopOffset * compassScale + 30f * compassScale + 2f * compassScale;
				if (Settings.CompassShowBiome)
				{
					num += 20f * compassScale;
				}
				float num2 = Settings.CompassOpacity * ShoutMarkers.Opacity(_namedMarker);
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, Mathf.Round(num), (float)Screen.width, 18f * compassScale);
				Color color = GUI.color;
				_labelStyle.fontSize = Mathf.Max(8, Mathf.RoundToInt(12f * compassScale));
				_labelStyle.normal.textColor = Color.white;
				GUI.color = new Color(0f, 0f, 0f, num2 * 0.7f);
				GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _namedMarker.Name, _labelStyle);
				GUI.color = WithAlpha(_color.Get(Settings.CompassColor), num2);
				GUI.Label(val, _namedMarker.Name, _labelStyle);
				GUI.color = color;
			}
		}

		private void DrawShoutIcon(Rect rect, float alpha)
		{
			//IL_004c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			EnsureShoutSprite();
			if ((Object)(object)_shoutTexture != (Object)null)
			{
				GUI.color = new Color(1f, 1f, 1f, alpha);
				GUI.DrawTextureWithTexCoords(rect, _shoutTexture, _shoutCoords);
				return;
			}
			GUI.color = WithAlpha(_markerColor.Get(Settings.CompassMarkerColor), alpha);
			float num = ((Rect)(ref rect)).width * 0.5f;
			for (int i = 0; i < Mathf.RoundToInt(((Rect)(ref rect)).height); i++)
			{
				float num2 = Mathf.Abs((float)i - num) / num;
				float num3 = Mathf.Max(1f, ((Rect)(ref rect)).width * (1f - num2));
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + num - num3 * 0.5f, ((Rect)(ref rect)).y + (float)i, num3, 1f), (Texture)(object)_pixel);
			}
		}

		private void EnsureShoutSprite()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (_shoutChecked)
			{
				return;
			}
			_shoutChecked = true;
			try
			{
				Minimap instance = Minimap.instance;
				MethodInfo methodInfo = AccessTools.Method(typeof(Minimap), "GetSprite", new Type[1] { typeof(PinType) }, (Type[])null);
				if (!((Object)(object)instance == (Object)null) && !(methodInfo == null))
				{
					object? obj = methodInfo.Invoke(instance, new object[1] { (object)(PinType)7 });
					Sprite val = (Sprite)((obj is Sprite) ? obj : null);
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val.texture == (Object)null))
					{
						Rect textureRect = val.textureRect;
						_shoutTexture = (Texture)(object)val.texture;
						_shoutCoords = new Rect(((Rect)(ref textureRect)).x / (float)((Texture)val.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)val.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)val.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)val.texture).height);
					}
				}
			}
			catch (Exception ex)
			{
				WayfindingPlugin.Log.LogWarning((object)("Could not borrow the shout icon: " + ex.Message));
			}
		}

		private void DrawTick(float x, float height, float scale, float alpha)
		{
			//IL_000b: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			GUI.color = WithAlpha(_color.Get(Settings.CompassColor), alpha);
			GUI.DrawTexture(new Rect(x - 0.5f, height - 5f * scale, 1f, 5f * scale), (Texture)(object)_pixel);
		}

		private void DrawBiome()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			string name = localPlayer.GetCurrentBiomeData().GetName(false);
			if (!string.IsNullOrEmpty(name))
			{
				if (name != _biomeName)
				{
					_biomeName = name;
					_biomeChangedAt = Time.realtimeSinceStartup;
				}
				float compassScale = Settings.CompassScale;
				float num = Time.realtimeSinceStartup - _biomeChangedAt;
				float num2 = 1f + 0.35f * Mathf.Exp(-6f * num);
				_labelStyle.fontSize = Mathf.Max(9, Mathf.RoundToInt(14f * compassScale * num2));
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, Mathf.Round(Settings.CompassTopOffset * compassScale + 30f * compassScale + 2f * compassScale), (float)Screen.width, 20f * compassScale);
				Color color = GUI.color;
				float compassOpacity = Settings.CompassOpacity;
				GUI.color = new Color(0f, 0f, 0f, compassOpacity * 0.7f);
				_labelStyle.normal.textColor = Color.white;
				GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _biomeName, _labelStyle);
				GUI.color = WithAlpha(_color.Get(Settings.CompassColor), compassOpacity);
				GUI.Label(val, _biomeName, _labelStyle);
				GUI.color = color;
			}
		}

		private void DrawLabel(string text, float x, float height, float scale, float alpha)
		{
			//IL_0040: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			float num = 24f * scale;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(x - num, 0f, num * 2f, height - 6f * scale);
			GUI.color = new Color(0f, 0f, 0f, alpha * 0.7f);
			_labelStyle.normal.textColor = Color.white;
			GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text, _labelStyle);
			GUI.color = WithAlpha(_color.Get(Settings.CompassColor), alpha);
			GUI.Label(val, text, _labelStyle);
		}
	}
	internal class CompassSettingsPanel : MonoBehaviour
	{
		private const int WindowId = 5131607;

		private static Rect _window = new Rect(80f, 80f, 300f, 0f);

		private Texture2D _swatch;

		private GUIStyle _headerStyle;

		private bool _savedSaveOnSet;

		public static bool IsOpen { get; private set; }

		private void Update()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				Close();
			}
			else if (Input.GetKeyDown(Settings.SettingsKey) && !TypingSomewhere())
			{
				if (IsOpen)
				{
					Close();
				}
				else
				{
					Open();
				}
			}
		}

		private static bool TypingSomewhere()
		{
			if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible())
			{
				return Minimap.InTextInput();
			}
			return true;
		}

		private void Open()
		{
			IsOpen = true;
			ConfigFile file = PluginConfig.File;
			if (file != null)
			{
				_savedSaveOnSet = file.SaveOnConfigSet;
				file.SaveOnConfigSet = false;
			}
		}

		private void Close()
		{
			if (IsOpen)
			{
				IsOpen = false;
				ConfigFile file = PluginConfig.File;
				if (file != null)
				{
					file.SaveOnConfigSet = _savedSaveOnSet;
					file.Save();
				}
			}
		}

		private void OnDestroy()
		{
			Close();
			if ((Object)(object)_swatch != (Object)null)
			{
				Object.Destroy((Object)(object)_swatch);
				_swatch = null;
			}
		}

		private void OnGUI()
		{
			//IL_0013: 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_0033: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen)
			{
				EnsureResources();
				_window = GUILayout.Window(5131607, _window, new WindowFunction(DrawWindow), "NoMap Wayfinding", Array.Empty<GUILayoutOption>());
			}
		}

		private void EnsureResources()
		{
			//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_0025: Expected O, but got Unknown
			//IL_002d: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			if ((Object)(object)_swatch == (Object)null)
			{
				_swatch = new Texture2D(1, 1, (TextureFormat)5, false)
				{
					hideFlags = (HideFlags)61
				};
				_swatch.SetPixel(0, 0, Color.white);
				_swatch.Apply();
			}
			if (_headerStyle == null)
			{
				_headerStyle = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1
				};
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0024: 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)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Space(4f);
			Color color = ColorRow("Compass", CurrentColor(Settings.CompassColor, new Color(1f, 0.97f, 0.88f)));
			Write(PluginConfig.CompassColor, color);
			GUILayout.Space(6f);
			Color color2 = ColorRow("Marker", CurrentColor(Settings.CompassMarkerColor, new Color(1f, 0.94f, 0.78f)));
			Write(PluginConfig.CompassMarkerColor, color2);
			GUILayout.Space(6f);
			GUILayout.Label("Opacity", _headerStyle, Array.Empty<GUILayoutOption>());
			float num = Slider(PluginConfig.CompassOpacity.Value, 0.1f, 1f);
			if (!Mathf.Approximately(num, PluginConfig.CompassOpacity.Value))
			{
				PluginConfig.CompassOpacity.Value = num;
			}
			GUILayout.Space(10f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Reset", Array.Empty<GUILayoutOption>()))
			{
				PluginConfig.CompassColor.Value = (string)((ConfigEntryBase)PluginConfig.CompassColor).DefaultValue;
				PluginConfig.CompassMarkerColor.Value = (string)((ConfigEntryBase)PluginConfig.CompassMarkerColor).DefaultValue;
				PluginConfig.CompassOpacity.Value = (float)((ConfigEntryBase)PluginConfig.CompassOpacity).DefaultValue;
			}
			if (GUILayout.Button("Close", Array.Empty<GUILayoutOption>()))
			{
				Close();
			}
			GUILayout.EndHorizontal();
			GUILayout.Label(((object)Settings.SettingsKey/*cast due to .constrained prefix*/).ToString() + " to reopen. Everything else is in the config file.", GUI.skin.label, Array.Empty<GUILayoutOption>());
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
		}

		private Color ColorRow(string label, Color value)
		{
			//IL_0006: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Invalid comparison between Unknown and I4
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0073: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label(label + "   " + Hex(value), _headerStyle, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			Rect rect = GUILayoutUtility.GetRect(44f, 44f, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(44f),
				GUILayout.ExpandWidth(false)
			});
			if ((int)Event.current.type == 7)
			{
				Color color = GUI.color;
				GUI.color = Color.black;
				GUI.DrawTexture(rect, (Texture)(object)_swatch);
				GUI.color = value;
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), (Texture)(object)_swatch);
				GUI.color = color;
			}
			GUILayout.Space(6f);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			float num = Channel("R", value.r);
			float num2 = Channel("G", value.g);
			float num3 = Channel("B", value.b);
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			return new Color(num, num2, num3, 1f);
		}

		private float Channel(string name, float value)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(12f) });
			float num = Slider(value, 0f, 1f);
			GUILayout.Label(Mathf.RoundToInt(num * 255f).ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) });
			GUILayout.EndHorizontal();
			return num;
		}

		private static float Slider(float value, float min, float max)
		{
			return GUILayout.HorizontalSlider(value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(120f) });
		}

		private static Color CurrentColor(string text, Color fallback)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (!ColorUtility.TryParseHtmlString(text, ref result))
			{
				return fallback;
			}
			return result;
		}

		private static string Hex(Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return "#" + ColorUtility.ToHtmlStringRGB(color);
		}

		private static void Write(ConfigEntry<string> entry, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string text = Hex(color);
			if (entry.Value != text)
			{
				entry.Value = text;
			}
		}
	}
	internal static class MapAccess
	{
		private static Vector3 _tablePosition;

		public static bool Granted { get; private set; }

		public static void Open(MapTable table)
		{
			//IL_001f: 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)
			Minimap instance = Minimap.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)table == (Object)null))
			{
				_tablePosition = ((Component)table).transform.position;
				Granted = true;
				instance.SetMapMode((MapMode)2);
			}
		}

		public static void Close()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			if (Granted)
			{
				Granted = false;
				Minimap instance = Minimap.instance;
				if ((Object)(object)instance != (Object)null && (int)instance.m_mode == 2)
				{
					instance.SetMapMode((MapMode)1);
				}
			}
		}

		public static void Tick()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//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)
			if (!Granted)
			{
				return;
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null)
			{
				Granted = false;
				return;
			}
			if ((int)instance.m_mode != 2)
			{
				Granted = false;
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				Close();
				return;
			}
			float num = Mathf.Max(1f, Settings.TableRange);
			if (Vector3.Distance(((Component)localPlayer).transform.position, _tablePosition) > num)
			{
				Close();
			}
		}
	}
	internal static class PatchTargets
	{
		public static bool Verify()
		{
			List<string> list = new List<string>();
			Require(list, "Minimap.SetMapMode", AccessTools.Method(typeof(Minimap), "SetMapMode", new Type[1] { typeof(MapMode) }, (Type[])null));
			Require(list, "Minimap.Update", AccessTools.Method(typeof(Minimap), "Update", (Type[])null, (Type[])null));
			Require(list, "Minimap.m_smallRoot", AccessTools.Field(typeof(Minimap), "m_smallRoot"));
			Require(list, "Minimap.m_mode", AccessTools.Field(typeof(Minimap), "m_mode"));
			Type[] array = new Type[3]
			{
				typeof(Switch),
				typeof(Humanoid),
				typeof(ItemData)
			};
			Require(list, "MapTable.OnRead", AccessTools.Method(typeof(MapTable), "OnRead", array, (Type[])null));
			Require(list, "MapTable.OnWrite", AccessTools.Method(typeof(MapTable), "OnWrite", array, (Type[])null));
			Require(list, "Player.TakeInput", AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null));
			Require(list, "GameCamera.UpdateMouseCapture", AccessTools.Method(typeof(GameCamera), "UpdateMouseCapture", (Type[])null, (Type[])null));
			Require(list, "Piece.SetCreator", AccessTools.Method(typeof(Piece), "SetCreator", (Type[])null, (Type[])null));
			Require(list, "Piece.DropResources", AccessTools.Method(typeof(Piece), "DropResources", (Type[])null, (Type[])null));
			Require(list, "Chat.OnNewChatMessage", AccessTools.Method(typeof(Chat), "OnNewChatMessage", (Type[])null, (Type[])null));
			if (list.Count == 0)
			{
				return true;
			}
			WayfindingPlugin.Log.LogError((object)("NoMap Wayfinding could not find these members in this version of Valheim: " + string.Join(", ", list.ToArray()) + ". The game has probably been updated; the mod needs a rebuild against the new assemblies."));
			return false;
		}

		private static void Require(List<string> missing, string name, MemberInfo member)
		{
			if (member == null)
			{
				missing.Add(name);
			}
		}
	}
	internal static class PluginConfig
	{
		public static ConfigFile File;

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> EnforceOnClients;

		public static ConfigEntry<bool> RequireModdedClients;

		public static ConfigEntry<float> ClientGraceSeconds;

		public static ConfigEntry<bool> HideMinimap;

		public static ConfigEntry<bool> RequireTableForMap;

		public static ConfigEntry<bool> AutoSyncAtTable;

		public static ConfigEntry<float> TableRange;

		public static ConfigEntry<float> TableSettlingSeconds;

		public static ConfigEntry<bool> TableNoRefund;

		public static ConfigEntry<bool> CompassEnabled;

		public static ConfigEntry<float> CompassWidth;

		public static ConfigEntry<float> CompassTopOffset;

		public static ConfigEntry<float> CompassPixelsPerDegree;

		public static ConfigEntry<float> CompassOpacity;

		public static ConfigEntry<float> CompassScale;

		public static ConfigEntry<bool> CompassShowBiome;

		public static ConfigEntry<string> CompassColor;

		public static ConfigEntry<string> CompassMarkerColor;

		public static ConfigEntry<float> CompassShoutSeconds;

		public static ConfigEntry<KeyCode> SettingsKey;

		public static void Bind(ConfigFile cfg)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Expected O, but got Unknown
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Expected O, but got Unknown
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Expected O, but got Unknown
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Expected O, but got Unknown
			File = cfg;
			Enabled = cfg.Bind<bool>("General", "Enabled", true, "Master switch. When false the mod does nothing and Valheim behaves normally.");
			EnforceOnClients = cfg.Bind<bool>("Server", "EnforceOnClients", true, "Server side only. When this instance is a server, send its Map and Table settings to connecting clients that have the mod, overriding their local ones for as long as they are connected. Compass appearance is never sent - that stays each player's own choice. This cannot affect players who do not have the mod installed: the minimap is drawn on their machine, not the server's.");
			RequireModdedClients = cfg.Bind<bool>("Server", "RequireModdedClients", false, "Off by default; opt in only if you run a server and want it. Disconnects players who do not have this mod. Be aware that hosting a game from your own client makes you a server, so switching this on there turns away friends who have not installed it. The vanilla NoMap world key is usually the better tool: it costs unmodded clients the map through the game's own code without excluding anyone. Treat this as keeping honest players honest rather than as a guarantee: a mod cannot enforce anything on a machine it does not control.");
			ClientGraceSeconds = cfg.Bind<float>("Server", "ClientGraceSeconds", 20f, new ConfigDescription("Server side only. How long a joining player has to identify themselves as having the mod before being turned away. The clock starts once Valheim's own handshake finishes, so this measures the mod, not the connection.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 120f), Array.Empty<object>()));
			HideMinimap = cfg.Bind<bool>("Map", "HideMinimap", true, "Hide the corner minimap. Exploration still records normally, it is just never drawn.");
			RequireTableForMap = cfg.Bind<bool>("Map", "RequireTableForMap", true, "Block the full-screen map key. The world map can then only be opened by using a cartography table.");
			AutoSyncAtTable = cfg.Bind<bool>("Table", "AutoSyncOnUse", true, "Using a cartography table merges in both directions at once: the table's exploration is added to yours and yours is added to the table. One interaction instead of separate read and write.");
			TableRange = cfg.Bind<float>("Table", "Range", 8f, new ConfigDescription("How far you can walk from the cartography table before the map closes, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 64f), Array.Empty<object>()));
			TableSettlingSeconds = cfg.Bind<float>("Table", "SettlingSeconds", 600f, new ConfigDescription("How long a newly built cartography table must stand before it can be read, in seconds. This stops a table being used as a portable position finder - carry the materials, build one to see where you are, dismantle it and walk on. A table you built and left standing is unaffected. Set to 0 to allow reading immediately. Tables that already existed when this was installed are never affected.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 7200f), Array.Empty<object>()));
			TableNoRefund = cfg.Bind<bool>("Table", "NoRefundOnRemove", false, "Give nothing back when a cartography table is removed, so using one as a disposable position finder costs a full table every time. This also applies when a table is destroyed rather than dismantled, since the game routes both through the same code.");
			CompassEnabled = cfg.Bind<bool>("Compass", "Enabled", true, "Draw a compass strip at the top of the screen in place of the minimap.");
			CompassWidth = cfg.Bind<float>("Compass", "Width", 460f, new ConfigDescription("Width of the compass strip in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(160f, 1600f), Array.Empty<object>()));
			CompassTopOffset = cfg.Bind<float>("Compass", "TopOffset", 16f, new ConfigDescription("Distance from the top of the screen in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 400f), Array.Empty<object>()));
			CompassPixelsPerDegree = cfg.Bind<float>("Compass", "PixelsPerDegree", 3.2f, new ConfigDescription("Horizontal scale. Higher spreads the headings further apart.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 12f), Array.Empty<object>()));
			CompassOpacity = cfg.Bind<float>("Compass", "Opacity", 0.85f, new ConfigDescription("Opacity of the compass at its centre.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			CompassScale = cfg.Bind<float>("Compass", "Scale", 2f, new ConfigDescription("Overall size of the compass. Lower it if the ribbon feels too big.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			CompassShowBiome = cfg.Bind<bool>("Compass", "ShowBiomeName", true, "Show the current biome under the compass. The vanilla biome label sits inside the minimap panel, so hiding the minimap hides it too; this puts that information back.");
			CompassColor = cfg.Bind<string>("Compass", "Color", "#FFF7E0", "Colour of the headings, the tick marks and the biome name. Either a hex value such as #FFF7E0 or #RRGGBB, or a colour name such as cyan. Transparency comes from Opacity below rather than from this value.");
			CompassMarkerColor = cfg.Bind<string>("Compass", "MarkerColor", "#FFF0C7", "Colour of the fixed marker in the centre of the compass, the one that shows the way you are actually facing. Give it something distinct from Color to make it easier to pick out at a glance.");
			SettingsKey = cfg.Bind<KeyCode>("Compass", "SettingsKey", (KeyCode)288, "Opens a small panel for changing the compass colours in game, with the compass recolouring live behind it. Set to None to disable the panel entirely.");
			CompassShoutSeconds = cfg.Bind<float>("Compass", "ShoutMarkerSeconds", 120f, new ConfigDescription("When another player shouts, mark the direction it came from on the compass for this many seconds, using the game's own shout icon. The marker stays where the shout was, so it points at where they called from rather than following them. Set to 0 to turn it off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
		}
	}
	internal static class Settings
	{
		public static bool Enabled
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.Enabled.Value;
				}
				return ServerRules.Current.Enabled;
			}
		}

		public static bool HideMinimap
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.HideMinimap.Value;
				}
				return ServerRules.Current.HideMinimap;
			}
		}

		public static bool RequireTableForMap
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.RequireTableForMap.Value;
				}
				return ServerRules.Current.RequireTableForMap;
			}
		}

		public static bool AutoSyncAtTable
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.AutoSyncAtTable.Value;
				}
				return ServerRules.Current.AutoSyncAtTable;
			}
		}

		public static float TableRange
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.TableRange.Value;
				}
				return ServerRules.Current.TableRange;
			}
		}

		public static float TableSettlingSeconds
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.TableSettlingSeconds.Value;
				}
				return ServerRules.Current.TableSettlingSeconds;
			}
		}

		public static bool TableNoRefund
		{
			get
			{
				if (!ServerRules.Active)
				{
					return PluginConfig.TableNoRefund.Value;
				}
				return ServerRules.Current.TableNoRefund;
			}
		}

		public static bool CompassEnabled => PluginConfig.CompassEnabled.Value;

		public static bool CompassShowBiome => PluginConfig.CompassShowBiome.Value;

		public static string CompassColor => PluginConfig.CompassColor.Value;

		public static string CompassMarkerColor => PluginConfig.CompassMarkerColor.Value;

		public static float CompassShoutSeconds => PluginConfig.CompassShoutSeconds.Value;

		public static KeyCode SettingsKey => PluginConfig.SettingsKey.Value;

		public static float CompassWidth => PluginConfig.CompassWidth.Value;

		public static float CompassTopOffset => PluginConfig.CompassTopOffset.Value;

		public static float CompassPixelsPerDegree => PluginConfig.CompassPixelsPerDegree.Value;

		public static float CompassOpacity => PluginConfig.CompassOpacity.Value;

		public static float CompassScale => PluginConfig.CompassScale.Value;
	}
	internal static class ShoutMarkers
	{
		internal class Marker
		{
			public Vector3 Position;

			public string Name;

			public float ExpiresAt;
		}

		private const int MaxTracked = 8;

		public const float FadeSeconds = 10f;

		private static readonly List<Marker> Markers = new List<Marker>();

		public static void Record(Vector3 position, string name)
		{
			//IL_001a: 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)
			float compassShoutSeconds = Settings.CompassShoutSeconds;
			if (!(compassShoutSeconds <= 0f))
			{
				Markers.Add(new Marker
				{
					Position = position,
					Name = (string.IsNullOrEmpty(name) ? "" : name),
					ExpiresAt = Time.time + compassShoutSeconds
				});
				while (Markers.Count > 8)
				{
					Markers.RemoveAt(0);
				}
			}
		}

		public static List<Marker> Active()
		{
			float time = Time.time;
			for (int num = Markers.Count - 1; num >= 0; num--)
			{
				if (Markers[num].ExpiresAt <= time)
				{
					Markers.RemoveAt(num);
				}
			}
			return Markers;
		}

		public static float Opacity(Marker marker)
		{
			float num = marker.ExpiresAt - Time.time;
			if (num >= 10f)
			{
				return 1f;
			}
			return Mathf.Clamp01(num / 10f);
		}

		public static void Clear()
		{
			Markers.Clear();
		}
	}
	internal static class TableSettling
	{
		private static readonly int PlacedAtKey = StringExtensionMethods.GetStableHashCode("nmw_tablePlacedAt");

		public static void StampPlacement(MapTable table)
		{
			if (!((Object)(object)table == (Object)null))
			{
				ZNetView component = ((Component)table).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner() && !((Object)(object)ZNet.instance == (Object)null))
				{
					component.GetZDO().Set(PlacedAtKey, (long)ZNet.instance.GetTimeSeconds());
				}
			}
		}

		public static bool IsSettled(MapTable table)
		{
			return RemainingSeconds(table) <= 0.0;
		}

		public static double RemainingSeconds(MapTable table)
		{
			float tableSettlingSeconds = Settings.TableSettlingSeconds;
			if (tableSettlingSeconds <= 0f || (Object)(object)table == (Object)null || (Object)(object)ZNet.instance == (Object)null)
			{
				return 0.0;
			}
			ZNetView component = ((Component)table).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return 0.0;
			}
			long num = component.GetZDO().GetLong(PlacedAtKey, 0L);
			if (num == 0L)
			{
				return 0.0;
			}
			double num2 = ZNet.instance.GetTimeSeconds() - (double)num;
			if (num2 < 0.0)
			{
				return 0.0;
			}
			double num3 = (double)tableSettlingSeconds - num2;
			if (!(num3 > 0.0))
			{
				return 0.0;
			}
			return num3;
		}

		public static string DescribeRemaining(double seconds)
		{
			int num = Mathf.CeilToInt((float)seconds);
			if (num < 60)
			{
				return num + "s";
			}
			int num2 = num / 60;
			int num3 = num % 60;
			if (num3 != 0)
			{
				return num2 + "m " + num3 + "s";
			}
			return num2 + "m";
		}
	}
	[BepInPlugin("com.rynwind.nomapwayfinding", "NoMap Wayfinding", "1.1.1")]
	public class WayfindingPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.rynwind.nomapwayfinding";

		public const string Name = "NoMap Wayfinding";

		public const string Version = "1.1.1";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private static bool IsHeadless => (int)SystemInfo.graphicsDeviceType == 4;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			PluginConfig.Bind(OpenConfigFile());
			_harmony = new Harmony("com.rynwind.nomapwayfinding");
			_harmony.PatchAll(typeof(ZRoutedRpcConstructorPatch));
			((Component)this).gameObject.AddComponent<ServerGate>();
			if (IsHeadless)
			{
				Log.LogInfo((object)"NoMap Wayfinding 1.1.1 loaded in server mode.");
				Log.LogInfo((object)(PluginConfig.EnforceOnClients.Value ? "  Rules: modded clients will be given this server's Map and Table settings." : "  Rules: not enforced; clients keep their own settings."));
				Log.LogInfo((object)(PluginConfig.RequireModdedClients.Value ? ("  Access: players WITHOUT the mod will be refused after " + PluginConfig.ClientGraceSeconds.Value + "s. Set Server.RequireModdedClients to false to allow them.") : "  Access: players without the mod are allowed, and will keep their minimap."));
			}
			else if (PatchTargets.Verify())
			{
				_harmony.PatchAll(typeof(MinimapPatches));
				_harmony.PatchAll(typeof(MapTablePatches));
				_harmony.PatchAll(typeof(PanelInputPatches));
				_harmony.PatchAll(typeof(PiecePatches));
				_harmony.PatchAll(typeof(ChatPatches));
				((Component)this).gameObject.AddComponent<CompassHud>();
				((Component)this).gameObject.AddComponent<CompassSettingsPanel>();
				((Component)this).gameObject.AddComponent<ConfigSyncClient>();
				Log.LogInfo((object)"NoMap Wayfinding 1.1.1 loaded.");
			}
		}

		private ConfigFile OpenConfigFile()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "nomapwayfinding.cfg");
			string text2 = Path.Combine(Paths.ConfigPath, "com.rynwind.nomapwayfinding.cfg");
			try
			{
				if (!File.Exists(text) && File.Exists(text2))
				{
					File.Copy(text2, text);
					Log.LogInfo((object)("Carried settings over from " + Path.GetFileName(text2) + " into nomapwayfinding.cfg. The old file is no longer read and can be deleted."));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not carry settings over from the old config file: " + ex.Message));
			}
			return new ConfigFile(text, true, ((BaseUnityPlugin)this).Info.Metadata);
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace NoMapWayfinding.Sync
{
	internal static class ConfigSync
	{
		public const string RequestRpc = "Wayfinding_RequestRules";

		public const string ApplyRpc = "Wayfinding_Rules";

		public static void Register()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				instance.Register<ZPackage>("Wayfinding_RequestRules", (Action<long, ZPackage>)OnRulesRequested);
				instance.Register<ZPackage>("Wayfinding_Rules", (Action<long, ZPackage>)OnRulesReceived);
			}
		}

		private static void OnRulesRequested(long sender, ZPackage pkg)
		{
			ZNet instance = ZNet.instance;
			if (!((Object)(object)instance == (Object)null) && instance.IsServer())
			{
				ModdedClientGate.MarkVerified(sender);
				if (PluginConfig.EnforceOnClients.Value)
				{
					ServerRules serverRules = ServerRules.FromLocalConfig();
					ZRoutedRpc.instance.InvokeRoutedRPC(sender, "Wayfinding_Rules", new object[1] { serverRules.Serialize() });
					WayfindingPlugin.Log.LogInfo((object)("Sent Wayfinding rules to peer " + sender + ": " + serverRules));
				}
			}
		}

		private static void OnRulesReceived(long sender, ZPackage pkg)
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null || instance.IsServer())
			{
				return;
			}
			ZNetPeer serverPeer = instance.GetServerPeer();
			if (serverPeer == null || sender != serverPeer.m_uid)
			{
				WayfindingPlugin.Log.LogWarning((object)("Ignoring Wayfinding rules from peer " + sender + ", which is not the server."));
				return;
			}
			ServerRules serverRules = ServerRules.Deserialize(pkg);
			if (serverRules != null)
			{
				ServerRules.Apply(serverRules);
				WayfindingPlugin.Log.LogInfo((object)("This server sets the Wayfinding rules: " + serverRules));
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class ZRoutedRpcConstructorPatch
	{
		private static void Postfix()
		{
			ConfigSync.Register();
		}
	}
	internal class ConfigSyncClient : MonoBehaviour
	{
		private const float RetryInterval = 2f;

		private const int MaxAttempts = 5;

		private float _nextAttemptAt;

		private int _attempts;

		private void Update()
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				ServerRules.Clear();
				_attempts = 0;
			}
			else if (instance.IsServer())
			{
				_attempts = 0;
			}
			else if (!ServerRules.Active && _attempts < 5 && !(Time.time < _nextAttemptAt) && instance.GetServerPeer() != null && ZRoutedRpc.instance != null)
			{
				_nextAttemptAt = Time.time + 2f;
				_attempts++;
				ZRoutedRpc.instance.InvokeRoutedRPC("Wayfinding_RequestRules", new object[1] { (object)new ZPackage() });
				if (_attempts == 5)
				{
					WayfindingPlugin.Log.LogInfo((object)"Server did not send Wayfinding rules; using local settings.");
				}
			}
		}
	}
	internal static class ModdedClientGate
	{
		private const float DisconnectDelay = 1f;

		private static readonly HashSet<long> Verified = new HashSet<long>();

		private static readonly Dictionary<long, float> FirstSeen = new Dictionary<long, float>();

		private static readonly Dictionary<long, float> Rejecting = new Dictionary<long, float>();

		public static void MarkVerified(long peerId)
		{
			Verified.Add(peerId);
		}

		public static void Tick()
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null || !instance.IsServer())
			{
				Forget();
				return;
			}
			List<ZNetPeer> connectedPeers = instance.GetConnectedPeers();
			HashSet<long> hashSet = new HashSet<long>();
			foreach (ZNetPeer item in connectedPeers)
			{
				if (item != null && item.m_uid != 0L)
				{
					hashSet.Add(item.m_uid);
					Consider(instance, item);
				}
			}
			Prune(hashSet);
		}

		private static void Consider(ZNet znet, ZNetPeer peer)
		{
			long uid = peer.m_uid;
			if (Rejecting.TryGetValue(uid, out var value))
			{
				if (Time.time - value >= 1f)
				{
					znet.Disconnect(peer);
					Rejecting.Remove(uid);
				}
			}
			else if (!Verified.Contains(uid))
			{
				if (!FirstSeen.ContainsKey(uid))
				{
					FirstSeen[uid] = Time.time;
				}
				else if (PluginConfig.RequireModdedClients.Value && !(Time.time - FirstSeen[uid] < Mathf.Max(5f, PluginConfig.ClientGraceSeconds.Value)))
				{
					Reject(peer);
				}
			}
		}

		private static void Reject(ZNetPeer peer)
		{
			string text = (string.IsNullOrEmpty(peer.m_playerName) ? ("peer " + peer.m_uid) : peer.m_playerName);
			WayfindingPlugin.Log.LogWarning((object)("Refusing " + text + ": this server requires the NoMap Wayfinding mod and that client did not identify itself as having it. Set Server.RequireModdedClients to false to allow unmodded players."));
			try
			{
				if (peer.m_rpc != null && peer.m_rpc.IsConnected())
				{
					peer.m_rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			catch (Exception ex)
			{
				WayfindingPlugin.Log.LogWarning((object)("Could not send the rejection notice: " + ex.Message));
			}
			Rejecting[peer.m_uid] = Time.time;
		}

		private static void Prune(HashSet<long> present)
		{
			Drop(FirstSeen, present);
			Drop(Rejecting, present);
			Verified.RemoveWhere((long uid) => !present.Contains(uid));
		}

		private static void Drop(Dictionary<long, float> map, HashSet<long> present)
		{
			if (map.Count == 0)
			{
				return;
			}
			List<long> list = new List<long>();
			foreach (KeyValuePair<long, float> item in map)
			{
				if (!present.Contains(item.Key))
				{
					list.Add(item.Key);
				}
			}
			foreach (long item2 in list)
			{
				map.Remove(item2);
			}
		}

		private static void Forget()
		{
			if (Verified.Count != 0 || FirstSeen.Count != 0 || Rejecting.Count != 0)
			{
				Verified.Clear();
				FirstSeen.Clear();
				Rejecting.Clear();
			}
		}
	}
	internal class ServerGate : MonoBehaviour
	{
		private const float Interval = 1f;

		private float _nextTickAt;

		private void Update()
		{
			if (!(Time.time < _nextTickAt))
			{
				_nextTickAt = Time.time + 1f;
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					WorldRules.Reset();
					ShoutMarkers.Clear();
					ModdedClientGate.Tick();
				}
				else
				{
					WorldRules.AnnounceOnce();
					ModdedClientGate.Tick();
				}
			}
		}
	}
	internal class ServerRules
	{
		private const int PayloadVersion = 2;

		public bool Enabled = true;

		public bool HideMinimap = true;

		public bool RequireTableForMap = true;

		public bool AutoSyncAtTable = true;

		public float TableRange = 8f;

		public float TableSettlingSeconds;

		public bool TableNoRefund;

		public static bool Active { get; private set; }

		public static ServerRules Current { get; private set; }

		public static ServerRules FromLocalConfig()
		{
			return new ServerRules
			{
				Enabled = PluginConfig.Enabled.Value,
				HideMinimap = PluginConfig.HideMinimap.Value,
				RequireTableForMap = PluginConfig.RequireTableForMap.Value,
				AutoSyncAtTable = PluginConfig.AutoSyncAtTable.Value,
				TableRange = PluginConfig.TableRange.Value,
				TableSettlingSeconds = PluginConfig.TableSettlingSeconds.Value,
				TableNoRefund = PluginConfig.TableNoRefund.Value
			};
		}

		public static void Apply(ServerRules rules)
		{
			Current = rules;
			Active = true;
		}

		public static void Clear()
		{
			if (Active)
			{
				Active = false;
				Current = null;
				WayfindingPlugin.Log.LogInfo((object)"Left the server; local Wayfinding settings are in force again.");
			}
		}

		public ZPackage Serialize()
		{
			//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_0030: 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_0048: 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_0061: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(2);
			val.Write(Enabled);
			val.Write(HideMinimap);
			val.Write(RequireTableForMap);
			val.Write(AutoSyncAtTable);
			val.Write(TableRange);
			val.Write(TableSettlingSeconds);
			val.Write(TableNoRefund);
			return val;
		}

		public static ServerRules Deserialize(ZPackage pkg)
		{
			if (pkg == null)
			{
				return null;
			}
			try
			{
				int num = pkg.ReadInt();
				if (num != 2)
				{
					WayfindingPlugin.Log.LogWarning((object)("Server sent Wayfinding rules version " + num + ", expected " + 2 + ". Ignoring them and keeping local settings; the server and this client are running different versions of the mod."));
					return null;
				}
				return new ServerRules
				{
					Enabled = pkg.ReadBool(),
					HideMinimap = pkg.ReadBool(),
					RequireTableForMap = pkg.ReadBool(),
					AutoSyncAtTable = pkg.ReadBool(),
					TableRange = Mathf.Clamp(pkg.ReadSingle(), 2f, 64f),
					TableSettlingSeconds = Mathf.Clamp(pkg.ReadSingle(), 0f, 7200f),
					TableNoRefund = pkg.ReadBool()
				};
			}
			catch (Exception ex)
			{
				WayfindingPlugin.Log.LogWarning((object)("Could not read Wayfinding rules from the server: " + ex.Message));
				return null;
			}
		}

		public override string ToString()
		{
			return "enabled=" + Enabled + " hideMinimap=" + HideMinimap + " requireTable=" + RequireTableForMap + " autoSync=" + AutoSyncAtTable + " range=" + TableRange + " settling=" + TableSettlingSeconds + " noRefund=" + TableNoRefund;
		}
	}
	internal static class WorldRules
	{
		private static bool _announced;

		public static bool NoMap
		{
			get
			{
				if ((Object)(object)ZoneSystem.instance != (Object)null)
				{
					return ZoneSystem.instance.GetGlobalKey((GlobalKeys)31);
				}
				return false;
			}
		}

		public static void AnnounceOnce()
		{
			if (!_announced && !((Object)(object)ZoneSystem.instance == (Object)null))
			{
				_announced = true;
				bool noMap = NoMap;
				if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
				{
					WayfindingPlugin.Log.LogInfo((object)(noMap ? "This world has the NoMap global key set. Every client loses the minimap and the map key through the game's own code, so Server.RequireModdedClients is optional here: players without the mod can join, they just cannot see a map." : "This world does not have the NoMap global key set, so players without the mod keep their minimap. Setting it (world modifiers, or setglobalkey NoMap) is the only way to stop that without turning them away."));
				}
				else if (noMap)
				{
					WayfindingPlugin.Log.LogInfo((object)"This world forbids the map. Wayfinding will still open it at a cartography table.");
				}
			}
		}

		public static void Reset()
		{
			_announced = false;
		}
	}
}
namespace NoMapWayfinding.Patches
{
	[HarmonyPatch]
	internal static class ChatPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Chat), "OnNewChatMessage")]
		private static void OnNewChatMessage_Postfix(long senderID, Vector3 pos, Type type, UserInfo sender)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			if (!Settings.Enabled || Settings.CompassShoutSeconds <= 0f || (int)type != 2)
			{
				return;
			}
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				ZDOID localPlayerCharacterID = ZNet.instance.LocalPlayerCharacterID;
				if (senderID == ((ZDOID)(ref localPlayerCharacterID)).UserID)
				{
					return;
				}
			}
			ShoutMarkers.Record(pos, (sender != null) ? sender.GetDisplayName() : "");
		}
	}
	[HarmonyPatch]
	internal static class MapTablePatches
	{
		private static readonly Type[] SwitchCallbackArgs = new Type[3]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		};

		private static readonly MethodInfo OnWriteMethod = AccessTools.Method(typeof(MapTable), "OnWrite", SwitchCallbackArgs, (Type[])null);

		private static bool _syncing;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static bool OnRead_Prefix(MapTable __instance, Humanoid user, ItemData item)
		{
			return !Refused(__instance, user, item);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "OnWrite", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static bool OnWrite_Prefix(MapTable __instance, Humanoid user, ItemData item)
		{
			if (Refused(__instance, user, item))
			{
				return false;
			}
			if (ShouldHandle(user, item))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.ClaimOwnership();
				}
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static void OnRead_Postfix(MapTable __instance, Switch caller, Humanoid user, ItemData item)
		{
			if (!_syncing && ShouldHandle(user, item) && TableSettling.IsSettled(__instance))
			{
				if (Settings.AutoSyncAtTable)
				{
					PushLocalMapToTable(__instance, caller, user, item);
				}
				OfferMap(__instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MapTable), "OnWrite", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static void OnWrite_Postfix(MapTable __instance, Humanoid user, ItemData item)
		{
			if (!_syncing && ShouldHandle(user, item) && TableSettling.IsSettled(__instance))
			{
				OfferMap(__instance);
			}
		}

		private static bool Refused(MapTable table, Humanoid user, ItemData item)
		{
			if (_syncing || !ShouldHandle(user, item))
			{
				return false;
			}
			double num = TableSettling.RemainingSeconds(table);
			if (num <= 0.0)
			{
				return false;
			}
			((Character)user).Message((MessageType)2, "The charts are still being drawn (" + TableSettling.DescribeRemaining(num) + ")", 0, (Sprite)null, false);
			return true;
		}

		private static void PushLocalMapToTable(MapTable table, Switch caller, Humanoid user, ItemData item)
		{
			if (OnWriteMethod == null)
			{
				return;
			}
			_syncing = true;
			try
			{
				OnWriteMethod.Invoke(table, new object[3] { caller, user, item });
			}
			catch (Exception ex)
			{
				WayfindingPlugin.Log.LogWarning((object)("Cartography table sync failed: " + ex));
			}
			finally
			{
				_syncing = false;
			}
		}

		private static bool ShouldHandle(Humanoid user, ItemData item)
		{
			if (!Settings.Enabled)
			{
				return false;
			}
			if (item != null)
			{
				return false;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val != (Object)null)
			{
				return (Object)(object)val == (Object)(object)Player.m_localPlayer;
			}
			return false;
		}

		private static void OfferMap(MapTable table)
		{
			if (Settings.RequireTableForMap)
			{
				MapAccess.Open(table);
			}
		}
	}
	[HarmonyPatch(typeof(Minimap))]
	internal static class MinimapPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("SetMapMode")]
		private static void SetMapMode_Prefix(ref MapMode mode, out bool __state)
		{
			__state = Game.m_noMap;
			if (Settings.Enabled)
			{
				if ((int)mode == 2 && MapAccess.Granted)
				{
					Game.m_noMap = false;
				}
				else if ((int)mode == 2 && Settings.RequireTableForMap)
				{
					mode = (MapMode)1;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetMapMode")]
		private static void SetMapMode_Postfix(Minimap __instance, bool __state)
		{
			Game.m_noMap = __state;
			ApplyMinimapVisibility(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Update_Postfix(Minimap __instance)
		{
			ApplyMinimapVisibility(__instance);
			MapAccess.Tick();
		}

		private static void ApplyMinimapVisibility(Minimap map)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			if (!((Object)(object)map == (Object)null) && !((Object)(object)map.m_smallRoot == (Object)null) && (int)map.m_mode == 1)
			{
				bool flag = !Settings.Enabled || !Settings.HideMinimap;
				SetActive(map.m_smallRoot, flag);
				if ((Object)(object)map.m_pinRootSmall != (Object)null)
				{
					SetActive(((Component)map.m_pinRootSmall).gameObject, flag);
				}
				if ((Object)(object)map.m_pinNameRootSmall != (Object)null)
				{
					SetActive(((Component)map.m_pinNameRootSmall).gameObject, flag);
				}
				if (!flag && (Object)(object)map.m_sharedMapHint != (Object)null)
				{
					SetActive(map.m_sharedMapHint, active: false);
				}
			}
		}

		private static void SetActive(GameObject target, bool active)
		{
			if ((Object)(object)target != (Object)null && target.activeSelf != active)
			{
				target.SetActive(active);
			}
		}
	}
	[HarmonyPatch]
	internal static class PanelInputPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "TakeInput")]
		private static void TakeInput_Postfix(ref bool __result)
		{
			if (CompassSettingsPanel.IsOpen)
			{
				__result = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		private static bool UpdateMouseCapture_Prefix()
		{
			if (!CompassSettingsPanel.IsOpen)
			{
				return true;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class PiecePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Piece), "SetCreator")]
		private static void SetCreator_Postfix(Piece __instance)
		{
			if (Settings.Enabled && !(Settings.TableSettlingSeconds <= 0f))
			{
				MapTable componentInChildren = ((Component)__instance).GetComponentInChildren<MapTable>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					TableSettling.StampPlacement(componentInChildren);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Piece), "DropResources")]
		private static bool DropResources_Prefix(Piece __instance)
		{
			if (!Settings.Enabled || !Settings.TableNoRefund)
			{
				return true;
			}
			return (Object)(object)((Component)__instance).GetComponentInChildren<MapTable>(true) == (Object)null;
		}
	}
}