Decompiled source of Meteors v1.0.1

EmpressMeteor.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Networking;
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("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressMeteor")]
[assembly: AssemblyTitle("EmpressMeteor")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EmpressMeteor
{
	[BepInPlugin("empress.peak.meteor", "EmpressMeteor", "1.3.1")]
	public sealed class EmpressMeteorPlugin : BaseUnityPlugin
	{
		private readonly struct MeteorSpawnData
		{
			internal readonly string SceneName;

			internal readonly int SegmentIndex;

			internal readonly Vector3 StartPoint;

			internal readonly Vector3 ImpactPoint;

			internal readonly Vector3 ImpactNormal;

			internal readonly float Scale;

			internal readonly float Duration;

			internal MeteorSpawnData(string sceneName, int segmentIndex, Vector3 startPoint, Vector3 impactPoint, Vector3 impactNormal, float scale, float duration)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				SceneName = sceneName;
				SegmentIndex = segmentIndex;
				StartPoint = startPoint;
				ImpactPoint = impactPoint;
				ImpactNormal = impactNormal;
				Scale = scale;
				Duration = duration;
			}
		}

		internal const string PluginGuid = "empress.peak.meteor";

		internal const string PluginName = "EmpressMeteor";

		internal const string PluginVersion = "1.3.1";

		private const byte MeteorEventCode = 82;

		private const int MaxAudibleFallingSources = 2;

		private const string FallingAudioFileName = "falling.mp3";

		private const string ImpactAudioFileName = "hit.mp3";

		private static readonly string[] ExcludedNameTokens = new string[15]
		{
			"water", "river", "lava", "cloud", "rope", "vine", "grass", "mushroom", "particle", "vfx",
			"decal", "foliage", "leaf", "fog", "ui"
		};

		private readonly List<Transform> _activeRoots = new List<Transform>();

		private readonly List<AudioSource> _fallingAudioSources = new List<AudioSource>();

		private Bounds _activeBounds;

		private bool _hasActiveBounds;

		private int _trackedSegment = -1;

		private string _trackedSceneName = string.Empty;

		private bool _refreshRequested = true;

		private float _nextShowerAt;

		private bool _runningShower;

		private Material? _meteorMaterial;

		private Material? _trailMaterial;

		private Material? _impactMaterial;

		private AudioClip? _fallingClip;

		private AudioClip? _impactClip;

		private bool _audioLoading;

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<bool> _allowNetworkSessions;

		private ConfigEntry<float> _minSecondsBetweenShowers;

		private ConfigEntry<float> _maxSecondsBetweenShowers;

		private ConfigEntry<int> _minMeteorsPerShower;

		private ConfigEntry<int> _maxMeteorsPerShower;

		private ConfigEntry<float> _minBurstSpacing;

		private ConfigEntry<float> _maxBurstSpacing;

		private ConfigEntry<float> _spawnHeight;

		private ConfigEntry<float> _meteorSpeed;

		private ConfigEntry<float> _explosionRadius;

		private ConfigEntry<float> _explosionForce;

		private ConfigEntry<float> _minimumBoundsMagnitude;

		private ConfigEntry<int> _fallingVolumePercent;

		private ConfigEntry<int> _impactVolumePercent;

		private void Awake()
		{
			//IL_0014: 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)
			((Component)this).transform.SetParent((Transform)null, true);
			GameObject gameObject = ((Component)this).gameObject;
			((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x23);
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch for the meteor shower.");
			_allowNetworkSessions = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowNetworkSessions", true, "If enabled, the room host controls meteor showers and syncs them to all clients.");
			_minSecondsBetweenShowers = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "MinSecondsBetweenShowers", 5f, "Minimum seconds between meteor showers.");
			_maxSecondsBetweenShowers = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "MaxSecondsBetweenShowers", 10f, "Maximum seconds between meteor showers.");
			_minMeteorsPerShower = ((BaseUnityPlugin)this).Config.Bind<int>("Timing", "MinMeteorsPerShower", 3, "Minimum meteors spawned in one shower burst.");
			_maxMeteorsPerShower = ((BaseUnityPlugin)this).Config.Bind<int>("Timing", "MaxMeteorsPerShower", 6, "Maximum meteors spawned in one shower burst.");
			_minBurstSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "MinBurstSpacing", 0.18f, "Minimum delay between meteors inside one shower burst.");
			_maxBurstSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "MaxBurstSpacing", 0.42f, "Maximum delay between meteors inside one shower burst.");
			_spawnHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Meteor", "SpawnHeight", 90f, "How high above the impact point meteors begin.");
			_meteorSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Meteor", "MeteorSpeed", 70f, "Meteor travel speed in meters per second.");
			_explosionRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Explosion", "ExplosionRadius", 10f, "Explosion radius applied on impact.");
			_explosionForce = ((BaseUnityPlugin)this).Config.Bind<float>("Explosion", "ExplosionForce", 42f, "Explosion force applied to nearby rigidbodies.");
			_minimumBoundsMagnitude = ((BaseUnityPlugin)this).Config.Bind<float>("Bounds", "MinimumBoundsMagnitude", 4f, "Minimum renderer or collider bounds magnitude used when building the active level bounds.");
			_fallingVolumePercent = ((BaseUnityPlugin)this).Config.Bind<int>("Audio", "FallingVolumePercent", 30, "Meteor falling rumble volume in percent. 30 = 30%.");
			_impactVolumePercent = ((BaseUnityPlugin)this).Config.Bind<int>("Audio", "ImpactVolumePercent", 30, "Meteor impact volume in percent. 30 = 30%.");
			SceneManager.sceneLoaded += OnSceneLoaded;
			PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;
			EnsureAudioLoadingStarted();
			ScheduleNextShower(initial: true);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"EmpressMeteor 1.3.1 loaded.");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived -= OnPhotonEvent;
			}
			_fallingAudioSources.Clear();
			if ((Object)(object)_fallingClip != (Object)null)
			{
				Object.Destroy((Object)(object)_fallingClip);
				_fallingClip = null;
			}
			if ((Object)(object)_impactClip != (Object)null)
			{
				Object.Destroy((Object)(object)_impactClip);
				_impactClip = null;
			}
		}

		private void Update()
		{
			if (_enabled.Value)
			{
				UpdateFallingAudioMix();
				if (CanRunInCurrentContext() && RefreshBoundsIfNeeded() && CanDriveShowers() && !_runningShower && !(Time.time < _nextShowerAt))
				{
					((MonoBehaviour)this).StartCoroutine(RunLocalShower());
				}
			}
		}

		private void OnSceneLoaded(Scene _, LoadSceneMode __)
		{
			_refreshRequested = true;
			_runningShower = false;
			_audioLoading = false;
			((MonoBehaviour)this).StopAllCoroutines();
			EnsureAudioLoadingStarted();
			ScheduleNextShower(initial: true);
		}

		private bool CanRunInCurrentContext()
		{
			//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)
			Scene activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).IsValid() || !((Scene)(ref activeScene)).isLoaded)
			{
				return false;
			}
			if (((Scene)(ref activeScene)).name.Equals("Title", StringComparison.OrdinalIgnoreCase) || ((Scene)(ref activeScene)).name.Equals("Airport", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (!MapHandler.Exists)
			{
				return false;
			}
			if (PhotonNetwork.InRoom && !_allowNetworkSessions.Value)
			{
				return false;
			}
			return (Object)(object)MapHandler.CurrentMapSegment.segmentParent != (Object)null;
		}

		private bool CanDriveShowers()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return !_allowNetworkSessions.Value;
			}
			return true;
		}

		private bool RefreshBoundsIfNeeded()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected I4, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			int num = (int)MapHandler.CurrentSegmentNumber;
			if (!_refreshRequested && num == _trackedSegment && string.Equals(((Scene)(ref activeScene)).name, _trackedSceneName, StringComparison.Ordinal))
			{
				return _hasActiveBounds;
			}
			_refreshRequested = false;
			_trackedSegment = num;
			_trackedSceneName = ((Scene)(ref activeScene)).name;
			_activeRoots.Clear();
			_hasActiveBounds = false;
			GameObject segmentParent = MapHandler.CurrentMapSegment.segmentParent;
			CaptureRoot((segmentParent != null) ? segmentParent.transform : null);
			GameObject segmentCampfire = MapHandler.CurrentMapSegment.segmentCampfire;
			CaptureRoot((segmentCampfire != null) ? segmentCampfire.transform : null);
			for (int i = 0; i < _activeRoots.Count; i++)
			{
				EncapsulateRootBounds(_activeRoots[i]);
			}
			if (_hasActiveBounds)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} using bounds {1} in scene '{2}' segment {3}.", "EmpressMeteor", ((Bounds)(ref _activeBounds)).size, _trackedSceneName, _trackedSegment));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)string.Format("{0} could not build active level bounds in scene '{1}' segment {2}.", "EmpressMeteor", _trackedSceneName, _trackedSegment));
			}
			return _hasActiveBounds;
		}

		private void CaptureRoot(Transform? root)
		{
			if ((Object)(object)root == (Object)null || !((Component)root).gameObject.activeInHierarchy)
			{
				return;
			}
			for (int i = 0; i < _activeRoots.Count; i++)
			{
				if ((Object)(object)_activeRoots[i] == (Object)(object)root)
				{
					return;
				}
			}
			_activeRoots.Add(root);
		}

		private void EncapsulateRootBounds(Transform root)
		{
			//IL_0018: 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_005d: 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)
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(false);
			foreach (Renderer val in componentsInChildren)
			{
				if (IsEligibleBoundsSource(((Object)val).name, val.bounds, val.enabled))
				{
					EncapsulateBounds(val.bounds);
				}
			}
			Collider[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Collider>(false);
			foreach (Collider val2 in componentsInChildren2)
			{
				if (IsEligibleBoundsSource(((Object)val2).name, val2.bounds, val2.enabled))
				{
					EncapsulateBounds(val2.bounds);
				}
			}
		}

		private bool IsEligibleBoundsSource(string objectName, Bounds bounds, bool enabled)
		{
			//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)
			if (enabled)
			{
				Vector3 size = ((Bounds)(ref bounds)).size;
				if (!(((Vector3)(ref size)).magnitude < _minimumBoundsMagnitude.Value))
				{
					string text = objectName.ToLowerInvariant();
					for (int i = 0; i < ExcludedNameTokens.Length; i++)
					{
						if (text.Contains(ExcludedNameTokens[i]))
						{
							return false;
						}
					}
					return true;
				}
			}
			return false;
		}

		private void EncapsulateBounds(Bounds bounds)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			if (!_hasActiveBounds)
			{
				_activeBounds = bounds;
				_hasActiveBounds = true;
			}
			else
			{
				((Bounds)(ref _activeBounds)).Encapsulate(bounds);
			}
		}

		private IEnumerator RunLocalShower()
		{
			_runningShower = true;
			int meteorCount = Random.Range(Mathf.Min(_minMeteorsPerShower.Value, _maxMeteorsPerShower.Value), Mathf.Max(_minMeteorsPerShower.Value, _maxMeteorsPerShower.Value) + 1);
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} starting shower with {1} meteors.", "EmpressMeteor", meteorCount));
			for (int index = 0; index < meteorCount; index++)
			{
				if (TryPickMeteor(out var data))
				{
					if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && _allowNetworkSessions.Value)
					{
						BroadcastMeteor(data);
					}
					else
					{
						((MonoBehaviour)this).StartCoroutine(RunMeteor(data));
					}
					if (index < meteorCount - 1)
					{
						float num = Random.Range(Mathf.Min(_minBurstSpacing.Value, _maxBurstSpacing.Value), Mathf.Max(_minBurstSpacing.Value, _maxBurstSpacing.Value));
						yield return (object)new WaitForSeconds(num);
					}
				}
			}
			_runningShower = false;
			ScheduleNextShower(initial: false);
		}

		private bool TryPickMeteor(out MeteorSpawnData data)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_01d1: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			data = default(MeteorSpawnData);
			if (!_hasActiveBounds)
			{
				return false;
			}
			LayerMask allPhysicalExceptCharacter = HelperFunctions.AllPhysicalExceptCharacter;
			float num = ((Bounds)(ref _activeBounds)).max.y + _spawnHeight.Value + 12f;
			float num2 = Mathf.Max(250f, ((Bounds)(ref _activeBounds)).size.y + _spawnHeight.Value * 2f + 30f);
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < 32; i++)
			{
				if (Physics.Raycast(new Vector3(Random.Range(((Bounds)(ref _activeBounds)).min.x, ((Bounds)(ref _activeBounds)).max.x), num, Random.Range(((Bounds)(ref _activeBounds)).min.z, ((Bounds)(ref _activeBounds)).max.z)), Vector3.down, ref val, num2, LayerMask.op_Implicit(allPhysicalExceptCharacter), (QueryTriggerInteraction)1) && !ShouldSkipImpact(((RaycastHit)(ref val)).collider))
				{
					Vector3 point = ((RaycastHit)(ref val)).point;
					Vector3 val2 = BuildMeteorStart(point);
					float scale = Random.Range(0.85f, 1.45f);
					float duration = Mathf.Clamp(Vector3.Distance(val2, point) / Mathf.Max(10f, _meteorSpeed.Value), 0.65f, 2.2f);
					string trackedSceneName = _trackedSceneName;
					int trackedSegment = _trackedSegment;
					Vector3 normal = ((RaycastHit)(ref val)).normal;
					Vector3 impactNormal;
					if (!(((Vector3)(ref normal)).sqrMagnitude > 0.01f))
					{
						impactNormal = Vector3.up;
					}
					else
					{
						normal = ((RaycastHit)(ref val)).normal;
						impactNormal = ((Vector3)(ref normal)).normalized;
					}
					data = new MeteorSpawnData(trackedSceneName, trackedSegment, val2, point, impactNormal, scale, duration);
					return true;
				}
			}
			Vector3 center = ((Bounds)(ref _activeBounds)).center;
			Vector3 val3 = BuildMeteorStart(center);
			data = new MeteorSpawnData(_trackedSceneName, _trackedSegment, val3, center, Vector3.up, 1.1f, Mathf.Clamp(Vector3.Distance(val3, center) / Mathf.Max(10f, _meteorSpeed.Value), 0.65f, 2.2f));
			return true;
		}

		private bool ShouldSkipImpact(Collider? collider)
		{
			if ((Object)(object)collider == (Object)null)
			{
				return true;
			}
			string text = (((Object)collider).name + " " + ((Object)((Component)collider).transform.root).name).ToLowerInvariant();
			for (int i = 0; i < ExcludedNameTokens.Length; i++)
			{
				if (text.Contains(ExcludedNameTokens[i]))
				{
					return true;
				}
			}
			return false;
		}

		private Vector3 BuildMeteorStart(Vector3 impactPoint)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized;
			if (((Vector2)(ref val)).sqrMagnitude < 0.001f)
			{
				val = Vector2.right;
			}
			val *= Random.Range(10f, 22f);
			return impactPoint + new Vector3(val.x, _spawnHeight.Value, val.y);
		}

		private void BroadcastMeteor(MeteorSpawnData data)
		{
			//IL_0020: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[7] { data.SceneName, data.SegmentIndex, data.StartPoint, data.ImpactPoint, data.ImpactNormal, data.Scale, data.Duration };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			};
			SendOptions val2 = default(SendOptions);
			((SendOptions)(ref val2)).Reliability = true;
			SendOptions val3 = val2;
			PhotonNetwork.RaiseEvent((byte)82, (object)array, val, val3);
		}

		private void OnPhotonEvent(EventData eventData)
		{
			//IL_0056: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			if (eventData.Code == 82 && eventData.CustomData is object[] array && array.Length >= 7)
			{
				MeteorSpawnData data = new MeteorSpawnData((array[0] as string) ?? string.Empty, (array[1] is byte b) ? b : Convert.ToInt32(array[1]), (Vector3)array[2], (Vector3)array[3], (Vector3)array[4], Convert.ToSingle(array[5]), Convert.ToSingle(array[6]));
				((MonoBehaviour)this).StartCoroutine(PlayNetworkMeteorWhenReady(data));
			}
		}

		private IEnumerator PlayNetworkMeteorWhenReady(MeteorSpawnData data)
		{
			float timeoutAt = Time.time + 12f;
			while (Time.time < timeoutAt)
			{
				if (CanRunInCurrentContext())
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (string.Equals(((Scene)(ref activeScene)).name, data.SceneName, StringComparison.Ordinal) && (int)MapHandler.CurrentSegmentNumber == data.SegmentIndex)
					{
						yield return RunMeteor(data);
						yield break;
					}
				}
				yield return null;
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)string.Format("{0} skipped a synced meteor because scene '{1}' segment {2} never became ready.", "EmpressMeteor", data.SceneName, data.SegmentIndex));
		}

		private IEnumerator RunMeteor(MeteorSpawnData data)
		{
			GameObject meteor = CreateMeteorVisual(data.Scale);
			meteor.transform.position = data.StartPoint;
			AudioSource fallingSource = AttachFallingAudio(meteor, data.Scale);
			Vector3 midPoint = Vector3.Lerp(data.StartPoint, data.ImpactPoint, 0.5f) + Vector3.up * Mathf.Max(5f, Vector3.Distance(data.StartPoint, data.ImpactPoint) * 0.12f);
			float duration = Mathf.Max(0.2f, data.Duration);
			for (float elapsed = 0f; elapsed < duration; elapsed += Time.deltaTime)
			{
				float num = Mathf.Clamp01(elapsed / duration);
				float num2 = 1f - Mathf.Pow(1f - num, 2.6f);
				Vector3 val = Vector3.Lerp(data.StartPoint, midPoint, num2);
				Vector3 val2 = Vector3.Lerp(midPoint, data.ImpactPoint, num2);
				Vector3 val3 = Vector3.Lerp(val, val2, num2);
				meteor.transform.position = val3;
				Vector3 val4 = data.ImpactPoint - val3;
				if (((Vector3)(ref val4)).sqrMagnitude > 0.001f)
				{
					meteor.transform.rotation = Quaternion.LookRotation(((Vector3)(ref val4)).normalized);
				}
				yield return null;
			}
			meteor.transform.position = data.ImpactPoint;
			ExplodeMeteor(data);
			if ((Object)(object)fallingSource != (Object)null)
			{
				_fallingAudioSources.Remove(fallingSource);
			}
			Object.Destroy((Object)(object)meteor);
		}

		private GameObject CreateMeteorVisual(float scale)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val).name = "EmpressMeteor";
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.localScale = Vector3.one * scale;
			Renderer component = val.GetComponent<Renderer>();
			component.sharedMaterial = GetMeteorMaterial();
			component.shadowCastingMode = (ShadowCastingMode)0;
			component.receiveShadows = false;
			TrailRenderer obj = val.AddComponent<TrailRenderer>();
			obj.time = 0.7f;
			obj.minVertexDistance = 0.06f;
			obj.startWidth = 1.45f * scale;
			obj.endWidth = 0.08f * scale;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			((Renderer)obj).sharedMaterial = GetTrailMaterial();
			obj.colorGradient = BuildTrailGradient();
			Light obj2 = val.AddComponent<Light>();
			obj2.type = (LightType)2;
			obj2.range = 24f * scale;
			obj2.intensity = 6.5f;
			obj2.color = new Color(1f, 0.55f, 0.15f);
			AddFireParticles(val.transform, scale);
			AddSmokeParticles(val.transform, scale);
			return val;
		}

		private void AddFireParticles(Transform parent, float scale)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_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_0046: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_015a: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01bd: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01fe: 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_0214: 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_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MeteorFire");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.12f, 0.28f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.6f, 2.4f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.22f * scale, 0.56f * scale);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(1f, 0.72f, 0.16f, 0.9f), new Color(1f, 0.28f, 0.05f, 0.4f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.08f);
			((MainModule)(ref main)).maxParticles = 120;
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(42f);
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
			((ShapeModule)(ref shape)).angle = 18f;
			((ShapeModule)(ref shape)).radius = 0.08f * scale;
			((ShapeModule)(ref shape)).position = new Vector3(0f, 0f, 0.55f * scale);
			((ShapeModule)(ref shape)).rotation = new Vector3(180f, 0f, 0f);
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
			{
				new GradientColorKey(new Color(1f, 0.96f, 0.56f), 0f),
				new GradientColorKey(new Color(1f, 0.46f, 0.12f), 0.45f),
				new GradientColorKey(new Color(0.38f, 0.1f, 0.04f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0.92f, 0f),
				new GradientAlphaKey(0.55f, 0.5f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val3);
			SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			AnimationCurve val4 = new AnimationCurve();
			val4.AddKey(0f, 0.35f);
			val4.AddKey(0.2f, 1f);
			val4.AddKey(1f, 0.08f);
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val4);
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).sharedMaterial = GetTrailMaterial();
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
		}

		private void AddSmokeParticles(Transform parent, float scale)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_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_0045: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MeteorSmoke");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
			val.transform.SetParent(parent, false);
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			MainModule main = obj.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.8f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.5f, 1.4f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.35f * scale, 0.82f * scale);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.24f, 0.18f, 0.16f, 0.42f), new Color(0.05f, 0.05f, 0.05f, 0.18f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.02f);
			((MainModule)(ref main)).maxParticles = 90;
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(16f);
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
			((ShapeModule)(ref shape)).angle = 10f;
			((ShapeModule)(ref shape)).radius = 0.12f * scale;
			((ShapeModule)(ref shape)).position = new Vector3(0f, 0f, 0.8f * scale);
			((ShapeModule)(ref shape)).rotation = new Vector3(180f, 0f, 0f);
			ParticleSystemRenderer component = ((Component)obj).GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).sharedMaterial = GetTrailMaterial();
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
		}

		private void ExplodeMeteor(MeteorSpawnData data)
		{
			//IL_0002: 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_0026: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			PlayImpactAudio(data.ImpactPoint, data.Scale);
			CreateImpactFlash(data.ImpactPoint, data.Scale);
			CreateExplosionParticles(data.ImpactPoint, data.Scale);
			ApplyExplosionForces(data.ImpactPoint, _explosionRadius.Value * data.Scale, _explosionForce.Value * data.Scale);
			if ((Object)(object)GamefeelHandler.instance != (Object)null)
			{
				GamefeelHandler.instance.AddPerlinShakeProximity(data.ImpactPoint, 12f * data.Scale, 0.55f, 18f, 95f);
			}
		}

		private void CreateImpactFlash(Vector3 impactPoint, float scale)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0049: 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_006b: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val).name = "EmpressMeteorImpactFlash";
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.position = impactPoint;
			val.transform.localScale = Vector3.one * (0.45f * scale);
			Renderer component = val.GetComponent<Renderer>();
			component.sharedMaterial = new Material(GetImpactMaterial());
			component.shadowCastingMode = (ShadowCastingMode)0;
			component.receiveShadows = false;
			Light val2 = val.AddComponent<Light>();
			val2.type = (LightType)2;
			val2.color = new Color(1f, 0.78f, 0.42f);
			val2.range = 26f * scale;
			val2.intensity = 8f;
			((MonoBehaviour)this).StartCoroutine(AnimateImpactFlash(val, component.material, val2, scale));
		}

		private IEnumerator AnimateImpactFlash(GameObject flash, Material flashMaterial, Light light, float scale)
		{
			float maxScale = 10f * scale;
			for (float elapsed = 0f; elapsed < 0.32f; elapsed += Time.deltaTime)
			{
				float num = Mathf.Clamp01(elapsed / 0.32f);
				float num2 = 1f - num;
				flash.transform.localScale = Vector3.one * Mathf.Lerp(0.4f * scale, maxScale, num);
				if (flashMaterial.HasProperty("_Color"))
				{
					Color color = flashMaterial.color;
					color.a = num2;
					flashMaterial.color = color;
				}
				if (flashMaterial.HasProperty("_EmissionColor"))
				{
					flashMaterial.SetColor("_EmissionColor", new Color(4.5f, 2.3f, 0.9f) * num2);
				}
				light.intensity = Mathf.Lerp(8f, 0f, num);
				yield return null;
			}
			Object.Destroy((Object)(object)flashMaterial);
			Object.Destroy((Object)(object)flash);
		}

		private void CreateExplosionParticles(Vector3 impactPoint, float scale)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_000d: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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)
			GameObject val = new GameObject("EmpressMeteorExplosion");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
			val.transform.position = impactPoint;
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).duration = 0.8f;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.22f, 0.55f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(5f * scale, 11f * scale);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.28f * scale, 1.15f * scale);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(1f, 0.86f, 0.45f, 0.95f), new Color(1f, 0.34f, 0.08f, 0.42f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).maxParticles = 120;
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
			{
				new Burst(0f, (short)Mathf.RoundToInt(40f * scale))
			});
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.45f * scale;
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val3 = new Gradient();
			val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
			{
				new GradientColorKey(new Color(1f, 0.94f, 0.62f), 0f),
				new GradientColorKey(new Color(1f, 0.48f, 0.14f), 0.35f),
				new GradientColorKey(new Color(0.15f, 0.12f, 0.12f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0.92f, 0f),
				new GradientAlphaKey(0.5f, 0.5f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val3);
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).sharedMaterial = GetTrailMaterial();
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			val2.Play();
			Object.Destroy((Object)(object)val, 2f);
		}

		private void ApplyExplosionForces(Vector3 impactPoint, float radius, float force)
		{
			//IL_0000: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(impactPoint, radius, LayerMask.op_Implicit(HelperFunctions.AllPhysicalExceptCharacter), (QueryTriggerInteraction)1);
			HashSet<Rigidbody> hashSet = new HashSet<Rigidbody>();
			for (int i = 0; i < array.Length; i++)
			{
				Rigidbody attachedRigidbody = array[i].attachedRigidbody;
				if ((Object)(object)attachedRigidbody != (Object)null)
				{
					hashSet.Add(attachedRigidbody);
				}
			}
			foreach (Rigidbody item in hashSet)
			{
				item.AddExplosionForce(force, impactPoint, radius, 1.2f, (ForceMode)1);
			}
		}

		private Material GetMeteorMaterial()
		{
			//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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_meteorMaterial != (Object)null)
			{
				return _meteorMaterial;
			}
			Shader val = Shader.Find("Standard") ?? Shader.Find("Sprites/Default");
			_meteorMaterial = new Material(val)
			{
				color = new Color(0.82f, 0.26f, 0.08f)
			};
			if (_meteorMaterial.HasProperty("_EmissionColor"))
			{
				_meteorMaterial.EnableKeyword("_EMISSION");
				_meteorMaterial.SetColor("_EmissionColor", new Color(3f, 1.2f, 0.25f));
			}
			return _meteorMaterial;
		}

		private Material GetTrailMaterial()
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			if ((Object)(object)_trailMaterial != (Object)null)
			{
				return _trailMaterial;
			}
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Standard");
			_trailMaterial = new Material(val)
			{
				color = new Color(1f, 0.56f, 0.15f, 0.88f)
			};
			return _trailMaterial;
		}

		private Material GetImpactMaterial()
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_impactMaterial != (Object)null)
			{
				return _impactMaterial;
			}
			Shader val = Shader.Find("Standard") ?? Shader.Find("Sprites/Default");
			_impactMaterial = new Material(val)
			{
				color = new Color(1f, 0.78f, 0.4f, 0.75f)
			};
			if (_impactMaterial.HasProperty("_EmissionColor"))
			{
				_impactMaterial.EnableKeyword("_EMISSION");
				_impactMaterial.SetColor("_EmissionColor", new Color(4f, 2.5f, 0.9f));
			}
			return _impactMaterial;
		}

		private static Gradient BuildTrailGradient()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
			{
				new GradientColorKey(new Color(1f, 0.9f, 0.34f), 0f),
				new GradientColorKey(new Color(1f, 0.46f, 0.1f), 0.5f),
				new GradientColorKey(new Color(0.1f, 0.08f, 0.08f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0.92f, 0f),
				new GradientAlphaKey(0.38f, 0.42f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}

		private void ScheduleNextShower(bool initial)
		{
			float num = Mathf.Max(2f, _minSecondsBetweenShowers.Value);
			float num2 = Mathf.Max(num, _maxSecondsBetweenShowers.Value);
			float num3 = Mathf.Max(2.8f, Mathf.Min(6f, num2));
			float num4 = (initial ? Random.Range(2.5f, num3) : Random.Range(num, num2));
			_nextShowerAt = Time.time + num4;
		}

		private void EnsureAudioLoadingStarted()
		{
			if (!_audioLoading && (!((Object)(object)_fallingClip != (Object)null) || !((Object)(object)_impactClip != (Object)null)))
			{
				((MonoBehaviour)this).StartCoroutine(LoadAudioAssets());
			}
		}

		private IEnumerator LoadAudioAssets()
		{
			_audioLoading = true;
			yield return LoadClipIfNeeded("falling.mp3", delegate(AudioClip clip)
			{
				_fallingClip = clip;
			}, "meteor falling");
			yield return LoadClipIfNeeded("hit.mp3", delegate(AudioClip clip)
			{
				_impactClip = clip;
			}, "meteor impact");
			_audioLoading = false;
		}

		private IEnumerator LoadClipIfNeeded(string fileName, Action<AudioClip> setter, string label)
		{
			string audioPath = ResolveAudioPath(fileName);
			if (!File.Exists(audioPath))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("EmpressMeteor could not find " + label + " audio at '" + audioPath + "'."));
				yield break;
			}
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(audioPath).AbsoluteUri, (AudioType)13);
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("EmpressMeteor failed to load " + label + " audio '" + audioPath + "': " + request.error));
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(request);
				if ((Object)(object)content == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("EmpressMeteor received an empty clip for " + label + " audio '" + audioPath + "'."));
				}
				else
				{
					((Object)content).name = Path.GetFileNameWithoutExtension(fileName);
					setter(content);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("EmpressMeteor loaded " + label + " audio from '" + audioPath + "'."));
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		private string ResolveAudioPath(string fileName)
		{
			string path = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? Paths.PluginPath;
			string text = Path.Combine(path, fileName);
			if (File.Exists(text))
			{
				return text;
			}
			string text2 = Path.Combine(path, "Audio", fileName);
			if (File.Exists(text2))
			{
				return text2;
			}
			string text3 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", fileName);
			if (File.Exists(text3))
			{
				return text3;
			}
			return text2;
		}

		private AudioSource? AttachFallingAudio(GameObject meteor, float scale)
		{
			if ((Object)(object)_fallingClip == (Object)null)
			{
				return null;
			}
			AudioSource val = meteor.AddComponent<AudioSource>();
			val.clip = _fallingClip;
			val.loop = true;
			val.playOnAwake = false;
			val.spatialBlend = 1f;
			val.rolloffMode = (AudioRolloffMode)0;
			val.minDistance = 7f * scale;
			val.maxDistance = 40f * scale;
			val.dopplerLevel = 0f;
			val.spread = 0f;
			val.reverbZoneMix = 0.85f;
			val.priority = 175;
			val.volume = 0f;
			val.pitch = Random.Range(0.94f, 1.06f);
			if (_fallingClip.length > 0.3f)
			{
				float num = Mathf.Max(0.05f, Mathf.Min(_fallingClip.length - 0.05f, 1.1f));
				val.time = Random.Range(0f, num);
			}
			val.Play();
			_fallingAudioSources.Add(val);
			return val;
		}

		private void PlayImpactAudio(Vector3 impactPoint, float scale)
		{
			//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_001a: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			if (!((Object)(object)_impactClip == (Object)null))
			{
				GameObject val = new GameObject("EmpressMeteorImpactAudio");
				((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 3);
				val.transform.position = impactPoint;
				AudioSource obj = val.AddComponent<AudioSource>();
				obj.clip = _impactClip;
				obj.loop = false;
				obj.playOnAwake = false;
				obj.spatialBlend = 1f;
				obj.rolloffMode = (AudioRolloffMode)0;
				obj.minDistance = 12f * scale;
				obj.maxDistance = 150f * scale;
				obj.dopplerLevel = 0f;
				obj.spread = 0f;
				obj.reverbZoneMix = 1f;
				obj.priority = 96;
				obj.volume = GetVolumeFromPercent(_impactVolumePercent.Value);
				obj.pitch = Random.Range(0.97f, 1.03f);
				obj.Play();
				Object.Destroy((Object)val, Mathf.Max(2.5f, _impactClip.length + 0.35f));
			}
		}

		private void UpdateFallingAudioMix()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if (_fallingAudioSources.Count == 0)
			{
				return;
			}
			for (int num = _fallingAudioSources.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_fallingAudioSources[num] == (Object)null)
				{
					_fallingAudioSources.RemoveAt(num);
				}
			}
			if (_fallingAudioSources.Count == 0)
			{
				return;
			}
			if (!TryGetListenerPosition(out var listenerPosition))
			{
				for (int i = 0; i < _fallingAudioSources.Count; i++)
				{
					_fallingAudioSources[i].volume = 0f;
				}
				return;
			}
			AudioSource[] array = (AudioSource[])(object)new AudioSource[2];
			float[] array2 = new float[2];
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j] = float.MaxValue;
			}
			for (int k = 0; k < _fallingAudioSources.Count; k++)
			{
				AudioSource val = _fallingAudioSources[k];
				Vector3 val2 = ((Component)val).transform.position - listenerPosition;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				for (int l = 0; l < array2.Length; l++)
				{
					if (!(sqrMagnitude >= array2[l]))
					{
						for (int num2 = array2.Length - 1; num2 > l; num2--)
						{
							array2[num2] = array2[num2 - 1];
							array[num2] = array[num2 - 1];
						}
						array2[l] = sqrMagnitude;
						array[l] = val;
						break;
					}
				}
			}
			float volumeFromPercent = GetVolumeFromPercent(_fallingVolumePercent.Value);
			for (int m = 0; m < _fallingAudioSources.Count; m++)
			{
				AudioSource val3 = _fallingAudioSources[m];
				bool flag = false;
				for (int n = 0; n < array.Length; n++)
				{
					if ((Object)(object)array[n] == (Object)(object)val3)
					{
						flag = true;
						break;
					}
				}
				float num3 = (flag ? volumeFromPercent : 0f);
				val3.volume = Mathf.MoveTowards(val3.volume, num3, Time.deltaTime * 3f);
			}
		}

		private bool TryGetListenerPosition(out Vector3 listenerPosition)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Character observedCharacter = Character.observedCharacter;
			if ((Object)(object)observedCharacter != (Object)null)
			{
				listenerPosition = observedCharacter.Head;
				return true;
			}
			AudioListener val = Object.FindAnyObjectByType<AudioListener>();
			if ((Object)(object)val != (Object)null)
			{
				listenerPosition = ((Component)val).transform.position;
				return true;
			}
			if ((Object)(object)Camera.main != (Object)null)
			{
				listenerPosition = ((Component)Camera.main).transform.position;
				return true;
			}
			listenerPosition = Vector3.zero;
			return false;
		}

		private static float GetVolumeFromPercent(int percent)
		{
			return (float)Mathf.Clamp(percent, 0, 100) / 100f;
		}
	}
}