Decompiled source of TSDynamicWeatherEffects v0.6.4

plugins/TSDynamicWeatherEffects.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.Singletons;
using Bounce.TaleSpire.AssetManagement;
using Bounce.UnsafeViews;
using Bouncyrock.Physics;
using TMPro;
using TaleSpire.Atmosphere;
using TaleSpire.ContentManagement;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Physics;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TSDynamicWeatherEffects")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.4.0")]
[assembly: AssemblyInformationalVersion("0.6.4+95f0982901f1410ff0d8951636764bd52166ec96")]
[assembly: AssemblyProduct("TSDynamicWeatherEffects")]
[assembly: AssemblyTitle("TSDynamicWeatherEffects")]
[assembly: InternalsVisibleTo("Weather.Tests")]
[assembly: AssemblyVersion("0.6.4.0")]
namespace TSDynamicWeatherEffects;

internal sealed class BoardWeatherStore
{
	private const string Header = "TSDynamicWeatherBoardsV1";

	private readonly string _filePath;

	private readonly Action<string> _warn;

	private readonly Dictionary<Guid, WeatherState> _boards = new Dictionary<Guid, WeatherState>();

	private bool _loaded;

	public BoardWeatherStore(string filePath, Action<string> warn = null)
	{
		_filePath = filePath;
		_warn = warn;
	}

	public WeatherState GetOrDefault(Guid board)
	{
		if (board == Guid.Empty)
		{
			return WeatherState.Default;
		}
		EnsureLoaded();
		if (!_boards.TryGetValue(board, out var value))
		{
			return WeatherState.Default;
		}
		return value;
	}

	public void Save(Guid board, WeatherState state)
	{
		if (!(board == Guid.Empty))
		{
			EnsureLoaded();
			if (!_boards.TryGetValue(board, out var value) || !(value == state))
			{
				_boards[board] = state;
				FlushToDisk();
			}
		}
	}

	private void EnsureLoaded()
	{
		if (_loaded)
		{
			return;
		}
		_loaded = true;
		if (string.IsNullOrEmpty(_filePath) || !File.Exists(_filePath))
		{
			return;
		}
		try
		{
			string[] array = File.ReadAllLines(_filePath, Encoding.UTF8);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0 && !(text == "TSDynamicWeatherBoardsV1") && !text.StartsWith("#", StringComparison.Ordinal))
				{
					string[] array2 = text.Split('|');
					if (array2.Length == 5 && Guid.TryParse(array2[0], out var result) && !(result == Guid.Empty) && int.TryParse(array2[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) && int.TryParse(array2[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result3) && int.TryParse(array2[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result4) && byte.TryParse(array2[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result5))
					{
						_boards[result] = WeatherState.FromFlags((WeatherKind)result2, (Intensity)result3, (WindStrength)result4, result5);
					}
				}
			}
		}
		catch (Exception ex)
		{
			_warn?.Invoke("Could not read saved board weather: " + ex.Message);
		}
	}

	private void FlushToDisk()
	{
		if (string.IsNullOrEmpty(_filePath))
		{
			return;
		}
		try
		{
			string directoryName = Path.GetDirectoryName(_filePath);
			if (!string.IsNullOrEmpty(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("TSDynamicWeatherBoardsV1");
			foreach (KeyValuePair<Guid, WeatherState> board in _boards)
			{
				WeatherState value = board.Value;
				stringBuilder.Append(board.Key.ToString("D")).Append('|').Append((int)value.Mode)
					.Append('|')
					.Append((int)value.Tier)
					.Append('|')
					.Append((int)value.Wind)
					.Append('|')
					.Append(value.PackFlags().ToString(CultureInfo.InvariantCulture))
					.AppendLine();
			}
			string text = _filePath + ".tmp";
			File.WriteAllText(text, stringBuilder.ToString(), Encoding.UTF8);
			if (File.Exists(_filePath))
			{
				File.Delete(_filePath);
			}
			File.Move(text, _filePath);
		}
		catch (Exception ex)
		{
			_warn?.Invoke("Could not save board weather: " + ex.Message);
		}
	}
}
internal static class LoginModListFormatter
{
	public const string Header = "Installed Mods:";

	public const string HeaderSuffix = "\n\nInstalled Mods:";

	public static string FormatEntry(string modName, string modVersion)
	{
		return "\n<indent=5%>" + modName.Trim() + " - " + modVersion.Trim() + "</indent>";
	}

	public static string Append(string existing, string modName, string modVersion, out bool addedHeader, out bool modified)
	{
		addedHeader = false;
		modified = false;
		string text = existing ?? string.Empty;
		string text2 = modName?.Trim() ?? string.Empty;
		if (text2.Length == 0)
		{
			return text;
		}
		string text3 = FormatEntry(text2, modVersion ?? string.Empty);
		string value = "<indent=5%>" + text2 + " - ";
		if (text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return text;
		}
		modified = true;
		addedHeader = text.IndexOf("Installed Mods:", StringComparison.OrdinalIgnoreCase) < 0;
		return text + (addedHeader ? "\n\nInstalled Mods:" : string.Empty) + text3;
	}

	public static string Remove(string existing, string modName, string modVersion, bool addedHeader)
	{
		if (string.IsNullOrEmpty(existing) || string.IsNullOrWhiteSpace(modName))
		{
			return existing ?? string.Empty;
		}
		string text = FormatEntry(modName, modVersion ?? string.Empty);
		int num = existing.IndexOf(text, StringComparison.Ordinal);
		if (num < 0)
		{
			return existing;
		}
		string text2 = existing.Remove(num, text.Length);
		if (addedHeader && text2.EndsWith("\n\nInstalled Mods:", StringComparison.Ordinal))
		{
			text2 = text2.Substring(0, text2.Length - "\n\nInstalled Mods:".Length);
		}
		return text2;
	}
}
internal sealed class LoginModBadge : IDisposable
{
	private const string LoginScene = "Login";

	private const string TargetObjectName = "Copyright Text";

	private readonly string _name;

	private readonly string _version;

	private readonly ManualLogSource _log;

	private TMP_Text _target;

	private bool _addedHeader;

	public LoginModBadge(string modName, string modVersion, ManualLogSource log)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		_name = modName;
		_version = modVersion;
		_log = log;
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.sceneUnloaded += OnSceneUnloaded;
		Apply(SceneManager.GetActiveScene());
	}

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

	private void OnSceneUnloaded(Scene scene)
	{
		if (!(((Scene)(ref scene)).name != "Login"))
		{
			_target = null;
			_addedHeader = false;
		}
	}

	private void Apply(Scene scene)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (!((Scene)(ref scene)).IsValid() || ((Scene)(ref scene)).name != "Login")
		{
			return;
		}
		try
		{
			TMP_Text[] array = Object.FindObjectsOfType<TMP_Text>(true);
			foreach (TMP_Text val in array)
			{
				if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "Copyright Text") && !(((Component)val).gameObject.scene != scene))
				{
					bool addedHeader;
					bool modified;
					string text = LoginModListFormatter.Append(val.text, _name, _version, out addedHeader, out modified);
					if (modified)
					{
						_target = val;
						_addedHeader = addedHeader;
						val.text = text;
					}
					break;
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogWarning((object)("Could not register login screen mod badge: " + ex.Message));
			}
		}
	}

	public void Dispose()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
		SceneManager.sceneUnloaded -= OnSceneUnloaded;
		if ((Object)(object)_target == (Object)null)
		{
			return;
		}
		try
		{
			string text = LoginModListFormatter.Remove(_target.text, _name, _version, _addedHeader);
			if (!string.Equals(_target.text, text, StringComparison.Ordinal))
			{
				_target.text = text;
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogWarning((object)("Could not remove login screen mod badge: " + ex.Message));
			}
		}
		_target = null;
		_addedHeader = false;
	}
}
internal readonly struct BoardSlice
{
	public readonly Bounds HideVolume;

	private readonly bool _hasHide;

	private readonly Vector3 _hideMin;

	private readonly Vector3 _hideMax;

	private readonly bool _hasCut;

	private readonly Vector3 _cutMin;

	private readonly Vector3 _cutMax;

	public BoardSlice(Bounds hideVolume, Bounds cutVolume)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		HideVolume = hideVolume;
		_hasHide = ((Bounds)(ref hideVolume)).size.y > 0f;
		_hideMin = ((Bounds)(ref hideVolume)).min;
		_hideMax = ((Bounds)(ref hideVolume)).max;
		_hasCut = ((Bounds)(ref cutVolume)).size.y > 0f;
		_cutMin = ((Bounds)(ref cutVolume)).min;
		_cutMax = ((Bounds)(ref cutVolume)).max;
	}

	public bool Hides(Vector3 p)
	{
		//IL_0008: 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_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		if (!_hasHide || !(p.x >= _hideMin.x) || !(p.x <= _hideMax.x) || !(p.y >= _hideMin.y) || !(p.y <= _hideMax.y) || !(p.z >= _hideMin.z) || !(p.z <= _hideMax.z))
		{
			if (_hasCut && p.x >= _cutMin.x && p.x <= _cutMax.x && p.y >= _cutMin.y && p.y <= _cutMax.y && p.z >= _cutMin.z)
			{
				return p.z <= _cutMax.z;
			}
			return false;
		}
		return true;
	}

	public float ExtendEmissionDepth(Vector3 eye, Vector3 forward, float depth, float far)
	{
		//IL_0008: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		if (!_hasHide || forward.y > -0.05f)
		{
			return depth;
		}
		float y = _hideMin.y;
		float num = (eye.y - y + 0.65f) / (0f - forward.y);
		if (num <= depth || num >= far)
		{
			return depth;
		}
		Vector3 val = eye + forward * ((eye.y - y) / (0f - forward.y));
		if (!(val.x >= _hideMin.x) || !(val.x <= _hideMax.x) || !(val.z >= _hideMin.z) || !(val.z <= _hideMax.z))
		{
			return depth;
		}
		return num;
	}
}
internal interface IRoofSampler
{
	float SampleRoof(float x, float z);
}
internal sealed class PrecipitationMask
{
	private struct Slot
	{
		public int X;

