Decompiled source of WeatherControl v1.0.0

Mods/WeatherControl.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using WeatherControl;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "WeatherControl", "1.0.0", "kamonkus", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WeatherControl
{
	internal sealed class SkyKey
	{
		public Vector3 zen;

		public Vector3 hor;

		public Vector3 filter;

		public float ev;

		public float stars;
	}
	internal sealed class Look
	{
		public Vector3 zen;

		public Vector3 hor;

		public Vector3 gnd;

		public Vector3 sunCol;

		public Vector3 filter;

		public Vector3 ambSky;

		public Vector3 ambEq;

		public Vector3 ambGnd;

		public Vector3 fogCol;

		public Vector3 lightCol;

		public Vector3 cloudCol;

		public float ev;

		public float contrast;

		public float sat;

		public float stars;

		public float lightMul;

		public float fogDen;

		public float cloudAmt;

		public float rain;

		public float snow;

		public float wind;

		public float fogAmt;

		public float thunder;

		public float glowSun;

		public float glowMoon;

		public float sunVis;

		public float moonVis;

		public float refl;

		private static float L(float a, float b, float k)
		{
			return a + (b - a) * k;
		}

		public void CopyFrom(Look o)
		{
			//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_000e: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			zen = o.zen;
			hor = o.hor;
			gnd = o.gnd;
			sunCol = o.sunCol;
			filter = o.filter;
			ambSky = o.ambSky;
			ambEq = o.ambEq;
			ambGnd = o.ambGnd;
			fogCol = o.fogCol;
			lightCol = o.lightCol;
			cloudCol = o.cloudCol;
			ev = o.ev;
			contrast = o.contrast;
			sat = o.sat;
			stars = o.stars;
			lightMul = o.lightMul;
			fogDen = o.fogDen;
			cloudAmt = o.cloudAmt;
			rain = o.rain;
			snow = o.snow;
			wind = o.wind;
			fogAmt = o.fogAmt;
			thunder = o.thunder;
			glowSun = o.glowSun;
			glowMoon = o.glowMoon;
			sunVis = o.sunVis;
			moonVis = o.moonVis;
			refl = o.refl;
		}

		public void LerpTo(Look t, float k)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0073: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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)
			//IL_00eb: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			zen = Vector3.Lerp(zen, t.zen, k);
			hor = Vector3.Lerp(hor, t.hor, k);
			gnd = Vector3.Lerp(gnd, t.gnd, k);
			sunCol = Vector3.Lerp(sunCol, t.sunCol, k);
			filter = Vector3.Lerp(filter, t.filter, k);
			ambSky = Vector3.Lerp(ambSky, t.ambSky, k);
			ambEq = Vector3.Lerp(ambEq, t.ambEq, k);
			ambGnd = Vector3.Lerp(ambGnd, t.ambGnd, k);
			fogCol = Vector3.Lerp(fogCol, t.fogCol, k);
			lightCol = Vector3.Lerp(lightCol, t.lightCol, k);
			cloudCol = Vector3.Lerp(cloudCol, t.cloudCol, k);
			ev = L(ev, t.ev, k);
			contrast = L(contrast, t.contrast, k);
			sat = L(sat, t.sat, k);
			stars = L(stars, t.stars, k);
			lightMul = L(lightMul, t.lightMul, k);
			fogDen = L(fogDen, t.fogDen, k);
			cloudAmt = L(cloudAmt, t.cloudAmt, k);
			rain = L(rain, t.rain, k);
			snow = L(snow, t.snow, k);
			wind = L(wind, t.wind, k);
			fogAmt = L(fogAmt, t.fogAmt, k);
			thunder = L(thunder, t.thunder, k);
			glowSun = L(glowSun, t.glowSun, k);
			glowMoon = L(glowMoon, t.glowMoon, k);
			sunVis = L(sunVis, t.sunVis, k);
			moonVis = L(moonVis, t.moonVis, k);
			refl = L(refl, t.refl, k);
		}
	}
	internal static class Astro
	{
		private static readonly float[] H = new float[12]
		{
			0f, 4.5f, 5.75f, 6.5f, 8f, 12.5f, 16.5f, 18.2f, 19f, 19.75f,
			21f, 24f
		};

		private static readonly Vector3[] Z = (Vector3[])(object)new Vector3[12]
		{
			new Vector3(0.02f, 0.035f, 0.1f),
			new Vector3(0.025f, 0.045f, 0.12f),
			new Vector3(0.13f, 0.18f, 0.36f),
			new Vector3(0.33f, 0.48f, 0.76f),
			new Vector3(0.28f, 0.5f, 0.88f),
			new Vector3(0.15f, 0.37f, 0.82f),
			new Vector3(0.19f, 0.39f, 0.8f),
			new Vector3(0.26f, 0.36f, 0.66f),
			new Vector3(0.18f, 0.2f, 0.45f),
			new Vector3(0.06f, 0.07f, 0.2f),
			new Vector3(0.025f, 0.04f, 0.11f),
			new Vector3(0.02f, 0.035f, 0.1f)
		};

		private static readonly Vector3[] Hr = (Vector3[])(object)new Vector3[12]
		{
			new Vector3(0.05f, 0.075f, 0.16f),
			new Vector3(0.07f, 0.1f, 0.2f),
			new Vector3(0.62f, 0.4f, 0.42f),
			new Vector3(1f, 0.62f, 0.38f),
			new Vector3(0.76f, 0.83f, 0.93f),
			new Vector3(0.62f, 0.78f, 0.95f),
			new Vector3(0.7f, 0.79f, 0.9f),
			new Vector3(1f, 0.58f, 0.28f),
			new Vector3(0.95f, 0.36f, 0.21f),
			new Vector3(0.42f, 0.19f, 0.26f),
			new Vector3(0.075f, 0.095f, 0.17f),
			new Vector3(0.05f, 0.075f, 0.16f)
		};

		private static readonly float[] Ev = new float[12]
		{
			-1.9f, -1.8f, -1.1f, -0.35f, 0f, 0f, 0f, -0.3f, -0.8f, -1.5f,
			-1.8f, -1.9f
		};

		private static readonly Vector3[] F = (Vector3[])(object)new Vector3[12]
		{
			new Vector3(0.62f, 0.76f, 1f),
			new Vector3(0.64f, 0.78f, 1f),
			new Vector3(0.85f, 0.82f, 0.98f),
			new Vector3(1f, 0.9f, 0.8f),
			new Vector3(1f, 0.98f, 0.94f),
			new Vector3(1f, 1f, 1f),
			new Vector3(1f, 0.98f, 0.94f),
			new Vector3(1f, 0.88f, 0.76f),
			new Vector3(1f, 0.76f, 0.7f),
			new Vector3(0.8f, 0.74f, 0.95f),
			new Vector3(0.64f, 0.76f, 1f),
			new Vector3(0.62f, 0.76f, 1f)
		};

		private static readonly float[] St = new float[12]
		{
			1f, 1f, 0.45f, 0f, 0f, 0f, 0f, 0f, 0.05f, 0.6f,
			1f, 1f
		};

		public static float Elev(float h)
		{
			if (h >= 6f && h <= 19f)
			{
				return 65f * Mathf.Sin((float)Math.PI * (h - 6f) / 13f);
			}
			float num = ((h > 19f) ? (h - 19f) : (h + 5f));
			return -45f * Mathf.Sin((float)Math.PI * num / 11f);
		}

		public static float Az(float h)
		{
			if (h >= 6f && h <= 19f)
			{
				return Mathf.Lerp(80f, 280f, (h - 6f) / 13f);
			}
			float num = ((h > 19f) ? (h - 19f) : (h + 5f));
			return 280f + 160f * (num / 11f);
		}

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

		public static Vector3 SunTint(float el)
		{
			//IL_000f: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Lerp(new Vector3(1f, 0.45f, 0.18f), new Vector3(1f, 0.95f, 0.85f), U.Sm(0f, 28f, el));
		}

		public static void Sample(float h, SkyKey o)
		{
			//IL_0062: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			h = Mathf.Repeat(h, 24f);
			int i;
			for (i = 0; i < H.Length - 2 && h >= H[i + 1]; i++)
			{
			}
			float num = (h - H[i]) / (H[i + 1] - H[i]);
			num = num * num * (3f - 2f * num);
			o.zen = Vector3.Lerp(Z[i], Z[i + 1], num);
			o.hor = Vector3.Lerp(Hr[i], Hr[i + 1], num);
			o.filter = Vector3.Lerp(F[i], F[i + 1], num);
			o.ev = Mathf.Lerp(Ev[i], Ev[i + 1], num);
			o.stars = Mathf.Lerp(St[i], St[i + 1], num);
		}
	}
	internal static class Env
	{
		private static bool _levelReady;

		private static bool _applied;

		private static bool _curInit;

		private static bool _covered;

		private static float _readyAt = float.MaxValue;

		private static float _blend;

		private static float _curHour = 12.5f;

		private static float _curSkyHour = 12.5f;

		private static float _indoor = 1f;

		private static float _nextIndoor;

		private static readonly Look _cur = new Look();

		private static readonly Look _tgt = new Look();

		private static readonly SkyKey _kw = new SkyKey();

		private static readonly SkyKey _ks = new SkyKey();

		private static readonly SkyState _sky = new SkyState();

		private static Camera _boundCam;

		private static Light _sun;

		private static bool _fogOurs;

		private static AmbientMode oAmbMode;

		private static Color oAmbSky;

		private static Color oAmbEq;

		private static Color oAmbGnd;

		private static Color oAmbLight;

		private static float oAmbInt;

		private static float oRefl;

		private static float oFogDen;

		private static float oFogStart;

		private static float oFogEnd;

		private static float oSunInt;

		private static bool oFog;

		private static FogMode oFogMode;

		private static Color oFogCol;

		private static Color oSunCol;

		private static Quaternion oSunRot;

		public static float CurHour => _curHour;

		public static void Init()
		{
			_readyAt = Time.realtimeSinceStartup + 6f;
		}

		public static void OnLevelLoaded()
		{
			_readyAt = Time.realtimeSinceStartup + 1.5f;
		}

		public static void OnLevelUnloaded()
		{
			_levelReady = false;
			_applied = false;
			_fogOurs = false;
			_sun = null;
			_blend = 0f;
			_boundCam = null;
			HideAll();
		}

		public static void ResetEnvironment()
		{
			_blend = 0f;
			HideAll();
			if (_applied)
			{
				Restore();
			}
		}

		private static void HideAll()
		{
			try
			{
				SkyDome.Hide();
				WeatherFx.Hide();
				PostFx.Hide();
			}
			catch (Exception ex)
			{
				U.Warn("hide failed: " + ex.Message);
			}
		}

		private static void Capture()
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			oAmbMode = RenderSettings.ambientMode;
			oAmbSky = RenderSettings.ambientSkyColor;
			oAmbEq = RenderSettings.ambientEquatorColor;
			oAmbGnd = RenderSettings.ambientGroundColor;
			oAmbLight = RenderSettings.ambientLight;
			oAmbInt = RenderSettings.ambientIntensity;
			oRefl = RenderSettings.reflectionIntensity;
			oFog = RenderSettings.fog;
			oFogMode = RenderSettings.fogMode;
			oFogCol = RenderSettings.fogColor;
			oFogDen = RenderSettings.fogDensity;
			oFogStart = RenderSettings.fogStartDistance;
			oFogEnd = RenderSettings.fogEndDistance;
			_sun = RenderSettings.sun;
			if ((Object)(object)_sun == (Object)null)
			{
				try
				{
					Il2CppArrayBase<Light> val = Object.FindObjectsOfType<Light>();
					float num = -1f;
					for (int i = 0; i < val.Length; i++)
					{
						Light val2 = val[i];
						if (!((Object)(object)val2 == (Object)null) && (int)val2.type == 1 && val2.intensity > num)
						{
							num = val2.intensity;
							_sun = val2;
						}
					}
				}
				catch (Exception ex)
				{
					U.Warn("sun search failed: " + ex.Message);
				}
			}
			if ((Object)(object)_sun != (Object)null)
			{
				oSunCol = _sun.color;
				oSunInt = _sun.intensity;
				oSunRot = ((Component)_sun).transform.rotation;
			}
			U.Log("Captured map lighting. Sun light: " + (((Object)(object)_sun != (Object)null) ? ((Object)_sun).name : "none") + ", ambient mode: " + ((object)Unsafe.As<AmbientMode, AmbientMode>(ref oAmbMode)/*cast due to .constrained prefix*/).ToString() + ", fog: " + oFog);
		}

		private static void Restore()
		{
			//IL_0000: 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_0014: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				RenderSettings.ambientMode = oAmbMode;
				RenderSettings.ambientSkyColor = oAmbSky;
				RenderSettings.ambientEquatorColor = oAmbEq;
				RenderSettings.ambientGroundColor = oAmbGnd;
				RenderSettings.ambientLight = oAmbLight;
				RenderSettings.ambientIntensity = oAmbInt;
				RenderSettings.reflectionIntensity = oRefl;
				RenderSettings.fog = oFog;
				RenderSettings.fogMode = oFogMode;
				RenderSettings.fogColor = oFogCol;
				RenderSettings.fogDensity = oFogDen;
				RenderSettings.fogStartDistance = oFogStart;
				RenderSettings.fogEndDistance = oFogEnd;
				if ((Object)(object)_sun != (Object)null)
				{
					_sun.color = oSunCol;
					_sun.intensity = oSunInt;
					((Component)_sun).transform.rotation = oSunRot;
				}
			}
			catch (Exception ex)
			{
				U.Warn("restore failed: " + ex.Message);
			}
			_applied = false;
			_fogOurs = false;
			U.Log("Map environment restored.");
		}

		private static float MoveHour(float cur, float target, float dt, float k)
		{
			float num = Mathf.DeltaAngle(cur * 15f, target * 15f) / 15f;
			if (Mathf.Abs(num) < 0.002f)
			{
				return target;
			}
			return Mathf.Repeat(cur + num * (1f - Mathf.Exp((0f - dt) * k)), 24f);
		}

		public static void Tick()
		{
			//IL_02a0: 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_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: 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_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: 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_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: 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_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			float num = Mathf.Clamp(Time.unscaledDeltaTime, 0.0005f, 0.1f);
			if (!_levelReady)
			{
				if (realtimeSinceStartup < _readyAt || (Object)(object)U.HeadCam() == (Object)null)
				{
					return;
				}
				_levelReady = true;
				U.Log("Level ready.");
			}
			bool enabled = Settings.Enabled;
			float num2 = (enabled ? 1f : 0f);
			if (_blend < num2)
			{
				_blend = Mathf.Min(num2, _blend + num / 1.5f);
			}
			else if (_blend > num2)
			{
				_blend = Mathf.Max(num2, _blend - num / 1.5f);
			}
			if (_blend <= 0.0001f && !enabled)
			{
				if (_applied)
				{
					HideAll();
					Restore();
				}
				return;
			}
			Camera val = U.HeadCam();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if ((Object)(object)val != (Object)(object)_boundCam)
			{
				_boundCam = val;
				PostFx.Bind(val);
			}
			if (!_applied)
			{
				Capture();
				_applied = true;
			}
			float blend = _blend;
			float num3 = Params.Get(P.TransitionSpeed);
			if (Params.Bool(P.AutoTime))
			{
				float num4 = Params.Get(P.Hour) + num * 24f / (Params.Get(P.DayLength) * 60f);
				if (num4 >= 24f)
				{
					num4 -= 24f;
				}
				Params.Set(P.Hour, num4, notify: false);
				_curHour = num4;
			}
			else if (!_curInit)
			{
				_curHour = Params.Get(P.Hour);
			}
			else
			{
				_curHour = MoveHour(_curHour, Params.Get(P.Hour), num, 1.2f * num3);
			}
			int num5 = Mathf.RoundToInt(Params.Get(P.SkyStyle));
			float num6 = _curHour;
			switch (num5)
			{
			case 1:
				num6 = 7.2f;
				break;
			case 2:
				num6 = 12.5f;
				break;
			case 3:
				num6 = 18.9f;
				break;
			case 4:
				num6 = 23.5f;
				break;
			}
			_curSkyHour = (_curInit ? MoveHour(_curSkyHour, num6, num, 1.2f * num3) : num6);
			Compute(_tgt);
			if (!_curInit)
			{
				_cur.CopyFrom(_tgt);
				_curInit = true;
			}
			else
			{
				_cur.LerpTo(_tgt, 1f - Mathf.Exp((0f - num) * 1.4f * num3));
			}
			Look cur = _cur;
			float num7 = (35f + 30f * Mathf.Sin(realtimeSinceStartup * 0.05f)) * ((float)Math.PI / 180f);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(Mathf.Sin(num7), 0f, Mathf.Cos(num7));
			UpdateIndoor(val, num, realtimeSinceStartup);
			float num8 = cur.ev * blend;
			Vector3 val3 = Vector3.Lerp(Vector3.one, cur.filter, blend);
			float num9 = Mathf.Pow(2f, num8);
			Vector3 comp = default(Vector3);
			((Vector3)(ref comp))..ctor(1f / (num9 * Mathf.Max(0.2f, val3.x)), 1f / (num9 * Mathf.Max(0.2f, val3.y)), 1f / (num9 * Mathf.Max(0.2f, val3.z)));
			Vector3 fogRender = RenderFog(cur.fogCol, comp);
			WeatherFx.Tick(cur, ((Component)val).transform, fogRender, blend, _indoor, num, val2);
			float num10 = WeatherFx.Flash * blend;
			float num11 = Params.Get(P.SkyRotation);
			float elDeg = Astro.Elev(_curSkyHour);
			float azDeg = Astro.Az(_curSkyHour) + num11;
			Vector3 val4 = Astro.Dir(elDeg, azDeg);
			SkyState sky = _sky;
			sky.pos = ((Component)val).transform.position;
			sky.radius = Mathf.Clamp(val.farClipPlane * 0.9f, 30f, 1500f);
			sky.zen = cur.zen;
			sky.hor = cur.hor;
			sky.gnd = cur.gnd;
			sky.sunCol = cur.sunCol;
			sky.glowCol = cur.sunCol;
			sky.sunDir = val4;
			sky.moonDir = -val4;
			sky.sunGlow = cur.glowSun;
			sky.moonGlow = cur.glowMoon;
			sky.sunAlpha = cur.sunVis;
			sky.moonAlpha = cur.moonVis;
			sky.starAlpha = cur.stars;
			sky.cloudAmt = cur.cloudAmt;
			sky.cloudCol = cur.cloudCol;
			sky.cloudOpacity = 0.92f * Params.Get(P.CloudOpacity);
			sky.cloudStyle = Mathf.RoundToInt(Params.Get(P.CloudStyle));
			sky.cloudSize = Params.Get(P.CloudSize);
			sky.cloudHigh = Params.Get(P.CloudHigh);
			sky.cloudSoft = Params.Get(P.CloudSoft);
			sky.fogCol = cur.fogCol;
			sky.fogAmt = cur.fogAmt;
			sky.alpha = blend * Params.Get(P.SkyIntensity);
			sky.skyMul = Params.Get(P.SkyBrightness) * Mathf.Pow(2f, Params.Get(P.SkyExposure));
			sky.comp = comp;
			sky.flash = num10;
			sky.rotation = num11;
			sky.skyHour = _curSkyHour;
			float num12 = (0.004f + 0.02f * cur.wind) * Params.Get(P.CloudSpeed);
			sky.windX = val2.x * num12;
			sky.windZ = val2.z * num12;
			sky.dt = num;
			SkyDome.Update(sky);
			PostFx.Apply(blend, cur.ev + num10 * 1.1f, cur.filter, cur.contrast, cur.sat, Params.Bool(P.BloomManual), Params.Get(P.Bloom));
			ApplyRender(cur, blend, comp, num11);
		}

		private static void WeatherTint(ref Vector3 zen, ref Vector3 hor, ref Vector3 gnd, float overcast, float dark, float snow, bool custom, int style, float dayS)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e6: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0135: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0172: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01d3: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			float num = overcast * 0.88f;
			if (custom)
			{
				num *= 0.3f;
			}
			Vector3 val = Vector3.one * (U.Lum(zen) * Mathf.Lerp(1f, 0.75f, overcast) + 0.02f);
			Vector3 val2 = Vector3.one * (U.Lum(hor) * Mathf.Lerp(1.1f, 0.85f, overcast) + 0.02f);
			zen = Vector3.Lerp(zen, val, num);
			hor = Vector3.Lerp(hor, val2, num);
			gnd = Vector3.Lerp(gnd, val2 * 0.5f, num);
			float num2 = 1f - 0.5f * dark;
			zen *= num2;
			hor *= num2;
			gnd *= num2;
			if (style == 6)
			{
				float num3 = 0.25f + 0.75f * dayS;
				zen = Vector3.Lerp(zen, new Vector3(0.1f, 0.12f, 0.13f) * num3, 0.6f);
				hor = Vector3.Lerp(hor, new Vector3(0.22f, 0.25f, 0.26f) * num3, 0.6f);
				gnd = Vector3.Lerp(gnd, new Vector3(0.1f, 0.11f, 0.11f) * num3, 0.6f);
			}
			if (snow > 0f)
			{
				Vector3 val3 = Vector3.one * (0.06f * snow);
				zen += val3;
				hor += val3;
			}
		}

		private static void Compute(Look t)
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: 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_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: 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_0441: 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_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.RoundToInt(Params.Get(P.SkyStyle));
			float num2 = Params.Get(P.WeatherIntensity);
			float num3 = U.C01(Params.Get(P.Clouds) * num2);
			float num4 = U.C01(Params.Get(P.Rain) * num2);
			float num5 = U.C01(Params.Get(P.Fog) * num2);
			float wind = U.C01(Params.Get(P.Wind) * num2);
			float num6 = U.C01(Params.Get(P.Snow) * num2);
			float num7 = U.C01(Params.Get(P.Thunder) * num2);
			float num8 = Mathf.Max(Mathf.Max(num3, num4 * 0.8f), Mathf.Max(num6 * 0.6f, num7 * 0.9f));
			if (num == 5)
			{
				num8 = Mathf.Max(num8, 0.75f);
			}
			if (num == 6)
			{
				num8 = 1f;
			}
			float num9 = U.C01(num8 * 0.85f + num4 * 0.2f + num6 * 0.1f + num5 * 0.15f);
			float num10 = U.C01(num4 * 0.45f + num7 * 0.4f + ((num == 6) ? 0.55f : 0f) + num8 * 0.12f);
			Astro.Sample(_curHour, _kw);
			Astro.Sample(_curSkyHour, _ks);
			float num11 = Astro.Elev(_curSkyHour);
			float num12 = U.Sm(-2f, 14f, num11);
			Vector3 zen = _ks.zen;
			Vector3 hor = _ks.hor;
			float num13 = _ks.stars;
			bool flag = num == 7;
			if (flag)
			{
				((Vector3)(ref zen))..ctor(Params.Get(P.CustomZR), Params.Get(P.CustomZG), Params.Get(P.CustomZB));
				((Vector3)(ref hor))..ctor(Params.Get(P.CustomHR), Params.Get(P.CustomHG), Params.Get(P.CustomHB));
				num13 = 0f;
			}
			Vector3 gnd = hor * 0.45f;
			WeatherTint(ref zen, ref hor, ref gnd, num9, num10, num6, flag, num, num12);
			t.zen = zen;
			t.hor = hor;
			t.gnd = gnd;
			t.stars = num13 * (1f - U.C01(num9 * 1.1f)) * (1f - 0.6f * num5);
			t.sunCol = Astro.SunTint(num11);
			t.sunVis = U.Sm(-4f, 3f, num11) * (1f - 0.85f * num9) * (1f - 0.5f * num5);
			t.moonVis = U.Sm(-4f, 6f, 0f - num11) * (1f - 0.9f * num9) * (1f - 0.6f * num5);
			t.glowSun = (0.08f + (1f - U.Sm(0f, 25f, num11)) * 0.5f) * U.Sm(-14f, 2f, num11) * (1f - 0.8f * num9);
			t.glowMoon = 0.12f * U.Sm(-4f, 6f, 0f - num11) * (1f - 0.9f * num9);
			Vector3 val = Vector3.Lerp(t.sunCol, Vector3.one, 0.45f);
			Vector3 val2 = Vector3.Lerp(new Vector3(0.1f, 0.12f, 0.2f), val, num12);
			t.cloudCol = val2 * (1f - 0.5f * num10);
			t.cloudAmt = num8;
			float num14 = Astro.Elev(_curHour);
			float num15 = U.Sm(0f, 10f, num14);
			Vector3 zen2 = _kw.zen;
			Vector3 hor2 = _kw.hor;
			Vector3 gnd2 = hor2 * 0.45f;
			WeatherTint(ref zen2, ref hor2, ref gnd2, num9, num10, num6, custom: false, -1, num15);
			bool flag2 = Params.Bool(P.SunManual);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(Params.Get(P.SunR), Params.Get(P.SunG), Params.Get(P.SunB));
			float num16 = Params.Get(P.SunIntensity);
			if (num14 > 0f)
			{
				t.lightCol = (flag2 ? val3 : Astro.SunTint(num14));
				t.lightMul = num16 * num15 * (1f - 0.65f * num9);
			}
			else
			{
				t.lightCol = (Vector3)(flag2 ? val3 : new Vector3(0.45f, 0.55f, 0.95f));
				t.lightMul = num16 * 0.35f * U.Sm(-2f, -14f, num14) * (1f - 0.5f * num9);
			}
			float num17 = Params.Get(P.AmbientBrightness);
			if (Params.Bool(P.AmbManual))
			{
				Vector3 val4 = default(Vector3);
				((Vector3)(ref val4))..ctor(Params.Get(P.AmbR), Params.Get(P.AmbG), Params.Get(P.AmbB));
				t.ambSky = val4 * num17;
				t.ambEq = val4 * (0.85f * num17);
				t.ambGnd = val4 * (0.6f * num17);
			}
			else
			{
				float num18 = Mathf.Lerp(0.45f, 1f, num15) * (1f - 0.2f * num9) * num17;
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(0.5f, 0.5f, 0.5f);
				t.ambSky = Vector3.Lerp(zen2, val5, 0.35f) * num18;
				t.ambEq = Vector3.Lerp(hor2, val5, 0.3f) * num18;
				t.ambGnd = gnd2 * (0.6f * num18) + Vector3.one * 0.03f;
			}
			t.fogAmt = num5;
			t.fogDen = num5 * 0.045f + num4 * 0.007f + num6 * 0.012f;
			Vector3 fogCol = Vector3.Lerp(hor2, Vector3.one * U.Lum(hor2), 0.4f);
			if (Params.Bool(P.FogManual))
			{
				((Vector3)(ref fogCol))..ctor(Params.Get(P.FogR), Params.Get(P.FogG), Params.Get(P.FogB));
			}
			t.fogCol = fogCol;
			t.ev = Mathf.Clamp(_kw.ev + Mathf.Log(Mathf.Max(0.05f, Params.Get(P.TimeIntensity)), 2f) + Params.Get(P.Exposure) - 0.35f * num9 - 0.7f * num10, -6f, 3f);
			t.filter = _kw.filter;
			t.sat = Params.Get(P.Saturation) - 35f * num9 - 20f * num5;
			t.contrast = Params.Get(P.Contrast) + 8f * num10;
			t.refl = Mathf.Lerp(0.5f, 1f, num15) * (1f - 0.3f * num9);
			t.rain = num4;
			t.snow = num6;
			t.wind = wind;
			t.thunder = num7;
		}

		private static Vector3 RenderFog(Vector3 fogS, Vector3 comp)
		{
			//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_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			return U.LToG(U.NormC(U.Mul(U.GToL(fogS), comp)));
		}

		private static Color Cl(Vector3 v)
		{
			//IL_0000: 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_002a: 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)
			return new Color(Mathf.Clamp(v.x, 0f, 2f), Mathf.Clamp(v.y, 0f, 2f), Mathf.Clamp(v.z, 0f, 2f), 1f);
		}

		private static void ApplyRender(Look l, float b, Vector3 comp, float rot)
		{
			//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_0021: 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_002c: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00d9: 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_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_0146: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0183: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			RenderSettings.ambientMode = (AmbientMode)1;
			RenderSettings.ambientSkyColor = Color.Lerp(oAmbSky, Cl(l.ambSky), b);
			RenderSettings.ambientEquatorColor = Color.Lerp(oAmbEq, Cl(l.ambEq), b);
			RenderSettings.ambientGroundColor = Color.Lerp(oAmbGnd, Cl(l.ambGnd), b);
			RenderSettings.reflectionIntensity = Mathf.Lerp(oRefl, oRefl * l.refl, b);
			if (l.fogDen > 0.0004f)
			{
				_fogOurs = true;
				RenderSettings.fog = true;
				RenderSettings.fogMode = (FogMode)3;
				RenderSettings.fogColor = Color.Lerp(oFogCol, Cl(RenderFog(l.fogCol, comp)), b);
				RenderSettings.fogDensity = l.fogDen * b;
			}
			else if (_fogOurs)
			{
				_fogOurs = false;
				RenderSettings.fog = oFog;
				RenderSettings.fogMode = oFogMode;
				RenderSettings.fogColor = oFogCol;
				RenderSettings.fogDensity = oFogDen;
				RenderSettings.fogStartDistance = oFogStart;
				RenderSettings.fogEndDistance = oFogEnd;
			}
			if ((Object)(object)_sun != (Object)null)
			{
				float num = Astro.Elev(_curHour);
				Vector3 val = Astro.Dir(num, Astro.Az(_curHour) + rot);
				if (num <= 0f)
				{
					val = -val;
				}
				Quaternion val2 = Quaternion.LookRotation(-val);
				((Component)_sun).transform.rotation = Quaternion.Slerp(oSunRot, val2, b);
				_sun.color = Color.Lerp(oSunCol, Cl(l.lightCol), b);
				_sun.intensity = Mathf.Lerp(oSunInt, oSunInt * l.lightMul, b);
			}
		}

		private static void UpdateIndoor(Camera cam, float dt, float now)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!Params.Bool(P.IndoorDetect))
			{
				_indoor += (1f - _indoor) * Mathf.Min(1f, dt * 3f);
				return;
			}
			if (now >= _nextIndoor)
			{
				_nextIndoor = now + 0.3f;
				_covered = IsCovered(((Component)cam).transform.position);
			}
			float num = (_covered ? 0f : 1f);
			_indoor += (num - _indoor) * Mathf.Min(1f, dt * 2.5f);
		}

		private static bool IsCovered(Vector3 head)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = head + Vector3.up * 0.35f;
			Transform val2 = null;
			try
			{
				RigManager rigManager = Player.RigManager;
				if ((Object)(object)rigManager != (Object)null)
				{
					val2 = ((Component)rigManager).transform;
				}
			}
			catch (Exception)
			{
			}
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < 4; i++)
			{
				if (!Physics.Raycast(val, Vector3.up, ref val3, 25f, U.RoofMask, (QueryTriggerInteraction)1))
				{
					return false;
				}
				Transform transform = ((Component)((RaycastHit)(ref val3)).collider).transform;
				if ((Object)(object)val2 != (Object)null && transform.IsChildOf(val2))
				{
					val = ((RaycastHit)(ref val3)).point + Vector3.up * 0.05f;
					continue;
				}
				return true;
			}
			return false;
		}
	}
	public class Main : MelonMod
	{
		private float _nextErrorLog;

		public override void OnInitializeMelon()
		{
			try
			{
				Settings.Init();
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[WeatherControl] settings init error: " + ex);
			}
			Env.Init();
			Hooking.OnLevelLoaded += delegate
			{
				Env.OnLevelLoaded();
			};
			Hooking.OnLevelUnloaded += Env.OnLevelUnloaded;
			try
			{
				Settings.BuildMenu();
			}
			catch (Exception ex2)
			{
				MelonLogger.Error("[WeatherControl] menu error: " + ex2);
			}
			MelonLogger.Msg("WeatherControl loaded.");
		}

		public override void OnLateUpdate()
		{
			try
			{
				Env.Tick();
				Settings.Tick();
			}
			catch (Exception ex)
			{
				if (Time.realtimeSinceStartup > _nextErrorLog)
				{
					_nextErrorLog = Time.realtimeSinceStartup + 5f;
					MelonLogger.Error("[WeatherControl] tick error: " + ex);
				}
			}
		}
	}
	public enum P
	{
		Hour,
		AutoTime,
		DayLength,
		TimeIntensity,
		SunIntensity,
		AmbientBrightness,
		TransitionSpeed,
		Clouds,
		Rain,
		Fog,
		Wind,
		Snow,
		Thunder,
		WeatherIntensity,
		IndoorDetect,
		Sounds,
		SoundVolume,
		CloudStyle,
		CloudSize,
		CloudSpeed,
		CloudOpacity,
		CloudHigh,
		CloudSoft,
		SkyStyle,
		SkyBrightness,
		SkyExposure,
		SkyRotation,
		SkyIntensity,
		CustomZR,
		CustomZG,
		CustomZB,
		CustomHR,
		CustomHG,
		CustomHB,
		SunManual,
		SunR,
		SunG,
		SunB,
		AmbManual,
		AmbR,
		AmbG,
		AmbB,
		FogManual,
		FogR,
		FogG,
		FogB,
		Exposure,
		Contrast,
		Saturation,
		BloomManual,
		Bloom
	}
	public enum SkyStyle
	{
		Auto,
		Morning,
		Day,
		Sunset,
		Night,
		Cloudy,
		Storm,
		Custom
	}
	public enum CloudStyle
	{
		Soft,
		Classic,
		Streaks,
		Puffy,
		Wispy,
		Overcast,
		Stormy
	}
	public enum PK
	{
		Float,
		Bool,
		Enum
	}
	public sealed class PDef
	{
		public P Id;

		public string Key;

		public string Label;

		public float Min;

		public float Max;

		public float Step;

		public float Def;

		public PK Kind;

		public bool Global;
	}
	public static class Params
	{
		public static readonly PDef[] Defs;

		public static readonly float[] V;

		public static readonly string[] BuiltinNames;

		public static event Action<P> Changed;

		static Params()
		{
			BuiltinNames = new string[14]
			{
				"Sunny Day", "Morning", "Evening", "Sunset", "Night", "Midnight", "Rain", "Storm", "Foggy", "Snow",
				"Winter", "Windy", "Apocalypse", "Dream"
			};
			int num = Enum.GetNames(typeof(P)).Length;
			Defs = new PDef[num];
			V = new float[num];
			D(P.Hour, "Hour (0-24)", 0f, 24f, 0.5f, 12.5f);
			D(P.AutoTime, "Auto time flow", 0f, 1f, 1f, 0f, PK.Bool);
			D(P.DayLength, "Day length (min)", 1f, 120f, 1f, 12f);
			D(P.TimeIntensity, "Time intensity", 0.1f, 2f, 0.1f, 1f);
			D(P.SunIntensity, "Sun brightness", 0f, 3f, 0.1f, 1f);
			D(P.AmbientBrightness, "Ambient brightness", 0f, 3f, 0.1f, 1f);
			D(P.TransitionSpeed, "Transition speed", 0.1f, 5f, 0.1f, 1f, PK.Float, global: true);
			D(P.Clouds, "Cloud density", 0f, 1f, 0.05f, 0.3f);
			D(P.Rain, "Rain intensity", 0f, 1f, 0.05f, 0f);
			D(P.Fog, "Fog density", 0f, 1f, 0.05f, 0f);
			D(P.Wind, "Wind strength", 0f, 1f, 0.05f, 0.15f);
			D(P.Snow, "Snow intensity", 0f, 1f, 0.05f, 0f);
			D(P.Thunder, "Thunderstorm", 0f, 1f, 0.1f, 0f);
			D(P.WeatherIntensity, "Weather intensity", 0f, 1.5f, 0.1f, 1f);
			D(P.IndoorDetect, "Hide rain/snow indoors", 0f, 1f, 1f, 1f, PK.Bool, global: true);
			D(P.Sounds, "Weather sounds", 0f, 1f, 1f, 1f, PK.Bool, global: true);
			D(P.SoundVolume, "Sound volume", 0f, 1f, 0.1f, 0.6f, PK.Float, global: true);
			D(P.CloudStyle, "Cloud style", 0f, 6f, 1f, 0f, PK.Enum);
			D(P.CloudSize, "Cloud size", 0.5f, 2.5f, 0.1f, 1f);
			D(P.CloudSpeed, "Cloud speed", 0f, 4f, 0.25f, 1f);
			D(P.CloudOpacity, "Cloud opacity", 0.2f, 1f, 0.05f, 1f);
			D(P.CloudHigh, "High cloud layer", 0f, 1f, 0.1f, 0.5f);
			D(P.CloudSoft, "Edge softness", 0.4f, 2f, 0.1f, 1f);
			D(P.SkyStyle, "Sky", 0f, 7f, 1f, 0f, PK.Enum);
			D(P.SkyBrightness, "Sky brightness", 0.2f, 3f, 0.1f, 1f);
			D(P.SkyExposure, "Sky exposure", -3f, 3f, 0.25f, 0f);
			D(P.SkyRotation, "Sky rotation", 0f, 360f, 15f, 0f);
			D(P.SkyIntensity, "Sky intensity", 0f, 1f, 0.1f, 1f);
			D(P.CustomZR, "Zenith red", 0f, 1f, 0.05f, 0.1f);
			D(P.CustomZG, "Zenith green", 0f, 1f, 0.05f, 0.3f);
			D(P.CustomZB, "Zenith blue", 0f, 1f, 0.05f, 0.7f);
			D(P.CustomHR, "Horizon red", 0f, 1f, 0.05f, 0.6f);
			D(P.CustomHG, "Horizon green", 0f, 1f, 0.05f, 0.75f);
			D(P.CustomHB, "Horizon blue", 0f, 1f, 0.05f, 0.9f);
			D(P.SunManual, "Manual sun color", 0f, 1f, 1f, 0f, PK.Bool);
			D(P.SunR, "Sun red", 0f, 1f, 0.05f, 1f);
			D(P.SunG, "Sun green", 0f, 1f, 0.05f, 0.9f);
			D(P.SunB, "Sun blue", 0f, 1f, 0.05f, 0.8f);
			D(P.AmbManual, "Manual ambient color", 0f, 1f, 1f, 0f, PK.Bool);
			D(P.AmbR, "Ambient red", 0f, 1f, 0.05f, 0.5f);
			D(P.AmbG, "Ambient green", 0f, 1f, 0.05f, 0.6f);
			D(P.AmbB, "Ambient blue", 0f, 1f, 0.05f, 0.8f);
			D(P.FogManual, "Manual fog color", 0f, 1f, 1f, 0f, PK.Bool);
			D(P.FogR, "Fog red", 0f, 1f, 0.05f, 0.6f);
			D(P.FogG, "Fog green", 0f, 1f, 0.05f, 0.65f);
			D(P.FogB, "Fog blue", 0f, 1f, 0.05f, 0.7f);
			D(P.Exposure, "Exposure", -4f, 4f, 0.25f, 0f);
			D(P.Contrast, "Contrast", -50f, 50f, 5f, 0f);
			D(P.Saturation, "Saturation", -100f, 100f, 10f, 0f);
			D(P.BloomManual, "Manual bloom", 0f, 1f, 1f, 0f, PK.Bool);
			D(P.Bloom, "Bloom intensity", 0f, 5f, 0.25f, 1f);
			for (int i = 0; i < num; i++)
			{
				if (Defs[i] == null)
				{
					P p = (P)i;
					throw new Exception("WeatherControl param not defined: " + p);
				}
				V[i] = Defs[i].Def;
			}
		}

		private static void D(P id, string label, float min, float max, float step, float def, PK kind = PK.Float, bool global = false)
		{
			Defs[(int)id] = new PDef
			{
				Id = id,
				Key = id.ToString(),
				Label = label,
				Min = min,
				Max = max,
				Step = step,
				Def = def,
				Kind = kind,
				Global = global
			};
		}

		public static float Get(P id)
		{
			return V[(int)id];
		}

		public static bool Bool(P id)
		{
			return V[(int)id] > 0.5f;
		}

		public static void Set(P id, float v, bool notify = true)
		{
			PDef pDef = Defs[(int)id];
			if (v < pDef.Min)
			{
				v = pDef.Min;
			}
			if (v > pDef.Max)
			{
				v = pDef.Max;
			}
			if (pDef.Kind != PK.Float)
			{
				v = (float)Math.Round(v);
			}
			if (V[(int)id] != v)
			{
				V[(int)id] = v;
				if (notify && Params.Changed != null)
				{
					Params.Changed(id);
				}
			}
		}

		public static void ResetAll()
		{
			for (int i = 0; i < Defs.Length; i++)
			{
				if (!Defs[i].Global)
				{
					Set((P)i, Defs[i].Def);
				}
			}
		}

		public static string Serialize()
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < Defs.Length; i++)
			{
				if (!Defs[i].Global)
				{
					stringBuilder.Append(Defs[i].Key).Append('=').Append(V[i].ToString("0.####", CultureInfo.InvariantCulture))
						.Append(';');
				}
			}
			return stringBuilder.ToString();
		}

		public static void Deserialize(string data)
		{
			for (int i = 0; i < Defs.Length; i++)
			{
				if (!Defs[i].Global)
				{
					Set((P)i, Defs[i].Def);
				}
			}
			if (string.IsNullOrEmpty(data))
			{
				return;
			}
			string[] array = data.Split(';');
			foreach (string text in array)
			{
				int num = text.IndexOf('=');
				if (num > 0)
				{
					string value = text.Substring(0, num);
					if (float.TryParse(text.Substring(num + 1), NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && Enum.TryParse<P>(value, out var result2))
					{
						Set(result2, result);
					}
				}
			}
		}

		public static string Builtin(string name)
		{
			return name switch
			{
				"Sunny Day" => "Hour=12.5;Clouds=0.35;Wind=0.15;CloudStyle=3", 
				"Morning" => "Hour=7;Clouds=0.3;Fog=0.15;Wind=0.1;CloudStyle=0", 
				"Evening" => "Hour=18.4;Clouds=0.4;Wind=0.1;CloudStyle=4", 
				"Sunset" => "Hour=18.9;Clouds=0.5;SunIntensity=1.1;CloudStyle=4", 
				"Night" => "Hour=23;Clouds=0.25;CloudStyle=0", 
				"Midnight" => "Hour=0.5;Clouds=0.15;TimeIntensity=0.7;CloudStyle=4", 
				"Rain" => "Hour=14;Clouds=0.85;Rain=0.55;Wind=0.3;CloudStyle=5", 
				"Storm" => "Hour=17;SkyStyle=6;Clouds=1;Rain=0.9;Wind=0.7;Thunder=0.8;Fog=0.1;CloudStyle=6;CloudSpeed=1.5", 
				"Foggy" => "Hour=8;Clouds=0.5;Fog=0.65;Wind=0.05;CloudStyle=5", 
				"Snow" => "Hour=13;Clouds=0.75;Snow=0.7;Wind=0.25;Fog=0.15;CloudStyle=5", 
				"Winter" => "Hour=12;Clouds=0.6;Snow=0.5;Fog=0.2;Wind=0.2;Saturation=-25;SunIntensity=0.9;CloudStyle=0", 
				"Windy" => "Hour=15;Clouds=0.55;Wind=0.9;CloudStyle=2;CloudSpeed=2", 
				"Apocalypse" => "Hour=17.5;SkyStyle=7;CustomZR=0.25;CustomZG=0.03;CustomZB=0.02;CustomHR=0.7;CustomHG=0.12;CustomHB=0.05;Clouds=0.6;CloudStyle=6;Fog=0.75;FogManual=1;FogR=0.35;FogG=0.06;FogB=0.04;SunManual=1;SunR=1;SunG=0.3;SunB=0.15;Wind=0.4;TimeIntensity=0.75;Contrast=10;Saturation=10", 
				"Dream" => "Hour=16.5;SkyStyle=7;CustomZR=0.65;CustomZG=0.55;CustomZB=0.9;CustomHR=1;CustomHG=0.8;CustomHB=0.9;Clouds=0.7;CloudStyle=3;CloudSize=1.3;Fog=0.25;FogManual=1;FogR=0.9;FogG=0.75;FogB=0.95;BloomManual=1;Bloom=2;Contrast=-15;Saturation=20;Wind=0.1", 
				_ => "", 
			};
		}
	}
	internal static class PostFx
	{
		private sealed class PRef
		{
			public object Param;

			public PropertyInfo Val;

			public PropertyInfo Ov;
		}

		private const BindingFlags BF = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;

		private static GameObject _go;

		private static Volume _vol;

		private static VolumeProfile _prof;

		private static VolumeComponent _ca;

		private static VolumeComponent _bloom;

		private static bool _failed;

		private static readonly Dictionary<string, PRef> _cache = new Dictionary<string, PRef>();

		private static readonly HashSet<string> _warned = new HashSet<string>();

		private static void Ensure()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if ((Object)(object)_vol != (Object)null || _failed)
			{
				return;
			}
			try
			{
				_go = new GameObject("WC_Volume");
				Object.DontDestroyOnLoad((Object)(object)_go);
				_vol = _go.AddComponent<Volume>();
				_vol.isGlobal = true;
				_vol.priority = 300f;
				_vol.weight = 0f;
				_prof = ScriptableObject.CreateInstance<VolumeProfile>();
				((Object)_prof).hideFlags = (HideFlags)32;
				_ca = (VolumeComponent)(object)_prof.Add<ColorAdjustments>(false);
				_bloom = (VolumeComponent)(object)_prof.Add<Bloom>(false);
				_vol.sharedProfile = _prof;
				U.Log("Post-processing volume created.");
			}
			catch (Exception ex)
			{
				_failed = true;
				U.Err("Could not create post-processing volume: " + ex);
			}
		}

		public static void Bind(Camera cam)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			if (_failed || (Object)(object)cam == (Object)null)
			{
				return;
			}
			try
			{
				UniversalAdditionalCameraData component = ((Component)cam).GetComponent<UniversalAdditionalCameraData>();
				if ((Object)(object)component == (Object)null)
				{
					U.Warn("Camera '" + ((Object)cam).name + "' has no UniversalAdditionalCameraData - color grading may not apply.");
					return;
				}
				bool renderPostProcessing = component.renderPostProcessing;
				if (!renderPostProcessing)
				{
					component.renderPostProcessing = true;
					U.Log("Post-processing was OFF on camera '" + ((Object)cam).name + "' - turned it on.");
				}
				LayerMask volumeLayerMask = component.volumeLayerMask;
				int value = ((LayerMask)(ref volumeLayerMask)).value;
				int num = 0;
				if ((value & 1) == 0)
				{
					num = -1;
					for (int i = 0; i < 32; i++)
					{
						if ((value & (1 << i)) != 0)
						{
							num = i;
							break;
						}
					}
					if (num < 0)
					{
						num = 0;
					}
				}
				_go.layer = num;
				U.Log("Volume bound to camera '" + ((Object)cam).name + "' (post-processing=" + renderPostProcessing + ", volume layer=" + num + ", mask=" + value + ").");
			}
			catch (Exception ex)
			{
				U.Warn("Bind camera failed: " + ex.Message);
			}
		}

		public static void Hide()
		{
			if (!((Object)(object)_vol == (Object)null))
			{
				_vol.weight = 0f;
				((Behaviour)_vol).enabled = false;
			}
		}

		public static void Apply(float weight, float ev, Vector3 filter, float contrast, float sat, bool bloomOn, float bloom)
		{
			//IL_004f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			Ensure();
			if (!_failed)
			{
				((Behaviour)_vol).enabled = weight > 0.001f;
				_vol.weight = Mathf.Clamp01(weight);
				Set(_ca, "postExposure", ev, over: true);
				Set(_ca, "colorFilter", (object)new Color(Mathf.Clamp01(filter.x), Mathf.Clamp01(filter.y), Mathf.Clamp01(filter.z), 1f), over: true);
				Set(_ca, "contrast", Mathf.Clamp(contrast, -100f, 100f), Mathf.Abs(contrast) > 0.05f);
				Set(_ca, "saturation", Mathf.Clamp(sat, -100f, 100f), Mathf.Abs(sat) > 0.05f);
				Set(_bloom, "intensity", Mathf.Max(0f, bloom), bloomOn);
			}
		}

		private static PropertyInfo FindProp(Type t, string name)
		{
			PropertyInfo[] properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
			for (int i = 0; i < properties.Length; i++)
			{
				if (properties[i].Name == name && properties[i].GetIndexParameters().Length == 0)
				{
					return properties[i];
				}
			}
			return null;
		}

		private static PRef Get(VolumeComponent comp, string name)
		{
			string text = ((object)comp).GetType().Name + "." + name;
			if (_cache.TryGetValue(text, out var value))
			{
				return value;
			}
			value = null;
			try
			{
				Type type = ((object)comp).GetType();
				object obj = null;
				PropertyInfo propertyInfo = FindProp(type, name);
				if (propertyInfo != null)
				{
					obj = propertyInfo.GetValue(comp, null);
				}
				else
				{
					FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
					if (field != null)
					{
						obj = field.GetValue(comp);
					}
				}
				if (obj != null)
				{
					Type type2 = obj.GetType();
					PropertyInfo propertyInfo2 = FindProp(type2, "value");
					PropertyInfo ov = FindProp(type2, "overrideState");
					if (propertyInfo2 != null)
					{
						value = new PRef
						{
							Param = obj,
							Val = propertyInfo2,
							Ov = ov
						};
					}
				}
			}
			catch (Exception ex)
			{
				U.Warn("Param lookup failed for " + text + ": " + ex.Message);
			}
			if (value == null && _warned.Add(text))
			{
				U.Warn("Volume parameter not found: " + text);
			}
			_cache[text] = value;
			return value;
		}

		private static void Set(VolumeComponent comp, string name, object value, bool over)
		{
			if ((Object)(object)comp == (Object)null)
			{
				return;
			}
			PRef pRef = Get(comp, name);
			if (pRef == null)
			{
				return;
			}
			try
			{
				if (over)
				{
					pRef.Val.SetValue(pRef.Param, value, null);
					if (pRef.Ov != null)
					{
						pRef.Ov.SetValue(pRef.Param, true, null);
					}
				}
				else if (pRef.Ov != null)
				{
					pRef.Ov.SetValue(pRef.Param, false, null);
				}
			}
			catch (Exception ex)
			{
				string item = ((object)comp).GetType().Name + "." + name + "!";
				if (_warned.Add(item))
				{
					U.Warn("Could not set " + name + ": " + ex.Message);
				}
			}
		}
	}
	internal static class Settings
	{
		public static bool Enabled = true;

		private const int Slots = 6;

		private static MelonPreferences_Category _cat;

		private static MelonPreferences_Entry<bool> _enEntry;

		private static MelonPreferences_Entry<float>[] _ent;

		private static MelonPreferences_Entry<string>[] _slotEnt;

		private static bool _dirty;

		private static bool _suppress;

		private static float _saveAt;

		private static float _nextHourSync;

		private static float _nextHourSave;

		private static float _nextClock;

		private static readonly Dictionary<P, List<FloatElement>> _fl = new Dictionary<P, List<FloatElement>>();

		private static readonly Dictionary<P, BoolElement> _bl = new Dictionary<P, BoolElement>();

		private static readonly Dictionary<P, EnumElement> _en = new Dictionary<P, EnumElement>();

		private static readonly Dictionary<P, Type> _enType = new Dictionary<P, Type>();

		private static BoolElement _enabledEl;

		private static FunctionElement _clock;

		private static readonly FunctionElement[] _slotStatus = (FunctionElement[])(object)new FunctionElement[6];

		private static string _lastClock = "";

		public static void Init()
		{
			_cat = MelonPreferences.CreateCategory("WeatherControl");
			_enEntry = _cat.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Enabled = _enEntry.Value;
			int num = Params.Defs.Length;
			_ent = new MelonPreferences_Entry<float>[num];
			for (int i = 0; i < num; i++)
			{
				PDef pDef = Params.Defs[i];
				_ent[i] = _cat.CreateEntry<float>("P_" + pDef.Key, pDef.Def, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
				Params.V[i] = Mathf.Clamp(_ent[i].Value, pDef.Min, pDef.Max);
			}
			_slotEnt = new MelonPreferences_Entry<string>[6];
			for (int j = 0; j < 6; j++)
			{
				_slotEnt[j] = _cat.CreateEntry<string>("Preset" + (j + 1), "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			Params.Changed += OnParamChanged;
		}

		private static void MarkDirty()
		{
			_dirty = true;
			_saveAt = Time.realtimeSinceStartup + 1.5f;
		}

		private static void OnParamChanged(P id)
		{
			try
			{
				_ent[(int)id].Value = Params.Get(id);
				MarkDirty();
			}
			catch (Exception)
			{
			}
			SyncElement(id);
		}

		private static void SetEnabled(bool v)
		{
			Enabled = v;
			_enEntry.Value = v;
			MarkDirty();
		}

		public static void Tick()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (_dirty && realtimeSinceStartup >= _saveAt)
			{
				_dirty = false;
				try
				{
					MelonPreferences.Save();
				}
				catch (Exception ex)
				{
					U.Warn("save prefs failed: " + ex.Message);
				}
			}
			if (Params.Bool(P.AutoTime))
			{
				if (realtimeSinceStartup >= _nextHourSync)
				{
					_nextHourSync = realtimeSinceStartup + 0.5f;
					SyncElement(P.Hour);
				}
				if (realtimeSinceStartup >= _nextHourSave)
				{
					_nextHourSave = realtimeSinceStartup + 5f;
					try
					{
						_ent[0].Value = Params.Get(P.Hour);
						MarkDirty();
					}
					catch (Exception)
					{
					}
				}
			}
			if (_clock == null || !(realtimeSinceStartup >= _nextClock))
			{
				return;
			}
			_nextClock = realtimeSinceStartup + 0.5f;
			string text = "Clock: " + FmtHour(Env.CurHour);
			if (text != _lastClock)
			{
				_lastClock = text;
				try
				{
					((Element)_clock).ElementName = text;
				}
				catch (Exception)
				{
				}
			}
		}

		private static string FmtHour(float h)
		{
			int num = (int)(Mathf.Repeat(h, 24f) * 60f);
			return (num / 60).ToString("00") + ":" + (num % 60).ToString("00");
		}

		private static void AddFloat(Page pg, P id, Color c)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			PDef pDef = Params.Defs[(int)id];
			FloatElement item = pg.CreateFloat(pDef.Label, c, Params.Get(id), pDef.Step, pDef.Min, pDef.Max, (Action<float>)delegate(float v)
			{
				if (!_suppress)
				{
					Params.Set(id, v);
				}
			});
			if (!_fl.TryGetValue(id, out var value))
			{
				value = new List<FloatElement>();
				_fl[id] = value;
			}
			value.Add(item);
		}

		private static void AddBool(Page pg, P id, Color c)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			PDef pDef = Params.Defs[(int)id];
			BoolElement value = pg.CreateBool(pDef.Label, c, Params.Bool(id), (Action<bool>)delegate(bool v)
			{
				if (!_suppress)
				{
					Params.Set(id, v ? 1f : 0f);
				}
			});
			_bl[id] = value;
		}

		private static void AddEnum(Page pg, P id, Color c, Type enumType)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			PDef pDef = Params.Defs[(int)id];
			Enum obj = (Enum)Enum.ToObject(enumType, (int)Params.Get(id));
			EnumElement value = pg.CreateEnum(pDef.Label, c, obj, (Action<Enum>)delegate(Enum v)
			{
				if (!_suppress)
				{
					Params.Set(id, Convert.ToInt32(v));
				}
			});
			_en[id] = value;
			_enType[id] = enumType;
		}

		private static void SyncElement(P id)
		{
			bool suppress = _suppress;
			_suppress = true;
			try
			{
				float num = Params.Get(id);
				if (_fl.TryGetValue(id, out var value))
				{
					for (int i = 0; i < value.Count; i++)
					{
						if (Mathf.Abs(value[i].Value - num) > 0.0001f)
						{
							value[i].Value = num;
						}
					}
				}
				if (_bl.TryGetValue(id, out var value2))
				{
					bool flag = num > 0.5f;
					if (value2.Value != flag)
					{
						value2.Value = flag;
					}
				}
				if (_en.TryGetValue(id, out var value3) && Convert.ToInt32(value3.Value) != (int)num)
				{
					value3.Value = (Enum)Enum.ToObject(_enType[id], (int)num);
				}
			}
			catch (Exception ex)
			{
				U.Warn("menu sync: " + ex.Message);
			}
			finally
			{
				_suppress = suppress;
			}
		}

		private static void AtLeast(P id, float v)
		{
			if (Params.Get(id) < v)
			{
				Params.Set(id, v);
			}
		}

		public static void BuildMenu()
		{
			//IL_000a: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00b1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			Page obj = Page.Root.CreatePage("WeatherControl", Color.cyan, 0, true);
			_enabledEl = obj.CreateBool("Enabled", Color.green, Enabled, (Action<bool>)delegate(bool v)
			{
				if (!_suppress)
				{
					SetEnabled(v);
				}
			});
			BuildTime(obj.CreatePage("Time of day", Color.yellow, 0, true));
			BuildWeather(obj.CreatePage("Weather", Color.cyan, 0, true));
			BuildClouds(obj.CreatePage("Clouds", Color.white, 0, true));
			BuildSky(obj.CreatePage("Sky", Color.magenta, 0, true));
			BuildLighting(obj.CreatePage("Lighting", Color.white, 0, true));
			BuildPresets(obj.CreatePage("Presets", Color.green, 0, true));
			obj.CreateFunction("Default settings", Color.red, (Action)delegate
			{
				Params.ResetAll();
				U.Log("Settings reset to defaults.");
			});
			obj.CreateFunction("Reset environment (restore map)", Color.red, (Action)delegate
			{
				SetEnabled(v: false);
				SyncEnabledElement();
				Env.ResetEnvironment();
			});
		}

		private static void SyncEnabledElement()
		{
			bool suppress = _suppress;
			_suppress = true;
			try
			{
				if (_enabledEl != null && _enabledEl.Value != Enabled)
				{
					_enabledEl.Value = Enabled;
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				_suppress = suppress;
			}
		}

		private static void BuildTime(Page pg)
		{
			//IL_0006: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			pg.CreateFunction("Morning", Color.yellow, (Action)delegate
			{
				Params.Set(P.Hour, 7f);
			});
			pg.CreateFunction("Day", Color.yellow, (Action)delegate
			{
				Params.Set(P.Hour, 12.5f);
			});
			pg.CreateFunction("Evening", Color.yellow, (Action)delegate
			{
				Params.Set(P.Hour, 18.4f);
			});
			pg.CreateFunction("Night", Color.yellow, (Action)delegate
			{
				Params.Set(P.Hour, 23f);
			});
			_clock = pg.CreateFunction("Clock: --:--", Color.gray, (Action)delegate
			{
			});
			AddFloat(pg, P.Hour, Color.white);
			AddBool(pg, P.AutoTime, Color.white);
			AddFloat(pg, P.DayLength, Color.white);
			AddFloat(pg, P.TimeIntensity, Color.white);
			AddFloat(pg, P.SunIntensity, Color.white);
			AddFloat(pg, P.AmbientBrightness, Color.white);
			AddFloat(pg, P.TransitionSpeed, Color.white);
		}

		private static void BuildWeather(Page pg)
		{
			//IL_0006: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			pg.CreateFunction("Clear", Color.yellow, (Action)delegate
			{
				Params.Set(P.Clouds, 0.1f);
				Params.Set(P.Rain, 0f);
				Params.Set(P.Fog, 0f);
				Params.Set(P.Snow, 0f);
				Params.Set(P.Thunder, 0f);
				Params.Set(P.Wind, 0.1f);
			});
			pg.CreateFunction("Clouds", Color.yellow, (Action)delegate
			{
				Params.Set(P.Clouds, 0.85f);
			});
			pg.CreateFunction("Rain", Color.yellow, (Action)delegate
			{
				Params.Set(P.Rain, 0.5f);
				AtLeast(P.Clouds, 0.6f);
			});
			pg.CreateFunction("Heavy rain", Color.yellow, (Action)delegate
			{
				Params.Set(P.Rain, 1f);
				AtLeast(P.Clouds, 0.85f);
				AtLeast(P.Wind, 0.35f);
			});
			pg.CreateFunction("Fog", Color.yellow, (Action)delegate
			{
				Params.Set(P.Fog, 0.5f);
			});
			pg.CreateFunction("Wind", Color.yellow, (Action)delegate
			{
				Params.Set(P.Wind, 0.8f);
			});
			pg.CreateFunction("Snow", Color.yellow, (Action)delegate
			{
				Params.Set(P.Snow, 0.7f);
				AtLeast(P.Clouds, 0.6f);
			});
			pg.CreateFunction("Storm", Color.yellow, (Action)delegate
			{
				Params.Set(P.Rain, 0.9f);
				Params.Set(P.Thunder, 0.8f);
				Params.Set(P.Clouds, 1f);
				AtLeast(P.Wind, 0.6f);
			});
			AddFloat(pg, P.WeatherIntensity, Color.white);
			AddFloat(pg, P.Clouds, Color.white);
			AddFloat(pg, P.Rain, Color.white);
			AddFloat(pg, P.Fog, Color.white);
			AddFloat(pg, P.Wind, Color.white);
			AddFloat(pg, P.Snow, Color.white);
			AddFloat(pg, P.Thunder, Color.white);
			AddBool(pg, P.IndoorDetect, Color.white);
			AddBool(pg, P.Sounds, Color.white);
			AddFloat(pg, P.SoundVolume, Color.white);
		}

		private static void BuildClouds(Page pg)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			AddEnum(pg, P.CloudStyle, Color.yellow, typeof(CloudStyle));
			AddFloat(pg, P.Clouds, Color.white);
			AddFloat(pg, P.CloudSize, Color.white);
			AddFloat(pg, P.CloudSpeed, Color.white);
			AddFloat(pg, P.CloudOpacity, Color.white);
			AddFloat(pg, P.CloudHigh, Color.white);
			AddFloat(pg, P.CloudSoft, Color.white);
		}

		private static void BuildSky(Page pg)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0094: 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)
			AddEnum(pg, P.SkyStyle, Color.white, typeof(SkyStyle));
			AddFloat(pg, P.SkyBrightness, Color.white);
			AddFloat(pg, P.SkyExposure, Color.white);
			AddFloat(pg, P.SkyRotation, Color.white);
			AddFloat(pg, P.SkyIntensity, Color.white);
			Page pg2 = pg.CreatePage("Custom sky colors", Color.magenta, 0, true);
			AddFloat(pg2, P.CustomZR, Color.red);
			AddFloat(pg2, P.CustomZG, Color.green);
			AddFloat(pg2, P.CustomZB, Color.cyan);
			AddFloat(pg2, P.CustomHR, Color.red);
			AddFloat(pg2, P.CustomHG, Color.green);
			AddFloat(pg2, P.CustomHB, Color.cyan);
		}

		private static void BuildLighting(Page pg)
		{
			//IL_0002: 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_001b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			AddFloat(pg, P.SunIntensity, Color.white);
			AddFloat(pg, P.AmbientBrightness, Color.white);
			AddFloat(pg, P.Exposure, Color.white);
			AddFloat(pg, P.Contrast, Color.white);
			AddFloat(pg, P.Saturation, Color.white);
			AddFloat(pg, P.Fog, Color.white);
			AddBool(pg, P.BloomManual, Color.white);
			AddFloat(pg, P.Bloom, Color.white);
			Page pg2 = pg.CreatePage("Sun color", Color.yellow, 0, true);
			AddBool(pg2, P.SunManual, Color.white);
			AddFloat(pg2, P.SunR, Color.red);
			AddFloat(pg2, P.SunG, Color.green);
			AddFloat(pg2, P.SunB, Color.cyan);
			Page pg3 = pg.CreatePage("Ambient color", Color.cyan, 0, true);
			AddBool(pg3, P.AmbManual, Color.white);
			AddFloat(pg3, P.AmbR, Color.red);
			AddFloat(pg3, P.AmbG, Color.green);
			AddFloat(pg3, P.AmbB, Color.cyan);
			Page pg4 = pg.CreatePage("Fog color", Color.gray, 0, true);
			AddBool(pg4, P.FogManual, Color.white);
			AddFloat(pg4, P.FogR, Color.red);
			AddFloat(pg4, P.FogG, Color.green);
			AddFloat(pg4, P.FogB, Color.cyan);
		}

		private static string Clean(string s)
		{
			if (s == null)
			{
				return "";
			}
			return s.Replace("|", " ").Replace(";", " ").Replace("=", " ")
				.Trim();
		}

		private static string SlotName(int i)
		{
			string value = _slotEnt[i].Value;
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			int num = value.IndexOf('|');
			if (num >= 0)
			{
				return value.Substring(0, num);
			}
			return value;
		}

		private static string SlotData(int i)
		{
			string value = _slotEnt[i].Value;
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			int num = value.IndexOf('|');
			if (num >= 0)
			{
				return value.Substring(num + 1);
			}
			return "";
		}

		private static string SlotStatus(int i)
		{
			if (string.IsNullOrEmpty(SlotData(i)))
			{
				return "Status: empty";
			}
			string text = SlotName(i);
			return "Status: saved" + ((text.Length > 0) ? (" (" + text + ")") : "");
		}

		private static void RefreshStatus(int i)
		{
			try
			{
				if (_slotStatus[i] != null)
				{
					((Element)_slotStatus[i]).ElementName = SlotStatus(i);
				}
			}
			catch (Exception)
			{
			}
		}

		private static void BuildPresets(Page pg)
		{
			//IL_0006: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			Page val = pg.CreatePage("Built-in presets", Color.green, 0, true);
			for (int i = 0; i < Params.BuiltinNames.Length; i++)
			{
				string name = Params.BuiltinNames[i];
				val.CreateFunction(name, Color.green, (Action)delegate
				{
					Params.Deserialize(Params.Builtin(name));
					U.Log("Preset loaded: " + name);
				});
			}
			Page val2 = pg.CreatePage("My presets", Color.cyan, 0, true);
			for (int num = 0; num < 6; num++)
			{
				int s = num;
				Page val3 = val2.CreatePage("Slot " + (s + 1), Color.cyan, 0, true);
				val3.CreateString("Name (rename)", Color.white, SlotName(s), (Action<string>)delegate(string v)
				{
					string text = SlotData(s);
					_slotEnt[s].Value = Clean(v) + "|" + text;
					MarkDirty();
					RefreshStatus(s);
				});
				val3.CreateFunction("Save current settings", Color.green, (Action)delegate
				{
					string text = Clean(SlotName(s));
					if (text.Length == 0)
					{
						text = "Preset " + (s + 1);
					}
					_slotEnt[s].Value = text + "|" + Params.Serialize();
					MarkDirty();
					RefreshStatus(s);
					U.Log("Saved preset slot " + (s + 1) + " (" + text + ").");
				});
				val3.CreateFunction("Load", Color.yellow, (Action)delegate
				{
					string text = SlotData(s);
					if (string.IsNullOrEmpty(text))
					{
						U.Log("Slot " + (s + 1) + " is empty.");
					}
					else
					{
						Params.Deserialize(text);
						U.Log("Loaded preset slot " + (s + 1) + ".");
					}
				});
				val3.CreateFunction("Delete", Color.red, (Action)delegate
				{
					_slotEnt[s].Value = "";
					MarkDirty();
					RefreshStatus(s);
				});
				_slotStatus[s] = val3.CreateFunction(SlotStatus(s), Color.gray, (Action)delegate
				{
				});
			}
		}
	}
	internal sealed class SkyState
	{
		public Vector3 pos;

		public float radius = 500f;

		public Vector3 zen;

		public Vector3 hor;

		public Vector3 gnd;

		public Vector3 sunCol = Vector3.one;

		public Vector3 glowCol = new Vector3(1f, 0.8f, 0.55f);

		public Vector3 moonGlowCol = new Vector3(0.45f, 0.55f, 0.9f);

		public Vector3 flashCol = new Vector3(0.75f, 0.8f, 1f);

		public Vector3 cloudCol = Vector3.one;

		public Vector3 fogCol = new Vector3(0.6f, 0.65f, 0.7f);

		public Vector3 sunDir = Vector3.up;

		public Vector3 moonDir = Vector3.down;

		public float sunGlow;

		public float moonGlow;

		public float sunAlpha;

		public float moonAlpha;

		public float starAlpha;

		public float cloudAmt;

		public float cloudOpacity = 0.92f;

		public float fogAmt;

		public int cloudStyle;

		public float cloudSize = 1f;

		public float cloudHigh = 0.5f;

		public float cloudSoft = 1f;

		public float alpha = 1f;

		public float skyMul = 1f;

		public Vector3 comp = Vector3.one;

		public float flash;

		public float rotation;

		public float skyHour;

		public float windX;

		public float windZ;

		public float dt;
	}
	internal static class SkyDome
	{
		private sealed class Recipe
		{
			public float[] F1;

			public float[] F2;

			public float ThrA = 0.95f;

			public float ThrB = 0.2f;

			public float Edge = 0.25f;

			public float Thick = 0.65f;

			public float Dark1 = 0.42f;

			public float Dark2 = 0.15f;

			public float Op1 = 1f;

			public float Op2 = 0.5f;

			public float L2Base = 0.05f;

			public float L2Gain = 0.75f;
		}

		private const int CloudRes = 192;

		private static GameObject _root;

		private static bool _built;

		private static bool _failed;

		private static bool _visible;

		private static Mesh _domeMesh;

		private static Mesh _starMesh;

		private static Mesh _cloudMesh;

		private static Mesh _sunMesh;

		private static Mesh _moonMesh;

		private static Vector3[] _domeDirs;

		private static Vector3[] _starDirs;

		private static Vector3[] _cloudDirs;

		private static float[] _cloudFade;

		private static Il2CppStructArray<Color32> _domeCol;

		private static Il2CppStructArray<Color32> _starCol;

		private static Il2CppStructArray<Color32> _cloudColArr;

		private static Il2CppStructArray<Color32> _sunColArr;

		private static Il2CppStructArray<Color32> _moonColArr;

		private static Material _domeMat;

		private static Material _starMat;

		private static Material _sunMat;

		private static Material _moonMat;

		private static Material _cloudMat;

		private static MeshRenderer _domeMR;

		private static MeshRenderer _starMR;

		private static MeshRenderer _sunMR;

		private static MeshRenderer _moonMR;

		private static MeshRenderer _cloudMR;

		private static Transform _starT;

		private static Transform _sunT;

		private static Transform _moonT;

		private static Texture2D _cloudTex;

		private static readonly Recipe[] _recipes = new Recipe[7];

		private static float[] _blobNoise;

		private static Il2CppStructArray<Vector2> _uv1;

		private static Il2CppStructArray<Vector2> _uv2;

		private static Vector2[] _baseUv1;

		private static Vector2[] _baseUv2;

		private static float _builtScale = 1f;

		private static float _builtSoft = -1f;

		private static int _builtStyle = -1;

		private static Mesh _cloudMesh2;

		private static Il2CppStructArray<Color32> _cloudColArr2;

		private static Il2CppStructArray<Color32> _cloudPx2;

		private static Texture2D _cloudTex2;

		private static Material _cloudMat2;

		private static MeshRenderer _cloudMR2;

		private static Il2CppStructArray<Color32> _cloudPx;

		private static float _builtCloud = -1f;

		private static float _nextCloudBuild;

		private static float _nextPaint;

		private static float _scrollX;

		private static float _scrollY;

		private static readonly Vector3 PoleAxis = new Vector3(0f, 0.64f, 0.77f);

		private static GameObject AddMesh(string name, Mesh mesh, Material mat, out MeshRenderer mr)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.layer = 2;
			val.transform.SetParent(_root.transform, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			mr = val.AddComponent<MeshRenderer>();
			((Renderer)mr).sharedMaterial = mat;
			((Renderer)mr).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)mr).receiveShadows = false;
			return val;
		}

		private static void Build()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			if (_built || _failed)
			{
				return;
			}
			try
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				_root = new GameObject("WC_Sky");
				_root.layer = 2;
				Object.DontDestroyOnLoad((Object)(object)_root);
				Texture2D tex = U.White();
				_domeMesh = U.MakeDome(64, 40, upperOnly: false, planarUv: false, 0f, 0f, 0f, out _domeDirs, out _domeCol, out var uvArr);
				_domeMat = U.MakeMat((Texture)(object)tex, 2600);
				AddMesh("WC_Dome", _domeMesh, _domeMat, out _domeMR);
				_starMesh = U.MakeDome(64, 32, upperOnly: false, planarUv: false, 0f, 0f, 0f, out _starDirs, out _starCol, out uvArr);
				_starMat = U.MakeMat((Texture)(object)MakeStarTex(), 2601);
				_starT = AddMesh("WC_Stars", _starMesh, _starMat, out _starMR).transform;
				_sunMesh = U.MakeQuad(out _sunColArr);
				_sunMat = U.MakeMat((Texture)(object)MakeSunTex(), 2602);
				_sunT = AddMesh("WC_Sun", _sunMesh, _sunMat, out _sunMR).transform;
				_moonMesh = U.MakeQuad(out _moonColArr);
				_moonMat = U.MakeMat((Texture)(object)MakeMoonTex(), 2603);
				_moonT = AddMesh("WC_Moon", _moonMesh, _moonMat, out _moonMR).transform;
				_cloudMesh = U.MakeDome(64, 24, upperOnly: true, planarUv: true, 0.8f, 0.1f, 0f, out _cloudDirs, out _cloudColArr, out _uv1);
				_cloudMesh2 = U.MakeDome(64, 24, upperOnly: true, planarUv: true, 1.1f, 0.3f, 37f, out var _, out _cloudColArr2, out _uv2);
				_baseUv1 = (Vector2[])(object)new Vector2[((Il2CppArrayBase<Vector2>)(object)_uv1).Length];
				_baseUv2 = (Vector2[])(object)new Vector2[((Il2CppArrayBase<Vector2>)(object)_uv2).Length];
				for (int i = 0; i < _baseUv1.Length; i++)
				{
					_baseUv1[i] = ((Il2CppArrayBase<Vector2>)(object)_uv1)[i];
					_baseUv2[i] = ((Il2CppArrayBase<Vector2>)(object)_uv2)[i];
				}
				_cloudFade = new float[_cloudDirs.Length];
				for (int j = 0; j < _cloudFade.Length; j++)
				{
					_cloudFade[j] = U.Sm(0.02f, 0.22f, _cloudDirs[j].y);
				}
				_cloudPx = new Il2CppStructArray<Color32>(36864L);
				_cloudPx2 = new Il2CppStructArray<Color32>(36864L);
				_cloudTex = U.MakeTex(192, 192, _cloudPx, (TextureWrapMode)0);
				_cloudTex2 = U.MakeTex(192, 192, _cloudPx2, (TextureWrapMode)0);
				_cloudMat = U.MakeMat((Texture)(object)_cloudTex, 2604);
				_cloudMat2 = U.MakeMat((Texture)(object)_cloudTex2, 2603);
				AddMesh("WC_CloudsHigh", _cloudMesh2, _cloudMat2, out _cloudMR2);
				AddMesh("WC_Clouds", _cloudMesh, _cloudMat, out _cloudMR);
				_built = true;
				_visible = true;
				U.Log("Sky built in " + ((Time.realtimeSinceStartup - realtimeSinceStartup) * 1000f).ToString("0") + " ms.");
			}
			catch (Exception ex)
			{
				_failed = true;
				U.Err("Sky build failed: " + ex);
			}
		}

		private static Texture2D MakeStarTex()
		{
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = new byte[524288];
			byte[] array2 = new byte[524288];
			byte[] array3 = new byte[524288];
			byte[] array4 = new byte[524288];
			Rng rng = new Rng(4242);
			for (int i = 0; i < 2300; i++)
			{
				float num = rng.Next() * 2f - 1f;
				float num2 = rng.Next();
				float num3 = Mathf.Asin(num);
				float num4 = num2 * 1024f;
				float num5 = (num3 / (float)Math.PI + 0.5f) * 512f;
				float num6 = Mathf.Pow(rng.Next(), 3f);
				float num7 = 0.35f + 0.65f * num6;
				float num8 = 0.7f + 1.5f * num6;
				float num9 = Mathf.Max(0.15f, Mathf.Cos(num3));
				float num10 = Mathf.Min(40f, num8 / num9);
				float num11 = rng.Next();
				byte b = byte.MaxValue;
				byte b2 = byte.MaxValue;
				byte b3 = byte.MaxValue;
				if (num11 < 0.25f)
				{
					b = 190;
					b2 = 210;
					b3 = byte.MaxValue;
				}
				else if (num11 > 0.85f)
				{
					b = byte.MaxValue;
					b2 = 225;
					b3 = 190;
				}
				int num12 = (int)Mathf.Ceil(num10 + 1f);
				int num13 = (int)Mathf.Ceil(num8 + 1f);
				for (int j = -num13; j <= num13; j++)
				{
					int num14 = (int)num5 + j;
					if (num14 < 0 || num14 >= 512)
					{
						continue;
					}
					for (int k = -num12; k <= num12; k++)
					{
						float num15 = (float)k / num10;
						float num16 = (float)j / num8;
						float num17 = num15 * num15 + num16 * num16;
						if (!(num17 > 1.4f))
						{
							float num18 = Mathf.Exp((0f - num17) * 2.2f) * num7;
							int num19 = ((int)num4 + k) % 1024;
							if (num19 < 0)
							{
								num19 += 1024;
							}
							int num20 = num14 * 1024 + num19;
							byte b4 = (byte)Mathf.Clamp(Mathf.RoundToInt(num18 * 255f), 0, 255);
							if (b4 > array[num20])
							{
								array[num20] = b4;
								array2[num20] = b;
								array3[num20] = b2;
								array4[num20] = b3;
							}
						}
					}
				}
			}
			Il2CppStructArray<Color32> val = new Il2CppStructArray<Color32>(524288L);
			for (int l = 0; l < 524288; l++)
			{
				(