Decompiled source of Hardship v0.0.16

Hardship.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("Hardship")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.16")]
[assembly: AssemblyInformationalVersion("0.0.16+037d210113da64e7dcd0a569239c32a825ac14e5")]
[assembly: AssemblyProduct("Hardship")]
[assembly: AssemblyTitle("Hardship")]
[assembly: AssemblyVersion("0.0.16.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[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 Hardship
{
	[BepInPlugin("com.valheim.hardship", "Hardship", "0.0.16")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Hardship : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Player), "FixedUpdate")]
		public static class CryptEntryPatch
		{
			private static void Postfix()
			{
				if ((Object)(object)EnvMan.instance != (Object)null)
				{
					CryptEnvironmentPatch.Refresh(EnvMan.instance);
				}
			}
		}

		[HarmonyPatch(typeof(Location), "Awake")]
		public static class GeyserTerrainPatch
		{
			private sealed class GeyserTarRingEffect : MonoBehaviour
			{
				private static readonly List<GeyserTarRingEffect> ActiveRings = new List<GeyserTarRingEffect>();

				private static Character affectedCharacter;

				private static GeyserTarRingEffect activeRing;

				private float groundHeight;

				private float movementSurfaceHeight;

				private Mesh ownedMesh;

				private void OnEnable()
				{
					if (!ActiveRings.Contains(this))
					{
						ActiveRings.Add(this);
					}
				}

				private void OnDisable()
				{
					ActiveRings.Remove(this);
					if ((Object)(object)activeRing == (Object)(object)this)
					{
						ClearLiquidLevel();
					}
				}

				public static void UpdatePlayer(Player player)
				{
					//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_002f: Unknown result type (might be due to invalid IL or missing references)
					//IL_003b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: Unknown result type (might be due to invalid IL or missing references)
					//IL_0054: Unknown result type (might be due to invalid IL or missing references)
					//IL_0073: Unknown result type (might be due to invalid IL or missing references)
					GeyserTarRingEffect geyserTarRingEffect = null;
					Vector3 position = ((Component)player).transform.position;
					foreach (GeyserTarRingEffect activeRing in ActiveRings)
					{
						if (!((Object)(object)activeRing == (Object)null))
						{
							float num = position.x - ((Component)activeRing).transform.position.x;
							float num2 = position.z - ((Component)activeRing).transform.position.z;
							float num3 = num * num + num2 * num2;
							float num4 = 57.76f;
							float num5 = position.y - activeRing.groundHeight;
							if (num3 <= num4 && num5 >= -1.5f && num5 <= activeRing.movementSurfaceHeight - activeRing.groundHeight + 1.5f)
							{
								geyserTarRingEffect = activeRing;
								break;
							}
						}
					}
					if ((Object)(object)affectedCharacter != (Object)null && (Object)(object)affectedCharacter != (Object)(object)player)
					{
						ClearLiquidLevel();
					}
					if ((Object)(object)geyserTarRingEffect == (Object)null)
					{
						ClearLiquidLevel();
						return;
					}
					((Character)player).SetLiquidLevel(geyserTarRingEffect.movementSurfaceHeight, (LiquidType)1, (Component)(object)geyserTarRingEffect);
					((Character)player).GetSEMan().AddStatusEffect(SEMan.s_statusEffectTared, true, 0, 0f, (short)(-1));
					affectedCharacter = (Character)(object)player;
					GeyserTarRingEffect.activeRing = geyserTarRingEffect;
				}

				private static void ClearLiquidLevel()
				{
					if ((Object)(object)affectedCharacter != (Object)null && (Object)(object)activeRing != (Object)null)
					{
						affectedCharacter.SetLiquidLevel(-10000f, (LiquidType)1, (Component)(object)activeRing);
					}
					affectedCharacter = null;
					activeRing = null;
				}

				public void Configure(float terrainHeight, float liquidSurfaceHeight, Mesh mesh)
				{
					groundHeight = terrainHeight;
					movementSurfaceHeight = liquidSurfaceHeight;
					MeshFilter component = ((Component)this).GetComponent<MeshFilter>();
					if ((Object)(object)ownedMesh != (Object)null)
					{
						Object.Destroy((Object)(object)ownedMesh);
					}
					ownedMesh = mesh;
					component.sharedMesh = ownedMesh;
				}

				private void OnDestroy()
				{
					if ((Object)(object)ownedMesh != (Object)null)
					{
						Object.Destroy((Object)(object)ownedMesh);
						ownedMesh = null;
					}
				}
			}

			[HarmonyPatch(typeof(Player), "FixedUpdate")]
			private static class GeyserTarRingPlayerPatch
			{
				[HarmonyPostfix]
				private static void ApplyGeyserTarToLocalPlayer(Player __instance)
				{
					if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
					{
						GeyserTarRingEffect.UpdatePlayer(__instance);
					}
				}
			}

			private sealed class GeyserGasSpawner : MonoBehaviour
			{
				private sealed class GeyserGasCloudEffect : MonoBehaviour
				{
					[HarmonyPatch(typeof(Player), "FixedUpdate")]
					private static class GeyserGasPlayerPatch
					{
						[HarmonyPostfix]
						private static void ApplyGeyserGasToLocalPlayer(Player __instance)
						{
							if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
							{
								ApplyToLocalPlayer(__instance);
							}
						}
					}

					private static readonly List<GeyserGasCloudEffect> ActiveClouds = new List<GeyserGasCloudEffect>();

					private static float staminaExhaustedTime;

					private static float nextDrowningDamageTime;

					private static readonly string[] GasParticleShaderNames = new string[3] { "Particles/Standard Unlit", "Legacy Shaders/Particles/Alpha Blended", "Sprites/Default" };

					private Vector3 cloudPosition;

					private float radius;

					private float duration;

					private float elapsed;

					private Material particleMaterial;

					public static void Spawn(Vector3 position, float cloudRadius, float cloudDuration)
					{
						//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_0010: 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)
						GameObject val = new GameObject("Hardship_GeyserSuffocatingGas");
						val.transform.position = position;
						val.AddComponent<GeyserGasCloudEffect>().Configure(position, cloudRadius, cloudDuration);
					}

					private void OnEnable()
					{
						if (!ActiveClouds.Contains(this))
						{
							ActiveClouds.Add(this);
						}
					}

					private void OnDisable()
					{
						ActiveClouds.Remove(this);
					}

					private void Configure(Vector3 position, float cloudRadius, float cloudDuration)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						cloudPosition = position;
						radius = cloudRadius;
						duration = cloudDuration;
						CreateVisibleCloud();
					}

					private void Update()
					{
						elapsed += Time.deltaTime;
						if (elapsed >= duration)
						{
							Object.Destroy((Object)(object)((Component)this).gameObject);
						}
					}

					private void OnDestroy()
					{
						if ((Object)(object)particleMaterial != (Object)null)
						{
							Object.Destroy((Object)(object)particleMaterial);
						}
					}

					private void CreateVisibleCloud()
					{
						//IL_0005: Unknown result type (might be due to invalid IL or missing references)
						//IL_000b: Expected O, but got Unknown
						//IL_0025: 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_004c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
						//IL_0098: Unknown result type (might be due to invalid IL or missing references)
						//IL_009d: Unknown result type (might be due to invalid IL or missing references)
						//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f7: 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_010a: Unknown result type (might be due to invalid IL or missing references)
						//IL_010f: Unknown result type (might be due to invalid IL or missing references)
						//IL_011a: Unknown result type (might be due to invalid IL or missing references)
						//IL_011f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0137: Unknown result type (might be due to invalid IL or missing references)
						//IL_0141: Unknown result type (might be due to invalid IL or missing references)
						//IL_0158: Unknown result type (might be due to invalid IL or missing references)
						//IL_015d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0167: Unknown result type (might be due to invalid IL or missing references)
						//IL_016e: Expected O, but got Unknown
						//IL_0187: Unknown result type (might be due to invalid IL or missing references)
						//IL_0191: Unknown result type (might be due to invalid IL or missing references)
						//IL_0196: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
						//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
						//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
						//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
						//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
						//IL_01ed: 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_0203: 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_0219: Unknown result type (might be due to invalid IL or missing references)
						//IL_0227: Unknown result type (might be due to invalid IL or missing references)
						//IL_0255: Unknown result type (might be due to invalid IL or missing references)
						//IL_025a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0265: Unknown result type (might be due to invalid IL or missing references)
						//IL_027a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0289: Expected O, but got Unknown
						GameObject val = new GameObject("GasParticles");
						val.transform.SetParent(((Component)this).transform, false);
						ParticleSystem val2 = val.AddComponent<ParticleSystem>();
						MainModule main = val2.main;
						((MainModule)(ref main)).duration = duration;
						((MainModule)(ref main)).loop = false;
						((MainModule)(ref main)).startLifetime = new MinMaxCurve(5f, 9f);
						((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.7f, 1.7f);
						((MainModule)(ref main)).startSize = new MinMaxCurve(1.5f, 3f);
						((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.55f, 0.7f, 0.28f, 0.65f));
						((MainModule)(ref main)).maxParticles = 160;
						((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
						EmissionModule emission = val2.emission;
						((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(10f);
						((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[3]
						{
							new Burst(0f, (short)28),
							new Burst(2f, (short)18),
							new Burst(4f, (short)18)
						});
						ShapeModule shape = val2.shape;
						((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
						((ShapeModule)(ref shape)).radius = 0.55f;
						((ShapeModule)(ref shape)).position = Vector3.up * 0.5f;
						((ShapeModule)(ref shape)).randomDirectionAmount = 0.8f;
						ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
						((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
						Gradient val3 = new Gradient();
						val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
						{
							new GradientColorKey(new Color(0.62f, 0.76f, 0.3f), 0f),
							new GradientColorKey(new Color(0.35f, 0.54f, 0.18f), 1f)
						}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
						{
							new GradientAlphaKey(0f, 0f),
							new GradientAlphaKey(0.55f, 0.15f),
							new GradientAlphaKey(0.4f, 0.75f),
							new GradientAlphaKey(0f, 1f)
						});
						((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
						ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
						component.renderMode = (ParticleSystemRenderMode)0;
						Shader val4 = FindGasParticleShader();
						if ((Object)(object)val4 != (Object)null)
						{
							particleMaterial = new Material(val4)
							{
								name = "Hardship_GeyserGasMaterial",
								color = new Color(0.55f, 0.7f, 0.28f, 0.65f)
							};
							((Renderer)component).sharedMaterial = particleMaterial;
						}
						val2.Play();
					}

					private static Shader FindGasParticleShader()
					{
						string[] gasParticleShaderNames = GasParticleShaderNames;
						for (int i = 0; i < gasParticleShaderNames.Length; i++)
						{
							Shader val = Shader.Find(gasParticleShaderNames[i]);
							if ((Object)(object)val != (Object)null)
							{
								return val;
							}
						}
						Logger.LogError((object)"Hardship: could not find a particle shader for the geyser gas cloud.");
						return null;
					}

					private static void ApplyToLocalPlayer(Player player)
					{
						//IL_004c: 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_0057: Unknown result type (might be due to invalid IL or missing references)
						//IL_005c: Unknown result type (might be due to invalid IL or missing references)
						//IL_011a: Unknown result type (might be due to invalid IL or missing references)
						//IL_011f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0122: Unknown result type (might be due to invalid IL or missing references)
						//IL_0140: Unknown result type (might be due to invalid IL or missing references)
						//IL_0142: Unknown result type (might be due to invalid IL or missing references)
						//IL_0147: Unknown result type (might be due to invalid IL or missing references)
						//IL_0149: Unknown result type (might be due to invalid IL or missing references)
						//IL_014e: 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_0154: 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_0169: Unknown result type (might be due to invalid IL or missing references)
						//IL_016b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0171: Expected O, but got Unknown
						if ((Object)(object)player == (Object)null || ((Character)player).IsDead())
						{
							staminaExhaustedTime = 0f;
							nextDrowningDamageTime = 0f;
							return;
						}
						bool flag = false;
						foreach (GeyserGasCloudEffect activeCloud in ActiveClouds)
						{
							if (!((Object)(object)activeCloud == (Object)null))
							{
								Vector3 val = ((Component)player).transform.position - activeCloud.cloudPosition;
								if (((Vector3)(ref val)).sqrMagnitude <= activeCloud.radius * activeCloud.radius)
								{
									flag = true;
									break;
								}
							}
						}
						if (!flag)
						{
							staminaExhaustedTime = 0f;
							nextDrowningDamageTime = 0f;
							return;
						}
						((Character)player).UseStamina(GeyserGasStaminaDrainPerSecond.Value * Time.deltaTime);
						if (((Character)player).HaveStamina(0f))
						{
							staminaExhaustedTime = 0f;
							nextDrowningDamageTime = 0f;
							return;
						}
						staminaExhaustedTime += Time.deltaTime;
						if (!(staminaExhaustedTime < 1f) && !(staminaExhaustedTime < nextDrowningDamageTime))
						{
							nextDrowningDamageTime = staminaExhaustedTime + 1f;
							HitData val2 = new HitData
							{
								m_damage = new DamageTypes
								{
									m_damage = Mathf.Ceil(((Character)player).GetMaxHealth() / 20f)
								},
								m_point = ((Character)player).GetCenterPoint(),
								m_dir = Vector3.down,
								m_pushForce = 10f,
								m_hitType = (HitType)4
							};
							((Character)player).Damage(val2);
						}
					}
				}

				private const string GasCloudRpcName = "Hardship_GeyserGasCloud";

				private static readonly Dictionary<long, Dictionary<Vector3, double>> NextCloudTimesByWorld = new Dictionary<long, Dictionary<Vector3, double>>();

				private static bool rpcRegistered;

				private float groundHeight;

				private bool configured;

				public void Configure(float terrainHeight)
				{
					groundHeight = terrainHeight;
					configured = true;
				}

				private void Update()
				{
					//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_007f: 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_00ae: 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_0108: Unknown result type (might be due to invalid IL or missing references)
					//IL_0115: Unknown result type (might be due to invalid IL or missing references)
					EnsureRpcRegistered();
					if (configured && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
					{
						long worldUID = ZNet.instance.GetWorldUID();
						double timeSeconds = ZNet.instance.GetTimeSeconds();
						if (!NextCloudTimesByWorld.TryGetValue(worldUID, out var value))
						{
							value = new Dictionary<Vector3, double>();
							NextCloudTimesByWorld.Add(worldUID, value);
						}
						Vector3 position = ((Component)this).transform.position;
						if (!value.TryGetValue(position, out var value2))
						{
							value2 = timeSeconds + GetRandomInterval();
							value.Add(position, value2);
						}
						if (!(timeSeconds < value2) && rpcRegistered)
						{
							Vector3 val = default(Vector3);
							((Vector3)(ref val))..ctor(position.x, groundHeight - 0.65f + 0.5f, position.z);
							ZRoutedRpc.instance.InvokeRoutedRPC(0L, "Hardship_GeyserGasCloud", new object[3] { val, GeyserGasCloudRadius.Value, GeyserGasCloudDuration.Value });
							Logger.LogDebug((object)string.Concat(str1: $"next eruption in {(value[position] = timeSeconds + GetRandomInterval()) - timeSeconds:F1} seconds.", str0: $"Hardship: geyser at {position} released a suffocating gas cloud; "));
						}
					}
				}

				private static double GetRandomInterval()
				{
					float num = Mathf.Min(GeyserGasMinimumIntervalSeconds.Value, GeyserGasMaximumIntervalSeconds.Value);
					float num2 = Mathf.Max(GeyserGasMinimumIntervalSeconds.Value, GeyserGasMaximumIntervalSeconds.Value);
					return Random.Range(num, num2);
				}

				private static void EnsureRpcRegistered()
				{
					if (!rpcRegistered && ZRoutedRpc.instance != null)
					{
						ZRoutedRpc.instance.Register<Vector3, float, float>("Hardship_GeyserGasCloud", (Action<long, Vector3, float, float>)OnGasCloudRpc);
						rpcRegistered = true;
						Logger.LogDebug((object)"Hardship: geyser gas RPC registered.");
					}
				}

				private static void OnGasCloudRpc(long sender, Vector3 position, float radius, float duration)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					GeyserGasCloudEffect.Spawn(position, radius, duration);
				}
			}

			private sealed class GeyserCoreSpawner : MonoBehaviour
			{
				private const double MinimumSpawnIntervalSeconds = 7200.0;

				private const double MaximumSpawnIntervalSeconds = 43200.0;

				private const double ExistingCoreCheckIntervalSeconds = 30.0;

				private const double SpawnRetryIntervalSeconds = 60.0;

				private const float CoreSearchRadius = 14.190001f;

				private static readonly Dictionary<long, Dictionary<Vector3, double>> NextSpawnTimesByWorld = new Dictionary<long, Dictionary<Vector3, double>>();

				private float groundHeight;

				private double nextCheckTime;

				private bool configured;

				private bool waitingForExistingCore;

				public void Configure(float terrainHeight)
				{
					groundHeight = terrainHeight;
					configured = true;
				}

				private void Update()
				{
					//IL_005f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
					//IL_007a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0087: Unknown result type (might be due to invalid IL or missing references)
					//IL_00da: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
					//IL_015c: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
					//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
					//IL_01fa: 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_021c: 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)
					if (!configured || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
					{
						return;
					}
					long worldUID = ZNet.instance.GetWorldUID();
					double timeSeconds = ZNet.instance.GetTimeSeconds();
					if (!NextSpawnTimesByWorld.TryGetValue(worldUID, out var value))
					{
						value = new Dictionary<Vector3, double>();
						NextSpawnTimesByWorld.Add(worldUID, value);
					}
					Vector3 position = ((Component)this).transform.position;
					if (!value.TryGetValue(position, out var value2))
					{
						value2 = timeSeconds + GetRandomSpawnInterval();
						value.Add(position, value2);
						Logger.LogDebug((object)($"Hardship: geyser at {position} will first spawn a Surtling Core " + $"in {(value2 - timeSeconds) / 60.0:F1} minutes."));
					}
					else
					{
						if (timeSeconds < value2 || timeSeconds < nextCheckTime)
						{
							return;
						}
						nextCheckTime = timeSeconds + 30.0;
						if (HasNearbySurtlingCore(position))
						{
							if (!waitingForExistingCore)
							{
								Logger.LogDebug((object)($"Hardship: geyser at {position} already has a Surtling Core; " + "waiting for it to be collected before spawning another."));
								waitingForExistingCore = true;
							}
							return;
						}
						waitingForExistingCore = false;
						GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("SurtlingCore") : null);
						if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ItemDrop>() == (Object)null)
						{
							Logger.LogError((object)("Hardship: could not find the 'SurtlingCore' item prefab " + $"for geyser at {position}; will retry in {60.0:F0} seconds."));
							nextCheckTime = timeSeconds + 60.0;
						}
						else if ((Object)(object)val.GetComponent<ZNetView>() == (Object)null)
						{
							Logger.LogError((object)("Hardship: prefab 'SurtlingCore' has no ZNetView; " + $"cannot network-spawn a geyser core at {position}."));
							nextCheckTime = timeSeconds + 60.0;
						}
						else
						{
							Vector3 val2 = default(Vector3);
							((Vector3)(ref val2))..ctor(position.x, groundHeight - 0.65f + 0.2f, position.z);
							Object.Instantiate<GameObject>(val, val2, Quaternion.identity);
							Logger.LogDebug((object)string.Concat(str1: $"next spawn attempt in {((value[position] = timeSeconds + GetRandomSpawnInterval()) - timeSeconds) / 60.0:F1} minutes.", str0: $"Hardship: spawned a Surtling Core at geyser {position}; "));
						}
					}
				}

				private static double GetRandomSpawnInterval()
				{
					return Random.Range(7200f, 43200f);
				}

				private static bool HasNearbySurtlingCore(Vector3 geyserPosition)
				{
					//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_0055: Unknown result type (might be due to invalid IL or missing references)
					//IL_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_0062: 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_0071: Unknown result type (might be due to invalid IL or missing references)
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_0084: Unknown result type (might be due to invalid IL or missing references)
					float num = 201.35611f;
					ItemDrop[] array = Object.FindObjectsByType<ItemDrop>((FindObjectsSortMode)0);
					foreach (ItemDrop val in array)
					{
						if ((Object)(object)val == (Object)null)
						{
							continue;
						}
						Scene scene = ((Component)val).gameObject.scene;
						if (((Scene)(ref scene)).IsValid() && ((Object)((Component)val).gameObject).name.StartsWith("SurtlingCore", StringComparison.Ordinal))
						{
							Vector3 val2 = ((Component)val).transform.position - geyserPosition;
							if (val2.x * val2.x + val2.z * val2.z <= num && Mathf.Abs(val2.y) <= 14.190001f)
							{
								return true;
							}
						}
					}
					return false;
				}
			}

			private const string ModifierObjectName = "Hardship_GeyserTerrainModifier";

			private const string PlateObjectName = "Hardship_GeyserBasePlate";

			private const string TarRingObjectName = "Hardship_GeyserTarRing";

			private const string SurtlingCorePrefabName = "SurtlingCore";

			private const float PlateOuterRadius = 12.5f;

			private const float PlateScaleFactor = 21.5f;

			private const float PlateInnerRimRadius = 0.49f;

			private const float PlateMeshOuterRadius = 14.190001f;

			private const float TarPoolRadius = 7.6f;

			private const float TarFlowRadius = 10.535f;

			private const float TerrainLoweringOffset = -0.5f;

			private const float TarPoolDepth = 0.35f;

			private const int TarSegments = 96;

			private const float LevelRadius = 12.5f;

			private const float SmoothRadius = 16f;

			private const float WaterClearance = 0.4f;

			private const float TerrainLowering = 0.2f;

			private const float WaterSampleStep = 2.5f;

			private const float RaycastHeight = 500f;

			private const float RaycastDistance = 1000f;

			private const float PlateEmbedDepth = 3f;

			private const float PlateTopHeight = 0.04f;

			private const float PlateBowlDepth = 0.65f;

			private const float PlateTopRimHeight = 0.03f;

			private const int PlateSegments = 48;

			private static readonly int WaterLayerMask = LayerMask.GetMask(new string[1] { "Water" });

			private static readonly Vector3 PlateScale = new Vector3(21.5f, 1f, 21.5f);

			private static GameObject platePrefab;

			private static bool platePrefabInitialized;

			private static GameObject tarRingPrefab;

			private static bool tarRingPrefabInitialized;

			private static Texture2D mudBubbleTexture;

			[HarmonyPostfix]
			private static void OnLocationAwake(Location __instance)
			{
				//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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: 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_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_016c: 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_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0340: Unknown result type (might be due to invalid IL or missing references)
				//IL_036b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0385: Unknown result type (might be due to invalid IL or missing references)
				//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_05de: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_049e: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance == (Object)null || !((Object)((Component)__instance).gameObject).name.StartsWith("FireHole", StringComparison.Ordinal))
				{
					return;
				}
				Vector3 position = ((Component)__instance).transform.position;
				Transform val = ((Component)__instance).transform.Find("Hardship_GeyserTerrainModifier");
				bool flag = (Object)(object)val != (Object)null;
				Logger.LogDebug((object)($"Hardship: found geyser '{((Object)((Component)__instance).gameObject).name}' at {position}; " + $"terrain modifier exists={(Object)(object)val != (Object)null}, water layer mask={WaterLayerMask}."));
				float groundHeight;
				bool flag2 = TryGetGroundHeight(position, out groundHeight);
				float num = (flag2 ? groundHeight : position.y);
				if ((Object)(object)val != (Object)null)
				{
					num = val.position.y;
					TerrainModifier component = ((Component)val).GetComponent<TerrainModifier>();
					if ((Object)(object)component != (Object)null)
					{
						ConfigureTerrainModifier(component);
						PokeTerrainHeightmaps(component);
						flag = true;
						Logger.LogDebug((object)("Hardship: updated existing geyser terrain modifier; " + $"level radius={12.5f:F2}m, target offset={-0.5f:F2}m."));
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					float highestWaterSurface;
					bool flag3 = TryGetHighestWaterSurface(position, out highestWaterSurface);
					if (flag3 && highestWaterSurface > position.y)
					{
						float highestTerrainHeight = GetHighestTerrainHeight(position, 16f);
						float num2 = Mathf.Max(highestWaterSurface + 0.4f, highestTerrainHeight);
						float num3 = num2 - 0.2f;
						GameObject val2 = new GameObject("Hardship_GeyserTerrainModifier");
						val2.SetActive(false);
						val2.transform.SetParent(((Component)__instance).transform, true);
						val2.transform.position = new Vector3(position.x, num3, position.z);
						ConfigureTerrainModifier(val2.AddComponent<TerrainModifier>());
						val2.SetActive(true);
						num = num3;
						flag = true;
						Logger.LogDebug((object)("Hardship: raised terrain at " + ((Object)((Component)__instance).gameObject).name + "; " + $"radius={12.5f}m, target y={num3:F2}, " + $"lowered from y={num2:F2} by {0.2f:F2}m, " + $"additional level offset={-0.5f:F2}m, " + $"water y={highestWaterSurface:F2}, highest ground={highestTerrainHeight:F2}."));
					}
					else
					{
						Logger.LogDebug((object)("Hardship: did not raise terrain at '" + ((Object)((Component)__instance).gameObject).name + "'; " + string.Format("water found={0}, water y={1}, ", flag3, flag3 ? highestWaterSurface.ToString("F2") : "<none>") + $"geyser y={position.y:F2}."));
					}
				}
				PlaceGeyserEffectsAtBowlFloor(__instance, num);
				GeyserGasSpawner geyserGasSpawner = ((Component)__instance).GetComponent<GeyserGasSpawner>();
				if ((Object)(object)geyserGasSpawner == (Object)null)
				{
					geyserGasSpawner = ((Component)__instance).gameObject.AddComponent<GeyserGasSpawner>();
				}
				geyserGasSpawner.Configure(num);
				GeyserCoreSpawner geyserCoreSpawner = ((Component)__instance).GetComponent<GeyserCoreSpawner>();
				if ((Object)(object)geyserCoreSpawner == (Object)null)
				{
					geyserCoreSpawner = ((Component)__instance).gameObject.AddComponent<GeyserCoreSpawner>();
				}
				geyserCoreSpawner.Configure(num);
				if (flag)
				{
					PlaceTarRing(__instance, num);
				}
				Transform val3 = ((Component)__instance).transform.Find("Hardship_GeyserBasePlate");
				if (val3 != null)
				{
					val3.localScale = PlateScale;
					MeshRenderer component2 = ((Component)val3).GetComponent<MeshRenderer>();
					MeshCollider component3 = ((Component)val3).GetComponent<MeshCollider>();
					Logger.LogDebug((object)($"Hardship: geyser plate already exists at {val3.position}; " + "sampled ground y=" + (TryGetGroundHeight(position, out var groundHeight2) ? groundHeight2.ToString("F2") : "<no heightmap>") + ", renderer bounds=" + FormatBounds((Renderer)(object)component2) + ", " + $"collider enabled={(Object)(object)component3 != (Object)null && ((Collider)component3).enabled}."));
					return;
				}
				GameObject val4 = GetPlatePrefab(__instance);
				if (val4 == null)
				{
					Logger.LogError((object)("Hardship: could not create a base plate for geyser '" + ((Object)((Component)__instance).gameObject).name + "'."));
					return;
				}
				if (flag2 && groundHeight + 0.01f < num)
				{
					Logger.LogWarning((object)($"Hardship: using terrain target y={num:F2} instead of sampled ground " + $"y={groundHeight:F2} " + "for geyser '" + ((Object)((Component)__instance).gameObject).name + "'."));
				}
				else if (!flag2)
				{
					Logger.LogWarning((object)("Hardship: no heightmap found below geyser '" + ((Object)((Component)__instance).gameObject).name + "' " + $"at {position}; placing plate using terrain target y={num:F2}."));
				}
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(position.x, num, position.z);
				GameObject val6 = Object.Instantiate<GameObject>(val4, val5, Quaternion.identity, ((Component)__instance).transform);
				((Object)val6).name = "Hardship_GeyserBasePlate";
				val6.transform.localScale = PlateScale;
				val6.SetActive(true);
				MeshRenderer component4 = val6.GetComponent<MeshRenderer>();
				MeshCollider component5 = val6.GetComponent<MeshCollider>();
				Logger.LogDebug((object)("Hardship: spawned geyser plate '" + ((Object)((Component)__instance).gameObject).name + "'; " + $"plate ground y={num:F2}, sampled ground y={groundHeight:F2}, " + $"outer radius={14.190001f:F2}m, " + $"rim height={0.04f:F2}m above ground, " + $"bowl depth={0.65f:F2}m, " + $"tar pool diameter={15.2f:F2}m, " + $"embed depth={3f:F2}m, " + $"plate center={val6.transform.position}, " + $"world scale={val6.transform.lossyScale}, " + "renderer bounds=" + FormatBounds((Renderer)(object)component4) + ", " + $"collider enabled={(Object)(object)component5 != (Object)null && ((Collider)component5).enabled}, " + "collider bounds=" + FormatBounds((Collider)(object)component5) + "."));
			}

			private static void ConfigureTerrainModifier(TerrainModifier modifier)
			{
				modifier.m_level = true;
				modifier.m_levelRadius = 12.5f;
				modifier.m_square = false;
				modifier.m_levelOffset = -0.5f;
				modifier.m_smooth = true;
				modifier.m_smoothRadius = 16f;
				modifier.m_smoothPower = 3f;
				modifier.m_playerModifiction = false;
				modifier.m_paintCleared = false;
			}

			private static void PokeTerrainHeightmaps(TerrainModifier modifier)
			{
				foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps())
				{
					if ((Object)(object)allHeightmap != (Object)null && allHeightmap.TerrainVSModifier(modifier))
					{
						allHeightmap.Poke(2, false);
					}
				}
			}

			private static bool TryGetGroundHeight(Vector3 position, out float groundHeight)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps())
				{
					if ((Object)(object)allHeightmap != (Object)null && allHeightmap.GetWorldHeight(position, ref groundHeight))
					{
						return true;
					}
				}
				groundHeight = 0f;
				return false;
			}

			private static string FormatBounds(Renderer renderer)
			{
				//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)
				if (!((Object)(object)renderer != (Object)null))
				{
					return "<missing>";
				}
				return ((object)renderer.bounds/*cast due to .constrained prefix*/).ToString();
			}

			private static string FormatBounds(Collider collider)
			{
				//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)
				if (!((Object)(object)collider != (Object)null))
				{
					return "<missing>";
				}
				return ((object)collider.bounds/*cast due to .constrained prefix*/).ToString();
			}

			private static void PlaceTarRing(Location geyser, float groundHeight)
			{
				//IL_005a: 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_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				Transform val = ((Component)geyser).transform.Find("Hardship_GeyserTarRing");
				GameObject val2;
				if ((Object)(object)val != (Object)null)
				{
					val2 = ((Component)val).gameObject;
				}
				else
				{
					GameObject val3 = GetTarRingPrefab(geyser);
					if (val3 == null)
					{
						Logger.LogError((object)("Hardship: could not create a tar ring for geyser '" + ((Object)((Component)geyser).gameObject).name + "'."));
						return;
					}
					val2 = Object.Instantiate<GameObject>(val3, new Vector3(((Component)geyser).transform.position.x, groundHeight, ((Component)geyser).transform.position.z), Quaternion.identity, ((Component)geyser).transform);
					((Object)val2).name = "Hardship_GeyserTarRing";
					val2.transform.localScale = Vector3.one;
					val2.SetActive(true);
				}
				val2.transform.position = new Vector3(((Component)geyser).transform.position.x, groundHeight, ((Component)geyser).transform.position.z);
				GeyserTarRingEffect geyserTarRingEffect = val2.GetComponent<GeyserTarRingEffect>();
				if ((Object)(object)geyserTarRingEffect == (Object)null)
				{
					geyserTarRingEffect = val2.AddComponent<GeyserTarRingEffect>();
				}
				EnsureMudBubbles(val2);
				Mesh mesh = BuildTarPoolMesh();
				float liquidSurfaceHeight = groundHeight + 0.04f;
				geyserTarRingEffect.Configure(groundHeight, liquidSurfaceHeight, mesh);
				Logger.LogDebug((object)("Hardship: placed tar pool in geyser plate '" + ((Object)((Component)geyser).gameObject).name + "'; " + $"pool diameter={15.2f:F2}m, flow reaches radius={10.535f:F2}m, " + $"bowl diameter={PlateScale.x * 0.8f:F2}m, bowl depth={0.65f:F2}m, " + $"tar bottom offset={-0.29999998f:F2}m, " + $"surface offset={0.04f:F2}m, no collider."));
			}

			private static Texture2D GetMudBubbleTexture()
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Expected O, but got Unknown
				//IL_005b: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)mudBubbleTexture != (Object)null)
				{
					return mudBubbleTexture;
				}
				mudBubbleTexture = new Texture2D(32, 32, (TextureFormat)4, false)
				{
					name = "Hardship_MudBubble",
					hideFlags = (HideFlags)61,
					wrapMode = (TextureWrapMode)1
				};
				for (int i = 0; i < 32; i++)
				{
					for (int j = 0; j < 32; j++)
					{
						float num = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(16f, 16f)) / 16f;
						float num2 = Mathf.Clamp01(1f - Mathf.Abs(num - 0.8f) / 0.2f);
						float num3 = ((num < 0.8f) ? 0.25f : 0f);
						float num4 = Mathf.Max(num2, num3);
						mudBubbleTexture.SetPixel(j, i, new Color(1f, 1f, 1f, num4));
					}
				}
				mudBubbleTexture.Apply();
				return mudBubbleTexture;
			}

			private static void EnsureMudBubbles(GameObject tarRing)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_003c: 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_0065: 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_0084: 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_00b2: 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_00e8: 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_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				//IL_0147: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_01a9: 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_01bf: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01da: Unknown result type (might be due to invalid IL or missing references)
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Expected O, but got Unknown
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f4: 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_0205: Expected O, but got Unknown
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0219: Unknown result type (might be due to invalid IL or missing references)
				//IL_021e: 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_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0234: Unknown result type (might be due to invalid IL or missing references)
				//IL_024b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0261: Unknown result type (might be due to invalid IL or missing references)
				//IL_0266: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_027c: Unknown result type (might be due to invalid IL or missing references)
				//IL_028d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0292: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: 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_0303: Expected O, but got Unknown
				if ((Object)(object)tarRing.transform.Find("Hardship_MudBubbles") != (Object)null)
				{
					return;
				}
				GameObject val = new GameObject("Hardship_MudBubbles");
				val.transform.SetParent(tarRing.transform, false);
				val.transform.localPosition = Vector3.up * 0.07f;
				val.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
				ParticleSystem val2 = val.AddComponent<ParticleSystem>();
				val2.Stop(true, (ParticleSystemStopBehavior)0);
				MainModule main = val2.main;
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).playOnAwake = true;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.8f, 1.8f);
				((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.35f, 1.1f);
				((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.55f, 0.43f, 0.28f, 0.9f), new Color(0.42f, 0.32f, 0.2f, 0.9f));
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
				((MainModule)(ref main)).maxParticles = 150;
				EmissionModule emission = val2.emission;
				((EmissionModule)(ref emission)).rateOverTime = new MinMaxCurve(2f, 6f);
				ShapeModule shape = val2.shape;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10;
				((ShapeModule)(ref shape)).radius = 7.22f;
				((ShapeModule)(ref shape)).radiusThickness = 1f;
				SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[4]
				{
					new Keyframe(0f, 0.2f),
					new Keyframe(0.7f, 1f),
					new Keyframe(0.85f, 1.15f),
					new Keyframe(1f, 0.3f)
				}));
				ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
				Gradient val3 = new Gradient();
				val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(Color.white, 0f),
					new GradientColorKey(Color.white, 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
				{
					new GradientAlphaKey(0f, 0f),
					new GradientAlphaKey(1f, 0.15f),
					new GradientAlphaKey(1f, 0.85f),
					new GradientAlphaKey(0f, 1f)
				});
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
				ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
				component.renderMode = (ParticleSystemRenderMode)2;
				Shader val4 = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("Sprites/Default");
				if ((Object)(object)val4 != (Object)null)
				{
					Material val5 = new Material(val4)
					{
						name = "Hardship_MudBubbleMaterial"
					};
					val5.mainTexture = (Texture)(object)GetMudBubbleTexture();
					if (val5.HasProperty("_Mode"))
					{
						val5.SetFloat("_Mode", 2f);
						val5.EnableKeyword("_ALPHABLEND_ON");
						val5.SetInt("_SrcBlend", 5);
						val5.SetInt("_DstBlend", 10);
						val5.SetInt("_ZWrite", 0);
						val5.renderQueue = 3000;
					}
					((Renderer)component).sharedMaterial = val5;
				}
				val2.Play();
			}

			private static GameObject GetTarRingPrefab(Location geyser)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Expected O, but got Unknown
				//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_007b: Expected O, but got Unknown
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				if (tarRingPrefabInitialized)
				{
					return tarRingPrefab;
				}
				if (!TryGetPlateMaterial(geyser, out var material))
				{
					Logger.LogError((object)("Hardship: could not find a reusable material for tar around geyser '" + ((Object)((Component)geyser).gameObject).name + "'."));
					return null;
				}
				tarRingPrefab = new GameObject("Hardship_GeyserTarRing");
				tarRingPrefab.SetActive(false);
				((Object)tarRingPrefab).hideFlags = (HideFlags)61;
				tarRingPrefab.AddComponent<MeshFilter>();
				Material val = new Material(material)
				{
					name = "Hardship_GeyserTarMaterial"
				};
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.286f, 0.267f, 0.231f);
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", val2);
				}
				if (val.HasProperty("_BaseColor"))
				{
					val.SetColor("_BaseColor", val2);
				}
				if (val.HasProperty("_Glossiness"))
				{
					val.SetFloat("_Glossiness", 0.25f);
				}
				if (val.HasProperty("_Metallic"))
				{
					val.SetFloat("_Metallic", 0f);
				}
				((Renderer)tarRingPrefab.AddComponent<MeshRenderer>()).sharedMaterial = val;
				tarRingPrefabInitialized = true;
				Logger.LogDebug((object)("Hardship: created geyser tar ring material from '" + ((Object)material).name + "'."));
				return tarRingPrefab;
			}

			private static Mesh BuildTarPoolMesh()
			{
				//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_0011: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: 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_023c: Unknown result type (might be due to invalid IL or missing references)
				Mesh val = new Mesh
				{
					name = "Hardship_GeyserTarPoolMesh"
				};
				float[] array = new float[11]
				{
					0.5f, 2f, 4.5f, 6.3f, 7f, 7.2999997f, 7.6f, 8.2f, 8.8f, 9.4f,
					10.535f
				};
				int num = 96;
				List<Vector3> list = new List<Vector3>(1 + array.Length * num)
				{
					new Vector3(0f, 0.04f, 0f)
				};
				List<int> list2 = new List<int>(96 * (array.Length + 2) * 6);
				for (int i = 0; i < array.Length; i++)
				{
					for (int j = 0; j < 96; j++)
					{
						float num2 = (float)j / 96f * (float)Math.PI * 2f;
						float num3 = Mathf.Sin(num2 * 3f + (float)i * 0.7f) * 0.015f + Mathf.Sin(num2 * 7f - (float)i) * 0.008f;
						float num4 = array[i];
						float num5 = Mathf.SmoothStep(7.2f, 10.535f, num4);
						float num6 = 1f - num5;
						list.Add(new Vector3(Mathf.Cos(num2) * num4, 0.04f + num3 * num6, Mathf.Sin(num2) * num4));
					}
				}
				for (int k = 0; k < 96; k++)
				{
					int num7 = (k + 1) % 96;
					list2.Add(0);
					list2.Add(1 + num7);
					list2.Add(1 + k);
					for (int l = 0; l < array.Length - 1; l++)
					{
						int num8 = 1 + l * num;
						int num9 = num8 + num;
						int item = num8 + k;
						int item2 = num8 + num7;
						int item3 = num9 + k;
						int item4 = num9 + num7;
						list2.Add(item);
						list2.Add(item2);
						list2.Add(item4);
						list2.Add(item);
						list2.Add(item4);
						list2.Add(item3);
					}
				}
				float num10 = -0.29999998f;
				int count = list.Count;
				list.Add(new Vector3(0f, num10, 0f));
				int count2 = list.Count;
				for (int m = 0; m < 96; m++)
				{
					float num11 = (float)m / 96f * (float)Math.PI * 2f;
					list.Add(new Vector3(Mathf.Cos(num11) * 10.535f, num10, Mathf.Sin(num11) * 10.535f));
				}
				int num12 = 1 + (array.Length - 1) * num;
				for (int n = 0; n < 96; n++)
				{
					int num13 = (n + 1) % 96;
					int item5 = num12 + n;
					int item6 = num12 + num13;
					int item7 = count2 + n;
					int item8 = count2 + num13;
					list2.Add(item5);
					list2.Add(item6);
					list2.Add(item8);
					list2.Add(item5);
					list2.Add(item8);
					list2.Add(item7);
					list2.Add(count);
					list2.Add(item7);
					list2.Add(item8);
				}
				val.SetVertices(list);
				val.SetTriangles(list2, 0);
				val.RecalculateNormals();
				val.RecalculateBounds();
				return val;
			}

			private static void PlaceGeyserEffectsAtBowlFloor(Location geyser, float plateGroundHeight)
			{
				//IL_0091: 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_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				HashSet<Transform> hashSet = new HashSet<Transform>();
				int num = 0;
				ParticleSystem[] componentsInChildren = ((Component)geyser).GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem obj in componentsInChildren)
				{
					num++;
					Transform transform = ((Component)obj).transform;
					if ((Object)(object)transform == (Object)(object)((Component)geyser).transform)
					{
						continue;
					}
					bool flag = false;
					Transform parent = transform.parent;
					while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)((Component)geyser).transform)
					{
						if ((Object)(object)((Component)parent).GetComponent<ParticleSystem>() != (Object)null)
						{
							flag = true;
							break;
						}
						parent = parent.parent;
					}
					if (!flag && hashSet.Add(transform))
					{
						Vector3 position = transform.position;
						transform.position = new Vector3(position.x, plateGroundHeight - 0.65f, position.z);
						Logger.LogDebug((object)("Hardship: positioned geyser particle effect '" + ((Object)transform).name + "' " + $"at bowl floor y={transform.position.y:F2} " + $"(plate ground y={plateGroundHeight:F2}, depth={0.65f:F2}m)."));
					}
				}
				if (hashSet.Count == 0)
				{
					Logger.LogWarning((object)($"Hardship: found {num} particle system(s) on geyser " + "'" + ((Object)((Component)geyser).gameObject).name + "' but no child effect transform to place at the bowl floor."));
				}
			}

			private static GameObject GetPlatePrefab(Location geyser)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Expected O, but got Unknown
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//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_009a: Expected O, but got Unknown
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: 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)
				if (platePrefabInitialized)
				{
					return platePrefab;
				}
				if (!TryGetPlateMaterial(geyser, out var material))
				{
					Logger.LogError((object)("Hardship: could not find a reusable material for geyser '" + ((Object)((Component)geyser).gameObject).name + "'. Checked geyser renderers, terrain renderers, and loaded mesh renderers."));
					return null;
				}
				Mesh val = BuildStonePlateMesh();
				platePrefab = new GameObject("Hardship_GeyserBasePlate");
				platePrefab.SetActive(false);
				((Object)platePrefab).hideFlags = (HideFlags)61;
				platePrefab.transform.localScale = PlateScale;
				platePrefab.AddComponent<MeshFilter>().sharedMesh = val;
				Material val2 = new Material(material)
				{
					name = "Hardship_GeyserBasePlateMaterial"
				};
				Color val3 = default(Color);
				((Color)(ref val3))..ctor(0.34f, 0.31f, 0.27f);
				if (val2.HasProperty("_Color"))
				{
					val2.SetColor("_Color", val3);
				}
				if (val2.HasProperty("_BaseColor"))
				{
					val2.SetColor("_BaseColor", val3);
				}
				((Renderer)platePrefab.AddComponent<MeshRenderer>()).sharedMaterial = val2;
				platePrefab.AddComponent<MeshCollider>().sharedMesh = val;
				platePrefabInitialized = true;
				Logger.LogDebug((object)($"Hardship: created geyser plate mesh; vertices={val.vertexCount}, " + $"mesh bounds={val.bounds}, material='{((Object)material).name}', " + $"shader='{((Object)material.shader).name}', scale={PlateScale}, " + $"rim height={0.04f:F2}m, bowl depth={0.65f:F2}m, " + $"tar pool diameter={15.2f:F2}m, " + $"embed depth={3f:F2}m."));
				return platePrefab;
			}

			private static bool TryGetPlateMaterial(Location geyser, out Material material)
			{
				MeshRenderer[] componentsInChildren = ((Component)geyser).GetComponentsInChildren<MeshRenderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (TryGetFirstMaterial((Renderer)(object)componentsInChildren[i], out material))
					{
						Logger.LogDebug((object)("Hardship: using geyser material '" + ((Object)material).name + "' (shader '" + ((Object)material.shader).name + "') for its base plate."));
						return true;
					}
				}
				componentsInChildren = Object.FindObjectsByType<MeshRenderer>((FindObjectsSortMode)0);
				foreach (MeshRenderer val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<Heightmap>() != (Object)null) && TryGetFirstMaterial((Renderer)(object)val, out material))
					{
						Logger.LogDebug((object)("Hardship: using scene material '" + ((Object)material).name + "' (shader '" + ((Object)material.shader).name + "') for geyser plate."));
						return true;
					}
				}
				material = null;
				return false;
			}

			private static bool TryGetFirstMaterial(Renderer renderer, out Material material)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					Material[] sharedMaterials = renderer.sharedMaterials;
					foreach (Material val in sharedMaterials)
					{
						if ((Object)(object)val != (Object)null && (Object)(object)val.shader != (Object)null)
						{
							material = val;
							return true;
						}
					}
				}
				material = null;
				return false;
			}

			private static Mesh BuildStonePlateMesh()
			{
				//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_0011: Expected O, but got Unknown
				//IL_0076: 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)
				Mesh val = new Mesh
				{
					name = "Hardship_GeyserBasePlateMesh"
				};
				float[] array = new float[22]
				{
					0.02f, 0.08f, 0.16f, 0.24f, 0.32f, 0.4f, 0.43f, 0.46f, 0.49f, 0.515f,
					0.54f, 0.56f, 0.58f, 0.6f, 0.62f, 0.64f, 0.66f, 0.62f, 0.55f, 0.5f,
					0.47f, 0.02f
				};
				float[] array2 = new float[22]
				{
					-0.65f, -0.65f, -0.65f, -0.65f, -0.65f, -0.65f, -0.43875f, -0.21124998f, 0.04f, -0.08f,
					-0.22f, -0.36f, -0.5f, -0.7f, -1.2f, -2f, -3f, -3f, -3f, -3f,
					-3f, -3f
				};
				List<int> list = new List<int>(288 * array.Length + 144);
				int[] array3 = new int[array.Length];
				int item = 0;
				List<Vector3> list2 = new List<Vector3>(48 * array.Length + 1)
				{
					new Vector3(0f, -0.65f, 0f)
				};
				for (int i = 0; i < array.Length; i++)
				{
					array3[i] = list2.Count;
					for (int j = 0; j < 48; j++)
					{
						float num = (float)j / 48f * (float)Math.PI * 2f;
						float num2 = Mathf.PerlinNoise(Mathf.Cos(num) * 4f + (float)i * 19f + 13f, Mathf.Sin(num) * 4f + (float)i * 23f + 29f) - 0.5f;
						float num3 = ((i < 2 || i >= array.Length - 4 || array[i] == 0.49f) ? 0f : 0.012f);
						float num4 = array[i] + num2 * num3;
						list2.Add(new Vector3(Mathf.Cos(num) * num4, array2[i], Mathf.Sin(num) * num4));
					}
				}
				for (int k = 0; k < 48; k++)
				{
					int num5 = k;
					int num6 = (k + 1) % 48;
					list.Add(item);
					list.Add(array3[0] + num6);
					list.Add(array3[0] + num5);
					for (int l = 0; l < array3.Length; l++)
					{
						int num7 = (l + 1) % array3.Length;
						int item2 = array3[l] + num5;
						int item3 = array3[l] + num6;
						int item4 = array3[num7] + num5;
						int item5 = array3[num7] + num6;
						list.Add(item4);
						list.Add(item2);
						list.Add(item3);
						list.Add(item4);
						list.Add(item3);
						list.Add(item5);
					}
				}
				val.SetVertices(list2);
				val.SetTriangles(list, 0);
				val.RecalculateNormals();
				val.RecalculateBounds();
				return val;
			}

			private static bool TryGetHighestWaterSurface(Vector3 center, out float highestWaterSurface)
			{
				//IL_0031: 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_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0057: 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)
				highestWaterSurface = float.NegativeInfinity;
				if (WaterLayerMask == 0)
				{
					return false;
				}
				RaycastHit val = default(RaycastHit);
				for (float num = -12.5f; num <= 12.5f; num += 2.5f)
				{
					for (float num2 = -12.5f; num2 <= 12.5f; num2 += 2.5f)
					{
						if (!(num2 * num2 + num * num > 156.25f) && Physics.Raycast(center + new Vector3(num2, 0f, num) + Vector3.up * 500f, Vector3.down, ref val, 1000f, WaterLayerMask, (QueryTriggerInteraction)2))
						{
							highestWaterSurface = Mathf.Max(highestWaterSurface, ((RaycastHit)(ref val)).point.y);
						}
					}
				}
				return !float.IsNegativeInfinity(highestWaterSurface);
			}

			private static float GetHighestTerrainHeight(Vector3 center, float radius)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//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)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: 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_009f: 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)
				float num = center.y;
				float num2 = radius * radius;
				float num6 = default(float);
				foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps())
				{
					if ((Object)(object)allHeightmap == (Object)null)
					{
						continue;
					}
					float num3 = (float)allHeightmap.m_width * allHeightmap.m_scale * 0.5f;
					for (int i = 0; i <= allHeightmap.m_width; i++)
					{
						for (int j = 0; j <= allHeightmap.m_width; j++)
						{
							Vector3 val = ((Component)allHeightmap).transform.position + new Vector3(0f - num3 + (float)j * allHeightmap.m_scale, 0f, 0f - num3 + (float)i * allHeightmap.m_scale);
							float num4 = val.x - center.x;
							float num5 = val.z - center.z;
							if (!(num4 * num4 + num5 * num5 > num2) && allHeightmap.GetWorldHeight(val, ref num6))
							{
								num = Mathf.Max(num, num6);
							}
						}
					}
				}
				return num;
			}
		}

		[HarmonyPatch(typeof(MonsterAI), "SetEventCreature")]
		public static class RaidCreaturePatch
		{
			private static void Postfix(MonsterAI __instance, bool despawn)
			{
				if (despawn)
				{
					ZNetView val = ((__instance != null) ? ((Component)__instance).GetComponent<ZNetView>() : null);
					if (!((Object)(object)val == (Object)null) && val.IsValid())
					{
						val.GetZDO().Set("Hardship_RaidSpawn", true);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
		public static class RaidLootPatch
		{
			private static bool Prefix(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result)
			{
				if (BlockRaidDrops == null || !BlockRaidDrops.Value || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				bool num = (Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetBool("Hardship_RaidSpawn", false);
				MonsterAI component2 = ((Component)__instance).GetComponent<MonsterAI>();
				bool flag = (Object)(object)component2 != (Object)null && component2.IsEventCreature();
				if (!num && !flag)
				{
					return true;
				}
				__result = new List<KeyValuePair<GameObject, int>>();
				return false;
			}

			private static void Postfix(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result)
			{
				if ((Object)(object)__instance == (Object)null || __result == null)
				{
					return;
				}
				string name = ((Object)((Component)__instance).gameObject).name;
				if (name.StartsWith("Greydwarf_Elite", StringComparison.Ordinal))
				{
					__result.RemoveAll((KeyValuePair<GameObject, int> drop) => (Object)(object)drop.Key != (Object)null && ((Object)drop.Key).name == "AncientSeed");
				}
				if (name.StartsWith("Surtling", StringComparison.Ordinal))
				{
					__result.RemoveAll((KeyValuePair<GameObject, int> drop) => (Object)(object)drop.Key != (Object)null && ((Object)drop.Key).name == "SurtlingCore");
				}
			}
		}

		[HarmonyPatch(typeof(DropOnDestroyed), "Awake")]
		public static class GreydwarfNestVanillaDropPatch
		{
			private static void Prefix(DropOnDestroyed __instance)
			{
				if ((Object)(object)__instance != (Object)null && GreydwarfNestDropPatch.IsNest(__instance))
				{
					int num = __instance.m_dropWhenDestroyed.m_drops.RemoveAll((DropData drop) => (Object)(object)drop.m_item != (Object)null && ((Object)drop.m_item).name == "AncientSeed");
					Logger.LogDebug((object)$"Greydwarf nest '{((Object)((Component)__instance).gameObject).name}' initialised; removed {num} vanilla AncientSeed drop(s), {__instance.m_dropWhenDestroyed.m_drops.Count} other drop(s) remain.");
				}
			}
		}

		[HarmonyPatch(typeof(DropOnDestroyed), "OnDestroyed")]
		public static class GreydwarfNestDropPatch
		{
			private const float AncientSeedChancePercent = 40f;

			internal static bool IsNest(DropOnDestroyed instance)
			{
				if ((Object)(object)instance != (Object)null)
				{
					return ((Object)((Component)instance).gameObject).name.StartsWith("Spawner_GreydwarfNest", StringComparison.Ordinal);
				}
				return false;
			}

			private static void Postfix(DropOnDestroyed __instance)
			{
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
				if (!IsNest(__instance) || (Object)(object)ZNetScene.instance == (Object)null)
				{
					return;
				}
				float num = Random.Range(0f, 100f);
				bool flag = num < 40f;
				Logger.LogDebug((object)string.Format("Greydwarf nest destroyed: Ancient Seed roll {0:F1} (needs < {1:F0}) -> {2}.", num, 40f, flag ? "drop" : "no drop"));
				if (flag)
				{
					GameObject prefab = ZNetScene.instance.GetPrefab("AncientSeed");
					if ((Object)(object)prefab == (Object)null)
					{
						Logger.LogWarning((object)"AncientSeed prefab not found; nest drop skipped.");
						return;
					}
					Vector3 val = ((Component)__instance).transform.position + Vector3.up * __instance.m_spawnYOffset;
					ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
					bool flag2 = (Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetBool(ZDOVars.s_cheated, false) && !PlayerProfile.s_bypassCheatChecks;
					ItemDrop.OnCreateNew(Object.Instantiate<GameObject>(prefab, val, Quaternion.identity), flag2);
				}
			}
		}

		[HarmonyPatch(typeof(Piece), "DropResources")]
		public static class KilnSurtlingCoreCostPatch
		{
			private static bool Prefix(Piece __instance)
			{
				if (!IsSurtlingCoreConsumingKiln(__instance))
				{
					return true;
				}
				if (__instance.m_resources == null)
				{
					return true;
				}
				Requirement[] resources = __instance.m_resources;
				foreach (Requirement val in resources)
				{
					if ((Object)(object)val?.m_resItem != (Object)null && Utils.GetPrefabName(((Object)val.m_resItem).name) == "SurtlingCore")
					{
						val.m_recover = false;
					}
				}
				return true;
			}

			private static bool IsSurtlingCoreConsumingKiln(Piece piece)
			{
				if ((Object)(object)piece == (Object)null)
				{
					return false;
				}
				switch (Utils.GetPrefabName(((Object)((Component)piece).gameObject).name))
				{
				default:
					if (!(piece.m_name == "$piece_smelter") && !(piece.m_name == "$piece_charcoal_kiln"))
					{
						return piece.m_name == "$piece_blastfurnace";
					}
					break;
				case "smelter":
				case "charcoal_kiln":
				case "blastfurnace":
				case "piece_smelter":
				case "piece_charcoal_kiln":
				case "piece_blastfurnace":
					break;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
		public static class StormShipDamagePatch
		{
			private static readonly Dictionary<int, float> nextDamageTime = new Dictionary<int, float>();

			private static void Postfix(Ship __instance)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//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_0147: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0168: 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_017a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0193: 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_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Expected O, but got Unknown
				//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance == (Object)null || StormShipDamageEnabled == null || !StormShipDamageEnabled.Value || !IsStormWeather() || StormShipDamagePerSecond == null || StormShipDamagePerSecond.Value <= 0f || (Object)(object)EnvMan.instance == (Object)null)
				{
					return;
				}
				Vector3 windForce = EnvMan.instance.GetWindForce();
				float magnitude = ((Vector3)(ref windForce)).magnitude;
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				WearNTear component2 = ((Component)__instance).GetComponent<WearNTear>();
				if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || !component.IsValid() || !component.IsOwner() || magnitude < StormWindThreshold.Value)
				{
					return;
				}
				int instanceID = ((Object)__instance).GetInstanceID();
				if ((!nextDamageTime.TryGetValue(instanceID, out var value) || !(Time.time < value)) && (!(StormShallowWaterDepth.Value > 0f) || !IsInShallowWater(__instance)))
				{
					nextDamageTime[instanceID] = Time.time + 1f;
					float num = ((StormWindThreshold.Value >= 1f) ? 1f : Mathf.Clamp01((magnitude - StormWindThreshold.Value) / (1f - StormWindThreshold.Value)));
					float num2 = Mathf.Lerp(1f, StormMaxDamageMultiplier.Value, num);
					HitData val = new HitData
					{
						m_damage = new DamageTypes
						{
							m_blunt = StormShipDamagePerSecond.Value * num2
						},
						m_point = ((Component)__instance).transform.position + ((Component)__instance).transform.right * 1.5f,
						m_dir = Vector3.up,
						m_dodgeable = false
					};
					component2.Damage(val);
					if ((Object)(object)GameCamera.instance != (Object)null && StormShakeStrength.Value > 0f && StormShakeRange.Value > 0f)
					{
						GameCamera.instance.AddShake(((Component)__instance).transform.position, StormShakeRange.Value, StormShakeStrength.Value, false);
					}
				}
			}

			private static bool IsStormWeather()
			{
				EnvMan instance = EnvMan.instance;
				EnvSetup environment = ((instance != null) ? instance.GetCurrentEnvironment() : null);
				if (environment == null || StormWeatherNames == null || string.IsNullOrWhiteSpace(StormWeatherNames.Value))
				{
					return false;
				}
				return (from name in StormWeatherNames.Value.Split(new char[1] { ',' })
					select name.Trim()).Any((string name) => string.Equals(name, environment.m_name, StringComparison.OrdinalIgnoreCase));
			}

			private static bool IsInShallowWater(Ship ship)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)ship == (Object)null || StormShallowWaterDepth.Value <= 0f)
				{
					return false;
				}
				Heightmap val = Heightmap.FindHeightmap(((Component)ship).transform.position);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				float oceanDepth = val.GetOceanDepth(((Component)ship).transform.position);
				float num = StormShallowWaterDepth.Value + 1.5f;
				if (oceanDepth >= 0f)
				{
					return oceanDepth <= num;
				}
				return false;
			}
		}

		[HarmonyPatch]
		public static class LightningStrikePatch
		{
			private sealed class LightningFlashEffect : MonoBehaviour
			{
				private const float HoldDuration = 2f;

				private const float FadeDuration = 1f;

				private const float StartIntensity = 6f;

				private float elapsed;

				private Light flashLight;

				private void Awake()
				{
					flashLight = ((Component)this).GetComponent<Light>();
				}

				private void Update()
				{
					elapsed += Time.deltaTime;
					if ((Object)(object)flashLight != (Object)null)
					{
						float num = Mathf.Clamp01((elapsed - 2f) / 1f);
						flashLight.intensity = Mathf.Lerp(6f, 0f, num);
					}
					if (elapsed >= 3f)
					{
						Object.Destroy((Object)(object)((Component)this).gameObject);
					}
				}
			}

			private const string RpcName = "Hardship_LightningStrike";

			private static readonly int RoofRaycastMask = ~LayerMask.GetMask(new string[4] { "Character", "character_trigger", "character_noenv", "Default_small" });

			private static float nextCheckTime;

			private static float nextStrikeAllowedTime;

			private static bool rpcRegistered;

			private static readonly string[] BoltShaderNames = new string[3] { "Unlit/Color", "Sprites/Default", "Standard" };

			private static void EnsureRpcRegistered()
			{
				if (!rpcRegistered && ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.Register<Vector3, string>("Hardship_LightningStrike", (Action<long, Vector3, string>)OnLightningStrikeRpc);
					rpcRegistered = true;
					Logger.LogDebug((object)"Hardship: lightning RPC registered.");
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Player), "FixedUpdate")]
			private static void OnPlayerFixedUpdate()
			{
				EnsureRpcRegistered();
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || LightningEnabled == null || !LightningEnabled.Value || Time.time < nextCheckTime)
				{
					return;
				}
				nextCheckTime = Time.time + Mathf.Max(0.1f, LightningCheckInterval.Value);
				if (!(Time.time < nextStrikeAllowedTime) && IsThunderstorm() && !HasRoofOverhead(localPlayer))
				{
					float num = (((Object)(object)((Component)localPlayer).GetComponentInParent<Ship>() != (Object)null) ? LightningShipChance.Value : LightningLandChance.Value);
					if (!(Random.Range(0f, 100f) >= num))
					{
						StrikePlayer(localPlayer);
					}
				}
			}

			private static bool IsThunderstorm()
			{
				EnvMan instance = EnvMan.instance;
				EnvSetup environment = ((instance != null) ? instance.GetCurrentEnvironment() : null);
				if (environment == null || string.IsNullOrEmpty(LightningWeatherNames.Value))
				{
					return false;
				}
				return (from name in LightningWeatherNames.Value.Split(new char[1] { ',' })
					select name.Trim()).Any((string name) => string.Equals(name, environment.m_name, StringComparison.OrdinalIgnoreCase));
			}

			private static bool HasRoofOverhead(Player player)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				return Physics.Raycast(((Component)player).transform.position + Vector3.up * 0.5f, Vector3.up, 300f, RoofRaycastMask);
			}

			private static void StrikePlayer(Player player)
			{
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				nextStrikeAllowedTime = Time.time + Mathf.Max(0f, LightningCooldownSeconds.Value);
				((Character)player).SetHealth(10f);
				((Character)player).Message((MessageType)2, "Thor's wrath has struck you down!", 0, (Sprite)null, false);
				((MonoBehaviour)player).StartCoroutine(ClearCenterMessageAfter(3f));
				Logger.LogDebug((object)$"Hardship: lightning struck {player.GetPlayerName()} at {((Component)player).transform.position}, sending RPC.");
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "Hardship_LightningStrike", new object[2]
				{
					((Component)player).transform.position,
					player.GetPlayerName()
				});
			}

			private static IEnumerator ClearCenterMessageAfter(float delay)
			{
				yield return (object)new WaitForSeconds(delay);
				MessageHud instance = MessageHud.instance;
				if (instance != null)
				{
					instance.ShowMessage((MessageType)2, string.Empty, 0, (Sprite)null, false, true);
				}
			}

			private static void OnLightningStrikeRpc(long sender, Vector3 position, string playerName)
			{
				//IL_0006: 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)
				Logger.LogDebug((object)$"Hardship: lightning RPC received for {playerName} at {position}.");
				SpawnLightningVisual(position);
				if ((Object)(object)Player.m_localPlayer != (Object)null && !string.Equals(Player.m_localPlayer.GetPlayerName(), playerName, StringComparison.Ordinal))
				{
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)1, "Thor struck " + playerName + " down!", 0, (Sprite)null, false, true);
					}
				}
			}

			private static void SpawnLightningVisual(Vector3 position)
			{
				//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_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_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Expected O, but got Unknown
				//IL_00a6: 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_00bd: Expected O, but got Unknown
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("Hardship_LightningBolt");
				val.transform.position = position;
				Light obj = val.AddComponent<Light>();
				obj.type = (LightType)2;
				obj.color = new Color(0.75f, 0.85f, 1f);
				obj.intensity = 6f;
				obj.range = 20f;
				obj.shadows = (LightShadows)0;
				Shader shader = ResolveBoltShader();
				Vector3[] points = GenerateBoltPoints(position + Vector3.up * 40f, position);
				CreateBoltLine(val, "Glow", points, shader, 0.6f, new Color(0.6f, 0.8f, 1f, 0.35f));
				CreateBoltLine(val, "Core", points, shader, 0.12f, Color.white);
				val.AddComponent<LightningFlashEffect>();
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					GameCamera.instance.AddShake(position, 15f, 0.3f, false);
				}
			}

			private static Vector3[] GenerateBoltPoints(Vector3 start, Vector3 end)
			{
				//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_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: 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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: 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_007a: 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_007d: 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)
				Vector3[] array = (Vector3[])(object)new Vector3[11]
				{
					start,
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					default(Vector3),
					end
				};
				for (int i = 1; i < 10; i++)
				{
					float num = (float)i / 10f;
					Vector3 val = Vector3.Lerp(start, end, num);
					float num2 = Mathf.Sin(num * (float)Math.PI);
					Vector3 val2 = new Vector3(Random.Range(-1f, 1f), 0f, Random.Range(-1f, 1f)) * num2 * 1.5f;
					array[i] = val + val2;
				}
				return array;
			}

			private static void CreateBoltLine(GameObject parent, string childName, Vector3[] points, Shader shader, float width, Color color)
			{
				//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_004c: 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_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_0069: 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_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Expected O, but got Unknown
				GameObject val = new GameObject(childName);
				val.transform.SetParent(parent.transform, true);
				LineRenderer val2 = val.AddComponent<LineRenderer>();
				val2.positionCount = points.Length;
				val2.SetPositions(points);
				val2.startWidth = width;
				val2.endWidth = width * 0.3f;
				val2.useWorldSpace = true;
				val2.startColor = color;
				val2.endColor = new Color(color.r, color.g, color.b, color.a * 0.5f);
				if ((Object)(object)shader != (Object)null)
				{
					((Renderer)val2).material = new Material(shader)
					{
						color = color
					};
				}
			}

			private static Shader ResolveBoltShader()
			{
				string[] boltShaderNames = BoltShaderNames;
				for (int i = 0; i < boltShaderNames.Length; i++)
				{
					Shader val = Shader.Find(boltShaderNames[i]);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				return null;
			}
		}

		[HarmonyPatch]
		public static class CryptLootPatch
		{
			private const string ProcessedCoreStandZdoKey = "Hardship_CryptCoreProcessed";

			private static bool wasInsideCrypt;

			private static readonly HashSet<int> processedStandInstanceIds = new HashSet<int>();

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Player), "FixedUpdate")]
			private static void OnPlayerFixedUpdate()
			{
				if (!((Object)(object)Player.m_localPlayer == (Object)null))
				{
					if (!((Character)Player.m_localPlayer).InInterior())
					{
						wasInsideCrypt = false;
					}
					else if (!wasInsideCrypt)
					{
						wasInsideCrypt = true;
						ProcessCurrentCrypt();
					}
				}
			}

			private static void ProcessCurrentCrypt()
			{
				//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_0093: 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_0149: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0167: Unknown result type (might be due to invalid IL or missing references)
				ItemDrop surtlingCore = Cache.GetPrefab<ItemDrop>("SurtlingCore");
				if ((Object)(object)surtlingCore == (Object)null)
				{
					return;
				}
				Vector3 playerPos = ((Component)Player.m_localPlayer).transform.position;
				Room val = Object.FindObjectsByType<Room>((FindObjectsSortMode)0).Where(delegate(Room room)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					Scene scene = ((Component)room).gameObject.scene;
					return ((Scene)(ref scene)).IsValid() && DungeonRoomUtils.IsPositionInsideRoom(room, playerPos);
				}).OrderBy(delegate(Room room)
				{
					//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_0016: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val3 = ((Component)room).transform.position - playerPos;
					return ((Vector3)(ref val3)).sqrMagnitude;
				})
					.FirstOrDefault();
				DungeonGenerator val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInParent<DungeonGenerator>() : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					Logger.LogWarning((object)$"Hardship: Could not find the current crypt room for player at {playerPos}; skipping Surtling Core processing.");
					return;
				}
				Room[] rooms = ((Component)val2).GetComponentsInChildren<Room>(true);
				List<Pickable> list = Object.FindObjectsByType<Pickable>((FindObjectsSortMode)0).Where(delegate(Pickable p)
				{
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001d: Unknown result type (might be due to invalid IL or missing references)
					Scene scene = ((Component)p).gameObject.scene;
					return ((Scene)(ref scene)).IsValid() && (Object)(object)p.m_itemPrefab == (Object)(object)((Component)surtlingCore).gameObject && rooms.Any((Room room) => DungeonRoomUtils.IsPositionInsideRoom(room, ((Component)p).transform.position));
				}).OrderBy(delegate(Pickable p)
				{
					//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_0016: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val3 = ((Component)p).transform.position - playerPos;
					return ((Vector3)(ref val3)).sqrMagnitude;
				})
					.ToList();
				Logger.LogDebug((object)$"Hardship: Entered crypt room '{((Object)((Component)val).gameObject).name}' ({val.m_theme}); checking its {rooms.Length} rooms.");
				Logger.LogDebug((object)$"Hardship: Found {list.Count} Surtling Core stand(s) in this crypt.");
				foreach (Pickable item in list)
				{
					float num = Vector3.Distance(((Component)item).transform.position, playerPos);
					Logger.LogDebug((object)$"Hardship: Core stand at {((Component)item).transform.position}, {num:F1}m away, processed={IsCoreStandProcessed(item)}.");
				}
				if (list.Count == 0)
				{
					return;
				}
				if (list.Any(IsCoreStandProcessed))
				{
					Logger.LogDebug((object)"Hardship: A core stand was already processed; keeping the existing result.");
					return;
				}
				float num2 = Random.Range(0f, 100f);
				float num3 = ((cryptSurtlingCoreChance != null) ? cryptSurtlingCoreChance.Value : 50f);
				bool num4 = num2 < num3;
				Logger.LogDebug((object)$"Hardship: roll: {num2}");
				if (num4)
				{
					Logger.LogDebug((object)"Hardship: Keeping one Surtling Core stand in the crypt.");
					MarkCoreStandProcessed(list[0]);
				}
				else
				{
					Logger.LogDebug((object)"Hardship: Not keeping any Surtling Core stands in the crypt.");
				}
				IEnumerable<Pickable> enumerable2;
				if (!num4)
				{
					IEnumerable<Pickable> enumerable = list;
					enumerable2 = enumerable;
				}
				else
				{
					enumerable2 = list.Skip(1);
				}
				foreach (Pickable item2 in enumerable2)
				{
					GameObject gameObject = ((Component)item2).gameObject;
					if ((Object)(object)ZNetScene.instance != (Object)null)
					{
						ZNetScene.instance.Destroy(gameObject);
					}
					else
					{
						Object.Destroy((Object)(object)gameObject);
					}
				}
			}

			private static bool IsCoreStandProcessed(Pickable stand)
			{
				if ((Object)(object)stand == (Object)null)
				{
					return false;
				}
				ZNetView component = ((Component)stand).GetComponent<ZNetView>();
				if (!((Object)(object)component != (Object)null) || !component.IsValid() || !component.GetZDO().GetBool("Hardship_CryptCoreProcessed", false))
				{
					return processedStandInstanceIds.Contains(((Object)stand).GetInstanceID());
				}
				return true;
			}

			private static void MarkCoreStandProcessed(Pickable stand)
			{
				processedStandInstanceIds.Add(((Object)stand).GetInstanceID());
				ZNetView component = ((Component)stand).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.GetZDO().Set("Hardship_CryptCoreProcessed", true);
				}
			}
		}

		internal static class DungeonRoomUtils
		{
			private static readonly HashSet<Room> sunkenCryptRooms = new HashSet<Room>();

			private static bool sunkenCryptRoomsInitialized;

			public static bool IsPositionInsideRoom(Room room, Vector3 position)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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_0057: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = ((Component)room).transform.InverseTransformPoint(position);
				if (Mathf.Abs(val.x) <= (float)((Vector3Int)(ref room.m_size)).x * 0.5f + 0.5f && Mathf.Abs(val.y) <= (float)((Vector3Int)(ref room.m_size)).y * 0.5f + 0.5f)
				{
					return Mathf.Abs(val.z) <= (float)((Vector3Int)(ref room.m_size)).z * 0.5f + 0.5f;
				}
				return false;
			}

			public static bool IsPositionInsideSunkenCrypt(Vector3 position)
			{
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				if (!sunkenCryptRoomsInitialized)
				{
					Room[] array = Object.FindObjectsByType<Room>((FindObjectsSortMode)0);
					for (int i = 0; i < array.Length; i++)
					{
						RegisterSunkenCryptRoom(array[i]);
					}
					sunkenCryptRoomsInitialized = true;
				}
				sunkenCryptRooms.RemoveWhere((Room r) => (Object)(object)r == (Object)null);
				foreach (Room sunkenCryptRoom in sunkenCryptRooms)
				{
					if ((Object)(object)sunkenCryptRoom != (Object)null)
					{
						Scene scene = ((Component)sunkenCryptRoom).gameObject.scene;
						if (((Scene)(ref scene)).IsValid() && IsPositionInsideRoom(sunkenCryptRoom, position))
						{
							return true;
						}
					}
				}
				return false;
			}

			public static void RegisterSunkenCryptRoom(Room room)
			{
				//IL_000a: 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)
				if ((Object)(object)room != (Object)null && (room.m_theme & 2) != 0)
				{
					sunkenCryptRooms.Add(room);
				}
			}
		}

		[HarmonyPatch(typeof(Room), "Awake")]
		public static class DungeonRoomAwa