Decompiled source of BikiniBottom v1.0.0

LethalMoon.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using DunGen;
using DunGen.Graph;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalMoon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+f95d6733ed7647fc24db95d1fa47f5f380ee1e8a")]
[assembly: AssemblyProduct("LethalMoon")]
[assembly: AssemblyTitle("LethalMoon")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace LethalMoon;

internal static class AutoLandingTest
{
	private static ManualLogSource log;

	private static string flagPath;

	private static AutoTestGate gate;

	private static string folder;

	public static void Enable(string pluginFolder, ManualLogSource logger)
	{
		//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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_0074: 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_00a9: Expected O, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		folder = pluginFolder;
		flagPath = Path.Combine(pluginFolder, "autotest.flag");
		if (File.Exists(flagPath))
		{
			gate = new AutoTestGate(armed: true);
			log = logger;
			Harmony val = new Harmony("com.lethalmoon.plugin.autotest");
			val.Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(AutoLandingTest), "OnStartOfRoundStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(typeof(PreInitSceneScript), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(AutoLandingTest), "OnLaunchScreen", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(typeof(MenuManager), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(AutoLandingTest), "OnMenu", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			log.LogWarning((object)"AUTOTEST armed");
		}
	}

	private static void OnLaunchScreen(PreInitSceneScript __instance)
	{
		((MonoBehaviour)__instance).StartCoroutine(ChooseLan(__instance));
	}

	private static IEnumerator ChooseLan(PreInitSceneScript screen)
	{
		yield return (object)new WaitForSeconds(5f);
		if (File.Exists(flagPath))
		{
			log.LogInfo((object)"AUTOTEST choosing LAN");
			screen.ChooseLaunchOption(false);
		}
	}

	private static void OnMenu(MenuManager __instance)
	{
		((MonoBehaviour)__instance).StartCoroutine(Host(__instance));
	}

	private static IEnumerator Host(MenuManager menu)
	{
		yield return (object)new WaitForSeconds(8f);
		if (File.Exists(flagPath) && !((Object)(object)menu.HostSettingsScreen == (Object)null) && !((Object)(object)GameNetworkManager.Instance == (Object)null))
		{
			menu.ClickHostButton();
			yield return (object)new WaitForSeconds(2f);
			menu.LAN_HostSetLocal();
			GameNetworkManager.Instance.currentSaveFileName = "LCSaveFile3";
			GameNetworkManager.Instance.saveFileNum = 2;
			yield return (object)new WaitForSeconds(1f);
			if (GameNetworkManager.Instance.currentSaveFileName != "LCSaveFile3")
			{
				log.LogError((object)"AUTOTEST fail: save file 3 not selected");
				yield break;
			}
			log.LogInfo((object)"AUTOTEST hosting on save file 3");
			menu.ConfirmHostButton();
		}
	}

	private static void OnStartOfRoundStart()
	{
		string text = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.currentSaveFileName);
		if (gate.TryStart(text))
		{
			((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Run());
		}
		else
		{
			log.LogWarning((object)("AUTOTEST standing down (save=" + text + ")"));
		}
	}

	private static IEnumerator Run()
	{
		yield return Round(1);
		if (StartOfRound.Instance.inShipPhase)
		{
			yield return (object)new WaitForSeconds(40f);
			yield return Round(2);
			LunarEclipse.Force = null;
			log.LogInfo((object)"AUTOTEST finished");
			Application.Quit();
		}
	}

	private static IEnumerator Round(int number)
	{
		log.LogInfo((object)$"AUTOTEST round {number}");
		yield return (object)new WaitForSeconds(20f);
		StartOfRound start = StartOfRound.Instance;
		if (!((NetworkBehaviour)start).IsServer)
		{
			log.LogWarning((object)"AUTOTEST skipped: not the host");
			yield break;
		}
		File.Delete(flagPath);
		TideRun.Force = number == 1;
		LunarEclipse.Force = number == 2;
		LunarEclipse.Decide();
		start.allowLocalPlayerDeath = false;
		SelectableLevel val = ((IEnumerable<SelectableLevel>)start.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => l.sceneName == "BrinebiteScene"));
		Terminal val2 = Object.FindObjectOfType<Terminal>();
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: level or terminal missing");
			yield break;
		}
		log.LogInfo((object)$"AUTOTEST routing to {val.PlanetName} id={val.levelID}");
		start.ChangeLevelServerRpc(val.levelID, val2.groupCredits);
		yield return (object)new WaitForSeconds(20f);
		StartMatchLever obj = Object.FindObjectOfType<StartMatchLever>();
		log.LogInfo((object)("AUTOTEST pulling lever, current=" + start.currentLevel.PlanetName));
		obj.LeverAnimation();
		obj.PullLever();
		PlayerControllerB rider = GameNetworkManager.Instance.localPlayerController;
		for (int waited = 0; waited < 180; waited++)
		{
			if (start.shipHasLanded)
			{
				break;
			}
			yield return (object)new WaitForSeconds(1f);
			log.LogInfo((object)$"AUTOTEST descent ship={start.elevatorTransform.position:F1} player={((Component)rider).transform.position:F1} dead={rider.isPlayerDead}");
			if (rider.isPlayerDead)
			{
				log.LogError((object)"AUTOTEST fail: player died during landing");
				yield break;
			}
		}
		if (!start.shipHasLanded)
		{
			log.LogError((object)"AUTOTEST fail: ship did not land within 180s");
			yield break;
		}
		yield return (object)new WaitForSeconds(10f);
		log.LogInfo((object)$"AUTOTEST landed ship={start.elevatorTransform.position:F2} player={((Component)rider).transform.position:F2} dead={rider.isPlayerDead}");
		LogInterior();
		float day = TimeOfDay.Instance.normalizedTimeOfDay;
		PlayerControllerB player = GameNetworkManager.Instance.localPlayerController;
		Vector3 val3 = default(Vector3);
		((Vector3)(ref val3))..ctor(-14f, 1.5f, -14.4f);
		player.isInHangarShipRoom = false;
		player.isInElevator = false;
		player.TeleportPlayer(val3, false, 0f, false, true);
		yield return (object)new WaitForSeconds(6f);
		log.LogInfo((object)$"AUTOTEST outside player={((Component)player).transform.position:F2} grounded={player.thisController.isGrounded} dead={player.isPlayerDead}");
		ScreenCapture.CaptureScreenshot(Path.Combine(folder, $"shot_outside_{number}.png"));
		yield return (object)new WaitForSeconds(5f);
		int id;
		for (id = 0; id < 2; id++)
		{
			EntranceTeleport[] source = (from e in Object.FindObjectsOfType<EntranceTeleport>()
				where e.entranceId == id
				select e).ToArray();
			EntranceTeleport val4 = ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => e.isEntranceToBuilding));
			EntranceTeleport insideDoor = ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => !e.isEntranceToBuilding));
			if ((Object)(object)val4 == (Object)null || (Object)(object)insideDoor == (Object)null)
			{
				log.LogError((object)$"AUTOTEST fail: entrance {id} outside={(Object)(object)val4 != (Object)null} inside={(Object)(object)insideDoor != (Object)null}");
				continue;
			}
			log.LogInfo((object)$"AUTOTEST entrance {id} spawned={((NetworkBehaviour)val4).IsSpawned} trigger={(Object)(object)((Component)val4).GetComponent<InteractTrigger>() != (Object)null}");
			((UnityEvent<PlayerControllerB>)(object)((Component)val4).GetComponent<InteractTrigger>().onInteract).Invoke(player);
			yield return (object)new WaitForSeconds(4f);
			log.LogInfo((object)$"AUTOTEST entrance {id} went in: player={((Component)player).transform.position:F1} insideFactory={player.isInsideFactory} dead={player.isPlayerDead} grounded={player.thisController.isGrounded} arrivedAt={insideDoor.entrancePoint.position:F1}");
			if (((Component)player).transform.position.y < insideDoor.entrancePoint.position.y - 5f)
			{
				log.LogError((object)$"AUTOTEST fail: fell out of the interior at entrance {id}");
			}
			log.LogInfo((object)$"AUTOTEST entrance {id} inside door at={((Component)insideDoor).transform.position:F2} facing={((Component)insideDoor).transform.eulerAngles:F0}");
			insideDoor.TeleportPlayer();
			yield return (object)new WaitForSeconds(4f);
			log.LogInfo((object)$"AUTOTEST entrance {id} came out: player={((Component)player).transform.position:F1} insideFactory={player.isInsideFactory} dead={player.isPlayerDead}");
		}
		if (number == 1)
		{
			yield return Photograph(player);
		}
		Reports(day);
		if (number == 1)
		{
			yield return Checks(player);
		}
		int num = Object.FindObjectsOfType<GrabbableObject>().Count((GrabbableObject g) => g.isInFactory && g.itemProperties.isScrap);
		log.LogInfo((object)$"AUTOTEST interior scrap={num} vents={Object.FindObjectsOfType<EnemyVent>().Length} enemies={RoundManager.Instance.SpawnedEnemies.Count}");
		Transform vaultTile = VaultAlarm.FindVault();
		log.LogInfo((object)$"AUTOTEST vault scrap={Object.FindObjectsOfType<GrabbableObject>().Count(delegate(GrabbableObject g)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (g.isInFactory && g.itemProperties.isScrap && (Object)(object)vaultTile != (Object)null)
			{
				Vector3 val5 = vaultTile.InverseTransformPoint(((Component)g).transform.position);
				return ((Vector3)(ref val5)).magnitude < 9f;
			}
			return false;
		})}");
		LogVentPaths();
		if (number == 2)
		{
			player.TeleportPlayer(start.middleOfShipNode.position, false, 0f, false, true);
			for (int waited = 0; waited < 240; waited += 10)
			{
				if (RoundManager.Instance.SpawnedEnemies.Count != 0)
				{
					break;
				}
				yield return (object)new WaitForSeconds(10f);
			}
			string arg = string.Join(",", RoundManager.Instance.SpawnedEnemies.Select((EnemyAI e) => e.enemyType.enemyName + (e.isOutside ? "(out)" : "(in)")));
			log.LogInfo((object)$"AUTOTEST enemies after waiting: {RoundManager.Instance.SpawnedEnemies.Count} [{arg}]");
		}
		player.TeleportPlayer(start.middleOfShipNode.position, false, 0f, false, true);
		player.isInHangarShipRoom = true;
		player.isInElevator = true;
		yield return (object)new WaitForSeconds(5f);
		log.LogInfo((object)"AUTOTEST leaving");
		StartMatchLever obj2 = Object.FindObjectOfType<StartMatchLever>();
		obj2.LeverAnimation();
		obj2.PullLever();
		for (int waited = 0; waited < 180; waited++)
		{
			if (start.inShipPhase)
			{
				break;
			}
			yield return (object)new WaitForSeconds(1f);
		}
		log.LogInfo((object)(start.inShipPhase ? "AUTOTEST done: back in orbit" : "AUTOTEST fail: take off did not finish within 180s"));
	}

	private static IEnumerator Checks(PlayerControllerB player)
	{
		Transform vault = VaultAlarm.FindVault();
		GrabbableObject scrap = (((Object)(object)vault == (Object)null) ? null : ((IEnumerable<GrabbableObject>)Object.FindObjectsOfType<GrabbableObject>()).FirstOrDefault((Func<GrabbableObject, bool>)delegate(GrabbableObject g)
		{
			//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_0033: Unknown result type (might be due to invalid IL or missing references)
			if (g.isInFactory && g.itemProperties.isScrap && !g.isHeld)
			{
				Vector3 val = vault.InverseTransformPoint(((Component)g).transform.position);
				return ((Vector3)(ref val)).magnitude < 9f;
			}
			return false;
		}));
		if ((Object)(object)scrap == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: no scrap in the vault");
		}
		else
		{
			int before = RoundManager.Instance.SpawnedEnemies.Count;
			scrap.isHeld = true;
			yield return (object)new WaitForSeconds(6f);
			scrap.isHeld = false;
			log.LogInfo((object)$"AUTOTEST alarm enemies +{RoundManager.Instance.SpawnedEnemies.Count - before}");
		}
		TimeOfDay instance = TimeOfDay.Instance;
		float num = instance.totalTime / Mathf.Max(0.01f, instance.globalTimeSpeedMultiplier);
		(string, float)[] array = new(string, float)[2]
		{
			("night", (12f + 12f / (num / 14f)) / 14f),
			("day", 0.3f)
		};
		for (int before = 0; before < array.Length; before++)
		{
			(string, float) tuple = array[before];
			string name = tuple.Item1;
			float item = tuple.Item2;
			NightCurrentRun.TimeOverride = item;
			player.TeleportPlayer(new Vector3(-33f, 0.5f, 55f), false, 0f, false, true);
			yield return (object)new WaitForSeconds(1f);
			Vector3 from = ((Component)player).transform.position;
			for (int second = 0; second < 4; second++)
			{
				yield return (object)new WaitForSeconds(1f);
				log.LogInfo((object)$"AUTOTEST current {name} t={second} at=({((Component)player).transform.position.x:F1},{((Component)player).transform.position.z:F1}) outsideEnemies={RoundManager.Instance.SpawnedEnemies.Count((EnemyAI e) => (Object)(object)e != (Object)null && e.isOutside)} forces={((Vector3)(ref player.externalForces)).magnitude:F2}");
			}
			float num2 = Vector3.Distance(new Vector3(from.x, 0f, from.z), new Vector3(((Component)player).transform.position.x, 0f, ((Component)player).transform.position.z));
			log.LogInfo((object)$"AUTOTEST current {name} moved={num2:F2} m");
		}
		NightCurrentRun.TimeOverride = null;
		yield return CheckTide(player);
		yield return CheckHook(player);
	}

	private static IEnumerator CheckTide(PlayerControllerB player)
	{
		RuntimeDungeon dungeonGenerator = RoundManager.Instance.dungeonGenerator;
		object obj;
		if (dungeonGenerator == null)
		{
			obj = null;
		}
		else
		{
			DungeonGenerator generator = dungeonGenerator.Generator;
			obj = ((generator != null) ? generator.CurrentDungeon : null);
		}
		Dungeon dungeon = (Dungeon)obj;
		EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsOfType<EntranceTeleport>()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => e.entranceId == 0 && e.isEntranceToBuilding));
		if ((Object)(object)dungeon == (Object)null || (Object)(object)val == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: no dungeon for the tide");
			yield break;
		}
		((UnityEvent<PlayerControllerB>)(object)((Component)val).GetComponent<InteractTrigger>().onInteract).Invoke(player);
		yield return (object)new WaitForSeconds(4f);
		Transform[] source = (from c in dungeon.AllTiles.SelectMany((Tile t) => from c in ((Component)t).GetComponentsInChildren<Transform>()
				where ((Component)c).CompareTag("AINode")
				select c)
			orderby c.position.y
			select c).ToArray();
		Transform low = source.First();
		Transform item = ((Component)dungeon.AllTiles.First((Tile t) => ((Object)t).name.StartsWith("InteriorStart"))).GetComponentsInChildren<Transform>().First((Transform c) => ((Component)c).CompareTag("AINode"));
		TimeOfDay instance = TimeOfDay.Instance;
		float daySeconds = instance.totalTime / Mathf.Max(0.01f, instance.globalTimeSpeedMultiplier);
		(string, float, Transform)[] array = new(string, float, Transform)[4]
		{
			("dry", -60f, low),
			("deep", 210f, low),
			("entrance", 210f, item),
			("drained", 600f, low)
		};
		for (int num = 0; num < array.Length; num++)
		{
			(string, float, Transform) tuple = array[num];
			string name = tuple.Item1;
			float item2 = tuple.Item2;
			Transform where = tuple.Item3;
			TideRun.TimeOverride = 0.4f + item2 / daySeconds;
			yield return (object)new WaitForSeconds(2f);
			player.TeleportPlayer(where.position + Vector3.up * 0.2f, false, 0f, false, true);
			yield return (object)new WaitForSeconds(3f);
			int num2;
			if (player.isUnderwater && (Object)(object)player.underwaterCollider != (Object)null)
			{
				Bounds bounds = player.underwaterCollider.bounds;
				num2 = (((Bounds)(ref bounds)).Contains(((Component)player.gameplayCamera).transform.position) ? 1 : 0);
			}
			else
			{
				num2 = 0;
			}
			bool flag = (byte)num2 != 0;
			log.LogInfo((object)$"AUTOTEST tide {name}: floor={where.position.y - TideRun.EntranceFloor:F1} surface={TideRun.Surface - TideRun.EntranceFloor:F1} feetInWater={player.isUnderwater} headUnder={flag} hindered={player.isMovementHindered}");
			if ((!(name == "deep")) ? ((!(name == "entrance")) ? (flag || player.isUnderwater || player.isMovementHindered != 0) : (flag || !player.isUnderwater || player.isMovementHindered != 1)) : (!flag || player.isMovementHindered != 1))
			{
				log.LogError((object)("AUTOTEST fail: tide " + name));
			}
		}
		if (low.position.y - TideRun.EntranceFloor > -5f)
		{
			log.LogError((object)"AUTOTEST fail: no floor below the entrance");
		}
		TideRun.TimeOverride = null;
		Object.FindObjectsOfType<EntranceTeleport>().First((EntranceTeleport e) => e.entranceId == 0 && !e.isEntranceToBuilding).TeleportPlayer();
		yield return (object)new WaitForSeconds(4f);
	}

	private static IEnumerator CheckHook(PlayerControllerB player)
	{
		Transform val = ((IEnumerable<Transform>)Object.FindObjectsOfType<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "FishHook_3"));
		if ((Object)(object)val == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: no hook to touch");
			yield break;
		}
		StartOfRound start = StartOfRound.Instance;
		FishHooks.NewLanding();
		player.health = 100;
		start.allowLocalPlayerDeath = true;
		float floor = val.position.y - 1.2f;
		player.TeleportPlayer(new Vector3(val.position.x, floor, val.position.z), false, 0f, false, true);
		float highest = floor;
		float reached = 0f;
		float left = 0f;
		for (float elapsed = 0f; elapsed < 8f; elapsed += Time.deltaTime)
		{
			if (player.health != 100)
			{
				break;
			}
			float y = ((Component)player).transform.position.y;
			if (y > highest + 0.01f)
			{
				highest = y;
				reached = elapsed;
				left = 0f;
			}
			else if (left == 0f && highest - floor > 40f && y < highest - 2f)
			{
				left = elapsed;
			}
			yield return null;
		}
		start.allowLocalPlayerDeath = false;
		log.LogInfo((object)$"AUTOTEST hook rose={highest - floor:F1} m hung={left - reached:F2} s health={player.health} dead={player.isPlayerDead}");
		if (highest - floor < 70f || left == 0f || left - reached > 0.5f || player.health != 10 || player.isPlayerDead)
		{
			log.LogError((object)"AUTOTEST fail: hook");
		}
		player.health = 100;
	}

	private static void Reports(float earlier)
	{
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		TimeOfDay instance = TimeOfDay.Instance;
		float num = instance.normalizedTimeOfDay - earlier;
		log.LogInfo((object)string.Format("AUTOTEST clock time={0:F3} moved={1:F3} shown='{2}'", instance.normalizedTimeOfDay, num, ((TMP_Text)HUDManager.Instance.clockNumber).text.Replace("\n", " ")));
		if (num <= 0f)
		{
			log.LogError((object)"AUTOTEST fail: time of day is standing still");
		}
		string[] array = (from n in Object.FindObjectsOfType<ScanNodeProperties>()
			where ((Object)n).name.StartsWith("ScanNode_")
			select n.headerText).ToArray();
		bool flag = (from e in Object.FindObjectsOfType<EntranceTeleport>()
			where e.isEntranceToBuilding
			select e).All((EntranceTeleport e) => (Object)(object)((Component)e).GetComponent<InteractTrigger>().hoverIcon != (Object)null);
		log.LogInfo((object)string.Format("AUTOTEST scan nodes=[{0}] doorIcons={1}", string.Join(",", array), flag));
		if (array.Length != 2 || !flag)
		{
			log.LogError((object)"AUTOTEST fail: scan markers or door icons missing");
		}
		IEnumerable<string> values = from e in RoundManager.Instance.SpawnedEnemies
			where (Object)(object)e != (Object)null
			group e by e.enemyType.enemyName into g
			select $"{g.Key}x{g.Count()}";
		int num2 = Object.FindObjectsOfType<GrabbableObject>().Count((GrabbableObject g) => g.itemProperties.itemName == "Hive");
		RadMechAI[] array2 = Object.FindObjectsOfType<RadMechAI>();
		log.LogInfo((object)string.Format("AUTOTEST creatures [{0}] hives={1} oldBirds={2} at={3}", string.Join(", ", values), num2, array2.Length, string.Join(" ", array2.Select(delegate(RadMechAI b)
		{
			//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)
			Vector3 position = ((Component)b).transform.position;
			return ((Vector3)(ref position)).ToString("F0");
		}))));
		if (array2.Length != DinerRules.OldBirds(LunarEclipse.Active) || num2 != 4)
		{
			log.LogError((object)$"AUTOTEST fail: expected {DinerRules.OldBirds(LunarEclipse.Active)} old birds and four hives");
		}
		log.LogInfo((object)$"AUTOTEST diner doors={DinerRooms.DoorCount} locked={Object.FindObjectsOfType<DoorLock>().Count((DoorLock d) => d.isLocked)} keys={Object.FindObjectsOfType<GrabbableObject>().Count((GrabbableObject g) => g is KeyItem)} lit={DinerRooms.LitCount} lunar={LunarEclipse.Active} weather={StartOfRound.Instance.currentLevel.currentWeather} inside={StartOfRound.Instance.currentLevel.maxEnemyPowerCount} outside={StartOfRound.Instance.currentLevel.maxOutsideEnemyPowerCount}");
		if (DinerRooms.DoorCount < 10 || DinerRooms.LitCount == 0)
		{
			log.LogError((object)"AUTOTEST fail: diner doors or lit rooms missing");
		}
	}

	private static IEnumerator Photograph(PlayerControllerB player)
	{
		EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsOfType<EntranceTeleport>()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => e.entranceId == 0 && e.isEntranceToBuilding));
		RuntimeDungeon dungeonGenerator = RoundManager.Instance.dungeonGenerator;
		object obj;
		if (dungeonGenerator == null)
		{
			obj = null;
		}
		else
		{
			DungeonGenerator generator = dungeonGenerator.Generator;
			obj = ((generator != null) ? generator.CurrentDungeon : null);
		}
		Dungeon dungeon = (Dungeon)obj;
		if ((Object)(object)val == (Object)null || (Object)(object)dungeon == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: nothing to photograph");
			yield break;
		}
		((UnityEvent<PlayerControllerB>)(object)((Component)val).GetComponent<InteractTrigger>().onInteract).Invoke(player);
		yield return (object)new WaitForSeconds(4f);
		string[] array = new string[14]
		{
			"InteriorStart", "InteriorHall", "InteriorKitchen", "InteriorFreezer", "InteriorStairs", "InteriorCellar", "InteriorVault", "InteriorBanquet", "InteriorCross", "InteriorLongHall",
			"InteriorStorage", "InteriorGallery", "InteriorBoiler", "InteriorQuarters"
		};
		foreach (string kind in array)
		{
			Tile tile = ((IEnumerable<Tile>)dungeon.AllTiles).FirstOrDefault((Func<Tile, bool>)((Tile t) => ((Object)t).name.StartsWith(kind)));
			if (!((Object)(object)tile == (Object)null))
			{
				Transform val2 = ((IEnumerable<Transform>)((Component)tile).GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Component)t).CompareTag("AINode")));
				player.TeleportPlayer((((Object)(object)val2 != (Object)null) ? val2.position : ((Component)tile).transform.position) + Vector3.up * 0.2f, false, 0f, false, true);
				for (int turn = 0; turn < 2; turn++)
				{
					player.thisPlayerBody.eulerAngles = new Vector3(0f, ((Component)tile).transform.eulerAngles.y + (float)(turn * 180), 0f);
					yield return (object)new WaitForSeconds(2f);
					ScreenCapture.CaptureScreenshot(Path.Combine(folder, $"shot_{kind}_{turn}.png"));
					yield return (object)new WaitForSeconds(1f);
				}
				log.LogInfo((object)("AUTOTEST photographed " + kind));
			}
		}
		DoorLock val3 = Object.FindObjectsOfType<DoorLock>().FirstOrDefault();
		if ((Object)(object)val3 != (Object)null)
		{
			Transform body = ((Component)((Component)val3).GetComponentInParent<NetworkObject>()).transform;
			for (int num = 0; num < 2; num++)
			{
				Vector3 val4 = (float)((num == 0) ? 1 : (-1)) * body.forward * 3.5f;
				player.TeleportPlayer(body.position + val4 + Vector3.up * 0.2f, false, 0f, false, true);
				Transform thisPlayerBody = player.thisPlayerBody;
				Quaternion val5 = Quaternion.LookRotation(-val4);
				thisPlayerBody.eulerAngles = new Vector3(0f, ((Quaternion)(ref val5)).eulerAngles.y, 0f);
				yield return (object)new WaitForSeconds(2f);
				ScreenCapture.CaptureScreenshot(Path.Combine(folder, $"shot_door_{num}.png"));
				yield return (object)new WaitForSeconds(1f);
			}
			log.LogInfo((object)$"AUTOTEST photographed a door scale={body.localScale:F2}");
		}
		Object.FindObjectsOfType<EntranceTeleport>().First((EntranceTeleport e) => e.entranceId == 0 && !e.isEntranceToBuilding).TeleportPlayer();
		yield return (object)new WaitForSeconds(4f);
	}

	private static void LogInterior()
	{
		DungeonGenerator val = (((Object)(object)RoundManager.Instance.dungeonGenerator == (Object)null) ? null : RoundManager.Instance.dungeonGenerator.Generator);
		if (val == null || (Object)(object)val.CurrentDungeon == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: no dungeon");
			return;
		}
		ReadOnlyCollection<Tile> allTiles = val.CurrentDungeon.AllTiles;
		string arg = string.Join(" ", allTiles.Select((Tile t) => string.Format("{0}@{1:F0},{2:F0}", ((Object)t).name.Replace("(Clone)", ""), ((Component)t).transform.position.x, ((Component)t).transform.position.z)));
		log.LogInfo((object)$"AUTOTEST interior flow={((Object)val.DungeonFlow).name} tiles={allTiles.Count} layout=[{arg}]");
		IEnumerable<string> values = from t in allTiles
			group t by ((Object)t).name.Replace("(Clone)", "") into g
			orderby g.Key
			select $"{g.Key}x{g.Count()}";
		log.LogInfo((object)("AUTOTEST kinds " + string.Join(" ", values)));
		if (((Object)val.DungeonFlow).name == "BrinebiteDinerFlow" && (allTiles.Count < 16 || allTiles.Count > 32))
		{
			log.LogError((object)$"AUTOTEST fail: {allTiles.Count} rooms, want about 24");
		}
		if (((Object)val.DungeonFlow).name == "BrinebiteDinerFlow" && allTiles.Count((Tile t) => ((Object)t).name.StartsWith("InteriorVault")) != 1)
		{
			log.LogError((object)"AUTOTEST fail: there must be exactly one vault");
		}
	}

	private static void LogVentPaths()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0061: 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_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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Invalid comparison between Unknown and I4
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsOfType<EntranceTeleport>()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => e.entranceId == 0 && !e.isEntranceToBuilding));
		if ((Object)(object)val == (Object)null)
		{
			log.LogError((object)"AUTOTEST fail: no inside door");
			return;
		}
		EnemyVent[] array = Object.FindObjectsOfType<EnemyVent>();
		NavMeshHit val4 = default(NavMeshHit);
		NavMeshHit val5 = default(NavMeshHit);
		foreach (EnemyVent val2 in array)
		{
			NavMeshPath val3 = new NavMeshPath();
			bool flag = NavMesh.SamplePosition(val2.floorNode.position, ref val4, 3f, -1) && NavMesh.SamplePosition(val.entrancePoint.position, ref val5, 3f, -1) && NavMesh.CalculatePath(((NavMeshHit)(ref val4)).position, ((NavMeshHit)(ref val5)).position, -1, val3) && (int)val3.status == 0;
			log.LogInfo((object)string.Format("AUTOTEST vent path {0} from {1:F1}", flag ? "ok" : "blocked", val2.floorNode.position));
		}
	}
}
public sealed class AutoTestGate
{
	private bool armed;

	public AutoTestGate(bool armed)
	{
		this.armed = armed;
	}

	public bool TryStart(string save)
	{
		bool result = armed && save == "LCSaveFile3";
		armed = false;
		return result;
	}
}
internal static class BrinebiteMoon
{
	public const string SceneName = "BrinebiteScene";

	private const string AssetsBundle = "brinebite.assets";

	private const string SceneBundle = "brinebitescene.lethalbundle";

	private static SelectableLevel level;

	private static ManualLogSource log;

	private static ExtendedDungeonFlow interior;

	public static DungeonFlow DinerFlow
	{
		get
		{
			if (!((Object)(object)interior == (Object)null))
			{
				return interior.DungeonFlow;
			}
			return null;
		}
	}

	public static void Register(string pluginFolder, ManualLogSource logger)
	{
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Expected O, but got Unknown
		log = logger;
		string text = Path.Combine(pluginFolder, "brinebite.assets");
		string text2 = Path.Combine(pluginFolder, "brinebitescene.lethalbundle");
		AssetBundle val = ((File.Exists(text) && File.Exists(text2)) ? AssetBundle.LoadFromFile(text) : null);
		GameObject val2 = (((Object)(object)val == (Object)null) ? null : val.LoadAsset<GameObject>("BrinebitePlanet"));
		if ((Object)(object)val2 == (Object)null)
		{
			log.LogWarning((object)("Brinebite skipped: " + text + " or " + text2 + " is missing or unreadable"));
			return;
		}
		level = ScriptableObject.CreateInstance<SelectableLevel>();
		((Object)level).name = "BrinebiteLevel";
		level.PlanetName = "77 Bikini Bottom";
		level.sceneName = "BrinebiteScene";
		level.riskLevel = "S+";
		level.LevelDescription = "A sunken diner town. Something is still cooking.";
		level.planetPrefab = val2;
		level.currentWeather = (LevelWeatherType)(-1);
		level.spawnEnemiesAndScrap = true;
		level.planetHasTime = true;
		level.DaySpeedMultiplier = 1f;
		FillNullMembers(level);
		LunarEclipse.Enable(level, logger);
		ExtendedLevel val3 = ScriptableObject.CreateInstance<ExtendedLevel>();
		((Object)val3).name = "BrinebiteExtendedLevel";
		val3.SelectableLevel = level;
		val3.RoutePrice = 0;
		val3.OverrideCameraFarPlaneDistanceOutside = 950f;
		val3.OverrideDynamicRiskLevelAssignment = true;
		interior = InteriorSetup.Create(val, pluginFolder, logger);
		ExtendedContent[] array = (ExtendedContent[])(object)((!((Object)(object)interior == (Object)null)) ? new ExtendedContent[2]
		{
			(ExtendedContent)val3,
			(ExtendedContent)interior
		} : new ExtendedContent[1] { (ExtendedContent)val3 });
		ExtendedMod obj = ExtendedMod.Create("Brinebite", "LethalMoon", array);
		obj.StreamingLethalBundleNames.Add("brinebitescene.lethalbundle");
		PatchedContent.RegisterExtendedMod(obj);
		new Harmony("com.lethalmoon.plugin").Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BrinebiteMoon), "OnStartOfRoundStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		log.LogInfo((object)("Brinebite registered: " + level.PlanetName));
	}

	private static void OnStartOfRoundStart()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: 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_0125: Unknown result type (might be due to invalid IL or missing references)
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			log.LogWarning((object)"BRINEBITE data: StartOfRound is not ready");
			return;
		}
		SelectableLevel val = ((IEnumerable<SelectableLevel>)instance.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => (Object)(object)l != (Object)null && l.PlanetName.Contains("Titan")));
		if ((Object)(object)val == (Object)null)
		{
			log.LogWarning((object)"BRINEBITE data: Titan level not found");
		}
		else
		{
			CopyLevelData(val, instance);
		}
		if ((Object)(object)interior == (Object)null || !InteriorSetup.Finish(interior))
		{
			AllowFacilityInterior();
		}
		Bounds bounds = instance.shipInnerRoomBounds.bounds;
		Bounds bounds2 = instance.shipBounds.bounds;
		log.LogInfo((object)($"BRINEBITE ship elevator={instance.elevatorTransform.position:F2} inner={((Bounds)(ref bounds)).center:F2}/{((Bounds)(ref bounds)).size:F2} " + $"outer={((Bounds)(ref bounds2)).center:F2}/{((Bounds)(ref bounds2)).size:F2} doorNode={instance.shipDoorNode.position:F2} " + $"outsideSpawn={instance.outsideShipSpawnPosition.position:F2} groundSpawn={instance.groundOutsideShipSpawnPosition.position:F2}"));
	}

	private static void AllowFacilityInterior()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		ExtendedDungeonFlow val = ((IEnumerable<ExtendedDungeonFlow>)PatchedContent.ExtendedDungeonFlows).FirstOrDefault((Func<ExtendedDungeonFlow, bool>)((ExtendedDungeonFlow f) => f.DungeonName == "Facility"));
		if ((Object)(object)val == (Object)null)
		{
			log.LogWarning((object)"BRINEBITE interior: Facility dungeon not found");
			return;
		}
		List<StringWithRarity> planetNames = val.LevelMatchingProperties.planetNames;
		if (planetNames.All((StringWithRarity n) => n.Name != "Bikini Bottom"))
		{
			planetNames.Add(new StringWithRarity("Bikini Bottom", 300));
		}
		log.LogInfo((object)"BRINEBITE interior: Facility allowed");
	}

	private static void CopyLevelData(SelectableLevel source, StartOfRound start)
	{
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		level.dungeonFlowTypes = source.dungeonFlowTypes.ToArray();
		level.factorySizeMultiplier = source.factorySizeMultiplier;
		level.DaySpeedMultiplier = source.DaySpeedMultiplier;
		level.OffsetFromGlobalTime = source.OffsetFromGlobalTime;
		level.spawnableScrap = source.spawnableScrap.ToList();
		level.minScrap = source.minScrap;
		level.maxScrap = source.maxScrap;
		level.minTotalScrapValue = source.minTotalScrapValue;
		level.maxTotalScrapValue = source.maxTotalScrapValue;
		level.Enemies = source.Enemies.ToList();
		level.OutsideEnemies = source.OutsideEnemies.ToList();
		level.DaytimeEnemies = source.DaytimeEnemies.ToList();
		level.enemySpawnChanceThroughoutDay = new AnimationCurve(source.enemySpawnChanceThroughoutDay.keys);
		level.outsideEnemySpawnChanceThroughDay = new AnimationCurve(source.outsideEnemySpawnChanceThroughDay.keys);
		level.daytimeEnemySpawnChanceThroughDay = new AnimationCurve(source.daytimeEnemySpawnChanceThroughDay.keys);
		level.spawnProbabilityRange = source.spawnProbabilityRange;
		level.daytimeEnemiesProbabilityRange = source.daytimeEnemiesProbabilityRange;
		level.maxEnemyPowerCount = source.maxEnemyPowerCount;
		level.maxOutsideEnemyPowerCount = source.maxOutsideEnemyPowerCount;
		level.maxDaytimeEnemyPowerCount = source.maxDaytimeEnemyPowerCount;
		level.maxInsideDiversityPowerCount = source.maxInsideDiversityPowerCount;
		level.maxOutsideDiversityPowerCount = source.maxOutsideDiversityPowerCount;
		level.spawnableMapObjects = source.spawnableMapObjects.ToArray();
		level.indoorMapHazards = source.indoorMapHazards.ToArray();
		level.levelAmbienceClips = source.levelAmbienceClips;
		level.overrideWeather = false;
		SelectableLevel obj = level;
		LevelWeatherType[] array = new LevelWeatherType[3];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		obj.randomWeathers = (from type in (IEnumerable<LevelWeatherType>)(object)array
			select start.levels.Where((SelectableLevel l) => (Object)(object)l != (Object)null && l.randomWeathers != null).SelectMany((SelectableLevel l) => l.randomWeathers).FirstOrDefault((Func<RandomWeatherWithVariables, bool>)((RandomWeatherWithVariables w) => w.weatherType == type)) into w
			where w != null
			select w).ToArray();
		LunarEclipse.SetBaseline(source.maxEnemyPowerCount, source.maxOutsideEnemyPowerCount);
		LunarEclipse.Decide();
		log.LogInfo((object)string.Format("BRINEBITE data scrap={0} enemies={1} weathers=[{2}] flows={3} daySpeed={4}", level.spawnableScrap.Count, level.Enemies.Count, string.Join(",", level.randomWeathers.Select((RandomWeatherWithVariables w) => w.weatherType)), level.dungeonFlowTypes.Length, level.DaySpeedMultiplier));
	}

	private static void FillNullMembers(object target)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		FieldInfo[] fields = target.GetType().GetFields();
		foreach (FieldInfo fieldInfo in fields)
		{
			if (fieldInfo.GetValue(target) == null)
			{
				Type fieldType = fieldInfo.FieldType;
				if (fieldType.IsArray)
				{
					fieldInfo.SetValue(target, Array.CreateInstance(fieldType.GetElementType(), 0));
				}
				else if (fieldType == typeof(AnimationCurve))
				{
					fieldInfo.SetValue(target, (object?)new AnimationCurve());
				}
				else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
				{
					fieldInfo.SetValue(target, Activator.CreateInstance(fieldType));
				}
				else if (fieldType == typeof(string))
				{
					fieldInfo.SetValue(target, string.Empty);
				}
				else if (fieldType.IsClass && fieldType.IsSerializable && !typeof(Object).IsAssignableFrom(fieldType) && fieldType.GetConstructor(Type.EmptyTypes) != null)
				{
					fieldInfo.SetValue(target, Activator.CreateInstance(fieldType));
				}
			}
		}
	}
}
internal static class DinerRooms
{
	private const float LitIntensity = 4000f;