		public int Z;

		public float Height;

		public float RefreshAt;

		public bool Valid;
	}

	private const float CellSize = 0.5f;

	private const float InvCellSize = 2f;

	private const int FillSamplesPerFrame = 24;

	private const int TrickleRefreshPerFrame = 2;

	private const int Ways = 4;

	private const int SetCount = 2048;

	private const int SetMask = 2047;

	private const float RefreshSeconds = 6f;

	private readonly IRoofSampler _sampler;

	private readonly Slot[] _slots = new Slot[8192];

	private float _time;

	private float _maxShelterY = float.PositiveInfinity;

	private int _fillBudget;

	private int _refreshBudget;

	public PrecipitationMask(IRoofSampler sampler)
	{
		_sampler = sampler;
	}

	public void BeginFrame(float maxShelterY = float.PositiveInfinity)
	{
		BeginFrame(Time.unscaledTime, maxShelterY);
	}

	public void BeginFrame(float time, float maxShelterY = float.PositiveInfinity)
	{
		_time = time;
		_maxShelterY = maxShelterY;
		_fillBudget = 24;
		_refreshBudget = 2;
	}

	public static int ComputeSetOffset(int cx, int cz)
	{
		return (((cx * 73856093) ^ (cz * 19349663)) & 0x7FF) * 4;
	}

	public bool TrySampleColumn(Vector3 position, out bool sheltered, out float roofHeight)
	{
		//IL_0000: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		if (position.y > _maxShelterY)
		{
			roofHeight = float.NegativeInfinity;
			sheltered = false;
			return true;
		}
		int num = Mathf.FloorToInt(position.x * 2f);
		int num2 = Mathf.FloorToInt(position.z * 2f);
		int num3 = ComputeSetOffset(num, num2);
		int num4 = -1;
		int num5 = num3;
		float num6 = float.PositiveInfinity;
		for (int i = 0; i < 4; i++)
		{
			int num7 = num3 + i;
			ref Slot reference = ref _slots[num7];
			if (!reference.Valid)
			{
				if (num6 > float.NegativeInfinity)
				{
					num5 = num7;
					num6 = float.NegativeInfinity;
				}
				continue;
			}
			if (reference.X == num && reference.Z == num2)
			{
				num4 = num7;
				break;
			}
			if (reference.RefreshAt < num6)
			{
				num6 = reference.RefreshAt;
				num5 = num7;
			}
		}
		if (num4 >= 0)
		{
			ref Slot reference2 = ref _slots[num4];
			if (reference2.RefreshAt <= _time && _refreshBudget > 0)
			{
				_refreshBudget--;
				reference2.Height = _sampler.SampleRoof(((float)num + 0.5f) * 0.5f, ((float)num2 + 0.5f) * 0.5f);
				reference2.RefreshAt = _time + 6f;
			}
			roofHeight = reference2.Height;
			sheltered = position.y <= reference2.Height;
			return true;
		}
		if (_fillBudget > 0)
		{
			_fillBudget--;
			float num8 = _sampler.SampleRoof(((float)num + 0.5f) * 0.5f, ((float)num2 + 0.5f) * 0.5f);
			_slots[num5] = new Slot
			{
				X = num,
				Z = num2,
				Height = num8,
				RefreshAt = _time + 6f,
				Valid = true
			};
			roofHeight = num8;
			sheltered = position.y <= num8;
			return true;
		}
		roofHeight = float.NegativeInfinity;
		sheltered = false;
		return false;
	}

	public void Clear()
	{
		Array.Clear(_slots, 0, _slots.Length);
	}
}
internal sealed class PuddleCoverage : IDisposable
{
	private struct Cell
	{
		public Vector2Int Position;

		public Vector2 Heights;

		public bool Sampled;
	}

	public static readonly Vector2 NoSurface = new Vector2(-1000000f, -1000000f);

	private const int Side = 48;

	private const int FillSamplesPerFrame = 12;

	private const int TrickleVerifyPerFrame = 2;

	private const int AnchorStep = 4;

	private const float UploadInterval = 0.16f;

	private readonly Cell[] _cache = new Cell[2304];

	private readonly Vector2[] _pixels = (Vector2[])(object)new Vector2[2304];

	private readonly Vector2Int[] _scanOrder = MakeScanOrder();

	private Vector2Int _origin;

	private Vector2Int _anchor;

	private int _fillCursor;

	private int _verifyCursor;

	private float _nextUpload;

	private bool _placed;

	private bool _dirty;

	public Texture2D Texture { get; }

	public Vector4 Region => new Vector4((float)((Vector2Int)(ref _origin)).x, (float)((Vector2Int)(ref _origin)).y, 48f, 1f / 48f);

	public PuddleCoverage()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		if (SystemInfo.SupportsTextureFormat((TextureFormat)19))
		{
			Texture = new Texture2D(48, 48, (TextureFormat)19, false, true)
			{
				name = "Rain exposed tiles",
				hideFlags = (HideFlags)52,
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1
			};
		}
	}

	private static Vector2Int[] MakeScanOrder()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Vector2Int[] array = (Vector2Int[])(object)new Vector2Int[2304];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new Vector2Int(i % 48, i / 48);
		}
		Array.Sort(array, delegate(Vector2Int a, Vector2Int b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			Vector2Int val = a - new Vector2Int(24, 24);
			int sqrMagnitude = ((Vector2Int)(ref val)).sqrMagnitude;
			val = b - new Vector2Int(24, 24);
			return sqrMagnitude.CompareTo(((Vector2Int)(ref val)).sqrMagnitude);
		});
		return array;
	}

	private static int Modulo(int value)
	{
		return (value % 48 + 48) % 48;
	}

	private ref Cell At(Vector2Int position)
	{
		return ref _cache[Modulo(((Vector2Int)(ref position)).y) * 48 + Modulo(((Vector2Int)(ref position)).x)];
	}

	public void Update(Vector3 focus, Func<float, float, Vector2> sample)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Texture == (Object)null)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		Vector2Int val = default(Vector2Int);
		((Vector2Int)(ref val))..ctor(Mathf.FloorToInt(focus.x / 4f) * 4, Mathf.FloorToInt(focus.z / 4f) * 4);
		bool flag = !_placed || val != _anchor;
		if (flag)
		{
			_anchor = val;
			_origin = val - new Vector2Int(24, 24);
			_fillCursor = 0;
			_placed = true;
			_dirty = true;
		}
		int num = 0;
		for (int i = 0; i < _scanOrder.Length; i++)
		{
			if (num >= 12)
			{
				break;
			}
			Vector2Int val2 = _origin + _scanOrder[_fillCursor];
			_fillCursor = (_fillCursor + 1) % _scanOrder.Length;
			ref Cell reference = ref At(val2);
			if (!reference.Sampled || !(reference.Position == val2))
			{
				Vector2 heights = sample((float)((Vector2Int)(ref val2)).x + 0.5f, (float)((Vector2Int)(ref val2)).y + 0.5f);
				reference = new Cell
				{
					Position = val2,
					Heights = heights,
					Sampled = true
				};
				_dirty = true;
				num++;
			}
		}
		if (num == 0)
		{
			for (int j = 0; j < 2; j++)
			{
				Vector2Int val3 = _origin + _scanOrder[_verifyCursor];
				_verifyCursor = (_verifyCursor + 1) % _scanOrder.Length;
				ref Cell reference2 = ref At(val3);
				Vector2 val4 = sample((float)((Vector2Int)(ref val3)).x + 0.5f, (float)((Vector2Int)(ref val3)).y + 0.5f);
				if (!reference2.Sampled || reference2.Position != val3 || !SameHeights(reference2.Heights, val4))
				{
					reference2 = new Cell
					{
						Position = val3,
						Heights = val4,
						Sampled = true
					};
					_dirty = true;
				}
			}
		}
		if (_dirty && (flag || !(unscaledTime < _nextUpload)))
		{
			for (int k = 0; k < _pixels.Length; k++)
			{
				Vector2Int val5 = _origin + new Vector2Int(k % 48, k / 48);
				ref Cell reference3 = ref At(val5);
				_pixels[k] = ((reference3.Sampled && reference3.Position == val5) ? reference3.Heights : NoSurface);
			}
			Texture.SetPixelData<Vector2>(_pixels, 0, 0);
			Texture.Apply(false, false);
			_nextUpload = unscaledTime + 0.16f;
			_dirty = false;
		}
	}

	private static bool SameHeights(Vector2 a, Vector2 b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (Mathf.Abs(a.x - b.x) <= 0.002f)
		{
			return Mathf.Abs(a.y - b.y) <= 0.002f;
		}
		return false;
	}

	public void Clear()
	{
		if (_placed)
		{
			Array.Clear(_cache, 0, _cache.Length);
			_placed = false;
			_dirty = false;
		}
	}

	public void Dispose()
	{
		if ((Object)(object)Texture != (Object)null)
		{
			Object.Destroy((Object)(object)Texture);
		}
	}
}
internal sealed class RainAudio : IDisposable
{
	private struct Track
	{
		public bool Found;

		public InternedContentAddress Id;

		public Packed ClipAddress;

		public AudioSource Source;

		public FetchKey Fetch;

		public int Failures;

		public float RetryAt;
	}

	private readonly GameObject _owner;

	private readonly Track[] _tracks = new Track[3];

	private float _retry;

	public RainAudio(GameObject owner)
	{
		_owner = owner;
	}

	private AudioSource CreateSource()
	{
		AudioSource val = _owner.AddComponent<AudioSource>();
		val.playOnAwake = false;
		val.loop = true;
		val.spatialBlend = 0f;
		val.volume = 0f;
		if (SimpleSingletonBehaviour<AtmosphereManager>.HasInstance)
		{
			AudioSource[] components = ((Component)SimpleSingletonBehaviour<AtmosphereManager>.Instance).GetComponents<AudioSource>();
			if (components.Length != 0)
			{
				val.outputAudioMixerGroup = components[0].outputAudioMixerGroup;
			}
		}
		return val;
	}

	public void Update(in WeatherFrame frame, int nextTier, bool sheltered, float userVolume)
	{
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if (userVolume <= 0.001f || !SimpleSingletonBehaviour<AssetDb>.HasInstance || !SimpleSingletonBehaviour<AtmosphereManager>.HasInstance)
		{
			Stop();
			return;
		}
		if (!_tracks[1].Found && Time.unscaledTime >= _retry)
		{
			_retry = Time.unscaledTime + 4f;
			FindTracks();
		}
		AtmosphereReferenceData currentReferenceData = AtmosphereManager.GetCurrentReferenceData();
		if (currentReferenceData == null)
		{
			return;
		}
		Track[] tracks = _tracks;
		for (int i = 0; i < tracks.Length; i++)
		{
			Track track = tracks[i];
			if (track.Found)
			{
				InternedContentAddress ambientMusic = currentReferenceData.AmbientMusic;
				if (((InternedContentAddress)(ref ambientMusic)).Equals(track.Id))
				{
					Stop();
					return;
				}
			}
		}
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(frame.RainVolume(Intensity.Light), frame.RainVolume(Intensity.Moderate), frame.RainVolume(Intensity.Heavy));
		for (int j = 0; j < _tracks.Length; j++)
		{
			if (j != 1 && (!_tracks[j].Found || _tracks[j].Failures >= 2))
			{
				val.y += ((Vector3)(ref val))[j];
				((Vector3)(ref val))[j] = 0f;
				if (nextTier == j)
				{
					nextTier = 1;
				}
			}
		}
		float num = Mathf.Clamp01(((currentReferenceData.AmbientVolume < 0f) ? 0.25f : Mathf.Clamp01(currentReferenceData.AmbientVolume)) * Mathf.Clamp(userVolume, 0f, 1.5f)) * (sheltered ? 0.32f : 1f);
		for (int k = 0; k < _tracks.Length; k++)
		{
			if (_tracks[k].Found)
			{
				UpdateTrack(ref _tracks[k], ((Vector3)(ref val))[k] * num, k == nextTier || ((Vector3)(ref val))[k] > 0f);
			}
		}
	}

	private void UpdateTrack(ref Track track, float volume, bool needed)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Invalid comparison between Unknown and I4
		//IL_0104: 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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Invalid comparison between Unknown and I4
		if (!needed)
		{
			StopTrack(ref track);
		}
		else
		{
			if (track.Failures >= 2 || Time.unscaledTime < track.RetryAt)
			{
				return;
			}
			if ((Object)(object)track.Source == (Object)null)
			{
				track.Source = CreateSource();
			}
			if ((Object)(object)track.Source.clip == (Object)null && !((FetchKey)(ref track.Fetch)).IsCreated)
			{
				Packed clipAddress = track.ClipAddress;
				track.Fetch = ContentManager.FetchAudioClip(ref clipAddress, track.Failures > 0);
				if (!((FetchKey)(ref track.Fetch)).IsCreated)
				{
					MarkFailure(ref track);
					return;
				}
			}
			if (((FetchKey)(ref track.Fetch)).IsCreated && (Object)(object)track.Source.clip == (Object)null)
			{
				InternedContentAddress val2 = default(InternedContentAddress);
				float num = default(float);
				AudioClip val3 = default(AudioClip);
				ContentLoadFailureReason val4 = default(ContentLoadFailureReason);
				FetchState val = ContentManager.TryGetAudioClip(track.Fetch, ref val2, ref num, ref val3, ref val4);
				if ((int)val == 2)
				{
					track.Fetch = default(FetchKey);
					track.Source.clip = val3;
					if ((Object)(object)val3 != (Object)null)
					{
						track.Source.Play();
						track.Failures = 0;
					}
					else
					{
						MarkFailure(ref track);
					}
				}
				else if ((int)val == 0 || (int)val == 3)
				{
					ContentManager.AbandonFetch(ref track.Fetch);
					MarkFailure(ref track);
				}
			}
			track.Source.volume = Mathf.MoveTowards(track.Source.volume, volume, Time.unscaledDeltaTime);
		}
	}

	private static void MarkFailure(ref Track track)
	{
		track.Failures++;
		track.RetryAt = Time.unscaledTime + 4f;
		if (track.Failures == 2)
		{
			Debug.LogWarning((object)"TSDynamicWeatherEffects: the game could not load the rain audio after retrying.");
		}
	}

	private void FindTracks()
	{
		//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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Invalid comparison between Unknown and I4
		//IL_0093: 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)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		NativeParallelHashMap<InternedContentAddress, UnsafeView<MusicDataV0>> music = InternalPackManager.Music;
		if (!music.IsCreated)
		{
			return;
		}
		NativeKeyValueArrays<InternedContentAddress, UnsafeView<MusicDataV0>> keyValueArrays = music.GetKeyValueArrays(AllocatorHandle.op_Implicit((Allocator)2));
		try
		{
			int num = 0;
			while (true)
			{
				int num2 = num;
				NativeArray<InternedContentAddress> keys = keyValueArrays.Keys;
				if (num2 >= keys.Length)
				{
					break;
				}
				NativeArray<UnsafeView<MusicDataV0>> values = keyValueArrays.Values;
				ref MusicDataV0 value = ref values[num].Value;
				if ((int)value.Kind == 1)
				{
					int num3 = WeatherPresets.RainTrackTier(((String)(ref value.Name)).GetString());
					if (num3 >= 0 && !_tracks[num3].Found)
					{
						_tracks[num3].Found = true;
						ref Track reference = ref _tracks[num3];
						keys = keyValueArrays.Keys;
						reference.Id = keys[num];
						_tracks[num3].ClipAddress = value.Address;
					}
				}
				num++;
			}
		}
		finally
		{
			((IDisposable)keyValueArrays/*cast due to .constrained prefix*/).Dispose();
		}
	}

	public void AllowRetry()
	{
		for (int i = 0; i < _tracks.Length; i++)
		{
			_tracks[i].Failures = 0;
			_tracks[i].RetryAt = 0f;
		}
	}

	public void Stop()
	{
		for (int i = 0; i < _tracks.Length; i++)
		{
			StopTrack(ref _tracks[i]);
		}
	}

	private static void StopTrack(ref Track track)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)track.Source != (Object)null && ((Object)(object)track.Source.clip != (Object)null || track.Source.volume != 0f))
		{
			if (track.Source.isPlaying)
			{
				track.Source.Stop();
			}
			track.Source.clip = null;
			track.Source.volume = 0f;
		}
		if (((FetchKey)(ref track.Fetch)).IsCreated)
		{
			ContentManager.AbandonFetch(ref track.Fetch);
		}
		track.Fetch = default(FetchKey);
	}

	public void Dispose()
	{
		Stop();
		for (int i = 0; i < _tracks.Length; i++)
		{
			if ((Object)(object)_tracks[i].Source != (Object)null)
			{
				Object.Destroy((Object)(object)_tracks[i].Source);
				_tracks[i].Source = null;
			}
		}
	}
}
internal sealed class RainLighting
{
	private const float Tolerance = 0.0005f;

	private static readonly FieldInfo AtmosphereSun = typeof(AtmosphereApplier).GetField("_sunLight", BindingFlags.Instance | BindingFlags.NonPublic);

	private Light _sun;

	private float _nextSunSearch;

	private bool _hasAmbient;

	private bool _hasSun;

	private float _ambient;

	private float _direct;

	private float _shadows;

	private Color _sky;

	private Color _sunColor;

	private float _lastAmbient;

	private float _lastDirect;

	private float _lastShadows;

	private Color _lastSky;

	private Color _lastSunColor;

	public void Apply(float rainWeight, float snowWeight, bool enabled)
	{
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Invalid comparison between Unknown and I4
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		if (!enabled || (rainWeight <= 0f && snowWeight <= 0f))
		{
			Restore();
			return;
		}
		if ((Object)(object)_sun == (Object)null && Time.unscaledTime >= _nextSunSearch)
		{
			_nextSunSearch = Time.unscaledTime + 1f;
			AtmosphereApplier val = Object.FindObjectOfType<AtmosphereApplier>();
			_sun = (Light)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)_sun == (Object)null)
			{
				_sun = RenderSettings.sun;
			}
			_hasSun = false;
		}
		float num = Mathf.Clamp01(0.12f * rainWeight + 0.05f * snowWeight);
		float amount = Mathf.Clamp01(0.3f * rainWeight + 0.2f * snowWeight);
		float num2 = Mathf.Clamp01(0.4f * rainWeight + 0.18f * snowWeight);
		float num3 = Mathf.Clamp01(0.45f * rainWeight + 0.24f * snowWeight);
		float amount2 = Mathf.Clamp01(0.28f * rainWeight + 0.16f * snowWeight);
		float ambientIntensity = RenderSettings.ambientIntensity;
		Color ambientSkyColor = RenderSettings.ambientSkyColor;
		if (!_hasAmbient || !Near(ambientIntensity, _lastAmbient))
		{
			_ambient = ambientIntensity;
		}
		if (!_hasAmbient || !NearColor(ambientSkyColor, _lastSky))
		{
			_sky = ambientSkyColor;
		}
		float num4 = _ambient * (1f - num);
		Color val2 = Mute(_sky, amount);
		if (!Near(ambientIntensity, num4))
		{
			RenderSettings.ambientIntensity = num4;
		}
		if (!NearColor(ambientSkyColor, val2))
		{
			RenderSettings.ambientSkyColor = val2;
		}
		_lastAmbient = RenderSettings.ambientIntensity;
		_lastSky = RenderSettings.ambientSkyColor;
		_hasAmbient = true;
		if (!((Object)(object)_sun == (Object)null) && (int)_sun.type == 1)
		{
			float intensity = _sun.intensity;
			float shadowStrength = _sun.shadowStrength;
			Color color = _sun.color;
			if (!_hasSun || !Near(intensity, _lastDirect))
			{
				_direct = intensity;
			}
			if (!_hasSun || !Near(shadowStrength, _lastShadows))
			{
				_shadows = shadowStrength;
			}
			if (!_hasSun || !NearColor(color, _lastSunColor))
			{
				_sunColor = color;
			}
			float num5 = _direct * (1f - num2);
			float num6 = _shadows * (1f - num3);
			Color val3 = Mute(_sunColor, amount2);
			if (!Near(intensity, num5))
			{
				_sun.intensity = num5;
			}
			if (!Near(shadowStrength, num6))
			{
				_sun.shadowStrength = num6;
			}
			if (!NearColor(color, val3))
			{
				_sun.color = val3;
			}
			_lastDirect = _sun.intensity;
			_lastShadows = _sun.shadowStrength;
			_lastSunColor = _sun.color;
			_hasSun = true;
		}
	}

	private static bool Near(float a, float b)
	{
		return Mathf.Abs(a - b) <= 0.0005f;
	}

	private static bool NearColor(Color a, Color b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if (Near(a.r, b.r) && Near(a.g, b.g) && Near(a.b, b.b))
		{
			return Near(a.a, b.a);
		}
		return false;
	}

	private static Color Mute(Color color, float amount)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		float grayscale = ((Color)(ref color)).grayscale;
		return Color.Lerp(color, new Color(grayscale * 0.96f, grayscale * 0.99f, Mathf.Min(1f, grayscale * 1.04f), color.a), amount);
	}

	public void Restore()
	{
		RestoreBeforeAtmosphere();
		_sun = null;
		_nextSunSearch = 0f;
	}

	public void RestoreBeforeAtmosphere()
	{
		//IL_0025: 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_0038: 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_00c0: 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)
		if (_hasAmbient)
		{
			if (Near(RenderSettings.ambientIntensity, _lastAmbient))
			{
				RenderSettings.ambientIntensity = _ambient;
			}
			if (NearColor(RenderSettings.ambientSkyColor, _lastSky))
			{
				RenderSettings.ambientSkyColor = _sky;
			}
			_hasAmbient = false;
		}
		if (_hasSun && (Object)(object)_sun != (Object)null)
		{
			if (Near(_sun.intensity, _lastDirect))
			{
				_sun.intensity = _direct;
			}
			if (Near(_sun.shadowStrength, _lastShadows))
			{
				_sun.shadowStrength = _shadows;
			}
			if (NearColor(_sun.color, _lastSunColor))
			{
				_sun.color = _sunColor;
			}
		}
		_hasSun = false;
	}
}
internal sealed class RainSurface : IDisposable
{
	private const CameraEvent SurfaceEvent = (CameraEvent)16;

	private const CameraEvent DropsEvent = (CameraEvent)19;

	private static readonly int SurfaceCopy = Shader.PropertyToID("_TSWeatherOpaqueCopy");

	private static readonly int DropsCopy = Shader.PropertyToID("_TSWeatherDropsCopy");

	private static readonly int Region = Shader.PropertyToID("_WeatherRegion");

	private static readonly int Params = Shader.PropertyToID("_WeatherParams");

	private static readonly int DepthStep = Shader.PropertyToID("_WeatherDepthStep");

	private static readonly int Puddles = Shader.PropertyToID("_WeatherPuddles");

	private static readonly int Projection = Shader.PropertyToID("_WeatherInvProjection");

	private static readonly int CameraToWorld = Shader.PropertyToID("_WeatherCameraToWorld");

	private static readonly int DropAspect = Shader.PropertyToID("_WeatherDropInvAspect");

	private readonly CommandBuffer _surfaces = new CommandBuffer
	{
		name = "TaleSpire wet opaque surfaces"
	};

	private readonly CommandBuffer _droplets = new CommandBuffer
	{
		name = "TaleSpire screen droplets"
	};

	private readonly PuddleCoverage _coverage = new PuddleCoverage();

	private readonly ScreenDroplets _screenDrops = new ScreenDroplets();

	private readonly Stream _bundleStream;

	private readonly AssetBundle _bundle;

	private readonly Material _material;

	private readonly Texture2D _noise;

	private Camera _camera;

	private bool _surfaceHdr;

	private bool _surfaceAttached;

	private bool _dropsAttached;

	private float _wetness;

	private float _ripples;

	private float _puddles;

	private float _openSky;

	private int _dropWidth;

	private int _dropHeight;

	private GraphicsFormat _dropFormat;

	public RainSurface()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		try
		{
			_bundleStream = typeof(RainSurface).Assembly.GetManifestResourceStream("TSDynamicWeather.Shader");
			if (_bundleStream == null)
			{
				throw new InvalidOperationException("Weather shader resource is missing.");
			}
			_bundle = AssetBundle.LoadFromStream(_bundleStream);
			Shader val = (((Object)(object)_bundle != (Object)null) ? _bundle.LoadAsset<Shader>("Assets/WeatherSurface.shader") : null);
			if ((Object)(object)val == (Object)null || !val.isSupported)
			{
				throw new InvalidOperationException("Weather surface shader is unsupported.");
			}
			_material = new Material(val)
			{
				hideFlags = (HideFlags)52
			};
			_noise = MakeNoise();
			_material.SetTexture("_WeatherNoise", (Texture)(object)_noise);
			if ((Object)(object)_coverage.Texture != (Object)null)
			{
				_material.SetTexture("_WeatherCover", (Texture)(object)_coverage.Texture);
			}
			Camera.onPreRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreRender, (Delegate?)new CameraCallback(PrepareCamera));
		}
		catch
		{
			Dispose();
			throw;
		}
	}

	private static Texture2D MakeNoise()
	{
		//IL_00b1: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[16384];
		for (int i = 0; i < 128; i++)
		{
			for (int j = 0; j < 128; j++)
			{
				float u = ((float)j + 0.5f) / 128f;
				float v = ((float)i + 0.5f) / 128f;
				byte b = (byte)(Mathf.Clamp01(0.76f * TileNoise(u, v, 9f) + 0.24f * TileNoise(u, v, 25f)) * 255f);
				array[i * 128 + j] = new Color32(b, b, b, byte.MaxValue);
			}
		}
		Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true, true)
		{
			name = "Rain puddle Perlin noise",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)0,
			filterMode = (FilterMode)2
		};
		val.SetPixels32(array);
		val.Apply(true, true);
		return val;
	}

	private static float TileNoise(float u, float v, float span)
	{
		float num = 18.7f + u * span;
		float num2 = 42.4f + v * span;
		float num3 = Mathf.SmoothStep(0f, 1f, u);
		float num4 = Mathf.SmoothStep(0f, 1f, v);
		return Mathf.Lerp(Mathf.Lerp(Mathf.PerlinNoise(num, num2), Mathf.PerlinNoise(num - span, num2), num3), Mathf.Lerp(Mathf.PerlinNoise(num, num2 - span), Mathf.PerlinNoise(num - span, num2 - span), num3), num4);
	}

	public void Update(Camera camera, Vector3 focus, Func<float, float, Vector2> sampleSurface, float rainStrength, float puddles, bool sheltered, bool drawWetSurfaces, bool drawRipples, bool drawDrops)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Invalid comparison between Unknown and I4
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Invalid comparison between Unknown and I4
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		_wetness = rainStrength;
		_ripples = (drawRipples ? rainStrength : 0f);
		_puddles = puddles;
		if ((Object)(object)_camera == (Object)null)
		{
			_openSky = (sheltered ? 0f : 1f);
		}
		_openSky = Mathf.MoveTowards(_openSky, sheltered ? 0f : 1f, Time.unscaledDeltaTime * 0.9f);
		if ((Object)(object)_camera != (Object)(object)camera || _surfaceHdr != camera.allowHDR)
		{
			Detach();
			_camera = camera;
			_surfaceHdr = camera.allowHDR;
			RecordSurfacePass();
			_dropWidth = (_dropHeight = 0);
		}
		bool flag = (int)camera.actualRenderingPath == 3 || (camera.depthTextureMode & 1) > 0;
		bool flag2 = drawWetSurfaces && flag && (Object)(object)_coverage.Texture != (Object)null && (rainStrength > 0f || puddles > 0f);
		if (flag2)
		{
			_coverage.Update(focus, sampleSurface);
		}
		SetPass((CameraEvent)16, _surfaces, flag2, ref _surfaceAttached);
		float spawnRain = ((drawDrops && !sheltered) ? (rainStrength * _openSky) : 0f);
		bool flag3 = _screenDrops.Update(Time.unscaledDeltaTime, spawnRain, Mathf.Max(0.01f, camera.aspect));
		if (flag3)
		{
			PrepareDropsPass(camera);
		}
		SetPass((CameraEvent)19, _droplets, flag3, ref _dropsAttached);
	}

	private void RecordSurfacePass()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		_surfaces.Clear();
		_surfaces.GetTemporaryRT(SurfaceCopy, -1, -1, 0, (FilterMode)1, (RenderTextureFormat)(_surfaceHdr ? 9 : 7));
		_surfaces.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), RenderTargetIdentifier.op_Implicit(SurfaceCopy));
		_surfaces.Blit(RenderTargetIdentifier.op_Implicit(SurfaceCopy), RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), _material, 0);
		_surfaces.ReleaseTemporaryRT(SurfaceCopy);
	}

	private void PrepareDropsPass(Camera camera)
	{
		//IL_0033: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_00ac: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Max(1, camera.scaledPixelWidth);
		int num2 = Mathf.Max(1, camera.scaledPixelHeight);
		RenderTexture targetTexture = camera.targetTexture;
		GraphicsFormat val = (((Object)(object)targetTexture != (Object)null) ? targetTexture.graphicsFormat : SystemInfo.GetGraphicsFormat((DefaultFormat)0));
		if (_dropWidth != num || _dropHeight != num2 || _dropFormat != val)
		{
			_dropWidth = num;
			_dropHeight = num2;
			_dropFormat = val;
			_droplets.Clear();
			_droplets.GetTemporaryRT(DropsCopy, num, num2, 0, (FilterMode)1, val);
			_droplets.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), RenderTargetIdentifier.op_Implicit(DropsCopy));
			_droplets.SetRenderTarget(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2));
			_droplets.DrawMesh(_screenDrops.Mesh, Matrix4x4.identity, _material, 0, 1);
			_droplets.ReleaseTemporaryRT(DropsCopy);
		}
	}

	private void SetPass(CameraEvent stage, CommandBuffer buffer, bool active, ref bool attached)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (active == attached)
		{
			return;
		}
		if ((Object)(object)_camera != (Object)null)
		{
			if (active)
			{
				_camera.AddCommandBuffer(stage, buffer);
			}
			else
			{
				_camera.RemoveCommandBuffer(stage, buffer);
			}
		}
		attached = active;
	}

	private void PrepareCamera(Camera camera)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)camera != (Object)(object)_camera))
		{
			if (_surfaceAttached)
			{
				Material material = _material;
				int projection = Projection;
				Matrix4x4 gPUProjectionMatrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
				material.SetMatrix(projection, ((Matrix4x4)(ref gPUProjectionMatrix)).inverse);
				_material.SetMatrix(CameraToWorld, camera.cameraToWorldMatrix);
				_material.SetVector(Region, ((Object)(object)_coverage.Texture == (Object)null) ? Vector4.zero : _coverage.Region);
				_material.SetVector(Params, new Vector4(_wetness, _ripples, Time.unscaledTime, 0f));
				float num = 2.5f / (float)Mathf.Max(1, camera.scaledPixelWidth);
				float num2 = 2.5f / (float)Mathf.Max(1, camera.scaledPixelHeight);
				_material.SetVector(DepthStep, new Vector4(num, num2, 0f, 0f));
				_material.SetFloat(Puddles, _puddles);
			}
			if (_dropsAttached)
			{
				_material.SetFloat(DropAspect, 1f / Mathf.Max(0.01f, camera.aspect));
			}
		}
	}

	private void Detach()
	{
		SetPass((CameraEvent)16, _surfaces, active: false, ref _surfaceAttached);
		SetPass((CameraEvent)19, _droplets, active: false, ref _dropsAttached);
		_camera = null;
	}

	public void Stop()
	{
		Detach();
		_coverage.Clear();
		_screenDrops.ClearImmediate();
		_wetness = (_ripples = (_puddles = (_openSky = 0f)));
	}

	public void Dispose()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		Camera.onPreRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreRender, (Delegate?)new CameraCallback(PrepareCamera));
		Detach();
		_surfaces.Release();
		_droplets.Release();
		_screenDrops.Dispose();
		_coverage.Dispose();
		if ((Object)(object)_material != (Object)null)
		{
			Object.Destroy((Object)(object)_material);
		}
		if ((Object)(object)_noise != (Object)null)
		{
			Object.Destroy((Object)(object)_noise);
		}
		if ((Object)(object)_bundle != (Object)null)
		{
			_bundle.Unload(true);
		}
		_bundleStream?.Dispose();
	}
}
internal sealed class ScreenDroplets : IDisposable
{
	private struct Drop
	{
		public Vector2 Origin;

		public float Age;

		public float Life;

		public float Radius;

		public float Stretch;

		public float Hold;

		public float Speed;

		public float Drift;

		public float WobblePhase;
	}

	private const int Capacity = 22;

	private const float SpawnThreshold = 0.005f;

	private readonly Random _random;

	private readonly Drop[] _drops = new Drop[22];

	private readonly Vector3[] _vertices = (Vector3[])(object)new Vector3[88];

	private readonly Vector4[] _shape = (Vector4[])(object)new Vector4[88];

	private int _count;

	private int _meshCount;

	private float _untilSpawn = 0.22f;

	private float _presence;

	public Mesh Mesh { get; private set; }

	public int ActiveCount => _count;

	public ScreenDroplets(Random random = null, bool createMesh = true)
	{
		_random = random ?? new Random();
		if (createMesh)
		{
			InitMesh();
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private void InitMesh()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_002f: 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)
		Mesh = new Mesh
		{
			name = "TaleSpire screen droplets",
			hideFlags = (HideFlags)52
		};
		Mesh.MarkDynamic();
		Mesh.bounds = new Bounds(Vector3.zero, new Vector3(2f, 2f, 1f));
		int[] array = new int[132];
		for (int i = 0; i < 22; i++)
		{
			int num = 4 * i;
			int num2 = 6 * i;
			array[num2] = num;
			array[num2 + 1] = num + 2;
			array[num2 + 2] = num + 1;
			array[num2 + 3] = num + 1;
			array[num2 + 4] = num + 2;
			array[num2 + 5] = num + 3;
		}
		Mesh.SetVertices(_vertices, 0, _vertices.Length, (MeshUpdateFlags)8);
		Mesh.SetUVs(0, _shape, 0, _shape.Length, (MeshUpdateFlags)8);
		Mesh.SetTriangles(array, 0, false);
		_meshCount = 22;
		SetVisibleCount(0);
	}

	public bool Update(float seconds, float spawnRain, float aspect)
	{
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		bool flag = spawnRain > 0.005f;
		float num = (flag ? Mathf.Clamp01(Mathf.Sqrt(spawnRain)) : 0f);
		float num2 = ((num > _presence) ? 1.8f : 0.42f);
		_presence = Mathf.MoveTowards(_presence, num, seconds * num2);
		if (!flag && (_count == 0 || _presence <= 0.001f))
		{
			ClearImmediate();
			return false;
		}
		if (flag)
		{
			_untilSpawn -= seconds * Mathf.Lerp(0.45f, 1.15f, Mathf.Clamp01(spawnRain));
			while (_untilSpawn <= 0f)
			{
				if (_count < 22)
				{
					_drops[_count++] = NewDrop();
				}
				_untilSpawn += Range(0.28f, 0.62f);
			}
		}
		int num3 = 0;
		float num4 = (flag ? 1f : 1.55f);
		int num5 = 0;
		while (num5 < _count)
		{
			ref Drop reference = ref _drops[num5];
			reference.Age += seconds * num4;
			if (reference.Age >= reference.Life)
			{
				_drops[num5] = _drops[--_count];
				continue;
			}
			float num6 = Mathf.Max(0f, reference.Age - reference.Hold);
			float num7 = num6 * (0.38f + 0.62f * Mathf.Clamp01(num6 / 2.2f));
			float num8 = ((num6 > 0f) ? (Mathf.Sin(num6 * 5f + reference.WobblePhase) * 0.0011f) : 0f);
			Vector2 val = reference.Origin + new Vector2(num6 * reference.Drift + num8, (0f - num7) * reference.Speed);
			float num9 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(reference.Age / 0.25f));
			float num10 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((reference.Life - reference.Age) / 1.1f));
			float num11 = _presence * num9 * num10;
			if (num11 > 0.002f && val.y > -0.04f)
			{
				float stretch = reference.Stretch + 0.16f * Mathf.Clamp01(num6 / 2f);
				WriteQuad(num3++, val, reference.Radius * Mathf.Lerp(0.78f, 1f, num9), stretch, num11, aspect);
			}
			num5++;
		}
		if (num3 > 0 && Mesh != null)
		{
			UploadMeshChannels();
		}
		SetVisibleCount(num3);
		return num3 > 0;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private void UploadMeshChannels()
	{
		Mesh.SetVertices(_vertices, 0, _vertices.Length, (MeshUpdateFlags)8);
		Mesh.SetUVs(0, _shape, 0, _shape.Length, (MeshUpdateFlags)8);
	}

	private void SetVisibleCount(int count)
	{
		if (_meshCount != count && Mesh != null)
		{
			ApplySubMesh(count);
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private void ApplySubMesh(int count)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		SubMeshDescriptor val = default(SubMeshDescriptor);
		((SubMeshDescriptor)(ref val))..ctor(0, count * 6, (MeshTopology)0);
		((SubMeshDescriptor)(ref val)).bounds = Mesh.bounds;
		((SubMeshDescriptor)(ref val)).vertexCount = count * 4;
		SubMeshDescriptor val2 = val;
		Mesh.SetSubMesh(0, val2, (MeshUpdateFlags)8);
		_meshCount = count;
	}

	private Drop NewDrop()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		bool flag = _random.NextDouble() < 0.24;
		return new Drop
		{
			Origin = new Vector2(Range(0.04f, 0.96f), Range(0.14f, 0.95f)),
			Life = (flag ? Range(3.8f, 5.6f) : Range(2.8f, 4.6f)),
			Radius = (flag ? Range(0.0072f, 0.0104f) : Range(0.0038f, 0.0068f)),
			Stretch = (flag ? Range(1.04f, 1.24f) : Range(0.96f, 1.14f)),
			Hold = (flag ? Range(0.35f, 0.95f) : Range(0.55f, 1.45f)),
			Speed = (flag ? Range(0.016f, 0.034f) : Range(0.006f, 0.016f)),
			Drift = Range(-0.0018f, 0.0018f),
			WobblePhase = Range(0f, MathF.PI * 2f)
		};
	}

	private float Range(float from, float to)
	{
		return from + (to - from) * (float)_random.NextDouble();
	}

	private void WriteQuad(int index, Vector2 center, float radius, float stretch, float opacity, float aspect)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		Vector2 size = default(Vector2);
		((Vector2)(ref size))..ctor(radius / aspect, radius * stretch);
		int num = index * 4;
		SetCorner(num, center, size, -1f, -1f, opacity);
		SetCorner(num + 1, center, size, 1f, -1f, opacity);
		SetCorner(num + 2, center, size, -1f, 1f, opacity);
		SetCorner(num + 3, center, size, 1f, 1f, opacity);
	}

	private void SetCorner(int index, Vector2 center, Vector2 size, float x, float y, float opacity)
	{
		//IL_000c: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		_vertices[index] = new Vector3(2f * (center.x + x * size.x) - 1f, 2f * (center.y + y * size.y) - 1f, 0f);
		_shape[index] = new Vector4(x, y, size.y, opacity);
	}

	public void ClearImmediate()
	{
		_count = 0;
		_presence = 0f;
		_untilSpawn = 0.22f;
		SetVisibleCount(0);
	}

	public void Dispose()
	{
		if ((Object)(object)Mesh != (Object)null)
		{
			Object.Destroy((Object)(object)Mesh);
		}
	}
}
internal sealed class TaleSpireShelter : IRoofSampler
{
	private readonly CollisionFilter _geometry = BouncePhysicsLayers.GetQueryFilterByLayerNames(new string[4] { "Tile", "Props", "TileHidden", "PropsHidden" });

	private readonly CollisionFilter _tiles = BouncePhysicsLayers.GetQueryFilterByLayerNames(new string[2] { "Tile", "TileHidden" });

	private PhysicsEngine _engine;

	private Aabb _bounds;

	private float _nextBoundsRefresh;

	private bool _hasBounds;

	public float MaxY => _bounds.Max.y;

	public void Invalidate()
	{
		_hasBounds = false;
		_nextBoundsRefresh = 0f;
	}

	public bool BeginFrame()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		if (!PhysicsEngine.TryGetDefaultEngine(ref _engine) || !((PhysicsWorld)(ref _engine.PhysicsWorld)).IsCreated)
		{
			return false;
		}
		float unscaledTime = Time.unscaledTime;
		if (!_hasBounds || unscaledTime >= _nextBoundsRefresh)
		{
			_bounds = ((CollisionWorld)(ref _engine.PhysicsWorld.CollisionWorld)).CalculateAabb();
			_nextBoundsRefresh = unscaledTime + 0.5f;
			_hasBounds = true;
		}
		return true;
	}

	public float SampleRoof(float x, float z)
	{
		//IL_0093: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: 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)
		if (_bounds.Max.y < _bounds.Min.y || x < _bounds.Min.x || x > _bounds.Max.x || z < _bounds.Min.z || z > _bounds.Max.z)
		{
			return float.NegativeInfinity;
		}
		float3 val = default(float3);
		((float3)(ref val))..ctor(x, _bounds.Max.y + 1f, z);
		float num = val.y - _bounds.Min.y + 1f;
		HitInfo val2 = default(HitInfo);
		if (!_engine.Raycast(val, new float3(0f, -1f, 0f), ref val2, num, _geometry))
		{
			return float.NegativeInfinity;
		}
		return val2.point.y;
	}

	public static BoardSlice ReadSlice()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		CutVolume val = default(CutVolume);
		Bounds val2 = default(Bounds);
		return new BoardSlice(new Bounds(Vector4.op_Implicit(Shader.GetGlobalVector(GlobalShaderData.ID_HideCubeBoundsCenter)), Vector4.op_Implicit(Shader.GetGlobalVector(GlobalShaderData.ID_HideCubeBoundsSize))), (Bounds)((CameraController.TryGetCutVolume(ref val, ref val2) && val.Active) ? val2 : default(Bounds)));
	}

	public Vector2 SampleSurface(float x, float z)
	{
		//IL_006e: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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_00ef: 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_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		if (_bounds.Max.y < _bounds.Min.y || x < _bounds.Min.x || x > _bounds.Max.x || z < _bounds.Min.z || z > _bounds.Max.z)
		{
			return PuddleCoverage.NoSurface;
		}
		float3 val = default(float3);
		((float3)(ref val))..ctor(x, _bounds.Max.y + 1f, z);
		float3 val2 = default(float3);
		((float3)(ref val2))..ctor(0f, -1f, 0f);
		HitInfo val3 = default(HitInfo);
		if (!_engine.Raycast(val, val2, ref val3, val.y - _bounds.Min.y + 1f, _geometry))
		{
			return PuddleCoverage.NoSurface;
		}
		float y = PuddleCoverage.NoSurface.y;
		if (val3.normal.y >= 0.68f)
		{
			float3 val4 = default(float3);
			((float3)(ref val4))..ctor(x, val3.point.y + 0.06f, z);
			HitInfo val5 = default(HitInfo);
			if (_engine.Raycast(val4, val2, ref val5, 0.26f, _tiles) && val5.point.y >= val3.point.y - 0.18f)
			{
				y = val5.point.y;
			}
		}
		return new Vector2(val3.point.y, y);
	}
}
internal sealed class WeatherEmitter : IDisposable
{
	private const int MaxSplashesPerTick = 4;

	private readonly WeatherKind _kind;

	private readonly float _cullInterval;

	private readonly GameObject _host;

	private readonly ParticleSystem _particles;

	private readonly ParticleSystemRenderer _renderer;

	private readonly Material _material;

	private readonly Texture2D _texture;

	private readonly GameObject _splashHost;

	private readonly ParticleSystem _splashes;

	private readonly Material _splashMaterial;

	private readonly Texture2D _splashTexture;

	private readonly PrecipitationMask _mask;

	private readonly Particle[] _visibleParticles;

	private readonly int _tintProperty;

	private readonly Color _baseTint;

	private readonly float _lightRate;

	private readonly Color32 _particleColor;

	private WindStrength _wind = (WindStrength)(-1);

	private float _rate = -1f;

	private float _nextCullTime;

	private int _splashStride;

	private Camera _camera;

	private Vector3 _box;

	public WeatherEmitter(Transform parent, WeatherKind kind, PrecipitationMask mask)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: 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_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Expected O, but got Unknown
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Expected O, but got Unknown
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Expected O, but got Unknown
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Expected O, but got Unknown
		_kind = kind;
		_mask = mask;
		bool flag = kind == WeatherKind.Rain;
		_cullInterval = (flag ? (1f / 60f) : (1f / 36f));
		_lightRate = WeatherPresets.Rate(kind, Intensity.Light);
		_particleColor = Color32.op_Implicit(flag ? new Color(0.76f, 0.87f, 1f, 0.72f) : new Color(0.95f, 0.98f, 1f, 0.94f));
		int layer = ResolveDefaultLayer();
		_host = new GameObject("TSDynamicWeatherEffects." + kind)
		{
			layer = layer,
			hideFlags = (HideFlags)52
		};
		_host.SetActive(false);
		_host.transform.SetParent(parent, false);
		try
		{
			_particles = _host.AddComponent<ParticleSystem>();
			_renderer = _host.GetComponent<ParticleSystemRenderer>();
			MainModule main = _particles.main;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)0;
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			ShapeModule shape = _particles.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			VelocityOverLifetimeModule velocityOverLifetime = _particles.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
			ColorOverLifetimeModule colorOverLifetime = _particles.colorOverLifetime;
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.08f),
				new GradientAlphaKey(1f, 0.78f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val);
			Shader val2 = FindParticleShader(((Renderer)_renderer).sharedMaterial);
			_material = new Material(val2)
			{
				name = "Weather particles",
				hideFlags = (HideFlags)52
			};
			_tintProperty = Shader.PropertyToID(_material.HasProperty("_TintColor") ? "_TintColor" : "_Color");
			_baseTint = (_material.HasProperty(_tintProperty) ? _material.GetColor(_tintProperty) : Color.white);
			_texture = (flag ? MakeRainStreakTexture() : MakeSnowflakeTexture());
			_material.mainTexture = (Texture)(object)_texture;
			ConfigureRenderer(_renderer, _material);
			_visibleParticles = (Particle[])(object)new Particle[flag ? 1200 : 960];
			ConfigureEmitter(flag);
			ApplyWind(WindStrength.Breeze);
			if (flag)
			{
				_splashHost = new GameObject("TSDynamicWeatherEffects.RainSplashes")
				{
					layer = layer,
					hideFlags = (HideFlags)52
				};
				_splashHost.SetActive(false);
				_splashHost.transform.SetParent(parent, false);
				_splashes = _splashHost.AddComponent<ParticleSystem>();
				ParticleSystemRenderer component = _splashHost.GetComponent<ParticleSystemRenderer>();
				_splashTexture = MakeSplashRingTexture();
				_splashMaterial = new Material(val2)
				{
					name = "Rain ground splashes",
					hideFlags = (HideFlags)52,
					mainTexture = (Texture)(object)_splashTexture
				};
				ConfigureRenderer(component, _splashMaterial);
				component.renderMode = (ParticleSystemRenderMode)2;
				ConfigureSplashes();
			}
		}
		catch
		{
			Dispose();
			throw;
		}
	}

	private static int ResolveDefaultLayer()
	{
		int num = LayerMask.NameToLayer("TransparentFX");
		if (num < 0)
		{
			return 0;
		}
		return num;
	}

	private static void ConfigureRenderer(ParticleSystemRenderer renderer, Material material)
	{
		((Renderer)renderer).sharedMaterial = material;
		((Renderer)renderer).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)renderer).receiveShadows = false;
		((Renderer)renderer).lightProbeUsage = (LightProbeUsage)0;
		((Renderer)renderer).reflectionProbeUsage = (ReflectionProbeUsage)0;
		((Renderer)renderer).motionVectorGenerationMode = (MotionVectorGenerationMode)2;
		renderer.sortMode = (ParticleSystemSortMode)0;
		renderer.minParticleSize = 0f;
	}

	private static Shader FindParticleShader(Material fallback)
	{
		string[] array = new string[2] { "Legacy Shaders/Particles/Alpha Blended", "Sprites/Default" };
		for (int i = 0; i < array.Length; i++)
		{
			Shader val = Shader.Find(array[i]);
			if ((Object)(object)val != (Object)null && val.isSupported)
			{
				return val;
			}
		}
		if ((Object)(object)fallback != (Object)null && fallback.shader.isSupported && fallback.HasProperty("_MainTex"))
		{
			return fallback.shader;
		}
		throw new InvalidOperationException("No supported transparent particle shader available.");
	}

	private static Texture2D MakeRainStreakTexture()
	{
		//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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Expected O, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[1024];
		for (int i = 0; i < 64; i++)
		{
			float num = ((float)i + 0.5f) / 64f;
			float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 0.18f));
			float num3 = Mathf.Pow(Mathf.Clamp01((1f - num) / 0.82f), 1.35f);
			float num4 = num2 * num3;
			for (int j = 0; j < 16; j++)
			{
				float num5 = 2f * ((float)j + 0.5f) / 16f - 1f;
				float num6 = Mathf.Clamp01(1f - num5 * num5);
				float num7 = Mathf.Clamp01(num6 * num6 * num4 * 1.15f);
				array[i * 16 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * num7));
			}
		}
		Texture2D val = new Texture2D(16, 64, (TextureFormat)4, true)
		{
			name = "Rain streak",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)1,
			filterMode = (FilterMode)2
		};
		val.SetPixels32(array);
		val.Apply(true, true);
		return val;
	}

	private static Texture2D MakeSnowflakeTexture()
	{
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: 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_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[1024];
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num = 2f * ((float)j + 0.5f) / 32f - 1f;
				float num2 = 2f * ((float)i + 0.5f) / 32f - 1f;
				float num3 = num * num + num2 * num2;
				float num4 = Mathf.Atan2(num2, num);
				float num5 = 0.88f + 0.12f * Mathf.Cos(6f * num4);
				float num6 = Mathf.Clamp01((1f - num3 / (num5 * num5)) * 1.28f);
				float num7 = Mathf.SmoothStep(0f, 1f, num6);
				array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * num7));
			}
		}
		Texture2D val = new Texture2D(32, 32, (TextureFormat)4, true)
		{
			name = "Snowflake crystal",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)1,
			filterMode = (FilterMode)2
		};
		val.SetPixels32(array);
		val.Apply(true, true);
		return val;
	}

	private static Texture2D MakeSplashRingTexture()
	{
		//IL_00f4: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Expected O, but got Unknown
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[1024];
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num = 2f * ((float)j + 0.5f) / 32f - 1f;
				float num2 = 2f * ((float)i + 0.5f) / 32f - 1f;
				float num3 = Mathf.Sqrt(num * num + num2 * num2);
				float num4 = Mathf.SmoothStep(0.32f, 0.72f, num3) * (1f - Mathf.SmoothStep(0.74f, 1f, num3));
				float num5 = (1f - Mathf.SmoothStep(0f, 0.3f, num3)) * 0.35f;
				float num6 = Mathf.Clamp01(num4 + num5);
				array[i * 32 + j] = new Color32((byte)225, (byte)238, byte.MaxValue, (byte)(255f * num6));
			}
		}
		Texture2D val = new Texture2D(32, 32, (TextureFormat)4, true)
		{
			name = "Rain splash ring",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)1,
			filterMode = (FilterMode)1
		};
		val.SetPixels32(array);
		val.Apply(true, true);
		return val;
	}

	private void ConfigureSplashes()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		MainModule main = _splashes.main;
		((MainModule)(ref main)).playOnAwake = false;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).maxParticles = 96;
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).cullingMode = (ParticleSystemCullingMode)0;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.14f, 0.23f);
		((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.08f, 0.16f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.82f, 0.9f, 1f, 0.52f));
		EmissionModule emission = _splashes.emission;
		((EmissionModule)(ref emission)).enabled = false;
		SizeOverLifetimeModule sizeOverLifetime = _splashes.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 0.38f, 1f, 1.35f));
		ColorOverLifetimeModule colorOverLifetime = _splashes.colorOverLifetime;
		Gradient val = new Gradient();
		val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(0.95f, 0f),
			new GradientAlphaKey(0.55f, 0.45f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val);
	}

	public void Stop()
	{
		if (!((Object)(object)_camera == (Object)null) || _host.activeSelf)
		{
			_particles.Stop(false, (ParticleSystemStopBehavior)0);
			_host.SetActive(false);
			if ((Object)(object)_splashHost != (Object)null)
			{
				_splashes.Clear(false);
				_splashHost.SetActive(false);
			}
			_camera = null;
			_nextCullTime = 0f;
		}
	}

	private void SyncCameraLayer(int cullingMask)
	{
		if ((cullingMask & (1 << _host.layer)) != 0)
		{
			return;
		}
		int num = (((cullingMask & 1) == 0) ? (-1) : 0);
		if (num >= 0)
		{
			_host.layer = num;
			if ((Object)(object)_splashHost != (Object)null)
			{
				_splashHost.layer = num;
			}
		}
	}

	public void Show(Camera camera, float boardHeight, float rate, WindStrength wind, bool spawnSplashes, in BoardSlice slice)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		if (rate <= 0f || (Object)(object)camera == (Object)null || !((Behaviour)camera).isActiveAndEnabled)
		{
			Stop();
			return;
		}
		SyncCameraLayer(camera.cullingMask);
		if ((camera.cullingMask & (1 << _host.layer)) == 0)
		{
			Stop();
			return;
		}
		if (_wind != wind)
		{
			ApplyWind(wind);
		}
		Transform transform = ((Component)camera).transform;
		Vector3 forward = transform.forward;
		float num = ((Mathf.Abs(forward.y) > 0.05f) ? ((boardHeight - transform.position.y) / forward.y) : 0f);
		float nearClipPlane = camera.nearClipPlane;
		float depth = Mathf.Clamp((num > 0f) ? (num * 0.6f) : 6f, nearClipPlane + 0.75f, Mathf.Max(20f, nearClipPlane + 0.75f));
		depth = slice.ExtendEmissionDepth(transform.position, forward, depth, camera.farClipPlane);
		float num2 = (camera.orthographic ? camera.orthographicSize : (depth * Mathf.Tan(0.5f * camera.fieldOfView * (MathF.PI / 180f))));
		float num3 = Mathf.Max(1f, num2 * 2f);
		float num4 = num3 * camera.aspect;
		float num5 = Mathf.Min(5.5f, (depth - nearClipPlane) * 0.82f);
		Vector3 val = Vector3.up - forward * forward.y;
		Vector3 val2 = transform.position + forward * depth + val * (0.16f * num3);
		Transform transform2 = _host.transform;
		Vector3 val3 = val2 - transform2.position;
		float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
		bool num6 = (Object)(object)_camera != (Object)(object)camera;
		bool flag = !num6 && (sqrMagnitude > num3 * num3 || Vector3.Dot(forward, transform2.forward) < 0.5f);
		float num7 = ((num > 0f) ? Mathf.InverseLerp(18f, 52f, num) : 0f);
		float num8 = rate * Mathf.Lerp(1f, 0.7f, num7);
		if (num6 || flag)
		{
			_particles.Stop(false, (ParticleSystemStopBehavior)0);
		}
		if (Mathf.Abs(_rate - num8) > 0.25f)
		{
			EmissionModule emission = _particles.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(num8);
			if (_material.HasProperty(_tintProperty))
			{
				Color baseTint = _baseTint;
				baseTint.a *= Mathf.Clamp01(rate / _lightRate);
				_material.SetColor(_tintProperty, baseTint);
			}
			_rate = num8;
		}
		if (num6 || sqrMagnitude > 1E-06f || transform2.rotation != transform.rotation)
		{
			transform2.SetPositionAndRotation(val2, transform.rotation);
		}
		Vector3 val4 = default(Vector3);
		((Vector3)(ref val4))..ctor(num4 * 1.24f, num3 * 1.34f, num5);
		if (!num6)
		{
			val3 = val4 - _box;
			if (!(((Vector3)(ref val3)).sqrMagnitude > 0.0004f * ((Vector3)(ref val4)).sqrMagnitude))
			{
				goto IL_033f;
			}
		}
		ShapeModule shape = _particles.shape;
		((ShapeModule)(ref shape)).scale = val4;
		_box = val4;
		goto IL_033f;
		IL_033f:
		_camera = camera;
		if (num6 || flag)
		{
			_host.SetActive(true);
			_particles.Play(false);
			_nextCullTime = 0f;
		}
		bool flag2 = spawnSplashes && num < 38f;
		if ((Object)(object)_splashHost != (Object)null && _splashHost.activeSelf != flag2)
		{
			if (!flag2)
			{
				_splashes.Clear(false);
			}
			_splashHost.SetActive(flag2);
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime >= _nextCullTime)
		{
			_nextCullTime = unscaledTime + _cullInterval;
			CullParticles(in slice, flag2 && (Object)(object)_splashes != (Object)null);
		}
	}

	private void CullParticles(in BoardSlice slice, bool spawnSplashes)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing ref