Decompiled source of StrangerThings v1.0.0

StrangerThings.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DigitalRuby.ThunderAndLightning;
using GameNetcodeStuff;
using HarmonyLib;
using LegaFusionCore;
using LegaFusionCore.Behaviours.Shaders;
using LegaFusionCore.Managers;
using LegaFusionCore.Managers.NetworkManagers;
using LegaFusionCore.Registries;
using LegaFusionCore.Utilities;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using StrangerThings.Behaviours.Enemies;
using StrangerThings.Behaviours.Items;
using StrangerThings.Behaviours.MapObjects;
using StrangerThings.Behaviours.Scripts;
using StrangerThings.Managers;
using StrangerThings.ModsCompat;
using StrangerThings.NetcodePatcher;
using StrangerThings.Patches;
using StrangerThings.Registries;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StrangerThings")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StrangerThings")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("55a48e0f-a2f5-4aaf-a2fa-909d3c45d5d2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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;
		}
	}
}
namespace StrangerThings
{
	internal class Constants
	{
		public const string GLOBAL = "_Global_";

		public const string MIRROR_SCRAPS = "Mirror Scraps";

		public const string UPSIDE_DOWN = "Upside Down";

		public const string CORRUPTED_PORTALS = "Corrupted Portals";

		public const string DEMOGORGON = "Demogorgon";

		public const string VECNA = "Vecna";

		public const string CRUSTAPIKAN = "Crustapikan";

		public const string CRUSTAPIKAN_LARVAE = "Crustapikan Larvae";

		public const string LIMADON = "Limadon";

		public const string MIRROR_FUSION = "Mirror Fusion : [E]";
	}
	[BepInPlugin("Lega.StrangerThings", "Stranger Things", "1.0.0")]
	public class StrangerThings : BaseUnityPlugin
	{
		internal const string modGUID = "Lega.StrangerThings";

		internal const string modName = "Stranger Things";

		internal const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Lega.StrangerThings");

		internal static readonly AssetBundle bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "strangerthings"));

		internal static ManualLogSource mls;

		public static ConfigFile configFile;

		public static GameObject managerPrefab = NetworkPrefabs.CreateNetworkPrefab("StrangerThingsNetworkManager");

		public static Dictionary<EnemyType, int> upsideDownEnemies = new Dictionary<EnemyType, int>();

		public static GameObject upsideDownAtmosphere;

		public static GameObject upsideDownPortal;

		public static GameObject upsideDownMirrorObject;

		public static GameObject antennaHazard;

		public static GameObject rockProjectileObj;

		public static GameObject rockExplosionAudio;

		public static Item antennaItem;

		public static EnemyType limadonType;

		public static EnemyType crustopikanLarvaeType;

		public void Awake()
		{
			mls = Logger.CreateLogSource("StrangerThings");
			configFile = ((BaseUnityPlugin)this).Config;
			ConfigManager.Load();
			LoadManager();
			NetcodePatcher();
			LoadItems();
			LoadEnemies();
			LoadPrefabs();
			LoadNetworkPrefabs();
			harmony.PatchAll(typeof(AudioMixerPatch));
			harmony.PatchAll(typeof(NetworkBehaviourPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(GrabbableObjectPatch));
			harmony.PatchAll(typeof(ShotgunItemPatch));
			harmony.PatchAll(typeof(FlashlightItemPatch));
			harmony.PatchAll(typeof(GiftBoxItemPatch));
			harmony.PatchAll(typeof(StormyWeatherPatch));
			harmony.PatchAll(typeof(LightningBoltScriptPatch));
			harmony.PatchAll(typeof(DoorLockPatch));
			harmony.PatchAll(typeof(EnemyAIPatch));
			harmony.PatchAll(typeof(FlowerSnakeEnemyPatch));
			harmony.PatchAll(typeof(HoarderBugAIPatch));
			harmony.PatchAll(typeof(JesterAIPatch));
			harmony.PatchAll(typeof(NutcrackerEnemyAIPatch));
			harmony.PatchAll(typeof(RadMechAIPatch));
			harmony.PatchAll(typeof(SandSpiderWebTrapPatch));
			harmony.PatchAll(typeof(DeadBodyInfoPatch));
			harmony.PatchAll(typeof(VehicleControllerPatch));
			MelaniesVoiceSoftCompat.Patch(harmony);
			SelfSortingStorageSoftCompat.Patch(harmony);
			OpenBodyCamsSoftCompat.Patch(harmony);
		}

		public static void LoadManager()
		{
			Utilities.FixMixerGroups(managerPrefab);
			managerPrefab.AddComponent<StrangerThingsNetworkManager>();
		}

		private static void NetcodePatcher()
		{
			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 LoadItems()
		{
			antennaItem = LFCObjectsManager.RegisterObject(typeof(AntennaItem), bundle.LoadAsset<Item>("Assets/Antenna/AntennaItem.asset"));
			Items.RegisterShopItem(antennaItem, 10);
		}

		public void LoadEnemies()
		{
			RegisterEnemy(bundle.LoadAsset<EnemyType>("Assets/Demogorgon/DemogorgonKidnapperEnemy.asset"), ConfigManager.demogorgonRarity.Value, (LevelTypes)(-1), bundle.LoadAsset<TerminalNode>("Assets/Demogorgon/DemogorgonTN.asset"), bundle.LoadAsset<TerminalKeyword>("Assets/Demogorgon/DemogorgonTK.asset"), bundle.LoadAsset<Item>("Assets/Demogorgon/DemogorgonHeadItem.asset"), ConfigManager.demogorgonMinHeadValue.Value, ConfigManager.demogorgonMaxHeadValue.Value);
			RegisterEnemy(bundle.LoadAsset<EnemyType>("Assets/Demogorgon/DemogorgonHunterEnemy.asset"), ConfigManager.demogorgonRarity.Value, (LevelTypes)(-1), bundle.LoadAsset<TerminalNode>("Assets/Demogorgon/DemogorgonTN.asset"), bundle.LoadAsset<TerminalKeyword>("Assets/Demogorgon/DemogorgonTK.asset"), bundle.LoadAsset<Item>("Assets/Demogorgon/DemogorgonHeadItem.asset"), ConfigManager.demogorgonMinHeadValue.Value, ConfigManager.demogorgonMaxHeadValue.Value);
			RegisterUpsideDownEnemy(bundle.LoadAsset<EnemyType>("Assets/Crustapikan/CrustapikanEnemy.asset"), ConfigManager.crustapikanRarity.Value, bundle.LoadAsset<TerminalNode>("Assets/Crustapikan/CrustapikanTN.asset"), bundle.LoadAsset<TerminalKeyword>("Assets/Crustapikan/CrustapikanTK.asset"), bundle.LoadAsset<Item>("Assets/Crustapikan/CrustapikanArmItem.asset"), ConfigManager.crustapikanMinArmValue.Value, ConfigManager.crustapikanMaxArmValue.Value);
			limadonType = RegisterUpsideDownEnemy(bundle.LoadAsset<EnemyType>("Assets/Limadon/LimadonEnemy.asset"), ConfigManager.limadonRarity.Value, bundle.LoadAsset<TerminalNode>("Assets/Limadon/LimadonTN.asset"), bundle.LoadAsset<TerminalKeyword>("Assets/Limadon/LimadonTK.asset"), bundle.LoadAsset<Item>("Assets/Limadon/LimadonCorpseItem.asset"), ConfigManager.limadonMinCorpseValue.Value, ConfigManager.limadonMaxCorpseValue.Value);
			crustopikanLarvaeType = RegisterUpsideDownEnemy(bundle.LoadAsset<EnemyType>("Assets/CrustapikanLarvae/CrustapikanLarvaeEnemy.asset"), ConfigManager.crustapikanLarvaeRarity.Value, bundle.LoadAsset<TerminalNode>("Assets/CrustapikanLarvae/CrustapikanLarvaeTN.asset"), bundle.LoadAsset<TerminalKeyword>("Assets/CrustapikanLarvae/CrustapikanLarvaeTK.asset"), bundle.LoadAsset<Item>("Assets/CrustapikanLarvae/CrustapikanLarvaeCorpseItem.asset"), ConfigManager.crustapikanLarvaeMinCorpseValue.Value, ConfigManager.crustapikanLarvaeMaxCorpseValue.Value);
		}

		public EnemyType RegisterEnemy(EnemyType enemyType, int rarity, LevelTypes levelTypes, TerminalNode terminalNode, TerminalKeyword terminalKeyword, Item bodyItem, int bodyMinValue, int bodyMaxValue, bool bodyEnabled = true)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			NetworkPrefabs.RegisterNetworkPrefab(enemyType.enemyPrefab);
			Enemies.RegisterEnemy(enemyType, rarity, levelTypes, terminalNode, terminalKeyword);
			SellBodiesFixedSoftCompat.RegisterBody(enemyType.enemyName, bodyItem, bodyMinValue, bodyMaxValue, bodyEnabled);
			return enemyType;
		}

		public EnemyType RegisterUpsideDownEnemy(EnemyType enemyType, int rarity, TerminalNode terminalNode, TerminalKeyword terminalKeyword, Item bodyItem, int bodyMinValue, int bodyMaxValue, bool bodyEnabled = true)
		{
			RegisterEnemy(enemyType, rarity, (LevelTypes)1, terminalNode, terminalKeyword, bodyItem, bodyMinValue, bodyMaxValue, bodyEnabled);
			upsideDownEnemies.Add(enemyType, rarity);
			return enemyType;
		}

		public void LoadPrefabs()
		{
			upsideDownAtmosphere = bundle.LoadAsset<GameObject>("Assets/UpsideDown/UpsideDownAtmosphere.prefab");
		}

		public void LoadNetworkPrefabs()
		{
			HashSet<GameObject> hashSet = new HashSet<GameObject>
			{
				upsideDownPortal = bundle.LoadAsset<GameObject>("Assets/UpsideDown/Portal/UpsideDownPortal.prefab"),
				upsideDownMirrorObject = bundle.LoadAsset<GameObject>("Assets/Items/UpsideDownMirrorObject.prefab"),
				antennaHazard = bundle.LoadAsset<GameObject>("Assets/Antenna/AntennaHazard.prefab"),
				rockProjectileObj = bundle.LoadAsset<GameObject>("Assets/Crustapikan/RockProjectile.prefab"),
				rockExplosionAudio = bundle.LoadAsset<GameObject>("Assets/Crustapikan/RockExplosionAudio.prefab")
			};
			foreach (GameObject item in hashSet)
			{
				NetworkPrefabs.RegisterNetworkPrefab(item);
				Utilities.FixMixerGroups(item);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "StrangerThings";

		public const string PLUGIN_NAME = "StrangerThings";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace StrangerThings.Registries
{
	public class DimensionRegistry : MonoBehaviour
	{
		private static readonly HashSet<GameObject> upsideDownEntities = new HashSet<GameObject>();

		public static GameObject GetUpsideDownEntity(GameObject entity)
		{
			upsideDownEntities.RemoveWhere((GameObject e) => (Object)(object)e == (Object)null);
			return ((IEnumerable<GameObject>)upsideDownEntities).FirstOrDefault((Func<GameObject, bool>)((GameObject e) => (Object)(object)e == (Object)(object)entity));
		}

		public static bool CanSetInUpsideDown(GameObject entity, bool isInUpsideDown)
		{
			PlayerControllerB safeComponent = LFCUtilities.GetSafeComponent<PlayerControllerB>(entity);
			if ((Object)(object)safeComponent != (Object)null && !safeComponent.isPlayerDead && !isInUpsideDown)
			{
				UpsideDownPortal[] upsideDownPortals = MapObjectsManager.GetUpsideDownPortals();
				foreach (UpsideDownPortal upsideDownPortal in upsideDownPortals)
				{
					if ((Object)(object)upsideDownPortal.corruptedPlayer == (Object)(object)safeComponent)
					{
						if (LFCUtilities.ShouldBeLocalPlayer(safeComponent))
						{
							HUDManager.Instance.DisplayTip("Impossible action", "You have been corrupted. You must find another way out.", false, false, "LC_Tip1");
						}
						return false;
					}
				}
			}
			if (!isInUpsideDown)
			{
				return upsideDownEntities.Remove(entity);
			}
			return upsideDownEntities.Add(entity);
		}

		public static void SetInUpsideDown(GameObject entity, bool isInUpsideDown)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer == (Object)null || (Object)(object)entity == (Object)null || !CanSetInUpsideDown(entity, isInUpsideDown))
			{
				return;
			}
			PlayerControllerB safeComponent = LFCUtilities.GetSafeComponent<PlayerControllerB>(entity);
			if ((Object)(object)safeComponent != (Object)null)
			{
				if (LFCUtilities.ShouldBeLocalPlayer(safeComponent))
				{
					RefreshStatesForLocalClient();
					UpdateLightsVisibilityForLocalClient();
					UpdateShipFeaturesForLocalClient();
					UpdateFlickeringFlashlights(safeComponent);
					UpsideDownAtmosphereController.Instance.SetUpsideDownState(isInUpsideDown);
				}
				else
				{
					if (LFCUtilities.LocalPlayer.isPlayerDead && (Object)(object)LFCUtilities.LocalPlayer.spectatedPlayerScript == (Object)(object)safeComponent)
					{
						SetInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject, isInUpsideDown);
						return;
					}
					UpdateVisibilityState(((Component)safeComponent).gameObject);
					UpdateFlickeringFlashlights(safeComponent);
				}
				StartOfRound.Instance.UpdatePlayerVoiceEffects();
			}
			else
			{
				UpdateVisibilityState(entity);
			}
		}

		public static bool IsInUpsideDown(GameObject entity)
		{
			if ((Object)(object)entity != (Object)null)
			{
				return Object.op_Implicit((Object)(object)GetUpsideDownEntity(entity));
			}
			return false;
		}

		public static bool AreInSameDimension(GameObject a, GameObject b)
		{
			if (!((Object)(object)a == (Object)null) && !((Object)(object)b == (Object)null) && !IsBlacklisted(a) && !IsBlacklisted(b))
			{
				return IsInUpsideDown(a) == IsInUpsideDown(b);
			}
			return true;
		}

		public static void RefreshStatesForLocalClient()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			NetworkBehaviour[] array = Object.FindObjectsOfType<NetworkBehaviour>(true);
			foreach (NetworkBehaviour val in array)
			{
				if (val.IsSpawned && IsWhitelisted(((Component)val).gameObject))
				{
					UpdateVisibilityState(((Component)val).gameObject);
				}
			}
			foreach (GrabbableObject allA in LFCSpawnRegistry.GetAllAs<GrabbableObject>())
			{
				if (LFCUtilities.LocalPlayer.ItemSlots.Contains(allA))
				{
					StrangerThingsNetworkManager.Instance.SetGObjectInUpsideDownEveryoneRpc(NetworkObjectReference.op_Implicit(((Component)allA).GetComponent<NetworkObject>()), IsInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject));
				}
				else
				{
					UpdateVisibilityState(((Component)allA).gameObject);
				}
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if (LFCUtilities.ShouldNotBeLocalPlayer(val2))
				{
					UpdateVisibilityState(((Component)val2).gameObject);
				}
			}
			SandSpiderWebTrap[] array2 = Object.FindObjectsOfType<SandSpiderWebTrap>(true);
			foreach (SandSpiderWebTrap val3 in array2)
			{
				UpdateVisibilityState(((Component)val3).gameObject);
			}
			DeadBodyInfo[] array3 = Object.FindObjectsOfType<DeadBodyInfo>(true);
			foreach (DeadBodyInfo val4 in array3)
			{
				UpdateVisibilityState(((Component)val4).gameObject);
			}
		}

		public static void UpdateVisibilityState(GameObject entity)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, entity))
			{
				LFCVisibilityRegistry.Restore(entity, "Stranger ThingsDimension");
			}
			else
			{
				LFCVisibilityRegistry.Hide(entity, "Stranger ThingsDimension");
			}
		}

		private static void UpdateLightsVisibilityForLocalClient()
		{
			foreach (Animator allPoweredLightsAnimator in RoundManager.Instance.allPoweredLightsAnimators)
			{
				if (IsInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject))
				{
					LFCPoweredLightsRegistry.AddLock(allPoweredLightsAnimator, "Stranger Things");
				}
				else
				{
					LFCPoweredLightsRegistry.RemoveLock(allPoweredLightsAnimator, "Stranger Things");
				}
			}
		}

		private static void UpdateShipFeaturesForLocalClient()
		{
			if (IsInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject))
			{
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)0, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)1, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)2, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)3, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)4, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)5, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)6, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)7, "Stranger Things");
				LFCShipFeatureRegistry.AddLock((ShipFeatureType)8, "Stranger Things");
			}
			else
			{
				LFCShipFeatureRegistry.ClearLocks("Stranger Things");
			}
		}

		private static void UpdateFlickeringFlashlights(PlayerControllerB player)
		{
			if (IsInUpsideDown(((Component)player).gameObject))
			{
				return;
			}
			HashSet<Component> setExact = LFCSpawnRegistry.GetSetExact<FlashlightItem>();
			if (setExact == null)
			{
				return;
			}
			foreach (FlashlightItem item in setExact.Cast<FlashlightItem>())
			{
				LFCObjectStateRegistry.RemoveFlickeringFlashlight(item, "Stranger Things" + player.playerUsername);
			}
		}

		public static bool IsWhitelisted(GameObject gObject)
		{
			if ((Object)(object)gObject != (Object)null && !IsBlacklisted(gObject))
			{
				EnemyAI val = default(EnemyAI);
				VehicleController val2 = default(VehicleController);
				RockProjectile rockProjectile = default(RockProjectile);
				AntennaHazard antennaHazard = default(AntennaHazard);
				if (!gObject.TryGetComponent<EnemyAI>(ref val) && !gObject.TryGetComponent<VehicleController>(ref val2) && !gObject.TryGetComponent<RockProjectile>(ref rockProjectile) && !gObject.TryGetComponent<AntennaHazard>(ref antennaHazard))
				{
					return LFCUtilities.HasNameFromList(LFCUtilities.GetGameObjectName(gObject), ConfigManager.visibilityStateInclusions.Value);
				}
				return true;
			}
			return false;
		}

		public static bool IsBlacklisted(GameObject gObject)
		{
			if ((Object)(object)gObject != (Object)null)
			{
				return LFCUtilities.HasNameFromList(LFCUtilities.GetGameObjectName(gObject), ConfigManager.visibilityStateExclusions.Value);
			}
			return false;
		}
	}
}
namespace StrangerThings.Patches
{
	public class AudioMixerPatch
	{
		[HarmonyPatch(typeof(AudioMixer), "SetFloat")]
		[HarmonyBefore(new string[] { "me.swipez.melonloader.morecompany" })]
		[HarmonyPrefix]
		private static void UpdatePlayerVolume(string name, ref float value)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null || !name.StartsWith("PlayerVolume"))
			{
				return;
			}
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null || !localPlayer.isPlayerControlled || localPlayer.isPlayerDead)
			{
				return;
			}
			int length = "PlayerVolume".Length;
			string s = name.Substring(length, name.Length - length);
			if (int.TryParse(s, out var result) && result >= 0 && result < StartOfRound.Instance.allPlayerScripts.Length)
			{
				float num = 1f;
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[result];
				if ((Object)(object)val != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)localPlayer).gameObject, ((Component)val).gameObject))
				{
					num = ((!DimensionRegistry.IsInUpsideDown(((Component)localPlayer).gameObject)) ? (((!localPlayer.speakingToWalkieTalkie || !val.holdingWalkieTalkie) && (!val.speakingToWalkieTalkie || !localPlayer.holdingWalkieTalkie)) ? 0f : (MapObjectsManager.IsNearAntennaHazard(val) ? 1f : 0f)) : (((!localPlayer.speakingToWalkieTalkie || !val.holdingWalkieTalkie) && (!val.speakingToWalkieTalkie || !localPlayer.holdingWalkieTalkie)) ? 0.1f : (MapObjectsManager.IsNearAntennaHazard(localPlayer) ? 1f : 0f)));
				}
				value *= num;
			}
		}
	}
	public class DeadBodyInfoPatch
	{
		[HarmonyPatch(typeof(DeadBodyInfo), "Awake")]
		[HarmonyPostfix]
		private static void AwakeDeadBodyInfo(DeadBodyInfo __instance)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)null)
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}
	}
	public class DoorLockPatch
	{
		[HarmonyPatch(typeof(DoorLock), "OnTriggerStay")]
		[HarmonyPostfix]
		private static void BreakDoor(DoorLock __instance, ref Collider other)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (LFCUtilities.IsServer && !__instance.isDoorOpened && !((Object)(object)((Component)__instance).GetComponent<DoorProjectile>() != (Object)null) && !((Object)(object)other == (Object)null) && ((Component)other).CompareTag("Enemy"))
			{
				EnemyAICollisionDetect component = ((Component)other).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && component.mainScript is DemogorgonAI demogorgonAI && demogorgonAI.isDashing)
				{
					Vector3 val = ((Component)((EnemyAI)demogorgonAI).targetPlayer).transform.position - ((Component)demogorgonAI).transform.position;
					Vector3 direction = ((Vector3)(ref val)).normalized * 5f;
					demogorgonAI.BreakDoorEveryoneRpc(NetworkObjectReference.op_Implicit(((Component)__instance).GetComponentInParent<NetworkObject>()), direction);
					((EnemyAI)demogorgonAI).agent.speed = 0f;
					((EnemyAI)demogorgonAI).agent.velocity = Vector3.zero;
				}
			}
		}
	}
	public class EnemyAIPatch
	{
		[HarmonyPatch(typeof(EnemyAI), "Start")]
		[HarmonyPostfix]
		private static void StartEnemy(ref EnemyAI __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (LFCUtilities.IsServer && !(__instance is UpsideDownEnemyAI))
			{
				SpawnUpsideDownEnemy(__instance.isOutside, ((Component)__instance).transform.position);
			}
		}

		private static void SpawnUpsideDownEnemy(bool isOutside, Vector3 position)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			EnemyType randomEnemy = GetRandomEnemy(isOutside);
			if ((Object)(object)randomEnemy != (Object)null)
			{
				position = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(position, 10f, default(NavMeshHit));
				GameObject val = Object.Instantiate<GameObject>(randomEnemy.enemyPrefab, position, Quaternion.identity);
				NetworkObject componentInChildren = val.GetComponentInChildren<NetworkObject>();
				componentInChildren.Spawn(true);
				randomEnemy.numberSpawned++;
				RoundManager.Instance.SpawnedEnemies.Add(val.GetComponent<EnemyAI>());
			}
		}

		public static EnemyType GetRandomEnemy(bool isOutside)
		{
			List<EnemyType> eligibleEnemies = GetEligibleEnemies(isOutside);
			if (eligibleEnemies.Count <= 0)
			{
				return null;
			}
			return eligibleEnemies[new Random().Next(eligibleEnemies.Count)];
		}

		public static List<EnemyType> GetEligibleEnemies(bool isOutside)
		{
			List<EnemyType> list = new List<EnemyType>();
			foreach (KeyValuePair<EnemyType, int> upsideDownEnemy in StrangerThings.upsideDownEnemies)
			{
				EnemyType key = upsideDownEnemy.Key;
				EnemyAI component = key.enemyPrefab.GetComponent<EnemyAI>();
				if ((Object)(object)component != (Object)null && component.isOutside == isOutside && key.numberSpawned < key.MaxCount)
				{
					for (int i = 0; i < upsideDownEnemy.Value; i++)
					{
						list.Add(key);
					}
				}
			}
			return list;
		}

		[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
		[HarmonyPrefix]
		private static bool PlayerIsTargetable(ref EnemyAI __instance, ref bool __result, PlayerControllerB playerScript)
		{
			if (!DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)playerScript).gameObject) && (!(__instance is DemogorgonKidnapperAI demogorgonKidnapperAI) || ((EnemyAI)demogorgonKidnapperAI).currentBehaviourStateIndex != 0))
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyAI), "NavigateTowardsTargetPlayer")]
		[HarmonyPrefix]
		private static bool NavigateTowardsPlayer(ref EnemyAI __instance)
		{
			//IL_0021: 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)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__instance.targetPlayer).gameObject))
			{
				UpsideDownPortal closestPortal = MapObjectsManager.GetClosestPortal(((Component)__instance).transform.position);
				if ((Object)(object)closestPortal == (Object)null)
				{
					return true;
				}
				__instance.destination = ((Component)closestPortal).transform.position;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyAI), "TargetClosestPlayer")]
		[HarmonyPostfix]
		private static void PreventTargetClosestPlayer(EnemyAI __instance, ref bool __result)
		{
			if (__result && (Object)(object)__instance.targetPlayer != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__instance.targetPlayer).gameObject))
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForClosestPlayer")]
		[HarmonyPostfix]
		private static void PreventCheckLineOfSightForClosestPlayer(EnemyAI __instance, ref PlayerControllerB __result)
		{
			if ((Object)(object)__result != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__result).gameObject))
			{
				__result = null;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForPlayer")]
		[HarmonyPostfix]
		private static void PreventCheckLineOfSightForPlayer(EnemyAI __instance, ref PlayerControllerB __result)
		{
			if ((Object)(object)__result != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__result).gameObject))
			{
				__result = null;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "GetClosestPlayer")]
		[HarmonyPostfix]
		private static void PreventGetClosestPlayer(EnemyAI __instance, ref PlayerControllerB __result)
		{
			if ((Object)(object)__result != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__result).gameObject))
			{
				__result = null;
			}
		}
	}
	public class FlashlightItemPatch
	{
		[HarmonyPatch(typeof(FlashlightItem), "SwitchFlashlight")]
		[HarmonyPostfix]
		private static void SwitchFlashlight(FlashlightItem __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}

		[HarmonyPatch(typeof(FlashlightItem), "PocketFlashlightClientRpc")]
		[HarmonyPostfix]
		private static void PocketFlashlightForClients(FlashlightItem __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}
	}
	public class FlowerSnakeEnemyPatch
	{
		[HarmonyPatch(typeof(FlowerSnakeEnemy), "Update")]
		[HarmonyPostfix]
		private static void UpdateTulipSnake(FlowerSnakeEnemy __instance)
		{
			if ((Object)(object)__instance.clingingToPlayer != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)__instance.clingingToPlayer).gameObject))
			{
				__instance.StopClingingOnLocalClient(__instance.clingPosition == 4);
			}
		}
	}
	public class GiftBoxItemPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(GiftBoxItem), "OpenGiftBoxServerRpc")]
		private static IEnumerable<CodeInstruction> OpenGiftBoxForServer(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(NetworkObject), "Spawn", new Type[1] { typeof(bool) }, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(NetworkBehaviour), "NetworkObject");
			MethodInfo methodInfo3 = AccessTools.Method(typeof(GiftBoxItemPatch), "SetInUpsideDown", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count; i++)
			{
				if (!CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					continue;
				}
				int num = -1;
				for (int num2 = i; num2 >= 1; num2--)
				{
					if (CodeInstructionExtensions.Calls(list[num2], methodInfo2) && CodeInstructionExtensions.IsLdloc(list[num2 - 1], (LocalBuilder)null))
					{
						num = num2 - 1;
						break;
					}
				}
				if (num != -1)
				{
					List<CodeInstruction> list2 = new List<CodeInstruction>(3)
					{
						list[num].Clone(),
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Call, (object)methodInfo3)
					};
					int index = i + 1;
					list.InsertRange(index, list2);
					i += list2.Count;
				}
			}
			return list;
		}

		private static void SetInUpsideDown(GrabbableObject grabbableObject, GiftBoxItem giftBox)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)grabbableObject != (Object)null && (Object)(object)giftBox != (Object)null && DimensionRegistry.IsInUpsideDown(((Component)giftBox).gameObject))
			{
				StrangerThingsNetworkManager.Instance.SetGObjectInUpsideDownEveryoneRpc(NetworkObjectReference.op_Implicit(((Component)grabbableObject).GetComponent<NetworkObject>()), isInUpsideDown: true);
			}
		}
	}
	public class GrabbableObjectPatch
	{
		[HarmonyPatch(typeof(GrabbableObject), "EnableItemMeshes")]
		[HarmonyPostfix]
		private static void EnableItemMeshes(GrabbableObject __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "PocketItem")]
		[HarmonyPostfix]
		private static void PocketItem(GrabbableObject __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "DiscardItem")]
		[HarmonyPostfix]
		private static void DiscardItem(GrabbableObject __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "UseItemBatteries")]
		[HarmonyPrefix]
		private static bool UseItemBatteries(GrabbableObject __instance, ref bool __result)
		{
			if (__instance is AntennaItem)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	public class HoarderBugAIPatch
	{
		[HarmonyPatch(typeof(HoarderBugAI), "RefreshGrabbableObjectsInMapList")]
		[HarmonyPostfix]
		private static void RefreshGrabbableObjects()
		{
			HashSet<GameObject> gObjects = new HashSet<GameObject>(from g in LFCSpawnRegistry.GetAllAs<GrabbableObject>()
				where (Object)(object)g != (Object)null && DimensionRegistry.IsInUpsideDown(((Component)g).gameObject)
				select ((Component)g).gameObject);
			HoarderBugAI.grabbableObjectsInMap.RemoveAll((GameObject g) => (Object)(object)g == (Object)null || gObjects.Contains(g));
			HoarderBugAI.HoarderBugItems.RemoveAll((HoarderBugItem h) => h == null || (Object)(object)h.itemGrabbableObject == (Object)null || gObjects.Contains(((Component)h.itemGrabbableObject).gameObject));
		}
	}
	public static class JesterAIPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(JesterAI), "Update")]
		private static void CaptureTimer(ref float ___noPlayersToChaseTimer, ref float __state)
		{
			__state = ___noPlayersToChaseTimer;
		}

		[HarmonyPostfix]
		[HarmonyAfter(new string[] { "AudioKnight.StarlancerAIFix" })]
		[HarmonyPatch(typeof(JesterAI), "Update")]
		private static void UpdateJester(ref JesterAI __instance, ref bool ___targetingPlayer, ref float ___noPlayersToChaseTimer, float __state)
		{
			if (!LFCUtilities.IsServer || ((EnemyAI)__instance).currentBehaviourStateIndex != 2)
			{
				return;
			}
			if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)((EnemyAI)__instance).targetPlayer).gameObject))
			{
				((EnemyAI)__instance).targetPlayer = null;
			}
			___targetingPlayer = false;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isPlayerControlled && val.isInsideFactory != ((EnemyAI)__instance).isOutside && DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)val).gameObject))
				{
					___targetingPlayer = true;
					break;
				}
			}
			float num = __state;
			if (!___targetingPlayer)
			{
				num -= Time.deltaTime;
				if (num <= 0f)
				{
					((EnemyAI)__instance).SwitchToBehaviourState(0);
				}
			}
			else
			{
				num = 5f;
			}
			___noPlayersToChaseTimer = num;
		}
	}
	public class LightningBoltScriptPatch
	{
		[HarmonyPatch(typeof(LightningBoltScript), "CreateParameters")]
		[HarmonyPostfix]
		private static void UpsideDownStrike(ref LightningBoltParameters __result)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (DimensionRegistry.IsInUpsideDown((localPlayer != null) ? ((Component)localPlayer).gameObject : null))
			{
				Color32 val = default(Color32);
				((Color32)(ref val))..ctor((byte)230, (byte)25, (byte)25, byte.MaxValue);
				__result.Color = val;
				__result.MainTrunkTintColor = val;
				__result.Intensity = 1.6f;
				__result.GlowIntensity = 1.4f;
				__result.GlowWidthMultiplier = 1.2f;
				__result.Forkedness = 1.2f;
			}
		}
	}
	public class NetworkBehaviourPatch
	{
		[HarmonyPatch(typeof(NetworkBehaviour), "InternalOnNetworkSpawn")]
		[HarmonyPostfix]
		private static void SpawnNetworkBehaviour(NetworkBehaviour __instance)
		{
			VehicleController val = default(VehicleController);
			if (!((Component)__instance).gameObject.TryGetComponent<VehicleController>(ref val) && (DimensionRegistry.IsWhitelisted(((Component)__instance).gameObject) || __instance is GrabbableObject))
			{
				if (__instance is UpsideDownObject || __instance is UpsideDownEnemyAI)
				{
					DimensionRegistry.SetInUpsideDown(((Component)__instance).gameObject, isInUpsideDown: true);
				}
				else
				{
					DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
				}
			}
		}
	}
	public class NutcrackerEnemyAIPatch
	{
		[HarmonyPatch(typeof(NutcrackerEnemyAI), "CheckLineOfSightForLocalPlayer")]
		[HarmonyPostfix]
		private static void PreventCheckLineOfSightForLocalPlayer(NutcrackerEnemyAI __instance, ref bool __result)
		{
			if (__result && (Object)(object)LFCUtilities.LocalPlayer != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance).gameObject, ((Component)LFCUtilities.LocalPlayer).gameObject))
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(NutcrackerEnemyAI), "TurnTorsoToTargetDegrees")]
		[HarmonyPostfix]
		private static void TurnTorsoAudio(NutcrackerEnemyAI __instance)
		{
			GameObject gameObject = ((Component)__instance).gameObject;
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (!DimensionRegistry.AreInSameDimension(gameObject, (localPlayer != null) ? ((Component)localPlayer).gameObject : null))
			{
				__instance.torsoTurnAudio.volume = 0f;
			}
		}
	}
	public class PlayerControllerBPatch
	{
		private static bool canFlick = false;

		private static float flickerTimer = 0f;

		private static readonly float flickerCooldown = 0.5f;

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		private static void StartPlayer(PlayerControllerB __instance)
		{
			if (LFCUtilities.ShouldBeLocalPlayer(__instance) && (Object)(object)UpsideDownAtmosphereController.Instance == (Object)null)
			{
				Object.Instantiate<GameObject>(StrangerThings.upsideDownAtmosphere, ((Component)__instance.gameplayCamera).transform);
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPrefix]
		private static void PreUpdatePlayer(PlayerControllerB __instance, bool ___isCameraDisabled, bool ___isPlayerControlled, bool ___isHostPlayerObject, bool ___isTestingPlayer)
		{
			if (___isCameraDisabled && ((((NetworkBehaviour)__instance).IsOwner && ___isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || ___isHostPlayerObject)) || ___isTestingPlayer) && DimensionRegistry.IsInUpsideDown(((Component)__instance).gameObject))
			{
				DimensionRegistry.SetInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject, isInUpsideDown: false);
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void PostUpdatePlayer(PlayerControllerB __instance)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)RoundManager.Instance == (Object)null)
			{
				return;
			}
			if (LFCUtilities.ShouldBeLocalPlayer(__instance))
			{
				LFCUtilities.UpdateTimer(ref flickerTimer, flickerCooldown, !canFlick, (Action)delegate
				{
					canFlick = true;
				});
			}
			else
			{
				if (!canFlick || !DimensionRegistry.IsInUpsideDown(((Component)__instance).gameObject))
				{
					return;
				}
				canFlick = false;
				Animator val = null;
				float num = float.MaxValue;
				Vector3 val2;
				foreach (Animator allPoweredLightsAnimator in RoundManager.Instance.allPoweredLightsAnimators)
				{
					val2 = ((Component)allPoweredLightsAnimator).transform.position - ((Component)__instance).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (!LFCPoweredLightsRegistry.IsLocked(allPoweredLightsAnimator) && sqrMagnitude <= 50f && sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = allPoweredLightsAnimator;
					}
				}
				if (val != null)
				{
					val.SetTrigger("Flicker");
				}
				HashSet<Component> setExact = LFCSpawnRegistry.GetSetExact<FlashlightItem>();
				if (setExact == null)
				{
					return;
				}
				foreach (FlashlightItem item in setExact.Cast<FlashlightItem>())
				{
					if (!DimensionRegistry.IsInUpsideDown(((Component)item).gameObject))
					{
						val2 = ((Component)item).transform.position - ((Component)__instance).transform.position;
						if (((Vector3)(ref val2)).sqrMagnitude <= 25f)
						{
							LFCObjectStateRegistry.AddFlickeringFlashlight(item, "Stranger Things" + __instance.playerUsername);
							continue;
						}
					}
					LFCObjectStateRegistry.RemoveFlickeringFlashlight(item, "Stranger Things" + __instance.playerUsername);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger")]
		[HarmonyPrefix]
		private static bool SetHoverTipMirrorFusion(PlayerControllerB __instance)
		{
			if (DimensionRegistry.IsInUpsideDown(((Component)__instance).gameObject) && !string.IsNullOrEmpty(((TMP_Text)__instance.cursorTip).text))
			{
				return !((TMP_Text)__instance.cursorTip).text.Equals("Mirror Fusion : [E]");
			}
			return true;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
		[HarmonyPrefix]
		private static bool MirrorFusionActivate(PlayerControllerB __instance, ref CallbackContext context)
		{
			if (!((CallbackContext)(ref context)).performed || !LFCUtilities.ShouldBeLocalPlayer(__instance) || !DimensionRegistry.IsInUpsideDown(((Component)__instance).gameObject) || __instance.isPlayerDead || !__instance.isPlayerControlled || __instance.isGrabbingObjectAnimation || __instance.inSpecialMenu || __instance.quickMenuManager.isMenuOpen)
			{
				return true;
			}
			GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
			UpsideDownMirrorBehaviour upsideDownMirrorBehaviour = default(UpsideDownMirrorBehaviour);
			if ((Object)(object)currentlyHeldObjectServer != (Object)null && LFCUtilities.TryGetComponentInChildren<UpsideDownMirrorBehaviour>(((Component)currentlyHeldObjectServer).gameObject, ref upsideDownMirrorBehaviour) && upsideDownMirrorBehaviour.canFusion)
			{
				upsideDownMirrorBehaviour.CompleteFusionServerRpc();
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerClientRpc")]
		[HarmonyPostfix]
		private static void KillPlayerForClients(PlayerControllerB __instance)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)(object)__instance && DimensionRegistry.IsInUpsideDown(((Component)__instance).gameObject))
			{
				DimensionRegistry.SetInUpsideDown(((Component)__instance).gameObject, isInUpsideDown: false);
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SpectateNextPlayer")]
		[HarmonyPostfix]
		private static void SwitchSpectatedPlayer(PlayerControllerB __instance)
		{
			if ((Object)(object)__instance.spectatedPlayerScript != (Object)null && !DimensionRegistry.AreInSameDimension(((Component)__instance.spectatedPlayerScript).gameObject, ((Component)__instance).gameObject))
			{
				DimensionRegistry.SetInUpsideDown(((Component)__instance).gameObject, DimensionRegistry.IsInUpsideDown(((Component)__instance.spectatedPlayerScript).gameObject));
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ResetZAndXRotation")]
		[HarmonyPostfix]
		private static void ResetZAndXRotation(PlayerControllerB __instance)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)(object)__instance)
			{
				PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
				if (!DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject))
				{
					DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
				}
			}
		}
	}
	public class RadMechAIPatch
	{
		[HarmonyPatch(typeof(RadMechAI), "ShootGun")]
		[HarmonyPrefix]
		private static bool ShootGun(RadMechAI __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			return DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject);
		}

		[HarmonyPatch(typeof(RadMechAI), "SetExplosion")]
		[HarmonyPrefix]
		private static bool SetExplosion(RadMechAI __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			return DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject);
		}

		[HarmonyPatch(typeof(RadMechAI), "Stomp")]
		[HarmonyPrefix]
		private static bool Stomp(RadMechAI __instance)
		{
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			return DimensionRegistry.AreInSameDimension((localPlayer != null) ? ((Component)localPlayer).gameObject : null, ((Component)__instance).gameObject);
		}

		[HarmonyPatch(typeof(RadMechAI), "CheckSightForThreat")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CheckSightForThreatTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(RadMechAI), "focusedThreatTransform");
			MethodInfo methodInfo = AccessTools.Method(typeof(RadMechAIPatch), "AreInSameDimension", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i].opcode == OpCodes.Stfld && list[i].operand is FieldInfo fieldInfo2 && fieldInfo2 == fieldInfo)
				{
					Label label = il.DefineLabel();
					list[i + 1].labels.Add(label);
					list.InsertRange(i + 1, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[5]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Call, (object)methodInfo),
						new CodeInstruction(OpCodes.Brtrue_S, (object)label),
						new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
						new CodeInstruction(OpCodes.Ret, (object)null)
					}));
					break;
				}
			}
			return list;
		}

		private static bool AreInSameDimension(RadMechAI radMech)
		{
			Transform focusedThreatTransform = radMech.focusedThreatTransform;
			if (!DimensionRegistry.AreInSameDimension((focusedThreatTransform != null) ? ((Component)focusedThreatTransform).gameObject : null, ((Component)radMech).gameObject))
			{
				((EnemyAI)radMech).SwitchToBehaviourStateOnLocalClient(0);
				return false;
			}
			return true;
		}
	}
	public class RoundManagerPatch
	{
		[HarmonyPatch(typeof(RoundManager), "waitForScrapToSpawnToSync")]
		[HarmonyPostfix]
		private static IEnumerator SpawnMirrorObjects(IEnumerator result)
		{
			while (result.MoveNext())
			{
				yield return result.Current;
			}
			int num = Random.Range(ConfigManager.minMirrorScraps.Value, ConfigManager.maxMirrorScraps.Value + 1);
			int num2 = 0;
			foreach (GrabbableObject allA in LFCSpawnRegistry.GetAllAs<GrabbableObject>())
			{
				if (!string.IsNullOrEmpty(allA.itemProperties?.itemName) && (string.IsNullOrEmpty(ConfigManager.scrapExclusions.Value) || !ConfigManager.scrapExclusions.Value.Contains(allA.itemProperties.itemName)) && allA.isInFactory && !allA.isInShipRoom && allA.scrapValue > 0)
				{
					GrabbableObject val = SpawnUpsideDownObject(allA.itemProperties);
					if ((Object)(object)val != (Object)null)
					{
						GameObject val2 = Object.Instantiate<GameObject>(StrangerThings.upsideDownMirrorObject, ((Component)val).transform.position, Quaternion.identity);
						NetworkObject component = val2.GetComponent<NetworkObject>();
						component.Spawn(false);
						StrangerThingsNetworkManager.Instance.AddToMirrorEveryoneRpc(NetworkObjectReference.op_Implicit(component), NetworkObjectReference.op_Implicit(((Component)val).GetComponent<NetworkObject>()), NetworkObjectReference.op_Implicit(((Component)allA).GetComponent<NetworkObject>()));
					}
					if (num <= num2++)
					{
						break;
					}
				}
			}
		}

		public static GrabbableObject SpawnUpsideDownObject(Item itemToSpawn, int value = 0)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			List<RandomScrapSpawn> list = Object.FindObjectsOfType<RandomScrapSpawn>().ToList();
			if (list.Any())
			{
				LFCUtilities.Shuffle<RandomScrapSpawn>((IList<RandomScrapSpawn>)list);
				int index = new Random().Next(0, list.Count);
				RandomScrapSpawn val = list[index];
				RoundManager instance = RoundManager.Instance;
				((Component)val).transform.position = instance.GetRandomNavMeshPositionInBoxPredictable(((Component)val).transform.position, val.itemSpawnRange, instance.navHit, instance.AnomalyRandom, -1, 1f) + Vector3.up * itemToSpawn.verticalOffset;
				Vector3 val2 = ((Component)val).transform.position + Vector3.up * 0.5f;
				GrabbableObject val3 = LFCObjectsManager.SpawnObjectForServer(itemToSpawn.spawnPrefab, val2);
				if (!(val3 is UpsideDownObject))
				{
					StrangerThingsNetworkManager.Instance.SetGObjectInUpsideDownEveryoneRpc(NetworkObjectReference.op_Implicit(((Component)val3).GetComponent<NetworkObject>()), isInUpsideDown: true);
				}
				LFCNetworkManager.Instance.SetScrapValueEveryoneRpc(NetworkObjectReference.op_Implicit(((Component)val3).GetComponent<NetworkObject>()), value);
				return val3;
			}
			return null;
		}

		[HarmonyPatch(typeof(RoundManager), "ResetEnemyTypesSpawnedCounts")]
		[HarmonyPostfix]
		private static void ResetEnemyTypesSpawnedCounts(RoundManager __instance)
		{
			foreach (KeyValuePair<EnemyType, int> upsideDownEnemy in StrangerThings.upsideDownEnemies)
			{
				EnemyType key = upsideDownEnemy.Key;
				key.numberSpawned = 0;
				foreach (EnemyAI spawnedEnemy in __instance.SpawnedEnemies)
				{
					if ((Object)(object)spawnedEnemy.enemyType == (Object)(object)key)
					{
						key.numberSpawned++;
					}
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "PlayRandomClip")]
		[HarmonyPrefix]
		private static bool PlayRandomClip(AudioSource audioSource)
		{
			GameObject val = ((audioSource != null) ? ((Component)audioSource).gameObject : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			GameObject val2 = ((localPlayer != null) ? ((Component)localPlayer).gameObject : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return true;
			}
			EnemyAI val3 = default(EnemyAI);
			if (LFCUtilities.TryGetComponentInParent<EnemyAI>(val, ref val3))
			{
				return DimensionRegistry.AreInSameDimension(((Component)val3).gameObject, val2);
			}
			GrabbableObject val4 = default(GrabbableObject);
			if (LFCUtilities.TryGetComponentInParent<GrabbableObject>(val, ref val4))
			{
				return DimensionRegistry.AreInSameDimension(((Component)val4).gameObject, val2);
			}
			return true;
		}
	}
	public class SandSpiderWebTrapPatch
	{
		[HarmonyPatch(typeof(SandSpiderWebTrap), "Awake")]
		[HarmonyPostfix]
		private static void AwakeSpiderWeb(SandSpiderWebTrap __instance)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)null)
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}
	}
	public class ShotgunItemPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(ShotgunItem), "ShootGun")]
		private static IEnumerable<CodeInstruction> ShootGun(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Expected O, but got Unknown
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Expected O, but got Unknown
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Expected O, but got Unknown
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Expected O, but got Unknown
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Expected O, but got Unknown
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Expected O, but got Unknown
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Expected O, but got Unknown
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(PlayerControllerB), "DamagePlayer", new Type[7]
			{
				typeof(int),
				typeof(bool),
				typeof(bool),
				typeof(CauseOfDeath),
				typeof(int),
				typeof(bool),
				typeof(Vector3)
			}, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(IHittable), "Hit", new Type[5]
			{
				typeof(int),
				typeof(Vector3),
				typeof(PlayerControllerB),
				typeof(bool),
				typeof(int)
			}, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.PropertyGetter(typeof(Component), "gameObject");
			MethodInfo methodInfo4 = AccessTools.Method(typeof(DimensionRegistry), "AreInSameDimension", new Type[2]
			{
				typeof(GameObject),
				typeof(GameObject)
			}, (Type[])null);
			for (int i = 0; i < list.Count; i++)
			{
				if (methodInfo != null && CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					int num = FindPrevLdlocIndex(list, i, 1);
					if (num != -1)
					{
						Label label = il.DefineLabel();
						Label label2 = il.DefineLabel();
						list[num].labels.Add(label);
						if (i + 1 < list.Count)
						{
							list[i + 1].labels.Add(label2);
						}
						List<CodeInstruction> list2 = new List<CodeInstruction>(7)
						{
							new CodeInstruction(OpCodes.Ldarg_0, (object)null),
							new CodeInstruction(OpCodes.Callvirt, (object)methodInfo3),
							new CodeInstruction(OpCodes.Ldloc_1, (object)null),
							new CodeInstruction(OpCodes.Callvirt, (object)methodInfo3),
							new CodeInstruction(OpCodes.Call, (object)methodInfo4),
							new CodeInstruction(OpCodes.Brtrue_S, (object)label),
							new CodeInstruction(OpCodes.Br_S, (object)label2)
						};
						list.InsertRange(num, list2);
						i += list2.Count;
					}
				}
				else
				{
					if (!(methodInfo2 != null) || !CodeInstructionExtensions.Calls(list[i], methodInfo2))
					{
						continue;
					}
					int num2 = FindPrevLdlocIndex(list, i, 10);
					if (num2 == -1)
					{
						continue;
					}
					Label label4;
					if (i + 1 < list.Count && (list[i + 1].opcode == OpCodes.Brfalse || list[i + 1].opcode == OpCodes.Brfalse_S) && list[i + 1].operand is Label label3)
					{
						label4 = label3;
					}
					else
					{
						label4 = il.DefineLabel();
						if (i + 1 < list.Count)
						{
							list[i + 1].labels.Add(label4);
						}
					}
					List<CodeInstruction> list3 = new List<CodeInstruction>(6)
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Callvirt, (object)methodInfo3),
						new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)12),
						new CodeInstruction(OpCodes.Callvirt, (object)methodInfo3),
						new CodeInstruction(OpCodes.Call, (object)methodInfo4),
						new CodeInstruction(OpCodes.Brfalse_S, (object)label4)
					};
					list.InsertRange(num2, list3);
					i += list3.Count;
				}
			}
			return list;
		}

		private static int FindPrevLdlocIndex(List<CodeInstruction> code, int fromIndex, int localIndex)
		{
			for (int num = fromIndex; num >= 0; num--)
			{
				if (TryGetLdlocIndex(code[num], out var index) && index == localIndex)
				{
					return num;
				}
			}
			return -1;
		}

		private static bool TryGetLdlocIndex(CodeInstruction ci, out int index)
		{
			index = -1;
			if (ci.opcode == OpCodes.Ldloc_0)
			{
				index = 0;
				return true;
			}
			if (ci.opcode == OpCodes.Ldloc_1)
			{
				index = 1;
				return true;
			}
			if (ci.opcode == OpCodes.Ldloc_2)
			{
				index = 2;
				return true;
			}
			if (ci.opcode == OpCodes.Ldloc_3)
			{
				index = 3;
				return true;
			}
			if (ci.opcode != OpCodes.Ldloc && ci.opcode != OpCodes.Ldloc_S)
			{
				return false;
			}
			if (ci.operand is LocalBuilder localBuilder)
			{
				index = localBuilder.LocalIndex;
				return true;
			}
			if (ci.operand is int num)
			{
				index = num;
				return true;
			}
			if (ci.operand is byte b)
			{
				index = b;
				return true;
			}
			return false;
		}
	}
	public class StartOfRoundPatch
	{
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void StartRound(StartOfRound __instance)
		{
			if (NetworkManager.Singleton.IsHost && (Object)(object)StrangerThingsNetworkManager.Instance == (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(StrangerThings.managerPrefab, ((Component)__instance).transform.parent);
				val.GetComponent<NetworkObject>().Spawn(false);
				StrangerThings.mls.LogInfo((object)"Spawning StrangerThingsNetworkManager");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
		[HarmonyPostfix]
		public static void EndRound(StartOfRound __instance)
		{
			PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (DimensionRegistry.IsInUpsideDown(((Component)val).gameObject))
				{
					DimensionRegistry.SetInUpsideDown(((Component)val).gameObject, isInUpsideDown: false);
				}
			}
			MapObjectsManager.upsideDownPortals.Clear();
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable()
		{
			StrangerThingsNetworkManager.Instance = null;
		}
	}
	public class StormyWeatherPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(StormyWeather), "Update")]
		private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "isInFactory");
			MethodInfo operand = AccessTools.Method(typeof(StormyWeatherPatch), "IsUntargetableObject", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo2 && fieldInfo2 == fieldInfo)
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = operand;
				}
			}
			return list;
		}

		[HarmonyPatch(typeof(StormyWeather), "LightningStrike")]
		[HarmonyPrefix]
		private static bool ShouldRunLightningStrike(StormyWeather __instance)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((int)StartOfRound.Instance.currentLevel.currentWeather != 2)
			{
				PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
				if (!DimensionRegistry.IsInUpsideDown((localPlayer != null) ? ((Component)localPlayer).gameObject : null))
				{
					__instance.staticElectricityParticle.Stop();
					((Component)__instance.staticElectricityParticle).GetComponent<AudioSource>().Stop();
					__instance.setStaticToObject = null;
					return false;
				}
			}
			return true;
		}

		private static bool IsUntargetableObject(GrabbableObject grabbableObject)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (!((Object)(object)grabbableObject == (Object)null) && !grabbableObject.isInFactory)
			{
				if ((int)StartOfRound.Instance.currentLevel.currentWeather != 2)
				{
					return !DimensionRegistry.IsInUpsideDown(((Component)grabbableObject).gameObject);
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(StormyWeather), "SetStaticElectricityWarning")]
		[HarmonyPrefix]
		private static bool SetStaticElectricityWarning(NetworkObject warningObject)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			GameObject gameObject = ((Component)warningObject).gameObject;
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if (DimensionRegistry.AreInSameDimension(gameObject, (localPlayer != null) ? ((Component)localPlayer).gameObject : null))
			{
				if ((int)StartOfRound.Instance.currentLevel.currentWeather != 2)
				{
					PlayerControllerB localPlayer2 = LFCUtilities.LocalPlayer;
					return DimensionRegistry.IsInUpsideDown((localPlayer2 != null) ? ((Component)localPlayer2).gameObject : null);
				}
				return true;
			}
			return false;
		}

		[HarmonyPatch(typeof(StormyWeather), "PlayThunderEffects")]
		[HarmonyPrefix]
		private static void FogFlash()
		{
			UpsideDownAtmosphereController.Instance?.TriggerLightning();
		}
	}
	public class VehicleControllerPatch
	{
		[HarmonyPatch(typeof(VehicleController), "Start")]
		[HarmonyPostfix]
		private static void StartVehicleController(VehicleController __instance)
		{
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)null)
			{
				DimensionRegistry.UpdateVisibilityState(((Component)__instance).gameObject);
			}
		}
	}
}
namespace StrangerThings.ModsCompat
{
	public static class MelaniesVoiceSoftCompat
	{
		private static PropertyInfo piPlayerAudioGroup;

		private static PropertyInfo piPlayerScript;

		private static PropertyInfo piGroupVolume;

		public static void Patch(Harmony harmony)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Type type = Type.GetType("com.github.zehsteam.MelaniesVoice.MonoBehaviours.VoiceController, com.github.zehsteam.MelaniesVoice");
			if (type != null)
			{
				MethodInfo methodInfo = AccessTools.Method(type, "UpdateVoiceVolume", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					piPlayerAudioGroup = AccessTools.Property(type, "PlayerAudioGroup");
					piPlayerScript = AccessTools.Property(type, "PlayerScript");
					HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(MelaniesVoiceSoftCompat), "UpdateVoiceVolume", (Type[])null, (Type[])null));
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static void UpdateVoiceVolume(object __instance)
		{
			if (__instance == null)
			{
				return;
			}
			PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null || !localPlayer.isPlayerControlled || localPlayer.isPlayerDead)
			{
				return;
			}
			object? obj = piPlayerScript?.GetValue(__instance, null);
			PlayerControllerB val = (PlayerControllerB)((obj is PlayerControllerB) ? obj : null);
			if (!LFCUtilities.ShouldNotBeLocalPlayer(val) || DimensionRegistry.AreInSameDimension(((Component)localPlayer).gameObject, ((Component)val).gameObject))
			{
				return;
			}
			object obj2 = piPlayerAudioGroup?.GetValue(__instance, null);
			if (obj2 == null)
			{
				return;
			}
			if (piGroupVolume == null)
			{
				piGroupVolume = AccessTools.Property(obj2.GetType(), "Volume");
			}
			float num = ((piGroupVolume != null) ? ((float)piGroupVolume.GetValue(obj2, null)) : 0f);
			if (num > 0f)
			{
				float num2 = ((!DimensionRegistry.IsInUpsideDown(((Component)localPlayer).gameObject)) ? (((!localPlayer.speakingToWalkieTalkie || !val.holdingWalkieTalkie) && (!val.speakingToWalkieTalkie || !localPlayer.holdingWalkieTalkie)) ? 0f : (MapObjectsManager.IsNearAntennaHazard(val) ? 1f : 0f)) : (((!localPlayer.speakingToWalkieTalkie || !val.holdingWalkieTalkie) && (!val.speakingToWalkieTalkie || !localPlayer.holdingWalkieTalkie)) ? 0.1f : (MapObjectsManager.IsNearAntennaHazard(localPlayer) ? 1f : 0f)));
				if (piGroupVolume != null && piGroupVolume.CanWrite)
				{
					piGroupVolume.SetValue(obj2, num * num2, null);
				}
			}
		}
	}
	public static class OpenBodyCamsSoftCompat
	{
		private static FieldInfo fiCurrentActualTarget;

		private static FieldInfo fiCurrentPlayer;

		private static FieldInfo fiEnableCamera;

		private static MethodInfo miGetForceTargetInvalid;

		private static Type statusEnumType;

		private static object statusDisabled;

		private static object statusTargetInvalid;

		public static void Patch(Harmony harmony)
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			Type type = Type.GetType("OpenBodyCams.BodyCamComponent, OpenBodyCams");
			if (!(type != null))
			{
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "GetUpdatedCameraStatus", (Type[])null, (Type[])null);
			if (!(methodInfo != null))
			{
				return;
			}
			statusEnumType = methodInfo.ReturnType;
			if (statusEnumType != null && statusEnumType.IsEnum)
			{
				statusDisabled = Enum.Parse(statusEnumType, "Disabled", ignoreCase: false);
				statusTargetInvalid = Enum.Parse(statusEnumType, "TargetInvalid", ignoreCase: false);
				fiEnableCamera = AccessTools.Field(type, "EnableCamera");
				miGetForceTargetInvalid = AccessTools.PropertyGetter(type, "ForceTargetInvalid");
				fiCurrentActualTarget = AccessTools.Field(type, "currentActualTarget");
				fiCurrentPlayer = AccessTools.Field(type, "currentPlayer");
				if (fiEnableCamera == null || miGetForceTargetInvalid == null || fiCurrentActualTarget == null || fiCurrentPlayer == null)
				{
					StrangerThings.mls.LogError((object)"OpenBodyCams compat: members not found.");
					return;
				}
				HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(OpenBodyCamsSoftCompat), "GetUpdatedCameraStatus_Prefix", (Type[])null, (Type[])null));
				harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static bool GetUpdatedCameraStatus_Prefix(object __instance, ref object __result)
		{
			if (!(bool)fiEnableCamera.GetValue(__instance) || fiCurrentActualTarget.GetValue(__instance) == null || (bool)miGetForceTargetInvalid.Invoke(__instance, null))
			{
				return true;
			}
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)null && DimensionRegistry.IsInUpsideDown(((Component)LFCUtilities.LocalPlayer).gameObject))
			{
				__result = statusDisabled;
				return false;
			}
			PlayerControllerB val = (PlayerControllerB)((fiCurrentPlayer != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)LFCUtilities.LocalPlayer != (Object)null && (Object)(object)val != (Object)null && val.isPlayerControlled && !DimensionRegistry.AreInSameDimension(((Component)LFCUtilities.LocalPlayer).gameObject, ((Component)val).gameObject))
			{
				__result = statusTargetInvalid;
				return false;
			}
			return true;
		}
	}
	public static class SelfSortingStorageSoftCompat
	{
		public static void Patch(Harmony harmony)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			Type type = Type.GetType("SelfSortingStorage.Utils.Effects, SelfSortingStorage") ?? AccessTools.TypeByName("SelfSortingStorage.Utils.Effects");
			if (type != null)
			{
				MethodInfo methodInfo = AccessTools.Method(type, "SpawnItem", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(SelfSortingStorageSoftCompat), "SpawnItem", (Type[])null, (Type[])null));
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static void SpawnItem(object __result)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (__result == null)
			{
				return;
			}
			FieldInfo fieldInfo = AccessTools.GetDeclaredFields(__result.GetType()).FirstOrDefault((FieldInfo f) => f.FieldType == typeof(NetworkObjectReference));
			if (fieldInfo == null)
			{
				return;
			}
			NetworkObjectReference val = (NetworkObjectReference)fieldInfo.GetValue(__result);
			NetworkObject val2 = default(NetworkObject);
			if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null) && (Object)(object)val2 != (Object)null)
			{
				GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
				if (component is UpsideDownObject)
				{
					StrangerThingsNetworkManager.Instance?.SetGObjectInUpsideDownEveryoneRpc(NetworkObjectReference.op_Implicit(val2), isInUpsideDown: false);
				}
			}
		}
	}
	public static class SellBodiesFixedSoftCompat
	{
		private static readonly BaseUnityPlugin SellBodiesInstance;

		static SellBodiesFixedSoftCompat()
		{
			if (Chainloader.PluginInfos.TryGetValue("Entity378.sellbodies", out var value))
			{
				SellBodiesInstance = value.Instance;
			}
		}

		public static void RegisterBody(string enemyName, Item item, int minValue, int maxValue, bool enabled)
		{
			if ((Object)(object)SellBodiesInstance != (Object)null && (Object)(object)item != (Object)null)
			{
				Utilities.FixMixerGroups(item.spawnPrefab);
				item.spawnPrefab.AddComponent(AccessTools.TypeByName("BodySyncer"));
				item.minValue = minValue;
				item.maxValue = maxValue;
				NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
				Items.RegisterItem(item);
				if (enabled && AccessTools.Field(((object)SellBodiesInstance).GetType(), "BodySpawns")?.GetValue(SellBodiesInstance) is IDictionary dictionary)
				{
					dictionary[enemyName] = item;
				}
			}
		}
	}
}
namespace StrangerThings.Managers
{
	public class ConfigManager
	{
		public static ConfigEntry<bool> globalTips;

