Decompiled source of BigSky v1.0.1

plugin/BigWalkDayNight.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigWalkDayNight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BigWalkDayNight")]
[assembly: AssemblyTitle("BigWalkDayNight")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.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 BigWalkDayNight
{
	internal static class AudioBeds
	{
		private static GameObject _go;

		private static AudioSource _rain;

		private static AudioSource _day;

		private static AudioSource _night;

		private static AudioSource _thunder;

		private static AudioClip _rainClip;

		private static AudioClip _dayClip;

		private static AudioClip _nightClip;

		private static AudioClip _thunderClip;

		private static bool _loading;

		private static void Ensure()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (!((Object)(object)_go != (Object)null))
			{
				_go = new GameObject("BWDN Audio");
				Object.DontDestroyOnLoad((Object)(object)_go);
				_rain = Src("rain", loop: true);
				_day = Src("day", loop: true);
				_night = Src("night", loop: true);
				_thunder = Src("thunder", loop: false);
				_rainClip = MakeRainClip();
				_rain.clip = _rainClip;
				if (!_loading && (Object)(object)Runner.Instance != (Object)null)
				{
					_loading = true;
					Runner.Instance.Run(LoadAll());
				}
			}
		}

		private static AudioSource Src(string n, bool loop)
		{
			AudioSource val = _go.AddComponent<AudioSource>();
			val.loop = loop;
			val.playOnAwake = false;
			val.spatialBlend = 0f;
			val.volume = 0f;
			val.ignoreListenerPause = true;
			return val;
		}

		public static void Tick()
		{
			if (!Settings.AudioEnabled.Value)
			{
				if ((Object)(object)_go != (Object)null)
				{
					SilenceAll();
				}
				return;
			}
			if (!Env.WorldReady)
			{
				if ((Object)(object)_go != (Object)null)
				{
					SilenceAll();
				}
				return;
			}
			Ensure();
			float rainBlend = Env.RainBlend;
			float target = Mathf.Clamp01(Settings.RainVolume.Value) * rainBlend;
			Drive(_rain, target, 1f);
			float num = 0f;
			float num2 = 0f;
			if (Env.CelestialValid)
			{
				num = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((Env.SignedElevation - 18f) / 28f));
				num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((0f - Env.SignedElevation - 6f) / 14f));
			}
			float num3 = Mathf.Lerp(1f, Mathf.Clamp01(Settings.RainBedMultiplier.Value), rainBlend);
			float blend = 1f - Mathf.Exp((0f - Mathf.Min(Time.unscaledDeltaTime, 0.1f)) * 4.6f / Mathf.Clamp(Settings.BedFade.Value, 2f, 40f));
			Drive(_day, Mathf.Clamp01(Settings.DayBedVolume.Value) * num * num3, blend);
			Drive(_night, Mathf.Clamp01(Settings.NightBedVolume.Value) * num2 * num3, blend);
		}

		private static void Drive(AudioSource s, float target, float blend)
		{
			if ((Object)(object)s == (Object)null)
			{
				return;
			}
			s.volume = ((blend >= 1f) ? target : Mathf.Lerp(s.volume, target, blend));
			if (target > 0.0005f && (Object)(object)s.clip != (Object)null && !s.isPlaying)
			{
				if (s.clip.length > 1f)
				{
					s.time = Random.value * (s.clip.length - 0.1f);
				}
				s.Play();
			}
			else if (target <= 0.0005f && s.volume <= 0.0006f && s.isPlaying)
			{
				s.Stop();
			}
		}

		private static void SilenceAll()
		{
			AudioSource[] array = (AudioSource[])(object)new AudioSource[3] { _rain, _day, _night };
			foreach (AudioSource val in array)
			{
				if ((Object)(object)val != (Object)null && val.isPlaying)
				{
					val.volume = 0f;
					val.Stop();
				}
			}
		}

		public static void PlayThunder(float volume)
		{
			if ((Object)(object)_thunder != (Object)null && (Object)(object)_thunderClip != (Object)null && Settings.AudioEnabled.Value)
			{
				_thunder.PlayOneShot(_thunderClip, volume * 0.9f);
			}
		}

		private static AudioClip MakeRainClip()
		{
			float[] array = new float[110250];
			Random random = new Random(20260929);
			float num = 0f;
			float num2 = 0f;
			for (int i = 0; i < 110250; i++)
			{
				float num3 = (float)(random.NextDouble() * 2.0 - 1.0);
				num += (num3 - num) * 0.55f;
				num2 += (num - num2) * 0.02f;
				array[i] = num - num2;
			}
			for (int j = 0; j < 5512; j++)
			{
				float num4 = (float)j / 5512f;
				array[j] = array[j] * num4 + array[104738 + j] * (1f - num4);
			}
			float num5 = 0f;
			for (int k = 0; k < 104738; k++)
			{
				num5 = Mathf.Max(num5, Mathf.Abs(array[k]));
			}
			float num6 = ((num5 > 0.0001f) ? (0.9f / num5) : 1f);
			float[] array2 = new float[104738];
			for (int l = 0; l < 104738; l++)
			{
				array2[l] = array[l] * num6;
			}
			AudioClip val = AudioClip.Create("BWDN Rain", 104738, 1, 22050, false);
			val.SetData(Il2CppStructArray<float>.op_Implicit(array2), 0);
			Env.Keep<AudioClip>(val);
			return val;
		}

		private static string Resolve(string dir, string name)
		{
			string[] array = new string[3] { ".ogg", ".wav", ".mp3" };
			foreach (string text in array)
			{
				string text2 = Path.Combine(dir, name + text);
				if (File.Exists(text2))
				{
					return text2;
				}
			}
			return null;
		}

		private static IEnumerator LoadAll()
		{
			string dir = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "audio");
			yield return LoadOne(Resolve(dir, "day_bed"), delegate(AudioClip c)
			{
				_dayClip = c;
				if ((Object)(object)_day != (Object)null)
				{
					_day.clip = c;
				}
			});
			yield return LoadOne(Resolve(dir, "night_bed"), delegate(AudioClip c)
			{
				_nightClip = c;
				if ((Object)(object)_night != (Object)null)
				{
					_night.clip = c;
				}
			});
			yield return LoadOne(Resolve(dir, "thunder"), delegate(AudioClip c)
			{
				_thunderClip = c;
			});
			Plugin.L.LogInfo((object)("AUDIO beds day=" + ((Object)(object)_dayClip != (Object)null) + " night=" + ((Object)(object)_nightClip != (Object)null) + " thunder=" + ((Object)(object)_thunderClip != (Object)null)));
		}

		private static IEnumerator LoadOne(string path, Action<AudioClip> done)
		{
			if (path == null)
			{
				yield break;
			}
			string ext = Path.GetExtension(path).ToLowerInvariant();
			AudioType type = (AudioType)((ext == ".wav") ? 20 : ((ext == ".mp3") ? 13 : 14));
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, type);
			yield return req.SendWebRequest();
			if ((int)req.result == 1)
			{
				AudioClip clip = DownloadHandlerAudioClip.GetContent(req);
				if ((Object)(object)clip != (Object)null)
				{
					((Object)clip).name = "BWDN " + Path.GetFileNameWithoutExtension(path);
					done(clip);
				}
			}
			else
			{
				Plugin.L.LogWarning((object)("AUDIO load failed " + Path.GetFileName(path) + ": " + req.error));
			}
			req.Dispose();
		}
	}
	internal static class Celestials
	{
		private static Mesh _quad;

		private static Texture2D _glow;

		private static GameObject _sunGo;

		private static Material _sunMat;

		private static Texture2D _sunTex;

		private static GameObject _moonGo;

		private static Material _moonMat;

		private static Texture2D _moonTex;

		private static float _moonPhase;

		private static float _lastMoonTexPhase = -10f;

		private static float _nextMoonUpdate;

		private static GameObject _glowGo;

		private static Material _glowMat;

		private static GameObject _starGo;

		private static Material _starMat;

		private static Mesh _starMesh;

		private static int _starBuilt = -1;

		private static Color[] _starBase;

		private static Color[] _starAnim;

		private static float[] _starPhase;

		private static float[] _starSpeed;

		private static float[] _starAmt;

		private static float _nextTwinkle;

		private static GameObject _cloudRoot;

		private static Material _cloudMat;

		private static string _cloudKey = "";

		private static readonly List<Transform> _clouds = new List<Transform>();

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

		private const float CloudField = 210f;

		private static float _nextDbg;

		private static float _nextStarRetry;

		private static bool Ready()
		{
			if ((Object)(object)_quad == (Object)null)
			{
				_quad = Env.Quad();
			}
			if ((Object)(object)_glow == (Object)null)
			{
				_glow = Env.GlowTexture();
			}
			return true;
		}

		public static void Tick()
		{
			bool flag = Env.WorldReady && Env.CelestialValid;
			Camera cam = Env.Cam;
			if (Settings.Debug.Value && Time.unscaledTime >= _nextDbg)
			{
				_nextDbg = Time.unscaledTime + 10f;
				Plugin.L.LogInfo((object)("CELESTIALS worldReady=" + Env.WorldReady + " valid=" + Env.CelestialValid + " skyActive=" + Sky.Active + " cam=" + ((Object)(object)cam != (Object)null) + " elev=" + Env.SignedElevation.ToString("F1") + " sun=" + ((Object)(object)_sunGo != (Object)null && _sunGo.activeSelf) + " moon=" + ((Object)(object)_moonGo != (Object)null && _moonGo.activeSelf) + " stars=" + ((Object)(object)_starGo != (Object)null && _starGo.activeSelf) + " clouds=" + ((Object)(object)_cloudRoot != (Object)null && _cloudRoot.activeSelf) + "/" + _clouds.Count));
			}
			if (!flag || (Object)(object)cam == (Object)null)
			{
				HideAll();
				return;
			}
			Ready();
			UpdateMoonPhase();
			UpdateSun(cam);
			UpdateMoon(cam);
			UpdateGlow(cam);
			UpdateStars(cam);
			UpdateClouds(cam);
		}

		private static void HideAll()
		{
			GameObject[] array = (GameObject[])(object)new GameObject[5] { _sunGo, _moonGo, _glowGo, _starGo, _cloudRoot };
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null && val.activeSelf)
				{
					val.SetActive(false);
				}
			}
		}

		private static float Dist(Camera cam)
		{
			return Mathf.Clamp(cam.farClipPlane * 0.72f, 80f, 500f);
		}

		private static void UpdateSun(Camera cam)
		{
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: 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_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01((Env.SignedElevation + 4.5f) / 5.5f) * (1f - Mathf.Clamp01(Env.RainBlend * 2.2f));
			if (num <= 0.01f)
			{
				if ((Object)(object)_sunGo != (Object)null)
				{
					_sunGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_sunGo == (Object)null)
			{
				_sunTex = new Texture2D(128, 128, (TextureFormat)4, false);
				Env.Keep<Texture2D>(_sunTex);
				Color32[] array = (Color32[])(object)new Color32[16384];
				for (int i = 0; i < 128; i++)
				{
					for (int j = 0; j < 128; j++)
					{
						float num2 = ((float)j + 0.5f) / 128f - 0.5f;
						float num3 = ((float)i + 0.5f) / 128f - 0.5f;
						float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3) * 2f;
						float num5 = 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.23f, 0.3f, num4));
						float num6 = Mathf.Pow(Mathf.Clamp01(1f - num4), 2f) * 0.75f;
						array[i * 128 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(num5 + num6 * (1f - num5)) * 255f));
					}
				}
				_sunTex.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
				((Texture)_sunTex).wrapMode = (TextureWrapMode)1;
				_sunTex.Apply();
				_sunMat = Env.SpriteMaterial("BWDN Sun", (Texture)(object)_sunTex, 3000);
				if ((Object)(object)_sunMat == (Object)null)
				{
					return;
				}
				_sunGo = Env.MakeProp("BWDN Sun", _quad, _sunMat, -1000);
			}
			float num7 = Dist(cam);
			_sunGo.transform.position = ((Component)cam).transform.position + Env.Dir(Env.SignedElevation, Env.SunAzimuth + 180f) * num7;
			_sunGo.transform.rotation = ((Component)cam).transform.rotation;
			float num8 = num7 * Mathf.Clamp(Settings.SunSize.Value, 0.01f, 0.12f) * 6.5f;
			_sunGo.transform.localScale = new Vector3(num8, num8, 1f);
			float num9 = 1f - Mathf.Clamp01(Env.SignedElevation / 18f);
			Color val = Color.Lerp(new Color(1f, 0.97f, 0.9f, 1f), Env.TwilightSun, num9 * 0.85f);
			_sunMat.color = new Color(val.r, val.g, val.b, num);
			_sunGo.SetActive(true);
		}

		private static void UpdateMoonPhase()
		{
			if (!Settings.MoonEnabled.Value)
			{
				Env.MoonIllumination = 1f;
			}
			else if (!(Time.unscaledTime < _nextMoonUpdate))
			{
				_nextMoonUpdate = Time.unscaledTime + 10f;
				double num = Mathf.Clamp(Settings.CycleMinutes.Value, 5f, 1440f);
				double num2 = Mathf.Clamp(Settings.LunarDays.Value, 2f, 64f);
				double num3 = (double)DateTime.UtcNow.Ticks / 600000000.0 / (num * num2);
				_moonPhase = (float)(num3 - Math.Floor(num3));
				Env.MoonIllumination = 0.5f - 0.5f * Mathf.Cos(_moonPhase * (float)Math.PI * 2f);
			}
		}

		private static void RebuildMoonTexture()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: 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_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: 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_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_moonTex == (Object)null)
			{
				_moonTex = new Texture2D(128, 128, (TextureFormat)4, false);
				Env.Keep<Texture2D>(_moonTex);
				((Texture)_moonTex).wrapMode = (TextureWrapMode)1;
			}
			float num = _moonPhase * (float)Math.PI * 2f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Mathf.Sin(num), 0f, 0f - Mathf.Cos(num));
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.82f, 0.9f, 1f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.055f, 0.075f, 0.14f, 1f);
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.24f, 0.22f, 0.13f),
				new Vector3(0.18f, 0.3f, 0.09f),
				new Vector3(0.27f, -0.12f, 0.15f),
				new Vector3(-0.08f, -0.27f, 0.1f)
			};
			Color32[] array2 = (Color32[])(object)new Color32[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num2 = ((float)j + 0.5f) / 128f * 2f - 1f;
					float num3 = ((float)i + 0.5f) / 128f * 2f - 1f;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					Color val4 = Color.clear;
					if (num4 <= 0.72f)
					{
						float num5 = num2 / 0.72f;
						float num6 = num3 / 0.72f;
						float num7 = Mathf.Sqrt(Mathf.Max(0f, 1f - num5 * num5 - num6 * num6));
						float num8 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(-0.025f, 0.055f, num5 * val.x + num6 * val.y + num7 * val.z));
						float num9 = 1f;
						Vector3[] array3 = array;
						foreach (Vector3 val5 in array3)
						{
							float num10 = Mathf.Sqrt((num5 - val5.x) * (num5 - val5.x) + (num6 - val5.y) * (num6 - val5.y));
							if (num10 < val5.z)
							{
								num9 *= Mathf.Lerp(0.72f, 1f, num10 / val5.z);
							}
						}
						Color val6 = val2 * ((0.78f + 0.22f * num7) * num9);
						val6.a = 1f;
						val4 = Color.Lerp(val3, val6, num8);
						val4.a = Mathf.Clamp01((0.72f - num4) / 0.018f) * Mathf.Lerp(0.2f, 1f, num8);
					}
					else if (num4 < 1f)
					{
						float num11 = Mathf.Clamp01((1f - num4) / 0.27999997f);
						((Color)(ref val4))..ctor(val2.r, val2.g, val2.b, num11 * num11 * num11 * 0.13f * Env.MoonIllumination);
					}
					array2[i * 128 + j] = Color32.op_Implicit(val4);
				}
			}
			_moonTex.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array2));
			_moonTex.Apply(false);
			if ((Object)(object)_moonMat != (Object)null)
			{
				_moonMat.mainTexture = (Texture)(object)_moonTex;
			}
		}

		private static void UpdateMoon(Camera cam)
		{
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.MoonEnabled.Value)
			{
				if ((Object)(object)_moonGo != (Object)null)
				{
					_moonGo.SetActive(false);
				}
				return;
			}
			float num = Mathf.Clamp01((0f - Env.SignedElevation + 2f) / 5f) * (1f - Env.RainBlend);
			if (num <= 0.01f)
			{
				if ((Object)(object)_moonGo != (Object)null)
				{
					_moonGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_moonGo == (Object)null)
			{
				RebuildMoonTexture();
				_moonMat = Env.SpriteMaterial("BWDN Moon", (Texture)(object)_moonTex, 3000);
				if ((Object)(object)_moonMat == (Object)null)
				{
					return;
				}
				_moonGo = Env.MakeProp("BWDN Moon", _quad, _moonMat, -1000);
			}
			float num2 = Mathf.Abs(_moonPhase - _lastMoonTexPhase);
			num2 = Mathf.Min(num2, 1f - num2);
			if (num2 >= 0.002f)
			{
				RebuildMoonTexture();
				_lastMoonTexPhase = _moonPhase;
			}
			float num3 = Dist(cam);
			_moonGo.transform.position = ((Component)cam).transform.position + Env.Dir(0f - Env.SignedElevation, Env.SunAzimuth + 180f) * num3;
			_moonGo.transform.rotation = ((Component)cam).transform.rotation;
			float num4 = num3 * Mathf.Clamp(Settings.MoonSize.Value, 0.025f, 0.16f);
			_moonGo.transform.localScale = new Vector3(num4, num4, 1f);
			_moonMat.color = new Color(1f, 1f, 1f, num);
			_moonGo.SetActive(true);
		}

		private static void UpdateGlow(Camera cam)
		{
			//IL_00e4: 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_0116: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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)
			float num = (Settings.SunsetGlow.Value ? (Env.Twilight * Mathf.Clamp(Settings.GlowStrength.Value, 0f, 6f) * (1f - Env.RainBlend)) : 0f);
			if (num <= 0.02f)
			{
				if ((Object)(object)_glowGo != (Object)null)
				{
					_glowGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_glowGo == (Object)null)
			{
				_glowMat = Env.SpriteMaterial("BWDN Glow", (Texture)(object)_glow, 2995);
				if ((Object)(object)_glowMat == (Object)null)
				{
					return;
				}
				_glowGo = Env.MakeProp("BWDN Glow", _quad, _glowMat, -1001);
			}
			Vector3 val = Env.Dir(0f, Env.SunAzimuth + 180f);
			float num2 = Mathf.Clamp(cam.farClipPlane * 0.45f, 60f, 320f);
			_glowGo.transform.position = ((Component)cam).transform.position + val * num2 + Vector3.up * (num2 * 0.1f);
			_glowGo.transform.rotation = Quaternion.LookRotation(val, Vector3.up);
			_glowGo.transform.localScale = new Vector3(num2 * 2.9f, num2 * 1.15f * Mathf.Lerp(1f, 1.9f, Mathf.Clamp01((num - 1.43f) / 4.57f)), 1f);
			float num3 = Mathf.Max(1f, 0.7f * num);
			Color twilightGlow = Env.TwilightGlow;
			_glowMat.color = new Color(twilightGlow.r * num3, twilightGlow.g * num3, twilightGlow.b * num3, Mathf.Clamp01(0.7f * num));
			_glowGo.SetActive(true);
		}

		private static void BuildStars(int count)
		{
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Expected O, but got Unknown
			//IL_0160: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: 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)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_starGo != (Object)null)
			{
				Object.Destroy((Object)(object)_starGo);
			}
			if ((Object)(object)_starMesh != (Object)null)
			{
				Object.Destroy((Object)(object)_starMesh);
			}
			_starMat = Env.SpriteMaterial("BWDN Stars", (Texture)(object)_glow, 2993);
			if ((Object)(object)_starMat == (Object)null)
			{
				_starBuilt = count;
				return;
			}
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Color> list3 = new List<Color>();
			List<int> list4 = new List<int>();
			_starBase = (Color[])(object)new Color[count];
			_starAnim = (Color[])(object)new Color[count * 4];
			_starPhase = new float[count];
			_starSpeed = new float[count];
			_starAmt = new float[count];
			Random random = new Random(52341);
			Vector3 val = default(Vector3);
			for (int i = 0; i < count; i++)
			{
				float num = 0.06f + (float)random.NextDouble() * 0.94f;
				float num2 = (float)random.NextDouble() * (float)Math.PI * 2f;
				float num3 = Mathf.Sqrt(Mathf.Max(0f, 1f - num * num));
				((Vector3)(ref val))..ctor(num3 * Mathf.Cos(num2), num, num3 * Mathf.Sin(num2));
				Vector3 val2 = ((Mathf.Abs(val.y) > 0.99f) ? Vector3.right : Vector3.Normalize(Vector3.Cross(Vector3.up, val)));
				Vector3 val3 = Vector3.Cross(val, val2);
				float num4 = 0.0016f + (float)random.NextDouble() * 0.003f;
				float num5 = 0.42f + (float)random.NextDouble() * (float)random.NextDouble() * 0.58f;
				double num6 = random.NextDouble();
				Color val4 = ((num6 < 0.58) ? new Color(0.86f, 0.93f, 1f, num5) : ((num6 < 0.84) ? new Color(1f, 0.98f, 0.86f, num5) : new Color(0.92f, 0.82f, 1f, num5)));
				int count2 = list.Count;
				list.Add(val - val2 * num4 - val3 * num4);
				list.Add(val + val2 * num4 - val3 * num4);
				list.Add(val - val2 * num4 + val3 * num4);
				list.Add(val + val2 * num4 + val3 * num4);
				list2.Add(new Vector2(0f, 0f));
				list2.Add(new Vector2(1f, 0f));
				list2.Add(new Vector2(0f, 1f));
				list2.Add(new Vector2(1f, 1f));
				for (int j = 0; j < 4; j++)
				{
					list3.Add(val4);
				}
				list4.Add(count2);
				list4.Add(count2 + 2);
				list4.Add(count2 + 1);
				list4.Add(count2 + 1);
				list4.Add(count2 + 2);
				list4.Add(count2 + 3);
				_starBase[i] = val4;
				_starPhase[i] = (float)random.NextDouble() * (float)Math.PI * 2f;
				_starSpeed[i] = 0.45f + (float)random.NextDouble() * 1.35f;
				_starAmt[i] = 0.2f + (float)random.NextDouble() * 0.3f;
			}
			_starMesh = new Mesh();
			((Object)_starMesh).name = "BWDN Stars";
			Env.Keep<Mesh>(_starMesh);
			_starMesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(list.ToArray());
			_starMesh.uv = Il2CppStructArray<Vector2>.op_Implicit(list2.ToArray());
			_starMesh.colors = Il2CppStructArray<Color>.op_Implicit(list3.ToArray());
			_starMesh.triangles = Il2CppStructArray<int>.op_Implicit(list4.ToArray());
			_starMesh.RecalculateBounds();
			_starMesh.MarkDynamic();
			_starGo = Env.MakeProp("BWDN Stars", _starMesh, _starMat, -1003);
			_starBuilt = count;
		}

		private static void UpdateStars(Camera cam)
		{
			//IL_0118: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Settings.StarCount.Value, 40, 800);
			float num2 = (Settings.StarsEnabled.Value ? (Mathf.Clamp01((0.22f - Env.DayWeight) / 0.22f) * (1f - Env.RainBlend)) : 0f);
			if (num2 <= 0.01f)
			{
				if ((Object)(object)_starGo != (Object)null)
				{
					_starGo.SetActive(false);
				}
				return;
			}
			if (_starBuilt != num || (((Object)(object)_starGo == (Object)null || (Object)(object)_starMesh == (Object)null) && Time.unscaledTime >= _nextStarRetry))
			{
				_nextStarRetry = Time.unscaledTime + 3f;
				BuildStars(num);
			}
			if ((Object)(object)_starGo == (Object)null)
			{
				return;
			}
			float num3 = Mathf.Clamp(cam.farClipPlane * 0.68f, 60f, 400f);
			_starGo.transform.position = ((Component)cam).transform.position;
			_starGo.transform.rotation = Quaternion.Euler(0f, Env.Phase * 90f + 20f, 0f);
			_starGo.transform.localScale = Vector3.one * num3;
			if (Time.unscaledTime >= _nextTwinkle)
			{
				_nextTwinkle = Time.unscaledTime + 0.12f;
				for (int i = 0; i < _starBase.Length; i++)
				{
					Color val = _starBase[i];
					val.a *= Mathf.Lerp(1f - _starAmt[i], 1f, 0.5f + 0.5f * Mathf.Sin(_starPhase[i] + Time.unscaledTime * _starSpeed[i]));
					_starAnim[i * 4] = val;
					_starAnim[i * 4 + 1] = val;
					_starAnim[i * 4 + 2] = val;
					_starAnim[i * 4 + 3] = val;
				}
				_starMesh.colors = Il2CppStructArray<Color>.op_Implicit(_starAnim);
			}
			_starMat.color = new Color(1f, 1f, 1f, num2);
			_starGo.SetActive(true);
		}

		private static Mesh CloudMesh(Random r)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Color> list2 = new List<Color>();
			List<int> list3 = new List<int>();
			int num = 3 + r.Next(4);
			Vector3 zero = default(Vector3);
			Vector3 val = default(Vector3);
			for (int i = 0; i < num; i++)
			{
				float num2;
				if (i == 0)
				{
					zero = Vector3.zero;
					num2 = 6f + (float)r.NextDouble() * 4f;
				}
				else
				{
					float num3 = (float)r.NextDouble() * (float)Math.PI * 2f;
					float num4 = 4f + (float)r.NextDouble() * 7f;
					((Vector3)(ref zero))..ctor(Mathf.Cos(num3) * num4, (float)r.NextDouble() * 1.4f, Mathf.Sin(num3) * num4 * 0.7f);
					num2 = 3f + (float)r.NextDouble() * 4f;
				}
				int count = list.Count;
				for (int j = 0; j <= 7; j++)
				{
					float num5 = (float)Math.PI * (float)j / 7f;
					float num6 = Mathf.Cos(num5);
					float num7 = Mathf.Sin(num5);
					for (int k = 0; k < 10; k++)
					{
						float num8 = (float)Math.PI * 2f * (float)k / 10f;
						((Vector3)(ref val))..ctor(num7 * Mathf.Cos(num8), num6, num7 * Mathf.Sin(num8));
						Vector3 val2 = zero + Vector3.Scale(val, new Vector3(num2, num2 * 0.5f, num2));
						if (val2.y < -1.2f)
						{
							val2.y = -1.2f;
						}
						list.Add(val2);
						float num9 = Mathf.Lerp(0.72f, 1f, Mathf.Clamp01(val.y * 0.5f + 0.5f));
						list2.Add(new Color(num9, num9, Mathf.Min(1f, num9 * 1.04f), 1f));
					}
				}
				for (int l = 0; l < 7; l++)
				{
					for (int m = 0; m < 10; m++)
					{
						int num10 = (m + 1) % 10;
						int item = count + l * 10 + m;
						int item2 = count + l * 10 + num10;
						int item3 = count + (l + 1) * 10 + m;
						int item4 = count + (l + 1) * 10 + num10;
						list3.Add(item);
						list3.Add(item2);
						list3.Add(item3);
						list3.Add(item2);
						list3.Add(item4);
						list3.Add(item3);
					}
				}
			}
			Vector2[] array = (Vector2[])(object)new Vector2[list.Count];
			for (int n = 0; n < array.Length; n++)
			{
				array[n] = new Vector2(0.5f, 0.5f);
			}
			Mesh val3 = new Mesh();
			((Object)val3).name = "BWDN Cloud";
			Env.Keep<Mesh>(val3);
			val3.vertices = Il2CppStructArray<Vector3>.op_Implicit(list.ToArray());
			val3.uv = Il2CppStructArray<Vector2>.op_Implicit(array);
			val3.colors = Il2CppStructArray<Color>.op_Implicit(list2.ToArray());
			val3.triangles = Il2CppStructArray<int>.op_Implicit(list3.ToArray());
			val3.RecalculateBounds();
			return val3;
		}

		private static void BuildClouds(string key)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0104: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cloudRoot != (Object)null)
			{
				Object.Destroy((Object)(object)_cloudRoot);
			}
			_clouds.Clear();
			_cloudScales.Clear();
			_cloudKey = key;
			if ((Object)(object)_cloudMat == (Object)null)
			{
				_cloudMat = Env.SpriteMaterial("BWDN Clouds", (Texture)(object)Texture2D.whiteTexture, 3000);
			}
			if (!((Object)(object)_cloudMat == (Object)null))
			{
				_cloudRoot = new GameObject("BWDN Clouds");
				Object.DontDestroyOnLoad((Object)(object)_cloudRoot);
				Random random = new Random(978231);
				int num = Mathf.Clamp(Settings.CloudCount.Value, 1, 40);
				float num2 = Mathf.Clamp(Settings.CloudAltitude.Value, 25f, 300f);
				float num3 = Mathf.Clamp(Settings.CloudScale.Value, 0.3f, 3f);
				Camera cam = Env.Cam;
				Vector3 val = (((Object)(object)cam != (Object)null) ? ((Component)cam).transform.position : Vector3.zero);
				for (int i = 0; i < num; i++)
				{
					GameObject val2 = new GameObject("Cloud " + i);
					val2.transform.SetParent(_cloudRoot.transform, false);
					float num4 = (float)random.NextDouble() * (float)Math.PI * 2f;
					float num5 = Mathf.Sqrt((float)random.NextDouble()) * 210f;
					val2.transform.position = new Vector3(val.x + Mathf.Cos(num4) * num5, num2 + ((float)random.NextDouble() - 0.5f) * 14f, val.z + Mathf.Sin(num4) * num5);
					val2.transform.rotation = Quaternion.Euler(0f, (float)random.NextDouble() * 360f, 0f);
					Vector3 val3 = Vector3.one * (num3 * (0.8f + (float)random.NextDouble() * 0.9f));
					val2.transform.localScale = val3;
					val2.AddComponent<MeshFilter>().sharedMesh = CloudMesh(random);
					MeshRenderer val4 = val2.AddComponent<MeshRenderer>();
					((Renderer)val4).sharedMaterial = _cloudMat;
					((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)val4).receiveShadows = false;
					_clouds.Add(val2.transform);
					_cloudScales.Add(val3);
				}
			}
		}

		private static void UpdateClouds(Camera cam)
		{
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_019e: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: 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_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: 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_0278: 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_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: 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_0328: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.CloudsEnabled.Value)
			{
				if ((Object)(object)_cloudRoot != (Object)null)
				{
					_cloudRoot.SetActive(false);
				}
				return;
			}
			string text = Settings.CloudCount.Value + "|" + Settings.CloudAltitude.Value + "|" + Settings.CloudScale.Value;
			if ((Object)(object)_cloudRoot == (Object)null || (Object)(object)_cloudMat == (Object)null || (_clouds.Count > 0 && (Object)(object)_clouds[0] == (Object)null) || text != _cloudKey)
			{
				BuildClouds(text);
			}
			if ((Object)(object)_cloudRoot == (Object)null || (Object)(object)_cloudMat == (Object)null)
			{
				return;
			}
			float num = 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.05f, 0.72f, Env.RainBlend));
			_cloudRoot.SetActive(num > 0.005f);
			float dayWeight = Env.DayWeight;
			float twilight = Env.Twilight;
			Color val = Color.Lerp(new Color(0.26f, 0.31f, 0.44f, 1f), Color.white, Mathf.Clamp01(dayWeight));
			val = Color.Lerp(val, Color.Lerp(Color.white, Env.TwilightGlow, 0.55f), twilight * 0.7f);
			_cloudMat.color = val;
			Vector3 position = ((Component)cam).transform.position;
			float num2 = Mathf.Min(Time.unscaledDeltaTime, 0.25f);
			Vector3 val2 = Quaternion.Euler(0f, Mathf.Repeat(Settings.CloudDirection.Value, 360f), 0f) * Vector3.forward * (Mathf.Clamp(Settings.CloudSpeed.Value, 0f, 30f) * num2);
			for (int i = 0; i < _clouds.Count; i++)
			{
				Transform val3 = _clouds[i];
				if (!((Object)(object)val3 == (Object)null))
				{
					Vector3 val4 = val3.position + val2;
					float num3 = val4.x - position.x;
					float num4 = val4.z - position.z;
					if (num3 > 210f)
					{
						num3 -= 420f;
					}
					else if (num3 < -210f)
					{
						num3 += 420f;
					}
					if (num4 > 210f)
					{
						num4 -= 420f;
					}
					else if (num4 < -210f)
					{
						num4 += 420f;
					}
					val3.position = new Vector3(position.x + num3, val4.y, position.z + num4);
					val3.localScale = _cloudScales[i] * num;
				}
			}
		}
	}
	internal static class ConfigMenu
	{
		private static bool _open;

		private static Rect _rect = new Rect(30f, 30f, 520f, 560f);

		private static Vector2 _scroll;

		private static int _tab;

		private static CursorLockMode _lock;

		private static bool _vis;

		private static WindowFunction _fn;

		private static readonly string[] Tabs = new string[4] { "General", "Sky", "Weather", "Grading" };

		private static float _y;

		private static float _vw;

		private static float _contentHeight = 600f;

		private const float Row = 26f;

		private const float LabelW = 200f;

		private const float ValueW = 58f;

		public static void Update()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.MenuEnabled.Value && Input.GetKeyDown(Settings.MenuKeyCode))
			{
				Toggle();
			}
			if (_open && Input.GetKeyDown((KeyCode)27))
			{
				Toggle();
			}
			if (_open)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			Settings.FlushIfIdle(force: false);
		}

		private static void Toggle()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			_open = !_open;
			if (_open)
			{
				_lock = Cursor.lockState;
				_vis = Cursor.visible;
			}
			else
			{
				Cursor.lockState = _lock;
				Cursor.visible = _vis;
				Settings.FlushIfIdle(force: true);
			}
		}

		public static void OnGUI()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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)
			if (_open)
			{
				if ((Delegate)(object)_fn == (Delegate)null)
				{
					_fn = WindowFunction.op_Implicit((Action<int>)Draw);
				}
				((Rect)(ref _rect)).width = Mathf.Min(520f, (float)Screen.width - 40f);
				((Rect)(ref _rect)).height = Mathf.Min(560f, (float)Screen.height - 40f);
				_rect = GUI.Window(190019, _rect, _fn, "Big Walk: Day and Night 0.1.0");
			}
		}

		private static void Draw(int id)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0733: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			float width = ((Rect)(ref _rect)).width;
			float height = ((Rect)(ref _rect)).height;
			float num = (width - 16f) / (float)Tabs.Length;
			Color backgroundColor = GUI.backgroundColor;
			for (int i = 0; i < Tabs.Length; i++)
			{
				GUI.backgroundColor = (Color)((i == _tab) ? new Color(0.4f, 0.68f, 0.88f, 1f) : backgroundColor);
				if (GUI.Button(new Rect(8f + (float)i * num, 24f, num - 2f, 26f), Tabs[i]) && _tab != i)
				{
					_tab = i;
					_scroll = Vector2.zero;
				}
			}
			GUI.backgroundColor = backgroundColor;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(8f, 56f, width - 16f, height - 64f);
			_vw = ((Rect)(ref val)).width - 22f;
			_scroll = GUI.BeginScrollView(val, _scroll, new Rect(0f, 0f, _vw, Mathf.Max(_contentHeight, ((Rect)(ref val)).height)));
			_y = 0f;
			if (_tab == 0)
			{
				Tog(Settings.DayCycle, "Day cycle effects");
				Int(Settings.ClockMode, "Clock: 0 game / 1 mod", 0, 1);
				Tog(Settings.DriveSunLight, "Mod drives sun light too");
				Sld(Settings.VisualHourOffset, "Visual hour offset", -12f, 12f);
				Tog(Settings.Debug, "Debug logging");
				Tog(Settings.Freeze, "Hold time of day");
				Sld(Settings.FrozenHour, "Time to hold (h)", 0f, 24f);
				Sld(Settings.CycleMinutes, "Cycle minutes", 5f, 1440f);
				Sld(Settings.MaxElevation, "Noon sun elevation", 20f, 80f);
				Sld(Settings.Azimuth, "Sun azimuth", 0f, 360f);
				Sld(Settings.NightBrightness, "Night brightness", 0f, 1f);
				Sld(Settings.MinNightLight, "Minimum night light", 0.15f, 0.7f);
				Sld(Settings.ShadowStrength, "Shadow strength", 0f, 1f);
				Sld(Settings.AmbientIntensity, "Ambient", 0.2f, 2f);
				Int(Settings.TwilightOverride, "Twilight colour (0=rand)", 0, 4);
				Sld(Settings.TwilightWorldTint, "Twilight world tint", 0f, 4f);
				Sld(Settings.TwilightWidth, "Twilight width", 2f, 90f);
				Sld(Settings.TwilightFalloff, "Twilight falloff", 0.2f, 8f);
			}
			else if (_tab == 1)
			{
				Tog(Settings.SkyEnabled, "Custom sky (F5)");
				Tog(Settings.ForceSkyboxClear, "Force camera to skybox");
				Sld(Settings.SkyExposure, "Sky exposure", 0.05f, 4f);
				Sld(Settings.Atmosphere, "Atmosphere", 0.1f, 3f);
				Sld(Settings.SunSize, "Sun size", 0.01f, 0.08f);
				Tog(Settings.MoonEnabled, "Moon phases");
				Sld(Settings.MoonSize, "Moon size", 0.025f, 0.14f);
				Tog(Settings.StarsEnabled, "Stars");
				Int(Settings.StarCount, "Star count", 40, 800);
				Tog(Settings.SunsetGlow, "Sunset glow");
				Sld(Settings.GlowStrength, "Glow strength", 0f, 3f);
				Tog(Settings.CloudsEnabled, "Clouds");
				Int(Settings.CloudCount, "Cloud count", 1, 40);
				Sld(Settings.CloudAltitude, "Cloud altitude", 25f, 300f);
				Sld(Settings.CloudSpeed, "Cloud speed", 0f, 30f);
				Sld(Settings.CloudScale, "Cloud scale", 0.3f, 3f);
			}
			else if (_tab == 2)
			{
				Tog(Settings.WeatherEnabled, "Weather");
				Tog(Settings.RandomRain, "Random rain");
				Tog(Settings.AlwaysRain, "Always raining");
				Sld(Settings.RainChance, "Rain chance", 0.02f, 0.9f);
				Sld(Settings.RainDensity, "Rain density", 0.5f, 2f);
				Sld(Settings.RainDropSize, "Drop size", 0.4f, 1.4f);
				Sld(Settings.RainTransition, "Transition seconds", 2f, 60f);
				Sld(Settings.RainLight, "Rain light multiplier", 0.2f, 1f);
				Sld(Settings.RainVolume, "Rain volume", 0f, 1f);
				Sld(Settings.Thunder, "Thunder / min", 0f, 1f);
				if (GUI.Button(new Rect(0f, _y, _vw, 28f), Weather.Raining ? "Stop rain now" : "Start rain now"))
				{
					Weather.SetRain(!Weather.Raining, manual: true);
				}
				_y += 34f;
				Tog(Settings.AudioEnabled, "Audio");
				Sld(Settings.DayBedVolume, "Day bed volume", 0f, 1f);
				Sld(Settings.NightBedVolume, "Night bed volume", 0f, 1f);
			}
			else
			{
				Tog(Settings.GradingEnabled, "Colour grade (F6)");
				Sld(Settings.Temperature, "Temperature", -100f, 100f);
				Sld(Settings.Tint, "Tint", -100f, 100f);
				Sld(Settings.PostExposure, "Exposure EV", -2f, 2f);
				Sld(Settings.Contrast, "Contrast", -100f, 100f);
				Sld(Settings.Saturation, "Saturation", -100f, 100f);
				Sld(Settings.NightExposureDip, "Night exposure dip", -1f, 0f);
				Tog(Settings.NoBloom, "Override bloom off");
				Tog(Settings.NoVignette, "Override vignette off");
				Tog(Settings.NoGrain, "Override film grain off");
				Tog(Settings.NoDof, "Override depth of field off");
				Tog(Settings.NoMotionBlur, "Override motion blur off");
			}
			_contentHeight = _y + 8f;
			GUI.EndScrollView();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
		}

		private static void Tog(ConfigEntry<bool> e, string label)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			bool flag = GUI.Toggle(new Rect(0f, _y, _vw, 22f), e.Value, label);
			_y += 26f;
			if (flag != e.Value)
			{
				e.Value = flag;
				Settings.MarkDirty();
			}
		}

		private static void Sld(ConfigEntry<float> e, string label, float min, float max)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(0f, _y, 200f, 22f), label);
			float num = GUI.HorizontalSlider(new Rect(206f, _y + 6f, _vw - 200f - 58f - 12f, 16f), e.Value, min, max);
			GUI.Label(new Rect(_vw - 58f, _y, 58f, 22f), num.ToString("F2"));
			_y += 26f;
			if (Mathf.Abs(num - e.Value) > 0.0001f)
			{
				e.Value = num;
				Settings.MarkDirty();
			}
		}

		private static void Int(ConfigEntry<int> e, string label, int min, int max)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(0f, _y, 200f, 22f), label);
			int num = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(206f, _y + 6f, _vw - 200f - 58f - 12f, 16f), (float)e.Value, (float)min, (float)max));
			GUI.Label(new Rect(_vw - 58f, _y, 58f, 22f), num.ToString());
			_y += 26f;
			if (num != e.Value)
			{
				e.Value = num;
				Settings.MarkDirty();
			}
		}
	}
	internal static class Env
	{
		public static float DayWeight = 1f;

		public static float SignedElevation = 45f;

		public static float SunAzimuth;

		public static float Twilight;

		public static float Phase;

		public static float RainBlend;

		public static float Lightning;

		public static float MoonIllumination = 1f;

		public static bool CelestialValid;

		public static Color TwilightGlow = new Color(1f, 0.42f, 0.1f, 1f);

		public static Color TwilightSky = new Color(0.82f, 0.44f, 0.18f, 1f);

		public static Color TwilightSun = new Color(1f, 0.7f, 0.38f, 1f);

		private static Camera _cam;

		private static float _nextCam;

		private static bool _worldReady;

		private static float _nextWorldCheck;

		private static bool _warnedSprite;

		public static Camera Cam
		{
			get
			{
				if ((Object)(object)_cam == (Object)null && Time.unscaledTime >= _nextCam)
				{
					_nextCam = Time.unscaledTime + 1f;
					_cam = Camera.main;
				}
				return _cam;
			}
		}

		public static bool WorldReady
		{
			get
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				if (Time.unscaledTime >= _nextWorldCheck)
				{
					_nextWorldCheck = Time.unscaledTime + 2f;
					Scene activeScene = SceneManager.GetActiveScene();
					string name = ((Scene)(ref activeScene)).name;
					bool flag = false;
					string value = Settings.InactiveScenes.Value;
					if (!string.IsNullOrEmpty(value))
					{
						string[] array = value.Split(',');
						foreach (string text in array)
						{
							if (text.Trim().Length > 0 && string.Equals(text.Trim(), name, StringComparison.OrdinalIgnoreCase))
							{
								flag = true;
							}
						}
					}
					_worldReady = !flag && SunCycle.HasSun && (Object)(object)Cam != (Object)null;
				}
				return _worldReady;
			}
		}

		public static void ResetCamera()
		{
			_cam = null;
			_nextCam = 0f;
		}

		public static T Keep<T>(T o) where T : Object
		{
			//IL_001d: 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)
			if ((Object)(object)o != (Object)null)
			{
				((Object)o).hideFlags = (HideFlags)(((Object)o).hideFlags | 0x20);
			}
			return o;
		}

		public static Shader FindShader(params string[] names)
		{
			for (int i = 0; i < names.Length; i++)
			{
				Shader val = Shader.Find(names[i]);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		public static Material SpriteMaterial(string name, Texture tex, int queue)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Shader val = FindShader("Sprites/Default", "Universal Render Pipeline/Particles/Unlit", "Universal Render Pipeline/Unlit");
			if ((Object)(object)val == (Object)null)
			{
				if (!_warnedSprite)
				{
					_warnedSprite = true;
					Plugin.L.LogWarning((object)"No sprite/unlit shader available (stripped?). Celestials disabled.");
				}
				return null;
			}
			Material val2 = new Material(val);
			((Object)val2).name = name;
			val2.mainTexture = tex;
			val2.renderQueue = queue;
			Env.Keep<Material>(val2);
			return val2;
		}

		public static Mesh Quad()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			((Object)val).name = "BWDN Quad";
			Env.Keep<Mesh>(val);
			val.vertices = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f)
			});
			val.uv = Il2CppStructArray<Vector2>.op_Implicit((Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f)
			});
			val.triangles = Il2CppStructArray<int>.op_Implicit(new int[6] { 0, 2, 1, 1, 2, 3 });
			val.RecalculateBounds();
			return val;
		}

		public static Texture2D GlowTexture()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//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)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Env.Keep<Texture2D>(val);
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j + 0.5f) / 64f - 0.5f;
					float num2 = ((float)i + 0.5f) / 64f - 0.5f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2) * 2f);
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * num3 * 255f));
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			((Texture)val).wrapMode = (TextureWrapMode)1;
			val.Apply();
			return val;
		}

		public static GameObject MakeProp(string name, Mesh mesh, Material mat, int sortingOrder)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			((Renderer)val2).sharedMaterial = mat;
			((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val2).receiveShadows = false;
			((Renderer)val2).sortingOrder = sortingOrder;
			val.SetActive(false);
			return val;
		}

		public static Vector3 Dir(float elevDeg, float azDeg)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			float num = elevDeg * ((float)Math.PI / 180f);
			float num2 = azDeg * ((float)Math.PI / 180f);
			float num3 = Mathf.Cos(num);
			return new Vector3(num3 * Mathf.Sin(num2), Mathf.Sin(num), num3 * Mathf.Cos(num2));
		}

		public static float TwilightCurve(float signedElevation)
		{
			float num = Mathf.Clamp(Settings.TwilightWidth.Value, 2f, 90f);
			float num2 = 1f - Mathf.Clamp01(Mathf.Abs(signedElevation) / num);
			return Mathf.Pow(num2, Mathf.Clamp(Settings.TwilightFalloff.Value, 0.2f, 8f));
		}
	}
	[BepInPlugin("local.bigwalk.dayandnight", "Big Walk: Day and Night", "0.1.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "local.bigwalk.dayandnight";

		public const string Name = "Big Walk: Day and Night";

		public const string Version = "0.1.0";

		internal static ManualLogSource L;

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			Settings.Init(((BasePlugin)this).Config);
			ClassInjector.RegisterTypeInIl2Cpp<Runner>();
			((BasePlugin)this).AddComponent<Runner>();
			L.LogInfo((object)"Big Walk: Day and Night 0.1.0 loaded.");
		}
	}
	public class Runner : MonoBehaviour
	{
		internal static Runner Instance;

		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			Instance = this;
			SceneManager.sceneLoaded += UnityAction<Scene, LoadSceneMode>.op_Implicit((Action<Scene, LoadSceneMode>)OnSceneLoaded);
		}

		[HideFromIl2Cpp]
		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			World.OnSceneLoaded(mode);
		}

		[HideFromIl2Cpp]
		internal void Run(IEnumerator routine)
		{
			MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)this, routine);
		}

		private void Update()
		{
			World.Update();
		}

		private void LateUpdate()
		{
			World.LateUpdate();
		}

		private void OnGUI()
		{
			ConfigMenu.OnGUI();
		}
	}
	internal static class Settings
	{
		public static ConfigFile File;

		private static float _lastSave;

		private static bool _dirty;

		public static ConfigEntry<bool> DayCycle;

		public static ConfigEntry<bool> Freeze;

		public static ConfigEntry<bool> DriveSunLight;

		public static ConfigEntry<bool> Debug;

		public static ConfigEntry<int> ClockMode;

		public static ConfigEntry<float> VisualHourOffset;

		public static ConfigEntry<float> CycleMinutes;

		public static ConfigEntry<float> NoonMinute;

		public static ConfigEntry<float> FrozenHour;

		public static ConfigEntry<float> MaxElevation;

		public static ConfigEntry<float> Azimuth;

		public static ConfigEntry<float> NightBrightness;

		public static ConfigEntry<float> MinNightLight;

		public static ConfigEntry<float> ShadowStrength;

		public static ConfigEntry<float> AmbientIntensity;

		public static ConfigEntry<float> TwilightWidth;

		public static ConfigEntry<float> TwilightFalloff;

		public static ConfigEntry<float> TwilightWorldTint;

		public static ConfigEntry<float> PinkChance;

		public static ConfigEntry<float> RedChance;

		public static ConfigEntry<int> TwilightOverride;

		public static ConfigEntry<string> InactiveScenes;

		public static ConfigEntry<bool> SkyEnabled;

		public static ConfigEntry<bool> ForceSkyboxClear;

		public static ConfigEntry<bool> StarsEnabled;

		public static ConfigEntry<bool> MoonEnabled;

		public static ConfigEntry<bool> SunsetGlow;

		public static ConfigEntry<bool> CloudsEnabled;

		public static ConfigEntry<float> SkyExposure;

		public static ConfigEntry<float> Atmosphere;

		public static ConfigEntry<float> SunSize;

		public static ConfigEntry<float> MoonSize;

		public static ConfigEntry<float> LunarDays;

		public static ConfigEntry<float> GlowStrength;

		public static ConfigEntry<float> CloudSpeed;

		public static ConfigEntry<float> CloudDirection;

		public static ConfigEntry<float> CloudAltitude;

		public static ConfigEntry<float> CloudScale;

		public static ConfigEntry<int> StarCount;

		public static ConfigEntry<int> CloudCount;

		public static ConfigEntry<bool> GradingEnabled;

		public static ConfigEntry<bool> NoBloom;

		public static ConfigEntry<bool> NoVignette;

		public static ConfigEntry<bool> NoGrain;

		public static ConfigEntry<bool> NoDof;

		public static ConfigEntry<bool> NoMotionBlur;

		public static ConfigEntry<float> Temperature;

		public static ConfigEntry<float> Tint;

		public static ConfigEntry<float> PostExposure;

		public static ConfigEntry<float> Contrast;

		public static ConfigEntry<float> Saturation;

		public static ConfigEntry<float> NightExposureDip;

		public static ConfigEntry<bool> WeatherEnabled;

		public static ConfigEntry<bool> RandomRain;

		public static ConfigEntry<bool> AlwaysRain;

		public static ConfigEntry<float> RainChance;

		public static ConfigEntry<float> RainMin;

		public static ConfigEntry<float> RainMax;

		public static ConfigEntry<float> RainTransition;

		public static ConfigEntry<float> RainLight;

		public static ConfigEntry<float> RainExposureDip;

		public static ConfigEntry<float> RainVolume;

		public static ConfigEntry<float> Thunder;

		public static ConfigEntry<float> RainDensity;

		public static ConfigEntry<float> RainDropSize;

		public static ConfigEntry<bool> AudioEnabled;

		public static ConfigEntry<float> DayBedVolume;

		public static ConfigEntry<float> NightBedVolume;

		public static ConfigEntry<float> BedFade;

		public static ConfigEntry<float> RainBedMultiplier;

		public static ConfigEntry<bool> MenuEnabled;

		public static ConfigEntry<string> RainKey;

		public static ConfigEntry<string> MenuKey;

		public static KeyCode RainKeyCode = (KeyCode)291;

		public static KeyCode MenuKeyCode = (KeyCode)292;

		private static ConfigEntry<T> B<T>(string s, string k, T d, string desc)
		{
			return File.Bind<T>(s, k, d, desc);
		}

		public static void Init(ConfigFile c)
		{
			File = c;
			File.SaveOnConfigSet = false;
			DayCycle = B("Day cycle", "Enabled", d: true, "Real-clock day/night cycle. Overrides the game's static sun.");
			ClockMode = B("Day cycle", "Clock mode", 0, "0 = follow the game's own SkyManager clock, 1 = drive SkyManager from this mod's real-clock cycle.");
			DriveSunLight = B("Day cycle", "Drive sun light directly", d: false, "Off: SkyManager owns the sun light and ambient; the mod only adds sky/grading/moon/clouds. On: the mod also rotates/dims the light itself (can fight SkyManager).");
			VisualHourOffset = B("Day cycle", "Visual hour offset", 0f, "-12..12. Shifts when the mod's sky/moon/stars think it is dusk relative to the game's hour. Use if the moon or sunset colours are out of step with the game's lighting.");
			Debug = B("Day cycle", "Debug logging", d: true, "Periodic SKYSYNC / CELESTIALS lines in the log for calibration.");
			CycleMinutes = B("Day cycle", "Cycle minutes", 60f, "Real minutes per full day (5-1440). 1440 = follows the real day.");
			NoonMinute = B("Day cycle", "Noon at minute", 0f, "Minute of the hour that is noon (cycles under 12h only).");
			Freeze = B("Day cycle", "Hold time of day", d: false, "Freeze the clock at 'Time to hold'.");
			FrozenHour = B("Day cycle", "Time to hold", 18f, "0-24. 12 noon, 0/24 midnight, 18 sunset, 6 sunrise.");
			MaxElevation = B("Day cycle", "Max sun elevation", 70f, "Noon sun height in degrees (20-80).");
			Azimuth = B("Day cycle", "Sun azimuth", 330f, "Compass offset of the sun path.");
			NightBrightness = B("Day cycle", "Night brightness", 0.5f, "0-1 moonlight strength vs daylight.");
			MinNightLight = B("Day cycle", "Minimum night light", 0.3f, "0.15-0.7 floor for the main light at night.");
			ShadowStrength = B("Day cycle", "Shadow strength", 0.8f, "0-1 sun shadow strength.");
			AmbientIntensity = B("Day cycle", "Ambient multiplier", 1f, "Multiplier on ambient light.");
			TwilightWidth = B("Day cycle", "Twilight width", 18f, "Degrees either side of the horizon a twilight reaches.");
			TwilightFalloff = B("Day cycle", "Twilight falloff", 3f, "Higher pushes colour into the last few degrees.");
			TwilightWorldTint = B("Day cycle", "Twilight world tint", 0.5f, "0-4 how much the whole frame takes the twilight colour.");
			PinkChance = B("Day cycle", "Pink twilight chance", 0.05f, "0-1.");
			RedChance = B("Day cycle", "Crimson twilight chance", 0.03f, "0-1.");
			TwilightOverride = B("Day cycle", "Force twilight colour", 0, "0 random, 1 golden, 2 yellow dawn, 3 pink, 4 crimson.");
			InactiveScenes = B("Day cycle", "Inactive scenes", "", "Comma list of scene names where all effects are hidden (main menu, etc).");
			SkyEnabled = B("Sky", "Replace skybox", d: true, "Procedural sky. F5 toggles.");
			ForceSkyboxClear = B("Sky", "Force camera to render skybox", d: true, "Sets camera clear flags to Skybox if the game uses a solid colour.");
			SkyExposure = B("Sky", "Exposure", 1.2f, "Skybox brightness.");
			Atmosphere = B("Sky", "Atmosphere thickness", 0.7f, "0.5-2.");
			SunSize = B("Sky", "Sun size", 0.028f, "Apparent daytime sun size.");
			StarsEnabled = B("Sky", "Stars", d: true, "");
			StarCount = B("Sky", "Star count", 200, "40-800.");
			MoonEnabled = B("Sky", "Moon phases", d: true, "");
			MoonSize = B("Sky", "Moon size", 0.075f, "");
			LunarDays = B("Sky", "Lunar cycle game days", 8f, "");
			SunsetGlow = B("Sky", "Sunset glow", d: true, "");
			GlowStrength = B("Sky", "Sunset glow strength", 1f, "0-2.");
			CloudsEnabled = B("Sky", "Clouds", d: true, "Procedural drifting clouds.");
			CloudCount = B("Sky", "Cloud count", 24, "1-40.");
			CloudSpeed = B("Sky", "Cloud speed", 0.8f, "m/s.");
			CloudDirection = B("Sky", "Cloud direction", 25f, "Degrees.");
			CloudAltitude = B("Sky", "Cloud altitude", 90f, "World units. Raise if your world is tall.");
			CloudScale = B("Sky", "Cloud scale", 1f, "0.3-3.");
			GradingEnabled = B("Grading", "Enabled", d: true, "URP colour grade. F6 toggles.");
			Temperature = B("Grading", "Temperature", 0f, "-100..100");
			Tint = B("Grading", "Tint", 0f, "-100..100");
			PostExposure = B("Grading", "Post exposure", 0f, "EV");
			Contrast = B("Grading", "Contrast", 10f, "-100..100");
			Saturation = B("Grading", "Saturation", 3f, "-100..100");
			NightExposureDip = B("Grading", "Night exposure dip", -0.12f, "EV at deep night.");
			NoBloom = B("Grading", "Override bloom off", d: false, "");
			NoVignette = B("Grading", "Override vignette off", d: false, "");
			NoGrain = B("Grading", "Override film grain off", d: false, "");
			NoDof = B("Grading", "Override depth of field off", d: false, "");
			NoMotionBlur = B("Grading", "Override motion blur off", d: false, "");
			WeatherEnabled = B("Weather", "Enabled", d: true, "");
			RandomRain = B("Weather", "Random rain", d: true, "");
			AlwaysRain = B("Weather", "Always raining", d: false, "");
			RainChance = B("Weather", "Rain chance", 0.2f, "0.02-0.9, roughly the share of time it rains.");
			RainMin = B("Weather", "Rain minutes min", 2.5f, "");
			RainMax = B("Weather", "Rain minutes max", 5.5f, "");
			RainTransition = B("Weather", "Transition seconds", 14f, "");
			RainLight = B("Weather", "Rain light multiplier", 0.58f, "0.2-1.");
			RainExposureDip = B("Weather", "Rain exposure dip", -0.18f, "EV");
			RainVolume = B("Weather", "Rain volume", 0.5f, "0-1.");
			Thunder = B("Weather", "Thunder per minute", 0.06f, "");
			RainDensity = B("Weather", "Rain density", 1.4f, "0.5-2.");
			RainDropSize = B("Weather", "Rain drop size", 0.6f, "0.4-1.4.");
			RainKey = B("Weather", "Toggle rain key", "F10", "");
			AudioEnabled = B("Audio", "Enabled", d: true, "Rain loop is generated. Optional beds: audio/day_bed.ogg, night_bed.ogg, thunder.ogg.");
			DayBedVolume = B("Audio", "Day bed volume", 0.05f, "");
			NightBedVolume = B("Audio", "Night bed volume", 0.06f, "");
			BedFade = B("Audio", "Fade seconds", 12f, "");
			RainBedMultiplier = B("Audio", "Bed volume in rain", 0.2f, "");
			MenuEnabled = B("Interface", "Enable menu", d: true, "");
			MenuKey = B("Interface", "Menu key", "F11", "");
			Reparse();
			RainKey.SettingChanged += delegate
			{
				Reparse();
			};
			MenuKey.SettingChanged += delegate
			{
				Reparse();
			};
			File.Save();
		}

		private static void Reparse()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			RainKeyCode = (KeyCode)((!Enum.TryParse<KeyCode>(RainKey.Value, ignoreCase: true, out KeyCode result)) ? 291 : ((int)result));
			MenuKeyCode = (KeyCode)((!Enum.TryParse<KeyCode>(MenuKey.Value, ignoreCase: true, out result)) ? 292 : ((int)result));
		}

		public static void MarkDirty()
		{
			_dirty = true;
		}

		public static void FlushIfIdle(bool force)
		{
			if (_dirty && (force || !(Time.unscaledTime - _lastSave < 1.5f)))
			{
				_dirty = false;
				_lastSave = Time.unscaledTime;
				File.Save();
			}
		}
	}
	internal static class Sky
	{
		private static Material _mat;

		private static Material _orig;

		private static bool _applied;

		private static bool _warned;

		private static bool _hooked;

		public static bool Active => _applied && (Object)(object)_mat != (Object)null && Settings.SkyEnabled.Value && (Object)(object)RenderSettings.skybox == (Object)(object)_mat;

		public static void Reset()
		{
			_applied = false;
		}

		public static void Hook()
		{
			if (!_hooked)
			{
				_hooked = true;
				RenderPipelineManager.beginCameraRendering += Action<ScriptableRenderContext, Camera>.op_Implicit((Action<ScriptableRenderContext, Camera>)OnBeginCamera);
				Plugin.L.LogInfo((object)"SKY render hook installed.");
			}
		}

		private static void OnBeginCamera(ScriptableRenderContext ctx, Camera cam)
		{
			try
			{
				if ((Object)(object)cam != (Object)null && (Object)(object)cam == (Object)(object)Env.Cam)
				{
					Enforce(cam);
				}
			}
			catch
			{
			}
		}

		private static void Enforce(Camera cam)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			if (!_applied || (Object)(object)_mat == (Object)null || !Settings.SkyEnabled.Value)
			{
				return;
			}
			if ((Object)(object)RenderSettings.skybox != (Object)(object)_mat)
			{
				RenderSettings.skybox = _mat;
			}
			if (!((Object)(object)cam == (Object)null))
			{
				if (Settings.ForceSkyboxClear.Value && (int)cam.clearFlags != 1)
				{
					cam.clearFlags = (CameraClearFlags)1;
				}
				Skybox component = ((Component)cam).GetComponent<Skybox>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled && (Object)(object)component.material != (Object)(object)_mat)
				{
					component.material = _mat;
				}
			}
		}

		public static void Guard()
		{
			Enforce(Env.Cam);
		}

		public static void Apply()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.SkyEnabled.Value)
			{
				Restore();
				return;
			}
			if ((Object)(object)_mat == (Object)null)
			{
				Shader val = Env.FindShader("Skybox/Procedural");
				if ((Object)(object)val == (Object)null)
				{
					if (!_warned)
					{
						_warned = true;
						Plugin.L.LogWarning((object)"Skybox/Procedural not found (stripped from build?). Sky replacement unavailable.");
					}
					return;
				}
				_mat = Env.Keep<Material>(new Material(val));
				((Object)_mat).name = "BWDN Sky";
				_mat.DisableKeyword("_SUNDISK_SIMPLE");
				_mat.DisableKeyword("_SUNDISK_HIGH_QUALITY");
				_mat.EnableKeyword("_SUNDISK_NONE");
				_mat.SetFloat("_SunDisk", 0f);
			}
			if ((Object)(object)RenderSettings.skybox != (Object)(object)_mat)
			{
				if (!_applied || (Object)(object)RenderSettings.skybox != (Object)null)
				{
					_orig = RenderSettings.skybox;
				}
				RenderSettings.skybox = _mat;
			}
			_applied = true;
			if (Env.CelestialValid)
			{
				float dayWeight = Env.DayWeight;
				float twilight = Env.Twilight;
				float signedElevation = Env.SignedElevation;
				float rainBlend = Env.RainBlend;
				float num = 1f - Mathf.Clamp01(signedElevation / 35f);
				_mat.SetFloat("_Exposure", Mathf.Clamp(Settings.SkyExposure.Value, 0.05f, 8f) * Mathf.Lerp(0.5f, 1f, dayWeight) * (1f - 0.18f * twilight) * Mathf.Lerp(1f, 0.62f, rainBlend));
				_mat.SetFloat("_AtmosphereThickness", Mathf.Lerp(Mathf.Clamp(Settings.Atmosphere.Value + 0.3f * num * dayWeight, 0.1f, 3f), 0.55f, rainBlend));
				float num2 = Mathf.Max(num * dayWeight, twilight * Mathf.Clamp01((signedElevation + 12f) / 14f));
				Color twilightSky = Env.TwilightSky;
				float num3 = twilightSky.r * 0.72f;
				if (twilightSky.g > num3)
				{
					twilightSky.g = num3;
				}
				Color val2 = Color.Lerp(new Color(0.5f, 0.5f, 0.5f, 1f), twilightSky, num2 * 0.9f);
				_mat.SetColor("_SkyTint", Color.Lerp(val2, new Color(0.36f, 0.41f, 0.49f, 1f), rainBlend));
				_mat.SetColor("_GroundColor", new Color(0.6f, 0.8f, 0.85f, 1f) * Mathf.Lerp(0.45f, 1f, dayWeight));
			}
		}

		private static void Restore()
		{
			if (_applied && (Object)(object)_mat != (Object)null && (Object)(object)RenderSettings.skybox == (Object)(object)_mat)
			{
				RenderSettings.skybox = _orig;
			}
			_applied = false;
		}
	}
	internal static class Grading
	{
		private static GameObject _go;

		private static Volume _vol;

		private static VolumeProfile _profile;

		private static WhiteBalance _wb;

		private static ColorAdjustments _ca;

		private static Bloom _bloom;

		private static Vignette _vig;

		private static FilmGrain _grain;

		private static DepthOfField _dof;

		private static MotionBlur _mb;

		private static float _nextCam;

		private static void Build()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_go = new GameObject("BWDN Global Volume");
			Object.DontDestroyOnLoad((Object)(object)_go);
			_vol = _go.AddComponent<Volume>();
			_vol.isGlobal = true;
			_vol.priority = 5000f;
			_profile = Env.Keep<VolumeProfile>(ScriptableObject.CreateInstance<VolumeProfile>());
			_wb = _profile.Add<WhiteBalance>(true);
			_ca = _profile.Add<ColorAdjustments>(true);
			_bloom = _profile.Add<Bloom>(true);
			_vig = _profile.Add<Vignette>(true);
			_grain = _profile.Add<FilmGrain>(true);
			_dof = _profile.Add<DepthOfField>(true);
			_mb = _profile.Add<MotionBlur>(true);
			_vol.sharedProfile = _profile;
			Plugin.L.LogInfo((object)"GRADING volume created.");
		}

		public static void Apply()
		{
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_vol == (Object)null)
			{
				Build();
			}
			((Behaviour)_vol).enabled = Settings.GradingEnabled.Value;
			if (Settings.GradingEnabled.Value)
			{
				((VolumeParameter<float>)(object)_wb.temperature).Override(Mathf.Clamp(Settings.Temperature.Value, -100f, 100f));
				((VolumeParameter<float>)(object)_wb.tint).Override(Mathf.Clamp(Settings.Tint.Value, -100f, 100f));
				((VolumeParameter<float>)(object)_ca.contrast).Override(Mathf.Clamp(Settings.Contrast.Value, -100f, 100f));
				((VolumeParameter<float>)(object)_ca.saturation).Override(Mathf.Clamp(Settings.Saturation.Value, -100f, 100f));
				((VolumeParameter<float>)(object)_bloom.intensity).value = 0f;
				((VolumeParameter)_bloom.intensity).overrideState = Settings.NoBloom.Value;
				((VolumeParameter<float>)(object)_vig.intensity).value = 0f;
				((VolumeParameter)_vig.intensity).overrideState = Settings.NoVignette.Value;
				((VolumeParameter<float>)(object)_grain.intensity).value = 0f;
				((VolumeParameter)_grain.intensity).overrideState = Settings.NoGrain.Value;
				((VolumeParameter<DepthOfFieldMode>)(object)_dof.mode).value = (DepthOfFieldMode)0;
				((VolumeParameter)_dof.mode).overrideState = Settings.NoDof.Value;
				((VolumeParameter<float>)(object)_mb.intensity).value = 0f;
				((VolumeParameter)_mb.intensity).overrideState = Settings.NoMotionBlur.Value;
				if (!Env.CelestialValid)
				{
					((VolumeParameter<float>)(object)_ca.postExposure).Override(Settings.PostExposure.Value);
					return;
				}
				float dayWeight = Env.DayWeight;
				float twilight = Env.Twilight;
				float rainBlend = Env.RainBlend;
				float num = Settings.NightExposureDip.Value * (1f - dayWeight) * Mathf.Lerp(1f, 0.4f, twilight) + Settings.RainExposureDip.Value * rainBlend;
				((VolumeParameter<float>)(object)_ca.postExposure).Override(Settings.PostExposure.Value + num + Env.Lightning * 1f);
				Color val = Color.Lerp(new Color(0.88f, 0.91f, 1f, 1f), Color.white, dayWeight);
				Color val2 = Color.LerpUnclamped(Color.white, Color.Lerp(Color.white, Env.TwilightGlow, 0.75f), Mathf.Clamp(Settings.TwilightWorldTint.Value, 0f, 4f) * twilight);
				val2.r = Mathf.Max(0f, val2.r);
				val2.g = Mathf.Max(0f, val2.g);
				val2.b = Mathf.Max(0f, val2.b);
				val *= val2;
				val *= Color.Lerp(Color.white, new Color(0.88f, 0.91f, 0.97f, 1f), rainBlend);
				((VolumeParameter<Color>)(object)_ca.colorFilter).Override(val);
			}
		}

		public static void EnsureCamera()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextCam)
			{
				return;
			}
			_nextCam = Time.unscaledTime + 1f;
			Camera cam = Env.Cam;
			if ((Object)(object)cam == (Object)null || (Object)(object)_go == (Object)null)
			{
				return;
			}
			UniversalAdditionalCameraData component = ((Component)cam).GetComponent<UniversalAdditionalCameraData>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (!component.renderPostProcessing)
			{
				component.renderPostProcessing = true;
				Plugin.L.LogInfo((object)"Camera post-processing was off; enabled.");
			}
			LayerMask volumeLayerMask = component.volumeLayerMask;
			int value = ((LayerMask)(ref volumeLayerMask)).value;
			if ((value & (1 << _go.layer)) != 0)
			{
				return;
			}
			for (int i = 0; i < 32; i++)
			{
				if ((value & (1 << i)) != 0)
				{
					_go.layer = i;
					break;
				}
			}
		}
	}
	internal static class SunCycle
	{
		private static Light _sun;

		private static Quaternion _rot;

		private static Color _col;

		private static float _int;

		private static float _shadow;

		private static bool _ambCap;

		private static AmbientMode _ambMode;

		private static Color _ambLight;

		private static Color _ambSky;

		private static Color _ambEq;

		private static Color _ambGround;

		private static float _ambInt;

		private static bool _drove;

		private static float _next;

		private static float _nextFind;

		private static float _nextGi;

		private static float _nextDbg;

		private static int _lastHalf = int.MinValue;

		private static int _lastOv = -1;

		private static bool _forced;

		private static float _origHour = -1f;

		private static bool _warnedSky;

		private static float _prevHour = -1f;

		private static int _dayCount;

		private static float _lastAz;

		public static bool HasSun => (Object)(object)_sun != (Object)null;

		public static Light Sun => _sun;

		public static void Reset()
		{
			_sun = null;
			_ambCap = false;
			_drove = false;
			Env.CelestialValid = false;
		}

		private static Light FindSun()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			Light sun = RenderSettings.sun;
			if ((Object)(object)sun != (Object)null)
			{
				return sun;
			}
			Light val = null;
			foreach (Light item in Object.FindObjectsOfType<Light>())
			{
				if (!((Object)(object)item == (Object)null) && (int)item.type == 1 && ((Behaviour)item).enabled && ((Object)(object)val == (Object)null || item.intensity > val.intensity))
				{
					val = item;
				}
			}
			return val;
		}

		private static bool SkyReady()
		{
			try
			{
				return SkyManager.initalized;
			}
			catch
			{
				if (!_warnedSky)
				{
					_warnedSky = true;
					Plugin.L.LogWarning((object)"SkyManager not available yet; using the mod's own clock for visuals.");
				}
				return false;
			}
		}

		private static float RealClockHour()
		{
			double num = Mathf.Clamp(Settings.CycleMinutes.Value, 5f, 1440f);
			double num2 = num * 60.0;
			double num3 = ((num >= 720.0) ? 43200.0 : ((double)Settings.NoonMinute.Value * 60.0));
			double num4 = DateTime.Now.TimeOfDay.TotalSeconds - num3;
			float num5 = (float)((num4 % num2 + num2) % num2 / num2);
			return Mathf.Repeat(num5 * 24f + 12f, 24f);
		}

		private static float ResolveHour()
		{
			bool flag = SkyReady();
			bool value = Settings.Freeze.Value;
			bool flag2 = value || Settings.ClockMode.Value == 1;
			float num = RealClockHour();
			if (flag2)
			{
				float num2 = (value ? Mathf.Repeat(Mathf.Clamp(Settings.FrozenHour.Value, 0f, 24f), 24f) : num);
				if (flag)
				{
					try
					{
						if (!_forced)
						{
							_origHour = SkyManager.GetCurrentTime();
						}
						SkyManager.SetFixedTime(num2);
						_forced = true;
					}
					catch (Exception ex)
					{
						Plugin.L.LogWarning((object)("SkyManager.SetFixedTime failed: " + ex.Message));
					}
				}
				return num2;
			}
			ReleaseForce();
			if (flag)
			{
				try
				{
					return SkyManager.GetCurrentTime();
				}
				catch
				{
				}
			}
			return num;
		}

		private static void ReleaseForce()
		{
			if (!_forced)
			{
				return;
			}
			_forced = false;
			if (!SkyReady())
			{
				return;
			}
			try
			{
				if (_origHour >= 0f)
				{
					SkyManager.SetFixedTime(_origHour);
				}
				SkyManager.ClearFixedTime();
				Plugin.L.LogInfo((object)("SkyManager released (restored " + _origHour.ToString("0.0") + "h)."));
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("SkyManager release failed: " + ex.Message));
			}
		}

		private static void RestoreLight()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (_drove)
			{
				_drove = false;
				if ((Object)(object)_sun != (Object)null)
				{
					((Component)_sun).transform.rotation = _rot;
					_sun.color = _col;
					_sun.intensity = _int;
					_sun.shadowStrength = _shadow;
				}
				if (_ambCap)
				{
					RenderSettings.ambientLight = _ambLight;
					RenderSettings.ambientSkyColor = _ambSky;
					RenderSettings.ambientEquatorColor = _ambEq;
					RenderSettings.ambientGroundColor = _ambGround;
					RenderSettings.ambientIntensity = _ambInt;
				}
			}
		}

		public static bool Tick()
		{
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			if ((Object)(object)_sun == (Object)null)
			{
				if (unscaledTime < _nextFind)
				{
					return false;
				}
				_nextFind = unscaledTime + 2f;
				_sun = FindSun();
				if ((Object)(object)_sun == (Object)null)
				{
					return false;
				}
				if ((Object)(object)RenderSettings.sun == (Object)null)
				{
					RenderSettings.sun = _sun;
				}
				_rot = ((Component)_sun).transform.rotation;
				_col = _sun.color;
				_int = _sun.intensity;
				_shadow = _sun.shadowStrength;
				Plugin.L.LogInfo((object)("SUN found '" + ((Object)_sun).name + "' intensity=" + _int + " euler=" + ((object)((Quaternion)(ref _rot)).eulerAngles/*cast due to .constrained prefix*/).ToString() + " skyManagerReady=" + SkyReady()));
			}
			if (!_ambCap)
			{
				_ambMode = RenderSettings.ambientMode;
				_ambLight = RenderSettings.ambientLight;
				_ambSky = RenderSettings.ambientSkyColor;
				_ambEq = RenderSettings.ambientEquatorColor;
				_ambGround = RenderSettings.ambientGroundColor;
				_ambInt = RenderSettings.ambientIntensity;
				_ambCap = true;
			}
			if (!Settings.DayCycle.Value)
			{
				ReleaseForce();
				RestoreLight();
				Env.CelestialValid = false;
				return false;
			}
			if (unscaledTime < _next)
			{
				return false;
			}
			_next = unscaledTime + 0.05f;
			float num = Mathf.Repeat(ResolveHour() + Settings.VisualHourOffset.Value, 24f);
			if (_prevHour > 20f && num < 4f)
			{
				_dayCount++;
			}
			_prevHour = num;
			float num2 = (Env.Phase = Mathf.Repeat((num - 12f) / 24f, 1f));
			float num3 = Mathf.Clamp(Settings.MaxElevation.Value, 20f, 80f);
			float num4 = num3 * Mathf.Cos(num2 * 2f * (float)Math.PI);
			float elev = Mathf.Sqrt(num4 * num4 + 36f);
			float num5 = Mathf.Clamp01((num4 + 8f) / 16f);
			float num6 = Env.TwilightCurve(num4);
			bool value = Settings.DriveSunLight.Value;
			float num7;
			if (value)
			{
				num7 = Mathf.Repeat(Settings.Azimuth.Value + num2 * 360f, 360f);
			}
			else
			{
				Vector3 forward = ((Component)_sun).transform.forward;
				if (forward.x * forward.x + forward.z * forward.z > 0.0025f)
				{
					_lastAz = Mathf.Repeat(Mathf.Atan2(forward.x, forward.z) * 57.29578f, 360f);
				}
				num7 = _lastAz;
			}
			Env.DayWeight = num5;
			Env.SignedElevation = num4;
			Env.SunAzimuth = num7;
			Env.Twilight = num6;
			Env.CelestialValid = true;
			UpdateVariant(num);
			if (value)
			{
				DriveLight(num4, elev, num7, num5, num6);
			}
			else
			{
				RestoreLight();
			}
			if (unscaledTime >= _nextGi)
			{
				_nextGi = unscaledTime + ((num6 > 0.2f) ? 2f : 10f);
				if (value)
				{
					DynamicGI.UpdateEnvironment();
				}
			}
			if (Settings.Debug.Value && unscaledTime >= _nextDbg)
			{
				_nextDbg = unscaledTime + 10f;
				Plugin.L.LogInfo((object)("SKYSYNC hour=" + num.ToString("0.00") + " clockMode=" + Settings.ClockMode.Value + " forced=" + _forced + " skyMgr=" + SkyReady() + " signedElev=" + num4.ToString("0.0") + " day=" + num5.ToString("0.00") + " lightEuler=" + ((object)((Component)_sun).transform.eulerAngles/*cast due to .constrained prefix*/).ToString() + " lightInt=" + _sun.intensity.ToString("0.00") + " drive=" + value));
			}
			return true;
		}

		private static void DriveLight(float signed, float elev, float az, float day, float tw)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing r