Decompiled source of Endless Containment v1.0.2

plugins/EndlessContainment.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Mirror;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("EndlessContainment")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("EndlessContainment")]
[assembly: AssemblyTitle("EndlessContainment")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace EndlessContainment;

internal sealed class DepositForager : MonoBehaviour
{
	private static readonly FieldInfo mode = Members.Field<Beetle>("_state");

	private static readonly FieldInfo pause = Members.Field<Beetle>("_pauseTimeRemaining");

	private static readonly object hunting = Enum.Parse(mode.FieldType, "Hunting");

	private static readonly object eating = Enum.Parse(mode.FieldType, "Eating");

	private static readonly object wandering = Enum.Parse(mode.FieldType, "Wandering");

	private static readonly FieldInfo packClaims = Members.Field<IncrementalTank>("_claims");

	private static readonly Func<Beetle, Vector3, bool> approach = (Func<Beetle, Vector3, bool>)Delegate.CreateDelegate(typeof(Func<Beetle, Vector3, bool>), Members.Method<Beetle>("TrySetDestination"));

	private static readonly Action<Beetle> eatFx = (Action<Beetle>)Delegate.CreateDelegate(typeof(Action<Beetle>), Members.Method<Beetle>("PlayEatEffect"));

	private static readonly HashSet<uint> reservations = new HashSet<uint>();

	private Beetle beetle;

	private FreedDeposit meal;

	private uint reserved;

	private float nextSearch;

	private float nextRoute;

	private float routeUntil;

	private float biteAt = -1f;

	private Vector3 routedTo;

	private void Awake()
	{
		beetle = ((Component)this).GetComponent<Beetle>();
	}

	private void OnDestroy()
	{
		Release(resetMode: false);
	}

	internal static bool IsFood(FreedDeposit item)
	{
		if ((Object)(object)item == (Object)null || !((Component)item).gameObject.activeInHierarchy || !item.LiesLoose || ((HeldItem)item).IsPocketed || (Object)(object)((HeldItem)item).Holder != (Object)null || ((HeldItem)item).PickupLocked || !IncrementalTank.GoesInTank((HeldItem)(object)item))
		{
			return false;
		}
		IncrementalTank instance = IncrementalTank.Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			return !((Dictionary<FreedDeposit, ulong>)packClaims.GetValue(instance)).ContainsKey(item);
		}
		return true;
	}

	internal static bool FloorNear(EggMeshGenerator egg, out Vector3 position)
	{
		//IL_0001: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		position = default(Vector3);
		if ((Object)(object)egg == (Object)null)
		{
			return false;
		}
		float num = egg.Radius * Mathf.Abs(((Component)egg).transform.lossyScale.x) + 1.25f;
		NavMeshHit val = default(NavMeshHit);
		for (int i = 0; i < 8; i++)
		{
			float num2 = (float)i * (float)Math.PI * 0.25f;
			Vector3 position2 = ((Component)egg).transform.position;
			position2.x += Mathf.Cos(num2) * num;
			position2.z += Mathf.Sin(num2) * num;
			position2.y = (((Object)(object)IncrementalLab.Instance != (Object)null) ? ((Component)IncrementalLab.Instance).transform.position.y : 0f);
			if (NavMesh.SamplePosition(position2, ref val, 2f, -1))
			{
				position = ((NavMeshHit)(ref val)).position;
				return true;
			}
		}
		return false;
	}

	internal bool Feed(NavMeshAgent agent, Transform mouth, float range, ref float hunger, float threshold, float fullness, float chewTime)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: 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_013b: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		if (reserved != 0 && !IsFood(meal))
		{
			Release(resetMode: true);
		}
		if (reserved == 0)
		{
			if (beetle.IsEating || hunger < threshold || Time.time < nextSearch)
			{
				return false;
			}
			nextSearch = Time.time + 1.25f;
			if (!FindMeal(agent, range))
			{
				return false;
			}
			mode.SetValue(beetle, hunting);
			pause.SetValue(beetle, 0f);
		}
		Vector3 position = ((Component)meal).transform.position;
		if (!(Time.time >= routeUntil))
		{
			Vector3 val;
			if (Time.time >= nextRoute)
			{
				val = position - routedTo;
				if (((Vector3)(ref val)).sqrMagnitude > 0.16f && !Route(agent, position))
				{
					goto IL_00e4;
				}
			}
			Vector3 val2 = (((Object)(object)mouth != (Object)null) ? mouth.position : ((Component)this).transform.position);
			Collider componentInChildren = ((Component)meal).GetComponentInChildren<Collider>();
			float num;
			if (!((Object)(object)componentInChildren != (Object)null))
			{
				val = val2 - position;
				num = ((Vector3)(ref val)).sqrMagnitude;
			}
			else
			{
				Bounds bounds = componentInChildren.bounds;
				num = ((Bounds)(ref bounds)).SqrDistance(val2);
			}
			if (num > 0.3025f)
			{
				if (biteAt >= 0f)
				{
					mode.SetValue(beetle, hunting);
				}
				biteAt = -1f;
				return true;
			}
			if (biteAt < 0f)
			{
				biteAt = Time.time + Mathf.Max(0.2f, chewTime);
				mode.SetValue(beetle, eating);
			}
			if (Time.time < biteAt)
			{
				return true;
			}
			FreedDeposit val3 = meal;
			Release(resetMode: true);
			if (!IsFood(val3) || !NetworkServer.spawned.ContainsKey(((NetworkBehaviour)val3).netId))
			{
				return true;
			}
			hunger = Mathf.Clamp01(hunger - fullness);
			eatFx(beetle);
			NetworkServer.Destroy(((Component)val3).gameObject);
			return true;
		}
		goto IL_00e4;
		IL_00e4:
		Release(resetMode: true);
		return false;
	}

	private bool FindMeal(NavMeshAgent agent, float range)
	{
		//IL_0042: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
		List<FreedDeposit> list = new List<FreedDeposit>();
		foreach (HeldItem serverItem in ItemRestSync.ServerItems)
		{
			FreedDeposit val = (FreedDeposit)(object)((serverItem is FreedDeposit) ? serverItem : null);
			if (val != null && IsFood(val) && !reservations.Contains(((NetworkBehaviour)val).netId))
			{
				Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
				if (((Vector3)(ref val2)).sqrMagnitude <= range * range)
				{
					list.Add(val);
				}
			}
		}
		list.Sort(delegate(FreedDeposit a, FreedDeposit b)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val3 = ((Component)a).transform.position - ((Component)this).transform.position;
			float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
			val3 = ((Component)b).transform.position - ((Component)this).transform.position;
			return sqrMagnitude.CompareTo(((Vector3)(ref val3)).sqrMagnitude);
		});
		foreach (FreedDeposit item in list)
		{
			if (Route(agent, ((Component)item).transform.position))
			{
				meal = item;
				reserved = ((NetworkBehaviour)item).netId;
				reservations.Add(reserved);
				routeUntil = Time.time + 24f;
				return true;
			}
		}
		return false;
	}

	private bool Route(NavMeshAgent agent, Vector3 point)
	{
		//IL_0011: 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_002e: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		nextRoute = Time.time + 0.6f;
		NavMeshHit val = default(NavMeshHit);
		if (!NavMesh.SamplePosition(point, ref val, 1.2f, agent.areaMask) || Mathf.Abs(point.y - ((NavMeshHit)(ref val)).position.y) > 1f || !approach(beetle, ((NavMeshHit)(ref val)).position))
		{
			return false;
		}
		routedTo = point;
		return true;
	}

	internal void Release(bool resetMode)
	{
		if (reserved != 0)
		{
			reservations.Remove(reserved);
			reserved = 0u;
			meal = null;
			biteAt = -1f;
			if (resetMode && (Object)(object)beetle != (Object)null)
			{
				mode.SetValue(beetle, wandering);
			}
		}
	}
}
[HarmonyPatch(typeof(Beetle), "OnStartServer")]
internal static class BeetleDiet
{
	private static void Postfix(Beetle __instance)
	{
		if (Run.Active)
		{
			((Component)__instance).gameObject.AddComponent<DepositForager>();
		}
	}
}
[HarmonyPatch(typeof(Beetle), "UpdateFeeding")]
internal static class BeetleFeed
{
	private static bool Prefix(Beetle __instance, NavMeshAgent ___agent, Transform ___mouthPoint, ResourcePickup ____target, float ____noFoodUntil, float ____fleeUntil, float ___senseRadiusPeckish, float ___senseRadiusStarving, float ___huntAbove, float ___fullnessPerMeal, float ___chewTime, ref float ___hunger)
	{
		DepositForager depositForager = default(DepositForager);
		if (!Run.Active || (Object)(object)____target != (Object)null || SaveManager.LoadInProgress || ____noFoodUntil > Time.time || ____fleeUntil > Time.time || !((Component)__instance).TryGetComponent<DepositForager>(ref depositForager))
		{
			return true;
		}
		float range = Mathf.Lerp(___senseRadiusPeckish, ___senseRadiusStarving, ___hunger);
		return !depositForager.Feed(___agent, ___mouthPoint, range, ref ___hunger, ___huntAbove, ___fullnessPerMeal, ___chewTime);
	}
}
[HarmonyPatch(typeof(Beetle), "ReleaseTarget")]
internal static class LetGoOfFood
{
	private static void Prefix(Beetle __instance)
	{
		DepositForager depositForager = default(DepositForager);
		if (Run.Active && ((Component)__instance).TryGetComponent<DepositForager>(ref depositForager))
		{
			depositForager.Release(resetMode: true);
		}
	}
}
[HarmonyPatch(typeof(BeetleSwarmEvent), "ServerCanRun")]
internal static class FloorSwarmEligible
{
	private static void Postfix(ref bool __result, Beetle ___beetlePrefab, EggMeshGenerator ___egg)
	{
		if (Run.Active && !((Object)(object)___beetlePrefab == (Object)null))
		{
			if (Object.FindObjectsByType<Beetle>((FindObjectsSortMode)0).Length >= 12)
			{
				__result = false;
			}
			else if (!__result)
			{
				__result = DepositForager.FloorNear(___egg, out var _);
			}
		}
	}
}
[HarmonyPatch(typeof(BeetleSwarmEvent), "TrySpawnOne")]
internal static class FloorSwarmSpawn
{
	private static bool Prefix(ref bool __result)
	{
		if (!Run.Active || Object.FindObjectsByType<Beetle>((FindObjectsSortMode)0).Length < 12)
		{
			return true;
		}
		__result = false;
		return false;
	}

	private static void Postfix(ref bool __result, Beetle ___beetlePrefab, EggMeshGenerator ___egg)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (!(!Run.Active | __result) && !((Object)(object)___beetlePrefab == (Object)null) && NetworkServer.active && Object.FindObjectsByType<Beetle>((FindObjectsSortMode)0).Length < 12 && DepositForager.FloorNear(___egg, out var position))
		{
			NetworkServer.Spawn(((Component)Object.Instantiate<Beetle>(___beetlePrefab, position, Quaternion.identity)).gameObject, (NetworkConnectionToClient)null);
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(EggTerrain), "ComputeDensity")]
internal static class CorePocket
{
	private static readonly MethodInfo bindVirgin = Members.Method<EggTerrain>("BindVirginUniforms");

	private static readonly MethodInfo bindCarve = Members.Method<EggTerrain>("BindCarveUniforms");

	private static readonly MethodInfo bindShape = Members.Method<EggTerrain>("BindCarveShape");

	private static readonly int[] clear = new int[17];

	private static void Postfix(EggTerrain __instance, ComputeShader ___editCompute, ComputeBuffer ___removedCountBuffer)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		if (Run.Current && !(Eggs.CoreRadius <= 0f) && !((Object)(object)__instance.TypeRegistry != (Object)(object)Eggs.Registry))
		{
			float coreRadius = Eggs.CoreRadius;
			Vector3Int val = __instance.LocalToVoxel(Vector3.zero);
			Vector3Int textureSize = __instance.TextureSize;
			Vector3Int val2 = Vector3Int.Max(Vector3Int.zero, __instance.LocalToVoxel(-Vector3.one * coreRadius) - Vector3Int.one * 2);
			Vector3Int val3 = Vector3Int.Min(textureSize - Vector3Int.one, __instance.LocalToVoxel(Vector3.one * coreRadius) + Vector3Int.one * 2) - val2 + Vector3Int.one;
			bindVirgin.Invoke(__instance, new object[1] { ___editCompute });
			bindCarve.Invoke(__instance, null);
			CarvePrimitive[] array = (CarvePrimitive[])(object)new CarvePrimitive[1] { CarvePrimitive.Sphere(Vector3.zero, coreRadius) };
			bindShape.Invoke(__instance, new object[1] { array });
			___removedCountBuffer.SetData((Array)clear);
			___editCompute.SetFloat("weight", 1000000f);
			___editCompute.SetFloat("deltaTime", 1f);
			___editCompute.SetInts("brushCentre", new int[3]
			{
				((Vector3Int)(ref val)).x,
				((Vector3Int)(ref val)).y,
				((Vector3Int)(ref val)).z
			});
			___editCompute.SetFloats("brushPointLocal", new float[3]);
			___editCompute.SetInt("brushRadius", Math.Max(((Vector3Int)(ref val3)).x, Math.Max(((Vector3Int)(ref val3)).y, ((Vector3Int)(ref val3)).z)));
			___editCompute.SetFloat("brushWorldRadius", coreRadius);
			___editCompute.SetInt("allowedTypeMask", 255);
			___editCompute.SetInts("regionMin", new int[3]
			{
				((Vector3Int)(ref val2)).x,
				((Vector3Int)(ref val2)).y,
				((Vector3Int)(ref val2)).z
			});
			uint span = default(uint);
			uint span2 = default(uint);
			uint span3 = default(uint);
			___editCompute.GetKernelThreadGroupSizes(0, ref span, ref span2, ref span3);
			___editCompute.Dispatch(0, Groups(((Vector3Int)(ref val3)).x, span), Groups(((Vector3Int)(ref val3)).y, span2), Groups(((Vector3Int)(ref val3)).z, span3));
			bindShape.Invoke(__instance, new object[1]);
		}
	}

	private static int Groups(int n, uint span)
	{
		return (n + (int)span - 1) / (int)span;
	}
}
[HarmonyPatch(typeof(EggTerrain), "HealRoutine")]
internal static class ProtectCore
{
	private static void Prefix(ref CarvePrimitive[] localPockets)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		if (Run.Current)
		{
			CarvePrimitive val = CarvePrimitive.Sphere(Vector3.zero, Eggs.CoreRadius);
			CarvePrimitive[] array = localPockets ?? Array.Empty<CarvePrimitive>();
			localPockets = (CarvePrimitive[])(object)new CarvePrimitive[array.Length + 1];
			localPockets[0] = val;
			Array.Copy(array, 0, localPockets, 1, array.Length);
		}
	}
}
[HarmonyPatch(typeof(EggTerrain), "BaselineHash")]
internal static class TerrainVersion
{
	private static void Postfix(ref string __result)
	{
		if (Run.Current)
		{
			__result = __result + "-EC1-" + Run.Seed.ToString("X8") + "-" + IncrementalEgg.Number.ToString("X8");
		}
	}
}
[HarmonyPatch(typeof(EggMembrane), "Generate")]
internal static class CoreSkin
{
	private static void Prefix(ref EggMeshGenerator eggMesh, ref float surfacePadding, ref float terrainThickness, float ____inset, out GameObject __state)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		__state = null;
		if (Run.Current)
		{
			__state = new GameObject("Core mesh dimensions")
			{
				hideFlags = (HideFlags)61
			};
			__state.SetActive(false);
			EggMeshGenerator val = __state.AddComponent<EggMeshGenerator>();
			val.ApplyRecipeShape(Eggs.CoreRadius, Eggs.CoreRadius, 0f, eggMesh.Resolution, 1f);
			eggMesh = val;
			surfacePadding = 0f - ____inset;
			terrainThickness = 0f;
		}
	}

	private static void Finalizer(GameObject __state)
	{
		if ((Object)(object)__state != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)__state);
		}
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "get_SackDetail")]
internal static class SmallSackDetail
{
	private static void Postfix(ref float __result)
	{
		if (Run.Current)
		{
			__result = Mathf.Clamp(Eggs.CoreRadius * 0.45f, 0.05f, 1f);
		}
	}
}
[HarmonyPatch(typeof(TerrainDepositManager), "ApplyRecipeDepositsOnSack")]
internal static class BuryNodes
{
	private static bool Prefix(ref bool ____onSack)
	{
		if (!Run.Current)
		{
			return true;
		}
		____onSack = false;
		return false;
	}
}
[HarmonyPatch(typeof(TerrainDepositManager), "get_Settings")]
internal static class SizeNodes
{
	private static void Postfix(ref Settings __result)
	{
		if (Run.Current && !(Eggs.CoreRadius <= 0f))
		{
			float num = Eggs.CoreRadius / Eggs.CurrentLayout.Core;
			__result.maxDepositRadius = Mathf.Max(0.04f, num * 0.14f);
			__result.maxAttemptsPerDeposit = Math.Max(100, __result.maxAttemptsPerDeposit);
			__result.burialMargin = Mathf.Min(__result.burialMargin, num * 0.025f);
			__result.globalMinDistance = Mathf.Min(__result.globalMinDistance, num * 0.1f);
		}
	}
}
[HarmonyPatch(typeof(TerrainDepositManager), "CandidateAllowed")]
internal static class DepositInTissue
{
	private static bool Prefix(EggTerrain ____terrain, Vector3 candidate, ref float depth, ref bool __result)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		if (!Run.Current)
		{
			return true;
		}
		depth = ____terrain.ComputeNormalizedDepth(candidate);
		__result = ((Vector3)(ref candidate)).sqrMagnitude > Eggs.CoreRadius * Eggs.CoreRadius && ____terrain.DistanceOutsideEgg(candidate) < 0f && (Object)(object)Eggs.Registry != (Object)null && !Eggs.Registry.IsSealedBand(Eggs.Registry.CPUBandType(depth, candidate));
		return false;
	}
}
[HarmonyPatch(typeof(TerrainDepositManager), "PlacementSafe")]
internal static class NodeCoreClearance
{
	private static bool Prefix(Vector3 local, float boundRadius, ref bool __result)
	{
		if (!Run.Current)
		{
			return true;
		}
		float num = Eggs.CoreRadius + boundRadius;
		__result = ((Vector3)(ref local)).sqrMagnitude > num * num;
		return false;
	}
}
internal static class Eggs
{
	private static readonly Dictionary<int, EggRecipe> recipes = new Dictionary<int, EggRecipe>();

	internal static Layout CurrentLayout;

	internal static float CoreRadius;

	private static float extent;

	private static TerrainDepositType[] sceneDeposits = Array.Empty<TerrainDepositType>();

	private static readonly FieldInfo geodeLoot = Members.Field<Geode>("pickup");

	internal static TerrainTypeRegistry Registry;

	private static readonly List<Object> paletteObjects = new List<Object>();

	private static readonly Dictionary<(TerrainType[], int), TerrainType[]> toolMasks = new Dictionary<(TerrainType[], int), TerrainType[]>();

	private static readonly FieldInfo types = Members.Field<TerrainTypeRegistry>("types");

	private static readonly FieldInfo sceneTypes = Members.Field<TerrainTypeRegistry>("_sceneTypes");

	private static readonly FieldInfo warbled = Members.Field<TerrainTypeRegistry>("_warbled");

	private static readonly ResourceType[] Palette;

	private static readonly Color[] colours;

	internal static void Clear()
	{
		foreach (EggRecipe value in recipes.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
		}
		recipes.Clear();
		ClearPalette();
		CoreRadius = 0f;
		sceneDeposits = Array.Empty<TerrainDepositType>();
	}

	internal static void CaptureDeposits(Scene scene)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		sceneDeposits = (from d in (from m in Members.InScene<TerrainDepositManager>(scene)
				where m.DepositTypes != null
				select m).SelectMany((TerrainDepositManager m) => m.DepositTypes).Concat(Resources.LoadAll<TerrainDepositType>(string.Empty))
			where (Object)(object)d != (Object)null
			select d).Distinct().ToArray();
		if (recipes.Count == 0)
		{
			return;
		}
		EggSequence val = IncrementalEgg.Recipes;
		EggRecipe[] array = val.eggs.Where((EggRecipe e) => (Object)(object)e != (Object)null && e.scale > 0f).ToArray();
		foreach (KeyValuePair<int, EggRecipe> recipe in recipes)
		{
			Layout layout = Layout.Roll(Run.Seed, recipe.Key, array.Length);
			recipe.Value.deposits = Deposits(val, array[layout.SizeIndex], layout.Richness);
		}
	}

	internal static bool IsCurrentRecipe(EggRecipe recipe)
	{
		if (Run.Current && recipes.TryGetValue(IncrementalEgg.Number, out var value))
		{
			return (Object)(object)value == (Object)(object)recipe;
		}
		return false;
	}

	private static void ClearPalette()
	{
		Dictionary<Material, Material> dictionary = (((Object)(object)Registry != (Object)null) ? ((Dictionary<Material, Material>)warbled.GetValue(Registry)) : null);
		foreach (Object paletteObject in paletteObjects)
		{
			Material val = (Material)(object)((paletteObject is Material) ? paletteObject : null);
			if (val != null && dictionary != null && dictionary.TryGetValue(val, out var value))
			{
				dictionary.Remove(val);
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			if (paletteObject != (Object)null)
			{
				Object.Destroy(paletteObject);
			}
		}
		paletteObjects.Clear();
		toolMasks.Clear();
		Registry = null;
	}

	internal static EggRecipe Recipe(int number)
	{
		if (recipes.TryGetValue(number, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		EggSequence val = IncrementalEgg.Recipes;
		EggRecipe[] array = val.eggs.Where((EggRecipe e) => (Object)(object)e != (Object)null && e.scale > 0f).ToArray();
		if (array.Length == 0)
		{
			throw new InvalidOperationException("The incremental egg sequence has no size templates.");
		}
		Layout layout = Layout.Roll(Run.Seed, number, array.Length);
		EggRecipe val2 = array[layout.SizeIndex];
		EggRecipe val3 = Object.Instantiate<EggRecipe>(array[layout.LookIndex]);
		((Object)val3).name = "Containment Egg " + (number + 1);
		((Object)val3).hideFlags = (HideFlags)52;
		val3.scale = val2.scale;
		val3.bottomHeight = val2.bottomHeight;
		val3.sharpness = val2.sharpness;
		val3.fleshDepth = val3.scale * 5f * (1f - layout.Core);
		val3.specialDeposits = Array.Empty<SpecialDeposit>();
		val3.deposits = Deposits(val, val2, layout.Richness);
		recipes.Add(number, val3);
		int[] array2 = recipes.Keys.Where((int k) => k != 0 && k != number && k != IncrementalEgg.Number).ToArray();
		foreach (int key in array2)
		{
			Object.Destroy((Object)(object)recipes[key]);
			recipes.Remove(key);
		}
		return val3;
	}

	private static DepositEntry[] Deposits(EggSequence sequence, EggRecipe template, float richness)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: 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_027e: Invalid comparison between Unknown and I4
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Invalid comparison between Unknown and I4
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		List<DepositEntry> list = new List<DepositEntry>();
		DepositEntry[] array = template.deposits ?? Array.Empty<DepositEntry>();
		foreach (DepositEntry val in array)
		{
			if ((Object)(object)val.type != (Object)null && val.count > 0)
			{
				list.Add(val);
			}
		}
		MaterialPriceList val2 = Resources.Load<MaterialPriceList>("Incremental/MaterialPrices");
		EggRecipe[] source = (from r in sequence.eggs.Concat((IEnumerable<EggRecipe>)(object)new EggRecipe[1] { sequence.overtime })
			where (Object)(object)r != (Object)null
			select r).ToArray();
		TerrainDepositType[] source2 = (from t in (from d in source.SelectMany((EggRecipe r) => r.deposits ?? Array.Empty<DepositEntry>())
				select d.type).Concat(from s in source.SelectMany((EggRecipe r) => r.specialDeposits ?? Array.Empty<SpecialDeposit>())
				where s != null
				select s.type).Concat(sceneDeposits).Concat(((Object)(object)val2 == (Object)null) ? Enumerable.Empty<TerrainDepositType>() : val2.deposits.Select((DepositPrice p) => p.type))
			where (Object)(object)t != (Object)null && (Object)(object)t.freedDepositPrefab != (Object)null
			select t).Distinct().OrderBy<TerrainDepositType, string>((TerrainDepositType t) => ((Object)t).name, StringComparer.Ordinal).ToArray();
		ResourceType[] array2 = (ResourceType[])(object)new ResourceType[2]
		{
			(ResourceType)9,
			(ResourceType)15
		};
		for (int i = 0; i < array2.Length; i++)
		{
			ResourceType kind = array2[i];
			TerrainDepositType geode = ((IEnumerable<TerrainDepositType>)source2).FirstOrDefault((Func<TerrainDepositType, bool>)((TerrainDepositType t) => t.resourceType == kind && t.freedDepositPrefab is Geode)) ?? ((IEnumerable<TerrainDepositType>)source2).FirstOrDefault((Func<TerrainDepositType, bool>)delegate(TerrainDepositType t)
			{
				//IL_0024: 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)
				FreedDeposit freedDepositPrefab = t.freedDepositPrefab;
				Geode val4 = (Geode)(object)((freedDepositPrefab is Geode) ? freedDepositPrefab : null);
				if (val4 != null)
				{
					object? value = geodeLoot.GetValue(val4);
					GenericPickup val5 = (GenericPickup)((value is GenericPickup) ? value : null);
					if (val5 != null)
					{
						return val5.Resource == kind;
					}
				}
				return false;
			});
			if ((Object)(object)geode == (Object)null && (int)kind == 15)
			{
				geode = ((IEnumerable<TerrainDepositType>)source2).FirstOrDefault((Func<TerrainDepositType, bool>)((TerrainDepositType t) => t.resourceType == kind));
			}
			if ((Object)(object)geode == (Object)null)
			{
				Plugin.Log.LogWarning((object)("No authored geode asset for " + ((object)Unsafe.As<ResourceType, ResourceType>(ref kind)/*cast due to .constrained prefix*/).ToString() + "."));
				continue;
			}
			int num = Math.Max(1, Mathf.RoundToInt((((int)kind == 15) ? 2f : 4f) * template.scale * template.scale * richness));
			int num2 = list.FindIndex((DepositEntry d) => (Object)(object)d.type == (Object)(object)geode);
			if (num2 >= 0)
			{
				num = Math.Max(list[num2].count, num);
			}
			DepositEntry val3 = new DepositEntry
			{
				type = geode,
				count = num
			};
			if (num2 < 0)
			{
				list.Add(val3);
			}
			else
			{
				list[num2] = val3;
			}
		}
		return list.ToArray();
	}

	internal static void ConfigureShape(EggRecipe recipe, EggMeshGenerator mesh)
	{
		CurrentLayout = Layout.Roll(Run.Seed, IncrementalEgg.Number, IncrementalEgg.Recipes.eggs.Count((EggRecipe e) => (Object)(object)e != (Object)null && e.scale > 0f));
		CoreRadius = mesh.Radius * CurrentLayout.Core;
		extent = Mathf.Min(mesh.Radius, mesh.Height);
		recipe.fleshDepth = Mathf.Max(0.01f, mesh.Radius - mesh.ShellThickness - CoreRadius);
	}

	internal static void BuildPalette(EggTerrain terrain, EggRecipe recipe)
	{
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Expected O, but got Unknown
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Invalid comparison between Unknown and I4
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Invalid comparison between Unknown and I4
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		TerrainTypeRegistry typeRegistry = terrain.TypeRegistry;
		if ((Object)(object)typeRegistry == (Object)null)
		{
			throw new InvalidOperationException("Missing egg terrain material registry.");
		}
		TerrainType[] allTypes = typeRegistry.AllTypes;
		TerrainType[] source = (from t in allTypes.Where((TerrainType t) => (Object)(object)t != (Object)null).Concat((from t in Resources.LoadAll<TerrainType>("Terrain Types")
				where (Object)(object)t != (Object)null
				select t).OrderBy<TerrainType, string>((TerrainType t) => ((Object)t).name, StringComparer.Ordinal))
			select (!((Object)(object)t.paintAs != (Object)null)) ? t : t.paintAs).Distinct().ToArray();
		TerrainType val = ((IEnumerable<TerrainType>)source).FirstOrDefault((Func<TerrainType, bool>)((TerrainType t) => (int)t.resourceType == 1 && (Object)(object)t.material != (Object)null));
		if ((Object)(object)val == (Object)null)
		{
			throw new InvalidOperationException("Missing tissue terrain material.");
		}
		typeRegistry.ApplyRecipeForms((TerrainType[])null);
		ClearPalette();
		TerrainType[] array = (TerrainType[])(object)new TerrainType[8];
		LayoutRandom layoutRandom = new LayoutRandom(Run.Seed ^ 0x21A39C, IncrementalEgg.Number);
		for (int num = 0; num < array.Length; num++)
		{
			ResourceType kind = Palette[num];
			TerrainType val2 = ((IEnumerable<TerrainType>)source).FirstOrDefault((Func<TerrainType, bool>)((TerrainType t) => t.resourceType == kind && (Object)(object)t.material != (Object)null));
			TerrainType val3 = Object.Instantiate<TerrainType>(((Object)(object)val2 != (Object)null) ? val2 : val);
			paletteObjects.Add((Object)(object)val3);
			((Object)val3).hideFlags = (HideFlags)52;
			((Object)val3).name = ((object)Unsafe.As<ResourceType, ResourceType>(ref kind)/*cast due to .constrained prefix*/).ToString();
			val3.resourceType = kind;
			val3.isVein = num >= 4;
			val3.paintAs = null;
			val3.sealedFromVeins = num == 1 || num == 2;
			val3.boundaryNoiseAmplitude = 0f;
			val3.boundaryNoiseFrequency = 0f;
			if ((Object)(object)val2 == (Object)null)
			{
				Material val4 = new Material(val.material)
				{
					name = ((Object)val3).name,
					hideFlags = (HideFlags)52
				};
				if (val4.HasProperty("_BaseColor"))
				{
					val4.SetColor("_BaseColor", colours[num]);
				}
				if (val4.HasProperty("_Color"))
				{
					val4.SetColor("_Color", colours[num]);
				}
				paletteObjects.Add((Object)(object)val4);
				val3.material = val4;
				val3.hard = num == 1 || (int)kind == 12 || (int)kind == 13;
			}
			if (num == 1)
			{
				val3.hard = true;
			}
			if (num == 1)
			{
				val3.depthThreshold = CurrentLayout.PlatingStart;
			}
			if (num == 2)
			{
				val3.depthThreshold = CurrentLayout.MembraneStart;
			}
			if (num == 3)
			{
				val3.depthThreshold = CurrentLayout.InnerTissueStart;
			}
			if (val3.isVein)
			{
				float num2 = Mathf.Max(0.42f, extent * layoutRandom.Between(0.3f, 0.43f));
				val3.veinShape = (VeinShape)3;
				val3.veinSeed = layoutRandom.Between(1f, 450f);
				val3.clusterSpacing = num2;
				val3.clusterChance = 0.9f;
				val3.clusterPiecesMin = 2;
				val3.clusterPiecesMax = 4;
				val3.clusterRadiusMin = num2 * 0.19f;
				val3.clusterRadiusMax = num2 * 0.31f;
				val3.clusterLength = num2 * 0.5f;
				val3.veinMinDepth = 0.02f;
				val3.veinMaxDepth = 0.98f;
				val3.veinMinHeight = 0f;
			}
			array[num] = val3;
		}
		sceneTypes.SetValue(typeRegistry, allTypes);
		types.SetValue(typeRegistry, array);
		Registry = typeRegistry;
		typeRegistry.ApplyRecipeWarble(recipe.warbleStrength);
		typeRegistry.ApplyRecipeHue((Dictionary<Material, float>)null);
		Plugin.Log.LogInfo((object)$"Egg {IncrementalEgg.Number + 1}, scale {recipe.scale:F3}, core {CurrentLayout.Core:P1}, layout seed {Run.Seed}.");
	}

	internal static TerrainType[] ExpandTools(TerrainType[] stock, HeldItem tool)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Invalid comparison between Unknown and I4
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		if (stock == null || stock.Length == 0 || (Object)(object)Registry == (Object)null)
		{
			return stock;
		}
		Role val = default(Role);
		bool flag = IncrementalTools.TryGetRole(tool, ref val);
		bool sharp = flag && (int)val == 0;
		bool soft = flag && (int)val == 1;
		(TerrainType[], int) key = (stock, sharp ? 1 : (soft ? 2 : 0));
		if (toolMasks.TryGetValue(key, out var value))
		{
			return value;
		}
		TerrainType[] array = stock.Concat(Registry.Types.Where((TerrainType t) => (!sharp) ? ((!soft) ? stock.Any((TerrainType s) => (Object)(object)s != (Object)null && s.resourceType == t.resourceType) : (!t.hard)) : t.hard)).Distinct().ToArray();
		toolMasks[key] = array;
		return array;
	}

	static Eggs()
	{
		//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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		ResourceType[] array = new ResourceType[8];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		Palette = (ResourceType[])(object)array;
		colours = (Color[])(object)new Color[8]
		{
			new Color(0.86f, 0.49f, 0.43f),
			new Color(0.48f, 0.51f, 0.54f),
			new Color(0.86f, 0.72f, 0.6f),
			new Color(0.86f, 0.49f, 0.43f),
			new Color(0.93f, 0.63f, 0.44f),
			new Color(0.3f, 0.65f, 0.68f),
			new Color(0.36f, 0.25f, 0.4f),
			new Color(0.84f, 0.83f, 0.71f)
		};
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "Apply")]
internal static class CheckDepositAssets
{
	private static void Prefix(Scene scene)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (Run.Active)
		{
			Eggs.CaptureDeposits(scene);
		}
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "FinerFor")]
internal static class ResolveCoreGrid
{
	private static bool Prefix(EggRecipe recipe, ref float __result, float ___s_r0, float ___s_pad, int ___s_points, Vector3Int ___s_c0)
	{
		if (!Eggs.IsCurrentRecipe(recipe) || ___s_r0 <= 0f || ((Vector3Int)(ref ___s_c0)).x <= 0)
		{
			return true;
		}
		float num = 2f * (___s_r0 + ___s_pad) / (float)(((Vector3Int)(ref ___s_c0)).x * Mathf.Max(1, ___s_points - 1));
		float num2 = ___s_r0 * recipe.scale * 0.1f;
		__result = Mathf.Max(1f, 4f * num / num2);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "RecipeFor")]
internal static class RecipeLookup
{
	private static bool Prefix(int number, ref EggRecipe __result)
	{
		if (!Run.Generated(number))
		{
			return true;
		}
		__result = Eggs.Recipe(number);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "LookRecipeFor")]
internal static class LookLookup
{
	private static bool Prefix(int number, ref EggRecipe __result)
	{
		if (!Run.Generated(number))
		{
			return true;
		}
		__result = Eggs.Recipe(number);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "CreatureFor")]
internal static class CreatureLookup
{
	private static bool Prefix(int number, ref GameObject __result)
	{
		if (!Run.Generated(number))
		{
			return true;
		}
		__result = Eggs.Recipe(number).creature;
		if ((Object)(object)__result == (Object)null)
		{
			__result = ((IEnumerable<EggRecipe>)IncrementalEgg.Recipes.eggs).FirstOrDefault((Func<EggRecipe, bool>)((EggRecipe e) => (Object)(object)e != (Object)null && (Object)(object)e.creature != (Object)null))?.creature;
		}
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "ApplyShape")]
internal static class RecordShape
{
	private static void Postfix(EggRecipe recipe, EggMeshGenerator mesh, EggTerrain terrain)
	{
		if (Run.Current)
		{
			Eggs.ConfigureShape(recipe, mesh);
			terrain.ApplyRecipeThickness(0f);
		}
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "ApplyLayers")]
internal static class ApplyInterior
{
	private static bool Prefix(EggTerrain terrain, EggRecipe recipe)
	{
		if (!Run.Current)
		{
			return true;
		}
		Eggs.BuildPalette(terrain, recipe);
		return false;
	}
}
[HarmonyPatch(typeof(TerrainTypeRegistry), "GetTypeId")]
internal static class ResolveAuthoredMaterial
{
	private static void Postfix(TerrainTypeRegistry __instance, TerrainType terrainType, ref int __result)
	{
		if (__result < 0 && Run.Current && !((Object)(object)__instance != (Object)(object)Eggs.Registry) && !((Object)(object)terrainType == (Object)null))
		{
			TerrainType source = (((Object)(object)terrainType.paintAs != (Object)null) ? terrainType.paintAs : terrainType);
			__result = Array.FindIndex(__instance.Types, (TerrainType t) => t.resourceType == source.resourceType);
		}
	}
}
[HarmonyPatch(typeof(IncrementalTools), "LayersFor")]
internal static class ToolMaterials
{
	private static void Postfix(HeldItem tool, ref TerrainType[] __result)
	{
		if (Run.Current)
		{
			__result = Eggs.ExpandTools(__result, tool);
		}
	}
}
[HarmonyPatch(typeof(EggTerrainSync), "BuildBreakMask")]
internal static class MatchingBands
{
	private static void Postfix(TerrainType[] breakable, ref byte __result)
	{
		if (!Run.Current || (Object)(object)Eggs.Registry == (Object)null || breakable == null || breakable.Length == 0)
		{
			return;
		}
		TerrainType[] slots = Eggs.Registry.Types;
		int i;
		for (i = 0; i < slots.Length; i++)
		{
			if (Array.Exists(breakable, (TerrainType t) => (Object)(object)t != (Object)null && t.resourceType == slots[i].resourceType))
			{
				__result |= (byte)(1 << i);
			}
		}
	}
}
[HarmonyPatch(typeof(IncrementalTools), "Init")]
internal static class RemoveEveryLayer
{
	private static void Prefix(ref RoleUpgradeList upgrades)
	{
		if (Run.Active)
		{
			upgrades = Object.Instantiate<RoleUpgradeList>(upgrades);
			((Object)upgrades).hideFlags = (HideFlags)52;
			upgrades.upgrades = upgrades.upgrades.Where((Upgrade u) => u == null || (int)u.stat != 38).ToArray();
		}
	}

	private static void Postfix(IncrementalTools __instance)
	{
		if (Run.Active)
		{
			((Component)__instance).gameObject.AddComponent<OwnedShopList>().List = __instance.Upgrades;
		}
	}
}
internal sealed class OwnedShopList : MonoBehaviour
{
	internal RoleUpgradeList List;

	private void OnDestroy()
	{
		if ((Object)(object)List != (Object)null)
		{
			Object.Destroy((Object)(object)List);
		}
	}
}
[HarmonyPatch(typeof(IncrementalFinale), "ServerBegin")]
internal static class ContinuousShift
{
	private static bool Prefix(ref bool __result)
	{
		if (!Run.Active)
		{
			return true;
		}
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "get_HasOvertime")]
internal static class SuccessorAvailable
{
	private static void Postfix(ref bool __result)
	{
		if (Run.Active)
		{
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "get_HardMaterialReached")]
internal static class HardLayersPresent
{
	private static void Postfix(ref bool __result)
	{
		if (Run.Current)
		{
			__result = true;
		}
	}
}
internal static class Hazards
{
	private static readonly MethodInfo cancelLead = Members.Method<EventDirector>("ServerCancelLeadIn");

	private static readonly MethodInfo beginNow = Members.Method<EventDirector>("BeginNow");

	private static readonly FieldInfo gridReady = Members.Field<AgitationManager>("_gridReady");

	private static readonly FieldInfo eyeHealPump = Members.Field<EyeballEvent>("_healPump");

	private static readonly FieldInfo eyeHealQueue = Members.Field<EyeballEvent>("_healQueue");

	private static readonly MethodInfo clearEyeHeals = eyeHealQueue.FieldType.GetMethod("Clear", Type.EmptyTypes);

	private static readonly List<Light> cutLamps = new List<Light>();

	private static Type lastEvent;

	private static float nextCheck;

	internal static float RestoreSeconds = -1f;

	internal static float NextOutageLength = 180f;

	internal static bool ResumingOutage { get; private set; }

	internal static float Remaining
	{
		get
		{
			if (!(RestoreSeconds >= 0f))
			{
				if (!((Object)(object)EventDirector.instance != (Object)null))
				{
					return 0f;
				}
				return EventDirector.instance.PowerRestoreSecondsLeft;
			}
			return RestoreSeconds;
		}
	}

	internal static bool PowerOut
	{
		get
		{
			if (Run.Active && (Object)(object)EventDirector.instance != (Object)null)
			{
				return EventDirector.instance.Network_powerRestoreAtNetTime > 0.0;
			}
			return false;
		}
	}

	internal static bool EligibleType(WorldEvent e)
	{
		if (!(e is BeetleSwarmEvent) && !(e is TentacleEvent) && !(e is PowerCutEvent))
		{
			if (e is EyeballEvent || e is MagneticFieldEvent)
			{
				return e.ShakeConsequence;
			}
			return false;
		}
		return true;
	}

	internal static void Clear()
	{
		RestoreSeconds = -1f;
		NextOutageLength = 180f;
		ResumingOutage = false;
		EmergencyLanterns.Clear();
		lastEvent = null;
		nextCheck = 0f;
		RestoreLights();
	}

	internal static void Tick(EventDirector director)
	{
		if (!Run.Active || !((NetworkBehaviour)director).isServer || SaveManager.LoadInProgress)
		{
			return;
		}
		if (RestoreSeconds >= 0f)
		{
			float restoreSeconds = RestoreSeconds;
			RestoreSeconds = -1f;
			if (PowerOut)
			{
				foreach (WorldEvent @event in director.Events)
				{
					if (@event is PowerCutEvent)
					{
						director.ServerEnd(@event);
					}
				}
			}
			if (restoreSeconds > 0.05f)
			{
				ResumeOutage(director, restoreSeconds);
			}
		}
		if (Time.time < nextCheck || !IncrementalScene.WorkHudShown || IncrementalEggSwap.ServerSwapping || IncrementalEggSwap.ServerEggComing || director.RunningCount > 0 || director.ServerAnnouncing || (Object)(object)EggProgress.Instance == (Object)null || EggProgress.Instance.Finished || (Object)(object)AgitationManager.instance == (Object)null || !AgitationManager.instance.IsFull)
		{
			return;
		}
		nextCheck = Time.time + 1f;
		List<WorldEvent> list = director.Events.Where((WorldEvent e) => (Object)(object)e != (Object)null && EligibleType(e) && ((Behaviour)e).isActiveAndEnabled && e.ServerCanRun() && GameManager.PlayerCount >= e.MinPlayers && (Object)(object)director.ServerBlockedBy(e) == (Object)null).ToList();
		if (list.Count > 1 && list.Any((WorldEvent e) => ((object)e).GetType() != lastEvent))
		{
			list.RemoveAll((WorldEvent e) => ((object)e).GetType() == lastEvent);
		}
		if (list.Count != 0)
		{
			WorldEvent val = list[Random.Range(0, list.Count)];
			lastEvent = ((object)val).GetType();
			director.ServerForceRun(val, true);
		}
	}

	private static void ResumeOutage(EventDirector director, float seconds)
	{
		for (int i = 0; i < director.Events.Count; i++)
		{
			if (director.Events[i] is PowerCutEvent)
			{
				Type parameterType = beginNow.GetParameters()[0].ParameterType;
				object obj = Activator.CreateInstance(parameterType);
				parameterType.GetField("index").SetValue(obj, i);
				parameterType.GetField("fromHeat").SetValue(obj, true);
				parameterType.GetField("forced").SetValue(obj, true);
				NextOutageLength = seconds;
				ResumingOutage = true;
				try
				{
					beginNow.Invoke(director, new object[1] { obj });
					break;
				}
				finally
				{
					ResumingOutage = false;
					NextOutageLength = 180f;
				}
			}
		}
	}

	internal static void BeforeCarry()
	{
		if (!Run.Active || !NetworkServer.active)
		{
			return;
		}
		EventDirector instance = EventDirector.instance;
		if ((Object)(object)instance != (Object)null)
		{
			cancelLead.Invoke(instance, null);
			foreach (WorldEvent @event in instance.Events)
			{
				if ((Object)(object)@event != (Object)null && !(@event is PowerCutEvent) && EligibleType(@event))
				{
					instance.ServerEnd(@event);
				}
				EyeballEvent val = (EyeballEvent)(object)((@event is EyeballEvent) ? @event : null);
				if (val != null && (Object)(object)val != (Object)null)
				{
					object? value = eyeHealPump.GetValue(val);
					Coroutine val2 = (Coroutine)((value is Coroutine) ? value : null);
					if (val2 != null)
					{
						((MonoBehaviour)val).StopCoroutine(val2);
					}
					eyeHealPump.SetValue(val, null);
					clearEyeHeals.Invoke(eyeHealQueue.GetValue(val), null);
				}
			}
		}
		Beetle[] array = Object.FindObjectsByType<Beetle>((FindObjectsSortMode)0);
		foreach (Beetle val3 in array)
		{
			if (((NetworkBehaviour)val3).isServer)
			{
				NetworkServer.Destroy(((Component)val3).gameObject);
			}
		}
		CreatureWarningDirector instance2 = CreatureWarningDirector.instance;
		if (instance2 != null)
		{
			instance2.ServerCancelWarning();
		}
	}

	internal static void NewEgg()
	{
		if (Run.Active && NetworkServer.active)
		{
			AgitationManager instance = AgitationManager.instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.ServerClearHeat();
				gridReady.SetValue(instance, false);
			}
			CreatureWarningDirector instance2 = CreatureWarningDirector.instance;
			if (instance2 != null)
			{
				instance2.ServerCancelWarning();
			}
			CreatureWarningDirector instance3 = CreatureWarningDirector.instance;
			if (instance3 != null)
			{
				instance3.ServerResetCycle();
			}
			nextCheck = Time.time + 1f;
		}
	}

	internal static void CutLights(Scene scene)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		RestoreLights();
		foreach (Light item in Members.InScene<IncrementalBakeLight>(scene).SelectMany((IncrementalBakeLight b) => ((Component)b).GetComponentsInChildren<Light>(true)).Distinct())
		{
			if (((Behaviour)item).enabled)
			{
				cutLamps.Add(item);
				((Behaviour)item).enabled = false;
			}
		}
	}

	internal static void RestoreLights()
	{
		foreach (Light cutLamp in cutLamps)
		{
			if ((Object)(object)cutLamp != (Object)null)
			{
				((Behaviour)cutLamp).enabled = true;
			}
		}
		cutLamps.Clear();
	}
}
[HarmonyPatch(typeof(EventDirector), "Update")]
internal static class IncrementalHeatClock
{
	private static void Postfix(EventDirector __instance)
	{
		Hazards.Tick(__instance);
	}
}
[HarmonyPatch(typeof(EventDirector), "ServerPlanDay")]
internal static class NoStorySchedule
{
	private static bool Prefix()
	{
		return !Run.Active;
	}
}
[HarmonyPatch(typeof(EventDirector), "ServerTryHeatEvent")]
internal static class UseRoomEvents
{
	private static bool Prefix()
	{
		return !Run.Active;
	}
}
[HarmonyPatch(typeof(EventDirector), "InEventHours")]
internal static class WorkClock
{
	private static bool Prefix(ref bool __result)
	{
		if (!Run.Active)
		{
			return true;
		}
		__result = IncrementalScene.WorkStarted;
		return false;
	}
}
[HarmonyPatch(typeof(EventDirector), "ServerForceRun")]
internal static class AccessibleEvents
{
	private static bool Prefix(WorldEvent evt)
	{
		if (Run.Active)
		{
			return Hazards.EligibleType(evt);
		}
		return true;
	}
}
[HarmonyPatch(typeof(IncrementalEggSwap), "ServerCarryOutThenSwap")]
internal static class EggLeaving
{
	private static void Prefix()
	{
		Hazards.BeforeCarry();
	}
}
[HarmonyPatch(typeof(IncrementalEggSwap), "Update")]
internal static class WaitForHealing
{
	private static bool Prefix(EggTerrainSync ____terrainSync)
	{
		if (!Run.Active || !NetworkServer.active || (Object)(object)EggProgress.Instance == (Object)null || !EggProgress.Instance.Finished)
		{
			return true;
		}
		if ((Object)(object)____terrainSync == (Object)null || !____terrainSync.ServerHealBusy)
		{
			if (!((Object)(object)EggHealDirector.instance == (Object)null))
			{
				return !EggHealDirector.instance.IsHealing;
			}
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(WorldEvent), "ServerCloseHotSpots")]
internal static class NoHealingAtCompletion
{
	private static bool Prefix()
	{
		if (Run.Active)
		{
			if (((Object)(object)EggProgress.Instance == (Object)null || !EggProgress.Instance.Finished) && !Hazards.ResumingOutage)
			{
				return !IncrementalEggSwap.ServerEggComing;
			}
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "ApplyForSwap")]
internal static class EggHeatReset
{
	private static void Postfix(bool __result)
	{
		if (__result)
		{
			Hazards.NewEgg();
		}
	}
}
[HarmonyPatch(typeof(AgitationManager), "Update")]
internal static class HoldHeatGrid
{
	private static bool Prefix()
	{
		if (Run.Active)
		{
			return !IncrementalEggSwap.ServerEggComing;
		}
		return true;
	}
}
[HarmonyPatch(typeof(AgitationManager), "AddActivity")]
internal static class QuietDelivery
{
	private static bool Prefix()
	{
		if (Run.Active)
		{
			return !IncrementalEggSwap.ServerEggComing;
		}
		return true;
	}
}
[HarmonyPatch(typeof(PowerCutEvent), "OnServerBegin")]
internal static class OutageLength
{
	private static void Prefix(ref float ___shakeOutageSeconds)
	{
		if (Run.Active)
		{
			___shakeOutageSeconds = Hazards.NextOutageLength;
			if (!Hazards.ResumingOutage)
			{
				EmergencyLanterns.Issued = false;
			}
		}
	}
}
[HarmonyPatch(typeof(WorldEvent), "ServerBegin")]
internal static class UseTimedBlackout
{
	private static void Prefix(WorldEvent __instance, ref bool fromShake)
	{
		if (Run.Active && __instance is PowerCutEvent)
		{
			fromShake = true;
		}
	}
}
[HarmonyPatch(typeof(PowerCutEvent), "ServerShakeOutage")]
internal static class OutageTimer
{
	private static bool Prefix(PowerCutEvent __instance, ref IEnumerator __result, float ___shakeOutageSeconds, int ___maxLanterns)
	{
		if (!Run.Active)
		{
			return true;
		}
		__result = UntilRestored(__instance, GameTime.Now + (double)___shakeOutageSeconds, ___maxLanterns);
		return false;
	}

	private static IEnumerator UntilRestored(PowerCutEvent outage, double deadline, int lanternLimit)
	{
		double retryAt = GameTime.Now + 5.0;
		while (GameTime.Now < deadline)
		{
			if (!EmergencyLanterns.Issued && GameTime.Now >= retryAt && !SaveManager.LoadInProgress)
			{
				retryAt = GameTime.Now + 5.0;
				EmergencyLanterns.Supply(lanternLimit);
			}
			yield return null;
		}
		if ((Object)(object)EventDirector.instance != (Object)null)
		{
			EventDirector.instance.ServerEnd((WorldEvent)(object)outage);
		}
	}
}
[HarmonyPatch(typeof(PowerCutEvent), "OnEventStarted")]
internal static class LabBlackout
{
	private static void Postfix(PowerCutEvent __instance)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (Run.Active)
		{
			Hazards.CutLights(((Component)__instance).gameObject.scene);
		}
	}
}
[HarmonyPatch(typeof(PowerCutEvent), "OnEventStopped")]
internal static class LabPowerRestored
{
	private static void Postfix()
	{
		if (Run.Active)
		{
			Hazards.RestoreLights();
		}
	}
}
[HarmonyPatch(typeof(PowerCutController), "Start")]
internal static class KeepBlackoutOnStartup
{
	private static void Prefix(PowerCutController __instance, out PowerCutReason __state)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		__state = (PowerCutReason)(Run.Active ? ((int)__instance.Reasons) : 0);
		if (((uint)__state & 1u) != 0)
		{
			Hazards.RestoreLights();
		}
	}

	private static void Postfix(PowerCutController __instance, PowerCutReason __state)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__state != 0)
		{
			__instance.SetReason(__state, true);
			if ((__state & 1) != 0)
			{
				Hazards.CutLights(((Component)__instance).gameObject.scene);
			}
		}
	}
}
[HarmonyPatch(typeof(MiningRig), "Update")]
internal static class RigPower
{
	private static readonly Action<MiningRig> stop = (Action<MiningRig>)Delegate.CreateDelegate(typeof(Action<MiningRig>), Members.Method<MiningRig>("StopLoops"));

	private static bool Prefix(MiningRig __instance)
	{
		if (!Hazards.PowerOut || !__instance.IsPlanted)
		{
			return true;
		}
		stop(__instance);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalCollector), "ServerUpdate")]
internal static class RobotPower
{
	private static bool Prefix(CollectorDriver ____driver)
	{
		if (!Hazards.PowerOut)
		{
			return true;
		}
		____driver.Freeze();
		return false;
	}
}
[HarmonyPatch(typeof(CollectorDepot), "ServerTick")]
internal static class DepotPower
{
	private static bool Prefix(ref float ____phaseEnds, ref float ____fillFrom, ref float ____claimedAt, ref float ____nextSell)
	{
		if (!Hazards.PowerOut)
		{
			return true;
		}
		float deltaTime = Time.deltaTime;
		____phaseEnds += deltaTime;
		____fillFrom += deltaTime;
		____claimedAt += deltaTime;
		____nextSell += deltaTime;
		return false;
	}
}
internal static class Lab
{
	private static readonly HashSet<GameObject> keep = new HashSet<GameObject>();

	private static readonly FieldInfo station = Members.Field<CreatureWarningDirector>("calmingStation");

	internal static void BeforeSetup(Scene scene)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0077: 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_0083: 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_008f: 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_00b8: Expected O, but got Unknown
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		keep.Clear();
		if (GameMode.IsIncremental && NetworkServer.active && !Run.Configured)
		{
			int selectedSlot = SaveSlots.SelectedSlot;
			IncrementalEgg.ResolveForHost(selectedSlot, !SaveSlots.SlotExists(selectedSlot), 0);
		}
		if (!Run.Active)
		{
			return;
		}
		KeepScene<AgitationManager>(scene);
		KeepScene<CreatureWarningDirector>(scene);
		KeepScene<EventDirector>(scene);
		KeepScene<EggShakeEvent>(scene);
		KeepScene<DangerApp>(scene);
		KeepScene<DangerHeatmap>(scene);
		KeepScene<EggScanDisplay>(scene);
		KeepScene<BeetleSwarmEvent>(scene);
		KeepScene<TentacleEvent>(scene);
		KeepScene<PowerCutEvent>(scene);
		KeepScene<EyeballEvent>(scene);
		KeepScene<MagneticFieldEvent>(scene);
		KeepScene<PowerCutController>(scene);
		KeepScene<PowerOutageUI>(scene);
		foreach (CreatureWarningDirector item in Members.InScene<CreatureWarningDirector>(scene))
		{
			Terminal val = (Terminal)station.GetValue(item);
			if (val == null)
			{
				continue;
			}
			Keep((Component)(object)val.station);
			Keep((Component)(object)val.waypoint);
			Keep((Component)(object)val.alarm);
			if (!((Object)(object)val.station != (Object)null))
			{
				continue;
			}
			Type type = typeof(ComputerStation);
			while (type != typeof(NetworkBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (fieldInfo.IsDefined(typeof(SerializeField), inherit: true))
					{
						object? value = fieldInfo.GetValue(val.station);
						Component val2 = (Component)((value is Component) ? value : null);
						if (val2 != null && val2.gameObject.scene == scene && !(val2 is ShopDispenser))
						{
							Keep(val2);
						}
						GameObject val3 = (GameObject)((value is GameObject) ? value : null);
						if (val3 != null && val3.scene == scene)
						{
							Keep((Component)(object)val3.transform);
						}
					}
				}
				type = type.BaseType;
			}
		}
	}

	private static void KeepScene<T>(Scene scene) where T : Component
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		foreach (T item in Members.InScene<T>(scene))
		{
			Keep((Component)(object)item);
		}
	}

	private static void Keep(Component component)
	{
		if (!((Object)(object)component == (Object)null))
		{
			Transform val = component.transform;
			while ((Object)(object)val != (Object)null)
			{
				keep.Add(((Component)val).gameObject);
				val = val.parent;
			}
		}
	}

	internal static void Filter(Type type, List<Component> found)
	{
		if (Run.Active && keep.Count != 0 && !(type == typeof(LabWallSection)))
		{
			found.RemoveAll((Component c) => (Object)(object)c != (Object)null && keep.Contains(c.gameObject));
		}
	}

	internal static void Done()
	{
		keep.Clear();
	}

	internal static bool SetUpDisplays(Scene scene)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected O, but got Unknown
		if (!Run.Active)
		{
			return false;
		}
		DangerApp[] array = (from app in Members.InScene<DangerApp>(scene)
			orderby ((Behaviour)app).isActiveAndEnabled descending
			select app).ToArray();
		if (array.Length == 0)
		{
			Plugin.Log.LogError((object)"No danger board in the incremental room.");
			return false;
		}
		RectTransform val = Resources.Load<RectTransform>("Incremental/PF_App_Survey");
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		if (array.Length == 1)
		{
			RectTransform board = (RectTransform)((Component)array[0]).transform;
			Transform[] array2 = (from i in Enumerable.Range(0, ((Transform)board).childCount)
				select ((Transform)board).GetChild(i)).ToArray();
			RectTransform val2 = Panel(board, "Agitation", -0.25f);
			Transform[] array3 = array2;
			for (int num = 0; num < array3.Length; num++)
			{
				array3[num].SetParent((Transform)(object)val2, false);
			}
			RectTransform val3 = Panel(board, "Survey", 0.25f);
			Fill(Object.Instantiate<RectTransform>(val, (Transform)(object)val3, false));
		}
		else
		{
			foreach (DangerApp item in array.Skip(1))
			{
				((Behaviour)item).enabled = false;
				RectTransform val4 = (RectTransform)((Component)item).transform;
				for (int num2 = 0; num2 < ((Transform)val4).childCount; num2++)
				{
					((Component)((Transform)val4).GetChild(num2)).gameObject.SetActive(false);
				}
				Fill(Object.Instantiate<RectTransform>(val, (Transform)(object)val4, false));
			}
		}
		return true;
	}

	private static RectTransform Panel(RectTransform parent, string name, float offset)
	{
		//IL_0014: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0031: 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_0033: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0069: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
		((Transform)val).SetParent((Transform)(object)parent, false);
		Fill(val);
		val.anchorMin += new Vector2(offset, 0f);
		val.anchorMax += new Vector2(offset, 0f);
		((Transform)val).localScale = Vector3.one * 0.5f;
		return val;
	}

	private static void Fill(RectTransform rect)
	{
		//IL_0001: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		rect.anchorMin = Vector2.zero;
		rect.anchorMax = Vector2.one;
		Vector2 offsetMin = (rect.offsetMax = Vector2.zero);
		rect.offsetMin = offsetMin;
	}
}
[HarmonyPatch(typeof(ModeSetup), "Apply")]
internal static class ProtectScene
{
	private static void Prefix(Scene scene)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		Lab.BeforeSetup(scene);
	}

	private static void Finalizer()
	{
		Lab.Done();
	}
}
[HarmonyPatch(typeof(ModeSetup), "Find")]
internal static class PreserveSelectedObjects
{
	private static void Postfix(Type type, List<Component> __result)
	{
		Lab.Filter(type, __result);
	}
}
[HarmonyPatch(typeof(IncrementalScene), "SwapDangerBoards")]
internal static class WallBoards
{
	private static bool Prefix(Scene scene)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		return !Lab.SetUpDisplays(scene);
	}
}
[HarmonyPatch(typeof(IncrementalScene), "SwitchOffStoryHud")]
internal static class OutageCard
{
	private static void Postfix(Scene scene)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (!Run.Active)
		{
			return;
		}
		foreach (PowerOutageUI item in Members.InScene<PowerOutageUI>(scene))
		{
			((Component)item).gameObject.SetActive(true);
		}
	}
}
internal static class EmergencyLanterns
{
	internal const string DeliveryKey = "crack.endlesscontainment.outage-lantern";

	private static readonly FieldInfo lanternItem = Members.Field<PowerCutEvent>("lanternItem");

	private static Flashlight prefab;

	private static uint assetId;

	private static string orderKey;

	private static bool reportedFailure;

	internal static bool Issued;

	internal static void Clear()
	{
		prefab = null;
		assetId = 0u;
		orderKey = null;
		reportedFailure = false;
		Issued = false;
	}

	internal static void Register(Scene scene)
	{
		//IL_0000: 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_002f: Expected O, but got Unknown
		Flashlight light = default(Flashlight);
		NetworkIdentity val2 = default(NetworkIdentity);
		foreach (PowerCutEvent item in Members.InScene<PowerCutEvent>(scene))
		{
			ShopItemData val = (ShopItemData)lanternItem.GetValue(item);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.spawnPrefab == (Object)null) && val.spawnPrefab.TryGetComponent<Flashlight>(ref light) && val.spawnPrefab.TryGetComponent<NetworkIdentity>(ref val2) && val2.assetId != 0)
			{
				prefab = light;
				assetId = val2.assetId;
				IncrementalTools instance = IncrementalTools.Instance;
				Tier val3 = ((instance == null) ? null : ((IEnumerable<Tier>)instance.List?.tiers).FirstOrDefault((Func<Tier, bool>)((Tier t) => t != null && (Object)(object)t.prefab == (Object)(object)light)));
				orderKey = (string.IsNullOrEmpty(val3?.key) ? "crack.endlesscontainment.outage-lantern" : val3.key);
				if (!NetworkClient.prefabs.ContainsKey(val2.assetId))
				{
					NetworkClient.RegisterPrefab(val.spawnPrefab);
				}
				return;
			}
		}
		Plugin.Log.LogWarning((object)"No network lantern prefab was found on the room's power-cut event.");
	}

	internal static int Supply(int limit)
	{
		if (Issued || !NetworkServer.active || (Object)(object)prefab == (Object)null || (Object)(object)ShopDelivery.Instance == (Object)null)
		{
			return 0;
		}
		try
		{
			int usable = ItemRestSync.ServerItems.Count(delegate(HeldItem item)
			{
				Flashlight val = (Flashlight)(object)((item is Flashlight) ? item : null);
				return val != null && (Object)(object)val != (Object)null && ((NetworkBehaviour)val).netIdentity.assetId == assetId && !((HeldItem)val).IsBroken;
			});
			int result = OrderMissing(GameManager.PlayerCount, limit, usable, ShopDelivery.Collect(), orderKey, (Action<Order>)ShopDelivery.ServerOrder);
			reportedFailure = false;
			return result;
		}
		catch (Exception ex)
		{
			if (!reportedFailure)
			{
				Plugin.Log.LogWarning((object)("Emergency lantern delivery will retry: " + ex.Message));
			}
			reportedFailure = true;
			return 0;
		}
	}

	internal static int OrderMissing(int crew, int limit, int usable, SaveData[] deliveries, string key, Action<Order> submit)
	{
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Expected O, but got Unknown
		if (Issued)
		{
			return 0;
		}
		int num = Math.Max(1, Math.Min(crew, limit));
		int num2 = usable;
		SaveData[] array = deliveries ?? Array.Empty<SaveData>();
		foreach (SaveData val in array)
		{
			if (val == null || val.kind != 0)
			{
				continue;
			}
			if (val.key == key || val.key == "crack.endlesscontainment.outage-lantern")
			{
				num2++;
			}
			if (val.more != null)
			{
				num2 += val.more.Count((string k) => k == key || k == "crack.endlesscontainment.outage-lantern");
			}
		}
		int num3 = Math.Max(0, num - num2);
		for (int num4 = 0; num4 < num3; num4++)
		{
			submit(new Order
			{
				kind = (Kind)0,
				key = key,
				rush = true,
				paidCents = 0
			});
		}
		Issued = true;
		return num3;
	}

	internal static bool Unbox(Vector3 position, Quaternion facing)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || (Object)(object)prefab == (Object)null)
		{
			return false;
		}
		Flashlight val = Object.Instantiate<Flashlight>(prefab, position + Vector3.up * 0.3f, facing);
		NetworkServer.Spawn(((Component)val).gameObject, (NetworkConnectionToClient)null);
		if (((NetworkBehaviour)val).netId != 0)
		{
			return true;
		}
		Object.Destroy((Object)(object)((Component)val).gameObject);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalTools), "Create")]
internal static class RegisterOutageLantern
{
	private static void Postfix(Scene scene)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (Run.Active)
		{
			EmergencyLanterns.Register(scene);
		}
	}
}
[HarmonyPatch(typeof(PowerCutEvent), "ServerDispenseLanterns")]
internal static class DeliverOutageLanterns
{
	private static bool Prefix(int ___maxLanterns, ref int __result)
	{
		if (!Run.Active)
		{
			return true;
		}
		__result = EmergencyLanterns.Supply(___maxLanterns);
		return false;
	}
}
[HarmonyPatch(typeof(IncrementalTools), "ServerSpawnDelivered")]
internal static class UnboxOutageLantern
{
	private static bool Prefix(string key, Vector3 at, Quaternion facing, ref bool __result)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		if (!Run.Active || key != "crack.endlesscontainment.outage-lantern")
		{
			return true;
		}
		__result = EmergencyLanterns.Unbox(at, facing);
		return false;
	}
}
internal struct LayoutRandom
{
	private uint state;

	internal LayoutRandom(int seed, int number)
	{
		state = (uint)(seed ^ (-1640531527 * (number + 1)));
	}

	private uint Next()
	{
		uint num = (state += 2654435769u);
		int num2 = (int)(num ^ (num >> 16)) * -2048144789;
		int num3 = (num2 ^ (num2 >>> 13)) * -1028477387;
		return (uint)(num3 ^ (num3 >>> 16));
	}

	internal int Index(int count)
	{
		if (count < 1)
		{
			throw new ArgumentOutOfRangeException("count");
		}
		return (int)(Next() % (uint)count);
	}

	internal float Between(float lo, float hi)
	{
		return lo + (hi - lo) * ((float)(Next() >> 8) * 5.9604645E-08f);
	}
}
internal struct Layout
{
	internal int SizeIndex;

	internal int LookIndex;

	internal float Core;

	internal float PlatingStart;

	internal float MembraneStart;

	internal float InnerTissueStart;

	internal float Richness;

	internal static Layout Roll(int seed, int number, int templates)
	{
		LayoutRandom layoutRandom = new LayoutRandom(seed, number);
		Layout result = default(Layout);
		result.SizeIndex = layoutRandom.Index(templates);
		result.LookIndex = layoutRandom.Index(templates);
		result.Core = layoutRandom.Between(0.1f, 0.2f);
		result.PlatingStart = layoutRandom.Between(0.3f, 0.53f);
		result.MembraneStart = result.PlatingStart + layoutRandom.Between(0.075f, 0.12f);
		result.InnerTissueStart = result.MembraneStart + layoutRandom.Between(0.065f, 0.1f);
		result.Richness = layoutRandom.Between(0.8f, 1.25f);
		return result;
	}
}
[BepInPlugin("crack.endlesscontainment", "Endless Containment", "1.0.2")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Id = "crack.endlesscontainment";

	public const string Version = "1.0.2";

	internal static ManualLogSource Log;

	private Harmony patches;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		patches = new Harmony("crack.endlesscontainment");
		try
		{
			patches.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Endless Containment 1.0.2 loaded.");
		}
		catch
		{
			patches.UnpatchSelf();
			throw;
		}
	}
}
internal static class Members
{
	internal static FieldInfo Field<T>(string name)
	{
		return AccessTools.Field(typeof(T), name) ?? throw new MissingFieldException(typeof(T).FullName, name);
	}

	internal static MethodInfo Method<T>(string name)
	{
		return AccessTools.Method(typeof(T), name, (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(T).FullName, name);
	}

	internal static IEnumerable<T> InScene<T>(Scene scene) where T : Component
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
		foreach (GameObject val in rootGameObjects)
		{
			T[] componentsInChildren = val.GetComponentsInChildren<T>(true);
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				yield return componentsInChildren[j];
			}
		}
	}
}
[Serializable]
public sealed class ContainmentSave : IncrementalWorldSaveData
{
	public int containmentSchema;

	public int containmentSeed;

	public int containmentFirstEgg;

	public float containmentPowerSeconds;

	public bool containmentOutageLanternsIssued;
}
[Serializable]
internal sealed class LayoutHeader
{
	public int containmentSchema;

	public int containmentSeed;

	public int containmentFirstEgg;
}
internal static class Run
{
	internal const int Schema = 1;

	private const uint Magic = 826494533u;

	internal static int Seed { get; private set; }

	internal static int FirstEgg { get; private set; }

	internal static bool Configured { get; private set; }

	internal static bool Active
	{
		get
		{
			if (Configured)
			{
				return GameMode.IsIncremental;
			}
			return false;
		}
	}

	internal static bool Current => Generated(IncrementalEgg.Number);

	internal static bool Generated(int number)
	{
		if (Active)
		{
			return number >= FirstEgg;
		}
		return false;
	}

	internal static void Set(int seed, int first)
	{
		Seed = seed;
		FirstEgg = first;
		Configured = true;
	}

	internal static void Clear()
	{
		Configured = false;
		Eggs.Clear();
		Hazards.Clear();
		Protocol.Verified.Clear();
	}

	internal static void Select(int slot, bool newGame)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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)
		Clear();
		if (!GameMode.IsIncremental)
		{
			return;
		}
		if (!newGame)
		{
			ContinueRead val = SaveSlots.ReadForContinue(slot);
			if (val.ok)
			{
				LayoutHeader layoutHeader = JsonUtility.FromJson<LayoutHeader>(val.json);
				if (layoutHeader != null && layoutHeader.containmentSchema == 1)
				{
					Set(layoutHeader.containmentSeed, layoutHeader.containmentFirstEgg);
					return;
				}
				if (layoutHeader != null && layoutHeader.containmentSchema != 0)
				{
					throw new InvalidDataException("This save needs a different Endless Containment version.");
				}
			}
		}
		Set(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0), (!newGame) ? checked(IncrementalEgg.Number + 1) : 0);
	}

	internal static void WriteHeader(NetworkWriter writer, ModeMessage value)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		Protocol.BaseWrite(writer, value);
		if ((int)value.mode == 1 && Configured)
		{
			NetworkWriterExtensions.WriteUInt(writer, 826494533u);
			NetworkWriterExtensions.WriteInt(writer, 1);
			NetworkWriterExtensions.WriteInt(writer, Seed);
			NetworkWriterExtensions.WriteInt(writer, FirstEgg);
		}
	}

	internal static ModeMessage ReadHeader(NetworkReader reader)
	{
		//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_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_0013: Invalid comparison between Unknown and I4
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		ModeMessage val = Protocol.BaseRead(reader);
		if ((int)val.mode != 1 || reader.Remaining == 0)
		{
			if (!NetworkServer.active)
			{
				Configured = false;
			}
			return val;
		}
		if (reader.Remaining < 16 || NetworkReaderExtensions.ReadUInt(reader) != 826494533 || NetworkReaderExtensions.ReadInt(reader) != 1)
		{
			throw new InvalidDataException("Incompatible Endless Containment recipe protocol.");
		}
		int seed = NetworkReaderExtensions.ReadInt(reader);
		int num = NetworkReaderExtensions.ReadInt(reader);
		if (num < 0)
		{
			throw new InvalidDataException("Invalid first procedural egg.");
		}
		Set(seed, num);
		return val;
	}
}
internal static class Protocol
{
	internal struct Ready : NetworkMessage
	{
		public int version;
	}

	internal const int PeerVersion = 3;

	internal static readonly HashSet<NetworkConnectionToClient> Verified = new HashSet<NetworkConnectionToClient>();

	internal static Action<NetworkWriter, ModeMessage> BaseWrite;

	internal static Func<NetworkReader, ModeMessage> BaseRead;

	internal static void Install()
	{
		if (Writer<ModeMessage>.write != new Action<NetworkWriter, ModeMessage>(Run.WriteHeader))
		{
			BaseWrite = Writer<ModeMessage>.write ?? throw new InvalidOperationException("Missing game-mode writer.");
			Writer<ModeMessage>.write = Run.WriteHeader;
		}
		if (Reader<ModeMessage>.read != new Func<NetworkReader, ModeMessage>(Run.ReadHeader))
		{
			BaseRead = Reader<ModeMessage>.read ?? throw new InvalidOperationException("Missing game-mode reader.");
			Reader<ModeMessage>.read = Run.ReadHeader;
		}
		Writer<Ready>.write = delegate(NetworkWriter w, Ready m)
		{
			NetworkWriterExtensions.WriteInt(w, m.version);
		};
		Reader<Ready>.read = (NetworkReader r) => new Ready
		{
			version = NetworkReaderExtensions.ReadInt(r)
		};
	}
}
[HarmonyPatch(typeof(IncrementalEgg), "ResolveForHost")]
internal static class SlotPatch
{
	private static void Postfix(int slot, bool newGame)
	{
		Run.Select(slot, newGame);
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnStartServer")]
internal static class ServerStart
{
	private static void Postfix()
	{
		if (GameMode.IsIncremental && !Run.Configured)
		{
			IncrementalEgg.ResolveForHost(SaveSlots.SelectedSlot, !SaveSlots.SlotExists(SaveSlots.SelectedSlot), 0);
		}
		Protocol.Install();
		NetworkServer.RegisterHandler<Protocol.Ready>((Action<NetworkConnectionToClient, Protocol.Ready>)delegate(NetworkConnectionToClient conn, Protocol.Ready m)
		{
			if (m.version == 3)
			{
				Protocol.Verified.Add(conn);
			}
		}, true);
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnStartClient")]
internal static class ClientStart
{
	private static void Postfix()
	{
		Protocol.Install();
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnClientConnect")]
internal static class ClientHello
{
	private static void Prefix()
	{
		if (Run.Active && !NetworkServer.active)
		{
			NetworkClient.Send<Protocol.Ready>(new Protocol.Ready
			{
				version = 3
			}, 0);
		}
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnServerReady")]
internal static class CheckRecipeVersion
{
	private static bool Prefix(NetworkConnectionToClient conn)
	{
		if (!Run.Active || (object)conn == NetworkServer.localConnection || Protocol.Verified.Contains(conn))
		{
			return true;
		}
		Plugin.Log.LogWarning((object)"A crew member needs the same Endless Containment mod to load this egg.");
		((NetworkConnection)conn).Disconnect();
		return false;
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnServerDisconnect")]
internal static class ForgetPeer
{
	private static void Postfix(NetworkConnectionToClient conn)
	{
		Protocol.Verified.Remove(conn);
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnStopClient")]
internal static class SessionEndClient
{
	private static void Postfix()
	{
		if (!NetworkServer.active)
		{
			Run.Clear();
		}
	}
}
[HarmonyPatch(typeof(MyNetworkManager), "OnStopServer")]
internal static class SessionEndServer
{
	private static void Postfix()
	{
		Run.Clear();
	}
}
[HarmonyPatch(typeof(SaveManager), "CollectWorld")]
internal static class SaveClass
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> input)
	{
		ConstructorInfo ctor = typeof(IncrementalWorldSaveData).GetConstructor(Type.EmptyTypes);
		int found = 0;
		foreach (CodeInstruction item in input)
		{
			if (item.opcode == OpCodes.Newobj && object.Equals(item.operand, ctor))
			{
				item.operand = typeof(ContainmentSave).GetConstructor(Type.EmptyTypes);
				found++;
			}
			yield return item;
		}
		if (found != 1)
		{
			throw new MissingMethodException("Unexpected incremental save constructor in CollectWorld.");
		}
	}
}
[HarmonyPatch(typeof(SaveManager), "ParseWorld")]
internal static class ReadSaveClass
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> input)
	{
		int found = 0;
		foreach (CodeInstruction item in input)
		{
			if (item.operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(JsonUtility) && methodInfo.Name == "FromJson" && methodInfo.IsGenericMethod && methodInfo.GetGenericArguments()[0] == typeof(IncrementalWorldSaveData))
			{
				item.operand = methodInfo.GetGenericMethodDefinition().MakeGenericMethod(typeof(ContainmentSave));
				found++;
			}
			yield return item;
		}
		if (found != 1)
		{
			throw new MissingMethodException("Unexpected incremental save reader in ParseWorld.");
		}
	}
}
[HarmonyPatch(typeof(IncrementalSave), "Collect")]
internal static class SaveLayout
{
	private static void Postfix(IncrementalWorldSaveData data)
	{
		if (Run.Active && data is ContainmentSave containmentSave)
		{
			containmentSave.containmentSchema = 1;
			containmentSave.containmentSeed = Run.Seed;
			containmentSave.containmentFirstEgg = Run.FirstEgg;
			containmentSave.containmentPowerSeconds = Hazards.Remaining;
			containmentSave.containmentOutageLanternsIssued = containmentSave.containmentPowerSeconds > 0f && EmergencyLanterns.Issued;
		}
	}
}
[HarmonyPatch(typeof(IncrementalSave), "Apply")]
internal static class LoadBlackout
{
	private static void Postfix(IncrementalWorldSaveData data)
	{
		if (Run.Active && NetworkServer.active)
		{
			ContainmentSave obj = data as ContainmentSave;
			Hazards.RestoreSeconds = Mathf.Clamp(obj?.containmentPowerSeconds ?? 0f, 0f, 180f);
			EmergencyLanterns.Issued = obj?.containmentOutageLanternsIssued ?? false;
		}
	}
}