Decompiled source of Verdant v0.1.0

Verdant.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using ModMenu;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
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("Verdant")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+ad3106051585a87c82cf0ca50a4c11a5c7569db5")]
[assembly: AssemblyProduct("Verdant")]
[assembly: AssemblyTitle("Verdant")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Verdant
{
	internal static class FloraScrap
	{
		internal sealed class ScrapSpec
		{
			public string Key;

			public string DisplayName;

			public string ModelAssetName;

			public string IconAssetName;

			public int MinDollars;

			public int MaxDollars;

			public float WeightLb;

			public bool Conductive;

			public Color? GlowColor;

			public float GlowLumens;

			public Func<int> GetRarity;

			public GameObject ModelAsset;

			public Sprite Icon;

			public Item BuiltItem;
		}

		internal static readonly List<ScrapSpec> Specs = new List<ScrapSpec>
		{
			new ScrapSpec
			{
				Key = "GlowingOrchid",
				DisplayName = "Glowing orchid",
				ModelAssetName = "GlowingOrchidModel",
				IconAssetName = "icon_orchid",
				MinDollars = 44,
				MaxDollars = 76,
				WeightLb = 8f,
				Conductive = false,
				GlowColor = new Color(0.32f, 0.86f, 0.96f),
				GlowLumens = 16f,
				GetRarity = () => Plugin.OrchidRarity.Value
			},
			new ScrapSpec
			{
				Key = "BrassSprayer",
				DisplayName = "Brass plant sprayer",
				ModelAssetName = "BrassSprayerModel",
				IconAssetName = "icon_sprayer",
				MinDollars = 36,
				MaxDollars = 64,
				WeightLb = 14f,
				Conductive = true,
				GlowColor = null,
				GlowLumens = 0f,
				GetRarity = () => Plugin.SprayerRarity.Value
			},
			new ScrapSpec
			{
				Key = "SeedCanister",
				DisplayName = "Seed canister",
				ModelAssetName = "SeedCanisterModel",
				IconAssetName = "icon_canister",
				MinDollars = 52,
				MaxDollars = 88,
				WeightLb = 16f,
				Conductive = true,
				GlowColor = new Color(0.3f, 0.95f, 0.42f),
				GlowLumens = 14f,
				GetRarity = () => Plugin.CanisterRarity.Value
			}
		};

		internal static readonly List<Item> RegisteredItems = new List<Item>();

		private static GameObject _prefabContainer;

		private static bool _built;

		internal static void TryLoadAndRegister()
		{
			string text = Path.Combine(Plugin.Folder, "verdant_scrap");
			if (!File.Exists(text))
			{
				Plugin.Log.LogWarning((object)("Verdant: verdant_scrap bundle not found at " + text));
				return;
			}
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)("Verdant: failed loading verdant_scrap bundle at " + text));
				return;
			}
			int num = 0;
			foreach (ScrapSpec spec in Specs)
			{
				spec.ModelAsset = val.LoadAsset<GameObject>(spec.ModelAssetName);
				spec.Icon = val.LoadAsset<Sprite>(spec.IconAssetName);
				if ((Object)(object)spec.ModelAsset != (Object)null)
				{
					num++;
				}
			}
			Plugin.Log.LogInfo((object)$"Verdant: loaded {num}/{Specs.Count} flora scrap models from verdant_scrap.");
		}

		internal static void BuildNetworkPrefabs()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			if (_built)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				return;
			}
			List<GrabbableObject> source = (from p in singleton.NetworkConfig.Prefabs.Prefabs
				select (!((Object)(object)p.Prefab != (Object)null)) ? null : p.Prefab.GetComponent<GrabbableObject>() into g
				where (Object)(object)g != (Object)null && (Object)(object)g.itemProperties != (Object)null && g is PhysicsProp && !g.itemProperties.twoHanded
				select g).ToList();
			GrabbableObject val = ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g.itemProperties.itemName == "Plastic fish")) ?? ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g.itemProperties.itemName == "Brass bell")) ?? source.FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Verdant: could not find vanilla PhysicsProp template to build flora scrap.");
				return;
			}
			_prefabContainer = new GameObject("Verdant.FloraScrapPrefabs");
			_prefabContainer.SetActive(false);
			((Object)_prefabContainer).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)_prefabContainer);
			AudioSource component = ((Component)val).GetComponent<AudioSource>();
			ScanNodeProperties componentInChildren = ((Component)val).GetComponentInChildren<ScanNodeProperties>(true);
			Bounds bounds = default(Bounds);
			foreach (ScrapSpec spec in Specs)
			{
				if ((Object)(object)spec.ModelAsset == (Object)null)
				{
					continue;
				}
				GameObject val2 = new GameObject("Verdant_" + spec.Key);
				val2.transform.SetParent(_prefabContainer.transform, false);
				val2.layer = ((Component)val).gameObject.layer;
				val2.tag = ((Component)val).gameObject.tag;
				NetworkObject obj = val2.AddComponent<NetworkObject>();
				AccessTools.Field(typeof(NetworkObject), "GlobalObjectIdHash").SetValue(obj, StableHash("daniel.lethalcompany.verdant.Scrap." + spec.Key));
				AudioSource val3 = val2.AddComponent<AudioSource>();
				val3.playOnAwake = false;
				val3.spatialBlend = 1f;
				val3.rolloffMode = (AudioRolloffMode)1;
				val3.minDistance = 2f;
				val3.maxDistance = 22f;
				if ((Object)(object)component != (Object)null)
				{
					val3.outputAudioMixerGroup = component.outputAudioMixerGroup;
				}
				GameObject val4 = Object.Instantiate<GameObject>(spec.ModelAsset, val2.transform, false);
				((Object)val4).name = "Model";
				Transform[] componentsInChildren = val4.GetComponentsInChildren<Transform>(true);
				for (int num = 0; num < componentsInChildren.Length; num++)
				{
					((Component)componentsInChildren[num]).gameObject.layer = val2.layer;
				}
				((Bounds)(ref bounds))..ctor(Vector3.up * 0.18f, new Vector3(0.22f, 0.36f, 0.22f));
				MeshRenderer[] componentsInChildren2 = val4.GetComponentsInChildren<MeshRenderer>();
				if (componentsInChildren2.Length != 0)
				{
					bounds = ((Renderer)componentsInChildren2[0]).bounds;
					for (int num2 = 1; num2 < componentsInChildren2.Length; num2++)
					{
						((Bounds)(ref bounds)).Encapsulate(((Renderer)componentsInChildren2[num2]).bounds);
					}
				}
				BoxCollider val5 = val2.AddComponent<BoxCollider>();
				val5.center = ((Bounds)(ref bounds)).center - val2.transform.position;
				val5.size = new Vector3(Mathf.Max(0.18f, ((Bounds)(ref bounds)).size.x), Mathf.Max(0.24f, ((Bounds)(ref bounds)).size.y), Mathf.Max(0.18f, ((Bounds)(ref bounds)).size.z));
				if ((Object)(object)componentInChildren != (Object)null)
				{
					ScanNodeProperties component2 = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, val2.transform, false).GetComponent<ScanNodeProperties>();
					((Component)component2).transform.localPosition = val5.center;
					component2.headerText = spec.DisplayName;
					component2.subText = "Value: ";
					component2.scrapValue = 0;
					component2.nodeType = 2;
					component2.minRange = 1;
					component2.maxRange = 13;
				}
				if (spec.GlowColor.HasValue && spec.GlowLumens > 0f)
				{
					GameObject val6 = new GameObject("BioGlow");
					val6.transform.SetParent(val4.transform, false);
					val6.transform.localPosition = new Vector3(0f, 0.26f, 0f);
					val6.layer = val2.layer;
					Light obj2 = val6.AddComponent<Light>();
					obj2.type = (LightType)2;
					obj2.color = spec.GlowColor.Value;
					obj2.range = 2.8f;
					obj2.shadows = (LightShadows)0;
					HDAdditionalLightData obj3 = val6.AddComponent<HDAdditionalLightData>();
					obj3.SetIntensity(spec.GlowLumens, (LightUnit)0);
					obj3.SetRange(2.8f);
					obj3.SetColor(spec.GlowColor.Value, -1f);
					obj3.EnableShadows(false);
				}
				Item val7 = Object.Instantiate<Item>(val.itemProperties);
				((Object)val7).name = spec.Key + "Item";
				val7.itemName = spec.DisplayName;
				if ((Object)(object)spec.Icon != (Object)null)
				{
					val7.itemIcon = spec.Icon;
				}
				val7.spawnPrefab = val2;
				val7.isScrap = true;
				val7.minValue = Mathf.RoundToInt((float)spec.MinDollars / 0.4f);
				val7.maxValue = Mathf.RoundToInt((float)spec.MaxDollars / 0.4f);
				val7.creditsWorth = 0;
				val7.twoHanded = false;
				val7.requiresBattery = false;
				val7.isConductiveMetal = spec.Conductive;
				val7.weight = 1f + spec.WeightLb / 105f;
				val7.verticalOffset = 0.02f;
				val7.restingRotation = Vector3.zero;
				val7.positionOffset = new Vector3(0.02f, 0.14f, -0.04f);
				val7.rotationOffset = new Vector3(0f, 0f, -90f);
				val7.meshVariants = Array.Empty<Mesh>();
				val7.materialVariants = Array.Empty<Material>();
				PhysicsProp obj4 = val2.AddComponent<PhysicsProp>();
				((GrabbableObject)obj4).itemProperties = val7;
				((GrabbableObject)obj4).grabbable = true;
				((GrabbableObject)obj4).grabbableToEnemies = true;
				((GrabbableObject)obj4).isInFactory = true;
				((GrabbableObject)obj4).mainObjectRenderer = componentsInChildren2.FirstOrDefault();
				singleton.AddNetworkPrefab(val2);
				int num3 = Mathf.Max(0, spec.GetRarity());
				Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int> { 
				{
					(LevelTypes)1024,
					Mathf.Max(4, num3 / 5)
				} };
				Dictionary<string, int> dictionary2 = new Dictionary<string, int>
				{
					{ "33 Verdant", num3 },
					{ "Verdant", num3 }
				};
				Items.RegisterScrap(val7, dictionary, dictionary2);
				spec.BuiltItem = val7;
				RegisteredItems.Add(val7);
			}
			_built = true;
			Plugin.Log.LogInfo((object)$"Verdant: built and registered {RegisteredItems.Count} networked flora scrap items.");
		}

		private static uint StableHash(string s)
		{
			using MD5 mD = MD5.Create();
			return BitConverter.ToUInt32(mD.ComputeHash(Encoding.UTF8.GetBytes(s)), 0);
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Start")]
	internal static class FloraScrapNetworkPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			try
			{
				FloraScrap.BuildNetworkPrefabs();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Verdant: failed building flora scrap prefabs: " + ex));
			}
		}
	}
	internal static class MenuHooks
	{
		internal const string ModMenuGuid = "daniel.lethalcompany.modmenu";

		private const string Tab = "33-Verdant";

		private static StartOfRound Sor => StartOfRound.Instance;

		private static PlayerControllerB Me
		{
			get
			{
				if (!((Object)(object)Sor != (Object)null))
				{
					return null;
				}
				return Sor.localPlayerController;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			try
			{
				RegisterConfigSettings();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Verdant: ModMenu < 0.3.6 fallback (" + ex.GetType().Name + "); using legacy toggles."));
				MenuApi.Toggle("33-Verdant", "Skylight hazards", (Func<bool>)(() => Plugin.SkylightHazards.Value), (Func<bool, string>)delegate(bool on)
				{
					Plugin.SkylightHazards.Value = on;
					return "skylight hazards " + (on ? "on" : "off");
				}, true, false, (Func<string>)null, "overhead dome glass cracks and rains shards in Stormy or Rainy weather");
				MenuApi.Choice("33-Verdant", "Skylight shatter chance", new string[4] { "15%", "35%", "60%", "100%" }, (Func<int, string>)delegate(int i)
				{
					float num = (new float[4] { 15f, 35f, 60f, 100f })[i];
					Plugin.SkylightShatterChance.Value = num;
					return $"shatter chance set to {num:0}%";
				}, true, false, (Func<string>)null, "percent chance per storm check that an overhead skylight fractures");
				MenuApi.Toggle("33-Verdant", "Crack warning ring & HUD alert", (Func<bool>)(() => Plugin.ShatterWarnings.Value), (Func<bool, string>)delegate(bool on)
				{
					Plugin.ShatterWarnings.Value = on;
					return "warnings " + (on ? "on" : "off");
				}, false, false, (Func<string>)null, "local player visual warning ring and tip before shards fall");
			}
			MenuApi.Button("33-Verdant", "Shatter skylight now", (Func<string>)ShatterNow, true, true, (Func<string>)RequireLandedOnVerdant, "triggers an immediate telegraphed glass-shard cascade 5 m ahead of you (any weather)");
			MenuApi.Button("33-Verdant", "Route ship to 33-Verdant", (Func<string>)RouteToVerdant, true, true, (Func<string>)RouteBlocked, "free debug route to 33-Verdant while in orbit");
			MenuApi.Button("33-Verdant", "Teleport: Dome Atrium", (Func<string>)(() => TeleportLocal(SkylightHazard.DomeWorldCenter + Vector3.up * 0.5f, inside: false)), true, true, (Func<string>)RequireLandedOnVerdant, "teleports you to the central botanical dome plaza");
			MenuApi.Button("33-Verdant", "Teleport: Main Entrance (outside)", (Func<string>)(() => TeleportToEntrance(main: true)), true, true, (Func<string>)RequireLanded, "teleports you outside the Conservatory main entrance");
			MenuApi.Button("33-Verdant", "Teleport: Fire Exit (outside)", (Func<string>)(() => TeleportToEntrance(main: false)), true, true, (Func<string>)RequireLanded, "teleports you outside the upper-terrace fire exit");
			MenuApi.Button("33-Verdant", "Teleport: Ship", (Func<string>)TeleportToShip, true, true, (Func<string>)RequireLanded, "teleports you back inside the landed ship");
			foreach (FloraScrap.ScrapSpec spec in FloraScrap.Specs)
			{
				FloraScrap.ScrapSpec sp = spec;
				MenuApi.Button("33-Verdant", "Spawn " + sp.DisplayName, (Func<string>)(() => SpawnScrapAhead(sp.BuiltItem)), true, true, (Func<string>)delegate
				{
					object obj = RequireInGame();
					if (obj == null)
					{
						if (!((Object)(object)sp.BuiltItem == (Object)null))
						{
							return (string)null;
						}
						obj = "scrap bundle not loaded";
					}
					return (string)obj;
				}, $"spawns {sp.DisplayName} (${sp.MinDollars}-${sp.MaxDollars}) ahead of you");
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterConfigSettings()
		{
			MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.SkylightHazards, "Skylight hazards", true, "overhead dome glass cracks and rains shards in Stormy or Rainy weather", (Func<string>)null);
			MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.SkylightShatterChance, "Skylight shatter chance (%)", true, "percent chance per storm check that an overhead skylight fractures (0-100)", (Func<string>)null);
			MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.ShatterWarnings, "Crack warning ring & HUD alert", false, "local player visual warning ring and tip before shards fall", (Func<string>)null);
			MenuApi.Tuning((Action)delegate
			{
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.TelegraphSeconds, "Telegraph warning seconds", true, "seconds between fracture flash and shards hitting the ground", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.ShardDamage, "Shard hit damage", true, "HP lost if caught in falling shards without overhead cover", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.ShardRadius, "Shard zone radius (m)", true, "radius of the skylight shatter hazard circle", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.ShatterIntervalSeconds, "Storm check interval (s)", true, "seconds between skylight shatter rolls in Stormy/Rainy weather", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.RainyChanceScale, "Rainy weather chance multiplier", true, "scales SkylightShatterChance when weather is Rainy instead of Stormy", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.OrchidRarity, "Glowing Orchid spawn weight", true, "scrap table weight (applies on game start)", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.SprayerRarity, "Brass Sprayer spawn weight", true, "scrap table weight (applies on game start)", (Func<string>)null);
				MenuApi.Setting("33-Verdant", (ConfigEntryBase)(object)Plugin.CanisterRarity, "Seed Canister spawn weight", true, "scrap table weight (applies on game start)", (Func<string>)null);
			});
		}

		private static string RequireInGame()
		{
			if ((Object)(object)Sor == (Object)null || (Object)(object)Me == (Object)null)
			{
				return "not in a game";
			}
			return null;
		}

		private static string RequireLanded()
		{
			if ((Object)(object)Sor == (Object)null || (Object)(object)Me == (Object)null)
			{
				return "not in a game";
			}
			if (Sor.inShipPhase || (Object)(object)RoundManager.Instance == (Object)null)
			{
				return "land on a moon first";
			}
			if (Me.isPlayerDead)
			{
				return "you are dead";
			}
			return null;
		}

		private static string RequireLandedOnVerdant()
		{
			string text = RequireLanded();
			if (text != null)
			{
				return text;
			}
			if (!Plugin.IsOnVerdant())
			{
				return "land on 33-Verdant first";
			}
			return null;
		}

		private static SelectableLevel FindVerdantLevel()
		{
			if ((Object)(object)Sor == (Object)null || Sor.levels == null)
			{
				return null;
			}
			return ((IEnumerable<SelectableLevel>)Sor.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => (Object)(object)l != (Object)null && ((l.PlanetName != null && l.PlanetName.IndexOf("Verdant", StringComparison.OrdinalIgnoreCase) >= 0) || (l.sceneName != null && l.sceneName.StartsWith("Verdant", StringComparison.OrdinalIgnoreCase)))));
		}

		private static string RouteBlocked()
		{
			if ((Object)(object)Sor == (Object)null || (Object)(object)Me == (Object)null)
			{
				return "not in a game";
			}
			SelectableLevel val = FindVerdantLevel();
			if ((Object)(object)val == (Object)null)
			{
				return "33-Verdant moon bundle not loaded";
			}
			if ((Object)(object)Sor.currentLevel == (Object)(object)val)
			{
				return "already routed to 33-Verdant";
			}
			if (!Sor.inShipPhase)
			{
				return "in orbit only";
			}
			if (Sor.travellingToNewLevel)
			{
				return "already travelling";
			}
			return null;
		}

		private static string RouteToVerdant()
		{
			SelectableLevel val = FindVerdantLevel();
			Terminal val2 = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return null;
			}
			Sor.ChangeLevelServerRpc(val.levelID, val2.groupCredits);
			return "routed the ship to " + val.PlanetName;
		}

		private static string ShatterNow()
		{
			//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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB me = Me;
			if ((Object)(object)me == (Object)null)
			{
				return null;
			}
			Vector3 forward = ((Component)me).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.01f)
			{
				forward = Vector3.forward;
			}
			Vector3 val = ((Component)me).transform.position + ((Vector3)(ref forward)).normalized * 5f;
			int collidersAndRoomMaskAndDefault = Sor.collidersAndRoomMaskAndDefault;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val + Vector3.up * 20f, Vector3.down, ref val2, 50f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				val = ((RaycastHit)(ref val2)).point;
			}
			Vector3 roof = val + Vector3.up * 26f;
			SkylightHazard.TriggerAt(val, roof);
			return "shattering skylight 5 m ahead";
		}

		private static string TeleportToEntrance(bool main)
		{
			//IL_0090: 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_009f: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsOfType<EntranceTeleport>()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => (Object)(object)e != (Object)null && e.isEntranceToBuilding && ((!main) ? (e.entranceId != 0) : (e.entranceId == 0))));
			if ((Object)(object)val == (Object)null)
			{
				if (!main)
				{
					return "no fire exit found";
				}
				return "no main entrance found";
			}
			return TeleportLocal(((Object)(object)val.entrancePoint != (Object)null) ? (val.entrancePoint.position + Vector3.up * 0.25f) : (((Component)val).transform.position - ((Component)val).transform.forward * 1.6f + Vector3.up * 0.25f), inside: false, inShip: false, main ? "main entrance" : "fire exit");
		}

		private static string TeleportToShip()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Sor == (Object)null || (Object)(object)Sor.middleOfShipNode == (Object)null)
			{
				return null;
			}
			return TeleportLocal(Sor.middleOfShipNode.position, inside: false, inShip: true, "the ship");
		}

		private static string TeleportLocal(Vector3 pos, bool inside, bool inShip = false, string label = "dome atrium")
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB me = Me;
			if ((Object)(object)me == (Object)null)
			{
				return null;
			}
			me.TeleportPlayer(pos, false, 0f, false, true);
			me.isInsideFactory = inside;
			me.isInElevator = inShip;
			me.isInHangarShipRoom = inShip;
			return "teleported to " + label;
		}

		private static string SpawnScrapAhead(Item item)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0060: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)item == (Object)null || (Object)(object)item.spawnPrefab == (Object)null || (Object)(object)Me == (Object)null || (Object)(object)RoundManager.Instance == (Object)null)
			{
				return null;
			}
			Vector3 val = ((Component)Me).transform.position + ((Component)Me).transform.forward * 2f + Vector3.up * 0.5f;
			GameObject obj = Object.Instantiate<GameObject>(item.spawnPrefab, val, Quaternion.identity, RoundManager.Instance.spawnedScrapContainer);
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			int num = Random.Range(item.minValue, item.maxValue + 1);
			if ((Object)(object)component != (Object)null)
			{
				component.fallTime = 0f;
				component.SetScrapValue(num);
			}
			NetworkObject component2 = obj.GetComponent<NetworkObject>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Spawn(false);
			}
			return $"spawned {item.itemName} (${num})";
		}
	}
	internal static class Net
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnShatterMessage;
		}

		private const string MsgShatter = "daniel.verdant.shatter";

		private static bool _registered;

		private static NetworkManager _nm;

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton != (Object)null)
				{
					return NetworkManager.Singleton.IsServer;
				}
				return false;
			}
		}

		public static void Tick()
		{
			//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_006f: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				_registered = false;
				_nm = null;
			}
			else
			{
				if (_registered && (Object)(object)singleton == (Object)(object)_nm)
				{
					return;
				}
				if (!singleton.IsServer)
				{
					CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
					object obj = <>O.<0>__OnShatterMessage;
					if (obj == null)
					{
						HandleNamedMessageDelegate val = OnShatterMessage;
						<>O.<0>__OnShatterMessage = val;
						obj = (object)val;
					}
					customMessagingManager.RegisterNamedMessageHandler("daniel.verdant.shatter", (HandleNamedMessageDelegate)obj);
				}
				_registered = true;
				_nm = singleton;
			}
		}

		public unsafe static void BroadcastShatter(Vector3 groundPos, Vector3 roofPos, float telegraphSec, float radius, int damage, int seed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00ad: 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)
			SkylightHazard.SpawnLocalSequence(groundPos, roofPos, telegraphSec, radius, damage, seed);
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L)
				{
					((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
					try
					{
						((FastBufferWriter)(ref val)).WriteValueSafe(ref groundPos);
						((FastBufferWriter)(ref val)).WriteValueSafe(ref roofPos);
						((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref telegraphSec, default(ForPrimitives));
						((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref radius, default(ForPrimitives));
						((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref damage, default(ForPrimitives));
						((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref seed, default(ForPrimitives));
						singleton.CustomMessagingManager.SendNamedMessage("daniel.verdant.shatter", connectedClientsId, val, (NetworkDelivery)3);
					}
					finally
					{
						((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
					}
				}
			}
		}

		private static void OnShatterMessage(ulong senderClientId, FastBufferReader reader)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (senderClientId == 0L)
			{
				Vector3 groundPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref groundPos);
				Vector3 roofPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref roofPos);
				float telegraphSec = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref telegraphSec, default(ForPrimitives));
				float radius = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref radius, default(ForPrimitives));
				int damage = default(int);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref damage, default(ForPrimitives));
				int seed = default(int);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref seed, default(ForPrimitives));
				SkylightHazard.SpawnLocalSequence(groundPos, roofPos, telegraphSec, radius, damage, seed);
			}
		}
	}
	[BepInPlugin("daniel.lethalcompany.verdant", "Verdant", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "daniel.lethalcompany.verdant";

		public const string ScenePrefix = "Verdant";

		public const string PlanetMatch = "Verdant";

		internal static ManualLogSource Log;

		internal static string Folder;

		internal static ConfigEntry<bool> SkylightHazards;

		internal static ConfigEntry<float> SkylightShatterChance;

		internal static ConfigEntry<bool> ShatterWarnings;

		internal static ConfigEntry<float> TelegraphSeconds;

		internal static ConfigEntry<int> ShardDamage;

		internal static ConfigEntry<float> ShardRadius;

		internal static ConfigEntry<float> ShatterIntervalSeconds;

		internal static ConfigEntry<float> RainyChanceScale;

		internal static ConfigEntry<int> OrchidRarity;

		internal static ConfigEntry<int> SprayerRarity;

		internal static ConfigEntry<int> CanisterRarity;

		private void Awake()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Expected O, but got Unknown
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Folder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty;
			SkylightHazards = ((BaseUnityPlugin)this).Config.Bind<bool>("Skylights", "SkylightHazards", true, "In Stormy or Rainy weather on 33-Verdant, overhead dome panels periodically crack and rain glass shards (host).");
			SkylightShatterChance = ((BaseUnityPlugin)this).Config.Bind<float>("Skylights", "SkylightShatterChance", 35f, new ConfigDescription("Percent chance (0-100) each storm check that an overhead geodesic glass panel cracks and shatters (host).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			ShatterWarnings = ((BaseUnityPlugin)this).Config.Bind<bool>("Skylights", "ShatterWarnings", true, "Show the ground warning ring and HUD alert when an overhead panel begins cracking above you (local).");
			TelegraphSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "TelegraphSeconds", 2.6f, new ConfigDescription("Seconds between overhead panel fracture telegraph and glass shards landing (host).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.8f, 8f), Array.Empty<object>()));
			ShardDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Tuning", "ShardDamage", 30, new ConfigDescription("Damage dealt if caught in falling glass shards without cover; telegraphed hazard, never instant death (host).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 85), Array.Empty<object>()));
			ShardRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "ShardRadius", 3.2f, new ConfigDescription("Radius in metres of each skylight shard-fall zone (host).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.5f, 8f), Array.Empty<object>()));
			ShatterIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "ShatterIntervalSeconds", 7f, new ConfigDescription("Seconds between skylight fracture checks during Stormy/Rainy weather (host).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), Array.Empty<object>()));
			RainyChanceScale = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "RainyChanceScale", 0.6f, new ConfigDescription("Multiplier on SkylightShatterChance during Rainy weather compared to Stormy (host).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1.5f), Array.Empty<object>()));
			OrchidRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Tuning", "OrchidRarity", 42, new ConfigDescription("Spawn weight of the Glowing Orchid scrap on 33-Verdant.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			SprayerRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Tuning", "SprayerRarity", 38, new ConfigDescription("Spawn weight of the Brass Plant Sprayer scrap on 33-Verdant.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			CanisterRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Tuning", "CanisterRarity", 32, new ConfigDescription("Spawn weight of the Seed Canister scrap on 33-Verdant.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			FloraScrap.TryLoadAndRegister();
			new Harmony("daniel.lethalcompany.verdant").PatchAll(typeof(Plugin).Assembly);
			if (Chainloader.PluginInfos.ContainsKey("daniel.lethalcompany.modmenu"))
			{
				MenuHooks.Register();
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
			GameObject val = new GameObject("VerdantRunner");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<VerdantRunner>();
			Log.LogInfo((object)"33-Verdant plugin loaded");
		}

		internal static bool IsVerdantScene(Scene s)
		{
			if (((Scene)(ref s)).IsValid() && ((Scene)(ref s)).name != null)
			{
				return ((Scene)(ref s)).name.StartsWith("Verdant");
			}
			return false;
		}

		internal static bool IsOnVerdant()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.currentLevel == (Object)null)
			{
				return false;
			}
			string obj = instance.currentLevel.PlanetName ?? string.Empty;
			string text = instance.currentLevel.sceneName ?? string.Empty;
			if (obj.IndexOf("Verdant", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return text.StartsWith("Verdant", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static void OnSceneLoaded(Scene s, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (IsVerdantScene(s))
			{
				SkylightHazard.OnVerdantSceneLoaded(s);
			}
		}
	}
	internal sealed class VerdantRunner : MonoBehaviour
	{
		private float _nextNetTick;

		private void Update()
		{
			if (Time.unscaledTime >= _nextNetTick)
			{
				_nextNetTick = Time.unscaledTime + 0.5f;
				Net.Tick();
			}
			SkylightHazard.Tick();
		}
	}
	internal static class SkylightHazard
	{
		private sealed class ActiveShatter
		{
			public Vector3 Ground;

			public Vector3 Roof;

			public float StartTime;

			public float TelegraphSec;

			public float Radius;

			public int Damage;

			public bool Impacted;

			public bool WarnedHud;

			public GameObject Root;

			public Transform RingTransform;

			public Light OverheadLight;

			public Light GroundLight;

			public readonly List<ShardPiece> Shards = new List<ShardPiece>();
		}

		private struct ShardPiece
		{
			public Transform Tf;

			public Vector3 Start;

			public Vector3 End;

			public Vector3 Spin;

			public float Delay;
		}

		internal static Vector3 DomeWorldCenter = new Vector3(-70.3f, 0f, -15.2f);

		internal const float DomePlayableRadius = 43f;

		internal const float DomeApexHeight = 36.2f;

		private static float _nextStormRoll;

		private static Mesh _shardMesh;

		private static Material _shardMat;

		private static Material _ringMat;

		private static readonly List<ActiveShatter> _active = new List<ActiveShatter>();

		internal static void OnVerdantSceneLoaded(Scene s)
		{
			//IL_002e: 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)
			ClearAll();
			GameObject[] rootGameObjects = ((Scene)(ref s)).GetRootGameObjects();
			for (int i = 0; i < rootGameObjects.Length; i++)
			{
				Transform val = rootGameObjects[i].transform.Find("VerdantDomeCenter");
				if ((Object)(object)val != (Object)null)
				{
					DomeWorldCenter = val.position;
					break;
				}
			}
			_nextStormRoll = Time.time + 8f;
		}

		internal static void Tick()
		{
			//IL_0089: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Invalid comparison between Unknown and I4
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.inShipPhase || !Plugin.IsOnVerdant())
			{
				if (_active.Count > 0)
				{
					ClearAll();
				}
				return;
			}
			UpdateActiveSequences();
			if (!Net.IsHost || !Plugin.SkylightHazards.Value || Time.time < _nextStormRoll)
			{
				return;
			}
			float num = Mathf.Max(2f, Plugin.ShatterIntervalSeconds.Value);
			_nextStormRoll = Time.time + num;
			TimeOfDay instance2 = TimeOfDay.Instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				return;
			}
			LevelWeatherType currentLevelWeather = instance2.currentLevelWeather;
			if ((int)currentLevelWeather == 2 || (int)currentLevelWeather == 1)
			{
				float num2 = Plugin.SkylightShatterChance.Value;
				if ((int)currentLevelWeather == 1)
				{
					num2 *= Plugin.RainyChanceScale.Value;
				}
				if (!(Random.Range(0f, 100f) > num2) && TryPickTargetSpot(nearPlayers: true, out var ground, out var roof))
				{
					TriggerAt(ground, roof);
				}
			}
		}

		internal static void TriggerAt(Vector3 ground, Vector3 roof)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Net.BroadcastShatter(ground, roof, Plugin.TelegraphSeconds.Value, Plugin.ShardRadius.Value, Plugin.ShardDamage.Value, Random.Range(1, int.MaxValue));
		}

		internal static bool TryPickTargetSpot(bool nearPlayers, out Vector3 ground, out Vector3 roof)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: 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_011b: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			ground = Vector3.zero;
			roof = Vector3.zero;
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			Vector3 val = DomeWorldCenter;
			bool flag = false;
			if (nearPlayers && instance.allPlayerScripts != null)
			{
				List<PlayerControllerB> list = new List<PlayerControllerB>();
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				Vector2 val3 = default(Vector2);
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if (!((Object)(object)val2 == (Object)null) && val2.isPlayerControlled && !val2.isPlayerDead && !val2.isInsideFactory && !val2.isInHangarShipRoom)
					{
						((Vector2)(ref val3))..ctor(((Component)val2).transform.position.x - DomeWorldCenter.x, ((Component)val2).transform.position.z - DomeWorldCenter.z);
						if (((Vector2)(ref val3)).magnitude <= 43f)
						{
							list.Add(val2);
						}
					}
				}
				if (list.Count > 0)
				{
					PlayerControllerB obj = list[Random.Range(0, list.Count)];
					Vector2 val4 = Random.insideUnitCircle * 5.5f;
					val = ((Component)obj).transform.position + new Vector3(val4.x, 0f, val4.y);
					flag = true;
				}
			}
			if (!flag)
			{
				Vector2 val5 = Random.insideUnitCircle * 33.539997f;
				val = DomeWorldCenter + new Vector3(val5.x, 8f, val5.y);
			}
			int collidersAndRoomMaskAndDefault = instance.collidersAndRoomMaskAndDefault;
			RaycastHit val6 = default(RaycastHit);
			if (Physics.Raycast(new Vector3(val.x, DomeWorldCenter.y + 36.2f - 2f, val.z), Vector3.down, ref val6, 56.2f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				ground = ((RaycastHit)(ref val6)).point;
			}
			else
			{
				ground = new Vector3(val.x, DomeWorldCenter.y, val.z);
			}
			float num = Mathf.Clamp01(Vector2.Distance(new Vector2(ground.x, ground.z), new Vector2(DomeWorldCenter.x, DomeWorldCenter.z)) / 46f);
			float num2 = DomeWorldCenter.y + 3f + Mathf.Sqrt(Mathf.Max(0.05f, 1f - num * num)) * 31f;
			roof = new Vector3(ground.x, Mathf.Max(ground.y + 8f, num2), ground.z);
			return true;
		}

		internal static void SpawnLocalSequence(Vector3 groundPos, Vector3 roofPos, float telegraphSec, float radius, int damage, int seed)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0097: 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_00a2: 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_00de: 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_0123: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: 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_026f: Expected O, but got Unknown
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			EnsureVisualAssets();
			GameObject val = new GameObject("VerdantSkylightShatter");
			val.transform.position = groundPos;
			ActiveShatter activeShatter = new ActiveShatter
			{
				Ground = groundPos,
				Roof = roofPos,
				StartTime = Time.time,
				TelegraphSec = Mathf.Max(0.5f, telegraphSec),
				Radius = Mathf.Max(1f, radius),
				Damage = Mathf.Clamp(damage, 1, 95),
				Root = val
			};
			GameObject val2 = new GameObject("FractureGlow");
			val2.transform.SetParent(val.transform, false);
			val2.transform.position = roofPos - Vector3.up * 0.8f;
			activeShatter.OverheadLight = val2.AddComponent<Light>();
			activeShatter.OverheadLight.type = (LightType)2;
			activeShatter.OverheadLight.color = new Color(1f, 0.68f, 0.25f);
			activeShatter.OverheadLight.range = 22f;
			activeShatter.OverheadLight.intensity = 18f;
			if (Plugin.ShatterWarnings.Value)
			{
				GameObject val3 = new GameObject("TelegraphGroundLight");
				val3.transform.SetParent(val.transform, false);
				val3.transform.position = groundPos + Vector3.up * 1.1f;
				activeShatter.GroundLight = val3.AddComponent<Light>();
				activeShatter.GroundLight.type = (LightType)2;
				activeShatter.GroundLight.color = new Color(1f, 0.62f, 0.18f);
				activeShatter.GroundLight.range = radius * 2.4f;
				activeShatter.GroundLight.intensity = 8f;
				GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)2);
				((Object)val4).name = "WarningDisc";
				Object.Destroy((Object)(object)val4.GetComponent<Collider>());
				val4.transform.SetParent(val.transform, false);
				val4.transform.position = groundPos + Vector3.up * 0.04f;
				val4.transform.localScale = new Vector3(radius * 2f, 0.012f, radius * 2f);
				((Renderer)val4.GetComponent<MeshRenderer>()).sharedMaterial = _ringMat;
				activeShatter.RingTransform = val4.transform;
			}
			Random random = new Random(seed);
			for (int i = 0; i < 18; i++)
			{
				GameObject val5 = new GameObject("GlassShard_" + i);
				val5.transform.SetParent(val.transform, false);
				val5.AddComponent<MeshFilter>().sharedMesh = _shardMesh;
				((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterial = _shardMat;
				float num = (float)(random.NextDouble() * 3.1415927410125732 * 2.0);
				float num2 = Mathf.Sqrt((float)random.NextDouble()) * radius * 0.92f;
				Vector3 end = groundPos + new Vector3(Mathf.Cos(num) * num2, 0.06f, Mathf.Sin(num) * num2);
				Vector3 start = roofPos + new Vector3(Mathf.Cos(num) * num2 * 0.25f, 0f, Mathf.Sin(num) * num2 * 0.25f);
				float num3 = 0.18f + (float)random.NextDouble() * 0.28f;
				val5.transform.localScale = new Vector3(num3, num3 * 1.35f, num3);
				val5.SetActive(false);
				activeShatter.Shards.Add(new ShardPiece
				{
					Tf = val5.transform,
					Start = start,
					End = end,
					Spin = new Vector3((float)random.NextDouble() * 520f, (float)random.NextDouble() * 520f, (float)random.NextDouble() * 520f),
					Delay = (float)random.NextDouble() * 0.28f
				});
			}
			_active.Add(activeShatter);
		}

		private static void UpdateActiveSequences()
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			PlayerControllerB val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.localPlayerController : null);
			for (int num = _active.Count - 1; num >= 0; num--)
			{
				ActiveShatter activeShatter = _active[num];
				if ((Object)(object)activeShatter.Root == (Object)null)
				{
					_active.RemoveAt(num);
				}
				else
				{
					float num2 = time - activeShatter.StartTime;
					float num3 = 0.65f;
					if (num2 < activeShatter.TelegraphSec)
					{
						float num4 = num2 / activeShatter.TelegraphSec;
						float num5 = 0.6f + 0.4f * Mathf.Sin(num2 * (10f + 16f * num4));
						if ((Object)(object)activeShatter.OverheadLight != (Object)null)
						{
							activeShatter.OverheadLight.intensity = 18f * num5;
						}
						if ((Object)(object)activeShatter.GroundLight != (Object)null)
						{
							activeShatter.GroundLight.intensity = 10f * num5;
						}
						if ((Object)(object)activeShatter.RingTransform != (Object)null)
						{
							float num6 = activeShatter.Radius * 2f * (0.94f + 0.06f * num5);
							activeShatter.RingTransform.localScale = new Vector3(num6, 0.012f, num6);
						}
						if (!activeShatter.WarnedHud && Plugin.ShatterWarnings.Value && (Object)(object)val != (Object)null && !val.isPlayerDead && !val.isInsideFactory && Vector3.Distance(((Component)val).transform.position, activeShatter.Ground) <= activeShatter.Radius + 1.8f && (Object)(object)HUDManager.Instance != (Object)null)
						{
							activeShatter.WarnedHud = true;
							HUDManager.Instance.DisplayTip("Skylight cracking!", "Overhead dome glass is fracturing — step clear!", true, false, "LC_Tip1");
						}
					}
					else
					{
						float num7 = num2 - activeShatter.TelegraphSec;
						for (int i = 0; i < activeShatter.Shards.Count; i++)
						{
							ShardPiece shardPiece = activeShatter.Shards[i];
							float num8 = Mathf.Clamp01((num7 - shardPiece.Delay) / num3);
							if (!(num8 <= 0f))
							{
								if (!((Component)shardPiece.Tf).gameObject.activeSelf)
								{
									((Component)shardPiece.Tf).gameObject.SetActive(true);
								}
								float num9 = num8 * num8;
								shardPiece.Tf.position = Vector3.Lerp(shardPiece.Start, shardPiece.End, num9);
								if (num8 < 1f)
								{
									shardPiece.Tf.Rotate(shardPiece.Spin * Time.deltaTime, (Space)1);
								}
							}
						}
						if (!activeShatter.Impacted && num7 >= num3 * 0.85f)
						{
							activeShatter.Impacted = true;
							if ((Object)(object)activeShatter.RingTransform != (Object)null)
							{
								((Component)activeShatter.RingTransform).gameObject.SetActive(false);
							}
							if ((Object)(object)activeShatter.GroundLight != (Object)null)
							{
								activeShatter.GroundLight.intensity = 0f;
							}
							if ((Object)(object)activeShatter.OverheadLight != (Object)null)
							{
								activeShatter.OverheadLight.intensity = 3f;
							}
							ApplyLocalImpactDamage(val, activeShatter);
						}
						if (num7 >= num3 + 2.5f)
						{
							Object.Destroy((Object)(object)activeShatter.Root);
							_active.RemoveAt(num);
						}
					}
				}
			}
		}

		private static void ApplyLocalImpactDamage(PlayerControllerB me, ActiveShatter s)
		{
			//IL_0028: 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_0042: 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_0075: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_010c: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)me == (Object)null) && !me.isPlayerDead && !me.isInsideFactory && !me.isInHangarShipRoom && !(Vector2.Distance(new Vector2(((Component)me).transform.position.x, ((Component)me).transform.position.z), new Vector2(s.Ground.x, s.Ground.z)) > s.Radius) && !(Mathf.Abs(((Component)me).transform.position.y - s.Ground.y) > 4.5f))
			{
				int num = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : (-5));
				Vector3 val = (((Object)(object)me.gameplayCamera != (Object)null) ? ((Component)me.gameplayCamera).transform.position : (((Component)me).transform.position + Vector3.up * 1.6f));
				RaycastHit val2 = default(RaycastHit);
				if (!Physics.Raycast(val, Vector3.up, ref val2, Mathf.Max(2f, s.Roof.y - val.y - 1.5f), num, (QueryTriggerInteraction)1))
				{
					me.DamagePlayer(s.Damage, true, true, (CauseOfDeath)2, 0, false, Vector3.down * 4f);
				}
			}
		}

		private static void EnsureVisualAssets()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//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_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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_01cb: 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_01e0: Expected O, but got Unknown
			//IL_0141: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_shardMesh == (Object)null)
			{
				_shardMesh = new Mesh
				{
					name = "VerdantGlassShardMesh"
				};
				_shardMesh.vertices = (Vector3[])(object)new Vector3[4]
				{
					new Vector3(0f, 0.5f, 0f),
					new Vector3(-0.35f, -0.45f, 0.08f),
					new Vector3(0.38f, -0.35f, -0.06f),
					new Vector3(0.02f, -0.15f, -0.12f)
				};
				_shardMesh.triangles = new int[12]
				{
					0, 1, 2, 0, 2, 3, 0, 3, 1, 1,
					3, 2
				};
				_shardMesh.RecalculateNormals();
			}
			Shader val = Shader.Find("HDRP/Lit") ?? Shader.Find("Standard");
			if ((Object)(object)_shardMat == (Object)null && (Object)(object)val != (Object)null)
			{
				_shardMat = new Material(val)
				{
					name = "VerdantShardMat"
				};
				if (_shardMat.HasProperty("_BaseColor"))
				{
					_shardMat.SetColor("_BaseColor", new Color(0.82f, 0.95f, 1f, 0.85f));
				}
				if (_shardMat.HasProperty("_Smoothness"))
				{
					_shardMat.SetFloat("_Smoothness", 0.95f);
				}
				if (_shardMat.HasProperty("_EmissiveColor"))
				{
					_shardMat.SetColor("_EmissiveColor", new Color(0.45f, 0.72f, 0.9f) * 1.5f);
				}
			}
			if ((Object)(object)_ringMat == (Object)null && (Object)(object)val != (Object)null)
			{
				_ringMat = new Material(val)
				{
					name = "VerdantWarningRingMat"
				};
				if (_ringMat.HasProperty("_BaseColor"))
				{
					_ringMat.SetColor("_BaseColor", new Color(1f, 0.65f, 0.18f, 0.45f));
				}
				if (_ringMat.HasProperty("_EmissiveColor"))
				{
					_ringMat.SetColor("_EmissiveColor", new Color(1f, 0.6f, 0.15f) * 2.5f);
				}
			}
		}

		private static void ClearAll()
		{
			for (int i = 0; i < _active.Count; i++)
			{
				if ((Object)(object)_active[i].Root != (Object)null)
				{
					Object.Destroy((Object)(object)_active[i].Root);
				}
			}
			_active.Clear();
		}
	}
}