Decompiled source of Welcome To Ooblterra v1.2.0

Welcome_To_Ooblterra.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering.HighDefinition;
using Welcome_To_Ooblterra.Enemies;
using Welcome_To_Ooblterra.Enemies.EnemyThings;
using Welcome_To_Ooblterra.Items;
using Welcome_To_Ooblterra.Patches;
using Welcome_To_Ooblterra.Properties;
using Welcome_To_Ooblterra.RoomBehaviors;
using Welcome_To_Ooblterra.Things;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Welcome_To_Ooblterra")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Welcome_To_Ooblterra")]
[assembly: AssemblyCopyright("Copyright © Skeleton Studios 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ef012de-dac8-42a5-b383-0c7886f684ae")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.8.9042.31329")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace Welcome_To_Ooblterra
{
	internal class WTONetworkHandler : NetworkBehaviour
	{
		public static WTONetworkHandler Instance { get; private set; }

		public static event Action<string> LevelEvent;

		public override void OnNetworkSpawn()
		{
			WTONetworkHandler.LevelEvent = null;
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				WTONetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		[ClientRpc]
		public void EventClientRpc(string eventName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1907558404u, val, (RpcDelivery)0);
				bool flag = eventName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1907558404u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				WTONetworkHandler.LevelEvent?.Invoke(eventName);
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_WTONetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1907558404u, new RpcReceiveHandler(__rpc_handler_1907558404));
		}

		private static void __rpc_handler_1907558404(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string eventName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((WTONetworkHandler)(object)target).EventClientRpc(eventName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "WTONetworkHandler";
		}
	}
}
namespace Welcome_To_Ooblterra.Properties
{
	[HideInInspector]
	public enum SuitStatus
	{
		Enable,
		Purchase,
		Disable,
		SleepsSpecial
	}
	public enum PosterStatus
	{
		ReplaceVanilla,
		AddAsDecor,
		Disable
	}
	public enum FootstepEnum
	{
		Enable,
		Quiet,
		Disable
	}
	public enum TiedToLabEnum
	{
		WTOOnly,
		AppendWTO,
		UseMoonDefault
	}
	[BepInPlugin("SkullCrusher.WTO", "Welcome To Ooblterra", "1.1.0")]
	public class WTOBase : BaseUnityPlugin
	{
		private const string modGUID = "SkullCrusher.WTO";

		private const string modName = "Welcome To Ooblterra";

		private const string modVersion = "1.1.0";

		private readonly Harmony WTOHarmony = new Harmony("SkullCrusher.WTO");

		public static ManualLogSource WTOLogSource;

		public static WTOBase Instance;

		public static AssetBundle LevelAssetBundle;

		public static AssetBundle ItemAssetBundle;

		public static AssetBundle FactoryAssetBundle;

		public static AssetBundle MonsterAssetBundle;

		public const string RootPath = "Assets/Resources/WelcomeToOoblterra/";

		public static ConfigEntry<bool> WTODebug;

		public static ConfigEntry<bool> WTOCustomSuits;

		public static ConfigEntry<bool> WTOCustomPoster;

		public static ConfigEntry<bool> WTOScalePrice;

		public static ConfigEntry<string> WTOHazardList;

		public static ConfigEntry<string> WTOHazardMoonList;

		public static ConfigEntry<int> WTOFootsteps;

		public static ConfigEntry<int> WTOMusic;

		public static ConfigEntry<TiedToLabEnum> WTOForceHazards;

		public static ConfigEntry<TiedToLabEnum> WTOForceInsideMonsters;

		public static ConfigEntry<TiedToLabEnum> WTOForceOutsideMonsters;

		public static ConfigEntry<TiedToLabEnum> WTOForceDaytimeMonsters;

		public static ConfigEntry<TiedToLabEnum> WTOForceScrap;

		public static ConfigEntry<bool> WTOForceOutsideOnly;

		public static ConfigEntry<int> WTOWeightScale;

		[HarmonyPatch(typeof(StartOfRound), "Update")]
		[HarmonyPostfix]
		public static void DebugHelper(StartOfRound __instance)
		{
		}

		private void Awake()
		{
			WTODebug = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Debugging", "Print Debug Strings", false, "Whether or not to write WTO's debug print-strings to the log.");
			WTOFootsteps = ((BaseUnityPlugin)this).Config.Bind<int>("2. Accessibility", "Footstep Sounds", 100, "Adjust the volume of 523 Ooblterra's custom footstep sound. Binds between 0 and 100.");
			WTOMusic = ((BaseUnityPlugin)this).Config.Bind<int>("2. Accessibility", "Music Volume", 100, "Adjust the volume of 523-Ooblterra's custom Time-Of-Day music. Binds between 0 and 100.");
			WTOCustomSuits = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Ship Stuff", "Custom Suit Status", true, "Whether or not to add WTO's custom suits.");
			WTOCustomPoster = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Ship Stuff", "Visit Ooblterra Poster Status", true, "Whether or not to add WTO's custom poster.");
			WTOHazardList = ((BaseUnityPlugin)this).Config.Bind<string>("4. Map Hazards", "Custom Hazard List", "SpikeTrap, TeslaCoil, BabyLurkerEgg, BearTrap", "A list of all of WTO's custom hazards to enable. Affects 523-Ooblterra, and also has influence on the settings below.");
			WTOForceHazards = ((BaseUnityPlugin)this).Config.Bind<TiedToLabEnum>("5. Modpack Controls", "Bind WTO Hazards to Oobl Lab", TiedToLabEnum.WTOOnly, "Whether the Oobl Lab should always spawn with its own hazards, regardless of moon. See the wiki on Thunderstore for more information.");
			WTOForceInsideMonsters = ((BaseUnityPlugin)this).Config.Bind<TiedToLabEnum>("5. Modpack Controls", "Bind WTO Inside Enemies to Oobl Lab", TiedToLabEnum.WTOOnly, "Whether the Oobl Lab should always spawn with its own inside enemies, regardless of moon. See the wiki on Thunderstore for more information.");
			WTOForceOutsideMonsters = ((BaseUnityPlugin)this).Config.Bind<TiedToLabEnum>("5. Modpack Controls", "Bind WTO Outside Enemies to Oobl Lab", TiedToLabEnum.WTOOnly, "Whether the Oobl Lab should always spawn with 523 Ooblterra's outside enemies, regardless of moon. See the wiki on Thunderstore for more information.");
			WTOForceDaytimeMonsters = ((BaseUnityPlugin)this).Config.Bind<TiedToLabEnum>("5. Modpack Controls", "Bind WTO Daytime Enemies to Oobl Lab", TiedToLabEnum.WTOOnly, "Whether the Oobl Lab should always spawn with 523 Ooblterra's daytime enemies, regardless of moon. See the wiki on Thunderstore for more information.");
			WTOForceScrap = ((BaseUnityPlugin)this).Config.Bind<TiedToLabEnum>("5. Modpack Controls", "Bind WTO Scrap to Oobl Lab", TiedToLabEnum.WTOOnly, "Whether the Oobl Lab should always spawn with its own scrap, regardless of moon. See the wiki on Thunderstore for more information.");
			WTOWeightScale = ((BaseUnityPlugin)this).Config.Bind<int>("5. Modpack Controls", "WTOAppend Weight Scale", 1, "For any setting configured to WTOAppend above, this setting multiplies that thing's weight before appending it to list.");
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			WTOLogSource = Logger.CreateLogSource("SkullCrusher.WTO");
			WTOHarmony.PatchAll(typeof(WTOBase));
			WTOHarmony.PatchAll(typeof(FactoryPatch));
			WTOHarmony.PatchAll(typeof(ItemPatch));
			WTOHarmony.PatchAll(typeof(MonsterPatch));
			WTOHarmony.PatchAll(typeof(MoonPatch));
			WTOHarmony.PatchAll(typeof(SuitPatch));
			WTOHarmony.PatchAll(typeof(TerminalPatch));
			LogToConsole("BEGIN PRINTING LOADED ASSETS");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "customdungeon");
			FactoryAssetBundle = AssetBundle.LoadFromFile(text);
			string text2 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "customitems");
			ItemAssetBundle = AssetBundle.LoadFromFile(text2);
			string text3 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "custommoon");
			LevelAssetBundle = AssetBundle.LoadFromFile(text3);
			string text4 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "customenemies");
			MonsterAssetBundle = AssetBundle.LoadFromFile(text4);
			MoonPatch.Start();
			FactoryPatch.Start();
			ItemPatch.Start();
			MonsterPatch.Start();
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		public void Update()
		{
		}

		public static T ContextualLoadAsset<T>(AssetBundle Bundle, string PathToAsset, bool LogLoading = true) where T : Object
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)Application.platform == 7)
			{
				string text = PathToAsset.Substring(17);
				text = text.Substring(0, text.LastIndexOf("."));
				if (LogLoading)
				{
					LogToConsole("Loading " + text + " from resources folder...", AddFlair: true, ForcePrint: true);
				}
				return Resources.Load<T>(text);
			}
			int length = PathToAsset.Length - PathToAsset.LastIndexOf("/");
			string text2 = PathToAsset.Substring(PathToAsset.LastIndexOf("/"), length);
			if (LogLoading)
			{
				LogToConsole("Loading " + text2 + " from " + ((Object)Bundle).name + "...", AddFlair: true, ForcePrint: true);
			}
			return Bundle.LoadAsset<T>(PathToAsset);
		}

		public static void LogToConsole(string text, bool AddFlair = true, bool ForcePrint = false)
		{
			if (AddFlair)
			{
				text = "=======" + text + "=======";
			}
			if (WTODebug.Value || ForcePrint)
			{
				WTOLogSource.LogMessage((object)text);
			}
		}

		public static List<string> CSVSeperatedStringList(string InputString)
		{
			List<string> list = new List<string>();
			InputString = InputString.Replace(" ", "");
			InputString = InputString.ToLower();
			return InputString.Split(new char[1] { ',' }).ToList();
		}
	}
}
namespace Welcome_To_Ooblterra.Patches
{
	internal class ItemPatch
	{
		public class ItemData
		{
			private string AssetName;

			private int Rarity;

			private Item Itemref;

			public ItemData(string name, int rarity)
			{
				AssetName = "Assets/Resources/WelcomeToOoblterra/CustomItems/" + name;
				Rarity = rarity;
			}

			public string GetItemPath()
			{
				return AssetName;
			}

			public int GetRarity()
			{
				return Rarity;
			}

			public void SetItem(Item ItemToSet)
			{
				Itemref = ItemToSet;
			}

			public Item GetItem()
			{
				return Itemref;
			}
		}

		private static AudioClip CachedDiscoBallMusic;

		private static AudioClip OoblterraDiscoMusic;

		private static readonly AssetBundle ItemBundle = WTOBase.ItemAssetBundle;

		private const string ItemPath = "Assets/Resources/WelcomeToOoblterra/CustomItems/";

		private static Dictionary<string, List<SpawnableItemWithRarity>> MoonsToItemLists = new Dictionary<string, List<SpawnableItemWithRarity>>();

		public static ItemData[] ItemList = new ItemData[11]
		{
			new ItemData("AlienCrate.asset", 30),
			new ItemData("FiveSixShovel.asset", 10),
			new ItemData("HandCrystal.asset", 30),
			new ItemData("OoblCorpse.asset", 5),
			new ItemData("StatueSmall.asset", 40),
			new ItemData("WandCorpse.asset", 5),
			new ItemData("WandFeed.asset", 20),
			new ItemData("SprintTotem.asset", 25),
			new ItemData("CursedTotem.asset", 20),
			new ItemData("Chems.asset", 0),
			new ItemData("Battery.asset", 0)
		};

		[HarmonyPatch(typeof(RoundManager), "SetLockedDoors")]
		[HarmonyPrefix]
		private static void ReplaceKeys(RoundManager __instance)
		{
			if (!(__instance.currentLevel.PlanetName != MoonPatch.MoonFriendlyName))
			{
				GameObject keyPrefab = Object.Instantiate<GameObject>(WTOBase.ContextualLoadAsset<GameObject>(ItemBundle, "Assets/Resources/WelcomeToOoblterra/CustomItems/OoblKey.prefab", LogLoading: true), __instance.mapPropsContainer.transform);
				__instance.keyPrefab = keyPrefab;
			}
		}

		[HarmonyPatch(typeof(CozyLights), "SetAudio")]
		[HarmonyPrefix]
		private static bool ReplaceDiscoBall(CozyLights __instance)
		{
			if (StartOfRound.Instance.currentLevel.PlanetName != MoonPatch.MoonFriendlyName)
			{
				if ((Object)(object)__instance.turnOnAudio != (Object)null)
				{
					__instance.turnOnAudio.clip = CachedDiscoBallMusic;
				}
				return true;
			}
			if ((Object)(object)__instance.turnOnAudio != (Object)null)
			{
				__instance.turnOnAudio.clip = OoblterraDiscoMusic;
			}
			return true;
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void SetItemsWTO(RoundManager __instance)
		{
			string planetName = __instance.currentLevel.PlanetName;
			if ((Object)(object)DungeonManager.CurrentExtendedDungeonFlow != (Object)(object)FactoryPatch.OoblDungeonFlow)
			{
				if (MoonsToItemLists.TryGetValue(planetName, out var value))
				{
					__instance.currentLevel.spawnableScrap = value;
				}
			}
			else
			{
				SetItemStuff(WTOBase.WTOForceScrap.Value, ref __instance.currentLevel.spawnableScrap, MoonsToItemLists[MoonPatch.MoonFriendlyName]);
			}
		}

		public static void Start()
		{
			ItemData[] itemList = ItemList;
			foreach (ItemData itemData in itemList)
			{
				Item val = WTOBase.ContextualLoadAsset<Item>(ItemBundle, itemData.GetItemPath(), LogLoading: true);
				NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
				Items.RegisterScrap(val, itemData.GetRarity(), (LevelTypes)1);
				itemData.SetItem(val);
			}
			NetworkPrefabs.RegisterNetworkPrefab(WTOBase.ContextualLoadAsset<GameObject>(ItemBundle, "Assets/Resources/WelcomeToOoblterra/CustomItems/OoblKey.prefab", LogLoading: true));
			CachedDiscoBallMusic = WTOBase.ContextualLoadAsset<AudioClip>(ItemBundle, "Assets/Resources/WelcomeToOoblterra/CustomItems/Boombox6QuestionMark.ogg", LogLoading: false);
			OoblterraDiscoMusic = WTOBase.ContextualLoadAsset<AudioClip>(ItemBundle, "Assets/Resources/WelcomeToOoblterra/CustomItems/ooblboombox.ogg", LogLoading: false);
			if (!MoonsToItemLists.ContainsKey(MoonPatch.MoonFriendlyName))
			{
				MoonsToItemLists.Add(MoonPatch.MoonFriendlyName, MoonPatch.OoblterraExtendedLevel.SelectableLevel.spawnableScrap);
			}
		}

		private static void SetItemStuff(TiedToLabEnum TiedToLabState, ref List<SpawnableItemWithRarity> CurrentMoonItemList, List<SpawnableItemWithRarity> OoblterraItemList)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			List<SpawnableItemWithRarity> list = new List<SpawnableItemWithRarity>();
			foreach (SpawnableItemWithRarity OoblterraItem in OoblterraItemList)
			{
				list.Add(new SpawnableItemWithRarity
				{
					spawnableItem = OoblterraItem.spawnableItem,
					rarity = OoblterraItem.rarity * WTOBase.WTOWeightScale.Value
				});
			}
			switch (TiedToLabState)
			{
			case TiedToLabEnum.WTOOnly:
				CurrentMoonItemList = OoblterraItemList;
				break;
			case TiedToLabEnum.AppendWTO:
				CurrentMoonItemList.AddRange(list);
				break;
			}
		}
	}
	internal class TerminalPatch
	{
		public static Dictionary<int, int> LogDictionary = new Dictionary<int, int>();

		private const string TerminalPath = "Assets/Resources/WelcomeToOoblterra/CustomTerminal/";

		private static List<TerminalKeyword> KeywordList;

		private static List<TerminalNode> NodeList = new List<TerminalNode>();

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void AddLogs()
		{
			LoadLogKeywords();
			LoadLogNodes();
			LoadStoryLogs();
		}

		private static void LoadLogKeywords()
		{
			KeywordList = new List<TerminalKeyword>
			{
				WTOBase.ContextualLoadAsset<TerminalKeyword>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile1Keyword.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalKeyword>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile2Keyword.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalKeyword>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile3Keyword.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalKeyword>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile4Keyword.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalKeyword>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile5Keyword.asset", LogLoading: true)
			};
		}

		private static void LoadLogNodes()
		{
			NodeList = new List<TerminalNode>
			{
				WTOBase.ContextualLoadAsset<TerminalNode>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile1.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalNode>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile2.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalNode>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile3.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalNode>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile4.asset", LogLoading: true),
				WTOBase.ContextualLoadAsset<TerminalNode>(MoonPatch.LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomTerminal/WTOLogFile5.asset", LogLoading: true)
			};
		}

		private static void LoadStoryLogs()
		{
			try
			{
				Object.FindObjectOfType<Terminal>().logEntryFiles.First((TerminalNode x) => x.creatureName == NodeList[0].creatureName);
				return;
			}
			catch
			{
				WTOBase.LogToConsole("WTO Story logs not found in list. Attempting to add...");
			}
			int num = Object.FindObjectOfType<Terminal>().logEntryFiles.Count;
			TerminalKeyword val = Object.FindObjectOfType<Terminal>().terminalNodes.allKeywords[19];
			List<int> list = new List<int> { 5231111, 5231112, 5231113, 5231114, 5231115 };
			bool flag = false;
			TerminalKeyword[] allKeywords = Object.FindObjectOfType<Terminal>().terminalNodes.allKeywords;
			foreach (TerminalKeyword val2 in allKeywords)
			{
				if (val2.word == "mack1")
				{
					flag = true;
				}
			}
			for (int j = 0; j < NodeList.Count; j++)
			{
				WTOBase.LogToConsole($"nextIndex = {num}");
				KeywordList[j].defaultVerb = val;
				NodeList[j].storyLogFileID = num;
				Object.FindObjectOfType<Terminal>().logEntryFiles.Add(NodeList[j]);
				try
				{
					LogDictionary.Add(list[j], num);
				}
				catch
				{
				}
				if (!flag)
				{
					Extensions.AddCompatibleNoun(val, KeywordList[j], NodeList[j]);
					num++;
				}
			}
			Object.FindObjectOfType<Terminal>().terminalNodes.allKeywords = Object.FindObjectOfType<Terminal>().terminalNodes.allKeywords.Concat(KeywordList).ToArray();
			WTOBase.LogToConsole("END ADD WTO STORY LOGS!");
		}
	}
	internal class FactoryPatch
	{
		public static EntranceTeleport MainExit;

		public static EntranceTeleport FireExit;

		private static readonly AssetBundle FactoryBundle = WTOBase.FactoryAssetBundle;

		private const string DungeonPath = "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Data/";

		private const string BehaviorPath = "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Behaviors/";

		private const string SecurityPath = "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Security/";

		private const string DoorPath = "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Doors/";

		public static List<SpawnableMapObject> SecurityList = new List<SpawnableMapObject>();

		public static ExtendedDungeonFlow OoblDungeonFlow;

		[HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")]
		[HarmonyPrefix]
		private static bool WTOSpawnMapObjects(RoundManager __instance)
		{
			//IL_0308: 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_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			if (WTOBase.WTOForceHazards.Value == TiedToLabEnum.UseMoonDefault && __instance.currentLevel.PlanetName != MoonPatch.MoonFriendlyName)
			{
				return true;
			}
			if ((Object)(object)DungeonManager.CurrentExtendedDungeonFlow != (Object)(object)OoblDungeonFlow)
			{
				return true;
			}
			if (__instance.currentLevel.spawnableMapObjects == null || __instance.currentLevel.spawnableMapObjects.Length == 0)
			{
				return true;
			}
			Random random = new Random(StartOfRound.Instance.randomMapSeed + 587);
			__instance.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
			RandomMapObject[] array = Object.FindObjectsOfType<RandomMapObject>();
			List<string> list = WTOBase.CSVSeperatedStringList(WTOBase.WTOHazardList.Value);
			if (WTOBase.WTOForceHazards.Value != 0)
			{
				SpawnableMapObject[] spawnableMapObjects = __instance.currentLevel.spawnableMapObjects;
				foreach (SpawnableMapObject val in spawnableMapObjects)
				{
					list.Add(((Object)val.prefabToSpawn).name.ToLower());
				}
			}
			for (int j = 0; j < __instance.currentLevel.spawnableMapObjects.Length; j++)
			{
				if (!list.Contains(((Object)__instance.currentLevel.spawnableMapObjects[j].prefabToSpawn).name.ToLower()))
				{
					WTOBase.LogToConsole("Object " + ((Object)__instance.currentLevel.spawnableMapObjects[j].prefabToSpawn).name.ToLower() + " not found in valid spawn list!");
					continue;
				}
				List<RandomMapObject> list2 = new List<RandomMapObject>();
				int num = (int)__instance.currentLevel.spawnableMapObjects[j].numberToSpawn.Evaluate((float)random.NextDouble());
				WTOBase.WTOLogSource.LogInfo((object)$"Attempting to spawn {__instance.currentLevel.spawnableMapObjects[j].prefabToSpawn}; Quantity: {num}");
				if (__instance.increasedMapHazardSpawnRateIndex == j)
				{
					num = Mathf.Min(num * 2, 150);
				}
				if (num <= 0)
				{
					continue;
				}
				for (int k = 0; k < array.Length; k++)
				{
					string text = "";
					foreach (GameObject spawnablePrefab in array[k].spawnablePrefabs)
					{
						if (object.Equals(spawnablePrefab, __instance.currentLevel.spawnableMapObjects[j].prefabToSpawn))
						{
							list2.Add(array[k]);
						}
						text = text + ((object)spawnablePrefab)?.ToString() + ", ";
					}
				}
				for (int l = 0; l < num; l++)
				{
					if (list2.Count <= 0)
					{
						WTOBase.WTOLogSource.LogInfo((object)"Objects will not spawn; no valid random spots found!");
						break;
					}
					RandomMapObject val2 = list2[random.Next(0, list2.Count)];
					Vector3 position = ((Component)val2).transform.position;
					GameObject val3 = Object.Instantiate<GameObject>(__instance.currentLevel.spawnableMapObjects[j].prefabToSpawn, position, ((Component)val2).transform.rotation, __instance.mapPropsContainer.transform);
					val3.GetComponent<NetworkObject>().Spawn(true);
					WTOBase.WTOLogSource.LogInfo((object)$"Spawned new {val3}");
					list2.Remove(val2);
				}
			}
			return false;
		}

		public static void Start()
		{
			OoblDungeonFlow = WTOBase.ContextualLoadAsset<ExtendedDungeonFlow>(FactoryBundle, "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Data/OoblLabExtendedDungeonFlow.asset", LogLoading: true);
			PatchedContent.RegisterExtendedDungeonFlow(OoblDungeonFlow);
			NetworkPrefabs.RegisterNetworkPrefab(WTOBase.ContextualLoadAsset<GameObject>(FactoryBundle, "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Behaviors/ChargedBattery.prefab", LogLoading: true));
			NetworkPrefabs.RegisterNetworkPrefab(WTOBase.ContextualLoadAsset<GameObject>(FactoryBundle, "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Security/TeslaCoil.prefab", LogLoading: true));
			NetworkPrefabs.RegisterNetworkPrefab(WTOBase.ContextualLoadAsset<GameObject>(FactoryBundle, "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Security/SpikeTrap.prefab", LogLoading: true));
			NetworkPrefabs.RegisterNetworkPrefab(WTOBase.ContextualLoadAsset<GameObject>(FactoryBundle, "Assets/Resources/WelcomeToOoblterra/CustomDungeon/Security/BabyLurkerEgg.prefab", LogLoading: true));
		}
	}
	internal class MonsterPatch
	{
		public static List<SpawnableEnemyWithRarity> InsideEnemies = new List<SpawnableEnemyWithRarity>();

		public static List<SpawnableEnemyWithRarity> OutsideEnemies = new List<SpawnableEnemyWithRarity>();

		public static List<SpawnableEnemyWithRarity> DaytimeEnemies = new List<SpawnableEnemyWithRarity>();

		public static List<SpawnableEnemyWithRarity> AdultWandererContainer = new List<SpawnableEnemyWithRarity>();

		private static readonly AssetBundle EnemyBundle = WTOBase.MonsterAssetBundle;

		private const string EnemyPath = "Assets/Resources/WelcomeToOoblterra/CustomEnemies/";

		private static bool EnemiesInList;

		public const bool ShouldDebugEnemies = true;

		private static Dictionary<string, List<SpawnableEnemyWithRarity>> MoonsToInsideSpawnLists = new Dictionary<string, List<SpawnableEnemyWithRarity>>();

		private static Dictionary<string, List<SpawnableEnemyWithRarity>> MoonsToOutsideSpawnLists = new Dictionary<string, List<SpawnableEnemyWithRarity>>();

		private static Dictionary<string, List<SpawnableEnemyWithRarity>> MoonsToDaytimeSpawnLists = new Dictionary<string, List<SpawnableEnemyWithRarity>>();

		[HarmonyPatch(typeof(EnemyAI), "SetEnemyStunned")]
		[HarmonyPostfix]
		private static void SetOwnershipToStunningPlayer(EnemyAI __instance)
		{
			if (__instance is WTOEnemy && !((Object)(object)__instance.stunnedByPlayer == (Object)null))
			{
				WTOBase.LogToConsole($"Enemy: {((object)__instance).GetType()} STUNNED BY: {__instance.stunnedByPlayer}; Switching ownership...");
				__instance.ChangeOwnershipOfEnemy(__instance.stunnedByPlayer.actualClientId);
			}
		}

		[HarmonyPatch(typeof(HUDManager), "UseSignalTranslatorClientRpc")]
		[HarmonyPostfix]
		private static void TellAllGhostsOfSignalTransmission()
		{
			OoblGhostAI[] array = Object.FindObjectsOfType<OoblGhostAI>();
			OoblGhostAI[] array2 = array;
			foreach (OoblGhostAI ooblGhostAI in array2)
			{
				ooblGhostAI.EvalulateSignalTranslatorUse();
			}
		}

		[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
		[HarmonyPrefix]
		private static void SetInsideEnemiesWTO(RoundManager __instance)
		{
			string planetName = __instance.currentLevel.PlanetName;
			if ((Object)(object)DungeonManager.CurrentExtendedDungeonFlow != (Object)(object)FactoryPatch.OoblDungeonFlow)
			{
				if (MoonsToInsideSpawnLists.TryGetValue(planetName, out var value))
				{
					__instance.currentLevel.Enemies = value;
				}
			}
			else
			{
				SetMonsterStuff(WTOBase.WTOForceInsideMonsters.Value, ref __instance.currentLevel.Enemies, MoonsToInsideSpawnLists[MoonPatch.MoonFriendlyName]);
			}
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnRandomOutsideEnemy")]
		[HarmonyPrefix]
		private static void SetOutsideEnemiesWTO(RoundManager __instance)
		{
			string planetName = __instance.currentLevel.PlanetName;
			if ((Object)(object)DungeonManager.CurrentExtendedDungeonFlow != (Object)(object)FactoryPatch.OoblDungeonFlow)
			{
				if (MoonsToOutsideSpawnLists.TryGetValue(planetName, out var value))
				{
					__instance.currentLevel.OutsideEnemies = value;
				}
			}
			else
			{
				SetMonsterStuff(WTOBase.WTOForceOutsideMonsters.Value, ref __instance.currentLevel.OutsideEnemies, MoonsToOutsideSpawnLists[MoonPatch.MoonFriendlyName]);
			}
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnRandomDaytimeEnemy")]
		[HarmonyPrefix]
		private static void SetDaytimeEnemiesWTO(RoundManager __instance)
		{
			string planetName = __instance.currentLevel.PlanetName;
			if ((Object)(object)DungeonManager.CurrentExtendedDungeonFlow != (Object)(object)FactoryPatch.OoblDungeonFlow)
			{
				if (MoonsToDaytimeSpawnLists.TryGetValue(planetName, out var value))
				{
					__instance.currentLevel.OutsideEnemies = value;
				}
			}
			else
			{
				SetMonsterStuff(WTOBase.WTOForceDaytimeMonsters.Value, ref __instance.currentLevel.DaytimeEnemies, MoonsToDaytimeSpawnLists[MoonPatch.MoonFriendlyName]);
			}
		}

		public static void Start()
		{
			CreateEnemy("Wanderer.asset", DaytimeEnemies, 50, (SpawnType)1, "WandererTerminal.asset", "WandererKeyword.asset");
			CreateEnemy("AdultWanderer.asset", AdultWandererContainer, 0, (SpawnType)2, "AdultWandererTerminal.asset", "AdultWandererKeyword.asset");
			CreateEnemy("Gallenarma.asset", InsideEnemies, 30, (SpawnType)0, "GallenTerminal.asset", "GallenKeyword.asset");
			CreateEnemy("EyeSecurity.asset", InsideEnemies, 20, (SpawnType)0, "EyeSecTerminal.asset", "EyeSecKeyword.asset");
			CreateEnemy("OoblGhost.asset", InsideEnemies, 20, (SpawnType)0, "OoblGhostTerminal.asset", "OoblGhostKeyword.asset");
			CreateEnemy("Enforcer.asset", InsideEnemies, 10, (SpawnType)0, "EnforcerTerminal.asset", "EnforcerKeyword.asset");
			CreateEnemy("BabyLurker.asset", InsideEnemies, 10, (SpawnType)0, "BabyLurkerTerminal.asset", "BabyLurkerKeyword.asset");
			CreateEnemy("GhostPlayer.asset", OutsideEnemies, 10, (SpawnType)2);
			if (!MoonsToInsideSpawnLists.ContainsKey(MoonPatch.MoonFriendlyName))
			{
				MoonsToInsideSpawnLists.Add(MoonPatch.MoonFriendlyName, MoonPatch.OoblterraExtendedLevel.SelectableLevel.Enemies);
			}
			if (!MoonsToOutsideSpawnLists.ContainsKey(MoonPatch.MoonFriendlyName))
			{
				MoonsToOutsideSpawnLists.Add(MoonPatch.MoonFriendlyName, MoonPatch.OoblterraExtendedLevel.SelectableLevel.OutsideEnemies);
			}
			if (!MoonsToDaytimeSpawnLists.ContainsKey(MoonPatch.MoonFriendlyName))
			{
				MoonsToDaytimeSpawnLists.Add(MoonPatch.MoonFriendlyName, MoonPatch.OoblterraExtendedLevel.SelectableLevel.DaytimeEnemies);
			}
		}

		public static void CreateEnemy(string EnemyName, List<SpawnableEnemyWithRarity> EnemyList, int rarity, SpawnType SpawnType, string InfoName = null, string KeywordName = null)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			string text = EnemyName.Remove(EnemyName.Length - 6, 6) + "/";
			TerminalNode val = null;
			TerminalKeyword val2 = null;
			EnemyType val3 = WTOBase.ContextualLoadAsset<EnemyType>(EnemyBundle, "Assets/Resources/WelcomeToOoblterra/CustomEnemies/" + text + EnemyName, LogLoading: true);
			val3.enemyPrefab.GetComponent<EnemyAI>().debugEnemyAI = false;
			if (InfoName != null)
			{
				val = WTOBase.ContextualLoadAsset<TerminalNode>(EnemyBundle, "Assets/Resources/WelcomeToOoblterra/CustomEnemies/" + text + InfoName, LogLoading: true);
			}
			if (KeywordName != null)
			{
				val2 = WTOBase.ContextualLoadAsset<TerminalKeyword>(EnemyBundle, "Assets/Resources/WelcomeToOoblterra/CustomEnemies/" + text + KeywordName, LogLoading: true);
			}
			NetworkPrefabs.RegisterNetworkPrefab(val3.enemyPrefab);
			Enemies.RegisterEnemy(val3, rarity, (LevelTypes)1, SpawnType, val, val2);
			EnemyList?.Add(new SpawnableEnemyWithRarity
			{
				enemyType = val3,
				rarity = rarity
			});
			WTOBase.LogToConsole("Monster Loaded: " + EnemyName.Remove(EnemyName.Length - 6, 6));
		}

		private static void SetMonsterStuff(TiedToLabEnum TiedToLabState, ref List<SpawnableEnemyWithRarity> CurrentMoonEnemyList, List<SpawnableEnemyWithRarity> OoblterraEnemyList)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
			foreach (SpawnableEnemyWithRarity OoblterraEnemy in OoblterraEnemyList)
			{
				list.Add(new SpawnableEnemyWithRarity
				{
					enemyType = OoblterraEnemy.enemyType,
					rarity = OoblterraEnemy.rarity * WTOBase.WTOWeightScale.Value
				});
			}
			switch (TiedToLabState)
			{
			case TiedToLabEnum.WTOOnly:
				CurrentMoonEnemyList = OoblterraEnemyList;
				break;
			case TiedToLabEnum.AppendWTO:
				CurrentMoonEnemyList.AddRange(list);
				break;
			}
		}
	}
	internal class MoonPatch
	{
		public static string MoonFriendlyName;

		public static SelectableLevel MyNewMoon;

		public static Animator OoblFogAnimator;

		public static readonly AssetBundle LevelBundle = WTOBase.LevelAssetBundle;

		public const string MoonPath = "Assets/Resources/WelcomeToOoblterra/CustomMoon/";

		private static FootstepSurface GrassSurfaceRef;

		private static AudioClip[] OoblFootstepClips;

		private static AudioClip OoblHitSFX;

		private static AudioClip[] GrassFootstepClips;

		private static AudioClip GrassHitSFX;

		private static AudioClip[] CachedTODMusic;

		private static AudioClip[] CachedAmbientMusic;

		private static AudioClip[] OoblTODMusic;

		private static SpawnableMapObject[] CachedSpawnableMapObjects;

		public static ExtendedLevel OoblterraExtendedLevel;

		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
		[HarmonyPostfix]
		private static void ManageNav(StartOfRound __instance)
		{
			GrassSurfaceRef = StartOfRound.Instance.footstepSurfaces[4];
			if (GrassFootstepClips == null)
			{
				GrassFootstepClips = StartOfRound.Instance.footstepSurfaces[4].clips;
				GrassHitSFX = StartOfRound.Instance.footstepSurfaces[4].hitSurfaceSFX;
			}
			if (OoblFootstepClips == null)
			{
				OoblFootstepClips = (AudioClip[])(object)new AudioClip[5]
				{
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLESTEP01.wav", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLESTEP02.wav", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLESTEP03.wav", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLESTEP04.wav", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLESTEP05.wav", LogLoading: true)
				};
				OoblHitSFX = WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Sound/Footsteps/TENTACLE_Fall.wav", LogLoading: true);
			}
			if (CachedTODMusic == null)
			{
				CachedTODMusic = TimeOfDay.Instance.timeOfDayCues;
				CachedAmbientMusic = SoundManager.Instance.DaytimeMusic;
			}
			if (OoblTODMusic == null)
			{
				OoblTODMusic = (AudioClip[])(object)new AudioClip[4]
				{
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Oobl_StartOfDay.ogg", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Oobl_MidDay.ogg", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Oobl_LateDay.ogg", LogLoading: true),
					WTOBase.ContextualLoadAsset<AudioClip>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/Oobl_Night.ogg", LogLoading: true)
				};
			}
			if (__instance.currentLevel.PlanetName != MoonFriendlyName)
			{
				TimeOfDay.Instance.timeOfDayCues = CachedTODMusic;
				SoundManager.Instance.DaytimeMusic = CachedAmbientMusic;
				GrassSurfaceRef.clips = GrassFootstepClips;
				GrassSurfaceRef.hitSurfaceSFX = GrassHitSFX;
			}
			else
			{
				MoveNavNodesToNewPositions();
				GrassSurfaceRef.clips = OoblFootstepClips;
				GrassSurfaceRef.hitSurfaceSFX = OoblHitSFX;
				TimeOfDay.Instance.timeOfDayCues = OoblTODMusic;
				SoundManager.Instance.DaytimeMusic = (AudioClip[])(object)new AudioClip[0];
				ReplaceStoryLogIDs();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")]
		[HarmonyPostfix]
		private static void SetFogTies(StartOfRound __instance)
		{
			if (!(__instance.currentLevel.PlanetName != MoonFriendlyName))
			{
				OoblFogAnimator = GameObject.Find("OoblFog").gameObject.GetComponent<Animator>();
				WTOBase.LogToConsole($"Fog animator found : {(Object)(object)OoblFogAnimator != (Object)null}");
				if ((Object)(object)TimeOfDay.Instance.sunAnimator == (Object)(object)OoblFogAnimator)
				{
					WTOBase.LogToConsole("Sun Animator IS fog animator, supposedly");
					return;
				}
				TimeOfDay.Instance.sunAnimator = OoblFogAnimator;
				WTOBase.LogToConsole($"Is Sun Animator Fog Animator? {(Object)(object)TimeOfDay.Instance.sunAnimator == (Object)(object)OoblFogAnimator}");
				TimeOfDay.Instance.playDelayedMusicCoroutine = null;
			}
		}

		[HarmonyPatch(typeof(TimeOfDay), "SetInsideLightingDimness")]
		[HarmonyPrefix]
		private static void SpoofLightValues(TimeOfDay __instance)
		{
			if (!(__instance.currentLevel.PlanetName != MoonFriendlyName))
			{
				Light component = GameObject.Find("ActualSun").GetComponent<Light>();
				Light component2 = GameObject.Find("ActualIndirect").GetComponent<Light>();
				TimeOfDay val = Object.FindObjectOfType<TimeOfDay>();
				val.sunIndirect = component2;
				val.sunDirect = component;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepSound")]
		[HarmonyPrefix]
		private static void PatchFootstepSound(PlayerControllerB __instance)
		{
			if (StartOfRound.Instance.currentLevel.PlanetName != MoonFriendlyName || __instance.currentFootstepSurfaceIndex != 4)
			{
				__instance.movementAudio.volume = 0.447f;
				return;
			}
			float num = Mathf.Clamp((float)WTOBase.WTOFootsteps.Value, 0f, 100f);
			__instance.movementAudio.volume = num / 100f * 0.447f;
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnOutsideHazards")]
		[HarmonyPrefix]
		private static bool WTOSpawnOutsideObjects(RoundManager __instance)
		{
			if (__instance.currentLevel.PlanetName != MoonFriendlyName)
			{
				return true;
			}
			if (!WTOBase.CSVSeperatedStringList(WTOBase.WTOHazardList.Value).Contains("beartrap"))
			{
				__instance.currentLevel.spawnableMapObjects = null;
				return false;
			}
			__instance.currentLevel.spawnableMapObjects = CachedSpawnableMapObjects;
			return true;
		}

		[HarmonyPatch(typeof(TimeOfDay), "Start")]
		[HarmonyPrefix]
		private static bool AdjustTODMusic(TimeOfDay __instance)
		{
			if (RoundManager.Instance.currentLevel.PlanetName != MoonFriendlyName)
			{
				__instance.TimeOfDayMusic.volume = 1f;
				return true;
			}
			float num = Mathf.Clamp((float)WTOBase.WTOFootsteps.Value, 0f, 100f);
			__instance.TimeOfDayMusic.volume = num / 100f;
			return true;
		}

		public static void Start()
		{
			OoblterraExtendedLevel = WTOBase.ContextualLoadAsset<ExtendedLevel>(LevelBundle, "Assets/Resources/WelcomeToOoblterra/CustomMoon/OoblterraExtendedLevel.asset", LogLoading: true);
			MoonFriendlyName = OoblterraExtendedLevel.SelectableLevel.PlanetName;
			WTOBase.LogToConsole($"Ooblterra Found: {(Object)(object)OoblterraExtendedLevel != (Object)null}");
			PatchedContent.RegisterExtendedLevel(OoblterraExtendedLevel);
			CachedSpawnableMapObjects = OoblterraExtendedLevel.SelectableLevel.spawnableMapObjects;
			foreach (SpawnableItemWithRarity item in OoblterraExtendedLevel.SelectableLevel.spawnableScrap)
			{
				WTOBase.LogToConsole(((Object)item.spawnableItem).name ?? "");
			}
		}

		private static void MoveNavNodesToNewPositions()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
			List<GameObject> list = new List<GameObject>();
			IEnumerable<GameObject> enumerable = from obj in Object.FindObjectsOfType<GameObject>()
				where ((Object)obj).name == "OoblOutsideNode"
				select obj;
			foreach (GameObject item in enumerable)
			{
				list.Add(item);
			}
			WTOBase.LogToConsole("Outside nav points: " + list.Count());
			for (int i = 0; i < array.Count(); i++)
			{
				if (list.Count() > i)
				{
					array[i].transform.position = list[i].transform.position;
				}
				else
				{
					Object.Destroy((Object)(object)array[i]);
				}
			}
		}

		private static void ReplaceStoryLogIDs()
		{
			StoryLog[] array = Object.FindObjectsOfType<StoryLog>();
			StoryLog[] array2 = array;
			foreach (StoryLog val in array2)
			{
				if (TerminalPatch.LogDictionary.TryGetValue(val.storyLogID, out var value))
				{
					val.storyLogID = value;
				}
			}
		}
	}
	internal class SuitPatch
	{
		private const string SuitPath = "Assets/Resources/WelcomeToOoblterra/CustomSuits/";

		private const string BlackSuitPath = "Assets/Resources/WelcomeToOoblterra/CustomSuits/BlackSuits";

		private static readonly AssetBundle SuitBundle = WTOBase.ItemAssetBundle;

		private const string PosterGameObject = "HangarShip/Plane.001";

		private static string[] SuitMaterialNames = new string[7] { "RedSuit.mat", "ProtSuit.mat", "YellowSuit.mat", "GreenSuit.mat", "BlueSuit.mat", "IndigoSuit.mat", "MackSuit.mat" };

		private static bool SuitsLoaded = false;

		public static Material GhostPlayerSuit;

		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
		[HarmonyPrefix]
		private static void StartPatch(ref StartOfRound __instance)
		{
			GhostPlayerSuit = WTOBase.ContextualLoadAsset<Material>(SuitBundle, "Assets/Resources/WelcomeToOoblterra/CustomSuits/GhostPlayerSuit.mat", LogLoading: true);
			if (WTOBase.WTOCustomSuits.Value)
			{
				LoadSuits("Assets/Resources/WelcomeToOoblterra/CustomSuits/");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void PatchPosters(StartOfRound __instance)
		{
			if (WTOBase.WTOCustomPoster.Value)
			{
				ReplacePoster();
			}
		}

		private static void LoadSuits(string RelevantPath)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			if (SuitsLoaded)
			{
				WTOBase.LogToConsole("SUITS ALREADY LOADED!");
				return;
			}
			UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables.First((UnlockableItem x) => (Object)(object)x.suitMaterial != (Object)null);
			string[] suitMaterialNames = SuitMaterialNames;
			foreach (string text in suitMaterialNames)
			{
				UnlockableItem val2 = JsonUtility.FromJson<UnlockableItem>(JsonUtility.ToJson((object)val));
				UnlockableSuit val3 = new UnlockableSuit();
				val2.suitMaterial = WTOBase.ContextualLoadAsset<Material>(SuitBundle, RelevantPath + text, LogLoading: true);
				string unlockableName = text.Substring(0, text.Length - 4);
				val2.unlockableName = unlockableName;
				StartOfRound.Instance.unlockablesList.unlockables.Add(val2);
			}
			SuitsLoaded = true;
		}

		private static void AddSuitPurchaseNode()
		{
		}

		private static void ReplacePoster()
		{
			if (!((Object)(object)GameObject.Find("HangarShip/Plane.001") == (Object)null))
			{
				Material[] materials = ((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials;
				materials[1] = WTOBase.ContextualLoadAsset<Material>(SuitBundle, "Assets/Resources/WelcomeToOoblterra/CustomSuits/Poster.mat", LogLoading: true);
				((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials = materials;
			}
		}

		private static void AddPosterShipDeco()
		{
		}
	}
}
namespace Welcome_To_Ooblterra.Security
{
	internal class SpikeTrap : NetworkBehaviour
	{
		public GameObject SpikeMesh;

		public AudioClip SpikesExtend;

		public AudioClip SpikesRetract;

		public AudioClip SpikesDisable;

		public AudioSource SpikeSoundPlayer;

		public Transform RootRotation;

		private bool SpikesEnabled = true;

		private bool SpikesActivated;

		private bool AllowDamagePlayer;

		private float SecondsSinceSpikesActivated;

		private float SecondsUntilCanDamagePlayer;

		private int PlayerDamageAmount = 80;

		private float TimeElapsed;

		private const float MoveTime = 0.2f;

		private Vector3 SpikeRaisePos = new Vector3(0f, 1.163f, 0f);

		private Vector3 SpikeFallPos;

		public void OnTriggerEnter(Collider other)
		{
			if (SpikesEnabled && !SpikesActivated && ((Component)other).gameObject.CompareTag("Player"))
			{
				WTOBase.LogToConsole("Player entered spike trap, calling Raise RPC!");
				RaiseSpikesServerRpc();
			}
		}

		public void OnTriggerStay(Collider other)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (AllowDamagePlayer && ((Component)other).gameObject.CompareTag("Player") && SecondsUntilCanDamagePlayer <= 0f)
			{
				PlayerDamageAmount = ((StartOfRound.Instance.connectedPlayersAmount <= 0) ? 80 : 100);
				((Component)other).GetComponent<PlayerControllerB>().DamagePlayer(PlayerDamageAmount, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
				SecondsUntilCanDamagePlayer = 0.75f;
			}
		}

		public void Update()
		{
			if (SecondsUntilCanDamagePlayer > 0f)
			{
				SecondsUntilCanDamagePlayer -= Time.deltaTime;
			}
			if (SecondsSinceSpikesActivated >= 3f)
			{
				if (SpikesActivated)
				{
					SpikeSoundPlayer.clip = SpikesRetract;
					SpikeSoundPlayer.Play();
					TimeElapsed = 0f;
				}
				SpikesActivated = false;
				WTOBase.LogToConsole("Lowering Spikes!");
				((MonoBehaviour)this).StartCoroutine(LowerSpikes());
			}
			if (SpikesEnabled && SpikesActivated)
			{
				WTOBase.LogToConsole("Raising Spikes!");
				((MonoBehaviour)this).StartCoroutine(RaiseSpikes());
				SecondsSinceSpikesActivated += Time.deltaTime;
			}
		}

		private IEnumerator RaiseSpikes()
		{
			TimeElapsed += Time.deltaTime;
			SpikeMesh.transform.localPosition = Vector3.Lerp(SpikeFallPos, SpikeRaisePos, TimeElapsed / 0.2f);
			if (TimeElapsed / 0.2f >= 1f)
			{
				AllowDamagePlayer = true;
				WTOBase.LogToConsole("Finished Raising Spikes");
				((MonoBehaviour)this).StopCoroutine(RaiseSpikes());
			}
			yield return null;
		}

		private IEnumerator LowerSpikes()
		{
			TimeElapsed += Time.deltaTime;
			WTOBase.LogToConsole($"Current Lerp Position: {TimeElapsed / 0.2f}");
			SpikeMesh.transform.localPosition = Vector3.Lerp(SpikeRaisePos, SpikeFallPos, TimeElapsed / 0.2f);
			if (TimeElapsed / 0.2f >= 1f)
			{
				AllowDamagePlayer = false;
				WTOBase.LogToConsole("Finished Lowering Spikes");
				((MonoBehaviour)this).StopCoroutine(LowerSpikes());
				SecondsSinceSpikesActivated = 0f;
				((Renderer)SpikeMesh.GetComponent<MeshRenderer>()).enabled = false;
			}
			yield return null;
		}

		public void RecieveToggleSpikes(bool enabled)
		{
			WTOBase.LogToConsole($"Called toggle spikes with state: {enabled}");
			ToggleSpikesServerRpc(enabled);
			ToggleSpikes(enabled);
		}

		[ServerRpc(RequireOwnership = false)]
		public void ToggleSpikesServerRpc(bool enabled)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1273677579u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref enabled, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1273677579u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					WTOBase.LogToConsole($"Toggling spikes to {enabled} serverRpc");
					ToggleSpikesClientRpc(enabled);
				}
			}
		}

		[ClientRpc]
		public void ToggleSpikesClientRpc(bool enabled)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1768198554u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref enabled, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1768198554u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				WTOBase.LogToConsole($"Toggling spikes to {enabled} clientRpc");
				if (SpikesEnabled != enabled)
				{
					ToggleSpikes(enabled);
				}
			}
		}

		private void ToggleSpikes(bool enabled)
		{
			if (!enabled)
			{
				SpikeSoundPlayer.clip = SpikesDisable;
				SpikeSoundPlayer.Play();
			}
			SpikesEnabled = enabled;
			WTOBase.LogToConsole($"SPIKES STATE: {SpikesEnabled}");
			if (SpikesActivated)
			{
				SecondsSinceSpikesActivated = 5f;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void RaiseSpikesServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2638217131u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2638217131u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					RaiseSpikesClientRpc();
				}
			}
		}

		[ClientRpc]
		public void RaiseSpikesClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3449189664u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3449189664u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					TimeElapsed = 0f;
					SpikeSoundPlayer.clip = SpikesExtend;
					SpikeSoundPlayer.Play();
					((Renderer)SpikeMesh.GetComponent<MeshRenderer>()).enabled = true;
					SpikesActivated = true;
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_SpikeTrap()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1273677579u, new RpcReceiveHandler(__rpc_handler_1273677579));
			NetworkManager.__rpc_func_table.Add(1768198554u, new RpcReceiveHandler(__rpc_handler_1768198554));
			NetworkManager.__rpc_func_table.Add(2638217131u, new RpcReceiveHandler(__rpc_handler_2638217131));
			NetworkManager.__rpc_func_table.Add(3449189664u, new RpcReceiveHandler(__rpc_handler_3449189664));
		}

		private static void __rpc_handler_1273677579(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool enabled = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref enabled, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SpikeTrap)(object)target).ToggleSpikesServerRpc(enabled);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1768198554(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool enabled = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref enabled, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SpikeTrap)(object)target).ToggleSpikesClientRpc(enabled);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2638217131(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SpikeTrap)(object)target).RaiseSpikesServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3449189664(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SpikeTrap)(object)target).RaiseSpikesClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "SpikeTrap";
		}
	}
}
namespace Welcome_To_Ooblterra.RoomBehaviors
{
	public class FrankensteinVisuals : MonoBehaviour
	{
		[InspectorName("SceneAnim")]
		public AudioClip ReviveSound;

		public AudioSource ReviveSoundPlayer;

		public Animator CoilAnim;

		public ParticleSystem[] LightningParticles;

		public LightComponent[] Lights;

		private bool ShouldAnimate;

		private bool AnimStarted;

		private bool AnimStopped;

		private Random MyRandom;

		private void Start()
		{
			MyRandom = new Random(StartOfRound.Instance.randomMapSeed);
		}

		private void Update()
		{
			if (ShouldAnimate)
			{
				((MonoBehaviour)this).StartCoroutine(VisualsHandler());
			}
		}

		public void StartVisuals()
		{
			WTOBase.LogToConsole("Visuals script starting coroutine ...");
			ShouldAnimate = true;
		}

		private IEnumerator VisualsHandler()
		{
			if (!AnimStarted)
			{
				ReviveSoundPlayer.clip = ReviveSound;
				ReviveSoundPlayer.Play();
				CoilAnim.SetTrigger("HeatCoils");
				ParticleSystem[] lightningParticles = LightningParticles;
				foreach (ParticleSystem LightningBolt2 in lightningParticles)
				{
					LightningBolt2.Play();
				}
				AnimStarted = true;
			}
			if (!AnimStopped)
			{
				LightComponent[] lights = Lights;
				foreach (LightComponent Light2 in lights)
				{
					Light2.SetLightBrightness((MyRandom.Next(0, 10) % 2 == 0) ? 200 : 0);
				}
			}
			yield return (object)new WaitForSeconds(3.4f);
			if (!AnimStopped)
			{
				ParticleSystem[] lightningParticles2 = LightningParticles;
				foreach (ParticleSystem LightningBolt in lightningParticles2)
				{
					LightningBolt.Stop();
				}
				LightComponent[] lights2 = Lights;
				foreach (LightComponent Light in lights2)
				{
					Light.SetLightBrightness(0);
				}
				AnimStopped = true;
			}
		}
	}
}
namespace Welcome_To_Ooblterra.Things
{
	public class BabyLurkerEgg : NetworkBehaviour
	{
		private Random enemyRandom;

