Decompiled source of ExplorersVision v0.1.1

ExplorersVision.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Configs;
using ExplorersVision.Patches;
using HarmonyLib;
using Jotunn.Extensions;
using Jotunn.Utils;
using Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ExplorersVision")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExplorersVision")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08a6f7d7-cf93-4931-aecd-abf2ce6ed34c")]
[assembly: AssemblyFileVersion("0.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Logging
{
	internal static class Log
	{
		internal enum InfoLevel
		{
			Low,
			Medium,
			High
		}

		private static ManualLogSource logSource;

		internal static ConfigEntry<InfoLevel> Verbosity { get; set; }

		internal static InfoLevel VerbosityLevel => Verbosity.Value;

		internal static bool IsVerbosityLow => Verbosity.Value >= InfoLevel.Low;

		internal static bool IsVerbosityMedium => Verbosity.Value >= InfoLevel.Medium;

		internal static bool IsVerbosityHigh => Verbosity.Value >= InfoLevel.High;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			logSource.LogFatal(data);
		}

		internal static void LogMessage(object data)
		{
			logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			logSource.LogWarning(data);
		}

		internal static void LogInfo(object data, InfoLevel level = InfoLevel.Low)
		{
			if (Verbosity == null || VerbosityLevel >= level)
			{
				logSource.LogInfo(data);
			}
		}

		internal static void LogGameObject(GameObject prefab, bool includeChildren = false)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			LogInfo("***** " + ((Object)prefab).name + " *****");
			Component[] components = prefab.GetComponents<Component>();
			for (int i = 0; i < components.Length; i++)
			{
				LogComponent(components[i]);
			}
			if (!includeChildren)
			{
				return;
			}
			LogInfo("***** " + ((Object)prefab).name + " (children) *****");
			foreach (Transform item in prefab.transform)
			{
				Transform val = item;
				if (Object.op_Implicit((Object)(object)val))
				{
					LogInfo(" - " + ((Object)val).name);
					components = ((Component)val).GetComponents<Component>();
					for (int i = 0; i < components.Length; i++)
					{
						LogComponent(components[i]);
					}
				}
			}
		}

		internal static void LogComponent(Component compo)
		{
			if (!Object.op_Implicit((Object)(object)compo))
			{
				return;
			}
			try
			{
				LogInfo("--- " + ((object)compo).GetType().Name + ": " + ((Object)compo).name + " ---");
			}
			catch (Exception ex)
			{
				LogError(ex.ToString());
				LogWarning("Could not get type name for component!");
				return;
			}
			try
			{
				foreach (PropertyInfo declaredProperty in AccessTools.GetDeclaredProperties(((object)compo).GetType()))
				{
					try
					{
						LogInfo($" - {declaredProperty.Name} = {declaredProperty.GetValue(compo)}");
					}
					catch (Exception ex2)
					{
						LogError(ex2.ToString());
						LogWarning("Could not get property: " + declaredProperty.Name + " for component!");
					}
				}
			}
			catch (Exception ex3)
			{
				LogError(ex3.ToString());
				LogWarning("Could not get properties for component!");
			}
			try
			{
				foreach (FieldInfo declaredField in AccessTools.GetDeclaredFields(((object)compo).GetType()))
				{
					try
					{
						LogInfo($" - {declaredField.Name} = {declaredField.GetValue(compo)}");
					}
					catch (Exception ex4)
					{
						LogError(ex4.ToString());
						LogWarning("Could not get field: " + declaredField.Name + " for component!");
					}
				}
			}
			catch (Exception ex5)
			{
				LogError(ex5.ToString());
				LogWarning("Could not get fields for component!");
			}
		}
	}
}
namespace ExplorersVision
{
	[BepInPlugin("Searica.Valheim.ExplorersVision", "ExplorersVision", "0.1.1")]
	[BepInDependency("com.jotunn.jotunn", "2.23.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	internal sealed class ExplorersVision : BaseUnityPlugin
	{
		public const string PluginName = "ExplorersVision";

		internal const string Author = "Searica";

		public const string PluginGUID = "Searica.Valheim.ExplorersVision";

		public const string PluginVersion = "0.1.1";

		internal static ExplorersVision Instance;

		internal static ConfigFile ConfigFile;

		internal static ConfigFileWatcher ConfigFileWatcher;

		internal const string GlobalSection = "Global";

		internal const string MultiplierSection = "Multipliers";

		internal const string MiscSection = "Miscellaneous";

		public ConfigEntry<float> LandExploreRadius { get; private set; }

		public ConfigEntry<float> SeaExploreRadius { get; private set; }

		public ConfigEntry<float> AltitudeRadiusBonus { get; private set; }

		public ConfigEntry<float> ForestRadiusPenalty { get; private set; }

		public ConfigEntry<float> DaylightRadiusScale { get; private set; }

		public ConfigEntry<float> WeatherRadiusScale { get; private set; }

		public ConfigEntry<bool> DisplayCurrentRadiusValue { get; private set; }

		public ConfigEntry<bool> DisplayVariables { get; private set; }

		public void Awake()
		{
			Instance = this;
			ConfigFile = ((BaseUnityPlugin)this).Config;
			Log.Init(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Config.DisableSaveOnConfigSet();
			SetUpConfigEntries();
			((BaseUnityPlugin)this).Config.Save();
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Searica.Valheim.ExplorersVision");
			Game.isModded = true;
			ConfigFileWatcher = new ConfigFileWatcher(((BaseUnityPlugin)this).Config);
		}

		internal void SetUpConfigEntries()
		{
			LandExploreRadius = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Global", "LandExploreRadius", 150f, "The radius around the player to uncover while travelling on land near sea level. Higher values may cause performance issues. Game default is 100.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 1000f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			SeaExploreRadius = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Global", "SeaExploreRadius", 300f, "The radius around the player to uncover while travelling on a boat. Higher values may cause performance issues. Game default is 100.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 1000f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			AltitudeRadiusBonus = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Multipliers", "AltitudeRadiusBonus", 0.5f, "Bonus multiplier to apply to land exploration radius based on altitude. For every 100 units above sea level (smooth scale), add this value multiplied by LandExploreRadius to the total. For example, with a radius of 200 and a multiplier of 0.5, radius is 200 at sea level, 250 at 50 altitude, 300 at 100 altitude, 400 at 200 altitude, etc. For reference, a typical mountain peak is around 170 altitude. Set to 0 to disable.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			ForestRadiusPenalty = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Multipliers", "ForestRadiusPenalty", 0.3f, "Penalty to apply to land exploration radius when in a forest (black forest, forested parts of meadows and plains). This value is multiplied by the base land exploration radius and subtraced from the total. Set to 0 to disable.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			DaylightRadiusScale = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Multipliers", "DaylightRadiusScale", 0.2f, "Influences how much daylight (directional and ambient light) affects exploration radius. This value is multiplied by the base land or sea exploration radius and added to the total. Set to 0 to disable.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			WeatherRadiusScale = ConfigFileExtensions.BindConfigInOrder<float>(((BaseUnityPlugin)this).Config, "Multipliers", "WeatherRadiusScale", 0.5f, "Influences how much the current weather affects exploration radius. This value is multiplied by the base land or sea exploration radius and added to the total. Set to 0 to disable.", true, true, true, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			DisplayCurrentRadiusValue = ConfigFileExtensions.BindConfigInOrder<bool>(((BaseUnityPlugin)this).Config, "Miscellaneous", "DisplayCurrentRadiusValue", false, "Enabling this will display the currently computed exploration radius in the bottom left of the in-game Hud. Useful if you are trying to tweak config values and want to see the result.", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			DisplayCurrentRadiusValue.SettingChanged += UpdateDisplayRadiusText;
			DisplayVariables = ConfigFileExtensions.BindConfigInOrder<bool>(((BaseUnityPlugin)this).Config, "Miscellaneous", "DisplayVariables", false, "Enabling this will display on the Hud the values of various variables that go into calculating the exploration radius. Mostly useful for debugging and tweaking the config.", false, true, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			DisplayVariables.SettingChanged += UdpateDisplayVariablesText;
		}

		private void UpdateDisplayRadiusText(object sender, EventArgs e)
		{
			if (HudPatches.RadiusHudText != null)
			{
				((Component)HudPatches.RadiusHudText).gameObject.SetActive(DisplayVariables.Value);
				if (!DisplayVariables.Value)
				{
					HudPatches.RadiusHudText.text = string.Empty;
				}
			}
		}

		private void UdpateDisplayVariablesText(object sender, EventArgs e)
		{
			if (HudPatches.VariablesHudText != null)
			{
				((Component)HudPatches.VariablesHudText).gameObject.SetActive(DisplayVariables.Value);
				if (!DisplayVariables.Value)
				{
					HudPatches.VariablesHudText.text = string.Empty;
				}
			}
		}

		public void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}
	}
}
namespace ExplorersVision.Patches
{
	[HarmonyPatch]
	internal static class HudPatches
	{
		private const string Format = "+0.000;-0.000;0.000";

		private static GameObject RadiusGameObject;

		private static GameObject VariablesGameObject;

		public static Text RadiusHudText { get; private set; }

		public static Text VariablesHudText { get; private set; }

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hud), "Awake")]
		private static void CreateDisplayObjects(Hud __instance)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			if (!Object.op_Implicit((Object)(object)RadiusGameObject))
			{
				RadiusGameObject = new GameObject("ExplorersVision_RadiusHudText");
				RadiusGameObject.AddComponent<CanvasRenderer>();
				RadiusGameObject.transform.localPosition = Vector3.zero;
				RectTransform obj = RadiusGameObject.AddComponent<RectTransform>();
				((Transform)obj).SetParent(__instance.m_rootObject.transform);
				((Vector2)(ref val))..ctor(0f, 0f);
				obj.anchorMax = val;
				Vector2 pivot = (obj.anchorMin = val);
				obj.pivot = pivot;
				obj.offsetMin = new Vector2(10f, 5f);
				obj.offsetMax = new Vector2(210f, 165f);
				RadiusHudText = RadiusGameObject.AddComponent<Text>();
				((Graphic)RadiusHudText).raycastTarget = false;
				RadiusHudText.font = Font.CreateDynamicFontFromOSFont(new string[3] { "Segoe UI", "Helvetica", "Arial" }, 12);
				RadiusHudText.fontStyle = (FontStyle)1;
				((Graphic)RadiusHudText).color = Color.white;
				RadiusHudText.fontSize = 12;
				RadiusHudText.alignment = (TextAnchor)6;
				((Shadow)RadiusGameObject.AddComponent<Outline>()).effectColor = Color.black;
				RadiusGameObject.SetActive(ExplorersVision.Instance.DisplayCurrentRadiusValue.Value);
			}
			if (!Object.op_Implicit((Object)(object)VariablesGameObject))
			{
				VariablesGameObject = new GameObject("ExplorersVision_VariablesHudText");
				VariablesGameObject.AddComponent<CanvasRenderer>();
				VariablesGameObject.transform.localPosition = Vector3.zero;
				RectTransform obj2 = VariablesGameObject.AddComponent<RectTransform>();
				((Transform)obj2).SetParent(__instance.m_rootObject.transform);
				((Vector2)(ref val))..ctor(0f, 0f);
				obj2.anchorMax = val;
				Vector2 pivot = (obj2.anchorMin = val);
				obj2.pivot = pivot;
				obj2.offsetMin = new Vector2(240f, 5f);
				obj2.offsetMax = new Vector2(440f, 165f);
				VariablesHudText = VariablesGameObject.AddComponent<Text>();
				((Graphic)VariablesHudText).raycastTarget = false;
				VariablesHudText.font = Font.CreateDynamicFontFromOSFont(new string[3] { "Segoe UI", "Helvetica", "Arial" }, 12);
				VariablesHudText.fontStyle = (FontStyle)1;
				((Graphic)VariablesHudText).color = Color.white;
				VariablesHudText.fontSize = 12;
				VariablesHudText.alignment = (TextAnchor)6;
				((Shadow)VariablesGameObject.AddComponent<Outline>()).effectColor = Color.black;
				VariablesGameObject.SetActive(ExplorersVision.Instance.DisplayVariables.Value);
			}
		}

		public static void SetDisplayRadiusText(float radius)
		{
			if (ExplorersVision.Instance.DisplayCurrentRadiusValue.Value)
			{
				RadiusHudText.text = $"Dynamic Radius: {radius:0.0}";
			}
		}

		public static void SetDisplayVariablesText(float radius, float baseRadius, float multiplier, float light, float weather, float altitude, float environment)
		{
			if (ExplorersVision.Instance.DisplayVariables.Value)
			{
				VariablesHudText.text = "Dynamic Variables\n" + $"Radius: {radius:0.0}\n" + $"Base: {baseRadius:0.#}\n" + $"Multiplier: {multiplier:0.000}\n\n" + "Light: " + light.ToString("+0.000;-0.000;0.000") + "\nWeather: " + weather.ToString("+0.000;-0.000;0.000") + "\nAltitude: " + altitude.ToString("+0.000;-0.000;0.000") + "\nEnvironment: " + environment.ToString("+0.000;-0.000;0.000") + "\n";
			}
		}
	}
	[HarmonyPatch]
	internal static class MapRadiusPatches
	{
		[HarmonyPrefix]
		[HarmonyPriority(200)]
		[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
		private static void AdjustExploreRadius_Prefix(Minimap __instance, out float __state)
		{
			__state = __instance.m_exploreRadius;
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				__instance.m_exploreRadius = GetExploreRadius(Player.m_localPlayer);
			}
		}

		[HarmonyPostfix]
		[HarmonyPriority(600)]
		[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
		private static void AdjustExploreRadius_Postfix(Minimap __instance, ref float __state)
		{
			__instance.m_exploreRadius = __state;
		}

		private static float GetExploreRadius(Player player)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			if (((Character)player).InInterior())
			{
				float num = Mathf.Max(ExplorersVision.Instance.LandExploreRadius.Value * 0.2f, 10f);
				HudPatches.SetDisplayRadiusText(num);
				return num;
			}
			float num2 = 1f;
			Ship localShip = Ship.GetLocalShip();
			float num3 = ((!Object.op_Implicit((Object)(object)localShip) || !localShip.IsPlayerInBoat(player)) ? ExplorersVision.Instance.LandExploreRadius.Value : ExplorersVision.Instance.SeaExploreRadius.Value);
			float num4 = Mathf.Max(GetColorMagnitude(EnvMan.instance.m_dirLight.color * EnvMan.instance.m_dirLight.intensity), GetColorMagnitude(RenderSettings.ambientLight));
			float num5 = (num4 - 1f) * ExplorersVision.Instance.DaylightRadiusScale.Value;
			num2 += num5;
			float num6 = 0f;
			GameObject[] psystems = EnvMan.instance.GetCurrentEnvironment().m_psystems;
			foreach (GameObject obj in psystems)
			{
				if (((Object)obj).name.Equals("Mist", StringComparison.InvariantCultureIgnoreCase))
				{
					num6 += 0.5f;
				}
				if (((Object)obj).name.Equals("SnowStorm", StringComparison.InvariantCultureIgnoreCase))
				{
					num6 += 0.7f * num4;
				}
			}
			float num7 = (0f - Mathf.Clamp(RenderSettings.fogDensity * 10f + num6, 0f, 1.5f)) * ExplorersVision.Instance.WeatherRadiusScale.Value;
			num2 += num7;
			float num8 = Mathf.Clamp(((Component)player).transform.position.y - ZoneSystem.instance.m_waterLevel, 0f, 400f) / 100f * Mathf.Max(0.05f, 1f - num6);
			float num9 = num8 * ExplorersVision.Instance.AltitudeRadiusBonus.Value;
			num2 += num9;
			float environementModifier = GetEnvironementModifier(player, num8);
			num2 += environementModifier;
			num2 = Mathf.Clamp(num2, 0.2f, 5f);
			float num10 = Mathf.Clamp(num3 * num2, 20f, 2000f);
			HudPatches.SetDisplayRadiusText(num10);
			HudPatches.SetDisplayVariablesText(num10, num3, num2, num5, num7, num9, environementModifier);
			return num10;
		}

		private static float GetColorMagnitude(Color color)
		{
			//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_000d: 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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Sqrt(color.r * color.r + color.g * color.g + color.b * color.b);
		}

		private static float GetEnvironementModifier(Player player, float altitude)
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_005d: 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_0035: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			float num = ExplorersVision.Instance.ForestRadiusPenalty.Value * (1f + altitude * ExplorersVision.Instance.AltitudeRadiusBonus.Value);
			Biome currentBiome = player.GetCurrentBiome();
			if ((int)currentBiome != 1)
			{
				if ((int)currentBiome != 8)
				{
					if ((int)currentBiome == 16)
					{
						float value = ExplorersVision.Instance.DaylightRadiusScale.Value;
						return ((WorldGenerator.GetForestFactor(((Component)player).transform.position) < 0.8f) ? (0f - num) : 0f) + 0.1f * value;
					}
					return 0f;
				}
				return 0f - num - 0.25f * ExplorersVision.Instance.DaylightRadiusScale.Value;
			}
			if (!WorldGenerator.InForest(((Component)player).transform.position))
			{
				return 0f;
			}
			return 0f - num;
		}
	}
}
namespace Configs
{
	public static class ConfigFileExtensions
	{
		public static bool DisableSaveOnConfigSet(this ConfigFile configFile)
		{
			bool saveOnConfigSet = configFile.SaveOnConfigSet;
			configFile.SaveOnConfigSet = false;
			return saveOnConfigSet;
		}
	}
	internal sealed class ConfigFileWatcher
	{
		private const long RELOAD_DELAY = 10000000L;

		private DateTime lastReadTime = DateTime.MinValue;

		private readonly ConfigFile configFile;

		private readonly string ConfigFileDir;

		private readonly string ConfigFileName;

		internal event Action OnConfigFileReloaded;

		internal ConfigFileWatcher(ConfigFile configFile)
		{
			this.configFile = configFile;
			ConfigFileDir = Directory.GetParent(configFile.ConfigFilePath).FullName;
			ConfigFileName = Path.GetFileName(configFile.ConfigFilePath);
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(ConfigFileDir, ConfigFileName);
			fileSystemWatcher.Changed += ReloadConfigFile;
			fileSystemWatcher.Created += ReloadConfigFile;
			fileSystemWatcher.Renamed += ReloadConfigFile;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void InvokeOnConfigFileReloaded()
		{
			this.OnConfigFileReloaded?.SafeInvoke();
		}

		internal void ReloadConfigFile(object sender, FileSystemEventArgs eventArgs)
		{
			DateTime now = DateTime.Now;
			long num = now.Ticks - lastReadTime.Ticks;
			if (!File.Exists(configFile.ConfigFilePath) || num < 10000000)
			{
				return;
			}
			try
			{
				Log.LogInfo("Reloading " + configFile.ConfigFilePath);
				bool saveOnConfigSet = configFile.DisableSaveOnConfigSet();
				configFile.Reload();
				configFile.SaveOnConfigSet = saveOnConfigSet;
				lastReadTime = now;
				InvokeOnConfigFileReloaded();
			}
			catch
			{
				Log.LogError("There was an issue loading " + configFile.ConfigFilePath);
				Log.LogError("Please check your config entries for spelling and format!");
			}
		}
	}
	internal static class SafeInvokeEvent
	{
		internal static void SafeInvoke(this Action events)
		{
			if (events == null)
			{
				return;
			}
			Delegate[] invocationList = events.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action action = (Action)invocationList[i];
				try
				{
					action();
				}
				catch (Exception arg)
				{
					Log.LogWarning("Exception thrown at event " + new StackFrame(1).GetMethod().Name + $" in {action.Method.DeclaringType.Name}.{action.Method.Name}:\n{arg}");
				}
			}
		}
	}
}