	private const float DimIntensity = 1200f;

	public static int LitCount { get; private set; }

	public static int DoorCount { get; private set; }

	public static IEnumerator Run(Scene scene, ManualLogSource log)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		DoorCount = 0;
		LitCount = 0;
		StartOfRound start = StartOfRound.Instance;
		Transform vault = null;
		while (((Scene)(ref scene)).isLoaded && !start.shipIsLeaving)
		{
			if (RoundManager.Instance.dungeonCompletedGenerating)
			{
				Transform val;
				vault = (val = VaultAlarm.FindVault());
				if (!((Object)(object)val == (Object)null))
				{
					break;
				}
			}
			yield return (object)new WaitForSeconds(0.5f);
		}
		if ((Object)(object)vault == (Object)null)
		{
			yield break;
		}
		List<Tile> list = RoundManager.Instance.dungeonGenerator.Generator.CurrentDungeon.AllTiles.Where((Tile t) => (Object)(object)t != (Object)null).ToList();
		bool[] array = DinerRules.LitRooms(start.randomMapSeed, list.Count);
		for (int num = 0; num < list.Count; num++)
		{
			bool flag = array[num] && (Object)(object)((Component)list[num]).transform != (Object)(object)vault;
			Light[] componentsInChildren = ((Component)list[num]).GetComponentsInChildren<Light>(true);
			foreach (Light val2 in componentsInChildren)
			{
				if (!flag)
				{
					val2.intensity = 1200f;
				}
			}
			if (flag)
			{
				componentsInChildren = ((Component)list[num]).GetComponentsInChildren<Light>(true);
				foreach (Light obj in componentsInChildren)
				{
					obj.intensity = 4000f;
					obj.color = new Color(1f, 0.92f, 0.78f);
				}
				LitCount++;
			}
		}
		log.LogInfo((object)$"BRINEBITE rooms: lit {LitCount} of {list.Count}");
		HashSet<NetworkObject> done = new HashSet<NetworkObject>();
		for (float waited = 0f; waited < 60f; waited += 1f)
		{
			if (!((Scene)(ref scene)).isLoaded)
			{
				break;
			}
			if (start.shipIsLeaving)
			{
				break;
			}
			DoorLock[] array2 = Object.FindObjectsOfType<DoorLock>();
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				NetworkObject componentInParent = ((Component)array2[num2]).GetComponentInParent<NetworkObject>();
				if (!((Object)(object)componentInParent == (Object)null) && done.Add(componentInParent))
				{
					Grow(((Component)componentInParent).transform);
				}
			}
			if (done.Count != DoorCount)
			{
				DoorCount = done.Count;
				log.LogInfo((object)$"BRINEBITE rooms: doors {DoorCount}, locked {Object.FindObjectsOfType<DoorLock>().Count((DoorLock d) => d.isLocked)}");
			}
			yield return (object)new WaitForSeconds(1f);
		}
	}

	private static void Grow(Transform door)
	{
		//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_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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)
		Vector3 val = Foot(door);
		door.localScale *= 1.2f;
		door.position += val - Foot(door);
	}

	private static Vector3 Foot(Transform door)
	{
		//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_000d: 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_0041: 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_0059: 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)
		Renderer[] componentsInChildren = ((Component)door).GetComponentsInChildren<Renderer>(true);
		if (componentsInChildren.Length == 0)
		{
			return door.position;
		}
		Bounds bounds = componentsInChildren[0].bounds;
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			((Bounds)(ref bounds)).Encapsulate(val.bounds);
		}
		return new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z);
	}
}
public static class DinerRules
{
	public const double LitShare = 0.25;

	public const double LunarChance = 0.08;

	public const float DoorScale = 1.2f;

	private const double InsideShare = 0.6;

	private const double LunarOutside = 1.5;

	public static bool[] LitRooms(int seed, int count)
	{
		Random random = new Random(seed + 4041);
		bool[] array = new bool[count];
		for (int i = 0; i < count; i++)
		{
			array[i] = random.NextDouble() < 0.25;
		}
		if (count > 0 && Array.IndexOf(array, value: true) < 0)
		{
			array[random.Next(count)] = true;
		}
		return array;
	}

	public static bool IsLunar(int seed)
	{
		return new Random(seed + 7777).NextDouble() < 0.08;
	}

	public static int InsidePower(int baseline, bool lunar)
	{
		if (!lunar)
		{
			return Math.Max(1, (int)Math.Round((double)baseline * 0.6));
		}
		return baseline;
	}

	public static int OutsidePower(int baseline, bool lunar)
	{
		if (!lunar)
		{
			return baseline;
		}
		return (int)Math.Round((double)baseline * 1.5);
	}

	public static int OldBirds(bool lunar)
	{
		return lunar ? 1 : 0;
	}

	public static string LunarText(string text)
	{
		return Regex.Replace(text, "(Bikini Bottom[^\\n]*?)\\(Eclipsed\\)", "$1(Lunar Eclipse)");
	}

	public static string LunarScreen(string text)
	{
		return text.Replace("Eclipsed", "Lunar Eclipse");
	}
}
internal static class EntranceSetup
{
	public static bool TryAttach(Transform target)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Expected O, but got Unknown
		if (!SceneMarker.TryParseEntrance(((Object)target).name, out var id))
		{
			return false;
		}
		GameObject gameObject = ((Component)target).gameObject;
		Transform val = target.Find($"Entrance_{id}_Point");
		if ((Object)(object)val == (Object)null || (Object)(object)gameObject.GetComponent<NetworkObject>() == (Object)null)
		{
			return false;
		}
		InteractTrigger obj = gameObject.AddComponent<InteractTrigger>();
		obj.hoverTip = "Enter: [LMB]";
		obj.interactable = true;
		obj.oneHandedItemAllowed = true;
		obj.twoHandedItemAllowed = true;
		obj.holdInteraction = true;
		obj.timeToHold = 0.7f;
		obj.timeToHoldSpeedMultiplier = 1f;
		obj.interactCooldown = true;
		obj.cooldownTime = 1f;
		obj.onInteract = new InteractEvent();
		obj.onInteractEarly = new InteractEvent();
		obj.onInteractEarlyOtherClients = new InteractEvent();
		obj.onStopInteract = new InteractEvent();
		obj.onCancelAnimation = new InteractEvent();
		obj.holdingInteractEvent = new InteractEventFloat();
		EntranceTeleport teleport = gameObject.AddComponent<EntranceTeleport>();
		teleport.isEntranceToBuilding = true;
		teleport.entranceId = id;
		teleport.entrancePoint = val;
		teleport.entrancePointAudio = gameObject.GetComponent<AudioSource>();
		teleport.audioReverbPreset = -1;
		((UnityEvent<PlayerControllerB>)(object)obj.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate
		{
			teleport.TeleportPlayer();
		});
		return true;
	}
}
internal static class FishHooks
{
	private const float Reach = 0.9f;

	private const float Gravity = 38f;

	private const float ThrowSpeed = 15f;

	private static int catches;

	public static void NewLanding()
	{
		catches = 0;
	}

	public static IEnumerator Run(Transform hook, ManualLogSource log)
	{
		if (!int.TryParse(((Object)hook).name.Substring(((Object)hook).name.IndexOf('_') + 1), out var index))
		{
			yield break;
		}
		HookState state = new HookState();
		Vector3 rest = hook.localPosition;
		PlayerControllerB caught = null;
		float floor = 0f;
		while ((Object)(object)hook != (Object)null)
		{
			StartOfRound instance = StartOfRound.Instance;
			float nightAmount = (((Object)(object)TimeOfDay.Instance != (Object)null) ? SkyCycle.NightAmount(TimeOfDay.Instance.normalizedTimeOfDay) : 0f);
			bool flag = HookState.IsOut(index, nightAmount) || state.Phase != HookPhase.Waiting;
			if (((Component)hook).gameObject.activeSelf != flag)
			{
				((Component)hook).gameObject.SetActive(flag);
			}
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			bool touched = false;
			if (flag && state.Phase == HookPhase.Waiting && instance.shipHasLanded)
			{
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if (!((Object)(object)val2 == (Object)null) && val2.isPlayerControlled && !val2.isPlayerDead && !val2.isInsideFactory && (!((Object)(object)val2 == (Object)(object)val) || ((Collider)val2.thisController).enabled) && Touches(val2, hook.position))
					{
						touched = true;
						if (!((Object)(object)val2 != (Object)(object)val))
						{
							caught = val2;
							floor = ((Component)val2).transform.position.y;
							catches++;
							log.LogInfo((object)$"BRINEBITE hook {index} caught the local player");
						}
					}
				}
			}
			float num = state.Step(touched, Time.deltaTime);
			hook.localPosition = rest + Vector3.up * num;
			if ((Object)(object)caught != (Object)null)
			{
				if (caught.isPlayerDead || instance.shipIsLeaving)
				{
					Release(caught);
					caught = null;
				}
				else if (state.Phase == HookPhase.Returning)
				{
					Carry(caught, hook.position);
					((MonoBehaviour)instance).StartCoroutine(Drop(caught, floor, log));
					caught = null;
				}
				else if (state.Phase != HookPhase.Waiting)
				{
					Carry(caught, hook.position);
				}
			}
			yield return null;
		}
		if ((Object)(object)caught != (Object)null)
		{
			Release(caught);
		}
	}

	private static bool Touches(PlayerControllerB player, Vector3 point)
	{
		//IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0032: 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)
		Vector3 val = point - ((Component)player).transform.position;
		Vector2 val2 = new Vector2(val.x, val.z);
		if (((Vector2)(ref val2)).magnitude < 0.9f && val.y > -0.3f)
		{
			return val.y < 2.6f;
		}
		return false;
	}

	private static void Carry(PlayerControllerB player, Vector3 point)
	{
		//IL_0012: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		((Collider)player.thisController).enabled = false;
		((Component)player).transform.position = point - Vector3.up * 1.4f;
		player.ResetFallGravity();
	}

	private static IEnumerator Drop(PlayerControllerB player, float floor, ManualLogSource log)
	{
		float speed = 15f;
		while ((Object)(object)player != (Object)null && !player.isPlayerDead && !StartOfRound.Instance.shipIsLeaving && ((Component)player).transform.position.y > floor)
		{
			speed += 38f * Time.deltaTime;
			Vector3 position = ((Component)player).transform.position;
			position.y = Mathf.Max(floor, position.y - speed * Time.deltaTime);
			((Component)player).transform.position = position;
			player.ResetFallGravity();
			yield return null;
		}
		if ((Object)(object)player == (Object)null || player.isPlayerDead)
		{
			yield break;
		}
		bool num = !StartOfRound.Instance.shipIsLeaving;
		Release(player);
		if (!num)
		{
			yield break;
		}
		if (HookState.IsFatal(catches))
		{
			player.KillPlayer(Vector3.zero, true, (CauseOfDeath)2, 0, default(Vector3), false);
			log.LogInfo((object)$"BRINEBITE hook drop killed the player on catch {catches}");
			yield break;
		}
		int num2 = HookState.LandingDamage(player.health);
		if (num2 > 0)
		{
			player.DamagePlayer(num2, true, true, (CauseOfDeath)2, 0, false, default(Vector3));
		}
		log.LogInfo((object)$"BRINEBITE hook drop landed, damage={num2} health={player.health}");
	}

	private static void Release(PlayerControllerB player)
	{
		if (!((Object)(object)player == (Object)null) && !((Object)(object)player.thisController == (Object)null))
		{
			player.ResetFallGravity();
			if (!player.isPlayerDead)
			{
				((Collider)player.thisController).enabled = true;
			}
		}
	}
}
public enum HookPhase
{
	Waiting,
	Reeling,
	Returning
}
public sealed class HookState
{
	public const float TopHeight = 80f;

	public const int DayHooks = 50;

	private const int HealthLeft = 10;

	private const float ReelSpeed = 150f;

	private const float ReturnSpeed = 15f;

	private float height;

	public HookPhase Phase { get; private set; }

	public static bool IsFatal(int catches)
	{
		return catches >= 2;
	}

	public static int LandingDamage(int health)
	{
		return Math.Max(0, health - 10);
	}

	public static bool IsOut(int index, float nightAmount)
	{
		if (index >= 50)
		{
			return nightAmount >= 0.5f;
		}
		return true;
	}

	public float Step(bool touched, float seconds)
	{
		switch (Phase)
		{
		case HookPhase.Waiting:
			if (touched)
			{
				Phase = HookPhase.Reeling;
			}
			break;
		case HookPhase.Reeling:
			height = Math.Min(80f, height + 150f * seconds);
			if (height >= 80f)
			{
				Phase = HookPhase.Returning;
			}
			break;
		case HookPhase.Returning:
			height = Math.Max(0f, height - 15f * seconds);
			if (height <= 0f)
			{
				Phase = HookPhase.Waiting;
			}
			break;
		}
		return height;
	}
}
internal static class InteriorLook
{
	public static IEnumerator Run(Scene scene, DungeonFlow diner, ManualLogSource log)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("BrinebiteInteriorLook");
		SceneManager.MoveGameObjectToScene(val, scene);
		Volume volume = val.AddComponent<Volume>();
		volume.isGlobal = true;
		volume.priority = 100f;
		volume.weight = 0f;
		VolumeProfile val2 = ScriptableObject.CreateInstance<VolumeProfile>();
		((VolumeParameter<int>)(object)val2.Add<VisualEnvironment>(false).skyType).Override(0);
		Fog obj = val2.Add<Fog>(false);
		((VolumeParameter<bool>)(object)obj.enabled).Override(true);
		((VolumeParameter<FogColorMode>)(object)obj.colorMode).Override((FogColorMode)0);
		((VolumeParameter<Color>)(object)obj.color).Override(Color.black);
		((VolumeParameter<float>)(object)obj.meanFreePath).Override(60f);
		((VolumeParameter<bool>)(object)obj.enableVolumetricFog).Override(false);
		IndirectLightingController obj2 = val2.Add<IndirectLightingController>(false);
		((VolumeParameter<float>)(object)obj2.indirectDiffuseLightingMultiplier).Override(0.08f);
		((VolumeParameter<float>)(object)obj2.reflectionLightingMultiplier).Override(0f);
		Exposure obj3 = val2.Add<Exposure>(false);
		((VolumeParameter<ExposureMode>)(object)obj3.mode).Override((ExposureMode)0);
		((VolumeParameter<float>)(object)obj3.fixedExposure).Override(7f);
		volume.sharedProfile = val2;
		AudioSource hum = val.AddComponent<AudioSource>();
		hum.clip = Synth.Drone();
		hum.loop = true;
		hum.spatialBlend = 0f;
		hum.volume = 0f;
		hum.Play();
		AudioClip drip = Synth.Drip();
		float nextDrip = 0f;
		while ((Object)(object)volume != (Object)null)
		{
			PlayerControllerB val3 = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.localPlayerController);
			if ((Object)(object)val3 != (Object)null && val3.isPlayerDead && (Object)(object)val3.spectatedPlayerScript != (Object)null)
			{
				val3 = val3.spectatedPlayerScript;
			}
			RuntimeDungeon val4 = (((Object)(object)RoundManager.Instance == (Object)null) ? null : RoundManager.Instance.dungeonGenerator);
			float num = (((Object)(object)val4 != (Object)null && (Object)(object)val4.Generator.DungeonFlow == (Object)(object)diner && (Object)(object)val3 != (Object)null && val3.isInsideFactory) ? 1f : 0f);
			if (num != volume.weight)
			{
				volume.weight = num;
				log.LogInfo((object)("BRINEBITE interior look " + ((num > 0f) ? "on" : "off")));
			}
			hum.volume = Mathf.MoveTowards(hum.volume, num * 0.1f, 0.2f);
			if (num > 0f && Time.time > nextDrip)
			{
				hum.PlayOneShot(drip, 0.3f);
				nextDrip = Time.time + Random.Range(3f, 9f);
			}
			yield return (object)new WaitForSeconds(0.2f);
		}
	}
}
public enum InteriorPart
{
	None,
	Doorway,
	ScrapSpot,
	VentSpot,
	EntranceSpot,
	FireSpot
}
public static class InteriorMarker
{
	private static readonly Regex Name = new Regex("^(Doorway|ScrapSpot|VentSpot|EntranceSpot|FireSpot)(_\\d+)?$");

	public static InteriorPart Parse(string name)
	{
		Match match = Name.Match(name ?? string.Empty);
		if (!match.Success)
		{
			return InteriorPart.None;
		}
		return (InteriorPart)Enum.Parse(typeof(InteriorPart), match.Groups[1].Value);
	}
}
internal static class InteriorSetup
{
	public const string FlowName = "Brinebite Diner";

	private const int VentProps = 5;

	private const int FireExitProp = 1231;

	private static ManualLogSource log;

	private static readonly string[] RoomNames = new string[17]
	{
		"InteriorStart", "InteriorCorridor", "InteriorDeadEnd", "InteriorHall", "InteriorKitchen", "InteriorFreezer", "InteriorStairs", "InteriorCellar", "InteriorVault", "InteriorBanquet",
		"InteriorCross", "InteriorLongHall", "InteriorBend", "InteriorStorage", "InteriorGallery", "InteriorBoiler", "InteriorQuarters"
	};

	private static Dictionary<string, GameObject> rooms;

	private static bool finished;

	internal static ExtendedDungeonFlow Create(AssetBundle bundle, string pluginFolder, ManualLogSource logger)
	{
		//IL_00d3: 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_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		log = logger;
		try
		{
			rooms = RoomNames.ToDictionary((string n) => n, (string n) => bundle.LoadAsset<GameObject>(n));
			TideRun.WaterMaterial = bundle.LoadAsset<Material>("InteriorWater");
			if (rooms.Values.Any((GameObject r) => (Object)(object)r == (Object)null))
			{
				Warn("room prefabs are missing from the bundle");
				return null;
			}
			DoorwaySocket val = ScriptableObject.CreateInstance<DoorwaySocket>();
			((Object)val).name = "BrinebiteSocket";
			AccessTools.Field(typeof(DoorwaySocket), "size").SetValue(val, (object)new Vector2(2.4f, 3.95f));
			foreach (GameObject value in rooms.Values)
			{
				AddTile(value, val);
			}
			ExtendedDungeonFlow val2 = (ExtendedDungeonFlow)AccessTools.Method(typeof(ExtendedDungeonFlow), "Create", (Type[])null, (Type[])null).Invoke(null, new object[4]
			{
				BuildFlow(),
				null,
				Vector3.zero,
				6
			});
			((Object)val2).name = "BrinebiteDinerExtendedFlow";
			val2.DungeonName = "Brinebite Diner";
			val2.MapTileSize = 1f;
			return val2;
		}
		catch (Exception arg)
		{
			Warn($"could not build the diner flow: {arg}");
			return null;
		}
	}

