Decompiled source of AtlyssSeasons v1.0.0

AtlyssSeasons.dll

Decompiled 10 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using AtlyssCommandLib.API;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CodeTalker;
using CodeTalker.Networking;
using CodeTalker.Packets;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using Nessie.ATLYSS.EasySettings;
using Nessie.ATLYSS.EasySettings.UIElements;
using Newtonsoft.Json;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AtlyssSeasons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AtlyssSeasons")]
[assembly: AssemblyTitle("AtlyssSeasons")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 AtlyssSeasons
{
	internal struct AmbientProfile
	{
		internal Color Colour;

		internal float Density;

		internal float Size;

		internal float RiseSpeed;

		internal float Drift;

		internal float Area;

		internal float Height;

		internal float SnapStep;

		internal bool Pulse;

		internal bool Spherical;

		internal bool Centred;

		internal float Stretch;

		internal bool Glow;

		internal Color[]? Palette;

		internal float MinDistance;

		internal float HeightOffset;

		internal bool GroundPinned;

		internal bool GroundOnly;

		internal float PlacedLife;

		internal bool HoldWhenStill;

		internal float Thickness;

		internal bool AvoidWater;

		internal float Lifetime;

		internal Color[]? MixColours;

		internal float MixChance;

		internal float SpawnDepth;

		internal float Flatten;
	}
	internal sealed class AmbientEffect
	{
		private struct Placement
		{
			internal Vector3 Centre;

			internal Vector3 Heading;

			internal float Minimum;

			internal float Reach;

			internal float Thickness;

			internal float HeightOffset;

			internal bool Moving;

			internal bool AvoidWater;
		}

		private readonly string _label;

		private readonly int _drawOrder;

		private Vector3 _lastSnap = new Vector3(float.MinValue, 0f, 0f);

		private GameObject? _host;

		private ParticleSystem? _system;

		private ParticleSystemRenderer? _renderer;

		private Material? _material;

		private int _appliedSignature;

		private int _granted;

		private float _restingNoise = 0.25f;

		private float _appliedLifetime;

		private float _appliedSize;

		private Particle[]? _live;

		private float _placeCarry;

		private float _lastPlaceAt = -1f;

		private float _stillSince = -1f;

		private bool _holding;

		private Vector3 _placeCentre = new Vector3(float.MinValue, 0f, 0f);

		private Placement _plan;

		private int _queued;

		private int _queuedAtTick;

		private float _queuedAt;

		private int _placePlaced;

		private int _placeSkipped;

		private bool _grounded;

		private bool _blendFailed;

		private float _thickness;

		internal int LiveParticles
		{
			get
			{
				if (!((Object)(object)_system == (Object)null))
				{
					return _system.particleCount;
				}
				return 0;
			}
		}

		internal bool Running
		{
			get
			{
				if ((Object)(object)_system != (Object)null)
				{
					return _system.isPlaying;
				}
				return false;
			}
		}

		internal AmbientEffect(string label, int drawOrder)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			_label = label;
			_drawOrder = drawOrder;
		}

		private void Create()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			if (!((Object)(object)_host != (Object)null))
			{
				_host = new GameObject("AtlyssSeasons_Ambient_" + _label)
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)_host);
				_system = _host.AddComponent<ParticleSystem>();
				_renderer = _host.GetComponent<ParticleSystemRenderer>();
				_material = new Material(FallingParticles.SharedShader())
				{
					name = "AtlyssSeasons_Ambient" + _label,
					hideFlags = (HideFlags)61
				};
				_material.mainTexture = (Texture)(object)FallingParticles.SharedDotTexture();
				FallingParticles.ApplyNeutralTint(_material, doubledAlpha: false);
				_blendFailed = !FallingParticles.MakeBlended(_material);
				if (_blendFailed)
				{
					ManualLogSource log = Plugin.Log;
					string[] obj = new string[5] { "[SeasonsAmbient] \"", null, null, null, null };
					Shader shader = _material.shader;
					obj[1] = ((shader != null) ? ((Object)shader).name : null) ?? "unknown";
					obj[2] = "\" cannot be made see-through, so ";
					obj[3] = _label;
					obj[4] = " would draw as opaque squares. It is being left undrawn instead.";
					log.LogError((object)string.Concat(obj));
				}
				((Renderer)_renderer).material = _material;
				((Renderer)_renderer).enabled = !_blendFailed;
				_renderer.alignment = (ParticleSystemRenderSpace)0;
				_renderer.sortMode = (ParticleSystemSortMode)0;
				((Renderer)_renderer).sortingOrder = _drawOrder;
				((Renderer)_renderer).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)_renderer).receiveShadows = false;
				_appliedSignature = 0;
			}
		}

		private unsafe int BuildSignature(AmbientProfile profile, int allowance)
		{
			int hashCode = _label.GetHashCode();
			hashCode = hashCode * 31 + ((object)(*(Color*)(&profile.Colour))/*cast due to .constrained prefix*/).GetHashCode();
			hashCode = hashCode * 31 + (profile.Glow ? 977 : 13);
			if (profile.Palette != null)
			{
				for (int i = 0; i < profile.Palette.Length; i++)
				{
					hashCode = hashCode * 31 + ((object)Unsafe.As<Color, Color>(ref profile.Palette[i])/*cast due to .constrained prefix*/).GetHashCode();
				}
			}
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Density * 100f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Size * 1000f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.RiseSpeed * 1000f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Drift * 1000f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Area);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Height);
			hashCode = hashCode * 31 + (profile.Pulse ? 61 : 7);
			hashCode = hashCode * 31 + (profile.Spherical ? 71 : 11);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.MinDistance * 10f);
			hashCode = hashCode * 31 + (profile.Centred ? 83 : 13);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Stretch * 100f);
			hashCode = hashCode * 31 + (profile.GroundOnly ? 911 : 17);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.PlacedLife);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Thickness * 10f);
			hashCode = hashCode * 31 + (profile.HoldWhenStill ? 197 : 23);
			hashCode = hashCode * 31 + (profile.AvoidWater ? 347 : 29);
			hashCode = hashCode * 31 + Mathf.RoundToInt(ResolvedLifetime(profile) * 100f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.MixChance * 1000f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.SpawnDepth * 10f);
			hashCode = hashCode * 31 + Mathf.RoundToInt(profile.Flatten * 10f);
			if (profile.MixColours != null)
			{
				for (int j = 0; j < profile.MixColours.Length; j++)
				{
					hashCode = hashCode * 31 + ((object)Unsafe.As<Color, Color>(ref profile.MixColours[j])/*cast due to .constrained prefix*/).GetHashCode();
				}
			}
			return hashCode * 31 + allowance;
		}

		private static float ResolvedLifetime(AmbientProfile profile)
		{
			if (profile.GroundOnly)
			{
				return Mathf.Max(2f, profile.PlacedLife);
			}
			return EffectLife.Resolve(profile.Lifetime, Mathf.Max(3f, profile.Height), Mathf.Max(0.01f, Mathf.Abs(profile.RiseSpeed)));
		}

		private void Configure(AmbientProfile profile, int allowance)
		{
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Expected O, but got Unknown
			//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_069c: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_system == (Object)null || (Object)(object)_renderer == (Object)null)
			{
				return;
			}
			if (_grounded != profile.GroundOnly && _system.particleCount > 0)
			{
				_system.Clear(true);
			}
			_grounded = profile.GroundOnly;
			int num = BuildSignature(profile, allowance);
			if (num == _appliedSignature)
			{
				return;
			}
			_appliedSignature = num;
			_granted = allowance;
			float num2 = Mathf.Max(6f, profile.Area);
			float num3 = Mathf.Max(3f, profile.Height);
			float speed = Mathf.Max(0.01f, Mathf.Abs(profile.RiseSpeed));
			float num4 = EffectLife.Resolve(profile.Lifetime, num3, speed);
			float num5 = Mathf.Max(1f, profile.Density);
			int num6 = Mathf.CeilToInt(num5 * num4 * 1.15f);
			if (num6 > allowance)
			{
				num5 = (float)allowance / 1.15f / num4;
				num6 = allowance;
			}
			if (_grounded)
			{
				num4 = Mathf.Max(2f, profile.PlacedLife);
				num5 = 0f;
				num6 = allowance;
			}
			if (_appliedLifetime > 0.01f && _system.particleCount > 0 && (!Mathf.Approximately(_appliedLifetime, num4) || !Mathf.Approximately(_appliedSize, profile.Size)))
			{
				RescaleLive(num4 / _appliedLifetime, (_appliedSize > 0.0001f) ? (profile.Size / _appliedSize) : 1f);
			}
			_appliedLifetime = num4;
			_appliedSize = profile.Size;
			_thickness = profile.Thickness;
			MainModule main = _system.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).prewarm = true;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).startSize3D = false;
			((MainModule)(ref main)).startSize = new MinMaxCurve(profile.Size * 0.6f, profile.Size * 1.4f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(num4);
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).maxParticles = Mathf.Max(20, num6);
			((MainModule)(ref main)).startColor = BuildStartColour(profile);
			if ((Object)(object)_material != (Object)null)
			{
				Texture val = (Texture)(object)(profile.Glow ? FallingParticles.SharedGlowTexture() : FallingParticles.SharedDotTexture());
				if (_material.mainTexture != val)
				{
					_material.mainTexture = val;
				}
			}
			if (profile.Stretch > 0.01f)
			{
				_renderer.renderMode = (ParticleSystemRenderMode)1;
				_renderer.lengthScale = profile.Stretch;
				_renderer.maxParticleSize = 4f;
				_renderer.velocityScale = 0f;
				_renderer.cameraVelocityScale = 0f;
			}
			else
			{
				_renderer.renderMode = (ParticleSystemRenderMode)0;
				_renderer.maxParticleSize = 0.5f;
			}
			EmissionModule emission = _system.emission;
			((EmissionModule)(ref emission)).enabled = !_grounded;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(num5);
			ShapeModule shape = _system.shape;
			((ShapeModule)(ref shape)).enabled = !_grounded;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)((!profile.Spherical) ? 5 : 0);
			bool flag = profile.MinDistance > 0.5f;
			float num7 = Mathf.Max(1f, num2 * 0.5f);
			if (flag)
			{
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radiusThickness = Mathf.Clamp01(1f - Mathf.Clamp(profile.MinDistance, 0f, num7 * 0.95f) / num7);
			}
			else
			{
				((ShapeModule)(ref shape)).radiusThickness = 1f;
			}
			((ShapeModule)(ref shape)).radius = ((profile.Spherical || flag) ? num7 : 1f);
			Vector3 scale = (Vector3)((profile.Spherical || flag) ? Vector3.one : (profile.Centred ? new Vector3(num2, num3, num2) : new Vector3(num2, Mathf.Max(0.1f, profile.SpawnDepth), num2)));
			if ((profile.Spherical || flag) && profile.Flatten > 0.01f)
			{
				scale.y = Mathf.Clamp(profile.Flatten / (2f * num7), 0.01f, 1f);
			}
			((ShapeModule)(ref shape)).scale = scale;
			((ShapeModule)(ref shape)).rotation = Vector3.zero;
			((ShapeModule)(ref shape)).position = Vector3.zero;
			VelocityOverLifetimeModule velocityOverLifetime = _system.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(0f - profile.Drift, profile.Drift);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(profile.RiseSpeed * 0.7f, profile.RiseSpeed * 1.3f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(0f - profile.Drift, profile.Drift);
			NoiseModule noise = _system.noise;
			((NoiseModule)(ref noise)).enabled = profile.Drift > 0.001f;
			((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(profile.Drift);
			_restingNoise = profile.Drift;
			((NoiseModule)(ref noise)).frequency = 0.12f;
			((NoiseModule)(ref noise)).scrollSpeed = MinMaxCurve.op_Implicit(0.2f);
			((NoiseModule)(ref noise)).damping = true;
			((NoiseModule)(ref noise)).quality = (ParticleSystemNoiseQuality)0;
			ColorOverLifetimeModule colorOverLifetime = _system.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val2 = new Gradient();
			GradientAlphaKey[] array = (GradientAlphaKey[])(object)((!profile.Pulse) ? new GradientAlphaKey[4]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.2f),
				new GradientAlphaKey(1f, 0.8f),
				new GradientAlphaKey(0f, 1f)
			} : new GradientAlphaKey[7]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.15f),
				new GradientAlphaKey(0.25f, 0.35f),
				new GradientAlphaKey(1f, 0.55f),
				new GradientAlphaKey(0.25f, 0.75f),
				new GradientAlphaKey(1f, 0.9f),
				new GradientAlphaKey(0f, 1f)
			});
			val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, array);
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val2);
			CollisionModule collision = _system.collision;
			((CollisionModule)(ref collision)).enabled = false;
			Plugin.LogInfoIfDebug($"[SeasonsAmbient] {_label} configured: rate={num5:0.#}, cap={num6}, life={num4:0.#}s.");
		}

		internal void Tick(bool shouldRun, AmbientProfile profile, int allowance)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			if (!shouldRun || allowance <= 0)
			{
				Pause();
				return;
			}
			Create();
			Configure(profile, allowance);
			if ((Object)(object)_system == (Object)null || (Object)(object)_host == (Object)null)
			{
				return;
			}
			Transform val = ViewPoint.Transform();
			if ((Object)(object)val == (Object)null)
			{
				Pause();
				return;
			}
			Player mainPlayer = Player._mainPlayer;
			Vector3 val2 = (((Object)(object)mainPlayer == (Object)null) ? val.position : ((Component)mainPlayer).transform.position);
			if (_grounded)
			{
				PlaceGrounded(profile, val2, Mathf.Max(0f, profile.Density));
				if (!_system.isPlaying && !_holding)
				{
					_system.Play();
				}
				return;
			}
			if (!profile.Centred)
			{
				val2.y += ((profile.RiseSpeed >= 0f) ? (0f - Mathf.Max(1f, profile.Height * 0.35f)) : Mathf.Max(3f, profile.Height * 0.8f));
			}
			if (profile.GroundPinned && GroundFinder.Below(val2 + Vector3.up * 5f, 250f, out var ground))
			{
				val2.y = ((RaycastHit)(ref ground)).point.y;
			}
			val2.y += profile.HeightOffset;
			if (!profile.Centred && profile.SpawnDepth > 0.1f)
			{
				val2.y += profile.SpawnDepth * 0.5f;
			}
			if (profile.SnapStep > 0.01f)
			{
				float snapStep = profile.SnapStep;
				val2.x = Mathf.Round(val2.x / snapStep) * snapStep;
				val2.y = Mathf.Round(val2.y / snapStep) * snapStep;
				val2.z = Mathf.Round(val2.z / snapStep) * snapStep;
			}
			if (profile.SnapStep > 0.01f && val2 != _lastSnap)
			{
				bool num = _lastSnap.x <= float.MinValue;
				_lastSnap = val2;
				if (!num)
				{
					MainModule main = _system.main;
					int num2 = Mathf.Clamp(((MainModule)(ref main)).maxParticles - _system.particleCount, 0, 900);
					if (num2 > 0)
					{
						_host.transform.position = val2;
						_system.Emit(num2);
					}
				}
			}
			_host.transform.position = val2;
			EmissionModule emission = _system.emission;
			if (!((EmissionModule)(ref emission)).enabled)
			{
				((EmissionModule)(ref emission)).enabled = true;
			}
			if (!_system.isPlaying)
			{
				_system.Play();
			}
		}

		internal void Gust(float strength)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_system == (Object)null) && _system.isPlaying)
			{
				NoiseModule noise = _system.noise;
				if (((NoiseModule)(ref noise)).enabled)
				{
					((NoiseModule)(ref noise)).scrollSpeed = MinMaxCurve.op_Implicit(0.2f + strength * 1.6f);
					((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(_restingNoise * (1f + strength * 2.5f));
				}
			}
		}

		private void RescaleLive(float life, float size)
		{
			if (!((Object)(object)_system == (Object)null))
			{
				int particleCount = _system.particleCount;
				if (_live == null || _live.Length < particleCount)
				{
					_live = (Particle[]?)(object)new Particle[particleCount];
				}
				int particles = _system.GetParticles(_live);
				for (int i = 0; i < particles; i++)
				{
					ref Particle reference = ref _live[i];
					((Particle)(ref reference)).startLifetime = ((Particle)(ref reference)).startLifetime * life;
					ref Particle reference2 = ref _live[i];
					((Particle)(ref reference2)).remainingLifetime = ((Particle)(ref reference2)).remainingLifetime * life;
					ref Particle reference3 = ref _live[i];
					((Particle)(ref reference3)).startSize = ((Particle)(ref reference3)).startSize * size;
				}
				_system.SetParticles(_live, particles);
			}
		}

		private static MinMaxGradient BuildStartColour(AmbientProfile profile)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (profile.MixColours != null && profile.MixColours.Length != 0 && profile.MixChance > 0.001f)
			{
				return BuildMixedColour(profile);
			}
			Color[] palette = profile.Palette;
			if (palette == null || palette.Length == 0)
			{
				return new MinMaxGradient(profile.Colour);
			}
			if (palette.Length == 1)
			{
				return new MinMaxGradient(new Color(palette[0].r, palette[0].g, palette[0].b, profile.Colour.a));
			}
			GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[Mathf.Min(palette.Length, 8)];
			GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[2];
			for (int i = 0; i < array.Length; i++)
			{
				float num = ((array.Length == 1) ? 0f : ((float)i / (float)(array.Length - 1)));
				array[i] = new GradientColorKey(palette[i], num);
			}
			array2[0] = new GradientAlphaKey(profile.Colour.a, 0f);
			array2[1] = new GradientAlphaKey(profile.Colour.a, 1f);
			Gradient val = new Gradient();
			val.SetKeys(array, array2);
			MinMaxGradient result = default(MinMaxGradient);
			((MinMaxGradient)(ref result))..ctor(val);
			((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
			return result;
		}

		private static MinMaxGradient BuildMixedColour(AmbientProfile profile)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			Color[] mixColours = profile.MixColours;
			float[] array = MistMix.KeyTimes(profile.MixChance, mixColours.Length);
			GradientColorKey[] array2 = (GradientColorKey[])(object)new GradientColorKey[array.Length];
			array2[0] = new GradientColorKey(profile.Colour, array[0]);
			for (int i = 1; i < array.Length; i++)
			{
				array2[i] = new GradientColorKey(mixColours[i - 1], array[i]);
			}
			Gradient val = new Gradient
			{
				mode = (GradientMode)1
			};
			val.SetKeys(array2, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(profile.Colour.a, 0f),
				new GradientAlphaKey(profile.Colour.a, 1f)
			});
			MinMaxGradient result = default(MinMaxGradient);
			((MinMaxGradient)(ref result))..ctor(val);
			((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
			return result;
		}

		internal void ClearNow()
		{
			//IL_0031: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_system == (Object)null))
			{
				Release();
				_system.Clear(true);
				_lastSnap = new Vector3(float.MinValue, float.MinValue, float.MinValue);
				_placeCarry = 0f;
				_queued = 0;
				_lastPlaceAt = -1f;
				_stillSince = -1f;
				_placeCentre = new Vector3(float.MinValue, 0f, 0f);
			}
		}

		private void PlaceGrounded(AmbientProfile profile, Vector3 centre, float rate)
		{
			//IL_00dd: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_system == (Object)null)
			{
				return;
			}
			if (_queued > 0)
			{
				PlaceQueued(_queued);
			}
			float num = Mathf.Max(6f, profile.Area) * 0.5f;
			float minimum = Mathf.Clamp(profile.MinDistance, 0f, num * 0.95f);
			float thickness = Mathf.Max(1f, (profile.Thickness > 0.01f) ? profile.Thickness : profile.Height);
			float num2 = ((_lastPlaceAt < 0f) ? Time.deltaTime : (Time.unscaledTime - _lastPlaceAt));
			_lastPlaceAt = Time.unscaledTime;
			_placeCarry += rate * Mathf.Clamp(num2, 0f, 1f);
			bool flag = _placeCentre.x <= float.MinValue;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(centre.x, 0f, centre.z);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(_placeCentre.x, 0f, _placeCentre.z);
			float num3 = (flag ? 0f : Vector3.Distance(val, val2));
			Vector3 heading = Vector3.zero;
			if (num3 > 0.01f)
			{
				Vector3 val3 = val - val2;
				heading = ((Vector3)(ref val3)).normalized;
				float num4 = rate * Mathf.Max(1f, profile.PlacedLife);
				float num5 = Mathf.Min(1f, num3 * 2f * num / (MathF.PI * num * num));
				_placeCarry += num4 * num5;
			}
			if (num3 > 0.01f || flag)
			{
				_placeCentre = centre;
				_stillSince = -1f;
				Release();
			}
			else if (_stillSince < 0f)
			{
				_stillSince = Time.unscaledTime;
			}
			if (!profile.HoldWhenStill)
			{
				Release();
			}
			if (profile.HoldWhenStill && _stillSince >= 0f && Time.unscaledTime - _stillSince >= 2f)
			{
				_placeCarry = 0f;
				if (!_holding)
				{
					_holding = true;
					_system.Pause(true);
				}
				return;
			}
			int num6 = Mathf.FloorToInt(_placeCarry);
			if (num6 > 0)
			{
				_placeCarry -= num6;
				MainModule main = _system.main;
				int num7 = ((MainModule)(ref main)).maxParticles - _system.particleCount;
				num6 = Mathf.Clamp(num6, 0, Mathf.Min(num7, (num3 > 0.01f) ? 400 : 40));
				if (num6 > 0)
				{
					_plan = new Placement
					{
						Centre = centre,
						Heading = heading,
						Minimum = minimum,
						Reach = num,
						Thickness = thickness,
						HeightOffset = profile.HeightOffset,
						Moving = (num3 > 0.01f),
						AvoidWater = profile.AvoidWater
					};
					_queued = num6;
					_queuedAtTick = num6;
					_queuedAt = Time.unscaledTime;
				}
			}
		}

		internal void PumpPlacement()
		{
			if (_queued > 0)
			{
				if (!_grounded)
				{
					_queued = 0;
					return;
				}
				float interval = Mathf.Max(0.1f, Plugin.ModConfig.ApplyIntervalSeconds.Value);
				PlaceQueued(PlacementPace.Step(_queued, _queuedAtTick, Time.unscaledDeltaTime, interval, Time.unscaledTime - _queuedAt));
			}
		}

		private void PlaceQueued(int count)
		{
			//IL_0031: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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)
			count = Mathf.Min(count, _queued);
			_queued -= count;
			if ((Object)(object)_system == (Object)null || count <= 0)
			{
				return;
			}
			EmitParams val = default(EmitParams);
			((EmitParams)(ref val)).applyShapeToPosition = false;
			EmitParams val2 = val;
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < count; i++)
			{
				float num = Random.value * MathF.PI * 2f;
				float num2 = Mathf.Lerp(_plan.Minimum, _plan.Reach, Mathf.Sqrt(Random.value));
				if (_plan.Moving && Random.value < 0.75f && Vector3.Dot(new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)), _plan.Heading) < 0f)
				{
					num += MathF.PI;
				}
				float num3 = _plan.Centre.x + Mathf.Cos(num) * num2;
				float num4 = _plan.Centre.z + Mathf.Sin(num) * num2;
				PerfStats.CountRay();
				if (!Physics.Raycast(new Vector3(num3, _plan.Centre.y + _plan.Thickness + 60f, num4), Vector3.down, ref val3, _plan.Thickness * 2f + 280f, -1, (QueryTriggerInteraction)1) || (_plan.AvoidWater && (Object)(object)((RaycastHit)(ref val3)).collider != (Object)null && ((Component)((RaycastHit)(ref val3)).collider).gameObject.layer == WaterSurfaces.WaterLayer()))
				{
					_placeSkipped++;
					continue;
				}
				float value = Random.value;
				float num5 = ((RaycastHit)(ref val3)).point.y + _plan.HeightOffset + _plan.Thickness * value * value;
				((EmitParams)(ref val2)).position = new Vector3(num3, num5, num4);
				_system.Emit(val2, 1);
				_placePlaced++;
			}
		}

		private void Release()
		{
			if (_holding)
			{
				_holding = false;
				if ((Object)(object)_system != (Object)null && _system.isPaused)
				{
					_system.Play(true);
				}
			}
		}

		internal void Pause()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_system == (Object)null))
			{
				Release();
				_queued = 0;
				EmissionModule emission = _system.emission;
				if (((EmissionModule)(ref emission)).enabled)
				{
					((EmissionModule)(ref emission)).enabled = false;
				}
				if (_grounded)
				{
					_placeCarry = 0f;
					_placeCentre = new Vector3(float.MinValue, 0f, 0f);
				}
			}
		}

		internal void Destroy()
		{
			_holding = false;
			_queued = 0;
			if ((Object)(object)_system != (Object)null && _system.isPlaying)
			{
				_system.Stop(true, (ParticleSystemStopBehavior)0);
			}
			if ((Object)(object)_host != (Object)null)
			{
				Object.Destroy((Object)(object)_host);
				_host = null;
				_system = null;
				_renderer = null;
			}
			if ((Object)(object)_material != (Object)null)
			{
				Object.Destroy((Object)(object)_material);
				_material = null;
			}
			_appliedSignature = 0;
			_granted = 0;
			_appliedLifetime = 0f;
		}

		internal string DescribeMaterial()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_material == (Object)null)
			{
				return _label + ": no material";
			}
			Texture mainTexture = _material.mainTexture;
			string[] obj = new string[15]
			{
				_label,
				": ",
				_blendFailed ? "NOT DRAWN, could not be made see-through, " : "",
				"shader=\"",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			Shader shader = _material.shader;
			obj[4] = ((shader != null) ? ((Object)shader).name : null) ?? "none";
			obj[5] = "\", texture=\"";
			obj[6] = ((mainTexture != null) ? ((Object)mainTexture).name : null) ?? "none";
			obj[7] = "\" ";
			obj[8] = (((Object)(object)mainTexture == (Object)null) ? "" : (mainTexture.width + "px"));
			obj[9] = ", render=";
			ParticleSystemRenderer? renderer = _renderer;
			obj[10] = ((renderer != null) ? ((object)renderer.renderMode/*cast due to .constrained prefix*/).ToString() : null) ?? "none";
			obj[11] = ", blend src=";
			obj[12] = (_material.HasProperty("_SrcBlend") ? _material.GetFloat("_SrcBlend").ToString("0") : "n/a");
			obj[13] = " dst=";
			obj[14] = (_material.HasProperty("_DstBlend") ? _material.GetFloat("_DstBlend").ToString("0") : "n/a");
			return string.Concat(obj);
		}

		internal string Order()
		{
			return $"{_label} {(((Object)(object)_renderer == (Object)null) ? _drawOrder : ((Renderer)_renderer).sortingOrder)}";
		}

		internal string Describe()
		{
			if ((Object)(object)_system == (Object)null)
			{
				return _label + "=off";
			}
			if (!_grounded)
			{
				return $"{_label}: {LiveParticles}/{_granted}";
			}
			return string.Format("{0}: {1}/{2}, placed {3} skipped {4} (no ground, or only water, under them), layer {5:0.#} tall{6}", _label, LiveParticles, _granted, _placePlaced, _placeSkipped, _thickness, _holding ? ", held" : "");
		}
	}
	internal static class AmbientEffects
	{
		private sealed class NameList
		{
			private readonly List<string> Names = new List<string>();

			private string _raw = string.Empty;

			private void Rebuild(string list)
			{
				if (string.Equals(list, _raw, StringComparison.Ordinal))
				{
					return;
				}
				_raw = list ?? string.Empty;
				Names.Clear();
				string[] array = _raw.Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length > 0)
					{
						Names.Add(text);
					}
				}
			}

			internal bool Matches(string? mapName, string list, bool blankMatchesAll)
			{
				Rebuild(list);
				if (Names.Count == 0)
				{
					return blankMatchesAll;
				}
				string currentRegionName = RegionWatcher.CurrentRegionName;
				for (int i = 0; i < Names.Count; i++)
				{
					string value = Names[i];
					if (!string.IsNullOrWhiteSpace(mapName) && mapName.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return true;
					}
					if (currentRegionName.Length > 0 && currentRegionName.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return true;
					}
				}
				return false;
			}
		}

		private sealed class ColourList
		{
			private string? _raw;

			private Color[]? _colours;

			internal Color[]? Get(string raw)
			{
				if (string.Equals(raw, _raw, StringComparison.Ordinal))
				{
					return _colours;
				}
				_raw = raw;
				_colours = Parse(raw);
				return _colours;
			}

			private static Color[]? Parse(string raw)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				if (string.IsNullOrWhiteSpace(raw))
				{
					return null;
				}
				string[] array = raw.Split(',');
				List<Color> list = new List<Color>();
				Color item = default(Color);
				for (int i = 0; i < array.Length; i++)
				{
					if (ColorUtility.TryParseHtmlString(array[i].Trim(), ref item))
					{
						list.Add(item);
					}
				}
				if (list.Count != 0)
				{
					return list.ToArray();
				}
				return null;
			}
		}

		private static readonly AmbientEffect Fog = new AmbientEffect("Fog", 1);

		private static readonly AmbientEffect GroundMist = new AmbientEffect("GroundMist", 2);

		private static readonly AmbientEffect SoulMist = new AmbientEffect("SoulMist", 3);

		private static readonly AmbientEffect HeatWave = new AmbientEffect("HeatWave", 4);

		private static readonly AmbientEffect Shimmer = new AmbientEffect("Shimmer", 5);

		private static readonly AmbientEffect Dust = new AmbientEffect("Dust", 6);

		private static readonly AmbientEffect Rays = new AmbientEffect("GodRays", 7);

		private static readonly AmbientEffect SpringSouls = new AmbientEffect("SpringSouls", 8);

		private static readonly AmbientEffect GroundSouls = new AmbientEffect("GroundSouls", 9);

		private static readonly AmbientEffect SoulFireSouls = new AmbientEffect("SoulFire", 10);

		private static readonly AmbientEffect Fireflies = new AmbientEffect("Fireflies", 11);

		private static readonly AmbientEffect Fairies = new AmbientEffect("Fairies", 12);

		private static readonly AmbientEffect Embers = new AmbientEffect("Embers", 13);

		private static readonly NameList DustMaps = new NameList();

		private static readonly NameList FireflyMaps = new NameList();

		private static readonly NameList SpringSoulMaps = new NameList();

		private static readonly NameList GroundSoulMaps = new NameList();

		private static readonly NameList EmberMaps = new NameList();

		private static readonly NameList FairyMaps = new NameList();

		private static readonly NameList RayMaps = new NameList();

		private static readonly NameList RayNeverIn = new NameList();

		private static readonly NameList HeatMaps = new NameList();

		private static Color _dustColour = new Color(0.7882f, 0.7608f, 0.6902f, 1f);

		private static string _dustRaw = string.Empty;

		private static readonly Dictionary<string, Color> Parsed = new Dictionary<string, Color>();

		private static readonly ColourList FairyColours = new ColourList();

		private static readonly ColourList SoulMistColours = new ColourList();

		private static readonly Color[] DefaultSoulMist = (Color[])(object)new Color[1]
		{
			new Color(0.58f, 0.44f, 0.72f)
		};

		private static bool _soulMistShown;

		private static string _groundSoulsNow = "not checked yet";

		private static string _lastMap = string.Empty;

		internal static string GroundSoulsNow => _groundSoulsNow;

		internal static int LiveParticles => Dust.LiveParticles + Fireflies.LiveParticles + SpringSouls.LiveParticles + GroundSouls.LiveParticles + SoulFireSouls.LiveParticles + SoulMist.LiveParticles + Embers.LiveParticles + Fog.LiveParticles + GroundMist.LiveParticles + Shimmer.LiveParticles + Fairies.LiveParticles + Rays.LiveParticles + HeatWave.LiveParticles;

		private static Color Colour(string raw, Color fallback, float opacity)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			raw = (raw ?? string.Empty).Trim();
			if (raw.Length > 0)
			{
				Color val = default(Color);
				if (Parsed.TryGetValue(raw, out var value))
				{
					fallback = value;
				}
				else if (ColorUtility.TryParseHtmlString(raw, ref val))
				{
					fallback = val;
					Parsed[raw] = val;
				}
			}
			fallback.a = Mathf.Clamp01(opacity);
			return fallback;
		}

		private static void TonightsSouls(SeasonsConfig config, out bool rising, out bool fire, out bool asMist)
		{
			if (config.AutumnGroundSoulsNewStyleEachNight.Value)
			{
				int num = NightPick.Style((int)SeasonsAuthority.ActiveSeason, WorldStateStore.SeasonElapsedGameDays);
				rising = num == 0;
				fire = num == 1;
				asMist = num == 2;
			}
			else if (config.AutumnGroundSoulsAllStyles.Value)
			{
				rising = true;
				fire = true;
				asMist = true;
			}
			else
			{
				asMist = config.AutumnGroundSoulsAsMist.Value;
				fire = config.AutumnGroundSoulsAsSoulFire.Value && !asMist;
				rising = !asMist && !fire;
			}
		}

		private static string ExplainGroundSouls(SeasonsConfig config, bool wanted, bool rising, bool fire, bool asMist, bool mist)
		{
			if (HolidayDay.Active)
			{
				return "A holiday night: its own souls are rising.";
			}
			if (wanted)
			{
				string text = ((rising && fire && asMist) ? "rising, soul fire and mist" : (rising ? "rising" : (fire ? "soul fire" : "mist")));
				string text2 = (config.AutumnGroundSoulsNewStyleEachNight.Value ? ", a new style each night" : string.Empty);
				if (!asMist || !config.SoulsAsMistUseMistSettings.Value || mist)
				{
					return "Showing: " + text + text2 + ".";
				}
				return "Tonight: " + text + text2 + ". As mist in mist's own settings they only show while ground mist is out, and it is not out here today.";
			}
			if (!config.AutumnGroundSouls.Value)
			{
				return "Off.";
			}
			if (!Allowed() || !SeasonsAuthority.ShouldApplyVisuals())
			{
				return "Seasons are not drawing anything here.";
			}
			if (!config.EffectsInEverySeason.Value && SeasonsAuthority.ActiveSeason != Season.Autumn)
			{
				return "Only in autumn, and it is " + SeasonTable.Name(SeasonsAuthority.ActiveSeason) + ".";
			}
			if (!SeasonsGameAccess.WorldClockSettled)
			{
				return "Waiting on the world clock.";
			}
			if (!config.AutumnGroundSoulsByDay.Value && !NightNow())
			{
				return "Only at night, and it is day. Ground Souls By Day lets them out in the day too.";
			}
			return "Not on this map, or this place is left out.";
		}

		private static bool Allowed()
		{
			SeasonsConfig modConfig = Plugin.ModConfig;
			if (modConfig != null && modConfig.AmbientEffectsEnabled.Value && !modConfig.LowSpecMode.Value)
			{
				return modConfig.ClientVisualsEnabled.Value;
			}
			return false;
		}

		private static bool PlaceAllows()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			SeasonsConfig modConfig = Plugin.ModConfig;
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			if ((Object)(object)localMapInstance == (Object)null)
			{
				return false;
			}
			if (!InstanceGate.IsVanillaMap(localMapInstance))
			{
				return false;
			}
			DungeonFilter.Rebuild(modConfig.DungeonMaps.Value);
			if ((DungeonFilter.IsExcluded(localMapInstance._mapName) || (int)localMapInstance._zoneType == 2) && !SeasonsAuthority.ApplyToDungeons)
			{
				return false;
			}
			if (!modConfig.AmbientEffectsIndoors.Value && (RegionWatcher.InsideInteriorRegion || IndoorProbe.Indoors))
			{
				return false;
			}
			return true;
		}

		internal static bool NightOutside()
		{
			return NightNow();
		}

		private static bool NightNow()
		{
			return SeasonsGameAccess.NightConfirmed;
		}

		private static bool DustWanted()
		{
			SeasonsConfig modConfig = Plugin.ModConfig;
			if (!Allowed() || !modConfig.CatacombsDust.Value || !SeasonsAuthority.ShouldApplyVisuals())
			{
				return false;
			}
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			if ((Object)(object)localMapInstance != (Object)null)
			{
				return DustMaps.Matches(localMapInstance._mapName, modConfig.CatacombsDustMaps.Value, blankMatchesAll: false);
			}
			return false;
		}

		private static bool Wanted(bool enabled, Season season, bool nightOnly, NameList maps, string list, bool dayOnly = false, bool ignoreSeason = false)
		{
			if (!Allowed() || !enabled || !SeasonsAuthority.ShouldApplyVisuals())
			{
				return false;
			}
			if (!Plugin.ModConfig.EffectsInEverySeason.Value && !ignoreSeason && SeasonsAuthority.ActiveSeason != season)
			{
				return false;
			}
			if ((nightOnly || dayOnly) && !SeasonsGameAccess.WorldClockSettled)
			{
				return false;
			}
			if (nightOnly && !NightNow())
			{
				return false;
			}
			if (dayOnly && NightNow())
			{
				return false;
			}
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			if ((Object)(object)localMapInstance == (Object)null || MapFilter.IsExcludedHere(localMapInstance) || !PlaceAllows())
			{
				return false;
			}
			return maps.Matches(localMapInstance._mapName, list, blankMatchesAll: true);
		}

		private static AmbientProfile SoulFire(SeasonsConfig config)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0035: 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)
			//IL_0045: 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_0054: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			Color val = Colour(config.AutumnSoulFireColor.Value, new Color(0.66f, 0.77f, 0.75f), 0.85f);
			return new AmbientProfile
			{
				Colour = val,
				Palette = (Color[]?)(object)new Color[3]
				{
					Color.Lerp(val, Color.white, 0.55f),
					val,
					new Color(val.r * 0.55f, val.g * 0.65f, val.b * 0.8f, val.a)
				},
				Density = config.AutumnSoulFireDensity.Value,
				Size = config.AutumnSoulFireSize.Value,
				RiseSpeed = 1.1f,
				Drift = 0.12f,
				Area = config.AutumnSoulFireArea.Value,
				Height = 3f,
				Lifetime = config.AutumnSoulFireLife.Value,
				GroundPinned = true,
				Pulse = true,
				Glow = true,
				Stretch = 1.6f
			};
		}

		internal static void ReloadNow()
		{
			Dust.ClearNow();
			Fireflies.ClearNow();
			SpringSouls.ClearNow();
			GroundSouls.ClearNow();
			SoulFireSouls.ClearNow();
			SoulMist.ClearNow();
			Embers.ClearNow();
			Fog.ClearNow();
			GroundMist.ClearNow();
			Shimmer.ClearNow();
			Fairies.ClearNow();
			Rays.ClearNow();
			HeatWave.ClearNow();
			_lastMap = string.Empty;
		}

		internal static void PumpPlacement()
		{
			Dust.PumpPlacement();
			Fireflies.PumpPlacement();
			SpringSouls.PumpPlacement();
			GroundSouls.PumpPlacement();
			SoulFireSouls.PumpPlacement();
			SoulMist.PumpPlacement();
			Embers.PumpPlacement();
			Fog.PumpPlacement();
			GroundMist.PumpPlacement();
			Shimmer.PumpPlacement();
			Fairies.PumpPlacement();
			Rays.PumpPlacement();
			HeatWave.PumpPlacement();
		}

		private static void ClearOnMapChange()
		{
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			string text = (((Object)(object)localMapInstance == (Object)null) ? string.Empty : (localMapInstance._mapName ?? string.Empty));
			if (!string.Equals(text, _lastMap, StringComparison.Ordinal))
			{
				_lastMap = text;
				Dust.ClearNow();
				Fireflies.ClearNow();
				SpringSouls.ClearNow();
				GroundSouls.ClearNow();
				SoulFireSouls.ClearNow();
				SoulMist.ClearNow();
				Embers.ClearNow();
				Fog.ClearNow();
				GroundMist.ClearNow();
				Shimmer.ClearNow();
				Fairies.ClearNow();
				Rays.ClearNow();
				HeatWave.ClearNow();
			}
		}

		internal static void Tick()
		{
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0725: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_070b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0922: Unknown result type (might be due to invalid IL or missing references)
			//IL_092c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0931: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0afd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bcb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bdf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cde: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cfe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d0d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d84: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d97: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ecb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ed5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f05: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ffc: Unknown result type (might be due to invalid IL or missing references)
			//IL_1001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ef6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f00: Unknown result type (might be due to invalid IL or missing references)
			//IL_120f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1219: Unknown result type (might be due to invalid IL or missing references)
			//IL_121e: Unknown result type (might be due to invalid IL or missing references)
			SeasonsConfig modConfig = Plugin.ModConfig;
			ClearOnMapChange();
			if (modConfig != null)
			{
				FogWeather.Tick();
				MistWeather.Tick();
				Season activeSeason = SeasonsAuthority.ActiveSeason;
				bool num = Allowed() && SeasonsAuthority.ShouldApplyVisuals() && PlaceAllows();
				bool flag = modConfig.FogMistOnOtherMaps.Value || !InstanceGate.IsModdedMap(SeasonsGameAccess.LocalMapInstance);
				bool flag2 = num && flag && FogWeather.Active;
				bool flag3 = num && flag && MistWeather.Active && (MistWeather.RegionSaysDay || (!MistWeather.RegionSaysNight && (!SeasonsAuthority.Fog<bool>(modConfig.GroundMistNightOnly) || (MistWeather.FromList && SeasonsAuthority.Fog<bool>(modConfig.MistAlwaysIgnoresNight)))) || (SeasonsGameAccess.WorldClockSettled && NightNow()));
				bool flag4 = num && modConfig.WinterShimmerEnabled.Value && (modConfig.EffectsInEverySeason.Value || activeSeason == Season.Winter);
				bool flag5 = DustWanted();
				bool flag6 = Wanted(modConfig.CaveFireflies.Value, Season.Summer, nightOnly: false, FireflyMaps, modConfig.CaveFirefliesMaps.Value);
				bool flag7 = Wanted(modConfig.SpringSoulLights.Value, Season.Spring, !modConfig.SpringSoulLightsByDay.Value, SpringSoulMaps, modConfig.SpringSoulLightsMaps.Value);
				bool flag8 = Wanted(modConfig.AutumnGroundSouls.Value, Season.Autumn, !modConfig.AutumnGroundSoulsByDay.Value, GroundSoulMaps, modConfig.AutumnGroundSoulsMaps.Value, dayOnly: false, HolidayDay.Active);
				TonightsSouls(modConfig, out var rising, out var fire, out var asMist);
				bool active = HolidayDay.Active;
				bool flag9 = (active && !flag8) || (flag8 && rising);
				bool flag10 = flag8 && fire;
				bool num2 = flag8 && asMist;
				bool flag11 = num2 && modConfig.SoulsAsMistUseMistSettings.Value;
				bool flag12 = num2 && !modConfig.SoulsAsMistUseMistSettings.Value;
				_groundSoulsNow = ExplainGroundSouls(modConfig, flag8, rising, fire, asMist, flag3);
				_soulMistShown = flag11 && flag3;
				bool flag13 = flag11 && (float)NightPick.Roll((int)activeSeason, WorldStateStore.SeasonElapsedGameDays) < Mathf.Clamp(modConfig.SoulMistFullChance.Value, 0f, 100f);
				bool flag14 = Wanted(modConfig.SummerEmbers.Value, Season.Summer, nightOnly: false, EmberMaps, modConfig.SummerEmbersMaps.Value);
				bool flag15 = Wanted(modConfig.SpringCaveFairies.Value, Season.Spring, nightOnly: false, FairyMaps, modConfig.SpringCaveFairiesMaps.Value);
				bool value = modConfig.GodRaysAtNight.Value;
				bool flag16 = Wanted(modConfig.GodRays.Value, Season.Summer, nightOnly: false, RayMaps, modConfig.GodRaysMaps.Value, !value) && !RayNeverIn.Matches(SeasonsGameAccess.LocalMapInstance?._mapName, modConfig.GodRaysExcludedMaps.Value, blankMatchesAll: false);
				bool flag17 = Wanted(modConfig.HeatWaveEnabled.Value, Season.Summer, nightOnly: false, HeatMaps, string.Empty, !modConfig.HeatWaveAtNight.Value);
				int num3 = (flag5 ? 1 : 0) + (flag6 ? 1 : 0) + (flag7 ? 1 : 0) + (flag9 ? 1 : 0) + (flag10 ? 1 : 0) + (flag12 ? 1 : 0) + (flag14 ? 1 : 0) + (flag2 ? 1 : 0) + (flag3 ? 1 : 0) + (flag4 ? 1 : 0) + (flag15 ? 1 : 0) + (flag16 ? 1 : 0) + (flag17 ? 1 : 0);
				int num4 = Mathf.Clamp(modConfig.AmbientMaxParticles.Value, 50, 16000);
				if (modConfig.LowSpecMode.Value)
				{
					num4 = Mathf.Max(50, num4 / 3);
				}
				int num5 = num3 + (flag2 ? 1 : 0) + (flag3 ? 1 : 0);
				int num6 = ((num5 != 0) ? (num4 / num5) : 0);
				int allowance = num6 * 2;
				int allowance2 = num6 * 2;
				Dust.Tick(flag5, new AmbientProfile
				{
					Colour = DustColour(),
					Density = modConfig.CatacombsDustDensity.Value,
					Size = modConfig.CatacombsDustSize.Value,
					RiseSpeed = -0.12f,
					Drift = 0.25f,
					Area = modConfig.CatacombsDustArea.Value,
					Height = 9f,
					Lifetime = modConfig.CatacombsDustLife.Value
				}, num6);
				Fireflies.Tick(flag6, new AmbientProfile
				{
					Colour = Colour(modConfig.CaveFirefliesColor.Value, new Color(0.78f, 0.88f, 0.42f), 0.85f),
					Density = modConfig.CaveFirefliesDensity.Value,
					Size = modConfig.CaveFirefliesSize.Value,
					RiseSpeed = 0.05f,
					Drift = 0.55f,
					Area = modConfig.CaveFirefliesArea.Value,
					Height = 8f,
					Pulse = modConfig.CaveFirefliesPulse.Value,
					Lifetime = modConfig.CaveFirefliesLife.Value
				}, num6);
				bool flag18 = SeasonsAuthority.Fog<bool>(modConfig.FogHighQuality);
				RegionFog.Override values;
				bool flag19 = RegionFog.TryGet(out values);
				Color colour = (Color)((flag19 && values.HasColour) ? new Color(values.Colour.r, values.Colour.g, values.Colour.b, SeasonsAuthority.Fog<float>(modConfig.FogOpacity)) : FogWeather.ColourFor(activeSeason));
				float num7 = (flag19 ? RegionFog.Or(values.Density, SeasonsAuthority.Fog<float>(modConfig.FogDensity)) : SeasonsAuthority.Fog<float>(modConfig.FogDensity)) * HolidayDay.FogScale;
				float num8 = (flag19 ? RegionFog.Or(values.Size, SeasonsAuthority.Fog<float>(modConfig.FogSize)) : SeasonsAuthority.Fog<float>(modConfig.FogSize));
				Fog.Tick(flag2, new AmbientProfile
				{
					Colour = colour,
					Density = num7 * (flag18 ? 2.2f : 1f),
					Size = num8 * (flag18 ? 0.6f : 1f),
					RiseSpeed = 0.01f,
					Drift = 0.04f,
					Area = (flag19 ? RegionFog.Or(values.Area, SeasonsAuthority.Fog<float>(modConfig.FogArea)) : SeasonsAuthority.Fog<float>(modConfig.FogArea)),
					MinDistance = SeasonsAuthority.Fog<float>(modConfig.FogMinDistance),
					HeightOffset = SeasonsAuthority.Fog<float>(modConfig.FogHeight),
					Thickness = SeasonsAuthority.Fog<float>(modConfig.FogThickness),
					Height = SeasonsAuthority.Fog<float>(modConfig.FogThickness),
					Spherical = flag18,
					Centred = true,
					GroundOnly = true,
					PlacedLife = SeasonsAuthority.Fog<float>(modConfig.FogParticleLife),
					HoldWhenStill = SeasonsAuthority.Fog<bool>(modConfig.FogHoldWhenStill)
				}, allowance);
				RegionFog.Override values2;
				bool num9 = RegionFog.Mist.TryGet(out values2);
				Color colour2 = (Color)((num9 && values2.HasColour) ? new Color(values2.Colour.r, values2.Colour.g, values2.Colour.b, SeasonsAuthority.Fog<float>(modConfig.MistOpacity)) : MistWeather.ColourFor(activeSeason));
				float density = (num9 ? RegionFog.Mist.Or(values2.Density, SeasonsAuthority.Fog<float>(modConfig.GroundMistDensity)) : SeasonsAuthority.Fog<float>(modConfig.GroundMistDensity));
				float size = (num9 ? RegionFog.Mist.Or(values2.Size, SeasonsAuthority.Fog<float>(modConfig.GroundMistSize)) : SeasonsAuthority.Fog<float>(modConfig.GroundMistSize));
				float area = (num9 ? RegionFog.Mist.Or(values2.Area, SeasonsAuthority.Fog<float>(modConfig.GroundMistArea)) : SeasonsAuthority.Fog<float>(modConfig.GroundMistArea));
				GroundMist.Tick(flag3, new AmbientProfile
				{
					Colour = colour2,
					Density = density,
					Size = size,
					RiseSpeed = 0.02f,
					Drift = 0.08f,
					Area = area,
					MinDistance = SeasonsAuthority.Fog<float>(modConfig.MistMinDistance),
					HeightOffset = SeasonsAuthority.Fog<float>(modConfig.MistHeight),
					GroundPinned = true,
					Height = SeasonsAuthority.Fog<float>(modConfig.MistThickness),
					Thickness = SeasonsAuthority.Fog<float>(modConfig.MistThickness),
					GroundOnly = true,
					PlacedLife = SeasonsAuthority.Fog<float>(modConfig.MistParticleLife),
					HoldWhenStill = SeasonsAuthority.Fog<bool>(modConfig.MistHoldWhenStill),
					MixColours = ((!flag11) ? null : ((active && modConfig.HolidayMistColours.Value) ? Holidays.SoulColours : (SoulMistColours.Get(modConfig.AutumnGroundMistColor.Value) ?? DefaultSoulMist))),
					MixChance = ((!flag11) ? 0f : (flag13 ? 1f : Mathf.Clamp01(modConfig.SoulMistChance.Value / 100f)))
				}, allowance2);
				Fairies.Tick(flag15, new AmbientProfile
				{
					Colour = Colour(modConfig.SpringCaveFairiesColor.Value, new Color(0.95f, 0.65f, 0.82f), 0.9f),
					Density = modConfig.SpringCaveFairiesDensity.Value,
					Size = modConfig.SpringCaveFairiesSize.Value,
					RiseSpeed = 0.06f,
					Drift = 0.85f,
					Area = modConfig.SpringCaveFairiesArea.Value,
					Height = 12f,
					Pulse = true,
					Glow = true,
					Palette = FairyColours.Get(modConfig.SpringCaveFairiesPalette.Value),
					Lifetime = modConfig.SpringCaveFairiesLife.Value
				}, num6);
				Shimmer.Tick(flag4, new AmbientProfile
				{
					Colour = Colour(modConfig.WinterShimmerColor.Value, new Color(0.97f, 0.99f, 1f), 1f),
					Density = modConfig.WinterShimmerDensity.Value,
					Size = modConfig.WinterShimmerSize.Value,
					RiseSpeed = 0.5f,
					Drift = 0.05f,
					Area = modConfig.WinterShimmerArea.Value,
					Height = 12f,
					Pulse = true,
					Glow = true,
					Stretch = 3.5f,
					GroundOnly = true,
					AvoidWater = true,
					Thickness = 1.5f,
					PlacedLife = modConfig.WinterShimmerLife.Value
				}, num6);
				SpringSouls.Tick(flag7, new AmbientProfile
				{
					Colour = Colour(modConfig.SpringSoulLightsColor.Value, new Color(0.75f, 0.91f, 0.88f), 0.7f),
					Density = modConfig.SpringSoulLightsDensity.Value,
					Size = modConfig.SpringSoulLightsSize.Value,
					RiseSpeed = 0.22f,
					Drift = 0.35f,
					Area = modConfig.SpringSoulLightsArea.Value,
					Height = 12f,
					Lifetime = modConfig.SpringSoulLightsLife.Value,
					GroundPinned = true,
					HeightOffset = 0.3f
				}, num6);
				GroundSouls.Tick(flag9, new AmbientProfile
				{
					Colour = (Color)(active ? new Color(Holidays.SoulColour.r, Holidays.SoulColour.g, Holidays.SoulColour.b, 0.8f) : Colour(modConfig.AutumnGroundSoulsColor.Value, new Color(0.66f, 0.77f, 0.75f), 0.65f)),
					Palette = (active ? Holidays.SoulColours : null),
					Density = modConfig.AutumnGroundSoulsDensity.Value + (active ? modConfig.HolidaySoulDensity.Value : 0f),
					Size = (active ? modConfig.HolidaySoulSize.Value : modConfig.AutumnGroundSoulsSize.Value),
					RiseSpeed = 0.5f,
					Drift = 0.18f,
					Area = modConfig.AutumnGroundSoulsArea.Value,
					Height = 14f,
					Lifetime = modConfig.AutumnGroundSoulsLife.Value,
					GroundPinned = true,
					HeightOffset = 0.5f,
					SpawnDepth = 4f
				}, num6);
				AmbientProfile profile = SoulFire(modConfig);
				if (active)
				{
					Color[] soulColours = Holidays.SoulColours;
					Color val = soulColours[0];
					profile.Colour = new Color(val.r, val.g, val.b, profile.Colour.a);
					profile.Palette = soulColours;
					profile.Density += modConfig.HolidaySoulDensity.Value;
				}
				SoulFireSouls.Tick(flag10, profile, num6);
				Color[] array = ((active && modConfig.HolidayMistColours.Value) ? Holidays.SoulColours : (SoulMistColours.Get(modConfig.AutumnGroundMistColor.Value) ?? DefaultSoulMist));
				Color val2 = array[0];
				SoulMist.Tick(flag12, new AmbientProfile
				{
					Colour = new Color(val2.r, val2.g, val2.b, 0.3f),
					Palette = array,
					Density = modConfig.AutumnGroundSoulsDensity.Value,
					Size = modConfig.AutumnGroundSoulsSize.Value * 26f,
					RiseSpeed = 0.02f,
					Drift = 0.06f,
					Area = modConfig.AutumnGroundSoulsArea.Value,
					Height = SeasonsAuthority.Fog<float>(modConfig.MistThickness),
					GroundOnly = true,
					Thickness = SeasonsAuthority.Fog<float>(modConfig.MistThickness),
					HeightOffset = SeasonsAuthority.Fog<float>(modConfig.MistHeight),
					MinDistance = SeasonsAuthority.Fog<float>(modConfig.MistMinDistance),
					PlacedLife = SeasonsAuthority.Fog<float>(modConfig.MistParticleLife),
					HoldWhenStill = SeasonsAuthority.Fog<bool>(modConfig.MistHoldWhenStill)
				}, num6);
				Rays.Tick(flag16, new AmbientProfile
				{
					Colour = ((value && NightNow()) ? Colour(modConfig.GodRaysNightColor.Value, new Color(0.79f, 0.85f, 0.94f), 0.13f) : Colour(modConfig.GodRaysColor.Value, new Color(1f, 0.95f, 0.81f), 0.16f)),
					Density = modConfig.GodRaysDensity.Value,
					Size = modConfig.GodRaysSize.Value,
					RiseSpeed = -0.35f,
					Drift = 0f,
					Area = modConfig.GodRaysArea.Value,
					Height = Mathf.Max(10f, modConfig.GodRaysArea.Value * 0.4f),
					SnapStep = modConfig.FogSnapStep.Value,
					Centred = true,
					Stretch = modConfig.GodRaysLength.Value,
					Lifetime = modConfig.GodRaysLife.Value
				}, num6);
				HeatWave.Tick(flag17, new AmbientProfile
				{
					Colour = Colour(modConfig.HeatWaveColor.Value, new Color(1f, 0.94f, 0.85f), modConfig.HeatWaveOpacity.Value),
					Density = modConfig.HeatWaveDensity.Value,
					Size = modConfig.HeatWaveSize.Value,
					RiseSpeed = 0.35f,
					Drift = 0.5f,
					Area = modConfig.HeatWaveArea.Value,
					MinDistance = ((modConfig.HeatWaveMinDistance.Value > 0.01f) ? modConfig.HeatWaveMinDistance.Value : (modConfig.HeatWaveArea.Value * 0.45f)),
					Height = Mathf.Max(10f, modConfig.HeatWaveArea.Value * 0.3f),
					Centred = true,
					Lifetime = modConfig.HeatWaveLife.Value,
					Flatten = modConfig.HeatWaveThickness.Value,
					HeightOffset = modConfig.HeatWaveThickness.Value * 0.25f
				}, num6);
				if (modConfig.WindGusts.Value)
				{
					float num10 = Mathf.PerlinNoise(Time.time * 0.14f * Mathf.Clamp(modConfig.WindGustFrequency.Value, 0.1f, 5f), 0.37f);
					num10 = Mathf.Clamp01((num10 - 0.45f) * 2.4f) * Mathf.Clamp(modConfig.WindGustStrength.Value, 0f, 4f);
					Dust.Gust(num10);
					Fireflies.Gust(num10);
					SpringSouls.Gust(num10);
					GroundSouls.Gust(num10);
					SoulMist.Gust(num10);
					Embers.Gust(num10);
					Fog.Gust(num10);
					GroundMist.Gust(num10);
					Fairies.Gust(num10);
					HeatWave.Gust(num10);
				}
				Embers.Tick(flag14, new AmbientProfile
				{
					Colour = Colour(modConfig.SummerEmbersColor.Value, new Color(0.94f, 0.63f, 0.31f), 0.75f),
					Density = modConfig.SummerEmbersDensity.Value,
					Size = modConfig.SummerEmbersSize.Value,
					RiseSpeed = 0.16f,
					Drift = 0.62f,
					Area = modConfig.SummerEmbersArea.Value,
					Height = 10f,
					Lifetime = modConfig.SummerEmbersLife.Value
				}, num6);
			}
		}

		private static Color DustColour()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			string text = Plugin.ModConfig.CatacombsDustColor.Value ?? string.Empty;
			if (!string.Equals(text, _dustRaw, StringComparison.Ordinal))
			{
				_dustRaw = text;
				ConfigWarnings.Begin("SeasonsAmbient.CatacombsDustColor");
				Color dustColour = default(Color);
				if (ColorUtility.TryParseHtmlString(text.Trim(), ref dustColour))
				{
					_dustColour = dustColour;
				}
				else if (text.Trim().Length > 0)
				{
					ConfigWarnings.Warn("SeasonsAmbient.CatacombsDustColor", "[SeasonsAmbient] CatacombsDustColor \"" + text + "\" is not a valid colour, keeping the previous one.");
				}
			}
			Color dustColour2 = _dustColour;
			if (Plugin.ModConfig.DustSeasonColours.Value)
			{
				switch (SeasonsAuthority.ActiveSeason)
				{
				case Season.Spring:
					((Color)(ref dustColour2))..ctor(0.72f, 0.72f, 0.7f);
					break;
				case Season.Summer:
					((Color)(ref dustColour2))..ctor(0.3f, 0.28f, 0.26f);
					break;
				case Season.Autumn:
					((Color)(ref dustColour2))..ctor(0.55f, 0.66f, 0.47f);
					break;
				case Season.Winter:
					((Color)(ref dustColour2))..ctor(0.78f, 0.84f, 0.9f);
					break;
				}
			}
			dustColour2.a = Mathf.Clamp01(Plugin.ModConfig.CatacombsDustOpacity.Value);
			return dustColour2;
		}

		internal static void Restore()
		{
			Dust.Destroy();
			Fireflies.Destroy();
			SpringSouls.Destroy();
			GroundSouls.Destroy();
			SoulFireSouls.Destroy();
			SoulMist.Destroy();
			Embers.Destroy();
			Fog.Destroy();
			GroundMist.Destroy();
			Shimmer.Destroy();
			Fairies.Destroy();
			Rays.Destroy();
			HeatWave.Destroy();
			FogWeather.Reset();
			MistWeather.Reset();
		}

		internal static string DescribeMaterials()
		{
			return "ambient materials: " + Fairies.DescribeMaterial() + " | " + Fog.DescribeMaterial() + " | " + Shimmer.DescribeMaterial() + " | drawn in order: " + string.Join(", ", Fog.Order(), GroundMist.Order(), SoulMist.Order(), HeatWave.Order(), Shimmer.Order(), Dust.Order(), Rays.Order(), SpringSouls.Order(), GroundSouls.Order(), SoulFireSouls.Order(), Fireflies.Order(), Fairies.Order(), Embers.Order());
		}

		internal static string Describe()
		{
			SeasonsConfig modConfig = Plugin.ModConfig;
			if (modConfig == null)
			{
				return "ambient: unavailable";
			}
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			string text = (((Object)(object)localMapInstance == (Object)null) ? "map=none" : MapRegistry.Describe(localMapInstance._mapName));
			string currentRegionName = RegionWatcher.CurrentRegionName;
			bool flag = (Object)(object)localMapInstance != (Object)null && DustMaps.Matches(localMapInstance._mapName, modConfig.CatacombsDustMaps.Value, blankMatchesAll: false);
			return string.Format("ambient: {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, soul mist={13}, night={14}, placeAllows={15}, budget={16}, enabled={17}, {18}, region=\"{19}\", dustMatches={20}", Dust.Describe(), Fireflies.Describe(), SpringSouls.Describe(), GroundSouls.Describe(), SoulFireSouls.Describe(), SoulMist.Describe(), Embers.Describe(), Fog.Describe(), GroundMist.Describe(), Shimmer.Describe(), Fairies.Describe(), Rays.Describe(), HeatWave.Describe(), _soulMistShown ? $"{modConfig.SoulMistChance.Value:0}% of the mist" : "off", NightNow(), PlaceAllows(), modConfig.AmbientMaxParticles.Value, modConfig.AmbientEffectsEnabled.Value, text, (currentRegionName.Length == 0) ? "none" : currentRegionName, flag);
		}
	}
	internal static class AreaLog
	{
		private static string? _path;

		private static string Path()
		{
			if (_path != null)
			{
				return _path;
			}
			string text = System.IO.Path.Combine(Paths.ConfigPath, "AtlyssSeasons");
			try
			{
				if (!Directory.Exists(text))
				{
					Directory.CreateDirectory(text);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[SeasonsAreas] Could not create the areas folder: " + ex.Message));
			}
			_path = System.IO.Path.Combine(text, "areas.txt");
			return _path;
		}

		internal static void Write()
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("ATLYSS Seasons marked areas");
				stringBuilder.AppendLine($"written {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("A zone is a box placed by standing at its entrance and facing in.");
				stringBuilder.AppendLine("A boundary is a straight line splitting a map into a vanilla side and a seasonal side.");
				stringBuilder.AppendLine();
				int length = stringBuilder.Length;
				SeasonZone.AppendReadable(stringBuilder);
				SeasonBoundary.AppendReadable(stringBuilder);
				if (stringBuilder.Length == length)
				{
					stringBuilder.AppendLine("Nothing is marked yet.");
				}
				File.WriteAllText(Path(), stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[SeasonsAreas] Could not write the areas file: " + ex.Message));
			}
		}
	}
	internal sealed class AreaOverlay : MonoBehaviour
	{
		private static readonly List<Vector3> Points = new List<Vector3>();

		private static readonly List<Color> Colours = new List<Color>();

		private static Material? _material;

		private static int _extentKey;

		private static Bounds _extent;

		private static bool _hasExtent;

		private static readonly List<Vector3> LabelAt = new List<Vector3>();

		private static readonly List<string> LabelText = new List<string>();

		private static GUIStyle? _labelStyle;

		private static Material? LineMaterial()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0063: Expected O, but got Unknown
			if ((Object)(object)_material != (Object)null)
			{
				return _material;
			}
			Shader val = Shader.Find("Hidden/Internal-Colored") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			_material = new Material(val)
			{
				name = "AtlyssSeasons_AreaOverlay",
				hideFlags = (HideFlags)61
			};
			_material.SetInt("_SrcBlend", 5);
			_material.SetInt("_DstBlend", 10);
			_material.SetInt("_Cull", 0);
			_material.SetInt("_ZWrite", 0);
			_material.SetInt("_ZTest", 8);
			return _material;
		}

		private void OnRenderObject()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.ModConfig == null || !Plugin.ModConfig.ShowAreaOutlines.Value)
			{
				return;
			}
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			if ((Object)(object)localMapInstance == (Object)null)
			{
				return;
			}
			Points.Clear();
			Colours.Clear();
			SeasonZone.CollectOutline(localMapInstance._mapName, Points, Colours);
			Bounds bounds;
			bool hasExtent = TryExtent(localMapInstance, out bounds);
			SeasonBoundary.CollectOutline(localMapInstance._mapName, ViewPoint.Position(), bounds, hasExtent, Points, Colours);
			if (Points.Count == 0)
			{
				return;
			}
			Material val = LineMaterial();
			if (!((Object)(object)val == (Object)null))
			{
				val.SetPass(0);
				GL.PushMatrix();
				GL.MultMatrix(Matrix4x4.identity);
				GL.Begin(1);
				for (int i = 0; i + 1 < Points.Count; i += 2)
				{
					GL.Color(Colours[i / 2]);
					GL.Vertex(Points[i]);
					GL.Vertex(Points[i + 1]);
				}
				GL.End();
				GL.PopMatrix();
			}
		}

		private static bool TryExtent(MapInstance local, out Bounds bounds)
		{
			//IL_0024: 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_009f: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)local).GetInstanceID();
			if (_hasExtent && instanceID == _extentKey)
			{
				bounds = _extent;
				return true;
			}
			bounds = default(Bounds);
			Renderer[] array = SeasonsGameAccess.EnvironmentRenderers(local);
			if (array == null || array.Length == 0)
			{
				return false;
			}
			bool flag = false;
			int num = Mathf.Min(array.Length, 4000);
			for (int i = 0; i < num; i++)
			{
				Renderer val = array[i];
				if (!((Object)(object)val == (Object)null) && val.enabled)
				{
					Bounds bounds2 = val.bounds;
					if (!flag)
					{
						bounds = bounds2;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(bounds2);
					}
				}
			}
			if (!flag)
			{
				return false;
			}
			_extentKey = instanceID;
			_extent = bounds;
			_hasExtent = true;
			return true;
		}

		internal static void Invalidate()
		{
			_hasExtent = false;
			_extentKey = 0;
		}

		internal static void AddLabel(Vector3 position, string text)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			LabelAt.Add(position);
			LabelText.Add(text);
		}

		private void OnGUI()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_00a2: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.ModConfig == null || !Plugin.ModConfig.ShowAreaOutlines.Value)
			{
				return;
			}
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			if ((Object)(object)localMapInstance == (Object)null)
			{
				return;
			}
			Camera val = ViewPoint.Camera();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			LabelAt.Clear();
			LabelText.Clear();
			SeasonZone.CollectLabels(localMapInstance._mapName);
			if (LabelAt.Count == 0)
			{
				return;
			}
			Rect val3 = default(Rect);
			for (int i = 0; i < LabelAt.Count; i++)
			{
				Vector3 val2 = val.WorldToScreenPoint(LabelAt[i]);
				if (!(val2.z <= 0f))
				{
					((Rect)(ref val3))..ctor(val2.x - 150f, (float)Screen.height - val2.y - 12f, 300f, 24f);
					GUI.color = new Color(0f, 0f, 0f, 0.85f);
					GUI.Label(new Rect(((Rect)(ref val3)).x + 1f, ((Rect)(ref val3)).y + 1f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), LabelText[i], LabelStyle());
					GUI.color = Color.white;
					GUI.Label(val3, LabelText[i], LabelStyle());
				}
			}
			GUI.color = Color.white;
		}

		private static GUIStyle LabelStyle()
		{
			//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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (_labelStyle != null)
			{
				return _labelStyle;
			}
			_labelStyle = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 13,
				fontStyle = (FontStyle)1,
				wordWrap = false
			};
			_labelStyle.normal.textColor = Color.white;
			return _labelStyle;
		}

		internal static void AddGrid(Vector3[] corners, Color colour, List<Vector3> points, List<Color> colours)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Plugin.ModConfig.AreaGridDivisions.Value, 0, 12);
			if (num < 2)
			{
				return;
			}
			Color item = default(Color);
			((Color)(ref item))..ctor(colour.r, colour.g, colour.b, colour.a * 0.55f);
			int[][] array = new int[6][]
			{
				new int[4] { 0, 1, 3, 2 },
				new int[4] { 4, 5, 7, 6 },
				new int[4] { 0, 1, 4, 5 },
				new int[4] { 3, 2, 7, 6 },
				new int[4] { 0, 3, 4, 7 },
				new int[4] { 1, 2, 5, 6 }
			};
			for (int i = 0; i < array.Length; i++)
			{
				int num2 = array[i][0];
				int num3 = array[i][1];
				int num4 = array[i][2];
				int num5 = array[i][3];
				for (int j = 1; j < num; j++)
				{
					float num6 = (float)j / (float)num;
					points.Add(Vector3.Lerp(corners[num2], corners[num3], num6));
					points.Add(Vector3.Lerp(corners[num4], corners[num5], num6));
					colours.Add(item);
					points.Add(Vector3.Lerp(corners[num2], corners[num4], num6));
					points.Add(Vector3.Lerp(corners[num3], corners[num5], num6));
					colours.Add(item);
				}
			}
		}

		internal static void AddBox(Vector3[] corners, Color colour, List<Vector3> points, List<Color> colours)
		{
			//IL_001c: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			int[] array = new int[24]
			{
				0, 1, 1, 2, 2, 3, 3, 0, 4, 5,
				5, 6, 6, 7, 7, 4, 0, 4, 1, 5,
				2, 6, 3, 7
			};
			for (int i = 0; i + 1 < array.Length; i += 2)
			{
				points.Add(corners[array[i]]);
				points.Add(corners[array[i + 1]]);
				colours.Add(colour);
			}
		}

		internal static void Destroy()
		{
			if (!((Object)(object)_material == (Object)null))
			{
				Object.Destroy((Object)(object)_material);
				_material = null;
			}
		}
	}
	internal static class BugReports
	{
		internal const string FileName = "Seasons Bug Reports.txt";

		private const string DraftName = "Seasons Bug Report Draft.txt";

		private static readonly UTF8Encoding Utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

		internal static string MainFolder
		{
			get
			{
				string text = null;
				try
				{
					text = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				}
				catch (Exception)
				{
					text = null;
				}
				return Path.Combine(string.IsNullOrEmpty(text) ? Paths.PluginPath : text, "Bug Reports");
			}
		}

		internal static string BackupFolder => Path.Combine(Paths.BepInExRootPath, "AtlyssSeasons Bug Reports (backup)");

		private static string DraftFile => Path.Combine(MainFolder, "Seasons Bug Report Draft.txt");

		internal static string MainPath(string fileName)
		{
			return Path.Combine(MainFolder, fileName);
		}

		internal static List<ReportFileInfo> Files()
		{
			return ReportFiles.List(MainFolder, BackupFolder);
		}

		internal static string NewestFile()
		{
			return ReportFiles.Newest(MainFolder, BackupFolder, "Seasons Bug Reports.txt");
		}

		internal static string NewFileName()
		{
			return ReportFiles.NewFileName(MainFolder, BackupFolder, DateTime.Now);
		}

		internal static ReportSaveResult Save(string fileName, Func<int, string> build)
		{
			return ReportFiles.Save(MainFolder, BackupFolder, fileName, build);
		}

		internal static ReportSaveResult SaveQuick(string text, string subject, List<ReportSection> sections)
		{
			string title = ReportText.OneLine(text);
			if (title.Length > 60)
			{
				title = title.Substring(0, 57) + "...";
			}
			return Save(NewestFile(), (int number) => ReportText.Block(number, DateTime.Now, "1.0.0", subject, string.Empty, title, text, sections));
		}

		internal static int NextNumber(string fileName)
		{
			return ReportFiles.NextNumber(Path.Combine(MainFolder, fileName), Path.Combine(BackupFolder, fileName));
		}

		internal static void SaveDraft(string draft)
		{
			try
			{
				Directory.CreateDirectory(MainFolder);
				File.WriteAllText(DraftFile, draft, Utf8);
			}
			catch (Exception ex)
			{
				Plugin.LogInfoIfDebug("[SeasonsReport] Draft not written: " + ex.Message);
			}
		}

		internal static string LoadDraft()
		{
			try
			{
				return File.Exists(DraftFile) ? File.ReadAllText(DraftFile, Utf8) : string.Empty;
			}
			catch (Exception ex)
			{
				Plugin.LogInfoIfDebug("[SeasonsReport] Draft not read: " + ex.Message);
				return string.Empty;
			}
		}

		internal static void ClearDraft()
		{
			try
			{
				if (File.Exists(DraftFile))
				{
					File.WriteAllText(DraftFile, string.Empty, Utf8);
				}
			}
			catch (Exception ex)
			{
				Plugin.LogInfoIfDebug("[SeasonsReport] Draft not cleared: " + ex.Message);
			}
		}

		internal static string OpenFolder(bool backup, string fileName)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			string text = (backup ? BackupFolder : MainFolder);
			string text2 = Path.Combine(text, ReportFiles.IsReportFile(fileName) ? fileName : "Seasons Bug Reports.txt");
			try
			{
				Directory.CreateDirectory(text);
				if ((int)Application.platform == 2)
				{
					string arguments = (File.Exists(text2) ? ("/select,\"" + text2 + "\"") : ("\"" + text + "\""));
					Process.Start(new ProcessStartInfo("explorer.exe", arguments)
					{
						UseShellExecute = true
					})?.Dispose();
					return string.Empty;
				}
				Application.OpenURL(new Uri(text + Path.DirectorySeparatorChar).AbsoluteUri);
				return string.Empty;
			}
			catch (Exception ex)
			{
				try
				{
					Application.OpenURL(new Uri(text + Path.DirectorySeparatorChar).AbsoluteUri);
					return string.Empty;
				}
				catch (Exception)
				{
					return ex.Message;
				}
			}
		}

		internal static List<string> WhereLines()
		{
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			SeasonsConfig modConfig = Plugin.ModConfig;
			Player mainPlayer = Player._mainPlayer;
			MapInstance localMapInstance = SeasonsGameAccess.LocalMapInstance;
			bool flag = PlayerLookup.InSession();
			string arg = (PlayerLookup.IsHeadless() ? "dedicated server" : (PlayerLookup.AmHost() ? "host" : (flag ? "client" : "not in a game")));
			int qualityLevel = QualitySettings.GetQualityLevel();
			string[] names = QualitySettings.names;
			string text = ((qualityLevel >= 0 && qualityLevel < names.Length) ? names[qualityLevel] : qualityLevel.ToString());
			List<string> list = new List<string>();
			list.Add(string.Format("Seasons {0}, signature {1}, protocol {2}, config model {3}", "1.0.0", "ATLYSSSEASONS-1.0.0-RELEASE-B", 7, 62));
			list.Add($"role: {arg}, players in the world: {(flag ? PlayerLookup.OnlinePlayers().Count : 0)}");
			list.Add(string.Format("map: {0}, region: \"{1}\", interior region: {2}, under a roof: {3} (found by {4})", ((Object)(object)localMapInstance == (Object)null) ? "none" : localMapInstance._mapName, RegionWatcher.CurrentRegionName, RegionWatcher.InsideInteriorRegion, IndoorProbe.Indoors, IndoorProbe.LastBy));
			list.Add($"season: {SeasonTable.Name(SeasonsAuthority.ActiveSeason)} ({SeasonsAuthority.AuthoritySource}), holiday running: {HolidayDay.Active}");
			list.Add("time: " + TimeController.Describe());
			list.Add("weather: " + WeatherController.Describe());
			List<string> list2 = list;
			if ((Object)(object)mainPlayer != (Object)null)
			{
				Vector3 position = ((Component)mainPlayer).transform.position;
				list2.Add($"position: {position.x:0.#}, {position.y:0.#}, {position.z:0.#}");
			}
			list2.Add($"panel: {modConfig.PanelLook.Value} look, {modConfig.PanelWidth.Value:0} x {modConfig.PanelHeight.Value:0}, scale {modConfig.PanelScale.Value:0.##}");
			list2.Add(string.Format("screen {0} x {1}, {2} ({3}), quality {4}, Low Spec Mode {5}, {6}", Screen.width, Screen.height, SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceType, text, modConfig.LowSpecMode.Value ? "on" : "off", SystemInfo.operatingSystem));
			return list2;
		}
	}
	internal static class CherryBlossom
	{
		private static readonly List<string> Names = new List<string>();

		private static string _lastRaw = string.Empty;

		private static Color _light = new Color(1f, 0.8824f, 0.8275f, 1f);

		private static string _lightRaw = string.Empty;

		private static Color _leaf = new Color(0.949f, 0.6549f, 0.7216f, 1f);

		private static string _leafRaw = string.Empty;

		private static Color _wood = new Color(0.349f, 0.2549f, 0.2431f, 1f);

		private static string _woodRaw = string.Empty;

		internal static int Count => Names.Count;

		internal static void Rebuild(string raw)
		{
			if (string.Equals(raw, _lastRaw, StringComparison.Ordinal))
			{
				return;
			}
			_lastRaw = raw ?? string.Empty;
			Names.Clear();
			if (string.IsNullOrWhiteSpace(_lastRaw))
			{
				return;
			}
			string[] array = _lastRaw.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length >= 3)
				{
					Names.Add(text);
				}
			}
		}

		internal static bool AppliesTo(MapInstance? instance)
		{
			if (!Plugin.ModConfig.CherryBlossomEnabled.Value || (Object)(object)instance == (Object)null)
			{
				return false;
			}
			Rebuild(Plugin.ModConfig.CherryBlossomMaps.Value);
			if (Names.Count == 0)
			{
				return false;
			}
			string mapName = instance._mapName;
			if (string.IsNullOrWhiteSpace(mapName))
			{
				return false;
			}
			for (int i = 0; i < Names.Count; i++)
			{
				if (mapName.IndexOf(Names[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool AppliesHere()
		{
			return AppliesHere(SeasonsGameAccess.LocalMapInstance);
		}

		internal static bool AppliesHere(MapInstance? local)
		{
			if (!AppliesTo(local))
			{
				return PlayerInRegion();
			}
			return true;
		}

		internal static bool HoldsSeasonOut(MapInstance? instance)
		{