Decompiled source of LightGreen v0.1.0

LightGreen.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Game.Rendering.Fog;
using HTraceAO.Rendering.Shared.Globals;
using HTraceAO.Rendering.URP.Infrastructure;
using HarmonyLib;
using LightGreen.Core;
using LightGreen.Presets;
using LightGreen.Systems;
using Mirror;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.RenderGraphModule;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LightGreen")]
[assembly: AssemblyDescription("Lighting, atmosphere and weather for Super Battle Golf that keep its cel-shaded look. Client-side: only you need it.")]
[assembly: AssemblyProduct("LightGreen")]
[assembly: AssemblyCompany("lmkHenlo")]
[assembly: AssemblyCopyright("Copyright (c) 2026 lmkHenlo")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace LightGreen
{
	internal enum AOQuality
	{
		Low,
		Medium,
		High
	}
	internal static class Settings
	{
		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<Key> ToggleKey;

		internal static ConfigEntry<Key> TimeKey;

		internal static ConfigEntry<TimeOfDay> Time;

		internal static ConfigEntry<float> ProgressionMinutes;

		internal static ConfigEntry<float> TransitionSeconds;

		internal static ConfigEntry<float> ShadowTint;

		internal static ConfigEntry<float> ColorGrading;

		internal static ConfigEntry<float> DistanceHaze;

		internal static ConfigEntry<float> LensFlare;

		internal static ConfigEntry<float> WaterTuning;

		internal static ConfigEntry<float> IceGlints;

		internal static ConfigEntry<float> TiltShift;

		internal static ConfigEntry<float> PhotoDepthOfField;

		internal static ConfigEntry<float> Vignette;

		internal static ConfigEntry<float> ChromaticAberration;

		internal static ConfigEntry<float> AmbientOcclusion;

		internal static ConfigEntry<float> EffectLights;

		internal static ConfigEntry<float> BallGlow;

		internal static ConfigEntry<bool> BallGlowOwnOnly;

		internal static ConfigEntry<float> Lightning;

		internal static ConfigEntry<float> CityNight;

		internal static ConfigEntry<float> Rain;

		internal static ConfigEntry<float> Footprints;

		internal static ConfigEntry<float> FootprintSeconds;

		internal static ConfigEntry<int> FootprintMax;

		internal static ConfigEntry<bool> Grass;

		internal static ConfigEntry<int> SunShadowResolution;

		internal static ConfigEntry<float> SunShadowDistance;

		internal static ConfigEntry<AOQuality> AmbientOcclusionQuality;

		private static readonly AcceptableValueRange<float> Strength = new AcceptableValueRange<float>(0f, 2f);

		private static readonly ConfigDefinition[] Removed = (ConfigDefinition[])(object)new ConfigDefinition[3]
		{
			new ConfigDefinition("Effects", "FilmGrain"),
			new ConfigDefinition("Quality", "AmbientOcclusionIgnoresGrass"),
			new ConfigDefinition("Effects", "Snowfall")
		};

		internal static void Bind(ConfigFile config)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Expected O, but got Unknown
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Expected O, but got Unknown
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Expected O, but got Unknown
			Enabled = config.Bind<bool>("General", "Enabled", true, "Turns LightGreen on. Off: the game looks exactly as it does without the mod.");
			ToggleKey = config.Bind<Key>("Keys", "ToggleKey", (Key)101, "Switches LightGreen off and on while playing, to compare with the game's own look.");
			TimeKey = config.Bind<Key>("Keys", "TimeKey", (Key)102, "Steps through the times of day (it changes TimeOfDay.Time).");
			Time = config.Bind<TimeOfDay>("TimeOfDay", "Time", TimeOfDay.HoleDefault, "HoleDefault keeps each hole's own sun and sky. Dawn, Morning, Noon, GoldenHour, Sunset, BlueHour and Night move the sun and recolour the sky, light, haze and water. Only you see it; nothing is sent to other players.");
			ProgressionMinutes = config.Bind<float>("TimeOfDay", "ProgressionMinutes", 0f, new ConfigDescription("Minutes for a full day (Dawn through Night and round again). 0 = the time stays put.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 240f), Array.Empty<object>()));
			TransitionSeconds = config.Bind<float>("TimeOfDay", "TransitionSeconds", 3f, new ConfigDescription("How long a change of time of day takes to blend in.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
			ShadowTint = Effect(config, "ShadowTint", 1f, "Shadows lean toward the biome's hue (cool in Snow, warm in Desert).");
			ColorGrading = Effect(config, "ColorGrading", 1f, "Per-biome and time-of-day white balance, saturation and contrast.");
			DistanceHaze = Effect(config, "DistanceHaze", 1f, "Distant terrain fades toward the horizon colour.");
			LensFlare = Effect(config, "LensFlare", 1f, "Streaks and ghosts when looking toward a low sun. Off in VR.");
			WaterTuning = Effect(config, "WaterTuning", 1f, "Sun highlights on water, and water that follows the time of day.");
			IceGlints = Effect(config, "IceGlints", 1f, "Sparkle on snow terrain. Halved in VR.");
			TiltShift = Effect(config, "TiltShift", 1f, "The hole-overview flyover looks like a miniature. Off in VR.");
			PhotoDepthOfField = Effect(config, "PhotoDepthOfField", 1f, "Photo mode focuses on what's in the middle of the frame and softens the rest. Off in VR.");
			Vignette = Effect(config, "Vignette", 0f, "Darker screen corners, on top of the course's own. Off in VR.");
			ChromaticAberration = Effect(config, "ChromaticAberration", 0f, "Colour fringes at the screen edges. Off in VR.");
			AmbientOcclusion = Effect(config, "AmbientOcclusion", 1f, "Soft darkening where surfaces meet: under and around objects, in corners and crevices. Uses the game's own ambient occlusion (HTrace AO), turned on for every course, with the grass blades left out so open grass stays even. Off in VR.");
			EffectLights = Effect(config, "EffectLights", 1f, "Explosions light the ground and players around them for a moment (the big ones with shadows), muzzle flashes pop, and rocket and freeze-bomb trails carry a light. Gentler with the game's Explosion flashes option off. Needs the game's Dynamic Lighting setting on.");
			BallGlow = Effect(config, "BallGlow", 1f, "Balls glow evenly all over in the dark, your own the brightest, so they stay easy to find at night. Off in daylight.");
			BallGlowOwnOnly = config.Bind<bool>("Effects", "BallGlowOwnOnly", false, "Only your own ball glows (a calmer scene in a crowded lobby).");
			Lightning = Effect(config, "Lightning", 1f, "The Thunderstorm item's lightning lights where it lands (with a shadow) and the ground for a long way round, flickering two or three times. With the game's Explosion flashes option off, and in VR, it is one gentle pulse instead. Needs the game's Dynamic Lighting setting on.");
			CityNight = Effect(config, "CityNight", 1f, "City holes at night, as the game's own night City holes look: building windows and vehicle lights glow, lampposts light the street (the nearest with shadows), and bright light blooms. Follows how dark it is; nothing by day. The lampposts need the game's Dynamic Lighting setting on.");
			Rain = Effect(config, "Rain", 0f, "Rain on every course: streaks, splashes where it lands, and a grey overcast sky. Surfaces don't get wet. Off by default: it's only a look, and could be mistaken for the Thunderstorm item. The value is how heavy.");
			Footprints = Effect(config, "Footprints", 1f, "Footprints in snow last longer (Effects.FootprintSeconds) and show as blue-grey dents that read on white, fading out at the end. Sand keeps the game's prints, and so does a player a smoke bomb hides from you. The value is how dark the prints are.");
			FootprintSeconds = config.Bind<float>("Effects", "FootprintSeconds", 45f, new ConfigDescription("How long a footprint in snow lasts, in seconds (the game's last about 2).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 180f), Array.Empty<object>()));
			FootprintMax = config.Bind<int>("Effects", "FootprintMax", 300, new ConfigDescription("How many footprints in snow there can be at once; past it the oldest fade out. Lower it for big lobbies on a slower PC.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 2000), Array.Empty<object>()));
			Grass = config.Bind<bool>("Shading", "Grass", true, "Draws the game's grass blades. false hides them: the terrain's own colour shows instead, and drawing the grass costs nothing. The grass comes back with LightGreen off (ToggleKey).");
			SunShadowResolution = config.Bind<int>("Quality", "SunShadowResolution", 4096, new ConfigDescription("Sun shadow map size in pixels: sharper shadows. 0 = the game's setting.", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[4] { 0, 2048, 4096, 8192 }), Array.Empty<object>()));
			SunShadowDistance = config.Bind<float>("Quality", "SunShadowDistance", 200f, new ConfigDescription("How far away (metres) the sun still casts shadows. 0 = the game's setting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>()));
			AmbientOcclusionQuality = config.Bind<AOQuality>("Quality", "AmbientOcclusionQuality", AOQuality.Medium, "Ambient occlusion detail. Low: quarter resolution, cheapest. Medium: half resolution. High: full resolution.");
			DropRemovedSettings(config);
		}

		private static void DropRemovedSettings(ConfigFile config)
		{
			try
			{
				Dictionary<ConfigDefinition, string> value = Traverse.Create((object)config).Property("OrphanedEntries", (object[])null).GetValue<Dictionary<ConfigDefinition, string>>();
				if (value != null)
				{
					bool flag = false;
					ConfigDefinition[] removed = Removed;
					foreach (ConfigDefinition key in removed)
					{
						flag |= value.Remove(key);
					}
					if (flag)
					{
						config.Save();
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Couldn't tidy removed settings from the config file: " + ex.Message));
				}
			}
		}

		private static ConfigEntry<float> Effect(ConfigFile config, string key, float value, string description)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			return config.Bind<float>("Effects", key, value, new ConfigDescription(description + " 0 = off, 1 = tuned, 2 = double.", (AcceptableValueBase)(object)Strength, Array.Empty<object>()));
		}
	}
	[BepInPlugin("com.lightgreen", "LightGreen", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.lightgreen";

		public const string Name = "LightGreen";

		public const string Version = "0.1.0";

		internal const string ExpectedUnity = "6000.3.27f2";

		internal static ManualLogSource Log;

		private readonly FeatureHost _features = new FeatureHost();

		private readonly EnvironmentController _environment = new EnvironmentController();

		private readonly SunShadows _shadows = new SunShadows();

		private readonly AmbientOcclusion _occlusion = new AmbientOcclusion();

		private readonly LightPool _lightPool = new LightPool();

		private MaterialTuner _materials;

		private VolumeLayer _volumes;

		private CityNight _cityNight;

		private Rain _rain;

		private readonly Footprints _footprints = new Footprints();

		private Harmony _harmony;

		private bool _comparing;

		private float _nextConfigCheck;

		private DateTime _configWriteTime;

		private string _notice;

		private float _noticeUntil;

		private GUIStyle _noticeStyle;

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

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Settings.Bind(((BaseUnityPlugin)this).Config);
			PresetStore.Load(Log);
			GameEvents.Hook(Log);
			_harmony = new Harmony("com.lightgreen");
			_materials = new MaterialTuner(_environment);
			_volumes = new VolumeLayer(_environment);
			_features.Add(_environment);
			_features.Add(_volumes);
			_features.Add(_materials);
			_features.Add(_shadows);
			_features.Add(_occlusion);
			_features.Add(new GrassToggle());
			_cityNight = new CityNight(_lightPool, _environment);
			_features.Add(new EffectLights(_lightPool));
			_features.Add(new LightningLights(_lightPool));
			_features.Add(_cityNight);
			_features.Add(new BallGlow(_environment));
			_features.Add(_lightPool);
			_rain = new Rain(_environment);
			_features.Add(_rain);
			_features.Add(_footprints);
			new PatchModule(typeof(EffectLights.PlayedPatch), "Hook: Effects played").TryApply(_harmony, Log);
			new PatchModule(typeof(LightningLights.StrikePatch), "Hook: Lightning strikes").TryApply(_harmony, Log);
			new PatchModule(typeof(Footprints.StepPatch), "Hook: Footsteps").TryApply(_harmony, Log);
			new PatchModule(typeof(Footprints.EffectPatch), "Hook: Footprint effects").TryApply(_harmony, Log);
			GrassToggle.Hooked = new PatchModule(typeof(GrassToggle.DrawPatch), "Hook: Grass drawing").TryApply(_harmony, Log);
			GrassFreeDepth.GrassHooked = new PatchModule(typeof(GrassFreeDepth.GrassPatch), "Hook: Grass material").TryApply(_harmony, Log);
			GrassFreeDepth.HTraceHooked = new PatchModule(typeof(GrassFreeDepth.HTracePatch), "Hook: Ambient occlusion depth").TryApply(_harmony, Log);
			GameEvents.BiomeChanged += delegate(Biome biome)
			{
				Log.LogInfo((object)$"Biome: {biome}.");
				ForgetLogged("hole:");
				_materials.Rescan(announce: true);
				_cityNight.Rescan();
				_rain.Rescan();
			};
			GameEvents.HoleChanged += delegate
			{
				_materials.Rescan();
				_cityNight.Rescan();
				_rain.Rescan();
				_footprints.Clear();
			};
			GameEvents.GraphicsSettingsApplied += _shadows.OnGameApplied;
			PresetStore.Reloaded += _environment.OnPresetsReloaded;
			Settings.Time.SettingChanged += delegate
			{
				Notify($"Time of day: {Settings.Time.Value}");
			};
			if (Application.unityVersion != "6000.3.27f2")
			{
				Log.LogWarning((object)("The game runs Unity " + Application.unityVersion + "; this LightGreen was made for 6000.3.27f2 (Super Battle Golf 1.4.0). The game may have updated: some effects may not work until LightGreen does too."));
			}
			Settings.Enabled.SettingChanged += delegate
			{
				Log.LogInfo((object)(Settings.Enabled.Value ? "Enabled." : "Disabled (General.Enabled = false): the game's own look."));
			};
			Log.LogInfo((object)("LightGreen 0.1.0 loaded: " + Application.productName + " " + Application.version + ", Unity " + Application.unityVersion + ". " + $"{_features.Count} features. {Settings.ToggleKey.Value} compares with the game's own look, " + $"{Settings.TimeKey.Value} changes the time of day." + (Settings.Enabled.Value ? "" : " (Off: General.Enabled = false.)")));
		}

		private void Update()
		{
			ReloadConfigIfEdited();
			PresetStore.Poll();
			Vr.Poll();
			ReadKeys();
			if (Settings.Enabled.Value && !_comparing)
			{
				_features.Apply();
			}
			else
			{
				_features.Restore();
			}
		}

		private void ReadKeys()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current != null && Settings.Enabled.Value)
			{
				if (Pressed(current, Settings.ToggleKey.Value))
				{
					_comparing = !_comparing;
					string text = (_comparing ? "off (the game's own look)" : "on");
					Log.LogInfo((object)text);
					Notify(text);
				}
				if (Pressed(current, Settings.TimeKey.Value) && !_comparing)
				{
					EnvironmentController.StepTime();
					_configWriteTime = File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
					Log.LogInfo((object)$"Time of day: {Settings.Time.Value}");
				}
			}
		}

		internal static void LogChange(string key, string message)
		{
			if (!Logged.TryGetValue(key, out var value) || !(value == message))
			{
				Logged[key] = message;
				Log.LogInfo((object)message);
			}
		}

		private static void ForgetLogged(string prefix)
		{
			foreach (string item in new List<string>(Logged.Keys))
			{
				if (item.StartsWith(prefix, StringComparison.Ordinal))
				{
					Logged.Remove(item);
				}
			}
		}

		private static bool Pressed(Keyboard keyboard, Key key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if ((int)key == 0)
			{
				return false;
			}
			try
			{
				return ((ButtonControl)keyboard[key]).wasPressedThisFrame;
			}
			catch (ArgumentException)
			{
				return false;
			}
		}

		private void ReloadConfigIfEdited()
		{
			if (Time.unscaledTime < _nextConfigCheck)
			{
				return;
			}
			_nextConfigCheck = Time.unscaledTime + 1f;
			try
			{
				DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
				if (_configWriteTime == default(DateTime))
				{
					_configWriteTime = lastWriteTimeUtc;
				}
				else if (!(lastWriteTimeUtc == _configWriteTime))
				{
					((BaseUnityPlugin)this).Config.Reload();
					_configWriteTime = File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
					Log.LogInfo((object)"Config reloaded.");
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Couldn't reload the config: " + ex.Message));
			}
		}

		private void Notify(string text)
		{
			_notice = text;
			_noticeUntil = Time.unscaledTime + 2.5f;
		}

		private void OnGUI()
		{
			//IL_00b1: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if (_notice != null && !(Time.unscaledTime > _noticeUntil))
			{
				float num = (float)Screen.height / 1080f;
				if (_noticeStyle == null)
				{
					_noticeStyle = new GUIStyle(GUI.skin.label)
					{
						fontStyle = (FontStyle)1
					};
				}
				_noticeStyle.fontSize = Mathf.RoundToInt(22f * num);
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(24f * num, 24f * num, 900f * num, 40f * num);
				string text = "LightGreen: " + _notice;
				_noticeStyle.normal.textColor = new Color(0f, 0f, 0f, 0.7f);
				GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text, _noticeStyle);
				_noticeStyle.normal.textColor = Color.white;
				GUI.Label(val, text, _noticeStyle);
			}
		}

		private void OnDestroy()
		{
			_features.RestoreAll();
			_volumes?.Destroy();
			_occlusion.Destroy();
			_lightPool.Destroy();
			_rain?.Destroy();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			GameEvents.Unhook();
		}
	}
	internal static class Vr
	{
		private static readonly List<XRDisplaySubsystem> Displays = new List<XRDisplaySubsystem>();

		private static int _checkedFrame = -1;

		private static bool _running;

		private static bool _loggedRunning;

		internal static bool IsRunning
		{
			get
			{
				if (_checkedFrame == Time.frameCount)
				{
					return _running;
				}
				_checkedFrame = Time.frameCount;
				SubsystemManager.GetSubsystems<XRDisplaySubsystem>(Displays);
				_running = false;
				foreach (XRDisplaySubsystem display in Displays)
				{
					if (display != null && ((IntegratedSubsystem)display).running)
					{
						_running = true;
						break;
					}
				}
				if (_running != _loggedRunning)
				{
					_loggedRunning = _running;
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)(_running ? "VR is running: lens effects off, ice glints halved." : "VR stopped."));
					}
				}
				return _running;
			}
		}

		internal static void Poll()
		{
			_ = IsRunning;
		}
	}
}
namespace LightGreen.Core
{
	internal enum Biome
	{
		None,
		DrivingRange,
		Coast,
		Forest,
		Desert,
		Snow,
		City,
		Unknown
	}
	internal static class BiomeDetection
	{
		internal static Biome FromLoadedScenes()
		{
			//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)
			Biome result = Biome.None;
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				if (((Scene)(ref sceneAt)).isLoaded)
				{
					Biome biome = FromScenePath(((Scene)(ref sceneAt)).path);
					switch (biome)
					{
					default:
						return biome;
					case Biome.DrivingRange:
						result = biome;
						break;
					case Biome.None:
						break;
					}
				}
			}
			return result;
		}

		internal static Biome FromScenePath(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return Biome.None;
			}
			if (path.EndsWith("/Driving range.unity", StringComparison.OrdinalIgnoreCase))
			{
				return Biome.DrivingRange;
			}
			int num = path.IndexOf("/Holes/", StringComparison.Ordinal);
			if (num < 0)
			{
				return Biome.None;
			}
			num += "/Holes/".Length;
			int num2 = path.IndexOf('/', num);
			if (num2 < 0)
			{
				return Biome.None;
			}
			return path.Substring(num, num2 - num) switch
			{
				"Coast" => Biome.Coast, 
				"Forest" => Biome.Forest, 
				"Desert" => Biome.Desert, 
				"Snow" => Biome.Snow, 
				"City" => Biome.City, 
				_ => Biome.Unknown, 
			};
		}
	}
	internal static class GameWind
	{
		internal static Vector2 Direction
		{
			get
			{
				//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_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_002f: 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)
				Vector3 currentWindDirection = WindManager.CurrentWindDirection;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(currentWindDirection.x, currentWindDirection.z);
				if (!(((Vector2)(ref val)).sqrMagnitude > 1E-06f))
				{
					return Vector2.zero;
				}
				return ((Vector2)(ref val)).normalized;
			}
		}

		internal static float SpeedKmh
		{
			get
			{
				//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)
				if (!(Direction == Vector2.zero))
				{
					return Mathf.Max(0f, (float)WindManager.CurrentWindSpeed);
				}
				return 0f;
			}
		}
	}
	internal sealed class MaterialEdits
	{
		private sealed class Stock
		{
			internal readonly Dictionary<string, bool> Keywords = new Dictionary<string, bool>();

			internal readonly Dictionary<string, float> Floats = new Dictionary<string, float>();

			internal readonly Dictionary<string, Color> Colors = new Dictionary<string, Color>();

			internal readonly Dictionary<string, Vector4> Vectors = new Dictionary<string, Vector4>();
		}

		private readonly Dictionary<Material, Stock> _stock = new Dictionary<Material, Stock>();

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

		private readonly Dictionary<string, Dictionary<Vector4, Vector4>> _vectorOrigins = new Dictionary<string, Dictionary<Vector4, Vector4>>();

		private readonly Dictionary<string, Dictionary<float, float>> _floatOrigins = new Dictionary<string, Dictionary<float, float>>();

		internal int Count => _stock.Count;

		private Stock For(Material m)
		{
			if (!_stock.TryGetValue(m, out var value))
			{
				value = (_stock[m] = new Stock());
			}
			return value;
		}

		internal bool StockKeyword(Material m, string keyword)
		{
			Stock stock = For(m);
			if (!stock.Keywords.TryGetValue(keyword, out var value))
			{
				value = (stock.Keywords[keyword] = m.IsKeywordEnabled(keyword));
			}
			return value;
		}

		private static bool IsInteger(Material m, string property)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			Shader shader = m.shader;
			if ((Object)(object)shader == (Object)null)
			{
				return false;
			}
			int num = shader.FindPropertyIndex(property);
			if (num >= 0)
			{
				return (int)shader.GetPropertyType(num) == 5;
			}
			return false;
		}

		private static float ReadFloat(Material m, string property)
		{
			if (!IsInteger(m, property))
			{
				return m.GetFloat(property);
			}
			return m.GetInteger(property);
		}

		private static void WriteFloat(Material m, string property, float value)
		{
			if (IsInteger(m, property))
			{
				m.SetInteger(property, Mathf.RoundToInt(value));
			}
			else
			{
				m.SetFloat(property, value);
			}
		}

		internal float StockFloat(Material m, string property)
		{
			Stock stock = For(m);
			if (!stock.Floats.TryGetValue(property, out var value))
			{
				value = (stock.Floats[property] = ReadFloat(m, property));
			}
			return value;
		}

		internal Color StockColor(Material m, string property)
		{
			//IL_002d: 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_0026: 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)
			Stock stock = For(m);
			if (!stock.Colors.TryGetValue(property, out var value))
			{
				value = (stock.Colors[property] = m.GetColor(property));
			}
			return value;
		}

		internal Vector4 StockVector(Material m, string property)
		{
			//IL_002d: 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_0026: 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)
			Stock stock = For(m);
			if (!stock.Vectors.TryGetValue(property, out var value))
			{
				value = (stock.Vectors[property] = m.GetVector(property));
			}
			return value;
		}

		internal void SetKeyword(Material m, string keyword, bool on)
		{
			StockKeyword(m, keyword);
			if (m.IsKeywordEnabled(keyword) != on)
			{
				if (on)
				{
					m.EnableKeyword(keyword);
				}
				else
				{
					m.DisableKeyword(keyword);
				}
			}
		}

		internal void SetFloat(Material m, string property, float value)
		{
			if (m.HasProperty(property))
			{
				float num = StockFloat(m, property);
				if (value != num)
				{
					Remember(_floatOrigins, property, value, num);
				}
				WriteFloat(m, property, value);
			}
		}

		internal void SetColor(Material m, string property, Color value)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0014: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(property))
			{
				Color val = StockColor(m, property);
				if (value != val)
				{
					Remember(_colorOrigins, property, value, val);
				}
				m.SetColor(property, value);
			}
		}

		internal void SetVector(Material m, string property, Vector4 value)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0014: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(property))
			{
				Vector4 val = StockVector(m, property);
				if (value != val)
				{
					Remember(_vectorOrigins, property, value, val);
				}
				m.SetVector(property, value);
			}
		}

		private static void Remember<T>(Dictionary<string, Dictionary<T, T>> origins, string property, T value, T stock)
		{
			if (!origins.TryGetValue(property, out var value2))
			{
				value2 = (origins[property] = new Dictionary<T, T>());
			}
			if (value2.Count > 4096)
			{
				value2.Clear();
			}
			value2[value] = stock;
		}

		private static bool Origin<T>(Dictionary<string, Dictionary<T, T>> origins, string property, T value, out T stock)
		{
			stock = default(T);
			if (origins.TryGetValue(property, out var value2))
			{
				return value2.TryGetValue(value, out stock);
			}
			return false;
		}

		internal bool IsTracked(Material m)
		{
			return _stock.ContainsKey(m);
		}

		internal bool AdoptColor(Material m, string property)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!m.HasProperty(property))
			{
				return false;
			}
			Stock stock = For(m);
			if (stock.Colors.ContainsKey(property))
			{
				return false;
			}
			if (!Origin(_colorOrigins, property, m.GetColor(property), out var stock2))
			{
				return false;
			}
			stock.Colors[property] = stock2;
			return true;
		}

		internal bool AdoptVector(Material m, string property)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!m.HasProperty(property))
			{
				return false;
			}
			Stock stock = For(m);
			if (stock.Vectors.ContainsKey(property))
			{
				return false;
			}
			if (!Origin(_vectorOrigins, property, m.GetVector(property), out var stock2))
			{
				return false;
			}
			stock.Vectors[property] = stock2;
			return true;
		}

		internal bool AdoptFloat(Material m, string property)
		{
			if (!m.HasProperty(property))
			{
				return false;
			}
			Stock stock = For(m);
			if (stock.Floats.ContainsKey(property))
			{
				return false;
			}
			if (!Origin(_floatOrigins, property, ReadFloat(m, property), out var stock2))
			{
				return false;
			}
			stock.Floats[property] = stock2;
			return true;
		}

		internal void AdoptKeyword(Material m, string keyword, bool stock)
		{
			Stock stock2 = For(m);
			if (!stock2.Keywords.ContainsKey(keyword))
			{
				stock2.Keywords[keyword] = stock;
			}
		}

		internal void ForgetDestroyed()
		{
			foreach (Material item in _stock.Keys.Where((Material m) => (Object)(object)m == (Object)null).ToList())
			{
				_stock.Remove(item);
			}
		}

		internal void Restore()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<Material, Stock> item in _stock)
			{
				Material key = item.Key;
				if ((Object)(object)key == (Object)null)
				{
					continue;
				}
				Stock value = item.Value;
				foreach (KeyValuePair<string, float> @float in value.Floats)
				{
					WriteFloat(key, @float.Key, @float.Value);
				}
				foreach (KeyValuePair<string, Color> color in value.Colors)
				{
					key.SetColor(color.Key, color.Value);
				}
				foreach (KeyValuePair<string, Vector4> vector in value.Vectors)
				{
					key.SetVector(vector.Key, vector.Value);
				}
				foreach (KeyValuePair<string, bool> keyword in value.Keywords)
				{
					if (key.IsKeywordEnabled(keyword.Key) != keyword.Value)
					{
						if (keyword.Value)
						{
							key.EnableKeyword(keyword.Key);
						}
						else
						{
							key.DisableKeyword(keyword.Key);
						}
					}
				}
			}
			_stock.Clear();
		}
	}
	internal sealed class PatchModule
	{
		internal readonly Type Type;

		internal readonly string Label;

		internal PatchModule(Type type, string label)
		{
			Type = type;
			Label = label;
		}

		internal bool TryApply(Harmony harmony, ManualLogSource log)
		{
			try
			{
				List<MethodInfo> list = harmony.CreateClassProcessor(Type).Patch();
				if (list == null || list.Count == 0)
				{
					log.LogError((object)("[FAILED] " + Label + ": no game method to patch"));
					return false;
				}
				log.LogInfo((object)("[ok] " + Label));
				return true;
			}
			catch (Exception arg)
			{
				log.LogError((object)$"[FAILED] {Label}: {arg}");
				return false;
			}
		}
	}
	internal interface IFeature
	{
		string Name { get; }

		void Apply();

		void Restore();
	}
	internal sealed class FeatureHost
	{
		private readonly List<IFeature> _features = new List<IFeature>();

		private readonly HashSet<IFeature> _failed = new HashSet<IFeature>();

		private bool _applied;

		internal int Count => _features.Count;

		internal void Add(IFeature feature)
		{
			_features.Add(feature);
		}

		internal void Apply()
		{
			_applied = true;
			foreach (IFeature feature in _features)
			{
				if (!_failed.Contains(feature))
				{
					try
					{
						feature.Apply();
					}
					catch (Exception arg)
					{
						_failed.Add(feature);
						Plugin.Log.LogError((object)($"[FAILED] {feature.Name}: {arg}\n{feature.Name} is off until the game restarts; " + "the rest of LightGreen carries on."));
						Restore(feature);
					}
				}
			}
		}

		internal void Restore()
		{
			if (!_applied)
			{
				return;
			}
			_applied = false;
			foreach (IFeature feature in _features)
			{
				Restore(feature);
			}
		}

		internal void RestoreAll()
		{
			_applied = false;
			foreach (IFeature feature in _features)
			{
				Restore(feature);
			}
		}

		private static void Restore(IFeature feature)
		{
			try
			{
				feature.Restore();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)(feature.Name + " couldn't put the game back as it was: " + ex.Message));
			}
		}
	}
	internal static class GameEvents
	{
		private static readonly List<Action> Unhooks = new List<Action>();

		private static ManualLogSource _log;

		internal static Biome CurrentBiome { get; private set; } = Biome.None;

		internal static bool InHole => CurrentBiome != Biome.None;

		internal static event Action<Biome> BiomeChanged;

		internal static event Action HoleChanged;

		internal static event Action GraphicsSettingsApplied;

		internal static event Action CameraModuleChanged;

		internal static void Hook(ManualLogSource log)
		{
			_log = log;
			TryHook("Scenes loaded", delegate
			{
				SceneManager.sceneLoaded += OnSceneLoaded;
				SceneManager.sceneUnloaded += OnSceneUnloaded;
				Unhooks.Add(delegate
				{
					SceneManager.sceneLoaded -= OnSceneLoaded;
					SceneManager.sceneUnloaded -= OnSceneUnloaded;
				});
			});
			TryHook("Hole changed", delegate
			{
				CourseManager.CurrentHoleGlobalIndexChanged += OnHoleChanged;
				Unhooks.Add(delegate
				{
					CourseManager.CurrentHoleGlobalIndexChanged -= OnHoleChanged;
				});
			});
			TryHook("Graphics settings applied", delegate
			{
				GraphicsSettings.OnGraphicsQualityApply += OnGraphicsApplied;
				Unhooks.Add(delegate
				{
					GraphicsSettings.OnGraphicsQualityApply -= OnGraphicsApplied;
				});
			});
			TryHook("Camera mode changed", delegate
			{
				CameraModuleController.ModuleTypeChanged += OnCameraModuleChanged;
				Unhooks.Add(delegate
				{
					CameraModuleController.ModuleTypeChanged -= OnCameraModuleChanged;
				});
			});
			UpdateBiome();
		}

		internal static void Unhook()
		{
			foreach (Action unhook in Unhooks)
			{
				try
				{
					unhook();
				}
				catch
				{
				}
			}
			Unhooks.Clear();
		}

		private static void TryHook(string label, Action hook)
		{
			try
			{
				hook();
				_log.LogInfo((object)("[ok] Hook: " + label));
			}
			catch (Exception ex)
			{
				_log.LogError((object)("[FAILED] Hook: " + label + ": " + ex.GetType().Name + ": " + ex.Message));
			}
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			UpdateBiome();
		}

		private static void OnSceneUnloaded(Scene scene)
		{
			UpdateBiome();
		}

		private static void OnHoleChanged()
		{
			UpdateBiome();
			Raise(GameEvents.HoleChanged, "HoleChanged");
		}

		private static void OnGraphicsApplied()
		{
			Raise(GameEvents.GraphicsSettingsApplied, "GraphicsSettingsApplied");
		}

		private static void OnCameraModuleChanged()
		{
			Raise(GameEvents.CameraModuleChanged, "CameraModuleChanged");
		}

		private static void UpdateBiome()
		{
			Biome biome = BiomeDetection.FromLoadedScenes();
			if (biome == CurrentBiome)
			{
				return;
			}
			CurrentBiome = biome;
			Action<Biome> biomeChanged = GameEvents.BiomeChanged;
			if (biomeChanged == null)
			{
				return;
			}
			Delegate[] invocationList = biomeChanged.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<Biome> action = (Action<Biome>)invocationList[i];
				try
				{
					action(biome);
				}
				catch (Exception arg)
				{
					_log.LogError((object)$"BiomeChanged handler failed: {arg}");
				}
			}
		}

		private static void Raise(Action handlers, string name)
		{
			if (handlers == null)
			{
				return;
			}
			Delegate[] invocationList = handlers.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action action = (Action)invocationList[i];
				try
				{
					action();
				}
				catch (Exception arg)
				{
					_log.LogError((object)$"{name} handler failed: {arg}");
				}
			}
		}
	}
	internal static class GameFlashes
	{
		internal static bool Off
		{
			get
			{
				try
				{
					AllSettings all = GameSettings.All;
					GeneralSettings val = ((all != null) ? all.General : null);
					return val != null && !val.ExplosionFlashes;
				}
				catch (Exception)
				{
					return false;
				}
			}
		}
	}
	internal static class ToonEmissive
	{
		internal const string ShaderName = "Custom/ToonShader";

		internal const string Keyword = "_EMISSIVEENABLE_ON";

		internal const string Toggle = "_EmissiveEnable";

		internal const string ColorProperty = "_EmissiveColor";

		internal const string TextureProperty = "_EmissiveTex";

		private static readonly string[][] EmissiveBases = new string[5][]
		{
			new string[0],
			new string[1] { "_USE_1STAS2ND_ON" },
			new string[2] { "_TINTMASKENABLE_ON", "_USE_1STAS2ND_ON" },
			new string[2] { "_BLOATENABLE_ON", "_USE_1STAS2ND_ON" },
			new string[3] { "_ALPHACUTOFFENABLE_ON", "_BLOATENABLE_ON", "_USE_1STAS2ND_ON" }
		};

		private static readonly string[] FeatureKeywords = new string[9] { "_UVMODE_WORLDSPACE", "_UVMODE_TRIPLANAR", "_USE_1STAS2ND_ON", "_USENORMALMAP_ON", "_ALPHACUTOFFENABLE_ON", "_TINTMASKENABLE_ON", "_BLOATENABLE_ON", "_SNOWENABLE_ON", "_FRESNELENABLE_ON" };

		internal static bool IsToon(Material m)
		{
			if ((Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null)
			{
				return ((Object)m.shader).name == "Custom/ToonShader";
			}
			return false;
		}

		internal static bool HasVariant(Material m)
		{
			HashSet<string> features = new HashSet<string>(m.shaderKeywords.Where((string k) => FeatureKeywords.Contains(k)));
			return EmissiveBases.Any((string[] b) => features.SetEquals(b));
		}
	}
}
namespace LightGreen.Presets
{
	public enum TimeOfDay
	{
		HoleDefault,
		Dawn,
		Morning,
		Noon,
		GoldenHour,
		Sunset,
		BlueHour,
		Night
	}
	[Serializable]
	public class TimePreset
	{
		public string name = "";

