Decompiled source of WeatherRegistry v0.7.4

WeatherRegistry.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConsoleTables;
using GameNetcodeStuff;
using HarmonyLib;
using Imperium.API.Types.Networking;
using JLL.Components;
using LethalLib.Modules;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Malfunctions;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using MrovLib;
using MrovLib.Compatibility;
using MrovLib.Events;
using Newtonsoft.Json;
using On;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using WeatherRegistry.Algorithms;
using WeatherRegistry.Compatibility;
using WeatherRegistry.Definitions;
using WeatherRegistry.Editor;
using WeatherRegistry.Events;
using WeatherRegistry.Managers;
using WeatherRegistry.Modules;
using WeatherRegistry.NetcodePatcher;
using WeatherRegistry.Networking;
using WeatherRegistry.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Malfunctions")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("WeatherRegistry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Weather API for Lethal Company.")]
[assembly: AssemblyFileVersion("0.7.4.0")]
[assembly: AssemblyInformationalVersion("0.7.4+63966697fb0a71e451228a5f1a74bff49cc2296a")]
[assembly: AssemblyProduct("WeatherRegistry")]
[assembly: AssemblyTitle("WeatherRegistry")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/AndreyMrovol/LethalWeatherRegistry/")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<WeatherSyncDataWrapper>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<WeatherSyncDataWrapper>();
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<WeatherEffectDataWrapper>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<WeatherEffectDataWrapper>();
		NetworkVariableSerializationTypes.InitializeSerializer_FixedString<FixedString4096Bytes>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<FixedString4096Bytes>();
	}
}
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 WeatherRegistry
{
	public class AssetBundleLoader
	{
		internal static DirectoryInfo pluginsFolder = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.Parent;

		private static Dictionary<string, AssetBundle> LoadedBundles = new Dictionary<string, AssetBundle>();

		private static List<EffectOverride> LoadedEffectOverrides = new List<EffectOverride>();

		private static List<PlanetNameOverride> LoadedPlanetNameOverrides = new List<PlanetNameOverride>();

		private static List<ModdedWeathersMatcher> LoadedModdedWeathersMatchers = new List<ModdedWeathersMatcher>();

		private static readonly Logger Logger = new Logger("AssetBundleLoader", (LoggingType)1);

		internal static void LoadAssetBundles()
		{
			string fullName = pluginsFolder.FullName;
			if (!Directory.Exists(fullName))
			{
				((Logger)Logger).LogWarning("AssetBundles folder not found: " + fullName);
				return;
			}
			LoadAllBundlesInFolder(fullName);
			((Logger)Logger).LogCustom(string.Format("Loaded {0} weather definitions from asset bundles: [{1}]", WeatherManager.RegisteredWeathers.Count, string.Join(", ", WeatherManager.RegisteredWeathers.Select((Weather w) => w.Name))), (LogLevel)16, (LoggingType)0);
		}

		private static void LoadAllBundlesInFolder(string bundlesPath)
		{
			string[] files = Directory.GetFiles(bundlesPath, "*.weatherbundle", SearchOption.AllDirectories);
			string[] array = files;
			foreach (string text in array)
			{
				string fileName = Path.GetFileName(text);
				LoadBundle(text, fileName);
			}
		}

		private static void LoadBundle(string bundlePath, string bundleName)
		{
			try
			{
				AssetBundle val = AssetBundle.LoadFromFile(bundlePath);
				if ((Object)(object)val == (Object)null)
				{
					((Logger)Logger).LogError("Failed to load asset bundle: " + bundleName);
					return;
				}
				LoadedBundles[bundleName] = val;
				((Logger)Logger).LogInfo("Loaded asset bundle: " + bundleName);
				LoadWeatherFromBundle(val, bundleName);
			}
			catch (Exception ex)
			{
				((Logger)Logger).LogError("Error loading bundle " + bundleName + ": " + ex.Message);
			}
		}

		private static void LoadWeatherFromBundle(AssetBundle bundle, string bundleName)
		{
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			string[] allAssetNames = bundle.GetAllAssetNames();
			((Logger)Logger).LogInfo($"Bundle {bundleName} contains {allAssetNames.Length} assets");
			WeatherDefinition[] array = bundle.LoadAllAssets<WeatherDefinition>();
			LoadedEffectOverrides.AddRange(bundle.LoadAllAssets<EffectOverride>().ToList());
			LoadedPlanetNameOverrides.AddRange(bundle.LoadAllAssets<PlanetNameOverride>().ToList());
			LoadedModdedWeathersMatchers.AddRange(bundle.LoadAllAssets<ModdedWeathersMatcher>().ToList());
			WeatherDefinition[] array2 = array;
			foreach (WeatherDefinition weatherDefinition in array2)
			{
				GameObject val = null;
				if ((Object)(object)weatherDefinition.Effect.EffectObject != (Object)null)
				{
					val = Object.Instantiate<GameObject>(weatherDefinition.Effect.EffectObject);
					if ((Object)(object)val != (Object)null)
					{
						((Object)val).hideFlags = (HideFlags)61;
						Object.DontDestroyOnLoad((Object)(object)val);
					}
				}
				GameObject val2 = null;
				if ((Object)(object)weatherDefinition.Effect.WorldObject != (Object)null)
				{
					val2 = Object.Instantiate<GameObject>(weatherDefinition.Effect.WorldObject);
					if ((Object)(object)val2 != (Object)null)
					{
						((Object)val2).hideFlags = (HideFlags)61;
						Object.DontDestroyOnLoad((Object)(object)val2);
					}
				}
				ImprovedWeatherEffect effect = new ImprovedWeatherEffect(val, val2)
				{
					SunAnimatorBool = weatherDefinition.Effect.SunAnimatorBool,
					DefaultVariable1 = weatherDefinition.Effect.DefaultVariable1,
					DefaultVariable2 = weatherDefinition.Effect.DefaultVariable2
				};
				Weather obj = new Weather(weatherDefinition.Name, effect)
				{
					Color = weatherDefinition.Color,
					Origin = WeatherOrigin.WeatherRegistry,
					Type = WeatherType.Modded,
					Config = weatherDefinition.Config.CreateFullConfig()
				};
				((Object)obj).hideFlags = (HideFlags)61;
				Weather weather = obj;
				Object.DontDestroyOnLoad((Object)(object)weather);
				WeatherManager.RegisterWeather(weather);
			}
		}

		public static void LoadWeatherOverrides()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			foreach (EffectOverride loadedEffectOverride in LoadedEffectOverrides)
			{
				if ((Object)(object)loadedEffectOverride == (Object)null || string.IsNullOrEmpty(loadedEffectOverride.weatherName))
				{
					((Logger)Logger).LogWarning("EffectOverride is null or has no weatherName, skipping.");
					continue;
				}
				Weather weather = ConfigHelper.ResolveStringToWeather(loadedEffectOverride.weatherName);
				if ((Object)(object)weather == (Object)null)
				{
					((Logger)Logger).LogWarning("Weather " + loadedEffectOverride.weatherName + " not found, skipping EffectOverride.");
					continue;
				}
				SelectableLevel[] array = ConfigHelper.ConvertStringToLevels(loadedEffectOverride.levelName);
				ImprovedWeatherEffect overrideEffect = loadedEffectOverride.OverrideEffect;
				PlanetNameOverride planetNameOverride = LoadedPlanetNameOverrides.Where((PlanetNameOverride o) => (Object)(object)o.effectOverride == (Object)(object)overrideEffect).First();
				SelectableLevel[] array2 = array;
				foreach (SelectableLevel level in array2)
				{
					WeatherEffectOverride key = new WeatherEffectOverride(weather, level, overrideEffect, loadedEffectOverride.weatherDisplayName, loadedEffectOverride.weatherDisplayColor);
					if ((Object)(object)planetNameOverride != (Object)null && !string.IsNullOrEmpty(planetNameOverride.newPlanetName))
					{
						WeatherOverrideManager.PlanetOverrideNames.Add(key, planetNameOverride.newPlanetName);
					}
				}
			}
		}

		public static void LoadModdedWeathersMatchers()
		{
			foreach (ModdedWeathersMatcher loadedModdedWeathersMatcher in LoadedModdedWeathersMatchers)
			{
				if ((Object)(object)loadedModdedWeathersMatcher == (Object)null || loadedModdedWeathersMatcher.Weathers == null || (Object)(object)loadedModdedWeathersMatcher.Level == (Object)null || loadedModdedWeathersMatcher.Weathers.Length == 0)
				{
					((Logger)Logger).LogWarning("ModdedWeathersMatcher " + ((Object)loadedModdedWeathersMatcher).name + " is null or has no weathers!");
					continue;
				}
				SelectableLevel level = loadedModdedWeathersMatcher.Level;
				loadedModdedWeathersMatcher.Weathers.ToList().ForEach(delegate(WeatherMatchingProperties weather)
				{
					Weather weather2 = ConfigHelper.ResolveStringToWeather(weather.Name);
					int defaultLevelWeight = weather.DefaultLevelWeight;
					if ((Object)(object)weather2 == (Object)null)
					{
						((Logger)Logger).LogDebug("Weather " + weather.Name + " not found!");
					}
					else
					{
						LevelRarity[] value = ((ConfigHandler<LevelRarity[], string>)weather2.Config.LevelWeights).Value;
						List<SelectableLevel> source = value.Select((LevelRarity rarity) => rarity.Level).ToList();
						List<string> list = source.Select((SelectableLevel planet) => planet.PlanetName).ToList();
						if (!list.Contains(level.PlanetName))
						{
							((Logger)Logger).LogDebug("Level " + level.PlanetName + " not found in " + weather2.Name);
							if (weather2.Config.LevelWeights.ConfigEntryActive)
							{
								((Logger)Logger).LogDebug($"Adding {level.PlanetName} to {weather2.Name} with weight {defaultLevelWeight}");
								ConfigEntry<string> configEntry = ((ConfigHandler<LevelRarity[], string>)weather2.Config.LevelWeights).ConfigEntry;
								configEntry.Value += $";{ConfigHelper.GetAlphanumericName(level)}@{defaultLevelWeight};";
							}
						}
						else
						{
							((Logger)Logger).LogDebug("Level " + level.PlanetName + " already exists in " + weather2.Name + " LevelWeights, skipping.");
						}
					}
				});
			}
		}
	}
	public class Rarity
	{
		private int _weight;

		public int Weight
		{
			get
			{
				return _weight;
			}
			set
			{
				_weight = Math.Clamp(value, 0, 10000);
			}
		}
	}
	public class NameRarity : Rarity
	{
		public string Name { get; set; }
	}
	public class LevelRarity : Rarity
	{
		public SelectableLevel Level { get; set; }
	}
	public class WeatherRarity : Rarity
	{
		public Weather Weather { get; set; }
	}
	public abstract class ConfigHandler<T, CT> : WeatherRegistry.Definitions.ConfigHandler<T, CT>
	{
		public ConfigFile ConfigFile { get; set; } = ConfigManager.configFile;


		public ConfigHandler(CT value, bool enabled = true)
		{
			((ConfigHandler<T, CT>)this).DefaultValue = value;
			base.Enabled = enabled;
		}

		public void SetConfigEntry(Weather weather, string configTitle, ConfigDescription configDescription = null)
		{
			if (base.Enabled)
			{
				((ConfigHandler<T, CT>)this).ConfigEntry = ConfigFile.Bind<CT>(ConfigHelper.CleanStringForConfig(weather.ConfigCategory), ConfigHelper.CleanStringForConfig(configTitle), ((ConfigHandler<T, CT>)this).DefaultValue, configDescription);
				return;
			}
			((ConfigHandler<T, CT>)this).ConfigEntry = null;
			((Logger)Plugin.debugLogger).LogDebug("Config entry for " + weather.Name + ": " + configTitle + " is disabled");
		}

		public void SetConfigEntry(string configCategory, string configTitle, ConfigDescription configDescription = null)
		{
			if (base.Enabled)
			{
				((ConfigHandler<T, CT>)this).ConfigEntry = ConfigFile.Bind<CT>(ConfigHelper.CleanStringForConfig(configCategory), ConfigHelper.CleanStringForConfig(configTitle), ((ConfigHandler<T, CT>)this).DefaultValue, configDescription);
				return;
			}
			((ConfigHandler<T, CT>)this).ConfigEntry = null;
			((Logger)Plugin.debugLogger).LogDebug("Config entry " + configTitle + " is disabled");
		}
	}
	public class LevelListConfigHandler : ConfigHandler<SelectableLevel[], string>
	{
		public override SelectableLevel[] Value => ConfigHelper.ConvertStringToLevels(base.ConfigEntryActive ? ((ConfigHandler<SelectableLevel[], string>)this).ConfigEntry.Value : ((ConfigHandler<SelectableLevel[], string>)this).DefaultValue);

		public LevelListConfigHandler(string value, bool enabled = true)
			: base(value, enabled)
		{
		}

		public LevelListConfigHandler(string[] value, bool enabled = true)
			: base(string.Join(";", value), enabled)
		{
		}
	}
	public class LevelWeightsConfigHandler : ConfigHandler<LevelRarity[], string>
	{
		public override LevelRarity[] Value => ConfigHelper.ConvertStringToLevelRarities(base.ConfigEntryActive ? ((ConfigHandler<LevelRarity[], string>)this).ConfigEntry.Value : ((ConfigHandler<LevelRarity[], string>)this).DefaultValue);

		public LevelWeightsConfigHandler(string value, bool enabled = true)
			: base(value, enabled)
		{
		}

		public LevelWeightsConfigHandler(string[] value, bool enabled = true)
			: base(string.Join(";", value), enabled)
		{
		}
	}
	public class WeatherWeightsConfigHandler : ConfigHandler<WeatherRarity[], string>
	{
		public override WeatherRarity[] Value => ConfigHelper.ConvertStringToWeatherWeights(base.ConfigEntryActive ? ((ConfigHandler<WeatherRarity[], string>)this).ConfigEntry.Value : ((ConfigHandler<WeatherRarity[], string>)this).DefaultValue);

		public WeatherWeightsConfigHandler(string value, bool enabled = true)
			: base(value, enabled)
		{
		}

		public WeatherWeightsConfigHandler(string[] value, bool enabled = true)
			: base(string.Join(";", value), enabled)
		{
		}
	}
	public class BooleanConfigHandler : ConfigHandler<bool, bool>
	{
		public override bool Value
		{
			get
			{
				if (!base.ConfigEntryActive)
				{
					return ((ConfigHandler<bool, bool>)this).DefaultValue;
				}
				return ((ConfigHandler<bool, bool>)this).ConfigEntry.Value;
			}
		}

		public BooleanConfigHandler(bool value, bool enabled = true)
			: base(value, enabled)
		{
		}

		public BooleanConfigHandler(FilteringOption filteringOption, bool enabled = true)
			: base(filteringOption == FilteringOption.Include, enabled)
		{
		}
	}
	public class IntegerConfigHandler : ConfigHandler<int, int>
	{
		public override int Value
		{
			get
			{
				if (!base.ConfigEntryActive)
				{
					return ((ConfigHandler<int, int>)this).DefaultValue;
				}
				return ((ConfigHandler<int, int>)this).ConfigEntry.Value;
			}
		}

		public IntegerConfigHandler(int value, bool enabled = true)
			: base(value, enabled)
		{
		}
	}
	public class FloatConfigHandler : ConfigHandler<float, float>
	{
		public override float Value
		{
			get
			{
				if (!base.ConfigEntryActive)
				{
					return ((ConfigHandler<float, float>)this).DefaultValue;
				}
				return ((ConfigHandler<float, float>)this).ConfigEntry.Value;
			}
		}

		public FloatConfigHandler(float value, bool enabled = true)
			: base(value, enabled)
		{
		}
	}
	public class StringConfigHandler : ConfigHandler<string, string>
	{
		public override string Value
		{
			get
			{
				if (!base.ConfigEntryActive)
				{
					return ((ConfigHandler<string, string>)this).DefaultValue;
				}
				return ((ConfigHandler<string, string>)this).ConfigEntry.Value;
			}
		}

		public StringConfigHandler(string value, bool enabled = true)
			: base(value, enabled)
		{
		}
	}
	public class ConfigHelper
	{
		private static Logger logger = new Logger("ConfigHelper", (LoggingType)1);

		private static readonly Regex ConfigCleanerRegex = new Regex("[\\n\\t\"`\\[\\]']");

		private static Dictionary<string, Weather> _weathersDictionary = null;

		public static Dictionary<string, Weather> StringToWeather
		{
			get
			{
				if (_weathersDictionary != null)
				{
					return _weathersDictionary;
				}
				Dictionary<string, Weather> Weathers = new Dictionary<string, Weather>();
				WeatherManager.Weathers.ToList().ForEach(delegate(Weather weather)
				{
					Weathers.TryAdd(((Object)weather).name.ToLowerInvariant(), weather);
					Weathers.TryAdd(weather.Name.ToLowerInvariant(), weather);
					Weathers.TryAdd(GetAlphanumericName(weather).ToLowerInvariant(), weather);
				});
				_weathersDictionary = Weathers;
				return Weathers;
			}
			set
			{
				_weathersDictionary = value;
			}
		}

		internal static string CleanStringForConfig(string input)
		{
			return ConfigCleanerRegex.Replace(input, string.Empty).Trim();
		}

		public static Weather ResolveStringToWeather(string str)
		{
			return StringToWeather.GetValueOrDefault(str.ToLowerInvariant());
		}

		public static List<Weather> ResolveStringToWeathers(string str)
		{
			if (string.IsNullOrWhiteSpace(str))
			{
				return new List<Weather>();
			}
			string[] array = ConvertStringToArray(str);
			List<Weather> list = new List<Weather>();
			string[] array2 = array;
			foreach (string text in array2)
			{
				Weather weather = ResolveStringToWeather(text);
				if ((Object)(object)weather != (Object)null)
				{
					list.Add(weather);
				}
				else
				{
					((Logger)logger).LogWarning("Invalid weather name: " + text);
				}
			}
			return list;
		}

		public static string GetNumberlessName(SelectableLevel level)
		{
			return StringResolver.GetNumberlessName(level);
		}

		public static string GetAlphanumericName(SelectableLevel level)
		{
			Regex regex = new Regex("^[0-9]+|[-_/\\\\\\ ]");
			return new string(regex.Replace(level.PlanetName, ""));
		}

		public static string GetAlphanumericName(Weather weather)
		{
			Regex regex = new Regex("^[0-9]+|[-_/\\\\\\ ]");
			return new string(regex.Replace(weather.Name, ""));
		}

		public static string[] ConvertStringToArray(string str)
		{
			return (from s in str.Split(';')
				where !string.IsNullOrWhiteSpace(s)
				select s.Trim()).ToArray();
		}

		public static SelectableLevel[] ConvertStringToLevels(string str)
		{
			return StringResolver.ResolveStringToLevels(str);
		}

		public static NameRarity[] ConvertStringToRarities(string str)
		{
			string[] array = ConvertStringToArray(str);
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split('@');
				if (array3.Length == 2 && int.TryParse(array3[1], out var result))
				{
					string key = array3[0].Trim();
					if (!dictionary.ContainsKey(key))
					{
						dictionary.Add(key, result);
					}
				}
			}
			return dictionary.Select((KeyValuePair<string, int> rarity) => new NameRarity
			{
				Name = rarity.Key,
				Weight = rarity.Value
			}).ToArray();
		}

		public static LevelRarity[] ConvertStringToLevelRarities(string str)
		{
			Dictionary<SelectableLevel, int> dictionary = new Dictionary<SelectableLevel, int>();
			NameRarity[] array = ConvertStringToRarities(str);
			NameRarity[] array2 = array;
			foreach (NameRarity nameRarity in array2)
			{
				SelectableLevel[] array3 = StringResolver.ResolveStringToLevels(nameRarity.Name);
				SelectableLevel[] array4 = array3;
				foreach (SelectableLevel val in array4)
				{
					if (!((Object)(object)val == (Object)null))
					{
						dictionary.TryAdd(val, nameRarity.Weight);
					}
				}
			}
			return dictionary.Select((KeyValuePair<SelectableLevel, int> rarity) => new LevelRarity
			{
				Level = rarity.Key,
				Weight = rarity.Value
			}).ToArray();
		}

		public static WeatherRarity[] ConvertStringToWeatherWeights(string str)
		{
			Dictionary<Weather, int> dictionary = new Dictionary<Weather, int>();
			NameRarity[] array = ConvertStringToRarities(str);
			NameRarity[] array2 = array;
			foreach (NameRarity nameRarity in array2)
			{
				Weather weather = ResolveStringToWeather(nameRarity.Name);
				if (!((Object)(object)weather == (Object)null))
				{
					dictionary.TryAdd(weather, nameRarity.Weight);
				}
			}
			return dictionary.Select((KeyValuePair<Weather, int> rarity) => new WeatherRarity
			{
				Weather = rarity.Key,
				Weight = rarity.Value
			}).ToArray();
		}
	}
	internal class ConfigManager
	{
		internal static ConfigFile configFile;

		internal static ConfigManager Instance { get; private set; }

		internal static ConfigEntry<LoggingType> LoggingLevels { get; private set; }

		internal static ConfigEntry<WeatherCalculation.WeatherAlgorithm> WeatherAlgorithm { get; private set; }

		internal static ConfigEntry<bool> ColoredWeathers { get; private set; }

		internal static ConfigEntry<bool> PlanetVideos { get; private set; }

		internal static ConfigEntry<bool> ShowWeatherMultipliers { get; private set; }

		internal static ConfigEntry<bool> UseScrapMultipliers { get; private set; }

		internal static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}

		private ConfigManager(ConfigFile config)
		{
			configFile = config;
			LoggingLevels = configFile.Bind<LoggingType>("|Logging", "Display Log Levels", (LoggingType)0, "Select which logs to show.");
			WeatherAlgorithm = configFile.Bind<WeatherCalculation.WeatherAlgorithm>("|WeatherSelection", "Weather Selection Algorithm", WeatherCalculation.WeatherAlgorithm.Registry, "Select the algorithm to use during weather selection.");
			ColoredWeathers = configFile.Bind<bool>("|General", "Colored Weathers", true, "Enable colored weathers on map screen");
			PlanetVideos = configFile.Bind<bool>("|General", "Planet Videos", true, "Display planet videos on map screen");
			ShowWeatherMultipliers = configFile.Bind<bool>("|General", "Show Weather Multipliers", false, "Show weather multipliers on map screen");
			UseScrapMultipliers = configFile.Bind<bool>("|General", "Scrap multipliers", true, "Use Registry's scrap multipliers. Disable if you prefer to use other mod's multiplier settings.");
		}

		internal void RemoveOrphanedEntries()
		{
			Plugin.logger.LogInfo((object)"Removing orphaned config entries...");
			PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> orphanedEntries = (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
			List<KeyValuePair<ConfigDefinition, string>> list = orphanedEntries.Where((KeyValuePair<ConfigDefinition, string> entry) => entry.Key.Section.Contains("|")).ToList();
			Plugin.logger.LogWarning((object)$"Found {list.Count} orphaned config entries.");
			list.ForEach(delegate(KeyValuePair<ConfigDefinition, string> entry)
			{
				((Logger)Plugin.debugLogger).LogWarning("Removing orphaned config entry: " + entry.Key.Section + " - " + entry.Key.Key);
				orphanedEntries.Remove(entry.Key);
			});
			configFile.Save();
		}
	}
	internal class Defaults
	{
		internal static List<LevelWeatherType> VanillaWeathers = Defaults.VanillaWeathers;

		internal static Dictionary<LevelWeatherType, Color> VanillaWeatherColors = new Dictionary<LevelWeatherType, Color>
		{
			{
				(LevelWeatherType)(-1),
				new Color(0.41f, 1f, 0.42f, 1f)
			},
			{
				(LevelWeatherType)0,
				new Color(0.62f, 0.4f, 0.42f, 1f)
			},
			{
				(LevelWeatherType)3,
				new Color(1f, 0.86f, 0f, 1f)
			},
			{
				(LevelWeatherType)1,
				new Color(1f, 0.86f, 0f, 1f)
			},
			{
				(LevelWeatherType)2,
				new Color(1f, 0.57f, 0f, 1f)
			},
			{
				(LevelWeatherType)4,
				new Color(1f, 0.57f, 0f, 1f)
			},
			{
				(LevelWeatherType)5,
				new Color(1f, 0f, 0f, 1f)
			}
		};

		internal static Dictionary<LevelWeatherType, string> VanillaWeatherToWeatherWeights = new Dictionary<LevelWeatherType, string>
		{
			{
				(LevelWeatherType)(-1),
				"None@160; Rainy@100; Stormy@70; Flooded@20; Foggy@40; Eclipsed@10"
			},
			{
				(LevelWeatherType)1,
				"None@100; Rainy@60; Stormy@40; Flooded@30; Foggy@50; Eclipsed@20"
			},
			{
				(LevelWeatherType)2,
				"None@160; Rainy@110; Stormy@10; Flooded@120; Foggy@20; Eclipsed@80"
			},
			{
				(LevelWeatherType)4,
				"None@160; Rainy@60; Stormy@50; Flooded@10; Foggy@60; Eclipsed@40"
			},
			{
				(LevelWeatherType)3,
				"None@200; Rainy@60; Stormy@50; Flooded@10; Foggy@30; Eclipsed@20"
			},
			{
				(LevelWeatherType)5,
				"None@300; Rainy@40; Stormy@16; Flooded@20; Foggy@60; Eclipsed@10"
			}
		};

		public static readonly string DefaultLevelFilters = "Company";

		public static readonly string DefaultLevelWeights = "MoonName@50";

		public static readonly string DefaultWeatherToWeatherWeights = "WeatherName@50";

		public static readonly int DefaultWeight = 100;

		public static readonly float ScrapAmountMultiplier = 1f;

		public static readonly float ScrapValueMultiplier = 1f;

		public static readonly FilteringOption FilteringOption = FilteringOption.Exclude;

		internal static Color LethalLibColor = new Color(0f, 0.44f, 0.76f, 1f);

		internal static readonly string WeatherSaveKey = "WeatherRegistryCurrentWeathers";
	}
	[CreateAssetMenu(fileName = "WeatherEffect", menuName = "WeatherRegistry/ImprovedWeatherEffect", order = 90)]
	public class ImprovedWeatherEffect : ScriptableObject
	{
		[JsonIgnore]
		[Tooltip("The GameObject that is visible only for the player, i.e. rain particles, sound effects etc.")]
		[SerializeField]
		public GameObject EffectObject;

		[JsonIgnore]
		[Tooltip("The GameObject that is placed in the world, i.e. floodwater, lightning bolts etc.")]
		[SerializeField]
		public GameObject WorldObject;

		private bool _effectEnabled;

		[Tooltip("The name of sun animator's bool that gets toggled when the weather effect is enabled. Vanilla uses '' for clear weather, 'overcast' for stormy/flooded, 'eclipse' for eclipsed.")]
		[field: SerializeField]
		public string SunAnimatorBool { get; set; }

		[field: SerializeField]
		public int DefaultVariable1 { get; set; }

		[field: SerializeField]
		public int DefaultVariable2 { get; set; }

		public LevelWeatherType LevelWeatherType { get; internal set; }

		public WeatherEffect VanillaWeatherEffect { get; internal set; }

		public virtual bool EffectEnabled
		{
			get
			{
				return _effectEnabled;
			}
			set
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				((Logger)WeatherEffectManager.Logger).LogDebug($"Setting effect {((Object)this).name} to {value} - is player inside? {Settings.IsPlayerInside}");
				if (!Settings.IsPlayerInside)
				{
					GameObject effectObject = EffectObject;
					if (effectObject != null)
					{
						effectObject.SetActive(value);
					}
					WeatherEffectController.SetTimeOfDayEffect(LevelWeatherType, value);
				}
				GameObject worldObject = WorldObject;
				if (worldObject != null)
				{
					worldObject.SetActive(value);
				}
				_effectEnabled = value;
			}
		}

		public bool EffectActive
		{
			get
			{
				GameObject effectObject = EffectObject;
				if (effectObject == null)
				{
					return false;
				}
				return effectObject.activeSelf;
			}
		}

		public virtual void DisableEffect(bool permament = false)
		{
			if (permament)
			{
				EffectEnabled = false;
				return;
			}
			GameObject effectObject = EffectObject;
			if (effectObject != null)
			{
				effectObject.SetActive(false);
			}
		}

		public ImprovedWeatherEffect(GameObject effectObject, GameObject worldObject)
		{
			EffectObject = effectObject;
			WorldObject = worldObject;
			GameObject effectObject2 = EffectObject;
			if (effectObject2 != null)
			{
				effectObject2.SetActive(false);
			}
			GameObject worldObject2 = WorldObject;
			if (worldObject2 != null)
			{
				worldObject2.SetActive(false);
			}
		}

		public ImprovedWeatherEffect(WeatherEffect weatherEffect)
		{
			EffectObject = weatherEffect.effectObject;
			WorldObject = weatherEffect.effectPermanentObject;
			VanillaWeatherEffect = weatherEffect;
			GameObject effectObject = EffectObject;
			if (effectObject != null)
			{
				effectObject.SetActive(false);
			}
			GameObject worldObject = WorldObject;
			if (worldObject != null)
			{
				worldObject.SetActive(false);
			}
		}
	}
	public class EventManager
	{
		public static WeatherRegistryEvent DisableAllWeathers = new WeatherRegistryEvent();

		public static WeatherRegistryEvent BeforeSetupStart = new WeatherRegistryEvent();

		public static WeatherRegistryEvent SetupFinished = new WeatherRegistryEvent();

		public static WeatherRegistryEvent<int> DayChanged = new WeatherRegistryEvent<int>();

		public static WeatherRegistryEvent<(SelectableLevel level, Weather weather, string screenText)> MapScreenUpdated = new WeatherRegistryEvent<(SelectableLevel, Weather, string)>();

		public static WeatherRegistryEvent<(SelectableLevel level, Weather weather)> WeatherChanged = new WeatherRegistryEvent<(SelectableLevel, Weather)>();

		public static WeatherRegistryEvent<(SelectableLevel level, Weather weather)> ShipLanding = new WeatherRegistryEvent<(SelectableLevel, Weather)>();
	}
	public static class Forecasts
	{
		private static readonly Logger Logger = new Logger("Forecast", (LoggingType)1);

		public static (List<CompatibleNoun> compatibleNouns, List<TerminalNode> forecastNodes, List<TerminalKeyword> forecastKeywords) InitializeForecastNodes()
		{
			List<CompatibleNoun> compatibleNouns = new List<CompatibleNoun>();
			List<TerminalNode> forecastNodes = new List<TerminalNode>();
			List<TerminalKeyword> forecastKeywords = new List<TerminalKeyword>();
			LevelHelper.Levels.ForEach(delegate(SelectableLevel level)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Expected O, but got Unknown
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Expected O, but got Unknown
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Expected O, but got Unknown
				TerminalNode val = new TerminalNode();
				TerminalKeyword val2 = new TerminalKeyword();
				CompatibleNoun val3 = new CompatibleNoun();
				string alphanumericName = ConfigHelper.GetAlphanumericName(level);
				val2 = ScriptableObject.CreateInstance<TerminalKeyword>();
				val2.word = alphanumericName.ToLowerInvariant() ?? "";
				((Object)val2).name = "Forecast" + alphanumericName + "Keyword";
				val2.defaultVerb = Plugin.ForecastVerb;
				val = ScriptableObject.CreateInstance<TerminalNode>();
				((Object)val).name = "Forecast" + alphanumericName;
				val.clearPreviousText = true;
				val.acceptAnything = true;
				val.terminalOptions = Array.Empty<CompatibleNoun>();
				val.maxCharactersToType = 25;
				val.itemCost = 0;
				val.buyItemIndex = -1;
				val.buyVehicleIndex = -1;
				val.buyRerouteToMoon = -1;
				val.displayPlanetInfo = -1;
				val.shipUnlockableID = -1;
				val.creatureFileID = -1;
				val.storyLogFileID = -1;
				val.playSyncedClip = -1;
				val.terminalEvent = "forecast";
				val.displayText = GetForecast(level);
				val3 = new CompatibleNoun
				{
					noun = val2,
					result = val
				};
				val2.compatibleNouns = (CompatibleNoun[])(object)new CompatibleNoun[1] { val3 };
				compatibleNouns.Add(val3);
				forecastNodes.Add(val);
				forecastKeywords.Add(val2);
				TerminalNodeManager.ForecastTerminalNodes.Add(val, level);
			});
			return (compatibleNouns, forecastNodes, forecastKeywords);
		}

		public static string GetForecast(SelectableLevel level)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			string alphanumericName = ConfigHelper.GetAlphanumericName(level);
			ConsoleTable val = new ConsoleTable(new string[2] { "Weather", "Tomorrow" });
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("Forecasting weather for " + alphanumericName);
			stringBuilder.AppendLine("Current weather: " + WeatherManager.GetCurrentWeather(level).Name + "\n");
			stringBuilder.AppendLine("Weights for next days:\n");
			Dictionary<string, int> tomorrowWeights = new Dictionary<string, int>();
			WeatherManager.GetWeathers().ForEach(delegate(Weather weather)
			{
				tomorrowWeights.Add(weather.Name, weather.GetWeight(level));
			});
			int num = tomorrowWeights.Values.Sum();
			tomorrowWeights = tomorrowWeights.OrderByDescending((KeyValuePair<string, int> x) => x.Value).ToDictionary((KeyValuePair<string, int> x) => x.Key, (KeyValuePair<string, int> x) => x.Value);
			((Logger)Logger).LogDebug($"Total weight for {alphanumericName}: {num}");
			foreach (KeyValuePair<string, int> item in tomorrowWeights)
			{
				val.AddRow(new object[2]
				{
					item.Key,
					item.Value.ToString().PadRight(5) + " (" + ((float)((double)item.Value / (double)num) * 100f).ToString("0.00") + "%)"
				});
			}
			stringBuilder.Append(val.ToStringCustomDecoration(true, false, false));
			return stringBuilder.ToString();
		}
	}
	public class Logger : Logger
	{
		public override ManualLogSource LogSource { get; protected set; }

		public Logger(string SourceName, LoggingType defaultLoggingType = 1)
			: base(SourceName, defaultLoggingType)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Logger)this).ModName = SourceName;
			((Logger)this).LogSource = Logger.CreateLogSource("WeatherRegistry");
			((Logger)this)._name = SourceName;
		}

		public override bool ShouldLog(LoggingType type)
		{
			//IL_0005: 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)
			return ConfigManager.LoggingLevels.Value >= type;
		}
	}
	public static class WeatherOverrideManager
	{
		public static List<WeatherEffectOverride> WeatherEffectOverrides { get; internal set; } = new List<WeatherEffectOverride>();


		public static Dictionary<WeatherEffectOverride, string> PlanetOverrideNames { get; internal set; } = new Dictionary<WeatherEffectOverride, string>();


		public static WeatherEffectOverride GetCurrentWeatherOverride(SelectableLevel level, Weather weather)
		{
			weather.WeatherEffectOverrides.TryGetValue(level, out var value);
			return value;
		}

		public static string GetPlanetOverrideName(WeatherEffectOverride overrideEffect)
		{
			if (PlanetOverrideNames.TryGetValue(overrideEffect, out var value))
			{
				return value;
			}
			return null;
		}
	}
	public enum WeatherType
	{
		Clear,
		Vanilla,
		Modded
	}
	public enum WeatherOrigin
	{
		Vanilla,
		WeatherRegistry,
		LethalLib,
		LethalLevelLoader,
		WeatherTweaks
	}
	public enum FilteringOption
	{
		Include,
		Exclude
	}
	[JsonObject(/*Could not decode attribute arguments.*/)]
	public class Weather : ScriptableObject
	{
		[JsonProperty]
		public string Name;

		[JsonIgnore]
		public ImprovedWeatherEffect Effect;

		[JsonIgnore]
		public Dictionary<SelectableLevel, LevelWeatherVariables> WeatherVariables = new Dictionary<SelectableLevel, LevelWeatherVariables>();

		[JsonIgnore]
		[Obsolete]
		public AnimationClip AnimationClip;

		[JsonIgnore]
		public RegistryWeatherConfig Config = new RegistryWeatherConfig();

		[JsonIgnore]
		internal Dictionary<SelectableLevel, WeatherEffectOverride> WeatherEffectOverrides = new Dictionary<SelectableLevel, WeatherEffectOverride>();

		[Obsolete("Use Weather.Config.DefaultWeight instead")]
		internal int _defaultWeight = 100;

		[Obsolete("Use Weather.Config.ScrapAmountMultiplier instead")]
		internal float _scrapAmountMultiplier = 1f;

		[Obsolete("Use Weather.Config.ScrapValueMultiplier instead")]
		internal float _scrapValueMultiplier = 1f;

		[JsonProperty]
		public LevelWeatherType VanillaWeatherType { get; internal set; } = (LevelWeatherType)(-1);


		[JsonIgnore]
		internal WeatherOrigin Origin { get; set; } = WeatherOrigin.WeatherRegistry;


		[JsonProperty]
		public WeatherType Type { get; internal set; } = WeatherType.Modded;


		[field: SerializeField]
		public Color Color { get; set; } = Color.cyan;


		[SerializeField]
		public int DefaultWeight
		{
			get
			{
				return ((ConfigHandler<int, int>)Config.DefaultWeight).Value;
			}
			[Obsolete("Use Weather.Config.DefaultWeight instead")]
			set
			{
				_defaultWeight = value;
			}
		}

		[Obsolete("Use Weather.Config.LevelFilters instead")]
		public string[] DefaultLevelFilters
		{
			get
			{
				return ((ConfigHandler<SelectableLevel[], string>)Config.LevelFilters).DefaultValue.Split(";");
			}
			set
			{
				Config.LevelFilters = new LevelListConfigHandler(value);
			}
		}

		[Obsolete("Use Weather.Config.LevelWeights instead")]
		public string[] DefaultLevelWeights
		{
			get
			{
				return ((ConfigHandler<LevelRarity[], string>)Config.LevelWeights).DefaultValue.Split(";");
			}
			set
			{
				Config.LevelWeights = new LevelWeightsConfigHandler(value);
			}
		}

		[Obsolete("Use Weather.Config.WeatherToWeatherWeights instead")]
		public string[] DefaultWeatherToWeatherWeights
		{
			get
			{
				return ((ConfigHandler<WeatherRarity[], string>)Config.WeatherToWeatherWeights).DefaultValue.Split(";");
			}
			set
			{
				Config.WeatherToWeatherWeights = new WeatherWeightsConfigHandler(value);
			}
		}

		public float ScrapAmountMultiplier
		{
			get
			{
				return ((ConfigHandler<float, float>)Config.ScrapAmountMultiplier).Value;
			}
			[Obsolete("Use Weather.Config.ScrapAmountMultiplier instead")]
			set
			{
				Config.ScrapAmountMultiplier = new FloatConfigHandler(value);
			}
		}

		public float ScrapValueMultiplier
		{
			get
			{
				return ((ConfigHandler<float, float>)Config.ScrapValueMultiplier).Value;
			}
			[Obsolete("Use Weather.Config.ScrapValueMultiplier instead")]
			set
			{
				Config.ScrapValueMultiplier = new FloatConfigHandler(value);
			}
		}

		[SerializeField]
		[JsonIgnore]
		public FilteringOption LevelFilteringOption
		{
			get
			{
				if (!((ConfigHandler<bool, bool>)Config.FilteringOption).Value)
				{
					return FilteringOption.Exclude;
				}
				return FilteringOption.Include;
			}
			[Obsolete("Use Weather.Config.FilteringOption instead")]
			set
			{
				Config.FilteringOption = new BooleanConfigHandler(value == FilteringOption.Include);
			}
		}

		[JsonIgnore]
		public List<SelectableLevel> LevelFilters => ((ConfigHandler<SelectableLevel[], string>)Config.LevelFilters).Value.ToList();

		[JsonIgnore]
		public Dictionary<LevelWeatherType, int> WeatherWeights => ((ConfigHandler<WeatherRarity[], string>)Config.WeatherToWeatherWeights).Value.ToDictionary((WeatherRarity rarity) => rarity.Weather.VanillaWeatherType, (WeatherRarity rarity) => rarity.Weight);

		[JsonIgnore]
		public Dictionary<SelectableLevel, int> LevelWeights => ((ConfigHandler<LevelRarity[], string>)Config.LevelWeights).Value.ToDictionary((LevelRarity rarity) => rarity.Level, (LevelRarity rarity) => rarity.Weight);

		internal virtual string ConfigCategory => ((Type == WeatherType.Vanilla || Type == WeatherType.Clear) ? "Vanilla" : "Modded") + " Weather: " + ((Object)this).name.Replace(" ", "") + ((Origin != WeatherOrigin.WeatherRegistry && Origin != 0) ? $" ({Origin})" : "");

		public Weather(string name = "None", ImprovedWeatherEffect effect = null)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Regex regex = new Regex("<.*?>");
			Name = regex.Replace(name, "");
			((Object)this).name = regex.Replace(name, "");
			Effect = effect;
			if ((Object)(object)effect != (Object)null)
			{
				((Object)Effect).name = name;
			}
			Object.DontDestroyOnLoad((Object)(object)this);
		}

		internal virtual void Init()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Config.Init(this);
			if ((Object)(object)Effect != (Object)null)
			{
				Effect.LevelWeatherType = VanillaWeatherType;
			}
			((Object)this).hideFlags = (HideFlags)61;
		}

		public override string ToString()
		{
			return Name;
		}

		public void RemoveFromMoon(string moonNames)
		{
			ConfigHelper.ConvertStringToLevels(moonNames).ToList().ForEach(delegate(SelectableLevel level)
			{
				LevelFilters.Remove(level);
			});
		}

		public void RemoveFromMoon(SelectableLevel moon)
		{
			LevelFilters.Remove(moon);
		}

		public (int weight, WeatherWeightType type) GetWeightWithOrigin(SelectableLevel level)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Logger logger = WeatherCalculation.Logger;
			int item = DefaultWeight;
			WeatherWeightType weatherWeightType = WeatherWeightType.Default;
			Weather weather = WeatherManager.GetWeather(level.currentWeather);
			if ((Object)(object)weather == (Object)null)
			{
				((Logger)logger).LogError("Previous weather is null for " + ((Object)level).name);
			}
			int value2;
			if (LevelWeights.TryGetValue(level, out var value))
			{
				weatherWeightType = WeatherWeightType.Level;
				item = value;
			}
			else if (weather.WeatherWeights.TryGetValue(VanillaWeatherType, out value2) && StartOfRound.Instance.gameStats.daysSpent != 0)
			{
				weatherWeightType = WeatherWeightType.WeatherToWeather;
				item = value2;
			}
			else
			{
				weatherWeightType = WeatherWeightType.Default;
			}
			return (item, weatherWeightType);
		}

		public int GetWeight(SelectableLevel level)
		{
			return GetWeightWithOrigin(level).weight;
		}

		public string GetAlphanumericName()
		{
			return ConfigHelper.GetAlphanumericName(this);
		}

		public (bool isWTW, int weight) GetWeatherToWeatherWeight(Weather previousWeather)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (previousWeather.WeatherWeights.TryGetValue(VanillaWeatherType, out var value))
			{
				return (true, value);
			}
			return (false, DefaultWeight);
		}

		public WeatherEffectOverride GetEffectOverride(SelectableLevel level)
		{
			if (WeatherEffectOverrides.ContainsKey(level))
			{
				return WeatherEffectOverrides[level];
			}
			return null;
		}
	}
	public class LevelWeatherVariables
	{
		public SelectableLevel Level;

		public int WeatherVariable1;

		public int WeatherVariable2;
	}
	[Obsolete]
	public class LevelWeather : LevelWeatherVariables
	{
		public Weather Weather;

		public LevelWeatherVariables Variables;
	}
	public enum WeatherWeightType
	{
		Default,
		WeatherToWeather,
		Level
	}
	[BepInPlugin("mrov.WeatherRegistry", "WeatherRegistry", "0.7.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("Ozzymops.DisableStormyWeather")]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Event <>9__13_1;

			public static Event <>9__13_2;

			internal void <Awake>b__13_1()
			{
				ContentManager.AddTerminalKeywords(new List<TerminalKeyword>(1) { ForecastVerb });
				var (list, list2, list3) = Forecasts.InitializeForecastNodes();
				ForecastVerb.compatibleNouns = list.ToArray();
				ContentManager.AddTerminalNodes(list2);
				ContentManager.AddTerminalKeywords(list3);
				ConfigManager.Instance.RemoveOrphanedEntries();
			}

			internal void <Awake>b__13_2()
			{
				AssetBundleLoader.LoadWeatherOverrides();
				AssetBundleLoader.LoadModdedWeathersMatchers();
			}
		}

		[Obsolete("Use PluginInfo.PLUGIN_GUID instead")]
		public const string GUID = "mrov.WeatherRegistry";

		internal static ManualLogSource logger;

		internal static Logger debugLogger = new Logger("Debug", (LoggingType)1);

		internal static Harmony harmony = new Harmony("mrov.WeatherRegistry");

		internal static bool IsLethalLibLoaded = false;

		internal static JLLCompat JLLCompat;

		internal static LobbyControlCompat LobbyControlCompat;

		internal static FacilityMeltdownCompat FacilityMeltdownCompat;

		internal static OrbitsCompat OrbitsCompat;

		internal static ImperiumCompat ImperiumCompat;

		internal static MalfunctionsCompat MalfunctionsCompat;

		internal static Hook WeatherTypeEnumHook;

		internal static TerminalKeyword ForecastVerb;

		private void Awake()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00b0: 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)
			//IL_00bb: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			AssetBundleLoader.LoadAssetBundles();
			ForecastVerb = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)ForecastVerb).name = "Forecast";
			ForecastVerb.word = "forecast";
			ForecastVerb.isVerb = true;
			EventManager.MainMenuLoaded.AddListener((Event)delegate
			{
				MainMenuInit();
			});
			WeatherRegistryEvent setupFinished = EventManager.SetupFinished;
			object obj = <>c.<>9__13_1;
			if (obj == null)
			{
				Event val = delegate
				{
					ContentManager.AddTerminalKeywords(new List<TerminalKeyword>(1) { ForecastVerb });
					var (list, list2, list3) = Forecasts.InitializeForecastNodes();
					ForecastVerb.compatibleNouns = list.ToArray();
					ContentManager.AddTerminalNodes(list2);
					ContentManager.AddTerminalKeywords(list3);
					ConfigManager.Instance.RemoveOrphanedEntries();
				};
				<>c.<>9__13_1 = val;
				obj = (object)val;
			}
			((CustomEvent)setupFinished).AddListener((Event)obj);
			WeatherRegistryEvent setupFinished2 = EventManager.SetupFinished;
			object obj2 = <>c.<>9__13_2;
			if (obj2 == null)
			{
				Event val2 = delegate
				{
					AssetBundleLoader.LoadWeatherOverrides();
					AssetBundleLoader.LoadModdedWeathersMatchers();
				};
				<>c.<>9__13_2 = val2;
				obj2 = (object)val2;
			}
			((CustomEvent)setupFinished2).AddListener((Event)obj2);
			if (Chainloader.PluginInfos.ContainsKey("evaisa.lethallib"))
			{
				IsLethalLibLoaded = true;
				LethalLibPatch.Init();
			}
			else
			{
				logger.LogDebug((object)"LethalLib not detected!");
			}
			WeatherTypeEnumHook = new Hook((MethodBase)typeof(Enum).GetMethod("ToString", Array.Empty<Type>()), typeof(EnumPatches).GetMethod("LevelWeatherTypeEnumToStringHook"));
			if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
			{
				LobbyCompatibilityCompatibility.Init();
			}
			JLLCompat = new JLLCompat("JacobG5.JLL");
			LobbyControlCompat = new LobbyControlCompat("mattymatty.LobbyControl");
			LobbyControlCompat.Init();
			FacilityMeltdownCompat = new FacilityMeltdownCompat("me.loaforc.facilitymeltdown");
			OrbitsCompat = new OrbitsCompat("com.fiufki.orbits");
			OrbitsCompat.Init();
			ImperiumCompat = new ImperiumCompat("giosuel.Imperium");
			MalfunctionsCompat = new MalfunctionsCompat("com.zealsprince.malfunctions");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin mrov.WeatherRegistry is loaded!");
		}

		private void MainMenuInit()
		{
			ImperiumCompat.Init();
		}
	}
	public class Settings
	{
		public static Dictionary<string, Color> ScreenMapColors = new Dictionary<string, Color>();

		public static bool SetupFinished => WeatherManager.IsSetupFinished;

		public static bool IsGameStarted { get; internal set; } = false;


		public static bool IsPlayerInside { get; set; } = false;


		public static bool SelectWeathers { get; set; } = true;


		public static WeatherSelectionAlgorithm WeatherSelectionAlgorithm { get; set; } = WeatherCalculation.WeatherAlgorithms[ConfigManager.WeatherAlgorithm.Value];


		public static bool ScrapMultipliers { get; set; } = ConfigManager.UseScrapMultipliers.Value;


		public static bool ColoredWeathers { get; set; } = ConfigManager.ColoredWeathers.Value;


		public static bool WeatherOverrideNames { get; set; } = true;


		public static bool PlanetVideos { get; set; } = ConfigManager.PlanetVideos.Value;


		public static bool MapScreenOverride { get; set; } = true;

	}
	public static class Startup
	{
		internal static Logger Logger = new Logger("Startup", (LoggingType)2);

		internal static WeatherEffect[] vanillaEffectsArray { get; private set; } = null;


		public static void Init(Terminal __instance)
		{
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Expected O, but got Unknown
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_0824: Unknown result type (might be due to invalid IL or missing references)
			//IL_082e: Expected O, but got Unknown
			//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b4: Expected O, but got Unknown
			//IL_090f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0919: Expected O, but got Unknown
			//IL_0974: Unknown result type (might be due to invalid IL or missing references)
			//IL_097e: Expected O, but got Unknown
			//IL_0a1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0c: Unknown result type (might be due to invalid IL or missing references)
			((Logger)Logger).LogInfo("Terminal Start Patch");
			WeatherManager.Reset();
			Settings.IsPlayerInside = false;
			Settings.IsGameStarted = false;
			((CustomEvent)EventManager.BeforeSetupStart).Invoke();
			WeatherEffect[] effects = TimeOfDay.Instance.effects;
			List<WeatherEffect> list = effects.ToList();
			if (effects == null || effects.Count() == 0)
			{
				((Logger)Logger).LogInfo("Effects are null");
			}
			else
			{
				((Logger)Logger).LogInfo($"Effects: {effects.Count()}");
			}
			foreach (SelectableLevel level in LevelHelper.Levels)
			{
				List<RandomWeatherWithVariables> list2 = level.randomWeathers.ToList();
				RandomWeatherWithVariables[] randomWeathers = level.randomWeathers;
				foreach (RandomWeatherWithVariables val in randomWeathers)
				{
					if (!Enum.IsDefined(typeof(LevelWeatherType), val.weatherType))
					{
						list2.Remove(val);
						Plugin.logger.LogDebug((object)$"Removing weather {val.weatherType} from level {((Object)level).name}");
					}
				}
				if (list2.Count != level.randomWeathers.Count())
				{
					level.randomWeathers = list2.ToArray();
				}
			}
			((Logger)Logger).LogInfo("Creating NoneWeather type");
			Weather weather4 = new Weather("None", new ImprovedWeatherEffect(null, null));
			weather4.Type = WeatherType.Clear;
			weather4.Color = Defaults.VanillaWeatherColors[(LevelWeatherType)(-1)];
			weather4.VanillaWeatherType = (LevelWeatherType)(-1);
			weather4.Origin = WeatherOrigin.Vanilla;
			weather4.Config.WeatherToWeatherWeights = new WeatherWeightsConfigHandler(Defaults.VanillaWeatherToWeatherWeights.TryGetValue((LevelWeatherType)(-1), out var value) ? (string.Join(';', value) + ";") : Defaults.DefaultWeatherToWeatherWeights);
			Weather weather5 = weather4;
			WeatherManager.WeathersDictionary.Add((LevelWeatherType)(-1), weather5);
			WeatherManager.NoneWeather = weather5;
			for (int j = 0; j < effects.Count(); j++)
			{
				WeatherEffect val2 = effects[j];
				LevelWeatherType val3 = (LevelWeatherType)j;
				bool flag = Defaults.VanillaWeathers.Contains(val3);
				string text = ((object)(LevelWeatherType)(ref val3)).ToString();
				if (text == "DustClouds")
				{
					text = "Dust Clouds";
				}
				WeatherType type = (flag ? WeatherType.Vanilla : WeatherType.Modded);
				Color color = (flag ? Defaults.VanillaWeatherColors[val3] : Color.blue);
				ImprovedWeatherEffect effect = new ImprovedWeatherEffect(val2.effectObject, val2.effectPermanentObject)
				{
					SunAnimatorBool = val2.sunAnimatorBool
				};
				weather4 = new Weather(text, effect);
				weather4.Type = type;
				weather4.Color = color;
				weather4.VanillaWeatherType = val3;
				weather4.Origin = WeatherOrigin.Vanilla;
				weather4.Config.WeatherToWeatherWeights = new WeatherWeightsConfigHandler(Defaults.VanillaWeatherToWeatherWeights.TryGetValue(val3, out var value2) ? (string.Join(';', value2) + ";") : Defaults.DefaultWeatherToWeatherWeights);
				Weather weather6 = weather4;
				WeatherManager.WeathersDictionary.Add(weather6.VanillaWeatherType, weather6);
			}
			if (Plugin.IsLethalLibLoaded)
			{
				((Logger)Logger).LogDebug("Getting LethalLib Weathers");
				List<Weather> list3 = LethalLibPatch.ConvertLLWeathers();
				foreach (Weather item in list3)
				{
					((Logger)Logger).LogDebug("LethalLib Weather: " + item.Name);
					WeatherManager.RegisteredWeathers.Add(item);
				}
			}
			int biggestKeyInModdedWeathersDictionary = Enum.GetValues(typeof(LevelWeatherType)).Length - 1;
			if (WeatherManager.ModdedWeatherEnumExtension.Count > 0)
			{
				biggestKeyInModdedWeathersDictionary = WeatherManager.ModdedWeatherEnumExtension.Keys.Max() + 1;
			}
			((Logger)Logger).LogDebug("Biggest key in modded weathers dictionary: " + biggestKeyInModdedWeathersDictionary);
			WeatherManager.RegisteredWeathers.Where((Weather weather) => weather.Origin == WeatherOrigin.WeatherRegistry || weather.Origin == WeatherOrigin.WeatherTweaks).ToList().ForEach(delegate(Weather weather)
			{
				int num3 = biggestKeyInModdedWeathersDictionary;
				weather.VanillaWeatherType = (LevelWeatherType)num3;
				((Logger)Logger).LogInfo($"Registering weather {weather.Name} under ID {num3}");
				WeatherManager.ModdedWeatherEnumExtension.Add(num3, weather);
				biggestKeyInModdedWeathersDictionary++;
			});
			int num = 0;
			foreach (KeyValuePair<int, Weather> item2 in WeatherManager.ModdedWeatherEnumExtension)
			{
				if (item2.Key > num)
				{
					num = item2.Key;
				}
			}
			while (list.Count <= num)
			{
				list.Add(null);
			}
			foreach (KeyValuePair<int, Weather> item3 in WeatherManager.ModdedWeatherEnumExtension)
			{
				if ((Object)(object)item3.Value.Effect == (Object)null)
				{
					Weather value3 = item3.Value;
					ImprovedWeatherEffect improvedWeatherEffect = new ImprovedWeatherEffect(null, null);
					((Object)improvedWeatherEffect).name = item3.Value.Name;
					value3.Effect = improvedWeatherEffect;
				}
				if (item3.Value.Effect.VanillaWeatherEffect != null)
				{
					((Object)item3.Value.Effect).name = item3.Value.Name;
					list[item3.Key] = item3.Value.Effect.VanillaWeatherEffect;
					continue;
				}
				list[item3.Key] = new WeatherEffect
				{
					name = item3.Value.Name,
					effectObject = item3.Value.Effect.EffectObject,
					effectPermanentObject = item3.Value.Effect.WorldObject,
					sunAnimatorBool = item3.Value.Effect.SunAnimatorBool,
					effectEnabled = false,
					lerpPosition = false,
					transitioning = false
				};
				item3.Value.Effect.VanillaWeatherEffect = list[item3.Key];
				if ((Object)(object)list[item3.Key].effectObject != (Object)null)
				{
					list[item3.Key].effectObject.SetActive(false);
				}
				if ((Object)(object)list[item3.Key].effectPermanentObject != (Object)null)
				{
					list[item3.Key].effectPermanentObject.SetActive(false);
				}
			}
			TimeOfDay.Instance.effects = list.ToArray();
			List<Weather> list4 = WeatherManager.RegisteredWeathers.Distinct().ToList();
			list4.Sort(delegate(Weather a, Weather b)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				LevelWeatherType vanillaWeatherType = a.VanillaWeatherType;
				return ((Enum)(LevelWeatherType)(ref vanillaWeatherType)).CompareTo((object?)b.VanillaWeatherType);
			});
			for (int k = 0; k < list4.Count; k++)
			{
				((Logger)Logger).LogInfo("Registered Weather: " + list4[k].Name);
				Weather weather7 = list4[k];
				WeatherManager.WeathersDictionary.Add(weather7.VanillaWeatherType, weather7);
			}
			((Logger)Logger).LogDebug($"Weathers: {WeatherManager.Weathers.Count}");
			foreach (Weather weather3 in WeatherManager.Weathers)
			{
				Settings.ScreenMapColors.Add(weather3.Name, weather3.Color);
				weather3.Init();
				((Logger)Logger).LogInfo($"Weather {weather3.Name} has {weather3.LevelFilteringOption} filtering option set up");
				List<SelectableLevel> list5 = new List<SelectableLevel>();
				if (weather3.LevelFilteringOption == FilteringOption.Include)
				{
					list5 = weather3.LevelFilters;
				}
				else if (weather3.LevelFilteringOption == FilteringOption.Exclude)
				{
					list5 = LevelHelper.SortedLevels.ToList();
					list5.RemoveAll((SelectableLevel level) => weather3.LevelFilters.Contains(level));
				}
				AddWeatherToLevels(weather3, list5);
			}
			ConsoleTable possibleWeathersTable = new ConsoleTable(new string[2] { "Planet", "Random weathers" });
			LevelHelper.SortedLevels.ForEach(delegate(SelectableLevel level)
			{
				List<LevelWeatherType> list6 = level.randomWeathers.Select((RandomWeatherWithVariables x) => x.weatherType).ToList();
				list6.Sort();
				string text3 = JsonConvert.SerializeObject((object)list6.Select((LevelWeatherType x) => ((object)(LevelWeatherType)(ref x)).ToString()).ToList());
				possibleWeathersTable.AddRow(new object[2]
				{
					ConfigHelper.GetNumberlessName(level),
					text3
				});
			});
			((Logger)Logger).LogInfo("Possible weathers:\n" + possibleWeathersTable.ToMinimalString());
			string[] second = WeatherManager.Weathers.Select((Weather weather) => weather.Name).ToArray();
			ConsoleTable defaultWeightsTable = new ConsoleTable(new string[2] { "Weather", "Default weight" });
			WeatherManager.Weathers.ForEach(delegate(Weather weather)
			{
				defaultWeightsTable.AddRow(new object[2]
				{
					weather.Name,
					((ConfigHandler<int, int>)weather.Config.DefaultWeight).Value
				});
			});
			((Logger)Logger).LogCustom("Default weights:\n" + defaultWeightsTable.ToMinimalString(), (LogLevel)16, (LoggingType)0);
			string[] first = new string[1] { "From \\ To" };
			first = first.Concat(second).ToArray();
			ConsoleTable weatherToWeatherWeightsTable = new ConsoleTable(first);
			WeatherManager.Weathers.ForEach(delegate(Weather weather)
			{
				List<string> row2 = new List<string> { weather.Name };
				WeatherManager.Weathers.ForEach(delegate(Weather weather2)
				{
					var (flag2, num2) = weather2.GetWeatherToWeatherWeight(weather);
					if (flag2)
					{
						row2.Add(num2.ToString());
					}
					else
					{
						row2.Add("X");
					}
				});
				ConsoleTable obj2 = weatherToWeatherWeightsTable;
				object[] array2 = row2.ToArray();
				obj2.AddRow(array2);
			});
			((Logger)Logger).LogCustom("Weather-weather weights:\n" + weatherToWeatherWeightsTable.ToMinimalString(), (LogLevel)16, (LoggingType)0);
			string[] first2 = new string[1] { "Level" };
			first2 = first2.Concat(second).ToArray();
			ConsoleTable levelWeightsTable = new ConsoleTable(first2);
			LevelHelper.SortedLevels.ForEach(delegate(SelectableLevel level)
			{
				List<string> row = new List<string> { ConfigHelper.GetNumberlessName(level) };
				WeatherManager.Weathers.ForEach(delegate(Weather weather)
				{
					if (weather.LevelWeights.TryGetValue(level, out var value4))
					{
						row.Add(value4.ToString());
					}
					else
					{
						row.Add("X");
					}
				});
				ConsoleTable obj = levelWeightsTable;
				object[] array = row.ToArray();
				obj.AddRow(array);
			});
			((Logger)Logger).LogCustom("Level weights:\n" + levelWeightsTable.ToMinimalString(), (LogLevel)16, (LoggingType)0);
			WeatherManager.IsSetupFinished = true;
			((CustomEvent)EventManager.SetupFinished).Invoke();
			StartOfRound.Instance.SetPlanetsWeather(0);
			StartOfRound.Instance.SetMapScreenInfoToCurrentLevel();
			if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				WeatherLevelData.ApplyReceivedWeathers(WeatherSync.Instance.Weather);
			}
			if (((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				WeatherSync.Instance.WeatherList = FixedString4096Bytes.op_Implicit(WeatherManager.GetWeatherList());
				return;
			}
			FixedString4096Bytes weatherList = WeatherSync.Instance.WeatherList;
			string text2 = ((object)(FixedString4096Bytes)(ref weatherList)).ToString();
			string weatherList2 = WeatherManager.GetWeatherList();
			if (text2 != weatherList2)
			{
				((Logger)Logger).LogError("Weathers are different between clients!");
				((Logger)Logger).LogDebug("Host: " + text2);
				((Logger)Logger).LogDebug("Local: " + weatherList2);
			}
		}

		private static void AddWeatherToLevels(Weather weather, List<SelectableLevel> LevelsToApply)
		{
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Expected O, but got Unknown
			weather.WeatherVariables.Clear();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Weather: " + weather.Name);
			foreach (SelectableLevel sortedLevel in LevelHelper.SortedLevels)
			{
				stringBuilder.AppendLine();
				stringBuilder.Append(ConfigHelper.GetNumberlessName(sortedLevel) + ": ");
				List<RandomWeatherWithVariables> list = sortedLevel.randomWeathers.ToList();
				RandomWeatherWithVariables val = ((IEnumerable<RandomWeatherWithVariables>)sortedLevel.randomWeathers).FirstOrDefault((Func<RandomWeatherWithVariables, bool>)((RandomWeatherWithVariables rw) => rw.weatherType == weather.VanillaWeatherType));
				bool flag = LevelsToApply.Contains(sortedLevel);
				if (val == null && weather.Type == WeatherType.Vanilla)
				{
					stringBuilder.Append("Vanilla weather not defined by moon creator");
				}
				else if (weather.Type == WeatherType.Clear && Settings.WeatherSelectionAlgorithm != WeatherCalculation.VanillaAlgorithm)
				{
					list.RemoveAll((RandomWeatherWithVariables rw) => rw.weatherType == weather.VanillaWeatherType);
					RandomWeatherWithVariables[] randomWeathersWithVariables = (RandomWeatherWithVariables[])(object)GetRandomWeathersWithVariables(list);
					sortedLevel.randomWeathers = randomWeathersWithVariables;
					stringBuilder.Append("Clear weather type removed");
				}
				else if (LevelHelper.CompanyMoons.Contains(sortedLevel) && !flag)
				{
					list.RemoveAll((RandomWeatherWithVariables rw) => rw.weatherType == weather.VanillaWeatherType);
					RandomWeatherWithVariables[] randomWeathersWithVariables = (RandomWeatherWithVariables[])(object)GetRandomWeathersWithVariables(list);
					sortedLevel.randomWeathers = randomWeathersWithVariables;
					stringBuilder.Append("Removed from company moon");
				}
				else if (!flag)
				{
					if (val != null)
					{
						list.RemoveAll((RandomWeatherWithVariables rw) => rw.weatherType == weather.VanillaWeatherType);
						RandomWeatherWithVariables[] randomWeathersWithVariables = (RandomWeatherWithVariables[])(object)GetRandomWeathersWithVariables(list);
						sortedLevel.randomWeathers = randomWeathersWithVariables;
					}
					stringBuilder.Append("Level not in list to apply weather to");
				}
				else if (weather.Type <= WeatherType.Vanilla)
				{
					stringBuilder.Append("Weather is already there" + ((val != null) ? $" (variables {val.weatherVariable}/{val.weatherVariable2})" : ""));
				}
				else
				{
					if (weather.Type != WeatherType.Modded)
					{
						continue;
					}
					if (val != null)
					{
						stringBuilder.Append("Removing existing weather (added before lobby reload)");
						list.RemoveAll((RandomWeatherWithVariables rw) => rw.weatherType == weather.VanillaWeatherType);
					}
					stringBuilder.Append($"Injecting modded weather (variables {weather.Effect.DefaultVariable1}/{weather.Effect.DefaultVariable2})");
					RandomWeatherWithVariables item = new RandomWeatherWithVariables
					{
						weatherType = weather.VanillaWeatherType,
						weatherVariable = weather.Effect.DefaultVariable1,
						weatherVariable2 = weather.Effect.DefaultVariable2
					};
					list.Add(item);
					RandomWeatherWithVariables[] randomWeathersWithVariables = (RandomWeatherWithVariables[])(object)GetRandomWeathersWithVariables(list);
					sortedLevel.randomWeathers = randomWeathersWithVariables;
				}
			}
			stringBuilder.AppendLine();
			((Logger)Logger).LogDebug(stringBuilder.ToString());
		}

		private static ImprovedRandomWeatherWithVariables[] GetRandomWeathersWithVariables(List<RandomWeatherWithVariables> randomWeathers)
		{
			return randomWeathers.Select((RandomWeatherWithVariables rw) => new ImprovedRandomWeatherWithVariables
			{
				weatherType = rw.weatherType,
				weatherVariable = rw.weatherVariable,
				weatherVariable2 = rw.weatherVariable2
			}).ToArray();
		}
	}
	public static class WeatherCalculation
	{
		public enum WeatherAlgorithm
		{
			Registry,
			Vanilla,
			Hybrid
		}

		internal static Dictionary<string, LevelWeatherType> previousDayWeather = new Dictionary<string, LevelWeatherType>();

		internal static Logger Logger = new Logger("WeatherCalculation", (LoggingType)0);

		internal static WeatherSelectionAlgorithm RegistryAlgorithm = new WeatherRegistryWeatherSelection();

		internal static WeatherSelectionAlgorithm VanillaAlgorithm = new VanillaWeatherSelection();

		internal static WeatherSelectionAlgorithm HybridAlgorithm = new HybridWeatherSelection();

		public static Dictionary<WeatherAlgorithm, WeatherSelectionAlgorithm> WeatherAlgorithms = new Dictionary<WeatherAlgorithm, WeatherSelectionAlgorithm>
		{
			{
				WeatherAlgorithm.Registry,
				RegistryAlgorithm
			},
			{
				WeatherAlgorithm.Vanilla,
				VanillaAlgorithm
			},
			{
				WeatherAlgorithm.Hybrid,
				HybridAlgorithm
			}
		};

		[Obsolete("Use Settings.WeatherSelectionAlgorithm instead")]
		public static WeatherSelectionAlgorithm WeatherSelectionAlgorithm
		{
			get
			{
				return Settings.WeatherSelectionAlgorithm;
			}
			set
			{
				Settings.WeatherSelectionAlgorithm = value;
			}
		}
	}
	public static class WeatherController
	{
		private static Logger Logger = new Logger("WeatherController", (LoggingType)0);

		public static void ChangeCurrentWeather(Weather weather)
		{
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			ChangeWeather(currentLevel, weather);
		}

		public static void ChangeCurrentWeather(LevelWeatherType weatherType)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			ChangeWeather(currentLevel, weatherType);
		}

		public static void ChangeWeather(SelectableLevel level, LevelWeatherType weatherType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Weather weather = WeatherManager.GetWeather(weatherType);
			ChangeWeather(level, weather);
		}

		public static void ChangeWeather(SelectableLevel level, Weather weather)
		{
			//IL_000a: 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)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.SelectWeathers)
			{
				return;
			}
			level.currentWeather = weather.VanillaWeatherType;
			if ((Object)(object)StartOfRound.Instance.currentLevel == (Object)(object)level)
			{
				TimeOfDay.Instance.currentLevelWeather = weather.VanillaWeatherType;
			}
			((Logger)Logger).LogDebug($"Changed weather for {ConfigHelper.GetNumberlessName(level)} to {weather.VanillaWeatherType}");
			if (!StartOfRound.Instance.inShipPhase)
			{
				if ((Object)(object)StartOfRound.Instance.currentLevel == (Object)(object)level)
				{
					((Logger)Logger).LogDebug("Ship has already landed, changing weather effects");
					SetWeatherEffects(weather);
					return;
				}
				((Logger)Logger).LogDebug("Ship has already landed - cannot change weather effect on other level!");
			}
			WeatherManager.CurrentWeathers.SetWeather(level, weather);
			((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).Invoke((level, weather));
			StartOfRound.Instance.SetMapScreenInfoToCurrentLevel();
		}

		public static void SetRandomWeathers(SelectableLevel level, List<RandomWeatherWithVariables> randomWeathers)
		{
			SetRandomWeathers(level, randomWeathers.ToArray());
		}

		public static void SetRandomWeathers(SelectableLevel level, RandomWeatherWithVariables[] randomWeathers)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			level.randomWeathers = randomWeathers.ToArray();
			string alphanumericName = ConfigHelper.GetAlphanumericName(level);
			foreach (RandomWeatherWithVariables val in randomWeathers)
			{
				((Logger)Logger).LogWarning($"Adding random weather {val.weatherType} to {alphanumericName}");
				WeatherManager.GetWeather(val.weatherType).WeatherVariables[level] = new LevelWeatherVariables
				{
					Level = level,
					WeatherVariable1 = val.weatherVariable,
					WeatherVariable2 = val.weatherVariable2
				};
			}
		}

		public static void AddRandomWeather(SelectableLevel level, RandomWeatherWithVariables randomWeather)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0048: 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)
			List<RandomWeatherWithVariables> list = level.randomWeathers.ToList();
			if ((int)randomWeather.weatherType == -1)
			{
				((Logger)Logger).LogInfo("Cannot add None weather to random weathers, skipping");
				return;
			}
			list.Add(randomWeather);
			level.randomWeathers = list.Distinct().ToArray();
			Plugin.logger.LogInfo((object)$"Adding random weather {randomWeather.weatherType} to {ConfigHelper.GetAlphanumericName(level)}");
			WeatherManager.GetWeather(randomWeather.weatherType).WeatherVariables[level] = new LevelWeatherVariables
			{
				Level = level,
				WeatherVariable1 = randomWeather.weatherVariable,
				WeatherVariable2 = randomWeather.weatherVariable2
			};
		}

		public static void RemoveRandomWeather(SelectableLevel level, RandomWeatherWithVariables randomWeather)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			List<RandomWeatherWithVariables> list = level.randomWeathers.ToList();
			list.Remove(randomWeather);
			level.randomWeathers = list.ToArray();
			WeatherManager.GetWeather(randomWeather.weatherType).WeatherVariables.Remove(level);
		}

		public static void RemoveRandomWeather(SelectableLevel level, LevelWeatherType weatherType)
		{
			//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)
			List<RandomWeatherWithVariables> list = level.randomWeathers.Where((RandomWeatherWithVariables rw) => rw.weatherType == weatherType).ToList();
			foreach (RandomWeatherWithVariables item in list)
			{
				RemoveRandomWeather(level, item);
			}
		}

		public static void SetWeatherEffects(LevelWeatherType weatherType)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			WeatherSync.Instance.SetWeatherEffectOnHost(weatherType);
		}

		public static void SetWeatherEffects(Weather weather)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			SetWeatherEffects(weather.VanillaWeatherType);
		}

		public static void AddWeatherEffect(LevelWeatherType weatherType)
		{
			//IL_000a: 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)
			Plugin.logger.LogDebug((object)$"Adding weather effect {weatherType}");
			List<LevelWeatherType> list = WeatherSync.Instance.Effects.Effects.ToList();
			list.Add(weatherType);
			WeatherSync.Instance.SetWeatherEffectsOnHost(list.ToArray());
		}

		public static void AddWeatherEffect(Weather weather)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			AddWeatherEffect(weather.VanillaWeatherType);
		}
	}
	public static class WeatherEffectController
	{
		internal static void SetTimeOfDayEffect(LevelWeatherType weatherType, bool enabled)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0026: 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)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((int)weatherType != -1)
			{
				if (Settings.IsPlayerInside)
				{
					Plugin.logger.LogWarning((object)"Player is inside, not setting time of day effect");
				}
				else if (TimeOfDay.Instance.effects[weatherType] != null)
				{
					((Logger)Plugin.debugLogger).LogDebug($"Setting time of day effect {weatherType} to {enabled}");
					TimeOfDay.Instance.effects[weatherType].effectEnabled = enabled;
				}
			}
		}

		[Obsolete("Use SetWeatherEffects(Weather[]) instead")]
		public static void SetWeatherEffects(Weather weather)
		{
			SetWeatherEffects(new Weather[1] { weather });
		}

		public static void SetWeatherEffects(Weather[] weathers)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			DisableWeatherEffects(weathers);
			foreach (Weather weather2 in weathers)
			{
				if ((Object)(object)weather2 == (Object)null)
				{
					continue;
				}
				if ((int)weather2.VanillaWeatherType != 4)
				{
					PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
					localPlayerController.isUnderwater = false;
					localPlayerController.sourcesCausingSinking = Mathf.Clamp(localPlayerController.sourcesCausingSinking - 1, 0, 100);
					localPlayerController.isMovementHindered = Mathf.Clamp(localPlayerController.isMovementHindered - 1, 0, 100);
					localPlayerController.hinderedMultiplier = 1f;
				}
				if ((int)weather2.VanillaWeatherType == -1)
				{
					SunAnimator.OverrideSunAnimator(weather2.VanillaWeatherType);
					continue;
				}
				if (((CompatibilityBase)Plugin.JLLCompat).IsModPresent)
				{
					var (flag, val) = Plugin.JLLCompat.GetJLLData();
					if (flag)
					{
						Plugin.logger.LogInfo((object)"Enabling JLL WeatherEffect");
						val.effectEnabled = true;
						GameObject effectObject = val.effectObject;
						if (effectObject != null)
						{
							effectObject.SetActive(true);
						}
						continue;
					}
				}
				WeatherEffectOverride effectOverride = weather2.GetEffectOverride(currentLevel);
				if (effectOverride == null)
				{
					weather2.Effect.EffectEnabled = true;
					SetTimeOfDayEffect(weather2.VanillaWeatherType, enabled: true);
				}
				else
				{
					weather2.Effect.EffectEnabled = false;
					effectOverride.OverrideEffect.EffectEnabled = true;
				}
			}
			try
			{
				SunAnimator.OverrideSunAnimator(weathers.Any((Weather weather) => Defaults.VanillaWeathers.Contains(weather.VanillaWeatherType)) ? weathers.Where((Weather weather) => Defaults.VanillaWeathers.Contains(weather.VanillaWeatherType)).Max((Weather weather) => weather.VanillaWeatherType) : weathers.Max((Weather weather) => weather.VanillaWeatherType));
			}
			catch (Exception ex)
			{
				Plugin.logger.LogError((object)("SunAnimator exception: " + ex.Message));
				Plugin.logger.LogWarning((object)"PLEASE report this issue to the mod developer with your modpack code and this log!");
			}
		}

		public static void SetWeatherEffects(LevelWeatherType[] weatherTypes)
		{
			Weather[] weatherEffects = weatherTypes.Select(WeatherManager.GetWeather).ToArray();
			SetWeatherEffects(weatherEffects);
		}

		public static void DisableWeatherEffects(Weather[] newWeathers)
		{
			foreach (WeatherEffectOverride weatherEffectOverride in WeatherOverrideManager.WeatherEffectOverrides)
			{
				if (!newWeathers.Contains(weatherEffectOverride.Weather))
				{
					weatherEffectOverride.OverrideEffect.DisableEffect(permament: true);
				}
			}
			foreach (Weather weather in WeatherManager.Weathers)
			{
				if (!newWeathers.Contains(weather))
				{
					weather.Effect.DisableEffect(permament: true);
				}
			}
			if (!((CompatibilityBase)Plugin.JLLCompat).IsModPresent)
			{
				return;
			}
			var (flag, val) = Plugin.JLLCompat.GetJLLData();
			if (flag)
			{
				Plugin.logger.LogInfo((object)"Disabling JLL WeatherEffect");
				val.effectEnabled = false;
				GameObject effectObject = val.effectObject;
				if (effectObject != null)
				{
					effectObject.SetActive(false);
				}
			}
		}

		public static void EnableCurrentWeatherEffects()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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)
			if (((CompatibilityBase)Plugin.JLLCompat).IsModPresent)
			{
				var (flag, val) = Plugin.JLLCompat.GetJLLData();
				if (flag)
				{
					Plugin.logger.LogInfo((object)"Enabling JLL WeatherEffect");
					val.effectEnabled = true;
					GameObject effectObject = val.effectObject;
					if (effectObject != null)
					{
						effectObject.SetActive(true);
					}
				}
			}
			foreach (LevelWeatherType currentEffectType in WeatherManager.CurrentEffectTypes)
			{
				Weather weather = WeatherManager.GetWeather(currentEffectType);
				weather.Effect.EffectEnabled = true;
				SetTimeOfDayEffect(weather.VanillaWeatherType, enabled: true);
			}
		}

		public static void HandleJLLOverride(LevelWeatherType weatherType, bool enable)
		{
			if (Plugin.JLLCompat.IsJLLDoingWeatherOverride())
			{
				Plugin.logger.LogInfo((object)"Detected JLL WeatherOverride");
			}
		}
	}
	public static class WeatherManager
	{
		internal static bool IsSetupFinished = false;

		public static Dictionary<int, Weather> ModdedWeatherEnumExtension = new Dictionary<int, Weather>();

		public static CurrentWeathers CurrentWeathers = new CurrentWeathers();

		public static List<Weather> RegisteredWeathers { get; internal set; } = new List<Weather>();


		[Obsolete("Use WeatherOverrideManager.WeatherEffectOverrides instead")]
		public static List<WeatherEffectOverride> WeatherEffectOverrides => WeatherOverrideManager.WeatherEffectOverrides;

		public static List<Weather> Weathers => WeathersDictionary.Values.ToList();

		public static Dictionary<LevelWeatherType, Weather> WeathersDictionary { get; internal set; } = new Dictionary<LevelWeatherType, Weather>();


		public static Weather NoneWeather { get; internal set; }

		public static List<LevelWeatherType> LevelWeatherTypes => Weathers.Select((Weather weather) => weather.VanillaWeatherType).ToList();

		public static List<LevelWeatherType> CurrentEffectTypes => (from weather in Weathers
			where (Object)(object)weather.Effect != (Object)null
			where weather.Effect.EffectEnabled
			select weather.VanillaWeatherType).ToList();

		public static void RegisterWeather(Weather weather)
		{
			RegisteredWeathers.Add(weather);
		}

		public static Weather GetWeather(LevelWeatherType levelWeatherType)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (WeathersDictionary.ContainsKey(levelWeatherType))
			{
				return WeathersDictionary[levelWeatherType];
			}
			Plugin.logger.LogWarning((object)$"Weather {levelWeatherType} not found in dictionary");
			return null;
		}

		public static List<Weather> GetWeathers()
		{
			return Weathers;
		}

		internal static void Reset()
		{
			IsSetupFinished = false;
			Weathers.ForEach(delegate(Weather weather)
			{
				if (weather.Origin != WeatherOrigin.WeatherRegistry && weather.Origin != WeatherOrigin.WeatherTweaks)
				{
					Object.Destroy((Object)(object)weather.Effect);
					Object.Destroy((Object)(object)weather);
				}
			});
			Weathers.Clear();
			WeathersDictionary.Clear();
			ModdedWeatherEnumExtension.Clear();
			CurrentWeathers.Clear();
			WeatherOverrideManager.WeatherEffectOverrides.Clear();
			Settings.ScreenMapColors.Clear();
			ConfigHelper.StringToWeather = null;
			RegisteredWeathers.RemoveAll((Weather weather) => weather.Origin != WeatherOrigin.WeatherRegistry && weather.Origin != WeatherOrigin.WeatherTweaks);
			WeatherLevelData.LatestWeathersReceived = Array.Empty<WeatherSyncData>();
		}

		public static string WeatherDisplayOverride(SelectableLevel level)
		{
			return string.Empty;
		}

		internal static List<LevelWeatherType> GetPlanetPossibleWeathers(SelectableLevel level)
		{
			List<LevelWeatherType> list = (from randomWeather in level.randomWeathers
				where (int)randomWeather.weatherType != -1
				select randomWeather into x
				select x.weatherType).Distinct().ToList();
			list.Insert(0, (LevelWeatherType)(-1));
			if (list == null || list.Count() == 0)
			{
				Plugin.logger.LogWarning((object)"Level's random weathers are null");
				return new List<LevelWeatherType>();
			}
			return list;
		}

		public static WeightHandler<Weather, WeatherWeightType> GetPlanetWeightedList(SelectableLevel level)
		{
			//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)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			WeightHandler<Weather, WeatherWeightType> weightHandler = new WeightHandler<Weather, WeatherWeightType>();
			Logger logger = WeatherCalculation.Logger;
			List<LevelWeatherType> planetPossibleWeathers = GetPlanetPossibleWeathers(level);
			if (planetPossibleWeathers == null || planetPossibleWeathers.Count() == 0)
			{
				Plugin.logger.LogWarning((object)"Level's random weathers are null");
				return weightHandler;
			}
			foreach (LevelWeatherType item in planetPossibleWeathers)
			{
				Weather weather = GetWeather(item);
				var (num, weatherWeightType) = weather.GetWeightWithOrigin(level);
				((WeightHandler<Weather>)weightHandler).Add(weather, num);
			}
			return weightHandler;
		}

		public static Weather GetCurrentWeather(SelectableLevel level)
		{
			if (!Settings.SetupFinished)
			{
				Plugin.logger.LogWarning((object)"Something is trying to get the current weather before setup is finished!");
				return null;
			}
			return CurrentWeathers.GetLevelWeather(level);
		}

		public static Weather GetCurrentLevelWeather()
		{
			return GetCurrentWeather(StartOfRound.Instance.currentLevel);
		}

		public static string GetCurrentWeatherName(SelectableLevel level, bool ignoreOverride = false)
		{
			string text = WeatherDisplayOverride(level);
			if (text != string.Empty && !ignoreOverride)
			{
				return text;
			}
			return GetCurrentWeather(level).Name;
		}

		[Obsolete]
		internal static AnimationClip GetWeatherAnimationClip(LevelWeatherType weatherType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return GetWeather(weatherType).AnimationClip;
		}

		[Obsolete("Use WeatherOverrideManager.GetCurrentWeatherOverride instead")]
		public static WeatherEffectOverride GetCurrentWeatherOverride(SelectableLevel level, Weather weather)
		{
			return WeatherOverrideManager.GetCurrentWeatherOverride(level, weather);
		}

		public static string GetWeatherList()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected I4, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			List<WeatherListData> list = new List<WeatherListData>();
			foreach (Weather weather in Weathers)
			{
				list.Add(new WeatherListData
				{
					WeatherID = FixedString64Bytes.op_Implicit(((int)weather.VanillaWeatherType).ToString()),
					WeatherName = FixedString64Bytes.op_Implicit(weather.Name)
				});
			}
			return JsonConvert.SerializeObject((object)list, (Formatting)0, new JsonSerializerSettings
			{
				ReferenceLoopHandling = (ReferenceLoopHandling)1
			});
		}
	}
	public class WeatherResolvable
	{
		public virtual string WeatherName { get; }

		public virtual LevelWeatherType WeatherType { get; }

		public override string ToString()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected I4, but got Unknown
			return $"{WeatherName} ({(int)WeatherType})";
		}
	}
	public class WeatherNameResolvable : WeatherResolvable
	{
		[CompilerGenerated]
		private string <weatherName>P;

		public override string WeatherName => <weatherName>P;

		public override LevelWeatherType WeatherType
		{
			get
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (WeatherManager.IsSetupFinished)
				{
					Weather weather = ConfigHelper.ResolveStringToWeather(<weatherName>P);
					if (!((Object)(object)weather == (Object)null))
					{
						return weather.VanillaWeatherType;
					}
					return (LevelWeatherType)(-1);
				}
				((Logger)Plugin.debugLogger).LogDebug("Tried to resolve weather name " + <weatherName>P + " before setup finished");
				return (LevelWeatherType)(-1);
			}
		}

		public WeatherNameResolvable(string weatherName)
		{
			<weatherName>P = weatherName;
			base..ctor();
		}
	}
	public class WeatherTypeResolvable : WeatherResolvable
	{
		[CompilerGenerated]
		private LevelWeatherType <weatherType>P;

		public override LevelWeatherType WeatherType => <weatherType>P;

		public override string WeatherName
		{
			get
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				if (WeatherManager.IsSetupFinished)
				{
					return WeatherManager.GetWeather(<weatherType>P).Name;
				}
				return "";
			}
		}

		public WeatherTypeResolvable(LevelWeatherType weatherType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			<weatherType>P = weatherType;
			base..ctor();
		}
	}
	internal class WeatherSync : NetworkBehaviour
	{
		private static Logger Logger = new Logger("WeatherSync", (LoggingType)1);

		public NetworkVariable<WeatherSyncDataWrapper> WeathersSynced = new NetworkVariable<WeatherSyncDataWrapper>(new WeatherSyncDataWrapper
		{
			Weathers = Array.Empty<WeatherSyncData>()
		}, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public NetworkVariable<WeatherEffectDataWrapper> EffectsSynced = new NetworkVariable<WeatherEffectDataWrapper>(new WeatherEffectDataWrapper
		{
			Effects = (LevelWeatherType[])(object)new LevelWeatherType[1] { (LevelWeatherType)(-1) }
		}, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public NetworkVariable<FixedString4096Bytes> WeatherData = new NetworkVariable<FixedString4096Bytes>(default(FixedString4096Bytes), (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public static GameObject WeatherSyncPrefab;

		public static NetworkManager networkManager;

		public static bool networkHasStarted = false;

		private static WeatherSync _instance;

		private static List<GameObject> queuedNetworkPrefabs = new List<GameObject>();

		public WeatherSyncData[] Weather
		{
			get
			{
				return WeathersSynced.Value.Weathers;
			}
			set
			{
				WeathersSynced.Value = new WeatherSyncDataWrapper
				{
					Weathers = value
				};
			}
		}

		public WeatherEffectDataWrapper Effects
		{
			get
			{
				return EffectsSynced.Value;
			}
			set
			{
				EffectsSynced.Value = new WeatherEffectDataWrapper
				{
					Effects = value.Effects
				};
			}
		}

		public FixedString4096Bytes WeatherList
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return WeatherData.Value;
			}
			set
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				WeatherData.Value = value;
			}
		}

		public static WeatherSync Instance
		{
			get
			{
				if ((Object)(object)_instance == (Object)null)
				{
					_instance = Object.FindObjectOfType<WeatherSync>();
					if ((Object)(object)_instance == (Object)null)
					{
						((Logger)Logger).LogError("WeatherSync instance is null");
					}
				}
				return _instance;
			}
			private set
			{
				_instance = value;
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			InitializeInstance();
			NetworkVariable<WeatherSyncDataWrapper> weathersSynced = WeathersSynced;
			weathersSynced.OnValueChanged = (OnValueChangedDelegate<WeatherSyncDataWrapper>)(object)Delegate.Combine((Delegate?)(object)weathersSynced.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<WeatherSyncDataWrapper>(WeatherLevelData.WeathersReceived));
			NetworkVariable<WeatherEffectDataWrapper> effectsSynced = EffectsSynced;
			effectsSynced.OnValueChanged = (OnValueChangedDelegate<WeatherEffectDataWrapper>)(object)Delegate.Combine((Delegate?)(object)effectsSynced.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<WeatherEffectDataWrapper>(WeatherEffectData.EffectsReceived));
		}

		public void SetNewOnHost(Dictionary<string, LevelWeatherType> weathers)
		{
			if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				((Logger)Logger).LogDebug("Cannot set weathers, not a host!");
				return;
			}
			WeatherSyncData[] weather = weathers.Select(delegate(KeyValuePair<string, LevelWeatherType> kvp)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: 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_0024: Unknown result type (might be due to invalid IL or missing references)
				WeatherSyncData result = default(WeatherSyncData);
				result.Weather = kvp.Value;
				result.LevelName = new FixedString64Bytes(kvp.Key);
				return result;
			}).ToArray();
			Weather = weather;
		}

		public void SetWeatherEffectOnHost(LevelWeatherType weatherType)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected I4, but got Unknown
			SetWeatherEffectsOnHost((LevelWeatherType[])(object)new LevelWeatherType[1] { (LevelWeatherType)(int)weatherType });
		}

		public void SetWeatherEffectsOnHost(LevelWeatherType[] weatherTypes)
		{
			if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				((Logger)Logger).LogDebug("Cannot set effects, not a host!");
				return;
			}
			((Logger)Logger).LogDebug("Setting effects: [" + string.Join("; ", weatherTypes) + "]");
			Effects = new WeatherEffectDataWrapper
			{
				Effects = weatherTypes
			};
		}

		public static void RegisterNetworkPrefab(GameObject prefab)
		{
			if (!networkHasStarted)
			{
				((Logger)Logger).LogDebug("Registering NetworkPrefab: " + (object)prefab);
				queuedNetworkPrefabs.Add(prefab);
			}
			else
			{
				((Logger)Logger).LogWarning("Attempted To Register NetworkPrefab: " + ((object)prefab)?.ToString() + " After GameNetworkManager Has Started!");
			}
		}

		internal static void RegisterPrefabs(NetworkManager networkManager)
		{
			((Logger)Logger).LogDebug("Registering NetworkPrefabs in NetworkManager");
			List<GameObject> existingPrefabs = GetExistingPrefabs(networkManager);
			RegisterQueuedPrefabs(networkManager, existingPrefabs);
			networkHasStarted = true;
		}

		private void InitializeInstance()
		{
			((Object)((Component)this).gameObject).name = "WeatherSync";
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Logger)Logger).LogDebug($"WeathersSynced: {WeathersSynced.Value}");
		}

		private static List<GameObject> GetExistingPrefabs(NetworkManager networkManager)
		{
			List<GameObject> list = new List<GameObject>();
			foreach (NetworkPrefab prefab in networkManager.NetworkConfig.Prefabs.m_Prefabs)
			{
				list.Add(prefab.Prefab);
			}
			return list;
		}

		private static void RegisterQueuedPrefabs(NetworkManager networkManager, List<GameObject> addedNetworkPrefabs)
		{
			int num = 0;
			foreach (GameObject queuedNetworkPrefab in queuedNetworkPrefabs)
			{
				((Logger)Logger).LogDebug("Trying To Register Prefab: