Decompiled source of AstralSkies v0.4.4

BepInEx\plugins\Zephyrfit-AstralSkies\AstralSkies.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("AstralSkies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.4.0")]
[assembly: AssemblyInformationalVersion("0.4.4")]
[assembly: AssemblyProduct("AstralSkies")]
[assembly: AssemblyTitle("AstralSkies")]
[assembly: AssemblyVersion("0.4.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AstralSkies
{
	public static class Astronomy
	{
		public struct Vector
		{
			public double x;

			public double y;

			public double z;

			public double Length => Math.Sqrt(x * x + y * y + z * z);

			public Vector(double x, double y, double z)
			{
				this.x = x;
				this.y = y;
				this.z = z;
			}

			public static Vector operator -(Vector a, Vector b)
			{
				return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
			}
		}

		public const double Rad = Math.PI / 180.0;

		private static readonly double[,] elements = new double[6, 12]
		{
			{
				0.38709843, 0.20563661, 7.00559432, 252.25166724, 77.45771895, 48.33961819, 0.0, 2.123E-05, -0.00590158, 149472.67486623,
				0.15940013, -0.12214182
			},
			{
				0.72332102, 0.00676399, 3.39777545, 181.9797085, 131.76755713, 76.67261496, -2.6E-07, -5.107E-05, 0.00043494, 58517.8156026,
				0.05679648, -0.27274174
			},
			{
				1.00000018, 0.01673163, -0.00054346, 100.46691572, 102.93005885, -5.11260389, -3E-08, -3.661E-05, -0.01337178, 35999.37306329,
				0.3179526, -0.24123856
			},
			{
				1.52371243, 0.09336511, 1.85181869, -4.56813164, -23.91744784, 49.71320984, 9.7E-07, 9.149E-05, -0.00724757, 19140.29934243,
				0.45223625, -0.26852431
			},
			{
				5.20248019, 0.0485359, 1.29861416, 34.33479152, 14.27495244, 100.29282654, -2.864E-05, -0.00018026, -0.00322699, 3034.90371757,
				0.18199196, 0.13024619
			},
			{
				9.54149883, 0.05550825, 2.49424102, 50.07571329, 92.86136063, 113.63998702, -3.065E-05, -0.00032044, 0.00451969, 1222.11494724,
				0.54179478, -0.25015002
			}
		};

		public static double EccentricAnomaly(double mean, double e)
		{
			mean = Math.IEEERemainder(mean, Math.PI * 2.0);
			double num = mean;
			for (int i = 0; i < 16; i++)
			{
				double num2 = (num - e * Math.Sin(num) - mean) / (1.0 - e * Math.Cos(num));
				num -= num2;
				if (Math.Abs(num2) < 1E-12)
				{
					break;
				}
			}
			return num;
		}

		public static Vector Heliocentric(int body, double days)
		{
			if (body < 0 || body > 5 || double.IsNaN(days) || days < -1826250.0 || days > 365250.0)
			{
				throw new ArgumentOutOfRangeException();
			}
			double num = days / 36525.0;
			double num2 = elements[body, 0] + num * elements[body, 6];
			double num3 = elements[body, 1] + num * elements[body, 7];
			double num4 = (elements[body, 2] + num * elements[body, 8]) * (Math.PI / 180.0);
			double num5 = (elements[body, 4] + num * elements[body, 10]) * (Math.PI / 180.0);
			double num6 = (elements[body, 5] + num * elements[body, 11]) * (Math.PI / 180.0);
			double num7 = elements[body, 3] + num * elements[body, 9] - num5 / (Math.PI / 180.0);
			if (body == 4)
			{
				num7 += -0.00012452 * num * num + 0.0606406 * Math.Cos(38.35125 * num * (Math.PI / 180.0)) - 0.35635438 * Math.Sin(38.35125 * num * (Math.PI / 180.0));
			}
			if (body == 5)
			{
				num7 += 0.00025899 * num * num - 0.13434469 * Math.Cos(38.35125 * num * (Math.PI / 180.0)) + 0.87320147 * Math.Sin(38.35125 * num * (Math.PI / 180.0));
			}
			double num8 = EccentricAnomaly(num7 * (Math.PI / 180.0), num3);
			double num9 = num2 * (Math.Cos(num8) - num3);
			double num10 = num2 * Math.Sqrt(1.0 - num3 * num3) * Math.Sin(num8);
			double num11 = num5 - num6;
			double num12 = Math.Cos(num11);
			double num13 = Math.Sin(num11);
			double num14 = Math.Cos(num6);
			double num15 = Math.Sin(num6);
			double num16 = Math.Cos(num4);
			double num17 = Math.Sin(num4);
			return new Vector((num12 * num14 - num13 * num15 * num16) * num9 + ((0.0 - num13) * num14 - num12 * num15 * num16) * num10, (num12 * num15 + num13 * num14 * num16) * num9 + ((0.0 - num13) * num15 + num12 * num14 * num16) * num10, num13 * num17 * num9 + num12 * num17 * num10);
		}

		public static Vector Equatorial(Vector ecliptic)
		{
			double num = Math.Cos(0.4090926102968565);
			double num2 = Math.Sin(0.4090926102968565);
			return new Vector(ecliptic.x, num * ecliptic.y - num2 * ecliptic.z, num2 * ecliptic.y + num * ecliptic.z);
		}

		public static Vector Geocentric(int body, double days)
		{
			return Equatorial(Heliocentric(body, days) - Heliocentric(2, days));
		}

		public static double SiderealAngle(double days)
		{
			if (days > 365250.0)
			{
				return Math.PI * 2.0 * SkyMath.Fraction(days * 1.0027379 + 0.78);
			}
			Vector vector = Heliocentric(2, days);
			Vector vector2 = Equatorial(new Vector(0.0 - vector.x, 0.0 - vector.y, 0.0 - vector.z));
			return Math.Atan2(vector2.y, vector2.x) + Math.PI * 2.0 * (SkyMath.Fraction(days) - 0.5);
		}

		public static Vector Horizontal(Vector v, double latitude, double sidereal)
		{
			double num = Math.Cos(sidereal);
			double num2 = Math.Sin(sidereal);
			double num3 = Math.Sin(latitude * (Math.PI / 180.0));
			double num4 = Math.Cos(latitude * (Math.PI / 180.0));
			double num5 = num * v.x + num2 * v.y;
			return new Vector((0.0 - num2) * v.x + num * v.y, num4 * num5 + num3 * v.z, (0.0 - num3) * num5 + num4 * v.z);
		}

		public static double PlanetMagnitude(int body, double days)
		{
			Vector vector = Heliocentric(body, days);
			Vector vector2 = Heliocentric(2, days);
			Vector vector3 = vector - vector2;
			double length = vector.Length;
			double length2 = vector3.Length;
			double num = Math.Acos(SkyMath.Clamp((vector.x * vector3.x + vector.y * vector3.y + vector.z * vector3.z) / (length * length2), -1.0, 1.0));
			double d = Math.Max(0.001, (Math.Sin(num) + (Math.PI - num) * Math.Cos(num)) / Math.PI);
			return body switch
			{
				4 => -9.4, 
				3 => -1.52, 
				1 => -4.4, 
				0 => -0.42, 
				_ => -8.88, 
			} + 5.0 * Math.Log10(length * length2) - 2.5 * Math.Log10(d);
		}

		public static double StellarFlux(double magnitude)
		{
			return Math.Pow(10.0, -0.18 * (magnitude + 1.46));
		}

		public static double MoonWashout(double magnitude, double illumination, double strength)
		{
			return Math.Exp((0.0 - SkyMath.Clamp(strength, 0.0, 1.0)) * SkyMath.Clamp(illumination, 0.0, 1.0) * Math.Max(0.0, magnitude - 1.0) * 0.42);
		}

		public static double MeteorDuration(long slot, int seed)
		{
			return 1.4 + 1.2 * SkyMath.Random((uint)((int)slot + seed + 91));
		}

		public static bool Meteor(double seconds, double rate, int seed, out long slot, out double age)
		{
			slot = 0L;
			age = 0.0;
			if (rate <= 0.0 || seconds < 0.0 || double.IsNaN(seconds) || double.IsInfinity(seconds) || double.IsNaN(rate) || double.IsInfinity(rate))
			{
				return false;
			}
			double num = 60.0 / SkyMath.Clamp(rate, 0.05, 12.0);
			double num2 = SkyMath.Random((uint)seed) * 0.6 * num;
			slot = (long)Math.Floor((seconds - num2) / num);
			age = seconds - num2 - (double)slot * num;
			if (age >= 0.0)
			{
				return age < MeteorDuration(slot, seed);
			}
			return false;
		}

		public static double NextMeteor(double seconds, double rate, int seed)
		{
			if (rate <= 0.0 || seconds < 0.0 || double.IsNaN(seconds) || double.IsInfinity(seconds) || double.IsNaN(rate) || double.IsInfinity(rate))
			{
				return double.PositiveInfinity;
			}
			double num = 60.0 / SkyMath.Clamp(rate, 0.05, 12.0);
			double num2 = SkyMath.Random((uint)seed) * 0.6 * num;
			return num - (seconds - num2 - Math.Floor((seconds - num2) / num) * num);
		}
	}
	internal sealed class AtmosphereFrame
	{
		private readonly Color fog = RenderSettings.fogColor;

		private readonly Color sky = RenderSettings.ambientSkyColor;

		private readonly Color equator = RenderSettings.ambientEquatorColor;

		private readonly Color ground = RenderSettings.ambientGroundColor;

		private readonly Color ambient = RenderSettings.ambientLight;

		private readonly Light light = RenderSettings.sun;

		private readonly SphericalHarmonicsL2 probe = RenderSettings.ambientProbe;

		private SphericalHarmonicsL2 appliedProbe;

		private bool probeEdited;

		private readonly float lightIntensity;

		private float appliedIntensity;

		private bool dimmed;

		private readonly Color lightColor;

		private readonly Quaternion lightRotation;

		private Color appliedFog;

		private Color appliedSky;

		private Color appliedEquator;

		private Color appliedGround;

		private Color appliedAmbient;

		private Color appliedLight;

		private Quaternion appliedRotation;

		private bool tinted;

		private bool rotated;

		private readonly bool canRestoreRotation;

		public AtmosphereFrame()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)light))
			{
				lightColor = light.color;
				lightIntensity = light.intensity;
				canRestoreRotation = UnityRotation.Normalize(((Component)light).transform.rotation, out var result);
				lightRotation = result;
			}
		}

		public static Color CopperTint(Color color, float amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			Astronomy.Vector vector = SkyMath.CopperColor(new Astronomy.Vector(color.r, color.g, color.b), amount);
			return new Color((float)vector.x, (float)vector.y, (float)vector.z, color.a);
		}

		private static bool SameProbe(SphericalHarmonicsL2 a, SphericalHarmonicsL2 b)
		{
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 9; j++)
				{
					if (((SphericalHarmonicsL2)(ref a))[i, j] != ((SphericalHarmonicsL2)(ref b))[i, j])
					{
						return false;
					}
				}
			}
			return true;
		}

		private static Color ScaleRgb(Color color, float factor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001e: Unknown result type (might be due to invalid IL or missing references)
			return new Color(color.r * factor, color.g * factor, color.b * factor, color.a);
		}

		public void Apply(float copper, Vector3? lightDirection, float eclipse = 0f, float raidDarkness = 0f)
		{
			//IL_0024: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			if (copper > 0f || eclipse > 0f || raidDarkness > 0f)
			{
				tinted = true;
				RenderSettings.fogColor = CopperTint(fog, copper);
				RenderSettings.ambientSkyColor = CopperTint(sky, copper);
				RenderSettings.ambientEquatorColor = CopperTint(equator, copper);
				RenderSettings.ambientGroundColor = CopperTint(ground, copper);
				RenderSettings.ambientLight = CopperTint(ambient, copper);
				if (eclipse > 0f || raidDarkness > 0f)
				{
					float factor = Mathf.Lerp(1f, 0.06f, eclipse) * (float)SkyMath.RaidLightFactor(1.0, raidDarkness, 0.8);
					RenderSettings.fogColor = ScaleRgb(RenderSettings.fogColor, factor);
					RenderSettings.ambientSkyColor = ScaleRgb(RenderSettings.ambientSkyColor, factor);
					RenderSettings.ambientEquatorColor = ScaleRgb(RenderSettings.ambientEquatorColor, factor);
					RenderSettings.ambientGroundColor = ScaleRgb(RenderSettings.ambientGroundColor, factor);
					RenderSettings.ambientLight = ScaleRgb(RenderSettings.ambientLight, factor);
					if (Object.op_Implicit((Object)(object)light))
					{
						dimmed = true;
						appliedIntensity = lightIntensity * Mathf.Lerp(1f, 0.015f, eclipse) * (float)SkyMath.RaidLightFactor(1.0, raidDarkness, 0.7);
						light.intensity = appliedIntensity;
					}
				}
				if (copper > 0f || raidDarkness > 0f)
				{
					float num = Mathf.Lerp(1f, 0.06f, eclipse) * (float)SkyMath.RaidLightFactor(1.0, raidDarkness, 0.8);
					appliedProbe = probe;
					for (int i = 0; i < 9; i++)
					{
						SphericalHarmonicsL2 val = probe;
						double x = ((SphericalHarmonicsL2)(ref val))[0, i];
						val = probe;
						double y = ((SphericalHarmonicsL2)(ref val))[1, i];
						val = probe;
						Astronomy.Vector vector = SkyMath.CopperColor(new Astronomy.Vector(x, y, ((SphericalHarmonicsL2)(ref val))[2, i]), copper);
						((SphericalHarmonicsL2)(ref appliedProbe))[0, i] = (float)vector.x * num;
						((SphericalHarmonicsL2)(ref appliedProbe))[1, i] = (float)vector.y * num;
						((SphericalHarmonicsL2)(ref appliedProbe))[2, i] = (float)vector.z * num;
					}
					probeEdited = true;
					RenderSettings.ambientProbe = appliedProbe;
				}
				appliedFog = RenderSettings.fogColor;
				appliedSky = RenderSettings.ambientSkyColor;
				appliedEquator = RenderSettings.ambientEquatorColor;
				appliedGround = RenderSettings.ambientGroundColor;
				appliedAmbient = RenderSettings.ambientLight;
				if (Object.op_Implicit((Object)(object)light))
				{
					light.color = CopperTint(lightColor, copper);
					appliedLight = light.color;
				}
			}
			if (Object.op_Implicit((Object)(object)light) && canRestoreRotation && lightDirection.HasValue && UnityRotation.Look(-lightDirection.Value, out appliedRotation))
			{
				rotated = true;
				string operation = RotationDiagnostics.Operation;
				RotationDiagnostics.Operation = "Apply normalized sky light rotation";
				try
				{
					((Component)light).transform.rotation = appliedRotation;
				}
				finally
				{
					RotationDiagnostics.Operation = operation;
				}
			}
		}

		public void Restore()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0153: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			bool num = probeEdited && SameProbe(RenderSettings.ambientProbe, appliedProbe);
			if (tinted)
			{
				if (RenderSettings.fogColor == appliedFog)
				{
					RenderSettings.fogColor = fog;
				}
				if (RenderSettings.ambientSkyColor == appliedSky)
				{
					RenderSettings.ambientSkyColor = sky;
				}
				if (RenderSettings.ambientEquatorColor == appliedEquator)
				{
					RenderSettings.ambientEquatorColor = equator;
				}
				if (RenderSettings.ambientGroundColor == appliedGround)
				{
					RenderSettings.ambientGroundColor = ground;
				}
				if (RenderSettings.ambientLight == appliedAmbient)
				{
					RenderSettings.ambientLight = ambient;
				}
				if (Object.op_Implicit((Object)(object)light) && light.color == appliedLight)
				{
					light.color = lightColor;
				}
			}
			if (dimmed && Object.op_Implicit((Object)(object)light) && light.intensity == appliedIntensity)
			{
				light.intensity = lightIntensity;
			}
			if (num)
			{
				RenderSettings.ambientProbe = probe;
			}
			if (rotated && Object.op_Implicit((Object)(object)light) && ((Component)light).transform.rotation == appliedRotation)
			{
				string operation = RotationDiagnostics.Operation;
				RotationDiagnostics.Operation = "Restore normalized sky light rotation";
				try
				{
					((Component)light).transform.rotation = lightRotation;
				}
				finally
				{
					RotationDiagnostics.Operation = operation;
				}
			}
		}
	}
	internal sealed class ButtonRepeat
	{
		private double next;

		private bool stopped;

		public string Key { get; private set; }

		public void Begin(string key, double now)
		{
			Key = key;
			next = now + 0.4;
			stopped = false;
		}

		public bool Tick(string key, double now, bool held, bool inside)
		{
			if (Key != key)
			{
				return false;
			}
			if (!held || !inside)
			{
				stopped = true;
				return false;
			}
			if (stopped || now < next)
			{
				return false;
			}
			next = now + 0.08;
			return true;
		}

		public void Reset()
		{
			Key = null;
			stopped = false;
			next = 0.0;
		}
	}
	internal static class CelestialDetail
	{
		public static readonly Astronomy.Vector Andromeda = Equatorial(10.6847, 41.2687);

		public static readonly Astronomy.Vector Pleiades = Equatorial(56.75, 24.1167);

		public const double ShowerPeriod = 120.0;

		public const double ShowerDuration = 40.0;

		public static Astronomy.Vector Equatorial(double ra, double dec)
		{
			ra *= Math.PI / 180.0;
			dec *= Math.PI / 180.0;
			return new Astronomy.Vector(Math.Cos(dec) * Math.Cos(ra), Math.Cos(dec) * Math.Sin(ra), Math.Sin(dec));
		}

		public static double GalacticLight(double longitude, double latitude)
		{
			double num = 0.06 + 0.015 * Math.Sin(3.0 * longitude + 0.4);
			double num2 = 0.67 + 0.18 * Math.Sin(5.0 * longitude + latitude * 23.0) + 0.09 * Math.Sin(17.0 * longitude + 0.8 - latitude * 39.0) + 0.035 * Math.Sin(43.0 * longitude + latitude * 117.0) + 0.025 * Math.Cos(71.0 * longitude - latitude * 193.0);
			double num3 = 0.5 + 0.5 * Math.Cos(longitude);
			double num4 = latitude - 0.018 * Math.Sin(4.0 * longitude);
			double num5 = 1.0 - 0.7 * Math.Exp((0.0 - num4) * num4 / 0.00015);
			double num6 = SolarLunar.Smooth((0.24 - Math.Abs(latitude)) / 0.06);
			return Math.Exp((0.0 - latitude) * latitude / (2.0 * num * num)) * num2 * (0.55 + 0.85 * num3 * num3) * num5 * num6;
		}

		public static double GalaxyProfile(double longitude, double latitude, double width, double contrast)
		{
			double num = GalacticLight(longitude, latitude / width);
			if (!(num <= 0.0))
			{
				return Math.Pow(num, contrast) * Math.Pow(0.35, 1.0 - contrast);
			}
			return 0.0;
		}

		public static double GalaxyHaloExpansion(double width)
		{
			return Math.Min(1.5, 1.5697963267948967 / (0.24 * width));
		}

		public static Astronomy.Vector GalacticSaturation(Astronomy.Vector color, double saturation)
		{
			if (saturation == 1.0)
			{
				return color;
			}
			double num = 0.2126 * color.x + 0.7152 * color.y + 0.0722 * color.z;
			double num2 = Math.Min(color.x, Math.Min(color.y, color.z));
			double num3 = SkyMath.Clamp(saturation, 0.0, 3.0);
			if (num2 < num)
			{
				num3 = Math.Min(num3, num / (num - num2));
			}
			return new Astronomy.Vector(num + (color.x - num) * num3, num + (color.y - num) * num3, num + (color.z - num) * num3);
		}

		public static Astronomy.Vector PlanetTint(int body, double emphasis)
		{
			double num = 1.0;
			double num2 = 1.0;
			double num3 = 1.0;
			switch (body)
			{
			case 0:
				num = 0.9;
				num2 = 0.88;
				num3 = 0.85;
				break;
			case 1:
				num = 1.0;
				num2 = 0.96;
				num3 = 0.86;
				break;
			case 3:
				num = 1.0;
				num2 = 0.55;
				num3 = 0.32;
				break;
			case 4:
				num = 1.0;
				num2 = 0.9;
				num3 = 0.76;
				break;
			case 5:
				num = 1.0;
				num2 = 0.86;
				num3 = 0.6;
				break;
			}
			emphasis = SkyMath.Clamp(emphasis, 0.0, 2.0);
			return new Astronomy.Vector(SkyMath.Clamp(1.0 + (num - 1.0) * emphasis, 0.0, 1.0), SkyMath.Clamp(1.0 + (num2 - 1.0) * emphasis, 0.0, 1.0), SkyMath.Clamp(1.0 + (num3 - 1.0) * emphasis, 0.0, 1.0));
		}

		public static bool Shower(double seconds, out double remaining)
		{
			if (double.IsNaN(seconds) || double.IsInfinity(seconds) || seconds < 0.0)
			{
				remaining = 0.0;
				return false;
			}
			double num = seconds % 120.0;
			bool flag = num < 40.0;
			remaining = (flag ? (40.0 - num) : (120.0 - num));
			return flag;
		}

		public static bool ShowerMeteor(double seconds, double rate, int seed, out long slot, out double age)
		{
			double remaining;
			if (Astronomy.Meteor(seconds, rate, seed, out slot, out age))
			{
				return Shower(seconds - age, out remaining);
			}
			return false;
		}

		public static double MeteorRate(double baseRate, double density)
		{
			if (!(baseRate <= 0.0))
			{
				return SkyMath.Clamp(baseRate * density, 0.05, 12.0);
			}
			return 0.0;
		}
	}
	internal sealed class CelestialDiscs : IDisposable
	{
		private readonly Settings config;

		private Material material;

		private Mesh quad;

		private Texture2D sun;

		private Texture2D halo;

		private readonly MaterialPropertyBlock properties = new MaterialPropertyBlock();

		public bool Ready
		{
			get
			{
				if (Object.op_Implicit((Object)(object)material) && Object.op_Implicit((Object)(object)quad) && Object.op_Implicit((Object)(object)sun))
				{
					return Object.op_Implicit((Object)(object)halo);
				}
				return false;
			}
		}

		public CelestialDiscs(Settings settings)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_011c: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0171: 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_017d: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			config = settings;
			Shader val = Shader.Find("Sprites/Default");
			if (Object.op_Implicit((Object)(object)val) && val.isSupported)
			{
				material = new Material(val)
				{
					hideFlags = (HideFlags)61,
					name = "AstralSkies sky discs"
				};
				quad = new Mesh
				{
					name = "AstralSkies disc quad",
					hideFlags = (HideFlags)61
				};
				quad.vertices = (Vector3[])(object)new Vector3[4]
				{
					new Vector3(-1f, -1f, 0f),
					new Vector3(1f, -1f, 0f),
					new Vector3(-1f, 1f, 0f),
					new Vector3(1f, 1f, 0f)
				};
				quad.uv = (Vector2[])(object)new Vector2[4]
				{
					new Vector2(0f, 0f),
					new Vector2(1f, 0f),
					new Vector2(0f, 1f),
					new Vector2(1f, 1f)
				};
				quad.colors = (Color[])(object)new Color[4]
				{
					Color.white,
					Color.white,
					Color.white,
					Color.white
				};
				quad.triangles = new int[6] { 0, 2, 1, 2, 3, 1 };
				sun = Radial(glow: false);
				halo = Radial(glow: true);
			}
		}

		private static Texture2D Radial(bool glow)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[65536];
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					Vector2 val = new Vector2(((float)j + 0.5f) / 256f * 2f - 1f, ((float)i + 0.5f) / 256f * 2f - 1f);
					float magnitude = ((Vector2)(ref val)).magnitude;
					float num = (glow ? Mathf.Max(0f, Mathf.Exp((0f - magnitude) * magnitude * 6f) - Mathf.Exp(-6f)) : Mathf.Clamp01((1f - magnitude) * 256f / 2f));
					float num2 = (glow ? 1f : (0.8f + 0.2f * Mathf.Sqrt(Mathf.Max(0f, 1f - magnitude * magnitude))));
					array[i * 256 + j] = new Color(num2, num2, num2, num);
				}
			}
			Texture2D val2 = new Texture2D(256, 256, (TextureFormat)4, false, true)
			{
				name = "AstralSkies analytic solar " + (glow ? "halo" : "disc"),
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
			val2.SetPixels(array);
			val2.Apply(false, true);
			return val2;
		}

		public static Vector3 Direction(double fraction, double phase, float latitude, float yaw)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Astronomy.Vector vector = SolarLunar.Direction(fraction, phase, latitude);
			double num = (double)yaw * (Math.PI / 180.0);
			double num2 = Math.Cos(num);
			double num3 = Math.Sin(num);
			return new Vector3((float)(num2 * vector.x + num3 * vector.z), (float)vector.y, (float)((0.0 - num3) * vector.x + num2 * vector.z));
		}

		public static Vector3 Calibrated(Astronomy.Vector v, float yaw)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			double num = (double)yaw * (Math.PI / 180.0);
			double num2 = Math.Cos(num);
			double num3 = Math.Sin(num);
			return new Vector3((float)(num2 * v.x + num3 * v.z), (float)v.y, (float)((0.0 - num3) * v.x + num2 * v.z));
		}

		public bool Draw(CommandBuffer cb, Camera camera, SkyTextures textures, SkyState state, float blood, double fraction, EclipseMath.Frame frame)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00ff: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: 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_0226: 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_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: 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_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: 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_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: 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_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: 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_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: 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_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: 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_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready || !Object.op_Implicit((Object)(object)textures.Moon))
			{
				return false;
			}
			double num = SkyMath.Phase(state.worldSeconds / state.dayLength, state.cycle, state.offset);
			SolarLunar.BloodPhase(num, blood);
			Vector3 val = Calibrated(frame.Sun, config.NorthYaw.Value);
			Vector3 val2 = Calibrated(frame.Moon, config.NorthYaw.Value);
			float num2 = 1f - Mathf.Clamp01(val.y * 4f);
			Color val3 = Color.Lerp(new Color(1f, 0.98f, 0.9f), new Color(1f, 0.53f, 0.24f), num2 * config.TwilightWarmth.Value);
			float num3 = (float)SolarLunar.Horizon(val.y);
			DrawDisc(cb, camera, val, Vector3.up, (Texture)(object)sun, (float)frame.SunRadius, new Color(val3.r, val3.g, val3.b, num3));
			float radius = Mathf.Min(0.5f, 0.035f * (float)(frame.SunRadius / 0.00465) * (1f + 0.04f * (config.SunHalo.Value - 2f)));
			DrawDisc(cb, camera, val, Vector3.up, (Texture)(object)halo, radius, new Color(val3.r, val3.g, val3.b, num3 * (float)SolarLunar.HaloOpacity(config.SunHalo.Value) * (1f - (float)frame.Dimming * 0.9f)));
			float num4 = (float)SolarLunar.Smooth((frame.SolarCoverage - 0.93) / 0.07);
			if (num4 > 0f)
			{
				DrawDisc(cb, camera, val, Vector3.up, (Texture)(object)halo, (float)frame.SunRadius * 3f, new Color(0.8f, 0.88f, 1f, num4 * 0.35f));
			}
			if (frame.SolarCoverage > 0.0)
			{
				DrawDisc(cb, camera, val2, Vector3.up, (Texture)(object)sun, (float)frame.MoonRadius, Color.black);
			}
			Vector3 val4 = val - val2 * Vector3.Dot(val, val2);
			Vector3 val5;
			Vector3 val6;
			if (!(((Vector3)(ref val4)).sqrMagnitude > 0.0001f))
			{
				val5 = Vector3.Cross(Vector3.up, val2);
				val6 = ((Vector3)(ref val5)).normalized;
			}
			else
			{
				val6 = ((Vector3)(ref val4)).normalized * (float)((Math.Sin(num * Math.PI * 2.0) >= 0.0) ? 1 : (-1));
			}
			val5 = Vector3.Cross(val6, val2);
			Vector3 normalized = ((Vector3)(ref val5)).normalized;
			float num5 = (float)frame.MoonRadius;
			float num6 = (float)SolarLunar.Horizon(val2.y) * Mathf.Lerp(0.16f, 1f, (float)SkyMath.NightVisibility(fraction, config.TwilightLength.Value));
			Color val7 = Color.Lerp(Color.white, new Color(1f, 0.28f, 0.09f), blood * config.RedStrength.Value);
			val7 *= config.MoonBrightness.Value * config.MoonGain.Value;
			val7.a = num6;
			DrawDisc(cb, camera, val2, normalized, (Texture)(object)textures.Moon, num5, val7);
			DrawDisc(cb, camera, val2, normalized, (Texture)(object)halo, num5 * 3f, new Color(1f, 0.22f, 0.07f, num6 * blood * 0.12f));
			return true;
		}

		private void DrawDisc(CommandBuffer cb, Camera camera, Vector3 direction, Vector3 up, Texture texture, float radius, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (!(color.a <= 0f))
			{
				float num = camera.farClipPlane * 0.85f;
				if (UnityRotation.Billboard(direction, up, num, num * Mathf.Tan(radius), out var result))
				{
					properties.Clear();
					properties.SetTexture("_MainTex", texture);
					properties.SetColor("_Color", color);
					cb.DrawMesh(quad, result, material, 0, 0, properties);
				}
			}
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
			if (Object.op_Implicit((Object)(object)quad))
			{
				Object.Destroy((Object)(object)quad);
			}
			if (Object.op_Implicit((Object)(object)sun))
			{
				Object.Destroy((Object)(object)sun);
			}
			if (Object.op_Implicit((Object)(object)halo))
			{
				Object.Destroy((Object)(object)halo);
			}
		}
	}
	internal static class EclipseMath
	{
		public struct Frame
		{
			public Astronomy.Vector Sun;

			public Astronomy.Vector Moon;

			public double SunRadius;

			public double MoonRadius;

			public double SolarCoverage;

			public double LunarCoverage;

			public double ShadowX;

			public double ShadowY;

			public double ShadowRadius;

			public double Dimming => SolarLunar.Smooth((SolarCoverage - 0.05) / 0.95);
		}

		public const double ReferenceRadius = 0.00465;

		public static double Dot(Astronomy.Vector a, Astronomy.Vector b)
		{
			return a.x * b.x + a.y * b.y + a.z * b.z;
		}

		public static Astronomy.Vector Cross(Astronomy.Vector a, Astronomy.Vector b)
		{
			return new Astronomy.Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
		}

		public static Astronomy.Vector Scale(Astronomy.Vector a, double s)
		{
			return new Astronomy.Vector(a.x * s, a.y * s, a.z * s);
		}

		public static Astronomy.Vector Unit(Astronomy.Vector a)
		{
			if (!(a.Length > 1E-12))
			{
				return new Astronomy.Vector(1.0, 0.0, 0.0);
			}
			return Scale(a, 1.0 / a.Length);
		}

		public static double MoonRatio(double days, double cycle)
		{
			return 1.0 + 0.055 * Math.Cos(Math.PI * 2.0 * days / (cycle * 0.93));
		}

		public static double Coverage(double r, double occultor, double distance)
		{
			if (r <= 0.0 || occultor <= 0.0 || distance >= r + occultor)
			{
				return 0.0;
			}
			if (distance <= Math.Abs(r - occultor))
			{
				return Math.Min(1.0, occultor * occultor / (r * r));
			}
			double num = Math.Acos(SkyMath.Clamp((distance * distance + r * r - occultor * occultor) / (2.0 * distance * r), -1.0, 1.0));
			double num2 = Math.Acos(SkyMath.Clamp((distance * distance + occultor * occultor - r * r) / (2.0 * distance * occultor), -1.0, 1.0));
			double val = (0.0 - distance + r + occultor) * (distance + r - occultor) * (distance - r + occultor) * (distance + r + occultor);
			return SkyMath.Clamp((r * r * num + occultor * occultor * num2 - 0.5 * Math.Sqrt(Math.Max(0.0, val))) / (Math.PI * r * r), 0.0, 1.0);
		}

		public static Frame Evaluate(double days, double fraction, double phase, double cycle, double latitude, double orbitCycles, double scale, double normalSun, double normalMoon, double raid, double blood, bool enabled)
		{
			double num = SolarLunar.BloodPhase(phase, blood) * 2.0 * Math.PI;
			double num2 = Math.PI * -2.0 * days / (cycle * ((orbitCycles >= 2.0) ? orbitCycles : 6.0));
			double num3 = (enabled ? (0.08979719001510825 * Math.Sin(num - num2) * (1.0 - SolarLunar.Smooth(blood))) : 0.0);
			Astronomy.Vector vector = SolarLunar.Direction(fraction, 0.0, latitude);
			Astronomy.Vector vector2 = Astronomy.Horizontal(new Astronomy.Vector(Math.Cos(num) * Math.Cos(num3), Math.Sin(num) * Math.Cos(num3), Math.Sin(num3)), latitude, Math.PI * 2.0 * (SkyMath.Fraction(fraction) - 0.5));
			double num4 = 0.00465 * (enabled ? scale : normalSun);
			double num5 = 0.00465 * SolarLunar.RaidDiameter(enabled ? (scale * MoonRatio(days, cycle)) : normalMoon, raid, blood);
			Frame result = new Frame
			{
				Sun = vector,
				Moon = vector2,
				SunRadius = num4,
				MoonRadius = num5
			};
			if (!enabled || blood > 0.0)
			{
				return result;
			}
			double num6 = Math.Acos(SkyMath.Clamp(Dot(vector, vector2), -1.0, 1.0));
			if (vector.y > 0.0 && vector2.y > 0.0)
			{
				result.SolarCoverage = Coverage(num4, num5, num6) * SolarLunar.Smooth(Math.Min(vector.y, vector2.y) / 0.04);
			}
			double distance = Math.PI - num6;
			double num7 = 0.00465 * scale * 2.65;
			if (vector2.y > 0.0)
			{
				result.LunarCoverage = Coverage(num5, num7, distance) * SolarLunar.Smooth(vector2.y / 0.04);
			}
			if (result.LunarCoverage > 0.0)
			{
				MoonBasis(vector, vector2, phase, out var right, out var up);
				Astronomy.Vector a = Scale(vector, -1.0);
				double num8 = Dot(a, vector2) * Math.Tan(num5);
				if (num8 > 1E-09)
				{
					result.ShadowX = Dot(a, right) / num8;
					result.ShadowY = Dot(a, up) / num8;
					result.ShadowRadius = Math.Tan(num7) / Math.Tan(num5);
				}
			}
			return result;
		}

		public static void MoonBasis(Astronomy.Vector sun, Astronomy.Vector moon, double phase, out Astronomy.Vector right, out Astronomy.Vector up)
		{
			Astronomy.Vector a = sun - Scale(moon, Dot(sun, moon));
			right = ((a.Length > 0.01) ? Scale(Unit(a), (Math.Sin(phase * 2.0 * Math.PI) >= 0.0) ? 1 : (-1)) : Unit(Cross(new Astronomy.Vector(0.0, 1.0, 0.0), moon)));
			up = Unit(Cross(right, moon));
		}

		public static double LunarShadow(double x, double y, Frame frame)
		{
			if (frame.LunarCoverage <= 0.0 || frame.ShadowRadius <= 0.0)
			{
				return 0.0;
			}
			double num = x - frame.ShadowX;
			double num2 = y - frame.ShadowY;
			return SolarLunar.Smooth((frame.ShadowRadius - Math.Sqrt(num * num + num2 * num2)) / 0.28);
		}
	}
	internal sealed class GameApi
	{
		private const BindingFlags All = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private readonly Dictionary<string, Type> types = new Dictionary<string, Type>();

		private readonly Dictionary<string, MemberInfo> members = new Dictionary<string, MemberInfo>();

		public bool IsServer
		{
			get
			{
				object obj = Call(Instance("ZNet"), "IsServer");
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public long ServerId
		{
			get
			{
				object target = Call(Instance("ZNet"), "GetServerPeer");
				object obj = Get(target, "m_uid");
				if (obj is long)
				{
					return (long)obj;
				}
				return 0L;
			}
		}

		public bool InWorld
		{
			get
			{
				if (Instance("ZNet") != null)
				{
					return Instance("EnvMan") != null;
				}
				return false;
			}
		}

		public object LocalPlayer => Get(Type("Player"), "m_localPlayer") ?? Get(Type("Player"), "s_localPlayer");

		public bool HasPlayer
		{
			get
			{
				Type target = Type("Player");
				object obj = Get(target, "m_localPlayer") ?? Get(target, "s_localPlayer");
				Object val = (Object)((obj is Object) ? obj : null);
				if (val != null)
				{
					return Object.op_Implicit(val);
				}
				return false;
			}
		}

		public bool French
		{
			get
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Invalid comparison between Unknown and I4
				string text = Call(Instance("Localization"), "GetSelectedLanguage") as string;
				if (!(text == "French"))
				{
					if (text == null)
					{
						return (int)Application.systemLanguage == 14;
					}
					return false;
				}
				return true;
			}
		}

		public Type Type(string name)
		{
			if (!types.TryGetValue(name, out var value))
			{
				value = (from a in AppDomain.CurrentDomain.GetAssemblies()
					select a.GetType(name, throwOnError: false)).FirstOrDefault((Type x) => x != null);
				types[name] = value;
			}
			return value;
		}

		public object Get(object target, string name)
		{
			if (target == null)
			{
				return null;
			}
			Type type = (target as Type) ?? target.GetType();
			string key = type.FullName + "." + name;
			if (!members.TryGetValue(key, out var value))
			{
				value = (MemberInfo)(((object)type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) ?? ((object)type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)));
				members[key] = value;
			}
			object obj = ((target is Type) ? null : target);
			if (!(value is FieldInfo fieldInfo))
			{
				if (!(value is PropertyInfo propertyInfo))
				{
					return null;
				}
				return propertyInfo.GetValue(obj, null);
			}
			return fieldInfo.GetValue(obj);
		}

		public object Instance(string name)
		{
			Type target = Type(name);
			object obj = Get(target, "instance") ?? Get(target, "s_instance") ?? Get(target, "m_instance");
			Object val = (Object)((obj is Object) ? obj : null);
			if (val == null || Object.op_Implicit(val))
			{
				return obj;
			}
			return null;
		}

		public object Call(object target, string name, params object[] args)
		{
			if (target == null)
			{
				return null;
			}
			Type type = (target as Type) ?? target.GetType();
			string key = type.FullName + "::" + name + "/" + args.Length;
			if (!members.TryGetValue(key, out var value))
			{
				value = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo x) => x.Name == name && !x.IsGenericMethod && x.GetParameters().Length == args.Length && x.GetParameters().Select((ParameterInfo p, int i) => args[i] == null || p.ParameterType.IsInstanceOfType(args[i])).All((bool result) => result));
				members[key] = value;
			}
			return (value as MethodInfo)?.Invoke((target is Type) ? null : target, args);
		}

		public bool Has(object target, string name)
		{
			if (target == null)
			{
				return false;
			}
			Type type = (target as Type) ?? target.GetType();
			if (!(type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null) && !(type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null))
			{
				return type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Any((MethodInfo m) => m.Name == name);
			}
			return true;
		}

		public bool ReadyPeer(long id)
		{
			object obj = Call(Instance("ZNet"), "GetPeer", id);
			bool flag = default(bool);
			int num;
			if (obj != null)
			{
				object obj2 = Call(obj, "IsReady");
				if (obj2 is bool)
				{
					flag = (bool)obj2;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		public bool TryDayFraction(out double value)
		{
			object target = Instance("EnvMan");
			object obj = Call(target, "GetDayFraction") ?? Get(target, "m_smoothDayFraction");
			value = ((obj is float || obj is double) ? Convert.ToDouble(obj) : double.NaN);
			if (!double.IsNaN(value))
			{
				return !double.IsInfinity(value);
			}
			return false;
		}

		public float StarVisibility(float twilightLength = 1.8f)
		{
			object obj = Instance("EnvMan");
			if (obj == null)
			{
				return 0f;
			}
			object obj2 = Call(obj, "GetDayFraction") ?? Get(obj, "m_smoothDayFraction");
			if (obj2 is float || obj2 is double)
			{
				return (float)SkyMath.NightVisibility(Convert.ToDouble(obj2), twilightLength);
			}
			object obj3 = Call(obj, "IsNight");
			bool flag = default(bool);
			int num;
			if (obj3 is bool)
			{
				flag = (bool)obj3;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (((uint)num & (flag ? 1u : 0u)) != 0) ? 1 : 0;
		}

		public bool TryClock(out double seconds, out double dayLength, out bool night)
		{
			seconds = 0.0;
			dayLength = 1800.0;
			night = false;
			object obj = Instance("EnvMan");
			object obj2 = Instance("ZNet");
			if (obj == null || obj2 == null)
			{
				return false;
			}
			object obj3 = Call(obj2, "GetTimeSeconds");
			object obj4 = Call(obj, "IsNight");
			if (obj3 == null || !(obj4 is bool))
			{
				return false;
			}
			seconds = Convert.ToDouble(obj3);
			object obj5 = Get(obj, "m_dayLengthSec");
			if (obj5 != null)
			{
				dayLength = Math.Max(1.0, Convert.ToDouble(obj5));
			}
			night = (bool)obj4;
			if (!double.IsNaN(seconds) && !double.IsInfinity(seconds))
			{
				return seconds >= 0.0;
			}
			return false;
		}

		public bool TryRaid(out string name)
		{
			name = "";
			object obj = Instance("RandEventSystem");
			if (obj == null || !Has(obj, "m_randomEvent"))
			{
				return false;
			}
			object obj2 = Get(obj, "m_randomEvent");
			if (obj2 != null)
			{
				name = (Get(obj2, "m_name") as string) ?? "";
			}
			return true;
		}

		public void Register(object rpc, string name, Action<long, string> callback)
		{
			MethodInfo? methodInfo = rpc.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "Register" && m.IsGenericMethodDefinition && m.GetGenericArguments().Length == 1 && m.GetParameters().Length == 2);
			if (methodInfo == null)
			{
				throw new MissingMethodException("ZRoutedRpc.Register<T>(string, Action<long,T>)");
			}
			methodInfo.MakeGenericMethod(typeof(string)).Invoke(rpc, new object[2] { name, callback });
		}

		public void Send(long target, string name, string payload)
		{
			object obj = Instance("ZRoutedRpc");
			if (obj != null && target != 0L)
			{
				Call(obj, "InvokeRoutedRPC", target, name, new object[1] { payload });
			}
		}

		public void Unregister(object rpc, string name)
		{
			if (Get(rpc, "m_functions") is IDictionary dictionary)
			{
				Type target = Type("StringExtensionMethods");
				object obj = Call(target, "GetStableHashCode", name);
				if (obj != null && dictionary.Contains(obj))
				{
					dictionary.Remove(obj);
				}
			}
		}

		public string Validate()
		{
			List<string> list = new List<string>();
			string[] array = new string[11]
			{
				"ZNet.GetTimeSeconds", "ZNet.IsServer", "ZNet.GetServerPeer", "ZNet.GetPeer", "ZNetPeer.m_uid", "ZRoutedRpc.InvokeRoutedRPC", "ZRoutedRpc.Register", "EnvMan.IsNight", "EnvMan.m_dayLengthSec", "RandEventSystem.m_randomEvent",
				"RandomEvent.m_name"
			};
			foreach (string text in array)
			{
				string[] array2 = text.Split(new char[1] { '.' });
				if (!Has(Type(array2[0]), array2[1]))
				{
					list.Add(text);
				}
			}
			return string.Join(", ", list.ToArray());
		}
	}
	internal sealed class GpuSky : IDisposable
	{
		private sealed class Builder
		{
			public int Segments = 12;

			private readonly List<Vector3> vertices = new List<Vector3>();

			private readonly List<Color> colors = new List<Color>();

			private readonly List<int> triangles = new List<int>();

			private void AddColor(Color color)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				color.a = 0f;
				colors.Add(color);
			}

			public void Clear()
			{
				vertices.Clear();
				colors.Clear();
				triangles.Clear();
			}

			public void Spot(Vector3 direction, float radius, Color color)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: 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_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: 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_0053: 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_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//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_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
				int count = vertices.Count;
				Vector3 val = Vector3.Cross(direction, ((double)Mathf.Abs(direction.y) > 0.9) ? Vector3.right : Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val2 = Vector3.Cross(direction, normalized);
				vertices.Add(direction);
				AddColor(color);
				for (int i = 0; i < 2; i++)
				{
					for (int j = 0; j < Segments; j++)
					{
						float num = (float)(j * 2) * (float)Math.PI / (float)Segments;
						vertices.Add(direction + (normalized * Mathf.Cos(num) + val2 * Mathf.Sin(num)) * radius * ((i == 0) ? 0.7f : 2f));
						AddColor((i == 0) ? (color * 0.5f) : Color.clear);
					}
				}
				for (int k = 0; k < Segments; k++)
				{
					int num2 = (k + 1) % Segments;
					int item = count + 1 + k;
					int item2 = count + 1 + num2;
					int item3 = count + 1 + Segments + k;
					int item4 = count + 1 + Segments + num2;
					triangles.Add(count);
					triangles.Add(item);
					triangles.Add(item2);
					triangles.Add(item);
					triangles.Add(item3);
					triangles.Add(item4);
					triangles.Add(item);
					triangles.Add(item4);
					triangles.Add(item2);
				}
			}

			public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color ca, Color cb, Color cc, Color cd)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				int count = vertices.Count;
				vertices.Add(a);
				vertices.Add(b);
				vertices.Add(c);
				vertices.Add(d);
				AddColor(ca);
				AddColor(cb);
				AddColor(cc);
				AddColor(cd);
				triangles.Add(count);
				triangles.Add(count + 1);
				triangles.Add(count + 2);
				triangles.Add(count + 2);
				triangles.Add(count + 1);
				triangles.Add(count + 3);
			}

			public void Ellipse(Vector3 direction, float major, float minor, float angle, Color color)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//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)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//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_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: 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_0108: 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_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: 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_0158: 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_0162: 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_016b: 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_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: 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_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: 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_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: 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_01aa: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = Vector3.forward - direction * Vector3.Dot(Vector3.forward, direction);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				val = Vector3.Cross(Vector3.forward, direction);
				Vector3 normalized2 = ((Vector3)(ref val)).normalized;
				Vector3 val2 = normalized * Mathf.Cos(angle * ((float)Math.PI / 180f)) + normalized2 * Mathf.Sin(angle * ((float)Math.PI / 180f));
				val = Vector3.Cross(direction, val2);
				Vector3 normalized3 = ((Vector3)(ref val)).normalized;
				for (int i = 0; i < 8; i++)
				{
					for (int j = 0; j < 48; j++)
					{
						float num = (float)i / 8f;
						float num2 = (float)(i + 1) / 8f;
						float num3 = (float)j * (float)Math.PI / 24f;
						float num4 = (float)(j + 1) * (float)Math.PI / 24f;
						Vector3 val3 = val2 * (Mathf.Cos(num3) * major) + normalized3 * (Mathf.Sin(num3) * minor);
						Vector3 val4 = val2 * (Mathf.Cos(num4) * major) + normalized3 * (Mathf.Sin(num4) * minor);
						Color val5 = color * (Mathf.Exp((0f - num) * num * 4f) - Mathf.Exp(-4f));
						Color val6 = color * (Mathf.Exp((0f - num2) * num2 * 4f) - Mathf.Exp(-4f));
						val = direction + val3 * num;
						Vector3 normalized4 = ((Vector3)(ref val)).normalized;
						val = direction + val4 * num;
						Vector3 normalized5 = ((Vector3)(ref val)).normalized;
						val = direction + val3 * num2;
						Vector3 normalized6 = ((Vector3)(ref val)).normalized;
						val = direction + val4 * num2;
						Quad(normalized4, normalized5, normalized6, ((Vector3)(ref val)).normalized, val5, val5, val6, val6);
					}
				}
			}

			public void Line(Vector3 start, Vector3 end, float width, Color color)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: 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_004d: 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_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = Vector3.Cross(start, end);
				Vector3 val2 = ((Vector3)(ref val)).normalized * width;
				int count = vertices.Count;
				vertices.Add(start - val2);
				vertices.Add(start + val2);
				vertices.Add(end - val2);
				vertices.Add(end + val2);
				for (int i = 0; i < 4; i++)
				{
					AddColor(color);
				}
				triangles.Add(count);
				triangles.Add(count + 1);
				triangles.Add(count + 2);
				triangles.Add(count + 2);
				triangles.Add(count + 1);
				triangles.Add(count + 3);
			}

			public void Apply(Mesh mesh)
			{
				mesh.Clear();
				mesh.SetVertices(vertices);
				mesh.SetColors(colors);
				mesh.SetTriangles(triangles, 0);
			}
		}

		private readonly Settings config;

		private readonly int refresh;

		private readonly int segments;

		private Matrix4x4 calibration = Matrix4x4.identity;

		private readonly string quality;

		private readonly Mesh[] stars = (Mesh[])(object)new Mesh[8];

		private readonly MaterialPropertyBlock[] properties = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[8];

		private readonly Builder dynamicBuilder = new Builder();

		private Mesh dynamicMesh;

		private Mesh galaxy;

		private Mesh constellations;

		private Mesh deepSky;

		private Mesh galaxyHalo;

		private Mesh galaxyStars;

		private Mesh galaxyParticles;

		private readonly Builder particleBuilder = new Builder
		{
			Segments = 8
		};

		private readonly MaterialPropertyBlock galaxyHaloProperties = new MaterialPropertyBlock();

		private readonly MaterialPropertyBlock galaxyStarProperties = new MaterialPropertyBlock();

		private readonly MaterialPropertyBlock particleProperties = new MaterialPropertyBlock();

		private float builtWidth;

		private float builtContrast;

		private float builtDensity;

		private float nextGalaxyBuild;

		private Vector3 galaxyPole;

		private Vector3 galaxyA;

		private Vector3 galaxyB;

		private float builtStarSize;

		private float guideStarted = -1f;

		private readonly Mesh[] guideLines = (Mesh[])(object)new Mesh[12];

		private readonly MaterialPropertyBlock[] lineProperties = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[12];

		private Material material;

		private float nextFrame;

		private float previousVisibility = -1f;

		private readonly MaterialPropertyBlock fadeProperties = new MaterialPropertyBlock();

		private readonly MaterialPropertyBlock guideProperties = new MaterialPropertyBlock();

		private readonly MaterialPropertyBlock galaxyProperties = new MaterialPropertyBlock();

		private readonly MaterialPropertyBlock deepProperties = new MaterialPropertyBlock();

		private double previousDay = double.NaN;

		private readonly float[] representativeMag = new float[8] { 0.5f, 0.5f, 2.5f, 2.5f, 4.5f, 4.5f, 6f, 6f };

		public Matrix4x4 Rotation { get; private set; } = Matrix4x4.identity;

		public GpuSky(Settings settings, string activeQuality)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			config = settings;
			quality = activeQuality;
			refresh = SolarLunar.Refresh(quality);
			segments = SolarLunar.StarSegments(quality);
			dynamicBuilder.Segments = segments;
			try
			{
				Initialize();
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		private void Initialize()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Hidden/Internal-Colored");
			if (!Object.op_Implicit((Object)(object)val) || !val.isSupported)
			{
				throw new NotSupportedException("GPU sky shader unavailable");
			}
			material = new Material(val)
			{
				name = "AstralSkies radial lights",
				hideFlags = (HideFlags)61
			};
			material.SetInt("_SrcBlend", 1);
			material.SetInt("_DstBlend", 1);
			material.SetInt("_Cull", 0);
			material.SetInt("_ZWrite", 0);
			material.SetInt("_ZTest", 4);
			material.SetColor("_Color", Color.white);
			BuildCatalogue();
			dynamicMesh = NewMesh("Planets and meteors");
			dynamicMesh.MarkDynamic();
			BuildDiffuseSky();
		}

		private void BuildCatalogue()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Expected O, but got Unknown
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: 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_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: 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_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			builtStarSize = config.StarSize.Value;
			Dictionary<int, Vector3> dictionary = new Dictionary<int, Vector3>();
			Builder[] array = new Builder[8];
			for (int i = 0; i < 8; i++)
			{
				array[i] = new Builder
				{
					Segments = segments
				};
				if (properties[i] == null)
				{
					properties[i] = new MaterialPropertyBlock();
				}
			}
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AstralSkies.stars.csv"))
			{
				using StreamReader streamReader = new StreamReader(stream);
				string text;
				Vector3 val = default(Vector3);
				while ((text = streamReader.ReadLine()) != null)
				{
					if (text.Length != 0 && text[0] != '#')
					{
						string[] array2 = text.Split(new char[1] { ',' });
						int num = int.Parse(array2[0], CultureInfo.InvariantCulture);
						double num2 = double.Parse(array2[1], CultureInfo.InvariantCulture) * (Math.PI / 180.0);
						double num3 = double.Parse(array2[2], CultureInfo.InvariantCulture) * (Math.PI / 180.0);
						double num4 = double.Parse(array2[3], CultureInfo.InvariantCulture);
						double num5 = double.Parse(array2[4], CultureInfo.InvariantCulture);
						((Vector3)(ref val))..ctor((float)(Math.Cos(num3) * Math.Cos(num2)), (float)(Math.Cos(num3) * Math.Sin(num2)), (float)Math.Sin(num3));
						dictionary[num] = val;
						int num6 = ((!(num4 < 1.5)) ? ((num4 < 3.5) ? 1 : ((num4 < 5.5) ? 2 : 3)) : 0) * 2 + (num & 1);
						Color val2 = Color.Lerp(Color.white, SkyTextures.TemperatureColor(4600.0 * (1.0 / (0.92 * num5 + 1.7) + 1.0 / (0.92 * num5 + 0.62))), 0.4f);
						float radius = (1.15f + (float)Math.Max(0.0, 2.0 - num4) * 0.14f) * builtStarSize / 1024f;
						array[num6].Spot(val, radius, val2 * (float)Astronomy.StellarFlux(num4));
					}
				}
			}
			for (int j = 0; j < 8; j++)
			{
				if (!Object.op_Implicit((Object)(object)stars[j]))
				{
					stars[j] = NewMesh("Catalogue " + j);
				}
				array[j].Apply(stars[j]);
			}
			Builder builder = new Builder
			{
				Segments = segments
			};
			HashSet<int> hashSet = new HashSet<int>();
			Builder[] array3 = new Builder[12];
			for (int k = 0; k < 12; k++)
			{
				array3[k] = new Builder();
				if (lineProperties[k] == null)
				{
					lineProperties[k] = new MaterialPropertyBlock();
				}
			}
			int[][] paths = GuideCatalog.Paths;
			foreach (int[] array4 in paths)
			{
				int[] array5 = array4;
				foreach (int item in array5)
				{
					hashSet.Add(item);
				}
				for (int n = 1; n < array4.Length; n++)
				{
					Vector3 val3 = dictionary[array4[n - 1]];
					Vector3 val4 = dictionary[array4[n]];
					for (int num7 = 0; num7 < 12; num7++)
					{
						array3[Math.Min(11, (int)(((float)(n - 1) + (float)num7 / 12f) / (float)(array4.Length - 1) * 12f))].Line(Vector3.Slerp(val3, val4, (float)num7 / 12f), Vector3.Slerp(val3, val4, (float)(num7 + 1) / 12f), 0.00065f, new Color(0.025f, 0.045f, 0.055f));
					}
				}
			}
			foreach (int item2 in hashSet)
			{
				builder.Spot(dictionary[item2], 0.0034f, new Color(0.09f, 0.14f, 0.16f));
			}
			builder.Spot(dictionary[424], 0.004f, new Color(0.12f, 0.15f, 0.16f));
			if (!Object.op_Implicit((Object)(object)constellations))
			{
				constellations = NewMesh("Big Dipper, Cassiopeia and Polaris guides");
			}
			builder.Apply(constellations);
			for (int num8 = 0; num8 < 12; num8++)
			{
				if (!Object.op_Implicit((Object)(object)guideLines[num8]))
				{
					guideLines[num8] = NewMesh("Guide reveal " + num8);
				}
				array3[num8].Apply(guideLines[num8]);
			}
		}

		private void BuildDiffuseSky()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: 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_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: 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_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			builtWidth = config.GalaxyWidth.Value;
			builtContrast = config.GalaxyContrast.Value;
			builtDensity = config.GalaxyDensity.Value;
			Builder builder = new Builder();
			Builder builder2 = new Builder();
			Vector3 val = V(CelestialDetail.Equatorial(192.85948, 27.12825));
			Vector3 val2 = Vector3.Cross(val, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			Vector3 b = Vector3.Cross(val, normalized);
			galaxyPole = val;
			galaxyA = normalized;
			galaxyB = b;
			int num = SolarLunar.GalaxyColumns(quality);
			int num2 = SolarLunar.GalaxyRows(quality);
			float num3 = (float)CelestialDetail.GalaxyHaloExpansion(builtWidth);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					float longitude = (float)(i * 2) * (float)Math.PI / (float)num;
					float longitude2 = (float)((i + 1) * 2) * (float)Math.PI / (float)num;
					float num4 = (-0.24f + (float)j * 0.48f / (float)num2) * builtWidth;
					float num5 = (-0.24f + (float)(j + 1) * 0.48f / (float)num2) * builtWidth;
					builder.Quad(BandDirection(normalized, b, val, longitude, num4), BandDirection(normalized, b, val, longitude2, num4), BandDirection(normalized, b, val, longitude, num5), BandDirection(normalized, b, val, longitude2, num5), BandColor(longitude, num4), BandColor(longitude2, num4), BandColor(longitude, num5), BandColor(longitude2, num5));
					builder2.Quad(BandDirection(normalized, b, val, longitude, num4 * num3), BandDirection(normalized, b, val, longitude2, num4 * num3), BandDirection(normalized, b, val, longitude, num5 * num3), BandDirection(normalized, b, val, longitude2, num5 * num3), HaloColor(longitude, num4), HaloColor(longitude2, num4), HaloColor(longitude, num5), HaloColor(longitude2, num5));
				}
			}
			if (!Object.op_Implicit((Object)(object)galaxy))
			{
				galaxy = NewMesh("Procedural galactic clouds and dust lane");
			}
			builder.Apply(galaxy);
			if (!Object.op_Implicit((Object)(object)galaxyHalo))
			{
				galaxyHalo = NewMesh("Galactic radiance");
			}
			builder2.Apply(galaxyHalo);
			Builder builder3 = new Builder
			{
				Segments = 6
			};
			int num6 = (int)((float)((quality == "Ultra") ? 1400 : ((quality == "High") ? 900 : ((quality == "Performance") ? 160 : 450))) * builtDensity);
			for (uint num7 = 0u; num7 < num6; num7++)
			{
				float longitude3 = (float)SkyMath.Random(num7 * 7 + 101) * 2f * (float)Math.PI;
				float latitude = ((float)SkyMath.Random(num7 * 7 + 102) + (float)SkyMath.Random(num7 * 7 + 103) - 1f) * 0.15f * builtWidth;
				float num8 = 0.025f + 0.075f * (float)SkyMath.Random(num7 * 7 + 104);
				builder3.Spot(BandDirection(normalized, b, val, longitude3, latitude), 0.00038f + 0.00025f * (float)SkyMath.Random(num7 * 7 + 105), new Color(0.8f, 0.87f, 1f) * num8);
			}
			if (!Object.op_Implicit((Object)(object)galaxyStars))
			{
				galaxyStars = NewMesh("Artistic galactic background stars");
			}
			builder3.Apply(galaxyStars);
			if (!Object.op_Implicit((Object)(object)galaxyParticles))
			{
				galaxyParticles = NewMesh("Optional galactic particles");
				galaxyParticles.MarkDynamic();
			}
			Builder builder4 = new Builder();
			builder4.Ellipse(V(CelestialDetail.Andromeda), 0.027f, 0.009f, 38f, new Color(0.16f, 0.17f, 0.19f));
			builder4.Ellipse(V(CelestialDetail.Andromeda), 0.006f, 0.003f, 38f, new Color(0.35f, 0.31f, 0.26f));
			builder4.Ellipse(V(CelestialDetail.Pleiades), 0.015f, 0.012f, 0f, new Color(0.025f, 0.07f, 0.13f));
			if (!Object.op_Implicit((Object)(object)deepSky))
			{
				deepSky = NewMesh("Andromeda and Pleiades approximate diffuse glow");
			}
			builder4.Apply(deepSky);
		}

		private static Vector3 BandDirection(Vector3 a, Vector3 b, Vector3 pole, float longitude, float latitude)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			return (a * Mathf.Cos(longitude) + b * Mathf.Sin(longitude)) * Mathf.Cos(latitude) + pole * Mathf.Sin(latitude);
		}

		private Color BandColor(float longitude, float latitude)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			return Color.white * (float)CelestialDetail.GalaxyProfile(longitude, latitude, builtWidth, builtContrast);
		}

		private Color HaloColor(float longitude, float latitude)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			float num = latitude / builtWidth;
			return Color.white * (float)(0.2 * Math.Exp((double)((0f - num) * num) / 0.025) * SolarLunar.Smooth((0.24 - (double)Math.Abs(num)) / 0.06) * (0.7 + 0.3 * Math.Cos(longitude)));
		}

		private static Color GalacticTint(string palette)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(palette switch
			{
				"Neutral" => new Color(0.095f, 0.09f, 0.085f), 
				"Copper" => new Color(0.12f, 0.07f, 0.035f), 
				"Amethyst" => new Color(0.1f, 0.055f, 0.13f), 
				"Emerald" => new Color(0.045f, 0.105f, 0.08f), 
				_ => new Color(0.075f, 0.083f, 0.1f), 
			});
		}

		private static void Gain(MaterialPropertyBlock block, float gain)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			block.SetColor("_Color", new Color(gain, gain, gain, 1f));
		}

		private static Mesh NewMesh(string name)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			return new Mesh
			{
				name = "AstralSkies " + name,
				indexFormat = (IndexFormat)1,
				hideFlags = (HideFlags)61
			};
		}

		private static Vector3 Face(int f, double u, double v)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			SkyMath.FaceDirection(f, u, v, out var x, out var y, out var z);
			return new Vector3((float)x, (float)y, (float)z);
		}

		private static Vector3 V(Astronomy.Vector v)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3((float)v.x, (float)v.y, (float)v.z);
		}

		public void Update(SkyState state, float blood, float visibility)
		{
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: 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_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: 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_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0574: 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_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_078e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0797: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a8: Unknown result type (might be due to invalid IL or missing r