		[Tooltip("0 keeps the hole's sun; 1 uses this preset's sun height and colour.")]
		public float sunWeight;

		[Tooltip("Sun height above the horizon in degrees. Below 0 the sun has set and the scene light becomes the moon.")]
		public float sunElevation = 45f;

		public Color sunColor = Color.white;

		[Tooltip("Multiplies the hole's sun brightness.")]
		public float sunIntensity = 1f;

		[Tooltip("Once the sun is below the horizon: the moon's height in degrees, its colour, and its brightness (times the hole's sun).")]
		public float moonElevation = 40f;

		public Color moonColor = new Color(0.36f, 0.48f, 0.62f);

		public float moonIntensity = 0.85f;

		[Tooltip("How far the sky colours move toward the colours below (0 to 1).")]
		public float skyBlend;

		public Color skyColor = new Color(0.4f, 0.6f, 1f);

		public Color horizonColor = new Color(0.8f, 0.9f, 1f);

		public Color sunGlowColor = new Color(1f, 0.9f, 0.7f);

		[Tooltip("Multiplies the hole's ambient (fill) light. 0 = none.")]
		public float ambientIntensity = 1f;

		[Tooltip("Colour the ambient light is multiplied by (white = unchanged).")]
		public Color ambientTint = Color.white;