	internal static bool Finish(ExtendedDungeonFlow flow)
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		try
		{
			if (!finished)
			{
				if (!Furnish())
				{
					return false;
				}
				finished = true;
			}
			if ((Object)(object)flow.LevelMatchingProperties == (Object)null)
			{
				Warn("the diner flow has no matching properties");
				return false;
			}
			List<StringWithRarity> planetNames = flow.LevelMatchingProperties.planetNames;
			if (planetNames.All((StringWithRarity n) => n.Name != "Bikini Bottom"))
			{
				planetNames.Add(new StringWithRarity("Bikini Bottom", 300));
			}
			return true;
		}
		catch (Exception arg)
		{
			Warn($"could not furnish the diner: {arg}");
			return false;
		}
	}

	private static bool Furnish()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_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_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Expected O, but got Unknown
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		ExtendedDungeonFlow val = ((IEnumerable<ExtendedDungeonFlow>)PatchedContent.ExtendedDungeonFlows).FirstOrDefault((Func<ExtendedDungeonFlow, bool>)((ExtendedDungeonFlow f) => f.DungeonName == "Facility"));
		if ((Object)(object)val == (Object)null)
		{
			Warn("Facility dungeon not found");
			return false;
		}
		GameObject val2 = null;
		GameObject val3 = null;
		GameObject val4 = null;
		Quaternion tilt = Quaternion.identity;
		Quaternion tilt2 = Quaternion.identity;
		Quaternion tilt3 = Quaternion.identity;
		ItemGroup val5 = null;
		foreach (GameObject item in FacilityPrefabs(val.DungeonFlow))
		{
			SpawnSyncedObject[] componentsInChildren = item.GetComponentsInChildren<SpawnSyncedObject>(true);
			foreach (SpawnSyncedObject val6 in componentsInChildren)
			{
				GameObject spawnPrefab = val6.spawnPrefab;
				if ((Object)(object)spawnPrefab == (Object)null)
				{
					continue;
				}
				EntranceTeleport componentInChildren = spawnPrefab.GetComponentInChildren<EntranceTeleport>(true);
				if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.isEntranceToBuilding)
				{
					if (componentInChildren.entranceId == 0)
					{
						val2 = spawnPrefab;
						tilt = Tilt(((Component)val6).transform);
					}
					else
					{
						val3 = spawnPrefab;
						tilt2 = Tilt(((Component)val6).transform);
					}
				}
				else if ((Object)(object)spawnPrefab.GetComponentInChildren<EnemyVent>(true) != (Object)null)
				{
					val4 = spawnPrefab;
					tilt3 = Tilt(((Component)val6).transform);
				}
			}
			RandomScrapSpawn[] componentsInChildren2 = item.GetComponentsInChildren<RandomScrapSpawn>(true);
			foreach (RandomScrapSpawn val7 in componentsInChildren2)
			{
				if ((Object)(object)val7.spawnableItems != (Object)null && ((Object)val7.spawnableItems).name == "GeneralItemClass")
				{
					val5 = val7.spawnableItems;
				}
			}
		}
		GameObject val8 = FacilityPrefabs(val.DungeonFlow).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p.GetComponent<Tile>() == (Object)null && p.GetComponentsInChildren<SpawnSyncedObject>(true).Any((SpawnSyncedObject s) => (Object)(object)s.spawnPrefab != (Object)null && (Object)(object)s.spawnPrefab.GetComponentInChildren<DoorLock>(true) != (Object)null)));
		string[] array = (from m in new(bool, string)[5]
			{
				((Object)(object)val2 == (Object)null, "main entrance"),
				((Object)(object)val3 == (Object)null, "fire exit"),
				((Object)(object)val4 == (Object)null, "vent"),
				((Object)(object)val5 == (Object)null, "scrap group"),
				((Object)(object)val8 == (Object)null, "door")
			}
			where m.Item1
			select m.Item2).ToArray();
		if (array.Length != 0)
		{
			Warn("missing vanilla parts: " + string.Join(", ", array));
			return false;
		}
		foreach (Doorway item2 in rooms.Values.SelectMany((GameObject r) => r.GetComponentsInChildren<Doorway>(true)))
		{
			item2.ConnectorPrefabWeights = new List<GameObjectWeight>
			{
				new GameObjectWeight
				{
					GameObject = val8,
					Weight = 1f
				}
			};
		}
		log.LogInfo((object)("BRINEBITE interior: doors from " + ((Object)val8).name));
		int num2 = 0;
		int num3 = 0;
		foreach (GameObject item3 in RoomNames.Select((string n) => rooms[n]))
		{
			Transform[] componentsInChildren3 = item3.GetComponentsInChildren<Transform>(true);
			foreach (Transform val9 in componentsInChildren3)
			{
				ApplyMarker(val9);
				switch (InteriorMarker.Parse(((Object)val9).name))
				{
				case InteriorPart.EntranceSpot:
					Door(val9, val2, tilt);
					break;
				case InteriorPart.FireSpot:
					Door(val9, val3, tilt2);
					Prop(val9, 1231);
					break;
				case InteriorPart.VentSpot:
					Spawner(val9, val4, tilt3, val4.GetComponentInChildren<EnemyVent>(true).floorNode, val4.transform.position, 0f);
					Prop(val9, 5);
					num2++;
					break;
				case InteriorPart.ScrapSpot:
				{
					for (int num4 = 0; num4 < ((!(((Object)item3).name == "InteriorVault")) ? 1 : 6); num4++)
					{
						RandomScrapSpawn obj = ((Component)val9).gameObject.AddComponent<RandomScrapSpawn>();
						obj.spawnableItems = val5;
						obj.itemSpawnRange = ((((Object)item3).name == "InteriorVault") ? 1.6f : 1f);
					}
					num3++;
					break;
				}
				}
			}
		}
		log.LogInfo((object)$"BRINEBITE interior: diner ready tiles={rooms.Count} vents={num2} scrapSpots={num3}");
		return true;
	}

	private static IEnumerable<GameObject> FacilityPrefabs(DungeonFlow flow)
	{
		List<GameObject> list = (from w in (from s in flow.Nodes.SelectMany((GraphNode n) => n.TileSets).Concat(flow.Lines.SelectMany((GraphLine l) => l.DungeonArchetypes).SelectMany((DungeonArchetype a) => a.TileSets.Concat(a.BranchCapTileSets))).Concat(flow.TileInjectionRules.Select((TileInjectionRule r) => r.TileSet))
				where (Object)(object)s != (Object)null
				select s).SelectMany((TileSet s) => s.TileWeights.Weights)
			select w.Value into v
			where (Object)(object)v != (Object)null
			select v).Distinct().ToList();
		List<GameObject> second = (from p in list.SelectMany((GameObject t) => t.GetComponentsInChildren<Doorway>(true)).SelectMany((Doorway d) => d.ConnectorPrefabWeights.Select((GameObjectWeight w) => w.GameObject).Concat(d.BlockerPrefabWeights.Select((GameObjectWeight w) => w.GameObject)))
			where (Object)(object)p != (Object)null
			select p).Distinct().ToList();
		return list.Concat(second);
	}

	private static Quaternion Tilt(Transform spawner)
	{
		//IL_0001: 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_001b: Unknown result type (might be due to invalid IL or missing references)
		return Quaternion.Euler(spawner.eulerAngles.x, 0f, spawner.eulerAngles.z);
	}

	private static void Door(Transform marker, GameObject prefab, Quaternion tilt)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		EntranceTeleport componentInChildren = prefab.GetComponentInChildren<EntranceTeleport>(true);
		BoxCollider component = ((Component)componentInChildren).GetComponent<BoxCollider>();
		Vector3 anchor = (((Object)(object)component == (Object)null) ? ((Component)componentInChildren).transform.position : ((Component)component).transform.TransformPoint(component.center));
		Spawner(marker, prefab, tilt, componentInChildren.entrancePoint, anchor, 0.35f);
	}

	private static void Spawner(Transform marker, GameObject prefab, Quaternion tilt, Transform floorPoint, Vector3 anchor, float outFromWall)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: 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_004e: 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_0067: 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_006c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0087: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_00c3: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_00f8: 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_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: 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_012d: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: 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_0165: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		(Transform c, Vector3 position, Quaternion rotation)[] array = (from Transform c in (IEnumerable)marker
			select (c: c, position: c.position, rotation: c.rotation)).ToArray();
		Transform root = prefab.transform;
		Vector3 val = Relative(((Object)(object)floorPoint == (Object)null) ? root.position : floorPoint.position);
		Vector3 val2 = Relative(anchor);
		Vector3 val3 = val - val2;
		val3.y = 0f;
		Vector3 forward = marker.forward;
		Quaternion val4 = ((((Vector3)(ref val3)).magnitude > 0.1f) ? Quaternion.Euler(0f, Vector3.SignedAngle(val3, forward, Vector3.up), 0f) : marker.rotation);
		Vector3 val5 = marker.position + forward * outFromWall;
		Vector3 val6 = val4 * val2;
		marker.SetPositionAndRotation(new Vector3(val5.x - val6.x, marker.root.position.y + 0.1f - (val4 * val).y, val5.z - val6.z), val4 * tilt);
		(Transform, Vector3, Quaternion)[] array2 = array;
		for (int num = 0; num < array2.Length; num++)
		{
			var (val7, val8, val9) = array2[num];
			val7.SetPositionAndRotation(val8, val9);
		}
		((Component)marker).gameObject.AddComponent<SpawnSyncedObject>().spawnPrefab = prefab;
		log.LogInfo((object)($"BRINEBITE interior: {((Object)marker.root).name}/{((Object)marker).name} -> {((Object)prefab).name} floor={val:F2} anchor={val2:F2} " + $"scale={root.localScale:F2} tilt={((Quaternion)(ref tilt)).eulerAngles:F0} placed={marker.position:F2}"));
		Vector3 Relative(Vector3 world)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			return tilt * (Quaternion.Inverse(root.rotation) * (world - root.position));
		}
	}

	private static void Prop(Transform marker, int group)
	{
		GlobalProp obj = ((Component)marker).gameObject.AddComponent<GlobalProp>();
		obj.PropGroupID = group;
		obj.MainPathWeight = 1f;
		obj.BranchPathWeight = 1f;
		obj.DepthWeightScale = AnimationCurve.Linear(0f, 1f, 1f, 1f);
	}

	private static void ApplyMarker(Transform child)
	{
		if (SceneMarker.TryParse(((Object)child).name, out var tag, out var layer))
		{
			if (layer != null && LayerMask.NameToLayer(layer) >= 0)
			{
				((Component)child).gameObject.layer = LayerMask.NameToLayer(layer);
			}
			if (tag != null)
			{
				((Component)child).gameObject.tag = tag;
			}
		}
	}

	private static void AddTile(GameObject room, DoorwaySocket socket)
	{
		room.AddComponent<Tile>();
		FieldInfo fieldInfo = AccessTools.Field(typeof(Doorway), "socket");
		Transform[] componentsInChildren = room.GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (InteriorMarker.Parse(((Object)val).name) == InteriorPart.Doorway)
			{
				Doorway val2 = ((Component)val).gameObject.AddComponent<Doorway>();
				fieldInfo.SetValue(val2, socket);
				val2.BlockerSceneObjects = (from Transform c in (IEnumerable)val
					select ((Component)c).gameObject).ToList();
				val2.ConnectorSceneObjects = new List<GameObject>();
			}
		}
		if (!(((Object)room).name != "InteriorStairs"))
		{
			Doorway[] array = (from d in room.GetComponentsInChildren<Doorway>(true)
				orderby ((Component)d).transform.position.y descending
				select d).ToArray();
			Tile component = room.GetComponent<Tile>();
			component.Entrances = new List<Doorway> { array[0] };
			component.Exits = new List<Doorway> { array[^1] };
		}
	}

	private static DungeonFlow BuildFlow()
	{
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Expected O, but got Unknown
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Expected O, but got Unknown
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Expected O, but got Unknown
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Expected O, but got Unknown
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Expected O, but got Unknown
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Expected O, but got Unknown
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Expected O, but got Unknown
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Expected O, but got Unknown
		//IL_0392: Expected O, but got Unknown
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Expected O, but got Unknown
		//IL_03b5: Expected O, but got Unknown
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Expected O, but got Unknown
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_040e: Expected O, but got Unknown
		//IL_0413: Expected O, but got Unknown
		//IL_0414: Unknown result type (might be due to invalid IL or missing references)
		//IL_0419: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0428: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_0441: Unknown result type (might be due to invalid IL or missing references)
		//IL_044b: Expected O, but got Unknown
		//IL_044b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Expected O, but got Unknown
		//IL_0465: Expected O, but got Unknown
		TileSet item = Set("BrinebiteStartSet", ("InteriorStart", 1f));
		TileSet item2 = Set("BrinebitePathSet", ("InteriorCorridor", 3f), ("InteriorLongHall", 2f), ("InteriorCross", 2f), ("InteriorBend", 2f), ("InteriorHall", 1.5f), ("InteriorKitchen", 1.5f), ("InteriorStorage", 1.5f), ("InteriorBoiler", 1.5f), ("InteriorBanquet", 1f), ("InteriorGallery", 1f), ("InteriorStairs", 1f));
		TileSet item3 = Set("BrinebiteCapSet", ("InteriorDeadEnd", 1f), ("InteriorFreezer", 1f), ("InteriorCellar", 1f), ("InteriorQuarters", 1f));
		TileSet item4 = Set("BrinebiteVaultSet", ("InteriorVault", 1f));
		TileSet tileSet = Set("BrinebiteStairSet", ("InteriorStairs", 1f));
		TileSet tileSet2 = Set("BrinebiteCorridorSet", ("InteriorCorridor", 1f));
		DungeonArchetype val = ScriptableObject.CreateInstance<DungeonArchetype>();
		((Object)val).name = "BrinebiteArchetype";
		val.TileSets = new List<TileSet> { item2 };
		val.BranchCapTileSets = new List<TileSet> { item3 };
		val.BranchCapType = (BranchCapType)0;
		val.BranchingDepth = new IntRange(2, 3);
		val.BranchCount = new IntRange(0, 1);
		DungeonFlow val2 = ScriptableObject.CreateInstance<DungeonFlow>();
		((Object)val2).name = "BrinebiteDinerFlow";
		val2.Length = new IntRange(4, 4);
		val2.BranchCount = new IntRange(2, 3);
		val2.DoorwayConnectionChance = 0.5f;
		val2.Nodes = new List<GraphNode>
		{
			new GraphNode(val2)
			{
				NodeType = (NodeType)1,
				Position = 0f,
				Label = "Start",
				TileSets = new List<TileSet> { item }
			},
			new GraphNode(val2)
			{
				NodeType = (NodeType)2,
				Position = 1f,
				Label = "Goal",
				TileSets = new List<TileSet> { item4 }
			}
		};
		val2.Lines = new List<GraphLine>
		{
			new GraphLine(val2)
			{
				Position = 0f,
				Length = 1f,
				DungeonArchetypes = new List<DungeonArchetype> { val }
			}
		};
		val2.GlobalProps = new List<GlobalPropSettings>
		{
			new GlobalPropSettings
			{
				ID = 5,
				Count = new IntRange(7, 12)
			},
			new GlobalPropSettings
			{
				ID = 1231,
				Count = new IntRange(1, 1)
			}
		};
		val2.TileInjectionRules = new List<TileInjectionRule>
		{
			new TileInjectionRule
			{
				TileSet = tileSet2,
				IsRequired = true,
				CanAppearOnMainPath = true,
				CanAppearOnBranchPath = false,
				NormalizedPathDepth = new FloatRange(0.2f, 0.8f),
				NormalizedBranchDepth = new FloatRange(0f, 1f)
			},
			new TileInjectionRule
			{
				TileSet = tileSet,
				IsRequired = true,
				CanAppearOnMainPath = true,
				CanAppearOnBranchPath = false,
				NormalizedPathDepth = new FloatRange(0.25f, 0.75f),
				NormalizedBranchDepth = new FloatRange(0f, 1f)
			}
		};
		return val2;
	}

	private static TileSet Set(string name, params (string room, float weight)[] entries)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0059: 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: Expected O, but got Unknown
		TileSet val = ScriptableObject.CreateInstance<TileSet>();
		((Object)val).name = name;
		for (int i = 0; i < entries.Length; i++)
		{
			var (key, num) = entries[i];
			val.TileWeights.Weights.Add(new GameObjectChance
			{
				Value = rooms[key],
				MainPathWeight = num,
				BranchPathWeight = num,
				DepthWeightScale = AnimationCurve.Linear(0f, 1f, 1f, 1f),
				TileSet = val
			});
		}
		return val;
	}

	private static void Warn(string text)
	{
		log.LogWarning((object)("BRINEBITE interior: " + text));
	}
}
internal static class LunarEclipse
{
	public static readonly Color Tint = new Color(0.62f, 0.35f, 1f);

	public static bool? Force;

	private static SelectableLevel level;

	private static ManualLogSource log;

	private static int baseInside = -1;

	private static int baseOutside = -1;

	public static bool Active { get; private set; }

	public static void Enable(SelectableLevel moon, ManualLogSource logger)
	{
		//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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		level = moon;
		log = logger;
		Harmony val = new Harmony("com.lethalmoon.plugin.lunar");
		val.Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "SetPlanetsWeather", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LunarEclipse), "Decide", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "SetMapScreenInfoToCurrentLevel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LunarEclipse), "OnMapScreen", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Terminal), "TextPostProcess", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LunarEclipse), "OnTerminalText", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void SetBaseline(int inside, int outside)
	{
		baseInside = inside;
		baseOutside = outside;
		Apply();
	}

	public static void Decide()
	{
		//IL_0073: 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)
		StartOfRound instance = StartOfRound.Instance;
		if (!((Object)(object)instance == (Object)null) && !((Object)(object)level == (Object)null))
		{
			Active = Force ?? DinerRules.IsLunar(instance.randomMapSeed);
			if (Active)
			{
				level.currentWeather = (LevelWeatherType)5;
			}
			Apply();
			log.LogInfo((object)string.Format("BRINEBITE weather {0}{1} inside={2} outside={3}", level.currentWeather, Active ? " (lunar eclipse)" : "", level.maxEnemyPowerCount, level.maxOutsideEnemyPowerCount));
		}
	}

	private static void Apply()
	{
		if (!((Object)(object)level == (Object)null) && baseInside >= 0)
		{
			level.maxEnemyPowerCount = DinerRules.InsidePower(baseInside, Active);
			level.maxOutsideEnemyPowerCount = DinerRules.OutsidePower(baseOutside, Active);
		}
	}

	private static void OnMapScreen(StartOfRound __instance)
	{
		if (Active && (Object)(object)__instance.currentLevel == (Object)(object)level && (Object)(object)__instance.screenLevelDescription != (Object)null)
		{
			((TMP_Text)__instance.screenLevelDescription).text = DinerRules.LunarScreen(((TMP_Text)__instance.screenLevelDescription).text);
		}
	}

	private static void OnTerminalText(ref string __result)
	{
		if (Active && __result != null)
		{
			__result = DinerRules.LunarText(__result);
		}
	}

	public static IEnumerator Run(Scene scene)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			yield break;
		}
		Fog val = default(Fog);
		foreach (Volume item in ((Scene)(ref scene)).GetRootGameObjects().SelectMany((GameObject r) => r.GetComponentsInChildren<Volume>(true)))
		{
			if ((Object)(object)item.profile != (Object)null && item.profile.TryGet<Fog>(ref val))
			{
				((VolumeParameter<Color>)(object)val.albedo).Override(((VolumeParameter<Color>)(object)val.albedo).value * Tint);
				((VolumeParameter<Color>)(object)val.color).Override(((VolumeParameter<Color>)(object)val.color).value * Tint);
			}
		}
		GameObject val2 = new GameObject("BrinebiteLunarLook");
		SceneManager.MoveGameObjectToScene(val2, scene);
		Volume look = val2.AddComponent<Volume>();
		look.isGlobal = true;
		look.priority = 50f;
		VolumeProfile val3 = ScriptableObject.CreateInstance<VolumeProfile>();
		ColorAdjustments obj = val3.Add<ColorAdjustments>(false);
		((VolumeParameter<Color>)(object)obj.colorFilter).Override(new Color(0.85f, 0.5f, 1f));
		((VolumeParameter<float>)(object)obj.saturation).Override(15f);
		look.sharedProfile = val3;
		StartOfRound start = StartOfRound.Instance;
		bool warned = false;
		while ((Object)(object)look != (Object)null && ((Scene)(ref scene)).isLoaded)
		{
			PlayerControllerB val4 = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.localPlayerController);
			if ((Object)(object)val4 != (Object)null && val4.isPlayerDead && (Object)(object)val4.spectatedPlayerScript != (Object)null)
			{
				val4 = val4.spectatedPlayerScript;
			}
			look.weight = (((Object)(object)val4 != (Object)null && val4.isInsideFactory) ? 0f : 1f);
			if (!warned && start.shipHasLanded)
			{
				warned = true;
				yield return (object)new WaitForSeconds(3f);
				if ((Object)(object)HUDManager.Instance != (Object)null)
				{
					HUDManager.Instance.DisplayTip("LUNAR ECLIPSE", "The moon has turned purple. Far more of them are out tonight.", true, false, "LC_Tip1");
				}
				log.LogInfo((object)"BRINEBITE lunar eclipse: landed");
			}
			yield return (object)new WaitForSeconds(0.2f);
		}
	}
}
internal static class MoonClock
{
	public static IEnumerator Run(Scene scene)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		float nextShow = 0f;
		while (((Scene)(ref scene)).isLoaded)
		{
			TimeOfDay instance = TimeOfDay.Instance;
			HUDManager instance2 = HUDManager.Instance;
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.localPlayerController);
			if ((Object)(object)instance != (Object)null && (Object)(object)instance2 != (Object)null && (Object)(object)val != (Object)null && instance.currentDayTimeStarted && (Object)(object)instance.sunAnimator == (Object)null)
			{
				instance.normalizedTimeOfDay = instance.currentDayTime / instance.totalTime;
				PlayerControllerB val2 = ((val.isPlayerDead && (Object)(object)val.spectatedPlayerScript != (Object)null) ? val.spectatedPlayerScript : val);
				instance2.SetClockVisible(!val2.isInsideFactory);
				if (Time.time >= nextShow)
				{
					nextShow = Time.time + 1f;
					instance2.SetClock(instance.normalizedTimeOfDay, (float)instance.numberOfHours, true);
				}
			}
			yield return null;
		}
	}
}
public static class NightCurrent
{
	public const int Cycles = 14;

	public const float Share = 0.35f;

	public const float Top = 3.5f;

	public const float Ramp = 1f;

	public const float WarnSeconds = 2f;

	private const float DarkEnough = 0.5f;

	public static (float dx, float dz, float strength) Gust(float time, float night, float daySeconds)
	{
		if (night < 0.5f)
		{
			return (dx: 0f, dz: 0f, strength: 0f);
		}
		float num = time * 14f;
		int num2 = (int)Math.Floor(num);
		float num3 = num - (float)num2;
		if (num3 >= 0.35f)
		{
			return (dx: 0f, dz: 0f, strength: 0f);
		}
		float num4 = daySeconds / 14f;
		float val = num3 * num4 / 1f;
		float val2 = (0.35f - num3) * num4 / 1f;
		float item = 3.5f * Math.Min(1f, Math.Min(val, val2));
		float num5 = (float)(uint)((num2 * -1640531535 >>> 8) & 0xFFFF) / 65536f * 2f * MathF.PI;
		return (dx: (float)Math.Cos(num5), dz: (float)Math.Sin(num5), strength: item);
	}

	public static bool Warning(float time, float night, float daySeconds)
	{
		if (night < 0.5f)
		{
			return false;
		}
		float num = time * 14f - (float)Math.Floor(time * 14f);
		if (num < 0.35f)
		{
			return false;
		}
		return (1f - num) * daySeconds / 14f <= 2f;
	}
}
internal static class NightCurrentRun
{
	internal static float? TimeOverride;

	public static IEnumerator Run(Scene scene, ManualLogSource log)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		AudioSource hum = new GameObject("BrinebiteCurrentHum").AddComponent<AudioSource>();
		SceneManager.MoveGameObjectToScene(((Component)hum).gameObject, scene);
		hum.clip = Synth.Whoosh();
		hum.loop = true;
		hum.spatialBlend = 0f;
		hum.volume = 0f;
		hum.Play();
		int slot = -1;
		Vector3 val2 = default(Vector3);
		while (((Scene)(ref scene)).isLoaded && (Object)(object)hum != (Object)null)
		{
			StartOfRound instance = StartOfRound.Instance;
			TimeOfDay instance2 = TimeOfDay.Instance;
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.localPlayerController);
			float num = 0f;
			if ((Object)(object)instance2 != (Object)null && (Object)(object)val != (Object)null && instance.shipHasLanded && !instance.shipIsLeaving)
			{
				float num2 = TimeOverride ?? instance2.normalizedTimeOfDay;
				float night = SkyCycle.NightAmount(num2);
				float daySeconds = instance2.totalTime / Mathf.Max(0.01f, instance2.globalTimeSpeedMultiplier);
				(float, float, float) tuple = NightCurrent.Gust(num2, night, daySeconds);
				bool flag = !val.isPlayerDead && !val.isInsideFactory && !val.isInHangarShipRoom && ((Collider)val.thisController).enabled;
				if (flag && tuple.Item3 > 0f)
				{
					int num3 = Mathf.FloorToInt(num2 * 14f);
					if (num3 != slot)
					{
						slot = num3;
						log.LogInfo((object)$"BRINEBITE current: gust {num3} dir=({tuple.Item1:F2},{tuple.Item2:F2})");
					}
					((Vector3)(ref val2))..ctor(tuple.Item1, 0f, tuple.Item2);
					Vector3 val3 = val.externalForces;
					float num4 = Vector3.Dot(val3, val2);
					if (num4 < tuple.Item3)
					{
						val3 += val2 * (tuple.Item3 - num4);
					}
					val.externalForces = val3;
					num = tuple.Item3 / 3.5f * 0.7f;
				}
				else if (flag && NightCurrent.Warning(num2, night, daySeconds))
				{
					num = 0.12f;
				}
			}
			hum.volume = Mathf.MoveTowards(hum.volume, num, Time.deltaTime * 0.6f);
			yield return null;
		}
	}
}
internal static class OutdoorGuests
{
	private const int Beehives = 4;

	private const int LocustsAtLeast = 3;

	private const int LocustsAtMost = 6;

	private const float AwayFromShip = 45f;

	private const float Apart = 25f;

	public static IEnumerator Run(Scene scene, ManualLogSource log)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		StartOfRound start = StartOfRound.Instance;
		while (((Scene)(ref scene)).isLoaded && !start.shipHasLanded)
		{
			yield return null;
		}
		yield return (object)new WaitForSeconds(5f);
		EnemyType[] types;
		List<Vector3> open;
		List<Vector3> taken;
		if (((Scene)(ref scene)).isLoaded && !start.shipIsLeaving && ((NetworkBehaviour)RoundManager.Instance).IsServer)
		{
			types = Resources.FindObjectsOfTypeAll<EnemyType>();
			Vector3 ship = new Vector3(2.76f, 0f, -13.86f);
			open = (from n in GameObject.FindGameObjectsWithTag("OutsideAINode")
				select n.transform.position into _
				where Vector2.Distance(new Vector2(_.x, _.z), new Vector2(ship.x, ship.z)) > 45f
				orderby Random.value
				select _).ToList();
			taken = new List<Vector3>();
			int num = Send("RadMech", DinerRules.OldBirds(LunarEclipse.Active));
			int num2 = Send("Red Locust Bees", 4);
			int num3 = Send("Docile Locust Bees", Random.Range(3, 7));
			log.LogInfo((object)$"BRINEBITE guests: oldBirds={num} beehives={num2} locustSwarms={num3}");
		}
		int Send(string name, int count)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			EnemyType val = ((IEnumerable<EnemyType>)types).FirstOrDefault((Func<EnemyType, bool>)((EnemyType t) => t.enemyName == name && (Object)(object)t.enemyPrefab != (Object)null));
			if ((Object)(object)val == (Object)null)
			{
				log.LogWarning((object)("BRINEBITE guests: no enemy called '" + name + "' (" + string.Join(", ", types.Select((EnemyType t) => t.enemyName).Distinct()) + ")"));
				return 0;
			}
			int num4 = 0;
			foreach (Vector3 spot in open)
			{
				if (num4 >= count)
				{
					break;
				}
				if (!taken.Any((Vector3 t) => Vector3.Distance(t, spot) < 25f))
				{
					if (val.requireNestObjectsToSpawn)
					{
						RoundManager.Instance.SpawnNestObjectForOutsideEnemy(val, new Random(start.randomMapSeed + num4));
					}
					RoundManager.Instance.SpawnEnemyGameObject(spot, Random.Range(0f, 360f), -1, val);
					taken.Add(spot);
					num4++;
				}
			}
			return num4;
		}
	}
}
[BepInPlugin("com.lethalmoon.plugin", "LethalMoon", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"LethalMoon 0.1.0 loaded");
		SceneSetup.Enable(((BaseUnityPlugin)this).Logger);
		AutoLandingTest.Enable(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), ((BaseUnityPlugin)this).Logger);
		BrinebiteMoon.Register(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), ((BaseUnityPlugin)this).Logger);
	}
}
public static class SceneMarker
{
	public static bool TryParse(string name, out string tag, out string layer)
	{
		tag = null;
		layer = null;
		string[] array = name.Split('@');
		for (int i = 1; i < array.Length; i++)
		{
			string[] array2 = array[i].Split('=');
			if (array2.Length == 2 && array2[1].Trim().Length != 0)
			{
				if (array2[0] == "tag")
				{
					tag = array2[1].Trim();
				}
				else if (array2[0] == "layer")
				{
					layer = array2[1].Trim();
				}
			}
		}
		if (tag == null)
		{
			return layer != null;
		}
		return true;
	}

	public static bool TryParseEntrance(s