		public static ConfigEntry<int> minMirrorScraps;

		public static ConfigEntry<int> maxMirrorScraps;

		public static ConfigEntry<bool> colorBlindTips;

		public static ConfigEntry<string> scrapExclusions;

		public static ConfigEntry<int> demogorgonRarity;

		public static ConfigEntry<int> demogorgonMinHeadValue;

		public static ConfigEntry<int> demogorgonMaxHeadValue;

		public static ConfigEntry<int> crustapikanRarity;

		public static ConfigEntry<int> crustapikanMinArmValue;

		public static ConfigEntry<int> crustapikanMaxArmValue;

		public static ConfigEntry<int> crustapikanLarvaeRarity;

		public static ConfigEntry<int> crustapikanLarvaeMinCorpseValue;

		public static ConfigEntry<int> crustapikanLarvaeMaxCorpseValue;

		public static ConfigEntry<int> limadonRarity;

		public static ConfigEntry<int> limadonMinCorpseValue;

		public static ConfigEntry<int> limadonMaxCorpseValue;

		public static ConfigEntry<int> portalLockDuration;

		public static ConfigEntry<float> upsideDownVolume;

		public static ConfigEntry<string> visibilityStateInclusions;

		public static ConfigEntry<string> visibilityStateExclusions;

		public static ConfigEntry<int> corruptedPortalsAmount;

		public static ConfigEntry<float> corruptedPortalsMinCooldown;

		public static ConfigEntry<float> corruptedPortalsMaxCooldown;

		public static void Load()
		{
			globalTips = StrangerThings.configFile.Bind<bool>("_Global_", "Global tips", true, "Enable global tips to help learn the mod’s mechanics.");
			minMirrorScraps = StrangerThings.configFile.Bind<int>("Mirror Scraps", "Min Mirror Scraps", 6, "Min Mirror Scraps.");
			maxMirrorScraps = StrangerThings.configFile.Bind<int>("Mirror Scraps", "Max Mirror Scraps", 10, "Max Mirror Scraps.");
			colorBlindTips = StrangerThings.configFile.Bind<bool>("Mirror Scraps", "Colorblind tips", true, "Enable particle color change notifications for mirror Mirror Scraps.");
			scrapExclusions = StrangerThings.configFile.Bind<string>("Mirror Scraps", "Exclusion list", "Key,Bee hive,Apparatus,EnginePart1,V-type engine,Toy car", "List of scraps that will not spawn in the Upside Down.\nYou can add scraps by separating them with a comma.");
			demogorgonRarity = StrangerThings.configFile.Bind<int>("Demogorgon", "Rarity", 20, "Demogorgon base rarity.");
			demogorgonMinHeadValue = StrangerThings.configFile.Bind<int>("Demogorgon", "Min head value", 80, "Demogorgon min head value (SellBodiesFixed must be installed).");
			demogorgonMaxHeadValue = StrangerThings.configFile.Bind<int>("Demogorgon", "Max head value", 120, "Demogorgon max head value (SellBodiesFixed must be installed).");
			crustapikanRarity = StrangerThings.configFile.Bind<int>("Crustapikan", "Rarity", 20, "Crustapikan base rarity.");
			crustapikanMinArmValue = StrangerThings.configFile.Bind<int>("Crustapikan", "Min arm value", 250, "Crustapikan min arm value (SellBodiesFixed must be installed).");
			crustapikanMaxArmValue = StrangerThings.configFile.Bind<int>("Crustapikan", "Max arm value", 300, "Crustapikan max arm value (SellBodiesFixed must be installed).");
			crustapikanLarvaeRarity = StrangerThings.configFile.Bind<int>("Crustapikan Larvae", "Rarity", 20, "Crustapikan Larvae base rarity.");
			crustapikanLarvaeMinCorpseValue = StrangerThings.configFile.Bind<int>("Crustapikan Larvae", "Min corpse value", 20, "Crustapikan Larvae min corpse value (SellBodiesFixed must be installed).");
			crustapikanLarvaeMaxCorpseValue = StrangerThings.configFile.Bind<int>("Crustapikan Larvae", "Max corpse value", 40, "Crustapikan Larvae max corpse value (SellBodiesFixed must be installed).");
			limadonRarity = StrangerThings.configFile.Bind<int>("Limadon", "Rarity", 20, "Limadon base rarity.");
			limadonMinCorpseValue = StrangerThings.configFile.Bind<int>("Limadon", "Min corpse value", 70, "Limadon min corpse value (SellBodiesFixed must be installed).");
			limadonMaxCorpseValue = StrangerThings.configFile.Bind<int>("Limadon", "Max corpse value", 110, "Limadon max corpse value (SellBodiesFixed must be installed).");
			portalLockDuration = StrangerThings.configFile.Bind<int>("Upside Down", "Portal lock duration", 60, "Portal lock duration when entering or exiting.");
			upsideDownVolume = StrangerThings.configFile.Bind<float>("Upside Down", "Upside Down volume", 1f, "Volume of background music in the Upside Down.");
			visibilityStateInclusions = StrangerThings.configFile.Bind<string>("Upside Down", "Visibility state whitelist", "SP_Snowman,SP_SnowPile,LK_Lantern,SawBoxExplosive,ChainEscape", "Additional list of Network Objects whose visibility (visible/invisible) will be updated when switching between dimensions.");
			visibilityStateExclusions = StrangerThings.configFile.Bind<string>("Upside Down", "Visibility state blacklist", "Locker,DressGirl", "Network Objects whose visibility (visible/invisible) will not be updated when switching between dimensions.");
			corruptedPortalsAmount = StrangerThings.configFile.Bind<int>("Corrupted Portals", "Amount", 3, "Amount of simultaneous Corrupted Portals.");
			corruptedPortalsMinCooldown = StrangerThings.configFile.Bind<float>("Corrupted Portals", "Min cooldown", 30f, "Minimum Corrupted Portals cooldown.");
			corruptedPortalsMaxCooldown = StrangerThings.configFile.Bind<float>("Corrupted Portals", "Max cooldown", 300f, "Maximum Corrupted Portals cooldown.");
		}
	}
	public static class MapObjectsManager
	{
		public static HashSet<UpsideDownPortal> upsideDownPortals = new HashSet<UpsideDownPortal>();

		public static HashSet<AntennaHazard> antennaHazards = new HashSet<AntennaHazard>();

		public static void AddUpsideDownPortal(UpsideDownPortal upsideDownPortal)
		{
			upsideDownPortals.Add(upsideDownPortal);
		}

		public static UpsideDownPortal[] GetUpsideDownPortals()
		{
			upsideDownPortals.RemoveWhere((UpsideDownPortal p) => (Object)(object)p == (Object)null);
			return upsideDownPortals.Where((UpsideDownPortal p) => !p.isFake).ToArray();
		}

		public static void SpawnPortalsForServer()
		{
			if (GetUpsideDownPortals().Length < 8)
			{
				LFCMapObjectsManager.SpawnScatteredMapObjectsForServer(8, 2, 2, (Action<Vector3, bool>)delegate(Vector3 position, bool isOutside)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					SpawnUpsideDownPortalForServer(position, isOutside);
				});
			}
		}

		public static UpsideDownPortal SpawnUpsideDownPortalForServer(Vector3 position, bool isOutside, bool isFake = false)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(StrangerThings.upsideDownPortal, position + Vector3.down * 0.1f, Quaternion.identity, RoundManager.Instance.mapPropsContainer.transform);
			val.GetComponent<NetworkObject>().Spawn(true);
			UpsideDownPortal component = val.GetComponent<UpsideDownPortal>();
			component.InitializeEveryoneRpc(isOutside, isFake);
			return component;
		}

		public static UpsideDownPortal GetClosestPortal(Vector3 position)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			UpsideDownPortal result = null;
			float num = float.MaxValue;
			UpsideDownPortal[] array = GetUpsideDownPortals();
			foreach (UpsideDownPortal upsideDownPortal in array)
			{
				if ((Object)(object)upsideDownPortal != (Object)null)
				{
					float num2 = Vector3.SqrMagnitude(((Component)upsideDownPortal).transform.position - position);
					if (num2 < num)
					{
						num = num2;
						result = upsideDownPortal;
					}
				}
			}
			return result;
		}

		public static void AddAntennaHazards(AntennaHazard antennaHazard)
		{
			antennaHazards.Add(antennaHazard);
		}

		public static HashSet<AntennaHazard> GetAntennaHazards()
		{
			antennaHazards.RemoveWhere((AntennaHazard p) => (Object)(object)p == (Object)null);
			return antennaHazards;
		}

		public static bool IsNearAntennaHazard(PlayerControllerB player)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			foreach (AntennaHazard antennaHazard in GetAntennaHazards())
			{
				if ((Object)(object)antennaHazard != (Object)null && (Object)(object)antennaHazard.antennaItem != (Object)null && ((GrabbableObject)antennaHazard.antennaItem).insertedBattery != null && !((GrabbableObject)antennaHazard.antennaItem).insertedBattery.empty)
				{
					float num = Vector3.SqrMagnitude(((Component)antennaHazard).transform.position - ((Component)player).transform.position);
					if (num < 2500f)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	public class StrangerThingsNetworkManager : NetworkBehaviour
	{
		public static StrangerThingsNetworkManager Instance;

		public void Awake()
		{
			Instance = this;
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		public void SetPlayerInUpsideDownEveryoneRpc(int playerId, bool isInUpsideDown)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
				{
					RpcAttributeParams val = new RpcAttributeParams
					{
						RequireOwnership = false
					};
					RpcParams val2 = default(RpcParams);
					FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(792643303u, val2, val, (SendTo)6, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val3, playerId);
					((FastBufferWriter)(ref val3)).WriteValueSafe<bool>(ref isInUpsideDown, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendRpc(ref val3, 792643303u, val2, val, (SendTo)6, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1)
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					GameObject entity = StartOfRound.Instance.allPlayerObjects[playerId];
					DimensionRegistry.SetInUpsideDown(entity, isInUpsideDown);
				}
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		public void SetGObjectInUpsideDownEveryoneRpc(NetworkObjectReference obj, bool isInUpsideDown)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Invalid comparison between Unknown and I4
			//IL_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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 != 1)
			{
				RpcAttributeParams val = new RpcAttributeParams
				{
					RequireOwnership = false
				};
				RpcParams val2 = default(RpcParams);
				FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(968582711u, val2, val, (SendTo)6, (RpcDelivery)0);
				((FastBufferWriter)(ref val3)).WriteValueSafe<NetworkObjectReference>(ref obj, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val3)).WriteValueSafe<bool>(ref isInUpsideDown, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendRpc(ref val3, 968582711u, val2, val, (SendTo)6, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1)
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			NetworkObject val4 = default(NetworkObject);
			if (((NetworkObjectReference)(ref obj)).TryGet(ref val4, (NetworkManager)null))
			{
				DimensionRegistry.SetInUpsideDown(((Component)val4).gameObject, isInUpsideDown);
				GrabbableObject val5 = default(GrabbableObject);
				if (LFCUtilities.IsServer && LFCUtilities.TryGetComponentInChildren<GrabbableObject>(((Component)val4).gameObject, ref val5))
				{
					HoarderBugAI.RefreshGrabbableObjectsInMapList();
				}
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		public void AddToMirrorEveryoneRpc(NetworkObjectReference scriptObj, NetworkObjectReference mirrorObj, NetworkObjectReference twinObj)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Invalid comparison between Unknown and I4
			//IL_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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 != 1)
			{
				RpcAttributeParams val = new RpcAttributeParams
				{
					RequireOwnership = false
				};
				RpcParams val2 = default(RpcParams);
				FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(2994801010u, val2, val, (SendTo)6, (RpcDelivery)0);
				((FastBufferWriter)(ref val3)).WriteValueSafe<NetworkObjectReference>(ref scriptObj, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val3)).WriteValueSafe<NetworkObjectReference>(ref mirrorObj, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val3)).WriteValueSafe<NetworkObjectReference>(ref twinObj, default(ForNetworkSerializable));
				((NetworkBehaviour)this).__endSendRpc(ref val3, 2994801010u, val2, val, (SendTo)6, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1)
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			NetworkObject val4 = default(NetworkObject);
			NetworkObject val5 = default(NetworkObject);
			NetworkObject val6 = default(NetworkObject);
			UpsideDownMirrorBehaviour upsideDownMirrorBehaviour = default(UpsideDownMirrorBehaviour);
			if (((NetworkObjectReference)(ref scriptObj)).TryGet(ref val4, (NetworkManager)null) && ((NetworkObjectReference)(ref mirrorObj)).TryGet(ref val5, (NetworkManager)null) && ((NetworkObjectReference)(ref twinObj)).TryGet(ref val6, (NetworkManager)null) && ((Component)val4).TryGetComponent<UpsideDownMirrorBehaviour>(ref upsideDownMirrorBehaviour))
			{
				GrabbableObject val7 = (upsideDownMirrorBehaviour.mirror = ((Component)val5).GetComponentInChildren<GrabbableObject>());
				((Component)val4).transform.SetParent(((Component)val7).transform, true);
				GrabbableObject val8 = (upsideDownMirrorBehaviour.twin = ((Component)val6).GetComponentInChildren<GrabbableObject>());
				upsideDownMirrorBehaviour.twinRenderers = (from r in ((Component)val8).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)r).enabled
					select r).ToList();
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		public void PlayPoisonExplosionEveryoneRpc(Vector3 position)
		{
			//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_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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 != 1)
			{
				RpcAttributeParams val = new RpcAttributeParams
				{
					RequireOwnership = false
				};
				RpcParams val2 = default(RpcParams);
				FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(1550006684u, val2, val, (SendTo)6, (RpcDelivery)0);
				((FastBufferWriter)(ref val3)).WriteValueSafe(ref position);
				((NetworkBehaviour)this).__endSendRpc(ref val3, 1550006684u, val2, val, (SendTo)6, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1)
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (LFCUtilities.IsServer)
				{
					((MonoBehaviour)this).StartCoroutine(PoisonCoroutine(position, 4f));
				}
				string text = "Lega Fusion Core" + ((Object)LegaFusionCore.poisonExplosionParticle).name;
				Vector3 val4 = position;
				Quaternion val5 = Quaternion.Euler(90f, 0f, 0f);
				PlayerControllerB localPlayer = LFCUtilities.LocalPlayer;
				LFCGlobalManager.PlayParticle(text, val4, val5, 4f, DimensionRegistry.IsInUpsideDown((localPlayer != null) ? ((Component)localPlayer).gameObject : null));
				string text2 = "Lega Fusion Core" + ((Object)LegaFusionCore.poisonExplosionAudio).name;
				Vector3 val6 = position;
				PlayerControllerB localPlayer2 = LFCUtilities.LocalPlayer;
				LFCGlobalManager.PlayAudio(text2, val6, DimensionRegistry.IsInUpsideDown((localPlayer2 != null) ? ((Component)localPlayer2).gameObject : null));
			}
		}

		public IEnumerator PoisonCoroutine(Vector3 position, float duration)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			for (float timePassed = 0f; timePassed < duration; timePassed += 0.2f)
			{
				Collider[] array = Physics.OverlapSphere(position, Mathf.Max(timePassed * 5f, 7.5f), StartOfRound.Instance.playersMask, (QueryTriggerInteraction)2);
				foreach (Collider val in array)
				{
					PlayerControllerB component = ((Component)val).GetComponent<PlayerControllerB>();
					if (!((Object)(object)component == (Object)null) && !component.isPlayerDead && DimensionRegistry.IsInUpsideDown(((Component)component).gameObject))
					{
						LFCNetworkManager.Instance.ApplyStatusEveryoneRpc(-1, (int)component.playerClientId, 2, 10, 20);
					}
				}
				yield return (object)new WaitForSeconds(0.2f);
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(792643303u, new RpcReceiveHandler(__rpc_handler_792643303), "SetPlayerInUpsideDownEveryoneRpc");
			((NetworkBehaviour)this).__registerRpc(968582711u, new RpcReceiveHandler(__rpc_handler_968582711), "SetGObjectInUpsideDownEveryoneRpc");
			((NetworkBehaviour)this).__registerRpc(2994801010u, new RpcReceiveHandler(__rpc_handler_2994801010), "AddToMirrorEveryoneRpc");
			((NetworkBehaviour)this)