		[Tooltip("0 = day, 1 = night: shows the sky's stars and moon and dims the sun's glow in the sky.")]
		public float night;

		[Tooltip("Moon phase the sky shows at night (0 to 1).")]
		public float moonPhase = 0.5f;

		[Tooltip("How far the distance haze colour moves toward the sky's horizon colour (0 to 1).")]
		public float fogColorBlend;

		[Tooltip("Multiplies how far away the haze reaches full strength.")]
		public float fogDistance = 1f;

		[Tooltip("Rim light colour at this time of day; the biome and config scale its strength.")]
		public Color rimColor = new Color(0.75f, 0.85f, 1f);

		[Tooltip("Colour grading added on top of the course's own: white balance, saturation, contrast, exposure.")]
		public float temperature;

		public float tint;

		public float saturation;

		public float contrast;

		public float exposure;

		[Tooltip("Lens flare strength when looking toward the sun (0 = none).")]
		public float lensFlare;

		[Tooltip("How much the water takes on the sun's colour (0 to 1).")]
		public float waterTint;

		internal static TimePreset Lerp(TimePreset a, TimePreset b, float t)
		{
			//IL_0089: 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_0095: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			t = Mathf.Clamp01(t);
			float num = ((a.sunWeight > 0f) ? a.sunElevation : b.sunElevation);
			float num2 = ((b.sunWeight > 0f) ? b.sunElevation : a.sunElevation);
			return new TimePreset
			{
				name = ((t < 0.5f) ? a.name : b.name),
				sunWeight = Mathf.Lerp(a.sunWeight, b.sunWeight, t),
				sunElevation = Mathf.Lerp(num, num2, t),
				sunColor = Color.Lerp(a.sunColor, b.sunColor, t),
				sunIntensity = Mathf.Lerp(a.sunIntensity, b.sunIntensity, t),
				moonElevation = Mathf.Lerp(a.moonElevation, b.moonElevation, t),
				moonColor = Color.Lerp(a.moonColor, b.moonColor, t),
				moonIntensity = Mathf.Lerp(a.moonIntensity, b.moonIntensity, t),
				skyBlend = Mathf.Lerp(a.skyBlend, b.skyBlend, t),
				skyColor = Color.Lerp(a.skyColor, b.skyColor, t),
				horizonColor = Color.Lerp(a.horizonColor, b.horizonColor, t),
				sunGlowColor = Color.Lerp(a.sunGlowColor, b.sunGlowColor, t),
				ambientIntensity = Mathf.Lerp(a.ambientIntensity, b.ambientIntensity, t),
				ambientTint = Color.Lerp(a.ambientTint, b.ambientTint, t),
				night = Mathf.Lerp(a.night, b.night, t),
				moonPhase = Mathf.Lerp(a.moonPhase, b.moonPhase, t),
				fogColorBlend = Mathf.Lerp(a.fogColorBlend, b.fogColorBlend, t),
				fogDistance = Mathf.Lerp(a.fogDistance, b.fogDistance, t),
				rimColor = Color.Lerp(a.rimColor, b.rimColor, t),
				temperature = Mathf.Lerp(a.temperature, b.temperature, t),
				tint = Mathf.Lerp(a.tint, b.tint, t),
				saturation = Mathf.Lerp(a.saturation, b.saturation, t),
				contrast = Mathf.Lerp(a.contrast, b.contrast, t),
				exposure = Mathf.Lerp(a.exposure, b.exposure, t),
				lensFlare = Mathf.Lerp(a.lensFlare, b.lensFlare, t),
				waterTint = Mathf.Lerp(a.waterTint, b.waterTint, t)
			};
		}
	}
	[Serializable]
	public class BiomePreset
	{
		public string biome = "";

		[Tooltip("The hue shadows lean toward. Each material keeps its own shade brightness.")]
		public Color shadeTint = new Color(0.6f, 0.65f, 1f);

		[Tooltip("How far shade colours move toward the tint (0 to 1).")]
		public float shadeTintStrength = 0.3f;

		[Tooltip("Multiplies where the haze starts and where it is full. Lower = more haze.")]
		public float fogStart = 0.8f;

		public float fogEnd = 0.75f;

		[Tooltip("How far the haze colour moves toward the sky's horizon colour (0 to 1).")]
		public float fogColorBlend = 0.4f;

		[Tooltip("Colour grading for this biome, added on top of the course's own.")]
		public float temperature;

		public float tint;

		public float saturation;

		public float contrast;

		public float exposure;

		[Tooltip("Multiplies the rim light strength in this biome.")]
		public float rim = 1f;

		[Tooltip("Ice glint strength on terrain that supports it (0 = stock).")]
		public float glints;

		[Tooltip("Sun highlight strength on water (0 = stock: no highlight).")]
		public float waterSpecular = 0.5f;

		[Tooltip("Multiplies the ambient occlusion strength in this biome (0 = the course's own).")]
		public float ambientOcclusion = 1f;
	}
	[Serializable]
	public class PresetFile
	{
		public int version = 1;

		public BiomePreset[] biomes = Array.Empty<BiomePreset>();

		public TimePreset[] times = Array.Empty<TimePreset>();
	}
	internal static class DefaultPresets
	{
		internal const int Version = 6;

		internal static PresetFile Create()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: 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_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: 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_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_063f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_0719: Unknown result type (might be due to invalid IL or missing references)
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0733: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: Unknown result type (might be due to invalid IL or missing references)
			//IL_074d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0783: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0802: Unknown result type (might be due to invalid IL or missing references)
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_0847: Unknown result type (might be due to invalid IL or missing references)
			//IL_084c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0861: Unknown result type (might be due to invalid IL or missing references)
			//IL_0866: Unknown result type (might be due to invalid IL or missing references)
			//IL_089c: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_092c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0931: Unknown result type (might be due to invalid IL or missing references)
			//IL_095c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0961: Unknown result type (might be due to invalid IL or missing references)
			//IL_0976: Unknown result type (might be due to invalid IL or missing references)
			//IL_097b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0990: Unknown result type (might be due to invalid IL or missing references)
			//IL_0995: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_09fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a90: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ada: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b5f: Unknown result type (might be due to invalid IL or missing references)
			PresetFile presetFile = new PresetFile();
			presetFile.version = 6;
			presetFile.biomes = new BiomePreset[7]
			{
				new BiomePreset
				{
					biome = "DrivingRange",
					shadeTint = new Color(0.55f, 0.7f, 0.95f),
					shadeTintStrength = 0.25f,
					fogStart = 0.9f,
					fogEnd = 0.85f,
					saturation = 2f,
					waterSpecular = 0.5f
				},
				new BiomePreset
				{
					biome = "Coast",
					shadeTint = new Color(0.35f, 0.8f, 0.85f),
					shadeTintStrength = 0.3f,
					fogStart = 0.85f,
					fogEnd = 0.8f,
					fogColorBlend = 0.5f,
					temperature = 2f,
					saturation = 4f,
					waterSpecular = 0.7f
				},
				new BiomePreset
				{
					biome = "Forest",
					shadeTint = new Color(0.45f, 0.7f, 0.6f),
					shadeTintStrength = 0.3f,
					fogStart = 0.75f,
					fogEnd = 0.7f,
					fogColorBlend = 0.35f,
					temperature = -1f,
					saturation = 3f,
					contrast = 3f
				},
				new BiomePreset
				{
					biome = "Desert",
					shadeTint = new Color(0.85f, 0.55f, 0.45f),
					shadeTintStrength = 0.35f,
					fogStart = 0.7f,
					fogEnd = 0.6f,
					fogColorBlend = 0.5f,
					temperature = 2f,
					saturation = 1f,
					contrast = 2f
				},
				new BiomePreset
				{
					biome = "Snow",
					shadeTint = new Color(0.55f, 0.55f, 1f),
					shadeTintStrength = 0.4f,
					fogStart = 0.75f,
					fogEnd = 0.65f,
					fogColorBlend = 0.5f,
					temperature = -4f,
					saturation = 2f,
					glints = 2.5f
				},
				new BiomePreset
				{
					biome = "City",
					shadeTint = new Color(0.6f, 0.5f, 0.95f),
					shadeTintStrength = 0.3f,
					fogStart = 0.85f,
					fogEnd = 0.75f,
					fogColorBlend = 0.4f,
					saturation = 2f,
					contrast = 3f,
					rim = 1.2f
				},
				new BiomePreset
				{
					biome = "Unknown",
					shadeTintStrength = 0.2f
				}
			};
			presetFile.times = new TimePreset[8]
			{
				new TimePreset
				{
					name = "HoleDefault",
					rimColor = new Color(0.75f, 0.85f, 1f),
					lensFlare = 0.15f,
					waterTint = 0f
				},
				new TimePreset
				{
					name = "Dawn",
					sunWeight = 1f,
					sunElevation = 3f,
					sunColor = new Color(1f, 0.72f, 0.62f),
					sunIntensity = 0.75f,
					skyBlend = 0.55f,
					skyColor = new Color(0.32f, 0.42f, 0.8f),
					horizonColor = new Color(1f, 0.7f, 0.66f),
					sunGlowColor = new Color(1f, 0.74f, 0.6f),
					ambientIntensity = 1f,
					ambientTint = new Color(0.92f, 0.92f, 1f),
					night = 0.3f,
					moonPhase = 0.5f,
					fogColorBlend = 0.7f,
					fogDistance = 0.75f,
					rimColor = new Color(1f, 0.8f, 0.76f),
					temperature = -2f,
					tint = 4f,
					exposure = -0.05f,
					lensFlare = 0.5f,
					waterTint = 0.4f
				},
				new TimePreset
				{
					name = "Morning",
					sunWeight = 1f,
					sunElevation = 20f,
					sunColor = new Color(1f, 0.92f, 0.8f),
					sunIntensity = 0.9f,
					skyBlend = 0.35f,
					skyColor = new Color(0.5f, 0.72f, 1f),
					horizonColor = new Color(1f, 0.86f, 0.72f),
					sunGlowColor = new Color(1f, 0.85f, 0.65f),
					ambientIntensity = 0.95f,
					fogColorBlend = 0.6f,
					fogDistance = 0.85f,
					rimColor = new Color(1f, 0.9f, 0.8f),
					temperature = -3f,
					saturation = 2f,
					lensFlare = 0.35f,
					waterTint = 0.2f
				},
				new TimePreset
				{
					name = "Noon",
					sunWeight = 1f,
					sunElevation = 62f,
					sunColor = new Color(1f, 0.98f, 0.95f),
					sunIntensity = 1.05f,
					skyBlend = 0.15f,
					skyColor = new Color(0.32f, 0.58f, 1f),
					horizonColor = new Color(0.75f, 0.88f, 1f),
					sunGlowColor = new Color(1f, 0.97f, 0.9f),
					ambientIntensity = 1f,
					fogColorBlend = 0.3f,
					fogDistance = 1.1f,
					rimColor = new Color(0.8f, 0.9f, 1f),
					saturation = 3f,
					contrast = 2f,
					lensFlare = 0.1f,
					waterTint = 0f
				},
				new TimePreset
				{
					name = "GoldenHour",
					sunWeight = 1f,
					sunElevation = 8f,
					sunColor = new Color(1f, 0.78f, 0.52f),
					sunIntensity = 1f,
					skyBlend = 0.5f,
					skyColor = new Color(0.45f, 0.6f, 0.95f),
					horizonColor = new Color(1f, 0.74f, 0.45f),
					sunGlowColor = new Color(1f, 0.7f, 0.35f),
					ambientIntensity = 1.08f,
					fogColorBlend = 0.6f,
					fogDistance = 0.85f,
					rimColor = new Color(1f, 0.72f, 0.4f),
					temperature = 7f,
					saturation = 3f,
					contrast = 2f,
					lensFlare = 0.6f,
					waterTint = 0.45f
				},
				new TimePreset
				{
					name = "Sunset",
					sunWeight = 1f,
					sunElevation = 2.5f,
					sunColor = new Color(1f, 0.6f, 0.38f),
					sunIntensity = 0.9f,
					skyBlend = 0.65f,
					skyColor = new Color(0.36f, 0.38f, 0.72f),
					horizonColor = new Color(1f, 0.52f, 0.32f),
					sunGlowColor = new Color(1f, 0.5f, 0.25f),
					ambientIntensity = 1.15f,
					fogColorBlend = 0.6f,
					fogDistance = 0.8f,
					rimColor = new Color(1f, 0.55f, 0.35f),
					temperature = 10f,
					tint = 2f,
					saturation = 2f,
					contrast = 2f,
					lensFlare = 0.7f,
					waterTint = 0.5f
				},
				new TimePreset
				{
					name = "BlueHour",
					sunWeight = 1f,
					sunElevation = -6f,
					moonElevation = 20f,
					moonColor = new Color(0.5f, 0.6f, 0.95f),
					moonIntensity = 0.45f,
					skyBlend = 0.75f,
					skyColor = new Color(0.12f, 0.2f, 0.55f),
					horizonColor = new Color(0.55f, 0.5f, 0.75f),
					sunGlowColor = new Color(0.8f, 0.6f, 0.72f),
					ambientIntensity = 0.85f,
					ambientTint = new Color(0.75f, 0.82f, 1f),
					night = 0.5f,
					moonPhase = 0.5f,
					fogColorBlend = 0.75f,
					fogDistance = 0.8f,
					rimColor = new Color(0.6f, 0.75f, 1f),
					temperature = -8f,
					saturation = -4f,
					contrast = 2f,
					exposure = -0.12f,
					lensFlare = 0.1f,
					waterTint = 0.6f
				},
				new TimePreset
				{
					name = "Night",
					sunWeight = 1f,
					sunElevation = -30f,
					moonElevation = 40f,
					moonColor = new Color(0.36f, 0.48f, 0.62f),
					moonIntensity = 0.85f,
					skyBlend = 0.85f,
					skyColor = new Color(0.03f, 0.06f, 0.18f),
					horizonColor = new Color(0.12f, 0.16f, 0.32f),
					sunGlowColor = new Color(0.55f, 0.65f, 0.9f),
					ambientIntensity = 0.6f,
					ambientTint = new Color(0.7f, 0.8f, 1f),
					night = 1f,
					moonPhase = 0.5f,
					fogColorBlend = 0.8f,
					fogDistance = 0.8f,
					rimColor = new Color(0.7f, 0.85f, 1.2f),
					temperature = -12f,
					saturation = -12f,
					contrast = 3f,
					exposure = -0.25f,
					lensFlare = 0.05f,
					waterTint = 0.6f
				}
			};
			return presetFile;
		}
	}
	internal static class PresetStore
	{
		private static PresetFile _file = DefaultPresets.Create();

		private static DateTime _loadedWriteTime;

		private static float _nextCheck;

		private static ManualLogSource _log;

		internal static string FilePath => Path.Combine(Paths.ConfigPath, "LightGreen.presets.json");

		internal static event Action Reloaded;

		internal static void Load(ManualLogSource log)
		{
			_log = log;
			try
			{
				if (!File.Exists(FilePath))
				{
					File.WriteAllText(FilePath, JsonUtility.ToJson((object)DefaultPresets.Create(), true));
					_log.LogInfo((object)("Wrote the default presets to " + FilePath + ". Edit it while the game runs to tune the looks."));
				}
				Read();
				if (_file.version < 6)
				{
					string text = FilePath + $".v{_file.version}.bak";
					File.Copy(FilePath, text, overwrite: true);
					File.WriteAllText(FilePath, JsonUtility.ToJson((object)DefaultPresets.Create(), true));
					Read();
					_log.LogInfo((object)$"Updated the presets to LightGreen's new defaults (version {6}). Your previous file is at {text}.");
				}
			}
			catch (Exception ex)
			{
				_file = DefaultPresets.Create();
				_log.LogError((object)("Couldn't read " + FilePath + " (" + ex.Message + "); using the built-in presets."));
			}
		}

		internal static void Poll()
		{
			if (Time.unscaledTime < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.unscaledTime + 1f;
			try
			{
				if (File.Exists(FilePath) && !(File.GetLastWriteTimeUtc(FilePath) == _loadedWriteTime))
				{
					Read();
					_log.LogInfo((object)"Presets reloaded.");
					PresetStore.Reloaded?.Invoke();
				}
			}
			catch (Exception ex)
			{
				_loadedWriteTime = File.GetLastWriteTimeUtc(FilePath);
				_log.LogError((object)("Couldn't reload the presets (" + ex.Message + "); keeping the previous ones."));
			}
		}

		private static void Read()
		{
			_loadedWriteTime = File.GetLastWriteTimeUtc(FilePath);
			PresetFile presetFile = JsonUtility.FromJson<PresetFile>(File.ReadAllText(FilePath));
			if (presetFile == null)
			{
				throw new InvalidDataException("the file is empty or not JSON");
			}
			PresetFile presetFile2 = DefaultPresets.Create();
			List<BiomePreset> list = new List<BiomePreset>(presetFile.biomes ?? Array.Empty<BiomePreset>());
			BiomePreset[] biomes = presetFile2.biomes;
			foreach (BiomePreset b in biomes)
			{
				if (!list.Any((BiomePreset x) => string.Equals(x.biome, b.biome, StringComparison.OrdinalIgnoreCase)))
				{
					list.Add(b);
				}
			}
			List<TimePreset> list2 = new List<TimePreset>(presetFile.times ?? Array.Empty<TimePreset>());
			TimePreset[] times = presetFile2.times;
			foreach (TimePreset t in times)
			{
				if (!list2.Any((TimePreset x) => string.Equals(x.name, t.name, StringComparison.OrdinalIgnoreCase)))
				{
					list2.Add(t);
				}
			}
			presetFile.biomes = list.ToArray();
			presetFile.times = list2.ToArray();
			_file = presetFile;
		}

		internal static BiomePreset ForBiome(Biome biome)
		{
			string name = biome.ToString();
			return _file.biomes.FirstOrDefault((BiomePreset b) => string.Equals(b.biome, name, StringComparison.OrdinalIgnoreCase)) ?? _file.biomes.FirstOrDefault((BiomePreset b) => string.Equals(b.biome, "Unknown", StringComparison.OrdinalIgnoreCase)) ?? new BiomePreset();
		}

		internal static TimePreset ForTime(TimeOfDay time)
		{
			string name = time.ToString();
			return _file.times.FirstOrDefault((TimePreset t) => string.Equals(t.name, name, StringComparison.OrdinalIgnoreCase)) ?? new TimePreset
			{
				name = name
			};
		}
	}
}
namespace LightGreen.Systems
{
	internal sealed class AmbientOcclusion : IFeature
	{
		private const float Priority = 2002f;

		private const float TunedIntensity = 0.5f;

		private const float Radius = 1f;

		private static readonly int OcclusionTextureId = Shader.PropertyToID("_ScreenSpaceOcclusionTexture");

		private GameObject _root;

		private Volume _volume;

		private VolumeProfile _profile;

		private HTraceAOVolume _ao;

		private bool _hooked;

		private AOQuality? _loggedQuality;

		public string Name => "Ambient occlusion";

		public void Apply()
		{
			BiomePreset biomePreset = PresetStore.ForBiome(GameEvents.CurrentBiome);
			float num = Settings.AmbientOcclusion.Value * Mathf.Max(0f, biomePreset.ambientOcclusion);
			if (!GameEvents.InHole || num <= 0f || Vr.IsRunning)
			{
				Restore();
				return;
			}
			EnsureVolume();
			((VolumeParameter<bool>)(object)_ao.Enable).Override(true);
			((VolumeParameter<AmbientOcclusionMode>)(object)_ao.AmbientOcclusionMode).Override((AmbientOcclusionMode)1);
			((VolumeParameter<URPInjectionPoint>)(object)_ao.InjectionPoint).Override((URPInjectionPoint)2);
			((VolumeParameter<bool>)(object)_ao.ReconstructNormals).Override(true);
			ApplyQuality(Settings.AmbientOcclusionQuality.Value);
			((VolumeParameter<float>)(object)_ao.GTAOWorldSpaceRadius).Override(1f);
			((VolumeParameter<GTAODenoisingMode>)(object)_ao.GTAODenoising).Override((GTAODenoisingMode)3);
			((VolumeParameter<float>)(object)_ao.Intensity).Override(Mathf.Clamp(0.5f * num, 0f, 4f));
			((VolumeParameter<float>)(object)_ao.DirectLightingOcclusion).Override(0f);
			((Behaviour)_volume).enabled = true;
			if (Settings.AmbientOcclusionQuality.Value != _loggedQuality)
			{
				_loggedQuality = Settings.AmbientOcclusionQuality.Value;
				Plugin.Log.LogInfo((object)$"Ambient occlusion: on, {_loggedQuality} quality.");
			}
			Hook(on: true);
			GrassFreeDepth.ForOcclusion(on: true);
		}

		private void ApplyQuality(AOQuality quality)
		{
			switch (quality)
			{
			case AOQuality.Low:
				((VolumeParameter<GTAOResolutionMode>)(object)_ao.GTAOResolution).Override((GTAOResolutionMode)2);
				((VolumeParameter<int>)(object)_ao.GTAOSliceCount).Override(2);
				((VolumeParameter<int>)(object)_ao.GTAOStepCount).Override(12);
				break;
			case AOQuality.High:
				((VolumeParameter<GTAOResolutionMode>)(object)_ao.GTAOResolution).Override((GTAOResolutionMode)0);
				((VolumeParameter<int>)(object)_ao.GTAOSliceCount).Override(2);
				((VolumeParameter<int>)(object)_ao.GTAOStepCount).Override(16);
				break;
			default:
				((VolumeParameter<GTAOResolutionMode>)(object)_ao.GTAOResolution).Override((GTAOResolutionMode)1);
				((VolumeParameter<int>)(object)_ao.GTAOSliceCount).Override(2);
				((VolumeParameter<int>)(object)_ao.GTAOStepCount).Override(16);
				break;
			}
		}

		public void Restore()
		{
			if ((Object)(object)_volume != (Object)null)
			{
				((Behaviour)_volume).enabled = false;
			}
			Hook(on: false);
			GrassFreeDepth.ForOcclusion(on: false);
		}

		private void Hook(bool on)
		{
			if (on != _hooked)
			{
				if (on)
				{
					RenderPipelineManager.beginCameraRendering += ClearOcclusionTexture;
				}
				else
				{
					RenderPipelineManager.beginCameraRendering -= ClearOcclusionTexture;
				}
				_hooked = on;
			}
		}

		private static void ClearOcclusionTexture(ScriptableRenderContext context, Camera camera)
		{
			Shader.SetGlobalTexture(OcclusionTextureId, (Texture)(object)Texture2D.whiteTexture);
		}

		internal void Destroy()
		{
			Restore();
			GrassFreeDepth.Destroy();
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			if ((Object)(object)_profile != (Object)null)
			{
				Object.Destroy((Object)(object)_profile);
			}
			_root = null;
		}

		private void EnsureVolume()
		{
			//IL_0015: 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: Expected O, but got Unknown
			if (!((Object)(object)_root != (Object)null))
			{
				_root = new GameObject("LightGreen ambient occlusion")
				{
					hideFlags = (HideFlags)52
				};
				Object.DontDestroyOnLoad((Object)(object)_root);
				_profile = ScriptableObject.CreateInstance<VolumeProfile>();
				((Object)_profile).hideFlags = (HideFlags)52;
				_ao = _profile.Add<HTraceAOVolume>(false);
				_volume = _root.AddComponent<Volume>();
				_volume.isGlobal = true;
				_volume.priority = 2002f;
				_volume.weight = 1f;
				_volume.sharedProfile = _profile;
				((Behaviour)_volume).enabled = false;
			}
		}
	}
	internal sealed class CityNight : IFeature
	{
		private struct Lamp
		{
			internal Vector3 Position;

			internal float Intensity;

			internal float Range;
		}

		private readonly LightPool _pool;

		private readonly EnvironmentController _environment;

		private const string Emissive = "_EMISSIVEENABLE_ON";

		private const string EmissiveToggle = "_EmissiveEnable";

		private const string EmissiveColor = "_EmissiveColor";

		private const string EmissiveTex = "_EmissiveTex";

		private static readonly string[] GlowPrefixes = new string[5] { "M_Buildings_", "Bus ", "SmallCar", "Van", "Police Car" };

		private static readonly string[] NoGlow = new string[1] { "Bus Station" };

		private const float Glow = 1.5f;

		private static readonly Color LampColor = new Color(1f, 0.95f, 0.85f);

		private const float LampGroundBrightness = 0.8f;

		private const float LampSpotAngle = 117f;

		private readonly MaterialEdits _edits = new MaterialEdits();

		private readonly List<Material> _glowing = new List<Material>();

		private readonly HashSet<Material> _checked = new HashSet<Material>();

		private readonly List<Lamp> _lamps = new List<Lamp>();

		private float _nextScan;

		private bool _scanned;

		private float _appliedLevel = -1f;

		private bool _logged;

		private int _skipped;

		public string Name => "City night";

		internal CityNight(LightPool pool, EnvironmentController environment)
		{
			_pool = pool;
			_environment = environment;
		}

		public void Apply()
		{
			if (!GameEvents.InHole)
			{
				Restore();
			}
			else
			{
				Update(_pool, _environment, Settings.CityNight.Value);
			}
		}

		internal void Rescan()
		{
			_scanned = false;
			_logged = false;
			_skipped = 0;
		}

		private void Update(LightPool pool, EnvironmentController environment, float strength)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			float num = ((GameEvents.CurrentBiome == Biome.City) ? (Mathf.Clamp01(environment.Darkness) * strength) : 0f);
			if (num <= 0.01f)
			{
				if (_glowing.Count > 0 || _scanned)
				{
					Restore();
				}
				return;
			}
			if (!_scanned || Time.unscaledTime >= _nextScan)
			{
				Scan();
			}
			ApplyGlow(num);
			foreach (Lamp lamp in _lamps)
			{
				pool.Request(new LightRequest
				{
					Position = lamp.Position,
					Color = LampColor,
					Intensity = lamp.Intensity * num,
					Range = lamp.Range,
					Shadows = true,
					Priority = 1.5f,
					SpotAngle = 117f
				});
			}
		}

		private void Scan()
		{
			bool flag = !_scanned;
			_scanned = true;
			_nextScan = Time.unscaledTime + 15f;
			_edits.ForgetDestroyed();
			_glowing.RemoveAll((Material m) => (Object)(object)m == (Object)null);
			int num = 0;
			Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			for (int num2 = 0; num2 < array.Length; num2++)
			{
				Material[] sharedMaterials = array[num2].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (!((Object)(object)val == (Object)null) && _checked.Add(val) && ShouldGlow(val))
					{
						_glowing.Add(val);
						num++;
					}
				}
			}
			if (num > 0)
			{
				_appliedLevel = -1f;
			}
			if (!flag)
			{
				return;
			}
			FindLamps();
			if (!_logged)
			{
				_logged = true;
				Plugin.Log.LogInfo((object)(string.Format("City night: {0} materials glow ({1}", _glowing.Count, string.Join(", ", from m in _glowing.Take(8)
					select ((Object)m).name)) + string.Format("{0}); {1} lampposts lit", (_glowing.Count > 8) ? ", …" : "", _lamps.Count) + ((_skipped > 0) ? $"; {_skipped} left dark (no glowing variant in the game's toon shader)." : ".")));
			}
		}

		private bool ShouldGlow(Material m)
		{
			string name = ((Object)m).name.Replace(" (Instance)", "");
			if (!GlowPrefixes.Any((string p) => name.StartsWith(p)) || NoGlow.Any((string p) => name.StartsWith(p)))
			{
				return false;
			}
			if (!m.HasProperty("_EmissiveTex") || (Object)(object)m.GetTexture("_EmissiveTex") == (Object)null || !m.HasProperty("_EmissiveColor"))
			{
				return false;
			}
			if (m.IsKeywordEnabled("_EMISSIVEENABLE_ON"))
			{
				return false;
			}
			if (!ToonEmissive.HasVariant(m))
			{
				_skipped++;
				return false;
			}
			return true;
		}

		private void ApplyGlow(float level)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Abs(level - _appliedLevel) < 0.01f)
			{
				return;
			}
			_appliedLevel = level;
			foreach (Material item in _glowing)
			{
				if (!((Object)(object)item == (Object)null))
				{
					_edits.SetKeyword(item, "_EMISSIVEENABLE_ON", on: true);
					if (item.HasProperty("_EmissiveEnable"))
					{
						_edits.SetFloat(item, "_EmissiveEnable", 1f);
					}
					Color val = _edits.StockColor(item, "_EmissiveColor");
					float num = 1.5f * level;
					_edits.SetColor(item, "_EmissiveColor", new Color(val.r * num, val.g * num, val.b * num, val.a));
				}
			}
		}

		private void FindLamps()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00dc: 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_00ee: 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_00fd: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			_lamps.Clear();
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			foreach (Transform val in array)
			{
				if (!IsLamppost(val) || ((Object)(object)val.parent != (Object)null && IsLamppost(val.parent)) || (Object)(object)((Component)val).GetComponentInChildren<Light>(true) != (Object)null)
				{
					continue;
				}
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>();
				if (componentsInChildren.Length == 0)
				{
					continue;
				}
				Bounds bounds = componentsInChildren[0].bounds;
				for (int j = 1; j < componentsInChildren.Length; j++)
				{
					((Bounds)(ref bounds)).Encapsulate(componentsInChildren[j].bounds);
				}
				float y = ((Bounds)(ref bounds)).size.y;
				if (!(y < 2f) && !(y > 30f))
				{
					Vector3 position = val.position;
					Vector3 val2 = new Vector3(((Bounds)(ref bounds)).center.x - position.x, 0f, ((Bounds)(ref bounds)).center.z - position.z) * 2f;
					if (((Vector3)(ref val2)).magnitude > 5f)
					{
						val2 = Vector3.zero;
					}
					Vector3 val3 = new Vector3(position.x, ((Bounds)(ref bounds)).max.y - 0.8f, position.z) + val2;
					if (val2 == Vector3.zero)
					{
						((Vector3)(ref val3))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y - 0.8f, ((Bounds)(ref bounds)).center.z);
					}
					float num = Mathf.Max(2f, val3.y - ((Bounds)(ref bounds)).min.y);
					_lamps.Add(new Lamp
					{
						Position = val3,
						Intensity = Mathf.Clamp(0.8f * num * num, 5f, 200f),
						Range = Mathf.Clamp(num * 1.8f, 8f, 30f)
					});
				}
			}
		}

		private static bool IsLamppost(Transform t)
		{
			if (!((Object)t).name.StartsWith("Lamppost"))
			{
				return ((Object)t).name.StartsWith("Lampost");
			}
			return true;
		}

		public void Restore()
		{
			if (_glowing.Count != 0 || _scanned || _checked.Count != 0)
			{
				_edits.Restore();
				_glowing.Clear();
				_checked.Clear();
				_lamps.Clear();
				_scanned = false;
				_skipped = 0;
				_appliedLevel = -1f;
			}
		}
	}
	internal sealed class BallGlow : IFeature
	{
		private readonly EnvironmentController _environment;

		private const float OwnGlow = 0.75f;

		private const float OtherGlow = 0.5f;

		private static readonly int EmissiveColorId = Shader.PropertyToID("_EmissiveColor");

		private static readonly int EmissiveTexId = Shader.PropertyToID("_EmissiveTex");

		private static readonly int BaseColorId = Shader.PropertyToID("_BaseColor");

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		private static readonly int MainTexId = Shader.PropertyToID("_MainTex");

		private readonly MaterialEdits _edits = new MaterialEdits();

		private readonly MaterialPropertyBlock _block = new MaterialPropertyBlock();

		private readonly Dictionary<Renderer, bool> _glowing = new Dictionary<Renderer, bool>();

		private readonly HashSet<Renderer> _thisFrame = new HashSet<Renderer>();

		private readonly List<Renderer> _done = new List<Renderer>();

		private readonly HashSet<Material> _cantGlow = new HashSet<Material>();

		private GolfBall[] _balls = (GolfBall[])(object)new GolfBall[0];

		private float _nextScan;

		public string Name => "Ball glow";

		internal BallGlow(EnvironmentController environment)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_environment = environment;
		}

		public void Apply()
		{
			float value = Settings.BallGlow.Value;
			float darkness = _environment.Darkness;
			if (!GameEvents.InHole || value <= 0f || darkness <= 0.01f)
			{
				Restore();
				return;
			}
			if (Time.unscaledTime >= _nextScan)
			{
				_nextScan = Time.unscaledTime + 1f;
				_balls = Object.FindObjectsByType<GolfBall>((FindObjectsSortMode)0);
			}
			bool value2 = Settings.BallGlowOwnOnly.Value;
			_thisFrame.Clear();
			GolfBall[] balls = _balls;
			foreach (GolfBall val in balls)
			{
				if ((Object)(object)val == (Object)null || !((Behaviour)val).isActiveAndEnabled || val.IsHidden)
				{
					continue;
				}
				bool flag = (Object)(object)val.Owner != (Object)null && ((NetworkBehaviour)val.Owner).isLocalPlayer;
				if (value2 && !flag)
				{
					continue;
				}
				float level = (flag ? 0.75f : 0.5f) * value * darkness;
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>();
				foreach (Renderer val2 in componentsInChildren)
				{
					if (Glow(val2, level))
					{
						_thisFrame.Add(val2);
					}
				}
			}
			_done.Clear();
			foreach (Renderer key in _glowing.Keys)
			{
				if (!_thisFrame.Contains(key))
				{
					_done.Add(key);
				}
			}
			foreach (Renderer item in _done)
			{
				Unglow(item);
			}
		}

		private bool Glow(Renderer r, float level)
		{
			//IL_0120: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)r == (Object)null || !(r is MeshRenderer))
			{
				return false;
			}
			Material sharedMaterial = r.sharedMaterial;
			if (!ToonEmissive.IsToon(sharedMaterial) || _cantGlow.Contains(sharedMaterial))
			{
				return false;
			}
			if (!sharedMaterial.IsKeywordEnabled("_EMISSIVEENABLE_ON"))
			{
				Color val = (sharedMaterial.HasProperty(EmissiveColorId) ? _edits.StockColor(sharedMaterial, "_EmissiveColor") : Color.black);
				if (!ToonEmissive.HasVariant(sharedMaterial) || ((Color)(ref val)).maxColorComponent > 0.001f)
				{
					_cantGlow.Add(sharedMaterial);
					Plugin.LogChange("ballglow:" + ((Object)sharedMaterial).name, "Ball glow: " + ((Object)sharedMaterial).name + " doesn't glow (it can't be switched to glow without changing how it's drawn).");
					return false;
				}
				_edits.SetKeyword(sharedMaterial, "_EMISSIVEENABLE_ON", on: true);
				if (sharedMaterial.HasProperty("_EmissiveEnable"))
				{
					_edits.SetFloat(sharedMaterial, "_EmissiveEnable", 1f);
				}
			}
			Color val2 = (sharedMaterial.HasProperty(BaseColorId) ? sharedMaterial.GetColor(BaseColorId) : (sharedMaterial.HasProperty(ColorId) ? sharedMaterial.GetColor(ColorId) : Color.white));
			Texture val3 = (sharedMaterial.HasProperty(MainTexId) ? sharedMaterial.GetTexture(MainTexId) : null);
			if (!_glowing.ContainsKey(r))
			{
				_glowing[r] = r.HasPropertyBlock();
			}
			r.GetPropertyBlock(_block);
			_block.SetColor(EmissiveColorId, new Color(val2.r * level, val2.g * level, val2.b * level, 1f));
			_block.SetTexture(EmissiveTexId, (Texture)(((Object)(object)val3 != (Object)null) ? ((object)val3) : ((object)Texture2D.whiteTexture)));
			r.SetPropertyBlock(_block);
			return true;
		}

		private void Unglow(Renderer r)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!_glowing.TryGetValue(r, out var value))
			{
				return;
			}
			_glowing.Remove(r);
			if (!((Object)(object)r == (Object)null))
			{
				if (!value)
				{
					r.SetPropertyBlock((MaterialPropertyBlock)null);
					return;
				}
				Material sharedMaterial = r.sharedMaterial;
				r.GetPropertyBlock(_block);
				_block.SetColor(EmissiveColorId, ((Object)(object)sharedMaterial != (Object)null && sharedMaterial.HasProperty(EmissiveColorId)) ? sharedMaterial.GetColor(EmissiveColorId) : Color.black);
				Texture val = (((Object)(object)sharedMaterial != (Object)null && sharedMaterial.HasProperty(EmissiveTexId)) ? sharedMaterial.GetTexture(EmissiveTexId) : null);
				_block.SetTexture(EmissiveTexId, (Texture)(((Object)(object)val != (Object)null) ? ((object)val) : ((object)Texture2D.whiteTexture)));
				r.SetPropertyBlock(_block);
			}
		}

		public void Restore()
		{
			if (_glowing.Count > 0)
			{
				_done.Clear();
				_done.AddRange(_glowing.Keys);
				foreach (Renderer item in _done)
				{
					Unglow(item);
				}
			}
			_edits.Restore();
			_balls = (GolfBall[])(object)new GolfBall[0];
			_nextScan = 0f;
		}
	}
	internal sealed class ParticleLayer
	{
		internal struct Spec
		{
			internal string Name;

			internal float Width;

			internal float Height;

			internal float Lift;

			internal float Density;

			internal float Fall;

			internal float MinSize;

			internal float MaxSize;

			internal float MaxScreenSize;

			internal float Alpha;

			internal float Stretch;
		}

		private const string ShaderName = "Universal Render Pipeline/Particles/Unlit";

		private const string GameMaterialName = "ParticlesUnlit";

		private const float CutDistance = 25f;

		private static Material _source;

		private static float _nextLook;

		private static bool _loggedSource;

		private readonly Spec[] _specs;

		private readonly string _rootName;

		private GameObject _root;

		private readonly List<ParticleSystem> _systems = new List<ParticleSystem>();

		private readonly List<Material> _materials = new List<Material>();

		private Vector3 _lastCamera;

		private bool _running;

		private float _density = -1f;

		internal bool Running => _running;

		internal ParticleLayer(string rootName, params Spec[] specs)
		{
			_rootName = rootName;
			_specs = specs;
		}

		internal void Update(Camera camera, float density, Color color, Vector2 wind)
		{
			//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_0035: 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_003c: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00c3: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)camera == (Object)null || density <= 0f)
			{
				Stop();
			}
			else
			{
				if (!EnsureBuilt())
				{
					return;
				}
				Vector3 position = ((Component)camera).transform.position;
				int num;
				if (_running)
				{
					Vector3 val = position - _lastCamera;
					num = ((((Vector3)(ref val)).sqrMagnitude > 625f) ? 1 : 0);
				}
				else
				{
					num = 1;
				}
				bool flag = (byte)num != 0;
				bool flag2 = Mathf.Abs(density - _density) > 0.01f;
				_lastCamera = position;
				if (!_root.activeSelf)
				{
					_root.SetActive(true);
				}
				for (int i = 0; i < _systems.Count; i++)
				{
					Spec spec = _specs[i];
					ParticleSystem val2 = _systems[i];
					((Component)val2).transform.position = position + Vector3.up * spec.Lift;
					if (flag2)
					{
						SetDensity(val2, spec, density);
					}
					VelocityOverLifetimeModule velocityOverLifetime = val2.velocityOverLifetime;
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(wind.x * 0.8f, wind.x * 1.2f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve((0f - spec.Fall) * 1.25f, (0f - spec.Fall) * 0.75f);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(wind.y * 0.8f, wind.y * 1.2f);
					Color val3 = color;
					val3.a *= spec.Alpha;
					_materials[i].SetColor("_BaseColor", val3);
					if (flag)
					{
						val2.Clear(true);
						val2.Simulate(Lifetime(spec), true, true, false);
						val2.Play(true);
					}
					else if (!val2.isPlaying)
					{
						val2.Play(true);
					}
				}
				if (flag2)
				{
					_density = density;
				}
				_running = true;
			}
		}

		private static float Lifetime(Spec spec)
		{
			return spec.Height / Mathf.Max(0.1f, spec.Fall);
		}

		private static void SetDensity(ParticleSystem ps, Spec spec, float density)
		{
			//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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			float num = Lifetime(spec);
			float num2 = spec.Width * spec.Width * spec.Height * spec.Density * density;
			MainModule main = ps.main;
			((MainModule)(ref main)).maxParticles = Mathf.CeilToInt(num2 * 1.3f) + 16;
			EmissionModule emission = ps.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(num2 / (num * 0.75f));
		}

		private bool EnsureBuilt()
		{
			//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_003a: Expected O, but got Unknown
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			Material val = Source();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_root = new GameObject(_rootName)
			{
				hideFlags = (HideFlags)52
			};
			Object.DontDestroyOnLoad((Object)(object)_root);
			_root.SetActive(false);
			Spec[] specs = _specs;
			foreach (Spec spec in specs)
			{
				_systems.Add(Build(spec, val));
			}
			return true;
		}

		private ParticleSystem Build(Spec spec, Material source)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0051: 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_008a: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			GameObject val = new GameObject(_rootName + ": " + spec.Name)
			{
				hideFlags = (HideFlags)52
			};
			val.transform.SetParent(_root.transform, false);
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			float num = Lifetime(spec);
			MainModule main = obj.main;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).duration = 10f;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(num * 0.5f, num);
			((MainModule)(ref main)).startSize = new MinMaxCurve(spec.MinSize, spec.MaxSize);
			((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, (float)Math.PI * 2f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white);
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			((ShapeModule)(ref shape)).scale = new Vector3(spec.Width, spec.Height, spec.Width);
			VelocityOverLifetimeModule velocityOverLifetime = obj.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(0f, 0f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(0f - spec.Fall, 0f - spec.Fall);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(0f, 0f);
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			if (spec.Stretch > 0f)
			{
				component.renderMode = (ParticleSystemRenderMode)1;
				component.velocityScale = spec.Stretch;
				component.lengthScale = 1f;
				component.cameraVelocityScale = 0f;
			}
			else
			{
				component.renderMode = (ParticleSystemRenderMode)0;
				component.alignment = (ParticleSystemRenderSpace)0;
			}
			component.sortMode = (ParticleSystemSortMode)0;
			component.maxParticleSize = spec.MaxScreenSize;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			Material item = (((Renderer)component).sharedMaterial = new Material(source)
			{
				name = _rootName + ": " + spec.Name,
				hideFlags = (HideFlags)52
			});
			_materials.Add(item);
			return obj;
		}

		internal void Stop()
		{
			if (!_running)
			{
				return;
			}
			foreach (ParticleSystem system in _systems)
			{
				if ((Object)(object)system != (Object)null)
				{
					system.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			_running = false;
		}

		internal void Destroy()
		{
			Stop();
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			foreach (Material material in _materials)
			{
				if ((Object)(object)material != (Object)null)
				{
					Object.Destroy((Object)(object)material);
				}
			}
			_root = null;
			_systems.Clear();
			_materials.Clear();
			_density = -1f;
		}

		internal static Material SharedMaterial()
		{
			return Source();
		}

		private static Material Source()
		{
			//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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_0080: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			if ((Object)(object)_source != (Object)null)
			{
				return _source;
			}
			if (Time.unscaledTime < _nextLook)
			{
				return null;
			}
			_nextLook = Time.unscaledTime + 2f;
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "ParticlesUnlit") && !((Object)(object)val.shader == (Object)null) && !(((Object)val.shader).name != "Uni