		private GameObject HiveProjectile;

		public GameObject HiveMesh;

		public GameObject projectileTemplate;

		public GameObject MapDot;

		public Transform DropTransform;

		public Transform TraceTransform;

		public AudioClip[] BreakoffSound;

		private bool EggSpawned = false;

		private bool EggDropped = false;

		private float SecondsUntilNextSpawnAttempt = 15f;

		public ScanNodeProperties ScanNode;

		private void OnTriggerStay(Collider other)
		{
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if (((Component)other).gameObject.CompareTag("Player") && EggSpawned && !EggDropped)
			{
				SpawnProjectileServerRpc((int)component.actualClientId);
			}
		}

		private void Start()
		{
			enemyRandom = new Random(StartOfRound.Instance.randomMapSeed);
			SecondsUntilNextSpawnAttempt = enemyRandom.Next(15, 40);
			ScanNode.creatureScanID = ((IEnumerable<SpawnableEnemy>)Enemies.spawnableEnemies).FirstOrDefault((Func<SpawnableEnemy, bool>)((SpawnableEnemy x) => x.enemy.enemyName == "Baby Lurker")).terminalNode.creatureFileID;
			SpawnEgg();
		}

		private void Update()
		{
			if (!EggSpawned)
			{
				if (SecondsUntilNextSpawnAttempt > 0f)
				{
					SecondsUntilNextSpawnAttempt -= Time.deltaTime;
				}
				else if (enemyRandom.Next(0, 100) < 60)
				{
					SpawnEggServerRpc();
				}
				else
				{
					SecondsUntilNextSpawnAttempt = enemyRandom.Next(15, 40);
				}
			}
		}

		public void SpawnEgg()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!EggSpawned)
			{
				HiveMesh.SetActive(true);
				MapDot.SetActive(true);
				RaycastHit val = default(RaycastHit);
				if (Physics.Linecast(TraceTransform.position, TraceTransform.position + Vector3.up * 5000f, ref val, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
				{
					HiveMesh.transform.position = ((RaycastHit)(ref val)).point;
					HiveMesh.transform.rotation = new Quaternion(180f, 0f, 0f, 0f);
					WTOBase.LogToConsole("Lurker Egg active!");
					EggSpawned = true;
				}
				else
				{
					WTOBase.LogToConsole("Lurker Egg Line trace failed!");
				}
			}
		}

		[ServerRpc]
		public void SpawnEggServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1413104468u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1413104468u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				SpawnEggClientRpc();
			}
		}

		[ClientRpc]
		public void SpawnEggClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2661667374u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2661667374u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					SpawnEgg();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SpawnProjectileServerRpc(int targetID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1224589768u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, targetID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1224589768u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					SpawnProjectileClientRpc(targetID);
				}
			}
		}

		[ClientRpc]
		public void SpawnProjectileClientRpc(int targetID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2345419954u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, targetID);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2345419954u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !EggDropped)
			{
				MapDot.SetActive(false);
				AudioSource component = ((Component)this).GetComponent<AudioSource>();
				if (component != null)
				{
					component.PlayOneShot(BreakoffSound[enemyRandom.Next(0, BreakoffSound.Length)]);
				}
				WTOBase.LogToConsole("Lurker egg projectile being spawned!");
				HiveProjectile = Object.Instantiate<GameObject>(projectileTemplate, DropTransform.position, DropTransform.rotation);
				HiveProjectile.GetComponent<BabyLurkerEggProjectile>().TargetID = targetID;
				EggDropped = true;
				Object.Destroy((Object)(object)HiveMesh);
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_BabyLurkerEgg()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1413104468u, new RpcReceiveHandler(__rpc_handler_1413104468));
			NetworkManager.__rpc_func_table.Add(2661667374u, new RpcReceiveHandler(__rpc_handler_2661667374));
			NetworkManager.__rpc_func_table.Add(1224589768u, new RpcReceiveHandler(__rpc_handler_1224589768));
			NetworkManager.__rpc_func_table.Add(2345419954u, new RpcReceiveHandler(__rpc_handler_2345419954));
		}

		private static void __rpc_handler_1413104468(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((BabyLurkerEgg)(object)target).SpawnEggServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2661667374(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((BabyLurkerEgg)(object)target).SpawnEggClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1224589768(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int targetID = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref targetID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((BabyLurkerEgg)(object)target).SpawnProjectileServerRpc(targetID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2345419954(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int targetID = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref targetID);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((BabyLurkerEgg)(object)target).SpawnProjectileClientRpc(targetID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "BabyLurkerEgg";
		}
	}
	public class BatteryRecepticle : NetworkBehaviour
	{
		[InspectorName("Defaults")]
		public NetworkObject parentTo;

		public NetworkObject BatteryNetObj;

		public InteractTrigger triggerScript;

		public Transform BatteryTransform;

		public BoxCollider BatteryHitbox;

		private WTOBattery InsertedBattery;

		private bool RecepticleHasBattery;

		public Animator MachineAnimator;

		public AudioSource Noisemaker;

		public AudioClip FacilityPowerUp;

		public AudioSource Pistons;

		public AudioSource MachineAmbience;

		public MeshRenderer[] WallLights;

		public Material WallLightMat;

		public Color LightColor;

		public Light CenterLight;

		private ScrapShelf scrapShelf;

		public GameObject BatteryPrefab;

		public Material FrontConsoleMaterial;

		public Material SideConsoleMaterial;

		public MeshRenderer MachineMesh;

		private Random MachineRandom;

		private WideDoorway[] Doorways;

		public void Start()
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			scrapShelf = Object.FindFirstObjectByType<ScrapShelf>();
			Object.FindObjectsByType<WideDoorway>((FindObjectsSortMode)0);
			WTOBattery[] source = Object.FindObjectsOfType<WTOBattery>();
			InsertedBattery = source.First((WTOBattery x) => !x.HasCharge);
			RecepticleHasBattery = true;
			CenterLight.intensity = 0f;
			MeshRenderer[] wallLights = WallLights;
			foreach (MeshRenderer val in wallLights)
			{
				((Renderer)val).sharedMaterial = WallLightMat;
			}
			MachineRandom = new Random();
			SpawnBatteryAtFurthestPoint();
			foreach (LightComponent item in from x in Object.FindObjectsOfType<LightComponent>()
				where x.SetColorByDistance
				select x)
			{
				item.SetColorRelative(((Component)this).transform.position);
			}
			Doorways = Object.FindObjectsByType<WideDoorway>((FindObjectsSortMode)0);
		}

		private void Update()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			WallLightMat.SetColor("_EmissiveColor", LightColor);
			if (RecepticleHasBattery)
			{
				((Collider)BatteryHitbox).enabled = false;
				triggerScript.interactable = false;
				triggerScript.disabledHoverTip = "";
				if ((Object)(object)InsertedBattery != (Object)null && ((GrabbableObject)InsertedBattery).isHeld)
				{
					InsertedBattery = null;
					RecepticleHasBattery = false;
				}
			}
			else
			{
				((Collider)BatteryHitbox).enabled = true;
				((Behaviour)triggerScript).enabled = true;
				if (GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer is WTOBattery)
				{
					triggerScript.interactable = true;
					triggerScript.hoverTip = "Insert Battery : [E]";
				}
				else
				{
					triggerScript.interactable = false;
					triggerScript.disabledHoverTip = "[Requires Battery]";
				}
			}
		}

		private void SpawnBatteryAtFurthestPoint()
		{
			//IL_0060: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			List<RandomMapObject> list = new List<RandomMapObject>();
			List<RandomMapObject> list2 = new List<RandomMapObject>();
			list.AddRange(Object.FindObjectsOfType<RandomMapObject>());
			float num = 80f;
			foreach (RandomMapObject item in list.Where((RandomMapObject x) => x.spawnablePrefabs.Contains(BatteryPrefab)))
			{
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)item).transform.position);
				WTOBase.LogToConsole($"BATTERY DISTANCE: {num2}");
				if (num2 > num)
				{
					list2.Add(item);
				}
			}
			WTOBase.LogToConsole($"Viable Battery Spawns: {list2.Count}");
			RandomMapObject val = list2[MachineRandom.Next(0, list2.Count)];
			GameObject val2 = Object.Instantiate<GameObject>(BatteryPrefab, ((Component)val).transform.position, ((Component)val).transform.rotation, RoundManager.Instance.mapPropsContainer.transform);
			val2.GetComponent<NetworkObject>().Spawn(true);
		}

		public void TryInsertOrRemoveBattery(PlayerControllerB playerWhoTriggered)
		{
			//IL_002b: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0120: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (RecepticleHasBattery && !InsertedBattery.HasCharge)
			{
				playerWhoTriggered.GrabObjectServerRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)InsertedBattery).NetworkObject));
				RecepticleHasBattery = false;
			}
			else if (playerWhoTriggered.isHoldingObject && (Object)(object)playerWhoTriggered.currentlyHeldObjectServer != (Object)null)
			{
				WTOBase.LogToConsole("Placing battery in recepticle");
				Vector3 val = BatteryTransform.position;
				if ((Object)(object)parentTo != (Object)null)
				{
					val = ((Component)parentTo).transform.InverseTransformPoint(val);
				}
				InsertedBattery = (WTOBattery)(object)playerWhoTriggered.currentlyHeldObjectServer;
				RecepticleHasBattery = true;
				WTOBase.LogToConsole("discard held object called from placeobject");
				playerWhoTriggered.DiscardHeldObject(true, parentTo, val, true);
				((Component)InsertedBattery).transform.rotation = Quaternion.identity;
				((Component)InsertedBattery).transform.Rotate(305f, 45f, 0f, (Space)1);
				InsertBatteryServerRpc(NetworkObjectReference.op_Implicit(((Component)InsertedBattery).gameObject.GetComponent<NetworkObject>()));
				if (InsertedBattery.HasCharge)
				{
					TurnOnPowerServerRpc();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void InsertBatteryServerRpc(NetworkObjectReference grabbableObjectNetObject)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2534650821u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref grabbableObjectNetObject, default(ForNetworkSerializable));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2534650821u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					InsertBatteryClientRpc(grabbableObjectNetObject);
				}
			}
		}

		[ClientRpc]
		public void InsertBatteryClientRpc(NetworkObjectReference grabbableObjectNetObject)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1080085237u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref grabbableObjectNetObject, default(ForNetworkSerializable));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1080085237u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					InsertBattery(grabbableObjectNetObject);
				}
			}
		}

		public void InsertBattery(NetworkObjectReference grabbableObjectNetObject)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkObjectReference)(ref grabbableObjectNetObject)).TryGet(ref BatteryNetObj, (NetworkManager)null))
			{
				((Component)BatteryNetObj).gameObject.GetComponentInChildren<GrabbableObject>().EnablePhysics(false);
				InsertedBattery = ((Component)BatteryNetObj).GetComponentInChildren<WTOBattery>();
			}
			else
			{
				WTOBase.WTOLogSource.LogError((object)"BATTERY COULD NOT BE CONVERTED.");
			}
			((Component)((Component)BatteryNetObj).GetComponentInChildren<GrabbableObject>()).transform.rotation = Quaternion.identity;
			((Component)((Component)BatteryNetObj).GetComponentInChildren<GrabbableObject>()).transform.Rotate(305f, 45f, 0f, (Space)1);
			RecepticleHasBattery = true;
			if (InsertedBattery.HasCharge)
			{
				((GrabbableObject)InsertedBattery).grabbable = false;
				return;
			}
			((GrabbableObject)InsertedBattery).grabbable = true;
			((Collider)((Component)InsertedBattery).GetComponent<BoxCollider>()).enabled = true;
		}

		[ServerRpc(RequireOwnership = false)]
		public void TurnOnPowerServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3606445563u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3606445563u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					TurnOnPowerClientRpc();
				}
			}
		}

		[ClientRpc]
		public void TurnOnPowerClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(195750096u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 195750096u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					TurnOnPower();
				}
			}
		}

		public void TurnOnPower()
		{
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				Noisemaker.PlayOneShot(FacilityPowerUp);
			}
			scrapShelf.OpenShelf();
			MachineAmbience.Play();
			Pistons.Play();
			LightComponent[] array = Object.FindObjectsOfType<LightComponent>();
			LightComponent[] array2 = array;
			foreach (LightComponent lightComponent in array2)
			{
				lightComponent.SetLightColor();
				lightComponent.SetLightBrightness(150);
			}
			Material[] materials = ((Renderer)MachineMesh).materials;
			materials[2] = SideConsoleMaterial;
			materials[11] = FrontConsoleMaterial;
			((Renderer)MachineMesh).materials = materials;
			MachineAnimator.SetTrigger("PowerOn");
			StartRoomLight startRoomLight = Object.FindObjectOfType<StartRoomLight>();
			startRoomLight.SetCentralRoomWhite();
			((Component)BatteryNetObj).gameObject.GetComponentInChildren<GrabbableObject>().grabbable = false;
			ManageEnemies();
			WideDoorway[] doorways = Doorways;
			foreach (WideDoorway wideDoorway in doorways)
			{
				wideDoorway.RaiseDoor();
			}
		}

		private void ManageEnemies()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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)
			EyeSecAI.BuffedByMachineOn = true;
			if (OoblGhostAI.GhostList.Count < 1)
			{
				RoundManager.Instance.SpawnEnemyGameObject(new Vector3(0f, -1000f, 0f), 0f, 1, MonsterPatch.InsideEnemies.First((SpawnableEnemyWithRarity x) => x.enemyType.enemyName == "Oobl Ghost").enemyType);
			}
			RoundManager.Instance.SpawnEnemyGameObject(new Vector3(0f, -1000f, 0f), 0f, 1, MonsterPatch.InsideEnemies.First((SpawnableEnemyWithRarity x) => x.enemyType.enemyName == "Oobl Ghost").enemyType);
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_BatteryRecepticle()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2534650821u, new RpcReceiveHandler(__rpc_handler_2534650821));
			NetworkManager.__rpc_func_table.Add(1080085237u, new RpcReceiveHandler(__rpc_handler_1080085237));
			NetworkManager.__rpc_func_table.Add(3606445563u, new RpcReceiveHandler(__rpc_handler_3606445563));
			NetworkManager.__rpc_func_table.Add(195750096u, new RpcReceiveHandler(__rpc_handler_195750096));
		}

		private static void __rpc_handler_2534650821(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference grabbableObjectNetObject = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref grabbableObjectNetObject, default(ForNetworkSerializable));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((BatteryRecepticle)(object)target).InsertBatteryServerRpc(grabbableObjectNetObject);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1080085237(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference grabbableObjectNetObject = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref grabbableObjectNetObject, default(ForNetworkSerializable));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((BatteryRecepticle)(object)target).InsertBatteryClientRpc(grabbableObjectNetObject);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3606445563(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((BatteryRecepticle)(object)target).TurnOnPowerServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_195750096(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((BatteryRecepticle)(object)target).TurnOnPowerClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "BatteryRecepticle";
		}
	}
	public class ScrapShelf : NetworkBehaviour
	{
		public Transform[] ScrapSpawnPoints;

		public Animator ShelfOpener;

		public AudioSource ShelfSFX;

		private Random ShelfRandom;

		public void Start()
		{
			//IL_0119: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			List<SpawnableItemWithRarity> spawnableScrap = StartOfRound.Instance.currentLevel.spawnableScrap;
			List<SpawnableItemWithRarity> list = new List<SpawnableItemWithRarity>();
			List<SpawnableItemWithRarity> list2 = new List<SpawnableItemWithRarity>();
			ShelfRandom = new Random(StartOfRound.Instance.randomMapSeed);
			foreach (SpawnableItemWithRarity item in spawnableScrap)
			{
				if (item.spawnableItem.twoHanded)
				{
					list2.Add(item);
				}
				else
				{
					list.Add(item);
				}
			}
			Transform[] scrapSpawnPoints = ScrapSpawnPoints;
			foreach (Transform val in scrapSpawnPoints)
			{
				if (((NetworkBehaviour)this).IsServer)
				{
					SpawnableItemWithRarity val2 = ((ShelfRandom.Next(0, 100) >= 80) ? list[ShelfRandom.Next(0, list2.Count)] : list2[ShelfRandom.Next(0, list2.Count)]);
					GameObject val3 = Object.Instantiate<GameObject>(val2.spawnableItem.spawnPrefab, ((Component)val).transform.position, ((Component)val).transform.rotation, RoundManager.Instance.mapPropsContainer.transform);
					GrabbableObject component = val3.GetComponent<GrabbableObject>();
					int num = ShelfRandom.Next(component.itemProperties.minValue, component.itemProperties.maxValue);
					num = (int)Math.Round((double)num * 0.4);
					NetworkObject component2 = val3.GetComponent<NetworkObject>();
					component2.Spawn(true);
					RoundManager.Instance.spawnedSyncedObjects.Add(val3);
					SetScrapValueServerRpc(NetworkObjectReference.op_Implicit(component2), num);
				}
			}
		}

		public void OpenShelf()
		{
			ShelfOpener.SetTrigger("Open");
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				ShelfSFX.Play();
			}
		}

		[ServerRpc]
		public void SetScrapValueServerRpc(NetworkObjectReference ScrapToSet, int ScrapValue)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Invalid comparison between Unknown and I4
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown