Decompiled source of SunkenCryptTimer v1.1.8

Plugins/SunkenCryptTimer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using SoftReferenceableAssets;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("SunkenCryptTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.8.0")]
[assembly: AssemblyInformationalVersion("1.1.8")]
[assembly: AssemblyProduct("SunkenCryptTimer")]
[assembly: AssemblyTitle("SunkenCryptTimer")]
[assembly: AssemblyVersion("1.1.8.0")]
namespace SunkenCryptTimer;

[BepInPlugin("lan124.SunkenCryptTimer", "SunkenCryptTimer", "1.1.8")]
public class SunkenCryptTimerPlugin : BaseUnityPlugin
{
	internal enum InstanceNaming
	{
		Type,
		NameAndZone,
		Name,
		Zone
	}

	public const string PluginGuid = "lan124.SunkenCryptTimer";

	public const string PluginName = "SunkenCryptTimer";

	public const string PluginVersion = "1.1.8";

	internal static ManualLogSource Log;

	internal const string VlrLastResetField = "VV_LastReset";

	internal const string VlrPluginGuid = "com.orianaventure.mod.LocationReset";

	internal static ConfigEntry<bool> CeEnabled;

	internal static ConfigEntry<bool> CeDebug;

	internal static ConfigEntry<float> CeScanRadius;

	internal static ConfigEntry<float> CeUpdateInterval;

	internal static ConfigEntry<float> CeHudOffsetY;

	internal static ConfigEntry<int> CeFallbackResetDays;

	internal static ConfigEntry<bool> CeRingEnabled;

	internal static ConfigEntry<float> CeRingShowRadius;

	internal static ConfigEntry<InstanceNaming> CeInstanceNaming;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		CeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch for the dungeon reset timer HUD.");
		CeDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", false, "Log scanner decisions each update (verbose; for troubleshooting).");
		CeScanRadius = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "ScanRadiusMeters", 80f, "Show the timer when the player is within this distance of a dungeon entrance (float, meters).");
		CeUpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "UpdateIntervalSeconds", 1f, "How often to rescan for nearby dungeons (float, seconds). 1 is plenty.");
		CeHudOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "HudOffsetY", 170f, "Fallback top offset for the timer text, used only until the status-effect row (Rested/Wet icons) is found - normally the timer positions itself just below that row (float, pixels).");
		CeFallbackResetDays = ((BaseUnityPlugin)this).Config.Bind<int>("Timers", "FallbackResetDays", 10, "Assumed reset interval (in-game days) when Venture Location Reset is not installed on this client and its synced config cannot be read. Set this to match the server you play on. Ignored whenever VLR's own (server-synced) config is available.");
		CeRingEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Rings", "Enabled", true, "Draw a workbench-style ground ring around each nearby instanced dungeon (crypts, burial chambers, troll caves, ...), sized to the radius Venture Location Reset checks for it (45 m for sunken crypts). Instanced dungeons only - ground locations get no ring.");
		CeRingShowRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Rings", "ShowRadiusMeters", 100f, "Show a dungeon's ring while the player is within this distance of its entrance (float, meters). 100 matches Venture Location Reset's own reset-trigger distance.");
		CeInstanceNaming = ((BaseUnityPlugin)this).Config.Bind<InstanceNaming>("HUD", "InstanceNaming", InstanceNaming.NameAndZone, "How the timer names the dungeon: Type (vanilla type name), NameAndZone (\"Odin's Tomb (-70,-21)\" - name deterministic per instance, zone readable on the minimap), Name, or Zone.");
		((Component)this).gameObject.AddComponent<Tracker>();
		Log.LogInfo((object)"SunkenCryptTimer 1.1.8 loaded.");
	}
}
internal static class DungeonNames
{
	private static readonly string[] Roots = new string[36]
	{
		"Odin", "Thor", "Loki", "Freya", "Fenrir", "Ymir", "Hel", "Baldur", "Tyr", "Njord",
		"Sif", "Bragi", "Heimdall", "Frigg", "Ragnar", "Bjorn", "Astrid", "Grimr", "Ulf", "Sigrid",
		"Ivar", "Ketil", "Orm", "Hilda", "Eirik", "Gudrun", "Thyri", "Vali", "Hod", "Nanna",
		"Fafnir", "Jormungandr", "Surt", "Skadi", "Vidar", "Mimir"
	};

	private static readonly string[] Burial = new string[6] { "Tomb", "Barrow", "Crypt", "Rest", "Grave", "Cairn" };

	private static readonly string[] Cave = new string[4] { "Den", "Hollow", "Howl", "Lair" };

	private static readonly string[] Camp = new string[4] { "Camp", "Hold", "Stead", "Watch" };

	private static readonly string[] Generic = new string[4] { "Rest", "Hollow", "Refuge", "Cache" };

	internal static string Name(long uid, string prefabName)
	{
		string[] array = SuffixesFor(prefabName);
		Random random = new Random((int)(uid & 0xFFFFFFFFu) ^ (int)(uid >> 32));
		return Roots[random.Next(Roots.Length)] + "'s " + array[random.Next(array.Length)];
	}

	internal static string Zone(Vector3 position)
	{
		//IL_0000: 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)
		int num = Mathf.FloorToInt(position.x / 64f);
		int num2 = Mathf.FloorToInt(position.z / 64f);
		return $"({num},{num2})";
	}

	private static string[] SuffixesFor(string prefabName)
	{
		if (prefabName == null)
		{
			return Generic;
		}
		if (prefabName.IndexOf("Crypt", StringComparison.OrdinalIgnoreCase) >= 0 || prefabName.IndexOf("Burial", StringComparison.OrdinalIgnoreCase) >= 0 || prefabName.IndexOf("Grave", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return Burial;
		}
		if (prefabName.IndexOf("Cave", StringComparison.OrdinalIgnoreCase) >= 0 || prefabName.IndexOf("Troll", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return Cave;
		}
		if (prefabName.IndexOf("Camp", StringComparison.OrdinalIgnoreCase) >= 0 || prefabName.IndexOf("Village", StringComparison.OrdinalIgnoreCase) >= 0 || prefabName.IndexOf("Farm", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return Camp;
		}
		return Generic;
	}
}
internal static class HudLabel
{
	private const string LabelName = "SunkenCryptTimer.HudLabel";

	private static TextMeshProUGUI _label;

	private static readonly FieldInfo HudInstanceField = typeof(Hud).GetField("m_instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

	private static bool _statusTextSizeApplied;

	private static bool _fontWarned;

	private static bool _fontErrored;

	private static Hud HudInstance
	{
		get
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (!(HudInstanceField != null))
			{
				return null;
			}
			return (Hud)HudInstanceField.GetValue(null);
		}
	}

	internal static void Show(string text)
	{
		TextMeshProUGUI orCreate = GetOrCreate();
		if ((Object)(object)orCreate == (Object)null)
		{
			return;
		}
		if (!IsUsable(((TMP_Text)orCreate).font))
		{
			Hud hudInstance = HudInstance;
			if ((Object)(object)hudInstance != (Object)null && (Object)(object)hudInstance.m_eventName != (Object)null)
			{
				((TMP_Text)orCreate).font = ResolveFont(hudInstance, hudInstance.m_eventName);
			}
		}
		if (!((Component)orCreate).gameObject.activeSelf)
		{
			((Component)orCreate).gameObject.SetActive(true);
		}
		MatchStatusEffectRow(orCreate);
		((TMP_Text)orCreate).text = text;
	}

	private static void MatchStatusEffectRow(TextMeshProUGUI label)
	{
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_017c: 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_019b: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		Hud hudInstance = HudInstance;
		if ((Object)(object)hudInstance == (Object)null || (Object)(object)hudInstance.m_statusEffectListRoot == (Object)null)
		{
			return;
		}
		if (!_statusTextSizeApplied)
		{
			RectTransform statusEffectTemplate = hudInstance.m_statusEffectTemplate;
			if ((Object)(object)statusEffectTemplate != (Object)null)
			{
				TMP_Text[] componentsInChildren = ((Component)statusEffectTemplate).GetComponentsInChildren<TMP_Text>(true);
				int num = 0;
				if (num < componentsInChildren.Length)
				{
					TMP_Text val = componentsInChildren[num];
					((TMP_Text)label).fontSize = val.fontSize;
					_statusTextSizeApplied = true;
				}
			}
		}
		RectTransform statusEffectListRoot = hudInstance.m_statusEffectListRoot;
		RectTransform canvasRect = (RectTransform)((Component)((Graphic)label).canvas).transform;
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		float bottom = float.MaxValue;
		float right = float.MinValue;
		bool flag = false;
		foreach (Transform item in (Transform)statusEffectListRoot)
		{
			Transform val2 = item;
			if (((Component)val2).gameObject.activeSelf)
			{
				((RectTransform)val2).GetWorldCorners(array);
				Vector3[] array2 = array;
				for (int num = 0; num < array2.Length; num++)
				{
					Consider(array2[num]);
				}
				flag = true;
			}
		}
		if (!flag)
		{
			statusEffectListRoot.GetWorldCorners(array);
			Vector3[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				Consider(array2[num]);
			}
		}
		if (bottom > float.MinValue && right < float.MaxValue)
		{
			Rect rect = canvasRect.rect;
			float num2 = ((Rect)(ref rect)).max.y - bottom + 10f;
			float num3 = ((Rect)(ref rect)).max.x - right;
			((RectTransform)((TMP_Text)label).transform).anchoredPosition = new Vector2(0f - num3, 0f - num2);
		}
		void Consider(Vector3 worldCorner)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val3 = ((Transform)canvasRect).InverseTransformPoint(worldCorner);
			if (val3.y < bottom)
			{
				bottom = val3.y;
			}
			if (val3.x > right)
			{
				right = val3.x;
			}
		}
	}

	internal static void Hide()
	{
		if ((Object)(object)_label != (Object)null && ((Component)_label).gameObject.activeSelf)
		{
			((Component)_label).gameObject.SetActive(false);
		}
	}

	private static TextMeshProUGUI GetOrCreate()
	{
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Expected O, but got Unknown
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_label != (Object)null)
		{
			return _label;
		}
		Hud hudInstance = HudInstance;
		if ((Object)(object)hudInstance == (Object)null || (Object)(object)hudInstance.m_eventName == (Object)null)
		{
			return null;
		}
		TMP_Text val = hudInstance.m_eventName;
		TextMeshProUGUI[] array;
		if (!IsUsable(val.font))
		{
			val = null;
			array = Object.FindObjectsOfType<TextMeshProUGUI>();
			foreach (TextMeshProUGUI val2 in array)
			{
				if (((Behaviour)val2).isActiveAndEnabled && IsUsable(((TMP_Text)val2).font) && (Object)(object)((Graphic)val2).canvas != (Object)null && ((Behaviour)((Graphic)val2).canvas).isActiveAndEnabled)
				{
					val = (TMP_Text)(object)val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				SunkenCryptTimerPlugin.Log.LogWarning((object)"No live HUD label to take a font from yet; retrying next update.");
				return null;
			}
			SunkenCryptTimerPlugin.Log.LogWarning((object)("HUD label font taken from '" + ((Object)val).name + "' (canvas '" + ((Object)((Graphic)val).canvas).name + "')."));
		}
		array = Object.FindObjectsOfType<TextMeshProUGUI>();
		foreach (TextMeshProUGUI val3 in array)
		{
			if (((Object)val3).name == "SunkenCryptTimer.HudLabel")
			{
				Object.Destroy((Object)(object)((Component)val3).gameObject);
			}
		}
		Canvas val4 = ((((Component)hudInstance).gameObject.activeInHierarchy && (Object)(object)((Graphic)hudInstance.m_eventName).canvas != (Object)null) ? ((Graphic)hudInstance.m_eventName).canvas : ((Graphic)val).canvas);
		GameObject val5 = new GameObject("SunkenCryptTimer.HudLabel", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		val5.transform.SetParent(((Component)val4).transform, false);
		RectTransform val6 = (RectTransform)val5.transform;
		val6.anchorMin = new Vector2(1f, 1f);
		val6.anchorMax = new Vector2(1f, 1f);
		val6.pivot = new Vector2(1f, 1f);
		val6.anchoredPosition = new Vector2(-20f, 0f - SunkenCryptTimerPlugin.CeHudOffsetY.Value);
		RectTransform val7 = (RectTransform)((Component)val4).transform;
		Rect rect = val7.rect;
		val6.sizeDelta = new Vector2(Mathf.Min(700f, ((Rect)(ref rect)).width - 40f), 30f);
		_label = val5.GetComponent<TextMeshProUGUI>();
		_statusTextSizeApplied = false;
		((TMP_Text)_label).font = val.font;
		((TMP_Text)_label).fontSize = val.fontSize;
		((Graphic)_label).color = ((Graphic)hudInstance.m_eventName).color;
		((TMP_Text)_label).alignment = (TextAlignmentOptions)516;
		((TMP_Text)_label).enableWordWrapping = true;
		((TMP_Text)_label).overflowMode = (TextOverflowModes)0;
		((Graphic)_label).raycastTarget = false;
		SunkenCryptTimerPlugin.Log.LogInfo((object)("HUD label ready on canvas '" + ((Object)val4).name + "' (font from '" + ((Object)val).name + "')."));
		return _label;
	}

	private static TMP_FontAsset ResolveFont(Hud hud, TMP_Text template)
	{
		if (IsUsable(template.font))
		{
			return template.font;
		}
		TextMeshProUGUI[] componentsInChildren = ((Component)hud).GetComponentsInChildren<TextMeshProUGUI>(true);
		foreach (TextMeshProUGUI val in componentsInChildren)
		{
			if (((Behaviour)val).isActiveAndEnabled && IsUsable(((TMP_Text)val).font))
			{
				WarnOnce("Event font not usable; using font from HUD label '" + ((Object)val).name + "'.");
				return ((TMP_Text)val).font;
			}
		}
		componentsInChildren = Object.FindObjectsOfType<TextMeshProUGUI>();
		foreach (TextMeshProUGUI val2 in componentsInChildren)
		{
			if (IsUsable(((TMP_Text)val2).font))
			{
				WarnOnce("Event font not usable; using font from scene label '" + ((Object)val2).name + "'.");
				return ((TMP_Text)val2).font;
			}
		}
		if (IsUsable(TMP_Settings.defaultFontAsset))
		{
			WarnOnce("No usable font in HUD; using TMP_Settings.defaultFontAsset.");
			return TMP_Settings.defaultFontAsset;
		}
		if (!_fontErrored)
		{
			_fontErrored = true;
			SunkenCryptTimerPlugin.Log.LogError((object)"No usable TMP font found yet; will retry each update.");
		}
		return null;
	}

	private static bool IsUsable(TMP_FontAsset font)
	{
		if ((Object)(object)font != (Object)null)
		{
			if (!((Object)(object)font.atlas != (Object)null))
			{
				return (Object)(object)font.atlasTexture != (Object)null;
			}
			return true;
		}
		return false;
	}

	private static void WarnOnce(string message)
	{
		if (!_fontWarned)
		{
			_fontWarned = true;
			SunkenCryptTimerPlugin.Log.LogWarning((object)message);
		}
	}
}
internal static class ResetTimer
{
	private static readonly Dictionary<string, string> TypeConfigKeys = new Dictionary<string, string>
	{
		{ "SunkenCrypt4", "CryptResetTime" },
		{ "Crypt2", "BurialResetTime" },
		{ "Crypt3", "BurialResetTime" },
		{ "Crypt4", "BurialResetTime" },
		{ "TrollCave02", "TrollResetTime" },
		{ "MountainCave02", "CaveResetTime" },
		{ "GoblinCamp2", "CampResetTime" },
		{ "WoodFarm1", "FarmResetTime" },
		{ "WoodVillage1", "VillageResetTime" },
		{ "Mistlands_DvergrTownEntrance1", "MineResetTime" },
		{ "Mistlands_DvergrTownEntrance2", "MineResetTime" },
		{ "Mistlands_DvergrBossEntrance1", "QueenResetTime" },
		{ "Hildir_crypt", "HildirCryptResetTime" },
		{ "Hildir_cave", "HildirCaveResetTime" },
		{ "Hildir_plainsfortress", "HildirTowerResetTime" },
		{ "CharredFortress", "CharredFortressResetTime" },
		{ "LeviathanLava", "LeviathanLavaResetTime" },
		{ "MorgenHole1", "MorgenHoleResetTime" },
		{ "MorgenHole2", "MorgenHoleResetTime" },
		{ "MorgenHole3", "MorgenHoleResetTime" },
		{ "PlaceofMystery1", "PlaceofMysteryResetTime" },
		{ "PlaceofMystery2", "PlaceofMysteryResetTime" },
		{ "PlaceofMystery3", "PlaceofMysteryResetTime" },
		{ "VV_CopperTinCave", "CopperTinCaveResetTime" },
		{ "VV_SilverCave", "SilverCaveResetTime" }
	};

	private static readonly Dictionary<string, string> PrettyNames = new Dictionary<string, string>
	{
		{ "SunkenCrypt4", "Sunken Crypt" },
		{ "Crypt2", "Burial Chamber" },
		{ "Crypt3", "Burial Chamber" },
		{ "Crypt4", "Burial Chamber" },
		{ "TrollCave02", "Troll Cave" },
		{ "MountainCave02", "Frost Cave" },
		{ "GoblinCamp2", "Goblin Camp" },
		{ "WoodFarm1", "Abandoned Farm" },
		{ "WoodVillage1", "Abandoned Village" },
		{ "Mistlands_DvergrTownEntrance1", "Dvergr Town" },
		{ "Mistlands_DvergrTownEntrance2", "Dvergr Town" },
		{ "Mistlands_DvergrBossEntrance1", "Dvergr Queen Lair" },
		{ "Hildir_crypt", "Hildir's Crypt" },
		{ "Hildir_cave", "Hildir's Cave" },
		{ "Hildir_plainsfortress", "Hildir's Fortress" },
		{ "CharredFortress", "Charred Fortress" },
		{ "MorgenHole1", "Morgen Hole" },
		{ "MorgenHole2", "Morgen Hole" },
		{ "MorgenHole3", "Morgen Hole" },
		{ "PlaceofMystery1", "Place of Mystery" },
		{ "PlaceofMystery2", "Place of Mystery" },
		{ "PlaceofMystery3", "Place of Mystery" },
		{ "VV_CopperTinCave", "Copper/Tin Cave" },
		{ "VV_SilverCave", "Silver Cave" },
		{ "DG_SunkenCrypt", "Sunken Crypt" },
		{ "DG_BurialChambers", "Burial Chamber" },
		{ "DG_TrollCave", "Troll Cave" },
		{ "Grave1", "Grave" },
		{ "Grave2", "Grave" },
		{ "Grave3", "Grave" },
		{ "InfestedTree01", "Infested Tree" },
		{ "SwampHut1", "Swamp Hut" },
		{ "SwampHut2", "Swamp Hut" },
		{ "SwampHut3", "Swamp Hut" },
		{ "SwampHut4", "Swamp Hut" },
		{ "SwampHut5", "Swamp Hut" },
		{ "SwampRuin1", "Swamp Ruin" },
		{ "StoneTower1", "Stone Tower" },
		{ "ShipSetting01", "Shipwreck" },
		{ "ShipSetting02", "Shipwreck" },
		{ "Dolmen01", "Dolmen" },
		{ "GoblinCamp1", "Goblin Camp" },
		{ "WoodHouse1", "Abandoned House" },
		{ "WoodHouse2", "Abandoned House" },
		{ "WoodHouse3", "Abandoned House" },
		{ "WoodHouse4", "Abandoned House" },
		{ "WoodHouse5", "Abandoned House" },
		{ "WoodHouse6", "Abandoned House" },
		{ "WoodHouse7", "Abandoned House" }
	};

	private static ConfigFile _vlrConfig;

	private static bool _vlrConfigResolved;

	internal static string PrettyName(string prefabName)
	{
		if (PrettyNames.TryGetValue(prefabName, out var value))
		{
			return value;
		}
		if (prefabName.StartsWith("Runestone", StringComparison.Ordinal))
		{
			return "Runestone";
		}
		if (prefabName.StartsWith("StoneTowerRuins", StringComparison.Ordinal))
		{
			return "Ruined Tower";
		}
		return prefabName;
	}

	internal static int GetResetDays(string prefabName)
	{
		ConfigFile vlrConfig = GetVlrConfig();
		if (vlrConfig == null)
		{
			return SunkenCryptTimerPlugin.CeFallbackResetDays.Value;
		}
		if (!ReadBool(vlrConfig, "Advanced", "OverrideResetTimes"))
		{
			return ReadInt(vlrConfig, "General", "ResetTime", SunkenCryptTimerPlugin.CeFallbackResetDays.Value);
		}
		if (TypeConfigKeys.TryGetValue(prefabName, out var value))
		{
			return ReadInt(vlrConfig, "Advanced", value, ReadInt(vlrConfig, "General", "ResetTime", SunkenCryptTimerPlugin.CeFallbackResetDays.Value));
		}
		return ReadInt(vlrConfig, "General", "ResetTime", SunkenCryptTimerPlugin.CeFallbackResetDays.Value);
	}

	private static ConfigFile GetVlrConfig()
	{
		if (!_vlrConfigResolved)
		{
			_vlrConfigResolved = true;
			if (Chainloader.PluginInfos.TryGetValue("com.orianaventure.mod.LocationReset", out var value))
			{
				_vlrConfig = value.Instance.Config;
				SunkenCryptTimerPlugin.Log.LogDebug((object)"Venture Location Reset detected - using its live (server-synced) config.");
			}
			else
			{
				SunkenCryptTimerPlugin.Log.LogDebug((object)"Venture Location Reset not installed - using FallbackResetDays.");
			}
		}
		return _vlrConfig;
	}

	private static int ReadInt(ConfigFile file, string section, string key, int fallback)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		ConfigEntry<int> val = default(ConfigEntry<int>);
		if (!file.TryGetEntry<int>(new ConfigDefinition(section, key), ref val))
		{
			return fallback;
		}
		return val.Value;
	}

	private static bool ReadBool(ConfigFile file, string section, string key)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		ConfigEntry<bool> val = default(ConfigEntry<bool>);
		if (file.TryGetEntry<bool>(new ConfigDefinition(section, key), ref val))
		{
			return val.Value;
		}
		return false;
	}
}
internal class Tracker : MonoBehaviour
{
	internal readonly struct NearbyDungeon
	{
		public readonly string PrefabName;

		public readonly int LastResetDay;

		public readonly float Distance;

		public readonly Vector3 Position;

		public readonly long Uid;

		public NearbyDungeon(string prefabName, int lastResetDay, float distance, Vector3 position, long uid)
		{
			//IL_0016: 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)
			PrefabName = prefabName;
			LastResetDay = lastResetDay;
			Distance = distance;
			Position = position;
			Uid = uid;
		}
	}

	private float _nextScan;

	private readonly HashSet<int> _loggedUntracked = new HashSet<int>();

	private readonly HashSet<int> _loggedNames = new HashSet<int>();

	private readonly List<NearbyDungeon> _nearby = new List<NearbyDungeon>();

	private static readonly FieldInfo TotalSecondsField = GetEnvField("m_totalSeconds");

	private static bool _totalSecondsFallbackWarned;

	private static readonly FieldInfo InstanceField = typeof(LocationProxy).GetField("m_instance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private void Update()
	{
		//IL_0098: 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)
		if (!SunkenCryptTimerPlugin.CeEnabled.Value)
		{
			HudLabel.Hide();
			ZoneRing.ClearAll();
		}
		else if (!(Time.time < _nextScan))
		{
			_nextScan = Time.time + Mathf.Max(0.25f, SunkenCryptTimerPlugin.CeUpdateInterval.Value);
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)EnvMan.instance == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				HudLabel.Hide();
				ZoneRing.ClearAll();
				return;
			}
			_nearby.Clear();
			CollectTrackedDungeons(((Component)localPlayer).transform.position, _nearby);
			UpdateHudLabel();
			ZoneRing.UpdateRings(((Component)localPlayer).transform.position, _nearby);
		}
	}

	private void UpdateHudLabel()
	{
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		NearbyDungeon? nearbyDungeon = null;
		foreach (NearbyDungeon item in _nearby)
		{
			if (!nearbyDungeon.HasValue || item.Distance < nearbyDungeon.Value.Distance)
			{
				nearbyDungeon = item;
			}
		}
		if (!nearbyDungeon.HasValue || nearbyDungeon.Value.Distance > SunkenCryptTimerPlugin.CeScanRadius.Value)
		{
			if (SunkenCryptTimerPlugin.CeDebug.Value && nearbyDungeon.HasValue)
			{
				SunkenCryptTimerPlugin.Log.LogDebug((object)($"Nearest tracked dungeon {nearbyDungeon.Value.PrefabName} at {nearbyDungeon.Value.Distance:F0}m " + $"(> {SunkenCryptTimerPlugin.CeScanRadius.Value:F0}m radius), hiding label."));
			}
			HudLabel.Hide();
			return;
		}
		string prefabName = nearbyDungeon.Value.PrefabName;
		int lastResetDay = nearbyDungeon.Value.LastResetDay;
		int resetDays = ResetTimer.GetResetDays(prefabName);
		double num = (double)(lastResetDay + resetDays) - CurrentFractionalDay();
		string text = ((num > 0.0) ? (DisplayName(prefabName, nearbyDungeon.Value.Uid, nearbyDungeon.Value.Position) + " - resets in " + FormatRemaining(num)) : (DisplayName(prefabName, nearbyDungeon.Value.Uid, nearbyDungeon.Value.Position) + " - reset ready (regenerates on approach)"));
		if (SunkenCryptTimerPlugin.CeDebug.Value)
		{
			SunkenCryptTimerPlugin.Log.LogDebug((object)($"{prefabName}: lastResetDay={lastResetDay} resetDays={resetDays} " + $"now={CurrentFractionalDay():F2} remaining={num:F2} -> \"{text}\""));
		}
		HudLabel.Show(text);
	}

	private void CollectTrackedDungeons(Vector3 playerPos, List<NearbyDungeon> results)
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: 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_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		LocationProxy[] array = Object.FindObjectsOfType<LocationProxy>();
		foreach (LocationProxy val in array)
		{
			ZNetView component = ((Component)val).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				continue;
			}
			ZDO zDO = component.GetZDO();
			if (zDO == null)
			{
				continue;
			}
			int num = zDO.GetInt("VV_LastReset", -1);
			if (num < 0)
			{
				if (SunkenCryptTimerPlugin.CeDebug.Value && _loggedUntracked.Add((int)((ZDOID)(ref zDO.m_uid)).ID))
				{
					SunkenCryptTimerPlugin.Log.LogDebug((object)(string.Format("LocationProxy {0} has no {1} ", zDO.m_uid, "VV_LastReset") + "stamp (server without Venture Location Reset, or timer not started yet)."));
				}
				continue;
			}
			string text = "instance";
			string text2 = null;
			GameObject val2 = (GameObject)((InstanceField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val2 != (Object)null)
			{
				text2 = ((Object)val2).name;
				int num2 = text2.IndexOf("(Clone)", StringComparison.Ordinal);
				if (num2 >= 0)
				{
					text2 = text2.Substring(0, num2);
				}
			}
			if (string.IsNullOrEmpty(text2))
			{
				text2 = zDO.GetString(ZDOVars.s_location, "");
				text = "zdo";
			}
			if (string.IsNullOrEmpty(text2))
			{
				text2 = ResolveNameFromZoneSystem(((Component)val).transform.position);
				text = "zonesystem";
			}
			if (text2 == "Dungeon")
			{
				DungeonGenerator val3 = ZoneRing.FindRootGenerator(((Component)val).transform.position, 150f);
				if ((Object)(object)val3 != (Object)null && ((Component)val3).transform.position.y >= 4000f)
				{
					int num3 = ((Object)val3).name.IndexOf("(Clone)", StringComparison.Ordinal);
					text2 = ((num3 >= 0) ? ((Object)val3).name.Substring(0, num3) : ((Object)val3).name);
					text = "generator";
				}
			}
			if (_loggedNames.Add((int)((ZDOID)(ref zDO.m_uid)).ID))
			{
				SunkenCryptTimerPlugin.Log.LogInfo((object)$"tracked dungeon: '{text2}' (via {text}) at ({((Component)val).transform.position.x:F0}, {((Component)val).transform.position.z:F0})");
			}
			results.Add(new NearbyDungeon(text2, num, Vector3.Distance(playerPos, ((Component)val).transform.position), ((Component)val).transform.position, ((ZDOID)(ref zDO.m_uid)).ID));
		}
	}

	private static string ResolveNameFromZoneSystem(Vector3 position)
	{
		//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_002f: 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)
		//IL_0039: 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)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<Vector2s, LocationInstance> locationInstances = ZoneSystem.instance.m_locationInstances;
		string result = "Dungeon";
		float num = float.MaxValue;
		foreach (KeyValuePair<Vector2s, LocationInstance> item in locationInstances)
		{
			LocationInstance value = item.Value;
			if (value.m_location != null)
			{
				float num2 = Vector3.Distance(position, value.m_position);
				if (num2 < num)
				{
					num = num2;
					result = value.m_location.m_prefabName;
				}
			}
		}
		return result;
	}

	private static string DisplayName(string prefabName, long uid, Vector3 position)
	{
		//IL_004c: 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)
		return SunkenCryptTimerPlugin.CeInstanceNaming.Value switch
		{
			SunkenCryptTimerPlugin.InstanceNaming.Name => DungeonNames.Name(uid, prefabName), 
			SunkenCryptTimerPlugin.InstanceNaming.Zone => ResetTimer.PrettyName(prefabName) + " " + DungeonNames.Zone(position), 
			SunkenCryptTimerPlugin.InstanceNaming.NameAndZone => DungeonNames.Name(uid, prefabName) + " " + DungeonNames.Zone(position), 
			_ => ResetTimer.PrettyName(prefabName), 
		};
	}

	internal static double CurrentFractionalDay()
	{
		long dayLengthSec = EnvMan.instance.m_dayLengthSec;
		if (dayLengthSec <= 0)
		{
			return 1.0;
		}
		return ReadTotalSeconds() / (double)dayLengthSec + 1.0;
	}

	private static double ReadTotalSeconds()
	{
		if (TotalSecondsField != null && (Object)(object)EnvMan.instance != (Object)null)
		{
			return (double)TotalSecondsField.GetValue(EnvMan.instance);
		}
		if (!_totalSecondsFallbackWarned)
		{
			_totalSecondsFallbackWarned = true;
			SunkenCryptTimerPlugin.Log.LogWarning((object)"EnvMan.m_totalSeconds not found via reflection; falling back to ZNet.GetTimeSeconds(). Countdown may be offset by less than a day.");
		}
		if (!((Object)(object)ZNet.instance != (Object)null))
		{
			return 0.0;
		}
		return ZNet.instance.GetTimeSeconds();
	}

	private static FieldInfo GetEnvField(string name)
	{
		return typeof(EnvMan).GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
	}

	internal static string FormatRemaining(double remainingDays)
	{
		if (remainingDays >= 1.0)
		{
			int num = (int)remainingDays;
			int num2 = (int)((remainingDays - (double)num) * 24.0);
			return $"{num}d {num2}h";
		}
		int num3 = (int)(remainingDays * 24.0);
		if (num3 >= 1)
		{
			int num4 = (int)((remainingDays * 24.0 - (double)num3) * 60.0);
			return $"{num3}h {num4}m";
		}
		return $"{(int)(remainingDays * 24.0 * 60.0)}m";
	}
}
internal static class ZoneRing
{
	private class RingEntry
	{
		public GameObject Root;

		public CircleProjector Projector;

		public long Uid;

		public float Radius;

		public float LastSeen;

		public bool SeenThisTick;
	}

	private const int MaxRings = 4;

	private const float EntryTimeoutSeconds = 30f;

	internal const float SkyY = 4000f;

	private const string TemplatePrefabPrimary = "piece_workbench";

	private const string TemplatePrefabFallback = "guard_stone";

	private static readonly Dictionary<long, RingEntry> _entries = new Dictionary<long, RingEntry>();

	private static readonly Dictionary<string, float> _radiusCache = new Dictionary<string, float>();

	private static readonly HashSet<string> _warnedPrefabs = new HashSet<string>();

	private static readonly HashSet<string> _loggedRadius = new HashSet<string>();

	private static readonly List<Tracker.NearbyDungeon> _candidates = new List<Tracker.NearbyDungeon>();

	private static readonly List<RingEntry> _sweep = new List<RingEntry>();

	private static GameObject _root;

	private static Transform _template;

	private static bool _templateWarned;

	private static Dictionary<string, Location> _locationPrefabs;

	internal static void UpdateRings(Vector3 playerPos, List<Tracker.NearbyDungeon> nearby)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		if (!SunkenCryptTimerPlugin.CeRingEnabled.Value)
		{
			ClearAll();
		}
		else
		{
			if ((Object)(object)EnsureRoot() == (Object)null)
			{
				return;
			}
			float num = Mathf.Max(10f, SunkenCryptTimerPlugin.CeRingShowRadius.Value);
			bool flag = playerPos.y >= 4000f;
			_candidates.Clear();
			foreach (Tracker.NearbyDungeon item in nearby)
			{
				if (item.Distance <= num)
				{
					_candidates.Add(item);
				}
			}
			if (_candidates.Count > 4)
			{
				_candidates.Sort((Tracker.NearbyDungeon a, Tracker.NearbyDungeon b) => a.Distance.CompareTo(b.Distance));
				_candidates.RemoveRange(4, _candidates.Count - 4);
			}
			foreach (Tracker.NearbyDungeon candidate in _candidates)
			{
				float num2 = ResolveRadius(candidate.PrefabName, candidate.Position);
				if (num2 <= 0f)
				{
					continue;
				}
				RingEntry orCreateEntry = GetOrCreateEntry(candidate.Uid, candidate.PrefabName, candidate.Position, num2);
				if (orCreateEntry != null)
				{
					orCreateEntry.SeenThisTick = true;
					orCreateEntry.LastSeen = Time.time;
					if (!Mathf.Approximately(orCreateEntry.Radius, num2))
					{
						orCreateEntry.Projector.m_radius = num2;
						orCreateEntry.Radius = num2;
					}
					orCreateEntry.Root.SetActive(!flag);
					if (SunkenCryptTimerPlugin.CeDebug.Value)
					{
						SunkenCryptTimerPlugin.Log.LogDebug((object)$"ring {candidate.PrefabName} uid={candidate.Uid} r={num2:F1} dist={candidate.Distance:F0}m");
					}
				}
			}
			SweepUnseen();
		}
	}

	internal static void ClearAll()
	{
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
			_root = null;
		}
		_entries.Clear();
	}

	private static GameObject EnsureRoot()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		if ((Object)(object)_root != (Object)null)
		{
			return _root;
		}
		_entries.Clear();
		_template = null;
		_locationPrefabs = null;
		GameObject val = ZNetScene.instance.GetPrefab("piece_workbench") ?? ZNetScene.instance.GetPrefab("guard_stone");
		Transform val2 = (((Object)(object)val != (Object)null) ? val.transform.Find("AreaMarker") : null);
		if ((Object)(object)val2 == (Object)null)
		{
			if (!_templateWarned)
			{
				_templateWarned = true;
				SunkenCryptTimerPlugin.Log.LogWarning((object)"No AreaMarker template found (piece_workbench/guard_stone); zone rings disabled until the next world.");
			}
			return null;
		}
		_template = val2;
		_root = new GameObject("SunkenCryptTimer.Rings");
		SunkenCryptTimerPlugin.Log.LogInfo((object)("zone rings: template ready (" + ((Object)val).name + "/" + ((Object)val2).name + ")"));
		if (SunkenCryptTimerPlugin.CeDebug.Value)
		{
			SunkenCryptTimerPlugin.Log.LogDebug((object)("ring container created, template from " + ((Object)val).name));
		}
		return _root;
	}

	private static RingEntry GetOrCreateEntry(long uid, string prefabName, Vector3 position, float radius)
	{
		//IL_0049: 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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		if (_entries.TryGetValue(uid, out var value))
		{
			return value;
		}
		GameObject val = Object.Instantiate<GameObject>(((Component)_template).gameObject, _root.transform, false);
		((Object)val).name = $"Ring_{prefabName}_{uid}";
		val.transform.position = position;
		val.SetActive(false);
		foreach (Transform item in val.transform)
		{
			((Component)item).gameObject.SetActive(false);
		}
		CircleProjector component = val.GetComponent<CircleProjector>();
		component.m_radius = radius;
		value = new RingEntry
		{
			Root = val,
			Projector = component,
			Uid = uid,
			Radius = radius,
			LastSeen = Time.time
		};
		_entries[uid] = value;
		SunkenCryptTimerPlugin.Log.LogInfo((object)$"ring created: {prefabName} uid={uid} r={radius:F1}m at ({position.x:F0}, {position.z:F0})");
		return value;
	}

	private static float ResolveRadius(string prefabName, Vector3 featurePos)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		float num = ComputeRadius(prefabName, featurePos);
		if (_loggedRadius.Add(prefabName))
		{
			SunkenCryptTimerPlugin.Log.LogInfo((object)((num > 0f) ? $"ring radius: {prefabName} {num:F1}m" : ("ring radius: " + prefabName + " none (not an instanced dungeon or prefab unresolved)")));
		}
		return num;
	}

	private static float ComputeRadius(string prefabName, Vector3 featurePos)
	{
		//IL_0027: 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_005e: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		Location val = FindLocationPrefab(prefabName);
		if ((Object)(object)val == (Object)null || !val.m_hasInterior)
		{
			if ((Object)(object)val != (Object)null)
			{
				return 0f;
			}
			DungeonGenerator val2 = FindRootGenerator(featurePos, 120f);
			if (!((Object)(object)val2 != (Object)null) || !(((Component)val2).transform.position.y >= 4000f))
			{
				return 0f;
			}
			return HalfDiagonal(val2.m_zoneSize);
		}
		if (_radiusCache.TryGetValue(prefabName, out var value))
		{
			return value;
		}
		DungeonGenerator val3 = (((Object)(object)val.m_generator != (Object)null) ? val.m_generator : FindPrefabGenerator(val.m_interiorPrefab));
		float num = (((Object)(object)val3 != (Object)null) ? HalfDiagonal(val3.m_zoneSize) : val.m_interiorRadius);
		DungeonGenerator val4 = FindRootGenerator(featurePos, Mathf.Max(new float[3] { num, val.m_exteriorRadius, val.m_interiorRadius }));
		if ((Object)(object)val4 != (Object)null && ((Component)val4).transform.position.y >= 4000f)
		{
			float num2 = HalfDiagonal(val4.m_zoneSize);
			if (Mathf.Abs(num2 - num) > 0.25f)
			{
				if (SunkenCryptTimerPlugin.CeDebug.Value)
				{
					SunkenCryptTimerPlugin.Log.LogDebug((object)$"{prefabName}: live generator radius {num2:F1}m overrides prefab value {num:F1}m");
				}
				num = num2;
			}
			_radiusCache[prefabName] = num;
		}
		if (num <= 0.5f && _warnedPrefabs.Add(prefabName))
		{
			SunkenCryptTimerPlugin.Log.LogDebug((object)("no ring radius for " + prefabName + " (no generator on prefab)."));
		}
		return num;
	}

	private static DungeonGenerator FindPrefabGenerator(GameObject interiorPrefab)
	{
		if (!((Object)(object)interiorPrefab != (Object)null))
		{
			return null;
		}
		return interiorPrefab.GetComponentInChildren<DungeonGenerator>();
	}

	private static Location FindLocationPrefab(string name)
	{
		//IL_003a: 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)
		if (_locationPrefabs == null || !_locationPrefabs.ContainsKey(name))
		{
			_locationPrefabs = new Dictionary<string, Location>();
			foreach (ZoneLocation location in ZoneSystem.instance.m_locations)
			{
				SoftReference<GameObject> prefab = location.m_prefab;
				if (prefab.IsLoaded)
				{
					GameObject asset = prefab.Asset;
					Location val = (((Object)(object)asset != (Object)null) ? asset.GetComponent<Location>() : null);
					if ((Object)(object)val != (Object)null && !_locationPrefabs.ContainsKey(((Object)asset).name))
					{
						_locationPrefabs.Add(((Object)asset).name, val);
					}
				}
			}
		}
		if (_locationPrefabs.TryGetValue(name, out var value))
		{
			return value;
		}
		GameObject prefab2 = ZNetScene.instance.GetPrefab(name);
		if (!((Object)(object)prefab2 != (Object)null))
		{
			return null;
		}
		return prefab2.GetComponent<Location>();
	}

	internal static DungeonGenerator FindRootGenerator(Vector3 center, float bound)
	{
		//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_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)
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		foreach (GameObject val in rootGameObjects)
		{
			DungeonGenerator component = val.GetComponent<DungeonGenerator>();
			if ((Object)(object)component != (Object)null && Utils.DistanceXZ(val.transform.position, center) <= bound)
			{
				return component;
			}
		}
		return null;
	}

	private static float HalfDiagonal(Vector3 zoneSize)
	{
		//IL_0000: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = new Vector2(zoneSize.x * 0.5f, zoneSize.z * 0.5f);
		return ((Vector2)(ref val)).magnitude;
	}

	private static void SweepUnseen()
	{
		_sweep.Clear();
		foreach (RingEntry value in _entries.Values)
		{
			if (value.SeenThisTick)
			{
				value.SeenThisTick = false;
			}
			else if ((Object)(object)value.Root != (Object)null)
			{
				value.Root.SetActive(false);
				if (Time.time - value.LastSeen > 30f)
				{
					_sweep.Add(value);
				}
			}
			else
			{
				_sweep.Add(value);
			}
		}
		foreach (RingEntry item in _sweep)
		{
			if ((Object)(object)item.Root != (Object)null)
			{
				Object.Destroy((Object)(object)item.Root);
			}
			_entries.Remove(item.Uid);
		}
	}
}