Decompiled source of SnowDay v0.1.0

SnowDay.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using HolidayShared;
using Microsoft.CodeAnalysis;
using ModMenu;
using Unity.Collections;
using Unity.Jobs;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SnowDay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+804736a943d89bfe81479d69df1205845c6f1a8b")]
[assembly: AssemblyProduct("SnowDay")]
[assembly: AssemblyTitle("SnowDay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HolidayShared
{
	internal enum ChristmasMode
	{
		Auto,
		On,
		Off
	}
	internal static class Season
	{
		internal static bool IsChristmas(DateTime day)
		{
			if (day.Month != 12)
			{
				if (day.Month == 1)
				{
					return day.Day <= 6;
				}
				return false;
			}
			return true;
		}

		internal static bool Decide(ChristmasMode mode, DateTime today)
		{
			return mode switch
			{
				ChristmasMode.Auto => IsChristmas(today), 
				ChristmasMode.On => true, 
				_ => false, 
			};
		}

		internal static DateTime Today(string testDate, DateTime now, out bool overridden)
		{
			overridden = TryParse(testDate, now, out var day);
			if (!overridden)
			{
				return now.Date;
			}
			return day;
		}

		internal static bool TryParse(string testDate, DateTime now, out DateTime day)
		{
			day = default(DateTime);
			string text = (testDate ?? "").Trim();
			if (text.Length == 0)
			{
				return false;
			}
			if (DateTime.TryParseExact(text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out day))
			{
				return true;
			}
			if (DateTime.TryParseExact(now.Year + "-" + text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out day))
			{
				return true;
			}
			return false;
		}

		internal static string Why(ChristmasMode mode, DateTime today, bool overridden)
		{
			switch (mode)
			{
			case ChristmasMode.On:
				return "set to On";
			case ChristmasMode.Off:
				return "set to Off";
			default:
			{
				string text = today.ToString("d MMM", CultureInfo.InvariantCulture) + (overridden ? " (test date)" : "");
				if (!IsChristmas(today))
				{
					return "Auto, " + text + " is outside 1 Dec to 6 Jan";
				}
				return "Auto, " + text + " is in 1 Dec to 6 Jan";
			}
			}
		}
	}
	internal sealed class Holiday
	{
		internal readonly ConfigEntry<ChristmasMode> Mode;

		internal readonly ConfigEntry<string> TestDate;

		private readonly string _tag;

		private readonly ManualLogSource _log;

		private readonly Action _broadcast;

		private readonly string _msgAsk;

		private readonly string _msgState;

		private NetworkManager _nm;

		private bool _ownRegistered;

		private bool _decided;

		private bool _hostOn;

		private bool _hostKnown;

		private bool _hostWord;

		private bool _last;

		private string _why = "not in a lobby";

		private float _nextDateCheck;

		private float _nextAsk;

		private int _asks;

		private bool _wasLanded;

		internal bool On
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
				{
					return false;
				}
				if (singleton.IsServer)
				{
					if (!_decided)
					{
						Decide("lobby opened");
					}
					return _hostOn;
				}
				if (_hostKnown)
				{
					return _hostWord;
				}
				return false;
			}
		}

		internal string Why
		{
			get
			{
				if (!IsClient)
				{
					return _why;
				}
				if (!_hostKnown)
				{
					return "no word from the host";
				}
				return "the host's word";
			}
		}

		internal bool IsClient
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening)
				{
					return !singleton.IsServer;
				}
				return false;
			}
		}

		internal bool IsHost
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening)
				{
					return singleton.IsServer;
				}
				return false;
			}
		}

		internal byte Field => On ? ((byte)1) : ((byte)0);

		internal event Action<bool> Changed;

		internal Holiday(ConfigFile config, ManualLogSource log, string tag, Action broadcast = null)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			_tag = tag;
			_log = log;
			_broadcast = broadcast;
			_msgAsk = tag + ".Xmas.Ask";
			_msgState = tag + ".Xmas";
			Mode = config.Bind<ChristmasMode>("Holiday", "Christmas", ChristmasMode.Auto, "Christmas decorations. Auto: on from 1 December to 6 January by the host's date. On or Off: always. The host's setting counts for everyone; a client follows the host, and stays off when the host doesn't have it.");
			TestDate = config.Bind<string>("Holiday", "ChristmasTestDate", "", "Testing: the date Auto pretends it is, as 2026-12-24 or 12-24 (this year). Blank uses the real date.");
			Mode.SettingChanged += delegate
			{
				Decide("Christmas set to " + Mode.Value);
			};
			TestDate.SettingChanged += delegate
			{
				Decide("test date " + (string.IsNullOrWhiteSpace(TestDate.Value) ? "cleared" : TestDate.Value));
			};
			GameObject val = new GameObject("HolidayRunner." + tag)
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<HolidayRunner>().Holiday = this;
		}

		internal void WriteField(FastBufferWriter w)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			byte field = Field;
			((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref field, default(ForPrimitives));
		}

		internal void ReadField(FastBufferReader r)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref r)).Position + 1 <= ((FastBufferReader)(ref r)).Length)
			{
				byte b = default(byte);
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
				FromHost((b & 1) != 0);
			}
			else
			{
				FromHost(null);
			}
		}

		internal void FromHost(bool? on)
		{
			if (IsClient)
			{
				bool num = _hostKnown != on.HasValue || _hostWord != (on == true);
				_hostKnown = on.HasValue;
				_hostWord = on == true;
				if (num)
				{
					_log.LogInfo((object)(_tag + ": Christmas " + ((on == true) ? "on" : "off") + ", " + (on.HasValue ? "the host's word" : "the host sends no Christmas field") + "."));
				}
				Refresh();
			}
		}

		internal void Decide(string reason)
		{
			if (!IsHost)
			{
				return;
			}
			bool overridden;
			DateTime today = Season.Today(TestDate.Value, DateTime.Now, out overridden);
			bool flag = Season.Decide(Mode.Value, today);
			_why = Season.Why(Mode.Value, today, overridden);
			bool flag2 = !_decided;
			bool num = flag2 || flag != _hostOn;
			_decided = true;
			_hostOn = flag;
			if (num)
			{
				_log.LogInfo((object)(_tag + ": Christmas " + (flag ? "on" : "off") + " (" + _why + "; " + reason + ")."));
				Refresh();
				if (!flag2)
				{
					Broadcast();
				}
			}
		}

		internal void Broadcast()
		{
			if (!IsHost)
			{
				return;
			}
			if (_broadcast != null)
			{
				try
				{
					_broadcast();
					return;
				}
				catch (Exception ex)
				{
					_log.LogWarning((object)(_tag + ": Christmas broadcast: " + ex.Message));
					return;
				}
			}
			foreach (ulong connectedClientsId in NetworkManager.Singleton.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L)
				{
					SendState(connectedClientsId);
				}
			}
		}

		internal void Tick()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				if ((Object)(object)_nm != (Object)null)
				{
					EndSession();
				}
				Refresh();
				return;
			}
			if ((Object)(object)singleton != (Object)(object)_nm)
			{
				if ((Object)(object)_nm != (Object)null)
				{
					EndSession();
				}
				_nm = singleton;
			}
			if (_broadcast == null)
			{
				TickOwnMessage(singleton);
			}
			if (singleton.IsServer)
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					bool shipHasLanded = instance.shipHasLanded;
					if (shipHasLanded && !_wasLanded)
					{
						Decide("landing");
					}
					else if (instance.inShipPhase && Time.unscaledTime >= _nextDateCheck)
					{
						_nextDateCheck = Time.unscaledTime + 10f;
						Decide("in orbit");
					}
					_wasLanded = shipHasLanded;
				}
				else if (!_decided)
				{
					Decide("lobby opened");
				}
			}
			Refresh();
		}

		private void EndSession()
		{
			if (_ownRegistered && (Object)(object)_nm != (Object)null && _nm.CustomMessagingManager != null)
			{
				try
				{
					_nm.CustomMessagingManager.UnregisterNamedMessageHandler(_msgAsk);
				}
				catch
				{
				}
				try
				{
					_nm.CustomMessagingManager.UnregisterNamedMessageHandler(_msgState);
				}
				catch
				{
				}
			}
			_nm = null;
			_ownRegistered = false;
			_decided = false;
			_hostOn = false;
			_hostKnown = false;
			_hostWord = false;
			_why = "not in a lobby";
			_nextDateCheck = 0f;
			_nextAsk = 0f;
			_asks = 0;
			_wasLanded = false;
		}

		private void Refresh()
		{
			bool flag = On;
			if (flag == _last)
			{
				return;
			}
			_last = flag;
			Action<bool> action = this.Changed;
			if (action == null)
			{
				return;
			}
			Delegate[] invocationList = action.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<bool> action2 = (Action<bool>)invocationList[i];
				try
				{
					action2(flag);
				}
				catch (Exception arg)
				{
					_log.LogError((object)string.Format("{0}: Christmas {1} handler: {2}", _tag, flag ? "on" : "off", arg));
				}
			}
		}

		private void TickOwnMessage(NetworkManager nm)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (!_ownRegistered)
			{
				CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
				if (nm.IsServer)
				{
					customMessagingManager.RegisterNamedMessageHandler(_msgAsk, (HandleNamedMessageDelegate)delegate(ulong sender, FastBufferReader r)
					{
						SendState(sender);
					});
				}
				else
				{
					customMessagingManager.RegisterNamedMessageHandler(_msgState, (HandleNamedMessageDelegate)delegate(ulong sender, FastBufferReader r)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						ReadField(r);
					});
				}
				_ownRegistered = true;
			}
			if (!nm.IsServer && nm.IsConnectedClient && !_hostKnown && !(Time.unscaledTime < _nextAsk))
			{
				_nextAsk = Time.unscaledTime + ((_asks < 10) ? 3f : 15f);
				_asks++;
				Send(_msgAsk, 0uL, null);
			}
		}

		private void SendState(ulong to)
		{
			Send(_msgState, to, WriteField);
		}

		private static void Send(string name, ulong to, Action<FastBufferWriter> write)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, 64);
			try
			{
				write?.Invoke(val);
				singleton.CustomMessagingManager.SendNamedMessage(name, to, val, (NetworkDelivery)3);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}
	}
	internal sealed class HolidayRunner : MonoBehaviour
	{
		internal Holiday Holiday;

		private float _next;

		private void Update()
		{
			if (Holiday == null || Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 0.25f;
			try
			{
				Holiday.Tick();
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Holiday tick: " + ex.Message));
			}
		}
	}
}
namespace SnowDay
{
	internal sealed class CoverGrid : IDisposable
	{
		private readonly Texture2D texture;

		private readonly ushort[] samples;

		private readonly int side;

		private readonly Vector2 origin;

		private readonly float step;

		internal CoverGrid(Texture2D texture, ushort[] samples, int side, Vector2 origin, float step)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			this.texture = texture;
			this.samples = samples;
			this.side = side;
			this.origin = origin;
			this.step = step;
		}

		private Vector2 At(int x, int z)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			int num = 2 * (Mathf.Clamp(z, 0, side - 1) * side + Mathf.Clamp(x, 0, side - 1));
			return new Vector2(Mathf.HalfToFloat(samples[num]), Mathf.HalfToFloat(samples[num + 1]));
		}

		internal bool Sample(Vector3 point, out Vector2 value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			value = default(Vector2);
			float num = (point.x - origin.x) / step;
			float num2 = (point.z - origin.y) / step;
			if (!(num >= 0f) || !(num2 >= 0f) || !(num < (float)side) || !(num2 < (float)side))
			{
				return false;
			}
			float x = At((int)num, (int)num2).x;
			num -= 0.5f;
			num2 -= 0.5f;
			int num3 = Mathf.FloorToInt(num);
			int num4 = Mathf.FloorToInt(num2);
			Vector2 val = Vector2.Lerp(At(num3, num4), At(num3 + 1, num4), num - (float)num3);
			Vector2 val2 = Vector2.Lerp(At(num3, num4 + 1), At(num3 + 1, num4 + 1), num - (float)num3);
			value = Vector2.Lerp(val, val2, num2 - (float)num4);
			if (Mathf.Abs(value.x - x) >= ((step <= 1f) ? 0.48f : 1.35f))
			{
				value.x = x;
			}
			return true;
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)texture))
			{
				Object.Destroy((Object)(object)texture);
			}
		}
	}
	internal sealed class GroundField : ICoverMap, IDisposable
	{
		private const uint Receiver = 32768u;

		private const int TileSize = 48;

		private readonly Dictionary<Renderer, uint> meshes = new Dictionary<Renderer, uint>();

		private readonly Dictionary<Terrain, uint> terrains = new Dictionary<Terrain, uint>();

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

		private readonly HashSet<Collider> water = new HashSet<Collider>();

		private readonly List<Bounds> wetPlanes = new List<Bounds>();

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

		private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[32];

		private readonly Material material;

		private readonly GameObject root;

		private CoverGrid fineGrid;

		private CoverGrid farGrid;

		private readonly HashSet<Collider> receivers = new HashSet<Collider>();

		private readonly Vector2 patternOffset;

		private readonly List<Bounds> existingSnow = new List<Bounds>();

		private Vector2Int cell = new Vector2Int(int.MinValue, int.MinValue);

		private readonly float altitude;

		private Transform tidalSurface;

		private float seaHeight = -65000f;

		private float bias;

		private float opacity;

		private int radius = 2;

		private static readonly int HiddenLayers = LayerMask.GetMask(new string[6] { "MapRadar", "Triggers", "ScanNode", "NavigationSurface", "Colliders", "UI" });

		private readonly Dictionary<Renderer, Material[]> originals = new Dictionary<Renderer, Material[]>();

		private readonly Dictionary<Material, Material> replacements = new Dictionary<Material, Material>();

		public int MeshCount => meshes.Count;

		public int TerrainCount => terrains.Count;

		public int ReboundMaterials => replacements.Count;

		public void SetTideHeight(float height)
		{
			if (seaHeight != height)
			{
				seaHeight = height;
				material.SetFloat("_SeaHeight", height);
			}
		}

		public GroundField(Material source, Vector3 landing, int seed)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			material = new Material(source)
			{
				enableInstancing = true
			};
			material.SetVector("_FineRect", Vector4.zero);
			material.SetVector("_FarRect", Vector4.zero);
			root = new GameObject("Snow Day projectors");
			altitude = landing.y;
			patternOffset = new Vector2((float)(seed & 0xFF) * 1.37f, (float)((seed >> 8) & 0xFF) * 1.79f);
		}

		private static bool Wet(string name)
		{
			if (!name.Contains("puddle") && !(name == "ocean"))
			{
				if (name.Contains("water") && !name.Contains("waterdam") && !name.Contains("watertower"))
				{
					return !name.Contains("tidewater");
				}
				return false;
			}
			return true;
		}

		private static bool Excluded(Transform t, Transform stop)
		{
			while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)stop)
			{
				string text = ((Object)t).name.ToLowerInvariant();
				bool flag = (!Object.op_Implicit((Object)(object)t.parent) && text == "environment") || (text == "map" && Object.op_Implicit((Object)(object)t.parent) && ((Object)t.parent).name == "Environment" && !Object.op_Implicit((Object)(object)t.parent.parent));
				if (Wet(text) || (text.Contains("door") && !text.Contains("outdoor") && !text.Contains("indoor")) || text.Contains("ladder") || text.Contains("glass") || text.Contains("terminal") || text.Contains("lever") || text.Contains("landmine") || text.Contains("turret") || text.StartsWith("vent") || text.Contains("airvent") || text.Contains("enemyvent") || text.Contains("xmas") || text.Contains("christmas") || text.Contains("dungeon") || text.StartsWith("interior") || text.Contains("snowmesh"))
				{
					return true;
				}
				if (Object.op_Implicit((Object)(object)((Component)t).GetComponent<Animator>()) || Object.op_Implicit((Object)(object)((Component)t).GetComponent<Rigidbody>()) || (!flag && Object.op_Implicit((Object)(object)((Component)t).GetComponent("NetworkObject"))) || Object.op_Implicit((Object)(object)((Component)t).GetComponent("GrabbableObject")))
				{
					return true;
				}
				t = t.parent;
			}
			return false;
		}

		private static bool Drawable(Renderer r)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)r) && r.enabled && ((Component)r).gameObject.activeInHierarchy && (int)r.shadowCastingMode != 3)
			{
				return (HiddenLayers & (1 << ((Component)r).gameObject.layer)) == 0;
			}
			return false;
		}

		private static bool Eligible(Material m)
		{
			if (!Object.op_Implicit((Object)(object)m) || !Object.op_Implicit((Object)(object)m.shader) || !m.shader.isSupported || m.renderQueue >= 3000 || !m.HasProperty("_SupportDecals"))
			{
				return false;
			}
			string text = ((Object)m).name.ToLowerInvariant();
			if (!Wet(text) && !text.Contains("glass") && !text.Contains("christmas") && !text.Contains("snow") && !m.IsKeywordEnabled("_DISABLE_DECALS"))
			{
				return m.GetFloat("_SupportDecals") > 0f;
			}
			return false;
		}

		public IEnumerable<int> Collect(GameObject group, bool ship = false, Shader shipLit = null)
		{
			if (((Object)group).name == "TidewaterWater")
			{
				tidalSurface = group.transform.Find("TideWater_Outside");
				yield break;
			}
			Transform stop = (ship ? group.transform : null);
			MeshRenderer[] componentsInChildren = group.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer r in componentsInChildren)
			{
				yield return 0;
				if (!Drawable((Renderer)(object)r))
				{
					continue;
				}
				Material[] sharedMaterials = ((Renderer)r).sharedMaterials;
				if (!ship && (Wet(((Object)r).name.ToLowerInvariant()) || Array.Exists(sharedMaterials, (Material m) => Object.op_Implicit((Object)(object)m) && Wet(((Object)m).name.ToLowerInvariant()))))
				{
					Bounds bounds = ((Renderer)r).bounds;
					if (((Bounds)(ref bounds)).size.y < 1.5f)
					{
						bounds = ((Renderer)r).bounds;
						if (((Bounds)(ref bounds)).size.x > 1f)
						{
							bounds = ((Renderer)r).bounds;
							if (((Bounds)(ref bounds)).size.z > 1f)
							{
								wetPlanes.Add(((Renderer)r).bounds);
							}
						}
					}
				}
				if (((Object)r).name.IndexOf("snow", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)((Component)r).GetComponentInParent<ParticleSystem>() == (Object)null)
				{
					Bounds bounds2 = ((Renderer)r).bounds;
					((Bounds)(ref bounds2)).Expand(0.6f);
					existingSnow.Add(bounds2);
				}
				if (!Excluded(((Component)r).transform, stop) && sharedMaterials.Length != 0 && Array.TrueForAll(sharedMaterials, Eligible) && (!ship || Hull(((Component)r).transform, stop)) && (!ship || !IsBundleHull(((Component)r).transform, stop) || UseGameLit((Renderer)(object)r, sharedMaterials, shipLit)) && (ship || !Object.op_Implicit((Object)(object)shipLit) || !Array.TrueForAll(sharedMaterials, (Material m) => ((Object)m.shader).name == "HDRP/Lit") || UseGameLit((Renderer)(object)r, sharedMaterials, shipLit)) && !meshes.ContainsKey((Renderer)(object)r))
				{
					meshes.Add((Renderer)(object)r, ((Renderer)r).renderingLayerMask);
					((Renderer)r).renderingLayerMask = ((Renderer)r).renderingLayerMask | 0x8000;
				}
			}
			Terrain[] componentsInChildren2 = group.GetComponentsInChildren<Terrain>();
			foreach (Terrain val in componentsInChildren2)
			{
				if (!ship && ((Behaviour)val).enabled && !Excluded(((Component)val).transform, stop) && (!Object.op_Implicit((Object)(object)val.materialTemplate) || Eligible(val.materialTemplate)))
				{
					terrains.Add(val, val.renderingLayerMask);
					val.renderingLayerMask |= 0x8000;
				}
			}
			Collider[] componentsInChildren3 = group.GetComponentsInChildren<Collider>();
			foreach (Collider c in componentsInChildren3)
			{
				yield return 0;
				if (!c.enabled)
				{
					continue;
				}
				if (Wet(((Object)c).name.ToLowerInvariant()) || Wet(((Component)c).tag.ToLowerInvariant()))
				{
					water.Add(c);
				}
				else if (!c.isTrigger && !Object.op_Implicit((Object)(object)c.attachedRigidbody))
				{
					Terrain component = ((Component)c).GetComponent<Terrain>();
					MeshRenderer componentInParent = ((Component)c).GetComponentInParent<MeshRenderer>();
					bool flag = ship && Hull(((Component)c).transform, stop);
					if (c is TerrainCollider || Drawable((Renderer)(object)componentInParent) || flag)
					{
						blockers.Add(((Object)c).GetInstanceID());
					}
					if ((Object.op_Implicit((Object)(object)component) && terrains.ContainsKey(component)) || (Object.op_Implicit((Object)(object)componentInParent) && meshes.ContainsKey((Renderer)(object)componentInParent)) || (flag && !Excluded(((Component)c).transform, stop) && HullReceiverNear(c.bounds)))
					{
						receivers.Add(c);
					}
				}
			}
		}

		private static bool IsBundleHull(Transform t, Transform stop)
		{
			while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)stop)
			{
				if (((Object)t).name.StartsWith("NewShip_", StringComparison.Ordinal))
				{
					return true;
				}
				t = t.parent;
			}
			return false;
		}

		private bool UseGameLit(Renderer r, Material[] mats, Shader gameLit)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)gameLit) || ((Object)gameLit).name != "HDRP/Lit" || !Array.TrueForAll(mats, (Material m) => ((Object)m.shader).name == ((Object)gameLit).name))
			{
				return false;
			}
			if (Array.TrueForAll(mats, (Material m) => (Object)(object)m.shader == (Object)(object)gameLit))
			{
				return true;
			}
			originals[r] = mats;
			Material[] array = (Material[])mats.Clone();
			for (int num = 0; num < mats.Length; num++)
			{
				if (!((Object)(object)mats[num].shader == (Object)(object)gameLit))
				{
					if (!replacements.TryGetValue(mats[num], out var value))
					{
						value = new Material(mats[num])
						{
							shader = gameLit
						};
						value.CopyPropertiesFromMaterial(mats[num]);
						replacements.Add(mats[num], value);
					}
					array[num] = value;
				}
			}
			r.sharedMaterials = array;
			return true;
		}

		private static bool Hull(Transform t, Transform stop)
		{
			while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)stop)
			{
				string text = ((Object)t).name.ToLowerInvariant();
				if (text.StartsWith("interior") || text.StartsWith("rig") || text.Contains("furniture"))
				{
					return false;
				}
				if (text.Contains("roof") || text.StartsWith("exterior") || text == "shipouterhull" || text == "shiphull")
				{
					return true;
				}
				t = t.parent;
			}
			return false;
		}

		public IEnumerable<int> BuildMap(Vector3 center, int side, float step, bool fine)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			float span = (float)side * step;
			Vector2 start = new Vector2(Mathf.Floor(center.x / step) * step - span / 2f, Mathf.Floor(center.z / step) * step - span / 2f);
			ushort[] pixels = new ushort[2 * side * side];
			QueryParameters query = new QueryParameters(-1, false, (QueryTriggerInteraction)2, false);
			Vector3 val = default(Vector3);
			for (int first = 0; first < side * side; first += 8192)
			{
				int length = Mathf.Min(8192, side * side - first);
				NativeArray<RaycastCommand> commands = new NativeArray<RaycastCommand>(length, (Allocator)4, (NativeArrayOptions)1);
				try
				{
					NativeArray<RaycastHit> firstHits = new NativeArray<RaycastHit>(length, (Allocator)4, (NativeArrayOptions)1);
					try
					{
						NativeArray<RaycastCommand> writable = commands;
						for (int i = 0; i < length; i++)
						{
							int num = first + i;
							((Vector3)(ref val))..ctor(start.x + ((float)(num % side) + 0.5f) * step, altitude + 360f, start.y + ((float)(num / side) + 0.5f) * step);
							writable[i] = new RaycastCommand(val, Vector3.down, query, 560f);
							if ((i & 0x1FF) == 511)
							{
								yield return 0;
							}
						}
						JobHandle job = RaycastCommand.ScheduleBatch(commands, firstHits, 64, 1, default(JobHandle));
						try
						{
							JobHandle.ScheduleBatchedJobs();
							while (!((JobHandle)(ref job)).IsCompleted)
							{
								yield return -1;
							}
						}
						finally
						{
							((JobHandle)(ref job)).Complete();
						}
						for (int i = 0; i < length; i++)
						{
							RaycastCommand val2 = commands[i];
							Vector3 val3 = ((RaycastCommand)(ref val2)).from;
							float x = val3.x;
							float z = val3.z;
							RaycastHit val4 = firstHits[i];
							float num2 = float.NegativeInfinity;
							float num3 = float.NegativeInfinity;
							if (blockers.Contains(((RaycastHit)(ref val4)).colliderInstanceID))
							{
								num2 = ((RaycastHit)(ref val4)).point.y;
							}
							else if (((RaycastHit)(ref val4)).colliderInstanceID != 0)
							{
								int num4 = Physics.RaycastNonAlloc(new Ray(val3, Vector3.down), hits, 560f, -1, (QueryTriggerInteraction)2);
								if (num4 < hits.Length)
								{
									for (int j = 0; j < num4; j++)
									{
										RaycastHit val5 = hits[j];
										if (water.Contains(((RaycastHit)(ref val5)).collider))
										{
											num3 = Mathf.Max(num3, ((RaycastHit)(ref val5)).point.y);
										}
										else if (blockers.Contains(((RaycastHit)(ref val5)).colliderInstanceID))
										{
											num2 = Mathf.Max(num2, ((RaycastHit)(ref val5)).point.y);
										}
									}
								}
							}
							foreach (Bounds wetPlane in wetPlanes)
							{
								Bounds current = wetPlane;
								if (x >= ((Bounds)(ref current)).min.x && x <= ((Bounds)(ref current)).max.x && z >= ((Bounds)(ref current)).min.z && z <= ((Bounds)(ref current)).max.z)
								{
									num3 = Mathf.Max(num3, ((Bounds)(ref current)).max.y);
								}
							}
							int num5 = 2 * (first + i);
							float num6 = 65000f;
							float num7 = 0f;
							if (!float.IsNegativeInfinity(num2))
							{
								num6 = Mathf.Max(num2, num3 + 0.4f);
								float num8 = x + patternOffset.x;
								float num9 = z + patternOffset.y;
								float num10 = Mathf.PerlinNoise(num8 / 14.3f + 71f, num9 / 14.3f + 19f);
								float num11 = Mathf.PerlinNoise((num8 + num9 * 0.46f) / 2.7f + 29f, (num9 - num8 * 0.46f) / 2.7f + 87f);
								num7 = num10 * 0.76f + num11 * 0.24f;
								foreach (Bounds item in existingSnow)
								{
									Bounds current2 = item;
									if (((Bounds)(ref current2)).Contains(new Vector3(x, num2, z)))
									{
										num6 = 65000f;
										num7 = 0f;
										break;
									}
								}
							}
							pixels[num5] = Mathf.FloatToHalf(num6);
							pixels[num5 + 1] = Mathf.FloatToHalf(num7);
							if ((i & 0x7F) == 127)
							{
								yield return 0;
							}
						}
					}
					finally
					{
						((IDisposable)firstHits/*cast due to .constrained prefix*/).Dispose();
					}
				}
				finally
				{
					((IDisposable)commands/*cast due to .constrained prefix*/).Dispose();
				}
			}
			Texture2D val6 = new Texture2D(side, side, (TextureFormat)16, false, true)
			{
				name = "Snow Day shelter",
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1
			};
			CoverGrid coverGrid = new CoverGrid(val6, pixels, side, start, step);
			if (fine)
			{
				fineGrid?.Dispose();
				fineGrid = coverGrid;
			}
			else
			{
				farGrid?.Dispose();
				farGrid = coverGrid;
			}
			val6.SetPixelData<ushort>(pixels, 0, 0);
			val6.Apply(false, true);
			string text = (fine ? "_Fine" : "_Far");
			material.SetTexture(text, (Texture)(object)val6);
			material.SetVector(text + "Rect", new Vector4(start.x, start.y, 1f / span, 0f));
		}

		public void Show(Vector3 eye, bool visible)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)tidalSurface))
			{
				SetTideHeight(tidalSurface.position.y);
			}
			root.SetActive(visible);
			if (!visible)
			{
				return;
			}
			Vector2Int val = default(Vector2Int);
			((Vector2Int)(ref val))..ctor(Mathf.FloorToInt(eye.x / 48f), Mathf.FloorToInt(eye.z / 48f));
			if (cell == val)
			{
				return;
			}
			cell = val;
			int i = -radius;
			int num = 0;
			for (; i <= radius; i++)
			{
				int num2 = -radius;
				while (num2 <= radius)
				{
					if (tiles.Count == num)
					{
						GameObject val2 = new GameObject("Snow cell");
						val2.SetActive(false);
						val2.transform.SetParent(root.transform, false);
						val2.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
						DecalProjector obj = val2.AddComponent<DecalProjector>();
						obj.material = material;
						obj.fadeFactor = opacity;
						obj.decalLayerMask = (DecalLayerEnum)128;
						obj.affectsTransparency = false;
						obj.size = new Vector3(48f, 48f, 230f);
						obj.pivot = Vector3.zero;
						obj.startAngleFade = 40f;
						obj.endAngleFade = 57f;
						obj.drawDistance = 230f;
						tiles.Add(val2.transform);
					}
					tiles[num].position = new Vector3(((float)(((Vector2Int)(ref cell)).x + num2) + 0.5f) * 48f, altitude + 35f, ((float)(((Vector2Int)(ref cell)).y + i) + 0.5f) * 48f);
					((Component)tiles[num]).gameObject.SetActive(true);
					num2++;
					num++;
				}
			}
			for (int j = (2 * radius + 1) * (2 * radius + 1); j < tiles.Count; j++)
			{
				((Component)tiles[j]).gameObject.SetActive(false);
			}
		}

		private static void Release(Object item)
		{
			if (Object.op_Implicit(item))
			{
				if (Application.isPlaying)
				{
					Object.Destroy(item);
				}
				else
				{
					Object.DestroyImmediate(item);
				}
			}
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)root))
			{
				root.SetActive(false);
			}
			foreach (KeyValuePair<Renderer, uint> mesh in meshes)
			{
				if (Object.op_Implicit((Object)(object)mesh.Key))
				{
					mesh.Key.renderingLayerMask = (mesh.Key.renderingLayerMask & 0xFFFF7FFFu) | (mesh.Value & 0x8000);
				}
			}
			foreach (KeyValuePair<Terrain, uint> terrain in terrains)
			{
				if (Object.op_Implicit((Object)(object)terrain.Key))
				{
					terrain.Key.renderingLayerMask = (terrain.Key.renderingLayerMask & 0xFFFF7FFFu) | (terrain.Value & 0x8000);
				}
			}
			foreach (KeyValuePair<Renderer, Material[]> original in originals)
			{
				if (!Object.op_Implicit((Object)(object)original.Key))
				{
					continue;
				}
				Material[] sharedMaterials = original.Key.sharedMaterials;
				for (int i = 0; i < Mathf.Min(sharedMaterials.Length, original.Value.Length); i++)
				{
					if (replacements.TryGetValue(original.Value[i], out var value) && (Object)(object)sharedMaterials[i] == (Object)(object)value)
					{
						sharedMaterials[i] = original.Value[i];
					}
				}
				original.Key.sharedMaterials = sharedMaterials;
			}
			foreach (Material value2 in replacements.Values)
			{
				Release((Object)(object)value2);
			}
			Release((Object)(object)root);
			fineGrid?.Dispose();
			farGrid?.Dispose();
			Release((Object)(object)material);
		}

		private bool HullReceiverNear(Bounds bounds)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			((Bounds)(ref bounds)).Expand(0.3f);
			foreach (Renderer key in meshes.Keys)
			{
				if (Object.op_Implicit((Object)(object)key) && ((Bounds)(ref bounds)).Intersects(key.bounds) && ((Component)key).transform.IsChildOf(StartOfRound.Instance.elevatorTransform))
				{
					return true;
				}
			}
			return false;
		}

		public bool Sheltered(Vector3 point)
		{
			//IL_000e: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((fineGrid != null && fineGrid.Sample(point, out var value)) || (farGrid != null && farGrid.Sample(point, out value)))
			{
				if (!(point.y + 0.21f < value.x))
				{
					return point.y < seaHeight;
				}
				return true;
			}
			return true;
		}

		public float GroundCover(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(point + Vector3.up * 0.35f, Vector3.down, ref val, 0.9f, -5, (QueryTriggerInteraction)1))
			{
				return 0f;
			}
			return SurfaceCover(((RaycastHit)(ref val)).point, ((RaycastHit)(ref val)).normal, ((RaycastHit)(ref val)).collider);
		}

		public float SurfaceCover(Vector3 point, Vector3 normal, Collider collider)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (!receivers.Contains(collider) || !collider.enabled || fineGrid == null || !fineGrid.Sample(point, out var value))
			{
				return 0f;
			}
			float y = ((Vector3)(ref normal)).normalized.y;
			float num = Mathf.InverseLerp(0.545f, 0.766f, y);
			float num2 = Mathf.InverseLerp(-0.04f, 0.13f, point.y - value.x + 0.255f);
			float num3 = Mathf.InverseLerp(0.04f, 0.34f, point.y - seaHeight);
			return Mathf.Clamp01(Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.4f, 0.54f, value.y + bias)) * num * num2 * num3 * opacity);
		}

		public void SetAppearance(float coverageBias, float fade, bool low)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (coverageBias != bias)
			{
				bias = coverageBias;
				material.SetFloat("_CoverBias", bias);
			}
			if (opacity != fade)
			{
				opacity = fade;
				foreach (Transform tile in tiles)
				{
					((Component)tile).GetComponent<DecalProjector>().fadeFactor = fade;
				}
			}
			int num = (low ? 1 : 2);
			if (num != radius)
			{
				radius = num;
				material.SetFloat("_BumpStrength", (float)((!low) ? 1 : 0));
				cell = new Vector2Int(int.MinValue, int.MinValue);
			}
		}
	}
	internal static class MoonRules
	{
		internal static bool AlreadySnowy(SelectableLevel level, Vector3 shipPosition, Scene moon)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (level.levelIncludesSnowFootprints)
			{
				return true;
			}
			if (level.sceneName.IndexOf("Artifice", StringComparison.OrdinalIgnoreCase) >= 0 && WeatherNames.Current().IndexOf("blizzard", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			int num = 0;
			int num2 = 0;
			RaycastHit val = default(RaycastHit);
			for (int i = -2; i <= 2; i++)
			{
				for (int j = -2; j <= 2; j++)
				{
					if (Physics.Raycast(shipPosition + new Vector3((float)(j * 12), 55f, (float)(i * 12)), Vector3.down, ref val, 130f, -5, (QueryTriggerInteraction)1) && !(((Component)((RaycastHit)(ref val)).collider).gameObject.scene != moon))
					{
						num++;
						if (string.Equals(((Component)((RaycastHit)(ref val)).collider).tag, "Snow", StringComparison.OrdinalIgnoreCase))
						{
							num2++;
						}
					}
				}
			}
			if (num >= 6)
			{
				return num2 * 2 > num;
			}
			return false;
		}

		internal static int PatternSeed(string scene)
		{
			switch (scene)
			{
			case "Level1Experimentation":
			case "Level3Vow":
			case "CompanyBuilding":
				return 0;
			default:
			{
				if (scene.StartsWith("Tidewater", StringComparison.OrdinalIgnoreCase))
				{
					return 0;
				}
				int num = 17;
				foreach (char c in scene)
				{
					num = num * 31 + c;
				}
				return num;
			}
			}
		}
	}
	internal interface ICoverMap
	{
		float GroundCover(Vector3 groundPoint);

		bool Sheltered(Vector3 point);

		float SurfaceCover(Vector3 point, Vector3 normal, Collider collider);
	}
	public static class SnowCover
	{
		internal static ICoverMap Map { get; private set; }

		public static int Version => 1;

		public static bool Active => Map != null;

		public static event Action<bool> Changed;

		public static float CoverAt(Vector3 groundPoint)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return Map?.GroundCover(groundPoint) ?? 0f;
		}

		public static bool IsSnowy(Vector3 groundPoint)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return CoverAt(groundPoint) >= 0.45f;
		}

		public static bool Sheltered(Vector3 point)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return Map?.Sheltered(point) ?? true;
		}

		public static bool TryGetCover(Vector3 point, Vector3 normal, Collider collider, out float cover)
		{
			//IL_0020: 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)
			cover = ((!Object.op_Implicit((Object)(object)collider)) ? 0f : (Map?.SurfaceCover(point, normal, collider) ?? 0f));
			return cover > 0f;
		}

		internal static void Use(ICoverMap map)
		{
			bool active = Active;
			Map = map;
			if (active == Active || SnowCover.Changed == null)
			{
				return;
			}
			Delegate[] invocationList = SnowCover.Changed.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<bool> action = (Action<bool>)invocationList[i];
				try
				{
					action(Active);
				}
				catch (Exception ex)
				{
					Debug.LogException(ex);
				}
			}
		}
	}
	public static class SnowApi
	{
		public static int Version => SnowCover.Version;

		public static event Action<bool> Changed
		{
			add
			{
				SnowCover.Changed += value;
			}
			remove
			{
				SnowCover.Changed -= value;
			}
		}

		public static bool TryGetCover(Vector3 point, Vector3 normal, Collider collider, out float cover)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return SnowCover.TryGetCover(point, normal, collider, out cover);
		}
	}
	internal static class WeatherNames
	{
		private static bool looked;

		private static MethodInfo getWeather;

		private static SelectableLevel lastLevel;

		private static LevelWeatherType lastWeather;

		private static float nextLookup;

		private static string lastName = "";

		internal static string Current()
		{
			//IL_0053: 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)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			SelectableLevel val = StartOfRound.Instance?.currentLevel;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return "";
			}
			if ((Object)(object)lastLevel == (Object)(object)val && lastWeather == val.currentWeather && Time.unscaledTime < nextLookup)
			{
				return lastName;
			}
			lastLevel = val;
			lastWeather = val.currentWeather;
			nextLookup = Time.unscaledTime + 0.5f;
			if (!looked)
			{
				looked = true;
				getWeather = AccessTools.TypeByName("WeatherRegistry.WeatherManager")?.GetMethod("GetCurrentLevelWeather", Type.EmptyTypes);
			}
			if (getWeather != null)
			{
				try
				{
					object obj = getWeather.Invoke(null, null);
					if (obj?.GetType().GetProperty("Name")?.GetValue(obj) is string { Length: not 0 } text)
					{
						return lastName = text;
					}
				}
				catch (Exception)
				{
					getWeather = null;
				}
			}
			return lastName = ((object)Unsafe.As<LevelWeatherType, LevelWeatherType>(ref val.currentWeather)/*cast due to .constrained prefix*/).ToString();
		}

		internal static bool Contains(string list, string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			ReadOnlySpan<char> readOnlySpan = list.AsSpan();
			while (!readOnlySpan.IsEmpty)
			{
				int num = readOnlySpan.IndexOf(',');
				if (MemoryExtensions.Equals(((num < 0) ? readOnlySpan : readOnlySpan.Slice(0, num)).Trim(), name.AsSpan(), StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				if (num < 0)
				{
					break;
				}
				readOnlySpan = readOnlySpan.Slice(num + 1);
			}
			return false;
		}
	}
	public sealed class SnowfallFx : IDisposable
	{
		private const string BuiltInWetWeathers = "Rainy,Stormy,Flooded";

		private static readonly int UnlitColorId = Shader.PropertyToID("_UnlitColor");

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		private readonly Material material;

		private readonly Color baseColor;

		private GameObject root;

		private ParticleSystem system;

		private int lastFalling = -1;

		private int lastQuality = -1;

		private int lastCollisionMask;

		private float lastFade = -1f;

		private float lastNightBlend = -1f;

		private float nextSceneScan = -10f;

		private bool sceneSnowUp;

		public SnowfallFx(Material flakeMaterial)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)flakeMaterial))
			{
				material = new Material(flakeMaterial)
				{
					name = "SnowDay Flakes (Instance)"
				};
				baseColor = (Color)(material.HasProperty(UnlitColorId) ? material.GetColor(UnlitColorId) : (material.HasProperty(ColorId) ? material.GetColor(ColorId) : new Color(0.69f, 0.74f, 0.8f, 0.73f)));
			}
		}

		public static SnowfallFx FromBundle(AssetBundle bundle)
		{
			return new SnowfallFx(Object.op_Implicit((Object)(object)bundle) ? bundle.LoadAsset<Material>("Flakes") : null);
		}

		public void Tick(int falling, int quality, float fade = 1f, string mutedWeathers = "Snowfall,Blizzard")
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)material))
			{
				return;
			}
			fade = Mathf.Clamp01(fade);
			StartOfRound instance = StartOfRound.Instance;
			PlayerControllerB val = (Object.op_Implicit((Object)(object)instance) ? instance.localPlayerController : null);
			if (falling <= 0 || fade <= 0.004f || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)val) || val.isInsideFactory)
			{
				Clear();
				return;
			}
			Camera val2 = (Object.op_Implicit((Object)(object)instance.activeCamera) ? instance.activeCamera : val.gameplayCamera);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			if (!SnowCover.Active)
			{
				if (Object.op_Implicit((Object)(object)system) && system.particleCount > 0)
				{
					root.transform.position = ((Component)val2).transform.position;
					StopEmitting(clearParticles: false);
					ApplyProfile(falling, quality, fade);
				}
				return;
			}
			if (WeatherSuppressed(mutedWeathers) || MoonXmasSnowfallUp(Object.op_Implicit((Object)(object)instance.currentLevel) ? instance.currentLevel.sceneName : null))
			{
				StopEmitting(clearParticles: true);
				return;
			}
			EnsureSystem(instance.walkableSurfacesMask);
			Vector3 position = ((Component)val2).transform.position;
			root.transform.position = position;
			ApplyProfile(falling, quality, fade);
			bool flag = val.isInHangarShipRoom || SnowCover.Sheltered(position);
			EmissionModule emission = system.emission;
			if (((EmissionModule)(ref emission)).enabled == flag)
			{
				((EmissionModule)(ref emission)).enabled = !flag;
			}
			if (!system.isPlaying)
			{
				system.Play();
			}
		}

		public void Clear()
		{
			StopEmitting(clearParticles: true);
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)root))
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			system = null;
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
		}

		private void StopEmitting(bool clearParticles)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)system))
			{
				EmissionModule emission = system.emission;
				if (((EmissionModule)(ref emission)).enabled)
				{
					((EmissionModule)(ref emission)).enabled = false;
				}
				if (clearParticles && system.particleCount > 0)
				{
					system.Clear();
				}
			}
		}

		private void EnsureSystem(int walkableMask)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: 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_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			int num = ((walkableMask != 0) ? walkableMask : 2305);
			if (Object.op_Implicit((Object)(object)system))
			{
				if (num != lastCollisionMask)
				{
					CollisionModule collision = system.collision;
					((CollisionModule)(ref collision)).collidesWith = LayerMask.op_Implicit(num);
					lastCollisionMask = num;
				}
				return;
			}
			root = new GameObject("Snow Day snowfall")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)root);
			system = root.AddComponent<ParticleSystem>();
			system.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = system.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).prewarm = false;
			((MainModule)(ref main)).duration = 10f;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(8.5f, 12.5f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.042f, 0.102f);
			((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, MathF.PI * 2f);
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).maxParticles = 1600;
			((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)3;
			EmissionModule emission = system.emission;
			((EmissionModule)(ref emission)).enabled = false;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(140f);
			ShapeModule shape = system.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			((ShapeModule)(ref shape)).scale = new Vector3(48f, 1.5f, 48f);
			((ShapeModule)(ref shape)).position = new Vector3(0f, 12.5f, 0f);
			VelocityOverLifetimeModule velocityOverLifetime = system.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.32f, 0.42f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(-1.42f, -0.86f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(-0.28f, 0.34f);
			RotationOverLifetimeModule rotationOverLifetime = system.rotationOverLifetime;
			((RotationOverLifetimeModule)(ref rotationOverLifetime)).enabled = true;
			((RotationOverLifetimeModule)(ref rotationOverLifetime)).z = new MinMaxCurve(-0.75f, 0.75f);
			NoiseModule noise = system.noise;
			((NoiseModule)(ref noise)).enabled = true;
			((NoiseModule)(ref noise)).separateAxes = true;
			((NoiseModule)(ref noise)).strengthX = MinMaxCurve.op_Implicit(0.36f);
			((NoiseModule)(ref noise)).strengthY = MinMaxCurve.op_Implicit(0.14f);
			((NoiseModule)(ref noise)).strengthZ = MinMaxCurve.op_Implicit(0.36f);
			((NoiseModule)(ref noise)).frequency = 0.23f;
			((NoiseModule)(ref noise)).scrollSpeed = MinMaxCurve.op_Implicit(0.21f);
			((NoiseModule)(ref noise)).quality = (ParticleSystemNoiseQuality)0;
			CollisionModule collision2 = system.collision;
			((CollisionModule)(ref collision2)).enabled = true;
			((CollisionModule)(ref collision2)).type = (ParticleSystemCollisionType)1;
			((CollisionModule)(ref collision2)).mode = (ParticleSystemCollisionMode)0;
			((CollisionModule)(ref collision2)).quality = (ParticleSystemCollisionQuality)2;
			((CollisionModule)(ref collision2)).lifetimeLoss = MinMaxCurve.op_Implicit(1f);
			((CollisionModule)(ref collision2)).radiusScale = 0.5f;
			((CollisionModule)(ref collision2)).collidesWith = LayerMask.op_Implicit(num);
			lastCollisionMask = num;
			ParticleSystemRenderer component = root.GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).sharedMaterial = material;
			component.maxParticleSize = 0.016f;
			component.minParticleSize = 0f;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
		}

		private void ApplyProfile(int falling, int quality, float fade)
		{
			//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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = falling >= 2;
			int num = Mathf.Clamp(quality, 0, 2);
			if (falling != lastFalling || num != lastQuality)
			{
				lastFalling = falling;
				lastQuality = num;
				MainModule main = system.main;
				((MainModule)(ref main)).maxParticles = ((!flag) ? (num switch
				{
					2 => 2200, 
					0 => 750, 
					_ => 1600, 
				}) : (num switch
				{
					2 => 4600, 
					0 => 1500, 
					_ => 3400, 
				}));
				((MainModule)(ref main)).startSize = (flag ? new MinMaxCurve(0.048f, 0.118f) : new MinMaxCurve(0.042f, 0.102f));
				VelocityOverLifetimeModule velocityOverLifetime = system.velocityOverLifetime;
				if (flag)
				{
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.55f, 0.95f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(-2.05f, -1.25f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(-0.45f, 0.65f);
				}
				else
				{
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.32f, 0.42f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(-1.42f, -0.86f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(-0.28f, 0.34f);
				}
				lastFade = -1f;
			}
			float num2 = NightBlend();
			if (Mathf.Abs(fade - lastFade) > 0.005f || Mathf.Abs(num2 - lastNightBlend) > 0.01f)
			{
				lastFade = fade;
				lastNightBlend = num2;
				float num3 = ((!flag) ? (num switch
				{
					2 => 185f, 
					0 => 65f, 
					_ => 140f, 
				}) : (num switch
				{
					2 => 440f, 
					0 => 150f, 
					_ => 320f, 
				}));
				EmissionModule emission = system.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(num3 * fade);
				Color val = default(Color);
				((Color)(ref val))..ctor(baseColor.r * 0.52f, baseColor.g * 0.56f, baseColor.b * 0.65f, baseColor.a * 0.92f);
				Color val2 = Color.Lerp(baseColor, val, num2);
				val2.a *= fade;
				if (material.HasProperty(UnlitColorId))
				{
					material.SetColor(UnlitColorId, val2);
				}
				if (material.HasProperty(ColorId))
				{
					material.SetColor(ColorId, val2);
				}
			}
		}

		internal static float NightBlend()
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return 0f;
			}
			return Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.55f, 0.8f, instance.normalizedTimeOfDay));
		}

		private static bool WeatherSuppressed(string mutedWeathers)
		{
			string text = WeatherNames.Current();
			if (string.IsNullOrEmpty(text) || string.Equals(text, "None", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (WeatherNames.Contains("Rainy,Stormy,Flooded", text))
			{
				return true;
			}
			if (!string.IsNullOrWhiteSpace(mutedWeathers))
			{
				return WeatherNames.Contains(mutedWeathers, text);
			}
			return false;
		}

		private bool MoonXmasSnowfallUp(string sceneName)
		{
			//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)
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < nextSceneScan)
			{
				return sceneSnowUp;
			}
			nextSceneScan = unscaledTime + 0.5f;
			sceneSnowUp = false;
			if (string.IsNullOrEmpty(sceneName))
			{
				return false;
			}
			Scene sceneByName = SceneManager.GetSceneByName(sceneName);
			if (!((Scene)(ref sceneByName)).IsValid() || !((Scene)(ref sceneByName)).isLoaded)
			{
				return false;
			}
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			foreach (GameObject val in rootGameObjects)
			{
				if (!Object.op_Implicit((Object)(object)val) || !val.activeInHierarchy)
				{
					continue;
				}
				if (((Object)val).name == "GordionXmas_Snowfall")
				{
					sceneSnowUp = HasActiveFlakes(val);
					if (sceneSnowUp)
					{
						return true;
					}
				}
				else if (((Object)val).name == "XmasTidewater")
				{
					Transform val2 = val.transform.Find("Xmas_Snowfall");
					if (Object.op_Implicit((Object)(object)val2) && ((Component)val2).gameObject.activeInHierarchy && HasActiveFlakes(((Component)val2).gameObject))
					{
						sceneSnowUp = true;
						return true;
					}
				}
			}
			return false;
		}

		private static bool HasActiveFlakes(GameObject go)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem component = go.GetComponent<ParticleSystem>();
			if (Object.op_Implicit((Object)(object)component))
			{
				EmissionModule emission = component.emission;
				return ((EmissionModule)(ref emission)).enabled;
			}
			return false;
		}
	}
	public static class SnowShader
	{
		public const string CoverBiasProperty = "_CoverBias";

		public const string BumpStrengthProperty = "_BumpStrength";

		public const string SeaHeightProperty = "_SeaHeight";

		public const float DustingBias = -0.13f;

		public const float PatchyBias = 0f;

		public const float FullBias = 0.2f;

		public static float CoverBiasFor(int amount)
		{
			if (amount > 0)
			{
				if (amount < 2)
				{
					return 0f;
				}
				return 0.2f;
			}
			return -0.13f;
		}

		public static float BumpStrengthFor(int quality)
		{
			if (quality > 0)
			{
				return 1f;
			}
			return 0f;
		}

		public static void Apply(Material material, float coverBias, float bumpStrength)
		{
			if (Object.op_Implicit((Object)(object)material))
			{
				material.SetFloat("_CoverBias", coverBias);
				material.SetFloat("_BumpStrength", Mathf.Clamp01(bumpStrength));
			}
		}
	}
	public static class SnowSteps
	{
		private struct PlayerStepState
		{
			public int SurfaceIndex;

			public bool StandingOnTerrain;
		}

		[HarmonyPatch]
		private static class Patches
		{
			[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepSound")]
			[HarmonyPrefix]
			private static void PlayerStepPrefix(PlayerControllerB __instance, bool ___standingOnTerrain, out PlayerStepState __state)
			{
				__state = new PlayerStepState
				{
					SurfaceIndex = __instance.currentFootstepSurfaceIndex,
					StandingOnTerrain = ___standingOnTerrain
				};
				inPlayerStep = ActiveForSteps && !__instance.isInsideFactory && !__instance.isInHangarShipRoom;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "GetCurrentMaterialStandingOn")]
			[HarmonyPostfix]
			private static void PlayerMaterialPostfix(PlayerControllerB __instance)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				if (!inPlayerStep)
				{
					return;
				}
				inPlayerStep = false;
				StartOfRound instance = StartOfRound.Instance;
				int num = FindSnowSurfaceIndex(instance);
				if (num < 0 || !TrySampleStepCover(Object.op_Implicit((Object)(object)__instance.thisPlayerBody) ? __instance.thisPlayerBody.position : ((Component)__instance).transform.position, instance, out var hit, out var cover))
				{
					return;
				}
				__instance.currentFootstepSurfaceIndex = num;
				int num2;
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					if (Object.op_Implicit((Object)(object)__instance.playerBodyAnimator))
					{
						AnimatorStateInfo currentAnimatorStateInfo = __instance.playerBodyAnimator.GetCurrentAnimatorStateInfo(0);
						num2 = (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsTag("Sprinting") ? 1 : 0);
					}
					else
					{
						num2 = 0;
					}
				}
				else
				{
					num2 = (__instance.isSprinting ? 1 : 0);
				}
				bool sprinting = (byte)num2 != 0;
				EmitPuff(((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal, cover, sprinting, landing: false, hardLanding: false);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepSound")]
			[HarmonyFinalizer]
			private static Exception PlayerStepFinalizer(Exception __exception, PlayerControllerB __instance, PlayerStepState __state, ref bool ___standingOnTerrain)
			{
				inPlayerStep = false;
				__instance.currentFootstepSurfaceIndex = __state.SurfaceIndex;
				___standingOnTerrain = __state.StandingOnTerrain;
				return __exception;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayHitGroundAudio")]
			[HarmonyPrefix]
			private static void PlayerLandPrefix(PlayerControllerB __instance, bool hitHard, float ___slimeSlipAudioVolumeSync, out int __state)
			{
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				__state = __instance.currentFootstepSurfaceIndex;
				if (ActiveForSteps && !__instance.isInsideFactory && !__instance.isInHangarShipRoom && (!((NetworkBehaviour)__instance).IsOwner || !(__instance.slipperyFloor > 0.5f)) && (((NetworkBehaviour)__instance).IsOwner || !(___slimeSlipAudioVolumeSync > 0f)))
				{
					StartOfRound instance = StartOfRound.Instance;
					int num = FindSnowSurfaceIndex(instance);
					if (num >= 0 && TrySampleStepCover(Object.op_Implicit((Object)(object)__instance.thisPlayerBody) ? __instance.thisPlayerBody.position : ((Component)__instance).transform.position, instance, out var hit, out var cover))
					{
						__instance.currentFootstepSurfaceIndex = num;
						EmitPuff(((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal, cover, sprinting: false, landing: true, hitHard);
					}
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayHitGroundAudio")]
			[HarmonyFinalizer]
			private static Exception PlayerLandFinalizer(Exception __exception, PlayerControllerB __instance, int __state)
			{
				__instance.currentFootstepSurfaceIndex = __state;
				return __exception;
			}

			[HarmonyPatch(typeof(MaskedPlayerEnemy), "PlayFootstepSound")]
			[HarmonyPrefix]
			private static void MaskedStepPrefix(MaskedPlayerEnemy __instance, int ___currentFootstepSurfaceIndex, out int __state)
			{
				__state = ___currentFootstepSurfaceIndex;
				inMaskedStep = ActiveForSteps && ((EnemyAI)__instance).isOutside;
			}

			[HarmonyPatch(typeof(MaskedPlayerEnemy), "GetMaterialStandingOn")]
			[HarmonyPostfix]
			private static void MaskedMaterialPostfix(MaskedPlayerEnemy __instance, ref int ___currentFootstepSurfaceIndex, bool ___sprinting)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				if (inMaskedStep)
				{
					inMaskedStep = false;
					StartOfRound instance = StartOfRound.Instance;
					int num = FindSnowSurfaceIndex(instance);
					if (num >= 0 && TrySampleStepCover(((Component)__instance).transform.position, instance, out var hit, out var cover))
					{
						___currentFootstepSurfaceIndex = num;
						EmitPuff(((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal, cover, ___sprinting, landing: false, hardLanding: false);
					}
				}
			}

			[HarmonyPatch(typeof(MaskedPlayerEnemy), "PlayFootstepSound")]
			[HarmonyFinalizer]
			private static Exception MaskedStepFinalizer(Exception __exception, ref int ___currentFootstepSurfaceIndex, int __state)
			{
				inMaskedStep = false;
				___currentFootstepSurfaceIndex = __state;
				return __exception;
			}
		}

		private const float MaxPuffDistanceSq = 1024f;

		private static readonly int UnlitColorId = Shader.PropertyToID("_UnlitColor");

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		private static Harmony ownedHarmony;

		private static bool patched;

		private static bool enabled = true;

		private static int quality = 1;

		private static float fade = 1f;

		private static Material puffMaterial;

		private static GameObject puffRoot;

		private static ParticleSystem puffSystem;

		private static FootstepSurface[] cachedSurfaces;

		private static int cachedSnowIndex = -1;

		private static bool inPlayerStep;

		private static bool inMaskedStep;

		private static bool ActiveForSteps
		{
			get
			{
				if (enabled && fade >= 0.25f)
				{
					return SnowCover.Active;
				}
				return false;
			}
		}

		public static void Install(AssetBundle bundle)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (ownedHarmony == null)
			{
				ownedHarmony = new Harmony("daniel.lethalcompany.snowday.fx");
			}
			Install(ownedHarmony, Object.op_Implicit((Object)(object)bundle) ? bundle.LoadAsset<Material>("Flakes") : null);
		}

		public static void Install(Harmony harmony, Material flakeMaterial = null)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)flakeMaterial) && !Object.op_Implicit((Object)(object)puffMaterial))
			{
				puffMaterial = new Material(flakeMaterial)
				{
					name = "SnowDay StepPuff (Instance)"
				};
				Color val = default(Color);
				((Color)(ref val))..ctor(0.76f, 0.81f, 0.88f, 0.44f);
				if (puffMaterial.HasProperty(UnlitColorId))
				{
					puffMaterial.SetColor(UnlitColorId, val);
				}
				if (puffMaterial.HasProperty(ColorId))
				{
					puffMaterial.SetColor(ColorId, val);
				}
			}
			if (!patched && harmony != null)
			{
				harmony.CreateClassProcessor(typeof(Patches)).Patch();
				patched = true;
			}
		}

		public static void Configure(bool stepsEnabled, int qualityLevel = 1, float fadeWeight = 1f)
		{
			enabled = stepsEnabled;
			quality = Mathf.Clamp(qualityLevel, 0, 2);
			fade = Mathf.Clamp01(fadeWeight);
			if ((!enabled || fade <= 0.01f) && Object.op_Implicit((Object)(object)puffSystem) && puffSystem.particleCount > 0)
			{
				puffSystem.Clear();
			}
		}

		public static void Clear()
		{
			if (Object.op_Implicit((Object)(object)puffSystem) && puffSystem.particleCount > 0)
			{
				puffSystem.Clear();
			}
		}

		public static void Uninstall()
		{
			if (ownedHarmony != null)
			{
				ownedHarmony.UnpatchSelf();
				ownedHarmony = null;
				patched = false;
			}
			if (Object.op_Implicit((Object)(object)puffRoot))
			{
				Object.Destroy((Object)(object)puffRoot);
			}
			puffRoot = null;
			puffSystem = null;
			if (Object.op_Implicit((Object)(object)puffMaterial))
			{
				Object.Destroy((Object)(object)puffMaterial);
			}
			puffMaterial = null;
		}

		private static int FindSnowSurfaceIndex(StartOfRound round)
		{
			if (!Object.op_Implicit((Object)(object)round) || round.footstepSurfaces == null)
			{
				return -1;
			}
			if (cachedSurfaces == round.footstepSurfaces && cachedSnowIndex >= 0)
			{
				return cachedSnowIndex;
			}
			cachedSurfaces = round.footstepSurfaces;
			cachedSnowIndex = -1;
			for (int i = 0; i < cachedSurfaces.Length; i++)
			{
				if (cachedSurfaces[i] != null && string.Equals(cachedSurfaces[i].surfaceTag, "Snow", StringComparison.OrdinalIgnoreCase))
				{
					cachedSnowIndex = i;
					break;
				}
			}
			return cachedSnowIndex;
		}

		private static bool TrySampleStepCover(Vector3 bodyOrigin, StartOfRound round, out RaycastHit hit, out float cover)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			cover = 0f;
			if (!Physics.Raycast(bodyOrigin + Vector3.up * 0.6f, Vector3.down, ref hit, 1.8f, round.walkableSurfacesMask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			if (SnowCover.TryGetCover(((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal, ((RaycastHit)(ref hit)).collider, out cover))
			{
				return cover >= 0.45f;
			}
			return false;
		}

		private static void EmitPuff(Vector3 point, Vector3 normal, float cover, bool sprinting, bool landing, bool hardLanding)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: 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_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: 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_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)puffMaterial))
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			Camera val = ((!Object.op_Implicit((Object)(object)instance)) ? null : (Object.op_Implicit((Object)(object)instance.activeCamera) ? instance.activeCamera : instance.localPlayerController?.gameplayCamera));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			Vector3 val2 = ((Component)val).transform.position - point;
			if (!(((Vector3)(ref val2)).sqrMagnitude > 1024f))
			{
				EnsurePuffSystem();
				int num = ((!landing) ? (sprinting ? 6 : 4) : (hardLanding ? 12 : 8));
				if (quality == 0)
				{
					num = Mathf.Max(2, num / 2);
				}
				else if (quality == 2)
				{
					num += 2;
				}
				Vector3 val3 = ((((Vector3)(ref normal)).sqrMagnitude > 0.01f) ? ((Vector3)(ref normal)).normalized : Vector3.up);
				float num2 = Mathf.Clamp01(cover * fade);
				float num3 = SnowfallFx.NightBlend();
				Color val4 = Color.Lerp(new Color(0.76f, 0.81f, 0.88f, 0.46f * num2), new Color(0.39f, 0.45f, 0.55f, 0.42f * num2), num3);
				if (puffMaterial.HasProperty(UnlitColorId))
				{
					puffMaterial.SetColor(UnlitColorId, val4);
				}
				if (puffMaterial.HasProperty(ColorId))
				{
					puffMaterial.SetColor(ColorId, val4);
				}
				Vector3 normalized = default(Vector3);
				for (int i = 0; i < num; i++)
				{
					float num4 = Random.Range(0f, MathF.PI * 2f);
					float num5 = (landing ? Random.Range(0.45f, 1.35f) : (sprinting ? Random.Range(0.28f, 0.85f) : Random.Range(0.16f, 0.52f)));
					((Vector3)(ref normalized))..ctor(Mathf.Cos(num4), 0f, Mathf.Sin(num4));
					val2 = normalized - Vector3.Dot(normalized, val3) * val3;
					normalized = ((Vector3)(ref val2)).normalized;
					EmitParams val5 = default(EmitParams);
					((EmitParams)(ref val5)).position = point + val3 * 0.04f + normalized * Random.Range(0.03f, 0.14f);
					((EmitParams)(ref val5)).velocity = normalized * num5 + val3 * (landing ? Random.Range(0.35f, 0.95f) : Random.Range(0.18f, 0.55f));
					((EmitParams)(ref val5)).startSize = Random.Range(0.048f, landing ? 0.115f : 0.088f);
					((EmitParams)(ref val5)).startLifetime = Random.Range(0.28f, landing ? 0.58f : 0.44f);
					((EmitParams)(ref val5)).rotation = Random.Range(0f, 360f);
					((EmitParams)(ref val5)).angularVelocity = Random.Range(-90f, 90f);
					EmitParams val6 = val5;
					puffSystem.Emit(val6, 1);
				}
			}
		}

		private static void EnsurePuffSystem()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)puffSystem))
			{
				puffRoot = new GameObject("Snow Day step puffs")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)puffRoot);
				puffSystem = puffRoot.AddComponent<ParticleSystem>();
				puffSystem.Stop(true, (ParticleSystemStopBehavior)0);
				MainModule main = puffSystem.main;
				((MainModule)(ref main)).loop = false;
				((MainModule)(ref main)).playOnAwake = false;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
				((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.28f);
				((MainModule)(ref main)).maxParticles = 256;
				((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)3;
				EmissionModule emission = puffSystem.emission;
				((EmissionModule)(ref emission)).enabled = false;
				ShapeModule shape = puffSystem.shape;
				((ShapeModule)(ref shape)).enabled = false;
				SizeOverLifetimeModule sizeOverLifetime = puffSystem.sizeOverLifetime;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
				AnimationCurve val = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
				{
					new Keyframe(0f, 0.55f),
					new Keyframe(0.35f, 1.15f),
					new Keyframe(1f, 0f)
				});
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val);
				LimitVelocityOverLifetimeModule limitVelocityOverLifetime = puffSystem.limitVelocityOverLifetime;
				((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).enabled = true;
				((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).dampen = 0.22f;
				((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit = MinMaxCurve.op_Implicit(0.35f);
				ParticleSystemRenderer component = puffRoot.GetComponent<ParticleSystemRenderer>();
				component.renderMode = (ParticleSystemRenderMode)0;
				((Renderer)component).sharedMaterial = puffMaterial;
				component.maxParticleSize = 0.04f;
				((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)component).receiveShadows = false;
			}
		}
	}
	internal sealed class HostState : IDisposable
	{
		private const string Ask = "SnowDay.Request.v1";

		private const string State = "SnowDay.State.v1";

		private readonly HashSet<ulong> listeners = new HashSet<ulong>();

		private readonly Holiday season;

		private NetworkManager session;

		private bool server;

		private bool known;

		private bool allowed;

		private int remoteMoon;

		private int sentMoon;

		private byte sentFlags = byte.MaxValue;

		private SnowAmount remoteAmount;

		private float nextAsk;

		internal SnowAmount Amount
		{
			get
			{
				if (!server)
				{
					return remoteAmount;
				}
				return Settings.Amount.Value;
			}
		}

		internal bool Allowed
		{
			get
			{
				if (Object.op_Implicit((Object)(object)session) && session.IsListening)
				{
					if (!server)
					{
						if (known && remoteMoon == MoonId(Settings.SceneName))
						{
							return allowed;
						}
						return false;
					}
					if (season.On)
					{
						return !Settings.IsSkipped(Settings.SceneName);
					}
					return false;
				}
				return false;
			}
		}

		internal HostState(Holiday season)
		{
			this.season = season;
		}

		private static int MoonId(string scene)
		{
			int num = 17;
			foreach (char c in scene)
			{
				num = num * 31 + c;
			}
			return num;
		}

		internal unsafe void Tick()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!Object.op_Implicit((Object)(object)singleton) || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				if (Object.op_Implicit((Object)(object)session) || known)
				{
					Dispose();
				}
				return;
			}
			if ((Object)(object)singleton != (Object)(object)session || server != singleton.IsServer)
			{
				Dispose();
				session = singleton;
				server = singleton.IsServer;
				singleton.OnClientDisconnectCallback += Disconnected;
				if (server)
				{
					singleton.CustomMessagingManager.RegisterNamedMessageHandler("SnowDay.Request.v1", new HandleNamedMessageDelegate(OnAsk));
				}
				else
				{
					singleton.CustomMessagingManager.RegisterNamedMessageHandler("SnowDay.State.v1", new HandleNamedMessageDelegate(OnState));
				}
			}
			int num = MoonId(Settings.SceneName);
			if (server)
			{
				byte b = Flags();
				if (num == sentMoon && b == sentFlags)
				{
					return;
				}
				sentMoon = num;
				sentFlags = b;
				{
					foreach (ulong listener in listeners)
					{
						Send(listener);
					}
					return;
				}
			}
			if (!singleton.IsConnectedClient || (known && remoteMoon == num) || !(Time.unscaledTime >= nextAsk))
			{
				return;
			}
			nextAsk = Time.unscaledTime + 3f;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(1, (Allocator)2, -1);
			try
			{
				singleton.CustomMessagingManager.SendNamedMessage("SnowDay.Request.v1", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private byte Flags()
		{
			return (byte)(((uint)Settings.Amount.Value << 1) | (uint)((season.On && !Settings.IsSkipped(Settings.SceneName)) ? 1 : 0));
		}

		private void OnAsk(ulong peer, FastBufferReader reader)
		{
			if (server && peer != 0L && session.ConnectedClients.ContainsKey(peer))
			{
				listeners.Add(peer);
				Send(peer);
			}
		}

		private unsafe void Send(ulong peer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
			try
			{
				int num = MoonId(Settings.SceneName);
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				byte b = Flags();
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				session.CustomMessagingManager.SendNamedMessage("SnowDay.State.v1", peer, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void OnState(ulong sender, FastBufferReader reader)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			if (!server && sender == 0L && ((FastBufferReader)(ref reader)).TryBeginRead(5))
			{
				int num = default(int);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
				byte b = default(byte);
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
				if (b >> 1 <= 2)
				{
					remoteMoon = num;
					remoteAmount = (SnowAmount)(b >> 1);
					allowed = (b & 1) != 0;
					known = true;
				}
			}
		}

		private void Disconnected(ulong peer)
		{
			if (server)
			{
				listeners.Remove(peer);
			}
			else if (peer == 0L || peer == session.LocalClientId)
			{
				Dispose();
			}
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)session))
			{
				session.OnClientDisconnectCallback -= Disconnected;
				CustomMessagingManager customMessagingManager = session.CustomMessagingManager;
				if (customMessagingManager != null)
				{
					customMessagingManager.UnregisterNamedMessageHandler(server ? "SnowDay.Request.v1" : "SnowDay.State.v1");
				}
			}
			session = null;
			known = false;
			server = false;
			nextAsk = 0f;
			listeners.Clear();
			sentFlags = byte.MaxValue;
		}
	}
	internal static class MenuHooks
	{
		internal const string Guid = "daniel.lethalcompany.modmenu";

		private const string Tab = "Snow Day";

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			MenuApi.Choice("Snow Day", "Snow", new string[3] { "Auto", "On", "Off" }, (Func<int, string>)delegate(int i)
			{
				Plugin.Season.Mode.Value = (ChristmasMode)i;
				return "snow " + Plugin.Season.Mode.Value;
			}, true, false, (Func<string>)null, "Auto follows the host's date, December 1 through January 6 inclusive.");
			MenuApi.Choice("Snow Day", "Amount", Enum.GetNames(typeof(SnowAmount)), (Func<int, string>)delegate(int i)
			{
				Settings.Amount.Value = (SnowAmount)i;
				return Settings.Amount.Value.ToString();
			}, true, false, (Func<string>)null, (string)null);
			MenuApi.Choice("Snow Day", "This moon", new string[2] { "Snow here", "Skip here" }, (Func<int, string>)delegate(int i)
			{
				string sceneName = Settings.SceneName;
				if (sceneName.Length == 0)
				{
					return "select a moon first";
				}
				Settings.SetSkipped(sceneName, i == 1);
				return sceneName + ((i == 1) ? " skipped" : " enabled");
			}, true, false, (Func<string>)null, (string)null);
			string[] dates = new string[3] { "", "12-24", "02-01" };
			MenuApi.Choice("Snow Day", "Test date", new string[3] { "Real date", "24 Dec", "1 Feb" }, (Func<int, string>)delegate(int i)
			{
				Plugin.Season.TestDate.Value = dates[i];
				return Plugin.Season.Why;
			}, true, false, (Func<string>)null, (string)null);
			MenuApi.Toggle("Snow Day", "Show snow (F8)", (Func<bool>)(() => Settings.Show.Value), (Func<bool, string>)delegate(bool on)
			{
				Settings.Show.Value = on;
				return (!on) ? "snow hidden" : "snow visible";
			}, false, false, (Func<string>)null, (string)null);
			MenuApi.Choice("Snow Day", "Falling snow", Enum.GetNames(typeof(FlakeAmount)), (Func<int, string>)delegate(int i)
			{
				Settings.Falling.Value = (FlakeAmount)i;
				return Settings.Falling.Value.ToString();
			}, false, false, (Func<string>)null, (string)null);
			MenuApi.Toggle("Snow Day", "Snow steps", (Func<bool>)(() => Settings.Steps.Value), (Func<bool, string>)delegate(bool on)
			{
				Settings.Steps.Value = on;
				return (!on) ? "snow steps off" : "snow steps on";
			}, false, false, (Func<string>)null, (string)null);
			MenuApi.Choice("Snow Day", "Quality", Enum.GetNames(typeof(SnowQuality)), (Func<int, string>)delegate(int i)
			{
				Settings.Quality.Value = (SnowQuality)i;
				return Settings.Quality.Value.ToString();
			}, false, false, (Func<string>)null, (string)null);
			MenuApi.Toggle("Snow Day", "Suppress flakes in current weather", (Func<bool>)(() => WeatherNames.Contains(Settings.MutedWeather.Value, WeatherNames.Current())), (Func<bool, string>)delegate(bool on)
			{
				List<string> list = new List<string>(Settings.MutedWeather.Value.Split(','));
				string weather = WeatherNames.Current();
				list.RemoveAll((string x) => string.IsNullOrWhiteSpace(x) || string.Equals(x.Trim(), weather, StringComparison.OrdinalIgnoreCase));
				if (on)
				{
					list.Add(weather);
				}
				Settings.MutedWeather.Value = string.Join(",", list);
				return weather + (on ? " flakes suppressed" : " flakes enabled");
			}, false, false, (Func<string>)(() => (Settings.SceneName.Length != 0) ? null : "select a moon first"), "Rainy, Stormy and Flooded always use their own weather.");
		}
	}
	[BepInPlugin("daniel.lethalcompany.snowday", "Snow Day", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal const string Version = "0.1.0";

		internal static Holiday Season;

		private HostState host;

		private AssetBundle bundle;

		private Material patchy;

		private SnowfallFx snowfall;

		private GroundField field;

		private IEnumerator<int> scan;

		private int landingHandle = -1;

		private bool alreadySnowy;

		private bool failed;

		private bool ready;

		private float alpha;

		private float bias;

		private Transform flood;

		private readonly Stopwatch budget = new Stopwatch();

		private void Awake()
		{
			Settings.Bind(((BaseUnityPlugin)this).Config);
			Season = new Holiday(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger, "SnowDay", delegate
			{
			});
			host = new HostState(Season);
			if (Chainloader.PluginInfos.ContainsKey("daniel.lethalcompany.modmenu"))
			{
				MenuHooks.Register();
			}
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "snowday");
			bundle = AssetBundle.LoadFromFile(text);
			patchy = (Object.op_Implicit((Object)(object)bundle) ? bundle.LoadAsset<Material>("Patchy") : null);
			if (!Object.op_Implicit((Object)(object)patchy))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Missing ground material in " + text));
				((Behaviour)this).enabled = false;
				return;
			}
			snowfall = SnowfallFx.FromBundle(bundle);
			try
			{
				SnowSteps.Install(bundle);
			}
			catch (Exception ex)
			{
				SnowSteps.Uninstall();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Snow step sounds unavailable: " + ex));
			}
		}

		private void Update()
		{
			try
			{
				host.Tick();
				Keyboard current = Keyboard.current;
				if (current != null && ((ButtonControl)current.f8Key).wasPressedThisFrame)
				{
					Settings.Show.Value = !Settings.Show.Value;
				}
				Tick();
			}
			catch (Exception ex)
			{
				Clear();
				if (!failed)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Snow disabled for this landing: " + ex));
				}
				failed = true;
			}
		}

		private void Tick()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (