Decompiled source of Quest Day Night v2.1.0

Mods/QuestDayNight.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.VRMK;
using MelonLoader;
using MelonLoader.Preferences;
using QuestDayNight;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Main), "Quest Day Night", "2.1.0", "adama", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: HarmonyDontPatchAll]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.0.0")]
[module: UnverifiableCode]
namespace QuestDayNight;

public class Main : MelonMod
{
	public enum Rating
	{
		EF1 = 1,
		EF2,
		EF3,
		EF4,
		EF5
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Action<LevelInfo> <>9__26_0;

		public static Action<bool> <>9__27_0;

		public static Action<float> <>9__27_1;

		public static Action <>9__27_2;

		public static Action <>9__27_3;

		public static Action <>9__27_4;

		public static Action <>9__27_5;

		public static Action <>9__27_6;

		public static Action<bool> <>9__27_7;

		public static Action<float> <>9__27_8;

		public static Action<bool> <>9__27_9;

		public static Action<float> <>9__27_10;

		public static Action<bool> <>9__27_11;

		public static Action<float> <>9__27_12;

		public static Action<bool> <>9__27_13;

		public static Action<float> <>9__27_14;

		public static Action <>9__27_15;

		public static Action<bool> <>9__27_16;

		public static Action<global::System.Enum> <>9__27_17;

		public static Action<bool> <>9__27_18;

		public static Action <>9__27_19;

		public static Action<bool> <>9__27_20;

		public static Action<float> <>9__27_21;

		public static Action<bool> <>9__27_22;

		public static Action<bool> <>9__27_23;

		public static Action<float> <>9__27_24;

		public static Action<bool> <>9__27_25;

		public static Action<float> <>9__27_26;

		public static Action<float> <>9__27_27;

		internal void <OnInitializeMelon>b__26_0(LevelInfo _)
		{
			Sky.OnLevelLoaded();
		}

		internal void <OnLateInitializeMelon>b__27_0(bool v)
		{
			On.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_1(float v)
		{
			SetHour(v);
		}

		internal void <OnLateInitializeMelon>b__27_2()
		{
			SetHour(6.2f);
		}

		internal void <OnLateInitializeMelon>b__27_3()
		{
			SetHour(12f);
		}

		internal void <OnLateInitializeMelon>b__27_4()
		{
			SetHour(17.4f);
		}

		internal void <OnLateInitializeMelon>b__27_5()
		{
			SetHour(17.8f);
		}

		internal void <OnLateInitializeMelon>b__27_6()
		{
			SetHour(0f);
		}

		internal void <OnLateInitializeMelon>b__27_7(bool v)
		{
			TimeRuns.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_8(float v)
		{
			DayMinutes.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_9(bool v)
		{
			Clouds.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_10(float v)
		{
			CloudAmount.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_11(bool v)
		{
			Rain.Value = v;
			Save();
			Sky.Refresh();
		}

		internal void <OnLateInitializeMelon>b__27_12(float v)
		{
			RainAmount.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_13(bool v)
		{
			Thunder.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_14(float v)
		{
			ThunderDistance.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_15()
		{
			Storm.Strike();
		}

		internal void <OnLateInitializeMelon>b__27_16(bool v)
		{
			TornadoOn.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_17(global::System.Enum v)
		{
			TornadoRating.Value = Convert.ToInt32((object)v);
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_18(bool v)
		{
			TornadoLifts.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_19()
		{
			Tornado.Toward();
		}

		internal void <OnLateInitializeMelon>b__27_20(bool v)
		{
			RadarOn.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_21(float v)
		{
			NightDarkness.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_22(bool v)
		{
			AutoDaylight.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_23(bool v)
		{
			Flare.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_24(float v)
		{
			FlareStrength.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_25(bool v)
		{
			Shadows.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_26(float v)
		{
			ShadowDarkness.Value = v;
			Save();
		}

		internal void <OnLateInitializeMelon>b__27_27(float v)
		{
			SandboxRadius.Value = v;
			Save();
		}
	}

	internal const string Version = "2.1.0";

	internal static Instance Log;

	private static MelonPreferences_Category _prefs;

	internal static MelonPreferences_Entry<bool> On;

	internal static MelonPreferences_Entry<bool> TimeRuns;

	internal static MelonPreferences_Entry<bool> Clouds;

	internal static MelonPreferences_Entry<bool> AutoDaylight;

	internal static MelonPreferences_Entry<bool> Flare;

	internal static MelonPreferences_Entry<bool> Shadows;

	internal static MelonPreferences_Entry<bool> Rain;

	internal static MelonPreferences_Entry<bool> Thunder;

	internal static MelonPreferences_Entry<bool> TornadoOn;

	internal static MelonPreferences_Entry<bool> TornadoLifts;

	internal static MelonPreferences_Entry<bool> RadarOn;

	internal static MelonPreferences_Entry<float> Hour;

	internal static MelonPreferences_Entry<float> DayMinutes;

	internal static MelonPreferences_Entry<float> CloudAmount;

	internal static MelonPreferences_Entry<float> NightDarkness;

	internal static MelonPreferences_Entry<float> FlareStrength;

	internal static MelonPreferences_Entry<float> SandboxRadius;

	internal static MelonPreferences_Entry<float> ShadowDarkness;

	internal static MelonPreferences_Entry<float> RainAmount;

	internal static MelonPreferences_Entry<float> ThunderDistance;

	internal static MelonPreferences_Entry<int> TornadoRating;

	private static float _nextError;

	public override void OnInitializeMelon()
	{
		Log = ((MelonBase)this).LoggerInstance;
		_prefs = MelonPreferences.CreateCategory("QuestDayNight");
		On = _prefs.CreateEntry<bool>("On", true, "Day and night on", (string)null, false, false, (ValueValidator)null, (string)null);
		Hour = _prefs.CreateEntry<float>("Hour", 12f, "The time of day (0-24)", (string)null, false, false, (ValueValidator)null, (string)null);
		TimeRuns = _prefs.CreateEntry<bool>("TimeRuns", true, "Time passes by itself", (string)null, false, false, (ValueValidator)null, (string)null);
		DayMinutes = _prefs.CreateEntry<float>("DayMinutes", 24f, "Real minutes in a whole day", (string)null, false, false, (ValueValidator)null, (string)null);
		Clouds = _prefs.CreateEntry<bool>("Clouds", true, "Clouds", (string)null, false, false, (ValueValidator)null, (string)null);
		CloudAmount = _prefs.CreateEntry<float>("CloudAmount", 0.5f, "How cloudy (0-1)", (string)null, false, false, (ValueValidator)null, (string)null);
		NightDarkness = _prefs.CreateEntry<float>("NightDarkness", 1f, "How dark night is (0-1)", (string)null, false, false, (ValueValidator)null, (string)null);
		AutoDaylight = _prefs.CreateEntry<bool>("AutoDaylight", true, "Brighten dark maps in the daytime", (string)null, false, false, (ValueValidator)null, (string)null);
		Flare = _prefs.CreateEntry<bool>("LensFlare", true, "Sunbeams fanning out from the sun across the sky", (string)null, false, false, (ValueValidator)null, (string)null);
		FlareStrength = _prefs.CreateEntry<float>("FlareStrength", 1f, "How strong the sunbeams are", (string)null, false, false, (ValueValidator)null, (string)null);
		SandboxRadius = _prefs.CreateEntry<float>("SandboxRadius", 0f, "How far out a flat floor reaches around you, in metres (0 = none)", (string)null, false, false, (ValueValidator)null, (string)null);
		Shadows = _prefs.CreateEntry<bool>("Shadows", true, "Your body and weapons cast a shadow from the sun", (string)null, false, false, (ValueValidator)null, (string)null);
		ShadowDarkness = _prefs.CreateEntry<float>("ShadowDarkness", 0.55f, "How dark your shadow is (0-1)", (string)null, false, false, (ValueValidator)null, (string)null);
		Rain = _prefs.CreateEntry<bool>("Rain", false, "Rain: streaks and splashes round you (not under a roof), its sound, a grey sky", (string)null, false, false, (ValueValidator)null, (string)null);
		RainAmount = _prefs.CreateEntry<float>("RainAmount", 0.7f, "How hard it rains (0.1-1)", (string)null, false, false, (ValueValidator)null, (string)null);
		Thunder = _prefs.CreateEntry<bool>("Thunder", false, "Thunderstorms: lightning in the sky and thunder now and then", (string)null, false, false, (ValueValidator)null, (string)null);
		ThunderDistance = _prefs.CreateEntry<float>("ThunderDistance", 800f, "How far away lightning strikes, in metres (50 = right on top of you)", (string)null, false, false, (ValueValidator)null, (string)null);
		TornadoOn = _prefs.CreateEntry<bool>("Tornado", false, "A tornado on the map: dark green storm sky, its wind and roar", (string)null, false, false, (ValueValidator)null, (string)null);
		TornadoRating = _prefs.CreateEntry<int>("TornadoRating", 3, "Its strength on the Enhanced Fujita scale (1-5)", (string)null, false, false, (ValueValidator)null, (string)null);
		TornadoLifts = _prefs.CreateEntry<bool>("TornadoLiftsYou", true, "Its wind can push and lift you too", (string)null, false, false, (ValueValidator)null, (string)null);
		RadarOn = _prefs.CreateEntry<bool>("RadarScreen", true, "The weather radar screen at your lower left", (string)null, false, false, (ValueValidator)null, (string)null);
		Hooking.OnLevelLoaded += delegate
		{
			Sky.OnLevelLoaded();
		};
	}

	public override void OnLateInitializeMelon()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Expected O, but got Unknown
		//IL_017a: 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_015f: Expected O, but got Unknown
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Expected O, but got Unknown
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0440: Unknown result type (might be due to invalid IL or missing references)
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_0459: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Expected O, but got Unknown
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0543: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_055c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0567: Expected O, but got Unknown
		//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_062c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0666: Unknown result type (might be due to invalid IL or missing references)
		//IL_06af: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0731: Unknown result type (might be due to invalid IL or missing references)
		Page obj = Page.Root.CreatePage("Quest Day Night", new Color(1f, 0.75f, 0.3f), 0, true);
		obj.CreateBool("Day And Night", Color.white, On.Value, (Action<bool>)delegate(bool v)
		{
			On.Value = v;
			Save();
		});
		obj.CreateFloat("Time (hour)", Color.white, Hour.Value, 0.5f, 0f, 24f, (Action<float>)delegate(float v)
		{
			SetHour(v);
		});
		Color val = new Color(1f, 0.7f, 0.4f);
		object obj2 = <>c.<>9__27_2;
		if (obj2 == null)
		{
			Action val2 = delegate
			{
				SetHour(6.2f);
			};
			<>c.<>9__27_2 = val2;
			obj2 = (object)val2;
		}
		obj.CreateFunction("Sunrise", val, (Action)obj2);
		Color val3 = new Color(1f, 1f, 0.7f);
		object obj3 = <>c.<>9__27_3;
		if (obj3 == null)
		{
			Action val4 = delegate
			{
				SetHour(12f);
			};
			<>c.<>9__27_3 = val4;
			obj3 = (object)val4;
		}
		obj.CreateFunction("Noon", val3, (Action)obj3);
		Color val5 = new Color(1f, 0.85f, 0.55f);
		object obj4 = <>c.<>9__27_4;
		if (obj4 == null)
		{
			Action val6 = delegate
			{
				SetHour(17.4f);
			};
			<>c.<>9__27_4 = val6;
			obj4 = (object)val6;
		}
		obj.CreateFunction("Golden Hour", val5, (Action)obj4);
		Color val7 = new Color(1f, 0.5f, 0.3f);
		object obj5 = <>c.<>9__27_5;
		if (obj5 == null)
		{
			Action val8 = delegate
			{
				SetHour(17.8f);
			};
			<>c.<>9__27_5 = val8;
			obj5 = (object)val8;
		}
		obj.CreateFunction("Sunset", val7, (Action)obj5);
		Color val9 = new Color(0.5f, 0.6f, 1f);
		object obj6 = <>c.<>9__27_6;
		if (obj6 == null)
		{
			Action val10 = delegate
			{
				SetHour(0f);
			};
			<>c.<>9__27_6 = val10;
			obj6 = (object)val10;
		}
		obj.CreateFunction("Midnight", val9, (Action)obj6);
		obj.CreateBool("Time Runs", Color.white, TimeRuns.Value, (Action<bool>)delegate(bool v)
		{
			TimeRuns.Value = v;
			Save();
		});
		obj.CreateFloat("Day Length (minutes)", Color.white, DayMinutes.Value, 2f, 2f, 120f, (Action<float>)delegate(float v)
		{
			DayMinutes.Value = v;
			Save();
		});
		obj.CreateBool("Clouds", Color.white, Clouds.Value, (Action<bool>)delegate(bool v)
		{
			Clouds.Value = v;
			Save();
		});
		obj.CreateFloat("Cloud Amount", Color.white, CloudAmount.Value, 0.1f, 0.1f, 1f, (Action<float>)delegate(float v)
		{
			CloudAmount.Value = v;
			Save();
		});
		obj.CreateBool("Rain", new Color(0.6f, 0.75f, 1f), Rain.Value, (Action<bool>)delegate(bool v)
		{
			Rain.Value = v;
			Save();
			Sky.Refresh();
		});
		obj.CreateFloat("Rain Amount", new Color(0.6f, 0.75f, 1f), RainAmount.Value, 0.1f, 0.1f, 1f, (Action<float>)delegate(float v)
		{
			RainAmount.Value = v;
			Save();
		});
		obj.CreateBool("Thunder", new Color(0.75f, 0.7f, 1f), Thunder.Value, (Action<bool>)delegate(bool v)
		{
			Thunder.Value = v;
			Save();
		});
		obj.CreateFloat("Thunder Distance (m)", new Color(0.75f, 0.7f, 1f), ThunderDistance.Value, 50f, 50f, 5000f, (Action<float>)delegate(float v)
		{
			ThunderDistance.Value = v;
			Save();
		});
		Color val11 = new Color(0.85f, 0.85f, 1f);
		object obj7 = <>c.<>9__27_15;
		if (obj7 == null)
		{
			Action val12 = delegate
			{
				Storm.Strike();
			};
			<>c.<>9__27_15 = val12;
			obj7 = (object)val12;
		}
		obj.CreateFunction("Lightning Strike Now", val11, (Action)obj7);
		Color val13 = default(Color);
		((Color)(ref val13))..ctor(0.55f, 0.85f, 0.6f);
		obj.CreateBool("Tornado", val13, TornadoOn.Value, (Action<bool>)delegate(bool v)
		{
			TornadoOn.Value = v;
			Save();
		});
		obj.CreateEnum("Tornado Rating", val13, (global::System.Enum)(Rating)Math.Clamp(TornadoRating.Value, 1, 5), (Action<global::System.Enum>)delegate(global::System.Enum v)
		{
			TornadoRating.Value = Convert.ToInt32((object)v);
			Save();
		});
		obj.CreateBool("Tornado Can Lift You", val13, TornadoLifts.Value, (Action<bool>)delegate(bool v)
		{
			TornadoLifts.Value = v;
			Save();
		});
		Color val14 = new Color(1f, 0.55f, 0.45f);
		object obj8 = <>c.<>9__27_19;
		if (obj8 == null)
		{
			Action val15 = delegate
			{
				Tornado.Toward();
			};
			<>c.<>9__27_19 = val15;
			obj8 = (object)val15;
		}
		obj.CreateFunction("Tornado Toward Me", val14, (Action)obj8);
		obj.CreateBool("Radar Screen", val13, RadarOn.Value, (Action<bool>)delegate(bool v)
		{
			RadarOn.Value = v;
			Save();
		});
		obj.CreateFloat("Night Darkness", Color.white, NightDarkness.Value, 0.1f, 0f, 1f, (Action<float>)delegate(float v)
		{
			NightDarkness.Value = v;
			Save();
		});
		obj.CreateBool("Auto Daylight", Color.white, AutoDaylight.Value, (Action<bool>)delegate(bool v)
		{
			AutoDaylight.Value = v;
			Save();
		});
		obj.CreateBool("Sunbeams", Color.white, Flare.Value, (Action<bool>)delegate(bool v)
		{
			Flare.Value = v;
			Save();
		});
		obj.CreateFloat("Sunbeam Strength", Color.white, FlareStrength.Value, 0.25f, 0.25f, 3f, (Action<float>)delegate(float v)
		{
			FlareStrength.Value = v;
			Save();
		});
		obj.CreateBool("Body Shadow", Color.white, Shadows.Value, (Action<bool>)delegate(bool v)
		{
			Shadows.Value = v;
			Save();
		});
		obj.CreateFloat("Shadow Darkness", Color.white, ShadowDarkness.Value, 0.05f, 0.05f, 1f, (Action<float>)delegate(float v)
		{
			ShadowDarkness.Value = v;
			Save();
		});
		obj.CreateFloat("Sandbox Radius (m)", Color.white, SandboxRadius.Value, 10f, 0f, 3.4028235E+38f, (Action<float>)delegate(float v)
		{
			SandboxRadius.Value = v;
			Save();
		});
	}

	private static void SetHour(float hour)
	{
		Hour.Value = Mathf.Repeat(hour, 24f);
		Save();
		Sky.Refresh();
	}

	internal static void Save()
	{
		_prefs.SaveToFile(false);
	}

	public override void OnLateUpdate()
	{
		try
		{
			Sky.Tick();
		}
		catch (global::System.Exception ex)
		{
			if (!(Time.unscaledTime < _nextError))
			{
				_nextError = Time.unscaledTime + 10f;
				Log.Warning("Day and night: " + ex.Message);
			}
		}
	}
}
public static class Sync
{
	public const int Size = 12;

	[CompilerGenerated]
	private static Action<float, float, int, bool> m_Struck;

	internal static bool Live;

	internal static readonly float[] State = new float[12];

	internal static float At;

	public static event Action<float, float, int, bool> Struck
	{
		[CompilerGenerated]
		add
		{
			Action<float, float, int, bool> val = Sync.m_Struck;
			Action<float, float, int, bool> val2;
			do
			{
				val2 = val;
				Action<float, float, int, bool> val3 = (Action<float, float, int, bool>)(object)global::System.Delegate.Combine((global::System.Delegate)(object)val2, (global::System.Delegate)(object)value);
				val = Interlocked.CompareExchange<Action<float, float, int, bool>>(ref Sync.m_Struck, val3, val2);
			}
			while (val != val2);
		}
		[CompilerGenerated]
		remove
		{
			Action<float, float, int, bool> val = Sync.m_Struck;
			Action<float, float, int, bool> val2;
			do
			{
				val2 = val;
				Action<float, float, int, bool> val3 = (Action<float, float, int, bool>)(object)global::System.Delegate.Remove((global::System.Delegate)(object)val2, (global::System.Delegate)(object)value);
				val = Interlocked.CompareExchange<Action<float, float, int, bool>>(ref Sync.m_Struck, val3, val2);
			}
			while (val != val2);
		}
	}

	public static void Read(float[] into)
	{
		into[0] = Now.Hour;
		into[1] = Now.Rain;
		into[2] = (Now.Thunder ? 1f : 0f);
		into[3] = Now.ThunderDistance;
		into[4] = (Now.Tornado ? 1f : 0f);
		into[5] = Now.Rating;
		into[6] = Tornado.Position.X;
		into[7] = Tornado.Position.Z;
		into[8] = MathF.Atan2(Tornado.Heading.Z, Tornado.Heading.X);
		into[9] = (Now.Clouds ? 1f : 0f);
		into[10] = Now.CloudAmount;
		into[11] = (Tornado.Down ? 1f : 0f);
	}

	public static void Write(float[] from)
	{
		global::System.Array.Copy((global::System.Array)from, (global::System.Array)State, Math.Min(from.Length, 12));
		Live = true;
		At = Time.unscaledTime;
	}

	public static void Release()
	{
		Live = false;
	}

	public static void StrikeAt(float x, float z, int seed)
	{
		Storm.StrikeAt(x, z, seed, own: false);
	}

	internal static void OnStruck(float x, float z, int seed, bool own)
	{
		try
		{
			Sync.Struck?.Invoke(x, z, seed, own);
		}
		catch
		{
		}
	}
}
internal static class Now
{
	internal static float Hour
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.Hour.Value;
			}
			return Sync.State[0];
		}
	}

	internal static float Rain
	{
		get
		{
			if (!Sync.Live)
			{
				if (!Main.Rain.Value)
				{
					return 0f;
				}
				return Math.Clamp(Main.RainAmount.Value, 0.1f, 1f);
			}
			return Sync.State[1];
		}
	}

	internal static bool Thunder
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.Thunder.Value;
			}
			return Sync.State[2] > 0.5f;
		}
	}

	internal static float ThunderDistance
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.ThunderDistance.Value;
			}
			return Sync.State[3];
		}
	}

	internal static bool Tornado
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.TornadoOn.Value;
			}
			return Sync.State[4] > 0.5f;
		}
	}

	internal static int Rating
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.TornadoRating.Value;
			}
			return (int)Sync.State[5];
		}
	}

	internal static bool Clouds
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.Clouds.Value;
			}
			return Sync.State[9] > 0.5f;
		}
	}

	internal static float CloudAmount
	{
		get
		{
			if (!Sync.Live)
			{
				return Main.CloudAmount.Value;
			}
			return Sync.State[10];
		}
	}
}
internal static class Sky
{
	private enum Look
	{
		Circle,
		Glow,
		Streak
	}

	private readonly struct C
	{
		public readonly float R;

		public readonly float G;

		public readonly float B;

		public C(float r, float g, float b)
		{
			R = r;
			G = g;
			B = b;
		}
	}

	private const float CloudSpeed = 0.003f;

	private const float CirrusSpeed = 0.0015f;

	private const float RecolorEvery = 0.12f;

	private const float MeasureEvery = 0.5f;

	private const float Relief = 0.07f;

	private const float WantedDaylight = 0.35f;

	private const float MaxDayGain = 4f;

	private const float IndoorGrade = 0.3f;

	private const float SkyCeiling = 80f;

	private const float FlareDepth = 1.2f;

	private const float BurstSize = 0.42f;

	private const float StreakWidth = 0.03f;

	private const float SunSightEvery = 0.1f;

	private const float MaxBacklight = 0.45f;

	private const float TileMetres = 3f;

	private const float MaxFloor = 1000000f;

	private const float MaxFar = 20000f;

	private const int DomeRings = 16;

	private const int DomeSegments = 32;

	private const int StarCount = 1100;

	private const int TexSize = 256;

	private const int HazeSegments = 36;

	private static readonly float[] Heights;

	private static readonly C[] Zenith;

	private static readonly C[] HorizonToSun;

	private static readonly C[] HorizonAway;

	private static readonly C[] SunColor;

	private static readonly C[] MapLight;

	private static readonly C[] CloudShade;

	private static readonly C[] CloudAmbient;

	private static readonly ValueTuple<float, float, float, Look, Color>[] Elements;

	private static GameObject _root;

	private static GameObject _view;

	private static GameObject _hazeRoot;

	private static GameObject _flareRoot;

	private static GameObject _sandbox;

	private static Camera _cam;

	private static Transform _sun;

	private static Transform _moon;

	private static Transform _stars;

	private static Transform _burst;

	private static Transform _sandboxFloor;

	private static Transform _beams;

	private static Transform _beams2;

	private static Transform[] _parts;

	private static readonly Material[] _partMats;

	private static BoxCollider _sandboxCollider;

	private static Mesh _domeMesh;

	private static Mesh _litMesh;

	private static Mesh _shadeMesh;

	private static Mesh _cirrusMesh;

	private static Mesh _hazeMesh;

	private static Mesh _sunMesh;

	private static Mesh _moonMesh;

	private static Mesh _starMesh;

	private static Mesh _quad;

	private static Mesh _burstMesh;

	private static Mesh _circleMesh;

	private static Mesh _glowMesh;

	private static Mesh _floorMesh;

	private static Material _domeMat;

	private static Material _litMat;

	private static Material _shadeMat;

	private static Material _cirrusMat;

	private static Material _sunMat;

	private static Material _moonMat;

	private static Material _starMat;

	private static Material _gradeA;

	private static Material _gradeB;

	private static Material _burstMat;

	private static Material _floorMat;

	private static Material _hazeMat;

	private static Material _beamMat;

	private static Material _beamMat2;

	private static Material _scudMat;

	private static Material _curtainMat;

	private static Renderer _lit;

	private static Renderer _shade;

	private static Renderer _cirrus;

	private static Renderer _gradeARenderer;

	private static Renderer _gradeBRenderer;

	private static Renderer _starRenderer;

	private static Texture2D _cloudTex;

	private static Texture2D _cirrusTex;

	private static Texture2D _moonTex;

	private static Texture2D _tileTex;

	private static float[] _dirs;

	private static float[] _capDirs;

	private static float[] _capFade;

	private static float[] _hazeDirs;

	private static float[] _cloudNoise;

	private static Color32[] _colors;

	private static Color32[] _litColors;

	private static Color32[] _hazeColors;

	private static float _sunSeen;

	private static float _nextSunSight;

	private static float _flareShown;

	private static float _backlight;

	private static float _sandboxFor;

	private static float _cirrusSlide;

	private static float _sandboxAfter;

	private static byte[] _bytes;

	private static bool? _linear;

	private static bool _built;

	private static bool _failed;

	private static bool _noProbes;

	private static bool _fogWasOn;

	private static bool _announced;

	private static float _nextRecolor;

	private static float _nextMeasure;

	private static float _domeCheck1;

	private static float _domeCheck2;

	private static float _outdoors;

	private static float _dayGain;

	private static float _wantGain;

	private static float _bakedAmount;

	private static float _cloudSlide;

	private static C _grade;

	private static readonly List<Renderer> _hidden;

	private static Camera _skyboxCam;

	private static float _menuEase;

	private static float _nextMenuLook;

	private static float _flashShown;

	private static bool _menuOpen;

	private static bool _beamsOn;

	private static bool _scudOn;

	private static bool _curtainsOn;

	private static float _bakedStorm;

	private static float _scudSlide;

	private static float _curtainSlide;

	private static Renderer _scud;

	private static Renderer _curtains;

	internal static float Stormy;

	internal static float Green;

	internal static Vector3 WindNow;

	private static Vector3 _beamSun;

	private static float _sunWanted;

	internal static void OnLevelLoaded()
	{
		_hidden.Clear();
		_fogWasOn = false;
		_domeCheck1 = Time.unscaledTime + 2f;
		_domeCheck2 = Time.unscaledTime + 10f;
		_sandboxFor = -1f;
		_sandboxAfter = Time.unscaledTime + 2.5f;
		BodyShadow.Wait = Time.unscaledTime + 3f;
		Rain.Reset();
		Shafts.Reset();
		Tornado.Reset();
		Refresh();
		Main.Save();
	}

	internal static void Refresh()
	{
		_nextRecolor = 0f;
	}

	internal static void Tick()
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Invalid comparison between Unknown and I4
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_02bd: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_046f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		Transform head = Player.Head;
		if (!Main.On.Value || (Object)(object)head == (Object)null)
		{
			if (!Main.On.Value)
			{
				TurnOff();
			}
		}
		else
		{
			if (_failed || !Build())
			{
				return;
			}
			if (Sync.Live && Time.unscaledTime - Sync.At > 3f)
			{
				Sync.Release();
			}
			if (!_root.activeSelf)
			{
				_root.SetActive(true);
			}
			if (_hazeRoot.activeSelf)
			{
				_hazeRoot.SetActive(false);
			}
			if (!((Object)(object)_view == (Object)null) || BuildView())
			{
				if (!_view.activeSelf)
				{
					_view.SetActive(true);
				}
				if ((int)_cam.clearFlags == 1)
				{
					_cam.clearFlags = (CameraClearFlags)2;
					_skyboxCam = _cam;
				}
				if (Main.TimeRuns.Value && !Sync.Live)
				{
					Main.Hour.Value = Mathf.Repeat(Main.Hour.Value + Time.deltaTime / 60f / Mathf.Max(Main.DayMinutes.Value, 1f) * 24f, 24f);
				}
				UpdateSandbox(head.position);
				_root.transform.position = head.position;
				float num = Mathf.Max(_cam.farClipPlane * 0.997f, 10f);
				_root.transform.localScale = Vector3.one * num;
				if (Time.unscaledTime >= _nextMeasure)
				{
					_nextMeasure = Time.unscaledTime + 0.5f;
					MeasureOutdoors(head.position);
					MeasureLight(head.position);
					KeepFogOff();
				}
				_dayGain = Mathf.MoveTowards(_dayGain, _wantGain, Time.unscaledDeltaTime);
				if (_domeCheck1 > 0f && Time.unscaledTime >= _domeCheck1)
				{
					_domeCheck1 = 0f;
					HideDomes(head.position);
				}
				if (_domeCheck2 > 0f && Time.unscaledTime >= _domeCheck2)
				{
					_domeCheck2 = 0f;
					HideDomes(head.position);
				}
				Sun(out var x, out var y, out var z);
				UpdateBacklight(x, y, z);
				UpdateGrade(y);
				if (Time.unscaledTime >= _nextRecolor)
				{
					_nextRecolor = Time.unscaledTime + 0.12f;
					Recolor(x, y, z);
				}
				UpdateLights(x, y, z);
				UpdateClouds(y);
				UpdateSunSight(head.position, x, y, z);
				Vector3 position = ((Component)_cam).transform.position;
				float rain = Now.Rain;
				float dt = Math.Min(Time.unscaledDeltaTime, 0.05f);
				Weather(rain, dt);
				Rain.Tick(head.position, position, rain, WindNow);
				Storm.Tick(head.position, Now.Thunder || Tornado.Down, rain, Math.Clamp((0.02f - y) / 0.2f, 0f, 1f));
				Transform transform = ((Component)_cam).transform;
				float light = (0.22f + 0.78f * Math.Clamp((y + 0.1f) / 0.3f, 0f, 1f)) * (1f - 0.45f * Stormy);
				Tornado.Tick(head.position, position, Engine.N(transform.right), Engine.N(transform.up), Now.Tornado, Now.Rating, light);
				Radar.Tick(head.position, Engine.N(transform.forward), Main.RadarOn.Value, Stormy, Rain.Shown, WindNow);
				UpdateBeams(x, y, z);
				float num2 = ((Main.Flare.Value && y > 0.03f) ? (Mathf.Clamp(Main.FlareStrength.Value, 0.25f, 3f) * (0.45f + 0.55f * Math.Clamp(1f - y / 0.6f, 0f, 1f)) * (1f - Math.Max(Rain.Shown, Stormy))) : 0f);
				C c = At(SunColor, y);
				Shafts.Tick(head.position, position, new Vector3(x, y, z), 0.07f * num2, Engine.Rgba(c.R, c.G, c.B, 1f));
				UpdateCurtains(light, dt);
				LightningGlow();
				float darkness = (Main.Shadows.Value ? (Mathf.Clamp01(Main.ShadowDarkness.Value) * _sunSeen * _outdoors * Math.Clamp((y - 0.04f) / 0.1f, 0f, 1f) * (1f - Math.Max(Rain.Shown, Stormy))) : 0f);
				BodyShadow.Tick(x, y, z, darkness, head.position);
				if (!_announced)
				{
					_announced = true;
					Main.Log.Msg($"Sky ready: far clip {num / 0.997f:0} m, {_hidden.Count} sky meshes hidden, linear colour {IsLinear()}");
				}
			}
		}
	}

	private static void TurnOff()
	{
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_root != (Object)null && _root.activeSelf)
		{
			_root.SetActive(false);
		}
		if ((Object)(object)_hazeRoot != (Object)null && _hazeRoot.activeSelf)
		{
			_hazeRoot.SetActive(false);
		}
		if ((Object)(object)_sandbox != (Object)null && _sandbox.activeSelf)
		{
			_sandbox.SetActive(false);
		}
		if ((Object)(object)_view != (Object)null && _view.activeSelf)
		{
			_view.SetActive(false);
		}
		if ((Object)(object)_skyboxCam != (Object)null)
		{
			_skyboxCam.clearFlags = (CameraClearFlags)1;
		}
		_skyboxCam = null;
		BodyShadow.Hide();
		Rain.Hide();
		Shafts.Hide();
		Tornado.Hide();
		Radar.Hide();
		Enumerator<Renderer> enumerator = _hidden.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				Renderer current = enumerator.Current;
				if ((Object)(object)current != (Object)null)
				{
					current.enabled = true;
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		_hidden.Clear();
		if (_fogWasOn)
		{
			RenderSettings.fog = true;
		}
		_fogWasOn = false;
	}

	private static void Sun(out float x, out float y, out float z)
	{
		float num = (Now.Hour - 6f) / 24f * (float)Math.PI * 2f;
		x = MathF.Cos(num);
		y = MathF.Sin(num) * MathF.Cos(0.42f);
		z = MathF.Sin(num) * MathF.Sin(0.42f);
	}

	private static C At(C[] table, float height)
	{
		if (height <= Heights[0])
		{
			return table[0];
		}
		for (int i = 1; i < Heights.Length; i++)
		{
			if (!(height > Heights[i]))
			{
				float num = (height - Heights[i - 1]) / (Heights[i] - Heights[i - 1]);
				C c = table[i - 1];
				C c2 = table[i];
				return new C(c.R + (c2.R - c.R) * num, c.G + (c2.G - c.G) * num, c.B + (c2.B - c.B) * num);
			}
		}
		return table[table.Length - 1];
	}

	private static float Linear(float v)
	{
		if (!IsLinear())
		{
			return v;
		}
		return MathF.Pow(v, 2.2f);
	}

	private static bool IsLinear()
	{
		if (!_linear.HasValue)
		{
			try
			{
				_linear = LinearSpace();
			}
			catch
			{
				_linear = true;
			}
		}
		return _linear.Value;
	}

	[MethodImpl((MethodImplOptions)8)]
	private static bool LinearSpace()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		return (int)QualitySettings.activeColorSpace == 1;
	}

	private static void UpdateBacklight(float sx, float sy, float sz)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0021: Unknown result type (might be due to invalid IL or missing references)
		Vector3 forward = ((Component)_cam).transform.forward;
		float num = Math.Clamp((forward.x * sx + forward.y * sy + forward.z * sz - 0.4f) / 0.55f, 0f, 1f);
		float num2 = ((sy < -0.05f) ? 0f : Math.Clamp(1f - sy / 0.5f, 0f, 1f));
		_backlight = Mathf.MoveTowards(_backlight, num * num2 * _outdoors * 0.45f, Time.unscaledDeltaTime * 0.8f);
	}

	private static void UpdateGrade(float sunHeight)
	{
		C c = At(MapLight, sunHeight);
		float dark = Mathf.Clamp01(Main.NightDarkness.Value);
		float num = Math.Clamp((sunHeight + 0.05f) / 0.25f, 0f, 1f);
		float gain = (1f + (_dayGain - 1f) * num) * (1f - _backlight) * (1f - 0.35f * Math.Max(Rain.Shown, Stormy) - 0.3f * Green) * (1f + Storm.Light);
		_grade = new C(GradeOf(c.R, dark, gain), GradeOf(c.G, dark, gain), GradeOf(c.B, dark, gain));
		if (Green > 0f)
		{
			_grade = new C(_grade.R * (1f - 0.12f * Green), _grade.G * (1f - 0.02f * Green), _grade.B * (1f - 0.08f * Green));
		}
		_menuEase = Mathf.MoveTowards(_menuEase, MenuOpen() ? 1f : 0f, Time.unscaledDeltaTime * 4f);
		if (_menuEase > 0f)
		{
			_grade = new C(Readable(_grade.R), Readable(_grade.G), Readable(_grade.B));
		}
		SetGrade(_gradeA, _grade.R, _grade.G, _grade.B, 2f);
		bool flag = _grade.R > 2f || _grade.G > 2f || _grade.B > 2f;
		if (_gradeBRenderer.enabled != flag)
		{
			_gradeBRenderer.enabled = flag;
		}
		if (flag)
		{
			SetGrade(_gradeB, _grade.R / 2f, _grade.G / 2f, _grade.B / 2f, 2f);
		}
	}

	private static float Readable(float grade)
	{
		return grade + (Math.Clamp(grade, 0.7f, 1.25f) - grade) * _menuEase;
	}

	private static bool MenuOpen()
	{
		if (Time.unscaledTime < _nextMenuLook)
		{
			return _menuOpen;
		}
		_nextMenuLook = Time.unscaledTime + 0.1f;
		try
		{
			UIRig uIRig = Player.UIRig;
			PopUpMenuView val = (((Object)(object)uIRig != (Object)null) ? uIRig.popUpMenu : null);
			_menuOpen = (Object)(object)val != (Object)null && val.m_IsActivated;
		}
		catch
		{
			_menuOpen = false;
		}
		return _menuOpen;
	}

	private static float GradeOf(float look, float dark, float gain)
	{
		float num = (1f + (Linear(look) - 1f) * dark) * gain;
		float num2 = 1f + (num - 1f) * 0.3f;
		return num2 + (num - num2) * _outdoors;
	}

	private static void SetGrade(Material m, float r, float g, float b, float most)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		m.SetColor("_BaseColor", new Color(Shade(Math.Min(r, most) * 0.5f), Shade(Math.Min(g, most) * 0.5f), Shade(Math.Min(b, most) * 0.5f), 1f));
	}

	private static float Shade(float v)
	{
		if (!IsLinear())
		{
			return v;
		}
		if (!(v <= 0.0031308f))
		{
			return 1.055f * MathF.Pow(v, 5f / 12f) - 0.055f;
		}
		return v * 12.92f;
	}

	private static void MeasureOutdoors(Vector3 head)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		for (int i = 0; i < 5; i++)
		{
			if (!Physics.Raycast(new Vector3(head.x + i switch
			{
				2 => -1.5f, 
				1 => 1.5f, 
				0 => 0f, 
				_ => 0f, 
			}, head.y + 0.35f, head.z + i switch
			{
				4 => -1.5f, 
				3 => 1.5f, 
				_ => 0f, 
			}), Vector3.up, 80f, -5, (QueryTriggerInteraction)1))
			{
				num++;
			}
		}
		_outdoors = Mathf.MoveTowards(_outdoors, (float)num / 5f, 0.25f);
	}

	private static void MeasureLight(Vector3 head)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		_wantGain = 1f;
		if (!Main.AutoDaylight.Value || _noProbes)
		{
			return;
		}
		try
		{
			_wantGain = Math.Clamp(0.35f / Math.Max(Probe(head), 0.02f), 1f, 4f);
		}
		catch (global::System.Exception ex)
		{
			_noProbes = true;
			Main.Log.Warning("Can't read the light here, so dark maps stay dark by day: " + ex.Message);
		}
	}

	[MethodImpl((MethodImplOptions)8)]
	private static float Probe(Vector3 at)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		SphericalHarmonicsL2 val = default(SphericalHarmonicsL2);
		LightProbes.GetInterpolatedProbe(at, _gradeARenderer, ref val);
		return Math.Max(0f, 0.3f * ((SphericalHarmonicsL2)(ref val))[0, 0] + 0.59f * ((SphericalHarmonicsL2)(ref val))[1, 0] + 0.11f * ((SphericalHarmonicsL2)(ref val))[2, 0]);
	}

	private static void KeepFogOff()
	{
		if (RenderSettings.fog)
		{
			_fogWasOn = true;
			RenderSettings.fog = false;
		}
	}

	private static void HideDomes(Vector3 head)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		global::System.Collections.Generic.IEnumerator<MeshRenderer> enumerator = Object.FindObjectsOfType<MeshRenderer>().GetEnumerator();
		try
		{
			while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
			{
				MeshRenderer current = enumerator.Current;
				if ((Object)(object)current == (Object)null || !((Renderer)current).enabled)
				{
					continue;
				}
				Bounds bounds = ((Renderer)current).bounds;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				if (((Vector3)(ref extents)).sqrMagnitude < 3600f)
				{
					continue;
				}
				bounds = ((Renderer)current).bounds;
				if (!((Bounds)(ref bounds)).Contains(head))
				{
					continue;
				}
				string name = ((Object)current).name;
				if (!name.StartsWith("QuestDayNight", (StringComparison)4))
				{
					Material sharedMaterial = ((Renderer)current).sharedMaterial;
					if (IsSky(name) || (!((Object)(object)sharedMaterial == (Object)null) && (IsSky(((Object)sharedMaterial).name) || (!((Object)(object)sharedMaterial.shader == (Object)null) && IsSky(((Object)sharedMaterial.shader).name)))))
					{
						((Renderer)current).enabled = false;
						_hidden.Add((Renderer)(object)current);
					}
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator)?.Dispose();
		}
	}

	private static bool IsSky(string s)
	{
		if (s.IndexOf("sky", (StringComparison)5) < 0)
		{
			return s.IndexOf("dome", (StringComparison)5) >= 0;
		}
		return true;
	}

	private static void Recolor(float sx, float sy, float sz)
	{
		C c = At(Zenith, sy);
		C c2 = At(HorizonToSun, sy);
		C c3 = At(HorizonAway, sy);
		C c4 = At(SunColor, sy);
		C c5 = At(CloudAmbient, sy);
		float num = ((sy < -0.2f) ? 0f : Math.Clamp(1.15f - sy, 0.3f, 1f));
		float num2 = Math.Max(Rain.Shown, 0.8f * Stormy);
		float num3 = 1f - 0.45f * num2;
		for (int i = 0; i < _colors.Length; i++)
		{
			float num4 = _dirs[i * 3];
			float num5 = _dirs[i * 3 + 1];
			float num6 = _dirs[i * 3 + 2];
			float num7 = num4 * sx + num5 * sy + num6 * sz;
			float num8 = (num7 + 1f) * 0.5f;
			num8 *= num8;
			float num9 = c3.R + (c2.R - c3.R) * num8;
			float num10 = c3.G + (c2.G - c3.G) * num8;
			float num11 = c3.B + (c2.B - c3.B) * num8;
			float num12 = ((num5 > 0f) ? MathF.Pow(num5, 0.45f) : 0f);
			float num13 = num9 + (c.R - num9) * num12;
			float num14 = num10 + (c.G - num10) * num12;
			float num15 = num11 + (c.B - num11) * num12;
			if (num5 < 0f)
			{
				float num16 = 0.35f + 0.65f * Math.Clamp(1f + num5 * 6f, 0f, 1f);
				num13 *= num16;
				num14 *= num16;
				num15 *= num16;
			}
			if (num7 > 0f)
			{
				float num17 = 0.22f * num7 * num7 * num7 * num * (1f - num2);
				num13 += c4.R * num17;
				num14 += c4.G * num17;
				num15 += c4.B * num17;
			}
			if (num2 > 0f)
			{
				float num18 = (num13 + num14 + num15) * (1f / 3f);
				float num19 = 0.75f * num2;
				num13 = (num13 + (num18 - num13) * num19) * num3;
				num14 = (num14 + (num18 - num14) * num19) * num3;
				num15 = (num15 + (num18 - num15) * num19) * num3;
			}
			if (Stormy > 0f)
			{
				float num20 = num5 - 0.03f;
				float num21 = 1f + 1.1f * Stormy * MathF.Exp((0f - num20) * num20 / 0.0025f);
				float num22 = 1f - 0.3f * Stormy * Math.Clamp(num5 * 3f, 0f, 1f);
				num13 *= num22 * num21 * (1f - 0.35f * Green);
				num14 *= num22 * num21 * (1f + 0.05f * Green);
				num15 *= num22 * num21 * (1f - 0.12f * Green);
			}
			_colors[i].r = ToByte(Linear(num13) / Math.Max(_grade.R, 0.02f));
			_colors[i].g = ToByte(Linear(num14) / Math.Max(_grade.G, 0.02f));
			_colors[i].b = ToByte(Linear(num15) / Math.Max(_grade.B, 0.02f));
			_colors[i].a = 255;
		}
		_domeMesh.colors32 = Il2CppStructArray<Color32>.op_Implicit(_colors);
		if (Now.Clouds || Now.Rain > 0f)
		{
			for (int j = 0; j < _litColors.Length; j++)
			{
				float num23 = _capDirs[j * 3] * sx + _capDirs[j * 3 + 1] * sy + _capDirs[j * 3 + 2] * sz;
				float num24 = ((num23 > 0f) ? ((0.15f * num23 + 0.55f * num23 * num23 * num23 * num23 + 0.9f * MathF.Pow(num23, 16f)) * num * (1f - 0.85f * num2)) : 0f);
				float num25 = _capFade[j];
				_litColors[j].r = ToByte(Linear(c5.R * num3 + c4.R * num24) * num25 / Math.Max(_grade.R, 0.02f));
				_litColors[j].g = ToByte(Linear(c5.G * num3 + c4.G * num24) * num25 / Math.Max(_grade.G, 0.02f));
				_litColors[j].b = ToByte(Linear(c5.B * num3 + c4.B * num24) * num25 / Math.Max(_grade.B, 0.02f));
				_litColors[j].a = 255;
			}
			_litMesh.colors32 = Il2CppStructArray<Color32>.op_Implicit(_litColors);
		}
		float num26 = MathF.Sqrt(sx * sx + sz * sz);
		float num27 = ((num26 > 0.001f) ? (sx / num26) : 1f);
		float num28 = ((num26 > 0.001f) ? (sz / num26) : 0f);
		for (int k = 0; k < _hazeColors.Length; k++)
		{
			float num29 = (_hazeDirs[k * 3] * num27 + _hazeDirs[k * 3 + 1] * num28 + 1f) * 0.5f;
			num29 *= num29;
			float num30 = _hazeDirs[k * 3 + 2] * _outdoors;
			_hazeColors[k].r = ToByte(Linear(c3.R + (c2.R - c3.R) * num29) * num30 / Math.Max(_grade.R, 0.02f));
			_hazeColors[k].g = ToByte(Linear(c3.G + (c2.G - c3.G) * num29) * num30 / Math.Max(_grade.G, 0.02f));
			_hazeColors[k].b = ToByte(Linear(c3.B + (c2.B - c3.B) * num29) * num30 / Math.Max(_grade.B, 0.02f));
			_hazeColors[k].a = 255;
		}
		_hazeMesh.colors32 = Il2CppStructArray<Color32>.op_Implicit(_hazeColors);
	}

	private static byte ToByte(float v)
	{
		return (byte)(Math.Clamp(v, 0f, 1f) * 255f + 0.5f);
	}

	private static void UpdateLights(float sx, float sy, float sz)
	{
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_014e: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: 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_027f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(sx, sy, sz);
		((Component)_sun).gameObject.SetActive(sy > -0.14f);
		if (sy > -0.14f)
		{
			C c = At(SunColor, sy);
			_sun.localPosition = val * 0.99f;
			_sun.localRotation = Quaternion.LookRotation(val);
			float num = 1f - 0.92f * Rain.Shown;
			_sunMat.SetColor("_BaseColor", new Color(Over(c.R * num, _grade.R), Over(c.G * num, _grade.G), Over(c.B * num, _grade.B), 1f));
		}
		Vector3 val2 = new Vector3(0f - sx, 0f - sy + 0.12f, 0f - sz + 0.18f);
		Vector3 normalized = ((Vector3)(ref val2)).normalized;
		float num2 = Math.Clamp((0f - sy + 0.02f) / 0.2f, 0f, 1f);
		bool flag = num2 > 0.01f && normalized.y > -0.1f;
		((Component)_moon).gameObject.SetActive(flag);
		if (flag)
		{
			_moon.localPosition = normalized * 0.988f;
			_moon.localRotation = Quaternion.LookRotation(normalized);
			float num3 = 0.85f * num2 * (1f - 0.9f * Rain.Shown);
			_moonMat.SetColor("_BaseColor", new Color(Over(num3, _grade.R), Over(num3, _grade.G), Over(num3 * 0.95f, _grade.B), 1f));
		}
		bool flag2 = num2 > 0.01f;
		if (_starRenderer.enabled != flag2)
		{
			_starRenderer.enabled = flag2;
		}
		if (flag2)
		{
			_stars.localRotation = Quaternion.AngleAxis(Now.Hour * 15f, new Vector3(0.38f, 0.92f, 0f));
			float v = num2 * (1f - Rain.Shown);
			_starMat.SetColor("_BaseColor", new Color(Over(v, _grade.R), Over(v, _grade.G), Over(v, _grade.B), 1f));
		}
	}

	private static float Over(float v, float grade)
	{
		return Math.Clamp(v / Math.Max(MathF.Sqrt(grade), 0.05f), 0f, 1f);
	}

	private static void UpdateClouds(float sy)
	{
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: 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_02f1: 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_0360: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Now.Clouds || Now.Rain > 0f || Stormy > 0.01f;
		if (_lit.enabled != flag)
		{
			_lit.enabled = flag;
			_shade.enabled = flag;
			_cirrus.enabled = flag;
		}
		if (flag)
		{
			float num = Mathf.Clamp(Now.CloudAmount, 0.1f, 1f);
			if (Now.Rain > 0f)
			{
				num = Math.Max(num, 0.85f);
			}
			if (Math.Abs(num - _bakedAmount) > 0.001f || Math.Abs(Stormy - _bakedStorm) > 0.15f)
			{
				BakeClouds(num, Stormy);
			}
			_cloudSlide = (_cloudSlide + Time.deltaTime * 0.003f * (1f + 5f * Stormy)) % 1f;
			_cirrusSlide = (_cirrusSlide + Time.deltaTime * 0.0015f) % 1f;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(_cloudSlide, _cloudSlide * 0.6f);
			_litMat.SetTextureOffset("_BaseMap", val);
			_shadeMat.SetTextureOffset("_BaseMap", val);
			_cirrusMat.SetTextureOffset("_BaseMap", new Vector2(_cirrusSlide, 0f));
			C c = At(CloudShade, sy);
			C c2 = At(SunColor, sy);
			C c3 = At(CloudAmbient, sy);
			float num2 = (1f + 0.7f * Rain.Shown + 1.1f * Stormy) * (1f - 0.7f * Storm.Flash);
			float num3 = 0.5f * (1f - 0.7f * Math.Max(Rain.Shown, Stormy));
			_shadeMat.SetColor("_BaseColor", new Color(Math.Min(c.R * num2, 1f), Math.Min(c.G * num2, 1f), Math.Min(c.B * num2, 1f), 1f));
			_cirrusMat.SetColor("_BaseColor", new Color(Over((c3.R + c2.R) * num3, _grade.R), Over((c3.G + c2.G) * num3, _grade.G), Over((c3.B + c2.B) * num3, _grade.B), 1f));
			bool flag2 = Stormy > 0.02f;
			if (_scudOn != flag2)
			{
				_scudOn = flag2;
				_scud.enabled = flag2;
			}
			if (flag2)
			{
				_scudSlide = (_scudSlide + Time.deltaTime * 0.003f * 14f) % 1f;
				Vector2 val2 = new Vector2
				{
					x = _scudSlide,
					y = _scudSlide * 0.3f
				};
				_scudMat.SetTextureOffset("_BaseMap", val2);
				float num4 = 0.55f * Stormy * (1f - 0.7f * Storm.Flash);
				_scudMat.SetColor("_BaseColor", Engine.Rgba(num4, num4, num4 * 0.95f, 1f));
			}
		}
	}

	private static void Weather(float rain, float dt)
	{
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		float to = Math.Max(Math.Max((rain > 0f) ? (0.55f + 0.45f * rain) : 0f, Now.Thunder ? 0.8f : 0f), Now.Tornado ? 1f : 0f);
		Stormy = Engine.Toward(Stormy, to, dt / 6f);
		Green = Engine.Toward(Green, Now.Tornado ? 1f : 0f, dt / 6f);
		float time = Time.time;
		float num = 0.65f + 0.35f * MathF.Sin(time * 0.9f) * MathF.Sin(time * 0.37f + 1f);
		float num2 = (0.6f + 3.5f * Stormy + 3f * Green) * num;
		float num3 = 2f + time * 0.01f;
		WindNow = new Vector3(MathF.Cos(num3) * num2, 0f, MathF.Sin(num3) * num2);
	}

	private static void UpdateCurtains(float light, float dt)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		float num = Math.Max(Rain.Shown, 0.6f * Stormy);
		bool flag = num > 0.01f;
		if (_curtainsOn != flag)
		{
			_curtainsOn = flag;
			_curtains.enabled = flag;
		}
		if (flag)
		{
			_curtainSlide = (_curtainSlide + dt * 0.35f) % 1f;
			Vector2 val = new Vector2
			{
				x = Time.time * 0.004f % 1f,
				y = _curtainSlide
			};
			_curtainMat.SetTextureOffset("_BaseMap", val);
			float num2 = 0.42f * Math.Max(light, 0.3f);
			_curtainMat.SetColor("_BaseColor", Engine.Rgba(num2 * 0.95f, num2, num2 * 1.05f, 0.75f * num));
		}
	}

	private static void UpdateSunSight(Vector3 head, float sx, float sy, float sz)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		if (sy <= -0.05f)
		{
			_sunSeen = 0f;
			return;
		}
		if (Time.unscaledTime >= _nextSunSight)
		{
			_nextSunSight = Time.unscaledTime + 0.1f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(sx, sy, sz);
			RigManager rigManager = Player.RigManager;
			bool flag = true;
			global::System.Collections.Generic.IEnumerator<RaycastHit> enumerator = ((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(head + val * 0.3f, val, 1000f, -5, (QueryTriggerInteraction)1)).GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					RaycastHit current = enumerator.Current;
					if (!((Object)(object)((RaycastHit)(ref current)).collider == (Object)null) && (!((Object)(object)rigManager != (Object)null) || !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)rigManager).transform)))
					{
						flag = false;
						break;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			_sunWanted = (flag ? 1f : 0f);
		}
		_sunSeen = Mathf.MoveTowards(_sunSeen, _sunWanted, Time.unscaledDeltaTime * 5f);
	}

	private static void UpdateBeams(float sx, float sy, float sz)
	{
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: 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_014f: 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_016a: 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_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		float t = (Now.Clouds ? Mathf.Clamp01(Now.CloudAmount) : 0f);
		float num = Engine.Smooth(0.1f, 0.45f, t) * (1f - Engine.Smooth(0.75f, 1f, t));
		float num2 = ((Main.Flare.Value && sy > -0.04f) ? (Mathf.Clamp(Main.FlareStrength.Value, 0.25f, 3f) * Math.Clamp((sy + 0.04f) / 0.1f, 0f, 1f) * (0.2f + 0.8f * Math.Clamp(1f - sy / 0.5f, 0f, 1f)) * (0.3f + 0.7f * _sunSeen) * (0.25f + 0.75f * num) * (1f - Math.Max(Rain.Shown, Stormy))) : 0f);
		bool flag = num2 > 0.01f;
		if (_beamsOn != flag)
		{
			_beamsOn = flag;
			((Component)_beams).gameObject.SetActive(flag);
			((Component)_beams2).gameObject.SetActive(flag);
		}
		if (flag)
		{
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(sx, sy, sz);
			if (Vector3.Dot(val, _beamSun) < 0.999999f)
			{
				_beamSun = val;
				Quaternion localRotation = Engine.Look(val, (MathF.Abs(sy) < 0.98f) ? Vector3.UnitY : Vector3.UnitZ);
				_beams.localRotation = localRotation;
				_beams2.localRotation = localRotation;
			}
			float num3 = 0.5f + 0.5f * MathF.Sin(Time.time * 0.05f);
			float num4 = 0.2f + 0.8f * num3;
			float num5 = 1f - 0.8f * num3;
			float num6 = 0.12f * num2;
			C c = At(SunColor, sy);
			_beamMat.SetColor("_BaseColor", Engine.Rgba(Over(c.R * num6 * num4, _grade.R), Over(c.G * num6 * num4, _grade.G), Over(c.B * num6 * num4, _grade.B), 1f));
			_beamMat2.SetColor("_BaseColor", Engine.Rgba(Over(c.R * num6 * num5, _grade.R), Over(c.G * num6 * num5, _grade.G), Over(c.B * num6 * num5, _grade.B), 1f));
		}
	}

	private static Mesh BeamMesh(int seed)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_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_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_01a7: 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)
		float[] array = new float[5];
		RuntimeHelpers.InitializeArray((global::System.Array)array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		float[] array2 = array;
		float[] array3 = new float[5];
		RuntimeHelpers.InitializeArray((global::System.Array)array3, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		float[] array4 = array3;
		List<Vector3> val = new List<Vector3>();
		List<Color32> val2 = new List<Color32>();
		List<int> val3 = new List<int>();
		Random rng = new Random(seed);
		Vector3 val4 = default(Vector3);
		Vector3 val5 = default(Vector3);
		for (int i = 0; i < 18; i++)
		{
			float num = (R() * 2f - 1f) * 1.3f;
			float num2 = 0.6f + 1f * R();
			float num3 = 0.004f + 0.008f * R();
			float num4 = 0.06f + 0.11f * R();
			float num5 = 0.35f + 0.5f * R();
			((Vector3)(ref val4))..ctor(MathF.Sin(num), 0f - MathF.Cos(num), 0f);
			((Vector3)(ref val5))..ctor(0f - val4.Y, val4.X, 0f);
			int count = val.Count;
			for (int j = 0; j <= 10; j++)
			{
				float num6 = (float)j / 10f;
				float num7 = 0.02f + num2 * num6;
				float num8 = (num3 + (num4 - num3) * num6) * (1f + num7 * num7);
				float num9 = Engine.Smooth(0f, 0.15f, num6) * MathF.Pow(1f - num6, 1.5f) * num5;
				Vector3 val6 = Vector3.UnitZ + val4 * num7;
				for (int k = 0; k < 5; k++)
				{
					val.Add(Engine.U(Vector3.Normalize(val6 + val5 * (num8 * array2[k])) * 0.985f));
					val2.Add(new Color32
					{
						rgba = Engine.Grey((int)(Math.Clamp(num9 * array4[k], 0f, 1f) * 255f))
					});
				}
			}
			for (int l = 0; l < 10; l++)
			{
				for (int m = 0; m < 4; m++)
				{
					int num10 = count + l * 5 + m;
					int num11 = num10 + 5;
					val3.Add(num10);
					val3.Add(num11);
					val3.Add(num10 + 1);
					val3.Add(num10 + 1);
					val3.Add(num11);
					val3.Add(num11 + 1);
				}
			}
		}
		return NewMesh("Beams", val.ToArray(), val2.ToArray(), (Vector2[])(object)new Vector2[val.Count], val3.ToArray(), 4f);
		[CompilerGenerated]
		float R()
		{
			return (float)rng.NextDouble();
		}
	}

	private static void LightningGlow()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		float flash = Storm.Flash;
		if (!(flash <= 0.003f) || !(_flashShown <= 0f))
		{
			_flashShown = ((flash > 0.003f) ? flash : 0f);
			_litMat.SetColor("_BaseColor", Engine.Rgba(1f + 2.6f * flash, 1f + 1.9f * flash, 1f + 3.4f * flash, 1f));
			_domeMat.SetColor("_BaseColor", Engine.Rgba(1f + 1f * flash, 1f + 0.7f * flash, 1f + 1.5f * flash, 1f));
		}
	}

	private static void UpdateFlare(float sx, float sy, float sz)
	{
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: 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_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: 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_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: 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_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		if (Main.Flare.Value && sy > -0.05f)
		{
			Vector3 forward = ((Component)_cam).transform.forward;
			float num2 = Math.Clamp((forward.x * sx + forward.y * sy + forward.z * sz - 0.55f) / 0.42f, 0f, 1f);
			num = _sunSeen * num2 * num2 * (3f - 2f * num2) * Math.Clamp((sy + 0.05f) / 0.1f, 0f, 1f);
		}
		_flareShown = Mathf.MoveTowards(_flareShown, num, Time.unscaledDeltaTime * 4f);
		float num3 = _flareShown * Mathf.Clamp(Main.FlareStrength.Value, 0.25f, 3f);
		Vector3 val = ((Component)_cam).transform.InverseTransformDirection(new Vector3(sx, sy, sz));
		bool flag = num3 > 0.01f && val.z > 0.05f;
		if (_flareRoot.activeSelf != flag)
		{
			_flareRoot.SetActive(flag);
		}
		if (!flag)
		{
			return;
		}
		float num4 = Mathf.Clamp(_cam.farClipPlane * 0.45f, 3f, 400f);
		_flareRoot.transform.localPosition = new Vector3(0f, 0f, num4);
		_flareRoot.transform.localScale = Vector3.one * (num4 / 1.2f);
		float num5 = val.x / val.z * 1.2f;
		float num6 = val.y / val.z * 1.2f;
		_burst.localPosition = new Vector3(num5, num6, 0f);
		_burstMat.SetColor("_BaseColor", new Color(num3, num3, num3, 1f));
		for (int i = 0; i < Elements.Length; i++)
		{
			ValueTuple<float, float, float, Look, Color> val2 = Elements[i];
			_parts[i].localPosition = new Vector3(num5 * val2.Item1 - num6 * val2.Item2, num6 * val2.Item1 + num5 * val2.Item2, 0f);
			if (val2.Item4 == Look.Streak)
			{
				_parts[i].localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(num6, num5) * 57.29578f);
			}
			_partMats[i].SetColor("_BaseColor", new Color(val2.Item5.r * num3, val2.Item5.g * num3, val2.Item5.b * num3, 1f));
		}
	}

	private static void BuildFlare()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Expected O, but got Unknown
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: 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_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		if (_burstMesh == null)
		{
			_burstMesh = BurstMesh();
		}
		if (_circleMesh == null)
		{
			_circleMesh = Radial("Circle", null, new ValueTuple<float, Color>(0f, Grey(0.55f)), new ValueTuple<float, Color>(0.7f, Grey(0.6f)), new ValueTuple<float, Color>(0.9f, Grey(0.85f)), new ValueTuple<float, Color>(0.97f, Grey(0.5f)), new ValueTuple<float, Color>(1f, Color.black));
		}
		if (_glowMesh == null)
		{
			_glowMesh = Radial("Glow", null, new ValueTuple<float, Color>(0f, Color.white), new ValueTuple<float, Color>(0.2f, Grey(0.55f)), new ValueTuple<float, Color>(0.45f, Grey(0.2f)), new ValueTuple<float, Color>(0.7f, Grey(0.05f)), new ValueTuple<float, Color>(1f, Color.black));
		}
		_flareRoot = new GameObject("QuestDayNight_Flare");
		_flareRoot.transform.SetParent(_view.transform, false);
		_flareRoot.transform.localPosition = new Vector3(0f, 0f, 1.2f);
		_parts = (Transform[])(object)new Transform[Elements.Length];
		for (int i = 0; i < Elements.Length; i++)
		{
			ValueTuple<float, float, float, Look, Color> val = Elements[i];
			Material[] partMats = _partMats;
			int num = i;
			if (partMats[num] == null)
			{
				partMats[num] = Blended((BlendMode)1, (BlendMode)1, 4102, (Texture)(object)Texture2D.whiteTexture);
			}
			_parts[i] = ((Component)Part(_flareRoot.transform, (val.Item4 == Look.Circle) ? _circleMesh : _glowMesh, _partMats[i])).transform;
			float num2 = val.Item3 * 1.2f;
			_parts[i].localScale = ((val.Item4 == Look.Streak) ? new Vector3(num2, 0.036000002f, 1f) : new Vector3(num2, num2, 1f));
		}
		if (_burstMat == null)
		{
			_burstMat = Blended((BlendMode)1, (BlendMode)1, 4102, (Texture)(object)Texture2D.whiteTexture);
		}
		_burst = ((Component)Part(_flareRoot.transform, _burstMesh, _burstMat)).transform;
		_burst.localScale = new Vector3(0.504f, 0.504f, 1f);
		_flareRoot.SetActive(false);
	}

	private static Color Grey(float v)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return new Color(v, v, v, 1f);
	}

	private static Mesh BurstMesh()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_00b4: 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_00ce: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0181: 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_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: 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_0219: 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_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_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: 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_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: 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_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: 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_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: 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_0361: Unknown result type (might be due to invalid IL or missing references)
		List<ValueTuple<Vector3, Color>> val = new List<ValueTuple<Vector3, Color>>();
		Random rng = new Random(4127);
		Color val2 = default(Color);
		Color val3 = default(Color);
		Vector3 val4 = default(Vector3);
		Vector3 val5 = default(Vector3);
		Vector3 val6 = default(Vector3);
		Vector3 val7 = default(Vector3);
		Vector3 val8 = default(Vector3);
		for (int i = 0; i < 46; i++)
		{
			float num = R() * 6.2832f;
			float num2 = 0.22f + 0.78f * R() * R();
			float num3 = 0.006f + 0.012f * R();
			float num4 = (0.5f + 0.5f * R()) * (1f - num2 * 0.4f);
			float num5 = MathF.Cos(num);
			float num6 = MathF.Sin(num);
			((Color)(ref val2))..ctor(1f * num4, 0.62f * num4, 0.22f * num4, 1f);
			((Color)(ref val3))..ctor(val2.r * 0.5f, val2.g * 0.5f, val2.b * 0.5f, 1f);
			float num7 = num5 * num2 * 0.3f;
			float num8 = num6 * num2 * 0.3f;
			((Vector3)(ref val4))..ctor(0f, 0f, 0f);
			((Vector3)(ref val5))..ctor(num7, num8, 0f);
			((Vector3)(ref val6))..ctor(num5 * num2, num6 * num2, 0f);
			((Vector3)(ref val7))..ctor(num7 - num6 * num3, num8 + num5 * num3, 0f);
			((Vector3)(ref val8))..ctor(num7 + num6 * num3, num8 - num5 * num3, 0f);
			val.Add(new ValueTuple<Vector3, Color>(val4, val2));
			val.Add(new ValueTuple<Vector3, Color>(val7, Color.black));
			val.Add(new ValueTuple<Vector3, Color>(val5, val3));
			val.Add(new ValueTuple<Vector3, Color>(val4, val2));
			val.Add(new ValueTuple<Vector3, Color>(val5, val3));
			val.Add(new ValueTuple<Vector3, Color>(val8, Color.black));
			val.Add(new ValueTuple<Vector3, Color>(val5, val3));
			val.Add(new ValueTuple<Vector3, Color>(val7, Color.black));
			val.Add(new ValueTuple<Vector3, Color>(val6, Color.black));
			val.Add(new ValueTuple<Vector3, Color>(val5, val3));
			val.Add(new ValueTuple<Vector3, Color>(val6, Color.black));
			val.Add(new ValueTuple<Vector3, Color>(val8, Color.black));
		}
		return Radial("Burst", val, new ValueTuple<float, Color>(0f, new Color(1f, 0.98f, 0.85f)), new ValueTuple<float, Color>(0.06f, new Color(1f, 0.95f, 0.7f)), new ValueTuple<float, Color>(0.1f, new Color(1f, 0.72f, 0.3f)), new ValueTuple<float, Color>(0.16f, new Color(0.85f, 0.42f, 0.1f)), new ValueTuple<float, Color>(0.3f, new Color(0.45f, 0.19f, 0.04f)), new ValueTuple<float, Color>(0.55f, new Color(0.18f, 0.07f, 0.015f)), new ValueTuple<float, Color>(0.8f, new Color(0.05f, 0.018f, 0.004f)), new ValueTuple<float, Color>(1f, Color.black));
		[CompilerGenerated]
		float R()
		{
			return (float)rng.NextDouble();
		}
	}

	private static Mesh Radial(string name, List<ValueTuple<Vector3, Color>> extra, params ValueTuple<float, Color>[] rings)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Expected O, but got Unknown
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> val = new List<Vector3>();
		List<Color> val2 = new List<Color>();
		List<int> val3 = new List<int>();
		for (int i = 0; i < rings.Length; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num = (float)j * (float)Math.PI * 2f / 32f;
				float item = rings[i].Item1;
				val.Add(new Vector3(MathF.Cos(num) * item, MathF.Sin(num) * item, 0f));
				val2.Add(rings[i].Item2);
			}
		}
		for (int k = 0; k + 1 < rings.Length; k++)
		{
			for (int l = 0; l < 32; l++)
			{
				int num2 = (l + 1) % 32;
				int num3 = k * 32 + l;
				int num4 = k * 32 + num2;
				int num5 = num3 + 32;
				int num6 = num4 + 32;
				val3.Add(num3);
				val3.Add(num6);
				val3.Add(num4);
				val3.Add(num3);
				val3.Add(num5);
				val3.Add(num6);
			}
		}
		if (extra != null)
		{
			Enumerator<ValueTuple<Vector3, Color>> enumerator = extra.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ValueTuple<Vector3, Color> current = enumerator.Current;
					Vector3 item2 = current.Item1;
					Color item3 = current.Item2;
					val3.Add(val.Count);
					val.Add(item2);
					val2.Add(item3);
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
		}
		Mesh val4 = new Mesh
		{
			name = "QuestDayNight_" + name,
			hideFlags = (HideFlags)32,
			vertices = Il2CppStructArray<Vector3>.op_Implicit(val.ToArray()),
			colors = Il2CppStructArray<Color>.op_Implicit(val2.ToArray()),
			uv = Il2CppStructArray<Vector2>.op_Implicit((Vector2[])(object)new Vector2[val.Count]),
			triangles = Il2CppStructArray<int>.op_Implicit(val3.ToArray())
		};
		val4.RecalculateBounds();
		val4.RecalculateNormals();
		return val4;
	}

	private static void UpdateSandbox(Vector3 head)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		float num = Math.Min(Main.SandboxRadius.Value, 1000000f);
		if (num <= 0f)
		{
			if ((Object)(object)_sandbox != (Object)null && _sandbox.activeSelf)
			{
				_sandbox.SetActive(false);
			}
		}
		else if (!((Object)(object)_sandbox == (Object)null) || (!(Time.unscaledTime < _sandboxAfter) && BuildSandbox(head)))
		{
			if (!_sandbox.activeSelf)
			{
				_sandbox.SetActive(true);
			}
			float num2 = Math.Min(num * 1.25f, 20000f);
			if (_cam.farClipPlane < num2)
			{
				_cam.farClipPlane = num2;
			}
			if (num != _sandboxFor)
			{
				_sandboxFor = num;
				_sandboxFloor.localScale = new Vector3(num * 2f, 1f, num * 2f);
				_sandboxCollider.size = new Vector3(num * 2f, 20f, num * 2f);
				_floorMat.SetTextureScale("_BaseMap", new Vector2(num * 2f / 3f, num * 2f / 3f));
			}
		}
	}

	private static bool BuildSandbox(Vector3 head)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		RigManager rigManager = Player.RigManager;
		float num = 3.4028235E+38f;
		float ground = 0f;
		int layer = 0;
		global::System.Collections.Generic.IEnumerator<RaycastHit> enumerator = ((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(head, Vector3.down, 100f, -5, (QueryTriggerInteraction)1)).GetEnumerator();
		try
		{
			while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
			{
				RaycastHit current = enumerator.Current;
				if (!(((RaycastHit)(ref current)).distance >= num) && !((Object)(object)((RaycastHit)(ref current)).collider == (Object)null) && (!((Object)(object)rigManager != (Object)null) || !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)rigManager).transform)))
				{
					num = ((RaycastHit)(ref current)).distance;
					ground = ((RaycastHit)(ref current)).point.y;
					layer = ((Component)((RaycastHit)(ref current)).collider).gameObject.layer;
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator)?.Dispose();
		}
		if (num == 3.4028235E+38f)
		{
			return false;
		}
		ground = LowestMapPoint(head, ground) - 0.3f;
		_sandbox = new GameObject("QuestDayNight_Sandbox");
		_sandbox.layer = layer;
		_sandbox.transform.position = new Vector3(head.x, ground, head.z);
		_sandboxCollider = _sandbox.AddComponent<BoxCollider>();
		_sandboxCollider.center = new Vector3(0f, -10f, 0f);
		if (_floorMesh == null)
		{
			_floorMesh = FloorMesh();
		}
		if ((Object)(object)_tileTex == (Object)null)
		{
			_tileTex = TileTexture();
		}
		if ((Object)(object)_floorMat == (Object)null)
		{
			_floorMat = Blended((BlendMode)1, (BlendMode)0, 2000, (Texture)(object)_tileTex);
			_floorMat.SetFloat("_ZWrite", 1f);
			_floorMat.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
			if (_floorMat.HasProperty("_Surface"))
			{
				_floorMat.SetFloat("_Surface", 0f);
			}
		}
		_sandboxFloor = ((Component)Part(_sandbox.transform, _floorMesh, _floorMat)).transform;
		return true;
	}

	private static float LowestMapPoint(Vector3 head, float ground)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		float num = ground;
		global::System.Collections.Generic.IEnumerator<MeshRenderer> enumerator = Object.FindObjectsOfType<MeshRenderer>().GetEnumerator();
		try
		{
			while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
			{
				MeshRenderer current = enumerator.Current;
				if ((Object)(object)current == (Object)null || !((Renderer)current).enabled || ((Object)current).name.StartsWith("QuestDayNight", (StringComparison)4))
				{
					continue;
				}
				Bounds bounds = ((Renderer)current).bounds;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				if (((Vector3)(ref extents)).sqrMagnitude > 4000000f)
				{
					continue;
				}
				float num2 = ((Bounds)(ref bounds)).center.x - head.x;
				float num3 = ((Bounds)(ref bounds)).center.z - head.z;
				if (!(num2 * num2 + num3 * num3 > 160000f))
				{
					float y = ((Bounds)(ref bounds)).min.y;
					if (y < num && y > ground - 150f)
					{
						num = y;
					}
				}
			}
			return num;
		}
		finally
		{
			((global::System.IDisposable)enumerator)?.Dispose();
		}
	}

	private static Mesh FloorMesh()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		Color32 val = default(Color32);
		((Color32)(ref val))..ctor((byte)255, (byte)255, (byte)255, (byte)255);
		Vector3[] v = new Vector3[4]
		{
			new Vector3(-0.5f, 0f, -0.5f),
			new Vector3(0.5f, 0f, -0.5f),
			new Vector3(0.5f, 0f, 0.5f),
			new Vector3(-0.5f, 0f, 0.5f)
		};
		Color32[] c = new Color32[4] { val, val, val, val };
		Vector2[] uv = new Vector2[4]
		{
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f)
		};
		int[] array = new int[6];
		RuntimeHelpers.InitializeArray((global::System.Array)array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		return NewMesh("Floor", (Vector3[])(object)v, (Color32[])(object)c, (Vector2[])(object)uv, array, 4f);
	}

	private static Texture2D TileTexture()
	{
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0094: 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)
		Color32[] array = (Color32[])(object)new Color32[16384];
		for (int i = 0; i < 128; i++)
		{
			for (int j = 0; j < 128; j++)
			{
				int num = Math.Min(Math.Min(j, 127 - j), Math.Min(i, 127 - i));
				float num2 = Math.Clamp(1.8f - (float)num, 0f, 1f);
				array[i * 128 + j] = new Color32(Byte(0.16f + 0.3f * num2), Byte(0.18f + 0.28f * num2), Byte(0.21f + 0.26f * num2), (byte)255);
			}
		}
		Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
		{
			wrapMode = (TextureWrapMode)0,
			anisoLevel = 8,
			hideFlags = (HideFlags)32
		};
		val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
		val.Apply(true, true);
		return val;
	}

	internal static Material Blended(BlendMode src, BlendMode dst, int queue, Texture tex)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("Universal Render Pipeline/Particles/Unlit (Particles)") ?? Shader.Find("Universal Render Pipeline/Particles/Unlit") ?? Shader.Find("Universal Render Pipeline/Unlit");
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val)
		{
			name = "QuestDayNight",
			hideFlags = (HideFlags)32,
			renderQueue = queue
		};
		val2.SetFloat("_SrcBlend", (float)src);
		val2.SetFloat("_DstBlend", (float)dst);
		val2.SetFloat("_ZWrite", 0f);
		val2.SetFloat("_Cull", 0f);
		if (val2.HasProperty("_Surface"))
		{
			val2.SetFloat("_Surface", 1f);
		}
		val2.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
		if ((Object)(object)tex != (Object)null)
		{
			val2.SetTexture("_BaseMap", tex);
		}
		val2.SetColor("_BaseColor", Color.white);
		return val2;
	}

	private static bool Build()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//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_0175: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: 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)
		//IL_02fd: 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_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Expected O, but got Unknown
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_050b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0515: Unknown result type (might be due to invalid IL or missing references)
		//IL_057b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Expected O, but got Unknown
		if (_built && (Object)(object)_root != (Object)null)
		{
			return true;
		}
		_domeMat = Blended((BlendMode)1, (BlendMode)0, 2501, (Texture)(object)Texture2D.whiteTexture);
		if ((Object)(object)_domeMat == (Object)null)
		{
			_failed = true;
			Main.Log.Warning("The shader this needs isn't in this game build: day and night is off.");
			return false;
		}
		_root = new GameObject("QuestDayNight_Sky");
		Object.DontDestroyOnLoad((Object)(object)_root);
		_domeMesh = Dome();
		Part(_root.transform, _domeMesh, _domeMat);
		_starMat = Blended((BlendMode)1, (BlendMode)1, 2502, (Texture)(object)Texture2D.whiteTexture);
		_starMesh = Stars();
		_starRenderer = Part(_root.transform, _starMesh, _starMat);
		_stars = ((Component)_starRenderer).transform;
		_moonTex = MoonTexture();
		_moonMat = Blended((BlendMode)1, (BlendMode)1, 2503, (Texture)(object)_moonTex);
		_moonMesh = Round(true, new ValueTuple<float, float>(0f, 1f), new ValueTuple<float, float>(0.92f, 1f), new V